|
7 | 7 |
|
8 | 8 | #include <consensus/amount.h> |
9 | 9 | #include <key.h> |
| 10 | +#include <musig.h> |
10 | 11 | #include <policy/policy.h> |
11 | 12 | #include <primitives/transaction.h> |
| 13 | +#include <random.h> |
12 | 14 | #include <script/keyorigin.h> |
13 | 15 | #include <script/miniscript.h> |
14 | 16 | #include <script/script.h> |
@@ -100,6 +102,34 @@ bool MutableTransactionSignatureCreator::CreateSchnorrSig(const SigningProvider& |
100 | 102 | return true; |
101 | 103 | } |
102 | 104 |
|
| 105 | +std::vector<uint8_t> MutableTransactionSignatureCreator::CreateMuSig2Nonce(const SigningProvider& provider, const CPubKey& aggregate_pubkey, const CPubKey& script_pubkey, const CPubKey& part_pubkey, const uint256* leaf_hash, const uint256* merkle_root, SigVersion sigversion, const SignatureData& sigdata) const |
| 106 | +{ |
| 107 | + assert(sigversion == SigVersion::TAPROOT || sigversion == SigVersion::TAPSCRIPT); |
| 108 | + |
| 109 | + // Retrieve the private key |
| 110 | + CKey key; |
| 111 | + if (!provider.GetKey(part_pubkey.GetID(), key)) return {}; |
| 112 | + |
| 113 | + // Retrieve participant pubkeys |
| 114 | + auto it = sigdata.musig2_pubkeys.find(aggregate_pubkey); |
| 115 | + if (it == sigdata.musig2_pubkeys.end()) return {}; |
| 116 | + const std::vector<CPubKey>& pubkeys = it->second; |
| 117 | + if (std::find(pubkeys.begin(), pubkeys.end(), part_pubkey) == pubkeys.end()) return {}; |
| 118 | + |
| 119 | + // Compute sighash |
| 120 | + std::optional<uint256> sighash = ComputeSchnorrSignatureHash(leaf_hash, sigversion); |
| 121 | + if (!sighash.has_value()) return {}; |
| 122 | + |
| 123 | + MuSig2SecNonce secnonce; |
| 124 | + std::vector<uint8_t> out = key.CreateMuSig2Nonce(secnonce, *sighash, aggregate_pubkey, pubkeys); |
| 125 | + if (out.empty()) return {}; |
| 126 | + |
| 127 | + // Store the secnonce in the SigningProvider |
| 128 | + provider.SetMuSig2SecNonce(MuSig2SessionID(script_pubkey, part_pubkey, *sighash), std::move(secnonce)); |
| 129 | + |
| 130 | + return out; |
| 131 | +} |
| 132 | + |
103 | 133 | static bool GetCScript(const SigningProvider& provider, const SignatureData& sigdata, const CScriptID& scriptid, CScript& script) |
104 | 134 | { |
105 | 135 | if (provider.GetCScript(scriptid, script)) { |
@@ -755,6 +785,12 @@ class DummySignatureCreator final : public BaseSignatureCreator { |
755 | 785 | sig.assign(64, '\000'); |
756 | 786 | return true; |
757 | 787 | } |
| 788 | + std::vector<uint8_t> CreateMuSig2Nonce(const SigningProvider& provider, const CPubKey& aggregate_pubkey, const CPubKey& script_pubkey, const CPubKey& part_pubkey, const uint256* leaf_hash, const uint256* merkle_root, SigVersion sigversion, const SignatureData& sigdata) const override |
| 789 | + { |
| 790 | + std::vector<uint8_t> out; |
| 791 | + out.assign(MUSIG2_PUBNONCE_SIZE, '\000'); |
| 792 | + return out; |
| 793 | + } |
758 | 794 | }; |
759 | 795 |
|
760 | 796 | } |
|
0 commit comments