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

bump @metamask/eth-sig-util to latest #914

Merged
merged 4 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"@keystonehq/metamask-airgapped-keyring": "^0.6.1",
"@metamask/base-controller": "workspace:^",
"@metamask/controller-utils": "workspace:^",
"@metamask/eth-sig-util": "^5.0.2",
adonesky1 marked this conversation as resolved.
Show resolved Hide resolved
"@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
38 changes: 21 additions & 17 deletions packages/keyring-controller/src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { bufferToHex } from 'ethereumjs-util';
import {
recoverPersonalSignature,
recoverTypedSignature,
recoverTypedSignature_v4,
recoverTypedSignatureLegacy,
} from 'eth-sig-util';
SignTypedDataVersion,
} from '@metamask/eth-sig-util';
import * as sinon from 'sinon';
import Common from '@ethereumjs/common';
import { TransactionFactory } from '@ethereumjs/tx';
Expand All @@ -20,7 +19,6 @@ import {
KeyringConfig,
KeyringController,
KeyringTypes,
SignTypedDataVersion,
} from './KeyringController';

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

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

Expand Down Expand Up @@ -450,9 +448,10 @@ describe('KeyringController', () => {
{ data: typedMsgParams, from: account },
SignTypedDataVersion.V1,
);
const recovered = recoverTypedSignatureLegacy({
const recovered = recoverTypedSignature({
data: typedMsgParams,
sig: signature as string,
signature,
version: SignTypedDataVersion.V1,
});
expect(account).toBe(recovered);
});
Expand Down Expand Up @@ -502,7 +501,8 @@ describe('KeyringController', () => {
);
const recovered = recoverTypedSignature({
data: msgParams as any,
adonesky1 marked this conversation as resolved.
Show resolved Hide resolved
sig: signature as string,
signature,
version: SignTypedDataVersion.V3,
});
expect(account).toBe(recovered);
});
Expand Down Expand Up @@ -564,9 +564,10 @@ describe('KeyringController', () => {
{ data: JSON.stringify(msgParams), from: account },
SignTypedDataVersion.V4,
);
const recovered = recoverTypedSignature_v4({
const recovered = recoverTypedSignature({
data: msgParams as any,
adonesky1 marked this conversation as resolved.
Show resolved Hide resolved
sig: signature as string,
signature,
version: SignTypedDataVersion.V4,
});
expect(account).toBe(recovered);
});
Expand Down Expand Up @@ -850,7 +851,7 @@ describe('KeyringController', () => {
data,
from: account,
});
const recovered = recoverPersonalSignature({ data, sig: signature });
const recovered = recoverPersonalSignature({ data, signature });
expect(account.toLowerCase()).toBe(recovered.toLowerCase());
});

Expand Down Expand Up @@ -883,9 +884,10 @@ describe('KeyringController', () => {
{ data: typedMsgParams, from: account },
SignTypedDataVersion.V1,
);
const recovered = recoverTypedSignatureLegacy({
const recovered = recoverTypedSignature({
data: typedMsgParams,
sig: signature as string,
signature,
version: SignTypedDataVersion.V1,
});
expect(account.toLowerCase()).toBe(recovered.toLowerCase());
});
Expand Down Expand Up @@ -915,7 +917,8 @@ describe('KeyringController', () => {
);
const recovered = recoverTypedSignature({
data: JSON.parse(msg),
sig: signature as string,
signature,
version: SignTypedDataVersion.V3,
});
expect(account.toLowerCase()).toBe(recovered);
});
Expand All @@ -940,9 +943,10 @@ describe('KeyringController', () => {
{ data: msg, from: account },
SignTypedDataVersion.V4,
);
const recovered = recoverTypedSignature_v4({
const recovered = recoverTypedSignature({
data: JSON.parse(msg),
sig: signature as string,
signature,
version: SignTypedDataVersion.V4,
});
expect(account.toLowerCase()).toBe(recovered);
});
Expand Down
17 changes: 10 additions & 7 deletions packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import {
import {
normalize as normalizeAddress,
signTypedData,
signTypedData_v4,
signTypedDataLegacy,
} from 'eth-sig-util';
} from '@metamask/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 @@ -481,17 +479,22 @@ export class KeyringController extends BaseController<
const privateKeyBuffer = toBuffer(addHexPrefix(privateKey));
switch (version) {
case SignTypedDataVersion.V1:
// signTypedDataLegacy will throw if the data is invalid.
return signTypedDataLegacy(privateKeyBuffer, {
return signTypedData({
privateKey: privateKeyBuffer,
data: messageParams.data as any,
version: SignTypedDataVersion.V1,
});
case SignTypedDataVersion.V3:
return signTypedData(privateKeyBuffer, {
return signTypedData({
privateKey: privateKeyBuffer,
data: JSON.parse(messageParams.data as string),
version: SignTypedDataVersion.V3,
});
case SignTypedDataVersion.V4:
return signTypedData_v4(privateKeyBuffer, {
return signTypedData({
privateKey: privateKeyBuffer,
data: JSON.parse(messageParams.data as string),
version: SignTypedDataVersion.V4,
});
default:
throw new Error(`Unexpected signTypedMessage version: '${version}'`);
Expand Down
16 changes: 15 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,20 @@ __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 @@ -1726,13 +1740,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