@waku/core 0.0.5 → 0.0.6

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 (78) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/bundle/{index-a67d7136.js → index-925587a4.js} +1696 -113
  3. package/bundle/index.js +12942 -15253
  4. package/bundle/lib/predefined_bootstrap_nodes.js +24 -4
  5. package/bundle/lib/wait_for_remote_peer.js +4 -6
  6. package/bundle/lib/waku_message/topic_only_message.js +2 -3
  7. package/bundle/lib/waku_message/version_0.js +17 -4
  8. package/bundle/{message-049c8b67.js → message-70dbb19b.js} +1419 -753
  9. package/bundle/{topic_only_message-5ad3a869.js → topic_only_message-a80fe8b2.js} +2 -2
  10. package/dist/index.d.ts +5 -4
  11. package/dist/index.js +5 -4
  12. package/dist/index.js.map +1 -1
  13. package/dist/lib/predefined_bootstrap_nodes.d.ts +1 -2
  14. package/dist/lib/predefined_bootstrap_nodes.js +0 -2
  15. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
  16. package/dist/lib/to_proto_message.js +1 -0
  17. package/dist/lib/to_proto_message.js.map +1 -1
  18. package/dist/lib/wait_for_remote_peer.js +2 -2
  19. package/dist/lib/wait_for_remote_peer.js.map +1 -1
  20. package/dist/lib/waku.d.ts +16 -15
  21. package/dist/lib/waku.js +31 -33
  22. package/dist/lib/waku.js.map +1 -1
  23. package/dist/lib/waku_filter/index.d.ts +10 -35
  24. package/dist/lib/waku_filter/index.js +13 -7
  25. package/dist/lib/waku_filter/index.js.map +1 -1
  26. package/dist/lib/waku_light_push/index.d.ts +8 -24
  27. package/dist/lib/waku_light_push/index.js +12 -6
  28. package/dist/lib/waku_light_push/index.js.map +1 -1
  29. package/dist/lib/waku_message/topic_only_message.d.ts +3 -2
  30. package/dist/lib/waku_message/topic_only_message.js +1 -0
  31. package/dist/lib/waku_message/topic_only_message.js.map +1 -1
  32. package/dist/lib/waku_message/version_0.d.ts +5 -2
  33. package/dist/lib/waku_message/version_0.js +9 -2
  34. package/dist/lib/waku_message/version_0.js.map +1 -1
  35. package/dist/lib/waku_relay/index.d.ts +3 -45
  36. package/dist/lib/waku_relay/index.js +6 -3
  37. package/dist/lib/waku_relay/index.js.map +1 -1
  38. package/dist/lib/waku_store/index.d.ts +11 -71
  39. package/dist/lib/waku_store/index.js +34 -10
  40. package/dist/lib/waku_store/index.js.map +1 -1
  41. package/dist/proto/filter.d.ts +1 -0
  42. package/dist/proto/filter.js +7 -0
  43. package/dist/proto/filter.js.map +1 -1
  44. package/dist/proto/light_push.d.ts +1 -0
  45. package/dist/proto/light_push.js +7 -0
  46. package/dist/proto/light_push.js.map +1 -1
  47. package/dist/proto/message.d.ts +1 -0
  48. package/dist/proto/message.js +7 -0
  49. package/dist/proto/message.js.map +1 -1
  50. package/dist/proto/store.d.ts +1 -0
  51. package/dist/proto/store.js +7 -0
  52. package/dist/proto/store.js.map +1 -1
  53. package/package.json +11 -13
  54. package/src/index.ts +10 -4
  55. package/src/lib/predefined_bootstrap_nodes.ts +1 -5
  56. package/src/lib/to_proto_message.ts +1 -0
  57. package/src/lib/wait_for_remote_peer.ts +2 -2
  58. package/src/lib/waku.ts +51 -47
  59. package/src/lib/waku_filter/index.ts +28 -7
  60. package/src/lib/waku_light_push/index.ts +26 -6
  61. package/src/lib/waku_message/topic_only_message.ts +4 -2
  62. package/src/lib/waku_message/version_0.ts +8 -2
  63. package/src/lib/waku_relay/index.ts +13 -3
  64. package/src/lib/waku_store/index.ts +63 -12
  65. package/src/proto/filter.ts +9 -0
  66. package/src/proto/light_push.ts +9 -0
  67. package/src/proto/message.ts +9 -0
  68. package/src/proto/store.ts +9 -0
  69. package/bundle/browser-1e1a2f27.js +0 -722
  70. package/bundle/events-158407bb.js +0 -1929
  71. package/bundle/index-64ce43f0.js +0 -69
  72. package/bundle/index-8710041d.js +0 -2962
  73. package/bundle/lib/peer_discovery_static_list.js +0 -89
  74. package/bundle/random_subset-75d1c511.js +0 -26
  75. package/dist/lib/peer_discovery_static_list.d.ts +0 -44
  76. package/dist/lib/peer_discovery_static_list.js +0 -72
  77. package/dist/lib/peer_discovery_static_list.js.map +0 -1
  78. package/src/lib/peer_discovery_static_list.ts +0 -118
@@ -1,33 +1,10 @@
1
- import { d as debug } from './browser-1e1a2f27.js';
2
- import { i as createCodec, C as CODEC_TYPES, m as message, j as encodeMessage, k as decodeMessage } from './message-049c8b67.js';
3
- import { e as errCode } from './index-64ce43f0.js';
1
+ import { d as debug, j as createCodec$1, C as CODEC_TYPES, m as message, k as encodeMessage, l as decodeMessage } from './message-70dbb19b.js';
4
2
 
5
3
  /**
6
4
  * DefaultPubSubTopic is the default gossipsub topic to use for Waku.
7
5
  */
8
6
  const DefaultPubSubTopic = "/waku/2/default-waku/proto";
9
7
 
10
- function enumeration(v) {
11
- function findValue(val) {
12
- // Use the reverse mapping to look up the enum key for the stored value
13
- // https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
14
- if (v[val.toString()] == null) {
15
- throw new Error('Invalid enum value');
16
- }
17
- return v[val];
18
- }
19
- const encode = function enumEncode(val, writer) {
20
- const enumValue = findValue(val);
21
- writer.int32(enumValue);
22
- };
23
- const decode = function enumDecode(reader) {
24
- const val = reader.uint32();
25
- return findValue(val);
26
- };
27
- // @ts-expect-error yeah yeah
28
- return createCodec('enum', CODEC_TYPES.VARINT, encode, decode);
29
- }
30
-
31
8
  var Protocols;
32
9
  (function (Protocols) {
33
10
  Protocols["Relay"] = "relay";
@@ -63,7 +40,7 @@ var itAll = all;
63
40
  * To guarantee Uint8Array semantics, convert nodejs Buffers
64
41
  * into vanilla Uint8Arrays
65
42
  */
66
- function asUint8Array$1(buf) {
43
+ function asUint8Array(buf) {
67
44
  if (globalThis.Buffer != null) {
68
45
  return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
69
46
  }
@@ -76,7 +53,7 @@ function asUint8Array$1(buf) {
76
53
  */
77
54
  function alloc(size = 0) {
78
55
  if (globalThis.Buffer?.alloc != null) {
79
- return asUint8Array$1(globalThis.Buffer.alloc(size));
56
+ return asUint8Array(globalThis.Buffer.alloc(size));
80
57
  }
81
58
  return new Uint8Array(size);
82
59
  }
@@ -85,9 +62,9 @@ function alloc(size = 0) {
85
62
  * uninitialized memory. Only use if you are certain you will immediately
86
63
  * overwrite every value in the returned `Uint8Array`.
87
64
  */
88
- function allocUnsafe$2(size = 0) {
65
+ function allocUnsafe$1(size = 0) {
89
66
  if (globalThis.Buffer?.allocUnsafe != null) {
90
- return asUint8Array$1(globalThis.Buffer.allocUnsafe(size));
67
+ return asUint8Array(globalThis.Buffer.allocUnsafe(size));
91
68
  }
92
69
  return new Uint8Array(size);
93
70
  }
@@ -95,23 +72,23 @@ function allocUnsafe$2(size = 0) {
95
72
  /**
96
73
  * Returns a new Uint8Array created by concatenating the passed ArrayLikes
97
74
  */
98
- function concat(arrays, length) {
75
+ function concat$1(arrays, length) {
99
76
  if (length == null) {
100
77
  length = arrays.reduce((acc, curr) => acc + curr.length, 0);
101
78
  }
102
- const output = allocUnsafe$2(length);
79
+ const output = allocUnsafe$1(length);
103
80
  let offset = 0;
104
81
  for (const arr of arrays) {
105
82
  output.set(arr, offset);
106
83
  offset += arr.length;
107
84
  }
108
- return asUint8Array$1(output);
85
+ return asUint8Array(output);
109
86
  }
110
87
 
111
88
  /**
112
89
  * Returns true if the two passed Uint8Arrays have the same content
113
90
  */
114
- function equals(a, b) {
91
+ function equals$2(a, b) {
115
92
  if (a === b) {
116
93
  return true;
117
94
  }
@@ -281,7 +258,7 @@ class Uint8ArrayList {
281
258
  */
282
259
  slice(beginInclusive, endExclusive) {
283
260
  const { bufs, length } = this._subList(beginInclusive, endExclusive);
284
- return concat(bufs, length);
261
+ return concat$1(bufs, length);
285
262
  }
286
263
  /**
287
264
  * Returns a alloc from the given start and end element index.
@@ -294,7 +271,7 @@ class Uint8ArrayList {
294
271
  if (bufs.length === 1) {
295
272
  return bufs[0];
296
273
  }
297
- return concat(bufs, length);
274
+ return concat$1(bufs, length);
298
275
  }
299
276
  /**
300
277
  * Returns a allocList from the given start and end element index.
@@ -385,7 +362,7 @@ class Uint8ArrayList {
385
362
  return view.getInt8(0);
386
363
  }
387
364
  setInt8(byteOffset, value) {
388
- const buf = allocUnsafe$2(1);
365
+ const buf = allocUnsafe$1(1);
389
366
  const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
390
367
  view.setInt8(0, value);
391
368
  this.write(buf, byteOffset);
@@ -429,7 +406,7 @@ class Uint8ArrayList {
429
406
  return view.getUint8(0);
430
407
  }
431
408
  setUint8(byteOffset, value) {
432
- const buf = allocUnsafe$2(1);
409
+ const buf = allocUnsafe$1(1);
433
410
  const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
434
411
  view.setUint8(0, value);
435
412
  this.write(buf, byteOffset);
@@ -500,7 +477,7 @@ class Uint8ArrayList {
500
477
  return false;
501
478
  }
502
479
  for (let i = 0; i < this.bufs.length; i++) {
503
- if (!equals(this.bufs[i], other.bufs[i])) {
480
+ if (!equals$2(this.bufs[i], other.bufs[i])) {
504
481
  return false;
505
482
  }
506
483
  }
@@ -720,65 +697,42 @@ class LongBits {
720
697
  }
721
698
  }
722
699
 
723
- /**
724
- * To guarantee Uint8Array semantics, convert nodejs Buffers
725
- * into vanilla Uint8Arrays
726
- */
727
- function asUint8Array(buf) {
728
- if (globalThis.Buffer != null) {
729
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
730
- }
731
- return buf;
732
- }
733
-
734
- /**
735
- * Where possible returns a Uint8Array of the requested size that references
736
- * uninitialized memory. Only use if you are certain you will immediately
737
- * overwrite every value in the returned `Uint8Array`.
738
- */
739
- function allocUnsafe$1(size = 0) {
740
- if (globalThis.Buffer?.allocUnsafe != null) {
741
- return asUint8Array(globalThis.Buffer.allocUnsafe(size));
742
- }
743
- return new Uint8Array(size);
744
- }
745
-
746
- const N1 = Math.pow(2, 7);
747
- const N2 = Math.pow(2, 14);
748
- const N3 = Math.pow(2, 21);
749
- const N4 = Math.pow(2, 28);
750
- const N5 = Math.pow(2, 35);
751
- const N6 = Math.pow(2, 42);
752
- const N7 = Math.pow(2, 49);
753
- const N8 = Math.pow(2, 56);
754
- const N9 = Math.pow(2, 63);
700
+ const N1$1 = Math.pow(2, 7);
701
+ const N2$1 = Math.pow(2, 14);
702
+ const N3$1 = Math.pow(2, 21);
703
+ const N4$1 = Math.pow(2, 28);
704
+ const N5$1 = Math.pow(2, 35);
705
+ const N6$1 = Math.pow(2, 42);
706
+ const N7$1 = Math.pow(2, 49);
707
+ const N8$1 = Math.pow(2, 56);
708
+ const N9$1 = Math.pow(2, 63);
755
709
  const unsigned = {
756
710
  encodingLength(value) {
757
- if (value < N1) {
711
+ if (value < N1$1) {
758
712
  return 1;
759
713
  }
760
- if (value < N2) {
714
+ if (value < N2$1) {
761
715
  return 2;
762
716
  }
763
- if (value < N3) {
717
+ if (value < N3$1) {
764
718
  return 3;
765
719
  }
766
- if (value < N4) {
720
+ if (value < N4$1) {
767
721
  return 4;
768
722
  }
769
- if (value < N5) {
723
+ if (value < N5$1) {
770
724
  return 5;
771
725
  }
772
- if (value < N6) {
726
+ if (value < N6$1) {
773
727
  return 6;
774
728
  }
775
- if (value < N7) {
729
+ if (value < N7$1) {
776
730
  return 7;
777
731
  }
778
- if (value < N8) {
732
+ if (value < N8$1) {
779
733
  return 8;
780
734
  }
781
- if (value < N9) {
735
+ if (value < N9$1) {
782
736
  return 9;
783
737
  }
784
738
  return 10;
@@ -813,7 +767,7 @@ const defaultEncoder = (length) => {
813
767
  return lengthBuf;
814
768
  };
815
769
  defaultEncoder.bytes = 0;
816
- function encode(options) {
770
+ function encode$4(options) {
817
771
  options = options ?? {};
818
772
  const encodeLength = options.lengthEncoder ?? defaultEncoder;
819
773
  const encoder = async function* (source) {
@@ -838,12 +792,80 @@ function encode(options) {
838
792
  };
839
793
  return encoder;
840
794
  }
841
- encode.single = (chunk, options) => {
795
+ encode$4.single = (chunk, options) => {
842
796
  options = options ?? {};
843
797
  const encodeLength = options.lengthEncoder ?? defaultEncoder;
844
798
  return new Uint8ArrayList(encodeLength(chunk.byteLength), chunk);
845
799
  };
846
800
 
801
+ /**
802
+ * @typedef {{ [key: string]: any }} Extensions
803
+ * @typedef {Error} Err
804
+ * @property {string} message
805
+ */
806
+
807
+ /**
808
+ *
809
+ * @param {Error} obj
810
+ * @param {Extensions} props
811
+ * @returns {Error & Extensions}
812
+ */
813
+ function assign(obj, props) {
814
+ for (const key in props) {
815
+ Object.defineProperty(obj, key, {
816
+ value: props[key],
817
+ enumerable: true,
818
+ configurable: true,
819
+ });
820
+ }
821
+
822
+ return obj;
823
+ }
824
+
825
+ /**
826
+ *
827
+ * @param {any} err - An Error
828
+ * @param {string|Extensions} code - A string code or props to set on the error
829
+ * @param {Extensions} [props] - Props to set on the error
830
+ * @returns {Error & Extensions}
831
+ */
832
+ function createError(err, code, props) {
833
+ if (!err || typeof err === 'string') {
834
+ throw new TypeError('Please pass an Error to err-code');
835
+ }
836
+
837
+ if (!props) {
838
+ props = {};
839
+ }
840
+
841
+ if (typeof code === 'object') {
842
+ props = code;
843
+ code = '';
844
+ }
845
+
846
+ if (code) {
847
+ props.code = code;
848
+ }
849
+
850
+ try {
851
+ return assign(err, props);
852
+ } catch (_) {
853
+ props.message = err.message;
854
+ props.stack = err.stack;
855
+
856
+ const ErrClass = function () {};
857
+
858
+ ErrClass.prototype = Object.create(Object.getPrototypeOf(err));
859
+
860
+ // @ts-ignore
861
+ const output = assign(new ErrClass(), props);
862
+
863
+ return output;
864
+ }
865
+ }
866
+
867
+ var errCode = createError;
868
+
847
869
  /* eslint max-depth: ["error", 6] */
848
870
  // Maximum length of the length section of the message
849
871
  const MAX_LENGTH_LENGTH = 8; // Varint.encode(Number.MAX_SAFE_INTEGER).length
@@ -860,7 +882,7 @@ const defaultDecoder = (buf) => {
860
882
  return length;
861
883
  };
862
884
  defaultDecoder.bytes = 0;
863
- function decode(options) {
885
+ function decode$5(options) {
864
886
  const decoder = async function* (source) {
865
887
  const buffer = new Uint8ArrayList();
866
888
  let mode = ReadMode.LENGTH;
@@ -924,7 +946,7 @@ function decode(options) {
924
946
  * @param {import('./types').DecoderOptions} [options]
925
947
  * @returns
926
948
  */
927
- decode.fromReader = (reader, options) => {
949
+ decode$5.fromReader = (reader, options) => {
928
950
  let byteLength = 1; // Read single byte chunks until the length is known
929
951
  const varByteSource = (async function* () {
930
952
  while (true) {
@@ -953,7 +975,7 @@ decode.fromReader = (reader, options) => {
953
975
  * Once the length has been parsed, read chunk for that length
954
976
  */
955
977
  const onLength = (l) => { byteLength = l; };
956
- return decode({
978
+ return decode$5({
957
979
  ...(options ?? {}),
958
980
  onLength
959
981
  })(varByteSource);
@@ -1572,6 +1594,7 @@ const EmptyMessage = {
1572
1594
  version: undefined,
1573
1595
  timestamp: undefined,
1574
1596
  rateLimitProof: undefined,
1597
+ ephemeral: undefined,
1575
1598
  };
1576
1599
  function toProtoMessage(wire) {
1577
1600
  return { ...EmptyMessage, ...wire };
@@ -2058,6 +2081,27 @@ function sha1(bytes) {
2058
2081
 
2059
2082
  v35('v5', 0x50, sha1);
2060
2083
 
2084
+ function enumeration(v) {
2085
+ function findValue(val) {
2086
+ // Use the reverse mapping to look up the enum key for the stored value
2087
+ // https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
2088
+ if (v[val.toString()] == null) {
2089
+ throw new Error('Invalid enum value');
2090
+ }
2091
+ return v[val];
2092
+ }
2093
+ const encode = function enumEncode(val, writer) {
2094
+ const enumValue = findValue(val);
2095
+ writer.int32(enumValue);
2096
+ };
2097
+ const decode = function enumDecode(reader) {
2098
+ const val = reader.uint32();
2099
+ return findValue(val);
2100
+ };
2101
+ // @ts-expect-error yeah yeah
2102
+ return createCodec$1('enum', CODEC_TYPES.VARINT, encode, decode);
2103
+ }
2104
+
2061
2105
  /* eslint-disable import/export */
2062
2106
  var FilterRequest;
2063
2107
  (function (FilterRequest) {
@@ -2435,6 +2479,10 @@ var WakuMessage$2;
2435
2479
  writer.uint32(170);
2436
2480
  RateLimitProof$2.codec().encode(obj.rateLimitProof, writer);
2437
2481
  }
2482
+ if (obj.ephemeral != null) {
2483
+ writer.uint32(248);
2484
+ writer.bool(obj.ephemeral);
2485
+ }
2438
2486
  if (opts.lengthDelimited !== false) {
2439
2487
  writer.ldelim();
2440
2488
  }
@@ -2462,6 +2510,9 @@ var WakuMessage$2;
2462
2510
  case 21:
2463
2511
  obj.rateLimitProof = RateLimitProof$2.codec().decode(reader, reader.uint32());
2464
2512
  break;
2513
+ case 31:
2514
+ obj.ephemeral = reader.bool();
2515
+ break;
2465
2516
  default:
2466
2517
  reader.skipType(tag & 7);
2467
2518
  break;
@@ -2532,12 +2583,12 @@ const log$2 = debug("waku:filter");
2532
2583
  * - https://github.com/status-im/nwaku/issues/948
2533
2584
  */
2534
2585
  class WakuFilter {
2535
- constructor(libp2p, options) {
2536
- this.libp2p = libp2p;
2586
+ constructor(components, options) {
2587
+ this.components = components;
2537
2588
  this.subscriptions = new Map();
2538
2589
  this.decoders = new Map();
2539
2590
  this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
2540
- this.libp2p
2591
+ this.components.registrar
2541
2592
  .handle(FilterCodec, this.onRequest.bind(this))
2542
2593
  .catch((e) => log$2("Failed to register filter protocol", e));
2543
2594
  }
@@ -2561,7 +2612,7 @@ class WakuFilter {
2561
2612
  const peer = await this.getPeer(opts?.peerId);
2562
2613
  const stream = await this.newStream(peer);
2563
2614
  try {
2564
- const res = await pipe([request.encode()], encode(), stream, decode(), async (source) => await itAll(source));
2615
+ const res = await pipe([request.encode()], encode$4(), stream, decode$5(), async (source) => await itAll(source));
2565
2616
  log$2("response", res);
2566
2617
  }
2567
2618
  catch (e) {
@@ -2576,10 +2627,13 @@ class WakuFilter {
2576
2627
  this.deleteCallback(requestId);
2577
2628
  };
2578
2629
  }
2630
+ get peerStore() {
2631
+ return this.components.peerStore;
2632
+ }
2579
2633
  onRequest(streamData) {
2580
2634
  log$2("Receiving message push");
2581
2635
  try {
2582
- pipe(streamData.stream, decode(), async (source) => {
2636
+ pipe(streamData.stream, decode$5(), async (source) => {
2583
2637
  for await (const bytes of source) {
2584
2638
  const res = FilterRPC.decode(bytes.slice());
2585
2639
  if (res.requestId && res.push?.messages?.length) {
@@ -2663,7 +2717,7 @@ class WakuFilter {
2663
2717
  const unsubscribeRequest = FilterRPC.createRequest(topic, contentFilters, requestId, false);
2664
2718
  const stream = await this.newStream(peer);
2665
2719
  try {
2666
- await pipe([unsubscribeRequest.encode()], encode(), stream.sink);
2720
+ await pipe([unsubscribeRequest.encode()], encode$4(), stream.sink);
2667
2721
  }
2668
2722
  catch (e) {
2669
2723
  log$2("Error unsubscribing", e);
@@ -2671,7 +2725,7 @@ class WakuFilter {
2671
2725
  }
2672
2726
  }
2673
2727
  async newStream(peer) {
2674
- const connections = this.libp2p.connectionManager.getConnections(peer.id);
2728
+ const connections = this.components.connectionManager.getConnections(peer.id);
2675
2729
  const connection = selectConnection(connections);
2676
2730
  if (!connection) {
2677
2731
  throw new Error("Failed to get a connection to the peer");
@@ -2679,24 +2733,27 @@ class WakuFilter {
2679
2733
  return connection.newStream(FilterCodec);
2680
2734
  }
2681
2735
  async getPeer(peerId) {
2682
- const res = await selectPeerForProtocol(this.libp2p.peerStore, [FilterCodec], peerId);
2736
+ const res = await selectPeerForProtocol(this.components.peerStore, [FilterCodec], peerId);
2683
2737
  if (!res) {
2684
2738
  throw new Error(`Failed to select peer for ${FilterCodec}`);
2685
2739
  }
2686
2740
  return res.peer;
2687
2741
  }
2688
2742
  async peers() {
2689
- return getPeersForProtocol(this.libp2p.peerStore, [FilterCodec]);
2743
+ return getPeersForProtocol(this.components.peerStore, [FilterCodec]);
2690
2744
  }
2691
2745
  async randomPeer() {
2692
2746
  return selectRandomPeer(await this.peers());
2693
2747
  }
2694
2748
  }
2749
+ function wakuFilter(init = {}) {
2750
+ return (components) => new WakuFilter(components, init);
2751
+ }
2695
2752
 
2696
2753
  var index$2 = /*#__PURE__*/Object.freeze({
2697
2754
  __proto__: null,
2698
2755
  FilterCodec: FilterCodec,
2699
- WakuFilter: WakuFilter
2756
+ wakuFilter: wakuFilter
2700
2757
  });
2701
2758
 
2702
2759
  /* eslint-disable import/export */
@@ -3021,6 +3078,10 @@ var WakuMessage$1;
3021
3078
  writer.uint32(170);
3022
3079
  RateLimitProof$1.codec().encode(obj.rateLimitProof, writer);
3023
3080
  }
3081
+ if (obj.ephemeral != null) {
3082
+ writer.uint32(248);
3083
+ writer.bool(obj.ephemeral);
3084
+ }
3024
3085
  if (opts.lengthDelimited !== false) {
3025
3086
  writer.ldelim();
3026
3087
  }
@@ -3048,6 +3109,9 @@ var WakuMessage$1;
3048
3109
  case 21:
3049
3110
  obj.rateLimitProof = RateLimitProof$1.codec().decode(reader, reader.uint32());
3050
3111
  break;
3112
+ case 31:
3113
+ obj.ephemeral = reader.bool();
3114
+ break;
3051
3115
  default:
3052
3116
  reader.skipType(tag & 7);
3053
3117
  break;
@@ -3101,18 +3165,18 @@ const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
3101
3165
  * Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
3102
3166
  */
3103
3167
  class WakuLightPush {
3104
- constructor(libp2p, options) {
3105
- this.libp2p = libp2p;
3168
+ constructor(components, options) {
3169
+ this.components = components;
3106
3170
  this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
3107
3171
  }
3108
3172
  async push(encoder, message, opts) {
3109
3173
  const pubSubTopic = opts?.pubSubTopic ? opts.pubSubTopic : this.pubSubTopic;
3110
- const res = await selectPeerForProtocol(this.libp2p.peerStore, [LightPushCodec], opts?.peerId);
3174
+ const res = await selectPeerForProtocol(this.components.peerStore, [LightPushCodec], opts?.peerId);
3111
3175
  if (!res) {
3112
3176
  throw new Error("Failed to get a peer");
3113
3177
  }
3114
3178
  const { peer } = res;
3115
- const connections = this.libp2p.connectionManager.getConnections(peer.id);
3179
+ const connections = this.components.connectionManager.getConnections(peer.id);
3116
3180
  const connection = selectConnection(connections);
3117
3181
  if (!connection)
3118
3182
  throw "Failed to get a connection to the peer";
@@ -3125,7 +3189,7 @@ class WakuLightPush {
3125
3189
  return { recipients };
3126
3190
  }
3127
3191
  const query = PushRPC.createRequest(protoMessage, pubSubTopic);
3128
- const res = await pipe([query.encode()], encode(), stream, decode(), async (source) => await itAll(source));
3192
+ const res = await pipe([query.encode()], encode$4(), stream, decode$5(), async (source) => await itAll(source));
3129
3193
  try {
3130
3194
  const bytes = new Uint8ArrayList();
3131
3195
  res.forEach((chunk) => {
@@ -3155,7 +3219,7 @@ class WakuLightPush {
3155
3219
  * peers.
3156
3220
  */
3157
3221
  async peers() {
3158
- return getPeersForProtocol(this.libp2p.peerStore, [LightPushCodec]);
3222
+ return getPeersForProtocol(this.components.peerStore, [LightPushCodec]);
3159
3223
  }
3160
3224
  /**
3161
3225
  * Returns a random peer that supports light push protocol from the address
@@ -3165,15 +3229,1504 @@ class WakuLightPush {
3165
3229
  async randomPeer() {
3166
3230
  return selectRandomPeer(await this.peers());
3167
3231
  }
3232
+ get peerStore() {
3233
+ return this.components.peerStore;
3234
+ }
3235
+ }
3236
+ function wakuLightPush(init = {}) {
3237
+ return (components) => new WakuLightPush(components, init);
3168
3238
  }
3169
3239
 
3170
3240
  var index$1 = /*#__PURE__*/Object.freeze({
3171
3241
  __proto__: null,
3172
3242
  LightPushCodec: LightPushCodec,
3173
3243
  get PushResponse () { return PushResponse; },
3174
- WakuLightPush: WakuLightPush
3244
+ wakuLightPush: wakuLightPush
3245
+ });
3246
+
3247
+ function number(n) {
3248
+ if (!Number.isSafeInteger(n) || n < 0)
3249
+ throw new Error(`Wrong positive integer: ${n}`);
3250
+ }
3251
+ function bool(b) {
3252
+ if (typeof b !== 'boolean')
3253
+ throw new Error(`Expected boolean, not ${b}`);
3254
+ }
3255
+ function bytes(b, ...lengths) {
3256
+ if (!(b instanceof Uint8Array))
3257
+ throw new TypeError('Expected Uint8Array');
3258
+ if (lengths.length > 0 && !lengths.includes(b.length))
3259
+ throw new TypeError(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
3260
+ }
3261
+ function hash(hash) {
3262
+ if (typeof hash !== 'function' || typeof hash.create !== 'function')
3263
+ throw new Error('Hash should be wrapped by utils.wrapConstructor');
3264
+ number(hash.outputLen);
3265
+ number(hash.blockLen);
3266
+ }
3267
+ function exists(instance, checkFinished = true) {
3268
+ if (instance.destroyed)
3269
+ throw new Error('Hash instance has been destroyed');
3270
+ if (checkFinished && instance.finished)
3271
+ throw new Error('Hash#digest() has already been called');
3272
+ }
3273
+ function output(out, instance) {
3274
+ bytes(out);
3275
+ const min = instance.outputLen;
3276
+ if (out.length < min) {
3277
+ throw new Error(`digestInto() expects output buffer of length at least ${min}`);
3278
+ }
3279
+ }
3280
+ const assert = {
3281
+ number,
3282
+ bool,
3283
+ bytes,
3284
+ hash,
3285
+ exists,
3286
+ output,
3287
+ };
3288
+
3289
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3290
+ // Cast array to view
3291
+ const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
3292
+ // The rotate right (circular right shift) operation for uint32
3293
+ const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
3294
+ const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
3295
+ // There is almost no big endian hardware, but js typed arrays uses platform specific endianness.
3296
+ // So, just to be sure not to corrupt anything.
3297
+ if (!isLE)
3298
+ throw new Error('Non little-endian hardware is not supported');
3299
+ Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
3300
+ function utf8ToBytes$1(str) {
3301
+ if (typeof str !== 'string') {
3302
+ throw new TypeError(`utf8ToBytes expected string, got ${typeof str}`);
3303
+ }
3304
+ return new TextEncoder().encode(str);
3305
+ }
3306
+ function toBytes(data) {
3307
+ if (typeof data === 'string')
3308
+ data = utf8ToBytes$1(data);
3309
+ if (!(data instanceof Uint8Array))
3310
+ throw new TypeError(`Expected input type is Uint8Array (got ${typeof data})`);
3311
+ return data;
3312
+ }
3313
+ // For runtime check if class implements interface
3314
+ class Hash {
3315
+ // Safe version that clones internal state
3316
+ clone() {
3317
+ return this._cloneInto();
3318
+ }
3319
+ }
3320
+ function wrapConstructor(hashConstructor) {
3321
+ const hashC = (message) => hashConstructor().update(toBytes(message)).digest();
3322
+ const tmp = hashConstructor();
3323
+ hashC.outputLen = tmp.outputLen;
3324
+ hashC.blockLen = tmp.blockLen;
3325
+ hashC.create = () => hashConstructor();
3326
+ return hashC;
3327
+ }
3328
+
3329
+ // Polyfill for Safari 14
3330
+ function setBigUint64(view, byteOffset, value, isLE) {
3331
+ if (typeof view.setBigUint64 === 'function')
3332
+ return view.setBigUint64(byteOffset, value, isLE);
3333
+ const _32n = BigInt(32);
3334
+ const _u32_max = BigInt(0xffffffff);
3335
+ const wh = Number((value >> _32n) & _u32_max);
3336
+ const wl = Number(value & _u32_max);
3337
+ const h = isLE ? 4 : 0;
3338
+ const l = isLE ? 0 : 4;
3339
+ view.setUint32(byteOffset + h, wh, isLE);
3340
+ view.setUint32(byteOffset + l, wl, isLE);
3341
+ }
3342
+ // Base SHA2 class (RFC 6234)
3343
+ class SHA2 extends Hash {
3344
+ constructor(blockLen, outputLen, padOffset, isLE) {
3345
+ super();
3346
+ this.blockLen = blockLen;
3347
+ this.outputLen = outputLen;
3348
+ this.padOffset = padOffset;
3349
+ this.isLE = isLE;
3350
+ this.finished = false;
3351
+ this.length = 0;
3352
+ this.pos = 0;
3353
+ this.destroyed = false;
3354
+ this.buffer = new Uint8Array(blockLen);
3355
+ this.view = createView(this.buffer);
3356
+ }
3357
+ update(data) {
3358
+ assert.exists(this);
3359
+ const { view, buffer, blockLen } = this;
3360
+ data = toBytes(data);
3361
+ const len = data.length;
3362
+ for (let pos = 0; pos < len;) {
3363
+ const take = Math.min(blockLen - this.pos, len - pos);
3364
+ // Fast path: we have at least one block in input, cast it to view and process
3365
+ if (take === blockLen) {
3366
+ const dataView = createView(data);
3367
+ for (; blockLen <= len - pos; pos += blockLen)
3368
+ this.process(dataView, pos);
3369
+ continue;
3370
+ }
3371
+ buffer.set(data.subarray(pos, pos + take), this.pos);
3372
+ this.pos += take;
3373
+ pos += take;
3374
+ if (this.pos === blockLen) {
3375
+ this.process(view, 0);
3376
+ this.pos = 0;
3377
+ }
3378
+ }
3379
+ this.length += data.length;
3380
+ this.roundClean();
3381
+ return this;
3382
+ }
3383
+ digestInto(out) {
3384
+ assert.exists(this);
3385
+ assert.output(out, this);
3386
+ this.finished = true;
3387
+ // Padding
3388
+ // We can avoid allocation of buffer for padding completely if it
3389
+ // was previously not allocated here. But it won't change performance.
3390
+ const { buffer, view, blockLen, isLE } = this;
3391
+ let { pos } = this;
3392
+ // append the bit '1' to the message
3393
+ buffer[pos++] = 0b10000000;
3394
+ this.buffer.subarray(pos).fill(0);
3395
+ // we have less than padOffset left in buffer, so we cannot put length in current block, need process it and pad again
3396
+ if (this.padOffset > blockLen - pos) {
3397
+ this.process(view, 0);
3398
+ pos = 0;
3399
+ }
3400
+ // Pad until full block byte with zeros
3401
+ for (let i = pos; i < blockLen; i++)
3402
+ buffer[i] = 0;
3403
+ // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
3404
+ // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
3405
+ // So we just write lowest 64 bits of that value.
3406
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
3407
+ this.process(view, 0);
3408
+ const oview = createView(out);
3409
+ this.get().forEach((v, i) => oview.setUint32(4 * i, v, isLE));
3410
+ }
3411
+ digest() {
3412
+ const { buffer, outputLen } = this;
3413
+ this.digestInto(buffer);
3414
+ const res = buffer.slice(0, outputLen);
3415
+ this.destroy();
3416
+ return res;
3417
+ }
3418
+ _cloneInto(to) {
3419
+ to || (to = new this.constructor());
3420
+ to.set(...this.get());
3421
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
3422
+ to.length = length;
3423
+ to.pos = pos;
3424
+ to.finished = finished;
3425
+ to.destroyed = destroyed;
3426
+ if (length % blockLen)
3427
+ to.buffer.set(buffer);
3428
+ return to;
3429
+ }
3430
+ }
3431
+
3432
+ // Choice: a ? b : c
3433
+ const Chi = (a, b, c) => (a & b) ^ (~a & c);
3434
+ // Majority function, true if any two inpust is true
3435
+ const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
3436
+ // Round constants:
3437
+ // first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
3438
+ // prettier-ignore
3439
+ const SHA256_K = new Uint32Array([
3440
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
3441
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
3442
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
3443
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
3444
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
3445
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
3446
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
3447
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
3448
+ ]);
3449
+ // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
3450
+ // prettier-ignore
3451
+ const IV = new Uint32Array([
3452
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
3453
+ ]);
3454
+ // Temporary buffer, not used to store anything between runs
3455
+ // Named this way because it matches specification.
3456
+ const SHA256_W = new Uint32Array(64);
3457
+ class SHA256 extends SHA2 {
3458
+ constructor() {
3459
+ super(64, 32, 8, false);
3460
+ // We cannot use array here since array allows indexing by variable
3461
+ // which means optimizer/compiler cannot use registers.
3462
+ this.A = IV[0] | 0;
3463
+ this.B = IV[1] | 0;
3464
+ this.C = IV[2] | 0;
3465
+ this.D = IV[3] | 0;
3466
+ this.E = IV[4] | 0;
3467
+ this.F = IV[5] | 0;
3468
+ this.G = IV[6] | 0;
3469
+ this.H = IV[7] | 0;
3470
+ }
3471
+ get() {
3472
+ const { A, B, C, D, E, F, G, H } = this;
3473
+ return [A, B, C, D, E, F, G, H];
3474
+ }
3475
+ // prettier-ignore
3476
+ set(A, B, C, D, E, F, G, H) {
3477
+ this.A = A | 0;
3478
+ this.B = B | 0;
3479
+ this.C = C | 0;
3480
+ this.D = D | 0;
3481
+ this.E = E | 0;
3482
+ this.F = F | 0;
3483
+ this.G = G | 0;
3484
+ this.H = H | 0;
3485
+ }
3486
+ process(view, offset) {
3487
+ // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
3488
+ for (let i = 0; i < 16; i++, offset += 4)
3489
+ SHA256_W[i] = view.getUint32(offset, false);
3490
+ for (let i = 16; i < 64; i++) {
3491
+ const W15 = SHA256_W[i - 15];
3492
+ const W2 = SHA256_W[i - 2];
3493
+ const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
3494
+ const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
3495
+ SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
3496
+ }
3497
+ // Compression function main loop, 64 rounds
3498
+ let { A, B, C, D, E, F, G, H } = this;
3499
+ for (let i = 0; i < 64; i++) {
3500
+ const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
3501
+ const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
3502
+ const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
3503
+ const T2 = (sigma0 + Maj(A, B, C)) | 0;
3504
+ H = G;
3505
+ G = F;
3506
+ F = E;
3507
+ E = (D + T1) | 0;
3508
+ D = C;
3509
+ C = B;
3510
+ B = A;
3511
+ A = (T1 + T2) | 0;
3512
+ }
3513
+ // Add the compressed chunk to the current hash value
3514
+ A = (A + this.A) | 0;
3515
+ B = (B + this.B) | 0;
3516
+ C = (C + this.C) | 0;
3517
+ D = (D + this.D) | 0;
3518
+ E = (E + this.E) | 0;
3519
+ F = (F + this.F) | 0;
3520
+ G = (G + this.G) | 0;
3521
+ H = (H + this.H) | 0;
3522
+ this.set(A, B, C, D, E, F, G, H);
3523
+ }
3524
+ roundClean() {
3525
+ SHA256_W.fill(0);
3526
+ }
3527
+ destroy() {
3528
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
3529
+ this.buffer.fill(0);
3530
+ }
3531
+ }
3532
+ /**
3533
+ * SHA2-256 hash function
3534
+ * @param message - data that would be hashed
3535
+ */
3536
+ const sha256$1 = wrapConstructor(() => new SHA256());
3537
+
3538
+ // base-x encoding / decoding
3539
+ // Copyright (c) 2018 base-x contributors
3540
+ // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
3541
+ // Distributed under the MIT software license, see the accompanying
3542
+ // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
3543
+ function base (ALPHABET, name) {
3544
+ if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
3545
+ var BASE_MAP = new Uint8Array(256);
3546
+ for (var j = 0; j < BASE_MAP.length; j++) {
3547
+ BASE_MAP[j] = 255;
3548
+ }
3549
+ for (var i = 0; i < ALPHABET.length; i++) {
3550
+ var x = ALPHABET.charAt(i);
3551
+ var xc = x.charCodeAt(0);
3552
+ if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
3553
+ BASE_MAP[xc] = i;
3554
+ }
3555
+ var BASE = ALPHABET.length;
3556
+ var LEADER = ALPHABET.charAt(0);
3557
+ var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
3558
+ var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
3559
+ function encode (source) {
3560
+ if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
3561
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
3562
+ } else if (Array.isArray(source)) {
3563
+ source = Uint8Array.from(source);
3564
+ }
3565
+ if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
3566
+ if (source.length === 0) { return '' }
3567
+ // Skip & count leading zeroes.
3568
+ var zeroes = 0;
3569
+ var length = 0;
3570
+ var pbegin = 0;
3571
+ var pend = source.length;
3572
+ while (pbegin !== pend && source[pbegin] === 0) {
3573
+ pbegin++;
3574
+ zeroes++;
3575
+ }
3576
+ // Allocate enough space in big-endian base58 representation.
3577
+ var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
3578
+ var b58 = new Uint8Array(size);
3579
+ // Process the bytes.
3580
+ while (pbegin !== pend) {
3581
+ var carry = source[pbegin];
3582
+ // Apply "b58 = b58 * 256 + ch".
3583
+ var i = 0;
3584
+ for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
3585
+ carry += (256 * b58[it1]) >>> 0;
3586
+ b58[it1] = (carry % BASE) >>> 0;
3587
+ carry = (carry / BASE) >>> 0;
3588
+ }
3589
+ if (carry !== 0) { throw new Error('Non-zero carry') }
3590
+ length = i;
3591
+ pbegin++;
3592
+ }
3593
+ // Skip leading zeroes in base58 result.
3594
+ var it2 = size - length;
3595
+ while (it2 !== size && b58[it2] === 0) {
3596
+ it2++;
3597
+ }
3598
+ // Translate the result into a string.
3599
+ var str = LEADER.repeat(zeroes);
3600
+ for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
3601
+ return str
3602
+ }
3603
+ function decodeUnsafe (source) {
3604
+ if (typeof source !== 'string') { throw new TypeError('Expected String') }
3605
+ if (source.length === 0) { return new Uint8Array() }
3606
+ var psz = 0;
3607
+ // Skip leading spaces.
3608
+ if (source[psz] === ' ') { return }
3609
+ // Skip and count leading '1's.
3610
+ var zeroes = 0;
3611
+ var length = 0;
3612
+ while (source[psz] === LEADER) {
3613
+ zeroes++;
3614
+ psz++;
3615
+ }
3616
+ // Allocate enough space in big-endian base256 representation.
3617
+ var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
3618
+ var b256 = new Uint8Array(size);
3619
+ // Process the characters.
3620
+ while (source[psz]) {
3621
+ // Decode character
3622
+ var carry = BASE_MAP[source.charCodeAt(psz)];
3623
+ // Invalid character
3624
+ if (carry === 255) { return }
3625
+ var i = 0;
3626
+ for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
3627
+ carry += (BASE * b256[it3]) >>> 0;
3628
+ b256[it3] = (carry % 256) >>> 0;
3629
+ carry = (carry / 256) >>> 0;
3630
+ }
3631
+ if (carry !== 0) { throw new Error('Non-zero carry') }
3632
+ length = i;
3633
+ psz++;
3634
+ }
3635
+ // Skip trailing spaces.
3636
+ if (source[psz] === ' ') { return }
3637
+ // Skip leading zeroes in b256.
3638
+ var it4 = size - length;
3639
+ while (it4 !== size && b256[it4] === 0) {
3640
+ it4++;
3641
+ }
3642
+ var vch = new Uint8Array(zeroes + (size - it4));
3643
+ var j = zeroes;
3644
+ while (it4 !== size) {
3645
+ vch[j++] = b256[it4++];
3646
+ }
3647
+ return vch
3648
+ }
3649
+ function decode (string) {
3650
+ var buffer = decodeUnsafe(string);
3651
+ if (buffer) { return buffer }
3652
+ throw new Error(`Non-${name} character`)
3653
+ }
3654
+ return {
3655
+ encode: encode,
3656
+ decodeUnsafe: decodeUnsafe,
3657
+ decode: decode
3658
+ }
3659
+ }
3660
+ var src = base;
3661
+
3662
+ var _brrp__multiformats_scope_baseX = src;
3663
+
3664
+ /**
3665
+ * @param {Uint8Array} aa
3666
+ * @param {Uint8Array} bb
3667
+ */
3668
+ const equals$1 = (aa, bb) => {
3669
+ if (aa === bb) return true
3670
+ if (aa.byteLength !== bb.byteLength) {
3671
+ return false
3672
+ }
3673
+
3674
+ for (let ii = 0; ii < aa.byteLength; ii++) {
3675
+ if (aa[ii] !== bb[ii]) {
3676
+ return false
3677
+ }
3678
+ }
3679
+
3680
+ return true
3681
+ };
3682
+
3683
+ /**
3684
+ * @param {ArrayBufferView|ArrayBuffer|Uint8Array} o
3685
+ * @returns {Uint8Array}
3686
+ */
3687
+ const coerce = o => {
3688
+ if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array') return o
3689
+ if (o instanceof ArrayBuffer) return new Uint8Array(o)
3690
+ if (ArrayBuffer.isView(o)) {
3691
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength)
3692
+ }
3693
+ throw new Error('Unknown type, must be binary type')
3694
+ };
3695
+
3696
+ /**
3697
+ * @param {string} str
3698
+ * @returns {Uint8Array}
3699
+ */
3700
+ const fromString$1 = str => (new TextEncoder()).encode(str);
3701
+
3702
+ /**
3703
+ * @param {Uint8Array} b
3704
+ * @returns {string}
3705
+ */
3706
+ const toString = b => (new TextDecoder()).decode(b);
3707
+
3708
+ /**
3709
+ * Class represents both BaseEncoder and MultibaseEncoder meaning it
3710
+ * can be used to encode to multibase or base encode without multibase
3711
+ * prefix.
3712
+ *
3713
+ * @class
3714
+ * @template {string} Base
3715
+ * @template {string} Prefix
3716
+ * @implements {API.MultibaseEncoder<Prefix>}
3717
+ * @implements {API.BaseEncoder}
3718
+ */
3719
+ class Encoder {
3720
+ /**
3721
+ * @param {Base} name
3722
+ * @param {Prefix} prefix
3723
+ * @param {(bytes:Uint8Array) => string} baseEncode
3724
+ */
3725
+ constructor (name, prefix, baseEncode) {
3726
+ this.name = name;
3727
+ this.prefix = prefix;
3728
+ this.baseEncode = baseEncode;
3729
+ }
3730
+
3731
+ /**
3732
+ * @param {Uint8Array} bytes
3733
+ * @returns {API.Multibase<Prefix>}
3734
+ */
3735
+ encode (bytes) {
3736
+ if (bytes instanceof Uint8Array) {
3737
+ return `${this.prefix}${this.baseEncode(bytes)}`
3738
+ } else {
3739
+ throw Error('Unknown type, must be binary type')
3740
+ }
3741
+ }
3742
+ }
3743
+
3744
+ /**
3745
+ * @template {string} Prefix
3746
+ */
3747
+ /**
3748
+ * Class represents both BaseDecoder and MultibaseDecoder so it could be used
3749
+ * to decode multibases (with matching prefix) or just base decode strings
3750
+ * with corresponding base encoding.
3751
+ *
3752
+ * @class
3753
+ * @template {string} Base
3754
+ * @template {string} Prefix
3755
+ * @implements {API.MultibaseDecoder<Prefix>}
3756
+ * @implements {API.UnibaseDecoder<Prefix>}
3757
+ * @implements {API.BaseDecoder}
3758
+ */
3759
+ class Decoder {
3760
+ /**
3761
+ * @param {Base} name
3762
+ * @param {Prefix} prefix
3763
+ * @param {(text:string) => Uint8Array} baseDecode
3764
+ */
3765
+ constructor (name, prefix, baseDecode) {
3766
+ this.name = name;
3767
+ this.prefix = prefix;
3768
+ /* c8 ignore next 3 */
3769
+ if (prefix.codePointAt(0) === undefined) {
3770
+ throw new Error('Invalid prefix character')
3771
+ }
3772
+ /** @private */
3773
+ this.prefixCodePoint = /** @type {number} */ (prefix.codePointAt(0));
3774
+ this.baseDecode = baseDecode;
3775
+ }
3776
+
3777
+ /**
3778
+ * @param {string} text
3779
+ */
3780
+ decode (text) {
3781
+ if (typeof text === 'string') {
3782
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
3783
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`)
3784
+ }
3785
+ return this.baseDecode(text.slice(this.prefix.length))
3786
+ } else {
3787
+ throw Error('Can only multibase decode strings')
3788
+ }
3789
+ }
3790
+
3791
+ /**
3792
+ * @template {string} OtherPrefix
3793
+ * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
3794
+ * @returns {ComposedDecoder<Prefix|OtherPrefix>}
3795
+ */
3796
+ or (decoder) {
3797
+ return or(this, decoder)
3798
+ }
3799
+ }
3800
+
3801
+ /**
3802
+ * @template {string} Prefix
3803
+ * @typedef {Record<Prefix, API.UnibaseDecoder<Prefix>>} Decoders
3804
+ */
3805
+
3806
+ /**
3807
+ * @template {string} Prefix
3808
+ * @implements {API.MultibaseDecoder<Prefix>}
3809
+ * @implements {API.CombobaseDecoder<Prefix>}
3810
+ */
3811
+ class ComposedDecoder {
3812
+ /**
3813
+ * @param {Decoders<Prefix>} decoders
3814
+ */
3815
+ constructor (decoders) {
3816
+ this.decoders = decoders;
3817
+ }
3818
+
3819
+ /**
3820
+ * @template {string} OtherPrefix
3821
+ * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
3822
+ * @returns {ComposedDecoder<Prefix|OtherPrefix>}
3823
+ */
3824
+ or (decoder) {
3825
+ return or(this, decoder)
3826
+ }
3827
+
3828
+ /**
3829
+ * @param {string} input
3830
+ * @returns {Uint8Array}
3831
+ */
3832
+ decode (input) {
3833
+ const prefix = /** @type {Prefix} */ (input[0]);
3834
+ const decoder = this.decoders[prefix];
3835
+ if (decoder) {
3836
+ return decoder.decode(input)
3837
+ } else {
3838
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)
3839
+ }
3840
+ }
3841
+ }
3842
+
3843
+ /**
3844
+ * @template {string} L
3845
+ * @template {string} R
3846
+ * @param {API.UnibaseDecoder<L>|API.CombobaseDecoder<L>} left
3847
+ * @param {API.UnibaseDecoder<R>|API.CombobaseDecoder<R>} right
3848
+ * @returns {ComposedDecoder<L|R>}
3849
+ */
3850
+ const or = (left, right) => new ComposedDecoder(/** @type {Decoders<L|R>} */({
3851
+ ...(left.decoders || { [/** @type API.UnibaseDecoder<L> */(left).prefix]: left }),
3852
+ ...(right.decoders || { [/** @type API.UnibaseDecoder<R> */(right).prefix]: right })
3853
+ }));
3854
+
3855
+ /**
3856
+ * @class
3857
+ * @template {string} Base
3858
+ * @template {string} Prefix
3859
+ * @implements {API.MultibaseCodec<Prefix>}
3860
+ * @implements {API.MultibaseEncoder<Prefix>}
3861
+ * @implements {API.MultibaseDecoder<Prefix>}
3862
+ * @implements {API.BaseCodec}
3863
+ * @implements {API.BaseEncoder}
3864
+ * @implements {API.BaseDecoder}
3865
+ */
3866
+ class Codec {
3867
+ /**
3868
+ * @param {Base} name
3869
+ * @param {Prefix} prefix
3870
+ * @param {(bytes:Uint8Array) => string} baseEncode
3871
+ * @param {(text:string) => Uint8Array} baseDecode
3872
+ */
3873
+ constructor (name, prefix, baseEncode, baseDecode) {
3874
+ this.name = name;
3875
+ this.prefix = prefix;
3876
+ this.baseEncode = baseEncode;
3877
+ this.baseDecode = baseDecode;
3878
+ this.encoder = new Encoder(name, prefix, baseEncode);
3879
+ this.decoder = new Decoder(name, prefix, baseDecode);
3880
+ }
3881
+
3882
+ /**
3883
+ * @param {Uint8Array} input
3884
+ */
3885
+ encode (input) {
3886
+ return this.encoder.encode(input)
3887
+ }
3888
+
3889
+ /**
3890
+ * @param {string} input
3891
+ */
3892
+ decode (input) {
3893
+ return this.decoder.decode(input)
3894
+ }
3895
+ }
3896
+
3897
+ /**
3898
+ * @template {string} Base
3899
+ * @template {string} Prefix
3900
+ * @param {object} options
3901
+ * @param {Base} options.name
3902
+ * @param {Prefix} options.prefix
3903
+ * @param {(bytes:Uint8Array) => string} options.encode
3904
+ * @param {(input:string) => Uint8Array} options.decode
3905
+ * @returns {Codec<Base, Prefix>}
3906
+ */
3907
+ const from$1 = ({ name, prefix, encode, decode }) =>
3908
+ new Codec(name, prefix, encode, decode);
3909
+
3910
+ /**
3911
+ * @template {string} Base
3912
+ * @template {string} Prefix
3913
+ * @param {object} options
3914
+ * @param {Base} options.name
3915
+ * @param {Prefix} options.prefix
3916
+ * @param {string} options.alphabet
3917
+ * @returns {Codec<Base, Prefix>}
3918
+ */
3919
+ const baseX = ({ prefix, name, alphabet }) => {
3920
+ const { encode, decode } = _brrp__multiformats_scope_baseX(alphabet, name);
3921
+ return from$1({
3922
+ prefix,
3923
+ name,
3924
+ encode,
3925
+ /**
3926
+ * @param {string} text
3927
+ */
3928
+ decode: text => coerce(decode(text))
3929
+ })
3930
+ };
3931
+
3932
+ /**
3933
+ * @param {string} string
3934
+ * @param {string} alphabet
3935
+ * @param {number} bitsPerChar
3936
+ * @param {string} name
3937
+ * @returns {Uint8Array}
3938
+ */
3939
+ const decode$4 = (string, alphabet, bitsPerChar, name) => {
3940
+ // Build the character lookup table:
3941
+ /** @type {Record<string, number>} */
3942
+ const codes = {};
3943
+ for (let i = 0; i < alphabet.length; ++i) {
3944
+ codes[alphabet[i]] = i;
3945
+ }
3946
+
3947
+ // Count the padding bytes:
3948
+ let end = string.length;
3949
+ while (string[end - 1] === '=') {
3950
+ --end;
3951
+ }
3952
+
3953
+ // Allocate the output:
3954
+ const out = new Uint8Array((end * bitsPerChar / 8) | 0);
3955
+
3956
+ // Parse the data:
3957
+ let bits = 0; // Number of bits currently in the buffer
3958
+ let buffer = 0; // Bits waiting to be written out, MSB first
3959
+ let written = 0; // Next byte to write
3960
+ for (let i = 0; i < end; ++i) {
3961
+ // Read one character from the string:
3962
+ const value = codes[string[i]];
3963
+ if (value === undefined) {
3964
+ throw new SyntaxError(`Non-${name} character`)
3965
+ }
3966
+
3967
+ // Append the bits to the buffer:
3968
+ buffer = (buffer << bitsPerChar) | value;
3969
+ bits += bitsPerChar;
3970
+
3971
+ // Write out some bits if the buffer has a byte's worth:
3972
+ if (bits >= 8) {
3973
+ bits -= 8;
3974
+ out[written++] = 0xff & (buffer >> bits);
3975
+ }
3976
+ }
3977
+
3978
+ // Verify that we have received just enough bits:
3979
+ if (bits >= bitsPerChar || 0xff & (buffer << (8 - bits))) {
3980
+ throw new SyntaxError('Unexpected end of data')
3981
+ }
3982
+
3983
+ return out
3984
+ };
3985
+
3986
+ /**
3987
+ * @param {Uint8Array} data
3988
+ * @param {string} alphabet
3989
+ * @param {number} bitsPerChar
3990
+ * @returns {string}
3991
+ */
3992
+ const encode$3 = (data, alphabet, bitsPerChar) => {
3993
+ const pad = alphabet[alphabet.length - 1] === '=';
3994
+ const mask = (1 << bitsPerChar) - 1;
3995
+ let out = '';
3996
+
3997
+ let bits = 0; // Number of bits currently in the buffer
3998
+ let buffer = 0; // Bits waiting to be written out, MSB first
3999
+ for (let i = 0; i < data.length; ++i) {
4000
+ // Slurp data into the buffer:
4001
+ buffer = (buffer << 8) | data[i];
4002
+ bits += 8;
4003
+
4004
+ // Write out as much as we can:
4005
+ while (bits > bitsPerChar) {
4006
+ bits -= bitsPerChar;
4007
+ out += alphabet[mask & (buffer >> bits)];
4008
+ }
4009
+ }
4010
+
4011
+ // Partial character:
4012
+ if (bits) {
4013
+ out += alphabet[mask & (buffer << (bitsPerChar - bits))];
4014
+ }
4015
+
4016
+ // Add padding characters until we hit a byte boundary:
4017
+ if (pad) {
4018
+ while ((out.length * bitsPerChar) & 7) {
4019
+ out += '=';
4020
+ }
4021
+ }
4022
+
4023
+ return out
4024
+ };
4025
+
4026
+ /**
4027
+ * RFC4648 Factory
4028
+ *
4029
+ * @template {string} Base
4030
+ * @template {string} Prefix
4031
+ * @param {object} options
4032
+ * @param {Base} options.name
4033
+ * @param {Prefix} options.prefix
4034
+ * @param {string} options.alphabet
4035
+ * @param {number} options.bitsPerChar
4036
+ */
4037
+ const rfc4648 = ({ name, prefix, bitsPerChar, alphabet }) => {
4038
+ return from$1({
4039
+ prefix,
4040
+ name,
4041
+ encode (input) {
4042
+ return encode$3(input, alphabet, bitsPerChar)
4043
+ },
4044
+ decode (input) {
4045
+ return decode$4(input, alphabet, bitsPerChar, name)
4046
+ }
4047
+ })
4048
+ };
4049
+
4050
+ // @ts-check
4051
+
4052
+ const identity$2 = from$1({
4053
+ prefix: '\x00',
4054
+ name: 'identity',
4055
+ encode: (buf) => toString(buf),
4056
+ decode: (str) => fromString$1(str)
4057
+ });
4058
+
4059
+ var identityBase = /*#__PURE__*/Object.freeze({
4060
+ __proto__: null,
4061
+ identity: identity$2
4062
+ });
4063
+
4064
+ // @ts-check
4065
+
4066
+ const base2 = rfc4648({
4067
+ prefix: '0',
4068
+ name: 'base2',
4069
+ alphabet: '01',
4070
+ bitsPerChar: 1
4071
+ });
4072
+
4073
+ var base2$1 = /*#__PURE__*/Object.freeze({
4074
+ __proto__: null,
4075
+ base2: base2
4076
+ });
4077
+
4078
+ // @ts-check
4079
+
4080
+ const base8 = rfc4648({
4081
+ prefix: '7',
4082
+ name: 'base8',
4083
+ alphabet: '01234567',
4084
+ bitsPerChar: 3
4085
+ });
4086
+
4087
+ var base8$1 = /*#__PURE__*/Object.freeze({
4088
+ __proto__: null,
4089
+ base8: base8
4090
+ });
4091
+
4092
+ const base10 = baseX({
4093
+ prefix: '9',
4094
+ name: 'base10',
4095
+ alphabet: '0123456789'
4096
+ });
4097
+
4098
+ var base10$1 = /*#__PURE__*/Object.freeze({
4099
+ __proto__: null,
4100
+ base10: base10
4101
+ });
4102
+
4103
+ // @ts-check
4104
+
4105
+ const base16 = rfc4648({
4106
+ prefix: 'f',
4107
+ name: 'base16',
4108
+ alphabet: '0123456789abcdef',
4109
+ bitsPerChar: 4
4110
+ });
4111
+
4112
+ const base16upper = rfc4648({
4113
+ prefix: 'F',
4114
+ name: 'base16upper',
4115
+ alphabet: '0123456789ABCDEF',
4116
+ bitsPerChar: 4
4117
+ });
4118
+
4119
+ var base16$1 = /*#__PURE__*/Object.freeze({
4120
+ __proto__: null,
4121
+ base16: base16,
4122
+ base16upper: base16upper
4123
+ });
4124
+
4125
+ const base32 = rfc4648({
4126
+ prefix: 'b',
4127
+ name: 'base32',
4128
+ alphabet: 'abcdefghijklmnopqrstuvwxyz234567',
4129
+ bitsPerChar: 5
4130
+ });
4131
+
4132
+ const base32upper = rfc4648({
4133
+ prefix: 'B',
4134
+ name: 'base32upper',
4135
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
4136
+ bitsPerChar: 5
4137
+ });
4138
+
4139
+ const base32pad = rfc4648({
4140
+ prefix: 'c',
4141
+ name: 'base32pad',
4142
+ alphabet: 'abcdefghijklmnopqrstuvwxyz234567=',
4143
+ bitsPerChar: 5
4144
+ });
4145
+
4146
+ const base32padupper = rfc4648({
4147
+ prefix: 'C',
4148
+ name: 'base32padupper',
4149
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=',
4150
+ bitsPerChar: 5
4151
+ });
4152
+
4153
+ const base32hex = rfc4648({
4154
+ prefix: 'v',
4155
+ name: 'base32hex',
4156
+ alphabet: '0123456789abcdefghijklmnopqrstuv',
4157
+ bitsPerChar: 5
4158
+ });
4159
+
4160
+ const base32hexupper = rfc4648({
4161
+ prefix: 'V',
4162
+ name: 'base32hexupper',
4163
+ alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV',
4164
+ bitsPerChar: 5
4165
+ });
4166
+
4167
+ const base32hexpad = rfc4648({
4168
+ prefix: 't',
4169
+ name: 'base32hexpad',
4170
+ alphabet: '0123456789abcdefghijklmnopqrstuv=',
4171
+ bitsPerChar: 5
4172
+ });
4173
+
4174
+ const base32hexpadupper = rfc4648({
4175
+ prefix: 'T',
4176
+ name: 'base32hexpadupper',
4177
+ alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV=',
4178
+ bitsPerChar: 5
4179
+ });
4180
+
4181
+ const base32z = rfc4648({
4182
+ prefix: 'h',
4183
+ name: 'base32z',
4184
+ alphabet: 'ybndrfg8ejkmcpqxot1uwisza345h769',
4185
+ bitsPerChar: 5
4186
+ });
4187
+
4188
+ var base32$1 = /*#__PURE__*/Object.freeze({
4189
+ __proto__: null,
4190
+ base32: base32,
4191
+ base32upper: base32upper,
4192
+ base32pad: base32pad,
4193
+ base32padupper: base32padupper,
4194
+ base32hex: base32hex,
4195
+ base32hexupper: base32hexupper,
4196
+ base32hexpad: base32hexpad,
4197
+ base32hexpadupper: base32hexpadupper,
4198
+ base32z: base32z
3175
4199
  });
3176
4200
 
4201
+ const base36 = baseX({
4202
+ prefix: 'k',
4203
+ name: 'base36',
4204
+ alphabet: '0123456789abcdefghijklmnopqrstuvwxyz'
4205
+ });
4206
+
4207
+ const base36upper = baseX({
4208
+ prefix: 'K',
4209
+ name: 'base36upper',
4210
+ alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4211
+ });
4212
+
4213
+ var base36$1 = /*#__PURE__*/Object.freeze({
4214
+ __proto__: null,
4215
+ base36: base36,
4216
+ base36upper: base36upper
4217
+ });
4218
+
4219
+ const base58btc = baseX({
4220
+ name: 'base58btc',
4221
+ prefix: 'z',
4222
+ alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
4223
+ });
4224
+
4225
+ const base58flickr = baseX({
4226
+ name: 'base58flickr',
4227
+ prefix: 'Z',
4228
+ alphabet: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
4229
+ });
4230
+
4231
+ var base58 = /*#__PURE__*/Object.freeze({
4232
+ __proto__: null,
4233
+ base58btc: base58btc,
4234
+ base58flickr: base58flickr
4235
+ });
4236
+
4237
+ // @ts-check
4238
+
4239
+ const base64 = rfc4648({
4240
+ prefix: 'm',
4241
+ name: 'base64',
4242
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
4243
+ bitsPerChar: 6
4244
+ });
4245
+
4246
+ const base64pad = rfc4648({
4247
+ prefix: 'M',
4248
+ name: 'base64pad',
4249
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
4250
+ bitsPerChar: 6
4251
+ });
4252
+
4253
+ const base64url = rfc4648({
4254
+ prefix: 'u',
4255
+ name: 'base64url',
4256
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
4257
+ bitsPerChar: 6
4258
+ });
4259
+
4260
+ const base64urlpad = rfc4648({
4261
+ prefix: 'U',
4262
+ name: 'base64urlpad',
4263
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=',
4264
+ bitsPerChar: 6
4265
+ });
4266
+
4267
+ var base64$1 = /*#__PURE__*/Object.freeze({
4268
+ __proto__: null,
4269
+ base64: base64,
4270
+ base64pad: base64pad,
4271
+ base64url: base64url,
4272
+ base64urlpad: base64urlpad
4273
+ });
4274
+
4275
+ const alphabet = Array.from('🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂');
4276
+ const alphabetBytesToChars = /** @type {string[]} */ (alphabet.reduce((p, c, i) => { p[i] = c; return p }, /** @type {string[]} */([])));
4277
+ const alphabetCharsToBytes = /** @type {number[]} */ (alphabet.reduce((p, c, i) => { p[/** @type {number} */ (c.codePointAt(0))] = i; return p }, /** @type {number[]} */([])));
4278
+
4279
+ /**
4280
+ * @param {Uint8Array} data
4281
+ * @returns {string}
4282
+ */
4283
+ function encode$2 (data) {
4284
+ return data.reduce((p, c) => {
4285
+ p += alphabetBytesToChars[c];
4286
+ return p
4287
+ }, '')
4288
+ }
4289
+
4290
+ /**
4291
+ * @param {string} str
4292
+ * @returns {Uint8Array}
4293
+ */
4294
+ function decode$3 (str) {
4295
+ const byts = [];
4296
+ for (const char of str) {
4297
+ const byt = alphabetCharsToBytes[/** @type {number} */ (char.codePointAt(0))];
4298
+ if (byt === undefined) {
4299
+ throw new Error(`Non-base256emoji character: ${char}`)
4300
+ }
4301
+ byts.push(byt);
4302
+ }
4303
+ return new Uint8Array(byts)
4304
+ }
4305
+
4306
+ const base256emoji = from$1({
4307
+ prefix: '🚀',
4308
+ name: 'base256emoji',
4309
+ encode: encode$2,
4310
+ decode: decode$3
4311
+ });
4312
+
4313
+ var base256emoji$1 = /*#__PURE__*/Object.freeze({
4314
+ __proto__: null,
4315
+ base256emoji: base256emoji
4316
+ });
4317
+
4318
+ var encode_1 = encode$1;
4319
+
4320
+ var MSB = 0x80
4321
+ , REST = 0x7F
4322
+ , MSBALL = ~REST
4323
+ , INT = Math.pow(2, 31);
4324
+
4325
+ function encode$1(num, out, offset) {
4326
+ out = out || [];
4327
+ offset = offset || 0;
4328
+ var oldOffset = offset;
4329
+
4330
+ while(num >= INT) {
4331
+ out[offset++] = (num & 0xFF) | MSB;
4332
+ num /= 128;
4333
+ }
4334
+ while(num & MSBALL) {
4335
+ out[offset++] = (num & 0xFF) | MSB;
4336
+ num >>>= 7;
4337
+ }
4338
+ out[offset] = num | 0;
4339
+
4340
+ encode$1.bytes = offset - oldOffset + 1;
4341
+
4342
+ return out
4343
+ }
4344
+
4345
+ var decode$2 = read;
4346
+
4347
+ var MSB$1 = 0x80
4348
+ , REST$1 = 0x7F;
4349
+
4350
+ function read(buf, offset) {
4351
+ var res = 0
4352
+ , offset = offset || 0
4353
+ , shift = 0
4354
+ , counter = offset
4355
+ , b
4356
+ , l = buf.length;
4357
+
4358
+ do {
4359
+ if (counter >= l) {
4360
+ read.bytes = 0;
4361
+ throw new RangeError('Could not decode varint')
4362
+ }
4363
+ b = buf[counter++];
4364
+ res += shift < 28
4365
+ ? (b & REST$1) << shift
4366
+ : (b & REST$1) * Math.pow(2, shift);
4367
+ shift += 7;
4368
+ } while (b >= MSB$1)
4369
+
4370
+ read.bytes = counter - offset;
4371
+
4372
+ return res
4373
+ }
4374
+
4375
+ var N1 = Math.pow(2, 7);
4376
+ var N2 = Math.pow(2, 14);
4377
+ var N3 = Math.pow(2, 21);
4378
+ var N4 = Math.pow(2, 28);
4379
+ var N5 = Math.pow(2, 35);
4380
+ var N6 = Math.pow(2, 42);
4381
+ var N7 = Math.pow(2, 49);
4382
+ var N8 = Math.pow(2, 56);
4383
+ var N9 = Math.pow(2, 63);
4384
+
4385
+ var length = function (value) {
4386
+ return (
4387
+ value < N1 ? 1
4388
+ : value < N2 ? 2
4389
+ : value < N3 ? 3
4390
+ : value < N4 ? 4
4391
+ : value < N5 ? 5
4392
+ : value < N6 ? 6
4393
+ : value < N7 ? 7
4394
+ : value < N8 ? 8
4395
+ : value < N9 ? 9
4396
+ : 10
4397
+ )
4398
+ };
4399
+
4400
+ var varint = {
4401
+ encode: encode_1
4402
+ , decode: decode$2
4403
+ , encodingLength: length
4404
+ };
4405
+
4406
+ var _brrp_varint = varint;
4407
+
4408
+ /**
4409
+ * @param {Uint8Array} data
4410
+ * @param {number} [offset=0]
4411
+ * @returns {[number, number]}
4412
+ */
4413
+ const decode$1 = (data, offset = 0) => {
4414
+ const code = _brrp_varint.decode(data, offset);
4415
+ return [code, _brrp_varint.decode.bytes]
4416
+ };
4417
+
4418
+ /**
4419
+ * @param {number} int
4420
+ * @param {Uint8Array} target
4421
+ * @param {number} [offset=0]
4422
+ */
4423
+ const encodeTo = (int, target, offset = 0) => {
4424
+ _brrp_varint.encode(int, target, offset);
4425
+ return target
4426
+ };
4427
+
4428
+ /**
4429
+ * @param {number} int
4430
+ * @returns {number}
4431
+ */
4432
+ const encodingLength = (int) => {
4433
+ return _brrp_varint.encodingLength(int)
4434
+ };
4435
+
4436
+ /**
4437
+ * Creates a multihash digest.
4438
+ *
4439
+ * @template {number} Code
4440
+ * @param {Code} code
4441
+ * @param {Uint8Array} digest
4442
+ */
4443
+ const create = (code, digest) => {
4444
+ const size = digest.byteLength;
4445
+ const sizeOffset = encodingLength(code);
4446
+ const digestOffset = sizeOffset + encodingLength(size);
4447
+
4448
+ const bytes = new Uint8Array(digestOffset + size);
4449
+ encodeTo(code, bytes, 0);
4450
+ encodeTo(size, bytes, sizeOffset);
4451
+ bytes.set(digest, digestOffset);
4452
+
4453
+ return new Digest(code, size, digest, bytes)
4454
+ };
4455
+
4456
+ /**
4457
+ * Turns bytes representation of multihash digest into an instance.
4458
+ *
4459
+ * @param {Uint8Array} multihash
4460
+ * @returns {MultihashDigest}
4461
+ */
4462
+ const decode = (multihash) => {
4463
+ const bytes = coerce(multihash);
4464
+ const [code, sizeOffset] = decode$1(bytes);
4465
+ const [size, digestOffset] = decode$1(bytes.subarray(sizeOffset));
4466
+ const digest = bytes.subarray(sizeOffset + digestOffset);
4467
+
4468
+ if (digest.byteLength !== size) {
4469
+ throw new Error('Incorrect length')
4470
+ }
4471
+
4472
+ return new Digest(code, size, digest, bytes)
4473
+ };
4474
+
4475
+ /**
4476
+ * @param {MultihashDigest} a
4477
+ * @param {unknown} b
4478
+ * @returns {b is MultihashDigest}
4479
+ */
4480
+ const equals = (a, b) => {
4481
+ if (a === b) {
4482
+ return true
4483
+ } else {
4484
+ const data = /** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */(b);
4485
+
4486
+ return (
4487
+ a.code === data.code &&
4488
+ a.size === data.size &&
4489
+ data.bytes instanceof Uint8Array &&
4490
+ equals$1(a.bytes, data.bytes)
4491
+ )
4492
+ }
4493
+ };
4494
+
4495
+ /**
4496
+ * @typedef {import('./interface.js').MultihashDigest} MultihashDigest
4497
+ */
4498
+
4499
+ /**
4500
+ * Represents a multihash digest which carries information about the
4501
+ * hashing alogrithm and an actual hash digest.
4502
+ *
4503
+ * @template {number} Code
4504
+ * @template {number} Size
4505
+ * @class
4506
+ * @implements {MultihashDigest}
4507
+ */
4508
+ class Digest {
4509
+ /**
4510
+ * Creates a multihash digest.
4511
+ *
4512
+ * @param {Code} code
4513
+ * @param {Size} size
4514
+ * @param {Uint8Array} digest
4515
+ * @param {Uint8Array} bytes
4516
+ */
4517
+ constructor (code, size, digest, bytes) {
4518
+ this.code = code;
4519
+ this.size = size;
4520
+ this.digest = digest;
4521
+ this.bytes = bytes;
4522
+ }
4523
+ }
4524
+
4525
+ /**
4526
+ * @template {string} Name
4527
+ * @template {number} Code
4528
+ * @param {object} options
4529
+ * @param {Name} options.name
4530
+ * @param {Code} options.code
4531
+ * @param {(input: Uint8Array) => Await<Uint8Array>} options.encode
4532
+ */
4533
+ const from = ({ name, code, encode }) => new Hasher(name, code, encode);
4534
+
4535
+ /**
4536
+ * Hasher represents a hashing algorithm implementation that produces as
4537
+ * `MultihashDigest`.
4538
+ *
4539
+ * @template {string} Name
4540
+ * @template {number} Code
4541
+ * @class
4542
+ * @implements {MultihashHasher<Code>}
4543
+ */
4544
+ class Hasher {
4545
+ /**
4546
+ *
4547
+ * @param {Name} name
4548
+ * @param {Code} code
4549
+ * @param {(input: Uint8Array) => Await<Uint8Array>} encode
4550
+ */
4551
+ constructor (name, code, encode) {
4552
+ this.name = name;
4553
+ this.code = code;
4554
+ this.encode = encode;
4555
+ }
4556
+
4557
+ /**
4558
+ * @param {Uint8Array} input
4559
+ * @returns {Await<Digest.Digest<Code, number>>}
4560
+ */
4561
+ digest (input) {
4562
+ if (input instanceof Uint8Array) {
4563
+ const result = this.encode(input);
4564
+ return result instanceof Uint8Array
4565
+ ? create(this.code, result)
4566
+ /* c8 ignore next 1 */
4567
+ : result.then(digest => create(this.code, digest))
4568
+ } else {
4569
+ throw Error('Unknown type, must be binary type')
4570
+ /* c8 ignore next 1 */
4571
+ }
4572
+ }
4573
+ }
4574
+
4575
+ /**
4576
+ * @template {number} Alg
4577
+ * @typedef {import('./interface.js').MultihashHasher} MultihashHasher
4578
+ */
4579
+
4580
+ /**
4581
+ * @template T
4582
+ * @typedef {Promise<T>|T} Await
4583
+ */
4584
+
4585
+ /* global crypto */
4586
+
4587
+ /**
4588
+ * @param {AlgorithmIdentifier} name
4589
+ */
4590
+ const sha = name =>
4591
+ /**
4592
+ * @param {Uint8Array} data
4593
+ */
4594
+ async data => new Uint8Array(await crypto.subtle.digest(name, data));
4595
+
4596
+ const sha256 = from({
4597
+ name: 'sha2-256',
4598
+ code: 0x12,
4599
+ encode: sha('SHA-256')
4600
+ });
4601
+
4602
+ const sha512 = from({
4603
+ name: 'sha2-512',
4604
+ code: 0x13,
4605
+ encode: sha('SHA-512')
4606
+ });
4607
+
4608
+ var sha2 = /*#__PURE__*/Object.freeze({
4609
+ __proto__: null,
4610
+ sha256: sha256,
4611
+ sha512: sha512
4612
+ });
4613
+
4614
+ const code = 0x0;
4615
+ const name = 'identity';
4616
+
4617
+ /** @type {(input:Uint8Array) => Uint8Array} */
4618
+ const encode = coerce;
4619
+
4620
+ /**
4621
+ * @param {Uint8Array} input
4622
+ * @returns {Digest.Digest<typeof code, number>}
4623
+ */
4624
+ const digest = (input) => create(code, encode(input));
4625
+
4626
+ const identity = { code, name, encode, digest };
4627
+
4628
+ var identity$1 = /*#__PURE__*/Object.freeze({
4629
+ __proto__: null,
4630
+ identity: identity
4631
+ });
4632
+
4633
+ // @ts-check
4634
+
4635
+ /**
4636
+ * @template T
4637
+ * @typedef {import('./interface.js').ByteView<T>} ByteView
4638
+ */
4639
+
4640
+ new TextEncoder();
4641
+ new TextDecoder();
4642
+
4643
+ // @ts-check
4644
+
4645
+ const bases = { ...identityBase, ...base2$1, ...base8$1, ...base10$1, ...base16$1, ...base32$1, ...base36$1, ...base58, ...base64$1, ...base256emoji$1 };
4646
+ ({ ...sha2, ...identity$1 });
4647
+
4648
+ function createCodec(name, prefix, encode, decode) {
4649
+ return {
4650
+ name,
4651
+ prefix,
4652
+ encoder: {
4653
+ name,
4654
+ prefix,
4655
+ encode
4656
+ },
4657
+ decoder: {
4658
+ decode
4659
+ }
4660
+ };
4661
+ }
4662
+ const string = createCodec('utf8', 'u', (buf) => {
4663
+ const decoder = new TextDecoder('utf8');
4664
+ return 'u' + decoder.decode(buf);
4665
+ }, (str) => {
4666
+ const encoder = new TextEncoder();
4667
+ return encoder.encode(str.substring(1));
4668
+ });
4669
+ const ascii = createCodec('ascii', 'a', (buf) => {
4670
+ let string = 'a';
4671
+ for (let i = 0; i < buf.length; i++) {
4672
+ string += String.fromCharCode(buf[i]);
4673
+ }
4674
+ return string;
4675
+ }, (str) => {
4676
+ str = str.substring(1);
4677
+ const buf = allocUnsafe$1(str.length);
4678
+ for (let i = 0; i < str.length; i++) {
4679
+ buf[i] = str.charCodeAt(i);
4680
+ }
4681
+ return buf;
4682
+ });
4683
+ const BASES = {
4684
+ utf8: string,
4685
+ 'utf-8': string,
4686
+ hex: bases.base16,
4687
+ latin1: ascii,
4688
+ ascii: ascii,
4689
+ binary: ascii,
4690
+ ...bases
4691
+ };
4692
+
4693
+ /**
4694
+ * Create a `Uint8Array` from the passed string
4695
+ *
4696
+ * Supports `utf8`, `utf-8`, `hex`, and any encoding supported by the multiformats module.
4697
+ *
4698
+ * Also `ascii` which is similar to node's 'binary' encoding.
4699
+ */
4700
+ function fromString(string, encoding = 'utf8') {
4701
+ const base = BASES[encoding];
4702
+ if (base == null) {
4703
+ throw new Error(`Unsupported encoding "${encoding}"`);
4704
+ }
4705
+ if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
4706
+ return asUint8Array(globalThis.Buffer.from(string, 'utf-8'));
4707
+ }
4708
+ // add multibase prefix
4709
+ return base.decoder.decode(`${base.prefix}${string}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
4710
+ }
4711
+
4712
+ /**
4713
+ * Encode utf-8 string to byte array.
4714
+ */
4715
+ const utf8ToBytes = (s) => fromString(s, "utf8");
4716
+ /**
4717
+ * Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
4718
+ */
4719
+ function concat(byteArrays, totalLength) {
4720
+ const len = totalLength ?? byteArrays.reduce((acc, curr) => acc + curr.length, 0);
4721
+ const res = new Uint8Array(len);
4722
+ let offset = 0;
4723
+ for (const bytes of byteArrays) {
4724
+ res.set(bytes, offset);
4725
+ offset += bytes.length;
4726
+ }
4727
+ return res;
4728
+ }
4729
+
3177
4730
  /* eslint-disable import/export */
3178
4731
  var Index;
3179
4732
  (function (Index) {
@@ -3727,6 +5280,10 @@ var WakuMessage;
3727
5280
  writer.uint32(170);
3728
5281
  RateLimitProof.codec().encode(obj.rateLimitProof, writer);
3729
5282
  }
5283
+ if (obj.ephemeral != null) {
5284
+ writer.uint32(248);
5285
+ writer.bool(obj.ephemeral);
5286
+ }
3730
5287
  if (opts.lengthDelimited !== false) {
3731
5288
  writer.ldelim();
3732
5289
  }
@@ -3754,6 +5311,9 @@ var WakuMessage;
3754
5311
  case 21:
3755
5312
  obj.rateLimitProof = RateLimitProof.codec().decode(reader, reader.uint32());
3756
5313
  break;
5314
+ case 31:
5315
+ obj.ephemeral = reader.bool();
5316
+ break;
3757
5317
  default:
3758
5318
  reader.skipType(tag & 7);
3759
5319
  break;
@@ -3851,8 +5411,8 @@ const DefaultPageSize = 10;
3851
5411
  * The Waku Store protocol can be used to retrieved historical messages.
3852
5412
  */
3853
5413
  class WakuStore {
3854
- constructor(libp2p, options) {
3855
- this.libp2p = libp2p;
5414
+ constructor(components, options) {
5415
+ this.components = components;
3856
5416
  this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
3857
5417
  }
3858
5418
  /**
@@ -3960,19 +5520,19 @@ class WakuStore {
3960
5520
  pageSize: DefaultPageSize,
3961
5521
  }, options, { contentTopics, startTime, endTime });
3962
5522
  log("Querying history with the following options", {
3963
- peerId: options?.peerId?.toString(),
3964
5523
  ...options,
5524
+ peerId: options?.peerId?.toString(),
3965
5525
  });
3966
- const res = await selectPeerForProtocol(this.libp2p.peerStore, [StoreCodec], options?.peerId);
5526
+ const res = await selectPeerForProtocol(this.components.peerStore, [StoreCodec], options?.peerId);
3967
5527
  if (!res) {
3968
5528
  throw new Error("Failed to get a peer");
3969
5529
  }
3970
5530
  const { peer, protocol } = res;
3971
- const connections = this.libp2p.connectionManager.getConnections(peer.id);
5531
+ const connections = this.components.connectionManager.getConnections(peer.id);
3972
5532
  const connection = selectConnection(connections);
3973
5533
  if (!connection)
3974
5534
  throw "Failed to get a connection to the peer";
3975
- for await (const messages of paginate(connection, protocol, queryOpts, decodersAsMap)) {
5535
+ for await (const messages of paginate(connection, protocol, queryOpts, decodersAsMap, options?.cursor)) {
3976
5536
  yield messages;
3977
5537
  }
3978
5538
  }
@@ -3981,21 +5541,23 @@ class WakuStore {
3981
5541
  * store protocol. Waku may or may not be currently connected to these peers.
3982
5542
  */
3983
5543
  async peers() {
3984
- return getPeersForProtocol(this.libp2p.peerStore, [StoreCodec]);
5544
+ return getPeersForProtocol(this.components.peerStore, [StoreCodec]);
5545
+ }
5546
+ get peerStore() {
5547
+ return this.components.peerStore;
3985
5548
  }
3986
5549
  }
3987
- async function* paginate(connection, protocol, queryOpts, decoders) {
5550
+ async function* paginate(connection, protocol, queryOpts, decoders, cursor) {
3988
5551
  if (queryOpts.contentTopics.toString() !==
3989
5552
  Array.from(decoders.keys()).toString()) {
3990
5553
  throw new Error("Internal error, the decoders should match the query's content topics");
3991
5554
  }
3992
- let cursor = undefined;
3993
5555
  while (true) {
3994
5556
  queryOpts = Object.assign(queryOpts, { cursor });
3995
5557
  const stream = await connection.newStream(protocol);
3996
5558
  const historyRpcQuery = HistoryRPC.createQuery(queryOpts);
3997
5559
  log("Querying store peer", connection.remoteAddr.toString(), `for (${queryOpts.pubSubTopic})`, queryOpts.contentTopics);
3998
- const res = await pipe([historyRpcQuery.encode()], encode(), stream, decode(), async (source) => await itAll(source));
5560
+ const res = await pipe([historyRpcQuery.encode()], encode$4(), stream, decode$5(), async (source) => await itAll(source));
3999
5561
  const bytes = new Uint8ArrayList();
4000
5562
  res.forEach((chunk) => {
4001
5563
  bytes.append(chunk);
@@ -4046,14 +5608,35 @@ async function* paginate(connection, protocol, queryOpts, decoders) {
4046
5608
  function isDefined(msg) {
4047
5609
  return !!msg;
4048
5610
  }
5611
+ async function createCursor(message, pubsubTopic = DefaultPubSubTopic) {
5612
+ if (!message ||
5613
+ !message.timestamp ||
5614
+ !message.payload ||
5615
+ !message.contentTopic) {
5616
+ throw new Error("Message is missing required fields");
5617
+ }
5618
+ const contentTopicBytes = utf8ToBytes(message.contentTopic);
5619
+ const digest = sha256$1(concat([contentTopicBytes, message.payload]));
5620
+ const messageTime = BigInt(message.timestamp.getTime()) * BigInt(1000000);
5621
+ return {
5622
+ digest,
5623
+ pubsubTopic,
5624
+ senderTime: messageTime,
5625
+ receivedTime: messageTime,
5626
+ };
5627
+ }
5628
+ function wakuStore(init = {}) {
5629
+ return (components) => new WakuStore(components, init);
5630
+ }
4049
5631
 
4050
5632
  var index = /*#__PURE__*/Object.freeze({
4051
5633
  __proto__: null,
4052
5634
  StoreCodec: StoreCodec,
4053
5635
  DefaultPageSize: DefaultPageSize,
4054
5636
  get PageDirection () { return PageDirection; },
4055
- WakuStore: WakuStore,
4056
- isDefined: isDefined
5637
+ isDefined: isDefined,
5638
+ createCursor: createCursor,
5639
+ wakuStore: wakuStore
4057
5640
  });
4058
5641
 
4059
- export { DefaultPubSubTopic as D, FilterCodec as F, LightPushCodec as L, Protocols as P, StoreCodec as S, Uint8ArrayList as U, WakuFilter as W, pipe as a, index$1 as b, WakuLightPush as c, decode as d, encode as e, PushResponse as f, index as g, PageDirection as h, index$2 as i, WakuStore as j, pushable$1 as p, unsigned as u };
5642
+ export { wakuLightPush as A, BASES as B, PushResponse as C, Digest as D, index as E, FilterCodec as F, PageDirection as G, wakuStore as H, createCursor as I, LightPushCodec as L, Protocols as P, StoreCodec as S, Uint8ArrayList as U, coerce as a, base32 as b, create as c, decode as d, equals as e, base58btc as f, encodeTo as g, decode$1 as h, encodingLength as i, concat$1 as j, fromString as k, errCode as l, base64 as m, equals$2 as n, identity as o, bases as p, pushable$1 as q, pipe as r, sha256 as s, encode$4 as t, unsigned as u, decode$5 as v, DefaultPubSubTopic as w, index$2 as x, wakuFilter as y, index$1 as z };