mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add admin signing module
This commit is contained in:
parent
b5643c4aba
commit
75135c62a4
1 changed files with 17 additions and 0 deletions
17
src/admin.ts
Normal file
17
src/admin.ts
Normal file
|
|
@ -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<K extends number = number>(event: EventTemplate<K>): Promise<SignedEvent<K>> {
|
||||||
|
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 };
|
||||||
Loading…
Add table
Reference in a new issue