{"version":3,"sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["/**\n * @otplib/plugin-base32-alt\n *\n * Alternative encoding plugins for otplib - use secrets without Base32 encoding.\n */\nimport { createBase32Plugin, stringToBytes, bytesToString } from \"@otplib/core\";\n\nimport { bytesToBase64, base64ToBytes, bytesToHex, hexToBytes } from \"./utils.js\";\n\nimport type { Base32Plugin } from \"@otplib/core\";\n\n/**\n * UTF-8 string bypass - treats secrets as plain text\n *\n * Use this when your secret is a plain text string that should be\n * converted directly to bytes without Base32 encoding.\n *\n * @example\n * ```ts\n * import { bypassAsString } from '@otplib/plugin-base32-alt';\n * import { generate } from '@otplib/totp';\n *\n * await generate({ secret: \"mysecretkey\", base32: bypassAsString, crypto });\n * ```\n */\nexport const bypassAsString: Base32Plugin = createBase32Plugin({\n  name: \"bypass-as-string\",\n  encode: bytesToString,\n  decode: stringToBytes,\n});\n\n/**\n * Hex string bypass - treats secrets as hex-encoded strings\n *\n * Use this when your secret is a hex string that should be\n * converted directly to bytes without Base32 encoding.\n *\n * @example\n * ```ts\n * import { bypassAsHex } from '@otplib/plugin-base32-alt';\n * import { generate } from '@otplib/totp';\n *\n * await generate({ secret: \"48656c6c6f\", base32: bypassAsHex, crypto });\n * ```\n */\nexport const bypassAsHex: Base32Plugin = createBase32Plugin({\n  name: \"bypass-as-hex\",\n  encode: bytesToHex,\n  decode: hexToBytes,\n});\n\n/**\n * Alias for bypassAsHex - base16 is the formal name for hex encoding\n */\nexport const bypassAsBase16: Base32Plugin = bypassAsHex;\n\n/**\n * Base64 string bypass - treats secrets as base64-encoded strings\n *\n * Use this when your secret is a base64 string that should be\n * converted directly to bytes without Base32 encoding.\n *\n * @example\n * ```ts\n * import { bypassAsBase64 } from '@otplib/plugin-base32-alt';\n * import { generate } from '@otplib/totp';\n *\n * await generate({ secret: \"SGVsbG8=\", base32: bypassAsBase64, crypto });\n * ```\n */\nexport const bypassAsBase64: Base32Plugin = createBase32Plugin({\n  name: \"bypass-as-base64\",\n  encode: bytesToBase64,\n  decode: base64ToBytes,\n});\n\n// Re-export factory for custom bypasses\nexport { createBase32Plugin } from \"@otplib/core\";\nexport type { CreateBase32PluginOptions } from \"@otplib/core\";\n","const NOT_HEX = /[^0-9a-f]/i;\n\nexport function hexToBytes(hex: string): Uint8Array {\n  if (hex.length === 0) {\n    return new Uint8Array(0);\n  }\n  if (hex.length % 2 !== 0) {\n    throw new Error(\"Hex string must have an even number of characters\");\n  }\n  if (NOT_HEX.test(hex)) {\n    throw new Error(\"Hex string contains invalid characters\");\n  }\n  const bytes = new Uint8Array(hex.length / 2);\n  for (let i = 0; i < bytes.length; i++) {\n    bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n  }\n  return bytes;\n}\n\nexport function bytesToHex(bytes: Uint8Array): string {\n  let hex = \"\";\n  for (let i = 0; i < bytes.length; i++) {\n    hex += bytes[i].toString(16).padStart(2, \"0\");\n  }\n  return hex;\n}\n\nexport function base64ToBytes(base64: string): Uint8Array {\n  return new Uint8Array([...atob(base64)].map((c) => c.charCodeAt(0)));\n}\n\nexport function bytesToBase64(bytes: Uint8Array): string {\n  return btoa(String.fromCharCode(...bytes));\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,mBAAAC,EAAA,6DAAAC,EAAAN,GAKA,IAAAO,EAAiE,wBCLjE,IAAMC,EAAU,aAET,SAASC,EAAWC,EAAyB,CAClD,GAAIA,EAAI,SAAW,EACjB,OAAO,IAAI,WAAW,CAAC,EAEzB,GAAIA,EAAI,OAAS,IAAM,EACrB,MAAM,IAAI,MAAM,mDAAmD,EAErE,GAAIF,EAAQ,KAAKE,CAAG,EAClB,MAAM,IAAI,MAAM,wCAAwC,EAE1D,IAAMC,EAAQ,IAAI,WAAWD,EAAI,OAAS,CAAC,EAC3C,QAASE,EAAI,EAAGA,EAAID,EAAM,OAAQC,IAChCD,EAAMC,CAAC,EAAI,SAASF,EAAI,MAAME,EAAI,EAAGA,EAAI,EAAI,CAAC,EAAG,EAAE,EAErD,OAAOD,CACT,CAEO,SAASE,EAAWF,EAA2B,CACpD,IAAID,EAAM,GACV,QAASE,EAAI,EAAGA,EAAID,EAAM,OAAQC,IAChCF,GAAOC,EAAMC,CAAC,EAAE,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,EAE9C,OAAOF,CACT,CAEO,SAASI,EAAcC,EAA4B,CACxD,OAAO,IAAI,WAAW,CAAC,GAAG,KAAKA,CAAM,CAAC,EAAE,IAAKC,GAAMA,EAAE,WAAW,CAAC,CAAC,CAAC,CACrE,CAEO,SAASC,EAAcN,EAA2B,CACvD,OAAO,KAAK,OAAO,aAAa,GAAGA,CAAK,CAAC,CAC3C,CD4CA,IAAAO,EAAmC,wBApDtBC,KAA+B,sBAAmB,CAC7D,KAAM,mBACN,OAAQ,gBACR,OAAQ,eACV,CAAC,EAgBYC,KAA4B,sBAAmB,CAC1D,KAAM,gBACN,OAAQC,EACR,OAAQC,CACV,CAAC,EAKYC,EAA+BH,EAgB/BI,KAA+B,sBAAmB,CAC7D,KAAM,mBACN,OAAQC,EACR,OAAQC,CACV,CAAC","names":["index_exports","__export","bypassAsBase16","bypassAsBase64","bypassAsHex","bypassAsString","__toCommonJS","import_core","NOT_HEX","hexToBytes","hex","bytes","i","bytesToHex","base64ToBytes","base64","c","bytesToBase64","import_core","bypassAsString","bypassAsHex","bytesToHex","hexToBytes","bypassAsBase16","bypassAsBase64","bytesToBase64","base64ToBytes"]}