From 4c23bd65fe6fa634726a5eb73c6d590f7348a97e Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Thu, 3 Sep 2020 17:24:52 +0200 Subject: [PATCH] fix(typescript): properly type all decode/verify/decrypt fn options --- types/index.d.ts | 60 ++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 56614fa6..015cd619 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -342,9 +342,9 @@ export namespace JWS { function general(payload: string | Buffer | object, key: ProduceKeyInputWithNone, protected?: object, header?: object): GeneralJWS; } - interface VerifyOptions { - complete?: komplet; - parse?: parse; + interface VerifyOptions { + complete?: boolean; + parse?: boolean; encoding?: BufferEncoding; crit?: string[]; algorithms?: string[]; @@ -357,12 +357,12 @@ export namespace JWS { header?: object; } + function verify(jws: string | FlattenedJWS | GeneralJWS, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options: VerifyOptions & { parse: false }): Buffer; + function verify(jws: string | FlattenedJWS | GeneralJWS, key: ConsumeKeyInput | EmbeddedVerifyKeys, options: VerifyOptions & { complete: true }): completeVerification; + function verify(jws: string | FlattenedJWS | GeneralJWS, key: ConsumeKeyInput | EmbeddedVerifyKeys, options: VerifyOptions & { complete: true, parse: false }): completeVerification; + function verify(jws: string | FlattenedJWS | GeneralJWS, key: NoneKey, options: VerifyOptions & { complete: true }): completeVerification; + function verify(jws: string | FlattenedJWS | GeneralJWS, key: NoneKey, options: VerifyOptions & { complete: true, parse: false }): completeVerification; function verify(jws: string | FlattenedJWS | GeneralJWS, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options?: VerifyOptions): string | object; - function verify(jws: string | FlattenedJWS | GeneralJWS, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options?: VerifyOptions): Buffer; - function verify(jws: string | FlattenedJWS | GeneralJWS, key: ConsumeKeyInput | EmbeddedVerifyKeys, options?: VerifyOptions): completeVerification; - function verify(jws: string | FlattenedJWS | GeneralJWS, key: ConsumeKeyInput | EmbeddedVerifyKeys, options?: VerifyOptions): completeVerification; - function verify(jws: string | FlattenedJWS | GeneralJWS, key: NoneKey, options?: VerifyOptions): completeVerification; - function verify(jws: string | FlattenedJWS | GeneralJWS, key: NoneKey, options?: VerifyOptions): completeVerification; } export namespace JWE { @@ -402,8 +402,8 @@ export namespace JWE { function general(payload: string | Buffer, key: ProduceKeyInput, protected?: object, header?: object, aad?: string): GeneralJWE; } - interface DecryptOptions { - complete?: komplet; + interface DecryptOptions { + complete?: boolean; crit?: string[]; algorithms?: string[]; } @@ -418,8 +418,8 @@ export namespace JWE { protected?: object; } - function decrypt(jwe: string | FlattenedJWE | GeneralJWE, key: ConsumeKeyInput, options?: DecryptOptions): Buffer; - function decrypt(jwe: string | FlattenedJWE | GeneralJWE, key: ConsumeKeyInput, options?: DecryptOptions): completeDecrypt; + function decrypt(jwe: string | FlattenedJWE | GeneralJWE, key: ConsumeKeyInput, options: DecryptOptions & { complete: true }): completeDecrypt; + function decrypt(jwe: string | FlattenedJWE | GeneralJWE, key: ConsumeKeyInput, options?: DecryptOptions): Buffer; } export namespace JWT { @@ -430,19 +430,19 @@ export namespace JWT { key: T; } - interface DecodeOptions { - complete?: komplet; + interface DecodeOptions { + complete?: boolean; } /** * Decodes the JWT **without verifying the token**. For JWT verification/validation use * `jose.JWT.verify`. */ - function decode(jwt: string, options?: DecodeOptions): object; - function decode(jwt: string, options?: DecodeOptions): completeResult; + function decode(jwt: string, options: DecodeOptions & { complete: true }): completeResult; + function decode(jwt: string, options?: DecodeOptions): object; - interface VerifyOptions { - complete?: komplet; + interface VerifyOptions { + complete?: boolean; ignoreExp?: boolean; ignoreNbf?: boolean; ignoreIat?: boolean; @@ -461,9 +461,9 @@ export namespace JWT { profile?: JWTProfiles; } - function verify(jwt: string, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options?: VerifyOptions): object; - function verify(jwt: string, key: ConsumeKeyInput | EmbeddedVerifyKeys, options?: VerifyOptions): completeResult; - function verify(jwt: string, key: NoneKey, options?: VerifyOptions): completeResult; + function verify(jwt: string, key: NoneKey, options: VerifyOptions & { complete: true }): completeResult; + function verify(jwt: string, key: ConsumeKeyInput | EmbeddedVerifyKeys, options: VerifyOptions & { complete: true }): completeResult; + function verify(jwt: string, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options?: VerifyOptions): object; interface SignOptions { iat?: boolean; @@ -489,21 +489,21 @@ export namespace JWT { } namespace IdToken { - function verify(jwt: string, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options: VerifyOptions & VerifyProfileOptions<'id_token'>): object; - function verify(jwt: string, key: ConsumeKeyInput | EmbeddedVerifyKeys, options: VerifyOptions & VerifyProfileOptions<'id_token'>): completeResult; - function verify(jwt: string, key: NoneKey, options: VerifyOptions & VerifyProfileOptions<'id_token'>): completeResult; + function verify(jwt: string, key: ConsumeKeyInput | EmbeddedVerifyKeys, options: VerifyOptions & { complete: true } & VerifyProfileOptions<'id_token'>): completeResult; + function verify(jwt: string, key: NoneKey, options: VerifyOptions & { complete: true } & VerifyProfileOptions<'id_token'>): completeResult; + function verify(jwt: string, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options: VerifyOptions & VerifyProfileOptions<'id_token'>): object; } namespace LogoutToken { - function verify(jwt: string, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options: VerifyOptions & VerifyProfileOptions<'logout_token'>): object; - function verify(jwt: string, key: ConsumeKeyInput | EmbeddedVerifyKeys, options: VerifyOptions & VerifyProfileOptions<'logout_token'>): completeResult; - function verify(jwt: string, key: NoneKey, options: VerifyOptions & VerifyProfileOptions<'logout_token'>): completeResult; + function verify(jwt: string, key: ConsumeKeyInput | EmbeddedVerifyKeys, options: VerifyOptions & { complete: true } & VerifyProfileOptions<'logout_token'>): completeResult; + function verify(jwt: string, key: NoneKey, options: VerifyOptions & { complete: true } & VerifyProfileOptions<'logout_token'>): completeResult; + function verify(jwt: string, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options: VerifyOptions & VerifyProfileOptions<'logout_token'>): object; } namespace AccessToken { - function verify(jwt: string, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options: VerifyOptions & VerifyProfileOptions<'at+JWT'>): object; - function verify(jwt: string, key: ConsumeKeyInput | EmbeddedVerifyKeys, options: VerifyOptions & VerifyProfileOptions<'at+JWT'>): completeResult; - function verify(jwt: string, key: NoneKey, options: VerifyOptions & VerifyProfileOptions<'at+JWT'>): completeResult; + function verify(jwt: string, key: ConsumeKeyInput | EmbeddedVerifyKeys, options: VerifyOptions & { complete: true } & VerifyProfileOptions<'at+JWT'>): completeResult; + function verify(jwt: string, key: NoneKey, options: VerifyOptions & { complete: true } & VerifyProfileOptions<'at+JWT'>): completeResult; + function verify(jwt: string, key: ConsumeKeyInputWithNone | EmbeddedVerifyKeys, options: VerifyOptions & VerifyProfileOptions<'at+JWT'>): object; } }