@@ -243,35 +243,46 @@ impl From<bitcoin::key::FromSliceError> for InputError {
243
243
/// is more than number of inputs in pbst
244
244
pub struct PsbtInputSatisfier < ' psbt > {
245
245
/// pbst
246
- pub psbt : & ' psbt Psbt ,
246
+ psbt : & ' psbt Psbt ,
247
247
/// input index
248
- pub index : usize ,
248
+ index : usize ,
249
249
}
250
250
251
251
impl < ' psbt > PsbtInputSatisfier < ' psbt > {
252
252
/// create a new PsbtInputsatisfier from
253
253
/// psbt and index
254
254
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 ] }
255
261
}
256
262
257
263
impl < 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
260
271
}
261
272
262
273
fn lookup_tap_leaf_script_sig (
263
274
& self ,
264
275
pk : & Pk ,
265
276
lh : & TapLeafHash ,
266
277
) -> Option < bitcoin:: taproot:: Signature > {
267
- self . psbt . inputs [ self . index ]
278
+ self . psbt_input ( )
268
279
. tap_script_sigs
269
280
. get ( & ( pk. to_x_only_pubkey ( ) , * lh) )
270
281
. copied ( )
271
282
}
272
283
273
284
fn lookup_raw_pkh_pk ( & self , pkh : & hash160:: Hash ) -> Option < bitcoin:: PublicKey > {
274
- self . psbt . inputs [ self . index ]
285
+ self . psbt_input ( )
275
286
. bip32_derivation
276
287
. iter ( )
277
288
. find ( |& ( pubkey, _) | pubkey. to_pubkeyhash ( SigType :: Ecdsa ) == * pkh)
@@ -281,14 +292,14 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfier<'_> {
281
292
fn lookup_tap_control_block_map (
282
293
& self ,
283
294
) -> Option < & BTreeMap < ControlBlock , ( bitcoin:: ScriptBuf , LeafVersion ) > > {
284
- Some ( & self . psbt . inputs [ self . index ] . tap_scripts )
295
+ Some ( & self . psbt_input ( ) . tap_scripts )
285
296
}
286
297
287
298
fn lookup_raw_pkh_tap_leaf_script_sig (
288
299
& self ,
289
300
pkh : & ( hash160:: Hash , TapLeafHash ) ,
290
301
) -> Option < ( bitcoin:: secp256k1:: XOnlyPublicKey , bitcoin:: taproot:: Signature ) > {
291
- self . psbt . inputs [ self . index ]
302
+ self . psbt_input ( )
292
303
. tap_script_sigs
293
304
. iter ( )
294
305
. find ( |& ( ( pubkey, lh) , _sig) | {
@@ -298,7 +309,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfier<'_> {
298
309
}
299
310
300
311
fn lookup_ecdsa_sig ( & self , pk : & Pk ) -> Option < bitcoin:: ecdsa:: Signature > {
301
- self . psbt . inputs [ self . index ]
312
+ self . psbt_input ( )
302
313
. partial_sigs
303
314
. get ( & pk. to_public_key ( ) )
304
315
. copied ( )
@@ -308,7 +319,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfier<'_> {
308
319
& self ,
309
320
pkh : & hash160:: Hash ,
310
321
) -> Option < ( bitcoin:: PublicKey , bitcoin:: ecdsa:: Signature ) > {
311
- self . psbt . inputs [ self . index ]
322
+ self . psbt_input ( )
312
323
. partial_sigs
313
324
. iter ( )
314
325
. find ( |& ( pubkey, _sig) | pubkey. to_pubkeyhash ( SigType :: Ecdsa ) == * pkh)
@@ -337,28 +348,28 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfier<'_> {
337
348
}
338
349
339
350
fn lookup_hash160 ( & self , h : & Pk :: Hash160 ) -> Option < Preimage32 > {
340
- self . psbt . inputs [ self . index ]
351
+ self . psbt_input ( )
341
352
. hash160_preimages
342
353
. get ( & Pk :: to_hash160 ( h) )
343
354
. and_then ( |x : & Vec < u8 > | <[ u8 ; 32 ] >:: try_from ( & x[ ..] ) . ok ( ) )
344
355
}
345
356
346
357
fn lookup_sha256 ( & self , h : & Pk :: Sha256 ) -> Option < Preimage32 > {
347
- self . psbt . inputs [ self . index ]
358
+ self . psbt_input ( )
348
359
. sha256_preimages
349
360
. get ( & Pk :: to_sha256 ( h) )
350
361
. and_then ( |x : & Vec < u8 > | <[ u8 ; 32 ] >:: try_from ( & x[ ..] ) . ok ( ) )
351
362
}
352
363
353
364
fn lookup_hash256 ( & self , h : & Pk :: Hash256 ) -> Option < Preimage32 > {
354
- self . psbt . inputs [ self . index ]
365
+ self . psbt_input ( )
355
366
. hash256_preimages
356
367
. get ( & sha256d:: Hash :: from_byte_array ( Pk :: to_hash256 ( h) . to_byte_array ( ) ) ) // upstream psbt operates on hash256
357
368
. and_then ( |x : & Vec < u8 > | <[ u8 ; 32 ] >:: try_from ( & x[ ..] ) . ok ( ) )
358
369
}
359
370
360
371
fn lookup_ripemd160 ( & self , h : & Pk :: Ripemd160 ) -> Option < Preimage32 > {
361
- self . psbt . inputs [ self . index ]
372
+ self . psbt_input ( )
362
373
. ripemd160_preimages
363
374
. get ( & Pk :: to_ripemd160 ( h) )
364
375
. and_then ( |x : & Vec < u8 > | <[ u8 ; 32 ] >:: try_from ( & x[ ..] ) . ok ( ) )
0 commit comments