@waku/rln 0.1.5-5e19700.0 → 0.1.5-ea6daae.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.
- package/README.md +0 -5
- package/bundle/_virtual/index2.js +1 -1
- package/bundle/_virtual/utils.js +2 -2
- package/bundle/_virtual/utils2.js +2 -2
- package/bundle/index.js +1 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/checksum.js +3 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/cipher.js +4 -4
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/class.js +7 -7
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/functional.js +7 -7
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/index.js +6 -6
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/kdf.js +5 -5
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/password.js +1 -1
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/schema-validation.js +2 -2
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/types.js +1 -1
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_assert.js +1 -1
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_sha2.js +3 -3
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_u64.js +1 -1
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/hmac.js +3 -3
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/pbkdf2.js +4 -4
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/scrypt.js +5 -5
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/sha256.js +3 -3
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/sha512.js +4 -4
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/utils.js +2 -2
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +3 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +7 -7
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +3 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +3 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +3 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +7 -7
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +1 -1
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +1 -1
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +19 -1
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +58 -10
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +1 -1
- package/bundle/node_modules/{@ethersproject/keccak256/node_modules/js-sha3 → js-sha3}/src/sha3.js +2 -2
- package/bundle/packages/rln/dist/contract/abi.js +248 -502
- package/bundle/packages/rln/dist/contract/constants.js +4 -4
- package/bundle/packages/rln/dist/contract/rln_contract.js +36 -120
- package/bundle/packages/rln/dist/keystore/cipher.js +3 -3
- package/bundle/packages/rln/dist/keystore/keystore.js +2 -3
- package/bundle/packages/rln/dist/rln.js +6 -6
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/abi.d.ts +17 -21
- package/dist/contract/abi.js +248 -502
- package/dist/contract/abi.js.map +1 -1
- package/dist/contract/constants.d.ts +18 -22
- package/dist/contract/constants.js +3 -3
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +3 -10
- package/dist/contract/rln_contract.js +36 -120
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.js +1 -2
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +0 -1
- package/dist/rln.d.ts +1 -1
- package/dist/rln.js +6 -6
- package/dist/rln.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/abi.ts +248 -502
- package/src/contract/constants.ts +3 -3
- package/src/contract/rln_contract.ts +46 -158
- package/src/index.ts +2 -17
- package/src/keystore/keystore.ts +1 -2
- package/src/keystore/types.ts +0 -1
- package/src/rln.ts +7 -7
- package/bundle/packages/rln/dist/contract/rln_light_contract.js +0 -473
- package/bundle/packages/rln/dist/rln_light.js +0 -149
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +0 -43
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +0 -116
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/hmac.js +0 -79
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/sha256.js +0 -126
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +0 -43
- package/dist/codec.test-utils.d.ts +0 -36
- package/dist/codec.test-utils.js +0 -56
- package/dist/codec.test-utils.js.map +0 -1
- package/dist/contract/rln_light_contract.d.ts +0 -124
- package/dist/contract/rln_light_contract.js +0 -456
- package/dist/contract/rln_light_contract.js.map +0 -1
- package/dist/contract/test-setup.d.ts +0 -26
- package/dist/contract/test-setup.js +0 -56
- package/dist/contract/test-setup.js.map +0 -1
- package/dist/contract/test-utils.d.ts +0 -39
- package/dist/contract/test-utils.js +0 -118
- package/dist/contract/test-utils.js.map +0 -1
- package/dist/rln_light.d.ts +0 -64
- package/dist/rln_light.js +0 -144
- package/dist/rln_light.js.map +0 -1
- package/src/codec.test-utils.ts +0 -80
- package/src/contract/rln_light_contract.ts +0 -718
- package/src/contract/test-setup.ts +0 -86
- package/src/contract/test-utils.ts +0 -179
- package/src/rln_light.ts +0 -235
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +0 -0
@@ -1,8 +1,8 @@
|
|
1
1
|
import { RLN_ABI } from "./abi.js";
|
2
2
|
|
3
|
-
export const
|
4
|
-
chainId:
|
5
|
-
address: "
|
3
|
+
export const SEPOLIA_CONTRACT = {
|
4
|
+
chainId: 11155111,
|
5
|
+
address: "0xCB33Aa5B38d79E3D9Fa8B10afF38AA201399a7e3",
|
6
6
|
abi: RLN_ABI
|
7
7
|
};
|
8
8
|
|
@@ -30,7 +30,7 @@ interface RLNContractInitOptions extends RLNContractOptions {
|
|
30
30
|
|
31
31
|
export interface MembershipRegisteredEvent {
|
32
32
|
idCommitment: string;
|
33
|
-
|
33
|
+
rateLimit: number;
|
34
34
|
index: ethers.BigNumber;
|
35
35
|
}
|
36
36
|
|
@@ -65,8 +65,7 @@ export class RLNContract {
|
|
65
65
|
|
66
66
|
private _members: Map<number, Member> = new Map();
|
67
67
|
private _membersFilter: ethers.EventFilter;
|
68
|
-
private
|
69
|
-
private _membersExpiredFilter: ethers.EventFilter;
|
68
|
+
private _membersRemovedFilter: ethers.EventFilter;
|
70
69
|
|
71
70
|
/**
|
72
71
|
* Asynchronous initializer for RLNContract.
|
@@ -95,7 +94,15 @@ export class RLNContract {
|
|
95
94
|
contract
|
96
95
|
} = options;
|
97
96
|
|
98
|
-
|
97
|
+
if (
|
98
|
+
rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
99
|
+
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE
|
100
|
+
) {
|
101
|
+
throw new Error(
|
102
|
+
`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE} messages per epoch`
|
103
|
+
);
|
104
|
+
}
|
105
|
+
|
99
106
|
this.rateLimit = rateLimit;
|
100
107
|
|
101
108
|
const initialRoot = rlnInstance.zerokit.getMerkleRoot();
|
@@ -104,25 +111,9 @@ export class RLNContract {
|
|
104
111
|
this.contract = contract || new ethers.Contract(address, RLN_ABI, signer);
|
105
112
|
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
106
113
|
|
107
|
-
// Initialize event filters
|
114
|
+
// Initialize event filters for MembershipRegistered and MembershipRemoved
|
108
115
|
this._membersFilter = this.contract.filters.MembershipRegistered();
|
109
|
-
this.
|
110
|
-
this._membersExpiredFilter = this.contract.filters.MembershipExpired();
|
111
|
-
}
|
112
|
-
|
113
|
-
/**
|
114
|
-
* Validates that the rate limit is within the allowed range
|
115
|
-
* @throws Error if the rate limit is outside the allowed range
|
116
|
-
*/
|
117
|
-
private validateRateLimit(rateLimit: number): void {
|
118
|
-
if (
|
119
|
-
rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
120
|
-
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE
|
121
|
-
) {
|
122
|
-
throw new Error(
|
123
|
-
`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE} messages per epoch`
|
124
|
-
);
|
125
|
-
}
|
116
|
+
this._membersRemovedFilter = this.contract.filters.MembershipRemoved();
|
126
117
|
}
|
127
118
|
|
128
119
|
/**
|
@@ -191,7 +182,7 @@ export class RLNContract {
|
|
191
182
|
this.contract.maxTotalRateLimit(),
|
192
183
|
this.contract.currentTotalRateLimit()
|
193
184
|
]);
|
194
|
-
return
|
185
|
+
return maxTotal.sub(currentTotal).toNumber();
|
195
186
|
}
|
196
187
|
|
197
188
|
/**
|
@@ -199,7 +190,6 @@ export class RLNContract {
|
|
199
190
|
* @param newRateLimit The new rate limit to use
|
200
191
|
*/
|
201
192
|
public async setRateLimit(newRateLimit: number): Promise<void> {
|
202
|
-
this.validateRateLimit(newRateLimit);
|
203
193
|
this.rateLimit = newRateLimit;
|
204
194
|
}
|
205
195
|
|
@@ -217,18 +207,11 @@ export class RLNContract {
|
|
217
207
|
return this._membersFilter;
|
218
208
|
}
|
219
209
|
|
220
|
-
private get
|
221
|
-
if (!this.
|
222
|
-
throw Error("
|
210
|
+
private get membersRemovedFilter(): ethers.EventFilter {
|
211
|
+
if (!this._membersRemovedFilter) {
|
212
|
+
throw Error("MembersRemoved filter was not initialized.");
|
223
213
|
}
|
224
|
-
return this.
|
225
|
-
}
|
226
|
-
|
227
|
-
private get membersExpiredFilter(): ethers.EventFilter {
|
228
|
-
if (!this._membersExpiredFilter) {
|
229
|
-
throw Error("MembersExpired filter was not initialized.");
|
230
|
-
}
|
231
|
-
return this._membersExpiredFilter;
|
214
|
+
return this._membersRemovedFilter;
|
232
215
|
}
|
233
216
|
|
234
217
|
public async fetchMembers(
|
@@ -243,19 +226,10 @@ export class RLNContract {
|
|
243
226
|
const removedMemberEvents = await queryFilter(this.contract, {
|
244
227
|
fromBlock: this.deployBlock,
|
245
228
|
...options,
|
246
|
-
membersFilter: this.
|
247
|
-
});
|
248
|
-
const expiredMemberEvents = await queryFilter(this.contract, {
|
249
|
-
fromBlock: this.deployBlock,
|
250
|
-
...options,
|
251
|
-
membersFilter: this.membersExpiredFilter
|
229
|
+
membersFilter: this.membersRemovedFilter
|
252
230
|
});
|
253
231
|
|
254
|
-
const events = [
|
255
|
-
...registeredMemberEvents,
|
256
|
-
...removedMemberEvents,
|
257
|
-
...expiredMemberEvents
|
258
|
-
];
|
232
|
+
const events = [...registeredMemberEvents, ...removedMemberEvents];
|
259
233
|
this.processEvents(rlnInstance, events);
|
260
234
|
}
|
261
235
|
|
@@ -268,26 +242,8 @@ export class RLNContract {
|
|
268
242
|
return;
|
269
243
|
}
|
270
244
|
|
271
|
-
if (
|
272
|
-
evt.
|
273
|
-
evt.event === "MembershipExpired"
|
274
|
-
) {
|
275
|
-
let index = evt.args.index;
|
276
|
-
|
277
|
-
if (!index) {
|
278
|
-
return;
|
279
|
-
}
|
280
|
-
|
281
|
-
if (typeof index === "number" || typeof index === "string") {
|
282
|
-
index = ethers.BigNumber.from(index);
|
283
|
-
} else {
|
284
|
-
log.error("Index is not a number or string", {
|
285
|
-
index,
|
286
|
-
event: evt
|
287
|
-
});
|
288
|
-
return;
|
289
|
-
}
|
290
|
-
|
245
|
+
if (evt.event === "MembershipRemoved") {
|
246
|
+
const index = evt.args.index as ethers.BigNumber;
|
291
247
|
const toRemoveVal = toRemoveTable.get(evt.blockNumber);
|
292
248
|
if (toRemoveVal != undefined) {
|
293
249
|
toRemoveVal.push(index.toNumber());
|
@@ -319,21 +275,15 @@ export class RLNContract {
|
|
319
275
|
if (!evt.args) return;
|
320
276
|
|
321
277
|
const _idCommitment = evt.args.idCommitment as string;
|
322
|
-
|
278
|
+
const index = evt.args.index as ethers.BigNumber;
|
323
279
|
|
324
280
|
if (!_idCommitment || !index) {
|
325
281
|
return;
|
326
282
|
}
|
327
283
|
|
328
|
-
if (typeof index === "number" || typeof index === "string") {
|
329
|
-
index = ethers.BigNumber.from(index);
|
330
|
-
}
|
331
|
-
|
332
284
|
const idCommitment = zeroPadLE(hexToBytes(_idCommitment), 32);
|
333
285
|
rlnInstance.zerokit.insertMember(idCommitment);
|
334
|
-
|
335
|
-
const numericIndex = index.toNumber();
|
336
|
-
this._members.set(numericIndex, {
|
286
|
+
this._members.set(index.toNumber(), {
|
337
287
|
index,
|
338
288
|
idCommitment: _idCommitment
|
339
289
|
});
|
@@ -366,7 +316,7 @@ export class RLNContract {
|
|
366
316
|
this.membersFilter,
|
367
317
|
(
|
368
318
|
_idCommitment: string,
|
369
|
-
|
319
|
+
_rateLimit: number,
|
370
320
|
_index: ethers.BigNumber,
|
371
321
|
event: ethers.Event
|
372
322
|
) => {
|
@@ -375,22 +325,9 @@ export class RLNContract {
|
|
375
325
|
);
|
376
326
|
|
377
327
|
this.contract.on(
|
378
|
-
this.
|
328
|
+
this.membersRemovedFilter,
|
379
329
|
(
|
380
330
|
_idCommitment: string,
|
381
|
-
_membershipRateLimit: ethers.BigNumber,
|
382
|
-
_index: ethers.BigNumber,
|
383
|
-
event: ethers.Event
|
384
|
-
) => {
|
385
|
-
this.processEvents(rlnInstance, [event]);
|
386
|
-
}
|
387
|
-
);
|
388
|
-
|
389
|
-
this.contract.on(
|
390
|
-
this.membersExpiredFilter,
|
391
|
-
(
|
392
|
-
_idCommitment: string,
|
393
|
-
_membershipRateLimit: ethers.BigNumber,
|
394
331
|
_index: ethers.BigNumber,
|
395
332
|
event: ethers.Event
|
396
333
|
) => {
|
@@ -407,45 +344,15 @@ export class RLNContract {
|
|
407
344
|
`Registering identity with rate limit: ${this.rateLimit} messages/epoch`
|
408
345
|
);
|
409
346
|
|
410
|
-
// Check if the ID commitment is already registered
|
411
|
-
const existingIndex = await this.getMemberIndex(
|
412
|
-
identity.IDCommitmentBigInt.toString()
|
413
|
-
);
|
414
|
-
if (existingIndex) {
|
415
|
-
throw new Error(
|
416
|
-
`ID commitment is already registered with index ${existingIndex}`
|
417
|
-
);
|
418
|
-
}
|
419
|
-
|
420
|
-
// Check if there's enough remaining rate limit
|
421
|
-
const remainingRateLimit = await this.getRemainingTotalRateLimit();
|
422
|
-
if (remainingRateLimit < this.rateLimit) {
|
423
|
-
throw new Error(
|
424
|
-
`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`
|
425
|
-
);
|
426
|
-
}
|
427
|
-
|
428
|
-
const estimatedGas = await this.contract.estimateGas.register(
|
429
|
-
identity.IDCommitmentBigInt,
|
430
|
-
this.rateLimit,
|
431
|
-
[]
|
432
|
-
);
|
433
|
-
const gasLimit = estimatedGas.add(10000);
|
434
|
-
|
435
347
|
const txRegisterResponse: ethers.ContractTransaction =
|
436
348
|
await this.contract.register(
|
437
349
|
identity.IDCommitmentBigInt,
|
438
350
|
this.rateLimit,
|
439
351
|
[],
|
440
|
-
{ gasLimit }
|
352
|
+
{ gasLimit: 300000 }
|
441
353
|
);
|
442
|
-
|
443
354
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
444
355
|
|
445
|
-
if (txRegisterReceipt.status === 0) {
|
446
|
-
throw new Error("Transaction failed on-chain");
|
447
|
-
}
|
448
|
-
|
449
356
|
const memberRegistered = txRegisterReceipt.events?.find(
|
450
357
|
(event) => event.event === "MembershipRegistered"
|
451
358
|
);
|
@@ -459,55 +366,30 @@ export class RLNContract {
|
|
459
366
|
|
460
367
|
const decodedData: MembershipRegisteredEvent = {
|
461
368
|
idCommitment: memberRegistered.args.idCommitment,
|
462
|
-
|
369
|
+
rateLimit: memberRegistered.args.rateLimit,
|
463
370
|
index: memberRegistered.args.index
|
464
371
|
};
|
465
372
|
|
466
373
|
log.info(
|
467
374
|
`Successfully registered membership with index ${decodedData.index} ` +
|
468
|
-
`and rate limit ${decodedData.
|
375
|
+
`and rate limit ${decodedData.rateLimit}`
|
469
376
|
);
|
470
377
|
|
471
378
|
const network = await this.contract.provider.getNetwork();
|
472
379
|
const address = this.contract.address;
|
473
|
-
const membershipId =
|
380
|
+
const membershipId = decodedData.index.toNumber();
|
474
381
|
|
475
382
|
return {
|
476
383
|
identity,
|
477
384
|
membership: {
|
478
385
|
address,
|
479
386
|
treeIndex: membershipId,
|
480
|
-
chainId: network.chainId
|
481
|
-
rateLimit: decodedData.membershipRateLimit.toNumber()
|
387
|
+
chainId: network.chainId
|
482
388
|
}
|
483
389
|
};
|
484
390
|
} catch (error) {
|
485
|
-
|
486
|
-
|
487
|
-
log.error("registerWithIdentity - error message:", errorMessage);
|
488
|
-
log.error("registerWithIdentity - error stack:", error.stack);
|
489
|
-
|
490
|
-
// Try to extract more specific error information
|
491
|
-
if (errorMessage.includes("CannotExceedMaxTotalRateLimit")) {
|
492
|
-
throw new Error(
|
493
|
-
"Registration failed: Cannot exceed maximum total rate limit"
|
494
|
-
);
|
495
|
-
} else if (errorMessage.includes("InvalidIdCommitment")) {
|
496
|
-
throw new Error("Registration failed: Invalid ID commitment");
|
497
|
-
} else if (errorMessage.includes("InvalidMembershipRateLimit")) {
|
498
|
-
throw new Error("Registration failed: Invalid membership rate limit");
|
499
|
-
} else if (errorMessage.includes("execution reverted")) {
|
500
|
-
throw new Error(
|
501
|
-
"Contract execution reverted. Check contract requirements."
|
502
|
-
);
|
503
|
-
} else {
|
504
|
-
throw new Error(`Error in registerWithIdentity: ${errorMessage}`);
|
505
|
-
}
|
506
|
-
} else {
|
507
|
-
throw new Error("Unknown error in registerWithIdentity", {
|
508
|
-
cause: error
|
509
|
-
});
|
510
|
-
}
|
391
|
+
log.error(`Error in registerWithIdentity: ${(error as Error).message}`);
|
392
|
+
return undefined;
|
511
393
|
}
|
512
394
|
}
|
513
395
|
|
@@ -585,26 +467,25 @@ export class RLNContract {
|
|
585
467
|
|
586
468
|
const decodedData: MembershipRegisteredEvent = {
|
587
469
|
idCommitment: memberRegistered.args.idCommitment,
|
588
|
-
|
470
|
+
rateLimit: memberRegistered.args.rateLimit,
|
589
471
|
index: memberRegistered.args.index
|
590
472
|
};
|
591
473
|
|
592
474
|
log.info(
|
593
475
|
`Successfully registered membership with permit. Index: ${decodedData.index}, ` +
|
594
|
-
`Rate limit: ${decodedData.
|
476
|
+
`Rate limit: ${decodedData.rateLimit}, Erased ${idCommitmentsToErase.length} commitments`
|
595
477
|
);
|
596
478
|
|
597
479
|
const network = await this.contract.provider.getNetwork();
|
598
480
|
const address = this.contract.address;
|
599
|
-
const membershipId =
|
481
|
+
const membershipId = decodedData.index.toNumber();
|
600
482
|
|
601
483
|
return {
|
602
484
|
identity,
|
603
485
|
membership: {
|
604
486
|
address,
|
605
487
|
treeIndex: membershipId,
|
606
|
-
chainId: network.chainId
|
607
|
-
rateLimit: decodedData.membershipRateLimit.toNumber()
|
488
|
+
chainId: network.chainId
|
608
489
|
}
|
609
490
|
};
|
610
491
|
} catch (error) {
|
@@ -679,9 +560,16 @@ export class RLNContract {
|
|
679
560
|
|
680
561
|
public async registerMembership(
|
681
562
|
idCommitment: string,
|
682
|
-
rateLimit: number =
|
563
|
+
rateLimit: number = DEFAULT_RATE_LIMIT
|
683
564
|
): Promise<ethers.ContractTransaction> {
|
684
|
-
|
565
|
+
if (
|
566
|
+
rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
567
|
+
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE
|
568
|
+
) {
|
569
|
+
throw new Error(
|
570
|
+
`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`
|
571
|
+
);
|
572
|
+
}
|
685
573
|
return this.contract.register(idCommitment, rateLimit, []);
|
686
574
|
}
|
687
575
|
|
package/src/index.ts
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
2
|
import { RLN_ABI } from "./contract/abi.js";
|
3
|
-
import {
|
4
|
-
import { RLNLightContract } from "./contract/rln_light_contract.js";
|
3
|
+
import { RLNContract, SEPOLIA_CONTRACT } from "./contract/index.js";
|
5
4
|
import { createRLN } from "./create.js";
|
6
5
|
import { IdentityCredential } from "./identity.js";
|
7
6
|
import { Keystore } from "./keystore/index.js";
|
8
7
|
import { Proof } from "./proof.js";
|
9
8
|
import { RLNInstance } from "./rln.js";
|
10
|
-
import { RLNLightInstance } from "./rln_light.js";
|
11
9
|
import { MerkleRootTracker } from "./root_tracker.js";
|
12
10
|
import { extractMetaMaskSigner } from "./utils/index.js";
|
13
11
|
|
14
12
|
export {
|
15
|
-
RLNLightInstance,
|
16
|
-
RLNLightContract,
|
17
13
|
createRLN,
|
18
14
|
Keystore,
|
19
15
|
RLNInstance,
|
@@ -23,18 +19,7 @@ export {
|
|
23
19
|
RLNDecoder,
|
24
20
|
MerkleRootTracker,
|
25
21
|
RLNContract,
|
26
|
-
|
22
|
+
SEPOLIA_CONTRACT,
|
27
23
|
extractMetaMaskSigner,
|
28
24
|
RLN_ABI
|
29
25
|
};
|
30
|
-
|
31
|
-
export type {
|
32
|
-
DecryptedCredentials,
|
33
|
-
EncryptedCredentials,
|
34
|
-
Keccak256Hash,
|
35
|
-
KeystoreEntity,
|
36
|
-
MembershipHash,
|
37
|
-
MembershipInfo,
|
38
|
-
Password,
|
39
|
-
Sha256Hash
|
40
|
-
} from "./keystore/types.js";
|
package/src/keystore/keystore.ts
CHANGED
@@ -274,8 +274,7 @@ export class Keystore {
|
|
274
274
|
membership: {
|
275
275
|
treeIndex: _.get(obj, "treeIndex"),
|
276
276
|
chainId: _.get(obj, "membershipContract.chainId"),
|
277
|
-
address: _.get(obj, "membershipContract.address")
|
278
|
-
rateLimit: _.get(obj, "membershipContract.rateLimit")
|
277
|
+
address: _.get(obj, "membershipContract.address")
|
279
278
|
}
|
280
279
|
};
|
281
280
|
} catch (err) {
|
package/src/keystore/types.ts
CHANGED
package/src/rln.ts
CHANGED
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
type RLNEncoder
|
17
17
|
} from "./codec.js";
|
18
18
|
import { DEFAULT_RATE_LIMIT } from "./contract/constants.js";
|
19
|
-
import {
|
19
|
+
import { RLNContract, SEPOLIA_CONTRACT } from "./contract/index.js";
|
20
20
|
import { IdentityCredential } from "./identity.js";
|
21
21
|
import { Keystore } from "./keystore/index.js";
|
22
22
|
import type {
|
@@ -108,7 +108,7 @@ type StartRLNOptions = {
|
|
108
108
|
*/
|
109
109
|
signer?: ethers.Signer;
|
110
110
|
/**
|
111
|
-
* If not set - will use default
|
111
|
+
* If not set - will use default SEPOLIA_CONTRACT address.
|
112
112
|
*/
|
113
113
|
address?: string;
|
114
114
|
/**
|
@@ -160,7 +160,7 @@ export class RLNInstance {
|
|
160
160
|
try {
|
161
161
|
const { credentials, keystore } =
|
162
162
|
await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
163
|
-
const { signer, address
|
163
|
+
const { signer, address } = await this.determineStartOptions(
|
164
164
|
options,
|
165
165
|
credentials
|
166
166
|
);
|
@@ -174,7 +174,7 @@ export class RLNInstance {
|
|
174
174
|
this._contract = await RLNContract.init(this, {
|
175
175
|
address: address!,
|
176
176
|
signer: signer!,
|
177
|
-
rateLimit: rateLimit ?? this.zerokit.getRateLimit
|
177
|
+
rateLimit: options.rateLimit ?? this.zerokit.getRateLimit
|
178
178
|
});
|
179
179
|
this.started = true;
|
180
180
|
} finally {
|
@@ -190,10 +190,10 @@ export class RLNInstance {
|
|
190
190
|
const address =
|
191
191
|
credentials?.membership.address ||
|
192
192
|
options.address ||
|
193
|
-
|
193
|
+
SEPOLIA_CONTRACT.address;
|
194
194
|
|
195
|
-
if (address ===
|
196
|
-
chainId =
|
195
|
+
if (address === SEPOLIA_CONTRACT.address) {
|
196
|
+
chainId = SEPOLIA_CONTRACT.chainId;
|
197
197
|
}
|
198
198
|
|
199
199
|
const signer = options.signer || (await extractMetaMaskSigner());
|