deno.land / x / jose@v5.2.4 / runtime / get_sign_verify_key.ts

get_sign_verify_key.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import crypto, { isCryptoKey } from './webcrypto.ts'import { checkSigCryptoKey } from '../lib/crypto_key.ts'import invalidKeyInput from '../lib/invalid_key_input.ts'import { types } from './is_key_like.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, ...types)) } return crypto.subtle.importKey( 'raw', key, { hash: `SHA-${alg.slice(-3)}`, name: 'HMAC' }, false, [usage], ) }
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'))}
jose

Version Info

Tagged at
a month ago