Closed ConorOkus closed 2 years ago
I've been looking into this and I think what we need is here with the to_seed()
method on the bdk::keys::bip39::Mnemonic
type.
An example of Rust code that generates the seed I think we need is the following:
use bdk::keys::bip39::{Language, Mnemonic};
use bitcoin::hashes::hex::ToHex;
fn main() {
let mnemonic = Mnemonic::parse_in_normalized(
Language::English,
"letter advice cage absurd amount doctor acoustic avoid letter advice cage above"
).unwrap();
let seed: [u8; 64] = mnemonic.to_seed_normalized("");
println!("{:?}", seed);
println!("{}", seed.to_hex());
println!("{}", seed[0..32].to_hex());
}
I think as discussed with @tnull, it's cleaner to simply use the private key of the root node (the m
in the derivation path), because it's 32 bytes in the first place. I think the code would then be
use bdk::keys::bip39::{Language, Mnemonic};
use bitcoin::hashes::hex::ToHex;
fn main() {
let mnemonic = Mnemonic::parse_in_normalized(
Language::English,
"letter advice cage absurd amount doctor acoustic avoid letter advice cage above"
).unwrap();
let seed: [u8; 64] = mnemonic.to_seed_normalized("");
let xprv = bitcoin::util::bip32::ExtendedPrivKey::new_master(Network::Testnet, &seed).unwrap();
let entropy_we_provide_to_ldk: [u8; 32] = xprv.private_key.secret_bytes();
}
Related PR - https://github.com/bitcoindevkit/bdk/pull/644
This can be used to seed an LDK KeysManager with the first 32 bytes from this 64-byte seed.
This enables the entropy we give to LDK to be within the backup system of the on-chain wallet, and allow for 12-to-24-word mnemonics with optional passphrases.