Skip to content

Commit

Permalink
Merge #753: Fix decoding of WIF with BIP32 origin
Browse files Browse the repository at this point in the history
9416098 Fix decoding of WIF with BIP32 origin (Nadav Ivgi)

Pull request description:

  A small fix for a small oversight.

  The test has to pattern match the inner `SinglePriv` because there's no other way to get derivation path (no `full_derivation_path(s)` method like `DescriptorPublicKey` has, which would be nice to have ^.^)

ACKs for top commit:
  apoelstra:
    ACK 9416098 successfully ran local tests; good catch!

Tree-SHA512: b80c89d553cafde4c579a0f395c100584150a9efe679daef093bd2de711f06ecc79f71d43ce6a9abc1b938da1449aa13d0225ce1b69205e33e473bb3404f387b
  • Loading branch information
apoelstra committed Oct 14, 2024
2 parents 307c1b3 + 9416098 commit 1e40a8d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ impl FromStr for DescriptorSecretKey {
if key_part.len() <= 52 {
let sk = bitcoin::PrivateKey::from_str(key_part)
.map_err(|_| DescriptorKeyParseError("Error while parsing a WIF private key"))?;
Ok(DescriptorSecretKey::Single(SinglePriv { key: sk, origin: None }))
Ok(DescriptorSecretKey::Single(SinglePriv { key: sk, origin }))
} else {
let (xpriv, derivation_paths, wildcard) = parse_xkey_deriv::<bip32::Xpriv>(key_part)?;
if derivation_paths.len() > 1 {
Expand Down Expand Up @@ -1489,6 +1489,27 @@ mod test {
DescriptorPublicKey::from_str("tpubDBrgjcxBxnXyL575sHdkpKohWu5qHKoQ7TJXKNrYznh5fVEGBv89hA8ENW7A8MFVpFUSvgLqc4Nj1WZcpePX6rrxviVtPowvMuGF5rdT2Vi/2/4/<0;1;>").unwrap_err();
}

#[test]
fn test_parse_wif() {
let secret_key = "[0dd03d09/0'/1/2']5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"
.parse()
.unwrap();
if let DescriptorSecretKey::Single(single) = secret_key {
assert_eq!(
single.key.inner,
"0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D"
.parse()
.unwrap()
);
assert_eq!(
single.origin,
Some(("0dd03d09".parse().unwrap(), "m/0'/1/2'".parse().unwrap()))
);
} else {
panic!("expected a DescriptorSecretKey::Single");
}
}

#[test]
#[cfg(feature = "serde")]
fn test_descriptor_public_key_serde() {
Expand Down

0 comments on commit 1e40a8d

Please sign in to comment.