diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 420dec32..5ca6458a 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -442,6 +442,12 @@ interface Descriptor { [Name=new_bip84_public] constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network); + [Name=new_bip86] + constructor(DescriptorSecretKey secret_key, KeychainKind keychain, Network network); + + [Name=new_bip86_public] + constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network); + string as_string(); string as_string_private(); diff --git a/bdk-ffi/src/descriptor.rs b/bdk-ffi/src/descriptor.rs index e33df686..dce8b520 100644 --- a/bdk-ffi/src/descriptor.rs +++ b/bdk-ffi/src/descriptor.rs @@ -7,7 +7,8 @@ use bdk::keys::{ DescriptorPublicKey as BdkDescriptorPublicKey, DescriptorSecretKey as BdkDescriptorSecretKey, }; use bdk::template::{ - Bip44, Bip44Public, Bip49, Bip49Public, Bip84, Bip84Public, DescriptorTemplate, + Bip44, Bip44Public, Bip49, Bip49Public, Bip84, Bip84Public, Bip86, Bip86Public, + DescriptorTemplate, }; use bdk::KeychainKind; use std::ops::Deref; @@ -183,6 +184,57 @@ impl Descriptor { } } + pub(crate) fn new_bip86( + secret_key: Arc, + keychain_kind: KeychainKind, + network: Network, + ) -> Self { + let derivable_key = secret_key.descriptor_secret_key_mutex.lock().unwrap(); + + match derivable_key.deref() { + BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { + let derivable_key = descriptor_x_key.xkey; + let (extended_descriptor, key_map, _) = + Bip86(derivable_key, keychain_kind).build(network).unwrap(); + Self { + extended_descriptor, + key_map, + } + } + BdkDescriptorSecretKey::Single(_) => { + unreachable!() + } + } + } + + pub(crate) fn new_bip86_public( + public_key: Arc, + fingerprint: String, + keychain_kind: KeychainKind, + network: Network, + ) -> Self { + let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); + let derivable_key = public_key.descriptor_public_key_mutex.lock().unwrap(); + + match derivable_key.deref() { + BdkDescriptorPublicKey::XPub(descriptor_x_key) => { + let derivable_key = descriptor_x_key.xkey; + let (extended_descriptor, key_map, _) = + Bip86Public(derivable_key, fingerprint, keychain_kind) + .build(network) + .unwrap(); + + Self { + extended_descriptor, + key_map, + } + } + BdkDescriptorPublicKey::Single(_) => { + unreachable!() + } + } + } + pub(crate) fn as_string_private(&self) -> String { let descriptor = &self.extended_descriptor; let key_map = &self.key_map;