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 +12 -4
- package/dist/index.js +12 -4
- package/package.json +1 -1
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
|
|
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))
|
|
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
|
-
|
|
1664
|
-
|
|
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
|
|
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))
|
|
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
|
-
|
|
961
|
-
|
|
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
|
}
|