From e45770adfcc46fe5f0350767801204efdb14313b Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 10 Sep 2022 17:18:53 +0200 Subject: verify sendere --- client-web/source/protocol/crypto.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'client-web/source/protocol/crypto.ts') 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 { +// 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 { +// return await crypto.subtle.generateKey( +// ECDSA_PARAMS, +// false, +// ["sign", "verify"] +// ) +// } +// export async function crypto_verify(key: CryptoKey, message: string, signature: string): Promise { +// 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 { +// 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 { +// 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); -- cgit v1.2.3-70-g09d2