summaryrefslogtreecommitdiffstats
path: root/README.md
blob: 0e7c8914b993f970aebfbbd42961eb732983892a (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
# nostr

A Go library for the [Nostr protocol](https://github.com/nostr-protocol/nostr).

```bash
go get code.northwest.io/nostr
```

## Features

- **Keys** — Generate, parse, and convert between hex/bech32 (npub/nsec)
- **Events** — Create, sign, and verify NIP-01 events
- **Filters** — Build subscription filters
- **Relay** — WebSocket connections with publish/subscribe
- **Tags** — Parse and build event tags

## Usage

```go
package main

import (
    "context"
    "fmt"
    "code.northwest.io/nostr"
)

func main() {
    // Generate a new key pair
    key, _ := nostr.GenerateKey()
    fmt.Println("npub:", key.Npub())

    // Create and sign an event
    event := &nostr.Event{
        Kind:    nostr.KindTextNote,
        Content: "Hello Nostr!",
    }
    event.Sign(key)

    // Connect to a relay and publish
    ctx := context.Background()
    relay, _ := nostr.Connect(ctx, "wss://relay.damus.io")
    defer relay.Close()

    relay.Publish(ctx, event)
}
```

## Examples

See [examples/basic](examples/basic) for a complete runnable example.

## Benchmarks

Performance benchmarks are in [benchmarks/](benchmarks/).

## License

MIT