@waku/rln 0.0.2-b4f5423.0 → 0.0.2-c8128d1.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/bundle/packages/rln/dist/contract/rln_contract.js +84 -10
- package/bundle/packages/rln/dist/rln.js +2 -8
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/rln_contract.d.ts +2 -2
- package/dist/contract/rln_contract.js +84 -10
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/rln.js +2 -8
- package/dist/rln.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/rln_contract.ts +143 -12
- package/src/rln.ts +3 -9
@@ -10,6 +10,7 @@ import { RATE_LIMIT_PARAMS, DEFAULT_RATE_LIMIT } from './constants.js';
|
|
10
10
|
import { Contract } from '../../../../node_modules/@ethersproject/contracts/lib.esm/index.js';
|
11
11
|
import { BigNumber } from '../../../../node_modules/@ethersproject/bignumber/lib.esm/bignumber.js';
|
12
12
|
|
13
|
+
/* eslint-disable no-console */
|
13
14
|
const log = new Logger("waku:rln:contract");
|
14
15
|
var MembershipState;
|
15
16
|
(function (MembershipState) {
|
@@ -48,7 +49,7 @@ class RLNContract {
|
|
48
49
|
// Use the injected contract if provided; otherwise, instantiate a new one.
|
49
50
|
this.contract = contract || new Contract(address, RLN_ABI, signer);
|
50
51
|
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
51
|
-
// Initialize event filters
|
52
|
+
// Initialize event filters
|
52
53
|
this._membersFilter = this.contract.filters.MembershipRegistered();
|
53
54
|
this._membersRemovedFilter = this.contract.filters.MembershipErased();
|
54
55
|
this._membersExpiredFilter = this.contract.filters.MembershipExpired();
|
@@ -177,7 +178,6 @@ class RLNContract {
|
|
177
178
|
evt.event === "MembershipExpired") {
|
178
179
|
// Both MembershipErased and MembershipExpired events should remove members
|
179
180
|
let index = evt.args.index;
|
180
|
-
// Ensure index is an ethers.BigNumber
|
181
181
|
if (!index) {
|
182
182
|
return;
|
183
183
|
}
|
@@ -202,7 +202,6 @@ class RLNContract {
|
|
202
202
|
eventsPerBlock.push(evt);
|
203
203
|
toInsertTable.set(evt.blockNumber, eventsPerBlock);
|
204
204
|
}
|
205
|
-
// MembershipExtended events don't change the membership set, so we don't need to handle them here
|
206
205
|
});
|
207
206
|
this.removeMembers(rlnInstance, toRemoveTable);
|
208
207
|
this.insertMembers(rlnInstance, toInsertTable);
|
@@ -260,25 +259,66 @@ class RLNContract {
|
|
260
259
|
}
|
261
260
|
async registerWithIdentity(identity) {
|
262
261
|
try {
|
262
|
+
console.log("registerWithIdentity - starting registration process");
|
263
|
+
console.log("registerWithIdentity - identity:", identity);
|
264
|
+
console.log("registerWithIdentity - IDCommitmentBigInt:", identity.IDCommitmentBigInt.toString());
|
265
|
+
console.log("registerWithIdentity - rate limit:", this.rateLimit);
|
263
266
|
log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
|
267
|
+
// Check if the ID commitment is already registered
|
268
|
+
const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt.toString());
|
269
|
+
if (existingIndex) {
|
270
|
+
console.error(`ID commitment is already registered with index ${existingIndex}`);
|
271
|
+
throw new Error(`ID commitment is already registered with index ${existingIndex}`);
|
272
|
+
}
|
273
|
+
// Check if there's enough remaining rate limit
|
274
|
+
const remainingRateLimit = await this.getRemainingTotalRateLimit();
|
275
|
+
if (remainingRateLimit < this.rateLimit) {
|
276
|
+
console.error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
|
277
|
+
throw new Error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
|
278
|
+
}
|
279
|
+
console.log("registerWithIdentity - calling contract.register");
|
264
280
|
const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], { gasLimit: 300000 });
|
281
|
+
console.log("registerWithIdentity - txRegisterResponse:", txRegisterResponse);
|
282
|
+
console.log("registerWithIdentity - hash:", txRegisterResponse.hash);
|
283
|
+
console.log("registerWithIdentity - waiting for transaction confirmation...");
|
265
284
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
285
|
+
console.log("registerWithIdentity - txRegisterReceipt:", txRegisterReceipt);
|
286
|
+
console.log("registerWithIdentity - transaction status:", txRegisterReceipt.status);
|
287
|
+
console.log("registerWithIdentity - block number:", txRegisterReceipt.blockNumber);
|
288
|
+
console.log("registerWithIdentity - gas used:", txRegisterReceipt.gasUsed.toString());
|
289
|
+
// Check transaction status
|
290
|
+
if (txRegisterReceipt.status === 0) {
|
291
|
+
console.error("Transaction failed on-chain");
|
292
|
+
throw new Error("Transaction failed on-chain");
|
293
|
+
}
|
266
294
|
const memberRegistered = txRegisterReceipt.events?.find((event) => event.event === "MembershipRegistered");
|
295
|
+
console.log("registerWithIdentity - memberRegistered event:", memberRegistered);
|
267
296
|
if (!memberRegistered || !memberRegistered.args) {
|
268
|
-
log
|
297
|
+
console.log("registerWithIdentity - ERROR: no memberRegistered event found");
|
298
|
+
console.log("registerWithIdentity - all events:", txRegisterReceipt.events);
|
299
|
+
console.error("Failed to register membership: No MembershipRegistered event found");
|
269
300
|
return undefined;
|
270
301
|
}
|
302
|
+
console.log("registerWithIdentity - memberRegistered args:", memberRegistered.args);
|
271
303
|
const decodedData = {
|
272
304
|
idCommitment: memberRegistered.args.idCommitment,
|
273
305
|
membershipRateLimit: memberRegistered.args.membershipRateLimit,
|
274
306
|
index: memberRegistered.args.index
|
275
307
|
};
|
308
|
+
console.log("registerWithIdentity - decodedData:", decodedData);
|
309
|
+
console.log("registerWithIdentity - index:", decodedData.index.toString());
|
310
|
+
console.log("registerWithIdentity - membershipRateLimit:", decodedData.membershipRateLimit.toString());
|
276
311
|
log.info(`Successfully registered membership with index ${decodedData.index} ` +
|
277
312
|
`and rate limit ${decodedData.membershipRateLimit}`);
|
313
|
+
console.log("registerWithIdentity - getting network information");
|
278
314
|
const network = await this.contract.provider.getNetwork();
|
315
|
+
console.log("registerWithIdentity - network:", network);
|
316
|
+
console.log("registerWithIdentity - chainId:", network.chainId);
|
279
317
|
const address = this.contract.address;
|
318
|
+
console.log("registerWithIdentity - contract address:", address);
|
280
319
|
const membershipId = decodedData.index.toNumber();
|
281
|
-
|
320
|
+
console.log("registerWithIdentity - membershipId:", membershipId);
|
321
|
+
const result = {
|
282
322
|
identity,
|
283
323
|
membership: {
|
284
324
|
address,
|
@@ -286,10 +326,39 @@ class RLNContract {
|
|
286
326
|
chainId: network.chainId
|
287
327
|
}
|
288
328
|
};
|
329
|
+
console.log("registerWithIdentity - returning result:", result);
|
330
|
+
return result;
|
289
331
|
}
|
290
332
|
catch (error) {
|
291
|
-
log
|
292
|
-
|
333
|
+
console.log("registerWithIdentity - ERROR:", error);
|
334
|
+
// Improved error handling to decode contract errors
|
335
|
+
if (error instanceof Error) {
|
336
|
+
const errorMessage = error.message;
|
337
|
+
console.log("registerWithIdentity - error message:", errorMessage);
|
338
|
+
console.log("registerWithIdentity - error stack:", error.stack);
|
339
|
+
// Try to extract more specific error information
|
340
|
+
if (errorMessage.includes("CannotExceedMaxTotalRateLimit")) {
|
341
|
+
console.error("Registration failed: Cannot exceed maximum total rate limit");
|
342
|
+
}
|
343
|
+
else if (errorMessage.includes("InvalidIdCommitment")) {
|
344
|
+
console.error("Registration failed: Invalid ID commitment");
|
345
|
+
}
|
346
|
+
else if (errorMessage.includes("InvalidMembershipRateLimit")) {
|
347
|
+
console.error("Registration failed: Invalid membership rate limit");
|
348
|
+
}
|
349
|
+
else if (errorMessage.includes("execution reverted")) {
|
350
|
+
// Generic revert
|
351
|
+
console.error("Contract execution reverted. Check contract requirements.");
|
352
|
+
}
|
353
|
+
else {
|
354
|
+
console.error(`Error in registerWithIdentity: ${errorMessage}`);
|
355
|
+
}
|
356
|
+
}
|
357
|
+
else {
|
358
|
+
console.error("Unknown error in registerWithIdentity");
|
359
|
+
}
|
360
|
+
// Re-throw the error to allow callers to handle it
|
361
|
+
throw error;
|
293
362
|
}
|
294
363
|
}
|
295
364
|
/**
|
@@ -390,17 +459,22 @@ class RLNContract {
|
|
390
459
|
}
|
391
460
|
}
|
392
461
|
async extendMembership(idCommitment) {
|
393
|
-
|
462
|
+
const tx = await this.contract.extendMemberships([idCommitment]);
|
463
|
+
return await tx.wait();
|
394
464
|
}
|
395
465
|
async eraseMembership(idCommitment, eraseFromMembershipSet = true) {
|
396
|
-
|
466
|
+
const tx = await this.contract.eraseMemberships([idCommitment], eraseFromMembershipSet);
|
467
|
+
return await tx.wait();
|
397
468
|
}
|
398
469
|
async registerMembership(idCommitment, rateLimit = DEFAULT_RATE_LIMIT) {
|
399
470
|
if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
400
471
|
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
|
401
472
|
throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
|
402
473
|
}
|
403
|
-
|
474
|
+
console.log("registering membership", idCommitment, rateLimit);
|
475
|
+
const txn = this.contract.register(idCommitment, rateLimit, []);
|
476
|
+
console.log("txn", txn);
|
477
|
+
return txn;
|
404
478
|
}
|
405
479
|
async getMemberIndex(idCommitment) {
|
406
480
|
try {
|
@@ -100,8 +100,6 @@ class RLNInstance {
|
|
100
100
|
return this._signer;
|
101
101
|
}
|
102
102
|
async start(options = {}) {
|
103
|
-
// eslint-disable-next-line no-console
|
104
|
-
console.log("starting", options);
|
105
103
|
if (this.started || this.starting) {
|
106
104
|
return;
|
107
105
|
}
|
@@ -133,12 +131,6 @@ class RLNInstance {
|
|
133
131
|
if (address === SEPOLIA_CONTRACT.address) {
|
134
132
|
chainId = SEPOLIA_CONTRACT.chainId;
|
135
133
|
}
|
136
|
-
// eslint-disable-next-line no-console
|
137
|
-
console.log({
|
138
|
-
chainId,
|
139
|
-
address,
|
140
|
-
SEPOLIA_CONTRACT
|
141
|
-
});
|
142
134
|
const signer = options.signer || (await extractMetaMaskSigner());
|
143
135
|
const currentChainId = await signer.getChainId();
|
144
136
|
if (chainId && chainId !== currentChainId) {
|
@@ -174,6 +166,8 @@ class RLNInstance {
|
|
174
166
|
if ("signature" in options) {
|
175
167
|
identity = this.zerokit.generateSeededIdentityCredential(options.signature);
|
176
168
|
}
|
169
|
+
// eslint-disable-next-line no-console
|
170
|
+
console.log("registering membership", identity);
|
177
171
|
if (!identity) {
|
178
172
|
throw Error("Missing signature or identity to register membership.");
|
179
173
|
}
|