@waku/core 0.0.36-b0a2e39.0 → 0.0.36-b4748fd.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
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 { x as createDecoder } from './version_0-
|
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;
|
@@ -2554,22 +2554,6 @@ class PushRpcV2 {
|
|
2554
2554
|
}
|
2555
2555
|
}
|
2556
2556
|
|
2557
|
-
const log$6 = new Logger("waku:light-push:utils");
|
2558
|
-
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
2559
|
-
/**
|
2560
|
-
* Validates a Light Push v3 request ID format.
|
2561
|
-
* Request IDs should be valid UUIDs, with special handling for "N/A" when rate limited.
|
2562
|
-
*
|
2563
|
-
* @param requestId - The request ID to validate
|
2564
|
-
* @returns true if the request ID is valid, false otherwise
|
2565
|
-
*/
|
2566
|
-
function isValidRequestId(requestId) {
|
2567
|
-
if (!requestId)
|
2568
|
-
return false;
|
2569
|
-
if (requestId === "N/A")
|
2570
|
-
return true; // Special case for rate-limited responses
|
2571
|
-
return UUID_REGEX.test(requestId);
|
2572
|
-
}
|
2573
2557
|
// should match nwaku
|
2574
2558
|
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/rln_relay.nim#L309
|
2575
2559
|
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim#L20
|
@@ -2587,61 +2571,12 @@ const isRLNResponseError = (info) => {
|
|
2587
2571
|
info.includes(RLN_MESSAGE_ID_PREFIX_ERROR) ||
|
2588
2572
|
info.includes(RLN_REMOTE_VALIDATION));
|
2589
2573
|
};
|
2590
|
-
function mapInfoToProtocolError(info) {
|
2591
|
-
if (!info) {
|
2592
|
-
return ProtocolError.REMOTE_PEER_REJECTED;
|
2593
|
-
}
|
2594
|
-
const lowerInfo = info.toLowerCase();
|
2595
|
-
if (isRLNResponseError(info)) {
|
2596
|
-
return ProtocolError.RLN_PROOF_GENERATION;
|
2597
|
-
}
|
2598
|
-
if (lowerInfo.includes("rate limit") ||
|
2599
|
-
lowerInfo.includes("too many requests")) {
|
2600
|
-
return ProtocolError.REMOTE_PEER_REJECTED;
|
2601
|
-
}
|
2602
|
-
if (lowerInfo.includes("topic") &&
|
2603
|
-
(lowerInfo.includes("not found") || lowerInfo.includes("not configured"))) {
|
2604
|
-
return ProtocolError.TOPIC_NOT_CONFIGURED;
|
2605
|
-
}
|
2606
|
-
if (lowerInfo.includes("too large") || lowerInfo.includes("size")) {
|
2607
|
-
return ProtocolError.SIZE_TOO_BIG;
|
2608
|
-
}
|
2609
|
-
if (lowerInfo.includes("decode") ||
|
2610
|
-
lowerInfo.includes("invalid") ||
|
2611
|
-
lowerInfo.includes("malformed")) {
|
2612
|
-
return ProtocolError.DECODE_FAILED;
|
2613
|
-
}
|
2614
|
-
if (lowerInfo.includes("empty") && lowerInfo.includes("payload")) {
|
2615
|
-
return ProtocolError.EMPTY_PAYLOAD;
|
2616
|
-
}
|
2617
|
-
return ProtocolError.REMOTE_PEER_REJECTED;
|
2618
|
-
}
|
2619
|
-
/**
|
2620
|
-
* Validates that a message conforms to Light Push protocol requirements.
|
2621
|
-
*
|
2622
|
-
* @param message - The message to validate
|
2623
|
-
* @param encoder - The encoder to use for message size validation
|
2624
|
-
* @returns A ProtocolError if validation fails, null if the message is valid
|
2625
|
-
*
|
2626
|
-
* @remarks
|
2627
|
-
* This function performs the following validations:
|
2628
|
-
* - Checks if the message payload exists and is not empty
|
2629
|
-
* - Verifies the encoded message size is under the network cap (1MB)
|
2630
|
-
*/
|
2631
|
-
async function validateMessage(message, encoder) {
|
2632
|
-
if (!message.payload?.length) {
|
2633
|
-
log$6.error("Failed to send waku light push: payload is empty");
|
2634
|
-
return ProtocolError.EMPTY_PAYLOAD;
|
2635
|
-
}
|
2636
|
-
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
2637
|
-
log$6.error("Failed to send waku light push: message is bigger than 1MB");
|
2638
|
-
return ProtocolError.SIZE_TOO_BIG;
|
2639
|
-
}
|
2640
|
-
return null;
|
2641
|
-
}
|
2642
2574
|
|
2643
|
-
const log$
|
2575
|
+
const log$4 = new Logger("light-push");
|
2644
2576
|
const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
2577
|
+
/**
|
2578
|
+
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
2579
|
+
*/
|
2645
2580
|
class LightPushCore extends BaseProtocol {
|
2646
2581
|
pubsubTopics;
|
2647
2582
|
constructor(pubsubTopics, libp2p) {
|
@@ -2650,23 +2585,27 @@ class LightPushCore extends BaseProtocol {
|
|
2650
2585
|
}
|
2651
2586
|
async preparePushMessage(encoder, message) {
|
2652
2587
|
try {
|
2653
|
-
|
2654
|
-
|
2655
|
-
return { query: null, error:
|
2588
|
+
if (!message.payload || message.payload.length === 0) {
|
2589
|
+
log$4.error("Failed to send waku light push: payload is empty");
|
2590
|
+
return { query: null, error: ProtocolError.EMPTY_PAYLOAD };
|
2591
|
+
}
|
2592
|
+
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
2593
|
+
log$4.error("Failed to send waku light push: message is bigger than 1MB");
|
2594
|
+
return { query: null, error: ProtocolError.SIZE_TOO_BIG };
|
2656
2595
|
}
|
2657
2596
|
const protoMessage = await encoder.toProtoObj(message);
|
2658
2597
|
if (!protoMessage) {
|
2659
|
-
log$
|
2598
|
+
log$4.error("Failed to encode to protoMessage, aborting push");
|
2660
2599
|
return {
|
2661
2600
|
query: null,
|
2662
2601
|
error: ProtocolError.ENCODE_FAILED
|
2663
2602
|
};
|
2664
2603
|
}
|
2665
|
-
const query =
|
2604
|
+
const query = PushRpc.createRequest(protoMessage, encoder.pubsubTopic);
|
2666
2605
|
return { query, error: null };
|
2667
2606
|
}
|
2668
2607
|
catch (error) {
|
2669
|
-
log$
|
2608
|
+
log$4.error("Failed to prepare push message", error);
|
2670
2609
|
return {
|
2671
2610
|
query: null,
|
2672
2611
|
error: ProtocolError.GENERIC_FAIL
|
@@ -2689,7 +2628,7 @@ class LightPushCore extends BaseProtocol {
|
|
2689
2628
|
stream = await this.getStream(peerId);
|
2690
2629
|
}
|
2691
2630
|
catch (error) {
|
2692
|
-
log$
|
2631
|
+
log$4.error("Failed to get stream", error);
|
2693
2632
|
return {
|
2694
2633
|
success: null,
|
2695
2634
|
failure: {
|
@@ -2703,7 +2642,8 @@ class LightPushCore extends BaseProtocol {
|
|
2703
2642
|
res = await pipe([query.encode()], encode, stream, decode, async (source) => await all(source));
|
2704
2643
|
}
|
2705
2644
|
catch (err) {
|
2706
|
-
|
2645
|
+
// can fail only because of `stream` abortion
|
2646
|
+
log$4.error("Failed to send waku light push request", err);
|
2707
2647
|
return {
|
2708
2648
|
success: null,
|
2709
2649
|
failure: {
|
@@ -2712,16 +2652,16 @@ class LightPushCore extends BaseProtocol {
|
|
2712
2652
|
}
|
2713
2653
|
};
|
2714
2654
|
}
|
2715
|
-
const bytes =
|
2716
|
-
|
2717
|
-
|
2718
|
-
}
|
2655
|
+
const bytes = new Uint8ArrayList();
|
2656
|
+
res.forEach((chunk) => {
|
2657
|
+
bytes.append(chunk);
|
2658
|
+
});
|
2719
2659
|
let response;
|
2720
2660
|
try {
|
2721
|
-
response =
|
2661
|
+
response = PushRpc.decode(bytes).response;
|
2722
2662
|
}
|
2723
2663
|
catch (err) {
|
2724
|
-
log$
|
2664
|
+
log$4.error("Failed to decode push reply", err);
|
2725
2665
|
return {
|
2726
2666
|
success: null,
|
2727
2667
|
failure: {
|
@@ -2731,7 +2671,7 @@ class LightPushCore extends BaseProtocol {
|
|
2731
2671
|
};
|
2732
2672
|
}
|
2733
2673
|
if (!response) {
|
2734
|
-
log$
|
2674
|
+
log$4.error("Remote peer fault: No response in PushRPC");
|
2735
2675
|
return {
|
2736
2676
|
success: null,
|
2737
2677
|
failure: {
|
@@ -2740,229 +2680,27 @@ class LightPushCore extends BaseProtocol {
|
|
2740
2680
|
}
|
2741
2681
|
};
|
2742
2682
|
}
|
2743
|
-
if (
|
2744
|
-
|
2745
|
-
log$5.error("Remote peer rejected the message: ", errorMessage);
|
2746
|
-
const error = mapInfoToProtocolError(response.info);
|
2683
|
+
if (isRLNResponseError(response.info)) {
|
2684
|
+
log$4.error("Remote peer fault: RLN generation");
|
2747
2685
|
return {
|
2748
2686
|
success: null,
|
2749
2687
|
failure: {
|
2750
|
-
error:
|
2688
|
+
error: ProtocolError.RLN_PROOF_GENERATION,
|
2751
2689
|
peerId: peerId
|
2752
2690
|
}
|
2753
2691
|
};
|
2754
2692
|
}
|
2755
|
-
|
2756
|
-
|
2757
|
-
|
2758
|
-
|
2759
|
-
|
2760
|
-
|
2761
|
-
|
2762
|
-
|
2763
|
-
|
2764
|
-
response;
|
2765
|
-
constructor(request, response) {
|
2766
|
-
this.request = request;
|
2767
|
-
this.response = response;
|
2768
|
-
}
|
2769
|
-
static createRequest(message, pubsubTopic) {
|
2770
|
-
const request = {
|
2771
|
-
requestId: v4(),
|
2772
|
-
message: message,
|
2773
|
-
...(pubsubTopic && { pubsubTopic })
|
2774
|
-
};
|
2775
|
-
return new PushRpcV3(request, undefined);
|
2776
|
-
}
|
2777
|
-
static decode(bytes) {
|
2778
|
-
const response = LightpushResponse.decode(bytes);
|
2779
|
-
return new PushRpcV3(undefined, response);
|
2780
|
-
}
|
2781
|
-
encode() {
|
2782
|
-
if (!this.request) {
|
2783
|
-
throw new Error("Cannot encode without a request");
|
2784
|
-
}
|
2785
|
-
return LightpushRequest.encode(this.request);
|
2786
|
-
}
|
2787
|
-
get query() {
|
2788
|
-
return this.request;
|
2789
|
-
}
|
2790
|
-
}
|
2791
|
-
|
2792
|
-
const log$4 = new Logger("light-push-v3");
|
2793
|
-
const STREAM_TIMEOUT_MS = 30000;
|
2794
|
-
class LightPushError extends Error {
|
2795
|
-
protocol;
|
2796
|
-
peerId;
|
2797
|
-
response;
|
2798
|
-
constructor(protocol, peerId, response, message) {
|
2799
|
-
super(message || protocol);
|
2800
|
-
this.protocol = protocol;
|
2801
|
-
this.peerId = peerId;
|
2802
|
-
this.response = response;
|
2803
|
-
this.name = "LightPushError";
|
2804
|
-
}
|
2805
|
-
}
|
2806
|
-
function withTimeout(promise, timeoutMs) {
|
2807
|
-
return Promise.race([
|
2808
|
-
promise,
|
2809
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error("Stream operation timed out")), timeoutMs))
|
2810
|
-
]);
|
2811
|
-
}
|
2812
|
-
function createSuccessResult(peerId, response) {
|
2813
|
-
return {
|
2814
|
-
success: peerId,
|
2815
|
-
failure: null,
|
2816
|
-
requestId: response.requestId,
|
2817
|
-
statusCode: response.statusCode,
|
2818
|
-
statusDesc: response.statusDesc,
|
2819
|
-
relayPeerCount: response.relayPeerCount
|
2820
|
-
};
|
2821
|
-
}
|
2822
|
-
function createFailureResult(error) {
|
2823
|
-
const result = {
|
2824
|
-
success: null,
|
2825
|
-
failure: {
|
2826
|
-
error: error.protocol,
|
2827
|
-
peerId: error.peerId
|
2828
|
-
}
|
2829
|
-
};
|
2830
|
-
if (error.response) {
|
2831
|
-
result.requestId = error.response.requestId;
|
2832
|
-
result.statusCode = error.response.statusCode;
|
2833
|
-
result.statusDesc = error.response.statusDesc;
|
2834
|
-
result.relayPeerCount = error.response.relayPeerCount;
|
2835
|
-
}
|
2836
|
-
return result;
|
2837
|
-
}
|
2838
|
-
function validateResponseSemantics(response, query, peerId) {
|
2839
|
-
if (!isValidRequestId(response.requestId)) {
|
2840
|
-
log$4.error("Invalid request ID format", { received: response.requestId });
|
2841
|
-
throw new LightPushError(ProtocolError.DECODE_FAILED, peerId, response, "Invalid request ID format");
|
2842
|
-
}
|
2843
|
-
if (response.requestId !== query.query?.requestId &&
|
2844
|
-
response.statusCode !== LightPushStatusCodeV3.TOO_MANY_REQUESTS) {
|
2845
|
-
log$4.error("Request ID mismatch", {
|
2846
|
-
sent: query.query?.requestId,
|
2847
|
-
received: response.requestId
|
2848
|
-
});
|
2849
|
-
throw new LightPushError(ProtocolError.GENERIC_FAIL, peerId, response, "Request ID mismatch");
|
2850
|
-
}
|
2851
|
-
if (response.statusDesc && isRLNResponseError(response.statusDesc)) {
|
2852
|
-
log$4.error("Remote peer fault: RLN generation");
|
2853
|
-
throw new LightPushError(ProtocolError.RLN_PROOF_GENERATION, peerId, response, "RLN proof generation failed");
|
2854
|
-
}
|
2855
|
-
}
|
2856
|
-
function ensureSuccessStatus(response, peerId) {
|
2857
|
-
if (!isSuccessStatusCodeV3(response.statusCode)) {
|
2858
|
-
const errorMessage = getLightPushStatusDescriptionV3(response.statusCode, response.statusDesc);
|
2859
|
-
log$4.error("Remote peer rejected the message:", errorMessage);
|
2860
|
-
const protocolError = lightPushStatusCodeToProtocolErrorV3(response.statusCode);
|
2861
|
-
throw new LightPushError(protocolError, peerId, response, errorMessage);
|
2862
|
-
}
|
2863
|
-
}
|
2864
|
-
function logResponseInfo(response) {
|
2865
|
-
if (response.statusCode === LightPushStatusCodeV3.TOO_MANY_REQUESTS) {
|
2866
|
-
if (response.requestId === "N/A") {
|
2867
|
-
log$4.warn("Rate limited by nwaku node", {
|
2868
|
-
statusDesc: response.statusDesc || "Request rejected due to too many requests"
|
2869
|
-
});
|
2870
|
-
}
|
2871
|
-
}
|
2872
|
-
if (response.relayPeerCount !== undefined) {
|
2873
|
-
log$4.info(`Message relayed to ${response.relayPeerCount} peers`);
|
2874
|
-
}
|
2875
|
-
}
|
2876
|
-
class LightPushCoreV3 extends BaseProtocol {
|
2877
|
-
pubsubTopics;
|
2878
|
-
constructor(pubsubTopics, libp2p) {
|
2879
|
-
super(LightPushCodecV3, libp2p.components, pubsubTopics);
|
2880
|
-
this.pubsubTopics = pubsubTopics;
|
2881
|
-
}
|
2882
|
-
async send(encoder, message, peerId) {
|
2883
|
-
try {
|
2884
|
-
const validated = await this.validateAndPrepareMessage(encoder, message, peerId);
|
2885
|
-
const streamResponse = await this.executeRequest(validated, peerId);
|
2886
|
-
const finalResponse = this.processResponse(streamResponse, peerId);
|
2887
|
-
logResponseInfo(finalResponse);
|
2888
|
-
return createSuccessResult(peerId, finalResponse);
|
2889
|
-
}
|
2890
|
-
catch (error) {
|
2891
|
-
if (error instanceof LightPushError) {
|
2892
|
-
return createFailureResult(error);
|
2893
|
-
}
|
2894
|
-
log$4.error("Unexpected error in send", error);
|
2895
|
-
return createFailureResult(new LightPushError(ProtocolError.GENERIC_FAIL, peerId));
|
2896
|
-
}
|
2897
|
-
}
|
2898
|
-
async validateAndPrepareMessage(encoder, message, peerId) {
|
2899
|
-
const validationError = await validateMessage(message, encoder);
|
2900
|
-
if (validationError) {
|
2901
|
-
throw new LightPushError(validationError, peerId);
|
2902
|
-
}
|
2903
|
-
const protoMessage = await encoder.toProtoObj(message);
|
2904
|
-
if (!protoMessage) {
|
2905
|
-
log$4.error("Failed to encode to protoMessage, aborting push");
|
2906
|
-
throw new LightPushError(ProtocolError.ENCODE_FAILED, peerId);
|
2907
|
-
}
|
2908
|
-
const query = PushRpcV3.createRequest(protoMessage, encoder.pubsubTopic);
|
2909
|
-
return { protoMessage: protoMessage, query };
|
2910
|
-
}
|
2911
|
-
async executeRequest(validated, peerId) {
|
2912
|
-
const stream = await this.acquireStream(peerId);
|
2913
|
-
try {
|
2914
|
-
const rawResponse = await this.sendAndReceive(validated.query, stream);
|
2915
|
-
const response = this.decodeResponse(rawResponse, peerId);
|
2916
|
-
return { response, query: validated.query };
|
2917
|
-
}
|
2918
|
-
finally {
|
2919
|
-
void stream.close();
|
2920
|
-
}
|
2921
|
-
}
|
2922
|
-
processResponse(streamResponse, peerId) {
|
2923
|
-
const { response, query } = streamResponse;
|
2924
|
-
validateResponseSemantics(response, query, peerId);
|
2925
|
-
ensureSuccessStatus(response, peerId);
|
2926
|
-
return response;
|
2927
|
-
}
|
2928
|
-
async acquireStream(peerId) {
|
2929
|
-
try {
|
2930
|
-
return await this.getStream(peerId);
|
2931
|
-
}
|
2932
|
-
catch (error) {
|
2933
|
-
log$4.error("Failed to get stream", error);
|
2934
|
-
throw new LightPushError(ProtocolError.NO_STREAM_AVAILABLE, peerId);
|
2935
|
-
}
|
2936
|
-
}
|
2937
|
-
async sendAndReceive(query, stream) {
|
2938
|
-
try {
|
2939
|
-
return await withTimeout(pipe([query.encode()], encode, stream, decode, async (source) => await all(source)), STREAM_TIMEOUT_MS);
|
2940
|
-
}
|
2941
|
-
catch (err) {
|
2942
|
-
log$4.error("Failed to send waku light push request", err);
|
2943
|
-
throw new Error("Stream operation failed");
|
2944
|
-
}
|
2945
|
-
}
|
2946
|
-
decodeResponse(rawResponse, peerId) {
|
2947
|
-
const bytes = rawResponse.reduce((acc, chunk) => {
|
2948
|
-
acc.append(chunk);
|
2949
|
-
return acc;
|
2950
|
-
}, new Uint8ArrayList());
|
2951
|
-
try {
|
2952
|
-
const response = LightpushResponse.decode(bytes);
|
2953
|
-
if (!response) {
|
2954
|
-
log$4.error("Remote peer fault: No response received");
|
2955
|
-
throw new LightPushError(ProtocolError.NO_RESPONSE, peerId);
|
2956
|
-
}
|
2957
|
-
return response;
|
2958
|
-
}
|
2959
|
-
catch (err) {
|
2960
|
-
if (err instanceof LightPushError) {
|
2961
|
-
throw err;
|
2962
|
-
}
|
2963
|
-
log$4.error("Failed to decode push response", err);
|
2964
|
-
throw new LightPushError(ProtocolError.DECODE_FAILED, peerId);
|
2693
|
+
if (!response.isSuccess) {
|
2694
|
+
log$4.error("Remote peer rejected the message: ", response.info);
|
2695
|
+
return {
|
2696
|
+
success: null,
|
2697
|
+
failure: {
|
2698
|
+
error: ProtocolError.REMOTE_PEER_REJECTED,
|
2699
|
+
peerId: peerId
|
2700
|
+
}
|
2701
|
+
};
|
2965
2702
|
}
|
2703
|
+
return { success: peerId, failure: null };
|
2966
2704
|
}
|
2967
2705
|
}
|
2968
2706
|
|
@@ -2970,7 +2708,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
2970
2708
|
__proto__: null,
|
2971
2709
|
LightPushCodec: LightPushCodec,
|
2972
2710
|
LightPushCore: LightPushCore,
|
2973
|
-
|
2711
|
+
get PushResponse () { return PushResponse; }
|
2974
2712
|
});
|
2975
2713
|
|
2976
2714
|
const EmptyMessage = {
|
@@ -4686,7 +4424,7 @@ class ConnectionManager extends TypedEventEmitter {
|
|
4686
4424
|
* // Dial using multiaddr with specific protocols
|
4687
4425
|
* await connectionManager.dialPeer(multiaddr, [
|
4688
4426
|
* "/vac/waku/relay/2.0.0",
|
4689
|
-
* "/vac/waku/lightpush/
|
4427
|
+
* "/vac/waku/lightpush/2.0.0-beta1"
|
4690
4428
|
* ]);
|
4691
4429
|
* ```
|
4692
4430
|
*
|
@@ -5235,4 +4973,4 @@ function messageHashStr(pubsubTopic, message) {
|
|
5235
4973
|
return hashStr;
|
5236
4974
|
}
|
5237
4975
|
|
5238
|
-
export { ConnectionManager, FilterCodecs, FilterCore, LightPushCodec, LightPushCore,
|
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';
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export { D as DecodedMessage, z as Decoder, E as Encoder, V as Version, x as createDecoder, k as createEncoder, y as proto } from '../../version_0-
|
2
|
-
import '../../index-
|
1
|
+
export { D as DecodedMessage, z as Decoder, E as Encoder, V as Version, x as createDecoder, k as createEncoder, y as proto } from '../../version_0-CyeTW0Vr.js';
|
2
|
+
import '../../index-CTo1my9M.js';
|