Add ability to retrieve private keys as bytes
This feature is needed for compatibility with LDKLite, where the initial entropy given to LDK is the private key of the root of the BIP32 derivation tree. Closes #188
This commit is contained in:
parent
c971d54aea
commit
f92b45db6a
@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
- APIs Added
|
||||
- Add ability to retrieve any private key inside a descriptor as bytes [#199]
|
||||
|
||||
[#199]: https://github.com/bitcoindevkit/bdk-ffi/pull/199
|
||||
|
||||
## [v0.9.0]
|
||||
- Breaking Changes
|
||||
|
@ -283,6 +283,8 @@ interface DescriptorSecretKey {
|
||||
|
||||
DescriptorPublicKey as_public();
|
||||
|
||||
sequence<u8> secret_key_bytes();
|
||||
|
||||
string as_string();
|
||||
};
|
||||
|
||||
|
16
src/lib.rs
16
src/lib.rs
@ -907,6 +907,22 @@ impl DescriptorSecretKey {
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the private key as bytes.
|
||||
fn secret_key_bytes(&self) -> Vec<u8> {
|
||||
let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap();
|
||||
let secret_key_bytes: Vec<u8> = match descriptor_secret_key.deref() {
|
||||
BdkDescriptorSecretKey::XPrv(descriptor_x_key) => {
|
||||
descriptor_x_key.xkey.private_key.secret_bytes().to_vec()
|
||||
}
|
||||
BdkDescriptorSecretKey::SinglePriv(descriptor_x_key) => {
|
||||
// unreachable!()
|
||||
descriptor_x_key.key.inner.secret_bytes().to_vec()
|
||||
}
|
||||
};
|
||||
|
||||
secret_key_bytes
|
||||
}
|
||||
|
||||
fn as_string(&self) -> String {
|
||||
self.descriptor_secret_key_mutex.lock().unwrap().to_string()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user