Skip to content

Commit 0b166b1

Browse files
committed
Add Mnemonic::generate() for bindings users
1 parent ad6daa1 commit 0b166b1

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

orange-sdk/src/ffi/ldk_node.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::ffi::orange::error::ConfigError;
33
use crate::{impl_from_core_type, impl_into_core_type};
44
use ldk_node::ChannelDetails as LDKChannelDetails;
55
use ldk_node::bip39::Mnemonic as LDKMnemonic;
6+
use ldk_node::bip39::rand_core::RngCore;
67
use ldk_node::bitcoin::Network as LDKNetwork;
78
use std::str::FromStr;
89

@@ -37,6 +38,13 @@ impl Mnemonic {
3738
Err(_) => Err(ConfigError::InvalidMnemonic),
3839
}
3940
}
41+
42+
#[uniffi::constructor]
43+
pub fn generate() -> Result<Self, ConfigError> {
44+
let mut entropy = [0u8; 16]; // 128 bits for 12-word mnemonic
45+
rand::thread_rng().fill_bytes(&mut entropy);
46+
Self::from_entropy(entropy.to_vec())
47+
}
4048
}
4149

4250
impl std::fmt::Display for Mnemonic {

0 commit comments

Comments
 (0)