This commit is contained in:
parent
8e71537d57
commit
fcc18ddcc8
96 changed files with 8074 additions and 214 deletions
26
pipeline/hash.ts
Normal file
26
pipeline/hash.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue