Skip to content

Commit 53bf620

Browse files
authored
docs(forge script): improve Mac Mismatch error referring to failure to decrypt of keystore (#8572)
* docs(`forge script`): improve `Mac Mismatch` error referring to failure to decrypt of keystore * chore: rename error
1 parent 26a7559 commit 53bf620

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/wallets/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ rpassword = "7"
4545
serde.workspace = true
4646
thiserror.workspace = true
4747
tracing.workspace = true
48+
eth-keystore = "0.5.0"
4849

4950
[dev-dependencies]
5051
tokio = { workspace = true, features = ["macros"] }

crates/wallets/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub enum PrivateKeyError {
2222
pub enum WalletSignerError {
2323
#[error(transparent)]
2424
Local(#[from] LocalSignerError),
25+
#[error("Failed to decrypt keystore: incorrect password")]
26+
IncorrectKeystorePassword,
2527
#[error(transparent)]
2628
Ledger(#[from] LedgerError),
2729
#[error(transparent)]

crates/wallets/src/wallet_signer.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,17 @@ impl PendingSigner {
263263
match self {
264264
Self::Keystore(path) => {
265265
let password = rpassword::prompt_password("Enter keystore password:")?;
266-
Ok(WalletSigner::Local(PrivateKeySigner::decrypt_keystore(path, password)?))
266+
match PrivateKeySigner::decrypt_keystore(path, password) {
267+
Ok(signer) => Ok(WalletSigner::Local(signer)),
268+
Err(e) => match e {
269+
// Catch the `MacMismatch` error, which indicates an incorrect password and
270+
// return a more user-friendly `IncorrectKeystorePassword`.
271+
alloy_signer_local::LocalSignerError::EthKeystoreError(
272+
eth_keystore::KeystoreError::MacMismatch,
273+
) => Err(WalletSignerError::IncorrectKeystorePassword),
274+
_ => Err(WalletSignerError::Local(e)),
275+
},
276+
}
267277
}
268278
Self::Interactive => {
269279
let private_key = rpassword::prompt_password("Enter private key:")?;

0 commit comments

Comments
 (0)