{"version":3,"file":"index.mjs","names":["nobleSha256","nobleSha512","sha256","nobleScrypt","nobleArgon2id","noble","nobleSchnorr","noble","sha512","nobleChacha20"],"sources":["../src/error.ts","../src/memzero.ts","../src/domain.ts","../src/hash.ts","../src/scrypt-core.ts","../src/kdf.ts","../src/aead.ts","../src/x25519.ts","../src/ecdsa.ts","../src/ed25519.ts","../src/stream.ts"],"sourcesContent":["/**\n * The single error type thrown by this package.\n *\n * @module error\n */\nimport { isBytes } from \"@noble/hashes/utils.js\";\n\n/** Machine-readable discriminant for a {@link CryptoError}. */\nexport type CryptoErrorCode =\n  \"InvalidSize\" | \"InvalidData\" | \"InvalidParameter\" | \"AuthenticationFailed\";\n\n/**\n * The structured payload of a {@link CryptoError}, discriminated by `code`:\n * `e.details.code === \"InvalidSize\"` narrows to `{ what, expected, actual }`.\n */\nexport type CryptoErrorDetails =\n  | {\n      /** A key, nonce, signature, tag or sealed buffer had the wrong length. */\n      readonly code: \"InvalidSize\";\n      /** The argument, e.g. `\"ECDSA private key\"`. */\n      readonly what: string;\n      /** The required length in bytes. */\n      readonly expected: number;\n      /** The length received. */\n      readonly actual: number;\n    }\n  | {\n      /** A key, point or signature of the right length that is not valid. */\n      readonly code: \"InvalidData\";\n      /** The argument, e.g. `\"ECDSA compressed public key\"`. */\n      readonly what: string;\n    }\n  | {\n      /**\n       * An argument outside its domain: a number that is not an integer of\n       * the Rust width, an options object that is not an object, a boolean\n       * option that is not a boolean, or a byte argument that is not a\n       * `Uint8Array`. Also a KDF parameter set the backend rejects.\n       */\n      readonly code: \"InvalidParameter\";\n      /** The argument, e.g. `\"scrypt logN\"` or `\"ECDSA message\"`. */\n      readonly what: string;\n    }\n  | {\n      /** AEAD authentication failed: wrong key, nonce or aad, or tampered data. */\n      readonly code: \"AuthenticationFailed\";\n    };\n\n/**\n * Thrown for wrong-length keys, nonces, signatures and public keys\n * (`InvalidSize`), a key, point or signature of the right length that is not\n * valid (`InvalidData`), an argument outside its domain, including a value\n * of the wrong type (`InvalidParameter`), and AEAD tag mismatch\n * (`AuthenticationFailed`).\n *\n * Every failure of an argument or of a primitive is a `CryptoError`; when a\n * backend error is what was caught, it is the `cause`. Two things propagate\n * unwrapped, because they are not this package's: a generator's own error\n * (`RandError` from `@blockchaincommons/rand`, including `InvalidGenerator`\n * for a generator that lacks a method the draw calls), and an allocation\n * failure outside the KDFs (`RangeError` from the engine). Instances come\n * from the static factories only.\n *\n * @example\n * ```ts\n * try {\n *   chacha20Poly1305.decrypt(key, nonce, sealed);\n * } catch (e) {\n *   if (CryptoError.isCryptoError(e) && e.is(\"AuthenticationFailed\")) {\n *     // tampered\n *   }\n * }\n * ```\n */\nexport class CryptoError extends Error {\n  /** Always `\"CryptoError\"`; the cross-copy identity {@link CryptoError.isCryptoError} checks. */\n  override readonly name = \"CryptoError\";\n  /** The discriminant; equals `details.code`. */\n  readonly code: CryptoErrorCode;\n  /** The structured payload, discriminated by `code`. */\n  readonly details: CryptoErrorDetails;\n\n  private constructor(message: string, details: CryptoErrorDetails, cause?: unknown) {\n    super(message, cause === undefined ? undefined : { cause });\n    this.code = details.code;\n    this.details = details;\n  }\n\n  /** Type guard for a `CryptoError`, including one from another copy of this package. */\n  static isCryptoError(value: unknown): value is CryptoError {\n    return value instanceof Error && value.name === \"CryptoError\" && \"code\" in value;\n  }\n\n  /** `true` when `code` is this error's code. */\n  is(code: CryptoErrorCode): boolean {\n    return this.code === code;\n  }\n\n  /** `what` had `actual` bytes; `expected` were required. */\n  static invalidSize(what: string, expected: number, actual: number): CryptoError {\n    return new CryptoError(`${what} must be ${expected} bytes, got ${actual}`, {\n      code: \"InvalidSize\",\n      what,\n      expected,\n      actual,\n    });\n  }\n\n  /** `what` has the right length but is not a valid key, point or signature. */\n  static invalidData(what: string, message: string, cause?: unknown): CryptoError {\n    return new CryptoError(message, { code: \"InvalidData\", what }, cause);\n  }\n\n  /** `what` (a number, an options object or a byte argument) is outside its domain. */\n  static invalidParameter(what: string, message: string, cause?: unknown): CryptoError {\n    return new CryptoError(message, { code: \"InvalidParameter\", what }, cause);\n  }\n\n  /** AEAD authentication failed (wrong key, nonce, aad, or tampered data). */\n  static authenticationFailed(cause?: unknown): CryptoError {\n    // The reference's `Error::Aead` displays as \"AEAD error\".\n    return new CryptoError(\"AEAD error\", { code: \"AuthenticationFailed\" }, cause);\n  }\n}\n\n/** @internal A short description of a rejected value for `got …` clauses. */\nexport function describeValue(value: unknown): string {\n  if (value === null) return \"null\";\n  if (Array.isArray(value)) return `Array(${value.length})`;\n  if (typeof value !== \"object\") return typeof value;\n  const proto = Object.getPrototypeOf(value) as { constructor?: { name?: unknown } } | null;\n  const name = proto?.constructor?.name;\n  return typeof name === \"string\" && name !== \"\" ? name : \"object\";\n}\n\n/**\n * @internal `value` must be a `Uint8Array` (from any realm; a `Buffer` is\n * one). Every byte argument is checked this way before any other precondition,\n * so a string, array or `ArrayBuffer` is `InvalidParameter` naming `what`.\n */\nexport function requireBytes(what: string, value: unknown): asserts value is Uint8Array {\n  if (!isBytes(value)) {\n    throw CryptoError.invalidParameter(\n      what,\n      `${what} must be a Uint8Array, got ${describeValue(value)}`,\n    );\n  }\n}\n\n/**\n * @internal An options argument must be an object. An optional one may be\n * `undefined`; a required one may not.\n */\nexport function requireOptions(\n  what: string,\n  value: unknown,\n  optional: boolean,\n): asserts value is object | undefined {\n  if (value === undefined && optional) return;\n  if (typeof value !== \"object\" || value === null) {\n    throw CryptoError.invalidParameter(\n      what,\n      `${what} must be an object, got ${describeValue(value)}`,\n    );\n  }\n}\n\n/** @internal A boolean option: `undefined` (absent) or a boolean. Returns it. */\nexport function expectBool(what: string, value: unknown): boolean | undefined {\n  if (value === undefined) return undefined;\n  if (typeof value !== \"boolean\") {\n    throw CryptoError.invalidParameter(\n      what,\n      `${what} must be a boolean, got ${describeValue(value)}`,\n    );\n  }\n  return value;\n}\n\n/**\n * @internal Length precondition shared by the key and signature functions.\n * The type check comes first, so a non-`Uint8Array` is `InvalidParameter`\n * and a wrong length is `InvalidSize`.\n */\nexport function requireLength(\n  what: string,\n  bytes: unknown,\n  expected: number,\n): asserts bytes is Uint8Array {\n  requireBytes(what, bytes);\n  if (bytes.length !== expected) throw CryptoError.invalidSize(what, expected, bytes.length);\n}\n","/**\n * Best-effort zeroing of secret buffers.\n *\n * @module memzero\n */\nimport { CryptoError, describeValue } from \"./error.js\";\n\n/** The typed arrays {@link memzero} zeroes: every numeric kind, not `BigInt64Array`/`BigUint64Array` or a `DataView`. */\nexport type NumericTypedArray =\n  | Uint8Array\n  | Uint8ClampedArray\n  | Uint16Array\n  | Uint32Array\n  | Int8Array\n  | Int16Array\n  | Int32Array\n  | Float32Array\n  | Float64Array;\n\n// Cross-realm safe: the tag comes from `Symbol.toStringTag`, not from `instanceof`.\nconst NUMERIC_TYPED_ARRAY_TAGS = new Set([\n  \"[object Uint8Array]\",\n  \"[object Uint8ClampedArray]\",\n  \"[object Uint16Array]\",\n  \"[object Uint32Array]\",\n  \"[object Int8Array]\",\n  \"[object Int16Array]\",\n  \"[object Int32Array]\",\n  \"[object Float32Array]\",\n  \"[object Float64Array]\",\n]);\n\nfunction requireNumericTypedArray(\n  what: string,\n  value: unknown,\n): asserts value is NumericTypedArray {\n  if (!NUMERIC_TYPED_ARRAY_TAGS.has(Object.prototype.toString.call(value))) {\n    throw CryptoError.invalidParameter(\n      what,\n      `${what} must be a numeric typed array, got ${describeValue(value)}`,\n    );\n  }\n}\n\n/**\n * Overwrite every element with zero.\n * @throws {CryptoError} `InvalidParameter` unless `data` is a numeric typed array.\n */\nexport function memzero(data: NumericTypedArray): void {\n  requireNumericTypedArray(\"memzero data\", data);\n  data.fill(0);\n}\n\n/**\n * {@link memzero} each array.\n * @throws {CryptoError} `InvalidParameter` unless `arrays` is an array of numeric typed arrays.\n */\nexport function memzeroAll(arrays: readonly NumericTypedArray[]): void {\n  const list: unknown = arrays;\n  if (!Array.isArray(list)) {\n    throw CryptoError.invalidParameter(\n      \"memzeroAll arrays\",\n      `memzeroAll arrays must be an array, got ${describeValue(list)}`,\n    );\n  }\n  for (const arr of list as readonly unknown[]) memzero(arr as NumericTypedArray);\n}\n","/**\n * Argument-domain checks and the boundary that turns a backend's throw into\n * a {@link CryptoError}.\n *\n * TypeScript has no integer widths: a `u32` parameter is a `number` that must\n * be an integer in `[0, 2^32 - 1]`. Every check names the argument and uses\n * one message shape, `\"<what> must be an integer in [<min>, <max>], got <value>\"`.\n *\n * @module domain\n */\nimport { CryptoError } from \"./error.js\";\n\n/** Throws `InvalidParameter` unless `value` is an integer `number` in `[min, max]`. Returns it. */\nexport function expectInt(what: string, value: number, min: number, max: number): number {\n  if (!Number.isInteger(value) || value < min || value > max) {\n    throw CryptoError.invalidParameter(\n      what,\n      `${what} must be an integer in [${min}, ${max}], got ${String(value)}`,\n    );\n  }\n  return value;\n}\n\n/** Throws `InvalidParameter` unless `bytes` has at least `min` bytes. Returns it. */\nexport function expectMinLength(what: string, bytes: Uint8Array, min: number): Uint8Array {\n  if (bytes.length < min) {\n    throw CryptoError.invalidParameter(\n      what,\n      `${what} must be at least ${min} bytes, got ${bytes.length}`,\n    );\n  }\n  return bytes;\n}\n\n/**\n * Runs `fn`; a throw that is not already a {@link CryptoError} is replaced by\n * `wrap(cause)`, so no backend error crosses the package boundary.\n */\nexport function guard<T>(fn: () => T, wrap: (cause: unknown) => CryptoError): T {\n  try {\n    return fn();\n  } catch (e) {\n    if (e instanceof CryptoError) throw e;\n    throw wrap(e);\n  }\n}\n\n/** The wrap for a KDF backend that rejects parameters the domain checks let through (e.g. scrypt's memory limit). */\nexport const backendRejected =\n  (what: string) =>\n  (cause: unknown): CryptoError =>\n    CryptoError.invalidParameter(\n      what,\n      `${what} rejected by the backend: ${cause instanceof Error ? cause.message : String(cause)}`,\n      cause,\n    );\n\n/** The wrap for a point decoder: bytes of the right length that are not a point on the curve. */\nexport const invalidPoint =\n  (what: string) =>\n  (cause: unknown): CryptoError =>\n    CryptoError.invalidData(what, `${what} is not a point on the curve`, cause);\n\nexport const U32_MAX = 0xffffffff;\n","/**\n * Hashes, MACs, key derivation, and CRC-32.\n *\n * @module hash\n */\nimport { sha256 as nobleSha256, sha512 as nobleSha512 } from \"@noble/hashes/sha2.js\";\nimport { hmac } from \"@noble/hashes/hmac.js\";\nimport { pbkdf2 } from \"@noble/hashes/pbkdf2.js\";\nimport { hkdf } from \"@noble/hashes/hkdf.js\";\nimport { expectBool, requireBytes, requireOptions } from \"./error.js\";\nimport { backendRejected, expectInt, guard, U32_MAX } from \"./domain.js\";\n\n/** Bytes in a CRC-32 checksum. */\nexport const CRC32_SIZE = 4;\n/** Bytes in a SHA-256 digest. */\nexport const SHA256_SIZE = 32;\n/** Bytes in a SHA-512 digest. */\nexport const SHA512_SIZE = 64;\n\n// CRC-32 lookup table (IEEE polynomial 0xedb88320), built once.\nconst CRC32_TABLE = new Uint32Array(256);\nfor (let i = 0; i < 256; i++) {\n  let crc = i;\n  for (let j = 0; j < 8; j++) crc = (crc & 1) !== 0 ? (crc >>> 1) ^ 0xedb88320 : crc >>> 1;\n  CRC32_TABLE[i] = crc >>> 0;\n}\n\n/**\n * CRC-32 (IEEE 802.3 / ISO-HDLC) as an unsigned 32-bit integer.\n * @throws {CryptoError} `InvalidParameter` unless `data` is a `Uint8Array`.\n */\nexport function crc32(data: Uint8Array): number {\n  requireBytes(\"crc32 data\", data);\n  let crc = 0xffffffff;\n  // Indexed loop: the iterator protocol over a typed array is 2× slower here.\n  // eslint-disable-next-line @typescript-eslint/prefer-for-of\n  for (let i = 0; i < data.length; i++) {\n    crc = CRC32_TABLE[(crc ^ data[i]) & 0xff] ^ (crc >>> 8);\n  }\n  return (crc ^ 0xffffffff) >>> 0;\n}\n\n/** Options for {@link crc32Bytes}. */\nexport interface Crc32Options {\n  /** Emit the checksum little-endian. Default: big-endian. */\n  readonly littleEndian?: boolean | undefined;\n}\n\n/**\n * CRC-32 as four bytes, big-endian unless `littleEndian` is set.\n * @throws {CryptoError} `InvalidParameter` unless `data` is a `Uint8Array`,\n * `options` an object (or absent) and `littleEndian` a boolean (or absent).\n */\nexport function crc32Bytes(data: Uint8Array, options?: Crc32Options): Uint8Array<ArrayBuffer> {\n  requireBytes(\"crc32 data\", data);\n  requireOptions(\"crc32 options\", options, true);\n  const littleEndian = expectBool(\"crc32 littleEndian\", options?.littleEndian) ?? false;\n  const result = new Uint8Array(4);\n  new DataView(result.buffer).setUint32(0, crc32(data), littleEndian);\n  return result;\n}\n\n/**\n * SHA-256 of `data` (32 bytes).\n * @throws {CryptoError} `InvalidParameter` unless `data` is a `Uint8Array`.\n */\nexport function sha256(data: Uint8Array): Uint8Array<ArrayBuffer> {\n  requireBytes(\"sha256 data\", data);\n  return nobleSha256(data);\n}\n\n/**\n * `sha256(sha256(data))`, the Bitcoin message hash.\n * @throws {CryptoError} `InvalidParameter` unless `data` is a `Uint8Array`.\n */\nexport function doubleSha256(data: Uint8Array): Uint8Array<ArrayBuffer> {\n  requireBytes(\"doubleSha256 data\", data);\n  return nobleSha256(nobleSha256(data));\n}\n\n/**\n * SHA-512 of `data` (64 bytes).\n * @throws {CryptoError} `InvalidParameter` unless `data` is a `Uint8Array`.\n */\nexport function sha512(data: Uint8Array): Uint8Array<ArrayBuffer> {\n  requireBytes(\"sha512 data\", data);\n  return nobleSha512(data);\n}\n\n/**\n * HMAC-SHA-256 of `message` under `key` (32 bytes).\n * @throws {CryptoError} `InvalidParameter` unless both arguments are `Uint8Array`s.\n */\nexport function hmacSha256(key: Uint8Array, message: Uint8Array): Uint8Array<ArrayBuffer> {\n  requireBytes(\"hmacSha256 key\", key);\n  requireBytes(\"hmacSha256 message\", message);\n  return hmac(nobleSha256, key, message);\n}\n\n/**\n * HMAC-SHA-512 of `message` under `key` (64 bytes).\n * @throws {CryptoError} `InvalidParameter` unless both arguments are `Uint8Array`s.\n */\nexport function hmacSha512(key: Uint8Array, message: Uint8Array): Uint8Array<ArrayBuffer> {\n  requireBytes(\"hmacSha512 key\", key);\n  requireBytes(\"hmacSha512 message\", message);\n  return hmac(nobleSha512, key, message);\n}\n\n/** Options for the PBKDF2 functions. */\nexport interface Pbkdf2Options {\n  /**\n   * PBKDF2 iteration count; an integer in [0, 2^32 − 1]. 0 derives what 1\n   * does: the reference's `pbkdf2` 0.12.2 computes the first block of each\n   * output block and then `rounds − 1` more, none for 0 or 1.\n   */\n  readonly iterations: number;\n  /**\n   * Derived key length in bytes; an integer in [0, (2^32 − 1) · hLen]\n   * (RFC 8018 §5.2, hLen 32 or 64). 0 is an empty key on both sides. An\n   * allocation the host cannot make surfaces as `InvalidParameter` with the\n   * engine error as `cause`.\n   */\n  readonly dkLen: number;\n}\n\nconst pbkdf2Domain = (options: Pbkdf2Options, hLen: number): { c: number; dkLen: number } => ({\n  // 0 iterations is 1 in the reference's crate (`for _ in 1..rounds` after the\n  // first block); noble requires c ≥ 1, so the same call is made for both.\n  c: Math.max(1, expectInt(\"pbkdf2 iterations\", options.iterations, 0, U32_MAX)),\n  // `dkLen: 0` is an empty key on both sides (the reference fills a zero-length Vec).\n  dkLen: expectInt(\"pbkdf2 dkLen\", options.dkLen, 0, U32_MAX * hLen),\n});\n\n/**\n * PBKDF2-HMAC-SHA-256.\n * @throws {CryptoError} `InvalidParameter` unless `password` and `salt` are\n * `Uint8Array`s, `options` is an object, `iterations` an integer in\n * [0, 2^32 − 1] and `dkLen` an integer in [0, (2^32 − 1) · 32].\n */\nexport function pbkdf2Sha256(\n  password: Uint8Array,\n  salt: Uint8Array,\n  options: Pbkdf2Options,\n): Uint8Array<ArrayBuffer> {\n  requireBytes(\"pbkdf2 password\", password);\n  requireBytes(\"pbkdf2 salt\", salt);\n  requireOptions(\"pbkdf2 options\", options, false);\n  const domain = pbkdf2Domain(options, SHA256_SIZE);\n  if (domain.dkLen === 0) return new Uint8Array(0);\n  return guard(\n    () => pbkdf2(nobleSha256, password, salt, domain),\n    backendRejected(\"pbkdf2 parameters\"),\n  );\n}\n\n/**\n * PBKDF2-HMAC-SHA-512.\n * @throws {CryptoError} `InvalidParameter` unless `password` and `salt` are\n * `Uint8Array`s, `options` is an object, `iterations` an integer in\n * [0, 2^32 − 1] and `dkLen` an integer in [0, (2^32 − 1) · 64].\n */\nexport function pbkdf2Sha512(\n  password: Uint8Array,\n  salt: Uint8Array,\n  options: Pbkdf2Options,\n): Uint8Array<ArrayBuffer> {\n  requireBytes(\"pbkdf2 password\", password);\n  requireBytes(\"pbkdf2 salt\", salt);\n  requireOptions(\"pbkdf2 options\", options, false);\n  const domain = pbkdf2Domain(options, SHA512_SIZE);\n  if (domain.dkLen === 0) return new Uint8Array(0);\n  return guard(\n    () => pbkdf2(nobleSha512, password, salt, domain),\n    backendRejected(\"pbkdf2 parameters\"),\n  );\n}\n\n/** Options for the HKDF functions. */\nexport interface HkdfOptions {\n  /** Derived key length in bytes; at most 255 × the hash length. */\n  readonly dkLen: number;\n}\n\n/**\n * HKDF-SHA-256 with no `info`, `dkLen` output bytes.\n * @throws {CryptoError} `InvalidParameter` unless `keyMaterial` and `salt`\n * are `Uint8Array`s, `options` is an object and `dkLen` an integer in [0, 255 · 32].\n */\nexport function hkdfSha256(\n  keyMaterial: Uint8Array,\n  salt: Uint8Array,\n  options: HkdfOptions,\n): Uint8Array<ArrayBuffer> {\n  requireBytes(\"hkdf key material\", keyMaterial);\n  requireBytes(\"hkdf salt\", salt);\n  requireOptions(\"hkdf options\", options, false);\n  const dkLen = expectInt(\"hkdf dkLen\", options.dkLen, 0, 255 * SHA256_SIZE);\n  return guard(\n    () => hkdf(nobleSha256, keyMaterial, salt, undefined, dkLen),\n    backendRejected(\"hkdf parameters\"),\n  );\n}\n\n/**\n * HKDF-SHA-512 with no `info`, `dkLen` output bytes.\n * @throws {CryptoError} `InvalidParameter` unless `keyMaterial` and `salt`\n * are `Uint8Array`s, `options` is an object and `dkLen` an integer in [0, 255 · 64].\n */\nexport function hkdfSha512(\n  keyMaterial: Uint8Array,\n  salt: Uint8Array,\n  options: HkdfOptions,\n): Uint8Array<ArrayBuffer> {\n  requireBytes(\"hkdf key material\", keyMaterial);\n  requireBytes(\"hkdf salt\", salt);\n  requireOptions(\"hkdf options\", options, false);\n  const dkLen = expectInt(\"hkdf dkLen\", options.dkLen, 0, 255 * SHA512_SIZE);\n  return guard(\n    () => hkdf(nobleSha512, keyMaterial, salt, undefined, dkLen),\n    backendRejected(\"hkdf parameters\"),\n  );\n}\n","/**\n * RFC 7914 scrypt over paged working memory.\n *\n * noble keeps `V` (128·r·N bytes) and `B` (128·r·p bytes) each in one typed\n * array, and JavaScriptCore (Bun, Safari) holds at most 2^32 bytes in one,\n * so parameter sets the reference derives with (for example logN 22, r 9,\n * 4.8 GiB) cannot run there. This core keeps both in pages of whole\n * 128·r-byte blocks, each page at most `pageBytes` (2^30 by default), and\n * {@link scrypt} dispatches to it only when a working buffer would exceed\n * 2^31 bytes; everything smaller goes to noble, which is faster. The bytes\n * are identical to noble's and to the reference's (`scrypt` 0.11.0).\n *\n * @module scrypt-core\n * @internal\n */\nimport { hmac } from \"@noble/hashes/hmac.js\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { rotl, swap32IfBE } from \"@noble/hashes/utils.js\";\n\n/** Parameters for {@link scryptCore}; already validated by the caller. */\nexport interface ScryptCoreParams {\n  /** CPU/memory cost, a power of two in [1, 2^32] (N = 1: one block of `V`, mixed once). */\n  readonly N: number;\n  /** Block size factor ≥ 1. */\n  readonly r: number;\n  /** Parallelism ≥ 1. */\n  readonly p: number;\n  /** Output length ≥ 1. */\n  readonly dkLen: number;\n  /** Largest page in bytes; a page always holds at least one 128·r-byte block. Tests use tiny pages. */\n  readonly pageBytes?: number | undefined;\n}\n\nconst DEFAULT_PAGE_BYTES = 2 ** 30;\n\n/** `units` blocks of `unitWords` 32-bit words, in pages of whole blocks. */\nclass PagedBlocks {\n  readonly pages: Uint32Array[] = [];\n  readonly unitsPerPage: number;\n  constructor(\n    units: number,\n    readonly unitWords: number,\n    pageBytes: number,\n  ) {\n    this.unitsPerPage = Math.max(1, Math.floor(pageBytes / (unitWords * 4)));\n    for (let done = 0; done < units; done += this.unitsPerPage) {\n      const n = Math.min(this.unitsPerPage, units - done);\n      this.pages.push(new Uint32Array(n * unitWords));\n    }\n  }\n  /** The page holding block `i` and the block's word offset in it. */\n  page(i: number): Uint32Array {\n    return this.pages[Math.floor(i / this.unitsPerPage)];\n  }\n  offset(i: number): number {\n    return (i % this.unitsPerPage) * this.unitWords;\n  }\n  /** The bytes of every page, in page order. */\n  bytes(): Uint8Array[] {\n    return this.pages.map((page) => new Uint8Array(page.buffer, page.byteOffset, page.byteLength));\n  }\n}\n\n/** `out[oi..oi+16] = Salsa20/8(a[ai..ai+16] xor b[bi..bi+16])` (RFC 7914 §3). */\nfunction salsa20_8Xor(\n  out: Uint32Array,\n  oi: number,\n  a: Uint32Array,\n  ai: number,\n  b: Uint32Array,\n  bi: number,\n): void {\n  const i0 = a[ai] ^ b[bi],\n    i1 = a[ai + 1] ^ b[bi + 1],\n    i2 = a[ai + 2] ^ b[bi + 2],\n    i3 = a[ai + 3] ^ b[bi + 3],\n    i4 = a[ai + 4] ^ b[bi + 4],\n    i5 = a[ai + 5] ^ b[bi + 5],\n    i6 = a[ai + 6] ^ b[bi + 6],\n    i7 = a[ai + 7] ^ b[bi + 7],\n    i8 = a[ai + 8] ^ b[bi + 8],\n    i9 = a[ai + 9] ^ b[bi + 9],\n    i10 = a[ai + 10] ^ b[bi + 10],\n    i11 = a[ai + 11] ^ b[bi + 11],\n    i12 = a[ai + 12] ^ b[bi + 12],\n    i13 = a[ai + 13] ^ b[bi + 13],\n    i14 = a[ai + 14] ^ b[bi + 14],\n    i15 = a[ai + 15] ^ b[bi + 15];\n  let x0 = i0,\n    x1 = i1,\n    x2 = i2,\n    x3 = i3,\n    x4 = i4,\n    x5 = i5,\n    x6 = i6,\n    x7 = i7,\n    x8 = i8,\n    x9 = i9,\n    x10 = i10,\n    x11 = i11,\n    x12 = i12,\n    x13 = i13,\n    x14 = i14,\n    x15 = i15;\n  // Eight rounds: four double-rounds of column then row quarter-rounds.\n  for (let round = 0; round < 8; round += 2) {\n    x4 ^= rotl((x0 + x12) | 0, 7);\n    x8 ^= rotl((x4 + x0) | 0, 9);\n    x12 ^= rotl((x8 + x4) | 0, 13);\n    x0 ^= rotl((x12 + x8) | 0, 18);\n    x9 ^= rotl((x5 + x1) | 0, 7);\n    x13 ^= rotl((x9 + x5) | 0, 9);\n    x1 ^= rotl((x13 + x9) | 0, 13);\n    x5 ^= rotl((x1 + x13) | 0, 18);\n    x14 ^= rotl((x10 + x6) | 0, 7);\n    x2 ^= rotl((x14 + x10) | 0, 9);\n    x6 ^= rotl((x2 + x14) | 0, 13);\n    x10 ^= rotl((x6 + x2) | 0, 18);\n    x3 ^= rotl((x15 + x11) | 0, 7);\n    x7 ^= rotl((x3 + x15) | 0, 9);\n    x11 ^= rotl((x7 + x3) | 0, 13);\n    x15 ^= rotl((x11 + x7) | 0, 18);\n    x1 ^= rotl((x0 + x3) | 0, 7);\n    x2 ^= rotl((x1 + x0) | 0, 9);\n    x3 ^= rotl((x2 + x1) | 0, 13);\n    x0 ^= rotl((x3 + x2) | 0, 18);\n    x6 ^= rotl((x5 + x4) | 0, 7);\n    x7 ^= rotl((x6 + x5) | 0, 9);\n    x4 ^= rotl((x7 + x6) | 0, 13);\n    x5 ^= rotl((x4 + x7) | 0, 18);\n    x11 ^= rotl((x10 + x9) | 0, 7);\n    x8 ^= rotl((x11 + x10) | 0, 9);\n    x9 ^= rotl((x8 + x11) | 0, 13);\n    x10 ^= rotl((x9 + x8) | 0, 18);\n    x12 ^= rotl((x15 + x14) | 0, 7);\n    x13 ^= rotl((x12 + x15) | 0, 9);\n    x14 ^= rotl((x13 + x12) | 0, 13);\n    x15 ^= rotl((x14 + x13) | 0, 18);\n  }\n  out[oi] = (i0 + x0) | 0;\n  out[oi + 1] = (i1 + x1) | 0;\n  out[oi + 2] = (i2 + x2) | 0;\n  out[oi + 3] = (i3 + x3) | 0;\n  out[oi + 4] = (i4 + x4) | 0;\n  out[oi + 5] = (i5 + x5) | 0;\n  out[oi + 6] = (i6 + x6) | 0;\n  out[oi + 7] = (i7 + x7) | 0;\n  out[oi + 8] = (i8 + x8) | 0;\n  out[oi + 9] = (i9 + x9) | 0;\n  out[oi + 10] = (i10 + x10) | 0;\n  out[oi + 11] = (i11 + x11) | 0;\n  out[oi + 12] = (i12 + x12) | 0;\n  out[oi + 13] = (i13 + x13) | 0;\n  out[oi + 14] = (i14 + x14) | 0;\n  out[oi + 15] = (i15 + x15) | 0;\n}\n\n/**\n * `out[oi..] = BlockMix(input[ii..])` over `2r` 64-byte sub-blocks (RFC 7914\n * §4): `X = B[2r−1]; for i: X = Salsa(X xor B[i]); Y[i] = X`, with the even\n * `Y` first and the odd `Y` after them. `out` may not overlap `input`.\n */\nfunction blockMix(input: Uint32Array, ii: number, out: Uint32Array, oi: number, r: number): void {\n  let even = oi;\n  let odd = oi + 16 * r;\n  // The running X starts as the last sub-block; the first odd slot holds it\n  // until that slot is written (its consumer runs first).\n  const last = ii + (2 * r - 1) * 16;\n  for (let t = 0; t < 16; t++) out[odd + t] = input[last + t];\n  let prev = odd;\n  for (let i = 0; i < r; i++) {\n    salsa20_8Xor(out, even, out, prev, input, ii + 32 * i); // Y[2i]\n    salsa20_8Xor(out, odd, out, even, input, ii + 32 * i + 16); // Y[2i+1]\n    prev = odd;\n    even += 16;\n    odd += 16;\n  }\n}\n\n/** One big-endian 32-bit block index, as PBKDF2's `INT(i)`. */\nfunction int32be(i: number): Uint8Array {\n  return Uint8Array.from([(i >>> 24) & 0xff, (i >>> 16) & 0xff, (i >>> 8) & 0xff, i & 0xff]);\n}\n\n/**\n * The scrypt KDF of RFC 7914 with `V` and `B` in pages. `password` and\n * `salt` are used as given; the caller validates the parameters.\n */\nexport function scryptCore(\n  password: Uint8Array,\n  salt: Uint8Array,\n  { N, r, p, dkLen, pageBytes = DEFAULT_PAGE_BYTES }: ScryptCoreParams,\n): Uint8Array<ArrayBuffer> {\n  const unitWords = 32 * r; // 128·r bytes\n  const B = new PagedBlocks(p, unitWords, pageBytes);\n  const V = new PagedBlocks(N, unitWords, pageBytes);\n\n  // B = PBKDF2-HMAC-SHA-256(P, S, 1, 128·r·p), block by block into the pages:\n  // T_i = HMAC(P, S ‖ INT(i)). A page holds whole 128·r-byte blocks, so a\n  // 32-byte T_i never straddles two pages.\n  const prf = hmac.create(sha256, password);\n  let block = 1;\n  for (const bytes of B.bytes()) {\n    for (let off = 0; off < bytes.length; off += 32, block++) {\n      bytes.set(prf.clone().update(salt).update(int32be(block)).digest(), off);\n    }\n  }\n  for (const page of B.pages) swap32IfBE(page);\n\n  const X = new Uint32Array(unitWords);\n  const T = new Uint32Array(unitWords);\n  for (let unit = 0; unit < p; unit++) {\n    const bPage = B.page(unit);\n    const bOff = B.offset(unit);\n    // V[0] = B_unit; V[j] = BlockMix(V[j−1]); X = BlockMix(V[N−1]).\n    V.page(0).set(bPage.subarray(bOff, bOff + unitWords), V.offset(0));\n    for (let j = 1; j < N; j++) {\n      blockMix(V.page(j - 1), V.offset(j - 1), V.page(j), V.offset(j), r);\n    }\n    blockMix(V.page(N - 1), V.offset(N - 1), X, 0, r);\n    // X = BlockMix(X xor V[Integerify(X) mod N]), N times. Integerify reads\n    // the first word of the last sub-block; N is a power of two ≤ 2^32.\n    for (let j = 0; j < N; j++) {\n      const k = (X[unitWords - 16] & (N - 1)) >>> 0;\n      const kPage = V.page(k);\n      const kOff = V.offset(k);\n      for (let t = 0; t < unitWords; t++) T[t] = X[t] ^ kPage[kOff + t];\n      blockMix(T, 0, X, 0, r);\n    }\n    bPage.set(X, bOff);\n  }\n  for (const page of B.pages) swap32IfBE(page);\n\n  // DK = PBKDF2-HMAC-SHA-256(P, B, 1, dkLen): one HMAC state absorbs the\n  // whole of B once; each output block clones it and appends INT(i).\n  const base = hmac.create(sha256, password);\n  for (const bytes of B.bytes()) base.update(bytes);\n  const out = new Uint8Array(dkLen);\n  for (let i = 1, off = 0; off < dkLen; i++, off += 32) {\n    const t = base.clone().update(int32be(i)).digest();\n    out.set(t.subarray(0, Math.min(32, dkLen - off)), off);\n  }\n  for (const page of V.pages) page.fill(0);\n  for (const page of B.pages) page.fill(0);\n  X.fill(0);\n  T.fill(0);\n  return out;\n}\n","/**\n * Password-based key derivation: scrypt and Argon2id.\n *\n * @module kdf\n */\nimport { scrypt as nobleScrypt } from \"@noble/hashes/scrypt.js\";\nimport { argon2id as nobleArgon2id } from \"@noble/hashes/argon2.js\";\nimport { CryptoError, requireBytes, requireOptions } from \"./error.js\";\nimport { backendRejected, expectInt, expectMinLength, guard, U32_MAX } from \"./domain.js\";\nimport { scryptCore } from \"./scrypt-core.js\";\n\n/**\n * A working buffer larger than this goes to the paged core: every engine\n * can hold 2^31 bytes in one typed array, JavaScriptCore no more than 2^32.\n */\nconst SINGLE_BUFFER_LIMIT = 2 ** 31;\n\n/** Options for {@link scrypt}. Defaults are the reference parameters. */\nexport interface ScryptOptions {\n  /**\n   * Derived key length in bytes. With any of `logN`, `r`, `p` given it must\n   * be in `[10, 64]` (the reference's parameterised path, `scrypt::Params::new`);\n   * with the defaults any length ≥ 1 is accepted (the reference's default path).\n   */\n  readonly dkLen: number;\n  /**\n   * log₂ of the CPU/memory cost `N`. Default 17 (N = 131072). An integer in\n   * [0, 32] and below `16·r` (`scrypt::Params::new`); 0 is N = 1, which the\n   * reference derives with. Values above 32 need at least 3.3 TiB.\n   */\n  readonly logN?: number | undefined;\n  /** Block size. Default 8. */\n  readonly r?: number | undefined;\n  /** Parallelism. Default 1. `r·p` must be below 2^30. */\n  readonly p?: number | undefined;\n  /**\n   * An optional ceiling in bytes on the working memory, `128·r·(N + p + 1)`.\n   * By default there is none, as in the reference, which allocates whatever\n   * the parameters imply; a parameter set above the ceiling is\n   * `InvalidParameter`. A ceiling does not bypass the `logN` limit or the\n   * runtime's allocation limits.\n   */\n  readonly maxmem?: number | undefined;\n}\n\n/** The output length `scrypt::scrypt` accepts: `(2^32 − 1) · 32`. */\nconst SCRYPT_MAX_DKLEN = 0xffffffff * 32;\n\n/**\n * @throws {CryptoError} `InvalidParameter` unless `password` and `salt` are\n * `Uint8Array`s and `options` an object; when `dkLen` is outside its domain\n * (see {@link ScryptOptions.dkLen}), `logN` not in [0, 32] or not below `16·r`\n * (scrypt requires `N < 2^(128·r/8)`), `r` or `p` not ≥ 1, `r·p` not below\n * 2^30, or the parameters exceed `maxmem`.\n */\nexport function scrypt(\n  password: Uint8Array,\n  salt: Uint8Array,\n  options: ScryptOptions,\n): Uint8Array<ArrayBuffer> {\n  requireBytes(\"scrypt password\", password);\n  requireBytes(\"scrypt salt\", salt);\n  requireOptions(\"scrypt options\", options, false);\n  const parameterised =\n    options.logN !== undefined || options.r !== undefined || options.p !== undefined;\n  const dkLen = parameterised\n    ? expectInt(\"scrypt dkLen\", options.dkLen, 10, 64)\n    : expectInt(\"scrypt dkLen\", options.dkLen, 1, SCRYPT_MAX_DKLEN);\n  const logN = expectInt(\"scrypt logN\", options.logN ?? 17, 0, 32);\n  const r = expectInt(\"scrypt r\", options.r ?? 8, 1, U32_MAX);\n  const p = expectInt(\"scrypt p\", options.p ?? 1, 1, U32_MAX);\n  // The two shape rules of RFC 7914 §2 that the reference's `scrypt::Params::new` enforces.\n  if (logN >= 16 * r) {\n    throw CryptoError.invalidParameter(\n      \"scrypt logN\",\n      `scrypt logN must be below 16·r (N < 2^(128·r/8)), got logN ${logN} with r ${r}`,\n    );\n  }\n  if (r * p >= 2 ** 30) {\n    throw CryptoError.invalidParameter(\"scrypt p\", `scrypt r·p must be below 2^30, got ${r * p}`);\n  }\n  // No ceiling unless asked: the reference has none. noble's own default (~1 GiB)\n  // would reject parameter sets the reference derives with.\n  const maxmem =\n    options.maxmem === undefined\n      ? Number.MAX_SAFE_INTEGER\n      : expectInt(\"scrypt maxmem\", options.maxmem, 1, Number.MAX_SAFE_INTEGER);\n  const N = 2 ** logN;\n  const blockBytes = 128 * r;\n  if (N === 1 || blockBytes * N > SINGLE_BUFFER_LIMIT || blockBytes * p > SINGLE_BUFFER_LIMIT) {\n    // The paged core: for a working buffer too large for one typed array on\n    // JavaScriptCore, and for N = 1, which noble refuses (`2^1 <= N`) and the\n    // reference's crate runs. Same `maxmem` rule and error shape as noble's.\n    const memUsed = blockBytes * (N + p + 1);\n    if (memUsed > maxmem) {\n      throw backendRejected(\"scrypt parameters\")(\n        new Error(`\"maxmem\" limit was hit: memUsed(128*r*(N+p+1))=${memUsed}, maxmem=${maxmem}`),\n      );\n    }\n    return guard(\n      () => scryptCore(password, salt, { N, r, p, dkLen }),\n      backendRejected(\"scrypt parameters\"),\n    );\n  }\n  return guard(\n    () => nobleScrypt(password, salt, { N, r, p, dkLen, maxmem }),\n    backendRejected(\"scrypt parameters\"),\n  );\n}\n\n/** Options for {@link argon2id}. */\nexport interface Argon2idOptions {\n  /** Derived key length in bytes; at least 4. */\n  readonly dkLen: number;\n}\n\n// The reference's `Argon2::default()`: Argon2id, version 0x13, m = 19456 KiB,\n// t = 2, p = 1. There are no other costs: the wire (`Argon2idParams`) carries\n// a salt only, so nothing else could be reproduced by another implementation.\nconst ARGON2ID_T = 2;\nconst ARGON2ID_M = 19456;\nconst ARGON2ID_P = 1;\n\n/**\n * Argon2id with the reference's fixed parameters (m 19456 KiB, t 2, p 1).\n * @throws {CryptoError} `InvalidParameter` unless `password` and `salt` are\n * `Uint8Array`s and `options` an object; when `dkLen` is not an integer ≥ 4\n * or `salt` is shorter than 8 bytes.\n */\nexport function argon2id(\n  password: Uint8Array,\n  salt: Uint8Array,\n  options: Argon2idOptions,\n): Uint8Array<ArrayBuffer> {\n  requireBytes(\"argon2id password\", password);\n  requireBytes(\"argon2id salt\", salt);\n  requireOptions(\"argon2id options\", options, false);\n  const dkLen = expectInt(\"argon2id dkLen\", options.dkLen, 4, U32_MAX);\n  expectMinLength(\"argon2id salt\", salt, 8);\n  return guard(\n    () => nobleArgon2id(password, salt, { t: ARGON2ID_T, m: ARGON2ID_M, p: ARGON2ID_P, dkLen }),\n    backendRejected(\"argon2id parameters\"),\n  );\n}\n","/**\n * ChaCha20-Poly1305 authenticated encryption.\n *\n * @module aead\n */\nimport { chacha20poly1305 } from \"@noble/ciphers/chacha.js\";\nimport { CryptoError, requireBytes, requireLength, requireOptions } from \"./error.js\";\n\nconst SYMMETRIC_KEY_SIZE = 32;\nconst SYMMETRIC_NONCE_SIZE = 12;\nconst SYMMETRIC_AUTH_SIZE = 16;\n\n/** Options for {@link chacha20Poly1305}. */\nexport interface AeadOptions {\n  /** Additional authenticated data; authenticated but not encrypted. */\n  readonly aad?: Uint8Array | undefined;\n}\n\nconst EMPTY = new Uint8Array(0);\n\n/** The `aad` option, validated: `undefined` means none (the same as empty). */\nfunction aadOf(options: AeadOptions | undefined): Uint8Array {\n  requireOptions(\"ChaCha20-Poly1305 options\", options, true);\n  const aad = options?.aad;\n  if (aad === undefined) return EMPTY;\n  requireBytes(\"ChaCha20-Poly1305 aad\", aad);\n  return aad;\n}\n\n/** The {@link chacha20Poly1305} family. */\nexport interface Chacha20Poly1305 {\n  /** Key length in bytes. */\n  readonly KEY_SIZE: 32;\n  /** Nonce length in bytes (IETF, 96-bit). */\n  readonly NONCE_SIZE: 12;\n  /** Poly1305 tag length in bytes; the trailing bytes of a sealed buffer. */\n  readonly TAG_SIZE: 16;\n  /**\n   * Returns `ciphertext || tag`; the tag is the trailing 16 bytes.\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array` argument;\n   * `InvalidSize` on a wrong-length key or nonce.\n   */\n  encrypt(\n    key: Uint8Array,\n    nonce: Uint8Array,\n    plaintext: Uint8Array,\n    options?: AeadOptions,\n  ): Uint8Array<ArrayBuffer>;\n  /**\n   * Takes `ciphertext || tag`.\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array` argument;\n   * `InvalidSize` on a wrong-length key or nonce, or sealed data shorter\n   * than the tag; `AuthenticationFailed` on tag mismatch.\n   */\n  decrypt(\n    key: Uint8Array,\n    nonce: Uint8Array,\n    sealed: Uint8Array,\n    options?: AeadOptions,\n  ): Uint8Array<ArrayBuffer>;\n}\n\n/** ChaCha20-Poly1305 (RFC 8439). */\nexport const chacha20Poly1305: Chacha20Poly1305 = {\n  KEY_SIZE: 32,\n  NONCE_SIZE: 12,\n  TAG_SIZE: 16,\n\n  encrypt(key, nonce, plaintext, options) {\n    requireLength(\"ChaCha20-Poly1305 key\", key, SYMMETRIC_KEY_SIZE);\n    requireLength(\"ChaCha20-Poly1305 nonce\", nonce, SYMMETRIC_NONCE_SIZE);\n    requireBytes(\"ChaCha20-Poly1305 plaintext\", plaintext);\n    const aad = aadOf(options);\n    return chacha20poly1305(key, nonce, aad).encrypt(plaintext);\n  },\n\n  decrypt(key, nonce, sealed, options) {\n    requireLength(\"ChaCha20-Poly1305 key\", key, SYMMETRIC_KEY_SIZE);\n    requireLength(\"ChaCha20-Poly1305 nonce\", nonce, SYMMETRIC_NONCE_SIZE);\n    requireBytes(\"ChaCha20-Poly1305 sealed data\", sealed);\n    const aad = aadOf(options);\n    if (sealed.length < SYMMETRIC_AUTH_SIZE) {\n      throw CryptoError.invalidSize(\n        \"ChaCha20-Poly1305 sealed data\",\n        SYMMETRIC_AUTH_SIZE,\n        sealed.length,\n      );\n    }\n    try {\n      return chacha20poly1305(key, nonce, aad).decrypt(sealed);\n    } catch (error) {\n      throw CryptoError.authenticationFailed(error);\n    }\n  },\n};\n","/**\n * X25519 key agreement and the HKDF key derivations built on it.\n *\n * @module x25519\n */\nimport { x25519 as noble } from \"@noble/curves/ed25519.js\";\nimport { type RngOptions, randomBytes, secureRng } from \"@blockchaincommons/rand\";\nimport { hkdfSha256 } from \"./hash.js\";\nimport { requireBytes, requireLength, requireOptions } from \"./error.js\";\nimport { backendRejected } from \"./domain.js\";\n\nconst X25519_PRIVATE_KEY_SIZE = 32;\nconst X25519_PUBLIC_KEY_SIZE = 32;\n\n/** noble's message for a low-order peer, the one throw `getSharedSecret` has for 32-byte arguments. */\nconst NOBLE_LOW_ORDER_PEER = \"invalid private or public key received\";\n\n// The HKDF salts are wire: every derived key in the stack depends on them.\nconst textEncoder = new TextEncoder();\nconst AGREEMENT_SALT = textEncoder.encode(\"agreement\");\nconst SIGNING_SALT = textEncoder.encode(\"signing\");\n\n/**\n * The stack's signing-key derivation: HKDF-SHA-256(keyMaterial, salt \"signing\")\n * → 32 bytes, used for ECDSA, Schnorr and Ed25519 private keys alike\n * (the reference's `derive_signing_private_key` ≡ `ecdsa_derive_private_key`).\n * @throws {CryptoError} `InvalidParameter` unless `keyMaterial` is a `Uint8Array`.\n */\nexport function deriveSigningPrivateKey(keyMaterial: Uint8Array): Uint8Array<ArrayBuffer> {\n  requireBytes(\"signing key material\", keyMaterial);\n  return hkdfSha256(keyMaterial, SIGNING_SALT, { dkLen: 32 });\n}\n\n/**\n * The stack's agreement-key derivation: HKDF-SHA-256(keyMaterial, salt\n * \"agreement\") → 32 bytes, an X25519 private key.\n * @throws {CryptoError} `InvalidParameter` unless `keyMaterial` is a `Uint8Array`.\n */\nexport function deriveAgreementPrivateKey(keyMaterial: Uint8Array): Uint8Array<ArrayBuffer> {\n  requireBytes(\"agreement key material\", keyMaterial);\n  return hkdfSha256(keyMaterial, AGREEMENT_SALT, { dkLen: X25519_PRIVATE_KEY_SIZE });\n}\n\n/** The shape of the {@link x25519} family. */\nexport interface X25519 {\n  /** Private key length in bytes. */\n  readonly PRIVATE_KEY_SIZE: 32;\n  /** Public key length in bytes. */\n  readonly PUBLIC_KEY_SIZE: 32;\n  /**\n   * 32 random bytes from `options.rng` (default secure), unvalidated; the\n   * reference's `x25519_new_private_key_using` (`random_data`). A generator's\n   * own error, including rand's `InvalidGenerator`, propagates unwrapped.\n   * @throws {CryptoError} `InvalidParameter` unless `options` is an object or absent.\n   */\n  generatePrivateKey(options?: RngOptions): Uint8Array<ArrayBuffer>;\n  /**\n   * The X25519 public key of `privateKey` (clamped per RFC 7748).\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong-length key.\n   */\n  publicKey(privateKey: Uint8Array): Uint8Array<ArrayBuffer>;\n  /**\n   * X25519 Diffie-Hellman, then HKDF-SHA-256 with salt \"agreement\" → 32 bytes\n   * (the reference's `x25519_shared_key`). A low-order `publicKey` (RFC 7748\n   * §6.1) gives the all-zero shared secret and so one fixed key, whatever the\n   * private key: the reference calls x25519-dalek's `diffie_hellman` without\n   * checking `was_contributory`, and neither does this. Reject such peers\n   * yourself before deriving from an untrusted key.\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong length.\n   */\n  sharedKey(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array<ArrayBuffer>;\n}\n\n/** X25519 key agreement: key generation, public keys and the salted shared key. */\nexport const x25519: X25519 = {\n  PRIVATE_KEY_SIZE: 32,\n  PUBLIC_KEY_SIZE: 32,\n\n  generatePrivateKey(options) {\n    requireOptions(\"X25519 options\", options, true);\n    return randomBytes(X25519_PRIVATE_KEY_SIZE, { rng: options?.rng ?? secureRng() });\n  },\n\n  publicKey(privateKey) {\n    requireLength(\"X25519 private key\", privateKey, X25519_PRIVATE_KEY_SIZE);\n    return noble.getPublicKey(privateKey);\n  },\n\n  sharedKey(privateKey, publicKey) {\n    requireLength(\"X25519 private key\", privateKey, X25519_PRIVATE_KEY_SIZE);\n    requireLength(\"X25519 public key\", publicKey, X25519_PUBLIC_KEY_SIZE);\n    // noble rejects the low-order peers before its ladder; the set is exactly\n    // the u values the ladder sends to zero, which x25519-dalek's unchecked\n    // `diffie_hellman` (the reference) returns as the all-zero secret. Both\n    // arguments are 32 bytes and every 32-byte private key is clamped, so\n    // that rejection is noble's only throw here; anything else is a fault.\n    let secret: Uint8Array;\n    try {\n      secret = noble.getSharedSecret(privateKey, publicKey);\n    } catch (e) {\n      if (!(e instanceof Error && e.message === NOBLE_LOW_ORDER_PEER)) {\n        throw backendRejected(\"X25519 public key\")(e);\n      }\n      secret = new Uint8Array(X25519_PUBLIC_KEY_SIZE);\n    }\n    return hkdfSha256(secret, AGREEMENT_SALT, { dkLen: 32 });\n  },\n};\n","/**\n * secp256k1: ECDSA keys and signatures, and BIP-340 Schnorr.\n *\n * @module ecdsa\n */\nimport { secp256k1, schnorr as nobleSchnorr } from \"@noble/curves/secp256k1.js\";\nimport { bytesToNumberBE } from \"@noble/curves/utils.js\";\nimport {\n  type RandomNumberGenerator,\n  type RngOptions,\n  randomBytes,\n  secureRng,\n} from \"@blockchaincommons/rand\";\nimport { doubleSha256 } from \"./hash.js\";\nimport { CryptoError, requireBytes, requireLength, requireOptions } from \"./error.js\";\nimport { guard, invalidPoint } from \"./domain.js\";\n\nconst ECDSA_PRIVATE_KEY_SIZE = 32;\nconst ECDSA_PUBLIC_KEY_SIZE = 33;\nconst ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE = 65;\nconst ECDSA_SIGNATURE_SIZE = 64;\nconst SCHNORR_PUBLIC_KEY_SIZE = 32;\nconst SCHNORR_SIGNATURE_SIZE = 64;\n\nconst invalidScalar =\n  (what: string) =>\n  (cause: unknown): CryptoError =>\n    CryptoError.invalidData(what, `${what} is not a valid scalar (must be in [1, n - 1])`, cause);\n\nconst CURVE_ORDER = secp256k1.Point.Fn.ORDER;\n\n/**\n * The reference's `Signature::from_compact` is `.expect`ed, and libsecp256k1's\n * `secp256k1_ecdsa_signature_parse_compact` fails only when r or s overflows\n * n: that is `InvalidData` here. r or s = 0 parses, and then does not verify.\n */\nfunction requireCompactScalars(what: string, signature: Uint8Array): void {\n  const r = bytesToNumberBE(signature.subarray(0, 32));\n  const s = bytesToNumberBE(signature.subarray(32));\n  if (r >= CURVE_ORDER || s >= CURVE_ORDER) {\n    throw CryptoError.invalidData(what, `${what} has r or s outside [0, n - 1]`);\n  }\n}\n\n/** The shape of the {@link ecdsa} family. */\nexport interface Ecdsa {\n  /** Private key (scalar) length in bytes. */\n  readonly PRIVATE_KEY_SIZE: 32;\n  /** Compressed public key length in bytes. */\n  readonly PUBLIC_KEY_SIZE: 33;\n  /** Uncompressed (`04 ‖ x ‖ y`) public key length in bytes. */\n  readonly UNCOMPRESSED_PUBLIC_KEY_SIZE: 65;\n  /** Length of the message hash that is signed (double SHA-256). */\n  readonly MESSAGE_HASH_SIZE: 32;\n  /** Compact (`r ‖ s`) signature length in bytes. */\n  readonly SIGNATURE_SIZE: 64;\n  /**\n   * 32 random bytes from `options.rng` (default secure), unvalidated; the\n   * reference's `ecdsa_new_private_key_using` (`random_data`). A generator's\n   * own error, including rand's `InvalidGenerator`, propagates unwrapped.\n   * @throws {CryptoError} `InvalidParameter` unless `options` is an object or absent.\n   */\n  generatePrivateKey(options?: RngOptions): Uint8Array<ArrayBuffer>;\n  /**\n   * Compressed (33-byte) public key.\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong length; `InvalidData` when the key is not a valid scalar (0 or ≥ n).\n   */\n  publicKey(privateKey: Uint8Array): Uint8Array<ArrayBuffer>;\n  /** @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong length; `InvalidData` when the bytes are not a point on the curve. */\n  decompressPublicKey(compressed: Uint8Array): Uint8Array<ArrayBuffer>;\n  /**\n   * 65 bytes: `04 ‖ x ‖ y`, or the hybrid `06`/`07` forms, whose low bit must\n   * equal the parity of y (libsecp256k1's parser, which the reference uses).\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong length; `InvalidData` when the bytes are not a point on the curve or a hybrid prefix disagrees with y.\n   */\n  compressPublicKey(uncompressed: Uint8Array): Uint8Array<ArrayBuffer>;\n  /**\n   * Deterministic (RFC 6979) signature over `doubleSha256(message)`; 64-byte compact form.\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong length; `InvalidData` when the key is not a valid scalar.\n   */\n  sign(privateKey: Uint8Array, message: Uint8Array): Uint8Array<ArrayBuffer>;\n  /**\n   * `false` on a signature that does not verify, r or s = 0 and a high s\n   * included (libsecp256k1's `secp256k1_ecdsa_verify`).\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong-length key or signature; `InvalidData` when the key is not a point on the curve or r or s ≥ n, the reference's `.expect`ed parses (`PublicKey::from_slice`, `Signature::from_compact`).\n   */\n  verify(publicKey: Uint8Array, signature: Uint8Array, message: Uint8Array): boolean;\n}\n\n/** secp256k1 ECDSA: keys, point compression, and RFC 6979 signatures over double SHA-256. */\nexport const ecdsa: Ecdsa = {\n  PRIVATE_KEY_SIZE: 32,\n  PUBLIC_KEY_SIZE: 33,\n  UNCOMPRESSED_PUBLIC_KEY_SIZE: 65,\n  MESSAGE_HASH_SIZE: 32,\n  SIGNATURE_SIZE: 64,\n\n  generatePrivateKey(options) {\n    requireOptions(\"ECDSA options\", options, true);\n    return randomBytes(ECDSA_PRIVATE_KEY_SIZE, { rng: options?.rng ?? secureRng() });\n  },\n\n  publicKey(privateKey) {\n    requireLength(\"ECDSA private key\", privateKey, ECDSA_PRIVATE_KEY_SIZE);\n    return guard(\n      () => secp256k1.getPublicKey(privateKey, true),\n      invalidScalar(\"ECDSA private key\"),\n    );\n  },\n\n  decompressPublicKey(compressed) {\n    requireLength(\"ECDSA compressed public key\", compressed, ECDSA_PUBLIC_KEY_SIZE);\n    return guard(\n      () => secp256k1.Point.fromBytes(compressed).toBytes(false),\n      invalidPoint(\"ECDSA compressed public key\"),\n    );\n  },\n\n  compressPublicKey(uncompressed) {\n    requireLength(\n      \"ECDSA uncompressed public key\",\n      uncompressed,\n      ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE,\n    );\n    const head = uncompressed[0];\n    return guard(() => {\n      if (head === 0x06 || head === 0x07) {\n        // libsecp256k1 (`secp256k1_eckey_pubkey_parse`) accepts the hybrid\n        // prefixes when the low bit states y's parity; noble parses `04` only.\n        const plain = Uint8Array.from(uncompressed);\n        plain[0] = 0x04;\n        const point = secp256k1.Point.fromBytes(plain);\n        if ((point.toAffine().y & 1n) !== BigInt(head & 1)) {\n          // A CryptoError passes through `guard`; the point is on the curve,\n          // so `invalidPoint`'s message would be wrong here. The reference\n          // does not distinguish the two: both are `InvalidPublicKey`.\n          throw CryptoError.invalidData(\n            \"ECDSA uncompressed public key\",\n            \"ECDSA uncompressed public key has a hybrid prefix that does not match the parity of y\",\n          );\n        }\n        return point.toBytes(true);\n      }\n      return secp256k1.Point.fromBytes(uncompressed).toBytes(true);\n    }, invalidPoint(\"ECDSA uncompressed public key\"));\n  },\n\n  sign(privateKey, message) {\n    requireLength(\"ECDSA private key\", privateKey, ECDSA_PRIVATE_KEY_SIZE);\n    requireBytes(\"ECDSA message\", message);\n    return guard(\n      () => secp256k1.sign(doubleSha256(message), privateKey, { prehash: false }),\n      invalidScalar(\"ECDSA private key\"),\n    );\n  },\n\n  verify(publicKey, signature, message) {\n    requireLength(\"ECDSA public key\", publicKey, ECDSA_PUBLIC_KEY_SIZE);\n    requireLength(\"ECDSA signature\", signature, ECDSA_SIGNATURE_SIZE);\n    requireBytes(\"ECDSA message\", message);\n    // The reference parses with `.expect`, the key first: an undecodable key\n    // or an r or s ≥ n is a panic. A parsed pair that does not verify is `false`.\n    guard(() => secp256k1.Point.fromBytes(publicKey), invalidPoint(\"ECDSA public key\"));\n    requireCompactScalars(\"ECDSA signature\", signature);\n    try {\n      return secp256k1.verify(signature, doubleSha256(message), publicKey, {\n        prehash: false,\n        lowS: true,\n      });\n    } catch {\n      return false;\n    }\n  },\n};\n\n/** Options for `schnorr.sign`: explicit aux-rand bytes, or a generator to draw them from. */\nexport interface SchnorrSignOptions {\n  /** 32 bytes of auxiliary randomness (BIP-340). Takes precedence over `rng`. */\n  readonly auxRand?: Uint8Array | undefined;\n  /** Generator to draw 32 aux-rand bytes from. Default: secure. */\n  readonly rng?: RandomNumberGenerator | undefined;\n}\n\n/** The shape of the {@link schnorr} family. */\nexport interface Schnorr {\n  /** x-only public key length in bytes. */\n  readonly PUBLIC_KEY_SIZE: 32;\n  /** BIP-340 signature length in bytes. */\n  readonly SIGNATURE_SIZE: 64;\n  /**\n   * x-only (32-byte) public key of a secp256k1 private key.\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong length; `InvalidData` when the key is not a valid scalar.\n   */\n  publicKey(privateKey: Uint8Array): Uint8Array<ArrayBuffer>;\n  /**\n   * BIP-340 signature. Aux-rand comes from `options.auxRand`, else 32 bytes\n   * drawn from `options.rng` (the reference's `schnorr_sign_using`,\n   * `random_data(32)`); a generator's own error propagates unwrapped.\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array` or a non-object `options`; `InvalidSize` on a wrong length; `InvalidData` when the key is not a valid scalar.\n   */\n  sign(\n    privateKey: Uint8Array,\n    message: Uint8Array,\n    options?: SchnorrSignOptions,\n  ): Uint8Array<ArrayBuffer>;\n  /**\n   * `false` on a signature that does not verify (BIP-340 vectors 6–13).\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong-length key or signature; `InvalidData` when the key is not the x of a point on the curve (BIP-340 vectors 5 and 14), the reference's `.expect`ed `XOnlyPublicKey::from_byte_array`.\n   */\n  verify(publicKey: Uint8Array, signature: Uint8Array, message: Uint8Array): boolean;\n}\n\n/** BIP-340 Schnorr signatures over secp256k1, with the two aux-rand paths. */\nexport const schnorr: Schnorr = {\n  PUBLIC_KEY_SIZE: 32,\n  SIGNATURE_SIZE: 64,\n\n  publicKey(privateKey) {\n    requireLength(\"Schnorr private key\", privateKey, ECDSA_PRIVATE_KEY_SIZE);\n    return guard(() => nobleSchnorr.getPublicKey(privateKey), invalidScalar(\"Schnorr private key\"));\n  },\n\n  sign(privateKey, message, options) {\n    requireLength(\"Schnorr private key\", privateKey, ECDSA_PRIVATE_KEY_SIZE);\n    requireBytes(\"Schnorr message\", message);\n    requireOptions(\"Schnorr options\", options, true);\n    const given = options?.auxRand;\n    if (given !== undefined) requireBytes(\"Schnorr auxiliary randomness\", given);\n    const auxRand = given ?? randomBytes(32, { rng: options?.rng ?? secureRng() });\n    if (auxRand.length !== 32)\n      throw CryptoError.invalidSize(\"Schnorr auxiliary randomness\", 32, auxRand.length);\n    return guard(\n      () => nobleSchnorr.sign(message, privateKey, auxRand),\n      invalidScalar(\"Schnorr private key\"),\n    );\n  },\n\n  verify(publicKey, signature, message) {\n    requireLength(\"Schnorr public key\", publicKey, SCHNORR_PUBLIC_KEY_SIZE);\n    requireLength(\"Schnorr signature\", signature, SCHNORR_SIGNATURE_SIZE);\n    requireBytes(\"Schnorr message\", message);\n    // The reference `.expect`s the key (`secp256k1_xonly_pubkey_parse`: x < p\n    // and on the curve, which is what `02 ‖ x` decodes under); any 64 bytes\n    // are a signature, which then verifies or not.\n    guard(\n      () => secp256k1.Point.fromBytes(Uint8Array.of(0x02, ...publicKey)),\n      invalidPoint(\"Schnorr public key\"),\n    );\n    try {\n      return nobleSchnorr.verify(signature, message, publicKey);\n    } catch {\n      return false;\n    }\n  },\n};\n","/**\n * Ed25519 signatures.\n *\n * @module ed25519\n */\nimport { ed25519 as noble } from \"@noble/curves/ed25519.js\";\nimport { bytesToNumberLE, equalBytes } from \"@noble/curves/utils.js\";\nimport { sha512 } from \"@noble/hashes/sha2.js\";\nimport {\n  type RandomNumberGenerator,\n  type RngOptions,\n  RandError,\n  fillRandomBytes,\n  secureRng,\n} from \"@blockchaincommons/rand\";\nimport { requireBytes, requireLength, requireOptions } from \"./error.js\";\nimport { guard, invalidPoint } from \"./domain.js\";\n\nconst ED25519_PUBLIC_KEY_SIZE = 32;\nconst ED25519_PRIVATE_KEY_SIZE = 32;\nconst ED25519_SIGNATURE_SIZE = 64;\n\n/** The shape of the {@link ed25519} family. */\nexport interface Ed25519 {\n  /** Private key (seed) length in bytes. */\n  readonly PRIVATE_KEY_SIZE: 32;\n  /** Public key length in bytes. */\n  readonly PUBLIC_KEY_SIZE: 32;\n  /** Signature length in bytes. */\n  readonly SIGNATURE_SIZE: 64;\n  /**\n   * 32 random bytes from `options.rng` (default secure). The reference's\n   * `ed25519_new_private_key_using` draws through `rand_core`'s `fill_bytes`,\n   * so the generator's `fillBytesPacked` is used when it has one (the packed\n   * stream of `SeededRng`), else `fillBytes` through rand's `fillRandomBytes`.\n   * A generator's own error propagates unwrapped; a `fillBytesPacked` that is\n   * present but not a function is rand's `RandError` `InvalidGenerator`.\n   * @throws {CryptoError} `InvalidParameter` unless `options` is an object or absent.\n   */\n  generatePrivateKey(options?: RngOptions): Uint8Array<ArrayBuffer>;\n  /**\n   * The public key of the 32-byte seed `privateKey` (RFC 8032).\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong-length key.\n   */\n  publicKey(privateKey: Uint8Array): Uint8Array<ArrayBuffer>;\n  /**\n   * Deterministic RFC 8032 signature (64 bytes).\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong-length key.\n   */\n  sign(privateKey: Uint8Array, message: Uint8Array): Uint8Array<ArrayBuffer>;\n  /**\n   * `(publicKey, signature, message)`, the same order as `ecdsa.verify` and `schnorr.verify`.\n   *\n   * Uses the reference's uncofactored verification equation (`verify_strict`):\n   * `false` for a small-order key or `R`, a non-canonical `R`, an `s` ≥ L,\n   * or a signature that does not verify. The key is decoded as the\n   * reference's `VerifyingKey::from_bytes` decodes it (a non-canonical y is\n   * reduced), and its `.unwrap()` on a key with no point is a panic.\n   * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array`; `InvalidSize` on a wrong-length key or signature; `InvalidData` when the key is not a point on the curve.\n   */\n  verify(publicKey: Uint8Array, signature: Uint8Array, message: Uint8Array): boolean;\n}\n\n/** Ed25519 (RFC 8032) signatures with strict verification. */\nexport const ed25519: Ed25519 = {\n  PRIVATE_KEY_SIZE: 32,\n  PUBLIC_KEY_SIZE: 32,\n  SIGNATURE_SIZE: 64,\n\n  generatePrivateKey(options) {\n    requireOptions(\"Ed25519 options\", options, true);\n    // The reference's `ed25519_new_private_key_using` reaches the generator\n    // through rand_core generics (`SigningKey::generate` → `fill_bytes`): the\n    // packed stream where a generator distinguishes one, else the same bytes\n    // as `randomBytes`.\n    const rng: RandomNumberGenerator = options?.rng ?? secureRng();\n    const key = new Uint8Array(ED25519_PRIVATE_KEY_SIZE);\n    // Read once. rand never calls this optional member, so its contract is\n    // checked here, with rand's own error, as rand checks the members it calls.\n    // The single read is deliberate; the call below rebinds `this` to `rng`.\n    // eslint-disable-next-line @typescript-eslint/unbound-method\n    const packed: unknown = rng.fillBytesPacked;\n    if (packed === undefined) {\n      fillRandomBytes(key, { rng });\n    } else if (typeof packed === \"function\") {\n      (packed as (dest: Uint8Array) => void).call(rng, key);\n    } else {\n      throw RandError.invalidGenerator(\"fillBytesPacked\", packed);\n    }\n    return key;\n  },\n\n  publicKey(privateKey) {\n    requireLength(\"Ed25519 private key\", privateKey, ED25519_PRIVATE_KEY_SIZE);\n    return noble.getPublicKey(privateKey);\n  },\n\n  sign(privateKey, message) {\n    requireLength(\"Ed25519 private key\", privateKey, ED25519_PRIVATE_KEY_SIZE);\n    requireBytes(\"Ed25519 message\", message);\n    return noble.sign(message, privateKey);\n  },\n\n  verify(publicKey, signature, message) {\n    requireLength(\"Ed25519 public key\", publicKey, ED25519_PUBLIC_KEY_SIZE);\n    requireLength(\"Ed25519 signature\", signature, ED25519_SIGNATURE_SIZE);\n    requireBytes(\"Ed25519 message\", message);\n    // dalek's `CompressedEdwardsY::decompress` reduces a non-canonical y and\n    // fails only when the reduced y has no x: noble's `zip215 = true` rule.\n    // The reference `.unwrap()`s it.\n    const a = guard(\n      () => noble.Point.fromBytes(publicKey, true),\n      invalidPoint(\"Ed25519 public key\"),\n    );\n    try {\n      // Canonical decoding (zip215 = false) of R, then the small-order checks\n      // `verify_strict` makes, then the equation. A decodable non-canonical\n      // key is small-order (rejected below and by `verify_strict`) or a point\n      // whose discrete logarithm nobody knows, so it is `false` on both sides.\n      const r = noble.Point.fromBytes(signature.subarray(0, 32), false);\n      if (a.isSmallOrder() || r.isSmallOrder()) return false;\n      const order = noble.Point.Fn.ORDER;\n      const s = bytesToNumberLE(signature.subarray(32));\n      if (s >= order) return false;\n      // Hash the original encodings. Clearing the cofactor here would accept\n      // mixed-order R values that dalek's verify_strict rejects.\n      const k =\n        bytesToNumberLE(\n          sha512\n            .create()\n            .update(signature.subarray(0, 32))\n            .update(publicKey)\n            .update(message)\n            .digest(),\n        ) % order;\n      const expectedR = noble.Point.BASE.multiplyUnsafe(s).subtract(a.multiplyUnsafe(k));\n      return equalBytes(expectedR.toBytes(), signature.subarray(0, 32));\n    } catch {\n      return false;\n    }\n  },\n};\n","/**\n * ChaCha20 as a keystream XOR (RFC 8439 §2.4), for callers that need the\n * raw cipher without Poly1305 — provenance marks obfuscate their tail with\n * it. Prefer {@link chacha20Poly1305} wherever authentication is possible.\n *\n * @module stream\n */\nimport { chacha20 as nobleChacha20 } from \"@noble/ciphers/chacha.js\";\nimport { CryptoError, requireBytes, requireLength, requireOptions } from \"./error.js\";\nimport { backendRejected, expectInt, guard, U32_MAX } from \"./domain.js\";\n\n/** Options for {@link chacha20}. */\nexport interface Chacha20Options {\n  /** The initial block counter (0 by default), in [0, 2^32 - 2]. */\n  readonly counter?: number | undefined;\n}\n\n/**\n * XORs `data` with the ChaCha20 keystream for `key` (32 bytes) and `nonce`\n * (12 bytes), starting at block `counter`. Applying it twice restores the\n * input. There is no `bc-crypto` function for this; it is provenance-mark's\n * `ChaCha20::new` + `apply_keystream` (the `chacha20` crate).\n * @throws {CryptoError} `InvalidParameter` on a non-`Uint8Array` argument or\n * a non-object `options`; `InvalidSize` on a wrong-length key or nonce;\n * `InvalidParameter` if `counter` is outside [0, 2^32 - 2] or the data\n * would use the backend-reserved block counter 2^32 - 1.\n */\nexport function chacha20(\n  key: Uint8Array,\n  nonce: Uint8Array,\n  data: Uint8Array,\n  options?: Chacha20Options,\n): Uint8Array<ArrayBuffer> {\n  requireLength(\"ChaCha20 key\", key, 32);\n  requireLength(\"ChaCha20 nonce\", nonce, 12);\n  requireBytes(\"ChaCha20 data\", data);\n  requireOptions(\"ChaCha20 options\", options, true);\n  const counter = expectInt(\"ChaCha20 counter\", options?.counter ?? 0, 0, U32_MAX - 1);\n  if (Math.ceil(data.length / 64) > U32_MAX - counter) {\n    throw CryptoError.invalidParameter(\n      \"ChaCha20 counter\",\n      \"ChaCha20 data exceeds the remaining block counter capacity\",\n    );\n  }\n  // noble writes into a fresh `Uint8Array(data.length)`, an ArrayBuffer-backed view.\n  return guard(\n    () => nobleChacha20(key, nonce, data, undefined, counter) as Uint8Array<ArrayBuffer>,\n    backendRejected(\"ChaCha20 parameters\"),\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,IAAa,cAAb,MAAa,oBAAoB,MAAM;;CAErC,AAAkB,OAAO;;CAEzB,AAAS;;CAET,AAAS;CAET,AAAQ,YAAY,SAAiB,SAA6B,OAAiB;EACjF,MAAM,SAAS,UAAU,SAAY,SAAY,EAAE,MAAM,CAAC;EAC1D,KAAK,OAAO,QAAQ;EACpB,KAAK,UAAU;CACjB;;CAGA,OAAO,cAAc,OAAsC;EACzD,OAAO,iBAAiB,SAAS,MAAM,SAAS,iBAAiB,UAAU;CAC7E;;CAGA,GAAG,MAAgC;EACjC,OAAO,KAAK,SAAS;CACvB;;CAGA,OAAO,YAAY,MAAc,UAAkB,QAA6B;EAC9E,OAAO,IAAI,YAAY,GAAG,KAAK,WAAW,SAAS,cAAc,UAAU;GACzE,MAAM;GACN;GACA;GACA;EACF,CAAC;CACH;;CAGA,OAAO,YAAY,MAAc,SAAiB,OAA8B;EAC9E,OAAO,IAAI,YAAY,SAAS;GAAE,MAAM;GAAe;EAAK,GAAG,KAAK;CACtE;;CAGA,OAAO,iBAAiB,MAAc,SAAiB,OAA8B;EACnF,OAAO,IAAI,YAAY,SAAS;GAAE,MAAM;GAAoB;EAAK,GAAG,KAAK;CAC3E;;CAGA,OAAO,qBAAqB,OAA8B;EAExD,OAAO,IAAI,YAAY,cAAc,EAAE,MAAM,uBAAuB,GAAG,KAAK;CAC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