@whooshbang/sdk 1.0.0-rc.14

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.
@@ -0,0 +1,29 @@
1
+ import { createMachineCredentialMaterial, validateRegisterMachineCredentialRequest, } from "@whooshbang/contracts";
2
+ import { WhooshBangValidationError } from "./errors.js";
3
+ /**
4
+ * Generates C0-03 machine credential material with secure randomness.
5
+ *
6
+ * The secret is 256 random bits from Web Crypto and the registration carries
7
+ * only its SHA-256 digest, so registering a credential discloses nothing that
8
+ * could authenticate as it. Hand `bearerToken` straight to a
9
+ * `WhooshBangClient` as its `credential` and keep it out of logs, files, and
10
+ * error messages.
11
+ */
12
+ export async function createMachineCredential(crypto) {
13
+ const material = await createMachineCredentialMaterial(crypto);
14
+ const registration = {
15
+ credential_id: material.registration.credential_id,
16
+ secret_sha256: material.registration.secret_sha256,
17
+ };
18
+ if (!validateRegisterMachineCredentialRequest(registration)) {
19
+ throw new WhooshBangValidationError("createMachineCredential", [
20
+ { code: "contract_mismatch", path: "registration" },
21
+ ]);
22
+ }
23
+ return {
24
+ bearerToken: material.bearerToken,
25
+ credentialId: material.credentialId,
26
+ registration,
27
+ };
28
+ }
29
+ //# sourceMappingURL=machine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"machine.js","sourceRoot":"","sources":["../src/machine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,wCAAwC,GACzC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AA0BxD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAAgC;IAEhC,MAAM,QAAQ,GAAG,MAAM,+BAA+B,CAAC,MAAM,CAAC,CAAC;IAC/D,MAAM,YAAY,GAAG;QACnB,aAAa,EAAE,QAAQ,CAAC,YAAY,CAAC,aAAa;QAClD,aAAa,EAAE,QAAQ,CAAC,YAAY,CAAC,aAAa;KACnD,CAAC;IACF,IAAI,CAAC,wCAAwC,CAAC,YAAY,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,yBAAyB,CAAC,yBAAyB,EAAE;YAC7D,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,cAAc,EAAE;SACpD,CAAC,CAAC;IACL,CAAC;IACD,OAAO;QACL,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,YAAY;KACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { verifyWebhookSignature } from "@whooshbang/contracts";
2
+ import type { VerifyWebhookSignatureOptions, WebhookVerificationFailureReason, WhooshBangEventV1ContractDocument } from "@whooshbang/contracts";
3
+ export interface VerifiedWhooshBangEvent {
4
+ readonly attempt: number;
5
+ readonly event: WhooshBangEventV1ContractDocument;
6
+ readonly eventId: string;
7
+ readonly timestamp: number;
8
+ readonly verified: true;
9
+ }
10
+ export interface RejectedWhooshBangEvent {
11
+ readonly reason: WebhookVerificationFailureReason | "event_contract_mismatch" | "event_id_mismatch";
12
+ readonly verified: false;
13
+ }
14
+ export type WhooshBangEventVerification = RejectedWhooshBangEvent | VerifiedWhooshBangEvent;
15
+ /**
16
+ * Verifies a signed customer event and returns its typed body.
17
+ *
18
+ * `rawBody` must be the exact bytes the receiver read from the wire. Framework
19
+ * re-serialization changes the signed input and is the usual cause of a
20
+ * spurious `signature_mismatch`.
21
+ *
22
+ * The body is only parsed after the signature, replay window, and version
23
+ * checks pass, so unsigned or stale bytes are never decoded. Supplying both
24
+ * the previous and the current secret verifies through a rotation-overlap
25
+ * window without a gap.
26
+ */
27
+ export declare function verifyWhooshBangEvent(options: VerifyWebhookSignatureOptions): Promise<WhooshBangEventVerification>;
28
+ /** Signature-only verification over the exact raw request bytes. */
29
+ export declare function verifyWhooshBangWebhook(options: VerifyWebhookSignatureOptions): ReturnType<typeof verifyWebhookSignature>;
@@ -0,0 +1,47 @@
1
+ import { validateWhooshBangEvent, verifyWebhookSignature, } from "@whooshbang/contracts";
2
+ /**
3
+ * Verifies a signed customer event and returns its typed body.
4
+ *
5
+ * `rawBody` must be the exact bytes the receiver read from the wire. Framework
6
+ * re-serialization changes the signed input and is the usual cause of a
7
+ * spurious `signature_mismatch`.
8
+ *
9
+ * The body is only parsed after the signature, replay window, and version
10
+ * checks pass, so unsigned or stale bytes are never decoded. Supplying both
11
+ * the previous and the current secret verifies through a rotation-overlap
12
+ * window without a gap.
13
+ */
14
+ export async function verifyWhooshBangEvent(options) {
15
+ const verification = await verifyWebhookSignature(options);
16
+ if (!verification.verified) {
17
+ return { reason: verification.reason, verified: false };
18
+ }
19
+ let parsed;
20
+ try {
21
+ parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(options.rawBody));
22
+ }
23
+ catch {
24
+ return { reason: "event_contract_mismatch", verified: false };
25
+ }
26
+ if (!validateWhooshBangEvent(parsed)) {
27
+ return { reason: "event_contract_mismatch", verified: false };
28
+ }
29
+ // The signed `webhook-id` and the body's own identifier must agree, or a
30
+ // receiver that dedupes on one and stores the other keys the same delivery
31
+ // twice.
32
+ if (parsed.id !== verification.eventId) {
33
+ return { reason: "event_id_mismatch", verified: false };
34
+ }
35
+ return {
36
+ attempt: verification.attempt,
37
+ event: parsed,
38
+ eventId: verification.eventId,
39
+ timestamp: verification.timestamp,
40
+ verified: true,
41
+ };
42
+ }
43
+ /** Signature-only verification over the exact raw request bytes. */
44
+ export async function verifyWhooshBangWebhook(options) {
45
+ return verifyWebhookSignature(options);
46
+ }
47
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AA2B/B;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OA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2
+ "name": "@whooshbang/sdk",
3
+ "version": "1.0.0-rc.14",
4
+ "description": "Fetch-injected JavaScript client for WhooshBang V1",
5
+ "private": false,
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "homepage": "https://whooshbang.com",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/flowxo/whooshbang.git",
13
+ "directory": "packages/sdk-js"
14
+ },
15
+ "keywords": [
16
+ "whooshbang",
17
+ "notifications",
18
+ "telegram",
19
+ "sdk"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "tag": "next"
24
+ },
25
+ "files": [
26
+ "LICENSE",
27
+ "README.md",
28
+ "dist"
29
+ ],
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "./package.json": "./package.json"
37
+ },
38
+ "scripts": {
39
+ "build": "node ../../scripts/clean-dist.mjs && tsc -p tsconfig.build.json",
40
+ "lint": "eslint examples scripts src test --max-warnings=0",
41
+ "test": "vitest run --no-file-parallelism",
42
+ "type-check": "tsc --noEmit -p tsconfig.json"
43
+ },
44
+ "dependencies": {
45
+ "@whooshbang/contracts": "1.0.0-rc.13"
46
+ },
47
+ "engines": {
48
+ "node": ">=22.13.0 <23"
49
+ }
50
+ }