aboutsummaryrefslogtreecommitdiff
path: root/client-web/source/protocol
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-11-25 20:59:54 +0100
committermetamuffin <metamuffin@disroot.org>2024-11-25 20:59:54 +0100
commit440c12ac024e84f166eaa4115ef6715c39de2eea (patch)
tree11f4a32e3478d6babee7fb30349c47d7f7983168 /client-web/source/protocol
parent55f58e1d7017ef0038840e2a9d506cfaf85e8ea8 (diff)
downloadkeks-meet-440c12ac024e84f166eaa4115ef6715c39de2eea.tar
keks-meet-440c12ac024e84f166eaa4115ef6715c39de2eea.tar.bz2
keks-meet-440c12ac024e84f166eaa4115ef6715c39de2eea.tar.zst
replace window usage with globalThis
Diffstat (limited to 'client-web/source/protocol')
-rw-r--r--client-web/source/protocol/crypto.ts14
-rw-r--r--client-web/source/protocol/mod.ts4
2 files changed, 9 insertions, 9 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
diff --git a/client-web/source/protocol/mod.ts b/client-web/source/protocol/mod.ts
index d554820..de4293d 100644
--- a/client-web/source/protocol/mod.ts
+++ b/client-web/source/protocol/mod.ts
@@ -21,7 +21,7 @@ export class SignalingConnection {
constructor() { }
async connect(): Promise<SignalingConnection> {
log("ws", "connecting…")
- const ws_url = new URL(`${window.location.protocol.endsWith("s:") ? "wss" : "ws"}://${window.location.host}/signaling`)
+ const ws_url = new URL(`${globalThis.location.protocol.endsWith("s:") ? "wss" : "ws"}://${globalThis.location.host}/signaling`)
this.websocket = new WebSocket(ws_url)
this.websocket.onerror = () => this.on_error()
this.websocket.onclose = () => this.on_close()
@@ -38,7 +38,7 @@ export class SignalingConnection {
on_close() {
log("ws", "websocket closed");
setTimeout(() => {
- window.location.reload()
+ globalThis.location.reload()
}, 1000)
}
on_open() {