Skip to content

Commit f805716

Browse files
committed
Using substitute_raw_pkh for taproot descriptor
Signed-off-by: Harshil Jani <[email protected]>
1 parent 7f1ea18 commit f805716

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/psbt/finalizer.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use bitcoin::taproot::LeafVersion;
1616
use bitcoin::{PublicKey, Script, ScriptBuf, TxOut, Witness};
1717

1818
use super::{sanity_check, Error, InputError, Psbt, PsbtInputSatisfier};
19-
use crate::prelude::*;
2019
use crate::util::witness_size;
2120
use 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

Comments
 (0)