5#include <boost/test/unit_test.hpp>
19struct BIP328TestVector {
20 std::vector<std::string> pubkeys;
21 std::string expected_aggregate_pubkey;
22 std::string expected_aggregate_xpub;
30 std::vector<BIP328TestVector> test_vectors = {
34 "03935F972DA013F80AE011890FA89B67A27B7BE6CCB24D3274D18B2D4067F261A9",
35 "02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9"
37 .expected_aggregate_pubkey =
"0354240c76b8f2999143301a99c7f721ee57eee0bce401df3afeaa9ae218c70f23",
38 .expected_aggregate_xpub =
"xpub661MyMwAqRbcFt6tk3uaczE1y6EvM1TqXvawXcYmFEWijEM4PDBnuCXwwXEKGEouzXE6QLLRxjatMcLLzJ5LV5Nib1BN7vJg6yp45yHHRbm"
43 "02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9",
44 "03DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659",
45 "023590A94E768F8E1815C2F24B4D80A8E3149316C3518CE7B7AD338368D038CA66"
47 .expected_aggregate_pubkey =
"0290539eede565f5d054f32cc0c220126889ed1e5d193baf15aef344fe59d4610c",
48 .expected_aggregate_xpub =
"xpub661MyMwAqRbcFt6tk3uaczE1y6EvM1TqXvawXcYmFEWijEM4PDBnuCXwwVk5TFJk8Tw5WAdV3DhrGfbFA216sE9BsQQiSFTdudkETnKdg8k"
53 "02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659",
54 "023590A94E768F8E1815C2F24B4D80A8E3149316C3518CE7B7AD338368D038CA66",
55 "02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9",
56 "03935F972DA013F80AE011890FA89B67A27B7BE6CCB24D3274D18B2D4067F261A9"
58 .expected_aggregate_pubkey =
"022479f134cdb266141dab1a023cbba30a870f8995b95a91fc8464e56a7d41f8ea",
59 .expected_aggregate_xpub =
"xpub661MyMwAqRbcFt6tk3uaczE1y6EvM1TqXvawXcYmFEWijEM4PDBnuCXwwUvaZYpysLX4wN59tjwU5pBuDjNrPEJbfxjLwn7ruzbXTcUTHkZ"
64 for (
int i = 0; i < (int) test_vectors.size(); ++i) {
65 const auto& test = test_vectors[i];
68 std::vector<CPubKey> pubkeys;
69 for (
const auto& hex_pubkey : test.pubkeys) {
72 pubkeys.push_back(pubkey);
77 BOOST_CHECK_MESSAGE(m_aggregate_pubkey.has_value(),
"Test vector " << i <<
": Failed to aggregate pubkeys");
80 std::string combined_keys =
HexStr(m_aggregate_pubkey.value());
81 BOOST_CHECK_MESSAGE(combined_keys == test.expected_aggregate_pubkey,
"Test vector " << i <<
": Aggregate pubkey mismatch");
88 BOOST_CHECK_MESSAGE(xpub == test.expected_aggregate_xpub,
"Test vector " << i <<
": Synthetic xpub mismatch");
94 std::vector<std::string> test_vectors = {
95 "00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
96 "02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659"
100 std::vector<CPubKey> pubkeys;
101 for (
const auto& hex_pubkey : test_vectors) {
104 pubkeys.push_back(pubkey);
109 BOOST_CHECK_MESSAGE(!m_aggregate_pubkey.has_value(),
"Aggregate key with an invalid public key is null");
An encapsulated public key.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
BOOST_AUTO_TEST_CASE(ipc_tests)
std::string EncodeExtPubKey(const CExtPubKey &key)
CExtPubKey CreateMuSig2SyntheticXpub(const CPubKey &pubkey)
Construct the BIP 328 synthetic xpub for a pubkey.
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.
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.