@@ -94,8 +94,8 @@ use bitcoin::hashes::{hash160, Hash};
9494use bitcoin:: secp256k1;
9595use bitcoin:: secp256k1:: { Message , Secp256k1 } ;
9696use bitcoin:: util:: bip32:: { ChildNumber , DerivationPath , ExtendedPrivKey , Fingerprint } ;
97- use bitcoin:: util:: { bip143 , ecdsa, psbt} ;
98- use bitcoin:: { PrivateKey , PublicKey , Script , SigHashType , Sighash } ;
97+ use bitcoin:: util:: { ecdsa, psbt, sighash } ;
98+ use bitcoin:: { EcdsaSighashType , PrivateKey , PublicKey , Script , Sighash } ;
9999
100100use miniscript:: descriptor:: { DescriptorSecretKey , DescriptorSinglePriv , DescriptorXKey , KeyMap } ;
101101use miniscript:: { Legacy , MiniscriptKey , Segwitv0 } ;
@@ -156,6 +156,14 @@ pub enum SignerError {
156156 NonStandardSighash ,
157157 /// Invalid SIGHASH for the signing context in use
158158 InvalidSighash ,
159+ /// Error while computing the hash to sign
160+ SighashError ( sighash:: Error ) ,
161+ }
162+
163+ impl From < sighash:: Error > for SignerError {
164+ fn from ( e : sighash:: Error ) -> Self {
165+ SignerError :: SighashError ( e)
166+ }
159167}
160168
161169impl fmt:: Display for SignerError {
@@ -518,7 +526,9 @@ impl ComputeSighash for Legacy {
518526 let psbt_input = & psbt. inputs [ input_index] ;
519527 let tx_input = & psbt. unsigned_tx . input [ input_index] ;
520528
521- let sighash = psbt_input. sighash_type . unwrap_or ( SigHashType :: All . into ( ) ) ;
529+ let sighash = psbt_input
530+ . sighash_type
531+ . unwrap_or ( EcdsaSighashType :: All . into ( ) ) ;
522532 let script = match psbt_input. redeem_script {
523533 Some ( ref redeem_script) => redeem_script. clone ( ) ,
524534 None => {
@@ -536,8 +546,11 @@ impl ComputeSighash for Legacy {
536546 } ;
537547
538548 Ok ( (
539- psbt. unsigned_tx
540- . signature_hash ( input_index, & script, sighash. to_u32 ( ) ) ,
549+ sighash:: SighashCache :: new ( & psbt. unsigned_tx ) . legacy_signature_hash (
550+ input_index,
551+ & script,
552+ sighash. to_u32 ( ) ,
553+ ) ?,
541554 sighash,
542555 ) )
543556 }
@@ -567,7 +580,7 @@ impl ComputeSighash for Segwitv0 {
567580
568581 let sighash = psbt_input
569582 . sighash_type
570- . unwrap_or ( SigHashType :: All . into ( ) )
583+ . unwrap_or ( EcdsaSighashType :: All . into ( ) )
571584 . ecdsa_hash_ty ( )
572585 . map_err ( |_| SignerError :: InvalidSighash ) ?;
573586
@@ -612,12 +625,12 @@ impl ComputeSighash for Segwitv0 {
612625 } ;
613626
614627 Ok ( (
615- bip143 :: SigHashCache :: new ( & psbt. unsigned_tx ) . signature_hash (
628+ sighash :: SighashCache :: new ( & psbt. unsigned_tx ) . segwit_signature_hash (
616629 input_index,
617630 & script,
618631 value,
619632 sighash,
620- ) ,
633+ ) ? ,
621634 sighash. into ( ) ,
622635 ) )
623636 }
0 commit comments