import { type AppContext } from '@/app.ts'; import { getEventHash, getPublicKey, getSignature, HTTPException } from '@/deps.ts'; import type { Event, EventTemplate, SignedEvent } from '@/event.ts'; /** Sign Nostr event using the app context. */ // deno-lint-ignore require-await async function signEvent(event: EventTemplate, c: AppContext): Promise> { const seckey = c.get('seckey'); // Ditto only supports publishing events with a private key (for now). // TODO: Let the client sign events through a websocket. if (!seckey) { throw new HTTPException(400, { res: c.json({ id: 'ditto.private_key', error: 'No private key' }, 400), }); } (event as Event).pubkey = getPublicKey(seckey); (event as Event).id = getEventHash(event as Event); (event as Event).sig = getSignature(event as Event, seckey); return event as SignedEvent; } export { signEvent };