outers
Version:
outers - a all in one package for your day to day use
93 lines (92 loc) • 4.88 kB
TypeScript
export default class Jwt {
#private;
/**
* The constructor function initializes the signatureKey property with the provided value or a default
* value of 'secret'.
* @param {string} signatureKey - The `signatureKey` parameter is a string that represents the key used
* for signing or verifying signatures. It is an optional parameter, meaning it can be provided or
* omitted when creating an instance of the class. If no value is provided, the default value is set to
* `'secret'`.
*/
constructor(signatureKey: string);
/**
* The function generates a token using a payload and an optional expiry time, and returns a record
* containing information about the generated token.
* @param {any} Payload - The `Payload` parameter is of type `unknown`, which means it can accept
* any type of data. It represents the data that you want to include in the token.
* @param [expiry=1h] - The `expiry` parameter is an optional parameter that specifies the expiration
* time for the generated token. It is set to a default value of '1h', which means the token will
* expire after 1 hour.
* @returns a Promise that resolves to a Record<string, unknown> object.
*/
generate(Payload: any, expiry?: string): Record<string, any>;
/**
* The function generates a login token by repeatedly calling a token generation function for a
* specified number of rounds.
* @param {unknown} Payload - The `Payload` parameter is of type `unknown` and represents the data that
* will be used to generate the login token. It can be any type of data, such as an object or a string.
* @param [Rounds=5] - The "Rounds" parameter determines the number of times the token generation
* process will be repeated. Each round generates a new token based on the previous token. The default
* value is 5 rounds.
* @param [expiry=1h] - The `expiry` parameter is a string that represents the expiration time of the
* generated token. It is set to a default value of '1h', which means the token will expire after 1
* hour.
* @returns an object with the following properties:
* - status: a boolean indicating whether the token was generated successfully or not.
* - message: a string message indicating the result of the token generation.
* - toKen: the generated token.
* - algoRithm: a string indicating the algorithm used for token generation (HS256 in this case).
* - expiry: a string indicating the expiration time of
*/
generateLoginToken(Payload: any, Rounds?: number, expiry?: string): {
status: boolean;
message: string;
toKen: any;
algoRithm: string;
expiry: string;
currentTimeStamp: string;
} | {
status: boolean;
message: string;
currentTimeStamp: string;
algoRithm: string;
toKen?: undefined;
expiry?: undefined;
};
/**
* The `destroy` function takes a token, adds ciphers to specific positions, reverses the token, and
* returns a result object with the modified token and other information.
* @param {string} token - The `token` parameter is a string that represents a token.
* @returns The `destroy` function returns a Promise that resolves to a `Record<string, unknown>`
* object.
*/
destroy(token: string): Record<string, any>;
/**
* The function decodes a token by verifying its cipher and checking if it is valid, returning an error
* object if it is empty, destroyed, or invalid.
* @param {string} token - The `token` parameter is a string that represents a token that needs to be
* decoded.
* @returns The function `decode` returns a Promise that resolves to an unknown value. The value being
* returned depends on the conditions inside the function.
*/
decode(token: string): any;
/**
* Sets or updates the cipher list.
*
* This method updates the internal cipher list used for cryptographic operations.
* It validates the input to ensure that it is a non-empty array of strings. If the
* input does not meet these criteria, an error is thrown.
*
* @param {string[]} cipherList - An array of strings representing the new cipher list.
* @throws {Error} Throws an error if `cipherList` is not provided or is not an array.
*/
setCipherList(cipherList: string[]): void;
/**
* Sets the signature key used for signing or verifying.
* This method updates the instance's signature key with the provided value.
*
* @param {string} signatureKey - The new signature key to be set. Must be a non-empty string.
* @throws Will throw an error if `signatureKey` is not provided or if it is not a string.
*/
setSignatureKey(signatureKey: string): void;
}