{"version":3,"file":"hash.cjs","names":[],"sources":["../../src/utils/hash.ts"],"sourcesContent":["/**\n * Hashing utilities for IAVL tree.\n * Uses SHA-256 for computing node hashes, compatible with Go's crypto/sha256.\n */\n\nimport {\n  sha256,\n} from \"@noble/hashes/sha2.js\";\n\n/**\n * Computes SHA-256 hash of the input bytes.\n *\n * @param data - Data to hash\n * @returns 32-byte hash\n */\nexport function hash(data: Uint8Array): Uint8Array {\n  return sha256(data);\n}\n\n/**\n * Computes SHA-256 hash of multiple byte arrays concatenated together.\n * This is more efficient than manually concatenating first.\n *\n * @param arrays - Arrays to hash\n * @returns 32-byte hash\n */\nexport function hashConcat(...arrays: Uint8Array[]): Uint8Array {\n  // Calculate total length\n  const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);\n\n  // Concatenate and hash\n  const combined = new Uint8Array(totalLength);\n  let offset = 0;\n  for (const arr of arrays) {\n    combined.set(arr, offset);\n    offset += arr.length;\n  }\n\n  return sha256(combined);\n}\n\n/**\n * Computes SHA-256 hash of a UTF-8 string.\n *\n * @param str - String to hash\n * @returns 32-byte hash\n */\nexport function hashString(str: string): Uint8Array {\n  const encoder = new TextEncoder();\n  return sha256(encoder.encode(str));\n}\n\n/**\n * Size of SHA-256 hash in bytes.\n */\nexport const HASH_SIZE = 32;\n\n/**\n * Creates an empty hash (all zeros).\n * Used as placeholder in some contexts.\n *\n * @returns 32-byte array of zeros\n */\nexport function emptyHash(): Uint8Array {\n  return new Uint8Array(HASH_SIZE);\n}\n"],"mappings":";;;;;;;;;;;AAeA,SAAgB,KAAK,MAA8B;AACjD,2CAAc,KAAK"}