From de33b6af53005037b463318d2628b5cfcaf39916 Mon Sep 17 00:00:00 2001 From: Steve <1848680+misko9@users.noreply.github.com> Date: Fri, 1 Mar 2024 10:36:07 -0700 Subject: [PATCH] feat: add unsafe-password support to cast wallet import (#6671) * feat: add unsafe-password support to cast wallet import * rustfmt fix * Change env CAST_PASSWORD to CAST_UNSAFE_PASSWORD for `cast wallet import` --------- Co-authored-by: Steve Miskovetz --- crates/cast/bin/cmd/wallet/mod.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/cast/bin/cmd/wallet/mod.rs b/crates/cast/bin/cmd/wallet/mod.rs index 9a08984d7ae9..931ecefa483a 100644 --- a/crates/cast/bin/cmd/wallet/mod.rs +++ b/crates/cast/bin/cmd/wallet/mod.rs @@ -136,6 +136,10 @@ pub enum WalletSubcommands { /// (~/.foundry/keystores) #[arg(long, short)] keystore_dir: Option, + /// Password for the JSON keystore in cleartext + /// This is unsafe, we recommend using the default hidden password prompt + #[arg(long, env = "CAST_UNSAFE_PASSWORD", value_name = "PASSWORD")] + unsafe_password: Option, #[command(flatten)] raw_wallet_options: RawWalletOpts, }, @@ -282,7 +286,12 @@ impl WalletSubcommands { println!("Validation failed. Address {address} did not sign this message."); } } - WalletSubcommands::Import { account_name, keystore_dir, raw_wallet_options } => { + WalletSubcommands::Import { + account_name, + keystore_dir, + unsafe_password, + raw_wallet_options, + } => { // Set up keystore directory let dir = if let Some(path) = keystore_dir { Path::new(&path).to_path_buf() @@ -318,7 +327,12 @@ flag to set your key via: })?; let private_key = wallet.signer().to_bytes(); - let password = rpassword::prompt_password("Enter password: ")?; + let password = if let Some(password) = unsafe_password { + password + } else { + // if no --unsafe-password was provided read via stdin + rpassword::prompt_password("Enter password: ")? + }; let mut rng = thread_rng(); eth_keystore::encrypt_key(