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

scripts/conformance/nip42.test.ts raw
1import { describe, it, expect } from "vitest";
2import { newEvent, newKey, now, RELAY_URL, sockets } from "./helpers.ts";
3
4const connect = sockets();
5
6describe("NIP-42 AUTH", () => {
7 it("refuses bad challenges, wrong relays, stale timestamps, wrong kinds; accepts several keys", async () => {
8 const sk = newKey();
9 const c = await connect();
10 const bad = (tags: string[][], ts = now(), kind = 22242) => newEvent(sk, kind, "", tags, ts);
11 let e = bad([["relay", RELAY_URL], ["challenge", "nope"]]);
12 c.send("AUTH", e);
13 expect(await c.expectOK(e.id, false)).toMatch(/challenge/);
14 e = bad([["relay", "wss://elsewhere.example"], ["challenge", c.challenge]]);
15 c.send("AUTH", e);
16 expect(await c.expectOK(e.id, false)).toMatch(/relay/);
17 e = bad([["relay", RELAY_URL], ["challenge", c.challenge]], now() - 3600);
18 c.send("AUTH", e);
19 expect(await c.expectOK(e.id, false)).toMatch(/time/);
20 e = bad([["relay", RELAY_URL], ["challenge", c.challenge]], now(), 1);
21 c.send("AUTH", e);
22 await c.expectOK(e.id, false);
23 // kind 22242 sent as a plain EVENT is never accepted.
24 const asEvent = newEvent(sk, 22242, "", [["relay", RELAY_URL], ["challenge", c.challenge]]);
25 c.send("EVENT", asEvent);
26 expect(await c.expectOK(asEvent.id, false)).toMatch(/^(blocked|invalid):/);
27 await c.auth(sk);
28 await c.auth(newKey());
29 });
30});

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

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

Refs