From 3ed2a7d49708b11516d492b293126babb8a7bd67 Mon Sep 17 00:00:00 2001 From: bdim1 Date: Thu, 21 Oct 2021 17:42:39 +0200 Subject: [PATCH] NRln rln_identifier added --- packages/protocols/src/nRln.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/protocols/src/nRln.ts b/packages/protocols/src/nRln.ts index 8e02dac..daa7390 100644 --- a/packages/protocols/src/nRln.ts +++ b/packages/protocols/src/nRln.ts @@ -9,6 +9,7 @@ class NRln extends ZkProtocol { * @param merkleProof merkle proof that identity exists in nrln tree * @param epoch epoch on which signal is broadcasted * @param signal signal that is being broadcasted + * @param rlnIdentifier identifier used by each separate app, needed for more accurate spam filtering * @param shouldHash should signal be hashed before broadcast * @returns rln witness */ @@ -17,6 +18,7 @@ class NRln extends ZkProtocol { merkleProof: any, epoch: string | bigint, signal: string, + rlnIdentifier: bigint, shouldHash = true ): any { return { @@ -24,7 +26,8 @@ class NRln extends ZkProtocol { path_elements: merkleProof.pathElements, identity_path_index: merkleProof.indices, x: shouldHash ? genSignalHash(signal) : signal, - epoch + epoch, + rln_identifier: rlnIdentifier } } @@ -34,9 +37,10 @@ class NRln extends ZkProtocol { * @param epoch epoch * @param x singal hash * @param limit number of messages per epoch allowed + * @param rlnIdentifier identifier used by each separate app, needed for more accurate spam filtering * @returns */ - calculateOutput(identitySecret: Array, epoch: bigint, x: bigint, limit: number): Array { + calculateOutput(identitySecret: Array, epoch: bigint, x: bigint, limit: number, rlnIdentifier: bigint): Array { const a0 = poseidonHash(identitySecret) const coeffs: Array = [] @@ -52,6 +56,7 @@ class NRln extends ZkProtocol { y = Fq.add(y, Fq.mul(coeffs[i], tmpX)) } + coeffs.push(poseidonHash([rlnIdentifier])); const nullifier: bigint = this.genNullifier(coeffs) return [y, nullifier] }