@waku/rln 0.1.5-9901863.0 → 0.1.5-aaa7a0c.0

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.
@@ -14,7 +14,6 @@ import {
14
14
  import _ from "lodash";
15
15
  import { v4 as uuidV4 } from "uuid";
16
16
 
17
- import { IdentityCredential } from "../identity.js";
18
17
  import { buildBigIntFromUint8Array } from "../utils/bytes.js";
19
18
 
20
19
  import { decryptEipKeystore, keccak256Checksum } from "./cipher.js";
@@ -251,32 +250,32 @@ export class Keystore {
251
250
  const str = bytesToUtf8(bytes);
252
251
  const obj = JSON.parse(str);
253
252
 
254
- // Get identity fields from named object
255
- const { idTrapdoor, idNullifier, idSecretHash, idCommitment } = _.get(
256
- obj,
257
- "identityCredential",
258
- {}
259
- );
260
-
261
- const idTrapdoorArray = new Uint8Array(idTrapdoor || []);
262
- const idNullifierArray = new Uint8Array(idNullifier || []);
263
- const idSecretHashArray = new Uint8Array(idSecretHash || []);
264
- const idCommitmentArray = new Uint8Array(idCommitment || []);
265
- const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitmentArray);
266
-
253
+ // TODO: add runtime validation of nwaku credentials
267
254
  return {
268
- identity: new IdentityCredential(
269
- idTrapdoorArray,
270
- idNullifierArray,
271
- idSecretHashArray,
272
- idCommitmentArray,
273
- idCommitmentBigInt
274
- ),
255
+ identity: {
256
+ IDCommitment: Keystore.fromArraylikeToBytes(
257
+ _.get(obj, "identityCredential.idCommitment", [])
258
+ ),
259
+ IDTrapdoor: Keystore.fromArraylikeToBytes(
260
+ _.get(obj, "identityCredential.idTrapdoor", [])
261
+ ),
262
+ IDNullifier: Keystore.fromArraylikeToBytes(
263
+ _.get(obj, "identityCredential.idNullifier", [])
264
+ ),
265
+ IDCommitmentBigInt: buildBigIntFromUint8Array(
266
+ Keystore.fromArraylikeToBytes(
267
+ _.get(obj, "identityCredential.idCommitment", [])
268
+ )
269
+ ),
270
+ IDSecretHash: Keystore.fromArraylikeToBytes(
271
+ _.get(obj, "identityCredential.idSecretHash", [])
272
+ )
273
+ },
275
274
  membership: {
276
275
  treeIndex: _.get(obj, "treeIndex"),
277
276
  chainId: _.get(obj, "membershipContract.chainId"),
278
277
  address: _.get(obj, "membershipContract.address"),
279
- rateLimit: _.get(obj, "userMessageLimit")
278
+ rateLimit: _.get(obj, "membershipContract.rateLimit")
280
279
  }
281
280
  };
282
281
  } catch (err) {
@@ -285,6 +284,30 @@ export class Keystore {
285
284
  }
286
285
  }
287
286
 
287
+ private static fromArraylikeToBytes(
288
+ obj:
289
+ | number[]
290
+ | {
291
+ [key: number]: number;
292
+ }
293
+ ): Uint8Array {
294
+ if (Array.isArray(obj)) {
295
+ return new Uint8Array(obj);
296
+ }
297
+
298
+ const bytes = [];
299
+ let index = 0;
300
+ let lastElement = obj[index];
301
+
302
+ while (lastElement !== undefined) {
303
+ bytes.push(lastElement);
304
+ index += 1;
305
+ lastElement = obj[index];
306
+ }
307
+
308
+ return new Uint8Array(bytes);
309
+ }
310
+
288
311
  // follows nwaku implementation
289
312
  // https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
290
313
  private static computeMembershipHash(info: MembershipInfo): MembershipHash {
@@ -298,18 +321,17 @@ export class Keystore {
298
321
  private static fromIdentityToBytes(options: KeystoreEntity): Uint8Array {
299
322
  return utf8ToBytes(
300
323
  JSON.stringify({
301
- membershipContract: {
302
- chainId: options.membership.chainId,
303
- address: options.membership.address
304
- },
305
324
  treeIndex: options.membership.treeIndex,
306
325
  identityCredential: {
307
- idTrapdoor: Array.from(options.identity.IDTrapdoor),
326
+ idCommitment: Array.from(options.identity.IDCommitment),
308
327
  idNullifier: Array.from(options.identity.IDNullifier),
309
328
  idSecretHash: Array.from(options.identity.IDSecretHash),
310
- idCommitment: Array.from(options.identity.IDCommitment)
329
+ idTrapdoor: Array.from(options.identity.IDTrapdoor)
311
330
  },
312
- userMessageLimit: options.membership.rateLimit
331
+ membershipContract: {
332
+ chainId: options.membership.chainId,
333
+ address: options.membership.address
334
+ }
313
335
  })
314
336
  );
315
337
  }
package/src/rln.ts CHANGED
@@ -58,6 +58,7 @@ export class RLNInstance extends RLNCredentialsManager {
58
58
  throw error;
59
59
  }
60
60
  }
61
+
61
62
  private constructor(public zerokit: Zerokit) {
62
63
  super(zerokit);
63
64
  }
package/src/zerokit.ts CHANGED
@@ -16,7 +16,7 @@ export class Zerokit {
16
16
  public constructor(
17
17
  private readonly zkRLN: number,
18
18
  private readonly witnessCalculator: WitnessCalculator,
19
- private readonly rateLimit: number = DEFAULT_RATE_LIMIT
19
+ private readonly _rateLimit: number = DEFAULT_RATE_LIMIT
20
20
  ) {}
21
21
 
22
22
  public get getZkRLN(): number {
@@ -27,8 +27,8 @@ export class Zerokit {
27
27
  return this.witnessCalculator;
28
28
  }
29
29
 
30
- public get getRateLimit(): number {
31
- return this.rateLimit;
30
+ public get rateLimit(): number {
31
+ return this._rateLimit;
32
32
  }
33
33
 
34
34
  public generateIdentityCredentials(): IdentityCredential {