diff --git a/jest.config.js b/jest.config.js index 178632c7..6fc5cddf 100644 --- a/jest.config.js +++ b/jest.config.js @@ -43,8 +43,8 @@ module.exports = { global: { branches: 65.42, functions: 88.57, - lines: 81.57, - statements: 81.49, + lines: 81.63, + statements: 81.55, }, }, diff --git a/package.json b/package.json index 0dbb1f98..f062325c 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,11 @@ "test:watch": "jest --watch" }, "dependencies": { + "@ethereumjs/rlp": "^4.0.0", "@ethereumjs/tx": "^4.1.1", + "@ethereumjs/util": "^8.0.0", "@metamask/utils": "^5.0.0", "eth-sig-util": "^2.0.0", - "ethereumjs-util": "^7.0.9", "hdkey": "0.8.0" }, "devDependencies": { @@ -90,11 +91,8 @@ "lavamoat": { "allowScripts": { "@lavamoat/preinstall-always-fail": false, - "eth-sig-util>ethereumjs-abi>ethereumjs-util>keccak": false, - "eth-sig-util>ethereumjs-util>keccak": false, - "ethereumjs-tx>ethereumjs-util>keccak": false, - "ethereumjs-util>ethereum-cryptography>keccak": false, - "ethereumjs-util>ethereum-cryptography>secp256k1": false, + "eth-sig-util>ethereumjs-util>ethereum-cryptography>keccak": false, + "eth-sig-util>ethereumjs-util>ethereum-cryptography>secp256k1": false, "hdkey>secp256k1": false } } diff --git a/src/ledger-keyring.test.ts b/src/ledger-keyring.test.ts index 4c15cd8f..9bfd4058 100644 --- a/src/ledger-keyring.test.ts +++ b/src/ledger-keyring.test.ts @@ -1,8 +1,9 @@ import { Common, Chain, Hardfork } from '@ethereumjs/common'; +import { RLP } from '@ethereumjs/rlp'; import { TransactionFactory } from '@ethereumjs/tx'; +import * as ethUtil from '@ethereumjs/util'; import sigUtil from 'eth-sig-util'; import EthereumTx from 'ethereumjs-tx'; -import * as ethUtil from 'ethereumjs-util'; import HDKey from 'hdkey'; import { LedgerBridge } from './ledger-bridge'; @@ -536,9 +537,7 @@ describe('LedgerKeyring', function () { .mockImplementation(async (params) => { expect(params).toStrictEqual({ hdPath: "m/44'/60'/0'/0", - tx: ethUtil.rlp - .encode(newFakeTx.getMessageToSign(false)) - .toString('hex'), + tx: RLP.encode(newFakeTx.getMessageToSign(false)).toString(), }); return expectedRSV; }); diff --git a/src/ledger-keyring.ts b/src/ledger-keyring.ts index bef198d3..24399214 100644 --- a/src/ledger-keyring.ts +++ b/src/ledger-keyring.ts @@ -1,9 +1,10 @@ +import { RLP } from '@ethereumjs/rlp'; import { TransactionFactory, TxData, TypedTransaction } from '@ethereumjs/tx'; +import * as ethUtil from '@ethereumjs/util'; // eslint-disable-next-line import/no-nodejs-modules import { Buffer } from 'buffer'; import * as sigUtil from 'eth-sig-util'; import type OldEthJsTransaction from 'ethereumjs-tx'; -import * as ethUtil from 'ethereumjs-util'; // eslint-disable-next-line import/no-nodejs-modules import { EventEmitter } from 'events'; import HDKey from 'hdkey'; @@ -333,7 +334,7 @@ export class LedgerKeyring extends EventEmitter { rawTxHex = Buffer.isBuffer(messageToSign) ? messageToSign.toString('hex') - : ethUtil.rlp.encode(messageToSign).toString('hex'); + : RLP.encode(messageToSign).toString(); return this.#signTransaction(address, rawTxHex, (payload) => { // Because tx will be immutable, first get a plain javascript object that diff --git a/yarn.lock b/yarn.lock index 0d1448f4..122b4d29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15,16 +15,7 @@ __metadata: languageName: node linkType: hard -"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.18.6": - version: 7.18.6 - resolution: "@babel/code-frame@npm:7.18.6" - dependencies: - "@babel/highlight": ^7.18.6 - checksum: 195e2be3172d7684bf95cff69ae3b7a15a9841ea9d27d3c843662d50cdd7d6470fd9c8e64be84d031117e4a4083486effba39f9aef6bbb2c89f7f21bcfba33ba - languageName: node - linkType: hard - -"@babel/code-frame@npm:^7.12.13, @babel/code-frame@npm:^7.21.4": +"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.12.13, @babel/code-frame@npm:^7.18.6, @babel/code-frame@npm:^7.21.4": version: 7.21.4 resolution: "@babel/code-frame@npm:7.21.4" dependencies: @@ -63,18 +54,6 @@ __metadata: languageName: node linkType: hard -"@babel/generator@npm:^7.21.3": - version: 7.21.3 - resolution: "@babel/generator@npm:7.21.3" - dependencies: - "@babel/types": ^7.21.3 - "@jridgewell/gen-mapping": ^0.3.2 - "@jridgewell/trace-mapping": ^0.3.17 - jsesc: ^2.5.1 - checksum: be6bb5a32a0273260b91210d4137b7b5da148a2db8dd324654275cb0af865ae59de5e1536e93ac83423b2586415059e1c24cf94293026755cf995757238da749 - languageName: node - linkType: hard - "@babel/generator@npm:^7.21.4, @babel/generator@npm:^7.7.2": version: 7.21.4 resolution: "@babel/generator@npm:7.21.4" @@ -230,7 +209,7 @@ __metadata: languageName: node linkType: hard -"@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.21.4": +"@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.16.4, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.21.4": version: 7.21.4 resolution: "@babel/parser@npm:7.21.4" bin: @@ -239,15 +218,6 @@ __metadata: languageName: node linkType: hard -"@babel/parser@npm:^7.16.4, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.21.3": - version: 7.21.3 - resolution: "@babel/parser@npm:7.21.3" - bin: - parser: ./bin/babel-parser.js - checksum: a71e6456a1260c2a943736b56cc0acdf5f2a53c6c79e545f56618967e51f9b710d1d3359264e7c979313a7153741b1d95ad8860834cc2ab4ce4f428b13cc07be - languageName: node - linkType: hard - "@babel/plugin-syntax-async-generators@npm:^7.8.4": version: 7.8.4 resolution: "@babel/plugin-syntax-async-generators@npm:7.8.4" @@ -402,25 +372,7 @@ __metadata: languageName: node linkType: hard -"@babel/traverse@npm:^7.12.5": - version: 7.21.3 - resolution: "@babel/traverse@npm:7.21.3" - dependencies: - "@babel/code-frame": ^7.18.6 - "@babel/generator": ^7.21.3 - "@babel/helper-environment-visitor": ^7.18.9 - "@babel/helper-function-name": ^7.21.0 - "@babel/helper-hoist-variables": ^7.18.6 - "@babel/helper-split-export-declaration": ^7.18.6 - "@babel/parser": ^7.21.3 - "@babel/types": ^7.21.3 - debug: ^4.1.0 - globals: ^11.1.0 - checksum: 0af5bcd47a2fc501592b90ac1feae9d449afb9ab0772a4f6e68230f4cd3a475795d538c1de3f880fe3414b6c2820bac84d02c6549eea796f39d74a603717447b - languageName: node - linkType: hard - -"@babel/traverse@npm:^7.21.0, @babel/traverse@npm:^7.21.2, @babel/traverse@npm:^7.21.4, @babel/traverse@npm:^7.7.2": +"@babel/traverse@npm:^7.12.5, @babel/traverse@npm:^7.21.0, @babel/traverse@npm:^7.21.2, @babel/traverse@npm:^7.21.4, @babel/traverse@npm:^7.7.2": version: 7.21.4 resolution: "@babel/traverse@npm:7.21.4" dependencies: @@ -438,7 +390,7 @@ __metadata: languageName: node linkType: hard -"@babel/types@npm:^7.0.0, @babel/types@npm:^7.20.2, @babel/types@npm:^7.21.2, @babel/types@npm:^7.21.4, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3": +"@babel/types@npm:^7.0.0, @babel/types@npm:^7.18.6, @babel/types@npm:^7.20.2, @babel/types@npm:^7.20.7, @babel/types@npm:^7.21.0, @babel/types@npm:^7.21.2, @babel/types@npm:^7.21.4, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.8.3": version: 7.21.4 resolution: "@babel/types@npm:7.21.4" dependencies: @@ -449,17 +401,6 @@ __metadata: languageName: node linkType: hard -"@babel/types@npm:^7.18.6, @babel/types@npm:^7.20.7, @babel/types@npm:^7.21.0, @babel/types@npm:^7.21.3, @babel/types@npm:^7.8.3": - version: 7.21.3 - resolution: "@babel/types@npm:7.21.3" - dependencies: - "@babel/helper-string-parser": ^7.19.4 - "@babel/helper-validator-identifier": ^7.19.1 - to-fast-properties: ^2.0.0 - checksum: b750274718ba9cefd0b81836c464009bb6ba339fccce51b9baff497a0a2d96c044c61dc90cf203cec0adc770454b53a9681c3f7716883c802b85ab84c365ba35 - languageName: node - linkType: hard - "@bcoe/v8-coverage@npm:^0.2.3": version: 0.2.3 resolution: "@bcoe/v8-coverage@npm:0.2.3" @@ -566,7 +507,7 @@ __metadata: languageName: node linkType: hard -"@ethereumjs/rlp@npm:^4.0.1": +"@ethereumjs/rlp@npm:^4.0.0, @ethereumjs/rlp@npm:^4.0.1": version: 4.0.1 resolution: "@ethereumjs/rlp@npm:4.0.1" bin: @@ -594,14 +535,14 @@ __metadata: languageName: node linkType: hard -"@ethereumjs/util@npm:^8.0.5": - version: 8.0.5 - resolution: "@ethereumjs/util@npm:8.0.5" +"@ethereumjs/util@npm:^8.0.0, @ethereumjs/util@npm:^8.0.5": + version: 8.1.0 + resolution: "@ethereumjs/util@npm:8.1.0" dependencies: - "@chainsafe/ssz": 0.9.4 "@ethereumjs/rlp": ^4.0.1 - ethereum-cryptography: ^1.1.2 - checksum: 318386785295b4584289b1aa576d2621392b3a918d127890db62d3f74184f3377694dd9e951e19bfb9ab80e8dc9e38e180236cac2651dead26097d10963731f9 + ethereum-cryptography: ^2.0.0 + micro-ftch: ^0.3.1 + checksum: 9ae5dee8f12b0faf81cd83f06a41560e79b0ba96a48262771d897a510ecae605eb6d84f687da001ab8ccffd50f612ae50f988ef76e6312c752897f462f3ac08d languageName: node linkType: hard @@ -1198,7 +1139,7 @@ __metadata: languageName: node linkType: hard -"@jridgewell/gen-mapping@npm:^0.3.0": +"@jridgewell/gen-mapping@npm:^0.3.0, @jridgewell/gen-mapping@npm:^0.3.2": version: 0.3.3 resolution: "@jridgewell/gen-mapping@npm:0.3.3" dependencies: @@ -1209,17 +1150,6 @@ __metadata: languageName: node linkType: hard -"@jridgewell/gen-mapping@npm:^0.3.2": - version: 0.3.2 - resolution: "@jridgewell/gen-mapping@npm:0.3.2" - dependencies: - "@jridgewell/set-array": ^1.0.1 - "@jridgewell/sourcemap-codec": ^1.4.10 - "@jridgewell/trace-mapping": ^0.3.9 - checksum: 1832707a1c476afebe4d0fbbd4b9434fdb51a4c3e009ab1e9938648e21b7a97049fa6009393bdf05cab7504108413441df26d8a3c12193996e65493a4efb6882 - languageName: node - linkType: hard - "@jridgewell/resolve-uri@npm:3.1.0, @jridgewell/resolve-uri@npm:^3.0.3": version: 3.1.0 resolution: "@jridgewell/resolve-uri@npm:3.1.0" @@ -1251,7 +1181,7 @@ __metadata: languageName: node linkType: hard -"@jridgewell/trace-mapping@npm:^0.3.12, @jridgewell/trace-mapping@npm:^0.3.13": +"@jridgewell/trace-mapping@npm:^0.3.12, @jridgewell/trace-mapping@npm:^0.3.13, @jridgewell/trace-mapping@npm:^0.3.17, @jridgewell/trace-mapping@npm:^0.3.9": version: 0.3.18 resolution: "@jridgewell/trace-mapping@npm:0.3.18" dependencies: @@ -1261,16 +1191,6 @@ __metadata: languageName: node linkType: hard -"@jridgewell/trace-mapping@npm:^0.3.17, @jridgewell/trace-mapping@npm:^0.3.9": - version: 0.3.17 - resolution: "@jridgewell/trace-mapping@npm:0.3.17" - dependencies: - "@jridgewell/resolve-uri": 3.1.0 - "@jridgewell/sourcemap-codec": 1.4.14 - checksum: 9d703b859cff5cd83b7308fd457a431387db5db96bd781a63bf48e183418dd9d3d44e76b9e4ae13237f6abeeb25d739ec9215c1d5bfdd08f66f750a50074a339 - languageName: node - linkType: hard - "@lavamoat/aa@npm:^3.1.1": version: 3.1.2 resolution: "@lavamoat/aa@npm:3.1.2" @@ -1449,7 +1369,9 @@ __metadata: resolution: "@metamask/eth-ledger-bridge-keyring@workspace:." dependencies: "@ethereumjs/common": ^3.1.1 + "@ethereumjs/rlp": ^4.0.0 "@ethereumjs/tx": ^4.1.1 + "@ethereumjs/util": ^8.0.0 "@lavamoat/allow-scripts": ^2.3.0 "@ledgerhq/hw-app-eth": ^6.32.0 "@metamask/auto-changelog": ^3.1.0 @@ -1476,7 +1398,6 @@ __metadata: eslint-plugin-prettier: ^4.2.1 eth-sig-util: ^2.0.0 ethereumjs-tx: ^1.3.4 - ethereumjs-util: ^7.0.9 hdkey: 0.8.0 jest: ^28.1.3 jest-it-up: ^2.2.0 @@ -1503,6 +1424,15 @@ __metadata: languageName: node linkType: hard +"@noble/curves@npm:1.1.0, @noble/curves@npm:~1.1.0": + version: 1.1.0 + resolution: "@noble/curves@npm:1.1.0" + dependencies: + "@noble/hashes": 1.3.1 + checksum: 2658cdd3f84f71079b4e3516c47559d22cf4b55c23ac8ee9d2b1f8e5b72916d9689e59820e0f9d9cb4a46a8423af5b56dc6bb7782405c88be06a015180508db5 + languageName: node + linkType: hard + "@noble/hashes@npm:1.2.0, @noble/hashes@npm:~1.2.0": version: 1.2.0 resolution: "@noble/hashes@npm:1.2.0" @@ -1510,6 +1440,20 @@ __metadata: languageName: node linkType: hard +"@noble/hashes@npm:1.3.1": + version: 1.3.1 + resolution: "@noble/hashes@npm:1.3.1" + checksum: 7fdefc0f7a0c1ec27acc6ff88841793e3f93ec4ce6b8a6a12bfc0dd70ae6b7c4c82fe305fdfeda1735d5ad4a9eebe761e6693b3d355689c559e91242f4bc95b1 + languageName: node + linkType: hard + +"@noble/hashes@npm:~1.3.0, @noble/hashes@npm:~1.3.1": + version: 1.3.2 + resolution: "@noble/hashes@npm:1.3.2" + checksum: fe23536b436539d13f90e4b9be843cc63b1b17666a07634a2b1259dded6f490be3d050249e6af98076ea8f2ea0d56f578773c2197f2aa0eeaa5fba5bc18ba474 + languageName: node + linkType: hard + "@noble/secp256k1@npm:1.7.1, @noble/secp256k1@npm:~1.7.0": version: 1.7.1 resolution: "@noble/secp256k1@npm:1.7.1" @@ -1624,6 +1568,17 @@ __metadata: languageName: node linkType: hard +"@scure/bip32@npm:1.3.1": + version: 1.3.1 + resolution: "@scure/bip32@npm:1.3.1" + dependencies: + "@noble/curves": ~1.1.0 + "@noble/hashes": ~1.3.1 + "@scure/base": ~1.1.0 + checksum: 394d65f77a40651eba21a5096da0f4233c3b50d422864751d373fcf142eeedb94a1149f9ab1dbb078086dab2d0bc27e2b1afec8321bf22d4403c7df2fea5bfe2 + languageName: node + linkType: hard + "@scure/bip39@npm:1.1.1": version: 1.1.1 resolution: "@scure/bip39@npm:1.1.1" @@ -1634,6 +1589,16 @@ __metadata: languageName: node linkType: hard +"@scure/bip39@npm:1.2.1": + version: 1.2.1 + resolution: "@scure/bip39@npm:1.2.1" + dependencies: + "@noble/hashes": ~1.3.0 + "@scure/base": ~1.1.0 + checksum: c5bd6f1328fdbeae2dcdd891825b1610225310e5e62a4942714db51066866e4f7bef242c7b06a1b9dcc8043a4a13412cf5c5df76d3b10aa9e36b82e9b6e3eeaa + languageName: node + linkType: hard + "@sinclair/typebox@npm:^0.24.1": version: 0.24.51 resolution: "@sinclair/typebox@npm:0.24.51" @@ -1735,7 +1700,7 @@ __metadata: languageName: node linkType: hard -"@types/bn.js@npm:*, @types/bn.js@npm:^5.1.0": +"@types/bn.js@npm:*": version: 5.1.1 resolution: "@types/bn.js@npm:5.1.1" dependencies: @@ -2682,7 +2647,7 @@ __metadata: languageName: node linkType: hard -"bn.js@npm:^5.1.2, bn.js@npm:^5.2.0, bn.js@npm:^5.2.1": +"bn.js@npm:^5.2.0, bn.js@npm:^5.2.1": version: 5.2.1 resolution: "bn.js@npm:5.2.1" checksum: 3dd8c8d38055fedfa95c1d5fc3c99f8dd547b36287b37768db0abab3c239711f88ff58d18d155dd8ad902b0b0cee973747b7ae20ea12a09473272b0201c9edd3 @@ -3959,6 +3924,18 @@ __metadata: languageName: node linkType: hard +"ethereum-cryptography@npm:^2.0.0": + version: 2.1.2 + resolution: "ethereum-cryptography@npm:2.1.2" + dependencies: + "@noble/curves": 1.1.0 + "@noble/hashes": 1.3.1 + "@scure/bip32": 1.3.1 + "@scure/bip39": 1.2.1 + checksum: 2e8f7b8cc90232ae838ab6a8167708e8362621404d26e79b5d9e762c7b53d699f7520aff358d9254de658fcd54d2d0af168ff909943259ed27dc4cef2736410c + languageName: node + linkType: hard + "ethereumjs-abi@npm:0.6.8": version: 0.6.8 resolution: "ethereumjs-abi@npm:0.6.8" @@ -4009,19 +3986,6 @@ __metadata: languageName: node linkType: hard -"ethereumjs-util@npm:^7.0.9": - version: 7.1.5 - resolution: "ethereumjs-util@npm:7.1.5" - dependencies: - "@types/bn.js": ^5.1.0 - bn.js: ^5.1.2 - create-hash: ^1.1.2 - ethereum-cryptography: ^0.1.3 - rlp: ^2.2.4 - checksum: 27a3c79d6e06b2df34b80d478ce465b371c8458b58f5afc14d91c8564c13363ad336e6e83f57eb0bd719fde94d10ee5697ceef78b5aa932087150c5287b286d1 - languageName: node - linkType: hard - "ethjs-util@npm:0.1.6, ethjs-util@npm:^0.1.3": version: 0.1.6 resolution: "ethjs-util@npm:0.1.6" @@ -6006,6 +5970,13 @@ __metadata: languageName: node linkType: hard +"micro-ftch@npm:^0.3.1": + version: 0.3.1 + resolution: "micro-ftch@npm:0.3.1" + checksum: 0e496547253a36e98a83fb00c628c53c3fb540fa5aaeaf718438873785afd193244988c09d219bb1802984ff227d04938d9571ef90fe82b48bd282262586aaff + languageName: node + linkType: hard + "micromatch@npm:^4.0.4": version: 4.0.5 resolution: "micromatch@npm:4.0.5" @@ -7039,7 +7010,7 @@ __metadata: languageName: node linkType: hard -"rlp@npm:^2.0.0, rlp@npm:^2.2.3, rlp@npm:^2.2.4": +"rlp@npm:^2.0.0, rlp@npm:^2.2.3": version: 2.2.7 resolution: "rlp@npm:2.2.7" dependencies: