From b2fbb232f91fbbffc5feb8d36b80cf763c124d17 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Fri, 14 Apr 2023 11:46:49 +0000 Subject: [PATCH] Update ethereum-cryptography from 1.2 to 2.0 --- package-lock.json | 172 ++++++++++++++--------------- packages/block/package.json | 2 +- packages/blockchain/package.json | 2 +- packages/client/package.json | 2 +- packages/devp2p/package.json | 2 +- packages/devp2p/src/dpt/dpt.ts | 4 +- packages/devp2p/src/rlpx/ecies.ts | 6 +- packages/devp2p/src/rlpx/rlpx.ts | 4 +- packages/devp2p/src/util.ts | 6 +- packages/ethash/package.json | 2 +- packages/evm/package.json | 2 +- packages/statemanager/package.json | 4 +- packages/trie/package.json | 2 +- packages/tx/package.json | 2 +- packages/util/package.json | 2 +- packages/util/src/account.ts | 16 +-- packages/util/src/constants.ts | 6 +- packages/util/src/signature.ts | 19 ++-- packages/vm/package.json | 2 +- 19 files changed, 129 insertions(+), 128 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3ee55b0781..07dd057513 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1770,17 +1770,6 @@ "@noble/hashes": "^1.3.0" } }, - "node_modules/@chainsafe/persistent-merkle-tree/node_modules/@noble/hashes": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz", - "integrity": "sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] - }, "node_modules/@chainsafe/ssz": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@chainsafe/ssz/-/ssz-0.11.0.tgz", @@ -2806,6 +2795,20 @@ "version": "4.0.1", "license": "MIT" }, + "node_modules/@noble/curves": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.0.0.tgz", + "integrity": "sha512-2upgEu0iLiDVDZkNLeFV2+ht0BAVgQnEmCk6JsOch9Rp8xfkMCbvbAZlA2pBHQc73dbl+vFOXfqkf4uemdn0bw==", + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "dependencies": { + "@noble/hashes": "1.3.0" + } + }, "node_modules/@noble/ed25519": { "version": "1.7.1", "funding": [ @@ -2817,14 +2820,15 @@ "license": "MIT" }, "node_modules/@noble/hashes": { - "version": "1.1.2", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz", + "integrity": "sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==", "funding": [ { "type": "individual", "url": "https://paulmillr.com/funding/" } - ], - "license": "MIT" + ] }, "node_modules/@noble/secp256k1": { "version": "1.6.3", @@ -2923,31 +2927,33 @@ "license": "MIT" }, "node_modules/@scure/bip32": { - "version": "1.1.0", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.3.0.tgz", + "integrity": "sha512-bcKpo1oj54hGholplGLpqPHRbIsnbixFtc06nwuNM5/dwSXOq/AAYoIBRsBmnZJSdfeNW5rnff7NTAz3ZCqR9Q==", "funding": [ { "type": "individual", "url": "https://paulmillr.com/funding/" } ], - "license": "MIT", "dependencies": { - "@noble/hashes": "~1.1.1", - "@noble/secp256k1": "~1.6.0", + "@noble/curves": "~1.0.0", + "@noble/hashes": "~1.3.0", "@scure/base": "~1.1.0" } }, "node_modules/@scure/bip39": { - "version": "1.1.0", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.0.tgz", + "integrity": "sha512-SX/uKq52cuxm4YFXWFaVByaSHJh2w3BnokVSeUJVCv6K7WulT9u2BuNRBhuFl8vAuYnzx9bEu9WgpcNYTrYieg==", "funding": [ { "type": "individual", "url": "https://paulmillr.com/funding/" } ], - "license": "MIT", "dependencies": { - "@noble/hashes": "~1.1.1", + "@noble/hashes": "~1.3.0", "@scure/base": "~1.1.0" } }, @@ -5532,14 +5538,6 @@ "dev": true, "license": "MIT" }, - "node_modules/cross-fetch": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", - "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", - "dependencies": { - "node-fetch": "2.6.7" - } - }, "node_modules/cross-spawn": { "version": "7.0.3", "license": "MIT", @@ -7186,13 +7184,14 @@ } }, "node_modules/ethereum-cryptography": { - "version": "1.1.2", - "license": "MIT", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-2.0.0.tgz", + "integrity": "sha512-g25m4EtfQGjstWgVE1aIz7XYYjf3kH5kG17ULWVB5dH6uLahsoltOhACzSxyDV+fhn4gbR4xRrOXGe6r2uh4Bg==", "dependencies": { - "@noble/hashes": "1.1.2", - "@noble/secp256k1": "1.6.3", - "@scure/bip32": "1.1.0", - "@scure/bip39": "1.1.0" + "@noble/curves": "1.0.0", + "@noble/hashes": "1.3.0", + "@scure/bip32": "1.3.0", + "@scure/bip39": "1.2.0" } }, "node_modules/ethers": { @@ -17833,7 +17832,7 @@ "@ethereumjs/trie": "^5.0.4", "@ethereumjs/tx": "^4.1.1", "@ethereumjs/util": "^8.0.5", - "ethereum-cryptography": "^1.1.2" + "ethereum-cryptography": "^2.0.0" }, "devDependencies": { "@types/lru-cache": "^5.1.0", @@ -17858,7 +17857,7 @@ "@ethereumjs/util": "^8.0.5", "abstract-level": "^1.0.3", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "level": "^8.0.0", "lru-cache": "^5.1.1", "memory-level": "^1.0.0" @@ -17898,7 +17897,7 @@ "connect": "^3.7.0", "cors": "^2.8.5", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "fs-extra": "^10.1.0", "it-pipe": "^1.1.0", "jayson": "^4.0.0", @@ -18029,7 +18028,7 @@ "@types/lru-cache": "^5.1.0", "bl": "^1.1.2", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "ip": "^1.1.3", "k-bucket": "^5.0.0", "lru-cache": "^5.1.1", @@ -18118,7 +18117,7 @@ "@ethereumjs/util": "^8.0.5", "abstract-level": "^1.0.3", "bigint-crypto-utils": "^3.0.23", - "ethereum-cryptography": "^1.1.2" + "ethereum-cryptography": "^2.0.0" }, "devDependencies": { "@ethereumjs/common": "^3.1.1", @@ -18138,7 +18137,7 @@ "@ethereumjs/util": "^8.0.5", "@ethersproject/providers": "^5.7.1", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "mcl-wasm": "^0.7.1", "rustbn.js": "~0.2.0" }, @@ -18181,7 +18180,7 @@ "@ethereumjs/common": "^3.1.1", "@ethereumjs/rlp": "^4.0.1", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "ethers": "^5.7.1", "js-sdsl": "^4.1.4" }, @@ -18193,7 +18192,7 @@ "@types/tape": "^4.13.2", "debug": "^4.3.3", "eslint": "^8.0.0", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "functional-red-black-tree": "^1.0.1", "karma": "^6.3.2", "karma-chrome-launcher": "^3.1.0", @@ -18215,7 +18214,7 @@ "@ethereumjs/rlp": "^4.0.1", "@ethereumjs/util": "^8.0.5", "@types/readable-stream": "^2.3.13", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "readable-stream": "^3.6.0" }, "devDependencies": { @@ -18255,7 +18254,7 @@ "@ethereumjs/common": "^3.1.1", "@ethereumjs/rlp": "^4.0.1", "@ethereumjs/util": "^8.0.5", - "ethereum-cryptography": "^1.1.2" + "ethereum-cryptography": "^2.0.0" }, "devDependencies": { "@types/minimist": "^1.2.0", @@ -18283,8 +18282,7 @@ "dependencies": { "@chainsafe/ssz": "^0.11.0", "@ethereumjs/rlp": "^4.0.1", - "cross-fetch": "^3.1.5", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "micro-ftch": "^0.3.1" }, "devDependencies": { @@ -18310,7 +18308,7 @@ "@ethereumjs/tx": "^4.1.1", "@ethereumjs/util": "^8.0.5", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "mcl-wasm": "^0.7.1", "rustbn.js": "~0.2.0" }, @@ -19481,13 +19479,6 @@ "requires": { "@chainsafe/as-sha256": "^0.4.0", "@noble/hashes": "^1.3.0" - }, - "dependencies": { - "@noble/hashes": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz", - "integrity": "sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==" - } } }, "@chainsafe/ssz": { @@ -19556,7 +19547,7 @@ "@ethereumjs/util": "^8.0.5", "@types/lru-cache": "^5.1.0", "c-kzg": "^1.0.8", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "testdouble": "^3.17.2" } }, @@ -19575,7 +19566,7 @@ "@types/lru-cache": "^5.1.0", "abstract-level": "^1.0.3", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "level": "^8.0.0", "lru-cache": "^5.1.1", "memory-level": "^1.0.0" @@ -19610,7 +19601,7 @@ "cors": "^2.8.5", "crypto-browserify": "^3.12.0", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "file-replace-loader": "^1.2.0", "fs-extra": "^10.1.0", "it-pair": "^1.0.0", @@ -19711,7 +19702,7 @@ "bl": "^1.1.2", "chalk": "^2.4.2", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "ip": "^1.1.3", "k-bucket": "^5.0.0", "lru-cache": "^5.1.1", @@ -19771,7 +19762,7 @@ "@ethereumjs/util": "^8.0.5", "abstract-level": "^1.0.3", "bigint-crypto-utils": "^3.0.23", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "memory-level": "^1.0.0" } }, @@ -19792,7 +19783,7 @@ "benchmark": "^2.1.4", "c-kzg": "^1.0.8", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "level": "^8.0.0", "mcl-wasm": "^0.7.1", "memory-level": "^1.0.0", @@ -19817,7 +19808,7 @@ "@types/tape": "^4.13.2", "debug": "^4.3.3", "eslint": "^8.0.0", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "ethers": "^5.7.1", "functional-red-black-tree": "^1.0.1", "js-sdsl": "^4.1.4", @@ -19842,7 +19833,7 @@ "@types/readable-stream": "^2.3.13", "0x": "^4.9.1", "abstract-level": "^1.0.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "level": "^8.0.0", "level-legacy": "npm:level@^7.0.0", "level-mem": "^6.0.1", @@ -19872,7 +19863,7 @@ "@ethereumjs/util": "^8.0.5", "@types/minimist": "^1.2.0", "@types/node-dir": "^0.0.34", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "minimist": "^1.2.0", "node-dir": "^0.1.16", "testdouble": "^3.17.2" @@ -19885,9 +19876,8 @@ "@ethereumjs/rlp": "^4.0.1", "@types/bn.js": "^5.1.0", "@types/secp256k1": "^4.0.1", - "cross-fetch": "^3.1.5", - "ethereum-cryptography": "^1.1.2", - "micro-ftch": "*" + "ethereum-cryptography": "^2.0.0", + "micro-ftch": "^0.3.1" } }, "@ethereumjs/vm": { @@ -19910,7 +19900,7 @@ "@types/node-dir": "^0.0.34", "benchmark": "^2.1.4", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "level": "^8.0.0", "mcl-wasm": "^0.7.1", "memory-level": "^1.0.0", @@ -20439,11 +20429,21 @@ "@multiformats/base-x": { "version": "4.0.1" }, + "@noble/curves": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.0.0.tgz", + "integrity": "sha512-2upgEu0iLiDVDZkNLeFV2+ht0BAVgQnEmCk6JsOch9Rp8xfkMCbvbAZlA2pBHQc73dbl+vFOXfqkf4uemdn0bw==", + "requires": { + "@noble/hashes": "1.3.0" + } + }, "@noble/ed25519": { "version": "1.7.1" }, "@noble/hashes": { - "version": "1.1.2" + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz", + "integrity": "sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==" }, "@noble/secp256k1": { "version": "1.6.3" @@ -20506,17 +20506,21 @@ "version": "1.1.1" }, "@scure/bip32": { - "version": "1.1.0", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.3.0.tgz", + "integrity": "sha512-bcKpo1oj54hGholplGLpqPHRbIsnbixFtc06nwuNM5/dwSXOq/AAYoIBRsBmnZJSdfeNW5rnff7NTAz3ZCqR9Q==", "requires": { - "@noble/hashes": "~1.1.1", - "@noble/secp256k1": "~1.6.0", + "@noble/curves": "~1.0.0", + "@noble/hashes": "~1.3.0", "@scure/base": "~1.1.0" } }, "@scure/bip39": { - "version": "1.1.0", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.0.tgz", + "integrity": "sha512-SX/uKq52cuxm4YFXWFaVByaSHJh2w3BnokVSeUJVCv6K7WulT9u2BuNRBhuFl8vAuYnzx9bEu9WgpcNYTrYieg==", "requires": { - "@noble/hashes": "~1.1.1", + "@noble/hashes": "~1.3.0", "@scure/base": "~1.1.0" } }, @@ -22355,14 +22359,6 @@ "version": "1.1.1", "dev": true }, - "cross-fetch": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", - "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", - "requires": { - "node-fetch": "2.6.7" - } - }, "cross-spawn": { "version": "7.0.3", "requires": { @@ -23527,12 +23523,14 @@ "dev": true }, "ethereum-cryptography": { - "version": "1.1.2", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-2.0.0.tgz", + "integrity": "sha512-g25m4EtfQGjstWgVE1aIz7XYYjf3kH5kG17ULWVB5dH6uLahsoltOhACzSxyDV+fhn4gbR4xRrOXGe6r2uh4Bg==", "requires": { - "@noble/hashes": "1.1.2", - "@noble/secp256k1": "1.6.3", - "@scure/bip32": "1.1.0", - "@scure/bip39": "1.1.0" + "@noble/curves": "1.0.0", + "@noble/hashes": "1.3.0", + "@scure/bip32": "1.3.0", + "@scure/bip39": "1.2.0" } }, "ethers": { diff --git a/packages/block/package.json b/packages/block/package.json index de6115a691..ae2f19bbd8 100644 --- a/packages/block/package.json +++ b/packages/block/package.json @@ -43,7 +43,7 @@ "@ethereumjs/trie": "^5.0.4", "@ethereumjs/tx": "^4.1.1", "@ethereumjs/util": "^8.0.5", - "ethereum-cryptography": "^1.1.2" + "ethereum-cryptography": "^2.0.0" }, "devDependencies": { "@types/lru-cache": "^5.1.0", diff --git a/packages/blockchain/package.json b/packages/blockchain/package.json index a92383cca3..39c38ee66a 100644 --- a/packages/blockchain/package.json +++ b/packages/blockchain/package.json @@ -47,7 +47,7 @@ "@ethereumjs/util": "^8.0.5", "abstract-level": "^1.0.3", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "level": "^8.0.0", "lru-cache": "^5.1.1", "memory-level": "^1.0.0" diff --git a/packages/client/package.json b/packages/client/package.json index 9fd6496abb..c017d47636 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -75,7 +75,7 @@ "cors": "^2.8.5", "c-kzg": "^1.0.8", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "fs-extra": "^10.1.0", "it-pipe": "^1.1.0", "jayson": "^4.0.0", diff --git a/packages/devp2p/package.json b/packages/devp2p/package.json index 722b94192f..63d7cda888 100644 --- a/packages/devp2p/package.json +++ b/packages/devp2p/package.json @@ -58,7 +58,7 @@ "@types/lru-cache": "^5.1.0", "bl": "^1.1.2", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "ip": "^1.1.3", "k-bucket": "^5.0.0", "lru-cache": "^5.1.1", diff --git a/packages/devp2p/src/dpt/dpt.ts b/packages/devp2p/src/dpt/dpt.ts index 90840f83a3..45f6910fd0 100644 --- a/packages/devp2p/src/dpt/dpt.ts +++ b/packages/devp2p/src/dpt/dpt.ts @@ -1,5 +1,5 @@ import { randomBytes } from 'crypto' -import { getPublicKey } from 'ethereum-cryptography/secp256k1' +import { secp256k1 } from 'ethereum-cryptography/secp256k1' import { EventEmitter } from 'events' import ms = require('ms') @@ -107,7 +107,7 @@ export class DPT extends EventEmitter { super() this.privateKey = Buffer.from(privateKey) - this._id = pk2id(Buffer.from(getPublicKey(this.privateKey, false))) + this._id = pk2id(Buffer.from(secp256k1.getPublicKey(this.privateKey, false))) this._shouldFindNeighbours = options.shouldFindNeighbours ?? true this._shouldGetDnsPeers = options.shouldGetDnsPeers ?? false // By default, tries to connect to 12 new peers every 3s diff --git a/packages/devp2p/src/rlpx/ecies.ts b/packages/devp2p/src/rlpx/ecies.ts index 0df8f1f7c2..0ea5f1da36 100644 --- a/packages/devp2p/src/rlpx/ecies.ts +++ b/packages/devp2p/src/rlpx/ecies.ts @@ -2,7 +2,7 @@ import { RLP } from '@ethereumjs/rlp' import { bufArrToArr } from '@ethereumjs/util' import * as crypto from 'crypto' import { debug as createDebugLogger } from 'debug' -import { getPublicKey } from 'ethereum-cryptography/secp256k1' +import { secp256k1 } from 'ethereum-cryptography/secp256k1' import { ecdh, ecdsaRecover, ecdsaSign } from 'ethereum-cryptography/secp256k1-compat' import { @@ -82,7 +82,7 @@ export class ECIES { this._nonce = crypto.randomBytes(32) this._ephemeralPrivateKey = genPrivateKey() - this._ephemeralPublicKey = Buffer.from(getPublicKey(this._ephemeralPrivateKey, false)) + this._ephemeralPublicKey = Buffer.from(secp256k1.getPublicKey(this._ephemeralPrivateKey, false)) } _encryptMessage(data: Buffer, sharedMacData: Buffer | null = null): Buffer | undefined { @@ -108,7 +108,7 @@ export class ECIES { .update(Buffer.concat([dataIV, sharedMacData])) .digest() - const publicKey = getPublicKey(privateKey, false) + const publicKey = secp256k1.getPublicKey(privateKey, false) return Buffer.concat([publicKey, dataIV, tag]) } diff --git a/packages/devp2p/src/rlpx/rlpx.ts b/packages/devp2p/src/rlpx/rlpx.ts index 7a5eae9136..04a647eb4c 100644 --- a/packages/devp2p/src/rlpx/rlpx.ts +++ b/packages/devp2p/src/rlpx/rlpx.ts @@ -1,5 +1,5 @@ import { debug as createDebugLogger } from 'debug' -import { getPublicKey } from 'ethereum-cryptography/secp256k1' +import { secp256k1 } from 'ethereum-cryptography/secp256k1' import { EventEmitter } from 'events' import * as LRUCache from 'lru-cache' import ms = require('ms') @@ -59,7 +59,7 @@ export class RLPx extends EventEmitter { super() this._privateKey = Buffer.from(privateKey) - this._id = pk2id(Buffer.from(getPublicKey(this._privateKey, false))) + this._id = pk2id(Buffer.from(secp256k1.getPublicKey(this._privateKey, false))) // options this._timeout = options.timeout ?? ms('10s') diff --git a/packages/devp2p/src/util.ts b/packages/devp2p/src/util.ts index de3f94761d..605d0bbb65 100644 --- a/packages/devp2p/src/util.ts +++ b/packages/devp2p/src/util.ts @@ -2,7 +2,7 @@ import { RLP } from '@ethereumjs/rlp' import { arrToBufArr } from '@ethereumjs/util' import { debug as createDebugLogger } from 'debug' import { keccak256 as _keccak256 } from 'ethereum-cryptography/keccak' -import { utils } from 'ethereum-cryptography/secp256k1' +import { secp256k1 } from 'ethereum-cryptography/secp256k1' import { publicKeyConvert } from 'ethereum-cryptography/secp256k1-compat' import type { ETH } from './protocol/eth' @@ -16,8 +16,8 @@ export function keccak256(...buffers: Buffer[]) { } export function genPrivateKey(): Buffer { - const privateKey = utils.randomPrivateKey() - return utils.isValidPrivateKey(privateKey) ? Buffer.from(privateKey) : genPrivateKey() + const privateKey = secp256k1.utils.randomPrivateKey() + return secp256k1.utils.isValidPrivateKey(privateKey) ? Buffer.from(privateKey) : genPrivateKey() } export function pk2id(pk: Buffer): Buffer { diff --git a/packages/ethash/package.json b/packages/ethash/package.json index ade619568c..70b4a911bb 100644 --- a/packages/ethash/package.json +++ b/packages/ethash/package.json @@ -41,7 +41,7 @@ "@ethereumjs/util": "^8.0.5", "abstract-level": "^1.0.3", "bigint-crypto-utils": "^3.0.23", - "ethereum-cryptography": "^1.1.2" + "ethereum-cryptography": "^2.0.0" }, "devDependencies": { "@ethereumjs/common": "^3.1.1", diff --git a/packages/evm/package.json b/packages/evm/package.json index fb64a886f3..625a4ceab5 100644 --- a/packages/evm/package.json +++ b/packages/evm/package.json @@ -51,7 +51,7 @@ "@ethereumjs/util": "^8.0.5", "@ethersproject/providers": "^5.7.1", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "mcl-wasm": "^0.7.1", "rustbn.js": "~0.2.0" }, diff --git a/packages/statemanager/package.json b/packages/statemanager/package.json index 78893ccfb0..dc5b9a0b65 100644 --- a/packages/statemanager/package.json +++ b/packages/statemanager/package.json @@ -44,7 +44,7 @@ "@ethereumjs/common": "^3.1.1", "@ethereumjs/rlp": "^4.0.1", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "ethers": "^5.7.1", "js-sdsl": "^4.1.4" }, @@ -56,7 +56,7 @@ "@types/tape": "^4.13.2", "debug": "^4.3.3", "eslint": "^8.0.0", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "functional-red-black-tree": "^1.0.1", "karma": "^6.3.2", "karma-chrome-launcher": "^3.1.0", diff --git a/packages/trie/package.json b/packages/trie/package.json index df98d20188..d9d6977742 100644 --- a/packages/trie/package.json +++ b/packages/trie/package.json @@ -48,7 +48,7 @@ "@ethereumjs/rlp": "^4.0.1", "@ethereumjs/util": "^8.0.5", "@types/readable-stream": "^2.3.13", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "readable-stream": "^3.6.0" }, "devDependencies": { diff --git a/packages/tx/package.json b/packages/tx/package.json index a6d90a9f44..c34260c036 100644 --- a/packages/tx/package.json +++ b/packages/tx/package.json @@ -55,7 +55,7 @@ "@ethereumjs/common": "^3.1.1", "@ethereumjs/rlp": "^4.0.1", "@ethereumjs/util": "^8.0.5", - "ethereum-cryptography": "^1.1.2" + "ethereum-cryptography": "^2.0.0" }, "peerDependencies": { "c-kzg": "^1.0.8" diff --git a/packages/util/package.json b/packages/util/package.json index 77ff0a638d..7ecd044a81 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -85,7 +85,7 @@ "dependencies": { "@chainsafe/ssz": "^0.11.0", "@ethereumjs/rlp": "^4.0.1", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "micro-ftch": "^0.3.1" }, "devDependencies": { diff --git a/packages/util/src/account.ts b/packages/util/src/account.ts index d181f3df24..261d6d8d6f 100644 --- a/packages/util/src/account.ts +++ b/packages/util/src/account.ts @@ -1,6 +1,6 @@ import { RLP } from '@ethereumjs/rlp' import { keccak256 } from 'ethereum-cryptography/keccak' -import { Point, utils } from 'ethereum-cryptography/secp256k1' +import { secp256k1 } from 'ethereum-cryptography/secp256k1' import { bytesToHex } from 'ethereum-cryptography/utils' import { @@ -239,7 +239,7 @@ export const generateAddress2 = function (from: Buffer, salt: Buffer, initCode: * Checks if the private key satisfies the rules of the curve secp256k1. */ export const isValidPrivate = function (privateKey: Buffer): boolean { - return utils.isValidPrivateKey(privateKey) + return secp256k1.utils.isValidPrivateKey(privateKey) } /** @@ -254,7 +254,7 @@ export const isValidPublic = function (publicKey: Buffer, sanitize: boolean = fa // Convert to SEC1 for secp256k1 // Automatically checks whether point is on curve try { - Point.fromHex(Buffer.concat([Buffer.from([4]), publicKey])) + secp256k1.ProjectivePoint.fromHex(Buffer.concat([Buffer.from([4]), publicKey])) return true } catch (e) { return false @@ -266,7 +266,7 @@ export const isValidPublic = function (publicKey: Buffer, sanitize: boolean = fa } try { - Point.fromHex(publicKey) + secp256k1.ProjectivePoint.fromHex(publicKey) return true } catch (e) { return false @@ -282,7 +282,7 @@ export const isValidPublic = function (publicKey: Buffer, sanitize: boolean = fa export const pubToAddress = function (pubKey: Buffer, sanitize: boolean = false): Buffer { assertIsBuffer(pubKey) if (sanitize && pubKey.length !== 64) { - pubKey = Buffer.from(Point.fromHex(pubKey).toRawBytes(false).slice(1)) + pubKey = Buffer.from(secp256k1.ProjectivePoint.fromHex(pubKey).toRawBytes(false).slice(1)) } if (pubKey.length !== 64) { throw new Error('Expected pubKey to be of length 64') @@ -299,7 +299,9 @@ export const publicToAddress = pubToAddress export const privateToPublic = function (privateKey: Buffer): Buffer { assertIsBuffer(privateKey) // skip the type flag and use the X, Y points - return Buffer.from(Point.fromPrivateKey(privateKey).toRawBytes(false).slice(1)) + return Buffer.from( + secp256k1.ProjectivePoint.fromPrivateKey(privateKey).toRawBytes(false).slice(1) + ) } /** @@ -316,7 +318,7 @@ export const privateToAddress = function (privateKey: Buffer): Buffer { export const importPublic = function (publicKey: Buffer): Buffer { assertIsBuffer(publicKey) if (publicKey.length !== 64) { - publicKey = Buffer.from(Point.fromHex(publicKey).toRawBytes(false).slice(1)) + publicKey = Buffer.from(secp256k1.ProjectivePoint.fromHex(publicKey).toRawBytes(false).slice(1)) } return publicKey } diff --git a/packages/util/src/constants.ts b/packages/util/src/constants.ts index 6b3d660217..606b303dab 100644 --- a/packages/util/src/constants.ts +++ b/packages/util/src/constants.ts @@ -1,5 +1,5 @@ import { Buffer } from 'buffer' -import { CURVE } from 'ethereum-cryptography/secp256k1' +import { secp256k1 } from 'ethereum-cryptography/secp256k1' /** * 2^64-1 @@ -22,8 +22,8 @@ export const MAX_INTEGER_BIGINT = BigInt( '115792089237316195423570985008687907853269984665640564039457584007913129639935' ) -export const SECP256K1_ORDER = CURVE.n -export const SECP256K1_ORDER_DIV_2 = CURVE.n / BigInt(2) +export const SECP256K1_ORDER = secp256k1.CURVE.n +export const SECP256K1_ORDER_DIV_2 = secp256k1.CURVE.n / BigInt(2) /** * 2^256 diff --git a/packages/util/src/signature.ts b/packages/util/src/signature.ts index 6294b1656a..35aaad4af9 100644 --- a/packages/util/src/signature.ts +++ b/packages/util/src/signature.ts @@ -1,5 +1,5 @@ import { keccak256 } from 'ethereum-cryptography/keccak' -import { recoverPublicKey, signSync } from 'ethereum-cryptography/secp256k1' +import { secp256k1 } from 'ethereum-cryptography/secp256k1' import { bufferToBigInt, bufferToHex, bufferToInt, setLengthLeft, toBuffer } from './bytes' import { SECP256K1_ORDER, SECP256K1_ORDER_DIV_2 } from './constants' @@ -18,15 +18,15 @@ export interface ECDSASignature { * accordingly, otherwise return a "static" `v` just derived from the `recovery` bit */ export function ecsign(msgHash: Buffer, privateKey: Buffer, chainId?: bigint): ECDSASignature { - const [signature, recovery] = signSync(msgHash, privateKey, { recovered: true, der: false }) - - const r = Buffer.from(signature.slice(0, 32)) - const s = Buffer.from(signature.slice(32, 64)) + const sig = secp256k1.sign(msgHash, privateKey) + const buf = sig.toCompactRawBytes() + const r = Buffer.from(buf.slice(0, 32)) + const s = Buffer.from(buf.slice(32, 64)) const v = chainId === undefined - ? BigInt(recovery + 27) - : BigInt(recovery + 35) + BigInt(chainId) * BigInt(2) + ? BigInt(sig.recovery! + 27) + : BigInt(sig.recovery! + 35) + BigInt(chainId) * BigInt(2) return { r, s, v } } @@ -62,8 +62,9 @@ export const ecrecover = function ( throw new Error('Invalid signature v value') } - const senderPubKey = recoverPublicKey(msgHash, signature, Number(recovery)) - return Buffer.from(senderPubKey.slice(1)) + const sig = secp256k1.Signature.fromCompact(signature).addRecoveryBit(Number(recovery)) + const senderPubKey = sig.recoverPublicKey(msgHash) + return Buffer.from(senderPubKey.toRawBytes(false).slice(1)) } /** diff --git a/packages/vm/package.json b/packages/vm/package.json index 2a0dbf5df1..09d2339f9f 100644 --- a/packages/vm/package.json +++ b/packages/vm/package.json @@ -66,7 +66,7 @@ "@ethereumjs/tx": "^4.1.1", "@ethereumjs/util": "^8.0.5", "debug": "^4.3.3", - "ethereum-cryptography": "^1.1.2", + "ethereum-cryptography": "^2.0.0", "mcl-wasm": "^0.7.1", "rustbn.js": "~0.2.0" },