nationid - v2.2.1
    Preparing search index...

    Function hash

    • Returns the hex-encoded digest of salt + normalize(input) using the given algorithm via the Web Crypto API. Works in Node 20+, Deno, Bun, modern browsers, and edge runtimes.

      Use this for deterministic equality lookups when you must not store raw PII. ALWAYS supply a per-tenant or per-user salt — an unsalted SHA-256 of an 11-digit CPF can be brute-forced in milliseconds.

      Parameters

      • code: DocumentTypeCode

        Document type whose normalization rules apply.

      • input: string

        Raw user input; normalized before hashing.

      • opts: HashOptions = {}

        Optional salt (strongly recommended) and algorithm (default "SHA-256").

      Returns Promise<string>

      A Promise resolving to the lowercase hex-encoded digest.

      if code is not registered.

      if globalThis.crypto.subtle is not available (very old runtimes).

      import { hash } from "nationid/pii";

      const fingerprint = await hash("BR_CPF", "111.444.777-35", {
      salt: `tenant:${tenantId}:`,
      });
      // → "f4a2c1…" (64 hex chars for SHA-256)