@waku/core 0.0.5 → 0.0.7

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 (129) hide show
  1. package/CHANGELOG.md +51 -3
  2. package/bundle/index.js +31146 -26342
  3. package/bundle/lib/message/topic_only_message.js +33 -0
  4. package/bundle/lib/message/version_0.js +133 -0
  5. package/bundle/lib/predefined_bootstrap_nodes.js +24 -4
  6. package/bundle/{message-049c8b67.js → peer_exchange-53df2b11.js} +3579 -1007
  7. package/dist/index.d.ts +14 -13
  8. package/dist/index.js +11 -10
  9. package/dist/index.js.map +1 -1
  10. package/dist/lib/{waku_filter → filter}/filter_rpc.d.ts +1 -1
  11. package/dist/lib/{waku_filter → filter}/filter_rpc.js +1 -1
  12. package/dist/lib/filter/filter_rpc.js.map +1 -0
  13. package/dist/lib/filter/index.d.ts +25 -0
  14. package/dist/lib/{waku_filter → filter}/index.js +14 -9
  15. package/dist/lib/filter/index.js.map +1 -0
  16. package/dist/lib/light_push/index.d.ts +22 -0
  17. package/dist/lib/{waku_light_push → light_push}/index.js +14 -9
  18. package/dist/lib/light_push/index.js.map +1 -0
  19. package/dist/lib/{waku_light_push → light_push}/push_rpc.d.ts +1 -1
  20. package/dist/lib/{waku_light_push → light_push}/push_rpc.js +1 -1
  21. package/dist/lib/light_push/push_rpc.js.map +1 -0
  22. package/dist/lib/message/topic_only_message.d.ts +16 -0
  23. package/dist/lib/{waku_message → message}/topic_only_message.js +2 -1
  24. package/dist/lib/message/topic_only_message.js.map +1 -0
  25. package/dist/lib/message/version_0.d.ts +54 -0
  26. package/dist/lib/{waku_message → message}/version_0.js +41 -6
  27. package/dist/lib/message/version_0.js.map +1 -0
  28. package/dist/lib/predefined_bootstrap_nodes.d.ts +1 -2
  29. package/dist/lib/predefined_bootstrap_nodes.js +0 -2
  30. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
  31. package/dist/lib/{waku_relay → relay}/constants.d.ts +0 -0
  32. package/dist/lib/{waku_relay → relay}/constants.js +0 -0
  33. package/dist/lib/relay/constants.js.map +1 -0
  34. package/dist/lib/relay/index.d.ts +24 -0
  35. package/dist/lib/{waku_relay → relay}/index.js +9 -6
  36. package/dist/lib/relay/index.js.map +1 -0
  37. package/dist/lib/{waku_store → store}/history_rpc.d.ts +1 -1
  38. package/dist/lib/{waku_store → store}/history_rpc.js +1 -1
  39. package/dist/lib/store/history_rpc.js.map +1 -0
  40. package/dist/lib/store/index.d.ts +68 -0
  41. package/dist/lib/{waku_store → store}/index.js +41 -16
  42. package/dist/lib/store/index.js.map +1 -0
  43. package/dist/lib/to_proto_message.d.ts +3 -3
  44. package/dist/lib/to_proto_message.js +1 -0
  45. package/dist/lib/to_proto_message.js.map +1 -1
  46. package/dist/lib/wait_for_remote_peer.js +14 -5
  47. package/dist/lib/wait_for_remote_peer.js.map +1 -1
  48. package/dist/lib/waku.d.ts +17 -15
  49. package/dist/lib/waku.js +49 -41
  50. package/dist/lib/waku.js.map +1 -1
  51. package/package.json +28 -31
  52. package/src/index.ts +25 -14
  53. package/src/lib/{waku_filter → filter}/filter_rpc.ts +1 -2
  54. package/src/lib/{waku_filter → filter}/index.ts +51 -30
  55. package/src/lib/{waku_light_push → light_push}/index.ts +38 -19
  56. package/src/lib/{waku_light_push → light_push}/push_rpc.ts +1 -2
  57. package/src/lib/{waku_message → message}/topic_only_message.ts +12 -7
  58. package/src/lib/{waku_message → message}/version_0.ts +59 -18
  59. package/src/lib/predefined_bootstrap_nodes.ts +2 -6
  60. package/src/lib/{waku_relay → relay}/constants.ts +0 -0
  61. package/src/lib/{waku_relay → relay}/index.ts +30 -26
  62. package/src/lib/{waku_store → store}/history_rpc.ts +1 -2
  63. package/src/lib/{waku_store → store}/index.ts +93 -28
  64. package/src/lib/to_proto_message.ts +5 -5
  65. package/src/lib/wait_for_remote_peer.ts +19 -7
  66. package/src/lib/waku.ts +78 -51
  67. package/bundle/browser-1e1a2f27.js +0 -722
  68. package/bundle/events-158407bb.js +0 -1929
  69. package/bundle/index-64ce43f0.js +0 -69
  70. package/bundle/index-8710041d.js +0 -2962
  71. package/bundle/index-a67d7136.js +0 -4059
  72. package/bundle/lib/peer_discovery_static_list.js +0 -89
  73. package/bundle/lib/wait_for_remote_peer.js +0 -326
  74. package/bundle/lib/waku_message/topic_only_message.js +0 -3
  75. package/bundle/lib/waku_message/version_0.js +0 -317
  76. package/bundle/random_subset-75d1c511.js +0 -26
  77. package/bundle/topic_only_message-5ad3a869.js +0 -82
  78. package/dist/lib/multiaddr_to_peer_info.d.ts +0 -3
  79. package/dist/lib/multiaddr_to_peer_info.js +0 -15
  80. package/dist/lib/multiaddr_to_peer_info.js.map +0 -1
  81. package/dist/lib/peer_discovery_static_list.d.ts +0 -44
  82. package/dist/lib/peer_discovery_static_list.js +0 -72
  83. package/dist/lib/peer_discovery_static_list.js.map +0 -1
  84. package/dist/lib/select_connection.d.ts +0 -2
  85. package/dist/lib/select_connection.js +0 -19
  86. package/dist/lib/select_connection.js.map +0 -1
  87. package/dist/lib/select_peer.d.ts +0 -15
  88. package/dist/lib/select_peer.js +0 -59
  89. package/dist/lib/select_peer.js.map +0 -1
  90. package/dist/lib/waku_filter/filter_rpc.js.map +0 -1
  91. package/dist/lib/waku_filter/index.d.ts +0 -50
  92. package/dist/lib/waku_filter/index.js.map +0 -1
  93. package/dist/lib/waku_light_push/index.d.ts +0 -38
  94. package/dist/lib/waku_light_push/index.js.map +0 -1
  95. package/dist/lib/waku_light_push/push_rpc.js.map +0 -1
  96. package/dist/lib/waku_message/topic_only_message.d.ts +0 -15
  97. package/dist/lib/waku_message/topic_only_message.js.map +0 -1
  98. package/dist/lib/waku_message/version_0.d.ts +0 -27
  99. package/dist/lib/waku_message/version_0.js.map +0 -1
  100. package/dist/lib/waku_relay/constants.js.map +0 -1
  101. package/dist/lib/waku_relay/index.d.ts +0 -66
  102. package/dist/lib/waku_relay/index.js.map +0 -1
  103. package/dist/lib/waku_store/history_rpc.js.map +0 -1
  104. package/dist/lib/waku_store/index.d.ts +0 -126
  105. package/dist/lib/waku_store/index.js.map +0 -1
  106. package/dist/proto/filter.d.ts +0 -65
  107. package/dist/proto/filter.js +0 -425
  108. package/dist/proto/filter.js.map +0 -1
  109. package/dist/proto/light_push.d.ts +0 -57
  110. package/dist/proto/light_push.js +0 -369
  111. package/dist/proto/light_push.js.map +0 -1
  112. package/dist/proto/message.d.ts +0 -29
  113. package/dist/proto/message.js +0 -215
  114. package/dist/proto/message.js.map +0 -1
  115. package/dist/proto/store.d.ts +0 -104
  116. package/dist/proto/store.js +0 -602
  117. package/dist/proto/store.js.map +0 -1
  118. package/dist/proto/topic_only_message.d.ts +0 -10
  119. package/dist/proto/topic_only_message.js +0 -46
  120. package/dist/proto/topic_only_message.js.map +0 -1
  121. package/src/lib/multiaddr_to_peer_info.ts +0 -17
  122. package/src/lib/peer_discovery_static_list.ts +0 -118
  123. package/src/lib/select_connection.ts +0 -24
  124. package/src/lib/select_peer.ts +0 -77
  125. package/src/proto/filter.ts +0 -602
  126. package/src/proto/light_push.ts +0 -526
  127. package/src/proto/message.ts +0 -304
  128. package/src/proto/store.ts +0 -844
  129. package/src/proto/topic_only_message.ts +0 -67
@@ -0,0 +1,33 @@
1
+ import { d as debug, T as TopicOnlyMessage$1 } from '../../peer_exchange-53df2b11.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 };
@@ -0,0 +1,133 @@
1
+ import { d as debug, W as WakuMessage } from '../../peer_exchange-53df2b11.js';
2
+ export { m as proto } from '../../peer_exchange-53df2b11.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,6 +1,27 @@
1
- import { m as multiaddr } from '../index-8710041d.js';
2
- import { g as getPseudoRandomSubset } from '../random_subset-75d1c511.js';
3
- import '../index-64ce43f0.js';
1
+ /**
2
+ * Return pseudo random subset of the input.
3
+ */
4
+ function getPseudoRandomSubset(values, wantedNumber) {
5
+ if (values.length <= wantedNumber || values.length <= 1) {
6
+ return values;
7
+ }
8
+ return shuffle(values).slice(0, wantedNumber);
9
+ }
10
+ function shuffle(arr) {
11
+ if (arr.length <= 1) {
12
+ return arr;
13
+ }
14
+ const randInt = () => {
15
+ return Math.floor(Math.random() * Math.floor(arr.length));
16
+ };
17
+ for (let i = 0; i < arr.length; i++) {
18
+ const j = randInt();
19
+ const tmp = arr[i];
20
+ arr[i] = arr[j];
21
+ arr[j] = tmp;
22
+ }
23
+ return arr;
24
+ }
4
25
 
5
26
  const DefaultWantedNumber = 1;
6
27
  var Fleet;
@@ -34,7 +55,6 @@ function getPredefinedBootstrapNodes(fleet = Fleet.Prod, wantedNumber = DefaultW
34
55
  nodes = fleets.fleets["wakuv2.prod"]["waku-websocket"];
35
56
  }
36
57
  nodes = Object.values(nodes);
37
- nodes = nodes.map((node) => multiaddr(node));
38
58
  return getPseudoRandomSubset(nodes, wantedNumber);
39
59
  }
40
60
  const fleets = {