UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 937 B
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{n as writeStableStringify}from"./stable-stringify-Cy0VZ0ci.mjs";import{createHash,hash}from"node:crypto";import{Buffer}from"node:buffer"; //!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)}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)}`}export{sha256StableValue as i,sha256Hex as n,sha256HexPrefixCore as r,redactIdentifier as t};