@highway1/cli 0.1.38 → 0.1.40
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 +62 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/join.ts +37 -12
package/dist/index.js
CHANGED
|
@@ -116897,7 +116897,7 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
|
|
|
116897
116897
|
function buildCircuitRelayAddr(relayAddr, targetPeerId) {
|
|
116898
116898
|
return `${relayAddr}/p2p-circuit/p2p/${targetPeerId}`;
|
|
116899
116899
|
}
|
|
116900
|
-
async function handleIncomingStream(stream, handlers, catchAllHandler,
|
|
116900
|
+
async function handleIncomingStream(stream, handlers, catchAllHandler, verifyFn) {
|
|
116901
116901
|
try {
|
|
116902
116902
|
const chunks = [];
|
|
116903
116903
|
for await (const chunk of stream.source) {
|
|
@@ -116927,6 +116927,26 @@ async function handleIncomingStream(stream, handlers, catchAllHandler, _verifyFn
|
|
|
116927
116927
|
});
|
|
116928
116928
|
return;
|
|
116929
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
|
+
}
|
|
116930
116950
|
logger5.info("Received message", {
|
|
116931
116951
|
id: envelope.id,
|
|
116932
116952
|
from: envelope.from,
|
|
@@ -118340,7 +118360,7 @@ function registerJoinCommand(program2) {
|
|
|
118340
118360
|
}
|
|
118341
118361
|
resolve();
|
|
118342
118362
|
}, 15e3);
|
|
118343
|
-
const onReservation = (
|
|
118363
|
+
const onReservation = () => {
|
|
118344
118364
|
reservationSucceeded = true;
|
|
118345
118365
|
info(`\u2713 Relay reservation successful!`);
|
|
118346
118366
|
clearTimeout(timeout);
|
|
@@ -118360,8 +118380,18 @@ function registerJoinCommand(program2) {
|
|
|
118360
118380
|
const relayAddrs = node.getMultiaddrs().filter((a2) => a2.includes("/p2p-circuit"));
|
|
118361
118381
|
const fallbackRelayAddrs = relayAddrs.length === 0 ? bootstrapPeers.map((r2) => `${r2}/p2p-circuit/p2p/${node.getPeerId()}`) : [];
|
|
118362
118382
|
const allAddrs = [...directAddrs, ...relayAddrs, ...fallbackRelayAddrs];
|
|
118363
|
-
const capabilities =
|
|
118364
|
-
|
|
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
|
+
}
|
|
118365
118395
|
const agentCard = createAgentCard(
|
|
118366
118396
|
identity3.did,
|
|
118367
118397
|
card.name,
|
|
@@ -118378,16 +118408,38 @@ function registerJoinCommand(program2) {
|
|
|
118378
118408
|
await dht.publishAgentCard(signedCard);
|
|
118379
118409
|
cardSpin.succeed("Agent Card published!");
|
|
118380
118410
|
const pingInterval = setInterval(async () => {
|
|
118381
|
-
|
|
118382
|
-
|
|
118383
|
-
|
|
118384
|
-
|
|
118411
|
+
const peers = node.libp2p.getPeers();
|
|
118412
|
+
if (peers.length === 0) {
|
|
118413
|
+
for (const bootstrapAddr of bootstrapPeers) {
|
|
118414
|
+
try {
|
|
118415
|
+
await node.libp2p.dial(bootstrapAddr);
|
|
118416
|
+
info("Reconnected to bootstrap peer");
|
|
118417
|
+
break;
|
|
118418
|
+
} catch {
|
|
118419
|
+
}
|
|
118385
118420
|
}
|
|
118421
|
+
} else {
|
|
118422
|
+
for (const peer of peers) {
|
|
118423
|
+
try {
|
|
118424
|
+
await node.libp2p.services.ping.ping(peer);
|
|
118425
|
+
} catch {
|
|
118426
|
+
}
|
|
118427
|
+
}
|
|
118428
|
+
}
|
|
118429
|
+
}, 15e3);
|
|
118430
|
+
const verifyFn = async (signature, data) => {
|
|
118431
|
+
try {
|
|
118432
|
+
const decoded = JSON.parse(new TextDecoder().decode(data));
|
|
118433
|
+
if (!decoded.from || typeof decoded.from !== "string") return false;
|
|
118434
|
+
const senderPublicKey = extractPublicKey(decoded.from);
|
|
118435
|
+
return verify(signature, data, senderPublicKey);
|
|
118436
|
+
} catch {
|
|
118437
|
+
return false;
|
|
118386
118438
|
}
|
|
118387
|
-
}
|
|
118439
|
+
};
|
|
118388
118440
|
const router = createMessageRouter(
|
|
118389
118441
|
node.libp2p,
|
|
118390
|
-
|
|
118442
|
+
verifyFn,
|
|
118391
118443
|
dht
|
|
118392
118444
|
);
|
|
118393
118445
|
const messageHandler = async (envelope) => {
|