diff --git a/bip-0352.mediawiki b/bip-0352.mediawiki new file mode 100644 index 0000000000..ce8aa74795 --- /dev/null +++ b/bip-0352.mediawiki @@ -0,0 +1,490 @@ +
+  BIP: 352
+  Layer: Applications
+  Title: Silent Payments
+  Author: josibake 
+          Ruben Somsen 
+  Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0352
+  Status: Draft
+  Type: Informational
+  Created: 2023-03-09
+  License: BSD-2-Clause
+
+ +== Introduction == + +=== Abstract === + +This document specifies a protocol for static payment addresses in Bitcoin without on-chain linkability of payments or a need for on-chain notifications. + +=== Copyright === + +This BIP is licensed under the BSD 2-clause license. + +=== Motivation === + +Using a new address for each Bitcoin transaction is a crucial aspect of maintaining privacy. This often requires a secure interaction between sender and receiver so that the receiver can hand out a fresh address, a batch of fresh addresses, or a method for the sender to generate addresses on-demand, such as an xpub. + +However, interaction is often infeasible and in many cases undesirable. To solve for this, various protocols have been proposed which use a static payment address and notifications sent via the blockchain'''Why not use out-of-band notifications''' Out of band notifications (e.g. using something other than the Bitcoin blockchain) have been proposed as a way of addressing the privacy and cost concerns of using the Bitcoin blockchain as a messaging layer. This, however, simply moves the privacy and cost concerns somewhere else and increases the risk of losing money due to a notification not being reliably delivered, or even censored, and makes this notification data critical for backup to recover funds.. These protocols eliminate the need for interaction, but at the expense of increased costs for one-time payments and a noticeable footprint in the blockchain, potentially revealing metadata about the sender and receiver. Notification schemes also allow the receiver to link all payments from the same sender, compromising sender privacy. + +This proposal aims to address the limitations of these current approaches by presenting a solution that eliminates the need for interaction, eliminates the need for notifications, and protects both sender and receiver privacy. These benefits come at the cost of requiring wallets to scan the blockchain in order to detect payments. This added requirement is generally feasible for full nodes but poses a challenge for light clients. While it is possible today to implement a privacy-preserving light client at the cost of increased bandwidth, light client support is considered an area of open research (see [[#appendix-a-light-client-support|Appendix A: Light Client Support]]). + +The design keeps collaborative transactions such as CoinJoins and inputs with MuSig and FROST keys in mind, but it is recommended that the keys of all inputs of a transaction belong to the same entity as there is no formal proof that the protocol is secure in a collaborative setting. + +== Goals == + +We aim to present a protocol which satisifies the following properties: + +* No increase in the size or cost of transactions +* Resulting transactions blend in with other bitcoin transactions and can't be distinguished +* Transactions can't be linked to a silent payment address by an outside observer +* No sender-receiver interaction required +* No linking of multiple payments to the same sender +* Each silent payment goes to a unique address, avoiding accidental address reuse +* Supports payment labeling +* Uses existing seed phrase or descriptor methods for backup and recovery +* Separates scanning and spending responsibilities +* Compatible with other spending protocols, such as CoinJoin +* Light client/SPV wallet support +* Protocol is upgradeable + +== Overview == + +We first present an informal overview of the protocol. In what follows, uppercase letters represent public keys, lowercase letters represent private keys, ''||'' refers to byte concatenation, ''G'' represents the generator point for ''secp256k1'', and ''n'' represents the curve order for ''secp256k1''. Each section of the overview is incomplete on its own and is meant to build on the previous section in order to introduce and briefly explain each aspect of the protocol. For the full protocol specification, see [[#specification|Specification]]. + +''' Simple case ''' + +Bob publishes a public key ''B'' as a silent payment address. Alice discovers Bob's silent payment address, selects a UTXO with private key ''a'', public key ''A'' and creates a destination output ''P'' for Bob in the following manner: + +* Let ''P = B + hash(a·B)·G'' +* Encode ''P'' as a [https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki BIP341] taproot output + +Since ''a·B == b·A'' ([https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman Elliptic-curve Diffie–Hellman]), Bob scans with his private key ''b'' by collecting the input public keys for each transaction with at least one unspent taproot output and performing the ECDH calculation until ''P'' is found (i.e. calculating ''P = B + hash(b·A)·G'' and seeing that ''P'' is present in the transaction outputs). + +''' Creating more than one output ''' + +In order to allow Alice to create more than one output for Bob'''Why allow for more than one output?''' Allowing Alice to break her payment to Bob into multiple amounts opens up a number of privacy improving techniques for Alice, making the transaction look like a CoinJoin or better hiding the change amount by splitting both the payment and change outputs into multiple amounts. It also allows for Alice and Carol to both have their own unique output paying Bob in the event they are in a collaborative transaction and both paying Bob's silent payment address., we include an integer in the following manner: + +* Let ''k = 0'' +* Let ''P0 = B + hash(a·B || k)·G'' +* For additional outputs: +** Increment ''k'' by one (''k++'') +** Let ''Pi = B + hash(a·B || k)·G'' + +Bob detects this output the same as before by searching for ''P0 = B + hash(b·A || 0)·G''. Once he detects the first output, he must: + +* Check for ''P1 = B + hash(b·A || 1)·G'' +* If ''P1'' is not found, stop +* If ''P1'' is found, continue to check for ''P2'' and so on until an additional output is not found + +Since Bob will only perform these subsequent checks after a transaction with at least one output paying him is found, the increase to his overall scanning requirement is negligible. It should also be noted that the order in which these outputs appear in the transaction does not affect the outcome. + +''' Preventing address reuse ''' + +If Alice were to use a different UTXO from the same public key ''A'' for a subsequent payment to Bob, she would end up deriving the same destinations ''Pi''. To prevent this, Alice should include an input hash in the following manner: + +* Let ''input_hash = hash(outpoint || A)'''''Why include A in the input hash calculation?''' By committing to A in input hash, this ensures that the sender cannot maliciously choose a private key ''a′'' in a subsequent transaction where ''a′ = input_hash·a / input_hash′'', which would force address reuse in the protocol. +* Let ''P0 = B + hash(input_hash·a·B || 0)·G'' + +Bob must calculate the same ''input_hash'' when scanning. + +''' Using all inputs ''' + +In our simplified example we have been referring to Alice's transactions as having only one input ''A'', but in reality a Bitcoin transaction can have many inputs. Instead of requiring Alice to pick a particular input and requiring Bob to check each input separately, we can instead require Alice to perform the tweak with the sum of the input public keys'''What about inputs without public keys?''' Inputs without public keys can still be spent in the transaction but are simply ignored in the silent payments protocol.. This significantly reduces Bob's scanning requirement, makes light client support more feasible'''How does using all inputs help light clients?''' If Alice uses a random input for the tweak, Bob necessarily has to have access to and check all transaction inputs, which requires performing an ECC multiplication per input. If instead Alice performs the tweak with the sum of the input public keys, Bob only needs the summed 33 byte public key per transaction and only does one ECC multiplication per transaction. Bob can then use BIP158 block filters to determine if any of the outputs exist in a block and thus avoids downloading transactions which don't belong to him. It is still an open question as to how Bob can source the 33 bytes per transaction in a trustless manner, see [[#appendix-a-light-client-support|Appendix A: Light Client Support]] for more details., and protects Alice's privacy in collaborative transaction protocols such as CoinJoin'''Why does using all inputs matter for CoinJoin?''' If Alice uses a random input to create the output for Bob, this necessarily reveals to Bob which input Alice has control of. If Alice is paying Bob as part of a CoinJoin, this would reveal which input belongs to her, degrading the anonymity set of the CoinJoin and giving Bob more information about Alice. If instead all inputs are used, Bob has no way of knowing which input(s) belong to Alice. This comes at the cost of increased complexity as the CoinJoin participants now need to coordinate to create the silent payment output and would need to use [https://gist.github.com/RubenSomsen/be7a4760dd4596d06963d67baf140406 Blind Diffie–Hellman] to prevent the other participants from learning who Alice is paying. Note it is currently not recommended to use this protocol for CoinJoins due to a lack of a formal security proof.. + +Alice performs the tweak with the sum of her input private keys in the following manner: + +* Let ''A = A0 + A1 + ... + An'' +* Let ''input_hash = hash(outpointL || A)'', where ''outpointL'' is the smallest outpoint lexicographically'''Why use the lexicographically smallest outpoint for the hash?''' Recall that the purpose of including the input hash is so that the sender and receiver can both come up with a deterministic nonce that ensures that a unique address is generated each time, even when reusing the same scriptPubKey as an input. Choosing the smallest outpoint lexicographically satisifes this requirement, while also ensuring that the generated output is not dependent on the final ordering of inputs in the transaction. Using a single outpoint also works well with memory constrained devices (such as hardware signing devices) as it does not require the device to have the entire transaction in memory in order to generate the silent payment output. +* Let ''a = a0 + a1 + ... + an'' +* Let ''P0 = B + hash(input_hash·a·B || 0)·G'' + +''' Spend and Scan Key ''' + +Since Bob needs his private key ''b'' to check for incoming payments, this requires ''b'' to be exposed to an online device. To minimize the risks involved, Bob can instead publish an address of the form ''(Bscan, Bspend)''. This allows Bob to keep ''bspend'' in offline cold storage and perform the scanning with the public key ''Bspend'' and private key ''bscan''. Alice performs the tweak using both of Bob's public keys in the following manner: + +* Let ''P0 = Bspend + hash(input_hash·a·Bscan || 0)·G'' + +Bob detects this payment by calculating ''P0 = Bspend + hash(input_hash·bscan·A)·G'' with his online device and can spend from his cold storage signing device using ''(bspend + hash(input_hash·bscan·A)) mod n'' as the private key. + +''' Labels ''' + +For a single silent payment address of the form ''(Bscan, Bspend)'', Bob may wish to differentiate incoming payments. Naively, Bob could publish multiple silent payment addresses, but this would require him to scan for each one, which becomes prohibitively expensive. Instead, Bob can label his spend public key ''Bspend'' with an integer ''m'' in the following way: + +* Let ''Bm = Bspend + hash(bscan || m)·G'' where m is an incrementable integer starting from 1 +* Publish ''(Bscan, B1)'', ''(Bscan, B2)'' etc. + +Alice performs the tweak as before using one of the published ''(Bscan, Bm)'' pairs. Bob detects the labeled payment in the following manner: + +* Let ''P0 = Bspend + hash(input_hash·bscan·A || 0)·G'' +* Subtract ''P0'' from each of the transaction outputs and check if the remainder matches any of the labels (''hash(bscan || 1)·G'', ''hash(bscan || 2)·G'' etc.) that the wallet has previously used + +It is important to note that an outside observer can easily deduce that each published ''(Bscan, Bm)'' pair is owned by the same entity as each published address will have ''Bscan'' in common. As such, labels are not meant as a way for Bob to manage separate identities, but rather a way for Bob to determine the source of an incoming payment. + +''' Labels for change ''' + +Bob can also use labels for managing his own change outputs. We reserve ''m = 0'' for this use case. This gives Bob an alternative to using BIP32 for managing change, while still allowing him to know which of his unspent outputs were change when recovering his wallet from the master key. It is important that the wallet never hands out the label with ''m = 0'' in order to ensure nobody else can create payments that are wrongly labeled as change. + +While the use of labels is optional, every receiving silent payments wallet should at least scan for the change label when recovering from backup in order to ensure maximum cross-compatibility. + +== Specification == + +We use the following functions and conventions: + +* ''outpoint'' (36 bytes): the COutPoint of an input (32-byte txid, least significant byte first || 4-byte vout, least significant byte first)'''Why are outpoints little-endian?''' Despite using big endian throughout the rest of the BIP, outpoints are sorted and hashed matching their transaction serialization, which is little-endian. This allows a wallet to parse a serialized transaction for use in silent payments without needing to re-order the bytes when computing the input hash. Note: despite outpoints being stored and serialized as little-endian, the transaction hash (txid) is always displayed as big-endian. +* ser32(i): serializes a 32-bit unsigned integer ''i'' as a 4-byte sequence, most significant byte first. +* ser256(p): serializes the integer p as a 32-byte sequence, most significant byte first. +* serP(P): serializes the coordinate pair P = (x,y) as a byte sequence using SEC1's compressed form: (0x02 or 0x03) || ser256(x), where the header byte depends on the parity of the omitted Y coordinate. +* hash(x): refers to SHA256(x) + +For everything not defined above, we use the notation from [https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#specification BIP340]. + +=== Versions === + +This document defines version 0 (''sp1q''). Version is communicated through the address in the same way as Segwit addresses. Future upgrades to silent payments will require a new version. As much as possible, future upgrades should support receiving from older wallets (e.g. a silent payments v0 wallet can send to both v0 and v1 addresses). Any changes that break compatibility with older silent payment versions should be a new BIP. + +Future silent payments versions will use the following scheme: + +{| class="wikitable" +|- +! +!0 +!1 +!2 +!3 +!4 +!5 +!6 +!7 +!Compatibility +|- +!+0 +|q||p||z||r||y||9||x||8||rowspan="4" | backwards compatible +|- +!+8 +|g||f||2||t||v||d||w||0 +|- +!+16 +|s||3||j||n||5||4||k||h +|- +!+24 +|c||e||6||m||u||a||7|| - +|} + +''v31'' (l) is reserved for a backwards incompatible change, if needed. For silent payments v0: + +* If the receiver's silent payment address version is: +** ''v0'': check that the data part is exactly 66-bytes. Otherwise, fail +** ''v1'' through ''v30'': read the first 66-bytes of the data part and discard the remaining bytes +** ''v31'': fail +* Receiver addresses are always [https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki BIP341] taproot outputs'''Why only taproot outputs?''' Providing too much optionality for the protocol makes it difficult to implement and can be at odds with the goal of providing the best privacy. Limiting to taproot outputs helps simplify the implementation significantly while also putting users in the best eventual anonymity set. +* The sender should sign with one of the sighash flags ''DEFAULT'', ''ALL'', ''SINGLE'', ''NONE'' (''ANYONECANPAY'' is unsafe). It is strongly recommended implementations use ''SIGHASH_ALL'' (''SIGHASH_DEFAULT'' for taproot inputs) when possible'''Why is it unsafe to use ''SIGHASH_ANYONECANPAY''?''' Since the output address for the receiver is derived from the sum of the [[#inputs-for-shared-secret-derivation|Inputs For Shared Secret Derivation]] public keys, the inputs must not change once the sender has signed the transaction. If the inputs are allowed to change after the fact, the receiver will not be able to calculate the shared secret needed to find and spend the output. It is currently an open question on how a future version of silent payments could be made to work with new sighash flags such as ''SIGHASH_GROUP'' and ''SIGHASH_ANYPREVOUT''. +* Inputs used to derive the shared secret are from the ''[[#inputs-for-shared-secret-derivation|Inputs For Shared Secret Derivation]]'' list + +=== Scanning silent payment eligible transactions === + +For silent payments v0 a transaction MUST be scanned if and only if all of the following are true: + +* The transaction contains at least one BIP341 taproot output (note: spent transactions optionally can be skipped by only considering unspent taproot outputs) +* The transaction has at least one input from the ''[[#inputs-for-shared-secret-derivation|Inputs For Shared Secret Derivation]]'' list +* The transaction does not spend an output with SegWit version > 1'''Why skip transactions that spend SegWit version > 1?''' Skipping transactions that spend unknown output scripts allows us to have a clean upgrade path for silent payments by avoiding the need to scan the same transaction multiple times with different rule sets. If a new SegWit version is added in the future and silent payments v1 is released with support, we would want to avoid having to first scan the transaction with the silent payment v0 rules and then again with the silent payment v1 rules. Note: this restriction only applies to the inputs of a transaction. + +=== Address encoding === + +A silent payment address is constructed in the following manner: + +* Let ''Bscan, bscan = Receiver's scan public key and corresponding private key'' +* Let ''Bspend, bspend = Receiver's spend public key and corresponding private key'' +* Let ''Bm = Bspend + hash(ser256(bscan) || ser32(m))·G'', where ''hash(ser256(bscan) || ser32(m))·G'' an optional integer tweak for labeling +** If no label is applied then ''Bm = Bspend'' +* The final address is a [https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki Bech32m] encoding of: +** The human-readable part "sp" for mainnet, "tsp" for testnets (e.g. signet, testnet) +** The data-part values: +*** The character "q", to represent a silent payment address of version 0 +*** The 66 byte concatenation of the receiver's public keys, ''serP(Bscan) || serP(Bm)'' + +Note: [https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki BIP173] imposes a 90 character limit for Bech32 strings, whereas a silent payment address requires ''at least'' 117 characters ''' Why do silent payment addresses need at least 117 characters?''' A silent payment address is a bech32m encoding comprised of the following parts: + + +* HRP [2-3 characters] +* separator [1 character] +* version [1-2 characters] +* payload, 66 bytes concatenated pubkeys [ceil(66*8/5) = 106 characters] +* checksum [6 characters] + + +For a silent payments v0 address, this results in a 117 character address when using a 3 character HRP. Future versions of silent payment addresses may add to the payload, which is why a 1023 character limit is suggested.. Additionally, since higher versions may add to the data field, it is recommended implementations use a limit of 1023 characters (see [https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#checksum-design BIP173: Checksum design] for more details). + +=== Inputs For Shared Secret Derivation === + +While any UTXO with known output scripts can be used to fund the transaction, the sender and receiver MUST use inputs from the following list when deriving the shared secret: + +* ''P2TR'' +* ''P2WPKH'' +* ''P2SH-P2WPKH'' +* ''P2PKH'' + +Inputs with conditional branches or multiple public keys (e.g. ''CHECKMULTISIG'') are excluded from shared secret derivation as this introduces malleability and would allow a sender to re-sign with a different set of public keys after the silent payment output has been derived. This is not a concern when the sender controls all of the inputs, but is an issue for CoinJoins and other collaborative protocols, where a malicious participant can participate in deriving the silent payment address with one set of keys and then re-broadcast the transaction with signatures for a different set of public keys. P2TR can have hidden conditional branches (script path), but we work around this by using only the output public key. + +For all of the output types listed, only X-only and compressed public keys are permitted''' Why only compressed public keys ''' Technically speaking, you could construct non-standard P2WPKH outputs using uncompressed or hybrid public keys, but why would you (see [https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#restrictions-on-public-key-type BIP143: Restrictions on public key type])? For P2PKH, uncompressed (even more so hybrid) public keys are less common than compressed keys and generally considered to be a bad idea due to their blockspace inefficiency.. + +''' P2TR ''' + +'' Keypath spend '' + + witness: + scriptSig: (empty) + scriptPubKey: 0 <32-byte-x-only-key> + (0x5120{32-byte-x-only-key}) + +The sender uses the private key corresponding to the taproot output key (i.e. the tweaked private key). This can be a single private key or an aggregate key (e.g. taproot outputs using MuSig or FROST)'''Are key aggregation techniques like FROST and MuSig supported?''' While we do not recommend it due to lack of a security proof (except if all participants are trusted or are the same entity), any taproot output able to do a key path theoretically is supported. Any offline key aggregation technique can be used, such as FROST or MuSig. This would require participants to perform the ECDH step collaboratively e.g. ''ECDH = a0·Bscan + a1·Bscan + ... + at·Bscan'' and ''P = Bspend + hash(input_hash·ECDH || 0)·G''. Additionally, it may be necessary for the participants to provide a DLEQ proof to ensure they are not acting maliciously.. The receiver obtains the public key from the ''scriptPubKey'' (i.e. the taproot output key). + +'' Script path spend '' + + witness: + scriptSig: (empty) + scriptPubKey: 0 <32-byte-x-only-key> + (0x5120{32-byte-x-only-key}) + +Same as a keypath spend, the sender MUST use the private key corresponding to the taproot output key. If this key is not available, the output cannot be included as an input to the transaction. Same as a keypath spend, the receiver obtains the public key from the ''scriptPubKey'' (i.e. the taproot output key)''' Why not skip all taproot script path spends? ''' This causes malleability issues for CoinJoins. If the silent payments protocol skipped taproot script path spends, this would allow an attacker to join a CoinJoin round, participate in deriving the silent payment address using the tweaked private key for a key path spend, and then broadcast their own version of the transaction using the script path spend. If the receiver were to only consider key path spends, they would skip the attacker's script path spend input when deriving the shared secret and not be able to find the funds. Additionally, there may be scenarios where the can perform ECDH with the key path private key but spends the output using the script path.. + +The one exception is script path spends that use NUMS point ''H'' as their internal key (where ''H'' is constructed by taking the hash of the standard uncompressed encoding of the secp256k1 base point ''G'' as X coordinate, see [https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#constructing-and-spending-taproot-outputs BIP341: Constructing and spending Taproot outputs] for more details), in which case the input will be skipped for the purposes of shared secret derivation'''Why skip outputs with H as the internal taproot key?''' If use cases get popularized where the taproot key path cannot be used, these outputs can still be included without getting in the way of making a silent payment, provided they specifically use H as their internal taproot key.. The receiver determines whether or not to skip the input by checking in the control block if the taproot internal key is equal to ''H''. + +''' P2WPKH ''' + + witness: <33-byte-compressed-key> + scriptSig: (empty) + scriptPubKey: 0 <20-byte-key-hash> + (0x0014{20-byte-key-hash}) + +The sender performs the tweak using the private key for the output and the receiver obtains the public key as the last witness item. + +''' P2SH-P2WPKH ''' + + witness: <33-byte-compressed-key> + scriptSig: <0 <20-byte-key-hash>> + (0x160014{20-byte-key-hash}) + scriptPubKey: HASH160 <20-byte-script-hash> EQUAL + (0xA914{20-byte-script-hash}87) + +The sender performs the tweak using the private key for the nested ''P2WPKH'' output and the receiver obtains the public key as the last witness item. + +''' P2PKH ''' + + scriptSig: <33-byte-compressed-key> + scriptPubKey: OP_DUP HASH160 <20-byte-key-hash> OP_EQUALVERIFY OP_CHECKSIG + (0x76A914{20-byte-key-hash}88AC) + +The receiver obtains the public key from the ''scriptSig''. The receiver MUST parse the ''scriptSig'' for the public key, even if the ''scriptSig'' does not match the template specified (e.g. OP_DROP ). This is to address the [https://en.bitcoin.it/wiki/Transaction_malleability third-party malleability of ''P2PKH'' ''scriptSigs'']. + +=== Input hash === + +The sender and receiver MUST calculate an outpoints hash for the transaction in the following manner: + +* Let ''A = A0 + A1 + ... + An'', where each ''Ai'' is the public key of an input from the ''[[#inputs-for-shared-secret-derivation|Inputs For Shared Secret Derivation]]'' list +* Let ''input_hash = hash(outpointL || A)'', where ''outpointL'' is the smallest outpoint lexicographically by txid and vout used in the transaction + +=== Sender === + +==== Selecting inputs ==== + +The sending wallet performs coin selection as usual with the following restrictions: + +* At least one input MUST be from the ''[[#inputs-for-shared-secret-derivation|Inputs For Shared Secret Derivation]]'' list +* Exclude inputs with SegWit version > 1 (see ''[[#scanning-silent-payment-eligible-transactions|Scanning silent payment eligible transactions]]'') +* For each taproot output spent the sending wallet MUST have access to the private key corresponding to the taproot output key, unless ''H'' is used as the internal public key + +==== Creating outputs ==== + +After the inputs have been selected, the sender can create one or more outputs for one or more silent payment addresses in the following manner: + +* Generate the ''input_hash'' with the smallest outpoint lexicographically, using the method described above +* Collect the private keys for each input from the ''[[#inputs-for-shared-secret-derivation|Inputs For Shared Secret Derivation]]'' list +* For each private key ''ai'' corresponding to a [https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki BIP341] taproot output, check that the private key produces a point with an even Y coordinate and negate the private key if not'''Why do taproot private keys need to be checked?''' Recall from [https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki BIP340] that each X-only public key has two corresponding private keys, ''d'' and ''n - d''. To maintain parity between sender and receiver, it is necessary to use the private key corresponding to the even Y coordinate when performing the ECDH step since the receiver will assume the even Y coordinate when summing the taproot X-only public keys. +* Let ''a = a0 + a1 + ... + an'', where each ''ai'' has been negated if necessary +* Group receiver silent payment addresses by ''Bscan'' (e.g. each group consists of one ''Bscan'' and one or more ''Bm'') +* For each group: +** Let ''ecdh_shared_secret = input_hash·a·Bscan'' +** Let ''k = 0'' +** For each ''Bm'' in the group: +*** Let ''tk = hash(serP(ecdh_shared_secret) || ser32(k))'' +**** If ''tk'' is not valid tweak, i.e., if ''tk = 0'' or ''tk'' is larger or equal to the secp256k1 group order, fail +*** Let ''Pmn = Bm + tk·G'' +*** Encode ''Pmn'' as a [https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki BIP341] taproot output +*** Optionally, repeat with k++ to create additional outputs for the current ''Bm'' +*** If no additional outputs are required, continue to the next ''Bm'' with ''k++''''' Why not re-use ''tk'' when paying different labels to the same receiver?''' If paying the same entity but to two separate labeled addresses in the same transaction without incrementing ''k'', an outside observer could subtract the two output values and observe that this value is the same as the difference between two published silent payment addresses and learn who the recipient is. +** Optionally, if the sending wallet implements receiving silent payments, it can create change outputs by sending to its own silent payment address using label ''m = 0'', following the steps above + +=== Receiver === + +==== Key Derivation ==== + +Two keys are needed to create a silent payments address: the spend key and the scan key. Wallet software MUST use BIP32 hardened derivation'''Why use BIP32 hardened derivation?''' Using BIP32 derivation allows users to add silent payments to an existing master seed. It also ensures that a user's silent payment funds are recoverable in any BIP32/BIP43 compatible wallet. Using hardened derivation ensures that it is safe to export the scan private key without exposing the master key or spend private key. for both the spend and scan key. + +A scan and spend key pair using BIP32 derivation are defined (taking inspiration from [https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki BIP44]) in the following manner: + + scan_private_key: m / purpose' / coin_type' / account' / 1' / 0 + spend_private_key: m / purpose' / coin_type' / account' / 0' / 0 + +purpose is a constant set to ''352'' following the BIP43 recommendation. Refer to [https://github.com/bitcoin/bips/blob/master/bip-0043.mediawiki BIP43] and [https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki BIP44] for more details. + +==== Scanning ==== + +If each of the checks in ''[[#scanning-silent-payment-eligible-transactions|Scanning silent payment eligible transactions]]'' passes, the receiving wallet must: + +* Generate the ''input_hash'' with the smallest outpoint lexicographically, using the method described above +* Let ''A = A0 + A1 + ... + An'', where each ''Ai'' is the public key of an input from the ''[[#inputs-for-shared-secret-derivation|Inputs For Shared Secret Derivation]]'' list +* Let ''ecdh_shared_secret = input_hash·bscan·A'' +* Check for outputs: +** Let ''outputs_to_check'' be the taproot output keys from all unspent taproot outputs in the transaction +** Starting with ''k = 0'': +*** Let ''tk = hash(serP(ecdh_shared_secret) || ser32(k))'' +**** If ''tk'' is not valid tweak, i.e., if ''tk = 0'' or ''tk'' is larger or equal to the secp256k1 group order, fail +*** Compute ''Pk = Bspend + tk·G'' +*** For each ''output'' in ''outputs_to_check'': +**** If ''Pk'' equals ''output'': +***** Add ''Pk'' to the wallet +***** Remove ''output'' from ''outputs_to_check'' and rescan ''outputs_to_check'' with ''k++'' +**** Else, check for labels (always check for the change label, i.e. ''hash(ser256(bscan) || ser32(m))'' where ''m = 0'')''' Why precompute labels?''' Precomputing the labels is not strictly necessary: a wallet could track the max number of labels it has used (call it ''M'') and scan for labels by adding ''hash(bscan || m)·G'' to ''P0'' for each label ''m'' up to ''M'' and comparing to the transaction outputs. This is more performant than precomputing the labels and checking via subtraction in cases where the number of eligible outputs exceeds the number of labels in use. In practice this will mainly apply to users that choose never to use labels, or users that use a single label for generating silent payment change outputs. If using a large number of labels, the wallet would need to add all possible labels to each output. This ends up being ''n·M'' additions, where ''n'' is the number of outputs in the transaction and ''M'' is the number of labels in the wallet. By precomputing the labels, the wallet only needs to compute ''hash(bscan || m)·G'' once when creating the labeled address and can determine if a label was used via a lookup, rather than adding each label to each output.: +***** Compute ''label = output - Pk'' +***** Check if ''label'' exists in the list of labels used by the wallet +***** If a match is found: +****** Add ''Pk + label·G'' to the wallet +****** Remove ''output'' from ''outputs_to_check'' and rescan ''outputs_to_check'' with ''k++'' +***** If a label is not found, negate ''output'' and check a second time''' Why negate the output?''' Unfortunately taproot outputs are X-only, meaning we don't know what the correct Y coordinate is. This causes this specific calculation to fail 50% of the time, so we need to repeat it with the other Y coordinate by negating the output. +*** If no matches are found, stop + +==== Spending ==== + +Recall that a silent payment output is of the form ''Bspend + tk·G + hash(ser256(bscan) || ser32(m))·G'', where ''hash(ser256(bscan) || ser32(m))·G'' is an optional label. To spend a silent payment output: + +* Let ''d = (bspend + tk + hash(ser256(bscan) || ser32(m))) mod n'', where ''hash(ser256(bscan) || ser32(m))'' is the optional label +* Spend the [https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki BIP341] output with the private key ''d'' + +==== Backup and Recovery ==== + +Since each silent payment output address is derived independently, regular backups are recommended. When recovering from a backup, the wallet will need to scan since the last backup to detect new payments. + +If using a seed/seed phrase only style backup, the user can recover the wallet's unspent outputs from the UTXO set (i.e. only scanning transactions with at least one unspent taproot output) and can recover the full wallet history by scanning the blockchain starting from the wallet birthday. If a wallet uses labels, this information SHOULD be included in the backup. If the user does not know whether labels were used, it is strongly recommended they always precompute and check a large number of labels (e.g. 100k labels) to use when re-scanning. This ensures that the wallet can recover all funds from only a seed/seed phrase backup. The change label should simply always be scanned for, even when no other labels were used. This ensures the use of a change label is not critical for backups and maximizes cross-compatibility. + +== Backward Compatibility == + +Silent payments introduces a new address format and protocol for sending and as such is not compatible with older wallet software or wallets which have not implemented the silent payments protocol. + +== Test Vectors == + +A [[bip-0352/send_and_receive_test_vectors.json|collection of test vectors in JSON format]] are provided, along with a [[bip-0352/reference.py|python reference implementation]]. Each test vector consists of a sending test case and corresponding receiving test case. This is to allow sending and receiving to be implemented separately. To ensure determinism while testing, sort the array of ''Bm'' by amount (see the [[bip-0352/reference.py|reference implementation]]). Test cases use the following schema: + +''' test_case ''' + + { + "comment": "Comment describing the behavior being tested", + "sending": [], + "receiving": [], + } + +''' sender ''' + + { + "given": { + "outpoints": [], + "input_priv_keys": [], + "recipients": [] + }, + "expected": { + "outputs": [ + "given": { + "outpoints": [], + "input_pub_keys": [], + "bip32_seed": "byte data for generating a bip32 master seed", + "scan_priv_key": , + "spend_priv_key": , + "labels": {}, + }, + "expected": { + "addresses": [], + "outputs": [ + { + "pub_key": , + "priv_key_teak": . + "signature": + }, + ... + ] + } + } + +Wallets should include inputs not in the ''[[#inputs-for-shared-secret-derivation|Inputs For Shared Secret Derivation]]'' list when testing to ensure that only inputs from the list are being used for shared secret derivation. Additionally, receiving wallets should include non-silent payment outputs for themselves in testing to ensure silent payments scanning does not interfere with regular outputs detection. + +=== Functional tests === + +Below is a list of functional tests which should be included in sending and receiving implementations. + +==== Sending ==== + +* Ensure taproot outputs are excluded during coin selection if the sender does not have access to the key path private key (unless using ''H'' as the taproot internal key) +* Ensure the silent payment address is re-derived if inputs are added or removed during RBF + +==== Receiving ==== + +* Ensure the public key can be extracted from non-standard ''P2PKH'' scriptSigs +* Ensure taproot script path spends are included, using the taproot output key (unless ''H'' is used as the taproot internal key) +* Ensure the scanner can extract the public key from each of the input types supported (e.g. ''P2WPKH'', ''P2SH-P2WPKH'', etc.) + +== Appendix A: Light Client Support == + +This section proposes a few ideas for how light clients could support scanning for incoming silent payments (sending is fairly straightforward) in ways that preserve bandwidth and privacy. While this is out of scope for the current BIP, it is included to movitate further research into this topic. In this context, a light client refers to any bitcoin wallet client which does not process blocks and does not have a direct connection to a node which does process blocks (e.g. a full node). Based on this definition, clients that directly connect to a personal electrum server or a bitcoin node are not light clients. + +This distinction makes the problem for light clients more clear: light clients need a way to source the necessary data for performing the tweaks and a way of determining if any of the generated outputs exist in a block. + +=== Tweak Data === + +Recall that a silent payment eligible transaction follows [[#scanning-silent-payment-eligible-transactions|certain conditions]] and should have at least one unspent taproot output. Full nodes (or any index server backed by a full node, such as electrum server) can build an index which collects all of the eligible public keys for a silent payments eligible transaction, sums them up, multiplies the sum by the ''input_hash'', and serves them to clients. This would be 33 bytes per silent payment eligible transaction. + +For a typical bitcoin block of ~3500 txs, lets assume every transaction is a silent payments eligible transaction. This means a client would need to request ''33 bytes * 3500'' of data per block (roughly 100 kb per block). If a client were to request data for every block, this would amount to ~450MB per month, assuming 100% taproot usage and all outputs remain unspent for > 1 month. As of today, these numbers are closer to 2kb - 10kb per block (10MB - 50MB per month)''' Data for Appendix A ''' These numbers are based on data from January 2023 until June 2023 (the last 6 months of data at time time of writing). See [https://github.com/josibake/bitcoin-data-analysis/blob/main/notebooks/silent-payments-light-client-data.ipynb Silent payments light client data] for the full analysis.. + +=== Transaction cut-through === + +It is unlikely a light client would need to scan every block and as such can take advantage of transaction cut-through, depending on how often they choose to scan for new blocks. Empirically, ~75% of transactions with at least one unspent taproot output will have spent all taproot UTXOs in 326 blocks or less. This means a client which only scans once every 3 days could ''significantly'' cut down on the number of blocks and the number of transactions per block that they need to request by only asking for data on transactions that were created since their last scan and that still have at least one unspent taproot output as of the current block height. Assuming 100% taproot usage, a client that scans once a month would likely only need around 50MB worth of data. Based on current taproot adoption, a light client scanning once every 3 days would use roughly 15MB per month and a client scanning once per month would use less than 5MB per month. + +[[File:bip-0352/scan_data_downloader_per_month.png]] + +=== BIP158 === + +Once a light client has the tweak data for a block, they can determine whether or not an output to them exists in the block using BIP158 block filters. Per BIP158, they would then request the entire block and add the transaction to their wallet, though it maybe be possible to only request the prevout txids and vouts for all transactions with at least one taproot output, along with the scriptPubKeys and amounts. This would allow the client to download the necessary data for constructing a spending transaction, without downloading the entire block. How this affects the security assumptions of BIP158 is an open question. + +=== Out-of-band notifications === + +Assuming a secure messaging protocol exists, the sender can send an encrypted (using the scan public key of the silent payment address) notification to the receiver with the following information: +* The spend public key (communicates the label) +* The shared secret portion of the private key (i.e ''hash(ecdh_shared_secret || k)'') +* The outpoint and amount (so it's immediately spendable) + +It is important to note that these notifications are not required. At any point, the receiver can fall back to scanning for silent payment transactions if they don't trust the notifications they are receiving, are being spammed with fake notifications, or if they are concerned that they are not receiving notifications. + +A malicious notification could potentially cause the following issues: + +* You did not actually receive money to the stated key +** This can be probabilistically resolved by matching the key against the BIP158 block filters and assuming it's not a false positive, or fully resolved by downloading the block +* You received money but the outpoint or amount is incorrect, so attempts to spend it will fail or cause you to overpay fees +** There doesn't seem to be much motivation for malicious senders to ever do this, but light clients need to take into account that this can occur and should ideally check for it by downloading the block +* The private key is correct but it wasn't actually derived using the silent payment protocol, causing recovery from back-up to fail (unsafe - no implementation should ever allow this) +** This can be detected by downloading the tweak data of the corresponding block and should be resolved by immediately spending the output + +Wallet designers can choose which tradeoffs they find appropriate. For example, a wallet could check the block filter to at least probabilistically confirm the likely existence of the UTXO, thus efficiently cutting down on spam. The payment could then be marked as unconfirmed until a scan is performed and the existence of the UTXO in accordance to the silent payment specification is verified. + + +== Acknowledgements == + +This document is the result of many discussions and contains contributions by a number of people. The authors wish to thank all those who provided valuable feedback and reviews, including the participants of the [https://gist.github.com/RubenSomsen/21c477c90c942acf45f8e8f5c1ad4fae BIP47 Prague discussion], the [https://github.com/josibake/silent-payments-workshop Advancing Bitcoin silent payments Workshop], and [https://btctranscripts.com/bitcoin-core-dev-tech/2023-04-26-silent-payments/ coredev]. The authors would like to also thank [https://github.com/w0xlt w0xlt] for writing the initial implementation of silent payments. + +== Rationale and References == + + diff --git a/bip-0352/bech32m.py b/bip-0352/bech32m.py new file mode 100644 index 0000000000..795e153863 --- /dev/null +++ b/bip-0352/bech32m.py @@ -0,0 +1,135 @@ +# Copyright (c) 2017, 2020 Pieter Wuille +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +"""Reference implementation for Bech32/Bech32m and segwit addresses.""" + + +from enum import Enum + +class Encoding(Enum): + """Enumeration type to list the various supported encodings.""" + BECH32 = 1 + BECH32M = 2 + +CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l" +BECH32M_CONST = 0x2bc830a3 + +def bech32_polymod(values): + """Internal function that computes the Bech32 checksum.""" + generator = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3] + chk = 1 + for value in values: + top = chk >> 25 + chk = (chk & 0x1ffffff) << 5 ^ value + for i in range(5): + chk ^= generator[i] if ((top >> i) & 1) else 0 + return chk + + +def bech32_hrp_expand(hrp): + """Expand the HRP into values for checksum computation.""" + return [ord(x) >> 5 for x in hrp] + [0] + [ord(x) & 31 for x in hrp] + + +def bech32_verify_checksum(hrp, data): + """Verify a checksum given HRP and converted data characters.""" + const = bech32_polymod(bech32_hrp_expand(hrp) + data) + if const == 1: + return Encoding.BECH32 + if const == BECH32M_CONST: + return Encoding.BECH32M + return None + +def bech32_create_checksum(hrp, data, spec): + """Compute the checksum values given HRP and data.""" + values = bech32_hrp_expand(hrp) + data + const = BECH32M_CONST if spec == Encoding.BECH32M else 1 + polymod = bech32_polymod(values + [0, 0, 0, 0, 0, 0]) ^ const + return [(polymod >> 5 * (5 - i)) & 31 for i in range(6)] + + +def bech32_encode(hrp, data, spec): + """Compute a Bech32 string given HRP and data values.""" + combined = data + bech32_create_checksum(hrp, data, spec) + return hrp + '1' + ''.join([CHARSET[d] for d in combined]) + +def bech32_decode(bech): + """Validate a Bech32/Bech32m string, and determine HRP and data.""" + if ((any(ord(x) < 33 or ord(x) > 126 for x in bech)) or + (bech.lower() != bech and bech.upper() != bech)): + return (None, None, None) + bech = bech.lower() + pos = bech.rfind('1') + + # remove the requirement that bech32m be less than 90 chars + if pos < 1 or pos + 7 > len(bech): + return (None, None, None) + if not all(x in CHARSET for x in bech[pos+1:]): + return (None, None, None) + hrp = bech[:pos] + data = [CHARSET.find(x) for x in bech[pos+1:]] + spec = bech32_verify_checksum(hrp, data) + if spec is None: + return (None, None, None) + return (hrp, data[:-6], spec) + +def convertbits(data, frombits, tobits, pad=True): + """General power-of-2 base conversion.""" + acc = 0 + bits = 0 + ret = [] + maxv = (1 << tobits) - 1 + max_acc = (1 << (frombits + tobits - 1)) - 1 + for value in data: + if value < 0 or (value >> frombits): + return None + acc = ((acc << frombits) | value) & max_acc + bits += frombits + while bits >= tobits: + bits -= tobits + ret.append((acc >> bits) & maxv) + if pad: + if bits: + ret.append((acc << (tobits - bits)) & maxv) + elif bits >= frombits or ((acc << (tobits - bits)) & maxv): + return None + return ret + + +def decode(hrp, addr): + """Decode a segwit address.""" + hrpgot, data, spec = bech32_decode(addr) + if hrpgot != hrp: + return (None, None) + decoded = convertbits(data[1:], 5, 8, False) + if decoded is None or len(decoded) < 2: + return (None, None) + if data[0] > 16: + return (None, None) + return (data[0], decoded) + + +def encode(hrp, witver, witprog): + """Encode a segwit address.""" + spec = Encoding.BECH32 if witver == 0 else Encoding.BECH32M + ret = bech32_encode(hrp, [witver] + convertbits(witprog, 8, 5), spec) + if decode(hrp, ret) == (None, None): + return None + return ret diff --git a/bip-0352/reference.py b/bip-0352/reference.py new file mode 100755 index 0000000000..0413c92b64 --- /dev/null +++ b/bip-0352/reference.py @@ -0,0 +1,318 @@ +#!/usr/bin/env python3 + +import hashlib +import json +import bip32 # type: ignore +from typing import List, Tuple, Dict, Union, cast +from sys import argv +from functools import reduce + +# local files +from bech32m import convertbits, bech32_encode, decode, Encoding +from secp256k1 import ECKey, ECPubKey + + +def sha256(s: Union[bytes, bytearray]) -> bytes: + return hashlib.sha256(s).digest() + + +def hash160(s: Union[bytes, bytearray]) -> bytes: + return hashlib.new("ripemd160", sha256(s)).digest() + + +def is_p2tr(spk: bytes) -> bool: + if len(spk) != 34: + return False + # OP_1 OP_PUSHBYTES_32 <32 bytes> + return (spk[0] == 0x51) & (spk[1] == 0x20) + + +def is_p2wpkh(spk: bytes) -> bool: + if len(spk) != 22: + return False + # OP_0 OP_PUSHBYTES_20 <20 bytes> + return (spk[0] == 0x00) & (spk[1] == 0x14) + + +def is_p2sh(spk: bytes) -> bool: + if len(spk) != 23: + return False + # OP_HASH160 OP_PUSHBYTES_20 <20 bytes> OP_EQUAL + return (spk[0] == 0xA9) & (spk[1] == 0x14) & (spk[-1] == 0x87) + + +def is_p2pkh(spk: bytes) -> bool: + if len(spk) != 25: + return False + # OP_DUP OP_HASH160 OP_PUSHBYTES_20 <20 bytes> OP_EQUALVERIFY OP_CHECKSIG + return (spk[0] == 0x76) & (spk[1] == 0xA9) & (spk[2] == 0x14) & (spk[-2] == 0x88) & (spk[-1] == 0xAC) + + +def get_pubkey_from_input(input) -> ECPubKey: + spk = bytes.fromhex(input["scriptPubKey"]) + if is_p2pkh(spk): + spk_pkh = spk[3:3 + 20] + script_sig = bytes.fromhex(input["prevout"][2]) + for i in range(len(script_sig), 0, -1): + if i - 33 >= 0: + pk = script_sig[i - 33:i] + pkh = hash160(pk) + if pkh == spk_pkh: + return ECPubKey().set(pk) + # should never happen, as this would be an invalid spend + return ECPubKey() + if is_p2sh(spk): + redeem_script = bytes.fromhex(input["prevout"][2])[1:] + if is_p2wpkh(redeem_script): + return ECPubKey().set(redeem_script[-33:]) + if is_p2wpkh(spk): + # the witness must contain two items and the second item is the pubkey + return ECPubKey().set(bytes.fromhex(input["prevout"][3])[-33:]) + if is_p2tr(spk): + return ECPubKey().set(spk[2:]) + return ECPubKey() + + +def ser_uint32(u: int) -> bytes: + return u.to_bytes(4, "big") + + +def get_input_nonce(outpoints: List[Tuple[str, int]], sum_input_pubkeys: ECPubKey) -> bytes: + lowest_outpoint = sorted([ + bytearray.fromhex(txid)[::-1] + n.to_bytes(4, "little") + for txid, n in outpoints + ])[0] + + s = hashlib.new("sha256") + s.update(lowest_outpoint) + s.update(sum_input_pubkeys.get_bytes(False)) + + return s.digest() + + +def derive_silent_payment_key_pair(seed: bytes) -> Tuple[ECKey, ECKey, ECPubKey, ECPubKey]: + SCAN_KEY = "m/352h/0h/0h/1h/0" + SPEND_KEY = "m/352h/0h/0h/0h/0" + + master = bip32.BIP32.from_seed(seed) + scan = ECKey().set(master.get_privkey_from_path(SCAN_KEY)) + spend = ECKey().set(master.get_privkey_from_path(SPEND_KEY)) + Scan = scan.get_pubkey() + Spend = spend.get_pubkey() + + return scan, spend, Scan, Spend + + +def encode_silent_payment_address(B_scan: ECPubKey, B_m: ECPubKey, hrp: str = "tsp", version: int = 0) -> str: + data = convertbits(B_scan.get_bytes(False) + B_m.get_bytes(False), 8, 5) + return bech32_encode(hrp, [version] + data, Encoding.BECH32M) + + +def generate_label(b_scan: ECKey, m: int) -> bytes: + return sha256(b_scan.get_bytes() + ser_uint32(m)) + + +def create_labeled_silent_payment_address(b_scan: ECKey, B_spend: ECPubKey, m: int, hrp: str = "tsp", version: int = 0) -> str: + G = ECKey().set(1).get_pubkey() + B_scan = b_scan.get_pubkey() + B_m = B_spend + generate_label(b_scan, m) * G + labeled_address = encode_silent_payment_address(B_scan, B_m, hrp, version) + + return labeled_address + + +def decode_silent_payment_address(address: str, hrp: str = "tsp") -> Tuple[ECPubKey, ECPubKey]: + version, data = decode(hrp, address) + B_scan = ECPubKey().set(data[:33]) + B_spend = ECPubKey().set(data[33:]) + + return B_scan, B_spend + + +def create_outputs(input_priv_keys: List[Tuple[ECKey, bool]], input_nonce: bytes, recipients: List[Tuple[str, float]], hrp="tsp") -> List[Tuple[str, float]]: + G = ECKey().set(1).get_pubkey() + negated_keys = [] + for key, is_xonly in input_priv_keys: + k = ECKey().set(key.get_bytes()) + if is_xonly and k.get_pubkey().get_y() % 2 != 0: + k.negate() + negated_keys.append(k) + + a_sum = sum(negated_keys) + silent_payment_groups: Dict[ECPubKey, List[Tuple[ECPubKey, float]]] = {} + for recipient in recipients: + addr, amount = recipient + B_scan, B_m = decode_silent_payment_address(addr, hrp=hrp) + if B_scan in silent_payment_groups: + silent_payment_groups[B_scan].append((B_m, amount)) + else: + silent_payment_groups[B_scan] = [(B_m, amount)] + + outputs = [] + for B_scan, B_m_values in silent_payment_groups.items(): + k = 0 + ecdh_shared_secret = input_nonce * a_sum * B_scan + + # Sort B_m_values by amount to ensure determinism in the tests + # Note: the receiver can find the outputs regardless of the ordering, this + # sorting step is only for testing + B_m_values.sort(key=lambda x: x[1]) + for B_m, amount in B_m_values: + t_k = sha256(ecdh_shared_secret.get_bytes(False) + ser_uint32(k)) + P_km = B_m + t_k * G + outputs.append((P_km.get_bytes().hex(), amount)) + k += 1 + return outputs + + +def scanning(b_scan: ECKey, B_spend: ECPubKey, A_sum: ECPubKey, input_nonce: bytes, outputs_to_check: List[ECPubKey], labels: Dict[str, str] = {}) -> List[Dict[str, str]]: + G = ECKey().set(1).get_pubkey() + ecdh_shared_secret = input_nonce * b_scan * A_sum + k = 0 + wallet = [] + while True: + t_k = sha256(ecdh_shared_secret.get_bytes(False) + ser_uint32(k)) + P_k = B_spend + t_k * G + for output in outputs_to_check: + if P_k == output: + wallet.append({"pub_key": P_k.get_bytes().hex(), "priv_key_tweak": t_k.hex()}) + outputs_to_check.remove(output) + k += 1 + break + elif labels: + m_G_sub = output - P_k + if m_G_sub.get_bytes(False).hex() in labels: + P_km = P_k + m_G_sub + wallet.append({ + "pub_key": P_km.get_bytes().hex(), + "priv_key_tweak": (ECKey().set(t_k).add( + bytes.fromhex(labels[m_G_sub.get_bytes(False).hex()]) + )).get_bytes().hex(), + }) + outputs_to_check.remove(output) + k += 1 + else: + output.negate() + m_G_sub = output - P_k + if m_G_sub.get_bytes(False).hex() in labels: + P_km = P_k + m_G_sub + wallet.append({ + "pub_key": P_km.get_bytes().hex(), + "priv_key_tweak": (ECKey().set(t_k).add( + bytes.fromhex(labels[m_G_sub.get_bytes(False).hex()]) + )).get_bytes().hex(), + }) + outputs_to_check.remove(output) + k += 1 + break + else: + break + return wallet + + +if __name__ == "__main__": + with open(argv[1], "r") as f: + test_data = json.loads(f.read()) + + # G , needed for generating the labels "database" + G = ECKey().set(1).get_pubkey() + for case in test_data: + print(case["comment"]) + # Test sending + for sending_test in case["sending"]: + given = sending_test["given"] + expected = sending_test["expected"] + + outpoints = [(input["prevout"][0], input["prevout"][1]) for input in given["inputs"]] + # Conver the tuples to lists so they can be easily compared to the json list of lists from the given test vectors + input_priv_keys = [] + input_pub_keys = [] + for input in given["inputs"]: + pubkey = get_pubkey_from_input(input) + if not pubkey.valid: + continue + input_priv_keys.append(( + ECKey().set(bytes.fromhex(input["private_key"])), + is_p2tr(bytes.fromhex(input["scriptPubKey"])), + )) + input_pub_keys.append(pubkey) + A_sum = reduce(lambda x, y: x + y, input_pub_keys) + input_nonce = get_input_nonce(outpoints, A_sum) + sending_outputs = [ + list(t) + for t in create_outputs(input_priv_keys, input_nonce, given["recipients"], hrp="sp") + ] + # Check that for a given set of inputs, we were able to generate the expected outputs for the receiver + sending_outputs.sort(key=lambda x: cast(float, x[1])) + assert sending_outputs == expected["outputs"], "Sending test failed" + + # Test receiving + msg = sha256(b"message") + aux = sha256(b"random auxiliary data") + for receiving_test in case["receiving"]: + given = receiving_test["given"] + expected = receiving_test["expected"] + outputs_to_check = [ + ECPubKey().set(bytes.fromhex(p)) for p in given["outputs"] + ] + outpoints = [ + (input["prevout"][0], input["prevout"][1]) for input in given["inputs"] + ] + + # Check that the given inputs for the receiving test match what was generated during the sending test + receiving_addresses = [] + b_scan = ECKey().set(bytes.fromhex(given["key_material"]["scan_priv_key"])) + b_spend = ECKey().set( + bytes.fromhex(given["key_material"]["spend_priv_key"]) + ) + B_scan = b_scan.get_pubkey() + B_spend = b_spend.get_pubkey() + receiving_addresses.append( + encode_silent_payment_address(B_scan, B_spend, hrp="sp") + ) + if given["labels"]: + for label in given["labels"]: + receiving_addresses.append( + create_labeled_silent_payment_address( + b_scan, B_spend, m=label, hrp="sp" + ) + ) + + # Check that the silent payment addresses match for the given BIP32 seed and labels dictionary + assert (receiving_addresses == expected["addresses"]), "Receiving addresses don't match" + input_pub_keys = [] + for input in given["inputs"]: + pubkey = get_pubkey_from_input(input) + if not pubkey.valid: + continue + input_pub_keys.append(pubkey) + A_sum = reduce(lambda x, y: x + y, input_pub_keys) + input_nonce = get_input_nonce(outpoints, A_sum) + pre_computed_labels = { + (generate_label(b_scan, label) * G).get_bytes(False).hex(): generate_label(b_scan, label).hex() + for label in given["labels"] + } + add_to_wallet = scanning( + b_scan=b_scan, + B_spend=B_spend, + A_sum=A_sum, + input_nonce=input_nonce, + outputs_to_check=outputs_to_check, + labels=pre_computed_labels, + ) + + # Check that the private key is correct for the found output public key + for output in add_to_wallet: + pub_key = ECPubKey().set(bytes.fromhex(output["pub_key"])) + full_private_key = b_spend.add(bytes.fromhex(output["priv_key_tweak"])) + if full_private_key.get_pubkey().get_y() % 2 != 0: + full_private_key.negate() + + sig = full_private_key.sign_schnorr(msg, aux) + assert pub_key.verify_schnorr(sig, msg), f"Invalid signature for {pub_key}" + output["signature"] = sig.hex() + + # Check if the found output public keys match the expected output public keys + assert add_to_wallet == expected["outputs"], "Receiving test failed" + + print("All tests passed") diff --git a/bip-0352/scan_data_downloader_per_month.png b/bip-0352/scan_data_downloader_per_month.png new file mode 100644 index 0000000000..ffcd0ddddb Binary files /dev/null and b/bip-0352/scan_data_downloader_per_month.png differ diff --git a/bip-0352/secp256k1.py b/bip-0352/secp256k1.py new file mode 100644 index 0000000000..340e75455a --- /dev/null +++ b/bip-0352/secp256k1.py @@ -0,0 +1,681 @@ +# Copyright (c) 2019 Pieter Wuille +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +"""Test-only secp256k1 elliptic curve implementation + +WARNING: This code is slow, uses bad randomness, does not properly protect +keys, and is trivially vulnerable to side channel attacks. Do not use for +anything but tests.""" +import random +import hashlib + +def TaggedHash(tag, data): + ss = hashlib.sha256(tag.encode('utf-8')).digest() + ss += ss + ss += data + return hashlib.sha256(ss).digest() + +def modinv(a, n): + """Compute the modular inverse of a modulo n + + See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Modular_integers. + """ + t1, t2 = 0, 1 + r1, r2 = n, a + while r2 != 0: + q = r1 // r2 + t1, t2 = t2, t1 - q * t2 + r1, r2 = r2, r1 - q * r2 + if r1 > 1: + return None + if t1 < 0: + t1 += n + return t1 + +def jacobi_symbol(n, k): + """Compute the Jacobi symbol of n modulo k + + See http://en.wikipedia.org/wiki/Jacobi_symbol + + For our application k is always prime, so this is the same as the Legendre symbol.""" + assert k > 0 and k & 1, "jacobi symbol is only defined for positive odd k" + n %= k + t = 0 + while n != 0: + while n & 1 == 0: + n >>= 1 + r = k & 7 + t ^= (r == 3 or r == 5) + n, k = k, n + t ^= (n & k & 3 == 3) + n = n % k + if k == 1: + return -1 if t else 1 + return 0 + +def modsqrt(a, p): + """Compute the square root of a modulo p when p % 4 = 3. + + The Tonelli-Shanks algorithm can be used. See https://en.wikipedia.org/wiki/Tonelli-Shanks_algorithm + + Limiting this function to only work for p % 4 = 3 means we don't need to + iterate through the loop. The highest n such that p - 1 = 2^n Q with Q odd + is n = 1. Therefore Q = (p-1)/2 and sqrt = a^((Q+1)/2) = a^((p+1)/4) + + secp256k1's is defined over field of size 2**256 - 2**32 - 977, which is 3 mod 4. + """ + if p % 4 != 3: + raise NotImplementedError("modsqrt only implemented for p % 4 = 3") + sqrt = pow(a, (p + 1)//4, p) + if pow(sqrt, 2, p) == a % p: + return sqrt + return None + +def int_or_bytes(s): + "Convert 32-bytes to int while accepting also int and returning it as is." + if isinstance(s, bytes): + assert(len(s) == 32) + s = int.from_bytes(s, 'big') + elif not isinstance(s, int): + raise TypeError + return s + +class EllipticCurve: + def __init__(self, p, a, b): + """Initialize elliptic curve y^2 = x^3 + a*x + b over GF(p).""" + self.p = p + self.a = a % p + self.b = b % p + + def affine(self, p1): + """Convert a Jacobian point tuple p1 to affine form, or None if at infinity. + + An affine point is represented as the Jacobian (x, y, 1)""" + x1, y1, z1 = p1 + if z1 == 0: + return None + inv = modinv(z1, self.p) + inv_2 = (inv**2) % self.p + inv_3 = (inv_2 * inv) % self.p + return ((inv_2 * x1) % self.p, (inv_3 * y1) % self.p, 1) + + def has_even_y(self, p1): + """Whether the point p1 has an even Y coordinate when expressed in affine coordinates.""" + return not (p1[2] == 0 or self.affine(p1)[1] & 1) + + def negate(self, p1): + """Negate a Jacobian point tuple p1.""" + x1, y1, z1 = p1 + return (x1, (self.p - y1) % self.p, z1) + + def on_curve(self, p1): + """Determine whether a Jacobian tuple p is on the curve (and not infinity)""" + x1, y1, z1 = p1 + z2 = pow(z1, 2, self.p) + z4 = pow(z2, 2, self.p) + return z1 != 0 and (pow(x1, 3, self.p) + self.a * x1 * z4 + self.b * z2 * z4 - pow(y1, 2, self.p)) % self.p == 0 + + def is_x_coord(self, x): + """Test whether x is a valid X coordinate on the curve.""" + x_3 = pow(x, 3, self.p) + return jacobi_symbol(x_3 + self.a * x + self.b, self.p) != -1 + + def lift_x(self, x): + """Given an X coordinate on the curve, return a corresponding affine point.""" + x_3 = pow(x, 3, self.p) + v = x_3 + self.a * x + self.b + y = modsqrt(v, self.p) + if y is None: + return None + return (x, y, 1) + + def double(self, p1): + """Double a Jacobian tuple p1 + + See https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates - Point Doubling""" + x1, y1, z1 = p1 + if z1 == 0: + return (0, 1, 0) + y1_2 = (y1**2) % self.p + y1_4 = (y1_2**2) % self.p + x1_2 = (x1**2) % self.p + s = (4*x1*y1_2) % self.p + m = 3*x1_2 + if self.a: + m += self.a * pow(z1, 4, self.p) + m = m % self.p + x2 = (m**2 - 2*s) % self.p + y2 = (m*(s - x2) - 8*y1_4) % self.p + z2 = (2*y1*z1) % self.p + return (x2, y2, z2) + + def add_mixed(self, p1, p2): + """Add a Jacobian tuple p1 and an affine tuple p2 + + See https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates - Point Addition (with affine point)""" + x1, y1, z1 = p1 + x2, y2, z2 = p2 + assert(z2 == 1) + # Adding to the point at infinity is a no-op + if z1 == 0: + return p2 + z1_2 = (z1**2) % self.p + z1_3 = (z1_2 * z1) % self.p + u2 = (x2 * z1_2) % self.p + s2 = (y2 * z1_3) % self.p + if x1 == u2: + if (y1 != s2): + # p1 and p2 are inverses. Return the point at infinity. + return (0, 1, 0) + # p1 == p2. The formulas below fail when the two points are equal. + return self.double(p1) + h = u2 - x1 + r = s2 - y1 + h_2 = (h**2) % self.p + h_3 = (h_2 * h) % self.p + u1_h_2 = (x1 * h_2) % self.p + x3 = (r**2 - h_3 - 2*u1_h_2) % self.p + y3 = (r*(u1_h_2 - x3) - y1*h_3) % self.p + z3 = (h*z1) % self.p + return (x3, y3, z3) + + def add(self, p1, p2): + """Add two Jacobian tuples p1 and p2 + + See https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates - Point Addition""" + x1, y1, z1 = p1 + x2, y2, z2 = p2 + # Adding the point at infinity is a no-op + if z1 == 0: + return p2 + if z2 == 0: + return p1 + # Adding an Affine to a Jacobian is more efficient since we save field multiplications and squarings when z = 1 + if z1 == 1: + return self.add_mixed(p2, p1) + if z2 == 1: + return self.add_mixed(p1, p2) + z1_2 = (z1**2) % self.p + z1_3 = (z1_2 * z1) % self.p + z2_2 = (z2**2) % self.p + z2_3 = (z2_2 * z2) % self.p + u1 = (x1 * z2_2) % self.p + u2 = (x2 * z1_2) % self.p + s1 = (y1 * z2_3) % self.p + s2 = (y2 * z1_3) % self.p + if u1 == u2: + if (s1 != s2): + # p1 and p2 are inverses. Return the point at infinity. + return (0, 1, 0) + # p1 == p2. The formulas below fail when the two points are equal. + return self.double(p1) + h = u2 - u1 + r = s2 - s1 + h_2 = (h**2) % self.p + h_3 = (h_2 * h) % self.p + u1_h_2 = (u1 * h_2) % self.p + x3 = (r**2 - h_3 - 2*u1_h_2) % self.p + y3 = (r*(u1_h_2 - x3) - s1*h_3) % self.p + z3 = (h*z1*z2) % self.p + return (x3, y3, z3) + + def mul(self, ps): + """Compute a (multi) point multiplication + + ps is a list of (Jacobian tuple, scalar) pairs. + """ + r = (0, 1, 0) + for i in range(255, -1, -1): + r = self.double(r) + for (p, n) in ps: + if ((n >> i) & 1): + r = self.add(r, p) + return r + +SECP256K1_FIELD_SIZE = 2**256 - 2**32 - 977 +SECP256K1 = EllipticCurve(SECP256K1_FIELD_SIZE, 0, 7) +SECP256K1_G = (0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798, 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8, 1) +SECP256K1_ORDER = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 +SECP256K1_ORDER_HALF = SECP256K1_ORDER // 2 + +class ECPubKey(): + """A secp256k1 public key""" + + def __init__(self): + """Construct an uninitialized public key""" + self.valid = False + + def __repr__(self): + return self.get_bytes().hex() + + def __eq__(self, other): + assert isinstance(other, ECPubKey) + return self.get_bytes() == other.get_bytes() + + def __hash__(self): + return hash(self.get_bytes()) + + def set(self, data): + """Construct a public key from a serialization in compressed or uncompressed DER format or BIP340 format""" + if (len(data) == 65 and data[0] == 0x04): + p = (int.from_bytes(data[1:33], 'big'), int.from_bytes(data[33:65], 'big'), 1) + self.valid = SECP256K1.on_curve(p) + if self.valid: + self.p = p + self.compressed = False + elif (len(data) == 33 and (data[0] == 0x02 or data[0] == 0x03)): + x = int.from_bytes(data[1:33], 'big') + if SECP256K1.is_x_coord(x): + p = SECP256K1.lift_x(x) + # if the oddness of the y co-ord isn't correct, find the other + # valid y + if (p[1] & 1) != (data[0] & 1): + p = SECP256K1.negate(p) + self.p = p + self.valid = True + self.compressed = True + else: + self.valid = False + elif (len(data) == 32): + x = int.from_bytes(data[0:32], 'big') + if SECP256K1.is_x_coord(x): + p = SECP256K1.lift_x(x) + # if the oddness of the y co-ord isn't correct, find the other + # valid y + if p[1]%2 != 0: + p = SECP256K1.negate(p) + self.p = p + self.valid = True + self.compressed = True + else: + self.valid = False + else: + self.valid = False + return self + + @property + def is_compressed(self): + return self.compressed + + @property + def is_valid(self): + return self.valid + + def get_y(self): + return SECP256K1.affine(self.p)[1] + + def get_x(self): + return SECP256K1.affine(self.p)[0] + + def get_bytes(self, bip340=True): + assert(self.valid) + p = SECP256K1.affine(self.p) + if p is None: + return None + if bip340: + return bytes(p[0].to_bytes(32, 'big')) + elif self.compressed: + return bytes([0x02 + (p[1] & 1)]) + p[0].to_bytes(32, 'big') + else: + return bytes([0x04]) + p[0].to_bytes(32, 'big') + p[1].to_bytes(32, 'big') + + def verify_ecdsa(self, sig, msg, low_s=True): + """Verify a strictly DER-encoded ECDSA signature against this pubkey. + + See https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm for the + ECDSA verifier algorithm""" + assert(self.valid) + + # Extract r and s from the DER formatted signature. Return false for + # any DER encoding errors. + if (sig[1] + 2 != len(sig)): + return False + if (len(sig) < 4): + return False + if (sig[0] != 0x30): + return False + if (sig[2] != 0x02): + return False + rlen = sig[3] + if (len(sig) < 6 + rlen): + return False + if rlen < 1 or rlen > 33: + return False + if sig[4] >= 0x80: + return False + if (rlen > 1 and (sig[4] == 0) and not (sig[5] & 0x80)): + return False + r = int.from_bytes(sig[4:4+rlen], 'big') + if (sig[4+rlen] != 0x02): + return False + slen = sig[5+rlen] + if slen < 1 or slen > 33: + return False + if (len(sig) != 6 + rlen + slen): + return False + if sig[6+rlen] >= 0x80: + return False + if (slen > 1 and (sig[6+rlen] == 0) and not (sig[7+rlen] & 0x80)): + return False + s = int.from_bytes(sig[6+rlen:6+rlen+slen], 'big') + + # Verify that r and s are within the group order + if r < 1 or s < 1 or r >= SECP256K1_ORDER or s >= SECP256K1_ORDER: + return False + if low_s and s >= SECP256K1_ORDER_HALF: + return False + z = int.from_bytes(msg, 'big') + + # Run verifier algorithm on r, s + w = modinv(s, SECP256K1_ORDER) + u1 = z*w % SECP256K1_ORDER + u2 = r*w % SECP256K1_ORDER + R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, u1), (self.p, u2)])) + if R is None or R[0] != r: + return False + return True + + def verify_schnorr(self, sig, msg): + assert(len(msg) == 32) + assert(len(sig) == 64) + assert(self.valid) + r = int.from_bytes(sig[0:32], 'big') + if r >= SECP256K1_FIELD_SIZE: + return False + s = int.from_bytes(sig[32:64], 'big') + if s >= SECP256K1_ORDER: + return False + e = int.from_bytes(TaggedHash("BIP0340/challenge", sig[0:32] + self.get_bytes() + msg), 'big') % SECP256K1_ORDER + R = SECP256K1.mul([(SECP256K1_G, s), (self.p, SECP256K1_ORDER - e)]) + if not SECP256K1.has_even_y(R): + return False + if ((r * R[2] * R[2]) % SECP256K1_FIELD_SIZE) != R[0]: + return False + return True + + def __add__(self, other): + """Adds two ECPubKey points.""" + assert isinstance(other, ECPubKey) + assert self.valid + assert other.valid + ret = ECPubKey() + ret.p = SECP256K1.add(other.p, self.p) + ret.valid = True + ret.compressed = self.compressed + return ret + + def __radd__(self, other): + """Allows this ECPubKey to be added to 0 for sum()""" + if other == 0: + return self + else: + return self + other + + def __mul__(self, other): + """Multiplies ECPubKey point with a scalar(int/32bytes/ECKey).""" + if isinstance(other, ECKey): + assert self.valid + assert other.secret is not None + multiplier = other.secret + else: + # int_or_bytes checks that other is `int` or `bytes` + multiplier = int_or_bytes(other) + + assert multiplier < SECP256K1_ORDER + multiplier = multiplier % SECP256K1_ORDER + ret = ECPubKey() + ret.p = SECP256K1.mul([(self.p, multiplier)]) + ret.valid = True + ret.compressed = self.compressed + return ret + + def __rmul__(self, other): + """Multiplies a scalar(int/32bytes/ECKey) with an ECPubKey point""" + return self * other + + def __sub__(self, other): + """Subtract one point from another""" + assert isinstance(other, ECPubKey) + assert self.valid + assert other.valid + ret = ECPubKey() + ret.p = SECP256K1.add(self.p, SECP256K1.negate(other.p)) + ret.valid = True + ret.compressed = self.compressed + return ret + + def tweak_add(self, tweak): + assert(self.valid) + t = int_or_bytes(tweak) + if t >= SECP256K1_ORDER: + return None + tweaked = SECP256K1.affine(SECP256K1.mul([(self.p, 1), (SECP256K1_G, t)])) + if tweaked is None: + return None + ret = ECPubKey() + ret.p = tweaked + ret.valid = True + ret.compressed = self.compressed + return ret + + def mul(self, data): + """Multiplies ECPubKey point with scalar data.""" + assert self.valid + other = ECKey() + other.set(data, True) + return self * other + + def negate(self): + self.p = SECP256K1.affine(SECP256K1.negate(self.p)) + +class ECKey(): + """A secp256k1 private key""" + + def __init__(self): + self.valid = False + + def __repr__(self): + return str(self.secret) + + def __eq__(self, other): + assert isinstance(other, ECKey) + return self.secret == other.secret + + def __hash__(self): + return hash(self.secret) + + def set(self, secret, compressed=True): + """Construct a private key object from either 32-bytes or an int secret and a compressed flag.""" + secret = int_or_bytes(secret) + + self.valid = (secret > 0 and secret < SECP256K1_ORDER) + if self.valid: + self.secret = secret + self.compressed = compressed + return self + + def generate(self, compressed=True): + """Generate a random private key (compressed or uncompressed).""" + self.set(random.randrange(1, SECP256K1_ORDER).to_bytes(32, 'big'), compressed) + return self + + def get_bytes(self): + """Retrieve the 32-byte representation of this key.""" + assert(self.valid) + return self.secret.to_bytes(32, 'big') + + def as_int(self): + return self.secret + + def from_int(self, secret, compressed=True): + self.valid = (secret > 0 and secret < SECP256K1_ORDER) + if self.valid: + self.secret = secret + self.compressed = compressed + + def __add__(self, other): + """Add key secrets. Returns compressed key.""" + assert isinstance(other, ECKey) + assert other.secret > 0 and other.secret < SECP256K1_ORDER + assert self.valid is True + ret_data = ((self.secret + other.secret) % SECP256K1_ORDER).to_bytes(32, 'big') + ret = ECKey() + ret.set(ret_data, True) + return ret + + def __radd__(self, other): + """Allows this ECKey to be added to 0 for sum()""" + if other == 0: + return self + else: + return self + other + + def __sub__(self, other): + """Subtract key secrets. Returns compressed key.""" + assert isinstance(other, ECKey) + assert other.secret > 0 and other.secret < SECP256K1_ORDER + assert self.valid is True + ret_data = ((self.secret - other.secret) % SECP256K1_ORDER).to_bytes(32, 'big') + ret = ECKey() + ret.set(ret_data, True) + return ret + + def __mul__(self, other): + """Multiply a private key by another private key or multiply a public key by a private key. Returns compressed key.""" + if isinstance(other, ECKey): + assert other.secret > 0 and other.secret < SECP256K1_ORDER + assert self.valid is True + ret_data = ((self.secret * other.secret) % SECP256K1_ORDER).to_bytes(32, 'big') + ret = ECKey() + ret.set(ret_data, True) + return ret + elif isinstance(other, ECPubKey): + return other * self + else: + # ECKey().set() checks that other is an `int` or `bytes` + assert self.valid + second = ECKey().set(other, self.compressed) + return self * second + + def __rmul__(self, other): + return self * other + + def add(self, data): + """Add key to scalar data. Returns compressed key.""" + other = ECKey() + other.set(data, True) + return self + other + + def mul(self, data): + """Multiply key secret with scalar data. Returns compressed key.""" + other = ECKey() + other.set(data, True) + return self * other + + def negate(self): + """Negate a private key.""" + assert self.valid + self.secret = SECP256K1_ORDER - self.secret + + @property + def is_valid(self): + return self.valid + + @property + def is_compressed(self): + return self.compressed + + def get_pubkey(self): + """Compute an ECPubKey object for this secret key.""" + assert(self.valid) + ret = ECPubKey() + p = SECP256K1.mul([(SECP256K1_G, self.secret)]) + ret.p = p + ret.valid = True + ret.compressed = self.compressed + return ret + + def sign_ecdsa(self, msg, low_s=True): + """Construct a DER-encoded ECDSA signature with this key. + + See https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm for the + ECDSA signer algorithm.""" + assert(self.valid) + z = int.from_bytes(msg, 'big') + # Note: no RFC6979, but a simple random nonce (some tests rely on distinct transactions for the same operation) + k = random.randrange(1, SECP256K1_ORDER) + R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, k)])) + r = R[0] % SECP256K1_ORDER + s = (modinv(k, SECP256K1_ORDER) * (z + self.secret * r)) % SECP256K1_ORDER + if low_s and s > SECP256K1_ORDER_HALF: + s = SECP256K1_ORDER - s + # Represent in DER format. The byte representations of r and s have + # length rounded up (255 bits becomes 32 bytes and 256 bits becomes 33 + # bytes). + rb = r.to_bytes((r.bit_length() + 8) // 8, 'big') + sb = s.to_bytes((s.bit_length() + 8) // 8, 'big') + return b'\x30' + bytes([4 + len(rb) + len(sb), 2, len(rb)]) + rb + bytes([2, len(sb)]) + sb + + def sign_schnorr(self, msg, aux=None): + """Create a Schnorr signature (see BIP340).""" + if aux is None: + aux = bytes(32) + + assert self.valid + assert len(msg) == 32 + assert len(aux) == 32 + + t = (self.secret ^ int.from_bytes(TaggedHash("BIP0340/aux", aux), 'big')).to_bytes(32, 'big') + kp = int.from_bytes(TaggedHash("BIP0340/nonce", t + self.get_pubkey().get_bytes() + msg), 'big') % SECP256K1_ORDER + assert kp != 0 + R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, kp)])) + k = kp if SECP256K1.has_even_y(R) else SECP256K1_ORDER - kp + e = int.from_bytes(TaggedHash("BIP0340/challenge", R[0].to_bytes(32, 'big') + self.get_pubkey().get_bytes() + msg), 'big') % SECP256K1_ORDER + return R[0].to_bytes(32, 'big') + ((k + e * self.secret) % SECP256K1_ORDER).to_bytes(32, 'big') + + def tweak_add(self, tweak): + """Return a tweaked version of this private key.""" + assert(self.valid) + t = int_or_bytes(tweak) + if t >= SECP256K1_ORDER: + return None + tweaked = (self.secret + t) % SECP256K1_ORDER + if tweaked == 0: + return None + ret = ECKey() + ret.set(tweaked.to_bytes(32, 'big'), self.compressed) + return ret + +def generate_key_pair(secret=None, compressed=True): + """Convenience function to generate a private-public key pair.""" + d = ECKey() + if secret: + d.set(secret, compressed) + else: + d.generate(compressed) + + P = d.get_pubkey() + return d, P + +def generate_bip340_key_pair(): + """Convenience function to generate a BIP0340 private-public key pair.""" + d = ECKey() + d.generate() + P = d.get_pubkey() + if P.get_y()%2 != 0: + d.negate() + P.negate() + return d, P + +def generate_schnorr_nonce(): + """Generate a random valid BIP340 nonce. + + See https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki. + This implementation ensures the y-coordinate of the nonce point is even.""" + kp = random.randrange(1, SECP256K1_ORDER) + assert kp != 0 + R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, kp)])) + k = kp if R[1] % 2 == 0 else SECP256K1_ORDER - kp + k_key = ECKey() + k_key.set(k.to_bytes(32, 'big'), True) + return k_key diff --git a/bip-0352/send_and_receive_test_vectors.json b/bip-0352/send_and_receive_test_vectors.json new file mode 100644 index 0000000000..6643562240 --- /dev/null +++ b/bip-0352/send_and_receive_test_vectors.json @@ -0,0 +1,1887 @@ +[ + { + "comment": "Simple send: two inputs", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "483046022100a6b5986a2143d7beb3c431d7b192bbec22b624f2efbb5dfcc658d66a5e41656d022100c70691f451cfec2dae191766fc4beffe6076c248dc3a12bc2ce83569018387f821025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "483046022100cd881ddd58407ed9fcc0beb3c997d2bba75018e7ad64832b8eeb0e397d5ae16e022100e78bbf5e6fbb3eea2c8f18d1e3ce1b921487bbef2f618fff219d133106508e8a2103bd85685d03d111699b15d046319febe77f8de5286e9e512703cdee1bf3be3792", + "" + ], + "scriptPubKey": "76a914d9317c66f54ff0a152ec50b1d19c25be50c8e15988ac", + "private_key": "93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "7f0e387ea0f9ebc9ad4955c39c1c656b709eb2fb420b9b0320bb3f88664deae9", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "483046022100a6b5986a2143d7beb3c431d7b192bbec22b624f2efbb5dfcc658d66a5e41656d022100c70691f451cfec2dae191766fc4beffe6076c248dc3a12bc2ce83569018387f821025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "483046022100cd881ddd58407ed9fcc0beb3c997d2bba75018e7ad64832b8eeb0e397d5ae16e022100e78bbf5e6fbb3eea2c8f18d1e3ce1b921487bbef2f618fff219d133106508e8a2103bd85685d03d111699b15d046319febe77f8de5286e9e512703cdee1bf3be3792", + "" + ], + "scriptPubKey": "76a914d9317c66f54ff0a152ec50b1d19c25be50c8e15988ac" + } + ], + "outputs": [ + "7f0e387ea0f9ebc9ad4955c39c1c656b709eb2fb420b9b0320bb3f88664deae9" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "7f0e387ea0f9ebc9ad4955c39c1c656b709eb2fb420b9b0320bb3f88664deae9", + "priv_key_tweak": "44348f94383ff282dee71d281fe3a122c69a2a2dc0976fb2e7e9613c78c1b19a", + "signature": "7041a38f6c422fdd7bf77335ae8614a6de20b2ff00e496a70b905f17220e9fb002d62043f54d9a4d1a6afce90e26c928734d303be62aaf41bc1bf2731b05dca7" + } + ] + } + } + ] + }, + { + "comment": "Simple send: two inputs, order reversed", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "46304402204ea12920c510f9a7b929852abcc1b507c049fd5187a3746bc98106ce3bcaab9d022027c22435c4702cceac9cb964d324079992e114394b7b3ceb4d9461af6cff3dda21025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "47304502207d82b2ecd2b56da78752214eadc3e68135fba894da92729bcb4ff639caa74605022100d27abccc2007fb10d247f7afe6c5f008dd2f2e6ff59c6cf45733214ae4381ed02103bd85685d03d111699b15d046319febe77f8de5286e9e512703cdee1bf3be3792", + "" + ], + "scriptPubKey": "76a914d9317c66f54ff0a152ec50b1d19c25be50c8e15988ac", + "private_key": "93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "7f0e387ea0f9ebc9ad4955c39c1c656b709eb2fb420b9b0320bb3f88664deae9", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "46304402204ea12920c510f9a7b929852abcc1b507c049fd5187a3746bc98106ce3bcaab9d022027c22435c4702cceac9cb964d324079992e114394b7b3ceb4d9461af6cff3dda21025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "47304502207d82b2ecd2b56da78752214eadc3e68135fba894da92729bcb4ff639caa74605022100d27abccc2007fb10d247f7afe6c5f008dd2f2e6ff59c6cf45733214ae4381ed02103bd85685d03d111699b15d046319febe77f8de5286e9e512703cdee1bf3be3792", + "" + ], + "scriptPubKey": "76a914d9317c66f54ff0a152ec50b1d19c25be50c8e15988ac" + } + ], + "outputs": [ + "7f0e387ea0f9ebc9ad4955c39c1c656b709eb2fb420b9b0320bb3f88664deae9" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "7f0e387ea0f9ebc9ad4955c39c1c656b709eb2fb420b9b0320bb3f88664deae9", + "priv_key_tweak": "44348f94383ff282dee71d281fe3a122c69a2a2dc0976fb2e7e9613c78c1b19a", + "signature": "7041a38f6c422fdd7bf77335ae8614a6de20b2ff00e496a70b905f17220e9fb002d62043f54d9a4d1a6afce90e26c928734d303be62aaf41bc1bf2731b05dca7" + } + ] + } + } + ] + }, + { + "comment": "Simple send: two inputs from the same transaction", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 3, + "473045022025ec2a44185e3a59fa5f7c44d65a7bf4f3fd900b493e74e78ac25a3454dfe47f022100a13804c1d69843007dce294c37bd63f6e7c9b2ca9a457c497c0862dabac4fd4821025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 7, + "473045022100d3572e04b2167246791018c835588660b1fce9e42f36cc702db697c35dd0c81b022057f3323bb0f588d4bcffdc576a5a9dc667687e11dd57bd1251afd06957c409a22103bd85685d03d111699b15d046319febe77f8de5286e9e512703cdee1bf3be3792", + "" + ], + "scriptPubKey": "76a914d9317c66f54ff0a152ec50b1d19c25be50c8e15988ac", + "private_key": "93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "9143650466b48b9e477c36153ebcfa98a5c0428583ffc498eb9eb0fdff71f395", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 3, + "473045022025ec2a44185e3a59fa5f7c44d65a7bf4f3fd900b493e74e78ac25a3454dfe47f022100a13804c1d69843007dce294c37bd63f6e7c9b2ca9a457c497c0862dabac4fd4821025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 7, + "473045022100d3572e04b2167246791018c835588660b1fce9e42f36cc702db697c35dd0c81b022057f3323bb0f588d4bcffdc576a5a9dc667687e11dd57bd1251afd06957c409a22103bd85685d03d111699b15d046319febe77f8de5286e9e512703cdee1bf3be3792", + "" + ], + "scriptPubKey": "76a914d9317c66f54ff0a152ec50b1d19c25be50c8e15988ac" + } + ], + "outputs": [ + "9143650466b48b9e477c36153ebcfa98a5c0428583ffc498eb9eb0fdff71f395" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "9143650466b48b9e477c36153ebcfa98a5c0428583ffc498eb9eb0fdff71f395", + "priv_key_tweak": "45e357513a2e82eb2f8d3d466b9cb66ef4031b672ee3a76ac1d4a3fd6ae1eea9", + "signature": "621ae10afffd794f1c0b59da3264a1b4470c7ea9aff22bbd29d9c319dac05834860789f4c9edb139714230f1f4b7ae5f9191cce106284f7221097f65cfd5ef9d" + } + ] + } + } + ] + }, + { + "comment": "Simple send: two inputs from the same transaction, order reversed", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 7, + "47304502200f3cbea3a383b6971e819e2d63e8c98eef00d1c89bfbbd9bb18ad0d0f1f93e16022100fa8666adde790d622601eb13eec1aff27a7688bf52b9138500946916fe19f8ee21025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 3, + "46304402206a48da9ff8c23169ec7fac46254994978223efe8a13e8f7fb1d9ad026452b5af02206d6cb662b08597665acfd7511d7ad90b6f3679ed55a6fe37db05b99dd5961a7a2103bd85685d03d111699b15d046319febe77f8de5286e9e512703cdee1bf3be3792", + "" + ], + "scriptPubKey": "76a914d9317c66f54ff0a152ec50b1d19c25be50c8e15988ac", + "private_key": "93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "4dbeac765ae35d74a5a3b0de21c905aa72cb00c927dd16a0be546e8a71a3220a", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 7, + "47304502200f3cbea3a383b6971e819e2d63e8c98eef00d1c89bfbbd9bb18ad0d0f1f93e16022100fa8666adde790d622601eb13eec1aff27a7688bf52b9138500946916fe19f8ee21025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 3, + "46304402206a48da9ff8c23169ec7fac46254994978223efe8a13e8f7fb1d9ad026452b5af02206d6cb662b08597665acfd7511d7ad90b6f3679ed55a6fe37db05b99dd5961a7a2103bd85685d03d111699b15d046319febe77f8de5286e9e512703cdee1bf3be3792", + "" + ], + "scriptPubKey": "76a914d9317c66f54ff0a152ec50b1d19c25be50c8e15988ac" + } + ], + "outputs": [ + "4dbeac765ae35d74a5a3b0de21c905aa72cb00c927dd16a0be546e8a71a3220a" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "4dbeac765ae35d74a5a3b0de21c905aa72cb00c927dd16a0be546e8a71a3220a", + "priv_key_tweak": "2cbefe5efa9fd262d6bf5a3cd20b68d31e2d95affd8c852c21151cab4f6c1842", + "signature": "2a07a15f3f12c225a8969578a7b4610966c3f8b37259661342a5feb8baa384e8eb13d6dc9a6b72f664483c410506a7e4e8572e663a048eb1dbd48830df96d928" + } + ] + } + } + ] + }, + { + "comment": "Single recipient: multiple UTXOs from the same public key", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100fb8b178739a78f27675bc29bf761092396796ea46bb7ce4eb16eae6af40d0b7c02207128fd37978b5f87bcc4b3140ec37f76ba298aeac19610ecdf0d98584022b41e21025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "473045022100d2273c82a0f82a5cfb344333c9c2b28e3949103f264238decbab02a97bc170e302207b63373cb9038b9ea74dc1fcb629cfcd44ca3433c51884ab84980b999388afee21025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "d87492c685f0949b8984355507f082a224ceee656d5379f25b57960d1766f5c2", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100fb8b178739a78f27675bc29bf761092396796ea46bb7ce4eb16eae6af40d0b7c02207128fd37978b5f87bcc4b3140ec37f76ba298aeac19610ecdf0d98584022b41e21025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "473045022100d2273c82a0f82a5cfb344333c9c2b28e3949103f264238decbab02a97bc170e302207b63373cb9038b9ea74dc1fcb629cfcd44ca3433c51884ab84980b999388afee21025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + } + ], + "outputs": [ + "d87492c685f0949b8984355507f082a224ceee656d5379f25b57960d1766f5c2" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "d87492c685f0949b8984355507f082a224ceee656d5379f25b57960d1766f5c2", + "priv_key_tweak": "c6728fa20e4e250569c3c6527663a6af28e037196a1025bf4783ef743764042f", + "signature": "2166d84fd52fb6332da41aabf6f3e7fbdefd7fc54b4778358fbd6a2d332f75ea96c12521cd977b672ad7d491d5be85c5c22c4103f588213a95d76c5a68870011" + } + ] + } + } + ] + }, + { + "comment": "Single recipient: taproot only inputs with even y-values", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "", + "0140c459b671370d12cfb5acee76da7e3ba7cc29b0b4653e3af8388591082660137d087fdc8e89a612cd5d15be0febe61fc7cdcf3161a26e599a4514aa5c3e86f47b" + ], + "scriptPubKey": "51205a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "", + "0140bd1e708f92dbeaf24a6b8dd22e59c6274355424d62baea976b449e220fd75b13578e262ab11b7aa58e037f0c6b0519b66803b7d9decaa1906dedebfb531c56c1" + ], + "scriptPubKey": "5120782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "private_key": "fc8716a97a48ba9a05a98ae47b5cd201a25a7fd5d8b73c203c5f7b6b6b3b6ad7" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "569808b1f30d9545a96f5daa2b606a738f9e9dc0fb93fd8725d9074fc49bd96a", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "", + "0140c459b671370d12cfb5acee76da7e3ba7cc29b0b4653e3af8388591082660137d087fdc8e89a612cd5d15be0febe61fc7cdcf3161a26e599a4514aa5c3e86f47b" + ], + "scriptPubKey": "51205a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "", + "0140bd1e708f92dbeaf24a6b8dd22e59c6274355424d62baea976b449e220fd75b13578e262ab11b7aa58e037f0c6b0519b66803b7d9decaa1906dedebfb531c56c1" + ], + "scriptPubKey": "5120782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338" + } + ], + "outputs": [ + "569808b1f30d9545a96f5daa2b606a738f9e9dc0fb93fd8725d9074fc49bd96a" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "569808b1f30d9545a96f5daa2b606a738f9e9dc0fb93fd8725d9074fc49bd96a", + "priv_key_tweak": "20136ed427b2360406220950c5aa412876305d3a4300f48a4478a5d99d42b9bf", + "signature": "3996845049944868c0ae3ce31f7c1394294caf04075a1d4aa3d0ad2d38208353179d9d301c813f20208911734f765f8d632804a1d58eb6dfc6d50017a3b7d99d" + } + ] + } + } + ] + }, + { + "comment": "Single recipient: taproot only with mixed even/odd y-values", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "", + "0140c459b671370d12cfb5acee76da7e3ba7cc29b0b4653e3af8388591082660137d087fdc8e89a612cd5d15be0febe61fc7cdcf3161a26e599a4514aa5c3e86f47b" + ], + "scriptPubKey": "51205a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "", + "01400a4d0dca6293f40499394d7eefe14a1de11e0e3454f51de2e802592abf5ee549042a1b1a8fb2e149ee9dd3f086c1b69b2f182565ab6ecf599b1ec9ebadfda6c5" + ], + "scriptPubKey": "51208c8d23d4764feffcd5e72e380802540fa0f88e3d62ad5e0b47955f74d7b283c4", + "private_key": "1d37787c2b7116ee983e9f9c13269df29091b391c04db94239e0d2bc2182c3bf" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "856c6088f3de9d44f6823fe11d69c3294d7eb18281217ecd4ff45e7abb17127c", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "", + "0140c459b671370d12cfb5acee76da7e3ba7cc29b0b4653e3af8388591082660137d087fdc8e89a612cd5d15be0febe61fc7cdcf3161a26e599a4514aa5c3e86f47b" + ], + "scriptPubKey": "51205a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "", + "01400a4d0dca6293f40499394d7eefe14a1de11e0e3454f51de2e802592abf5ee549042a1b1a8fb2e149ee9dd3f086c1b69b2f182565ab6ecf599b1ec9ebadfda6c5" + ], + "scriptPubKey": "51208c8d23d4764feffcd5e72e380802540fa0f88e3d62ad5e0b47955f74d7b283c4" + } + ], + "outputs": [ + "856c6088f3de9d44f6823fe11d69c3294d7eb18281217ecd4ff45e7abb17127c" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "856c6088f3de9d44f6823fe11d69c3294d7eb18281217ecd4ff45e7abb17127c", + "priv_key_tweak": "991389ce6e2fd5d491c047323fff87aaca8f9b4c8712085679a068b632e71435", + "signature": "280bd12fd4a213e97d24280220fd564b48bfdf943b8b08d774de0509c2edbe9c6bd339193d64176f4917d391d10fa1fd6ef6d89ebe78a8f02918261cfb4bf750" + } + ] + } + } + ] + }, + { + "comment": "Single recipient: taproot input with even y-value and non-taproot input", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "", + "0140c459b671370d12cfb5acee76da7e3ba7cc29b0b4653e3af8388591082660137d087fdc8e89a612cd5d15be0febe61fc7cdcf3161a26e599a4514aa5c3e86f47b" + ], + "scriptPubKey": "51205a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "473045022003bb1d4ea47105344c1f603c65c25d988e605b79c3f8d9f562cf034ea12c173c022100bea7ab487d2de4ed0e9b699577837001166066acdc46f9e5eb19e839da65aac72103e0ec4f64b3fa2e463ccfcf4e856e37d5e1e20275bc89ec1def9eb098eff1f85d", + "" + ], + "scriptPubKey": "76a9148cbc7dfe44f1579bff3340bbef1eddeaeb1fc97788ac", + "private_key": "8d4751f6e8a3586880fb66c19ae277969bd5aa06f61c4ee2f1e2486efdf666d3" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "39dc1b0f9226f22daccda2e0c593ab4243889f73d9554f4465ba7dfd552c6672", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "", + "0140c459b671370d12cfb5acee76da7e3ba7cc29b0b4653e3af8388591082660137d087fdc8e89a612cd5d15be0febe61fc7cdcf3161a26e599a4514aa5c3e86f47b" + ], + "scriptPubKey": "51205a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "473045022003bb1d4ea47105344c1f603c65c25d988e605b79c3f8d9f562cf034ea12c173c022100bea7ab487d2de4ed0e9b699577837001166066acdc46f9e5eb19e839da65aac72103e0ec4f64b3fa2e463ccfcf4e856e37d5e1e20275bc89ec1def9eb098eff1f85d", + "" + ], + "scriptPubKey": "76a9148cbc7dfe44f1579bff3340bbef1eddeaeb1fc97788ac" + } + ], + "outputs": [ + "39dc1b0f9226f22daccda2e0c593ab4243889f73d9554f4465ba7dfd552c6672" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "39dc1b0f9226f22daccda2e0c593ab4243889f73d9554f4465ba7dfd552c6672", + "priv_key_tweak": "66cf5461b2c8501bc2593182a6d92cfdad88bb2129bed4216dc9aa965b87f2fc", + "signature": "3a700319a56d280ef3460324a016f7c817587d60d26d192226e82c4ea0fd46645566bc3cfb956756aa04521905288a3942a10dd115f228654f5e6f326481a172" + } + ] + } + } + ] + }, + { + "comment": "Single recipient: taproot input with odd y-value and non-taproot input", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "", + "01400a4d0dca6293f40499394d7eefe14a1de11e0e3454f51de2e802592abf5ee549042a1b1a8fb2e149ee9dd3f086c1b69b2f182565ab6ecf599b1ec9ebadfda6c5" + ], + "scriptPubKey": "51208c8d23d4764feffcd5e72e380802540fa0f88e3d62ad5e0b47955f74d7b283c4", + "private_key": "1d37787c2b7116ee983e9f9c13269df29091b391c04db94239e0d2bc2182c3bf" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "48304602210086115b1d327cbe99fdc20c280f2a5ab6f358b2caa5e557c827d7bdf7f170924d0221009663105709c2f39f516896c185bbf583e9f12a3d75606254c2c761dad08fdcd42103e0ec4f64b3fa2e463ccfcf4e856e37d5e1e20275bc89ec1def9eb098eff1f85d", + "" + ], + "scriptPubKey": "76a9148cbc7dfe44f1579bff3340bbef1eddeaeb1fc97788ac", + "private_key": "8d4751f6e8a3586880fb66c19ae277969bd5aa06f61c4ee2f1e2486efdf666d3" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "e02a5a320697649bfd7bdd2eea80ae117dec20e23489947a5a2024de69dbbdb2", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "", + "01400a4d0dca6293f40499394d7eefe14a1de11e0e3454f51de2e802592abf5ee549042a1b1a8fb2e149ee9dd3f086c1b69b2f182565ab6ecf599b1ec9ebadfda6c5" + ], + "scriptPubKey": "51208c8d23d4764feffcd5e72e380802540fa0f88e3d62ad5e0b47955f74d7b283c4" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "48304602210086115b1d327cbe99fdc20c280f2a5ab6f358b2caa5e557c827d7bdf7f170924d0221009663105709c2f39f516896c185bbf583e9f12a3d75606254c2c761dad08fdcd42103e0ec4f64b3fa2e463ccfcf4e856e37d5e1e20275bc89ec1def9eb098eff1f85d", + "" + ], + "scriptPubKey": "76a9148cbc7dfe44f1579bff3340bbef1eddeaeb1fc97788ac" + } + ], + "outputs": [ + "e02a5a320697649bfd7bdd2eea80ae117dec20e23489947a5a2024de69dbbdb2" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "e02a5a320697649bfd7bdd2eea80ae117dec20e23489947a5a2024de69dbbdb2", + "priv_key_tweak": "dd66d74bd2ee8cb01a4b024313f279920de01dda5f515ae9a54bc031dbfcd1dc", + "signature": "092c57002a5e5d465440da20689416834d956e3f5f4b610c470bfc0815cdab27c62051c78f6d0575d309760788e32b07bfc4cfb5e942bfefe69356452b1813f5" + } + ] + } + } + ] + }, + { + "comment": "Multiple outputs: multiple outputs, same recipient", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100954340a90888fb4e5f0af3df70989f44f8a2e6a91319622734b352a6f3a37f61022006f2a219b19bb3daeeb7d1608293a4937f7fc0a661f9941189311d4711efd50621025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "46304402202858b6ffb1ba1738e87876abb9f0977369bb151606cb3bb3d335819d4b515bdf02206adf930fd3278cf1bb7af6c9537bcc3c3106c6c742f38c0796ead37470cce7052103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac", + "private_key": "0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 2.0 + ], + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 3.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + 2.0 + ], + [ + "c79b7e78c0525306e5306c45e5efbea768cb1caa546c0345cb0c9553f0f6a89c", + 3.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100954340a90888fb4e5f0af3df70989f44f8a2e6a91319622734b352a6f3a37f61022006f2a219b19bb3daeeb7d1608293a4937f7fc0a661f9941189311d4711efd50621025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "46304402202858b6ffb1ba1738e87876abb9f0977369bb151606cb3bb3d335819d4b515bdf02206adf930fd3278cf1bb7af6c9537bcc3c3106c6c742f38c0796ead37470cce7052103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "c79b7e78c0525306e5306c45e5efbea768cb1caa546c0345cb0c9553f0f6a89c", + "96b0690eeffb9caf329ff74dd7f564113352f3d98c5bd8e2dde17e1f9fa0da57", + "4885fc5028ec177827ea0ae1064be659a5b2b692badd25ae17565e4cc48c2775" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "priv_key_tweak": "f990515fa92c9baa6504697d2ee1eec7e8320308490a53a6add12493ef96953c", + "signature": "01322e61146a5dccaa246408289c4a48e4d332c74ab47a475fcaa95019a622d1b52a4c9d14af1c85afdb6a0e730e5cfd06cc8c2181aa14f78166ea70d710d76c" + }, + { + "pub_key": "c79b7e78c0525306e5306c45e5efbea768cb1caa546c0345cb0c9553f0f6a89c", + "priv_key_tweak": "aec9012d47d6d2f653a8f9d1f03c54a8113df7d649b11b3dd3a4c38cfbb5eb95", + "signature": "232ad9c93e4a9222b0aaab9a5087ac22cb7b453784357126fdcb204ab52b6ea4a47418d5a6045753af37290f3b2f2f69969e8822b5c0d1cd87f179d306c85341" + } + ] + } + } + ] + }, + { + "comment": "Multiple outputs: multiple outputs, multiple recipients", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100954340a90888fb4e5f0af3df70989f44f8a2e6a91319622734b352a6f3a37f61022006f2a219b19bb3daeeb7d1608293a4937f7fc0a661f9941189311d4711efd50621025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "46304402202858b6ffb1ba1738e87876abb9f0977369bb151606cb3bb3d335819d4b515bdf02206adf930fd3278cf1bb7af6c9537bcc3c3106c6c742f38c0796ead37470cce7052103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac", + "private_key": "0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 2.0 + ], + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 3.0 + ], + [ + "sp1qqgrz6j0lcqnc04vxccydl0kpsj4frfje0ktmgcl2t346hkw30226xqupawdf48k8882j0strrvcmgg2kdawz53a54dd376ngdhak364hzcmynqtn", + 4.0 + ], + [ + "sp1qqgrz6j0lcqnc04vxccydl0kpsj4frfje0ktmgcl2t346hkw30226xqupawdf48k8882j0strrvcmgg2kdawz53a54dd376ngdhak364hzcmynqtn", + 5.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + 2.0 + ], + [ + "c79b7e78c0525306e5306c45e5efbea768cb1caa546c0345cb0c9553f0f6a89c", + 3.0 + ], + [ + "96b0690eeffb9caf329ff74dd7f564113352f3d98c5bd8e2dde17e1f9fa0da57", + 4.0 + ], + [ + "4885fc5028ec177827ea0ae1064be659a5b2b692badd25ae17565e4cc48c2775", + 5.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100954340a90888fb4e5f0af3df70989f44f8a2e6a91319622734b352a6f3a37f61022006f2a219b19bb3daeeb7d1608293a4937f7fc0a661f9941189311d4711efd50621025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "46304402202858b6ffb1ba1738e87876abb9f0977369bb151606cb3bb3d335819d4b515bdf02206adf930fd3278cf1bb7af6c9537bcc3c3106c6c742f38c0796ead37470cce7052103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "c79b7e78c0525306e5306c45e5efbea768cb1caa546c0345cb0c9553f0f6a89c", + "96b0690eeffb9caf329ff74dd7f564113352f3d98c5bd8e2dde17e1f9fa0da57", + "4885fc5028ec177827ea0ae1064be659a5b2b692badd25ae17565e4cc48c2775" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "priv_key_tweak": "f990515fa92c9baa6504697d2ee1eec7e8320308490a53a6add12493ef96953c", + "signature": "01322e61146a5dccaa246408289c4a48e4d332c74ab47a475fcaa95019a622d1b52a4c9d14af1c85afdb6a0e730e5cfd06cc8c2181aa14f78166ea70d710d76c" + }, + { + "pub_key": "c79b7e78c0525306e5306c45e5efbea768cb1caa546c0345cb0c9553f0f6a89c", + "priv_key_tweak": "aec9012d47d6d2f653a8f9d1f03c54a8113df7d649b11b3dd3a4c38cfbb5eb95", + "signature": "232ad9c93e4a9222b0aaab9a5087ac22cb7b453784357126fdcb204ab52b6ea4a47418d5a6045753af37290f3b2f2f69969e8822b5c0d1cd87f179d306c85341" + } + ] + } + }, + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100954340a90888fb4e5f0af3df70989f44f8a2e6a91319622734b352a6f3a37f61022006f2a219b19bb3daeeb7d1608293a4937f7fc0a661f9941189311d4711efd50621025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "46304402202858b6ffb1ba1738e87876abb9f0977369bb151606cb3bb3d335819d4b515bdf02206adf930fd3278cf1bb7af6c9537bcc3c3106c6c742f38c0796ead37470cce7052103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "c79b7e78c0525306e5306c45e5efbea768cb1caa546c0345cb0c9553f0f6a89c", + "96b0690eeffb9caf329ff74dd7f564113352f3d98c5bd8e2dde17e1f9fa0da57", + "4885fc5028ec177827ea0ae1064be659a5b2b692badd25ae17565e4cc48c2775" + ], + "key_material": { + "spend_priv_key": "9902c3c56e84002a7cd410113a9ab21d142be7f53cf5200720bb01314c5eb920", + "scan_priv_key": "060b751d7892149006ed7b98606955a29fe284a1e900070c0971f5fb93dbf422" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgrz6j0lcqnc04vxccydl0kpsj4frfje0ktmgcl2t346hkw30226xqupawdf48k8882j0strrvcmgg2kdawz53a54dd376ngdhak364hzcmynqtn" + ], + "outputs": [ + { + "pub_key": "96b0690eeffb9caf329ff74dd7f564113352f3d98c5bd8e2dde17e1f9fa0da57", + "priv_key_tweak": "1614cf8a3f693374e88eade93a0631842b40312d35b514c1306435e6fabcd6a8", + "signature": "1a781d6a54005cd5c72d2352dacfa3c9303aed77f8c2b140e1da57fcebfc84f944c22091e7c19f8098b3135a2dc6b0987432f56270397e6d557748f903c03d11" + }, + { + "pub_key": "4885fc5028ec177827ea0ae1064be659a5b2b692badd25ae17565e4cc48c2775", + "priv_key_tweak": "b9e83c746123d572ed75b742c0fa9da77b9ef5273cede419718f6ed00d0bb4e9", + "signature": "df4cd62c311602716d819e18111d4482c2343cb03c9e66092a700e016a3ca6d95665d5e1d58f5a50482189a9fcec158a47023656a924302d2699c1cfdf973753" + } + ] + } + } + ] + }, + { + "comment": "Receiving with labels: label with odd parity", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "4830460221008066df7a28396408ac5f63ea212dbf10375cf2b7c782796d217013f202e4c6d0022100849d255d0867c3e3b2a679945c2c9133d398048d9f751895509eea28f684c24421025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "47304502201963a4f89f012b2eb5fb3130c083ceb268a8f19bd609bdd1611cea196cc9fc40022100feead4e7b001db92d068d3f19091fd7243d6481fddd5f86660984d6ada8a99432103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac", + "private_key": "0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqlqtzs0rexz7dksqyr5e9nqv6ym3j4p4a2hkpv55f4yccjzhz6wu5adxu0e", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "35bd8540cb41761b9848dbfe6c8edb2350ac8f7dec94e511c8365a9d4be7e711", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "4830460221008066df7a28396408ac5f63ea212dbf10375cf2b7c782796d217013f202e4c6d0022100849d255d0867c3e3b2a679945c2c9133d398048d9f751895509eea28f684c24421025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "47304502201963a4f89f012b2eb5fb3130c083ceb268a8f19bd609bdd1611cea196cc9fc40022100feead4e7b001db92d068d3f19091fd7243d6481fddd5f86660984d6ada8a99432103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "35bd8540cb41761b9848dbfe6c8edb2350ac8f7dec94e511c8365a9d4be7e711" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [ + 2, + 3, + 1001337 + ] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqlqtzs0rexz7dksqyr5e9nqv6ym3j4p4a2hkpv55f4yccjzhz6wu5adxu0e", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq60n0kvxr0lck9rlw7r5rdez5u4c5fqvrppct9plnzcnppp3cfa8c7ts0xh", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqmghhc39w7u5v3kvtl7lgna2dhjr4wlamrvmd3d3edw0u6jzd7xvu5wjgul" + ], + "outputs": [ + { + "pub_key": "35bd8540cb41761b9848dbfe6c8edb2350ac8f7dec94e511c8365a9d4be7e711", + "priv_key_tweak": "62aa6e447d324d1549aadfcb4a059ffcad09dd6d178a9e474501a3ac39a0e17b", + "signature": "25340d843e2734e5693a91d0292e2b27fcff1f141168a33e6e2a0146f7eb9edb0e292ca2522e29427c39dcc87747dd3883c0878241e1abaf13174b25fecb5bcf" + } + ] + } + } + ] + }, + { + "comment": "Receiving with labels: label with odd parity", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022030592547ec33661bebaf2f8903e0e2bab1dd39799bafdebf23c7c405c818ac3e022100fb7f7af1e26dbd4c703d43cfc082c18a795115d880440d181746d34b5c2847f521025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "473045022076685024a6a149076e57391cedacfa59de8d7ca0003e9134cb26aa006f099419022100863892321305eda8f2a72ce81bc815d0ebe8ab464d5502dc8e66ba73fa80e3842103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac", + "private_key": "0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq60n0kvxr0lck9rlw7r5rdez5u4c5fqvrppct9plnzcnppp3cfa8c7ts0xh", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "7a6862be9614902a6f3efd70bd3126a54cbec075241a5b5fc612953aa526af70", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022030592547ec33661bebaf2f8903e0e2bab1dd39799bafdebf23c7c405c818ac3e022100fb7f7af1e26dbd4c703d43cfc082c18a795115d880440d181746d34b5c2847f521025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "473045022076685024a6a149076e57391cedacfa59de8d7ca0003e9134cb26aa006f099419022100863892321305eda8f2a72ce81bc815d0ebe8ab464d5502dc8e66ba73fa80e3842103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "7a6862be9614902a6f3efd70bd3126a54cbec075241a5b5fc612953aa526af70" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [ + 2, + 3, + 1001337 + ] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqlqtzs0rexz7dksqyr5e9nqv6ym3j4p4a2hkpv55f4yccjzhz6wu5adxu0e", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq60n0kvxr0lck9rlw7r5rdez5u4c5fqvrppct9plnzcnppp3cfa8c7ts0xh", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqmghhc39w7u5v3kvtl7lgna2dhjr4wlamrvmd3d3edw0u6jzd7xvu5wjgul" + ], + "outputs": [ + { + "pub_key": "7a6862be9614902a6f3efd70bd3126a54cbec075241a5b5fc612953aa526af70", + "priv_key_tweak": "d95cb02470e00c19f54c0138eb55fa7719665fbd1123c1cc8e55d11aea2f7eac", + "signature": "4d609efb766640125e1b39290cc7bac128c1f157b989556e1a5ad16eec5ae3d9fc265a0b8d0184900cdeda184484e6868ba06856613227049f6e127ddd4af8c7" + } + ] + } + } + ] + }, + { + "comment": "Receiving with labels: label with odd parity", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "47304502204d646f77229d9df97ac6fec83cc09342d88eb1cb49b1d7e2562d435e9aed9e10022100c3380e8f7a0aa240fc6d7c1c14d8247acc2a6434b63bc09c6eaa7adbe9ad779e21025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "47304502206a52823add6f964a02580a3d81f9ce3e245089c8188ff10b40dd58a4a40a8bf7022100a2fe6500632b9074cfb1465f6f8305562f8caee001705112898ab4bf58273b212103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac", + "private_key": "0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqmghhc39w7u5v3kvtl7lgna2dhjr4wlamrvmd3d3edw0u6jzd7xvu5wjgul", + 1.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "a9fd32c0d5860d1423df49c26b3c7f2af7581e3c021504a4a1f650fbd28b1405", + 1.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "47304502204d646f77229d9df97ac6fec83cc09342d88eb1cb49b1d7e2562d435e9aed9e10022100c3380e8f7a0aa240fc6d7c1c14d8247acc2a6434b63bc09c6eaa7adbe9ad779e21025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "47304502206a52823add6f964a02580a3d81f9ce3e245089c8188ff10b40dd58a4a40a8bf7022100a2fe6500632b9074cfb1465f6f8305562f8caee001705112898ab4bf58273b212103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "a9fd32c0d5860d1423df49c26b3c7f2af7581e3c021504a4a1f650fbd28b1405" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [ + 2, + 3, + 1001337 + ] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqlqtzs0rexz7dksqyr5e9nqv6ym3j4p4a2hkpv55f4yccjzhz6wu5adxu0e", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq60n0kvxr0lck9rlw7r5rdez5u4c5fqvrppct9plnzcnppp3cfa8c7ts0xh", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqmghhc39w7u5v3kvtl7lgna2dhjr4wlamrvmd3d3edw0u6jzd7xvu5wjgul" + ], + "outputs": [ + { + "pub_key": "a9fd32c0d5860d1423df49c26b3c7f2af7581e3c021504a4a1f650fbd28b1405", + "priv_key_tweak": "d85096c6a8c5a444d7a7de42a2066d2039cd27ed7b946224f5fd2887c9169f31", + "signature": "a485d8d829d490326d4d7b95b1e732db0b8effd61768dc26f71528702eab89c13a00359e07c0ea8b6291d1e4c10761f2d851f72c612b04ce847db88c63b7ec56" + } + ] + } + } + ] + }, + { + "comment": "Multiple outputs with labels: multiple outputs for labeled address; same recipient", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100f5b04afadbb2dd5d0ba02e01de8f38e3511df436907229586181f4ec0cb28a57022037389e4d569e69a3acf68637b0ef97448da697bf0e67840418ee11a0326ad9f721025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "473045022048773219ae8f24ea5b476a27e3a7b897fc364fc16d7468afde57640d028b729e022100dc15e213c0afd19f15cf0c3aa7d20ae17a18141356905986faac5587ad81ee2f2103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac", + "private_key": "0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ], + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq5xznr7q7va9qqya76gktf32k2a9q7urxyh6pr9wj3a96p8960cyqtdrdl0", + 2.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + 1.0 + ], + [ + "6a03e0353d94a5da5af238c1ce8c3740815e7920d385d139e14b4cc35901e388", + 2.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100f5b04afadbb2dd5d0ba02e01de8f38e3511df436907229586181f4ec0cb28a57022037389e4d569e69a3acf68637b0ef97448da697bf0e67840418ee11a0326ad9f721025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "473045022048773219ae8f24ea5b476a27e3a7b897fc364fc16d7468afde57640d028b729e022100dc15e213c0afd19f15cf0c3aa7d20ae17a18141356905986faac5587ad81ee2f2103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "6a03e0353d94a5da5af238c1ce8c3740815e7920d385d139e14b4cc35901e388" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [ + 1 + ] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq5xznr7q7va9qqya76gktf32k2a9q7urxyh6pr9wj3a96p8960cyqtdrdl0" + ], + "outputs": [ + { + "pub_key": "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "priv_key_tweak": "f990515fa92c9baa6504697d2ee1eec7e8320308490a53a6add12493ef96953c", + "signature": "01322e61146a5dccaa246408289c4a48e4d332c74ab47a475fcaa95019a622d1b52a4c9d14af1c85afdb6a0e730e5cfd06cc8c2181aa14f78166ea70d710d76c" + }, + { + "pub_key": "6a03e0353d94a5da5af238c1ce8c3740815e7920d385d139e14b4cc35901e388", + "priv_key_tweak": "0d6cfa12865975792f1a88fb5c374c4b07e56e90d49b18de5be21e5d3fca96aa", + "signature": "6e4a69742589439edfab678fe7017f94c46b2082ef2dc7c2da946a24c981187dce73ef0a91f16b6048c64c42f5537211b21ce3d4fdef58377eeabfb9ad64ef41" + } + ] + } + } + ] + }, + { + "comment": "Multiple outputs with labels: multiple outputs for labeled address; same recipient", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100f0648dc1e97c7d075016789fc8105073458d0e1596b61baeecd23e4118a8224602206f0f823ebf8923e35cdff71435d69da4e6eff9ccc419e19afdc5b1d35ecee4c521025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "47304502206ff65484962a2af9c367c4adb4569d86e0c66d651aeb027b8074882848e4cb67022100c10ca811d9e4686a27cb2dde31541b306102993273f30ff6e79b890134e6553f2103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac", + "private_key": "0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq5xznr7q7va9qqya76gktf32k2a9q7urxyh6pr9wj3a96p8960cyqtdrdl0", + 3.0 + ], + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq5xznr7q7va9qqya76gktf32k2a9q7urxyh6pr9wj3a96p8960cyqtdrdl0", + 4.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "6e22e71d7cac7de425f5edd570b1645564eda24f1c986f9d4004cb17f70eaebd", + 3.0 + ], + [ + "6a03e0353d94a5da5af238c1ce8c3740815e7920d385d139e14b4cc35901e388", + 4.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100f0648dc1e97c7d075016789fc8105073458d0e1596b61baeecd23e4118a8224602206f0f823ebf8923e35cdff71435d69da4e6eff9ccc419e19afdc5b1d35ecee4c521025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "47304502206ff65484962a2af9c367c4adb4569d86e0c66d651aeb027b8074882848e4cb67022100c10ca811d9e4686a27cb2dde31541b306102993273f30ff6e79b890134e6553f2103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "6e22e71d7cac7de425f5edd570b1645564eda24f1c986f9d4004cb17f70eaebd", + "6a03e0353d94a5da5af238c1ce8c3740815e7920d385d139e14b4cc35901e388" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [ + 1 + ] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq5xznr7q7va9qqya76gktf32k2a9q7urxyh6pr9wj3a96p8960cyqtdrdl0" + ], + "outputs": [ + { + "pub_key": "6e22e71d7cac7de425f5edd570b1645564eda24f1c986f9d4004cb17f70eaebd", + "priv_key_tweak": "58344a44e7af3e2d4075f8a69adce66aded979c2d3f45147360e7f6433ab4051", + "signature": "14a92dfbe543c53e7a9498e177589720296932e8b04abdd3c7de0a2827a73e99f082e2004e4ab49cfe2ebf83f067614d19bfdb0130fe78a9eb87f81477992ef2" + }, + { + "pub_key": "6a03e0353d94a5da5af238c1ce8c3740815e7920d385d139e14b4cc35901e388", + "priv_key_tweak": "0d6cfa12865975792f1a88fb5c374c4b07e56e90d49b18de5be21e5d3fca96aa", + "signature": "6e4a69742589439edfab678fe7017f94c46b2082ef2dc7c2da946a24c981187dce73ef0a91f16b6048c64c42f5537211b21ce3d4fdef58377eeabfb9ad64ef41" + } + ] + } + } + ] + }, + { + "comment": "Multiple outputs with labels: multiple outputs for labeled address; same recipient", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "463044022003f01861a76c8ec3afebc8bee792c52159a024843794315ab3c12f8537424b3f02204456f24c0f18fc9b2d54bf9a9aa4d3c55a367fbaab79cb511873135510ee4a4021025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "483046022100e2d348a6683ef5a6183c99f6e5e0490fbc07262807ef96800d23d78dde2c03b7022100d80eb7c5ee7258a8ee7200022580ceb02af905a5905180941222a4bd1d4c97152103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac", + "private_key": "0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 5.0 + ], + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq5xznr7q7va9qqya76gktf32k2a9q7urxyh6pr9wj3a96p8960cyqtdrdl0", + 6.0 + ], + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqklxyqgwkvudqekrqczcmk8z73lve2g7wh0n354f4c7wlthkvhn3gqvaw2r", + 7.0 + ], + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqklxyqgwkvudqekrqczcmk8z73lve2g7wh0n354f4c7wlthkvhn3gqvaw2r", + 8.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + 5.0 + ], + [ + "6a03e0353d94a5da5af238c1ce8c3740815e7920d385d139e14b4cc35901e388", + 6.0 + ], + [ + "df6db64278db9d80a2d1616c4bdfcc31290953d0bf1a5691e49cd61070b5bd53", + 7.0 + ], + [ + "4cc9275fa5f7a929841e06e6b2c4c696d811f818b28c9d1544a7b003cd745f5d", + 8.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "463044022003f01861a76c8ec3afebc8bee792c52159a024843794315ab3c12f8537424b3f02204456f24c0f18fc9b2d54bf9a9aa4d3c55a367fbaab79cb511873135510ee4a4021025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "483046022100e2d348a6683ef5a6183c99f6e5e0490fbc07262807ef96800d23d78dde2c03b7022100d80eb7c5ee7258a8ee7200022580ceb02af905a5905180941222a4bd1d4c97152103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "6a03e0353d94a5da5af238c1ce8c3740815e7920d385d139e14b4cc35901e388", + "df6db64278db9d80a2d1616c4bdfcc31290953d0bf1a5691e49cd61070b5bd53", + "4cc9275fa5f7a929841e06e6b2c4c696d811f818b28c9d1544a7b003cd745f5d" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [ + 1 + ] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq5xznr7q7va9qqya76gktf32k2a9q7urxyh6pr9wj3a96p8960cyqtdrdl0" + ], + "outputs": [ + { + "pub_key": "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "priv_key_tweak": "f990515fa92c9baa6504697d2ee1eec7e8320308490a53a6add12493ef96953c", + "signature": "01322e61146a5dccaa246408289c4a48e4d332c74ab47a475fcaa95019a622d1b52a4c9d14af1c85afdb6a0e730e5cfd06cc8c2181aa14f78166ea70d710d76c" + }, + { + "pub_key": "6a03e0353d94a5da5af238c1ce8c3740815e7920d385d139e14b4cc35901e388", + "priv_key_tweak": "0d6cfa12865975792f1a88fb5c374c4b07e56e90d49b18de5be21e5d3fca96aa", + "signature": "6e4a69742589439edfab678fe7017f94c46b2082ef2dc7c2da946a24c981187dce73ef0a91f16b6048c64c42f5537211b21ce3d4fdef58377eeabfb9ad64ef41" + } + ] + } + } + ] + }, + { + "comment": "Single recipient: use silent payments for sender change", + "sending": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100cf5be8628bbab39acd5a741bf83a355b41ab5b51875b9ab9ee47bbbbe1da831602205de22981c3de1609f719a7135aafd6239cb41880b7276cec941de119e62e8db821025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac", + "private_key": "eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "483046022100eb64dca73feddaa80b139fe5d907f67e85a22f2a440589eafd32f5a6adccf38a022100eb79de1419707c150cee153e4c0a9f16a3e88bae5270c43c869dd563ed8679a22103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac", + "private_key": "0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a" + } + ], + "recipients": [ + [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv", + 1.0 + ], + [ + "sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqcdcp0nnsy6tn2372ylxt080qey7ktvgs32myw0jpphfe8dfpa74u7zjlg0", + 2.0 + ] + ] + }, + "expected": { + "outputs": [ + [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + 1.0 + ], + [ + "f05874d2064c7af6e77ecb10389b29dad8418c95cd0fa7b35b667ab800527d77", + 2.0 + ] + ] + } + } + ], + "receiving": [ + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100cf5be8628bbab39acd5a741bf83a355b41ab5b51875b9ab9ee47bbbbe1da831602205de22981c3de1609f719a7135aafd6239cb41880b7276cec941de119e62e8db821025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "483046022100eb64dca73feddaa80b139fe5d907f67e85a22f2a440589eafd32f5a6adccf38a022100eb79de1419707c150cee153e4c0a9f16a3e88bae5270c43c869dd563ed8679a22103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "f05874d2064c7af6e77ecb10389b29dad8418c95cd0fa7b35b667ab800527d77" + ], + "key_material": { + "spend_priv_key": "b8f87388cbb41934c50daca018901b00070a5ff6cc25a7e9e716a9d5b9e4d664", + "scan_priv_key": "11b7a82e06ca2648d5fded2366478078ec4fc9dc1d8ff487518226f229d768fd" + }, + "labels": [ + 0 + ] + }, + "expected": { + "addresses": [ + "sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqauj52ymtc4xdkmx3tgyhrsemg2g3303xk2gtzfy8h8ejet8fz8jcw23zua", + "sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqcdcp0nnsy6tn2372ylxt080qey7ktvgs32myw0jpphfe8dfpa74u7zjlg0" + ], + "outputs": [ + { + "pub_key": "f05874d2064c7af6e77ecb10389b29dad8418c95cd0fa7b35b667ab800527d77", + "priv_key_tweak": "668cfe89e4b06c1932bf23f4ca408598ff3802e06131a36ea22ac0bac3f45f7a", + "signature": "06aa6e0eafbf9b0f8e4c041c857f1222ffed20977638c477cea27e3110697f15f82c3949eaecc2e971869dae8069873219ea2e479873608b1fadcc1e40da7530" + } + ] + } + }, + { + "given": { + "inputs": [ + { + "prevout": [ + "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", + 0, + "473045022100cf5be8628bbab39acd5a741bf83a355b41ab5b51875b9ab9ee47bbbbe1da831602205de22981c3de1609f719a7135aafd6239cb41880b7276cec941de119e62e8db821025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5", + "" + ], + "scriptPubKey": "76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac" + }, + { + "prevout": [ + "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d", + 0, + "483046022100eb64dca73feddaa80b139fe5d907f67e85a22f2a440589eafd32f5a6adccf38a022100eb79de1419707c150cee153e4c0a9f16a3e88bae5270c43c869dd563ed8679a22103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338", + "" + ], + "scriptPubKey": "76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac" + } + ], + "outputs": [ + "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "f05874d2064c7af6e77ecb10389b29dad8418c95cd0fa7b35b667ab800527d77" + ], + "key_material": { + "spend_priv_key": "9d6ad855ce3417ef84e836892e5a56392bfba05fa5d97ccea30e266f540e08b3", + "scan_priv_key": "0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c" + }, + "labels": [] + }, + "expected": { + "addresses": [ + "sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv" + ], + "outputs": [ + { + "pub_key": "3b604ca7e7422dfa536ded65bb11762a3f3213de5c91b6b7b3127c94f4bb49cf", + "priv_key_tweak": "f990515fa92c9baa6504697d2ee1eec7e8320308490a53a6add12493ef96953c", + "signature": "01322e61146a5dccaa246408289c4a48e4d332c74ab47a475fcaa95019a622d1b52a4c9d14af1c85afdb6a0e730e5cfd06cc8c2181aa14f78166ea70d710d76c" + } + ] + } + } + ] + } +] \ No newline at end of file