signer: add a method to get the xpub at a given path
This commit is contained in:
parent
59e55ae9f2
commit
b88874107e
@ -191,6 +191,19 @@ impl HotSigner {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the extended public key at the given derivation path.
|
||||
pub fn xpub_at(
|
||||
&self,
|
||||
der_path: &bip32::DerivationPath,
|
||||
secp: &secp256k1::Secp256k1<impl secp256k1::Signing>,
|
||||
) -> bip32::ExtendedPubKey {
|
||||
let xpriv = self
|
||||
.master_xpriv
|
||||
.derive_priv(secp, der_path)
|
||||
.expect("Never fails");
|
||||
bip32::ExtendedPubKey::from_priv(secp, &xpriv)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -220,6 +233,13 @@ mod tests {
|
||||
.words(),
|
||||
signer.words()
|
||||
);
|
||||
|
||||
// We can get an xpub for it.
|
||||
let secp = secp256k1::Secp256k1::signing_only();
|
||||
let _ = signer.xpub_at(
|
||||
&bip32::DerivationPath::from_str("m/42'/43/0987'/0/2").unwrap(),
|
||||
&secp,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user