diff options
| -rw-r--r-- | README.md | 41 |
1 files changed, 27 insertions, 14 deletions
| @@ -1,18 +1,35 @@ | |||
| 1 | # nostr | 1 | # nostr |
| 2 | 2 | ||
| 3 | A Go library for the [Nostr protocol](https://github.com/nostr-protocol/nostr). | 3 | A minimal Go library for the [Nostr protocol](https://github.com/nostr-protocol/nostr). |
| 4 | 4 | ||
| 5 | ```bash | 5 | ```bash |
| 6 | go get code.northwest.io/nostr | 6 | go get code.northwest.io/nostr |
| 7 | ``` | 7 | ``` |
| 8 | 8 | ||
| 9 | ## Features | 9 | ## Why This Library? |
| 10 | 10 | ||
| 11 | - **Keys** — Generate, parse, and convert between hex/bech32 (npub/nsec) | 11 | **1 dependency.** That's it. |
| 12 | - **Events** — Create, sign, and verify NIP-01 events | 12 | |
| 13 | - **Filters** — Build subscription filters | 13 | Other Nostr libraries pull in 30+ dependencies. This one has exactly one direct dependency: `btcec` for Schnorr signatures (required by the protocol). |
| 14 | - **Relay** — WebSocket connections with publish/subscribe | 14 | |
| 15 | ``` | ||
| 16 | require github.com/btcsuite/btcd/btcec/v2 v2.3.4 | ||
| 17 | ``` | ||
| 18 | |||
| 19 | No WebSocket libraries, no logging frameworks, no kitchen sink. Just the core protocol. | ||
| 20 | |||
| 21 | ## What's Included | ||
| 22 | |||
| 23 | - **Keys** — Generate, parse, sign, verify (hex and bech32/npub/nsec) | ||
| 24 | - **Events** — Create, serialize, sign NIP-01 events | ||
| 25 | - **Filters** — Build and match subscription filters | ||
| 26 | - **Relay** — WebSocket pub/sub (stdlib `net/http` only) | ||
| 15 | - **Tags** — Parse and build event tags | 27 | - **Tags** — Parse and build event tags |
| 28 | - **Envelopes** — Protocol message parsing | ||
| 29 | |||
| 30 | ## What's Not Included | ||
| 31 | |||
| 32 | This is a minimal core library. It implements NIP-01 and the basics. It doesn't implement every NIP, handle connection pooling, or manage relay discovery. Build that yourself, or don't. | ||
| 16 | 33 | ||
| 17 | ## Usage | 34 | ## Usage |
| 18 | 35 | ||
| @@ -26,7 +43,7 @@ import ( | |||
| 26 | ) | 43 | ) |
| 27 | 44 | ||
| 28 | func main() { | 45 | func main() { |
| 29 | // Generate a new key pair | 46 | // Generate a key pair |
| 30 | key, _ := nostr.GenerateKey() | 47 | key, _ := nostr.GenerateKey() |
| 31 | fmt.Println("npub:", key.Npub()) | 48 | fmt.Println("npub:", key.Npub()) |
| 32 | 49 | ||
| @@ -37,22 +54,18 @@ func main() { | |||
| 37 | } | 54 | } |
| 38 | event.Sign(key) | 55 | event.Sign(key) |
| 39 | 56 | ||
| 40 | // Connect to a relay and publish | 57 | // Connect and publish |
| 41 | ctx := context.Background() | 58 | ctx := context.Background() |
| 42 | relay, _ := nostr.Connect(ctx, "wss://relay.damus.io") | 59 | relay, _ := nostr.Connect(ctx, "wss://relay.damus.io") |
| 43 | defer relay.Close() | 60 | defer relay.Close() |
| 44 | 61 | ||
| 45 | relay.Publish(ctx, event) | 62 | relay.Publish(ctx, event) |
| 46 | } | 63 | } |
| 47 | ``` | 64 | ``` |
| 48 | 65 | ||
| 49 | ## Examples | 66 | ## Examples |
| 50 | 67 | ||
| 51 | See [examples/basic](examples/basic) for a complete runnable example. | 68 | See [examples/basic](examples/basic) for a runnable example. |
| 52 | |||
| 53 | ## Benchmarks | ||
| 54 | |||
| 55 | Performance benchmarks are in [benchmarks/](benchmarks/). | ||
| 56 | 69 | ||
| 57 | ## License | 70 | ## License |
| 58 | 71 | ||
