import type { FileStorage } from "@mjackson/file-storage"; import * as jose from "jose"; export declare namespace JWK { /** * The possible algorithms for the JWK. * * - `ES256`: Used for signing keys based on ECDSA with the P-256 curve. * - `RSA_OAEP_512`: Used for RSA-based encryption with OAEP padding. */ enum Algoritm { ES256 = "ES256", RSA_OAEP_512 = "RSA-OAEP-512" } interface KeyPair { id: string; alg: Algoritm; public: jose.CryptoKey; private: jose.CryptoKey; created: Date; expired?: Date; jwk: jose.JWK; } /** * Imports a previously generated key pair and converts it into a usable * format. * * This includes converting the public key into JWK format and setting key * metadata. * * @param value - The previously generated key pair. * @returns A promise that resolves to an object containing the imported key pair. * * @example * const keyPair = await JWK.importKeyPair(existingKeyPair); * console.log(keyPair.public); */ function importKeyPair(value: Awaited>): Promise; /** * Generates a new cryptographic key pair using the specified algorithm. * * The keys are generated in an extractable format to allow export and import. * * @param alg - The algorithm to use for key generation. * @returns A promise that resolves to an object containing the generated key pair. * * @example * const keyPair = await JWK.generateKeyPair(JWK.Algoritm.ES256); * console.log(keyPair); */ function generateKeyPair(alg: Algoritm): Promise<{ id: `${string}-${string}-${string}-${string}-${string}`; publicKey: string; privateKey: string; created: number; alg: Algoritm; }>; /** * Retrieves the available signing keys from the provided file storage. * * If no valid signing keys exist, a new key pair is generated and stored. * * @param storage - The file storage system to retrieve keys from. * @returns A promise that resolves to an array of signing key pairs. * * @example * const keys = await JWK.signingKeys(storage); * console.log(keys); */ function signingKeys(storage: FileStorage): Promise; /** * Retrieves the available encryption keys from the provided file storage. * If no valid encryption keys exist, a new key pair is generated and stored. * * @param storage - The file storage system to retrieve keys from. * @returns A promise that resolves to an array of encryption key pairs. * * @example * const keys = await JWK.encryptionKeys(storage); * console.log(keys); */ function encryptionKeys(storage: FileStorage): Promise; /** * Imports a JSON Web Key Set (JWKS) for local verification. * * This allows JWTs to be verified against a predefined set of public keys. * * @param jwks - The JSON Web Key Set containing the public keys. * @param options - Optional settings, including the algorithm to use. * @returns A promise that resolves to an array containing the imported public key. * * @example * const publicKeys = await JWK.importLocal(jwks, { alg: JWK.Algoritm.ES256 }); * console.log(publicKeys); */ function importLocal(jwks: jose.JSONWebKeySet, options?: { alg: Algoritm; }): Promise<{ public: CryptoKey; }[]>; /** * Imports a JSON Web Key Set (JWKS) from a remote URL for verification. * * This method fetches public keys dynamically from an external endpoint. * * @param url - The URL of the remote JWKS endpoint. * @param options - Options for fetching the keys, including the expected algorithm. * @returns A promise that resolves to an array containing the imported public key. * * @example * const publicKeys = await JWK.importRemote(new URL("https://example.com/.well-known/jwks.json"), { alg: JWK.Algoritm.ES256 }); * console.log(publicKeys); */ function importRemote(url: URL, options: jose.RemoteJWKSetOptions & { alg: Algoritm; }): Promise<{ public: CryptoKey; }[]>; /** * Converts an array of key pairs into a JSON Web Key Set (JWKS) format. * * This format is commonly used for publishing public keys for JWT * verification. * * @param keys - An array of key pairs to convert into JWKS format. * @returns An object representing the JWKS structure. * * @example * const jwks = JWK.toJSON(keyPairs); * console.log(JSON.stringify(jwks, null, 2)); */ function toJSON(keys: KeyPair[]): { keys: { crv: string | undefined; kty: string | undefined; x: string | undefined; y: string | undefined; kid: string | undefined; }[]; }; }