1
0

Added more algorithms, keyid and did some cleanup

This commit is contained in:
2021-10-27 01:22:01 +02:00
parent 13943f64d7
commit e244ff0618
5 changed files with 79 additions and 476 deletions

20
index.d.ts vendored
View File

@@ -12,20 +12,20 @@ declare class JWT {
*
* @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`
* @param {JWTSignOptions | JWTAlgorithm} options The options object or the algorithm.
* @returns {Promise<string>} Returns token as a `string`.
*/
sign(payload: object, secret: string, algorithm?: "HS256" | "HS512"): Promise<string>
sign(payload: object, secret: string, options?: JWTSignOptions | JWTAlgorithm): Promise<string>
/**
* 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`
* @param {JWTVerifyOptions | JWTAlgorithm} options The options object or the algorithm.
* @returns {Promise<boolean>} 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<boolean>
verify(token: string, secret: string, options?: JWTVerifyOptions | JWTAlgorithm): Promise<boolean>
/**
* Returns the payload **without** verifying the integrity of the token. Please use `jwt.verify()` first to keep your application secure!
@@ -36,4 +36,16 @@ declare class JWT {
decode(token: string): object | null
}
declare const _exports: JWT
type JWTAlgorithm = 'ES256' | 'ES384' | 'ES512' | 'HS256' | 'HS384' | 'HS512'
type JWTSignOptions = {
algorithm?: JWTAlgorithm,
keyid?: string
}
type JWTVerifyOptions = {
algorithm?: JWTAlgorithm
}
export = _exports