diff --git a/package-lock.json b/package-lock.json index 9a670a5..ec48259 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "@chainsafe/bls-keystore": "^3.0.0", "@noble/curves": "^1.4.0", - "@noble/hashes": "^1.4.0", "@waku/core": "^0.0.25", "@waku/utils": "^0.0.13", "@waku/zerokit-rln-wasm": "^0.0.13", diff --git a/package.json b/package.json index 5af4205..1df0b7b 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,6 @@ "dependencies": { "@chainsafe/bls-keystore": "^3.0.0", "@noble/curves": "^1.4.0", - "@noble/hashes": "^1.4.0", "@waku/core": "^0.0.25", "@waku/utils": "^0.0.13", "@waku/zerokit-rln-wasm": "^0.0.13", diff --git a/src/proof.ts b/src/proof.ts index 0aea21e..9a4d68d 100644 --- a/src/proof.ts +++ b/src/proof.ts @@ -30,7 +30,7 @@ export class Proof implements IRateLimitProof { constructor(proofBytes: Uint8Array) { if (proofBytes.length < rlnIdentifierOffset) throw "invalid proof"; - // parse the proof as proof<128> | share_y<32> | nullifier<32> | root<32> | epoch<32> | share_x<32> | rln_identifier<32> + // parse the proof as proof<128> | root<32> | epoch<32> | share_x<32> | share_y<32> | nullifier<32> | rln_identifier<32> this.proof = proofBytes.subarray(0, proofOffset); this.merkleRoot = proofBytes.subarray(proofOffset, rootOffset); this.epoch = proofBytes.subarray(rootOffset, epochOffset); diff --git a/src/utils/hash.ts b/src/utils/hash.ts index 4190543..78422e2 100644 --- a/src/utils/hash.ts +++ b/src/utils/hash.ts @@ -1,7 +1,3 @@ -import * as mod from "@noble/curves/abstract/modular"; -import { bytesToNumberLE, numberToBytesLE } from "@noble/curves/abstract/utils"; -import { bn254 } from "@noble/curves/bn254"; -import { keccak_256 } from "@noble/hashes/sha3"; import * as zerokitRLN from "@waku/zerokit-rln-wasm"; import { concatenate, writeUIntLE } from "./bytes.js"; @@ -17,16 +13,3 @@ export function sha256(input: Uint8Array): Uint8Array { const lenPrefixedData = concatenate(inputLen, input); return zerokitRLN.hash(lenPrefixedData); } - -export function hashToBN254(data: Uint8Array): Uint8Array { - // Hash the data using Keccak256 - const hashed = keccak_256(data); - - // Convert hash to a field element (big integer modulo BN254 field order) - const fieldElement = mod.mod(bytesToNumberLE(hashed), bn254.CURVE.Fp.ORDER); - - // Convert the field element back to bytes, ensuring 32 bytes length - const fixedLenBytes = numberToBytesLE(fieldElement, 32); - - return fixedLenBytes; -} diff --git a/src/zerokit.ts b/src/zerokit.ts index d167e82..9bf2546 100644 --- a/src/zerokit.ts +++ b/src/zerokit.ts @@ -5,7 +5,6 @@ import * as zerokitRLN from "@waku/zerokit-rln-wasm"; import { IdentityCredential } from "./identity.js"; import { Proof, proofToBytes } from "./proof.js"; import { WitnessCalculator } from "./resources/witness_calculator.js"; -import { hashToBN254 } from "./utils/hash.js"; import { concatenate, dateToEpoch, @@ -125,7 +124,7 @@ export class Zerokit { const proofData = await response.json(); const pathElements: Uint8Array[] = proofData.pathElements.map(hexToBytes); - // Serialize number of path lements and each hash in path elements to a single Uint8Array + // Serialize number of path elements and each hash in path elements to a single Uint8Array const pathElementsBytes = new Uint8Array(8 + pathElements.length * 32); writeUIntLE(pathElementsBytes, pathElements.length, 0, 8); for (let i = 0; i < pathElements.length; i++) { @@ -143,8 +142,8 @@ export class Zerokit { ); } - const hashToFieldMsg = hashToBN254(serialized_msg); - const hashToFieldRLNIdentifier = hashToBN254(RLN_IDENTIFIER); + const hashToFieldMsg = zerokitRLN.hash(serialized_msg); + const hashToFieldRLNIdentifier = zerokitRLN.hash(RLN_IDENTIFIER); // Append all Uint8Array elements to a single Uint8Array rlnWitness = concatBytes( idSecretHash,