From c1de50ed4779e2f3032916b91c16d619d67f93b2 Mon Sep 17 00:00:00 2001 From: lispking Date: Tue, 10 Sep 2024 19:45:29 +0800 Subject: [PATCH 1/2] feat: new wallet support input password and silent options --- src/new.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/new.rs b/src/new.rs index 5822804..8425b9b 100644 --- a/src/new.rs +++ b/src/new.rs @@ -19,11 +19,22 @@ pub struct New { /// How many accounts to cache by default (Default 10) #[clap(short, long)] pub cache_accounts: Option, + + /// Directly provide the wallet password when create new wallet. + /// + /// WARNING: This is primarily provided for non-interactive testing. Using this flag is + /// prone to leaving your password exposed in your shell command history! + #[clap(short, long)] + pub password_non_interactive: Option, + + /// Silent mode, do not display the mnemonic phrase. + #[clap(short, long)] + pub silent: bool, } pub fn new_wallet_cli(wallet_path: &Path, new: New) -> anyhow::Result<()> { ensure_no_wallet_exists(wallet_path, new.force, stdin().lock())?; - let password = request_new_password(); + let password = new.password_non_interactive.unwrap_or_else(request_new_password); // Generate a random mnemonic phrase. let mnemonic = generate_mnemonic_phrase(&mut rand::thread_rng(), 24)?; write_wallet_from_mnemonic_and_password(wallet_path, &mnemonic, &password)?; @@ -35,9 +46,12 @@ pub fn new_wallet_cli(wallet_path: &Path, new: New) -> anyhow::Result<()> { )?; let mnemonic_string = format!("Wallet mnemonic phrase: {mnemonic}\n"); - display_string_discreetly( - &mnemonic_string, - "### Do not share or lose this mnemonic phrase! Press any key to complete. ###", - )?; + + if !new.silent { + display_string_discreetly( + &mnemonic_string, + "### Do not share or lose this mnemonic phrase! Press any key to complete. ###", + )?; + } Ok(()) } From 60d035b458f5c6367b797e57199b282dc11a9da8 Mon Sep 17 00:00:00 2001 From: lispking Date: Thu, 12 Sep 2024 04:57:21 +0800 Subject: [PATCH 2/2] rename password_non_interactive to unsafe_password --- src/new.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/new.rs b/src/new.rs index 8425b9b..767950e 100644 --- a/src/new.rs +++ b/src/new.rs @@ -25,7 +25,7 @@ pub struct New { /// WARNING: This is primarily provided for non-interactive testing. Using this flag is /// prone to leaving your password exposed in your shell command history! #[clap(short, long)] - pub password_non_interactive: Option, + pub unsafe_password: Option, /// Silent mode, do not display the mnemonic phrase. #[clap(short, long)] @@ -34,7 +34,7 @@ pub struct New { pub fn new_wallet_cli(wallet_path: &Path, new: New) -> anyhow::Result<()> { ensure_no_wallet_exists(wallet_path, new.force, stdin().lock())?; - let password = new.password_non_interactive.unwrap_or_else(request_new_password); + let password = new.unsafe_password.unwrap_or_else(request_new_password); // Generate a random mnemonic phrase. let mnemonic = generate_mnemonic_phrase(&mut rand::thread_rng(), 24)?; write_wallet_from_mnemonic_and_password(wallet_path, &mnemonic, &password)?;