From 9560e4750b2d9ff0db899d692da221b67e93b017 Mon Sep 17 00:00:00 2001 From: Inkvi Date: Fri, 10 May 2024 15:59:16 -0700 Subject: [PATCH] Support blob txs by upgrading to latest dependencies --- package-lock.json | 74 ++++++++++++-------- package.json | 6 +- src/server.ts | 2 +- src/web3-kms-signer/core/Signer.ts | 23 +++--- src/web3-kms-signer/core/Utils/UAddress.ts | 4 +- src/web3-kms-signer/core/Utils/UBuffer.ts | 4 ++ src/web3-kms-signer/core/Utils/UPublickey.ts | 6 +- 7 files changed, 67 insertions(+), 52 deletions(-) diff --git a/package-lock.json b/package-lock.json index 39d20cf..75bb897 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,9 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@ethereumjs/common": "^3.2.0", - "@ethereumjs/tx": "^4.2.0", - "@ethereumjs/util": "^8.1.0", + "@ethereumjs/common": "^4.3.0", + "@ethereumjs/tx": "^5.3.0", + "@ethereumjs/util": "^9.0.3", "@google-cloud/kms": "^4.2.0", "asn1js": "^3.0.5", "axios": "^1.6.8", @@ -23,9 +23,6 @@ "uuid": "^8.3.2", "web3": "^4.8.0" }, - "bin": { - "signer": "bin/signer" - }, "devDependencies": { "@types/bn.js": "^5.1.5", "@types/fast-crc32c": "^2.0.0", @@ -400,12 +397,11 @@ } }, "node_modules/@ethereumjs/common": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@ethereumjs/common/-/common-3.2.0.tgz", - "integrity": "sha512-pksvzI0VyLgmuEF2FA/JR/4/y6hcPq8OUail3/AvycBaW1d5VSauOZzqGvJ3RTmR4MU35lWE8KseKOsEhrFRBA==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/@ethereumjs/common/-/common-4.3.0.tgz", + "integrity": "sha512-shBNJ0ewcPNTUfZduHiczPmqkfJDn0Dh/9BR5fq7xUFTuIq7Fu1Vx00XDwQVIrpVL70oycZocOhBM6nDO+4FEQ==", "dependencies": { - "@ethereumjs/util": "^8.1.0", - "crc-32": "^1.2.0" + "@ethereumjs/util": "^9.0.3" } }, "node_modules/@ethereumjs/rlp": { @@ -420,30 +416,51 @@ } }, "node_modules/@ethereumjs/tx": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@ethereumjs/tx/-/tx-4.2.0.tgz", - "integrity": "sha512-1nc6VO4jtFd172BbSnTnDQVr9IYBFl1y4xPzZdtkrkKIncBCkdbgfdRV+MiTkJYAtTxvV12GRZLqBFT1PNK6Yw==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@ethereumjs/tx/-/tx-5.3.0.tgz", + "integrity": "sha512-uv++XYuIfuqYbvymL3/o14hHuC6zX0nRQ1nI2FHsbkkorLZ2ChEIDqVeeVk7Xc9/jQNU/22sk9qZZkRlsveXxw==", "dependencies": { - "@ethereumjs/common": "^3.2.0", - "@ethereumjs/rlp": "^4.0.1", - "@ethereumjs/util": "^8.1.0", - "ethereum-cryptography": "^2.0.0" + "@ethereumjs/common": "^4.3.0", + "@ethereumjs/rlp": "^5.0.2", + "@ethereumjs/util": "^9.0.3", + "ethereum-cryptography": "^2.1.3" }, "engines": { - "node": ">=14" + "node": ">=18" + } + }, + "node_modules/@ethereumjs/tx/node_modules/@ethereumjs/rlp": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@ethereumjs/rlp/-/rlp-5.0.2.tgz", + "integrity": "sha512-DziebCdg4JpGlEqEdGgXmjqcFoJi+JGulUXwEjsZGAscAQ7MyD/7LE/GVCP29vEQxKc7AAwjT3A2ywHp2xfoCA==", + "bin": { + "rlp": "bin/rlp.cjs" + }, + "engines": { + "node": ">=18" } }, "node_modules/@ethereumjs/util": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@ethereumjs/util/-/util-8.1.0.tgz", - "integrity": "sha512-zQ0IqbdX8FZ9aw11vP+dZkKDkS+kgIvQPHnSAXzP9pLu+Rfu3D3XEeLbicvoXJTYnhZiPmsZUxgdzXwNKxRPbA==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/@ethereumjs/util/-/util-9.0.3.tgz", + "integrity": "sha512-PmwzWDflky+7jlZIFqiGsBPap12tk9zK5SVH9YW2OEnDN7OEhCjUOMzbOqwuClrbkSIkM2ERivd7sXZ48Rh/vg==", "dependencies": { - "@ethereumjs/rlp": "^4.0.1", - "ethereum-cryptography": "^2.0.0", - "micro-ftch": "^0.3.1" + "@ethereumjs/rlp": "^5.0.2", + "ethereum-cryptography": "^2.1.3" }, "engines": { - "node": ">=14" + "node": ">=18" + } + }, + "node_modules/@ethereumjs/util/node_modules/@ethereumjs/rlp": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@ethereumjs/rlp/-/rlp-5.0.2.tgz", + "integrity": "sha512-DziebCdg4JpGlEqEdGgXmjqcFoJi+JGulUXwEjsZGAscAQ7MyD/7LE/GVCP29vEQxKc7AAwjT3A2ywHp2xfoCA==", + "bin": { + "rlp": "bin/rlp.cjs" + }, + "engines": { + "node": ">=18" } }, "node_modules/@fastify/ajv-compiler": { @@ -2196,11 +2213,6 @@ "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", "dev": true }, - "node_modules/micro-ftch": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/micro-ftch/-/micro-ftch-0.3.1.tgz", - "integrity": "sha512-/0LLxhzP0tfiR5hcQebtudP56gUurs2CLkGarnCiB/OqEyUFQ6U3paQi/tgLv0hBJYt2rnr9MNpxz4fiiugstg==" - }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", diff --git a/package.json b/package.json index b13a28d..fb77620 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,9 @@ "author": "", "license": "ISC", "dependencies": { - "@ethereumjs/common": "^3.2.0", - "@ethereumjs/tx": "^4.2.0", - "@ethereumjs/util": "^8.1.0", + "@ethereumjs/common": "^4.3.0", + "@ethereumjs/tx": "^5.3.0", + "@ethereumjs/util": "^9.0.3", "@google-cloud/kms": "^4.2.0", "asn1js": "^3.0.5", "axios": "^1.6.8", diff --git a/src/server.ts b/src/server.ts index 2f3b8af..9a0a8c5 100644 --- a/src/server.ts +++ b/src/server.ts @@ -66,7 +66,7 @@ async function handleEthSignTransaction(transactionArgs: TransactionArgs) { const start = async () => { try { - await app.listen({host:"0.0.0.0", port: 8000}); + await app.listen({port: 8000}); console.log('Server running at https://localhost:8000/'); } catch (err) { console.error(err); diff --git a/src/web3-kms-signer/core/Signer.ts b/src/web3-kms-signer/core/Signer.ts index d6dab79..b158e08 100644 --- a/src/web3-kms-signer/core/Signer.ts +++ b/src/web3-kms-signer/core/Signer.ts @@ -2,11 +2,10 @@ import { addHexPrefix, fromSigned, toUnsigned, - bigIntToBuffer, hashPersonalMessage, - bufferToBigInt, toBuffer + bigIntToBytes } from '@ethereumjs/util' -import { TxData } from '@ethereumjs/tx'; +import { TypedTxData } from '@ethereumjs/tx'; import { Common } from '@ethereumjs/common' import { Wallets } from './Wallets'; import { UBuffer } from './Utils/UBuffer'; @@ -43,13 +42,13 @@ export class Signer { * @param txData The transaction data to sign. * @returns A Promise that resolves to the serialized transaction as a '0x'-prefixed hex string. */ - public async signTransaction(account: { keyId: string, address?: Buffer }, txData: TxData) { + public async signTransaction(account: { keyId: string, address?: Buffer }, txData: TypedTxData) { let tx = TransactionFactory.fromTxData(txData, { common: this.common }); - const digest = tx.getMessageToSign() - const txType = Number(bufferToBigInt(toBuffer(txData.type))) - const {r, s, v} = await this.wallets.ecsign(account, digest, txType, this.common?.chainId()); + const digest = Buffer.from(tx.getHashedMessageToSign()) + + const {r, s, v} = await this.wallets.ecsign(account, digest, tx.type, this.common?.chainId()); const signed = TransactionFactory.fromTxData({...txData, r, s, v}, { common: this.common }); - return addHexPrefix(signed.serialize().toString('hex')); + return addHexPrefix(Buffer.from(signed.serialize()).toString('hex')); } /** @@ -61,7 +60,7 @@ export class Signer { */ public async signMessage(account: { keyId: string, address?: Buffer }, message: string) { const digest = hashPersonalMessage(Buffer.from(message)); - return this.signDigest(account, digest); + return this.signDigest(account, Buffer.from(digest)); } /** @@ -73,9 +72,9 @@ export class Signer { public async signDigest(account: { keyId: string, address?: Buffer }, digest: string | Buffer) { const {r, s, v} = await this.wallets.ecsign(account, UBuffer.bufferOrHex(digest)); - const rStr = toUnsigned(fromSigned(r)).toString('hex'); - const sStr = toUnsigned(fromSigned(s)).toString('hex'); - const vStr = bigIntToBuffer(v).toString('hex'); + const rStr = Buffer.from(toUnsigned(fromSigned(r))).toString('hex'); + const sStr = Buffer.from(toUnsigned(fromSigned(s))).toString('hex'); + const vStr = Buffer.from(bigIntToBytes(v)).toString('hex'); return addHexPrefix(rStr.concat(sStr, vStr)); } diff --git a/src/web3-kms-signer/core/Utils/UAddress.ts b/src/web3-kms-signer/core/Utils/UAddress.ts index 8ba7653..6c42794 100644 --- a/src/web3-kms-signer/core/Utils/UAddress.ts +++ b/src/web3-kms-signer/core/Utils/UAddress.ts @@ -19,7 +19,7 @@ export class UAddress { * Returns the wallet's address as a "0x" prefixed hex */ public getAddressHex(): string { - return ethutil.bufferToHex(this.getAddress()).toLowerCase(); + return UBuffer.bufferToHex(this.getAddress()).toLowerCase(); } /** @@ -35,7 +35,7 @@ export class UAddress { */ public static fromPublickey(input: Buffer | string) { - return new UAddress(ethutil.publicToAddress(UBuffer.bufferOrHex(input))); + return new UAddress(Buffer.from(ethutil.publicToAddress(UBuffer.bufferOrHex(input)))); } public static fromAddress(input: Buffer | string) { diff --git a/src/web3-kms-signer/core/Utils/UBuffer.ts b/src/web3-kms-signer/core/Utils/UBuffer.ts index 9c566e1..e58c48f 100644 --- a/src/web3-kms-signer/core/Utils/UBuffer.ts +++ b/src/web3-kms-signer/core/Utils/UBuffer.ts @@ -2,4 +2,8 @@ export class UBuffer { public static bufferOrHex(input: Buffer | string) { return (input instanceof Buffer) ? input : Buffer.from(input.replace('0x', ''), 'hex'); } + + public static bufferToHex = function (buf: Buffer): string { + return '0x' + buf.toString('hex') + } } \ No newline at end of file diff --git a/src/web3-kms-signer/core/Utils/UPublickey.ts b/src/web3-kms-signer/core/Utils/UPublickey.ts index 12a8649..3780b61 100644 --- a/src/web3-kms-signer/core/Utils/UPublickey.ts +++ b/src/web3-kms-signer/core/Utils/UPublickey.ts @@ -24,7 +24,7 @@ export class UPublickey { * Returns the wallet's public key as a "0x" prefixed hex */ public getPublickeyHex(): string { - return ethutil.bufferToHex(this.getPublickey()).toLowerCase(); + return UBuffer.bufferToHex(this.getPublickey()).toLowerCase(); } /** @@ -54,7 +54,7 @@ export class UPublickey { */ public static fromPrivatekey(input: Buffer | string) { - return new UPublickey(ethutil.privateToPublic(UBuffer.bufferOrHex(input))); + return new UPublickey(Buffer.from(ethutil.privateToPublic(UBuffer.bufferOrHex(input)))); } public static fromPublickey(input: Buffer | string) { @@ -62,6 +62,6 @@ export class UPublickey { } public static fromVRS(digest: Buffer, v: bigint, r: Buffer, s: Buffer, chainId?: bigint) { - return new UPublickey(ethutil.ecrecover(digest, v, r, s, chainId)); + return new UPublickey(Buffer.from(ethutil.ecrecover(digest, v, r, s, chainId))); } } \ No newline at end of file