Skip to content

Commit 7e99ee0

Browse files
committed
Fix bip32 usage in example
1 parent 7c900c9 commit 7e99ee0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

examples/v0.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
//! taken as NOT PROVEN CORRECT.
88
99
use std::collections::BTreeMap;
10+
use std::str::FromStr;
1011

12+
use psbt_v2::bitcoin::bip32::{DerivationPath, Fingerprint};
1113
use psbt_v2::bitcoin::hashes::Hash as _;
1214
use psbt_v2::bitcoin::locktime::absolute;
1315
use psbt_v2::bitcoin::opcodes::all::OP_CHECKMULTISIG;
@@ -86,6 +88,17 @@ fn main() -> anyhow::Result<()> {
8688
psbt.inputs[0].witness_utxo = Some(alice.input_utxo());
8789
psbt.inputs[1].witness_utxo = Some(bob.input_utxo());
8890

91+
// Add BIP32 derivation information for signing.
92+
// Without this, psbt.sign() will not sign the inputs because bip32_sign_ecdsa() iterates
93+
// over psbt.bip32_derivation to determine which keys should sign.
94+
let fake_fp: [u8; 4] = [0; 4];
95+
psbt.inputs[0]
96+
.bip32_derivation
97+
.insert(alice.0.pk, (Fingerprint::from(fake_fp), DerivationPath::from_str("m")?));
98+
psbt.inputs[1]
99+
.bip32_derivation
100+
.insert(bob.0.pk, (Fingerprint::from(fake_fp), DerivationPath::from_str("m")?));
101+
89102
// Since we are spending 2 p2wpkh inputs there are no other updates needed.
90103

91104
// Each party signs a copy of the PSBT.

0 commit comments

Comments
 (0)