finishEvent() takes an EventTemplate and returns an Event.

This commit is contained in:
fiatjaf
2023-02-16 11:58:13 -03:00
parent 95b03902cc
commit d13039dc11

View File

@@ -2,6 +2,7 @@ import * as secp256k1 from '@noble/secp256k1'
import {sha256} from '@noble/hashes/sha256'
import {utf8Encoder} from './utils'
import {getPublicKey} from './keys'
/* eslint-disable no-unused-vars */
export enum Kind {
@@ -47,6 +48,14 @@ export function getBlankEvent(): EventTemplate {
}
}
export function finishEvent(t: EventTemplate, privateKey: string): Event {
let event = t as Event
event.pubkey = getPublicKey(privateKey)
event.id = getEventHash(event)
event.sig = signEvent(event, privateKey)
return event
}
export function serializeEvent(evt: Event): string {
if (!validateEvent(evt))
throw new Error("can't serialize event with wrong or missing properties")