From b0d4084a0f9ee21f2e3dac979a281764d7fecb41 Mon Sep 17 00:00:00 2001 From: kira924age Date: Thu, 21 Dec 2023 21:50:12 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20reafactor=20decodePa?= =?UTF-8?q?yload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index e1e256b..e1be4d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -198,14 +198,8 @@ async function importKey(key: string | JsonWebKey, algorithm: SubtleCryptoImport function decodePayload(raw: string): T | undefined { try { - const binaryString = atob(raw) - const bytes = new Uint8Array(binaryString.length); - for (let i = 0; i < binaryString.length; i++) { - bytes[i] = binaryString.charCodeAt(i); - } - - const decoder = new TextDecoder('utf-8'); - const decodedString = decoder.decode(bytes); + const bytes = Array.from(atob(raw), char => char.charCodeAt(0)); + const decodedString = new TextDecoder('utf-8').decode(new Uint8Array(bytes)); return JSON.parse(decodedString); } catch {