{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/jkt-binding.ts","../src/base64url.ts","../src/jwk.ts","../src/middleware.ts","../src/compat.ts","../src/verify.ts","../src/stores/memory-nonce-provider.ts"],"sourcesContent":["export type { DPoPErrorCode, ProblemDetail, ProblemResponseExtras } from \"./errors.js\";\nexport {\n\tclampHttpStatus,\n\tDPoPErrors,\n\tDPoPProofError,\n\tproblemResponse,\n\twwwAuthenticateHeader,\n} from \"./errors.js\";\nexport type { AccessTokenClaimsWithCnf } from \"./jkt-binding.js\";\nexport { assertJktBinding, verifyJktBinding } from \"./jkt-binding.js\";\nexport type {\n\tEcPublicJwk,\n\tJwsAlgorithm,\n\tOkpPublicJwk,\n\tPublicJwk,\n\tRsaPublicJwk,\n} from \"./jwk.js\";\nexport {\n\tassertPublicJwk,\n\tjwkThumbprint,\n\tSUPPORTED_ALGORITHMS,\n} from \"./jwk.js\";\nexport { dpop } from \"./middleware.js\";\nexport type {\n\tD1DatabaseLike,\n\tD1PreparedStatementLike,\n\tD1StoreOptions,\n} from \"./stores/cloudflare-d1.js\";\nexport type { KVNamespaceLike, KVStoreOptions } from \"./stores/cloudflare-kv.js\";\nexport type {\n\tDurableObjectStorageLike,\n\tDurableObjectStoreOptions,\n} from \"./stores/durable-objects.js\";\nexport type { MemoryNonceStore, MemoryNonceStoreOptions } from \"./stores/memory.js\";\nexport type { MemoryNonceProviderOptions } from \"./stores/memory-nonce-provider.js\";\nexport { memoryNonceProvider } from \"./stores/memory-nonce-provider.js\";\nexport type { RedisClientLike, RedisStoreOptions } from \"./stores/redis.js\";\nexport type { DPoPNonceStore, NonceProvider } from \"./stores/types.js\";\nexport type { DPoPEnv, DPoPOptions, DPoPVerifiedProof } from \"./types.js\";\n","export type DPoPErrorCode =\n\t| \"INVALID_DPOP_PROOF\"\n\t| \"MISSING_ACCESS_TOKEN\"\n\t| \"ATH_MISMATCH\"\n\t| \"JTI_REPLAY\"\n\t| \"USE_NONCE\";\n\nexport interface ProblemDetail {\n\ttype: string;\n\ttitle: string;\n\tstatus: number;\n\tdetail: string;\n\tcode: DPoPErrorCode;\n\t/** Value for the `error` parameter of the WWW-Authenticate: DPoP header (RFC 9449 §7.1). */\n\twwwAuthError: string;\n\t/** Extra parameters merged into the WWW-Authenticate header (e.g., `nonce`, `algs`). */\n\twwwAuthExtras?: Record<string, string>;\n\t/** Extra response headers to set on the error response (e.g., `DPoP-Nonce`). */\n\tadditionalHeaders?: Record<string, string>;\n}\n\n/** Clamp HTTP status to 200-599 integer range; returns 500 for out-of-range or non-integer values. */\nexport function clampHttpStatus(status: number): number {\n\treturn Number.isInteger(status) && status >= 200 && status <= 599 ? status : 500;\n}\n\nconst PROBLEM_CONTENT_TYPE = \"application/problem+json; charset=utf-8\";\nconst BASE_URL = \"https://hono-dpop.dev/errors\";\n\n// RFC 7230 §3.2.6 quoted-string: quoted-pair = \"\\\" ( HTAB / SP / VCHAR / obs-text ).\n// Both backslash and double-quote must be backslash-escaped. Order matters —\n// escape backslashes BEFORE introducing new ones via the quote escape.\nfunction quoteString(v: string): string {\n\treturn v.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\n/** Build an `WWW-Authenticate: DPoP error=\"...\", key=\"value\", ...` header value. */\nexport function wwwAuthenticateHeader(\n\twwwAuthError: string,\n\textras?: Record<string, string>,\n): string {\n\tconst params: string[] = [`error=\"${quoteString(wwwAuthError)}\"`];\n\tif (extras) {\n\t\tfor (const [k, v] of Object.entries(extras)) {\n\t\t\tparams.push(`${k}=\"${quoteString(v)}\"`);\n\t\t}\n\t}\n\treturn `DPoP ${params.join(\", \")}`;\n}\n\nexport interface ProblemResponseExtras {\n\twwwAuthExtras?: Record<string, string>;\n\textraHeaders?: Record<string, string>;\n}\n\nexport function problemResponse(problem: ProblemDetail, extras?: ProblemResponseExtras): Response {\n\tlet body: string;\n\tlet status: number;\n\ttry {\n\t\tbody = JSON.stringify(problem);\n\t\tstatus = clampHttpStatus(problem.status);\n\t} catch {\n\t\tbody = '{\"title\":\"Internal Server Error\",\"status\":500}';\n\t\tstatus = 500;\n\t}\n\tconst mergedAuthExtras = { ...problem.wwwAuthExtras, ...extras?.wwwAuthExtras };\n\tconst headers: Record<string, string> = {\n\t\t\"Content-Type\": PROBLEM_CONTENT_TYPE,\n\t\t\"WWW-Authenticate\": wwwAuthenticateHeader(\n\t\t\tproblem.wwwAuthError,\n\t\t\tObject.keys(mergedAuthExtras).length > 0 ? mergedAuthExtras : undefined,\n\t\t),\n\t\t...problem.additionalHeaders,\n\t\t...extras?.extraHeaders,\n\t};\n\treturn new Response(body, { status, headers });\n}\n\n/** Thrown by verification helpers; carries the ProblemDetail that should be sent to the client. */\nexport class DPoPProofError extends Error {\n\treadonly problem: ProblemDetail;\n\n\tconstructor(problem: ProblemDetail) {\n\t\t// Use detail (specific) rather than title (generic) so error.message is\n\t\t// informative for logs and `toThrow(/specific/)` matches in tests.\n\t\tsuper(problem.detail);\n\t\tthis.name = \"DPoPProofError\";\n\t\tthis.problem = problem;\n\t}\n}\n\n/** Strip control characters (CR, LF, ESC, NUL, C1 range) and cap length.\n *  `invalidProof` detail is built from attacker-controlled proof claims (alg,\n *  typ, htm, htu) and is echoed in JSON response bodies AND often in operator\n *  logs verbatim. Sanitization prevents log/terminal injection (CRLF log\n *  forging, ANSI escape spoofing). */\nfunction sanitizeDetail(detail: string): string {\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: deliberate stripping of control chars.\n\tconst cleaned = detail.replace(/[\\x00-\\x1F\\x7F-\\x9F]/g, \"\");\n\tconst MAX_DETAIL_LEN = 256;\n\treturn cleaned.length > MAX_DETAIL_LEN ? `${cleaned.slice(0, MAX_DETAIL_LEN)}…` : cleaned;\n}\n\nexport const DPoPErrors = {\n\tinvalidProof(detail: string): ProblemDetail {\n\t\treturn {\n\t\t\ttype: `${BASE_URL}/invalid-dpop-proof`,\n\t\t\ttitle: \"Invalid DPoP proof\",\n\t\t\tstatus: 401,\n\t\t\tdetail: sanitizeDetail(detail),\n\t\t\tcode: \"INVALID_DPOP_PROOF\",\n\t\t\twwwAuthError: \"invalid_dpop_proof\",\n\t\t};\n\t},\n\tmissingAccessToken(): ProblemDetail {\n\t\treturn {\n\t\t\ttype: `${BASE_URL}/missing-access-token`,\n\t\t\ttitle: \"Access token is required\",\n\t\t\tstatus: 401,\n\t\t\tdetail: \"Authorization: DPoP <token> header is required\",\n\t\t\tcode: \"MISSING_ACCESS_TOKEN\",\n\t\t\twwwAuthError: \"invalid_token\",\n\t\t};\n\t},\n\tathMismatch(): ProblemDetail {\n\t\treturn {\n\t\t\ttype: `${BASE_URL}/ath-mismatch`,\n\t\t\ttitle: \"Access token hash mismatch\",\n\t\t\tstatus: 401,\n\t\t\tdetail: \"The DPoP proof's ath claim does not match the access token\",\n\t\t\tcode: \"ATH_MISMATCH\",\n\t\t\twwwAuthError: \"invalid_token\",\n\t\t};\n\t},\n\tjtiReplay(): ProblemDetail {\n\t\treturn {\n\t\t\ttype: `${BASE_URL}/jti-replay`,\n\t\t\ttitle: \"DPoP proof replayed\",\n\t\t\tstatus: 401,\n\t\t\tdetail: \"The jti has been used within the replay window\",\n\t\t\tcode: \"JTI_REPLAY\",\n\t\t\twwwAuthError: \"invalid_dpop_proof\",\n\t\t};\n\t},\n\tuseNonce(freshNonce: string): ProblemDetail {\n\t\treturn {\n\t\t\ttype: `${BASE_URL}/use-nonce`,\n\t\t\ttitle: \"DPoP nonce required\",\n\t\t\tstatus: 401,\n\t\t\tdetail: \"Resource server requires a server-issued nonce in the DPoP proof\",\n\t\t\tcode: \"USE_NONCE\",\n\t\t\twwwAuthError: \"use_dpop_nonce\",\n\t\t\twwwAuthExtras: { nonce: freshNonce },\n\t\t\tadditionalHeaders: { \"DPoP-Nonce\": freshNonce },\n\t\t};\n\t},\n} as const;\n","import { DPoPErrors, DPoPProofError } from \"./errors.js\";\n\nexport interface AccessTokenClaimsWithCnf {\n\tcnf?: { jkt?: string };\n}\n\n/**\n * Returns true when the access token's `cnf.jkt` claim equals the proof\n * thumbprint exposed on `c.get(\"dpop\").jkt`. Returns false on missing or\n * mismatched binding.\n *\n * Use this for explicit branching in route handlers. For the throwing\n * variant that integrates with the standard 401 + WWW-Authenticate\n * pipeline, see `assertJktBinding`.\n */\nexport function verifyJktBinding(\n\taccessTokenClaims: AccessTokenClaimsWithCnf,\n\tproofThumbprint: string,\n): boolean {\n\tconst bound = accessTokenClaims.cnf?.jkt;\n\treturn typeof bound === \"string\" && bound === proofThumbprint;\n}\n\n/**\n * Throws `DPoPProofError` (formatted as 401 + `WWW-Authenticate: DPoP error=\"invalid_dpop_proof\"`)\n * when the access token's `cnf.jkt` does not match the proof thumbprint, or when\n * `cnf.jkt` is missing entirely.\n *\n * Typical usage inside a route handler:\n * ```ts\n * const proof = c.get(\"dpop\")!;\n * const claims = await verifyMyJwt(token);\n * assertJktBinding(claims, proof.jkt);\n * ```\n */\nexport function assertJktBinding(\n\taccessTokenClaims: AccessTokenClaimsWithCnf,\n\tproofThumbprint: string,\n): void {\n\tif (!verifyJktBinding(accessTokenClaims, proofThumbprint)) {\n\t\tthrow new DPoPProofError(\n\t\t\tDPoPErrors.invalidProof(\"access token cnf.jkt does not match DPoP proof thumbprint\"),\n\t\t);\n\t}\n}\n","const encoder = new TextEncoder();\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\nconst BASE64URL_RE = /^[A-Za-z0-9_-]*$/;\n\nexport function base64urlEncode(input: Uint8Array | string): string {\n\tconst bytes = typeof input === \"string\" ? encoder.encode(input) : input;\n\tlet binary = \"\";\n\tfor (let i = 0; i < bytes.length; i++) {\n\t\tbinary += String.fromCharCode(bytes[i]);\n\t}\n\treturn btoa(binary).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\nexport function base64urlDecode(input: string): Uint8Array<ArrayBuffer> {\n\tif (!BASE64URL_RE.test(input)) {\n\t\tthrow new TypeError(\"invalid base64url\");\n\t}\n\tconst padLen = (4 - (input.length % 4)) % 4;\n\tconst padded = input.replace(/-/g, \"+\").replace(/_/g, \"/\") + \"=\".repeat(padLen);\n\tconst binary = atob(padded);\n\tconst bytes = new Uint8Array(binary.length);\n\tfor (let i = 0; i < binary.length; i++) {\n\t\tbytes[i] = binary.charCodeAt(i);\n\t}\n\treturn bytes;\n}\n\nexport function base64urlDecodeToString(input: string): string {\n\treturn decoder.decode(base64urlDecode(input));\n}\n","import { base64urlDecode, base64urlEncode } from \"./base64url.js\";\n\nexport type JwsAlgorithm =\n\t| \"ES256\"\n\t| \"ES384\"\n\t| \"ES512\"\n\t| \"RS256\"\n\t| \"RS384\"\n\t| \"RS512\"\n\t| \"PS256\"\n\t| \"PS384\"\n\t| \"PS512\"\n\t| \"EdDSA\"\n\t| \"Ed25519\";\n\nexport const SUPPORTED_ALGORITHMS = [\n\t\"ES256\",\n\t\"ES384\",\n\t\"ES512\",\n\t\"RS256\",\n\t\"RS384\",\n\t\"RS512\",\n\t\"PS256\",\n\t\"PS384\",\n\t\"PS512\",\n\t// `EdDSA` is the RFC 8037 / RFC 9449 identifier. `Ed25519` is the more\n\t// specific identifier introduced by RFC 9758 (\"Fully-Specified Algorithms\n\t// for JOSE and COSE\", 2025) — same crypto, different alg string. Verifiers\n\t// should accept both for forward compatibility.\n\t\"EdDSA\",\n\t\"Ed25519\",\n] as const satisfies readonly JwsAlgorithm[];\n\nexport interface EcPublicJwk {\n\tkty: \"EC\";\n\tcrv: \"P-256\" | \"P-384\" | \"P-521\";\n\tx: string;\n\ty: string;\n\t[k: string]: unknown;\n}\n\nexport interface RsaPublicJwk {\n\tkty: \"RSA\";\n\tn: string;\n\te: string;\n\t[k: string]: unknown;\n}\n\nexport interface OkpPublicJwk {\n\tkty: \"OKP\";\n\tcrv: \"Ed25519\";\n\tx: string;\n\t[k: string]: unknown;\n}\n\nexport type PublicJwk = EcPublicJwk | RsaPublicJwk | OkpPublicJwk;\n\n// JWK private fields per RFC 7517/7518 — proof MUST carry only the public key.\nconst PRIVATE_FIELDS = [\"d\", \"p\", \"q\", \"dp\", \"dq\", \"qi\", \"oth\", \"k\"] as const;\n\nexport function assertPublicJwk(jwk: unknown): asserts jwk is PublicJwk {\n\tif (!jwk || typeof jwk !== \"object\") {\n\t\tthrow new TypeError(\"jwk must be an object\");\n\t}\n\tconst j = jwk as Record<string, unknown>;\n\t// Use own-property check so a polluted Object.prototype cannot cause\n\t// false rejection of an otherwise valid public jwk.\n\tfor (const f of PRIVATE_FIELDS) {\n\t\tif (Object.hasOwn(j, f)) {\n\t\t\tthrow new TypeError(`jwk must not contain private field \"${f}\"`);\n\t\t}\n\t}\n\tswitch (j.kty) {\n\t\tcase \"EC\":\n\t\t\tif (typeof j.crv !== \"string\" || ![\"P-256\", \"P-384\", \"P-521\"].includes(j.crv)) {\n\t\t\t\tthrow new TypeError(\"EC jwk has unsupported crv\");\n\t\t\t}\n\t\t\tif (typeof j.x !== \"string\" || typeof j.y !== \"string\") {\n\t\t\t\tthrow new TypeError(\"EC jwk requires x and y\");\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"RSA\": {\n\t\t\tif (typeof j.n !== \"string\" || typeof j.e !== \"string\") {\n\t\t\t\tthrow new TypeError(\"RSA jwk requires n and e\");\n\t\t\t}\n\t\t\tlet nBytes: Uint8Array;\n\t\t\ttry {\n\t\t\t\tnBytes = base64urlDecode(j.n);\n\t\t\t} catch {\n\t\t\t\tthrow new TypeError(\"RSA jwk has malformed n (not valid base64url)\");\n\t\t\t}\n\t\t\t// RSA modulus length policy:\n\t\t\t//   < 256 bytes (2048 bits): cryptographically weak — reject.\n\t\t\t//   > 512 bytes (4096 bits): excessive — DoS amplification via slow verify.\n\t\t\tif (nBytes.length < 256) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`RSA jwk modulus must be at least 2048 bits; got ${nBytes.length * 8} bits`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (nBytes.length > 512) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`RSA jwk modulus must not exceed 4096 bits; got ${nBytes.length * 8} bits`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tcase \"OKP\":\n\t\t\tif (j.crv !== \"Ed25519\") {\n\t\t\t\tthrow new TypeError(\"OKP jwk only supports Ed25519\");\n\t\t\t}\n\t\t\tif (typeof j.x !== \"string\") {\n\t\t\t\tthrow new TypeError(\"OKP jwk requires x\");\n\t\t\t}\n\t\t\treturn;\n\t\tdefault:\n\t\t\tthrow new TypeError(`unsupported kty: ${String(j.kty)}`);\n\t}\n}\n\nconst encoder = new TextEncoder();\n\n/**\n * RFC 7638 JWK Thumbprint: canonical JSON of required members in lex order,\n * SHA-256, base64url (no padding).\n */\nexport async function jwkThumbprint(jwk: PublicJwk): Promise<string> {\n\tlet canonical: string;\n\tswitch (jwk.kty) {\n\t\tcase \"EC\":\n\t\t\tcanonical = JSON.stringify({ crv: jwk.crv, kty: \"EC\", x: jwk.x, y: jwk.y });\n\t\t\tbreak;\n\t\tcase \"RSA\":\n\t\t\tcanonical = JSON.stringify({ e: jwk.e, kty: \"RSA\", n: jwk.n });\n\t\t\tbreak;\n\t\tcase \"OKP\":\n\t\t\tcanonical = JSON.stringify({ crv: jwk.crv, kty: \"OKP\", x: jwk.x });\n\t\t\tbreak;\n\t}\n\tconst digest = await crypto.subtle.digest(\"SHA-256\", encoder.encode(canonical));\n\treturn base64urlEncode(new Uint8Array(digest));\n}\n\ninterface AlgorithmDescriptor {\n\timportParams: AlgorithmIdentifier | EcKeyImportParams | RsaHashedImportParams;\n\tverifyParams: AlgorithmIdentifier | EcdsaParams | RsaPssParams;\n}\n\nconst ALG: Record<JwsAlgorithm, AlgorithmDescriptor> = {\n\tES256: {\n\t\timportParams: { name: \"ECDSA\", namedCurve: \"P-256\" },\n\t\tverifyParams: { name: \"ECDSA\", hash: \"SHA-256\" },\n\t},\n\tES384: {\n\t\timportParams: { name: \"ECDSA\", namedCurve: \"P-384\" },\n\t\tverifyParams: { name: \"ECDSA\", hash: \"SHA-384\" },\n\t},\n\tES512: {\n\t\timportParams: { name: \"ECDSA\", namedCurve: \"P-521\" },\n\t\tverifyParams: { name: \"ECDSA\", hash: \"SHA-512\" },\n\t},\n\tRS256: {\n\t\timportParams: { name: \"RSASSA-PKCS1-v1_5\", hash: \"SHA-256\" },\n\t\tverifyParams: { name: \"RSASSA-PKCS1-v1_5\" },\n\t},\n\tRS384: {\n\t\timportParams: { name: \"RSASSA-PKCS1-v1_5\", hash: \"SHA-384\" },\n\t\tverifyParams: { name: \"RSASSA-PKCS1-v1_5\" },\n\t},\n\tRS512: {\n\t\timportParams: { name: \"RSASSA-PKCS1-v1_5\", hash: \"SHA-512\" },\n\t\tverifyParams: { name: \"RSASSA-PKCS1-v1_5\" },\n\t},\n\tPS256: {\n\t\timportParams: { name: \"RSA-PSS\", hash: \"SHA-256\" },\n\t\tverifyParams: { name: \"RSA-PSS\", saltLength: 32 },\n\t},\n\tPS384: {\n\t\timportParams: { name: \"RSA-PSS\", hash: \"SHA-384\" },\n\t\tverifyParams: { name: \"RSA-PSS\", saltLength: 48 },\n\t},\n\tPS512: {\n\t\timportParams: { name: \"RSA-PSS\", hash: \"SHA-512\" },\n\t\tverifyParams: { name: \"RSA-PSS\", saltLength: 64 },\n\t},\n\tEdDSA: {\n\t\timportParams: { name: \"Ed25519\" },\n\t\tverifyParams: { name: \"Ed25519\" },\n\t},\n\tEd25519: {\n\t\timportParams: { name: \"Ed25519\" },\n\t\tverifyParams: { name: \"Ed25519\" },\n\t},\n};\n\nexport function isSupportedAlgorithm(alg: string): alg is JwsAlgorithm {\n\treturn (SUPPORTED_ALGORITHMS as readonly string[]).includes(alg);\n}\n\n/**\n * Validates that a JWK's key type matches the declared `alg`. Catches the\n * \"alg confusion\" class of attack where a client claims ES256 but supplies an RSA jwk.\n */\nexport function assertAlgMatchesJwk(alg: JwsAlgorithm, jwk: PublicJwk): void {\n\tif (alg.startsWith(\"ES\")) {\n\t\tif (jwk.kty !== \"EC\") throw new TypeError(`alg ${alg} requires EC jwk`);\n\t\tconst expected = alg === \"ES256\" ? \"P-256\" : alg === \"ES384\" ? \"P-384\" : \"P-521\";\n\t\tif (jwk.crv !== expected) {\n\t\t\tthrow new TypeError(`alg ${alg} requires crv ${expected}`);\n\t\t}\n\t\treturn;\n\t}\n\tif (alg.startsWith(\"RS\") || alg.startsWith(\"PS\")) {\n\t\tif (jwk.kty !== \"RSA\") throw new TypeError(`alg ${alg} requires RSA jwk`);\n\t\treturn;\n\t}\n\t// EdDSA (RFC 8037) and Ed25519 (RFC 9758) — both use the same Ed25519 crypto.\n\tif (jwk.kty !== \"OKP\" || jwk.crv !== \"Ed25519\") {\n\t\tthrow new TypeError(`alg ${alg} requires OKP jwk with crv Ed25519`);\n\t}\n}\n\nexport async function importPublicJwk(jwk: PublicJwk, alg: JwsAlgorithm): Promise<CryptoKey> {\n\tconst desc = ALG[alg];\n\treturn crypto.subtle.importKey(\"jwk\", jwk as JsonWebKey, desc.importParams, false, [\"verify\"]);\n}\n\nexport function verifyParamsFor(\n\talg: JwsAlgorithm,\n): AlgorithmIdentifier | EcdsaParams | RsaPssParams {\n\treturn ALG[alg].verifyParams;\n}\n","import type { Context } from \"hono\";\nimport { createMiddleware } from \"hono/factory\";\nimport { getHonoProblemDetails } from \"./compat.js\";\nimport {\n\tDPoPErrors,\n\tDPoPProofError,\n\ttype ProblemDetail,\n\tproblemResponse,\n\twwwAuthenticateHeader,\n} from \"./errors.js\";\nimport {\n\tisSupportedAlgorithm,\n\ttype JwsAlgorithm,\n\tjwkThumbprint,\n\tSUPPORTED_ALGORITHMS,\n} from \"./jwk.js\";\nimport type { DPoPEnv, DPoPOptions, DPoPVerifiedProof } from \"./types.js\";\nimport {\n\tcomputeAth,\n\tnormalizeHtu,\n\ttype ParsedProof,\n\tparseProof,\n\ttimingSafeEqual,\n\tverifyProofClaims,\n\tverifyProofSignature,\n} from \"./verify.js\";\n\nconst DEFAULT_IAT_TOLERANCE = 60;\nconst DEFAULT_JTI_TTL_MS = 5 * 60_000;\nconst DEFAULT_MAX_PROOF_SIZE = 8192;\nconst DEFAULT_MAX_ACCESS_TOKEN_SIZE = 4096;\nconst DPOP_HEADER = \"DPoP\";\nconst DPOP_NONCE_HEADER = \"DPoP-Nonce\";\nconst AUTHORIZATION_HEADER = \"Authorization\";\n// RFC 7235 §2.1: scheme names are case-insensitive. We compare against the\n// lowercase form so `DPoP`, `dpop`, and `Dpop` all match.\nconst DPOP_AUTH_SCHEME = \"dpop\";\n\nconst sizingEncoder = new TextEncoder();\n\nexport function dpop(options: DPoPOptions) {\n\tconst {\n\t\tnonceStore,\n\t\talgorithms = SUPPORTED_ALGORITHMS,\n\t\tiatTolerance = DEFAULT_IAT_TOLERANCE,\n\t\tjtiTtl = DEFAULT_JTI_TTL_MS,\n\t\tgetRequestUrl,\n\t\tgetAccessToken,\n\t\trequireAccessToken = false,\n\t\tonError,\n\t\tnonceProvider,\n\t\tmaxProofSize = DEFAULT_MAX_PROOF_SIZE,\n\t\tmaxAccessTokenSize = DEFAULT_MAX_ACCESS_TOKEN_SIZE,\n\t\tclock = Date.now,\n\t\thtuComparison = \"strict\",\n\t\tallowFutureIat = false,\n\t} = options;\n\n\t// Fail fast on unsupported algs at factory time. Without this, a TypeScript\n\t// escape hatch (`[\"EvilAlg\" as any]`) would survive factory creation and\n\t// only surface at request time as \"unsupported alg\", which is harder to\n\t// catch in development and lets a misconfiguration ship to production.\n\tfor (const alg of algorithms) {\n\t\tif (!isSupportedAlgorithm(alg)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Unsupported algorithm in algorithms option: ${String(alg)}. ` +\n\t\t\t\t\t`Allowed: ${SUPPORTED_ALGORITHMS.join(\", \")}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst allowed = new Set<JwsAlgorithm>(algorithms);\n\tconst algsHint = algorithms.join(\" \");\n\n\treturn createMiddleware<DPoPEnv>(async (c, next) => {\n\t\tconst errorResponse = (problem: ProblemDetail) =>\n\t\t\trespondWithProblem(problem, c, onError, algsHint);\n\n\t\tconst proofHeader = c.req.header(DPOP_HEADER);\n\t\tif (!proofHeader) {\n\t\t\treturn errorResponse(DPoPErrors.invalidProof(\"DPoP header is missing\"));\n\t\t}\n\n\t\t// Size shield: bound the input before any decode/parse work.\n\t\tif (sizingEncoder.encode(proofHeader).length > maxProofSize) {\n\t\t\treturn errorResponse(DPoPErrors.invalidProof(`DPoP header exceeds ${maxProofSize} bytes`));\n\t\t}\n\n\t\t// RFC 9449 §4.3: exactly one DPoP header. The Headers API joins multiple\n\t\t// same-name headers with \", \"; DPoP proofs are base64url-only and never\n\t\t// contain commas, so a comma-space sequence is a positive signal of\n\t\t// header smuggling.\n\t\tif (proofHeader.includes(\", \")) {\n\t\t\treturn errorResponse(DPoPErrors.invalidProof(\"multiple DPoP headers are not allowed\"));\n\t\t}\n\n\t\t// Resolve and size-check the access token BEFORE expensive crypto work.\n\t\t// An attacker with their own valid keypair could otherwise force the\n\t\t// server to TextEncoder.encode + crypto.subtle.digest a multi-megabyte\n\t\t// `Authorization: DPoP ...` value during ath verification before being\n\t\t// rejected. Bounded DoS — fail fast on size first.\n\t\tconst accessToken = await resolveAccessToken(c, getAccessToken);\n\t\tif (\n\t\t\taccessToken !== undefined &&\n\t\t\tsizingEncoder.encode(accessToken).length > maxAccessTokenSize\n\t\t) {\n\t\t\treturn errorResponse(\n\t\t\t\tDPoPErrors.invalidProof(`access token exceeds ${maxAccessTokenSize} bytes`),\n\t\t\t);\n\t\t}\n\n\t\tlet parsed: ParsedProof;\n\t\ttry {\n\t\t\tparsed = parseProof(proofHeader, allowed);\n\n\t\t\tconst requestUrl = getRequestUrl ? await getRequestUrl(c) : c.req.url;\n\t\t\tverifyProofClaims(parsed, {\n\t\t\t\thtm: c.req.method,\n\t\t\t\thtu: requestUrl,\n\t\t\t\tnow: Math.floor(clock() / 1000),\n\t\t\t\tiatTolerance,\n\t\t\t\thtuComparison,\n\t\t\t\tallowFutureIat,\n\t\t\t});\n\n\t\t\tawait verifyProofSignature(parsed);\n\t\t} catch (err) {\n\t\t\tif (err instanceof DPoPProofError) return errorResponse(err.problem);\n\t\t\tthrow err;\n\t\t}\n\n\t\t// Lazy + memoized issueNonce: shared between the use_dpop_nonce error\n\t\t// path and the success-path echo so a request triggers at most one\n\t\t// provider RPC. Matters for shared-store providers (Redis, KV) where\n\t\t// each issueNonce() is a network round-trip.\n\t\tlet cachedNonce: string | undefined;\n\t\tconst issueNonceOnce = nonceProvider\n\t\t\t? async () => {\n\t\t\t\t\tif (cachedNonce === undefined) cachedNonce = await nonceProvider.issueNonce(c);\n\t\t\t\t\treturn cachedNonce;\n\t\t\t\t}\n\t\t\t: undefined;\n\n\t\t// Nonce challenge (RFC 9449 §8). Run after sig verification so that we\n\t\t// only mint nonces for cryptographically valid proofs — prevents nonce\n\t\t// flooding from unauthenticated clients.\n\t\tif (nonceProvider && issueNonceOnce) {\n\t\t\tconst nonceClaim = parsed.payload.nonce;\n\t\t\t// Always invoke isValid so the request-handling time does not depend on\n\t\t\t// whether the nonce claim is present. Distinguishing \"missing nonce\" from\n\t\t\t// \"invalid nonce\" by the absence of the provider RPC is a small timing\n\t\t\t// oracle for shared-store providers (Redis, KV) — close it. Provider\n\t\t\t// implementations are expected to treat the empty string as invalid.\n\t\t\tconst candidate = typeof nonceClaim === \"string\" ? nonceClaim : \"\";\n\t\t\tconst nonceOk = await nonceProvider.isValid(candidate, c);\n\t\t\tif (!nonceOk) {\n\t\t\t\treturn errorResponse(DPoPErrors.useNonce(await issueNonceOnce()));\n\t\t\t}\n\t\t}\n\n\t\tif (requireAccessToken && !accessToken) {\n\t\t\treturn errorResponse(DPoPErrors.missingAccessToken());\n\t\t}\n\t\tif (accessToken !== undefined) {\n\t\t\tif (typeof parsed.payload.ath !== \"string\") {\n\t\t\t\treturn errorResponse(\n\t\t\t\t\tDPoPErrors.invalidProof(\"ath claim is required when an access token is presented\"),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst expected = await computeAth(accessToken);\n\t\t\tif (!timingSafeEqual(expected, parsed.payload.ath)) {\n\t\t\t\treturn errorResponse(DPoPErrors.athMismatch());\n\t\t\t}\n\t\t}\n\n\t\t// jti replay check is last so leak-free: only valid proofs reach the store\n\t\tconst expiresAt = parsed.payload.iat * 1000 + jtiTtl;\n\t\tconst fresh = await nonceStore.check(parsed.payload.jti, expiresAt);\n\t\tif (!fresh) {\n\t\t\treturn errorResponse(DPoPErrors.jtiReplay());\n\t\t}\n\n\t\tconst jkt = await jwkThumbprint(parsed.header.jwk);\n\t\tconst verified: DPoPVerifiedProof = {\n\t\t\tjkt,\n\t\t\tjti: parsed.payload.jti,\n\t\t\tjwk: parsed.header.jwk,\n\t\t\thtm: parsed.payload.htm,\n\t\t\thtu: normalizeHtu(parsed.payload.htu, htuComparison),\n\t\t\tiat: parsed.payload.iat,\n\t\t\tath: parsed.payload.ath,\n\t\t\traw: parsed.raw,\n\t\t};\n\t\tc.set(\"dpop\", verified);\n\n\t\tawait next();\n\n\t\t// Echo the current nonce on success so clients learn it without an extra\n\t\t// challenge round-trip (RFC 9449 §8 recommendation). Reuses the cached\n\t\t// value if the use_dpop_nonce path already minted one (it didn't here,\n\t\t// since we reached success — but the closure is still memoized).\n\t\tif (issueNonceOnce) {\n\t\t\tc.res.headers.set(DPOP_NONCE_HEADER, await issueNonceOnce());\n\t\t}\n\t});\n}\n\nasync function resolveAccessToken(\n\tc: Context,\n\toverride?: DPoPOptions[\"getAccessToken\"],\n): Promise<string | undefined> {\n\tif (override) return override(c);\n\tconst auth = c.req.header(AUTHORIZATION_HEADER);\n\tif (!auth) return undefined;\n\t// RFC 7235 §2.1: authentication scheme names are case-insensitive. Match on\n\t// the lowercase scheme prefix but slice from the original to preserve the\n\t// token bytes (the token after the scheme is opaque and case-sensitive).\n\tconst space = auth.indexOf(\" \");\n\tif (space < 0) return undefined;\n\tif (auth.slice(0, space).toLowerCase() !== DPOP_AUTH_SCHEME) return undefined;\n\t// trim() handles the \"DPoP   token\" (extra interior whitespace) case.\n\t// A whitespace-only-after-the-scheme token (e.g. \"DPoP    \") cannot reach\n\t// this line on the platforms we target: the WHATWG fetch Headers API trims\n\t// trailing whitespace from header values before middleware sees them, so\n\t// `auth.indexOf(\" \")` returns -1 and we exit earlier. The trim here is a\n\t// belt-and-braces for proxies that preserve interior whitespace before the\n\t// first non-space token byte.\n\treturn auth.slice(space + 1).trim();\n}\n\nasync function respondWithProblem(\n\tproblem: ProblemDetail,\n\tc: Context,\n\tonError: DPoPOptions[\"onError\"] | undefined,\n\talgsHint: string,\n): Promise<Response> {\n\t// Surface supported algs on every 401 — RFC 9449 §7.1 lets clients\n\t// discover the server's algorithm preferences without trial-and-error.\n\tconst enriched: ProblemDetail = {\n\t\t...problem,\n\t\twwwAuthExtras: { ...problem.wwwAuthExtras, algs: algsHint },\n\t};\n\tif (onError) return onError(enriched, c);\n\tconst pd = await getHonoProblemDetails();\n\tif (pd) {\n\t\tconst response = pd\n\t\t\t.problemDetails({\n\t\t\t\ttype: enriched.type,\n\t\t\t\ttitle: enriched.title,\n\t\t\t\tstatus: enriched.status,\n\t\t\t\tdetail: enriched.detail,\n\t\t\t\textensions: { code: enriched.code },\n\t\t\t})\n\t\t\t.getResponse();\n\t\tresponse.headers.set(\n\t\t\t\"WWW-Authenticate\",\n\t\t\twwwAuthenticateHeader(enriched.wwwAuthError, enriched.wwwAuthExtras),\n\t\t);\n\t\tif (enriched.additionalHeaders) {\n\t\t\tfor (const [k, v] of Object.entries(enriched.additionalHeaders)) {\n\t\t\t\tresponse.headers.set(k, v);\n\t\t\t}\n\t\t}\n\t\treturn response;\n\t}\n\treturn problemResponse(enriched);\n}\n","type HonoProblemDetails = typeof import(\"hono-problem-details\");\n\nlet cached: HonoProblemDetails | null | undefined;\n\nexport async function getHonoProblemDetails(): Promise<HonoProblemDetails | null> {\n\tif (cached === undefined) {\n\t\ttry {\n\t\t\tcached = await import(\"hono-problem-details\");\n\t\t} catch {\n\t\t\tcached = null;\n\t\t}\n\t}\n\treturn cached;\n}\n","import { base64urlDecode, base64urlDecodeToString, base64urlEncode } from \"./base64url.js\";\nimport { DPoPErrors, DPoPProofError } from \"./errors.js\";\nimport {\n\tassertAlgMatchesJwk,\n\tassertPublicJwk,\n\timportPublicJwk,\n\tisSupportedAlgorithm,\n\ttype JwsAlgorithm,\n\ttype PublicJwk,\n\tverifyParamsFor,\n} from \"./jwk.js\";\n\nexport interface ParsedProof {\n\theader: { typ: \"dpop+jwt\"; alg: JwsAlgorithm; jwk: PublicJwk };\n\tpayload: {\n\t\tjti: string;\n\t\thtm: string;\n\t\thtu: string;\n\t\tiat: number;\n\t\tath?: string;\n\t\tnonce?: string;\n\t};\n\traw: string;\n}\n\nconst encoder = new TextEncoder();\n\n// Upper bound for iat (seconds). 1e10 ≈ year 2286 — far past any realistic\n// proof lifetime, but small enough that `iat * 1000` (used downstream as a\n// jti expiry timestamp in milliseconds) stays well below Number.MAX_SAFE_INTEGER.\n// Without this cap, a forged `iat` near Number.MAX_SAFE_INTEGER would lose\n// precision when multiplied, producing a near-Infinity expiry that makes the\n// jti effectively immortal in the replay store.\nconst MAX_IAT = 1e10;\n\nfunction fail(detail: string): never {\n\tthrow new DPoPProofError(DPoPErrors.invalidProof(detail));\n}\n\nexport function parseProof(jwt: string, allowed: ReadonlySet<JwsAlgorithm>): ParsedProof {\n\tif (typeof jwt !== \"string\" || jwt.length === 0) fail(\"DPoP header is missing\");\n\tconst parts = jwt.split(\".\");\n\tif (parts.length !== 3) fail(\"DPoP header is not a JWT\");\n\tconst [encHeader, encPayload, encSig] = parts;\n\n\tlet header: unknown;\n\tlet payload: unknown;\n\ttry {\n\t\theader = JSON.parse(base64urlDecodeToString(encHeader));\n\t} catch {\n\t\tfail(\"DPoP header section is not valid JSON\");\n\t}\n\ttry {\n\t\tpayload = JSON.parse(base64urlDecodeToString(encPayload));\n\t} catch {\n\t\tfail(\"DPoP payload section is not valid JSON\");\n\t}\n\tif (!header || typeof header !== \"object\" || Array.isArray(header)) {\n\t\tfail(\"DPoP header section is not a JSON object\");\n\t}\n\tif (!payload || typeof payload !== \"object\" || Array.isArray(payload)) {\n\t\tfail(\"DPoP payload section is not a JSON object\");\n\t}\n\n\tconst h = header as Record<string, unknown>;\n\tconst p = payload as Record<string, unknown>;\n\n\tif (h.typ !== \"dpop+jwt\") fail('typ must be \"dpop+jwt\"');\n\tif (typeof h.alg !== \"string\") fail(\"alg must be a string\");\n\tif (!isSupportedAlgorithm(h.alg)) fail(`unsupported alg: ${h.alg}`);\n\tif (!allowed.has(h.alg)) fail(`alg \"${h.alg}\" is not in the allowed set`);\n\tif (!h.jwk || typeof h.jwk !== \"object\") fail(\"jwk header is missing\");\n\n\tlet jwk: PublicJwk;\n\ttry {\n\t\tassertPublicJwk(h.jwk);\n\t\tjwk = h.jwk;\n\t\tassertAlgMatchesJwk(h.alg, jwk);\n\t} catch (err) {\n\t\tfail((err as Error).message);\n\t}\n\n\tif (typeof p.jti !== \"string\" || p.jti.length === 0) fail(\"jti is missing\");\n\tif (typeof p.htm !== \"string\") fail(\"htm must be a string\");\n\tif (typeof p.htu !== \"string\") fail(\"htu must be a string\");\n\tif (typeof p.iat !== \"number\" || !Number.isInteger(p.iat) || p.iat < 0 || p.iat > MAX_IAT) {\n\t\tfail(\"iat must be a non-negative integer within bounds\");\n\t}\n\tif (p.ath !== undefined && typeof p.ath !== \"string\") fail(\"ath must be a string\");\n\tif (p.nonce !== undefined && typeof p.nonce !== \"string\") fail(\"nonce must be a string\");\n\n\t// Validate base64url shape now so verifyProofSignature can decode without re-validating.\n\ttry {\n\t\tbase64urlDecode(encSig);\n\t} catch {\n\t\tfail(\"signature is not valid base64url\");\n\t}\n\n\treturn {\n\t\theader: { typ: \"dpop+jwt\", alg: h.alg, jwk },\n\t\tpayload: {\n\t\t\tjti: p.jti,\n\t\t\thtm: p.htm,\n\t\t\thtu: p.htu,\n\t\t\tiat: p.iat,\n\t\t\tath: p.ath as string | undefined,\n\t\t\tnonce: p.nonce as string | undefined,\n\t\t},\n\t\traw: jwt,\n\t};\n}\n\nexport type HtuComparison = \"strict\" | \"trailing-slash-insensitive\";\n\nexport interface ClaimVerifyOptions {\n\thtm: string;\n\thtu: string;\n\t/** Current time in seconds. */\n\tnow: number;\n\t/** Allowed clock skew on iat in seconds. */\n\tiatTolerance: number;\n\t/** htu comparison policy (default: \"strict\"). */\n\thtuComparison?: HtuComparison;\n\t/** Allow proofs with iat in the future (default: false). */\n\tallowFutureIat?: boolean;\n}\n\n/**\n * RFC 9449 §4.3 server checks for htm / htu / iat. Throws DPoPProofError on failure.\n */\nexport function verifyProofClaims(parsed: ParsedProof, opts: ClaimVerifyOptions): void {\n\tif (parsed.payload.htm !== opts.htm) {\n\t\tthrow new DPoPProofError(\n\t\t\tDPoPErrors.invalidProof(\n\t\t\t\t`htm \"${parsed.payload.htm}\" does not match request method \"${opts.htm}\"`,\n\t\t\t),\n\t\t);\n\t}\n\tconst policy = opts.htuComparison ?? \"strict\";\n\tconst expectedHtu = normalizeHtu(opts.htu, policy);\n\tconst actualHtu = normalizeHtu(parsed.payload.htu, policy);\n\tif (expectedHtu !== actualHtu) {\n\t\tthrow new DPoPProofError(DPoPErrors.invalidProof(\"htu does not match request URL\"));\n\t}\n\tconst delta = opts.now - parsed.payload.iat;\n\tconst tooOld = delta > opts.iatTolerance;\n\tconst tooNew = !opts.allowFutureIat && delta < -opts.iatTolerance;\n\tif (tooOld || tooNew) {\n\t\tthrow new DPoPProofError(\n\t\t\tDPoPErrors.invalidProof(`iat is outside the ${opts.iatTolerance}s window`),\n\t\t);\n\t}\n}\n\n/**\n * Normalize a URL for htu comparison: strip query and fragment.\n * RFC 9449 §4.3 step 11: \"ignoring any query and fragment parts\".\n *\n * When `policy` is `\"trailing-slash-insensitive\"`, a trailing `/` is stripped\n * from non-root paths so `https://x/api` and `https://x/api/` compare equal.\n */\nexport function normalizeHtu(input: string, policy: HtuComparison = \"strict\"): string {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(input);\n\t} catch {\n\t\tthrow new DPoPProofError(DPoPErrors.invalidProof(\"URL is not parseable\"));\n\t}\n\turl.hash = \"\";\n\turl.search = \"\";\n\tlet s = url.toString();\n\tif (policy === \"trailing-slash-insensitive\") {\n\t\t// Only strip trailing slash from non-root paths. URL.toString() always\n\t\t// emits at least \"scheme://host/\", so the shortest possible form ends\n\t\t// in exactly one \"/\" — leave that alone, strip any deeper trailing one.\n\t\tif (url.pathname !== \"/\" && s.endsWith(\"/\")) s = s.slice(0, -1);\n\t}\n\treturn s;\n}\n\nexport async function verifyProofSignature(parsed: ParsedProof): Promise<void> {\n\tconst [encHeader, encPayload, encSig] = parsed.raw.split(\".\");\n\tconst signingInput = encoder.encode(`${encHeader}.${encPayload}`);\n\tconst signature = base64urlDecode(encSig);\n\tconst key = await importPublicJwk(parsed.header.jwk, parsed.header.alg);\n\tconst ok = await crypto.subtle.verify(\n\t\tverifyParamsFor(parsed.header.alg),\n\t\tkey,\n\t\tsignature,\n\t\tsigningInput,\n\t);\n\tif (!ok) {\n\t\tthrow new DPoPProofError(DPoPErrors.invalidProof(\"signature verification failed\"));\n\t}\n}\n\nexport async function computeAth(accessToken: string): Promise<string> {\n\tconst digest = await crypto.subtle.digest(\"SHA-256\", encoder.encode(accessToken));\n\treturn base64urlEncode(new Uint8Array(digest));\n}\n\n/**\n * Constant-time string comparison to avoid timing leaks on ath comparisons.\n *\n * Length-tolerant: rather than early-returning on `a.length !== b.length` (which\n * leaks length information via timing), we mix the length difference into the\n * accumulated diff and walk the longer input to its end. Iteration count is\n * proportional to `max(|a|, |b|)`, not `min`, so an attacker cannot infer the\n * shorter side's length by measuring how long the comparison takes. Observable\n * behavior (true/false return) is unchanged.\n */\nexport function timingSafeEqual(a: string, b: string): boolean {\n\tconst aBytes = encoder.encode(a);\n\tconst bBytes = encoder.encode(b);\n\tlet diff = aBytes.length ^ bBytes.length;\n\tconst minLen = Math.min(aBytes.length, bBytes.length);\n\tfor (let i = 0; i < minLen; i++) {\n\t\tdiff |= aBytes[i] ^ bBytes[i];\n\t}\n\t// Touch the longer side's remaining bytes so iteration time is bounded by\n\t// max(|a|, |b|). The OR with the byte value also guarantees diff stays\n\t// nonzero when the longer side has any non-NUL trailing byte (the length\n\t// XOR above already ensures nonzero diff for unequal lengths regardless).\n\tconst longer = aBytes.length > bBytes.length ? aBytes : bBytes;\n\tfor (let i = minLen; i < longer.length; i++) {\n\t\tdiff |= longer[i];\n\t}\n\treturn diff === 0;\n}\n","import type { NonceProvider } from \"./types.js\";\n\nexport interface MemoryNonceProviderOptions {\n\t/** Rotate the nonce after this many milliseconds (default: 5 minutes). */\n\trotateAfter?: number;\n\t/** Accept the previous nonce in addition to the current one (default: true). */\n\tretainPrevious?: boolean;\n\t/** Override clock — function returning milliseconds epoch. Default: `Date.now`. */\n\tclock?: () => number;\n}\n\nconst DEFAULT_ROTATE_AFTER = 5 * 60_000;\n\n/**\n * In-process server nonce provider per RFC 9449 §8. Generates a UUID nonce that\n * rotates every `rotateAfter` milliseconds. By default, the previous nonce is also\n * accepted to absorb the natural race between rotation and an in-flight client request.\n *\n * Stateful and process-local — for multi-instance deployments, implement `NonceProvider`\n * against a shared store (Redis, Cloudflare KV, etc.).\n */\nexport function memoryNonceProvider(options: MemoryNonceProviderOptions = {}): NonceProvider {\n\tconst rotateAfter = options.rotateAfter ?? DEFAULT_ROTATE_AFTER;\n\tconst retainPrevious = options.retainPrevious ?? true;\n\tconst clock = options.clock ?? Date.now;\n\n\tlet current = crypto.randomUUID();\n\tlet previous: string | undefined;\n\tlet rotatedAt = clock();\n\n\tconst rotateIfDue = (): void => {\n\t\tconst now = clock();\n\t\tif (now - rotatedAt < rotateAfter) return;\n\t\tprevious = current;\n\t\tcurrent = crypto.randomUUID();\n\t\trotatedAt = now;\n\t};\n\n\treturn {\n\t\tissueNonce() {\n\t\t\trotateIfDue();\n\t\t\treturn current;\n\t\t},\n\t\tisValid(nonce) {\n\t\t\trotateIfDue();\n\t\t\tif (nonce === current) return true;\n\t\t\tif (retainPr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