@@ -21,7 +21,8 @@ use super::{sanity_check, Error, InputError, Psbt, PsbtInputSatisfier};
21
21
use crate :: prelude:: * ;
22
22
use crate :: util:: witness_size;
23
23
use crate :: {
24
- interpreter, BareCtx , Descriptor , ExtParams , Legacy , Miniscript , Satisfier , Segwitv0 , Tap ,
24
+ interpreter, BareCtx , Descriptor , ExtParams , Legacy , Miniscript , Satisfier , Segwitv0 , SigType ,
25
+ Tap , ToPublicKey ,
25
26
} ;
26
27
27
28
// Satisfy the taproot descriptor. It is not possible to infer the complete
@@ -33,6 +34,19 @@ fn construct_tap_witness(
33
34
sat : & PsbtInputSatisfier ,
34
35
allow_mall : bool ,
35
36
) -> 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
+ }
36
50
assert ! ( spk. is_v1_p2tr( ) ) ;
37
51
38
52
// try the key spend path first
@@ -55,7 +69,7 @@ fn construct_tap_witness(
55
69
script,
56
70
& ExtParams :: allow_all ( ) ,
57
71
) {
58
- Ok ( ms) => ms,
72
+ Ok ( ms) => ms. substitute_raw_pkh ( & hash_map ) ,
59
73
Err ( ..) => continue , // try another script
60
74
} ;
61
75
let mut wit = if allow_mall {
0 commit comments