@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.
- package/bundle/{base_protocol-DbwKyDLW.js → base_protocol-DvQrudwy.js} +1 -1
- package/bundle/{index-JnhMR9ZE.js → index-CTo1my9M.js} +1 -20
- package/bundle/index.js +44 -377
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-sWyv9XWm.js → version_0-CyeTW0Vr.js} +57 -780
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -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 -5
- package/dist/lib/light_push/index.js +1 -5
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/light_push.d.ts +4 -3
- package/dist/lib/light_push/light_push.js +21 -12
- package/dist/lib/light_push/light_push.js.map +1 -1
- 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/utils.d.ts +0 -6
- package/dist/lib/light_push/utils.js +0 -41
- package/dist/lib/light_push/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -5
- package/src/lib/connection_manager/connection_manager.ts +1 -1
- package/src/lib/light_push/index.ts +1 -22
- package/src/lib/light_push/light_push.ts +25 -19
- package/src/lib/light_push/push_rpc.ts +1 -1
- package/src/lib/light_push/utils.ts +0 -57
- package/dist/lib/light_push/light_push_v3.d.ts +0 -9
- package/dist/lib/light_push/light_push_v3.js +0 -171
- package/dist/lib/light_push/light_push_v3.js.map +0 -1
- package/dist/lib/light_push/push_rpc_v2.d.ts +0 -11
- package/dist/lib/light_push/push_rpc_v2.js +0 -32
- 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 -33
- package/dist/lib/light_push/push_rpc_v3.js.map +0 -1
- package/dist/lib/light_push/status_codes.d.ts +0 -14
- package/dist/lib/light_push/status_codes.js +0 -49
- package/dist/lib/light_push/status_codes.js.map +0 -1
- package/dist/lib/light_push/status_codes_v3.d.ts +0 -4
- package/dist/lib/light_push/status_codes_v3.js +0 -53
- package/dist/lib/light_push/status_codes_v3.js.map +0 -1
- package/src/lib/light_push/light_push_v3.ts +0 -232
- package/src/lib/light_push/push_rpc_v2.ts +0 -38
- package/src/lib/light_push/push_rpc_v3.ts +0 -46
- package/src/lib/light_push/status_codes.ts +0 -71
- package/src/lib/light_push/status_codes_v3.ts +0 -80
@@ -645,25 +645,6 @@ 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
|
-
|
667
648
|
var Protocols;
|
668
649
|
(function (Protocols) {
|
669
650
|
Protocols["Relay"] = "relay";
|
@@ -1559,4 +1540,4 @@ class Logger {
|
|
1559
1540
|
}
|
1560
1541
|
}
|
1561
1542
|
|
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,
|
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, EConnectionStateEvents as f, base256emoji$1 as g, base64$1 as h, base58 as i, base36$1 as j, base32$1 as k, base16$1 as l, base10$1 as m, base8$1 as n, base2$1 as o, identityBase as p };
|
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,
|
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$1, g as PushResponse, S as StoreQueryRequest$1, h as StoreQueryResponse$1, t as toString$1, i as bases, j as fromString, u as utf8ToBytes, k as createEncoder, p as pubsubTopicToSingleShardInfo, l as bytesToUtf8, s as shardInfoToPubsubTopics, W as WakuMetadataRequest, m as pubsubTopicsToShardInfo, n as WakuMetadataResponse, o as concat$1, q as sha256, r as bytesToHex, w as numberToBytes } from './version_0-CyeTW0Vr.js';
|
2
|
+
export { x as createDecoder } from './version_0-CyeTW0Vr.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, T as Tags, E as EPeersByDiscoveryEvents, f as EConnectionStateEvents } from './index-CTo1my9M.js';
|
4
|
+
import { B as BaseProtocol } from './base_protocol-DvQrudwy.js';
|
5
|
+
export { S as StreamManager } from './base_protocol-DvQrudwy.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$5 = 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$5.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$5.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$5.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$5.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$5.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$5.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$5.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$5.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$5.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$5.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$5.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$5.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$5.error("Received empty message");
|
2501
2501
|
return;
|
2502
2502
|
}
|
2503
2503
|
if (!pubsubTopic) {
|
2504
|
-
log$
|
2504
|
+
log$5.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$5.info("Receiving pipe closed.");
|
2511
2511
|
}, async (e) => {
|
2512
|
-
log$
|
2512
|
+
log$5.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$5.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 PushRpc {
|
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 PushRpc({
|
2534
2534
|
requestId: v4(),
|
2535
2535
|
request: {
|
2536
2536
|
message: message,
|
@@ -2540,11 +2540,11 @@ class PushRpcV2 {
|
|
2540
2540
|
});
|
2541
2541
|
}
|
2542
2542
|
static decode(bytes) {
|
2543
|
-
const res = PushRpc.decode(bytes);
|
2544
|
-
return new
|
2543
|
+
const res = PushRpc$1.decode(bytes);
|
2544
|
+
return new PushRpc(res);
|
2545
2545
|
}
|
2546
2546
|
encode() {
|
2547
|
-
return PushRpc.encode(this.proto);
|
2547
|
+
return PushRpc$1.encode(this.proto);
|
2548
2548
|
}
|
2549
2549
|
get query() {
|
2550
2550
|
return this.proto.request;
|
@@ -2571,260 +2571,18 @@ const isRLNResponseError = (info) => {
|
|
2571
2571
|
info.includes(RLN_MESSAGE_ID_PREFIX_ERROR) ||
|
2572
2572
|
info.includes(RLN_REMOTE_VALIDATION));
|
2573
2573
|
};
|
2574
|
-
/**
|
2575
|
-
* Maps error information from push response to appropriate ProtocolError
|
2576
|
-
* Uses pattern matching to handle various error cases
|
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
2574
|
|
2615
|
-
const log$
|
2575
|
+
const log$4 = new Logger("light-push");
|
2616
2576
|
const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
2617
|
-
|
2577
|
+
/**
|
2578
|
+
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
2579
|
+
*/
|
2618
2580
|
class LightPushCore extends BaseProtocol {
|
2619
2581
|
pubsubTopics;
|
2620
2582
|
constructor(pubsubTopics, libp2p) {
|
2621
2583
|
super(LightPushCodec, libp2p.components, pubsubTopics);
|
2622
2584
|
this.pubsubTopics = pubsubTopics;
|
2623
2585
|
}
|
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
|
-
}
|
2828
2586
|
async preparePushMessage(encoder, message) {
|
2829
2587
|
try {
|
2830
2588
|
if (!message.payload || message.payload.length === 0) {
|
@@ -2843,7 +2601,7 @@ class LightPushCoreV3 extends BaseProtocol {
|
|
2843
2601
|
error: ProtocolError.ENCODE_FAILED
|
2844
2602
|
};
|
2845
2603
|
}
|
2846
|
-
const query =
|
2604
|
+
const query = PushRpc.createRequest(protoMessage, encoder.pubsubTopic);
|
2847
2605
|
return { query, error: null };
|
2848
2606
|
}
|
2849
2607
|
catch (error) {
|
@@ -2884,6 +2642,7 @@ class LightPushCoreV3 extends BaseProtocol {
|
|
2884
2642
|
res = await pipe([query.encode()], encode, stream, decode, async (source) => await all(source));
|
2885
2643
|
}
|
2886
2644
|
catch (err) {
|
2645
|
+
// can fail only because of `stream` abortion
|
2887
2646
|
log$4.error("Failed to send waku light push request", err);
|
2888
2647
|
return {
|
2889
2648
|
success: null,
|
@@ -2899,10 +2658,10 @@ class LightPushCoreV3 extends BaseProtocol {
|
|
2899
2658
|
});
|
2900
2659
|
let response;
|
2901
2660
|
try {
|
2902
|
-
response =
|
2661
|
+
response = PushRpc.decode(bytes).response;
|
2903
2662
|
}
|
2904
2663
|
catch (err) {
|
2905
|
-
log$4.error("Failed to decode push
|
2664
|
+
log$4.error("Failed to decode push reply", err);
|
2906
2665
|
return {
|
2907
2666
|
success: null,
|
2908
2667
|
failure: {
|
@@ -2912,7 +2671,7 @@ class LightPushCoreV3 extends BaseProtocol {
|
|
2912
2671
|
};
|
2913
2672
|
}
|
2914
2673
|
if (!response) {
|
2915
|
-
log$4.error("Remote peer fault: No response
|
2674
|
+
log$4.error("Remote peer fault: No response in PushRPC");
|
2916
2675
|
return {
|
2917
2676
|
success: null,
|
2918
2677
|
failure: {
|
@@ -2921,37 +2680,7 @@ class LightPushCoreV3 extends BaseProtocol {
|
|
2921
2680
|
}
|
2922
2681
|
};
|
2923
2682
|
}
|
2924
|
-
|
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)) {
|
2683
|
+
if (isRLNResponseError(response.info)) {
|
2955
2684
|
log$4.error("Remote peer fault: RLN generation");
|
2956
2685
|
return {
|
2957
2686
|
success: null,
|
@@ -2961,14 +2690,12 @@ class LightPushCoreV3 extends BaseProtocol {
|
|
2961
2690
|
}
|
2962
2691
|
};
|
2963
2692
|
}
|
2964
|
-
if (!isSuccess) {
|
2965
|
-
|
2966
|
-
log$4.error("Remote peer rejected the message: ", errorMessage);
|
2967
|
-
const protocolError = lightPushStatusCodeToProtocolErrorV3(statusCode);
|
2693
|
+
if (!response.isSuccess) {
|
2694
|
+
log$4.error("Remote peer rejected the message: ", response.info);
|
2968
2695
|
return {
|
2969
2696
|
success: null,
|
2970
2697
|
failure: {
|
2971
|
-
error:
|
2698
|
+
error: ProtocolError.REMOTE_PEER_REJECTED,
|
2972
2699
|
peerId: peerId
|
2973
2700
|
}
|
2974
2701
|
};
|
@@ -2977,71 +2704,11 @@ class LightPushCoreV3 extends BaseProtocol {
|
|
2977
2704
|
}
|
2978
2705
|
}
|
2979
2706
|
|
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
|
-
|
3028
2707
|
var index$1 = /*#__PURE__*/Object.freeze({
|
3029
2708
|
__proto__: null,
|
3030
2709
|
LightPushCodec: LightPushCodec,
|
3031
|
-
LightPushCodecV2: LightPushCodecV2,
|
3032
2710
|
LightPushCore: LightPushCore,
|
3033
|
-
|
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
|
2711
|
+
get PushResponse () { return PushResponse; }
|
3045
2712
|
});
|
3046
2713
|
|
3047
2714
|
const EmptyMessage = {
|
@@ -4757,7 +4424,7 @@ class ConnectionManager extends TypedEventEmitter {
|
|
4757
4424
|
* // Dial using multiaddr with specific protocols
|
4758
4425
|
* await connectionManager.dialPeer(multiaddr, [
|
4759
4426
|
* "/vac/waku/relay/2.0.0",
|
4760
|
-
* "/vac/waku/lightpush/
|
4427
|
+
* "/vac/waku/lightpush/2.0.0-beta1"
|
4761
4428
|
* ]);
|
4762
4429
|
* ```
|
4763
4430
|
*
|
@@ -5306,4 +4973,4 @@ function messageHashStr(pubsubTopic, message) {
|
|
5306
4973
|
return hashStr;
|
5307
4974
|
}
|
5308
4975
|
|
5309
|
-
export { ConnectionManager, FilterCodecs, FilterCore, LightPushCodec,
|
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 };
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export { B as BaseProtocol } from '../base_protocol-
|
2
|
-
import '../index-
|
1
|
+
export { B as BaseProtocol } from '../base_protocol-DvQrudwy.js';
|
2
|
+
import '../index-CTo1my9M.js';
|