Skip to content

Commit 68c0e6e

Browse files
committed
Allow to configure a BIP 39 mnemonic
1 parent 6f572cf commit 68c0e6e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-li
4141
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
4242
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async"] }
4343

44-
bdk = { version = "0.28.0", default-features = false, features = ["std", "async-interface", "use-esplora-async", "sqlite-bundled"]}
44+
bdk = { version = "0.28.0", default-features = false, features = ["std", "async-interface", "use-esplora-async", "sqlite-bundled", "keys-bip39"]}
4545
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
4646
rusqlite = { version = "0.28.0", features = ["bundled"] }
4747
bitcoin = "0.29.2"
48+
bip39 = "2.0.0"
4849

4950
rand = "0.8.5"
5051
chrono = "0.4"

src/lib.rs

+16
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ mod test;
7878
mod types;
7979
mod wallet;
8080

81+
pub use bip39;
8182
pub use bitcoin;
8283
pub use lightning;
8384
pub use lightning_invoice;
@@ -188,6 +189,7 @@ impl Default for Config {
188189
enum WalletEntropySource {
189190
SeedFile(String),
190191
SeedBytes([u8; WALLET_KEYS_SEED_LEN]),
192+
Bip39Mnemonic { mnemonic: bip39::Mnemonic, passphrase: Option<String> },
191193
}
192194

193195
/// A builder for an [`Node`] instance, allowing to set some configuration and module choices from
@@ -227,6 +229,16 @@ impl Builder {
227229
self
228230
}
229231

232+
/// Configures the [`Node`] instance to source its wallet entropy from a [BIP 39] mnemonic.
233+
///
234+
/// [BIP 39]: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
235+
pub fn set_entropy_bip39_mnemonic(
236+
&mut self, mnemonic: bip39::Mnemonic, passphrase: Option<String>,
237+
) -> &mut Self {
238+
self.entropy_source = Some(WalletEntropySource::Bip39Mnemonic { mnemonic, passphrase });
239+
self
240+
}
241+
230242
/// Sets the used storage directory path.
231243
///
232244
/// Default: `/tmp/ldk_node/`
@@ -291,6 +303,10 @@ impl Builder {
291303
WalletEntropySource::SeedFile(seed_path) => {
292304
io::utils::read_or_generate_seed_file(seed_path)
293305
}
306+
WalletEntropySource::Bip39Mnemonic { mnemonic, passphrase } => match passphrase {
307+
Some(passphrase) => mnemonic.to_seed(passphrase),
308+
None => mnemonic.to_seed(""),
309+
},
294310
}
295311
} else {
296312
// Default to read or generate from the default location generate a seed file.

0 commit comments

Comments
 (0)