diff --git a/README.md b/README.md index c10cd99..a69425e 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Argument | Type | Satus | Default | Description `algorithm` | `string` | optional | `HS256` | The algorithm used to sign the payload, possible values: `HS256` or `HS512` #### `return` -returns token as a `string` +Returns token as a `string`.
diff --git a/index.d.ts b/index.d.ts index de03419..d42c02d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,38 @@ +/** + * JWT + * + * @class + * @constructor + * @public + */ declare class JWT { + + /** + * Signs a payload and returns the token + * + * @param {object} payload The payload object. To use `nbf` (Not Before) and/or `exp` (Expiration Time) add `nbf` and/or `exp` to the payload. + * @param {string} secret A string which is used to sign the payload. + * @param {'HS256' | 'HS512'} [algorithm=HS256] The algorithm used to sign the payload, possible values: `HS256` or `HS512` + * @returns {Promise} Returns token as a `string`. + */ sign(payload: object, secret: string, algorithm?: "HS256" | "HS512"): Promise + + /** + * Verifies the integrity of the token and returns a boolean value. + * + * @param {string} token The token string generated by `jwt.sign()`. + * @param {string} secret The string which was used to sign the payload. + * @param {'HS256' | 'HS512'} [algorithm=HS256] The algorithm used to sign the payload, possible values: `HS256` or `HS512` + * @returns {Promise} Returns `true` if signature, `nbf` (if set) and `exp` (if set) are valid, otherwise returns `false`. + */ verify(token: string, secret: string, algorithm?: "HS256" | "HS512"): Promise + + /** + * Returns the payload **without** verifying the integrity of the token. Please use `jwt.verify()` first to keep your application secure! + * + * @param {string} token The token string generated by `jwt.sign()`. + * @returns {object | null} Returns payload `object`. + */ decode(token: string): object | null } declare const _exports: JWT