Improve functions definitions

This commit is contained in:
SomaticIT
2014-09-15 19:38:14 +02:00
parent d6fe5776f8
commit 3f84d98bba
+34 -21
View File
@@ -3,9 +3,11 @@
// Definitions by: Maxime LUCE <https://github.com/SomaticIT>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "jsonwebtoken" {
interface SignOptions {
export interface SignOptions {
/**
* Signature algorithm. Could be one of these values :
* - HS256: HMAC using SHA-256 hash algorithm
@@ -27,40 +29,51 @@ declare module "jsonwebtoken" {
issuer?: string;
}
interface VerifyOptions {
export interface VerifyOptions {
audience?: string;
issuer?: string;
}
export interface VerifyCallbak {
(err: Error, decoded: any): void;
}
/**
* 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
* @returns The 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
* @returns {String} The JSON Web Token string
*/
function sign(payload: any, secretOrPrivateKey: any, options?: SignOptions): string;
export function sign(payload: string, secretOrPrivateKey: string): string;
export function sign(payload: string, secretOrPrivateKey: Buffer): string;
export function sign(payload: Buffer, secretOrPrivateKey: string): string;
export function sign(payload: Buffer, secretOrPrivateKey: Buffer): string;
export function sign(payload: Object, secretOrPrivateKey: string): string;
export function sign(payload: Object, secretOrPrivateKey: Buffer): string;
export function sign(payload: string, secretOrPrivateKey: string, options: SignOptions): string;
export function sign(payload: string, secretOrPrivateKey: Buffer, options: SignOptions): string;
export function sign(payload: Buffer, secretOrPrivateKey: string, options: SignOptions): string;
export function sign(payload: Buffer, secretOrPrivateKey: Buffer, options: SignOptions): string;
export function sign(payload: Object, secretOrPrivateKey: string, options: SignOptions): string;
export function sign(payload: Object, secretOrPrivateKey: Buffer, options: SignOptions): string;
/**
* 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 {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: any, callback: (err: Error, decoded: {}) => void): void;
/**
* 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: any, options: VerifyOptions, callback: (err: Error, decoded: {}) => void): void;
function verify(token: string, secretOrPublicKey: string, callback: VerifyCallbak): void;
function verify(token: string, secretOrPublicKey: Buffer, callback: VerifyCallbak): void;
function verify(token: string, secretOrPublicKey: string, options: VerifyOptions, callback: VerifyCallbak): void;
function verify(token: string, secretOrPublicKey: Buffer, options: VerifyOptions, callback: VerifyCallbak): void;
/**
* Returns the decoded payload without verifying if the signature is valid.
* @param {string} token - JWT string to decode
* @returns The decoded Token
* @param {String} token - JWT string to decode
* @returns {Object} The decoded Token
*/
function decode(token: string): {};
function decode(token: string): any;
}