{"version":3,"file":"base64.cjs","names":[],"sources":["../../src/utils/base64.ts"],"sourcesContent":["/**\n * Base64-encode bytes, without splatting the whole array into `fromCharCode`.\n *\n * `String.fromCharCode(...bytes)` overflows the argument limit somewhere around\n * a hundred thousand entries — which a compressed save reaches easily — so the\n * conversion walks the buffer in 32 KiB windows. That is also why this is the\n * version worth sharing: the byte-at-a-time loop the other two call sites used\n * has no argument limit either, but it is markedly slower on the payload sizes\n * `compressedStorage` exists for.\n *\n * @param bytes - The bytes to encode.\n * @param options - Pass `urlSafe` for the base64url alphabet (`-`/`_`, unpadded),\n *   which is what WebAuthn and anything travelling in a URL needs.\n * @returns Base64 text.\n */\nexport function bytesToBase64(bytes: Uint8Array, options: { urlSafe?: boolean } = {}): string {\n    let binary = \"\";\n    const chunkSize = 0x8000;\n    for (let index = 0; index < bytes.length; index += chunkSize) {\n        binary += String.fromCharCode(...bytes.subarray(index, index + chunkSize));\n    }\n    const encoded = btoa(binary);\n    if (!options.urlSafe) return encoded;\n    return encoded.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/**\n * Decode base64 into bytes, accepting either alphabet.\n *\n * Takes no `urlSafe` option on purpose: translating `-`/`_` and restoring the\n * padding are no-ops on standard padded base64, so one permissive decoder is\n * correct for both inputs. Getting this half wrong — usually by feeding\n * unpadded base64url straight to `atob` and losing the last byte — is the\n * classic broken-WebAuthn bug.\n *\n * @param value - Base64 or base64url text, with or without `=` padding.\n * @returns The decoded bytes.\n */\nexport function base64ToBytes(value: string): Uint8Array<ArrayBuffer> {\n    const standard = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n    const padded = standard.padEnd(standard.length + ((4 - (standard.length % 4)) % 4), \"=\");\n    const binary = atob(padded);\n    const bytes = new Uint8Array(binary.length);\n    for (let index = 0; index < binary.length; index += 1) {\n        bytes[index] = binary.charCodeAt(index);\n    }\n    return bytes;\n}\n"],"mappings":"AAeA,SAAgB,EAAc,EAAmB,EAAiC,CAAC,EAAW,CAC1F,IAAI,EAAS,GACP,EAAY,MAClB,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAM,OAAQ,GAAS,EAC/C,GAAU,OAAO,aAAa,GAAG,EAAM,SAAS,EAAO,EAAQ,CAAS,CAAC,EAE7E,IAAM,EAAU,KAAK,CAAM,EAE3B,OADK,EAAQ,QACN,EAAQ,QAAQ,MAAO,GAAG,CAAC,CAAC,QAAQ,MAAO,GAAG,CAAC,CAAC,QAAQ,MAAO,EAAE,EAD3C,CAEjC,CAcA,SAAgB,EAAc,EAAwC,CAClE,IAAM,EAAW,EAAM,QAAQ,KAAM,GAAG,CAAC,CAAC,QAAQ,KAAM,GAAG,EACrD,EAAS,EAAS,OAAO,EAAS,QAAW,EAAK,EAAS,OAAS,GAAM,EAAI,GAAG,EACjF,EAAS,KAAK,CAAM,EACpB,EAAQ,IAAI,WAAW,EAAO,MAAM,EAC1C,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAO,OAAQ,GAAS,EAChD,EAAM,GAAS,EAAO,WAAW,CAAK,EAE1C,OAAO,CACX"}