{
  "version": 3,
  "sources": ["../src/sha2.ts", "../src/helpers/hex-to-bytes.ts", "../src/constants.ts", "../src/helpers/encoding.ts", "../src/internal/sha512.ts"],
  "sourcesContent": ["import { ripemd160 as ripemd160Noble } from \"@noble/hashes/legacy.js\";\nimport { sha256 as sha256Noble } from \"@noble/hashes/sha2.js\";\nimport { bufferToHex, utf8ToBuffer } from \"./helpers/encoding\";\nimport { sha512 as sha512Async, sha512Sync } from \"./internal/sha512\";\n\n/**\n * Computes SHA-256 digest.\n * @param msg Input bytes.\n * @returns SHA-256 digest bytes.\n */\nexport async function sha256(msg: Uint8Array): Promise<Uint8Array> {\n  return sha256Noble(msg);\n}\n\n/**\n * Computes SHA-256 digest.\n * @param msg Input bytes.\n * @returns SHA-256 digest bytes.\n */\nexport function sha256Sync(msg: Uint8Array): Uint8Array {\n  return sha256Noble(msg);\n}\n\n/**\n * SHA-256 over UTF-8(`str`), returned as 64-character lowercase hex (no `0x` prefix).\n *\n * @param str Input string.\n * @returns Hex digest string.\n */\nexport async function sha256Utf8Hex(str: string): Promise<string> {\n  return bufferToHex(await sha256(utf8ToBuffer(str)));\n}\n\n/** Synchronous {@link sha256Utf8Hex}. */\nexport function sha256Utf8HexSync(str: string): string {\n  return bufferToHex(sha256Sync(utf8ToBuffer(str)));\n}\n\n/**\n * Computes SHA-512 digest.\n * @param msg Input bytes.\n * @returns SHA-512 digest bytes.\n */\nexport async function sha512(msg: Uint8Array): Promise<Uint8Array> {\n  return sha512Async(msg);\n}\n\nexport { sha512Sync };\n\n/**\n * Computes RIPEMD-160 digest.\n * @param msg Input bytes.\n * @returns RIPEMD-160 digest bytes.\n */\nexport async function ripemd160(msg: Uint8Array): Promise<Uint8Array> {\n  return ripemd160Noble(msg);\n}\n\n/**\n * Computes RIPEMD-160 digest.\n * @param msg Input bytes.\n * @returns RIPEMD-160 digest bytes.\n */\nexport function ripemd160Sync(msg: Uint8Array): Uint8Array {\n  return ripemd160Noble(msg);\n}\n", "/**\n * Hex string \u2192 byte values `0..255`. Odd length implies a leading `0` nibble (unlike {@link hexToBuffer}).\n *\n * @param hex Contiguous hex digits (no `0x` stripping).\n * @returns `number[]` of byte values.\n */\nexport function hexToBytes(hex: string): number[] {\n  const clean = hex.length % 2 ? `0${hex}` : hex;\n  const out: number[] = [];\n  for (let i = 0; i < clean.length; i += 2) {\n    out.push(Number.parseInt(clean.slice(i, i + 2), 16));\n  }\n  return out;\n}\n", "import { hexToBytes } from \"./helpers/hex-to-bytes\";\n\nexport const HEX_ENC = \"hex\";\nexport const UTF8_ENC = \"utf8\";\nexport const BINARY_ENC = \"binary\";\n\nexport const ENCRYPT_OP = \"encrypt\";\nexport const DECRYPT_OP = \"decrypt\";\n\nexport const SIGN_OP = \"sign\";\nexport const VERIFY_OP = \"verify\";\n\nexport const LENGTH_0 = 0;\nexport const LENGTH_1 = 1;\nexport const LENGTH_12 = 12;\nexport const LENGTH_16 = 16;\nexport const LENGTH_32 = 32;\nexport const LENGTH_64 = 64;\nexport const LENGTH_128 = 128;\nexport const LENGTH_256 = 256;\nexport const LENGTH_512 = 512;\nexport const LENGTH_1024 = 1024;\n\nexport const AES_LENGTH = LENGTH_256;\nexport const HMAC_LENGTH = LENGTH_256;\n\nexport const AES_BROWSER_ALGO = \"AES-CBC\";\nexport const HMAC_BROWSER_ALGO = `SHA-${AES_LENGTH}`;\nexport const HMAC_BROWSER = \"HMAC\";\n\nexport const SHA256_BROWSER_ALGO = \"SHA-256\";\nexport const SHA512_BROWSER_ALGO = \"SHA-512\";\n\nexport const AES_NODE_ALGO = `aes-${AES_LENGTH}-cbc`;\nexport const HMAC_NODE_ALGO = `sha${HMAC_LENGTH}`;\n\nexport const SHA256_NODE_ALGO = \"sha256\";\nexport const SHA512_NODE_ALGO = \"sha512\";\nexport const RIPEMD160_NODE_ALGO = \"ripemd160\";\n\nexport const PBKDF2_DIGEST_SHA256 = SHA256_NODE_ALGO;\nexport const PBKDF2_DIGEST_SHA512 = SHA512_NODE_ALGO;\n\nexport const PREFIX_LENGTH = LENGTH_1;\nexport const KEY_LENGTH = LENGTH_32;\nexport const IV_LENGTH = LENGTH_16;\nexport const AES_GCM_NONCE_LENGTH = LENGTH_12;\nexport const AES_GCM_ENVELOPE_NONCE_MAX_LENGTH = LENGTH_128;\nexport const AES_GCM_TAG_LENGTH = LENGTH_16;\nexport const MAC_LENGTH = LENGTH_32;\nexport const DECOMPRESSED_LENGTH = LENGTH_64;\n\nexport const PREFIXED_KEY_LENGTH = KEY_LENGTH + PREFIX_LENGTH;\nexport const PREFIXED_DECOMPRESSED_LENGTH = DECOMPRESSED_LENGTH + PREFIX_LENGTH;\n\nexport const ECIES_SERIALIZED_MIN_LENGTH =\n  IV_LENGTH + PREFIXED_KEY_LENGTH + MAC_LENGTH;\n\nexport const MAX_KEY_LENGTH = LENGTH_1024;\nexport const PBKDF2_DEFAULT_ITERATIONS = 210_000;\nexport const MAX_MSG_LENGTH = LENGTH_32;\n\nexport const EMPTY_BUFFER = new Uint8Array(LENGTH_0);\n\nexport const EC_GROUP_ORDER = new Uint8Array(\n  hexToBytes(\n    \"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141\"\n  )\n);\n\nexport const ZERO32 = new Uint8Array(LENGTH_32).fill(LENGTH_0);\n\nexport const ERROR_BAD_MAC = \"Bad MAC\";\nexport const ERROR_BAD_SIGNATURE = \"Bad signature\";\nexport const ERROR_BAD_PRIVATE_KEY = \"Bad private key\";\nexport const ERROR_BAD_PUBLIC_KEY = \"Bad public key\";\nexport const ERROR_ECIES_SERIALIZED_LENGTH =\n  \"ECIES deserialize: buffer shorter than minimum serialized length\";\n\nexport const ERROR_EMPTY_MESSAGE = \"Message should not be empty\";\nexport const ERROR_MESSAGE_TOO_LONG = \"Message is too long\";\n\nexport const ERROR_BAD_EPHEM_PRIVATE_KEY = \"Invalid ephemeral private key\";\n\nexport const ERROR_AES_IV_LENGTH = \"AES-CBC: IV must be 16 bytes\";\nexport const ERROR_AES_KEY_LENGTH = \"AES-CBC: key must be 32 bytes\";\n\nexport const ERROR_AES_GCM_KEY_LENGTH =\n  \"AES-GCM: key must be 16, 24, or 32 bytes\";\nexport const ERROR_AES_GCM_NONCE_LENGTH =\n  \"AES-GCM: nonce must be at least 8 bytes\";\nexport const ERROR_AES_GCM_CIPHERTEXT_LENGTH =\n  \"AES-GCM: ciphertext must be longer than the authentication tag\";\n", "import {\n  HEX_ENC,\n  LENGTH_0,\n  LENGTH_16,\n  type UTF8_ENC,\n} from \"../constants\";\n\nconst textEncoder = new TextEncoder();\nconst textDecoder = new TextDecoder();\n\n/**\n * Encodes a UTF-8 string into bytes.\n * @param str Input string.\n * @returns UTF-8 encoded bytes.\n */\nexport function utf8ToBuffer(str: string): Uint8Array {\n  return textEncoder.encode(str);\n}\n\n/**\n * Decodes UTF-8 bytes into a string.\n * @param buf UTF-8 encoded bytes.\n * @returns Decoded string.\n */\nexport function bufferToUtf8(buf: Uint8Array): string {\n  return textDecoder.decode(buf);\n}\n\n/**\n * Concatenates multiple byte arrays.\n * @param buffers Byte arrays to concatenate.\n * @returns Concatenated byte array.\n */\nexport function concatBuffers(...buffers: Uint8Array[]): Uint8Array {\n  const total = buffers.reduce((n, b) => n + b.length, LENGTH_0);\n  const out = new Uint8Array(total);\n  let offset = LENGTH_0;\n  for (const b of buffers) {\n    out.set(b, offset);\n    offset += b.length;\n  }\n  return out;\n}\n\n/**\n * Converts bytes to a lowercase hex string.\n * @param buf Input bytes.\n * @param enc Output encoding selector. Only `hex` is accepted.\n * @returns Hex string.\n */\nexport function bufferToHex(\n  buf: Uint8Array,\n  enc: typeof HEX_ENC | typeof UTF8_ENC = HEX_ENC\n): string {\n  if (enc !== HEX_ENC) {\n    throw new Error(\"bufferToHex: only hex encoding is supported\");\n  }\n  let hex = \"\";\n  for (const byte of buf) {\n    hex += byte.toString(16).padStart(2, \"0\");\n  }\n  return hex;\n}\n\n/**\n * Converts a hex string to bytes.\n * @param hex Input hex string, with optional `0x` prefix.\n * @returns Decoded bytes.\n */\nexport function hexToBuffer(hex: string): Uint8Array {\n  const clean = hex.startsWith(\"0x\") ? hex.slice(2) : hex;\n  if (clean.length % 2 !== 0) {\n    throw new Error(\"hexToBuffer: invalid length\");\n  }\n  const out = new Uint8Array(clean.length / 2);\n  for (let i = 0; i < out.length; i++) {\n    const byte = Number.parseInt(clean.slice(i * 2, i * 2 + 2), 16);\n    if (!Number.isFinite(byte) || byte < 0 || byte > 255) {\n      throw new Error(\"hexToBuffer: invalid hex character\");\n    }\n    out[i] = byte;\n  }\n  return out;\n}\n\n/**\n * Removes a leading `0x` prefix from a hex string.\n * @param hex Input hex string.\n * @returns Hex string without prefix.\n */\nexport function sanitizeHex(hex: string): string {\n  return hex.startsWith(\"0x\") ? hex.slice(2) : hex;\n}\n\n/**\n * Removes leading zeros from a hex string.\n * @param hex Input hex string.\n * @returns Hex string without leading zeros.\n */\nexport function removeHexLeadingZeros(hex: string): string {\n  const h = sanitizeHex(hex);\n  const stripped = h.replace(/^0+/, \"\");\n  return stripped.length ? stripped : \"0\";\n}\n\n/**\n * Parses a hex string into a number.\n * @param hex Input hex string.\n * @returns Parsed number.\n */\nexport function hexToNumber(hex: string): number {\n  return Number.parseInt(sanitizeHex(hex), 16);\n}\n\n/**\n * RFC 4648 Base64 from bytes. Chunks `btoa` input to avoid huge spread argument lists.\n *\n * @param buf Input bytes.\n * @returns Base64 string (no line breaks).\n */\nexport function bufferToBase64(buf: Uint8Array): string {\n  const chunk = 0x8000;\n  let binary = \"\";\n  for (let i = 0; i < buf.length; i += chunk) {\n    binary += String.fromCharCode(...buf.subarray(i, i + chunk));\n  }\n  return btoa(binary);\n}\n\n/**\n * RFC 4648 Base64 to bytes (whitespace stripped). Uses `atob`.\n *\n * @param str Base64 string.\n * @returns New `Uint8Array`.\n * @throws {DOMException} Invalid Base64 where `atob` throws.\n */\nexport function base64ToBuffer(str: string): Uint8Array {\n  const normalized = str.replace(/\\s+/g, \"\");\n  const binary = atob(normalized);\n  const out = new Uint8Array(binary.length);\n  for (let i = 0; i < binary.length; i++) {\n    out[i] = binary.charCodeAt(i) & 0xff;\n  }\n  return out;\n}\n\n/**\n * RFC 4648 Base64url without `=` padding (`-`/`_`). Common for JWK `k`.\n *\n * @param buf Input bytes.\n * @returns Base64url string.\n */\nexport function bufferToBase64Url(buf: Uint8Array): string {\n  return bufferToBase64(buf)\n    .replace(/\\+/g, \"-\")\n    .replace(/\\//g, \"_\")\n    .replace(/=+$/, \"\");\n}\n\n/**\n * Base64url to bytes (optional padding; then {@link base64ToBuffer}).\n *\n * @param str Base64url string.\n * @returns New `Uint8Array`.\n * @throws {Error} Length mod 4 === 1 (invalid).\n */\nexport function base64UrlToBuffer(str: string): Uint8Array {\n  let s = str.replace(/-/g, \"+\").replace(/_/g, \"/\");\n  const pad = s.length % 4;\n  if (pad === 2) s += \"==\";\n  else if (pad === 3) s += \"=\";\n  else if (pad === 1) {\n    throw new Error(\"base64UrlToBuffer: invalid length\");\n  }\n  return base64ToBuffer(s);\n}\n\n/**\n * 16-byte AES-128 raw key from `utf8ToBuffer(key.padEnd(16, \" \"))`. Must yield exactly 16 UTF-8 bytes\n * (same constraint as Web Crypto `importKey(\"raw\", \u2026)` for AES-128).\n *\n * @param key Passphrase.\n * @returns 16 key bytes.\n * @throws {Error} UTF-8 length \u2260 16 after padding.\n */\nexport function aes128StringKeyMaterial(key: string): Uint8Array {\n  const padded = key.padEnd(LENGTH_16, \" \");\n  const bytes = textEncoder.encode(padded);\n  if (bytes.length !== LENGTH_16) {\n    throw new Error(\n      \"aes128StringKeyMaterial: padded key must UTF-8 encode to exactly 16 bytes\",\n    );\n  }\n  return bytes;\n}\n\n", "import { sha512 as sha512Noble } from \"@noble/hashes/sha2.js\";\n\n/**\n * Computes SHA-512 digest.\n * @param msg Input bytes.\n * @returns SHA-512 digest bytes.\n */\nexport async function sha512(msg: Uint8Array): Promise<Uint8Array> {\n  return sha512Noble(msg);\n}\n\n/**\n * Computes SHA-512 digest.\n * @param msg Input bytes.\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