Bitcoin Core  31.0.0
P2P Digital Currency
musig.h
Go to the documentation of this file.
1 // Copyright (c) 2024-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_MUSIG_H
6 #define BITCOIN_MUSIG_H
7 
8 #include <pubkey.h>
9 
10 #include <optional>
11 #include <vector>
12 
14 class MuSig2SecNonceImpl;
16 
17 constexpr size_t MUSIG2_PUBNONCE_SIZE{66};
18 
22 std::optional<CPubKey> MuSig2AggregatePubkeys(const std::vector<CPubKey>& pubkeys, secp256k1_musig_keyagg_cache& keyagg_cache, const std::optional<CPubKey>& expected_aggregate);
23 std::optional<CPubKey> MuSig2AggregatePubkeys(const std::vector<CPubKey>& pubkeys);
24 
27 
40 {
41 private:
42  std::unique_ptr<MuSig2SecNonceImpl> m_impl;
43 
44 public:
46  MuSig2SecNonce(MuSig2SecNonce&&) noexcept;
47  MuSig2SecNonce& operator=(MuSig2SecNonce&&) noexcept;
48  ~MuSig2SecNonce();
49 
50  // Delete copy constructors
51  MuSig2SecNonce(const MuSig2SecNonce&) = delete;
52  MuSig2SecNonce& operator=(const MuSig2SecNonce&) = delete;
53 
55  void Invalidate();
56  bool IsValid();
57 };
58 
59 uint256 MuSig2SessionID(const CPubKey& script_pubkey, const CPubKey& part_pubkey, const uint256& sighash);
60 
61 std::optional<std::vector<uint8_t>> CreateMuSig2AggregateSig(const std::vector<CPubKey>& participants, const CPubKey& aggregate_pubkey, const std::vector<std::pair<uint256, bool>>& tweaks, const uint256& sighash, const std::map<CPubKey, std::vector<uint8_t>>& pubnonces, const std::map<CPubKey, uint256>& partial_sigs);
62 
63 #endif // BITCOIN_MUSIG_H
This module implements BIP 327 "MuSig2 for BIP340-compatible Multi-Signatures" (https://github.com/bitcoin/bips/blob/master/bip-0327.mediawiki) v1.0.0.
CExtPubKey CreateMuSig2SyntheticXpub(const CPubKey &pubkey)
Construct the BIP 328 synthetic xpub for a pubkey.
Definition: musig.cpp:71
Definition: common.h:29
MuSig2SecNonce encapsulates a secret nonce in use in a MuSig2 signing session.
Definition: musig.h:39
constexpr size_t MUSIG2_PUBNONCE_SIZE
Definition: musig.h:17
secp256k1_musig_secnonce * Get() const
Definition: musig.cpp:107
An encapsulated public key.
Definition: pubkey.h:33
bool IsValid()
Definition: musig.cpp:117
Opaque data structure that holds a signer&#39;s secret nonce.
uint256 MuSig2SessionID(const CPubKey &script_pubkey, const CPubKey &part_pubkey, const uint256 &sighash)
Definition: musig.cpp:122
std::optional< std::vector< uint8_t > > CreateMuSig2AggregateSig(const std::vector< CPubKey > &participants, const CPubKey &aggregate_pubkey, const std::vector< std::pair< uint256, bool >> &tweaks, const uint256 &sighash, const std::map< CPubKey, std::vector< uint8_t >> &pubnonces, const std::map< CPubKey, uint256 > &partial_sigs)
Definition: musig.cpp:129
std::unique_ptr< MuSig2SecNonceImpl > m_impl
Definition: musig.h:42
256-bit opaque blob.
Definition: uint256.h:195
std::optional< CPubKey > MuSig2AggregatePubkeys(const std::vector< CPubKey > &pubkeys, secp256k1_musig_keyagg_cache &keyagg_cache, const std::optional< CPubKey > &expected_aggregate)
Compute the full aggregate pubkey from the given participant pubkeys in their current order...
Definition: musig.cpp:54
void Invalidate()
Definition: musig.cpp:112