Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sending #9

Merged
merged 5 commits into from
May 1, 2024
Merged

Update sending #9

merged 5 commits into from
May 1, 2024

Conversation

josibake
Copy link
Contributor

Updates to align with BIP0352 spec, specifically:

  • Use the smallest outpoint instead of all of the outpoints
  • Add tagged hashes for shared secret and input hash
  • Commit to the public key A in the inputs hash

Also updates tests to handle new test cases, specifically:

  • Determine the UTXO type based on the input data
  • Use new test structure

I added a tests/utils.ts for parsing the UTXOType which is the minimal code I need for deserializing witness stacks and checking the scriptPubKey template. This file is only necessary for the BIP352 test vectors since in normal usage it is expected that the sending wallet can set this field directly.

josibake added 5 commits May 1, 2024 11:21
Get latest test vectors from BIP352. New test vectors follow a different
format and also include new tests cases.
Add UTXOType field for determining if a UTXO is eligible for shared
secret derivation.

Add tests/utils.ts for parsing BIP352 test vectors. These utils
are used to determine the UTXOType of the input.

The utilities are only added for the tests and not the general library since
in normal usage the sending wallet already knows the UTXOType and can
set it directly.
BIP352 specifies tagged hashes for:

* the outpointHash (BIP0352/Inputs)
* the shared secret (BIP0352/SharedSecret)

This also involves updating the output hash function to now:

* Use the smallest outpoint (as opposed to all outpoints)
* Commit to the public key A (the sum of the eligible input pubkeys)
adds functions for checking that the generated sending outputs matches
exactly one of the expected.outputs candidate sets.
tests/utils.ts Show resolved Hide resolved
tests/data/sending_test_vectors.json Show resolved Hide resolved
Comment on lines +5 to +8
// The following utilities are provided to determine the UTXOType of a transaction input.
// This is necessary for parsing the test vectors from BIP352, but in practice a sending
// wallet will already know the UTXOType for each UTXO it indends to spend and can set the
// UTXOType field directly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how complete (albeit inefficient) this code is? is it worth exporting it and makign it apart of the lib so poor souls who implement wallets but dont know their input types can throw it in and use it when using this js lib?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, not sure it makes sense for a sending wallet. A sending wallet will always know what kind of UTXOs it has based on what kind of addresses the wallet hands out, i.e. a wallet that only hands out native segwit and taproot addresses will only have native segwit and taproot UTXOs. It also needs to know the UTXO type to know how sign for it.

Also, for a sending wallet to use this function, they would need extra data that I'm pretty sure they won't have (like the prevout scriptPubKey).

tests/silent-payment.test.ts Show resolved Hide resolved
tests/silent-payment.test.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
@Overtorment Overtorment requested a review from limpbrains May 1, 2024 10:42
@Overtorment
Copy link
Member

@limpbrains would you like to join the fun?

@Overtorment Overtorment merged commit 8a76bde into BlueWallet:master May 1, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants