canonicalJson
JSON with every object's keys in order: two documents saying the same thing are the same text.
export const canonicalJson = (x: unknown): string => JSON.stringify(x, (_, val: unknown) => val && typeof val === "object" && !Array.isArray(val) ? Object.fromEntries(Object.entries(val).toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) : val, )