Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert sha3 library #2100

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 34 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {SHA3} from "sha3"
import {sha3_256} from "@noble/hashes/sha3"
import {bytesToHex} from "@noble/hashes/utils"
import {Buffer} from "@onflow/rlp"

export function genHash(utf8String) {
const sha = new SHA3(256)
sha.update(Buffer.from(utf8String, "utf8"))
return sha.digest("hex")
return bytesToHex(sha3_256(Buffer.from(utf8String, "utf8")))
}
3 changes: 1 addition & 2 deletions packages/fcl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -52,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"
}
}
11 changes: 5 additions & 6 deletions packages/sdk/src/encode/encode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {SHA3} from "sha3"
import {sha3_256} from "@noble/hashes/sha3"
import {bytesToHex} from "@noble/hashes/utils"
import {encode, Buffer, EncodeInput} from "@onflow/rlp"
import {sansPrefix} from "@onflow/util-address"

Expand All @@ -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")
Expand Down Expand Up @@ -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(Buffer.from(msg, "utf8")))
}

const preparePayload = (tx: Transaction) => {
Expand Down
Loading