@waku/rln 0.0.2-c41b319.0 → 0.0.2-c8128d1.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/index.js +1 -1
- package/bundle/packages/interfaces/dist/protocols.js +40 -45
- package/bundle/packages/rln/dist/contract/abi.js +648 -0
- package/bundle/packages/rln/dist/contract/constants.js +8 -13
- package/bundle/packages/rln/dist/contract/rln_contract.js +148 -25
- package/bundle/packages/rln/dist/identity.js +0 -24
- package/bundle/packages/rln/dist/rln.js +33 -15
- package/bundle/packages/rln/dist/zerokit.js +22 -16
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/{abi/rlnv2.d.ts → abi.d.ts} +22 -18
- package/dist/contract/abi.js +647 -0
- package/dist/contract/abi.js.map +1 -0
- package/dist/contract/constants.d.ts +22 -23
- package/dist/contract/constants.js +7 -12
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +13 -3
- package/dist/contract/rln_contract.js +148 -25
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/identity.d.ts +0 -1
- package/dist/identity.js +0 -24
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/rln.js +33 -14
- package/dist/rln.js.map +1 -1
- package/dist/zerokit.d.ts +5 -1
- package/dist/zerokit.js +22 -16
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/abi.ts +646 -0
- package/src/contract/constants.ts +8 -14
- package/src/contract/rln_contract.ts +227 -27
- package/src/identity.ts +0 -42
- package/src/index.ts +2 -2
- package/src/rln.ts +48 -14
- package/src/zerokit.ts +45 -16
- package/bundle/node_modules/@iden3/js-crypto/dist/browser/esm/index.js +0 -7
- package/bundle/node_modules/@stablelib/binary/lib/binary.js +0 -22
- package/bundle/node_modules/@stablelib/chacha/lib/chacha.js +0 -245
- package/bundle/node_modules/@stablelib/wipe/lib/wipe.js +0 -26
- package/bundle/packages/rln/dist/contract/abi/rlnv2.js +0 -394
- package/dist/contract/abi/rlnv2.js +0 -393
- package/dist/contract/abi/rlnv2.js.map +0 -1
- package/src/contract/abi/rlnv2.ts +0 -392
package/src/zerokit.ts
CHANGED
@@ -15,9 +15,22 @@ import {
|
|
15
15
|
export class Zerokit {
|
16
16
|
public constructor(
|
17
17
|
private readonly zkRLN: number,
|
18
|
-
private readonly witnessCalculator: WitnessCalculator
|
18
|
+
private readonly witnessCalculator: WitnessCalculator,
|
19
|
+
private readonly rateLimit: number = DEFAULT_RATE_LIMIT
|
19
20
|
) {}
|
20
21
|
|
22
|
+
public get getZkRLN(): number {
|
23
|
+
return this.zkRLN;
|
24
|
+
}
|
25
|
+
|
26
|
+
public get getWitnessCalculator(): WitnessCalculator {
|
27
|
+
return this.witnessCalculator;
|
28
|
+
}
|
29
|
+
|
30
|
+
public get getRateLimit(): number {
|
31
|
+
return this.rateLimit;
|
32
|
+
}
|
33
|
+
|
21
34
|
public generateIdentityCredentials(): IdentityCredential {
|
22
35
|
const memKeys = zerokitRLN.generateExtendedMembershipKey(this.zkRLN); // TODO: rename this function in zerokit rln-wasm
|
23
36
|
return IdentityCredential.fromBytes(memKeys);
|
@@ -67,12 +80,17 @@ export class Zerokit {
|
|
67
80
|
memIndex: number,
|
68
81
|
epoch: Uint8Array,
|
69
82
|
idKey: Uint8Array,
|
70
|
-
rateLimit
|
83
|
+
rateLimit?: number
|
71
84
|
): Uint8Array {
|
72
85
|
// calculate message length
|
73
86
|
const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
|
74
87
|
const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
|
75
|
-
const rateLimitBytes = writeUIntLE(
|
88
|
+
const rateLimitBytes = writeUIntLE(
|
89
|
+
new Uint8Array(8),
|
90
|
+
rateLimit ?? this.rateLimit,
|
91
|
+
0,
|
92
|
+
8
|
93
|
+
);
|
76
94
|
|
77
95
|
// [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> | rate_limit<8> ]
|
78
96
|
return concatenate(
|
@@ -90,7 +108,7 @@ export class Zerokit {
|
|
90
108
|
index: number,
|
91
109
|
epoch: Uint8Array | Date | undefined,
|
92
110
|
idSecretHash: Uint8Array,
|
93
|
-
rateLimit
|
111
|
+
rateLimit?: number
|
94
112
|
): Promise<IRateLimitProof> {
|
95
113
|
if (epoch === undefined) {
|
96
114
|
epoch = epochIntToBytes(dateToEpoch(new Date()));
|
@@ -98,12 +116,14 @@ export class Zerokit {
|
|
98
116
|
epoch = epochIntToBytes(dateToEpoch(epoch));
|
99
117
|
}
|
100
118
|
|
119
|
+
const effectiveRateLimit = rateLimit ?? this.rateLimit;
|
120
|
+
|
101
121
|
if (epoch.length !== 32) throw new Error("invalid epoch");
|
102
122
|
if (idSecretHash.length !== 32) throw new Error("invalid id secret hash");
|
103
123
|
if (index < 0) throw new Error("index must be >= 0");
|
104
124
|
if (
|
105
|
-
|
106
|
-
|
125
|
+
effectiveRateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
126
|
+
effectiveRateLimit > RATE_LIMIT_PARAMS.MAX_RATE
|
107
127
|
) {
|
108
128
|
throw new Error(
|
109
129
|
`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`
|
@@ -115,7 +135,7 @@ export class Zerokit {
|
|
115
135
|
index,
|
116
136
|
epoch,
|
117
137
|
idSecretHash,
|
118
|
-
|
138
|
+
effectiveRateLimit
|
119
139
|
);
|
120
140
|
const rlnWitness = zerokitRLN.getSerializedRLNWitness(
|
121
141
|
this.zkRLN,
|
@@ -150,9 +170,12 @@ export class Zerokit {
|
|
150
170
|
|
151
171
|
// calculate message length
|
152
172
|
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
153
|
-
const rateLimitBytes =
|
154
|
-
|
155
|
-
|
173
|
+
const rateLimitBytes = writeUIntLE(
|
174
|
+
new Uint8Array(8),
|
175
|
+
rateLimit ?? this.rateLimit,
|
176
|
+
0,
|
177
|
+
8
|
178
|
+
);
|
156
179
|
|
157
180
|
return zerokitRLN.verifyRLNProof(
|
158
181
|
this.zkRLN,
|
@@ -174,9 +197,12 @@ export class Zerokit {
|
|
174
197
|
}
|
175
198
|
// calculate message length
|
176
199
|
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
177
|
-
const rateLimitBytes =
|
178
|
-
|
179
|
-
|
200
|
+
const rateLimitBytes = writeUIntLE(
|
201
|
+
new Uint8Array(8),
|
202
|
+
rateLimit ?? this.rateLimit,
|
203
|
+
0,
|
204
|
+
8
|
205
|
+
);
|
180
206
|
|
181
207
|
const rootsBytes = concatenate(...roots);
|
182
208
|
|
@@ -201,9 +227,12 @@ export class Zerokit {
|
|
201
227
|
|
202
228
|
// calculate message length
|
203
229
|
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
204
|
-
const rateLimitBytes =
|
205
|
-
|
206
|
-
|
230
|
+
const rateLimitBytes = writeUIntLE(
|
231
|
+
new Uint8Array(8),
|
232
|
+
rateLimit ?? this.rateLimit,
|
233
|
+
0,
|
234
|
+
8
|
235
|
+
);
|
207
236
|
|
208
237
|
return zerokitRLN.verifyWithRoots(
|
209
238
|
this.zkRLN,
|