diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index a0e2bf27..52da8143 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -52,7 +52,7 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v2 with: - version: 9 + version: 10 - name: Install dependencies run: pnpm install diff --git a/package.json b/package.json index 2cfc8dc6..ded571e0 100644 --- a/package.json +++ b/package.json @@ -73,8 +73,7 @@ "bn.js": "^5.2.1", "bs58check": "^4.0.0", "buffer": "^6.0.3", - "cbor": "^10.0.2", - "cbor-bigdecimal": "^10.0.2", + "cbor2": "1.12.0", "crc-32": "^1.2.2", "elliptic": "6.6.1", "hash.js": "^1.1.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 80cc68c8..379cdac8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,12 +44,9 @@ importers: buffer: specifier: ^6.0.3 version: 6.0.3 - cbor: - specifier: ^10.0.2 - version: 10.0.2 - cbor-bigdecimal: - specifier: ^10.0.2 - version: 10.0.2(bignumber.js@9.3.1) + cbor2: + specifier: 1.12.0 + version: 1.12.0 crc-32: specifier: ^1.2.2 version: 1.2.2 @@ -1575,15 +1572,9 @@ packages: resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} engines: {node: '>=6'} - cbor-bigdecimal@10.0.2: - resolution: {integrity: sha512-O/rckJeYt+6rBmFsG8D6YIOdZs+sJmbgFh+Y1ld4PAIzwn6iFcLgdo1/pG9hYpEXAuSe3HBbULzIDusKjD655Q==} - engines: {node: '>=18'} - peerDependencies: - bignumber.js: ^9.1.0 - - cbor@10.0.2: - resolution: {integrity: sha512-wJjyC0Efg8yUKpq9/+5SIcUbmBtyw+ZbvE8nNwbfGEKUkrL01h5CQ7h9/OPWtSt5oikmx6E5MuB5rTFz8zmMww==} - engines: {node: '>=18'} + cbor2@1.12.0: + resolution: {integrity: sha512-3Cco8XQhi27DogSp9Ri6LYNZLi/TBY/JVnDe+mj06NkBjW/ZYOtekaEU4wZ4xcRMNrFkDv8KNtOAqHyDfz3lYg==} + engines: {node: '>=18.7'} chai@5.1.1: resolution: {integrity: sha512-pT1ZgP8rPNqUgieVaEY+ryQr6Q4HXNg8Ei9UnLUrjN4IA7dvQC5JB+/kxVcPNDHyBcc/26CXPkbNzq3qwrOEKA==} @@ -2391,10 +2382,6 @@ packages: resolution: {integrity: sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==} hasBin: true - nofilter@3.1.0: - resolution: {integrity: sha512-l2NNj07e9afPnhAhvgVrCD/oy2Ai1yfLpuo3EpiO1jFTsB4sFz6oIfAfSZyQzVpkZQ9xS8ZS5g1jCBgq4Hwo0g==} - engines: {node: '>=12.19'} - object-assign@4.1.1: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'} @@ -4468,13 +4455,7 @@ snapshots: callsites@3.1.0: {} - cbor-bigdecimal@10.0.2(bignumber.js@9.3.1): - dependencies: - bignumber.js: 9.3.1 - - cbor@10.0.2: - dependencies: - nofilter: 3.1.0 + cbor2@1.12.0: {} chai@5.1.1: dependencies: @@ -5420,8 +5401,6 @@ snapshots: node-gyp-build@4.8.4: optional: true - nofilter@3.1.0: {} - object-assign@4.1.1: {} once@1.4.0: diff --git a/src/ethereum.ts b/src/ethereum.ts index 64483d63..503fee00 100644 --- a/src/ethereum.ts +++ b/src/ethereum.ts @@ -5,6 +5,21 @@ import { SignTypedDataVersion, TypedDataUtils } from '@metamask/eth-sig-util'; import { Hash } from 'ox'; import { RLP } from '@ethereumjs/rlp'; import * as secp256k1 from 'secp256k1'; +import * as cbor from 'cbor2'; +import { + TransactionSerializable, + serializeTransaction, + type Hex, + hexToNumber, +} from 'viem'; +import { + type SigningPath, + type FirmwareConstants, + TransactionRequest, + TRANSACTION_TYPE, +} from './types'; +import { buildGenericSigningMsgRequest } from './genericSigning'; +import { TransactionSchema, type FlexibleTransaction } from './schemas'; import { ASCII_REGEX, HANDLE_LARGER_CHAIN_ID, @@ -21,26 +36,8 @@ import { splitFrames, convertRecoveryToV, } from './util'; -import * as cbor from 'cbor'; -import bdec from 'cbor-bigdecimal'; -import { - TransactionSerializable, - serializeTransaction, - type Hex, - hexToNumber, -} from 'viem'; -import { - type SigningPath, - type FirmwareConstants, - TransactionRequest, - TRANSACTION_TYPE, -} from './types'; -import { buildGenericSigningMsgRequest } from './genericSigning'; -import { TransactionSchema, type FlexibleTransaction } from './schemas'; - -bdec(cbor); -const buildEthereumMsgRequest = function (input) { +const buildEthereumMsgRequest = (input) => { if (!input.payload || !input.protocol || !input.signerPath) throw new Error( 'You must provide `payload`, `signerPath`, and `protocol` arguments in the messsage request', @@ -67,7 +64,7 @@ const buildEthereumMsgRequest = function (input) { } }; -const validateEthereumMsgResponse = function (res, req) { +const validateEthereumMsgResponse = (res, req) => { const { signer, sig } = res; const { input, msg, prehash = null } = req; if (input.protocol === 'signPersonal') { @@ -181,7 +178,7 @@ function normalizeTypedDataForHashing(value: any): any { return value; } -const buildEthereumTxRequest = function (data) { +const buildEthereumTxRequest = (data) => { try { let { chainId = 1 } = data; const { signerPath, eip155 = null, fwConstants, type = null } = data; @@ -497,7 +494,7 @@ function stripZeros(a) { // Given a 64-byte signature [r,s] we need to figure out the v value // and attah the full signature to the end of the transaction payload -const buildEthRawTx = function (tx, sig, address) { +const buildEthRawTx = (tx, sig, address) => { // RLP-encode the data we sent to the lattice const hash = Buffer.from( Hash.keccak256(get_rlp_encoded_preimage(tx.rawTx, tx.type)), @@ -1024,7 +1021,7 @@ function parseEIP712Item(data, type, forJSParser = false) { } } else if (type.slice(0, 5) === 'bytes') { // Fixed sizes bytes need to be buffer type. We also add some sanity checks. - const nBytes = parseInt(type.slice(5)); + const nBytes = Number.parseInt(type.slice(5)); data = ensureHexBuffer(data); // Edge case to handle empty bytesN values if (data.length === 0) {