From e40f20674f08e713b2e7645ecaae931923227138 Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Fri, 31 Jan 2025 13:03:11 -0800 Subject: [PATCH 1/4] Convert sha3 library --- package-lock.json | 50 ++++++++++++------- package.json | 3 ++ .../interaction-template-utils/utils/hash.js | 8 ++- packages/sdk/package.json | 1 + packages/sdk/src/encode/encode.ts | 11 ++-- 5 files changed, 45 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2005eb331..e4534a0b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "workspaces": [ "./packages/*" ], + "dependencies": { + "@noble/hashes": "^1.7.1" + }, "devDependencies": { "@babel/preset-typescript": "^7.25.7", "@changesets/changelog-github": "^0.4.8", @@ -5768,6 +5771,18 @@ "@tybys/wasm-util": "^0.9.0" } }, + "node_modules/@noble/hashes": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.7.1.tgz", + "integrity": "sha512-B8XBPsn4vT/KJAGqDzbwztd+6Yte3P4V7iafm24bxgDe/mlRuK6xmWPuCNrKt2vDafZ8MfJLlchDG/vYafQEjQ==", + "license": "MIT", + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "license": "MIT", @@ -29050,16 +29065,16 @@ }, "packages/fcl": { "name": "@onflow/fcl", - "version": "1.13.2", + "version": "1.13.4", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.25.7", "@onflow/config": "1.5.1", - "@onflow/fcl-core": "1.13.2", - "@onflow/fcl-wc": "5.5.2", + "@onflow/fcl-core": "1.13.4", + "@onflow/fcl-wc": "5.5.4", "@onflow/interaction": "0.0.11", "@onflow/rlp": "1.2.3", - "@onflow/sdk": "1.5.5", + "@onflow/sdk": "1.5.6", "@onflow/types": "1.4.1", "@onflow/util-actor": "1.3.4", "@onflow/util-address": "1.2.3", @@ -29124,7 +29139,7 @@ }, "packages/fcl-core": { "name": "@onflow/fcl-core", - "version": "1.13.2", + "version": "1.13.4", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.25.7", @@ -29132,8 +29147,8 @@ "@onflow/config": "1.5.1", "@onflow/interaction": "0.0.11", "@onflow/rlp": "1.2.3", - "@onflow/sdk": "1.5.5", - "@onflow/transport-http": "1.10.4", + "@onflow/sdk": "1.5.6", + "@onflow/transport-http": "1.10.5", "@onflow/types": "1.4.1", "@onflow/util-actor": "1.3.4", "@onflow/util-address": "1.2.3", @@ -29180,15 +29195,15 @@ }, "packages/fcl-react-native": { "name": "@onflow/fcl-react-native", - "version": "1.9.9", + "version": "1.9.11", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.25.7", "@onflow/config": "1.5.1", - "@onflow/fcl-core": "1.13.2", + "@onflow/fcl-core": "1.13.4", "@onflow/interaction": "0.0.11", "@onflow/rlp": "1.2.3", - "@onflow/sdk": "1.5.5", + "@onflow/sdk": "1.5.6", "@onflow/types": "1.4.1", "@onflow/util-actor": "1.3.4", "@onflow/util-address": "1.2.3", @@ -29240,7 +29255,7 @@ }, "packages/fcl-wc": { "name": "@onflow/fcl-wc", - "version": "5.5.2", + "version": "5.5.4", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.25.7", @@ -29268,7 +29283,7 @@ "jest-preset-preact": "^4.1.1" }, "peerDependencies": { - "@onflow/fcl-core": "1.13.2" + "@onflow/fcl-core": "1.13.4" } }, "packages/fcl/node_modules/cross-fetch": { @@ -29359,13 +29374,14 @@ }, "packages/sdk": { "name": "@onflow/sdk", - "version": "1.5.5", + "version": "1.5.6", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.25.7", + "@noble/hashes": "^1.7.1", "@onflow/config": "1.5.1", "@onflow/rlp": "1.2.3", - "@onflow/transport-http": "1.10.4", + "@onflow/transport-http": "1.10.5", "@onflow/typedefs": "1.4.0", "@onflow/util-actor": "1.3.4", "@onflow/util-address": "1.2.3", @@ -29414,13 +29430,13 @@ }, "devDependencies": { "@onflow/fcl-bundle": "1.6.0", - "@onflow/sdk": "1.5.5", + "@onflow/sdk": "1.5.6", "jest": "^29.7.0" } }, "packages/transport-http": { "name": "@onflow/transport-http", - "version": "1.10.4", + "version": "1.10.5", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.25.7", @@ -29437,7 +29453,7 @@ "devDependencies": { "@onflow/fcl-bundle": "1.6.0", "@onflow/rlp": "1.2.3", - "@onflow/sdk": "1.5.5", + "@onflow/sdk": "1.5.6", "@onflow/types": "1.4.1", "jest": "^29.7.0" } diff --git a/package.json b/package.json index 4699e1f07..c3e04d794 100644 --- a/package.json +++ b/package.json @@ -36,5 +36,8 @@ "@nx/nx-darwin-x64": "^17.3.2", "@nx/nx-linux-x64-gnu": "^17.3.2", "@nx/nx-win32-x64-msvc": "^17.3.2" + }, + "dependencies": { + "@noble/hashes": "^1.7.1" } } diff --git a/packages/fcl-core/src/interaction-template-utils/utils/hash.js b/packages/fcl-core/src/interaction-template-utils/utils/hash.js index 14917c2b4..1cd08ca83 100644 --- a/packages/fcl-core/src/interaction-template-utils/utils/hash.js +++ b/packages/fcl-core/src/interaction-template-utils/utils/hash.js @@ -1,8 +1,6 @@ -import {SHA3} from "sha3" -import {Buffer} from "@onflow/rlp" +import {sha3_256} from "@noble/hashes/sha3" +import {utf8ToBytes, bytesToHex} from "@noble/hashes/utils" export function genHash(utf8String) { - const sha = new SHA3(256) - sha.update(Buffer.from(utf8String, "utf8")) - return sha.digest("hex") + return bytesToHex(sha3_256(utf8ToBytes(utf8String))) } diff --git a/packages/sdk/package.json b/packages/sdk/package.json index a7ecd3639..e107c9c7b 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -41,6 +41,7 @@ }, "dependencies": { "@babel/runtime": "^7.25.7", + "@noble/hashes": "^1.7.1", "@onflow/config": "1.5.1", "@onflow/rlp": "1.2.3", "@onflow/transport-http": "1.10.5", diff --git a/packages/sdk/src/encode/encode.ts b/packages/sdk/src/encode/encode.ts index 3c9f31408..d0465376e 100644 --- a/packages/sdk/src/encode/encode.ts +++ b/packages/sdk/src/encode/encode.ts @@ -1,4 +1,5 @@ -import {SHA3} from "sha3" +import {sha3_256} from "@noble/hashes/sha3" +import {hexToBytes, bytesToHex} from "@noble/hashes/utils" import {encode, Buffer, EncodeInput} from "@onflow/rlp" import {sansPrefix} from "@onflow/util-address" @@ -7,7 +8,7 @@ export const encodeTransactionPayload = (tx: Transaction) => export const encodeTransactionEnvelope = (tx: Transaction) => prependTransactionDomainTag(rlpEncode(prepareEnvelope(tx))) export const encodeTxIdFromVoucher = (voucher: Voucher) => - sha3_256(rlpEncode(prepareVoucher(voucher))) + sha3_256_hash(rlpEncode(prepareVoucher(voucher))) const rightPaddedHexBuffer = (value: string, pad: number) => Buffer.from(value.padEnd(pad * 2, "0"), "hex") @@ -35,10 +36,8 @@ const rlpEncode = (v: EncodeInput) => { return encode(v).toString("hex") } -const sha3_256 = (msg: string) => { - const sha = new SHA3(256) - sha.update(Buffer.from(msg, "hex")) - return sha.digest().toString("hex") +const sha3_256_hash = (msg: string) => { + return bytesToHex(sha3_256(hexToBytes(msg))) } const preparePayload = (tx: Transaction) => { From 6d66c1a28ab22b2dac34d5c761d0e001e9f3710d Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:01:44 -0800 Subject: [PATCH 2/4] Use buffer --- .../fcl-core/src/interaction-template-utils/utils/hash.js | 5 +++-- packages/sdk/src/encode/encode.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/fcl-core/src/interaction-template-utils/utils/hash.js b/packages/fcl-core/src/interaction-template-utils/utils/hash.js index 1cd08ca83..aa1493c01 100644 --- a/packages/fcl-core/src/interaction-template-utils/utils/hash.js +++ b/packages/fcl-core/src/interaction-template-utils/utils/hash.js @@ -1,6 +1,7 @@ import {sha3_256} from "@noble/hashes/sha3" -import {utf8ToBytes, bytesToHex} from "@noble/hashes/utils" +import {bytesToHex} from "@noble/hashes/utils" +import {Buffer} from "@onflow/rlp" export function genHash(utf8String) { - return bytesToHex(sha3_256(utf8ToBytes(utf8String))) + return bytesToHex(sha3_256(Buffer.from(utf8String, "utf8"))) } diff --git a/packages/sdk/src/encode/encode.ts b/packages/sdk/src/encode/encode.ts index d0465376e..b1c7ad652 100644 --- a/packages/sdk/src/encode/encode.ts +++ b/packages/sdk/src/encode/encode.ts @@ -37,7 +37,7 @@ const rlpEncode = (v: EncodeInput) => { } const sha3_256_hash = (msg: string) => { - return bytesToHex(sha3_256(hexToBytes(msg))) + return bytesToHex(sha3_256(Buffer.from(msg, "utf8"))) } const preparePayload = (tx: Transaction) => { From 3904b9850a752a38002ceaf811d61e131bc337e1 Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:02:05 -0800 Subject: [PATCH 3/4] Remove --- packages/sdk/src/encode/encode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/src/encode/encode.ts b/packages/sdk/src/encode/encode.ts index b1c7ad652..8fe91e8da 100644 --- a/packages/sdk/src/encode/encode.ts +++ b/packages/sdk/src/encode/encode.ts @@ -1,5 +1,5 @@ import {sha3_256} from "@noble/hashes/sha3" -import {hexToBytes, bytesToHex} from "@noble/hashes/utils" +import {bytesToHex} from "@noble/hashes/utils" import {encode, Buffer, EncodeInput} from "@onflow/rlp" import {sansPrefix} from "@onflow/util-address" From 2beea46e74d66827cee4291ccc0ab2c2c4ccd9e7 Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:04:33 -0800 Subject: [PATCH 4/4] Remove sha3 --- package-lock.json | 11 +---------- packages/fcl/package.json | 3 +-- packages/sdk/package.json | 1 - 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index e4534a0b1..c8a1c4e38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26177,13 +26177,6 @@ "license": "ISC", "peer": true }, - "node_modules/sha3": { - "version": "2.1.4", - "license": "MIT", - "dependencies": { - "buffer": "6.0.3" - } - }, "node_modules/shallow-clone": { "version": "3.0.1", "license": "MIT", @@ -29087,8 +29080,7 @@ "@walletconnect/types": "^2.13.2", "abort-controller": "^3.0.0", "cross-fetch": "^4.0.0", - "events": "^3.3.0", - "sha3": "^2.1.4" + "events": "^3.3.0" }, "devDependencies": { "@onflow/fcl-bundle": "1.6.0", @@ -29390,7 +29382,6 @@ "@onflow/util-template": "1.2.3", "deepmerge": "^4.3.1", "events": "^3.3.0", - "sha3": "^2.1.4", "uuid": "^9.0.1" }, "devDependencies": { diff --git a/packages/fcl/package.json b/packages/fcl/package.json index ae3c2050f..ed46934fc 100644 --- a/packages/fcl/package.json +++ b/packages/fcl/package.json @@ -66,7 +66,6 @@ "@walletconnect/types": "^2.13.2", "abort-controller": "^3.0.0", "cross-fetch": "^4.0.0", - "events": "^3.3.0", - "sha3": "^2.1.4" + "events": "^3.3.0" } } diff --git a/packages/sdk/package.json b/packages/sdk/package.json index e107c9c7b..5ba9003d8 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -53,7 +53,6 @@ "@onflow/util-template": "1.2.3", "deepmerge": "^4.3.1", "events": "^3.3.0", - "sha3": "^2.1.4", "uuid": "^9.0.1" } }