Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions bdk-ffi/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Descriptor {
}

impl Descriptor {
pub(crate) fn new(descriptor: String, network: Network) -> Result<Self, DescriptorError> {
pub fn new(descriptor: String, network: Network) -> Result<Self, DescriptorError> {
let secp = Secp256k1::new();
let (extended_descriptor, key_map) = descriptor.into_wallet_descriptor(&secp, network)?;
Ok(Self {
Expand All @@ -35,7 +35,7 @@ impl Descriptor {
})
}

pub(crate) fn new_bip44(
pub fn new_bip44(
secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind,
network: Network,
Expand All @@ -61,7 +61,7 @@ impl Descriptor {
}
}

pub(crate) fn new_bip44_public(
pub fn new_bip44_public(
public_key: &DescriptorPublicKey,
fingerprint: String,
keychain_kind: KeychainKind,
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Descriptor {
}
}

pub(crate) fn new_bip49(
pub fn new_bip49(
secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind,
network: Network,
Expand All @@ -118,7 +118,7 @@ impl Descriptor {
}
}

pub(crate) fn new_bip49_public(
pub fn new_bip49_public(
public_key: &DescriptorPublicKey,
fingerprint: String,
keychain_kind: KeychainKind,
Expand Down Expand Up @@ -149,7 +149,7 @@ impl Descriptor {
}
}

pub(crate) fn new_bip84(
pub fn new_bip84(
secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind,
network: Network,
Expand All @@ -175,7 +175,7 @@ impl Descriptor {
}
}

pub(crate) fn new_bip84_public(
pub fn new_bip84_public(
public_key: &DescriptorPublicKey,
fingerprint: String,
keychain_kind: KeychainKind,
Expand Down Expand Up @@ -206,7 +206,7 @@ impl Descriptor {
}
}

pub(crate) fn new_bip86(
pub fn new_bip86(
secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind,
network: Network,
Expand All @@ -232,7 +232,7 @@ impl Descriptor {
}
}

pub(crate) fn new_bip86_public(
pub fn new_bip86_public(
public_key: &DescriptorPublicKey,
fingerprint: String,
keychain_kind: KeychainKind,
Expand Down Expand Up @@ -263,17 +263,17 @@ impl Descriptor {
}
}

pub(crate) fn to_string_with_secret(&self) -> String {
pub fn to_string_with_secret(&self) -> String {
let descriptor = &self.extended_descriptor;
let key_map = &self.key_map;
descriptor.to_string_with_secret(key_map)
}

pub(crate) fn is_multipath(&self) -> bool {
pub fn is_multipath(&self) -> bool {
self.extended_descriptor.is_multipath()
}

pub(crate) fn to_single_descriptors(&self) -> Result<Vec<Arc<Descriptor>>, MiniscriptError> {
pub fn to_single_descriptors(&self) -> Result<Vec<Arc<Descriptor>>, MiniscriptError> {
self.extended_descriptor
.clone()
.into_single_descriptors()
Expand Down
38 changes: 19 additions & 19 deletions bdk-ffi/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use std::ops::Deref;
use std::str::FromStr;
use std::sync::{Arc, Mutex};

pub(crate) struct Mnemonic(BdkMnemonic);
pub struct Mnemonic(BdkMnemonic);

impl Mnemonic {
pub(crate) fn new(word_count: WordCount) -> Self {
pub fn new(word_count: WordCount) -> Self {
// TODO 4: I DON'T KNOW IF THIS IS A DECENT WAY TO GENERATE ENTROPY PLEASE CONFIRM
let mut rng = rand::thread_rng();
let mut entropy = [0u8; 32];
Expand All @@ -34,13 +34,13 @@ impl Mnemonic {
Mnemonic(mnemonic)
}

pub(crate) fn from_string(mnemonic: String) -> Result<Self, Bip39Error> {
pub fn from_string(mnemonic: String) -> Result<Self, Bip39Error> {
BdkMnemonic::from_str(&mnemonic)
.map(Mnemonic)
.map_err(Bip39Error::from)
}

pub(crate) fn from_entropy(entropy: Vec<u8>) -> Result<Self, Bip39Error> {
pub fn from_entropy(entropy: Vec<u8>) -> Result<Self, Bip39Error> {
BdkMnemonic::from_entropy(entropy.as_slice())
.map(Mnemonic)
.map_err(Bip39Error::from)
Expand All @@ -53,12 +53,12 @@ impl Display for Mnemonic {
}
}

pub(crate) struct DerivationPath {
pub struct DerivationPath {
inner_mutex: Mutex<BdkDerivationPath>,
}

impl DerivationPath {
pub(crate) fn new(path: String) -> Result<Self, Bip32Error> {
pub fn new(path: String) -> Result<Self, Bip32Error> {
BdkDerivationPath::from_str(&path)
.map(|x| DerivationPath {
inner_mutex: Mutex::new(x),
Expand All @@ -71,7 +71,7 @@ impl DerivationPath {
pub struct DescriptorSecretKey(pub(crate) BdkDescriptorSecretKey);

impl DescriptorSecretKey {
pub(crate) fn new(network: Network, mnemonic: &Mnemonic, password: Option<String>) -> Self {
pub fn new(network: Network, mnemonic: &Mnemonic, password: Option<String>) -> Self {
let mnemonic = mnemonic.0.clone();
let xkey: ExtendedKey = (mnemonic, password).into_extended_key().unwrap();
let descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey {
Expand All @@ -83,13 +83,13 @@ impl DescriptorSecretKey {
Self(descriptor_secret_key)
}

pub(crate) fn from_string(private_key: String) -> Result<Self, DescriptorKeyError> {
pub fn from_string(private_key: String) -> Result<Self, DescriptorKeyError> {
let descriptor_secret_key = BdkDescriptorSecretKey::from_str(private_key.as_str())
.map_err(DescriptorKeyError::from)?;
Ok(Self(descriptor_secret_key))
}

pub(crate) fn derive(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
pub fn derive(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
let secp = Secp256k1::new();
let descriptor_secret_key = &self.0;
let path = path.inner_mutex.lock().unwrap().deref().clone();
Expand All @@ -116,7 +116,7 @@ impl DescriptorSecretKey {
}
}

pub(crate) fn extend(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
pub fn extend(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
let descriptor_secret_key = &self.0;
let path = path.inner_mutex.lock().unwrap().deref().clone();
match descriptor_secret_key {
Expand All @@ -135,13 +135,13 @@ impl DescriptorSecretKey {
}
}

pub(crate) fn as_public(&self) -> Arc<DescriptorPublicKey> {
pub fn as_public(&self) -> Arc<DescriptorPublicKey> {
let secp = Secp256k1::new();
let descriptor_public_key = self.0.to_public(&secp).unwrap();
Arc::new(DescriptorPublicKey(descriptor_public_key))
}

pub(crate) fn secret_bytes(&self) -> Vec<u8> {
pub fn secret_bytes(&self) -> Vec<u8> {
let inner = &self.0;
let secret_bytes: Vec<u8> = match inner {
BdkDescriptorSecretKey::Single(_) => {
Expand All @@ -158,7 +158,7 @@ impl DescriptorSecretKey {
secret_bytes
}

pub(crate) fn as_string(&self) -> String {
pub fn as_string(&self) -> String {
self.0.to_string()
}
}
Expand All @@ -167,13 +167,13 @@ impl DescriptorSecretKey {
pub struct DescriptorPublicKey(pub(crate) BdkDescriptorPublicKey);

impl DescriptorPublicKey {
pub(crate) fn from_string(public_key: String) -> Result<Self, DescriptorKeyError> {
pub fn from_string(public_key: String) -> Result<Self, DescriptorKeyError> {
let descriptor_public_key = BdkDescriptorPublicKey::from_str(public_key.as_str())
.map_err(DescriptorKeyError::from)?;
Ok(Self(descriptor_public_key))
}

pub(crate) fn derive(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
pub fn derive(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
let secp = Secp256k1::new();
let descriptor_public_key = &self.0;
let path = path.inner_mutex.lock().unwrap().deref().clone();
Expand Down Expand Up @@ -201,7 +201,7 @@ impl DescriptorPublicKey {
}
}

pub(crate) fn extend(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
pub fn extend(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
let descriptor_public_key = &self.0;
let path = path.inner_mutex.lock().unwrap().deref().clone();
match descriptor_public_key {
Expand All @@ -220,15 +220,15 @@ impl DescriptorPublicKey {
}
}

pub(crate) fn as_string(&self) -> String {
pub fn as_string(&self) -> String {
self.0.to_string()
}

pub(crate) fn is_multipath(&self) -> bool {
pub fn is_multipath(&self) -> bool {
self.0.is_multipath()
}

pub(crate) fn master_fingerprint(&self) -> String {
pub fn master_fingerprint(&self) -> String {
self.0.master_fingerprint().to_string()
}
}
Expand Down
Loading
Loading