/**
 * CloakBrowser per-worker fingerprint seed — single source of truth.
 *
 * Deterministic function of a stable key (the worker_id in cs mode). The worker
 * passes the result as `--fingerprint=<seed>` to CloakBrowser; the web admin
 * computes the SAME value to display it. Using one shared function guarantees
 * "what the web shows" == "what the browser launches with".
 *
 * Pure JS (FNV-1a 32-bit, no node:crypto) so it runs identically in Node (the
 * worker) and in the browser bundle (the web). Maps into CloakBrowser's 5-digit
 * seed space (10000-99999).
 */
export function cloakFingerprintSeed(key: string): number {
  const s = `dipclaw:fp:${key}`;
  let h = 0x811c9dc5; // FNV offset basis
  for (let i = 0; i < s.length; i++) {
    h ^= s.charCodeAt(i);
    h = Math.imul(h, 0x01000193); // FNV prime
  }
  return 10000 + ((h >>> 0) % 90000);
}
