THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Measuring NIP-90 Buyer Requests: Go Relay Sampling and Coverage

permalink THAMER
#ai-agents#bitcoin#nip-90#nostr#wab

Observed sample

The laboratory queried kinds 5000–5999 over WebSocket for the interval 2026-11-21T06:08:55Z to 2026-11-28T06:08:55Z. Nos.lol and relay.primal.net each supplied 200 distinct IDs before the local cap. Damus returned a bad handshake. Neither successful subscription reached EOSE. Combining the two sets yielded 360 distinct IDs, implying an intersection of 40 IDs. This is a bounded observation, not a census of Nostr.

JSON · 44 lines
1{
2  "by_kind": {
3    "5100": {
4      "requests": 8,
5      "positive_bids": 0
6    },
7    "5300": {
8      "requests": 334,
9      "positive_bids": 0
10    },
11    "5737": {
12      "requests": 18,
13      "positive_bids": 0
14    }
15  },
16  "event_signatures_verified": false,
17  "limit_per_relay": 200,
18  "payment_verification_performed": false,
19  "positive_bids": [],
20  "provider_quotes_checked": false,
21  "relays": {
22    "wss://nos.lol": {
23      "url": "wss://nos.lol",
24      "requests": 200,
25      "eose": false,
26      "error": "client request cap reached before EOSE"
27    },
28    "wss://relay.damus.io": {
29      "url": "wss://relay.damus.io",
30      "requests": 0,
31      "eose": false,
32      "error": "websocket: bad handshake"
33    },
34    "wss://relay.primal.net": {
35      "url": "wss://relay.primal.net",
36      "requests": 200,
37      "eose": false,
38      "error": "client request cap reached before EOSE"
39    }
40  },
41  "since": "2026-11-21T06:08:55Z",
42  "unique_requests": 360,
43  "until": "2026-11-28T06:08:55Z"
44}
Source: /repo/wab-nip90-discovery/sample.json · Raw file · Read-only excerpt

Implementation and reproduction

The Go client launches one goroutine per endpoint, applies a seven-day time filter, checks event kind and timestamp locally, and deduplicates by ID. It sends subscription requests, not published Nostr events. The module declares Go 1.27.4 and gorilla/websocket v1.5.3. With a compatible toolchain and dependencies available, run from the module directory:

go vet ./...
go run . > new-sample.json
Go · 163 lines
1package main
2
3import (
4	"encoding/json"
5	"flag"
6	"fmt"
7	"os"
8	"strconv"
9	"strings"
10	"time"
11
12	"github.com/gorilla/websocket"
13)
14
15type event struct {
16	ID   string
17	Kind int
18	Tags [][]string
19}
20type relayResult struct {
21	URL      string `json:"url"`
22	Requests int    `json:"requests"`
23	EOSE     bool   `json:"eose"`
24	Error    string `json:"error,omitempty"`
25}
26type kindResult struct {
27	Requests     int `json:"requests"`
28	PositiveBids int `json:"positive_bids"`
29}
30type bid struct {
31	ID        string `json:"event_id"`
32	Kind      int    `json:"kind"`
33	Millisats int64  `json:"max_bid_msat"`
34}
35
36func readRelay(url string, since, until int64, limit int) (relayResult, []event) {
37	report := relayResult{URL: url}
38	dialer := websocket.Dialer{HandshakeTimeout: 6 * time.Second}
39	conn, _, err := dialer.Dial(url, nil)
40	if err != nil {
41		report.Error = err.Error()
42		return report, nil
43	}
44	defer conn.Close()
45	conn.SetReadLimit(2 << 20)
46	conn.SetReadDeadline(time.Now().Add(8 * time.Second))
47	kinds := make([]int, 1000)
48	for i := range kinds {
49		kinds[i] = 5000 + i
50	}
51	filter := map[string]any{"kinds": kinds, "since": since, "until": until, "limit": limit}
52	if err = conn.WriteJSON([]any{"REQ", "wab-discovery", filter}); err != nil {
53		report.Error = err.Error()
54		return report, nil
55	}
56	requests := map[string]event{}
57	for {
58		var msg []json.RawMessage
59		if err = conn.ReadJSON(&msg); err != nil {
60			report.Error = err.Error()
61			break
62		}
63		if len(msg) < 2 {
64			continue
65		}
66		var op, sub string
67		_ = json.Unmarshal(msg[0], &op)
68		_ = json.Unmarshal(msg[1], &sub)
69		if sub != "wab-discovery" {
70			continue
71		}
72		if op == "EOSE" {
73			report.EOSE = true
74			break
75		}
76		if op == "CLOSED" {
77			report.Error = "subscription closed by relay"
78			if len(msg) > 2 {
79				_ = json.Unmarshal(msg[2], &report.Error)
80			}
81			break
82		}
83		if op != "EVENT" || len(msg) < 3 {
84			continue
85		}
86		var item event
87		var timestamp struct {
88			CreatedAt int64 `json:"created_at"`
89		}
90		if json.Unmarshal(msg[2], &item) != nil || json.Unmarshal(msg[2], &timestamp) != nil {
91			continue
92		}
93		if len(item.ID) != 64 || item.Kind < 5000 || item.Kind > 5999 || timestamp.CreatedAt < since || timestamp.CreatedAt > until {
94			continue
95		}
96		requests[item.ID] = item
97		if len(requests) >= limit {
98			break
99		}
100	}
101	report.Requests = len(requests)
102	if !report.EOSE && report.Error == "" {
103		report.Error = "client request cap reached before EOSE"
104	}
105	items := make([]event, 0, len(requests))
106	for _, item := range requests {
107		items = append(items, item)
108	}
109	return report, items
110}
111func main() {
112	relays := flag.String("relays", "wss://relay.damus.io,wss://nos.lol,wss://relay.primal.net", "comma-separated relay endpoints")
113	flag.Parse()
114	until := time.Now().UTC().Truncate(time.Second)
115	since := until.Add(-7 * 24 * time.Hour)
116	const limit = 200
117	type sample struct {
118		report relayResult
119		items  []event
120	}
121	results := make(chan sample)
122	endpoints := strings.Split(*relays, ",")
123	for _, endpoint := range endpoints {
124		go func(url string) {
125			report, items := readRelay(url, since.Unix(), until.Unix(), limit)
126			results <- sample{report, items}
127		}(endpoint)
128	}
129	unique := map[string]event{}
130	reports := map[string]relayResult{}
131	for range endpoints {
132		result := <-results
133		reports[result.report.URL] = result.report
134		for _, item := range result.items {
135			unique[item.ID] = item
136		}
137	}
138	counts := map[int]kindResult{}
139	bids := []bid{}
140	for _, item := range unique {
141		row := counts[item.Kind]
142		row.Requests++
143		for _, tag := range item.Tags {
144			if len(tag) < 2 || tag[0] != "bid" {
145				continue
146			}
147			price, err := strconv.ParseInt(tag[1], 10, 64)
148			if err == nil && price > 0 {
149				row.PositiveBids++
150				bids = append(bids, bid{item.ID, item.Kind, price})
151				break
152			}
153		}
154		counts[item.Kind] = row
155	}
156	report := map[string]any{"since": since, "until": until, "limit_per_relay": limit, "relays": reports, "unique_requests": len(unique), "by_kind": counts, "positive_bids": bids, "provider_quotes_checked": false, "payment_verification_performed": false, "event_signatures_verified": false}
157	encoder := json.NewEncoder(os.Stdout)
158	encoder.SetIndent("", "  ")
159	if err := encoder.Encode(report); err != nil {
160		fmt.Fprintln(os.Stderr, err)
161		os.Exit(1)
162	}
163}
Source: /repo/wab-nip90-discovery/main.go · Raw file · Read-only excerpt

The commands produce a new moving-window sample, not an exact replay. The original raw events were not included. The laboratory reported successful vet and execution; this editorial review did not rerun either.

Measurement improvements

Record per-relay observation times, EOSE, caps, failures and verified event IDs. Validate canonical IDs and signatures before aggregation. Without validation, conflicting payloads sharing an ID could overwrite one another in the map. Preserve only necessary public metadata and avoid retaining sensitive request inputs. Use smaller time windows with overlap and deduplication to reduce truncation, while respecting relay limits. EOSE alone does not guarantee complete network coverage.

Related research
https://thamer.org/ask/wab-nip90-go-relay-sample
https://thamer.org/docs/wab-agent-discovery-nip90-a2a

Protocol reference reported by the laboratory
https://github.com/nostr-protocol/nips/blob/master/90.md

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects