@waku/core 0.0.26 → 0.0.28-070b625.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/bundle/{base_protocol-pDODy0G6.js → base_protocol-D0Zdzb-v.js} +134 -89
  3. package/bundle/{browser-mTOOnVZp.js → browser-DoQRY-an.js} +518 -712
  4. package/bundle/{index-cmONXM-V.js → index-BJwgMx4y.js} +116 -88
  5. package/bundle/index.js +2967 -21667
  6. package/bundle/lib/base_protocol.js +3 -3
  7. package/bundle/lib/message/version_0.js +3 -3
  8. package/bundle/lib/predefined_bootstrap_nodes.js +17 -17
  9. package/bundle/version_0-C6o0DvNW.js +4055 -0
  10. package/dist/.tsbuildinfo +1 -1
  11. package/dist/index.d.ts +3 -6
  12. package/dist/index.js +3 -6
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/base_protocol.d.ts +15 -13
  15. package/dist/lib/base_protocol.js +35 -22
  16. package/dist/lib/base_protocol.js.map +1 -1
  17. package/dist/lib/connection_manager.d.ts +2 -2
  18. package/dist/lib/connection_manager.js +16 -6
  19. package/dist/lib/connection_manager.js.map +1 -1
  20. package/dist/lib/filter/index.d.ts +1 -1
  21. package/dist/lib/filter/index.js +144 -82
  22. package/dist/lib/filter/index.js.map +1 -1
  23. package/dist/lib/filterPeers.d.ts +8 -5
  24. package/dist/lib/filterPeers.js +12 -5
  25. package/dist/lib/filterPeers.js.map +1 -1
  26. package/dist/lib/keep_alive_manager.d.ts +2 -3
  27. package/dist/lib/keep_alive_manager.js.map +1 -1
  28. package/dist/lib/light_push/index.d.ts +12 -2
  29. package/dist/lib/light_push/index.js +80 -80
  30. package/dist/lib/light_push/index.js.map +1 -1
  31. package/dist/lib/message/version_0.js +1 -1
  32. package/dist/lib/message/version_0.js.map +1 -1
  33. package/dist/lib/metadata/index.d.ts +2 -2
  34. package/dist/lib/metadata/index.js +58 -16
  35. package/dist/lib/metadata/index.js.map +1 -1
  36. package/dist/lib/predefined_bootstrap_nodes.d.ts +11 -11
  37. package/dist/lib/predefined_bootstrap_nodes.js +16 -16
  38. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
  39. package/dist/lib/store/history_rpc.js +1 -1
  40. package/dist/lib/store/history_rpc.js.map +1 -1
  41. package/dist/lib/store/index.d.ts +14 -6
  42. package/dist/lib/store/index.js +51 -235
  43. package/dist/lib/store/index.js.map +1 -1
  44. package/dist/lib/stream_manager.d.ts +2 -2
  45. package/dist/lib/stream_manager.js.map +1 -1
  46. package/dist/lib/wait_for_remote_peer.d.ts +1 -1
  47. package/dist/lib/wait_for_remote_peer.js +42 -10
  48. package/dist/lib/wait_for_remote_peer.js.map +1 -1
  49. package/package.json +1 -127
  50. package/src/index.ts +3 -7
  51. package/src/lib/base_protocol.ts +57 -37
  52. package/src/lib/connection_manager.ts +17 -10
  53. package/src/lib/filter/index.ts +234 -136
  54. package/src/lib/filterPeers.ts +15 -7
  55. package/src/lib/keep_alive_manager.ts +2 -3
  56. package/src/lib/light_push/index.ts +104 -124
  57. package/src/lib/metadata/index.ts +92 -30
  58. package/src/lib/predefined_bootstrap_nodes.ts +22 -22
  59. package/src/lib/store/index.ts +79 -344
  60. package/src/lib/stream_manager.ts +2 -3
  61. package/src/lib/wait_for_remote_peer.ts +68 -12
  62. package/bundle/version_0-LQTFNC7k.js +0 -5008
  63. package/dist/lib/waku.d.ts +0 -57
  64. package/dist/lib/waku.js +0 -130
  65. package/dist/lib/waku.js.map +0 -1
  66. package/src/lib/waku.ts +0 -214
@@ -0,0 +1,4055 @@
1
+ import { a as allocUnsafe, h as fromString, d as alloc$1, L as Logger, i as determinePubsubTopic } from './index-BJwgMx4y.js';
2
+
3
+ /* eslint-disable no-fallthrough */
4
+ const N1 = Math.pow(2, 7);
5
+ const N2 = Math.pow(2, 14);
6
+ const N3 = Math.pow(2, 21);
7
+ const N4 = Math.pow(2, 28);
8
+ const N5 = Math.pow(2, 35);
9
+ const N6 = Math.pow(2, 42);
10
+ const N7 = Math.pow(2, 49);
11
+ /** Most significant bit of a byte */
12
+ const MSB = 0x80;
13
+ /** Rest of the bits in a byte */
14
+ const REST = 0x7f;
15
+ function encodingLength(value) {
16
+ if (value < N1) {
17
+ return 1;
18
+ }
19
+ if (value < N2) {
20
+ return 2;
21
+ }
22
+ if (value < N3) {
23
+ return 3;
24
+ }
25
+ if (value < N4) {
26
+ return 4;
27
+ }
28
+ if (value < N5) {
29
+ return 5;
30
+ }
31
+ if (value < N6) {
32
+ return 6;
33
+ }
34
+ if (value < N7) {
35
+ return 7;
36
+ }
37
+ if (Number.MAX_SAFE_INTEGER != null && value > Number.MAX_SAFE_INTEGER) {
38
+ throw new RangeError('Could not encode varint');
39
+ }
40
+ return 8;
41
+ }
42
+ function encodeUint8Array(value, buf, offset = 0) {
43
+ switch (encodingLength(value)) {
44
+ case 8: {
45
+ buf[offset++] = (value & 0xFF) | MSB;
46
+ value /= 128;
47
+ }
48
+ case 7: {
49
+ buf[offset++] = (value & 0xFF) | MSB;
50
+ value /= 128;
51
+ }
52
+ case 6: {
53
+ buf[offset++] = (value & 0xFF) | MSB;
54
+ value /= 128;
55
+ }
56
+ case 5: {
57
+ buf[offset++] = (value & 0xFF) | MSB;
58
+ value /= 128;
59
+ }
60
+ case 4: {
61
+ buf[offset++] = (value & 0xFF) | MSB;
62
+ value >>>= 7;
63
+ }
64
+ case 3: {
65
+ buf[offset++] = (value & 0xFF) | MSB;
66
+ value >>>= 7;
67
+ }
68
+ case 2: {
69
+ buf[offset++] = (value & 0xFF) | MSB;
70
+ value >>>= 7;
71
+ }
72
+ case 1: {
73
+ buf[offset++] = (value & 0xFF);
74
+ value >>>= 7;
75
+ break;
76
+ }
77
+ default: throw new Error('unreachable');
78
+ }
79
+ return buf;
80
+ }
81
+ function encodeUint8ArrayList(value, buf, offset = 0) {
82
+ switch (encodingLength(value)) {
83
+ case 8: {
84
+ buf.set(offset++, (value & 0xFF) | MSB);
85
+ value /= 128;
86
+ }
87
+ case 7: {
88
+ buf.set(offset++, (value & 0xFF) | MSB);
89
+ value /= 128;
90
+ }
91
+ case 6: {
92
+ buf.set(offset++, (value & 0xFF) | MSB);
93
+ value /= 128;
94
+ }
95
+ case 5: {
96
+ buf.set(offset++, (value & 0xFF) | MSB);
97
+ value /= 128;
98
+ }
99
+ case 4: {
100
+ buf.set(offset++, (value & 0xFF) | MSB);
101
+ value >>>= 7;
102
+ }
103
+ case 3: {
104
+ buf.set(offset++, (value & 0xFF) | MSB);
105
+ value >>>= 7;
106
+ }
107
+ case 2: {
108
+ buf.set(offset++, (value & 0xFF) | MSB);
109
+ value >>>= 7;
110
+ }
111
+ case 1: {
112
+ buf.set(offset++, (value & 0xFF));
113
+ value >>>= 7;
114
+ break;
115
+ }
116
+ default: throw new Error('unreachable');
117
+ }
118
+ return buf;
119
+ }
120
+ function decodeUint8Array(buf, offset) {
121
+ let b = buf[offset];
122
+ let res = 0;
123
+ res += b & REST;
124
+ if (b < MSB) {
125
+ return res;
126
+ }
127
+ b = buf[offset + 1];
128
+ res += (b & REST) << 7;
129
+ if (b < MSB) {
130
+ return res;
131
+ }
132
+ b = buf[offset + 2];
133
+ res += (b & REST) << 14;
134
+ if (b < MSB) {
135
+ return res;
136
+ }
137
+ b = buf[offset + 3];
138
+ res += (b & REST) << 21;
139
+ if (b < MSB) {
140
+ return res;
141
+ }
142
+ b = buf[offset + 4];
143
+ res += (b & REST) * N4;
144
+ if (b < MSB) {
145
+ return res;
146
+ }
147
+ b = buf[offset + 5];
148
+ res += (b & REST) * N5;
149
+ if (b < MSB) {
150
+ return res;
151
+ }
152
+ b = buf[offset + 6];
153
+ res += (b & REST) * N6;
154
+ if (b < MSB) {
155
+ return res;
156
+ }
157
+ b = buf[offset + 7];
158
+ res += (b & REST) * N7;
159
+ if (b < MSB) {
160
+ return res;
161
+ }
162
+ throw new RangeError('Could not decode varint');
163
+ }
164
+ function decodeUint8ArrayList(buf, offset) {
165
+ let b = buf.get(offset);
166
+ let res = 0;
167
+ res += b & REST;
168
+ if (b < MSB) {
169
+ return res;
170
+ }
171
+ b = buf.get(offset + 1);
172
+ res += (b & REST) << 7;
173
+ if (b < MSB) {
174
+ return res;
175
+ }
176
+ b = buf.get(offset + 2);
177
+ res += (b & REST) << 14;
178
+ if (b < MSB) {
179
+ return res;
180
+ }
181
+ b = buf.get(offset + 3);
182
+ res += (b & REST) << 21;
183
+ if (b < MSB) {
184
+ return res;
185
+ }
186
+ b = buf.get(offset + 4);
187
+ res += (b & REST) * N4;
188
+ if (b < MSB) {
189
+ return res;
190
+ }
191
+ b = buf.get(offset + 5);
192
+ res += (b & REST) * N5;
193
+ if (b < MSB) {
194
+ return res;
195
+ }
196
+ b = buf.get(offset + 6);
197
+ res += (b & REST) * N6;
198
+ if (b < MSB) {
199
+ return res;
200
+ }
201
+ b = buf.get(offset + 7);
202
+ res += (b & REST) * N7;
203
+ if (b < MSB) {
204
+ return res;
205
+ }
206
+ throw new RangeError('Could not decode varint');
207
+ }
208
+ function encode(value, buf, offset = 0) {
209
+ if (buf == null) {
210
+ buf = allocUnsafe(encodingLength(value));
211
+ }
212
+ if (buf instanceof Uint8Array) {
213
+ return encodeUint8Array(value, buf, offset);
214
+ }
215
+ else {
216
+ return encodeUint8ArrayList(value, buf, offset);
217
+ }
218
+ }
219
+ function decode(buf, offset = 0) {
220
+ if (buf instanceof Uint8Array) {
221
+ return decodeUint8Array(buf, offset);
222
+ }
223
+ else {
224
+ return decodeUint8ArrayList(buf, offset);
225
+ }
226
+ }
227
+
228
+ const f32 = new Float32Array([-0]);
229
+ const f8b = new Uint8Array(f32.buffer);
230
+ /**
231
+ * Writes a 32 bit float to a buffer using little endian byte order
232
+ */
233
+ function writeFloatLE(val, buf, pos) {
234
+ f32[0] = val;
235
+ buf[pos] = f8b[0];
236
+ buf[pos + 1] = f8b[1];
237
+ buf[pos + 2] = f8b[2];
238
+ buf[pos + 3] = f8b[3];
239
+ }
240
+ /**
241
+ * Reads a 32 bit float from a buffer using little endian byte order
242
+ */
243
+ function readFloatLE(buf, pos) {
244
+ f8b[0] = buf[pos];
245
+ f8b[1] = buf[pos + 1];
246
+ f8b[2] = buf[pos + 2];
247
+ f8b[3] = buf[pos + 3];
248
+ return f32[0];
249
+ }
250
+ const f64 = new Float64Array([-0]);
251
+ const d8b = new Uint8Array(f64.buffer);
252
+ /**
253
+ * Writes a 64 bit double to a buffer using little endian byte order
254
+ */
255
+ function writeDoubleLE(val, buf, pos) {
256
+ f64[0] = val;
257
+ buf[pos] = d8b[0];
258
+ buf[pos + 1] = d8b[1];
259
+ buf[pos + 2] = d8b[2];
260
+ buf[pos + 3] = d8b[3];
261
+ buf[pos + 4] = d8b[4];
262
+ buf[pos + 5] = d8b[5];
263
+ buf[pos + 6] = d8b[6];
264
+ buf[pos + 7] = d8b[7];
265
+ }
266
+ /**
267
+ * Reads a 64 bit double from a buffer using little endian byte order
268
+ */
269
+ function readDoubleLE(buf, pos) {
270
+ d8b[0] = buf[pos];
271
+ d8b[1] = buf[pos + 1];
272
+ d8b[2] = buf[pos + 2];
273
+ d8b[3] = buf[pos + 3];
274
+ d8b[4] = buf[pos + 4];
275
+ d8b[5] = buf[pos + 5];
276
+ d8b[6] = buf[pos + 6];
277
+ d8b[7] = buf[pos + 7];
278
+ return f64[0];
279
+ }
280
+
281
+ // the largest BigInt we can safely downcast to a Number
282
+ const MAX_SAFE_NUMBER_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
283
+ const MIN_SAFE_NUMBER_INTEGER = BigInt(Number.MIN_SAFE_INTEGER);
284
+ /**
285
+ * Constructs new long bits.
286
+ *
287
+ * @classdesc Helper class for working with the low and high bits of a 64 bit value.
288
+ * @memberof util
289
+ * @function Object() { [native code] }
290
+ * @param {number} lo - Low 32 bits, unsigned
291
+ * @param {number} hi - High 32 bits, unsigned
292
+ */
293
+ class LongBits {
294
+ lo;
295
+ hi;
296
+ constructor(lo, hi) {
297
+ // note that the casts below are theoretically unnecessary as of today, but older statically
298
+ // generated converter code might still call the ctor with signed 32bits. kept for compat.
299
+ /**
300
+ * Low bits
301
+ */
302
+ this.lo = lo | 0;
303
+ /**
304
+ * High bits
305
+ */
306
+ this.hi = hi | 0;
307
+ }
308
+ /**
309
+ * Converts this long bits to a possibly unsafe JavaScript number
310
+ */
311
+ toNumber(unsigned = false) {
312
+ if (!unsigned && (this.hi >>> 31) > 0) {
313
+ const lo = ~this.lo + 1 >>> 0;
314
+ let hi = ~this.hi >>> 0;
315
+ if (lo === 0) {
316
+ hi = hi + 1 >>> 0;
317
+ }
318
+ return -(lo + hi * 4294967296);
319
+ }
320
+ return this.lo + this.hi * 4294967296;
321
+ }
322
+ /**
323
+ * Converts this long bits to a bigint
324
+ */
325
+ toBigInt(unsigned = false) {
326
+ if (unsigned) {
327
+ return BigInt(this.lo >>> 0) + (BigInt(this.hi >>> 0) << 32n);
328
+ }
329
+ if ((this.hi >>> 31) !== 0) {
330
+ const lo = ~this.lo + 1 >>> 0;
331
+ let hi = ~this.hi >>> 0;
332
+ if (lo === 0) {
333
+ hi = hi + 1 >>> 0;
334
+ }
335
+ return -(BigInt(lo) + (BigInt(hi) << 32n));
336
+ }
337
+ return BigInt(this.lo >>> 0) + (BigInt(this.hi >>> 0) << 32n);
338
+ }
339
+ /**
340
+ * Converts this long bits to a string
341
+ */
342
+ toString(unsigned = false) {
343
+ return this.toBigInt(unsigned).toString();
344
+ }
345
+ /**
346
+ * Zig-zag encodes this long bits
347
+ */
348
+ zzEncode() {
349
+ const mask = this.hi >> 31;
350
+ this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
351
+ this.lo = (this.lo << 1 ^ mask) >>> 0;
352
+ return this;
353
+ }
354
+ /**
355
+ * Zig-zag decodes this long bits
356
+ */
357
+ zzDecode() {
358
+ const mask = -(this.lo & 1);
359
+ this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
360
+ this.hi = (this.hi >>> 1 ^ mask) >>> 0;
361
+ return this;
362
+ }
363
+ /**
364
+ * Calculates the length of this longbits when encoded as a varint.
365
+ */
366
+ length() {
367
+ const part0 = this.lo;
368
+ const part1 = (this.lo >>> 28 | this.hi << 4) >>> 0;
369
+ const part2 = this.hi >>> 24;
370
+ return part2 === 0
371
+ ? part1 === 0
372
+ ? part0 < 16384
373
+ ? part0 < 128 ? 1 : 2
374
+ : part0 < 2097152 ? 3 : 4
375
+ : part1 < 16384
376
+ ? part1 < 128 ? 5 : 6
377
+ : part1 < 2097152 ? 7 : 8
378
+ : part2 < 128 ? 9 : 10;
379
+ }
380
+ /**
381
+ * Constructs new long bits from the specified number
382
+ */
383
+ static fromBigInt(value) {
384
+ if (value === 0n) {
385
+ return zero;
386
+ }
387
+ if (value < MAX_SAFE_NUMBER_INTEGER && value > MIN_SAFE_NUMBER_INTEGER) {
388
+ return this.fromNumber(Number(value));
389
+ }
390
+ const negative = value < 0n;
391
+ if (negative) {
392
+ value = -value;
393
+ }
394
+ let hi = value >> 32n;
395
+ let lo = value - (hi << 32n);
396
+ if (negative) {
397
+ hi = ~hi | 0n;
398
+ lo = ~lo | 0n;
399
+ if (++lo > TWO_32) {
400
+ lo = 0n;
401
+ if (++hi > TWO_32) {
402
+ hi = 0n;
403
+ }
404
+ }
405
+ }
406
+ return new LongBits(Number(lo), Number(hi));
407
+ }
408
+ /**
409
+ * Constructs new long bits from the specified number
410
+ */
411
+ static fromNumber(value) {
412
+ if (value === 0) {
413
+ return zero;
414
+ }
415
+ const sign = value < 0;
416
+ if (sign) {
417
+ value = -value;
418
+ }
419
+ let lo = value >>> 0;
420
+ let hi = (value - lo) / 4294967296 >>> 0;
421
+ if (sign) {
422
+ hi = ~hi >>> 0;
423
+ lo = ~lo >>> 0;
424
+ if (++lo > 4294967295) {
425
+ lo = 0;
426
+ if (++hi > 4294967295) {
427
+ hi = 0;
428
+ }
429
+ }
430
+ }
431
+ return new LongBits(lo, hi);
432
+ }
433
+ /**
434
+ * Constructs new long bits from a number, long or string
435
+ */
436
+ static from(value) {
437
+ if (typeof value === 'number') {
438
+ return LongBits.fromNumber(value);
439
+ }
440
+ if (typeof value === 'bigint') {
441
+ return LongBits.fromBigInt(value);
442
+ }
443
+ if (typeof value === 'string') {
444
+ return LongBits.fromBigInt(BigInt(value));
445
+ }
446
+ return value.low != null || value.high != null ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
447
+ }
448
+ }
449
+ const zero = new LongBits(0, 0);
450
+ zero.toBigInt = function () { return 0n; };
451
+ zero.zzEncode = zero.zzDecode = function () { return this; };
452
+ zero.length = function () { return 1; };
453
+ const TWO_32 = 4294967296n;
454
+
455
+ /**
456
+ * Calculates the UTF8 byte length of a string
457
+ */
458
+ function length(string) {
459
+ let len = 0;
460
+ let c = 0;
461
+ for (let i = 0; i < string.length; ++i) {
462
+ c = string.charCodeAt(i);
463
+ if (c < 128) {
464
+ len += 1;
465
+ }
466
+ else if (c < 2048) {
467
+ len += 2;
468
+ }
469
+ else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
470
+ ++i;
471
+ len += 4;
472
+ }
473
+ else {
474
+ len += 3;
475
+ }
476
+ }
477
+ return len;
478
+ }
479
+ /**
480
+ * Reads UTF8 bytes as a string
481
+ */
482
+ function read(buffer, start, end) {
483
+ const len = end - start;
484
+ if (len < 1) {
485
+ return '';
486
+ }
487
+ let parts;
488
+ const chunk = [];
489
+ let i = 0; // char offset
490
+ let t; // temporary
491
+ while (start < end) {
492
+ t = buffer[start++];
493
+ if (t < 128) {
494
+ chunk[i++] = t;
495
+ }
496
+ else if (t > 191 && t < 224) {
497
+ chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
498
+ }
499
+ else if (t > 239 && t < 365) {
500
+ t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
501
+ chunk[i++] = 0xD800 + (t >> 10);
502
+ chunk[i++] = 0xDC00 + (t & 1023);
503
+ }
504
+ else {
505
+ chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
506
+ }
507
+ if (i > 8191) {
508
+ (parts ?? (parts = [])).push(String.fromCharCode.apply(String, chunk));
509
+ i = 0;
510
+ }
511
+ }
512
+ if (parts != null) {
513
+ if (i > 0) {
514
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
515
+ }
516
+ return parts.join('');
517
+ }
518
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
519
+ }
520
+ /**
521
+ * Writes a string as UTF8 bytes
522
+ */
523
+ function write(string, buffer, offset) {
524
+ const start = offset;
525
+ let c1; // character 1
526
+ let c2; // character 2
527
+ for (let i = 0; i < string.length; ++i) {
528
+ c1 = string.charCodeAt(i);
529
+ if (c1 < 128) {
530
+ buffer[offset++] = c1;
531
+ }
532
+ else if (c1 < 2048) {
533
+ buffer[offset++] = c1 >> 6 | 192;
534
+ buffer[offset++] = c1 & 63 | 128;
535
+ }
536
+ else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
537
+ c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
538
+ ++i;
539
+ buffer[offset++] = c1 >> 18 | 240;
540
+ buffer[offset++] = c1 >> 12 & 63 | 128;
541
+ buffer[offset++] = c1 >> 6 & 63 | 128;
542
+ buffer[offset++] = c1 & 63 | 128;
543
+ }
544
+ else {
545
+ buffer[offset++] = c1 >> 12 | 224;
546
+ buffer[offset++] = c1 >> 6 & 63 | 128;
547
+ buffer[offset++] = c1 & 63 | 128;
548
+ }
549
+ }
550
+ return offset - start;
551
+ }
552
+
553
+ /* istanbul ignore next */
554
+ function indexOutOfRange(reader, writeLength) {
555
+ return RangeError(`index out of range: ${reader.pos} + ${writeLength ?? 1} > ${reader.len}`);
556
+ }
557
+ function readFixed32End(buf, end) {
558
+ return (buf[end - 4] |
559
+ buf[end - 3] << 8 |
560
+ buf[end - 2] << 16 |
561
+ buf[end - 1] << 24) >>> 0;
562
+ }
563
+ /**
564
+ * Constructs a new reader instance using the specified buffer.
565
+ */
566
+ class Uint8ArrayReader {
567
+ buf;
568
+ pos;
569
+ len;
570
+ _slice = Uint8Array.prototype.subarray;
571
+ constructor(buffer) {
572
+ /**
573
+ * Read buffer
574
+ */
575
+ this.buf = buffer;
576
+ /**
577
+ * Read buffer position
578
+ */
579
+ this.pos = 0;
580
+ /**
581
+ * Read buffer length
582
+ */
583
+ this.len = buffer.length;
584
+ }
585
+ /**
586
+ * Reads a varint as an unsigned 32 bit value
587
+ */
588
+ uint32() {
589
+ let value = 4294967295;
590
+ value = (this.buf[this.pos] & 127) >>> 0;
591
+ if (this.buf[this.pos++] < 128)
592
+ return value;
593
+ value = (value | (this.buf[this.pos] & 127) << 7) >>> 0;
594
+ if (this.buf[this.pos++] < 128)
595
+ return value;
596
+ value = (value | (this.buf[this.pos] & 127) << 14) >>> 0;
597
+ if (this.buf[this.pos++] < 128)
598
+ return value;
599
+ value = (value | (this.buf[this.pos] & 127) << 21) >>> 0;
600
+ if (this.buf[this.pos++] < 128)
601
+ return value;
602
+ value = (value | (this.buf[this.pos] & 15) << 28) >>> 0;
603
+ if (this.buf[this.pos++] < 128)
604
+ return value;
605
+ if ((this.pos += 5) > this.len) {
606
+ this.pos = this.len;
607
+ throw indexOutOfRange(this, 10);
608
+ }
609
+ return value;
610
+ }
611
+ /**
612
+ * Reads a varint as a signed 32 bit value
613
+ */
614
+ int32() {
615
+ return this.uint32() | 0;
616
+ }
617
+ /**
618
+ * Reads a zig-zag encoded varint as a signed 32 bit value
619
+ */
620
+ sint32() {
621
+ const value = this.uint32();
622
+ return value >>> 1 ^ -(value & 1) | 0;
623
+ }
624
+ /**
625
+ * Reads a varint as a boolean
626
+ */
627
+ bool() {
628
+ return this.uint32() !== 0;
629
+ }
630
+ /**
631
+ * Reads fixed 32 bits as an unsigned 32 bit integer
632
+ */
633
+ fixed32() {
634
+ if (this.pos + 4 > this.len) {
635
+ throw indexOutOfRange(this, 4);
636
+ }
637
+ const res = readFixed32End(this.buf, this.pos += 4);
638
+ return res;
639
+ }
640
+ /**
641
+ * Reads fixed 32 bits as a signed 32 bit integer
642
+ */
643
+ sfixed32() {
644
+ if (this.pos + 4 > this.len) {
645
+ throw indexOutOfRange(this, 4);
646
+ }
647
+ const res = readFixed32End(this.buf, this.pos += 4) | 0;
648
+ return res;
649
+ }
650
+ /**
651
+ * Reads a float (32 bit) as a number
652
+ */
653
+ float() {
654
+ if (this.pos + 4 > this.len) {
655
+ throw indexOutOfRange(this, 4);
656
+ }
657
+ const value = readFloatLE(this.buf, this.pos);
658
+ this.pos += 4;
659
+ return value;
660
+ }
661
+ /**
662
+ * Reads a double (64 bit float) as a number
663
+ */
664
+ double() {
665
+ /* istanbul ignore if */
666
+ if (this.pos + 8 > this.len) {
667
+ throw indexOutOfRange(this, 4);
668
+ }
669
+ const value = readDoubleLE(this.buf, this.pos);
670
+ this.pos += 8;
671
+ return value;
672
+ }
673
+ /**
674
+ * Reads a sequence of bytes preceded by its length as a varint
675
+ */
676
+ bytes() {
677
+ const length = this.uint32();
678
+ const start = this.pos;
679
+ const end = this.pos + length;
680
+ /* istanbul ignore if */
681
+ if (end > this.len) {
682
+ throw indexOutOfRange(this, length);
683
+ }
684
+ this.pos += length;
685
+ return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
686
+ ? new Uint8Array(0)
687
+ : this.buf.subarray(start, end);
688
+ }
689
+ /**
690
+ * Reads a string preceded by its byte length as a varint
691
+ */
692
+ string() {
693
+ const bytes = this.bytes();
694
+ return read(bytes, 0, bytes.length);
695
+ }
696
+ /**
697
+ * Skips the specified number of bytes if specified, otherwise skips a varint
698
+ */
699
+ skip(length) {
700
+ if (typeof length === 'number') {
701
+ /* istanbul ignore if */
702
+ if (this.pos + length > this.len) {
703
+ throw indexOutOfRange(this, length);
704
+ }
705
+ this.pos += length;
706
+ }
707
+ else {
708
+ do {
709
+ /* istanbul ignore if */
710
+ if (this.pos >= this.len) {
711
+ throw indexOutOfRange(this);
712
+ }
713
+ } while ((this.buf[this.pos++] & 128) !== 0);
714
+ }
715
+ return this;
716
+ }
717
+ /**
718
+ * Skips the next element of the specified wire type
719
+ */
720
+ skipType(wireType) {
721
+ switch (wireType) {
722
+ case 0:
723
+ this.skip();
724
+ break;
725
+ case 1:
726
+ this.skip(8);
727
+ break;
728
+ case 2:
729
+ this.skip(this.uint32());
730
+ break;
731
+ case 3:
732
+ while ((wireType = this.uint32() & 7) !== 4) {
733
+ this.skipType(wireType);
734
+ }
735
+ break;
736
+ case 5:
737
+ this.skip(4);
738
+ break;
739
+ /* istanbul ignore next */
740
+ default:
741
+ throw Error(`invalid wire type ${wireType} at offset ${this.pos}`);
742
+ }
743
+ return this;
744
+ }
745
+ readLongVarint() {
746
+ // tends to deopt with local vars for octet etc.
747
+ const bits = new LongBits(0, 0);
748
+ let i = 0;
749
+ if (this.len - this.pos > 4) { // fast route (lo)
750
+ for (; i < 4; ++i) {
751
+ // 1st..4th
752
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
753
+ if (this.buf[this.pos++] < 128) {
754
+ return bits;
755
+ }
756
+ }
757
+ // 5th
758
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
759
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
760
+ if (this.buf[this.pos++] < 128) {
761
+ return bits;
762
+ }
763
+ i = 0;
764
+ }
765
+ else {
766
+ for (; i < 3; ++i) {
767
+ /* istanbul ignore if */
768
+ if (this.pos >= this.len) {
769
+ throw indexOutOfRange(this);
770
+ }
771
+ // 1st..3th
772
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
773
+ if (this.buf[this.pos++] < 128) {
774
+ return bits;
775
+ }
776
+ }
777
+ // 4th
778
+ bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
779
+ return bits;
780
+ }
781
+ if (this.len - this.pos > 4) { // fast route (hi)
782
+ for (; i < 5; ++i) {
783
+ // 6th..10th
784
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
785
+ if (this.buf[this.pos++] < 128) {
786
+ return bits;
787
+ }
788
+ }
789
+ }
790
+ else {
791
+ for (; i < 5; ++i) {
792
+ if (this.pos >= this.len) {
793
+ throw indexOutOfRange(this);
794
+ }
795
+ // 6th..10th
796
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
797
+ if (this.buf[this.pos++] < 128) {
798
+ return bits;
799
+ }
800
+ }
801
+ }
802
+ throw Error('invalid varint encoding');
803
+ }
804
+ readFixed64() {
805
+ if (this.pos + 8 > this.len) {
806
+ throw indexOutOfRange(this, 8);
807
+ }
808
+ const lo = readFixed32End(this.buf, this.pos += 4);
809
+ const hi = readFixed32End(this.buf, this.pos += 4);
810
+ return new LongBits(lo, hi);
811
+ }
812
+ /**
813
+ * Reads a varint as a signed 64 bit value
814
+ */
815
+ int64() {
816
+ return this.readLongVarint().toBigInt();
817
+ }
818
+ /**
819
+ * Reads a varint as a signed 64 bit value returned as a possibly unsafe
820
+ * JavaScript number
821
+ */
822
+ int64Number() {
823
+ return this.readLongVarint().toNumber();
824
+ }
825
+ /**
826
+ * Reads a varint as a signed 64 bit value returned as a string
827
+ */
828
+ int64String() {
829
+ return this.readLongVarint().toString();
830
+ }
831
+ /**
832
+ * Reads a varint as an unsigned 64 bit value
833
+ */
834
+ uint64() {
835
+ return this.readLongVarint().toBigInt(true);
836
+ }
837
+ /**
838
+ * Reads a varint as an unsigned 64 bit value returned as a possibly unsafe
839
+ * JavaScript number
840
+ */
841
+ uint64Number() {
842
+ const value = decodeUint8Array(this.buf, this.pos);
843
+ this.pos += encodingLength(value);
844
+ return value;
845
+ }
846
+ /**
847
+ * Reads a varint as an unsigned 64 bit value returned as a string
848
+ */
849
+ uint64String() {
850
+ return this.readLongVarint().toString(true);
851
+ }
852
+ /**
853
+ * Reads a zig-zag encoded varint as a signed 64 bit value
854
+ */
855
+ sint64() {
856
+ return this.readLongVarint().zzDecode().toBigInt();
857
+ }
858
+ /**
859
+ * Reads a zig-zag encoded varint as a signed 64 bit value returned as a
860
+ * possibly unsafe JavaScript number
861
+ */
862
+ sint64Number() {
863
+ return this.readLongVarint().zzDecode().toNumber();
864
+ }
865
+ /**
866
+ * Reads a zig-zag encoded varint as a signed 64 bit value returned as a
867
+ * string
868
+ */
869
+ sint64String() {
870
+ return this.readLongVarint().zzDecode().toString();
871
+ }
872
+ /**
873
+ * Reads fixed 64 bits
874
+ */
875
+ fixed64() {
876
+ return this.readFixed64().toBigInt();
877
+ }
878
+ /**
879
+ * Reads fixed 64 bits returned as a possibly unsafe JavaScript number
880
+ */
881
+ fixed64Number() {
882
+ return this.readFixed64().toNumber();
883
+ }
884
+ /**
885
+ * Reads fixed 64 bits returned as a string
886
+ */
887
+ fixed64String() {
888
+ return this.readFixed64().toString();
889
+ }
890
+ /**
891
+ * Reads zig-zag encoded fixed 64 bits
892
+ */
893
+ sfixed64() {
894
+ return this.readFixed64().toBigInt();
895
+ }
896
+ /**
897
+ * Reads zig-zag encoded fixed 64 bits returned as a possibly unsafe
898
+ * JavaScript number
899
+ */
900
+ sfixed64Number() {
901
+ return this.readFixed64().toNumber();
902
+ }
903
+ /**
904
+ * Reads zig-zag encoded fixed 64 bits returned as a string
905
+ */
906
+ sfixed64String() {
907
+ return this.readFixed64().toString();
908
+ }
909
+ }
910
+ function createReader(buf) {
911
+ return new Uint8ArrayReader(buf instanceof Uint8Array ? buf : buf.subarray());
912
+ }
913
+
914
+ function decodeMessage(buf, codec, opts) {
915
+ const reader = createReader(buf);
916
+ return codec.decode(reader, undefined, opts);
917
+ }
918
+
919
+ /**
920
+ * A general purpose buffer pool
921
+ */
922
+ function pool(size) {
923
+ const SIZE = size ?? 8192;
924
+ const MAX = SIZE >>> 1;
925
+ let slab;
926
+ let offset = SIZE;
927
+ return function poolAlloc(size) {
928
+ if (size < 1 || size > MAX) {
929
+ return allocUnsafe(size);
930
+ }
931
+ if (offset + size > SIZE) {
932
+ slab = allocUnsafe(SIZE);
933
+ offset = 0;
934
+ }
935
+ const buf = slab.subarray(offset, offset += size);
936
+ if ((offset & 7) !== 0) {
937
+ // align to 32 bit
938
+ offset = (offset | 7) + 1;
939
+ }
940
+ return buf;
941
+ };
942
+ }
943
+
944
+ /**
945
+ * Constructs a new writer operation instance.
946
+ *
947
+ * @classdesc Scheduled writer operation
948
+ */
949
+ class Op {
950
+ /**
951
+ * Function to call
952
+ */
953
+ fn;
954
+ /**
955
+ * Value byte length
956
+ */
957
+ len;
958
+ /**
959
+ * Next operation
960
+ */
961
+ next;
962
+ /**
963
+ * Value to write
964
+ */
965
+ val;
966
+ constructor(fn, len, val) {
967
+ this.fn = fn;
968
+ this.len = len;
969
+ this.next = undefined;
970
+ this.val = val; // type varies
971
+ }
972
+ }
973
+ /* istanbul ignore next */
974
+ function noop() { } // eslint-disable-line no-empty-function
975
+ /**
976
+ * Constructs a new writer state instance
977
+ */
978
+ class State {
979
+ /**
980
+ * Current head
981
+ */
982
+ head;
983
+ /**
984
+ * Current tail
985
+ */
986
+ tail;
987
+ /**
988
+ * Current buffer length
989
+ */
990
+ len;
991
+ /**
992
+ * Next state
993
+ */
994
+ next;
995
+ constructor(writer) {
996
+ this.head = writer.head;
997
+ this.tail = writer.tail;
998
+ this.len = writer.len;
999
+ this.next = writer.states;
1000
+ }
1001
+ }
1002
+ const bufferPool = pool();
1003
+ /**
1004
+ * Allocates a buffer of the specified size
1005
+ */
1006
+ function alloc(size) {
1007
+ if (globalThis.Buffer != null) {
1008
+ return allocUnsafe(size);
1009
+ }
1010
+ return bufferPool(size);
1011
+ }
1012
+ /**
1013
+ * When a value is written, the writer calculates its byte length and puts it into a linked
1014
+ * list of operations to perform when finish() is called. This both allows us to allocate
1015
+ * buffers of the exact required size and reduces the amount of work we have to do compared
1016
+ * to first calculating over objects and then encoding over objects. In our case, the encoding
1017
+ * part is just a linked list walk calling operations with already prepared values.
1018
+ */
1019
+ class Uint8ArrayWriter {
1020
+ /**
1021
+ * Current length
1022
+ */
1023
+ len;
1024
+ /**
1025
+ * Operations head
1026
+ */
1027
+ head;
1028
+ /**
1029
+ * Operations tail
1030
+ */
1031
+ tail;
1032
+ /**
1033
+ * Linked forked states
1034
+ */
1035
+ states;
1036
+ constructor() {
1037
+ this.len = 0;
1038
+ this.head = new Op(noop, 0, 0);
1039
+ this.tail = this.head;
1040
+ this.states = null;
1041
+ }
1042
+ /**
1043
+ * Pushes a new operation to the queue
1044
+ */
1045
+ _push(fn, len, val) {
1046
+ this.tail = this.tail.next = new Op(fn, len, val);
1047
+ this.len += len;
1048
+ return this;
1049
+ }
1050
+ /**
1051
+ * Writes an unsigned 32 bit value as a varint
1052
+ */
1053
+ uint32(value) {
1054
+ // here, the call to this.push has been inlined and a varint specific Op subclass is used.
1055
+ // uint32 is by far the most frequently used operation and benefits significantly from this.
1056
+ this.len += (this.tail = this.tail.next = new VarintOp((value = value >>> 0) <
1057
+ 128
1058
+ ? 1
1059
+ : value < 16384
1060
+ ? 2
1061
+ : value < 2097152
1062
+ ? 3
1063
+ : value < 268435456
1064
+ ? 4
1065
+ : 5, value)).len;
1066
+ return this;
1067
+ }
1068
+ /**
1069
+ * Writes a signed 32 bit value as a varint`
1070
+ */
1071
+ int32(value) {
1072
+ return value < 0
1073
+ ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
1074
+ : this.uint32(value);
1075
+ }
1076
+ /**
1077
+ * Writes a 32 bit value as a varint, zig-zag encoded
1078
+ */
1079
+ sint32(value) {
1080
+ return this.uint32((value << 1 ^ value >> 31) >>> 0);
1081
+ }
1082
+ /**
1083
+ * Writes an unsigned 64 bit value as a varint
1084
+ */
1085
+ uint64(value) {
1086
+ const bits = LongBits.fromBigInt(value);
1087
+ return this._push(writeVarint64, bits.length(), bits);
1088
+ }
1089
+ /**
1090
+ * Writes an unsigned 64 bit value as a varint
1091
+ */
1092
+ uint64Number(value) {
1093
+ return this._push(encodeUint8Array, encodingLength(value), value);
1094
+ }
1095
+ /**
1096
+ * Writes an unsigned 64 bit value as a varint
1097
+ */
1098
+ uint64String(value) {
1099
+ return this.uint64(BigInt(value));
1100
+ }
1101
+ /**
1102
+ * Writes a signed 64 bit value as a varint
1103
+ */
1104
+ int64(value) {
1105
+ return this.uint64(value);
1106
+ }
1107
+ /**
1108
+ * Writes a signed 64 bit value as a varint
1109
+ */
1110
+ int64Number(value) {
1111
+ return this.uint64Number(value);
1112
+ }
1113
+ /**
1114
+ * Writes a signed 64 bit value as a varint
1115
+ */
1116
+ int64String(value) {
1117
+ return this.uint64String(value);
1118
+ }
1119
+ /**
1120
+ * Writes a signed 64 bit value as a varint, zig-zag encoded
1121
+ */
1122
+ sint64(value) {
1123
+ const bits = LongBits.fromBigInt(value).zzEncode();
1124
+ return this._push(writeVarint64, bits.length(), bits);
1125
+ }
1126
+ /**
1127
+ * Writes a signed 64 bit value as a varint, zig-zag encoded
1128
+ */
1129
+ sint64Number(value) {
1130
+ const bits = LongBits.fromNumber(value).zzEncode();
1131
+ return this._push(writeVarint64, bits.length(), bits);
1132
+ }
1133
+ /**
1134
+ * Writes a signed 64 bit value as a varint, zig-zag encoded
1135
+ */
1136
+ sint64String(value) {
1137
+ return this.sint64(BigInt(value));
1138
+ }
1139
+ /**
1140
+ * Writes a boolish value as a varint
1141
+ */
1142
+ bool(value) {
1143
+ return this._push(writeByte, 1, value ? 1 : 0);
1144
+ }
1145
+ /**
1146
+ * Writes an unsigned 32 bit value as fixed 32 bits
1147
+ */
1148
+ fixed32(value) {
1149
+ return this._push(writeFixed32, 4, value >>> 0);
1150
+ }
1151
+ /**
1152
+ * Writes a signed 32 bit value as fixed 32 bits
1153
+ */
1154
+ sfixed32(value) {
1155
+ return this.fixed32(value);
1156
+ }
1157
+ /**
1158
+ * Writes an unsigned 64 bit value as fixed 64 bits
1159
+ */
1160
+ fixed64(value) {
1161
+ const bits = LongBits.fromBigInt(value);
1162
+ return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
1163
+ }
1164
+ /**
1165
+ * Writes an unsigned 64 bit value as fixed 64 bits
1166
+ */
1167
+ fixed64Number(value) {
1168
+ const bits = LongBits.fromNumber(value);
1169
+ return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
1170
+ }
1171
+ /**
1172
+ * Writes an unsigned 64 bit value as fixed 64 bits
1173
+ */
1174
+ fixed64String(value) {
1175
+ return this.fixed64(BigInt(value));
1176
+ }
1177
+ /**
1178
+ * Writes a signed 64 bit value as fixed 64 bits
1179
+ */
1180
+ sfixed64(value) {
1181
+ return this.fixed64(value);
1182
+ }
1183
+ /**
1184
+ * Writes a signed 64 bit value as fixed 64 bits
1185
+ */
1186
+ sfixed64Number(value) {
1187
+ return this.fixed64Number(value);
1188
+ }
1189
+ /**
1190
+ * Writes a signed 64 bit value as fixed 64 bits
1191
+ */
1192
+ sfixed64String(value) {
1193
+ return this.fixed64String(value);
1194
+ }
1195
+ /**
1196
+ * Writes a float (32 bit)
1197
+ */
1198
+ float(value) {
1199
+ return this._push(writeFloatLE, 4, value);
1200
+ }
1201
+ /**
1202
+ * Writes a double (64 bit float).
1203
+ *
1204
+ * @function
1205
+ * @param {number} value - Value to write
1206
+ * @returns {Writer} `this`
1207
+ */
1208
+ double(value) {
1209
+ return this._push(writeDoubleLE, 8, value);
1210
+ }
1211
+ /**
1212
+ * Writes a sequence of bytes
1213
+ */
1214
+ bytes(value) {
1215
+ const len = value.length >>> 0;
1216
+ if (len === 0) {
1217
+ return this._push(writeByte, 1, 0);
1218
+ }
1219
+ return this.uint32(len)._push(writeBytes, len, value);
1220
+ }
1221
+ /**
1222
+ * Writes a string
1223
+ */
1224
+ string(value) {
1225
+ const len = length(value);
1226
+ return len !== 0
1227
+ ? this.uint32(len)._push(write, len, value)
1228
+ : this._push(writeByte, 1, 0);
1229
+ }
1230
+ /**
1231
+ * Forks this writer's state by pushing it to a stack.
1232
+ * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
1233
+ */
1234
+ fork() {
1235
+ this.states = new State(this);
1236
+ this.head = this.tail = new Op(noop, 0, 0);
1237
+ this.len = 0;
1238
+ return this;
1239
+ }
1240
+ /**
1241
+ * Resets this instance to the last state
1242
+ */
1243
+ reset() {
1244
+ if (this.states != null) {
1245
+ this.head = this.states.head;
1246
+ this.tail = this.states.tail;
1247
+ this.len = this.states.len;
1248
+ this.states = this.states.next;
1249
+ }
1250
+ else {
1251
+ this.head = this.tail = new Op(noop, 0, 0);
1252
+ this.len = 0;
1253
+ }
1254
+ return this;
1255
+ }
1256
+ /**
1257
+ * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
1258
+ */
1259
+ ldelim() {
1260
+ const head = this.head;
1261
+ const tail = this.tail;
1262
+ const len = this.len;
1263
+ this.reset().uint32(len);
1264
+ if (len !== 0) {
1265
+ this.tail.next = head.next; // skip noop
1266
+ this.tail = tail;
1267
+ this.len += len;
1268
+ }
1269
+ return this;
1270
+ }
1271
+ /**
1272
+ * Finishes the write operation
1273
+ */
1274
+ finish() {
1275
+ let head = this.head.next; // skip noop
1276
+ const buf = alloc(this.len);
1277
+ let pos = 0;
1278
+ while (head != null) {
1279
+ head.fn(head.val, buf, pos);
1280
+ pos += head.len;
1281
+ head = head.next;
1282
+ }
1283
+ // this.head = this.tail = null;
1284
+ return buf;
1285
+ }
1286
+ }
1287
+ function writeByte(val, buf, pos) {
1288
+ buf[pos] = val & 255;
1289
+ }
1290
+ function writeVarint32(val, buf, pos) {
1291
+ while (val > 127) {
1292
+ buf[pos++] = val & 127 | 128;
1293
+ val >>>= 7;
1294
+ }
1295
+ buf[pos] = val;
1296
+ }
1297
+ /**
1298
+ * Constructs a new varint writer operation instance.
1299
+ *
1300
+ * @classdesc Scheduled varint writer operation
1301
+ */
1302
+ class VarintOp extends Op {
1303
+ next;
1304
+ constructor(len, val) {
1305
+ super(writeVarint32, len, val);
1306
+ this.next = undefined;
1307
+ }
1308
+ }
1309
+ function writeVarint64(val, buf, pos) {
1310
+ while (val.hi !== 0) {
1311
+ buf[pos++] = val.lo & 127 | 128;
1312
+ val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;
1313
+ val.hi >>>= 7;
1314
+ }
1315
+ while (val.lo > 127) {
1316
+ buf[pos++] = val.lo & 127 | 128;
1317
+ val.lo = val.lo >>> 7;
1318
+ }
1319
+ buf[pos++] = val.lo;
1320
+ }
1321
+ function writeFixed32(val, buf, pos) {
1322
+ buf[pos] = val & 255;
1323
+ buf[pos + 1] = val >>> 8 & 255;
1324
+ buf[pos + 2] = val >>> 16 & 255;
1325
+ buf[pos + 3] = val >>> 24;
1326
+ }
1327
+ function writeBytes(val, buf, pos) {
1328
+ buf.set(val, pos);
1329
+ }
1330
+ if (globalThis.Buffer != null) {
1331
+ Uint8ArrayWriter.prototype.bytes = function (value) {
1332
+ const len = value.length >>> 0;
1333
+ this.uint32(len);
1334
+ if (len > 0) {
1335
+ this._push(writeBytesBuffer, len, value);
1336
+ }
1337
+ return this;
1338
+ };
1339
+ Uint8ArrayWriter.prototype.string = function (value) {
1340
+ const len = globalThis.Buffer.byteLength(value);
1341
+ this.uint32(len);
1342
+ if (len > 0) {
1343
+ this._push(writeStringBuffer, len, value);
1344
+ }
1345
+ return this;
1346
+ };
1347
+ }
1348
+ function writeBytesBuffer(val, buf, pos) {
1349
+ buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
1350
+ // also works for plain array values
1351
+ }
1352
+ function writeStringBuffer(val, buf, pos) {
1353
+ if (val.length < 40) {
1354
+ // plain js is faster for short strings (probably due to redundant assertions)
1355
+ write(val, buf, pos);
1356
+ // @ts-expect-error buf isn't a Uint8Array?
1357
+ }
1358
+ else if (buf.utf8Write != null) {
1359
+ // @ts-expect-error buf isn't a Uint8Array?
1360
+ buf.utf8Write(val, pos);
1361
+ }
1362
+ else {
1363
+ buf.set(fromString(val), pos);
1364
+ }
1365
+ }
1366
+ /**
1367
+ * Creates a new writer
1368
+ */
1369
+ function createWriter() {
1370
+ return new Uint8ArrayWriter();
1371
+ }
1372
+
1373
+ function encodeMessage(message, codec) {
1374
+ const w = createWriter();
1375
+ codec.encode(message, w, {
1376
+ lengthDelimited: false
1377
+ });
1378
+ return w.finish();
1379
+ }
1380
+
1381
+ // https://developers.google.com/protocol-buffers/docs/encoding#structure
1382
+ var CODEC_TYPES;
1383
+ (function (CODEC_TYPES) {
1384
+ CODEC_TYPES[CODEC_TYPES["VARINT"] = 0] = "VARINT";
1385
+ CODEC_TYPES[CODEC_TYPES["BIT64"] = 1] = "BIT64";
1386
+ CODEC_TYPES[CODEC_TYPES["LENGTH_DELIMITED"] = 2] = "LENGTH_DELIMITED";
1387
+ CODEC_TYPES[CODEC_TYPES["START_GROUP"] = 3] = "START_GROUP";
1388
+ CODEC_TYPES[CODEC_TYPES["END_GROUP"] = 4] = "END_GROUP";
1389
+ CODEC_TYPES[CODEC_TYPES["BIT32"] = 5] = "BIT32";
1390
+ })(CODEC_TYPES || (CODEC_TYPES = {}));
1391
+ function createCodec(name, type, encode, decode) {
1392
+ return {
1393
+ name,
1394
+ type,
1395
+ encode,
1396
+ decode
1397
+ };
1398
+ }
1399
+
1400
+ function enumeration(v) {
1401
+ function findValue(val) {
1402
+ // Use the reverse mapping to look up the enum key for the stored value
1403
+ // https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
1404
+ if (v[val.toString()] == null) {
1405
+ throw new Error('Invalid enum value');
1406
+ }
1407
+ return v[val];
1408
+ }
1409
+ const encode = function enumEncode(val, writer) {
1410
+ const enumValue = findValue(val);
1411
+ writer.int32(enumValue);
1412
+ };
1413
+ const decode = function enumDecode(reader) {
1414
+ const val = reader.int32();
1415
+ return findValue(val);
1416
+ };
1417
+ // @ts-expect-error yeah yeah
1418
+ return createCodec('enum', CODEC_TYPES.VARINT, encode, decode);
1419
+ }
1420
+
1421
+ function message$1(encode, decode) {
1422
+ return createCodec('message', CODEC_TYPES.LENGTH_DELIMITED, encode, decode);
1423
+ }
1424
+
1425
+ /**
1426
+ * @packageDocumentation
1427
+ *
1428
+ * This module contains serialization/deserialization code used when encoding/decoding protobufs.
1429
+ *
1430
+ * It should be declared as a dependency of your project:
1431
+ *
1432
+ * ```console
1433
+ * npm i protons-runtime
1434
+ * ```
1435
+ */
1436
+ class CodeError extends Error {
1437
+ code;
1438
+ constructor(message, code, options) {
1439
+ super(message, options);
1440
+ this.code = code;
1441
+ }
1442
+ }
1443
+
1444
+ /* eslint-disable import/export */
1445
+ /* eslint-disable complexity */
1446
+ /* eslint-disable @typescript-eslint/no-namespace */
1447
+ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
1448
+ /* eslint-disable @typescript-eslint/no-empty-interface */
1449
+ var RateLimitProof$4;
1450
+ (function (RateLimitProof) {
1451
+ let _codec;
1452
+ RateLimitProof.codec = () => {
1453
+ if (_codec == null) {
1454
+ _codec = message$1((obj, w, opts = {}) => {
1455
+ if (opts.lengthDelimited !== false) {
1456
+ w.fork();
1457
+ }
1458
+ if ((obj.proof != null && obj.proof.byteLength > 0)) {
1459
+ w.uint32(10);
1460
+ w.bytes(obj.proof);
1461
+ }
1462
+ if ((obj.merkleRoot != null && obj.merkleRoot.byteLength > 0)) {
1463
+ w.uint32(18);
1464
+ w.bytes(obj.merkleRoot);
1465
+ }
1466
+ if ((obj.epoch != null && obj.epoch.byteLength > 0)) {
1467
+ w.uint32(26);
1468
+ w.bytes(obj.epoch);
1469
+ }
1470
+ if ((obj.shareX != null && obj.shareX.byteLength > 0)) {
1471
+ w.uint32(34);
1472
+ w.bytes(obj.shareX);
1473
+ }
1474
+ if ((obj.shareY != null && obj.shareY.byteLength > 0)) {
1475
+ w.uint32(42);
1476
+ w.bytes(obj.shareY);
1477
+ }
1478
+ if ((obj.nullifier != null && obj.nullifier.byteLength > 0)) {
1479
+ w.uint32(50);
1480
+ w.bytes(obj.nullifier);
1481
+ }
1482
+ if ((obj.rlnIdentifier != null && obj.rlnIdentifier.byteLength > 0)) {
1483
+ w.uint32(58);
1484
+ w.bytes(obj.rlnIdentifier);
1485
+ }
1486
+ if (opts.lengthDelimited !== false) {
1487
+ w.ldelim();
1488
+ }
1489
+ }, (reader, length, opts = {}) => {
1490
+ const obj = {
1491
+ proof: alloc$1(0),
1492
+ merkleRoot: alloc$1(0),
1493
+ epoch: alloc$1(0),
1494
+ shareX: alloc$1(0),
1495
+ shareY: alloc$1(0),
1496
+ nullifier: alloc$1(0),
1497
+ rlnIdentifier: alloc$1(0)
1498
+ };
1499
+ const end = length == null ? reader.len : reader.pos + length;
1500
+ while (reader.pos < end) {
1501
+ const tag = reader.uint32();
1502
+ switch (tag >>> 3) {
1503
+ case 1: {
1504
+ obj.proof = reader.bytes();
1505
+ break;
1506
+ }
1507
+ case 2: {
1508
+ obj.merkleRoot = reader.bytes();
1509
+ break;
1510
+ }
1511
+ case 3: {
1512
+ obj.epoch = reader.bytes();
1513
+ break;
1514
+ }
1515
+ case 4: {
1516
+ obj.shareX = reader.bytes();
1517
+ break;
1518
+ }
1519
+ case 5: {
1520
+ obj.shareY = reader.bytes();
1521
+ break;
1522
+ }
1523
+ case 6: {
1524
+ obj.nullifier = reader.bytes();
1525
+ break;
1526
+ }
1527
+ case 7: {
1528
+ obj.rlnIdentifier = reader.bytes();
1529
+ break;
1530
+ }
1531
+ default: {
1532
+ reader.skipType(tag & 7);
1533
+ break;
1534
+ }
1535
+ }
1536
+ }
1537
+ return obj;
1538
+ });
1539
+ }
1540
+ return _codec;
1541
+ };
1542
+ RateLimitProof.encode = (obj) => {
1543
+ return encodeMessage(obj, RateLimitProof.codec());
1544
+ };
1545
+ RateLimitProof.decode = (buf, opts) => {
1546
+ return decodeMessage(buf, RateLimitProof.codec(), opts);
1547
+ };
1548
+ })(RateLimitProof$4 || (RateLimitProof$4 = {}));
1549
+ var WakuMessage$4;
1550
+ (function (WakuMessage) {
1551
+ let _codec;
1552
+ WakuMessage.codec = () => {
1553
+ if (_codec == null) {
1554
+ _codec = message$1((obj, w, opts = {}) => {
1555
+ if (opts.lengthDelimited !== false) {
1556
+ w.fork();
1557
+ }
1558
+ if ((obj.payload != null && obj.payload.byteLength > 0)) {
1559
+ w.uint32(10);
1560
+ w.bytes(obj.payload);
1561
+ }
1562
+ if ((obj.contentTopic != null && obj.contentTopic !== '')) {
1563
+ w.uint32(18);
1564
+ w.string(obj.contentTopic);
1565
+ }
1566
+ if (obj.version != null) {
1567
+ w.uint32(24);
1568
+ w.uint32(obj.version);
1569
+ }
1570
+ if (obj.timestamp != null) {
1571
+ w.uint32(80);
1572
+ w.sint64(obj.timestamp);
1573
+ }
1574
+ if (obj.meta != null) {
1575
+ w.uint32(90);
1576
+ w.bytes(obj.meta);
1577
+ }
1578
+ if (obj.rateLimitProof != null) {
1579
+ w.uint32(170);
1580
+ RateLimitProof$4.codec().encode(obj.rateLimitProof, w);
1581
+ }
1582
+ if (obj.ephemeral != null) {
1583
+ w.uint32(248);
1584
+ w.bool(obj.ephemeral);
1585
+ }
1586
+ if (opts.lengthDelimited !== false) {
1587
+ w.ldelim();
1588
+ }
1589
+ }, (reader, length, opts = {}) => {
1590
+ const obj = {
1591
+ payload: alloc$1(0),
1592
+ contentTopic: ''
1593
+ };
1594
+ const end = length == null ? reader.len : reader.pos + length;
1595
+ while (reader.pos < end) {
1596
+ const tag = reader.uint32();
1597
+ switch (tag >>> 3) {
1598
+ case 1: {
1599
+ obj.payload = reader.bytes();
1600
+ break;
1601
+ }
1602
+ case 2: {
1603
+ obj.contentTopic = reader.string();
1604
+ break;
1605
+ }
1606
+ case 3: {
1607
+ obj.version = reader.uint32();
1608
+ break;
1609
+ }
1610
+ case 10: {
1611
+ obj.timestamp = reader.sint64();
1612
+ break;
1613
+ }
1614
+ case 11: {
1615
+ obj.meta = reader.bytes();
1616
+ break;
1617
+ }
1618
+ case 21: {
1619
+ obj.rateLimitProof = RateLimitProof$4.codec().decode(reader, reader.uint32(), {
1620
+ limits: opts.limits?.rateLimitProof
1621
+ });
1622
+ break;
1623
+ }
1624
+ case 31: {
1625
+ obj.ephemeral = reader.bool();
1626
+ break;
1627
+ }
1628
+ default: {
1629
+ reader.skipType(tag & 7);
1630
+ break;
1631
+ }
1632
+ }
1633
+ }
1634
+ return obj;
1635
+ });
1636
+ }
1637
+ return _codec;
1638
+ };
1639
+ WakuMessage.encode = (obj) => {
1640
+ return encodeMessage(obj, WakuMessage.codec());
1641
+ };
1642
+ WakuMessage.decode = (buf, opts) => {
1643
+ return decodeMessage(buf, WakuMessage.codec(), opts);
1644
+ };
1645
+ })(WakuMessage$4 || (WakuMessage$4 = {}));
1646
+
1647
+ var message = /*#__PURE__*/Object.freeze({
1648
+ __proto__: null,
1649
+ get RateLimitProof () { return RateLimitProof$4; },
1650
+ get WakuMessage () { return WakuMessage$4; }
1651
+ });
1652
+
1653
+ /* eslint-disable import/export */
1654
+ /* eslint-disable complexity */
1655
+ /* eslint-disable @typescript-eslint/no-namespace */
1656
+ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
1657
+ /* eslint-disable @typescript-eslint/no-empty-interface */
1658
+ var FilterRequest;
1659
+ (function (FilterRequest) {
1660
+ (function (ContentFilter) {
1661
+ let _codec;
1662
+ ContentFilter.codec = () => {
1663
+ if (_codec == null) {
1664
+ _codec = message$1((obj, w, opts = {}) => {
1665
+ if (opts.lengthDelimited !== false) {
1666
+ w.fork();
1667
+ }
1668
+ if ((obj.contentTopic != null && obj.contentTopic !== '')) {
1669
+ w.uint32(10);
1670
+ w.string(obj.contentTopic);
1671
+ }
1672
+ if (opts.lengthDelimited !== false) {
1673
+ w.ldelim();
1674
+ }
1675
+ }, (reader, length, opts = {}) => {
1676
+ const obj = {
1677
+ contentTopic: ''
1678
+ };
1679
+ const end = length == null ? reader.len : reader.pos + length;
1680
+ while (reader.pos < end) {
1681
+ const tag = reader.uint32();
1682
+ switch (tag >>> 3) {
1683
+ case 1: {
1684
+ obj.contentTopic = reader.string();
1685
+ break;
1686
+ }
1687
+ default: {
1688
+ reader.skipType(tag & 7);
1689
+ break;
1690
+ }
1691
+ }
1692
+ }
1693
+ return obj;
1694
+ });
1695
+ }
1696
+ return _codec;
1697
+ };
1698
+ ContentFilter.encode = (obj) => {
1699
+ return encodeMessage(obj, ContentFilter.codec());
1700
+ };
1701
+ ContentFilter.decode = (buf, opts) => {
1702
+ return decodeMessage(buf, ContentFilter.codec(), opts);
1703
+ };
1704
+ })(FilterRequest.ContentFilter || (FilterRequest.ContentFilter = {}));
1705
+ let _codec;
1706
+ FilterRequest.codec = () => {
1707
+ if (_codec == null) {
1708
+ _codec = message$1((obj, w, opts = {}) => {
1709
+ if (opts.lengthDelimited !== false) {
1710
+ w.fork();
1711
+ }
1712
+ if ((obj.subscribe != null && obj.subscribe !== false)) {
1713
+ w.uint32(8);
1714
+ w.bool(obj.subscribe);
1715
+ }
1716
+ if ((obj.topic != null && obj.topic !== '')) {
1717
+ w.uint32(18);
1718
+ w.string(obj.topic);
1719
+ }
1720
+ if (obj.contentFilters != null) {
1721
+ for (const value of obj.contentFilters) {
1722
+ w.uint32(26);
1723
+ FilterRequest.ContentFilter.codec().encode(value, w);
1724
+ }
1725
+ }
1726
+ if (opts.lengthDelimited !== false) {
1727
+ w.ldelim();
1728
+ }
1729
+ }, (reader, length, opts = {}) => {
1730
+ const obj = {
1731
+ subscribe: false,
1732
+ topic: '',
1733
+ contentFilters: []
1734
+ };
1735
+ const end = length == null ? reader.len : reader.pos + length;
1736
+ while (reader.pos < end) {
1737
+ const tag = reader.uint32();
1738
+ switch (tag >>> 3) {
1739
+ case 1: {
1740
+ obj.subscribe = reader.bool();
1741
+ break;
1742
+ }
1743
+ case 2: {
1744
+ obj.topic = reader.string();
1745
+ break;
1746
+ }
1747
+ case 3: {
1748
+ if (opts.limits?.contentFilters != null && obj.contentFilters.length === opts.limits.contentFilters) {
1749
+ throw new CodeError('decode error - map field "contentFilters" had too many elements', 'ERR_MAX_LENGTH');
1750
+ }
1751
+ obj.contentFilters.push(FilterRequest.ContentFilter.codec().decode(reader, reader.uint32(), {
1752
+ limits: opts.limits?.contentFilters$
1753
+ }));
1754
+ break;
1755
+ }
1756
+ default: {
1757
+ reader.skipType(tag & 7);
1758
+ break;
1759
+ }
1760
+ }
1761
+ }
1762
+ return obj;
1763
+ });
1764
+ }
1765
+ return _codec;
1766
+ };
1767
+ FilterRequest.encode = (obj) => {
1768
+ return encodeMessage(obj, FilterRequest.codec());
1769
+ };
1770
+ FilterRequest.decode = (buf, opts) => {
1771
+ return decodeMessage(buf, FilterRequest.codec(), opts);
1772
+ };
1773
+ })(FilterRequest || (FilterRequest = {}));
1774
+ var MessagePush$1;
1775
+ (function (MessagePush) {
1776
+ let _codec;
1777
+ MessagePush.codec = () => {
1778
+ if (_codec == null) {
1779
+ _codec = message$1((obj, w, opts = {}) => {
1780
+ if (opts.lengthDelimited !== false) {
1781
+ w.fork();
1782
+ }
1783
+ if (obj.messages != null) {
1784
+ for (const value of obj.messages) {
1785
+ w.uint32(10);
1786
+ WakuMessage$3.codec().encode(value, w);
1787
+ }
1788
+ }
1789
+ if (opts.lengthDelimited !== false) {
1790
+ w.ldelim();
1791
+ }
1792
+ }, (reader, length, opts = {}) => {
1793
+ const obj = {
1794
+ messages: []
1795
+ };
1796
+ const end = length == null ? reader.len : reader.pos + length;
1797
+ while (reader.pos < end) {
1798
+ const tag = reader.uint32();
1799
+ switch (tag >>> 3) {
1800
+ case 1: {
1801
+ if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) {
1802
+ throw new CodeError('decode error - map field "messages" had too many elements', 'ERR_MAX_LENGTH');
1803
+ }
1804
+ obj.messages.push(WakuMessage$3.codec().decode(reader, reader.uint32(), {
1805
+ limits: opts.limits?.messages$
1806
+ }));
1807
+ break;
1808
+ }
1809
+ default: {
1810
+ reader.skipType(tag & 7);
1811
+ break;
1812
+ }
1813
+ }
1814
+ }
1815
+ return obj;
1816
+ });
1817
+ }
1818
+ return _codec;
1819
+ };
1820
+ MessagePush.encode = (obj) => {
1821
+ return encodeMessage(obj, MessagePush.codec());
1822
+ };
1823
+ MessagePush.decode = (buf, opts) => {
1824
+ return decodeMessage(buf, MessagePush.codec(), opts);
1825
+ };
1826
+ })(MessagePush$1 || (MessagePush$1 = {}));
1827
+ var FilterRpc;
1828
+ (function (FilterRpc) {
1829
+ let _codec;
1830
+ FilterRpc.codec = () => {
1831
+ if (_codec == null) {
1832
+ _codec = message$1((obj, w, opts = {}) => {
1833
+ if (opts.lengthDelimited !== false) {
1834
+ w.fork();
1835
+ }
1836
+ if ((obj.requestId != null && obj.requestId !== '')) {
1837
+ w.uint32(10);
1838
+ w.string(obj.requestId);
1839
+ }
1840
+ if (obj.request != null) {
1841
+ w.uint32(18);
1842
+ FilterRequest.codec().encode(obj.request, w);
1843
+ }
1844
+ if (obj.push != null) {
1845
+ w.uint32(26);
1846
+ MessagePush$1.codec().encode(obj.push, w);
1847
+ }
1848
+ if (opts.lengthDelimited !== false) {
1849
+ w.ldelim();
1850
+ }
1851
+ }, (reader, length, opts = {}) => {
1852
+ const obj = {
1853
+ requestId: ''
1854
+ };
1855
+ const end = length == null ? reader.len : reader.pos + length;
1856
+ while (reader.pos < end) {
1857
+ const tag = reader.uint32();
1858
+ switch (tag >>> 3) {
1859
+ case 1: {
1860
+ obj.requestId = reader.string();
1861
+ break;
1862
+ }
1863
+ case 2: {
1864
+ obj.request = FilterRequest.codec().decode(reader, reader.uint32(), {
1865
+ limits: opts.limits?.request
1866
+ });
1867
+ break;
1868
+ }
1869
+ case 3: {
1870
+ obj.push = MessagePush$1.codec().decode(reader, reader.uint32(), {
1871
+ limits: opts.limits?.push
1872
+ });
1873
+ break;
1874
+ }
1875
+ default: {
1876
+ reader.skipType(tag & 7);
1877
+ break;
1878
+ }
1879
+ }
1880
+ }
1881
+ return obj;
1882
+ });
1883
+ }
1884
+ return _codec;
1885
+ };
1886
+ FilterRpc.encode = (obj) => {
1887
+ return encodeMessage(obj, FilterRpc.codec());
1888
+ };
1889
+ FilterRpc.decode = (buf, opts) => {
1890
+ return decodeMessage(buf, FilterRpc.codec(), opts);
1891
+ };
1892
+ })(FilterRpc || (FilterRpc = {}));
1893
+ var RateLimitProof$3;
1894
+ (function (RateLimitProof) {
1895
+ let _codec;
1896
+ RateLimitProof.codec = () => {
1897
+ if (_codec == null) {
1898
+ _codec = message$1((obj, w, opts = {}) => {
1899
+ if (opts.lengthDelimited !== false) {
1900
+ w.fork();
1901
+ }
1902
+ if ((obj.proof != null && obj.proof.byteLength > 0)) {
1903
+ w.uint32(10);
1904
+ w.bytes(obj.proof);
1905
+ }
1906
+ if ((obj.merkleRoot != null && obj.merkleRoot.byteLength > 0)) {
1907
+ w.uint32(18);
1908
+ w.bytes(obj.merkleRoot);
1909
+ }
1910
+ if ((obj.epoch != null && obj.epoch.byteLength > 0)) {
1911
+ w.uint32(26);
1912
+ w.bytes(obj.epoch);
1913
+ }
1914
+ if ((obj.shareX != null && obj.shareX.byteLength > 0)) {
1915
+ w.uint32(34);
1916
+ w.bytes(obj.shareX);
1917
+ }
1918
+ if ((obj.shareY != null && obj.shareY.byteLength > 0)) {
1919
+ w.uint32(42);
1920
+ w.bytes(obj.shareY);
1921
+ }
1922
+ if ((obj.nullifier != null && obj.nullifier.byteLength > 0)) {
1923
+ w.uint32(50);
1924
+ w.bytes(obj.nullifier);
1925
+ }
1926
+ if ((obj.rlnIdentifier != null && obj.rlnIdentifier.byteLength > 0)) {
1927
+ w.uint32(58);
1928
+ w.bytes(obj.rlnIdentifier);
1929
+ }
1930
+ if (opts.lengthDelimited !== false) {
1931
+ w.ldelim();
1932
+ }
1933
+ }, (reader, length, opts = {}) => {
1934
+ const obj = {
1935
+ proof: alloc$1(0),
1936
+ merkleRoot: alloc$1(0),
1937
+ epoch: alloc$1(0),
1938
+ shareX: alloc$1(0),
1939
+ shareY: alloc$1(0),
1940
+ nullifier: alloc$1(0),
1941
+ rlnIdentifier: alloc$1(0)
1942
+ };
1943
+ const end = length == null ? reader.len : reader.pos + length;
1944
+ while (reader.pos < end) {
1945
+ const tag = reader.uint32();
1946
+ switch (tag >>> 3) {
1947
+ case 1: {
1948
+ obj.proof = reader.bytes();
1949
+ break;
1950
+ }
1951
+ case 2: {
1952
+ obj.merkleRoot = reader.bytes();
1953
+ break;
1954
+ }
1955
+ case 3: {
1956
+ obj.epoch = reader.bytes();
1957
+ break;
1958
+ }
1959
+ case 4: {
1960
+ obj.shareX = reader.bytes();
1961
+ break;
1962
+ }
1963
+ case 5: {
1964
+ obj.shareY = reader.bytes();
1965
+ break;
1966
+ }
1967
+ case 6: {
1968
+ obj.nullifier = reader.bytes();
1969
+ break;
1970
+ }
1971
+ case 7: {
1972
+ obj.rlnIdentifier = reader.bytes();
1973
+ break;
1974
+ }
1975
+ default: {
1976
+ reader.skipType(tag & 7);
1977
+ break;
1978
+ }
1979
+ }
1980
+ }
1981
+ return obj;
1982
+ });
1983
+ }
1984
+ return _codec;
1985
+ };
1986
+ RateLimitProof.encode = (obj) => {
1987
+ return encodeMessage(obj, RateLimitProof.codec());
1988
+ };
1989
+ RateLimitProof.decode = (buf, opts) => {
1990
+ return decodeMessage(buf, RateLimitProof.codec(), opts);
1991
+ };
1992
+ })(RateLimitProof$3 || (RateLimitProof$3 = {}));
1993
+ var WakuMessage$3;
1994
+ (function (WakuMessage) {
1995
+ let _codec;
1996
+ WakuMessage.codec = () => {
1997
+ if (_codec == null) {
1998
+ _codec = message$1((obj, w, opts = {}) => {
1999
+ if (opts.lengthDelimited !== false) {
2000
+ w.fork();
2001
+ }
2002
+ if ((obj.payload != null && obj.payload.byteLength > 0)) {
2003
+ w.uint32(10);
2004
+ w.bytes(obj.payload);
2005
+ }
2006
+ if ((obj.contentTopic != null && obj.contentTopic !== '')) {
2007
+ w.uint32(18);
2008
+ w.string(obj.contentTopic);
2009
+ }
2010
+ if (obj.version != null) {
2011
+ w.uint32(24);
2012
+ w.uint32(obj.version);
2013
+ }
2014
+ if (obj.timestamp != null) {
2015
+ w.uint32(80);
2016
+ w.sint64(obj.timestamp);
2017
+ }
2018
+ if (obj.meta != null) {
2019
+ w.uint32(90);
2020
+ w.bytes(obj.meta);
2021
+ }
2022
+ if (obj.rateLimitProof != null) {
2023
+ w.uint32(170);
2024
+ RateLimitProof$3.codec().encode(obj.rateLimitProof, w);
2025
+ }
2026
+ if (obj.ephemeral != null) {
2027
+ w.uint32(248);
2028
+ w.bool(obj.ephemeral);
2029
+ }
2030
+ if (opts.lengthDelimited !== false) {
2031
+ w.ldelim();
2032
+ }
2033
+ }, (reader, length, opts = {}) => {
2034
+ const obj = {
2035
+ payload: alloc$1(0),
2036
+ contentTopic: ''
2037
+ };
2038
+ const end = length == null ? reader.len : reader.pos + length;
2039
+ while (reader.pos < end) {
2040
+ const tag = reader.uint32();
2041
+ switch (tag >>> 3) {
2042
+ case 1: {
2043
+ obj.payload = reader.bytes();
2044
+ break;
2045
+ }
2046
+ case 2: {
2047
+ obj.contentTopic = reader.string();
2048
+ break;
2049
+ }
2050
+ case 3: {
2051
+ obj.version = reader.uint32();
2052
+ break;
2053
+ }
2054
+ case 10: {
2055
+ obj.timestamp = reader.sint64();
2056
+ break;
2057
+ }
2058
+ case 11: {
2059
+ obj.meta = reader.bytes();
2060
+ break;
2061
+ }
2062
+ case 21: {
2063
+ obj.rateLimitProof = RateLimitProof$3.codec().decode(reader, reader.uint32(), {
2064
+ limits: opts.limits?.rateLimitProof
2065
+ });
2066
+ break;
2067
+ }
2068
+ case 31: {
2069
+ obj.ephemeral = reader.bool();
2070
+ break;
2071
+ }
2072
+ default: {
2073
+ reader.skipType(tag & 7);
2074
+ break;
2075
+ }
2076
+ }
2077
+ }
2078
+ return obj;
2079
+ });
2080
+ }
2081
+ return _codec;
2082
+ };
2083
+ WakuMessage.encode = (obj) => {
2084
+ return encodeMessage(obj, WakuMessage.codec());
2085
+ };
2086
+ WakuMessage.decode = (buf, opts) => {
2087
+ return decodeMessage(buf, WakuMessage.codec(), opts);
2088
+ };
2089
+ })(WakuMessage$3 || (WakuMessage$3 = {}));
2090
+
2091
+ /* eslint-disable import/export */
2092
+ /* eslint-disable complexity */
2093
+ /* eslint-disable @typescript-eslint/no-namespace */
2094
+ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
2095
+ /* eslint-disable @typescript-eslint/no-empty-interface */
2096
+ var TopicOnlyMessage;
2097
+ (function (TopicOnlyMessage) {
2098
+ let _codec;
2099
+ TopicOnlyMessage.codec = () => {
2100
+ if (_codec == null) {
2101
+ _codec = message$1((obj, w, opts = {}) => {
2102
+ if (opts.lengthDelimited !== false) {
2103
+ w.fork();
2104
+ }
2105
+ if ((obj.contentTopic != null && obj.contentTopic !== '')) {
2106
+ w.uint32(18);
2107
+ w.string(obj.contentTopic);
2108
+ }
2109
+ if (opts.lengthDelimited !== false) {
2110
+ w.ldelim();
2111
+ }
2112
+ }, (reader, length, opts = {}) => {
2113
+ const obj = {
2114
+ contentTopic: ''
2115
+ };
2116
+ const end = length == null ? reader.len : reader.pos + length;
2117
+ while (reader.pos < end) {
2118
+ const tag = reader.uint32();
2119
+ switch (tag >>> 3) {
2120
+ case 2: {
2121
+ obj.contentTopic = reader.string();
2122
+ break;
2123
+ }
2124
+ default: {
2125
+ reader.skipType(tag & 7);
2126
+ break;
2127
+ }
2128
+ }
2129
+ }
2130
+ return obj;
2131
+ });
2132
+ }
2133
+ return _codec;
2134
+ };
2135
+ TopicOnlyMessage.encode = (obj) => {
2136
+ return encodeMessage(obj, TopicOnlyMessage.codec());
2137
+ };
2138
+ TopicOnlyMessage.decode = (buf, opts) => {
2139
+ return decodeMessage(buf, TopicOnlyMessage.codec(), opts);
2140
+ };
2141
+ })(TopicOnlyMessage || (TopicOnlyMessage = {}));
2142
+
2143
+ /* eslint-disable import/export */
2144
+ /* eslint-disable complexity */
2145
+ /* eslint-disable @typescript-eslint/no-namespace */
2146
+ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
2147
+ /* eslint-disable @typescript-eslint/no-empty-interface */
2148
+ var FilterSubscribeRequest;
2149
+ (function (FilterSubscribeRequest) {
2150
+ let FilterSubscribeType;
2151
+ (function (FilterSubscribeType) {
2152
+ FilterSubscribeType["SUBSCRIBER_PING"] = "SUBSCRIBER_PING";
2153
+ FilterSubscribeType["SUBSCRIBE"] = "SUBSCRIBE";
2154
+ FilterSubscribeType["UNSUBSCRIBE"] = "UNSUBSCRIBE";
2155
+ FilterSubscribeType["UNSUBSCRIBE_ALL"] = "UNSUBSCRIBE_ALL";
2156
+ })(FilterSubscribeType = FilterSubscribeRequest.FilterSubscribeType || (FilterSubscribeRequest.FilterSubscribeType = {}));
2157
+ let __FilterSubscribeTypeValues;
2158
+ (function (__FilterSubscribeTypeValues) {
2159
+ __FilterSubscribeTypeValues[__FilterSubscribeTypeValues["SUBSCRIBER_PING"] = 0] = "SUBSCRIBER_PING";
2160
+ __FilterSubscribeTypeValues[__FilterSubscribeTypeValues["SUBSCRIBE"] = 1] = "SUBSCRIBE";
2161
+ __FilterSubscribeTypeValues[__FilterSubscribeTypeValues["UNSUBSCRIBE"] = 2] = "UNSUBSCRIBE";
2162
+ __FilterSubscribeTypeValues[__FilterSubscribeTypeValues["UNSUBSCRIBE_ALL"] = 3] = "UNSUBSCRIBE_ALL";
2163
+ })(__FilterSubscribeTypeValues || (__FilterSubscribeTypeValues = {}));
2164
+ (function (FilterSubscribeType) {
2165
+ FilterSubscribeType.codec = () => {
2166
+ return enumeration(__FilterSubscribeTypeValues);
2167
+ };
2168
+ })(FilterSubscribeType = FilterSubscribeRequest.FilterSubscribeType || (FilterSubscribeRequest.FilterSubscribeType = {}));
2169
+ let _codec;
2170
+ FilterSubscribeRequest.codec = () => {
2171
+ if (_codec == null) {
2172
+ _codec = message$1((obj, w, opts = {}) => {
2173
+ if (opts.lengthDelimited !== false) {
2174
+ w.fork();
2175
+ }
2176
+ if ((obj.requestId != null && obj.requestId !== '')) {
2177
+ w.uint32(10);
2178
+ w.string(obj.requestId);
2179
+ }
2180
+ if (obj.filterSubscribeType != null && __FilterSubscribeTypeValues[obj.filterSubscribeType] !== 0) {
2181
+ w.uint32(16);
2182
+ FilterSubscribeRequest.FilterSubscribeType.codec().encode(obj.filterSubscribeType, w);
2183
+ }
2184
+ if (obj.pubsubTopic != null) {
2185
+ w.uint32(82);
2186
+ w.string(obj.pubsubTopic);
2187
+ }
2188
+ if (obj.contentTopics != null) {
2189
+ for (const value of obj.contentTopics) {
2190
+ w.uint32(90);
2191
+ w.string(value);
2192
+ }
2193
+ }
2194
+ if (opts.lengthDelimited !== false) {
2195
+ w.ldelim();
2196
+ }
2197
+ }, (reader, length, opts = {}) => {
2198
+ const obj = {
2199
+ requestId: '',
2200
+ filterSubscribeType: FilterSubscribeType.SUBSCRIBER_PING,
2201
+ contentTopics: []
2202
+ };
2203
+ const end = length == null ? reader.len : reader.pos + length;
2204
+ while (reader.pos < end) {
2205
+ const tag = reader.uint32();
2206
+ switch (tag >>> 3) {
2207
+ case 1: {
2208
+ obj.requestId = reader.string();
2209
+ break;
2210
+ }
2211
+ case 2: {
2212
+ obj.filterSubscribeType = FilterSubscribeRequest.FilterSubscribeType.codec().decode(reader);
2213
+ break;
2214
+ }
2215
+ case 10: {
2216
+ obj.pubsubTopic = reader.string();
2217
+ break;
2218
+ }
2219
+ case 11: {
2220
+ if (opts.limits?.contentTopics != null && obj.contentTopics.length === opts.limits.contentTopics) {
2221
+ throw new CodeError('decode error - map field "contentTopics" had too many elements', 'ERR_MAX_LENGTH');
2222
+ }
2223
+ obj.contentTopics.push(reader.string());
2224
+ break;
2225
+ }
2226
+ default: {
2227
+ reader.skipType(tag & 7);
2228
+ break;
2229
+ }
2230
+ }
2231
+ }
2232
+ return obj;
2233
+ });
2234
+ }
2235
+ return _codec;
2236
+ };
2237
+ FilterSubscribeRequest.encode = (obj) => {
2238
+ return encodeMessage(obj, FilterSubscribeRequest.codec());
2239
+ };
2240
+ FilterSubscribeRequest.decode = (buf, opts) => {
2241
+ return decodeMessage(buf, FilterSubscribeRequest.codec(), opts);
2242
+ };
2243
+ })(FilterSubscribeRequest || (FilterSubscribeRequest = {}));
2244
+ var FilterSubscribeResponse$1;
2245
+ (function (FilterSubscribeResponse) {
2246
+ let _codec;
2247
+ FilterSubscribeResponse.codec = () => {
2248
+ if (_codec == null) {
2249
+ _codec = message$1((obj, w, opts = {}) => {
2250
+ if (opts.lengthDelimited !== false) {
2251
+ w.fork();
2252
+ }
2253
+ if ((obj.requestId != null && obj.requestId !== '')) {
2254
+ w.uint32(10);
2255
+ w.string(obj.requestId);
2256
+ }
2257
+ if ((obj.statusCode != null && obj.statusCode !== 0)) {
2258
+ w.uint32(80);
2259
+ w.uint32(obj.statusCode);
2260
+ }
2261
+ if (obj.statusDesc != null) {
2262
+ w.uint32(90);
2263
+ w.string(obj.statusDesc);
2264
+ }
2265
+ if (opts.lengthDelimited !== false) {
2266
+ w.ldelim();
2267
+ }
2268
+ }, (reader, length, opts = {}) => {
2269
+ const obj = {
2270
+ requestId: '',
2271
+ statusCode: 0
2272
+ };
2273
+ const end = length == null ? reader.len : reader.pos + length;
2274
+ while (reader.pos < end) {
2275
+ const tag = reader.uint32();
2276
+ switch (tag >>> 3) {
2277
+ case 1: {
2278
+ obj.requestId = reader.string();
2279
+ break;
2280
+ }
2281
+ case 10: {
2282
+ obj.statusCode = reader.uint32();
2283
+ break;
2284
+ }
2285
+ case 11: {
2286
+ obj.statusDesc = reader.string();
2287
+ break;
2288
+ }
2289
+ default: {
2290
+ reader.skipType(tag & 7);
2291
+ break;
2292
+ }
2293
+ }
2294
+ }
2295
+ return obj;
2296
+ });
2297
+ }
2298
+ return _codec;
2299
+ };
2300
+ FilterSubscribeResponse.encode = (obj) => {
2301
+ return encodeMessage(obj, FilterSubscribeResponse.codec());
2302
+ };
2303
+ FilterSubscribeResponse.decode = (buf, opts) => {
2304
+ return decodeMessage(buf, FilterSubscribeResponse.codec(), opts);
2305
+ };
2306
+ })(FilterSubscribeResponse$1 || (FilterSubscribeResponse$1 = {}));
2307
+ var MessagePush;
2308
+ (function (MessagePush) {
2309
+ let _codec;
2310
+ MessagePush.codec = () => {
2311
+ if (_codec == null) {
2312
+ _codec = message$1((obj, w, opts = {}) => {
2313
+ if (opts.lengthDelimited !== false) {
2314
+ w.fork();
2315
+ }
2316
+ if (obj.wakuMessage != null) {
2317
+ w.uint32(10);
2318
+ WakuMessage$2.codec().encode(obj.wakuMessage, w);
2319
+ }
2320
+ if (obj.pubsubTopic != null) {
2321
+ w.uint32(18);
2322
+ w.string(obj.pubsubTopic);
2323
+ }
2324
+ if (opts.lengthDelimited !== false) {
2325
+ w.ldelim();
2326
+ }
2327
+ }, (reader, length, opts = {}) => {
2328
+ const obj = {};
2329
+ const end = length == null ? reader.len : reader.pos + length;
2330
+ while (reader.pos < end) {
2331
+ const tag = reader.uint32();
2332
+ switch (tag >>> 3) {
2333
+ case 1: {
2334
+ obj.wakuMessage = WakuMessage$2.codec().decode(reader, reader.uint32(), {
2335
+ limits: opts.limits?.wakuMessage
2336
+ });
2337
+ break;
2338
+ }
2339
+ case 2: {
2340
+ obj.pubsubTopic = reader.string();
2341
+ break;
2342
+ }
2343
+ default: {
2344
+ reader.skipType(tag & 7);
2345
+ break;
2346
+ }
2347
+ }
2348
+ }
2349
+ return obj;
2350
+ });
2351
+ }
2352
+ return _codec;
2353
+ };
2354
+ MessagePush.encode = (obj) => {
2355
+ return encodeMessage(obj, MessagePush.codec());
2356
+ };
2357
+ MessagePush.decode = (buf, opts) => {
2358
+ return decodeMessage(buf, MessagePush.codec(), opts);
2359
+ };
2360
+ })(MessagePush || (MessagePush = {}));
2361
+ var RateLimitProof$2;
2362
+ (function (RateLimitProof) {
2363
+ let _codec;
2364
+ RateLimitProof.codec = () => {
2365
+ if (_codec == null) {
2366
+ _codec = message$1((obj, w, opts = {}) => {
2367
+ if (opts.lengthDelimited !== false) {
2368
+ w.fork();
2369
+ }
2370
+ if ((obj.proof != null && obj.proof.byteLength > 0)) {
2371
+ w.uint32(10);
2372
+ w.bytes(obj.proof);
2373
+ }
2374
+ if ((obj.merkleRoot != null && obj.merkleRoot.byteLength > 0)) {
2375
+ w.uint32(18);
2376
+ w.bytes(obj.merkleRoot);
2377
+ }
2378
+ if ((obj.epoch != null && obj.epoch.byteLength > 0)) {
2379
+ w.uint32(26);
2380
+ w.bytes(obj.epoch);
2381
+ }
2382
+ if ((obj.shareX != null && obj.shareX.byteLength > 0)) {
2383
+ w.uint32(34);
2384
+ w.bytes(obj.shareX);
2385
+ }
2386
+ if ((obj.shareY != null && obj.shareY.byteLength > 0)) {
2387
+ w.uint32(42);
2388
+ w.bytes(obj.shareY);
2389
+ }
2390
+ if ((obj.nullifier != null && obj.nullifier.byteLength > 0)) {
2391
+ w.uint32(50);
2392
+ w.bytes(obj.nullifier);
2393
+ }
2394
+ if ((obj.rlnIdentifier != null && obj.rlnIdentifier.byteLength > 0)) {
2395
+ w.uint32(58);
2396
+ w.bytes(obj.rlnIdentifier);
2397
+ }
2398
+ if (opts.lengthDelimited !== false) {
2399
+ w.ldelim();
2400
+ }
2401
+ }, (reader, length, opts = {}) => {
2402
+ const obj = {
2403
+ proof: alloc$1(0),
2404
+ merkleRoot: alloc$1(0),
2405
+ epoch: alloc$1(0),
2406
+ shareX: alloc$1(0),
2407
+ shareY: alloc$1(0),
2408
+ nullifier: alloc$1(0),
2409
+ rlnIdentifier: alloc$1(0)
2410
+ };
2411
+ const end = length == null ? reader.len : reader.pos + length;
2412
+ while (reader.pos < end) {
2413
+ const tag = reader.uint32();
2414
+ switch (tag >>> 3) {
2415
+ case 1: {
2416
+ obj.proof = reader.bytes();
2417
+ break;
2418
+ }
2419
+ case 2: {
2420
+ obj.merkleRoot = reader.bytes();
2421
+ break;
2422
+ }
2423
+ case 3: {
2424
+ obj.epoch = reader.bytes();
2425
+ break;
2426
+ }
2427
+ case 4: {
2428
+ obj.shareX = reader.bytes();
2429
+ break;
2430
+ }
2431
+ case 5: {
2432
+ obj.shareY = reader.bytes();
2433
+ break;
2434
+ }
2435
+ case 6: {
2436
+ obj.nullifier = reader.bytes();
2437
+ break;
2438
+ }
2439
+ case 7: {
2440
+ obj.rlnIdentifier = reader.bytes();
2441
+ break;
2442
+ }
2443
+ default: {
2444
+ reader.skipType(tag & 7);
2445
+ break;
2446
+ }
2447
+ }
2448
+ }
2449
+ return obj;
2450
+ });
2451
+ }
2452
+ return _codec;
2453
+ };
2454
+ RateLimitProof.encode = (obj) => {
2455
+ return encodeMessage(obj, RateLimitProof.codec());
2456
+ };
2457
+ RateLimitProof.decode = (buf, opts) => {
2458
+ return decodeMessage(buf, RateLimitProof.codec(), opts);
2459
+ };
2460
+ })(RateLimitProof$2 || (RateLimitProof$2 = {}));
2461
+ var WakuMessage$2;
2462
+ (function (WakuMessage) {
2463
+ let _codec;
2464
+ WakuMessage.codec = () => {
2465
+ if (_codec == null) {
2466
+ _codec = message$1((obj, w, opts = {}) => {
2467
+ if (opts.lengthDelimited !== false) {
2468
+ w.fork();
2469
+ }
2470
+ if ((obj.payload != null && obj.payload.byteLength > 0)) {
2471
+ w.uint32(10);
2472
+ w.bytes(obj.payload);
2473
+ }
2474
+ if ((obj.contentTopic != null && obj.contentTopic !== '')) {
2475
+ w.uint32(18);
2476
+ w.string(obj.contentTopic);
2477
+ }
2478
+ if (obj.version != null) {
2479
+ w.uint32(24);
2480
+ w.uint32(obj.version);
2481
+ }
2482
+ if (obj.timestamp != null) {
2483
+ w.uint32(80);
2484
+ w.sint64(obj.timestamp);
2485
+ }
2486
+ if (obj.meta != null) {
2487
+ w.uint32(90);
2488
+ w.bytes(obj.meta);
2489
+ }
2490
+ if (obj.rateLimitProof != null) {
2491
+ w.uint32(170);
2492
+ RateLimitProof$2.codec().encode(obj.rateLimitProof, w);
2493
+ }
2494
+ if (obj.ephemeral != null) {
2495
+ w.uint32(248);
2496
+ w.bool(obj.ephemeral);
2497
+ }
2498
+ if (opts.lengthDelimited !== false) {
2499
+ w.ldelim();
2500
+ }
2501
+ }, (reader, length, opts = {}) => {
2502
+ const obj = {
2503
+ payload: alloc$1(0),
2504
+ contentTopic: ''
2505
+ };
2506
+ const end = length == null ? reader.len : reader.pos + length;
2507
+ while (reader.pos < end) {
2508
+ const tag = reader.uint32();
2509
+ switch (tag >>> 3) {
2510
+ case 1: {
2511
+ obj.payload = reader.bytes();
2512
+ break;
2513
+ }
2514
+ case 2: {
2515
+ obj.contentTopic = reader.string();
2516
+ break;
2517
+ }
2518
+ case 3: {
2519
+ obj.version = reader.uint32();
2520
+ break;
2521
+ }
2522
+ case 10: {
2523
+ obj.timestamp = reader.sint64();
2524
+ break;
2525
+ }
2526
+ case 11: {
2527
+ obj.meta = reader.bytes();
2528
+ break;
2529
+ }
2530
+ case 21: {
2531
+ obj.rateLimitProof = RateLimitProof$2.codec().decode(reader, reader.uint32(), {
2532
+ limits: opts.limits?.rateLimitProof
2533
+ });
2534
+ break;
2535
+ }
2536
+ case 31: {
2537
+ obj.ephemeral = reader.bool();
2538
+ break;
2539
+ }
2540
+ default: {
2541
+ reader.skipType(tag & 7);
2542
+ break;
2543
+ }
2544
+ }
2545
+ }
2546
+ return obj;
2547
+ });
2548
+ }
2549
+ return _codec;
2550
+ };
2551
+ WakuMessage.encode = (obj) => {
2552
+ return encodeMessage(obj, WakuMessage.codec());
2553
+ };
2554
+ WakuMessage.decode = (buf, opts) => {
2555
+ return decodeMessage(buf, WakuMessage.codec(), opts);
2556
+ };
2557
+ })(WakuMessage$2 || (WakuMessage$2 = {}));
2558
+
2559
+ /* eslint-disable import/export */
2560
+ /* eslint-disable complexity */
2561
+ /* eslint-disable @typescript-eslint/no-namespace */
2562
+ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
2563
+ /* eslint-disable @typescript-eslint/no-empty-interface */
2564
+ var PushRequest;
2565
+ (function (PushRequest) {
2566
+ let _codec;
2567
+ PushRequest.codec = () => {
2568
+ if (_codec == null) {
2569
+ _codec = message$1((obj, w, opts = {}) => {
2570
+ if (opts.lengthDelimited !== false) {
2571
+ w.fork();
2572
+ }
2573
+ if ((obj.pubsubTopic != null && obj.pubsubTopic !== '')) {
2574
+ w.uint32(10);
2575
+ w.string(obj.pubsubTopic);
2576
+ }
2577
+ if (obj.message != null) {
2578
+ w.uint32(18);
2579
+ WakuMessage$1.codec().encode(obj.message, w);
2580
+ }
2581
+ if (opts.lengthDelimited !== false) {
2582
+ w.ldelim();
2583
+ }
2584
+ }, (reader, length, opts = {}) => {
2585
+ const obj = {
2586
+ pubsubTopic: ''
2587
+ };
2588
+ const end = length == null ? reader.len : reader.pos + length;
2589
+ while (reader.pos < end) {
2590
+ const tag = reader.uint32();
2591
+ switch (tag >>> 3) {
2592
+ case 1: {
2593
+ obj.pubsubTopic = reader.string();
2594
+ break;
2595
+ }
2596
+ case 2: {
2597
+ obj.message = WakuMessage$1.codec().decode(reader, reader.uint32(), {
2598
+ limits: opts.limits?.message
2599
+ });
2600
+ break;
2601
+ }
2602
+ default: {
2603
+ reader.skipType(tag & 7);
2604
+ break;
2605
+ }
2606
+ }
2607
+ }
2608
+ return obj;
2609
+ });
2610
+ }
2611
+ return _codec;
2612
+ };
2613
+ PushRequest.encode = (obj) => {
2614
+ return encodeMessage(obj, PushRequest.codec());
2615
+ };
2616
+ PushRequest.decode = (buf, opts) => {
2617
+ return decodeMessage(buf, PushRequest.codec(), opts);
2618
+ };
2619
+ })(PushRequest || (PushRequest = {}));
2620
+ var PushResponse;
2621
+ (function (PushResponse) {
2622
+ let _codec;
2623
+ PushResponse.codec = () => {
2624
+ if (_codec == null) {
2625
+ _codec = message$1((obj, w, opts = {}) => {
2626
+ if (opts.lengthDelimited !== false) {
2627
+ w.fork();
2628
+ }
2629
+ if ((obj.isSuccess != null && obj.isSuccess !== false)) {
2630
+ w.uint32(8);
2631
+ w.bool(obj.isSuccess);
2632
+ }
2633
+ if (obj.info != null) {
2634
+ w.uint32(18);
2635
+ w.string(obj.info);
2636
+ }
2637
+ if (opts.lengthDelimited !== false) {
2638
+ w.ldelim();
2639
+ }
2640
+ }, (reader, length, opts = {}) => {
2641
+ const obj = {
2642
+ isSuccess: false
2643
+ };
2644
+ const end = length == null ? reader.len : reader.pos + length;
2645
+ while (reader.pos < end) {
2646
+ const tag = reader.uint32();
2647
+ switch (tag >>> 3) {
2648
+ case 1: {
2649
+ obj.isSuccess = reader.bool();
2650
+ break;
2651
+ }
2652
+ case 2: {
2653
+ obj.info = reader.string();
2654
+ break;
2655
+ }
2656
+ default: {
2657
+ reader.skipType(tag & 7);
2658
+ break;
2659
+ }
2660
+ }
2661
+ }
2662
+ return obj;
2663
+ });
2664
+ }
2665
+ return _codec;
2666
+ };
2667
+ PushResponse.encode = (obj) => {
2668
+ return encodeMessage(obj, PushResponse.codec());
2669
+ };
2670
+ PushResponse.decode = (buf, opts) => {
2671
+ return decodeMessage(buf, PushResponse.codec(), opts);
2672
+ };
2673
+ })(PushResponse || (PushResponse = {}));
2674
+ var PushRpc$1;
2675
+ (function (PushRpc) {
2676
+ let _codec;
2677
+ PushRpc.codec = () => {
2678
+ if (_codec == null) {
2679
+ _codec = message$1((obj, w, opts = {}) => {
2680
+ if (opts.lengthDelimited !== false) {
2681
+ w.fork();
2682
+ }
2683
+ if ((obj.requestId != null && obj.requestId !== '')) {
2684
+ w.uint32(10);
2685
+ w.string(obj.requestId);
2686
+ }
2687
+ if (obj.request != null) {
2688
+ w.uint32(18);
2689
+ PushRequest.codec().encode(obj.request, w);
2690
+ }
2691
+ if (obj.response != null) {
2692
+ w.uint32(26);
2693
+ PushResponse.codec().encode(obj.response, w);
2694
+ }
2695
+ if (opts.lengthDelimited !== false) {
2696
+ w.ldelim();
2697
+ }
2698
+ }, (reader, length, opts = {}) => {
2699
+ const obj = {
2700
+ requestId: ''
2701
+ };
2702
+ const end = length == null ? reader.len : reader.pos + length;
2703
+ while (reader.pos < end) {
2704
+ const tag = reader.uint32();
2705
+ switch (tag >>> 3) {
2706
+ case 1: {
2707
+ obj.requestId = reader.string();
2708
+ break;
2709
+ }
2710
+ case 2: {
2711
+ obj.request = PushRequest.codec().decode(reader, reader.uint32(), {
2712
+ limits: opts.limits?.request
2713
+ });
2714
+ break;
2715
+ }
2716
+ case 3: {
2717
+ obj.response = PushResponse.codec().decode(reader, reader.uint32(), {
2718
+ limits: opts.limits?.response
2719
+ });
2720
+ break;
2721
+ }
2722
+ default: {
2723
+ reader.skipType(tag & 7);
2724
+ break;
2725
+ }
2726
+ }
2727
+ }
2728
+ return obj;
2729
+ });
2730
+ }
2731
+ return _codec;
2732
+ };
2733
+ PushRpc.encode = (obj) => {
2734
+ return encodeMessage(obj, PushRpc.codec());
2735
+ };
2736
+ PushRpc.decode = (buf, opts) => {
2737
+ return decodeMessage(buf, PushRpc.codec(), opts);
2738
+ };
2739
+ })(PushRpc$1 || (PushRpc$1 = {}));
2740
+ var RateLimitProof$1;
2741
+ (function (RateLimitProof) {
2742
+ let _codec;
2743
+ RateLimitProof.codec = () => {
2744
+ if (_codec == null) {
2745
+ _codec = message$1((obj, w, opts = {}) => {
2746
+ if (opts.lengthDelimited !== false) {
2747
+ w.fork();
2748
+ }
2749
+ if ((obj.proof != null && obj.proof.byteLength > 0)) {
2750
+ w.uint32(10);
2751
+ w.bytes(obj.proof);
2752
+ }
2753
+ if ((obj.merkleRoot != null && obj.merkleRoot.byteLength > 0)) {
2754
+ w.uint32(18);
2755
+ w.bytes(obj.merkleRoot);
2756
+ }
2757
+ if ((obj.epoch != null && obj.epoch.byteLength > 0)) {
2758
+ w.uint32(26);
2759
+ w.bytes(obj.epoch);
2760
+ }
2761
+ if ((obj.shareX != null && obj.shareX.byteLength > 0)) {
2762
+ w.uint32(34);
2763
+ w.bytes(obj.shareX);
2764
+ }
2765
+ if ((obj.shareY != null && obj.shareY.byteLength > 0)) {
2766
+ w.uint32(42);
2767
+ w.bytes(obj.shareY);
2768
+ }
2769
+ if ((obj.nullifier != null && obj.nullifier.byteLength > 0)) {
2770
+ w.uint32(50);
2771
+ w.bytes(obj.nullifier);
2772
+ }
2773
+ if ((obj.rlnIdentifier != null && obj.rlnIdentifier.byteLength > 0)) {
2774
+ w.uint32(58);
2775
+ w.bytes(obj.rlnIdentifier);
2776
+ }
2777
+ if (opts.lengthDelimited !== false) {
2778
+ w.ldelim();
2779
+ }
2780
+ }, (reader, length, opts = {}) => {
2781
+ const obj = {
2782
+ proof: alloc$1(0),
2783
+ merkleRoot: alloc$1(0),
2784
+ epoch: alloc$1(0),
2785
+ shareX: alloc$1(0),
2786
+ shareY: alloc$1(0),
2787
+ nullifier: alloc$1(0),
2788
+ rlnIdentifier: alloc$1(0)
2789
+ };
2790
+ const end = length == null ? reader.len : reader.pos + length;
2791
+ while (reader.pos < end) {
2792
+ const tag = reader.uint32();
2793
+ switch (tag >>> 3) {
2794
+ case 1: {
2795
+ obj.proof = reader.bytes();
2796
+ break;
2797
+ }
2798
+ case 2: {
2799
+ obj.merkleRoot = reader.bytes();
2800
+ break;
2801
+ }
2802
+ case 3: {
2803
+ obj.epoch = reader.bytes();
2804
+ break;
2805
+ }
2806
+ case 4: {
2807
+ obj.shareX = reader.bytes();
2808
+ break;
2809
+ }
2810
+ case 5: {
2811
+ obj.shareY = reader.bytes();
2812
+ break;
2813
+ }
2814
+ case 6: {
2815
+ obj.nullifier = reader.bytes();
2816
+ break;
2817
+ }
2818
+ case 7: {
2819
+ obj.rlnIdentifier = reader.bytes();
2820
+ break;
2821
+ }
2822
+ default: {
2823
+ reader.skipType(tag & 7);
2824
+ break;
2825
+ }
2826
+ }
2827
+ }
2828
+ return obj;
2829
+ });
2830
+ }
2831
+ return _codec;
2832
+ };
2833
+ RateLimitProof.encode = (obj) => {
2834
+ return encodeMessage(obj, RateLimitProof.codec());
2835
+ };
2836
+ RateLimitProof.decode = (buf, opts) => {
2837
+ return decodeMessage(buf, RateLimitProof.codec(), opts);
2838
+ };
2839
+ })(RateLimitProof$1 || (RateLimitProof$1 = {}));
2840
+ var WakuMessage$1;
2841
+ (function (WakuMessage) {
2842
+ let _codec;
2843
+ WakuMessage.codec = () => {
2844
+ if (_codec == null) {
2845
+ _codec = message$1((obj, w, opts = {}) => {
2846
+ if (opts.lengthDelimited !== false) {
2847
+ w.fork();
2848
+ }
2849
+ if ((obj.payload != null && obj.payload.byteLength > 0)) {
2850
+ w.uint32(10);
2851
+ w.bytes(obj.payload);
2852
+ }
2853
+ if ((obj.contentTopic != null && obj.contentTopic !== '')) {
2854
+ w.uint32(18);
2855
+ w.string(obj.contentTopic);
2856
+ }
2857
+ if (obj.version != null) {
2858
+ w.uint32(24);
2859
+ w.uint32(obj.version);
2860
+ }
2861
+ if (obj.timestamp != null) {
2862
+ w.uint32(80);
2863
+ w.sint64(obj.timestamp);
2864
+ }
2865
+ if (obj.meta != null) {
2866
+ w.uint32(90);
2867
+ w.bytes(obj.meta);
2868
+ }
2869
+ if (obj.rateLimitProof != null) {
2870
+ w.uint32(170);
2871
+ RateLimitProof$1.codec().encode(obj.rateLimitProof, w);
2872
+ }
2873
+ if (obj.ephemeral != null) {
2874
+ w.uint32(248);
2875
+ w.bool(obj.ephemeral);
2876
+ }
2877
+ if (opts.lengthDelimited !== false) {
2878
+ w.ldelim();
2879
+ }
2880
+ }, (reader, length, opts = {}) => {
2881
+ const obj = {
2882
+ payload: alloc$1(0),
2883
+ contentTopic: ''
2884
+ };
2885
+ const end = length == null ? reader.len : reader.pos + length;
2886
+ while (reader.pos < end) {
2887
+ const tag = reader.uint32();
2888
+ switch (tag >>> 3) {
2889
+ case 1: {
2890
+ obj.payload = reader.bytes();
2891
+ break;
2892
+ }
2893
+ case 2: {
2894
+ obj.contentTopic = reader.string();
2895
+ break;
2896
+ }
2897
+ case 3: {
2898
+ obj.version = reader.uint32();
2899
+ break;
2900
+ }
2901
+ case 10: {
2902
+ obj.timestamp = reader.sint64();
2903
+ break;
2904
+ }
2905
+ case 11: {
2906
+ obj.meta = reader.bytes();
2907
+ break;
2908
+ }
2909
+ case 21: {
2910
+ obj.rateLimitProof = RateLimitProof$1.codec().decode(reader, reader.uint32(), {
2911
+ limits: opts.limits?.rateLimitProof
2912
+ });
2913
+ break;
2914
+ }
2915
+ case 31: {
2916
+ obj.ephemeral = reader.bool();
2917
+ break;
2918
+ }
2919
+ default: {
2920
+ reader.skipType(tag & 7);
2921
+ break;
2922
+ }
2923
+ }
2924
+ }
2925
+ return obj;
2926
+ });
2927
+ }
2928
+ return _codec;
2929
+ };
2930
+ WakuMessage.encode = (obj) => {
2931
+ return encodeMessage(obj, WakuMessage.codec());
2932
+ };
2933
+ WakuMessage.decode = (buf, opts) => {
2934
+ return decodeMessage(buf, WakuMessage.codec(), opts);
2935
+ };
2936
+ })(WakuMessage$1 || (WakuMessage$1 = {}));
2937
+
2938
+ /* eslint-disable import/export */
2939
+ /* eslint-disable complexity */
2940
+ /* eslint-disable @typescript-eslint/no-namespace */
2941
+ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
2942
+ /* eslint-disable @typescript-eslint/no-empty-interface */
2943
+ var Index;
2944
+ (function (Index) {
2945
+ let _codec;
2946
+ Index.codec = () => {
2947
+ if (_codec == null) {
2948
+ _codec = message$1((obj, w, opts = {}) => {
2949
+ if (opts.lengthDelimited !== false) {
2950
+ w.fork();
2951
+ }
2952
+ if ((obj.digest != null && obj.digest.byteLength > 0)) {
2953
+ w.uint32(10);
2954
+ w.bytes(obj.digest);
2955
+ }
2956
+ if ((obj.receiverTime != null && obj.receiverTime !== 0n)) {
2957
+ w.uint32(16);
2958
+ w.sint64(obj.receiverTime);
2959
+ }
2960
+ if ((obj.senderTime != null && obj.senderTime !== 0n)) {
2961
+ w.uint32(24);
2962
+ w.sint64(obj.senderTime);
2963
+ }
2964
+ if ((obj.pubsubTopic != null && obj.pubsubTopic !== '')) {
2965
+ w.uint32(34);
2966
+ w.string(obj.pubsubTopic);
2967
+ }
2968
+ if (opts.lengthDelimited !== false) {
2969
+ w.ldelim();
2970
+ }
2971
+ }, (reader, length, opts = {}) => {
2972
+ const obj = {
2973
+ digest: alloc$1(0),
2974
+ receiverTime: 0n,
2975
+ senderTime: 0n,
2976
+ pubsubTopic: ''
2977
+ };
2978
+ const end = length == null ? reader.len : reader.pos + length;
2979
+ while (reader.pos < end) {
2980
+ const tag = reader.uint32();
2981
+ switch (tag >>> 3) {
2982
+ case 1: {
2983
+ obj.digest = reader.bytes();
2984
+ break;
2985
+ }
2986
+ case 2: {
2987
+ obj.receiverTime = reader.sint64();
2988
+ break;
2989
+ }
2990
+ case 3: {
2991
+ obj.senderTime = reader.sint64();
2992
+ break;
2993
+ }
2994
+ case 4: {
2995
+ obj.pubsubTopic = reader.string();
2996
+ break;
2997
+ }
2998
+ default: {
2999
+ reader.skipType(tag & 7);
3000
+ break;
3001
+ }
3002
+ }
3003
+ }
3004
+ return obj;
3005
+ });
3006
+ }
3007
+ return _codec;
3008
+ };
3009
+ Index.encode = (obj) => {
3010
+ return encodeMessage(obj, Index.codec());
3011
+ };
3012
+ Index.decode = (buf, opts) => {
3013
+ return decodeMessage(buf, Index.codec(), opts);
3014
+ };
3015
+ })(Index || (Index = {}));
3016
+ var PagingInfo;
3017
+ (function (PagingInfo) {
3018
+ (function (Direction) {
3019
+ Direction["BACKWARD"] = "BACKWARD";
3020
+ Direction["FORWARD"] = "FORWARD";
3021
+ })(PagingInfo.Direction || (PagingInfo.Direction = {}));
3022
+ let __DirectionValues;
3023
+ (function (__DirectionValues) {
3024
+ __DirectionValues[__DirectionValues["BACKWARD"] = 0] = "BACKWARD";
3025
+ __DirectionValues[__DirectionValues["FORWARD"] = 1] = "FORWARD";
3026
+ })(__DirectionValues || (__DirectionValues = {}));
3027
+ (function (Direction) {
3028
+ Direction.codec = () => {
3029
+ return enumeration(__DirectionValues);
3030
+ };
3031
+ })(PagingInfo.Direction || (PagingInfo.Direction = {}));
3032
+ let _codec;
3033
+ PagingInfo.codec = () => {
3034
+ if (_codec == null) {
3035
+ _codec = message$1((obj, w, opts = {}) => {
3036
+ if (opts.lengthDelimited !== false) {
3037
+ w.fork();
3038
+ }
3039
+ if (obj.pageSize != null) {
3040
+ w.uint32(8);
3041
+ w.uint64(obj.pageSize);
3042
+ }
3043
+ if (obj.cursor != null) {
3044
+ w.uint32(18);
3045
+ Index.codec().encode(obj.cursor, w);
3046
+ }
3047
+ if (obj.direction != null) {
3048
+ w.uint32(24);
3049
+ PagingInfo.Direction.codec().encode(obj.direction, w);
3050
+ }
3051
+ if (opts.lengthDelimited !== false) {
3052
+ w.ldelim();
3053
+ }
3054
+ }, (reader, length, opts = {}) => {
3055
+ const obj = {};
3056
+ const end = length == null ? reader.len : reader.pos + length;
3057
+ while (reader.pos < end) {
3058
+ const tag = reader.uint32();
3059
+ switch (tag >>> 3) {
3060
+ case 1: {
3061
+ obj.pageSize = reader.uint64();
3062
+ break;
3063
+ }
3064
+ case 2: {
3065
+ obj.cursor = Index.codec().decode(reader, reader.uint32(), {
3066
+ limits: opts.limits?.cursor
3067
+ });
3068
+ break;
3069
+ }
3070
+ case 3: {
3071
+ obj.direction = PagingInfo.Direction.codec().decode(reader);
3072
+ break;
3073
+ }
3074
+ default: {
3075
+ reader.skipType(tag & 7);
3076
+ break;
3077
+ }
3078
+ }
3079
+ }
3080
+ return obj;
3081
+ });
3082
+ }
3083
+ return _codec;
3084
+ };
3085
+ PagingInfo.encode = (obj) => {
3086
+ return encodeMessage(obj, PagingInfo.codec());
3087
+ };
3088
+ PagingInfo.decode = (buf, opts) => {
3089
+ return decodeMessage(buf, PagingInfo.codec(), opts);
3090
+ };
3091
+ })(PagingInfo || (PagingInfo = {}));
3092
+ var ContentFilter;
3093
+ (function (ContentFilter) {
3094
+ let _codec;
3095
+ ContentFilter.codec = () => {
3096
+ if (_codec == null) {
3097
+ _codec = message$1((obj, w, opts = {}) => {
3098
+ if (opts.lengthDelimited !== false) {
3099
+ w.fork();
3100
+ }
3101
+ if ((obj.contentTopic != null && obj.contentTopic !== '')) {
3102
+ w.uint32(10);
3103
+ w.string(obj.contentTopic);
3104
+ }
3105
+ if (opts.lengthDelimited !== false) {
3106
+ w.ldelim();
3107
+ }
3108
+ }, (reader, length, opts = {}) => {
3109
+ const obj = {
3110
+ contentTopic: ''
3111
+ };
3112
+ const end = length == null ? reader.len : reader.pos + length;
3113
+ while (reader.pos < end) {
3114
+ const tag = reader.uint32();
3115
+ switch (tag >>> 3) {
3116
+ case 1: {
3117
+ obj.contentTopic = reader.string();
3118
+ break;
3119
+ }
3120
+ default: {
3121
+ reader.skipType(tag & 7);
3122
+ break;
3123
+ }
3124
+ }
3125
+ }
3126
+ return obj;
3127
+ });
3128
+ }
3129
+ return _codec;
3130
+ };
3131
+ ContentFilter.encode = (obj) => {
3132
+ return encodeMessage(obj, ContentFilter.codec());
3133
+ };
3134
+ ContentFilter.decode = (buf, opts) => {
3135
+ return decodeMessage(buf, ContentFilter.codec(), opts);
3136
+ };
3137
+ })(ContentFilter || (ContentFilter = {}));
3138
+ var HistoryQuery;
3139
+ (function (HistoryQuery) {
3140
+ let _codec;
3141
+ HistoryQuery.codec = () => {
3142
+ if (_codec == null) {
3143
+ _codec = message$1((obj, w, opts = {}) => {
3144
+ if (opts.lengthDelimited !== false) {
3145
+ w.fork();
3146
+ }
3147
+ if (obj.pubsubTopic != null) {
3148
+ w.uint32(18);
3149
+ w.string(obj.pubsubTopic);
3150
+ }
3151
+ if (obj.contentFilters != null) {
3152
+ for (const value of obj.contentFilters) {
3153
+ w.uint32(26);
3154
+ ContentFilter.codec().encode(value, w);
3155
+ }
3156
+ }
3157
+ if (obj.pagingInfo != null) {
3158
+ w.uint32(34);
3159
+ PagingInfo.codec().encode(obj.pagingInfo, w);
3160
+ }
3161
+ if (obj.startTime != null) {
3162
+ w.uint32(40);
3163
+ w.sint64(obj.startTime);
3164
+ }
3165
+ if (obj.endTime != null) {
3166
+ w.uint32(48);
3167
+ w.sint64(obj.endTime);
3168
+ }
3169
+ if (opts.lengthDelimited !== false) {
3170
+ w.ldelim();
3171
+ }
3172
+ }, (reader, length, opts = {}) => {
3173
+ const obj = {
3174
+ contentFilters: []
3175
+ };
3176
+ const end = length == null ? reader.len : reader.pos + length;
3177
+ while (reader.pos < end) {
3178
+ const tag = reader.uint32();
3179
+ switch (tag >>> 3) {
3180
+ case 2: {
3181
+ obj.pubsubTopic = reader.string();
3182
+ break;
3183
+ }
3184
+ case 3: {
3185
+ if (opts.limits?.contentFilters != null && obj.contentFilters.length === opts.limits.contentFilters) {
3186
+ throw new CodeError('decode error - map field "contentFilters" had too many elements', 'ERR_MAX_LENGTH');
3187
+ }
3188
+ obj.contentFilters.push(ContentFilter.codec().decode(reader, reader.uint32(), {
3189
+ limits: opts.limits?.contentFilters$
3190
+ }));
3191
+ break;
3192
+ }
3193
+ case 4: {
3194
+ obj.pagingInfo = PagingInfo.codec().decode(reader, reader.uint32(), {
3195
+ limits: opts.limits?.pagingInfo
3196
+ });
3197
+ break;
3198
+ }
3199
+ case 5: {
3200
+ obj.startTime = reader.sint64();
3201
+ break;
3202
+ }
3203
+ case 6: {
3204
+ obj.endTime = reader.sint64();
3205
+ break;
3206
+ }
3207
+ default: {
3208
+ reader.skipType(tag & 7);
3209
+ break;
3210
+ }
3211
+ }
3212
+ }
3213
+ return obj;
3214
+ });
3215
+ }
3216
+ return _codec;
3217
+ };
3218
+ HistoryQuery.encode = (obj) => {
3219
+ return encodeMessage(obj, HistoryQuery.codec());
3220
+ };
3221
+ HistoryQuery.decode = (buf, opts) => {
3222
+ return decodeMessage(buf, HistoryQuery.codec(), opts);
3223
+ };
3224
+ })(HistoryQuery || (HistoryQuery = {}));
3225
+ var HistoryResponse;
3226
+ (function (HistoryResponse) {
3227
+ let HistoryError;
3228
+ (function (HistoryError) {
3229
+ HistoryError["NONE"] = "NONE";
3230
+ HistoryError["INVALID_CURSOR"] = "INVALID_CURSOR";
3231
+ })(HistoryError = HistoryResponse.HistoryError || (HistoryResponse.HistoryError = {}));
3232
+ let __HistoryErrorValues;
3233
+ (function (__HistoryErrorValues) {
3234
+ __HistoryErrorValues[__HistoryErrorValues["NONE"] = 0] = "NONE";
3235
+ __HistoryErrorValues[__HistoryErrorValues["INVALID_CURSOR"] = 1] = "INVALID_CURSOR";
3236
+ })(__HistoryErrorValues || (__HistoryErrorValues = {}));
3237
+ (function (HistoryError) {
3238
+ HistoryError.codec = () => {
3239
+ return enumeration(__HistoryErrorValues);
3240
+ };
3241
+ })(HistoryError = HistoryResponse.HistoryError || (HistoryResponse.HistoryError = {}));
3242
+ let _codec;
3243
+ HistoryResponse.codec = () => {
3244
+ if (_codec == null) {
3245
+ _codec = message$1((obj, w, opts = {}) => {
3246
+ if (opts.lengthDelimited !== false) {
3247
+ w.fork();
3248
+ }
3249
+ if (obj.messages != null) {
3250
+ for (const value of obj.messages) {
3251
+ w.uint32(18);
3252
+ WakuMessage.codec().encode(value, w);
3253
+ }
3254
+ }
3255
+ if (obj.pagingInfo != null) {
3256
+ w.uint32(26);
3257
+ PagingInfo.codec().encode(obj.pagingInfo, w);
3258
+ }
3259
+ if (obj.error != null && __HistoryErrorValues[obj.error] !== 0) {
3260
+ w.uint32(32);
3261
+ HistoryResponse.HistoryError.codec().encode(obj.error, w);
3262
+ }
3263
+ if (opts.lengthDelimited !== false) {
3264
+ w.ldelim();
3265
+ }
3266
+ }, (reader, length, opts = {}) => {
3267
+ const obj = {
3268
+ messages: [],
3269
+ error: HistoryError.NONE
3270
+ };
3271
+ const end = length == null ? reader.len : reader.pos + length;
3272
+ while (reader.pos < end) {
3273
+ const tag = reader.uint32();
3274
+ switch (tag >>> 3) {
3275
+ case 2: {
3276
+ if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) {
3277
+ throw new CodeError('decode error - map field "messages" had too many elements', 'ERR_MAX_LENGTH');
3278
+ }
3279
+ obj.messages.push(WakuMessage.codec().decode(reader, reader.uint32(), {
3280
+ limits: opts.limits?.messages$
3281
+ }));
3282
+ break;
3283
+ }
3284
+ case 3: {
3285
+ obj.pagingInfo = PagingInfo.codec().decode(reader, reader.uint32(), {
3286
+ limits: opts.limits?.pagingInfo
3287
+ });
3288
+ break;
3289
+ }
3290
+ case 4: {
3291
+ obj.error = HistoryResponse.HistoryError.codec().decode(reader);
3292
+ break;
3293
+ }
3294
+ default: {
3295
+ reader.skipType(tag & 7);
3296
+ break;
3297
+ }
3298
+ }
3299
+ }
3300
+ return obj;
3301
+ });
3302
+ }
3303
+ return _codec;
3304
+ };
3305
+ HistoryResponse.encode = (obj) => {
3306
+ return encodeMessage(obj, HistoryResponse.codec());
3307
+ };
3308
+ HistoryResponse.decode = (buf, opts) => {
3309
+ return decodeMessage(buf, HistoryResponse.codec(), opts);
3310
+ };
3311
+ })(HistoryResponse || (HistoryResponse = {}));
3312
+ var HistoryRpc$1;
3313
+ (function (HistoryRpc) {
3314
+ let _codec;
3315
+ HistoryRpc.codec = () => {
3316
+ if (_codec == null) {
3317
+ _codec = message$1((obj, w, opts = {}) => {
3318
+ if (opts.lengthDelimited !== false) {
3319
+ w.fork();
3320
+ }
3321
+ if ((obj.requestId != null && obj.requestId !== '')) {
3322
+ w.uint32(10);
3323
+ w.string(obj.requestId);
3324
+ }
3325
+ if (obj.query != null) {
3326
+ w.uint32(18);
3327
+ HistoryQuery.codec().encode(obj.query, w);
3328
+ }
3329
+ if (obj.response != null) {
3330
+ w.uint32(26);
3331
+ HistoryResponse.codec().encode(obj.response, w);
3332
+ }
3333
+ if (opts.lengthDelimited !== false) {
3334
+ w.ldelim();
3335
+ }
3336
+ }, (reader, length, opts = {}) => {
3337
+ const obj = {
3338
+ requestId: ''
3339
+ };
3340
+ const end = length == null ? reader.len : reader.pos + length;
3341
+ while (reader.pos < end) {
3342
+ const tag = reader.uint32();
3343
+ switch (tag >>> 3) {
3344
+ case 1: {
3345
+ obj.requestId = reader.string();
3346
+ break;
3347
+ }
3348
+ case 2: {
3349
+ obj.query = HistoryQuery.codec().decode(reader, reader.uint32(), {
3350
+ limits: opts.limits?.query
3351
+ });
3352
+ break;
3353
+ }
3354
+ case 3: {
3355
+ obj.response = HistoryResponse.codec().decode(reader, reader.uint32(), {
3356
+ limits: opts.limits?.response
3357
+ });
3358
+ break;
3359
+ }
3360
+ default: {
3361
+ reader.skipType(tag & 7);
3362
+ break;
3363
+ }
3364
+ }
3365
+ }
3366
+ return obj;
3367
+ });
3368
+ }
3369
+ return _codec;
3370
+ };
3371
+ HistoryRpc.encode = (obj) => {
3372
+ return encodeMessage(obj, HistoryRpc.codec());
3373
+ };
3374
+ HistoryRpc.decode = (buf, opts) => {
3375
+ return decodeMessage(buf, HistoryRpc.codec(), opts);
3376
+ };
3377
+ })(HistoryRpc$1 || (HistoryRpc$1 = {}));
3378
+ var RateLimitProof;
3379
+ (function (RateLimitProof) {
3380
+ let _codec;
3381
+ RateLimitProof.codec = () => {
3382
+ if (_codec == null) {
3383
+ _codec = message$1((obj, w, opts = {}) => {
3384
+ if (opts.lengthDelimited !== false) {
3385
+ w.fork();
3386
+ }
3387
+ if ((obj.proof != null && obj.proof.byteLength > 0)) {
3388
+ w.uint32(10);
3389
+ w.bytes(obj.proof);
3390
+ }
3391
+ if ((obj.merkleRoot != null && obj.merkleRoot.byteLength > 0)) {
3392
+ w.uint32(18);
3393
+ w.bytes(obj.merkleRoot);
3394
+ }
3395
+ if ((obj.epoch != null && obj.epoch.byteLength > 0)) {
3396
+ w.uint32(26);
3397
+ w.bytes(obj.epoch);
3398
+ }
3399
+ if ((obj.shareX != null && obj.shareX.byteLength > 0)) {
3400
+ w.uint32(34);
3401
+ w.bytes(obj.shareX);
3402
+ }
3403
+ if ((obj.shareY != null && obj.shareY.byteLength > 0)) {
3404
+ w.uint32(42);
3405
+ w.bytes(obj.shareY);
3406
+ }
3407
+ if ((obj.nullifier != null && obj.nullifier.byteLength > 0)) {
3408
+ w.uint32(50);
3409
+ w.bytes(obj.nullifier);
3410
+ }
3411
+ if ((obj.rlnIdentifier != null && obj.rlnIdentifier.byteLength > 0)) {
3412
+ w.uint32(58);
3413
+ w.bytes(obj.rlnIdentifier);
3414
+ }
3415
+ if (opts.lengthDelimited !== false) {
3416
+ w.ldelim();
3417
+ }
3418
+ }, (reader, length, opts = {}) => {
3419
+ const obj = {
3420
+ proof: alloc$1(0),
3421
+ merkleRoot: alloc$1(0),
3422
+ epoch: alloc$1(0),
3423
+ shareX: alloc$1(0),
3424
+ shareY: alloc$1(0),
3425
+ nullifier: alloc$1(0),
3426
+ rlnIdentifier: alloc$1(0)
3427
+ };
3428
+ const end = length == null ? reader.len : reader.pos + length;
3429
+ while (reader.pos < end) {
3430
+ const tag = reader.uint32();
3431
+ switch (tag >>> 3) {
3432
+ case 1: {
3433
+ obj.proof = reader.bytes();
3434
+ break;
3435
+ }
3436
+ case 2: {
3437
+ obj.merkleRoot = reader.bytes();
3438
+ break;
3439
+ }
3440
+ case 3: {
3441
+ obj.epoch = reader.bytes();
3442
+ break;
3443
+ }
3444
+ case 4: {
3445
+ obj.shareX = reader.bytes();
3446
+ break;
3447
+ }
3448
+ case 5: {
3449
+ obj.shareY = reader.bytes();
3450
+ break;
3451
+ }
3452
+ case 6: {
3453
+ obj.nullifier = reader.bytes();
3454
+ break;
3455
+ }
3456
+ case 7: {
3457
+ obj.rlnIdentifier = reader.bytes();
3458
+ break;
3459
+ }
3460
+ default: {
3461
+ reader.skipType(tag & 7);
3462
+ break;
3463
+ }
3464
+ }
3465
+ }
3466
+ return obj;
3467
+ });
3468
+ }
3469
+ return _codec;
3470
+ };
3471
+ RateLimitProof.encode = (obj) => {
3472
+ return encodeMessage(obj, RateLimitProof.codec());
3473
+ };
3474
+ RateLimitProof.decode = (buf, opts) => {
3475
+ return decodeMessage(buf, RateLimitProof.codec(), opts);
3476
+ };
3477
+ })(RateLimitProof || (RateLimitProof = {}));
3478
+ var WakuMessage;
3479
+ (function (WakuMessage) {
3480
+ let _codec;
3481
+ WakuMessage.codec = () => {
3482
+ if (_codec == null) {
3483
+ _codec = message$1((obj, w, opts = {}) => {
3484
+ if (opts.lengthDelimited !== false) {
3485
+ w.fork();
3486
+ }
3487
+ if ((obj.payload != null && obj.payload.byteLength > 0)) {
3488
+ w.uint32(10);
3489
+ w.bytes(obj.payload);
3490
+ }
3491
+ if ((obj.contentTopic != null && obj.contentTopic !== '')) {
3492
+ w.uint32(18);
3493
+ w.string(obj.contentTopic);
3494
+ }
3495
+ if (obj.version != null) {
3496
+ w.uint32(24);
3497
+ w.uint32(obj.version);
3498
+ }
3499
+ if (obj.timestamp != null) {
3500
+ w.uint32(80);
3501
+ w.sint64(obj.timestamp);
3502
+ }
3503
+ if (obj.meta != null) {
3504
+ w.uint32(90);
3505
+ w.bytes(obj.meta);
3506
+ }
3507
+ if (obj.rateLimitProof != null) {
3508
+ w.uint32(170);
3509
+ RateLimitProof.codec().encode(obj.rateLimitProof, w);
3510
+ }
3511
+ if (obj.ephemeral != null) {
3512
+ w.uint32(248);
3513
+ w.bool(obj.ephemeral);
3514
+ }
3515
+ if (opts.lengthDelimited !== false) {
3516
+ w.ldelim();
3517
+ }
3518
+ }, (reader, length, opts = {}) => {
3519
+ const obj = {
3520
+ payload: alloc$1(0),
3521
+ contentTopic: ''
3522
+ };
3523
+ const end = length == null ? reader.len : reader.pos + length;
3524
+ while (reader.pos < end) {
3525
+ const tag = reader.uint32();
3526
+ switch (tag >>> 3) {
3527
+ case 1: {
3528
+ obj.payload = reader.bytes();
3529
+ break;
3530
+ }
3531
+ case 2: {
3532
+ obj.contentTopic = reader.string();
3533
+ break;
3534
+ }
3535
+ case 3: {
3536
+ obj.version = reader.uint32();
3537
+ break;
3538
+ }
3539
+ case 10: {
3540
+ obj.timestamp = reader.sint64();
3541
+ break;
3542
+ }
3543
+ case 11: {
3544
+ obj.meta = reader.bytes();
3545
+ break;
3546
+ }
3547
+ case 21: {
3548
+ obj.rateLimitProof = RateLimitProof.codec().decode(reader, reader.uint32(), {
3549
+ limits: opts.limits?.rateLimitProof
3550
+ });
3551
+ break;
3552
+ }
3553
+ case 31: {
3554
+ obj.ephemeral = reader.bool();
3555
+ break;
3556
+ }
3557
+ default: {
3558
+ reader.skipType(tag & 7);
3559
+ break;
3560
+ }
3561
+ }
3562
+ }
3563
+ return obj;
3564
+ });
3565
+ }
3566
+ return _codec;
3567
+ };
3568
+ WakuMessage.encode = (obj) => {
3569
+ return encodeMessage(obj, WakuMessage.codec());
3570
+ };
3571
+ WakuMessage.decode = (buf, opts) => {
3572
+ return decodeMessage(buf, WakuMessage.codec(), opts);
3573
+ };
3574
+ })(WakuMessage || (WakuMessage = {}));
3575
+
3576
+ /* eslint-disable import/export */
3577
+ /* eslint-disable complexity */
3578
+ /* eslint-disable @typescript-eslint/no-namespace */
3579
+ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
3580
+ /* eslint-disable @typescript-eslint/no-empty-interface */
3581
+ var PeerInfo;
3582
+ (function (PeerInfo) {
3583
+ let _codec;
3584
+ PeerInfo.codec = () => {
3585
+ if (_codec == null) {
3586
+ _codec = message$1((obj, w, opts = {}) => {
3587
+ if (opts.lengthDelimited !== false) {
3588
+ w.fork();
3589
+ }
3590
+ if (obj.enr != null) {
3591
+ w.uint32(10);
3592
+ w.bytes(obj.enr);
3593
+ }
3594
+ if (opts.lengthDelimited !== false) {
3595
+ w.ldelim();
3596
+ }
3597
+ }, (reader, length, opts = {}) => {
3598
+ const obj = {};
3599
+ const end = length == null ? reader.len : reader.pos + length;
3600
+ while (reader.pos < end) {
3601
+ const tag = reader.uint32();
3602
+ switch (tag >>> 3) {
3603
+ case 1: {
3604
+ obj.enr = reader.bytes();
3605
+ break;
3606
+ }
3607
+ default: {
3608
+ reader.skipType(tag & 7);
3609
+ break;
3610
+ }
3611
+ }
3612
+ }
3613
+ return obj;
3614
+ });
3615
+ }
3616
+ return _codec;
3617
+ };
3618
+ PeerInfo.encode = (obj) => {
3619
+ return encodeMessage(obj, PeerInfo.codec());
3620
+ };
3621
+ PeerInfo.decode = (buf, opts) => {
3622
+ return decodeMessage(buf, PeerInfo.codec(), opts);
3623
+ };
3624
+ })(PeerInfo || (PeerInfo = {}));
3625
+ var PeerExchangeQuery;
3626
+ (function (PeerExchangeQuery) {
3627
+ let _codec;
3628
+ PeerExchangeQuery.codec = () => {
3629
+ if (_codec == null) {
3630
+ _codec = message$1((obj, w, opts = {}) => {
3631
+ if (opts.lengthDelimited !== false) {
3632
+ w.fork();
3633
+ }
3634
+ if (obj.numPeers != null) {
3635
+ w.uint32(8);
3636
+ w.uint64(obj.numPeers);
3637
+ }
3638
+ if (opts.lengthDelimited !== false) {
3639
+ w.ldelim();
3640
+ }
3641
+ }, (reader, length, opts = {}) => {
3642
+ const obj = {};
3643
+ const end = length == null ? reader.len : reader.pos + length;
3644
+ while (reader.pos < end) {
3645
+ const tag = reader.uint32();
3646
+ switch (tag >>> 3) {
3647
+ case 1: {
3648
+ obj.numPeers = reader.uint64();
3649
+ break;
3650
+ }
3651
+ default: {
3652
+ reader.skipType(tag & 7);
3653
+ break;
3654
+ }
3655
+ }
3656
+ }
3657
+ return obj;
3658
+ });
3659
+ }
3660
+ return _codec;
3661
+ };
3662
+ PeerExchangeQuery.encode = (obj) => {
3663
+ return encodeMessage(obj, PeerExchangeQuery.codec());
3664
+ };
3665
+ PeerExchangeQuery.decode = (buf, opts) => {
3666
+ return decodeMessage(buf, PeerExchangeQuery.codec(), opts);
3667
+ };
3668
+ })(PeerExchangeQuery || (PeerExchangeQuery = {}));
3669
+ var PeerExchangeResponse;
3670
+ (function (PeerExchangeResponse) {
3671
+ let _codec;
3672
+ PeerExchangeResponse.codec = () => {
3673
+ if (_codec == null) {
3674
+ _codec = message$1((obj, w, opts = {}) => {
3675
+ if (opts.lengthDelimited !== false) {
3676
+ w.fork();
3677
+ }
3678
+ if (obj.peerInfos != null) {
3679
+ for (const value of obj.peerInfos) {
3680
+ w.uint32(10);
3681
+ PeerInfo.codec().encode(value, w);
3682
+ }
3683
+ }
3684
+ if (opts.lengthDelimited !== false) {
3685
+ w.ldelim();
3686
+ }
3687
+ }, (reader, length, opts = {}) => {
3688
+ const obj = {
3689
+ peerInfos: []
3690
+ };
3691
+ const end = length == null ? reader.len : reader.pos + length;
3692
+ while (reader.pos < end) {
3693
+ const tag = reader.uint32();
3694
+ switch (tag >>> 3) {
3695
+ case 1: {
3696
+ if (opts.limits?.peerInfos != null && obj.peerInfos.length === opts.limits.peerInfos) {
3697
+ throw new CodeError('decode error - map field "peerInfos" had too many elements', 'ERR_MAX_LENGTH');
3698
+ }
3699
+ obj.peerInfos.push(PeerInfo.codec().decode(reader, reader.uint32(), {
3700
+ limits: opts.limits?.peerInfos$
3701
+ }));
3702
+ break;
3703
+ }
3704
+ default: {
3705
+ reader.skipType(tag & 7);
3706
+ break;
3707
+ }
3708
+ }
3709
+ }
3710
+ return obj;
3711
+ });
3712
+ }
3713
+ return _codec;
3714
+ };
3715
+ PeerExchangeResponse.encode = (obj) => {
3716
+ return encodeMessage(obj, PeerExchangeResponse.codec());
3717
+ };
3718
+ PeerExchangeResponse.decode = (buf, opts) => {
3719
+ return decodeMessage(buf, PeerExchangeResponse.codec(), opts);
3720
+ };
3721
+ })(PeerExchangeResponse || (PeerExchangeResponse = {}));
3722
+ var PeerExchangeRPC;
3723
+ (function (PeerExchangeRPC) {
3724
+ let _codec;
3725
+ PeerExchangeRPC.codec = () => {
3726
+ if (_codec == null) {
3727
+ _codec = message$1((obj, w, opts = {}) => {
3728
+ if (opts.lengthDelimited !== false) {
3729
+ w.fork();
3730
+ }
3731
+ if (obj.query != null) {
3732
+ w.uint32(10);
3733
+ PeerExchangeQuery.codec().encode(obj.query, w);
3734
+ }
3735
+ if (obj.response != null) {
3736
+ w.uint32(18);
3737
+ PeerExchangeResponse.codec().encode(obj.response, w);
3738
+ }
3739
+ if (opts.lengthDelimited !== false) {
3740
+ w.ldelim();
3741
+ }
3742
+ }, (reader, length, opts = {}) => {
3743
+ const obj = {};
3744
+ const end = length == null ? reader.len : reader.pos + length;
3745
+ while (reader.pos < end) {
3746
+ const tag = reader.uint32();
3747
+ switch (tag >>> 3) {
3748
+ case 1: {
3749
+ obj.query = PeerExchangeQuery.codec().decode(reader, reader.uint32(), {
3750
+ limits: opts.limits?.query
3751
+ });
3752
+ break;
3753
+ }
3754
+ case 2: {
3755
+ obj.response = PeerExchangeResponse.codec().decode(reader, reader.uint32(), {
3756
+ limits: opts.limits?.response
3757
+ });
3758
+ break;
3759
+ }
3760
+ default: {
3761
+ reader.skipType(tag & 7);
3762
+ break;
3763
+ }
3764
+ }
3765
+ }
3766
+ return obj;
3767
+ });
3768
+ }
3769
+ return _codec;
3770
+ };
3771
+ PeerExchangeRPC.encode = (obj) => {
3772
+ return encodeMessage(obj, PeerExchangeRPC.codec());
3773
+ };
3774
+ PeerExchangeRPC.decode = (buf, opts) => {
3775
+ return decodeMessage(buf, PeerExchangeRPC.codec(), opts);
3776
+ };
3777
+ })(PeerExchangeRPC || (PeerExchangeRPC = {}));
3778
+
3779
+ /* eslint-disable import/export */
3780
+ /* eslint-disable complexity */
3781
+ /* eslint-disable @typescript-eslint/no-namespace */
3782
+ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
3783
+ /* eslint-disable @typescript-eslint/no-empty-interface */
3784
+ var WakuMetadataRequest;
3785
+ (function (WakuMetadataRequest) {
3786
+ let _codec;
3787
+ WakuMetadataRequest.codec = () => {
3788
+ if (_codec == null) {
3789
+ _codec = message$1((obj, w, opts = {}) => {
3790
+ if (opts.lengthDelimited !== false) {
3791
+ w.fork();
3792
+ }
3793
+ if (obj.clusterId != null) {
3794
+ w.uint32(8);
3795
+ w.uint32(obj.clusterId);
3796
+ }
3797
+ if (obj.shards != null) {
3798
+ for (const value of obj.shards) {
3799
+ w.uint32(16);
3800
+ w.uint32(value);
3801
+ }
3802
+ }
3803
+ if (opts.lengthDelimited !== false) {
3804
+ w.ldelim();
3805
+ }
3806
+ }, (reader, length, opts = {}) => {
3807
+ const obj = {
3808
+ shards: []
3809
+ };
3810
+ const end = length == null ? reader.len : reader.pos + length;
3811
+ while (reader.pos < end) {
3812
+ const tag = reader.uint32();
3813
+ switch (tag >>> 3) {
3814
+ case 1: {
3815
+ obj.clusterId = reader.uint32();
3816
+ break;
3817
+ }
3818
+ case 2: {
3819
+ if (opts.limits?.shards != null && obj.shards.length === opts.limits.shards) {
3820
+ throw new CodeError('decode error - map field "shards" had too many elements', 'ERR_MAX_LENGTH');
3821
+ }
3822
+ obj.shards.push(reader.uint32());
3823
+ break;
3824
+ }
3825
+ default: {
3826
+ reader.skipType(tag & 7);
3827
+ break;
3828
+ }
3829
+ }
3830
+ }
3831
+ return obj;
3832
+ });
3833
+ }
3834
+ return _codec;
3835
+ };
3836
+ WakuMetadataRequest.encode = (obj) => {
3837
+ return encodeMessage(obj, WakuMetadataRequest.codec());
3838
+ };
3839
+ WakuMetadataRequest.decode = (buf, opts) => {
3840
+ return decodeMessage(buf, WakuMetadataRequest.codec(), opts);
3841
+ };
3842
+ })(WakuMetadataRequest || (WakuMetadataRequest = {}));
3843
+ var WakuMetadataResponse;
3844
+ (function (WakuMetadataResponse) {
3845
+ let _codec;
3846
+ WakuMetadataResponse.codec = () => {
3847
+ if (_codec == null) {
3848
+ _codec = message$1((obj, w, opts = {}) => {
3849
+ if (opts.lengthDelimited !== false) {
3850
+ w.fork();
3851
+ }
3852
+ if (obj.clusterId != null) {
3853
+ w.uint32(8);
3854
+ w.uint32(obj.clusterId);
3855
+ }
3856
+ if (obj.shards != null) {
3857
+ for (const value of obj.shards) {
3858
+ w.uint32(16);
3859
+ w.uint32(value);
3860
+ }
3861
+ }
3862
+ if (opts.lengthDelimited !== false) {
3863
+ w.ldelim();
3864
+ }
3865
+ }, (reader, length, opts = {}) => {
3866
+ const obj = {
3867
+ shards: []
3868
+ };
3869
+ const end = length == null ? reader.len : reader.pos + length;
3870
+ while (reader.pos < end) {
3871
+ const tag = reader.uint32();
3872
+ switch (tag >>> 3) {
3873
+ case 1: {
3874
+ obj.clusterId = reader.uint32();
3875
+ break;
3876
+ }
3877
+ case 2: {
3878
+ if (opts.limits?.shards != null && obj.shards.length === opts.limits.shards) {
3879
+ throw new CodeError('decode error - map field "shards" had too many elements', 'ERR_MAX_LENGTH');
3880
+ }
3881
+ obj.shards.push(reader.uint32());
3882
+ break;
3883
+ }
3884
+ default: {
3885
+ reader.skipType(tag & 7);
3886
+ break;
3887
+ }
3888
+ }
3889
+ }
3890
+ return obj;
3891
+ });
3892
+ }
3893
+ return _codec;
3894
+ };
3895
+ WakuMetadataResponse.encode = (obj) => {
3896
+ return encodeMessage(obj, WakuMetadataResponse.codec());
3897
+ };
3898
+ WakuMetadataResponse.decode = (buf, opts) => {
3899
+ return decodeMessage(buf, WakuMetadataResponse.codec(), opts);
3900
+ };
3901
+ })(WakuMetadataResponse || (WakuMetadataResponse = {}));
3902
+
3903
+ const log = new Logger("message:version-0");
3904
+ const OneMillion = BigInt(1_000_000);
3905
+ const Version = 0;
3906
+ class DecodedMessage {
3907
+ pubsubTopic;
3908
+ proto;
3909
+ constructor(pubsubTopic, proto) {
3910
+ this.pubsubTopic = pubsubTopic;
3911
+ this.proto = proto;
3912
+ }
3913
+ get ephemeral() {
3914
+ return Boolean(this.proto.ephemeral);
3915
+ }
3916
+ get payload() {
3917
+ return this.proto.payload;
3918
+ }
3919
+ get contentTopic() {
3920
+ return this.proto.contentTopic;
3921
+ }
3922
+ get _rawTimestamp() {
3923
+ return this.proto.timestamp;
3924
+ }
3925
+ get timestamp() {
3926
+ // In the case we receive a value that is bigger than JS's max number,
3927
+ // we catch the error and return undefined.
3928
+ try {
3929
+ if (this.proto.timestamp) {
3930
+ // nanoseconds 10^-9 to milliseconds 10^-3
3931
+ const timestamp = this.proto.timestamp / OneMillion;
3932
+ return new Date(Number(timestamp));
3933
+ }
3934
+ return;
3935
+ }
3936
+ catch (e) {
3937
+ return;
3938
+ }
3939
+ }
3940
+ get meta() {
3941
+ return this.proto.meta;
3942
+ }
3943
+ get version() {
3944
+ // https://rfc.vac.dev/spec/14/
3945
+ // > If omitted, the value SHOULD be interpreted as version 0.
3946
+ return this.proto.version ?? 0;
3947
+ }
3948
+ get rateLimitProof() {
3949
+ return this.proto.rateLimitProof;
3950
+ }
3951
+ }
3952
+ class Encoder {
3953
+ contentTopic;
3954
+ ephemeral;
3955
+ pubsubTopic;
3956
+ metaSetter;
3957
+ constructor(contentTopic, ephemeral = false, pubsubTopic, metaSetter) {
3958
+ this.contentTopic = contentTopic;
3959
+ this.ephemeral = ephemeral;
3960
+ this.pubsubTopic = pubsubTopic;
3961
+ this.metaSetter = metaSetter;
3962
+ if (!contentTopic || contentTopic === "") {
3963
+ throw new Error("Content topic must be specified");
3964
+ }
3965
+ }
3966
+ async toWire(message$1) {
3967
+ return WakuMessage$4.encode(await this.toProtoObj(message$1));
3968
+ }
3969
+ async toProtoObj(message) {
3970
+ const timestamp = message.timestamp ?? new Date();
3971
+ const protoMessage = {
3972
+ payload: message.payload,
3973
+ version: Version,
3974
+ contentTopic: this.contentTopic,
3975
+ timestamp: BigInt(timestamp.valueOf()) * OneMillion,
3976
+ meta: undefined,
3977
+ rateLimitProof: message.rateLimitProof,
3978
+ ephemeral: this.ephemeral
3979
+ };
3980
+ if (this.metaSetter) {
3981
+ const meta = this.metaSetter(protoMessage);
3982
+ return { ...protoMessage, meta };
3983
+ }
3984
+ return protoMessage;
3985
+ }
3986
+ }
3987
+ /**
3988
+ * Creates an encoder that encode messages without Waku level encryption or signature.
3989
+ *
3990
+ * An encoder is used to encode messages in the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
3991
+ * format to be sent over the Waku network. The resulting encoder can then be
3992
+ * pass to { @link @waku/interfaces!ISender.send } to automatically encode outgoing
3993
+ * messages.
3994
+ */
3995
+ function createEncoder({ pubsubTopic, pubsubTopicShardInfo, contentTopic, ephemeral, metaSetter }) {
3996
+ return new Encoder(contentTopic, ephemeral, determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo), metaSetter);
3997
+ }
3998
+ class Decoder {
3999
+ pubsubTopic;
4000
+ contentTopic;
4001
+ constructor(pubsubTopic, contentTopic) {
4002
+ this.pubsubTopic = pubsubTopic;
4003
+ this.contentTopic = contentTopic;
4004
+ if (!contentTopic || contentTopic === "") {
4005
+ throw new Error("Content topic must be specified");
4006
+ }
4007
+ }
4008
+ fromWireToProtoObj(bytes) {
4009
+ const protoMessage = WakuMessage$4.decode(bytes);
4010
+ return Promise.resolve({
4011
+ payload: protoMessage.payload,
4012
+ contentTopic: protoMessage.contentTopic,
4013
+ version: protoMessage.version ?? undefined,
4014
+ timestamp: protoMessage.timestamp ?? undefined,
4015
+ meta: protoMessage.meta ?? undefined,
4016
+ rateLimitProof: protoMessage.rateLimitProof ?? undefined,
4017
+ ephemeral: protoMessage.ephemeral ?? false
4018
+ });
4019
+ }
4020
+ async fromProtoObj(pubsubTopic, proto) {
4021
+ // https://rfc.vac.dev/spec/14/
4022
+ // > If omitted, the value SHOULD be interpreted as version 0.
4023
+ if (proto.version ?? 0 !== Version) {
4024
+ log.error("Failed to decode due to incorrect version, expected:", Version, ", actual:", proto.version);
4025
+ return Promise.resolve(undefined);
4026
+ }
4027
+ return new DecodedMessage(pubsubTopic, proto);
4028
+ }
4029
+ }
4030
+ /**
4031
+ * Creates a decoder that decode messages without Waku level encryption.
4032
+ *
4033
+ * A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
4034
+ * format when received from the Waku network. The resulting decoder can then be
4035
+ * pass to { @link @waku/interfaces!IReceiver.subscribe } to automatically decode incoming
4036
+ * messages.
4037
+ *
4038
+ * @param contentTopic The resulting decoder will only decode messages with this content topic.
4039
+ */
4040
+ function createDecoder(contentTopic, pubsubTopicShardInfo) {
4041
+ return new Decoder(determinePubsubTopic(contentTopic, pubsubTopicShardInfo), contentTopic);
4042
+ }
4043
+
4044
+ var version_0 = /*#__PURE__*/Object.freeze({
4045
+ __proto__: null,
4046
+ DecodedMessage: DecodedMessage,
4047
+ Decoder: Decoder,
4048
+ Encoder: Encoder,
4049
+ Version: Version,
4050
+ createDecoder: createDecoder,
4051
+ createEncoder: createEncoder,
4052
+ proto: message
4053
+ });
4054
+
4055
+ export { DecodedMessage as D, Encoder as E, FilterSubscribeRequest as F, HistoryRpc$1 as H, MessagePush as M, PushRpc$1 as P, Version as V, WakuMetadataResponse as W, encode as a, FilterSubscribeResponse$1 as b, PushResponse as c, decode as d, encodingLength as e, PagingInfo as f, HistoryResponse as g, createEncoder as h, WakuMetadataRequest as i, createDecoder as j, Decoder as k, message as m, version_0 as v };