@@ -19,9 +19,15 @@ use std::ops::Deref;
1919use std:: str:: FromStr ;
2020use std:: sync:: { Arc , Mutex } ;
2121
22+ /// A mnemonic seed phrase to recover a BIP-32 wallet.
23+ #[ derive( uniffi:: Object ) ]
24+ #[ uniffi:: export( Display ) ]
2225pub struct Mnemonic ( BdkMnemonic ) ;
2326
27+ #[ uniffi:: export]
2428impl Mnemonic {
29+ /// Generate a mnemonic given a word count.
30+ #[ uniffi:: constructor]
2531 pub fn new ( word_count : WordCount ) -> Self {
2632 // TODO 4: I DON'T KNOW IF THIS IS A DECENT WAY TO GENERATE ENTROPY PLEASE CONFIRM
2733 let mut rng = rand:: thread_rng ( ) ;
@@ -33,13 +39,18 @@ impl Mnemonic {
3339 let mnemonic = BdkMnemonic :: parse_in ( Language :: English , generated_key. to_string ( ) ) . unwrap ( ) ;
3440 Mnemonic ( mnemonic)
3541 }
36-
42+ /// Parse a string as a mnemonic seed phrase.
43+ #[ uniffi:: constructor]
3744 pub fn from_string ( mnemonic : String ) -> Result < Self , Bip39Error > {
3845 BdkMnemonic :: from_str ( & mnemonic)
3946 . map ( Mnemonic )
4047 . map_err ( Bip39Error :: from)
4148 }
4249
50+ /// Construct a mnemonic given an array of bytes. Note that using weak entropy will result in a loss
51+ /// of funds. To ensure the entropy is generated properly, read about your operating
52+ /// system specific ways to generate secure random numbers.
53+ #[ uniffi:: constructor]
4354 pub fn from_entropy ( entropy : Vec < u8 > ) -> Result < Self , Bip39Error > {
4455 BdkMnemonic :: from_entropy ( entropy. as_slice ( ) )
4556 . map ( Mnemonic )
@@ -53,11 +64,16 @@ impl Display for Mnemonic {
5364 }
5465}
5566
67+ /// A BIP-32 derivation path.
68+ #[ derive( uniffi:: Object ) ]
5669pub struct DerivationPath {
5770 inner_mutex : Mutex < BdkDerivationPath > ,
5871}
5972
73+ #[ uniffi:: export]
6074impl DerivationPath {
75+ /// Parse a string as a BIP-32 derivation path.
76+ #[ uniffi:: constructor]
6177 pub fn new ( path : String ) -> Result < Self , Bip32Error > {
6278 BdkDerivationPath :: from_str ( & path)
6379 . map ( |x| DerivationPath {
0 commit comments