@@ -94,8 +94,8 @@ use bitcoin::hashes::{hash160, Hash};
94
94
use bitcoin:: secp256k1;
95
95
use bitcoin:: secp256k1:: { Message , Secp256k1 } ;
96
96
use 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 } ;
99
99
100
100
use miniscript:: descriptor:: { DescriptorSecretKey , DescriptorSinglePriv , DescriptorXKey , KeyMap } ;
101
101
use miniscript:: { Legacy , MiniscriptKey , Segwitv0 } ;
@@ -156,6 +156,14 @@ pub enum SignerError {
156
156
NonStandardSighash ,
157
157
/// Invalid SIGHASH for the signing context in use
158
158
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
+ }
159
167
}
160
168
161
169
impl fmt:: Display for SignerError {
@@ -517,7 +525,9 @@ impl ComputeSighash for Legacy {
517
525
let psbt_input = & psbt. inputs [ input_index] ;
518
526
let tx_input = & psbt. unsigned_tx . input [ input_index] ;
519
527
520
- let sighash = psbt_input. sighash_type . unwrap_or ( SigHashType :: All . into ( ) ) ;
528
+ let sighash = psbt_input
529
+ . sighash_type
530
+ . unwrap_or ( EcdsaSighashType :: All . into ( ) ) ;
521
531
let script = match psbt_input. redeem_script {
522
532
Some ( ref redeem_script) => redeem_script. clone ( ) ,
523
533
None => {
@@ -535,8 +545,11 @@ impl ComputeSighash for Legacy {
535
545
} ;
536
546
537
547
Ok ( (
538
- psbt. unsigned_tx
539
- . signature_hash ( input_index, & script, sighash. to_u32 ( ) ) ,
548
+ sighash:: SighashCache :: new ( & psbt. unsigned_tx ) . legacy_signature_hash (
549
+ input_index,
550
+ & script,
551
+ sighash. to_u32 ( ) ,
552
+ ) ?,
540
553
sighash,
541
554
) )
542
555
}
@@ -566,7 +579,7 @@ impl ComputeSighash for Segwitv0 {
566
579
567
580
let sighash = psbt_input
568
581
. sighash_type
569
- . unwrap_or ( SigHashType :: All . into ( ) )
582
+ . unwrap_or ( EcdsaSighashType :: All . into ( ) )
570
583
. ecdsa_hash_ty ( )
571
584
. map_err ( |_| SignerError :: InvalidSighash ) ?;
572
585
@@ -611,12 +624,12 @@ impl ComputeSighash for Segwitv0 {
611
624
} ;
612
625
613
626
Ok ( (
614
- bip143 :: SigHashCache :: new ( & psbt. unsigned_tx ) . signature_hash (
627
+ sighash :: SighashCache :: new ( & psbt. unsigned_tx ) . segwit_signature_hash (
615
628
input_index,
616
629
& script,
617
630
value,
618
631
sighash,
619
- ) ,
632
+ ) ? ,
620
633
sighash. into ( ) ,
621
634
) )
622
635
}
0 commit comments