From 6f0f4394c98e33bdc4df676f017b9150039d962f Mon Sep 17 00:00:00 2001 From: Maximilian Dewald <20517052+Maggi64@users.noreply.github.com> Date: Mon, 13 Jun 2022 19:04:24 +0800 Subject: [PATCH] Update base64 encoding This new method doesn't rely on buffer anymore, which is NodeJS exclusive. Now this code can also run on the clientside. --- src/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6db4c79..9ceed10 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,14 +8,12 @@ // are little-endian. export function base64ToPasscodes(base64: string): Uint32Array { return new Uint32Array( - Uint8Array.from( - Buffer.from(base64, "base64") - ).buffer + new Uint8Array([...atob(base64)].map(c => c.fromCodePoint(0))).buffer ); } export function passcodesToBase64(passcodes: Uint32Array): string { - return Buffer.from(new Uint8Array(passcodes.buffer)).toString("base64"); + return btoa(String.fromCodePoint(...new Uint8Array(passcodes.buffer))) }