Merge rust-bitcoin/rust-bitcoin#2710: Document the *_encode_signing_data_to functions

dc8b900dec Document the *_encode_signing_data_to functions (Tobin C. Harding)

Pull request description:

  If one writes signing data using one of the two
  `*_encode_signing_data_to` functions then creating the message to sign is slightly nuanced and different for each of the functions. For Taproot one must use a specific tagged hash and for ECDSA one must use a sha256d hash.

  Add documentation that explains the hashing requirements for each function.

  Close: #2703

ACKs for top commit:
  apoelstra:
    ACK dc8b900dec we maybe should say specifically which tagged hash, but I think this is fine

Tree-SHA512: bfbabb822858e5bab56c3ed63a3a6541f44343925f304d027c2d1566485356950857c76ce03d4936aacfa8e11a65edaeb0b3d12114859c0c9e14c0e38b6c4b41
This commit is contained in:
Andrew Poelstra 2024-04-23 12:44:49 +00:00
commit fe1e849740
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 8 additions and 0 deletions

View File

@ -575,6 +575,10 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
/// Encodes the BIP341 signing data for any flag type into a given object implementing the
/// [`io::Write`] trait.
///
/// In order to sign, the data written by this function must be hashed using a tagged hash. This
/// can be achieved by using the [`TapSighash::engine()`] function, writing to the engine, then
/// finalizing the hash with [`TapSighash::from_engine()`].
pub fn taproot_encode_signing_data_to<W: Write + ?Sized, T: Borrow<TxOut>>(
&mut self,
writer: &mut W,
@ -766,6 +770,10 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
/// `script_code` is dependent on the type of the spend transaction. For p2wpkh use
/// [`Script::p2wpkh_script_code`], for p2wsh just pass in the witness script. (Also see
/// [`Self::p2wpkh_signature_hash`] and [`SighashCache::p2wsh_signature_hash`].)
///
/// In order to sign, the data written by this function must be hashed using a double SHA256
/// hash. This can be achieved either by using the [`hashes::sha256d::Hash`] type or one of the
/// custom sighash types in this module ([`SegwitV0Sighash`] and [`LegacySighash`]).
pub fn segwit_v0_encode_signing_data_to<W: Write + ?Sized>(
&mut self,
writer: &mut W,