@waku/core 0.0.36-76fb1ea.0 → 0.0.36-86bbf5b.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.
Files changed (50) hide show
  1. package/bundle/{base_protocol-DbwKyDLW.js → base_protocol-DvQrudwy.js} +1 -1
  2. package/bundle/{index-JnhMR9ZE.js → index-CTo1my9M.js} +1 -20
  3. package/bundle/index.js +44 -377
  4. package/bundle/lib/base_protocol.js +2 -2
  5. package/bundle/lib/message/version_0.js +2 -2
  6. package/bundle/{version_0-sWyv9XWm.js → version_0-CyeTW0Vr.js} +57 -780
  7. package/dist/.tsbuildinfo +1 -1
  8. package/dist/index.d.ts +0 -1
  9. package/dist/index.js +0 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/lib/connection_manager/connection_manager.d.ts +1 -1
  12. package/dist/lib/connection_manager/connection_manager.js +1 -1
  13. package/dist/lib/light_push/index.d.ts +1 -5
  14. package/dist/lib/light_push/index.js +1 -5
  15. package/dist/lib/light_push/index.js.map +1 -1
  16. package/dist/lib/light_push/light_push.d.ts +4 -3
  17. package/dist/lib/light_push/light_push.js +21 -12
  18. package/dist/lib/light_push/light_push.js.map +1 -1
  19. package/dist/lib/light_push/push_rpc.d.ts +1 -1
  20. package/dist/lib/light_push/push_rpc.js.map +1 -1
  21. package/dist/lib/light_push/utils.d.ts +0 -6
  22. package/dist/lib/light_push/utils.js +0 -41
  23. package/dist/lib/light_push/utils.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/index.ts +0 -5
  26. package/src/lib/connection_manager/connection_manager.ts +1 -1
  27. package/src/lib/light_push/index.ts +1 -22
  28. package/src/lib/light_push/light_push.ts +25 -19
  29. package/src/lib/light_push/push_rpc.ts +1 -1
  30. package/src/lib/light_push/utils.ts +0 -57
  31. package/dist/lib/light_push/light_push_v3.d.ts +0 -9
  32. package/dist/lib/light_push/light_push_v3.js +0 -171
  33. package/dist/lib/light_push/light_push_v3.js.map +0 -1
  34. package/dist/lib/light_push/push_rpc_v2.d.ts +0 -11
  35. package/dist/lib/light_push/push_rpc_v2.js +0 -32
  36. package/dist/lib/light_push/push_rpc_v2.js.map +0 -1
  37. package/dist/lib/light_push/push_rpc_v3.d.ts +0 -11
  38. package/dist/lib/light_push/push_rpc_v3.js +0 -33
  39. package/dist/lib/light_push/push_rpc_v3.js.map +0 -1
  40. package/dist/lib/light_push/status_codes.d.ts +0 -14
  41. package/dist/lib/light_push/status_codes.js +0 -49
  42. package/dist/lib/light_push/status_codes.js.map +0 -1
  43. package/dist/lib/light_push/status_codes_v3.d.ts +0 -4
  44. package/dist/lib/light_push/status_codes_v3.js +0 -53
  45. package/dist/lib/light_push/status_codes_v3.js.map +0 -1
  46. package/src/lib/light_push/light_push_v3.ts +0 -232
  47. package/src/lib/light_push/push_rpc_v2.ts +0 -38
  48. package/src/lib/light_push/push_rpc_v3.ts +0 -46
  49. package/src/lib/light_push/status_codes.ts +0 -71
  50. package/src/lib/light_push/status_codes_v3.ts +0 -80
@@ -1,49 +0,0 @@
1
- import { ProtocolError } from "@waku/interfaces";
2
- export var LightPushStatusCode;
3
- (function (LightPushStatusCode) {
4
- LightPushStatusCode[LightPushStatusCode["SUCCESS"] = 200] = "SUCCESS";
5
- LightPushStatusCode[LightPushStatusCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
6
- LightPushStatusCode[LightPushStatusCode["UNSUPPORTED_PUBSUB_TOPIC"] = 404] = "UNSUPPORTED_PUBSUB_TOPIC";
7
- LightPushStatusCode[LightPushStatusCode["REQUEST_TOO_LARGE"] = 413] = "REQUEST_TOO_LARGE";
8
- LightPushStatusCode[LightPushStatusCode["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
9
- LightPushStatusCode[LightPushStatusCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
10
- LightPushStatusCode[LightPushStatusCode["NO_PEERS_TO_RELAY"] = 503] = "NO_PEERS_TO_RELAY";
11
- })(LightPushStatusCode || (LightPushStatusCode = {}));
12
- export function lightPushStatusCodeToProtocolError(statusCode) {
13
- switch (statusCode) {
14
- case LightPushStatusCode.SUCCESS:
15
- return null;
16
- case LightPushStatusCode.BAD_REQUEST:
17
- return ProtocolError.GENERIC_FAIL;
18
- case LightPushStatusCode.UNSUPPORTED_PUBSUB_TOPIC:
19
- return ProtocolError.TOPIC_NOT_CONFIGURED;
20
- case LightPushStatusCode.REQUEST_TOO_LARGE:
21
- return ProtocolError.SIZE_TOO_BIG;
22
- case LightPushStatusCode.TOO_MANY_REQUESTS:
23
- return ProtocolError.GENERIC_FAIL;
24
- case LightPushStatusCode.INTERNAL_SERVER_ERROR:
25
- return ProtocolError.REMOTE_PEER_REJECTED;
26
- case LightPushStatusCode.NO_PEERS_TO_RELAY:
27
- return ProtocolError.NO_PEER_AVAILABLE;
28
- default:
29
- return ProtocolError.REMOTE_PEER_REJECTED;
30
- }
31
- }
32
- export const lightPushStatusDescriptions = {
33
- [LightPushStatusCode.SUCCESS]: "Message pushed successfully",
34
- [LightPushStatusCode.BAD_REQUEST]: "Invalid request format or missing required fields",
35
- [LightPushStatusCode.UNSUPPORTED_PUBSUB_TOPIC]: "The specified pubsub topic is not supported",
36
- [LightPushStatusCode.REQUEST_TOO_LARGE]: "Message size exceeds maximum allowed size",
37
- [LightPushStatusCode.TOO_MANY_REQUESTS]: "Rate limit exceeded, too many requests",
38
- [LightPushStatusCode.INTERNAL_SERVER_ERROR]: "Internal server error occurred",
39
- [LightPushStatusCode.NO_PEERS_TO_RELAY]: "No relay peers available to forward the message"
40
- };
41
- export function isSuccessStatusCode(statusCode) {
42
- return statusCode === LightPushStatusCode.SUCCESS;
43
- }
44
- export function getLightPushStatusDescription(statusCode, statusDesc) {
45
- return (statusDesc ||
46
- lightPushStatusDescriptions[statusCode] ||
47
- `Unknown status code: ${statusCode}`);
48
- }
49
- //# sourceMappingURL=status_codes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"status_codes.js","s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rC,2CAA2C;IAC7C,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,EACrC,wCAAwC;IAC1C,CAAC,mBAAmB,CAAC,qBAAqB,CAAC,EAAE,gCAAgC;IAC7E,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,EACrC,iDAAiD;CACpD,CAAC;AAEF,MAAM,UAAU,mBAAmB,CAAC,UAAkB;IACpD,OAAO,UAAU,KAAK,mBAAmB,CAAC,OAAO,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,UAAkB,EAClB,UAAmB;IAEnB,OAAO,CACL,UAAU;QACV,2BAA2B,CAAC,UAAU,CAAC;QACvC,wBAAwB,UAAU,EAAE,CACrC,CAAC;AACJ,CAAC"}
@@ -1,4 +0,0 @@
1
- import { LightPushStatusCodeV3, ProtocolError } from "@waku/interfaces";
2
- export declare const lightPushStatusDescriptionsV3: Record<LightPushStatusCodeV3, string>;
3
- export declare function lightPushStatusCodeToProtocolErrorV3(statusCode: LightPushStatusCodeV3 | number | undefined): ProtocolError;
4
- export declare function getLightPushStatusDescriptionV3(statusCode: number | undefined, customDesc?: string): string;
@@ -1,53 +0,0 @@
1
- import { LightPushStatusCodeV3, ProtocolError } from "@waku/interfaces";
2
- export const lightPushStatusDescriptionsV3 = {
3
- [LightPushStatusCodeV3.SUCCESS]: "Message sent successfully",
4
- [LightPushStatusCodeV3.BAD_REQUEST]: "Bad request format",
5
- [LightPushStatusCodeV3.PAYLOAD_TOO_LARGE]: "Message payload exceeds maximum size",
6
- [LightPushStatusCodeV3.INVALID_MESSAGE_ERROR]: "Message validation failed",
7
- [LightPushStatusCodeV3.UNSUPPORTED_PUBSUB_TOPIC]: "Unsupported pubsub topic",
8
- [LightPushStatusCodeV3.TOO_MANY_REQUESTS]: "Rate limit exceeded",
9
- [LightPushStatusCodeV3.INTERNAL_SERVER_ERROR]: "Internal server error",
10
- [LightPushStatusCodeV3.SERVICE_NOT_AVAILABLE]: "Service temporarily unavailable",
11
- [LightPushStatusCodeV3.OUT_OF_RLN_PROOF]: "RLN proof generation failed",
12
- [LightPushStatusCodeV3.NO_PEERS_TO_RELAY]: "No relay peers available"
13
- };
14
- export function lightPushStatusCodeToProtocolErrorV3(statusCode) {
15
- if (!statusCode) {
16
- return ProtocolError.GENERIC_FAIL;
17
- }
18
- switch (statusCode) {
19
- case LightPushStatusCodeV3.SUCCESS:
20
- return ProtocolError.GENERIC_FAIL;
21
- case LightPushStatusCodeV3.BAD_REQUEST:
22
- return ProtocolError.DECODE_FAILED;
23
- case LightPushStatusCodeV3.PAYLOAD_TOO_LARGE:
24
- return ProtocolError.SIZE_TOO_BIG;
25
- case LightPushStatusCodeV3.INVALID_MESSAGE_ERROR:
26
- return ProtocolError.EMPTY_PAYLOAD;
27
- case LightPushStatusCodeV3.UNSUPPORTED_PUBSUB_TOPIC:
28
- return ProtocolError.TOPIC_NOT_CONFIGURED;
29
- case LightPushStatusCodeV3.TOO_MANY_REQUESTS:
30
- return ProtocolError.REMOTE_PEER_REJECTED;
31
- case LightPushStatusCodeV3.INTERNAL_SERVER_ERROR:
32
- return ProtocolError.GENERIC_FAIL;
33
- case LightPushStatusCodeV3.SERVICE_NOT_AVAILABLE:
34
- return ProtocolError.NO_PEER_AVAILABLE;
35
- case LightPushStatusCodeV3.OUT_OF_RLN_PROOF:
36
- return ProtocolError.RLN_PROOF_GENERATION;
37
- case LightPushStatusCodeV3.NO_PEERS_TO_RELAY:
38
- return ProtocolError.NO_PEER_AVAILABLE;
39
- default:
40
- return ProtocolError.REMOTE_PEER_REJECTED;
41
- }
42
- }
43
- export function getLightPushStatusDescriptionV3(statusCode, customDesc) {
44
- if (customDesc) {
45
- return customDesc;
46
- }
47
- if (!statusCode) {
48
- return "Unknown error";
49
- }
50
- return (lightPushStatusDescriptionsV3[statusCode] ||
51
- `Unknown status code: ${statusCode}`);
52
- }
53
- //# sourceMappingURL=status_codes_v3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"status_codes_v3.js","sourceRo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;QAE5C,KAAK,qBAAqB,CAAC,iBAAiB;YAC1C,OAAO,aAAa,CAAC,oBAAoB,CAAC;QAE5C,KAAK,qBAAqB,CAAC,qBAAqB;YAC9C,OAAO,aAAa,CAAC,YAAY,CAAC;QAEpC,KAAK,qBAAqB,CAAC,qBAAqB;YAC9C,OAAO,aAAa,CAAC,iBAAiB,CAAC;QAEzC,KAAK,qBAAqB,CAAC,gBAAgB;YACzC,OAAO,aAAa,CAAC,oBAAoB,CAAC;QAE5C,KAAK,qBAAqB,CAAC,iBAAiB;YAC1C,OAAO,aAAa,CAAC,iBAAiB,CAAC;QAEzC;YACE,OAAO,aAAa,CAAC,oBAAoB,CAAC;IAC9C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,UAA8B,EAC9B,UAAmB;IAEnB,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,OAAO,CACL,6BAA6B,CAAC,UAAmC,CAAC;QAClE,wBAAwB,UAAU,EAAE,CACrC,CAAC;AACJ,CAAC"}
@@ -1,232 +0,0 @@
1
- import type { PeerId, Stream } from "@libp2p/interface";
2
- import {
3
- type CoreProtocolResult,
4
- type IBaseProtocolCore,
5
- type IEncoder,
6
- type IMessage,
7
- isSuccessStatusCodeV3,
8
- type Libp2p,
9
- LightPushCodecV3,
10
- LightPushStatusCodeV3,
11
- ProtocolError,
12
- PubsubTopic,
13
- type ThisOrThat
14
- } from "@waku/interfaces";
15
- import { proto_lightpush_v3, WakuMessage } from "@waku/proto";
16
- import { isMessageSizeUnderCap } from "@waku/utils";
17
- import { Logger } from "@waku/utils";
18
- import all from "it-all";
19
- import * as lp from "it-length-prefixed";
20
- import { pipe } from "it-pipe";
21
- import { Uint8ArrayList } from "uint8arraylist";
22
-
23
- import { BaseProtocol } from "../base_protocol.js";
24
-
25
- import { PushRpcV3 } from "./push_rpc_v3.js";
26
- import {
27
- getLightPushStatusDescriptionV3,
28
- lightPushStatusCodeToProtocolErrorV3
29
- } from "./status_codes_v3.js";
30
- import { isRLNResponseError } from "./utils.js";
31
-
32
- const log = new Logger("light-push-v3");
33
-
34
- type PreparePushMessageResult = ThisOrThat<"query", PushRpcV3>;
35
-
36
- export class LightPushCoreV3 extends BaseProtocol implements IBaseProtocolCore {
37
- public constructor(
38
- public readonly pubsubTopics: PubsubTopic[],
39
- libp2p: Libp2p
40
- ) {
41
- super(LightPushCodecV3, libp2p.components, pubsubTopics);
42
- }
43
-
44
- private async preparePushMessage(
45
- encoder: IEncoder,
46
- message: IMessage
47
- ): Promise<PreparePushMessageResult> {
48
- try {
49
- if (!message.payload || message.payload.length === 0) {
50
- log.error("Failed to send waku light push: payload is empty");
51
- return { query: null, error: ProtocolError.EMPTY_PAYLOAD };
52
- }
53
-
54
- if (!(await isMessageSizeUnderCap(encoder, message))) {
55
- log.error("Failed to send waku light push: message is bigger than 1MB");
56
- return { query: null, error: ProtocolError.SIZE_TOO_BIG };
57
- }
58
-
59
- const protoMessage = await encoder.toProtoObj(message);
60
- if (!protoMessage) {
61
- log.error("Failed to encode to protoMessage, aborting push");
62
- return {
63
- query: null,
64
- error: ProtocolError.ENCODE_FAILED
65
- };
66
- }
67
-
68
- const query = PushRpcV3.createRequest(
69
- protoMessage as WakuMessage,
70
- encoder.pubsubTopic
71
- );
72
- return { query, error: null };
73
- } catch (error) {
74
- log.error("Failed to prepare push message", error);
75
-
76
- return {
77
- query: null,
78
- error: ProtocolError.GENERIC_FAIL
79
- };
80
- }
81
- }
82
-
83
- public async send(
84
- encoder: IEncoder,
85
- message: IMessage,
86
- peerId: PeerId
87
- ): Promise<CoreProtocolResult> {
88
- const { query, error: preparationError } = await this.preparePushMessage(
89
- encoder,
90
- message
91
- );
92
-
93
- if (preparationError || !query) {
94
- return {
95
- success: null,
96
- failure: {
97
- error: preparationError,
98
- peerId
99
- }
100
- };
101
- }
102
-
103
- let stream: Stream;
104
- try {
105
- stream = await this.getStream(peerId);
106
- } catch (error) {
107
- log.error("Failed to get stream", error);
108
- return {
109
- success: null,
110
- failure: {
111
- error: ProtocolError.NO_STREAM_AVAILABLE,
112
- peerId: peerId
113
- }
114
- };
115
- }
116
-
117
- let res: Uint8ArrayList[] | undefined;
118
- try {
119
- res = await pipe(
120
- [query.encode()],
121
- lp.encode,
122
- stream,
123
- lp.decode,
124
- async (source) => await all(source)
125
- );
126
- } catch (err) {
127
- log.error("Failed to send waku light push request", err);
128
- return {
129
- success: null,
130
- failure: {
131
- error: ProtocolError.STREAM_ABORTED,
132
- peerId: peerId
133
- }
134
- };
135
- }
136
-
137
- const bytes = new Uint8ArrayList();
138
- res.forEach((chunk) => {
139
- bytes.append(chunk);
140
- });
141
-
142
- let response: proto_lightpush_v3.LightpushResponse | undefined;
143
- try {
144
- response = proto_lightpush_v3.LightpushResponse.decode(bytes);
145
- } catch (err) {
146
- log.error("Failed to decode push response", err);
147
- return {
148
- success: null,
149
- failure: {
150
- error: ProtocolError.DECODE_FAILED,
151
- peerId: peerId
152
- }
153
- };
154
- }
155
-
156
- if (!response) {
157
- log.error("Remote peer fault: No response received");
158
- return {
159
- success: null,
160
- failure: {
161
- error: ProtocolError.NO_RESPONSE,
162
- peerId: peerId
163
- }
164
- };
165
- }
166
-
167
- // Validate request ID matches (except for rate limiting responses)
168
- if (response.requestId !== query.query?.requestId) {
169
- // nwaku sends "N/A" for rate limiting responses
170
- if (response.statusCode !== LightPushStatusCodeV3.TOO_MANY_REQUESTS) {
171
- log.error("Request ID mismatch", {
172
- sent: query.query?.requestId,
173
- received: response.requestId
174
- });
175
- return {
176
- success: null,
177
- failure: {
178
- error: ProtocolError.GENERIC_FAIL,
179
- peerId: peerId
180
- }
181
- };
182
- }
183
- }
184
-
185
- const statusCode = response.statusCode;
186
- const isSuccess = isSuccessStatusCodeV3(statusCode);
187
-
188
- // Special handling for nwaku rate limiting
189
- if (statusCode === LightPushStatusCodeV3.TOO_MANY_REQUESTS) {
190
- if (response.requestId === "N/A") {
191
- log.warn("Rate limited by nwaku node", {
192
- statusDesc:
193
- response.statusDesc || "Request rejected due to too many requests"
194
- });
195
- }
196
- }
197
-
198
- if (response.relayPeerCount !== undefined) {
199
- log.info(`Message relayed to ${response.relayPeerCount} peers`);
200
- }
201
-
202
- if (response.statusDesc && isRLNResponseError(response.statusDesc)) {
203
- log.error("Remote peer fault: RLN generation");
204
- return {
205
- success: null,
206
- failure: {
207
- error: ProtocolError.RLN_PROOF_GENERATION,
208
- peerId: peerId
209
- }
210
- };
211
- }
212
-
213
- if (!isSuccess) {
214
- const errorMessage = getLightPushStatusDescriptionV3(
215
- statusCode,
216
- response.statusDesc
217
- );
218
- log.error("Remote peer rejected the message: ", errorMessage);
219
-
220
- const protocolError = lightPushStatusCodeToProtocolErrorV3(statusCode);
221
- return {
222
- success: null,
223
- failure: {
224
- error: protocolError,
225
- peerId: peerId
226
- }
227
- };
228
- }
229
-
230
- return { success: peerId, failure: null };
231
- }
232
- }
@@ -1,38 +0,0 @@
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
- }
@@ -1,46 +0,0 @@
1
- import { proto_lightpush_v3, WakuMessage } from "@waku/proto";
2
- import type { Uint8ArrayList } from "uint8arraylist";
3
- import { v4 as uuid } from "uuid";
4
-
5
- export class PushRpcV3 {
6
- public request?: proto_lightpush_v3.LightpushRequest;
7
- public response?: proto_lightpush_v3.LightpushResponse;
8
-
9
- private constructor(
10
- request?: proto_lightpush_v3.LightpushRequest,
11
- response?: proto_lightpush_v3.LightpushResponse
12
- ) {
13
- this.request = request;
14
- this.response = response;
15
- }
16
-
17
- public static createRequest(
18
- message: WakuMessage,
19
- pubsubTopic?: string
20
- ): PushRpcV3 {
21
- const request: proto_lightpush_v3.LightpushRequest = {
22
- requestId: uuid(),
23
- message: message,
24
- // Only include pubsubTopic if explicitly provided (for nwaku autosharding compatibility)
25
- ...(pubsubTopic && { pubsubTopic })
26
- };
27
-
28
- return new PushRpcV3(request, undefined);
29
- }
30
-
31
- public static decode(bytes: Uint8ArrayList | Uint8Array): PushRpcV3 {
32
- const response = proto_lightpush_v3.LightpushResponse.decode(bytes);
33
- return new PushRpcV3(undefined, response);
34
- }
35
-
36
- public encode(): Uint8Array {
37
- if (!this.request) {
38
- throw new Error("Cannot encode without a request");
39
- }
40
- return proto_lightpush_v3.LightpushRequest.encode(this.request);
41
- }
42
-
43
- public get query(): proto_lightpush_v3.LightpushRequest | undefined {
44
- return this.request;
45
- }
46
- }
@@ -1,71 +0,0 @@
1
- import { ProtocolError } from "@waku/interfaces";
2
-
3
- export enum LightPushStatusCode {
4
- SUCCESS = 200,
5
- BAD_REQUEST = 400,
6
- UNSUPPORTED_PUBSUB_TOPIC = 404,
7
- REQUEST_TOO_LARGE = 413,
8
- TOO_MANY_REQUESTS = 429,
9
- INTERNAL_SERVER_ERROR = 500,
10
- NO_PEERS_TO_RELAY = 503
11
- }
12
-
13
- export function lightPushStatusCodeToProtocolError(
14
- statusCode: number
15
- ): ProtocolError | null {
16
- switch (statusCode) {
17
- case LightPushStatusCode.SUCCESS:
18
- return null;
19
-
20
- case LightPushStatusCode.BAD_REQUEST:
21
- return ProtocolError.GENERIC_FAIL;
22
-
23
- case LightPushStatusCode.UNSUPPORTED_PUBSUB_TOPIC:
24
- return ProtocolError.TOPIC_NOT_CONFIGURED;
25
-
26
- case LightPushStatusCode.REQUEST_TOO_LARGE:
27
- return ProtocolError.SIZE_TOO_BIG;
28
-
29
- case LightPushStatusCode.TOO_MANY_REQUESTS:
30
- return ProtocolError.GENERIC_FAIL;
31
-
32
- case LightPushStatusCode.INTERNAL_SERVER_ERROR:
33
- return ProtocolError.REMOTE_PEER_REJECTED;
34
-
35
- case LightPushStatusCode.NO_PEERS_TO_RELAY:
36
- return ProtocolError.NO_PEER_AVAILABLE;
37
-
38
- default:
39
- return ProtocolError.REMOTE_PEER_REJECTED;
40
- }
41
- }
42
-
43
- export const lightPushStatusDescriptions: Record<number, string> = {
44
- [LightPushStatusCode.SUCCESS]: "Message pushed successfully",
45
- [LightPushStatusCode.BAD_REQUEST]:
46
- "Invalid request format or missing required fields",
47
- [LightPushStatusCode.UNSUPPORTED_PUBSUB_TOPIC]:
48
- "The specified pubsub topic is not supported",
49
- [LightPushStatusCode.REQUEST_TOO_LARGE]:
50
- "Message size exceeds maximum allowed size",
51
- [LightPushStatusCode.TOO_MANY_REQUESTS]:
52
- "Rate limit exceeded, too many requests",
53
- [LightPushStatusCode.INTERNAL_SERVER_ERROR]: "Internal server error occurred",
54
- [LightPushStatusCode.NO_PEERS_TO_RELAY]:
55
- "No relay peers available to forward the message"
56
- };
57
-
58
- export function isSuccessStatusCode(statusCode: number): boolean {
59
- return statusCode === LightPushStatusCode.SUCCESS;
60
- }
61
-
62
- export function getLightPushStatusDescription(
63
- statusCode: number,
64
- statusDesc?: string
65
- ): string {
66
- return (
67
- statusDesc ||
68
- lightPushStatusDescriptions[statusCode] ||
69
- `Unknown status code: ${statusCode}`
70
- );
71
- }
@@ -1,80 +0,0 @@
1
- import { LightPushStatusCodeV3, ProtocolError } from "@waku/interfaces";
2
-
3
- export const lightPushStatusDescriptionsV3: Record<
4
- LightPushStatusCodeV3,
5
- string
6
- > = {
7
- [LightPushStatusCodeV3.SUCCESS]: "Message sent successfully",
8
- [LightPushStatusCodeV3.BAD_REQUEST]: "Bad request format",
9
- [LightPushStatusCodeV3.PAYLOAD_TOO_LARGE]:
10
- "Message payload exceeds maximum size",
11
- [LightPushStatusCodeV3.INVALID_MESSAGE_ERROR]: "Message validation failed",
12
- [LightPushStatusCodeV3.UNSUPPORTED_PUBSUB_TOPIC]: "Unsupported pubsub topic",
13
- [LightPushStatusCodeV3.TOO_MANY_REQUESTS]: "Rate limit exceeded",
14
- [LightPushStatusCodeV3.INTERNAL_SERVER_ERROR]: "Internal server error",
15
- [LightPushStatusCodeV3.SERVICE_NOT_AVAILABLE]:
16
- "Service temporarily unavailable",
17
- [LightPushStatusCodeV3.OUT_OF_RLN_PROOF]: "RLN proof generation failed",
18
- [LightPushStatusCodeV3.NO_PEERS_TO_RELAY]: "No relay peers available"
19
- };
20
-
21
- export function lightPushStatusCodeToProtocolErrorV3(
22
- statusCode: LightPushStatusCodeV3 | number | undefined
23
- ): ProtocolError {
24
- if (!statusCode) {
25
- return ProtocolError.GENERIC_FAIL;
26
- }
27
-
28
- switch (statusCode) {
29
- case LightPushStatusCodeV3.SUCCESS:
30
- return ProtocolError.GENERIC_FAIL;
31
-
32
- case LightPushStatusCodeV3.BAD_REQUEST:
33
- return ProtocolError.DECODE_FAILED;
34
-
35
- case LightPushStatusCodeV3.PAYLOAD_TOO_LARGE:
36
- return ProtocolError.SIZE_TOO_BIG;
37
-
38
- case LightPushStatusCodeV3.INVALID_MESSAGE_ERROR:
39
- return ProtocolError.EMPTY_PAYLOAD;
40
-
41
- case LightPushStatusCodeV3.UNSUPPORTED_PUBSUB_TOPIC:
42
- return ProtocolError.TOPIC_NOT_CONFIGURED;
43
-
44
- case LightPushStatusCodeV3.TOO_MANY_REQUESTS:
45
- return ProtocolError.REMOTE_PEER_REJECTED;
46
-
47
- case LightPushStatusCodeV3.INTERNAL_SERVER_ERROR:
48
- return ProtocolError.GENERIC_FAIL;
49
-
50
- case LightPushStatusCodeV3.SERVICE_NOT_AVAILABLE:
51
- return ProtocolError.NO_PEER_AVAILABLE;
52
-
53
- case LightPushStatusCodeV3.OUT_OF_RLN_PROOF:
54
- return ProtocolError.RLN_PROOF_GENERATION;
55
-
56
- case LightPushStatusCodeV3.NO_PEERS_TO_RELAY:
57
- return ProtocolError.NO_PEER_AVAILABLE;
58
-
59
- default:
60
- return ProtocolError.REMOTE_PEER_REJECTED;
61
- }
62
- }
63
-
64
- export function getLightPushStatusDescriptionV3(
65
- statusCode: number | undefined,
66
- customDesc?: string
67
- ): string {
68
- if (customDesc) {
69
- return customDesc;
70
- }
71
-
72
- if (!statusCode) {
73
- return "Unknown error";
74
- }
75
-
76
- return (
77
- lightPushStatusDescriptionsV3[statusCode as LightPushStatusCodeV3] ||
78
- `Unknown status code: ${statusCode}`
79
- );
80
- }