Documentation
¶
Overview ¶
client/core/eventSerializer.go
Index ¶
- func ComputeEventID(event *nostr.Event) (string, error)
- func ContactListFilter(pubkey string) nostr.Filter
- func CreateNostrMessage(messageType string, args ...interface{}) ([]byte, error)
- func DerivePublicKey(privateKeyHex string) (string, error)
- func DeserializeEvent(data []byte) (*nostr.Event, error)
- func EventFromJSON(data []byte) (*nostr.Event, error)
- func EventToJSON(event *nostr.Event) ([]byte, error)
- func GeneratePrivateKey() (string, error)
- func GetPublicKeyFromExtension() (string, error)
- func NotesFilter(authors []string, limit int) nostr.Filter
- func ParseNostrMessage(data []byte) (messageType string, args []interface{}, err error)
- func ProfileFilter(pubkey string) nostr.Filter
- func ReactionsFilter(eventID string) nostr.Filter
- func RecentNotesFilter(limit int, maxAge time.Duration) nostr.Filter
- func RelayListFilter(pubkey string) nostr.Filter
- func SerializeEvent(evt nostr.Event) string
- func SerializeEventArray(events []*nostr.Event) ([]byte, error)
- func SignEventWithExtension(event *nostr.Event) error
- func TimeRangeFilter(since, until time.Time, kinds []int) nostr.Filter
- func ValidateEventStructure(event *nostr.Event) error
- func VerifyEventSignature(event *nostr.Event) bool
- type BroadcastResult
- func BroadcastEvent(event *nostr.Event, relays []string, pool *RelayPool) []BroadcastResult
- func BroadcastToUserRelays(event *nostr.Event, pubkey string, client *Client) []BroadcastResult
- func BroadcastWithRetry(event *nostr.Event, relays []string, pool *RelayPool, maxRetries int) []BroadcastResult
- func PublishEvent(client *Client, signer *EventSigner, eventBuilder *EventBuilder, ...) (*nostr.Event, []BroadcastResult, error)
- func PublishEventWithRetry(client *Client, signer *EventSigner, eventBuilder *EventBuilder, ...) (*nostr.Event, []BroadcastResult, error)
- type BroadcastSummary
- type Client
- func (c *Client) Close() error
- func (c *Client) ConnectToRelays(urls []string) error
- func (c *Client) ConnectToRelaysWithRetry(urls []string, maxRetries int) error
- func (c *Client) DisconnectFromRelay(relayURL string) error
- func (c *Client) DisconnectFromRelays(relayURLs []string) error
- func (c *Client) GetConnectedRelays() []string
- func (c *Client) GetRelayStatus() map[string]string
- func (c *Client) GetUserProfile(pubkey string, relayHints []string) (*nostr.Event, error)
- func (c *Client) GetUserRelays(pubkey string) (*Mailboxes, error)
- func (c *Client) PublishEvent(event *nostr.Event, targetRelays []string) ([]BroadcastResult, error)
- func (c *Client) PublishEventWithRetry(event *nostr.Event, targetRelays []string, maxRetries int) ([]BroadcastResult, error)
- func (c *Client) ReplaceRelayConnections(newRelays []RelayConfig) error
- func (c *Client) Subscribe(filters []nostr.Filter, relayHints []string) (*Subscription, error)
- func (c *Client) SwitchToDefaultRelays() error
- func (c *Client) SwitchToUserRelays(userRelays []RelayConfig) error
- type ClientError
- type Config
- type ConnectionStatus
- type EventBuilder
- func NewContactList() *EventBuilder
- func NewDeletion(eventIDs []string, reason string) *EventBuilder
- func NewEventBuilder(kind int) *EventBuilder
- func NewProfile() *EventBuilder
- func NewReaction(eventID string, content string) *EventBuilder
- func NewRelayList() *EventBuilder
- func NewRepost(eventID string, relayHint string) *EventBuilder
- func NewTextNote(content string) *EventBuilder
- func (eb *EventBuilder) ATag(kind int, pubkey string, dTag string, relayHint ...string) *EventBuilder
- func (eb *EventBuilder) Build() *nostr.Event
- func (eb *EventBuilder) Content(content string) *EventBuilder
- func (eb *EventBuilder) CreatedAt(t time.Time) *EventBuilder
- func (eb *EventBuilder) DTag(identifier string) *EventBuilder
- func (eb *EventBuilder) ETag(eventID string, relayHint, marker string) *EventBuilder
- func (eb *EventBuilder) PTag(pubkey string, relayHint ...string) *EventBuilder
- func (eb *EventBuilder) RTag(relayURL string, marker string) *EventBuilder
- func (eb *EventBuilder) TTag(hashtag string) *EventBuilder
- func (eb *EventBuilder) Tag(name string, values ...string) *EventBuilder
- type EventSigner
- type FilterBuilder
- func (fb *FilterBuilder) Authors(pubkeys ...string) *FilterBuilder
- func (fb *FilterBuilder) Build() nostr.Filter
- func (fb *FilterBuilder) IDs(ids ...string) *FilterBuilder
- func (fb *FilterBuilder) Kinds(kinds ...int) *FilterBuilder
- func (fb *FilterBuilder) Limit(limit int) *FilterBuilder
- func (fb *FilterBuilder) Since(timestamp time.Time) *FilterBuilder
- func (fb *FilterBuilder) Tag(name string, values ...string) *FilterBuilder
- func (fb *FilterBuilder) Until(timestamp time.Time) *FilterBuilder
- type Mailboxes
- type MessageRouter
- type RelayConfig
- type RelayConnection
- type RelayPool
- func (rp *RelayPool) BroadcastMessage(message interface{}, urls []string) error
- func (rp *RelayPool) Close() error
- func (rp *RelayPool) CloseConnection(url string) error
- func (rp *RelayPool) Connect(url string) error
- func (rp *RelayPool) GetConnectedRelays() []string
- func (rp *RelayPool) GetConnection(url string) (*RelayConnection, error)
- func (rp *RelayPool) RegisterSubscription(subID string, sub *Subscription)
- func (rp *RelayPool) SendMessage(url string, message interface{}) error
- func (rp *RelayPool) UnregisterSubscription(subID string)
- type Subscription
- func (s *Subscription) AddRelay(url string) error
- func (s *Subscription) Close() error
- func (s *Subscription) GetFilters() []nostr.Filter
- func (s *Subscription) GetRelayCount() int
- func (s *Subscription) IsActive() bool
- func (s *Subscription) RemoveRelay(url string) error
- func (s *Subscription) Start() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeEventID ¶
ComputeEventID computes the event ID according to NIP-01
func ContactListFilter ¶
ContactListFilter creates a filter for contact lists (kind 3)
func CreateNostrMessage ¶
CreateNostrMessage creates a properly formatted Nostr protocol message
func DerivePublicKey ¶
DerivePublicKey derives a public key from a private key hex
func DeserializeEvent ¶
DeserializeEvent deserializes JSON bytes to an event
func EventFromJSON ¶
EventFromJSON parses an event from JSON
func EventToJSON ¶
EventToJSON converts an event to pretty-printed JSON
func GeneratePrivateKey ¶
GeneratePrivateKey generates a new random private key
func GetPublicKeyFromExtension ¶
GetPublicKeyFromExtension attempts to get public key from browser extension
func NotesFilter ¶
NotesFilter creates a filter for notes from specific authors
func ParseNostrMessage ¶
ParseNostrMessage parses a Nostr protocol message
func ProfileFilter ¶
ProfileFilter creates a filter for user profiles (kind 0)
func ReactionsFilter ¶
ReactionsFilter creates a filter for reactions to a specific event
func RecentNotesFilter ¶
RecentNotesFilter creates a filter for recent notes
func RelayListFilter ¶
RelayListFilter creates a filter for relay lists (kind 10002)
func SerializeEvent ¶
SerializeEvent manually constructs the JSON string for event serialization according to NIP-01
func SerializeEventArray ¶
SerializeEventArray serializes an event for inclusion in a Nostr message array
func SignEventWithExtension ¶
SignEventWithExtension attempts to sign an event using browser extension (NIP-07)
func TimeRangeFilter ¶
TimeRangeFilter creates a filter for events within a specific time range
func ValidateEventStructure ¶
ValidateEventStructure validates the basic structure of an event
func VerifyEventSignature ¶
VerifyEventSignature verifies an event's signature
Types ¶
type BroadcastResult ¶
type BroadcastResult struct { RelayURL string Success bool Error error Message string Duration time.Duration }
BroadcastResult represents the result of broadcasting to a single relay
func BroadcastEvent ¶
func BroadcastEvent(event *nostr.Event, relays []string, pool *RelayPool) []BroadcastResult
BroadcastEvent sends an event to multiple relays using the relay pool
func BroadcastToUserRelays ¶
func BroadcastToUserRelays(event *nostr.Event, pubkey string, client *Client) []BroadcastResult
BroadcastToUserRelays broadcasts an event to a user's preferred relays
func BroadcastWithRetry ¶
func BroadcastWithRetry(event *nostr.Event, relays []string, pool *RelayPool, maxRetries int) []BroadcastResult
BroadcastWithRetry broadcasts an event with retry logic
func PublishEvent ¶
func PublishEvent(client *Client, signer *EventSigner, eventBuilder *EventBuilder, targetRelays []string) (*nostr.Event, []BroadcastResult, error)
PublishEvent is a high-level function to build, sign, and broadcast an event
func PublishEventWithRetry ¶
func PublishEventWithRetry(client *Client, signer *EventSigner, eventBuilder *EventBuilder, targetRelays []string, maxRetries int) (*nostr.Event, []BroadcastResult, error)
PublishEventWithRetry publishes an event with retry logic
type BroadcastSummary ¶
type BroadcastSummary struct { TotalRelays int Successful int Failed int SuccessRate float64 AverageDuration time.Duration Errors []string }
BroadcastSummary provides a summary of broadcast results
func SummarizeBroadcast ¶
func SummarizeBroadcast(results []BroadcastResult) BroadcastSummary
SummarizeBroadcast creates a summary of broadcast results
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents the main Nostr client with connection pooling
func (*Client) ConnectToRelays ¶
ConnectToRelays establishes connections to multiple relay URLs
func (*Client) ConnectToRelaysWithRetry ¶
ConnectToRelaysWithRetry establishes connections with retry logic
func (*Client) DisconnectFromRelay ¶ added in v0.4.12
DisconnectFromRelay closes a specific relay connection
func (*Client) DisconnectFromRelays ¶ added in v0.4.12
DisconnectFromRelays closes connections to multiple relays
func (*Client) GetConnectedRelays ¶
GetConnectedRelays returns a list of currently connected relay URLs
func (*Client) GetRelayStatus ¶
GetRelayStatus returns detailed status of all relay connections
func (*Client) GetUserProfile ¶
func (*Client) GetUserRelays ¶
GetUserRelays retrieves user relay list (kind 10002)
func (*Client) PublishEvent ¶
PublishEvent publishes an event to specified relays
func (*Client) PublishEventWithRetry ¶
func (c *Client) PublishEventWithRetry(event *nostr.Event, targetRelays []string, maxRetries int) ([]BroadcastResult, error)
PublishEventWithRetry publishes an event with retry logic
func (*Client) ReplaceRelayConnections ¶ added in v0.4.12
func (c *Client) ReplaceRelayConnections(newRelays []RelayConfig) error
ReplaceRelayConnections replaces current relay connections with a new set
func (*Client) SwitchToDefaultRelays ¶ added in v0.4.12
SwitchToDefaultRelays switches the client back to default app relays
func (*Client) SwitchToUserRelays ¶ added in v0.4.12
func (c *Client) SwitchToUserRelays(userRelays []RelayConfig) error
SwitchToUserRelays switches the client to use user's cached relays
type ClientError ¶
type ClientError struct {
Message string
}
ClientError represents client-specific errors
func (*ClientError) Error ¶
func (e *ClientError) Error() string
type Config ¶
type Config struct { DefaultRelays []string `json:"default_relays"` ConnectionTimeout time.Duration `json:"connection_timeout"` ReadTimeout time.Duration `json:"read_timeout"` WriteTimeout time.Duration `json:"write_timeout"` MaxConnections int `json:"max_connections"` RetryAttempts int `json:"retry_attempts"` RetryDelay time.Duration `json:"retry_delay"` KeepAlive bool `json:"keep_alive"` UserAgent string `json:"user_agent"` }
Config holds client-specific configuration
func ConfigFromServerConfig ¶ added in v0.4.11
func ConfigFromServerConfig(serverCfg *cfgType.ServerConfig) *Config
ConfigFromServerConfig creates a client config from server configuration
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a sensible default configuration
type ConnectionStatus ¶
type ConnectionStatus int
ConnectionStatus represents the state of a relay connection
const ( StatusDisconnected ConnectionStatus = iota StatusConnecting StatusConnected StatusError )
type EventBuilder ¶
type EventBuilder struct {
// contains filtered or unexported fields
}
EventBuilder provides a fluent interface for building Nostr events
func NewContactList ¶
func NewContactList() *EventBuilder
NewContactList creates a builder for a contact list (kind 3)
func NewDeletion ¶
func NewDeletion(eventIDs []string, reason string) *EventBuilder
NewDeletion creates a builder for a deletion event (kind 5)
func NewEventBuilder ¶
func NewEventBuilder(kind int) *EventBuilder
NewEventBuilder creates a new event builder with the specified kind
func NewProfile ¶
func NewProfile() *EventBuilder
NewProfile creates a builder for a profile event (kind 0)
func NewReaction ¶
func NewReaction(eventID string, content string) *EventBuilder
NewReaction creates a builder for a reaction (kind 7)
func NewRelayList ¶
func NewRelayList() *EventBuilder
NewRelayList creates a builder for a relay list (kind 10002)
func NewRepost ¶
func NewRepost(eventID string, relayHint string) *EventBuilder
NewRepost creates a builder for a repost (kind 6)
func NewTextNote ¶
func NewTextNote(content string) *EventBuilder
NewTextNote creates a builder for a text note (kind 1)
func (*EventBuilder) ATag ¶
func (eb *EventBuilder) ATag(kind int, pubkey string, dTag string, relayHint ...string) *EventBuilder
ATag adds an 'a' tag (address reference) to the event
func (*EventBuilder) Build ¶
func (eb *EventBuilder) Build() *nostr.Event
Build constructs the final Event struct (without signing)
func (*EventBuilder) Content ¶
func (eb *EventBuilder) Content(content string) *EventBuilder
Content sets the content of the event
func (*EventBuilder) CreatedAt ¶
func (eb *EventBuilder) CreatedAt(t time.Time) *EventBuilder
CreatedAt sets the created_at timestamp for the event
func (*EventBuilder) DTag ¶
func (eb *EventBuilder) DTag(identifier string) *EventBuilder
DTag adds a 'd' tag (identifier) to the event
func (*EventBuilder) ETag ¶
func (eb *EventBuilder) ETag(eventID string, relayHint, marker string) *EventBuilder
ETag adds an 'e' tag (event reference) to the event
func (*EventBuilder) PTag ¶
func (eb *EventBuilder) PTag(pubkey string, relayHint ...string) *EventBuilder
PTag adds a 'p' tag (pubkey reference) to the event
func (*EventBuilder) RTag ¶
func (eb *EventBuilder) RTag(relayURL string, marker string) *EventBuilder
RTag adds an 'r' tag (relay reference) to the event
func (*EventBuilder) TTag ¶
func (eb *EventBuilder) TTag(hashtag string) *EventBuilder
TTag adds a 't' tag (hashtag) to the event
func (*EventBuilder) Tag ¶
func (eb *EventBuilder) Tag(name string, values ...string) *EventBuilder
Tag adds a generic tag to the event
type EventSigner ¶
type EventSigner struct {
// contains filtered or unexported fields
}
EventSigner handles event signing with private keys
func NewEventSigner ¶
func NewEventSigner(privateKeyHex string) (*EventSigner, error)
NewEventSigner creates a new event signer from a hex private key
func NewEventSignerFromRandom ¶
func NewEventSignerFromRandom() (*EventSigner, error)
NewEventSignerFromRandom creates a new event signer with a random private key
func (*EventSigner) GetPrivateKeyHex ¶
func (es *EventSigner) GetPrivateKeyHex() string
GetPrivateKeyHex returns the private key in hex format (use carefully!)
func (*EventSigner) GetPublicKey ¶
func (es *EventSigner) GetPublicKey() string
GetPublicKey returns the public key in hex format
type FilterBuilder ¶
type FilterBuilder struct {
// contains filtered or unexported fields
}
FilterBuilder provides a fluent interface for building Nostr filters
func NewFilterBuilder ¶
func NewFilterBuilder() *FilterBuilder
NewFilterBuilder creates a new filter builder
func (*FilterBuilder) Authors ¶
func (fb *FilterBuilder) Authors(pubkeys ...string) *FilterBuilder
Authors sets the authors filter
func (*FilterBuilder) Build ¶
func (fb *FilterBuilder) Build() nostr.Filter
Build returns the constructed filter
func (*FilterBuilder) IDs ¶
func (fb *FilterBuilder) IDs(ids ...string) *FilterBuilder
IDs sets the event IDs filter
func (*FilterBuilder) Kinds ¶
func (fb *FilterBuilder) Kinds(kinds ...int) *FilterBuilder
Kinds sets the kinds filter
func (*FilterBuilder) Limit ¶
func (fb *FilterBuilder) Limit(limit int) *FilterBuilder
Limit sets the limit filter
func (*FilterBuilder) Since ¶
func (fb *FilterBuilder) Since(timestamp time.Time) *FilterBuilder
Since sets the since timestamp filter
func (*FilterBuilder) Tag ¶
func (fb *FilterBuilder) Tag(name string, values ...string) *FilterBuilder
Tag adds a tag filter
func (*FilterBuilder) Until ¶
func (fb *FilterBuilder) Until(timestamp time.Time) *FilterBuilder
Until sets the until timestamp filter
type Mailboxes ¶
type Mailboxes struct { Read []string `json:"read"` Write []string `json:"write"` Both []string `json:"both"` }
Mailboxes represents a user's relay preferences from NIP-65
func (Mailboxes) ToStringSlice ¶
ToStringSlice combines Read, Write, and Both into a single []string
type MessageRouter ¶
type MessageRouter struct {
// contains filtered or unexported fields
}
MessageRouter handles routing messages to subscriptions
func NewMessageRouter ¶
func NewMessageRouter() *MessageRouter
NewMessageRouter creates a new message router
func (*MessageRouter) RegisterSubscription ¶
func (mr *MessageRouter) RegisterSubscription(subID string, sub *Subscription)
RegisterSubscription registers a subscription for message routing
func (*MessageRouter) RouteMessage ¶
func (mr *MessageRouter) RouteMessage(subID string, messageType string, data interface{})
RouteMessage routes a message to the appropriate subscription
func (*MessageRouter) UnregisterSubscription ¶
func (mr *MessageRouter) UnregisterSubscription(subID string)
UnregisterSubscription removes a subscription from message routing
type RelayConfig ¶ added in v0.4.12
type RelayConfig struct { URL string `json:"url"` Read bool `json:"read"` Write bool `json:"write"` }
RelayConfig represents relay configuration with permissions
type RelayConnection ¶
type RelayConnection struct { URL string Conn *websocket.Conn Status ConnectionStatus LastPing time.Time Subscriptions map[string]bool // contains filtered or unexported fields }
RelayConnection represents a single relay connection
type RelayPool ¶
type RelayPool struct {
// contains filtered or unexported fields
}
RelayPool manages multiple relay connections
func NewRelayPool ¶
NewRelayPool creates a new relay pool
func (*RelayPool) BroadcastMessage ¶
BroadcastMessage sends a message to multiple relays
func (*RelayPool) CloseConnection ¶
CloseConnection closes a specific relay connection
func (*RelayPool) GetConnectedRelays ¶
GetConnectedRelays returns a list of connected relay URLs
func (*RelayPool) GetConnection ¶
func (rp *RelayPool) GetConnection(url string) (*RelayConnection, error)
GetConnection returns a specific relay connection
func (*RelayPool) RegisterSubscription ¶
func (rp *RelayPool) RegisterSubscription(subID string, sub *Subscription)
RegisterSubscription registers a subscription for message routing
func (*RelayPool) SendMessage ¶
SendMessage sends a message to a specific relay
func (*RelayPool) UnregisterSubscription ¶
UnregisterSubscription removes a subscription from message routing
type Subscription ¶
type Subscription struct { ID string Filters []nostr.Filter Relays []string Events chan *nostr.Event Errors chan error Done chan struct{} // contains filtered or unexported fields }
Subscription manages a Nostr subscription across multiple relays
func NewSubscription ¶
func NewSubscription(id string, filters []nostr.Filter, relays []string, client *Client) *Subscription
NewSubscription creates a new subscription instance
func (*Subscription) AddRelay ¶
func (s *Subscription) AddRelay(url string) error
AddRelay adds a new relay to an active subscription
func (*Subscription) GetFilters ¶
func (s *Subscription) GetFilters() []nostr.Filter
GetFilters returns a copy of the subscription filters
func (*Subscription) GetRelayCount ¶
func (s *Subscription) GetRelayCount() int
GetRelayCount returns the number of relays in this subscription
func (*Subscription) IsActive ¶
func (s *Subscription) IsActive() bool
IsActive returns whether the subscription is currently active
func (*Subscription) RemoveRelay ¶
func (s *Subscription) RemoveRelay(url string) error
RemoveRelay removes a relay from the subscription
func (*Subscription) Start ¶
func (s *Subscription) Start() error
Start begins the subscription on all specified relays