import type { Jwk } from '../jose/jwk.js'; type ExportedJwk = JsonWebKey & Jwk; interface WebcryptoSubtleFacade { decrypt(...args: unknown[]): Promise; deriveBits(...args: unknown[]): Promise; deriveKey(...args: unknown[]): Promise; digest(...args: unknown[]): Promise; encrypt(...args: unknown[]): Promise; exportKey(format: 'jwk', ...args: unknown[]): Promise; exportKey(format: 'raw' | 'spki' | 'pkcs8', ...args: unknown[]): Promise; generateKey(...args: unknown[]): Promise; importKey(...args: unknown[]): Promise; sign(...args: unknown[]): Promise; unwrapKey(...args: unknown[]): Promise; verify(...args: unknown[]): Promise; wrapKey(...args: unknown[]): Promise; } type WebcryptoFacade = Omit & { subtle: WebcryptoSubtleFacade; }; export function getWebcrypto(): WebcryptoFacade { const webCrypto = globalThis.crypto; if (!webCrypto) { throw new Error('crypto must be defined'); } return webCrypto as unknown as WebcryptoFacade; } export function getWebcryptoSubtle(): WebcryptoSubtleFacade { const subtle = getWebcrypto().subtle; if (!subtle) { throw new Error('crypto.subtle must be defined'); } return subtle; }