From d9aff1fdeba32fa2b956b8df7d479cc4d627a6ce Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Mon, 22 Oct 2018 11:56:03 -0500 Subject: [PATCH] [jsonwebtoken] FIX: Better typing to replace 'Function' --- types/jsonwebtoken/index.d.ts | 28 ++++++++++++++++++++++-- types/jsonwebtoken/jsonwebtoken-tests.ts | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/types/jsonwebtoken/index.d.ts b/types/jsonwebtoken/index.d.ts index ac2762dbd9..1c3cda40ba 100644 --- a/types/jsonwebtoken/index.d.ts +++ b/types/jsonwebtoken/index.d.ts @@ -90,6 +90,30 @@ export interface SignCallback { (err: Error, encoded: string): void; } + +export interface JwtHeader { + alg: string + typ?: string + kid?: string + jku?: string + x5u?: string + x5t?: string +} + +export interface SigningKeyCallback { + ( + err: any, + signingKey?: Secret, + ): void +} + +export interface GetPublicKeyOrSecret { + ( + header: JwtHeader, + callback: SigningKeyCallback + ): void; +} + export type Secret = string | Buffer | { key: string; passphrase: string }; /** @@ -150,12 +174,12 @@ export declare function verify( */ export declare function verify( token: string, - secretOrPublicKey: string | Buffer | Function, + secretOrPublicKey: string | Buffer | GetPublicKeyOrSecret, callback?: VerifyCallback, ): void; export declare function verify( token: string, - secretOrPublicKey: string | Buffer | Function, + secretOrPublicKey: string | Buffer | GetPublicKeyOrSecret, options?: VerifyOptions, callback?: VerifyCallback, ): void; diff --git a/types/jsonwebtoken/jsonwebtoken-tests.ts b/types/jsonwebtoken/jsonwebtoken-tests.ts index 6f9977995e..d1d51014fe 100644 --- a/types/jsonwebtoken/jsonwebtoken-tests.ts +++ b/types/jsonwebtoken/jsonwebtoken-tests.ts @@ -84,7 +84,7 @@ jwt.verify(token, cert, function(err, decoded) { }); // verify a token assymetric with async key fetch function -function getKey(header: Object, callback: Function) { +function getKey(header: jwt.JwtHeader, callback: jwt.SigningKeyCallback) { cert = fs.readFileSync("public.pem"); callback(null, cert);