@waku/core 0.0.36-acc9100.0 → 0.0.36-b0a2e39.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-DEDdl6tx.js} +1 -1
- package/bundle/{index-CTo1my9M.js → index-DckUzRoN.js} +80 -1
- package/bundle/index.js +330 -68
- 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-DyRL7WVV.js} +370 -32
- 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 +2 -1
- package/dist/lib/light_push/index.js +2 -1
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/light_push.d.ts +2 -7
- package/dist/lib/light_push/light_push.js +19 -35
- package/dist/lib/light_push/light_push.js.map +1 -1
- package/dist/lib/light_push/light_push_v3.d.ts +14 -0
- package/dist/lib/light_push/light_push_v3.js +187 -0
- package/dist/lib/light_push/light_push_v3.js.map +1 -0
- package/dist/lib/light_push/{push_rpc.d.ts → push_rpc_v2.d.ts} +3 -3
- package/dist/lib/light_push/{push_rpc.js → push_rpc_v2.js} +4 -4
- 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 +32 -0
- package/dist/lib/light_push/push_rpc_v3.js.map +1 -0
- package/dist/lib/light_push/utils.d.ts +24 -0
- package/dist/lib/light_push/utils.js +70 -0
- package/dist/lib/light_push/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +5 -1
- package/src/lib/connection_manager/connection_manager.ts +1 -1
- package/src/lib/light_push/index.ts +2 -1
- package/src/lib/light_push/light_push.ts +26 -43
- package/src/lib/light_push/light_push_v3.ts +319 -0
- package/src/lib/light_push/{push_rpc.ts → push_rpc_v2.ts} +5 -5
- package/src/lib/light_push/push_rpc_v3.ts +45 -0
- package/src/lib/light_push/utils.ts +95 -0
- package/dist/lib/light_push/push_rpc.js.map +0 -1
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, 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, 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-DyRL7WVV.js';
|
2
|
+
export { x as createDecoder } from './version_0-DyRL7WVV.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 LightPushCodecV3, g as LightPushStatusCodeV3, i as isSuccessStatusCodeV3, h as getLightPushStatusDescriptionV3, l as lightPushStatusCodeToProtocolErrorV3, T as Tags, E as EPeersByDiscoveryEvents, j as EConnectionStateEvents } from './index-DckUzRoN.js';
|
4
|
+
import { B as BaseProtocol } from './base_protocol-DEDdl6tx.js';
|
5
|
+
export { S as StreamManager } from './base_protocol-DEDdl6tx.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$7 = 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$7.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$7.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$7.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$7.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$7.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$7.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$7.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$7.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$7.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$7.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$7.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$7.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$7.error("Received empty message");
|
2501
2501
|
return;
|
2502
2502
|
}
|
2503
2503
|
if (!pubsubTopic) {
|
2504
|
-
log$
|
2504
|
+
log$7.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$7.info("Receiving pipe closed.");
|
2511
2511
|
}, async (e) => {
|
2512
|
-
log$
|
2512
|
+
log$7.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$7.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;
|
@@ -2554,6 +2554,22 @@ class PushRpc {
|
|
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
|
+
}
|
2557
2573
|
// should match nwaku
|
2558
2574
|
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/rln_relay.nim#L309
|
2559
2575
|
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim#L20
|
@@ -2571,12 +2587,61 @@ const isRLNResponseError = (info) => {
|
|
2571
2587
|
info.includes(RLN_MESSAGE_ID_PREFIX_ERROR) ||
|
2572
2588
|
info.includes(RLN_REMOTE_VALIDATION));
|
2573
2589
|
};
|
2574
|
-
|
2575
|
-
|
2576
|
-
|
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
|
+
}
|
2577
2619
|
/**
|
2578
|
-
*
|
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)
|
2579
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
|
+
|
2643
|
+
const log$5 = new Logger("light-push");
|
2644
|
+
const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
2580
2645
|
class LightPushCore extends BaseProtocol {
|
2581
2646
|
pubsubTopics;
|
2582
2647
|
constructor(pubsubTopics, libp2p) {
|
@@ -2585,27 +2650,23 @@ class LightPushCore extends BaseProtocol {
|
|
2585
2650
|
}
|
2586
2651
|
async preparePushMessage(encoder, message) {
|
2587
2652
|
try {
|
2588
|
-
|
2589
|
-
|
2590
|
-
return { query: null, error:
|
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 };
|
2653
|
+
const validationError = await validateMessage(message, encoder);
|
2654
|
+
if (validationError) {
|
2655
|
+
return { query: null, error: validationError };
|
2595
2656
|
}
|
2596
2657
|
const protoMessage = await encoder.toProtoObj(message);
|
2597
2658
|
if (!protoMessage) {
|
2598
|
-
log$
|
2659
|
+
log$5.error("Failed to encode to protoMessage, aborting push");
|
2599
2660
|
return {
|
2600
2661
|
query: null,
|
2601
2662
|
error: ProtocolError.ENCODE_FAILED
|
2602
2663
|
};
|
2603
2664
|
}
|
2604
|
-
const query =
|
2665
|
+
const query = PushRpcV2.createRequest(protoMessage, encoder.pubsubTopic);
|
2605
2666
|
return { query, error: null };
|
2606
2667
|
}
|
2607
2668
|
catch (error) {
|
2608
|
-
log$
|
2669
|
+
log$5.error("Failed to prepare push message", error);
|
2609
2670
|
return {
|
2610
2671
|
query: null,
|
2611
2672
|
error: ProtocolError.GENERIC_FAIL
|
@@ -2628,7 +2689,7 @@ class LightPushCore extends BaseProtocol {
|
|
2628
2689
|
stream = await this.getStream(peerId);
|
2629
2690
|
}
|
2630
2691
|
catch (error) {
|
2631
|
-
log$
|
2692
|
+
log$5.error("Failed to get stream", error);
|
2632
2693
|
return {
|
2633
2694
|
success: null,
|
2634
2695
|
failure: {
|
@@ -2642,8 +2703,7 @@ class LightPushCore extends BaseProtocol {
|
|
2642
2703
|
res = await pipe([query.encode()], encode, stream, decode, async (source) => await all(source));
|
2643
2704
|
}
|
2644
2705
|
catch (err) {
|
2645
|
-
|
2646
|
-
log$4.error("Failed to send waku light push request", err);
|
2706
|
+
log$5.error("Failed to send waku light push request", err);
|
2647
2707
|
return {
|
2648
2708
|
success: null,
|
2649
2709
|
failure: {
|
@@ -2652,16 +2712,16 @@ class LightPushCore extends BaseProtocol {
|
|
2652
2712
|
}
|
2653
2713
|
};
|
2654
2714
|
}
|
2655
|
-
const bytes =
|
2656
|
-
|
2657
|
-
|
2658
|
-
});
|
2715
|
+
const bytes = res.reduce((acc, chunk) => {
|
2716
|
+
acc.append(chunk);
|
2717
|
+
return acc;
|
2718
|
+
}, new Uint8ArrayList());
|
2659
2719
|
let response;
|
2660
2720
|
try {
|
2661
|
-
response =
|
2721
|
+
response = PushRpcV2.decode(bytes).response;
|
2662
2722
|
}
|
2663
2723
|
catch (err) {
|
2664
|
-
log$
|
2724
|
+
log$5.error("Failed to decode push reply", err);
|
2665
2725
|
return {
|
2666
2726
|
success: null,
|
2667
2727
|
failure: {
|
@@ -2671,7 +2731,7 @@ class LightPushCore extends BaseProtocol {
|
|
2671
2731
|
};
|
2672
2732
|
}
|
2673
2733
|
if (!response) {
|
2674
|
-
log$
|
2734
|
+
log$5.error("Remote peer fault: No response in PushRPC");
|
2675
2735
|
return {
|
2676
2736
|
success: null,
|
2677
2737
|
failure: {
|
@@ -2680,27 +2740,229 @@ class LightPushCore extends BaseProtocol {
|
|
2680
2740
|
}
|
2681
2741
|
};
|
2682
2742
|
}
|
2683
|
-
if (isRLNResponseError(response.info)) {
|
2684
|
-
log$4.error("Remote peer fault: RLN generation");
|
2685
|
-
return {
|
2686
|
-
success: null,
|
2687
|
-
failure: {
|
2688
|
-
error: ProtocolError.RLN_PROOF_GENERATION,
|
2689
|
-
peerId: peerId
|
2690
|
-
}
|
2691
|
-
};
|
2692
|
-
}
|
2693
2743
|
if (!response.isSuccess) {
|
2694
|
-
|
2744
|
+
const errorMessage = response.info || "Message rejected";
|
2745
|
+
log$5.error("Remote peer rejected the message: ", errorMessage);
|
2746
|
+
const error = mapInfoToProtocolError(response.info);
|
2695
2747
|
return {
|
2696
2748
|
success: null,
|
2697
2749
|
failure: {
|
2698
|
-
error:
|
2750
|
+
error: error,
|
2699
2751
|
peerId: peerId
|
2700
2752
|
}
|
2701
2753
|
};
|
2702
2754
|
}
|
2703
|
-
return {
|
2755
|
+
return {
|
2756
|
+
success: peerId,
|
2757
|
+
failure: null
|
2758
|
+
};
|
2759
|
+
}
|
2760
|
+
}
|
2761
|
+
|
2762
|
+
class PushRpcV3 {
|
2763
|
+
request;
|
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);
|
2965
|
+
}
|
2704
2966
|
}
|
2705
2967
|
}
|
2706
2968
|
|
@@ -2708,7 +2970,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
2708
2970
|
__proto__: null,
|
2709
2971
|
LightPushCodec: LightPushCodec,
|
2710
2972
|
LightPushCore: LightPushCore,
|
2711
|
-
|
2973
|
+
LightPushCoreV3: LightPushCoreV3
|
2712
2974
|
});
|
2713
2975
|
|
2714
2976
|
const EmptyMessage = {
|
@@ -4424,7 +4686,7 @@ class ConnectionManager extends TypedEventEmitter {
|
|
4424
4686
|
* // Dial using multiaddr with specific protocols
|
4425
4687
|
* await connectionManager.dialPeer(multiaddr, [
|
4426
4688
|
* "/vac/waku/relay/2.0.0",
|
4427
|
-
* "/vac/waku/lightpush/
|
4689
|
+
* "/vac/waku/lightpush/3.0.0"
|
4428
4690
|
* ]);
|
4429
4691
|
* ```
|
4430
4692
|
*
|
@@ -4973,4 +5235,4 @@ function messageHashStr(pubsubTopic, message) {
|
|
4973
5235
|
return hashStr;
|
4974
5236
|
}
|
4975
5237
|
|
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 };
|
5238
|
+
export { ConnectionManager, FilterCodecs, FilterCore, LightPushCodec, LightPushCore, 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-DEDdl6tx.js';
|
2
|
+
import '../index-DckUzRoN.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-DyRL7WVV.js';
|
2
|
+
import '../../index-DckUzRoN.js';
|