deno.land / x / jose@v5.2.4 / jwk / embedded.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
28
29
30
31
32
33
import type { KeyLike, FlattenedJWSInput, JWSHeaderParameters } from '../types.d.ts'import { importJWK } from '../key/import.ts'import isObject from '../lib/is_object.ts'import { JWSInvalid } from '../util/errors.ts'
/** * EmbeddedJWK is an implementation of a GetKeyFunction intended to be used with the JWS/JWT verify * operations whenever you need to opt-in to verify signatures with a public key embedded in the * token's "jwk" (JSON Web Key) Header Parameter. It is recommended to combine this with the verify * function's `algorithms` option to define accepted JWS "alg" (Algorithm) Header Parameter values. * */export async function EmbeddedJWK<KeyLikeType extends KeyLike = KeyLike>( protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput,): Promise<KeyLikeType> { const joseHeader = { ...protectedHeader, ...token?.header, } if (!isObject(joseHeader.jwk)) { throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object') }
const key = await importJWK<KeyLikeType>({ ...joseHeader.jwk, ext: true }, joseHeader.alg!)
if (key instanceof Uint8Array || key.type !== 'public') { throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key') }
return key}
jose

Version Info

Tagged at
a month ago