mirror of
https://github.com/logos-messaging/js-rln.git
synced 2026-01-02 13:43:06 +00:00
fix: use correct hash and x value for proof
This commit is contained in:
parent
25607793e7
commit
06d00e1742
1
package-lock.json
generated
1
package-lock.json
generated
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user