Skip to content
Open
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
1 change: 1 addition & 0 deletions crates/bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async-trait = { workspace = true }

serde = { workspace = true }
hex = "0.4.3"
zeroize = "1.9"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2", features = [
Expand Down
11 changes: 9 additions & 2 deletions crates/bitcoin/src/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bdk_wallet::{
},
miniscript::BareCtx,
};
use zeroize::{Zeroize, Zeroizing};

use crate::error::Error;

Expand Down Expand Up @@ -90,8 +91,14 @@ impl Mnemonic {

let generated_key: GeneratedKey<_, BareCtx> =
BdkMnemonic::generate_with_entropy((word_count, Language::English), entropy).expect("should not fail");

let mnemonic = BdkMnemonic::parse_in(Language::English, generated_key.to_string())?;
// The entropy has been consumed to derive the mnemonic; wipe our copy so
// the raw seed material does not linger in memory.
entropy.zeroize();

// `generated_key.to_string()` materialises the mnemonic phrase as a plaintext
// String; keep it in a Zeroizing wrapper so it is wiped once parsed.
let phrase = Zeroizing::new(generated_key.to_string());
let mnemonic = BdkMnemonic::parse_in(Language::English, phrase.as_str())?;

Ok(Mnemonic { inner: mnemonic })
}
Expand Down