@@ -40,29 +40,38 @@ impl std::error::Error for EntropyError {}
4040///
4141/// [`Node`]: crate::Node
4242#[ derive( Copy , Clone ) ]
43+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Object ) ) ]
4344pub struct NodeEntropy ( [ u8 ; WALLET_KEYS_SEED_LEN ] ) ;
4445
46+ impl NodeEntropy {
47+ /// Configures the [`Node`] instance to source its wallet entropy from the given
48+ /// [`WALLET_KEYS_SEED_LEN`] seed bytes.
49+ ///
50+ /// [`Node`]: crate::Node
51+ #[ cfg( not( feature = "uniffi" ) ) ]
52+ pub fn from_seed_bytes ( seed_bytes : [ u8 ; WALLET_KEYS_SEED_LEN ] ) -> Self {
53+ Self ( seed_bytes)
54+ }
55+
56+ pub ( crate ) fn to_seed_bytes ( & self ) -> [ u8 ; WALLET_KEYS_SEED_LEN ] {
57+ self . 0
58+ }
59+ }
60+
61+ #[ cfg_attr( feature = "uniffi" , uniffi:: export) ]
4562impl NodeEntropy {
4663 /// Configures the [`Node`] instance to source its wallet entropy from a [BIP 39] mnemonic.
4764 ///
4865 /// [BIP 39]: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
4966 /// [`Node`]: crate::Node
67+ #[ cfg_attr( feature = "uniffi" , uniffi:: constructor) ]
5068 pub fn from_bip39_mnemonic ( mnemonic : Mnemonic , passphrase : Option < String > ) -> Self {
5169 match passphrase {
5270 Some ( passphrase) => Self ( mnemonic. to_seed ( passphrase) ) ,
5371 None => Self ( mnemonic. to_seed ( "" ) ) ,
5472 }
5573 }
5674
57- /// Configures the [`Node`] instance to source its wallet entropy from the given
58- /// [`WALLET_KEYS_SEED_LEN`] seed bytes.
59- ///
60- /// [`Node`]: crate::Node
61- #[ cfg( not( feature = "uniffi" ) ) ]
62- pub fn from_seed_bytes ( seed_bytes : [ u8 ; WALLET_KEYS_SEED_LEN ] ) -> Self {
63- Self ( seed_bytes)
64- }
65-
6675 /// Configures the [`Node`] instance to source its wallet entropy from the given
6776 /// [`WALLET_KEYS_SEED_LEN`] seed bytes.
6877 ///
@@ -71,6 +80,7 @@ impl NodeEntropy {
7180 ///
7281 /// [`Node`]: crate::Node
7382 #[ cfg( feature = "uniffi" ) ]
83+ #[ uniffi:: constructor]
7484 pub fn from_seed_bytes ( seed_bytes : Vec < u8 > ) -> Result < NodeEntropy , EntropyError > {
7585 if seed_bytes. len ( ) != WALLET_KEYS_SEED_LEN {
7686 return Err ( EntropyError :: InvalidSeedBytes ) ;
@@ -86,16 +96,13 @@ impl NodeEntropy {
8696 /// stored at the given location.
8797 ///
8898 /// [`Node`]: crate::Node
99+ #[ cfg_attr( feature = "uniffi" , uniffi:: constructor) ]
89100 pub fn from_seed_path ( seed_path : String ) -> Result < Self , EntropyError > {
90101 Ok ( Self (
91102 io:: utils:: read_or_generate_seed_file ( & seed_path)
92103 . map_err ( |_| EntropyError :: InvalidSeedFile ) ?,
93104 ) )
94105 }
95-
96- pub ( crate ) fn to_seed_bytes ( & self ) -> [ u8 ; WALLET_KEYS_SEED_LEN ] {
97- self . 0
98- }
99106}
100107
101108impl fmt:: Display for NodeEntropy {
0 commit comments