@pithy-sh/auth 0.15.3 → 0.17.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 (209) 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 +49 -6
  63. package/dist/capability.d.ts.map +1 -1
  64. package/dist/capability.js +42 -7
  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 +19 -1
  80. package/dist/data/tables.d.ts.map +1 -1
  81. package/dist/data/tables.js +6 -2
  82. package/dist/data/userLifecycle.d.ts +1 -0
  83. package/dist/data/userLifecycle.d.ts.map +1 -1
  84. package/dist/data/userLifecycle.js +3 -2
  85. package/dist/hooks/runtime.d.ts +32 -0
  86. package/dist/hooks/runtime.d.ts.map +1 -0
  87. package/dist/hooks/runtime.js +25 -0
  88. package/dist/http/adminRoutes.d.ts.map +1 -1
  89. package/dist/http/adminRoutes.js +4 -2
  90. package/dist/http/devLoginRoute.js +3 -3
  91. package/dist/http/resolve.d.ts.map +1 -1
  92. package/dist/http/resolve.js +3 -2
  93. package/dist/http/responses.d.ts +15 -0
  94. package/dist/http/responses.d.ts.map +1 -1
  95. package/dist/http/responses.js +13 -2
  96. package/dist/http/routes.d.ts +5 -1
  97. package/dist/http/routes.d.ts.map +1 -1
  98. package/dist/http/routes.js +92 -25
  99. package/dist/http/schemas.d.ts +7 -0
  100. package/dist/http/schemas.d.ts.map +1 -1
  101. package/dist/http/schemas.js +7 -1
  102. package/dist/index.js +1 -1
  103. package/dist/instance/secrets.d.ts +86 -7
  104. package/dist/instance/secrets.d.ts.map +1 -1
  105. package/dist/instance/secrets.js +54 -8
  106. package/dist/lifecycle/erasure.d.ts.map +1 -1
  107. package/dist/lifecycle/erasure.js +2 -1
  108. package/dist/lifecycle/hooks.d.ts +18 -10
  109. package/dist/lifecycle/hooks.d.ts.map +1 -1
  110. package/dist/lifecycle/request.d.ts +2 -1
  111. package/dist/lifecycle/request.d.ts.map +1 -1
  112. package/dist/lifecycle/request.js +4 -1
  113. package/dist/lifecycle/transitions.d.ts +24 -16
  114. package/dist/lifecycle/transitions.d.ts.map +1 -1
  115. package/dist/lifecycle/transitions.js +27 -16
  116. package/dist/migrations/0009_attestation_challenges.d.ts +9 -0
  117. package/dist/migrations/0009_attestation_challenges.d.ts.map +1 -0
  118. package/dist/migrations/0009_attestation_challenges.js +21 -0
  119. package/dist/migrations/0010_app_attest_keys.d.ts +9 -0
  120. package/dist/migrations/0010_app_attest_keys.d.ts.map +1 -0
  121. package/dist/migrations/0010_app_attest_keys.js +17 -0
  122. package/dist/migrations/0011_retained_basis_key.d.ts +10 -0
  123. package/dist/migrations/0011_retained_basis_key.d.ts.map +1 -0
  124. package/dist/migrations/0011_retained_basis_key.js +18 -0
  125. package/dist/migrations/set.d.ts +4 -1
  126. package/dist/migrations/set.d.ts.map +1 -1
  127. package/dist/migrations/set.js +8 -2
  128. package/dist/purge/run.d.ts +11 -11
  129. package/dist/purge/run.d.ts.map +1 -1
  130. package/dist/purge/run.js +9 -8
  131. package/dist/purge/workflow.d.ts +7 -1
  132. package/dist/purge/workflow.d.ts.map +1 -1
  133. package/dist/purge/workflow.js +6 -2
  134. package/dist/seeds/devSession.js +1 -1
  135. package/dist/test-utils/appAttestDevice.d.ts +92 -0
  136. package/dist/test-utils/appAttestDevice.d.ts.map +1 -0
  137. package/dist/test-utils/appAttestDevice.js +282 -0
  138. package/dist/test-utils/appAttestSample.d.ts +22 -0
  139. package/dist/test-utils/appAttestSample.d.ts.map +1 -0
  140. package/dist/test-utils/appAttestSample.js +24 -0
  141. package/dist/test-utils/googlePlay.d.ts +47 -0
  142. package/dist/test-utils/googlePlay.d.ts.map +1 -0
  143. package/dist/test-utils/googlePlay.js +117 -0
  144. package/dist/test-utils/liveApp.d.ts +76 -36
  145. package/dist/test-utils/liveApp.d.ts.map +1 -1
  146. package/dist/test-utils/liveApp.js +16 -5
  147. package/dist/test-utils/rollbackThrough.d.ts +11 -0
  148. package/dist/test-utils/rollbackThrough.d.ts.map +1 -0
  149. package/dist/test-utils/rollbackThrough.js +16 -0
  150. package/dist/test-utils/scopedBackend.d.ts +25 -0
  151. package/dist/test-utils/scopedBackend.d.ts.map +1 -1
  152. package/dist/test-utils/scopedBackend.js +1 -1
  153. package/dist/version.generated.d.ts +1 -1
  154. package/dist/version.generated.js +1 -1
  155. package/docs/account-lifecycle.md +46 -10
  156. package/docs/attestation.md +173 -0
  157. package/package.json +5 -5
  158. package/pithy.manifest.json +14 -0
  159. package/src/attestation/appAttest/assertion.ts +65 -0
  160. package/src/attestation/appAttest/attestation.ts +159 -0
  161. package/src/attestation/appAttest/authData.ts +45 -0
  162. package/src/attestation/appAttest/base64.ts +29 -0
  163. package/src/attestation/appAttest/bytes.ts +18 -0
  164. package/src/attestation/appAttest/cbor.ts +116 -0
  165. package/src/attestation/appAttest/der.ts +126 -0
  166. package/src/attestation/appAttest/keys.ts +57 -0
  167. package/src/attestation/appAttest/root.ts +13 -0
  168. package/src/attestation/appAttest/verifier.ts +113 -0
  169. package/src/attestation/appAttest/x509.ts +209 -0
  170. package/src/attestation/challenge.ts +56 -0
  171. package/src/attestation/config.ts +118 -0
  172. package/src/attestation/errors.ts +60 -0
  173. package/src/attestation/gate.ts +105 -0
  174. package/src/attestation/playIntegrity/google.ts +239 -0
  175. package/src/attestation/playIntegrity/verdict.ts +149 -0
  176. package/src/attestation/playIntegrity/verifier.ts +77 -0
  177. package/src/attestation/verifier.ts +87 -0
  178. package/src/attestation/wire.ts +79 -0
  179. package/src/capability.ts +85 -16
  180. package/src/client/api.ts +73 -40
  181. package/src/client/attestation.ts +404 -0
  182. package/src/client/projection.ts +29 -4
  183. package/src/data/appAttestKey.ts +45 -0
  184. package/src/data/attestationChallenge.ts +23 -0
  185. package/src/data/tables.ts +5 -1
  186. package/src/data/userLifecycle.ts +9 -2
  187. package/src/hooks/runtime.ts +41 -0
  188. package/src/http/adminRoutes.ts +14 -7
  189. package/src/http/resolve.ts +8 -4
  190. package/src/http/responses.ts +29 -1
  191. package/src/http/routes.ts +128 -38
  192. package/src/http/schemas.ts +24 -0
  193. package/src/instance/secrets.ts +88 -9
  194. package/src/lifecycle/erasure.ts +2 -1
  195. package/src/lifecycle/hooks.ts +22 -10
  196. package/src/lifecycle/request.ts +4 -1
  197. package/src/lifecycle/transitions.ts +47 -28
  198. package/src/migrations/0009_attestation_challenges.ts +28 -0
  199. package/src/migrations/0010_app_attest_keys.ts +27 -0
  200. package/src/migrations/0011_retained_basis_key.ts +19 -0
  201. package/src/migrations/set.ts +7 -1
  202. package/src/purge/run.ts +29 -17
  203. package/src/purge/workflow.ts +7 -3
  204. package/src/test-utils/appAttestDevice.ts +399 -0
  205. package/src/test-utils/appAttestSample.ts +20 -0
  206. package/src/test-utils/googlePlay.ts +144 -0
  207. package/src/test-utils/liveApp.ts +31 -5
  208. package/src/test-utils/rollbackThrough.ts +24 -0
  209. package/src/version.generated.ts +1 -1
@@ -0,0 +1,144 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { base64UrlDecode, base64UrlEncode } from "@pithy-sh/core/src/controlPlane/token/base64url";
5
+ import type { PlayIntegrityServiceAccount } from "../instance/secrets";
6
+
7
+ /** A service account as Google hands it over, with an RSA key made for the test, and the key to verify with. */
8
+ export interface TestServiceAccount {
9
+ account: PlayIntegrityServiceAccount;
10
+ publicKey: CryptoKey;
11
+ }
12
+
13
+ function pem(der: ArrayBuffer): string {
14
+ const body = btoa(String.fromCharCode(...new Uint8Array(der)));
15
+ const lines = body.match(/.{1,64}/g) ?? [];
16
+ return `-----BEGIN PRIVATE KEY-----\n${lines.join("\n")}\n-----END PRIVATE KEY-----\n`;
17
+ }
18
+
19
+ /** Make a service account whose `private_key` is a fresh RSA-2048 PKCS#8 PEM. */
20
+ export async function testServiceAccount(): Promise<TestServiceAccount> {
21
+ const pair = (await crypto.subtle.generateKey(
22
+ {
23
+ name: "RSASSA-PKCS1-v1_5",
24
+ modulusLength: 2048,
25
+ publicExponent: new Uint8Array([1, 0, 1]),
26
+ hash: "SHA-256",
27
+ },
28
+ true,
29
+ ["sign", "verify"],
30
+ )) as CryptoKeyPair;
31
+ const der = (await crypto.subtle.exportKey("pkcs8", pair.privateKey)) as ArrayBuffer;
32
+ return {
33
+ account: {
34
+ type: "service_account",
35
+ project_id: "example-project",
36
+ private_key_id: "0123456789abcdef",
37
+ private_key: pem(der),
38
+ client_email: "play-integrity@example-project.iam.gserviceaccount.com",
39
+ client_id: "1234567890",
40
+ token_uri: "https://oauth2.googleapis.com/token",
41
+ },
42
+ publicKey: pair.publicKey,
43
+ };
44
+ }
45
+
46
+ /** A JWT's three parts, decoded, and whether its RS256 signature verifies with `publicKey`. */
47
+ export async function readJwt(
48
+ jwt: string,
49
+ publicKey: CryptoKey,
50
+ ): Promise<{ header: Record<string, unknown>; claims: Record<string, unknown>; verified: boolean }> {
51
+ const [header = "", claims = "", signature = ""] = jwt.split(".");
52
+ const decode = (part: string) =>
53
+ JSON.parse(new TextDecoder().decode(base64UrlDecode(part))) as Record<string, unknown>;
54
+ const verified = await crypto.subtle.verify(
55
+ "RSASSA-PKCS1-v1_5",
56
+ publicKey,
57
+ base64UrlDecode(signature) as Uint8Array<ArrayBuffer>,
58
+ new TextEncoder().encode(`${header}.${claims}`),
59
+ );
60
+ return { header: decode(header), claims: decode(claims), verified };
61
+ }
62
+
63
+ /** One request the stub saw. */
64
+ export interface SeenRequest {
65
+ url: string;
66
+ method: string;
67
+ headers: Headers;
68
+ body: string;
69
+ }
70
+
71
+ /** A recorded answer: a status and a JSON body. */
72
+ export interface StubAnswer {
73
+ status: number;
74
+ body: unknown;
75
+ }
76
+
77
+ /**
78
+ * A `fetch` that answers Google's token endpoint and `decodeIntegrityToken`, from the answers it is handed, and
79
+ * records every request. Any other URL is a test fault and throws.
80
+ */
81
+ export function googleFetch(answers: {
82
+ token?: StubAnswer | (() => StubAnswer | Promise<StubAnswer>);
83
+ decode?: StubAnswer | ((request: SeenRequest) => StubAnswer | Promise<StubAnswer>);
84
+ }): { fetch: typeof fetch; seen: SeenRequest[] } {
85
+ const seen: SeenRequest[] = [];
86
+ const respond = (answer: StubAnswer) =>
87
+ new Response(JSON.stringify(answer.body), {
88
+ status: answer.status,
89
+ headers: { "content-type": "application/json" },
90
+ });
91
+ const stub = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
92
+ const request = new Request(input, init);
93
+ const record: SeenRequest = {
94
+ url: request.url,
95
+ method: request.method,
96
+ headers: request.headers,
97
+ body: await request.text(),
98
+ };
99
+ seen.push(record);
100
+ if (record.url === "https://oauth2.googleapis.com/token") {
101
+ const answer = answers.token ?? { status: 200, body: { access_token: "ya29.test", expires_in: 3599 } };
102
+ return respond(typeof answer === "function" ? await answer() : answer);
103
+ }
104
+ if (record.url.startsWith("https://playintegrity.googleapis.com/v1/")) {
105
+ const answer = answers.decode ?? { status: 500, body: {} };
106
+ return respond(typeof answer === "function" ? await answer(record) : answer);
107
+ }
108
+ throw new Error(`googleFetch: no stub for ${record.url}`);
109
+ };
110
+ return { fetch: stub as typeof fetch, seen };
111
+ }
112
+
113
+ /** A `decodeIntegrityToken` answer that passes, bound to `binding`, as Google records it for a standard request. */
114
+ export function passingDecode(binding: Uint8Array, now: Date, packageName = "com.example.app"): StubAnswer {
115
+ return passingDecodeOf(base64UrlEncode(binding), now, packageName);
116
+ }
117
+
118
+ /**
119
+ * A `decodeIntegrityToken` answer that passes, carrying `requestHash` exactly as the app handed it to Play Integrity:
120
+ * Google records the string it was given, so the Worker compares the client's own characters.
121
+ */
122
+ export function passingDecodeOf(requestHash: string, now: Date, packageName = "com.example.app"): StubAnswer {
123
+ return {
124
+ status: 200,
125
+ body: {
126
+ tokenPayloadExternal: {
127
+ requestDetails: {
128
+ requestPackageName: packageName,
129
+ requestHash,
130
+ timestampMillis: String(now.getTime() - 1_500),
131
+ },
132
+ appIntegrity: {
133
+ appRecognitionVerdict: "PLAY_RECOGNIZED",
134
+ packageName,
135
+ certificateSha256Digest: ["6a6a1474b5cbbb2b1aa57e0bc3"],
136
+ versionCode: "42",
137
+ },
138
+ deviceIntegrity: { deviceRecognitionVerdict: ["MEETS_DEVICE_INTEGRITY"] },
139
+ accountDetails: { appLicensingVerdict: "LICENSED" },
140
+ environmentDetails: { playProtectVerdict: "NO_ISSUES" },
141
+ },
142
+ },
143
+ };
144
+ }
@@ -18,17 +18,21 @@ import { type SecretFixture, seedSecrets } from "@pithy-sh/secrets/src/test-util
18
18
  import { turnstileSecretsRegistry } from "@pithy-sh/turnstile/src/secret/registry";
19
19
  import { Hono } from "hono";
20
20
  import { convertV4MiniflareOptions, Miniflare } from "miniflare";
21
+ import type { z } from "zod";
22
+ import type { AttestationConfig } from "../attestation/config";
23
+ import { createPlayIntegrityVerifier } from "../attestation/playIntegrity/verifier";
24
+ import { PLATFORM_VERIFIERS } from "../attestation/verifier";
21
25
  import { AuthConfig, type AuthWiring } from "../capability";
22
26
  import { publishSameOrigin } from "../http/csrf";
23
27
  import { createSessionMiddleware } from "../http/middleware";
24
28
  import { createRateLimitMiddleware } from "../http/rateLimit";
25
29
  import { createAuthRoutes } from "../http/routes";
26
- import { authSecretsRegistry } from "../instance/secrets";
30
+ import { authSecretsRegistry, type PlayIntegrityServiceAccount } from "../instance/secrets";
27
31
  import { AUTH_MIGRATION_ORDER } from "../migrations/0001_init";
28
32
  import { AUTH_MIGRATIONS } from "../migrations/set";
29
33
 
30
34
  /**
31
- * A real auth Worker on a real port, for the live suites (#84).
35
+ * A real auth Worker on a real port, for the live suites.
32
36
  *
33
37
  * The live E2E questions this package has are about an **origin**: which `redirect_uri` Better Auth
34
38
  * hands Google, whether a token posted from a browser survives the humanity gate, whether a callback
@@ -42,7 +46,7 @@ import { AUTH_MIGRATIONS } from "../migrations/set";
42
46
  *
43
47
  * - **Miniflare supplies D1**, from Node rather than from inside a worker. Two databases, as a deployed
44
48
  * worker has: `DB` for the `pithy_auth_*` and `pithy_email_*` tables, `SECRETS` for the encrypted
45
- * rows every secret is read from (#153). No plaintext binding stands in for either.
49
+ * rows every secret is read from. No plaintext binding stands in for either.
46
50
  * - **The migrations are the real ones**, run through the real registry and runner.
47
51
  * - **`node:http` gives the port.** Vitest's `fetch` reaches the app the way a browser would, so an
48
52
  * `Origin` header is a real one and a `Set-Cookie` is a real one.
@@ -62,6 +66,8 @@ export function resetLiveSecrets(): void {
62
66
  /** Tables the app database holds once both capabilities' migrations have run. */
63
67
  const TABLES = [
64
68
  "pithy_auth_accounts",
69
+ "pithy_auth_app_attest_keys",
70
+ "pithy_auth_attestation_challenges",
65
71
  "pithy_auth_devices",
66
72
  "pithy_auth_jwks",
67
73
  "pithy_auth_rate_limit",
@@ -111,10 +117,19 @@ export interface LiveAppOptions {
111
117
  * stanza. `dev` by default, because that is what these suites are: a developer's machine, running the
112
118
  * stack the way `pithy dev` does.
113
119
  *
114
- * It is an option because one thing now reads it — the turnstile gate refuses a Cloudflare test key
115
- * outside dev and staging (#374) — so a suite has to be able to say it is prod to prove that.
120
+ * It is an option because the turnstile gate refuses a Cloudflare test key
121
+ * outside dev and staging — so a suite has to be able to say it is prod to prove that.
116
122
  */
117
123
  environment?: string;
124
+ /** Auth's `attestation` block, as `auth()` takes it. Absent, attestation is not configured. */
125
+ attestation?: z.input<typeof AttestationConfig>;
126
+ /** The root an App Attest key's chain must lead to, DER, in place of Apple's: a test device's. */
127
+ appAttestRoot?: Uint8Array;
128
+ /**
129
+ * Play Integrity's service account, stored as auth's secret, and the `fetch` the verifier calls Google with: a
130
+ * stand-in for Google's token endpoint and `decodeIntegrityToken`, so Google is the one thing not live.
131
+ */
132
+ playIntegrity?: { account: PlayIntegrityServiceAccount; fetch: typeof fetch } | undefined;
118
133
  }
119
134
 
120
135
  /** A booted app: where it listens, what it was pinned to, and what it recorded. */
@@ -182,6 +197,7 @@ export async function startLiveApp(options: LiveAppOptions): Promise<LiveApp> {
182
197
 
183
198
  const fixture: SecretFixture<typeof LIVE_REGISTRY> = { "auth-session-secret": SESSION_SECRET };
184
199
  if (options.google) fixture["auth-google-credentials"] = options.google;
200
+ if (options.playIntegrity) fixture["auth-play-integrity-service-account"] = options.playIntegrity.account;
185
201
  if (options.turnstile) {
186
202
  fixture["turnstile-secret-keys"] = { [options.turnstile.mode]: { key: options.turnstile.secretKey } };
187
203
  }
@@ -199,12 +215,22 @@ export async function startLiveApp(options: LiveAppOptions): Promise<LiveApp> {
199
215
  basePath: options.basePath,
200
216
  trustedOrigins: [origin],
201
217
  google: { enabled: Boolean(options.google) },
218
+ ...(options.attestation ? { attestation: options.attestation } : {}),
202
219
  }),
203
220
  resolveGithubUserInfo: undefined,
204
221
  enqueueEmail: emailCapability.enqueue,
205
222
  turnstile: options.turnstile
206
223
  ? { mode: options.turnstile.mode, token: { field: "cf-turnstile-response" } }
207
224
  : undefined,
225
+ appAttestRoot: options.appAttestRoot,
226
+ ...(options.playIntegrity
227
+ ? {
228
+ attestationVerifiers: {
229
+ ...PLATFORM_VERIFIERS,
230
+ android: createPlayIntegrityVerifier({ fetch: options.playIntegrity.fetch }),
231
+ },
232
+ }
233
+ : {}),
208
234
  };
209
235
 
210
236
  const app = buildApp(wiring, events);
@@ -0,0 +1,24 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { D1Database } from "@cloudflare/workers-types";
5
+ import { MIGRATION_TABLE } from "@pithy-sh/core/src/migrations/bookkeeping";
6
+ import { rollbackMigration } from "@pithy-sh/core/src/migrations/runner";
7
+ import type { MigrationProvider } from "kysely/migration";
8
+ import type { AUTH_MIGRATIONS } from "../migrations/set";
9
+
10
+ /**
11
+ * Roll the auth chain back until `key` is no longer applied, so a migration's own `down` is reached however many
12
+ * migrations were appended after it. Throws when `key` was never applied.
13
+ */
14
+ export async function rollbackThrough(
15
+ d1: D1Database,
16
+ provider: MigrationProvider,
17
+ key: keyof typeof AUTH_MIGRATIONS,
18
+ ): Promise<void> {
19
+ const applied = async () =>
20
+ (await d1.prepare(`select name from ${MIGRATION_TABLE} where name like ? limit 1`).bind(`%auth_${key}`).first()) !==
21
+ null;
22
+ if (!(await applied())) throw new Error(`auth migration ${key} is not applied`);
23
+ while (await applied()) await rollbackMigration(d1, provider);
24
+ }
@@ -13,4 +13,4 @@
13
13
  export const PACKAGE_NAME = "@pithy-sh/auth";
14
14
 
15
15
  /** This package's version, stamped from its own package.json at generation time. */
16
- export const PACKAGE_VERSION = "0.15.3";
16
+ export const PACKAGE_VERSION = "0.17.0";