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:
thunderbiscuit committed 2022-10-03 14:53:25 -04:00
1 parent c971d54aea
commit f92b45db6a
3 files changed
+22

No files matched your search

+2
View File
@@ -283,6 +283,8 @@ interface DescriptorSecretKey {
DescriptorPublicKey as_public();
sequence<u8> secret_key_bytes();
string as_string();
};
+16
View File
@@ -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()
}