mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-26 09:13:41 +00:00
Mnemonic key recovery (#1579)
## Issue Addressed N/A ## Proposed Changes Add a `lighthouse am wallet recover` command that recreates a wallet from a mnemonic but no validator keys. Add a `lighthouse am validator recover` command which would directly create keys from a mnemonic for a given index and count. ## Additional Info Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
@@ -6,6 +6,6 @@ pub mod json_wallet;
|
||||
pub use bip39;
|
||||
pub use validator_path::{KeyType, ValidatorPath, COIN_TYPE, PURPOSE};
|
||||
pub use wallet::{
|
||||
recover_validator_secret, DerivedKey, Error, KeystoreError, PlainText, Uuid,
|
||||
ValidatorKeystores, Wallet, WalletBuilder,
|
||||
recover_validator_secret, recover_validator_secret_from_mnemonic, DerivedKey, Error,
|
||||
KeystoreError, PlainText, Uuid, ValidatorKeystores, Wallet, WalletBuilder,
|
||||
};
|
||||
|
||||
@@ -285,3 +285,19 @@ pub fn recover_validator_secret(
|
||||
|
||||
Ok((destination.secret().to_vec().into(), path))
|
||||
}
|
||||
|
||||
/// Returns `(secret, path)` for the `key_type` for the validator at `index`.
|
||||
///
|
||||
/// This function should only be used for key recovery since it can easily lead to key duplication.
|
||||
pub fn recover_validator_secret_from_mnemonic(
|
||||
secret: &[u8],
|
||||
index: u32,
|
||||
key_type: KeyType,
|
||||
) -> Result<(PlainText, ValidatorPath), Error> {
|
||||
let path = ValidatorPath::new(index, key_type);
|
||||
let master = DerivedKey::from_seed(secret).map_err(|()| Error::EmptyPassword)?;
|
||||
|
||||
let destination = path.iter_nodes().fold(master, |dk, i| dk.child(*i));
|
||||
|
||||
Ok((destination.secret().to_vec().into(), path))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user