import { sealedBoxKeyPair, sealedBoxOpen } from './sealed-box.js'; type Row = Record; export type Jwk = { kty: 'RSA'; use: 'sig'; alg: 'RS256'; kid: string; n: string; e: string; } | { kty: 'OKP'; use: 'sig'; alg: 'EdDSA'; crv: 'Ed25519'; kid: string; x: string; }; export type Jwks = { keys: Jwk[]; }; /** A signing key: an RSA or Ed25519 private key as a PEM (its public half, given or derived, is what a JWKS serves and * names by `kid`), or a shared secret. Only deterministic algorithms: an ECDSA signature is random, so a World signs * none; Ed25519's is deterministic (RFC 8032), Better Auth's default (`EdDSA`). */ export type SigningKey = { alg: 'RS256' | 'RS384' | 'RS512' | 'EdDSA'; privatePem: string; publicPem?: string; } | { alg: 'HS256' | 'HS384' | 'HS512'; secret: string; }; /** The algorithms `jwtSign` signs with. */ export declare const SIGNING_ALGORITHMS: ReadonlyArray; /** A token check's result, with its payload on success. `jwtVerify` checks time as well as the signature. */ export type JwtVerdict = { valid: boolean; payload?: Row; reason?: 'malformed' | 'unexpected_alg' | 'no_matching_key' | 'bad_signature' | 'expired' | 'not_yet_valid'; }; export type JwtVerificationKey = Jwks | { alg: 'HS256' | 'HS384' | 'HS512'; secret: string; }; export type JwtDecodeOptions = { strict?: boolean; integers?: 'exact' | 'number'; }; export type JwtSignatureOptions = JwtDecodeOptions & { hmacSignature?: 'canonical' | 'bytes'; }; /** A public key's id: a prefix and the first 16 hex of SHA-256 over its DER (what its JWKS and every token name). */ export declare function keyId(publicPem: string, prefix?: string): string; /** A JWT: `iat` and `nbf` are `now` (seconds), `exp` `now` plus the lifetime (60 s when none is given), unless the * claims name their own. `now` defaults to the receiver's clock (`receiverNow()`: the World's where the app reads it, * else the machine's), which a token's receiver checks those claims against (ADR 0036 §4). A token of a key pair * carries the key's `kid`. */ export declare function jwtSign(claims: Row, key: SigningKey, opts?: { now?: number; expiresInSeconds?: number; kidPrefix?: string; kid?: string; typ?: string; }): string; /** A JWT over exactly the supplied claims, without adding temporal claims. The caller owns their policy. A key's `kid` * is its thumbprint unless `kid` names the one a client's token carries as authored. */ export declare function jwtSignClaims(claims: Row, key: SigningKey, opts?: { kidPrefix?: string; kid?: string; typ?: string; }): string; /** A JWT's header and payload, unverified. Strict compact framing and ordinary JSON numbers are explicit * protocol policies; existing kernel callers retain permissive decoding and exact integer values. */ export declare function jwtDecode(token: string, opts?: JwtDecodeOptions): { header: Row; payload: Row; }; /** A token checked: an RS256 or EdDSA one against a JWKS (its `kid`'s key), an HS256 one against its secret (constant time), * then its `exp`/`nbf` at `now` (seconds; the receiver's clock, `receiverNow()`, by default, the clock `jwtSign` stamps on). */ export declare function jwtVerify(token: string, key: JwtVerificationKey, opts?: { now?: number; }): JwtVerdict; /** A token's signature checked without an `exp`/`nbf` policy. An issuer selector sees unverified claims and may * enforce its vendor's claim shape and key ownership before returning a key. HMAC signatures use canonical * text by default; a protocol that compares decoded bytes selects that existing wire policy explicitly. */ export declare function jwtVerifySignature(token: string, key: JwtVerificationKey | ((decoded: { header: Row; payload: Row; }) => JwtVerificationKey), opts?: JwtSignatureOptions): JwtVerdict; /** The JWKS that verifies every token a public key's pair signs. */ export declare function jwks(publicPem: string, kidPrefix?: string): Jwks; /** An HMAC of a value, hex or base64 (a webhook's signature, a signed id): SHA-256 unless the vendor names another * (OAuth 1.0a's HMAC-SHA1). The secret is its text, or its bytes where the vendor keys with a decoded secret (Svix's * `whsec_` base64). */ export declare const hmac: (secret: string | Uint8Array, value: string | Uint8Array, encoding?: "hex" | "base64" | "base64url", algorithm?: "sha1" | "sha256" | "sha512") => string; /** A SHA-256, hex (a key stored by its hash, a deterministic id). */ export declare const sha256: (value: string) => string; /** A digest of a value in the algorithm and encoding a vendor names (GoTrue's SHA-224 token hashes, a PKCE challenge's * base64url SHA-256). */ export declare function digest(algorithm: 'md5' | 'sha1' | 'sha224' | 'sha256' | 'sha384' | 'sha512', value: string | Uint8Array, encoding?: 'hex' | 'base64' | 'base64url'): string; /** RFC 3986 percent-encoding as RFC 5849 §3.6 uses it (unreserved: A-Z a-z 0-9 - . _ ~). */ export declare const oauth1Encode: (s: string) => string; /** The `Authorization: OAuth k="v", …` header's parameters, decoded, in order; undefined when it is not one. */ export declare function oauth1Header(value: string | null | undefined): Array<[string, string]> | undefined; /** The signature base string (RFC 5849 §3.4.1): the method, the base URL (no query) and the parameters signed, each * percent-encoded and sorted by name and value. */ export declare function oauth1BaseString(method: string, baseUrl: string, pairs: ReadonlyArray): string; /** The HMAC-SHA1 signature (RFC 5849 §3.4.2) over a base string, keyed by the consumer secret and the token secret. */ export declare const oauth1Signature: (base: string, consumerSecret: string, tokenSecret?: string) => string; /** A digest of a value as its bytes (a key or an id drawn from a hash's bytes, a deterministic embedding). */ export declare function digestBytes(algorithm: 'md5' | 'sha1' | 'sha224' | 'sha256' | 'sha384' | 'sha512', value: string | Uint8Array): Uint8Array; /** An MD5, hex (an object's ETag, as S3 and storage APIs give it); never a secret's protection. */ export declare const md5: (value: string | Uint8Array) => string; /** A version-4-shaped UUID derived from `seed`: the same seed gives the same id every run (R9). */ export declare function uuidFrom(seed: string): string; /** `count` lowercase letters derived from `seed` (a 20-letter project ref, a slug's suffix), the same every run (every * byte taken, as the ids already minted from it were). */ export declare function lettersFrom(seed: string, count?: number): string; /** `count` base62 characters (0-9A-Za-z) derived from `seed`, the same every run: the opaque tail of an id a vendor * writes in base62 (OpenAI's `call_unLAR8MvFNptuiZK6K6HCy5k`, 24 after its prefix). */ export declare function base62From(seed: string, count?: number): string; /** A key's or an id's shape as the vendor writes it: `prefix`, a body of `alphabet` characters (`base62`, `hex` * lowercase, `base64url`, `digits`, `letters` lowercase, or the characters of a string given), `suffix`; `length` is the * whole value's, prefix and suffix included (Anthropic's `sk-ant-api03-…AA`, 108; Stripe's `sk_test_51…`; OpenAI's * `sk-proj-…`; a KSUID's 27 base62; a snowflake's digits after a nonzero prefix digit). `'uuid'` is a version-4 UUID. */ export type KeyFormat = { prefix?: string; length: number; alphabet: 'base62' | 'hex' | 'base64url' | 'digits' | 'letters' | (string & {}); suffix?: string; } | 'uuid'; /** A key in `format` drawn from HMAC-SHA256(`secret`, `label`): the same secret and label give the same key, and no one * without the secret can compute it. Each body character is an unbiased draw (a byte past the alphabet's last whole * multiple is skipped). */ export declare function keyFrom(secret: string, label: string, format: KeyFormat): string; /** Two strings compared in constant time. */ export declare function equalSecrets(a: string, b: string): boolean; /** Bytes signed with a private key (RSA with SHA-256, or Ed25519), in the encoding asked: a certificate's signature, * a transparency log's checkpoint. */ export declare function signWith(privatePem: string, data: string | Uint8Array, encoding?: 'base64' | 'hex' | 'base64url'): string; /** Whether a signature holds over bytes under a public key or a certificate's (PEM, or a certificate's DER): any * scheme a vendor uses (ECDSA, RSA, Ed25519), since verifying draws nothing. The digest is SHA-256 unless named. */ export declare function verifyWith(publicKey: string | Uint8Array, data: string | Uint8Array, signature: string | Uint8Array, opts?: { digest?: 'sha256' | 'sha384' | 'sha512'; encoding?: 'base64' | 'hex'; }): boolean; /** A public key's PEM and its DER (SubjectPublicKeyInfo), from a public or private key's PEM or a certificate. */ export declare function publicKeyOf(key: string): { pem: string; der: Uint8Array; }; /** An X.509 certificate read (PEM or DER): its bytes, names, validity and key, and whether an issuer's key signed it; * undefined when it is not one. */ export declare function certificateOf(cert: string | Uint8Array): { der: Uint8Array; subject: string; issuer: string; subjectAltName: string | undefined; notBefore: string; notAfter: string; publicKey: { pem: string; der: Uint8Array; }; issuedBy(issuer: string | Uint8Array): boolean; } | undefined; /** What a handler signs and hashes with: `ctx.crypto`. */ export declare const handlerCrypto: { readonly jwtSign: typeof jwtSign; readonly jwtSignClaims: typeof jwtSignClaims; readonly jwtVerify: typeof jwtVerify; readonly jwtVerifySignature: typeof jwtVerifySignature; readonly jwtDecode: typeof jwtDecode; readonly jwks: typeof jwks; readonly keyId: typeof keyId; readonly hmac: (secret: string | Uint8Array, value: string | Uint8Array, encoding?: "hex" | "base64" | "base64url", algorithm?: "sha1" | "sha256" | "sha512") => string; readonly sha256: (value: string) => string; readonly md5: (value: string | Uint8Array) => string; readonly digest: typeof digest; readonly uuidFrom: typeof uuidFrom; readonly lettersFrom: typeof lettersFrom; readonly base62From: typeof base62From; readonly equalSecrets: typeof equalSecrets; readonly sealedBoxKeyPair: typeof sealedBoxKeyPair; readonly sealedBoxOpen: typeof sealedBoxOpen; readonly signWith: typeof signWith; readonly verifyWith: typeof verifyWith; readonly publicKeyOf: typeof publicKeyOf; readonly certificateOf: typeof certificateOf; }; export type HandlerCrypto = typeof handlerCrypto; /** A [KSUID](https://github.com/segmentio/ksuid) as 27 base62 characters (0-9A-Za-z, most significant first): `seconds` * past KSUID's epoch (1400000000) in four bytes, then `n` in four, then twelve bytes derived from `seed`, so KSUIDs * made in one second sort by `n`, at `width` characters (27 unless a vendor's id is longer or shorter). Deterministic: * the same arguments give the same id. */ export declare function ksuidFrom(seconds: number, n: number, seed: string, width?: number): string; export {};