@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,93 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ import { base64UrlEncode } from "@pithy-sh/core/src/controlPlane/token/base64url";
5
+ //#region src/attestation/playIntegrity/verdict.ts
6
+ /** How long after it was requested a token is still accepted, in seconds. */
7
+ const PLAY_INTEGRITY_MAX_AGE_SECONDS = 300;
8
+ /** How far ahead of the Worker's clock a token's timestamp may be, in seconds. */
9
+ const PLAY_INTEGRITY_MAX_SKEW_SECONDS = 60;
10
+ /** The device label every accepted verdict carries. */
11
+ const DEVICE_INTEGRITY = "MEETS_DEVICE_INTEGRITY";
12
+ /** The parts of `tokenPayloadExternal` auth judges. Every other field is ignored. */
13
+ const IntegrityTokenPayload = z.object({
14
+ requestDetails: z.object({
15
+ requestPackageName: z.string().describe("The package name the app requested the token for."),
16
+ requestHash: z.string().optional().describe("A standard request's binding: the base64url of SHA-256 over the challenge and the body."),
17
+ nonce: z.string().optional().describe("A classic request's binding, when the app sent one instead."),
18
+ timestampMillis: z.string().describe("When the token was requested, in milliseconds since the epoch.")
19
+ }).describe("What the app asked for, as Google recorded it."),
20
+ appIntegrity: z.object({
21
+ appRecognitionVerdict: z.string().optional().describe("`PLAY_RECOGNIZED` when the binary is the one Google Play distributes."),
22
+ packageName: z.string().optional().describe("The package Google Play attested the binary as. Unlike `requestPackageName`, Google vouches for it.")
23
+ }).optional().describe("Google Play's verdict on the app binary."),
24
+ deviceIntegrity: z.object({ deviceRecognitionVerdict: z.array(z.string()).optional().describe("The integrity labels the device meets, such as `MEETS_DEVICE_INTEGRITY`.") }).optional().describe("Google Play's verdict on the device.")
25
+ }).describe("A decoded Play Integrity token, as `decodeIntegrityToken` returns it in `tokenPayloadExternal`.");
26
+ const stripPadding = (value) => value.replace(/=+$/, "");
27
+ /** The binding check: `requestHash` on a standard request, `nonce` on a classic one, padding ignored. */
28
+ function judgeBinding(details, binding) {
29
+ const expected = base64UrlEncode(binding);
30
+ if (details.requestHash !== void 0) return stripPadding(details.requestHash) === expected ? { ok: true } : {
31
+ ok: false,
32
+ reason: "requestHash: the token is bound to another challenge or body"
33
+ };
34
+ if (details.nonce !== void 0) return stripPadding(details.nonce) === expected ? { ok: true } : {
35
+ ok: false,
36
+ reason: "nonce: the token is bound to another challenge or body"
37
+ };
38
+ return {
39
+ ok: false,
40
+ reason: "requestHash: the token carries neither a requestHash nor a nonce"
41
+ };
42
+ }
43
+ /**
44
+ * Judge a decoded Play Integrity payload. `reason` starts with the check that failed: `format`, `requestHash` or
45
+ * `nonce`, `requestPackageName`, `appRecognitionVerdict`, `appIntegrity` (the package Google attested is another
46
+ * app's), `deviceIntegrity` or `timestamp`.
47
+ */
48
+ function judgeIntegrityVerdict(payload, expected) {
49
+ const parsed = IntegrityTokenPayload.safeParse(payload);
50
+ if (!parsed.success) return {
51
+ ok: false,
52
+ reason: `format: the decoded token has the wrong shape: ${parsed.error.issues[0]?.message}`
53
+ };
54
+ const { requestDetails, appIntegrity, deviceIntegrity } = parsed.data;
55
+ const binding = judgeBinding(requestDetails, expected.binding);
56
+ if (!binding.ok) return binding;
57
+ if (requestDetails.requestPackageName !== expected.packageName) return {
58
+ ok: false,
59
+ reason: `requestPackageName: the token was requested for ${requestDetails.requestPackageName}, not ${expected.packageName}`
60
+ };
61
+ const recognition = appIntegrity?.appRecognitionVerdict ?? "absent";
62
+ if (recognition !== "PLAY_RECOGNIZED") return {
63
+ ok: false,
64
+ reason: `appRecognitionVerdict: Google Play calls the app ${recognition}`
65
+ };
66
+ const attested = appIntegrity?.packageName;
67
+ if (attested !== expected.packageName) return {
68
+ ok: false,
69
+ reason: `appIntegrity: Google Play attested the app as ${attested ?? "no package"}, not ${expected.packageName}`
70
+ };
71
+ const labels = deviceIntegrity?.deviceRecognitionVerdict ?? [];
72
+ if (!labels.includes(DEVICE_INTEGRITY)) return {
73
+ ok: false,
74
+ reason: `deviceIntegrity: the device does not meet ${DEVICE_INTEGRITY} (${labels.length === 0 ? "no label" : labels.join(", ")})`
75
+ };
76
+ const requestedAt = /^\d+$/.test(requestDetails.timestampMillis) ? Number(requestDetails.timestampMillis) : NaN;
77
+ if (!Number.isSafeInteger(requestedAt)) return {
78
+ ok: false,
79
+ reason: "timestamp: timestampMillis is not a number"
80
+ };
81
+ const age = expected.now.getTime() - requestedAt;
82
+ if (age > 3e5) return {
83
+ ok: false,
84
+ reason: `timestamp: the token was requested ${Math.round(age / 1e3)}s ago, over the 300s window`
85
+ };
86
+ if (-age > 6e4) return {
87
+ ok: false,
88
+ reason: `timestamp: the token is stamped ${Math.round(-age / 1e3)}s ahead of the Worker's clock`
89
+ };
90
+ return { ok: true };
91
+ }
92
+ //#endregion
93
+ export { IntegrityTokenPayload, PLAY_INTEGRITY_MAX_AGE_SECONDS, PLAY_INTEGRITY_MAX_SKEW_SECONDS, judgeIntegrityVerdict };
@@ -0,0 +1,22 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { type PlayIntegrityServiceAccount } from "../../instance/secrets";
4
+ import type { AttestationVerifier } from "../verifier";
5
+ /** What a Play Integrity verifier is built from. Both default to the Worker's own. */
6
+ export interface PlayIntegrityVerifierOptions {
7
+ /** How Google is called. */
8
+ fetch?: typeof fetch;
9
+ /** Where the service account is read from: auth's secret registry, by default. */
10
+ serviceAccount?: (env: Readonly<Record<string, unknown>>) => Promise<PlayIntegrityServiceAccount>;
11
+ }
12
+ /**
13
+ * Google Play Integrity. Decodes the token through Google's `decodeIntegrityToken` with the environment's service
14
+ * account, for each allowed package until one decodes, then judges the verdict against the request binding.
15
+ *
16
+ * The access token is held per service account for its lifetime, across requests this isolate serves. A Google
17
+ * credential or setup fault is `auth/attestation_config`, and the token is dropped so the next request mints anew.
18
+ */
19
+ export declare function createPlayIntegrityVerifier(options?: PlayIntegrityVerifierOptions): AttestationVerifier;
20
+ /** The Play Integrity verifier a Worker runs, calling Google with its own `fetch`. */
21
+ export declare const playIntegrityVerifier: AttestationVerifier;
22
+ //# sourceMappingURL=verifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifier.d.ts","sourceRoot":"","sources":["../../../src/attestation/playIntegrity/verifier.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,2BAA2B,EAEjC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAIvD,sFAAsF;AACtF,MAAM,WAAW,4BAA4B;IAC3C,4BAA4B;IAC5B,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,kFAAkF;IAClF,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,OAAO,CAAC,2BAA2B,CAAC,CAAC;CACnG;AAgBD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,GAAE,4BAAiC,GAAG,mBAAmB,CA8B3G;AAED,sFAAsF;AACtF,eAAO,MAAM,qBAAqB,EAAE,mBAAmD,CAAC"}
@@ -0,0 +1,64 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT, resolvePlayIntegrityServiceAccount } from "../../instance/secrets.js";
4
+ import { AttestationConfigError } from "../errors.js";
5
+ import { SERVICE_ACCOUNT_ACTION, createGoogleAccessTokens, decodeIntegrityToken } from "./google.js";
6
+ import { judgeIntegrityVerdict } from "./verdict.js";
7
+ //#region src/attestation/playIntegrity/verifier.ts
8
+ async function readServiceAccount(read, env) {
9
+ try {
10
+ return await read(env);
11
+ } catch (error) {
12
+ throw new AttestationConfigError({
13
+ detail: `the ${AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT} secret could not be read: ${error instanceof Error ? error.message : String(error)}`,
14
+ action: SERVICE_ACCOUNT_ACTION
15
+ });
16
+ }
17
+ }
18
+ /**
19
+ * Google Play Integrity. Decodes the token through Google's `decodeIntegrityToken` with the environment's service
20
+ * account, for each allowed package until one decodes, then judges the verdict against the request binding.
21
+ *
22
+ * The access token is held per service account for its lifetime, across requests this isolate serves. A Google
23
+ * credential or setup fault is `auth/attestation_config`, and the token is dropped so the next request mints anew.
24
+ */
25
+ function createPlayIntegrityVerifier(options = {}) {
26
+ const fetchImpl = options.fetch ?? ((input, init) => fetch(input, init));
27
+ const read = options.serviceAccount ?? ((env) => resolvePlayIntegrityServiceAccount(env));
28
+ const tokens = createGoogleAccessTokens(fetchImpl);
29
+ return { async verify({ presented, binding, settings, env, now }) {
30
+ if (settings.android.length === 0) return {
31
+ ok: false,
32
+ reason: "requestPackageName: no Android app is allowed to attest here"
33
+ };
34
+ const account = await readServiceAccount(read, env);
35
+ const refusals = [];
36
+ try {
37
+ const accessToken = await tokens.get(account, now);
38
+ for (const { packageName } of settings.android) {
39
+ const decoded = await decodeIntegrityToken(fetchImpl, {
40
+ accessToken,
41
+ packageName,
42
+ token: presented.assertion
43
+ });
44
+ if (decoded.ok) return judgeIntegrityVerdict(decoded.payload, {
45
+ binding,
46
+ packageName,
47
+ now
48
+ });
49
+ refusals.push(decoded.reason);
50
+ }
51
+ } catch (error) {
52
+ if (error instanceof AttestationConfigError) tokens.drop(account);
53
+ throw error;
54
+ }
55
+ return {
56
+ ok: false,
57
+ reason: `decode: ${refusals.join("; ")}`
58
+ };
59
+ } };
60
+ }
61
+ /** The Play Integrity verifier a Worker runs, calling Google with its own `fetch`. */
62
+ const playIntegrityVerifier = createPlayIntegrityVerifier();
63
+ //#endregion
64
+ export { createPlayIntegrityVerifier, playIntegrityVerifier };
@@ -0,0 +1,60 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import type { AuthDatabase } from "../data/tables";
4
+ import { type AttestationEnvironment, type AttestationPlatform } from "./config";
5
+ import type { PresentedAttestation } from "./wire";
6
+ /**
7
+ * The documented test assertion. In dev, staging or a feature deployment set to `test`, the gate accepts it from
8
+ * either platform in place of a real one, so simulators, emulators and CI get through.
9
+ */
10
+ export declare const ATTESTATION_TEST_ASSERTION = "pithy-test-attestation";
11
+ /** Everything a verifier is handed for one attestation. The challenge is already spent and was live. */
12
+ export interface AttestationVerification {
13
+ /** The decoded header. */
14
+ presented: PresentedAttestation;
15
+ /** {@link import("./wire").requestBinding} for this request: what the assertion must be made over. */
16
+ binding: Uint8Array;
17
+ /** The environment the Worker is stamped with, or `null` for an unstamped Worker. */
18
+ environment: string | null;
19
+ /** This environment's attestation block: the apps allowed to attest, and the mode. */
20
+ settings: AttestationEnvironment;
21
+ /** Auth's database, for a verifier that keeps state of its own, such as App Attest's registered keys. */
22
+ db: AuthDatabase;
23
+ /**
24
+ * The Worker's bindings, for a verifier that needs a credential: it reads its secret from auth's registry with
25
+ * `sharedSecretsStore(env, authSecretsRegistry)`, as Turnstile reads its own, and answers a missing or unusable
26
+ * one with `auth/attestation_config`.
27
+ */
28
+ env: Readonly<Record<string, unknown>>;
29
+ /** The instant the request is judged at. */
30
+ now: Date;
31
+ }
32
+ /** A verifier's answer. `reason` says why, for the refusal's `detail`; it never reaches the client. */
33
+ export type AttestationVerdict = {
34
+ ok: true;
35
+ } | {
36
+ ok: false;
37
+ reason: string;
38
+ };
39
+ /**
40
+ * One platform's verification. A verdict about the attestation is answered; a fault in the server's own setup is
41
+ * thrown as `auth/attestation_config`. Runs on WebCrypto alone.
42
+ */
43
+ export interface AttestationVerifier {
44
+ verify(verification: AttestationVerification): Promise<AttestationVerdict>;
45
+ }
46
+ /** The verifier for each platform. A platform with none answers `auth/attestation_config` for a real assertion. */
47
+ export type AttestationVerifiers = Partial<Record<AttestationPlatform, AttestationVerifier>>;
48
+ /** The verifiers this release ships for real assertions. */
49
+ export declare const PLATFORM_VERIFIERS: AttestationVerifiers;
50
+ /** Whether this attestation is the documented test assertion. */
51
+ export declare function isTestAssertion(presented: PresentedAttestation): boolean;
52
+ /**
53
+ * Accepts {@link ATTESTATION_TEST_ASSERTION} from either platform, only where the environment is set to `test` and
54
+ * the Worker's own stamp is one of {@link import("./config").TEST_ASSERTION_ENVIRONMENTS}, so no config can open
55
+ * it anywhere else.
56
+ */
57
+ export declare const testVerifier: AttestationVerifier;
58
+ /** The verifier an attestation goes to: the test verifier for the test assertion, otherwise its platform's. */
59
+ export declare function verifierFor(presented: PresentedAttestation, verifiers: AttestationVerifiers): AttestationVerifier | undefined;
60
+ //# sourceMappingURL=verifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifier.d.ts","sourceRoot":"","sources":["../../src/attestation/verifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,KAAK,sBAAsB,EAAE,KAAK,mBAAmB,EAA0B,MAAM,UAAU,CAAC;AAEzG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,0BAA0B,2BAA2B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ifier: MIT
3
+ import { testAssertionAllowedIn } from "./config.js";
4
+ import { appAttestVerifier } from "./appAttest/verifier.js";
5
+ import { playIntegrityVerifier } from "./playIntegrity/verifier.js";
6
+ //#region src/attestation/verifier.ts
7
+ /**
8
+ * The documented test assertion. In dev, staging or a feature deployment set to `test`, the gate accepts it from
9
+ * either platform in place of a real one, so simulators, emulators and CI get through.
10
+ */
11
+ const ATTESTATION_TEST_ASSERTION = "pithy-test-attestation";
12
+ /** The verifiers this release ships for real assertions. */
13
+ const PLATFORM_VERIFIERS = {
14
+ ios: appAttestVerifier,
15
+ android: playIntegrityVerifier
16
+ };
17
+ /** Whether this attestation is the documented test assertion. */
18
+ function isTestAssertion(presented) {
19
+ return presented.assertion === ATTESTATION_TEST_ASSERTION;
20
+ }
21
+ /**
22
+ * Accepts {@link ATTESTATION_TEST_ASSERTION} from either platform, only where the environment is set to `test` and
23
+ * the Worker's own stamp is one of {@link import("./config").TEST_ASSERTION_ENVIRONMENTS}, so no config can open
24
+ * it anywhere else.
25
+ */
26
+ const testVerifier = { async verify({ presented, environment, settings }) {
27
+ if (!isTestAssertion(presented)) return {
28
+ ok: false,
29
+ reason: "not the test assertion"
30
+ };
31
+ if (!testAssertionAllowedIn(environment)) return {
32
+ ok: false,
33
+ reason: `the test assertion is refused where ENVIRONMENT is ${environment ?? "unstamped"}, whatever the config says: only dev, staging or feature accept it`
34
+ };
35
+ if (settings.mode !== "test") return {
36
+ ok: false,
37
+ reason: `the test assertion is refused in ${environment}, which is set to enforce`
38
+ };
39
+ return { ok: true };
40
+ } };
41
+ /** The verifier an attestation goes to: the test verifier for the test assertion, otherwise its platform's. */
42
+ function verifierFor(presented, verifiers) {
43
+ return isTestAssertion(presented) ? testVerifier : verifiers[presented.platform];
44
+ }
45
+ //#endregion
46
+ export { ATTESTATION_TEST_ASSERTION, PLATFORM_VERIFIERS, isTestAssertion, testVerifier, verifierFor };
@@ -0,0 +1,42 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ /**
5
+ * The one header a native app's attestation travels in, on a send route.
6
+ *
7
+ * A header rather than body fields: the send routes' bodies are Better Auth's, forwarded untouched, and the
8
+ * attestation signs over those exact bytes ({@link requestBinding}), so it cannot sit inside them.
9
+ */
10
+ export declare const ATTESTATION_HEADER = "x-pithy-attestation";
11
+ /** The longest header value read. A Play Integrity token or an App Attest assertion fits well inside. */
12
+ export declare const MAX_ATTESTATION_HEADER = 16384;
13
+ /** What a client sends in {@link ATTESTATION_HEADER}, before its base64url encoding. */
14
+ export declare const PresentedAttestation: z.ZodObject<{
15
+ platform: z.ZodEnum<{
16
+ android: "android";
17
+ ios: "ios";
18
+ }>;
19
+ challenge: z.ZodString;
20
+ assertion: z.ZodString;
21
+ keyId: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strip>;
23
+ export type PresentedAttestation = z.output<typeof PresentedAttestation>;
24
+ /** A decoded header, or why it could not be read. */
25
+ export type DecodedAttestation = {
26
+ ok: true;
27
+ value: PresentedAttestation;
28
+ } | {
29
+ ok: false;
30
+ reason: string;
31
+ };
32
+ /** Encode an attestation for {@link ATTESTATION_HEADER}: unpadded base64url over its JSON. */
33
+ export declare function encodeAttestation(presented: PresentedAttestation): string;
34
+ /** Read {@link ATTESTATION_HEADER}'s value. Never throws: a header that does not read is the caller's refusal. */
35
+ export declare function decodeAttestation(header: string): DecodedAttestation;
36
+ /**
37
+ * The bytes a platform's assertion must be made over: SHA-256 of the challenge's UTF-8 and then the request body,
38
+ * byte for byte. App Attest takes it as `clientDataHash`; Play Integrity takes its base64url as `requestHash`. It
39
+ * binds one attestation to one challenge and one body, so it cannot be lifted onto another address.
40
+ */
41
+ export declare function requestBinding(challenge: string, body: Uint8Array): Promise<Uint8Array>;
42
+ //# sourceMappingURL=wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../src/attestation/wire.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AAExD,yGAAyG;AACzG,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAE7C,wFAAwF;AACxF,eAAO,MAAM,oBAAoB;;;;;;;;iBAkB9B,CAAC;AACJ,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEzE,qDAAqD;AACrD,MAAM,MAAM,kBAAkB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,oBAAoB,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3G,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,CAEzE;AAED,kHAAkH;AAClH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAgBpE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAM7F"}
@@ -0,0 +1,72 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { AttestationPlatform } from "./config.js";
4
+ import { z } from "zod";
5
+ import { base64UrlDecode, base64UrlEncode } from "@pithy-sh/core/src/controlPlane/token/base64url";
6
+ //#region src/attestation/wire.ts
7
+ /**
8
+ * The one header a native app's attestation travels in, on a send route.
9
+ *
10
+ * A header rather than body fields: the send routes' bodies are Better Auth's, forwarded untouched, and the
11
+ * attestation signs over those exact bytes ({@link requestBinding}), so it cannot sit inside them.
12
+ */
13
+ const ATTESTATION_HEADER = "x-pithy-attestation";
14
+ /** The longest header value read. A Play Integrity token or an App Attest assertion fits well inside. */
15
+ const MAX_ATTESTATION_HEADER = 16384;
16
+ /** What a client sends in {@link ATTESTATION_HEADER}, before its base64url encoding. */
17
+ const PresentedAttestation = z.object({
18
+ platform: AttestationPlatform,
19
+ challenge: z.string().min(1).max(128).describe("The challenge the challenge route issued. Single use: presenting it spends it, pass or fail."),
20
+ assertion: z.string().min(1).describe("What the platform produced over the request binding: an App Attest assertion from a key already registered at `POST /auth/attestation/ios/keys` on iOS, a Play Integrity token on Android, base64 as the platform hands it over. Never the App Attest attestation object, which goes only to that registration route. Or the documented test assertion, in a `test` environment."),
21
+ keyId: z.string().min(1).max(256).optional().describe("The App Attest key identifier on iOS. Android has none.")
22
+ }).describe("A native app attestation as a send route reads it: the platform, the challenge it answers, and the platform's assertion over the request.");
23
+ /** Encode an attestation for {@link ATTESTATION_HEADER}: unpadded base64url over its JSON. */
24
+ function encodeAttestation(presented) {
25
+ return base64UrlEncode(new TextEncoder().encode(JSON.stringify(presented)));
26
+ }
27
+ /** Read {@link ATTESTATION_HEADER}'s value. Never throws: a header that does not read is the caller's refusal. */
28
+ function decodeAttestation(header) {
29
+ if (header.length === 0) return {
30
+ ok: false,
31
+ reason: "the attestation header is empty"
32
+ };
33
+ if (header.length > 16384) return {
34
+ ok: false,
35
+ reason: `the attestation header is over ${MAX_ATTESTATION_HEADER} characters`
36
+ };
37
+ let json;
38
+ try {
39
+ json = JSON.parse(new TextDecoder("utf-8", {
40
+ fatal: true,
41
+ ignoreBOM: false
42
+ }).decode(base64UrlDecode(header)));
43
+ } catch {
44
+ return {
45
+ ok: false,
46
+ reason: "the attestation header is not base64url-encoded JSON"
47
+ };
48
+ }
49
+ const parsed = PresentedAttestation.safeParse(json);
50
+ if (!parsed.success) return {
51
+ ok: false,
52
+ reason: `the attestation header has the wrong shape: ${parsed.error.issues[0]?.message}`
53
+ };
54
+ return {
55
+ ok: true,
56
+ value: parsed.data
57
+ };
58
+ }
59
+ /**
60
+ * The bytes a platform's assertion must be made over: SHA-256 of the challenge's UTF-8 and then the request body,
61
+ * byte for byte. App Attest takes it as `clientDataHash`; Play Integrity takes its base64url as `requestHash`. It
62
+ * binds one attestation to one challenge and one body, so it cannot be lifted onto another address.
63
+ */
64
+ async function requestBinding(challenge, body) {
65
+ const prefix = new TextEncoder().encode(challenge);
66
+ const message = new Uint8Array(prefix.length + body.length);
67
+ message.set(prefix, 0);
68
+ message.set(body, prefix.length);
69
+ return new Uint8Array(await crypto.subtle.digest("SHA-256", message));
70
+ }
71
+ //#endregion
72
+ export { ATTESTATION_HEADER, MAX_ATTESTATION_HEADER, PresentedAttestation, decodeAttestation, encodeAttestation, requestBinding };
@@ -9,6 +9,10 @@ import { type TurnstileCapability } from "@pithy-sh/turnstile/src/capability";
9
9
  import { type TurnstileMode, type TurnstileTokenSource } from "@pithy-sh/turnstile/src/config/config";
10
10
  import type { Context } from "hono";
11
11
  import { z } from "zod";
12
+ import { AttestationConfig } from "./attestation/config";
13
+ import { type AttestationVerifiers } from "./attestation/verifier";
14
+ import type { AuthClientProjection } from "./client/projection";
15
+ import type { HookRuntime } from "./hooks/runtime";
12
16
  import type { GithubUserInfoResolver } from "./instance/githubUserInfo";
13
17
  import type { UserLifecycleHooks } from "./lifecycle/hooks";
14
18
  import type { McpHost, McpWiring } from "./mcp/host";
@@ -56,6 +60,22 @@ export declare const AuthConfig: z.ZodObject<{
56
60
  deletionScheduled: z.ZodDefault<z.ZodBoolean>;
57
61
  deletionComplete: z.ZodDefault<z.ZodBoolean>;
58
62
  }, z.core.$strip>>;
63
+ attestation: z.ZodPrefault<z.ZodObject<{
64
+ challengeExpiresIn: z.ZodDefault<z.ZodNumber>;
65
+ environments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
66
+ mode: z.ZodDefault<z.ZodEnum<{
67
+ enforce: "enforce";
68
+ test: "test";
69
+ }>>;
70
+ ios: z.ZodDefault<z.ZodArray<z.ZodObject<{
71
+ teamId: z.ZodString;
72
+ bundleId: z.ZodString;
73
+ }, z.core.$strip>>>;
74
+ android: z.ZodDefault<z.ZodArray<z.ZodObject<{
75
+ packageName: z.ZodString;
76
+ }, z.core.$strip>>>;
77
+ }, z.core.$strip>>>;
78
+ }, z.core.$strip>>;
59
79
  plugins: z.ZodDefault<z.ZodArray<z.ZodCustom<import("better-auth").BetterAuthPlugin, import("better-auth").BetterAuthPlugin>>>;
60
80
  }, z.core.$strip>;
61
81
  export type AuthConfig = z.output<typeof AuthConfig>;
@@ -81,6 +101,16 @@ export interface AuthWiring {
81
101
  enqueueEmail: EmailCapability["enqueue"] | undefined;
82
102
  /** The turnstile login gate, when the turnstile capability is composed. Set by `compose`. */
83
103
  turnstile: TurnstileLoginGate | undefined;
104
+ /**
105
+ * The verifier for each platform's real attestations. Absent means the ones this release ships,
106
+ * `PLATFORM_VERIFIERS`; a harness passes its own.
107
+ */
108
+ attestationVerifiers?: AttestationVerifiers | undefined;
109
+ /**
110
+ * The root CA an App Attest key's certificate chain must lead to, DER. Absent means Apple App Attestation Root
111
+ * CA, pinned in the package; a harness passes the root of its own test chain.
112
+ */
113
+ appAttestRoot?: Uint8Array | undefined;
84
114
  /**
85
115
  * The adopter's session-revoked listener, or absent. See {@link AuthOptions.onSessionRevoked}.
86
116
  *
@@ -139,12 +169,14 @@ export type ScopeResolver = (c: Context<PithyHonoEnv>, session: ScopeResolverSes
139
169
  * **Handed this request's D1 binding**, because the auth instance is built per request and the listener
140
170
  * almost certainly wants to write to the same database under a different capability's view of it. Taking
141
171
  * the binding rather than a typed database keeps this seam out of the business of knowing whose tables
142
- * the listener is about to touch.
172
+ * the listener is about to touch. **And handed the request's runtime**: its env, typed as `auth<Env>()` names
173
+ * it, and its `waitUntil`, so the listener can reach another binding or keep work running past the response.
174
+ * A listener that takes only `(session, d1)` is still one.
143
175
  */
144
- export type SessionRevokedListener = (session: {
176
+ export type SessionRevokedListener<Env = Record<string, unknown>> = (session: {
145
177
  id: string;
146
178
  userId: string;
147
- }, d1: D1Database) => Promise<void>;
179
+ }, d1: D1Database, runtime: HookRuntime<Env>) => Promise<void>;
148
180
  /**
149
181
  * What `auth()` takes: the config, plus the seams that are **behavior rather than data**.
150
182
  *
@@ -153,7 +185,7 @@ export type SessionRevokedListener = (session: {
153
185
  * `PaymentsOptions`: everything describable stays in {@link AuthConfig}, and a resolver is a sibling key
154
186
  * destructured off before the parse.
155
187
  */
156
- export type AuthOptions = AuthConfigInput & UserLifecycleHooks & {
188
+ export type AuthOptions<Env = Record<string, unknown>> = AuthConfigInput & UserLifecycleHooks<Env> & {
157
189
  /**
158
190
  * Resolve a GitHub identity yourself, replacing the kit's primary-only rule.
159
191
  *
@@ -184,7 +216,7 @@ export type AuthOptions = AuthConfigInput & UserLifecycleHooks & {
184
216
  *
185
217
  * A function, so it is destructured off before `AuthConfig.parse` for the reason above.
186
218
  */
187
- onSessionRevoked?: SessionRevokedListener;
219
+ onSessionRevoked?: SessionRevokedListener<Env>;
188
220
  /**
189
221
  * Decide, per request, what this request's caller is — and so which scope gates it opens.
190
222
  *
@@ -232,13 +264,24 @@ export interface AuthCapability extends Capability {
232
264
  /** What the MCP capability composed beside this one reads. See `mcp/host.ts`. */
233
265
  mcpHost: McpHost;
234
266
  }
267
+ /**
268
+ * The attestation half of the client projection for one environment: its mode as the Worker will apply it, and
269
+ * which platforms can pass by attesting, or nothing where the environment has no block. A Worker accepts the test
270
+ * assertion only in the environments {@link testAssertionAllowedIn} names, so a `test` block anywhere else projects
271
+ * as `enforce`. Under `enforce` a platform passes only with an allowed app and a verifier in `verifiers`: without
272
+ * the app its assertion is refused, and without the verifier it is answered `auth/attestation_config`, so it
273
+ * projects `false` and its phones keep Turnstile. The test assertion passes from either platform.
274
+ */
275
+ export declare function attestationProjection(config: AttestationConfig, environment: string, verifiers: AttestationVerifiers): Pick<Extract<AuthClientProjection, {
276
+ enabled: true;
277
+ }>, "attestation">;
235
278
  /**
236
279
  * The auth capability. Passwordless sign-in (magic link, OTP, Google, Apple), the hybrid bearer +
237
280
  * cookie token model, the per-device session registry, and the `bearer`/`session` fills for core's
238
281
  * `AuthContext` seam. Depends on `secrets` and `email`; auto-gates its send routes with `turnstile`
239
282
  * and emits `auth/*` through `audit` when those are composed.
240
283
  */
241
- export declare function auth(options: AuthOptions): AuthCapability;
284
+ export declare function auth<Env = Record<string, unknown>>(options: AuthOptions<Env>): AuthCapability;
242
285
  /** Type guard: is this capability the auth capability? */
243
286
  export declare function isAuthCapability(capability: Capability): capability is AuthCapability;
244
287
  //# sourceMappingURL=capability.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAmB,MAAM,0CAA0C,CAAC;AAE1G,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,qCAAqC,CAAC;AAEjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACrG,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC1B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAYxB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAIxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKrD,OAAO,EAAE,KAAK,QAAQ,EAAY,MAAM,QAAQ,CAAC;AAiCjD,mGAAmG;AACnG,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;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