@@ -21,7 +21,8 @@ use super::{sanity_check, Error, InputError, Psbt, PsbtInputSatisfier};
2121use crate :: prelude:: * ;
2222use crate :: util:: witness_size;
2323use crate :: {
24- interpreter, BareCtx , Descriptor , ExtParams , Legacy , Miniscript , Satisfier , Segwitv0 , Tap ,
24+ interpreter, BareCtx , Descriptor , ExtParams , Legacy , Miniscript , Satisfier , Segwitv0 , SigType ,
25+ Tap , ToPublicKey ,
2526} ;
2627
2728// Satisfy the taproot descriptor. It is not possible to infer the complete
@@ -33,6 +34,19 @@ fn construct_tap_witness(
3334 sat : & PsbtInputSatisfier ,
3435 allow_mall : bool ,
3536) -> Result < Vec < Vec < u8 > > , InputError > {
37+ let mut hash_map: BTreeMap < hash160:: Hash , bitcoin:: key:: XOnlyPublicKey > = BTreeMap :: new ( ) ;
38+ let psbt_inputs = & sat. psbt . inputs ;
39+ for psbt_input in psbt_inputs {
40+ // Use Tap Key Origins to get set of all possible keys.
41+ let public_keys = psbt_input. tap_key_origins . keys ( ) ;
42+ for key in public_keys {
43+ let bitcoin_key = * key;
44+ // Convert PubKeyHash into Hash::hash160
45+ let hash = bitcoin_key. to_pubkeyhash ( SigType :: Schnorr ) ;
46+ // Insert pair in HashMap
47+ hash_map. insert ( hash, bitcoin_key) ;
48+ }
49+ }
3650 assert ! ( spk. is_v1_p2tr( ) ) ;
3751
3852 // try the key spend path first
@@ -55,7 +69,7 @@ fn construct_tap_witness(
5569 script,
5670 & ExtParams :: allow_all ( ) ,
5771 ) {
58- Ok ( ms) => ms,
72+ Ok ( ms) => ms. substitute_raw_pkh ( & hash_map ) ,
5973 Err ( ..) => continue , // try another script
6074 } ;
6175 let mut wit = if allow_mall {
0 commit comments