@usethrottle/extension-bridge 0.2.0
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/chunk-XBGZRIHG.js +13 -0
- package/dist/chunk-XBGZRIHG.js.map +1 -0
- package/dist/extension-bridge.global.js +232 -0
- package/dist/extension-bridge.global.js.map +1 -0
- package/dist/index.cjs +239 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +109 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +208 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.cjs +40 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +70 -0
- package/dist/protocol.d.ts +70 -0
- package/dist/protocol.js +13 -0
- package/dist/protocol.js.map +1 -0
- package/dist/webhook.cjs +53 -0
- package/dist/webhook.cjs.map +1 -0
- package/dist/webhook.d.cts +11 -0
- package/dist/webhook.d.ts +11 -0
- package/dist/webhook.js +28 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +51 -0
package/dist/webhook.cjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/webhook.ts
|
|
21
|
+
var webhook_exports = {};
|
|
22
|
+
__export(webhook_exports, {
|
|
23
|
+
verifyWebhook: () => verifyWebhook
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(webhook_exports);
|
|
26
|
+
var import_node_crypto = require("crypto");
|
|
27
|
+
function verifyWebhook(rawBody, signatureHeader, secret, opts = {}) {
|
|
28
|
+
try {
|
|
29
|
+
if (!signatureHeader || typeof signatureHeader !== "string") return false;
|
|
30
|
+
const toleranceSeconds = opts.toleranceSeconds ?? 300;
|
|
31
|
+
const parts = {};
|
|
32
|
+
for (const segment of signatureHeader.split(",")) {
|
|
33
|
+
const idx = segment.indexOf("=");
|
|
34
|
+
if (idx > 0) parts[segment.slice(0, idx).trim()] = segment.slice(idx + 1).trim();
|
|
35
|
+
}
|
|
36
|
+
const ts = parts["t"] ? Number.parseInt(parts["t"], 10) : NaN;
|
|
37
|
+
const v1 = parts["v1"];
|
|
38
|
+
if (!Number.isFinite(ts) || !v1 || !/^[0-9a-f]+$/i.test(v1)) return false;
|
|
39
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
40
|
+
if (Math.abs(now - ts) > toleranceSeconds) return false;
|
|
41
|
+
const body = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8");
|
|
42
|
+
const expected = (0, import_node_crypto.createHmac)("sha256", secret).update(`${ts}.${body}`).digest("hex");
|
|
43
|
+
if (expected.length !== v1.length) return false;
|
|
44
|
+
return (0, import_node_crypto.timingSafeEqual)(Buffer.from(expected, "hex"), Buffer.from(v1, "hex"));
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
verifyWebhook
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=webhook.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/webhook.ts"],"sourcesContent":["/**\n * @usethrottle/extension-bridge/webhook\n *\n * Server-side webhook signature verifier. Uses node:crypto — keep out of browser bundles.\n * Import from `@usethrottle/extension-bridge/webhook`.\n *\n * Signature scheme: Header `X-Throttle-Signature: t=<unixSeconds>,v1=<hex-hmac-sha256>`\n * Signed payload: `${t}.${rawBody}` (matches signOutbound in @platform/webhooks)\n */\nimport { createHmac, timingSafeEqual } from 'node:crypto';\n\nexport interface VerifyWebhookOptions {\n /** Clock-skew tolerance in seconds. Default: 300. */\n toleranceSeconds?: number;\n}\n\n/**\n * Verify the `X-Throttle-Signature` header on an inbound webhook delivery.\n * @returns `true` if valid; `false` for any invalid/malformed input. Never throws.\n */\nexport function verifyWebhook(\n rawBody: string | Buffer,\n signatureHeader: string,\n secret: string,\n opts: VerifyWebhookOptions = {},\n): boolean {\n try {\n if (!signatureHeader || typeof signatureHeader !== 'string') return false;\n const toleranceSeconds = opts.toleranceSeconds ?? 300;\n const parts: Record<string, string> = {};\n for (const segment of signatureHeader.split(',')) {\n const idx = segment.indexOf('=');\n if (idx > 0) parts[segment.slice(0, idx).trim()] = segment.slice(idx + 1).trim();\n }\n const ts = parts['t'] ? Number.parseInt(parts['t'], 10) : NaN;\n const v1 = parts['v1'];\n if (!Number.isFinite(ts) || !v1 || !/^[0-9a-f]+$/i.test(v1)) return false;\n const now = Math.floor(Date.now() / 1000);\n if (Math.abs(now - ts) > toleranceSeconds) return false;\n const body = typeof rawBody === 'string' ? rawBody : rawBody.toString('utf8');\n const expected = createHmac('sha256', secret).update(`${ts}.${body}`).digest('hex');\n if (expected.length !== v1.length) return false;\n return timingSafeEqual(Buffer.from(expected, 'hex'), Buffer.from(v1, 'hex'));\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAA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ify the `X-Throttle-Signature` header on an inbound webhook delivery.
|
|
7
|
+
* @returns `true` if valid; `false` for any invalid/malformed input. Never throws.
|
|
8
|
+
*/
|
|
9
|
+
declare function verifyWebhook(rawBody: string | Buffer, signatureHeader: string, secret: string, opts?: VerifyWebhookOptions): boolean;
|
|
10
|
+
|
|
11
|
+
export { type VerifyWebhookOptions, verifyWebhook };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface VerifyWebhookOptions {
|
|
2
|
+
/** Clock-skew tolerance in seconds. Default: 300. */
|
|
3
|
+
toleranceSeconds?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Verify the `X-Throttle-Signature` header on an inbound webhook delivery.
|
|
7
|
+
* @returns `true` if valid; `false` for any invalid/malformed input. Never throws.
|
|
8
|
+
*/
|
|
9
|
+
declare function verifyWebhook(rawBody: string | Buffer, signatureHeader: string, secret: string, opts?: VerifyWebhookOptions): boolean;
|
|
10
|
+
|
|
11
|
+
export { type VerifyWebhookOptions, verifyWebhook };
|
package/dist/webhook.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/webhook.ts
|
|
2
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
|
3
|
+
function verifyWebhook(rawBody, signatureHeader, secret, opts = {}) {
|
|
4
|
+
try {
|
|
5
|
+
if (!signatureHeader || typeof signatureHeader !== "string") return false;
|
|
6
|
+
const toleranceSeconds = opts.toleranceSeconds ?? 300;
|
|
7
|
+
const parts = {};
|
|
8
|
+
for (const segment of signatureHeader.split(",")) {
|
|
9
|
+
const idx = segment.indexOf("=");
|
|
10
|
+
if (idx > 0) parts[segment.slice(0, idx).trim()] = segment.slice(idx + 1).trim();
|
|
11
|
+
}
|
|
12
|
+
const ts = parts["t"] ? Number.parseInt(parts["t"], 10) : NaN;
|
|
13
|
+
const v1 = parts["v1"];
|
|
14
|
+
if (!Number.isFinite(ts) || !v1 || !/^[0-9a-f]+$/i.test(v1)) return false;
|
|
15
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
16
|
+
if (Math.abs(now - ts) > toleranceSeconds) return false;
|
|
17
|
+
const body = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8");
|
|
18
|
+
const expected = createHmac("sha256", secret).update(`${ts}.${body}`).digest("hex");
|
|
19
|
+
if (expected.length !== v1.length) return false;
|
|
20
|
+
return timingSafeEqual(Buffer.from(expected, "hex"), Buffer.from(v1, "hex"));
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
verifyWebhook
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/webhook.ts"],"sourcesContent":["/**\n * @usethrottle/extension-bridge/webhook\n *\n * Server-side webhook signature verifier. Uses node:crypto — keep out of browser bundles.\n * Import from `@usethrottle/extension-bridge/webhook`.\n *\n * Signature scheme: Header `X-Throttle-Signature: t=<unixSeconds>,v1=<hex-hmac-sha256>`\n * Signed payload: `${t}.${rawBody}` (matches signOutbound in @platform/webhooks)\n */\nimport { createHmac, timingSafeEqual } from 'node:crypto';\n\nexport interface VerifyWebhookOptions {\n /** Clock-skew tolerance in seconds. Default: 300. */\n toleranceSeconds?: number;\n}\n\n/**\n * Verify the `X-Throttle-Signature` header on an inbound webhook delivery.\n * @returns `true` if valid; `false` for any invalid/malformed input. Never throws.\n */\nexport function verifyWebhook(\n rawBody: string | Buffer,\n signatureHeader: string,\n secret: string,\n opts: VerifyWebhookOptions = {},\n): boolean {\n try {\n if (!signatureHeader || typeof signatureHeader !== 'string') return false;\n const toleranceSeconds = opts.toleranceSeconds ?? 300;\n const parts: Record<string, string> = {};\n for (const segment of signatureHeader.split(',')) {\n const idx = segment.indexOf('=');\n if (idx > 0) parts[segment.slice(0, idx).trim()] = segment.slice(idx + 1).trim();\n }\n const ts = parts['t'] ? Number.parseInt(parts['t'], 10) : NaN;\n const v1 = parts['v1'];\n if (!Number.isFinite(ts) || !v1 || !/^[0-9a-f]+$/i.test(v1)) return false;\n const now = Math.floor(Date.now() / 1000);\n if (Math.abs(now - ts) > toleranceSeconds) return false;\n const body = typeof rawBody === 'string' ? rawBody : rawBody.toString('utf8');\n const expected = createHmac('sha256', secret).update(`${ts}.${body}`).digest('hex');\n if (expected.length !== v1.length) return false;\n return timingSafeEqual(Buffer.from(expected, 'hex'), Buffer.from(v1, 'hex'));\n } catch {\n return false;\n }\n}\n"],"mappings":";AASA,SAAS,YAAY,uBAAuB;AAWrC,SAAS,cACd,SACA,iBACA,QACA,OAA6B,CAAC,GACrB;AACT,MAAI;AACF,QAAI,CAAC,mBAAmB,OAAO,oBAAoB,SAAU,QAAO;AACpE,UAAM,mBAAmB,KAAK,oBAAoB;AAClD,UAAM,QAAgC,CAAC;AACvC,eAAW,WAAW,gBAAgB,MAAM,GAAG,GAAG;AAChD,YAAM,MAAM,QAAQ,QAAQ,GAAG;AAC/B,UAAI,MAAM,EAAG,OAAM,QAAQ,MAAM,GAAG,GAAG,EAAE,KAAK,CAAC,IAAI,QAAQ,MAAM,MAAM,CAAC,EAAE,KAAK;AAAA,IACjF;AACA,UAAM,KAAK,MAAM,GAAG,IAAI,OAAO,SAAS,MAAM,GAAG,GAAG,EAAE,IAAI;AAC1D,UAAM,KAAK,MAAM,IAAI;AACrB,QAAI,CAAC,OAAO,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,eAAe,KAAK,EAAE,EAAG,QAAO;AACpE,UAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACxC,QAAI,KAAK,IAAI,MAAM,EAAE,IAAI,iBAAkB,QAAO;AAClD,UAAM,OAAO,OAAO,YAAY,WAAW,UAAU,QAAQ,SAAS,MAAM;AAC5E,UAAM,WAAW,WAAW,UAAU,MAAM,EAAE,OAAO,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE,OAAO,KAAK;AAClF,QAAI,SAAS,WAAW,GAAG,OAAQ,QAAO;AAC1C,WAAO,gBAAgB,OAAO,KAAK,UAAU,KAAK,GAAG,OAAO,KAAK,IAAI,KAAK,CAAC;AAAA,EAC7E,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@usethrottle/extension-bridge",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "iframe bridge runtime for Throttle extensions — host helper + webhook verifier.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"unpkg": "./dist/extension-bridge.global.js",
|
|
10
|
+
"jsdelivr": "./dist/extension-bridge.global.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./webhook": {
|
|
18
|
+
"types": "./dist/webhook.d.ts",
|
|
19
|
+
"import": "./dist/webhook.js",
|
|
20
|
+
"require": "./dist/webhook.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./protocol": {
|
|
23
|
+
"types": "./dist/protocol.d.ts",
|
|
24
|
+
"import": "./dist/protocol.js",
|
|
25
|
+
"require": "./dist/protocol.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"typecheck": "tsc --noEmit"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"tsup": "^8.0.0",
|
|
40
|
+
"typescript": "^5.7.0",
|
|
41
|
+
"vitest": "^2.1.9",
|
|
42
|
+
"jsdom": "^25.0.0",
|
|
43
|
+
"@types/node": "^20.0.0"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=20"
|
|
50
|
+
}
|
|
51
|
+
}
|