aboutsummaryrefslogtreecommitdiffstats

nostr

A minimal Go library for the Nostr protocol.

go get code.northwest.io/nostr

Why This Library?

1 dependency. That's it.

Other Nostr libraries pull in 30+ dependencies. This one has exactly one direct dependency: btcec for Schnorr signatures (required by the protocol).

require github.com/btcsuite/btcd/btcec/v2 v2.3.4

No WebSocket libraries, no logging frameworks, no kitchen sink. Just the core protocol.

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 net/http only)
  • Tags — Parse and build event tags
  • Envelopes — Protocol message parsing

What's Not Included

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.

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