@waku/rln 0.1.6-b7e9b08.0 → 0.1.6-f911bf8.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.
Files changed (58) hide show
  1. package/bundle/index.js +2 -1
  2. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +1 -1
  3. package/bundle/node_modules/{@ethersproject/keccak256/node_modules/js-sha3 → js-sha3}/src/sha3.js +2 -2
  4. package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +0 -3
  5. package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +3 -3
  6. package/bundle/packages/core/dist/lib/filter/filter.js +0 -3
  7. package/bundle/packages/core/dist/lib/light_push/light_push.js +0 -3
  8. package/bundle/packages/core/dist/lib/metadata/metadata.js +0 -3
  9. package/bundle/packages/core/dist/lib/store/store.js +3 -3
  10. package/bundle/packages/rln/dist/codec.js +3 -3
  11. package/bundle/packages/rln/dist/contract/constants.js +1 -0
  12. package/bundle/packages/rln/dist/contract/rln_base_contract.js +130 -74
  13. package/bundle/packages/rln/dist/contract/rln_contract.js +3 -3
  14. package/bundle/packages/rln/dist/credentials_manager.js +4 -4
  15. package/bundle/packages/rln/dist/identity.js +1 -1
  16. package/bundle/packages/rln/dist/keystore/keystore.js +4 -4
  17. package/bundle/packages/rln/dist/rln.js +3 -3
  18. package/bundle/packages/rln/dist/utils/bytes.js +6 -2
  19. package/bundle/packages/rln/dist/utils/epoch.js +3 -3
  20. package/bundle/packages/utils/dist/common/sharding/index.js +4 -4
  21. package/dist/.tsbuildinfo +1 -1
  22. package/dist/contract/index.d.ts +1 -0
  23. package/dist/contract/index.js +1 -0
  24. package/dist/contract/index.js.map +1 -1
  25. package/dist/contract/rln_base_contract.d.ts +32 -22
  26. package/dist/contract/rln_base_contract.js +127 -71
  27. package/dist/contract/rln_base_contract.js.map +1 -1
  28. package/dist/contract/types.d.ts +5 -0
  29. package/dist/contract/types.js.map +1 -1
  30. package/dist/credentials_manager.js +1 -1
  31. package/dist/credentials_manager.js.map +1 -1
  32. package/dist/identity.js +1 -1
  33. package/dist/identity.js.map +1 -1
  34. package/dist/index.d.ts +2 -1
  35. package/dist/index.js +1 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/keystore/keystore.js.map +1 -1
  38. package/dist/keystore/types.d.ts +2 -2
  39. package/dist/utils/bytes.js +6 -2
  40. package/dist/utils/bytes.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/contract/index.ts +1 -0
  43. package/src/contract/rln_base_contract.ts +166 -102
  44. package/src/contract/types.ts +5 -0
  45. package/src/credentials_manager.ts +1 -1
  46. package/src/identity.ts +1 -1
  47. package/src/index.ts +3 -1
  48. package/src/keystore/keystore.ts +4 -2
  49. package/src/keystore/types.ts +2 -2
  50. package/src/utils/bytes.ts +6 -2
  51. package/bundle/packages/utils/node_modules/@waku/interfaces/dist/connection_manager.js +0 -19
  52. package/bundle/packages/utils/node_modules/@waku/interfaces/dist/health_indicator.js +0 -12
  53. package/bundle/packages/utils/node_modules/@waku/interfaces/dist/protocols.js +0 -92
  54. /package/bundle/packages/{utils/node_modules/@waku/interfaces → interfaces}/dist/constants.js +0 -0
  55. /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/native.js +0 -0
  56. /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/rng.js +0 -0
  57. /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/stringify.js +0 -0
  58. /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/v4.js +0 -0
package/bundle/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  export { RLNDecoder, RLNEncoder } from './packages/rln/dist/codec.js';
2
2
  export { RLN_ABI } from './packages/rln/dist/contract/abi.js';
3
3
  export { RLNContract } from './packages/rln/dist/contract/rln_contract.js';
4
- export { LINEA_CONTRACT } from './packages/rln/dist/contract/constants.js';
4
+ export { DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS } from './packages/rln/dist/contract/constants.js';
5
+ export { MembershipState } from './packages/rln/dist/contract/types.js';
5
6
  export { RLNBaseContract } from './packages/rln/dist/contract/rln_base_contract.js';
6
7
  export { createRLN } from './packages/rln/dist/create.js';
7
8
  export { RLNCredentialsManager } from './packages/rln/dist/credentials_manager.js';
@@ -1,4 +1,4 @@
1
- import sha3 from '../node_modules/js-sha3/src/sha3.js';
1
+ import sha3 from '../../../js-sha3/src/sha3.js';
2
2
  import { arrayify } from '../../bytes/lib.esm/index.js';
3
3
 
4
4
  function keccak256(data) {
@@ -1,5 +1,5 @@
1
- import { getDefaultExportFromCjs, commonjsGlobal } from '../../../../../../_virtual/_commonjsHelpers.js';
2
- import { __module as sha3$1 } from '../../../../../../_virtual/sha3.js';
1
+ import { getDefaultExportFromCjs, commonjsGlobal } from '../../../_virtual/_commonjsHelpers.js';
2
+ import { __module as sha3$1 } from '../../../_virtual/sha3.js';
3
3
 
4
4
  /**
5
5
  * [js-sha3]{@link https://github.com/emn178/js-sha3}
@@ -15,9 +15,6 @@ import '../../../../../node_modules/@multiformats/multiaddr/dist/src/multiaddr.j
15
15
  import '../../../../interfaces/dist/protocols.js';
16
16
  import '../../../../interfaces/dist/connection_manager.js';
17
17
  import '../../../../interfaces/dist/health_indicator.js';
18
- import '../../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
19
- import '../../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
20
- import '../../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
21
18
  import { Logger } from '../../../../utils/dist/logger/index.js';
22
19
  import './keep_alive_manager.js';
23
20
 
@@ -1,6 +1,6 @@
1
- import '../../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
2
- import '../../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
3
- import '../../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
1
+ import '../../../../interfaces/dist/protocols.js';
2
+ import '../../../../interfaces/dist/connection_manager.js';
3
+ import '../../../../interfaces/dist/health_indicator.js';
4
4
  import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
5
5
  import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
6
6
  import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -1,9 +1,6 @@
1
1
  import '../../../../interfaces/dist/protocols.js';
2
2
  import '../../../../interfaces/dist/connection_manager.js';
3
3
  import '../../../../interfaces/dist/health_indicator.js';
4
- import '../../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
5
- import '../../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
6
- import '../../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
7
4
  import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
8
5
  import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
9
6
  import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -10,9 +10,6 @@ import '../../../../proto/dist/generated/store_v3.js';
10
10
  import '../../../../proto/dist/generated/peer_exchange.js';
11
11
  import '../../../../proto/dist/generated/metadata.js';
12
12
  import '../../../../proto/dist/generated/sds_message.js';
13
- import '../../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
14
- import '../../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
15
- import '../../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
16
13
  import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
17
14
  import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
18
15
  import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -10,9 +10,6 @@ import '../../../../proto/dist/generated/store_v3.js';
10
10
  import '../../../../proto/dist/generated/peer_exchange.js';
11
11
  import '../../../../proto/dist/generated/metadata.js';
12
12
  import '../../../../proto/dist/generated/sds_message.js';
13
- import '../../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
14
- import '../../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
15
- import '../../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
16
13
  import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
17
14
  import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
18
15
  import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -1,6 +1,6 @@
1
- import '../../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
2
- import '../../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
3
- import '../../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
1
+ import '../../../../interfaces/dist/protocols.js';
2
+ import '../../../../interfaces/dist/connection_manager.js';
3
+ import '../../../../interfaces/dist/health_indicator.js';
4
4
  import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
5
5
  import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
6
6
  import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -1,6 +1,6 @@
1
- import '../../utils/node_modules/@waku/interfaces/dist/protocols.js';
2
- import '../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
3
- import '../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
1
+ import '../../interfaces/dist/protocols.js';
2
+ import '../../interfaces/dist/connection_manager.js';
3
+ import '../../interfaces/dist/health_indicator.js';
4
4
  import '../../../node_modules/multiformats/dist/src/bases/base10.js';
5
5
  import '../../../node_modules/multiformats/dist/src/bases/base16.js';
6
6
  import '../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -12,6 +12,7 @@ const LINEA_CONTRACT = {
12
12
  */
13
13
  const RATE_LIMIT_TIERS = {
14
14
  LOW: 20, // Suggested minimum rate - 20 messages per epoch
15
+ MEDIUM: 200,
15
16
  HIGH: 600 // Suggested maximum rate - 600 messages per epoch
16
17
  };
17
18
  // Global rate limit parameters
@@ -1,6 +1,6 @@
1
- import '../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
2
- import '../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
3
- import '../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
1
+ import '../../../interfaces/dist/protocols.js';
2
+ import '../../../interfaces/dist/connection_manager.js';
3
+ import '../../../interfaces/dist/health_indicator.js';
4
4
  import '../../../../node_modules/multiformats/dist/src/bases/base10.js';
5
5
  import '../../../../node_modules/multiformats/dist/src/bases/base16.js';
6
6
  import '../../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -24,15 +24,32 @@ class RLNBaseContract {
24
24
  contract;
25
25
  deployBlock;
26
26
  rateLimit;
27
+ minRateLimit;
28
+ maxRateLimit;
27
29
  _members = new Map();
28
30
  _membersFilter;
29
31
  _membershipErasedFilter;
30
32
  _membersExpiredFilter;
31
33
  /**
32
- * Constructor for RLNBaseContract.
33
- * Allows injecting a mocked contract for testing purposes.
34
+ * Private constructor for RLNBaseContract. Use static create() instead.
34
35
  */
35
36
  constructor(options) {
37
+ const { address, signer, rateLimit = DEFAULT_RATE_LIMIT, contract } = options;
38
+ log.info("Initializing RLNBaseContract", { address, rateLimit });
39
+ this.contract = contract || new Contract(address, RLN_ABI, signer);
40
+ this.rateLimit = rateLimit;
41
+ try {
42
+ log.info("Setting up event filters");
43
+ // Initialize event filters
44
+ this._membersFilter = this.contract.filters.MembershipRegistered();
45
+ this._membershipErasedFilter = this.contract.filters.MembershipErased();
46
+ this._membersExpiredFilter = this.contract.filters.MembershipExpired();
47
+ log.info("Event filters initialized successfully");
48
+ }
49
+ catch (error) {
50
+ log.error("Failed to initialize event filters", { error });
51
+ throw new Error("Failed to initialize event filters: " + error.message);
52
+ }
36
53
  // Initialize members and subscriptions
37
54
  this.fetchMembers()
38
55
  .then(() => {
@@ -41,14 +58,20 @@ class RLNBaseContract {
41
58
  .catch((error) => {
42
59
  log.error("Failed to initialize members", { error });
43
60
  });
44
- const { address, signer, rateLimit = DEFAULT_RATE_LIMIT, contract } = options;
45
- this.validateRateLimit(rateLimit);
46
- this.contract = contract || new Contract(address, RLN_ABI, signer);
47
- this.rateLimit = rateLimit;
48
- // Initialize event filters
49
- this._membersFilter = this.contract.filters.MembershipRegistered();
50
- this._membershipErasedFilter = this.contract.filters.MembershipErased();
51
- this._membersExpiredFilter = this.contract.filters.MembershipExpired();
61
+ }
62
+ /**
63
+ * Static async factory to create and initialize RLNBaseContract
64
+ */
65
+ static async create(options) {
66
+ const instance = new RLNBaseContract(options);
67
+ const [min, max] = await Promise.all([
68
+ instance.contract.minMembershipRateLimit(),
69
+ instance.contract.maxMembershipRateLimit()
70
+ ]);
71
+ instance.minRateLimit = BigNumber.from(min).toNumber();
72
+ instance.maxRateLimit = BigNumber.from(max).toNumber();
73
+ instance.validateRateLimit(instance.rateLimit);
74
+ return instance;
52
75
  }
53
76
  /**
54
77
  * Gets the current rate limit for this contract instance
@@ -69,20 +92,20 @@ class RLNBaseContract {
69
92
  return this.contract.provider;
70
93
  }
71
94
  /**
72
- * Gets the minimum allowed rate limit from the contract
73
- * @returns Promise<number> The minimum rate limit in messages per epoch
95
+ * Gets the minimum allowed rate limit (cached)
74
96
  */
75
- async getMinRateLimit() {
76
- const minRate = await this.contract.minMembershipRateLimit();
77
- return BigNumber.from(minRate).toNumber();
97
+ getMinRateLimit() {
98
+ if (this.minRateLimit === undefined)
99
+ throw new Error("minRateLimit not initialized");
100
+ return this.minRateLimit;
78
101
  }
79
102
  /**
80
- * Gets the maximum allowed rate limit from the contract
81
- * @returns Promise<number> The maximum rate limit in messages per epoch
103
+ * Gets the maximum allowed rate limit (cached)
82
104
  */
83
- async getMaxRateLimit() {
84
- const maxRate = await this.contract.maxMembershipRateLimit();
85
- return BigNumber.from(maxRate).toNumber();
105
+ getMaxRateLimit() {
106
+ if (this.maxRateLimit === undefined)
107
+ throw new Error("maxRateLimit not initialized");
108
+ return this.maxRateLimit;
86
109
  }
87
110
  /**
88
111
  * Gets the maximum total rate limit across all memberships
@@ -115,7 +138,7 @@ class RLNBaseContract {
115
138
  * Updates the rate limit for future registrations
116
139
  * @param newRateLimit The new rate limit to use
117
140
  */
118
- async setRateLimit(newRateLimit) {
141
+ setRateLimit(newRateLimit) {
119
142
  this.validateRateLimit(newRateLimit);
120
143
  this.rateLimit = newRateLimit;
121
144
  }
@@ -247,75 +270,67 @@ class RLNBaseContract {
247
270
  this.processEvents([event]);
248
271
  });
249
272
  }
250
- /**
251
- * Helper method to get remaining messages in current epoch
252
- * @param membershipId The ID of the membership to check
253
- * @returns number of remaining messages allowed in current epoch
254
- */
255
- async getRemainingMessages(membershipId) {
256
- try {
257
- const [startTime, , rateLimit] = await this.contract.getMembershipInfo(membershipId);
258
- // Calculate current epoch
259
- const currentTime = Math.floor(Date.now() / 1000);
260
- const epochsPassed = Math.floor((currentTime - startTime) / RATE_LIMIT_PARAMS.EPOCH_LENGTH);
261
- const currentEpochStart = startTime + epochsPassed * RATE_LIMIT_PARAMS.EPOCH_LENGTH;
262
- // Get message count in current epoch using contract's function
263
- const messageCount = await this.contract.getMessageCount(membershipId, currentEpochStart);
264
- return Math.max(0, BigNumber.from(rateLimit)
265
- .sub(BigNumber.from(messageCount))
266
- .toNumber());
267
- }
268
- catch (error) {
269
- log.error(`Error getting remaining messages: ${error.message}`);
270
- return 0; // Fail safe: assume no messages remaining on error
271
- }
272
- }
273
- async getMembershipInfo(idCommitment) {
273
+ async getMembershipInfo(idCommitmentBigInt) {
274
274
  try {
275
- const [startBlock, endBlock, rateLimit] = await this.contract.getMembershipInfo(idCommitment);
275
+ const membershipData = await this.contract.memberships(idCommitmentBigInt);
276
276
  const currentBlock = await this.contract.provider.getBlockNumber();
277
+ const [depositAmount, activeDuration, gracePeriodStartTimestamp, gracePeriodDuration, rateLimit, index, holder, token] = membershipData;
278
+ const gracePeriodEnd = gracePeriodStartTimestamp.add(gracePeriodDuration);
277
279
  let state;
278
- if (currentBlock < startBlock) {
280
+ if (currentBlock < gracePeriodStartTimestamp.toNumber()) {
279
281
  state = MembershipState.Active;
280
282
  }
281
- else if (currentBlock < endBlock) {
283
+ else if (currentBlock < gracePeriodEnd.toNumber()) {
282
284
  state = MembershipState.GracePeriod;
283
285
  }
284
286
  else {
285
287
  state = MembershipState.Expired;
286
288
  }
287
- const index = await this.getMemberIndex(idCommitment);
288
- if (!index)
289
- return undefined;
290
289
  return {
291
290
  index,
292
- idCommitment,
293
- rateLimit: rateLimit.toNumber(),
294
- startBlock: startBlock.toNumber(),
295
- endBlock: endBlock.toNumber(),
296
- state
291
+ idCommitment: idCommitmentBigInt.toString(),
292
+ rateLimit: Number(rateLimit),
293
+ startBlock: gracePeriodStartTimestamp.toNumber(),
294
+ endBlock: gracePeriodEnd.toNumber(),
295
+ state,
296
+ depositAmount,
297
+ activeDuration,
298
+ gracePeriodDuration,
299
+ holder,
300
+ token
297
301
  };
298
302
  }
299
303
  catch (error) {
304
+ log.error("Error in getMembershipInfo:", error);
300
305
  return undefined;
301
306
  }
302
307
  }
303
- async extendMembership(idCommitment) {
304
- return this.contract.extendMemberships([idCommitment]);
308
+ async extendMembership(idCommitmentBigInt) {
309
+ const tx = await this.contract.extendMemberships([idCommitmentBigInt]);
310
+ await tx.wait();
311
+ return tx;
305
312
  }
306
- async eraseMembership(idCommitment, eraseFromMembershipSet = true) {
307
- return this.contract.eraseMemberships([idCommitment], eraseFromMembershipSet);
313
+ async eraseMembership(idCommitmentBigInt, eraseFromMembershipSet = true) {
314
+ if (!(await this.isExpired(idCommitmentBigInt)) ||
315
+ !(await this.isInGracePeriod(idCommitmentBigInt))) {
316
+ throw new Error("Membership is not expired or in grace period");
317
+ }
318
+ const estimatedGas = await this.contract.estimateGas["eraseMemberships(uint256[],bool)"]([idCommitmentBigInt], eraseFromMembershipSet);
319
+ const gasLimit = estimatedGas.add(10000);
320
+ const tx = await this.contract["eraseMemberships(uint256[],bool)"]([idCommitmentBigInt], eraseFromMembershipSet, { gasLimit });
321
+ await tx.wait();
322
+ return tx;
308
323
  }
309
- async registerMembership(idCommitment, rateLimit = DEFAULT_RATE_LIMIT) {
324
+ async registerMembership(idCommitmentBigInt, rateLimit = DEFAULT_RATE_LIMIT) {
310
325
  if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
311
326
  rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
312
327
  throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
313
328
  }
314
- return this.contract.register(idCommitment, rateLimit, []);
329
+ return this.contract.register(idCommitmentBigInt, rateLimit, []);
315
330
  }
316
- async withdraw(token, holder) {
331
+ async withdraw(token, from) {
317
332
  try {
318
- const tx = await this.contract.withdraw(token, { from: holder });
333
+ const tx = await this.contract.withdraw(token, from);
319
334
  await tx.wait();
320
335
  }
321
336
  catch (error) {
@@ -326,7 +341,7 @@ class RLNBaseContract {
326
341
  try {
327
342
  log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
328
343
  // Check if the ID commitment is already registered
329
- const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt.toString());
344
+ const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt);
330
345
  if (existingIndex) {
331
346
  throw new Error(`ID commitment is already registered with index ${existingIndex}`);
332
347
  }
@@ -432,13 +447,15 @@ class RLNBaseContract {
432
447
  }
433
448
  }
434
449
  /**
435
- * Validates that the rate limit is within the allowed range
450
+ * Validates that the rate limit is within the allowed range (sync)
436
451
  * @throws Error if the rate limit is outside the allowed range
437
452
  */
438
453
  validateRateLimit(rateLimit) {
439
- if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
440
- rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
441
- throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE} messages per epoch`);
454
+ if (this.minRateLimit === undefined || this.maxRateLimit === undefined) {
455
+ throw new Error("Rate limits not initialized");
456
+ }
457
+ if (rateLimit < this.minRateLimit || rateLimit > this.maxRateLimit) {
458
+ throw new Error(`Rate limit must be between ${this.minRateLimit} and ${this.maxRateLimit} messages per epoch`);
442
459
  }
443
460
  }
444
461
  get membersFilter() {
@@ -459,9 +476,9 @@ class RLNBaseContract {
459
476
  }
460
477
  return this._membersExpiredFilter;
461
478
  }
462
- async getMemberIndex(idCommitment) {
479
+ async getMemberIndex(idCommitmentBigInt) {
463
480
  try {
464
- const events = await this.contract.queryFilter(this.contract.filters.MembershipRegistered(idCommitment));
481
+ const events = await this.contract.queryFilter(this.contract.filters.MembershipRegistered(idCommitmentBigInt));
465
482
  if (events.length === 0)
466
483
  return undefined;
467
484
  // Get the most recent registration event
@@ -472,6 +489,45 @@ class RLNBaseContract {
472
489
  return undefined;
473
490
  }
474
491
  }
492
+ async getMembershipStatus(idCommitment) {
493
+ const [isExpired, isInGrace] = await Promise.all([
494
+ this.contract.isExpired(idCommitment),
495
+ this.contract.isInGracePeriod(idCommitment)
496
+ ]);
497
+ if (isExpired)
498
+ return "expired";
499
+ if (isInGrace)
500
+ return "grace";
501
+ return "active";
502
+ }
503
+ /**
504
+ * Checks if a membership is expired for the given idCommitment
505
+ * @param idCommitmentBigInt The idCommitment as bigint
506
+ * @returns Promise<boolean> True if expired, false otherwise
507
+ */
508
+ async isExpired(idCommitmentBigInt) {
509
+ try {
510
+ return await this.contract.isExpired(idCommitmentBigInt);
511
+ }
512
+ catch (error) {
513
+ log.error("Error in isExpired:", error);
514
+ return false;
515
+ }
516
+ }
517
+ /**
518
+ * Checks if a membership is in grace period for the given idCommitment
519
+ * @param idCommitmentBigInt The idCommitment as bigint
520
+ * @returns Promise<boolean> True if in grace period, false otherwise
521
+ */
522
+ async isInGracePeriod(idCommitmentBigInt) {
523
+ try {
524
+ return await this.contract.isInGracePeriod(idCommitmentBigInt);
525
+ }
526
+ catch (error) {
527
+ log.error("Error in isInGracePeriod:", error);
528
+ return false;
529
+ }
530
+ }
475
531
  }
476
532
 
477
533
  export { RLNBaseContract };
@@ -1,6 +1,6 @@
1
- import '../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
2
- import '../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
3
- import '../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
1
+ import '../../../interfaces/dist/protocols.js';
2
+ import '../../../interfaces/dist/connection_manager.js';
3
+ import '../../../interfaces/dist/health_indicator.js';
4
4
  import { hexToBytes } from '../../../utils/dist/bytes/index.js';
5
5
  import { Logger } from '../../../utils/dist/logger/index.js';
6
6
  import { MerkleRootTracker } from '../root_tracker.js';
@@ -1,8 +1,8 @@
1
1
  import { hmac } from '../../../node_modules/@noble/hashes/esm/hmac.js';
2
2
  import { sha256 } from '../../../node_modules/@noble/hashes/esm/sha256.js';
3
- import '../../utils/node_modules/@waku/interfaces/dist/protocols.js';
4
- import '../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
5
- import '../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
3
+ import '../../interfaces/dist/protocols.js';
4
+ import '../../interfaces/dist/connection_manager.js';
5
+ import '../../interfaces/dist/health_indicator.js';
6
6
  import '../../../node_modules/multiformats/dist/src/bases/base10.js';
7
7
  import '../../../node_modules/multiformats/dist/src/bases/base16.js';
8
8
  import '../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -64,7 +64,7 @@ class RLNCredentialsManager {
64
64
  }
65
65
  this.credentials = credentials;
66
66
  this.signer = signer;
67
- this.contract = new RLNBaseContract({
67
+ this.contract = await RLNBaseContract.create({
68
68
  address: address,
69
69
  signer: signer,
70
70
  rateLimit: rateLimit ?? this.zerokit?.rateLimit
@@ -22,7 +22,7 @@ class IdentityCredential {
22
22
  const idNullifier = memKeys.subarray(32, 64);
23
23
  const idSecretHash = memKeys.subarray(64, 96);
24
24
  const idCommitment = memKeys.subarray(96, 128);
25
- const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
25
+ const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
26
26
  return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
27
27
  }
28
28
  }
@@ -1,7 +1,7 @@
1
1
  import '../../../../node_modules/@chainsafe/bls-keystore/lib/index.js';
2
- import '../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
3
- import '../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
4
- import '../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
2
+ import '../../../interfaces/dist/protocols.js';
3
+ import '../../../interfaces/dist/connection_manager.js';
4
+ import '../../../interfaces/dist/health_indicator.js';
5
5
  import '../../../../node_modules/multiformats/dist/src/bases/base10.js';
6
6
  import '../../../../node_modules/multiformats/dist/src/bases/base16.js';
7
7
  import '../../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -21,7 +21,7 @@ import { buildBigIntFromUint8Array } from '../utils/bytes.js';
21
21
  import { keccak256Checksum, decryptEipKeystore } from './cipher.js';
22
22
  import { isKeystoreValid, isCredentialValid } from './schema_validator.js';
23
23
  import { __exports as lib } from '../../../../_virtual/index.js';
24
- import v4 from '../../../../node_modules/uuid/dist/esm-browser/v4.js';
24
+ import v4 from '../../node_modules/uuid/dist/esm-browser/v4.js';
25
25
  import { bytesToHex, utf8ToBytes } from '../../../../node_modules/@noble/hashes/esm/utils.js';
26
26
 
27
27
  const log = new Logger("waku:rln:keystore");
@@ -3,9 +3,9 @@ import '../../core/dist/lib/filter/filter.js';
3
3
  import '../../core/dist/lib/light_push/light_push.js';
4
4
  import '../../core/dist/lib/store/store.js';
5
5
  import '../../core/dist/lib/connection_manager/connection_manager.js';
6
- import '../../utils/node_modules/@waku/interfaces/dist/protocols.js';
7
- import '../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
8
- import '../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
6
+ import '../../interfaces/dist/protocols.js';
7
+ import '../../interfaces/dist/connection_manager.js';
8
+ import '../../interfaces/dist/health_indicator.js';
9
9
  import '../../../node_modules/multiformats/dist/src/bases/base10.js';
10
10
  import '../../../node_modules/multiformats/dist/src/bases/base16.js';
11
11
  import '../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -45,8 +45,12 @@ function writeUIntLE(buf, value, offset, byteLength, noAssert) {
45
45
  * @returns BigInt
46
46
  */
47
47
  function buildBigIntFromUint8Array(array, byteOffset = 0) {
48
- const dataView = new DataView(array.buffer);
49
- return dataView.getBigUint64(byteOffset, true);
48
+ // Use all bytes from byteOffset to the end, big-endian
49
+ let hex = "";
50
+ for (let i = byteOffset; i < array.length; i++) {
51
+ hex += array[i].toString(16).padStart(2, "0");
52
+ }
53
+ return BigInt("0x" + hex);
50
54
  }
51
55
  /**
52
56
  * Fills with zeros to set length
@@ -1,6 +1,6 @@
1
- import '../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
2
- import '../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
3
- import '../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
1
+ import '../../../interfaces/dist/protocols.js';
2
+ import '../../../interfaces/dist/connection_manager.js';
3
+ import '../../../interfaces/dist/health_indicator.js';
4
4
  import '../../../../node_modules/multiformats/dist/src/bases/base10.js';
5
5
  import '../../../../node_modules/multiformats/dist/src/bases/base16.js';
6
6
  import '../../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -1,8 +1,8 @@
1
1
  import { sha256 } from '../../../../../node_modules/@noble/hashes/esm/sha256.js';
2
- import '../../../node_modules/@waku/interfaces/dist/protocols.js';
3
- import '../../../node_modules/@waku/interfaces/dist/connection_manager.js';
4
- import { DEFAULT_CLUSTER_ID } from '../../../node_modules/@waku/interfaces/dist/constants.js';
5
- import '../../../node_modules/@waku/interfaces/dist/health_indicator.js';
2
+ import '../../../../interfaces/dist/protocols.js';
3
+ import '../../../../interfaces/dist/connection_manager.js';
4
+ import { DEFAULT_CLUSTER_ID } from '../../../../interfaces/dist/constants.js';
5
+ import '../../../../interfaces/dist/health_indicator.js';
6
6
  import { concat, utf8ToBytes } from '../../bytes/index.js';
7
7
 
8
8
  const singleShardInfoToPubsubTopic = (shardInfo) => {