From 96e5c28d5d95066357a670305dc79d72db8c8681 Mon Sep 17 00:00:00 2001 From: Steve Miskovetz Date: Tue, 26 Dec 2023 22:31:55 -0600 Subject: [PATCH 1/3] feat: add unsafe-password support to cast wallet import --- crates/cast/bin/cmd/wallet/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/cast/bin/cmd/wallet/mod.rs b/crates/cast/bin/cmd/wallet/mod.rs index b4cec44e0879..44f8a79c198d 100644 --- a/crates/cast/bin/cmd/wallet/mod.rs +++ b/crates/cast/bin/cmd/wallet/mod.rs @@ -135,6 +135,10 @@ pub enum WalletSubcommands { /// (~/.foundry/keystores) #[clap(long, short)] keystore_dir: Option, + /// Password for the JSON keystore in cleartext + /// This is unsafe, we recommend using the default hidden password prompt + #[clap(long, env = "CAST_PASSWORD", value_name = "PASSWORD")] + unsafe_password: Option, #[clap(flatten)] raw_wallet_options: RawWallet, }, @@ -272,7 +276,7 @@ impl WalletSubcommands { } } } - 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() @@ -303,7 +307,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( From 9cedfd64747afc83a3c4003fee0bcbf3a2528a6f Mon Sep 17 00:00:00 2001 From: Steve Miskovetz Date: Wed, 27 Dec 2023 09:57:49 -0600 Subject: [PATCH 2/3] rustfmt fix --- crates/cast/bin/cmd/wallet/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/cast/bin/cmd/wallet/mod.rs b/crates/cast/bin/cmd/wallet/mod.rs index 44f8a79c198d..b642de0dac91 100644 --- a/crates/cast/bin/cmd/wallet/mod.rs +++ b/crates/cast/bin/cmd/wallet/mod.rs @@ -276,7 +276,12 @@ impl WalletSubcommands { } } } - WalletSubcommands::Import { account_name, keystore_dir, unsafe_password, 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() From 4f8e1793babee10703ee7062923cbc083aec1e9a Mon Sep 17 00:00:00 2001 From: Steve Miskovetz Date: Tue, 2 Jan 2024 20:45:57 -0600 Subject: [PATCH 3/3] Change env CAST_PASSWORD to CAST_UNSAFE_PASSWORD for `cast wallet import` --- crates/cast/bin/cmd/wallet/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cast/bin/cmd/wallet/mod.rs b/crates/cast/bin/cmd/wallet/mod.rs index b642de0dac91..eba40826afb9 100644 --- a/crates/cast/bin/cmd/wallet/mod.rs +++ b/crates/cast/bin/cmd/wallet/mod.rs @@ -137,7 +137,7 @@ pub enum WalletSubcommands { keystore_dir: Option, /// Password for the JSON keystore in cleartext /// This is unsafe, we recommend using the default hidden password prompt - #[clap(long, env = "CAST_PASSWORD", value_name = "PASSWORD")] + #[clap(long, env = "CAST_UNSAFE_PASSWORD", value_name = "PASSWORD")] unsafe_password: Option, #[clap(flatten)] raw_wallet_options: RawWallet,