signer: add a method to get the xpub at a given path

This commit is contained in:
Antoine Poinsot 2023-01-20 12:34:23 +01:00
parent 59e55ae9f2
commit b88874107e
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304

View File

@ -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]