Use globalThis for TextEncoder, TextDecoder, and atob browser globals

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-26 21:08:37 +01:00
parent a71493b87c
commit 73adc0a735
2 changed files with 3 additions and 3 deletions

View File

@@ -11,7 +11,7 @@ async function importKey(b64) {
async function encrypt(data) {
if (!encKey) return null
const json = new TextEncoder().encode(JSON.stringify(data))
const json = new globalThis.TextEncoder().encode(JSON.stringify(data))
const iv = globalThis.crypto.getRandomValues(new Uint8Array(12))
const encrypted = await globalThis.crypto.subtle.encrypt({ name: 'AES-GCM', iv, tagLength: 128 }, encKey, json)
const buf = new Uint8Array(encrypted)
@@ -28,7 +28,7 @@ async function decrypt(b64) {
const data = raw.slice(12)
try {
const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv, tagLength: 128 }, encKey, data)
return JSON.parse(new TextDecoder().decode(decrypted))
return JSON.parse(new globalThis.TextDecoder().decode(decrypted))
} catch {
return null
}

View File

@@ -403,7 +403,7 @@
let reference = decodedText;
try {
const decoded = atob(decodedText);
const decoded = globalThis.atob(decodedText);
if (decoded.startsWith('ETICKET-')) reference = decoded;
} catch {}