Improve chat encryption, delivery, and session handling

Adds robust session serialization/deserialization for ratchet state, session cleanup for corrupted data, and improved error handling in chat encryption hooks. Enhances chat delivery to support both local and remote recipients, ensures conversation creation, and adds timeouts to key fetches. Also introduces utilities for deleting and clearing encrypted session data from storage.
This commit is contained in:
Christopher
2026-01-27 20:36:03 -08:00
parent 8c3dffaa4c
commit e92c747a5b
7 changed files with 328 additions and 29 deletions
+18 -6
View File
@@ -12,14 +12,26 @@ export async function GET(request: NextRequest) {
const handle = searchParams.get('handle');
// Helper to fetch and check
// Helper to fetch and check with timeout
const tryFetch = async (url: string) => {
console.log(`[Proxy] Fetching keys from: ${url}`);
const res = await fetch(url, { headers: { 'Accept': 'application/json' } });
if (res.ok) return await res.json();
const text = await res.text();
console.warn(`[Proxy] Fetch failed for ${url} (${res.status}): ${text}`);
return null;
try {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), 5000); // 5s timeout
const res = await fetch(url, {
headers: { 'Accept': 'application/json' },
signal: controller.signal
});
clearTimeout(id);
if (res.ok) return await res.json();
const text = await res.text();
console.warn(`[Proxy] Fetch failed for ${url} (${res.status}): ${text}`);
return null;
} catch (err: any) {
console.warn(`[Proxy] Fetch error for ${url}: ${err.name} - ${err.message}`);
return null;
}
};
// 1. Try Primary DID