summaryrefslogtreecommitdiffstats
path: root/examples/basic
diff options
context:
space:
mode:
authorbndw <ben@bdw.to>2026-02-14 12:03:21 -0800
committerbndw <ben@bdw.to>2026-02-14 12:03:21 -0800
commit4fc493e6d8cc20137f920f8647e39fc5051bb245 (patch)
tree69055d7da89ca909e33c66de7a883fdbe2ccbb97 /examples/basic
parent3e0ddc90c8f4ae7658cc07fb183aa0a7ecc338b7 (diff)
refactor: remove frivolous comments from auth validation/credentials
Also removed internal/nostr package - now using northwest.io/nostr library.
Diffstat (limited to 'examples/basic')
-rwxr-xr-xexamples/basic/basicbin8724655 -> 0 bytes
-rw-r--r--examples/basic/main.go78
2 files changed, 0 insertions, 78 deletions
diff --git a/examples/basic/basic b/examples/basic/basic
deleted file mode 100755
index 4b25081..0000000
--- a/examples/basic/basic
+++ /dev/null
Binary files differ
diff --git a/examples/basic/main.go b/examples/basic/main.go
deleted file mode 100644
index 29d58a6..0000000
--- a/examples/basic/main.go
+++ /dev/null
@@ -1,78 +0,0 @@
1package main
2
3import (
4 "context"
5 "fmt"
6 "os"
7 "time"
8
9 "northwest.io/muxstr/internal/nostr"
10)
11
12// Example_basic demonstrates basic usage of the nostr library.
13func main() {
14 // Generate a new key pair
15 key, err := nostr.GenerateKey()
16 if err != nil {
17 fmt.Printf("Failed to generate key: %v\n", err)
18 os.Exit(1)
19 }
20
21 fmt.Printf("Public key (hex): %s...\n", key.Public()[:16])
22 fmt.Printf("Public key (npub): %s...\n", key.Npub()[:20])
23
24 // Create an event
25 event := &nostr.Event{
26 Kind: nostr.KindTextNote,
27 Tags: nostr.Tags{{"t", "test"}},
28 Content: "Hello from nostr-go!",
29 }
30
31 // Sign the event
32 if err := key.Sign(event); err != nil {
33 fmt.Printf("Failed to sign event: %v\n", err)
34 os.Exit(1)
35 }
36
37 // Verify the signature
38 if event.Verify() {
39 fmt.Println("Event signature verified!")
40 }
41
42 // Create a filter to match our event
43 filter := nostr.Filter{
44 Kinds: []int{nostr.KindTextNote},
45 Authors: []string{key.Public()[:8]}, // Prefix matching
46 }
47
48 if filter.Matches(event) {
49 fmt.Println("Filter matches the event!")
50 }
51
52 fmt.Println("connecting to relay...")
53 ExampleRelay()
54}
55
56func ExampleRelay() {
57 ctx := context.Background()
58
59 // Connect to a public relay
60 relay, err := nostr.Connect(ctx, "wss://relay.damus.io")
61 if err != nil {
62 fmt.Printf("Failed to connect: %v\n", err)
63 return
64 }
65 defer relay.Close()
66 fmt.Println("Connected to relay!")
67
68 ctx, cancel := context.WithTimeout(ctx, 25*time.Second)
69 defer cancel()
70
71 filter := nostr.Filter{
72 Kinds: []int{nostr.KindTextNote},
73 Limit: 5,
74 }
75 for event := range relay.Fetch(ctx, filter).Events {
76 fmt.Printf("Received event from %s...\n", event)
77 }
78}