UNPKG

@piggly/fastify-chassis

Version:

An ESM/CommonJS toolkit to help you to do common operations in your back-end applications with Fastify and NodeJS.

92 lines (91 loc) 2.65 kB
import { IStoreService, TOrUndefined } from '@piggly/ddd-toolkit'; /** * @file Nonce service. * @copyright Piggly Lab 2025 * @since 7.0.0 * @author Caique Araujo <caique@piggly.com.br> */ export declare class NonceTokenService { /** * Repository. * * @type {IStoreService} * @protected * @memberof NonceTokenService * @since 7.0.0 * @author Caique Araujo <caique@piggly.com.br> */ protected _repository: IStoreService; /** * Constructor. * * @param {IStoreService} repository * @public * @constructor * @memberof NonceTokenService * @since 7.0.0 * @author Caique Araujo <caique@piggly.com.br> */ constructor(repository: IStoreService); /** * Issue one or more nonces. * * @param {number} size * @returns {Promise<Array<string>>} * @throws {Error} If failed to issue nonce. Error may be produced by store service. * @since 7.0.0 * @author Caique Araujo <caique@piggly.com.br> */ issue(size?: number, ttl?: number): Promise<Array<string>>; /** * Verify a nonce. * * If will return undefined if nonce is not found * or the same nonce if found. But, if regenerate * is true, it will regenerate the nonce and return * the new nonce. * * @param {string} nonce * @param {boolean} regenerate * @param {number} ttl * @returns {Promise<TOrUndefined<string>>} * @throws {Error} If failed to verify/regenerate nonce. Error may be produced by store service. * @since 7.0.0 * @author Caique Araujo <caique@piggly.com.br> */ verify(nonce: string, regenerate?: boolean, ttl?: number): Promise<TOrUndefined<string>>; /** * Random generates a client secret. * * @param {number} [size=36] * @public * @static * @memberof NonceTokenService * @since 7.6.0 * @author Caique Araujo <caique@piggly.com.br> */ protected static generateClientSecret(size?: number): string; /** * Register application service. * * @param {NonceTokenService} store * @public * @static * @memberof NonceTokenService * @since 7.0.0 * @author Caique Araujo <caique@piggly.com.br> */ static register(store: IStoreService): void; /** * Resolve application service. * * @returns {NonceTokenService} * @throws {Error} If service is not registered. * @public * @static * @memberof NonceTokenService * @since 7.0.0 * @author Caique Araujo <caique@piggly.com.br> */ static resolve(): NonceTokenService; }