Skip to content

Commit 35987be

Browse files
committed
add pubkey hint to e tags
1 parent c644826 commit 35987be

File tree

5 files changed

+49
-31
lines changed

5 files changed

+49
-31
lines changed

.changeset/cold-pianos-tickle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nostr-dev-kit/ndk": minor
3+
---
4+
5+
deprecate user.zap/ndk.zap -- use new NDKZapper instead

.changeset/fifty-llamas-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nostr-dev-kit/ndk": patch
3+
---
4+
5+
add pubkey hint to e tags

.changeset/khaki-pets-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nostr-dev-kit/ndk": patch
3+
---
4+
5+
fix bug where both a and e tags were going in zap requests

ndk/src/events/index.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ describe("NDKEvent", () => {
2828

2929
describe("publish", () => {
3030
it("stores the relays where the event was successfully published to", async () => {
31-
const relay1 = new NDKRelay("wss://relay1.nos.dev");
32-
const relay2 = new NDKRelay("wss://relay2.nos.dev");
33-
const relay3 = new NDKRelay("wss://relay3.nos.dev");
31+
const relay1 = new NDKRelay("wss://relay1.nos.dev", undefined, ndk);
32+
const relay2 = new NDKRelay("wss://relay2.nos.dev", undefined, ndk);
33+
const relay3 = new NDKRelay("wss://relay3.nos.dev", undefined, ndk);
3434
const relaySet = new NDKRelaySet(new Set([relay1, relay2, relay3]), ndk);
3535
relaySet.publish = jest.fn().mockResolvedValue(new Set([relay1, relay2]));
3636

@@ -92,7 +92,7 @@ describe("NDKEvent", () => {
9292
otherEvent.author = user1;
9393

9494
event.tag(otherEvent);
95-
expect(event.tags).toEqual([["e", otherEvent.id]]);
95+
expect(event.tags).toEqual([["e", otherEvent.id, "", "", otherEvent.pubkey]]);
9696
});
9797

9898
it("tags an event with a marker", () => {
@@ -102,15 +102,15 @@ describe("NDKEvent", () => {
102102
} as NostrEvent);
103103
otherEvent.author = user1;
104104
event.tag(otherEvent, "marker");
105-
expect(event.tags).toEqual([["e", otherEvent.id, "", "marker"]]);
105+
expect(event.tags).toEqual([["e", otherEvent.id, "", "marker", otherEvent.pubkey]]);
106106
});
107107

108108
it("tags an event author when it's different from the signing user", () => {
109109
const otherEvent = new NDKEvent(ndk, { kind: 1 } as NostrEvent);
110110
otherEvent.author = user2;
111111
event.tag(otherEvent);
112112
expect(event.tags).toEqual([
113-
["e", otherEvent.id],
113+
["e", otherEvent.id, "", "", otherEvent.pubkey],
114114
["p", user2.pubkey],
115115
]);
116116
});
@@ -119,7 +119,7 @@ describe("NDKEvent", () => {
119119
const otherEvent = new NDKEvent(ndk, { kind: 1, id: "abc" } as NostrEvent);
120120
otherEvent.author = user1;
121121
event.tag(otherEvent);
122-
expect(event.tags).toEqual([["e", otherEvent.id]]);
122+
expect(event.tags).toEqual([["e", otherEvent.id, "", "", otherEvent.pubkey]]);
123123
});
124124

125125
it("does not re-tag the same user", () => {
@@ -130,9 +130,9 @@ describe("NDKEvent", () => {
130130
event.tag(otherEvent);
131131
event.tag(otherEvent2);
132132
expect(event.tags).toEqual([
133-
["e", otherEvent.id],
133+
["e", otherEvent.id, "", "", otherEvent.pubkey],
134134
["p", user2.pubkey],
135-
["e", otherEvent2.id],
135+
["e", otherEvent2.id, "", "", otherEvent2.pubkey],
136136
]);
137137
});
138138
});
@@ -223,11 +223,11 @@ describe("NDKEvent", () => {
223223

224224
expect(event1.referenceTags()).toEqual([
225225
["a", "30000:pubkey:d-code"],
226-
["e", "eventid1"],
226+
["e", "eventid1", "", "", "pubkey"],
227227
["p", "pubkey"],
228228
]);
229229
expect(event2.referenceTags()).toEqual([
230-
["e", "eventid2"],
230+
["e", "eventid2", "", "", "pubkey"],
231231
["p", "pubkey"],
232232
]);
233233
});
@@ -248,17 +248,17 @@ describe("NDKEvent", () => {
248248

249249
expect(nip33event.referenceTags("marker")).toEqual([
250250
["a", "30000:pubkey:d-code", "", "marker"],
251-
["e", "eventid1", "", "marker"],
251+
["e", "eventid1", "", "marker", "pubkey"],
252252
["p", "pubkey"],
253253
]);
254254
expect(event.referenceTags("marker")).toEqual([
255-
["e", "eventid2", "", "marker"],
255+
["e", "eventid2", "", "marker", "pubkey"],
256256
["p", "pubkey"],
257257
]);
258258
});
259259

260260
it("adds a marker to the reference tag if provided with relay if its set", () => {
261-
const relay = new NDKRelay("wss://relay.nos.dev/");
261+
const relay = new NDKRelay("wss://relay.nos.dev/", undefined, ndk);
262262
const nip33event = new NDKEvent(ndk, {
263263
kind: 30000,
264264
pubkey: "pubkey",
@@ -275,11 +275,11 @@ describe("NDKEvent", () => {
275275

276276
expect(nip33event.referenceTags("marker")).toEqual([
277277
["a", "30000:pubkey:d-code", "wss://relay.nos.dev/", "marker"],
278-
["e", "eventid1", "wss://relay.nos.dev/", "marker"],
278+
["e", "eventid1", "wss://relay.nos.dev/", "marker", "pubkey"],
279279
["p", "pubkey"],
280280
]);
281281
expect(event.referenceTags("marker")).toEqual([
282-
["e", "eventid2", "", "marker"],
282+
["e", "eventid2", "", "marker", "pubkey"],
283283
["p", "pubkey"],
284284
]);
285285
});
@@ -293,7 +293,7 @@ describe("NDKEvent", () => {
293293
} as NostrEvent);
294294

295295
expect(event.referenceTags()).toEqual([
296-
["e", "eventid"],
296+
["e", "eventid", "", "", "pubkey"],
297297
["h", "group-id"],
298298
["p", "pubkey"],
299299
]);

ndk/src/events/index.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -673,21 +673,24 @@ export class NDKEvent extends EventEmitter {
673673
}
674674

675675
// Add the relay url to all tags
676-
if (this.relay?.url) {
677-
tags = tags.map((tag) => {
678-
tag.push(this.relay?.url!);
679-
return tag;
680-
});
681-
} else if (marker) {
682-
tags = tags.map((tag) => {
683-
tag.push("");
684-
return tag;
685-
});
686-
}
676+
tags = tags.map((tag) => {
677+
if (tag[0] === "e" || marker) {
678+
tag.push(this.relay?.url ?? "");
679+
} else if (this.relay?.url) {
680+
tag.push(this.relay?.url);
681+
}
682+
return tag;
683+
});
687684

688-
if (marker) {
689-
tags.forEach((tag) => tag.push(marker)); // Add the marker to both "a" and "e" tags
690-
}
685+
// add marker and pubkey to e tags, and marker to a tags
686+
tags.forEach((tag) => {
687+
if (tag[0] === "e") {
688+
tag.push(marker ?? "");
689+
tag.push(this.pubkey);
690+
} else if (marker) {
691+
tag.push(marker);
692+
}
693+
});
691694

692695
// NIP-29 h-tags
693696
tags = [...tags, ...this.getMatchingTags("h")];

0 commit comments

Comments
 (0)