teqo-backup/src/utilities/consentContentHash.ts
Francisco Ignácio Fontoura Solla bcac665cb5 Ship /campanha nuclei MVP with RBAC, invites, and vote estimates.
Adds electoral nuclei, leaderships, updates, and WhatsApp invite flows behind campaign auth, plus the consolidated schema migration that Vercel applies on deploy.
2026-07-18 15:01:56 -03:00

17 lines
575 B
TypeScript

import { createHash } from 'node:crypto'
const canonicalize = (value: unknown): unknown => {
if (Array.isArray(value)) return value.map(canonicalize)
if (value === null || typeof value !== 'object') return value
return Object.fromEntries(
Object.entries(value)
.sort(([left], [right]) => left.localeCompare(right))
.map(([key, nestedValue]) => [key, canonicalize(nestedValue)]),
)
}
export const hashConsentContent = (content: unknown): string =>
createHash('sha256')
.update(JSON.stringify(canonicalize(content)), 'utf8')
.digest('hex')