@opendatalabs/vana-sdk
Version:
A TypeScript library for interacting with Vana Network smart contracts.
53 lines (52 loc) • 1.6 kB
TypeScript
/**
* Provides platform-aware base64 encoding utilities.
*
* @remarks
* This module provides base64 encoding/decoding operations across Node.js and browser
* environments. For hex and string conversions, use viem's utilities directly:
* - `toHex` / `fromHex` from 'viem'
* - `stringToBytes` / `bytesToString` from 'viem'
*
* @category Utilities
*/
/**
* Converts a Uint8Array to a base64 string.
*
* @param data - The byte array to encode into base64 format.
* @returns The base64-encoded string representation.
* @throws {Error} When no base64 encoding method is available in the environment.
*
* @example
* ```typescript
* const bytes = new Uint8Array([72, 101, 108, 108, 111]);
* const encoded = toBase64(bytes);
* console.log(encoded); // "SGVsbG8="
* ```
*/
export declare function toBase64(data: Uint8Array): string;
/**
* Converts a base64 string to a Uint8Array.
*
* @param str - The base64-encoded string to decode.
* @returns The decoded byte array.
* @throws {Error} When no base64 decoding method is available in the environment.
*
* @example
* ```typescript
* const decoded = fromBase64("SGVsbG8=");
* console.log(new TextDecoder().decode(decoded)); // "Hello"
* ```
*/
export declare function fromBase64(str: string): Uint8Array;
/**
* Type guard to check if running in Node.js environment
*
* @returns True if running in Node.js
*/
export declare function isNodeEnvironment(): boolean;
/**
* Type guard to check if running in browser environment
*
* @returns True if running in browser
*/
export declare function isBrowserEnvironment(): boolean;