cygnet3 / rust-silentpayments

A rust implementation of BIP352: Silent Payments.
MIT License
27 stars 14 forks source link

Add function to get expected ScriptPubKey for a given transaction #23

Closed cygnet3 closed 1 year ago

cygnet3 commented 1 year ago

For BIP158, we would need to scan for the presence of a certain ScriptPubKey in a block. In order to do so, we would need a function that takes tweak_data as an argument and computes this ScriptPubKey.

This is slightly different from the scan_transaction function: in this function, we provide the outputs as pub_keys_to_check as an argument and see if any of our calculated outputs matches any of our created ScriptPubKeys.

For this function, we would not need to implement label support, as BIP158 will primarily be used by mobile clients. However, we would need to handle change addresses (which is essentially a label).

cygnet3 commented 1 year ago

Decided that ScriptPubKey is too high level for this library. This requires rust-bitcoin library, which I don't want as a dependency. Instead, #25 adds an endpoint from which you can get a X-only taproot output, from that you can calculate the ScriptPubKey in the following way:

    let taproot_output = bob.get_taproot_output_from_tweak_data(&recipient_tweak_data).unwrap();
    let scriptpubkey = Payload::p2tr(&secp, taproot_output, None).script_pubkey();