tinyrelayfile
tinyrelay/scripts/conformance/nip17.test.ts/

scripts/conformance/nip17.test.ts raw
1import { describe, it, expect } from "vitest";
2import { newEvent, newKey, pub, now, sockets } from "./helpers.ts";
3
4const connect = sockets();
5
6describe("NIP-17 / NIP-59 private kinds", () => {
7 it("serves gift wraps only to their recipients, stored and live, and lets recipients delete them", async () => {
8 const sender = newKey();
9 const recipient = newKey();
10 const stranger = newKey();
11 const s = await connect();
12 const wrap = newEvent(sender, 1059, "ciphertext", [["p", pub(recipient)]], now() - 100);
13 await s.publish(wrap);
14
15 const x = await connect();
16 x.send("REQ", "dm", { kinds: [1059], "#p": [pub(recipient)] });
17 await x.expectClosed("auth-required:");
18 let r = await x.req({ "#p": [pub(recipient)] });
19 expect(r.events).toEqual([]);
20 expect(r.hints).toContain("auth");
21 x.send("COUNT", "n", { "#p": [pub(recipient)] });
22 expect((await x.expect("COUNT"))[2].count).toBe(0);
23
24 await x.auth(stranger);
25 r = await x.req({ kinds: [1059], "#p": [pub(recipient)] });
26 expect(r.events).toEqual([]);
27 x.send("REQ", "live", { kinds: [1059], "#p": [pub(recipient)] });
28 await x.expect("EOSE");
29 await s.publish(newEvent(sender, 1059, "ciphertext2", [["p", pub(recipient)]], now() - 99));
30 await x.expectNothing();
31
32 const rc = await connect();
33 await rc.auth(recipient);
34 r = await rc.req({ kinds: [1059], "#p": [pub(recipient)] });
35 expect(r.events.length).toBe(2);
36 rc.send("REQ", "live", { kinds: [1059], "#p": [pub(recipient)] });
37 await rc.drain();
38 const wrap3 = newEvent(sender, 1059, "ciphertext3", [["p", pub(recipient)]], now() - 98);
39 await s.publish(wrap3);
40 expect((await rc.expect("EVENT"))[2].id).toBe(wrap3.id);
41
42 await rc.publish(newEvent(recipient, 5, "", [["e", wrap3.id]]));
43 expect((await rc.req({ ids: [wrap3.id] })).events).toEqual([]);
44 s.send("EVENT", wrap3);
45 expect(await s.expectOK(wrap3.id, false)).toMatch(/^blocked:/);
46 });
47});

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs