1111#include < vector>
1212
1313struct secp256k1_musig_keyagg_cache ;
14+ class MuSig2SecNonceImpl ;
15+ struct secp256k1_musig_secnonce ;
1416
1517// ! MuSig2 chaincode as defined by BIP 328
1618using namespace util ::hex_literals;
@@ -26,4 +28,35 @@ std::optional<CPubKey> MuSig2AggregatePubkeys(const std::vector<CPubKey>& pubkey
2628// ! Construct the BIP 328 synthetic xpub for a pubkey
2729CExtPubKey CreateMuSig2SyntheticXpub (const CPubKey& pubkey);
2830
31+ /* *
32+ * MuSig2SecNonce encapsulates a secret nonce in use in a MuSig2 signing session.
33+ * Since this nonce persists outside of libsecp256k1 signing code, we must handle
34+ * its construction and destruction ourselves.
35+ * The secret nonce must be kept a secret, otherwise the private key may be leaked.
36+ * As such, it needs to be treated in the same way that CKeys are treated.
37+ * So this class handles the secure allocation of the secp256k1_musig_secnonce object
38+ * that libsecp256k1 uses, and only gives out references to this object to avoid
39+ * any possibility of copies being made. Furthermore, objects of this class are not
40+ * copyable to avoid nonce reuse.
41+ */
42+ class MuSig2SecNonce
43+ {
44+ private:
45+ std::unique_ptr<MuSig2SecNonceImpl> m_impl;
46+
47+ public:
48+ MuSig2SecNonce ();
49+ MuSig2SecNonce (MuSig2SecNonce&&) noexcept ;
50+ MuSig2SecNonce& operator =(MuSig2SecNonce&&) noexcept ;
51+ ~MuSig2SecNonce ();
52+
53+ // Delete copy constructors
54+ MuSig2SecNonce (const MuSig2SecNonce&) = delete ;
55+ MuSig2SecNonce& operator =(const MuSig2SecNonce&) = delete ;
56+
57+ secp256k1_musig_secnonce* Get () const ;
58+ void Invalidate ();
59+ bool IsValid ();
60+ };
61+
2962#endif // BITCOIN_MUSIG_H
0 commit comments