Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add unsafe-password support to cast wallet import #6671

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading