@dhaneshpurohit/mockstar 0.1.3 → 0.3.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/CHANGELOG.md +46 -0
- package/dist/cli.js +290 -16
- package/dist/core/config/schema.d.ts +289 -155
- package/dist/core/config/schema.d.ts.map +1 -1
- package/dist/features/openapi/converter.d.ts +8 -0
- package/dist/features/openapi/converter.d.ts.map +1 -1
- package/dist/features/webhooks/dispatcher.d.ts.map +1 -1
- package/dist/features/webhooks/index.d.ts +3 -1
- package/dist/features/webhooks/index.d.ts.map +1 -1
- package/dist/features/webhooks/scheme.d.ts +46 -0
- package/dist/features/webhooks/scheme.d.ts.map +1 -0
- package/dist/features/webhooks/signing.d.ts +24 -13
- package/dist/features/webhooks/signing.d.ts.map +1 -1
- package/dist/features/webhooks/types.d.ts +17 -3
- package/dist/features/webhooks/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +202 -10
- package/dist/version.d.ts +1 -1
- package/package.json +10 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/core/config/schema.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/core/config/schema.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,eAAO,MAAM,WAAW,8EAA4E,CAAC;AAyCrG,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAShB,CAAC;AASZ,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC,CAAC"}
|
|
@@ -45,6 +45,14 @@ export interface ConvertOptions {
|
|
|
45
45
|
* anything else is a security error — CVE-2026-39885 class).
|
|
46
46
|
*/
|
|
47
47
|
export declare function convertOpenApi(doc: unknown, opts?: ConvertOptions): Array<Record<string, unknown>>;
|
|
48
|
+
/**
|
|
49
|
+
* Best-effort synthesis of a representative body from a JSON Schema so imported mocks
|
|
50
|
+
* are shaped like the real API. Bounded (depth + a per-branch $ref-visited set) so
|
|
51
|
+
* self-referential schemas terminate. Emits literal placeholders; `mockstar enhance`
|
|
52
|
+
* upgrades them to Tier 2 tokens. Only in-document `#/…` $refs are followed (external
|
|
53
|
+
* refs are already rejected upstream — RT-8.3).
|
|
54
|
+
*/
|
|
55
|
+
export declare function synthesizeFromSchema(schema: unknown, doc: OpenApiDoc, seen?: ReadonlySet<string>, depth?: number): unknown;
|
|
48
56
|
/**
|
|
49
57
|
* OpenAPI uses `{name}` path params; we rewrite to `:name` for Hono-style
|
|
50
58
|
* matching. Path segments are URL-encoded to prevent traversal attacks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.d.ts","sourceRoot":"","sources":["../../../src/features/openapi/converter.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,UAAU,cAAc;IACtB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,OAAO,CAAC;CAC7C;AAED,UAAU,eAAe;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,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,OAAO,EACf,GAAG,EAAE,UAAU,EACf,IAAI,GAAE,WAAW,CAAC,MAAM,CAAa,EACrC,KAAK,SAAI,GACR,OAAO,CAkDT;AAmCD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAmB9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/dispatcher.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAiB,iBAAiB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/dispatcher.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAiB,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGnE,OAAO,KAAK,EACV,mBAAmB,EAIpB,MAAM,YAAY,CAAC;AASpB,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,sBAAsB,CAAC;IAChC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,sEAAsE;IACtE,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,iBAAiB,CAAC;IACtD,8EAA8E;IAC9E,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,KAAK,cAAc,CAAC;IAC7F,kGAAkG;IAClG,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;IAClB,qFAAqF;IACrF,gBAAgB,EAAE,MAAM,CAAC;IACzB,uHAAuH;IACvH,OAAO,EAAE,MAAM,CAAC;IAChB,yFAAyF;IACzF,QAAQ,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACzC,4FAA4F;IAC5F,eAAe,EAAE,eAAe,CAAC;IACjC,sFAAsF;IACtF,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,mGAAmG;IACnG,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,sBAAsB,GAAG,SAAS,MAAM,EAAE,CAkDvG"}
|
|
@@ -9,5 +9,7 @@ export { WebhookJournalRegistry } from "./journal.ts";
|
|
|
9
9
|
export type { WebhookJournalOptions } from "./journal.ts";
|
|
10
10
|
export { dispatchWebhooks } from "./dispatcher.ts";
|
|
11
11
|
export type { DispatcherDeps, DispatcherTriggerInput } from "./dispatcher.ts";
|
|
12
|
-
export { signPayload, verifySignature, withinReplayWindow, resolveSecret } from "./signing.ts";
|
|
12
|
+
export { signPayload, verifySignature, withinReplayWindow, resolveSecret, LEGACY_SCHEME } from "./signing.ts";
|
|
13
|
+
export { DEFAULT_SIGNATURE_TEMPLATE, DEFAULT_SIGNED_PAYLOAD, renderSignatureHeader, renderSignedPayload, timestampUnitFor, } from "./scheme.ts";
|
|
14
|
+
export type { DigestEncoding, SigningScheme } from "./scheme.ts";
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/index.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,YAAY,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE9E,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/index.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,YAAY,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE9E,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC9G,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Digest encodings receivers actually use. Shopify signs base64; everyone else here is hex. */
|
|
2
|
+
export type DigestEncoding = "hex" | "base64";
|
|
3
|
+
/** The resolved, validated wire format for one webhook's signature. */
|
|
4
|
+
export interface SigningScheme {
|
|
5
|
+
readonly signedPayload: string;
|
|
6
|
+
readonly signatureTemplate: string;
|
|
7
|
+
readonly digestEncoding: DigestEncoding;
|
|
8
|
+
readonly algorithm: "sha256";
|
|
9
|
+
}
|
|
10
|
+
export declare const DEFAULT_SIGNED_PAYLOAD = "{timestamp}.{body}";
|
|
11
|
+
export declare const DEFAULT_SIGNATURE_TEMPLATE = "{algorithm}={signature}";
|
|
12
|
+
export declare const SIGNED_PAYLOAD_PLACEHOLDERS: readonly ["body", "timestamp", "timestampSeconds"];
|
|
13
|
+
export declare const SIGNATURE_TEMPLATE_PLACEHOLDERS: readonly ["signature", "algorithm", "timestamp", "timestampSeconds"];
|
|
14
|
+
/** Names appearing in `template` that are not in `allowed`, de-duplicated, first-seen order. */
|
|
15
|
+
export declare function unknownPlaceholders(template: string, allowed: readonly string[]): string[];
|
|
16
|
+
/**
|
|
17
|
+
* #30 finding 3 (review round 2): after stripping every well-formed `{...}` span the scanner
|
|
18
|
+
* matched, a leftover `{` immediately followed by an ASCII letter looks like a placeholder the
|
|
19
|
+
* author meant to close but didn't — e.g. `"{timestamp.{body}"` has its trailing `{body}`
|
|
20
|
+
* stripped, leaving residue `"{timestamp."`, whose leftover `{` precedes `t`. That signedPayload
|
|
21
|
+
* signs the literal text `{timestamp.` plus the body and references no `{timestamp}` placeholder
|
|
22
|
+
* `timestampUnitFor()` can see, so the timestamp header is silently dropped from the delivery.
|
|
23
|
+
*
|
|
24
|
+
* A JSON envelope's outer brace is NOT this shape: stripping `{"t":{timestamp},"b":{body}}`'s
|
|
25
|
+
* two placeholder spans leaves residue `{"t":,"b":}`, whose leftover `{` precedes `"` — not a
|
|
26
|
+
* letter — so it passes. Only a leftover `{` directly followed by a letter is flagged; `{"`,
|
|
27
|
+
* `{}` (already consumed above), and a trailing `{` are all legitimate JSON-envelope shapes.
|
|
28
|
+
*/
|
|
29
|
+
export declare function hasUnbalancedPlaceholder(template: string): boolean;
|
|
30
|
+
export declare function renderSignedPayload(template: string, v: {
|
|
31
|
+
body: string;
|
|
32
|
+
timestampMs: number;
|
|
33
|
+
}): string;
|
|
34
|
+
export declare function renderSignatureHeader(template: string, v: {
|
|
35
|
+
signature: string;
|
|
36
|
+
algorithm: string;
|
|
37
|
+
timestampMs: number;
|
|
38
|
+
}): string;
|
|
39
|
+
/**
|
|
40
|
+
* Which unit the standalone timestamp header should carry — or `null` when the scheme
|
|
41
|
+
* never references a timestamp, in which case no timestamp header is emitted at all.
|
|
42
|
+
* Emitting milliseconds beside a seconds-based signature is exactly the class of
|
|
43
|
+
* mismatch this feature exists to eliminate, so the unit follows the scheme.
|
|
44
|
+
*/
|
|
45
|
+
export declare function timestampUnitFor(scheme: Pick<SigningScheme, "signedPayload" | "signatureTemplate">): "ms" | "s" | null;
|
|
46
|
+
//# sourceMappingURL=scheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheme.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/scheme.ts"],"names":[],"mappings":"AAUA,gGAAgG;AAChG,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE9C,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC;CAC9B;AAGD,eAAO,MAAM,sBAAsB,uBAAuB,CAAC;AAE3D,eAAO,MAAM,0BAA0B,4BAA4B,CAAC;AAEpE,eAAO,MAAM,2BAA2B,oDAAqD,CAAC;AAC9F,eAAO,MAAM,+BAA+B,sEAKlC,CAAC;AAgBX,gGAAgG;AAChG,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAe1F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGlE;AAiBD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAMtG;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,CAAC,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC/D,MAAM,CAOR;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,eAAe,GAAG,mBAAmB,CAAC,GACjE,IAAI,GAAG,GAAG,GAAG,IAAI,CAKnB"}
|
|
@@ -1,23 +1,34 @@
|
|
|
1
|
+
import { type SigningScheme } from "./scheme.ts";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* The pre-#30 wire format: Stripe's signed payload, GitHub's header prefix, hex digest.
|
|
4
|
+
* Used when a caller supplies no scheme, so library embedders calling signPayload/
|
|
5
|
+
* verifySignature directly keep their v0.2.x behaviour.
|
|
6
|
+
*/
|
|
7
|
+
export declare const LEGACY_SCHEME: SigningScheme;
|
|
8
|
+
/**
|
|
9
|
+
* Sign a webhook payload under `scheme`.
|
|
3
10
|
*
|
|
4
|
-
* The signed string is
|
|
5
|
-
*
|
|
6
|
-
*
|
|
11
|
+
* The signed string is `scheme.signedPayload` with {body}/{timestamp}/{timestampSeconds}
|
|
12
|
+
* substituted; the digest is encoded per `scheme.digestEncoding`. Receivers verify by
|
|
13
|
+
* reconstructing the same string and comparing constant-time.
|
|
7
14
|
*
|
|
8
|
-
* Replay-window enforcement is the receiver's responsibility — but we emit the
|
|
9
|
-
*
|
|
10
|
-
* is 300_000ms (5 minutes), matching industry default.
|
|
15
|
+
* Replay-window enforcement is the receiver's responsibility — but we emit the timestamp
|
|
16
|
+
* (in the unit the scheme uses, see timestampUnitFor) so they CAN enforce it.
|
|
11
17
|
*/
|
|
12
|
-
export declare function signPayload(rawBody: string, secret: string, timestampMs: number): string;
|
|
18
|
+
export declare function signPayload(rawBody: string, secret: string, timestampMs: number, scheme?: SigningScheme): string;
|
|
13
19
|
/**
|
|
14
|
-
* Verify a signature constant-time
|
|
15
|
-
* equivalent logic in their own language. Exposed so tests
|
|
16
|
-
* can verify what we sent matches what we documented (S1 + RT-2 evidence).
|
|
20
|
+
* Verify a signature constant-time under the SAME scheme it was produced with. Used by
|
|
21
|
+
* tests; receivers will implement equivalent logic in their own language. Exposed so tests
|
|
22
|
+
* against this module can verify what we sent matches what we documented (S1 + RT-2 evidence).
|
|
23
|
+
*
|
|
24
|
+
* Returns false on length mismatch, encoding mismatch, or timing-safe-compare miss. Never throws.
|
|
17
25
|
*
|
|
18
|
-
*
|
|
26
|
+
* This helper exists for tests and receiver-side reuse and is **not hardened for adversarial
|
|
27
|
+
* input**: in particular, `Buffer.from(x, "base64")` silently discards non-canonical trailing
|
|
28
|
+
* bits, so a non-canonical base64 variant can decode to the same bytes and compare equal. Real
|
|
29
|
+
* receivers should compare the encoded strings themselves, not just the decoded buffers.
|
|
19
30
|
*/
|
|
20
|
-
export declare function verifySignature(rawBody: string, secret: string, timestampMs: number,
|
|
31
|
+
export declare function verifySignature(rawBody: string, secret: string, timestampMs: number, signature: string, scheme?: SigningScheme): boolean;
|
|
21
32
|
/** Replay-window check helper — returns false if `timestampMs` is outside `[now - windowMs, now + skewMs]`. */
|
|
22
33
|
export declare function withinReplayWindow(timestampMs: number, windowMs: number, nowMs?: number, futureSkewMs?: number): boolean;
|
|
23
34
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/signing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/signing.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,KAAK,aAAa,EAEnB,MAAM,aAAa,CAAC;AAErB;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,aAK1B,CAAC;AAEH;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,aAA6B,GACpC,MAAM,CAGR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,MAAM,GAAE,aAA6B,GACpC,OAAO,CAaT;AAED,+GAA+G;AAC/G,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,KAAK,GAAE,MAAmB,EAC1B,YAAY,SAAS,GACpB,OAAO,CAGT;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAsBvD"}
|
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
import type { CompiledTemplate } from "../../core/templating/index.ts";
|
|
2
|
+
import type { DigestEncoding } from "./scheme.ts";
|
|
2
3
|
/** Terminal outcome of a delivery — every delivery resolves to exactly one of these. */
|
|
3
4
|
export type DeliveryOutcome = "success" | "failed" | "dropped" | "circuit-open";
|
|
4
5
|
/** Signing config for a single webhook. Off unless explicitly enabled (S1). */
|
|
5
6
|
export interface WebhookSigningSpec {
|
|
7
|
+
/** Signature mechanism. Only `hmac` in v0.x; the union exists so ed25519/oidc can follow (#30). */
|
|
8
|
+
mode: "hmac";
|
|
6
9
|
enabled: boolean;
|
|
7
10
|
/** Algorithm — only sha256 supported in v0.x. */
|
|
8
11
|
algorithm: "sha256";
|
|
9
12
|
/** Secret reference: must be `{{ env.NAME }}` form OR a file:// path. Inline strings rejected at config load (S3). */
|
|
10
13
|
secretRef: string;
|
|
11
|
-
/**
|
|
14
|
+
/** Template for the bytes fed to HMAC. Default `{timestamp}.{body}`. */
|
|
15
|
+
signedPayload: string;
|
|
16
|
+
/** Template for the signature header VALUE. Default `{algorithm}={signature}`. */
|
|
17
|
+
signatureTemplate: string;
|
|
18
|
+
/** Digest encoding. Default `hex`; `base64` for Shopify-style receivers. */
|
|
19
|
+
digestEncoding: DigestEncoding;
|
|
20
|
+
/** Header carrying the rendered signature. Default: x-mockstar-signature. */
|
|
12
21
|
signatureHeader: string;
|
|
13
|
-
/**
|
|
14
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Header carrying the timestamp, in the unit the scheme signs. `null` means: never emit a
|
|
24
|
+
* standalone timestamp header (e.g. Stripe carries its timestamp inside the signature header
|
|
25
|
+
* itself). Independently, no header is emitted when the scheme signs no timestamp at all,
|
|
26
|
+
* regardless of this field — see `timestampUnitFor` in scheme.ts.
|
|
27
|
+
*/
|
|
28
|
+
timestampHeader: string | null;
|
|
15
29
|
/** Replay window in ms. Default: 300_000 (5 minutes). Receiver should check timestamp delta. */
|
|
16
30
|
replayWindowMs: number;
|
|
17
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,wFAAwF;AACxF,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,QAAQ,GACR,SAAS,GACT,cAAc,CAAC;AAEnB,+EAA+E;AAC/E,MAAM,WAAW,kBAAkB;IACjC,mGAAmG;IACnG,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,SAAS,EAAE,QAAQ,CAAC;IAC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IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,qGAAqG;IACrG,UAAU,EAAE,MAAM,CAAC;IACnB,4GAA4G;IAC5G,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,gBAAgB,EAAE,MAAM,CAAC;IACzB,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,eAAe,CAAC;IACzB,0GAA0G;IAC1G,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mFAAmF;IACnF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iGAAiG;IACjG,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,mFAAmF;AACnF,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,eAAe,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -27,4 +27,6 @@ export interface Launched {
|
|
|
27
27
|
export declare function launch(opts: LaunchOptions): Promise<Launched>;
|
|
28
28
|
export type { RunningServer, CreateServerOptions } from "./server.ts";
|
|
29
29
|
export { SnapshotHolder } from "./core/config/index.ts";
|
|
30
|
+
export { signPayload, verifySignature, withinReplayWindow, LEGACY_SCHEME, } from "./features/webhooks/signing.ts";
|
|
31
|
+
export type { SigningScheme, DigestEncoding } from "./features/webhooks/scheme.ts";
|
|
30
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAiD,MAAM,wBAAwB,CAAC;AAEvG,OAAO,EAAE,KAAK,gBAAgB,EAAgB,MAAM,+BAA+B,CAAC;AAEpF,OAAO,EAA4B,KAAK,aAAa,EAAgB,MAAM,aAAa,CAAC;AAEzF,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,2EAA2E;IAC3E,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,kGAAkG;IAClG,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;CACjC;AAED;;;GAGG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmDnE;AAED,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC"}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AM,+BAA+B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -667,9 +667,13 @@ function compileOne(spec) {
|
|
|
667
667
|
jitterRatio: spec.retry.jitterRatio
|
|
668
668
|
},
|
|
669
669
|
signing: spec.signing ? {
|
|
670
|
+
mode: spec.signing.mode,
|
|
670
671
|
enabled: spec.signing.enabled,
|
|
671
672
|
algorithm: spec.signing.algorithm,
|
|
672
673
|
secretRef: spec.signing.secretRef,
|
|
674
|
+
signedPayload: spec.signing.signedPayload,
|
|
675
|
+
signatureTemplate: spec.signing.signatureTemplate,
|
|
676
|
+
digestEncoding: spec.signing.digestEncoding,
|
|
673
677
|
signatureHeader: spec.signing.signatureHeader,
|
|
674
678
|
timestampHeader: spec.signing.timestampHeader,
|
|
675
679
|
replayWindowMs: spec.signing.replayWindowMs
|
|
@@ -6533,6 +6537,63 @@ var coerce = {
|
|
|
6533
6537
|
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
6534
6538
|
};
|
|
6535
6539
|
var NEVER = INVALID;
|
|
6540
|
+
// src/features/webhooks/scheme.ts
|
|
6541
|
+
var DEFAULT_SIGNED_PAYLOAD = "{timestamp}.{body}";
|
|
6542
|
+
var DEFAULT_SIGNATURE_TEMPLATE = "{algorithm}={signature}";
|
|
6543
|
+
var SIGNED_PAYLOAD_PLACEHOLDERS = ["body", "timestamp", "timestampSeconds"];
|
|
6544
|
+
var SIGNATURE_TEMPLATE_PLACEHOLDERS = [
|
|
6545
|
+
"signature",
|
|
6546
|
+
"algorithm",
|
|
6547
|
+
"timestamp",
|
|
6548
|
+
"timestampSeconds"
|
|
6549
|
+
];
|
|
6550
|
+
var PLACEHOLDER_RE = /\{([A-Za-z][A-Za-z0-9]*)\}/g;
|
|
6551
|
+
var UNKNOWN_PLACEHOLDER_SCAN_RE = /\{[^{}]*\}/g;
|
|
6552
|
+
function unknownPlaceholders(template, allowed) {
|
|
6553
|
+
const seen = new Set;
|
|
6554
|
+
const out = [];
|
|
6555
|
+
for (const match of template.matchAll(UNKNOWN_PLACEHOLDER_SCAN_RE)) {
|
|
6556
|
+
const name = match[0].slice(1, -1);
|
|
6557
|
+
if (name === "")
|
|
6558
|
+
continue;
|
|
6559
|
+
if (allowed.includes(name) || seen.has(name))
|
|
6560
|
+
continue;
|
|
6561
|
+
seen.add(name);
|
|
6562
|
+
out.push(name);
|
|
6563
|
+
}
|
|
6564
|
+
return out;
|
|
6565
|
+
}
|
|
6566
|
+
function hasUnbalancedPlaceholder(template) {
|
|
6567
|
+
const residue = template.replace(UNKNOWN_PLACEHOLDER_SCAN_RE, "");
|
|
6568
|
+
return /\{[A-Za-z]/.test(residue);
|
|
6569
|
+
}
|
|
6570
|
+
function substitute(template, values) {
|
|
6571
|
+
return template.replace(PLACEHOLDER_RE, (match, name) => Object.hasOwn(values, name) ? values[name] : match);
|
|
6572
|
+
}
|
|
6573
|
+
function renderSignedPayload(template, v) {
|
|
6574
|
+
return substitute(template, {
|
|
6575
|
+
body: v.body,
|
|
6576
|
+
timestamp: String(v.timestampMs),
|
|
6577
|
+
timestampSeconds: String(Math.floor(v.timestampMs / 1000))
|
|
6578
|
+
});
|
|
6579
|
+
}
|
|
6580
|
+
function renderSignatureHeader(template, v) {
|
|
6581
|
+
return substitute(template, {
|
|
6582
|
+
signature: v.signature,
|
|
6583
|
+
algorithm: v.algorithm,
|
|
6584
|
+
timestamp: String(v.timestampMs),
|
|
6585
|
+
timestampSeconds: String(Math.floor(v.timestampMs / 1000))
|
|
6586
|
+
});
|
|
6587
|
+
}
|
|
6588
|
+
function timestampUnitFor(scheme) {
|
|
6589
|
+
const combined = `${scheme.signedPayload} ${scheme.signatureTemplate}`;
|
|
6590
|
+
if (combined.includes("{timestamp}"))
|
|
6591
|
+
return "ms";
|
|
6592
|
+
if (combined.includes("{timestampSeconds}"))
|
|
6593
|
+
return "s";
|
|
6594
|
+
return null;
|
|
6595
|
+
}
|
|
6596
|
+
|
|
6536
6597
|
// src/core/config/schema.ts
|
|
6537
6598
|
var MatchMethod = exports_external.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "*"]);
|
|
6538
6599
|
var StringMatch = exports_external.union([
|
|
@@ -6614,16 +6675,105 @@ var ScenarioRule = exports_external.object({
|
|
|
6614
6675
|
response: ScenarioResponse
|
|
6615
6676
|
}).strict();
|
|
6616
6677
|
var SECRET_REF_RE = /^(\{\{\s*env\.[A-Z_][A-Z0-9_]*\s*\}\}|file:.+)$/;
|
|
6617
|
-
var
|
|
6678
|
+
var HmacSigning = exports_external.object({
|
|
6679
|
+
mode: exports_external.literal("hmac").default("hmac"),
|
|
6618
6680
|
enabled: exports_external.boolean().default(false),
|
|
6619
6681
|
algorithm: exports_external.literal("sha256").default("sha256"),
|
|
6620
6682
|
secretRef: exports_external.string().regex(SECRET_REF_RE, {
|
|
6621
6683
|
message: "webhook signing.secretRef must be `{{ env.NAME }}` or `file:/path`; inline secrets rejected (S3)"
|
|
6622
6684
|
}),
|
|
6685
|
+
signedPayload: exports_external.string().min(1).default(DEFAULT_SIGNED_PAYLOAD),
|
|
6686
|
+
signatureTemplate: exports_external.string().min(1).default(DEFAULT_SIGNATURE_TEMPLATE),
|
|
6687
|
+
digestEncoding: exports_external.enum(["hex", "base64"]).default("hex"),
|
|
6623
6688
|
signatureHeader: exports_external.string().min(1).default("x-mockstar-signature"),
|
|
6624
|
-
timestampHeader: exports_external.string().min(1).default("x-mockstar-timestamp"),
|
|
6689
|
+
timestampHeader: exports_external.string().min(1).nullable().default("x-mockstar-timestamp"),
|
|
6625
6690
|
replayWindowMs: exports_external.number().int().positive().default(300000)
|
|
6626
6691
|
}).strict();
|
|
6692
|
+
var WebhookSigning = exports_external.preprocess((raw) => raw !== null && typeof raw === "object" && !Array.isArray(raw) && !("mode" in raw) ? { ...raw, mode: "hmac" } : raw, exports_external.discriminatedUnion("mode", [HmacSigning])).superRefine((v, ctx) => {
|
|
6693
|
+
if (typeof v.signedPayload !== "string" || typeof v.signatureTemplate !== "string")
|
|
6694
|
+
return;
|
|
6695
|
+
const fmt = (names) => names.map((n) => `{${n}}`).join(", ");
|
|
6696
|
+
const signedPayloadHasDoubleBrace = v.signedPayload.includes("{{");
|
|
6697
|
+
if (signedPayloadHasDoubleBrace) {
|
|
6698
|
+
ctx.addIssue({
|
|
6699
|
+
code: exports_external.ZodIssueCode.custom,
|
|
6700
|
+
path: ["signedPayload"],
|
|
6701
|
+
message: "signedPayload uses single-brace placeholders (e.g. {body}), not the {{ }} request-template syntax \u2014 did you mean {body} instead of {{ body }}?"
|
|
6702
|
+
});
|
|
6703
|
+
}
|
|
6704
|
+
const signatureTemplateHasDoubleBrace = v.signatureTemplate.includes("{{");
|
|
6705
|
+
if (signatureTemplateHasDoubleBrace) {
|
|
6706
|
+
ctx.addIssue({
|
|
6707
|
+
code: exports_external.ZodIssueCode.custom,
|
|
6708
|
+
path: ["signatureTemplate"],
|
|
6709
|
+
message: "signatureTemplate uses single-brace placeholders (e.g. {signature}), not the {{ }} request-template syntax \u2014 did you mean {signature} instead of {{ signature }}?"
|
|
6710
|
+
});
|
|
6711
|
+
}
|
|
6712
|
+
const signedPayloadHasTemplateLiteral = v.signedPayload.includes("${");
|
|
6713
|
+
if (signedPayloadHasTemplateLiteral) {
|
|
6714
|
+
ctx.addIssue({
|
|
6715
|
+
code: exports_external.ZodIssueCode.custom,
|
|
6716
|
+
path: ["signedPayload"],
|
|
6717
|
+
message: "signedPayload uses single-brace placeholders (e.g. {body}), not JS template-literal syntax \u2014 did you mean {body} instead of ${body}?"
|
|
6718
|
+
});
|
|
6719
|
+
}
|
|
6720
|
+
const signatureTemplateHasTemplateLiteral = v.signatureTemplate.includes("${");
|
|
6721
|
+
if (signatureTemplateHasTemplateLiteral) {
|
|
6722
|
+
ctx.addIssue({
|
|
6723
|
+
code: exports_external.ZodIssueCode.custom,
|
|
6724
|
+
path: ["signatureTemplate"],
|
|
6725
|
+
message: "signatureTemplate uses single-brace placeholders (e.g. {signature}), not JS template-literal syntax \u2014 did you mean {signature} instead of ${signature}?"
|
|
6726
|
+
});
|
|
6727
|
+
}
|
|
6728
|
+
if (!signedPayloadHasDoubleBrace && !signedPayloadHasTemplateLiteral) {
|
|
6729
|
+
const badPayload = unknownPlaceholders(v.signedPayload, SIGNED_PAYLOAD_PLACEHOLDERS);
|
|
6730
|
+
if (badPayload.length > 0) {
|
|
6731
|
+
ctx.addIssue({
|
|
6732
|
+
code: exports_external.ZodIssueCode.custom,
|
|
6733
|
+
path: ["signedPayload"],
|
|
6734
|
+
message: `unknown placeholder(s) ${fmt(badPayload)} \u2014 allowed: ${fmt(SIGNED_PAYLOAD_PLACEHOLDERS)}`
|
|
6735
|
+
});
|
|
6736
|
+
}
|
|
6737
|
+
if (!v.signedPayload.includes("{body}")) {
|
|
6738
|
+
ctx.addIssue({
|
|
6739
|
+
code: exports_external.ZodIssueCode.custom,
|
|
6740
|
+
path: ["signedPayload"],
|
|
6741
|
+
message: "signedPayload must contain {body} \u2014 otherwise the signature covers no request content"
|
|
6742
|
+
});
|
|
6743
|
+
}
|
|
6744
|
+
if (hasUnbalancedPlaceholder(v.signedPayload)) {
|
|
6745
|
+
ctx.addIssue({
|
|
6746
|
+
code: exports_external.ZodIssueCode.custom,
|
|
6747
|
+
path: ["signedPayload"],
|
|
6748
|
+
message: "signedPayload has an unmatched { that looks like an unterminated placeholder \u2014 check for a missing closing brace"
|
|
6749
|
+
});
|
|
6750
|
+
}
|
|
6751
|
+
}
|
|
6752
|
+
if (!signatureTemplateHasDoubleBrace && !signatureTemplateHasTemplateLiteral) {
|
|
6753
|
+
const badTemplate = unknownPlaceholders(v.signatureTemplate, SIGNATURE_TEMPLATE_PLACEHOLDERS);
|
|
6754
|
+
if (badTemplate.length > 0) {
|
|
6755
|
+
ctx.addIssue({
|
|
6756
|
+
code: exports_external.ZodIssueCode.custom,
|
|
6757
|
+
path: ["signatureTemplate"],
|
|
6758
|
+
message: `unknown placeholder(s) ${fmt(badTemplate)} \u2014 allowed: ${fmt(SIGNATURE_TEMPLATE_PLACEHOLDERS)}`
|
|
6759
|
+
});
|
|
6760
|
+
}
|
|
6761
|
+
if (!v.signatureTemplate.includes("{signature}")) {
|
|
6762
|
+
ctx.addIssue({
|
|
6763
|
+
code: exports_external.ZodIssueCode.custom,
|
|
6764
|
+
path: ["signatureTemplate"],
|
|
6765
|
+
message: "signatureTemplate must contain {signature} \u2014 otherwise the signature header carries no digest"
|
|
6766
|
+
});
|
|
6767
|
+
}
|
|
6768
|
+
if (hasUnbalancedPlaceholder(v.signatureTemplate)) {
|
|
6769
|
+
ctx.addIssue({
|
|
6770
|
+
code: exports_external.ZodIssueCode.custom,
|
|
6771
|
+
path: ["signatureTemplate"],
|
|
6772
|
+
message: "signatureTemplate has an unmatched { that looks like an unterminated placeholder \u2014 check for a missing closing brace"
|
|
6773
|
+
});
|
|
6774
|
+
}
|
|
6775
|
+
}
|
|
6776
|
+
});
|
|
6627
6777
|
var WebhookRetry = exports_external.object({
|
|
6628
6778
|
attempts: exports_external.number().int().min(1).max(20).default(6),
|
|
6629
6779
|
backoff: exports_external.array(exports_external.number().int().nonnegative()).default([1000, 2000, 4000, 8000, 16000]),
|
|
@@ -11109,7 +11259,7 @@ function adminRouter(deps) {
|
|
|
11109
11259
|
entryId,
|
|
11110
11260
|
id: spec.id,
|
|
11111
11261
|
method: spec.method,
|
|
11112
|
-
signing: spec.signing ? { enabled: spec.signing.enabled, algorithm: spec.signing.algorithm } : null,
|
|
11262
|
+
signing: spec.signing ? { mode: spec.signing.mode, enabled: spec.signing.enabled, algorithm: spec.signing.algorithm } : null,
|
|
11113
11263
|
retry: { attempts: spec.retry.attempts },
|
|
11114
11264
|
circuit: spec.circuit,
|
|
11115
11265
|
timeoutMs: spec.timeoutMs,
|
|
@@ -12185,9 +12335,33 @@ class WebhookJournalRegistry {
|
|
|
12185
12335
|
}
|
|
12186
12336
|
// src/features/webhooks/signing.ts
|
|
12187
12337
|
import { createHmac, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
12188
|
-
|
|
12189
|
-
|
|
12190
|
-
|
|
12338
|
+
var LEGACY_SCHEME = Object.freeze({
|
|
12339
|
+
signedPayload: DEFAULT_SIGNED_PAYLOAD,
|
|
12340
|
+
signatureTemplate: DEFAULT_SIGNATURE_TEMPLATE,
|
|
12341
|
+
digestEncoding: "hex",
|
|
12342
|
+
algorithm: "sha256"
|
|
12343
|
+
});
|
|
12344
|
+
function signPayload(rawBody, secret, timestampMs, scheme = LEGACY_SCHEME) {
|
|
12345
|
+
const stringToSign = renderSignedPayload(scheme.signedPayload, { body: rawBody, timestampMs });
|
|
12346
|
+
return createHmac(scheme.algorithm, secret).update(stringToSign, "utf8").digest(scheme.digestEncoding);
|
|
12347
|
+
}
|
|
12348
|
+
function verifySignature(rawBody, secret, timestampMs, signature, scheme = LEGACY_SCHEME) {
|
|
12349
|
+
try {
|
|
12350
|
+
const expected = signPayload(rawBody, secret, timestampMs, scheme);
|
|
12351
|
+
if (expected.length !== signature.length)
|
|
12352
|
+
return false;
|
|
12353
|
+
const a2 = Buffer.from(expected, scheme.digestEncoding);
|
|
12354
|
+
const b2 = Buffer.from(signature, scheme.digestEncoding);
|
|
12355
|
+
if (a2.length !== b2.length || a2.length === 0)
|
|
12356
|
+
return false;
|
|
12357
|
+
return timingSafeEqual2(a2, b2);
|
|
12358
|
+
} catch {
|
|
12359
|
+
return false;
|
|
12360
|
+
}
|
|
12361
|
+
}
|
|
12362
|
+
function withinReplayWindow(timestampMs, windowMs, nowMs = Date.now(), futureSkewMs = 60000) {
|
|
12363
|
+
const delta = nowMs - timestampMs;
|
|
12364
|
+
return delta <= windowMs && delta >= -futureSkewMs;
|
|
12191
12365
|
}
|
|
12192
12366
|
function resolveSecret(secretRef) {
|
|
12193
12367
|
const envMatch = secretRef.match(/^\{\{\s*env\.([A-Z_][A-Z0-9_]*)\s*\}\}$/);
|
|
@@ -12268,9 +12442,23 @@ async function performAttempt(spec, input, _deps) {
|
|
|
12268
12442
|
if (spec.signing?.enabled) {
|
|
12269
12443
|
const secret = resolveSecret(spec.signing.secretRef);
|
|
12270
12444
|
const timestampMs = Date.now();
|
|
12271
|
-
const
|
|
12272
|
-
|
|
12273
|
-
|
|
12445
|
+
const scheme = {
|
|
12446
|
+
signedPayload: spec.signing.signedPayload,
|
|
12447
|
+
signatureTemplate: spec.signing.signatureTemplate,
|
|
12448
|
+
digestEncoding: spec.signing.digestEncoding,
|
|
12449
|
+
algorithm: spec.signing.algorithm
|
|
12450
|
+
};
|
|
12451
|
+
const signature = signPayload(rawBody, secret, timestampMs, scheme);
|
|
12452
|
+
renderedHeaders.set(spec.signing.signatureHeader, renderSignatureHeader(scheme.signatureTemplate, {
|
|
12453
|
+
signature,
|
|
12454
|
+
algorithm: scheme.algorithm,
|
|
12455
|
+
timestampMs
|
|
12456
|
+
}));
|
|
12457
|
+
const unit = timestampUnitFor(scheme);
|
|
12458
|
+
if (unit !== null && spec.signing.timestampHeader !== null) {
|
|
12459
|
+
const value = unit === "s" ? Math.floor(timestampMs / 1000) : timestampMs;
|
|
12460
|
+
renderedHeaders.set(spec.signing.timestampHeader, String(value));
|
|
12461
|
+
}
|
|
12274
12462
|
}
|
|
12275
12463
|
if (!renderedHeaders.has("x-mockstar-delivery-id")) {
|
|
12276
12464
|
renderedHeaders.set("x-mockstar-delivery-id", input.triggerRequestId);
|
|
@@ -12808,6 +12996,10 @@ async function launch(opts) {
|
|
|
12808
12996
|
};
|
|
12809
12997
|
}
|
|
12810
12998
|
export {
|
|
12999
|
+
withinReplayWindow,
|
|
13000
|
+
verifySignature,
|
|
13001
|
+
signPayload,
|
|
12811
13002
|
launch,
|
|
12812
|
-
SnapshotHolder
|
|
13003
|
+
SnapshotHolder,
|
|
13004
|
+
LEGACY_SCHEME
|
|
12813
13005
|
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const MOCKSTAR_VERSION = "0.
|
|
1
|
+
export declare const MOCKSTAR_VERSION = "0.3.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhaneshpurohit/mockstar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Bun-based mock server with static + dynamic mocking, JSON config, named JS handlers, pass-through, multi-tenancy, and test-data utilities.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/dhanesh/mockstar.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/dhanesh/mockstar#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/dhanesh/mockstar/issues"
|
|
13
|
+
},
|
|
6
14
|
"type": "module",
|
|
7
15
|
"types": "./dist/index.d.ts",
|
|
8
16
|
"bin": {
|
|
@@ -31,6 +39,7 @@
|
|
|
31
39
|
"bench": "bun run bench/harness.ts",
|
|
32
40
|
"bench:proxy": "bun run bench/proxy.bench.ts",
|
|
33
41
|
"typecheck": "tsc --noEmit",
|
|
42
|
+
"verify": "bun run lint && bun run typecheck && bun run build && bun run test",
|
|
34
43
|
"lint": "bunx @biomejs/biome check src tests bench",
|
|
35
44
|
"format": "bunx @biomejs/biome format --write src tests bench"
|
|
36
45
|
},
|