diff --git a/.depcheckrc.json b/.depcheckrc.json index d77df4e8..00cf1cba 100644 --- a/.depcheckrc.json +++ b/.depcheckrc.json @@ -1,6 +1,7 @@ { "ignores": [ "@lavamoat/allow-scripts", + "@ledgerhq/types-cryptoassets", "@metamask/auto-changelog", "@types/*", "prettier-plugin-packagejson", 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 12b63851..3646b0f3 100644 --- a/package.json +++ b/package.json @@ -37,16 +37,18 @@ "test:watch": "jest --watch" }, "dependencies": { + "@ethereumjs/rlp": "^4.0.0", "@ethereumjs/tx": "^4.1.1", - "@metamask/utils": "^5.0.0", + "@ethereumjs/util": "^8.0.0", + "@metamask/utils": "^5.0.2", "eth-sig-util": "^2.0.0", - "ethereumjs-util": "^7.0.9", "hdkey": "0.8.0" }, "devDependencies": { "@ethereumjs/common": "^3.1.1", "@lavamoat/allow-scripts": "^2.3.0", "@ledgerhq/hw-app-eth": "^6.32.0", + "@ledgerhq/types-cryptoassets": "^7.6.0", "@metamask/auto-changelog": "^3.1.0", "@metamask/eslint-config": "^11.0.1", "@metamask/eslint-config-browser": "^11.0.0", @@ -90,10 +92,11 @@ "lavamoat": { "allowScripts": { "@lavamoat/preinstall-always-fail": false, + "hdkey>secp256k1": false, "@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false, - "ethereumjs-util>ethereum-cryptography>keccak": false, - "ethereumjs-util>ethereum-cryptography>secp256k1": false, - "hdkey>secp256k1": false + "eth-sig-util>ethereumjs-abi>ethereumjs-util>ethereum-cryptography>keccak": false, + "eth-sig-util>ethereumjs-util>ethereum-cryptography>keccak": false, + "eth-sig-util>ethereumjs-util>ethereum-cryptography>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 43ad117a..25b6186d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -507,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: @@ -534,15 +534,14 @@ __metadata: languageName: node linkType: hard -"@ethereumjs/util@npm:^8.0.6": - version: 8.0.6 - resolution: "@ethereumjs/util@npm:8.0.6" +"@ethereumjs/util@npm:^8.0.0, @ethereumjs/util@npm:^8.0.6": + version: 8.1.0 + resolution: "@ethereumjs/util@npm:8.1.0" dependencies: - "@chainsafe/ssz": ^0.11.1 "@ethereumjs/rlp": ^4.0.1 ethereum-cryptography: ^2.0.0 micro-ftch: ^0.3.1 - checksum: 034e06cddec27417318434a1a7cd7a9dc0f0b447c1f54423c515d8809c9697386eee6429d0a1c13517a85c696e6fdba570b243d882e65764c274859606027015 + checksum: 9ae5dee8f12b0faf81cd83f06a41560e79b0ba96a48262771d897a510ecae605eb6d84f687da001ab8ccffd50f612ae50f988ef76e6312c752897f462f3ac08d languageName: node linkType: hard @@ -1249,6 +1248,13 @@ __metadata: languageName: node linkType: hard +"@ledgerhq/types-cryptoassets@npm:^7.6.0": + version: 7.6.0 + resolution: "@ledgerhq/types-cryptoassets@npm:7.6.0" + checksum: a55b0bfaf6b5178259f79a0fd893b251ab57b7c31c64f84ec451976dcd4ca0a7b0f8f442429e4692018cce395116bdb55edefc312069fd1a43cd3f06f319b300 + languageName: node + linkType: hard + "@ledgerhq/types-live@npm:^6.32.1": version: 6.32.1 resolution: "@ledgerhq/types-live@npm:6.32.1" @@ -1337,16 +1343,19 @@ __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 "@metamask/auto-changelog": ^3.1.0 "@metamask/eslint-config": ^11.0.1 "@metamask/eslint-config-browser": ^11.0.0 "@metamask/eslint-config-jest": ^11.0.0 "@metamask/eslint-config-nodejs": ^11.0.0 "@metamask/eslint-config-typescript": ^11.0.0 - "@metamask/utils": ^5.0.0 + "@metamask/utils": ^5.0.2 "@types/eth-sig-util": ^2.1.1 "@types/ethereumjs-tx": ^1.0.1 "@types/hdkey": ^2.0.1 @@ -1364,7 +1373,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 @@ -1378,7 +1386,7 @@ __metadata: languageName: unknown linkType: soft -"@metamask/utils@npm:^5.0.0": +"@metamask/utils@npm:^5.0.2": version: 5.0.2 resolution: "@metamask/utils@npm:5.0.2" dependencies: @@ -1625,7 +1633,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: @@ -2567,7 +2575,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 @@ -3896,19 +3904,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" @@ -6987,7 +6982,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: