/** * Buffer Utility Functions * * This module provides utilities for converting between ArrayBuffer and Base64 string formats. * These are essential for WebAuthn operations where binary data needs to be serialized for * transmission or storage. * * @module utils/buffer */ /** * Converts an ArrayBuffer to a Base64-encoded string. * * This function is commonly used to serialize binary data from WebAuthn credentials * (such as credential IDs, attestation objects, and signatures) into a string format * suitable for JSON serialization and HTTP transmission. * * @param buffer - The ArrayBuffer to convert * @returns A Base64-encoded string representation of the buffer * * @example * ```typescript * const buffer = new Uint8Array([72, 101, 108, 108, 111]).buffer; * const base64 = bufferToBase64(buffer); * console.log(base64); // "SGVsbG8=" * ``` * * @remarks * This implementation uses a manual conversion approach rather than directly using btoa() * on the buffer to ensure compatibility with all buffer sizes and avoid potential issues * with binary data containing null bytes. */ export declare function bufferToBase64(buffer: ArrayBuffer): string; /** * Converts a Base64 or Base64URL string back to an ArrayBuffer. * * This function is commonly used to deserialize Base64-encoded credential data * received from a server or retrieved from storage back into the binary format * required by the WebAuthn API. * * **Both alphabets are accepted, deliberately.** WebAuthn hands out the same credential in two * encodings at once: `bufferToBase64(rawId)` gives standard Base64 (`+`, `/`, padded) while * `PublicKeyCredential.id` is Base64URL (`-`, `_`, unpadded). A single result object therefore * carries both spellings of one credential: * * ``` * credentialId: "bsA9+najCxZLvNhXIg/RawfFH77..." // standard * rawCredential.id: "bsA9-najCxZLvNhXIg_RawfFH77..." // Base64URL * ``` * * `atob` rejects `-` and `_` outright, so feeding it the second form threw * `InvalidCharacterError: The string to be decoded is not correctly encoded` — an error naming * neither the value nor the caller, typically surfacing from an `allowCredentials` entry that had * travelled through a store or a JSON round trip that normalised it. Since both spellings denote * the same bytes, normalising here is strictly better than making every caller guess which * alphabet it holds. * * Padding is restored too: Base64URL conventionally drops `=`, and `atob` requires it. * * @param base64 - The Base64 or Base64URL string to convert * @returns An ArrayBuffer containing the decoded binary data * @throws {Error} If the input is not valid in either alphabet — with the offending value in the * message, unlike the bare DOMException `atob` raises * * @example * ```typescript * base64ToBuffer('SGVsbG8='); // standard, padded * base64ToBuffer('SGVsbG8'); // unpadded * base64ToBuffer('a-b_c'); // Base64URL * ``` * * @remarks * The returned ArrayBuffer can be directly used with WebAuthn APIs that expect * BufferSource types, such as the `id` field in credential descriptors or the * `challenge` field in credential request options. */ export declare function base64ToBuffer(base64: string): ArrayBuffer; //# sourceMappingURL=buffer.d.ts.map