export const bufferToBase = (buf: Uint8Array, base = 10): string => { if (base < 2 || base > 36) { throw new RangeError("Base must be between 2 and 36."); } const max = Math.ceil(8 / Math.log2(base)); // Math.log2(1 << 8) = 8 return Array.from(buf, (byte) => byte.toString(base).padStart(max, "0")).join( "", ); };