agentbnb 3.1.5 → 3.1.6

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/cli/index.js CHANGED
@@ -1646,13 +1646,19 @@ function createGatewayServer(opts) {
1646
1646
  } = opts;
1647
1647
  const fastify = Fastify({ logger: !silent });
1648
1648
  const tokenSet = new Set(tokens);
1649
- fastify.addHook("onRequest", async (request, reply) => {
1649
+ fastify.addHook("onRequest", async (request) => {
1650
1650
  if (request.method === "GET" && request.url === "/health") return;
1651
1651
  const auth = request.headers.authorization;
1652
1652
  if (auth && auth.startsWith("Bearer ")) {
1653
1653
  const token = auth.slice("Bearer ".length).trim();
1654
- if (tokenSet.has(token)) return;
1654
+ if (tokenSet.has(token)) {
1655
+ request._authenticated = true;
1656
+ }
1655
1657
  }
1658
+ });
1659
+ fastify.addHook("preHandler", async (request, reply) => {
1660
+ if (request._authenticated) return;
1661
+ if (request.method === "GET" && request.url === "/health") return;
1656
1662
  const agentId = request.headers["x-agent-id"];
1657
1663
  const publicKeyHex = request.headers["x-agent-public-key"];
1658
1664
  const signature = request.headers["x-agent-signature"];
@@ -1660,8 +1666,10 @@ function createGatewayServer(opts) {
1660
1666
  try {
1661
1667
  const publicKeyBuf = Buffer.from(publicKeyHex, "hex");
1662
1668
  const body = request.body;
1663
- const valid = verifyEscrowReceipt(body, signature, publicKeyBuf);
1664
- if (valid) return;
1669
+ if (body && typeof body === "object") {
1670
+ const valid = verifyEscrowReceipt(body, signature, publicKeyBuf);
1671
+ if (valid) return;
1672
+ }
1665
1673
  } catch {
1666
1674
  }
1667
1675
  }
package/dist/index.js CHANGED
@@ -943,13 +943,19 @@ function createGatewayServer(opts) {
943
943
  } = opts;
944
944
  const fastify = Fastify({ logger: !silent });
945
945
  const tokenSet = new Set(tokens);
946
- fastify.addHook("onRequest", async (request, reply) => {
946
+ fastify.addHook("onRequest", async (request) => {
947
947
  if (request.method === "GET" && request.url === "/health") return;
948
948
  const auth = request.headers.authorization;
949
949
  if (auth && auth.startsWith("Bearer ")) {
950
950
  const token = auth.slice("Bearer ".length).trim();
951
- if (tokenSet.has(token)) return;
951
+ if (tokenSet.has(token)) {
952
+ request._authenticated = true;
953
+ }
952
954
  }
955
+ });
956
+ fastify.addHook("preHandler", async (request, reply) => {
957
+ if (request._authenticated) return;
958
+ if (request.method === "GET" && request.url === "/health") return;
953
959
  const agentId = request.headers["x-agent-id"];
954
960
  const publicKeyHex = request.headers["x-agent-public-key"];
955
961
  const signature = request.headers["x-agent-signature"];
@@ -957,8 +963,10 @@ function createGatewayServer(opts) {
957
963
  try {
958
964
  const publicKeyBuf = Buffer.from(publicKeyHex, "hex");
959
965
  const body = request.body;
960
- const valid = verifyEscrowReceipt(body, signature, publicKeyBuf);
961
- if (valid) return;
966
+ if (body && typeof body === "object") {
967
+ const valid = verifyEscrowReceipt(body, signature, publicKeyBuf);
968
+ if (valid) return;
969
+ }
962
970
  } catch {
963
971
  }
964
972
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentbnb",
3
- "version": "3.1.5",
3
+ "version": "3.1.6",
4
4
  "description": "P2P Agent Capability Sharing Protocol — Airbnb for AI agent pipelines",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",