@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
|
-
const
|
4
|
-
chainId:
|
5
|
-
address: "
|
3
|
+
const SEPOLIA_CONTRACT = {
|
4
|
+
chainId: 11155111,
|
5
|
+
address: "0xCB33Aa5B38d79E3D9Fa8B10afF38AA201399a7e3",
|
6
6
|
abi: RLN_ABI
|
7
7
|
};
|
8
8
|
/**
|
@@ -23,4 +23,4 @@ const RATE_LIMIT_PARAMS = {
|
|
23
23
|
};
|
24
24
|
const DEFAULT_RATE_LIMIT = RATE_LIMIT_PARAMS.MAX_RATE;
|
25
25
|
|
26
|
-
export { DEFAULT_RATE_LIMIT,
|
26
|
+
export { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS, SEPOLIA_CONTRACT };
|
@@ -25,8 +25,7 @@ class RLNContract {
|
|
25
25
|
rateLimit;
|
26
26
|
_members = new Map();
|
27
27
|
_membersFilter;
|
28
|
-
|
29
|
-
_membersExpiredFilter;
|
28
|
+
_membersRemovedFilter;
|
30
29
|
/**
|
31
30
|
* Asynchronous initializer for RLNContract.
|
32
31
|
* Allows injecting a mocked contract for testing purposes.
|
@@ -39,26 +38,18 @@ class RLNContract {
|
|
39
38
|
}
|
40
39
|
constructor(rlnInstance, options) {
|
41
40
|
const { address, signer, rateLimit = DEFAULT_RATE_LIMIT, contract } = options;
|
42
|
-
|
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
|
+
}
|
43
45
|
this.rateLimit = rateLimit;
|
44
46
|
const initialRoot = rlnInstance.zerokit.getMerkleRoot();
|
45
47
|
// Use the injected contract if provided; otherwise, instantiate a new one.
|
46
48
|
this.contract = contract || new Contract(address, RLN_ABI, signer);
|
47
49
|
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
48
|
-
// Initialize event filters
|
50
|
+
// Initialize event filters for MembershipRegistered and MembershipRemoved
|
49
51
|
this._membersFilter = this.contract.filters.MembershipRegistered();
|
50
|
-
this.
|
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
|
-
}
|
52
|
+
this._membersRemovedFilter = this.contract.filters.MembershipRemoved();
|
62
53
|
}
|
63
54
|
/**
|
64
55
|
* Gets the current rate limit for this contract instance
|
@@ -119,14 +110,13 @@ class RLNContract {
|
|
119
110
|
this.contract.maxTotalRateLimit(),
|
120
111
|
this.contract.currentTotalRateLimit()
|
121
112
|
]);
|
122
|
-
return
|
113
|
+
return maxTotal.sub(currentTotal).toNumber();
|
123
114
|
}
|
124
115
|
/**
|
125
116
|
* Updates the rate limit for future registrations
|
126
117
|
* @param newRateLimit The new rate limit to use
|
127
118
|
*/
|
128
119
|
async setRateLimit(newRateLimit) {
|
129
|
-
this.validateRateLimit(newRateLimit);
|
130
120
|
this.rateLimit = newRateLimit;
|
131
121
|
}
|
132
122
|
get members() {
|
@@ -139,17 +129,11 @@ class RLNContract {
|
|
139
129
|
}
|
140
130
|
return this._membersFilter;
|
141
131
|
}
|
142
|
-
get
|
143
|
-
if (!this.
|
144
|
-
throw Error("
|
132
|
+
get membersRemovedFilter() {
|
133
|
+
if (!this._membersRemovedFilter) {
|
134
|
+
throw Error("MembersRemoved filter was not initialized.");
|
145
135
|
}
|
146
|
-
return this.
|
147
|
-
}
|
148
|
-
get membersExpiredFilter() {
|
149
|
-
if (!this._membersExpiredFilter) {
|
150
|
-
throw Error("MembersExpired filter was not initialized.");
|
151
|
-
}
|
152
|
-
return this._membersExpiredFilter;
|
136
|
+
return this._membersRemovedFilter;
|
153
137
|
}
|
154
138
|
async fetchMembers(rlnInstance, options = {}) {
|
155
139
|
const registeredMemberEvents = await queryFilter(this.contract, {
|
@@ -160,18 +144,9 @@ class RLNContract {
|
|
160
144
|
const removedMemberEvents = await queryFilter(this.contract, {
|
161
145
|
fromBlock: this.deployBlock,
|
162
146
|
...options,
|
163
|
-
membersFilter: this.
|
164
|
-
});
|
165
|
-
const expiredMemberEvents = await queryFilter(this.contract, {
|
166
|
-
fromBlock: this.deployBlock,
|
167
|
-
...options,
|
168
|
-
membersFilter: this.membersExpiredFilter
|
147
|
+
membersFilter: this.membersRemovedFilter
|
169
148
|
});
|
170
|
-
const events = [
|
171
|
-
...registeredMemberEvents,
|
172
|
-
...removedMemberEvents,
|
173
|
-
...expiredMemberEvents
|
174
|
-
];
|
149
|
+
const events = [...registeredMemberEvents, ...removedMemberEvents];
|
175
150
|
this.processEvents(rlnInstance, events);
|
176
151
|
}
|
177
152
|
processEvents(rlnInstance, events) {
|
@@ -181,22 +156,8 @@ class RLNContract {
|
|
181
156
|
if (!evt.args) {
|
182
157
|
return;
|
183
158
|
}
|
184
|
-
if (evt.event === "
|
185
|
-
|
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
|
-
}
|
159
|
+
if (evt.event === "MembershipRemoved") {
|
160
|
+
const index = evt.args.index;
|
200
161
|
const toRemoveVal = toRemoveTable.get(evt.blockNumber);
|
201
162
|
if (toRemoveVal != undefined) {
|
202
163
|
toRemoveVal.push(index.toNumber());
|
@@ -224,17 +185,13 @@ class RLNContract {
|
|
224
185
|
if (!evt.args)
|
225
186
|
return;
|
226
187
|
const _idCommitment = evt.args.idCommitment;
|
227
|
-
|
188
|
+
const index = evt.args.index;
|
228
189
|
if (!_idCommitment || !index) {
|
229
190
|
return;
|
230
191
|
}
|
231
|
-
if (typeof index === "number" || typeof index === "string") {
|
232
|
-
index = BigNumber.from(index);
|
233
|
-
}
|
234
192
|
const idCommitment = zeroPadLE(hexToBytes(_idCommitment), 32);
|
235
193
|
rlnInstance.zerokit.insertMember(idCommitment);
|
236
|
-
|
237
|
-
this._members.set(numericIndex, {
|
194
|
+
this._members.set(index.toNumber(), {
|
238
195
|
index,
|
239
196
|
idCommitment: _idCommitment
|
240
197
|
});
|
@@ -256,36 +213,18 @@ class RLNContract {
|
|
256
213
|
});
|
257
214
|
}
|
258
215
|
subscribeToMembers(rlnInstance) {
|
259
|
-
this.contract.on(this.membersFilter, (_idCommitment,
|
260
|
-
this.processEvents(rlnInstance, [event]);
|
261
|
-
});
|
262
|
-
this.contract.on(this.membershipErasedFilter, (_idCommitment, _membershipRateLimit, _index, event) => {
|
216
|
+
this.contract.on(this.membersFilter, (_idCommitment, _rateLimit, _index, event) => {
|
263
217
|
this.processEvents(rlnInstance, [event]);
|
264
218
|
});
|
265
|
-
this.contract.on(this.
|
219
|
+
this.contract.on(this.membersRemovedFilter, (_idCommitment, _index, event) => {
|
266
220
|
this.processEvents(rlnInstance, [event]);
|
267
221
|
});
|
268
222
|
}
|
269
223
|
async registerWithIdentity(identity) {
|
270
224
|
try {
|
271
225
|
log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
|
272
|
-
|
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 });
|
226
|
+
const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], { gasLimit: 300000 });
|
285
227
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
286
|
-
if (txRegisterReceipt.status === 0) {
|
287
|
-
throw new Error("Transaction failed on-chain");
|
288
|
-
}
|
289
228
|
const memberRegistered = txRegisterReceipt.events?.find((event) => event.event === "MembershipRegistered");
|
290
229
|
if (!memberRegistered || !memberRegistered.args) {
|
291
230
|
log.error("Failed to register membership: No MembershipRegistered event found");
|
@@ -293,51 +232,26 @@ class RLNContract {
|
|
293
232
|
}
|
294
233
|
const decodedData = {
|
295
234
|
idCommitment: memberRegistered.args.idCommitment,
|
296
|
-
|
235
|
+
rateLimit: memberRegistered.args.rateLimit,
|
297
236
|
index: memberRegistered.args.index
|
298
237
|
};
|
299
238
|
log.info(`Successfully registered membership with index ${decodedData.index} ` +
|
300
|
-
`and rate limit ${decodedData.
|
239
|
+
`and rate limit ${decodedData.rateLimit}`);
|
301
240
|
const network = await this.contract.provider.getNetwork();
|
302
241
|
const address = this.contract.address;
|
303
|
-
const membershipId =
|
242
|
+
const membershipId = decodedData.index.toNumber();
|
304
243
|
return {
|
305
244
|
identity,
|
306
245
|
membership: {
|
307
246
|
address,
|
308
247
|
treeIndex: membershipId,
|
309
|
-
chainId: network.chainId
|
310
|
-
rateLimit: decodedData.membershipRateLimit.toNumber()
|
248
|
+
chainId: network.chainId
|
311
249
|
}
|
312
250
|
};
|
313
251
|
}
|
314
252
|
catch (error) {
|
315
|
-
|
316
|
-
|
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
|
-
}
|
253
|
+
log.error(`Error in registerWithIdentity: ${error.message}`);
|
254
|
+
return undefined;
|
341
255
|
}
|
342
256
|
}
|
343
257
|
/**
|
@@ -373,21 +287,20 @@ class RLNContract {
|
|
373
287
|
}
|
374
288
|
const decodedData = {
|
375
289
|
idCommitment: memberRegistered.args.idCommitment,
|
376
|
-
|
290
|
+
rateLimit: memberRegistered.args.rateLimit,
|
377
291
|
index: memberRegistered.args.index
|
378
292
|
};
|
379
293
|
log.info(`Successfully registered membership with permit. Index: ${decodedData.index}, ` +
|
380
|
-
`Rate limit: ${decodedData.
|
294
|
+
`Rate limit: ${decodedData.rateLimit}, Erased ${idCommitmentsToErase.length} commitments`);
|
381
295
|
const network = await this.contract.provider.getNetwork();
|
382
296
|
const address = this.contract.address;
|
383
|
-
const membershipId =
|
297
|
+
const membershipId = decodedData.index.toNumber();
|
384
298
|
return {
|
385
299
|
identity,
|
386
300
|
membership: {
|
387
301
|
address,
|
388
302
|
treeIndex: membershipId,
|
389
|
-
chainId: network.chainId
|
390
|
-
rateLimit: decodedData.membershipRateLimit.toNumber()
|
303
|
+
chainId: network.chainId
|
391
304
|
}
|
392
305
|
};
|
393
306
|
}
|
@@ -444,8 +357,11 @@ class RLNContract {
|
|
444
357
|
async eraseMembership(idCommitment, eraseFromMembershipSet = true) {
|
445
358
|
return this.contract.eraseMemberships([idCommitment], eraseFromMembershipSet);
|
446
359
|
}
|
447
|
-
async registerMembership(idCommitment, rateLimit =
|
448
|
-
|
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
|
+
}
|
449
365
|
return this.contract.register(idCommitment, rateLimit, []);
|
450
366
|
}
|
451
367
|
async getMemberIndex(idCommitment) {
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { cipherDecrypt as cipherDecrypt_1 } from '
|
2
|
-
import { kdf as kdf_2 } from '
|
3
|
-
import { normalizePassword as normalizePassword_1 } from '
|
1
|
+
import { cipherDecrypt as cipherDecrypt_1 } from '../../../../node_modules/@chainsafe/bls-keystore/lib/cipher.js';
|
2
|
+
import { kdf as kdf_2 } from '../../../../node_modules/@chainsafe/bls-keystore/lib/kdf.js';
|
3
|
+
import { normalizePassword as normalizePassword_1 } from '../../../../node_modules/@chainsafe/bls-keystore/lib/password.js';
|
4
4
|
import { keccak256 } from '../../../../node_modules/ethereum-cryptography/esm/keccak.js';
|
5
5
|
import { hexToBytes } from '../../../../node_modules/ethereum-cryptography/esm/utils.js';
|
6
6
|
import { concatBytes, bytesToHex } from '../../../../node_modules/@noble/hashes/esm/utils.js';
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import '
|
1
|
+
import '../../../../node_modules/@chainsafe/bls-keystore/lib/index.js';
|
2
2
|
import '../../../interfaces/dist/protocols.js';
|
3
3
|
import '../../../interfaces/dist/connection_manager.js';
|
4
4
|
import '../../../interfaces/dist/health_indicator.js';
|
@@ -176,8 +176,7 @@ class Keystore {
|
|
176
176
|
membership: {
|
177
177
|
treeIndex: _.get(obj, "treeIndex"),
|
178
178
|
chainId: _.get(obj, "membershipContract.chainId"),
|
179
|
-
address: _.get(obj, "membershipContract.address")
|
180
|
-
rateLimit: _.get(obj, "membershipContract.rateLimit")
|
179
|
+
address: _.get(obj, "membershipContract.address")
|
181
180
|
}
|
182
181
|
};
|
183
182
|
}
|
@@ -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 {
|
24
|
+
import { SEPOLIA_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';
|
@@ -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
|
109
|
+
const { signer, address } = 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: rateLimit ?? this.zerokit.getRateLimit
|
118
|
+
rateLimit: options.rateLimit ?? this.zerokit.getRateLimit
|
119
119
|
});
|
120
120
|
this.started = true;
|
121
121
|
}
|
@@ -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
|
-
|
131
|
-
if (address ===
|
132
|
-
chainId =
|
130
|
+
SEPOLIA_CONTRACT.address;
|
131
|
+
if (address === SEPOLIA_CONTRACT.address) {
|
132
|
+
chainId = SEPOLIA_CONTRACT.chainId;
|
133
133
|
}
|
134
134
|
const signer = options.signer || (await extractMetaMaskSigner());
|
135
135
|
const currentChainId = await signer.getChainId();
|