UNPKG

jose

Version:

JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes

13 lines (12 loc) 513 B
import { checkSigCryptoKey } from './crypto_key.js'; import invalidKeyInput from './invalid_key_input.js'; export default async (alg, key, usage) => { if (key instanceof Uint8Array) { if (!alg.startsWith('HS')) { throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'KeyObject', 'JSON Web Key')); } return crypto.subtle.importKey('raw', key, { hash: `SHA-${alg.slice(-3)}`, name: 'HMAC' }, false, [usage]); } checkSigCryptoKey(key, alg, usage); return key; };