MCPcopy Create free account
hub / github.com/acoyfellow/cloudbox / specHash

Function specHash

src/materialize.ts:55–63  ·  view source on GitHub ↗

* Stable, deterministic hash of a spec. Uses SHA-256 over the canonicalized * JSON. Output is the first 12 hex chars — enough to avoid collision in * practice, short enough to fit in URLs.

(spec: ComputerSpec)

Source from the content-addressed store, hash-verified

53 * practice, short enough to fit in URLs.
54 */
55async function specHash(spec: ComputerSpec): Promise<string> {
56 const canonical = JSON.stringify(spec, Object.keys(spec).sort());
57 const data = new TextEncoder().encode(canonical);
58 const digest = await crypto.subtle.digest("SHA-256", data);
59 const hex = Array.from(new Uint8Array(digest))
60 .map((b) => b.toString(16).padStart(2, "0"))
61 .join("");
62 return `cb_${hex.slice(0, 12)}`;
63}

Callers 1

materializeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected