@pithy-sh/payments 0.2.0 → 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/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +3 -0
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +2 -1
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +32 -1
- package/dist/http/webhookGuard.d.ts +9 -6
- package/dist/http/webhookGuard.d.ts.map +1 -1
- package/dist/http/webhookGuard.js +44 -8
- package/dist/rails/apple/x509.d.ts.map +1 -1
- package/dist/rails/apple/x509.js +6 -0
- package/dist/rails/google/oidc.d.ts +91 -31
- package/dist/rails/google/oidc.d.ts.map +1 -1
- package/dist/rails/google/oidc.js +144 -127
- package/dist/rails/google/playApi.js +1 -1
- package/dist/rails/google/rail.d.ts +25 -0
- package/dist/rails/google/rail.d.ts.map +1 -1
- package/dist/rails/google/rail.js +2 -1
- package/dist/rails/paddle/rail.d.ts +10 -1
- package/dist/rails/paddle/rail.d.ts.map +1 -1
- package/dist/rails/paddle/signature.d.ts +8 -2
- package/dist/rails/paddle/signature.d.ts.map +1 -1
- package/dist/rails/paddle/signature.js +17 -2
- package/dist/rails/providers.d.ts +15 -0
- package/dist/rails/providers.d.ts.map +1 -1
- package/dist/rails/providers.js +2 -1
- package/dist/rails/stripe/rail.d.ts +11 -1
- package/dist/rails/stripe/rail.d.ts.map +1 -1
- package/dist/rails/stripe/signature.d.ts +8 -1
- package/dist/rails/stripe/signature.d.ts.map +1 -1
- package/dist/secret/branches.d.ts +39 -0
- package/dist/secret/branches.d.ts.map +1 -0
- package/dist/secret/branches.js +46 -0
- package/dist/secret/registry.d.ts.map +1 -1
- package/dist/secret/registry.js +15 -15
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/package.json +11 -9
- package/src/capability.ts +7 -0
- package/src/config/config.ts +10 -1
- package/src/http/routes.ts +32 -1
- package/src/http/webhookGuard.ts +40 -7
- package/src/rails/apple/x509.ts +18 -0
- package/src/rails/google/oidc.ts +194 -218
- package/src/rails/google/rail.ts +28 -0
- package/src/rails/paddle/rail.ts +10 -1
- package/src/rails/paddle/signature.ts +39 -3
- package/src/rails/providers.ts +16 -0
- package/src/rails/stripe/rail.ts +11 -1
- package/src/rails/stripe/signature.ts +8 -1
- package/src/secret/branches.ts +48 -0
- package/src/secret/registry.ts +24 -2
- package/src/version.generated.ts +1 -1
package/dist/capability.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAI3E,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,KAAK,EAAE,uBAAuB,EAAuB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAI3E,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,KAAK,EAAE,uBAAuB,EAAuB,MAAM,2BAA2B,CAAC;AAU9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAK7C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG;IAClD;;;;OAIG;IACH,cAAc,CAAC,EAAE,uBAAuB,CAAC;CAC1C,CAAC;AAsMF,6FAA6F;AAC7F,MAAM,WAAW,kBACf,SAAQ,UAAU,CAAC,eAAe,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,iBAAiB,CAAC;IAC7F,4BAA4B;IAC5B,cAAc,EAAE,cAAc,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,kBAAkB,CAmGrE;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,kBAAkB,CAE7F"}
|
package/dist/capability.js
CHANGED
|
@@ -10,6 +10,7 @@ import { paymentsWorkflows } from "./workflows/specs.js";
|
|
|
10
10
|
import { paymentsAdminRoutes } from "./http/scopes.js";
|
|
11
11
|
import { registerPaymentsRoutes } from "./http/routes.js";
|
|
12
12
|
import { payments_0001_purchases } from "./migrations/0001_purchases.js";
|
|
13
|
+
import { paymentsInapplicableSecrets, paymentsSecretBranches } from "./secret/branches.js";
|
|
13
14
|
import { paymentsExampleSeed } from "./seeds/example.js";
|
|
14
15
|
import { PACKAGE_VERSION } from "./version.generated.js";
|
|
15
16
|
import { defineCapability } from "@pithy-sh/core/src/capability/capability";
|
|
@@ -211,6 +212,8 @@ function payments(options) {
|
|
|
211
212
|
dependsOn: ["secrets"],
|
|
212
213
|
providesEntitlements: true,
|
|
213
214
|
secretRegistry: paymentsSecretsRegistry,
|
|
215
|
+
secretBranches: paymentsSecretBranches(resolved.rails),
|
|
216
|
+
inapplicableSecrets: paymentsInapplicableSecrets(resolved.rails),
|
|
214
217
|
workflows: paymentsWorkflows,
|
|
215
218
|
compose: (context) => checkLedgerGrants(context, resolved),
|
|
216
219
|
boot: () => requireImplementedSubject(resolveSubject),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAoCjE,eAAO,MAAM,mBAAmB;;;;;;iBA6B+E,CAAC;AAChH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEtE,eAAO,MAAM,mBAAmB;;;;EAI7B,CAAC;AACJ,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEtE,eAAO,MAAM,oBAAoB;;iBAQyE,CAAC;AAC3G,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,eAAO,MAAM,qBAAqB;;iBAQuE,CAAC;AAC1G,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE1E,eAAO,MAAM,qBAAqB;;iBAUkE,CAAC;AACrG,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE1E,eAAO,MAAM,2BAA2B;;iBAUgE,CAAC;AACzG,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEtF,eAAO,MAAM,4BAA4B;;;iBAetC,CAAC;AACJ,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAExF,eAAO,MAAM,qBAAqB;;iBAUkE,CAAC;AACrG,MAAM,MAAM,qBAA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AAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAC3E,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEjF;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,wFAAwF;IACxF,EAAE,EAAE,MAAM,CAAC;IACX,gCAAgC;IAChC,OAAO,EAAE,eAAe,CAAC;CAC1B;AAED,yGAAyG;AACzG,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAalG;AAED,wGAAwG;AACxG,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAGnG;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE,MAAM,GACV,oBAAoB,GAAG,SAAS,CAKlC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,WAAW,CAAC,MAAM,CAAC,CAIjF;AAED,8GAA8G;AAC9G,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAE5F;AAED,sGAAsG;AACtG,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAE/E"}
|
package/dist/config/config.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { PAYMENTS_RAILS } from "../data/rail.js";
|
|
4
4
|
import { PaymentsSubjectType } from "../data/subject.js";
|
|
5
5
|
import { EntitlementKey } from "@pithy-sh/core/src/entitlement/entitlement";
|
|
6
|
+
import { SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS } from "@pithy-sh/core/src/http/webhookWindow";
|
|
6
7
|
import { z } from "zod";
|
|
7
8
|
//#region src/config/config.ts
|
|
8
9
|
/**
|
|
@@ -61,7 +62,7 @@ const PaymentsPaddleSettings = z.strictObject({
|
|
|
61
62
|
environment: z.enum(["sandbox", "production"]).describe("Which Paddle account this project sells through. Paddle Billing partitions sandbox from live by account — separate host, separate key, separate notification destinations — so this decides both the API host and every purchase's recorded environment. There is no `mode` field on a Paddle payload that could contradict it."),
|
|
62
63
|
successUrl: ReturnUrl.describe("Where a buyer lands after paying. Used as `settings.successUrl` for Paddle.js and as the redirect target in `hosted` mode. Build it on `PUBLIC_ORIGIN`, never on a literal."),
|
|
63
64
|
cancelUrl: ReturnUrl.optional().describe("Where a buyer who backs out lands, in `hosted` mode. Optional, because an overlay a buyer closes leaves them exactly where they were."),
|
|
64
|
-
webhookFreshnessSeconds: z.number().int().positive().optional().describe(
|
|
65
|
+
webhookFreshnessSeconds: z.number().int().positive().optional().describe(`How many seconds either side of now a delivery's \`ts\` may be dated. Omitted uses 300, deliberately not the 5 Paddle's own SDKs use: replay protection here is the webhook table's \`UNIQUE (rail, providerEventId)\`, which is absolute, and a five-second window adds nothing to that while turning ordinary clock skew into a dropped renewal. Bounded at ${SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS} because a freshness window is a replay window: every second of it is a second longer a captured delivery keeps working. That bound is enforced by the verifier rather than by this schema, so a number past it refuses the Paddle webhook route with \`core/internal\` naming this key, instead of refusing to boot the Worker.`),
|
|
65
66
|
storeCurrency: z.string().regex(CURRENCY_CODE_PATTERN, "A currency code is lowercase, digits, and dashes.").optional().describe("The currency this Paddle catalog prices in, lowercase ISO 4217 — `usd`. Optional, and the only thing it does is let a fixed-amount discount in another currency be refused when it is created rather than when a customer redeems it. Paddle accepts the mismatched object and fails at redemption, so without this the error arrives at the buyer instead of at you.")
|
|
66
67
|
}).describe("How this project sells through Paddle. `strictObject`, and that is what refuses `portalReturnUrl`: Paddle's customer portal takes no return parameter, so accepting one and dropping it would leave a URL an adopter wrote and believed in that nothing ever reads — a lie in a file they trust.");
|
|
67
68
|
const PaymentsStripeSettings = z.object({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/http/routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/http/routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAU7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,EAEL,KAAK,cAAc,EAKpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EAGL,KAAK,eAAe,EAGrB,MAAM,iBAAiB,CAAC;AAUzB,OAAO,EAAE,KAAK,mBAAmB,EAAkD,MAAM,4BAA4B,CAAC;AA0BtH,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,oBAAoB,CAAC;AA2EhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsJG;AACH,MAAM,WAAW,qBAAqB;IACpC,4BAA4B;IAC5B,MAAM,EAAE,cAAc,CAAC;IACvB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oGAAoG;IACpG,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B;AA2JD;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IACE,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,qCAAqC;IACrC,KAAK,EAAE,KAAK,CAAC;IACb,4GAA4G;IAC5G,QAAQ,EAAE,gBAAgB,CAAC;CAC5B,GACD;IACE,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd,8FAA8F;IAC9F,SAAS,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACxC,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAsB,sBAAsB,CAC1C,EAAE,EAAE,UAAU,EACd,OAAO,EAAE,eAAe,EACxB,GAAG,EAAE,IAAI,GACR,OAAO,CAAC,kBAAkB,CAAC,CA4B7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,UAAU,EACd,OAAO,EAAE,eAAe,EACxB,YAAY,EAAE,gBAAgB,GAC7B,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC,CAmBtC;AAkPD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,qBAAqB,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAi/DxG"}
|
package/dist/http/routes.js
CHANGED
|
@@ -30,6 +30,7 @@ import { InternalError, NotFoundError, PithyError, ValidationError } from "@pith
|
|
|
30
30
|
import { zValidator } from "@hono/zod-validator";
|
|
31
31
|
import { safeEmit } from "@pithy-sh/core/src/controlPlane/audit/actions";
|
|
32
32
|
import { requireControlPlane } from "@pithy-sh/core/src/controlPlane/http/guard";
|
|
33
|
+
import { memoryJwksCache } from "@pithy-sh/core/src/http/oidcWebhook";
|
|
33
34
|
import { validationHook } from "@pithy-sh/core/src/http/validation";
|
|
34
35
|
import { resolveWorkflowBinding } from "@pithy-sh/core/src/workflow/dispatch";
|
|
35
36
|
import { sharedSecretsStore } from "@pithy-sh/secrets/src/sharedSecretsStore";
|
|
@@ -501,7 +502,37 @@ function registerPaymentsRoutes(options) {
|
|
|
501
502
|
const { config } = options;
|
|
502
503
|
const base = options.basePath ?? config.basePath;
|
|
503
504
|
const clock = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
504
|
-
|
|
505
|
+
/**
|
|
506
|
+
* The caller's seams, plus the one thing a per-request rail cannot own: Google's key store.
|
|
507
|
+
*
|
|
508
|
+
* **Built here because this is the first thing in the chain that outlives a request.** `payments()` calls
|
|
509
|
+
* `registerPaymentsRoutes` once, at composition, so this object is constructed once per isolate and every
|
|
510
|
+
* delivery the Google webhook sees shares it. The rail below it is rebuilt per request by
|
|
511
|
+
* `resolveRailProvider` — a cache hung on that would be one that has never held anything — and the module
|
|
512
|
+
* variable that used to hold it is exactly what #520 deleted, because state no caller owns needs an
|
|
513
|
+
* exported `reset` for every suite that inherits it.
|
|
514
|
+
*
|
|
515
|
+
* **Owning the store is not the same as having none.** That is core's sentence, on `JwksCache`, about the
|
|
516
|
+
* surface anonymous traffic arrives on, and the Google webhook is one: the OIDC guard resolves a key by
|
|
517
|
+
* `kid` *before* it can check a signature, so with no store a forged token buys a round trip to Google,
|
|
518
|
+
* 1:1. Google rate-limits us, `fetchJwks` maps that to `core/upstream_failed`, and that code is in the
|
|
519
|
+
* webhook guard's pass-through set — so Pub/Sub redelivers the genuine notifications into the same
|
|
520
|
+
* uncached path. One anonymous caller, the whole rail down.
|
|
521
|
+
*
|
|
522
|
+
* **The store answers both floods, and only one of them is about a published `kid`.** What it holds
|
|
523
|
+
* collapses a forgery naming a key Google really publishes; `JwksCache.claimRefresh` — the window, one ask
|
|
524
|
+
* per `OIDC_JWKS_MIN_REFRESH_SECONDS` — collapses the cheaper one, the token naming a `kid` nobody has
|
|
525
|
+
* ever published, which is a miss and was therefore a fetch apiece however much was cached. Both live in
|
|
526
|
+
* this object, so a route passing its own store passes both bounds together.
|
|
527
|
+
*
|
|
528
|
+
* On `clock`, not wall time, so a suite injecting a clock governs the expiry too. A route wanting a bound
|
|
529
|
+
* harder than one isolate's memory — shared across isolates, or rate-limiting — passes its own
|
|
530
|
+
* `trust.googleJwksCache` and this one is never built.
|
|
531
|
+
*/
|
|
532
|
+
const trust = {
|
|
533
|
+
...options.trust ?? {},
|
|
534
|
+
googleJwksCache: options.trust?.googleJwksCache ?? memoryJwksCache({ now: clock })
|
|
535
|
+
};
|
|
505
536
|
/** The seam `payments()` built, or the resolver-less one this config implies. See {@link PaymentsRoutesOptions.subject}. */
|
|
506
537
|
const seam = options.subject ?? { billingSubject: config.billingSubject };
|
|
507
538
|
/**
|
|
@@ -38,12 +38,15 @@ export interface WebhookGuardOptions {
|
|
|
38
38
|
* distinction helps a developer; on a webhook it would only tell a forger how close it got. The original code
|
|
39
39
|
* rides in `detail`, which the HTTP codec strips.
|
|
40
40
|
*
|
|
41
|
-
* **
|
|
42
|
-
* store (`payments/provider_unavailable`) or cannot use its own credentials
|
|
43
|
-
* not judged the delivery at all — Google's rail must call the Play
|
|
44
|
-
* an outage there is ours, not the sender's.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
41
|
+
* **{@link PASS_THROUGH_CODES} pass through unchanged, because they are not the caller's failure.** A rail that
|
|
42
|
+
* cannot reach its store (`payments/provider_unavailable`) or cannot use its own credentials
|
|
43
|
+
* (`payments/rail_not_configured`) has not judged the delivery at all — Google's rail must call the Play
|
|
44
|
+
* Developer API to resolve a notification, and an outage there is ours, not the sender's. A rail handed a
|
|
45
|
+
* freshness window that is not a number (`core/internal`) has not judged it either, and that one is our
|
|
46
|
+
* configuration rather than our dependency's weather. Reporting any of them as a failed signature would send an
|
|
47
|
+
* operator hunting for a rotated key while the real answer is in a status page or in one line of
|
|
48
|
+
* `wrangler.jsonc`, and would tell the audit trail a forgery arrived when none did. All remain non-2xx, so the
|
|
49
|
+
* provider still redelivers.
|
|
47
50
|
*/
|
|
48
51
|
export declare function requireSignedWebhook(rail: PaymentsRail, options: WebhookGuardOptions): MiddlewareHandler<PithyHonoEnv>;
|
|
49
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhookGuard.d.ts","sourceRoot":"","sources":["../../src/http/webhookGuard.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAM7E,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"webhookGuard.d.ts","sourceRoot":"","sources":["../../src/http/webhookGuard.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAM7E,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,oBAAoB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) {
|
|
69
69
|
return cause instanceof PithyError ? cause.payload.code : "unknown";
|
|
70
70
|
}
|
|
71
|
-
/**
|
|
72
|
-
|
|
71
|
+
/**
|
|
72
|
+
* The codes a rail may raise that describe our side rather than the sender's, and so keep their own status.
|
|
73
|
+
*
|
|
74
|
+
* **Membership is decided by whose fault the code names, not by its status.** `payments/rail_not_configured`
|
|
75
|
+
* is a 404 and `core/internal` is a 500; what they share is that neither is a statement about the caller, so
|
|
76
|
+
* re-coding either as `payments/webhook_unverified` would be a lie in the one direction that costs the most —
|
|
77
|
+
* it names a culprit, and the culprit is us.
|
|
78
|
+
*
|
|
79
|
+
* The three `core/*` members are what #521 added, and they are the reason this set exists as a set. The
|
|
80
|
+
* signed-webhook verifiers now refuse a freshness window that is not a window — a `NaN` from
|
|
81
|
+
* `Number(env.STRIPE_WEBHOOK_TOLERANCE)` on a variable nobody set — as `core/internal`, because a comparison
|
|
82
|
+
* against `NaN` deletes the replay window rather than widening it. Caught here and re-rendered as a 401, that
|
|
83
|
+
* refusal arrived at the operator as *"check the webhook signing secret"*: it blamed the sender for our
|
|
84
|
+
* configuration, sent whoever was debugging to the one place the answer is not, and wrote an audit row saying
|
|
85
|
+
* a forgery had arrived when none had. CLAUDE.md §Errors gives a 500-class code exactly one job — *read **our**
|
|
86
|
+
* logs* — and laundering it into a 401 destroys that job entirely.
|
|
87
|
+
*
|
|
88
|
+
* `core/upstream_failed` and `core/upstream_timeout` ride along for the same reason `payments/provider_unavailable`
|
|
89
|
+
* already does: they are the shared-client spelling of a hop into something we do not control, and
|
|
90
|
+
* `workflows/retryPolicy.ts` already classifies the three together. Nothing on the verification path raises
|
|
91
|
+
* them today; the set is the place that would have to be edited if one ever did, and forgetting is what this
|
|
92
|
+
* comment exists to prevent.
|
|
93
|
+
*
|
|
94
|
+
* **The client boundary is untouched by any of this.** Every one of these still leaves through `clientError`,
|
|
95
|
+
* which strips `action` and `detail` — so the sender learns a status and a bland `message`, and the knob's
|
|
96
|
+
* name reaches the terminal, the `--json` line and the log alone. What changed is that the operator's surface
|
|
97
|
+
* and the status code stop saying *bad signature* when the truth is *this endpoint is misconfigured*.
|
|
98
|
+
*/
|
|
99
|
+
const PASS_THROUGH_CODES = /* @__PURE__ */ new Set([
|
|
100
|
+
"payments/provider_unavailable",
|
|
101
|
+
"payments/rail_not_configured",
|
|
102
|
+
"core/internal",
|
|
103
|
+
"core/upstream_failed",
|
|
104
|
+
"core/upstream_timeout"
|
|
105
|
+
]);
|
|
73
106
|
/**
|
|
74
107
|
* Request-scoped, keyed on the `Request` object so an entry cannot outlive its request and cannot be reached
|
|
75
108
|
* from another one. Weak, so a dropped request drops its entry with no bookkeeping.
|
|
@@ -102,12 +135,15 @@ function database(c) {
|
|
|
102
135
|
* distinction helps a developer; on a webhook it would only tell a forger how close it got. The original code
|
|
103
136
|
* rides in `detail`, which the HTTP codec strips.
|
|
104
137
|
*
|
|
105
|
-
* **
|
|
106
|
-
* store (`payments/provider_unavailable`) or cannot use its own credentials
|
|
107
|
-
* not judged the delivery at all — Google's rail must call the Play
|
|
108
|
-
* an outage there is ours, not the sender's.
|
|
109
|
-
*
|
|
110
|
-
*
|
|
138
|
+
* **{@link PASS_THROUGH_CODES} pass through unchanged, because they are not the caller's failure.** A rail that
|
|
139
|
+
* cannot reach its store (`payments/provider_unavailable`) or cannot use its own credentials
|
|
140
|
+
* (`payments/rail_not_configured`) has not judged the delivery at all — Google's rail must call the Play
|
|
141
|
+
* Developer API to resolve a notification, and an outage there is ours, not the sender's. A rail handed a
|
|
142
|
+
* freshness window that is not a number (`core/internal`) has not judged it either, and that one is our
|
|
143
|
+
* configuration rather than our dependency's weather. Reporting any of them as a failed signature would send an
|
|
144
|
+
* operator hunting for a rotated key while the real answer is in a status page or in one line of
|
|
145
|
+
* `wrangler.jsonc`, and would tell the audit trail a forgery arrived when none did. All remain non-2xx, so the
|
|
146
|
+
* provider still redelivers.
|
|
111
147
|
*/
|
|
112
148
|
function requireSignedWebhook(rail, options) {
|
|
113
149
|
return async (c, next) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x509.d.ts","sourceRoot":"","sources":["../../../src/rails/apple/x509.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"x509.d.ts","sourceRoot":"","sources":["../../../src/rails/apple/x509.ts"],"names":[],"mappings":"AAsFA;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,2BAA2B,6BAA6B,CAAC;AAStE,kFAAkF;AAClF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,UAAU,CAAC;CACnB;AAED,4GAA4G;AAC5G,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,sFAAsF;AACtF,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,GAAG,EAAE,UAAU,CAAC;IAChB,sGAAsG;IACtG,GAAG,EAAE,UAAU,CAAC;IAChB,gGAAgG;IAChG,MAAM,EAAE,UAAU,CAAC;IACnB,8BAA8B;IAC9B,OAAO,EAAE,UAAU,CAAC;IACpB,0CAA0C;IAC1C,SAAS,EAAE,IAAI,CAAC;IAChB,iCAAiC;IACjC,QAAQ,EAAE,IAAI,CAAC;IACf,gFAAgF;IAChF,IAAI,EAAE,UAAU,CAAC;IACjB,yCAAyC;IACzC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACzB,wEAAwE;IACxE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,uEAAuE;IACvE,SAAS,EAAE,UAAU,CAAC;IACtB,6GAA6G;IAC7G,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAC9C,uGAAuG;IACvG,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,sGAAsG;IACtG,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,yGAAyG;AACzG,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,SAAS,CAAC;IACf,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CAC1B;AAED,iGAAiG;AACjG,MAAM,WAAW,kBAAkB;IACjC,gGAAgG;IAChG,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,mEAAmE;IACnE,GAAG,EAAE,IAAI,CAAC;IACV;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,sGAAsG;IACtG,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzC;AA6FD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,GAAG,iBAAiB,CAuCnE;AAiCD;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CA8FvB"}
|
package/dist/rails/apple/x509.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { PaymentsInvalidReceiptError, PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
4
4
|
import { asn1Children, bytesEqual, decodeBase64, derSignatureToRaw, readAsn1, readBits, readBoolean, readInteger, readOid } from "./der.js";
|
|
5
|
+
import { InternalError } from "@pithy-sh/core/src/error/pithyError";
|
|
5
6
|
//#region src/rails/apple/x509.ts
|
|
6
7
|
/**
|
|
7
8
|
* X.509 certificates, and the chain check that makes an Apple signature mean something.
|
|
@@ -234,6 +235,11 @@ async function verifyCertificateChain(chain, options) {
|
|
|
234
235
|
if (chain.length > MAX_CHAIN_LENGTH) throw rejected(`X.509: a chain of ${chain.length} is longer than the ${MAX_CHAIN_LENGTH} accepted.`);
|
|
235
236
|
const certificates = chain.map((der) => parseCertificate(der));
|
|
236
237
|
const at = options.now.getTime();
|
|
238
|
+
if (!Number.isFinite(at)) throw new InternalError({
|
|
239
|
+
message: "That purchase could not be verified.",
|
|
240
|
+
action: "Give the Apple rail a valid clock.",
|
|
241
|
+
detail: "X.509: chain verification was handed a clock that is not a valid Date, so no certificate's validity window can be judged."
|
|
242
|
+
});
|
|
237
243
|
for (const [index, certificate] of certificates.entries()) if (at < certificate.notBefore.getTime() || at > certificate.notAfter.getTime()) throw rejected(`X.509: certificate ${index} is valid ${certificate.notBefore.toISOString()}–${certificate.notAfter.toISOString()}.`);
|
|
238
244
|
const root = certificates[certificates.length - 1];
|
|
239
245
|
if (!options.roots.some((encoded) => bytesEqual(decodeBase64(encoded), root.der))) throw rejected("X.509: the chain's root is not one of the pinned roots.");
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { type JwksCache, OidcJwk, OidcJwks } from "@pithy-sh/core/src/http/oidcWebhook";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
import {
|
|
5
|
+
import type { GoogleHttpFetch } from "./http";
|
|
5
6
|
/**
|
|
6
7
|
* The authenticity boundary on Google's webhook: the OIDC token a Pub/Sub push carries.
|
|
7
8
|
*
|
|
@@ -17,21 +18,47 @@ import { type GoogleHttpFetch } from "./http";
|
|
|
17
18
|
* for. Verify the signature and skip the audience and you have built an endpoint that accepts notifications
|
|
18
19
|
* from any Google customer who points a subscription at it.
|
|
19
20
|
*
|
|
20
|
-
*
|
|
21
|
+
* ## Everything above is `@pithy-sh/core/src/http/oidcWebhook`, and none of it is here
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* `jwk`/`x5u` handling here: a token that carries its own key is a token that verifies itself.
|
|
28
|
-
* 3. **Verify the signature over the exact received segments** — `header.claims` as encoded.
|
|
29
|
-
* 4. **Then read the claims,** and only then, because a claim from an unverified token means nothing.
|
|
23
|
+
* Algorithm pinning, key resolution by `kid`, signature verification, issuer, audience, `exp`, `nbf`, `iat`,
|
|
24
|
+
* the JWKS fetch and its cache: one implementation, in core, shared with every other OIDC sender the kit
|
|
25
|
+
* verifies. This module is the **Google specialization** — two issuer spellings, a key endpoint, an audience,
|
|
26
|
+
* and the one claim pair Google's own guidance adds — and nothing else. A second copy of a verifier is a
|
|
27
|
+
* second thing to keep current, and the thing that would drift here is an authentication boundary (#520).
|
|
30
28
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
29
|
+
* Core is stricter than the copy it replaced, deliberately: `nbf` is honored, a non-finite skew or key-set
|
|
30
|
+
* lifetime is refused rather than silently disabling the freshness checks, and a claim outside `Date`'s range
|
|
31
|
+
* is quoted as a number rather than throwing a `RangeError` while composing the refusal it had already
|
|
32
|
+
* decided on.
|
|
33
|
+
*
|
|
34
|
+
* ## What a refusal is called
|
|
35
|
+
*
|
|
36
|
+
* Core answers `core/webhook_unverified` for every failing step. The rail re-codes that to
|
|
37
|
+
* **`payments/verification_failed`**, so the audit trail's `metadata.step` stays a `payments/*` value and the
|
|
38
|
+
* webhook guard's pass-through set governs the rest. Core's `detail` rides along under a `Google:` prefix.
|
|
39
|
+
*
|
|
40
|
+
* `payments/invalid_receipt` no longer appears on this path, and that is a deliberate contract change rather
|
|
41
|
+
* than something the refactor dropped. It meant *the token could not be read*, which is a **receipt**
|
|
42
|
+
* distinction: `PaymentsRailProvider.verify` uses it for a client submission, where telling a developer that
|
|
43
|
+
* their payload is malformed is useful. A Pub/Sub push token is not a receipt, it is a webhook credential, and
|
|
44
|
+
* on the webhook path the guard already collapsed both codes to `payments/webhook_unverified` (401) before
|
|
45
|
+
* anything reached the sender — so no caller ever saw the difference, and core's own argument for one code
|
|
46
|
+
* applies with full force: a forger must not learn which check it tripped. Both codes were 400 and
|
|
47
|
+
* `verifyGoogleOidcToken` is not exported from the package, so the change is visible in exactly one place,
|
|
48
|
+
* the audit row's `metadata.step`.
|
|
49
|
+
*
|
|
50
|
+
* Two codes come from core untouched, because neither is a statement about the sender and both are already in
|
|
51
|
+
* the webhook guard's pass-through set: `core/internal` (500) for an endpoint of ours that is not configured
|
|
52
|
+
* to verify anything, and `core/upstream_failed` (502) for Google's key endpoint failing to answer. The
|
|
53
|
+
* second replaces `payments/provider_unavailable` (503) on the JWKS hop alone — CLAUDE.md §Errors gives the
|
|
54
|
+
* upstream pair exactly this job, and the Play Developer API hop is untouched and still 503.
|
|
55
|
+
*
|
|
56
|
+
* **A pass-through code is a code an anonymous caller must not be able to choose**, and that is what decided
|
|
57
|
+
* where the line sits. A published key that is not RSA, or will not import, used to be core's 502 and is
|
|
58
|
+
* core's 401 now: the key was reached because a `kid` in an unverified header selected it, so a 502 there
|
|
59
|
+
* let a forger pick a code this rail passes through — out of the audit trail, and into Pub/Sub's indefinite
|
|
60
|
+
* retry — by naming one `kid` instead of another. Nothing a `kid` can steer stays in the pass-through set.
|
|
61
|
+
* What is left in it is failure nobody chose: the endpoint being unreachable, and our own configuration.
|
|
35
62
|
*/
|
|
36
63
|
/** Where Google publishes the keys that sign an OIDC token. Public, so it is pinned here rather than stored. */
|
|
37
64
|
export declare const GOOGLE_JWKS_URL = "https://www.googleapis.com/oauth2/v3/certs";
|
|
@@ -41,8 +68,13 @@ export declare const GOOGLE_JWKS_URL = "https://www.googleapis.com/oauth2/v3/cer
|
|
|
41
68
|
*/
|
|
42
69
|
export declare const GOOGLE_OIDC_ISSUERS: readonly string[];
|
|
43
70
|
/**
|
|
44
|
-
* One published RSA verification key,
|
|
45
|
-
*
|
|
71
|
+
* One published RSA verification key, and the key set Google's endpoint returns.
|
|
72
|
+
*
|
|
73
|
+
* Core's schemas under the rail's published names, not copies of them. The shape is the JWKS shape — it
|
|
74
|
+
* belongs to RFC 7517 rather than to Google — and two declarations of one wire format is the same drift this
|
|
75
|
+
* module exists to remove, one layer down. The names stay because they are `@pithy-sh/payments`' public
|
|
76
|
+
* surface and an adopter typing a Pub/Sub emulator's key against `GoogleJwk` should not have to learn a
|
|
77
|
+
* second one.
|
|
46
78
|
*/
|
|
47
79
|
export declare const GoogleJwk: z.ZodObject<{
|
|
48
80
|
kid: z.ZodString;
|
|
@@ -52,8 +84,7 @@ export declare const GoogleJwk: z.ZodObject<{
|
|
|
52
84
|
alg: z.ZodOptional<z.ZodString>;
|
|
53
85
|
use: z.ZodOptional<z.ZodString>;
|
|
54
86
|
}, z.core.$loose>;
|
|
55
|
-
export type GoogleJwk =
|
|
56
|
-
/** Google's published key set. At least one key: an empty set is an endpoint that is not answering properly. */
|
|
87
|
+
export type GoogleJwk = OidcJwk;
|
|
57
88
|
export declare const GoogleJwks: z.ZodObject<{
|
|
58
89
|
keys: z.ZodArray<z.ZodObject<{
|
|
59
90
|
kid: z.ZodString;
|
|
@@ -64,19 +95,24 @@ export declare const GoogleJwks: z.ZodObject<{
|
|
|
64
95
|
use: z.ZodOptional<z.ZodString>;
|
|
65
96
|
}, z.core.$loose>>;
|
|
66
97
|
}, z.core.$loose>;
|
|
67
|
-
export type GoogleJwks =
|
|
98
|
+
export type GoogleJwks = OidcJwks;
|
|
68
99
|
/**
|
|
69
|
-
* The claims a Pub/Sub push token carries,
|
|
70
|
-
*
|
|
100
|
+
* The claims a Pub/Sub push token carries: core's, plus the two Google adds.
|
|
101
|
+
*
|
|
102
|
+
* `email` and `email_verified` are the extension, and they are the reason this schema exists at all — core
|
|
103
|
+
* reads what every OIDC token has and hands the rest to a predicate. Extended rather than redeclared, so
|
|
104
|
+
* `iss`/`aud`/`exp`/`nbf`/`iat` have one definition in the kit. Still `.loose()`: the whole token is never
|
|
105
|
+
* stored, and a claim set must not be refused for being richer than expected.
|
|
71
106
|
*/
|
|
72
107
|
export declare const GoogleOidcClaims: z.ZodObject<{
|
|
73
108
|
iss: z.ZodString;
|
|
74
109
|
aud: z.ZodString;
|
|
110
|
+
sub: z.ZodOptional<z.ZodString>;
|
|
75
111
|
exp: z.ZodNumber;
|
|
112
|
+
nbf: z.ZodOptional<z.ZodNumber>;
|
|
76
113
|
iat: z.ZodOptional<z.ZodNumber>;
|
|
77
114
|
email: z.ZodOptional<z.ZodString>;
|
|
78
115
|
email_verified: z.ZodOptional<z.ZodBoolean>;
|
|
79
|
-
sub: z.ZodOptional<z.ZodString>;
|
|
80
116
|
}, z.core.$loose>;
|
|
81
117
|
export type GoogleOidcClaims = z.infer<typeof GoogleOidcClaims>;
|
|
82
118
|
/** What verifying a push token needs. Everything is explicit, so verification is deterministic in a test. */
|
|
@@ -93,22 +129,46 @@ export interface VerifyGoogleOidcOptions {
|
|
|
93
129
|
* Keys accepted **in addition to** Google's published set, matched by `kid`.
|
|
94
130
|
*
|
|
95
131
|
* Additive, so nothing can narrow production's trust: a token whose `kid` these do not cover still resolves
|
|
96
|
-
* against Google. Two callers have a real reason — the tests, which mint their own key so the signature
|
|
97
|
-
* is exercised for real, and a local Pub/Sub emulator, whose tokens are signed by a key Google never
|
|
132
|
+
* against Google. Two callers have a real reason — the tests, which mint their own key so the signature
|
|
133
|
+
* check is exercised for real, and a local Pub/Sub emulator, whose tokens are signed by a key Google never
|
|
134
|
+
* saw.
|
|
98
135
|
*/
|
|
99
136
|
trustedKeys?: readonly GoogleJwk[];
|
|
100
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Tolerance on `exp`, `nbf` and `iat`, in seconds. Defaults to a minute, and must be a finite number from 0
|
|
139
|
+
* to core's maximum; anything else is `core/internal`, because this is the second operand of all three
|
|
140
|
+
* freshness comparisons and one `NaN` turns them into no-ops together.
|
|
141
|
+
*/
|
|
101
142
|
clockSkewSeconds?: number;
|
|
143
|
+
/**
|
|
144
|
+
* How long a fetched key set is held. Defaults to core's hour, and must be a finite number of seconds — a
|
|
145
|
+
* `NaN` is an entry that never expires, which pins a key Google has rotated out.
|
|
146
|
+
*/
|
|
147
|
+
jwksTtlSeconds?: number;
|
|
148
|
+
/**
|
|
149
|
+
* Where Google's fetched keys are held between deliveries.
|
|
150
|
+
*
|
|
151
|
+
* **Injected, and there is no default**, which is the point: this used to be a module variable no caller
|
|
152
|
+
* owned, and the only way a test suite could stop inheriting the previous one's keys was an exported
|
|
153
|
+
* `resetGoogleJwksCache` whose sole purpose was to undo it. With no cache the verifier fetches per call,
|
|
154
|
+
* which is correct and slow; a Worker that verifies more than one notification per hour passes a
|
|
155
|
+
* `memoryJwksCache` built once at module scope, or one over KV to share it across isolates.
|
|
156
|
+
*
|
|
157
|
+
* It is two bounds in one object: what Google published, and when Google was last asked. The second is
|
|
158
|
+
* what a token naming a `kid` nobody published runs into, and with no store there is no second bound
|
|
159
|
+
* either — which is why the webhook path is given one and the `verify` path is not.
|
|
160
|
+
*/
|
|
161
|
+
jwksCache?: JwksCache;
|
|
102
162
|
}
|
|
103
|
-
/** Drop the cached key set. For tests, which must not inherit another suite's keys. */
|
|
104
|
-
export declare function resetGoogleJwksCache(): void;
|
|
105
163
|
/**
|
|
106
164
|
* Verify one Pub/Sub push OIDC token and return its claims.
|
|
107
165
|
*
|
|
108
|
-
* @throws {@link
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
166
|
+
* @throws {@link PaymentsVerificationFailedError} when the sender did not prove itself — an unreadable token,
|
|
167
|
+
* an unknown key, a key that cannot verify an `RS256` signature, a bad signature, the wrong audience, the
|
|
168
|
+
* wrong issuer, an expiry, the wrong service account.
|
|
169
|
+
* @throws `core/internal` (500) when this endpoint is not configured to verify anything — an audience that is
|
|
170
|
+
* empty, a clock that is not a clock, a skew or key-set lifetime that is not a number.
|
|
171
|
+
* @throws `core/upstream_failed` (502) when Google's key endpoint could not be read.
|
|
112
172
|
*/
|
|
113
173
|
export declare function verifyGoogleOidcToken(token: string, options: VerifyGoogleOidcOptions): Promise<GoogleOidcClaims>;
|
|
114
174
|
//# sourceMappingURL=oidc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc.d.ts","sourceRoot":"","sources":["../../../src/rails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