UNPKG

remix-utils-rt

Version:

This package contains simple utility functions to use with [React Router](https://reactrouter.com/home).

72 lines (71 loc) 2.62 kB
export interface HoneypotInputProps { /** * The name expected to be used by the honeypot input field. */ nameFieldName: string; /** * The name expected to be used by the honeypot valid from input field. */ validFromFieldName: string | null; /** * The encrypted value of the current timestamp. */ encryptedValidFrom: string; } export interface HoneypotConfig { /** * Enable randomization of the name field name, this way the honeypot field * name will be different for each request. */ randomizeNameFieldName?: boolean; /** * The name of the field that will be used for the honeypot input. */ nameFieldName?: string; /** * The name of the field that will be used for the honeypot valid from input. */ validFromFieldName?: string | null; /** * The seed used for the encryption of the valid from timestamp. */ encryptionSeed?: string; } /** * The error thrown when the Honeypot fails, meaning some automated bot filled * the form and the request is probably spam. */ export declare class SpamError extends Error { readonly name = "SpamError"; } /** * Module used to implement a Honeypot. * A Honeypot is a visually hidden input that is used to detect spam bots. This * field is expected to be left empty by users because they don't see it, but * bots will fill it falling in the honeypot trap. */ export declare class Honeypot { private generatedEncryptionSeed; protected config: HoneypotConfig; constructor(config?: HoneypotConfig); /** * Get the HoneypotInputProps to be used in your forms. * @param options The options for the input props. * @param options.validFromTimestamp Since when the timestamp is valid. * @returns The props to be used in the form. */ getInputProps({ validFromTimestamp, }?: { validFromTimestamp?: number | undefined; }): Promise<HoneypotInputProps>; check(formData: FormData): Promise<void>; protected get nameFieldName(): string; protected get validFromFieldName(): string | null; protected get encryptionSeed(): string; protected getRandomizedNameFieldName(nameFieldName: string, formData: FormData): string | undefined; protected shouldCheckHoneypot(formData: FormData, nameFieldName: string): boolean; protected randomValue(): string; protected encrypt(value: string): Promise<string>; protected decrypt(value: string): Promise<string>; protected isFuture(timestamp: number): boolean; protected isValidTimeStamp(timestampp: number): boolean; }