@waku/core 0.0.36-b0a2e39.0 → 0.0.36-b133417.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-DEDdl6tx.js → base_protocol-DvQrudwy.js} +1 -1
- package/bundle/{index-DckUzRoN.js → index-CTo1my9M.js} +1 -80
- package/bundle/index.js +68 -330
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-DyRL7WVV.js → version_0-CyeTW0Vr.js} +32 -370
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- 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 +1 -2
- package/dist/lib/light_push/index.js +1 -2
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/light_push.d.ts +7 -2
- package/dist/lib/light_push/light_push.js +35 -19
- package/dist/lib/light_push/light_push.js.map +1 -1
- package/dist/lib/light_push/{push_rpc_v2.d.ts → push_rpc.d.ts} +3 -3
- package/dist/lib/light_push/{push_rpc_v2.js → push_rpc.js} +4 -4
- package/dist/lib/light_push/push_rpc.js.map +1 -0
- package/dist/lib/light_push/utils.d.ts +0 -24
- package/dist/lib/light_push/utils.js +0 -70
- package/dist/lib/light_push/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -5
- package/src/lib/connection_manager/connection_manager.ts +1 -1
- package/src/lib/light_push/index.ts +1 -2
- package/src/lib/light_push/light_push.ts +43 -26
- package/src/lib/light_push/{push_rpc_v2.ts → push_rpc.ts} +5 -5
- package/src/lib/light_push/utils.ts +0 -95
- package/dist/lib/light_push/light_push_v3.d.ts +0 -14
- package/dist/lib/light_push/light_push_v3.js +0 -187
- package/dist/lib/light_push/light_push_v3.js.map +0 -1
- package/dist/lib/light_push/push_rpc_v2.js.map +0 -1
- package/dist/lib/light_push/push_rpc_v3.d.ts +0 -11
- package/dist/lib/light_push/push_rpc_v3.js +0 -32
- package/dist/lib/light_push/push_rpc_v3.js.map +0 -1
- package/src/lib/light_push/light_push_v3.ts +0 -319
- package/src/lib/light_push/push_rpc_v3.ts +0 -45
@@ -1,10 +1,10 @@
|
|
1
1
|
import { proto_lightpush as proto } from "@waku/proto";
|
2
2
|
import type { Uint8ArrayList } from "uint8arraylist";
|
3
|
-
export declare class
|
3
|
+
export declare class PushRpc {
|
4
4
|
proto: proto.PushRpc;
|
5
5
|
constructor(proto: proto.PushRpc);
|
6
|
-
static createRequest(message: proto.WakuMessage, pubsubTopic: string):
|
7
|
-
static decode(bytes: Uint8ArrayList):
|
6
|
+
static createRequest(message: proto.WakuMessage, pubsubTopic: string): PushRpc;
|
7
|
+
static decode(bytes: Uint8ArrayList): PushRpc;
|
8
8
|
encode(): Uint8Array;
|
9
9
|
get query(): proto.PushRequest | undefined;
|
10
10
|
get response(): proto.PushResponse | undefined;
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { proto_lightpush as proto } from "@waku/proto";
|
2
2
|
import { v4 as uuid } from "uuid";
|
3
|
-
export class
|
3
|
+
export class PushRpc {
|
4
4
|
proto;
|
5
5
|
constructor(proto) {
|
6
6
|
this.proto = proto;
|
7
7
|
}
|
8
8
|
static createRequest(message, pubsubTopic) {
|
9
|
-
return new
|
9
|
+
return new PushRpc({
|
10
10
|
requestId: uuid(),
|
11
11
|
request: {
|
12
12
|
message: message,
|
@@ -17,7 +17,7 @@ export class PushRpcV2 {
|
|
17
17
|
}
|
18
18
|
static decode(bytes) {
|
19
19
|
const res = proto.PushRpc.decode(bytes);
|
20
|
-
return new
|
20
|
+
return new PushRpc(res);
|
21
21
|
}
|
22
22
|
encode() {
|
23
23
|
return proto.PushRpc.encode(this.proto);
|
@@ -29,4 +29,4 @@ export class PushRpcV2 {
|
|
29
29
|
return this.proto.response;
|
30
30
|
}
|
31
31
|
}
|
32
|
-
//# sourceMappingURL=
|
32
|
+
//# sourceMappingURL=push_rpc.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"push_rpc.js","sourceRoot":"","sources":["../../../src/lib/light_push/push_rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,MAAM,OAAO,OAAO;IACQ;IAA1B,YAA0B,KAAoB;QAApB,UAAK,GAAL,KAAK,CAAe;IAAG,CAAC;IAE3C,MAAM,CAAC,aAAa,CACzB,OAA0B,EAC1B,WAAmB;QAEnB,OAAO,IAAI,OAAO,CAAC;YACjB,SAAS,EAAE,IAAI,EAAE;YACjB,OAAO,EAAE;gBACP,OAAO,EAAE,OAAO;gBAChB,WAAW,EAAE,WAAW;aACzB;YACD,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,KAAqB;QACxC,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAEM,MAAM;QACX,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IAC5B,CAAC;IAED,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;CACF"}
|
@@ -1,25 +1 @@
|
|
1
|
-
import type { IEncoder, IMessage } from "@waku/interfaces";
|
2
|
-
import { ProtocolError } from "@waku/interfaces";
|
3
|
-
/**
|
4
|
-
* Validates a Light Push v3 request ID format.
|
5
|
-
* Request IDs should be valid UUIDs, with special handling for "N/A" when rate limited.
|
6
|
-
*
|
7
|
-
* @param requestId - The request ID to validate
|
8
|
-
* @returns true if the request ID is valid, false otherwise
|
9
|
-
*/
|
10
|
-
export declare function isValidRequestId(requestId: string | undefined): boolean;
|
11
1
|
export declare const isRLNResponseError: (info?: string) => boolean;
|
12
|
-
export declare function mapInfoToProtocolError(info?: string): ProtocolError;
|
13
|
-
/**
|
14
|
-
* Validates that a message conforms to Light Push protocol requirements.
|
15
|
-
*
|
16
|
-
* @param message - The message to validate
|
17
|
-
* @param encoder - The encoder to use for message size validation
|
18
|
-
* @returns A ProtocolError if validation fails, null if the message is valid
|
19
|
-
*
|
20
|
-
* @remarks
|
21
|
-
* This function performs the following validations:
|
22
|
-
* - Checks if the message payload exists and is not empty
|
23
|
-
* - Verifies the encoded message size is under the network cap (1MB)
|
24
|
-
*/
|
25
|
-
export declare function validateMessage(message: IMessage, encoder: IEncoder): Promise<ProtocolError | null>;
|
@@ -1,21 +1,3 @@
|
|
1
|
-
import { ProtocolError } from "@waku/interfaces";
|
2
|
-
import { isMessageSizeUnderCap, Logger } from "@waku/utils";
|
3
|
-
const log = new Logger("waku:light-push:utils");
|
4
|
-
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
5
|
-
/**
|
6
|
-
* Validates a Light Push v3 request ID format.
|
7
|
-
* Request IDs should be valid UUIDs, with special handling for "N/A" when rate limited.
|
8
|
-
*
|
9
|
-
* @param requestId - The request ID to validate
|
10
|
-
* @returns true if the request ID is valid, false otherwise
|
11
|
-
*/
|
12
|
-
export function isValidRequestId(requestId) {
|
13
|
-
if (!requestId)
|
14
|
-
return false;
|
15
|
-
if (requestId === "N/A")
|
16
|
-
return true; // Special case for rate-limited responses
|
17
|
-
return UUID_REGEX.test(requestId);
|
18
|
-
}
|
19
1
|
// should match nwaku
|
20
2
|
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/rln_relay.nim#L309
|
21
3
|
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim#L20
|
@@ -33,56 +15,4 @@ export const isRLNResponseError = (info) => {
|
|
33
15
|
info.includes(RLN_MESSAGE_ID_PREFIX_ERROR) ||
|
34
16
|
info.includes(RLN_REMOTE_VALIDATION));
|
35
17
|
};
|
36
|
-
export function mapInfoToProtocolError(info) {
|
37
|
-
if (!info) {
|
38
|
-
return ProtocolError.REMOTE_PEER_REJECTED;
|
39
|
-
}
|
40
|
-
const lowerInfo = info.toLowerCase();
|
41
|
-
if (isRLNResponseError(info)) {
|
42
|
-
return ProtocolError.RLN_PROOF_GENERATION;
|
43
|
-
}
|
44
|
-
if (lowerInfo.includes("rate limit") ||
|
45
|
-
lowerInfo.includes("too many requests")) {
|
46
|
-
return ProtocolError.REMOTE_PEER_REJECTED;
|
47
|
-
}
|
48
|
-
if (lowerInfo.includes("topic") &&
|
49
|
-
(lowerInfo.includes("not found") || lowerInfo.includes("not configured"))) {
|
50
|
-
return ProtocolError.TOPIC_NOT_CONFIGURED;
|
51
|
-
}
|
52
|
-
if (lowerInfo.includes("too large") || lowerInfo.includes("size")) {
|
53
|
-
return ProtocolError.SIZE_TOO_BIG;
|
54
|
-
}
|
55
|
-
if (lowerInfo.includes("decode") ||
|
56
|
-
lowerInfo.includes("invalid") ||
|
57
|
-
lowerInfo.includes("malformed")) {
|
58
|
-
return ProtocolError.DECODE_FAILED;
|
59
|
-
}
|
60
|
-
if (lowerInfo.includes("empty") && lowerInfo.includes("payload")) {
|
61
|
-
return ProtocolError.EMPTY_PAYLOAD;
|
62
|
-
}
|
63
|
-
return ProtocolError.REMOTE_PEER_REJECTED;
|
64
|
-
}
|
65
|
-
/**
|
66
|
-
* Validates that a message conforms to Light Push protocol requirements.
|
67
|
-
*
|
68
|
-
* @param message - The message to validate
|
69
|
-
* @param encoder - The encoder to use for message size validation
|
70
|
-
* @returns A ProtocolError if validation fails, null if the message is valid
|
71
|
-
*
|
72
|
-
* @remarks
|
73
|
-
* This function performs the following validations:
|
74
|
-
* - Checks if the message payload exists and is not empty
|
75
|
-
* - Verifies the encoded message size is under the network cap (1MB)
|
76
|
-
*/
|
77
|
-
export async function validateMessage(message, encoder) {
|
78
|
-
if (!message.payload?.length) {
|
79
|
-
log.error("Failed to send waku light push: payload is empty");
|
80
|
-
return ProtocolError.EMPTY_PAYLOAD;
|
81
|
-
}
|
82
|
-
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
83
|
-
log.error("Failed to send waku light push: message is bigger than 1MB");
|
84
|
-
return ProtocolError.SIZE_TOO_BIG;
|
85
|
-
}
|
86
|
-
return null;
|
87
|
-
}
|
88
18
|
//# sourceMappingURL=utils.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/light_push/utils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/light_push/utils.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,yHAAyH;AACzH,wIAAwI;AACxI,MAAM,2BAA2B,GAAG,8BAA8B,CAAC;AACnE,MAAM,2BAA2B,GAC/B,uDAAuD,CAAC;AAE1D,0BAA0B;AAC1B,wHAAwH;AACxH,gHAAgH;AAChH,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAEtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAa,EAAW,EAAE;IAC3D,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC;QAC1C,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC;QAC1C,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CACrC,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@waku/core","version":"0.0.36-
|
1
|
+
{"name":"@waku/core","version":"0.0.36-b133417.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-b133417.0","@waku/interfaces":"0.0.31-b133417.0","@libp2p/ping":"2.0.1","@waku/proto":"0.0.11-b133417.0","@waku/utils":"0.0.24-b133417.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
@@ -10,11 +10,7 @@ export * as waku_filter from "./lib/filter/index.js";
|
|
10
10
|
export { FilterCore, FilterCodecs } from "./lib/filter/index.js";
|
11
11
|
|
12
12
|
export * as waku_light_push from "./lib/light_push/index.js";
|
13
|
-
export {
|
14
|
-
LightPushCodec,
|
15
|
-
LightPushCore,
|
16
|
-
LightPushCoreV3
|
17
|
-
} from "./lib/light_push/index.js";
|
13
|
+
export { LightPushCodec, LightPushCore } from "./lib/light_push/index.js";
|
18
14
|
|
19
15
|
export * as waku_store from "./lib/store/index.js";
|
20
16
|
export { StoreCore, StoreCodec } from "./lib/store/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/2.0.0-beta1"
|
271
271
|
* ]);
|
272
272
|
* ```
|
273
273
|
*
|
@@ -1,2 +1 @@
|
|
1
|
-
export { LightPushCore, LightPushCodec } from "./light_push.js";
|
2
|
-
export { LightPushCoreV3 } from "./light_push_v3.js";
|
1
|
+
export { LightPushCore, LightPushCodec, PushResponse } from "./light_push.js";
|
@@ -1,15 +1,16 @@
|
|
1
1
|
import type { PeerId, Stream } from "@libp2p/interface";
|
2
2
|
import {
|
3
|
+
type CoreProtocolResult,
|
3
4
|
type IBaseProtocolCore,
|
4
5
|
type IEncoder,
|
5
6
|
type IMessage,
|
6
7
|
type Libp2p,
|
7
|
-
type LightPushResult,
|
8
8
|
ProtocolError,
|
9
9
|
PubsubTopic,
|
10
10
|
type ThisOrThat
|
11
11
|
} from "@waku/interfaces";
|
12
|
-
import {
|
12
|
+
import { PushResponse } from "@waku/proto";
|
13
|
+
import { isMessageSizeUnderCap } from "@waku/utils";
|
13
14
|
import { Logger } from "@waku/utils";
|
14
15
|
import all from "it-all";
|
15
16
|
import * as lp from "it-length-prefixed";
|
@@ -18,13 +19,19 @@ import { Uint8ArrayList } from "uint8arraylist";
|
|
18
19
|
|
19
20
|
import { BaseProtocol } from "../base_protocol.js";
|
20
21
|
|
21
|
-
import {
|
22
|
-
import {
|
22
|
+
import { PushRpc } from "./push_rpc.js";
|
23
|
+
import { isRLNResponseError } from "./utils.js";
|
23
24
|
|
24
25
|
const log = new Logger("light-push");
|
25
26
|
|
26
27
|
export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
28
|
+
export { PushResponse };
|
27
29
|
|
30
|
+
type PreparePushMessageResult = ThisOrThat<"query", PushRpc>;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
34
|
+
*/
|
28
35
|
export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
29
36
|
public constructor(
|
30
37
|
public readonly pubsubTopics: PubsubTopic[],
|
@@ -36,11 +43,16 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
36
43
|
private async preparePushMessage(
|
37
44
|
encoder: IEncoder,
|
38
45
|
message: IMessage
|
39
|
-
): Promise<
|
46
|
+
): Promise<PreparePushMessageResult> {
|
40
47
|
try {
|
41
|
-
|
42
|
-
|
43
|
-
return { query: null, error:
|
48
|
+
if (!message.payload || message.payload.length === 0) {
|
49
|
+
log.error("Failed to send waku light push: payload is empty");
|
50
|
+
return { query: null, error: ProtocolError.EMPTY_PAYLOAD };
|
51
|
+
}
|
52
|
+
|
53
|
+
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
54
|
+
log.error("Failed to send waku light push: message is bigger than 1MB");
|
55
|
+
return { query: null, error: ProtocolError.SIZE_TOO_BIG };
|
44
56
|
}
|
45
57
|
|
46
58
|
const protoMessage = await encoder.toProtoObj(message);
|
@@ -52,7 +64,7 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
52
64
|
};
|
53
65
|
}
|
54
66
|
|
55
|
-
const query =
|
67
|
+
const query = PushRpc.createRequest(protoMessage, encoder.pubsubTopic);
|
56
68
|
return { query, error: null };
|
57
69
|
} catch (error) {
|
58
70
|
log.error("Failed to prepare push message", error);
|
@@ -68,7 +80,7 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
68
80
|
encoder: IEncoder,
|
69
81
|
message: IMessage,
|
70
82
|
peerId: PeerId
|
71
|
-
): Promise<
|
83
|
+
): Promise<CoreProtocolResult> {
|
72
84
|
const { query, error: preparationError } = await this.preparePushMessage(
|
73
85
|
encoder,
|
74
86
|
message
|
@@ -108,6 +120,7 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
108
120
|
async (source) => await all(source)
|
109
121
|
);
|
110
122
|
} catch (err) {
|
123
|
+
// can fail only because of `stream` abortion
|
111
124
|
log.error("Failed to send waku light push request", err);
|
112
125
|
return {
|
113
126
|
success: null,
|
@@ -118,14 +131,14 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
118
131
|
};
|
119
132
|
}
|
120
133
|
|
121
|
-
const bytes =
|
122
|
-
|
123
|
-
|
124
|
-
}
|
134
|
+
const bytes = new Uint8ArrayList();
|
135
|
+
res.forEach((chunk) => {
|
136
|
+
bytes.append(chunk);
|
137
|
+
});
|
125
138
|
|
126
|
-
let response:
|
139
|
+
let response: PushResponse | undefined;
|
127
140
|
try {
|
128
|
-
response =
|
141
|
+
response = PushRpc.decode(bytes).response;
|
129
142
|
} catch (err) {
|
130
143
|
log.error("Failed to decode push reply", err);
|
131
144
|
return {
|
@@ -148,24 +161,28 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
148
161
|
};
|
149
162
|
}
|
150
163
|
|
151
|
-
if (
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
+
}
|
156
174
|
|
175
|
+
if (!response.isSuccess) {
|
176
|
+
log.error("Remote peer rejected the message: ", response.info);
|
157
177
|
return {
|
158
178
|
success: null,
|
159
179
|
failure: {
|
160
|
-
error:
|
180
|
+
error: ProtocolError.REMOTE_PEER_REJECTED,
|
161
181
|
peerId: peerId
|
162
182
|
}
|
163
183
|
};
|
164
184
|
}
|
165
185
|
|
166
|
-
return {
|
167
|
-
success: peerId,
|
168
|
-
failure: null
|
169
|
-
};
|
186
|
+
return { success: peerId, failure: null };
|
170
187
|
}
|
171
188
|
}
|
@@ -2,14 +2,14 @@ import { proto_lightpush as proto } from "@waku/proto";
|
|
2
2
|
import type { Uint8ArrayList } from "uint8arraylist";
|
3
3
|
import { v4 as uuid } from "uuid";
|
4
4
|
|
5
|
-
export class
|
5
|
+
export class PushRpc {
|
6
6
|
public constructor(public proto: proto.PushRpc) {}
|
7
7
|
|
8
8
|
public static createRequest(
|
9
9
|
message: proto.WakuMessage,
|
10
10
|
pubsubTopic: string
|
11
|
-
):
|
12
|
-
return new
|
11
|
+
): PushRpc {
|
12
|
+
return new PushRpc({
|
13
13
|
requestId: uuid(),
|
14
14
|
request: {
|
15
15
|
message: message,
|
@@ -19,9 +19,9 @@ export class PushRpcV2 {
|
|
19
19
|
});
|
20
20
|
}
|
21
21
|
|
22
|
-
public static decode(bytes: Uint8ArrayList):
|
22
|
+
public static decode(bytes: Uint8ArrayList): PushRpc {
|
23
23
|
const res = proto.PushRpc.decode(bytes);
|
24
|
-
return new
|
24
|
+
return new PushRpc(res);
|
25
25
|
}
|
26
26
|
|
27
27
|
public encode(): Uint8Array {
|
@@ -1,25 +1,3 @@
|
|
1
|
-
import type { IEncoder, IMessage } from "@waku/interfaces";
|
2
|
-
import { ProtocolError } from "@waku/interfaces";
|
3
|
-
import { isMessageSizeUnderCap, Logger } from "@waku/utils";
|
4
|
-
|
5
|
-
const log = new Logger("waku:light-push:utils");
|
6
|
-
|
7
|
-
const UUID_REGEX =
|
8
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
9
|
-
|
10
|
-
/**
|
11
|
-
* Validates a Light Push v3 request ID format.
|
12
|
-
* Request IDs should be valid UUIDs, with special handling for "N/A" when rate limited.
|
13
|
-
*
|
14
|
-
* @param requestId - The request ID to validate
|
15
|
-
* @returns true if the request ID is valid, false otherwise
|
16
|
-
*/
|
17
|
-
export function isValidRequestId(requestId: string | undefined): boolean {
|
18
|
-
if (!requestId) return false;
|
19
|
-
if (requestId === "N/A") return true; // Special case for rate-limited responses
|
20
|
-
return UUID_REGEX.test(requestId);
|
21
|
-
}
|
22
|
-
|
23
1
|
// should match nwaku
|
24
2
|
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/rln_relay.nim#L309
|
25
3
|
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim#L20
|
@@ -43,76 +21,3 @@ export const isRLNResponseError = (info?: string): boolean => {
|
|
43
21
|
info.includes(RLN_REMOTE_VALIDATION)
|
44
22
|
);
|
45
23
|
};
|
46
|
-
|
47
|
-
export function mapInfoToProtocolError(info?: string): ProtocolError {
|
48
|
-
if (!info) {
|
49
|
-
return ProtocolError.REMOTE_PEER_REJECTED;
|
50
|
-
}
|
51
|
-
|
52
|
-
const lowerInfo = info.toLowerCase();
|
53
|
-
|
54
|
-
if (isRLNResponseError(info)) {
|
55
|
-
return ProtocolError.RLN_PROOF_GENERATION;
|
56
|
-
}
|
57
|
-
|
58
|
-
if (
|
59
|
-
lowerInfo.includes("rate limit") ||
|
60
|
-
lowerInfo.includes("too many requests")
|
61
|
-
) {
|
62
|
-
return ProtocolError.REMOTE_PEER_REJECTED;
|
63
|
-
}
|
64
|
-
|
65
|
-
if (
|
66
|
-
lowerInfo.includes("topic") &&
|
67
|
-
(lowerInfo.includes("not found") || lowerInfo.includes("not configured"))
|
68
|
-
) {
|
69
|
-
return ProtocolError.TOPIC_NOT_CONFIGURED;
|
70
|
-
}
|
71
|
-
|
72
|
-
if (lowerInfo.includes("too large") || lowerInfo.includes("size")) {
|
73
|
-
return ProtocolError.SIZE_TOO_BIG;
|
74
|
-
}
|
75
|
-
|
76
|
-
if (
|
77
|
-
lowerInfo.includes("decode") ||
|
78
|
-
lowerInfo.includes("invalid") ||
|
79
|
-
lowerInfo.includes("malformed")
|
80
|
-
) {
|
81
|
-
return ProtocolError.DECODE_FAILED;
|
82
|
-
}
|
83
|
-
|
84
|
-
if (lowerInfo.includes("empty") && lowerInfo.includes("payload")) {
|
85
|
-
return ProtocolError.EMPTY_PAYLOAD;
|
86
|
-
}
|
87
|
-
|
88
|
-
return ProtocolError.REMOTE_PEER_REJECTED;
|
89
|
-
}
|
90
|
-
|
91
|
-
/**
|
92
|
-
* Validates that a message conforms to Light Push protocol requirements.
|
93
|
-
*
|
94
|
-
* @param message - The message to validate
|
95
|
-
* @param encoder - The encoder to use for message size validation
|
96
|
-
* @returns A ProtocolError if validation fails, null if the message is valid
|
97
|
-
*
|
98
|
-
* @remarks
|
99
|
-
* This function performs the following validations:
|
100
|
-
* - Checks if the message payload exists and is not empty
|
101
|
-
* - Verifies the encoded message size is under the network cap (1MB)
|
102
|
-
*/
|
103
|
-
export async function validateMessage(
|
104
|
-
message: IMessage,
|
105
|
-
encoder: IEncoder
|
106
|
-
): Promise<ProtocolError | null> {
|
107
|
-
if (!message.payload?.length) {
|
108
|
-
log.error("Failed to send waku light push: payload is empty");
|
109
|
-
return ProtocolError.EMPTY_PAYLOAD;
|
110
|
-
}
|
111
|
-
|
112
|
-
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
113
|
-
log.error("Failed to send waku light push: message is bigger than 1MB");
|
114
|
-
return ProtocolError.SIZE_TOO_BIG;
|
115
|
-
}
|
116
|
-
|
117
|
-
return null;
|
118
|
-
}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import type { PeerId } from "@libp2p/interface";
|
2
|
-
import { type IBaseProtocolCore, type IEncoder, type IMessage, type Libp2p, type LightPushResult, PubsubTopic } from "@waku/interfaces";
|
3
|
-
import { BaseProtocol } from "../base_protocol.js";
|
4
|
-
export declare class LightPushCoreV3 extends BaseProtocol implements IBaseProtocolCore {
|
5
|
-
readonly pubsubTopics: PubsubTopic[];
|
6
|
-
constructor(pubsubTopics: PubsubTopic[], libp2p: Libp2p);
|
7
|
-
send(encoder: IEncoder, message: IMessage, peerId: PeerId): Promise<LightPushResult>;
|
8
|
-
private validateAndPrepareMessage;
|
9
|
-
private executeRequest;
|
10
|
-
private processResponse;
|
11
|
-
private acquireStream;
|
12
|
-
private sendAndReceive;
|
13
|
-
private decodeResponse;
|
14
|
-
}
|