nip-59 gift wrap construct
This commit is contained in:
@ -11,6 +11,7 @@ enum EventKind {
|
|||||||
BadgeAward = 8, // NIP-58
|
BadgeAward = 8, // NIP-58
|
||||||
SnortSubscriptions = 1000, // NIP-XX
|
SnortSubscriptions = 1000, // NIP-XX
|
||||||
Polls = 6969, // NIP-69
|
Polls = 6969, // NIP-69
|
||||||
|
GiftWrap = 1059, // NIP-59
|
||||||
FileHeader = 1063, // NIP-94
|
FileHeader = 1063, // NIP-94
|
||||||
Relays = 10002, // NIP-65
|
Relays = 10002, // NIP-65
|
||||||
Ephemeral = 20_000,
|
Ephemeral = 20_000,
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import * as secp from "@noble/curves/secp256k1";
|
import * as secp from "@noble/curves/secp256k1";
|
||||||
import * as utils from "@noble/curves/abstract/utils";
|
import * as utils from "@noble/curves/abstract/utils";
|
||||||
import { unwrap, barrierQueue, processWorkQueue, WorkQueueItem } from "@snort/shared";
|
import { unwrap, barrierQueue, processWorkQueue, WorkQueueItem, getPublicKey } from "@snort/shared";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
EventKind,
|
EventKind,
|
||||||
FullRelaySettings,
|
FullRelaySettings,
|
||||||
HexKey,
|
HexKey,
|
||||||
Lists,
|
Lists,
|
||||||
|
Nip44Encryptor,
|
||||||
NostrEvent,
|
NostrEvent,
|
||||||
RelaySettings,
|
RelaySettings,
|
||||||
TaggedRawEvent,
|
TaggedRawEvent,
|
||||||
@ -16,6 +17,7 @@ import {
|
|||||||
|
|
||||||
import { EventBuilder } from "./EventBuilder";
|
import { EventBuilder } from "./EventBuilder";
|
||||||
import { EventExt } from "./EventExt";
|
import { EventExt } from "./EventExt";
|
||||||
|
import { findTag } from "./Utils";
|
||||||
|
|
||||||
const Nip7Queue: Array<WorkQueueItem> = [];
|
const Nip7Queue: Array<WorkQueueItem> = [];
|
||||||
processWorkQueue(Nip7Queue);
|
processWorkQueue(Nip7Queue);
|
||||||
@ -309,4 +311,25 @@ export class EventPublisher {
|
|||||||
fnHook(eb);
|
fnHook(eb);
|
||||||
return await this.#sign(eb);
|
return await this.#sign(eb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NIP-59 Gift Wrap event with ephemeral key
|
||||||
|
*/
|
||||||
|
async giftWrap(inner: NostrEvent) {
|
||||||
|
const secret = utils.bytesToHex(secp.secp256k1.utils.randomPrivateKey());
|
||||||
|
|
||||||
|
const pTag = findTag(inner, "p");
|
||||||
|
if (!pTag) throw new Error("Inner event must have a p tag");
|
||||||
|
|
||||||
|
const eb = new EventBuilder();
|
||||||
|
eb.pubKey(getPublicKey(secret));
|
||||||
|
eb.kind(EventKind.GiftWrap);
|
||||||
|
eb.tag(["p", pTag]);
|
||||||
|
|
||||||
|
const enc = new Nip44Encryptor();
|
||||||
|
const shared = enc.getSharedSecret(secret, pTag);
|
||||||
|
eb.content(enc.encryptData(JSON.stringify(inner), shared));
|
||||||
|
|
||||||
|
return await eb.buildAndSign(secret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user