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 77e65157..d6a6bea0 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/eth-sig-util": "^6.0.1", "@metamask/utils": "^5.0.0", - "ethereumjs-util": "^7.0.9", "hdkey": "0.8.0" }, "devDependencies": { @@ -91,11 +92,9 @@ "lavamoat": { "allowScripts": { "@lavamoat/preinstall-always-fail": false, + "@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false, "ethereumjs-tx>ethereumjs-util>keccak": false, - "ethereumjs-util>ethereum-cryptography>keccak": false, - "ethereumjs-util>ethereum-cryptography>secp256k1": false, - "hdkey>secp256k1": false, - "@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false + "hdkey>secp256k1": false } } } diff --git a/src/ledger-keyring.test.ts b/src/ledger-keyring.test.ts index edc2e6c5..f457001f 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 * as sigUtil from '@metamask/eth-sig-util'; import EthereumTx from 'ethereumjs-tx'; -import * as ethUtil from 'ethereumjs-util'; import HDKey from 'hdkey'; import { LedgerBridge } from './ledger-bridge'; @@ -544,9 +545,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 3fc83067..77392c5b 100644 --- a/src/ledger-keyring.ts +++ b/src/ledger-keyring.ts @@ -1,4 +1,6 @@ +import { RLP } from '@ethereumjs/rlp'; import { TransactionFactory, TxData, TypedTransaction } from '@ethereumjs/tx'; +import * as ethUtil from '@ethereumjs/util'; import type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util'; import { recoverPersonalSignature, @@ -9,7 +11,6 @@ import { // eslint-disable-next-line import/no-nodejs-modules import { Buffer } from 'buffer'; 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'; @@ -339,7 +340,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 fdec29d6..a00e81ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -523,7 +523,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: @@ -544,7 +544,7 @@ __metadata: languageName: node linkType: hard -"@ethereumjs/util@npm:^8.1.0": +"@ethereumjs/util@npm:^8.0.0, @ethereumjs/util@npm:^8.1.0": version: 8.1.0 resolution: "@ethereumjs/util@npm:8.1.0" dependencies: @@ -1616,7 +1616,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 "@ledgerhq/types-cryptoassets": ^7.6.0 @@ -1644,7 +1646,6 @@ __metadata: eslint-plugin-node: ^11.1.0 eslint-plugin-prettier: ^4.2.1 ethereumjs-tx: ^1.3.4 - ethereumjs-util: ^7.0.9 hdkey: 0.8.0 jest: ^28.1.3 jest-it-up: ^2.2.0 @@ -1945,15 +1946,6 @@ __metadata: languageName: node linkType: hard -"@types/bn.js@npm:^5.1.0": - version: 5.1.0 - resolution: "@types/bn.js@npm:5.1.0" - dependencies: - "@types/node": "*" - checksum: 1dc1cbbd7a1e8bf3614752e9602f558762a901031f499f3055828b5e3e2bba16e5b88c27b3c4152ad795248fbe4086c731a5c4b0f29bb243f1875beeeabee59c - languageName: node - linkType: hard - "@types/color-name@npm:^1.1.1": version: 1.1.1 resolution: "@types/color-name@npm:1.1.1" @@ -2089,15 +2081,6 @@ __metadata: languageName: node linkType: hard -"@types/pbkdf2@npm:^3.0.0": - version: 3.1.0 - resolution: "@types/pbkdf2@npm:3.1.0" - dependencies: - "@types/node": "*" - checksum: d15024b1957c21cf3b8887329d9bd8dfde754cf13a09d76ae25f1391cfc62bb8b8d7b760773c5dbaa748172fba8b3e0c3dbe962af6ccbd69b76df12a48dfba40 - languageName: node - linkType: hard - "@types/prettier@npm:^2.1.5": version: 2.7.3 resolution: "@types/prettier@npm:2.7.3" @@ -2105,15 +2088,6 @@ __metadata: languageName: node linkType: hard -"@types/secp256k1@npm:^4.0.1": - version: 4.0.1 - resolution: "@types/secp256k1@npm:4.0.1" - dependencies: - "@types/node": "*" - checksum: f89b71360e3fe5a02f649746832fc7af4c5c5b8f85897a2e74d5df40f2e02e4c3b8cca5c7c9b92282870bf03724ce142f817d5d07f5acf2f1c5769ab7403e65a - languageName: node - linkType: hard - "@types/semver@npm:^7.3.12": version: 7.5.3 resolution: "@types/semver@npm:7.5.3" @@ -2763,15 +2737,6 @@ __metadata: languageName: node linkType: hard -"base-x@npm:^3.0.2": - version: 3.0.8 - resolution: "base-x@npm:3.0.8" - dependencies: - safe-buffer: ^5.0.1 - checksum: 92b95493e636999d6505d9c5abfa049fce1bdde9327f733c5984e712cdb98482d2d45410e4ac1d04e5a004545e46898674f405db04c9555ba3e35fc00b150bf4 - languageName: node - linkType: hard - "bech32@npm:1.1.4": version: 1.1.4 resolution: "bech32@npm:1.1.4" @@ -2823,13 +2788,6 @@ __metadata: languageName: node linkType: hard -"blakejs@npm:^1.1.0": - version: 1.1.0 - resolution: "blakejs@npm:1.1.0" - checksum: 69df62aee27e30ff2af8d709dd4676e037f2e92ded09b0d1a8187d1a69edaf05f4e63f3f473a0e44576e517196e54193641eec345bcc505c8a221940ec491141 - languageName: node - linkType: hard - "bn.js@npm:^4.11.0, bn.js@npm:^4.11.1, bn.js@npm:^4.11.8, bn.js@npm:^4.11.9": version: 4.12.0 resolution: "bn.js@npm:4.12.0" @@ -2837,13 +2795,6 @@ __metadata: languageName: node linkType: hard -"bn.js@npm:^5.1.2": - version: 5.2.0 - resolution: "bn.js@npm:5.2.0" - checksum: 6117170393200f68b35a061ecbf55d01dd989302e7b3c798a3012354fa638d124f0b2f79e63f77be5556be80322a09c40339eda6413ba7468524c0b6d4b4cb7a - languageName: node - linkType: hard - "bn.js@npm:^5.2.1": version: 5.2.1 resolution: "bn.js@npm:5.2.1" @@ -2895,7 +2846,7 @@ __metadata: languageName: node linkType: hard -"browserify-aes@npm:^1.0.6, browserify-aes@npm:^1.2.0": +"browserify-aes@npm:^1.0.6": version: 1.2.0 resolution: "browserify-aes@npm:1.2.0" dependencies: @@ -2939,26 +2890,6 @@ __metadata: languageName: node linkType: hard -"bs58@npm:^4.0.0": - version: 4.0.1 - resolution: "bs58@npm:4.0.1" - dependencies: - base-x: ^3.0.2 - checksum: b3c5365bb9e0c561e1a82f1a2d809a1a692059fae016be233a6127ad2f50a6b986467c3a50669ce4c18929dcccb297c5909314dd347a25a68c21b68eb3e95ac2 - languageName: node - linkType: hard - -"bs58check@npm:^2.1.2": - version: 2.1.2 - resolution: "bs58check@npm:2.1.2" - dependencies: - bs58: ^4.0.0 - create-hash: ^1.1.0 - safe-buffer: ^5.1.2 - checksum: 43bdf08a5dd04581b78f040bc4169480e17008da482ffe2a6507327bbc4fc5c28de0501f7faf22901cfe57fbca79cbb202ca529003fedb4cb8dccd265b38e54d - languageName: node - linkType: hard - "bser@npm:2.1.1": version: 2.1.1 resolution: "bser@npm:2.1.1" @@ -3319,7 +3250,7 @@ __metadata: languageName: node linkType: hard -"create-hmac@npm:^1.1.4, create-hmac@npm:^1.1.7": +"create-hmac@npm:^1.1.4": version: 1.1.7 resolution: "create-hmac@npm:1.1.7" dependencies: @@ -4110,29 +4041,6 @@ __metadata: languageName: node linkType: hard -"ethereum-cryptography@npm:^0.1.3": - version: 0.1.3 - resolution: "ethereum-cryptography@npm:0.1.3" - dependencies: - "@types/pbkdf2": ^3.0.0 - "@types/secp256k1": ^4.0.1 - blakejs: ^1.1.0 - browserify-aes: ^1.2.0 - bs58check: ^2.1.2 - create-hash: ^1.2.0 - create-hmac: ^1.1.7 - hash.js: ^1.1.7 - keccak: ^3.0.0 - pbkdf2: ^3.0.17 - randombytes: ^2.1.0 - safe-buffer: ^5.1.2 - scrypt-js: ^3.0.0 - secp256k1: ^4.0.1 - setimmediate: ^1.0.5 - checksum: 54bae7a4a96bd81398cdc35c91cfcc74339f71a95ed1b5b694663782e69e8e3afd21357de3b8bac9ff4877fd6f043601e200a7ad9133d94be6fd7d898ee0a449 - languageName: node - linkType: hard - "ethereum-cryptography@npm:^2.0.0, ethereum-cryptography@npm:^2.1.2": version: 2.1.2 resolution: "ethereum-cryptography@npm:2.1.2" @@ -4170,20 +4078,6 @@ __metadata: languageName: node linkType: hard -"ethereumjs-util@npm:^7.0.9": - version: 7.0.9 - resolution: "ethereumjs-util@npm:7.0.9" - dependencies: - "@types/bn.js": ^5.1.0 - bn.js: ^5.1.2 - create-hash: ^1.1.2 - ethereum-cryptography: ^0.1.3 - ethjs-util: 0.1.6 - rlp: ^2.2.4 - checksum: 112da2a62d2722177c8b6bd4ffeac5961715cb7a06346996784e0ad4e1bb9178c6cf825e3552980ea1ebd4e0ef4855dc188f2b164364784c8aef7452f1bd02e2 - languageName: node - linkType: hard - "ethers@npm:5.7.2": version: 5.7.2 resolution: "ethers@npm:5.7.2" @@ -4222,7 +4116,7 @@ __metadata: languageName: node linkType: hard -"ethjs-util@npm:0.1.6, ethjs-util@npm:^0.1.3, ethjs-util@npm:^0.1.6": +"ethjs-util@npm:^0.1.3, ethjs-util@npm:^0.1.6": version: 0.1.6 resolution: "ethjs-util@npm:0.1.6" dependencies: @@ -4916,7 +4810,7 @@ __metadata: languageName: node linkType: hard -"hash.js@npm:1.1.7, hash.js@npm:^1.0.0, hash.js@npm:^1.0.3, hash.js@npm:^1.1.7": +"hash.js@npm:1.1.7, hash.js@npm:^1.0.0, hash.js@npm:^1.0.3": version: 1.1.7 resolution: "hash.js@npm:1.1.7" dependencies: @@ -6076,17 +5970,6 @@ __metadata: languageName: node linkType: hard -"keccak@npm:^3.0.0": - version: 3.0.1 - resolution: "keccak@npm:3.0.1" - dependencies: - node-addon-api: ^2.0.0 - node-gyp: latest - node-gyp-build: ^4.2.0 - checksum: 1de1b62fbb3e035ee186232b11f154bd5c2c12a2d910bc8ec313dab412b6f39ddc51d3a105618dd8de752875da0ead21abb0eb1d4e7d7b17771a4acbb7159390 - languageName: node - linkType: hard - "keccak@npm:^3.0.3": version: 3.0.4 resolution: "keccak@npm:3.0.4" @@ -6974,19 +6857,6 @@ __metadata: languageName: node linkType: hard -"pbkdf2@npm:^3.0.17": - version: 3.1.1 - resolution: "pbkdf2@npm:3.1.1" - dependencies: - create-hash: ^1.1.2 - create-hmac: ^1.1.4 - ripemd160: ^2.0.1 - safe-buffer: ^5.0.1 - sha.js: ^2.4.8 - checksum: c3de26b8eb363180687e31138e1a486c509d407f361ae222e0af4748d9a252326e14e8f3311182945dbc27e7f235b49fb7a578ad340302a83481585bbd3947d3 - languageName: node - linkType: hard - "picocolors@npm:^1.0.0": version: 1.0.0 resolution: "picocolors@npm:1.0.0" @@ -7139,15 +7009,6 @@ __metadata: languageName: node linkType: hard -"randombytes@npm:^2.1.0": - version: 2.1.0 - resolution: "randombytes@npm:2.1.0" - dependencies: - safe-buffer: ^5.1.0 - checksum: d779499376bd4cbb435ef3ab9a957006c8682f343f14089ed5f27764e4645114196e75b7f6abf1cbd84fd247c0cb0651698444df8c9bf30e62120fbbc52269d6 - languageName: node - linkType: hard - "react-dom@npm:^17.0.2": version: 17.0.2 resolution: "react-dom@npm:17.0.2" @@ -7370,17 +7231,6 @@ __metadata: languageName: node linkType: hard -"rlp@npm:^2.2.4": - version: 2.2.6 - resolution: "rlp@npm:2.2.6" - dependencies: - bn.js: ^4.11.1 - bin: - rlp: bin/rlp - checksum: 2601225df0fe7aa3b497b33a12fd9fbaf8fb1d2989ecc5c091918ed93ee77d1c3fab20ddd3891a9ca66a8ba66d993e6079be6fb31f450fcf38ba30873102ca46 - languageName: node - linkType: hard - "run-applescript@npm:^5.0.0": version: 5.0.0 resolution: "run-applescript@npm:5.0.0" @@ -7469,7 +7319,7 @@ __metadata: languageName: node linkType: hard -"scrypt-js@npm:3.0.1, scrypt-js@npm:^3.0.0": +"scrypt-js@npm:3.0.1": version: 3.0.1 resolution: "scrypt-js@npm:3.0.1" checksum: b7c7d1a68d6ca946f2fbb0778e0c4ec63c65501b54023b2af7d7e9f48fdb6c6580d6f7675cd53bda5944c5ebc057560d5a6365079752546865defb3b79dea454 @@ -7493,18 +7343,6 @@ __metadata: languageName: node linkType: hard -"secp256k1@npm:^4.0.1": - version: 4.0.2 - resolution: "secp256k1@npm:4.0.2" - dependencies: - elliptic: ^6.5.2 - node-addon-api: ^2.0.0 - node-gyp: latest - node-gyp-build: ^4.2.0 - checksum: 0d0d42e8033aee5aec5caaaa26d90fcaec4bf5e24dc4652552ddaa60734c2d95e90f7d95697b521fe833363c629d5ff623227961de86686c7a0ed5b5ffc1ebd0 - languageName: node - linkType: hard - "semver-compare@npm:^1.0.0": version: 1.0.0 resolution: "semver-compare@npm:1.0.0" @@ -7550,13 +7388,6 @@ __metadata: languageName: node linkType: hard -"setimmediate@npm:^1.0.5": - version: 1.0.5 - resolution: "setimmediate@npm:1.0.5" - checksum: c9a6f2c5b51a2dabdc0247db9c46460152ffc62ee139f3157440bd48e7c59425093f42719ac1d7931f054f153e2d26cf37dfeb8da17a794a58198a2705e527fd - languageName: node - linkType: hard - "sha.js@npm:^2.4.0, sha.js@npm:^2.4.8": version: 2.4.11 resolution: "sha.js@npm:2.4.11"