Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/server/src/request-identity-digest.ts?format=json
46 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 184, 1 version changed it
1import { createHash } from "node:crypto";
2import { jsonValueChunks } from "../../src/engine/json-value-chunks.ts";
3
4/** Preserve canonicalJson identity bytes without retaining the complete encoded request. */
5export function requestIdentityDigest(value: unknown): string {
6 const hash = createHash("sha256");
7 const active = new Set<object>();
8 function* chunks(input: unknown, absent?: string): Generator<string> {
9 if (typeof input === "string") {
10 yield* jsonValueChunks(input);
11 } else if (input && typeof input === "object") {
12 if (active.has(input)) throw new TypeError("cyclic request identity");
13 active.add(input);
14 try {
15 if (Array.isArray(input)) {
16 yield "[";
17 const length = input.length;
18 for (let i = 0; i < length; i++) {
19 if (i) yield ",";
20 if (i in input) yield* chunks(input[i], "");
21 }
22 yield "]";
23 } else {
24 yield "{";
25 let first = true;
26 for (const key of Object.keys(input).sort()) {
27 if (!first) yield ",";
28 first = false;
29 yield* jsonValueChunks(key);
30 yield ":";
31 yield* chunks((input as Record<string, unknown>)[key], "undefined");
32 }
33 yield "}";
34 }
35 } finally {
36 active.delete(input);
37 }
38 } else {
39 const encoded = JSON.stringify(input);
40 if (encoded === undefined && absent === undefined) throw new TypeError("unsupported request identity");
41 yield encoded ?? absent!;
42 }
43 }
44 for (const chunk of chunks(value)) hash.update(chunk);
45 return hash.digest("hex");