@@ -16,11 +16,11 @@ use bitcoin::taproot::LeafVersion;
16
16
use bitcoin:: { PublicKey , Script , ScriptBuf , TxOut , Witness } ;
17
17
18
18
use super :: { sanity_check, Error , InputError , Psbt , PsbtInputSatisfier } ;
19
- use crate :: prelude:: * ;
20
19
use crate :: util:: witness_size;
21
20
use crate :: {
22
21
interpreter, BareCtx , Descriptor , ExtParams , Legacy , Miniscript , Satisfier , Segwitv0 , Tap ,
23
22
} ;
23
+ use crate :: { prelude:: * , SigType , ToPublicKey } ;
24
24
25
25
// Satisfy the taproot descriptor. It is not possible to infer the complete
26
26
// descriptor from psbt because the information about all the scripts might not
@@ -31,6 +31,19 @@ fn construct_tap_witness(
31
31
sat : & PsbtInputSatisfier ,
32
32
allow_mall : bool ,
33
33
) -> 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
+ }
34
47
assert ! ( spk. is_v1_p2tr( ) ) ;
35
48
36
49
// try the key spend path first
@@ -53,7 +66,7 @@ fn construct_tap_witness(
53
66
script,
54
67
& ExtParams :: allow_all ( ) ,
55
68
) {
56
- Ok ( ms) => ms,
69
+ Ok ( ms) => ms. substitute_raw_pkh ( & hash_map ) ,
57
70
Err ( ..) => continue , // try another script
58
71
} ;
59
72
let mut wit = if allow_mall {
0 commit comments