Categorygithub.com/stackerstan/go-nostr
modulepackage
0.0.0
Repository: https://github.com/stackerstan/go-nostr.git
Documentation: pkg.go.dev

# README

go-nostr

A set of useful things for Nostr Protocol implementations.

GoDoc

Subscribing to a set of relays

pool := nostr.NewRelayPool()

pool.Add("wss://relay.nostr.com/",  nostr.SimplePolicy{Read: true, Write: true})
pool.Add("wss://nostrrelay.example.com/",  nostr.SimplePolicy{Read: true, Write: true})

for notice := range pool.Notices {
	log.Printf("%s has sent a notice: '%s'\n", notice.Relay, notice.Message)
}

Listening for events

subId, events, unsubscribe := pool.Sub(nostr.Filters{
	{
		Authors: []string{"0ded86bf80c76847320b16f22b7451c08169434837a51ad5fe3b178af6c35f5d"},
		Kinds:   []int{nostr.KindTextNote}, // or {1}
	},
})

go func() {
	for event := range nostr.Unique(events) {
		log.Print(event)
	}
}()

time.Sleep(5 * time.Second)
unsubscribe()

Publishing an event

secretKey := "3f06a81e0a0c2ad34ee9df2a30d87a810da9e3c3881f780755ace5e5e64d30a7"

pool.SecretKey = &secretKey

event, statuses, _ := pool.PublishEvent(&nostr.Event{
	CreatedAt: time.Now(),
	Kind:      nostr.KindTextNote,
	Tags:      make(nostr.Tags, 0),
	Content:   "hello",
})

log.Print(event.PubKey)
log.Print(event.ID)
log.Print(event.Sig)

for status := range statuses {
	switch status.Status {
	case nostr.PublishStatusSent:
		fmt.Printf("Sent event %s to '%s'.\n", event.ID, status.Relay)
	case nostr.PublishStatusFailed:
		fmt.Printf("Failed to send event %s to '%s'.\n", event.ID, status.Relay)
	case nostr.PublishStatusSucceeded:
		fmt.Printf("Event seen %s on '%s'.\n", event.ID, status.Relay)
	}
}

Generating a key

sk, _ := nostr.GenerateKey()

fmt.Println("sk:", sk)
fmt.Println("pk:", nostr.GetPublicKey(sk))

Example Program

go run example/example.go

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
New creates a new RelayPool with no relays in it.
No description provided by the author
No description provided by the author
RelayConnect forwards calls to RelayConnectContext with a background context.
RelayConnectContext creates a new relay client and connects to a canonical URL using Relay.ConnectContext, passing ctx as is.
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author