mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 12:58:31 +00:00
Interactive account passwords (#1623)
## Issue Addressed #1437 ## Proposed Changes - Make the `--wallet-password` flag optional and creates an interactive prompt if not provided. - Make the `--wallet-name` flag optional and creates an interactive prompt if not provided. - Add a minimum password requirement of a 12 character length. - Update the `--stdin-passwords` flag to `--stdin-inputs` because we have non-password user inputs ## Additional Info
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use account_utils::PlainText;
|
||||
use account_utils::{read_mnemonic_from_user, strip_off_newlines};
|
||||
use account_utils::{read_input_from_user, strip_off_newlines};
|
||||
use clap::ArgMatches;
|
||||
use eth2_wallet::bip39::{Language, Mnemonic};
|
||||
use std::fs;
|
||||
@@ -10,6 +10,7 @@ use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
pub const MNEMONIC_PROMPT: &str = "Enter the mnemonic phrase:";
|
||||
pub const WALLET_NAME_PROMPT: &str = "Enter wallet name:";
|
||||
|
||||
pub fn ensure_dir_exists<P: AsRef<Path>>(path: P) -> Result<(), String> {
|
||||
let path = path.as_ref();
|
||||
@@ -29,9 +30,11 @@ pub fn base_wallet_dir(matches: &ArgMatches, arg: &'static str) -> Result<PathBu
|
||||
)
|
||||
}
|
||||
|
||||
/// Reads in a mnemonic from the user. If the file path is provided, read from it. Otherwise, read
|
||||
/// from an interactive prompt using tty, unless the `--stdin-inputs` flag is provided.
|
||||
pub fn read_mnemonic_from_cli(
|
||||
mnemonic_path: Option<PathBuf>,
|
||||
stdin_password: bool,
|
||||
stdin_inputs: bool,
|
||||
) -> Result<Mnemonic, String> {
|
||||
let mnemonic = match mnemonic_path {
|
||||
Some(path) => fs::read(&path)
|
||||
@@ -51,7 +54,7 @@ pub fn read_mnemonic_from_cli(
|
||||
eprintln!("");
|
||||
eprintln!("{}", MNEMONIC_PROMPT);
|
||||
|
||||
let mnemonic = read_mnemonic_from_user(stdin_password)?;
|
||||
let mnemonic = read_input_from_user(stdin_inputs)?;
|
||||
|
||||
match Mnemonic::from_phrase(mnemonic.as_str(), Language::English) {
|
||||
Ok(mnemonic_m) => {
|
||||
@@ -68,3 +71,19 @@ pub fn read_mnemonic_from_cli(
|
||||
};
|
||||
Ok(mnemonic)
|
||||
}
|
||||
|
||||
/// Reads in a wallet name from the user. If the `--wallet-name` flag is provided, use it. Otherwise
|
||||
/// read from an interactive prompt using tty unless the `--stdin-inputs` flag is provided.
|
||||
pub fn read_wallet_name_from_cli(
|
||||
wallet_name: Option<String>,
|
||||
stdin_inputs: bool,
|
||||
) -> Result<String, String> {
|
||||
match wallet_name {
|
||||
Some(name) => Ok(name),
|
||||
None => {
|
||||
eprintln!("{}", WALLET_NAME_PROMPT);
|
||||
|
||||
read_input_from_user(stdin_inputs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user