1919//! `https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki`
2020//!
2121
22+ use std:: collections:: BTreeMap ;
2223use std:: { error, fmt} ;
2324
2425use bitcoin;
@@ -27,6 +28,7 @@ use bitcoin::secp256k1::{self, Secp256k1};
2728use bitcoin:: util:: psbt:: PartiallySignedTransaction as Psbt ;
2829use bitcoin:: Script ;
2930
31+ use bitcoin:: util:: taproot:: { ControlBlock , LeafVersion , TapLeafHash } ;
3032use interpreter;
3133use miniscript:: limits:: SEQUENCE_LOCKTIME_DISABLE_FLAG ;
3234use miniscript:: satisfy:: { After , Older } ;
@@ -231,6 +233,57 @@ impl<'psbt> PsbtInputSatisfier<'psbt> {
231233}
232234
233235impl < ' psbt , Pk : MiniscriptKey + ToPublicKey > Satisfier < Pk > for PsbtInputSatisfier < ' psbt > {
236+ fn lookup_tap_key_spend_sig ( & self ) -> Option < bitcoin:: SchnorrSig > {
237+ if let Some ( ( sig, hash_ty) ) = self . psbt . inputs [ self . index ] . tap_key_sig {
238+ Some ( bitcoin:: SchnorrSig { sig, hash_ty } )
239+ } else {
240+ None
241+ }
242+ }
243+
244+ fn lookup_tap_leaf_script_sig ( & self , pk : & Pk , lh : & TapLeafHash ) -> Option < bitcoin:: SchnorrSig > {
245+ let pk = pk. to_x_only_pubkey ( ) ;
246+
247+ if let Some ( ( sig, hash_ty) ) = self . psbt . inputs [ self . index ] . tap_script_sigs . get ( & ( pk, * lh) ) {
248+ Some ( bitcoin:: SchnorrSig {
249+ sig : * sig,
250+ hash_ty : * hash_ty,
251+ } )
252+ } else {
253+ None
254+ }
255+ }
256+
257+ fn lookup_tap_control_block_map (
258+ & self ,
259+ ) -> Option < & BTreeMap < ControlBlock , ( bitcoin:: Script , LeafVersion ) > > {
260+ Some ( & self . psbt . inputs [ self . index ] . tap_scripts )
261+ }
262+
263+ fn lookup_pkh_tap_leaf_script_sig (
264+ & self ,
265+ pkh : & ( Pk :: Hash , TapLeafHash ) ,
266+ ) -> Option < ( bitcoin:: schnorr:: PublicKey , bitcoin:: SchnorrSig ) > {
267+ if let Some ( ( ( pk, _lh) , sig) ) = self . psbt . inputs [ self . index ]
268+ . tap_script_sigs
269+ . iter ( )
270+ . filter ( |& ( ( pubkey, lh) , _sig) | {
271+ pubkey. to_pubkeyhash ( ) == Pk :: hash_to_hash160 ( & pkh. 0 ) && * lh == pkh. 1
272+ } )
273+ . next ( )
274+ {
275+ Some ( (
276+ * pk,
277+ bitcoin:: SchnorrSig {
278+ sig : sig. 0 ,
279+ hash_ty : sig. 1 ,
280+ } ,
281+ ) )
282+ } else {
283+ None
284+ }
285+ }
286+
234287 fn lookup_ec_sig ( & self , pk : & Pk ) -> Option < bitcoin:: EcdsaSig > {
235288 if let Some ( rawsig) = self . psbt . inputs [ self . index ]
236289 . partial_sigs
0 commit comments