@waku/rln 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waku/rln",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Rate Limit Nullifier for js-waku",
5
5
  "types": "./dist/index.d.ts",
6
6
  "module": "./dist/index.js",
@@ -125,6 +125,6 @@
125
125
  ]
126
126
  },
127
127
  "dependencies": {
128
- "@waku/zerokit-rln-wasm": "^0.0.3"
128
+ "@waku/zerokit-rln-wasm": "^0.0.4"
129
129
  }
130
130
  }
package/src/message.ts CHANGED
@@ -18,7 +18,7 @@ export class RlnMessage<T extends Message> implements Message {
18
18
 
19
19
  public verify(): boolean | undefined {
20
20
  return this.rateLimitProof
21
- ? this.rlnInstance.verifyRLNProof(this.rateLimitProof, toRLNSignal(this))
21
+ ? this.rlnInstance.verifyWithRoots(this.rateLimitProof, toRLNSignal(this)) // this.rlnInstance.verifyRLNProof once issue status-im/nwaku#1248 is fixed
22
22
  : undefined;
23
23
  }
24
24
 
package/src/rln.ts CHANGED
@@ -129,6 +129,10 @@ export class RLNInstance {
129
129
  zerokitRLN.insertMember(this.zkRLN, idCommitment);
130
130
  }
131
131
 
132
+ getMerkleRoot(): Uint8Array {
133
+ return zerokitRLN.getRoot(this.zkRLN);
134
+ }
135
+
132
136
  serializeMessage(
133
137
  uint8Msg: Uint8Array,
134
138
  memIndex: number,
@@ -197,4 +201,28 @@ export class RLNInstance {
197
201
  concatenate(pBytes, msgLen, msg)
198
202
  );
199
203
  }
204
+
205
+ verifyWithRoots(
206
+ proof: RateLimitProof | Uint8Array,
207
+ msg: Uint8Array
208
+ ): boolean {
209
+ let pBytes: Uint8Array;
210
+ if (proof instanceof Uint8Array) {
211
+ pBytes = proof;
212
+ } else {
213
+ pBytes = proofToBytes(proof);
214
+ }
215
+
216
+ // calculate message length
217
+ const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
218
+
219
+ // obtain root
220
+ const root = zerokitRLN.getRoot(this.zkRLN);
221
+
222
+ return zerokitRLN.verifyWithRoots(
223
+ this.zkRLN,
224
+ concatenate(pBytes, msgLen, msg),
225
+ root
226
+ );
227
+ }
200
228
  }
Binary file