summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/zk-encryption.ts
diff options
context:
space:
mode:
authorMaze <167211895+mazeincoding@users.noreply.github.com>2026-01-31 00:20:04 +0100
committerGitHub <noreply@github.com>2026-01-31 00:20:04 +0100
commit7bf0984698e43b9aa2dd879f65951318ed410390 (patch)
treeccf2cd590a47d550152afc07129cb55c71a9ec35 /apps/web/src/lib/zk-encryption.ts
parent0173db99448d1c4c6415dcf15272e17551b48b04 (diff)
downloadopencut-7bf0984698e43b9aa2dd879f65951318ed410390.tar.gz
codebase overhaul (#697)
Diffstat (limited to 'apps/web/src/lib/zk-encryption.ts')
-rw-r--r--apps/web/src/lib/zk-encryption.ts71
1 files changed, 0 insertions, 71 deletions
diff --git a/apps/web/src/lib/zk-encryption.ts b/apps/web/src/lib/zk-encryption.ts
deleted file mode 100644
index 58734807..00000000
--- a/apps/web/src/lib/zk-encryption.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * True zero-knowledge encryption utilities
- * Keys are generated randomly in the browser and never derived from server secrets
- */
-
-export interface ZeroKnowledgeEncryptionResult {
- encryptedData: ArrayBuffer;
- key: ArrayBuffer;
- iv: ArrayBuffer;
-}
-
-/**
- * Encrypt data with a randomly generated key (true zero-knowledge)
- */
-export async function encryptWithRandomKey(
- data: ArrayBuffer
-): Promise<ZeroKnowledgeEncryptionResult> {
- // Generate a truly random 256-bit key
- const key = crypto.getRandomValues(new Uint8Array(32));
-
- // Generate random IV
- const iv = crypto.getRandomValues(new Uint8Array(12));
-
- // Import the key for encryption
- const cryptoKey = await crypto.subtle.importKey(
- "raw",
- key,
- { name: "AES-GCM" },
- false,
- ["encrypt"]
- );
-
- // Encrypt the data
- const encryptedResult = await crypto.subtle.encrypt(
- { name: "AES-GCM", iv },
- cryptoKey,
- data
- );
-
- // For AES-GCM, we need to append the authentication tag
- // The encrypted result contains both ciphertext and tag
- return {
- encryptedData: encryptedResult,
- key: key.buffer,
- iv: iv.buffer,
- };
-}
-
-/**
- * Convert ArrayBuffer to base64 string for transmission
- */
-export function arrayBufferToBase64(buffer: ArrayBuffer): string {
- const bytes = new Uint8Array(buffer);
- let binary = "";
- for (let i = 0; i < bytes.byteLength; i++) {
- binary += String.fromCharCode(bytes[i]);
- }
- return btoa(binary);
-}
-
-/**
- * Convert base64 string back to ArrayBuffer
- */
-export function base64ToArrayBuffer(base64: string): ArrayBuffer {
- const binary = atob(base64);
- const bytes = new Uint8Array(binary.length);
- for (let i = 0; i < binary.length; i++) {
- bytes[i] = binary.charCodeAt(i);
- }
- return bytes.buffer;
-}