@@ -19,9 +19,15 @@ use std::ops::Deref;
19
19
use std:: str:: FromStr ;
20
20
use std:: sync:: { Arc , Mutex } ;
21
21
22
+ /// A mnemonic seed phrase to recover a BIP-32 wallet.
23
+ #[ derive( uniffi:: Object ) ]
24
+ #[ uniffi:: export( Display ) ]
22
25
pub struct Mnemonic ( BdkMnemonic ) ;
23
26
27
+ #[ uniffi:: export]
24
28
impl Mnemonic {
29
+ /// Generate a mnemonic given a word count.
30
+ #[ uniffi:: constructor]
25
31
pub fn new ( word_count : WordCount ) -> Self {
26
32
// TODO 4: I DON'T KNOW IF THIS IS A DECENT WAY TO GENERATE ENTROPY PLEASE CONFIRM
27
33
let mut rng = rand:: thread_rng ( ) ;
@@ -33,13 +39,18 @@ impl Mnemonic {
33
39
let mnemonic = BdkMnemonic :: parse_in ( Language :: English , generated_key. to_string ( ) ) . unwrap ( ) ;
34
40
Mnemonic ( mnemonic)
35
41
}
36
-
42
+ /// Parse a string as a mnemonic seed phrase.
43
+ #[ uniffi:: constructor]
37
44
pub fn from_string ( mnemonic : String ) -> Result < Self , Bip39Error > {
38
45
BdkMnemonic :: from_str ( & mnemonic)
39
46
. map ( Mnemonic )
40
47
. map_err ( Bip39Error :: from)
41
48
}
42
49
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]
43
54
pub fn from_entropy ( entropy : Vec < u8 > ) -> Result < Self , Bip39Error > {
44
55
BdkMnemonic :: from_entropy ( entropy. as_slice ( ) )
45
56
. map ( Mnemonic )
@@ -53,11 +64,16 @@ impl Display for Mnemonic {
53
64
}
54
65
}
55
66
67
+ /// A BIP-32 derivation path.
68
+ #[ derive( uniffi:: Object ) ]
56
69
pub struct DerivationPath {
57
70
inner_mutex : Mutex < BdkDerivationPath > ,
58
71
}
59
72
73
+ #[ uniffi:: export]
60
74
impl DerivationPath {
75
+ /// Parse a string as a BIP-32 derivation path.
76
+ #[ uniffi:: constructor]
61
77
pub fn new ( path : String ) -> Result < Self , Bip32Error > {
62
78
BdkDerivationPath :: from_str ( & path)
63
79
. map ( |x| DerivationPath {
0 commit comments