Files
Synapsis/src/app/.well-known/synapsis/chat/[did]/route.ts
T
Christopher a87977241c Refactor chat encryption to use sodium, update API
Replaces legacy chat encryption modules with new sodium-based implementation. Adds and updates API routes for chat key management and debugging, introduces new hooks and scripts for sodium chat, and updates related database schema and configuration. Removes old crypto modules and updates dependencies accordingly.
2026-01-28 06:07:03 -08:00

49 lines
1.4 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/db';
import { chatDeviceBundles } from '@/db/schema';
import { eq } from 'drizzle-orm';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ did: string }> }
) {
const { did } = await params;
// Fetch device bundle for this DID
const bundle = await db.query.chatDeviceBundles.findFirst({
where: eq(chatDeviceBundles.did, did),
});
if (!bundle) {
return NextResponse.json({ error: 'No keys found' }, { status: 404 });
}
const signedPreKey = JSON.parse(bundle.signedPreKey);
const kyberPreKey = bundle.kyberPreKey ? JSON.parse(bundle.kyberPreKey) : null;
// Format Response for Olm
const response = {
identityKey: bundle.identityKey, // curve25519
signingKey: signedPreKey.signingKey, // ed25519
oneTimeKeys: kyberPreKey?.oneTimeKeys || [],
};
return NextResponse.json(response, {
headers: {
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'max-age=60'
}
});
}
export async function OPTIONS() {
return new NextResponse(null, {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
});
}