diff options
Diffstat (limited to 'client-web/source/protocol/crypto.ts')
-rw-r--r-- | client-web/source/protocol/crypto.ts | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/client-web/source/protocol/crypto.ts b/client-web/source/protocol/crypto.ts index ebb552a..b75e816 100644 --- a/client-web/source/protocol/crypto.ts +++ b/client-web/source/protocol/crypto.ts @@ -14,14 +14,14 @@ const HASH_SALT = base64_to_buf("keksmeet/roomhashsaltA==") export async function derive_seeded_key(seed: string): Promise<CryptoKey> { log("crypto", "deriving crytographic key...") - const seed_key = await window.crypto.subtle.importKey( + const seed_key = await globalThis.crypto.subtle.importKey( "raw", new TextEncoder().encode(seed), "PBKDF2", false, ["deriveKey"] ) - const key = await window.crypto.subtle.deriveKey( + const key = await globalThis.crypto.subtle.deriveKey( { name: "PBKDF2", salt: CRYPTO_SALT, iterations: 250000, hash: "SHA-512" }, seed_key, { name: "AES-GCM", length: 256 }, @@ -34,14 +34,14 @@ export async function derive_seeded_key(seed: string): Promise<CryptoKey> { export async function room_hash(input: string): Promise<string> { log("crypto", "deriving room hash...") - const seed_key = await window.crypto.subtle.importKey( + const seed_key = await globalThis.crypto.subtle.importKey( "raw", new TextEncoder().encode(input), "PBKDF2", false, ["deriveBits"] ) - const key = await window.crypto.subtle.deriveBits( + const key = await globalThis.crypto.subtle.deriveBits( { name: "PBKDF2", salt: HASH_SALT, iterations: 250000, hash: "SHA-512" }, seed_key, 512 @@ -51,8 +51,8 @@ export async function room_hash(input: string): Promise<string> { } export async function encrypt(key: CryptoKey, data: string): Promise<string> { - const iv = window.crypto.getRandomValues(new Uint8Array(IV_LENGTH)); - const ciphertext = new Uint8Array(await window.crypto.subtle.encrypt( + const iv = globalThis.crypto.getRandomValues(new Uint8Array(IV_LENGTH)); + const ciphertext = new Uint8Array(await globalThis.crypto.subtle.encrypt( { name: "AES-GCM", iv }, key, new TextEncoder().encode(data) @@ -69,7 +69,7 @@ export async function decrypt(key: CryptoKey, data: string): Promise<string> { const buf = base64_to_buf(data); const iv = buf.slice(0, IV_LENGTH); const ciphertext = buf.slice(IV_LENGTH); - const decryptedContent = await window.crypto.subtle.decrypt( + const decryptedContent = await globalThis.crypto.subtle.decrypt( { name: "AES-GCM", iv }, key, ciphertext |