Bitcoin Core 30.99.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
16
18using namespace util::hex_literals;
20 // Use immediate lambda to work around GCC-14 bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117966
21 []() consteval { return uint256{"868087ca02a6f974c4598924c36b57762d32cb45717167e300622c7167e38965"_hex_u8}; }(),
22};
23
24
25
26constexpr size_t MUSIG2_PUBNONCE_SIZE{66};
27
31std::optional<CPubKey> MuSig2AggregatePubkeys(const std::vector<CPubKey>& pubkeys, secp256k1_musig_keyagg_cache& keyagg_cache, const std::optional<CPubKey>& expected_aggregate);
32std::optional<CPubKey> MuSig2AggregatePubkeys(const std::vector<CPubKey>& pubkeys);
33
36
49{
50private:
51 std::unique_ptr<MuSig2SecNonceImpl> m_impl;
52
53public:
56 MuSig2SecNonce& operator=(MuSig2SecNonce&&) noexcept;
58
59 // Delete copy constructors
61 MuSig2SecNonce& operator=(const MuSig2SecNonce&) = delete;
62
64 void Invalidate();
65 bool IsValid();
66};
67
68uint256 MuSig2SessionID(const CPubKey& script_pubkey, const CPubKey& part_pubkey, const uint256& sighash);
69
70std::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);
71
72#endif // BITCOIN_MUSIG_H
An encapsulated public key.
Definition: pubkey.h:34
MuSig2SecNonce encapsulates a secret nonce in use in a MuSig2 signing session.
Definition: musig.h:49
void Invalidate()
Definition: musig.cpp:105
bool IsValid()
Definition: musig.cpp:110
MuSig2SecNonce()
Definition: musig.cpp:93
secp256k1_musig_secnonce * Get() const
Definition: musig.cpp:100
std::unique_ptr< MuSig2SecNonceImpl > m_impl
Definition: musig.h:51
MuSig2SecNonce(MuSig2SecNonce &&) noexcept
256-bit opaque blob.
Definition: uint256.h:196
CExtPubKey CreateMuSig2SyntheticXpub(const CPubKey &pubkey)
Construct the BIP 328 synthetic xpub for a pubkey.
Definition: musig.cpp:64
constexpr size_t MUSIG2_PUBNONCE_SIZE
Definition: musig.h:26
uint256 MuSig2SessionID(const CPubKey &script_pubkey, const CPubKey &part_pubkey, const uint256 &sighash)
Definition: musig.cpp:115
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:122
constexpr uint256 MUSIG_CHAINCODE
Definition: musig.h:19
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:47
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
Definition: strencodings.h:384
This module implements BIP 327 "MuSig2 for BIP340-compatible Multi-Signatures" (https://github....
Opaque data structure that holds a signer's secret nonce.