Lumen/pipeline/hash.ts
Lumen Stage1 fcc18ddcc8
Some checks failed
ci / check (push) Has been cancelled
Checkpoint: current Lumen state
2026-09-23 18:58:21 -05:00

26 lines
771 B
TypeScript

/**
* SHA-256 helpers — Node crypto (pipeline build-time).
* Trace: ARCH 10.5, SPIKE-04 F-5, IMPLEMENTATION-CONTRACT.md §11
*/
import { createHash } from "node:crypto";
import { canonicalJson } from "./canonical-json.js";
export function sha256Hex(bytes: Uint8Array): string {
return createHash("sha256").update(bytes).digest("hex");
}
export function sha256HexOfString(str: string): string {
return sha256Hex(new TextEncoder().encode(str));
}
export function sha256HexOfJson(value: unknown): string {
return sha256HexOfString(canonicalJson(value));
}
export function bytesOfString(str: string): Uint8Array {
return new TextEncoder().encode(str);
}
export function bytesToString(bytes: Uint8Array): string {
return new TextDecoder().decode(bytes);
}