Skip to content

Commit f3788d0

Browse files
committed
deps(keyring-controller): ethereumjs-wallet@^1.0.1 -> @ethereumjs/wallet@^2.0.4
- fix: wallet privatekey import fix - fix: catch and throw error previously handled by ethereumjs-wallet
1 parent e825794 commit f3788d0

File tree

5 files changed

+73
-208
lines changed

5 files changed

+73
-208
lines changed

packages/keyring-controller/jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = merge(baseConfig, {
1717
// An object that configures minimum threshold enforcement for coverage results
1818
coverageThreshold: {
1919
global: {
20-
branches: 95.51,
20+
branches: 95.48,
2121
functions: 100,
2222
lines: 99.07,
2323
statements: 99.08,

packages/keyring-controller/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
},
4949
"dependencies": {
5050
"@ethereumjs/util": "^8.1.0",
51+
"@ethereumjs/wallet": "^2.0.4",
5152
"@keystonehq/metamask-airgapped-keyring": "^0.14.1",
5253
"@metamask/base-controller": "^7.1.0",
5354
"@metamask/browser-passworder": "^4.3.0",
@@ -59,7 +60,6 @@
5960
"@metamask/message-manager": "^11.0.3",
6061
"@metamask/utils": "^11.0.1",
6162
"async-mutex": "^0.5.0",
62-
"ethereumjs-wallet": "^1.0.1",
6363
"immer": "^9.0.6"
6464
},
6565
"devDependencies": {

packages/keyring-controller/src/KeyringController.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,9 @@ describe('KeyringController', () => {
11151115
'',
11161116
somePassword,
11171117
]),
1118-
).rejects.toThrow('Unexpected end of JSON input');
1118+
).rejects.toThrow(
1119+
'Key derivation failed - possibly wrong passphrase',
1120+
);
11191121
});
11201122
});
11211123

packages/keyring-controller/src/KeyringController.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { TxData, TypedTransaction } from '@ethereumjs/tx';
22
import { isValidPrivate, toBuffer, getBinarySize } from '@ethereumjs/util';
3+
import { Wallet, thirdparty as importers } from '@ethereumjs/wallet';
34
import type {
45
MetaMaskKeyring as QRKeyring,
56
IKeyringState as IQRKeyringState,
@@ -41,7 +42,6 @@ import {
4142
} from '@metamask/utils';
4243
import { Mutex } from 'async-mutex';
4344
import type { MutexInterface } from 'async-mutex';
44-
import Wallet, { thirdparty as importers } from 'ethereumjs-wallet';
4545
import type { Patch } from 'immer';
4646

4747
import { KeyringControllerError } from './constants';
@@ -1013,16 +1013,25 @@ export class KeyringController extends BaseController<
10131013

10141014
privateKey = remove0x(prefixed);
10151015
break;
1016-
case 'json':
1017-
let wallet;
1018-
const [input, password] = args;
1016+
case 'json': {
10191017
try {
1020-
wallet = importers.fromEtherWallet(input, password);
1018+
const getWallet = async (): Promise<Wallet> => {
1019+
const [input, password] = args;
1020+
try {
1021+
return await importers.fromEtherWallet(input, password);
1022+
} catch (e) {
1023+
return await Wallet.fromV3(input, password, true);
1024+
}
1025+
};
1026+
const wallet = await getWallet();
1027+
privateKey = bytesToHex(wallet.getPrivateKey());
1028+
break;
10211029
} catch (e) {
1022-
wallet = wallet || (await Wallet.fromV3(input, password, true));
1030+
throw new Error(
1031+
'Key derivation failed - possibly wrong passphrase',
1032+
);
10231033
}
1024-
privateKey = bytesToHex(wallet.getPrivateKey());
1025-
break;
1034+
}
10261035
default:
10271036
throw new Error(`Unexpected import strategy: '${strategy}'`);
10281037
}

0 commit comments

Comments
 (0)