@waku/rln 0.1.5 → 0.1.6-a7f52e4.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/index2.js +1 -1
- package/bundle/_virtual/utils.js +2 -2
- package/bundle/_virtual/utils2.js +2 -2
- package/bundle/index.js +2 -1
- 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/keccak256/lib.esm/index.js +1 -1
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +6 -32
- package/bundle/node_modules/@noble/hashes/esm/_md.js +22 -11
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +4 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@noble/hashes/esm/hmac.js +19 -10
- package/bundle/{packages/rln/node_modules/@noble/hashes/esm/sha256.js → node_modules/@noble/hashes/esm/sha2.js} +36 -50
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +5 -102
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +30 -24
- package/bundle/node_modules/@noble/hashes/esm/utils.js +69 -18
- package/bundle/node_modules/bn.js/lib/bn.js +1 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.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/constants.js +1 -0
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +127 -71
- package/bundle/packages/rln/dist/credentials_manager.js +3 -3
- package/bundle/packages/rln/dist/identity.js +1 -1
- package/bundle/packages/rln/dist/keystore/cipher.js +3 -3
- package/bundle/packages/rln/dist/keystore/keystore.js +1 -1
- package/bundle/packages/rln/dist/utils/bytes.js +6 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/index.d.ts +1 -0
- package/dist/contract/index.js +1 -0
- package/dist/contract/index.js.map +1 -1
- package/dist/contract/rln_base_contract.d.ts +32 -22
- package/dist/contract/rln_base_contract.js +127 -71
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/contract/types.d.ts +5 -0
- package/dist/contract/types.js.map +1 -1
- package/dist/credentials_manager.js +1 -1
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +2 -2
- package/dist/utils/bytes.d.ts +1 -1
- package/dist/utils/bytes.js +6 -3
- package/dist/utils/bytes.js.map +1 -1
- package/package.json +1 -92
- package/src/contract/index.ts +1 -0
- package/src/contract/rln_base_contract.ts +166 -102
- package/src/contract/types.ts +5 -0
- package/src/credentials_manager.ts +1 -1
- package/src/identity.ts +2 -1
- package/src/index.ts +3 -1
- package/src/keystore/keystore.ts +4 -2
- package/src/keystore/types.ts +2 -2
- package/src/utils/bytes.ts +6 -6
- 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/utils.js +0 -43
- /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
@@ -24,15 +24,32 @@ class RLNBaseContract {
|
|
24
24
|
contract;
|
25
25
|
deployBlock;
|
26
26
|
rateLimit;
|
27
|
+
minRateLimit;
|
28
|
+
maxRateLimit;
|
27
29
|
_members = new Map();
|
28
30
|
_membersFilter;
|
29
31
|
_membershipErasedFilter;
|
30
32
|
_membersExpiredFilter;
|
31
33
|
/**
|
32
|
-
*
|
33
|
-
* Allows injecting a mocked contract for testing purposes.
|
34
|
+
* Private constructor for RLNBaseContract. Use static create() instead.
|
34
35
|
*/
|
35
36
|
constructor(options) {
|
37
|
+
const { address, signer, rateLimit = DEFAULT_RATE_LIMIT, contract } = options;
|
38
|
+
log.info("Initializing RLNBaseContract", { address, rateLimit });
|
39
|
+
this.contract = contract || new Contract(address, RLN_ABI, signer);
|
40
|
+
this.rateLimit = rateLimit;
|
41
|
+
try {
|
42
|
+
log.info("Setting up event filters");
|
43
|
+
// Initialize event filters
|
44
|
+
this._membersFilter = this.contract.filters.MembershipRegistered();
|
45
|
+
this._membershipErasedFilter = this.contract.filters.MembershipErased();
|
46
|
+
this._membersExpiredFilter = this.contract.filters.MembershipExpired();
|
47
|
+
log.info("Event filters initialized successfully");
|
48
|
+
}
|
49
|
+
catch (error) {
|
50
|
+
log.error("Failed to initialize event filters", { error });
|
51
|
+
throw new Error("Failed to initialize event filters: " + error.message);
|
52
|
+
}
|
36
53
|
// Initialize members and subscriptions
|
37
54
|
this.fetchMembers()
|
38
55
|
.then(() => {
|
@@ -41,14 +58,20 @@ class RLNBaseContract {
|
|
41
58
|
.catch((error) => {
|
42
59
|
log.error("Failed to initialize members", { error });
|
43
60
|
});
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
61
|
+
}
|
62
|
+
/**
|
63
|
+
* Static async factory to create and initialize RLNBaseContract
|
64
|
+
*/
|
65
|
+
static async create(options) {
|
66
|
+
const instance = new RLNBaseContract(options);
|
67
|
+
const [min, max] = await Promise.all([
|
68
|
+
instance.contract.minMembershipRateLimit(),
|
69
|
+
instance.contract.maxMembershipRateLimit()
|
70
|
+
]);
|
71
|
+
instance.minRateLimit = BigNumber.from(min).toNumber();
|
72
|
+
instance.maxRateLimit = BigNumber.from(max).toNumber();
|
73
|
+
instance.validateRateLimit(instance.rateLimit);
|
74
|
+
return instance;
|
52
75
|
}
|
53
76
|
/**
|
54
77
|
* Gets the current rate limit for this contract instance
|
@@ -69,20 +92,20 @@ class RLNBaseContract {
|
|
69
92
|
return this.contract.provider;
|
70
93
|
}
|
71
94
|
/**
|
72
|
-
* Gets the minimum allowed rate limit
|
73
|
-
* @returns Promise<number> The minimum rate limit in messages per epoch
|
95
|
+
* Gets the minimum allowed rate limit (cached)
|
74
96
|
*/
|
75
|
-
|
76
|
-
|
77
|
-
|
97
|
+
getMinRateLimit() {
|
98
|
+
if (this.minRateLimit === undefined)
|
99
|
+
throw new Error("minRateLimit not initialized");
|
100
|
+
return this.minRateLimit;
|
78
101
|
}
|
79
102
|
/**
|
80
|
-
* Gets the maximum allowed rate limit
|
81
|
-
* @returns Promise<number> The maximum rate limit in messages per epoch
|
103
|
+
* Gets the maximum allowed rate limit (cached)
|
82
104
|
*/
|
83
|
-
|
84
|
-
|
85
|
-
|
105
|
+
getMaxRateLimit() {
|
106
|
+
if (this.maxRateLimit === undefined)
|
107
|
+
throw new Error("maxRateLimit not initialized");
|
108
|
+
return this.maxRateLimit;
|
86
109
|
}
|
87
110
|
/**
|
88
111
|
* Gets the maximum total rate limit across all memberships
|
@@ -115,7 +138,7 @@ class RLNBaseContract {
|
|
115
138
|
* Updates the rate limit for future registrations
|
116
139
|
* @param newRateLimit The new rate limit to use
|
117
140
|
*/
|
118
|
-
|
141
|
+
setRateLimit(newRateLimit) {
|
119
142
|
this.validateRateLimit(newRateLimit);
|
120
143
|
this.rateLimit = newRateLimit;
|
121
144
|
}
|
@@ -247,75 +270,67 @@ class RLNBaseContract {
|
|
247
270
|
this.processEvents([event]);
|
248
271
|
});
|
249
272
|
}
|
250
|
-
|
251
|
-
* Helper method to get remaining messages in current epoch
|
252
|
-
* @param membershipId The ID of the membership to check
|
253
|
-
* @returns number of remaining messages allowed in current epoch
|
254
|
-
*/
|
255
|
-
async getRemainingMessages(membershipId) {
|
256
|
-
try {
|
257
|
-
const [startTime, , rateLimit] = await this.contract.getMembershipInfo(membershipId);
|
258
|
-
// Calculate current epoch
|
259
|
-
const currentTime = Math.floor(Date.now() / 1000);
|
260
|
-
const epochsPassed = Math.floor((currentTime - startTime) / RATE_LIMIT_PARAMS.EPOCH_LENGTH);
|
261
|
-
const currentEpochStart = startTime + epochsPassed * RATE_LIMIT_PARAMS.EPOCH_LENGTH;
|
262
|
-
// Get message count in current epoch using contract's function
|
263
|
-
const messageCount = await this.contract.getMessageCount(membershipId, currentEpochStart);
|
264
|
-
return Math.max(0, BigNumber.from(rateLimit)
|
265
|
-
.sub(BigNumber.from(messageCount))
|
266
|
-
.toNumber());
|
267
|
-
}
|
268
|
-
catch (error) {
|
269
|
-
log.error(`Error getting remaining messages: ${error.message}`);
|
270
|
-
return 0; // Fail safe: assume no messages remaining on error
|
271
|
-
}
|
272
|
-
}
|
273
|
-
async getMembershipInfo(idCommitment) {
|
273
|
+
async getMembershipInfo(idCommitmentBigInt) {
|
274
274
|
try {
|
275
|
-
const
|
275
|
+
const membershipData = await this.contract.memberships(idCommitmentBigInt);
|
276
276
|
const currentBlock = await this.contract.provider.getBlockNumber();
|
277
|
+
const [depositAmount, activeDuration, gracePeriodStartTimestamp, gracePeriodDuration, rateLimit, index, holder, token] = membershipData;
|
278
|
+
const gracePeriodEnd = gracePeriodStartTimestamp.add(gracePeriodDuration);
|
277
279
|
let state;
|
278
|
-
if (currentBlock <
|
280
|
+
if (currentBlock < gracePeriodStartTimestamp.toNumber()) {
|
279
281
|
state = MembershipState.Active;
|
280
282
|
}
|
281
|
-
else if (currentBlock <
|
283
|
+
else if (currentBlock < gracePeriodEnd.toNumber()) {
|
282
284
|
state = MembershipState.GracePeriod;
|
283
285
|
}
|
284
286
|
else {
|
285
287
|
state = MembershipState.Expired;
|
286
288
|
}
|
287
|
-
const index = await this.getMemberIndex(idCommitment);
|
288
|
-
if (!index)
|
289
|
-
return undefined;
|
290
289
|
return {
|
291
290
|
index,
|
292
|
-
idCommitment,
|
293
|
-
rateLimit: rateLimit
|
294
|
-
startBlock:
|
295
|
-
endBlock:
|
296
|
-
state
|
291
|
+
idCommitment: idCommitmentBigInt.toString(),
|
292
|
+
rateLimit: Number(rateLimit),
|
293
|
+
startBlock: gracePeriodStartTimestamp.toNumber(),
|
294
|
+
endBlock: gracePeriodEnd.toNumber(),
|
295
|
+
state,
|
296
|
+
depositAmount,
|
297
|
+
activeDuration,
|
298
|
+
gracePeriodDuration,
|
299
|
+
holder,
|
300
|
+
token
|
297
301
|
};
|
298
302
|
}
|
299
303
|
catch (error) {
|
304
|
+
log.error("Error in getMembershipInfo:", error);
|
300
305
|
return undefined;
|
301
306
|
}
|
302
307
|
}
|
303
|
-
async extendMembership(
|
304
|
-
|
308
|
+
async extendMembership(idCommitmentBigInt) {
|
309
|
+
const tx = await this.contract.extendMemberships([idCommitmentBigInt]);
|
310
|
+
await tx.wait();
|
311
|
+
return tx;
|
305
312
|
}
|
306
|
-
async eraseMembership(
|
307
|
-
|
313
|
+
async eraseMembership(idCommitmentBigInt, eraseFromMembershipSet = true) {
|
314
|
+
if (!(await this.isExpired(idCommitmentBigInt)) ||
|
315
|
+
!(await this.isInGracePeriod(idCommitmentBigInt))) {
|
316
|
+
throw new Error("Membership is not expired or in grace period");
|
317
|
+
}
|
318
|
+
const estimatedGas = await this.contract.estimateGas["eraseMemberships(uint256[],bool)"]([idCommitmentBigInt], eraseFromMembershipSet);
|
319
|
+
const gasLimit = estimatedGas.add(10000);
|
320
|
+
const tx = await this.contract["eraseMemberships(uint256[],bool)"]([idCommitmentBigInt], eraseFromMembershipSet, { gasLimit });
|
321
|
+
await tx.wait();
|
322
|
+
return tx;
|
308
323
|
}
|
309
|
-
async registerMembership(
|
324
|
+
async registerMembership(idCommitmentBigInt, rateLimit = DEFAULT_RATE_LIMIT) {
|
310
325
|
if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
311
326
|
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
|
312
327
|
throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
|
313
328
|
}
|
314
|
-
return this.contract.register(
|
329
|
+
return this.contract.register(idCommitmentBigInt, rateLimit, []);
|
315
330
|
}
|
316
|
-
async withdraw(token,
|
331
|
+
async withdraw(token, from) {
|
317
332
|
try {
|
318
|
-
const tx = await this.contract.withdraw(token,
|
333
|
+
const tx = await this.contract.withdraw(token, from);
|
319
334
|
await tx.wait();
|
320
335
|
}
|
321
336
|
catch (error) {
|
@@ -326,7 +341,7 @@ class RLNBaseContract {
|
|
326
341
|
try {
|
327
342
|
log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
|
328
343
|
// Check if the ID commitment is already registered
|
329
|
-
const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt
|
344
|
+
const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt);
|
330
345
|
if (existingIndex) {
|
331
346
|
throw new Error(`ID commitment is already registered with index ${existingIndex}`);
|
332
347
|
}
|
@@ -432,13 +447,15 @@ class RLNBaseContract {
|
|
432
447
|
}
|
433
448
|
}
|
434
449
|
/**
|
435
|
-
* Validates that the rate limit is within the allowed range
|
450
|
+
* Validates that the rate limit is within the allowed range (sync)
|
436
451
|
* @throws Error if the rate limit is outside the allowed range
|
437
452
|
*/
|
438
453
|
validateRateLimit(rateLimit) {
|
439
|
-
if (
|
440
|
-
|
441
|
-
|
454
|
+
if (this.minRateLimit === undefined || this.maxRateLimit === undefined) {
|
455
|
+
throw new Error("Rate limits not initialized");
|
456
|
+
}
|
457
|
+
if (rateLimit < this.minRateLimit || rateLimit > this.maxRateLimit) {
|
458
|
+
throw new Error(`Rate limit must be between ${this.minRateLimit} and ${this.maxRateLimit} messages per epoch`);
|
442
459
|
}
|
443
460
|
}
|
444
461
|
get membersFilter() {
|
@@ -459,9 +476,9 @@ class RLNBaseContract {
|
|
459
476
|
}
|
460
477
|
return this._membersExpiredFilter;
|
461
478
|
}
|
462
|
-
async getMemberIndex(
|
479
|
+
async getMemberIndex(idCommitmentBigInt) {
|
463
480
|
try {
|
464
|
-
const events = await this.contract.queryFilter(this.contract.filters.MembershipRegistered(
|
481
|
+
const events = await this.contract.queryFilter(this.contract.filters.MembershipRegistered(idCommitmentBigInt));
|
465
482
|
if (events.length === 0)
|
466
483
|
return undefined;
|
467
484
|
// Get the most recent registration event
|
@@ -472,6 +489,45 @@ class RLNBaseContract {
|
|
472
489
|
return undefined;
|
473
490
|
}
|
474
491
|
}
|
492
|
+
async getMembershipStatus(idCommitment) {
|
493
|
+
const [isExpired, isInGrace] = await Promise.all([
|
494
|
+
this.contract.isExpired(idCommitment),
|
495
|
+
this.contract.isInGracePeriod(idCommitment)
|
496
|
+
]);
|
497
|
+
if (isExpired)
|
498
|
+
return "expired";
|
499
|
+
if (isInGrace)
|
500
|
+
return "grace";
|
501
|
+
return "active";
|
502
|
+
}
|
503
|
+
/**
|
504
|
+
* Checks if a membership is expired for the given idCommitment
|
505
|
+
* @param idCommitmentBigInt The idCommitment as bigint
|
506
|
+
* @returns Promise<boolean> True if expired, false otherwise
|
507
|
+
*/
|
508
|
+
async isExpired(idCommitmentBigInt) {
|
509
|
+
try {
|
510
|
+
return await this.contract.isExpired(idCommitmentBigInt);
|
511
|
+
}
|
512
|
+
catch (error) {
|
513
|
+
log.error("Error in isExpired:", error);
|
514
|
+
return false;
|
515
|
+
}
|
516
|
+
}
|
517
|
+
/**
|
518
|
+
* Checks if a membership is in grace period for the given idCommitment
|
519
|
+
* @param idCommitmentBigInt The idCommitment as bigint
|
520
|
+
* @returns Promise<boolean> True if in grace period, false otherwise
|
521
|
+
*/
|
522
|
+
async isInGracePeriod(idCommitmentBigInt) {
|
523
|
+
try {
|
524
|
+
return await this.contract.isInGracePeriod(idCommitmentBigInt);
|
525
|
+
}
|
526
|
+
catch (error) {
|
527
|
+
log.error("Error in isInGracePeriod:", error);
|
528
|
+
return false;
|
529
|
+
}
|
530
|
+
}
|
475
531
|
}
|
476
532
|
|
477
533
|
export { RLNBaseContract };
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { hmac } from '
|
2
|
-
import { sha256 } from '
|
1
|
+
import { hmac } from '../../../node_modules/@noble/hashes/esm/hmac.js';
|
2
|
+
import { sha256 } from '../../../node_modules/@noble/hashes/esm/sha256.js';
|
3
3
|
import '../../interfaces/dist/protocols.js';
|
4
4
|
import '../../interfaces/dist/connection_manager.js';
|
5
5
|
import '../../interfaces/dist/health_indicator.js';
|
@@ -64,7 +64,7 @@ class RLNCredentialsManager {
|
|
64
64
|
}
|
65
65
|
this.credentials = credentials;
|
66
66
|
this.signer = signer;
|
67
|
-
this.contract =
|
67
|
+
this.contract = await RLNBaseContract.create({
|
68
68
|
address: address,
|
69
69
|
signer: signer,
|
70
70
|
rateLimit: rateLimit ?? this.zerokit?.rateLimit
|
@@ -22,7 +22,7 @@ class IdentityCredential {
|
|
22
22
|
const idNullifier = memKeys.subarray(32, 64);
|
23
23
|
const idSecretHash = memKeys.subarray(64, 96);
|
24
24
|
const idCommitment = memKeys.subarray(96, 128);
|
25
|
-
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment
|
25
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
|
26
26
|
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
27
27
|
}
|
28
28
|
}
|
@@ -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';
|
@@ -44,9 +44,12 @@ function writeUIntLE(buf, value, offset, byteLength, noAssert) {
|
|
44
44
|
* @param array: Uint8Array
|
45
45
|
* @returns BigInt
|
46
46
|
*/
|
47
|
-
function buildBigIntFromUint8Array(array
|
48
|
-
|
49
|
-
|
47
|
+
function buildBigIntFromUint8Array(array) {
|
48
|
+
let hex = "";
|
49
|
+
for (let i = 0; i < array.length; i++) {
|
50
|
+
hex = array[i].toString(16).padStart(2, "0") + hex; // Reverse order for big-endian
|
51
|
+
}
|
52
|
+
return BigInt("0x" + hex);
|
50
53
|
}
|
51
54
|
/**
|
52
55
|
* Fills with zeros to set length
|