// Decrypting a stored event. Plain module (no runes) so the service worker // can use it too. import type { EventPlaintext, GroupEvent } from '@oweme/core'; import { decryptJson, type GroupKeys } from './crypto.ts'; export async function decryptEvent( keys: GroupKeys, groupId: string, e: { id: string; seq: number | null; deviceId: string; iv: string; ct: string }, ): Promise { try { const p = await decryptJson(keys.encKey, e.iv, e.ct, `${groupId}|${e.id}`); return { ...p, id: e.id, seq: e.seq, deviceId: e.deviceId }; } catch { return null; // wrong key or tampered: skip it } }