@waku/rln 0.1.5-053bb95.0 → 0.1.5-1d384f2.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/constants.js +5 -2
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +244 -114
- package/bundle/packages/rln/dist/contract/rln_contract.js +74 -89
- package/bundle/packages/rln/dist/credentials_manager.js +1 -1
- package/bundle/packages/rln/dist/identity.js +0 -8
- package/bundle/packages/rln/dist/keystore/keystore.js +28 -15
- 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/constants.d.ts +1 -1
- package/dist/contract/constants.js +1 -1
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_base_contract.d.ts +30 -22
- package/dist/contract/rln_base_contract.js +244 -114
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +4 -24
- package/dist/contract/rln_contract.js +74 -89
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/credentials_manager.js +1 -1
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.d.ts +0 -1
- package/dist/identity.js +0 -8
- package/dist/identity.js.map +1 -1
- package/dist/keystore/keystore.d.ts +1 -0
- package/dist/keystore/keystore.js +28 -15
- package/dist/keystore/keystore.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +1 -1
- package/src/contract/rln_base_contract.ts +390 -183
- package/src/contract/rln_contract.ts +95 -120
- package/src/credentials_manager.ts +1 -1
- package/src/identity.ts +0 -9
- package/src/keystore/keystore.ts +50 -27
- package/bundle/packages/rln/dist/contract/errors.js +0 -62
- package/dist/contract/errors.d.ts +0 -30
- package/dist/contract/errors.js +0 -61
- package/dist/contract/errors.js.map +0 -1
- package/src/contract/errors.ts +0 -75
@@ -1,11 +1,11 @@
|
|
1
1
|
import { Logger } from "@waku/utils";
|
2
2
|
import { hexToBytes } from "@waku/utils/bytes";
|
3
|
+
import { ethers } from "ethers";
|
3
4
|
|
4
5
|
import type { RLNInstance } from "../rln.js";
|
5
6
|
import { MerkleRootTracker } from "../root_tracker.js";
|
6
7
|
import { zeroPadLE } from "../utils/bytes.js";
|
7
8
|
|
8
|
-
import { ContractStateError } from "./errors.js";
|
9
9
|
import { RLNBaseContract } from "./rln_base_contract.js";
|
10
10
|
import { RLNContractInitOptions } from "./types.js";
|
11
11
|
|
@@ -14,7 +14,6 @@ const log = new Logger("waku:rln:contract");
|
|
14
14
|
export class RLNContract extends RLNBaseContract {
|
15
15
|
private instance: RLNInstance;
|
16
16
|
private merkleRootTracker: MerkleRootTracker;
|
17
|
-
private lastSyncedBlock: number = 0;
|
18
17
|
|
19
18
|
/**
|
20
19
|
* Asynchronous initializer for RLNContract.
|
@@ -25,42 +24,8 @@ export class RLNContract extends RLNBaseContract {
|
|
25
24
|
options: RLNContractInitOptions
|
26
25
|
): Promise<RLNContract> {
|
27
26
|
const rlnContract = new RLNContract(rlnInstance, options);
|
28
|
-
await rlnContract.syncState();
|
29
|
-
return rlnContract;
|
30
|
-
}
|
31
|
-
|
32
|
-
/**
|
33
|
-
* Override base contract method to keep Merkle tree in sync
|
34
|
-
* Registers a new membership with the given commitment and rate limit
|
35
|
-
*/
|
36
|
-
public override async registerMembership(
|
37
|
-
idCommitment: string,
|
38
|
-
rateLimit: number = this.getRateLimit()
|
39
|
-
): Promise<void> {
|
40
|
-
await super.registerMembership(idCommitment, rateLimit);
|
41
|
-
await this.syncState();
|
42
|
-
}
|
43
27
|
|
44
|
-
|
45
|
-
* Override base contract method to keep Merkle tree in sync
|
46
|
-
* Erases an existing membership from the contract
|
47
|
-
*/
|
48
|
-
public override async eraseMembership(
|
49
|
-
idCommitment: string,
|
50
|
-
eraseFromMembershipSet: boolean = true
|
51
|
-
): Promise<void> {
|
52
|
-
await super.eraseMembership(idCommitment, eraseFromMembershipSet);
|
53
|
-
await this.syncState();
|
54
|
-
}
|
55
|
-
|
56
|
-
/**
|
57
|
-
* Gets the current Merkle root
|
58
|
-
* Returns the latest valid root or empty array if no roots exist
|
59
|
-
*/
|
60
|
-
public async getMerkleRoot(): Promise<Uint8Array> {
|
61
|
-
await this.syncState();
|
62
|
-
const roots = this.merkleRootTracker.roots();
|
63
|
-
return roots.length > 0 ? roots[0] : new Uint8Array();
|
28
|
+
return rlnContract;
|
64
29
|
}
|
65
30
|
|
66
31
|
private constructor(
|
@@ -68,102 +33,112 @@ export class RLNContract extends RLNBaseContract {
|
|
68
33
|
options: RLNContractInitOptions
|
69
34
|
) {
|
70
35
|
super(options);
|
36
|
+
|
71
37
|
this.instance = rlnInstance;
|
38
|
+
|
72
39
|
const initialRoot = rlnInstance.zerokit.getMerkleRoot();
|
73
40
|
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
74
41
|
}
|
75
42
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
// If we're already synced, just get new members
|
84
|
-
if (this.lastSyncedBlock > 0) {
|
85
|
-
await this.syncNewMembers(this.lastSyncedBlock, currentBlock);
|
86
|
-
this.lastSyncedBlock = currentBlock;
|
43
|
+
public override processEvents(events: ethers.Event[]): void {
|
44
|
+
const toRemoveTable = new Map<number, number[]>();
|
45
|
+
const toInsertTable = new Map<number, ethers.Event[]>();
|
46
|
+
|
47
|
+
events.forEach((evt) => {
|
48
|
+
if (!evt.args) {
|
87
49
|
return;
|
88
50
|
}
|
89
51
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
this.instance.zerokit.deleteMember(i);
|
99
|
-
} catch (error) {
|
100
|
-
// Ignore errors for non-existent members
|
101
|
-
continue;
|
52
|
+
if (
|
53
|
+
evt.event === "MembershipErased" ||
|
54
|
+
evt.event === "MembershipExpired"
|
55
|
+
) {
|
56
|
+
let index = evt.args.index;
|
57
|
+
|
58
|
+
if (!index) {
|
59
|
+
return;
|
102
60
|
}
|
103
|
-
}
|
104
61
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
62
|
+
if (typeof index === "number" || typeof index === "string") {
|
63
|
+
index = ethers.BigNumber.from(index);
|
64
|
+
} else {
|
65
|
+
log.error("Index is not a number or string", {
|
66
|
+
index,
|
67
|
+
event: evt
|
68
|
+
});
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
|
72
|
+
const toRemoveVal = toRemoveTable.get(evt.blockNumber);
|
73
|
+
if (toRemoveVal != undefined) {
|
74
|
+
toRemoveVal.push(index.toNumber());
|
75
|
+
toRemoveTable.set(evt.blockNumber, toRemoveVal);
|
76
|
+
} else {
|
77
|
+
toRemoveTable.set(evt.blockNumber, [index.toNumber()]);
|
78
|
+
}
|
79
|
+
} else if (evt.event === "MembershipRegistered") {
|
80
|
+
let eventsPerBlock = toInsertTable.get(evt.blockNumber);
|
81
|
+
if (eventsPerBlock == undefined) {
|
82
|
+
eventsPerBlock = [];
|
83
|
+
}
|
84
|
+
|
85
|
+
eventsPerBlock.push(evt);
|
86
|
+
toInsertTable.set(evt.blockNumber, eventsPerBlock);
|
109
87
|
}
|
88
|
+
});
|
110
89
|
|
111
|
-
|
112
|
-
|
113
|
-
this.merkleRootTracker.pushRoot(currentBlock, currentRoot);
|
114
|
-
this.lastSyncedBlock = currentBlock;
|
115
|
-
|
116
|
-
log.info(
|
117
|
-
`Synced ${members.length} members to current block ${currentBlock}`
|
118
|
-
);
|
119
|
-
} catch (error) {
|
120
|
-
log.error("Failed to sync state", error);
|
121
|
-
throw new ContractStateError("Failed to sync contract state");
|
122
|
-
}
|
90
|
+
this.removeMembers(this.instance, toRemoveTable);
|
91
|
+
this.insertMembers(this.instance, toInsertTable);
|
123
92
|
}
|
124
93
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
this.merkleRootTracker.
|
156
|
-
}
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
94
|
+
private insertMembers(
|
95
|
+
rlnInstance: RLNInstance,
|
96
|
+
toInsert: Map<number, ethers.Event[]>
|
97
|
+
): void {
|
98
|
+
toInsert.forEach((events: ethers.Event[], blockNumber: number) => {
|
99
|
+
events.forEach((evt) => {
|
100
|
+
if (!evt.args) return;
|
101
|
+
|
102
|
+
const _idCommitment = evt.args.idCommitment as string;
|
103
|
+
let index = evt.args.index;
|
104
|
+
|
105
|
+
if (!_idCommitment || !index) {
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
|
109
|
+
if (typeof index === "number" || typeof index === "string") {
|
110
|
+
index = ethers.BigNumber.from(index);
|
111
|
+
}
|
112
|
+
|
113
|
+
const idCommitment = zeroPadLE(hexToBytes(_idCommitment), 32);
|
114
|
+
rlnInstance.zerokit.insertMember(idCommitment);
|
115
|
+
|
116
|
+
const numericIndex = index.toNumber();
|
117
|
+
this._members.set(numericIndex, {
|
118
|
+
index,
|
119
|
+
idCommitment: _idCommitment
|
120
|
+
});
|
121
|
+
});
|
122
|
+
|
123
|
+
const currentRoot = rlnInstance.zerokit.getMerkleRoot();
|
124
|
+
this.merkleRootTracker.pushRoot(blockNumber, currentRoot);
|
125
|
+
});
|
126
|
+
}
|
127
|
+
|
128
|
+
private removeMembers(
|
129
|
+
rlnInstance: RLNInstance,
|
130
|
+
toRemove: Map<number, number[]>
|
131
|
+
): void {
|
132
|
+
const removeDescending = new Map([...toRemove].reverse());
|
133
|
+
removeDescending.forEach((indexes: number[], blockNumber: number) => {
|
134
|
+
indexes.forEach((index) => {
|
135
|
+
if (this._members.has(index)) {
|
136
|
+
this._members.delete(index);
|
137
|
+
rlnInstance.zerokit.deleteMember(index);
|
138
|
+
}
|
139
|
+
});
|
140
|
+
|
141
|
+
this.merkleRootTracker.backFill(blockNumber);
|
142
|
+
});
|
168
143
|
}
|
169
144
|
}
|
@@ -155,7 +155,7 @@ export class RLNCredentialsManager {
|
|
155
155
|
LINEA_CONTRACT.address;
|
156
156
|
|
157
157
|
if (address === LINEA_CONTRACT.address) {
|
158
|
-
chainId = LINEA_CONTRACT.chainId;
|
158
|
+
chainId = LINEA_CONTRACT.chainId.toString();
|
159
159
|
log.info(`Using Linea contract with chainId: ${chainId}`);
|
160
160
|
}
|
161
161
|
|
package/src/identity.ts
CHANGED
@@ -28,13 +28,4 @@ export class IdentityCredential {
|
|
28
28
|
idCommitmentBigInt
|
29
29
|
);
|
30
30
|
}
|
31
|
-
|
32
|
-
public toJSON(): Record<string, number[]> {
|
33
|
-
return {
|
34
|
-
idTrapdoor: Array.from(this.IDTrapdoor),
|
35
|
-
idNullifier: Array.from(this.IDNullifier),
|
36
|
-
idSecretHash: Array.from(this.IDSecretHash),
|
37
|
-
idCommitment: Array.from(this.IDCommitment)
|
38
|
-
};
|
39
|
-
}
|
40
31
|
}
|
package/src/keystore/keystore.ts
CHANGED
@@ -14,7 +14,6 @@ import {
|
|
14
14
|
import _ from "lodash";
|
15
15
|
import { v4 as uuidV4 } from "uuid";
|
16
16
|
|
17
|
-
import { IdentityCredential } from "../identity.js";
|
18
17
|
import { buildBigIntFromUint8Array } from "../utils/bytes.js";
|
19
18
|
|
20
19
|
import { decryptEipKeystore, keccak256Checksum } from "./cipher.js";
|
@@ -251,27 +250,27 @@ export class Keystore {
|
|
251
250
|
const str = bytesToUtf8(bytes);
|
252
251
|
const obj = JSON.parse(str);
|
253
252
|
|
254
|
-
//
|
255
|
-
const { idTrapdoor, idNullifier, idSecretHash, idCommitment } = _.get(
|
256
|
-
obj,
|
257
|
-
"identityCredential",
|
258
|
-
{}
|
259
|
-
);
|
260
|
-
|
261
|
-
const idTrapdoorArray = new Uint8Array(idTrapdoor || []);
|
262
|
-
const idNullifierArray = new Uint8Array(idNullifier || []);
|
263
|
-
const idSecretHashArray = new Uint8Array(idSecretHash || []);
|
264
|
-
const idCommitmentArray = new Uint8Array(idCommitment || []);
|
265
|
-
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitmentArray);
|
266
|
-
|
253
|
+
// TODO: add runtime validation of nwaku credentials
|
267
254
|
return {
|
268
|
-
identity:
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
255
|
+
identity: {
|
256
|
+
IDCommitment: Keystore.fromArraylikeToBytes(
|
257
|
+
_.get(obj, "identityCredential.idCommitment", [])
|
258
|
+
),
|
259
|
+
IDTrapdoor: Keystore.fromArraylikeToBytes(
|
260
|
+
_.get(obj, "identityCredential.idTrapdoor", [])
|
261
|
+
),
|
262
|
+
IDNullifier: Keystore.fromArraylikeToBytes(
|
263
|
+
_.get(obj, "identityCredential.idNullifier", [])
|
264
|
+
),
|
265
|
+
IDCommitmentBigInt: buildBigIntFromUint8Array(
|
266
|
+
Keystore.fromArraylikeToBytes(
|
267
|
+
_.get(obj, "identityCredential.idCommitment", [])
|
268
|
+
)
|
269
|
+
),
|
270
|
+
IDSecretHash: Keystore.fromArraylikeToBytes(
|
271
|
+
_.get(obj, "identityCredential.idSecretHash", [])
|
272
|
+
)
|
273
|
+
},
|
275
274
|
membership: {
|
276
275
|
treeIndex: _.get(obj, "treeIndex"),
|
277
276
|
chainId: _.get(obj, "membershipContract.chainId"),
|
@@ -285,6 +284,30 @@ export class Keystore {
|
|
285
284
|
}
|
286
285
|
}
|
287
286
|
|
287
|
+
private static fromArraylikeToBytes(
|
288
|
+
obj:
|
289
|
+
| number[]
|
290
|
+
| {
|
291
|
+
[key: number]: number;
|
292
|
+
}
|
293
|
+
): Uint8Array {
|
294
|
+
if (Array.isArray(obj)) {
|
295
|
+
return new Uint8Array(obj);
|
296
|
+
}
|
297
|
+
|
298
|
+
const bytes = [];
|
299
|
+
let index = 0;
|
300
|
+
let lastElement = obj[index];
|
301
|
+
|
302
|
+
while (lastElement !== undefined) {
|
303
|
+
bytes.push(lastElement);
|
304
|
+
index += 1;
|
305
|
+
lastElement = obj[index];
|
306
|
+
}
|
307
|
+
|
308
|
+
return new Uint8Array(bytes);
|
309
|
+
}
|
310
|
+
|
288
311
|
// follows nwaku implementation
|
289
312
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
|
290
313
|
private static computeMembershipHash(info: MembershipInfo): MembershipHash {
|
@@ -298,16 +321,16 @@ export class Keystore {
|
|
298
321
|
private static fromIdentityToBytes(options: KeystoreEntity): Uint8Array {
|
299
322
|
return utf8ToBytes(
|
300
323
|
JSON.stringify({
|
301
|
-
membershipContract: {
|
302
|
-
chainId: options.membership.chainId,
|
303
|
-
address: options.membership.address
|
304
|
-
},
|
305
324
|
treeIndex: options.membership.treeIndex,
|
306
325
|
identityCredential: {
|
307
|
-
|
326
|
+
idCommitment: Array.from(options.identity.IDCommitment),
|
308
327
|
idNullifier: Array.from(options.identity.IDNullifier),
|
309
328
|
idSecretHash: Array.from(options.identity.IDSecretHash),
|
310
|
-
|
329
|
+
idTrapdoor: Array.from(options.identity.IDTrapdoor)
|
330
|
+
},
|
331
|
+
membershipContract: {
|
332
|
+
chainId: options.membership.chainId,
|
333
|
+
address: options.membership.address
|
311
334
|
},
|
312
335
|
userMessageLimit: options.membership.rateLimit
|
313
336
|
})
|
@@ -1,62 +0,0 @@
|
|
1
|
-
class RLNContractError extends Error {
|
2
|
-
constructor(message) {
|
3
|
-
super(message);
|
4
|
-
this.name = "RLNContractError";
|
5
|
-
}
|
6
|
-
}
|
7
|
-
class MembershipError extends RLNContractError {
|
8
|
-
constructor(message) {
|
9
|
-
super(message);
|
10
|
-
this.name = "MembershipError";
|
11
|
-
}
|
12
|
-
}
|
13
|
-
class RateLimitError extends RLNContractError {
|
14
|
-
constructor(message) {
|
15
|
-
super(message);
|
16
|
-
this.name = "RateLimitError";
|
17
|
-
}
|
18
|
-
}
|
19
|
-
class InvalidMembershipError extends MembershipError {
|
20
|
-
constructor(idCommitment) {
|
21
|
-
super(`Invalid membership ID commitment: ${idCommitment}`);
|
22
|
-
this.name = "InvalidMembershipError";
|
23
|
-
}
|
24
|
-
}
|
25
|
-
class MembershipNotFoundError extends MembershipError {
|
26
|
-
constructor(idCommitment) {
|
27
|
-
super(`Membership not found for ID commitment: ${idCommitment}`);
|
28
|
-
this.name = "MembershipNotFoundError";
|
29
|
-
}
|
30
|
-
}
|
31
|
-
class MembershipExistsError extends MembershipError {
|
32
|
-
constructor(idCommitment, index) {
|
33
|
-
super(`Membership already exists for ID commitment: ${idCommitment} at index ${index}`);
|
34
|
-
this.name = "MembershipExistsError";
|
35
|
-
}
|
36
|
-
}
|
37
|
-
class RateLimitExceededError extends RateLimitError {
|
38
|
-
constructor(requested, available) {
|
39
|
-
super(`Rate limit exceeded. Requested: ${requested}, Available: ${available}`);
|
40
|
-
this.name = "RateLimitExceededError";
|
41
|
-
}
|
42
|
-
}
|
43
|
-
class InvalidRateLimitError extends RateLimitError {
|
44
|
-
constructor(rateLimit, minRate, maxRate) {
|
45
|
-
super(`Invalid rate limit: ${rateLimit}. Must be between ${minRate} and ${maxRate}`);
|
46
|
-
this.name = "InvalidRateLimitError";
|
47
|
-
}
|
48
|
-
}
|
49
|
-
class ContractStateError extends RLNContractError {
|
50
|
-
constructor(message) {
|
51
|
-
super(`Contract state error: ${message}`);
|
52
|
-
this.name = "ContractStateError";
|
53
|
-
}
|
54
|
-
}
|
55
|
-
class TransactionError extends RLNContractError {
|
56
|
-
constructor(message) {
|
57
|
-
super(`Transaction failed: ${message}`);
|
58
|
-
this.name = "TransactionError";
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
export { ContractStateError, InvalidMembershipError, InvalidRateLimitError, MembershipError, MembershipExistsError, MembershipNotFoundError, RLNContractError, RateLimitError, RateLimitExceededError, TransactionError };
|
@@ -1,30 +0,0 @@
|
|
1
|
-
export declare class RLNContractError extends Error {
|
2
|
-
constructor(message: string);
|
3
|
-
}
|
4
|
-
export declare class MembershipError extends RLNContractError {
|
5
|
-
constructor(message: string);
|
6
|
-
}
|
7
|
-
export declare class RateLimitError extends RLNContractError {
|
8
|
-
constructor(message: string);
|
9
|
-
}
|
10
|
-
export declare class InvalidMembershipError extends MembershipError {
|
11
|
-
constructor(idCommitment: string);
|
12
|
-
}
|
13
|
-
export declare class MembershipNotFoundError extends MembershipError {
|
14
|
-
constructor(idCommitment: string);
|
15
|
-
}
|
16
|
-
export declare class MembershipExistsError extends MembershipError {
|
17
|
-
constructor(idCommitment: string, index: string);
|
18
|
-
}
|
19
|
-
export declare class RateLimitExceededError extends RateLimitError {
|
20
|
-
constructor(requested: number, available: number);
|
21
|
-
}
|
22
|
-
export declare class InvalidRateLimitError extends RateLimitError {
|
23
|
-
constructor(rateLimit: number, minRate: number, maxRate: number);
|
24
|
-
}
|
25
|
-
export declare class ContractStateError extends RLNContractError {
|
26
|
-
constructor(message: string);
|
27
|
-
}
|
28
|
-
export declare class TransactionError extends RLNContractError {
|
29
|
-
constructor(message: string);
|
30
|
-
}
|
package/dist/contract/errors.js
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
export class RLNContractError extends Error {
|
2
|
-
constructor(message) {
|
3
|
-
super(message);
|
4
|
-
this.name = "RLNContractError";
|
5
|
-
}
|
6
|
-
}
|
7
|
-
export class MembershipError extends RLNContractError {
|
8
|
-
constructor(message) {
|
9
|
-
super(message);
|
10
|
-
this.name = "MembershipError";
|
11
|
-
}
|
12
|
-
}
|
13
|
-
export class RateLimitError extends RLNContractError {
|
14
|
-
constructor(message) {
|
15
|
-
super(message);
|
16
|
-
this.name = "RateLimitError";
|
17
|
-
}
|
18
|
-
}
|
19
|
-
export class InvalidMembershipError extends MembershipError {
|
20
|
-
constructor(idCommitment) {
|
21
|
-
super(`Invalid membership ID commitment: ${idCommitment}`);
|
22
|
-
this.name = "InvalidMembershipError";
|
23
|
-
}
|
24
|
-
}
|
25
|
-
export class MembershipNotFoundError extends MembershipError {
|
26
|
-
constructor(idCommitment) {
|
27
|
-
super(`Membership not found for ID commitment: ${idCommitment}`);
|
28
|
-
this.name = "MembershipNotFoundError";
|
29
|
-
}
|
30
|
-
}
|
31
|
-
export class MembershipExistsError extends MembershipError {
|
32
|
-
constructor(idCommitment, index) {
|
33
|
-
super(`Membership already exists for ID commitment: ${idCommitment} at index ${index}`);
|
34
|
-
this.name = "MembershipExistsError";
|
35
|
-
}
|
36
|
-
}
|
37
|
-
export class RateLimitExceededError extends RateLimitError {
|
38
|
-
constructor(requested, available) {
|
39
|
-
super(`Rate limit exceeded. Requested: ${requested}, Available: ${available}`);
|
40
|
-
this.name = "RateLimitExceededError";
|
41
|
-
}
|
42
|
-
}
|
43
|
-
export class InvalidRateLimitError extends RateLimitError {
|
44
|
-
constructor(rateLimit, minRate, maxRate) {
|
45
|
-
super(`Invalid rate limit: ${rateLimit}. Must be between ${minRate} and ${maxRate}`);
|
46
|
-
this.name = "InvalidRateLimitError";
|
47
|
-
}
|
48
|
-
}
|
49
|
-
export class ContractStateError extends RLNContractError {
|
50
|
-
constructor(message) {
|
51
|
-
super(`Contract state error: ${message}`);
|
52
|
-
this.name = "ContractStateError";
|
53
|
-
}
|
54
|
-
}
|
55
|
-
export class TransactionError extends RLNContractError {
|
56
|
-
constructor(message) {
|
57
|
-
super(`Transaction failed: ${message}`);
|
58
|
-
this.name = "TransactionError";
|
59
|
-
}
|
60
|
-
}
|
61
|
-
//# sourceMappingURL=errors.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/contract/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,gBAAgB;IACnD,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,gBAAgB;IAClD,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,eAAe;IACzD,YAAmB,YAAoB;QACrC,KAAK,CAAC,qCAAqC,YAAY,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,eAAe;IAC1D,YAAmB,YAAoB;QACrC,KAAK,CAAC,2CAA2C,YAAY,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IACxD,YAAmB,YAAoB,EAAE,KAAa;QACpD,KAAK,CACH,gDAAgD,YAAY,aAAa,KAAK,EAAE,CACjF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,cAAc;IACxD,YAAmB,SAAiB,EAAE,SAAiB;QACrD,KAAK,CACH,mCAAmC,SAAS,gBAAgB,SAAS,EAAE,CACxE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,cAAc;IACvD,YAAmB,SAAiB,EAAE,OAAe,EAAE,OAAe;QACpE,KAAK,CACH,uBAAuB,SAAS,qBAAqB,OAAO,QAAQ,OAAO,EAAE,CAC9E,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,gBAAgB;IACtD,YAAmB,OAAe;QAChC,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,gBAAgB;IACpD,YAAmB,OAAe;QAChC,KAAK,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
|
package/src/contract/errors.ts
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
export class RLNContractError extends Error {
|
2
|
-
public constructor(message: string) {
|
3
|
-
super(message);
|
4
|
-
this.name = "RLNContractError";
|
5
|
-
}
|
6
|
-
}
|
7
|
-
|
8
|
-
export class MembershipError extends RLNContractError {
|
9
|
-
public constructor(message: string) {
|
10
|
-
super(message);
|
11
|
-
this.name = "MembershipError";
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
export class RateLimitError extends RLNContractError {
|
16
|
-
public constructor(message: string) {
|
17
|
-
super(message);
|
18
|
-
this.name = "RateLimitError";
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
export class InvalidMembershipError extends MembershipError {
|
23
|
-
public constructor(idCommitment: string) {
|
24
|
-
super(`Invalid membership ID commitment: ${idCommitment}`);
|
25
|
-
this.name = "InvalidMembershipError";
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
export class MembershipNotFoundError extends MembershipError {
|
30
|
-
public constructor(idCommitment: string) {
|
31
|
-
super(`Membership not found for ID commitment: ${idCommitment}`);
|
32
|
-
this.name = "MembershipNotFoundError";
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
export class MembershipExistsError extends MembershipError {
|
37
|
-
public constructor(idCommitment: string, index: string) {
|
38
|
-
super(
|
39
|
-
`Membership already exists for ID commitment: ${idCommitment} at index ${index}`
|
40
|
-
);
|
41
|
-
this.name = "MembershipExistsError";
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
export class RateLimitExceededError extends RateLimitError {
|
46
|
-
public constructor(requested: number, available: number) {
|
47
|
-
super(
|
48
|
-
`Rate limit exceeded. Requested: ${requested}, Available: ${available}`
|
49
|
-
);
|
50
|
-
this.name = "RateLimitExceededError";
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
export class InvalidRateLimitError extends RateLimitError {
|
55
|
-
public constructor(rateLimit: number, minRate: number, maxRate: number) {
|
56
|
-
super(
|
57
|
-
`Invalid rate limit: ${rateLimit}. Must be between ${minRate} and ${maxRate}`
|
58
|
-
);
|
59
|
-
this.name = "InvalidRateLimitError";
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
export class ContractStateError extends RLNContractError {
|
64
|
-
public constructor(message: string) {
|
65
|
-
super(`Contract state error: ${message}`);
|
66
|
-
this.name = "ContractStateError";
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
70
|
-
export class TransactionError extends RLNContractError {
|
71
|
-
public constructor(message: string) {
|
72
|
-
super(`Transaction failed: ${message}`);
|
73
|
-
this.name = "TransactionError";
|
74
|
-
}
|
75
|
-
}
|