@highway1/cli 0.1.37 → 0.1.38
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/dist/index.js +59 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/join.ts +47 -43
- package/src/commands/send.ts +13 -1
package/dist/index.js
CHANGED
|
@@ -116490,11 +116490,15 @@ function createDHTOperations(libp2p) {
|
|
|
116490
116490
|
break;
|
|
116491
116491
|
}
|
|
116492
116492
|
}
|
|
116493
|
-
const caps = (card.capabilities ?? []).
|
|
116494
|
-
(
|
|
116495
|
-
|
|
116493
|
+
const caps = (card.capabilities ?? []).flatMap((c2) => {
|
|
116494
|
+
if (typeof c2 === "string") return [c2];
|
|
116495
|
+
return [c2.name, c2.id].filter(Boolean);
|
|
116496
|
+
});
|
|
116496
116497
|
caps.push("__all__");
|
|
116497
116498
|
const importantCaps = ["__all__"];
|
|
116499
|
+
if (caps.some((cap) => capKey(cap) === "relay")) {
|
|
116500
|
+
importantCaps.push("relay");
|
|
116501
|
+
}
|
|
116498
116502
|
await Promise.all(importantCaps.map(async (cap) => {
|
|
116499
116503
|
const capKeyStr = `/clawiverse/cap/${capKey(cap)}`;
|
|
116500
116504
|
const capDHTKey = fromString2(capKeyStr);
|
|
@@ -116774,13 +116778,13 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
|
|
|
116774
116778
|
} catch {
|
|
116775
116779
|
}
|
|
116776
116780
|
}
|
|
116781
|
+
let lastError;
|
|
116777
116782
|
if (!stream) {
|
|
116778
116783
|
const allRelayAddrs = [
|
|
116779
116784
|
...relayMultiaddrs,
|
|
116780
116785
|
...(relayPeers ?? []).map((r2) => buildCircuitRelayAddr(r2, targetPeerIdStr))
|
|
116781
116786
|
];
|
|
116782
116787
|
const uniqueRelayAddrs = [...new Set(allRelayAddrs)];
|
|
116783
|
-
let lastError;
|
|
116784
116788
|
for (const addr of uniqueRelayAddrs) {
|
|
116785
116789
|
try {
|
|
116786
116790
|
const conn = await libp2p.dial(multiaddr(addr));
|
|
@@ -116793,7 +116797,6 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
|
|
|
116793
116797
|
lastError = relayErr;
|
|
116794
116798
|
}
|
|
116795
116799
|
}
|
|
116796
|
-
if (!stream) throw lastError ?? new MessagingError("All dial attempts failed");
|
|
116797
116800
|
}
|
|
116798
116801
|
if (!stream && dht && "queryRelayPeers" in dht) {
|
|
116799
116802
|
const discoveredRelays = await dht.queryRelayPeers();
|
|
@@ -116806,9 +116809,12 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
|
|
|
116806
116809
|
break;
|
|
116807
116810
|
} catch (e2) {
|
|
116808
116811
|
logger5.warn("DHT relay failed", { relayAddr, error: e2.message });
|
|
116812
|
+
lastError = e2;
|
|
116809
116813
|
}
|
|
116810
116814
|
}
|
|
116811
|
-
|
|
116815
|
+
}
|
|
116816
|
+
if (!stream) {
|
|
116817
|
+
throw lastError ?? new MessagingError("All dial attempts failed (including DHT-discovered relays)");
|
|
116812
116818
|
}
|
|
116813
116819
|
const encoded = encodeMessage2(envelope);
|
|
116814
116820
|
await stream.sink(
|
|
@@ -116910,6 +116916,17 @@ async function handleIncomingStream(stream, handlers, catchAllHandler, _verifyFn
|
|
|
116910
116916
|
logger5.warn("Received invalid message envelope");
|
|
116911
116917
|
return;
|
|
116912
116918
|
}
|
|
116919
|
+
const isValidSignature = await verifyEnvelope(envelope, async (signature, data2) => {
|
|
116920
|
+
const senderPublicKey = extractPublicKey(envelope.from);
|
|
116921
|
+
return verify(signature, data2, senderPublicKey);
|
|
116922
|
+
});
|
|
116923
|
+
if (!isValidSignature) {
|
|
116924
|
+
logger5.warn("Received message with invalid signature", {
|
|
116925
|
+
id: envelope.id,
|
|
116926
|
+
from: envelope.from
|
|
116927
|
+
});
|
|
116928
|
+
return;
|
|
116929
|
+
}
|
|
116913
116930
|
logger5.info("Received message", {
|
|
116914
116931
|
id: envelope.id,
|
|
116915
116932
|
from: envelope.from,
|
|
@@ -118310,41 +118327,32 @@ function registerJoinCommand(program2) {
|
|
|
118310
118327
|
resolve();
|
|
118311
118328
|
}, { once: true });
|
|
118312
118329
|
});
|
|
118313
|
-
const
|
|
118314
|
-
|
|
118315
|
-
|
|
118316
|
-
|
|
118317
|
-
|
|
118318
|
-
|
|
118319
|
-
|
|
118320
|
-
|
|
118330
|
+
const countRelayAddrs = () => node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit")).length;
|
|
118331
|
+
const initialRelayCount = countRelayAddrs();
|
|
118332
|
+
info(`Initial relay addresses: ${initialRelayCount}`);
|
|
118333
|
+
info("Waiting for relay reservation...");
|
|
118334
|
+
let reservationSucceeded = false;
|
|
118335
|
+
await new Promise((resolve) => {
|
|
118336
|
+
const timeout = setTimeout(() => {
|
|
118337
|
+
if (!reservationSucceeded) {
|
|
118338
|
+
info(`Relay reservation timeout after 15s.`);
|
|
118321
118339
|
info(`Connected peers: ${node.libp2p.getPeers().map((p2) => p2.toString()).join(", ")}`);
|
|
118322
|
-
|
|
118323
|
-
|
|
118324
|
-
|
|
118325
|
-
|
|
118326
|
-
|
|
118327
|
-
|
|
118328
|
-
|
|
118329
|
-
|
|
118330
|
-
|
|
118331
|
-
|
|
118332
|
-
|
|
118333
|
-
|
|
118334
|
-
|
|
118335
|
-
|
|
118336
|
-
|
|
118337
|
-
|
|
118338
|
-
};
|
|
118339
|
-
node.libp2p.addEventListener("relay:reservation", onReservation, { once: true });
|
|
118340
|
-
node.libp2p.addEventListener("self:peer:update", onPeerUpdate);
|
|
118341
|
-
setTimeout(() => {
|
|
118342
|
-
node.libp2p.removeEventListener("relay:reservation", onReservation);
|
|
118343
|
-
node.libp2p.removeEventListener("self:peer:update", onPeerUpdate);
|
|
118344
|
-
}, 1e4);
|
|
118345
|
-
});
|
|
118346
|
-
} else {
|
|
118347
|
-
info(`Relay address already present: ${node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit")).join(", ")}`);
|
|
118340
|
+
}
|
|
118341
|
+
resolve();
|
|
118342
|
+
}, 15e3);
|
|
118343
|
+
const onReservation = (evt) => {
|
|
118344
|
+
reservationSucceeded = true;
|
|
118345
|
+
info(`\u2713 Relay reservation successful!`);
|
|
118346
|
+
clearTimeout(timeout);
|
|
118347
|
+
setTimeout(resolve, 500);
|
|
118348
|
+
};
|
|
118349
|
+
node.libp2p.addEventListener("relay:reservation", onReservation, { once: true });
|
|
118350
|
+
setTimeout(() => {
|
|
118351
|
+
node.libp2p.removeEventListener("relay:reservation", onReservation);
|
|
118352
|
+
}, 15e3);
|
|
118353
|
+
});
|
|
118354
|
+
if (!reservationSucceeded) {
|
|
118355
|
+
info("\u26A0 Relay reservation did not complete - using fallback relay addresses");
|
|
118348
118356
|
}
|
|
118349
118357
|
connectSpin.succeed("Connected to network!");
|
|
118350
118358
|
const cardSpin = spinner("Publishing Agent Card to DHT...");
|
|
@@ -118610,9 +118618,19 @@ function registerSendCommand(program2) {
|
|
|
118610
118618
|
spin.text = "Connecting to network...";
|
|
118611
118619
|
await identifyDone;
|
|
118612
118620
|
const dht = createDHTOperations(node.libp2p);
|
|
118621
|
+
const verifyFn = async (signature, data) => {
|
|
118622
|
+
try {
|
|
118623
|
+
const decoded = JSON.parse(new TextDecoder().decode(data));
|
|
118624
|
+
if (!decoded.from || typeof decoded.from !== "string") return false;
|
|
118625
|
+
const senderPublicKey = extractPublicKey(decoded.from);
|
|
118626
|
+
return verify(signature, data, senderPublicKey);
|
|
118627
|
+
} catch {
|
|
118628
|
+
return false;
|
|
118629
|
+
}
|
|
118630
|
+
};
|
|
118613
118631
|
const router = createMessageRouter(
|
|
118614
118632
|
node.libp2p,
|
|
118615
|
-
|
|
118633
|
+
verifyFn,
|
|
118616
118634
|
dht,
|
|
118617
118635
|
bootstrapPeers
|
|
118618
118636
|
);
|