mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Please fill in this template. - [x] Use a meaningful title for the pull request. Include the name of the package modified. - [x] Test the change in your own code. (Compile and run.) - [x] Add or edit tests to reflect the change. (Run with `npm test`.) - [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request). - [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes). - [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present). - [x] The package does not already provide its own types, or cannot have its `.d.ts` files generated via `--declaration` - [x] If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package. - [x] Create it with `dts-gen --dt`, not by basing it on an existing project. - [x] `tslint.json` should be present, and `tsconfig.json` should have `noImplicitAny`, `noImplicitThis`, `strictNullChecks`, and `strictFunctionTypes` set to `true`.
64 lines
2.6 KiB
TypeScript
64 lines
2.6 KiB
TypeScript
// Type definitions for jwt-then 1.0
|
|
// Project: https://github.com/fl0w/jwt-then#readme
|
|
// Definitions by: Definitions by: Max Uetrecht <https://github.com/phenomax>
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
// TypeScript Version: 2.2
|
|
|
|
/// <reference types="node" />
|
|
|
|
export type Secret = string | Buffer | { key: string; passphrase: string };
|
|
|
|
export interface SignOptions {
|
|
/**
|
|
* Signature algorithm. Could be one of these values :
|
|
* - HS256: HMAC using SHA-256 hash algorithm (default)
|
|
* - HS384: HMAC using SHA-384 hash algorithm
|
|
* - HS512: HMAC using SHA-512 hash algorithm
|
|
* - RS256: RSASSA using SHA-256 hash algorithm
|
|
* - RS384: RSASSA using SHA-384 hash algorithm
|
|
* - RS512: RSASSA using SHA-512 hash algorithm
|
|
* - ES256: ECDSA using P-256 curve and SHA-256 hash algorithm
|
|
* - ES384: ECDSA using P-384 curve and SHA-384 hash algorithm
|
|
* - ES512: ECDSA using P-521 curve and SHA-512 hash algorithm
|
|
* - none: No digital signature or MAC value included
|
|
*/
|
|
algorithm?: string;
|
|
keyid?: string;
|
|
/** expressed in seconds or a string describing a time span [zeit/ms](https://github.com/zeit/ms.js). Eg: 60, "2 days", "10h", "7d" */
|
|
expiresIn?: string | number;
|
|
/** expressed in seconds or a string describing a time span [zeit/ms](https://github.com/zeit/ms.js). Eg: 60, "2 days", "10h", "7d" */
|
|
notBefore?: string | number;
|
|
audience?: string | string[];
|
|
subject?: string;
|
|
issuer?: string;
|
|
jwtid?: string;
|
|
noTimestamp?: boolean;
|
|
header?: object;
|
|
encoding?: string;
|
|
}
|
|
|
|
/**
|
|
* Sign the given payload into a JSON Web Token string
|
|
* @param payload - Payload to sign, could be an literal, buffer or string
|
|
* @param secretOrPrivateKey - Either the secret for HMAC algorithms, or the PEM encoded private key for RSA and ECDSA.
|
|
* @param [options] - Options for the signature
|
|
* @returns A proiose containing the JSON Web Token string
|
|
*/
|
|
export function sign(
|
|
payload: string | Buffer | object,
|
|
secretOrPrivateKey: Secret,
|
|
options?: SignOptions,
|
|
): Promise<string>;
|
|
|
|
/**
|
|
* Verify given token using a secret or a public key to get a decoded token
|
|
* @param token - JWT string to verify
|
|
* @param secretOrPublicKey - Either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA.
|
|
* @param [options] - Options for the verification
|
|
* @returns A promise containing either an error or the decoded JSON Web Token string
|
|
*/
|
|
export function verify(
|
|
token: string,
|
|
secretOrPublicKey: string | Buffer,
|
|
): Promise<object | string>;
|