app/lib/content/hashes.mjs
32 lines and 3 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| digestHex | 13 to 16 | 1 | 100% | OkCRAP 1 | No data: no mutants in this code |
| gitBlobSha | 22 to 29 | 1 | 100% | OkCRAP 1 | No data: no mutants in this code |
| renderHash | 35 to 37 | 1 | 100% | OkCRAP 1 | No data: no mutants in this code |
Imports
It imports app/lib/bytes.mjs. Imported by app/kb/procedures/compile.mjs, app/kb/registry/compile.mjs, app/lib/content/pipeline.mjs, app/lib/cv/compile.mjs, app/lib/dictionary/compile.mjs, app/lib/health/checks.server.ts, app/lib/llms/save.server.ts, app/lib/pages/compile.mjs, app/lib/phages/compile.mjs, app/lib/publications/compile.mjs, app/lib/roster/compile.mjs.
Source
// Every writer and comparer of posts.source_blob_sha and posts.render_hash uses this module;
// a second implementation is drift. The git header counts UTF-8 BYTES, not string.length.
import { toHex } from "../bytes.mjs";
const encoder = new TextEncoder();
/**
* @param {"SHA-1" | "SHA-256"} algorithm
* @param {Uint8Array<ArrayBuffer>} bytes
* @returns {Promise<string>} lowercase hex
*/
async function digestHex(algorithm, bytes) {
const digest = await crypto.subtle.digest(algorithm, bytes);
return toHex(digest);
}
/**
* @param {string} source the whole file, frontmatter included
* @returns {Promise<string>}
*/
export async function gitBlobSha(source) {
const body = encoder.encode(source);
const header = encoder.encode(`blob ${body.byteLength}\0`);
const framed = new Uint8Array(header.byteLength + body.byteLength);
framed.set(header, 0);
framed.set(body, header.byteLength);
return digestHex("SHA-1", framed);
}
/**
* @param {string} html
* @returns {Promise<string>}
*/
export async function renderHash(html) {
return digestHex("SHA-256", encoder.encode(html));
}