@waku/core 0.0.37-7a9850d.0 → 0.0.37-c7682ea.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 (45) hide show
  1. package/bundle/index.js +4745 -899
  2. package/bundle/lib/message/version_0.js +1 -1
  3. package/bundle/{version_0-9DPFjcJG.js → version_0-Bc0h7ah2.js} +312 -33
  4. package/dist/.tsbuildinfo +1 -1
  5. package/dist/lib/connection_manager/connection_limiter.d.ts +37 -0
  6. package/dist/lib/connection_manager/connection_limiter.js +124 -0
  7. package/dist/lib/connection_manager/connection_limiter.js.map +1 -0
  8. package/dist/lib/connection_manager/connection_manager.d.ts +20 -105
  9. package/dist/lib/connection_manager/connection_manager.js +83 -508
  10. package/dist/lib/connection_manager/connection_manager.js.map +1 -1
  11. package/dist/lib/connection_manager/dialer.d.ts +28 -0
  12. package/dist/lib/connection_manager/dialer.js +100 -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/package.json +1 -1
  36. package/src/lib/connection_manager/connection_limiter.ts +201 -0
  37. package/src/lib/connection_manager/connection_manager.ts +104 -669
  38. package/src/lib/connection_manager/dialer.ts +139 -0
  39. package/src/lib/connection_manager/discovery_dialer.ts +106 -0
  40. package/src/lib/connection_manager/keep_alive_manager.ts +154 -87
  41. package/src/lib/connection_manager/network_monitor.ts +112 -0
  42. package/src/lib/connection_manager/shard_reader.ts +134 -0
  43. package/src/lib/connection_manager/utils.ts +27 -1
  44. package/src/lib/filter/filter.ts +3 -28
  45. package/src/lib/light_push/light_push.ts +1 -5
@@ -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-Bc0h7ah2.js';
@@ -4653,6 +4653,8 @@ var SdsMessage;
4653
4653
  };
4654
4654
  })(SdsMessage || (SdsMessage = {}));
4655
4655
 
4656
+ const crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
4657
+
4656
4658
  /**
4657
4659
  * Utilities for hex, bytes, CSPRNG.
4658
4660
  * @module
@@ -4668,6 +4670,11 @@ var SdsMessage;
4668
4670
  function isBytes(a) {
4669
4671
  return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
4670
4672
  }
4673
+ /** Asserts something is positive integer. */
4674
+ function anumber(n) {
4675
+ if (!Number.isSafeInteger(n) || n < 0)
4676
+ throw new Error('positive integer expected, got ' + n);
4677
+ }
4671
4678
  /** Asserts something is Uint8Array. */
4672
4679
  function abytes(b, ...lengths) {
4673
4680
  if (!isBytes(b))
@@ -4675,6 +4682,13 @@ function abytes(b, ...lengths) {
4675
4682
  if (lengths.length > 0 && !lengths.includes(b.length))
4676
4683
  throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
4677
4684
  }
4685
+ /** Asserts something is hash */
4686
+ function ahash(h) {
4687
+ if (typeof h !== 'function' || typeof h.create !== 'function')
4688
+ throw new Error('Hash should be wrapped by utils.createHasher');
4689
+ anumber(h.outputLen);
4690
+ anumber(h.blockLen);
4691
+ }
4678
4692
  /** Asserts a hash instance has not been destroyed / finished */
4679
4693
  function aexists(instance, checkFinished = true) {
4680
4694
  if (instance.destroyed)
@@ -4704,6 +4718,65 @@ function createView(arr) {
4704
4718
  function rotr(word, shift) {
4705
4719
  return (word << (32 - shift)) | (word >>> shift);
4706
4720
  }
4721
+ // Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex
4722
+ const hasHexBuiltin = /* @__PURE__ */ (() =>
4723
+ // @ts-ignore
4724
+ typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();
4725
+ // Array where index 0xf0 (240) is mapped to string 'f0'
4726
+ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
4727
+ /**
4728
+ * Convert byte array to hex string. Uses built-in function, when available.
4729
+ * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
4730
+ */
4731
+ function bytesToHex$1(bytes) {
4732
+ abytes(bytes);
4733
+ // @ts-ignore
4734
+ if (hasHexBuiltin)
4735
+ return bytes.toHex();
4736
+ // pre-caching improves the speed 6x
4737
+ let hex = '';
4738
+ for (let i = 0; i < bytes.length; i++) {
4739
+ hex += hexes[bytes[i]];
4740
+ }
4741
+ return hex;
4742
+ }
4743
+ // We use optimized technique to convert hex string to byte array
4744
+ const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
4745
+ function asciiToBase16(ch) {
4746
+ if (ch >= asciis._0 && ch <= asciis._9)
4747
+ return ch - asciis._0; // '2' => 50-48
4748
+ if (ch >= asciis.A && ch <= asciis.F)
4749
+ return ch - (asciis.A - 10); // 'B' => 66-(65-10)
4750
+ if (ch >= asciis.a && ch <= asciis.f)
4751
+ return ch - (asciis.a - 10); // 'b' => 98-(97-10)
4752
+ return;
4753
+ }
4754
+ /**
4755
+ * Convert hex string to byte array. Uses built-in function, when available.
4756
+ * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
4757
+ */
4758
+ function hexToBytes(hex) {
4759
+ if (typeof hex !== 'string')
4760
+ throw new Error('hex string expected, got ' + typeof hex);
4761
+ // @ts-ignore
4762
+ if (hasHexBuiltin)
4763
+ return Uint8Array.fromHex(hex);
4764
+ const hl = hex.length;
4765
+ const al = hl / 2;
4766
+ if (hl % 2)
4767
+ throw new Error('hex string expected, got unpadded hex of length ' + hl);
4768
+ const array = new Uint8Array(al);
4769
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
4770
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
4771
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
4772
+ if (n1 === undefined || n2 === undefined) {
4773
+ const char = hex[hi] + hex[hi + 1];
4774
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
4775
+ }
4776
+ array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163
4777
+ }
4778
+ return array;
4779
+ }
4707
4780
  /**
4708
4781
  * Converts string to bytes using UTF8 encoding.
4709
4782
  * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
@@ -4724,6 +4797,22 @@ function toBytes(data) {
4724
4797
  abytes(data);
4725
4798
  return data;
4726
4799
  }
4800
+ /** Copies several Uint8Arrays into one. */
4801
+ function concatBytes(...arrays) {
4802
+ let sum = 0;
4803
+ for (let i = 0; i < arrays.length; i++) {
4804
+ const a = arrays[i];
4805
+ abytes(a);
4806
+ sum += a.length;
4807
+ }
4808
+ const res = new Uint8Array(sum);
4809
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
4810
+ const a = arrays[i];
4811
+ res.set(a, pad);
4812
+ pad += a.length;
4813
+ }
4814
+ return res;
4815
+ }
4727
4816
  /** For runtime check if class implements interface */
4728
4817
  class Hash {
4729
4818
  }
@@ -4736,6 +4825,17 @@ function createHasher(hashCons) {
4736
4825
  hashC.create = () => hashCons();
4737
4826
  return hashC;
4738
4827
  }
4828
+ /** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
4829
+ function randomBytes(bytesLength = 32) {
4830
+ if (crypto && typeof crypto.getRandomValues === 'function') {
4831
+ return crypto.getRandomValues(new Uint8Array(bytesLength));
4832
+ }
4833
+ // Legacy Node.js compatibility
4834
+ if (crypto && typeof crypto.randomBytes === 'function') {
4835
+ return Uint8Array.from(crypto.randomBytes(bytesLength));
4836
+ }
4837
+ throw new Error('crypto.getRandomValues must be defined');
4838
+ }
4739
4839
 
4740
4840
  /**
4741
4841
  * Internal Merkle-Damgard hash utils.
@@ -4876,6 +4976,56 @@ class HashMD extends Hash {
4876
4976
  const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
4877
4977
  0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
4878
4978
  ]);
4979
+ /** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */
4980
+ const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
4981
+ 0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1,
4982
+ 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,
4983
+ ]);
4984
+
4985
+ /**
4986
+ * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
4987
+ * @todo re-check https://issues.chromium.org/issues/42212588
4988
+ * @module
4989
+ */
4990
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
4991
+ const _32n = /* @__PURE__ */ BigInt(32);
4992
+ function fromBig(n, le = false) {
4993
+ if (le)
4994
+ return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
4995
+ return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
4996
+ }
4997
+ function split(lst, le = false) {
4998
+ const len = lst.length;
4999
+ let Ah = new Uint32Array(len);
5000
+ let Al = new Uint32Array(len);
5001
+ for (let i = 0; i < len; i++) {
5002
+ const { h, l } = fromBig(lst[i], le);
5003
+ [Ah[i], Al[i]] = [h, l];
5004
+ }
5005
+ return [Ah, Al];
5006
+ }
5007
+ // for Shift in [0, 32)
5008
+ const shrSH = (h, _l, s) => h >>> s;
5009
+ const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
5010
+ // Right rotate for Shift in [1, 32)
5011
+ const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
5012
+ const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
5013
+ // Right rotate for Shift in (32, 64), NOTE: 32 is special case.
5014
+ const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
5015
+ const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
5016
+ // JS uses 32-bit signed integers for bitwise operations which means we cannot
5017
+ // simple take carry out of low bit sum by shift, we need to use division.
5018
+ function add(Ah, Al, Bh, Bl) {
5019
+ const l = (Al >>> 0) + (Bl >>> 0);
5020
+ return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
5021
+ }
5022
+ // Addition with more than 2 elements
5023
+ const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
5024
+ const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
5025
+ const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
5026
+ const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
5027
+ const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
5028
+ const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
4879
5029
 
4880
5030
  /**
4881
5031
  * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
@@ -4976,6 +5126,162 @@ class SHA256 extends HashMD {
4976
5126
  clean(this.buffer);
4977
5127
  }
4978
5128
  }
5129
+ // SHA2-512 is slower than sha256 in js because u64 operations are slow.
5130
+ // Round contants
5131
+ // First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409
5132
+ // prettier-ignore
5133
+ const K512 = /* @__PURE__ */ (() => split([
5134
+ '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
5135
+ '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
5136
+ '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
5137
+ '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
5138
+ '0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
5139
+ '0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
5140
+ '0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
5141
+ '0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
5142
+ '0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
5143
+ '0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
5144
+ '0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
5145
+ '0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
5146
+ '0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
5147
+ '0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
5148
+ '0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
5149
+ '0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
5150
+ '0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
5151
+ '0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
5152
+ '0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
5153
+ '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
5154
+ ].map(n => BigInt(n))))();
5155
+ const SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
5156
+ const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
5157
+ // Reusable temporary buffers
5158
+ const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
5159
+ const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
5160
+ class SHA512 extends HashMD {
5161
+ constructor(outputLen = 64) {
5162
+ super(128, outputLen, 16, false);
5163
+ // We cannot use array here since array allows indexing by variable
5164
+ // which means optimizer/compiler cannot use registers.
5165
+ // h -- high 32 bits, l -- low 32 bits
5166
+ this.Ah = SHA512_IV[0] | 0;
5167
+ this.Al = SHA512_IV[1] | 0;
5168
+ this.Bh = SHA512_IV[2] | 0;
5169
+ this.Bl = SHA512_IV[3] | 0;
5170
+ this.Ch = SHA512_IV[4] | 0;
5171
+ this.Cl = SHA512_IV[5] | 0;
5172
+ this.Dh = SHA512_IV[6] | 0;
5173
+ this.Dl = SHA512_IV[7] | 0;
5174
+ this.Eh = SHA512_IV[8] | 0;
5175
+ this.El = SHA512_IV[9] | 0;
5176
+ this.Fh = SHA512_IV[10] | 0;
5177
+ this.Fl = SHA512_IV[11] | 0;
5178
+ this.Gh = SHA512_IV[12] | 0;
5179
+ this.Gl = SHA512_IV[13] | 0;
5180
+ this.Hh = SHA512_IV[14] | 0;
5181
+ this.Hl = SHA512_IV[15] | 0;
5182
+ }
5183
+ // prettier-ignore
5184
+ get() {
5185
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
5186
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
5187
+ }
5188
+ // prettier-ignore
5189
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
5190
+ this.Ah = Ah | 0;
5191
+ this.Al = Al | 0;
5192
+ this.Bh = Bh | 0;
5193
+ this.Bl = Bl | 0;
5194
+ this.Ch = Ch | 0;
5195
+ this.Cl = Cl | 0;
5196
+ this.Dh = Dh | 0;
5197
+ this.Dl = Dl | 0;
5198
+ this.Eh = Eh | 0;
5199
+ this.El = El | 0;
5200
+ this.Fh = Fh | 0;
5201
+ this.Fl = Fl | 0;
5202
+ this.Gh = Gh | 0;
5203
+ this.Gl = Gl | 0;
5204
+ this.Hh = Hh | 0;
5205
+ this.Hl = Hl | 0;
5206
+ }
5207
+ process(view, offset) {
5208
+ // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
5209
+ for (let i = 0; i < 16; i++, offset += 4) {
5210
+ SHA512_W_H[i] = view.getUint32(offset);
5211
+ SHA512_W_L[i] = view.getUint32((offset += 4));
5212
+ }
5213
+ for (let i = 16; i < 80; i++) {
5214
+ // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
5215
+ const W15h = SHA512_W_H[i - 15] | 0;
5216
+ const W15l = SHA512_W_L[i - 15] | 0;
5217
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
5218
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
5219
+ // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
5220
+ const W2h = SHA512_W_H[i - 2] | 0;
5221
+ const W2l = SHA512_W_L[i - 2] | 0;
5222
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
5223
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
5224
+ // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
5225
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
5226
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
5227
+ SHA512_W_H[i] = SUMh | 0;
5228
+ SHA512_W_L[i] = SUMl | 0;
5229
+ }
5230
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
5231
+ // Compression function main loop, 80 rounds
5232
+ for (let i = 0; i < 80; i++) {
5233
+ // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
5234
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
5235
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
5236
+ //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
5237
+ const CHIh = (Eh & Fh) ^ (~Eh & Gh);
5238
+ const CHIl = (El & Fl) ^ (~El & Gl);
5239
+ // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
5240
+ // prettier-ignore
5241
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
5242
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
5243
+ const T1l = T1ll | 0;
5244
+ // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
5245
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
5246
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
5247
+ const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
5248
+ const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
5249
+ Hh = Gh | 0;
5250
+ Hl = Gl | 0;
5251
+ Gh = Fh | 0;
5252
+ Gl = Fl | 0;
5253
+ Fh = Eh | 0;
5254
+ Fl = El | 0;
5255
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
5256
+ Dh = Ch | 0;
5257
+ Dl = Cl | 0;
5258
+ Ch = Bh | 0;
5259
+ Cl = Bl | 0;
5260
+ Bh = Ah | 0;
5261
+ Bl = Al | 0;
5262
+ const All = add3L(T1l, sigma0l, MAJl);
5263
+ Ah = add3H(All, T1h, sigma0h, MAJh);
5264
+ Al = All | 0;
5265
+ }
5266
+ // Add the compressed chunk to the current hash value
5267
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
5268
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
5269
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
5270
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
5271
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
5272
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
5273
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
5274
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
5275
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
5276
+ }
5277
+ roundClean() {
5278
+ clean(SHA512_W_H, SHA512_W_L);
5279
+ }
5280
+ destroy() {
5281
+ clean(this.buffer);
5282
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
5283
+ }
5284
+ }
4979
5285
  /**
4980
5286
  * SHA2-256 hash function from RFC 4634.
4981
5287
  *
@@ -4984,6 +5290,8 @@ class SHA256 extends HashMD {
4984
5290
  * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
4985
5291
  */
4986
5292
  const sha256$1 = /* @__PURE__ */ createHasher(() => new SHA256());
5293
+ /** SHA2-512 hash function from RFC 4634. */
5294
+ const sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
4987
5295
 
4988
5296
  /**
4989
5297
  * SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.
@@ -5095,17 +5403,6 @@ var Tags;
5095
5403
  Tags["PEER_EXCHANGE"] = "peer-exchange";
5096
5404
  Tags["LOCAL"] = "local-peer-cache";
5097
5405
  })(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 = {}));
5109
5406
 
5110
5407
  /**
5111
5408
  * The default cluster ID for The Waku Network
@@ -5181,27 +5478,9 @@ const singleShardInfoToPubsubTopic = (shardInfo) => {
5181
5478
  throw new Error("Invalid shard");
5182
5479
  return `/waku/2/rs/${shardInfo.clusterId ?? DEFAULT_CLUSTER_ID}/${shardInfo.shard}`;
5183
5480
  };
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
- };
5481
+ /**
5482
+ * @deprecated will be removed
5483
+ */
5205
5484
  const pubsubTopicToSingleShardInfo = (pubsubTopics) => {
5206
5485
  const parts = pubsubTopics.split("/");
5207
5486
  if (parts.length != 6 ||
@@ -6241,4 +6520,4 @@ var version_0 = /*#__PURE__*/Object.freeze({
6241
6520
  proto: message
6242
6521
  });
6243
6522
 
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 };
6523
+ export { sha256 as $, anumber as A, randomBytes as B, sha512 as C, enumeration as D, message$1 as E, FilterSubscribeRequest as F, encodeMessage as G, decodeMessage as H, Hash as I, ahash as J, toBytes as K, Logger as L, MessagePush as M, clean as N, aexists as O, ProtocolError as P, sha256$1 as Q, bases as R, StoreQueryRequest$1 as S, Tags as T, base64url as U, encodeUint8Array as V, bytesToUtf8 as W, WakuMetadataRequest as X, pubsubTopicsToShardInfo 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 };