@waku/core 0.0.27 → 0.0.28-b5e8b17.0
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/bundle/{base_protocol-LhsIWF3-.js → base_protocol-BCwLeb-A.js} +2 -5
- package/bundle/{browser-BQyFvtq6.js → browser-DoQRY-an.js} +18 -13
- package/bundle/{index-8YyfzF9R.js → index-vlQahmUj.js} +3 -1
- package/bundle/index.js +153 -98
- package/bundle/lib/base_protocol.js +3 -3
- package/bundle/lib/message/version_0.js +3 -3
- package/bundle/lib/predefined_bootstrap_nodes.js +1 -1
- package/bundle/{version_0-FXfzO8Km.js → version_0-DiakMc1A.js} +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/base_protocol.d.ts +4 -5
- package/dist/lib/base_protocol.js +0 -3
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/filter/index.js +4 -0
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +12 -2
- package/dist/lib/light_push/index.js +79 -76
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +1 -1
- package/dist/lib/metadata/index.js +42 -14
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js +3 -1
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/package.json +1 -129
- package/src/index.ts +1 -1
- package/src/lib/base_protocol.ts +4 -9
- package/src/lib/filter/index.ts +7 -0
- package/src/lib/light_push/index.ts +97 -118
- package/src/lib/metadata/index.ts +56 -26
- package/src/lib/wait_for_remote_peer.ts +13 -3
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { ProtocolError } from "@waku/interfaces";
|
2
2
|
import { PushResponse } from "@waku/proto";
|
3
|
-
import {
|
3
|
+
import { isMessageSizeUnderCap } from "@waku/utils";
|
4
4
|
import { Logger } from "@waku/utils";
|
5
5
|
import all from "it-all";
|
6
6
|
import * as lp from "it-length-prefixed";
|
@@ -14,114 +14,117 @@ export { PushResponse };
|
|
14
14
|
/**
|
15
15
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
16
16
|
*/
|
17
|
-
class
|
17
|
+
export class LightPushCore extends BaseProtocol {
|
18
18
|
constructor(libp2p, options) {
|
19
19
|
super(LightPushCodec, libp2p.components, log, options.pubsubTopics, options);
|
20
20
|
}
|
21
|
-
async preparePushMessage(encoder, message
|
21
|
+
async preparePushMessage(encoder, message) {
|
22
22
|
try {
|
23
23
|
if (!message.payload || message.payload.length === 0) {
|
24
24
|
log.error("Failed to send waku light push: payload is empty");
|
25
|
-
return { query: null, error:
|
25
|
+
return { query: null, error: ProtocolError.EMPTY_PAYLOAD };
|
26
26
|
}
|
27
27
|
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
28
28
|
log.error("Failed to send waku light push: message is bigger than 1MB");
|
29
|
-
return { query: null, error:
|
29
|
+
return { query: null, error: ProtocolError.SIZE_TOO_BIG };
|
30
30
|
}
|
31
31
|
const protoMessage = await encoder.toProtoObj(message);
|
32
32
|
if (!protoMessage) {
|
33
33
|
log.error("Failed to encode to protoMessage, aborting push");
|
34
34
|
return {
|
35
35
|
query: null,
|
36
|
-
error:
|
36
|
+
error: ProtocolError.ENCODE_FAILED
|
37
37
|
};
|
38
38
|
}
|
39
|
-
const query = PushRpc.createRequest(protoMessage, pubsubTopic);
|
39
|
+
const query = PushRpc.createRequest(protoMessage, encoder.pubsubTopic);
|
40
40
|
return { query, error: null };
|
41
41
|
}
|
42
42
|
catch (error) {
|
43
43
|
log.error("Failed to prepare push message", error);
|
44
44
|
return {
|
45
45
|
query: null,
|
46
|
-
error:
|
46
|
+
error: ProtocolError.GENERIC_FAIL
|
47
47
|
};
|
48
48
|
}
|
49
49
|
}
|
50
|
-
async send(encoder, message) {
|
51
|
-
const {
|
52
|
-
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
|
53
|
-
const recipients = [];
|
54
|
-
const { query, error: preparationError } = await this.preparePushMessage(encoder, message, pubsubTopic);
|
50
|
+
async send(encoder, message, peer) {
|
51
|
+
const { query, error: preparationError } = await this.preparePushMessage(encoder, message);
|
55
52
|
if (preparationError || !query) {
|
56
53
|
return {
|
57
|
-
|
58
|
-
|
54
|
+
success: null,
|
55
|
+
failure: {
|
56
|
+
error: preparationError,
|
57
|
+
peerId: peer.id
|
58
|
+
}
|
59
59
|
};
|
60
60
|
}
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
}
|
65
|
-
|
61
|
+
let stream;
|
62
|
+
try {
|
63
|
+
stream = await this.getStream(peer);
|
64
|
+
}
|
65
|
+
catch (err) {
|
66
|
+
log.error(`Failed to get a stream for remote peer${peer.id.toString()}`, err);
|
66
67
|
return {
|
67
|
-
|
68
|
-
|
68
|
+
success: null,
|
69
|
+
failure: {
|
70
|
+
error: ProtocolError.REMOTE_PEER_FAULT,
|
71
|
+
peerId: peer.id
|
72
|
+
}
|
69
73
|
};
|
70
74
|
}
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
const bytes = new Uint8ArrayList();
|
89
|
-
res.forEach((chunk) => {
|
90
|
-
bytes.append(chunk);
|
91
|
-
});
|
92
|
-
let response;
|
93
|
-
try {
|
94
|
-
response = PushRpc.decode(bytes).response;
|
95
|
-
}
|
96
|
-
catch (err) {
|
97
|
-
log.error("Failed to decode push reply", err);
|
98
|
-
return { recipients, error: SendError.DECODE_FAILED };
|
99
|
-
}
|
100
|
-
if (!response) {
|
101
|
-
log.error("Remote peer fault: No response in PushRPC");
|
102
|
-
return { recipients, error: SendError.REMOTE_PEER_FAULT };
|
103
|
-
}
|
104
|
-
if (!response.isSuccess) {
|
105
|
-
log.error("Remote peer rejected the message: ", response.info);
|
106
|
-
return { recipients, error: SendError.REMOTE_PEER_REJECTED };
|
107
|
-
}
|
108
|
-
recipients.some((recipient) => recipient.equals(peer.id)) ||
|
109
|
-
recipients.push(peer.id);
|
110
|
-
return { recipients };
|
75
|
+
let res;
|
76
|
+
try {
|
77
|
+
res = await pipe([query.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
78
|
+
}
|
79
|
+
catch (err) {
|
80
|
+
log.error("Failed to send waku light push request", err);
|
81
|
+
return {
|
82
|
+
success: null,
|
83
|
+
failure: {
|
84
|
+
error: ProtocolError.GENERIC_FAIL,
|
85
|
+
peerId: peer.id
|
86
|
+
}
|
87
|
+
};
|
88
|
+
}
|
89
|
+
const bytes = new Uint8ArrayList();
|
90
|
+
res.forEach((chunk) => {
|
91
|
+
bytes.append(chunk);
|
111
92
|
});
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
.
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
93
|
+
let response;
|
94
|
+
try {
|
95
|
+
response = PushRpc.decode(bytes).response;
|
96
|
+
}
|
97
|
+
catch (err) {
|
98
|
+
log.error("Failed to decode push reply", err);
|
99
|
+
return {
|
100
|
+
success: null,
|
101
|
+
failure: {
|
102
|
+
error: ProtocolError.DECODE_FAILED,
|
103
|
+
peerId: peer.id
|
104
|
+
}
|
105
|
+
};
|
106
|
+
}
|
107
|
+
if (!response) {
|
108
|
+
log.error("Remote peer fault: No response in PushRPC");
|
109
|
+
return {
|
110
|
+
success: null,
|
111
|
+
failure: {
|
112
|
+
error: ProtocolError.REMOTE_PEER_FAULT,
|
113
|
+
peerId: peer.id
|
114
|
+
}
|
115
|
+
};
|
116
|
+
}
|
117
|
+
if (!response.isSuccess) {
|
118
|
+
log.error("Remote peer rejected the message: ", response.info);
|
119
|
+
return {
|
120
|
+
success: null,
|
121
|
+
failure: {
|
122
|
+
error: ProtocolError.REMOTE_PEER_REJECTED,
|
123
|
+
peerId: peer.id
|
124
|
+
}
|
125
|
+
};
|
126
|
+
}
|
127
|
+
return { success: peer.id, failure: null };
|
122
128
|
}
|
123
129
|
}
|
124
|
-
export function wakuLightPush(init = {}) {
|
125
|
-
return (libp2p) => new LightPush(libp2p, init);
|
126
|
-
}
|
127
130
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/light_push/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/light_push/index.ts"],"names":[],"mappings":"AACA,OAAO,EAOL,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,cAAc,GAAG,iCAAiC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,CAAC;AAMxB;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAY;IAC7C,YAAY,MAAc,EAAE,OAA+B;QACzD,KAAK,CACH,cAAc,EACd,MAAM,CAAC,UAAU,EACjB,GAAG,EACH,OAAQ,CAAC,YAAa,EACtB,OAAO,CACR,CAAC;IACJ,C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@@
|
|
1
|
-
import type
|
1
|
+
import { type IMetadata, type Libp2pComponents, type ShardInfo } from "@waku/interfaces";
|
2
2
|
export declare const MetadataCodec = "/vac/waku/metadata/1.0.0";
|
3
3
|
export declare function wakuMetadata(shardInfo: ShardInfo): (components: Libp2pComponents) => IMetadata;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { ProtocolError } from "@waku/interfaces";
|
1
2
|
import { proto_metadata } from "@waku/proto";
|
2
3
|
import { encodeRelayShard, Logger, shardInfoToPubsubTopics } from "@waku/utils";
|
3
4
|
import all from "it-all";
|
@@ -10,7 +11,7 @@ export const MetadataCodec = "/vac/waku/metadata/1.0.0";
|
|
10
11
|
class Metadata extends BaseProtocol {
|
11
12
|
shardInfo;
|
12
13
|
libp2pComponents;
|
13
|
-
handshakesConfirmed = new
|
14
|
+
handshakesConfirmed = new Map();
|
14
15
|
constructor(shardInfo, libp2p) {
|
15
16
|
super(MetadataCodec, libp2p.components, log, shardInfoToPubsubTopics(shardInfo));
|
16
17
|
this.shardInfo = shardInfo;
|
@@ -27,8 +28,11 @@ class Metadata extends BaseProtocol {
|
|
27
28
|
const { stream, connection } = streamData;
|
28
29
|
const encodedShardInfo = proto_metadata.WakuMetadataResponse.encode(this.shardInfo);
|
29
30
|
const encodedResponse = await pipe([encodedShardInfo], lp.encode, stream, lp.decode, async (source) => await all(source));
|
30
|
-
const
|
31
|
-
|
31
|
+
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
32
|
+
if (error) {
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
await this.savePeerShardInfo(connection.remotePeer, shardInfo);
|
32
36
|
}
|
33
37
|
catch (error) {
|
34
38
|
log.error("Error handling metadata request", error);
|
@@ -41,19 +45,35 @@ class Metadata extends BaseProtocol {
|
|
41
45
|
const request = proto_metadata.WakuMetadataRequest.encode(this.shardInfo);
|
42
46
|
const peer = await this.peerStore.get(peerId);
|
43
47
|
if (!peer) {
|
44
|
-
|
48
|
+
return {
|
49
|
+
shardInfo: null,
|
50
|
+
error: ProtocolError.NO_PEER_AVAILABLE
|
51
|
+
};
|
45
52
|
}
|
46
53
|
const stream = await this.getStream(peer);
|
47
54
|
const encodedResponse = await pipe([request], lp.encode, stream, lp.decode, async (source) => await all(source));
|
48
|
-
const
|
49
|
-
|
50
|
-
|
55
|
+
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
56
|
+
if (error) {
|
57
|
+
return {
|
58
|
+
shardInfo: null,
|
59
|
+
error
|
60
|
+
};
|
61
|
+
}
|
62
|
+
await this.savePeerShardInfo(peerId, shardInfo);
|
63
|
+
return {
|
64
|
+
shardInfo,
|
65
|
+
error: null
|
66
|
+
};
|
51
67
|
}
|
52
68
|
async confirmOrAttemptHandshake(peerId) {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
69
|
+
const shardInfo = this.handshakesConfirmed.get(peerId.toString());
|
70
|
+
if (shardInfo) {
|
71
|
+
return {
|
72
|
+
shardInfo,
|
73
|
+
error: null
|
74
|
+
};
|
75
|
+
}
|
76
|
+
return await this.query(peerId);
|
57
77
|
}
|
58
78
|
decodeMetadataResponse(encodedResponse) {
|
59
79
|
const bytes = new Uint8ArrayList();
|
@@ -61,9 +81,17 @@ class Metadata extends BaseProtocol {
|
|
61
81
|
bytes.append(chunk);
|
62
82
|
});
|
63
83
|
const response = proto_metadata.WakuMetadataResponse.decode(bytes);
|
64
|
-
if (!response)
|
84
|
+
if (!response) {
|
65
85
|
log.error("Error decoding metadata response");
|
66
|
-
|
86
|
+
return {
|
87
|
+
shardInfo: null,
|
88
|
+
error: ProtocolError.DECODE_FAILED
|
89
|
+
};
|
90
|
+
}
|
91
|
+
return {
|
92
|
+
shardInfo: response,
|
93
|
+
error: null
|
94
|
+
};
|
67
95
|
}
|
68
96
|
async savePeerShardInfo(peerId, shardInfo) {
|
69
97
|
// add or update the shardInfo to peer store
|
@@ -72,7 +100,7 @@ class Metadata extends BaseProtocol {
|
|
72
100
|
shardInfo: encodeRelayShard(shardInfo)
|
73
101
|
}
|
74
102
|
});
|
75
|
-
this.handshakesConfirmed.
|
103
|
+
this.handshakesConfirmed.set(peerId.toString(), shardInfo);
|
76
104
|
}
|
77
105
|
}
|
78
106
|
export function wakuMetadata(shardInfo) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/metadata/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/metadata/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,aAAa,EAGd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAExD,MAAM,QAAS,SAAQ,YAAY;IAKxB;IAJD,gBAAgB,CAAmB;IAC3C,mBAAmB,GAA8B,IAAI,GAAG,EAAE,CAAC;IAE3D,YACS,SAAoB,EAC3B,MAAwB;QAExB,KAAK,CACH,aAAa,EACb,MAAM,CAAC,UAAU,EACjB,GAAG,EACH,uBAAuB,CAAC,SAAS,CAAC,CACnC,CAAC;QARK,cAAS,GAAT,SAAS,CAAW;QAS3B,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC;QAC/B,KAAK,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,aA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IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,GAAG,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;YAC9C,OAAO;gBACL,SAAS,EAAE,IAAI;gBACf,KAAK,EAAE,aAAa,CAAC,aAAa;aACnC,CAAC;QACJ,CAAC;QAED,OAAO;YACL,SAAS,EAAE,QAAQ;YACnB,KAAK,EAAE,IAAI;SACZ,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAC7B,MAAc,EACd,SAAoB;QAEpB,4CAA4C;QAC5C,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE;YAClD,QAAQ,EAAE;gBACR,SAAS,EAAE,gBAAgB,CAAC,SAAS,CAAC;aACvC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,CAAC,CAAC;IAC7D,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAC1B,SAAoB;IAEpB,OAAO,CAAC,UAA4B,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AAC/E,CAAC"}
|
@@ -2,6 +2,7 @@ import { Protocols } from "@waku/interfaces";
|
|
2
2
|
import { Logger } from "@waku/utils";
|
3
3
|
import { pEvent } from "p-event";
|
4
4
|
const log = new Logger("wait-for-remote-peer");
|
5
|
+
//TODO: move this function within the Waku class: https://github.com/waku-org/js-waku/issues/1761
|
5
6
|
/**
|
6
7
|
* Wait for a remote peer to be ready given the passed protocols.
|
7
8
|
* Must be used after attempting to connect to nodes, using
|
@@ -39,7 +40,7 @@ export async function waitForRemotePeer(waku, protocols, timeoutMs) {
|
|
39
40
|
if (protocols.includes(Protocols.LightPush)) {
|
40
41
|
if (!waku.lightPush)
|
41
42
|
throw new Error("Cannot wait for LightPush peer: protocol not mounted");
|
42
|
-
promises.push(waitForConnectedPeer(waku.lightPush, waku.libp2p.services.metadata));
|
43
|
+
promises.push(waitForConnectedPeer(waku.lightPush.protocol, waku.libp2p.services.metadata));
|
43
44
|
}
|
44
45
|
if (protocols.includes(Protocols.Filter)) {
|
45
46
|
if (!waku.filter)
|
@@ -53,6 +54,7 @@ export async function waitForRemotePeer(waku, protocols, timeoutMs) {
|
|
53
54
|
await Promise.all(promises);
|
54
55
|
}
|
55
56
|
}
|
57
|
+
//TODO: move this function within protocol SDK class: https://github.com/waku-org/js-waku/issues/1761
|
56
58
|
/**
|
57
59
|
* Wait for a peer with the given protocol to be connected.
|
58
60
|
* If sharding is enabled on the node, it will also wait for the peer to be confirmed by the metadata service.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"wait_for_remote_peer.js","sourceRoot":"","sources":["../../src/lib/wait_for_remote_peer.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"wait_for_remote_peer.js","sourceRoot":"","sources":["../../src/lib/wait_for_remote_peer.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAE/C,iGAAiG;AACjG;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAU,EACV,SAAuB,EACvB,SAAkB;IAElB,SAAS,GAAG,SAAS,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAEnD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAAE,OAAO,OAAO,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC;IAEzE,MAAM,QAAQ,GAAG,EAAE,CAAC;IAEpB,IAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,IAAI,C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M,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAEhF,KAAK,UAAU,eAAe,CAC5B,OAAmB,EACnB,SAAiB,EACjB,YAAoB;IAEpB,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAU;IACrC,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
@@ -1,129 +1 @@
|
|
1
|
-
{
|
2
|
-
"name": "@waku/core",
|
3
|
-
"version": "0.0.27",
|
4
|
-
"description": "TypeScript implementation of the Waku v2 protocol",
|
5
|
-
"types": "./dist/index.d.ts",
|
6
|
-
"module": "./dist/index.js",
|
7
|
-
"exports": {
|
8
|
-
".": {
|
9
|
-
"types": "./dist/index.d.ts",
|
10
|
-
"import": "./dist/index.js"
|
11
|
-
},
|
12
|
-
"./lib/predefined_bootstrap_nodes": {
|
13
|
-
"types": "./dist/lib/predefined_bootstrap_nodes.d.ts",
|
14
|
-
"import": "./dist/lib/predefined_bootstrap_nodes.js"
|
15
|
-
},
|
16
|
-
"./lib/message/version_0": {
|
17
|
-
"types": "./dist/lib/message/version_0.d.ts",
|
18
|
-
"import": "./dist/lib/message/version_0.js"
|
19
|
-
},
|
20
|
-
"./lib/base_protocol": {
|
21
|
-
"types": "./dist/lib/base_protocol.d.ts",
|
22
|
-
"import": "./dist/lib/base_protocol.js"
|
23
|
-
}
|
24
|
-
},
|
25
|
-
"typesVersions": {
|
26
|
-
"*": {
|
27
|
-
"lib/*": [
|
28
|
-
"dist/lib/*"
|
29
|
-
],
|
30
|
-
"constants/*": [
|
31
|
-
"dist/constants/*"
|
32
|
-
]
|
33
|
-
}
|
34
|
-
},
|
35
|
-
"type": "module",
|
36
|
-
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/core#readme",
|
37
|
-
"repository": {
|
38
|
-
"type": "git",
|
39
|
-
"url": "https://github.com/waku-org/js-waku.git"
|
40
|
-
},
|
41
|
-
"bugs": {
|
42
|
-
"url": "https://github.com/waku-org/js-waku/issues"
|
43
|
-
},
|
44
|
-
"license": "MIT OR Apache-2.0",
|
45
|
-
"keywords": [
|
46
|
-
"waku",
|
47
|
-
"decentralised",
|
48
|
-
"communication",
|
49
|
-
"web3",
|
50
|
-
"ethereum",
|
51
|
-
"dapps"
|
52
|
-
],
|
53
|
-
"scripts": {
|
54
|
-
"build": "run-s build:**",
|
55
|
-
"build:esm": "tsc",
|
56
|
-
"build:bundle": "rollup --config rollup.config.js",
|
57
|
-
"fix": "run-s fix:*",
|
58
|
-
"fix:lint": "eslint src *.js --fix",
|
59
|
-
"check": "run-s check:*",
|
60
|
-
"check:tsc": "tsc -p tsconfig.dev.json",
|
61
|
-
"check:lint": "eslint src *.js",
|
62
|
-
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
63
|
-
"test": "NODE_ENV=test run-s test:*",
|
64
|
-
"test:node": "NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
65
|
-
"test:browser": "NODE_ENV=test karma start karma.conf.cjs",
|
66
|
-
"watch:build": "tsc -p tsconfig.json -w",
|
67
|
-
"watch:test": "mocha --watch",
|
68
|
-
"prepublish": "npm run build",
|
69
|
-
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
70
|
-
},
|
71
|
-
"engines": {
|
72
|
-
"node": ">=18"
|
73
|
-
},
|
74
|
-
"dependencies": {
|
75
|
-
"@libp2p/ping": "^1.0.11",
|
76
|
-
"@noble/hashes": "^1.3.2",
|
77
|
-
"@waku/enr": "^0.0.21",
|
78
|
-
"@waku/interfaces": "0.0.22",
|
79
|
-
"@waku/message-hash": "^0.1.11",
|
80
|
-
"@waku/proto": "0.0.6",
|
81
|
-
"@waku/utils": "0.0.15",
|
82
|
-
"debug": "^4.3.4",
|
83
|
-
"it-all": "^3.0.4",
|
84
|
-
"it-length-prefixed": "^9.0.4",
|
85
|
-
"it-pipe": "^3.0.1",
|
86
|
-
"p-event": "^6.0.0",
|
87
|
-
"uint8arraylist": "^2.4.3",
|
88
|
-
"uuid": "^9.0.0"
|
89
|
-
},
|
90
|
-
"devDependencies": {
|
91
|
-
"@multiformats/multiaddr": "^12.0.0",
|
92
|
-
"@rollup/plugin-commonjs": "^25.0.7",
|
93
|
-
"@rollup/plugin-json": "^6.0.0",
|
94
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
95
|
-
"@types/chai": "^4.3.11",
|
96
|
-
"@types/debug": "^4.1.12",
|
97
|
-
"@types/mocha": "^10.0.6",
|
98
|
-
"@types/uuid": "^9.0.8",
|
99
|
-
"@waku/build-utils": "*",
|
100
|
-
"chai": "^4.3.10",
|
101
|
-
"cspell": "^8.3.2",
|
102
|
-
"fast-check": "^3.15.1",
|
103
|
-
"ignore-loader": "^0.1.2",
|
104
|
-
"isomorphic-fetch": "^3.0.0",
|
105
|
-
"mocha": "^10.3.0",
|
106
|
-
"npm-run-all": "^4.1.5",
|
107
|
-
"process": "^0.11.10",
|
108
|
-
"rollup": "^4.12.0"
|
109
|
-
},
|
110
|
-
"peerDependencies": {
|
111
|
-
"@multiformats/multiaddr": "^12.0.0",
|
112
|
-
"libp2p": "^1.1.2"
|
113
|
-
},
|
114
|
-
"peerDependenciesMeta": {
|
115
|
-
"@multiformats/multiaddr": {
|
116
|
-
"optional": true
|
117
|
-
}
|
118
|
-
},
|
119
|
-
"files": [
|
120
|
-
"dist",
|
121
|
-
"bundle",
|
122
|
-
"src/**/*.ts",
|
123
|
-
"!**/*.spec.*",
|
124
|
-
"!**/*.json",
|
125
|
-
"CHANGELOG.md",
|
126
|
-
"LICENSE",
|
127
|
-
"README.md"
|
128
|
-
]
|
129
|
-
}
|
1
|
+
{"name":"@waku/core","version":"0.0.28-b5e8b17.0","description":"TypeScript implementation of the Waku v2 protocol","types":"./dist/index.d.ts","module":"./dist/index.js","react-native":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js","import":"./dist/index.js","react-native":"./dist/index.js"},"./lib/predefined_bootstrap_nodes":{"types":"./dist/lib/predefined_bootstrap_nodes.d.ts","default":"./dist/lib/predefined_bootstrap_nodes.js","import":"./dist/lib/predefined_bootstrap_nodes.js","react-native":"./dist/lib/predefined_bootstrap_nodes.js"},"./lib/message/version_0":{"types":"./dist/lib/message/version_0.d.ts","default":"./dist/lib/message/version_0.js","import":"./dist/lib/message/version_0.js","react-native":"./dist/lib/message/version_0.js"},"./lib/base_protocol":{"types":"./dist/lib/base_protocol.d.ts","default":"./dist/lib/base_protocol.js","import":"./dist/lib/base_protocol.js","react-native":"./dist/lib/base_protocol.js"}},"typesVersions":{"*":{"lib/*":["dist/lib/*"],"constants/*":["dist/constants/*"]}},"type":"module","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/core#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","decentralised","communication","web3","ethereum","dapps"],"scripts":{"build":"run-s build:**","build:esm":"tsc","build:bundle":"rollup --config rollup.config.js","fix":"run-s fix:*","fix:lint":"eslint src *.js --fix","check":"run-s check:*","check:tsc":"tsc -p tsconfig.dev.json","check:lint":"eslint src *.js","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","test":"NODE_ENV=test run-s test:*","test:node":"NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha","test:browser":"NODE_ENV=test karma start karma.conf.cjs","watch:build":"tsc -p tsconfig.json -w","watch:test":"mocha --watch","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=18"},"dependencies":{"@libp2p/ping":"^1.0.12","@noble/hashes":"^1.3.2","@waku/enr":"0.0.22-b5e8b17.0","@waku/interfaces":"0.0.23-b5e8b17.0","@waku/message-hash":"0.1.12-b5e8b17.0","@waku/proto":"0.0.7-b5e8b17.0","@waku/utils":"0.0.16-b5e8b17.0","debug":"^4.3.4","it-all":"^3.0.4","it-length-prefixed":"^9.0.4","it-pipe":"^3.0.1","p-event":"^6.0.0","uint8arraylist":"^2.4.3","uuid":"^9.0.0"},"devDependencies":{"@multiformats/multiaddr":"^12.0.0","@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^4.3.11","@types/debug":"^4.1.12","@types/mocha":"^10.0.6","@types/uuid":"^9.0.8","@waku/build-utils":"*","chai":"^4.3.10","cspell":"^8.3.2","fast-check":"^3.15.1","ignore-loader":"^0.1.2","isomorphic-fetch":"^3.0.0","mocha":"^10.3.0","npm-run-all":"^4.1.5","process":"^0.11.10","rollup":"^4.12.0"},"peerDependencies":{"@multiformats/multiaddr":"^12.0.0","libp2p":"^1.1.2","@waku/enr":"0.0.22-b5e8b17.0","@waku/interfaces":"0.0.23-b5e8b17.0","@waku/message-hash":"0.1.12-b5e8b17.0","@waku/proto":"0.0.7-b5e8b17.0","@waku/utils":"0.0.16-b5e8b17.0"},"peerDependenciesMeta":{"@multiformats/multiaddr":{"optional":true},"@waku/interfaces":{"optional":true}},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
|
package/src/index.ts
CHANGED
@@ -10,7 +10,7 @@ export * as waku_filter from "./lib/filter/index.js";
|
|
10
10
|
export { wakuFilter, FilterCodecs } from "./lib/filter/index.js";
|
11
11
|
|
12
12
|
export * as waku_light_push from "./lib/light_push/index.js";
|
13
|
-
export { LightPushCodec,
|
13
|
+
export { LightPushCodec, LightPushCore } from "./lib/light_push/index.js";
|
14
14
|
|
15
15
|
export * as waku_store from "./lib/store/index.js";
|
16
16
|
|
package/src/lib/base_protocol.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { Libp2p } from "@libp2p/interface";
|
2
2
|
import type { Peer, PeerStore, Stream } from "@libp2p/interface";
|
3
3
|
import type {
|
4
|
-
|
4
|
+
IBaseProtocolCore,
|
5
5
|
Libp2pComponents,
|
6
6
|
ProtocolCreateOptions,
|
7
7
|
PubsubTopic
|
@@ -16,27 +16,22 @@ import {
|
|
16
16
|
import { filterPeersByDiscovery } from "./filterPeers.js";
|
17
17
|
import { StreamManager } from "./stream_manager.js";
|
18
18
|
|
19
|
-
const DEFAULT_NUM_PEERS_TO_USE = 3;
|
20
|
-
|
21
19
|
/**
|
22
20
|
* A class with predefined helpers, to be used as a base to implement Waku
|
23
21
|
* Protocols.
|
24
22
|
*/
|
25
|
-
export class BaseProtocol implements
|
23
|
+
export class BaseProtocol implements IBaseProtocolCore {
|
26
24
|
public readonly addLibp2pEventListener: Libp2p["addEventListener"];
|
27
25
|
public readonly removeLibp2pEventListener: Libp2p["removeEventListener"];
|
28
|
-
readonly numPeersToUse: number;
|
29
26
|
protected streamManager: StreamManager;
|
30
27
|
|
31
28
|
constructor(
|
32
29
|
public multicodec: string,
|
33
30
|
private components: Libp2pComponents,
|
34
31
|
private log: Logger,
|
35
|
-
|
32
|
+
public readonly pubsubTopics: PubsubTopic[],
|
36
33
|
private options?: ProtocolCreateOptions
|
37
34
|
) {
|
38
|
-
this.numPeersToUse = options?.numPeersToUse ?? DEFAULT_NUM_PEERS_TO_USE;
|
39
|
-
|
40
35
|
this.addLibp2pEventListener = components.events.addEventListener.bind(
|
41
36
|
components.events
|
42
37
|
);
|
@@ -86,7 +81,7 @@ export class BaseProtocol implements IBaseProtocol {
|
|
86
81
|
|
87
82
|
* @returns A list of peers that support the protocol sorted by latency.
|
88
83
|
*/
|
89
|
-
|
84
|
+
async getPeers(
|
90
85
|
{
|
91
86
|
numPeers,
|
92
87
|
maxBootstrapPeers
|
package/src/lib/filter/index.ts
CHANGED
@@ -340,6 +340,8 @@ class Subscription {
|
|
340
340
|
}
|
341
341
|
}
|
342
342
|
|
343
|
+
const DEFAULT_NUM_PEERS = 3;
|
344
|
+
|
343
345
|
class Filter extends BaseProtocol implements IReceiver {
|
344
346
|
private activeSubscriptions = new Map<string, Subscription>();
|
345
347
|
|
@@ -357,6 +359,9 @@ class Filter extends BaseProtocol implements IReceiver {
|
|
357
359
|
return subscription;
|
358
360
|
}
|
359
361
|
|
362
|
+
//TODO: Remove when FilterCore and FilterSDK are introduced
|
363
|
+
private readonly numPeersToUse: number;
|
364
|
+
|
360
365
|
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
|
361
366
|
super(
|
362
367
|
FilterCodecs.SUBSCRIBE,
|
@@ -366,6 +371,8 @@ class Filter extends BaseProtocol implements IReceiver {
|
|
366
371
|
options
|
367
372
|
);
|
368
373
|
|
374
|
+
this.numPeersToUse = options?.numPeersToUse ?? DEFAULT_NUM_PEERS;
|
375
|
+
|
369
376
|
libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
|
370
377
|
log.error("Failed to register ", FilterCodecs.PUSH, e);
|
371
378
|
});
|