Skip to content

Commit

Permalink
derive: test xpriv derivations
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Aug 21, 2024
1 parent 1a07bd7 commit 8faa3bc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions derive/src/xkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,4 +1124,26 @@ mod test {
let recovered = XprivAccount::from_str(&xpriv_account_str).unwrap();
assert_eq!(recovered, xpriv_account);
}

#[test]
fn xpriv_derivable() {
use secp256k1::rand::{self, RngCore};

let mut seed = vec![0u8; 128];
rand::thread_rng().fill_bytes(&mut seed);

let derivation = DerivationPath::from(h![86, 1, 0]);
let xpriv_account = XprivAccount::with_seed(true, &seed).derive(&derivation);
let xpub_account = xpriv_account.to_xpub_account();
let derivable_other =
XpubDerivable::try_custom(xpub_account.xpub, xpub_account.origin.clone(), [
Keychain::INNER,
Keychain::OUTER,
])
.unwrap();
let derivable = XpubDerivable::with(xpub_account, &[Keychain::INNER, Keychain::OUTER]);
assert_eq!(derivable, derivable_other);
assert_eq!(derivable.spec.origin, xpriv_account.origin);
assert_eq!(derivable.spec.origin.derivation, derivation);
}
}

0 comments on commit 8faa3bc

Please sign in to comment.