Skip to main content

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โ€‹

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 {
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());