Skip to content

Commit e2435c6

Browse files
authored
Merge branch 'main' into mikesposito/keyring-typed-message-type
2 parents 463d850 + 68a14b0 commit e2435c6

34 files changed

+317
-160
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/accounts-monorepo",
3-
"version": "35.0.0",
3+
"version": "39.0.0",
44
"private": true,
55
"description": "Monorepo for MetaMask accounts related packages",
66
"repository": {

packages/keyring-eth-hd/CHANGELOG.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [12.0.0]
11+
12+
### Changed
13+
14+
- **BREAKING:** The method `signTransaction` can now returns various type of transactions ([#209](https://github.com/MetaMask/accounts/pull/209))
15+
- Initially was supporting: `Transaction | AccessListEIP2930Transaction | FeeMarketEIP1559Transaction` (types from `@ethereumjs/tx`).
16+
- Now also supports `BlobEIP4844Transaction | EOACodeEIP7702Transaction` (types from `@ethereumjs/tx`).
17+
- **BREAKING:** Bump `@ethereumjs/tx` from `^4.2.0` to `^5.4.0` ([#209](https://github.com/MetaMask/accounts/pull/209))
18+
- **BREAKING:** Bump `@ethereumjs/util` from `^8.1.0` to `^9.1.0` ([#209](https://github.com/MetaMask/accounts/pull/209))
19+
20+
## [11.0.0]
21+
1022
### Changed
1123

1224
- **BREAKING:** The `HdKeyring` is not exported as default anymore ([#161](https://github.com/MetaMask/accounts/pull/161))
@@ -181,7 +193,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
181193
- Deserialize method (and `HdKeyring` constructor by extension) can no longer be passed an options object containing a value for `numberOfAccounts` if it is not also containing a value for `mnemonic`.
182194
- Package name changed from `eth-hd-keyring` to `@metamask/eth-hd-keyring`.
183195

184-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-hd-keyring@10.0.1...HEAD
196+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-hd-keyring@12.0.0...HEAD
197+
[12.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-hd-keyring@11.0.0...@metamask/eth-hd-keyring@12.0.0
198+
[11.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-hd-keyring@10.0.1...@metamask/eth-hd-keyring@11.0.0
185199
[10.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-hd-keyring@10.0.0...@metamask/eth-hd-keyring@10.0.1
186200
[10.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-hd-keyring@9.0.1...@metamask/eth-hd-keyring@10.0.0
187201
[9.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-hd-keyring@9.0.0...@metamask/eth-hd-keyring@9.0.1

packages/keyring-eth-hd/jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = merge(baseConfig, {
2626
branches: 83.87,
2727
functions: 100,
2828
lines: 95,
29-
statements: 97.93,
29+
statements: 97.91,
3030
},
3131
},
3232
});

packages/keyring-eth-hd/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/eth-hd-keyring",
3-
"version": "10.0.1",
3+
"version": "12.0.0",
44
"description": "A simple standard interface for a seed phrase generated set of Ethereum accounts.",
55
"keywords": [
66
"ethereum",
@@ -43,15 +43,15 @@
4343
"test:clean": "jest --clearCache"
4444
},
4545
"dependencies": {
46-
"@ethereumjs/util": "^8.1.0",
46+
"@ethereumjs/util": "^9.1.0",
4747
"@metamask/eth-sig-util": "^8.2.0",
4848
"@metamask/key-tree": "^10.0.2",
4949
"@metamask/scure-bip39": "^2.1.1",
5050
"@metamask/utils": "^11.1.0",
5151
"ethereum-cryptography": "^2.1.2"
5252
},
5353
"devDependencies": {
54-
"@ethereumjs/tx": "^4.2.0",
54+
"@ethereumjs/tx": "^5.4.0",
5555
"@lavamoat/allow-scripts": "^3.2.1",
5656
"@lavamoat/preinstall-always-fail": "^2.1.0",
5757
"@metamask/auto-changelog": "^3.4.4",

packages/keyring-eth-hd/src/hd-keyring.test.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { TransactionFactory, Transaction as EthereumTx } from '@ethereumjs/tx';
21
import {
3-
isValidAddress,
4-
bufferToHex,
5-
toBuffer,
6-
ecrecover,
7-
pubToAddress,
8-
} from '@ethereumjs/util';
2+
TransactionFactory,
3+
LegacyTransaction,
4+
type TypedTxData,
5+
} from '@ethereumjs/tx';
6+
import { isValidAddress, ecrecover, pubToAddress } from '@ethereumjs/util';
97
import * as oldMMForkBIP39 from '@metamask/bip39';
108
import {
119
normalize,
@@ -22,7 +20,7 @@ import {
2220
type EIP7702Authorization,
2321
} from '@metamask/eth-sig-util';
2422
import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';
25-
import { assert, type Hex } from '@metamask/utils';
23+
import { assert, bytesToHex, hexToBytes, type Hex } from '@metamask/utils';
2624
import { webcrypto } from 'crypto';
2725
import { keccak256 } from 'ethereum-cryptography/keccak';
2826
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -642,7 +640,7 @@ describe('hd-keyring', () => {
642640
numberOfAccounts: 1,
643641
});
644642
const localMessage = 'hello there!';
645-
const msgHashHex = bufferToHex(
643+
const msgHashHex = bytesToHex(
646644
Buffer.from(keccak256(Buffer.from(localMessage))),
647645
);
648646
await keyring.addAccounts(9);
@@ -655,12 +653,12 @@ describe('hd-keyring', () => {
655653
signatures.forEach((sgn, index) => {
656654
const accountAddress = addresses[index];
657655

658-
const signatureR = toBuffer(sgn.slice(0, 66));
659-
const signatureS = toBuffer(`0x${sgn.slice(66, 130)}`);
656+
const signatureR = hexToBytes(sgn.slice(0, 66));
657+
const signatureS = hexToBytes(`0x${sgn.slice(66, 130)}`);
660658
const signatureV = BigInt(`0x${sgn.slice(130, 132)}`);
661-
const messageHash = toBuffer(msgHashHex);
659+
const messageHash = hexToBytes(msgHashHex);
662660
const pub = ecrecover(messageHash, signatureV, signatureR, signatureS);
663-
const adr = `0x${pubToAddress(pub).toString('hex')}`;
661+
const adr = bytesToHex(pubToAddress(pub));
664662

665663
expect(adr).toBe(accountAddress);
666664
});
@@ -1055,8 +1053,7 @@ describe('hd-keyring', () => {
10551053
});
10561054
});
10571055

1058-
const txParams = {
1059-
from: firstAcct,
1056+
const txParams: TypedTxData = {
10601057
nonce: '0x00',
10611058
gasPrice: '0x09184e72a000',
10621059
gasLimit: '0x2710',
@@ -1065,7 +1062,7 @@ describe('hd-keyring', () => {
10651062
};
10661063

10671064
it('returns a signed legacy tx object', async function () {
1068-
const tx = new EthereumTx(txParams);
1065+
const tx = LegacyTransaction.fromTxData(txParams);
10691066
expect(tx.isSigned()).toBe(false);
10701067

10711068
const signed = await keyring.signTransaction(firstAcct, tx);

packages/keyring-eth-hd/src/hd-keyring.ts

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import type { TypedTransaction } from '@ethereumjs/tx';
2-
import {
3-
privateToPublic,
4-
publicToAddress,
5-
ecsign,
6-
arrToBufArr,
7-
bufferToHex,
8-
} from '@ethereumjs/util';
2+
import { privateToPublic, publicToAddress, ecsign } from '@ethereumjs/util';
93
import {
104
concatSig,
115
decrypt,
@@ -31,12 +25,13 @@ import {
3125
add0x,
3226
assert,
3327
assertIsHexString,
28+
bigIntToBytes,
29+
bytesToHex,
3430
type Hex,
3531
remove0x,
3632
} from '@metamask/utils';
3733
import { HDKey } from 'ethereum-cryptography/hdkey';
3834
import { keccak256 } from 'ethereum-cryptography/keccak';
39-
import { bytesToHex } from 'ethereum-cryptography/utils';
4035

4136
// Options:
4237
const hdPathString = `m/44'/60'/0'/0`;
@@ -227,7 +222,7 @@ export class HdKeyring {
227222
});
228223
assert(wallet.publicKey, 'Expected public key to be set');
229224
const appKeyAddress = this.#normalizeAddress(
230-
publicToAddress(wallet.publicKey).toString('hex'),
225+
bytesToHex(publicToAddress(wallet.publicKey)),
231226
);
232227
return appKeyAddress;
233228
}
@@ -253,7 +248,7 @@ export class HdKeyring {
253248
privateKey instanceof Uint8Array,
254249
'Expected private key to be of type Uint8Array',
255250
);
256-
return bytesToHex(privateKey);
251+
return remove0x(bytesToHex(privateKey));
257252
}
258253

259254
/**
@@ -293,10 +288,9 @@ export class HdKeyring {
293288
const privKey = this.#getPrivateKeyFor(address, opts);
294289
const msgSig = ecsign(Buffer.from(message, 'hex'), Buffer.from(privKey));
295290
const rawMsgSig = concatSig(
296-
// WARN: verify this cast to Buffer
297-
msgSig.v as unknown as Buffer,
298-
msgSig.r,
299-
msgSig.s,
291+
Buffer.from(bigIntToBytes(msgSig.v)),
292+
Buffer.from(msgSig.r),
293+
Buffer.from(msgSig.s),
300294
);
301295
return rawMsgSig;
302296
}
@@ -428,7 +422,7 @@ export class HdKeyring {
428422
opts: HDKeyringAccountSelectionOptions = {},
429423
): Promise<string> {
430424
const privKey = this.#getPrivateKeyFor(withAccount, opts);
431-
const publicKey = getEncryptionPublicKey(bytesToHex(privKey));
425+
const publicKey = getEncryptionPublicKey(remove0x(bytesToHex(privKey)));
432426
return publicKey;
433427
}
434428

@@ -570,8 +564,8 @@ export class HdKeyring {
570564
assert(privateKey, 'Expected private key to be set');
571565
const appKeyOriginBuffer = Buffer.from(withAppKeyOrigin, 'utf8');
572566
const appKeyBuffer = Buffer.concat([privateKey, appKeyOriginBuffer]);
573-
const appKeyPrivateKey = arrToBufArr(keccak256(appKeyBuffer));
574-
const appKeyPublicKey = privateToPublic(appKeyPrivateKey);
567+
const appKeyPrivateKey = Buffer.from(keccak256(appKeyBuffer));
568+
const appKeyPublicKey = Buffer.from(privateToPublic(appKeyPrivateKey));
575569
return { privateKey: appKeyPrivateKey, publicKey: appKeyPublicKey };
576570
}
577571

@@ -614,7 +608,7 @@ export class HdKeyring {
614608
*/
615609
#addressfromPublicKey(publicKey: Uint8Array): Hex {
616610
return add0x(
617-
bufferToHex(publicToAddress(Buffer.from(publicKey), true)).toLowerCase(),
611+
bytesToHex(publicToAddress(Buffer.from(publicKey), true)).toLowerCase(),
618612
);
619613
}
620614

packages/keyring-eth-ledger-bridge/CHANGELOG.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [10.0.0]
11+
12+
### Changed
13+
14+
- **BREAKING:** The method `signTransaction` can now returns various type of transactions ([#209](https://github.com/MetaMask/accounts/pull/209))
15+
- Initially was supporting: `Transaction | AccessListEIP2930Transaction | FeeMarketEIP1559Transaction` (types from `@ethereumjs/tx`).
16+
- Now also supports `BlobEIP4844Transaction | EOACodeEIP7702Transaction` (types from `@ethereumjs/tx`).
17+
- **BREAKING:** Bump `@ethereumjs/tx` from `^4.2.0` to `^5.4.0` ([#209](https://github.com/MetaMask/accounts/pull/209))
18+
- **BREAKING:** Bump `@ethereumjs/util` from `^8.1.0` to `^9.1.0` ([#209](https://github.com/MetaMask/accounts/pull/209))
19+
20+
## [9.0.0]
21+
1022
### Changed
1123

1224
- **BREAKING:** `LedgerKeyring` now implements the `Keyring` type ([#194](https://github.com/MetaMask/accounts/pull/194))
@@ -283,7 +295,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
283295

284296
- Support new versions of ethereumjs/tx ([#68](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/68))
285297

286-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@8.0.5...HEAD
298+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@10.0.0...HEAD
299+
[10.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@9.0.0...@metamask/eth-ledger-bridge-keyring@10.0.0
300+
[9.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@8.0.5...@metamask/eth-ledger-bridge-keyring@9.0.0
287301
[8.0.5]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@8.0.4...@metamask/eth-ledger-bridge-keyring@8.0.5
288302
[8.0.4]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@8.0.3...@metamask/eth-ledger-bridge-keyring@8.0.4
289303
[8.0.3]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@8.0.2...@metamask/eth-ledger-bridge-keyring@8.0.3

packages/keyring-eth-ledger-bridge/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/eth-ledger-bridge-keyring",
3-
"version": "8.0.5",
3+
"version": "10.0.0",
44
"description": "A MetaMask compatible keyring, for ledger hardware wallets",
55
"keywords": [
66
"ethereum",
@@ -47,14 +47,14 @@
4747
},
4848
"dependencies": {
4949
"@ethereumjs/rlp": "^5.0.2",
50-
"@ethereumjs/tx": "^4.2.0",
51-
"@ethereumjs/util": "^8.1.0",
50+
"@ethereumjs/tx": "^5.4.0",
51+
"@ethereumjs/util": "^9.1.0",
5252
"@ledgerhq/hw-app-eth": "^6.42.0",
5353
"@metamask/eth-sig-util": "^8.2.0",
5454
"hdkey": "^2.1.0"
5555
},
5656
"devDependencies": {
57-
"@ethereumjs/common": "^3.2.0",
57+
"@ethereumjs/common": "^4.4.0",
5858
"@lavamoat/allow-scripts": "^3.2.1",
5959
"@lavamoat/preinstall-always-fail": "^2.1.0",
6060
"@ledgerhq/hw-transport": "^6.31.3",

packages/keyring-eth-ledger-bridge/src/ledger-keyring.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RLP } from '@ethereumjs/rlp';
33
import { TransactionFactory } from '@ethereumjs/tx';
44
import * as ethUtil from '@ethereumjs/util';
55
import * as sigUtil from '@metamask/eth-sig-util';
6-
import { Hex } from '@metamask/utils';
6+
import { bytesToHex, Hex } from '@metamask/utils';
77
import EthereumTx from 'ethereumjs-tx';
88
import HDKey from 'hdkey';
99

@@ -49,7 +49,7 @@ const fakeTx = new EthereumTx({
4949
value: '0x00',
5050
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
5151
// EIP 155 chainId - mainnet: 1, ropsten: 3
52-
chainId: 1,
52+
chainId: '0x1',
5353
});
5454

5555
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Berlin });
@@ -646,7 +646,7 @@ describe('LedgerKeyring', function () {
646646
v: '0x26',
647647
r: '0xf3a7718999d1b87beda810b25cc025153e74df0745279826b9b2f3d1d1b6318',
648648
s: '0x7e33bdfbf5272dc4f55649e9ba729849670171a68ef8c0fbeed3b879b90b8954',
649-
};
649+
} as const;
650650

651651
await basicSetupToUnlockOneAccount();
652652

@@ -672,7 +672,7 @@ describe('LedgerKeyring', function () {
672672
expect(params).toStrictEqual({
673673
hdPath: "m/44'/60'/0'/0",
674674
tx: Buffer.from(
675-
RLP.encode(newFakeTx.getMessageToSign(false)),
675+
RLP.encode(newFakeTx.getMessageToSign()),
676676
).toString('hex'),
677677
});
678678
return expectedRSV;
@@ -694,7 +694,7 @@ describe('LedgerKeyring', function () {
694694
v: '0x0',
695695
r: '0x5ffb3adeaec80e430e7a7b02d95c5108b6f09a0bdf3cf69869dc1b38d0fb8d3a',
696696
s: '0x28b234a5403d31564e18258df84c51a62683e3f54fa2b106fdc1a9058006a112',
697-
};
697+
} as const;
698698

699699
await basicSetupToUnlockOneAccount();
700700

@@ -719,7 +719,7 @@ describe('LedgerKeyring', function () {
719719
.mockImplementation(async (params) => {
720720
expect(params).toStrictEqual({
721721
hdPath: "m/44'/60'/0'/0",
722-
tx: fakeTypeTwoTx.getMessageToSign(false).toString('hex'),
722+
tx: bytesToHex(fakeTypeTwoTx.getMessageToSign() as Uint8Array),
723723
});
724724
return expectedRSV;
725725
});

0 commit comments

Comments
 (0)