Bitcoin Core 31.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
13class CKey;
17
18constexpr size_t MUSIG2_PUBNONCE_SIZE{66};
19
23std::optional<CPubKey> MuSig2AggregatePubkeys(const std::vector<CPubKey>& pubkeys, secp256k1_musig_keyagg_cache& keyagg_cache, const std::optional<CPubKey>& expected_aggregate);
24std::optional<CPubKey> MuSig2AggregatePubkeys(const std::vector<CPubKey>& pubkeys);
25
28
41{
42private:
43 std::unique_ptr<MuSig2SecNonceImpl> m_impl;
44
45public:
48 MuSig2SecNonce& operator=(MuSig2SecNonce&&) noexcept;
50
51 // Delete copy constructors
53 MuSig2SecNonce& operator=(const MuSig2SecNonce&) = delete;
54
56 void Invalidate();
57 bool IsValid();
58};
59
60uint256 MuSig2SessionID(const CPubKey& script_pubkey, const CPubKey& part_pubkey, const uint256& sighash);
61
62std::vector<uint8_t> CreateMuSig2Nonce(MuSig2SecNonce& secnonce, const uint256& sighash, const CKey& our_seckey, const CPubKey& aggregate_pubkey, const std::vector<CPubKey>& pubkeys);
63std::optional<uint256> CreateMuSig2PartialSig(const uint256& hash, const CKey& our_seckey, const CPubKey& aggregate_pubkey, const std::vector<CPubKey>& pubkeys, const std::map<CPubKey, std::vector<uint8_t>>& pubnonces, MuSig2SecNonce& secnonce, const std::vector<std::pair<uint256, bool>>& tweaks);
64std::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);
65
66#endif // BITCOIN_MUSIG_H
An encapsulated private key.
Definition: key.h:37
An encapsulated public key.
Definition: pubkey.h:34
MuSig2SecNonce encapsulates a secret nonce in use in a MuSig2 signing session.
Definition: musig.h:41
void Invalidate()
Definition: musig.cpp:118
bool IsValid()
Definition: musig.cpp:123
secp256k1_musig_secnonce * Get() const
Definition: musig.cpp:113
std::unique_ptr< MuSig2SecNonceImpl > m_impl
Definition: musig.h:43
MuSig2SecNonce(MuSig2SecNonce &&) noexcept
256-bit opaque blob.
Definition: uint256.h:196
std::vector< uint8_t > CreateMuSig2Nonce(MuSig2SecNonce &secnonce, const uint256 &sighash, const CKey &our_seckey, const CPubKey &aggregate_pubkey, const std::vector< CPubKey > &pubkeys)
Definition: musig.cpp:135
CExtPubKey CreateMuSig2SyntheticXpub(const CPubKey &pubkey)
Construct the BIP 328 synthetic xpub for a pubkey.
Definition: musig.cpp:77
constexpr size_t MUSIG2_PUBNONCE_SIZE
Definition: musig.h:18
uint256 MuSig2SessionID(const CPubKey &script_pubkey, const CPubKey &part_pubkey, const uint256 &sighash)
Definition: musig.cpp:128
std::optional< uint256 > CreateMuSig2PartialSig(const uint256 &hash, const CKey &our_seckey, const CPubKey &aggregate_pubkey, const std::vector< CPubKey > &pubkeys, const std::map< CPubKey, std::vector< uint8_t > > &pubnonces, MuSig2SecNonce &secnonce, const std::vector< std::pair< uint256, bool > > &tweaks)
Definition: musig.cpp:168
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:257
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:60
Definition: common.h:30
This module implements BIP 327 "MuSig2 for BIP340-compatible Multi-Signatures" (https://github....
Opaque data structure that holds a signer's secret nonce.