import { type HexString } from './number/encoded'; /** * Represents a salt value used in hashing. * * @semanticType * @semanticTopic string * @semanticTopic dereekb-util:hash */ export type HashSalt = string; /** * A Map used for decoding hashed string values. * * @template H The type of the hashed string (key). * @template V The type of the original string (value). */ export type HashDecodeMap = Map; /** * Decodes a list of hashed string values using a provided list of potential original values and a hash function. * * @param hashedValues - Hashed inputs awaiting reverse lookup. * @param decodeValues - Plaintext candidates that may match one of the hashes. * @param hashFn - Deterministic hashing used to align the candidate set with the input hashes. * @returns Plaintext recovered from `decodeValues`, dropping any hash that lacks a match. * * @dbxUtil * @dbxUtilCategory hash * @dbxUtilTags hash, decode, lookup, reverse, salt * @dbxUtilRelated make-hash-decode-map, decode-hashed-values-with-decode-map * * @example * ```ts * const hashed = [hashFn('apple'), hashFn('banana')]; * decodeHashedValues(hashed, ['apple', 'banana', 'cherry'], hashFn); * // ['apple', 'banana'] * ``` */ export declare function decodeHashedValues(hashedValues: string[], decodeValues: string[], hashFn: (value: string) => string): string[]; /** * Creates a `HashDecodeMap` from a list of potential original string values and a hash function. * The map's keys are the hashed versions of the `decodeValues`, and the values are the original `decodeValues`. * * @param decodeValues - Plaintext candidates whose hashes the map should index. * @param hashFn - Deterministic hashing used to compute each key. * @returns Hash-to-plaintext lookup ready for reverse decoding. * * @dbxUtil * @dbxUtilCategory hash * @dbxUtilTags hash, decode, map, lookup, reverse, factory * @dbxUtilRelated decode-hashed-values, decode-hashed-values-with-decode-map * * @__NO_SIDE_EFFECTS__ */ export declare function makeHashDecodeMap(decodeValues: string[], hashFn: (value: string) => string): HashDecodeMap; /** * Decodes a list of hashed string values using a pre-built `HashDecodeMap`. * * @param hashedValues - Hashed inputs awaiting reverse lookup. * @param decodeMap - Pre-built hash-to-plaintext lookup. * @returns Plaintext recovered via `decodeMap`, dropping any hash missing from it. */ export declare function decodeHashedValuesWithDecodeMap(hashedValues: string[], decodeMap: HashDecodeMap): string[]; /** * Computes a stable, non-negative 32-bit integer hash for the input string using the FNV-1a algorithm. * * Deterministic and dependency-free (no `Math.random`): the same input always yields the same value, * making it suitable for deterministically mapping a string onto a fixed-size set (e.g. picking a * curated color for a name via `hashStringToNumber(value) % colors.length`). * * @param value - String to hash. * @returns A non-negative integer in the range `[0, 2^32)`. * * @dbxUtil * @dbxUtilCategory hash * @dbxUtilTags hash, string, number, deterministic, fnv, bucket, index * @dbxUtilRelated decode-hashed-values * * @example * ```ts * hashStringToNumber('Michelle B'); // stable integer, same every call * hashStringToNumber('Michelle B') % 12; // deterministic bucket index 0-11 * ``` */ export declare function hashStringToNumber(value: string): number; /** * SHA-256 of a string's UTF-8 bytes as 64 lowercase hex characters — synchronous and dependency-free, so it runs * unchanged in browsers, workers and Node. * * Byte-identical to node:crypto `createHash('sha256').update(text, 'utf8').digest('hex')` for EVERY JS string: the * text is encoded with `TextEncoder` (the WHATWG UTF-8 rules Node also applies), so a lone surrogate encodes as U+FFFD * (`EF BF BD`) instead of throwing. Use {@link sha256HexPrefix} for a short digest. * * @param text - The text to hash. * @returns The lowercase hex digest. * * @dbxUtil * @dbxUtilCategory hash * @dbxUtilTags hash, sha256, digest, hex, sync, crypto, fingerprint * @dbxUtilRelated sha256-hex-prefix, hash-string-to-number * * @example * ```ts * sha256Hex('abc'); // 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' * ``` */ export declare function sha256Hex(text: string): HexString; /** * The first `length` characters of {@link sha256Hex} — a short, stable fingerprint of a string's UTF-8 bytes. * * @param text - The text to hash. * @param length - How many leading hex characters to keep (at most 64). * @returns The lowercase hex digest prefix. * * @dbxUtil * @dbxUtilCategory hash * @dbxUtilTags hash, sha256, digest, hex, prefix, short, fingerprint * @dbxUtilRelated sha256-hex * * @example * ```ts * sha256HexPrefix('abc', 8); // 'ba7816bf' * ``` */ export declare function sha256HexPrefix(text: string, length: number): HexString;