export function bytesToHex(bytes){return Array.from(bytes).map(b=>b.toString(16).padStart(2,"0")).join("")}export function hexToBytes(hex){if(hex.length%2!==0){throw new Error("Invalid HEX string: length must be even")}const bytes=[];for(let i=0;i<hex.length;i+=2){const byte=parseInt(hex.substr(i,2),16);bytes.push(byte)}return bytes}export function bytesToUtf8(binaryArray){let decoder=new TextDecoder("utf-8");return decoder.decode(new Uint8Array(binaryArray).buffer)}export function utf8ToBytes(utf8String){let encoder=new TextEncoder("utf-8");let uint8Array=encoder.encode(utf8String);return Array.from(uint8Array)}export function bytesToBase64(bytes){let binary="";const array=new Uint8Array(bytes);const len=array.byteLength;for(let i=0;i<len;i++){binary+=String.fromCharCode(array[i])}return window.btoa(binary)}export function bytesToBase64UsingBlob(bytes){return new Promise((resolve,reject)=>{const blob=new Blob([bytes],{type:"application/octet-stream"});const reader=new FileReader;reader.onloadend=()=>resolve(reader.result.split(",")[1]);reader.onerror=reject;reader.readAsDataURL(blob)})}export function base64ToBytes(base64){base64=base64.replace(/[-_]/g,function(match){return match==="-"?"+":"/"}).replace(/[^A-Za-z0-9+/=]/g,"");const binaryString=window.atob(base64);const len=binaryString.length;const bytes=new Uint8Array(len);for(let i=0;i<len;i++){bytes[i]=binaryString.charCodeAt(i)}return Array.from(bytes)}export function utf8ToBase64(str){const encoder=new TextEncoder;const uint8Array=encoder.encode(str);let binary="";const len=uint8Array.byteLength;for(let i=0;i<len;i++){binary+=String.fromCharCode(uint8Array[i])}return window.btoa(binary)}export function stringToBase64UsingBlob(str){const blob=new Blob([str],{type:"text/plain"});const reader=new FileReader;reader.readAsDataURL(blob);reader.onloadend=function(){const base64data=reader.result.split(",")[1];console.log(base64data)}}export function base64ToUtf8(base64){const binaryString=window.atob(base64);const decoder=new TextDecoder("utf-8");return decoder.decode(new Uint8Array(Array.from(binaryString).map(char=>char.charCodeAt(0))))}export function hexToBase64Simpler(hex){const bytes=[];for(let i=0;i<hex.length;i+=2){bytes.push(parseInt(hex.substr(i,2),16))}const uint8Array=new Uint8Array(bytes);let binary="";const len=uint8Array.byteLength;for(let i=0;i<len;i++){binary+=String.fromCharCode(uint8Array[i])}return btoa(binary)}export function utf8ToBinary(utf8String){let encoder=new TextEncoder("utf-8");let uint8Array=encoder.encode(utf8String);return Array.from(uint8Array)}