@highway1/cli 0.1.37 → 0.1.39
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 +103 -45
- package/dist/index.js.map +1 -1
- package/package.json +9 -21
- package/bin/clawiverse.js +0 -2
- package/src/commands/card.ts +0 -99
- package/src/commands/discover.ts +0 -168
- package/src/commands/identity.ts +0 -37
- package/src/commands/init.ts +0 -54
- package/src/commands/join.ts +0 -243
- package/src/commands/send.ts +0 -148
- package/src/commands/status.ts +0 -45
- package/src/commands/trust.ts +0 -215
- package/src/config.ts +0 -74
- package/src/index.ts +0 -49
- package/src/ui.ts +0 -38
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(
|
|
@@ -116891,7 +116897,7 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
|
|
|
116891
116897
|
function buildCircuitRelayAddr(relayAddr, targetPeerId) {
|
|
116892
116898
|
return `${relayAddr}/p2p-circuit/p2p/${targetPeerId}`;
|
|
116893
116899
|
}
|
|
116894
|
-
async function handleIncomingStream(stream, handlers, catchAllHandler,
|
|
116900
|
+
async function handleIncomingStream(stream, handlers, catchAllHandler, verifyFn) {
|
|
116895
116901
|
try {
|
|
116896
116902
|
const chunks = [];
|
|
116897
116903
|
for await (const chunk of stream.source) {
|
|
@@ -116910,6 +116916,37 @@ 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
|
+
}
|
|
116930
|
+
try {
|
|
116931
|
+
const { signature, ...envelopeWithoutSig } = envelope;
|
|
116932
|
+
const dataBytes = new TextEncoder().encode(JSON.stringify(envelopeWithoutSig));
|
|
116933
|
+
const signatureBytes = Buffer.from(signature, "hex");
|
|
116934
|
+
const hookValid = await verifyFn(signatureBytes, dataBytes);
|
|
116935
|
+
if (!hookValid) {
|
|
116936
|
+
logger5.warn("Message rejected by custom verifier", {
|
|
116937
|
+
id: envelope.id,
|
|
116938
|
+
from: envelope.from
|
|
116939
|
+
});
|
|
116940
|
+
return;
|
|
116941
|
+
}
|
|
116942
|
+
} catch (error2) {
|
|
116943
|
+
logger5.warn("Custom verification hook failed", {
|
|
116944
|
+
id: envelope.id,
|
|
116945
|
+
from: envelope.from,
|
|
116946
|
+
error: error2.message
|
|
116947
|
+
});
|
|
116948
|
+
return;
|
|
116949
|
+
}
|
|
116913
116950
|
logger5.info("Received message", {
|
|
116914
116951
|
id: envelope.id,
|
|
116915
116952
|
from: envelope.from,
|
|
@@ -118310,41 +118347,32 @@ function registerJoinCommand(program2) {
|
|
|
118310
118347
|
resolve();
|
|
118311
118348
|
}, { once: true });
|
|
118312
118349
|
});
|
|
118313
|
-
const
|
|
118314
|
-
|
|
118315
|
-
|
|
118316
|
-
|
|
118317
|
-
|
|
118318
|
-
|
|
118319
|
-
|
|
118320
|
-
|
|
118350
|
+
const countRelayAddrs = () => node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit")).length;
|
|
118351
|
+
const initialRelayCount = countRelayAddrs();
|
|
118352
|
+
info(`Initial relay addresses: ${initialRelayCount}`);
|
|
118353
|
+
info("Waiting for relay reservation...");
|
|
118354
|
+
let reservationSucceeded = false;
|
|
118355
|
+
await new Promise((resolve) => {
|
|
118356
|
+
const timeout = setTimeout(() => {
|
|
118357
|
+
if (!reservationSucceeded) {
|
|
118358
|
+
info(`Relay reservation timeout after 15s.`);
|
|
118321
118359
|
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(", ")}`);
|
|
118360
|
+
}
|
|
118361
|
+
resolve();
|
|
118362
|
+
}, 15e3);
|
|
118363
|
+
const onReservation = () => {
|
|
118364
|
+
reservationSucceeded = true;
|
|
118365
|
+
info(`\u2713 Relay reservation successful!`);
|
|
118366
|
+
clearTimeout(timeout);
|
|
118367
|
+
setTimeout(resolve, 500);
|
|
118368
|
+
};
|
|
118369
|
+
node.libp2p.addEventListener("relay:reservation", onReservation, { once: true });
|
|
118370
|
+
setTimeout(() => {
|
|
118371
|
+
node.libp2p.removeEventListener("relay:reservation", onReservation);
|
|
118372
|
+
}, 15e3);
|
|
118373
|
+
});
|
|
118374
|
+
if (!reservationSucceeded) {
|
|
118375
|
+
info("\u26A0 Relay reservation did not complete - using fallback relay addresses");
|
|
118348
118376
|
}
|
|
118349
118377
|
connectSpin.succeed("Connected to network!");
|
|
118350
118378
|
const cardSpin = spinner("Publishing Agent Card to DHT...");
|
|
@@ -118352,8 +118380,18 @@ function registerJoinCommand(program2) {
|
|
|
118352
118380
|
const relayAddrs = node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit"));
|
|
118353
118381
|
const fallbackRelayAddrs = relayAddrs.length === 0 ? bootstrapPeers.map((r2) => `${r2}/p2p-circuit/p2p/${node.getPeerId()}`) : [];
|
|
118354
118382
|
const allAddrs = [...directAddrs, ...relayAddrs, ...fallbackRelayAddrs];
|
|
118355
|
-
const capabilities =
|
|
118356
|
-
|
|
118383
|
+
const capabilities = (card.capabilities ?? []).map((capability) => ({
|
|
118384
|
+
id: capability,
|
|
118385
|
+
name: capability,
|
|
118386
|
+
description: `Capability: ${capability}`
|
|
118387
|
+
}));
|
|
118388
|
+
if (options.relay) {
|
|
118389
|
+
capabilities.push({
|
|
118390
|
+
id: "relay",
|
|
118391
|
+
name: "relay",
|
|
118392
|
+
description: "Provides circuit relay service for NAT traversal"
|
|
118393
|
+
});
|
|
118394
|
+
}
|
|
118357
118395
|
const agentCard = createAgentCard(
|
|
118358
118396
|
identity3.did,
|
|
118359
118397
|
card.name,
|
|
@@ -118377,9 +118415,19 @@ function registerJoinCommand(program2) {
|
|
|
118377
118415
|
}
|
|
118378
118416
|
}
|
|
118379
118417
|
}, 3e4);
|
|
118418
|
+
const verifyFn = async (signature, data) => {
|
|
118419
|
+
try {
|
|
118420
|
+
const decoded = JSON.parse(new TextDecoder().decode(data));
|
|
118421
|
+
if (!decoded.from || typeof decoded.from !== "string") return false;
|
|
118422
|
+
const senderPublicKey = extractPublicKey(decoded.from);
|
|
118423
|
+
return verify(signature, data, senderPublicKey);
|
|
118424
|
+
} catch {
|
|
118425
|
+
return false;
|
|
118426
|
+
}
|
|
118427
|
+
};
|
|
118380
118428
|
const router = createMessageRouter(
|
|
118381
118429
|
node.libp2p,
|
|
118382
|
-
|
|
118430
|
+
verifyFn,
|
|
118383
118431
|
dht
|
|
118384
118432
|
);
|
|
118385
118433
|
const messageHandler = async (envelope) => {
|
|
@@ -118610,9 +118658,19 @@ function registerSendCommand(program2) {
|
|
|
118610
118658
|
spin.text = "Connecting to network...";
|
|
118611
118659
|
await identifyDone;
|
|
118612
118660
|
const dht = createDHTOperations(node.libp2p);
|
|
118661
|
+
const verifyFn = async (signature, data) => {
|
|
118662
|
+
try {
|
|
118663
|
+
const decoded = JSON.parse(new TextDecoder().decode(data));
|
|
118664
|
+
if (!decoded.from || typeof decoded.from !== "string") return false;
|
|
118665
|
+
const senderPublicKey = extractPublicKey(decoded.from);
|
|
118666
|
+
return verify(signature, data, senderPublicKey);
|
|
118667
|
+
} catch {
|
|
118668
|
+
return false;
|
|
118669
|
+
}
|
|
118670
|
+
};
|
|
118613
118671
|
const router = createMessageRouter(
|
|
118614
118672
|
node.libp2p,
|
|
118615
|
-
|
|
118673
|
+
verifyFn,
|
|
118616
118674
|
dht,
|
|
118617
118675
|
bootstrapPeers
|
|
118618
118676
|
);
|