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A,GAAM,UAAYA,EAAE,OAAS,IAAM,EAC5C,MAAM,IAAI,UACR,oCAAoC,OAAOA,CAAC,gBAAgBA,EAAE,MAAM,EAAE,EAE1E,OAAOA,EAAE,YAAW,CACtB,CAAC,CAAC,CACH,EAwBDoE,EAAqB,CACzB,KAAAR,GAAM,IAAAO,GAAK,OAAAzE,GAAQ,OAAAC,GAAQ,OAAAU,GAAQ,UAAAE,GAAW,OAAAI,EAAQ,UAAAI,IAGlDsD,GACJ,0GAcWC,GAAgB,CAACC,EAAiBxF,IAAmC,CAChF,GAAI,OAAOwF,GAAS,UAAY,CAACH,EAAO,eAAeG,CAAI,EAAG,MAAM,IAAI,UAAUF,EAAc,EAChG,GAAI,CAACzJ,EAAQmE,CAAK,EAAG,MAAM,IAAI,UAAU,oCAAoC,EAC7E,OAAOqF,EAAOG,CAAI,EAAE,OAAOxF,CAAK,CAClC,EAaakC,GAA4DqD,GAc5DE,GAAgB,CAACD,EAAiBtD,IAAiC,CAE9E,GAAI,OAAOsD,GAAS,UAAY,CAACH,EAAO,eAAeG,CAAI,EAAG,MAAM,IAAI,UAAUF,EAAc,EAChG,GAAI,OAAOpD,GAAQ,SAAU,MAAM,IAAI,UAAU,gCAAgC,EACjF,OAAOmD,EAAOG,CAAI,EAAE,OAAOtD,CAAG,CAChC,EAYalC,GAA4DyF","names":["isBytes","a","abytes","b","isArrayOf","isString","arr","item","afn","input","astr","label","anumber","n","aArr","astrArr","anumArr","chain","args","id","wrap","c","encode","x","decode","alphabet","letters","lettersA","len","indexes","l","i","digits","letter","join","separator","from","to","padding","bits","chr","data","end","normalize","fn","convertRadix","pos","res","d","dlen","carry","done","digit","fromCarry","digitBase","div","rounded","gcd","radix2carry","powers","convertRadix2","max","mask","pow","radix","num","_256","bytes","radix2","revPadding","unsafeWrapper","checksum","_fn","sum","payload","oldChecksum","newChecksum","utils","base16","base32","base32nopad","base32hex","base32hexnopad","base32crockford","s","hasBase64Builtin","ASCII_WHITESPACE","decodeBase64Builtin","isUrl","base64","base64nopad","base64url","base64urlnopad","genBase58","abc","base58","base58flickr","base58xrp","XMR_BLOCK_LEN","base58xmr","block","str","slice","blockLen","j","createBase58check","sha256","_sha256","base58check","BECH_ALPHABET","POLYMOD_GENERATORS","bech32Polymod","pre","chk","bechChecksum","prefix","words","encodingConst","v","genBech32","encoding","ENCODING_CONST","_words","fromWords","toWords","fromWordsUnsafe","limit","plen","actualLength","lowered","slen","sepIndex","decodeUnsafe","decodeToBytes","encodeFromBytes","bech32","bech32m","ascii","byte","charCode","_isWellFormedShim","_isWellFormed","utf8Fallback","cp","utf8","_utf8Encoder","_utf8Decoder","utf8Builtin","__TESTS","hasHexBuiltin","hexBuiltin","hex","CODERS","coderTypeError","bytesToString","type","stringToBytes"],"sources":["../esm/npm/@scure/base@2.2.0/node_modules/@scure/base/index.ts"],"sourcesContent":["/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n\n/** Transforms values between two representations. */\nexport interface Coder\u003cF, T\u003e {\n  /**\n   * Converts a value from the input representation to the output representation.\n   * @param from - Value in the source representation.\n   * @returns Converted value.\n   */\n  encode(from: F): T;\n  /**\n   * Converts a value from the output representation back to the input representation.\n   * @param to - Value in the target representation.\n   * @returns Converted value.\n   */\n  decode(to: T): F;\n}\n\n/** Coder that works with byte arrays and strings. */\nexport interface BytesCoder extends Coder\u003cUint8Array, string\u003e {\n  /**\n   * Encodes bytes into a string representation.\n   * @param data - Bytes to encode.\n   * @returns Encoded string.\n   */\n  encode: (data: Uint8Array) =\u003e string;\n  /**\n   * Decodes a string representation into raw bytes.\n   * @param str - Encoded string.\n   * @returns Decoded bytes.\n   */\n  decode: (str: string) =\u003e Uint8Array;\n}\n\n/**\n * Bytes API type helpers for old + new TypeScript.\n *\n * TS 5.6 has `Uint8Array`, while TS 5.9+ made it generic `Uint8Array\u003cArrayBuffer\u003e`.\n * We can't use specific return type, because TS 5.6 will error.\n * We can't use generic return type, because most TS 5.9 software will expect specific type.\n *\n * Maps typed-array input leaves to broad forms.\n * These are compatibility adapters, not ownership guarantees.\n *\n * - `TArg` keeps byte inputs broad.\n * - `TRet` marks byte outputs for TS 5.6 and TS 5.9+ compatibility.\n */\nexport type TypedArg\u003cT\u003e = T extends BigInt64Array\n  ? BigInt64Array\n  : T extends BigUint64Array\n    ? BigUint64Array\n    : T extends Float32Array\n      ? Float32Array\n      : T extends Float64Array\n        ? Float64Array\n        : T extends Int16Array\n          ? Int16Array\n          : T extends Int32Array\n            ? Int32Array\n            : T extends Int8Array\n              ? Int8Array\n              : T extends Uint16Array\n                ? Uint16Array\n                : T extends Uint32Array\n                  ? Uint32Array\n                  : T extends Uint8ClampedArray\n                    ? Uint8ClampedArray\n                    : T extends Uint8Array\n                      ? Uint8Array\n                      : never;\n/** Maps typed-array output leaves to narrow TS-compatible forms. */\nexport type TypedRet\u003cT\u003e = T extends BigInt64Array\n  ? ReturnType\u003ctypeof BigInt64Array.of\u003e\n  : T extends BigUint64Array\n    ? ReturnType\u003ctypeof BigUint64Array.of\u003e\n    : T extends Float32Array\n      ? ReturnType\u003ctypeof Float32Array.of\u003e\n      : T extends Float64Array\n        ? ReturnType\u003ctypeof Float64Array.of\u003e\n        : T extends Int16Array\n          ? ReturnType\u003ctypeof Int16Array.of\u003e\n          : T extends Int32Array\n            ? ReturnType\u003ctypeof Int32Array.of\u003e\n            : T extends Int8Array\n              ? ReturnType\u003ctypeof Int8Array.of\u003e\n              : T extends Uint16Array\n                ? ReturnType\u003ctypeof Uint16Array.of\u003e\n                : T extends Uint32Array\n                  ? ReturnType\u003ctypeof Uint32Array.of\u003e\n                  : T extends Uint8ClampedArray\n                    ? ReturnType\u003ctypeof Uint8ClampedArray.of\u003e\n                    : T extends Uint8Array\n                      ? ReturnType\u003ctypeof Uint8Array.of\u003e\n                      : never;\n/** Recursively adapts byte-carrying API input types. See {@link TypedArg}. */\nexport type TArg\u003cT\u003e =\n  | T\n  | ([TypedArg\u003cT\u003e] extends [never]\n      ? T extends (...args: infer A) =\u003e infer R\n        ? ((...args: { [K in keyof A]: TRet\u003cA[K]\u003e }) =\u003e TArg\u003cR\u003e) \u0026 {\n            [K in keyof T]: T[K] extends (...args: any) =\u003e any ? T[K] : TArg\u003cT[K]\u003e;\n          }\n        : T extends [infer A, ...infer R]\n          ? [TArg\u003cA\u003e, ...{ [K in keyof R]: TArg\u003cR[K]\u003e }]\n          : T extends readonly [infer A, ...infer R]\n            ? readonly [TArg\u003cA\u003e, ...{ [K in keyof R]: TArg\u003cR[K]\u003e }]\n            : T extends (infer A)[]\n              ? TArg\u003cA\u003e[]\n              : T extends readonly (infer A)[]\n                ? readonly TArg\u003cA\u003e[]\n                : T extends Promise\u003cinfer A\u003e\n                  ? Promise\u003cTArg\u003cA\u003e\u003e\n                  : T extends object\n                    ? { [K in keyof T]: TArg\u003cT[K]\u003e }\n                    : T\n      : TypedArg\u003cT\u003e);\n/** Recursively adapts byte-carrying API output types. See {@link TypedArg}. */\nexport type TRet\u003cT\u003e = T extends unknown\n  ? T \u0026\n      ([TypedRet\u003cT\u003e] extends [never]\n        ? T extends (...args: infer A) =\u003e infer R\n          ? ((...args: { [K in keyof A]: TArg\u003cA[K]\u003e }) =\u003e TRet\u003cR\u003e) \u0026 {\n              [K in keyof T]: T[K] extends (...args: any) =\u003e any ? T[K] : TRet\u003cT[K]\u003e;\n            }\n          : T extends [infer A, ...infer R]\n            ? [TRet\u003cA\u003e, ...{ [K in keyof R]: TRet\u003cR[K]\u003e }]\n            : T extends readonly [infer A, ...infer R]\n              ? readonly [TRet\u003cA\u003e, ...{ [K in keyof R]: TRet\u003cR[K]\u003e }]\n              : T extends (infer A)[]\n                ? TRet\u003cA\u003e[]\n                : T extends readonly (infer A)[]\n                  ? readonly TRet\u003cA\u003e[]\n                  : T extends Promise\u003cinfer A\u003e\n                    ? Promise\u003cTRet\u003cA\u003e\u003e\n                    : T extends object\n                      ? { [K in keyof T]: TRet\u003cT[K]\u003e }\n                      : T\n        : TypedRet\u003cT\u003e)\n  : never;\n\nfunction isBytes(a: unknown): a is Uint8Array {\n  // Plain `instanceof Uint8Array` is too strict for some Buffer / proxy / cross-realm cases. The\n  // fallback still requires a real ArrayBuffer view, so plain JSON-deserialized\n  // `{ constructor: ... }` spoofing is rejected. `BYTES_PER_ELEMENT === 1` keeps the\n  // fallback on byte-oriented views.\n  return (\n    a instanceof Uint8Array ||\n    (ArrayBuffer.isView(a) \u0026\u0026\n      a.constructor.name === 'Uint8Array' \u0026\u0026\n      'BYTES_PER_ELEMENT' in a \u0026\u0026\n      a.BYTES_PER_ELEMENT === 1)\n  );\n}\n/** Asserts something is Uint8Array. */\nfunction abytes(b: TArg\u003cUint8Array | undefined\u003e): void {\n  if (!isBytes(b)) throw new TypeError('Uint8Array expected');\n}\n\nfunction isArrayOf(isString: boolean, arr: any[]) {\n  if (!Array.isArray(arr)) return false;\n  if (arr.length === 0) return true;\n  if (isString) {\n    return arr.every((item) =\u003e typeof item === 'string');\n  } else {\n    return arr.every((item) =\u003e Number.isSafeInteger(item));\n  }\n}\n\nfunction afn(input: Function): input is Function {\n  if (typeof input !== 'function') throw new TypeError('function expected');\n  return true;\n}\n\nfunction astr(label: string, input: unknown): input is string {\n  if (typeof input !== 'string') throw new TypeError(`${label}: string expected`);\n  return true;\n}\n\nfunction anumber(n: number): void {\n  if (typeof n !== 'number') throw new TypeError(`number expected, got ${typeof n}`);\n  if (!Number.isSafeInteger(n)) throw new RangeError(`invalid integer: ${n}`);\n}\n\nfunction aArr(input: any[]) {\n  if (!Array.isArray(input)) throw new TypeError('array expected');\n}\nfunction astrArr(label: string, input: string[]) {\n  if (!isArrayOf(true, input)) throw new TypeError(`${label}: array of strings expected`);\n}\nfunction anumArr(label: string, input: number[]) {\n  if (!isArrayOf(false, input)) throw new TypeError(`${label}: array of numbers expected`);\n}\n\n// TODO: some recusive type inference so it would check correct order of input/output inside rest?\n// like \u003cstring, number\u003e, \u003cnumber, bytes\u003e, \u003cbytes, float\u003e\ntype Chain = [Coder\u003cany, any\u003e, ...Coder\u003cany, any\u003e[]];\n// Extract info from Coder type\ntype Input\u003cF\u003e = F extends Coder\u003cinfer T, any\u003e ? T : never;\ntype Output\u003cF\u003e = F extends Coder\u003cany, infer T\u003e ? T : never;\n// Generic function for arrays\ntype First\u003cT\u003e = T extends [infer U, ...any[]] ? U : never;\ntype Last\u003cT\u003e = T extends [...any[], infer U] ? U : never;\ntype Tail\u003cT\u003e = T extends [any, ...infer U] ? U : never;\n\ntype AsChain\u003cC extends Chain, Rest = Tail\u003cC\u003e\u003e = {\n  // C[K] = Coder\u003cInput\u003cC[K]\u003e, Input\u003cRest[k]\u003e\u003e\n  [K in keyof C]: Coder\u003cInput\u003cC[K]\u003e, Input\u003cK extends keyof Rest ? Rest[K] : any\u003e\u003e;\n};\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction chain\u003cT extends Chain \u0026 AsChain\u003cT\u003e\u003e(...args: T): Coder\u003cInput\u003cFirst\u003cT\u003e\u003e, Output\u003cLast\u003cT\u003e\u003e\u003e {\n  const id = (a: any) =\u003e a;\n  // Wrap call in closure so JIT can inline calls\n  const wrap = (a: any, b: any) =\u003e (c: any) =\u003e a(b(c));\n  // Construct chain of args[-1].encode(args[-2].encode([...]))\n  const encode = args.map((x) =\u003e x.encode).reduceRight(wrap, id);\n  // Construct chain of args[0].decode(args[1].decode(...))\n  const decode = args.map((x) =\u003e x.decode).reduce(wrap, id);\n  return { encode, decode };\n}\n\n/**\n * Encodes integer radix representation to array of strings using alphabet and back.\n * Could also be array of strings.\n * @__NO_SIDE_EFFECTS__\n */\nfunction alphabet(letters: string | string[]): Coder\u003cnumber[], string[]\u003e {\n  // mapping 1 to \"b\"\n  const lettersA = typeof letters === 'string' ? letters.split('') : letters;\n  const len = lettersA.length;\n  astrArr('alphabet', lettersA);\n\n  // mapping \"b\" to 1\n  const indexes = new Map(lettersA.map((l, i) =\u003e [l, i]));\n  return {\n    encode: (digits: number[]) =\u003e {\n      aArr(digits);\n      return digits.map((i) =\u003e {\n        if (!Number.isSafeInteger(i) || i \u003c 0 || i \u003e= len)\n          throw new Error(\n            `alphabet.encode: digit index outside alphabet \"${i}\". Allowed: ${letters}`\n          );\n        return lettersA[i]!;\n      });\n    },\n    decode: (input: string[]): number[] =\u003e {\n      aArr(input);\n      return input.map((letter) =\u003e {\n        astr('alphabet.decode', letter);\n        const i = indexes.get(letter);\n        if (i === undefined) throw new Error(`Unknown letter: \"${letter}\". Allowed: ${letters}`);\n        return i;\n      });\n    },\n  };\n}\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction join(separator = ''): Coder\u003cstring[], string\u003e {\n  astr('join', separator);\n  // join('') is only lossless when each chunk is already unambiguous, such as single-symbol alphabets.\n  // Multi-character tokens need a separator that cannot appear inside the chunks.\n  return {\n    encode: (from) =\u003e {\n      astrArr('join.decode', from);\n      return from.join(separator);\n    },\n    decode: (to) =\u003e {\n      astr('join.decode', to);\n      return to.split(separator);\n    },\n  };\n}\n\n/**\n * Pad strings array so it has integer number of bits\n * @__NO_SIDE_EFFECTS__\n */\nfunction padding(bits: number, chr = '='): Coder\u003cstring[], string[]\u003e {\n  anumber(bits);\n  astr('padding', chr);\n  return {\n    encode(data: string[]): string[] {\n      astrArr('padding.encode', data);\n      // Mutates the intermediate token array in place while appending pad chars.\n      // utils.padding callers that need to preserve their input should pass a copy.\n      while ((data.length * bits) % 8) data.push(chr);\n      return data;\n    },\n    decode(input: string[]): string[] {\n      astrArr('padding.decode', input);\n      let end = input.length;\n      if ((end * bits) % 8)\n        throw new Error('padding: invalid, string should have whole number of bytes');\n      for (; end \u003e 0 \u0026\u0026 input[end - 1] === chr; end--) {\n        const last = end - 1;\n        const byte = last * bits;\n        if (byte % 8 === 0) throw new Error('padding: invalid, string has too much padding');\n      }\n      return input.slice(0, end);\n    },\n  };\n}\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction normalize\u003cT\u003e(fn: (val: T) =\u003e T): Coder\u003cT, T\u003e {\n  afn(fn);\n  return { encode: (from: T) =\u003e from, decode: (to: T) =\u003e fn(to) };\n}\n\n/**\n * Slow: O(n^2) time complexity\n */\nfunction convertRadix(data: number[], from: number, to: number): number[] {\n  // base 1 is impossible\n  if (from \u003c 2)\n    throw new RangeError(`convertRadix: invalid from=${from}, base cannot be less than 2`);\n  if (to \u003c 2) throw new RangeError(`convertRadix: invalid to=${to}, base cannot be less than 2`);\n  aArr(data);\n  if (!data.length) return [];\n  let pos = 0;\n  const res = [];\n  const digits = Array.from(data, (d) =\u003e {\n    anumber(d);\n    if (d \u003c 0 || d \u003e= from) throw new Error(`invalid integer: ${d}`);\n    return d;\n  });\n  const dlen = digits.length;\n  while (true) {\n    let carry = 0;\n    let done = true;\n    for (let i = pos; i \u003c dlen; i++) {\n      const digit = digits[i]!;\n      const fromCarry = from * carry;\n      const digitBase = fromCarry + digit;\n      if (\n        !Number.isSafeInteger(digitBase) ||\n        fromCarry / from !== carry ||\n        digitBase - digit !== fromCarry\n      ) {\n        throw new Error('convertRadix: carry overflow');\n      }\n      const div = digitBase / to;\n      carry = digitBase % to;\n      const rounded = Math.floor(div);\n      digits[i] = rounded;\n      if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)\n        throw new Error('convertRadix: carry overflow');\n      if (!done) continue;\n      else if (!rounded) pos = i;\n      else done = false;\n    }\n    res.push(carry);\n    if (done) break;\n  }\n  // Preserve explicit leading zero digits so callers like base58 keep zero-prefix semantics.\n  for (let i = 0; i \u003c data.length - 1 \u0026\u0026 data[i] === 0; i++) res.push(0);\n  return res.reverse();\n}\n\nconst gcd = (a: number, b: number): number =\u003e (b === 0 ? a : gcd(b, a % b));\n// Maximum carry width before the `pos` cycle repeats.\n// Residues advance in gcd(from, to) steps, so the largest pre-drain width is from + (to - gcd).\nconst radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from: number, to: number) =\u003e\n  from + (to - gcd(from, to));\nconst powers: number[] = /* @__PURE__ */ (() =\u003e {\n  let res = [];\n  for (let i = 0; i \u003c 40; i++) res.push(2 ** i);\n  return res;\n})();\n/**\n * Implemented with numbers, because BigInt is 5x slower\n */\nfunction convertRadix2(data: number[], from: number, to: number, padding: boolean): number[] {\n  aArr(data);\n  if (from \u003c= 0 || from \u003e 32) throw new RangeError(`convertRadix2: wrong from=${from}`);\n  if (to \u003c= 0 || to \u003e 32) throw new RangeError(`convertRadix2: wrong to=${to}`);\n  if (radix2carry(from, to) \u003e 32) {\n    throw new Error(\n      `convertRadix2: carry overflow from=${from} to=${to} carryBits=${radix2carry(from, to)}`\n    );\n  }\n  let carry = 0;\n  let pos = 0; // bitwise position in current element\n  const max = powers[from]!;\n  const mask = powers[to]! - 1;\n  const res: number[] = [];\n  for (const n of data) {\n    anumber(n);\n    if (n \u003e= max) throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);\n    carry = (carry \u003c\u003c from) | n;\n    if (pos + from \u003e 32) throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);\n    pos += from;\n    for (; pos \u003e= to; pos -= to) res.push(((carry \u003e\u003e (pos - to)) \u0026 mask) \u003e\u003e\u003e 0);\n    const pow = powers[pos];\n    if (pow === undefined) throw new Error('invalid carry');\n    carry \u0026= pow - 1; // clean carry, otherwise it will cause overflow\n  }\n  carry = (carry \u003c\u003c (to - pos)) \u0026 mask;\n  // Canonical decode paths reject leftover whole input words and non-zero pad bits.\n  // For Bech32 5-\u003e8 regrouping, this is the \"4 bits or less, all zeroes\" tail rule.\n  if (!padding \u0026\u0026 pos \u003e= from) throw new Error('Excess padding');\n  if (!padding \u0026\u0026 carry \u003e 0) throw new Error(`Non-zero padding: ${carry}`);\n  if (padding \u0026\u0026 pos \u003e 0) res.push(carry \u003e\u003e\u003e 0);\n  return res;\n}\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction radix(num: number): TRet\u003cCoder\u003cUint8Array, number[]\u003e\u003e {\n  anumber(num);\n  const _256 = 2 ** 8;\n  // Base-range and carry-overflow checks live in convertRadix so encode/decode reject unsupported bases symmetrically.\n  return {\n    encode: (bytes: TArg\u003cUint8Array\u003e) =\u003e {\n      if (!isBytes(bytes)) throw new TypeError('radix.encode input should be Uint8Array');\n      return convertRadix(Array.from(bytes), _256, num);\n    },\n    decode: (digits: number[]) =\u003e {\n      anumArr('radix.decode', digits);\n      return Uint8Array.from(convertRadix(digits, num, _256));\n    },\n  };\n}\n\n/**\n * If both bases are power of same number (like `2**8 \u003c-\u003e 2**64`),\n * there is a linear algorithm. For now we have implementation for power-of-two bases only.\n * @__NO_SIDE_EFFECTS__\n */\nfunction radix2(bits: number, revPadding = false): TRet\u003cCoder\u003cUint8Array, number[]\u003e\u003e {\n  anumber(bits);\n  if (bits \u003c= 0 || bits \u003e 32) throw new RangeError('radix2: bits should be in (0..32]');\n  if (radix2carry(8, bits) \u003e 32 || radix2carry(bits, 8) \u003e 32)\n    throw new RangeError('radix2: carry overflow');\n  // revPadding flips which direction allows a partial zero tail.\n  // Default pads 8-\u003ebits and rejects extra bits on bits-\u003e8; `true` does the opposite.\n  return {\n    encode: (bytes: TArg\u003cUint8Array\u003e) =\u003e {\n      if (!isBytes(bytes)) throw new TypeError('radix2.encode input should be Uint8Array');\n      return convertRadix2(Array.from(bytes), 8, bits, !revPadding);\n    },\n    decode: (digits: number[]) =\u003e {\n      anumArr('radix2.decode', digits);\n      return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));\n    },\n  };\n}\n\ntype ArgumentTypes\u003cF extends Function\u003e = F extends (...args: infer A) =\u003e any ? A : never;\ntype BytesFn = (data: TArg\u003cUint8Array\u003e) =\u003e TRet\u003cUint8Array\u003e;\nfunction unsafeWrapper\u003cT extends (...args: any) =\u003e any\u003e(fn: T) {\n  afn(fn);\n  return function (...args: ArgumentTypes\u003cT\u003e): ReturnType\u003cT\u003e | void {\n    // Only for *Unsafe APIs that intentionally collapse validation failures to `undefined`.\n    // Do not wrap code that needs to preserve exception details.\n    try {\n      return fn.apply(null, args);\n    } catch (e) {}\n  };\n}\n\nfunction checksum(len: number, fn: TArg\u003cBytesFn\u003e): TRet\u003cCoder\u003cUint8Array, Uint8Array\u003e\u003e {\n  anumber(len);\n  // Reject degenerate zero-byte checksums up front so callers don't accidentally\n  // build a no-op checksum stage.\n  if (len \u003c= 0) throw new RangeError(`checksum length must be positive: ${len}`);\n  afn(fn);\n  const _fn = fn as BytesFn;\n  // Uses the first `len` bytes of fn(data) in both directions.\n  // Current call sites rely on `len \u003e 0` and checksum functions that return at least that many bytes.\n  return {\n    encode(data: TArg\u003cUint8Array\u003e) {\n      if (!isBytes(data)) throw new TypeError('checksum.encode: input should be Uint8Array');\n      const sum = _fn(data).slice(0, len);\n      const res = new Uint8Array(data.length + len);\n      res.set(data);\n      res.set(sum, data.length);\n      return res;\n    },\n    decode(data: TArg\u003cUint8Array\u003e) {\n      if (!isBytes(data)) throw new TypeError('checksum.decode: input should be Uint8Array');\n      const payload = data.slice(0, -len);\n      const oldChecksum = data.slice(-len);\n      const newChecksum = _fn(payload).slice(0, len);\n      for (let i = 0; i \u003c len; i++)\n        if (newChecksum[i] !== oldChecksum[i]) throw new Error('Invalid checksum');\n      return payload;\n    },\n  };\n}\n\n// prettier-ignore\n/**\n * Low-level building blocks used by the exported codecs.\n * @example\n * Build a radix-32 coder from the low-level helpers.\n * ```ts\n * import { utils } from '@scure/base';\n * utils.radix2(5).encode(Uint8Array.from([1, 2, 3]));\n * ```\n */\nexport const utils: { alphabet: typeof alphabet; chain: typeof chain; checksum: typeof checksum; convertRadix: typeof convertRadix; convertRadix2: typeof convertRadix2; radix: typeof radix; radix2: typeof radix2; join: typeof join; padding: typeof padding; } = /* @__PURE__ */ Object.freeze({\n  alphabet, chain, checksum, convertRadix, convertRadix2, radix, radix2, join, padding,\n});\n\n// RFC 4648 aka RFC 3548\n// ---------------------\n\n/**\n * base16 encoding from RFC 4648.\n * This codec uses RFC 4648 Table 5's uppercase alphabet directly.\n * RFC 4648 §8 calls base16 \"case-insensitive hex encoding\", but we intentionally do not case-fold decode input here.\n * Use `hex` for case-insensitive hex decoding.\n * @example\n * ```js\n * base16.encode(Uint8Array.from([0x12, 0xab]));\n * // =\u003e '12AB'\n * ```\n */\nexport const base16: BytesCoder = /* @__PURE__ */ Object.freeze(\n  chain(radix2(4), alphabet('0123456789ABCDEF'), join(''))\n);\n\n/**\n * base32 encoding from RFC 4648. Has padding.\n * RFC 4648 §6 Table 3 uses uppercase letters, and RFC 4648 §3.4 allows applications to choose\n * upper- or lowercase alphabets. We keep the published uppercase table and do not case-fold decode input.\n * Use `base32nopad` for unpadded version.\n * Also check out `base32hex`, `base32hexnopad`, `base32crockford`.\n * @example\n * ```js\n * base32.encode(Uint8Array.from([0x12, 0xab]));\n * // =\u003e 'CKVQ===='\n * base32.decode('CKVQ====');\n * // =\u003e Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32: BytesCoder = /* @__PURE__ */ Object.freeze(\n  chain(radix2(5), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'), padding(5), join(''))\n);\n\n/**\n * base32 encoding from RFC 4648. No padding.\n * This variant inherits RFC 4648 base32's uppercase table and intentionally does not case-fold decode input.\n * Use `base32` for padded version.\n * Also check out `base32hex`, `base32hexnopad`, `base32crockford`.\n * @example\n * ```js\n * base32nopad.encode(Uint8Array.from([0x12, 0xab]));\n * // =\u003e 'CKVQ'\n * base32nopad.decode('CKVQ');\n * // =\u003e Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32nopad: BytesCoder = /* @__PURE__ */ Object.freeze(\n  chain(radix2(5), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'), join(''))\n);\n/**\n * base32 encoding from RFC 4648. Padded. Compared to ordinary `base32`, slightly different alphabet.\n * RFC 4648 §7 Table 4 uses uppercase letters, and we intentionally keep that table without case-folding decode input.\n * Use `base32hexnopad` for unpadded version.\n * @example\n * ```js\n * base32hex.encode(Uint8Array.from([0x12, 0xab]));\n * // =\u003e '2ALG===='\n * base32hex.decode('2ALG====');\n * // =\u003e Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32hex: BytesCoder = /* @__PURE__ */ Object.freeze(\n  chain(radix2(5), alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV'), padding(5), join(''))\n);\n\n/**\n * base32 encoding from RFC 4648. No padding. Compared to ordinary `base32`, slightly different alphabet.\n * This variant inherits RFC 4648 base32hex's uppercase table and intentionally does not case-fold decode input.\n * Use `base32hex` for padded version.\n * @example\n * ```js\n * base32hexnopad.encode(Uint8Array.from([0x12, 0xab]));\n * // =\u003e '2ALG'\n * base32hexnopad.decode('2ALG');\n * // =\u003e Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32hexnopad: BytesCoder = /* @__PURE__ */ Object.freeze(\n  chain(radix2(5), alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV'), join(''))\n);\n/**\n * base32 encoding from RFC 4648. Doug Crockford's version.\n * See {@link https://www.crockford.com/base32.html | Douglas Crockford's Base32}.\n * @example\n * ```js\n * base32crockford.encode(Uint8Array.from([0x12, 0xab]));\n * // =\u003e '2ANG'\n * base32crockford.decode('2ANG');\n * // =\u003e Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32crockford: BytesCoder = /* @__PURE__ */ Object.freeze(\n  chain(\n    radix2(5),\n    alphabet('0123456789ABCDEFGHJKMNPQRSTVWXYZ'),\n    join(''),\n    normalize((s: string) =\u003e s.toUpperCase().replace(/O/g, '0').replace(/[IL]/g, '1'))\n  )\n);\n\n// Built-in base64 conversion https://caniuse.com/mdn-javascript_builtins_uint8array_frombase64\n// Require both directions before taking the native fast path, so base64/base64url don't mix native and JS behavior.\n// prettier-ignore\nconst hasBase64Builtin: boolean = /* @__PURE__ */ (() =\u003e\n  typeof (Uint8Array as any).from([]).toBase64 === 'function' \u0026\u0026\n  typeof (Uint8Array as any).fromBase64 === 'function')();\n\n// Native `Uint8Array.fromBase64()` accepts these ASCII whitespace chars.\n// Reject them first so the native base64 path still follows RFC 4648 §3.3.\n// ASCII whitespace is U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, or U+0020 SPACE\nconst ASCII_WHITESPACE = /[\\t\\n\\f\\r ]/;\n\nconst decodeBase64Builtin = (s: string, isUrl: boolean) =\u003e {\n  astr('base64', s);\n  const alphabet = isUrl ? 'base64url' : 'base64';\n  // Per spec, .fromBase64 already throws on any other non-alphabet symbols except ASCII whitespace\n  // And checking just for whitespace makes decoding about 3x faster than a full range check.\n  // lastChunkHandling: 'strict' rejects loose tails and non-zero pad bits so native decoding stays canonical.\n  if (s.length \u003e 0 \u0026\u0026 ASCII_WHITESPACE.test(s)) throw new Error('invalid base64');\n  return (Uint8Array as any).fromBase64(s, { alphabet, lastChunkHandling: 'strict' });\n};\n\n/**\n * base64 from RFC 4648. Padded.\n * Use `base64nopad` for unpadded version.\n * Also check out `base64url`, `base64urlnopad`.\n * Falls back to built-in function, when available.\n * @example\n * ```js\n * base64.encode(Uint8Array.from([0x12, 0xab]));\n * // =\u003e 'Eqs='\n * base64.decode('Eqs=');\n * // =\u003e Uint8Array.from([0x12, 0xab])\n * ```\n */\n// prettier-ignore\nexport const base64: BytesCoder = /* @__PURE__ */ Object.freeze(hasBase64Builtin ? {\n  encode(b) { abytes(b); return (b as any).toBase64(); },\n  decode(s) { return decodeBase64Builtin(s, false); },\n} : chain(\n  radix2(6),\n  alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'),\n  padding(6),\n  join('')\n));\n/**\n * base64 from RFC 4648. No padding.\n * Use `base64` for padded version.\n * @example\n * ```js\n * base64nopad.encode(Uint8Array.from([0x12, 0xab]));\n * // =\u003e 'Eqs'\n * base64nopad.decode('Eqs');\n * // =\u003e Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base64nopad: BytesCoder = /* @__PURE__ */ Object.freeze(\n  chain(\n    radix2(6),\n    alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'),\n    join('')\n  )\n);\n\n/**\n * base64 from RFC 4648, using URL-safe alphabet. Padded.\n * Use `base64urlnopad` for unpadded version.\n * Falls back to built-in function, when available.\n * @example\n * ```js\n * base64url.encode(Uint8Array.from([0x12, 0xab]));\n * // =\u003e 'Eqs='\n * base64url.decode('Eqs=');\n * // =\u003e Uint8Array.from([0x12, 0xab])\n * ```\n */\n// prettier-ignore\nexport const base64url: BytesCoder = /* @__PURE__ */ Object.freeze(hasBase64Builtin ? {\n  encode(b) { abytes(b); return (b as any).toBase64({ alphabet: 'base64url' }); },\n  decode(s) { return decodeBase64Builtin(s, true); },\n} : chain(\n  radix2(6),\n  alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'),\n  padding(6),\n  join('')\n));\n\n/**\n * base64 from RFC 4648, using URL-safe alphabet. No padding.\n * Use `base64url` for padded version.\n * @example\n * ```js\n * base64urlnopad.encode(Uint8Array.from([0x12, 0xab]));\n * // =\u003e 'Eqs'\n * base64urlnopad.decode('Eqs');\n * // =\u003e Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base64urlnopad: BytesCoder = /* @__PURE__ */ Object.freeze(\n  chain(\n    radix2(6),\n    alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'),\n    join('')\n  )\n);\n\n// base58 code\n// -----------\nconst genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc: string) =\u003e\n  chain(radix(58), alphabet(abc), join(''));\n\n/**\n * base58: base64 without ambigous characters +, /, 0, O, I, l.\n * Quadratic (O(n^2)) - so, can't be used on large inputs.\n * @example\n * ```js\n * const text = base58.encode(Uint8Array.from([0, 1, 2]));\n * base58.decode(text);\n * // =\u003e Uint8Array.from([0, 1, 2])\n * ```\n */\nexport const base58: BytesCoder = /* @__PURE__ */ Object.freeze(\n  genBase58('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz')\n);\n/**\n * base58: flickr version. Check out `base58`.\n * @example\n * Round-trip bytes with the Flickr alphabet.\n * ```ts\n * const text = base58flickr.encode(Uint8Array.from([0, 1, 2]));\n * base58flickr.decode(text);\n * ```\n */\nexport const base58flickr: BytesCoder = /* @__PURE__ */ Object.freeze(\n  genBase58('123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ')\n);\n/**\n * base58: XRP version. Check out `base58`.\n * @example\n * Round-trip bytes with the XRP alphabet.\n * ```ts\n * const text = base58xrp.encode(Uint8Array.from([0, 1, 2]));\n * base58xrp.decode(text);\n * ```\n */\nexport const base58xrp: BytesCoder = /* @__PURE__ */ Object.freeze(\n  genBase58('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz')\n);\n\n// Data len (index) -\u003e encoded block len.\n// Monero pads each 1..8-byte block to this fixed base58 width so decode can recover the tail length.\nconst XMR_BLOCK_LEN = [0, 2, 3, 5, 6, 7, 9, 10, 11];\n\n/**\n * base58: XMR version. Check out `base58`.\n * Done in 8-byte blocks (which equals 11 chars in decoding). Last (non-full) block padded with '1' to size in XMR_BLOCK_LEN.\n * Block encoding significantly reduces quadratic complexity of base58.\n * @example\n * Round-trip bytes with the Monero block codec.\n * ```ts\n * const text = base58xmr.encode(Uint8Array.from([0, 1, 2]));\n * base58xmr.decode(text);\n * ```\n */\nexport const base58xmr: BytesCoder = /* @__PURE__ */ Object.freeze({\n  encode(data: TArg\u003cUint8Array\u003e) {\n    abytes(data);\n    let res = '';\n    for (let i = 0; i \u003c data.length; i += 8) {\n      const block = data.subarray(i, i + 8);\n      res += base58.encode(block).padStart(XMR_BLOCK_LEN[block.length]!, '1');\n    }\n    return res;\n  },\n  decode(str: string) {\n    astr('base58xmr.decode', str);\n    let res: number[] = [];\n    for (let i = 0; i \u003c str.length; i += 11) {\n      const slice = str.slice(i, i + 11);\n      const blockLen = XMR_BLOCK_LEN.indexOf(slice.length);\n      const block = base58.decode(slice);\n      for (let j = 0; j \u003c block.length - blockLen; j++) {\n        if (block[j] !== 0) throw new Error('base58xmr: wrong padding');\n      }\n      res = res.concat(Array.from(block.slice(block.length - blockLen)));\n    }\n    return Uint8Array.from(res);\n  },\n});\n\n/**\n * Method, which creates base58check encoder.\n * Requires function, calculating sha256.\n * Callers must include any version bytes in `data`; this helper only applies the\n * 4-byte double-SHA256 checksum used by Bitcoin Base58Check.\n * @param sha256 - Function used to calculate the checksum hash.\n * @returns base58check codec using 4 checksum bytes.\n * @throws On wrong argument types. {@link TypeError}\n * @example\n * Create a base58check codec from a SHA-256 implementation.\n * ```ts\n * import { createBase58check } from '@scure/base';\n * import { sha256 } from '@noble/hashes/sha2.js';\n * const coder = createBase58check(sha256);\n * coder.encode(Uint8Array.from([1, 2, 3]));\n * ```\n */\nexport const createBase58check = (sha256: TArg\u003cBytesFn\u003e): BytesCoder =\u003e {\n  // Validate the hash function at construction time so wrong inputs fail before returning a coder.\n  afn(sha256);\n  const _sha256 = sha256 as BytesFn;\n  return chain(\n    checksum(4, (data: TArg\u003cUint8Array\u003e) =\u003e _sha256(_sha256(data))),\n    base58\n  );\n};\n\n/**\n * Use `createBase58check` instead.\n * @deprecated Use {@link createBase58check} instead.\n * Callers must include any version bytes in `data`; this alias keeps the same\n * 4-byte double-SHA256 checksum behavior as `createBase58check`.\n * @param sha256 - Function used to calculate the checksum hash.\n * @returns base58check codec using 4 checksum bytes.\n * @example\n * Create a base58check codec with the deprecated alias.\n * ```ts\n * import { base58check } from '@scure/base';\n * import { sha256 } from '@noble/hashes/sha2.js';\n * const coder = base58check(sha256);\n * coder.encode(Uint8Array.from([1, 2, 3]));\n * ```\n */\nexport const base58check: (sha256: TArg\u003cBytesFn\u003e) =\u003e BytesCoder = createBase58check;\n\n// Bech32 code\n// -----------\n/** Result of bech32 decoding. */\nexport interface Bech32Decoded\u003cPrefix extends string = string\u003e {\n  /** Human-readable bech32 prefix. */\n  prefix: Prefix;\n  /** Decoded 5-bit word payload. */\n  words: number[];\n}\n/** Result of bech32 decoding with original bytes attached. */\nexport interface Bech32DecodedWithArray\u003cPrefix extends string = string\u003e {\n  /** Human-readable bech32 prefix. */\n  prefix: Prefix;\n  /** Decoded 5-bit word payload. */\n  words: number[];\n  /** Decoded payload converted back into raw bytes. */\n  bytes: Uint8Array;\n}\n\n// BIP 173 character table: data values 0..31 map to `qpzry9x8gf2tvdw0s3jn54khce6mua7l`.\nconst BECH_ALPHABET: Coder\u003cnumber[], string\u003e = chain(\n  alphabet('qpzry9x8gf2tvdw0s3jn54khce6mua7l'),\n  join('')\n);\n\n// BIP 173 `bech32_polymod` GEN coefficients.\nconst POLYMOD_GENERATORS = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];\n// BIP 173 step split: this applies the polymod state transition before callers xor in the next 5-bit value.\nfunction bech32Polymod(pre: number): number {\n  const b = pre \u003e\u003e 25;\n  let chk = (pre \u0026 0x1ffffff) \u003c\u003c 5;\n  for (let i = 0; i \u003c POLYMOD_GENERATORS.length; i++) {\n    if (((b \u003e\u003e i) \u0026 1) === 1) chk ^= POLYMOD_GENERATORS[i]!;\n  }\n  return chk;\n}\n\nfunction bechChecksum(prefix: string, words: number[], encodingConst = 1): string {\n  const len = prefix.length;\n  let chk = 1;\n  for (let i = 0; i \u003c len; i++) {\n    const c = prefix.charCodeAt(i);\n    if (c \u003c 33 || c \u003e 126) throw new Error(`Invalid prefix (${prefix})`);\n    chk = bech32Polymod(chk) ^ (c \u003e\u003e 5);\n  }\n  chk = bech32Polymod(chk);\n  for (let i = 0; i \u003c len; i++) chk = bech32Polymod(chk) ^ (prefix.charCodeAt(i) \u0026 0x1f);\n  for (let v of words) chk = bech32Polymod(chk) ^ v;\n  for (let i = 0; i \u003c 6; i++) chk = bech32Polymod(chk);\n  // BIP 173/BIP 350: xor the final checksum constant, then emit the 30-bit state as six 5-bit symbols.\n  chk ^= encodingConst;\n  return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]!], 30, 5, false));\n}\n\n/** bech32 codec surface. */\nexport interface Bech32 {\n  /**\n   * Encodes a human-readable prefix and 5-bit words into a bech32 string.\n   * @param prefix - Human-readable prefix.\n   * @param words - 5-bit words or raw bytes.\n   * @param limit - Maximum accepted output length, or `false` to disable the limit.\n   * @returns Encoded bech32 string.\n   */\n  encode\u003cPrefix extends string\u003e(\n    prefix: Prefix,\n    words: number[] | Uint8Array,\n    limit?: number | false\n  ): `${Lowercase\u003cPrefix\u003e}1${string}`;\n  /**\n   * Decodes a bech32 string into prefix and words.\n   * @param str - Encoded bech32 string.\n   * @param limit - Maximum accepted input length, or `false` to disable the limit.\n   * @returns Decoded prefix and 5-bit words.\n   */\n  decode\u003cPrefix extends string\u003e(\n    str: `${Prefix}1${string}`,\n    limit?: number | false\n  ): Bech32Decoded\u003cPrefix\u003e;\n  decode(str: string, limit?: number | false): Bech32Decoded;\n  /**\n   * Encodes raw bytes by first converting them to 5-bit words.\n   * @param prefix - Human-readable prefix.\n   * @param bytes - Raw bytes to encode.\n   * @returns Encoded bech32 string.\n   */\n  encodeFromBytes(prefix: string, bytes: Uint8Array): string;\n  /**\n   * Decodes a bech32 string and converts the payload back into bytes.\n   * @param str - Encoded bech32 string.\n   * @returns Decoded prefix, words, and bytes.\n   */\n  decodeToBytes(str: string): Bech32DecodedWithArray;\n  /**\n   * Decodes a bech32 string, returning `undefined` instead of throwing on invalid input.\n   * @param str - Encoded bech32 string.\n   * @param limit - Maximum accepted input length, or `false` to disable the limit.\n   * @returns Decoded prefix and words, or `undefined` for invalid input.\n   */\n  decodeUnsafe(str: string, limit?: number | false): void | Bech32Decoded\u003cstring\u003e;\n  /**\n   * Converts 5-bit words back into raw bytes.\n   * @param to - 5-bit words to decode.\n   * @returns Decoded bytes.\n   */\n  fromWords(to: number[]): Uint8Array;\n  /**\n   * Converts 5-bit words back into raw bytes, returning `undefined` instead of throwing.\n   * @param to - 5-bit words to decode.\n   * @returns Decoded bytes, or `undefined` for invalid input.\n   */\n  fromWordsUnsafe(to: number[]): void | Uint8Array;\n  /**\n   * Converts raw bytes into 5-bit words for bech32 encoding.\n   * @param from - Raw bytes to convert.\n   * @returns 5-bit words.\n   */\n  toWords(from: Uint8Array): number[];\n}\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction genBech32(encoding: 'bech32' | 'bech32m'): TRet\u003cBech32\u003e {\n  // BIP 173 uses final xor constant 1; BIP 350 swaps in 0x2bc830a3 for Bech32m.\n  const ENCODING_CONST = encoding === 'bech32' ? 1 : 0x2bc830a3;\n  const _words = radix2(5);\n  const fromWords = _words.decode;\n  const toWords = _words.encode;\n  const fromWordsUnsafe = unsafeWrapper(fromWords);\n\n  function encode\u003cPrefix extends string\u003e(\n    prefix: Prefix,\n    words: TArg\u003cnumber[] | Uint8Array\u003e,\n    limit: number | false = 90\n  ): `${Lowercase\u003cPrefix\u003e}1${string}` {\n    astr('bech32.encode prefix', prefix);\n    if (isBytes(words)) words = Array.from(words);\n    anumArr('bech32.encode', words);\n    const plen = prefix.length;\n    if (plen === 0) throw new TypeError(`Invalid prefix length ${plen}`);\n    // Total output is hrp + `1` separator + payload words + 6 checksum chars.\n    const actualLength = plen + 7 + words.length;\n    if (limit !== false \u0026\u0026 actualLength \u003e limit)\n      throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);\n    const lowered = prefix.toLowerCase();\n    const sum = bechChecksum(lowered, words, ENCODING_CONST);\n    return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}` as `${Lowercase\u003cPrefix\u003e}1${string}`;\n  }\n\n  function decode\u003cPrefix extends string\u003e(\n    str: `${Prefix}1${string}`,\n    limit?: number | false\n  ): Bech32Decoded\u003cPrefix\u003e;\n  function decode(str: string, limit?: number | false): Bech32Decoded;\n  function decode(str: string, limit: number | false = 90): Bech32Decoded {\n    astr('bech32.decode input', str);\n    const slen = str.length;\n    // Minimum length is 1-char hrp + `1` separator + 6-char checksum.\n    if (slen \u003c 8 || (limit !== false \u0026\u0026 slen \u003e limit))\n      throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);\n    // don't allow mixed case\n    const lowered = str.toLowerCase();\n    if (str !== lowered \u0026\u0026 str !== str.toUpperCase())\n      throw new Error(`String must be lowercase or uppercase`);\n    const sepIndex = lowered.lastIndexOf('1');\n    if (sepIndex === 0 || sepIndex === -1)\n      throw new Error(`Letter \"1\" must be present between prefix and data only`);\n    const prefix = lowered.slice(0, sepIndex);\n    const data = lowered.slice(sepIndex + 1);\n    if (data.length \u003c 6) throw new Error('Data must be at least 6 characters long');\n    const words = BECH_ALPHABET.decode(data).slice(0, -6);\n    const sum = bechChecksum(prefix, words, ENCODING_CONST);\n    if (!data.endsWith(sum)) throw new Error(`Invalid checksum in ${str}: expected \"${sum}\"`);\n    return { prefix, words };\n  }\n\n  const decodeUnsafe = unsafeWrapper(decode);\n\n  function decodeToBytes(str: string): TRet\u003cBech32DecodedWithArray\u003e {\n    // Keep the byte helper unbounded; callers that need the default BIP 173 length cap should use decode(str).\n    const { prefix, words } = decode(str, false);\n    return {\n      prefix,\n      words,\n      bytes: fromWords(words) as TRet\u003cUint8Array\u003e,\n    } as TRet\u003cBech32DecodedWithArray\u003e;\n  }\n\n  function encodeFromBytes(prefix: string, bytes: TArg\u003cUint8Array\u003e) {\n    // Keep the convenience wrapper on encode()'s default 90-char cap; custom limits should call encode(prefix, toWords(bytes), limit).\n    return encode(prefix, toWords(bytes));\n  }\n\n  return {\n    encode,\n    decode,\n    encodeFromBytes,\n    decodeToBytes,\n    decodeUnsafe,\n    fromWords,\n    fromWordsUnsafe,\n    toWords,\n  };\n}\n\n/**\n * bech32 from BIP 173. Operates on words.\n * For high-level helpers, check out {@link https://github.com/paulmillr/scure-btc-signer | scure-btc-signer}.\n * @example\n * Convert bytes to words, encode them, then decode back.\n * ```ts\n * const words = bech32.toWords(Uint8Array.from([1, 2, 3]));\n * const text = bech32.encode('bc', words);\n * bech32.decode(text);\n * ```\n */\nexport const bech32: TRet\u003cBech32\u003e = /* @__PURE__ */ Object.freeze(genBech32('bech32'));\n\n/**\n * bech32m from BIP 350. Operates on words.\n * It was to mitigate `bech32` weaknesses.\n * For high-level helpers, check out {@link https://github.com/paulmillr/scure-btc-signer | scure-btc-signer}.\n * @example\n * Convert bytes to words, encode them with bech32m, then decode back.\n * ```ts\n * const words = bech32m.toWords(Uint8Array.from([1, 2, 3]));\n * const text = bech32m.encode('bc', words);\n * bech32m.decode(text);\n * ```\n */\nexport const bech32m: TRet\u003cBech32\u003e = /* @__PURE__ */ Object.freeze(genBech32('bech32m'));\n\ndeclare const TextEncoder: any;\ndeclare const TextDecoder: any;\n\n/**\n * ASCII-to-byte decoder. Rejects non-ASCII text and bytes instead of doing UTF-8 replacement.\n * Method names follow `BytesCoder`, so `encode(bytes)` returns a string and `decode(string)` returns bytes.\n * @example\n * ```js\n * const b = ascii.decode(\"ABC\"); // =\u003e new Uint8Array([ 65, 66, 67 ])\n * const str = ascii.encode(b); // \"ABC\"\n * ```\n */\nexport const ascii: TRet\u003cBytesCoder\u003e = /* @__PURE__ */ Object.freeze({\n  encode(data: TArg\u003cUint8Array\u003e) {\n    abytes(data);\n    let res = '';\n    for (let i = 0; i \u003c data.length; i++) {\n      const byte = data[i]!;\n      // ASCII is 7-bit; reject bytes outside 0x00..0x7f instead of silently widening to\n      // Latin-1/UTF-8.\n      if (byte \u003e 127) throw new RangeError(`bytes contain non-ASCII byte ${byte} at position ${i}`);\n      res += String.fromCharCode(byte);\n    }\n    return res;\n  },\n  decode(str: string) {\n    if (typeof str !== 'string') throw new TypeError('ascii string expected, got ' + typeof str);\n    const res = new Uint8Array(str.length);\n    for (let i = 0; i \u003c str.length; i++) {\n      // Indexed access is much faster than Uint8Array.from(str, mapFn) here and keeps\n      // exact error positions.\n      const charCode = str.charCodeAt(i);\n      if (charCode \u003e 127) {\n        throw new RangeError(\n          `string contains non-ASCII character \"${str[i]}\" with code ${charCode} at position ${i}`\n        );\n      }\n      res[i] = charCode;\n    }\n    return res;\n  },\n});\n\nconst _isWellFormedShim = (str: string): boolean =\u003e {\n  // encodeURI rejects malformed UTF-16, giving a compact fallback that matches native\n  // isWellFormed on our tests/fuzz corpus.\n  try {\n    return encodeURI(str) !== null;\n  } catch {\n    return false;\n  }\n};\nconst _isWellFormed: (str: string) =\u003e boolean = /* @__PURE__ */ (() =\u003e\n  // Pick the native check once so utf8.decode doesn't re-probe String.prototype on every call.\n  typeof ('' as any).isWellFormed === 'function'\n    ? (str) =\u003e (str as any).isWellFormed()\n    : _isWellFormedShim)();\n// This fallback stays small because strict UTF-8 only needs fatal decoding plus well-formed\n// UTF-16 checks, not the replacement, streaming, or legacy-encoding behavior of full platform\n// text codecs.\nconst utf8Fallback: BytesCoder = /* @__PURE__ */ Object.freeze({\n  encode(data: TArg\u003cUint8Array\u003e) {\n    abytes(data);\n    let res = '';\n    for (let i = 0; i \u003c data.length; ) {\n      const a = data[i++]!;\n      if (a \u003c 0b1000_0000) {\n        res += String.fromCharCode(a);\n        continue;\n      }\n      if (a \u003c 0b1100_0010 || i \u003e= data.length) throw new TypeError(`invalid utf8 at byte ${i - 1}`);\n      const b = data[i++]!;\n      if ((b \u0026 0b1100_0000) !== 0b1000_0000) throw new TypeError(`invalid utf8 at byte ${i - 1}`);\n      let cp = ((a \u0026 0b0001_1111) \u003c\u003c 6) | (b \u0026 0b0011_1111);\n      if (a \u003e= 0b1110_0000) {\n        if (i \u003e= data.length) throw new TypeError(`invalid utf8 at byte ${i - 1}`);\n        const c = data[i++]!;\n        if (\n          (c \u0026 0b1100_0000) !== 0b1000_0000 ||\n          (a === 0b1110_0000 \u0026\u0026 b \u003c 0b1010_0000) ||\n          (a === 0xed \u0026\u0026 b \u003e= 0b1010_0000)\n        )\n          throw new TypeError(`invalid utf8 at byte ${i - 1}`);\n        cp = ((a \u0026 0b0000_1111) \u003c\u003c 12) | ((b \u0026 0b0011_1111) \u003c\u003c 6) | (c \u0026 0b0011_1111);\n        if (a \u003e= 0b1111_0000) {\n          if (i \u003e= data.length) throw new TypeError(`invalid utf8 at byte ${i - 1}`);\n          const d = data[i++]!;\n          if (\n            a \u003e 0b1111_0100 ||\n            (d \u0026 0b1100_0000) !== 0b1000_0000 ||\n            (a === 0b1111_0000 \u0026\u0026 b \u003c 0b1001_0000) ||\n            (a === 0b1111_0100 \u0026\u0026 b \u003e= 0b1001_0000)\n          )\n            throw new TypeError(`invalid utf8 at byte ${i - 1}`);\n          cp =\n            ((a \u0026 7) \u003c\u003c 18) |\n            ((b \u0026 0b0011_1111) \u003c\u003c 12) |\n            ((c \u0026 0b0011_1111) \u003c\u003c 6) |\n            (d \u0026 0b0011_1111);\n        }\n      }\n      if (cp \u003c 0x10000) res += String.fromCharCode(cp);\n      else {\n        cp -= 0x10000;\n        res += String.fromCharCode((cp \u003e\u003e 10) + 0xd800, (cp \u0026 0x3ff) + 0xdc00);\n      }\n    }\n    return res;\n  },\n  decode(str: string) {\n    astr('utf8', str);\n    if (!_isWellFormed(str)) throw new TypeError('utf8 expected well-formed string');\n    // Direct Uint8Array writes are much faster than number[] + Uint8Array.from on Hermes and\n    // large Node inputs.\n    const res = new Uint8Array(str.length * 3);\n    let pos = 0;\n    for (let i = 0; i \u003c str.length; i++) {\n      let c = str.charCodeAt(i);\n      if (c \u003c 0b1000_0000) {\n        res[pos++] = c;\n        continue;\n      }\n      if (c \u003e= 0xd800 \u0026\u0026 c \u003c= 0xdfff) {\n        const d = str.charCodeAt(++i);\n        c = 0x10000 + ((c - 0xd800) \u003c\u003c 10) + d - 0xdc00;\n      }\n      if (c \u003e= 0x10000) {\n        res[pos++] = (c \u003e\u003e 18) | 0b1111_0000;\n        res[pos++] = ((c \u003e\u003e 12) \u0026 0b0011_1111) | 0b1000_0000;\n      } else if (c \u003e= 0x800) res[pos++] = (c \u003e\u003e 12) | 0b1110_0000;\n      else res[pos++] = (c \u003e\u003e 6) | 0b1100_0000;\n      if (c \u003e= 0x800) res[pos++] = ((c \u003e\u003e 6) \u0026 0b0011_1111) | 0b1000_0000;\n      res[pos++] = (c \u0026 0b0011_1111) | 0b1000_0000;\n    }\n    return res.subarray(0, pos);\n  },\n});\n\n/**\n * Strict UTF-8-to-byte decoder. Uses built-in TextDecoder / TextEncoder when available.\n * Method names follow `BytesCoder`, so `encode(bytes)` returns a string and\n * `decode(string)` returns bytes.\n * `encode(bytes)` requires Uint8Array input, preserves an explicit leading BOM, and\n *   throws on invalid UTF-8 bytes.\n * `decode(string)` requires a primitive string and throws on malformed UTF-16 strings with\n *   lone surrogates.\n * @example\n * ```js\n * const b = utf8.decode(\"hey\"); // =\u003e new Uint8Array([ 104, 101, 121 ])\n * const str = utf8.encode(b); // \"hey\"\n * ```\n */\nexport const utf8: BytesCoder = /* @__PURE__ */ (() =\u003e {\n  let _utf8Encoder: any;\n  let _utf8Decoder: any;\n  const utf8Builtin: BytesCoder = {\n    // ignoreBOM preserves an explicit leading U+FEFF;\n    // fatal rejects invalid UTF-8 bytes instead of replacing them.\n    encode(data) {\n      abytes(data);\n      return (\n        _utf8Decoder || (_utf8Decoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }))\n      ).decode(data);\n    },\n    decode(str) {\n      astr('utf8', str);\n      if (!_isWellFormed(str)) throw new TypeError('utf8 expected well-formed string');\n      return (_utf8Encoder || (_utf8Encoder = new TextEncoder())).encode(str);\n    },\n  };\n  return Object.freeze({\n    // Select each direction once at module init, since\n    // TextEncoder and TextDecoder can exist independently.\n    encode: typeof TextDecoder === 'function' ? utf8Builtin.encode : utf8Fallback.encode,\n    decode: typeof TextEncoder === 'function' ? utf8Builtin.decode : utf8Fallback.decode,\n  });\n})();\n// Keep fallback parity probes behind a test-only export until runtime fallback behavior is decided.\nexport const __TESTS: {\n  utf8Fallback: BytesCoder;\n  _isWellFormedShim: (str: string) =\u003e boolean;\n} = /* @__PURE__ */ Object.freeze({\n  utf8Fallback: utf8Fallback,\n  _isWellFormedShim: _isWellFormedShim,\n});\n\n// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex\n// prettier-ignore\nconst hasHexBuiltin: boolean = /* @__PURE__ */ (() =\u003e\n  // Require both directions before enabling the native hex path so encode/decode stay symmetric.\n  typeof (Uint8Array as any).from([]).toHex === 'function' \u0026\u0026\n  typeof (Uint8Array as any).fromHex === 'function')();\n// prettier-ignore\nconst hexBuiltin: BytesCoder = {\n  // Keep local type guards so the native path preserves library-level input errors.\n  // Native toHex emits lowercase hex, matching the fallback alphabet and Node's hex strings.\n  encode(data) { abytes(data); return (data as any).toHex(); },\n  // Native fromHex accepts either hex case and rejects odd-length / non-hex syntax.\n  decode(s) { astr('hex', s); return (Uint8Array as any).fromHex(s); },\n};\n/**\n * hex string decoder. Uses built-in function, when available.\n * Lowercase codec; unlike `base16`, this variant accepts either hex case and emits lowercase.\n * @example\n * ```js\n * const b = hex.decode(\"0102ff\"); // =\u003e new Uint8Array([ 1, 2, 255 ])\n * const str = hex.encode(b); // \"0102ff\"\n * ```\n */\nexport const hex: BytesCoder = /* @__PURE__ */ Object.freeze(\n  hasHexBuiltin\n    ? hexBuiltin\n    : chain(\n        radix2(4),\n        alphabet('0123456789abcdef'),\n        join(''),\n        normalize((s: string) =\u003e {\n          if (typeof s !== 'string' || s.length % 2 !== 0)\n            throw new TypeError(\n              `hex.decode: expected string, got ${typeof s} with length ${s.length}`\n            );\n          return s.toLowerCase();\n        })\n      )\n);\n\n/** Built-in codecs exposed through the deprecated string conversion helpers. */\nexport type SomeCoders = {\n  /** UTF-8 string codec. */\n  utf8: BytesCoder;\n  /** Hex codec. */\n  hex: BytesCoder;\n  /** Uppercase RFC 4648 base16 codec. */\n  base16: BytesCoder;\n  /** RFC 4648 base32 codec with padding. */\n  base32: BytesCoder;\n  /** RFC 4648 base64 codec with padding. */\n  base64: BytesCoder;\n  /** URL-safe base64 codec without `+` or `/`. */\n  base64url: BytesCoder;\n  /** Bitcoin-style base58 codec. */\n  base58: BytesCoder;\n  /** Monero-style base58 codec. */\n  base58xmr: BytesCoder;\n};\n// prettier-ignore\n// Keep this registry aligned with CoderType/coderTypeError; only byte\u003c-\u003estring codecs belong here.\nconst CODERS: SomeCoders = {\n  utf8, hex, base16, base32, base64, base64url, base58, base58xmr\n};\ntype CoderType = keyof SomeCoders;\nconst coderTypeError =\n  'Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr';\n\n/**\n * Encodes bytes with one of the built-in codecs.\n * @deprecated Use the codec directly, for example `hex.encode(bytes)`.\n * @param type - Codec name.\n * @param bytes - Bytes to encode.\n * @returns Encoded string.\n * @throws On wrong argument types. {@link TypeError}\n * @example\n * ```ts\n * bytesToString('hex', Uint8Array.from([1, 2, 255]));\n * ```\n */\nexport const bytesToString = (type: CoderType, bytes: TArg\u003cUint8Array\u003e): string =\u003e {\n  if (typeof type !== 'string' || !CODERS.hasOwnProperty(type)) throw new TypeError(coderTypeError);\n  if (!isBytes(bytes)) throw new TypeError('bytesToString() expects Uint8Array');\n  return CODERS[type].encode(bytes);\n};\n\n/**\n * Alias for `bytesToString`.\n * @deprecated Use {@link bytesToString} or the codec directly instead.\n * @param type - Codec name.\n * @param bytes - Bytes to encode.\n * @returns Encoded string.\n * @example\n * ```ts\n * str('hex', Uint8Array.from([1, 2, 255]));\n * ```\n */\nexport const str: (type: CoderType, bytes: TArg\u003cUint8Array\u003e) =\u003e string = bytesToString; // as in python, but for bytes only\n\n/**\n * Decodes a string with one of the built-in codecs.\n * @deprecated Use the codec directly, for example `hex.decode(text)`.\n * @param type - Codec name.\n * @param str - Encoded string.\n * @returns Decoded bytes.\n * @throws On wrong argument types. {@link TypeError}\n * @example\n * ```ts\n * stringToBytes('hex', '0102ff');\n * ```\n */\nexport const stringToBytes = (type: CoderType, str: string): TRet\u003cUint8Array\u003e =\u003e {\n  // Match bytesToString's selector validation so hostile `toString()` coercions can't leak custom errors.\n  if (typeof type !== 'string' || !CODERS.hasOwnProperty(type)) throw new TypeError(coderTypeError);\n  if (typeof str !== 'string') throw new TypeError('stringToBytes() expects string');\n  return CODERS[type].decode(str) as TRet\u003cUint8Array\u003e;\n};\n/**\n * Alias for `stringToBytes`.\n * @deprecated Use {@link stringToBytes} or the codec directly instead.\n * @param type - Codec name.\n * @param str - Encoded string.\n * @returns Decoded bytes.\n * @example\n * ```ts\n * bytes('hex', '0102ff');\n * ```\n */\nexport const bytes: (type: CoderType, str: string) =\u003e TRet\u003cUint8Array\u003e = stringToBytes;\n"],"version":3}
