fix(typescript): allow synchronous get key functions

This commit is contained in:
Filip Skokan 2022-02-22 10:38:49 +01:00
parent 404e9e0bc8
commit 7c99153a9e
2 changed files with 3 additions and 3 deletions

2
src/types.d.ts vendored
View file

@ -164,7 +164,7 @@ export interface JWK {
* @param token The consumed JWE or JWS token.
*/
export interface GetKeyFunction<T, T2> {
(protectedHeader: T, token: T2): Promise<KeyLike | Uint8Array>
(protectedHeader: T, token: T2): Promise<KeyLike | Uint8Array> | KeyLike | Uint8Array
}
/**

View file

@ -10,12 +10,12 @@ Deno.test('fetches the JWKSet', async () => {
const { alg, kid } = response.keys[0]
const jwks = createRemoteJWKSet(new URL(jwksUri))
await assertThrowsAsync(
() => jwks({ alg: 'RS256' }, <FlattenedJWSInput>{}),
async () => jwks({ alg: 'RS256' }, <FlattenedJWSInput>{}),
errors.JWKSMultipleMatchingKeys,
'multiple matching keys found in the JSON Web Key Set',
)
await assertThrowsAsync(
() => jwks({ kid: 'foo', alg: 'RS256' }, <FlattenedJWSInput>{}),
async () => jwks({ kid: 'foo', alg: 'RS256' }, <FlattenedJWSInput>{}),
errors.JWKSNoMatchingKey,
'no applicable key found in the JSON Web Key Set',
)