@waku/rln 0.0.2-3670e82.0 → 0.0.2-6661e30.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/_virtual/utils.js +2 -2
- package/bundle/_virtual/utils2.js +2 -2
- package/bundle/packages/rln/dist/contract/rln_contract.js +58 -59
- package/bundle/packages/rln/dist/rln.js +2 -4
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/rln_contract.d.ts +4 -4
- package/dist/contract/rln_contract.js +58 -59
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/contract/rln_light_contract.d.ts +124 -0
- package/dist/contract/rln_light_contract.js +454 -0
- package/dist/contract/rln_light_contract.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/rln.js +2 -4
- package/dist/rln.js.map +1 -1
- package/dist/rln_light.d.ts +64 -0
- package/dist/rln_light.js +144 -0
- package/dist/rln_light.js.map +1 -0
- package/package.json +1 -1
- package/src/contract/rln_contract.ts +73 -107
- package/src/contract/rln_light_contract.ts +716 -0
- package/src/index.ts +11 -0
- package/src/rln.ts +2 -5
- package/src/rln_light.ts +235 -0
package/bundle/_virtual/utils.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
var utils = {
|
1
|
+
var utils = {};
|
2
2
|
|
3
|
-
export { utils as
|
3
|
+
export { utils as __exports };
|
@@ -1,3 +1,3 @@
|
|
1
|
-
var utils = {};
|
1
|
+
var utils = {exports: {}};
|
2
2
|
|
3
|
-
export { utils as
|
3
|
+
export { utils as __module };
|
@@ -10,7 +10,6 @@ import { RATE_LIMIT_PARAMS, DEFAULT_RATE_LIMIT } from './constants.js';
|
|
10
10
|
import { Contract } from '../../../../node_modules/@ethersproject/contracts/lib.esm/index.js';
|
11
11
|
import { BigNumber } from '../../../../node_modules/@ethersproject/bignumber/lib.esm/bignumber.js';
|
12
12
|
|
13
|
-
/* eslint-disable no-console */
|
14
13
|
const log = new Logger("waku:rln:contract");
|
15
14
|
var MembershipState;
|
16
15
|
(function (MembershipState) {
|
@@ -26,7 +25,7 @@ class RLNContract {
|
|
26
25
|
rateLimit;
|
27
26
|
_members = new Map();
|
28
27
|
_membersFilter;
|
29
|
-
|
28
|
+
_membershipErasedFilter;
|
30
29
|
_membersExpiredFilter;
|
31
30
|
/**
|
32
31
|
* Asynchronous initializer for RLNContract.
|
@@ -51,7 +50,7 @@ class RLNContract {
|
|
51
50
|
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
52
51
|
// Initialize event filters
|
53
52
|
this._membersFilter = this.contract.filters.MembershipRegistered();
|
54
|
-
this.
|
53
|
+
this._membershipErasedFilter = this.contract.filters.MembershipErased();
|
55
54
|
this._membersExpiredFilter = this.contract.filters.MembershipExpired();
|
56
55
|
}
|
57
56
|
/**
|
@@ -113,7 +112,7 @@ class RLNContract {
|
|
113
112
|
this.contract.maxTotalRateLimit(),
|
114
113
|
this.contract.currentTotalRateLimit()
|
115
114
|
]);
|
116
|
-
return maxTotal
|
115
|
+
return Number(maxTotal) - Number(currentTotal);
|
117
116
|
}
|
118
117
|
/**
|
119
118
|
* Updates the rate limit for future registrations
|
@@ -132,11 +131,11 @@ class RLNContract {
|
|
132
131
|
}
|
133
132
|
return this._membersFilter;
|
134
133
|
}
|
135
|
-
get
|
136
|
-
if (!this.
|
137
|
-
throw Error("
|
134
|
+
get membershipErasedFilter() {
|
135
|
+
if (!this._membershipErasedFilter) {
|
136
|
+
throw Error("MembershipErased filter was not initialized.");
|
138
137
|
}
|
139
|
-
return this.
|
138
|
+
return this._membershipErasedFilter;
|
140
139
|
}
|
141
140
|
get membersExpiredFilter() {
|
142
141
|
if (!this._membersExpiredFilter) {
|
@@ -153,7 +152,7 @@ class RLNContract {
|
|
153
152
|
const removedMemberEvents = await queryFilter(this.contract, {
|
154
153
|
fromBlock: this.deployBlock,
|
155
154
|
...options,
|
156
|
-
membersFilter: this.
|
155
|
+
membersFilter: this.membershipErasedFilter
|
157
156
|
});
|
158
157
|
const expiredMemberEvents = await queryFilter(this.contract, {
|
159
158
|
fromBlock: this.deployBlock,
|
@@ -176,12 +175,10 @@ class RLNContract {
|
|
176
175
|
}
|
177
176
|
if (evt.event === "MembershipErased" ||
|
178
177
|
evt.event === "MembershipExpired") {
|
179
|
-
// Both MembershipErased and MembershipExpired events should remove members
|
180
178
|
let index = evt.args.index;
|
181
179
|
if (!index) {
|
182
180
|
return;
|
183
181
|
}
|
184
|
-
// Convert index to ethers.BigNumber if it's not already
|
185
182
|
if (typeof index === "number" || typeof index === "string") {
|
186
183
|
index = BigNumber.from(index);
|
187
184
|
}
|
@@ -213,20 +210,17 @@ class RLNContract {
|
|
213
210
|
return;
|
214
211
|
const _idCommitment = evt.args.idCommitment;
|
215
212
|
let index = evt.args.index;
|
216
|
-
// Ensure index is an ethers.BigNumber
|
217
213
|
if (!_idCommitment || !index) {
|
218
214
|
return;
|
219
215
|
}
|
220
|
-
// Convert index to ethers.BigNumber if it's not already
|
221
216
|
if (typeof index === "number" || typeof index === "string") {
|
222
217
|
index = BigNumber.from(index);
|
223
218
|
}
|
224
219
|
const idCommitment = zeroPadLE(hexToBytes(_idCommitment), 32);
|
225
220
|
rlnInstance.zerokit.insertMember(idCommitment);
|
226
|
-
// Always store the numeric index as the key, but the BigNumber as the value
|
227
221
|
const numericIndex = index.toNumber();
|
228
222
|
this._members.set(numericIndex, {
|
229
|
-
index,
|
223
|
+
index,
|
230
224
|
idCommitment: _idCommitment
|
231
225
|
});
|
232
226
|
});
|
@@ -250,7 +244,7 @@ class RLNContract {
|
|
250
244
|
this.contract.on(this.membersFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
|
251
245
|
this.processEvents(rlnInstance, [event]);
|
252
246
|
});
|
253
|
-
this.contract.on(this.
|
247
|
+
this.contract.on(this.membershipErasedFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
|
254
248
|
this.processEvents(rlnInstance, [event]);
|
255
249
|
});
|
256
250
|
this.contract.on(this.membersExpiredFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
|
@@ -259,49 +253,40 @@ class RLNContract {
|
|
259
253
|
}
|
260
254
|
async registerWithIdentity(identity) {
|
261
255
|
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);
|
266
256
|
log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
|
267
|
-
|
268
|
-
const
|
269
|
-
|
270
|
-
|
271
|
-
|
257
|
+
// Check if the ID commitment is already registered
|
258
|
+
const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt.toString());
|
259
|
+
if (existingIndex) {
|
260
|
+
throw new Error(`ID commitment is already registered with index ${existingIndex}`);
|
261
|
+
}
|
262
|
+
// Check if there's enough remaining rate limit
|
263
|
+
const remainingRateLimit = await this.getRemainingTotalRateLimit();
|
264
|
+
if (remainingRateLimit < this.rateLimit) {
|
265
|
+
throw new Error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
|
266
|
+
}
|
267
|
+
const estimatedGas = await this.contract.estimateGas.register(identity.IDCommitmentBigInt, this.rateLimit, []);
|
268
|
+
const gasLimit = estimatedGas.add(10000);
|
269
|
+
const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], { gasLimit });
|
272
270
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
console.log("registerWithIdentity - gas used:", txRegisterReceipt.gasUsed.toString());
|
271
|
+
if (txRegisterReceipt.status === 0) {
|
272
|
+
throw new Error("Transaction failed on-chain");
|
273
|
+
}
|
277
274
|
const memberRegistered = txRegisterReceipt.events?.find((event) => event.event === "MembershipRegistered");
|
278
|
-
console.log("registerWithIdentity - memberRegistered event:", memberRegistered);
|
279
275
|
if (!memberRegistered || !memberRegistered.args) {
|
280
|
-
console.log("registerWithIdentity - ERROR: no memberRegistered event found");
|
281
|
-
console.log("registerWithIdentity - all events:", txRegisterReceipt.events);
|
282
276
|
log.error("Failed to register membership: No MembershipRegistered event found");
|
283
277
|
return undefined;
|
284
278
|
}
|
285
|
-
console.log("registerWithIdentity - memberRegistered args:", memberRegistered.args);
|
286
279
|
const decodedData = {
|
287
280
|
idCommitment: memberRegistered.args.idCommitment,
|
288
281
|
membershipRateLimit: memberRegistered.args.membershipRateLimit,
|
289
282
|
index: memberRegistered.args.index
|
290
283
|
};
|
291
|
-
console.log("registerWithIdentity - decodedData:", decodedData);
|
292
|
-
console.log("registerWithIdentity - index:", decodedData.index.toString());
|
293
|
-
console.log("registerWithIdentity - membershipRateLimit:", decodedData.membershipRateLimit.toString());
|
294
284
|
log.info(`Successfully registered membership with index ${decodedData.index} ` +
|
295
285
|
`and rate limit ${decodedData.membershipRateLimit}`);
|
296
|
-
console.log("registerWithIdentity - getting network information");
|
297
286
|
const network = await this.contract.provider.getNetwork();
|
298
|
-
console.log("registerWithIdentity - network:", network);
|
299
|
-
console.log("registerWithIdentity - chainId:", network.chainId);
|
300
287
|
const address = this.contract.address;
|
301
|
-
|
302
|
-
|
303
|
-
console.log("registerWithIdentity - membershipId:", membershipId);
|
304
|
-
const result = {
|
288
|
+
const membershipId = Number(decodedData.index);
|
289
|
+
return {
|
305
290
|
identity,
|
306
291
|
membership: {
|
307
292
|
address,
|
@@ -309,15 +294,34 @@ class RLNContract {
|
|
309
294
|
chainId: network.chainId
|
310
295
|
}
|
311
296
|
};
|
312
|
-
console.log("registerWithIdentity - returning result:", result);
|
313
|
-
return result;
|
314
297
|
}
|
315
298
|
catch (error) {
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
299
|
+
if (error instanceof Error) {
|
300
|
+
const errorMessage = error.message;
|
301
|
+
log.error("registerWithIdentity - error message:", errorMessage);
|
302
|
+
log.error("registerWithIdentity - error stack:", error.stack);
|
303
|
+
// Try to extract more specific error information
|
304
|
+
if (errorMessage.includes("CannotExceedMaxTotalRateLimit")) {
|
305
|
+
throw new Error("Registration failed: Cannot exceed maximum total rate limit");
|
306
|
+
}
|
307
|
+
else if (errorMessage.includes("InvalidIdCommitment")) {
|
308
|
+
throw new Error("Registration failed: Invalid ID commitment");
|
309
|
+
}
|
310
|
+
else if (errorMessage.includes("InvalidMembershipRateLimit")) {
|
311
|
+
throw new Error("Registration failed: Invalid membership rate limit");
|
312
|
+
}
|
313
|
+
else if (errorMessage.includes("execution reverted")) {
|
314
|
+
throw new Error("Contract execution reverted. Check contract requirements.");
|
315
|
+
}
|
316
|
+
else {
|
317
|
+
throw new Error(`Error in registerWithIdentity: ${errorMessage}`);
|
318
|
+
}
|
319
|
+
}
|
320
|
+
else {
|
321
|
+
throw new Error("Unknown error in registerWithIdentity", {
|
322
|
+
cause: error
|
323
|
+
});
|
324
|
+
}
|
321
325
|
}
|
322
326
|
}
|
323
327
|
/**
|
@@ -360,7 +364,7 @@ class RLNContract {
|
|
360
364
|
`Rate limit: ${decodedData.membershipRateLimit}, Erased ${idCommitmentsToErase.length} commitments`);
|
361
365
|
const network = await this.contract.provider.getNetwork();
|
362
366
|
const address = this.contract.address;
|
363
|
-
const membershipId = decodedData.index
|
367
|
+
const membershipId = Number(decodedData.index);
|
364
368
|
return {
|
365
369
|
identity,
|
366
370
|
membership: {
|
@@ -418,22 +422,17 @@ class RLNContract {
|
|
418
422
|
}
|
419
423
|
}
|
420
424
|
async extendMembership(idCommitment) {
|
421
|
-
|
422
|
-
return await tx.wait();
|
425
|
+
return this.contract.extendMemberships([idCommitment]);
|
423
426
|
}
|
424
427
|
async eraseMembership(idCommitment, eraseFromMembershipSet = true) {
|
425
|
-
|
426
|
-
return await tx.wait();
|
428
|
+
return this.contract.eraseMemberships([idCommitment], eraseFromMembershipSet);
|
427
429
|
}
|
428
430
|
async registerMembership(idCommitment, rateLimit = DEFAULT_RATE_LIMIT) {
|
429
431
|
if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
430
432
|
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
|
431
433
|
throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
|
432
434
|
}
|
433
|
-
|
434
|
-
const txn = this.contract.register(idCommitment, rateLimit, []);
|
435
|
-
console.log("txn", txn);
|
436
|
-
return txn;
|
435
|
+
return this.contract.register(idCommitment, rateLimit, []);
|
437
436
|
}
|
438
437
|
async getMemberIndex(idCommitment) {
|
439
438
|
try {
|
@@ -106,7 +106,7 @@ class RLNInstance {
|
|
106
106
|
this.starting = true;
|
107
107
|
try {
|
108
108
|
const { credentials, keystore } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
109
|
-
const { signer, address } = await this.determineStartOptions(options, credentials);
|
109
|
+
const { signer, address, rateLimit } = await this.determineStartOptions(options, credentials);
|
110
110
|
if (keystore) {
|
111
111
|
this.keystore = keystore;
|
112
112
|
}
|
@@ -115,7 +115,7 @@ class RLNInstance {
|
|
115
115
|
this._contract = await RLNContract.init(this, {
|
116
116
|
address: address,
|
117
117
|
signer: signer,
|
118
|
-
rateLimit:
|
118
|
+
rateLimit: rateLimit ?? this.zerokit.getRateLimit
|
119
119
|
});
|
120
120
|
this.started = true;
|
121
121
|
}
|
@@ -166,8 +166,6 @@ class RLNInstance {
|
|
166
166
|
if ("signature" in options) {
|
167
167
|
identity = this.zerokit.generateSeededIdentityCredential(options.signature);
|
168
168
|
}
|
169
|
-
// eslint-disable-next-line no-console
|
170
|
-
console.log("registering membership", identity);
|
171
169
|
if (!identity) {
|
172
170
|
throw Error("Missing signature or identity to register membership.");
|
173
171
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { __exports as random } from '../../../../../../../_virtual/random.js';
|
2
2
|
import '../../../../@noble/hashes/utils.js';
|
3
|
-
import { __exports as utils } from '../../../../../../../_virtual/
|
3
|
+
import { __exports as utils } from '../../../../../../../_virtual/utils.js';
|
4
4
|
|
5
5
|
Object.defineProperty(random, "__esModule", { value: true });
|
6
6
|
random.getRandomBytes = random.getRandomBytesSync = undefined;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { commonjsGlobal } from '../../../../../../../_virtual/_commonjsHelpers.js';
|
2
2
|
import { commonjsRequire } from '../../../../../../../_virtual/_commonjs-dynamic-modules.js';
|
3
|
-
import { __module as utils } from '../../../../../../../_virtual/
|
3
|
+
import { __module as utils } from '../../../../../../../_virtual/utils2.js';
|
4
4
|
import '../../../../@noble/hashes/_assert.js';
|
5
5
|
import '../../../../@noble/hashes/utils.js';
|
6
6
|
import { __exports as _assert } from '../../../../../../../_virtual/_assert.js';
|
7
|
-
import { __exports as utils$1 } from '../../../../../../../_virtual/
|
7
|
+
import { __exports as utils$1 } from '../../../../../../../_virtual/utils.js';
|
8
8
|
|
9
9
|
utils.exports;
|
10
10
|
|
@@ -2,7 +2,7 @@ import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
|
|
2
2
|
import './_assert.js';
|
3
3
|
import './utils.js';
|
4
4
|
import { __exports as _assert } from '../../../../../_virtual/_assert.js';
|
5
|
-
import { __exports as utils } from '../../../../../_virtual/
|
5
|
+
import { __exports as utils } from '../../../../../_virtual/utils.js';
|
6
6
|
|
7
7
|
Object.defineProperty(_sha2, "__esModule", { value: true });
|
8
8
|
_sha2.SHA2 = undefined;
|
@@ -2,7 +2,7 @@ import { __exports as hmac } from '../../../../../_virtual/hmac.js';
|
|
2
2
|
import './_assert.js';
|
3
3
|
import './utils.js';
|
4
4
|
import { __exports as _assert } from '../../../../../_virtual/_assert.js';
|
5
|
-
import { __exports as utils } from '../../../../../_virtual/
|
5
|
+
import { __exports as utils } from '../../../../../_virtual/utils.js';
|
6
6
|
|
7
7
|
(function (exports) {
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
@@ -2,7 +2,7 @@ import { __exports as pbkdf2$1 } from '../../../../../_virtual/pbkdf22.js';
|
|
2
2
|
import './_assert.js';
|
3
3
|
import './hmac.js';
|
4
4
|
import './utils.js';
|
5
|
-
import { __exports as utils } from '../../../../../_virtual/
|
5
|
+
import { __exports as utils } from '../../../../../_virtual/utils.js';
|
6
6
|
import { __exports as _assert } from '../../../../../_virtual/_assert.js';
|
7
7
|
import { __exports as hmac } from '../../../../../_virtual/hmac.js';
|
8
8
|
|
@@ -3,7 +3,7 @@ import './_assert.js';
|
|
3
3
|
import './sha256.js';
|
4
4
|
import './pbkdf2.js';
|
5
5
|
import './utils.js';
|
6
|
-
import { __exports as utils } from '../../../../../_virtual/
|
6
|
+
import { __exports as utils } from '../../../../../_virtual/utils.js';
|
7
7
|
import { __exports as _assert } from '../../../../../_virtual/_assert.js';
|
8
8
|
import { __exports as sha256 } from '../../../../../_virtual/sha2562.js';
|
9
9
|
import { __exports as pbkdf2 } from '../../../../../_virtual/pbkdf22.js';
|
@@ -2,7 +2,7 @@ import { __exports as sha256 } from '../../../../../_virtual/sha2562.js';
|
|
2
2
|
import './_sha2.js';
|
3
3
|
import './utils.js';
|
4
4
|
import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
|
5
|
-
import { __exports as utils } from '../../../../../_virtual/
|
5
|
+
import { __exports as utils } from '../../../../../_virtual/utils.js';
|
6
6
|
|
7
7
|
Object.defineProperty(sha256, "__esModule", { value: true });
|
8
8
|
sha256.sha224 = sha256.sha256 = undefined;
|
@@ -4,7 +4,7 @@ import './_u64.js';
|
|
4
4
|
import './utils.js';
|
5
5
|
import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
|
6
6
|
import { __exports as _u64 } from '../../../../../_virtual/_u64.js';
|
7
|
-
import { __exports as utils } from '../../../../../_virtual/
|
7
|
+
import { __exports as utils } from '../../../../../_virtual/utils.js';
|
8
8
|
|
9
9
|
Object.defineProperty(sha512, "__esModule", { value: true });
|
10
10
|
sha512.sha384 = sha512.sha512_256 = sha512.sha512_224 = sha512.sha512 = sha512.SHA512 = undefined;
|