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 / object / nip05.test.ts
nip05.test.ts 2.8K
1// NIP-05: names under the relay's domain for its members.2import { SELF } from "cloudflare:test";3import { describe, it, expect } from "vitest";4import { generateSecretKey, getPublicKey } from "nostr-tools/pure";5import { ev, rpc } from "../helpers/relay.ts";6import { WS } from "../helpers/ws.ts";78describe("NIP-05", () => {9 it("serves members' names for the relay's own host, claimed via kind 0 or assigned by the owner", async () => {10 const host = "names.bind.ws";11 const owner = generateSecretKey();12 const alice = generateSecretKey();13 const stranger = generateSecretKey();14 await rpc(host, owner, "claim");15 await rpc(host, owner, "allowpubkey", getPublicKey(alice));16 const c = await WS.connect(host);17 await c.ok(ev(alice, 0, JSON.stringify({ name: "alice", nip05: "Alice@names.bind.ws" })));18 await c.ok(ev(stranger, 0, JSON.stringify({ name: "mallory", nip05: "alice@names.bind.ws" }))); // not a member: ignored19 await c.ok(ev(owner, 0, JSON.stringify({ nip05: "owner@elsewhere.example" }))); // other domain: ignored20 let doc: any = await (await SELF.fetch(`http://${host}/.well-known/nostr.json?name=alice`)).json();21 expect(doc.names).toEqual({ alice: getPublicKey(alice) });22 expect(doc.relays[getPublicKey(alice)]).toEqual(["wss://" + host]);23 doc = await (await SELF.fetch(`http://${host}/.well-known/nostr.json?name=nobody`)).json();24 expect(doc.names).toEqual({});25 // Owner assigns and removes names; a taken name can't be claimed by another member.26 expect((await rpc(host, owner, "setmember", getPublicKey(owner), { name: "_" })).result.name).toBe("_");27 expect((await rpc(host, owner, "setmember", getPublicKey(owner), { name: "bad name!" })).status).toBe(400);28 doc = await (await SELF.fetch(`http://${host}/.well-known/nostr.json`)).json();29 expect(Object.keys(doc.names).sort()).toEqual(["_", "alice"]);30 // Assigning a taken name to someone else moves it; clearing frees it.31 expect((await rpc(host, owner, "setmember", getPublicKey(stranger), { name: "alice" })).result.name).toBe("alice");32 expect((await rpc(host, owner, "listmembers")).result.members.find((m: any) => m.pubkey === getPublicKey(alice)).name).toBeNull();33 expect((await rpc(host, owner, "setmember", getPublicKey(stranger), { name: "" })).result.name).toBeNull();34 // The public directory lists people with their names; the owner can hide it.35 let people: any = await (await SELF.fetch(`http://${host}/people`)).json();36 expect(people.people.map((m: any) => m.role)).toEqual(["owner", "member", "member"]);37 expect(people.people[0].name).toBe("_");38 await rpc(host, owner, "setpolicy", { directoryPublic: false });39 people = await (await SELF.fetch(`http://${host}/people`)).json();40 expect(people.people).toEqual([]);41 });42});