UNPKG

mcard-js

Version:

MCard - Content-addressable storage with cryptographic hashing, handle resolution, and vector search for Node.js and browsers

21 lines 910 B
export async function computeHash(content) { let contentStr; if (typeof content === 'string') { contentStr = content; } else { // Canonicalize simply by stringifying for now. // In a real system, we'd want deterministic serialization (e.g. json-stable-stringify). // For parity with Python "content: Union[str, bytes]", we assume the input is the // string representation that matches what Python receives. contentStr = JSON.stringify(content); } const encoder = new TextEncoder(); const data = encoder.encode(contentStr); const hashBuffer = await crypto.subtle.digest('SHA-256', data); // Convert buffer to hex string const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); return hashHex; } //# sourceMappingURL=LocalSHA256.js.map