@waku/core 0.0.6 → 0.0.8

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 (111) hide show
  1. package/CHANGELOG.md +42 -4
  2. package/bundle/index.js +10870 -3756
  3. package/bundle/lib/message/topic_only_message.js +33 -0
  4. package/bundle/lib/message/version_0.js +133 -0
  5. package/bundle/{message-70dbb19b.js → peer_exchange-df95c3a7.js} +1899 -16
  6. package/dist/index.d.ts +14 -14
  7. package/dist/index.js +10 -10
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/{waku_filter → filter}/filter_rpc.d.ts +1 -1
  10. package/dist/lib/{waku_filter → filter}/filter_rpc.js +1 -1
  11. package/dist/lib/filter/filter_rpc.js.map +1 -0
  12. package/dist/lib/{waku_filter → filter}/index.d.ts +3 -3
  13. package/dist/lib/{waku_filter → filter}/index.js +3 -4
  14. package/dist/lib/filter/index.js.map +1 -0
  15. package/dist/lib/{waku_light_push → light_push}/index.d.ts +3 -3
  16. package/dist/lib/{waku_light_push → light_push}/index.js +4 -5
  17. package/dist/lib/light_push/index.js.map +1 -0
  18. package/dist/lib/{waku_light_push → light_push}/push_rpc.d.ts +1 -1
  19. package/dist/lib/{waku_light_push → light_push}/push_rpc.js +1 -1
  20. package/dist/lib/light_push/push_rpc.js.map +1 -0
  21. package/dist/lib/message/topic_only_message.d.ts +16 -0
  22. package/dist/lib/{waku_message → message}/topic_only_message.js +1 -1
  23. package/dist/lib/message/topic_only_message.js.map +1 -0
  24. package/dist/lib/message/version_0.d.ts +54 -0
  25. package/dist/lib/{waku_message → message}/version_0.js +35 -7
  26. package/dist/lib/message/version_0.js.map +1 -0
  27. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
  28. package/dist/lib/{waku_relay → relay}/constants.d.ts +0 -0
  29. package/dist/lib/{waku_relay → relay}/constants.js +0 -0
  30. package/dist/lib/relay/constants.js.map +1 -0
  31. package/dist/lib/{waku_relay → relay}/index.d.ts +5 -5
  32. package/dist/lib/{waku_relay → relay}/index.js +5 -5
  33. package/dist/lib/relay/index.js.map +1 -0
  34. package/dist/lib/{waku_store → store}/history_rpc.d.ts +1 -1
  35. package/dist/lib/{waku_store → store}/history_rpc.js +1 -1
  36. package/dist/lib/store/history_rpc.js.map +1 -0
  37. package/dist/lib/{waku_store → store}/index.d.ts +7 -5
  38. package/dist/lib/{waku_store → store}/index.js +9 -8
  39. package/dist/lib/store/index.js.map +1 -0
  40. package/dist/lib/to_proto_message.d.ts +3 -3
  41. package/dist/lib/to_proto_message.js.map +1 -1
  42. package/dist/lib/wait_for_remote_peer.js +12 -3
  43. package/dist/lib/wait_for_remote_peer.js.map +1 -1
  44. package/dist/lib/waku.d.ts +10 -9
  45. package/dist/lib/waku.js +19 -9
  46. package/dist/lib/waku.js.map +1 -1
  47. package/package.json +21 -19
  48. package/src/index.ts +19 -18
  49. package/src/lib/{waku_filter → filter}/filter_rpc.ts +1 -2
  50. package/src/lib/{waku_filter → filter}/index.ts +26 -26
  51. package/src/lib/{waku_light_push → light_push}/index.ts +17 -18
  52. package/src/lib/{waku_light_push → light_push}/push_rpc.ts +1 -2
  53. package/src/lib/{waku_message → message}/topic_only_message.ts +10 -7
  54. package/src/lib/{waku_message → message}/version_0.ts +53 -18
  55. package/src/lib/predefined_bootstrap_nodes.ts +1 -1
  56. package/src/lib/{waku_relay → relay}/constants.ts +0 -0
  57. package/src/lib/{waku_relay → relay}/index.ts +20 -26
  58. package/src/lib/{waku_store → store}/history_rpc.ts +1 -2
  59. package/src/lib/{waku_store → store}/index.ts +38 -24
  60. package/src/lib/to_proto_message.ts +4 -5
  61. package/src/lib/wait_for_remote_peer.ts +17 -5
  62. package/src/lib/waku.ts +40 -17
  63. package/bundle/index-925587a4.js +0 -5642
  64. package/bundle/lib/wait_for_remote_peer.js +0 -324
  65. package/bundle/lib/waku_message/topic_only_message.js +0 -2
  66. package/bundle/lib/waku_message/version_0.js +0 -330
  67. package/bundle/topic_only_message-a80fe8b2.js +0 -82
  68. package/dist/lib/multiaddr_to_peer_info.d.ts +0 -3
  69. package/dist/lib/multiaddr_to_peer_info.js +0 -15
  70. package/dist/lib/multiaddr_to_peer_info.js.map +0 -1
  71. package/dist/lib/select_connection.d.ts +0 -2
  72. package/dist/lib/select_connection.js +0 -19
  73. package/dist/lib/select_connection.js.map +0 -1
  74. package/dist/lib/select_peer.d.ts +0 -15
  75. package/dist/lib/select_peer.js +0 -59
  76. package/dist/lib/select_peer.js.map +0 -1
  77. package/dist/lib/waku_filter/filter_rpc.js.map +0 -1
  78. package/dist/lib/waku_filter/index.js.map +0 -1
  79. package/dist/lib/waku_light_push/index.js.map +0 -1
  80. package/dist/lib/waku_light_push/push_rpc.js.map +0 -1
  81. package/dist/lib/waku_message/topic_only_message.d.ts +0 -16
  82. package/dist/lib/waku_message/topic_only_message.js.map +0 -1
  83. package/dist/lib/waku_message/version_0.d.ts +0 -30
  84. package/dist/lib/waku_message/version_0.js.map +0 -1
  85. package/dist/lib/waku_relay/constants.js.map +0 -1
  86. package/dist/lib/waku_relay/index.js.map +0 -1
  87. package/dist/lib/waku_store/history_rpc.js.map +0 -1
  88. package/dist/lib/waku_store/index.js.map +0 -1
  89. package/dist/proto/filter.d.ts +0 -66
  90. package/dist/proto/filter.js +0 -432
  91. package/dist/proto/filter.js.map +0 -1
  92. package/dist/proto/light_push.d.ts +0 -58
  93. package/dist/proto/light_push.js +0 -376
  94. package/dist/proto/light_push.js.map +0 -1
  95. package/dist/proto/message.d.ts +0 -30
  96. package/dist/proto/message.js +0 -222
  97. package/dist/proto/message.js.map +0 -1
  98. package/dist/proto/store.d.ts +0 -105
  99. package/dist/proto/store.js +0 -609
  100. package/dist/proto/store.js.map +0 -1
  101. package/dist/proto/topic_only_message.d.ts +0 -10
  102. package/dist/proto/topic_only_message.js +0 -46
  103. package/dist/proto/topic_only_message.js.map +0 -1
  104. package/src/lib/multiaddr_to_peer_info.ts +0 -17
  105. package/src/lib/select_connection.ts +0 -24
  106. package/src/lib/select_peer.ts +0 -77
  107. package/src/proto/filter.ts +0 -611
  108. package/src/proto/light_push.ts +0 -535
  109. package/src/proto/message.ts +0 -313
  110. package/src/proto/store.ts +0 -853
  111. package/src/proto/topic_only_message.ts +0 -67
@@ -1,46 +0,0 @@
1
- /* eslint-disable import/export */
2
- /* eslint-disable @typescript-eslint/no-namespace */
3
- import { encodeMessage, decodeMessage, message } from "protons-runtime";
4
- export var TopicOnlyMessage;
5
- (function (TopicOnlyMessage) {
6
- let _codec;
7
- TopicOnlyMessage.codec = () => {
8
- if (_codec == null) {
9
- _codec = message((obj, writer, opts = {}) => {
10
- if (opts.lengthDelimited !== false) {
11
- writer.fork();
12
- }
13
- if (obj.contentTopic != null) {
14
- writer.uint32(18);
15
- writer.string(obj.contentTopic);
16
- }
17
- if (opts.lengthDelimited !== false) {
18
- writer.ldelim();
19
- }
20
- }, (reader, length) => {
21
- const obj = {};
22
- const end = length == null ? reader.len : reader.pos + length;
23
- while (reader.pos < end) {
24
- const tag = reader.uint32();
25
- switch (tag >>> 3) {
26
- case 2:
27
- obj.contentTopic = reader.string();
28
- break;
29
- default:
30
- reader.skipType(tag & 7);
31
- break;
32
- }
33
- }
34
- return obj;
35
- });
36
- }
37
- return _codec;
38
- };
39
- TopicOnlyMessage.encode = (obj) => {
40
- return encodeMessage(obj, TopicOnlyMessage.codec());
41
- };
42
- TopicOnlyMessage.decode = (buf) => {
43
- return decodeMessage(buf, TopicOnlyMessage.codec());
44
- };
45
- })(TopicOnlyMessage || (TopicOnlyMessage = {}));
46
- //# sourceMappingURL=topic_only_message.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"topic_only_message.js","sourceRoot":"","sources":["../../src/proto/topic_only_message.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,oDAAoD;AAEpD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAQxE,MAAM,KAAW,gBAAgB,CAuDhC;AAvDD,WAA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AAc,EAAE;QAC1D,OAAO,aAAa,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC;IAEW,uBAAM,GAAG,CACpB,GAAgC,EACd,EAAE;QACpB,OAAO,aAAa,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC,EAvDgB,gBAAgB,KAAhB,gBAAgB,QAuDhC"}
@@ -1,17 +0,0 @@
1
- import { PeerInfo } from "@libp2p/interface-peer-info";
2
- import { peerIdFromString } from "@libp2p/peer-id";
3
- import { Multiaddr } from "@multiformats/multiaddr";
4
-
5
- export function multiaddrsToPeerInfo(mas: Multiaddr[]): PeerInfo[] {
6
- return mas
7
- .map((ma) => {
8
- const peerIdStr = ma.getPeerId();
9
- const protocols: string[] = [];
10
- return {
11
- id: peerIdStr ? peerIdFromString(peerIdStr) : null,
12
- multiaddrs: [ma.decapsulateCode(421)],
13
- protocols,
14
- };
15
- })
16
- .filter((peerInfo): peerInfo is PeerInfo => peerInfo.id !== null);
17
- }
@@ -1,24 +0,0 @@
1
- import { Connection } from "@libp2p/interface-connection";
2
-
3
- export function selectConnection(
4
- connections: Connection[]
5
- ): Connection | undefined {
6
- if (!connections.length) return;
7
- if (connections.length === 1) return connections[0];
8
-
9
- let latestConnection: Connection | undefined;
10
-
11
- connections.forEach((connection) => {
12
- if (connection.stat.status === "OPEN") {
13
- if (!latestConnection) {
14
- latestConnection = connection;
15
- } else if (
16
- connection.stat.timeline.open > latestConnection.stat.timeline.open
17
- ) {
18
- latestConnection = connection;
19
- }
20
- }
21
- });
22
-
23
- return latestConnection;
24
- }
@@ -1,77 +0,0 @@
1
- import type { PeerId } from "@libp2p/interface-peer-id";
2
- import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
3
- import debug from "debug";
4
-
5
- const log = debug("waku:select-peer");
6
-
7
- /**
8
- * Returns a pseudo-random peer that supports the given protocol.
9
- * Useful for protocols such as store and light push
10
- */
11
- export function selectRandomPeer(peers: Peer[]): Peer | undefined {
12
- if (peers.length === 0) return;
13
-
14
- const index = Math.round(Math.random() * (peers.length - 1));
15
- return peers[index];
16
- }
17
-
18
- /**
19
- * Returns the list of peers that supports the given protocol.
20
- */
21
- export async function getPeersForProtocol(
22
- peerStore: PeerStore,
23
- protocols: string[]
24
- ): Promise<Peer[]> {
25
- const peers: Peer[] = [];
26
- await peerStore.forEach((peer) => {
27
- for (let i = 0; i < protocols.length; i++) {
28
- if (peer.protocols.includes(protocols[i])) {
29
- peers.push(peer);
30
- break;
31
- }
32
- }
33
- });
34
- return peers;
35
- }
36
-
37
- export async function selectPeerForProtocol(
38
- peerStore: PeerStore,
39
- protocols: string[],
40
- peerId?: PeerId
41
- ): Promise<{ peer: Peer; protocol: string } | undefined> {
42
- let peer;
43
- if (peerId) {
44
- peer = await peerStore.get(peerId);
45
- if (!peer) {
46
- log(
47
- `Failed to retrieve connection details for provided peer in peer store: ${peerId.toString()}`
48
- );
49
- return;
50
- }
51
- } else {
52
- const peers = await getPeersForProtocol(peerStore, protocols);
53
- peer = selectRandomPeer(peers);
54
- if (!peer) {
55
- log("Failed to find known peer that registers protocols", protocols);
56
- return;
57
- }
58
- }
59
-
60
- let protocol;
61
- for (const codec of protocols) {
62
- if (peer.protocols.includes(codec)) {
63
- protocol = codec;
64
- // Do not break as we want to keep the last value
65
- }
66
- }
67
- log(`Using codec ${protocol}`);
68
- if (!protocol) {
69
- log(
70
- `Peer does not register required protocols: ${peer.id.toString()}`,
71
- protocols
72
- );
73
- return;
74
- }
75
-
76
- return { peer, protocol };
77
- }