@waku/core 0.0.36-4997440.0 → 0.0.36-76fb1ea.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-DvQrudwy.js → base_protocol-DbwKyDLW.js} +1 -1
- package/bundle/{index-CTo1my9M.js → index-JnhMR9ZE.js} +20 -1
- package/bundle/index.js +377 -44
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-CyeTW0Vr.js → version_0-sWyv9XWm.js} +780 -57
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -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 +12 -21
- package/dist/lib/light_push/light_push.js.map +1 -1
- package/dist/lib/light_push/light_push_v3.d.ts +9 -0
- package/dist/lib/light_push/light_push_v3.js +171 -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 +4 -0
- package/dist/lib/light_push/status_codes_v3.js +53 -0
- package/dist/lib/light_push/status_codes_v3.js.map +1 -0
- package/dist/lib/light_push/utils.d.ts +6 -0
- package/dist/lib/light_push/utils.js +41 -0
- package/dist/lib/light_push/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +5 -0
- package/src/lib/connection_manager/connection_manager.ts +1 -1
- package/src/lib/light_push/index.ts +22 -1
- package/src/lib/light_push/light_push.ts +19 -25
- package/src/lib/light_push/light_push_v3.ts +232 -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 +80 -0
- package/src/lib/light_push/utils.ts +57 -0
@@ -645,6 +645,25 @@ var identityBase = /*#__PURE__*/Object.freeze({
|
|
645
645
|
new TextEncoder();
|
646
646
|
new TextDecoder();
|
647
647
|
|
648
|
+
// Light Push V3 Protocol Types and Constants
|
649
|
+
const LightPushCodecV3 = "/vac/waku/lightpush/3.0.0";
|
650
|
+
var LightPushStatusCodeV3;
|
651
|
+
(function (LightPushStatusCodeV3) {
|
652
|
+
LightPushStatusCodeV3[LightPushStatusCodeV3["SUCCESS"] = 200] = "SUCCESS";
|
653
|
+
LightPushStatusCodeV3[LightPushStatusCodeV3["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
654
|
+
LightPushStatusCodeV3[LightPushStatusCodeV3["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
655
|
+
LightPushStatusCodeV3[LightPushStatusCodeV3["INVALID_MESSAGE_ERROR"] = 420] = "INVALID_MESSAGE_ERROR";
|
656
|
+
LightPushStatusCodeV3[LightPushStatusCodeV3["UNSUPPORTED_PUBSUB_TOPIC"] = 421] = "UNSUPPORTED_PUBSUB_TOPIC";
|
657
|
+
LightPushStatusCodeV3[LightPushStatusCodeV3["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
658
|
+
LightPushStatusCodeV3[LightPushStatusCodeV3["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
659
|
+
LightPushStatusCodeV3[LightPushStatusCodeV3["SERVICE_NOT_AVAILABLE"] = 503] = "SERVICE_NOT_AVAILABLE";
|
660
|
+
LightPushStatusCodeV3[LightPushStatusCodeV3["OUT_OF_RLN_PROOF"] = 504] = "OUT_OF_RLN_PROOF";
|
661
|
+
LightPushStatusCodeV3[LightPushStatusCodeV3["NO_PEERS_TO_RELAY"] = 505] = "NO_PEERS_TO_RELAY";
|
662
|
+
})(LightPushStatusCodeV3 || (LightPushStatusCodeV3 = {}));
|
663
|
+
function isSuccessStatusCodeV3(statusCode) {
|
664
|
+
return statusCode === LightPushStatusCodeV3.SUCCESS;
|
665
|
+
}
|
666
|
+
|
648
667
|
var Protocols;
|
649
668
|
(function (Protocols) {
|
650
669
|
Protocols["Relay"] = "relay";
|
@@ -1540,4 +1559,4 @@ class Logger {
|
|
1540
1559
|
}
|
1541
1560
|
}
|
1542
1561
|
|
1543
|
-
export { EPeersByDiscoveryEvents as E, Logger as L, ProtocolError as P, Tags as T, base58btc as a, base32 as b, coerce as c, base36 as d, equals as e,
|
1562
|
+
export { EPeersByDiscoveryEvents as E, Logger as L, ProtocolError as P, Tags as T, base58btc as a, base32 as b, coerce as c, base36 as d, equals as e, LightPushStatusCodeV3 as f, LightPushCodecV3 as g, EConnectionStateEvents as h, isSuccessStatusCodeV3 as i, base256emoji$1 as j, base64$1 as k, base58 as l, base36$1 as m, base32$1 as n, base16$1 as o, base10$1 as p, base8$1 as q, base2$1 as r, identityBase as s };
|
package/bundle/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { v as version_0, a as allocUnsafe, b as alloc, e as encodingLength$1, c as encode$2, d as decode$4, F as FilterSubscribeRequest, f as FilterSubscribeResponse$1, M as MessagePush, P as PushRpc
|
2
|
-
export {
|
3
|
-
import { e as equals$2, c as coerce, b as base32, a as base58btc, d as base36, L as Logger, P as ProtocolError, T as Tags, E as EPeersByDiscoveryEvents,
|
4
|
-
import { B as BaseProtocol } from './base_protocol-
|
5
|
-
export { S as StreamManager } from './base_protocol-
|
1
|
+
import { v as version_0, a as allocUnsafe, b as alloc, e as encodingLength$1, c as encode$2, d as decode$4, F as FilterSubscribeRequest, f as FilterSubscribeResponse$1, M as MessagePush, P as PushRpc, L as LightpushResponse, g as LightpushRequest, h as PushResponse, S as StoreQueryRequest$1, i as StoreQueryResponse$1, t as toString$1, j as bases, k as fromString, u as utf8ToBytes, l as createEncoder, p as pubsubTopicToSingleShardInfo, m as bytesToUtf8, s as shardInfoToPubsubTopics, W as WakuMetadataRequest, n as pubsubTopicsToShardInfo, o as WakuMetadataResponse, q as concat$1, r as sha256, w as bytesToHex, x as numberToBytes } from './version_0-sWyv9XWm.js';
|
2
|
+
export { y as createDecoder } from './version_0-sWyv9XWm.js';
|
3
|
+
import { e as equals$2, c as coerce, b as base32, a as base58btc, d as base36, L as Logger, P as ProtocolError, f as LightPushStatusCodeV3, g as LightPushCodecV3, i as isSuccessStatusCodeV3, T as Tags, E as EPeersByDiscoveryEvents, h as EConnectionStateEvents } from './index-JnhMR9ZE.js';
|
4
|
+
import { B as BaseProtocol } from './base_protocol-DbwKyDLW.js';
|
5
|
+
export { S as StreamManager } from './base_protocol-DbwKyDLW.js';
|
6
6
|
|
7
7
|
/* eslint-disable */
|
8
8
|
var encode_1 = encode$1;
|
@@ -2298,7 +2298,7 @@ class FilterSubscribeResponse {
|
|
2298
2298
|
}
|
2299
2299
|
}
|
2300
2300
|
|
2301
|
-
const log$
|
2301
|
+
const log$6 = new Logger("filter:v2");
|
2302
2302
|
const FilterCodecs = {
|
2303
2303
|
SUBSCRIBE: "/vac/waku/filter-subscribe/2.0.0-beta1",
|
2304
2304
|
PUSH: "/vac/waku/filter-push/2.0.0-beta1"
|
@@ -2318,13 +2318,13 @@ class FilterCore extends BaseProtocol {
|
|
2318
2318
|
await prevHandler(pubsubTopic, message, peerIdStr);
|
2319
2319
|
}
|
2320
2320
|
catch (e) {
|
2321
|
-
log$
|
2321
|
+
log$6.error("Previous FilterCore incoming message handler failed ", e);
|
2322
2322
|
}
|
2323
2323
|
try {
|
2324
2324
|
await handleIncomingMessage(pubsubTopic, message, peerIdStr);
|
2325
2325
|
}
|
2326
2326
|
catch (e) {
|
2327
|
-
log$
|
2327
|
+
log$6.error("Present FilterCore incoming message handler failed ", e);
|
2328
2328
|
}
|
2329
2329
|
return;
|
2330
2330
|
};
|
@@ -2333,7 +2333,7 @@ class FilterCore extends BaseProtocol {
|
|
2333
2333
|
maxInboundStreams: 100
|
2334
2334
|
})
|
2335
2335
|
.catch((e) => {
|
2336
|
-
log$
|
2336
|
+
log$6.error("Failed to register ", FilterCodecs.PUSH, e);
|
2337
2337
|
});
|
2338
2338
|
}
|
2339
2339
|
async subscribe(pubsubTopic, peerId, contentTopics) {
|
@@ -2344,7 +2344,7 @@ class FilterCore extends BaseProtocol {
|
|
2344
2344
|
res = await pipe([request.encode()], encode, stream, decode, async (source) => await all(source));
|
2345
2345
|
}
|
2346
2346
|
catch (error) {
|
2347
|
-
log$
|
2347
|
+
log$6.error("Failed to send subscribe request", error);
|
2348
2348
|
return {
|
2349
2349
|
success: null,
|
2350
2350
|
failure: {
|
@@ -2355,7 +2355,7 @@ class FilterCore extends BaseProtocol {
|
|
2355
2355
|
}
|
2356
2356
|
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
2357
2357
|
if (statusCode < 200 || statusCode >= 300) {
|
2358
|
-
log$
|
2358
|
+
log$6.error(`Filter subscribe request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
2359
2359
|
return {
|
2360
2360
|
failure: {
|
2361
2361
|
error: ProtocolError.REMOTE_PEER_REJECTED,
|
@@ -2375,7 +2375,7 @@ class FilterCore extends BaseProtocol {
|
|
2375
2375
|
stream = await this.getStream(peerId);
|
2376
2376
|
}
|
2377
2377
|
catch (error) {
|
2378
|
-
log$
|
2378
|
+
log$6.error(`Failed to get a stream for remote peer${peerId.toString()}`, error);
|
2379
2379
|
return {
|
2380
2380
|
success: null,
|
2381
2381
|
failure: {
|
@@ -2389,7 +2389,7 @@ class FilterCore extends BaseProtocol {
|
|
2389
2389
|
await pipe([unsubscribeRequest.encode()], encode, stream.sink);
|
2390
2390
|
}
|
2391
2391
|
catch (error) {
|
2392
|
-
log$
|
2392
|
+
log$6.error("Failed to send unsubscribe request", error);
|
2393
2393
|
return {
|
2394
2394
|
success: null,
|
2395
2395
|
failure: {
|
@@ -2418,7 +2418,7 @@ class FilterCore extends BaseProtocol {
|
|
2418
2418
|
}
|
2419
2419
|
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
2420
2420
|
if (statusCode < 200 || statusCode >= 300) {
|
2421
|
-
log$
|
2421
|
+
log$6.error(`Filter unsubscribe all request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
2422
2422
|
return {
|
2423
2423
|
failure: {
|
2424
2424
|
error: ProtocolError.REMOTE_PEER_REJECTED,
|
@@ -2438,7 +2438,7 @@ class FilterCore extends BaseProtocol {
|
|
2438
2438
|
stream = await this.getStream(peerId);
|
2439
2439
|
}
|
2440
2440
|
catch (error) {
|
2441
|
-
log$
|
2441
|
+
log$6.error(`Failed to get a stream for remote peer${peerId.toString()}`, error);
|
2442
2442
|
return {
|
2443
2443
|
success: null,
|
2444
2444
|
failure: {
|
@@ -2453,7 +2453,7 @@ class FilterCore extends BaseProtocol {
|
|
2453
2453
|
res = await pipe([request.encode()], encode, stream, decode, async (source) => await all(source));
|
2454
2454
|
}
|
2455
2455
|
catch (error) {
|
2456
|
-
log$
|
2456
|
+
log$6.error("Failed to send ping request", error);
|
2457
2457
|
return {
|
2458
2458
|
success: null,
|
2459
2459
|
failure: {
|
@@ -2473,7 +2473,7 @@ class FilterCore extends BaseProtocol {
|
|
2473
2473
|
}
|
2474
2474
|
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
2475
2475
|
if (statusCode < 200 || statusCode >= 300) {
|
2476
|
-
log$
|
2476
|
+
log$6.error(`Filter ping request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
2477
2477
|
return {
|
2478
2478
|
success: null,
|
2479
2479
|
failure: {
|
@@ -2490,30 +2490,30 @@ class FilterCore extends BaseProtocol {
|
|
2490
2490
|
onRequest(streamData) {
|
2491
2491
|
const { connection, stream } = streamData;
|
2492
2492
|
const { remotePeer } = connection;
|
2493
|
-
log$
|
2493
|
+
log$6.info(`Received message from ${remotePeer.toString()}`);
|
2494
2494
|
try {
|
2495
2495
|
pipe(stream, decode, async (source) => {
|
2496
2496
|
for await (const bytes of source) {
|
2497
2497
|
const response = FilterPushRpc.decode(bytes.slice());
|
2498
2498
|
const { pubsubTopic, wakuMessage } = response;
|
2499
2499
|
if (!wakuMessage) {
|
2500
|
-
log$
|
2500
|
+
log$6.error("Received empty message");
|
2501
2501
|
return;
|
2502
2502
|
}
|
2503
2503
|
if (!pubsubTopic) {
|
2504
|
-
log$
|
2504
|
+
log$6.error("Pubsub topic missing from push message");
|
2505
2505
|
return;
|
2506
2506
|
}
|
2507
2507
|
await FilterCore.handleIncomingMessage?.(pubsubTopic, wakuMessage, connection.remotePeer.toString());
|
2508
2508
|
}
|
2509
2509
|
}).then(() => {
|
2510
|
-
log$
|
2510
|
+
log$6.info("Receiving pipe closed.");
|
2511
2511
|
}, async (e) => {
|
2512
|
-
log$
|
2512
|
+
log$6.error(`Error with receiving pipe on peer:${connection.remotePeer.toString()} -- stream:${stream.id} -- protocol:${stream.protocol}: `, e);
|
2513
2513
|
});
|
2514
2514
|
}
|
2515
2515
|
catch (e) {
|
2516
|
-
log$
|
2516
|
+
log$6.error("Error decoding message", e);
|
2517
2517
|
}
|
2518
2518
|
}
|
2519
2519
|
}
|
@@ -2524,13 +2524,13 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
2524
2524
|
FilterCore: FilterCore
|
2525
2525
|
});
|
2526
2526
|
|
2527
|
-
class
|
2527
|
+
class PushRpcV2 {
|
2528
2528
|
proto;
|
2529
2529
|
constructor(proto) {
|
2530
2530
|
this.proto = proto;
|
2531
2531
|
}
|
2532
2532
|
static createRequest(message, pubsubTopic) {
|
2533
|
-
return new
|
2533
|
+
return new PushRpcV2({
|
2534
2534
|
requestId: v4(),
|
2535
2535
|
request: {
|
2536
2536
|
message: message,
|
@@ -2540,11 +2540,11 @@ class PushRpc {
|
|
2540
2540
|
});
|
2541
2541
|
}
|
2542
2542
|
static decode(bytes) {
|
2543
|
-
const res = PushRpc
|
2544
|
-
return new
|
2543
|
+
const res = PushRpc.decode(bytes);
|
2544
|
+
return new PushRpcV2(res);
|
2545
2545
|
}
|
2546
2546
|
encode() {
|
2547
|
-
return PushRpc
|
2547
|
+
return PushRpc.encode(this.proto);
|
2548
2548
|
}
|
2549
2549
|
get query() {
|
2550
2550
|
return this.proto.request;
|
@@ -2571,18 +2571,260 @@ const isRLNResponseError = (info) => {
|
|
2571
2571
|
info.includes(RLN_MESSAGE_ID_PREFIX_ERROR) ||
|
2572
2572
|
info.includes(RLN_REMOTE_VALIDATION));
|
2573
2573
|
};
|
2574
|
-
|
2575
|
-
const log$4 = new Logger("light-push");
|
2576
|
-
const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
2577
2574
|
/**
|
2578
|
-
*
|
2575
|
+
* Maps error information from push response to appropriate ProtocolError
|
2576
|
+
* Uses pattern matching to handle various error cases
|
2579
2577
|
*/
|
2578
|
+
function mapInfoToProtocolError(info) {
|
2579
|
+
if (!info) {
|
2580
|
+
return ProtocolError.REMOTE_PEER_REJECTED;
|
2581
|
+
}
|
2582
|
+
const lowerInfo = info.toLowerCase();
|
2583
|
+
// RLN errors
|
2584
|
+
if (isRLNResponseError(info)) {
|
2585
|
+
return ProtocolError.RLN_PROOF_GENERATION;
|
2586
|
+
}
|
2587
|
+
// Rate limiting patterns
|
2588
|
+
if (lowerInfo.includes("rate limit") ||
|
2589
|
+
lowerInfo.includes("too many requests")) {
|
2590
|
+
return ProtocolError.REMOTE_PEER_REJECTED;
|
2591
|
+
}
|
2592
|
+
// Topic errors
|
2593
|
+
if (lowerInfo.includes("topic") &&
|
2594
|
+
(lowerInfo.includes("not found") || lowerInfo.includes("not configured"))) {
|
2595
|
+
return ProtocolError.TOPIC_NOT_CONFIGURED;
|
2596
|
+
}
|
2597
|
+
// Size errors
|
2598
|
+
if (lowerInfo.includes("too large") || lowerInfo.includes("size")) {
|
2599
|
+
return ProtocolError.SIZE_TOO_BIG;
|
2600
|
+
}
|
2601
|
+
// Decoding errors
|
2602
|
+
if (lowerInfo.includes("decode") ||
|
2603
|
+
lowerInfo.includes("invalid") ||
|
2604
|
+
lowerInfo.includes("malformed")) {
|
2605
|
+
return ProtocolError.DECODE_FAILED;
|
2606
|
+
}
|
2607
|
+
// Empty payload
|
2608
|
+
if (lowerInfo.includes("empty") && lowerInfo.includes("payload")) {
|
2609
|
+
return ProtocolError.EMPTY_PAYLOAD;
|
2610
|
+
}
|
2611
|
+
// Default case
|
2612
|
+
return ProtocolError.REMOTE_PEER_REJECTED;
|
2613
|
+
}
|
2614
|
+
|
2615
|
+
const log$5 = new Logger("light-push");
|
2616
|
+
const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
2617
|
+
const LightPushCodecV2 = LightPushCodec;
|
2580
2618
|
class LightPushCore extends BaseProtocol {
|
2581
2619
|
pubsubTopics;
|
2582
2620
|
constructor(pubsubTopics, libp2p) {
|
2583
2621
|
super(LightPushCodec, libp2p.components, pubsubTopics);
|
2584
2622
|
this.pubsubTopics = pubsubTopics;
|
2585
2623
|
}
|
2624
|
+
async preparePushMessage(encoder, message) {
|
2625
|
+
try {
|
2626
|
+
if (!message.payload || message.payload.length === 0) {
|
2627
|
+
log$5.error("Failed to send waku light push: payload is empty");
|
2628
|
+
return { query: null, error: ProtocolError.EMPTY_PAYLOAD };
|
2629
|
+
}
|
2630
|
+
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
2631
|
+
log$5.error("Failed to send waku light push: message is bigger than 1MB");
|
2632
|
+
return { query: null, error: ProtocolError.SIZE_TOO_BIG };
|
2633
|
+
}
|
2634
|
+
const protoMessage = await encoder.toProtoObj(message);
|
2635
|
+
if (!protoMessage) {
|
2636
|
+
log$5.error("Failed to encode to protoMessage, aborting push");
|
2637
|
+
return {
|
2638
|
+
query: null,
|
2639
|
+
error: ProtocolError.ENCODE_FAILED
|
2640
|
+
};
|
2641
|
+
}
|
2642
|
+
const query = PushRpcV2.createRequest(protoMessage, encoder.pubsubTopic);
|
2643
|
+
return { query, error: null };
|
2644
|
+
}
|
2645
|
+
catch (error) {
|
2646
|
+
log$5.error("Failed to prepare push message", error);
|
2647
|
+
return {
|
2648
|
+
query: null,
|
2649
|
+
error: ProtocolError.GENERIC_FAIL
|
2650
|
+
};
|
2651
|
+
}
|
2652
|
+
}
|
2653
|
+
async send(encoder, message, peerId) {
|
2654
|
+
const { query, error: preparationError } = await this.preparePushMessage(encoder, message);
|
2655
|
+
if (preparationError || !query) {
|
2656
|
+
return {
|
2657
|
+
success: null,
|
2658
|
+
failure: {
|
2659
|
+
error: preparationError,
|
2660
|
+
peerId
|
2661
|
+
}
|
2662
|
+
};
|
2663
|
+
}
|
2664
|
+
let stream;
|
2665
|
+
try {
|
2666
|
+
stream = await this.getStream(peerId);
|
2667
|
+
}
|
2668
|
+
catch (error) {
|
2669
|
+
log$5.error("Failed to get stream", error);
|
2670
|
+
return {
|
2671
|
+
success: null,
|
2672
|
+
failure: {
|
2673
|
+
error: ProtocolError.NO_STREAM_AVAILABLE,
|
2674
|
+
peerId: peerId
|
2675
|
+
}
|
2676
|
+
};
|
2677
|
+
}
|
2678
|
+
let res;
|
2679
|
+
try {
|
2680
|
+
res = await pipe([query.encode()], encode, stream, decode, async (source) => await all(source));
|
2681
|
+
}
|
2682
|
+
catch (err) {
|
2683
|
+
log$5.error("Failed to send waku light push request", err);
|
2684
|
+
return {
|
2685
|
+
success: null,
|
2686
|
+
failure: {
|
2687
|
+
error: ProtocolError.STREAM_ABORTED,
|
2688
|
+
peerId: peerId
|
2689
|
+
}
|
2690
|
+
};
|
2691
|
+
}
|
2692
|
+
const bytes = new Uint8ArrayList();
|
2693
|
+
res.forEach((chunk) => {
|
2694
|
+
bytes.append(chunk);
|
2695
|
+
});
|
2696
|
+
let response;
|
2697
|
+
try {
|
2698
|
+
response = PushRpcV2.decode(bytes).response;
|
2699
|
+
}
|
2700
|
+
catch (err) {
|
2701
|
+
log$5.error("Failed to decode push reply", err);
|
2702
|
+
return {
|
2703
|
+
success: null,
|
2704
|
+
failure: {
|
2705
|
+
error: ProtocolError.DECODE_FAILED,
|
2706
|
+
peerId: peerId
|
2707
|
+
}
|
2708
|
+
};
|
2709
|
+
}
|
2710
|
+
if (!response) {
|
2711
|
+
log$5.error("Remote peer fault: No response in PushRPC");
|
2712
|
+
return {
|
2713
|
+
success: null,
|
2714
|
+
failure: {
|
2715
|
+
error: ProtocolError.NO_RESPONSE,
|
2716
|
+
peerId: peerId
|
2717
|
+
}
|
2718
|
+
};
|
2719
|
+
}
|
2720
|
+
if (!response.isSuccess) {
|
2721
|
+
const errorMessage = response.info || "Message rejected";
|
2722
|
+
log$5.error("Remote peer rejected the message: ", errorMessage);
|
2723
|
+
// Use pattern matching to determine the appropriate error type
|
2724
|
+
const error = mapInfoToProtocolError(response.info);
|
2725
|
+
return {
|
2726
|
+
success: null,
|
2727
|
+
failure: {
|
2728
|
+
error: error,
|
2729
|
+
peerId: peerId
|
2730
|
+
}
|
2731
|
+
};
|
2732
|
+
}
|
2733
|
+
return { success: peerId, failure: null };
|
2734
|
+
}
|
2735
|
+
}
|
2736
|
+
const LightPushCoreV2 = LightPushCore;
|
2737
|
+
|
2738
|
+
class PushRpcV3 {
|
2739
|
+
request;
|
2740
|
+
response;
|
2741
|
+
constructor(request, response) {
|
2742
|
+
this.request = request;
|
2743
|
+
this.response = response;
|
2744
|
+
}
|
2745
|
+
static createRequest(message, pubsubTopic) {
|
2746
|
+
const request = {
|
2747
|
+
requestId: v4(),
|
2748
|
+
message: message,
|
2749
|
+
// Only include pubsubTopic if explicitly provided (for nwaku autosharding compatibility)
|
2750
|
+
...(pubsubTopic && { pubsubTopic })
|
2751
|
+
};
|
2752
|
+
return new PushRpcV3(request, undefined);
|
2753
|
+
}
|
2754
|
+
static decode(bytes) {
|
2755
|
+
const response = LightpushResponse.decode(bytes);
|
2756
|
+
return new PushRpcV3(undefined, response);
|
2757
|
+
}
|
2758
|
+
encode() {
|
2759
|
+
if (!this.request) {
|
2760
|
+
throw new Error("Cannot encode without a request");
|
2761
|
+
}
|
2762
|
+
return LightpushRequest.encode(this.request);
|
2763
|
+
}
|
2764
|
+
get query() {
|
2765
|
+
return this.request;
|
2766
|
+
}
|
2767
|
+
}
|
2768
|
+
|
2769
|
+
const lightPushStatusDescriptionsV3 = {
|
2770
|
+
[LightPushStatusCodeV3.SUCCESS]: "Message sent successfully",
|
2771
|
+
[LightPushStatusCodeV3.BAD_REQUEST]: "Bad request format",
|
2772
|
+
[LightPushStatusCodeV3.PAYLOAD_TOO_LARGE]: "Message payload exceeds maximum size",
|
2773
|
+
[LightPushStatusCodeV3.INVALID_MESSAGE_ERROR]: "Message validation failed",
|
2774
|
+
[LightPushStatusCodeV3.UNSUPPORTED_PUBSUB_TOPIC]: "Unsupported pubsub topic",
|
2775
|
+
[LightPushStatusCodeV3.TOO_MANY_REQUESTS]: "Rate limit exceeded",
|
2776
|
+
[LightPushStatusCodeV3.INTERNAL_SERVER_ERROR]: "Internal server error",
|
2777
|
+
[LightPushStatusCodeV3.SERVICE_NOT_AVAILABLE]: "Service temporarily unavailable",
|
2778
|
+
[LightPushStatusCodeV3.OUT_OF_RLN_PROOF]: "RLN proof generation failed",
|
2779
|
+
[LightPushStatusCodeV3.NO_PEERS_TO_RELAY]: "No relay peers available"
|
2780
|
+
};
|
2781
|
+
function lightPushStatusCodeToProtocolErrorV3(statusCode) {
|
2782
|
+
if (!statusCode) {
|
2783
|
+
return ProtocolError.GENERIC_FAIL;
|
2784
|
+
}
|
2785
|
+
switch (statusCode) {
|
2786
|
+
case LightPushStatusCodeV3.SUCCESS:
|
2787
|
+
return ProtocolError.GENERIC_FAIL;
|
2788
|
+
case LightPushStatusCodeV3.BAD_REQUEST:
|
2789
|
+
return ProtocolError.DECODE_FAILED;
|
2790
|
+
case LightPushStatusCodeV3.PAYLOAD_TOO_LARGE:
|
2791
|
+
return ProtocolError.SIZE_TOO_BIG;
|
2792
|
+
case LightPushStatusCodeV3.INVALID_MESSAGE_ERROR:
|
2793
|
+
return ProtocolError.EMPTY_PAYLOAD;
|
2794
|
+
case LightPushStatusCodeV3.UNSUPPORTED_PUBSUB_TOPIC:
|
2795
|
+
return ProtocolError.TOPIC_NOT_CONFIGURED;
|
2796
|
+
case LightPushStatusCodeV3.TOO_MANY_REQUESTS:
|
2797
|
+
return ProtocolError.REMOTE_PEER_REJECTED;
|
2798
|
+
case LightPushStatusCodeV3.INTERNAL_SERVER_ERROR:
|
2799
|
+
return ProtocolError.GENERIC_FAIL;
|
2800
|
+
case LightPushStatusCodeV3.SERVICE_NOT_AVAILABLE:
|
2801
|
+
return ProtocolError.NO_PEER_AVAILABLE;
|
2802
|
+
case LightPushStatusCodeV3.OUT_OF_RLN_PROOF:
|
2803
|
+
return ProtocolError.RLN_PROOF_GENERATION;
|
2804
|
+
case LightPushStatusCodeV3.NO_PEERS_TO_RELAY:
|
2805
|
+
return ProtocolError.NO_PEER_AVAILABLE;
|
2806
|
+
default:
|
2807
|
+
return ProtocolError.REMOTE_PEER_REJECTED;
|
2808
|
+
}
|
2809
|
+
}
|
2810
|
+
function getLightPushStatusDescriptionV3(statusCode, customDesc) {
|
2811
|
+
if (customDesc) {
|
2812
|
+
return customDesc;
|
2813
|
+
}
|
2814
|
+
if (!statusCode) {
|
2815
|
+
return "Unknown error";
|
2816
|
+
}
|
2817
|
+
return (lightPushStatusDescriptionsV3[statusCode] ||
|
2818
|
+
`Unknown status code: ${statusCode}`);
|
2819
|
+
}
|
2820
|
+
|
2821
|
+
const log$4 = new Logger("light-push-v3");
|
2822
|
+
class LightPushCoreV3 extends BaseProtocol {
|
2823
|
+
pubsubTopics;
|
2824
|
+
constructor(pubsubTopics, libp2p) {
|
2825
|
+
super(LightPushCodecV3, libp2p.components, pubsubTopics);
|
2826
|
+
this.pubsubTopics = pubsubTopics;
|
2827
|
+
}
|
2586
2828
|
async preparePushMessage(encoder, message) {
|
2587
2829
|
try {
|
2588
2830
|
if (!message.payload || message.payload.length === 0) {
|
@@ -2601,7 +2843,7 @@ class LightPushCore extends BaseProtocol {
|
|
2601
2843
|
error: ProtocolError.ENCODE_FAILED
|
2602
2844
|
};
|
2603
2845
|
}
|
2604
|
-
const query =
|
2846
|
+
const query = PushRpcV3.createRequest(protoMessage, encoder.pubsubTopic);
|
2605
2847
|
return { query, error: null };
|
2606
2848
|
}
|
2607
2849
|
catch (error) {
|
@@ -2642,7 +2884,6 @@ class LightPushCore extends BaseProtocol {
|
|
2642
2884
|
res = await pipe([query.encode()], encode, stream, decode, async (source) => await all(source));
|
2643
2885
|
}
|
2644
2886
|
catch (err) {
|
2645
|
-
// can fail only because of `stream` abortion
|
2646
2887
|
log$4.error("Failed to send waku light push request", err);
|
2647
2888
|
return {
|
2648
2889
|
success: null,
|
@@ -2658,10 +2899,10 @@ class LightPushCore extends BaseProtocol {
|
|
2658
2899
|
});
|
2659
2900
|
let response;
|
2660
2901
|
try {
|
2661
|
-
response =
|
2902
|
+
response = LightpushResponse.decode(bytes);
|
2662
2903
|
}
|
2663
2904
|
catch (err) {
|
2664
|
-
log$4.error("Failed to decode push
|
2905
|
+
log$4.error("Failed to decode push response", err);
|
2665
2906
|
return {
|
2666
2907
|
success: null,
|
2667
2908
|
failure: {
|
@@ -2671,7 +2912,7 @@ class LightPushCore extends BaseProtocol {
|
|
2671
2912
|
};
|
2672
2913
|
}
|
2673
2914
|
if (!response) {
|
2674
|
-
log$4.error("Remote peer fault: No response
|
2915
|
+
log$4.error("Remote peer fault: No response received");
|
2675
2916
|
return {
|
2676
2917
|
success: null,
|
2677
2918
|
failure: {
|
@@ -2680,7 +2921,37 @@ class LightPushCore extends BaseProtocol {
|
|
2680
2921
|
}
|
2681
2922
|
};
|
2682
2923
|
}
|
2683
|
-
|
2924
|
+
// Validate request ID matches (except for rate limiting responses)
|
2925
|
+
if (response.requestId !== query.query?.requestId) {
|
2926
|
+
// nwaku sends "N/A" for rate limiting responses
|
2927
|
+
if (response.statusCode !== LightPushStatusCodeV3.TOO_MANY_REQUESTS) {
|
2928
|
+
log$4.error("Request ID mismatch", {
|
2929
|
+
sent: query.query?.requestId,
|
2930
|
+
received: response.requestId
|
2931
|
+
});
|
2932
|
+
return {
|
2933
|
+
success: null,
|
2934
|
+
failure: {
|
2935
|
+
error: ProtocolError.GENERIC_FAIL,
|
2936
|
+
peerId: peerId
|
2937
|
+
}
|
2938
|
+
};
|
2939
|
+
}
|
2940
|
+
}
|
2941
|
+
const statusCode = response.statusCode;
|
2942
|
+
const isSuccess = isSuccessStatusCodeV3(statusCode);
|
2943
|
+
// Special handling for nwaku rate limiting
|
2944
|
+
if (statusCode === LightPushStatusCodeV3.TOO_MANY_REQUESTS) {
|
2945
|
+
if (response.requestId === "N/A") {
|
2946
|
+
log$4.warn("Rate limited by nwaku node", {
|
2947
|
+
statusDesc: response.statusDesc || "Request rejected due to too many requests"
|
2948
|
+
});
|
2949
|
+
}
|
2950
|
+
}
|
2951
|
+
if (response.relayPeerCount !== undefined) {
|
2952
|
+
log$4.info(`Message relayed to ${response.relayPeerCount} peers`);
|
2953
|
+
}
|
2954
|
+
if (response.statusDesc && isRLNResponseError(response.statusDesc)) {
|
2684
2955
|
log$4.error("Remote peer fault: RLN generation");
|
2685
2956
|
return {
|
2686
2957
|
success: null,
|
@@ -2690,12 +2961,14 @@ class LightPushCore extends BaseProtocol {
|
|
2690
2961
|
}
|
2691
2962
|
};
|
2692
2963
|
}
|
2693
|
-
if (!
|
2694
|
-
|
2964
|
+
if (!isSuccess) {
|
2965
|
+
const errorMessage = getLightPushStatusDescriptionV3(statusCode, response.statusDesc);
|
2966
|
+
log$4.error("Remote peer rejected the message: ", errorMessage);
|
2967
|
+
const protocolError = lightPushStatusCodeToProtocolErrorV3(statusCode);
|
2695
2968
|
return {
|
2696
2969
|
success: null,
|
2697
2970
|
failure: {
|
2698
|
-
error:
|
2971
|
+
error: protocolError,
|
2699
2972
|
peerId: peerId
|
2700
2973
|
}
|
2701
2974
|
};
|
@@ -2704,11 +2977,71 @@ class LightPushCore extends BaseProtocol {
|
|
2704
2977
|
}
|
2705
2978
|
}
|
2706
2979
|
|
2980
|
+
var LightPushStatusCode;
|
2981
|
+
(function (LightPushStatusCode) {
|
2982
|
+
LightPushStatusCode[LightPushStatusCode["SUCCESS"] = 200] = "SUCCESS";
|
2983
|
+
LightPushStatusCode[LightPushStatusCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
2984
|
+
LightPushStatusCode[LightPushStatusCode["UNSUPPORTED_PUBSUB_TOPIC"] = 404] = "UNSUPPORTED_PUBSUB_TOPIC";
|
2985
|
+
LightPushStatusCode[LightPushStatusCode["REQUEST_TOO_LARGE"] = 413] = "REQUEST_TOO_LARGE";
|
2986
|
+
LightPushStatusCode[LightPushStatusCode["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
2987
|
+
LightPushStatusCode[LightPushStatusCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
2988
|
+
LightPushStatusCode[LightPushStatusCode["NO_PEERS_TO_RELAY"] = 503] = "NO_PEERS_TO_RELAY";
|
2989
|
+
})(LightPushStatusCode || (LightPushStatusCode = {}));
|
2990
|
+
function lightPushStatusCodeToProtocolError(statusCode) {
|
2991
|
+
switch (statusCode) {
|
2992
|
+
case LightPushStatusCode.SUCCESS:
|
2993
|
+
return null;
|
2994
|
+
case LightPushStatusCode.BAD_REQUEST:
|
2995
|
+
return ProtocolError.GENERIC_FAIL;
|
2996
|
+
case LightPushStatusCode.UNSUPPORTED_PUBSUB_TOPIC:
|
2997
|
+
return ProtocolError.TOPIC_NOT_CONFIGURED;
|
2998
|
+
case LightPushStatusCode.REQUEST_TOO_LARGE:
|
2999
|
+
return ProtocolError.SIZE_TOO_BIG;
|
3000
|
+
case LightPushStatusCode.TOO_MANY_REQUESTS:
|
3001
|
+
return ProtocolError.GENERIC_FAIL;
|
3002
|
+
case LightPushStatusCode.INTERNAL_SERVER_ERROR:
|
3003
|
+
return ProtocolError.REMOTE_PEER_REJECTED;
|
3004
|
+
case LightPushStatusCode.NO_PEERS_TO_RELAY:
|
3005
|
+
return ProtocolError.NO_PEER_AVAILABLE;
|
3006
|
+
default:
|
3007
|
+
return ProtocolError.REMOTE_PEER_REJECTED;
|
3008
|
+
}
|
3009
|
+
}
|
3010
|
+
const lightPushStatusDescriptions = {
|
3011
|
+
[LightPushStatusCode.SUCCESS]: "Message pushed successfully",
|
3012
|
+
[LightPushStatusCode.BAD_REQUEST]: "Invalid request format or missing required fields",
|
3013
|
+
[LightPushStatusCode.UNSUPPORTED_PUBSUB_TOPIC]: "The specified pubsub topic is not supported",
|
3014
|
+
[LightPushStatusCode.REQUEST_TOO_LARGE]: "Message size exceeds maximum allowed size",
|
3015
|
+
[LightPushStatusCode.TOO_MANY_REQUESTS]: "Rate limit exceeded, too many requests",
|
3016
|
+
[LightPushStatusCode.INTERNAL_SERVER_ERROR]: "Internal server error occurred",
|
3017
|
+
[LightPushStatusCode.NO_PEERS_TO_RELAY]: "No relay peers available to forward the message"
|
3018
|
+
};
|
3019
|
+
function isSuccessStatusCode(statusCode) {
|
3020
|
+
return statusCode === LightPushStatusCode.SUCCESS;
|
3021
|
+
}
|
3022
|
+
function getLightPushStatusDescription(statusCode, statusDesc) {
|
3023
|
+
return (statusDesc ||
|
3024
|
+
lightPushStatusDescriptions[statusCode] ||
|
3025
|
+
`Unknown status code: ${statusCode}`);
|
3026
|
+
}
|
3027
|
+
|
2707
3028
|
var index$1 = /*#__PURE__*/Object.freeze({
|
2708
3029
|
__proto__: null,
|
2709
3030
|
LightPushCodec: LightPushCodec,
|
3031
|
+
LightPushCodecV2: LightPushCodecV2,
|
2710
3032
|
LightPushCore: LightPushCore,
|
2711
|
-
|
3033
|
+
LightPushCoreV2: LightPushCoreV2,
|
3034
|
+
LightPushCoreV3: LightPushCoreV3,
|
3035
|
+
get LightPushStatusCode () { return LightPushStatusCode; },
|
3036
|
+
get PushResponse () { return PushResponse; },
|
3037
|
+
PushRpcV3: PushRpcV3,
|
3038
|
+
getLightPushStatusDescription: getLightPushStatusDescription,
|
3039
|
+
getLightPushStatusDescriptionV3: getLightPushStatusDescriptionV3,
|
3040
|
+
isSuccessStatusCode: isSuccessStatusCode,
|
3041
|
+
lightPushStatusCodeToProtocolError: lightPushStatusCodeToProtocolError,
|
3042
|
+
lightPushStatusCodeToProtocolErrorV3: lightPushStatusCodeToProtocolErrorV3,
|
3043
|
+
lightPushStatusDescriptions: lightPushStatusDescriptions,
|
3044
|
+
lightPushStatusDescriptionsV3: lightPushStatusDescriptionsV3
|
2712
3045
|
});
|
2713
3046
|
|
2714
3047
|
const EmptyMessage = {
|
@@ -4424,7 +4757,7 @@ class ConnectionManager extends TypedEventEmitter {
|
|
4424
4757
|
* // Dial using multiaddr with specific protocols
|
4425
4758
|
* await connectionManager.dialPeer(multiaddr, [
|
4426
4759
|
* "/vac/waku/relay/2.0.0",
|
4427
|
-
* "/vac/waku/lightpush/
|
4760
|
+
* "/vac/waku/lightpush/3.0.0"
|
4428
4761
|
* ]);
|
4429
4762
|
* ```
|
4430
4763
|
*
|
@@ -4973,4 +5306,4 @@ function messageHashStr(pubsubTopic, message) {
|
|
4973
5306
|
return hashStr;
|
4974
5307
|
}
|
4975
5308
|
|
4976
|
-
export { ConnectionManager, FilterCodecs, FilterCore, LightPushCodec, LightPushCore, MetadataCodec, StoreCodec, StoreCore, createEncoder, index$3 as message, messageHash, messageHashStr, wakuMetadata, index$2 as waku_filter, index$1 as waku_light_push, index as waku_store };
|
5309
|
+
export { ConnectionManager, FilterCodecs, FilterCore, LightPushCodec, LightPushCodecV2, LightPushCore, LightPushCoreV2, LightPushCoreV3, MetadataCodec, StoreCodec, StoreCore, createEncoder, index$3 as message, messageHash, messageHashStr, wakuMetadata, index$2 as waku_filter, index$1 as waku_light_push, index as waku_store };
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export { B as BaseProtocol } from '../base_protocol-
|
2
|
-
import '../index-
|
1
|
+
export { B as BaseProtocol } from '../base_protocol-DbwKyDLW.js';
|
2
|
+
import '../index-JnhMR9ZE.js';
|