Provides SHA-256 hashing utilities for strings, buffers, and JSON values.
// Source: https://github.com/first-fluke/oh-my-agent | License: MIT | Copyright 2026 Eunkwang Shin, Gahyun Kim
// Provided via justclaw.it.com; keep this notice with the code.
import { createHash } from "node:crypto";
/** Full SHA-256 hex digest of string or binary content. */
export function sha256Hex(
value: string | Buffer,
encoding?: BufferEncoding,
): string {
const hash = createHash("sha256");
if (typeof value === "string") {
hash.update(value, encoding ?? "utf-8");
} else {
hash.update(value);
}
return hash.digest("hex");
}
/** First 16 hex chars of SHA-256 over JSON-serialized value (stable for plain objects/arrays). */
export function shortHash(value: unknown): string {
return createHash("sha256")
.update(JSON.stringify(value))
.digest("hex")
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key