From b29fb02ebe6c03d4822e05e1b2de15e5ccc8fa29 Mon Sep 17 00:00:00 2001 From: David Pfeffer Date: Thu, 28 Jan 2016 10:42:53 -0500 Subject: [PATCH] Asynchronous encoding and synchronous decoding --- jsonwebtoken/jsonwebtoken.d.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/jsonwebtoken/jsonwebtoken.d.ts b/jsonwebtoken/jsonwebtoken.d.ts index b558df2e5f..3c296d5329 100644 --- a/jsonwebtoken/jsonwebtoken.d.ts +++ b/jsonwebtoken/jsonwebtoken.d.ts @@ -43,12 +43,16 @@ declare module "jsonwebtoken" { maxAge?: string; } - export interface VerifyCallbak { + export interface VerifyCallback { (err: Error, decoded: any): void; } + export interface SignCallback { + (err: Error, encoded: string): void; + } + /** - * Sign the given payload into a JSON Web Token string + * Synchronously sign the given payload into a JSON Web Token string * @param {String|Object|Buffer} payload - Payload to sign, could be an literal, buffer or string * @param {String|Buffer} secretOrPrivateKey - Either the secret for HMAC algorithms, or the PEM encoded private key for RSA and ECDSA. * @param {SignOptions} [options] - Options for the signature @@ -57,14 +61,33 @@ declare module "jsonwebtoken" { export function sign(payload: string | Buffer | Object, secretOrPrivateKey: string | Buffer, options?: SignOptions): string; /** - * Verify given token using a secret or a public key to get a decoded token + * Sign the given payload into a JSON Web Token string + * @param {String|Object|Buffer} payload - Payload to sign, could be an literal, buffer or string + * @param {String|Buffer} secretOrPrivateKey - Either the secret for HMAC algorithms, or the PEM encoded private key for RSA and ECDSA. + * @param {SignOptions} [options] - Options for the signature + * @param {Function} callback - Callback to get the encoded token on + */ + export function sign(payload: string | Buffer | Object, secretOrPrivateKey: string | Buffer, options?: SignOptions, callback: SignCallback): void; + + /** + * Synchronously verify given token using a secret or a public key to get a decoded token + * @param {String} token - JWT string to verify + * @param {String|Buffer} secretOrPublicKey - Either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA. + * @param {VerifyOptions} [options] - Options for the verification + * @returns The decoded token. + */ + function verify(token: string, secretOrPublicKey: string | Buffer): any; + function verify(token: string, secretOrPublicKey: string | Buffer, options?: VerifyOptions): any; + + /** + * Asynchronously verify given token using a secret or a public key to get a decoded token * @param {String} token - JWT string to verify * @param {String|Buffer} secretOrPublicKey - Either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA. * @param {VerifyOptions} [options] - Options for the verification * @param {Function} callback - Callback to get the decoded token on */ - function verify(token: string, secretOrPublicKey: string | Buffer, callback?: VerifyCallbak): void; - function verify(token: string, secretOrPublicKey: string | Buffer, options?: VerifyOptions, callback?: VerifyCallbak): void; + function verify(token: string, secretOrPublicKey: string | Buffer, callback?: VerifyCallback): void; + function verify(token: string, secretOrPublicKey: string | Buffer, options?: VerifyOptions, callback?: VerifyCallback): void; /** * Returns the decoded payload without verifying if the signature is valid.