@waku/core 0.0.17 → 0.0.19

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 (84) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/bundle/{browser-2f1afe46.js → browser-bde977a3.js} +12 -9
  3. package/bundle/index.js +911 -32802
  4. package/bundle/lib/base_protocol.js +4 -1
  5. package/bundle/lib/message/version_0.js +2 -3
  6. package/bundle/{peer_exchange-1229c8b0.js → version_0-9c941081.js} +569 -63
  7. package/dist/index.d.ts +5 -5
  8. package/dist/index.js +5 -5
  9. package/dist/index.js.map +1 -1
  10. package/dist/lib/base_protocol.js +3 -0
  11. package/dist/lib/base_protocol.js.map +1 -1
  12. package/dist/lib/connection_manager.d.ts +1 -0
  13. package/dist/lib/connection_manager.js +33 -25
  14. package/dist/lib/connection_manager.js.map +1 -1
  15. package/dist/lib/filter/{filter_rpc.d.ts → v1/filter_rpc.d.ts} +1 -3
  16. package/dist/lib/filter/{filter_rpc.js → v1/filter_rpc.js} +1 -0
  17. package/dist/lib/filter/v1/filter_rpc.js.map +1 -0
  18. package/dist/lib/filter/{index.d.ts → v1/index.d.ts} +0 -2
  19. package/dist/lib/filter/{index.js → v1/index.js} +7 -4
  20. package/dist/lib/filter/v1/index.js.map +1 -0
  21. package/dist/lib/filter/v2/filter_rpc.d.ts +40 -0
  22. package/dist/lib/filter/v2/filter_rpc.js +109 -0
  23. package/dist/lib/filter/v2/filter_rpc.js.map +1 -0
  24. package/dist/lib/filter/v2/index.d.ts +3 -0
  25. package/dist/lib/filter/v2/index.js +235 -0
  26. package/dist/lib/filter/v2/index.js.map +1 -0
  27. package/dist/lib/keep_alive_manager.d.ts +1 -0
  28. package/dist/lib/keep_alive_manager.js +5 -1
  29. package/dist/lib/keep_alive_manager.js.map +1 -1
  30. package/dist/lib/light_push/index.d.ts +1 -1
  31. package/dist/lib/light_push/index.js +27 -7
  32. package/dist/lib/light_push/index.js.map +1 -1
  33. package/dist/lib/light_push/push_rpc.js +1 -0
  34. package/dist/lib/light_push/push_rpc.js.map +1 -1
  35. package/dist/lib/message/index.d.ts +0 -1
  36. package/dist/lib/message/index.js +0 -1
  37. package/dist/lib/message/index.js.map +1 -1
  38. package/dist/lib/message/version_0.d.ts +1 -2
  39. package/dist/lib/message/version_0.js +6 -0
  40. package/dist/lib/message/version_0.js.map +1 -1
  41. package/dist/lib/store/history_rpc.js +1 -0
  42. package/dist/lib/store/history_rpc.js.map +1 -1
  43. package/dist/lib/store/index.js +2 -0
  44. package/dist/lib/store/index.js.map +1 -1
  45. package/dist/lib/waku.d.ts +5 -5
  46. package/dist/lib/waku.js +6 -0
  47. package/dist/lib/waku.js.map +1 -1
  48. package/package.json +9 -13
  49. package/src/index.ts +6 -11
  50. package/src/lib/connection_manager.ts +13 -4
  51. package/src/lib/filter/{filter_rpc.ts → v1/filter_rpc.ts} +1 -4
  52. package/src/lib/filter/{index.ts → v1/index.ts} +6 -7
  53. package/src/lib/filter/v2/filter_rpc.ts +131 -0
  54. package/src/lib/filter/v2/index.ts +413 -0
  55. package/src/lib/keep_alive_manager.ts +1 -2
  56. package/src/lib/light_push/index.ts +26 -9
  57. package/src/lib/message/index.ts +0 -1
  58. package/src/lib/message/version_0.ts +1 -1
  59. package/src/lib/waku.ts +5 -7
  60. package/bundle/lib/message/topic_only_message.js +0 -3
  61. package/bundle/topic_only_message-e8406994.js +0 -43
  62. package/bundle/version_0-5a4becbc.js +0 -149
  63. package/dist/lib/filter/filter_rpc.js.map +0 -1
  64. package/dist/lib/filter/index.js.map +0 -1
  65. package/dist/lib/group_by.d.ts +0 -3
  66. package/dist/lib/group_by.js +0 -13
  67. package/dist/lib/group_by.js.map +0 -1
  68. package/dist/lib/message/topic_only_message.d.ts +0 -18
  69. package/dist/lib/message/topic_only_message.js +0 -35
  70. package/dist/lib/message/topic_only_message.js.map +0 -1
  71. package/dist/lib/relay/constants.d.ts +0 -63
  72. package/dist/lib/relay/constants.js +0 -64
  73. package/dist/lib/relay/constants.js.map +0 -1
  74. package/dist/lib/relay/index.d.ts +0 -11
  75. package/dist/lib/relay/index.js +0 -181
  76. package/dist/lib/relay/index.js.map +0 -1
  77. package/dist/lib/relay/message_validator.d.ts +0 -4
  78. package/dist/lib/relay/message_validator.js +0 -25
  79. package/dist/lib/relay/message_validator.js.map +0 -1
  80. package/src/lib/group_by.ts +0 -14
  81. package/src/lib/message/topic_only_message.ts +0 -51
  82. package/src/lib/relay/constants.ts +0 -74
  83. package/src/lib/relay/index.ts +0 -294
  84. package/src/lib/relay/message_validator.ts +0 -35
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waku/core",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "TypeScript implementation of the Waku v2 protocol",
5
5
  "types": "./dist/index.d.ts",
6
6
  "module": "./dist/index.js",
@@ -17,10 +17,6 @@
17
17
  "types": "./dist/lib/message/version_0.d.ts",
18
18
  "import": "./dist/lib/message/version_0.js"
19
19
  },
20
- "./lib/message/topic_only_message": {
21
- "types": "./dist/lib/message/topic_only_message.d.ts",
22
- "import": "./dist/lib/message/topic_only_message.js"
23
- },
24
20
  "./lib/base_protocol": {
25
21
  "types": "./dist/lib/base_protocol.d.ts",
26
22
  "import": "./dist/lib/base_protocol.js"
@@ -30,6 +26,9 @@
30
26
  "*": {
31
27
  "lib/*": [
32
28
  "dist/lib/*"
29
+ ],
30
+ "constants/*": [
31
+ "dist/constants/*"
33
32
  ]
34
33
  }
35
34
  },
@@ -57,7 +56,6 @@
57
56
  "build:bundle": "rollup --config rollup.config.js",
58
57
  "fix": "run-s fix:*",
59
58
  "fix:lint": "eslint src *.js --fix",
60
- "pretest": "run-s pretest:*",
61
59
  "check": "run-s check:*",
62
60
  "check:tsc": "tsc -p tsconfig.dev.json",
63
61
  "check:lint": "eslint src *.js",
@@ -74,12 +72,10 @@
74
72
  "node": ">=16"
75
73
  },
76
74
  "dependencies": {
77
- "@chainsafe/libp2p-gossipsub": "^6.1.0",
78
- "@libp2p/interface-pubsub": "^3.0.7",
79
75
  "@noble/hashes": "^1.3.0",
80
- "@waku/interfaces": "0.0.12",
81
- "@waku/proto": "0.0.4",
82
- "@waku/utils": "0.0.5",
76
+ "@waku/interfaces": "0.0.14",
77
+ "@waku/proto": "0.0.5",
78
+ "@waku/utils": "0.0.7",
83
79
  "debug": "^4.3.4",
84
80
  "it-all": "^3.0.1",
85
81
  "it-length-prefixed": "^9.0.1",
@@ -124,11 +120,11 @@
124
120
  "npm-run-all": "^4.1.5",
125
121
  "prettier": "^2.8.8",
126
122
  "process": "^0.11.10",
127
- "puppeteer": "^19.8.2",
123
+ "puppeteer": "^20.4.0",
128
124
  "rollup": "^3.21.3",
129
125
  "ts-loader": "^9.4.2",
130
126
  "ts-node": "^10.9.1",
131
- "typescript": "^4.9.5"
127
+ "typescript": "^5.0.4"
132
128
  },
133
129
  "peerDependencies": {
134
130
  "@multiformats/multiaddr": "^12.0.0",
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
- export { DefaultPubSubTopic } from "./lib/constants.js";
2
1
  export { DefaultUserAgent } from "./lib/waku.js";
3
-
2
+ export { DefaultPubSubTopic } from "./lib/constants.js";
4
3
  export { createEncoder, createDecoder } from "./lib/message/version_0.js";
5
4
  export type {
6
5
  Encoder,
@@ -12,19 +11,15 @@ export * as message from "./lib/message/index.js";
12
11
  export * as waku from "./lib/waku.js";
13
12
  export { WakuNode, WakuOptions } from "./lib/waku.js";
14
13
 
15
- export * as waku_filter from "./lib/filter/index.js";
16
- export { wakuFilter } from "./lib/filter/index.js";
14
+ export * as waku_filter_v1 from "./lib/filter/v1/index.js";
15
+ export { wakuFilter as wakuFilterV1 } from "./lib/filter/v1/index.js";
16
+
17
+ export * as waku_filter_v2 from "./lib/filter/v2/index.js";
18
+ export { wakuFilterV2 } from "./lib/filter/v2/index.js";
17
19
 
18
20
  export * as waku_light_push from "./lib/light_push/index.js";
19
21
  export { wakuLightPush, LightPushCodec } from "./lib/light_push/index.js";
20
22
 
21
- export * as waku_relay from "./lib/relay/index.js";
22
- export {
23
- wakuRelay,
24
- RelayCreateOptions,
25
- wakuGossipSub,
26
- } from "./lib/relay/index.js";
27
-
28
23
  export * as waku_store from "./lib/store/index.js";
29
24
  export {
30
25
  PageDirection,
@@ -19,6 +19,7 @@ export class ConnectionManager {
19
19
  private options: ConnectionManagerOptions;
20
20
  private libp2pComponents: Libp2p;
21
21
  private dialAttemptsForPeer: Map<string, number> = new Map();
22
+ private dialErrorsForPeer: Map<string, any> = new Map();
22
23
 
23
24
  public static create(
24
25
  peerId: string,
@@ -102,9 +103,11 @@ export class ConnectionManager {
102
103
 
103
104
  this.dialAttemptsForPeer.delete(peerId.toString());
104
105
  return;
105
- } catch (error) {
106
- log(`
107
- Error dialing peer ${peerId.toString()}`);
106
+ } catch (e) {
107
+ const error = e as AggregateError;
108
+ this.dialErrorsForPeer.set(peerId.toString(), error);
109
+ log(`Error dialing peer ${peerId.toString()} - ${error.errors}`);
110
+
108
111
  dialAttempt = this.dialAttemptsForPeer.get(peerId.toString()) ?? 1;
109
112
  this.dialAttemptsForPeer.set(peerId.toString(), dialAttempt + 1);
110
113
 
@@ -115,7 +118,13 @@ export class ConnectionManager {
115
118
  }
116
119
 
117
120
  try {
118
- log(`Deleting undialable peer ${peerId.toString()} from peer store`);
121
+ log(
122
+ `Deleting undialable peer ${peerId.toString()} from peer store. Error: ${JSON.stringify(
123
+ this.dialErrorsForPeer.get(peerId.toString()).errors[0]
124
+ )}
125
+ }`
126
+ );
127
+ this.dialErrorsForPeer.delete(peerId.toString());
119
128
  return await this.libp2pComponents.peerStore.delete(peerId);
120
129
  } catch (error) {
121
130
  throw `Error deleting undialable peer ${peerId.toString()} from peer store - ${error}`;
@@ -1,10 +1,7 @@
1
+ import { ContentFilter } from "@waku/interfaces";
1
2
  import { proto_filter as proto } from "@waku/proto";
2
3
  import { v4 as uuid } from "uuid";
3
4
 
4
- export type ContentFilter = {
5
- contentTopic: string;
6
- };
7
-
8
5
  /**
9
6
  * FilterRPC represents a message conforming to the Waku Filter protocol
10
7
  */
@@ -4,6 +4,7 @@ import type { IncomingStreamData } from "@libp2p/interface-registrar";
4
4
  import type {
5
5
  ActiveSubscriptions,
6
6
  Callback,
7
+ ContentFilter,
7
8
  IAsyncIterator,
8
9
  IDecodedMessage,
9
10
  IDecoder,
@@ -12,20 +13,18 @@ import type {
12
13
  ProtocolOptions,
13
14
  } from "@waku/interfaces";
14
15
  import { WakuMessage as WakuMessageProto } from "@waku/proto";
16
+ import { groupByContentTopic } from "@waku/utils";
15
17
  import { toAsyncIterator } from "@waku/utils";
16
18
  import debug from "debug";
17
19
  import all from "it-all";
18
20
  import * as lp from "it-length-prefixed";
19
21
  import { pipe } from "it-pipe";
20
22
 
21
- import { BaseProtocol } from "../base_protocol.js";
22
- import { DefaultPubSubTopic } from "../constants.js";
23
- import { groupByContentTopic } from "../group_by.js";
24
- import { toProtoMessage } from "../to_proto_message.js";
23
+ import { BaseProtocol } from "../../base_protocol.js";
24
+ import { DefaultPubSubTopic } from "../../constants.js";
25
+ import { toProtoMessage } from "../../to_proto_message.js";
25
26
 
26
- import { ContentFilter, FilterRpc } from "./filter_rpc.js";
27
-
28
- export { ContentFilter };
27
+ import { FilterRpc } from "./filter_rpc.js";
29
28
 
30
29
  export const FilterCodec = "/vac/waku/filter/2.0.0-beta1";
31
30
 
@@ -0,0 +1,131 @@
1
+ import { proto_filter_v2 as proto, WakuMessage } from "@waku/proto";
2
+ import { v4 as uuid } from "uuid";
3
+
4
+ /**
5
+ * FilterPushRPC represents a message conforming to the Waku FilterPush protocol.
6
+ * Protocol documentation: https://rfc.vac.dev/spec/12/
7
+ */
8
+ export class FilterPushRpc {
9
+ public constructor(public proto: proto.MessagePush) {}
10
+
11
+ static decode(bytes: Uint8Array): FilterPushRpc {
12
+ const res = proto.MessagePush.decode(bytes);
13
+ return new FilterPushRpc(res);
14
+ }
15
+
16
+ encode(): Uint8Array {
17
+ return proto.MessagePush.encode(this.proto);
18
+ }
19
+
20
+ get wakuMessage(): WakuMessage | undefined {
21
+ return this.proto.wakuMessage;
22
+ }
23
+
24
+ /**
25
+ * Get the pubsub topic from the FilterPushRpc object.
26
+ * @returns string
27
+ */
28
+ get pubsubTopic(): string | undefined {
29
+ return this.proto.pubsubTopic;
30
+ }
31
+ }
32
+
33
+ export class FilterSubscribeRpc {
34
+ public constructor(public proto: proto.FilterSubscribeRequest) {}
35
+
36
+ static createSubscribeRequest(
37
+ pubsubTopic: string,
38
+ contentTopics: string[]
39
+ ): FilterSubscribeRpc {
40
+ return new FilterSubscribeRpc({
41
+ requestId: uuid(),
42
+ filterSubscribeType:
43
+ proto.FilterSubscribeRequest.FilterSubscribeType.SUBSCRIBE,
44
+ pubsubTopic,
45
+ contentTopics,
46
+ });
47
+ }
48
+
49
+ static createUnsubscribeRequest(
50
+ pubsubTopic: string,
51
+ contentTopics: string[]
52
+ ): FilterSubscribeRpc {
53
+ return new FilterSubscribeRpc({
54
+ requestId: uuid(),
55
+ filterSubscribeType:
56
+ proto.FilterSubscribeRequest.FilterSubscribeType.UNSUBSCRIBE,
57
+ pubsubTopic,
58
+ contentTopics,
59
+ });
60
+ }
61
+
62
+ static createUnsubscribeAllRequest(pubsubTopic: string): FilterSubscribeRpc {
63
+ return new FilterSubscribeRpc({
64
+ requestId: uuid(),
65
+ filterSubscribeType:
66
+ proto.FilterSubscribeRequest.FilterSubscribeType.UNSUBSCRIBE_ALL,
67
+ pubsubTopic,
68
+ contentTopics: [],
69
+ });
70
+ }
71
+
72
+ static createSubscriberPingRequest(): FilterSubscribeRpc {
73
+ return new FilterSubscribeRpc({
74
+ requestId: uuid(),
75
+ filterSubscribeType:
76
+ proto.FilterSubscribeRequest.FilterSubscribeType.SUBSCRIBER_PING,
77
+ pubsubTopic: "",
78
+ contentTopics: [],
79
+ });
80
+ }
81
+
82
+ static decode(bytes: Uint8Array): FilterSubscribeRpc {
83
+ const res = proto.FilterSubscribeRequest.decode(bytes);
84
+ return new FilterSubscribeRpc(res);
85
+ }
86
+
87
+ encode(): Uint8Array {
88
+ return proto.FilterSubscribeRequest.encode(this.proto);
89
+ }
90
+
91
+ get filterSubscribeType(): proto.FilterSubscribeRequest.FilterSubscribeType {
92
+ return this.proto.filterSubscribeType;
93
+ }
94
+
95
+ get requestId(): string {
96
+ return this.proto.requestId;
97
+ }
98
+
99
+ get pubsubTopic(): string | undefined {
100
+ return this.proto.pubsubTopic;
101
+ }
102
+
103
+ get contentTopics(): string[] {
104
+ return this.proto.contentTopics;
105
+ }
106
+ }
107
+
108
+ export class FilterSubscribeResponse {
109
+ public constructor(public proto: proto.FilterSubscribeResponse) {}
110
+
111
+ static decode(bytes: Uint8Array): FilterSubscribeResponse {
112
+ const res = proto.FilterSubscribeResponse.decode(bytes);
113
+ return new FilterSubscribeResponse(res);
114
+ }
115
+
116
+ encode(): Uint8Array {
117
+ return proto.FilterSubscribeResponse.encode(this.proto);
118
+ }
119
+
120
+ get statusCode(): number {
121
+ return this.proto.statusCode;
122
+ }
123
+
124
+ get statusDesc(): string | undefined {
125
+ return this.proto.statusDesc;
126
+ }
127
+
128
+ get requestId(): string {
129
+ return this.proto.requestId;
130
+ }
131
+ }