godcrm/backend/services/tokens/tokenHash.js
GOD CRM Release f89e074dd1
Some checks failed
CI / Lint / Typecheck / Test / Build (push) Has been cancelled
CI / PostgreSQL Integration Tests (push) Has been cancelled
GOD CRM — public scrubbed snapshot
Governed substrate for autonomous agents: scoped identity (passports),
audited actions, MCP workspace. Infra IPs and secrets redacted for public release.
2026-08-10 04:01:45 +03:00

19 lines
676 B
JavaScript

// Single source of truth for prefix + SHA-256 hash on intake tokens.
// See ADR-0069. Used by:
// - webhook create / resolver
// - migration 070 backfill
// - any future intake-token table (api keys, deploy tokens) per the
// standing rule in ADR-0069 §"Standing rule".
import crypto from 'node:crypto';
export const TOKEN_PREFIX_LEN = 12;
export function hashToken(plain) {
if (typeof plain !== 'string') {
throw new TypeError(`hashToken: plaintext must be a string, got ${typeof plain}`);
}
const prefix = plain.slice(0, TOKEN_PREFIX_LEN);
const hash = crypto.createHash('sha256').update(plain, 'utf8').digest('hex');
return { prefix, hash };
}