import crypto from 'node:crypto' function stableStringify(value: unknown): string { if (value === null || value === undefined) return 'null' if (typeof value === 'string') return JSON.stringify(value) if (typeof value === 'number' || typeof value === 'boolean') return JSON.stringify(value) if (Array.isArray(value)) return `[${value.map((item) => stableStringify(item)).join(',')}]` if (typeof value === 'object') { const entries = Object.entries(value as Record).sort(([a], [b]) => a.localeCompare(b)) return `{${entries.map(([key, val]) => `${JSON.stringify(key)}:${stableStringify(val)}`).join(',')}}` } return JSON.stringify(value) } export function computeChecksum(source: unknown): string { const serialized = stableStringify(source) return crypto.createHash('sha256').update(serialized).digest('hex') }