From 75135c62a4b65208ead403a605dcb4835676510c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 10 Jun 2023 23:00:10 -0500 Subject: [PATCH] Add admin signing module --- src/admin.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/admin.ts diff --git a/src/admin.ts b/src/admin.ts new file mode 100644 index 0000000..ab11011 --- /dev/null +++ b/src/admin.ts @@ -0,0 +1,17 @@ +import { Conf } from '@/config.ts'; +import { finishEvent, nip19 } from '@/deps.ts'; + +import type { SignedEvent, EventTemplate } from '@/event.ts'; + +// deno-lint-ignore require-await +async function signAdminEvent(event: EventTemplate): Promise> { + if (!Conf.nsec) throw new Error('No secret key. Set one with DITTO_NSEC.'); + + const result = nip19.decode(Conf.nsec); + + if (result.type !== 'nsec') throw new Error('Invalid DITTO_NSEC. It should start with "nsec1..."'); + + return finishEvent(event, result.data); +} + +export { signAdminEvent }; \ No newline at end of file