Something went wrong. Try again.
Large file storage for AT Protocol: an IPFS server & gateway with XRPC upload & admin. atfs.dev
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778// Encodings shared by the setup flow. No dependencies: site/ is served// exactly as committed, so everything here has to run from source in a// browser with no build step.
const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
export function bytesToBase64(bytes) { let binary = ""; for (const byte of bytes) binary += String.fromCharCode(byte); return btoa(binary);}
export function base64ToBytes(text) { const binary = atob(text.trim()); const bytes = new Uint8Array(binary.length); for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i); return bytes;}
export function bytesToHex(bytes) { return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");}
export function hexToBytes(text) { const clean = text.trim().toLowerCase(); if (clean.length % 2 !== 0 || /[^0-9a-f]/.test(clean)) { throw new Error("not hexadecimal"); } const bytes = new Uint8Array(clean.length / 2); for (let i = 0; i < bytes.length; i++) { bytes[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16); } return bytes;}
export function bytesToBase58(bytes) { const digits = [0]; for (const byte of bytes) { let carry = byte; for (let i = 0; i < digits.length; i++) { carry += digits[i] << 8; digits[i] = carry % 58; carry = (carry / 58) | 0; } while (carry > 0) { digits.push(carry % 58); carry = (carry / 58) | 0; } }
let out = ""; for (const byte of bytes) { if (byte !== 0) break; out += BASE58_ALPHABET[0]; } for (let i = digits.length - 1; i >= 0; i--) out += BASE58_ALPHABET[digits[i]]; return out;}
export function concatBytes(...parts) { const total = parts.reduce((n, p) => n + p.length, 0); const out = new Uint8Array(total); let offset = 0; for (const part of parts) { out.set(part, offset); offset += part.length; } return out;}
export function bytesEqual(a, b) { if (a.length !== b.length) return false; for (let i = 0; i < a.length; i++) { if (a[i] !== b[i]) return false; } return true;}