summaryrefslogtreecommitdiff
path: root/client-web/source/protocol/crypto.ts
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-09-10 17:18:53 +0200
committermetamuffin <metamuffin@disroot.org>2022-09-10 17:18:53 +0200
commite45770adfcc46fe5f0350767801204efdb14313b (patch)
tree83574f71efd48cb743be7e20cbc59a8275883bbf /client-web/source/protocol/crypto.ts
parent4bbac9d27baa48c92cc299d03e86c9eed8881e08 (diff)
downloadkeks-meet-e45770adfcc46fe5f0350767801204efdb14313b.tar
keks-meet-e45770adfcc46fe5f0350767801204efdb14313b.tar.bz2
keks-meet-e45770adfcc46fe5f0350767801204efdb14313b.tar.zst
verify sendere
Diffstat (limited to 'client-web/source/protocol/crypto.ts')
-rw-r--r--client-web/source/protocol/crypto.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/client-web/source/protocol/crypto.ts b/client-web/source/protocol/crypto.ts
index 654e80b..76f48c0 100644
--- a/client-web/source/protocol/crypto.ts
+++ b/client-web/source/protocol/crypto.ts
@@ -73,6 +73,40 @@ export async function crypt_decrypt(key: CryptoKey, data: string): Promise<strin
}
}
+//* Code that might be useful in the future for signing
+// const ECDSA_PARAMS = { name: "ECDSA", namedCurve: "P-521", hash: { name: "SHA-384" } }
+// export async function crypto_sign(key: CryptoKey, message: string): Promise<string> {
+// const signature = await crypto.subtle.sign(
+// ECDSA_PARAMS,
+// key,
+// new TextEncoder().encode(message)
+// )
+// return buf_to_base64(new Uint8Array(signature))
+// }
+// export async function crypto_generate_signing_key(): Promise<CryptoKeyPair> {
+// return await crypto.subtle.generateKey(
+// ECDSA_PARAMS,
+// false,
+// ["sign", "verify"]
+// )
+// }
+// export async function crypto_verify(key: CryptoKey, message: string, signature: string): Promise<boolean> {
+// return await crypto.subtle.verify(
+// ECDSA_PARAMS,
+// key,
+// base64_to_buf(signature).buffer,
+// new TextEncoder().encode(message)
+// )
+// }
+// export async function export_public_signing_key(key: CryptoKey): Promise<string> {
+// const buf = await crypto.subtle.exportKey("spki", key)
+// return buf_to_base64(new Uint8Array(buf))
+// }
+// export async function import_public_signing_key(der: string): Promise<CryptoKey | undefined> {
+// const bin_der = base64_to_buf(der).buffer; // TODO safety
+// return await crypto.subtle.importKey("spki", bin_der, ECDSA_PARAMS, true, ["verify"]) // TODO safety
+// }
+
export function base64_to_buf(data: string): Uint8Array {
const binary_string = globalThis.atob(data);
const bytes = new Uint8Array(binary_string.length);