@@ -16,11 +16,11 @@ use bitcoin::taproot::LeafVersion;
1616use bitcoin:: { PublicKey , Script , ScriptBuf , TxOut , Witness } ;
1717
1818use super :: { sanity_check, Error , InputError , Psbt , PsbtInputSatisfier } ;
19- use crate :: prelude:: * ;
2019use crate :: util:: witness_size;
2120use crate :: {
2221 interpreter, BareCtx , Descriptor , ExtParams , Legacy , Miniscript , Satisfier , Segwitv0 , Tap ,
2322} ;
23+ use crate :: { prelude:: * , SigType , ToPublicKey } ;
2424
2525// Satisfy the taproot descriptor. It is not possible to infer the complete
2626// descriptor from psbt because the information about all the scripts might not
@@ -31,6 +31,19 @@ fn construct_tap_witness(
3131 sat : & PsbtInputSatisfier ,
3232 allow_mall : bool ,
3333) -> Result < Vec < Vec < u8 > > , InputError > {
34+ let mut hash_map: BTreeMap < hash160:: Hash , bitcoin:: key:: XOnlyPublicKey > = BTreeMap :: new ( ) ;
35+ let psbt_inputs = & sat. psbt . inputs ;
36+ for psbt_input in psbt_inputs {
37+ // Use Tap Key Origins to get set of all possible keys.
38+ let public_keys = psbt_input. tap_key_origins . keys ( ) ;
39+ for key in public_keys {
40+ let bitcoin_key = * key;
41+ // Convert PubKeyHash into Hash::hash160
42+ let hash = bitcoin_key. to_pubkeyhash ( SigType :: Schnorr ) ;
43+ // Insert pair in HashMap
44+ hash_map. insert ( hash, bitcoin_key) ;
45+ }
46+ }
3447 assert ! ( spk. is_v1_p2tr( ) ) ;
3548
3649 // try the key spend path first
@@ -53,7 +66,7 @@ fn construct_tap_witness(
5366 script,
5467 & ExtParams :: allow_all ( ) ,
5568 ) {
56- Ok ( ms) => ms,
69+ Ok ( ms) => ms. substitute_raw_pkh ( & hash_map ) ,
5770 Err ( ..) => continue , // try another script
5871 } ;
5972 let mut wit = if allow_mall {
0 commit comments