@@ -243,35 +243,46 @@ impl From<bitcoin::key::FromSliceError> for InputError {
243243/// is more than number of inputs in pbst
244244pub struct PsbtInputSatisfier < ' psbt > {
245245 /// pbst
246- pub psbt : & ' psbt Psbt ,
246+ psbt : & ' psbt Psbt ,
247247 /// input index
248- pub index : usize ,
248+ index : usize ,
249249}
250250
251251impl < ' psbt > PsbtInputSatisfier < ' psbt > {
252252 /// create a new PsbtInputsatisfier from
253253 /// psbt and index
254254 pub fn new ( psbt : & ' psbt Psbt , index : usize ) -> Self { Self { psbt, index } }
255+
256+ /// Accessor for the PSBT this satisfier is associated with.
257+ pub fn psbt ( & self ) -> & ' psbt Psbt { self . psbt }
258+
259+ /// Accessor for the input this satisfier is associated with.
260+ pub fn psbt_input ( & self ) -> & psbt:: Input { & self . psbt . inputs [ self . index ] }
255261}
256262
257263impl < Pk : MiniscriptKey + ToPublicKey > Satisfier < Pk > for PsbtInputSatisfier < ' _ > {
258- fn lookup_tap_key_spend_sig ( & self ) -> Option < bitcoin:: taproot:: Signature > {
259- self . psbt . inputs [ self . index ] . tap_key_sig
264+ fn lookup_tap_key_spend_sig ( & self , pk : & Pk ) -> Option < bitcoin:: taproot:: Signature > {
265+ if let Some ( key) = self . psbt_input ( ) . tap_internal_key {
266+ if pk. to_x_only_pubkey ( ) == key {
267+ return self . psbt_input ( ) . tap_key_sig ;
268+ }
269+ }
270+ None
260271 }
261272
262273 fn lookup_tap_leaf_script_sig (
263274 & self ,
264275 pk : & Pk ,
265276 lh : & TapLeafHash ,
266277 ) -> Option < bitcoin:: taproot:: Signature > {
267- self . psbt . inputs [ self . index ]
278+ self . psbt_input ( )
268279 . tap_script_sigs
269280 . get ( & ( pk. to_x_only_pubkey ( ) , * lh) )
270281 . copied ( )
271282 }
272283
273284 fn lookup_raw_pkh_pk ( & self , pkh : & hash160:: Hash ) -> Option < bitcoin:: PublicKey > {
274- self . psbt . inputs [ self . index ]
285+ self . psbt_input ( )
275286 . bip32_derivation
276287 . iter ( )
277288 . find ( |& ( pubkey, _) | pubkey. to_pubkeyhash ( SigType :: Ecdsa ) == * pkh)
@@ -281,14 +292,14 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfier<'_> {
281292 fn lookup_tap_control_block_map (
282293 & self ,
283294 ) -> Option < & BTreeMap < ControlBlock , ( bitcoin:: ScriptBuf , LeafVersion ) > > {
284- Some ( & self . psbt . inputs [ self . index ] . tap_scripts )
295+ Some ( & self . psbt_input ( ) . tap_scripts )
285296 }
286297
287298 fn lookup_raw_pkh_tap_leaf_script_sig (
288299 & self ,
289300 pkh : & ( hash160:: Hash , TapLeafHash ) ,
290301 ) -> Option < ( bitcoin:: secp256k1:: XOnlyPublicKey , bitcoin:: taproot:: Signature ) > {
291- self . psbt . inputs [ self . index ]
302+ self . psbt_input ( )
292303 . tap_script_sigs
293304 . iter ( )
294305 . find ( |& ( ( pubkey, lh) , _sig) | {
@@ -298,7 +309,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfier<'_> {
298309 }
299310
300311 fn lookup_ecdsa_sig ( & self , pk : & Pk ) -> Option < bitcoin:: ecdsa:: Signature > {
301- self . psbt . inputs [ self . index ]
312+ self . psbt_input ( )
302313 . partial_sigs
303314 . get ( & pk. to_public_key ( ) )
304315 . copied ( )
@@ -308,7 +319,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfier<'_> {
308319 & self ,
309320 pkh : & hash160:: Hash ,
310321 ) -> Option < ( bitcoin:: PublicKey , bitcoin:: ecdsa:: Signature ) > {
311- self . psbt . inputs [ self . index ]
322+ self . psbt_input ( )
312323 . partial_sigs
313324 . iter ( )
314325 . find ( |& ( pubkey, _sig) | pubkey. to_pubkeyhash ( SigType :: Ecdsa ) == * pkh)
@@ -337,28 +348,28 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfier<'_> {
337348 }
338349
339350 fn lookup_hash160 ( & self , h : & Pk :: Hash160 ) -> Option < Preimage32 > {
340- self . psbt . inputs [ self . index ]
351+ self . psbt_input ( )
341352 . hash160_preimages
342353 . get ( & Pk :: to_hash160 ( h) )
343354 . and_then ( |x : & Vec < u8 > | <[ u8 ; 32 ] >:: try_from ( & x[ ..] ) . ok ( ) )
344355 }
345356
346357 fn lookup_sha256 ( & self , h : & Pk :: Sha256 ) -> Option < Preimage32 > {
347- self . psbt . inputs [ self . index ]
358+ self . psbt_input ( )
348359 . sha256_preimages
349360 . get ( & Pk :: to_sha256 ( h) )
350361 . and_then ( |x : & Vec < u8 > | <[ u8 ; 32 ] >:: try_from ( & x[ ..] ) . ok ( ) )
351362 }
352363
353364 fn lookup_hash256 ( & self , h : & Pk :: Hash256 ) -> Option < Preimage32 > {
354- self . psbt . inputs [ self . index ]
365+ self . psbt_input ( )
355366 . hash256_preimages
356367 . get ( & sha256d:: Hash :: from_byte_array ( Pk :: to_hash256 ( h) . to_byte_array ( ) ) ) // upstream psbt operates on hash256
357368 . and_then ( |x : & Vec < u8 > | <[ u8 ; 32 ] >:: try_from ( & x[ ..] ) . ok ( ) )
358369 }
359370
360371 fn lookup_ripemd160 ( & self , h : & Pk :: Ripemd160 ) -> Option < Preimage32 > {
361- self . psbt . inputs [ self . index ]
372+ self . psbt_input ( )
362373 . ripemd160_preimages
363374 . get ( & Pk :: to_ripemd160 ( h) )
364375 . and_then ( |x : & Vec < u8 > | <[ u8 ; 32 ] >:: try_from ( & x[ ..] ) . ok ( ) )
0 commit comments