Skip to content

Commit

Permalink
Revert "bump @metamask/eth-sig-util to latest (#914)"
Browse files Browse the repository at this point in the history
This reverts commit 49d3fe6.
  • Loading branch information
gantunesr committed Feb 10, 2023
1 parent 6b22c3d commit 2fb64b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 51 deletions.
2 changes: 1 addition & 1 deletion packages/keyring-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
"@ledgerhq/metamask-keyring": "0.3.3",
"@metamask/base-controller": "workspace:^",
"@metamask/controller-utils": "workspace:^",
"@metamask/eth-sig-util": "^5.0.2",
"@metamask/message-manager": "workspace:^",
"@metamask/preferences-controller": "workspace:^",
"async-mutex": "^0.2.6",
"eth-keyring-controller": "^7.0.2",
"eth-sig-util": "^3.0.0",
"ethereumjs-util": "^7.0.10",
"ethereumjs-wallet": "^1.0.1"
},
Expand Down
46 changes: 21 additions & 25 deletions packages/keyring-controller/src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { BN, bufferToHex } from 'ethereumjs-util';
import {
recoverPersonalSignature,
recoverTypedSignature,
SignTypedDataVersion,
} from '@metamask/eth-sig-util';
recoverTypedSignature_v4,
recoverTypedSignatureLegacy,
} from 'eth-sig-util';
import * as sinon from 'sinon';
import Common from '@ethereumjs/common';
import { TransactionFactory, TypedTransaction } from '@ethereumjs/tx';
Expand All @@ -21,6 +22,7 @@ import {
KeyringConfig,
KeyringController,
KeyringTypes,
SignTypedDataVersion,
} from './KeyringController';

jest.mock('uuid', () => {
Expand Down Expand Up @@ -381,7 +383,7 @@ describe('KeyringController', () => {
data,
from: account,
});
const recovered = recoverPersonalSignature({ data, signature });
const recovered = recoverPersonalSignature({ data, sig: signature });
expect(account).toBe(recovered);
});

Expand All @@ -395,7 +397,7 @@ describe('KeyringController', () => {
data: '',
from: account,
});
const recovered = recoverPersonalSignature({ data: '', signature });
const recovered = recoverPersonalSignature({ data: '', sig: signature });
expect(account).toBe(recovered);
});

Expand Down Expand Up @@ -452,10 +454,9 @@ describe('KeyringController', () => {
{ data: typedMsgParams, from: account },
SignTypedDataVersion.V1,
);
const recovered = recoverTypedSignature({
const recovered = recoverTypedSignatureLegacy({
data: typedMsgParams,
signature,
version: SignTypedDataVersion.V1,
sig: signature as string,
});
expect(account).toBe(recovered);
});
Expand All @@ -479,7 +480,7 @@ describe('KeyringController', () => {
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
},
},
primaryType: 'Mail' as const,
primaryType: 'Mail',
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
Expand All @@ -504,9 +505,8 @@ describe('KeyringController', () => {
SignTypedDataVersion.V3,
);
const recovered = recoverTypedSignature({
data: msgParams,
signature,
version: SignTypedDataVersion.V3,
data: msgParams as any,
sig: signature as string,
});
expect(account).toBe(recovered);
});
Expand Down Expand Up @@ -539,7 +539,7 @@ describe('KeyringController', () => {
},
],
},
primaryType: 'Mail' as const,
primaryType: 'Mail',
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
Expand Down Expand Up @@ -568,10 +568,9 @@ describe('KeyringController', () => {
{ data: JSON.stringify(msgParams), from: account },
SignTypedDataVersion.V4,
);
const recovered = recoverTypedSignature({
data: msgParams,
signature,
version: SignTypedDataVersion.V4,
const recovered = recoverTypedSignature_v4({
data: msgParams as any,
sig: signature as string,
});
expect(account).toBe(recovered);
});
Expand Down Expand Up @@ -856,7 +855,7 @@ describe('KeyringController', () => {
data,
from: account,
});
const recovered = recoverPersonalSignature({ data, signature });
const recovered = recoverPersonalSignature({ data, sig: signature });
expect(account.toLowerCase()).toBe(recovered.toLowerCase());
});

Expand Down Expand Up @@ -889,10 +888,9 @@ describe('KeyringController', () => {
{ data: typedMsgParams, from: account },
SignTypedDataVersion.V1,
);
const recovered = recoverTypedSignature({
const recovered = recoverTypedSignatureLegacy({
data: typedMsgParams,
signature,
version: SignTypedDataVersion.V1,
sig: signature as string,
});
expect(account.toLowerCase()).toBe(recovered.toLowerCase());
});
Expand Down Expand Up @@ -922,8 +920,7 @@ describe('KeyringController', () => {
);
const recovered = recoverTypedSignature({
data: JSON.parse(msg),
signature,
version: SignTypedDataVersion.V3,
sig: signature as string,
});
expect(account.toLowerCase()).toBe(recovered);
});
Expand All @@ -948,10 +945,9 @@ describe('KeyringController', () => {
{ data: msg, from: account },
SignTypedDataVersion.V4,
);
const recovered = recoverTypedSignature({
const recovered = recoverTypedSignature_v4({
data: JSON.parse(msg),
signature,
version: SignTypedDataVersion.V4,
sig: signature as string,
});
expect(account.toLowerCase()).toBe(recovered);
});
Expand Down
17 changes: 7 additions & 10 deletions packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
import {
normalize as normalizeAddress,
signTypedData,
} from '@metamask/eth-sig-util';
signTypedData_v4,
signTypedDataLegacy,
} from 'eth-sig-util';
import Wallet, { thirdparty as importers } from 'ethereumjs-wallet';
import Keyring from 'eth-keyring-controller';
import { Mutex } from 'async-mutex';
Expand Down Expand Up @@ -490,22 +492,17 @@ export class KeyringController extends BaseController<
const privateKeyBuffer = toBuffer(addHexPrefix(privateKey));
switch (version) {
case SignTypedDataVersion.V1:
return signTypedData({
privateKey: privateKeyBuffer,
// signTypedDataLegacy will throw if the data is invalid.
return signTypedDataLegacy(privateKeyBuffer, {
data: messageParams.data as any,
version: SignTypedDataVersion.V1,
});
case SignTypedDataVersion.V3:
return signTypedData({
privateKey: privateKeyBuffer,
return signTypedData(privateKeyBuffer, {
data: JSON.parse(messageParams.data as string),
version: SignTypedDataVersion.V3,
});
case SignTypedDataVersion.V4:
return signTypedData({
privateKey: privateKeyBuffer,
return signTypedData_v4(privateKeyBuffer, {
data: JSON.parse(messageParams.data as string),
version: SignTypedDataVersion.V4,
});
default:
throw new Error(`Unexpected signTypedMessage version: '${version}'`);
Expand Down
16 changes: 1 addition & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1806,20 +1806,6 @@ __metadata:
languageName: node
linkType: hard

"@metamask/eth-sig-util@npm:^5.0.2":
version: 5.0.2
resolution: "@metamask/eth-sig-util@npm:5.0.2"
dependencies:
"@ethereumjs/util": ^8.0.0
bn.js: ^4.11.8
ethereum-cryptography: ^1.1.2
ethjs-util: ^0.1.6
tweetnacl: ^1.0.3
tweetnacl-util: ^0.15.1
checksum: 1fbf1a0f5e654058f0219c9018dbebadf53036c9c3b47c8faf1cac54816532bb18996821736f526ac4e3d579afcaf502af4ad07e88158a50f015141858b08a90
languageName: node
linkType: hard

"@metamask/gas-fee-controller@workspace:packages/gas-fee-controller":
version: 0.0.0-use.local
resolution: "@metamask/gas-fee-controller@workspace:packages/gas-fee-controller"
Expand Down Expand Up @@ -1864,13 +1850,13 @@ __metadata:
"@metamask/auto-changelog": ^3.1.0
"@metamask/base-controller": "workspace:^"
"@metamask/controller-utils": "workspace:^"
"@metamask/eth-sig-util": ^5.0.2
"@metamask/message-manager": "workspace:^"
"@metamask/preferences-controller": "workspace:^"
"@types/jest": ^26.0.22
async-mutex: ^0.2.6
deepmerge: ^4.2.2
eth-keyring-controller: ^7.0.2
eth-sig-util: ^3.0.0
ethereumjs-util: ^7.0.10
ethereumjs-wallet: ^1.0.1
jest: ^26.4.2
Expand Down

0 comments on commit 2fb64b9

Please sign in to comment.