@ik-firewall/core 2.3.1 → 2.3.2
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.cjs +11 -6
- package/dist/index.js +11 -6
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -198,7 +198,6 @@ var Registry = class _Registry {
|
|
|
198
198
|
};
|
|
199
199
|
|
|
200
200
|
// src/lib/hmac.ts
|
|
201
|
-
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
202
201
|
var IKHmac = class {
|
|
203
202
|
secret;
|
|
204
203
|
constructor(secret) {
|
|
@@ -207,12 +206,18 @@ var IKHmac = class {
|
|
|
207
206
|
/**
|
|
208
207
|
* Verifies that a response from the IK-Firewall server is authentic.
|
|
209
208
|
*/
|
|
210
|
-
verify(data) {
|
|
209
|
+
async verify(data) {
|
|
211
210
|
if (!data || !data.signature) return false;
|
|
212
211
|
const { signature, ...rest } = data;
|
|
213
212
|
const payload = JSON.stringify(rest);
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
try {
|
|
214
|
+
const crypto = await import("crypto");
|
|
215
|
+
const expectedSignature = crypto.createHmac("sha256", this.secret).update(payload).digest("hex");
|
|
216
|
+
return signature === expectedSignature;
|
|
217
|
+
} catch (e) {
|
|
218
|
+
console.warn("[IK_HMAC] Crypto not available in this environment. Verification skipped.");
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
216
221
|
}
|
|
217
222
|
};
|
|
218
223
|
|
|
@@ -1554,8 +1559,8 @@ var UsageTracker = class {
|
|
|
1554
1559
|
};
|
|
1555
1560
|
if (hmacSecret) {
|
|
1556
1561
|
const jsonStr = JSON.stringify(payload);
|
|
1557
|
-
const
|
|
1558
|
-
payload.signature =
|
|
1562
|
+
const crypto = await import("crypto");
|
|
1563
|
+
payload.signature = crypto.createHmac("sha256", hmacSecret).update(jsonStr).digest("hex");
|
|
1559
1564
|
}
|
|
1560
1565
|
const response = await fetch(endpoint, {
|
|
1561
1566
|
method: "POST",
|
package/dist/index.js
CHANGED
|
@@ -156,7 +156,6 @@ var Registry = class _Registry {
|
|
|
156
156
|
};
|
|
157
157
|
|
|
158
158
|
// src/lib/hmac.ts
|
|
159
|
-
import crypto from "crypto";
|
|
160
159
|
var IKHmac = class {
|
|
161
160
|
secret;
|
|
162
161
|
constructor(secret) {
|
|
@@ -165,12 +164,18 @@ var IKHmac = class {
|
|
|
165
164
|
/**
|
|
166
165
|
* Verifies that a response from the IK-Firewall server is authentic.
|
|
167
166
|
*/
|
|
168
|
-
verify(data) {
|
|
167
|
+
async verify(data) {
|
|
169
168
|
if (!data || !data.signature) return false;
|
|
170
169
|
const { signature, ...rest } = data;
|
|
171
170
|
const payload = JSON.stringify(rest);
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
try {
|
|
172
|
+
const crypto = await import("crypto");
|
|
173
|
+
const expectedSignature = crypto.createHmac("sha256", this.secret).update(payload).digest("hex");
|
|
174
|
+
return signature === expectedSignature;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
console.warn("[IK_HMAC] Crypto not available in this environment. Verification skipped.");
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
174
179
|
}
|
|
175
180
|
};
|
|
176
181
|
|
|
@@ -1512,8 +1517,8 @@ var UsageTracker = class {
|
|
|
1512
1517
|
};
|
|
1513
1518
|
if (hmacSecret) {
|
|
1514
1519
|
const jsonStr = JSON.stringify(payload);
|
|
1515
|
-
const
|
|
1516
|
-
payload.signature =
|
|
1520
|
+
const crypto = await import("crypto");
|
|
1521
|
+
payload.signature = crypto.createHmac("sha256", hmacSecret).update(jsonStr).digest("hex");
|
|
1517
1522
|
}
|
|
1518
1523
|
const response = await fetch(endpoint, {
|
|
1519
1524
|
method: "POST",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ik-firewall/core",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The core IK Firewall engine for semantic-driven AI optimization.",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"api_endpoint": "https://ik-firewall.vercel.app/api/v1",
|
|
21
21
|
"scripts": {
|
|
22
22
|
"prepare": "npm run build",
|
|
23
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
23
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --external crypto",
|
|
24
24
|
"build:wasm": "cd wasm-core && wasm-pack build --target nodejs",
|
|
25
25
|
"dev": "tsup src/index.ts --format cjs,esm --watch --dts",
|
|
26
26
|
"lint": "eslint src/**/*.ts",
|