Skip to content

Commit

Permalink
Fix decoding of WIF with BIP32 origin
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Oct 14, 2024
1 parent 307c1b3 commit 6e4d0ed
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 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,17 @@ mod test {
DescriptorPublicKey::from_str("tpubDBrgjcxBxnXyL575sHdkpKohWu5qHKoQ7TJXKNrYznh5fVEGBv89hA8ENW7A8MFVpFUSvgLqc4Nj1WZcpePX6rrxviVtPowvMuGF5rdT2Vi/2/4/<0;1;>").unwrap_err();
}

#[test]
fn test_parse_wif() {
let secret_key = DescriptorSecretKey::from_str("[0dd03d09/0'/1/2']5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ").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 6e4d0ed

Please # to comment.