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:
@@ -107,6 +107,23 @@ pub fn read_password_from_user(use_stdin: bool) -> Result<ZeroizeString, String>
|
||||
result.map(ZeroizeString::from)
|
||||
}
|
||||
|
||||
/// Reads a mnemonic phrase from TTY or stdin if `use_stdin == true`.
|
||||
pub fn read_mnemonic_from_user(use_stdin: bool) -> Result<String, String> {
|
||||
let mut input = String::new();
|
||||
if use_stdin {
|
||||
io::stdin()
|
||||
.read_line(&mut input)
|
||||
.map_err(|e| format!("Error reading from stdin: {}", e))?;
|
||||
} else {
|
||||
let tty = File::open("/dev/tty").map_err(|e| format!("Error opening tty: {}", e))?;
|
||||
let mut buf_reader = io::BufReader::new(tty);
|
||||
buf_reader
|
||||
.read_line(&mut input)
|
||||
.map_err(|e| format!("Error reading from tty: {}", e))?;
|
||||
}
|
||||
Ok(input)
|
||||
}
|
||||
|
||||
/// Provides a new-type wrapper around `String` that is zeroized on `Drop`.
|
||||
///
|
||||
/// Useful for ensuring that password memory is zeroed-out on drop.
|
||||
|
||||
Reference in New Issue
Block a user