import { Secret } from '@poppinss/utils'; /** * Verification token class can be used to create tokens publicly * shareable tokens while storing the token hash within the database. * * This class is used by the Auth and the Persona packages to manage * tokens for authentication and authorization purposes. * * @example * class UserToken extends VerificationToken { * constructor(user: User, secret: Secret) { * super() * this.tokenableId = user.id * this.computeValue(secret) * } * } */ export declare abstract class VerificationToken { /** * Decodes a publicly shared token and return the series * and the token value from it. * * Returns null when unable to decode the token because of * invalid format or encoding. * * @param value - The token string to decode */ static decode(value: string): null | { identifier: string; secret: Secret; }; /** * Creates a transient token that can be shared with the persistence * layer. * * @param userId - The user ID for whom the token is being created * @param size - The size of the random token seed * @param expiresIn - Token expiration time (string like '2h' or number in seconds) */ static createTransientToken(userId: string | number | BigInt, size: number, expiresIn: string | number): { secret: Secret; hash: string; userId: string | number | BigInt; expiresAt: Date; }; /** * Creates a secret opaque token and its hash. * * @param size - The length of the random token to generate */ static seed(size: number): { secret: Secret; hash: string; }; /** * Identifer is a unique sequence to identify the * token within database. It should be the * primary/unique key */ identifier: string | number | BigInt; /** * Reference to the user id for whom the token * is generated. */ tokenableId: string | number | BigInt; /** * Hash is computed from the seed to later verify the validity * of seed */ hash: string; /** * Timestamp at which the token will expire */ expiresAt: Date; /** * The value is a public representation of a token. It is created * by combining the "identifier"."secret" via the "computeValue" * method */ value?: Secret; /** * Compute the value property using the given secret. You can * get secret via the static "createTransientToken" method. * * @param secret - The secret value to compute the public token value from */ protected computeValue(secret: Secret): void; /** * Check if the token has been expired. Verifies * the "expiresAt" timestamp with the current * date. */ isExpired(): boolean; /** * Verifies the value of a token against the pre-defined hash * * @param secret - The secret to verify against the stored hash */ verify(secret: Secret): boolean; }