@pithy-sh/auth 0.15.3 → 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.
- package/README.md +4 -0
- package/dist/attestation/appAttest/assertion.d.ts +32 -0
- package/dist/attestation/appAttest/assertion.d.ts.map +1 -0
- package/dist/attestation/appAttest/assertion.js +59 -0
- package/dist/attestation/appAttest/attestation.d.ts +49 -0
- package/dist/attestation/appAttest/attestation.d.ts.map +1 -0
- package/dist/attestation/appAttest/attestation.js +111 -0
- package/dist/attestation/appAttest/authData.d.ts +24 -0
- package/dist/attestation/appAttest/authData.d.ts.map +1 -0
- package/dist/attestation/appAttest/authData.js +32 -0
- package/dist/attestation/appAttest/base64.d.ts +8 -0
- package/dist/attestation/appAttest/base64.d.ts.map +1 -0
- package/dist/attestation/appAttest/base64.js +27 -0
- package/dist/attestation/appAttest/bytes.d.ts +7 -0
- package/dist/attestation/appAttest/bytes.d.ts.map +1 -0
- package/dist/attestation/appAttest/bytes.js +19 -0
- package/dist/attestation/appAttest/cbor.d.ts +20 -0
- package/dist/attestation/appAttest/cbor.d.ts.map +1 -0
- package/dist/attestation/appAttest/cbor.js +96 -0
- package/dist/attestation/appAttest/der.d.ts +38 -0
- package/dist/attestation/appAttest/der.d.ts.map +1 -0
- package/dist/attestation/appAttest/der.js +106 -0
- package/dist/attestation/appAttest/keys.d.ts +15 -0
- package/dist/attestation/appAttest/keys.d.ts.map +1 -0
- package/dist/attestation/appAttest/keys.js +37 -0
- package/dist/attestation/appAttest/root.d.ts +9 -0
- package/dist/attestation/appAttest/root.d.ts.map +1 -0
- package/dist/attestation/appAttest/root.js +12 -0
- package/dist/attestation/appAttest/verifier.d.ts +39 -0
- package/dist/attestation/appAttest/verifier.d.ts.map +1 -0
- package/dist/attestation/appAttest/verifier.js +121 -0
- package/dist/attestation/appAttest/x509.d.ts +50 -0
- package/dist/attestation/appAttest/x509.d.ts.map +1 -0
- package/dist/attestation/appAttest/x509.js +163 -0
- package/dist/attestation/challenge.d.ts +26 -0
- package/dist/attestation/challenge.d.ts.map +1 -0
- package/dist/attestation/challenge.js +47 -0
- package/dist/attestation/config.d.ts +72 -0
- package/dist/attestation/config.d.ts.map +1 -0
- package/dist/attestation/config.js +52 -0
- package/dist/attestation/errors.d.ts +30 -0
- package/dist/attestation/errors.d.ts.map +1 -0
- package/dist/attestation/errors.js +45 -0
- package/dist/attestation/gate.d.ts +27 -0
- package/dist/attestation/gate.d.ts.map +1 -0
- package/dist/attestation/gate.js +78 -0
- package/dist/attestation/playIntegrity/google.d.ts +47 -0
- package/dist/attestation/playIntegrity/google.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/google.js +178 -0
- package/dist/attestation/playIntegrity/verdict.d.ts +40 -0
- package/dist/attestation/playIntegrity/verdict.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/verdict.js +93 -0
- package/dist/attestation/playIntegrity/verifier.d.ts +22 -0
- package/dist/attestation/playIntegrity/verifier.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/verifier.js +64 -0
- package/dist/attestation/verifier.d.ts +60 -0
- package/dist/attestation/verifier.d.ts.map +1 -0
- package/dist/attestation/verifier.js +46 -0
- package/dist/attestation/wire.d.ts +42 -0
- package/dist/attestation/wire.d.ts.map +1 -0
- package/dist/attestation/wire.js +72 -0
- package/dist/capability.d.ts +40 -0
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +38 -5
- package/dist/client/api.d.ts +37 -24
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +52 -41
- package/dist/client/attestation.d.ts +148 -0
- package/dist/client/attestation.d.ts.map +1 -0
- package/dist/client/attestation.js +321 -0
- package/dist/client/projection.d.ts +29 -4
- package/dist/client/projection.d.ts.map +1 -1
- package/dist/data/appAttestKey.d.ts +30 -0
- package/dist/data/appAttestKey.d.ts.map +1 -0
- package/dist/data/appAttestKey.js +25 -0
- package/dist/data/attestationChallenge.d.ts +17 -0
- package/dist/data/attestationChallenge.d.ts.map +1 -0
- package/dist/data/attestationChallenge.js +19 -0
- package/dist/data/tables.d.ts +18 -1
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +6 -2
- package/dist/http/devLoginRoute.js +3 -3
- package/dist/http/resolve.js +1 -1
- package/dist/http/responses.d.ts +12 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +11 -1
- package/dist/http/routes.d.ts +5 -1
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +92 -25
- package/dist/http/schemas.d.ts +7 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +7 -1
- package/dist/index.js +1 -1
- package/dist/instance/secrets.d.ts +86 -7
- package/dist/instance/secrets.d.ts.map +1 -1
- package/dist/instance/secrets.js +54 -8
- package/dist/migrations/0009_attestation_challenges.d.ts +9 -0
- package/dist/migrations/0009_attestation_challenges.d.ts.map +1 -0
- package/dist/migrations/0009_attestation_challenges.js +21 -0
- package/dist/migrations/0010_app_attest_keys.d.ts +9 -0
- package/dist/migrations/0010_app_attest_keys.d.ts.map +1 -0
- package/dist/migrations/0010_app_attest_keys.js +17 -0
- package/dist/migrations/set.d.ts +3 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +6 -2
- package/dist/seeds/devSession.js +1 -1
- package/dist/test-utils/appAttestDevice.d.ts +92 -0
- package/dist/test-utils/appAttestDevice.d.ts.map +1 -0
- package/dist/test-utils/appAttestDevice.js +282 -0
- package/dist/test-utils/appAttestSample.d.ts +22 -0
- package/dist/test-utils/appAttestSample.d.ts.map +1 -0
- package/dist/test-utils/appAttestSample.js +24 -0
- package/dist/test-utils/googlePlay.d.ts +47 -0
- package/dist/test-utils/googlePlay.d.ts.map +1 -0
- package/dist/test-utils/googlePlay.js +117 -0
- package/dist/test-utils/liveApp.d.ts +76 -36
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +16 -5
- package/dist/test-utils/rollbackThrough.d.ts +11 -0
- package/dist/test-utils/rollbackThrough.d.ts.map +1 -0
- package/dist/test-utils/rollbackThrough.js +16 -0
- package/dist/test-utils/scopedBackend.d.ts +25 -0
- package/dist/test-utils/scopedBackend.d.ts.map +1 -1
- package/dist/test-utils/scopedBackend.js +1 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/attestation.md +173 -0
- package/package.json +5 -5
- package/pithy.manifest.json +14 -0
- package/src/attestation/appAttest/assertion.ts +65 -0
- package/src/attestation/appAttest/attestation.ts +159 -0
- package/src/attestation/appAttest/authData.ts +45 -0
- package/src/attestation/appAttest/base64.ts +29 -0
- package/src/attestation/appAttest/bytes.ts +18 -0
- package/src/attestation/appAttest/cbor.ts +116 -0
- package/src/attestation/appAttest/der.ts +126 -0
- package/src/attestation/appAttest/keys.ts +57 -0
- package/src/attestation/appAttest/root.ts +13 -0
- package/src/attestation/appAttest/verifier.ts +113 -0
- package/src/attestation/appAttest/x509.ts +209 -0
- package/src/attestation/challenge.ts +56 -0
- package/src/attestation/config.ts +118 -0
- package/src/attestation/errors.ts +60 -0
- package/src/attestation/gate.ts +105 -0
- package/src/attestation/playIntegrity/google.ts +239 -0
- package/src/attestation/playIntegrity/verdict.ts +149 -0
- package/src/attestation/playIntegrity/verifier.ts +77 -0
- package/src/attestation/verifier.ts +87 -0
- package/src/attestation/wire.ts +79 -0
- package/src/capability.ts +64 -8
- package/src/client/api.ts +73 -40
- package/src/client/attestation.ts +404 -0
- package/src/client/projection.ts +29 -4
- package/src/data/appAttestKey.ts +45 -0
- package/src/data/attestationChallenge.ts +23 -0
- package/src/data/tables.ts +5 -1
- package/src/http/responses.ts +22 -0
- package/src/http/routes.ts +128 -38
- package/src/http/schemas.ts +24 -0
- package/src/instance/secrets.ts +88 -9
- package/src/migrations/0009_attestation_challenges.ts +28 -0
- package/src/migrations/0010_app_attest_keys.ts +27 -0
- package/src/migrations/set.ts +5 -1
- package/src/test-utils/appAttestDevice.ts +399 -0
- package/src/test-utils/appAttestSample.ts +20 -0
- package/src/test-utils/googlePlay.ts +144 -0
- package/src/test-utils/liveApp.ts +31 -5
- package/src/test-utils/rollbackThrough.ts +24 -0
- package/src/version.generated.ts +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The sample attestation Apple publishes in its Attestation Object Validation Guide
|
|
6
|
+
* (https://developer.apple.com/documentation/devicecheck/attestation-object-validation-guide): a real device's
|
|
7
|
+
* attestation, in Apple's production environment, chaining to Apple App Attestation Root CA.
|
|
8
|
+
*
|
|
9
|
+
* The app passed the challenge's own bytes to `attestKey` as its client data hash, which is why
|
|
10
|
+
* {@link APPLE_SAMPLE.clientDataHash} is the challenge text and not its digest. Its leaf certificate is valid from
|
|
11
|
+
* 2026-04-20T18:13:12Z to 2026-04-23T18:13:12Z, so it verifies only at a time inside that window.
|
|
12
|
+
*/
|
|
13
|
+
export const APPLE_SAMPLE = {
|
|
14
|
+
app: { teamId: "1234567890", bundleId: "com.example.myapp" },
|
|
15
|
+
keyId: "zgSY9YSD+7TaDXssY6WlOPVS1K3Lmk+pFhlcSWE+ZV0=",
|
|
16
|
+
clientDataHash: new TextEncoder().encode("example_server_challenge"),
|
|
17
|
+
at: new Date("2026-04-21T12:00:00.000Z"),
|
|
18
|
+
attestation:
|
|
19
|
+
"o2NmbXRvYXBwbGUtYXBwYXR0ZXN0Z2F0dFN0bXSiY3g1Y4JZBCEwggQdMIIDo6ADAgECAgYBnbE/C04wCgYIKoZIzj0EAwIwTzEjMCEGA1UEAwwaQXBwbGUgQXBwIEF0dGVzdGF0aW9uIENBIDExEzARBgNVBAoMCkFwcGxlIEluYy4xEzARBgNVBAgMCkNhbGlmb3JuaWEwHhcNMjYwNDIwMTgxMzEyWhcNMjYwNDIzMTgxMzEyWjCBkTFJMEcGA1UEAwxAY2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VLUrcuaT6kWGVxJYT5lXaUBAgMmIAEhWCBDMlRKzzI9t3REPKrzOfVufpXHJPrCwUJZ82XiRFZQsiJYILX7KFvPVJvLYFlEEudoKiQn7q2p+1Lf7QsasX7Qn6m9ondhcHBsZV9idW5kbGVfdmVyc2lvbl8wMWExeBxhcHBsZV92YWxpZGF0aW9uX2NhdGVnb3J5XzAxRAEAAAA=",
|
|
20
|
+
} as const;
|
|
@@ -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
|
|
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
|
|
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
|
|
115
|
-
* outside dev and staging
|
|
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
|
+
}
|
package/src/version.generated.ts
CHANGED