Skip to content

Commit

Permalink
fix: catch and throw weerror previously handled by ethereumjs-wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Jun 10, 2024
1 parent 0f986ad commit 6bb7c94
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,17 +1005,21 @@ export class KeyringController extends BaseController<
privateKey = remove0x(prefixed);
break;
case 'json': {
const getWallet = async (): Promise<Wallet> => {
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<Wallet> => {
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}'`);
Expand Down

0 comments on commit 6bb7c94

Please sign in to comment.