Skip to content

Commit 040b0e4

Browse files
authored
Merge pull request #66 from tnull/2023-04-allow-mnemonics
Allow to configure seed via a BIP 39 mnemonic
2 parents b51f9e8 + 1e149cb commit 040b0e4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ mod test;
8181
mod types;
8282
mod wallet;
8383

84+
pub use bip39;
8485
pub use bitcoin;
8586
pub use lightning;
8687
pub use lightning_invoice;
@@ -191,6 +192,7 @@ impl Default for Config {
191192
enum WalletEntropySource {
192193
SeedFile(String),
193194
SeedBytes([u8; WALLET_KEYS_SEED_LEN]),
195+
Bip39Mnemonic { mnemonic: bip39::Mnemonic, passphrase: Option<String> },
194196
}
195197

196198
/// A builder for an [`Node`] instance, allowing to set some configuration and module choices from
@@ -230,6 +232,16 @@ impl Builder {
230232
self
231233
}
232234

235+
/// Configures the [`Node`] instance to source its wallet entropy from a [BIP 39] mnemonic.
236+
///
237+
/// [BIP 39]: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
238+
pub fn set_entropy_bip39_mnemonic(
239+
&mut self, mnemonic: bip39::Mnemonic, passphrase: Option<String>,
240+
) -> &mut Self {
241+
self.entropy_source = Some(WalletEntropySource::Bip39Mnemonic { mnemonic, passphrase });
242+
self
243+
}
244+
233245
/// Sets the used storage directory path.
234246
///
235247
/// Default: `/tmp/ldk_node/`
@@ -293,6 +305,10 @@ impl Builder {
293305
WalletEntropySource::SeedFile(seed_path) => {
294306
io::utils::read_or_generate_seed_file(seed_path)
295307
}
308+
WalletEntropySource::Bip39Mnemonic { mnemonic, passphrase } => match passphrase {
309+
Some(passphrase) => mnemonic.to_seed(passphrase),
310+
None => mnemonic.to_seed(""),
311+
},
296312
}
297313
} else {
298314
// Default to read or generate from the default location generate a seed file.

0 commit comments

Comments
 (0)