@waku/rln 0.1.5-fdaf129.0 → 0.1.5

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 (54) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/bundle/_virtual/utils.js +2 -2
  3. package/bundle/_virtual/utils2.js +2 -2
  4. package/bundle/index.js +1 -2
  5. package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +1 -1
  6. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +1 -1
  7. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +1 -1
  8. package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +1 -1
  9. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +1 -1
  10. package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +1 -1
  11. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +1 -1
  12. package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +1 -1
  13. package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +1 -1
  14. package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +19 -1
  15. package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +1 -1
  16. package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +1 -1
  17. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +1 -1
  18. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +58 -10
  19. package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +1 -1
  20. package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +1 -1
  21. package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +1 -1
  22. package/bundle/packages/proto/dist/generated/sds_message.js +59 -3
  23. package/bundle/packages/rln/dist/contract/constants.js +0 -1
  24. package/bundle/packages/rln/dist/contract/rln_base_contract.js +59 -60
  25. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
  26. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
  27. package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +1 -1
  28. package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +1 -1
  29. package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +1 -1
  30. package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +1 -1
  31. package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +1 -1
  32. package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +1 -1
  33. package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +1 -1
  34. package/dist/.tsbuildinfo +1 -1
  35. package/dist/contract/index.d.ts +0 -1
  36. package/dist/contract/index.js +0 -1
  37. package/dist/contract/index.js.map +1 -1
  38. package/dist/contract/rln_base_contract.d.ts +11 -5
  39. package/dist/contract/rln_base_contract.js +59 -60
  40. package/dist/contract/rln_base_contract.js.map +1 -1
  41. package/dist/contract/types.d.ts +0 -5
  42. package/dist/contract/types.js.map +1 -1
  43. package/dist/index.d.ts +1 -2
  44. package/dist/index.js +0 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/keystore/keystore.js.map +1 -1
  47. package/dist/keystore/types.d.ts +2 -2
  48. package/package.json +92 -1
  49. package/src/contract/index.ts +0 -1
  50. package/src/contract/rln_base_contract.ts +85 -85
  51. package/src/contract/types.ts +0 -5
  52. package/src/index.ts +1 -3
  53. package/src/keystore/keystore.ts +2 -4
  54. package/src/keystore/types.ts +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.5](https://github.com/waku-org/js-waku/compare/rln-v0.1.4...rln-v0.1.5) (2025-04-23)
4
+
5
+
6
+ ### Features
7
+
8
+ * **rln:** Create `CredentialsManager` without Zerokit ([#2295](https://github.com/waku-org/js-waku/issues/2295)) ([4adf870](https://github.com/waku-org/js-waku/commit/4adf8706c3befd99ace8f02dc2a1350428d4a163))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **rln:** Update types to match nwaku ([#2339](https://github.com/waku-org/js-waku/issues/2339)) ([28f28d0](https://github.com/waku-org/js-waku/commit/28f28d0d3627d7fdd06c5970c6028ea73031786e))
14
+
15
+
16
+ ### Dependencies
17
+
18
+ * The following workspace dependencies were updated
19
+ * dependencies
20
+ * @waku/core bumped from ^0.0.34 to ^0.0.35
21
+ * @waku/utils bumped from ^0.0.22 to ^0.0.23
22
+ * devDependencies
23
+ * @waku/message-encryption bumped from ^0.0.32 to ^0.0.33
24
+
3
25
  ## [0.1.4](https://github.com/waku-org/js-waku/compare/rln-v0.1.3...rln-v0.1.4) (2025-03-24)
4
26
 
5
27
 
@@ -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 };
package/bundle/index.js CHANGED
@@ -1,8 +1,7 @@
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 { 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';
4
+ export { LINEA_CONTRACT } from './packages/rln/dist/contract/constants.js';
6
5
  export { RLNBaseContract } from './packages/rln/dist/contract/rln_base_contract.js';
7
6
  export { createRLN } from './packages/rln/dist/create.js';
8
7
  export { RLNCredentialsManager } from './packages/rln/dist/credentials_manager.js';
@@ -1,3 +1,3 @@
1
- const version = "abi/5.7.0";
1
+ const version = "abi/5.8.0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "abstract-provider/5.7.0";
1
+ const version = "abstract-provider/5.8.0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "abstract-signer/5.7.0";
1
+ const version = "abstract-signer/5.8.0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "address/5.7.0";
1
+ const version = "address/5.8.0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "bignumber/5.7.0";
1
+ const version = "bignumber/5.8.0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "contracts/5.7.0";
1
+ const version = "contracts/5.8.0";
2
2
 
3
3
  export { version };
@@ -763,7 +763,7 @@ class BaseContract {
763
763
  logger.throwError("events require a provider or a signer with a provider", Logger.errors.UNSUPPORTED_OPERATION, { operation: "once" });
764
764
  }
765
765
  runningEvent.addListener(listener, once);
766
- // Track this running event and its listeners (may already be there; but no hard in updating)
766
+ // Track this running event and its listeners (may already be there; but no harm in updating)
767
767
  this._runningEvents[runningEvent.tag] = runningEvent;
768
768
  // If we are not polling the provider, start polling
769
769
  if (!this._wrappedEmits[runningEvent.tag]) {
@@ -1,3 +1,3 @@
1
- const version = "hash/5.7.0";
1
+ const version = "hash/5.8.0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "networks/5.7.1";
1
+ const version = "networks/5.8.0";
2
2
 
3
3
  export { version };
@@ -59,6 +59,12 @@ function ethDefaultProvider(network) {
59
59
  }
60
60
  catch (error) { }
61
61
  }
62
+ if (providers.QuickNodeProvider && options.quicknode !== "-") {
63
+ try {
64
+ providerList.push(new providers.QuickNodeProvider(network, options.quicknode));
65
+ }
66
+ catch (error) { }
67
+ }
62
68
  if (providerList.length === 0) {
63
69
  return null;
64
70
  }
@@ -136,9 +142,15 @@ const networks = {
136
142
  kintsugi: { chainId: 1337702, name: "kintsugi" },
137
143
  sepolia: {
138
144
  chainId: 11155111,
145
+ ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
139
146
  name: "sepolia",
140
147
  _defaultProvider: ethDefaultProvider("sepolia")
141
148
  },
149
+ holesky: {
150
+ chainId: 17000,
151
+ name: "holesky",
152
+ _defaultProvider: ethDefaultProvider("holesky")
153
+ },
142
154
  // ETC (See: #351)
143
155
  classic: {
144
156
  chainId: 61,
@@ -159,7 +171,11 @@ const networks = {
159
171
  name: "matic",
160
172
  _defaultProvider: ethDefaultProvider("matic")
161
173
  },
162
- maticmum: { chainId: 80001, name: "maticmum" },
174
+ maticmum: {
175
+ chainId: 80001,
176
+ name: "maticmum",
177
+ _defaultProvider: ethDefaultProvider("maticmum")
178
+ },
163
179
  optimism: {
164
180
  chainId: 10,
165
181
  name: "optimism",
@@ -167,9 +183,11 @@ const networks = {
167
183
  },
168
184
  "optimism-kovan": { chainId: 69, name: "optimism-kovan" },
169
185
  "optimism-goerli": { chainId: 420, name: "optimism-goerli" },
186
+ "optimism-sepolia": { chainId: 11155420, name: "optimism-sepolia" },
170
187
  arbitrum: { chainId: 42161, name: "arbitrum" },
171
188
  "arbitrum-rinkeby": { chainId: 421611, name: "arbitrum-rinkeby" },
172
189
  "arbitrum-goerli": { chainId: 421613, name: "arbitrum-goerli" },
190
+ "arbitrum-sepolia": { chainId: 421614, name: "arbitrum-sepolia" },
173
191
  bnb: { chainId: 56, name: "bnb" },
174
192
  bnbt: { chainId: 97, name: "bnbt" },
175
193
  };
@@ -1,3 +1,3 @@
1
- const version = "properties/5.7.0";
1
+ const version = "properties/5.8.0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "providers/5.7.2";
1
+ const version = "providers/5.8.0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "signing-key/5.7.0";
1
+ const version = "signing-key/5.8.0";
2
2
 
3
3
  export { version };
@@ -103,12 +103,15 @@ utils.encode = utils_1.encode;
103
103
  // Represent num in a w-NAF form
104
104
  function getNAF(num, w, bits) {
105
105
  var naf = new Array(Math.max(num.bitLength(), bits) + 1);
106
- naf.fill(0);
106
+ var i;
107
+ for (i = 0; i < naf.length; i += 1) {
108
+ naf[i] = 0;
109
+ }
107
110
 
108
111
  var ws = 1 << (w + 1);
109
112
  var k = num.clone();
110
113
 
111
- for (var i = 0; i < naf.length; i++) {
114
+ for (i = 0; i < naf.length; i++) {
112
115
  var z;
113
116
  var mod = k.andln(ws - 1);
114
117
  if (k.isOdd()) {
@@ -1994,8 +1997,8 @@ KeyPair.prototype.sign = function sign(msg, enc, options) {
1994
1997
  return this.ec.sign(msg, this, enc, options);
1995
1998
  };
1996
1999
 
1997
- KeyPair.prototype.verify = function verify(msg, signature) {
1998
- return this.ec.verify(msg, signature, this);
2000
+ KeyPair.prototype.verify = function verify(msg, signature, options) {
2001
+ return this.ec.verify(msg, signature, this, undefined, options);
1999
2002
  };
2000
2003
 
2001
2004
  KeyPair.prototype.inspect = function inspect() {
@@ -2041,6 +2044,10 @@ function getLength(buf, p) {
2041
2044
  return false;
2042
2045
  }
2043
2046
 
2047
+ if(buf[p.place] === 0x00) {
2048
+ return false;
2049
+ }
2050
+
2044
2051
  var val = 0;
2045
2052
  for (var i = 0, off = p.place; i < octetLen; i++, off++) {
2046
2053
  val <<= 8;
@@ -2089,6 +2096,9 @@ Signature.prototype._importDER = function _importDER(data, enc) {
2089
2096
  if (rlen === false) {
2090
2097
  return false;
2091
2098
  }
2099
+ if ((data[p.place] & 128) !== 0) {
2100
+ return false;
2101
+ }
2092
2102
  var r = data.slice(p.place, rlen + p.place);
2093
2103
  p.place += rlen;
2094
2104
  if (data[p.place++] !== 0x02) {
@@ -2101,6 +2111,9 @@ Signature.prototype._importDER = function _importDER(data, enc) {
2101
2111
  if (data.length !== slen + p.place) {
2102
2112
  return false;
2103
2113
  }
2114
+ if ((data[p.place] & 128) !== 0) {
2115
+ return false;
2116
+ }
2104
2117
  var s = data.slice(p.place, slen + p.place);
2105
2118
  if (r[0] === 0) {
2106
2119
  if (r[1] & 0x80) {
@@ -2246,8 +2259,27 @@ EC.prototype.genKeyPair = function genKeyPair(options) {
2246
2259
  }
2247
2260
  };
2248
2261
 
2249
- EC.prototype._truncateToN = function _truncateToN(msg, truncOnly) {
2250
- var delta = msg.byteLength() * 8 - this.n.bitLength();
2262
+ EC.prototype._truncateToN = function _truncateToN(msg, truncOnly, bitLength) {
2263
+ var byteLength;
2264
+ if (BN.isBN(msg) || typeof msg === 'number') {
2265
+ msg = new BN(msg, 16);
2266
+ byteLength = msg.byteLength();
2267
+ } else if (typeof msg === 'object') {
2268
+ // BN assumes an array-like input and asserts length
2269
+ byteLength = msg.length;
2270
+ msg = new BN(msg, 16);
2271
+ } else {
2272
+ // BN converts the value to string
2273
+ var str = msg.toString();
2274
+ // HEX encoding
2275
+ byteLength = (str.length + 1) >>> 1;
2276
+ msg = new BN(str, 16);
2277
+ }
2278
+ // Allow overriding
2279
+ if (typeof bitLength !== 'number') {
2280
+ bitLength = byteLength * 8;
2281
+ }
2282
+ var delta = bitLength - this.n.bitLength();
2251
2283
  if (delta > 0)
2252
2284
  msg = msg.ushrn(delta);
2253
2285
  if (!truncOnly && msg.cmp(this.n) >= 0)
@@ -2264,8 +2296,18 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
2264
2296
  if (!options)
2265
2297
  options = {};
2266
2298
 
2299
+ if (typeof msg !== 'string' && typeof msg !== 'number' && !BN.isBN(msg)) {
2300
+ assert$5(typeof msg === 'object' && msg && typeof msg.length === 'number',
2301
+ 'Expected message to be an array-like, a hex string, or a BN instance');
2302
+ assert$5((msg.length >>> 0) === msg.length); // non-negative 32-bit integer
2303
+ for (var i = 0; i < msg.length; i++) assert$5((msg[i] & 255) === msg[i]);
2304
+ }
2305
+
2267
2306
  key = this.keyFromPrivate(key, enc);
2268
- msg = this._truncateToN(new BN(msg, 16));
2307
+ msg = this._truncateToN(msg, false, options.msgBitLength);
2308
+
2309
+ // Would fail further checks, but let's make the error message clear
2310
+ assert$5(!msg.isNeg(), 'Can not sign a negative message');
2269
2311
 
2270
2312
  // Zero-extend key to provide enough entropy
2271
2313
  var bytes = this.n.byteLength();
@@ -2274,6 +2316,9 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
2274
2316
  // Zero-extend nonce to have the same byte size as N
2275
2317
  var nonce = msg.toArray('be', bytes);
2276
2318
 
2319
+ // Recheck nonce to be bijective to msg
2320
+ assert$5((new BN(nonce)).eq(msg), 'Can not sign message');
2321
+
2277
2322
  // Instantiate Hmac_DRBG
2278
2323
  var drbg = new hmacDrbg({
2279
2324
  hash: this.hash,
@@ -2321,8 +2366,11 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
2321
2366
  }
2322
2367
  };
2323
2368
 
2324
- EC.prototype.verify = function verify(msg, signature$1, key, enc) {
2325
- msg = this._truncateToN(new BN(msg, 16));
2369
+ EC.prototype.verify = function verify(msg, signature$1, key, enc, options) {
2370
+ if (!options)
2371
+ options = {};
2372
+
2373
+ msg = this._truncateToN(msg, false, options.msgBitLength);
2326
2374
  key = this.keyFromPublic(key, enc);
2327
2375
  signature$1 = new signature(signature$1, 'hex');
2328
2376
 
@@ -2414,7 +2462,7 @@ var elliptic_1 = createCommonjsModule(function (module, exports) {
2414
2462
 
2415
2463
  var elliptic = exports;
2416
2464
 
2417
- elliptic.version = /*RicMoo:ethers*/{ version: "6.5.4" }.version;
2465
+ elliptic.version = /*RicMoo:ethers*/{ version: "6.6.1" }.version;
2418
2466
  elliptic.utils = utils_1$1;
2419
2467
  elliptic.rand = /*RicMoo:ethers:require(brorand)*/(function() { throw new Error('unsupported'); });
2420
2468
  elliptic.curve = curve_1;
@@ -1,3 +1,3 @@
1
- const version = "strings/5.7.0";
1
+ const version = "strings/5.8.0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "transactions/5.7.0";
1
+ const version = "transactions/5.8.0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "web/5.7.1";
1
+ const version = "web/5.8.0";
2
2
 
3
3
  export { version };
@@ -8,6 +8,60 @@ import { decodeMessage } from '../../../../node_modules/protons-runtime/dist/src
8
8
  /* eslint-disable @typescript-eslint/no-namespace */
9
9
  /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
10
10
  /* eslint-disable @typescript-eslint/no-empty-interface */
11
+ var HistoryEntry;
12
+ (function (HistoryEntry) {
13
+ let _codec;
14
+ HistoryEntry.codec = () => {
15
+ if (_codec == null) {
16
+ _codec = message((obj, w, opts = {}) => {
17
+ if (opts.lengthDelimited !== false) {
18
+ w.fork();
19
+ }
20
+ if ((obj.messageId != null && obj.messageId !== '')) {
21
+ w.uint32(10);
22
+ w.string(obj.messageId);
23
+ }
24
+ if (obj.retrievalHint != null) {
25
+ w.uint32(18);
26
+ w.bytes(obj.retrievalHint);
27
+ }
28
+ if (opts.lengthDelimited !== false) {
29
+ w.ldelim();
30
+ }
31
+ }, (reader, length, opts = {}) => {
32
+ const obj = {
33
+ messageId: ''
34
+ };
35
+ const end = length == null ? reader.len : reader.pos + length;
36
+ while (reader.pos < end) {
37
+ const tag = reader.uint32();
38
+ switch (tag >>> 3) {
39
+ case 1: {
40
+ obj.messageId = reader.string();
41
+ break;
42
+ }
43
+ case 2: {
44
+ obj.retrievalHint = reader.bytes();
45
+ break;
46
+ }
47
+ default: {
48
+ reader.skipType(tag & 7);
49
+ break;
50
+ }
51
+ }
52
+ }
53
+ return obj;
54
+ });
55
+ }
56
+ return _codec;
57
+ };
58
+ HistoryEntry.encode = (obj) => {
59
+ return encodeMessage(obj, HistoryEntry.codec());
60
+ };
61
+ HistoryEntry.decode = (buf, opts) => {
62
+ return decodeMessage(buf, HistoryEntry.codec(), opts);
63
+ };
64
+ })(HistoryEntry || (HistoryEntry = {}));
11
65
  var SdsMessage;
12
66
  (function (SdsMessage) {
13
67
  let _codec;
@@ -32,7 +86,7 @@ var SdsMessage;
32
86
  if (obj.causalHistory != null) {
33
87
  for (const value of obj.causalHistory) {
34
88
  w.uint32(90);
35
- w.string(value);
89
+ HistoryEntry.codec().encode(value, w);
36
90
  }
37
91
  }
38
92
  if (obj.bloomFilter != null) {
@@ -72,7 +126,9 @@ var SdsMessage;
72
126
  if (opts.limits?.causalHistory != null && obj.causalHistory.length === opts.limits.causalHistory) {
73
127
  throw new MaxLengthError('Decode error - map field "causalHistory" had too many elements');
74
128
  }
75
- obj.causalHistory.push(reader.string());
129
+ obj.causalHistory.push(HistoryEntry.codec().decode(reader, reader.uint32(), {
130
+ limits: opts.limits?.causalHistory$
131
+ }));
76
132
  break;
77
133
  }
78
134
  case 12: {
@@ -102,4 +158,4 @@ var SdsMessage;
102
158
  };
103
159
  })(SdsMessage || (SdsMessage = {}));
104
160
 
105
- export { SdsMessage };
161
+ export { HistoryEntry, SdsMessage };
@@ -12,7 +12,6 @@ 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,
16
15
  HIGH: 600 // Suggested maximum rate - 600 messages per epoch
17
16
  };
18
17
  // Global rate limit parameters
@@ -19,7 +19,6 @@ import { MembershipState } from './types.js';
19
19
  import { Contract } from '../../../../node_modules/@ethersproject/contracts/lib.esm/index.js';
20
20
  import { BigNumber } from '../../../../node_modules/@ethersproject/bignumber/lib.esm/bignumber.js';
21
21
 
22
- /* eslint-disable no-console */
23
22
  const log = new Logger("waku:rln:contract:base");
24
23
  class RLNBaseContract {
25
24
  contract;
@@ -34,22 +33,6 @@ class RLNBaseContract {
34
33
  * Allows injecting a mocked contract for testing purposes.
35
34
  */
36
35
  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
- }
53
36
  // Initialize members and subscriptions
54
37
  this.fetchMembers()
55
38
  .then(() => {
@@ -58,10 +41,14 @@ class RLNBaseContract {
58
41
  .catch((error) => {
59
42
  log.error("Failed to initialize members", { error });
60
43
  });
61
- // Validate rate limit asynchronously
62
- this.validateRateLimit(rateLimit).catch((error) => {
63
- log.error("Failed to validate initial rate limit", { error });
64
- });
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();
65
52
  }
66
53
  /**
67
54
  * Gets the current rate limit for this contract instance
@@ -129,7 +116,7 @@ class RLNBaseContract {
129
116
  * @param newRateLimit The new rate limit to use
130
117
  */
131
118
  async setRateLimit(newRateLimit) {
132
- await this.validateRateLimit(newRateLimit);
119
+ this.validateRateLimit(newRateLimit);
133
120
  this.rateLimit = newRateLimit;
134
121
  }
135
122
  get members() {
@@ -260,58 +247,75 @@ class RLNBaseContract {
260
247
  this.processEvents([event]);
261
248
  });
262
249
  }
263
- async getMembershipInfo(idCommitmentBigInt) {
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) {
264
256
  try {
265
- const membershipData = await this.contract.memberships(idCommitmentBigInt);
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) {
274
+ try {
275
+ const [startBlock, endBlock, rateLimit] = await this.contract.getMembershipInfo(idCommitment);
266
276
  const currentBlock = await this.contract.provider.getBlockNumber();
267
- console.log("membershipData", membershipData);
268
- const [depositAmount, activeDuration, gracePeriodStartTimestamp, gracePeriodDuration, rateLimit, index, holder, token] = membershipData;
269
- const gracePeriodEnd = gracePeriodStartTimestamp.add(gracePeriodDuration);
270
277
  let state;
271
- if (currentBlock < gracePeriodStartTimestamp.toNumber()) {
278
+ if (currentBlock < startBlock) {
272
279
  state = MembershipState.Active;
273
280
  }
274
- else if (currentBlock < gracePeriodEnd.toNumber()) {
281
+ else if (currentBlock < endBlock) {
275
282
  state = MembershipState.GracePeriod;
276
283
  }
277
284
  else {
278
285
  state = MembershipState.Expired;
279
286
  }
287
+ const index = await this.getMemberIndex(idCommitment);
288
+ if (!index)
289
+ return undefined;
280
290
  return {
281
291
  index,
282
- idCommitment: idCommitmentBigInt.toString(),
283
- rateLimit: Number(rateLimit),
284
- startBlock: gracePeriodStartTimestamp.toNumber(),
285
- endBlock: gracePeriodEnd.toNumber(),
286
- state,
287
- depositAmount,
288
- activeDuration,
289
- gracePeriodDuration,
290
- holder,
291
- token
292
+ idCommitment,
293
+ rateLimit: rateLimit.toNumber(),
294
+ startBlock: startBlock.toNumber(),
295
+ endBlock: endBlock.toNumber(),
296
+ state
292
297
  };
293
298
  }
294
299
  catch (error) {
295
- console.error("Error in getMembershipInfo:", error);
296
300
  return undefined;
297
301
  }
298
302
  }
299
- async extendMembership(idCommitmentBigInt) {
300
- return this.contract.extendMemberships([idCommitmentBigInt]);
303
+ async extendMembership(idCommitment) {
304
+ return this.contract.extendMemberships([idCommitment]);
301
305
  }
302
- async eraseMembership(idCommitmentBigInt, eraseFromMembershipSet = true) {
303
- return this.contract.eraseMemberships([idCommitmentBigInt], eraseFromMembershipSet);
306
+ async eraseMembership(idCommitment, eraseFromMembershipSet = true) {
307
+ return this.contract.eraseMemberships([idCommitment], eraseFromMembershipSet);
304
308
  }
305
- async registerMembership(idCommitmentBigInt, rateLimit = DEFAULT_RATE_LIMIT) {
309
+ async registerMembership(idCommitment, rateLimit = DEFAULT_RATE_LIMIT) {
306
310
  if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
307
311
  rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
308
312
  throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
309
313
  }
310
- return this.contract.register(idCommitmentBigInt, rateLimit, []);
314
+ return this.contract.register(idCommitment, rateLimit, []);
311
315
  }
312
- async withdraw(token, from) {
316
+ async withdraw(token, holder) {
313
317
  try {
314
- const tx = await this.contract.withdraw(token, from);
318
+ const tx = await this.contract.withdraw(token, { from: holder });
315
319
  await tx.wait();
316
320
  }
317
321
  catch (error) {
@@ -322,7 +326,7 @@ class RLNBaseContract {
322
326
  try {
323
327
  log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
324
328
  // Check if the ID commitment is already registered
325
- const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt);
329
+ const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt.toString());
326
330
  if (existingIndex) {
327
331
  throw new Error(`ID commitment is already registered with index ${existingIndex}`);
328
332
  }
@@ -431,15 +435,10 @@ class RLNBaseContract {
431
435
  * Validates that the rate limit is within the allowed range
432
436
  * @throws Error if the rate limit is outside the allowed range
433
437
  */
434
- async validateRateLimit(rateLimit) {
435
- const [minRate, maxRate] = await Promise.all([
436
- this.contract.minMembershipRateLimit(),
437
- this.contract.maxMembershipRateLimit()
438
- ]);
439
- const minRateNum = BigNumber.from(minRate).toNumber();
440
- const maxRateNum = BigNumber.from(maxRate).toNumber();
441
- if (rateLimit < minRateNum || rateLimit > maxRateNum) {
442
- throw new Error(`Rate limit must be between ${minRateNum} and ${maxRateNum} messages per epoch`);
438
+ 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`);
443
442
  }
444
443
  }
445
444
  get membersFilter() {
@@ -460,9 +459,9 @@ class RLNBaseContract {
460
459
  }
461
460
  return this._membersExpiredFilter;
462
461
  }
463
- async getMemberIndex(idCommitmentBigInt) {
462
+ async getMemberIndex(idCommitment) {
464
463
  try {
465
- const events = await this.contract.queryFilter(this.contract.filters.MembershipRegistered(idCommitmentBigInt));
464
+ const events = await this.contract.queryFilter(this.contract.filters.MembershipRegistered(idCommitment));
466
465
  if (events.length === 0)
467
466
  return undefined;
468
467
  // Get the most recent registration event
@@ -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 = void 0;