@waku/rln 0.1.6-ace7ca2.0 → 0.1.6-b0a2e39.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 +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/_sha2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/hmac.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/pbkdf2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/scrypt.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha256.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha512.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/utils.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +1 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +1 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +2 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +12 -9
- package/bundle/packages/core/dist/lib/light_push/light_push_v3.js +30 -0
- package/bundle/packages/core/dist/lib/light_push/utils.js +18 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +1 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +2 -0
- package/bundle/packages/core/dist/lib/store/store.js +2 -0
- package/bundle/packages/interfaces/dist/light_push_v3.js +29 -0
- package/bundle/packages/interfaces/dist/protocols.js +10 -0
- package/bundle/packages/proto/dist/generated/light_push.js +3 -3
- package/bundle/packages/proto/dist/generated/light_push_v3.js +348 -0
- package/bundle/packages/rln/dist/codec.js +1 -0
- package/bundle/packages/rln/dist/contract/constants.js +1 -7
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +8 -34
- package/bundle/packages/rln/dist/contract/rln_contract.js +1 -0
- package/bundle/packages/rln/dist/credentials_manager.js +15 -16
- package/bundle/packages/rln/dist/identity.js +8 -5
- package/bundle/packages/rln/dist/keystore/keystore.js +12 -15
- package/bundle/packages/rln/dist/message.js +2 -0
- package/bundle/packages/rln/dist/rln.js +2 -0
- package/bundle/packages/rln/dist/utils/bytes.js +16 -14
- package/bundle/packages/rln/dist/utils/epoch.js +1 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +1 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/constants.d.ts +0 -6
- package/dist/contract/constants.js +0 -6
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_base_contract.d.ts +0 -6
- package/dist/contract/rln_base_contract.js +7 -34
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/contract/test-utils.d.ts +39 -0
- package/dist/contract/test-utils.js +118 -0
- package/dist/contract/test-utils.js.map +1 -0
- package/dist/credentials_manager.js +14 -16
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.d.ts +2 -4
- package/dist/identity.js +6 -5
- package/dist/identity.js.map +1 -1
- package/dist/keystore/keystore.js +11 -15
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/utils/bytes.d.ts +6 -2
- package/dist/utils/bytes.js +15 -13
- package/dist/utils/bytes.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +0 -9
- package/src/contract/rln_base_contract.ts +14 -49
- package/src/contract/test-utils.ts +179 -0
- package/src/credentials_manager.ts +21 -27
- package/src/identity.ts +7 -5
- package/src/keystore/keystore.ts +24 -28
- package/src/utils/bytes.ts +25 -21
- package/src/utils/index.ts +1 -1
@@ -0,0 +1,348 @@
|
|
1
|
+
import { decodeMessage } from '../../../../node_modules/protons-runtime/dist/src/decode.js';
|
2
|
+
import { encodeMessage } from '../../../../node_modules/protons-runtime/dist/src/encode.js';
|
3
|
+
import '../../../../node_modules/protons-runtime/dist/src/codec.js';
|
4
|
+
import { message } from '../../../../node_modules/protons-runtime/dist/src/codecs/message.js';
|
5
|
+
import { alloc } from '../../../../node_modules/uint8arrays/dist/src/alloc.js';
|
6
|
+
import '../../../../node_modules/protons-runtime/dist/src/utils/float.js';
|
7
|
+
import '../../../../node_modules/protons-runtime/dist/src/utils/longbits.js';
|
8
|
+
import '../../../../node_modules/protons-runtime/dist/src/utils/writer.js';
|
9
|
+
|
10
|
+
/* eslint-disable import/export */
|
11
|
+
/* eslint-disable complexity */
|
12
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
13
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
|
14
|
+
/* eslint-disable @typescript-eslint/no-empty-interface */
|
15
|
+
var LightpushRequest;
|
16
|
+
(function (LightpushRequest) {
|
17
|
+
let _codec;
|
18
|
+
LightpushRequest.codec = () => {
|
19
|
+
if (_codec == null) {
|
20
|
+
_codec = message((obj, w, opts = {}) => {
|
21
|
+
if (opts.lengthDelimited !== false) {
|
22
|
+
w.fork();
|
23
|
+
}
|
24
|
+
if ((obj.requestId != null && obj.requestId !== '')) {
|
25
|
+
w.uint32(10);
|
26
|
+
w.string(obj.requestId);
|
27
|
+
}
|
28
|
+
if (obj.pubsubTopic != null) {
|
29
|
+
w.uint32(162);
|
30
|
+
w.string(obj.pubsubTopic);
|
31
|
+
}
|
32
|
+
if (obj.message != null) {
|
33
|
+
w.uint32(170);
|
34
|
+
WakuMessage.codec().encode(obj.message, w);
|
35
|
+
}
|
36
|
+
if (opts.lengthDelimited !== false) {
|
37
|
+
w.ldelim();
|
38
|
+
}
|
39
|
+
}, (reader, length, opts = {}) => {
|
40
|
+
const obj = {
|
41
|
+
requestId: ''
|
42
|
+
};
|
43
|
+
const end = length == null ? reader.len : reader.pos + length;
|
44
|
+
while (reader.pos < end) {
|
45
|
+
const tag = reader.uint32();
|
46
|
+
switch (tag >>> 3) {
|
47
|
+
case 1: {
|
48
|
+
obj.requestId = reader.string();
|
49
|
+
break;
|
50
|
+
}
|
51
|
+
case 20: {
|
52
|
+
obj.pubsubTopic = reader.string();
|
53
|
+
break;
|
54
|
+
}
|
55
|
+
case 21: {
|
56
|
+
obj.message = WakuMessage.codec().decode(reader, reader.uint32(), {
|
57
|
+
limits: opts.limits?.message
|
58
|
+
});
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
default: {
|
62
|
+
reader.skipType(tag & 7);
|
63
|
+
break;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
return obj;
|
68
|
+
});
|
69
|
+
}
|
70
|
+
return _codec;
|
71
|
+
};
|
72
|
+
LightpushRequest.encode = (obj) => {
|
73
|
+
return encodeMessage(obj, LightpushRequest.codec());
|
74
|
+
};
|
75
|
+
LightpushRequest.decode = (buf, opts) => {
|
76
|
+
return decodeMessage(buf, LightpushRequest.codec(), opts);
|
77
|
+
};
|
78
|
+
})(LightpushRequest || (LightpushRequest = {}));
|
79
|
+
var LightpushResponse;
|
80
|
+
(function (LightpushResponse) {
|
81
|
+
let _codec;
|
82
|
+
LightpushResponse.codec = () => {
|
83
|
+
if (_codec == null) {
|
84
|
+
_codec = message((obj, w, opts = {}) => {
|
85
|
+
if (opts.lengthDelimited !== false) {
|
86
|
+
w.fork();
|
87
|
+
}
|
88
|
+
if ((obj.requestId != null && obj.requestId !== '')) {
|
89
|
+
w.uint32(10);
|
90
|
+
w.string(obj.requestId);
|
91
|
+
}
|
92
|
+
if ((obj.statusCode != null && obj.statusCode !== 0)) {
|
93
|
+
w.uint32(80);
|
94
|
+
w.uint32(obj.statusCode);
|
95
|
+
}
|
96
|
+
if (obj.statusDesc != null) {
|
97
|
+
w.uint32(90);
|
98
|
+
w.string(obj.statusDesc);
|
99
|
+
}
|
100
|
+
if (obj.relayPeerCount != null) {
|
101
|
+
w.uint32(96);
|
102
|
+
w.uint32(obj.relayPeerCount);
|
103
|
+
}
|
104
|
+
if (opts.lengthDelimited !== false) {
|
105
|
+
w.ldelim();
|
106
|
+
}
|
107
|
+
}, (reader, length, opts = {}) => {
|
108
|
+
const obj = {
|
109
|
+
requestId: '',
|
110
|
+
statusCode: 0
|
111
|
+
};
|
112
|
+
const end = length == null ? reader.len : reader.pos + length;
|
113
|
+
while (reader.pos < end) {
|
114
|
+
const tag = reader.uint32();
|
115
|
+
switch (tag >>> 3) {
|
116
|
+
case 1: {
|
117
|
+
obj.requestId = reader.string();
|
118
|
+
break;
|
119
|
+
}
|
120
|
+
case 10: {
|
121
|
+
obj.statusCode = reader.uint32();
|
122
|
+
break;
|
123
|
+
}
|
124
|
+
case 11: {
|
125
|
+
obj.statusDesc = reader.string();
|
126
|
+
break;
|
127
|
+
}
|
128
|
+
case 12: {
|
129
|
+
obj.relayPeerCount = reader.uint32();
|
130
|
+
break;
|
131
|
+
}
|
132
|
+
default: {
|
133
|
+
reader.skipType(tag & 7);
|
134
|
+
break;
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
return obj;
|
139
|
+
});
|
140
|
+
}
|
141
|
+
return _codec;
|
142
|
+
};
|
143
|
+
LightpushResponse.encode = (obj) => {
|
144
|
+
return encodeMessage(obj, LightpushResponse.codec());
|
145
|
+
};
|
146
|
+
LightpushResponse.decode = (buf, opts) => {
|
147
|
+
return decodeMessage(buf, LightpushResponse.codec(), opts);
|
148
|
+
};
|
149
|
+
})(LightpushResponse || (LightpushResponse = {}));
|
150
|
+
var RateLimitProof;
|
151
|
+
(function (RateLimitProof) {
|
152
|
+
let _codec;
|
153
|
+
RateLimitProof.codec = () => {
|
154
|
+
if (_codec == null) {
|
155
|
+
_codec = message((obj, w, opts = {}) => {
|
156
|
+
if (opts.lengthDelimited !== false) {
|
157
|
+
w.fork();
|
158
|
+
}
|
159
|
+
if ((obj.proof != null && obj.proof.byteLength > 0)) {
|
160
|
+
w.uint32(10);
|
161
|
+
w.bytes(obj.proof);
|
162
|
+
}
|
163
|
+
if ((obj.merkleRoot != null && obj.merkleRoot.byteLength > 0)) {
|
164
|
+
w.uint32(18);
|
165
|
+
w.bytes(obj.merkleRoot);
|
166
|
+
}
|
167
|
+
if ((obj.epoch != null && obj.epoch.byteLength > 0)) {
|
168
|
+
w.uint32(26);
|
169
|
+
w.bytes(obj.epoch);
|
170
|
+
}
|
171
|
+
if ((obj.shareX != null && obj.shareX.byteLength > 0)) {
|
172
|
+
w.uint32(34);
|
173
|
+
w.bytes(obj.shareX);
|
174
|
+
}
|
175
|
+
if ((obj.shareY != null && obj.shareY.byteLength > 0)) {
|
176
|
+
w.uint32(42);
|
177
|
+
w.bytes(obj.shareY);
|
178
|
+
}
|
179
|
+
if ((obj.nullifier != null && obj.nullifier.byteLength > 0)) {
|
180
|
+
w.uint32(50);
|
181
|
+
w.bytes(obj.nullifier);
|
182
|
+
}
|
183
|
+
if ((obj.rlnIdentifier != null && obj.rlnIdentifier.byteLength > 0)) {
|
184
|
+
w.uint32(58);
|
185
|
+
w.bytes(obj.rlnIdentifier);
|
186
|
+
}
|
187
|
+
if (opts.lengthDelimited !== false) {
|
188
|
+
w.ldelim();
|
189
|
+
}
|
190
|
+
}, (reader, length, opts = {}) => {
|
191
|
+
const obj = {
|
192
|
+
proof: alloc(0),
|
193
|
+
merkleRoot: alloc(0),
|
194
|
+
epoch: alloc(0),
|
195
|
+
shareX: alloc(0),
|
196
|
+
shareY: alloc(0),
|
197
|
+
nullifier: alloc(0),
|
198
|
+
rlnIdentifier: alloc(0)
|
199
|
+
};
|
200
|
+
const end = length == null ? reader.len : reader.pos + length;
|
201
|
+
while (reader.pos < end) {
|
202
|
+
const tag = reader.uint32();
|
203
|
+
switch (tag >>> 3) {
|
204
|
+
case 1: {
|
205
|
+
obj.proof = reader.bytes();
|
206
|
+
break;
|
207
|
+
}
|
208
|
+
case 2: {
|
209
|
+
obj.merkleRoot = reader.bytes();
|
210
|
+
break;
|
211
|
+
}
|
212
|
+
case 3: {
|
213
|
+
obj.epoch = reader.bytes();
|
214
|
+
break;
|
215
|
+
}
|
216
|
+
case 4: {
|
217
|
+
obj.shareX = reader.bytes();
|
218
|
+
break;
|
219
|
+
}
|
220
|
+
case 5: {
|
221
|
+
obj.shareY = reader.bytes();
|
222
|
+
break;
|
223
|
+
}
|
224
|
+
case 6: {
|
225
|
+
obj.nullifier = reader.bytes();
|
226
|
+
break;
|
227
|
+
}
|
228
|
+
case 7: {
|
229
|
+
obj.rlnIdentifier = reader.bytes();
|
230
|
+
break;
|
231
|
+
}
|
232
|
+
default: {
|
233
|
+
reader.skipType(tag & 7);
|
234
|
+
break;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}
|
238
|
+
return obj;
|
239
|
+
});
|
240
|
+
}
|
241
|
+
return _codec;
|
242
|
+
};
|
243
|
+
RateLimitProof.encode = (obj) => {
|
244
|
+
return encodeMessage(obj, RateLimitProof.codec());
|
245
|
+
};
|
246
|
+
RateLimitProof.decode = (buf, opts) => {
|
247
|
+
return decodeMessage(buf, RateLimitProof.codec(), opts);
|
248
|
+
};
|
249
|
+
})(RateLimitProof || (RateLimitProof = {}));
|
250
|
+
var WakuMessage;
|
251
|
+
(function (WakuMessage) {
|
252
|
+
let _codec;
|
253
|
+
WakuMessage.codec = () => {
|
254
|
+
if (_codec == null) {
|
255
|
+
_codec = message((obj, w, opts = {}) => {
|
256
|
+
if (opts.lengthDelimited !== false) {
|
257
|
+
w.fork();
|
258
|
+
}
|
259
|
+
if ((obj.payload != null && obj.payload.byteLength > 0)) {
|
260
|
+
w.uint32(10);
|
261
|
+
w.bytes(obj.payload);
|
262
|
+
}
|
263
|
+
if ((obj.contentTopic != null && obj.contentTopic !== '')) {
|
264
|
+
w.uint32(18);
|
265
|
+
w.string(obj.contentTopic);
|
266
|
+
}
|
267
|
+
if (obj.version != null) {
|
268
|
+
w.uint32(24);
|
269
|
+
w.uint32(obj.version);
|
270
|
+
}
|
271
|
+
if (obj.timestamp != null) {
|
272
|
+
w.uint32(80);
|
273
|
+
w.sint64(obj.timestamp);
|
274
|
+
}
|
275
|
+
if (obj.meta != null) {
|
276
|
+
w.uint32(90);
|
277
|
+
w.bytes(obj.meta);
|
278
|
+
}
|
279
|
+
if (obj.rateLimitProof != null) {
|
280
|
+
w.uint32(170);
|
281
|
+
RateLimitProof.codec().encode(obj.rateLimitProof, w);
|
282
|
+
}
|
283
|
+
if (obj.ephemeral != null) {
|
284
|
+
w.uint32(248);
|
285
|
+
w.bool(obj.ephemeral);
|
286
|
+
}
|
287
|
+
if (opts.lengthDelimited !== false) {
|
288
|
+
w.ldelim();
|
289
|
+
}
|
290
|
+
}, (reader, length, opts = {}) => {
|
291
|
+
const obj = {
|
292
|
+
payload: alloc(0),
|
293
|
+
contentTopic: ''
|
294
|
+
};
|
295
|
+
const end = length == null ? reader.len : reader.pos + length;
|
296
|
+
while (reader.pos < end) {
|
297
|
+
const tag = reader.uint32();
|
298
|
+
switch (tag >>> 3) {
|
299
|
+
case 1: {
|
300
|
+
obj.payload = reader.bytes();
|
301
|
+
break;
|
302
|
+
}
|
303
|
+
case 2: {
|
304
|
+
obj.contentTopic = reader.string();
|
305
|
+
break;
|
306
|
+
}
|
307
|
+
case 3: {
|
308
|
+
obj.version = reader.uint32();
|
309
|
+
break;
|
310
|
+
}
|
311
|
+
case 10: {
|
312
|
+
obj.timestamp = reader.sint64();
|
313
|
+
break;
|
314
|
+
}
|
315
|
+
case 11: {
|
316
|
+
obj.meta = reader.bytes();
|
317
|
+
break;
|
318
|
+
}
|
319
|
+
case 21: {
|
320
|
+
obj.rateLimitProof = RateLimitProof.codec().decode(reader, reader.uint32(), {
|
321
|
+
limits: opts.limits?.rateLimitProof
|
322
|
+
});
|
323
|
+
break;
|
324
|
+
}
|
325
|
+
case 31: {
|
326
|
+
obj.ephemeral = reader.bool();
|
327
|
+
break;
|
328
|
+
}
|
329
|
+
default: {
|
330
|
+
reader.skipType(tag & 7);
|
331
|
+
break;
|
332
|
+
}
|
333
|
+
}
|
334
|
+
}
|
335
|
+
return obj;
|
336
|
+
});
|
337
|
+
}
|
338
|
+
return _codec;
|
339
|
+
};
|
340
|
+
WakuMessage.encode = (obj) => {
|
341
|
+
return encodeMessage(obj, WakuMessage.codec());
|
342
|
+
};
|
343
|
+
WakuMessage.decode = (buf, opts) => {
|
344
|
+
return decodeMessage(buf, WakuMessage.codec(), opts);
|
345
|
+
};
|
346
|
+
})(WakuMessage || (WakuMessage = {}));
|
347
|
+
|
348
|
+
export { LightpushRequest, LightpushResponse, RateLimitProof, WakuMessage };
|
@@ -22,12 +22,6 @@ const RATE_LIMIT_PARAMS = {
|
|
22
22
|
MAX_TOTAL_RATE: 160_000, // Maximum total rate limit across all memberships
|
23
23
|
EPOCH_LENGTH: 600 // Epoch length in seconds (10 minutes)
|
24
24
|
};
|
25
|
-
/**
|
26
|
-
* Default Q value for the RLN contract
|
27
|
-
* This is the upper bound for the ID commitment
|
28
|
-
* @see https://github.com/waku-org/specs/blob/master/standards/core/rln-contract.md#implementation-suggestions
|
29
|
-
*/
|
30
|
-
const DEFAULT_Q = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
|
31
25
|
const DEFAULT_RATE_LIMIT = RATE_LIMIT_PARAMS.MAX_RATE;
|
32
26
|
|
33
|
-
export {
|
27
|
+
export { DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS };
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import '../../../interfaces/dist/light_push_v3.js';
|
1
2
|
import '../../../interfaces/dist/protocols.js';
|
2
3
|
import '../../../interfaces/dist/connection_manager.js';
|
3
4
|
import '../../../interfaces/dist/health_indicator.js';
|
@@ -13,9 +14,8 @@ import '../../../../node_modules/multiformats/dist/src/bases/base8.js';
|
|
13
14
|
import '../../../../node_modules/multiformats/dist/src/bases/identity.js';
|
14
15
|
import '../../../../node_modules/multiformats/dist/src/codecs/json.js';
|
15
16
|
import { Logger } from '../../../utils/dist/logger/index.js';
|
16
|
-
import { buildBigIntFromUint8ArrayBE } from '../utils/bytes.js';
|
17
17
|
import { RLN_ABI } from './abi.js';
|
18
|
-
import {
|
18
|
+
import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './constants.js';
|
19
19
|
import { MembershipState } from './types.js';
|
20
20
|
import { Contract } from '../../../../node_modules/@ethersproject/contracts/lib.esm/index.js';
|
21
21
|
import { BigNumber } from '../../../../node_modules/@ethersproject/bignumber/lib.esm/bignumber.js';
|
@@ -27,11 +27,6 @@ class RLNBaseContract {
|
|
27
27
|
rateLimit;
|
28
28
|
minRateLimit;
|
29
29
|
maxRateLimit;
|
30
|
-
/**
|
31
|
-
* Default Q value for the RLN contract.
|
32
|
-
* @see https://github.com/waku-org/waku-rlnv2-contract/blob/b7e9a9b1bc69256a2a3076c1f099b50ce84e7eff/src/WakuRlnV2.sol#L25
|
33
|
-
*/
|
34
|
-
idCommitmentBigIntLimit = DEFAULT_Q;
|
35
30
|
_members = new Map();
|
36
31
|
_membersFilter;
|
37
32
|
_membershipErasedFilter;
|
@@ -70,14 +65,12 @@ class RLNBaseContract {
|
|
70
65
|
*/
|
71
66
|
static async create(options) {
|
72
67
|
const instance = new RLNBaseContract(options);
|
73
|
-
const [min, max
|
68
|
+
const [min, max] = await Promise.all([
|
74
69
|
instance.contract.minMembershipRateLimit(),
|
75
|
-
instance.contract.maxMembershipRateLimit()
|
76
|
-
instance.contract.Q()
|
70
|
+
instance.contract.maxMembershipRateLimit()
|
77
71
|
]);
|
78
72
|
instance.minRateLimit = BigNumber.from(min).toNumber();
|
79
73
|
instance.maxRateLimit = BigNumber.from(max).toNumber();
|
80
|
-
instance.idCommitmentBigIntLimit = BigInt(idCommitmentBigIntLimit.toString());
|
81
74
|
instance.validateRateLimit(instance.rateLimit);
|
82
75
|
return instance;
|
83
76
|
}
|
@@ -345,28 +338,11 @@ class RLNBaseContract {
|
|
345
338
|
log.error(`Error in withdraw: ${error.message}`);
|
346
339
|
}
|
347
340
|
}
|
348
|
-
getIdCommitmentBigInt(bytes) {
|
349
|
-
let idCommitmentBigIntBE = buildBigIntFromUint8ArrayBE(bytes);
|
350
|
-
log.info("getIdCommitmentBigInt", {
|
351
|
-
idCommitmentBigIntBE,
|
352
|
-
idCommitmentBigIntLimit: this.idCommitmentBigIntLimit
|
353
|
-
});
|
354
|
-
if (!this.contract) {
|
355
|
-
throw Error("RLN contract is not initialized");
|
356
|
-
}
|
357
|
-
const idCommitmentBigIntLimit = this.contract.idCommitmentBigIntLimit;
|
358
|
-
if (idCommitmentBigIntBE >= idCommitmentBigIntLimit) {
|
359
|
-
log.warn(`ID commitment is greater than Q, reducing it by Q(idCommitmentBigIntLimit): ${idCommitmentBigIntBE} % ${idCommitmentBigIntLimit}`);
|
360
|
-
idCommitmentBigIntBE = idCommitmentBigIntBE % idCommitmentBigIntLimit;
|
361
|
-
}
|
362
|
-
return idCommitmentBigIntBE;
|
363
|
-
}
|
364
341
|
async registerWithIdentity(identity) {
|
365
342
|
try {
|
366
343
|
log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
|
367
|
-
const idCommitmentBigInt = this.getIdCommitmentBigInt(identity.IDCommitment);
|
368
344
|
// Check if the ID commitment is already registered
|
369
|
-
const existingIndex = await this.getMemberIndex(
|
345
|
+
const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt);
|
370
346
|
if (existingIndex) {
|
371
347
|
throw new Error(`ID commitment is already registered with index ${existingIndex}`);
|
372
348
|
}
|
@@ -375,11 +351,9 @@ class RLNBaseContract {
|
|
375
351
|
if (remainingRateLimit < this.rateLimit) {
|
376
352
|
throw new Error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
|
377
353
|
}
|
378
|
-
const estimatedGas = await this.contract.estimateGas.register(
|
354
|
+
const estimatedGas = await this.contract.estimateGas.register(identity.IDCommitmentBigInt, this.rateLimit, []);
|
379
355
|
const gasLimit = estimatedGas.add(10000);
|
380
|
-
const txRegisterResponse = await this.contract.register(
|
381
|
-
gasLimit
|
382
|
-
});
|
356
|
+
const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], { gasLimit });
|
383
357
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
384
358
|
if (txRegisterReceipt.status === 0) {
|
385
359
|
throw new Error("Transaction failed on-chain");
|
@@ -441,7 +415,7 @@ class RLNBaseContract {
|
|
441
415
|
async registerWithPermitAndErase(identity, permit, idCommitmentsToErase) {
|
442
416
|
try {
|
443
417
|
log.info(`Registering identity with permit and rate limit: ${this.rateLimit} messages/epoch`);
|
444
|
-
const txRegisterResponse = await this.contract.registerWithPermit(permit.owner, permit.deadline, permit.v, permit.r, permit.s,
|
418
|
+
const txRegisterResponse = await this.contract.registerWithPermit(permit.owner, permit.deadline, permit.v, permit.r, permit.s, identity.IDCommitmentBigInt, this.rateLimit, idCommitmentsToErase.map((id) => BigNumber.from(id)));
|
445
419
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
446
420
|
const memberRegistered = txRegisterReceipt.events?.find((event) => event.event === "MembershipRegistered");
|
447
421
|
if (!memberRegistered || !memberRegistered.args) {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { hmac } from '../../../node_modules/@noble/hashes/esm/hmac.js';
|
2
|
-
import { sha256 } from '../../../node_modules/@noble/hashes/esm/
|
2
|
+
import { sha256 } from '../../../node_modules/@noble/hashes/esm/sha256.js';
|
3
|
+
import '../../interfaces/dist/light_push_v3.js';
|
3
4
|
import '../../interfaces/dist/protocols.js';
|
4
5
|
import '../../interfaces/dist/connection_manager.js';
|
5
6
|
import '../../interfaces/dist/health_indicator.js';
|
@@ -20,7 +21,7 @@ import { RLNBaseContract } from './contract/rln_base_contract.js';
|
|
20
21
|
import { IdentityCredential } from './identity.js';
|
21
22
|
import { Keystore } from './keystore/keystore.js';
|
22
23
|
import { extractMetaMaskSigner } from './utils/metamask.js';
|
23
|
-
import {
|
24
|
+
import { buildBigIntFromUint8Array } from './utils/bytes.js';
|
24
25
|
import './utils/epoch.js';
|
25
26
|
|
26
27
|
const log = new Logger("waku:credentials");
|
@@ -95,7 +96,7 @@ class RLNCredentialsManager {
|
|
95
96
|
}
|
96
97
|
else {
|
97
98
|
log.info("Using local implementation to generate identity");
|
98
|
-
identity =
|
99
|
+
identity = this.generateSeededIdentityCredential(options.signature);
|
99
100
|
}
|
100
101
|
}
|
101
102
|
if (!identity) {
|
@@ -191,26 +192,24 @@ class RLNCredentialsManager {
|
|
191
192
|
* @param seed A string seed to generate the identity from
|
192
193
|
* @returns IdentityCredential
|
193
194
|
*/
|
194
|
-
|
195
|
+
generateSeededIdentityCredential(seed) {
|
195
196
|
log.info("Generating seeded identity credential");
|
196
197
|
// Convert the seed to bytes
|
197
198
|
const encoder = new TextEncoder();
|
198
199
|
const seedBytes = encoder.encode(seed);
|
199
200
|
// Generate deterministic values using HMAC-SHA256
|
200
201
|
// We use different context strings for each component to ensure they're different
|
201
|
-
const
|
202
|
-
const
|
203
|
-
|
204
|
-
const
|
205
|
-
const
|
206
|
-
//
|
207
|
-
|
208
|
-
|
209
|
-
const
|
210
|
-
const idSecretHashLE = switchEndianness(idSecretHashBE);
|
211
|
-
const idCommitmentLE = switchEndianness(idCommitmentBE);
|
202
|
+
const idTrapdoor = hmac(sha256, seedBytes, encoder.encode("IDTrapdoor"));
|
203
|
+
const idNullifier = hmac(sha256, seedBytes, encoder.encode("IDNullifier"));
|
204
|
+
// Generate IDSecretHash as a hash of IDTrapdoor and IDNullifier
|
205
|
+
const combinedBytes = new Uint8Array([...idTrapdoor, ...idNullifier]);
|
206
|
+
const idSecretHash = sha256(combinedBytes);
|
207
|
+
// Generate IDCommitment as a hash of IDSecretHash
|
208
|
+
const idCommitment = sha256(idSecretHash);
|
209
|
+
// Convert IDCommitment to BigInt
|
210
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
|
212
211
|
log.info("Successfully generated identity credential");
|
213
|
-
return new IdentityCredential(
|
212
|
+
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
214
213
|
}
|
215
214
|
}
|
216
215
|
|
@@ -1,16 +1,18 @@
|
|
1
|
+
import { buildBigIntFromUint8Array } from './utils/bytes.js';
|
2
|
+
import './utils/epoch.js';
|
3
|
+
|
1
4
|
class IdentityCredential {
|
2
5
|
IDTrapdoor;
|
3
6
|
IDNullifier;
|
4
7
|
IDSecretHash;
|
5
8
|
IDCommitment;
|
6
|
-
|
7
|
-
|
8
|
-
*/
|
9
|
-
constructor(IDTrapdoor, IDNullifier, IDSecretHash, IDCommitment) {
|
9
|
+
IDCommitmentBigInt;
|
10
|
+
constructor(IDTrapdoor, IDNullifier, IDSecretHash, IDCommitment, IDCommitmentBigInt) {
|
10
11
|
this.IDTrapdoor = IDTrapdoor;
|
11
12
|
this.IDNullifier = IDNullifier;
|
12
13
|
this.IDSecretHash = IDSecretHash;
|
13
14
|
this.IDCommitment = IDCommitment;
|
15
|
+
this.IDCommitmentBigInt = IDCommitmentBigInt;
|
14
16
|
}
|
15
17
|
static fromBytes(memKeys) {
|
16
18
|
if (memKeys.length < 128) {
|
@@ -20,7 +22,8 @@ class IdentityCredential {
|
|
20
22
|
const idNullifier = memKeys.subarray(32, 64);
|
21
23
|
const idSecretHash = memKeys.subarray(64, 96);
|
22
24
|
const idCommitment = memKeys.subarray(96, 128);
|
23
|
-
|
25
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
|
26
|
+
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
24
27
|
}
|
25
28
|
}
|
26
29
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import '../../../../node_modules/@chainsafe/bls-keystore/lib/index.js';
|
2
|
+
import '../../../interfaces/dist/light_push_v3.js';
|
2
3
|
import '../../../interfaces/dist/protocols.js';
|
3
4
|
import '../../../interfaces/dist/connection_manager.js';
|
4
5
|
import '../../../interfaces/dist/health_indicator.js';
|
@@ -17,6 +18,7 @@ import { Logger } from '../../../utils/dist/logger/index.js';
|
|
17
18
|
import { sha256 } from '../../../../node_modules/ethereum-cryptography/esm/sha256.js';
|
18
19
|
import { bytesToUtf8 } from '../../../../node_modules/ethereum-cryptography/esm/utils.js';
|
19
20
|
import _ from '../../../../node_modules/lodash/lodash.js';
|
21
|
+
import { buildBigIntFromUint8Array } from '../utils/bytes.js';
|
20
22
|
import { keccak256Checksum, decryptEipKeystore } from './cipher.js';
|
21
23
|
import { isKeystoreValid, isCredentialValid } from './schema_validator.js';
|
22
24
|
import { __exports as lib } from '../../../../_virtual/index.js';
|
@@ -163,16 +165,14 @@ class Keystore {
|
|
163
165
|
try {
|
164
166
|
const str = bytesToUtf8(bytes);
|
165
167
|
const obj = JSON.parse(str);
|
166
|
-
|
167
|
-
const idTrapdoorLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", []));
|
168
|
-
const idNullifierLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", []));
|
169
|
-
const idSecretHashLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []));
|
168
|
+
// TODO: add runtime validation of nwaku credentials
|
170
169
|
return {
|
171
170
|
identity: {
|
172
|
-
IDCommitment:
|
173
|
-
IDTrapdoor:
|
174
|
-
IDNullifier:
|
175
|
-
|
171
|
+
IDCommitment: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", [])),
|
172
|
+
IDTrapdoor: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", [])),
|
173
|
+
IDNullifier: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", [])),
|
174
|
+
IDCommitmentBigInt: buildBigIntFromUint8Array(Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", []))),
|
175
|
+
IDSecretHash: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []))
|
176
176
|
},
|
177
177
|
membership: {
|
178
178
|
treeIndex: _.get(obj, "treeIndex"),
|
@@ -209,16 +209,13 @@ class Keystore {
|
|
209
209
|
// follows nwaku implementation
|
210
210
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L98
|
211
211
|
static fromIdentityToBytes(options) {
|
212
|
-
function toLittleEndian(bytes) {
|
213
|
-
return new Uint8Array(bytes).reverse();
|
214
|
-
}
|
215
212
|
return utf8ToBytes(JSON.stringify({
|
216
213
|
treeIndex: options.membership.treeIndex,
|
217
214
|
identityCredential: {
|
218
|
-
idCommitment: Array.from(
|
219
|
-
idNullifier: Array.from(
|
220
|
-
idSecretHash: Array.from(
|
221
|
-
idTrapdoor: Array.from(
|
215
|
+
idCommitment: Array.from(options.identity.IDCommitment),
|
216
|
+
idNullifier: Array.from(options.identity.IDNullifier),
|
217
|
+
idSecretHash: Array.from(options.identity.IDSecretHash),
|
218
|
+
idTrapdoor: Array.from(options.identity.IDTrapdoor)
|
222
219
|
},
|
223
220
|
membershipContract: {
|
224
221
|
chainId: options.membership.chainId,
|
@@ -1,8 +1,10 @@
|
|
1
1
|
import { Version } from '../../core/dist/lib/message/version_0.js';
|
2
2
|
import '../../core/dist/lib/filter/filter.js';
|
3
3
|
import '../../core/dist/lib/light_push/light_push.js';
|
4
|
+
import '../../core/dist/lib/light_push/light_push_v3.js';
|
4
5
|
import '../../core/dist/lib/store/store.js';
|
5
6
|
import '../../core/dist/lib/connection_manager/connection_manager.js';
|
7
|
+
import '../../interfaces/dist/light_push_v3.js';
|
6
8
|
import '../../interfaces/dist/protocols.js';
|
7
9
|
import '../../interfaces/dist/connection_manager.js';
|
8
10
|
import '../../interfaces/dist/health_indicator.js';
|
@@ -1,8 +1,10 @@
|
|
1
1
|
import { createEncoder, createDecoder } from '../../core/dist/lib/message/version_0.js';
|
2
2
|
import '../../core/dist/lib/filter/filter.js';
|
3
3
|
import '../../core/dist/lib/light_push/light_push.js';
|
4
|
+
import '../../core/dist/lib/light_push/light_push_v3.js';
|
4
5
|
import '../../core/dist/lib/store/store.js';
|
5
6
|
import '../../core/dist/lib/connection_manager/connection_manager.js';
|
7
|
+
import '../../interfaces/dist/light_push_v3.js';
|
6
8
|
import '../../interfaces/dist/protocols.js';
|
7
9
|
import '../../interfaces/dist/connection_manager.js';
|
8
10
|
import '../../interfaces/dist/health_indicator.js';
|