From 6bb7c9423a0d652a03d53a95e60d6b91c854f077 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Thu, 6 Jun 2024 22:18:11 +0000 Subject: [PATCH] fix: catch and throw weerror previously handled by ethereumjs-wallet --- .../src/KeyringController.ts | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/keyring-controller/src/KeyringController.ts b/packages/keyring-controller/src/KeyringController.ts index 1324b41ef26..658ae4c8b55 100644 --- a/packages/keyring-controller/src/KeyringController.ts +++ b/packages/keyring-controller/src/KeyringController.ts @@ -1005,17 +1005,21 @@ export class KeyringController extends BaseController< privateKey = remove0x(prefixed); break; case 'json': { - const getWallet = async (): Promise => { - const [input, password] = args; - try { - return importers.fromEtherWallet(input, password); - } catch (e) { - return Wallet.fromV3(input, password, true); - } - }; - const wallet = await getWallet(); - privateKey = bytesToHex(wallet.getPrivateKey()); - break; + try { + const getWallet = async (): Promise => { + const [input, password] = args; + try { + return importers.fromEtherWallet(input, password); + } catch (e) { + return Wallet.fromV3(input, password, true); + } + }; + const wallet = await getWallet(); + privateKey = bytesToHex(wallet.getPrivateKey()); + break; + } catch(e) { + throw new Error('Key derivation failed - possibly wrong passphrase'); + } } default: throw new Error(`Unexpected import strategy: '${strategy}'`);