Recover a BIP39 Seed with a Mnemonic and Optional Passphrase
Run the Example
You can recover a BIP39 seed with provided mnemonic and optional passphrase by running the following command from within
the client crate. Stronghold will store the recovered
seed at the provided path
.
cargo run --example cli bip39-recover --path "/path/to/snapshot.file" --client-path "client-path-0" --key "passphrase-for-snapshot" --mnemonic "けさき にんか せっさたくま よかん たいまつばな ちんもく そだてる ふっこく せっさたくま しゃおん そがい つうはん まなぶ りくぐん さのう" --passphrase "mnemonic-passphrase-if-present" --vault-path "vault-path" --record-path "record-path"
Expected Output
[2022-03-28T08:35:13Z INFO cli] Loading snapshot
[2022-03-28T08:35:13Z INFO cli] Recovering BIP39
[2022-03-28T08:35:13Z INFO cli] BIP39 Recovery successful? true
Example Code
client/examples/cli/main.rs
async fn command_bip39_recover(
path: String,
client_path: String,
key: String,
mnemonic: String,
output: VaultLocation,
passphrase: Option<String>,
) {
let stronghold = Stronghold::default();
let client_path = client_path.as_bytes().to_vec();
let snapshot_path = SnapshotPath::from_path(path);
// calculate hash from key
let key = hash_blake2b(key);
let keyprovider = KeyProvider::try_from(key).expect("Failed to load key");
info!("Loading snapshot");
let client = stronghold
.load_client_from_snapshot(client_path, &keyprovider, &snapshot_path)
.expect("Could not load client from Snapshot");
// get the public key
let procedure_bip39_recover = stronghold::procedures::BIP39Recover {
passphrase,
mnemonic,
output: output.to_location(),
};
info!("Recovering BIP39");
let procedure_result = client.execute_procedure(StrongholdProcedure::BIP39Recover(procedure_bip39_recover));
info!(r#"BIP39 Recovery successful? {}"#, procedure_result.is_ok());
}