UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

40 lines (39 loc) • 1.2 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { n as writeStableStringify } from "./stable-stringify-vqde_3tT.mjs"; import { createHash, hash } from "node:crypto"; import { Buffer } from "node:buffer"; //#region packages/normalization-core/src/node-crypto.ts function sha256Hex(e) { return hash("sha256", e, "hex"); } function sha256StableValue(e, t) { let n; let r = ""; let i = 0; writeStableStringify(e, (e) => { r += e; if (r.length >= 16384) { n ??= createHash("sha256"); n.update(r); i += Buffer.byteLength(r); r = ""; } }, t); i += Buffer.byteLength(r); return { digest: n ? n.update(r).digest("hex") : sha256Hex(r), byteWeight: i }; } function sha256HexPrefixCore(e, t) { return sha256Hex(e).slice(0, t); } /** Redacts an identifier to a stable hash label, or "-" for missing values. */ function redactIdentifier(e, t) { const n = normalizeOptionalString(e); if (!n) return "-"; const r = t?.len ?? 12; return `sha256:${sha256HexPrefixCore(n, Number.isFinite(r) ? Math.max(1, Math.floor(r)) : 12)}`; } //#endregion export { sha256StableValue as i, sha256Hex as n, sha256HexPrefixCore as r, redactIdentifier as t };