UNPKG

@opendatalabs/vana-sdk

Version:

A TypeScript library for interacting with Vana Network smart contracts.

39 lines 1.24 kB
function toBase64(data) { if (typeof Buffer !== "undefined" && Buffer.from) { return Buffer.from(data).toString("base64"); } if (typeof btoa !== "undefined") { const binary = Array.from(data, (byte) => String.fromCharCode(byte)).join( "" ); return btoa(binary); } throw new Error("No base64 encoding method available in this environment"); } function fromBase64(str) { if (typeof Buffer !== "undefined" && Buffer.from) { return new Uint8Array(Buffer.from(str, "base64")); } if (typeof atob !== "undefined") { const binary = atob(str); const bytes = new Uint8Array(binary.length); for (let i = 0; i < binary.length; i++) { bytes[i] = binary.charCodeAt(i); } return bytes; } throw new Error("No base64 decoding method available in this environment"); } function isNodeEnvironment() { return typeof Buffer !== "undefined" && typeof Buffer.from === "function" && typeof process !== "undefined" && process.versions?.node !== void 0; } function isBrowserEnvironment() { return typeof window !== "undefined" && typeof window.document !== "undefined"; } export { fromBase64, isBrowserEnvironment, isNodeEnvironment, toBase64 }; //# sourceMappingURL=encoding.js.map