@highway1/core 0.1.30 → 0.1.31

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
@@ -1502,7 +1502,7 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
1502
1502
  function buildCircuitRelayAddr(relayAddr, targetPeerId) {
1503
1503
  return `${relayAddr}/p2p-circuit/p2p/${targetPeerId}`;
1504
1504
  }
1505
- async function handleIncomingStream(stream, handlers, catchAllHandler, _verifyFn) {
1505
+ async function handleIncomingStream(stream, handlers, catchAllHandler, verifyFn) {
1506
1506
  try {
1507
1507
  const chunks = [];
1508
1508
  for await (const chunk of stream.source) {
@@ -1532,6 +1532,26 @@ async function handleIncomingStream(stream, handlers, catchAllHandler, _verifyFn
1532
1532
  });
1533
1533
  return;
1534
1534
  }
1535
+ try {
1536
+ const { signature, ...envelopeWithoutSig } = envelope;
1537
+ const dataBytes = new TextEncoder().encode(JSON.stringify(envelopeWithoutSig));
1538
+ const signatureBytes = Buffer.from(signature, "hex");
1539
+ const hookValid = await verifyFn(signatureBytes, dataBytes);
1540
+ if (!hookValid) {
1541
+ logger5.warn("Message rejected by custom verifier", {
1542
+ id: envelope.id,
1543
+ from: envelope.from
1544
+ });
1545
+ return;
1546
+ }
1547
+ } catch (error) {
1548
+ logger5.warn("Custom verification hook failed", {
1549
+ id: envelope.id,
1550
+ from: envelope.from,
1551
+ error: error.message
1552
+ });
1553
+ return;
1554
+ }
1535
1555
  logger5.info("Received message", {
1536
1556
  id: envelope.id,
1537
1557
  from: envelope.from,