@waku/core 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [@waku/core@0.0.9] - 2023-01-18
11
+
12
+ ### Changed
13
+
14
+ - Removed `/vac/waku/relay/2.0.0-beta2` from `WakuRelay` protocols.
15
+ - Moved `@chai` and `@fast-check` to `dependencies` list.
16
+ - Remove peer exchange from protocols to expect in `waitForRemotePeer` by default.
17
+
18
+ ### Fixed
19
+
20
+ - Documentation links.
21
+
10
22
  ## [@waku/core@0.0.8] - 2022-12-19
11
23
 
12
24
  ### Fixed
@@ -634,7 +646,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
634
646
  - [ReactJS Chat App example](./examples/web-chat).
635
647
  - [Typedoc Documentation](https://js-waku.wakuconnect.dev/).
636
648
 
637
- [unreleased]: https://github.com/status-im/js-waku/compare/@waku/core@0.0.8...HEAD
649
+ [unreleased]: https://github.com/status-im/js-waku/compare/@waku/core@0.0.9...HEAD
650
+ [@waku/core@0.0.9]: https://github.com/waku-org/js-waku/compare/@waku/core@0.0.8...@waku/core@0.0.9
638
651
  [@waku/core@0.0.8]: https://github.com/waku-org/js-waku/compare/@waku/core@0.0.7...@waku/core@0.0.8
639
652
  [@waku/core@0.0.7]: https://github.com/waku-org/js-waku/compare/@waku/core@0.0.6...@waku/core@0.0.7
640
653
  [@waku/core@0.0.6]: https://github.com/waku-org/js-waku/compare/@waku/core@0.0.5...@waku/core@0.0.6
package/bundle/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { c as commonjsGlobal, a as aspromise, b as base64$5, e as eventemitter, f as float, i as inquire_1, u as utf8$6, p as pool_1, g as getAugmentedNamespace, d as debug, F as FilterRPC$1, P as PushRPC$1, h as PushResponse, H as HistoryRPC$1, j as PagingInfo, k as HistoryResponse, l as getDefaultExportFromCjs } from './peer_exchange-df95c3a7.js';
2
- import { createEncoder } from './lib/message/version_0.js';
3
- export { DecodedMessage, createDecoder, createEncoder } from './lib/message/version_0.js';
4
- import { TopicOnlyDecoder } from './lib/message/topic_only_message.js';
1
+ import { c as commonjsGlobal, a as aspromise, b as base64$5, e as eventemitter, f as float, i as inquire_1, u as utf8$6, p as pool_1, g as getAugmentedNamespace, d as debug, F as FilterRPC$1, P as PushRPC$1, h as PushResponse, H as HistoryRPC$1, j as PagingInfo, k as HistoryResponse, l as getDefaultExportFromCjs } from './peer_exchange-53df2b11.js';
2
+ import { c as createEncoder, v as version_0 } from './version_0-b1fc527d.js';
3
+ export { D as DecodedMessage, a as createDecoder, c as createEncoder } from './version_0-b1fc527d.js';
4
+ import { t as topic_only_message, T as TopicOnlyDecoder } from './topic_only_message-ece0fef9.js';
5
5
 
6
6
  /**
7
7
  * DefaultPubSubTopic is the default gossipsub topic to use for Waku.
@@ -24116,12 +24116,12 @@ function decodeWaku2(byte) {
24116
24116
 
24117
24117
  const log$8 = debug("waku:enr");
24118
24118
  class ENR extends Map {
24119
- constructor(kvs = {}, seq = BigInt(1), signature = null) {
24119
+ constructor(kvs = {}, seq = BigInt(1), signature) {
24120
24120
  super(Object.entries(kvs));
24121
24121
  this.seq = seq;
24122
24122
  this.signature = signature;
24123
24123
  }
24124
- static async create(kvs = {}, seq = BigInt(1), signature = null) {
24124
+ static async create(kvs = {}, seq = BigInt(1), signature) {
24125
24125
  const enr = new ENR(kvs, seq, signature);
24126
24126
  try {
24127
24127
  const publicKey = enr.publicKey;
@@ -24198,7 +24198,7 @@ class ENR extends Map {
24198
24198
  return ENR.decode(fromString$1(encoded.slice(4), "base64url"));
24199
24199
  }
24200
24200
  set(k, v) {
24201
- this.signature = null;
24201
+ this.signature = undefined;
24202
24202
  this.seq++;
24203
24203
  return super.set(k, v);
24204
24204
  }
@@ -25957,6 +25957,83 @@ function pipe(first, ...rest) {
25957
25957
  const PeerExchangeCodec = "/vac/waku/peer-exchange/2.0.0-alpha1";
25958
25958
  debug("waku:peer-exchange");
25959
25959
 
25960
+ var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
25961
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
25962
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
25963
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
25964
+ };
25965
+ var _EventEmitter_listeners;
25966
+ /**
25967
+ * Adds types to the EventTarget class. Hopefully this won't be necessary forever.
25968
+ *
25969
+ * https://github.com/microsoft/TypeScript/issues/28357
25970
+ * https://github.com/microsoft/TypeScript/issues/43477
25971
+ * https://github.com/microsoft/TypeScript/issues/299
25972
+ * etc
25973
+ */
25974
+ class EventEmitter extends EventTarget {
25975
+ constructor() {
25976
+ super(...arguments);
25977
+ _EventEmitter_listeners.set(this, new Map());
25978
+ }
25979
+ listenerCount(type) {
25980
+ const listeners = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(type);
25981
+ if (listeners == null) {
25982
+ return 0;
25983
+ }
25984
+ return listeners.length;
25985
+ }
25986
+ addEventListener(type, listener, options) {
25987
+ super.addEventListener(type, listener, options);
25988
+ let list = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(type);
25989
+ if (list == null) {
25990
+ list = [];
25991
+ __classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(type, list);
25992
+ }
25993
+ list.push({
25994
+ callback: listener,
25995
+ once: (options !== true && options !== false && options?.once) ?? false
25996
+ });
25997
+ }
25998
+ removeEventListener(type, listener, options) {
25999
+ super.removeEventListener(type.toString(), listener ?? null, options);
26000
+ let list = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(type);
26001
+ if (list == null) {
26002
+ return;
26003
+ }
26004
+ list = list.filter(({ callback }) => callback !== listener);
26005
+ __classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(type, list);
26006
+ }
26007
+ dispatchEvent(event) {
26008
+ const result = super.dispatchEvent(event);
26009
+ let list = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(event.type);
26010
+ if (list == null) {
26011
+ return result;
26012
+ }
26013
+ list = list.filter(({ once }) => !once);
26014
+ __classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(event.type, list);
26015
+ return result;
26016
+ }
26017
+ }
26018
+ _EventEmitter_listeners = new WeakMap();
26019
+ /**
26020
+ * CustomEvent is a standard event but it's not supported by node.
26021
+ *
26022
+ * Remove this when https://github.com/nodejs/node/issues/40678 is closed.
26023
+ *
26024
+ * Ref: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
26025
+ */
26026
+ class CustomEventPolyfill extends Event {
26027
+ constructor(message, data) {
26028
+ super(message, data);
26029
+ // @ts-expect-error could be undefined
26030
+ this.detail = data?.detail;
26031
+ }
26032
+ }
26033
+ const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill;
26034
+
26035
+ debug("waku:peer-exchange-discovery");
26036
+
25960
26037
  function groupByContentTopic(values) {
25961
26038
  const groupedDecoders = new Map();
25962
26039
  values.forEach((value) => {
@@ -26681,7 +26758,7 @@ function wakuFilter(init = {}) {
26681
26758
  return (components) => new Filter(components, init);
26682
26759
  }
26683
26760
 
26684
- var index$3 = /*#__PURE__*/Object.freeze({
26761
+ var index$4 = /*#__PURE__*/Object.freeze({
26685
26762
  __proto__: null,
26686
26763
  FilterCodec: FilterCodec,
26687
26764
  wakuFilter: wakuFilter
@@ -26794,7 +26871,7 @@ function wakuLightPush(init = {}) {
26794
26871
  return (components) => new LightPush(components, init);
26795
26872
  }
26796
26873
 
26797
- var index$2 = /*#__PURE__*/Object.freeze({
26874
+ var index$3 = /*#__PURE__*/Object.freeze({
26798
26875
  __proto__: null,
26799
26876
  LightPushCodec: LightPushCodec,
26800
26877
  get PushResponse () { return PushResponse; },
@@ -26804,10 +26881,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
26804
26881
  /**
26805
26882
  * RelayCodec is the libp2p identifier for the waku relay protocol
26806
26883
  */
26807
- const RelayCodecs = [
26808
- "/vac/waku/relay/2.0.0-beta2",
26809
- "/vac/waku/relay/2.0.0",
26810
- ];
26884
+ const RelayCodecs = ["/vac/waku/relay/2.0.0"];
26811
26885
  const RelayPingContentTopic = "/relay-ping/1/ping/null";
26812
26886
 
26813
26887
  function number(n) {
@@ -27400,7 +27474,7 @@ function wakuStore(init = {}) {
27400
27474
  return (components) => new Store(components, init);
27401
27475
  }
27402
27476
 
27403
- var index$1 = /*#__PURE__*/Object.freeze({
27477
+ var index$2 = /*#__PURE__*/Object.freeze({
27404
27478
  __proto__: null,
27405
27479
  StoreCodec: StoreCodec,
27406
27480
  DefaultPageSize: DefaultPageSize,
@@ -27591,6 +27665,12 @@ var waku = /*#__PURE__*/Object.freeze({
27591
27665
  WakuNode: WakuNode
27592
27666
  });
27593
27667
 
27668
+ var index$1 = /*#__PURE__*/Object.freeze({
27669
+ __proto__: null,
27670
+ version_0: version_0,
27671
+ topic_only_message: topic_only_message
27672
+ });
27673
+
27594
27674
  const codes = {
27595
27675
  ERR_SIGNATURE_NOT_VALID: 'ERR_SIGNATURE_NOT_VALID'
27596
27676
  };
@@ -29697,81 +29777,6 @@ function createTopology(init) {
29697
29777
  return new TopologyImpl(init);
29698
29778
  }
29699
29779
 
29700
- var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
29701
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
29702
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
29703
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
29704
- };
29705
- var _EventEmitter_listeners;
29706
- /**
29707
- * Adds types to the EventTarget class. Hopefully this won't be necessary forever.
29708
- *
29709
- * https://github.com/microsoft/TypeScript/issues/28357
29710
- * https://github.com/microsoft/TypeScript/issues/43477
29711
- * https://github.com/microsoft/TypeScript/issues/299
29712
- * etc
29713
- */
29714
- class EventEmitter extends EventTarget {
29715
- constructor() {
29716
- super(...arguments);
29717
- _EventEmitter_listeners.set(this, new Map());
29718
- }
29719
- listenerCount(type) {
29720
- const listeners = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(type);
29721
- if (listeners == null) {
29722
- return 0;
29723
- }
29724
- return listeners.length;
29725
- }
29726
- addEventListener(type, listener, options) {
29727
- super.addEventListener(type, listener, options);
29728
- let list = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(type);
29729
- if (list == null) {
29730
- list = [];
29731
- __classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(type, list);
29732
- }
29733
- list.push({
29734
- callback: listener,
29735
- once: (options !== true && options !== false && options?.once) ?? false
29736
- });
29737
- }
29738
- removeEventListener(type, listener, options) {
29739
- super.removeEventListener(type.toString(), listener ?? null, options);
29740
- let list = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(type);
29741
- if (list == null) {
29742
- return;
29743
- }
29744
- list = list.filter(({ callback }) => callback !== listener);
29745
- __classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(type, list);
29746
- }
29747
- dispatchEvent(event) {
29748
- const result = super.dispatchEvent(event);
29749
- let list = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(event.type);
29750
- if (list == null) {
29751
- return result;
29752
- }
29753
- list = list.filter(({ once }) => !once);
29754
- __classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(event.type, list);
29755
- return result;
29756
- }
29757
- }
29758
- _EventEmitter_listeners = new WeakMap();
29759
- /**
29760
- * CustomEvent is a standard event but it's not supported by node.
29761
- *
29762
- * Remove this when https://github.com/nodejs/node/issues/40678 is closed.
29763
- *
29764
- * Ref: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
29765
- */
29766
- class CustomEventPolyfill extends Event {
29767
- constructor(message, data) {
29768
- super(message, data);
29769
- // @ts-expect-error could be undefined
29770
- this.detail = data?.detail;
29771
- }
29772
- }
29773
- const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill;
29774
-
29775
29780
  class MessageCache {
29776
29781
  /**
29777
29782
  * Holds history of messages in timebounded history arrays
@@ -39313,8 +39318,8 @@ const log = debug("waku:wait-for-remote-peer");
39313
39318
  /**
39314
39319
  * Wait for a remote peer to be ready given the passed protocols.
39315
39320
  * Must be used after attempting to connect to nodes, using
39316
- * {@link index.waku.WakuNode.dial} or a bootstrap method with
39317
- * {@link lib/create_waku.createLightNode}.
39321
+ * {@link @waku/core.WakuNode.dial} or a bootstrap method with
39322
+ * {@link @waku/create.createLightNode}.
39318
39323
  *
39319
39324
  * If the passed protocols is a GossipSub protocol, then it resolves only once
39320
39325
  * a peer is in a mesh, to help ensure that other peers will send and receive
@@ -39418,10 +39423,7 @@ function getEnabledProtocols(waku) {
39418
39423
  if (waku.lightPush) {
39419
39424
  protocols.push(Protocols.LightPush);
39420
39425
  }
39421
- if (waku.peerExchange) {
39422
- protocols.push(Protocols.PeerExchange);
39423
- }
39424
39426
  return protocols;
39425
39427
  }
39426
39428
 
39427
- export { DefaultPubSubTopic, DefaultUserAgent, LightPushCodec, PageDirection, StoreCodec, WakuNode, createCursor, waitForRemotePeer, waku, wakuFilter, wakuLightPush, wakuRelay, wakuStore, index$3 as waku_filter, index$2 as waku_light_push, index as waku_relay, index$1 as waku_store };
39429
+ export { DefaultPubSubTopic, DefaultUserAgent, LightPushCodec, PageDirection, StoreCodec, WakuNode, createCursor, index$1 as message, waitForRemotePeer, waku, wakuFilter, wakuLightPush, wakuRelay, wakuStore, index$4 as waku_filter, index$3 as waku_light_push, index as waku_relay, index$2 as waku_store };
@@ -1,33 +1,2 @@
1
- import { d as debug, T as TopicOnlyMessage$1 } from '../../peer_exchange-df95c3a7.js';
2
-
3
- const log = debug("waku:message:topic-only");
4
- class TopicOnlyMessage {
5
- constructor(proto) {
6
- this.proto = proto;
7
- }
8
- get contentTopic() {
9
- return this.proto.contentTopic ?? "";
10
- }
11
- }
12
- class TopicOnlyDecoder {
13
- constructor() {
14
- this.contentTopic = "";
15
- }
16
- fromWireToProtoObj(bytes) {
17
- const protoMessage = TopicOnlyMessage$1.decode(bytes);
18
- log("Message decoded", protoMessage);
19
- return Promise.resolve({
20
- contentTopic: protoMessage.contentTopic,
21
- payload: undefined,
22
- rateLimitProof: undefined,
23
- timestamp: undefined,
24
- version: undefined,
25
- ephemeral: undefined,
26
- });
27
- }
28
- async fromProtoObj(proto) {
29
- return new TopicOnlyMessage(proto);
30
- }
31
- }
32
-
33
- export { TopicOnlyDecoder, TopicOnlyMessage };
1
+ import '../../peer_exchange-53df2b11.js';
2
+ export { T as TopicOnlyDecoder, a as TopicOnlyMessage } from '../../topic_only_message-ece0fef9.js';
@@ -1,133 +1,2 @@
1
- import { d as debug, W as WakuMessage } from '../../peer_exchange-df95c3a7.js';
2
- export { m as proto } from '../../peer_exchange-df95c3a7.js';
3
-
4
- const log = debug("waku:message:version-0");
5
- const OneMillion = BigInt(1000000);
6
- const Version = 0;
7
- class DecodedMessage {
8
- constructor(proto) {
9
- this.proto = proto;
10
- }
11
- get _rawPayload() {
12
- if (this.proto.payload) {
13
- return new Uint8Array(this.proto.payload);
14
- }
15
- return;
16
- }
17
- get ephemeral() {
18
- return Boolean(this.proto.ephemeral);
19
- }
20
- get payload() {
21
- return this._rawPayload;
22
- }
23
- get contentTopic() {
24
- return this.proto.contentTopic;
25
- }
26
- get _rawTimestamp() {
27
- return this.proto.timestamp;
28
- }
29
- get timestamp() {
30
- // In the case we receive a value that is bigger than JS's max number,
31
- // we catch the error and return undefined.
32
- try {
33
- if (this.proto.timestamp) {
34
- // nanoseconds 10^-9 to milliseconds 10^-3
35
- const timestamp = this.proto.timestamp / OneMillion;
36
- return new Date(Number(timestamp));
37
- }
38
- if (this.proto.timestampDeprecated) {
39
- return new Date(this.proto.timestampDeprecated * 1000);
40
- }
41
- }
42
- catch (e) {
43
- return;
44
- }
45
- return;
46
- }
47
- get version() {
48
- // https://github.com/status-im/js-waku/issues/921
49
- return this.proto.version ?? 0;
50
- }
51
- get rateLimitProof() {
52
- return this.proto.rateLimitProof;
53
- }
54
- }
55
- class Encoder {
56
- constructor(contentTopic, ephemeral = false) {
57
- this.contentTopic = contentTopic;
58
- this.ephemeral = ephemeral;
59
- }
60
- async toWire(message$1) {
61
- return WakuMessage.encode(await this.toProtoObj(message$1));
62
- }
63
- async toProtoObj(message) {
64
- const timestamp = message.timestamp ?? new Date();
65
- return {
66
- payload: message.payload,
67
- version: Version,
68
- contentTopic: this.contentTopic,
69
- timestamp: BigInt(timestamp.valueOf()) * OneMillion,
70
- rateLimitProof: message.rateLimitProof,
71
- ephemeral: this.ephemeral,
72
- };
73
- }
74
- }
75
- /**
76
- * Creates an encoder that encode messages without Waku level encryption or signature.
77
- *
78
- * An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
79
- * format to be sent over the Waku network. The resulting encoder can then be
80
- * pass to { @link @waku/interfaces.LightPush.push } or
81
- * { @link @waku/interfaces.Relay.send } to automatically encode outgoing
82
- * messages.
83
- *
84
- * @param contentTopic The content topic to set on outgoing messages.
85
- * @param ephemeral An optional flag to mark message as ephemeral, ie, not to be stored by Waku Store nodes.
86
- */
87
- function createEncoder(contentTopic, ephemeral = false) {
88
- return new Encoder(contentTopic, ephemeral);
89
- }
90
- class Decoder {
91
- constructor(contentTopic) {
92
- this.contentTopic = contentTopic;
93
- }
94
- fromWireToProtoObj(bytes) {
95
- const protoMessage = WakuMessage.decode(bytes);
96
- log("Message decoded", protoMessage);
97
- return Promise.resolve({
98
- payload: protoMessage.payload ?? undefined,
99
- contentTopic: protoMessage.contentTopic ?? undefined,
100
- version: protoMessage.version ?? undefined,
101
- timestamp: protoMessage.timestamp ?? undefined,
102
- rateLimitProof: protoMessage.rateLimitProof ?? undefined,
103
- ephemeral: protoMessage.ephemeral ?? false,
104
- });
105
- }
106
- async fromProtoObj(proto) {
107
- // https://github.com/status-im/js-waku/issues/921
108
- if (proto.version === undefined) {
109
- proto.version = 0;
110
- }
111
- if (proto.version !== Version) {
112
- log("Failed to decode due to incorrect version, expected:", Version, ", actual:", proto.version);
113
- return Promise.resolve(undefined);
114
- }
115
- return new DecodedMessage(proto);
116
- }
117
- }
118
- /**
119
- * Creates an decoder that decode messages without Waku level encryption.
120
- *
121
- * A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
122
- * format when received from the Waku network. The resulting decoder can then be
123
- * pass to { @link @waku/interfaces.Filter.subscribe } or
124
- * { @link @waku/interfaces.Relay.subscribe } to automatically decode incoming
125
- * messages.
126
- *
127
- * @param contentTopic The resulting decoder will only decode messages with this content topic.
128
- */
129
- function createDecoder(contentTopic) {
130
- return new Decoder(contentTopic);
131
- }
132
-
133
- export { DecodedMessage, Decoder, Encoder, Version, createDecoder, createEncoder };
1
+ export { m as proto } from '../../peer_exchange-53df2b11.js';
2
+ export { D as DecodedMessage, b as Decoder, E as Encoder, V as Version, a as createDecoder, c as createEncoder } from '../../version_0-b1fc527d.js';