/** Random id of `size` symbols drawn uniformly from `alphabet`, which must hold 1-256 of them. */ export declare function nanoid(size?: number, alphabet?: string): string; export declare const HASH_ALGORITHMS: readonly ['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512']; export type HashAlgorithm = (typeof HASH_ALGORITHMS)[number]; export type DigestEncoding = 'hex' | 'base64' | 'base64url'; /** Text as its UTF-8 bytes, bytes as they are. */ export type CryptoInput = string | BufferSource; export declare function hmac(key: CryptoInput, message: CryptoInput, algorithm?: HashAlgorithm, encoding?: DigestEncoding): Promise; /** Digest of `data`, lowercase hex by default. */ export declare function digest(algorithm: HashAlgorithm, data: CryptoInput, encoding?: DigestEncoding): Promise; /** Lowercase hex digest of the text's UTF-8 bytes. */ export declare function digestHex(algorithm: HashAlgorithm, text: string): Promise; /** * Pinned rather than left to Bun's defaults, so a runtime upgrade can't quietly split the * stored corpus into two cost levels. Above the OWASP floor of m=19456, t=2, p=1. */ export declare const PASSWORD_HASH_PARAMS: { readonly algorithm: 'argon2id'; readonly memoryCost: 65536; readonly timeCost: 2; }; /** Argon2 costs to hash with, e.g. cheap ones in tests; unset ones keep `PASSWORD_HASH_PARAMS`. */ export interface PasswordHashParams { algorithm?: 'argon2id' | 'argon2i' | 'argon2d' | undefined; /** KiB of memory per hash. */ memoryCost?: number | undefined; /** Passes over that memory. */ timeCost?: number | undefined; } export declare function hashPassword(password: string, params?: PasswordHashParams): Promise; /** Verifies against any supported hash format; a malformed or unknown one is a mismatch, not a throw. */ export declare function comparePasswords(plaintextPassword: string, hashedPassword: string): Promise; /** True when `hashedPassword` was made with anything weaker than `PASSWORD_HASH_PARAMS`, or `params` when given: call it after a successful `comparePasswords` to re-hash the plaintext while you hold it. */ export declare function passwordNeedsRehash(hashedPassword: string, params?: PasswordHashParams): boolean; export declare function xmur3(str: string): () => number; export declare function sfc32(a: number, b: number, c: number, d: number): () => number; /** * Hashes a string to a normalized float in the range [0, 1]. * * @param str - The string to hash * @param options - Hashing options * @param options.algorithm - The hashing algorithm to use * - `FNV-1a` *(default)* — fast, good distribution, suitable for most use cases * - `sfc32` — higher quality output via PRNG seeded with xmur3, slightly slower * - `djb2` — extremely simple and fast, decent distribution * @returns A deterministic float in [0, 1] * * @example * hashString('my-service') // 0.6234... * hashString('my-service', { algorithm: 'sfc32' }) // 0.2841... */ export declare function hashString(str: string, { algorithm }?: { algorithm?: 'FNV-1a' | 'sfc32' | 'djb2'; }): number; //# sourceMappingURL=crypto.d.ts.map