export function bufferToBase64url(buffer: ArrayBuffer): string { const bytes = new Uint8Array(buffer); let binary = ""; bytes.forEach((b) => (binary += String.fromCharCode(b))); return btoa(binary) .replace(/\+/g, "-") .replace(/\//g, "_") .replace(/=+$/, ""); } export function base64urlToBuffer(baseurl64: string): ArrayBuffer { const padding = "=".repeat((4 - (baseurl64.length % 4)) % 4); const base64 = (baseurl64 + padding).replace(/\-/g, "+").replace(/_/g, "/"); const rawData = atob(base64); const outputArray = new Uint8Array(rawData.length); for (let i = 0; i < rawData.length; ++i) { outputArray[i] = rawData.charCodeAt(i); } return outputArray.buffer; }