clone

nostr relays on demand at <name>.bind.ws: claim one with your key, pay in zaps past the free allowance

dependabot/npm_and_yarn/npm-f01a459b0f
bindws / test / conformance / nip17.test.ts
nip17.test.ts 1.9K
1import { describe, it, expect } from "vitest";2import { newEvent, newKey, pub, now, sockets } from "./helpers.ts";34const connect = sockets();56describe("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);1415 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);2324 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();3132 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);4142 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});