Skip to content

Allow to configure seed via a BIP 39 mnemonic #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-li
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async"] }

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

rand = "0.8.5"
chrono = "0.4"
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod test;
mod types;
mod wallet;

pub use bip39;
pub use bitcoin;
pub use lightning;
pub use lightning_invoice;
Expand Down Expand Up @@ -188,6 +189,7 @@ impl Default for Config {
enum WalletEntropySource {
SeedFile(String),
SeedBytes([u8; WALLET_KEYS_SEED_LEN]),
Bip39Mnemonic { mnemonic: bip39::Mnemonic, passphrase: Option<String> },
}

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

/// Configures the [`Node`] instance to source its wallet entropy from a [BIP 39] mnemonic.
///
/// [BIP 39]: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
pub fn set_entropy_bip39_mnemonic(
&mut self, mnemonic: bip39::Mnemonic, passphrase: Option<String>,
) -> &mut Self {
self.entropy_source = Some(WalletEntropySource::Bip39Mnemonic { mnemonic, passphrase });
self
}

/// Sets the used storage directory path.
///
/// Default: `/tmp/ldk_node/`
Expand Down Expand Up @@ -291,6 +303,10 @@ impl Builder {
WalletEntropySource::SeedFile(seed_path) => {
io::utils::read_or_generate_seed_file(seed_path)
}
WalletEntropySource::Bip39Mnemonic { mnemonic, passphrase } => match passphrase {
Some(passphrase) => mnemonic.to_seed(passphrase),
None => mnemonic.to_seed(""),
},
}
} else {
// Default to read or generate from the default location generate a seed file.
Expand Down