blob: a96ebe8693ba4381c4126b07635c5492a290e417 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# NIP-42 Test Client
A test client for testing NIP-42 WebSocket authentication and rate limiting.
## Features
- ✅ **Persistent keypair**: Generates and saves a keypair to `testclient.key`
- ✅ **NIP-42 auth**: Automatically handles AUTH challenges (via library)
- ✅ **Publish events**: Posts a kind 1 note to test write access
- ✅ **Query events**: Subscribes to recent kind 1 notes to test read access
- ✅ **Rate limit testing**: Can be run repeatedly to test rate limits
## Usage
```bash
# Build
go build -o testclient
# Run against local relay
./testclient
# Run against remote relay
./testclient -relay wss://muxstr.x.bdw.to
# Run multiple times to test rate limiting
for i in {1..10}; do ./testclient; done
```
## Adding to Relay Allowlist
After first run, the client generates a keypair in `testclient.key`.
To get the pubkey for your allowlist:
```bash
# Get hex pubkey
cat testclient.key | xxd -r -p | sha256sum | cut -d' ' -f1
# Or run the client and copy from the log output
./testclient
# Look for: "Using pubkey: <hex>"
```
Add this pubkey to your `config.yaml`:
```yaml
auth:
write:
enabled: true
allowed_npubs:
- npub1yourpubkeyhere... # Convert hex to npub or use hex
```
## Testing Scenarios
### Test NIP-42 Auth
1. Enable write auth in config
2. Add testclient pubkey to allowlist
3. Run client - should succeed
4. Remove pubkey from allowlist
5. Run client - should receive AUTH challenge and fail
### Test Rate Limiting
```bash
# Spam events to trigger rate limit
while true; do ./testclient; sleep 0.1; done
```
Expected: After N requests/sec, receives "rate limit exceeded"
## Dependencies
- `fiatjaf.com/nostr` - Official Go Nostr library with NIP-42 support
|