Skip to content

Commit

Permalink
feat: add unsafe-password support to cast wallet import (#6671)
Browse files Browse the repository at this point in the history
* 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 <steve@mbwork.lan>
  • Loading branch information
misko9 and Steve Miskovetz committed Mar 1, 2024
1 parent e78b947 commit de33b6a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/cast/bin/cmd/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ pub enum WalletSubcommands {
/// (~/.foundry/keystores)
#[arg(long, short)]
keystore_dir: Option<String>,
/// 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<String>,
#[command(flatten)]
raw_wallet_options: RawWalletOpts,
},
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit de33b6a

Please sign in to comment.