nostr
A zero-dependency Go library for the Nostr protocol.
go get code.northwest.io/nostr
Why This Library?
You probably shouldn't use it.
This library rolls its own secp256k1 cryptography in pure Go. No CGO, no external dependencies, no nothing. I built it to see if it was possible to implement Nostr with truly zero dependencies. It is. But that doesn't mean it's a good idea.
What you get: - Zero external dependencies - Fully auditable pure-Go crypto - Passes all BIP-340 test vectors - Works fine for normal Nostr usage
What you're giving up: - Constant-time operations (timing attacks are theoretically possible) - Performance (~10x slower than btcec) - Battle-tested crypto code
If you're building something serious, use a library backed by btcec. If you're hacking on a side project or just want to read the code, welcome.
What's Included
- Keys — Generate, parse, sign, verify (hex and bech32/npub/nsec)
- Events — Create, serialize, sign NIP-01 events
- Filters — Build and match subscription filters
- Relay — WebSocket pub/sub (stdlib only)
- Tags — Parse and build event tags
- Envelopes — Protocol message parsing
Usage
package main
import (
"context"
"fmt"
"code.northwest.io/nostr"
)
func main() {
// Generate a key pair
key, _ := nostr.GenerateKey()
fmt.Println("npub:", key.Npub())
// Create and sign an event
event := &nostr.Event{
Kind: nostr.KindTextNote,
Content: "Hello Nostr!",
}
key.Sign(event)
// Connect and publish
ctx := context.Background()
relay, _ := nostr.Connect(ctx, "wss://relay.damus.io")
defer relay.Close()
relay.Publish(ctx, event)
}
Examples
See examples/basic for a runnable example.
License
MIT
