diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4eb828a4fd7..2e0456d5453d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -176,6 +176,7 @@ if(ENABLE_WALLET) bitcoin_wallet bitcoin_common bitcoin_util + univalue ) install_binary_component(bitcoin-wallet HAS_MANPAGE) endif() diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index ade6d292206f..3c7b8214a1c7 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -41,11 +41,17 @@ static void SetupWalletToolArgs(ArgsManager& argsman) argsman.AddArg("-dumpfile=", "When used with 'dump', writes out the records to this file. When used with 'createfromdump', loads the records into a new wallet.", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::COMMAND_OPTIONS); argsman.AddArg("-debug=", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); + argsman.AddArg("-pubkey=", "Extended public key (xpub/tpub) for decrypting a backup. Optional when -wallet is provided: candidate keys are then derived from the wallet's own keys at the backup's derivation path hints and the common derivation paths.", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::COMMAND_OPTIONS); + argsman.AddArg("-xpub=", "Extended public key (xpub/tpub) whose derivation path to include in backup header. Common derivation paths, which recovery implementations try automatically, are omitted.", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::COMMAND_OPTIONS); + argsman.AddArg("-compact", "Use compact descriptor backup content for encryptbackup and skip decoy secrets, minimizing the backup size. When importing decrypted compact descriptors, use timestamp \"now\" to avoid an automatic rescan, then call rescanblockchain after import.", ArgsManager::ALLOW_ANY, OptionsCategory::COMMAND_OPTIONS); argsman.AddCommand("info", "Get wallet info"); argsman.AddCommand("create", "Create a new descriptor wallet file"); argsman.AddCommand("dump", "Print out all of the wallet key-value records", {"-dumpfile"}); argsman.AddCommand("createfromdump", "Create new wallet file from dumped records", {"-dumpfile"}); + argsman.AddCommand("encryptbackup", "Create an encrypted backup of wallet descriptors (outputs base64)", {"-xpub", "-compact"}); + argsman.AddCommand("decryptbackup", "Decrypt an encrypted backup (reads base64 from stdin, requires -pubkey and/or -wallet; imports descriptors when -wallet is provided)", {"-pubkey"}); + argsman.AddCommand("inspectbackup", "Show unencrypted metadata from a backup (reads base64 from stdin)"); } static std::optional WalletAppInit(ArgsManager& args, int argc, char* argv[]) diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp index f9415458f394..c85f950b86b1 100644 --- a/src/dummywallet.cpp +++ b/src/dummywallet.cpp @@ -6,12 +6,16 @@ #include #include +#include +#include + class ArgsManager; namespace interfaces { class Chain; class Handler; class Wallet; +class WalletBackup; class WalletLoader; } @@ -62,4 +66,9 @@ std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args) throw std::logic_error("Wallet function called in non-wallet build."); } +std::unique_ptr MakeWalletBackup() +{ + throw std::logic_error("Wallet function called in non-wallet build."); +} + } // namespace interfaces diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index 032468139e3a..2a1504a56cb0 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -91,6 +91,9 @@ class Wallet //! Back up wallet. virtual bool backupWallet(const std::string& filename) = 0; + //! Create an encrypted backup of public wallet descriptors. + virtual util::Result createEncryptedDescriptorBackup(const std::optional& target_xpub, bool compact) = 0; + //! Get wallet name. virtual std::string getWalletName() = 0; @@ -318,6 +321,30 @@ class Wallet virtual util::Result exportWatchOnlyWallet(const fs::path& destination) = 0; }; +//! Metadata for an encrypted descriptor backup. +struct EncryptedDescriptorBackupMetadata +{ + int version{0}; + //! Number of individual secrets in the backup. May include decoys, so + //! this is an upper bound on the number of recipients, not their count. + size_t individual_secret_count{0}; + std::string encryption; + std::vector derivation_paths; +}; + +//! Interface for encrypted wallet backup utility operations. +class WalletBackup +{ +public: + virtual ~WalletBackup() = default; + + //! Decrypt an encrypted descriptor backup with an extended public key. + virtual util::Result> decryptEncryptedDescriptorBackup(const std::string& base64_str, const std::string& pubkey_str) = 0; + + //! Get metadata from an encrypted descriptor backup. + virtual util::Result getEncryptedDescriptorBackupMetadata(const std::string& base64_str) = 0; +}; + //! Wallet chain client that in addition to having chain client methods for //! starting up, shutting down, and registering RPCs, also has additional //! methods (called by the GUI) to load and create wallets. @@ -449,6 +476,10 @@ struct WalletMigrationResult //! dummywallet.cpp and throws if the wallet component is not compiled. std::unique_ptr MakeWallet(wallet::WalletContext& context, const std::shared_ptr& wallet); +//! Return implementation of WalletBackup interface. This function is defined in +//! dummywallet.cpp and throws if the wallet component is not compiled. +std::unique_ptr MakeWalletBackup(); + //! Return implementation of ChainClient interface for a wallet loader. This //! function will be undefined in builds where ENABLE_WALLET is false. std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args); diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 44d8763351ef..c8e509db95bf 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -265,6 +265,21 @@ struct PubkeyProvider virtual std::optional GetRootPubKey() const = 0; /** Return the extended public key for this PubkeyProvider, if it has one. */ virtual std::optional GetRootExtPubKey() const = 0; + /** Whether this PubkeyProvider is a bare xpub with no derivation. */ + virtual bool IsBareExtPubKey() const { return false; } + /** Add the extended public key represented by this provider, if any. + * + * @param[out] ext_pubs Any extended public keys + * @param[in] exclude_observable Whether to exclude xpubs that may be observable from spends + */ + virtual void GetExtPubKeys(std::set& ext_pubs, bool exclude_observable) const + { + // A bare xpub has no derivation boundary separating the descriptor key from the + // pubkey revealed by a spend, unlike xpub/path or xpub/* entries. + if (exclude_observable && IsBareExtPubKey()) return; + std::optional ext_pub = GetRootExtPubKey(); + if (ext_pub) ext_pubs.insert(*ext_pub); + } /** Make a deep copy of this PubkeyProvider */ virtual std::unique_ptr Clone() const = 0; @@ -370,6 +385,10 @@ class OriginPubkeyProvider final : public PubkeyProvider { return m_provider->GetRootExtPubKey(); } + bool IsBareExtPubKey() const override + { + return m_provider->IsBareExtPubKey(); + } std::unique_ptr Clone() const override { return std::make_unique(m_expr_index, m_origin, m_provider->Clone(), m_apostrophe); @@ -655,6 +674,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider { return m_root_extkey; } + bool IsBareExtPubKey() const override { return m_path.empty() && !IsRange(); } std::unique_ptr Clone() const override { return std::make_unique(m_expr_index, m_root_extkey, m_path, m_derive, m_apostrophe); @@ -849,6 +869,19 @@ class MuSigPubkeyProvider final : public PubkeyProvider { return std::nullopt; } + void GetExtPubKeys(std::set& ext_pubs, bool exclude_observable) const override + { + if (!exclude_observable) { + PubkeyProvider::GetExtPubKeys(ext_pubs, exclude_observable); + return; + } + // MuSig's participant xpubs are not descriptor root keys, so GetPubKeys() intentionally + // omits them. Recurse into participants for backup key discovery, where the aggregate key + // revealed by a spend does not reveal the participant xpubs. + for (const auto& prov : m_participants) { + prov->GetExtPubKeys(ext_pubs, /*exclude_observable=*/false); + } + } std::unique_ptr Clone() const override { @@ -1114,16 +1147,27 @@ class DescriptorImpl : public Descriptor std::optional MaxSatisfactionElems() const override { return {}; } // NOLINTNEXTLINE(misc-no-recursion) - void GetPubKeys(std::set& pubkeys, std::set& ext_pubs) const override + void GetPubKeys(std::set& pubkeys, std::set& ext_pubs, bool only_observable) const override { for (const auto& p : m_pubkey_args) { std::optional pub = p->GetRootPubKey(); if (pub) pubkeys.insert(*pub); std::optional ext_pub = p->GetRootExtPubKey(); - if (ext_pub) ext_pubs.insert(*ext_pub); + if (ext_pub && (!only_observable || p->IsBareExtPubKey())) ext_pubs.insert(*ext_pub); + } + for (const auto& arg : m_subdescriptor_args) { + arg->GetPubKeys(pubkeys, ext_pubs, only_observable); + } + } + + // NOLINTNEXTLINE(misc-no-recursion) + void GetExtPubKeys(std::set& ext_pubs, bool exclude_observable) const override + { + for (const auto& p : m_pubkey_args) { + p->GetExtPubKeys(ext_pubs, exclude_observable); } for (const auto& arg : m_subdescriptor_args) { - arg->GetPubKeys(pubkeys, ext_pubs); + arg->GetExtPubKeys(ext_pubs, exclude_observable); } } diff --git a/src/script/descriptor.h b/src/script/descriptor.h index b7dffeab9977..9cd99e85e31a 100644 --- a/src/script/descriptor.h +++ b/src/script/descriptor.h @@ -195,8 +195,16 @@ struct Descriptor { * * @param[out] pubkeys Any public keys * @param[out] ext_pubs Any extended public keys + * @param[in] only_observable Only return literal pubkeys and bare xpubs outside MuSig aggregates */ - virtual void GetPubKeys(std::set& pubkeys, std::set& ext_pubs) const = 0; + virtual void GetPubKeys(std::set& pubkeys, std::set& ext_pubs, bool only_observable = false) const = 0; + + /** Return all extended public keys for this descriptor, including any from subdescriptors. + * + * @param[out] ext_pubs Any extended public keys + * @param[in] exclude_observable Whether to exclude xpubs that may be observable from spends + */ + virtual void GetExtPubKeys(std::set& ext_pubs, bool exclude_observable = false) const = 0; /** Whether this descriptor produces any scripts with the Expand functions */ virtual bool HasScripts() const = 0; diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 00a2161aa4a1..35656a556829 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -132,6 +132,7 @@ add_executable(test_bitcoin util_not_null_tests.cpp util_expected_tests.cpp util_string_tests.cpp + utf8_tests.cpp util_tests.cpp util_threadnames_tests.cpp util_trace_tests.cpp @@ -148,6 +149,15 @@ include(TargetDataSources) target_json_data_sources(test_bitcoin data/base58_encode_decode.json data/bip341_wallet_vectors.json + data/bip138_recipient_keys.json + data/bip138_encryption_secret.json + data/bip138_derivation_path.json + data/bip138_individual_secrets.json + data/bip138_content_type.json + data/bip138_payload.json + data/bip138_encrypted_backup.json + data/bip138_chacha20poly1305_encryption.json + data/bip138_bip380_descriptor_backup.json data/bip352_send_and_receive_vectors.json data/blockfilters.json data/key_io_invalid.json @@ -160,6 +170,7 @@ target_json_data_sources(test_bitcoin ) target_raw_data_sources(test_bitcoin NAMESPACE test::data data/asmap.raw + data/bip138_bip380_descriptor_backup.txt ) add_windows_application_manifest(test_bitcoin) diff --git a/src/test/data/bip138_bip380_descriptor_backup.json b/src/test/data/bip138_bip380_descriptor_backup.json new file mode 100644 index 000000000000..3066c8b392dd --- /dev/null +++ b/src/test/data/bip138_bip380_descriptor_backup.json @@ -0,0 +1,45 @@ +[ + { + "description": "Descriptor with change descriptor", + "valid": true, + "document": { + "version": 1, + "descriptor_sets": [ + { + "archived": false, + "birth_time": 1710000000, + "range": [0, 999], + "descriptor": "wpkh([d34db33f/84h/1h/0h]tpubDC5FSnBiZDMmhiuCmWAYsLwgLYrrT9rAqvTySfuCCrgsWz8wxMXUS9Tb9iVMvcRbvFcAHGkMD5Kx8koh4GquNGNTfohfk7pgjhaPCdXpoba/0/*)", + "change_descriptor": "wpkh([d34db33f/84h/1h/0h]tpubDC5FSnBiZDMmhiuCmWAYsLwgLYrrT9rAqvTySfuCCrgsWz8wxMXUS9Tb9iVMvcRbvFcAHGkMD5Kx8koh4GquNGNTfohfk7pgjhaPCdXpoba/1/*)" + } + ] + } + }, + { + "description": "BIP389 multipath descriptor", + "valid": true, + "document": { + "version": 1, + "descriptor_sets": [ + { + "archived": false, + "birth_time": 1710000000, + "range": [0, 999], + "descriptor": "wpkh([d34db33f/84h/1h/0h]tpubDC5FSnBiZDMmhiuCmWAYsLwgLYrrT9rAqvTySfuCCrgsWz8wxMXUS9Tb9iVMvcRbvFcAHGkMD5Kx8koh4GquNGNTfohfk7pgjhaPCdXpoba/<0;1>/*)" + } + ] + } + }, + { + "description": "Receive-only descriptor set without optional metadata", + "valid": true, + "document": { + "version": 1, + "descriptor_sets": [ + { + "descriptor": "wpkh([d34db33f/84h/1h/0h]tpubDC5FSnBiZDMmhiuCmWAYsLwgLYrrT9rAqvTySfuCCrgsWz8wxMXUS9Tb9iVMvcRbvFcAHGkMD5Kx8koh4GquNGNTfohfk7pgjhaPCdXpoba/0/*)" + } + ] + } + } +] diff --git a/src/test/data/bip138_bip380_descriptor_backup.txt b/src/test/data/bip138_bip380_descriptor_backup.txt new file mode 100644 index 000000000000..4ce5adaa08aa --- /dev/null +++ b/src/test/data/bip138_bip380_descriptor_backup.txt @@ -0,0 +1,2 @@ +# BIP380 descriptor backup text vector +wpkh([d34db33f/84h/1h/0h]tpubDC5FSnBiZDMmhiuCmWAYsLwgLYrrT9rAqvTySfuCCrgsWz8wxMXUS9Tb9iVMvcRbvFcAHGkMD5Kx8koh4GquNGNTfohfk7pgjhaPCdXpoba/<0;1>/*) diff --git a/src/test/data/bip138_chacha20poly1305_encryption.json b/src/test/data/bip138_chacha20poly1305_encryption.json new file mode 100644 index 000000000000..08c752d2ac5c --- /dev/null +++ b/src/test/data/bip138_chacha20poly1305_encryption.json @@ -0,0 +1,37 @@ +[ + { + "description": "Basic encryption with short plaintext", + "nonce": "000102030405060708090a0b", + "plaintext": "48656c6c6f", + "secret": "0000000000000000000000000000000000000000000000000000000000000000", + "ciphertext": "7df9cb9a0ac5851cc054b14d05f781127b2b0d31fa" + }, + { + "description": "Empty plaintext should fail", + "nonce": "000102030405060708090a0b", + "plaintext": "", + "secret": "0000000000000000000000000000000000000000000000000000000000000000", + "ciphertext": null + }, + { + "description": "Encryption with zeroed nonce should fail", + "nonce": "000000000000000000000000", + "plaintext": "00000000000000000000000000000000", + "secret": "0000000000000000000000000000000000000000000000000000000000000000", + "ciphertext": null + }, + { + "description": "Encryption with all FFs", + "nonce": "ffffffffffffffffffffffff", + "plaintext": "ffffffffffffffffffffffffffffffff", + "secret": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "ciphertext": "22d8bfc313e141bd692c82cec7785b29a0e5d5014c0d3b2d3a8b00548cd8d221" + }, + { + "description": "Longer plaintext", + "nonce": "0f1e2d3c4b5a69788796a5b4", + "plaintext": "546869732069732061206c6f6e67657220706c61696e746578742074686174207368756c6420626520656e637279707465642070726f7065726c792e", + "secret": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", + "ciphertext": "2af094190e2b43a02b8dd6bfc25a8833f84f81bc6f690d75f0214e466ef392616c4644bee65118c444a926e1e365b3a7ba0509a5636524eb4e5722f5926938f32e4df79237acb6dd4a6ccbc4" + } +] diff --git a/src/test/data/bip138_content_type.json b/src/test/data/bip138_content_type.json new file mode 100644 index 000000000000..110d9f676a13 --- /dev/null +++ b/src/test/data/bip138_content_type.json @@ -0,0 +1,82 @@ +[ + { + "description": "Bip 138", + "valid": true, + "content": "01008a" + }, + { + "description": "Bip 380", + "valid": true, + "content": "01017c" + }, + { + "description": "Bip 388", + "valid": true, + "content": "010184" + }, + { + "description": "Bip 329", + "valid": true, + "content": "010149" + }, + { + "description": "Bip 999", + "valid": true, + "content": "0103e7" + }, + { + "description": "Bip max", + "valid": true, + "content": "01ffff" + }, + { + "description": "Bip min", + "valid": true, + "content": "010000" + }, + { + "description": "Propietary 00010203", + "valid": true, + "content": "020400010203" + }, + { + "description": "String", + "valid": true, + "content": "0300" + }, + { + "description": "TYPE 0x00 ends the content items", + "valid": false, + "content": "00" + }, + { + "description": "Invalid BIP (insufficient bytes)", + "valid": false, + "content": "0100" + }, + { + "description": "Invalid proprietary (missing data)", + "valid": false, + "content": "0201" + }, + { + "description": "Invalid proprietary (TYPE_LENGTH exceeds payload)", + "valid": false, + "content": "020500" + }, + { + "description": "Invalid string (metadata must be empty)", + "valid": false, + "content": "030161" + }, + { + "description": "TYPE >= 0x80 stops parsing", + "valid": false, + "content": "ff" + }, + { + "description": "TYPE >= 0x80 stops parsing", + "valid": false, + "content": "ff000000" + } +] diff --git a/src/test/data/bip138_derivation_path.json b/src/test/data/bip138_derivation_path.json new file mode 100644 index 000000000000..103492444a12 --- /dev/null +++ b/src/test/data/bip138_derivation_path.json @@ -0,0 +1,186 @@ +[ + { + "description": "Empty derivation paths", + "paths": [], + "expected": "00" + }, + { + "description": "Single path with one child: m/0", + "paths": ["m/0"], + "expected": "010100000000" + }, + { + "description": "Single path with hardened child: m/44'", + "paths": ["m/44'"], + "expected": "01018000002c" + }, + { + "description": "Standard BIP-84 path: m/84'/0'/0'", + "paths": ["m/84'/0'/0'"], + "expected": "0103800000548000000080000000" + }, + { + "description": "Mixed hardened and normal: m/0/1'/2/3'", + "paths": ["m/0/1'/2/3'"], + "expected": "010400000000800000010000000280000003" + }, + { + "description": "Multiple paths: m/0/1'/2/3' and m/84'/0'/0'/2'", + "paths": ["m/0/1'/2/3'", "m/84'/0'/0'/2'"], + "expected": "0204000000008000000100000002800000030480000054800000008000000080000002" + }, + { + "description": "Path with large indices: m/2147483647'/2147483646", + "paths": ["m/2147483647'/2147483646"], + "expected": "0102ffffffff7ffffffe" + }, + { + "description": "Single child path: m/1", + "paths": ["m/1"], + "expected": "010100000001" + }, + { + "description": "Path with max normal index: m/2147483647", + "paths": ["m/2147483647"], + "expected": "01017fffffff" + }, + { + "description": "Path with multiple normal indices: m/0/1/2/3/4", + "paths": ["m/0/1/2/3/4"], + "expected": "01050000000000000001000000020000000300000004" + }, + { + "description": "Path with all hardened: m/0'/1'/2'", + "paths": ["m/0'/1'/2'"], + "expected": "0103800000008000000180000002" + }, + { + "description": "Two different single-child paths: m/0 and m/1", + "paths": ["m/0", "m/1"], + "expected": "0201000000000100000001" + }, + { + "description": "Unsorted paths are sorted when encoded", + "paths": ["m/84'/0'/0'/2'", "m/0/1'/2/3'"], + "expected": "0204000000008000000100000002800000030480000054800000008000000080000002" + }, + { + "description": "Duplicate paths are deduplicated", + "paths": ["m/1", "m/0", "m/1"], + "expected": "0201000000000100000001" + }, + { + "description": "BIP-44 account 0: m/44'/0'/0'", + "paths": ["m/44'/0'/0'"], + "expected": "01038000002c8000000080000000" + }, + { + "description": "BIP-49 account 0: m/49'/0'/0'", + "paths": ["m/49'/0'/0'"], + "expected": "0103800000318000000080000000" + }, + { + "description": "Common fallback path: m/49'/0'/9'", + "paths": ["m/49'/0'/9'"], + "expected": "0103800000318000000080000009" + }, + { + "description": "Common fallback path: m/84'/1'/9'", + "paths": ["m/84'/1'/9'"], + "expected": "0103800000548000000180000009" + }, + { + "description": "Common fallback path: m/86'/1'/9'", + "paths": ["m/86'/1'/9'"], + "expected": "0103800000568000000180000009" + }, + { + "description": "Fallible fallback path: m/87'/1'/9'", + "paths": ["m/87'/1'/9'"], + "expected": "0103800000578000000180000009" + }, + { + "description": "Common fallback path: m/48'/0'/9'/1'", + "paths": ["m/48'/0'/9'/1'"], + "expected": "010480000030800000008000000980000001" + }, + { + "description": "Common fallback path: m/48'/1'/9'/2'", + "paths": ["m/48'/1'/9'/2'"], + "expected": "010480000030800000018000000980000002" + }, + { + "description": "Single path with 255 children (maximum depth, success)", + "paths": ["m/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0"], + "expected": "01ff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + }, + { + "description": "256 paths should fail (exceeds u8::MAX)", + "paths": [ + "m/0", "m/1", "m/2", "m/3", "m/4", "m/5", "m/6", "m/7", "m/8", "m/9", + "m/10", "m/11", "m/12", "m/13", "m/14", "m/15", "m/16", "m/17", "m/18", "m/19", + "m/20", "m/21", "m/22", "m/23", "m/24", "m/25", "m/26", "m/27", "m/28", "m/29", + "m/30", "m/31", "m/32", "m/33", "m/34", "m/35", "m/36", "m/37", "m/38", "m/39", + "m/40", "m/41", "m/42", "m/43", "m/44", "m/45", "m/46", "m/47", "m/48", "m/49", + "m/50", "m/51", "m/52", "m/53", "m/54", "m/55", "m/56", "m/57", "m/58", "m/59", + "m/60", "m/61", "m/62", "m/63", "m/64", "m/65", "m/66", "m/67", "m/68", "m/69", + "m/70", "m/71", "m/72", "m/73", "m/74", "m/75", "m/76", "m/77", "m/78", "m/79", + "m/80", "m/81", "m/82", "m/83", "m/84", "m/85", "m/86", "m/87", "m/88", "m/89", + "m/90", "m/91", "m/92", "m/93", "m/94", "m/95", "m/96", "m/97", "m/98", "m/99", + "m/100", "m/101", "m/102", "m/103", "m/104", "m/105", "m/106", "m/107", "m/108", "m/109", + "m/110", "m/111", "m/112", "m/113", "m/114", "m/115", "m/116", "m/117", "m/118", "m/119", + "m/120", "m/121", "m/122", "m/123", "m/124", "m/125", "m/126", "m/127", "m/128", "m/129", + "m/130", "m/131", "m/132", "m/133", "m/134", "m/135", "m/136", "m/137", "m/138", "m/139", + "m/140", "m/141", "m/142", "m/143", "m/144", "m/145", "m/146", "m/147", "m/148", "m/149", + "m/150", "m/151", "m/152", "m/153", "m/154", "m/155", "m/156", "m/157", "m/158", "m/159", + "m/160", "m/161", "m/162", "m/163", "m/164", "m/165", "m/166", "m/167", "m/168", "m/169", + "m/170", "m/171", "m/172", "m/173", "m/174", "m/175", "m/176", "m/177", "m/178", "m/179", + "m/180", "m/181", "m/182", "m/183", "m/184", "m/185", "m/186", "m/187", "m/188", "m/189", + "m/190", "m/191", "m/192", "m/193", "m/194", "m/195", "m/196", "m/197", "m/198", "m/199", + "m/200", "m/201", "m/202", "m/203", "m/204", "m/205", "m/206", "m/207", "m/208", "m/209", + "m/210", "m/211", "m/212", "m/213", "m/214", "m/215", "m/216", "m/217", "m/218", "m/219", + "m/220", "m/221", "m/222", "m/223", "m/224", "m/225", "m/226", "m/227", "m/228", "m/229", + "m/230", "m/231", "m/232", "m/233", "m/234", "m/235", "m/236", "m/237", "m/238", "m/239", + "m/240", "m/241", "m/242", "m/243", "m/244", "m/245", "m/246", "m/247", "m/248", "m/249", + "m/250", "m/251", "m/252", "m/253", "m/254", "m/255" + ], + "expected": null + }, + { + "description": "Path with 256 children should fail (exceeds u8::MAX)", + "paths": ["m/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0"], + "expected": null + }, + { + "description": "255 paths should succeed (maximum allowed)", + "paths": [ + "m/0", "m/1", "m/2", "m/3", "m/4", "m/5", "m/6", "m/7", "m/8", "m/9", + "m/10", "m/11", "m/12", "m/13", "m/14", "m/15", "m/16", "m/17", "m/18", "m/19", + "m/20", "m/21", "m/22", "m/23", "m/24", "m/25", "m/26", "m/27", "m/28", "m/29", + "m/30", "m/31", "m/32", "m/33", "m/34", "m/35", "m/36", "m/37", "m/38", "m/39", + "m/40", "m/41", "m/42", "m/43", "m/44", "m/45", "m/46", "m/47", "m/48", "m/49", + "m/50", "m/51", "m/52", "m/53", "m/54", "m/55", "m/56", "m/57", "m/58", "m/59", + "m/60", "m/61", "m/62", "m/63", "m/64", "m/65", "m/66", "m/67", "m/68", "m/69", + "m/70", "m/71", "m/72", "m/73", "m/74", "m/75", "m/76", "m/77", "m/78", "m/79", + "m/80", "m/81", "m/82", "m/83", "m/84", "m/85", "m/86", "m/87", "m/88", "m/89", + "m/90", "m/91", "m/92", "m/93", "m/94", "m/95", "m/96", "m/97", "m/98", "m/99", + "m/100", "m/101", "m/102", "m/103", "m/104", "m/105", "m/106", "m/107", "m/108", "m/109", + "m/110", "m/111", "m/112", "m/113", "m/114", "m/115", "m/116", "m/117", "m/118", "m/119", + "m/120", "m/121", "m/122", "m/123", "m/124", "m/125", "m/126", "m/127", "m/128", "m/129", + "m/130", "m/131", "m/132", "m/133", "m/134", "m/135", "m/136", "m/137", "m/138", "m/139", + "m/140", "m/141", "m/142", "m/143", "m/144", "m/145", "m/146", "m/147", "m/148", "m/149", + "m/150", "m/151", "m/152", "m/153", "m/154", "m/155", "m/156", "m/157", "m/158", "m/159", + "m/160", "m/161", "m/162", "m/163", "m/164", "m/165", "m/166", "m/167", "m/168", "m/169", + "m/170", "m/171", "m/172", "m/173", "m/174", "m/175", "m/176", "m/177", "m/178", "m/179", + "m/180", "m/181", "m/182", "m/183", "m/184", "m/185", "m/186", "m/187", "m/188", "m/189", + "m/190", "m/191", "m/192", "m/193", "m/194", "m/195", "m/196", "m/197", "m/198", "m/199", + "m/200", "m/201", "m/202", "m/203", "m/204", "m/205", "m/206", "m/207", "m/208", "m/209", + "m/210", "m/211", "m/212", "m/213", "m/214", "m/215", "m/216", "m/217", "m/218", "m/219", + "m/220", "m/221", "m/222", "m/223", "m/224", "m/225", "m/226", "m/227", "m/228", "m/229", + "m/230", "m/231", "m/232", "m/233", "m/234", "m/235", "m/236", "m/237", "m/238", "m/239", + "m/240", "m/241", "m/242", "m/243", "m/244", "m/245", "m/246", "m/247", "m/248", "m/249", + "m/250", "m/251", "m/252", "m/253", "m/254" + ], + "expected": "ff0100000000010000000101000000020100000003010000000401000000050100000006010000000701000000080100000009010000000a010000000b010000000c010000000d010000000e010000000f0100000010010000001101000000120100000013010000001401000000150100000016010000001701000000180100000019010000001a010000001b010000001c010000001d010000001e010000001f0100000020010000002101000000220100000023010000002401000000250100000026010000002701000000280100000029010000002a010000002b010000002c010000002d010000002e010000002f0100000030010000003101000000320100000033010000003401000000350100000036010000003701000000380100000039010000003a010000003b010000003c010000003d010000003e010000003f0100000040010000004101000000420100000043010000004401000000450100000046010000004701000000480100000049010000004a010000004b010000004c010000004d010000004e010000004f0100000050010000005101000000520100000053010000005401000000550100000056010000005701000000580100000059010000005a010000005b010000005c010000005d010000005e010000005f0100000060010000006101000000620100000063010000006401000000650100000066010000006701000000680100000069010000006a010000006b010000006c010000006d010000006e010000006f0100000070010000007101000000720100000073010000007401000000750100000076010000007701000000780100000079010000007a010000007b010000007c010000007d010000007e010000007f0100000080010000008101000000820100000083010000008401000000850100000086010000008701000000880100000089010000008a010000008b010000008c010000008d010000008e010000008f0100000090010000009101000000920100000093010000009401000000950100000096010000009701000000980100000099010000009a010000009b010000009c010000009d010000009e010000009f01000000a001000000a101000000a201000000a301000000a401000000a501000000a601000000a701000000a801000000a901000000aa01000000ab01000000ac01000000ad01000000ae01000000af01000000b001000000b101000000b201000000b301000000b401000000b501000000b601000000b701000000b801000000b901000000ba01000000bb01000000bc01000000bd01000000be01000000bf01000000c001000000c101000000c201000000c301000000c401000000c501000000c601000000c701000000c801000000c901000000ca01000000cb01000000cc01000000cd01000000ce01000000cf01000000d001000000d101000000d201000000d301000000d401000000d501000000d601000000d701000000d801000000d901000000da01000000db01000000dc01000000dd01000000de01000000df01000000e001000000e101000000e201000000e301000000e401000000e501000000e601000000e701000000e801000000e901000000ea01000000eb01000000ec01000000ed01000000ee01000000ef01000000f001000000f101000000f201000000f301000000f401000000f501000000f601000000f701000000f801000000f901000000fa01000000fb01000000fc01000000fd01000000fe" + } +] diff --git a/src/test/data/bip138_encrypted_backup.json b/src/test/data/bip138_encrypted_backup.json new file mode 100644 index 000000000000..f5ee9b672662 --- /dev/null +++ b/src/test/data/bip138_encrypted_backup.json @@ -0,0 +1,157 @@ +[ + { + "description": "Single key, no derivation paths, BIP380 content", + "version": 1, + "encryption": 1, + "content": "01017c", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443" + ], + "decoy_individual_secrets": [ + "0000000000000000000000000000000000000000000000000000000000000001", + "c000000000000000000000000000000000000000000000000000000000000000", + "c200000000000000000000000000000000000000000000000000000000000000", + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + ], + "derivation_paths": [], + "plaintext": "00", + "nonce": "a1b2c3d4e5f607080910a1b2", + "expected": "4249503133380100050000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000c14d5bfeb7f9709e996c6696959107d4c57d367d2aee207d5361f116e3c4708bc200000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01a1b2c3d4e5f607080910a1b216a42cdae8b34bb573f5cd678ef6a25c29a214abbf52de", + "trailing": "deadbeef00ff", + "expected_base64": "QklQMTM4AQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMFNW/63+XCemWxmlpWRB9TFfTZ9Ku4gfVNh8RbjxHCLwgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////////////////////////////////////////wGhssPU5fYHCAkQobIWpCza6LNLtXP1zWeO9qJcKaIUq79S3g==" + }, + { + "description": "Two keys, 1 derivation paths, BIP380 content", + "version": 1, + "encryption": 1, + "content": "01017c", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443", + "0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07" + ], + "decoy_individual_secrets": [ + "0000000000000000000000000000000000000000000000000000000000000001", + "c000000000000000000000000000000000000000000000000000000000000000", + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + ], + "derivation_paths": [ + "m/48'/1'/0'/2'" + ], + "plaintext": "wsh(or_d(pk([9d69155f/48'/1'/0'/2']tpubDDxT9mkZzWwkKwpGT5fY6iiM9muYTPkTx6Eig8dpHR7TChuGGCWYAHVmpW1ciido5RiFWwjzYsF1GZHkEHg2nrYp3zNtx3QQRkznyLhQ77x/<0;1>/*),and_v(v:pkh([9d69155f/48'/1'/0'/2']tpubDDxT9mkZzWwkKwpGT5fY6iiM9muYTPkTx6Eig8dpHR7TChuGGCWYAHVmpW1ciido5RiFWwjzYsF1GZHkEHg2nrYp3zNtx3QQRkznyLhQ77x/<2;3>/*),older(52596))))#gx5f42wh", + "nonce": "0102030405060708090a0b0c", + "expected": "4249503133380100050000000000000000000000000000000000000000000000000000000000000001b8c6ce74f81b0ffe7d7511824e75f95114f9b140e57bb570e5c5d807f0a5e96fb8e749fceb0dd84d20a75af4dbd6d585d89c54053f6313ac6592cbfe8c1bdd4fc000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff010102030405060708090a0b0cfd6601829ae3ce2f35059533a55d10fead962d645b08a53a6fad9da13e2aa270d4561f36602d92ba9af12ef4bb495fb8296a7f7ec1ddabef1d1b25cd7e93b8dc9d437dfcd282d24ab22aaa29292ceb463cb7560321cdcae6e537fafcbedbf59e75ccb15f3a930e132037b54d8bb9b675f5f979ed8c1e084b8d9e0216519bd8ab22825ab40868133ff0ec76b623d9341c51f96cbc97e61c753e4c12e5841b640fba3fc09864ac1b67f690447c6db5e960f2ca507cad5bfae71b2fef38cc0b68c34d7f956ca0cc59d54c2d53ff5a678b4e09ce5408f6ca723040ab42e889e77c6be3771fb38a0df881128466deaa8a84e3b7cbd0ddf4a000b03d63a8e2cf5f73310e1066d3b392dc45ad30bd664490641a6bd78d4008d44193b9ea3d9285029eaa309e80afff383dda3cff1df4df4b75a254eaaf8e0f0af86e90f40b78c9d98bd354eb6eb512b6b95d05d5f95c0ca56042cea52f76252d7f2e8a95ddc4e8bffe631b399a9d69ef80d56c", + "expected_base64": "QklQMTM4AQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAG4xs50+BsP/n11EYJOdflRFPmxQOV7tXDlxdgH8KXpb7jnSfzrDdhNIKda9NvW1YXYnFQFP2MTrGWSy/6MG91PwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////////////////////////////////////////wEBAgMEBQYHCAkKCwz9ZgGCmuPOLzUFlTOlXRD+rZYtZFsIpTpvrZ2hPiqicNRWHzZgLZK6mvEu9LtJX7gpan9+wd2r7x0bJc1+k7jcnUN9/NKC0kqyKqopKSzrRjy3VgMhzcrm5Tf6/L7b9Z51zLFfOpMOEyA3tU2LubZ19fl57YweCEuNngIWUZvYqyKCWrQIaBM/8Ox2tiPZNBxR+Wy8l+YcdT5MEuWEG2QPuj/AmGSsG2f2kER8bbXpYPLKUHytW/rnGy/vOMwLaMNNf5VsoMxZ1UwtU/9aZ4tOCc5UCPbKcjBAq0Loied8a+N3H7OKDfiBEoRm3qqKhOO3y9Dd9KAAsD1jqOLPX3MxDhBm07OS3EWtML1mRJBkGmvXjUAI1EGTueo9koUCnqownoCv/zg92jz/HfTfS3WiVOqvjg8K+G6Q9At4ydmL01TrbrUStrldBdX5XAylYELOpS92JS1/LoqV3cTov/5jGzmanWnvgNVs" + }, + { + "description": "Three keys, multiple derivation paths, BIP329 content", + "version": 1, + "encryption": 1, + "content": "010149", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443", + "0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07", + "03c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5" + ], + "decoy_individual_secrets": [ + "7000000000000000000000000000000000000000000000000000000000000000", + "8000000000000000000000000000000000000000000000000000000000000000" + ], + "derivation_paths": [ + "m/84'/0'/0'", + "m/0/1'/2/3'" + ], + "plaintext": "{\"type\":\"tx\",\"ref\":\"f91d0a8a78462bc59398f2c5d7a84fcff491c26ba54c4833478b202796c8aafd\",\"label\":\"Transaction\",\"origin\":\"wpkh([d34db33f/84'/0'/0'])\"}\n{\"type\":\"addr\",\"ref\":\"bc1q34aq5drpuwy3wgl9lhup9892qp6svr8ldzyy7c\",\"label\":\"Address\"}\n{\"type\":\"pubkey\",\"ref\":\"0283409659355b6d1cc3c32decd5d561abaac86c37a353b52895a5e6c196d6f448\",\"label\":\"Public Key\"}\n{\"type\":\"input\",\"ref\":\"f91d0a8a78462bc59398f2c5d7a84fcff491c26ba54c4833478b202796c8aafd:0\",\"label\":\"Input\"}\n{\"type\":\"output\",\"ref\":\"f91d0a8a78462bc59398f2c5d7a84fcff491c26ba54c4833478b202796c8aafd:1\",\"label\":\"Output\",\"spendable\":false}\n{\"type\":\"xpub\",\"ref\":\"xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8\",\"label\":\"Extended Public Key\"}\n{\"type\":\"tx\",\"ref\":\"f546156d9044844e02b181026a1a407abfca62e7ea1159f87bbeaa77b4286c74\",\"label\":\"Account #1 Transaction\",\"origin\":\"wpkh([d34db33f/84'/0'/1'])\"}", + "nonce": "deadbeefcafebabe12345678", + "expected": "4249503133380101040000000080000001000000028000000305281aff33e4b8186ac4176427b59ec3c72af96bf6ecd1ad7ed1d746103d078a17283b78bbf7aecfd999c52f51203def13e69c8eb336c90ba2518055e941b9be3770000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000f6353d50c714c43f7b86794ee21e3490af33468ef30217dd93003413e23b4c1701deadbeefcafebabe12345678fd9f032b5e117a385bfc3c88c2eae4e2e4aeeaaff5c5ced44579c77cb67fbb6c12bdc113c1e2c9bb1029ec47f589311030efe4aa3924958aa53b737d5fdf0fc2272037ba9260303a07010ceaf38e40aec5d28318968e833511bdc6d4ab99cb1e51153f0571fd6c0e08b58a8b75bdb91c7fb94b16872ac5800c981f06d3c28fdf71a9382c08c74d2d0ffe9e20774e6c8bec95cd6713ec60ff2fa54d50a507e84448d91ba5fcaa8dd17ad19dbb962e4514a127d795d8cf82ced19d242a9777a9bd6f714c3deec247530f74c055410e6b42ae98de71259103cf14f0d5719ae2900675841c010c1e6c076a9be2ddf271e3281184dc8759063a4c1be8f2e3a57e6557b76228bf13e5d1cf6fc8726d6429cad74c84fbb15046abb12fe7f6f6e3856016dae37fff0a161cb9da34e814976ccc9b03a587900eb36cbd56049cdc9680816fe9c4a14838fa2a999bf4ad7fe5efa7d31c7164886d6eafa18fe40185bcc982768d0a3ca05e3450979e4140cacd834f8e6399048b59e6ab025964c2afcf6119b614c56755e5e37b6425ea3926dd9b9fe4cd6e127d6006abdb38b393437cb26cd8ccbda13825c90b857deab2dbaf759b14ffb0692e448ecbba9a3cdbac7b7661be2a8cec5a0b9df3bbe1a67014653e159c41c3b36974563b8392731f3dec68c16e4a644bad4236208876aba0d00bdd3cefac04c31b1e1673b91d0010f8ebe7070c07f8b00effa79b8e94fb1b9285904114e37d4e2987d9246a300958a9fbf1c2af1016edcec7b9e0fca80935652c3426e837a9ce018615d1f1127da307daca4dc8bc201f44b09c0adb52859f49cc625a5ecd31bbe513ea5c97dfb8f192cffd60864acc4c1a0a4f630190cbf1e1fe8201d8b7b2b4da7e8813f56e1d885f57700289ee4661928540607be79221137c1a79b8b4ab6150f1c9c4c6ca2367a673d5f7faa2cbcdbc1fd68c45acb33e7344e55a431c03ad03fb4442bd01b8b51cce71c7779fa2f63120bed1ed30ff35969cc2cb049b598a473b670012bd155e6efcad815a83cd76ea06eef14867cef22998bf39debadd78fface8cb6cb9ee3f02636683d69458f6ace058f232ef1d1d547c0073a82ba507a006df40f69d2a247b485ee6010cfbb58bbc6f0423287f475df21c2e23533a1653c48aac55b7a64e489850477482a08924c984700d5be68834455c17b8cae220f898679515735273d4d8e8a0c62735e859d7a7158db7f8e8d1d94e94dd9750c1bd8b5a89a8f67a1ba146201a3999b00350ae1467de39d984b56d4d62ec04bdf0cf05a241468b6a0b70e8ccbbe476ee", + "expected_base64": "QklQMTM4AQEEAAAAAIAAAAEAAAACgAAAAwUoGv8z5LgYasQXZCe1nsPHKvlr9uzRrX7R10YQPQeKFyg7eLv3rs/ZmcUvUSA97xPmnI6zNskLolGAVelBub43cAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPY1PVDHFMQ/e4Z5TuIeNJCvM0aO8wIX3ZMANBPiO0wXAd6tvu/K/rq+EjRWeP2fAyteEXo4W/w8iMLq5OLkruqv9cXO1EV5x3y2f7tsEr3BE8HiybsQKexH9YkxEDDv5Ko5JJWKpTtzfV/fD8InIDe6kmAwOgcBDOrzjkCuxdKDGJaOgzURvcbUq5nLHlEVPwVx/WwOCLWKi3W9uRx/uUsWhyrFgAyYHwbTwo/fcak4LAjHTS0P/p4gd05si+yVzWcT7GD/L6VNUKUH6ERI2Rul/KqN0XrRnbuWLkUUoSfXldjPgs7RnSQql3epvW9xTD3uwkdTD3TAVUEOa0KumN5xJZEDzxTw1XGa4pAGdYQcAQwebAdqm+Ld8nHjKBGE3IdZBjpMG+jy46V+ZVe3Yii/E+XRz2/Icm1kKcrXTIT7sVBGq7Ev5/b244VgFtrjf/8KFhy52jToFJdszJsDpYeQDrNsvVYEnNyWgIFv6cShSDj6Kpmb9K1/5e+n0xxxZIhtbq+hj+QBhbzJgnaNCjygXjRQl55BQMrNg0+OY5kEi1nmqwJZZMKvz2EZthTFZ1Xl43tkJeo5Jt2bn+TNbhJ9YAar2zizk0N8smzYzL2hOCXJC4V96rLbr3WbFP+waS5Ejsu6mjzbrHt2Yb4qjOxaC53zu+GmcBRlPhWcQcOzaXRWO4OScx897GjBbkpkS61CNiCIdqug0AvdPO+sBMMbHhZzuR0AEPjr5wcMB/iwDv+nm46U+xuShZBBFON9TimH2SRqMAlYqfvxwq8QFu3Ox7ng/KgJNWUsNCboN6nOAYYV0fESfaMH2spNyLwgH0SwnArbUoWfScxiWl7NMbvlE+pcl9+48ZLP/WCGSsxMGgpPYwGQy/Hh/oIB2LeytNp+iBP1bh2IX1dwAonuRmGShUBge+eSIRN8Gnm4tKthUPHJxMbKI2emc9X3+qLLzbwf1oxFrLM+c0TlWkMcA60D+0RCvQG4tRzOccd3n6L2MSC+0e0w/zWWnMLLBJtZikc7ZwASvRVebvytgVqDzXbqBu7xSGfO8imYvzneut14/6zoy2y57j8CY2aD1pRY9qzgWPIy7x0dVHwAc6grpQegBt9A9p0qJHtIXuYBDPu1i7xvBCMof0dd8hwuI1M6FlPEiqxVt6ZOSJhQR3SCoIkkyYRwDVvmiDRFXBe4yuIg+JhnlRVzUnPU2Oigxic16FnXpxWNt/jo0dlOlN2XUMG9i1qJqPZ6G6FGIBo5mbADUK4UZ9452YS1bU1i7AS98M8FokFGi2oLcOjMu+R27g==" + }, + { + "description": "Single key, proprietary content (3 bytes)", + "version": 1, + "encryption": 1, + "content": "0204deadbeef", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443" + ], + "decoy_individual_secrets": [ + "0000000000000000000000000000000000000000000000000000000000000001", + "c000000000000000000000000000000000000000000000000000000000000000", + "c200000000000000000000000000000000000000000000000000000000000000", + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + ], + "derivation_paths": [], + "plaintext": "706c61696e74657874", + "nonce": "000102030405060708090a0b", + "expected": "4249503133380100050000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000c14d5bfeb7f9709e996c6696959107d4c57d367d2aee207d5361f116e3c4708bc200000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01000102030405060708090a0b2988e0747028c10af011cba311ebabb3a094366a96ad747cd8e3edfc1474b356c2393e13ee9c5cd0aae5", + "expected_base64": "QklQMTM4AQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMFNW/63+XCemWxmlpWRB9TFfTZ9Ku4gfVNh8RbjxHCLwgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////////////////////////////////////////wEAAQIDBAUGBwgJCgspiOB0cCjBCvARy6MR66uzoJQ2apatdHzY4+38FHSzVsI5PhPunFzQquU=" + }, + { + "description": "Two keys, BIP388 wallet policy content (multisig)", + "version": 1, + "encryption": 1, + "content": "010184", + "keys": [ + "02ee3887104834ec2970bb793abc7fd37661e2c44c49fb48c10745ef7d7c85b17c", + "036f155ae2153b09bb4e1383756723c0879e80d0f32767c7e4875d5de2fb9a400d" + ], + "decoy_individual_secrets": [ + "0000000000000000000000000000000000000000000000000000000000000001", + "8000000000000000000000000000000000000000000000000000000000000000", + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + ], + "derivation_paths": [ + "m/48'/0'/0'/2'" + ], + "plaintext": "{\"keys\":[\"[6738736c/48'/0'/0'/2']xpub6FC1fXFP1GXLX5TKtcjHGT4q89SDRehkQLtbKJ2PzWcvbBHtyDsJPLtpLtkGqYNYZdVVAjRQ5kug9CsapegmmeRutpP7PW4u4wVF9JfkDhw\",\"[b2b1f0cf/48'/0'/0'/2']xpub6EWhjpPa6FqrcaPBuGBZRJVjzGJ1ZsMygRF26RwN932Vfkn1gyCiTbECVitBjRCkexEvetLdiqzTcYimmzYxyR1BZ79KNevgt61PDcukmC7\"],\"policy\":\"wsh(sortedmulti(2,@0/**,@1/**))\"}", + "nonce": "000000000000000000000388", + "expected": "424950313338010005000000000000000000000000000000000000000000000000000000000000000163f5769bbb36d77fc5d3251700590c087013ca44284850e88f379f2519190f978000000000000000000000000000000000000000000000000000000000000000e5b4cabf8bdb9a04a92fc3e104dd2d8a2cb8e5ea886e143236dd4b04619e796dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01000000000000000000000388fd5d011def7dae872431f1fa0df78989f7e5087cd0cb112a69bc211d3346b1031c5d1e8702197712ac46597e05d80421fda7e60d09f3ba2178bd770c904bf840d3d779565fbd0668a989934483820c4c828f32ffe5fc1ce55bbfe287a6d4eb4461e4da1b6a6f22cc0932773c84f07d879b1ed8035831e2a358101be023ea2efb7c70411f757c42715f4e5f7eff416a456a5dadf1b980480e22a7b66726ebc84afe04acdfbf47c6b41c2bb39c5a069a93dba0de4ea9bc192f938f968c9fa2afc26025dd577461b73bad0870e97d7519945ced9d73500c7ece85696d98f223350cd6a337cb74feeeea8d5144ee94553dc54a46e43f67fa48f11c7746e006aac4478fa0c484f041be451548152a1f11f632a9d966de62e3cd80ed9885117e5901042974c80d3f95a13c1cfe2157f2bfb80bea7b3bc0a71127d8daa6a75d3cc517ef934dd9af4b504600c5ce223ba9538c9bc0472aa3832571b1486e2f51b40a5351", + "expected_base64": "QklQMTM4AQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFj9XabuzbXf8XTJRcAWQwIcBPKRChIUOiPN58lGRkPl4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5bTKv4vbmgSpL8PhBN0tiiy45eqIbhQyNt1LBGGeeW3//////////////////////////////////////////wEAAAAAAAAAAAAAA4j9XQEd732uhyQx8foN94mJ9+UIfNDLESppvCEdM0axAxxdHocCGXcSrEZZfgXYBCH9p+YNCfO6IXi9dwyQS/hA09d5Vl+9BmipiZNEg4IMTIKPMv/l/BzlW7/ih6bU60Rh5Nobam8izAkydzyE8H2Hmx7YA1gx4qNYEBvgI+ou+3xwQR91fEJxX05ffv9BakVqXa3xuYBIDiKntmcm68hK/gSs379HxrQcK7OcWgaak9ug3k6pvBkvk4+WjJ+ir8JgJd1XdGG3O60IcOl9dRmUXO2dc1AMfs6FaW2Y8iM1DNajN8t0/u7qjVFE7pRVPcVKRuQ/Z/pI8Rx3RuAGqsRHj6DEhPBBvkUVSBUqHxH2MqnZZt5i482A7ZiFEX5ZAQQpdMgNP5WhPBz+IVfyv7gL6ns7wKcRJ9japqddPMUX75NN2a9LUEYAxc4iO6lTjJvARyqjgyVxsUhuL1G0ClNR" + }, + { + "description": "Two content items in one payload (BIP380 descriptor + BIP329 labels)", + "version": 1, + "encryption": 1, + "content": "01017c", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443", + "0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07" + ], + "decoy_individual_secrets": [ + "0000000000000000000000000000000000000000000000000000000000000001", + "c000000000000000000000000000000000000000000000000000000000000000", + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + ], + "derivation_paths": [], + "plaintext": "wsh(or_d(pk([9d69155f/48'/1'/0'/2']tpubDDxT9mkZzWwkKwpGT5fY6iiM9muYTPkTx6Eig8dpHR7TChuGGCWYAHVmpW1ciido5RiFWwjzYsF1GZHkEHg2nrYp3zNtx3QQRkznyLhQ77x/<0;1>/*),and_v(v:pkh([9d69155f/48'/1'/0'/2']tpubDDxT9mkZzWwkKwpGT5fY6iiM9muYTPkTx6Eig8dpHR7TChuGGCWYAHVmpW1ciido5RiFWwjzYsF1GZHkEHg2nrYp3zNtx3QQRkznyLhQ77x/<2;3>/*),older(52596))))#gx5f42wh", + "nonce": "0c0d0e0f101112131415161a", + "expected": "4249503133380100050000000000000000000000000000000000000000000000000000000000000001b8c6ce74f81b0ffe7d7511824e75f95114f9b140e57bb570e5c5d807f0a5e96fb8e749fceb0dd84d20a75af4dbd6d585d89c54053f6313ac6592cbfe8c1bdd4fc000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff010c0d0e0f101112131415161afde201d35ed73109113688c5cc808c44e3e4a6837adf0ee8c9339947e176418c41f16e92c36b395a07e036117df93fda41bf3b1bacae6cb0fe1cf2c07f519fff3a96b95540de161c48cd8ee6485a1b5477c18d038257af7bacedc36ef0cea2f0661c2267b0d72cf8273f32d734046eb8fbfe75a47619a7d5c12b95e9ec6a49b0a031ccdbfaa6bd201ddf94cb3979ceae1390af41baaedeba38dfcf078c97c33404f0833d36a750e1ebac14d2139719c35aacfa025cde5a19f776d8e1d1367764700f8e8bc3ae99d08fbffaa322abe1e69f2839f8840cdffbcfed9544e4fde1dac882bee1e0d34367f63fc5eec38540f0b3683cd79dbe67eab0ddd52765edf6de7f24adb3e9df8e7b9bf793863f60dfa6fd39aed67eac5d4f774069af6ff436bd85affb199846c55e7d2063d950182b60886f8d65c890d0a4ff6253a8ed0963a052c46ed858dcdefe3e929d970e97d7b65b9843caf94a5649bd8547f5a976cc40b7356dfb6cf3df6b87267ca83d15a2d11cd8e918f2a2b17bb717b33f55a78fd5a6a01cd11d39b54af2734066be57977fb140db2944bf612ce63fa2dc7ae841f47f930637eaaacc96bf5a9cf82483f0aba57dafb79319631a3b954c0a05731607c29290b5c9487def5371585671f4ae6ab0e8cdb51423faf15de6ca34430d21581de9cfe36e", + "extra": [ + { + "content": "010149", + "plaintext": "{\"type\": \"tx\", \"ref\": \"f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16\", \"label\": \"multi content demo\"}" + } + ], + "expected_base64": "QklQMTM4AQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAG4xs50+BsP/n11EYJOdflRFPmxQOV7tXDlxdgH8KXpb7jnSfzrDdhNIKda9NvW1YXYnFQFP2MTrGWSy/6MG91PwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////////////////////////////////////////wEMDQ4PEBESExQVFhr94gHTXtcxCRE2iMXMgIxE4+Smg3rfDujJM5lH4XZBjEHxbpLDazlaB+A2EX35P9pBvzsbrK5ssP4c8sB/UZ//Opa5VUDeFhxIzY7mSFobVHfBjQOCV697rO3DbvDOovBmHCJnsNcs+Cc/Mtc0BG64+/51pHYZp9XBK5Xp7GpJsKAxzNv6pr0gHd+Uyzl5zq4TkK9Buq7eujjfzweMl8M0BPCDPTanUOHrrBTSE5cZw1qs+gJc3loZ93bY4dE2d2RwD46Lw66Z0I+/+qMiq+Hmnyg5+IQM3/vP7ZVE5P3h2siCvuHg00Nn9j/F7sOFQPCzaDzXnb5n6rDd1Sdl7fbefySts+nfjnub95OGP2Dfpv05rtZ+rF1Pd0Bpr2/0Nr2Fr/sZmEbFXn0gY9lQGCtgiG+NZciQ0KT/YlOo7QljoFLEbthY3N7+PpKdlw6X17ZbmEPK+UpWSb2FR/WpdsxAtzVt+2zz32uHJnyoPRWi0RzY6RjyorF7txezP1Wnj9WmoBzRHTm1SvJzQGa+V5d/sUDbKUS/YSzmP6LceuhB9H+TBjfqqsyWv1qc+CSD8Kulfa+3kxljGjuVTAoFcxYHwpKQtclIfe9TcVhWcfSuarDozbUUI/rxXebKNEMNIVgd6c/jbg==" + }, + { + "description": "All-zero nonce MUST be rejected", + "version": 1, + "encryption": 1, + "content": "01017c", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443", + "0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07" + ], + "decoy_individual_secrets": [ + "0000000000000000000000000000000000000000000000000000000000000001", + "c000000000000000000000000000000000000000000000000000000000000000", + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + ], + "derivation_paths": [], + "plaintext": "wsh(or_d(pk([9d69155f/48'/1'/0'/2']tpubDDxT9mkZzWwkKwpGT5fY6iiM9muYTPkTx6Eig8dpHR7TChuGGCWYAHVmpW1ciido5RiFWwjzYsF1GZHkEHg2nrYp3zNtx3QQRkznyLhQ77x/<0;1>/*),and_v(v:pkh([9d69155f/48'/1'/0'/2']tpubDDxT9mkZzWwkKwpGT5fY6iiM9muYTPkTx6Eig8dpHR7TChuGGCWYAHVmpW1ciido5RiFWwjzYsF1GZHkEHg2nrYp3zNtx3QQRkznyLhQ77x/<2;3>/*),older(52596))))#gx5f42wh", + "nonce": "000000000000000000000000", + "expected": "4249503133380100050000000000000000000000000000000000000000000000000000000000000001b8c6ce74f81b0ffe7d7511824e75f95114f9b140e57bb570e5c5d807f0a5e96fb8e749fceb0dd84d20a75af4dbd6d585d89c54053f6313ac6592cbfe8c1bdd4fc000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01000000000000000000000000fd66010d8538e52c03d7069660ca0fc3e961eb7d2ae284498ba1358b7476c09d44bfa60e1963f0271eaf66e816348f001fa4ee1d0fd11e24e93ed12ee288371ce6ca8629b70692e36a43d7647cb340f8f22c6ef4aeb8968f16920ddd2f11f450f7d2420f210f55204d4c40eb8306c02ec8e30c2fd13a15ba0999ad4831a9be7754eab3ddf4f5e71301b89a881a279cf262556708697b8e3da7236872270d3f8d62b6d56e4065835df66277f30177566c233764417eb7d2de6cf5f293321d80c6328c261d0f2d06c9fbd6fd29cd059e0db61d6e1b60951605f40f93c239b643da049186fcc5811bd116808d8bdd8beaefc0d4124088dcd00261c396eb3f27ed254ff91c4457a1c817c53004ea0e764309149044d4e8f92d2ee688619fc44a67a096bdd6c978411d6c103b634896e080cb3dba6f66f0fe580cdb9f944457c65312f449d82c2b1bc86ac972df641ae93ff2d1ea2d9ae64abdce2dd452bf2fc37a5f493dd1704f91a2c765", + "valid": false, + "expected_base64": "QklQMTM4AQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAG4xs50+BsP/n11EYJOdflRFPmxQOV7tXDlxdgH8KXpb7jnSfzrDdhNIKda9NvW1YXYnFQFP2MTrGWSy/6MG91PwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////////////////////////////////////////wEAAAAAAAAAAAAAAAD9ZgENhTjlLAPXBpZgyg/D6WHrfSrihEmLoTWLdHbAnUS/pg4ZY/AnHq9m6BY0jwAfpO4dD9EeJOk+0S7iiDcc5sqGKbcGkuNqQ9dkfLNA+PIsbvSuuJaPFpIN3S8R9FD30kIPIQ9VIE1MQOuDBsAuyOMML9E6FboJma1IMam+d1Tqs9309ecTAbiaiBonnPJiVWcIaXuOPacjaHInDT+NYrbVbkBlg132YnfzAXdWbCM3ZEF+t9LebPXykzIdgMYyjCYdDy0GyfvW/SnNBZ4Nth1uG2CVFgX0D5PCObZD2gSRhvzFgRvRFoCNi92L6u/A1BJAiNzQAmHDlus/J+0lT/kcRFehyBfFMATqDnZDCRSQRNTo+S0u5ohhn8RKZ6CWvdbJeEEdbBA7Y0iW4IDLPbpvZvD+WAzbn5REV8ZTEvRJ2CwrG8hqyXLfZBrpP/LR6i2a5kq9zi3UUr8vw3pfST3RcE+Rosdl" + } +] diff --git a/src/test/data/bip138_encryption_secret.json b/src/test/data/bip138_encryption_secret.json new file mode 100644 index 000000000000..b06d66b5450c --- /dev/null +++ b/src/test/data/bip138_encryption_secret.json @@ -0,0 +1,100 @@ +[ + { + "description": "Single public key", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443" + ], + "decryption_secret": "9628546fe8fbf82fb10ff692d82953fa2db546275be9ce1b00134aff1a8bacdd", + "individual_secrets": [ + "c14d5bfeb7f9709e996c6696959107d4c57d367d2aee207d5361f116e3c4708b" + ] + }, + { + "description": "Two public keys", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443", + "0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07" + ], + "decryption_secret": "efa3c1e5a719874f5516818603cdad7ffc31c11a947c5b16b6b763ee09ea3539", + "individual_secrets": [ + "b8e749fceb0dd84d20a75af4dbd6d585d89c54053f6313ac6592cbfe8c1bdd4f", + "b8c6ce74f81b0ffe7d7511824e75f95114f9b140e57bb570e5c5d807f0a5e96f" + ] + }, + { + "description": "Three public keys", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443", + "0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07", + "03c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5" + ], + "decryption_secret": "7f7ff0a2bbba90dbec74f423f82697e9c2311bac9dd6431882a5fdf9c4485641", + "individual_secrets": [ + "283b78bbf7aecfd999c52f51203def13e69c8eb336c90ba2518055e941b9be37", + "f6353d50c714c43f7b86794ee21e3490af33468ef30217dd93003413e23b4c17", + "281aff33e4b8186ac4176427b59ec3c72af96bf6ecd1ad7ed1d746103d078a17" + ] + }, + { + "description": "Three public keys bis (different sorting)", + "keys": [ + "03c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5", + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443", + "0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07" + ], + "decryption_secret": "7f7ff0a2bbba90dbec74f423f82697e9c2311bac9dd6431882a5fdf9c4485641", + "individual_secrets": [ + "283b78bbf7aecfd999c52f51203def13e69c8eb336c90ba2518055e941b9be37", + "f6353d50c714c43f7b86794ee21e3490af33468ef30217dd93003413e23b4c17", + "281aff33e4b8186ac4176427b59ec3c72af96bf6ecd1ad7ed1d746103d078a17" + ] + }, + { + "description": "Three public keys ter (different sorting)", + "keys": [ + "0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07", + "03c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5", + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443" + ], + "decryption_secret": "7f7ff0a2bbba90dbec74f423f82697e9c2311bac9dd6431882a5fdf9c4485641", + "individual_secrets": [ + "283b78bbf7aecfd999c52f51203def13e69c8eb336c90ba2518055e941b9be37", + "f6353d50c714c43f7b86794ee21e3490af33468ef30217dd93003413e23b4c17", + "281aff33e4b8186ac4176427b59ec3c72af96bf6ecd1ad7ed1d746103d078a17" + ] + }, + { + "description": "Keys processed in sorted order", + "keys": [ + "0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07", + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443" + ], + "decryption_secret": "efa3c1e5a719874f5516818603cdad7ffc31c11a947c5b16b6b763ee09ea3539", + "individual_secrets": [ + "b8e749fceb0dd84d20a75af4dbd6d585d89c54053f6313ac6592cbfe8c1bdd4f", + "b8c6ce74f81b0ffe7d7511824e75f95114f9b140e57bb570e5c5d807f0a5e96f" + ] + }, + { + "description": "Duplicate keys should be handled", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443", + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443" + ], + "decryption_secret": "9628546fe8fbf82fb10ff692d82953fa2db546275be9ce1b00134aff1a8bacdd", + "individual_secrets": [ + "c14d5bfeb7f9709e996c6696959107d4c57d367d2aee207d5361f116e3c4708b" + ] + }, + { + "description": "Keys sharing an x coordinate normalize to a single key", + "keys": [ + "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443", + "03e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443" + ], + "decryption_secret": "9628546fe8fbf82fb10ff692d82953fa2db546275be9ce1b00134aff1a8bacdd", + "individual_secrets": [ + "c14d5bfeb7f9709e996c6696959107d4c57d367d2aee207d5361f116e3c4708b" + ] + } +] diff --git a/src/test/data/bip138_individual_secrets.json b/src/test/data/bip138_individual_secrets.json new file mode 100644 index 000000000000..ff4e7b36595d --- /dev/null +++ b/src/test/data/bip138_individual_secrets.json @@ -0,0 +1,571 @@ +[ + { + "description": "Single secret", + "secrets": [ + "0101010101010101010101010101010101010101010101010101010101010101" + ], + "expected": "010101010101010101010101010101010101010101010101010101010101010101" + }, + { + "description": "Two different secrets", + "secrets": [ + "0101010101010101010101010101010101010101010101010101010101010101", + "0202020202020202020202020202020202020202020202020202020202020202" + ], + "expected": "0201010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202" + }, + { + "description": "Unsorted secrets are sorted when encoded", + "secrets": [ + "0202020202020202020202020202020202020202020202020202020202020202", + "0101010101010101010101010101010101010101010101010101010101010101" + ], + "expected": "0201010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202" + }, + { + "description": "Duplicate secrets are deduplicated", + "secrets": [ + "0202020202020202020202020202020202020202020202020202020202020202", + "0101010101010101010101010101010101010101010101010101010101010101", + "0202020202020202020202020202020202020202020202020202020202020202" + ], + "expected": "0201010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202" + }, + { + "description": "Three secrets with different patterns", + "secrets": [ + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "5555555555555555555555555555555555555555555555555555555555555555", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ], + "expected": "035555555555555555555555555555555555555555555555555555555555555555aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + }, + { + "description": "Empty secrets should fail", + "secrets": [], + "expected": null + }, + { + "description": "256 distinct non-zero secrets should fail (exceeds u8::MAX)", + "secrets": [ + "0000000000000000000000000000000000000000000000000000000000000001", + "0000000000000000000000000000000000000000000000000000000000000002", + "0000000000000000000000000000000000000000000000000000000000000003", + "0000000000000000000000000000000000000000000000000000000000000004", + "0000000000000000000000000000000000000000000000000000000000000005", + "0000000000000000000000000000000000000000000000000000000000000006", + "0000000000000000000000000000000000000000000000000000000000000007", + "0000000000000000000000000000000000000000000000000000000000000008", + "0000000000000000000000000000000000000000000000000000000000000009", + "000000000000000000000000000000000000000000000000000000000000000a", + "000000000000000000000000000000000000000000000000000000000000000b", + "000000000000000000000000000000000000000000000000000000000000000c", + "000000000000000000000000000000000000000000000000000000000000000d", + "000000000000000000000000000000000000000000000000000000000000000e", + "000000000000000000000000000000000000000000000000000000000000000f", + "0000000000000000000000000000000000000000000000000000000000000010", + "0000000000000000000000000000000000000000000000000000000000000011", + "0000000000000000000000000000000000000000000000000000000000000012", + "0000000000000000000000000000000000000000000000000000000000000013", + "0000000000000000000000000000000000000000000000000000000000000014", + "0000000000000000000000000000000000000000000000000000000000000015", + "0000000000000000000000000000000000000000000000000000000000000016", + "0000000000000000000000000000000000000000000000000000000000000017", + "0000000000000000000000000000000000000000000000000000000000000018", + "0000000000000000000000000000000000000000000000000000000000000019", + "000000000000000000000000000000000000000000000000000000000000001a", + "000000000000000000000000000000000000000000000000000000000000001b", + "000000000000000000000000000000000000000000000000000000000000001c", + "000000000000000000000000000000000000000000000000000000000000001d", + "000000000000000000000000000000000000000000000000000000000000001e", + "000000000000000000000000000000000000000000000000000000000000001f", + "0000000000000000000000000000000000000000000000000000000000000020", + "0000000000000000000000000000000000000000000000000000000000000021", + "0000000000000000000000000000000000000000000000000000000000000022", + "0000000000000000000000000000000000000000000000000000000000000023", + "0000000000000000000000000000000000000000000000000000000000000024", + "0000000000000000000000000000000000000000000000000000000000000025", + "0000000000000000000000000000000000000000000000000000000000000026", + "0000000000000000000000000000000000000000000000000000000000000027", + "0000000000000000000000000000000000000000000000000000000000000028", + "0000000000000000000000000000000000000000000000000000000000000029", + "000000000000000000000000000000000000000000000000000000000000002a", + "000000000000000000000000000000000000000000000000000000000000002b", + "000000000000000000000000000000000000000000000000000000000000002c", + "000000000000000000000000000000000000000000000000000000000000002d", + "000000000000000000000000000000000000000000000000000000000000002e", + "000000000000000000000000000000000000000000000000000000000000002f", + "0000000000000000000000000000000000000000000000000000000000000030", + "0000000000000000000000000000000000000000000000000000000000000031", + "0000000000000000000000000000000000000000000000000000000000000032", + "0000000000000000000000000000000000000000000000000000000000000033", + "0000000000000000000000000000000000000000000000000000000000000034", + "0000000000000000000000000000000000000000000000000000000000000035", + "0000000000000000000000000000000000000000000000000000000000000036", + "0000000000000000000000000000000000000000000000000000000000000037", + "0000000000000000000000000000000000000000000000000000000000000038", + "0000000000000000000000000000000000000000000000000000000000000039", + "000000000000000000000000000000000000000000000000000000000000003a", + "000000000000000000000000000000000000000000000000000000000000003b", + "000000000000000000000000000000000000000000000000000000000000003c", + "000000000000000000000000000000000000000000000000000000000000003d", + "000000000000000000000000000000000000000000000000000000000000003e", + "000000000000000000000000000000000000000000000000000000000000003f", + "0000000000000000000000000000000000000000000000000000000000000040", + "0000000000000000000000000000000000000000000000000000000000000041", + "0000000000000000000000000000000000000000000000000000000000000042", + "0000000000000000000000000000000000000000000000000000000000000043", + "0000000000000000000000000000000000000000000000000000000000000044", + "0000000000000000000000000000000000000000000000000000000000000045", + "0000000000000000000000000000000000000000000000000000000000000046", + "0000000000000000000000000000000000000000000000000000000000000047", + "0000000000000000000000000000000000000000000000000000000000000048", + "0000000000000000000000000000000000000000000000000000000000000049", + "000000000000000000000000000000000000000000000000000000000000004a", + "000000000000000000000000000000000000000000000000000000000000004b", + "000000000000000000000000000000000000000000000000000000000000004c", + "000000000000000000000000000000000000000000000000000000000000004d", + "000000000000000000000000000000000000000000000000000000000000004e", + "000000000000000000000000000000000000000000000000000000000000004f", + "0000000000000000000000000000000000000000000000000000000000000050", + "0000000000000000000000000000000000000000000000000000000000000051", + "0000000000000000000000000000000000000000000000000000000000000052", + "0000000000000000000000000000000000000000000000000000000000000053", + "0000000000000000000000000000000000000000000000000000000000000054", + "0000000000000000000000000000000000000000000000000000000000000055", + "0000000000000000000000000000000000000000000000000000000000000056", + "0000000000000000000000000000000000000000000000000000000000000057", + "0000000000000000000000000000000000000000000000000000000000000058", + "0000000000000000000000000000000000000000000000000000000000000059", + "000000000000000000000000000000000000000000000000000000000000005a", + "000000000000000000000000000000000000000000000000000000000000005b", + "000000000000000000000000000000000000000000000000000000000000005c", + "000000000000000000000000000000000000000000000000000000000000005d", + "000000000000000000000000000000000000000000000000000000000000005e", + "000000000000000000000000000000000000000000000000000000000000005f", + "0000000000000000000000000000000000000000000000000000000000000060", + "0000000000000000000000000000000000000000000000000000000000000061", + "0000000000000000000000000000000000000000000000000000000000000062", + "0000000000000000000000000000000000000000000000000000000000000063", + "0000000000000000000000000000000000000000000000000000000000000064", + "0000000000000000000000000000000000000000000000000000000000000065", + "0000000000000000000000000000000000000000000000000000000000000066", + "0000000000000000000000000000000000000000000000000000000000000067", + "0000000000000000000000000000000000000000000000000000000000000068", + "0000000000000000000000000000000000000000000000000000000000000069", + "000000000000000000000000000000000000000000000000000000000000006a", + "000000000000000000000000000000000000000000000000000000000000006b", + "000000000000000000000000000000000000000000000000000000000000006c", + "000000000000000000000000000000000000000000000000000000000000006d", + "000000000000000000000000000000000000000000000000000000000000006e", + "000000000000000000000000000000000000000000000000000000000000006f", + "0000000000000000000000000000000000000000000000000000000000000070", + "0000000000000000000000000000000000000000000000000000000000000071", + "0000000000000000000000000000000000000000000000000000000000000072", + "0000000000000000000000000000000000000000000000000000000000000073", + "0000000000000000000000000000000000000000000000000000000000000074", + "0000000000000000000000000000000000000000000000000000000000000075", + "0000000000000000000000000000000000000000000000000000000000000076", + "0000000000000000000000000000000000000000000000000000000000000077", + "0000000000000000000000000000000000000000000000000000000000000078", + "0000000000000000000000000000000000000000000000000000000000000079", + "000000000000000000000000000000000000000000000000000000000000007a", + "000000000000000000000000000000000000000000000000000000000000007b", + "000000000000000000000000000000000000000000000000000000000000007c", + "000000000000000000000000000000000000000000000000000000000000007d", + "000000000000000000000000000000000000000000000000000000000000007e", + "000000000000000000000000000000000000000000000000000000000000007f", + "0000000000000000000000000000000000000000000000000000000000000080", + "0000000000000000000000000000000000000000000000000000000000000081", + "0000000000000000000000000000000000000000000000000000000000000082", + "0000000000000000000000000000000000000000000000000000000000000083", + "0000000000000000000000000000000000000000000000000000000000000084", + "0000000000000000000000000000000000000000000000000000000000000085", + "0000000000000000000000000000000000000000000000000000000000000086", + "0000000000000000000000000000000000000000000000000000000000000087", + "0000000000000000000000000000000000000000000000000000000000000088", + "0000000000000000000000000000000000000000000000000000000000000089", + "000000000000000000000000000000000000000000000000000000000000008a", + "000000000000000000000000000000000000000000000000000000000000008b", + "000000000000000000000000000000000000000000000000000000000000008c", + "000000000000000000000000000000000000000000000000000000000000008d", + "000000000000000000000000000000000000000000000000000000000000008e", + "000000000000000000000000000000000000000000000000000000000000008f", + "0000000000000000000000000000000000000000000000000000000000000090", + "0000000000000000000000000000000000000000000000000000000000000091", + "0000000000000000000000000000000000000000000000000000000000000092", + "0000000000000000000000000000000000000000000000000000000000000093", + "0000000000000000000000000000000000000000000000000000000000000094", + "0000000000000000000000000000000000000000000000000000000000000095", + "0000000000000000000000000000000000000000000000000000000000000096", + "0000000000000000000000000000000000000000000000000000000000000097", + "0000000000000000000000000000000000000000000000000000000000000098", + "0000000000000000000000000000000000000000000000000000000000000099", + "000000000000000000000000000000000000000000000000000000000000009a", + "000000000000000000000000000000000000000000000000000000000000009b", + "000000000000000000000000000000000000000000000000000000000000009c", + "000000000000000000000000000000000000000000000000000000000000009d", + "000000000000000000000000000000000000000000000000000000000000009e", + "000000000000000000000000000000000000000000000000000000000000009f", + "00000000000000000000000000000000000000000000000000000000000000a0", + "00000000000000000000000000000000000000000000000000000000000000a1", + "00000000000000000000000000000000000000000000000000000000000000a2", + "00000000000000000000000000000000000000000000000000000000000000a3", + "00000000000000000000000000000000000000000000000000000000000000a4", + "00000000000000000000000000000000000000000000000000000000000000a5", + "00000000000000000000000000000000000000000000000000000000000000a6", + "00000000000000000000000000000000000000000000000000000000000000a7", + "00000000000000000000000000000000000000000000000000000000000000a8", + "00000000000000000000000000000000000000000000000000000000000000a9", + "00000000000000000000000000000000000000000000000000000000000000aa", + "00000000000000000000000000000000000000000000000000000000000000ab", + "00000000000000000000000000000000000000000000000000000000000000ac", + "00000000000000000000000000000000000000000000000000000000000000ad", + "00000000000000000000000000000000000000000000000000000000000000ae", + "00000000000000000000000000000000000000000000000000000000000000af", + "00000000000000000000000000000000000000000000000000000000000000b0", + "00000000000000000000000000000000000000000000000000000000000000b1", + "00000000000000000000000000000000000000000000000000000000000000b2", + "00000000000000000000000000000000000000000000000000000000000000b3", + "00000000000000000000000000000000000000000000000000000000000000b4", + "00000000000000000000000000000000000000000000000000000000000000b5", + "00000000000000000000000000000000000000000000000000000000000000b6", + "00000000000000000000000000000000000000000000000000000000000000b7", + "00000000000000000000000000000000000000000000000000000000000000b8", + "00000000000000000000000000000000000000000000000000000000000000b9", + "00000000000000000000000000000000000000000000000000000000000000ba", + "00000000000000000000000000000000000000000000000000000000000000bb", + "00000000000000000000000000000000000000000000000000000000000000bc", + "00000000000000000000000000000000000000000000000000000000000000bd", + "00000000000000000000000000000000000000000000000000000000000000be", + "00000000000000000000000000000000000000000000000000000000000000bf", + "00000000000000000000000000000000000000000000000000000000000000c0", + "00000000000000000000000000000000000000000000000000000000000000c1", + "00000000000000000000000000000000000000000000000000000000000000c2", + "00000000000000000000000000000000000000000000000000000000000000c3", + "00000000000000000000000000000000000000000000000000000000000000c4", + "00000000000000000000000000000000000000000000000000000000000000c5", + "00000000000000000000000000000000000000000000000000000000000000c6", + "00000000000000000000000000000000000000000000000000000000000000c7", + "00000000000000000000000000000000000000000000000000000000000000c8", + "00000000000000000000000000000000000000000000000000000000000000c9", + "00000000000000000000000000000000000000000000000000000000000000ca", + "00000000000000000000000000000000000000000000000000000000000000cb", + "00000000000000000000000000000000000000000000000000000000000000cc", + "00000000000000000000000000000000000000000000000000000000000000cd", + "00000000000000000000000000000000000000000000000000000000000000ce", + "00000000000000000000000000000000000000000000000000000000000000cf", + "00000000000000000000000000000000000000000000000000000000000000d0", + "00000000000000000000000000000000000000000000000000000000000000d1", + "00000000000000000000000000000000000000000000000000000000000000d2", + "00000000000000000000000000000000000000000000000000000000000000d3", + "00000000000000000000000000000000000000000000000000000000000000d4", + "00000000000000000000000000000000000000000000000000000000000000d5", + "00000000000000000000000000000000000000000000000000000000000000d6", + "00000000000000000000000000000000000000000000000000000000000000d7", + "00000000000000000000000000000000000000000000000000000000000000d8", + "00000000000000000000000000000000000000000000000000000000000000d9", + "00000000000000000000000000000000000000000000000000000000000000da", + "00000000000000000000000000000000000000000000000000000000000000db", + "00000000000000000000000000000000000000000000000000000000000000dc", + "00000000000000000000000000000000000000000000000000000000000000dd", + "00000000000000000000000000000000000000000000000000000000000000de", + "00000000000000000000000000000000000000000000000000000000000000df", + "00000000000000000000000000000000000000000000000000000000000000e0", + "00000000000000000000000000000000000000000000000000000000000000e1", + "00000000000000000000000000000000000000000000000000000000000000e2", + "00000000000000000000000000000000000000000000000000000000000000e3", + "00000000000000000000000000000000000000000000000000000000000000e4", + "00000000000000000000000000000000000000000000000000000000000000e5", + "00000000000000000000000000000000000000000000000000000000000000e6", + "00000000000000000000000000000000000000000000000000000000000000e7", + "00000000000000000000000000000000000000000000000000000000000000e8", + "00000000000000000000000000000000000000000000000000000000000000e9", + "00000000000000000000000000000000000000000000000000000000000000ea", + "00000000000000000000000000000000000000000000000000000000000000eb", + "00000000000000000000000000000000000000000000000000000000000000ec", + "00000000000000000000000000000000000000000000000000000000000000ed", + "00000000000000000000000000000000000000000000000000000000000000ee", + "00000000000000000000000000000000000000000000000000000000000000ef", + "00000000000000000000000000000000000000000000000000000000000000f0", + "00000000000000000000000000000000000000000000000000000000000000f1", + "00000000000000000000000000000000000000000000000000000000000000f2", + "00000000000000000000000000000000000000000000000000000000000000f3", + "00000000000000000000000000000000000000000000000000000000000000f4", + "00000000000000000000000000000000000000000000000000000000000000f5", + "00000000000000000000000000000000000000000000000000000000000000f6", + "00000000000000000000000000000000000000000000000000000000000000f7", + "00000000000000000000000000000000000000000000000000000000000000f8", + "00000000000000000000000000000000000000000000000000000000000000f9", + "00000000000000000000000000000000000000000000000000000000000000fa", + "00000000000000000000000000000000000000000000000000000000000000fb", + "00000000000000000000000000000000000000000000000000000000000000fc", + "00000000000000000000000000000000000000000000000000000000000000fd", + "00000000000000000000000000000000000000000000000000000000000000fe", + "00000000000000000000000000000000000000000000000000000000000000ff", + "0000000000000000000000000000000000000000000000000000000000000100" + ], + "expected": null + }, + { + "description": "255 distinct non-zero secrets should pass", + "secrets": [ + "0000000000000000000000000000000000000000000000000000000000000001", + "0000000000000000000000000000000000000000000000000000000000000002", + "0000000000000000000000000000000000000000000000000000000000000003", + "0000000000000000000000000000000000000000000000000000000000000004", + "0000000000000000000000000000000000000000000000000000000000000005", + "0000000000000000000000000000000000000000000000000000000000000006", + "0000000000000000000000000000000000000000000000000000000000000007", + "0000000000000000000000000000000000000000000000000000000000000008", + "0000000000000000000000000000000000000000000000000000000000000009", + "000000000000000000000000000000000000000000000000000000000000000a", + "000000000000000000000000000000000000000000000000000000000000000b", + "000000000000000000000000000000000000000000000000000000000000000c", + "000000000000000000000000000000000000000000000000000000000000000d", + "000000000000000000000000000000000000000000000000000000000000000e", + "000000000000000000000000000000000000000000000000000000000000000f", + "0000000000000000000000000000000000000000000000000000000000000010", + "0000000000000000000000000000000000000000000000000000000000000011", + "0000000000000000000000000000000000000000000000000000000000000012", + "0000000000000000000000000000000000000000000000000000000000000013", + "0000000000000000000000000000000000000000000000000000000000000014", + "0000000000000000000000000000000000000000000000000000000000000015", + "0000000000000000000000000000000000000000000000000000000000000016", + "0000000000000000000000000000000000000000000000000000000000000017", + "0000000000000000000000000000000000000000000000000000000000000018", + "0000000000000000000000000000000000000000000000000000000000000019", + "000000000000000000000000000000000000000000000000000000000000001a", + "000000000000000000000000000000000000000000000000000000000000001b", + "000000000000000000000000000000000000000000000000000000000000001c", + "000000000000000000000000000000000000000000000000000000000000001d", + "000000000000000000000000000000000000000000000000000000000000001e", + "000000000000000000000000000000000000000000000000000000000000001f", + "0000000000000000000000000000000000000000000000000000000000000020", + "0000000000000000000000000000000000000000000000000000000000000021", + "0000000000000000000000000000000000000000000000000000000000000022", + "0000000000000000000000000000000000000000000000000000000000000023", + "0000000000000000000000000000000000000000000000000000000000000024", + "0000000000000000000000000000000000000000000000000000000000000025", + "0000000000000000000000000000000000000000000000000000000000000026", + "0000000000000000000000000000000000000000000000000000000000000027", + "0000000000000000000000000000000000000000000000000000000000000028", + "0000000000000000000000000000000000000000000000000000000000000029", + "000000000000000000000000000000000000000000000000000000000000002a", + "000000000000000000000000000000000000000000000000000000000000002b", + "000000000000000000000000000000000000000000000000000000000000002c", + "000000000000000000000000000000000000000000000000000000000000002d", + "000000000000000000000000000000000000000000000000000000000000002e", + "000000000000000000000000000000000000000000000000000000000000002f", + "0000000000000000000000000000000000000000000000000000000000000030", + "0000000000000000000000000000000000000000000000000000000000000031", + "0000000000000000000000000000000000000000000000000000000000000032", + "0000000000000000000000000000000000000000000000000000000000000033", + "0000000000000000000000000000000000000000000000000000000000000034", + "0000000000000000000000000000000000000000000000000000000000000035", + "0000000000000000000000000000000000000000000000000000000000000036", + "0000000000000000000000000000000000000000000000000000000000000037", + "0000000000000000000000000000000000000000000000000000000000000038", + "0000000000000000000000000000000000000000000000000000000000000039", + "000000000000000000000000000000000000000000000000000000000000003a", + "000000000000000000000000000000000000000000000000000000000000003b", + "000000000000000000000000000000000000000000000000000000000000003c", + "000000000000000000000000000000000000000000000000000000000000003d", + "000000000000000000000000000000000000000000000000000000000000003e", + "000000000000000000000000000000000000000000000000000000000000003f", + "0000000000000000000000000000000000000000000000000000000000000040", + "0000000000000000000000000000000000000000000000000000000000000041", + "0000000000000000000000000000000000000000000000000000000000000042", + "0000000000000000000000000000000000000000000000000000000000000043", + "0000000000000000000000000000000000000000000000000000000000000044", + "0000000000000000000000000000000000000000000000000000000000000045", + "0000000000000000000000000000000000000000000000000000000000000046", + "0000000000000000000000000000000000000000000000000000000000000047", + "0000000000000000000000000000000000000000000000000000000000000048", + "0000000000000000000000000000000000000000000000000000000000000049", + "000000000000000000000000000000000000000000000000000000000000004a", + "000000000000000000000000000000000000000000000000000000000000004b", + "000000000000000000000000000000000000000000000000000000000000004c", + "000000000000000000000000000000000000000000000000000000000000004d", + "000000000000000000000000000000000000000000000000000000000000004e", + "000000000000000000000000000000000000000000000000000000000000004f", + "0000000000000000000000000000000000000000000000000000000000000050", + "0000000000000000000000000000000000000000000000000000000000000051", + "0000000000000000000000000000000000000000000000000000000000000052", + "0000000000000000000000000000000000000000000000000000000000000053", + "0000000000000000000000000000000000000000000000000000000000000054", + "0000000000000000000000000000000000000000000000000000000000000055", + "0000000000000000000000000000000000000000000000000000000000000056", + "0000000000000000000000000000000000000000000000000000000000000057", + "0000000000000000000000000000000000000000000000000000000000000058", + "0000000000000000000000000000000000000000000000000000000000000059", + "000000000000000000000000000000000000000000000000000000000000005a", + "000000000000000000000000000000000000000000000000000000000000005b", + "000000000000000000000000000000000000000000000000000000000000005c", + "000000000000000000000000000000000000000000000000000000000000005d", + "000000000000000000000000000000000000000000000000000000000000005e", + "000000000000000000000000000000000000000000000000000000000000005f", + "0000000000000000000000000000000000000000000000000000000000000060", + "0000000000000000000000000000000000000000000000000000000000000061", + "0000000000000000000000000000000000000000000000000000000000000062", + "0000000000000000000000000000000000000000000000000000000000000063", + "0000000000000000000000000000000000000000000000000000000000000064", + "0000000000000000000000000000000000000000000000000000000000000065", + "0000000000000000000000000000000000000000000000000000000000000066", + "0000000000000000000000000000000000000000000000000000000000000067", + "0000000000000000000000000000000000000000000000000000000000000068", + "0000000000000000000000000000000000000000000000000000000000000069", + "000000000000000000000000000000000000000000000000000000000000006a", + "000000000000000000000000000000000000000000000000000000000000006b", + "000000000000000000000000000000000000000000000000000000000000006c", + "000000000000000000000000000000000000000000000000000000000000006d", + "000000000000000000000000000000000000000000000000000000000000006e", + "000000000000000000000000000000000000000000000000000000000000006f", + "0000000000000000000000000000000000000000000000000000000000000070", + "0000000000000000000000000000000000000000000000000000000000000071", + "0000000000000000000000000000000000000000000000000000000000000072", + "0000000000000000000000000000000000000000000000000000000000000073", + "0000000000000000000000000000000000000000000000000000000000000074", + "0000000000000000000000000000000000000000000000000000000000000075", + "0000000000000000000000000000000000000000000000000000000000000076", + "0000000000000000000000000000000000000000000000000000000000000077", + "0000000000000000000000000000000000000000000000000000000000000078", + "0000000000000000000000000000000000000000000000000000000000000079", + "000000000000000000000000000000000000000000000000000000000000007a", + "000000000000000000000000000000000000000000000000000000000000007b", + "000000000000000000000000000000000000000000000000000000000000007c", + "000000000000000000000000000000000000000000000000000000000000007d", + "000000000000000000000000000000000000000000000000000000000000007e", + "000000000000000000000000000000000000000000000000000000000000007f", + "0000000000000000000000000000000000000000000000000000000000000080", + "0000000000000000000000000000000000000000000000000000000000000081", + "0000000000000000000000000000000000000000000000000000000000000082", + "0000000000000000000000000000000000000000000000000000000000000083", + "0000000000000000000000000000000000000000000000000000000000000084", + "0000000000000000000000000000000000000000000000000000000000000085", + "0000000000000000000000000000000000000000000000000000000000000086", + "0000000000000000000000000000000000000000000000000000000000000087", + "0000000000000000000000000000000000000000000000000000000000000088", + "0000000000000000000000000000000000000000000000000000000000000089", + "000000000000000000000000000000000000000000000000000000000000008a", + "000000000000000000000000000000000000000000000000000000000000008b", + "000000000000000000000000000000000000000000000000000000000000008c", + "000000000000000000000000000000000000000000000000000000000000008d", + "000000000000000000000000000000000000000000000000000000000000008e", + "000000000000000000000000000000000000000000000000000000000000008f", + "0000000000000000000000000000000000000000000000000000000000000090", + "0000000000000000000000000000000000000000000000000000000000000091", + "0000000000000000000000000000000000000000000000000000000000000092", + "0000000000000000000000000000000000000000000000000000000000000093", + "0000000000000000000000000000000000000000000000000000000000000094", + "0000000000000000000000000000000000000000000000000000000000000095", + "0000000000000000000000000000000000000000000000000000000000000096", + "0000000000000000000000000000000000000000000000000000000000000097", + "0000000000000000000000000000000000000000000000000000000000000098", + "0000000000000000000000000000000000000000000000000000000000000099", + "000000000000000000000000000000000000000000000000000000000000009a", + "000000000000000000000000000000000000000000000000000000000000009b", + "000000000000000000000000000000000000000000000000000000000000009c", + "000000000000000000000000000000000000000000000000000000000000009d", + "000000000000000000000000000000000000000000000000000000000000009e", + "000000000000000000000000000000000000000000000000000000000000009f", + "00000000000000000000000000000000000000000000000000000000000000a0", + "00000000000000000000000000000000000000000000000000000000000000a1", + "00000000000000000000000000000000000000000000000000000000000000a2", + "00000000000000000000000000000000000000000000000000000000000000a3", + "00000000000000000000000000000000000000000000000000000000000000a4", + "00000000000000000000000000000000000000000000000000000000000000a5", + "00000000000000000000000000000000000000000000000000000000000000a6", + "00000000000000000000000000000000000000000000000000000000000000a7", + "00000000000000000000000000000000000000000000000000000000000000a8", + "00000000000000000000000000000000000000000000000000000000000000a9", + "00000000000000000000000000000000000000000000000000000000000000aa", + "00000000000000000000000000000000000000000000000000000000000000ab", + "00000000000000000000000000000000000000000000000000000000000000ac", + "00000000000000000000000000000000000000000000000000000000000000ad", + "00000000000000000000000000000000000000000000000000000000000000ae", + "00000000000000000000000000000000000000000000000000000000000000af", + "00000000000000000000000000000000000000000000000000000000000000b0", + "00000000000000000000000000000000000000000000000000000000000000b1", + "00000000000000000000000000000000000000000000000000000000000000b2", + "00000000000000000000000000000000000000000000000000000000000000b3", + "00000000000000000000000000000000000000000000000000000000000000b4", + "00000000000000000000000000000000000000000000000000000000000000b5", + "00000000000000000000000000000000000000000000000000000000000000b6", + "00000000000000000000000000000000000000000000000000000000000000b7", + "00000000000000000000000000000000000000000000000000000000000000b8", + "00000000000000000000000000000000000000000000000000000000000000b9", + "00000000000000000000000000000000000000000000000000000000000000ba", + "00000000000000000000000000000000000000000000000000000000000000bb", + "00000000000000000000000000000000000000000000000000000000000000bc", + "00000000000000000000000000000000000000000000000000000000000000bd", + "00000000000000000000000000000000000000000000000000000000000000be", + "00000000000000000000000000000000000000000000000000000000000000bf", + "00000000000000000000000000000000000000000000000000000000000000c0", + "00000000000000000000000000000000000000000000000000000000000000c1", + "00000000000000000000000000000000000000000000000000000000000000c2", + "00000000000000000000000000000000000000000000000000000000000000c3", + "00000000000000000000000000000000000000000000000000000000000000c4", + "00000000000000000000000000000000000000000000000000000000000000c5", + "00000000000000000000000000000000000000000000000000000000000000c6", + "00000000000000000000000000000000000000000000000000000000000000c7", + "00000000000000000000000000000000000000000000000000000000000000c8", + "00000000000000000000000000000000000000000000000000000000000000c9", + "00000000000000000000000000000000000000000000000000000000000000ca", + "00000000000000000000000000000000000000000000000000000000000000cb", + "00000000000000000000000000000000000000000000000000000000000000cc", + "00000000000000000000000000000000000000000000000000000000000000cd", + "00000000000000000000000000000000000000000000000000000000000000ce", + "00000000000000000000000000000000000000000000000000000000000000cf", + "00000000000000000000000000000000000000000000000000000000000000d0", + "00000000000000000000000000000000000000000000000000000000000000d1", + "00000000000000000000000000000000000000000000000000000000000000d2", + "00000000000000000000000000000000000000000000000000000000000000d3", + "00000000000000000000000000000000000000000000000000000000000000d4", + "00000000000000000000000000000000000000000000000000000000000000d5", + "00000000000000000000000000000000000000000000000000000000000000d6", + "00000000000000000000000000000000000000000000000000000000000000d7", + "00000000000000000000000000000000000000000000000000000000000000d8", + "00000000000000000000000000000000000000000000000000000000000000d9", + "00000000000000000000000000000000000000000000000000000000000000da", + "00000000000000000000000000000000000000000000000000000000000000db", + "00000000000000000000000000000000000000000000000000000000000000dc", + "00000000000000000000000000000000000000000000000000000000000000dd", + "00000000000000000000000000000000000000000000000000000000000000de", + "00000000000000000000000000000000000000000000000000000000000000df", + "00000000000000000000000000000000000000000000000000000000000000e0", + "00000000000000000000000000000000000000000000000000000000000000e1", + "00000000000000000000000000000000000000000000000000000000000000e2", + "00000000000000000000000000000000000000000000000000000000000000e3", + "00000000000000000000000000000000000000000000000000000000000000e4", + "00000000000000000000000000000000000000000000000000000000000000e5", + "00000000000000000000000000000000000000000000000000000000000000e6", + "00000000000000000000000000000000000000000000000000000000000000e7", + "00000000000000000000000000000000000000000000000000000000000000e8", + "00000000000000000000000000000000000000000000000000000000000000e9", + "00000000000000000000000000000000000000000000000000000000000000ea", + "00000000000000000000000000000000000000000000000000000000000000eb", + "00000000000000000000000000000000000000000000000000000000000000ec", + "00000000000000000000000000000000000000000000000000000000000000ed", + "00000000000000000000000000000000000000000000000000000000000000ee", + "00000000000000000000000000000000000000000000000000000000000000ef", + "00000000000000000000000000000000000000000000000000000000000000f0", + "00000000000000000000000000000000000000000000000000000000000000f1", + "00000000000000000000000000000000000000000000000000000000000000f2", + "00000000000000000000000000000000000000000000000000000000000000f3", + "00000000000000000000000000000000000000000000000000000000000000f4", + "00000000000000000000000000000000000000000000000000000000000000f5", + "00000000000000000000000000000000000000000000000000000000000000f6", + "00000000000000000000000000000000000000000000000000000000000000f7", + "00000000000000000000000000000000000000000000000000000000000000f8", + "00000000000000000000000000000000000000000000000000000000000000f9", + "00000000000000000000000000000000000000000000000000000000000000fa", + "00000000000000000000000000000000000000000000000000000000000000fb", + "00000000000000000000000000000000000000000000000000000000000000fc", + "00000000000000000000000000000000000000000000000000000000000000fd", + "00000000000000000000000000000000000000000000000000000000000000fe", + "00000000000000000000000000000000000000000000000000000000000000ff" + ], + "expected": "ff000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001100000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000013000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000150000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001700000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000019000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001d000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000001f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002100000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000023000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000250000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002700000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000029000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002b000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000002f0000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003100000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000000000033000000000000000000000000000000000000000000000000000000000000003400000000000000000000000000000000000000000000000000000000000000350000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000000003700000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000039000000000000000000000000000000000000000000000000000000000000003a000000000000000000000000000000000000000000000000000000000000003b000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000003d000000000000000000000000000000000000000000000000000000000000003e000000000000000000000000000000000000000000000000000000000000003f0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004100000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000000000043000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000000000004700000000000000000000000000000000000000000000000000000000000000480000000000000000000000000000000000000000000000000000000000000049000000000000000000000000000000000000000000000000000000000000004a000000000000000000000000000000000000000000000000000000000000004b000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000004d000000000000000000000000000000000000000000000000000000000000004e000000000000000000000000000000000000000000000000000000000000004f0000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000005100000000000000000000000000000000000000000000000000000000000000520000000000000000000000000000000000000000000000000000000000000053000000000000000000000000000000000000000000000000000000000000005400000000000000000000000000000000000000000000000000000000000000550000000000000000000000000000000000000000000000000000000000000056000000000000000000000000000000000000000000000000000000000000005700000000000000000000000000000000000000000000000000000000000000580000000000000000000000000000000000000000000000000000000000000059000000000000000000000000000000000000000000000000000000000000005a000000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000005c000000000000000000000000000000000000000000000000000000000000005d000000000000000000000000000000000000000000000000000000000000005e000000000000000000000000000000000000000000000000000000000000005f0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000620000000000000000000000000000000000000000000000000000000000000063000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000650000000000000000000000000000000000000000000000000000000000000066000000000000000000000000000000000000000000000000000000000000006700000000000000000000000000000000000000000000000000000000000000680000000000000000000000000000000000000000000000000000000000000069000000000000000000000000000000000000000000000000000000000000006a000000000000000000000000000000000000000000000000000000000000006b000000000000000000000000000000000000000000000000000000000000006c000000000000000000000000000000000000000000000000000000000000006d000000000000000000000000000000000000000000000000000000000000006e000000000000000000000000000000000000000000000000000000000000006f0000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000007100000000000000000000000000000000000000000000000000000000000000720000000000000000000000000000000000000000000000000000000000000073000000000000000000000000000000000000000000000000000000000000007400000000000000000000000000000000000000000000000000000000000000750000000000000000000000000000000000000000000000000000000000000076000000000000000000000000000000000000000000000000000000000000007700000000000000000000000000000000000000000000000000000000000000780000000000000000000000000000000000000000000000000000000000000079000000000000000000000000000000000000000000000000000000000000007a000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000007c000000000000000000000000000000000000000000000000000000000000007d000000000000000000000000000000000000000000000000000000000000007e000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000008100000000000000000000000000000000000000000000000000000000000000820000000000000000000000000000000000000000000000000000000000000083000000000000000000000000000000000000000000000000000000000000008400000000000000000000000000000000000000000000000000000000000000850000000000000000000000000000000000000000000000000000000000000086000000000000000000000000000000000000000000000000000000000000008700000000000000000000000000000000000000000000000000000000000000880000000000000000000000000000000000000000000000000000000000000089000000000000000000000000000000000000000000000000000000000000008a000000000000000000000000000000000000000000000000000000000000008b000000000000000000000000000000000000000000000000000000000000008c000000000000000000000000000000000000000000000000000000000000008d000000000000000000000000000000000000000000000000000000000000008e000000000000000000000000000000000000000000000000000000000000008f0000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000009100000000000000000000000000000000000000000000000000000000000000920000000000000000000000000000000000000000000000000000000000000093000000000000000000000000000000000000000000000000000000000000009400000000000000000000000000000000000000000000000000000000000000950000000000000000000000000000000000000000000000000000000000000096000000000000000000000000000000000000000000000000000000000000009700000000000000000000000000000000000000000000000000000000000000980000000000000000000000000000000000000000000000000000000000000099000000000000000000000000000000000000000000000000000000000000009a000000000000000000000000000000000000000000000000000000000000009b000000000000000000000000000000000000000000000000000000000000009c000000000000000000000000000000000000000000000000000000000000009d000000000000000000000000000000000000000000000000000000000000009e000000000000000000000000000000000000000000000000000000000000009f00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a100000000000000000000000000000000000000000000000000000000000000a200000000000000000000000000000000000000000000000000000000000000a300000000000000000000000000000000000000000000000000000000000000a400000000000000000000000000000000000000000000000000000000000000a500000000000000000000000000000000000000000000000000000000000000a600000000000000000000000000000000000000000000000000000000000000a700000000000000000000000000000000000000000000000000000000000000a800000000000000000000000000000000000000000000000000000000000000a900000000000000000000000000000000000000000000000000000000000000aa00000000000000000000000000000000000000000000000000000000000000ab00000000000000000000000000000000000000000000000000000000000000ac00000000000000000000000000000000000000000000000000000000000000ad00000000000000000000000000000000000000000000000000000000000000ae00000000000000000000000000000000000000000000000000000000000000af00000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000b100000000000000000000000000000000000000000000000000000000000000b200000000000000000000000000000000000000000000000000000000000000b300000000000000000000000000000000000000000000000000000000000000b400000000000000000000000000000000000000000000000000000000000000b500000000000000000000000000000000000000000000000000000000000000b600000000000000000000000000000000000000000000000000000000000000b700000000000000000000000000000000000000000000000000000000000000b800000000000000000000000000000000000000000000000000000000000000b900000000000000000000000000000000000000000000000000000000000000ba00000000000000000000000000000000000000000000000000000000000000bb00000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000000bd00000000000000000000000000000000000000000000000000000000000000be00000000000000000000000000000000000000000000000000000000000000bf00000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000c100000000000000000000000000000000000000000000000000000000000000c200000000000000000000000000000000000000000000000000000000000000c300000000000000000000000000000000000000000000000000000000000000c400000000000000000000000000000000000000000000000000000000000000c500000000000000000000000000000000000000000000000000000000000000c600000000000000000000000000000000000000000000000000000000000000c700000000000000000000000000000000000000000000000000000000000000c800000000000000000000000000000000000000000000000000000000000000c900000000000000000000000000000000000000000000000000000000000000ca00000000000000000000000000000000000000000000000000000000000000cb00000000000000000000000000000000000000000000000000000000000000cc00000000000000000000000000000000000000000000000000000000000000cd00000000000000000000000000000000000000000000000000000000000000ce00000000000000000000000000000000000000000000000000000000000000cf00000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000d100000000000000000000000000000000000000000000000000000000000000d200000000000000000000000000000000000000000000000000000000000000d300000000000000000000000000000000000000000000000000000000000000d400000000000000000000000000000000000000000000000000000000000000d500000000000000000000000000000000000000000000000000000000000000d600000000000000000000000000000000000000000000000000000000000000d700000000000000000000000000000000000000000000000000000000000000d800000000000000000000000000000000000000000000000000000000000000d900000000000000000000000000000000000000000000000000000000000000da00000000000000000000000000000000000000000000000000000000000000db00000000000000000000000000000000000000000000000000000000000000dc00000000000000000000000000000000000000000000000000000000000000dd00000000000000000000000000000000000000000000000000000000000000de00000000000000000000000000000000000000000000000000000000000000df00000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000e100000000000000000000000000000000000000000000000000000000000000e200000000000000000000000000000000000000000000000000000000000000e300000000000000000000000000000000000000000000000000000000000000e400000000000000000000000000000000000000000000000000000000000000e500000000000000000000000000000000000000000000000000000000000000e600000000000000000000000000000000000000000000000000000000000000e700000000000000000000000000000000000000000000000000000000000000e800000000000000000000000000000000000000000000000000000000000000e900000000000000000000000000000000000000000000000000000000000000ea00000000000000000000000000000000000000000000000000000000000000eb00000000000000000000000000000000000000000000000000000000000000ec00000000000000000000000000000000000000000000000000000000000000ed00000000000000000000000000000000000000000000000000000000000000ee00000000000000000000000000000000000000000000000000000000000000ef00000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000000f100000000000000000000000000000000000000000000000000000000000000f200000000000000000000000000000000000000000000000000000000000000f300000000000000000000000000000000000000000000000000000000000000f400000000000000000000000000000000000000000000000000000000000000f500000000000000000000000000000000000000000000000000000000000000f600000000000000000000000000000000000000000000000000000000000000f700000000000000000000000000000000000000000000000000000000000000f800000000000000000000000000000000000000000000000000000000000000f900000000000000000000000000000000000000000000000000000000000000fa00000000000000000000000000000000000000000000000000000000000000fb00000000000000000000000000000000000000000000000000000000000000fc00000000000000000000000000000000000000000000000000000000000000fd00000000000000000000000000000000000000000000000000000000000000fe00000000000000000000000000000000000000000000000000000000000000ff" + } +] diff --git a/src/test/data/bip138_payload.json b/src/test/data/bip138_payload.json new file mode 100644 index 000000000000..90ee8f6569a2 --- /dev/null +++ b/src/test/data/bip138_payload.json @@ -0,0 +1,18 @@ +[ + { + "description": "Bytes after terminator are ignored", + "valid": true, + "payload": "030001610080ff", + "items": [ + { + "type": 3, + "content": "61" + } + ] + }, + { + "description": "Payload with no content item.", + "valid": false, + "payload": "00" + } +] diff --git a/src/test/data/bip138_recipient_keys.json b/src/test/data/bip138_recipient_keys.json new file mode 100644 index 000000000000..f12adb0b99b6 --- /dev/null +++ b/src/test/data/bip138_recipient_keys.json @@ -0,0 +1,131 @@ +[ + { + "description": "Xpub with origin and multipath wildcard", + "descriptors": [ + "tr([58b7f8dc/48'/1'/0'/2']tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw/<0;1>/*)" + ], + "expected_keys": [ + "ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708" + ] + }, + { + "description": "Xpub with single-path wildcard", + "descriptors": [ + "tr([58b7f8dc/48'/1'/0'/2']tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw/0/*)" + ], + "expected_keys": [ + "ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708" + ] + }, + { + "description": "Xpub with bare wildcard (no preceding path)", + "descriptors": [ + "tr([58b7f8dc/48'/1'/0'/2']tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw/*)" + ], + "expected_keys": [ + "ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708" + ] + }, + { + "description": "Xpub with fixed deep derivation, no wildcard", + "descriptors": [ + "tr([58b7f8dc/48'/1'/0'/2']tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw/0/5)" + ], + "expected_keys": [ + "ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708" + ] + }, + { + "description": "Xpub with multipath, no wildcard", + "descriptors": [ + "tr([58b7f8dc/48'/1'/0'/2']tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw/<0;1>)" + ], + "expected_keys": [ + "ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708" + ] + }, + { + "description": "Bare xpub (no derivation, no wildcard); DISALLOWED", + "descriptors": [ + "tr([d4ab66f1/48'/1'/1'/2']tpubDFTxBKyUCgkwp5enwZh3t2FJ5AMJqmCWoh1NRT13qNYQb1iKTUrAG6u5gpsDYhG8cZGXouYWuQtzcuSVjPStTc4dwU6JqPMFtgaLGvSQXhi)" + ], + "expected_keys": null + }, + { + "description": "Compressed literal pubkey; DISALLOWED", + "descriptors": [ + "tr(02ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708)" + ], + "expected_keys": null + }, + { + "description": "X-only literal pubkey; DISALLOWED", + "descriptors": [ + "tr(ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708)" + ], + "expected_keys": null + }, + { + "description": "Uncompressed literal pubkey; DISALLOWED", + "descriptors": [ + "pk(04ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b517089e956909c4c07e8529f45f3ff8904d28df5a181619e21bdf748a896322530039)" + ], + "expected_keys": null + }, + { + "description": "Bare MuSig participant xpubs", + "descriptors": [ + "tr(musig(tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw,tpubDC5FSnBiZDMmhiuCmWAYsLwgLYrrT9rAqvTySfuCCrgsWz8wxMXUS9Tb9iVMvcRbvFcAHGkMD5Kx8koh4GquNGNTfohfk7pgjhaPCdXpoba))" + ], + "expected_keys": [ + "8b42cd4776376c82791b494155151f56c2d7b471e0c7a526a7ce60dd872e3867", + "ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708" + ] + }, + { + "description": "Derivation after MuSig aggregation", + "descriptors": [ + "tr(musig(tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw,tpubDC5FSnBiZDMmhiuCmWAYsLwgLYrrT9rAqvTySfuCCrgsWz8wxMXUS9Tb9iVMvcRbvFcAHGkMD5Kx8koh4GquNGNTfohfk7pgjhaPCdXpoba)/<0;1>/*)" + ], + "expected_keys": [ + "8b42cd4776376c82791b494155151f56c2d7b471e0c7a526a7ce60dd872e3867", + "ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708" + ] + }, + { + "description": "Same root in several descriptor sets contributes once", + "descriptors": [ + "tr(tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw/0/*)", + "tr(tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw/1/*)", + "tr(tpubDC5FSnBiZDMmhiuCmWAYsLwgLYrrT9rAqvTySfuCCrgsWz8wxMXUS9Tb9iVMvcRbvFcAHGkMD5Kx8koh4GquNGNTfohfk7pgjhaPCdXpoba/*)" + ], + "expected_keys": [ + "8b42cd4776376c82791b494155151f56c2d7b471e0c7a526a7ce60dd872e3867", + "ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708" + ] + }, + { + "description": "Root used both bare and derived is excluded", + "descriptors": [ + "wsh(or_i(pk(tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw/0/*),pk(tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw)))" + ], + "expected_keys": null + }, + { + "description": "Xpub root (03ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708) excluded by an opposite-parity literal in another descriptor set", + "descriptors": [ + "tr(tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw/*)", + "wpkh(02ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708)" + ], + "expected_keys": null + }, + { + "description": "MuSig participant exposed in a script leaf", + "descriptors": [ + "tr(musig(tpubDC5FSnBiZDMmhiuCmWAYsLwgLYrrT9rAqvTySfuCCrgsWz8wxMXUS9Tb9iVMvcRbvFcAHGkMD5Kx8koh4GquNGNTfohfk7pgjhaPCdXpoba,tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw)/0/*,pk(tpubDC5FSnBiZDMmhiuCmWAYsLwgLYrrT9rAqvTySfuCCrgsWz8wxMXUS9Tb9iVMvcRbvFcAHGkMD5Kx8koh4GquNGNTfohfk7pgjhaPCdXpoba))" + ], + "expected_keys": [ + "ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708" + ] + } +] diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp index c54f355a0c4f..eda5d1372ec4 100644 --- a/src/test/descriptor_tests.cpp +++ b/src/test/descriptor_tests.cpp @@ -1468,6 +1468,70 @@ void CheckUnused(const std::string& prv, const std::string& pub) BOOST_CHECK_EQUAL(pub_pubkeys.size() + pub_extpubs.size(), 1); } +std::set GetExtPubKeysForDescriptor(const std::string& desc, bool exclude_observable = false) +{ + FlatSigningProvider keys; + std::string error; + std::set ext_pubkeys; + auto parsed{Parse(desc, keys, error)}; + BOOST_REQUIRE_MESSAGE(!parsed.empty(), error); + for (const auto& parsed_desc : parsed) { + parsed_desc->GetExtPubKeys(ext_pubkeys, exclude_observable); + } + return ext_pubkeys; +} + +BOOST_AUTO_TEST_CASE(descriptor_get_extpubkeys_exclude_observable_test) +{ + const std::string xpub{"xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y"}; + const std::string xpub2{"xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL"}; + const std::string literal_pubkey{"03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"}; + + auto ext_pubkeys{GetExtPubKeysForDescriptor("wpkh(" + xpub + ")")}; + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + ext_pubkeys = GetExtPubKeysForDescriptor("wpkh(" + xpub + ")", /*exclude_observable=*/true); + BOOST_CHECK(ext_pubkeys.empty()); + + ext_pubkeys = GetExtPubKeysForDescriptor("wpkh([01234567]" + xpub + "/0)"); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + ext_pubkeys = GetExtPubKeysForDescriptor("wpkh([01234567]" + xpub + "/0)", /*exclude_observable=*/true); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + + ext_pubkeys = GetExtPubKeysForDescriptor("wpkh(" + xpub + "/*)"); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + ext_pubkeys = GetExtPubKeysForDescriptor("wpkh(" + xpub + "/*)", /*exclude_observable=*/true); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + + ext_pubkeys = GetExtPubKeysForDescriptor("wpkh(" + xpub + "/<0;1>)"); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + ext_pubkeys = GetExtPubKeysForDescriptor("wpkh(" + xpub + "/<0;1>)", /*exclude_observable=*/true); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + + ext_pubkeys = GetExtPubKeysForDescriptor("wsh(multi(1," + xpub + "/0," + literal_pubkey + "))"); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + ext_pubkeys = GetExtPubKeysForDescriptor("wsh(multi(1," + xpub + "/0," + literal_pubkey + "))", /*exclude_observable=*/true); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + + ext_pubkeys = GetExtPubKeysForDescriptor("tr(" + xpub + "/0/*,pk(" + xpub + "/1/*))"); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + ext_pubkeys = GetExtPubKeysForDescriptor("tr(" + xpub + "/0/*,pk(" + xpub + "/1/*))", /*exclude_observable=*/true); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 1); + + ext_pubkeys = GetExtPubKeysForDescriptor("tr(musig(" + xpub + "/0," + xpub2 + "/0))"); + BOOST_CHECK(ext_pubkeys.empty()); + ext_pubkeys = GetExtPubKeysForDescriptor("tr(musig(" + xpub + "/0," + xpub2 + "/0))", /*exclude_observable=*/true); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 2); + + ext_pubkeys = GetExtPubKeysForDescriptor("tr(musig(" + xpub + "," + xpub2 + "))"); + BOOST_CHECK(ext_pubkeys.empty()); + ext_pubkeys = GetExtPubKeysForDescriptor("tr(musig(" + xpub + "," + xpub2 + "))", /*exclude_observable=*/true); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 2); + ext_pubkeys = GetExtPubKeysForDescriptor("tr(musig(" + xpub + "," + xpub2 + ")/*)"); + BOOST_CHECK(ext_pubkeys.empty()); + ext_pubkeys = GetExtPubKeysForDescriptor("tr(musig(" + xpub + "," + xpub2 + ")/*)", /*exclude_observable=*/true); + BOOST_REQUIRE_EQUAL(ext_pubkeys.size(), 2); +} + // unused() descriptors don't produce scripts, so these need to be tested separately BOOST_AUTO_TEST_CASE(unused_descriptor_test) { diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 6ff1788b1b53..faa836291059 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -546,6 +546,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std:: // double spend txn pair in tx_mempool, template creation fails tx.vin[0].prevout.hash = txFirst[0]->GetHash(); + tx.vin[0].prevout.n = 0; tx.vin[0].scriptSig = CScript() << OP_1; tx.vout[0].nValue = BLOCKSUBSIDY - HIGHFEE; tx.vout[0].scriptPubKey = CScript() << OP_1; diff --git a/src/test/utf8_tests.cpp b/src/test/utf8_tests.cpp new file mode 100644 index 000000000000..ed6cb5b3d85f --- /dev/null +++ b/src/test/utf8_tests.cpp @@ -0,0 +1,59 @@ +// Copyright (c) The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +BOOST_AUTO_TEST_SUITE(utf8_tests) + +BOOST_AUTO_TEST_CASE(valid_utf8) +{ + BOOST_CHECK(IsValidUTF8({})); + std::array ascii; + for (size_t i{0}; i < ascii.size(); ++i) ascii[i] = i; + BOOST_CHECK(IsValidUTF8(ascii)); + + std::vector combined; + for (const std::string hex : {"c280", "dfbf", "e0a080", "ed9fbf", "ee8080", "efbfbf", "efbbbf", "f0908080", "f48fbfbf"}) { + BOOST_TEST_CONTEXT(hex) { + const auto text{ParseHex(hex)}; + BOOST_CHECK(IsValidUTF8(text)); + // Every proper, nonempty prefix of a multibyte character is incomplete. + for (size_t size{1}; size < text.size(); ++size) { + BOOST_CHECK(!IsValidUTF8(std::span{text}.first(size))); + } + combined.insert(combined.end(), text.begin(), text.end()); + combined.push_back(0); + } + } + BOOST_CHECK(IsValidUTF8(combined)); +} + +BOOST_AUTO_TEST_CASE(invalid_utf8) +{ + // Stray continuation bytes, overlong encodings, bad continuations, + // surrogate code points, and encodings beyond U+10FFFF. + for (const std::string hex : {"80", "bf", "c080", "c1bf", "c241", "e08080", "e228a1", + "eda080", "edbfbf", "f0808080", "f0908041", "f4908080", + "f5808080", "f888808080", "fc8480808080", "ff"}) { + BOOST_TEST_CONTEXT(hex) { + auto text{ParseHex(hex)}; + BOOST_CHECK(!IsValidUTF8(text)); + text.insert(text.begin(), 'a'); + text.push_back('z'); + BOOST_CHECK(!IsValidUTF8(text)); + } + } +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/univalue/include/univalue_utffilter.h b/src/univalue/include/univalue_utffilter.h index 41d8e6bb05f7..b2de934a6de1 100644 --- a/src/univalue/include/univalue_utffilter.h +++ b/src/univalue/include/univalue_utffilter.h @@ -4,6 +4,9 @@ #ifndef BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_UTFFILTER_H #define BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_UTFFILTER_H +#include +#include + #include /** @@ -20,36 +23,14 @@ class JSONUTF8StringFilter // Write single 8-bit char (may be part of UTF-8 sequence) void push_back(unsigned char ch) { - if (state == 0) { - if (ch < 0x80) // 7-bit ASCII, fast direct pass-through - str.push_back(ch); - else if (ch < 0xc0) // Mid-sequence character, invalid in this state - is_valid = false; - else if (ch < 0xe0) { // Start of 2-byte sequence - codepoint = (ch & 0x1f) << 6; - state = 6; - } else if (ch < 0xf0) { // Start of 3-byte sequence - codepoint = (ch & 0x0f) << 12; - state = 12; - } else if (ch < 0xf8) { // Start of 4-byte sequence - codepoint = (ch & 0x07) << 18; - state = 18; - } else // Reserved, invalid - is_valid = false; - } else { - if ((ch & 0xc0) != 0x80) // Not a continuation, invalid - is_valid = false; - state -= 6; - codepoint |= (ch & 0x3f) << state; - if (state == 0) - push_back_u(codepoint); - } + if (surpair) // A surrogate pair must consist of adjacent Unicode escapes. + is_valid = false; + // Preserve raw bytes so validation cannot normalize an invalid encoding. + str.push_back(char(ch)); } // Write codepoint directly, possibly collating surrogate pairs void push_back_u(unsigned int codepoint_) { - if (state) // Only accept full codepoints in open state - is_valid = false; if (codepoint_ >= 0xD800 && codepoint_ < 0xDC00) { // First half of surrogate pair if (surpair) // Two subsequent surrogate pair openers - fail is_valid = false; @@ -58,7 +39,7 @@ class JSONUTF8StringFilter } else if (codepoint_ >= 0xDC00 && codepoint_ < 0xE000) { // Second half of surrogate pair if (surpair) { // Open surrogate pair, expect second half // Compute code point from UTF-16 surrogate pair - append_codepoint(0x10000 | ((surpair - 0xD800)<<10) | (codepoint_ - 0xDC00)); + append_codepoint(0x10000 + ((surpair - 0xD800)<<10) + (codepoint_ - 0xDC00)); surpair = 0; } else // Second half doesn't follow a first half - fail is_valid = false; @@ -73,17 +54,13 @@ class JSONUTF8StringFilter // No open sequences, no open surrogate pairs, etc bool finalize() { - if (state || surpair) + if (surpair) is_valid = false; - return is_valid; + return is_valid && IsValidUTF8(MakeUCharSpan(str)); } private: std::string &str; bool is_valid{true}; - // Current UTF-8 decoding state - unsigned int codepoint{0}; - int state{0}; // Top bit to be filled in for next UTF-8 byte, or 0 - // Keep track of the following state to handle the following section of // RFC4627: // @@ -107,11 +84,13 @@ class JSONUTF8StringFilter str.push_back((char)(0xE0 | (codepoint_ >> 12))); str.push_back((char)(0x80 | ((codepoint_ >> 6) & 0x3F))); str.push_back((char)(0x80 | (codepoint_ & 0x3F))); - } else if (codepoint_ <= 0x1FFFFF) { + } else if (codepoint_ <= 0x10FFFF) { str.push_back((char)(0xF0 | (codepoint_ >> 18))); str.push_back((char)(0x80 | ((codepoint_ >> 12) & 0x3F))); str.push_back((char)(0x80 | ((codepoint_ >> 6) & 0x3F))); str.push_back((char)(0x80 | (codepoint_ & 0x3F))); + } else { + is_valid = false; } } }; diff --git a/src/univalue/test/unitester.cpp b/src/univalue/test/unitester.cpp index e82ea74dec48..60cd19e2db88 100644 --- a/src/univalue/test/unitester.cpp +++ b/src/univalue/test/unitester.cpp @@ -4,7 +4,6 @@ // file COPYING or https://opensource.org/licenses/mit-license.php. #include - #include #include #include @@ -66,6 +65,7 @@ #include #include #include +#include static std::string rtrim(std::string s) { @@ -177,6 +177,40 @@ void unescape_unicode_test() testResult = val.read("[\"\\ud834\\udd61\"]"); assert(testResult); assert(val[0].get_str() == "\xf0\x9d\x85\xa1"); + // The offset for supplementary characters must carry into the next plane. + assert(val.read("[\"\\ud840\\udc00\"]")); + assert(val[0].get_str() == "\xf0\xa0\x80\x80"); // U+20000 + assert(val.read("[\"\\udbff\\udfff\"]")); + assert(val[0].get_str() == "\xf4\x8f\xbf\xbf"); // U+10FFFF +} + +void utf8_test() +{ + UniValue val; + for (const std::string text : {"ascii", "\xc2\x80", "\xed\x9f\xbf", "\xee\x80\x80", + "\xf0\x90\x80\x80", "\xf4\x8f\xbf\xbf"}) { + assert(val.read("\"" + text + "\"")); + assert(val.get_str() == text); + assert(val.read("{\"" + text + "\":0}")); + assert(val.getKeys()[0] == text); + } + + // Invalid UTF-8 must be rejected, not normalized into valid characters. + for (const std::string text : {"\xc0\x80", "\xe0\x80\x80", "\xf0\x80\x80\x80", + "\xed\xa0\x80", "\xed\xa0\x80\xed\xb0\x80", + "\xf4\x90\x80\x80", "\xf8\x88\x80\x80\x80", + "\x80", "\xc2", "\xe2\x28\xa1"}) { + assert(!val.read("\"" + text + "\"")); + assert(!val.read("{\"" + text + "\":0}")); + } + + // Escapes cannot complete a raw UTF-8 sequence or an interrupted surrogate pair. + for (const std::string text : {"\xc2\\u0080", "\xc2\\n", "\\ud800x\\udc00", + "\\ud800\\n\\udc00", "\\ud800\\u0041\\udc00", + "\\ud800\xc2\xa2\\udc00", "\xed\xa0\x80\\udc00", + "\\ud800\xed\xb0\x80"}) { + assert(!val.read("\"" + text + "\"")); + } } void no_nul_test() @@ -193,6 +227,7 @@ int main(int argc, char* argv[]) } unescape_unicode_test(); + utf8_test(); no_nul_test(); return 0; diff --git a/src/util/utf8.h b/src/util/utf8.h new file mode 100644 index 000000000000..4821728c65b4 --- /dev/null +++ b/src/util/utf8.h @@ -0,0 +1,32 @@ +// Copyright (c) The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_UTIL_UTF8_H +#define BITCOIN_UTIL_UTF8_H + +#include +#include +#include + +/** Validate UTF-8 as specified by RFC 3629, including empty strings and embedded NULs. */ +inline bool IsValidUTF8(std::span text) +{ + for (size_t pos{0}; pos < text.size();) { + const uint8_t first{text[pos++]}; + if (first < 0x80) continue; + const size_t following{first >= 0xc2 && first <= 0xdf ? 1U : + first >= 0xe0 && first <= 0xef ? 2U : + first >= 0xf0 && first <= 0xf4 ? 3U : 0U}; + if (following == 0 || following > text.size() - pos) return false; + // Exclude overlong encodings, surrogate code points, and values above U+10FFFF. + if ((first == 0xe0 && text[pos] < 0xa0) || (first == 0xed && text[pos] >= 0xa0) || + (first == 0xf0 && text[pos] < 0x90) || (first == 0xf4 && text[pos] >= 0x90)) return false; + for (size_t i{0}; i < following; ++i) { + if ((text[pos++] & 0xc0) != 0x80) return false; + } + } + return true; +} + +#endif // BITCOIN_UTIL_UTF8_H diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt index 1ecacf3af5bf..9a04c4a91a5c 100644 --- a/src/wallet/CMakeLists.txt +++ b/src/wallet/CMakeLists.txt @@ -9,7 +9,10 @@ add_library(bitcoin_wallet STATIC EXCLUDE_FROM_ALL context.cpp crypter.cpp db.cpp + descriptor_info.cpp + descriptor_recombiner.cpp dump.cpp + encrypted_backup.cpp export.cpp external_signer_scriptpubkeyman.cpp feebumper.cpp diff --git a/src/wallet/descriptor_info.cpp b/src/wallet/descriptor_info.cpp new file mode 100644 index 000000000000..0e2940e0046e --- /dev/null +++ b/src/wallet/descriptor_info.cpp @@ -0,0 +1,32 @@ +// Copyright (c) The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include + +namespace wallet { + +UniValue DescriptorInfoToUniValue(const WalletDescriptorInfo& info) +{ + UniValue obj(UniValue::VOBJ); + obj.pushKV("desc", info.descriptor); + obj.pushKV("timestamp", info.creation_time); + obj.pushKV("active", info.active); + if (info.internal.has_value()) { + obj.pushKV("internal", info.internal.value()); + } + if (info.range.has_value()) { + UniValue range(UniValue::VARR); + range.push_back(info.range->first); + // range_end is exclusive internally, display as inclusive (hence -1) + range.push_back(info.range->second - 1); + obj.pushKV("range", std::move(range)); + obj.pushKV("next", info.next_index); + obj.pushKV("next_index", info.next_index); + } + return obj; +} + +} // namespace wallet diff --git a/src/wallet/descriptor_info.h b/src/wallet/descriptor_info.h new file mode 100644 index 000000000000..6bf37e625533 --- /dev/null +++ b/src/wallet/descriptor_info.h @@ -0,0 +1,30 @@ +// Copyright (c) The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_WALLET_DESCRIPTOR_INFO_H +#define BITCOIN_WALLET_DESCRIPTOR_INFO_H + +#include + +class UniValue; + +namespace wallet { + +/** + * Information about a wallet descriptor, used for serialization to JSON. + * This struct captures all the metadata needed for listdescriptors output + * and importdescriptors input. + */ +using WalletDescriptorInfo = WalletDescInfo; + +/** + * Convert a WalletDescriptorInfo to a UniValue object. + * The output format is compatible with both listdescriptors output and + * importdescriptors input. + */ +UniValue DescriptorInfoToUniValue(const WalletDescriptorInfo& info); + +} // namespace wallet + +#endif // BITCOIN_WALLET_DESCRIPTOR_INFO_H diff --git a/src/wallet/descriptor_recombiner.cpp b/src/wallet/descriptor_recombiner.cpp new file mode 100644 index 000000000000..02205171c008 --- /dev/null +++ b/src/wallet/descriptor_recombiner.cpp @@ -0,0 +1,148 @@ +// Copyright (c) The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or https://opensource.org/license/mit/. + +#include + +#include