import { createHash } from "node:crypto"; function canonical(value: unknown): unknown { if (Array.isArray(value)) return value.map(canonical); if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, canonical(item)])); return value; } /** The target lives in providerMetadata.connectionId; execution keys are excluded. */ export function canonicalPostHash }>(post: T): string { const metadata = { ...post.providerMetadata }; delete metadata.idempotencyKey; delete metadata.draftId; return createHash("sha256").update(JSON.stringify(canonical({ ...post, providerMetadata: metadata }))).digest("hex"); }