mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-10 09:08:50 +00:00
finishEvent() takes an EventTemplate and returns an Event.
This commit is contained in:
9
event.ts
9
event.ts
@@ -2,6 +2,7 @@ import * as secp256k1 from '@noble/secp256k1'
|
|||||||
import {sha256} from '@noble/hashes/sha256'
|
import {sha256} from '@noble/hashes/sha256'
|
||||||
|
|
||||||
import {utf8Encoder} from './utils'
|
import {utf8Encoder} from './utils'
|
||||||
|
import {getPublicKey} from './keys'
|
||||||
|
|
||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
export enum Kind {
|
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 {
|
export function serializeEvent(evt: Event): string {
|
||||||
if (!validateEvent(evt))
|
if (!validateEvent(evt))
|
||||||
throw new Error("can't serialize event with wrong or missing properties")
|
throw new Error("can't serialize event with wrong or missing properties")
|
||||||
|
|||||||
Reference in New Issue
Block a user