@waku/rln 0.1.4-d27db21.0 → 0.1.5-76f86de.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 (92) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +5 -0
  3. package/bundle/index.js +1 -1
  4. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +1 -1
  5. package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +1 -1
  6. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +1 -1
  7. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +11 -11
  8. package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +1 -1
  9. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +7 -7
  10. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +2 -2
  11. package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +2 -2
  12. package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +1 -1
  13. package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +1 -1
  14. package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +1 -1
  15. package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +44 -44
  16. package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +8 -8
  17. package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +1 -1
  18. package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +1 -1
  19. package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +1 -1
  20. package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +2 -2
  21. package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +1 -0
  22. package/bundle/node_modules/@noble/hashes/esm/sha3.js +1 -1
  23. package/bundle/node_modules/bn.js/lib/bn.js +1 -1
  24. package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +6 -6
  25. package/bundle/packages/rln/dist/contract/abi.js +502 -248
  26. package/bundle/packages/rln/dist/contract/constants.js +4 -5
  27. package/bundle/packages/rln/dist/contract/rln_contract.js +121 -37
  28. package/bundle/packages/rln/dist/keystore/keystore.js +2 -1
  29. package/bundle/packages/rln/dist/rln.js +4 -4
  30. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +2 -2
  31. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +3 -3
  32. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +4 -4
  33. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +4 -4
  34. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +4 -4
  35. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +1 -1
  36. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
  37. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +1 -1
  38. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +1 -1
  39. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +1 -1
  40. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
  41. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +1 -1
  42. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +1 -1
  43. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +1 -1
  44. package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +1 -1
  45. package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +2 -2
  46. package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +1 -1
  47. package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
  48. package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +2 -2
  49. package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +1 -1
  50. package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +2 -2
  51. package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +1 -1
  52. package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +2 -2
  53. package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +1 -1
  54. package/dist/.tsbuildinfo +1 -1
  55. package/dist/codec.test-utils.d.ts +36 -0
  56. package/dist/codec.test-utils.js +56 -0
  57. package/dist/codec.test-utils.js.map +1 -0
  58. package/dist/contract/abi.d.ts +21 -17
  59. package/dist/contract/abi.js +502 -248
  60. package/dist/contract/abi.js.map +1 -1
  61. package/dist/contract/constants.d.ts +22 -18
  62. package/dist/contract/constants.js +3 -3
  63. package/dist/contract/constants.js.map +1 -1
  64. package/dist/contract/rln_contract.d.ts +10 -3
  65. package/dist/contract/rln_contract.js +120 -36
  66. package/dist/contract/rln_contract.js.map +1 -1
  67. package/dist/contract/test-setup.d.ts +26 -0
  68. package/dist/contract/test-setup.js +56 -0
  69. package/dist/contract/test-setup.js.map +1 -0
  70. package/dist/contract/test-utils.d.ts +39 -0
  71. package/dist/contract/test-utils.js +118 -0
  72. package/dist/contract/test-utils.js.map +1 -0
  73. package/dist/index.d.ts +3 -2
  74. package/dist/index.js +2 -2
  75. package/dist/index.js.map +1 -1
  76. package/dist/keystore/keystore.js +2 -1
  77. package/dist/keystore/keystore.js.map +1 -1
  78. package/dist/keystore/types.d.ts +1 -0
  79. package/dist/rln.d.ts +1 -1
  80. package/dist/rln.js +4 -4
  81. package/dist/rln.js.map +1 -1
  82. package/package.json +1 -1
  83. package/src/codec.test-utils.ts +80 -0
  84. package/src/contract/abi.ts +502 -248
  85. package/src/contract/constants.ts +3 -3
  86. package/src/contract/rln_contract.ts +158 -46
  87. package/src/contract/test-setup.ts +86 -0
  88. package/src/contract/test-utils.ts +179 -0
  89. package/src/index.ts +13 -2
  90. package/src/keystore/keystore.ts +2 -1
  91. package/src/keystore/types.ts +1 -0
  92. package/src/rln.ts +5 -5
@@ -1,8 +1,8 @@
1
1
  import { RLN_ABI } from './abi.js';
2
2
 
3
- const SEPOLIA_CONTRACT = {
4
- chainId: 11155111,
5
- address: "0xCB33Aa5B38d79E3D9Fa8B10afF38AA201399a7e3",
3
+ const LINEA_CONTRACT = {
4
+ chainId: 59141,
5
+ address: "0xb9cd878c90e49f797b4431fbf4fb333108cb90e6",
6
6
  abi: RLN_ABI
7
7
  };
8
8
  /**
@@ -12,7 +12,6 @@ const SEPOLIA_CONTRACT = {
12
12
  */
13
13
  const RATE_LIMIT_TIERS = {
14
14
  LOW: 20, // Suggested minimum rate - 20 messages per epoch
15
- MEDIUM: 200,
16
15
  HIGH: 600 // Suggested maximum rate - 600 messages per epoch
17
16
  };
18
17
  // Global rate limit parameters
@@ -24,4 +23,4 @@ const RATE_LIMIT_PARAMS = {
24
23
  };
25
24
  const DEFAULT_RATE_LIMIT = RATE_LIMIT_PARAMS.MAX_RATE;
26
25
 
27
- export { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS, SEPOLIA_CONTRACT };
26
+ export { DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS };
@@ -6,7 +6,7 @@ import { Logger } from '../../../utils/dist/logger/index.js';
6
6
  import { MerkleRootTracker } from '../root_tracker.js';
7
7
  import { zeroPadLE } from '../utils/bytes.js';
8
8
  import { RLN_ABI } from './abi.js';
9
- import { RATE_LIMIT_PARAMS, DEFAULT_RATE_LIMIT } from './constants.js';
9
+ import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } 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
 
@@ -25,7 +25,8 @@ class RLNContract {
25
25
  rateLimit;
26
26
  _members = new Map();
27
27
  _membersFilter;
28
- _membersRemovedFilter;
28
+ _membershipErasedFilter;
29
+ _membersExpiredFilter;
29
30
  /**
30
31
  * Asynchronous initializer for RLNContract.
31
32
  * Allows injecting a mocked contract for testing purposes.
@@ -38,18 +39,26 @@ class RLNContract {
38
39
  }
39
40
  constructor(rlnInstance, options) {
40
41
  const { address, signer, rateLimit = DEFAULT_RATE_LIMIT, contract } = options;
41
- if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
42
- rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
43
- throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE} messages per epoch`);
44
- }
42
+ this.validateRateLimit(rateLimit);
45
43
  this.rateLimit = rateLimit;
46
44
  const initialRoot = rlnInstance.zerokit.getMerkleRoot();
47
45
  // Use the injected contract if provided; otherwise, instantiate a new one.
48
46
  this.contract = contract || new Contract(address, RLN_ABI, signer);
49
47
  this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
50
- // Initialize event filters for MembershipRegistered and MembershipRemoved
48
+ // Initialize event filters
51
49
  this._membersFilter = this.contract.filters.MembershipRegistered();
52
- this._membersRemovedFilter = this.contract.filters.MembershipRemoved();
50
+ this._membershipErasedFilter = this.contract.filters.MembershipErased();
51
+ this._membersExpiredFilter = this.contract.filters.MembershipExpired();
52
+ }
53
+ /**
54
+ * Validates that the rate limit is within the allowed range
55
+ * @throws Error if the rate limit is outside the allowed range
56
+ */
57
+ validateRateLimit(rateLimit) {
58
+ if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
59
+ rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
60
+ throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE} messages per epoch`);
61
+ }
53
62
  }
54
63
  /**
55
64
  * Gets the current rate limit for this contract instance
@@ -110,13 +119,14 @@ class RLNContract {
110
119
  this.contract.maxTotalRateLimit(),
111
120
  this.contract.currentTotalRateLimit()
112
121
  ]);
113
- return maxTotal.sub(currentTotal).toNumber();
122
+ return Number(maxTotal) - Number(currentTotal);
114
123
  }
115
124
  /**
116
125
  * Updates the rate limit for future registrations
117
126
  * @param newRateLimit The new rate limit to use
118
127
  */
119
128
  async setRateLimit(newRateLimit) {
129
+ this.validateRateLimit(newRateLimit);
120
130
  this.rateLimit = newRateLimit;
121
131
  }
122
132
  get members() {
@@ -129,11 +139,17 @@ class RLNContract {
129
139
  }
130
140
  return this._membersFilter;
131
141
  }
132
- get membersRemovedFilter() {
133
- if (!this._membersRemovedFilter) {
134
- throw Error("MembersRemoved filter was not initialized.");
142
+ get membershipErasedFilter() {
143
+ if (!this._membershipErasedFilter) {
144
+ throw Error("MembershipErased filter was not initialized.");
135
145
  }
136
- return this._membersRemovedFilter;
146
+ return this._membershipErasedFilter;
147
+ }
148
+ get membersExpiredFilter() {
149
+ if (!this._membersExpiredFilter) {
150
+ throw Error("MembersExpired filter was not initialized.");
151
+ }
152
+ return this._membersExpiredFilter;
137
153
  }
138
154
  async fetchMembers(rlnInstance, options = {}) {
139
155
  const registeredMemberEvents = await queryFilter(this.contract, {
@@ -144,9 +160,18 @@ class RLNContract {
144
160
  const removedMemberEvents = await queryFilter(this.contract, {
145
161
  fromBlock: this.deployBlock,
146
162
  ...options,
147
- membersFilter: this.membersRemovedFilter
163
+ membersFilter: this.membershipErasedFilter
164
+ });
165
+ const expiredMemberEvents = await queryFilter(this.contract, {
166
+ fromBlock: this.deployBlock,
167
+ ...options,
168
+ membersFilter: this.membersExpiredFilter
148
169
  });
149
- const events = [...registeredMemberEvents, ...removedMemberEvents];
170
+ const events = [
171
+ ...registeredMemberEvents,
172
+ ...removedMemberEvents,
173
+ ...expiredMemberEvents
174
+ ];
150
175
  this.processEvents(rlnInstance, events);
151
176
  }
152
177
  processEvents(rlnInstance, events) {
@@ -156,8 +181,22 @@ class RLNContract {
156
181
  if (!evt.args) {
157
182
  return;
158
183
  }
159
- if (evt.event === "MembershipRemoved") {
160
- const index = evt.args.index;
184
+ if (evt.event === "MembershipErased" ||
185
+ evt.event === "MembershipExpired") {
186
+ let index = evt.args.index;
187
+ if (!index) {
188
+ return;
189
+ }
190
+ if (typeof index === "number" || typeof index === "string") {
191
+ index = BigNumber.from(index);
192
+ }
193
+ else {
194
+ log.error("Index is not a number or string", {
195
+ index,
196
+ event: evt
197
+ });
198
+ return;
199
+ }
161
200
  const toRemoveVal = toRemoveTable.get(evt.blockNumber);
162
201
  if (toRemoveVal != undefined) {
163
202
  toRemoveVal.push(index.toNumber());
@@ -185,13 +224,17 @@ class RLNContract {
185
224
  if (!evt.args)
186
225
  return;
187
226
  const _idCommitment = evt.args.idCommitment;
188
- const index = evt.args.index;
227
+ let index = evt.args.index;
189
228
  if (!_idCommitment || !index) {
190
229
  return;
191
230
  }
231
+ if (typeof index === "number" || typeof index === "string") {
232
+ index = BigNumber.from(index);
233
+ }
192
234
  const idCommitment = zeroPadLE(hexToBytes(_idCommitment), 32);
193
235
  rlnInstance.zerokit.insertMember(idCommitment);
194
- this._members.set(index.toNumber(), {
236
+ const numericIndex = index.toNumber();
237
+ this._members.set(numericIndex, {
195
238
  index,
196
239
  idCommitment: _idCommitment
197
240
  });
@@ -213,18 +256,36 @@ class RLNContract {
213
256
  });
214
257
  }
215
258
  subscribeToMembers(rlnInstance) {
216
- this.contract.on(this.membersFilter, (_idCommitment, _rateLimit, _index, event) => {
259
+ this.contract.on(this.membersFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
260
+ this.processEvents(rlnInstance, [event]);
261
+ });
262
+ this.contract.on(this.membershipErasedFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
217
263
  this.processEvents(rlnInstance, [event]);
218
264
  });
219
- this.contract.on(this.membersRemovedFilter, (_idCommitment, _index, event) => {
265
+ this.contract.on(this.membersExpiredFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
220
266
  this.processEvents(rlnInstance, [event]);
221
267
  });
222
268
  }
223
269
  async registerWithIdentity(identity) {
224
270
  try {
225
271
  log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
226
- const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], { gasLimit: 300000 });
272
+ // Check if the ID commitment is already registered
273
+ const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt.toString());
274
+ if (existingIndex) {
275
+ throw new Error(`ID commitment is already registered with index ${existingIndex}`);
276
+ }
277
+ // Check if there's enough remaining rate limit
278
+ const remainingRateLimit = await this.getRemainingTotalRateLimit();
279
+ if (remainingRateLimit < this.rateLimit) {
280
+ throw new Error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
281
+ }
282
+ const estimatedGas = await this.contract.estimateGas.register(identity.IDCommitmentBigInt, this.rateLimit, []);
283
+ const gasLimit = estimatedGas.add(10000);
284
+ const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], { gasLimit });
227
285
  const txRegisterReceipt = await txRegisterResponse.wait();
286
+ if (txRegisterReceipt.status === 0) {
287
+ throw new Error("Transaction failed on-chain");
288
+ }
228
289
  const memberRegistered = txRegisterReceipt.events?.find((event) => event.event === "MembershipRegistered");
229
290
  if (!memberRegistered || !memberRegistered.args) {
230
291
  log.error("Failed to register membership: No MembershipRegistered event found");
@@ -232,26 +293,51 @@ class RLNContract {
232
293
  }
233
294
  const decodedData = {
234
295
  idCommitment: memberRegistered.args.idCommitment,
235
- rateLimit: memberRegistered.args.rateLimit,
296
+ membershipRateLimit: memberRegistered.args.membershipRateLimit,
236
297
  index: memberRegistered.args.index
237
298
  };
238
299
  log.info(`Successfully registered membership with index ${decodedData.index} ` +
239
- `and rate limit ${decodedData.rateLimit}`);
300
+ `and rate limit ${decodedData.membershipRateLimit}`);
240
301
  const network = await this.contract.provider.getNetwork();
241
302
  const address = this.contract.address;
242
- const membershipId = decodedData.index.toNumber();
303
+ const membershipId = Number(decodedData.index);
243
304
  return {
244
305
  identity,
245
306
  membership: {
246
307
  address,
247
308
  treeIndex: membershipId,
248
- chainId: network.chainId
309
+ chainId: network.chainId,
310
+ rateLimit: decodedData.membershipRateLimit.toNumber()
249
311
  }
250
312
  };
251
313
  }
252
314
  catch (error) {
253
- log.error(`Error in registerWithIdentity: ${error.message}`);
254
- return undefined;
315
+ if (error instanceof Error) {
316
+ const errorMessage = error.message;
317
+ log.error("registerWithIdentity - error message:", errorMessage);
318
+ log.error("registerWithIdentity - error stack:", error.stack);
319
+ // Try to extract more specific error information
320
+ if (errorMessage.includes("CannotExceedMaxTotalRateLimit")) {
321
+ throw new Error("Registration failed: Cannot exceed maximum total rate limit");
322
+ }
323
+ else if (errorMessage.includes("InvalidIdCommitment")) {
324
+ throw new Error("Registration failed: Invalid ID commitment");
325
+ }
326
+ else if (errorMessage.includes("InvalidMembershipRateLimit")) {
327
+ throw new Error("Registration failed: Invalid membership rate limit");
328
+ }
329
+ else if (errorMessage.includes("execution reverted")) {
330
+ throw new Error("Contract execution reverted. Check contract requirements.");
331
+ }
332
+ else {
333
+ throw new Error(`Error in registerWithIdentity: ${errorMessage}`);
334
+ }
335
+ }
336
+ else {
337
+ throw new Error("Unknown error in registerWithIdentity", {
338
+ cause: error
339
+ });
340
+ }
255
341
  }
256
342
  }
257
343
  /**
@@ -287,20 +373,21 @@ class RLNContract {
287
373
  }
288
374
  const decodedData = {
289
375
  idCommitment: memberRegistered.args.idCommitment,
290
- rateLimit: memberRegistered.args.rateLimit,
376
+ membershipRateLimit: memberRegistered.args.membershipRateLimit,
291
377
  index: memberRegistered.args.index
292
378
  };
293
379
  log.info(`Successfully registered membership with permit. Index: ${decodedData.index}, ` +
294
- `Rate limit: ${decodedData.rateLimit}, Erased ${idCommitmentsToErase.length} commitments`);
380
+ `Rate limit: ${decodedData.membershipRateLimit}, Erased ${idCommitmentsToErase.length} commitments`);
295
381
  const network = await this.contract.provider.getNetwork();
296
382
  const address = this.contract.address;
297
- const membershipId = decodedData.index.toNumber();
383
+ const membershipId = BigNumber.from(decodedData.index).toNumber();
298
384
  return {
299
385
  identity,
300
386
  membership: {
301
387
  address,
302
388
  treeIndex: membershipId,
303
- chainId: network.chainId
389
+ chainId: network.chainId,
390
+ rateLimit: decodedData.membershipRateLimit.toNumber()
304
391
  }
305
392
  };
306
393
  }
@@ -357,11 +444,8 @@ class RLNContract {
357
444
  async eraseMembership(idCommitment, eraseFromMembershipSet = true) {
358
445
  return this.contract.eraseMemberships([idCommitment], eraseFromMembershipSet);
359
446
  }
360
- async registerMembership(idCommitment, rateLimit = DEFAULT_RATE_LIMIT) {
361
- if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
362
- rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
363
- throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
364
- }
447
+ async registerMembership(idCommitment, rateLimit = this.rateLimit) {
448
+ this.validateRateLimit(rateLimit);
365
449
  return this.contract.register(idCommitment, rateLimit, []);
366
450
  }
367
451
  async getMemberIndex(idCommitment) {
@@ -176,7 +176,8 @@ class Keystore {
176
176
  membership: {
177
177
  treeIndex: _.get(obj, "treeIndex"),
178
178
  chainId: _.get(obj, "membershipContract.chainId"),
179
- address: _.get(obj, "membershipContract.address")
179
+ address: _.get(obj, "membershipContract.address"),
180
+ rateLimit: _.get(obj, "membershipContract.rateLimit")
180
181
  }
181
182
  };
182
183
  }
@@ -21,7 +21,7 @@ import { Logger } from '../../utils/dist/logger/index.js';
21
21
  import '../../core/dist/lib/metadata/metadata.js';
22
22
  import __wbg_init, { init_panic_hook, newRLN } from '../../../node_modules/@waku/zerokit-rln-wasm/rln_wasm.js';
23
23
  import { createRLNEncoder, createRLNDecoder } from './codec.js';
24
- import { DEFAULT_RATE_LIMIT, SEPOLIA_CONTRACT } from './contract/constants.js';
24
+ import { LINEA_CONTRACT, DEFAULT_RATE_LIMIT } from './contract/constants.js';
25
25
  import { RLNContract } from './contract/rln_contract.js';
26
26
  import { Keystore } from './keystore/keystore.js';
27
27
  import verificationKey from './resources/verification_key.js';
@@ -127,9 +127,9 @@ class RLNInstance {
127
127
  let chainId = credentials?.membership.chainId;
128
128
  const address = credentials?.membership.address ||
129
129
  options.address ||
130
- SEPOLIA_CONTRACT.address;
131
- if (address === SEPOLIA_CONTRACT.address) {
132
- chainId = SEPOLIA_CONTRACT.chainId;
130
+ LINEA_CONTRACT.address;
131
+ if (address === LINEA_CONTRACT.address) {
132
+ chainId = LINEA_CONTRACT.chainId;
133
133
  }
134
134
  const signer = options.signer || (await extractMetaMaskSigner());
135
135
  const currentChainId = await signer.getChainId();
@@ -14,7 +14,7 @@ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisAr
14
14
  });
15
15
  };
16
16
  Object.defineProperty(checksum$1, "__esModule", { value: true });
17
- checksum$1.verifyChecksum = checksum$1.checksum = checksum$1.defaultSha256Module = undefined;
17
+ checksum$1.verifyChecksum = checksum$1.checksum = checksum$1.defaultSha256Module = void 0;
18
18
  const sha256_1 = sha256;
19
19
  const utils_1 = utilsExports;
20
20
  // default checksum configuration
@@ -38,7 +38,7 @@ function checksum(mod, key, ciphertext) {
38
38
  }
39
39
  checksum$1.checksum = checksum;
40
40
  function verifyChecksum(mod, key, ciphertext) {
41
- return __awaiter(this, undefined, undefined, function* () {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
42
  if (mod.function === "sha256") {
43
43
  return utils_1.equalsBytes(utils_1.hexToBytes(mod.message), sha256_1.sha256(checksumData(key, ciphertext)));
44
44
  }
@@ -16,7 +16,7 @@ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisAr
16
16
  });
17
17
  };
18
18
  Object.defineProperty(cipher, "__esModule", { value: true });
19
- var cipherDecrypt_1 = cipher.cipherDecrypt = cipher.cipherEncrypt = cipher.defaultAes128CtrModule = undefined;
19
+ var cipherDecrypt_1 = cipher.cipherDecrypt = cipher.cipherEncrypt = cipher.defaultAes128CtrModule = void 0;
20
20
  const random_1 = random;
21
21
  const aes_1 = aes;
22
22
  const utils_1 = utilsExports;
@@ -30,7 +30,7 @@ function defaultAes128CtrModule() {
30
30
  }
31
31
  cipher.defaultAes128CtrModule = defaultAes128CtrModule;
32
32
  function cipherEncrypt(mod, key, data) {
33
- return __awaiter(this, undefined, undefined, function* () {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
34
  if (mod.function === "aes-128-ctr") {
35
35
  try {
36
36
  return yield aes_1.encrypt(data, key, utils_1.hexToBytes(mod.params.iv), mod.function, false);
@@ -46,7 +46,7 @@ function cipherEncrypt(mod, key, data) {
46
46
  }
47
47
  cipher.cipherEncrypt = cipherEncrypt;
48
48
  function cipherDecrypt(mod, key) {
49
- return __awaiter(this, undefined, undefined, function* () {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
50
  if (mod.function === "aes-128-ctr") {
51
51
  try {
52
52
  return yield aes_1.decrypt(utils_1.hexToBytes(mod.message), key, utils_1.hexToBytes(mod.params.iv), mod.function, false);
@@ -21,7 +21,7 @@ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisAr
21
21
  });
22
22
  };
23
23
  Object.defineProperty(_class, "__esModule", { value: true });
24
- _class.Keystore = undefined;
24
+ _class.Keystore = void 0;
25
25
  const kdf_1 = kdf;
26
26
  const checksum_1 = checksum;
27
27
  const cipher_1 = cipher;
@@ -47,7 +47,7 @@ class Keystore {
47
47
  * Create a new Keystore object
48
48
  */
49
49
  static create(password, secret, pubkey, path, description = null, kdfMod = kdf_1.defaultPbkdfModule(), checksumMod = checksum_1.defaultSha256Module(), cipherMod = cipher_1.defaultAes128CtrModule()) {
50
- return __awaiter(this, undefined, undefined, function* () {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
51
  const obj = yield functional_1.create(password, secret, pubkey, path, description, kdfMod, checksumMod, cipherMod);
52
52
  return new Keystore(obj);
53
53
  });
@@ -69,7 +69,7 @@ class Keystore {
69
69
  * Decrypt a keystore, returns the secret key or throws on invalid password
70
70
  */
71
71
  decrypt(password) {
72
- return __awaiter(this, undefined, undefined, function* () {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
73
  return functional_1.decrypt(this, password);
74
74
  });
75
75
  }
@@ -77,7 +77,7 @@ class Keystore {
77
77
  * Verify the password as correct or not
78
78
  */
79
79
  verifyPassword(password) {
80
- return __awaiter(this, undefined, undefined, function* () {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
81
  return functional_1.verifyPassword(this, password);
82
82
  });
83
83
  }
@@ -22,7 +22,7 @@ import { __exports as password } from '../../../../../../_virtual/password.js';
22
22
  });
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.decrypt = exports.verifyPassword = exports.create = exports.defaultAes128CtrModule = exports.defaultSha256Module = exports.defaultScryptModule = exports.defaultPbkdfModule = undefined;
25
+ exports.decrypt = exports.verifyPassword = exports.create = exports.defaultAes128CtrModule = exports.defaultSha256Module = exports.defaultScryptModule = exports.defaultPbkdfModule = void 0;
26
26
  const uuid_1 = require$$0;
27
27
  const kdf_1 = kdf;
28
28
  Object.defineProperty(exports, "defaultPbkdfModule", { enumerable: true, get: function () { return kdf_1.defaultPbkdfModule; } });
@@ -45,7 +45,7 @@ import { __exports as password } from '../../../../../../_virtual/password.js';
45
45
  * @param cipherMod cipher configuration module
46
46
  */
47
47
  function create(password, secret, pubkey, path, description = null, kdfMod = kdf_1.defaultPbkdfModule(), checksumMod = checksum_1.defaultSha256Module(), cipherMod = cipher_1.defaultAes128CtrModule()) {
48
- return __awaiter(this, undefined, undefined, function* () {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
49
  const encryptionKey = yield kdf_1.kdf(kdfMod, password_1.normalizePassword(password));
50
50
  const ciphertext = yield cipher_1.cipherEncrypt(cipherMod, encryptionKey.slice(0, 16), secret);
51
51
  return {
@@ -79,7 +79,7 @@ import { __exports as password } from '../../../../../../_virtual/password.js';
79
79
  * Verify the password of a keystore object
80
80
  */
81
81
  function verifyPassword(keystore, password) {
82
- return __awaiter(this, undefined, undefined, function* () {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
83
  const decryptionKey = yield kdf_1.kdf(keystore.crypto.kdf, password_1.normalizePassword(password));
84
84
  const ciphertext = utils_1.hexToBytes(keystore.crypto.cipher.message);
85
85
  return checksum_1.verifyChecksum(keystore.crypto.checksum, decryptionKey, ciphertext);
@@ -90,7 +90,7 @@ import { __exports as password } from '../../../../../../_virtual/password.js';
90
90
  * Decrypt a keystore, returns the secret key or throws on invalid password
91
91
  */
92
92
  function decrypt(keystore, password) {
93
- return __awaiter(this, undefined, undefined, function* () {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
94
  const decryptionKey = yield kdf_1.kdf(keystore.crypto.kdf, password_1.normalizePassword(password));
95
95
  const ciphertext = utils_1.hexToBytes(keystore.crypto.cipher.message);
96
96
  if (!(yield checksum_1.verifyChecksum(keystore.crypto.checksum, decryptionKey, ciphertext))) {
@@ -18,7 +18,7 @@ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisAr
18
18
  });
19
19
  };
20
20
  Object.defineProperty(kdf$1, "__esModule", { value: true });
21
- var kdf_2 = kdf$1.kdf = kdf$1.defaultScryptModule = kdf$1.defaultPbkdfModule = undefined;
21
+ var kdf_2 = kdf$1.kdf = kdf$1.defaultScryptModule = kdf$1.defaultPbkdfModule = void 0;
22
22
  const random_1 = random;
23
23
  const pbkdf2_1 = pbkdf2;
24
24
  const scrypt_1 = scrypt;
@@ -51,7 +51,7 @@ function defaultScryptModule() {
51
51
  kdf$1.defaultScryptModule = defaultScryptModule;
52
52
  // kdf operations
53
53
  function kdf(mod, password) {
54
- return __awaiter(this, undefined, undefined, function* () {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
55
  if (mod.function === "pbkdf2") {
56
56
  return yield doPbkdf2(mod.params, password);
57
57
  }
@@ -65,12 +65,12 @@ function kdf(mod, password) {
65
65
  }
66
66
  kdf_2 = kdf$1.kdf = kdf;
67
67
  function doPbkdf2(params, password) {
68
- return __awaiter(this, undefined, undefined, function* () {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
69
  return pbkdf2_1.pbkdf2(password, utils_1.hexToBytes(params.salt), params.c, params.dklen, params.prf.slice(5));
70
70
  });
71
71
  }
72
72
  function doScrypt(params, password) {
73
- return __awaiter(this, undefined, undefined, function* () {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
74
  return scrypt_1.scrypt(password, utils_1.hexToBytes(params.salt), params.n, params.p, params.r, params.dklen);
75
75
  });
76
76
  }
@@ -2,7 +2,7 @@ import { __exports as password } from '../../../../../../_virtual/password.js';
2
2
  import { u as utilsExports } from '../node_modules/ethereum-cryptography/utils.js';
3
3
 
4
4
  Object.defineProperty(password, "__esModule", { value: true });
5
- var normalizePassword_1 = password.normalizePassword = undefined;
5
+ var normalizePassword_1 = password.normalizePassword = void 0;
6
6
  const utils_1 = utilsExports;
7
7
  function normalizePassword(password) {
8
8
  if (typeof password === "string") {
@@ -1,7 +1,7 @@
1
1
  import { __exports as schemaValidationGenerated } from '../../../../../../_virtual/schema-validation-generated.js';
2
2
 
3
3
  Object.defineProperty(schemaValidationGenerated, "__esModule", { value: true });
4
- schemaValidationGenerated.Keystore = undefined;
4
+ schemaValidationGenerated.Keystore = void 0;
5
5
  schemaValidationGenerated.Keystore = validate19;
6
6
  const pattern0 = new RegExp("^pbkdf2$", "u");
7
7
  const pattern1 = new RegExp("^hmac-sha256$", "u");
@@ -3,7 +3,7 @@ import './schema-validation-generated.js';
3
3
  import { __exports as schemaValidationGenerated } from '../../../../../../_virtual/schema-validation-generated.js';
4
4
 
5
5
  Object.defineProperty(schemaValidation, "__esModule", { value: true });
6
- schemaValidation.isValidKeystore = schemaValidation.validateKeystore = schemaValidation.schemaValidationErrors = undefined;
6
+ schemaValidation.isValidKeystore = schemaValidation.validateKeystore = schemaValidation.schemaValidationErrors = void 0;
7
7
  const schema_validation_generated_1 = schemaValidationGenerated;
8
8
  // Redeclare generated function with the proper type
9
9
  const _validateKeystore = schema_validation_generated_1.Keystore;
@@ -4,7 +4,7 @@ import { u as utilsExports } from './utils.js';
4
4
  import { __exports as cryptoBrowser } from '../../../../../../../_virtual/cryptoBrowser.js';
5
5
 
6
6
  Object.defineProperty(aes, "__esModule", { value: true });
7
- aes.decrypt = aes.encrypt = undefined;
7
+ aes.decrypt = aes.encrypt = void 0;
8
8
  const crypto_1 = cryptoBrowser;
9
9
  const utils_1 = utilsExports;
10
10
  function validateOpt(key, iv, mode) {
@@ -8,7 +8,7 @@ import { __exports as sha256 } from '../../../../../../../_virtual/sha2562.js';
8
8
  import { __exports as sha512 } from '../../../../../../../_virtual/sha512.js';
9
9
 
10
10
  Object.defineProperty(pbkdf2$1, "__esModule", { value: true });
11
- pbkdf2$1.pbkdf2Sync = pbkdf2$1.pbkdf2 = undefined;
11
+ pbkdf2$1.pbkdf2Sync = pbkdf2$1.pbkdf2 = void 0;
12
12
  const pbkdf2_1 = pbkdf2$2;
13
13
  const sha256_1 = sha256;
14
14
  const sha512_1 = sha512;
@@ -3,7 +3,7 @@ import '../../../../@noble/hashes/utils.js';
3
3
  import { __exports as utils } from '../../../../../../../_virtual/utils.js';
4
4
 
5
5
  Object.defineProperty(random, "__esModule", { value: true });
6
- random.getRandomBytes = random.getRandomBytesSync = undefined;
6
+ random.getRandomBytes = random.getRandomBytesSync = void 0;
7
7
  const utils_1 = utils;
8
8
  function getRandomBytesSync(bytes) {
9
9
  return (0, utils_1.randomBytes)(bytes);
@@ -4,7 +4,7 @@ import { u as utilsExports } from './utils.js';
4
4
  import { __exports as scrypt$2 } from '../../../../../../../_virtual/scrypt2.js';
5
5
 
6
6
  Object.defineProperty(scrypt$1, "__esModule", { value: true });
7
- scrypt$1.scryptSync = scrypt$1.scrypt = undefined;
7
+ scrypt$1.scryptSync = scrypt$1.scrypt = void 0;
8
8
  const scrypt_1 = scrypt$2;
9
9
  const utils_1 = utilsExports;
10
10
  async function scrypt(password, salt, n, p, r, dkLen, onProgress) {
@@ -4,7 +4,7 @@ import { u as utilsExports } from './utils.js';
4
4
  import { __exports as sha256$1 } from '../../../../../../../_virtual/sha2562.js';
5
5
 
6
6
  Object.defineProperty(sha256, "__esModule", { value: true });
7
- sha256.sha256 = undefined;
7
+ sha256.sha256 = void 0;
8
8
  const sha256_1 = sha256$1;
9
9
  const utils_1 = utilsExports;
10
10
  sha256.sha256 = (0, utils_1.wrapHash)(sha256_1.sha256);
@@ -13,7 +13,7 @@ utils.exports;
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.crypto = exports.wrapHash = exports.equalsBytes = exports.hexToBytes = exports.bytesToUtf8 = exports.utf8ToBytes = exports.createView = exports.concatBytes = exports.toHex = exports.bytesToHex = exports.assertBytes = exports.assertBool = undefined;
16
+ exports.crypto = exports.wrapHash = exports.equalsBytes = exports.hexToBytes = exports.bytesToUtf8 = exports.utf8ToBytes = exports.createView = exports.concatBytes = exports.toHex = exports.bytesToHex = exports.assertBytes = exports.assertBool = void 0;
17
17
  // buf.toString('hex') -> toHex(buf)
18
18
  const _assert_1 = __importDefault(_assert);
19
19
  const utils_1 = utils$1;
@@ -1,7 +1,7 @@
1
1
  import { __exports as _assert } from '../../../../../_virtual/_assert.js';
2
2
 
3
3
  Object.defineProperty(_assert, "__esModule", { value: true });
4
- _assert.output = _assert.exists = _assert.hash = _assert.bytes = _assert.bool = _assert.number = undefined;
4
+ _assert.output = _assert.exists = _assert.hash = _assert.bytes = _assert.bool = _assert.number = void 0;
5
5
  function number(n) {
6
6
  if (!Number.isSafeInteger(n) || n < 0)
7
7
  throw new Error(`Wrong positive integer: ${n}`);
@@ -1,11 +1,11 @@
1
1
  import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
2
2
  import './_assert.js';
3
3
  import './utils.js';
4
- import { __exports as _assert } from '../../../../../_virtual/_assert.js';
5
4
  import { __exports as utils } from '../../../../../_virtual/utils.js';
5
+ import { __exports as _assert } from '../../../../../_virtual/_assert.js';
6
6
 
7
7
  Object.defineProperty(_sha2, "__esModule", { value: true });
8
- _sha2.SHA2 = undefined;
8
+ _sha2.SHA2 = void 0;
9
9
  const _assert_js_1 = _assert;
10
10
  const utils_js_1 = utils;
11
11
  // Polyfill for Safari 14
@@ -2,7 +2,7 @@ import { __exports as _u64 } from '../../../../../_virtual/_u64.js';
2
2
 
3
3
  (function (exports) {
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.add = exports.toBig = exports.split = exports.fromBig = undefined;
5
+ exports.add = exports.toBig = exports.split = exports.fromBig = void 0;
6
6
  const U32_MASK64 = BigInt(2 ** 32 - 1);
7
7
  const _32n = BigInt(32);
8
8
  // We are not using BigUint64Array, because they are extremely slow as per 2022
@@ -1,7 +1,7 @@
1
1
  import { __exports as cryptoBrowser } from '../../../../../_virtual/cryptoBrowser.js';
2
2
 
3
3
  Object.defineProperty(cryptoBrowser, "__esModule", { value: true });
4
- cryptoBrowser.crypto = undefined;
4
+ cryptoBrowser.crypto = void 0;
5
5
  cryptoBrowser.crypto = {
6
6
  node: undefined,
7
7
  web: typeof self === 'object' && 'crypto' in self ? self.crypto : undefined,