@waku/rln 0.0.2-3ab8023.0 → 0.0.2-6cb9c9c.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/index.js +2 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +30 -150
- package/bundle/packages/rln/dist/identity_generator.js +75 -0
- package/bundle/packages/rln/dist/rln.js +2 -4
- package/bundle/packages/rln/dist/rln_light.js +223 -0
- 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 -10
- package/dist/contract/rln_contract.js +30 -150
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/identity_generator.d.ts +19 -0
- package/dist/identity_generator.js +72 -0
- package/dist/identity_generator.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/rln.js +2 -4
- package/dist/rln.js.map +1 -1
- package/dist/rln_light.d.ts +95 -0
- package/dist/rln_light.js +206 -0
- package/dist/rln_light.js.map +1 -0
- package/package.json +1 -1
- package/src/contract/rln_contract.ts +36 -218
- package/src/identity_generator.ts +108 -0
- package/src/index.ts +15 -0
- package/src/rln.ts +2 -5
- package/src/rln_light.ts +298 -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 };
|
package/bundle/index.js
CHANGED
@@ -4,9 +4,11 @@ export { RLNContract } from './packages/rln/dist/contract/rln_contract.js';
|
|
4
4
|
export { SEPOLIA_CONTRACT } from './packages/rln/dist/contract/constants.js';
|
5
5
|
export { createRLN } from './packages/rln/dist/create.js';
|
6
6
|
export { IdentityCredential } from './packages/rln/dist/identity.js';
|
7
|
+
export { IdentityGenerator } from './packages/rln/dist/identity_generator.js';
|
7
8
|
export { Keystore } from './packages/rln/dist/keystore/keystore.js';
|
8
9
|
export { Proof } from './packages/rln/dist/proof.js';
|
9
10
|
export { RLNInstance } from './packages/rln/dist/rln.js';
|
11
|
+
export { RLNLight } from './packages/rln/dist/rln_light.js';
|
10
12
|
export { MerkleRootTracker } from './packages/rln/dist/root_tracker.js';
|
11
13
|
export { extractMetaMaskSigner } from './packages/rln/dist/utils/metamask.js';
|
12
14
|
import './packages/rln/dist/utils/epoch.js';
|
@@ -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,69 +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
257
|
// Check if the ID commitment is already registered
|
268
258
|
const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt.toString());
|
269
259
|
if (existingIndex) {
|
270
|
-
console.error(`ID commitment is already registered with index ${existingIndex}`);
|
271
260
|
throw new Error(`ID commitment is already registered with index ${existingIndex}`);
|
272
261
|
}
|
273
262
|
// Check if there's enough remaining rate limit
|
274
263
|
const remainingRateLimit = await this.getRemainingTotalRateLimit();
|
275
264
|
if (remainingRateLimit < this.rateLimit) {
|
276
|
-
console.error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
|
277
265
|
throw new Error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
|
278
266
|
}
|
279
|
-
console.log("registerWithIdentity - calling contract.register");
|
280
|
-
// Estimate gas for the transaction
|
281
267
|
const estimatedGas = await this.contract.estimateGas.register(identity.IDCommitmentBigInt, this.rateLimit, []);
|
282
268
|
const gasLimit = estimatedGas.add(10000);
|
283
269
|
const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], { gasLimit });
|
284
|
-
console.log("registerWithIdentity - txRegisterResponse:", txRegisterResponse);
|
285
|
-
console.log("registerWithIdentity - hash:", txRegisterResponse.hash);
|
286
|
-
console.log("registerWithIdentity - waiting for transaction confirmation...");
|
287
270
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
288
|
-
console.log("registerWithIdentity - txRegisterReceipt:", txRegisterReceipt);
|
289
|
-
console.log("registerWithIdentity - transaction status:", txRegisterReceipt.status);
|
290
|
-
console.log("registerWithIdentity - block number:", txRegisterReceipt.blockNumber);
|
291
|
-
console.log("registerWithIdentity - gas used:", txRegisterReceipt.gasUsed.toString());
|
292
|
-
// Check transaction status
|
293
271
|
if (txRegisterReceipt.status === 0) {
|
294
|
-
console.error("Transaction failed on-chain");
|
295
272
|
throw new Error("Transaction failed on-chain");
|
296
273
|
}
|
297
274
|
const memberRegistered = txRegisterReceipt.events?.find((event) => event.event === "MembershipRegistered");
|
298
|
-
console.log("registerWithIdentity - memberRegistered event:", memberRegistered);
|
299
275
|
if (!memberRegistered || !memberRegistered.args) {
|
300
|
-
|
301
|
-
console.log("registerWithIdentity - all events:", txRegisterReceipt.events);
|
302
|
-
console.error("Failed to register membership: No MembershipRegistered event found");
|
276
|
+
log.error("Failed to register membership: No MembershipRegistered event found");
|
303
277
|
return undefined;
|
304
278
|
}
|
305
|
-
console.log("registerWithIdentity - memberRegistered args:", memberRegistered.args);
|
306
279
|
const decodedData = {
|
307
280
|
idCommitment: memberRegistered.args.idCommitment,
|
308
281
|
membershipRateLimit: memberRegistered.args.membershipRateLimit,
|
309
282
|
index: memberRegistered.args.index
|
310
283
|
};
|
311
|
-
console.log("registerWithIdentity - decodedData:", decodedData);
|
312
|
-
console.log("registerWithIdentity - index:", decodedData.index.toString());
|
313
|
-
console.log("registerWithIdentity - membershipRateLimit:", decodedData.membershipRateLimit.toString());
|
314
284
|
log.info(`Successfully registered membership with index ${decodedData.index} ` +
|
315
285
|
`and rate limit ${decodedData.membershipRateLimit}`);
|
316
|
-
console.log("registerWithIdentity - getting network information");
|
317
286
|
const network = await this.contract.provider.getNetwork();
|
318
|
-
console.log("registerWithIdentity - network:", network);
|
319
|
-
console.log("registerWithIdentity - chainId:", network.chainId);
|
320
287
|
const address = this.contract.address;
|
321
|
-
|
322
|
-
|
323
|
-
console.log("registerWithIdentity - membershipId:", membershipId);
|
324
|
-
const result = {
|
288
|
+
const membershipId = Number(decodedData.index);
|
289
|
+
return {
|
325
290
|
identity,
|
326
291
|
membership: {
|
327
292
|
address,
|
@@ -329,39 +294,34 @@ class RLNContract {
|
|
329
294
|
chainId: network.chainId
|
330
295
|
}
|
331
296
|
};
|
332
|
-
console.log("registerWithIdentity - returning result:", result);
|
333
|
-
return result;
|
334
297
|
}
|
335
298
|
catch (error) {
|
336
|
-
console.log("registerWithIdentity - ERROR:", error);
|
337
|
-
// Improved error handling to decode contract errors
|
338
299
|
if (error instanceof Error) {
|
339
300
|
const errorMessage = error.message;
|
340
|
-
|
341
|
-
|
301
|
+
log.error("registerWithIdentity - error message:", errorMessage);
|
302
|
+
log.error("registerWithIdentity - error stack:", error.stack);
|
342
303
|
// Try to extract more specific error information
|
343
304
|
if (errorMessage.includes("CannotExceedMaxTotalRateLimit")) {
|
344
|
-
|
305
|
+
throw new Error("Registration failed: Cannot exceed maximum total rate limit");
|
345
306
|
}
|
346
307
|
else if (errorMessage.includes("InvalidIdCommitment")) {
|
347
|
-
|
308
|
+
throw new Error("Registration failed: Invalid ID commitment");
|
348
309
|
}
|
349
310
|
else if (errorMessage.includes("InvalidMembershipRateLimit")) {
|
350
|
-
|
311
|
+
throw new Error("Registration failed: Invalid membership rate limit");
|
351
312
|
}
|
352
313
|
else if (errorMessage.includes("execution reverted")) {
|
353
|
-
|
354
|
-
console.error("Contract execution reverted. Check contract requirements.");
|
314
|
+
throw new Error("Contract execution reverted. Check contract requirements.");
|
355
315
|
}
|
356
316
|
else {
|
357
|
-
|
317
|
+
throw new Error(`Error in registerWithIdentity: ${errorMessage}`);
|
358
318
|
}
|
359
319
|
}
|
360
320
|
else {
|
361
|
-
|
321
|
+
throw new Error("Unknown error in registerWithIdentity", {
|
322
|
+
cause: error
|
323
|
+
});
|
362
324
|
}
|
363
|
-
// Re-throw the error to allow callers to handle it
|
364
|
-
throw error;
|
365
325
|
}
|
366
326
|
}
|
367
327
|
/**
|
@@ -404,7 +364,7 @@ class RLNContract {
|
|
404
364
|
`Rate limit: ${decodedData.membershipRateLimit}, Erased ${idCommitmentsToErase.length} commitments`);
|
405
365
|
const network = await this.contract.provider.getNetwork();
|
406
366
|
const address = this.contract.address;
|
407
|
-
const membershipId = decodedData.index
|
367
|
+
const membershipId = Number(decodedData.index);
|
408
368
|
return {
|
409
369
|
identity,
|
410
370
|
membership: {
|
@@ -462,29 +422,17 @@ class RLNContract {
|
|
462
422
|
}
|
463
423
|
}
|
464
424
|
async extendMembership(idCommitment) {
|
465
|
-
|
466
|
-
return await tx.wait();
|
425
|
+
return this.contract.extendMemberships([idCommitment]);
|
467
426
|
}
|
468
427
|
async eraseMembership(idCommitment, eraseFromMembershipSet = true) {
|
469
|
-
|
470
|
-
return await tx.wait();
|
428
|
+
return this.contract.eraseMemberships([idCommitment], eraseFromMembershipSet);
|
471
429
|
}
|
472
430
|
async registerMembership(idCommitment, rateLimit = DEFAULT_RATE_LIMIT) {
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
|
477
|
-
}
|
478
|
-
// Try to register
|
479
|
-
return this.contract.register(idCommitment, rateLimit, []);
|
480
|
-
}
|
481
|
-
catch (error) {
|
482
|
-
console.error("Error in registerMembership:", error);
|
483
|
-
// Run debug to help diagnose the issue
|
484
|
-
await this.debugRegistration(idCommitment, rateLimit);
|
485
|
-
// Re-throw the error
|
486
|
-
throw error;
|
431
|
+
if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
432
|
+
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
|
433
|
+
throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
|
487
434
|
}
|
435
|
+
return this.contract.register(idCommitment, rateLimit, []);
|
488
436
|
}
|
489
437
|
async getMemberIndex(idCommitment) {
|
490
438
|
try {
|
@@ -499,74 +447,6 @@ class RLNContract {
|
|
499
447
|
return undefined;
|
500
448
|
}
|
501
449
|
}
|
502
|
-
/**
|
503
|
-
* Debug function to check why a registration might fail
|
504
|
-
* @param idCommitment The ID commitment to check
|
505
|
-
* @param rateLimit The rate limit to check
|
506
|
-
*/
|
507
|
-
async debugRegistration(idCommitment, rateLimit) {
|
508
|
-
console.log("=== DEBUG REGISTRATION ===");
|
509
|
-
console.log(`ID Commitment: ${idCommitment}`);
|
510
|
-
console.log(`Rate Limit: ${rateLimit}`);
|
511
|
-
// Check if ID commitment is already registered
|
512
|
-
try {
|
513
|
-
const existingIndex = await this.getMemberIndex(idCommitment);
|
514
|
-
if (existingIndex) {
|
515
|
-
console.error(`ERROR: ID commitment is already registered with index ${existingIndex}`);
|
516
|
-
}
|
517
|
-
else {
|
518
|
-
console.log("ID commitment is not yet registered ✓");
|
519
|
-
}
|
520
|
-
}
|
521
|
-
catch (error) {
|
522
|
-
console.error("Error checking if ID commitment is registered:", error);
|
523
|
-
}
|
524
|
-
// Check rate limit constraints
|
525
|
-
try {
|
526
|
-
const minRateLimit = await this.getMinRateLimit();
|
527
|
-
const maxRateLimit = await this.getMaxRateLimit();
|
528
|
-
const maxTotalRateLimit = await this.getMaxTotalRateLimit();
|
529
|
-
const currentTotalRateLimit = await this.getCurrentTotalRateLimit();
|
530
|
-
const remainingRateLimit = await this.getRemainingTotalRateLimit();
|
531
|
-
console.log(`Min Rate Limit: ${minRateLimit}`);
|
532
|
-
console.log(`Max Rate Limit: ${maxRateLimit}`);
|
533
|
-
console.log(`Max Total Rate Limit: ${maxTotalRateLimit}`);
|
534
|
-
console.log(`Current Total Rate Limit: ${currentTotalRateLimit}`);
|
535
|
-
console.log(`Remaining Rate Limit: ${remainingRateLimit}`);
|
536
|
-
if (rateLimit < minRateLimit) {
|
537
|
-
console.error(`ERROR: Rate limit ${rateLimit} is below minimum ${minRateLimit}`);
|
538
|
-
}
|
539
|
-
if (rateLimit > maxRateLimit) {
|
540
|
-
console.error(`ERROR: Rate limit ${rateLimit} exceeds maximum ${maxRateLimit}`);
|
541
|
-
}
|
542
|
-
if (rateLimit > remainingRateLimit) {
|
543
|
-
console.error(`ERROR: Rate limit ${rateLimit} exceeds remaining capacity ${remainingRateLimit}`);
|
544
|
-
}
|
545
|
-
}
|
546
|
-
catch (error) {
|
547
|
-
console.error("Error checking rate limit constraints:", error);
|
548
|
-
}
|
549
|
-
// Try to estimate gas for the transaction to see if it would revert
|
550
|
-
try {
|
551
|
-
await this.contract.estimateGas.register(idCommitment, rateLimit, []);
|
552
|
-
console.log("Transaction gas estimation succeeded ✓");
|
553
|
-
}
|
554
|
-
catch (error) {
|
555
|
-
console.error("Transaction would revert with error:", error);
|
556
|
-
// Try to extract more specific error information
|
557
|
-
const errorMessage = error.message;
|
558
|
-
if (errorMessage.includes("CannotExceedMaxTotalRateLimit")) {
|
559
|
-
console.error("Cannot exceed maximum total rate limit");
|
560
|
-
}
|
561
|
-
else if (errorMessage.includes("InvalidIdCommitment")) {
|
562
|
-
console.error("Invalid ID commitment format");
|
563
|
-
}
|
564
|
-
else if (errorMessage.includes("InvalidMembershipRateLimit")) {
|
565
|
-
console.error("Invalid membership rate limit");
|
566
|
-
}
|
567
|
-
}
|
568
|
-
console.log("=== END DEBUG ===");
|
569
|
-
}
|
570
450
|
}
|
571
451
|
// These values should be tested on other networks
|
572
452
|
const FETCH_CHUNK = 5;
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { keccak256 } from '../../../node_modules/@ethersproject/keccak256/lib.esm/index.js';
|
2
|
+
import { toUtf8Bytes } from '../../../node_modules/@ethersproject/strings/lib.esm/utf8.js';
|
3
|
+
import { IdentityCredential } from './identity.js';
|
4
|
+
import { buildBigIntFromUint8Array } from './utils/bytes.js';
|
5
|
+
import './utils/epoch.js';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* A standalone implementation of identity generation for RLN memberships
|
9
|
+
* without Zerokit dependency. Only supports identity creation and membership
|
10
|
+
* registration.
|
11
|
+
*/
|
12
|
+
class IdentityGenerator {
|
13
|
+
/**
|
14
|
+
* Generate a new random identity credential
|
15
|
+
* @returns An IdentityCredential object
|
16
|
+
*/
|
17
|
+
generateIdentityCredentials() {
|
18
|
+
// Generate random values for IDTrapdoor and IDNullifier
|
19
|
+
const idTrapdoor = crypto.getRandomValues(new Uint8Array(32));
|
20
|
+
const idNullifier = crypto.getRandomValues(new Uint8Array(32));
|
21
|
+
// Generate IDSecretHash by concatenating and hashing
|
22
|
+
const combined = new Uint8Array(64);
|
23
|
+
combined.set(idTrapdoor, 0);
|
24
|
+
combined.set(idNullifier, 32);
|
25
|
+
const idSecretHash = new Uint8Array(keccak256(combined)
|
26
|
+
.substring(2)
|
27
|
+
.match(/.{1,2}/g)
|
28
|
+
.map((byte) => parseInt(byte, 16)));
|
29
|
+
// Generate IDCommitment by hashing IDSecretHash
|
30
|
+
const idCommitment = new Uint8Array(keccak256(idSecretHash)
|
31
|
+
.substring(2)
|
32
|
+
.match(/.{1,2}/g)
|
33
|
+
.map((byte) => parseInt(byte, 16)));
|
34
|
+
// Generate BigInt from IDCommitment
|
35
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
|
36
|
+
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
37
|
+
}
|
38
|
+
/**
|
39
|
+
* Generate an identity credential from a seed
|
40
|
+
* @param seed A string seed to generate a deterministic identity
|
41
|
+
* @returns An IdentityCredential object
|
42
|
+
*/
|
43
|
+
generateSeededIdentityCredential(seed) {
|
44
|
+
// Convert seed to bytes
|
45
|
+
const seedBytes = toUtf8Bytes(seed);
|
46
|
+
// Use the seed to derive IDTrapdoor and IDNullifier deterministically
|
47
|
+
const seedHash = keccak256(seedBytes);
|
48
|
+
const seedHashBytes = new Uint8Array(seedHash
|
49
|
+
.substring(2)
|
50
|
+
.match(/.{1,2}/g)
|
51
|
+
.map((byte) => parseInt(byte, 16)));
|
52
|
+
// Use first half for IDTrapdoor, second half for IDNullifier
|
53
|
+
const idTrapdoor = seedHashBytes.slice(0, 32);
|
54
|
+
const idNullifier = keccak256(seedHashBytes).substring(2);
|
55
|
+
const idNullifierBytes = new Uint8Array(idNullifier.match(/.{1,2}/g).map((byte) => parseInt(byte, 16))).slice(0, 32);
|
56
|
+
// Generate IDSecretHash by concatenating and hashing
|
57
|
+
const combined = new Uint8Array(64);
|
58
|
+
combined.set(idTrapdoor, 0);
|
59
|
+
combined.set(idNullifierBytes, 32);
|
60
|
+
const idSecretHash = new Uint8Array(keccak256(combined)
|
61
|
+
.substring(2)
|
62
|
+
.match(/.{1,2}/g)
|
63
|
+
.map((byte) => parseInt(byte, 16)));
|
64
|
+
// Generate IDCommitment by hashing IDSecretHash
|
65
|
+
const idCommitment = new Uint8Array(keccak256(idSecretHash)
|
66
|
+
.substring(2)
|
67
|
+
.match(/.{1,2}/g)
|
68
|
+
.map((byte) => parseInt(byte, 16)));
|
69
|
+
// Generate BigInt from IDCommitment
|
70
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
|
71
|
+
return new IdentityCredential(idTrapdoor, idNullifierBytes, idSecretHash, idCommitment, idCommitmentBigInt);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
export { IdentityGenerator };
|
@@ -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
|
}
|