@waku/rln 0.0.2-00f2e75.0 → 0.0.2-2380dac.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.
@@ -1,3 +1,3 @@
1
- var utils = {exports: {}};
1
+ var utils = {};
2
2
 
3
- export { utils as __module };
3
+ export { utils as __exports };
@@ -1,3 +1,3 @@
1
- var utils = {};
1
+ var utils = {exports: {}};
2
2
 
3
- export { utils as __exports };
3
+ export { utils as __module };
@@ -10,7 +10,6 @@ import { RATE_LIMIT_PARAMS, DEFAULT_RATE_LIMIT } from './constants.js';
10
10
  import { Contract } from '../../../../node_modules/@ethersproject/contracts/lib.esm/index.js';
11
11
  import { BigNumber } from '../../../../node_modules/@ethersproject/bignumber/lib.esm/bignumber.js';
12
12
 
13
- /* eslint-disable no-console */
14
13
  const log = new Logger("waku:rln:contract");
15
14
  var MembershipState;
16
15
  (function (MembershipState) {
@@ -26,7 +25,7 @@ class RLNContract {
26
25
  rateLimit;
27
26
  _members = new Map();
28
27
  _membersFilter;
29
- _membersRemovedFilter;
28
+ _membershipErasedFilter;
30
29
  _membersExpiredFilter;
31
30
  /**
32
31
  * Asynchronous initializer for RLNContract.
@@ -51,7 +50,7 @@ class RLNContract {
51
50
  this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
52
51
  // Initialize event filters
53
52
  this._membersFilter = this.contract.filters.MembershipRegistered();
54
- this._membersRemovedFilter = this.contract.filters.MembershipErased();
53
+ this._membershipErasedFilter = this.contract.filters.MembershipErased();
55
54
  this._membersExpiredFilter = this.contract.filters.MembershipExpired();
56
55
  }
57
56
  /**
@@ -109,12 +108,11 @@ class RLNContract {
109
108
  * @returns Promise<number> The remaining rate limit that can be allocated
110
109
  */
111
110
  async getRemainingTotalRateLimit() {
112
- // const [maxTotal, currentTotal] = await Promise.all([
113
- // this.contract.maxTotalRateLimit(),
114
- // this.contract.currentTotalRateLimit()
115
- // ]);
116
- // return maxTotal.sub(currentTotal).toNumber();
117
- return 10_000;
111
+ const [maxTotal, currentTotal] = await Promise.all([
112
+ this.contract.maxTotalRateLimit(),
113
+ this.contract.currentTotalRateLimit()
114
+ ]);
115
+ return Number(maxTotal) - Number(currentTotal);
118
116
  }
119
117
  /**
120
118
  * Updates the rate limit for future registrations
@@ -133,11 +131,11 @@ class RLNContract {
133
131
  }
134
132
  return this._membersFilter;
135
133
  }
136
- get membersRemovedFilter() {
137
- if (!this._membersRemovedFilter) {
138
- throw Error("MembersErased filter was not initialized.");
134
+ get membershipErasedFilter() {
135
+ if (!this._membershipErasedFilter) {
136
+ throw Error("MembershipErased filter was not initialized.");
139
137
  }
140
- return this._membersRemovedFilter;
138
+ return this._membershipErasedFilter;
141
139
  }
142
140
  get membersExpiredFilter() {
143
141
  if (!this._membersExpiredFilter) {
@@ -154,7 +152,7 @@ class RLNContract {
154
152
  const removedMemberEvents = await queryFilter(this.contract, {
155
153
  fromBlock: this.deployBlock,
156
154
  ...options,
157
- membersFilter: this.membersRemovedFilter
155
+ membersFilter: this.membershipErasedFilter
158
156
  });
159
157
  const expiredMemberEvents = await queryFilter(this.contract, {
160
158
  fromBlock: this.deployBlock,
@@ -251,7 +249,7 @@ class RLNContract {
251
249
  this.contract.on(this.membersFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
252
250
  this.processEvents(rlnInstance, [event]);
253
251
  });
254
- this.contract.on(this.membersRemovedFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
252
+ this.contract.on(this.membershipErasedFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
255
253
  this.processEvents(rlnInstance, [event]);
256
254
  });
257
255
  this.contract.on(this.membersExpiredFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
@@ -260,69 +258,40 @@ class RLNContract {
260
258
  }
261
259
  async registerWithIdentity(identity) {
262
260
  try {
263
- console.log("registerWithIdentity - starting registration process");
264
- console.log("registerWithIdentity - identity:", identity);
265
- console.log("registerWithIdentity - IDCommitmentBigInt:", identity.IDCommitmentBigInt.toString());
266
- console.log("registerWithIdentity - rate limit:", this.rateLimit);
267
261
  log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
268
262
  // Check if the ID commitment is already registered
269
263
  const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt.toString());
270
264
  if (existingIndex) {
271
- console.error(`ID commitment is already registered with index ${existingIndex}`);
272
265
  throw new Error(`ID commitment is already registered with index ${existingIndex}`);
273
266
  }
274
267
  // Check if there's enough remaining rate limit
275
268
  const remainingRateLimit = await this.getRemainingTotalRateLimit();
276
269
  if (remainingRateLimit < this.rateLimit) {
277
- console.error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
278
270
  throw new Error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
279
271
  }
280
- console.log("registerWithIdentity - calling contract.register");
281
- // Estimate gas for the transaction
282
272
  const estimatedGas = await this.contract.estimateGas.register(identity.IDCommitmentBigInt, this.rateLimit, []);
283
273
  const gasLimit = estimatedGas.add(10000);
284
274
  const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], { gasLimit });
285
- console.log("registerWithIdentity - txRegisterResponse:", txRegisterResponse);
286
- console.log("registerWithIdentity - hash:", txRegisterResponse.hash);
287
- console.log("registerWithIdentity - waiting for transaction confirmation...");
288
275
  const txRegisterReceipt = await txRegisterResponse.wait();
289
- console.log("registerWithIdentity - txRegisterReceipt:", txRegisterReceipt);
290
- console.log("registerWithIdentity - transaction status:", txRegisterReceipt.status);
291
- console.log("registerWithIdentity - block number:", txRegisterReceipt.blockNumber);
292
- console.log("registerWithIdentity - gas used:", txRegisterReceipt.gasUsed.toString());
293
- // Check transaction status
294
276
  if (txRegisterReceipt.status === 0) {
295
- console.error("Transaction failed on-chain");
296
277
  throw new Error("Transaction failed on-chain");
297
278
  }
298
279
  const memberRegistered = txRegisterReceipt.events?.find((event) => event.event === "MembershipRegistered");
299
- console.log("registerWithIdentity - memberRegistered event:", memberRegistered);
300
280
  if (!memberRegistered || !memberRegistered.args) {
301
- console.log("registerWithIdentity - ERROR: no memberRegistered event found");
302
- console.log("registerWithIdentity - all events:", txRegisterReceipt.events);
303
- console.error("Failed to register membership: No MembershipRegistered event found");
281
+ log.error("Failed to register membership: No MembershipRegistered event found");
304
282
  return undefined;
305
283
  }
306
- console.log("registerWithIdentity - memberRegistered args:", memberRegistered.args);
307
284
  const decodedData = {
308
285
  idCommitment: memberRegistered.args.idCommitment,
309
286
  membershipRateLimit: memberRegistered.args.membershipRateLimit,
310
287
  index: memberRegistered.args.index
311
288
  };
312
- console.log("registerWithIdentity - decodedData:", decodedData);
313
- console.log("registerWithIdentity - index:", decodedData.index.toString());
314
- console.log("registerWithIdentity - membershipRateLimit:", decodedData.membershipRateLimit.toString());
315
289
  log.info(`Successfully registered membership with index ${decodedData.index} ` +
316
290
  `and rate limit ${decodedData.membershipRateLimit}`);
317
- console.log("registerWithIdentity - getting network information");
318
291
  const network = await this.contract.provider.getNetwork();
319
- console.log("registerWithIdentity - network:", network);
320
- console.log("registerWithIdentity - chainId:", network.chainId);
321
292
  const address = this.contract.address;
322
- console.log("registerWithIdentity - contract address:", address);
323
293
  const membershipId = Number(decodedData.index);
324
- console.log("registerWithIdentity - membershipId:", membershipId);
325
- const result = {
294
+ return {
326
295
  identity,
327
296
  membership: {
328
297
  address,
@@ -330,39 +299,34 @@ class RLNContract {
330
299
  chainId: network.chainId
331
300
  }
332
301
  };
333
- console.log("registerWithIdentity - returning result:", result);
334
- return result;
335
302
  }
336
303
  catch (error) {
337
- console.log("registerWithIdentity - ERROR:", error);
338
- // Improved error handling to decode contract errors
339
304
  if (error instanceof Error) {
340
305
  const errorMessage = error.message;
341
- console.log("registerWithIdentity - error message:", errorMessage);
342
- console.log("registerWithIdentity - error stack:", error.stack);
306
+ log.error("registerWithIdentity - error message:", errorMessage);
307
+ log.error("registerWithIdentity - error stack:", error.stack);
343
308
  // Try to extract more specific error information
344
309
  if (errorMessage.includes("CannotExceedMaxTotalRateLimit")) {
345
- console.error("Registration failed: Cannot exceed maximum total rate limit");
310
+ throw new Error("Registration failed: Cannot exceed maximum total rate limit");
346
311
  }
347
312
  else if (errorMessage.includes("InvalidIdCommitment")) {
348
- console.error("Registration failed: Invalid ID commitment");
313
+ throw new Error("Registration failed: Invalid ID commitment");
349
314
  }
350
315
  else if (errorMessage.includes("InvalidMembershipRateLimit")) {
351
- console.error("Registration failed: Invalid membership rate limit");
316
+ throw new Error("Registration failed: Invalid membership rate limit");
352
317
  }
353
318
  else if (errorMessage.includes("execution reverted")) {
354
- // Generic revert
355
- console.error("Contract execution reverted. Check contract requirements.");
319
+ throw new Error("Contract execution reverted. Check contract requirements.");
356
320
  }
357
321
  else {
358
- console.error(`Error in registerWithIdentity: ${errorMessage}`);
322
+ throw new Error(`Error in registerWithIdentity: ${errorMessage}`);
359
323
  }
360
324
  }
361
325
  else {
362
- console.error("Unknown error in registerWithIdentity");
326
+ throw new Error("Unknown error in registerWithIdentity", {
327
+ cause: error
328
+ });
363
329
  }
364
- // Re-throw the error to allow callers to handle it
365
- throw error;
366
330
  }
367
331
  }
368
332
  /**
@@ -463,29 +427,17 @@ class RLNContract {
463
427
  }
464
428
  }
465
429
  async extendMembership(idCommitment) {
466
- const tx = await this.contract.extendMemberships([idCommitment]);
467
- return await tx.wait();
430
+ return this.contract.extendMemberships([idCommitment]);
468
431
  }
469
432
  async eraseMembership(idCommitment, eraseFromMembershipSet = true) {
470
- const tx = await this.contract.eraseMemberships([idCommitment], eraseFromMembershipSet);
471
- return await tx.wait();
433
+ return this.contract.eraseMemberships([idCommitment], eraseFromMembershipSet);
472
434
  }
473
435
  async registerMembership(idCommitment, rateLimit = DEFAULT_RATE_LIMIT) {
474
- try {
475
- if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
476
- rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
477
- throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
478
- }
479
- // Try to register
480
- return this.contract.register(idCommitment, rateLimit, []);
481
- }
482
- catch (error) {
483
- console.error("Error in registerMembership:", error);
484
- // Run debug to help diagnose the issue
485
- await this.debugRegistration(idCommitment, rateLimit);
486
- // Re-throw the error
487
- throw error;
436
+ if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
437
+ rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
438
+ throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
488
439
  }
440
+ return this.contract.register(idCommitment, rateLimit, []);
489
441
  }
490
442
  async getMemberIndex(idCommitment) {
491
443
  try {
@@ -500,74 +452,6 @@ class RLNContract {
500
452
  return undefined;
501
453
  }
502
454
  }
503
- /**
504
- * Debug function to check why a registration might fail
505
- * @param idCommitment The ID commitment to check
506
- * @param rateLimit The rate limit to check
507
- */
508
- async debugRegistration(idCommitment, rateLimit) {
509
- console.log("=== DEBUG REGISTRATION ===");
510
- console.log(`ID Commitment: ${idCommitment}`);
511
- console.log(`Rate Limit: ${rateLimit}`);
512
- // Check if ID commitment is already registered
513
- try {
514
- const existingIndex = await this.getMemberIndex(idCommitment);
515
- if (existingIndex) {
516
- console.error(`ERROR: ID commitment is already registered with index ${existingIndex}`);
517
- }
518
- else {
519
- console.log("ID commitment is not yet registered ✓");
520
- }
521
- }
522
- catch (error) {
523
- console.error("Error checking if ID commitment is registered:", error);
524
- }
525
- // Check rate limit constraints
526
- try {
527
- const minRateLimit = await this.getMinRateLimit();
528
- const maxRateLimit = await this.getMaxRateLimit();
529
- const maxTotalRateLimit = await this.getMaxTotalRateLimit();
530
- const currentTotalRateLimit = await this.getCurrentTotalRateLimit();
531
- const remainingRateLimit = await this.getRemainingTotalRateLimit();
532
- console.log(`Min Rate Limit: ${minRateLimit}`);
533
- console.log(`Max Rate Limit: ${maxRateLimit}`);
534
- console.log(`Max Total Rate Limit: ${maxTotalRateLimit}`);
535
- console.log(`Current Total Rate Limit: ${currentTotalRateLimit}`);
536
- console.log(`Remaining Rate Limit: ${remainingRateLimit}`);
537
- if (rateLimit < minRateLimit) {
538
- console.error(`ERROR: Rate limit ${rateLimit} is below minimum ${minRateLimit}`);
539
- }
540
- if (rateLimit > maxRateLimit) {
541
- console.error(`ERROR: Rate limit ${rateLimit} exceeds maximum ${maxRateLimit}`);
542
- }
543
- if (rateLimit > remainingRateLimit) {
544
- console.error(`ERROR: Rate limit ${rateLimit} exceeds remaining capacity ${remainingRateLimit}`);
545
- }
546
- }
547
- catch (error) {
548
- console.error("Error checking rate limit constraints:", error);
549
- }
550
- // Try to estimate gas for the transaction to see if it would revert
551
- try {
552
- await this.contract.estimateGas.register(idCommitment, rateLimit, []);
553
- console.log("Transaction gas estimation succeeded ✓");
554
- }
555
- catch (error) {
556
- console.error("Transaction would revert with error:", error);
557
- // Try to extract more specific error information
558
- const errorMessage = error.message;
559
- if (errorMessage.includes("CannotExceedMaxTotalRateLimit")) {
560
- console.error("Cannot exceed maximum total rate limit");
561
- }
562
- else if (errorMessage.includes("InvalidIdCommitment")) {
563
- console.error("Invalid ID commitment format");
564
- }
565
- else if (errorMessage.includes("InvalidMembershipRateLimit")) {
566
- console.error("Invalid membership rate limit");
567
- }
568
- }
569
- console.log("=== END DEBUG ===");
570
- }
571
455
  }
572
456
  // These values should be tested on other networks
573
457
  const FETCH_CHUNK = 5;
@@ -166,8 +166,6 @@ class RLNInstance {
166
166
  if ("signature" in options) {
167
167
  identity = this.zerokit.generateSeededIdentityCredential(options.signature);
168
168
  }
169
- // eslint-disable-next-line no-console
170
- console.log("registering membership", identity);
171
169
  if (!identity) {
172
170
  throw Error("Missing signature or identity to register membership.");
173
171
  }
@@ -1,6 +1,6 @@
1
1
  import { __exports as random } from '../../../../../../../_virtual/random.js';
2
2
  import '../../../../@noble/hashes/utils.js';
3
- import { __exports as utils } from '../../../../../../../_virtual/utils2.js';
3
+ import { __exports as utils } from '../../../../../../../_virtual/utils.js';
4
4
 
5
5
  Object.defineProperty(random, "__esModule", { value: true });
6
6
  random.getRandomBytes = random.getRandomBytesSync = undefined;
@@ -1,10 +1,10 @@
1
1
  import { commonjsGlobal } from '../../../../../../../_virtual/_commonjsHelpers.js';
2
2
  import { commonjsRequire } from '../../../../../../../_virtual/_commonjs-dynamic-modules.js';
3
- import { __module as utils } from '../../../../../../../_virtual/utils.js';
3
+ import { __module as utils } from '../../../../../../../_virtual/utils2.js';
4
4
  import '../../../../@noble/hashes/_assert.js';
5
5
  import '../../../../@noble/hashes/utils.js';
6
6
  import { __exports as _assert } from '../../../../../../../_virtual/_assert.js';
7
- import { __exports as utils$1 } from '../../../../../../../_virtual/utils2.js';
7
+ import { __exports as utils$1 } from '../../../../../../../_virtual/utils.js';
8
8
 
9
9
  utils.exports;
10
10
 
@@ -2,7 +2,7 @@ import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
2
2
  import './_assert.js';
3
3
  import './utils.js';
4
4
  import { __exports as _assert } from '../../../../../_virtual/_assert.js';
5
- import { __exports as utils } from '../../../../../_virtual/utils2.js';
5
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
6
6
 
7
7
  Object.defineProperty(_sha2, "__esModule", { value: true });
8
8
  _sha2.SHA2 = undefined;
@@ -2,7 +2,7 @@ import { __exports as hmac } from '../../../../../_virtual/hmac.js';
2
2
  import './_assert.js';
3
3
  import './utils.js';
4
4
  import { __exports as _assert } from '../../../../../_virtual/_assert.js';
5
- import { __exports as utils } from '../../../../../_virtual/utils2.js';
5
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
6
6
 
7
7
  (function (exports) {
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -2,7 +2,7 @@ import { __exports as pbkdf2$1 } from '../../../../../_virtual/pbkdf22.js';
2
2
  import './_assert.js';
3
3
  import './hmac.js';
4
4
  import './utils.js';
5
- import { __exports as utils } from '../../../../../_virtual/utils2.js';
5
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
6
6
  import { __exports as _assert } from '../../../../../_virtual/_assert.js';
7
7
  import { __exports as hmac } from '../../../../../_virtual/hmac.js';
8
8
 
@@ -3,7 +3,7 @@ import './_assert.js';
3
3
  import './sha256.js';
4
4
  import './pbkdf2.js';
5
5
  import './utils.js';
6
- import { __exports as utils } from '../../../../../_virtual/utils2.js';
6
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
7
7
  import { __exports as _assert } from '../../../../../_virtual/_assert.js';
8
8
  import { __exports as sha256 } from '../../../../../_virtual/sha2562.js';
9
9
  import { __exports as pbkdf2 } from '../../../../../_virtual/pbkdf22.js';
@@ -2,7 +2,7 @@ import { __exports as sha256 } from '../../../../../_virtual/sha2562.js';
2
2
  import './_sha2.js';
3
3
  import './utils.js';
4
4
  import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
5
- import { __exports as utils } from '../../../../../_virtual/utils2.js';
5
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
6
6
 
7
7
  Object.defineProperty(sha256, "__esModule", { value: true });
8
8
  sha256.sha224 = sha256.sha256 = undefined;
@@ -4,7 +4,7 @@ import './_u64.js';
4
4
  import './utils.js';
5
5
  import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
6
6
  import { __exports as _u64 } from '../../../../../_virtual/_u64.js';
7
- import { __exports as utils } from '../../../../../_virtual/utils2.js';
7
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
8
8
 
9
9
  Object.defineProperty(sha512, "__esModule", { value: true });
10
10
  sha512.sha384 = sha512.sha512_256 = sha512.sha512_224 = sha512.sha512 = sha512.SHA512 = undefined;
@@ -1,4 +1,4 @@
1
- import { __exports as utils } from '../../../../../_virtual/utils2.js';
1
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
2
2
  import './cryptoBrowser.js';
3
3
  import { __exports as cryptoBrowser } from '../../../../../_virtual/cryptoBrowser.js';
4
4