@waku/core 0.0.36-16328a3.0 → 0.0.36-3730abc.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/index.js +476 -54
- package/bundle/lib/message/version_0.js +1 -1
- package/bundle/{version_0-CiYGrPc2.js → version_0-y7BmRolm.js} +919 -184
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/connection_manager/connection_manager.d.ts +1 -1
- package/dist/lib/connection_manager/connection_manager.js +1 -1
- package/dist/lib/light_push/index.d.ts +5 -1
- package/dist/lib/light_push/index.js +5 -1
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/light_push.d.ts +3 -4
- package/dist/lib/light_push/light_push.js +18 -19
- package/dist/lib/light_push/light_push.js.map +1 -1
- package/dist/lib/light_push/light_push_v3.d.ts +10 -0
- package/dist/lib/light_push/light_push_v3.js +172 -0
- package/dist/lib/light_push/light_push_v3.js.map +1 -0
- package/dist/lib/light_push/push_rpc.d.ts +1 -1
- package/dist/lib/light_push/push_rpc.js.map +1 -1
- package/dist/lib/light_push/push_rpc_v2.d.ts +11 -0
- package/dist/lib/light_push/push_rpc_v2.js +32 -0
- package/dist/lib/light_push/push_rpc_v2.js.map +1 -0
- package/dist/lib/light_push/push_rpc_v3.d.ts +11 -0
- package/dist/lib/light_push/push_rpc_v3.js +33 -0
- package/dist/lib/light_push/push_rpc_v3.js.map +1 -0
- package/dist/lib/light_push/status_codes.d.ts +14 -0
- package/dist/lib/light_push/status_codes.js +49 -0
- package/dist/lib/light_push/status_codes.js.map +1 -0
- package/dist/lib/light_push/status_codes_v3.d.ts +17 -0
- package/dist/lib/light_push/status_codes_v3.js +69 -0
- package/dist/lib/light_push/status_codes_v3.js.map +1 -0
- package/dist/lib/message/version_0.d.ts +2 -3
- package/dist/lib/message/version_0.js +1 -4
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/message_hash/index.d.ts +1 -0
- package/dist/lib/message_hash/index.js +2 -0
- package/dist/lib/message_hash/index.js.map +1 -0
- package/dist/lib/message_hash/message_hash.d.ts +52 -0
- package/dist/lib/message_hash/message_hash.js +84 -0
- package/dist/lib/message_hash/message_hash.js.map +1 -0
- package/dist/lib/store/rpc.js +16 -10
- package/dist/lib/store/rpc.js.map +1 -1
- package/dist/lib/store/store.js +12 -2
- package/dist/lib/store/store.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +11 -0
- package/src/lib/connection_manager/connection_manager.ts +1 -1
- package/src/lib/light_push/index.ts +24 -1
- package/src/lib/light_push/light_push.ts +25 -23
- package/src/lib/light_push/light_push_v3.ts +233 -0
- package/src/lib/light_push/push_rpc.ts +1 -1
- package/src/lib/light_push/push_rpc_v2.ts +38 -0
- package/src/lib/light_push/push_rpc_v3.ts +46 -0
- package/src/lib/light_push/status_codes.ts +71 -0
- package/src/lib/light_push/status_codes_v3.ts +97 -0
- package/src/lib/message/version_0.ts +3 -7
- package/src/lib/message_hash/index.ts +1 -0
- package/src/lib/message_hash/message_hash.ts +106 -0
- package/src/lib/store/rpc.ts +23 -19
- package/src/lib/store/store.ts +13 -1
@@ -0,0 +1,84 @@
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha256";
|
2
|
+
import { isDefined } from "@waku/utils";
|
3
|
+
import { bytesToHex, concat, numberToBytes, utf8ToBytes } from "@waku/utils/bytes";
|
4
|
+
/**
|
5
|
+
* Deterministic Message Hashing as defined in
|
6
|
+
* [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/#deterministic-message-hashing)
|
7
|
+
*
|
8
|
+
* Computes a SHA-256 hash of the concatenation of pubsub topic, payload, content topic, meta, and timestamp.
|
9
|
+
*
|
10
|
+
* @param pubsubTopic - The pubsub topic string
|
11
|
+
* @param message - The message to be hashed
|
12
|
+
* @returns A Uint8Array containing the SHA-256 hash
|
13
|
+
*
|
14
|
+
* @example
|
15
|
+
* ```typescript
|
16
|
+
* import { messageHash } from "@waku/core";
|
17
|
+
*
|
18
|
+
* const pubsubTopic = "/waku/2/default-waku/proto";
|
19
|
+
* const message = {
|
20
|
+
* payload: new Uint8Array([1, 2, 3, 4]),
|
21
|
+
* contentTopic: "/waku/2/default-content/proto",
|
22
|
+
* meta: new Uint8Array([5, 6, 7, 8]),
|
23
|
+
* timestamp: new Date()
|
24
|
+
* };
|
25
|
+
*
|
26
|
+
* const hash = messageHash(pubsubTopic, message);
|
27
|
+
* ```
|
28
|
+
*/
|
29
|
+
export function messageHash(pubsubTopic, message) {
|
30
|
+
const pubsubTopicBytes = utf8ToBytes(pubsubTopic);
|
31
|
+
const contentTopicBytes = utf8ToBytes(message.contentTopic);
|
32
|
+
const timestampBytes = tryConvertTimestampToBytes(message.timestamp);
|
33
|
+
const bytes = concat([
|
34
|
+
pubsubTopicBytes,
|
35
|
+
message.payload,
|
36
|
+
contentTopicBytes,
|
37
|
+
message.meta,
|
38
|
+
timestampBytes
|
39
|
+
].filter(isDefined));
|
40
|
+
return sha256(bytes);
|
41
|
+
}
|
42
|
+
function tryConvertTimestampToBytes(timestamp) {
|
43
|
+
if (!timestamp) {
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
let bigIntTimestamp;
|
47
|
+
if (typeof timestamp === "bigint") {
|
48
|
+
bigIntTimestamp = timestamp;
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
bigIntTimestamp = BigInt(timestamp.valueOf()) * 1000000n;
|
52
|
+
}
|
53
|
+
return numberToBytes(bigIntTimestamp);
|
54
|
+
}
|
55
|
+
/**
|
56
|
+
* Computes a deterministic message hash and returns it as a hexadecimal string.
|
57
|
+
* This is a convenience wrapper around messageHash that converts the result to a hex string.
|
58
|
+
*
|
59
|
+
* @param pubsubTopic - The pubsub topic string
|
60
|
+
* @param message - The message to be hashed
|
61
|
+
* @returns A string containing the hex representation of the SHA-256 hash
|
62
|
+
*
|
63
|
+
* @example
|
64
|
+
* ```typescript
|
65
|
+
* import { messageHashStr } from "@waku/core";
|
66
|
+
*
|
67
|
+
* const pubsubTopic = "/waku/2/default-waku/proto";
|
68
|
+
* const message = {
|
69
|
+
* payload: new Uint8Array([1, 2, 3, 4]),
|
70
|
+
* contentTopic: "/waku/2/default-content/proto",
|
71
|
+
* meta: new Uint8Array([5, 6, 7, 8]),
|
72
|
+
* timestamp: new Date()
|
73
|
+
* };
|
74
|
+
*
|
75
|
+
* const hashString = messageHashStr(pubsubTopic, message);
|
76
|
+
* console.log(hashString); // e.g. "a1b2c3d4..."
|
77
|
+
* ```
|
78
|
+
*/
|
79
|
+
export function messageHashStr(pubsubTopic, message) {
|
80
|
+
const hash = messageHash(pubsubTopic, message);
|
81
|
+
const hashStr = bytesToHex(hash);
|
82
|
+
return hashStr;
|
83
|
+
}
|
84
|
+
//# sourceMappingURL=message_hash.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"message_hash.js","sourceRoot":"","sources":["../../../src/lib/message_hash/message_hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,UAAU,EACV,MAAM,EACN,aAAa,EACb,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,WAAW,CACzB,WAAmB,EACnB,OAAwC;IAExC,MAAM,gBAAgB,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IAClD,MAAM,iBAAiB,GAAG,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5D,MAAM,cAAc,GAAG,0BAA0B,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAErE,MAAM,KAAK,GAAG,MAAM,CAClB;QACE,gBAAgB;QAChB,OAAO,CAAC,OAAO;QACf,iBAAiB;QACjB,OAAO,CAAC,IAAI;QACZ,cAAc;KACf,CAAC,MAAM,CAAC,SAAS,CAAC,CACpB,CAAC;IAEF,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,0BAA0B,CACjC,SAA6C;IAE7C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;IACT,CAAC;IAED,IAAI,eAAuB,CAAC;IAE5B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,eAAe,GAAG,SAAS,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,QAAQ,CAAC;IAC3D,CAAC;IAED,OAAO,aAAa,CAAC,eAAe,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,cAAc,CAC5B,WAAmB,EACnB,OAAwC;IAExC,MAAM,IAAI,GAAG,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/lib/store/rpc.js
CHANGED
@@ -12,6 +12,7 @@ export class StoreQueryRequest {
|
|
12
12
|
static create(params) {
|
13
13
|
const request = new StoreQueryRequest({
|
14
14
|
...params,
|
15
|
+
contentTopics: params.contentTopics || [],
|
15
16
|
requestId: uuid(),
|
16
17
|
timeStart: params.timeStart
|
17
18
|
? BigInt(params.timeStart.getTime() * ONE_MILLION)
|
@@ -24,17 +25,22 @@ export class StoreQueryRequest {
|
|
24
25
|
? BigInt(params.paginationLimit)
|
25
26
|
: undefined
|
26
27
|
});
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
const isHashQuery = params.messageHashes && params.messageHashes.length > 0;
|
29
|
+
const hasContentTopics = params.contentTopics && params.contentTopics.length > 0;
|
30
|
+
const hasTimeFilter = params.timeStart || params.timeEnd;
|
31
|
+
if (isHashQuery) {
|
32
|
+
if (hasContentTopics || hasTimeFilter) {
|
33
|
+
throw new Error("Message hash lookup queries cannot include content filter criteria (contentTopics, timeStart, or timeEnd)");
|
34
|
+
}
|
31
35
|
}
|
32
|
-
|
33
|
-
(params.pubsubTopic
|
34
|
-
params.contentTopics ||
|
35
|
-
params.
|
36
|
-
|
37
|
-
|
36
|
+
else {
|
37
|
+
if ((params.pubsubTopic &&
|
38
|
+
(!params.contentTopics || params.contentTopics.length === 0)) ||
|
39
|
+
(!params.pubsubTopic &&
|
40
|
+
params.contentTopics &&
|
41
|
+
params.contentTopics.length > 0)) {
|
42
|
+
throw new Error("Both pubsubTopic and contentTopics must be set together for content-filtered queries");
|
43
|
+
}
|
38
44
|
}
|
39
45
|
return request;
|
40
46
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../src/lib/store/rpc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,iHAAiH;AACjH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AACjC,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,MAAM,OAAO,iBAAiB;IACF;IAA1B,YAA0B,KAA8B;QAA9B,UAAK,GAAL,KAAK,CAAyB;IAAG,CAAC;IAErD,MAAM,CAAC,MAAM,CAAC,MAA0B;QAC7C,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC;YACpC,GAAG,MAAM;YACT,SAAS,EAAE,IAAI,EAAE;YACjB,SAAS,EAAE,MAAM,CAAC,SAAS;gBACzB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,WAAW,CAAC;gBAClD,CAAC,CAAC,SAA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C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,OAAO,kBAAkB;IACH;IAA1B,YAA0B,KAA+B;QAA/B,UAAK,GAAL,KAAK,CAA0B;IAAG,CAAC;IAEtD,MAAM,CAAC,MAAM,CAAC,KAAqB;QACxC,MAAM,GAAG,GAAG,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnD,OAAO,IAAI,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAEM,MAAM;QACX,OAAO,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IAC/B,CAAC;IAED,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IAC/B,CAAC;IAED,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED,IAAW,gBAAgB;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC;IACrC,CAAC;CACF"}
|
package/dist/lib/store/store.js
CHANGED
@@ -15,8 +15,12 @@ export class StoreCore extends BaseProtocol {
|
|
15
15
|
this.pubsubTopics = pubsubTopics;
|
16
16
|
}
|
17
17
|
async *queryPerPage(queryOpts, decoders, peerId) {
|
18
|
-
|
19
|
-
|
18
|
+
// Only validate decoder content topics for content-filtered queries
|
19
|
+
const isHashQuery = queryOpts.messageHashes && queryOpts.messageHashes.length > 0;
|
20
|
+
if (!isHashQuery &&
|
21
|
+
queryOpts.contentTopics &&
|
22
|
+
queryOpts.contentTopics.toString() !==
|
23
|
+
Array.from(decoders.keys()).toString()) {
|
20
24
|
throw new Error("Internal error, the decoders should match the query's content topics");
|
21
25
|
}
|
22
26
|
let currentCursor = queryOpts.paginationCursor;
|
@@ -25,6 +29,12 @@ export class StoreCore extends BaseProtocol {
|
|
25
29
|
...queryOpts,
|
26
30
|
paginationCursor: currentCursor
|
27
31
|
});
|
32
|
+
log.info("Sending store query request:", {
|
33
|
+
hasMessageHashes: !!queryOpts.messageHashes?.length,
|
34
|
+
messageHashCount: queryOpts.messageHashes?.length,
|
35
|
+
pubsubTopic: queryOpts.pubsubTopic,
|
36
|
+
contentTopics: queryOpts.contentTopics
|
37
|
+
});
|
28
38
|
let stream;
|
29
39
|
try {
|
30
40
|
stream = await this.getStream(peerId);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/lib/store/store.ts"],"names":[],"mappings":"AASA,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;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAElB,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,UAAU,GAAG,6BAA6B,CAAC;AAExD,MAAM,OAAO,SAAU,SAAQ,YAAY;IAEvB;IADlB,YACkB,YAA2B,EAC3C,MAAc;QAEd,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QAHnC,iBAAY,GAAZ,YAAY,CAAe;IAI7C,CAAC;IAEM,KAAK,CAAC,CAAC,YAAY,CACxB,SAA6B,EAC7B,QAAkC,EAClC,M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ChC,aAAa;oBACX,kBAAkB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;yBAChE,WAAW,CAAC;YACnB,CAAC;iBAAM,CAAC;gBACN,aAAa,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YAC7D,CAAC;YAED,IACE,kBAAkB,CAAC,QAAQ,CAAC,MAAM,GAAG,aAAa;gBAClD,kBAAkB,CAAC,QAAQ,CAAC,MAAM;oBAChC,CAAC,SAAS,CAAC,eAAe,IAAI,iBAAiB,CAAC,EAClD,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@waku/core","version":"0.0.36-
|
1
|
+
{"name":"@waku/core","version":"0.0.36-3730abc.0","description":"TypeScript implementation of the Waku v2 protocol","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./lib/message/version_0":{"types":"./dist/lib/message/version_0.d.ts","import":"./dist/lib/message/version_0.js"},"./lib/base_protocol":{"types":"./dist/lib/base_protocol.d.ts","import":"./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":">=20"},"dependencies":{"@waku/enr":"0.0.30-3730abc.0","@waku/interfaces":"0.0.31-3730abc.0","@libp2p/ping":"2.0.1","@waku/proto":"0.0.11-3730abc.0","@waku/utils":"0.0.24-3730abc.0","debug":"^4.3.4","@noble/hashes":"^1.3.2","it-all":"^3.0.4","it-length-prefixed":"^9.0.4","it-pipe":"^3.0.1","uint8arraylist":"^2.4.3","uuid":"^9.0.0"},"devDependencies":{"@libp2p/peer-id":"^5.0.1","@libp2p/interface":"^2.1.3","@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","sinon":"^18.0.0","cspell":"^8.6.1","fast-check":"^3.19.0","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":"2.1.8"},"peerDependenciesMeta":{"@multiformats/multiaddr":{"optional":true},"libp2p":{"optional":true}},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
|
package/src/index.ts
CHANGED
@@ -11,6 +11,15 @@ export { FilterCore, FilterCodecs } from "./lib/filter/index.js";
|
|
11
11
|
|
12
12
|
export * as waku_light_push from "./lib/light_push/index.js";
|
13
13
|
export { LightPushCodec, LightPushCore } from "./lib/light_push/index.js";
|
14
|
+
export {
|
15
|
+
LightPushCoreV2,
|
16
|
+
LightPushCodecV2,
|
17
|
+
LightPushCoreV3,
|
18
|
+
LightPushCodecV3,
|
19
|
+
LightPushStatusCodeV3,
|
20
|
+
lightPushStatusCodeToProtocolErrorV3,
|
21
|
+
isSuccessStatusCodeV3
|
22
|
+
} from "./lib/light_push/index.js";
|
14
23
|
|
15
24
|
export * as waku_store from "./lib/store/index.js";
|
16
25
|
export { StoreCore, StoreCodec } from "./lib/store/index.js";
|
@@ -20,3 +29,5 @@ export { ConnectionManager } from "./lib/connection_manager/index.js";
|
|
20
29
|
export { StreamManager } from "./lib/stream_manager/index.js";
|
21
30
|
|
22
31
|
export { MetadataCodec, wakuMetadata } from "./lib/metadata/index.js";
|
32
|
+
|
33
|
+
export { messageHash, messageHashStr } from "./lib/message_hash/index.js";
|
@@ -267,7 +267,7 @@ export class ConnectionManager
|
|
267
267
|
* // Dial using multiaddr with specific protocols
|
268
268
|
* await connectionManager.dialPeer(multiaddr, [
|
269
269
|
* "/vac/waku/relay/2.0.0",
|
270
|
-
* "/vac/waku/lightpush/
|
270
|
+
* "/vac/waku/lightpush/3.0.0"
|
271
271
|
* ]);
|
272
272
|
* ```
|
273
273
|
*
|
@@ -1 +1,24 @@
|
|
1
|
-
export {
|
1
|
+
export {
|
2
|
+
LightPushCore,
|
3
|
+
LightPushCodec,
|
4
|
+
LightPushCoreV2,
|
5
|
+
LightPushCodecV2,
|
6
|
+
PushResponse
|
7
|
+
} from "./light_push.js";
|
8
|
+
|
9
|
+
export { LightPushCoreV3, LightPushCodecV3 } from "./light_push_v3.js";
|
10
|
+
export { PushRpcV3 } from "./push_rpc_v3.js";
|
11
|
+
export {
|
12
|
+
LightPushStatusCodeV3,
|
13
|
+
lightPushStatusCodeToProtocolErrorV3,
|
14
|
+
lightPushStatusDescriptionsV3,
|
15
|
+
getLightPushStatusDescriptionV3,
|
16
|
+
isSuccessStatusCodeV3
|
17
|
+
} from "./status_codes_v3.js";
|
18
|
+
export {
|
19
|
+
LightPushStatusCode,
|
20
|
+
lightPushStatusCodeToProtocolError,
|
21
|
+
lightPushStatusDescriptions,
|
22
|
+
getLightPushStatusDescription,
|
23
|
+
isSuccessStatusCode
|
24
|
+
} from "./status_codes.js";
|
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
PubsubTopic,
|
10
10
|
type ThisOrThat
|
11
11
|
} from "@waku/interfaces";
|
12
|
-
import { PushResponse } from "@waku/proto";
|
12
|
+
import { proto_lightpush_v2, PushResponse } from "@waku/proto";
|
13
13
|
import { isMessageSizeUnderCap } from "@waku/utils";
|
14
14
|
import { Logger } from "@waku/utils";
|
15
15
|
import all from "it-all";
|
@@ -19,19 +19,17 @@ import { Uint8ArrayList } from "uint8arraylist";
|
|
19
19
|
|
20
20
|
import { BaseProtocol } from "../base_protocol.js";
|
21
21
|
|
22
|
-
import {
|
22
|
+
import { PushRpcV2 } from "./push_rpc_v2.js";
|
23
23
|
import { isRLNResponseError } from "./utils.js";
|
24
24
|
|
25
25
|
const log = new Logger("light-push");
|
26
26
|
|
27
27
|
export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
28
|
-
export { PushResponse };
|
29
28
|
|
30
|
-
|
29
|
+
export const LightPushCodecV2 = LightPushCodec;
|
30
|
+
|
31
|
+
type PreparePushMessageResult = ThisOrThat<"query", PushRpcV2>;
|
31
32
|
|
32
|
-
/**
|
33
|
-
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
34
|
-
*/
|
35
33
|
export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
36
34
|
public constructor(
|
37
35
|
public readonly pubsubTopics: PubsubTopic[],
|
@@ -64,7 +62,7 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
64
62
|
};
|
65
63
|
}
|
66
64
|
|
67
|
-
const query =
|
65
|
+
const query = PushRpcV2.createRequest(protoMessage, encoder.pubsubTopic);
|
68
66
|
return { query, error: null };
|
69
67
|
} catch (error) {
|
70
68
|
log.error("Failed to prepare push message", error);
|
@@ -120,7 +118,6 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
120
118
|
async (source) => await all(source)
|
121
119
|
);
|
122
120
|
} catch (err) {
|
123
|
-
// can fail only because of `stream` abortion
|
124
121
|
log.error("Failed to send waku light push request", err);
|
125
122
|
return {
|
126
123
|
success: null,
|
@@ -136,9 +133,9 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
136
133
|
bytes.append(chunk);
|
137
134
|
});
|
138
135
|
|
139
|
-
let response: PushResponse | undefined;
|
136
|
+
let response: proto_lightpush_v2.PushResponse | undefined;
|
140
137
|
try {
|
141
|
-
response =
|
138
|
+
response = PushRpcV2.decode(bytes).response;
|
142
139
|
} catch (err) {
|
143
140
|
log.error("Failed to decode push reply", err);
|
144
141
|
return {
|
@@ -161,19 +158,21 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
161
158
|
};
|
162
159
|
}
|
163
160
|
|
164
|
-
if (isRLNResponseError(response.info)) {
|
165
|
-
log.error("Remote peer fault: RLN generation");
|
166
|
-
return {
|
167
|
-
success: null,
|
168
|
-
failure: {
|
169
|
-
error: ProtocolError.RLN_PROOF_GENERATION,
|
170
|
-
peerId: peerId
|
171
|
-
}
|
172
|
-
};
|
173
|
-
}
|
174
|
-
|
175
161
|
if (!response.isSuccess) {
|
176
|
-
|
162
|
+
const errorMessage = response.info || "Message rejected";
|
163
|
+
log.error("Remote peer rejected the message: ", errorMessage);
|
164
|
+
|
165
|
+
if (response.info && isRLNResponseError(response.info)) {
|
166
|
+
log.error("Remote peer fault: RLN generation");
|
167
|
+
return {
|
168
|
+
success: null,
|
169
|
+
failure: {
|
170
|
+
error: ProtocolError.RLN_PROOF_GENERATION,
|
171
|
+
peerId: peerId
|
172
|
+
}
|
173
|
+
};
|
174
|
+
}
|
175
|
+
|
177
176
|
return {
|
178
177
|
success: null,
|
179
178
|
failure: {
|
@@ -186,3 +185,6 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
186
185
|
return { success: peerId, failure: null };
|
187
186
|
}
|
188
187
|
}
|
188
|
+
|
189
|
+
export const LightPushCoreV2 = LightPushCore;
|
190
|
+
export { PushResponse };
|
@@ -0,0 +1,233 @@
|
|
1
|
+
import type { PeerId, Stream } from "@libp2p/interface";
|
2
|
+
import {
|
3
|
+
type CoreProtocolResult,
|
4
|
+
type IBaseProtocolCore,
|
5
|
+
type IEncoder,
|
6
|
+
type IMessage,
|
7
|
+
type Libp2p,
|
8
|
+
ProtocolError,
|
9
|
+
PubsubTopic,
|
10
|
+
type ThisOrThat
|
11
|
+
} from "@waku/interfaces";
|
12
|
+
import { proto_lightpush_v3, WakuMessage } from "@waku/proto";
|
13
|
+
import { isMessageSizeUnderCap } from "@waku/utils";
|
14
|
+
import { Logger } from "@waku/utils";
|
15
|
+
import all from "it-all";
|
16
|
+
import * as lp from "it-length-prefixed";
|
17
|
+
import { pipe } from "it-pipe";
|
18
|
+
import { Uint8ArrayList } from "uint8arraylist";
|
19
|
+
|
20
|
+
import { BaseProtocol } from "../base_protocol.js";
|
21
|
+
|
22
|
+
import { PushRpcV3 } from "./push_rpc_v3.js";
|
23
|
+
import {
|
24
|
+
getLightPushStatusDescriptionV3,
|
25
|
+
isSuccessStatusCodeV3,
|
26
|
+
lightPushStatusCodeToProtocolErrorV3,
|
27
|
+
LightPushStatusCodeV3
|
28
|
+
} from "./status_codes_v3.js";
|
29
|
+
import { isRLNResponseError } from "./utils.js";
|
30
|
+
|
31
|
+
const log = new Logger("light-push-v3");
|
32
|
+
|
33
|
+
export const LightPushCodecV3 = "/vac/waku/lightpush/3.0.0";
|
34
|
+
|
35
|
+
type PreparePushMessageResult = ThisOrThat<"query", PushRpcV3>;
|
36
|
+
|
37
|
+
export class LightPushCoreV3 extends BaseProtocol implements IBaseProtocolCore {
|
38
|
+
public constructor(
|
39
|
+
public readonly pubsubTopics: PubsubTopic[],
|
40
|
+
libp2p: Libp2p
|
41
|
+
) {
|
42
|
+
super(LightPushCodecV3, libp2p.components, pubsubTopics);
|
43
|
+
}
|
44
|
+
|
45
|
+
private async preparePushMessage(
|
46
|
+
encoder: IEncoder,
|
47
|
+
message: IMessage
|
48
|
+
): Promise<PreparePushMessageResult> {
|
49
|
+
try {
|
50
|
+
if (!message.payload || message.payload.length === 0) {
|
51
|
+
log.error("Failed to send waku light push: payload is empty");
|
52
|
+
return { query: null, error: ProtocolError.EMPTY_PAYLOAD };
|
53
|
+
}
|
54
|
+
|
55
|
+
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
56
|
+
log.error("Failed to send waku light push: message is bigger than 1MB");
|
57
|
+
return { query: null, error: ProtocolError.SIZE_TOO_BIG };
|
58
|
+
}
|
59
|
+
|
60
|
+
const protoMessage = await encoder.toProtoObj(message);
|
61
|
+
if (!protoMessage) {
|
62
|
+
log.error("Failed to encode to protoMessage, aborting push");
|
63
|
+
return {
|
64
|
+
query: null,
|
65
|
+
error: ProtocolError.ENCODE_FAILED
|
66
|
+
};
|
67
|
+
}
|
68
|
+
|
69
|
+
const query = PushRpcV3.createRequest(
|
70
|
+
protoMessage as WakuMessage,
|
71
|
+
encoder.pubsubTopic
|
72
|
+
);
|
73
|
+
return { query, error: null };
|
74
|
+
} catch (error) {
|
75
|
+
log.error("Failed to prepare push message", error);
|
76
|
+
|
77
|
+
return {
|
78
|
+
query: null,
|
79
|
+
error: ProtocolError.GENERIC_FAIL
|
80
|
+
};
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
public async send(
|
85
|
+
encoder: IEncoder,
|
86
|
+
message: IMessage,
|
87
|
+
peerId: PeerId
|
88
|
+
): Promise<CoreProtocolResult> {
|
89
|
+
const { query, error: preparationError } = await this.preparePushMessage(
|
90
|
+
encoder,
|
91
|
+
message
|
92
|
+
);
|
93
|
+
|
94
|
+
if (preparationError || !query) {
|
95
|
+
return {
|
96
|
+
success: null,
|
97
|
+
failure: {
|
98
|
+
error: preparationError,
|
99
|
+
peerId
|
100
|
+
}
|
101
|
+
};
|
102
|
+
}
|
103
|
+
|
104
|
+
let stream: Stream;
|
105
|
+
try {
|
106
|
+
stream = await this.getStream(peerId);
|
107
|
+
} catch (error) {
|
108
|
+
log.error("Failed to get stream", error);
|
109
|
+
return {
|
110
|
+
success: null,
|
111
|
+
failure: {
|
112
|
+
error: ProtocolError.NO_STREAM_AVAILABLE,
|
113
|
+
peerId: peerId
|
114
|
+
}
|
115
|
+
};
|
116
|
+
}
|
117
|
+
|
118
|
+
let res: Uint8ArrayList[] | undefined;
|
119
|
+
try {
|
120
|
+
res = await pipe(
|
121
|
+
[query.encode()],
|
122
|
+
lp.encode,
|
123
|
+
stream,
|
124
|
+
lp.decode,
|
125
|
+
async (source) => await all(source)
|
126
|
+
);
|
127
|
+
} catch (err) {
|
128
|
+
log.error("Failed to send waku light push request", err);
|
129
|
+
return {
|
130
|
+
success: null,
|
131
|
+
failure: {
|
132
|
+
error: ProtocolError.STREAM_ABORTED,
|
133
|
+
peerId: peerId
|
134
|
+
}
|
135
|
+
};
|
136
|
+
}
|
137
|
+
|
138
|
+
const bytes = new Uint8ArrayList();
|
139
|
+
res.forEach((chunk) => {
|
140
|
+
bytes.append(chunk);
|
141
|
+
});
|
142
|
+
|
143
|
+
let response: proto_lightpush_v3.LightpushResponse | undefined;
|
144
|
+
try {
|
145
|
+
response = proto_lightpush_v3.LightpushResponse.decode(bytes);
|
146
|
+
} catch (err) {
|
147
|
+
log.error("Failed to decode push response", err);
|
148
|
+
return {
|
149
|
+
success: null,
|
150
|
+
failure: {
|
151
|
+
error: ProtocolError.DECODE_FAILED,
|
152
|
+
peerId: peerId
|
153
|
+
}
|
154
|
+
};
|
155
|
+
}
|
156
|
+
|
157
|
+
if (!response) {
|
158
|
+
log.error("Remote peer fault: No response received");
|
159
|
+
return {
|
160
|
+
success: null,
|
161
|
+
failure: {
|
162
|
+
error: ProtocolError.NO_RESPONSE,
|
163
|
+
peerId: peerId
|
164
|
+
}
|
165
|
+
};
|
166
|
+
}
|
167
|
+
|
168
|
+
// Validate request ID matches (except for rate limiting responses)
|
169
|
+
if (response.requestId !== query.query?.requestId) {
|
170
|
+
// nwaku sends "N/A" for rate limiting responses
|
171
|
+
if (response.statusCode !== LightPushStatusCodeV3.TOO_MANY_REQUESTS) {
|
172
|
+
log.error("Request ID mismatch", {
|
173
|
+
sent: query.query?.requestId,
|
174
|
+
received: response.requestId
|
175
|
+
});
|
176
|
+
return {
|
177
|
+
success: null,
|
178
|
+
failure: {
|
179
|
+
error: ProtocolError.GENERIC_FAIL,
|
180
|
+
peerId: peerId
|
181
|
+
}
|
182
|
+
};
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
const statusCode = response.statusCode;
|
187
|
+
const isSuccess = isSuccessStatusCodeV3(statusCode);
|
188
|
+
|
189
|
+
// Special handling for nwaku rate limiting
|
190
|
+
if (statusCode === LightPushStatusCodeV3.TOO_MANY_REQUESTS) {
|
191
|
+
if (response.requestId === "N/A") {
|
192
|
+
log.warn("Rate limited by nwaku node", {
|
193
|
+
statusDesc:
|
194
|
+
response.statusDesc || "Request rejected due to too many requests"
|
195
|
+
});
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
if (response.relayPeerCount !== undefined) {
|
200
|
+
log.info(`Message relayed to ${response.relayPeerCount} peers`);
|
201
|
+
}
|
202
|
+
|
203
|
+
if (response.statusDesc && isRLNResponseError(response.statusDesc)) {
|
204
|
+
log.error("Remote peer fault: RLN generation");
|
205
|
+
return {
|
206
|
+
success: null,
|
207
|
+
failure: {
|
208
|
+
error: ProtocolError.RLN_PROOF_GENERATION,
|
209
|
+
peerId: peerId
|
210
|
+
}
|
211
|
+
};
|
212
|
+
}
|
213
|
+
|
214
|
+
if (!isSuccess) {
|
215
|
+
const errorMessage = getLightPushStatusDescriptionV3(
|
216
|
+
statusCode,
|
217
|
+
response.statusDesc
|
218
|
+
);
|
219
|
+
log.error("Remote peer rejected the message: ", errorMessage);
|
220
|
+
|
221
|
+
const protocolError = lightPushStatusCodeToProtocolErrorV3(statusCode);
|
222
|
+
return {
|
223
|
+
success: null,
|
224
|
+
failure: {
|
225
|
+
error: protocolError,
|
226
|
+
peerId: peerId
|
227
|
+
}
|
228
|
+
};
|
229
|
+
}
|
230
|
+
|
231
|
+
return { success: peerId, failure: null };
|
232
|
+
}
|
233
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { proto_lightpush_v2 as proto } from "@waku/proto";
|
2
|
+
import type { Uint8ArrayList } from "uint8arraylist";
|
3
|
+
import { v4 as uuid } from "uuid";
|
4
|
+
|
5
|
+
export class PushRpcV2 {
|
6
|
+
public constructor(public proto: proto.PushRpc) {}
|
7
|
+
|
8
|
+
public static createRequest(
|
9
|
+
message: proto.WakuMessage,
|
10
|
+
pubsubTopic: string
|
11
|
+
): PushRpcV2 {
|
12
|
+
return new PushRpcV2({
|
13
|
+
requestId: uuid(),
|
14
|
+
request: {
|
15
|
+
message: message,
|
16
|
+
pubsubTopic: pubsubTopic
|
17
|
+
},
|
18
|
+
response: undefined
|
19
|
+
});
|
20
|
+
}
|
21
|
+
|
22
|
+
public static decode(bytes: Uint8ArrayList): PushRpcV2 {
|
23
|
+
const res = proto.PushRpc.decode(bytes);
|
24
|
+
return new PushRpcV2(res);
|
25
|
+
}
|
26
|
+
|
27
|
+
public encode(): Uint8Array {
|
28
|
+
return proto.PushRpc.encode(this.proto);
|
29
|
+
}
|
30
|
+
|
31
|
+
public get query(): proto.PushRequest | undefined {
|
32
|
+
return this.proto.request;
|
33
|
+
}
|
34
|
+
|
35
|
+
public get response(): proto.PushResponse | undefined {
|
36
|
+
return this.proto.response;
|
37
|
+
}
|
38
|
+
}
|