Files
SerpentRace/SerpentRace_Backend/dist/Application/Services/TokenService.d.ts
T

80 lines
2.8 KiB
TypeScript

export interface VerificationToken {
token: string;
expiresAt: Date;
createdAt: Date;
}
export interface PasswordResetToken {
token: string;
expiresAt: Date;
createdAt: Date;
}
export declare class TokenService {
private static readonly VERIFICATION_TOKEN_EXPIRES_HOURS;
private static readonly PASSWORD_RESET_TOKEN_EXPIRES_HOURS;
private static readonly TOKEN_LENGTH;
/**
* Generate a secure random token
* @param length - Length of the token in bytes (default: 32)
* @returns Hexadecimal string token
*/
static generateSecureToken(length?: number): string;
/**
* Generate email verification token with expiration
* @returns VerificationToken object with token and expiration info
*/
static generateVerificationToken(): VerificationToken;
/**
* Generate password reset token with expiration
* @returns PasswordResetToken object with token and expiration info
*/
static generatePasswordResetToken(): PasswordResetToken;
/**
* Check if a token has expired
* @param expiresAt - Expiration date of the token
* @returns True if token has expired, false otherwise
*/
static isTokenExpired(expiresAt: Date): boolean;
/**
* Validate token format (basic validation)
* @param token - Token to validate
* @returns True if token format is valid, false otherwise
*/
static isValidTokenFormat(token: string): boolean;
/**
* Generate a verification URL with token
* @param baseUrl - Base URL of the application
* @param token - Verification token
* @returns Complete verification URL
*/
static generateVerificationUrl(baseUrl: string, token: string): string;
/**
* Generate a password reset URL with token
* @param baseUrl - Base URL of the application
* @param token - Password reset token
* @returns Complete password reset URL
*/
static generatePasswordResetUrl(baseUrl: string, token: string): string;
/**
* Hash a token for secure storage in database
* @param token - Plain text token to hash
* @returns Hashed token
*/
static hashToken(token: string): Promise<string>;
/**
* Verify a plain text token against a hashed token
* @param plainToken - Plain text token to verify
* @param hashedToken - Hashed token to compare against
* @returns True if tokens match, false otherwise
*/
static verifyToken(plainToken: string, hashedToken: string): Promise<boolean>;
/**
* Get token expiration info in human-readable format
* @param expiresAt - Expiration date
* @returns Human-readable expiration info
*/
static getExpirationInfo(expiresAt: Date): {
expired: boolean;
timeLeft: string;
};
}
//# sourceMappingURL=TokenService.d.ts.map