@pithy-sh/auth 0.15.2 → 0.16.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.
Files changed (169) hide show
  1. package/README.md +4 -0
  2. package/dist/attestation/appAttest/assertion.d.ts +32 -0
  3. package/dist/attestation/appAttest/assertion.d.ts.map +1 -0
  4. package/dist/attestation/appAttest/assertion.js +59 -0
  5. package/dist/attestation/appAttest/attestation.d.ts +49 -0
  6. package/dist/attestation/appAttest/attestation.d.ts.map +1 -0
  7. package/dist/attestation/appAttest/attestation.js +111 -0
  8. package/dist/attestation/appAttest/authData.d.ts +24 -0
  9. package/dist/attestation/appAttest/authData.d.ts.map +1 -0
  10. package/dist/attestation/appAttest/authData.js +32 -0
  11. package/dist/attestation/appAttest/base64.d.ts +8 -0
  12. package/dist/attestation/appAttest/base64.d.ts.map +1 -0
  13. package/dist/attestation/appAttest/base64.js +27 -0
  14. package/dist/attestation/appAttest/bytes.d.ts +7 -0
  15. package/dist/attestation/appAttest/bytes.d.ts.map +1 -0
  16. package/dist/attestation/appAttest/bytes.js +19 -0
  17. package/dist/attestation/appAttest/cbor.d.ts +20 -0
  18. package/dist/attestation/appAttest/cbor.d.ts.map +1 -0
  19. package/dist/attestation/appAttest/cbor.js +96 -0
  20. package/dist/attestation/appAttest/der.d.ts +38 -0
  21. package/dist/attestation/appAttest/der.d.ts.map +1 -0
  22. package/dist/attestation/appAttest/der.js +106 -0
  23. package/dist/attestation/appAttest/keys.d.ts +15 -0
  24. package/dist/attestation/appAttest/keys.d.ts.map +1 -0
  25. package/dist/attestation/appAttest/keys.js +37 -0
  26. package/dist/attestation/appAttest/root.d.ts +9 -0
  27. package/dist/attestation/appAttest/root.d.ts.map +1 -0
  28. package/dist/attestation/appAttest/root.js +12 -0
  29. package/dist/attestation/appAttest/verifier.d.ts +39 -0
  30. package/dist/attestation/appAttest/verifier.d.ts.map +1 -0
  31. package/dist/attestation/appAttest/verifier.js +121 -0
  32. package/dist/attestation/appAttest/x509.d.ts +50 -0
  33. package/dist/attestation/appAttest/x509.d.ts.map +1 -0
  34. package/dist/attestation/appAttest/x509.js +163 -0
  35. package/dist/attestation/challenge.d.ts +26 -0
  36. package/dist/attestation/challenge.d.ts.map +1 -0
  37. package/dist/attestation/challenge.js +47 -0
  38. package/dist/attestation/config.d.ts +72 -0
  39. package/dist/attestation/config.d.ts.map +1 -0
  40. package/dist/attestation/config.js +52 -0
  41. package/dist/attestation/errors.d.ts +30 -0
  42. package/dist/attestation/errors.d.ts.map +1 -0
  43. package/dist/attestation/errors.js +45 -0
  44. package/dist/attestation/gate.d.ts +27 -0
  45. package/dist/attestation/gate.d.ts.map +1 -0
  46. package/dist/attestation/gate.js +78 -0
  47. package/dist/attestation/playIntegrity/google.d.ts +47 -0
  48. package/dist/attestation/playIntegrity/google.d.ts.map +1 -0
  49. package/dist/attestation/playIntegrity/google.js +178 -0
  50. package/dist/attestation/playIntegrity/verdict.d.ts +40 -0
  51. package/dist/attestation/playIntegrity/verdict.d.ts.map +1 -0
  52. package/dist/attestation/playIntegrity/verdict.js +93 -0
  53. package/dist/attestation/playIntegrity/verifier.d.ts +22 -0
  54. package/dist/attestation/playIntegrity/verifier.d.ts.map +1 -0
  55. package/dist/attestation/playIntegrity/verifier.js +64 -0
  56. package/dist/attestation/verifier.d.ts +60 -0
  57. package/dist/attestation/verifier.d.ts.map +1 -0
  58. package/dist/attestation/verifier.js +46 -0
  59. package/dist/attestation/wire.d.ts +42 -0
  60. package/dist/attestation/wire.d.ts.map +1 -0
  61. package/dist/attestation/wire.js +72 -0
  62. package/dist/capability.d.ts +40 -0
  63. package/dist/capability.d.ts.map +1 -1
  64. package/dist/capability.js +38 -5
  65. package/dist/client/api.d.ts +37 -24
  66. package/dist/client/api.d.ts.map +1 -1
  67. package/dist/client/api.js +52 -41
  68. package/dist/client/attestation.d.ts +148 -0
  69. package/dist/client/attestation.d.ts.map +1 -0
  70. package/dist/client/attestation.js +321 -0
  71. package/dist/client/projection.d.ts +29 -4
  72. package/dist/client/projection.d.ts.map +1 -1
  73. package/dist/data/appAttestKey.d.ts +30 -0
  74. package/dist/data/appAttestKey.d.ts.map +1 -0
  75. package/dist/data/appAttestKey.js +25 -0
  76. package/dist/data/attestationChallenge.d.ts +17 -0
  77. package/dist/data/attestationChallenge.d.ts.map +1 -0
  78. package/dist/data/attestationChallenge.js +19 -0
  79. package/dist/data/tables.d.ts +18 -1
  80. package/dist/data/tables.d.ts.map +1 -1
  81. package/dist/data/tables.js +6 -2
  82. package/dist/http/devLoginRoute.js +3 -3
  83. package/dist/http/resolve.js +1 -1
  84. package/dist/http/responses.d.ts +12 -0
  85. package/dist/http/responses.d.ts.map +1 -1
  86. package/dist/http/responses.js +11 -1
  87. package/dist/http/routes.d.ts +5 -1
  88. package/dist/http/routes.d.ts.map +1 -1
  89. package/dist/http/routes.js +92 -25
  90. package/dist/http/schemas.d.ts +7 -0
  91. package/dist/http/schemas.d.ts.map +1 -1
  92. package/dist/http/schemas.js +7 -1
  93. package/dist/index.js +1 -1
  94. package/dist/instance/secrets.d.ts +86 -7
  95. package/dist/instance/secrets.d.ts.map +1 -1
  96. package/dist/instance/secrets.js +54 -8
  97. package/dist/migrations/0009_attestation_challenges.d.ts +9 -0
  98. package/dist/migrations/0009_attestation_challenges.d.ts.map +1 -0
  99. package/dist/migrations/0009_attestation_challenges.js +21 -0
  100. package/dist/migrations/0010_app_attest_keys.d.ts +9 -0
  101. package/dist/migrations/0010_app_attest_keys.d.ts.map +1 -0
  102. package/dist/migrations/0010_app_attest_keys.js +17 -0
  103. package/dist/migrations/set.d.ts +3 -1
  104. package/dist/migrations/set.d.ts.map +1 -1
  105. package/dist/migrations/set.js +6 -2
  106. package/dist/seeds/devSession.js +1 -1
  107. package/dist/test-utils/appAttestDevice.d.ts +92 -0
  108. package/dist/test-utils/appAttestDevice.d.ts.map +1 -0
  109. package/dist/test-utils/appAttestDevice.js +282 -0
  110. package/dist/test-utils/appAttestSample.d.ts +22 -0
  111. package/dist/test-utils/appAttestSample.d.ts.map +1 -0
  112. package/dist/test-utils/appAttestSample.js +24 -0
  113. package/dist/test-utils/googlePlay.d.ts +47 -0
  114. package/dist/test-utils/googlePlay.d.ts.map +1 -0
  115. package/dist/test-utils/googlePlay.js +117 -0
  116. package/dist/test-utils/liveApp.d.ts +76 -36
  117. package/dist/test-utils/liveApp.d.ts.map +1 -1
  118. package/dist/test-utils/liveApp.js +16 -5
  119. package/dist/test-utils/rollbackThrough.d.ts +11 -0
  120. package/dist/test-utils/rollbackThrough.d.ts.map +1 -0
  121. package/dist/test-utils/rollbackThrough.js +16 -0
  122. package/dist/test-utils/scopedBackend.d.ts +25 -0
  123. package/dist/test-utils/scopedBackend.d.ts.map +1 -1
  124. package/dist/test-utils/scopedBackend.js +1 -1
  125. package/dist/version.generated.d.ts +1 -1
  126. package/dist/version.generated.js +1 -1
  127. package/docs/attestation.md +173 -0
  128. package/package.json +5 -5
  129. package/pithy.manifest.json +14 -0
  130. package/src/attestation/appAttest/assertion.ts +65 -0
  131. package/src/attestation/appAttest/attestation.ts +159 -0
  132. package/src/attestation/appAttest/authData.ts +45 -0
  133. package/src/attestation/appAttest/base64.ts +29 -0
  134. package/src/attestation/appAttest/bytes.ts +18 -0
  135. package/src/attestation/appAttest/cbor.ts +116 -0
  136. package/src/attestation/appAttest/der.ts +126 -0
  137. package/src/attestation/appAttest/keys.ts +57 -0
  138. package/src/attestation/appAttest/root.ts +13 -0
  139. package/src/attestation/appAttest/verifier.ts +113 -0
  140. package/src/attestation/appAttest/x509.ts +209 -0
  141. package/src/attestation/challenge.ts +56 -0
  142. package/src/attestation/config.ts +118 -0
  143. package/src/attestation/errors.ts +60 -0
  144. package/src/attestation/gate.ts +105 -0
  145. package/src/attestation/playIntegrity/google.ts +239 -0
  146. package/src/attestation/playIntegrity/verdict.ts +149 -0
  147. package/src/attestation/playIntegrity/verifier.ts +77 -0
  148. package/src/attestation/verifier.ts +87 -0
  149. package/src/attestation/wire.ts +79 -0
  150. package/src/capability.ts +64 -8
  151. package/src/client/api.ts +73 -40
  152. package/src/client/attestation.ts +404 -0
  153. package/src/client/projection.ts +29 -4
  154. package/src/data/appAttestKey.ts +45 -0
  155. package/src/data/attestationChallenge.ts +23 -0
  156. package/src/data/tables.ts +5 -1
  157. package/src/http/responses.ts +22 -0
  158. package/src/http/routes.ts +128 -38
  159. package/src/http/schemas.ts +24 -0
  160. package/src/instance/secrets.ts +88 -9
  161. package/src/migrations/0009_attestation_challenges.ts +28 -0
  162. package/src/migrations/0010_app_attest_keys.ts +27 -0
  163. package/src/migrations/set.ts +5 -1
  164. package/src/test-utils/appAttestDevice.ts +399 -0
  165. package/src/test-utils/appAttestSample.ts +20 -0
  166. package/src/test-utils/googlePlay.ts +144 -0
  167. package/src/test-utils/liveApp.ts +31 -5
  168. package/src/test-utils/rollbackThrough.ts +24 -0
  169. package/src/version.generated.ts +1 -1
@@ -313,6 +313,16 @@ const HandoffExchangeResponse = z.object({
313
313
  token: z.string().describe("The raw session token: the bearer credential for `Authorization: Bearer`, and the refresh credential `/token/rotate` takes. Hold it in secure storage."),
314
314
  expiresAt: z.iso.datetime().describe("When the session lapses unless it is rotated first, ISO-8601.")
315
315
  }).describe("The session a redirect sign-in made, handed to the native app that started it.");
316
+ /** `POST {base}/attestation/challenge`. */
317
+ const AttestationChallengeResponse = z.object({
318
+ challenge: z.string().describe("The challenge: 32 random bytes, unpadded base64url. Good once, on one send route, until `expiresAt`. The platform's assertion is made over SHA-256 of these characters followed by that request's exact body."),
319
+ expiresAt: z.iso.datetime().describe("When the challenge stops being accepted, ISO-8601.")
320
+ }).describe("A single-use challenge for a native app attestation.");
321
+ /** `POST {base}/attestation/ios/keys`. */
322
+ const AppAttestKeyResponse = z.object({
323
+ keyId: z.string().describe("The key identifier, as the request sent it. Assertions name it as `keyId`."),
324
+ registeredAt: z.iso.datetime().describe("When the key was registered, ISO-8601.")
325
+ }).describe("An App Attest key this server verified and registered.");
316
326
  /** One of the caller's own registered devices. */
317
327
  const MyDeviceView = z.object({
318
328
  id: z.string().describe("The client-generated device id it registered at sign-in."),
@@ -341,4 +351,4 @@ const AccountDeleteResponse = z.object({
341
351
  mailed: z.boolean().describe("Whether the deletion-scheduled mail, with the purge date and how to ask for the account back, was sent.")
342
352
  }).describe("The caller's own account, deleted: when its data will be erased, and whether they were mailed.");
343
353
  //#endregion
344
- export { AccountDeleteResponse, AdminDeviceRevokeResponse, AdminDeviceView, AdminDevicesResponse, AdminRevokeResponse, AdminSessionView, AdminUserDeleteResponse, AdminUserExportResponse, AdminUserReinstateResponse, AdminUserResponse, AdminUserRestoreResponse, AdminUserSuspendResponse, AdminUserView, AdminUsersResponse, AdminVerificationView, AdminVerificationsResponse, AuthUserExport, HandoffExchangeResponse, MyDeviceRevokeResponse, MyDeviceView, MyDevicesResponse, TokenRotateResponse, VerificationTypeCounts };
354
+ export { AccountDeleteResponse, AdminDeviceRevokeResponse, AdminDeviceView, AdminDevicesResponse, AdminRevokeResponse, AdminSessionView, AdminUserDeleteResponse, AdminUserExportResponse, AdminUserReinstateResponse, AdminUserResponse, AdminUserRestoreResponse, AdminUserSuspendResponse, AdminUserView, AdminUsersResponse, AdminVerificationView, AdminVerificationsResponse, AppAttestKeyResponse, AttestationChallengeResponse, AuthUserExport, HandoffExchangeResponse, MyDeviceRevokeResponse, MyDeviceView, MyDevicesResponse, TokenRotateResponse, VerificationTypeCounts };
@@ -3,10 +3,12 @@
3
3
  import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
4
4
  import type { Hono } from "hono";
5
5
  import type { AuthWiring } from "../capability";
6
+ /** The routes that send a sign-in email, under `basePath`: the ones Turnstile and attestation gate. */
7
+ export declare const SEND_ROUTES: readonly ["/sign-in/magic-link", "/email-otp/send-verification-otp"];
6
8
  /**
7
9
  * Register the auth routes onto the backend's Hono app.
8
10
  *
9
- * Order matters: turnstile gates the human-initiated send routes (only when composed), Pithy's own
11
+ * Order matters: Turnstile and attestation gate the send routes ({@link SEND_ROUTES}), Pithy's own
10
12
  * routes are registered before the catch-all so they win, and Better Auth owns everything else under
11
13
  * `basePath`. A handler that returns a Response ends the chain, so the specific routes never fall
12
14
  * through to the catch-all. (The tier-1 edge rate limiter is contributed as capability *middleware*, so
@@ -17,6 +19,8 @@ import type { AuthWiring } from "../capability";
17
19
  * | Route | Verification | Input |
18
20
  * | -------------------------- | --------------- | --------------------------- |
19
21
  * | `POST /token/rotate` | bearer/session | none — the credential only |
22
+ * | `POST /attestation/challenge` | public | none |
23
+ * | `POST /attestation/ios/keys` | public | json `AppAttestKeyBody` |
20
24
  * | `GET /sign-in/social/start` | public | query `SocialSignInStartQuery` |
21
25
  * | `POST /handoff` | public | json `HandoffExchangeBody` |
22
26
  * | `GET /devices` | bearer/session | none |
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/http/routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAS7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAkDhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAyKtF"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/http/routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAU7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAU1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAsDhD,uGAAuG;AACvG,eAAO,MAAM,WAAW,YAAI,qBAAqB,EAAE,kCAAkC,CAAU,CAAC;AAMhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAgNtF"}
@@ -1,5 +1,10 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
+ import { attestationIsConfigured } from "../attestation/config.js";
4
+ import { issueChallenge } from "../attestation/challenge.js";
5
+ import { registerAppAttestKey } from "../attestation/appAttest/verifier.js";
6
+ import { AttestationFailedError } from "../attestation/errors.js";
7
+ import { PLATFORM_VERIFIERS } from "../attestation/verifier.js";
3
8
  import { authDatabase } from "../data/tables.js";
4
9
  import { correlation, emitDenied, emitDeviceRevoked, emitTokenRefresh, emitTokenReuseDetected } from "../audit/emit.js";
5
10
  import { deleteDevice, deviceSessionTokens, listDevices } from "../device/registry.js";
@@ -11,11 +16,13 @@ import { PROFILE_IMAGE_PATH } from "../profile/profile.js";
11
16
  import { collapseProviderRefusal } from "./providerRefusal.js";
12
17
  import { getAuthInstance, resolveDb } from "./resolve.js";
13
18
  import { userSessionTokens } from "../admin/users.js";
19
+ import { APPLE_APP_ATTESTATION_ROOT } from "../attestation/appAttest/root.js";
20
+ import { assertAttestationBlock, sendGate } from "../attestation/gate.js";
14
21
  import { lifecycleDeps } from "../lifecycle/request.js";
15
22
  import { deleteUser } from "../lifecycle/transitions.js";
16
23
  import { consumeSession, findConsumedToken, pruneConsumedTokens, recordConsumedToken, revokeFamily } from "../token/rotation.js";
17
- import { AccountDeleteResponse, HandoffExchangeResponse, MyDeviceRevokeResponse, MyDevicesResponse, TokenRotateResponse } from "./responses.js";
18
- import { DeleteAccountBody, HandoffExchangeBody, RevokeDeviceBody, SocialSignInStartQuery } from "./schemas.js";
24
+ import { AccountDeleteResponse, AppAttestKeyResponse, AttestationChallengeResponse, HandoffExchangeResponse, MyDeviceRevokeResponse, MyDevicesResponse, TokenRotateResponse } from "./responses.js";
25
+ import { AppAttestKeyBody, DeleteAccountBody, HandoffExchangeBody, RevokeDeviceBody, SocialSignInStartQuery } from "./schemas.js";
19
26
  import { accountDeletionView } from "./views.js";
20
27
  import { registerAuthAdminRoutes } from "./adminRoutes.js";
21
28
  import { guardErrorCallbackURL } from "./errorCallbackUrl.js";
@@ -29,6 +36,7 @@ import { validate } from "@pithy-sh/core/src/http/validation";
29
36
  import { STORED_IMAGE_HEADERS, storedImageBytes } from "@pithy-sh/core/src/image/storedImage";
30
37
  import { requireSameOrigin } from "@pithy-sh/core/src/http/sameOrigin";
31
38
  import { announceSessionRotated } from "@pithy-sh/core/src/session/rotated";
39
+ import { workerIdentity } from "@pithy-sh/core/src/worker/identity";
32
40
  import { turnstile } from "@pithy-sh/turnstile/src/http/middleware";
33
41
  //#region src/http/routes.ts
34
42
  /**
@@ -40,13 +48,15 @@ const BETTER_AUTH_ANSWER = {
40
48
  description: "Better Auth's own answer. See its endpoint reference.",
41
49
  contentType: "application/json"
42
50
  };
51
+ /** The routes that send a sign-in email, under `basePath`: the ones Turnstile and attestation gate. */
52
+ const SEND_ROUTES = ["/sign-in/magic-link", "/email-otp/send-verification-otp"];
43
53
  function db(c, wiring) {
44
54
  return authDatabase(resolveDb(c.env, wiring.config.database));
45
55
  }
46
56
  /**
47
57
  * Register the auth routes onto the backend's Hono app.
48
58
  *
49
- * Order matters: turnstile gates the human-initiated send routes (only when composed), Pithy's own
59
+ * Order matters: Turnstile and attestation gate the send routes ({@link SEND_ROUTES}), Pithy's own
50
60
  * routes are registered before the catch-all so they win, and Better Auth owns everything else under
51
61
  * `basePath`. A handler that returns a Response ends the chain, so the specific routes never fall
52
62
  * through to the catch-all. (The tier-1 edge rate limiter is contributed as capability *middleware*, so
@@ -57,6 +67,8 @@ function db(c, wiring) {
57
67
  * | Route | Verification | Input |
58
68
  * | -------------------------- | --------------- | --------------------------- |
59
69
  * | `POST /token/rotate` | bearer/session | none — the credential only |
70
+ * | `POST /attestation/challenge` | public | none |
71
+ * | `POST /attestation/ios/keys` | public | json `AppAttestKeyBody` |
60
72
  * | `GET /sign-in/social/start` | public | query `SocialSignInStartQuery` |
61
73
  * | `POST /handoff` | public | json `HandoffExchangeBody` |
62
74
  * | `GET /devices` | bearer/session | none |
@@ -79,16 +91,33 @@ function createAuthRoutes(wiring) {
79
91
  return (app) => {
80
92
  const base = wiring.config.basePath;
81
93
  const csrf = requireSameOrigin();
82
- if (wiring.turnstile) {
83
- const { mode, token } = wiring.turnstile;
84
- const guard = turnstile({
85
- mode,
86
- field: token.field,
87
- header: token.header,
88
- action: TURNSTILE_LOGIN_ACTION
89
- });
90
- app.use(`${base}/sign-in/magic-link`, guard);
91
- app.use(`${base}/email-otp/send-verification-otp`, guard);
94
+ const humanity = wiring.turnstile ? turnstile({
95
+ mode: wiring.turnstile.mode,
96
+ field: wiring.turnstile.token.field,
97
+ header: wiring.turnstile.token.header,
98
+ action: TURNSTILE_LOGIN_ACTION
99
+ }) : void 0;
100
+ const { attestation } = wiring.config;
101
+ const guard = attestationIsConfigured(attestation) ? sendGate({
102
+ attestation,
103
+ database: wiring.config.database,
104
+ verifiers: wiring.attestationVerifiers ?? PLATFORM_VERIFIERS,
105
+ turnstile: humanity
106
+ }) : humanity;
107
+ if (guard) for (const path of SEND_ROUTES) app.use(`${base}${path}`, guard);
108
+ if (attestationIsConfigured(attestation)) {
109
+ app.post(`${base}/attestation/challenge`, describeRoute({
110
+ summary: "Issue a single-use challenge for a native app attestation.",
111
+ description: "A native app asks for one before each send. It attests over SHA-256 of the challenge followed by the send's exact body, and sends the result in the `x-pithy-attestation` header: unpadded base64url over the JSON `{ platform, challenge, assertion, keyId? }`. The challenge is good once, pass or fail, until `expiresAt`. An environment with no attestation block answers `auth/attestation_config`.",
112
+ verification: ["public"],
113
+ responses: { 200: AttestationChallengeResponse }
114
+ }), (c) => issueAttestationChallenge(c, wiring));
115
+ app.post(`${base}/attestation/ios/keys`, describeRoute({
116
+ summary: "Register an iOS app's App Attest key, with Apple's attestation of it.",
117
+ description: "Once per key, before its first assertion. The app asks for a challenge, passes SHA-256 of its characters to `attestKey` as the client data hash, and sends the key id and the attestation object here. The certificate chain must lead to Apple App Attestation Root CA, the `rpIdHash` must be an allowed app's, and the key must be from Apple's production environment, or from either in dev, staging and a feature deployment. Then each send carries an assertion by this key in `x-pithy-attestation`. Any check that fails, a key already registered included, answers `auth/attestation_failed`; an environment with no attestation block answers `auth/attestation_config`.",
118
+ verification: ["public"],
119
+ responses: { 200: AppAttestKeyResponse }
120
+ }), validate("json", AppAttestKeyBody), (c) => registerIosKey(c, wiring, c.req.valid("json")));
92
121
  }
93
122
  app.post(`${base}/token/rotate`, describeRoute({
94
123
  summary: "Trade the current session token for its successor, and a JWT for services outside this Worker.",
@@ -190,9 +219,9 @@ function isSignInAttempt(path) {
190
219
  * (`better-call@1.4.0`, `dist/router.mjs:83-89`), which renders an `APIError` as a Response and returns
191
220
  * it. The throw is swallowed one frame later by the library that asked for it.
192
221
  *
193
- * So the `emitDenied` call this replaces — gated on catching an `APIError` — had never run once. No
194
- * failed one-time code, no bad magic link, no refused OAuth callback has ever reached
195
- * `pithy_audit_events`, which is the largest class of security event this capability has (#449).
222
+ * A refusal recorded by catching an `APIError` would therefore never be recorded: no failed one-time code,
223
+ * no bad magic link, no refused OAuth callback, which is the largest class of security event this
224
+ * capability has.
196
225
  *
197
226
  * **The body is cloned, never consumed.** The Response is handed back to the caller untouched: Better
198
227
  * Auth's own flat shape is a contract adopters read through `createAuthClient`, and the browser client
@@ -216,12 +245,11 @@ async function auditRefusal(c, response) {
216
245
  /**
217
246
  * Delegate to Better Auth's fetch handler, and record what it refused.
218
247
  *
219
- * **The answer is returned exactly as Better Auth wrote it.** Re-homing its flat `{ message, code }`
220
- * into the kit envelope was tried and taken back out: `packages/auth/README.md` documents
221
- * `createAuthClient` from `better-auth/client` as a first-class client surface (#271), and
222
- * `@better-fetch/fetch` builds its error as `{ ...parsedBody, status }` — so rewriting the body would
223
- * make `error.code` `undefined` for every adopter on the documented path. The wire is Better Auth's
224
- * contract. `readFailure` in `../client/api` learns to read it instead (#449).
248
+ * **The answer is returned exactly as Better Auth wrote it, never re-homed in the kit envelope.**
249
+ * `packages/auth/README.md` documents `createAuthClient` from `better-auth/client` as a first-class client
250
+ * surface, and `@better-fetch/fetch` builds its error as `{ ...parsedBody, status }`, so rewriting the body
251
+ * would make `error.code` `undefined` for every adopter on the documented path. The wire is Better Auth's
252
+ * contract, and `readFailure` in `../client/api` reads it.
225
253
  *
226
254
  * The `catch` covers what better-call genuinely hands on: a non-`APIError` throw from an endpoint
227
255
  * (`router.mjs:88`), and a throw from a plugin's `onRequest` hook, which runs outside the router's own
@@ -281,7 +309,7 @@ const ROTATION_REUSE_GRACE_MS = 3e4;
281
309
  * token + refresh token. This is the "refresh credential rotates on use" primitive Better Auth does not
282
310
  * provide natively.
283
311
  *
284
- * Two hardenings over a naive rotate (#59):
312
+ * Two hardenings over a naive rotate:
285
313
  * - **Reuse detection.** A presented token that no longer resolves to a live session but was previously
286
314
  * consumed is a replayed refresh token — the compromise signal for rotated refresh tokens
287
315
  * (RFC 6819 §5.2.2.3). The whole family is revoked and the attempt denied. (Covers the bearer refresh
@@ -382,7 +410,7 @@ async function listMyDevices(c, wiring) {
382
410
  return c.json({ devices: await listDevices(db(c, wiring), userId) });
383
411
  }
384
412
  /**
385
- * Delete the caller's own account (#622): soft, on the configured window, audited as `auth/user_self_deleted`
413
+ * Delete the caller's own account: soft, on the configured window, audited as `auth/user_self_deleted`
386
414
  * with them as the actor, and every session they hold ended after the columns are written — through Better
387
415
  * Auth's adapter, so `onSessionRevoked` hears each. No reason: a person leaving owes nobody one.
388
416
  */
@@ -463,5 +491,44 @@ async function serveMyImage(c, wiring) {
463
491
  ...STORED_IMAGE_HEADERS
464
492
  } });
465
493
  }
494
+ /**
495
+ * Verify an App Attest attestation against the environment's iOS apps and, when it holds, store the
496
+ * key so its later assertions verify. A failed attestation answers `auth/attestation_failed`.
497
+ */
498
+ async function registerIosKey(c, wiring, body) {
499
+ const environment = workerIdentity(c.env).environment;
500
+ const settings = assertAttestationBlock(wiring.config.attestation, environment);
501
+ const now = /* @__PURE__ */ new Date();
502
+ const verdict = await registerAppAttestKey({
503
+ db: db(c, wiring),
504
+ challenge: body.challenge,
505
+ keyId: body.keyId,
506
+ attestation: body.attestation,
507
+ apps: settings.ios,
508
+ environment,
509
+ root: wiring.appAttestRoot ?? APPLE_APP_ATTESTATION_ROOT,
510
+ now
511
+ });
512
+ if (!verdict.ok) throw new AttestationFailedError({ detail: verdict.reason });
513
+ c.header("cache-control", "no-store");
514
+ return c.json({
515
+ keyId: body.keyId,
516
+ registeredAt: now.toISOString()
517
+ });
518
+ }
519
+ /** Issue an attestation challenge, where this environment has a block to judge its use by. */
520
+ async function issueAttestationChallenge(c, wiring) {
521
+ const { attestation } = wiring.config;
522
+ assertAttestationBlock(attestation, workerIdentity(c.env).environment);
523
+ const issued = await issueChallenge(db(c, wiring), {
524
+ now: /* @__PURE__ */ new Date(),
525
+ expiresIn: attestation.challengeExpiresIn
526
+ });
527
+ c.header("cache-control", "no-store");
528
+ return c.json({
529
+ challenge: issued.challenge,
530
+ expiresAt: issued.expiresAt.toISOString()
531
+ });
532
+ }
466
533
  //#endregion
467
- export { createAuthRoutes };
534
+ export { SEND_ROUTES, createAuthRoutes };
@@ -33,6 +33,13 @@ export declare const HandoffExchangeBody: z.ZodObject<{
33
33
  verifier: z.ZodString;
34
34
  }, z.core.$strip>;
35
35
  export type HandoffExchangeBody = z.output<typeof HandoffExchangeBody>;
36
+ /** `POST {base}/attestation/ios/keys`: an App Attest key and Apple's attestation of it. */
37
+ export declare const AppAttestKeyBody: z.ZodObject<{
38
+ challenge: z.ZodString;
39
+ keyId: z.ZodString;
40
+ attestation: z.ZodString;
41
+ }, z.core.$strip>;
42
+ export type AppAttestKeyBody = z.output<typeof AppAttestKeyBody>;
36
43
  /** The providers a native app can sign in with through the system browser: every redirect provider auth offers. */
37
44
  export declare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C;AAE7D,uDAAuD;AACvD,eAAO,MAAM,eAAe;;iBAEiF,CAAC;AAC9G,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,cAAc;;kBAOoB,CAAC;AAChD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAE7D;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;;iBAM+E,CAAC;AAC9G,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -36,6 +36,12 @@ const HandoffExchangeBody = z.object({
36
36
  code: z.string().min(1).max(256).describe("The one-time code from the `code` parameter of the deep link the sign-in returned to."),
37
37
  verifier: z.string().min(1).max(256).describe("The random verifier the app made before the sign-in started: 43 to 128 characters from `A-Z a-z 0-9 - . _ ~`, as RFC 7636 shapes it. Its S256 digest is the `handoff_challenge` the sign-in's `callbackURL` carried.")
38
38
  }).describe("The code a native app trades for its session after a redirect sign-in, with the verifier that binds it.");
39
+ /** `POST {base}/attestation/ios/keys`: an App Attest key and Apple's attestation of it. */
40
+ const AppAttestKeyBody = z.object({
41
+ challenge: z.string().min(1).max(128).describe("A challenge from `POST {base}/attestation/challenge`. The app passes SHA-256 of its characters to `attestKey` as the client data hash. Spent by this request, pass or fail."),
42
+ keyId: z.string().min(1).max(256).describe("The key identifier `generateKey` returned, base64 as Apple hands it over."),
43
+ attestation: z.string().min(1).max(16384).describe("The attestation object `attestKey` returned, base64 as Apple hands it over.")
44
+ }).describe("A new App Attest key for this server to verify and register before the app makes assertions with it.");
39
45
  /** The providers a native app can sign in with through the system browser: every redirect provider auth offers. */
40
46
  const RedirectProvider = z.enum([
41
47
  "apple",
@@ -188,4 +194,4 @@ const ExportUserBody = z.object({ reason: LifecycleReason.describe("Why this per
188
194
  */
189
195
  const DeleteAccountBody = z.object({ confirm: z.literal(true).describe("Must be `true`. The person confirmed, in your app, that they want their account deleted.") }).describe("A self-service deletion: the person's own confirmation. Always soft, on the configured window.");
190
196
  //#endregion
191
- export { DeleteAccountBody, DeleteUserBody, DeletionMode, ExportUserBody, HandoffExchangeBody, ListDevicesQuery, ListUsersQuery, ListVerificationsQuery, RedirectProvider, ReinstateUserBody, RestoreUserBody, RevokeDeviceBody, RevokeSessionBody, SearchUsersBody, SocialSignInStartQuery, SuspendUserBody, UserIdParam };
197
+ export { AppAttestKeyBody, DeleteAccountBody, DeleteUserBody, DeletionMode, ExportUserBody, HandoffExchangeBody, ListDevicesQuery, ListUsersQuery, ListVerificationsQuery, RedirectProvider, ReinstateUserBody, RestoreUserBody, RevokeDeviceBody, RevokeSessionBody, SearchUsersBody, SocialSignInStartQuery, SuspendUserBody, UserIdParam };
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
+ import { AUTH_APPLE_CREDENTIALS, AUTH_GOOGLE_CREDENTIALS, AUTH_SESSION_SECRET, AppleOAuthCredentials, GoogleOAuthCredentials, authSecretsRegistry } from "./instance/secrets.js";
3
4
  import { AuthAuditActions } from "./audit/actions.js";
4
5
  import { DevicePlatform } from "./data/device.js";
5
6
  import { authDatabase } from "./data/tables.js";
6
- import { AUTH_APPLE_CREDENTIALS, AUTH_GOOGLE_CREDENTIALS, AUTH_SESSION_SECRET, AppleOAuthCredentials, GoogleOAuthCredentials, authSecretsRegistry } from "./instance/secrets.js";
7
7
  import { DEVICE_HEADERS } from "./device/registry.js";
8
8
  import { requireAuth } from "./http/middleware.js";
9
9
  import { RecentSignInOptions, requireRecentSignIn } from "./http/recentSignIn.js";
@@ -24,6 +24,9 @@ import type { SessionSecretVersions } from "./sessionSecrets";
24
24
  * - `auth-microsoft-credentials` — the Microsoft Entra ID app registration's client id, client secret,
25
25
  * and tenant, as a typed JSON value. The tenant rides inside because it means nothing apart from the
26
26
  * registration it belongs to. Rotatable: an Entra client secret expires (24 months at most).
27
+ * - `auth-play-integrity-service-account` — the Google Cloud service account JSON key the Worker decodes Play
28
+ * Integrity tokens with. Read only when an Android attestation arrives; rotated by adding a key in Google
29
+ * Cloud Console, not on our schedule.
27
30
  */
28
31
  export declare const AUTH_SESSION_SECRET = "auth-session-secret";
29
32
  export declare const AUTH_GOOGLE_CREDENTIALS = "auth-google-credentials";
@@ -31,8 +34,9 @@ export declare const AUTH_APPLE_CREDENTIALS = "auth-apple-credentials";
31
34
  export declare const AUTH_FACEBOOK_CREDENTIALS = "auth-facebook-credentials";
32
35
  export declare const AUTH_GITHUB_CREDENTIALS = "auth-github-credentials";
33
36
  export declare const AUTH_MICROSOFT_CREDENTIALS = "auth-microsoft-credentials";
37
+ export declare const AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT = "auth-play-integrity-service-account";
34
38
  /**
35
- * The JWKS private keys, as `auth-session-secret`'s overlap names them (#602).
39
+ * The JWKS private keys, as `auth-session-secret`'s overlap names them.
36
40
  *
37
41
  * Better Auth encrypts every key in `pithy_auth_jwks` under the session secret, and a key never expires —
38
42
  * so retiring the version one is sealed under would leave a signing key nothing can open. The session
@@ -96,6 +100,20 @@ export declare const MicrosoftOAuthCredentials: z.ZodObject<{
96
100
  tenantId: z.ZodString;
97
101
  }, z.core.$strip>;
98
102
  export type MicrosoftOAuthCredentials = z.infer<typeof MicrosoftOAuthCredentials>;
103
+ /**
104
+ * The Google Cloud service account key Play Integrity tokens are decoded with: the JSON file Google Cloud
105
+ * Console downloads, pasted whole. Fields auth does not read are dropped on write.
106
+ */
107
+ export declare const PlayIntegrityServiceAccount: z.ZodObject<{
108
+ type: z.ZodOptional<z.ZodLiteral<"service_account">>;
109
+ project_id: z.ZodOptional<z.ZodString>;
110
+ private_key_id: z.ZodOptional<z.ZodString>;
111
+ private_key: z.ZodString;
112
+ client_email: z.ZodString;
113
+ client_id: z.ZodOptional<z.ZodString>;
114
+ token_uri: z.ZodOptional<z.ZodString>;
115
+ }, z.core.$strip>;
116
+ export type PlayIntegrityServiceAccount = z.infer<typeof PlayIntegrityServiceAccount>;
99
117
  export declare const authSecretsRegistry: {
100
118
  readonly "auth-session-secret": {
101
119
  readonly backend: "d1";
@@ -222,9 +240,34 @@ export declare const authSecretsRegistry: {
222
240
  readonly documentation: "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
223
241
  };
224
242
  };
243
+ readonly "auth-play-integrity-service-account": {
244
+ readonly backend: "d1";
245
+ readonly scope: "environment";
246
+ readonly rotatable: false;
247
+ readonly valueType: "json";
248
+ readonly schema: z.ZodObject<{
249
+ type: z.ZodOptional<z.ZodLiteral<"service_account">>;
250
+ project_id: z.ZodOptional<z.ZodString>;
251
+ private_key_id: z.ZodOptional<z.ZodString>;
252
+ private_key: z.ZodString;
253
+ client_email: z.ZodString;
254
+ client_id: z.ZodOptional<z.ZodString>;
255
+ token_uri: z.ZodOptional<z.ZodString>;
256
+ }, z.core.$strip>;
257
+ readonly origin: {
258
+ readonly kind: "obtained";
259
+ readonly issuer: "google";
260
+ readonly documentation: "https://console.cloud.google.com/iam-admin/serviceaccounts";
261
+ };
262
+ readonly rotation: {
263
+ readonly kind: "manual";
264
+ readonly issuer: "google";
265
+ readonly documentation: "https://console.cloud.google.com/iam-admin/serviceaccounts";
266
+ };
267
+ };
225
268
  };
226
269
  /**
227
- * **The registry `auth()` contributes, from its own configuration (#602).**
270
+ * **The registry `auth()` contributes, from its own configuration.**
228
271
  *
229
272
  * The session secret's overlap follows the configured session lifetime — {@link sessionSecretOverlapDays} —
230
273
  * and it is both the overlap and its floor: an adopter who lengthens sessions lengthens the overlap with
@@ -347,6 +390,31 @@ export declare function authSecretsRegistryFor(config: {
347
390
  readonly documentation: "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
348
391
  };
349
392
  };
393
+ readonly "auth-play-integrity-service-account": {
394
+ readonly backend: "d1";
395
+ readonly scope: "environment";
396
+ readonly rotatable: false;
397
+ readonly valueType: "json";
398
+ readonly schema: z.ZodObject<{
399
+ type: z.ZodOptional<z.ZodLiteral<"service_account">>;
400
+ project_id: z.ZodOptional<z.ZodString>;
401
+ private_key_id: z.ZodOptional<z.ZodString>;
402
+ private_key: z.ZodString;
403
+ client_email: z.ZodString;
404
+ client_id: z.ZodOptional<z.ZodString>;
405
+ token_uri: z.ZodOptional<z.ZodString>;
406
+ }, z.core.$strip>;
407
+ readonly origin: {
408
+ readonly kind: "obtained";
409
+ readonly issuer: "google";
410
+ readonly documentation: "https://console.cloud.google.com/iam-admin/serviceaccounts";
411
+ };
412
+ readonly rotation: {
413
+ readonly kind: "manual";
414
+ readonly issuer: "google";
415
+ readonly documentation: "https://console.cloud.google.com/iam-admin/serviceaccounts";
416
+ };
417
+ };
350
418
  readonly "auth-session-secret": {
351
419
  readonly backend: "d1";
352
420
  readonly scope: "environment";
@@ -373,7 +441,7 @@ export declare function authSecretsRegistryFor(config: {
373
441
  };
374
442
  };
375
443
  /**
376
- * Which provider a credential belongs to — the join the CLI must never make by spelling (#541).
444
+ * Which provider a credential belongs to — the join the CLI must never make by spelling.
377
445
  *
378
446
  * `auth-apple-credentials` and the `apple` config key look like each other and that is a coincidence:
379
447
  * nothing makes a secret name and a config key the same thing, and a reporting command that matched
@@ -388,9 +456,9 @@ export type AuthProviderToggles = Record<(typeof PROVIDER_CREDENTIALS)[number][0
388
456
  * **The provider credentials this composition cannot reach**, as the `inapplicableSecrets` contribution.
389
457
  *
390
458
  * Auth declares five credentials whether or not a project runs five providers, so a project on Google
391
- * and GitHub carries two secrets nothing will ever read. `pithy doctor` asked for them every run under
392
- * *"fine to leave until you need it"* — softening, not silence, and "until you need it" is wrong about a
393
- * provider the configuration has not enabled.
459
+ * and GitHub carries two secrets nothing will ever read. A disabled provider's credential is listed as not
460
+ * applicable rather than as outstanding work: "set it until you need it" is wrong about a provider the
461
+ * configuration has not enabled.
394
462
  *
395
463
  * **The session secret is never in here**, and that is the line this draws: it is read on every sign-in
396
464
  * whatever the providers are, so it is outstanding work in every project that has not set it.
@@ -402,7 +470,7 @@ export declare function inapplicableProviderSecrets(providers: AuthProviderToggl
402
470
  /** Resolve the Better Auth session secret for this invocation — the current version alone. */
403
471
  export declare function resolveSessionSecret(env: SecretsStoreEnv): Promise<string>;
404
472
  /**
405
- * Resolve every retained version of the session secret (#602) — what an instance needs to open values sealed
473
+ * Resolve every retained version of the session secret: what an instance needs to open values sealed
406
474
  * under the previous version, and what a credential signed under it is verified against. One read through
407
475
  * the same cached accessor as {@link resolveSessionSecret}.
408
476
  */
@@ -415,6 +483,17 @@ export declare function resolveAppleCredentials(env: SecretsStoreEnv): Promise<A
415
483
  export declare function resolveFacebookCredentials(env: SecretsStoreEnv): Promise<FacebookOAuthCredentials>;
416
484
  /** Resolve the GitHub OAuth credential pair for this invocation (only call when GitHub is enabled). */
417
485
  export declare function resolveGithubCredentials(env: SecretsStoreEnv): Promise<GithubOAuthCredentials>;
486
+ /**
487
+ * The Play Integrity service account when no environment of this composition allows an Android app: nothing
488
+ * there reads it.
489
+ */
490
+ export declare function inapplicablePlayIntegritySecret(attestation: {
491
+ environments: Record<string, {
492
+ android: readonly unknown[];
493
+ }>;
494
+ }): Record<string, string>;
495
+ /** Resolve the Play Integrity service account for this invocation (only call for an Android attestation). */
496
+ export declare function resolvePlayIntegrityServiceAccount(env: SecretsStoreEnv): Promise<PlayIntegrityServiceAccount>;
418
497
  /** Resolve the Microsoft Entra ID credentials for this invocation (only call when Microsoft is enabled). */
419
498
  export declare function resolveMicrosoftCredentials(env: SecretsStoreEnv): Promise<MicrosoftOAuthCredentials>;
420
499
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/instance/secrets.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAG1E,OAAO,EAAE,CAAC,EAAE,MAAM,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e,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAGxG;AAED,uGAAuG;AACvG,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAGpG;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,WAAW,EAAE;IAC3D,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,SAAS,OAAO,EAAE,CAAA;KAAE,CAAC,CAAC;CAC/D,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKzB;AAED,6GAA6G;AAC7G,wBAAsB,kCAAkC,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAGnH;AAED,4GAA4G;AAC5G,wBAAsB,2BAA2B,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAG1G"}
@@ -26,6 +26,9 @@ import { sharedSecretsStore } from "@pithy-sh/secrets/src/sharedSecretsStore";
26
26
  * - `auth-microsoft-credentials` — the Microsoft Entra ID app registration's client id, client secret,
27
27
  * and tenant, as a typed JSON value. The tenant rides inside because it means nothing apart from the
28
28
  * registration it belongs to. Rotatable: an Entra client secret expires (24 months at most).
29
+ * - `auth-play-integrity-service-account` — the Google Cloud service account JSON key the Worker decodes Play
30
+ * Integrity tokens with. Read only when an Android attestation arrives; rotated by adding a key in Google
31
+ * Cloud Console, not on our schedule.
29
32
  */
30
33
  const AUTH_SESSION_SECRET = "auth-session-secret";
31
34
  const AUTH_GOOGLE_CREDENTIALS = "auth-google-credentials";
@@ -33,8 +36,9 @@ const AUTH_APPLE_CREDENTIALS = "auth-apple-credentials";
33
36
  const AUTH_FACEBOOK_CREDENTIALS = "auth-facebook-credentials";
34
37
  const AUTH_GITHUB_CREDENTIALS = "auth-github-credentials";
35
38
  const AUTH_MICROSOFT_CREDENTIALS = "auth-microsoft-credentials";
39
+ const AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT = "auth-play-integrity-service-account";
36
40
  /**
37
- * The JWKS private keys, as `auth-session-secret`'s overlap names them (#602).
41
+ * The JWKS private keys, as `auth-session-secret`'s overlap names them.
38
42
  *
39
43
  * Better Auth encrypts every key in `pithy_auth_jwks` under the session secret, and a key never expires —
40
44
  * so retiring the version one is sealed under would leave a signing key nothing can open. The session
@@ -98,6 +102,19 @@ const MicrosoftOAuthCredentials = z.object({
98
102
  tenantId: z.string().min(1).meta({ multiline: false }).describe("Who may sign in: a directory (tenant) ID for one organization, `organizations` for any work or school account, `consumers` for personal accounts only, or `common` for both.")
99
103
  }).describe("A Microsoft Entra ID credential set (`clientId` + `clientSecret` + `tenantId`) for one environment.");
100
104
  /**
105
+ * The Google Cloud service account key Play Integrity tokens are decoded with: the JSON file Google Cloud
106
+ * Console downloads, pasted whole. Fields auth does not read are dropped on write.
107
+ */
108
+ const PlayIntegrityServiceAccount = z.object({
109
+ type: z.literal("service_account").optional().meta({ multiline: false }).describe("The key file's kind. Google writes `service_account`."),
110
+ project_id: z.string().optional().meta({ multiline: false }).describe("The Google Cloud project the service account belongs to, linked to the app in Play Console."),
111
+ private_key_id: z.string().optional().meta({ multiline: false }).describe("The key's id, sent as the assertion's `kid` so Google picks the right public key."),
112
+ private_key: z.string().min(1).meta({ multiline: true }).describe("The RSA private key, a PKCS#8 PEM. It spans many lines, so paste the whole JSON file."),
113
+ client_email: z.string().min(1).meta({ multiline: false }).describe("The service account's address, such as `play-integrity@my-project.iam.gserviceaccount.com`."),
114
+ client_id: z.string().optional().meta({ multiline: false }).describe("The service account's numeric id. Not read; kept so the stored value matches the file."),
115
+ token_uri: z.string().regex(/^https:\/\//, "The token endpoint is an https URL.").optional().meta({ multiline: false }).describe("Google's OAuth token endpoint. Defaults to `https://oauth2.googleapis.com/token`.")
116
+ }).describe("A Google Cloud service account JSON key, for decoding Play Integrity tokens in one environment.");
117
+ /**
101
118
  * Where a human goes for each OAuth credential pair, and where the same human rotates it.
102
119
  *
103
120
  * **The settings page, not the product homepage.** The point is to end a search, not to start one — and
@@ -110,6 +127,7 @@ const APPLE_KEYS_PAGE = "https://developer.apple.com/account/resources/authkeys/
110
127
  const FACEBOOK_APPS_PAGE = "https://developers.facebook.com/apps/";
111
128
  const GITHUB_OAUTH_APPS_PAGE = "https://github.com/settings/developers";
112
129
  const MICROSOFT_APP_REGISTRATIONS_PAGE = "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
130
+ const GOOGLE_SERVICE_ACCOUNTS_PAGE = "https://console.cloud.google.com/iam-admin/serviceaccounts";
113
131
  const authSecretsRegistry = defineSecretRegistry({
114
132
  [AUTH_SESSION_SECRET]: {
115
133
  backend: "d1",
@@ -216,10 +234,27 @@ const authSecretsRegistry = defineSecretRegistry({
216
234
  issuer: "microsoft",
217
235
  documentation: MICROSOFT_APP_REGISTRATIONS_PAGE
218
236
  }
237
+ },
238
+ [AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT]: {
239
+ backend: "d1",
240
+ scope: "environment",
241
+ rotatable: false,
242
+ valueType: "json",
243
+ schema: PlayIntegrityServiceAccount,
244
+ origin: {
245
+ kind: "obtained",
246
+ issuer: "google",
247
+ documentation: GOOGLE_SERVICE_ACCOUNTS_PAGE
248
+ },
249
+ rotation: {
250
+ kind: "manual",
251
+ issuer: "google",
252
+ documentation: GOOGLE_SERVICE_ACCOUNTS_PAGE
253
+ }
219
254
  }
220
255
  });
221
256
  /**
222
- * **The registry `auth()` contributes, from its own configuration (#602).**
257
+ * **The registry `auth()` contributes, from its own configuration.**
223
258
  *
224
259
  * The session secret's overlap follows the configured session lifetime — {@link sessionSecretOverlapDays} —
225
260
  * and it is both the overlap and its floor: an adopter who lengthens sessions lengthens the overlap with
@@ -257,7 +292,7 @@ function authSecretsRegistryFor(config) {
257
292
  });
258
293
  }
259
294
  /**
260
- * Which provider a credential belongs to — the join the CLI must never make by spelling (#541).
295
+ * Which provider a credential belongs to — the join the CLI must never make by spelling.
261
296
  *
262
297
  * `auth-apple-credentials` and the `apple` config key look like each other and that is a coincidence:
263
298
  * nothing makes a secret name and a config key the same thing, and a reporting command that matched
@@ -274,9 +309,9 @@ const PROVIDER_CREDENTIALS = [
274
309
  * **The provider credentials this composition cannot reach**, as the `inapplicableSecrets` contribution.
275
310
  *
276
311
  * Auth declares five credentials whether or not a project runs five providers, so a project on Google
277
- * and GitHub carries two secrets nothing will ever read. `pithy doctor` asked for them every run under
278
- * *"fine to leave until you need it"* — softening, not silence, and "until you need it" is wrong about a
279
- * provider the configuration has not enabled.
312
+ * and GitHub carries two secrets nothing will ever read. A disabled provider's credential is listed as not
313
+ * applicable rather than as outstanding work: "set it until you need it" is wrong about a provider the
314
+ * configuration has not enabled.
280
315
  *
281
316
  * **The session secret is never in here**, and that is the line this draws: it is read on every sign-in
282
317
  * whatever the providers are, so it is outstanding work in every project that has not set it.
@@ -297,7 +332,7 @@ async function resolveSessionSecret(env) {
297
332
  return (await sharedSecretsStore(env, authSecretsRegistry)).get(AUTH_SESSION_SECRET);
298
333
  }
299
334
  /**
300
- * Resolve every retained version of the session secret (#602) — what an instance needs to open values sealed
335
+ * Resolve every retained version of the session secret: what an instance needs to open values sealed
301
336
  * under the previous version, and what a credential signed under it is verified against. One read through
302
337
  * the same cached accessor as {@link resolveSessionSecret}.
303
338
  */
@@ -320,9 +355,20 @@ async function resolveFacebookCredentials(env) {
320
355
  async function resolveGithubCredentials(env) {
321
356
  return (await sharedSecretsStore(env, authSecretsRegistry)).get(AUTH_GITHUB_CREDENTIALS);
322
357
  }
358
+ /**
359
+ * The Play Integrity service account when no environment of this composition allows an Android app: nothing
360
+ * there reads it.
361
+ */
362
+ function inapplicablePlayIntegritySecret(attestation) {
363
+ return Object.values(attestation.environments).some((block) => block.android.length > 0) ? {} : { [AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT]: "auth() allows no Android app to attest in any environment" };
364
+ }
365
+ /** Resolve the Play Integrity service account for this invocation (only call for an Android attestation). */
366
+ async function resolvePlayIntegrityServiceAccount(env) {
367
+ return (await sharedSecretsStore(env, authSecretsRegistry)).get(AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT);
368
+ }
323
369
  /** Resolve the Microsoft Entra ID credentials for this invocation (only call when Microsoft is enabled). */
324
370
  async function resolveMicrosoftCredentials(env) {
325
371
  return (await sharedSecretsStore(env, authSecretsRegistry)).get(AUTH_MICROSOFT_CREDENTIALS);
326
372
  }
327
373
  //#endregion
328
- export { AUTH_APPLE_CREDENTIALS, AUTH_FACEBOOK_CREDENTIALS, AUTH_GITHUB_CREDENTIALS, AUTH_GOOGLE_CREDENTIALS, AUTH_JWKS_DEPENDENT, AUTH_MICROSOFT_CREDENTIALS, AUTH_SESSION_SECRET, AppleOAuthCredentials, FacebookOAuthCredentials, GithubOAuthCredentials, GoogleOAuthCredentials, MicrosoftOAuthCredentials, SESSION_SECRET_SEALING_PLUGINS, authSecretsRegistry, authSecretsRegistryFor, inapplicableProviderSecrets, resolveAppleCredentials, resolveFacebookCredentials, resolveGithubCredentials, resolveGoogleCredentials, resolveMicrosoftCredentials, resolveSessionSecret, resolveSessionSecrets, sessionSecretOverlapDays };
374
+ export { AUTH_APPLE_CREDENTIALS, AUTH_FACEBOOK_CREDENTIALS, AUTH_GITHUB_CREDENTIALS, AUTH_GOOGLE_CREDENTIALS, AUTH_JWKS_DEPENDENT, AUTH_MICROSOFT_CREDENTIALS, AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT, AUTH_SESSION_SECRET, AppleOAuthCredentials, FacebookOAuthCredentials, GithubOAuthCredentials, GoogleOAuthCredentials, MicrosoftOAuthCredentials, PlayIntegrityServiceAccount, SESSION_SECRET_SEALING_PLUGINS, authSecretsRegistry, authSecretsRegistryFor, inapplicablePlayIntegritySecret, inapplicableProviderSecrets, resolveAppleCredentials, resolveFacebookCredentials, resolveGithubCredentials, resolveGoogleCredentials, resolveMicrosoftCredentials, resolvePlayIntegrityServiceAccount, resolveSessionSecret, resolveSessionSecrets, sessionSecretOverlapDays };