13 std::vector<secp256k1_pubkey> secp_pubkeys;
14 std::vector<const secp256k1_pubkey*> pubkey_ptrs;
15 for (
const CPubKey& pubkey : pubkeys) {
20 pubkey_ptrs.reserve(secp_pubkeys.size());
22 pubkey_ptrs.push_back(&p);
44 return CPubKey(ser_agg_pubkey, ser_agg_pubkey + ser_agg_pubkey_len);
53 if (!agg_key.has_value())
return std::nullopt;
54 if (expected_aggregate.has_value() && expected_aggregate != agg_key)
return std::nullopt;
102 return m_impl->
Get();
107 return m_impl->Invalidate();
118 hasher << script_pubkey << part_pubkey << sighash;
122std::optional<std::vector<uint8_t>>
CreateMuSig2AggregateSig(
const std::vector<CPubKey>& part_pubkeys,
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)
124 if (!part_pubkeys.size())
return std::nullopt;
131 if (pubnonces.size() != part_pubkeys.size())
return std::nullopt;
132 if (partial_sigs.size() != part_pubkeys.size())
return std::nullopt;
135 std::vector<std::tuple<secp256k1_pubkey, secp256k1_musig_pubnonce, secp256k1_musig_partial_sig>> signers_data;
136 std::vector<const secp256k1_musig_pubnonce*> pubnonce_ptrs;
137 std::vector<const secp256k1_musig_partial_sig*> partial_sig_ptrs;
138 for (
const CPubKey& part_pk : part_pubkeys) {
139 const auto& pn_it = pubnonces.find(part_pk);
140 if (pn_it == pubnonces.end())
return std::nullopt;
141 const std::vector<uint8_t> pubnonce = pn_it->second;
143 const auto& it = partial_sigs.find(part_pk);
144 if (it == partial_sigs.end())
return std::nullopt;
145 const uint256& partial_sig = it->second;
147 auto& [secp_pk, secp_pn, secp_ps] = signers_data.emplace_back();
161 pubnonce_ptrs.reserve(signers_data.size());
162 partial_sig_ptrs.reserve(signers_data.size());
163 for (
auto& [
_, pn, ps] : signers_data) {
164 pubnonce_ptrs.push_back(&pn);
165 partial_sig_ptrs.push_back(&ps);
175 for (
const auto& [
tweak, xonly] : tweaks) {
192 for (
const auto& [
pk, pb, ps] : signers_data) {
199 std::vector<uint8_t> sig;
An encapsulated public key.
static constexpr unsigned int COMPRESSED_SIZE
A writer stream (for serialization) that computes a 256-bit hash.
uint256 GetSHA256()
Compute the SHA256 hash of all data written to this object.
MuSig2SecNonce encapsulates a secret nonce in use in a MuSig2 signing session.
secp256k1_musig_secnonce * Get() const
std::unique_ptr< MuSig2SecNonceImpl > m_impl
secp256k1_musig_secnonce * Get() const
MuSig2SecNonceImpl & operator=(const MuSig2SecNonceImpl &)=delete
secure_unique_ptr< secp256k1_musig_secnonce > m_nonce
The actual secnonce itself.
MuSig2SecNonceImpl(const MuSig2SecNonceImpl &)=delete
constexpr const unsigned char * data() const
static int tweak(const secp256k1_context *ctx, secp256k1_xonly_pubkey *agg_pk, secp256k1_musig_keyagg_cache *cache)
CExtPubKey CreateMuSig2SyntheticXpub(const CPubKey &pubkey)
Construct the BIP 328 synthetic xpub for a pubkey.
std::optional< std::vector< uint8_t > > CreateMuSig2AggregateSig(const std::vector< CPubKey > &part_pubkeys, 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)
uint256 MuSig2SessionID(const CPubKey &script_pubkey, const CPubKey &part_pubkey, const uint256 &sighash)
static std::optional< CPubKey > GetCPubKeyFromMuSig2KeyAggCache(secp256k1_musig_keyagg_cache &keyagg_cache)
static bool GetMuSig2KeyAggCache(const std::vector< CPubKey > &pubkeys, secp256k1_musig_keyagg_cache &keyagg_cache)
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.
constexpr size_t MUSIG2_PUBNONCE_SIZE
constexpr uint256 MUSIG_CHAINCODE
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize a pubkey object into a serialized byte sequence.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a variable-length public key into the pubkey object.
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize.
SECP256K1_API const secp256k1_context *const secp256k1_context_static
A built-in constant secp256k1 context object with static storage duration, to be used in conjunction ...
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_pubkey_ec_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *output_pubkey, secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Apply plain "EC" tweaking to a public key in a given keyagg_cache by adding the generator multiplied ...
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_pubkey_xonly_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *output_pubkey, secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Apply x-only tweaking to a public key in a given keyagg_cache by adding the generator multiplied with...
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_partial_sig_parse(const secp256k1_context *ctx, secp256k1_musig_partial_sig *sig, const unsigned char *in32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a MuSig partial signature.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_pubnonce_parse(const secp256k1_context *ctx, secp256k1_musig_pubnonce *nonce, const unsigned char *in66) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a signer's public nonce.
SECP256K1_API int secp256k1_musig_nonce_agg(const secp256k1_context *ctx, secp256k1_musig_aggnonce *aggnonce, const secp256k1_musig_pubnonce *const *pubnonces, size_t n_pubnonces) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Aggregates the nonces of all signers into a single nonce.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_pubkey_get(const secp256k1_context *ctx, secp256k1_pubkey *agg_pk, const secp256k1_musig_keyagg_cache *keyagg_cache) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Obtain the aggregate public key from a keyagg_cache.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_partial_sig_verify(const secp256k1_context *ctx, const secp256k1_musig_partial_sig *partial_sig, const secp256k1_musig_pubnonce *pubnonce, const secp256k1_pubkey *pubkey, const secp256k1_musig_keyagg_cache *keyagg_cache, const secp256k1_musig_session *session) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6)
Verifies an individual signer's partial signature.
SECP256K1_API int secp256k1_musig_partial_sig_agg(const secp256k1_context *ctx, unsigned char *sig64, const secp256k1_musig_session *session, const secp256k1_musig_partial_sig *const *partial_sigs, size_t n_sigs) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Aggregates partial signatures.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_pubkey_agg(const secp256k1_context *ctx, secp256k1_xonly_pubkey *agg_pk, secp256k1_musig_keyagg_cache *keyagg_cache, const secp256k1_pubkey *const *pubkeys, size_t n_pubkeys) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(4)
Computes an aggregate public key and uses it to initialize a keyagg_cache.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_nonce_process(const secp256k1_context *ctx, secp256k1_musig_session *session, const secp256k1_musig_aggnonce *aggnonce, const unsigned char *msg32, const secp256k1_musig_keyagg_cache *keyagg_cache) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5)
Takes the aggregate nonce and creates a session that is required for signing and verification of part...
secure_unique_ptr< T > make_secure_unique(Args &&... as)
std::unique_ptr< T, SecureUniqueDeleter< T > > secure_unique_ptr
unsigned char vchFingerprint[4]
Opaque data structure that holds an aggregate public nonce.
This module implements BIP 327 "MuSig2 for BIP340-compatible Multi-Signatures" (https://github....
Opaque data structure that holds a signer's secret nonce.
Opaque data structure that holds a MuSig session.
Opaque data structure that holds a parsed and valid public key.
consteval auto _(util::TranslatedLiteral str)