diff --git a/src/index.d.ts b/src/index.d.ts index f896524..82c15f6 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -63,8 +63,8 @@ type SignerCallback = (e: Error | TokenError | null, token: string) => void type VerifierCallback = (e: Error | TokenError | null, payload: any) => void type DecodedJwt = { - header: { [key: string]: any }, - payload: any, + header: Record + payload: any signature: string } @@ -80,7 +80,7 @@ declare function VerifierSync(token: string | Buffer): any declare function VerifierAsync(token: string | Buffer): Promise declare function VerifierAsync(token: string | Buffer, cb: object): void -export interface JwtHeader { +export interface JwtHeader extends Record { alg: string | Algorithm typ?: string | undefined cty?: string | undefined diff --git a/test/types.spec.ts b/test/types.spec.ts index d0db95a..a7d7d6f 100644 --- a/test/types.spec.ts +++ b/test/types.spec.ts @@ -3,7 +3,15 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ -import { createDecoder, createSigner, createVerifier, DecodedJwt, JwtHeader, TokenError, TokenValidationErrorCode } from '..' +import { + createDecoder, + createSigner, + createVerifier, + DecodedJwt, + JwtHeader, + TokenError, + TokenValidationErrorCode +} from '..' import { expectAssignable, expectNotAssignable, expectType } from 'tsd' // Signing @@ -94,6 +102,24 @@ const signerOptions = { } expectAssignable(signerOptions.header) +const signerOptionsCustomHeaders = { + header: { + alg: 'RS256', + typ: '', + cty: '', + crit: [''], + kid: '', + jku: '', + x5u: '', + 'x5t#S256': '', + x5t: '', + x5c: '', + customClaim: 'my-custom-claim', + customClaim2: 'my-custom-claim2' + } +} +expectAssignable(signerOptionsCustomHeaders.header) + const signerOptionsNoAlg = { header: { typ: '',