Skip to main content
Module

x/jose/runtime/get_sign_verify_key.ts

"JSON Web Almost Everything" - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto in Node.js, Browser, Cloudflare Workers, Electron, and Deno.
Extremely Popular
Go to Latest
File
import crypto, { isCryptoKey } from './webcrypto.ts'import { checkSigCryptoKey } from '../lib/crypto_key.ts'import invalidKeyInput from '../lib/invalid_key_input.ts'
export default function getCryptoKey(alg: string, key: unknown, usage: KeyUsage) { if (isCryptoKey(key)) { checkSigCryptoKey(key, alg, usage) return key }
if (key instanceof Uint8Array) { if (!alg.startsWith('HS')) { throw new TypeError(invalidKeyInput(key, 'CryptoKey')) } return crypto.subtle.importKey( 'raw', key, { hash: `SHA-${alg.substr(-3)}`, name: 'HMAC' }, false, [usage], ) }
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'Uint8Array'))}