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

deps(keyring-controller): ethereumjs-wallet@^1.0.1 -> @ethereumjs/wallet@^2.0.4 #4190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/keyring-controller/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = merge(baseConfig, {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 95.51,
branches: 95.48,
functions: 100,
lines: 99.07,
statements: 99.08,
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
},
"dependencies": {
"@ethereumjs/util": "^8.1.0",
"@ethereumjs/wallet": "^2.0.4",
"@keystonehq/metamask-airgapped-keyring": "^0.14.1",
"@metamask/base-controller": "^7.1.0",
"@metamask/browser-passworder": "^4.3.0",
Expand All @@ -59,7 +60,6 @@
"@metamask/message-manager": "^11.0.3",
"@metamask/utils": "^11.0.1",
"async-mutex": "^0.5.0",
"ethereumjs-wallet": "^1.0.1",
"immer": "^9.0.6"
},
"devDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion packages/keyring-controller/src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,9 @@ describe('KeyringController', () => {
'',
somePassword,
]),
).rejects.toThrow('Unexpected end of JSON input');
).rejects.toThrow(
'Key derivation failed - possibly wrong passphrase',
);
});
});

Expand Down
25 changes: 17 additions & 8 deletions packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { TxData, TypedTransaction } from '@ethereumjs/tx';
import { isValidPrivate, toBuffer, getBinarySize } from '@ethereumjs/util';
import { Wallet, thirdparty as importers } from '@ethereumjs/wallet';
import type {
MetaMaskKeyring as QRKeyring,
IKeyringState as IQRKeyringState,
Expand Down Expand Up @@ -41,7 +42,6 @@ import {
} from '@metamask/utils';
import { Mutex } from 'async-mutex';
import type { MutexInterface } from 'async-mutex';
import Wallet, { thirdparty as importers } from 'ethereumjs-wallet';
import type { Patch } from 'immer';

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

privateKey = remove0x(prefixed);
break;
case 'json':
let wallet;
const [input, password] = args;
case 'json': {
try {
wallet = importers.fromEtherWallet(input, password);
const getWallet = async (): Promise<Wallet> => {
const [input, password] = args;
try {
return await importers.fromEtherWallet(input, password);
} catch (e) {
return await Wallet.fromV3(input, password, true);
}
};
const wallet = await getWallet();
privateKey = bytesToHex(wallet.getPrivateKey());
break;
} catch (e) {
wallet = wallet || (await Wallet.fromV3(input, password, true));
throw new Error(
'Key derivation failed - possibly wrong passphrase',
);
}
privateKey = bytesToHex(wallet.getPrivateKey());
break;
}
default:
throw new Error(`Unexpected import strategy: '${strategy}'`);
}
Expand Down
Loading