@cboxdk/id-js 0.20.0 → 0.21.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/issuer.ts","../src/agent/errors.ts","../src/agent/http.ts","../src/pkce.ts","../src/agent/client-auth.ts","../src/agent/register.ts","../src/agent/grants.ts","../src/agent/binding.ts"],"names":["generateKeyPair","exportJWK","calculateJwkThumbprint","SignJWT","alg","importJWK"],"mappings":";;;;;AAIO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EACrC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,OAAO,GAAA,CAAA,MAAA,CAAW,IAAA;AAAA,EACzB;AACF;AAGO,IAAM,kBAAA,GAAN,cAAiC,WAAA,CAAY;AAAC;AAmB9C,IAAM,mBAAA,GAAN,cAAkC,WAAA,CAAY;AAAA,EACnD,WAAA,CACE,OAAA,EAES,KAAA,EAEA,gBAAA,EAEA,QAUA,UAAA,EACT;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAhBJ,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAEA,IAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA;AAEA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAUA,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA,EAGX;AAAA,EAjBW,KAAA;AAAA,EAEA,gBAAA;AAAA,EAEA,MAAA;AAAA,EAUA,UAAA;AAAA;AAAA,EAMX,IAAI,aAAA,GAAyB;AAC3B,IAAA,OAAO,KAAK,MAAA,KAAW,GAAA;AAAA,EACzB;AACF;;;AC7CO,SAAS,mBAAmB,MAAA,EAAsB;AACvD,EAAA,IAAI,GAAA;AAEJ,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,IAAI,IAAI,MAAM,CAAA;AAAA,EACtB,CA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GnC,EAAA,MAAM,KAAA,GAAQ,MAAO,GAAA,GAAM,IAAA;AAC3B,EAAA,IAAI,IAAA,GAAO,EAAA;AAEX,EAAA,OAAO,IAAA,CAAK,SAAS,MAAA,EAAQ;AAC3B,IAAA,KAAA,MAAW,IAAA,IAAQ,OAAO,eAAA,CAAgB,IAAI,WAAW,MAAA,GAAS,CAAC,CAAC,CAAA,EAAG;AACrE,MAAA,IAAI,IAAA,GAAO,KAAA,IAAS,IAAA,CAAK,MAAA,GAAS,MAAA,EAAQ;AACxC,QAAA,IAAA,IAAQ,qBAAA,CAAsB,OAAO,IAAI,CAAA;AAAA,MAC3C;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,IAAA;AACT","file":"agent.cjs","sourcesContent":["/**\n * Base class for every error this SDK throws, so callers can `catch (e) { if (e\n * instanceof CboxIdError) ... }` in one branch.\n */\nexport class CboxIdError extends Error {\n constructor(message: string) {\n super(message);\n this.name = new.target.name;\n }\n}\n\n/** The client is misconfigured (a required option is missing or empty). */\nexport class ConfigurationError extends CboxIdError {}\n\n/**\n * The login `state` did not match what was stored — the callback is forged or\n * stale. Treat as a fresh start, not an error to surface to the user.\n */\nexport class InvalidStateError extends CboxIdError {}\n\n/**\n * Login could not be completed: the provider returned an error, the callback was\n * missing a code, or a token / id_token failed verification.\n *\n * `error` carries the RFC 6749 §5.2 code the authorization server sent, when it sent one.\n * It used to be discarded at every back-channel boundary, leaving a single message string\n * for outcomes that need opposite responses: `invalid_grant` on a refresh means the\n * session is over and the person has to sign in again, while `temporarily_unavailable`\n * means try the same token in a moment. A caller reduced to matching on prose either\n * retries what can never succeed, or signs out somebody who did not need to be.\n */\nexport class AuthenticationError extends CboxIdError {\n constructor(\n message: string,\n /** RFC 6749 §5.2 error code, when the server sent a parseable one. */\n readonly error?: string,\n /** The server's `error_description`, verbatim. Not end-user copy. */\n readonly errorDescription?: string,\n /** HTTP status, for the cases where the body says nothing useful. */\n readonly status?: number,\n /**\n * Seconds to wait, off the `Retry-After` header — set only on a 429.\n *\n * The distinction it carries is the one a caller most needs and could least infer:\n * a 429 is the ONLY back-channel failure where the same request will succeed\n * unchanged if you simply wait. Every other one needs a different request, or a new\n * sign-in. Without this the SDK reported \"token refresh failed\" and a caller with a\n * retry loop hammered a limiter that was already telling it exactly how long to stop.\n */\n readonly retryAfter?: number,\n ) {\n super(message);\n }\n\n /** Whether waiting `retryAfter` seconds and repeating the same request is worth it. */\n get isRateLimited(): boolean {\n return this.status === 429;\n }\n}\n\n/**\n * Read an OAuth error out of a failed token-endpoint response.\n *\n * Best-effort by design: a 502 from a proxy is HTML, a captive portal is worse, and the\n * caller still needs an error rather than a parse exception. What it must never do is\n * invent a code — an absent or unparseable `error` stays undefined, so\n * `e.error === 'invalid_grant'` is true only because the server said so.\n */\nexport async function oauthError(response: Response, fallback: string): Promise<AuthenticationError> {\n const body = await response.text().catch(() => '');\n\n let code: string | undefined;\n let description: string | undefined;\n\n try {\n const parsed: unknown = JSON.parse(body);\n\n if (typeof parsed === 'object' && parsed !== null) {\n const { error, error_description: errorDescription } = parsed as Record<string, unknown>;\n code = typeof error === 'string' ? error : undefined;\n description = typeof errorDescription === 'string' ? errorDescription : undefined;\n }\n } catch {\n // Not JSON. The status and the truncated body below are all there is to report.\n }\n\n // THE BODY IS NEVER ECHOED. These calls carry `client_secret`, `code_verifier` and\n // refresh tokens in their REQUEST, and a debug proxy, a captive portal or an upstream\n // error page that reflects what it received puts those straight into a thrown message\n // — which production apps log. Only the server's own OAuth error code travels, and\n // failing that, the status alone.\n const detail = code ?? `HTTP ${response.status}`;\n\n // `Retry-After` is seconds here — Laravel's throttler writes the integer form. The\n // HTTP-date form is legal too and is deliberately NOT parsed: guessing at a clock\n // skew is worse than saying nothing, and `status === 429` still tells the caller to\n // back off.\n const retryAfterHeader = response.headers.get('retry-after');\n const retryAfter = retryAfterHeader !== null && /^\\d+$/.test(retryAfterHeader.trim())\n ? Number(retryAfterHeader.trim())\n : undefined;\n\n return new AuthenticationError(`${fallback}: ${detail}`, code, description, response.status, retryAfter);\n}\n\n/**\n * The Frontend API refused, or could not be reached.\n *\n * Carries a `code` because the four ways this goes wrong need four different responses\n * from the caller, and telling them apart from a message string is the kind of thing\n * that works until somebody rewords the message:\n *\n * - `origin_not_allowed` — the overwhelmingly likely cause of a refusal, and a\n * configuration problem the developer fixes once in the console.\n * - `rate_limited` — back off; `retryAfter` says for how long, when the server said.\n * - `unavailable` — the network, or a 5xx. Transient by assumption; already retried.\n * - `malformed` — a 200 whose body is not the document we expect, which means something\n * between the page and us is rewriting responses (a proxy, an extension, a captive\n * portal). Worth distinguishing, because retrying it never helps.\n */\nexport class FrontendApiError extends CboxIdError {\n constructor(\n message: string,\n readonly code: 'origin_not_allowed' | 'rate_limited' | 'unavailable' | 'malformed',\n readonly status?: number,\n readonly retryAfter?: number,\n ) {\n super(message);\n }\n}\n","import { ConfigurationError } from './errors.js';\n\n/**\n * An issuer must be HTTPS.\n *\n * Everything this SDK does with it carries a credential: the authorization code, the PKCE\n * verifier, the client secret, the refresh token. Over `http://` a network attacker reads\n * all of them — and, worse, replaces the discovery document and JWKS, at which point a\n * forged id_token verifies cleanly and the whole verification chain proves nothing.\n *\n * Loopback is allowed because a native app's own callback listener is loopback by\n * definition (RFC 8252) and a dev instance runs there.\n */\nexport function assertSecureIssuer(issuer: string): void {\n let url: URL;\n\n try {\n url = new URL(issuer);\n } catch {\n throw new ConfigurationError('Cbox ID config `issuer` is not a valid URL.');\n }\n\n if (url.protocol === 'https:') {\n return;\n }\n\n const loopback = url.hostname === 'localhost' || url.hostname === '127.0.0.1' || url.hostname === '[::1]' || url.hostname === '::1';\n\n if (url.protocol === 'http:' && loopback) {\n return;\n }\n\n throw new ConfigurationError(\n `Cbox ID config \\`issuer\\` must be https (got ${url.protocol}//${url.hostname}).`,\n );\n}\n","import { AuthenticationError, CboxIdError } from '../errors.js';\n\n/**\n * A CIBA, device-grant or registration request was refused with an OAuth error.\n *\n * Extends {@link AuthenticationError}, so `error`, `errorDescription`, `status` and\n * `retryAfter` read the same as on every other back-channel failure in this SDK, and a\n * caller already catching `AuthenticationError` keeps working. Branch on the subclass (or\n * on `error`), never on the message.\n *\n * The REQUEST is never part of the error: these calls carry client assertions, secrets and\n * device codes, and production CLIs log what they throw.\n */\nexport class AgentGrantError extends AuthenticationError {}\n\n/** The person declined (`access_denied`). Final — do not poll again. */\nexport class AccessDeniedError extends AgentGrantError {}\n\n/**\n * The `auth_req_id` or `device_code` expired before anyone approved it (`expired_token`).\n * Also thrown locally when the wait outlives the request's `expires_in`. Start again.\n */\nexport class ExpiredTokenError extends AgentGrantError {}\n\n/** The `auth_req_id`, `device_code` or refresh token is not valid (`invalid_grant`). */\nexport class InvalidGrantError extends AgentGrantError {}\n\n/**\n * The `resource` (RFC 8707) is not one this client may ask for, the poll named a\n * different resource than the request that started it, or the resource lets\n * self-registered clients use CIBA only with `private_key_jwt` and this one is keyless\n * (`invalid_target`).\n */\nexport class InvalidTargetError extends AgentGrantError {}\n\n/**\n * Client authentication failed (`invalid_client`): an unknown `client_id`, a bad secret, an\n * assertion signed by a key the server does not hold, or a replayed `jti`.\n */\nexport class InvalidClientError extends AgentGrantError {}\n\n/** The `login_hint` names nobody the server can reach (`unknown_user_id`). */\nexport class UnknownUserIdError extends AgentGrantError {}\n\n/**\n * The `binding_message` is missing where the server requires one (self-registered clients),\n * or too long to show beside Approve (`invalid_binding_message`).\n */\nexport class InvalidBindingMessageError extends AgentGrantError {}\n\n/**\n * The server asked us to slow down (`slow_down`, or HTTP 429). `retryAfter` carries the\n * `Retry-After` seconds when the server sent them. The wait helpers absorb this themselves;\n * it is thrown only from a call that does not loop (registration, starting a flow).\n */\nexport class SlowDownError extends AgentGrantError {}\n\n/** The caller aborted the wait (its `AbortSignal` fired). */\nexport class GrantCancelledError extends CboxIdError {}\n\nconst BY_CODE: Record<string, typeof AgentGrantError> = {\n access_denied: AccessDeniedError,\n expired_token: ExpiredTokenError,\n invalid_grant: InvalidGrantError,\n invalid_target: InvalidTargetError,\n invalid_client: InvalidClientError,\n unknown_user_id: UnknownUserIdError,\n invalid_binding_message: InvalidBindingMessageError,\n slow_down: SlowDownError,\n};\n\n/** A parsed `{ error, error_description }` body plus the bits of the response that matter. */\nexport interface OAuthFailure {\n error: string | undefined;\n errorDescription: string | undefined;\n status: number;\n retryAfter: number | undefined;\n}\n\n/**\n * Read an OAuth error body without ever echoing it. A 502 from a proxy is HTML, and an\n * error page that reflects the request would put a client assertion into a log line — so\n * only the server's own `error` code (or the status) reaches the message.\n */\nexport async function readOAuthFailure(response: Response): Promise<OAuthFailure> {\n const text = await response.text().catch(() => '');\n let error: string | undefined;\n let errorDescription: string | undefined;\n\n try {\n const parsed: unknown = JSON.parse(text);\n\n if (typeof parsed === 'object' && parsed !== null) {\n const record = parsed as Record<string, unknown>;\n error = typeof record['error'] === 'string' ? record['error'] : undefined;\n errorDescription = typeof record['error_description'] === 'string' ? record['error_description'] : undefined;\n }\n } catch {\n // Not JSON: the status alone is what there is to report.\n }\n\n // A 429 IS slow_down, whatever (or whether) the body says — the limiter in front of the\n // endpoint may answer before the OAuth layer does.\n if (response.status === 429 && error === undefined) {\n error = 'slow_down';\n }\n\n // Seconds only. The HTTP-date form is legal but guessing at clock skew is worse than\n // falling back to the +5s rule.\n const header = response.headers.get('retry-after');\n const retryAfter = header !== null && /^\\d+$/.test(header.trim()) ? Number(header.trim()) : undefined;\n\n return { error, errorDescription, status: response.status, retryAfter };\n}\n\n/** The typed error for a failure: a subclass for the codes callers branch on, else the base. */\nexport function grantError(failure: OAuthFailure, fallback: string): AgentGrantError {\n const Klass = (failure.error !== undefined ? BY_CODE[failure.error] : undefined) ?? AgentGrantError;\n const detail = failure.error ?? `HTTP ${failure.status}`;\n\n return new Klass(`${fallback}: ${detail}`, failure.error, failure.errorDescription, failure.status, failure.retryAfter);\n}\n","import { assertSecureIssuer } from '../issuer.js';\nimport { AuthenticationError, ConfigurationError } from '../errors.js';\nimport { GrantCancelledError } from './errors.js';\n\n/**\n * RFC 8414 authorization server metadata, as Cbox ID publishes it at\n * `{issuer}/.well-known/oauth-authorization-server`. Only the members this module reads are\n * typed; the rest pass through.\n */\nexport interface AuthorizationServerMetadata {\n issuer: string;\n token_endpoint: string;\n registration_endpoint?: string;\n backchannel_authentication_endpoint?: string;\n device_authorization_endpoint?: string;\n backchannel_token_delivery_modes_supported?: string[];\n backchannel_user_code_parameter_supported?: boolean;\n grant_types_supported?: string[];\n token_endpoint_auth_methods_supported?: string[];\n token_endpoint_auth_signing_alg_values_supported?: string[];\n [member: string]: unknown;\n}\n\n/** Transport options every call in this module takes. */\nexport interface AgentRequestOptions {\n /** A `fetch` to use instead of the global one (tests, proxies, instrumentation). */\n fetch?: typeof fetch;\n /** Per-request timeout in milliseconds. Default 10 000. */\n timeoutMs?: number;\n /** Abort the call (and, for the wait helpers, the whole wait). */\n signal?: AbortSignal;\n}\n\n/** Where to find the server: its issuer, and optionally metadata you already discovered. */\nexport interface AgentServerOptions extends AgentRequestOptions {\n /** The Cbox ID issuer, e.g. `https://acme.cboxid.com`. Must be https (loopback excepted). */\n issuer: string;\n /**\n * Metadata from {@link discoverAuthorizationServer}. Pass it to skip a discovery round\n * trip per call; omitted, each call discovers it (the wait helpers discover once).\n */\n metadata?: AuthorizationServerMetadata;\n}\n\n/**\n * Fetch and check the authorization server metadata (RFC 8414).\n *\n * The document's `issuer` must equal the one asked for (§3.3) — otherwise a host answering\n * with another tenant's metadata would receive this client's assertions and codes.\n */\nexport async function discoverAuthorizationServer(\n issuer: string,\n options: AgentRequestOptions = {},\n): Promise<AuthorizationServerMetadata> {\n if (!issuer) {\n throw new ConfigurationError('An `issuer` is required.');\n }\n assertSecureIssuer(issuer);\n\n const url = `${trimSlash(issuer)}/.well-known/oauth-authorization-server`;\n const response = await send(url, { method: 'GET', headers: { accept: 'application/json' } }, options);\n\n if (!response.ok) {\n throw new AuthenticationError(`Discovery request failed with status ${response.status}.`, undefined, undefined, response.status);\n }\n\n let doc: unknown;\n try {\n doc = await response.json();\n } catch {\n throw new AuthenticationError('The authorization server metadata was not JSON.');\n }\n\n if (typeof doc !== 'object' || doc === null) {\n throw new AuthenticationError('The authorization server metadata was not an object.');\n }\n\n const metadata = doc as AuthorizationServerMetadata;\n\n if (typeof metadata.issuer !== 'string' || trimSlash(metadata.issuer) !== trimSlash(issuer)) {\n throw new AuthenticationError(`The authorization server metadata is for a different issuer (${String(metadata.issuer)}).`);\n }\n if (typeof metadata.token_endpoint !== 'string' || metadata.token_endpoint === '') {\n throw new AuthenticationError('The authorization server metadata has no token_endpoint.');\n }\n\n return metadata;\n}\n\n/** Metadata from the options, or discovered. */\nexport function resolveMetadata(options: AgentServerOptions): Promise<AuthorizationServerMetadata> {\n return options.metadata !== undefined\n ? Promise.resolve(options.metadata)\n : discoverAuthorizationServer(options.issuer, options);\n}\n\n/** A named endpoint, or a ConfigurationError saying the server does not offer it. */\nexport function requireEndpoint(\n metadata: AuthorizationServerMetadata,\n name: 'registration_endpoint' | 'backchannel_authentication_endpoint' | 'device_authorization_endpoint' | 'token_endpoint',\n what: string,\n): string {\n const value = metadata[name];\n if (typeof value !== 'string' || value === '') {\n throw new ConfigurationError(`This Cbox ID instance does not advertise a ${name}, so it does not support ${what}.`);\n }\n return value;\n}\n\n/**\n * `fetch` with a timeout and the caller's signal combined. A caller abort becomes\n * {@link GrantCancelledError}; a timeout or network failure an {@link AuthenticationError}.\n */\nexport async function send(url: string, init: RequestInit, options: AgentRequestOptions): Promise<Response> {\n const fetchImpl = options.fetch ?? globalThis.fetch;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? 10_000);\n const onAbort = (): void => controller.abort();\n\n if (options.signal?.aborted === true) {\n clearTimeout(timer);\n throw new GrantCancelledError('The request was cancelled.');\n }\n options.signal?.addEventListener('abort', onAbort, { once: true });\n\n try {\n return await fetchImpl(url, { ...init, signal: controller.signal });\n } catch (error) {\n // Re-read through a widened type: the early return above narrowed `aborted` to false,\n // but the signal may have fired while the request was in flight.\n if ((options.signal as AbortSignal | undefined)?.aborted === true) {\n throw new GrantCancelledError('The request was cancelled.');\n }\n if (controller.signal.aborted) {\n throw new AuthenticationError(`The request to ${new URL(url).origin} timed out.`);\n }\n throw new AuthenticationError(`The request to ${new URL(url).origin} failed: ${String(error)}`);\n } finally {\n clearTimeout(timer);\n options.signal?.removeEventListener('abort', onAbort);\n }\n}\n\nexport function trimSlash(value: string): string {\n return value.replace(/\\/+$/, '');\n}\n","/**\n * PKCE (RFC 7636) and the random values the login flow needs, built on Web Crypto\n * (`globalThis.crypto`) so the same code runs on Node, edge runtimes and browsers.\n */\n\nfunction base64url(bytes: Uint8Array): string {\n let binary = '';\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n}\n\n/** A URL-safe random token of `bytes` bytes (default 32), for state and nonce. */\nexport function randomToken(bytes = 32): string {\n return base64url(crypto.getRandomValues(new Uint8Array(bytes)));\n}\n\n/** A high-entropy PKCE code verifier. */\nexport function createVerifier(): string {\n return randomToken(32);\n}\n\n/** The S256 code challenge for a verifier. */\nexport async function challenge(verifier: string): Promise<string> {\n const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier));\n return base64url(new Uint8Array(digest));\n}\n","import { calculateJwkThumbprint, exportJWK, generateKeyPair, importJWK, SignJWT, type JWK } from 'jose';\nimport { ConfigurationError } from '../errors.js';\nimport { randomToken } from '../pkce.js';\n\n/** The client-assertion algorithms this module signs with. Cbox ID accepts both. */\nexport type ClientKeyAlgorithm = 'ES256' | 'RS256';\n\n/** A signing key pair for `private_key_jwt`, from {@link generateClientKeyPair}. */\nexport interface ClientKeyPair {\n alg: ClientKeyAlgorithm;\n /** The RFC 7638 thumbprint of the public key, used as `kid`. */\n kid: string;\n /** The public JWK (with `kid`, `alg`, `use: 'sig'`) — what registration sends in `jwks`. */\n publicJwk: JWK;\n /**\n * The private JWK. PERSIST THIS, and only this, somewhere the user alone can read\n * (mode 0600, the OS keychain). It is the client's credential: whoever holds it is the\n * client. Never log it, never commit it.\n */\n privateJwk: JWK;\n /** The private key as a WebCrypto `CryptoKey`, ready to sign with. */\n privateKey: CryptoKey;\n}\n\n/**\n * How the client authenticates at the backchannel, device and token endpoints.\n *\n * - `private_key_jwt` (RFC 7523): a short-lived assertion signed with your private key.\n * The right choice for a self-registered agent or CLI: nothing secret ever crosses the\n * wire, and the server stores only the public key.\n * - `client_secret_basic` / `client_secret_post`: a console-issued secret.\n * - `none`: a public client names itself by `client_id` only. Fine for the device grant.\n * For CIBA, Cbox ID accepts a keyless self-registered client only when the resource\n * allows it (`dynamic_public_backchannel`); otherwise the answer is `invalid_target`.\n * Prefer `private_key_jwt` for CIBA: a public `client_id` proves nothing, and CIBA has no front\n * channel to bind the flow to.\n */\nexport type ClientAuth =\n | {\n method: 'private_key_jwt';\n clientId: string;\n /** A `CryptoKey`, or the private JWK you persisted from {@link generateClientKeyPair}. */\n privateKey: CryptoKey | JWK;\n /** Inferred from the key when omitted. */\n alg?: ClientKeyAlgorithm;\n /** Sent as the assertion's `kid`. Taken from a JWK's own `kid` when omitted. */\n kid?: string;\n }\n | { method: 'client_secret_basic' | 'client_secret_post'; clientId: string; clientSecret: string }\n | { method: 'none'; clientId: string };\n\n/**\n * A fresh signing key pair for `private_key_jwt`, generated with WebCrypto (via `jose`), so\n * it runs on Node, Deno, Bun and edge runtimes. ES256 by default — small keys, small\n * signatures. The private key is extractable on purpose: the caller must persist it.\n */\nexport async function generateClientKeyPair(alg: ClientKeyAlgorithm = 'ES256'): Promise<ClientKeyPair> {\n const { publicKey, privateKey } = await generateKeyPair(alg, { extractable: true });\n const publicBare = await exportJWK(publicKey);\n const kid = await calculateJwkThumbprint(publicBare, 'sha256');\n\n const publicJwk: JWK = { ...publicBare, kid, alg, use: 'sig' };\n const privateJwk: JWK = { ...(await exportJWK(privateKey)), kid, alg, use: 'sig' };\n\n return { alg, kid, publicJwk, privateJwk, privateKey };\n}\n\n/**\n * A signed RFC 7523 client assertion: `iss` = `sub` = client id, `aud` = the token\n * endpoint, a random `jti` (the server remembers it, so each assertion is single-use),\n * `iat` now and `exp` at most 60 seconds later.\n */\nexport async function createClientAssertion(\n auth: Extract<ClientAuth, { method: 'private_key_jwt' }>,\n audience: string,\n options: { now?: () => number; lifetimeSeconds?: number } = {},\n): Promise<string> {\n const lifetime = Math.min(Math.max(options.lifetimeSeconds ?? 60, 1), 60);\n const nowSeconds = Math.floor((options.now ?? Date.now)() / 1000);\n const { key, alg, kid } = await signingKey(auth);\n\n const header: { alg: string; kid?: string } = { alg };\n if (kid !== undefined) {\n header.kid = kid;\n }\n\n return new SignJWT({})\n .setProtectedHeader(header)\n .setIssuer(auth.clientId)\n .setSubject(auth.clientId)\n .setAudience(audience)\n .setJti(randomToken(16))\n .setIssuedAt(nowSeconds)\n .setExpirationTime(nowSeconds + lifetime)\n .sign(key);\n}\n\n/**\n * Put client authentication on a request: fields in the form body, and/or an\n * `Authorization` header. `audience` is the token endpoint, the one value Cbox ID accepts\n * on assertions to all of its endpoints.\n */\nexport async function applyClientAuth(\n auth: ClientAuth,\n body: URLSearchParams,\n headers: Record<string, string>,\n audience: string,\n): Promise<void> {\n if (!auth.clientId) {\n throw new ConfigurationError('A `clientId` is required.');\n }\n\n switch (auth.method) {\n case 'private_key_jwt':\n body.set('client_id', auth.clientId);\n body.set('client_assertion_type', 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer');\n body.set('client_assertion', await createClientAssertion(auth, audience));\n return;\n case 'client_secret_basic':\n if (!auth.clientSecret) {\n throw new ConfigurationError('`client_secret_basic` needs a `clientSecret`.');\n }\n // RFC 6749 §2.3.1: both halves are form-encoded before they are joined.\n headers['authorization'] = `Basic ${btoa(`${formEncode(auth.clientId)}:${formEncode(auth.clientSecret)}`)}`;\n return;\n case 'client_secret_post':\n if (!auth.clientSecret) {\n throw new ConfigurationError('`client_secret_post` needs a `clientSecret`.');\n }\n body.set('client_id', auth.clientId);\n body.set('client_secret', auth.clientSecret);\n return;\n case 'none':\n body.set('client_id', auth.clientId);\n return;\n }\n}\n\nasync function signingKey(\n auth: Extract<ClientAuth, { method: 'private_key_jwt' }>,\n): Promise<{ key: CryptoKey | Uint8Array; alg: ClientKeyAlgorithm; kid: string | undefined }> {\n const source = auth.privateKey;\n\n if (isCryptoKey(source)) {\n const alg = auth.alg ?? algFromCryptoKey(source);\n return { key: source, alg, kid: auth.kid };\n }\n\n if (typeof source !== 'object' || source === null || typeof source.d !== 'string') {\n throw new ConfigurationError('`privateKey` must be a CryptoKey or a private JWK (with `d`).');\n }\n\n const alg = auth.alg ?? algFromJwk(source);\n const key = await importJWK(source, alg);\n\n return { key, alg, kid: auth.kid ?? (typeof source.kid === 'string' ? source.kid : undefined) };\n}\n\nfunction isCryptoKey(value: unknown): value is CryptoKey {\n return typeof CryptoKey !== 'undefined' && value instanceof CryptoKey;\n}\n\nfunction algFromCryptoKey(key: CryptoKey): ClientKeyAlgorithm {\n if (key.algorithm.name === 'ECDSA') {\n return 'ES256';\n }\n if (key.algorithm.name === 'RSASSA-PKCS1-v1_5') {\n return 'RS256';\n }\n throw new ConfigurationError(`Unsupported client key algorithm ${key.algorithm.name}; use ES256 or RS256.`);\n}\n\nfunction algFromJwk(jwk: JWK): ClientKeyAlgorithm {\n if (jwk.alg === 'ES256' || jwk.alg === 'RS256') {\n return jwk.alg as ClientKeyAlgorithm;\n }\n if (jwk.alg === undefined && jwk.kty === 'EC' && jwk.crv === 'P-256') {\n return 'ES256';\n }\n if (jwk.alg === undefined && jwk.kty === 'RSA') {\n return 'RS256';\n }\n throw new ConfigurationError('The private JWK is not an ES256 (P-256) or RS256 key.');\n}\n\nfunction formEncode(value: string): string {\n return encodeURIComponent(value).replace(/%20/g, '+');\n}\n","import { AuthenticationError, ConfigurationError } from '../errors.js';\nimport { generateClientKeyPair, type ClientAuth, type ClientKeyAlgorithm, type ClientKeyPair } from './client-auth.js';\nimport { grantError, readOAuthFailure } from './errors.js';\nimport { requireEndpoint, resolveMetadata, send, type AgentServerOptions } from './http.js';\n\n/** The CIBA grant type (OpenID CIBA Core). */\nexport const CIBA_GRANT_TYPE = 'urn:openid:params:grant-type:ciba';\n/** The device authorization grant type (RFC 8628). */\nexport const DEVICE_CODE_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code';\n\nexport interface RegisterAgentClientOptions extends AgentServerOptions {\n /** Shown to the person approving, so make it recognisable: \"Cbox Brain CLI on ada-mbp\". */\n clientName: string;\n /** e.g. `[CIBA_GRANT_TYPE, 'refresh_token']` or `[DEVICE_CODE_GRANT_TYPE, 'refresh_token']`. */\n grantTypes: string[];\n /** The scope ceiling to register. A space-separated string or a list. */\n scope?: string | string[];\n /**\n * `private_key_jwt` (default): a key pair is generated (or `keyPair` used) and the\n * public half registered inline as `jwks`. `none`: a public client — the device grant,\n * or CIBA where the resource allows keyless clients. `private_key_jwt` is recommended for CIBA.\n */\n tokenEndpointAuthMethod?: 'private_key_jwt' | 'none';\n /** Algorithm for the generated key pair. Default ES256. */\n alg?: ClientKeyAlgorithm;\n /** Register an existing key pair instead of generating one. */\n keyPair?: ClientKeyPair;\n /** RFC 7591 §3 initial access token, when the instance requires one to register. */\n initialAccessToken?: string;\n /** Further RFC 7591 client metadata, sent as-is (e.g. `software_id`, `client_uri`). */\n extraMetadata?: Record<string, unknown>;\n}\n\nexport interface RegisteredAgentClient {\n clientId: string;\n /** Present only if the server issued one; a `private_key_jwt` or `none` client has none. */\n clientSecret: string | null;\n /** RFC 7592 credential for reading/updating/deleting the registration. Persist it if you need that. */\n registrationAccessToken: string | null;\n registrationClientUri: string | null;\n tokenEndpointAuthMethod: string;\n grantTypes: string[];\n scope: string | null;\n /** The key pair registered, for `private_key_jwt`. Persist `keyPair.privateJwk`. */\n keyPair: ClientKeyPair | null;\n /** Ready to hand to {@link startBackchannel} / {@link startDeviceAuthorization}. */\n auth: ClientAuth;\n /** The full registration response. */\n raw: Record<string, unknown>;\n}\n\n/**\n * Register this agent or CLI as an OAuth client (RFC 7591 dynamic client registration).\n *\n * Do it once per installation and persist the result: `clientId` and, for\n * `private_key_jwt`, `keyPair.privateJwk`. Re-registering on every run fills the\n * environment's app list with copies.\n *\n * @throws ConfigurationError when the instance has dynamic registration switched off.\n * @throws AgentGrantError (e.g. `invalid_client_metadata`) when the server refuses.\n */\nexport async function registerAgentClient(options: RegisterAgentClientOptions): Promise<RegisteredAgentClient> {\n if (!options.clientName) {\n throw new ConfigurationError('`clientName` is required.');\n }\n if (options.grantTypes.length === 0) {\n throw new ConfigurationError('`grantTypes` must name at least one grant.');\n }\n\n const metadata = await resolveMetadata(options);\n const endpoint = requireEndpoint(metadata, 'registration_endpoint', 'dynamic client registration');\n const method = options.tokenEndpointAuthMethod ?? 'private_key_jwt';\n\n const keyPair = method === 'private_key_jwt'\n ? options.keyPair ?? (await generateClientKeyPair(options.alg ?? 'ES256'))\n : null;\n\n const document: Record<string, unknown> = {\n ...options.extraMetadata,\n client_name: options.clientName,\n grant_types: options.grantTypes,\n token_endpoint_auth_method: method,\n // Neither CIBA nor the device grant has a redirect; say so rather than let the server\n // assume an authorization-code client.\n redirect_uris: [],\n response_types: [],\n };\n\n if (options.scope !== undefined) {\n document['scope'] = scopeString(options.scope);\n }\n if (keyPair !== null) {\n document['jwks'] = { keys: [keyPair.publicJwk] };\n }\n\n const headers: Record<string, string> = { 'content-type': 'application/json', accept: 'application/json' };\n if (options.initialAccessToken) {\n headers['authorization'] = `Bearer ${options.initialAccessToken}`;\n }\n\n const response = await send(endpoint, { method: 'POST', headers, body: JSON.stringify(document) }, options);\n\n if (!response.ok) {\n throw grantError(await readOAuthFailure(response), 'Client registration failed');\n }\n\n const raw = (await response.json().catch(() => null)) as Record<string, unknown> | null;\n const clientId = raw?.['client_id'];\n\n if (raw === null || typeof clientId !== 'string' || clientId === '') {\n throw new AuthenticationError('The registration response carried no client_id.');\n }\n\n const clientSecret = typeof raw['client_secret'] === 'string' ? raw['client_secret'] : null;\n const registeredMethod = typeof raw['token_endpoint_auth_method'] === 'string' ? raw['token_endpoint_auth_method'] : method;\n\n let auth: ClientAuth;\n if (keyPair !== null) {\n auth = { method: 'private_key_jwt', clientId, privateKey: keyPair.privateKey, alg: keyPair.alg, kid: keyPair.kid };\n } else if (clientSecret !== null) {\n auth = { method: 'client_secret_basic', clientId, clientSecret };\n } else {\n auth = { method: 'none', clientId };\n }\n\n return {\n clientId,\n clientSecret,\n registrationAccessToken: typeof raw['registration_access_token'] === 'string' ? raw['registration_access_token'] : null,\n registrationClientUri: typeof raw['registration_client_uri'] === 'string' ? raw['registration_client_uri'] : null,\n tokenEndpointAuthMethod: registeredMethod,\n grantTypes: Array.isArray(raw['grant_types']) ? raw['grant_types'].filter((g): g is string => typeof g === 'string') : options.grantTypes,\n scope: typeof raw['scope'] === 'string' ? raw['scope'] : null,\n keyPair,\n auth,\n raw,\n };\n}\n\nexport function scopeString(scope: string | string[]): string {\n return (typeof scope === 'string' ? scope.split(/\\s+/) : scope).filter((s) => s !== '').join(' ');\n}\n","import { AuthenticationError, ConfigurationError } from '../errors.js';\nimport { applyClientAuth, type ClientAuth } from './client-auth.js';\nimport { ExpiredTokenError, GrantCancelledError, grantError, readOAuthFailure } from './errors.js';\nimport {\n requireEndpoint,\n resolveMetadata,\n send,\n type AgentServerOptions,\n type AuthorizationServerMetadata,\n} from './http.js';\nimport { CIBA_GRANT_TYPE, DEVICE_CODE_GRANT_TYPE, scopeString } from './register.js';\n\n/** Tokens from a completed CIBA or device grant. */\nexport interface AgentTokens {\n accessToken: string;\n tokenType: string;\n /** Seconds, when the server said. */\n expiresIn: number | null;\n refreshToken: string | null;\n /**\n * The id_token, when `openid` was granted — returned as-is, NOT verified here. Verify it\n * with `CboxIdClient` (or `jose` against the JWKS) before trusting anything in it.\n */\n idToken: string | null;\n scope: string | null;\n /** The full token response. */\n raw: Record<string, unknown>;\n}\n\n/** One poll's outcome. Final failures are thrown, not returned. */\nexport type PollResult =\n | { status: 'complete'; tokens: AgentTokens }\n | { status: 'pending' }\n /** Slow down: add 5 s to the interval, and wait at least `retryAfter` seconds if given. */\n | { status: 'slow_down'; retryAfter: number | null };\n\n/** Options shared by the wait helpers. */\nexport interface WaitOptions {\n /** Replace the timer — tests pass a fake that records the waits. Must honour `signal`. */\n sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;\n /** Clock in epoch milliseconds. Default `Date.now`. */\n now?: () => number;\n}\n\ninterface ClientOptions extends AgentServerOptions {\n /** How the client authenticates. See {@link ClientAuth}. */\n client: ClientAuth;\n}\n\n// ---------------------------------------------------------------------------------------\n// CIBA (poll mode)\n// ---------------------------------------------------------------------------------------\n\nexport interface StartBackchannelOptions extends ClientOptions {\n /** Who should approve: a Cbox ID user id, or a confirmed email address. */\n loginHint: string;\n /** Space-separated string or list. Bounded by the client's registered scopes. */\n scope: string | string[];\n /**\n * Shown beside Approve. Put a {@link createBindingCode} code in it and print the same\n * code locally. Required by Cbox ID for self-registered clients; at most 255 characters.\n */\n bindingMessage: string;\n /**\n * RFC 8707 resource indicator(s) — the API the token is for. Optional in the type, but\n * REQUIRED by Cbox ID for self-registered clients.\n * Its settings also decide whether a keyless (`none`) client may use CIBA at all.\n */\n resource?: string | string[];\n /** Seconds the request may wait for approval (the server may shorten it). */\n requestedExpiry?: number;\n /** Echoed into the id_token, so you can bind it to this request. */\n nonce?: string;\n}\n\n/** A started CIBA request. Persistable as JSON. */\nexport interface BackchannelAuthorization {\n authReqId: string;\n expiresIn: number;\n /** Seconds between polls. */\n interval: number;\n /** Epoch ms after which polling is pointless. */\n expiresAt: number;\n /** The resource(s) the request named, re-sent on every poll (the server checks they match). */\n resource: string[];\n}\n\n/**\n * Start a CIBA request (OpenID CIBA Core §7, poll mode): Cbox ID shows `bindingMessage` to\n * the person named by `loginHint` and waits for Approve.\n *\n * `backchannel_user_code_parameter` is not supported by Cbox ID, so no user code is sent.\n *\n * @throws InvalidClientError, UnknownUserIdError, InvalidBindingMessageError,\n * InvalidTargetError, SlowDownError, AgentGrantError.\n */\nexport async function startBackchannel(options: StartBackchannelOptions): Promise<BackchannelAuthorization> {\n const now = Date.now();\n const metadata = await resolveMetadata(options);\n const endpoint = requireEndpoint(metadata, 'backchannel_authentication_endpoint', 'CIBA');\n\n if (!options.loginHint) {\n throw new ConfigurationError('`loginHint` is required.');\n }\n\n const resource = resourceList(options.resource);\n const body = new URLSearchParams({ login_hint: options.loginHint, scope: scopeString(options.scope) });\n\n if (options.bindingMessage !== '') {\n body.set('binding_message', options.bindingMessage);\n }\n for (const r of resource) {\n body.append('resource', r);\n }\n if (options.requestedExpiry !== undefined) {\n body.set('requested_expiry', String(options.requestedExpiry));\n }\n if (options.nonce !== undefined && options.nonce !== '') {\n body.set('nonce', options.nonce);\n }\n\n const payload = await postForm(endpoint, body, options, metadata, 'Backchannel authentication request failed');\n const authReqId = payload['auth_req_id'];\n\n if (typeof authReqId !== 'string' || authReqId === '') {\n throw new AuthenticationError('The backchannel authentication response carried no auth_req_id.');\n }\n\n const expiresIn = positiveNumber(payload['expires_in']) ?? 120;\n\n return {\n authReqId,\n expiresIn,\n // CIBA Core §7.3: absent means 5 seconds.\n interval: positiveNumber(payload['interval']) ?? 5,\n expiresAt: now + expiresIn * 1000,\n resource,\n };\n}\n\nexport interface PollBackchannelOptions extends ClientOptions {\n authorization: Pick<BackchannelAuthorization, 'authReqId' | 'resource'>;\n}\n\n/**\n * Poll the token endpoint once for a CIBA request.\n *\n * @throws AccessDeniedError, ExpiredTokenError, InvalidGrantError, InvalidTargetError,\n * InvalidClientError, AgentGrantError.\n */\nexport async function pollBackchannel(options: PollBackchannelOptions): Promise<PollResult> {\n const body = new URLSearchParams({ grant_type: CIBA_GRANT_TYPE, auth_req_id: options.authorization.authReqId });\n return pollToken(body, options.authorization.resource, options, 'Backchannel token request failed');\n}\n\n/**\n * Poll until the person approves, and return the tokens.\n *\n * Waits `interval` seconds before each poll; on `slow_down` (or a 429) adds five seconds\n * for good and waits at least `Retry-After`; keeps going on `authorization_pending`; stops\n * on anything final. Throws {@link ExpiredTokenError} once `expiresAt` passes and\n * {@link GrantCancelledError} when `signal` fires — wire it to Ctrl-C.\n */\nexport async function waitForBackchannelToken(\n options: PollBackchannelOptions & WaitOptions & { authorization: BackchannelAuthorization },\n): Promise<AgentTokens> {\n const metadata = await resolveMetadata(options);\n const authorization = options.authorization;\n\n return waitLoop(authorization, options, () => pollBackchannel({ ...options, metadata }), 'backchannel request');\n}\n\n// ---------------------------------------------------------------------------------------\n// Device authorization grant (RFC 8628)\n// ---------------------------------------------------------------------------------------\n\nexport interface StartDeviceAuthorizationOptions extends ClientOptions {\n scope?: string | string[];\n /** RFC 8707 resource indicator(s). */\n resource?: string | string[];\n}\n\n/** A started device authorization. Persistable as JSON. */\nexport interface DeviceGrantAuthorization {\n deviceCode: string;\n /** Show this to the person. */\n userCode: string;\n /** Where they enter it. */\n verificationUri: string;\n /** The same page with the code filled in — good for a QR code or `open`. */\n verificationUriComplete: string | null;\n expiresIn: number;\n interval: number;\n expiresAt: number;\n resource: string[];\n}\n\n/**\n * Start the device authorization grant: you get a `userCode` to show and a\n * `verificationUri` for the person to open on any device.\n *\n * @throws InvalidClientError, InvalidTargetError, SlowDownError, AgentGrantError.\n */\nexport async function startDeviceAuthorization(options: StartDeviceAuthorizationOptions): Promise<DeviceGrantAuthorization> {\n const now = Date.now();\n const metadata = await resolveMetadata(options);\n const endpoint = requireEndpoint(metadata, 'device_authorization_endpoint', 'the device grant');\n const resource = resourceList(options.resource);\n const body = new URLSearchParams();\n\n if (options.scope !== undefined) {\n body.set('scope', scopeString(options.scope));\n }\n for (const r of resource) {\n body.append('resource', r);\n }\n\n const payload = await postForm(endpoint, body, options, metadata, 'Device authorization request failed');\n const deviceCode = payload['device_code'];\n const userCode = payload['user_code'];\n const verificationUri = payload['verification_uri'];\n\n if (typeof deviceCode !== 'string' || typeof userCode !== 'string' || typeof verificationUri !== 'string') {\n throw new AuthenticationError('The device authorization response was incomplete.');\n }\n\n const expiresIn = positiveNumber(payload['expires_in']) ?? 600;\n\n return {\n deviceCode,\n userCode,\n verificationUri,\n verificationUriComplete: typeof payload['verification_uri_complete'] === 'string' ? payload['verification_uri_complete'] : null,\n expiresIn,\n // RFC 8628 §3.2: absent means 5 seconds.\n interval: positiveNumber(payload['interval']) ?? 5,\n expiresAt: now + expiresIn * 1000,\n resource,\n };\n}\n\nexport interface PollDeviceAuthorizationOptions extends ClientOptions {\n authorization: Pick<DeviceGrantAuthorization, 'deviceCode' | 'resource'>;\n}\n\n/** Poll the token endpoint once for a device authorization. */\nexport async function pollDeviceAuthorization(options: PollDeviceAuthorizationOptions): Promise<PollResult> {\n const body = new URLSearchParams({ grant_type: DEVICE_CODE_GRANT_TYPE, device_code: options.authorization.deviceCode });\n return pollToken(body, options.authorization.resource, options, 'Device token request failed');\n}\n\n/** Poll until the person approves the device code. Same rules as {@link waitForBackchannelToken}. */\nexport async function waitForDeviceToken(\n options: PollDeviceAuthorizationOptions & WaitOptions & { authorization: DeviceGrantAuthorization },\n): Promise<AgentTokens> {\n const metadata = await resolveMetadata(options);\n\n return waitLoop(options.authorization, options, () => pollDeviceAuthorization({ ...options, metadata }), 'device code');\n}\n\n// ---------------------------------------------------------------------------------------\n// Refresh\n// ---------------------------------------------------------------------------------------\n\nexport interface RefreshAgentTokensOptions extends ClientOptions {\n refreshToken: string;\n /** Narrow the scope (never widen it). */\n scope?: string | string[];\n /** RFC 8707 resource indicator(s) for the new access token. */\n resource?: string | string[];\n}\n\n/**\n * Exchange a refresh token, authenticating the same way the grant did (including\n * `private_key_jwt`). Cbox ID rotates refresh tokens and revokes the family on reuse, so\n * ALWAYS persist the returned `refreshToken` and discard the old one.\n *\n * @throws InvalidGrantError when the refresh token is no longer valid — sign in again.\n */\nexport async function refreshAgentTokens(options: RefreshAgentTokensOptions): Promise<AgentTokens> {\n if (!options.refreshToken) {\n throw new ConfigurationError('`refreshToken` is required.');\n }\n\n const body = new URLSearchParams({ grant_type: 'refresh_token', refresh_token: options.refreshToken });\n if (options.scope !== undefined) {\n body.set('scope', scopeString(options.scope));\n }\n\n // `polling: false`: pending and slow_down mean nothing on a refresh, so they are thrown\n // like any other refusal (a 429 as SlowDownError with its Retry-After).\n const result = await pollToken(body, resourceList(options.resource), options, 'Token refresh failed', false);\n\n return (result as Extract<PollResult, { status: 'complete' }>).tokens;\n}\n\n// ---------------------------------------------------------------------------------------\n// Shared\n// ---------------------------------------------------------------------------------------\n\nasync function waitLoop(\n authorization: { interval: number; expiresAt: number },\n options: WaitOptions & { signal?: AbortSignal },\n poll: () => Promise<PollResult>,\n what: string,\n): Promise<AgentTokens> {\n const sleep = options.sleep ?? defaultSleep;\n const now = options.now ?? Date.now;\n let intervalMs = Math.max(authorization.interval, 0) * 1000;\n let nextWaitMs = intervalMs;\n\n for (;;) {\n throwIfAborted(options.signal);\n\n if (now() >= authorization.expiresAt) {\n throw new ExpiredTokenError(`The ${what} expired before it was approved. Start again.`, 'expired_token');\n }\n\n await sleep(nextWaitMs, options.signal);\n // A custom sleep may not honour the signal; check again before spending a request.\n throwIfAborted(options.signal);\n\n if (now() >= authorization.expiresAt) {\n throw new ExpiredTokenError(`The ${what} expired before it was approved. Start again.`, 'expired_token');\n }\n\n const result = await poll();\n\n if (result.status === 'complete') {\n return result.tokens;\n }\n\n if (result.status === 'slow_down') {\n // Permanently, not for one round (RFC 8628 §3.5, CIBA Core §11): returning to the\n // refused rate earns the same answer forever.\n intervalMs += 5000;\n nextWaitMs = Math.max(intervalMs, (result.retryAfter ?? 0) * 1000);\n continue;\n }\n\n nextWaitMs = intervalMs;\n }\n}\n\nasync function pollToken(\n body: URLSearchParams,\n resource: readonly string[],\n options: ClientOptions,\n fallback: string,\n polling = true,\n): Promise<PollResult> {\n const metadata = await resolveMetadata(options);\n const endpoint = requireEndpoint(metadata, 'token_endpoint', 'token requests');\n\n // The same resource(s) the request started with; Cbox ID refuses a mismatch with\n // invalid_target.\n for (const r of resource) {\n body.append('resource', r);\n }\n\n const headers: Record<string, string> = { 'content-type': 'application/x-www-form-urlencoded', accept: 'application/json' };\n await applyClientAuth(options.client, body, headers, metadata.token_endpoint);\n\n const response = await send(endpoint, { method: 'POST', headers, body }, options);\n\n if (response.ok) {\n return { status: 'complete', tokens: await tokensFrom(response) };\n }\n\n const failure = await readOAuthFailure(response);\n\n if (polling && failure.error === 'authorization_pending') {\n return { status: 'pending' };\n }\n if (polling && failure.error === 'slow_down') {\n return { status: 'slow_down', retryAfter: failure.retryAfter ?? null };\n }\n\n throw grantError(failure, fallback);\n}\n\nasync function postForm(\n endpoint: string,\n body: URLSearchParams,\n options: ClientOptions,\n metadata: AuthorizationServerMetadata,\n fallback: string,\n): Promise<Record<string, unknown>> {\n const headers: Record<string, string> = { 'content-type': 'application/x-www-form-urlencoded', accept: 'application/json' };\n await applyClientAuth(options.client, body, headers, metadata.token_endpoint);\n\n const response = await send(endpoint, { method: 'POST', headers, body }, options);\n\n if (!response.ok) {\n throw grantError(await readOAuthFailure(response), fallback);\n }\n\n const payload: unknown = await response.json().catch(() => null);\n if (typeof payload !== 'object' || payload === null) {\n throw new AuthenticationError(`${fallback}: the response was not a JSON object.`);\n }\n return payload as Record<string, unknown>;\n}\n\nasync function tokensFrom(response: Response): Promise<AgentTokens> {\n const raw = (await response.json().catch(() => null)) as Record<string, unknown> | null;\n const accessToken = raw?.['access_token'];\n\n if (raw === null || typeof accessToken !== 'string' || accessToken === '') {\n throw new AuthenticationError('The token response carried no access_token.');\n }\n\n return {\n accessToken,\n tokenType: typeof raw['token_type'] === 'string' ? raw['token_type'] : 'Bearer',\n expiresIn: typeof raw['expires_in'] === 'number' ? raw['expires_in'] : null,\n refreshToken: typeof raw['refresh_token'] === 'string' ? raw['refresh_token'] : null,\n idToken: typeof raw['id_token'] === 'string' ? raw['id_token'] : null,\n scope: typeof raw['scope'] === 'string' ? raw['scope'] : null,\n raw,\n };\n}\n\nfunction resourceList(resource: string | string[] | undefined): string[] {\n if (resource === undefined) {\n return [];\n }\n const list = typeof resource === 'string' ? [resource] : [...resource];\n for (const r of list) {\n // RFC 8707 §2: an absolute URI without a fragment.\n let url: URL;\n try {\n url = new URL(r);\n } catch {\n throw new ConfigurationError(`\\`resource\\` must be an absolute URI (got ${r}).`);\n }\n if (url.hash !== '') {\n throw new ConfigurationError('`resource` must not contain a fragment.');\n }\n }\n return list;\n}\n\nfunction positiveNumber(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null;\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted === true) {\n throw new GrantCancelledError('The wait for approval was cancelled.');\n }\n}\n\n/** An interruptible timer: the abort is wired to the timer, so Ctrl-C does not wait out an interval. */\nfunction defaultSleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted === true) {\n reject(new GrantCancelledError('The wait for approval was cancelled.'));\n return;\n }\n const onAbort = (): void => {\n clearTimeout(timer);\n reject(new GrantCancelledError('The wait for approval was cancelled.'));\n };\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n","import { ConfigurationError } from '../errors.js';\n\n/**\n * Uppercase letters and digits a person cannot confuse when reading them off one screen\n * and matching them on another: no 0/O, 1/I/L, 5/S, 2/Z, 8/B.\n */\nexport const BINDING_CODE_ALPHABET = 'ACDEFGHJKMNPQRTUVWXY34679';\n\n/**\n * A short random code for a CIBA `binding_message`, e.g. `K7QM`.\n *\n * Show it in your terminal and put it in the binding message; Cbox ID shows the message\n * beside Approve, and the person approves only when the two match. That is what stops a\n * prompt somebody else triggered from being approved by reflex. Cbox ID requires a\n * binding message from self-registered clients.\n *\n * Uniform over the alphabet (rejection sampling, WebCrypto randomness).\n */\nexport function createBindingCode(length = 4): string {\n if (!Number.isInteger(length) || length < 1 || length > 32) {\n throw new ConfigurationError('A binding code length must be an integer from 1 to 32.');\n }\n\n const size = BINDING_CODE_ALPHABET.length;\n // The largest multiple of `size` that fits in a byte; bytes at or above it are dropped so\n // every character is equally likely.\n const limit = 256 - (256 % size);\n let code = '';\n\n while (code.length < length) {\n for (const byte of crypto.getRandomValues(new Uint8Array(length * 2))) {\n if (byte < limit && code.length < length) {\n code += BINDING_CODE_ALPHABET[byte % size];\n }\n }\n }\n\n return code;\n}\n"]}
@@ -0,0 +1,400 @@
1
+ import { JWK } from 'jose';
2
+ import { A as AuthenticationError, C as CboxIdError } from './errors-D61xljZE.cjs';
3
+ export { a as ConfigurationError } from './errors-D61xljZE.cjs';
4
+
5
+ /**
6
+ * RFC 8414 authorization server metadata, as Cbox ID publishes it at
7
+ * `{issuer}/.well-known/oauth-authorization-server`. Only the members this module reads are
8
+ * typed; the rest pass through.
9
+ */
10
+ interface AuthorizationServerMetadata {
11
+ issuer: string;
12
+ token_endpoint: string;
13
+ registration_endpoint?: string;
14
+ backchannel_authentication_endpoint?: string;
15
+ device_authorization_endpoint?: string;
16
+ backchannel_token_delivery_modes_supported?: string[];
17
+ backchannel_user_code_parameter_supported?: boolean;
18
+ grant_types_supported?: string[];
19
+ token_endpoint_auth_methods_supported?: string[];
20
+ token_endpoint_auth_signing_alg_values_supported?: string[];
21
+ [member: string]: unknown;
22
+ }
23
+ /** Transport options every call in this module takes. */
24
+ interface AgentRequestOptions {
25
+ /** A `fetch` to use instead of the global one (tests, proxies, instrumentation). */
26
+ fetch?: typeof fetch;
27
+ /** Per-request timeout in milliseconds. Default 10 000. */
28
+ timeoutMs?: number;
29
+ /** Abort the call (and, for the wait helpers, the whole wait). */
30
+ signal?: AbortSignal;
31
+ }
32
+ /** Where to find the server: its issuer, and optionally metadata you already discovered. */
33
+ interface AgentServerOptions extends AgentRequestOptions {
34
+ /** The Cbox ID issuer, e.g. `https://acme.cboxid.com`. Must be https (loopback excepted). */
35
+ issuer: string;
36
+ /**
37
+ * Metadata from {@link discoverAuthorizationServer}. Pass it to skip a discovery round
38
+ * trip per call; omitted, each call discovers it (the wait helpers discover once).
39
+ */
40
+ metadata?: AuthorizationServerMetadata;
41
+ }
42
+ /**
43
+ * Fetch and check the authorization server metadata (RFC 8414).
44
+ *
45
+ * The document's `issuer` must equal the one asked for (§3.3) — otherwise a host answering
46
+ * with another tenant's metadata would receive this client's assertions and codes.
47
+ */
48
+ declare function discoverAuthorizationServer(issuer: string, options?: AgentRequestOptions): Promise<AuthorizationServerMetadata>;
49
+
50
+ /** The client-assertion algorithms this module signs with. Cbox ID accepts both. */
51
+ type ClientKeyAlgorithm = 'ES256' | 'RS256';
52
+ /** A signing key pair for `private_key_jwt`, from {@link generateClientKeyPair}. */
53
+ interface ClientKeyPair {
54
+ alg: ClientKeyAlgorithm;
55
+ /** The RFC 7638 thumbprint of the public key, used as `kid`. */
56
+ kid: string;
57
+ /** The public JWK (with `kid`, `alg`, `use: 'sig'`) — what registration sends in `jwks`. */
58
+ publicJwk: JWK;
59
+ /**
60
+ * The private JWK. PERSIST THIS, and only this, somewhere the user alone can read
61
+ * (mode 0600, the OS keychain). It is the client's credential: whoever holds it is the
62
+ * client. Never log it, never commit it.
63
+ */
64
+ privateJwk: JWK;
65
+ /** The private key as a WebCrypto `CryptoKey`, ready to sign with. */
66
+ privateKey: CryptoKey;
67
+ }
68
+ /**
69
+ * How the client authenticates at the backchannel, device and token endpoints.
70
+ *
71
+ * - `private_key_jwt` (RFC 7523): a short-lived assertion signed with your private key.
72
+ * The right choice for a self-registered agent or CLI: nothing secret ever crosses the
73
+ * wire, and the server stores only the public key.
74
+ * - `client_secret_basic` / `client_secret_post`: a console-issued secret.
75
+ * - `none`: a public client names itself by `client_id` only. Fine for the device grant.
76
+ * For CIBA, Cbox ID accepts a keyless self-registered client only when the resource
77
+ * allows it (`dynamic_public_backchannel`); otherwise the answer is `invalid_target`.
78
+ * Prefer `private_key_jwt` for CIBA: a public `client_id` proves nothing, and CIBA has no front
79
+ * channel to bind the flow to.
80
+ */
81
+ type ClientAuth = {
82
+ method: 'private_key_jwt';
83
+ clientId: string;
84
+ /** A `CryptoKey`, or the private JWK you persisted from {@link generateClientKeyPair}. */
85
+ privateKey: CryptoKey | JWK;
86
+ /** Inferred from the key when omitted. */
87
+ alg?: ClientKeyAlgorithm;
88
+ /** Sent as the assertion's `kid`. Taken from a JWK's own `kid` when omitted. */
89
+ kid?: string;
90
+ } | {
91
+ method: 'client_secret_basic' | 'client_secret_post';
92
+ clientId: string;
93
+ clientSecret: string;
94
+ } | {
95
+ method: 'none';
96
+ clientId: string;
97
+ };
98
+ /**
99
+ * A fresh signing key pair for `private_key_jwt`, generated with WebCrypto (via `jose`), so
100
+ * it runs on Node, Deno, Bun and edge runtimes. ES256 by default — small keys, small
101
+ * signatures. The private key is extractable on purpose: the caller must persist it.
102
+ */
103
+ declare function generateClientKeyPair(alg?: ClientKeyAlgorithm): Promise<ClientKeyPair>;
104
+ /**
105
+ * A signed RFC 7523 client assertion: `iss` = `sub` = client id, `aud` = the token
106
+ * endpoint, a random `jti` (the server remembers it, so each assertion is single-use),
107
+ * `iat` now and `exp` at most 60 seconds later.
108
+ */
109
+ declare function createClientAssertion(auth: Extract<ClientAuth, {
110
+ method: 'private_key_jwt';
111
+ }>, audience: string, options?: {
112
+ now?: () => number;
113
+ lifetimeSeconds?: number;
114
+ }): Promise<string>;
115
+
116
+ /** The CIBA grant type (OpenID CIBA Core). */
117
+ declare const CIBA_GRANT_TYPE = "urn:openid:params:grant-type:ciba";
118
+ /** The device authorization grant type (RFC 8628). */
119
+ declare const DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
120
+ interface RegisterAgentClientOptions extends AgentServerOptions {
121
+ /** Shown to the person approving, so make it recognisable: "Cbox Brain CLI on ada-mbp". */
122
+ clientName: string;
123
+ /** e.g. `[CIBA_GRANT_TYPE, 'refresh_token']` or `[DEVICE_CODE_GRANT_TYPE, 'refresh_token']`. */
124
+ grantTypes: string[];
125
+ /** The scope ceiling to register. A space-separated string or a list. */
126
+ scope?: string | string[];
127
+ /**
128
+ * `private_key_jwt` (default): a key pair is generated (or `keyPair` used) and the
129
+ * public half registered inline as `jwks`. `none`: a public client — the device grant,
130
+ * or CIBA where the resource allows keyless clients. `private_key_jwt` is recommended for CIBA.
131
+ */
132
+ tokenEndpointAuthMethod?: 'private_key_jwt' | 'none';
133
+ /** Algorithm for the generated key pair. Default ES256. */
134
+ alg?: ClientKeyAlgorithm;
135
+ /** Register an existing key pair instead of generating one. */
136
+ keyPair?: ClientKeyPair;
137
+ /** RFC 7591 §3 initial access token, when the instance requires one to register. */
138
+ initialAccessToken?: string;
139
+ /** Further RFC 7591 client metadata, sent as-is (e.g. `software_id`, `client_uri`). */
140
+ extraMetadata?: Record<string, unknown>;
141
+ }
142
+ interface RegisteredAgentClient {
143
+ clientId: string;
144
+ /** Present only if the server issued one; a `private_key_jwt` or `none` client has none. */
145
+ clientSecret: string | null;
146
+ /** RFC 7592 credential for reading/updating/deleting the registration. Persist it if you need that. */
147
+ registrationAccessToken: string | null;
148
+ registrationClientUri: string | null;
149
+ tokenEndpointAuthMethod: string;
150
+ grantTypes: string[];
151
+ scope: string | null;
152
+ /** The key pair registered, for `private_key_jwt`. Persist `keyPair.privateJwk`. */
153
+ keyPair: ClientKeyPair | null;
154
+ /** Ready to hand to {@link startBackchannel} / {@link startDeviceAuthorization}. */
155
+ auth: ClientAuth;
156
+ /** The full registration response. */
157
+ raw: Record<string, unknown>;
158
+ }
159
+ /**
160
+ * Register this agent or CLI as an OAuth client (RFC 7591 dynamic client registration).
161
+ *
162
+ * Do it once per installation and persist the result: `clientId` and, for
163
+ * `private_key_jwt`, `keyPair.privateJwk`. Re-registering on every run fills the
164
+ * environment's app list with copies.
165
+ *
166
+ * @throws ConfigurationError when the instance has dynamic registration switched off.
167
+ * @throws AgentGrantError (e.g. `invalid_client_metadata`) when the server refuses.
168
+ */
169
+ declare function registerAgentClient(options: RegisterAgentClientOptions): Promise<RegisteredAgentClient>;
170
+
171
+ /** Tokens from a completed CIBA or device grant. */
172
+ interface AgentTokens {
173
+ accessToken: string;
174
+ tokenType: string;
175
+ /** Seconds, when the server said. */
176
+ expiresIn: number | null;
177
+ refreshToken: string | null;
178
+ /**
179
+ * The id_token, when `openid` was granted — returned as-is, NOT verified here. Verify it
180
+ * with `CboxIdClient` (or `jose` against the JWKS) before trusting anything in it.
181
+ */
182
+ idToken: string | null;
183
+ scope: string | null;
184
+ /** The full token response. */
185
+ raw: Record<string, unknown>;
186
+ }
187
+ /** One poll's outcome. Final failures are thrown, not returned. */
188
+ type PollResult = {
189
+ status: 'complete';
190
+ tokens: AgentTokens;
191
+ } | {
192
+ status: 'pending';
193
+ }
194
+ /** Slow down: add 5 s to the interval, and wait at least `retryAfter` seconds if given. */
195
+ | {
196
+ status: 'slow_down';
197
+ retryAfter: number | null;
198
+ };
199
+ /** Options shared by the wait helpers. */
200
+ interface WaitOptions {
201
+ /** Replace the timer — tests pass a fake that records the waits. Must honour `signal`. */
202
+ sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
203
+ /** Clock in epoch milliseconds. Default `Date.now`. */
204
+ now?: () => number;
205
+ }
206
+ interface ClientOptions extends AgentServerOptions {
207
+ /** How the client authenticates. See {@link ClientAuth}. */
208
+ client: ClientAuth;
209
+ }
210
+ interface StartBackchannelOptions extends ClientOptions {
211
+ /** Who should approve: a Cbox ID user id, or a confirmed email address. */
212
+ loginHint: string;
213
+ /** Space-separated string or list. Bounded by the client's registered scopes. */
214
+ scope: string | string[];
215
+ /**
216
+ * Shown beside Approve. Put a {@link createBindingCode} code in it and print the same
217
+ * code locally. Required by Cbox ID for self-registered clients; at most 255 characters.
218
+ */
219
+ bindingMessage: string;
220
+ /**
221
+ * RFC 8707 resource indicator(s) — the API the token is for. Optional in the type, but
222
+ * REQUIRED by Cbox ID for self-registered clients.
223
+ * Its settings also decide whether a keyless (`none`) client may use CIBA at all.
224
+ */
225
+ resource?: string | string[];
226
+ /** Seconds the request may wait for approval (the server may shorten it). */
227
+ requestedExpiry?: number;
228
+ /** Echoed into the id_token, so you can bind it to this request. */
229
+ nonce?: string;
230
+ }
231
+ /** A started CIBA request. Persistable as JSON. */
232
+ interface BackchannelAuthorization {
233
+ authReqId: string;
234
+ expiresIn: number;
235
+ /** Seconds between polls. */
236
+ interval: number;
237
+ /** Epoch ms after which polling is pointless. */
238
+ expiresAt: number;
239
+ /** The resource(s) the request named, re-sent on every poll (the server checks they match). */
240
+ resource: string[];
241
+ }
242
+ /**
243
+ * Start a CIBA request (OpenID CIBA Core §7, poll mode): Cbox ID shows `bindingMessage` to
244
+ * the person named by `loginHint` and waits for Approve.
245
+ *
246
+ * `backchannel_user_code_parameter` is not supported by Cbox ID, so no user code is sent.
247
+ *
248
+ * @throws InvalidClientError, UnknownUserIdError, InvalidBindingMessageError,
249
+ * InvalidTargetError, SlowDownError, AgentGrantError.
250
+ */
251
+ declare function startBackchannel(options: StartBackchannelOptions): Promise<BackchannelAuthorization>;
252
+ interface PollBackchannelOptions extends ClientOptions {
253
+ authorization: Pick<BackchannelAuthorization, 'authReqId' | 'resource'>;
254
+ }
255
+ /**
256
+ * Poll the token endpoint once for a CIBA request.
257
+ *
258
+ * @throws AccessDeniedError, ExpiredTokenError, InvalidGrantError, InvalidTargetError,
259
+ * InvalidClientError, AgentGrantError.
260
+ */
261
+ declare function pollBackchannel(options: PollBackchannelOptions): Promise<PollResult>;
262
+ /**
263
+ * Poll until the person approves, and return the tokens.
264
+ *
265
+ * Waits `interval` seconds before each poll; on `slow_down` (or a 429) adds five seconds
266
+ * for good and waits at least `Retry-After`; keeps going on `authorization_pending`; stops
267
+ * on anything final. Throws {@link ExpiredTokenError} once `expiresAt` passes and
268
+ * {@link GrantCancelledError} when `signal` fires — wire it to Ctrl-C.
269
+ */
270
+ declare function waitForBackchannelToken(options: PollBackchannelOptions & WaitOptions & {
271
+ authorization: BackchannelAuthorization;
272
+ }): Promise<AgentTokens>;
273
+ interface StartDeviceAuthorizationOptions extends ClientOptions {
274
+ scope?: string | string[];
275
+ /** RFC 8707 resource indicator(s). */
276
+ resource?: string | string[];
277
+ }
278
+ /** A started device authorization. Persistable as JSON. */
279
+ interface DeviceGrantAuthorization {
280
+ deviceCode: string;
281
+ /** Show this to the person. */
282
+ userCode: string;
283
+ /** Where they enter it. */
284
+ verificationUri: string;
285
+ /** The same page with the code filled in — good for a QR code or `open`. */
286
+ verificationUriComplete: string | null;
287
+ expiresIn: number;
288
+ interval: number;
289
+ expiresAt: number;
290
+ resource: string[];
291
+ }
292
+ /**
293
+ * Start the device authorization grant: you get a `userCode` to show and a
294
+ * `verificationUri` for the person to open on any device.
295
+ *
296
+ * @throws InvalidClientError, InvalidTargetError, SlowDownError, AgentGrantError.
297
+ */
298
+ declare function startDeviceAuthorization(options: StartDeviceAuthorizationOptions): Promise<DeviceGrantAuthorization>;
299
+ interface PollDeviceAuthorizationOptions extends ClientOptions {
300
+ authorization: Pick<DeviceGrantAuthorization, 'deviceCode' | 'resource'>;
301
+ }
302
+ /** Poll the token endpoint once for a device authorization. */
303
+ declare function pollDeviceAuthorization(options: PollDeviceAuthorizationOptions): Promise<PollResult>;
304
+ /** Poll until the person approves the device code. Same rules as {@link waitForBackchannelToken}. */
305
+ declare function waitForDeviceToken(options: PollDeviceAuthorizationOptions & WaitOptions & {
306
+ authorization: DeviceGrantAuthorization;
307
+ }): Promise<AgentTokens>;
308
+ interface RefreshAgentTokensOptions extends ClientOptions {
309
+ refreshToken: string;
310
+ /** Narrow the scope (never widen it). */
311
+ scope?: string | string[];
312
+ /** RFC 8707 resource indicator(s) for the new access token. */
313
+ resource?: string | string[];
314
+ }
315
+ /**
316
+ * Exchange a refresh token, authenticating the same way the grant did (including
317
+ * `private_key_jwt`). Cbox ID rotates refresh tokens and revokes the family on reuse, so
318
+ * ALWAYS persist the returned `refreshToken` and discard the old one.
319
+ *
320
+ * @throws InvalidGrantError when the refresh token is no longer valid — sign in again.
321
+ */
322
+ declare function refreshAgentTokens(options: RefreshAgentTokensOptions): Promise<AgentTokens>;
323
+
324
+ /**
325
+ * Uppercase letters and digits a person cannot confuse when reading them off one screen
326
+ * and matching them on another: no 0/O, 1/I/L, 5/S, 2/Z, 8/B.
327
+ */
328
+ declare const BINDING_CODE_ALPHABET = "ACDEFGHJKMNPQRTUVWXY34679";
329
+ /**
330
+ * A short random code for a CIBA `binding_message`, e.g. `K7QM`.
331
+ *
332
+ * Show it in your terminal and put it in the binding message; Cbox ID shows the message
333
+ * beside Approve, and the person approves only when the two match. That is what stops a
334
+ * prompt somebody else triggered from being approved by reflex. Cbox ID requires a
335
+ * binding message from self-registered clients.
336
+ *
337
+ * Uniform over the alphabet (rejection sampling, WebCrypto randomness).
338
+ */
339
+ declare function createBindingCode(length?: number): string;
340
+
341
+ /**
342
+ * A CIBA, device-grant or registration request was refused with an OAuth error.
343
+ *
344
+ * Extends {@link AuthenticationError}, so `error`, `errorDescription`, `status` and
345
+ * `retryAfter` read the same as on every other back-channel failure in this SDK, and a
346
+ * caller already catching `AuthenticationError` keeps working. Branch on the subclass (or
347
+ * on `error`), never on the message.
348
+ *
349
+ * The REQUEST is never part of the error: these calls carry client assertions, secrets and
350
+ * device codes, and production CLIs log what they throw.
351
+ */
352
+ declare class AgentGrantError extends AuthenticationError {
353
+ }
354
+ /** The person declined (`access_denied`). Final — do not poll again. */
355
+ declare class AccessDeniedError extends AgentGrantError {
356
+ }
357
+ /**
358
+ * The `auth_req_id` or `device_code` expired before anyone approved it (`expired_token`).
359
+ * Also thrown locally when the wait outlives the request's `expires_in`. Start again.
360
+ */
361
+ declare class ExpiredTokenError extends AgentGrantError {
362
+ }
363
+ /** The `auth_req_id`, `device_code` or refresh token is not valid (`invalid_grant`). */
364
+ declare class InvalidGrantError extends AgentGrantError {
365
+ }
366
+ /**
367
+ * The `resource` (RFC 8707) is not one this client may ask for, the poll named a
368
+ * different resource than the request that started it, or the resource lets
369
+ * self-registered clients use CIBA only with `private_key_jwt` and this one is keyless
370
+ * (`invalid_target`).
371
+ */
372
+ declare class InvalidTargetError extends AgentGrantError {
373
+ }
374
+ /**
375
+ * Client authentication failed (`invalid_client`): an unknown `client_id`, a bad secret, an
376
+ * assertion signed by a key the server does not hold, or a replayed `jti`.
377
+ */
378
+ declare class InvalidClientError extends AgentGrantError {
379
+ }
380
+ /** The `login_hint` names nobody the server can reach (`unknown_user_id`). */
381
+ declare class UnknownUserIdError extends AgentGrantError {
382
+ }
383
+ /**
384
+ * The `binding_message` is missing where the server requires one (self-registered clients),
385
+ * or too long to show beside Approve (`invalid_binding_message`).
386
+ */
387
+ declare class InvalidBindingMessageError extends AgentGrantError {
388
+ }
389
+ /**
390
+ * The server asked us to slow down (`slow_down`, or HTTP 429). `retryAfter` carries the
391
+ * `Retry-After` seconds when the server sent them. The wait helpers absorb this themselves;
392
+ * it is thrown only from a call that does not loop (registration, starting a flow).
393
+ */
394
+ declare class SlowDownError extends AgentGrantError {
395
+ }
396
+ /** The caller aborted the wait (its `AbortSignal` fired). */
397
+ declare class GrantCancelledError extends CboxIdError {
398
+ }
399
+
400
+ export { AccessDeniedError, AgentGrantError, type AgentRequestOptions, type AgentServerOptions, type AgentTokens, AuthenticationError, type AuthorizationServerMetadata, BINDING_CODE_ALPHABET, type BackchannelAuthorization, CIBA_GRANT_TYPE, CboxIdError, type ClientAuth, type ClientKeyAlgorithm, type ClientKeyPair, DEVICE_CODE_GRANT_TYPE, type DeviceGrantAuthorization, ExpiredTokenError, GrantCancelledError, InvalidBindingMessageError, InvalidClientError, InvalidGrantError, InvalidTargetError, type PollBackchannelOptions, type PollDeviceAuthorizationOptions, type PollResult, type RefreshAgentTokensOptions, type RegisterAgentClientOptions, type RegisteredAgentClient, SlowDownError, type StartBackchannelOptions, type StartDeviceAuthorizationOptions, UnknownUserIdError, type WaitOptions, createBindingCode, createClientAssertion, discoverAuthorizationServer, generateClientKeyPair, pollBackchannel, pollDeviceAuthorization, refreshAgentTokens, registerAgentClient, startBackchannel, startDeviceAuthorization, waitForBackchannelToken, waitForDeviceToken };