{"draft":null,"from":175,"to":318,"files":[{"path":"server/src/request-identity-digest.ts","added":46,"removed":0,"diff":"--- /dev/null\n+++ b/server/src/request-identity-digest.ts\n@@ -0,0 +1,46 @@\n+import { createHash } from \"node:crypto\";\n+import { jsonValueChunks } from \"../../src/engine/json-value-chunks.ts\";\n+\n+/** Preserve canonicalJson identity bytes without retaining the complete encoded request. */\n+export function requestIdentityDigest(value: unknown): string {\n+\tconst hash = createHash(\"sha256\");\n+\tconst active = new Set<object>();\n+\tfunction* chunks(input: unknown, absent?: string): Generator<string> {\n+\t\tif (typeof input === \"string\") {\n+\t\t\tyield* jsonValueChunks(input);\n+\t\t} else if (input && typeof input === \"object\") {\n+\t\t\tif (active.has(input)) throw new TypeError(\"cyclic request identity\");\n+\t\t\tactive.add(input);\n+\t\t\ttry {\n+\t\t\t\tif (Array.isArray(input)) {\n+\t\t\t\t\tyield \"[\";\n+\t\t\t\t\tconst length = input.length;\n+\t\t\t\t\tfor (let i = 0; i < length; i++) {\n+\t\t\t\t\t\tif (i) yield \",\";\n+\t\t\t\t\t\tif (i in input) yield* chunks(input[i], \"\");\n+\t\t\t\t\t}\n+\t\t\t\t\tyield \"]\";\n+\t\t\t\t} else {\n+\t\t\t\t\tyield \"{\";\n+\t\t\t\t\tlet first = true;\n+\t\t\t\t\tfor (const key of Object.keys(input).sort()) {\n+\t\t\t\t\t\tif (!first) yield \",\";\n+\t\t\t\t\t\tfirst = false;\n+\t\t\t\t\t\tyield* jsonValueChunks(key);\n+\t\t\t\t\t\tyield \":\";\n+\t\t\t\t\t\tyield* chunks((input as Record<string, unknown>)[key], \"undefined\");\n+\t\t\t\t\t}\n+\t\t\t\t\tyield \"}\";\n+\t\t\t\t}\n+\t\t\t} finally {\n+\t\t\t\tactive.delete(input);\n+\t\t\t}\n+\t\t} else {\n+\t\t\tconst encoded = JSON.stringify(input);\n+\t\t\tif (encoded === undefined && absent === undefined) throw new TypeError(\"unsupported request identity\");\n+\t\t\tyield encoded ?? absent!;\n+\t\t}\n+\t}\n+\tfor (const chunk of chunks(value)) hash.update(chunk);\n+\treturn hash.digest(\"hex\");\n+}"}],"unmatched":[]}