@highway1/cli 0.1.38 → 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 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, _verifyFn) {
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 = (evt) => {
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 = [...card.capabilities ?? []];
118364
- if (options.relay) capabilities.push("relay");
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,
@@ -118385,9 +118415,19 @@ function registerJoinCommand(program2) {
118385
118415
  }
118386
118416
  }
118387
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
+ };
118388
118428
  const router = createMessageRouter(
118389
118429
  node.libp2p,
118390
- async () => true,
118430
+ verifyFn,
118391
118431
  dht
118392
118432
  );
118393
118433
  const messageHandler = async (envelope) => {