Documentation ¶
Index ¶
- Constants
- Variables
- func FilterEqual(a Filter, b Filter) bool
- func GeneratePrivateKey() string
- func GetPublicKey(sk string) (string, error)
- func IsValidPublicKeyHex(pk string) bool
- func NormalizeURL(u string) string
- type AuthEnvelope
- type CloseEnvelope
- type Connection
- type EOSEEnvelope
- type EntityPointer
- type Envelope
- type Event
- func (evt Event) CheckSignature() (bool, error)
- func (evt Event) GetExtra(key string) any
- func (evt Event) GetExtraBoolean(key string) bool
- func (evt Event) GetExtraNumber(key string) float64
- func (evt Event) GetExtraString(key string) string
- func (evt *Event) GetID() string
- func (v Event) MarshalEasyJSON(w *jwriter.Writer)
- func (v Event) MarshalJSON() ([]byte, error)
- func (evt *Event) Serialize() []byte
- func (evt *Event) SetExtra(key string, value any)
- func (evt *Event) Sign(privateKey string) error
- func (evt Event) String() string
- func (v *Event) UnmarshalEasyJSON(l *jlexer.Lexer)
- func (v *Event) UnmarshalJSON(data []byte) error
- type EventEnvelope
- type EventMessage
- type EventPointer
- type Filter
- type Filters
- type NoticeEnvelope
- type OKEnvelope
- type ProfileMetadata
- type ProfilePointer
- type Relay
- func (r *Relay) Auth(ctx context.Context, event Event) (Status, error)
- func (r *Relay) Close() error
- func (r *Relay) Connect(ctx context.Context) error
- func (r *Relay) Context() context.Context
- func (r *Relay) PrepareSubscription(ctx context.Context) *Subscription
- func (r *Relay) Publish(ctx context.Context, event Event) (Status, error)
- func (r *Relay) QuerySync(ctx context.Context, filter Filter) ([]*Event, error)
- func (r *Relay) String() string
- func (r *Relay) Subscribe(ctx context.Context, filters Filters) (*Subscription, error)
- type ReqEnvelope
- type SimplePool
- type Status
- type Subscription
- type Tag
- type TagMap
- type Tags
- func (tags Tags) AppendUnique(tag Tag) Tags
- func (tags Tags) ContainsAny(tagName string, values []string) bool
- func (tags Tags) FilterOut(tagPrefix []string) Tags
- func (tags Tags) GetAll(tagPrefix []string) Tags
- func (tags Tags) GetFirst(tagPrefix []string) *Tag
- func (tags Tags) GetLast(tagPrefix []string) *Tag
- func (t *Tags) Scan(src any) error
- type Timestamp
Examples ¶
Constants ¶
const ( KindSetMetadata int = 0 KindTextNote int = 1 KindRecommendServer int = 2 KindContactList int = 3 KindEncryptedDirectMessage int = 4 KindDeletion int = 5 KindBoost int = 6 KindReaction int = 7 KindChannelCreation int = 40 KindChannelMetadata int = 41 KindChannelMessage int = 42 KindChannelHideMessage int = 43 KindChannelMuteUser int = 44 KindZapRequest int = 9734 KindZap int = 9735 )
Variables ¶
Functions ¶
func FilterEqual ¶
func GeneratePrivateKey ¶
func GeneratePrivateKey() string
func GetPublicKey ¶
func IsValidPublicKeyHex ¶ added in v0.14.0
func NormalizeURL ¶
NormalizeURL normalizes the url and replaces http://, https:// schemes by ws://, wss://.
Example ¶
fmt.Println(NormalizeURL("")) fmt.Println(NormalizeURL("wss://x.com/y")) fmt.Println(NormalizeURL("wss://x.com/y/")) fmt.Println(NormalizeURL("http://x.com/y")) fmt.Println(NormalizeURL(NormalizeURL("http://x.com/y"))) fmt.Println(NormalizeURL("wss://x.com")) fmt.Println(NormalizeURL("wss://x.com/")) fmt.Println(NormalizeURL(NormalizeURL(NormalizeURL("wss://x.com/")))) fmt.Println(NormalizeURL("x.com")) fmt.Println(NormalizeURL("x.com/")) fmt.Println(NormalizeURL("x.com////")) fmt.Println(NormalizeURL("x.com/?x=23"))
Output: wss://x.com/y wss://x.com/y ws://x.com/y ws://x.com/y wss://x.com wss://x.com wss://x.com wss://x.com wss://x.com wss://x.com wss://x.com?x=23
Types ¶
type AuthEnvelope ¶ added in v0.18.1
func (AuthEnvelope) Label ¶ added in v0.18.1
func (_ AuthEnvelope) Label() string
func (AuthEnvelope) MarshalJSON ¶ added in v0.18.1
func (v AuthEnvelope) MarshalJSON() ([]byte, error)
func (*AuthEnvelope) UnmarshalJSON ¶ added in v0.18.1
func (v *AuthEnvelope) UnmarshalJSON(data []byte) error
type CloseEnvelope ¶ added in v0.18.1
type CloseEnvelope string
func (CloseEnvelope) Label ¶ added in v0.18.1
func (_ CloseEnvelope) Label() string
func (CloseEnvelope) MarshalJSON ¶ added in v0.18.1
func (v CloseEnvelope) MarshalJSON() ([]byte, error)
func (*CloseEnvelope) UnmarshalJSON ¶ added in v0.18.1
func (v *CloseEnvelope) UnmarshalJSON(data []byte) error
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func NewConnection ¶
func (*Connection) Close ¶
func (c *Connection) Close() error
func (*Connection) Ping ¶ added in v0.18.0
func (c *Connection) Ping() error
func (*Connection) ReadMessage ¶ added in v0.18.0
func (c *Connection) ReadMessage(ctx context.Context) ([]byte, error)
func (*Connection) WriteMessage ¶
func (c *Connection) WriteMessage(data []byte) error
type EOSEEnvelope ¶ added in v0.18.1
type EOSEEnvelope string
func (EOSEEnvelope) Label ¶ added in v0.18.1
func (_ EOSEEnvelope) Label() string
func (EOSEEnvelope) MarshalJSON ¶ added in v0.18.1
func (v EOSEEnvelope) MarshalJSON() ([]byte, error)
func (*EOSEEnvelope) UnmarshalJSON ¶ added in v0.18.1
func (v *EOSEEnvelope) UnmarshalJSON(data []byte) error
type EntityPointer ¶ added in v0.14.0
type Envelope ¶ added in v0.18.1
type Envelope interface { Label() string UnmarshalJSON([]byte) error MarshalJSON() ([]byte, error) }
func ParseMessage ¶ added in v0.18.1
type Event ¶
type Event struct { ID string `json:"id"` PubKey string `json:"pubkey"` CreatedAt Timestamp `json:"created_at"` Kind int `json:"kind"` Tags Tags `json:"tags"` Content string `json:"content"` Sig string `json:"sig"` // contains filtered or unexported fields }
func (Event) CheckSignature ¶
CheckSignature checks if the signature is valid for the id (which is a hash of the serialized event content). returns an error if the signature itself is invalid.
func (Event) GetExtra ¶ added in v0.8.2
GetExtra tries to get a value under the given key that may be present in the event object but is hidden in the basic type since it is out of the spec.
func (Event) GetExtraBoolean ¶ added in v0.8.2
GetExtraBoolean is like Event.GetExtra, but only works if the value is a boolean, otherwise returns the zero-value.
func (Event) GetExtraNumber ¶ added in v0.8.2
GetExtraNumber is like Event.GetExtra, but only works if the value is a float64, otherwise returns the zero-value.
func (Event) GetExtraString ¶ added in v0.8.2
GetExtraString is like Event.GetExtra, but only works if the value is a string, otherwise returns the zero-value.
func (Event) MarshalEasyJSON ¶ added in v0.17.0
MarshalEasyJSON supports easyjson.Marshaler interface
func (Event) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Event) Serialize ¶
Serialize outputs a byte array that can be hashed/signed to identify/authenticate. JSON encoding as defined in RFC4627.
func (*Event) SetExtra ¶ added in v0.8.2
SetExtra sets an out-of-the-spec value under the given key into the event object.
func (Event) String ¶ added in v0.16.3
Event Stringer interface, just returns the raw JSON as a string
func (*Event) UnmarshalEasyJSON ¶ added in v0.17.0
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Event) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type EventEnvelope ¶ added in v0.18.1
func (EventEnvelope) Label ¶ added in v0.18.1
func (_ EventEnvelope) Label() string
func (EventEnvelope) MarshalJSON ¶ added in v0.18.1
func (v EventEnvelope) MarshalJSON() ([]byte, error)
func (*EventEnvelope) UnmarshalJSON ¶ added in v0.18.1
func (v *EventEnvelope) UnmarshalJSON(data []byte) error
type EventMessage ¶
type EventPointer ¶ added in v0.13.0
type Filter ¶
type Filter struct { IDs []string `json:"ids,omitempty"` Kinds []int `json:"kinds,omitempty"` Authors []string `json:"authors,omitempty"` Tags TagMap `json:"-,omitempty"` Since *Timestamp `json:"since,omitempty"` Until *Timestamp `json:"until,omitempty"` Limit int `json:"limit,omitempty"` Search string `json:"search,omitempty"` }
func (Filter) MarshalEasyJSON ¶ added in v0.17.0
MarshalEasyJSON supports easyjson.Marshaler interface
func (Filter) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Filter) UnmarshalEasyJSON ¶ added in v0.17.0
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Filter) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type NoticeEnvelope ¶ added in v0.18.1
type NoticeEnvelope string
func (NoticeEnvelope) Label ¶ added in v0.18.1
func (_ NoticeEnvelope) Label() string
func (NoticeEnvelope) MarshalJSON ¶ added in v0.18.1
func (v NoticeEnvelope) MarshalJSON() ([]byte, error)
func (*NoticeEnvelope) UnmarshalJSON ¶ added in v0.18.1
func (v *NoticeEnvelope) UnmarshalJSON(data []byte) error
type OKEnvelope ¶ added in v0.18.1
func (OKEnvelope) Label ¶ added in v0.18.1
func (_ OKEnvelope) Label() string
func (OKEnvelope) MarshalJSON ¶ added in v0.18.1
func (v OKEnvelope) MarshalJSON() ([]byte, error)
func (*OKEnvelope) UnmarshalJSON ¶ added in v0.18.1
func (v *OKEnvelope) UnmarshalJSON(data []byte) error
type ProfileMetadata ¶ added in v0.9.0
type ProfileMetadata struct { Name string `json:"name,omitempty"` DisplayName string `json:"display_name,omitempty"` About string `json:"about,omitempty"` Website string `json:"website,omitempty"` Picture string `json:"picture,omitempty"` Banner string `json:"banner,omitempty"` NIP05 string `json:"nip05,omitempty"` LUD16 string `json:"lud16,omitempty"` }
func ParseMetadata ¶ added in v0.9.0
func ParseMetadata(event Event) (*ProfileMetadata, error)
type ProfilePointer ¶ added in v0.13.0
type Relay ¶
type Relay struct { URL string RequestHeader http.Header // e.g. for origin header Connection *Connection Challenges chan string // NIP-42 Challenges Notices chan string ConnectionError error // custom things that aren't often used // AssumeValid bool // this will skip verifying signatures for events received from this relay // contains filtered or unexported fields }
func NewRelay ¶
NewRelay returns a new relay. The relay connection will be closed when the context is canceled.
func RelayConnect ¶ added in v0.8.1
RelayConnect returns a relay object connected to url. Once successfully connected, cancelling ctx has no effect. To close the connection, call r.Close().
func (*Relay) Auth ¶ added in v0.12.0
Auth sends an "AUTH" command client -> relay as in NIP-42. Status can be: success, failed, or sent (no response from relay before ctx times out).
func (*Relay) Connect ¶
Connect tries to establish a websocket connection to r.URL. If the context expires before the connection is complete, an error is returned. Once successfully connected, context expiration has no effect: call r.Close to close the connection.
The underlying relay connection will use a background context. If you want to pass a custom context to the underlying relay connection, use NewRelay() and then Relay.Connect().
func (*Relay) Context ¶ added in v0.18.1
Context retrieves the context that is associated with this relay connection.
func (*Relay) PrepareSubscription ¶ added in v0.8.2
func (r *Relay) PrepareSubscription(ctx context.Context) *Subscription
func (*Relay) Publish ¶
Publish sends an "EVENT" command to the relay r as in NIP-01. Status can be: success, failed, or sent (no response from relay before ctx times out).
type ReqEnvelope ¶ added in v0.18.1
func (ReqEnvelope) Label ¶ added in v0.18.1
func (_ ReqEnvelope) Label() string
func (ReqEnvelope) MarshalJSON ¶ added in v0.18.1
func (v ReqEnvelope) MarshalJSON() ([]byte, error)
func (*ReqEnvelope) UnmarshalJSON ¶ added in v0.18.1
func (v *ReqEnvelope) UnmarshalJSON(data []byte) error
type SimplePool ¶ added in v0.18.0
type SimplePool struct { Relays map[string]*Relay Context context.Context // contains filtered or unexported fields }
func NewSimplePool ¶ added in v0.18.0
func NewSimplePool(ctx context.Context) *SimplePool
func (*SimplePool) EnsureRelay ¶ added in v0.18.0
func (pool *SimplePool) EnsureRelay(url string) (*Relay, error)
func (*SimplePool) SubMany ¶ added in v0.18.0
SubMany opens a subscription with the given filters to multiple relays the subscriptions only end when the context is canceled
func (*SimplePool) SubManyEose ¶ added in v0.18.0
func (pool *SimplePool) SubManyEose( ctx context.Context, urls []string, filters Filters, ) chan *Event
SubManyEose is like SubMany, but it stops subscriptions and closes the channel when gets a EOSE
type Subscription ¶
type Subscription struct { Relay *Relay Filters Filters Events chan *Event EndOfStoredEvents chan struct{} Context context.Context // contains filtered or unexported fields }
func (*Subscription) Fire ¶ added in v0.8.2
func (sub *Subscription) Fire() error
Fire sends the "REQ" command to the relay.
func (*Subscription) GetID ¶ added in v0.14.0
func (sub *Subscription) GetID() string
GetID return the Nostr subscription ID as given to the relay, it will be a sequential number, stringified.
func (*Subscription) SetLabel ¶ added in v0.14.0
func (sub *Subscription) SetLabel(label string)
SetLabel puts a label on the subscription that is prepended to the id that is sent to relays,
it's only useful for debugging and sanity purposes.
func (*Subscription) Sub ¶
func (sub *Subscription) Sub(ctx context.Context, filters Filters)
Sub sets sub.Filters and then calls sub.Fire(ctx).
func (*Subscription) Unsub ¶
func (sub *Subscription) Unsub()
Unsub closes the subscription, sending "CLOSE" to relay as in NIP-01. Unsub() also closes the channel sub.Events.
type Tag ¶
type Tag []string
func (Tag) StartsWith ¶
StartsWith checks if a tag contains a prefix. for example,
["p", "abcdef...", "wss://relay.com"]
would match against
["p", "abcdef..."]
or even
["p", "abcdef...", "wss://"]
type Tags ¶
type Tags []Tag
func (Tags) AppendUnique ¶
AppendUnique appends a tag if it doesn't exist yet, otherwise does nothing. the uniqueness comparison is done based only on the first 2 elements of the tag.
func (Tags) FilterOut ¶
FilterOut removes all tags that match the prefix, see Tag.StartsWith
func (Tags) GetAll ¶
GetAll gets all the tags that match the prefix, see Tag.StartsWith
func (Tags) GetFirst ¶
GetFirst gets the first tag in tags that matches the prefix, see Tag.StartsWith
func (Tags) GetLast ¶
GetLast gets the last tag in tags that matches the prefix, see Tag.StartsWith
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package nip13 implements NIP-13 See https://github.com/nostr-protocol/nips/blob/master/13.md for details.
|
Package nip13 implements NIP-13 See https://github.com/nostr-protocol/nips/blob/master/13.md for details. |