// A case's private names as stored (lib/research/caseTypes.ts, "PRIVATE NAMES ARE NEVER TEXT"): the sha256 of each // term, never the term. The gate hashes privateNameCandidates of what it checks and compares. import { createHash } from "node:crypto"; import { normalizeTerm, privateNameCandidates } from "./caseTypes"; /** A term's stored form: sha256 of normalizeTerm(term), lowercase hex. */ export function privateNameHash(term: string): string { return createHash("sha256").update(normalizeTerm(term)).digest("hex"); } /** How many of `text`'s words and 2–3-word phrases hash to one of `hashes`: a count, never which. */ export function privateNameHits(text: string, hashes: readonly string[]): number { if (!hashes.length) return 0; const set = new Set(hashes); return privateNameCandidates(text).filter((c) => set.has(privateNameHash(c))).length; }