@waku/core 0.0.37-7a9850d.0 → 0.0.37-c24842a.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 (49) hide show
  1. package/bundle/index.js +4852 -904
  2. package/bundle/lib/message/version_0.js +1 -1
  3. package/bundle/{version_0-9DPFjcJG.js → version_0-BHaZD8Qu.js} +485 -60
  4. package/dist/.tsbuildinfo +1 -1
  5. package/dist/lib/connection_manager/connection_limiter.d.ts +46 -0
  6. package/dist/lib/connection_manager/connection_limiter.js +177 -0
  7. package/dist/lib/connection_manager/connection_limiter.js.map +1 -0
  8. package/dist/lib/connection_manager/connection_manager.d.ts +18 -106
  9. package/dist/lib/connection_manager/connection_manager.js +95 -512
  10. package/dist/lib/connection_manager/connection_manager.js.map +1 -1
  11. package/dist/lib/connection_manager/dialer.d.ts +34 -0
  12. package/dist/lib/connection_manager/dialer.js +135 -0
  13. package/dist/lib/connection_manager/dialer.js.map +1 -0
  14. package/dist/lib/connection_manager/discovery_dialer.d.ts +26 -0
  15. package/dist/lib/connection_manager/discovery_dialer.js +68 -0
  16. package/dist/lib/connection_manager/discovery_dialer.js.map +1 -0
  17. package/dist/lib/connection_manager/keep_alive_manager.d.ts +17 -7
  18. package/dist/lib/connection_manager/keep_alive_manager.js +110 -74
  19. package/dist/lib/connection_manager/keep_alive_manager.js.map +1 -1
  20. package/dist/lib/connection_manager/network_monitor.d.ts +36 -0
  21. package/dist/lib/connection_manager/network_monitor.js +81 -0
  22. package/dist/lib/connection_manager/network_monitor.js.map +1 -0
  23. package/dist/lib/connection_manager/shard_reader.d.ts +28 -0
  24. package/dist/lib/connection_manager/shard_reader.js +70 -0
  25. package/dist/lib/connection_manager/shard_reader.js.map +1 -0
  26. package/dist/lib/connection_manager/utils.d.ts +16 -1
  27. package/dist/lib/connection_manager/utils.js +23 -0
  28. package/dist/lib/connection_manager/utils.js.map +1 -1
  29. package/dist/lib/filter/filter.d.ts +2 -3
  30. package/dist/lib/filter/filter.js +5 -25
  31. package/dist/lib/filter/filter.js.map +1 -1
  32. package/dist/lib/light_push/light_push.d.ts +2 -3
  33. package/dist/lib/light_push/light_push.js +1 -3
  34. package/dist/lib/light_push/light_push.js.map +1 -1
  35. package/dist/lib/metadata/metadata.d.ts +2 -2
  36. package/dist/lib/metadata/metadata.js +14 -8
  37. package/dist/lib/metadata/metadata.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/lib/connection_manager/connection_limiter.ts +292 -0
  40. package/src/lib/connection_manager/connection_manager.ts +112 -673
  41. package/src/lib/connection_manager/dialer.ts +192 -0
  42. package/src/lib/connection_manager/discovery_dialer.ts +104 -0
  43. package/src/lib/connection_manager/keep_alive_manager.ts +154 -87
  44. package/src/lib/connection_manager/network_monitor.ts +112 -0
  45. package/src/lib/connection_manager/shard_reader.ts +134 -0
  46. package/src/lib/connection_manager/utils.ts +27 -1
  47. package/src/lib/filter/filter.ts +3 -28
  48. package/src/lib/light_push/light_push.ts +1 -5
  49. package/src/lib/metadata/metadata.ts +13 -12
@@ -1 +1 @@
1
- export { K as DecodedMessage, O as Decoder, N as Encoder, V as Version, I as createDecoder, s as createEncoder, J as proto } from '../../version_0-9DPFjcJG.js';
1
+ export { a5 as DecodedMessage, a7 as Decoder, a6 as Encoder, a3 as Version, a2 as createDecoder, o as createEncoder, a4 as proto } from '../../version_0-BHaZD8Qu.js';
@@ -3379,6 +3379,18 @@ var PushResponse;
3379
3379
  w.uint32(18);
3380
3380
  w.string(obj.info);
3381
3381
  }
3382
+ if (obj.statusCode != null) {
3383
+ w.uint32(80);
3384
+ w.uint32(obj.statusCode);
3385
+ }
3386
+ if (obj.statusDesc != null) {
3387
+ w.uint32(90);
3388
+ w.string(obj.statusDesc);
3389
+ }
3390
+ if (obj.relayPeerCount != null) {
3391
+ w.uint32(96);
3392
+ w.uint32(obj.relayPeerCount);
3393
+ }
3382
3394
  if (opts.lengthDelimited !== false) {
3383
3395
  w.ldelim();
3384
3396
  }
@@ -3398,6 +3410,18 @@ var PushResponse;
3398
3410
  obj.info = reader.string();
3399
3411
  break;
3400
3412
  }
3413
+ case 10: {
3414
+ obj.statusCode = reader.uint32();
3415
+ break;
3416
+ }
3417
+ case 11: {
3418
+ obj.statusDesc = reader.string();
3419
+ break;
3420
+ }
3421
+ case 12: {
3422
+ obj.relayPeerCount = reader.uint32();
3423
+ break;
3424
+ }
3401
3425
  default: {
3402
3426
  reader.skipType(tag & 7);
3403
3427
  break;
@@ -3482,6 +3506,141 @@ var PushRpc$1;
3482
3506
  return decodeMessage(buf, PushRpc.codec(), opts);
3483
3507
  };
3484
3508
  })(PushRpc$1 || (PushRpc$1 = {}));
3509
+ var LightPushRequestV3;
3510
+ (function (LightPushRequestV3) {
3511
+ let _codec;
3512
+ LightPushRequestV3.codec = () => {
3513
+ if (_codec == null) {
3514
+ _codec = message$1((obj, w, opts = {}) => {
3515
+ if (opts.lengthDelimited !== false) {
3516
+ w.fork();
3517
+ }
3518
+ if ((obj.requestId != null && obj.requestId !== '')) {
3519
+ w.uint32(10);
3520
+ w.string(obj.requestId);
3521
+ }
3522
+ if (obj.pubsubTopic != null) {
3523
+ w.uint32(162);
3524
+ w.string(obj.pubsubTopic);
3525
+ }
3526
+ if (obj.message != null) {
3527
+ w.uint32(170);
3528
+ WakuMessage$1.codec().encode(obj.message, w);
3529
+ }
3530
+ if (opts.lengthDelimited !== false) {
3531
+ w.ldelim();
3532
+ }
3533
+ }, (reader, length, opts = {}) => {
3534
+ const obj = {
3535
+ requestId: ''
3536
+ };
3537
+ const end = length == null ? reader.len : reader.pos + length;
3538
+ while (reader.pos < end) {
3539
+ const tag = reader.uint32();
3540
+ switch (tag >>> 3) {
3541
+ case 1: {
3542
+ obj.requestId = reader.string();
3543
+ break;
3544
+ }
3545
+ case 20: {
3546
+ obj.pubsubTopic = reader.string();
3547
+ break;
3548
+ }
3549
+ case 21: {
3550
+ obj.message = WakuMessage$1.codec().decode(reader, reader.uint32(), {
3551
+ limits: opts.limits?.message
3552
+ });
3553
+ break;
3554
+ }
3555
+ default: {
3556
+ reader.skipType(tag & 7);
3557
+ break;
3558
+ }
3559
+ }
3560
+ }
3561
+ return obj;
3562
+ });
3563
+ }
3564
+ return _codec;
3565
+ };
3566
+ LightPushRequestV3.encode = (obj) => {
3567
+ return encodeMessage(obj, LightPushRequestV3.codec());
3568
+ };
3569
+ LightPushRequestV3.decode = (buf, opts) => {
3570
+ return decodeMessage(buf, LightPushRequestV3.codec(), opts);
3571
+ };
3572
+ })(LightPushRequestV3 || (LightPushRequestV3 = {}));
3573
+ var LightPushResponseV3;
3574
+ (function (LightPushResponseV3) {
3575
+ let _codec;
3576
+ LightPushResponseV3.codec = () => {
3577
+ if (_codec == null) {
3578
+ _codec = message$1((obj, w, opts = {}) => {
3579
+ if (opts.lengthDelimited !== false) {
3580
+ w.fork();
3581
+ }
3582
+ if ((obj.requestId != null && obj.requestId !== '')) {
3583
+ w.uint32(10);
3584
+ w.string(obj.requestId);
3585
+ }
3586
+ if ((obj.statusCode != null && obj.statusCode !== 0)) {
3587
+ w.uint32(80);
3588
+ w.uint32(obj.statusCode);
3589
+ }
3590
+ if (obj.statusDesc != null) {
3591
+ w.uint32(90);
3592
+ w.string(obj.statusDesc);
3593
+ }
3594
+ if (obj.relayPeerCount != null) {
3595
+ w.uint32(96);
3596
+ w.uint32(obj.relayPeerCount);
3597
+ }
3598
+ if (opts.lengthDelimited !== false) {
3599
+ w.ldelim();
3600
+ }
3601
+ }, (reader, length, opts = {}) => {
3602
+ const obj = {
3603
+ requestId: '',
3604
+ statusCode: 0
3605
+ };
3606
+ const end = length == null ? reader.len : reader.pos + length;
3607
+ while (reader.pos < end) {
3608
+ const tag = reader.uint32();
3609
+ switch (tag >>> 3) {
3610
+ case 1: {
3611
+ obj.requestId = reader.string();
3612
+ break;
3613
+ }
3614
+ case 10: {
3615
+ obj.statusCode = reader.uint32();
3616
+ break;
3617
+ }
3618
+ case 11: {
3619
+ obj.statusDesc = reader.string();
3620
+ break;
3621
+ }
3622
+ case 12: {
3623
+ obj.relayPeerCount = reader.uint32();
3624
+ break;
3625
+ }
3626
+ default: {
3627
+ reader.skipType(tag & 7);
3628
+ break;
3629
+ }
3630
+ }
3631
+ }
3632
+ return obj;
3633
+ });
3634
+ }
3635
+ return _codec;
3636
+ };
3637
+ LightPushResponseV3.encode = (obj) => {
3638
+ return encodeMessage(obj, LightPushResponseV3.codec());
3639
+ };
3640
+ LightPushResponseV3.decode = (buf, opts) => {
3641
+ return decodeMessage(buf, LightPushResponseV3.codec(), opts);
3642
+ };
3643
+ })(LightPushResponseV3 || (LightPushResponseV3 = {}));
3485
3644
  var RateLimitProof$1;
3486
3645
  (function (RateLimitProof) {
3487
3646
  let _codec;
@@ -4653,6 +4812,8 @@ var SdsMessage;
4653
4812
  };
4654
4813
  })(SdsMessage || (SdsMessage = {}));
4655
4814
 
4815
+ const crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
4816
+
4656
4817
  /**
4657
4818
  * Utilities for hex, bytes, CSPRNG.
4658
4819
  * @module
@@ -4668,6 +4829,11 @@ var SdsMessage;
4668
4829
  function isBytes(a) {
4669
4830
  return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
4670
4831
  }
4832
+ /** Asserts something is positive integer. */
4833
+ function anumber(n) {
4834
+ if (!Number.isSafeInteger(n) || n < 0)
4835
+ throw new Error('positive integer expected, got ' + n);
4836
+ }
4671
4837
  /** Asserts something is Uint8Array. */
4672
4838
  function abytes(b, ...lengths) {
4673
4839
  if (!isBytes(b))
@@ -4675,6 +4841,13 @@ function abytes(b, ...lengths) {
4675
4841
  if (lengths.length > 0 && !lengths.includes(b.length))
4676
4842
  throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
4677
4843
  }
4844
+ /** Asserts something is hash */
4845
+ function ahash(h) {
4846
+ if (typeof h !== 'function' || typeof h.create !== 'function')
4847
+ throw new Error('Hash should be wrapped by utils.createHasher');
4848
+ anumber(h.outputLen);
4849
+ anumber(h.blockLen);
4850
+ }
4678
4851
  /** Asserts a hash instance has not been destroyed / finished */
4679
4852
  function aexists(instance, checkFinished = true) {
4680
4853
  if (instance.destroyed)
@@ -4704,6 +4877,65 @@ function createView(arr) {
4704
4877
  function rotr(word, shift) {
4705
4878
  return (word << (32 - shift)) | (word >>> shift);
4706
4879
  }
4880
+ // Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex
4881
+ const hasHexBuiltin = /* @__PURE__ */ (() =>
4882
+ // @ts-ignore
4883
+ typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();
4884
+ // Array where index 0xf0 (240) is mapped to string 'f0'
4885
+ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
4886
+ /**
4887
+ * Convert byte array to hex string. Uses built-in function, when available.
4888
+ * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
4889
+ */
4890
+ function bytesToHex$1(bytes) {
4891
+ abytes(bytes);
4892
+ // @ts-ignore
4893
+ if (hasHexBuiltin)
4894
+ return bytes.toHex();
4895
+ // pre-caching improves the speed 6x
4896
+ let hex = '';
4897
+ for (let i = 0; i < bytes.length; i++) {
4898
+ hex += hexes[bytes[i]];
4899
+ }
4900
+ return hex;
4901
+ }
4902
+ // We use optimized technique to convert hex string to byte array
4903
+ const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
4904
+ function asciiToBase16(ch) {
4905
+ if (ch >= asciis._0 && ch <= asciis._9)
4906
+ return ch - asciis._0; // '2' => 50-48
4907
+ if (ch >= asciis.A && ch <= asciis.F)
4908
+ return ch - (asciis.A - 10); // 'B' => 66-(65-10)
4909
+ if (ch >= asciis.a && ch <= asciis.f)
4910
+ return ch - (asciis.a - 10); // 'b' => 98-(97-10)
4911
+ return;
4912
+ }
4913
+ /**
4914
+ * Convert hex string to byte array. Uses built-in function, when available.
4915
+ * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
4916
+ */
4917
+ function hexToBytes(hex) {
4918
+ if (typeof hex !== 'string')
4919
+ throw new Error('hex string expected, got ' + typeof hex);
4920
+ // @ts-ignore
4921
+ if (hasHexBuiltin)
4922
+ return Uint8Array.fromHex(hex);
4923
+ const hl = hex.length;
4924
+ const al = hl / 2;
4925
+ if (hl % 2)
4926
+ throw new Error('hex string expected, got unpadded hex of length ' + hl);
4927
+ const array = new Uint8Array(al);
4928
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
4929
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
4930
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
4931
+ if (n1 === undefined || n2 === undefined) {
4932
+ const char = hex[hi] + hex[hi + 1];
4933
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
4934
+ }
4935
+ array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163
4936
+ }
4937
+ return array;
4938
+ }
4707
4939
  /**
4708
4940
  * Converts string to bytes using UTF8 encoding.
4709
4941
  * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
@@ -4724,6 +4956,22 @@ function toBytes(data) {
4724
4956
  abytes(data);
4725
4957
  return data;
4726
4958
  }
4959
+ /** Copies several Uint8Arrays into one. */
4960
+ function concatBytes(...arrays) {
4961
+ let sum = 0;
4962
+ for (let i = 0; i < arrays.length; i++) {
4963
+ const a = arrays[i];
4964
+ abytes(a);
4965
+ sum += a.length;
4966
+ }
4967
+ const res = new Uint8Array(sum);
4968
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
4969
+ const a = arrays[i];
4970
+ res.set(a, pad);
4971
+ pad += a.length;
4972
+ }
4973
+ return res;
4974
+ }
4727
4975
  /** For runtime check if class implements interface */
4728
4976
  class Hash {
4729
4977
  }
@@ -4736,6 +4984,17 @@ function createHasher(hashCons) {
4736
4984
  hashC.create = () => hashCons();
4737
4985
  return hashC;
4738
4986
  }
4987
+ /** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
4988
+ function randomBytes(bytesLength = 32) {
4989
+ if (crypto && typeof crypto.getRandomValues === 'function') {
4990
+ return crypto.getRandomValues(new Uint8Array(bytesLength));
4991
+ }
4992
+ // Legacy Node.js compatibility
4993
+ if (crypto && typeof crypto.randomBytes === 'function') {
4994
+ return Uint8Array.from(crypto.randomBytes(bytesLength));
4995
+ }
4996
+ throw new Error('crypto.getRandomValues must be defined');
4997
+ }
4739
4998
 
4740
4999
  /**
4741
5000
  * Internal Merkle-Damgard hash utils.
@@ -4876,6 +5135,56 @@ class HashMD extends Hash {
4876
5135
  const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
4877
5136
  0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
4878
5137
  ]);
5138
+ /** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */
5139
+ const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
5140
+ 0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1,
5141
+ 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,
5142
+ ]);
5143
+
5144
+ /**
5145
+ * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
5146
+ * @todo re-check https://issues.chromium.org/issues/42212588
5147
+ * @module
5148
+ */
5149
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
5150
+ const _32n = /* @__PURE__ */ BigInt(32);
5151
+ function fromBig(n, le = false) {
5152
+ if (le)
5153
+ return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
5154
+ return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
5155
+ }
5156
+ function split(lst, le = false) {
5157
+ const len = lst.length;
5158
+ let Ah = new Uint32Array(len);
5159
+ let Al = new Uint32Array(len);
5160
+ for (let i = 0; i < len; i++) {
5161
+ const { h, l } = fromBig(lst[i], le);
5162
+ [Ah[i], Al[i]] = [h, l];
5163
+ }
5164
+ return [Ah, Al];
5165
+ }
5166
+ // for Shift in [0, 32)
5167
+ const shrSH = (h, _l, s) => h >>> s;
5168
+ const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
5169
+ // Right rotate for Shift in [1, 32)
5170
+ const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
5171
+ const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
5172
+ // Right rotate for Shift in (32, 64), NOTE: 32 is special case.
5173
+ const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
5174
+ const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
5175
+ // JS uses 32-bit signed integers for bitwise operations which means we cannot
5176
+ // simple take carry out of low bit sum by shift, we need to use division.
5177
+ function add(Ah, Al, Bh, Bl) {
5178
+ const l = (Al >>> 0) + (Bl >>> 0);
5179
+ return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
5180
+ }
5181
+ // Addition with more than 2 elements
5182
+ const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
5183
+ const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
5184
+ const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
5185
+ const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
5186
+ const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
5187
+ const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
4879
5188
 
4880
5189
  /**
4881
5190
  * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
@@ -4976,6 +5285,162 @@ class SHA256 extends HashMD {
4976
5285
  clean(this.buffer);
4977
5286
  }
4978
5287
  }
5288
+ // SHA2-512 is slower than sha256 in js because u64 operations are slow.
5289
+ // Round contants
5290
+ // First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409
5291
+ // prettier-ignore
5292
+ const K512 = /* @__PURE__ */ (() => split([
5293
+ '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
5294
+ '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
5295
+ '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
5296
+ '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
5297
+ '0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
5298
+ '0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
5299
+ '0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
5300
+ '0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
5301
+ '0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
5302
+ '0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
5303
+ '0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
5304
+ '0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
5305
+ '0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
5306
+ '0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
5307
+ '0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
5308
+ '0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
5309
+ '0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
5310
+ '0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
5311
+ '0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
5312
+ '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
5313
+ ].map(n => BigInt(n))))();
5314
+ const SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
5315
+ const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
5316
+ // Reusable temporary buffers
5317
+ const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
5318
+ const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
5319
+ class SHA512 extends HashMD {
5320
+ constructor(outputLen = 64) {
5321
+ super(128, outputLen, 16, false);
5322
+ // We cannot use array here since array allows indexing by variable
5323
+ // which means optimizer/compiler cannot use registers.
5324
+ // h -- high 32 bits, l -- low 32 bits
5325
+ this.Ah = SHA512_IV[0] | 0;
5326
+ this.Al = SHA512_IV[1] | 0;
5327
+ this.Bh = SHA512_IV[2] | 0;
5328
+ this.Bl = SHA512_IV[3] | 0;
5329
+ this.Ch = SHA512_IV[4] | 0;
5330
+ this.Cl = SHA512_IV[5] | 0;
5331
+ this.Dh = SHA512_IV[6] | 0;
5332
+ this.Dl = SHA512_IV[7] | 0;
5333
+ this.Eh = SHA512_IV[8] | 0;
5334
+ this.El = SHA512_IV[9] | 0;
5335
+ this.Fh = SHA512_IV[10] | 0;
5336
+ this.Fl = SHA512_IV[11] | 0;
5337
+ this.Gh = SHA512_IV[12] | 0;
5338
+ this.Gl = SHA512_IV[13] | 0;
5339
+ this.Hh = SHA512_IV[14] | 0;
5340
+ this.Hl = SHA512_IV[15] | 0;
5341
+ }
5342
+ // prettier-ignore
5343
+ get() {
5344
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
5345
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
5346
+ }
5347
+ // prettier-ignore
5348
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
5349
+ this.Ah = Ah | 0;
5350
+ this.Al = Al | 0;
5351
+ this.Bh = Bh | 0;
5352
+ this.Bl = Bl | 0;
5353
+ this.Ch = Ch | 0;
5354
+ this.Cl = Cl | 0;
5355
+ this.Dh = Dh | 0;
5356
+ this.Dl = Dl | 0;
5357
+ this.Eh = Eh | 0;
5358
+ this.El = El | 0;
5359
+ this.Fh = Fh | 0;
5360
+ this.Fl = Fl | 0;
5361
+ this.Gh = Gh | 0;
5362
+ this.Gl = Gl | 0;
5363
+ this.Hh = Hh | 0;
5364
+ this.Hl = Hl | 0;
5365
+ }
5366
+ process(view, offset) {
5367
+ // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
5368
+ for (let i = 0; i < 16; i++, offset += 4) {
5369
+ SHA512_W_H[i] = view.getUint32(offset);
5370
+ SHA512_W_L[i] = view.getUint32((offset += 4));
5371
+ }
5372
+ for (let i = 16; i < 80; i++) {
5373
+ // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
5374
+ const W15h = SHA512_W_H[i - 15] | 0;
5375
+ const W15l = SHA512_W_L[i - 15] | 0;
5376
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
5377
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
5378
+ // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
5379
+ const W2h = SHA512_W_H[i - 2] | 0;
5380
+ const W2l = SHA512_W_L[i - 2] | 0;
5381
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
5382
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
5383
+ // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
5384
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
5385
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
5386
+ SHA512_W_H[i] = SUMh | 0;
5387
+ SHA512_W_L[i] = SUMl | 0;
5388
+ }
5389
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
5390
+ // Compression function main loop, 80 rounds
5391
+ for (let i = 0; i < 80; i++) {
5392
+ // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
5393
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
5394
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
5395
+ //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
5396
+ const CHIh = (Eh & Fh) ^ (~Eh & Gh);
5397
+ const CHIl = (El & Fl) ^ (~El & Gl);
5398
+ // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
5399
+ // prettier-ignore
5400
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
5401
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
5402
+ const T1l = T1ll | 0;
5403
+ // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
5404
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
5405
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
5406
+ const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
5407
+ const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
5408
+ Hh = Gh | 0;
5409
+ Hl = Gl | 0;
5410
+ Gh = Fh | 0;
5411
+ Gl = Fl | 0;
5412
+ Fh = Eh | 0;
5413
+ Fl = El | 0;
5414
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
5415
+ Dh = Ch | 0;
5416
+ Dl = Cl | 0;
5417
+ Ch = Bh | 0;
5418
+ Cl = Bl | 0;
5419
+ Bh = Ah | 0;
5420
+ Bl = Al | 0;
5421
+ const All = add3L(T1l, sigma0l, MAJl);
5422
+ Ah = add3H(All, T1h, sigma0h, MAJh);
5423
+ Al = All | 0;
5424
+ }
5425
+ // Add the compressed chunk to the current hash value
5426
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
5427
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
5428
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
5429
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
5430
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
5431
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
5432
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
5433
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
5434
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
5435
+ }
5436
+ roundClean() {
5437
+ clean(SHA512_W_H, SHA512_W_L);
5438
+ }
5439
+ destroy() {
5440
+ clean(this.buffer);
5441
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
5442
+ }
5443
+ }
4979
5444
  /**
4980
5445
  * SHA2-256 hash function from RFC 4634.
4981
5446
  *
@@ -4984,6 +5449,8 @@ class SHA256 extends HashMD {
4984
5449
  * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
4985
5450
  */
4986
5451
  const sha256$1 = /* @__PURE__ */ createHasher(() => new SHA256());
5452
+ /** SHA2-512 hash function from RFC 4634. */
5453
+ const sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
4987
5454
 
4988
5455
  /**
4989
5456
  * SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.
@@ -5089,37 +5556,34 @@ var ProtocolError;
5089
5556
  ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
5090
5557
  })(ProtocolError || (ProtocolError = {}));
5091
5558
 
5559
+ // Peer tags
5092
5560
  var Tags;
5093
5561
  (function (Tags) {
5094
5562
  Tags["BOOTSTRAP"] = "bootstrap";
5095
5563
  Tags["PEER_EXCHANGE"] = "peer-exchange";
5096
5564
  Tags["LOCAL"] = "local-peer-cache";
5097
5565
  })(Tags || (Tags = {}));
5098
- var EPeersByDiscoveryEvents;
5099
- (function (EPeersByDiscoveryEvents) {
5100
- EPeersByDiscoveryEvents["PEER_DISCOVERY_BOOTSTRAP"] = "peer:discovery:bootstrap";
5101
- EPeersByDiscoveryEvents["PEER_DISCOVERY_PEER_EXCHANGE"] = "peer:discovery:peer-exchange";
5102
- EPeersByDiscoveryEvents["PEER_CONNECT_BOOTSTRAP"] = "peer:connected:bootstrap";
5103
- EPeersByDiscoveryEvents["PEER_CONNECT_PEER_EXCHANGE"] = "peer:connected:peer-exchange";
5104
- })(EPeersByDiscoveryEvents || (EPeersByDiscoveryEvents = {}));
5105
- var EConnectionStateEvents;
5106
- (function (EConnectionStateEvents) {
5107
- EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
5108
- })(EConnectionStateEvents || (EConnectionStateEvents = {}));
5566
+ // Connection tag
5567
+ const CONNECTION_LOCKED_TAG = "locked";
5109
5568
 
5110
5569
  /**
5111
5570
  * The default cluster ID for The Waku Network
5112
5571
  */
5113
5572
  const DEFAULT_CLUSTER_ID = 1;
5114
5573
 
5115
- var HealthStatusChangeEvents;
5116
- (function (HealthStatusChangeEvents) {
5117
- HealthStatusChangeEvents["StatusChange"] = "health:change";
5118
- })(HealthStatusChangeEvents || (HealthStatusChangeEvents = {}));
5119
5574
  var HealthStatus;
5120
5575
  (function (HealthStatus) {
5576
+ /**
5577
+ * No peer connections
5578
+ */
5121
5579
  HealthStatus["Unhealthy"] = "Unhealthy";
5580
+ /**
5581
+ * At least 1 peer supporting both Filter and LightPush protocols
5582
+ */
5122
5583
  HealthStatus["MinimallyHealthy"] = "MinimallyHealthy";
5584
+ /**
5585
+ * At least 2 peers supporting both Filter and LightPush protocols
5586
+ */
5123
5587
  HealthStatus["SufficientlyHealthy"] = "SufficientlyHealthy";
5124
5588
  })(HealthStatus || (HealthStatus = {}));
5125
5589
 
@@ -5181,27 +5645,9 @@ const singleShardInfoToPubsubTopic = (shardInfo) => {
5181
5645
  throw new Error("Invalid shard");
5182
5646
  return `/waku/2/rs/${shardInfo.clusterId ?? DEFAULT_CLUSTER_ID}/${shardInfo.shard}`;
5183
5647
  };
5184
- const shardInfoToPubsubTopics = (shardInfo) => {
5185
- if ("contentTopics" in shardInfo && shardInfo.contentTopics) {
5186
- // Autosharding: explicitly defined content topics
5187
- return Array.from(new Set(shardInfo.contentTopics.map((contentTopic) => contentTopicToPubsubTopic(contentTopic, shardInfo.clusterId))));
5188
- }
5189
- else if ("shards" in shardInfo) {
5190
- // Static sharding
5191
- if (shardInfo.shards === undefined)
5192
- throw new Error("Invalid shard");
5193
- return Array.from(new Set(shardInfo.shards.map((index) => `/waku/2/rs/${shardInfo.clusterId ?? DEFAULT_CLUSTER_ID}/${index}`)));
5194
- }
5195
- else if ("application" in shardInfo && "version" in shardInfo) {
5196
- // Autosharding: single shard from application and version
5197
- return [
5198
- contentTopicToPubsubTopic(`/${shardInfo.application}/${shardInfo.version}/default/default`, shardInfo.clusterId)
5199
- ];
5200
- }
5201
- else {
5202
- throw new Error("Missing required configuration in shard parameters");
5203
- }
5204
- };
5648
+ /**
5649
+ * @deprecated will be removed
5650
+ */
5205
5651
  const pubsubTopicToSingleShardInfo = (pubsubTopics) => {
5206
5652
  const parts = pubsubTopics.split("/");
5207
5653
  if (parts.length != 6 ||
@@ -5218,27 +5664,6 @@ const pubsubTopicToSingleShardInfo = (pubsubTopics) => {
5218
5664
  shard
5219
5665
  };
5220
5666
  };
5221
- const pubsubTopicsToShardInfo = (pubsubTopics) => {
5222
- const shardInfoSet = new Set();
5223
- const clusterIds = new Set();
5224
- for (const topic of pubsubTopics) {
5225
- const { clusterId, shard } = pubsubTopicToSingleShardInfo(topic);
5226
- shardInfoSet.add(`${clusterId}:${shard}`);
5227
- clusterIds.add(clusterId);
5228
- }
5229
- if (shardInfoSet.size === 0) {
5230
- throw new Error("No valid pubsub topics provided");
5231
- }
5232
- if (clusterIds.size > 1) {
5233
- throw new Error("Pubsub topics from multiple cluster IDs are not supported");
5234
- }
5235
- const clusterId = clusterIds.values().next().value;
5236
- const shards = Array.from(shardInfoSet).map((info) => parseInt(info.split(":")[1]));
5237
- return {
5238
- clusterId,
5239
- shards
5240
- };
5241
- };
5242
5667
  /**
5243
5668
  * Given a string, will throw an error if it is not formatted as a valid content topic for autosharding based on https://rfc.vac.dev/spec/51/
5244
5669
  * @param contentTopic String to validate
@@ -6070,7 +6495,7 @@ class Logger {
6070
6495
  _warn;
6071
6496
  _error;
6072
6497
  static createDebugNamespace(level, prefix) {
6073
- return prefix ? `${APP_NAME}:${level}:${prefix}` : `${APP_NAME}:${level}`;
6498
+ return prefix ? `${APP_NAME}:${prefix}:${level}` : `${APP_NAME}:${level}`;
6074
6499
  }
6075
6500
  constructor(prefix) {
6076
6501
  this._info = debug(Logger.createDebugNamespace("info", prefix));
@@ -6087,7 +6512,7 @@ class Logger {
6087
6512
  return this._error;
6088
6513
  }
6089
6514
  log(level, ...args) {
6090
- const logger = this[level];
6515
+ const logger = this[level] || this.log;
6091
6516
  logger(...args);
6092
6517
  }
6093
6518
  }
@@ -6241,4 +6666,4 @@ var version_0 = /*#__PURE__*/Object.freeze({
6241
6666
  proto: message
6242
6667
  });
6243
6668
 
6244
- export { pubsubTopicsToShardInfo as A, WakuMetadataResponse as B, concat as C, sha256 as D, EPeersByDiscoveryEvents as E, FilterSubscribeRequest as F, bytesToHex as G, numberToBytes as H, createDecoder as I, message as J, DecodedMessage as K, Logger as L, MessagePush as M, Encoder as N, Decoder as O, ProtocolError as P, StoreQueryRequest$1 as S, Tags as T, Version as V, WakuMetadataRequest as W, base58btc as a, base32 as b, coerce as c, base36 as d, equals as e, allocUnsafe as f, alloc$1 as g, encodingLength as h, encode$2 as i, decode$2 as j, FilterSubscribeResponse$1 as k, PushRpc$1 as l, PushResponse as m, StoreQueryResponse$1 as n, bases as o, fromString as p, base64url as q, encodeUint8Array as r, createEncoder as s, toString as t, utf8ToBytes as u, version_0 as v, pubsubTopicToSingleShardInfo as w, bytesToUtf8 as x, shardInfoToPubsubTopics as y, EConnectionStateEvents as z };
6669
+ export { sha256 as $, anumber as A, randomBytes as B, CONNECTION_LOCKED_TAG as C, sha512 as D, enumeration as E, FilterSubscribeRequest as F, message$1 as G, encodeMessage as H, decodeMessage as I, Hash as J, ahash as K, Logger as L, MessagePush as M, toBytes as N, clean as O, ProtocolError as P, aexists as Q, sha256$1 as R, StoreQueryRequest$1 as S, Tags as T, bases as U, base64url as V, encodeUint8Array as W, bytesToUtf8 as X, WakuMetadataRequest as Y, WakuMetadataResponse as Z, concat as _, base58btc as a, bytesToHex as a0, numberToBytes as a1, createDecoder as a2, Version as a3, message as a4, DecodedMessage as a5, Encoder as a6, Decoder as a7, base32 as b, coerce as c, base36 as d, equals as e, allocUnsafe as f, alloc$1 as g, encodingLength as h, encode$2 as i, decode$2 as j, FilterSubscribeResponse$1 as k, PushRpc$1 as l, PushResponse as m, StoreQueryResponse$1 as n, createEncoder as o, pubsubTopicToSingleShardInfo as p, contentTopicToShardIndex as q, fromString as r, hexToBytes as s, toString as t, utf8ToBytes as u, version_0 as v, isBytes as w, abytes as x, bytesToHex$1 as y, concatBytes as z };