From 214b2ffa014cdc3a0a793d66b5f88375841df838 Mon Sep 17 00:00:00 2001 From: netbonus <151201453+netbonus@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:12:22 -0500 Subject: [PATCH] swaps cbor lib for bignumber handling (#582) --- package.json | 3 ++- pnpm-lock.yaml | 66 ++++++++++++++++++++++++------------------------- src/ethereum.ts | 4 ++- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index 445a77db..899fd257 100644 --- a/package.json +++ b/package.json @@ -60,9 +60,10 @@ "bignumber.js": "^9.1.2", "bitwise": "^2.2.1", "bn.js": "^5.2.1", - "borc": "^3.0.0", "bs58check": "^4.0.0", "buffer": "^6.0.3", + "cbor": "^10.0.2", + "cbor-bigdecimal": "^10.0.2", "crc-32": "^1.2.2", "elliptic": "6.5.7", "hash.js": "^1.1.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1ffd574b..5c8b0089 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -43,15 +43,18 @@ dependencies: bn.js: specifier: ^5.2.1 version: 5.2.1 - borc: - specifier: ^3.0.0 - version: 3.0.0 bs58check: specifier: ^4.0.0 version: 4.0.0 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.1.2) crc-32: specifier: ^1.2.2 version: 1.2.2 @@ -1430,11 +1433,6 @@ packages: - utf-8-validate dev: true - /@sovpro/delimited-stream@1.1.0: - resolution: {integrity: sha512-kQpk267uxB19X3X2T1mvNMjyvIEonpNSHrMlK5ZaBU6aZxw7wPbpgKJOjHN3+/GPVpXgAV9soVT2oyHpLkLtyw==} - engines: {node: '>= 8'} - dev: false - /@swc/helpers@0.5.13: resolution: {integrity: sha512-UoKGxQ3r5kYI9dALKJapMmuK+1zWM/H17Z1+iwnNmzcJRnfFuevZs375TA5rW31pu4BS4NoSy1fRsexDXfWn5w==} dependencies: @@ -2252,20 +2250,6 @@ packages: /bn.js@5.2.1: resolution: {integrity: sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==} - /borc@3.0.0: - resolution: {integrity: sha512-ec4JmVC46kE0+layfnwM3l15O70MlFiEbmQHY/vpqIKiUtPVntv4BY4NVnz3N4vb21edV3mY97XVckFvYHWF9g==} - engines: {node: '>=4'} - hasBin: true - dependencies: - bignumber.js: 9.1.2 - buffer: 6.0.3 - commander: 2.20.3 - ieee754: 1.2.1 - iso-url: 1.2.1 - json-text-sequence: 0.3.0 - readable-stream: 3.6.2 - dev: false - /borsh@0.7.0: resolution: {integrity: sha512-CLCsZGIBCFnPtkNnieW/a8wmreDmfUtjU2m9yHrzPXIlNbqVs0AQrSatSG6vdNYUqdc83tkQi2eHfF98ubzQLA==} dependencies: @@ -2390,6 +2374,22 @@ packages: engines: {node: '>=6'} dev: true + /cbor-bigdecimal@10.0.2(bignumber.js@9.1.2): + resolution: {integrity: sha512-O/rckJeYt+6rBmFsG8D6YIOdZs+sJmbgFh+Y1ld4PAIzwn6iFcLgdo1/pG9hYpEXAuSe3HBbULzIDusKjD655Q==} + engines: {node: '>=18'} + peerDependencies: + bignumber.js: ^9.1.0 + dependencies: + bignumber.js: 9.1.2 + dev: false + + /cbor@10.0.2: + resolution: {integrity: sha512-wJjyC0Efg8yUKpq9/+5SIcUbmBtyw+ZbvE8nNwbfGEKUkrL01h5CQ7h9/OPWtSt5oikmx6E5MuB5rTFz8zmMww==} + engines: {node: '>=18'} + dependencies: + nofilter: 3.1.0 + dev: false + /chai@5.1.1: resolution: {integrity: sha512-pT1ZgP8rPNqUgieVaEY+ryQr6Q4HXNg8Ei9UnLUrjN4IA7dvQC5JB+/kxVcPNDHyBcc/26CXPkbNzq3qwrOEKA==} engines: {node: '>=12'} @@ -2490,6 +2490,7 @@ packages: /commander@2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} + dev: true /common-tags@1.8.2: resolution: {integrity: sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==} @@ -3428,11 +3429,6 @@ packages: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} dev: true - /iso-url@1.2.1: - resolution: {integrity: sha512-9JPDgCN4B7QPkLtYAAOrEuAWvP9rWvR5offAr0/SeF046wIkglqH3VXgYYP6NcsKslH80UIVgmPqNe3j7tG2ng==} - engines: {node: '>=12'} - dev: false - /isomorphic-ws@4.0.1(ws@7.5.10): resolution: {integrity: sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w==} peerDependencies: @@ -3597,13 +3593,6 @@ packages: resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==} dev: true - /json-text-sequence@0.3.0: - resolution: {integrity: sha512-7khKIYPKwXQem4lWXfpIN/FEnhztCeRPSxH4qm3fVlqulwujrRDD54xAwDDn/qVKpFtV550+QAkcWJcufzqQuA==} - engines: {node: '>=10.18.0'} - dependencies: - '@sovpro/delimited-stream': 1.1.0 - dev: false - /jsonc@2.0.0: resolution: {integrity: sha512-B281bLCT2TRMQa+AQUQY5AGcqSOXBOKaYGP4wDzoA/+QswUfN8sODektbPEs9Baq7LGKun5jQbNFpzwGuVYKhw==} engines: {node: '>=8'} @@ -3914,6 +3903,11 @@ packages: resolution: {integrity: sha512-IRUxE4BVsHWXkV/SFOut4qTlagw2aM8T5/vnTsmrHJvVoKueJHRc/JaFND7QDDc61kLYUJ6qlZM3sqTSyx2dTw==} hasBin: true + /nofilter@3.1.0: + resolution: {integrity: sha512-l2NNj07e9afPnhAhvgVrCD/oy2Ai1yfLpuo3EpiO1jFTsB4sFz6oIfAfSZyQzVpkZQ9xS8ZS5g1jCBgq4Hwo0g==} + engines: {node: '>=12.19'} + dev: false + /once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} dependencies: @@ -4181,6 +4175,7 @@ packages: inherits: 2.0.4 string_decoder: 1.3.0 util-deprecate: 1.0.2 + dev: true /readline-sync@1.4.10: resolution: {integrity: sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==} @@ -4299,6 +4294,7 @@ packages: /safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + dev: true /scrypt-js@3.0.1: resolution: {integrity: sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==} @@ -4444,6 +4440,7 @@ packages: resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} dependencies: safe-buffer: 5.2.1 + dev: true /strip-ansi@3.0.1: resolution: {integrity: sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg==} @@ -4706,6 +4703,7 @@ packages: /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + dev: true /uuid@10.0.0: resolution: {integrity: sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==} diff --git a/src/ethereum.ts b/src/ethereum.ts index 52f50746..1eb7d55b 100644 --- a/src/ethereum.ts +++ b/src/ethereum.ts @@ -3,7 +3,6 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common'; import { TransactionFactory } from '@ethereumjs/tx'; import BN from 'bignumber.js'; -import cbor from 'borc'; import { SignTypedDataVersion, TypedDataUtils } from '@metamask/eth-sig-util'; import { keccak256 } from 'js-sha3'; import { RLP } from '@ethereumjs/rlp'; @@ -22,6 +21,9 @@ import { isAsciiStr, splitFrames, } from './util'; +import cbor from 'cbor'; +import bdec from 'cbor-bigdecimal'; +bdec(cbor); const buildEthereumMsgRequest = function (input) { if (!input.payload || !input.protocol || !input.signerPath)