import * as Context from "../Context.ts"; import type * as Duration from "../Duration.ts"; import * as Effect from "../Effect.ts"; import * as HttpClient from "../http/HttpClient.ts"; import * as Layer from "../Layer.ts"; import * as Schema from "../Schema.ts"; import type * as Scope from "../Scope.ts"; import * as JoseError from "./JoseError.ts"; import { type AsymmetricAlgorithm, type PublicKey } from "./Jwk.ts"; import type * as Jws from "./Jws.ts"; /** * Schema for a set of public JWKs. * * **Details** * * Keys of other families or curves are kept but never selected. Private or * symmetric members anywhere in the set fail decoding. * * @stability unstable * @category schemas * @since 4.1.1 */ export declare const KeySet: Schema.Struct<{ readonly keys: Schema.$Array; readonly p: Schema.optionalKey; readonly q: Schema.optionalKey; readonly dp: Schema.optionalKey; readonly dq: Schema.optionalKey; readonly qi: Schema.optionalKey; readonly oth: Schema.optionalKey; readonly k: Schema.optionalKey; readonly kid: Schema.optionalKey; readonly alg: Schema.optionalKey; readonly use: Schema.optionalKey; readonly key_ops: Schema.optionalKey>; readonly kty: Schema.Literal<"RSA">; readonly n: Schema.String; readonly e: Schema.String; }>, Schema.Struct<{ readonly d: Schema.optionalKey; readonly p: Schema.optionalKey; readonly q: Schema.optionalKey; readonly dp: Schema.optionalKey; readonly dq: Schema.optionalKey; readonly qi: Schema.optionalKey; readonly oth: Schema.optionalKey; readonly k: Schema.optionalKey; readonly kid: Schema.optionalKey; readonly alg: Schema.optionalKey; readonly use: Schema.optionalKey; readonly key_ops: Schema.optionalKey>; readonly kty: Schema.Literal<"EC">; readonly crv: Schema.Literals; readonly x: Schema.String; readonly y: Schema.String; }>, Schema.Struct<{ readonly d: Schema.optionalKey; readonly p: Schema.optionalKey; readonly q: Schema.optionalKey; readonly dp: Schema.optionalKey; readonly dq: Schema.optionalKey; readonly qi: Schema.optionalKey; readonly oth: Schema.optionalKey; readonly k: Schema.optionalKey; readonly kid: Schema.optionalKey; readonly alg: Schema.optionalKey; readonly use: Schema.optionalKey; readonly key_ops: Schema.optionalKey>; readonly kty: Schema.Literal<"OKP">; readonly crv: Schema.Literal<"Ed25519">; readonly x: Schema.String; }>]>, Schema.StructWithRest; readonly p: Schema.optionalKey; readonly q: Schema.optionalKey; readonly dp: Schema.optionalKey; readonly dq: Schema.optionalKey; readonly qi: Schema.optionalKey; readonly oth: Schema.optionalKey; readonly k: Schema.optionalKey; readonly kty: Schema.String; readonly crv: Schema.optionalKey; }>, readonly [Schema.$Record]>]>>; }>; /** * A set of public JWKs. * * @stability unstable * @category models * @since 4.1.1 */ export type KeySet = typeof KeySet.Type; /** * The algorithm, and optionally the key id, of the key to resolve. * * @stability unstable * @category models * @since 4.1.1 */ export interface Selection { readonly algorithm: AsymmetricAlgorithm; readonly kid?: string | undefined; /** * The unauthenticated header when resolving a token's key. Use it only for * key selection; it is authenticated only after verification succeeds. */ readonly protectedHeader?: Jws.ProtectedHeader | undefined; } declare const Jwks_base: Context.ServiceClass Effect.Effect; }>; /** * Service that resolves the verification key for a selection. * * @stability unstable * @category services * @since 4.1.1 */ export declare class Jwks extends Jwks_base { } /** * Builds a `Jwks` service for a fixed key set. * * **Example** (Resolving a key by `kid`) * * ```ts import.meta.vitest * import { Effect, Layer } from "effect" * import { SecureRandom, Signature } from "effect/crypto" * import { Jwk, Jwks } from "effect/jose" * * const layer = Signature.layerWebCrypto.pipe(Layer.provide(SecureRandom.layerWebCrypto)) * * const kid = await Effect.runPromise(Effect.gen(function*() { * const pair = yield* Jwk.generateKeyPair({ algorithm: "ES256", kid: "signing-1" }) * const jwks = yield* Jwks.makeLocal({ keys: [pair.publicKey] }) * const key = yield* jwks.resolve({ algorithm: "ES256", kid: "signing-1" }) * return key.kid * }).pipe(Effect.provide(layer))) * kid // => "signing-1" * ``` * * @stability unstable * @category constructors * @since 4.1.1 */ export declare const makeLocal: (keySet: KeySet) => Effect.Effect; /** * Layer that provides `Jwks` for a fixed key set. * * @stability unstable * @category layers * @since 4.1.1 */ export declare const layerLocal: (keySet: KeySet) => Layer.Layer; /** * Options for {@link makeRemote} and {@link layerRemote}. * * @stability unstable * @category models * @since 4.1.1 */ export interface RemoteOptions { /** * The HTTPS key-set URL, without credentials or a fragment. Take it from * configuration, never from a token. */ readonly url: string; /** * How long a fetched key set is used. Defaults to 10 minutes. */ readonly timeToLive?: Duration.Input | undefined; /** * Minimum time before retrying after a failed fetch, or refetching for an * unknown key. Defaults to 30 seconds. */ readonly cooldown?: Duration.Input | undefined; /** * Timeout for the request and reading its body. Defaults to 5 seconds. */ readonly timeout?: Duration.Input | undefined; /** * Maximum response body size. Defaults to 131072 bytes. */ readonly maxResponseBytes?: number | undefined; /** * Maximum number of keys in the set. Defaults to 64. */ readonly maxKeys?: number | undefined; } /** * Builds a `Jwks` service for a remote key set, using the `HttpClient` * service. Use it when the URL is only known at runtime, for example from * OpenID Connect discovery. * * **Details** * * The key set is fetched on first use and reused until `timeToLive` passes. * Concurrent callers share one request. A selection that finds no key fetches * the set again, at most once per `cooldown`, so rotated keys are picked up * without letting unknown `kid`s drive a request per token. A failed fetch * fails every caller until `cooldown` passes; there is no fallback to an * expired set. * * Only a 200 response from the configured URL is accepted, so a redirected * key set is rejected. The check runs on the response, so it cannot stop a * client from sending the redirected request. * * **Gotchas** * * Supply a client that does not follow redirects. `FetchHttpClient` follows * them by default: provide `FetchHttpClient.RequestInit` with * `{ redirect: "manual" }` on its layer so a redirect fails before any further * request. Clients wrapped with `HttpClient.followRedirects` also follow them. * * Closing the scope interrupts any request in flight, and later resolutions * fail with `KeySetUnavailable`. * * @stability unstable * @category constructors * @since 4.1.1 */ export declare const makeRemote: (options: RemoteOptions) => Effect.Effect<{ readonly resolve: (selection: Selection) => Effect.Effect; }, JoseError.JoseError, HttpClient.HttpClient | Scope.Scope>; /** * Layer that provides `Jwks` from a remote key set built by {@link makeRemote}. * Closing the layer interrupts any request in flight. * * @stability unstable * @category layers * @since 4.1.1 */ export declare const layerRemote: (options: RemoteOptions) => Layer.Layer; export {}; //# sourceMappingURL=Jwks.d.ts.map