@dr.pogodin/csurf
Version:
CSRF token middleware for ExpressJS
34 lines (33 loc) • 884 B
TypeScript
/**
* Verify if a given token is valid for a given secret.
*/
export declare function verify(secret: string, token: string): boolean;
export type Options = {
saltLength?: number;
secretLength?: number;
};
/**
* Token generation/verification class.
*/
export default class Tokens {
private saltLength;
private secretLength;
/**
* @param [options]
* @param [options.saltLength=8] The string length of the salt
* @param [options.secretLength=18] The byte length of the secret key
*/
constructor(options?: Options);
/**
* Create a new CSRF token.
*
* @param secret The secret for the token.
*/
create(secret: string): string;
secret(): Promise<string>;
secret(callback: (err: unknown, str: string) => void): void;
/**
* Create a new secret key synchronously.
*/
secretSync(): string;
}