The whole project lived under a redundant veritas/ subdirectory with only a stub README.md at the repo root, so GitHub showed caelum0x/veritas as veritas/<everything>. Move all files up to the root and drop the stub. History is preserved (git detects renames). Build unaffected: 0 type errors across packages + all 31 apps, 49 tests passing from the new root. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
26 lines
866 B
TypeScript
26 lines
866 B
TypeScript
// SHA-256 hashing and content-addressable hashing over canonical JSON.
|
|
|
|
import { createHash } from "node:crypto";
|
|
import { canonicalize } from "./json.js";
|
|
|
|
/** A content hash string of the form "sha256:<hex>". */
|
|
export type ContentHash = `sha256:${string}`;
|
|
|
|
/** Compute the lowercase hex SHA-256 digest of a string or buffer. */
|
|
export function sha256Hex(input: string | Uint8Array): string {
|
|
return createHash("sha256").update(input).digest("hex");
|
|
}
|
|
|
|
/**
|
|
* Compute a stable content hash over any value via canonical JSON.
|
|
* Equal logical values always produce the same hash.
|
|
*/
|
|
export function contentHash(value: unknown): ContentHash {
|
|
return `sha256:${sha256Hex(canonicalize(value))}`;
|
|
}
|
|
|
|
/** Validate the "sha256:<64-hex>" shape. */
|
|
export function isContentHash(value: string): value is ContentHash {
|
|
return /^sha256:[0-9a-f]{64}$/.test(value);
|
|
}
|