NIP-46 draft

This commit is contained in:
2023-07-05 11:41:47 +01:00
parent 9640a7fa57
commit 68b9a89278
8 changed files with 256 additions and 65 deletions

View File

@ -1,4 +1,4 @@
import { EventKind, HexKey, NostrPrefix, NostrEvent } from ".";
import { EventKind, HexKey, NostrPrefix, NostrEvent, EventSigner } from ".";
import { HashtagRegex } from "./const";
import { getPublicKey, unixNow } from "@snort/shared";
import { EventExt } from "./event-ext";
@ -73,10 +73,15 @@ export class EventBuilder {
* Build and sign event
* @param pk Private key to sign event with
*/
async buildAndSign(pk: HexKey) {
const ev = this.pubKey(getPublicKey(pk)).build();
await EventExt.sign(ev, pk);
return ev;
async buildAndSign(pk: HexKey | EventSigner) {
if (typeof pk === "string") {
const ev = this.pubKey(getPublicKey(pk)).build();
EventExt.sign(ev, pk);
return ev;
} else {
const ev = this.pubKey(await pk.getPubKey()).build();
return await pk.sign(ev);
}
}
#validate() {