{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @otplib/plugin-base32-scure\n *\n * Base32 plugin for otplib using @scure/base.\n * Works universally across all JavaScript runtimes.\n */\n\nimport { base32 as scureBase32 } from \"@scure/base\";\n\nimport type { Base32EncodeOptions } from \"@otplib/core\";\nimport type { Base32Plugin } from \"@otplib/core\";\n\n/**\n * Scure Base32 plugin\n *\n * This implementation uses @scure/base for Base32 encoding/decoding.\n * @scure/base is a modern, audited cryptography library with zero dependencies.\n *\n * @example\n * ```ts\n * import { ScureBase32Plugin } from '@otplib/plugin-base32-scure';\n *\n * const plugin = new ScureBase32Plugin();\n * const encoded = plugin.encode(data);\n * const decoded = plugin.decode(encoded);\n * ```\n */\nexport class ScureBase32Plugin implements Base32Plugin {\n  readonly name = \"scure\";\n\n  /**\n   * Encode binary data to Base32 string\n   *\n   * @param data - Uint8Array to encode\n   * @param options - Encoding options\n   * @returns Base32 encoded string\n   */\n  encode(data: Uint8Array, options: Base32EncodeOptions = {}): string {\n    const { padding = false } = options;\n\n    const encoded = scureBase32.encode(data);\n    return padding ? encoded : encoded.replace(/=+$/, \"\");\n  }\n\n  /**\n   * Decode Base32 string to binary data\n   *\n   * @param str - Base32 string to decode\n   * @returns Decoded Uint8Array\n   * @throws {Error} If string contains invalid characters\n   */\n  decode(str: string): Uint8Array {\n    try {\n      const uppercased = str.toUpperCase();\n      const padded = uppercased.padEnd(Math.ceil(uppercased.length / 8) * 8, \"=\");\n      return scureBase32.decode(padded);\n    } catch (error) {\n      // @scure/base always throws Error instances; cast keeps the catch branchless.\n      throw new Error(`Invalid Base32 string: ${(error as Error).message}`);\n    }\n  }\n}\n\n/**\n * Default singleton instance for convenience\n *\n * @example\n * ```ts\n * import { base32 } from '@otplib/plugin-base32-scure';\n *\n * const encoded = base32.encode(data);\n * ```\n */\nexport const base32: Base32Plugin = Object.freeze(new ScureBase32Plugin());\n\nexport default ScureBase32Plugin;\n"],"mappings":"AAOA,OAAS,UAAUA,MAAmB,cAoB/B,IAAMC,EAAN,KAAgD,CAC5C,KAAO,QAShB,OAAOC,EAAkBC,EAA+B,CAAC,EAAW,CAClE,GAAM,CAAE,QAAAC,EAAU,EAAM,EAAID,EAEtBE,EAAUL,EAAY,OAAOE,CAAI,EACvC,OAAOE,EAAUC,EAAUA,EAAQ,QAAQ,MAAO,EAAE,CACtD,CASA,OAAOC,EAAyB,CAC9B,GAAI,CACF,IAAMC,EAAaD,EAAI,YAAY,EAC7BE,EAASD,EAAW,OAAO,KAAK,KAAKA,EAAW,OAAS,CAAC,EAAI,EAAG,GAAG,EAC1E,OAAOP,EAAY,OAAOQ,CAAM,CAClC,OAASC,EAAO,CAEd,MAAM,IAAI,MAAM,0BAA2BA,EAAgB,OAAO,EAAE,CACtE,CACF,CACF,EAYaC,EAAuB,OAAO,OAAO,IAAIT,CAAmB,EAElEU,EAAQV","names":["scureBase32","ScureBase32Plugin","data","options","padding","encoded","str","uppercased","padded","error","base32","index_default"]}