Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientInterface ¶
type ClientInterface interface {
SendMessage(msg interface{})
// SendMessageBlocking enqueues with backpressure for REQ-fulfillment
// loops that need producer/consumer rate parity. Never call from
// BroadcastEvent. Returns non-nil if the client has gone away.
SendMessageBlocking(msg interface{}) error
GetWS() *websocket.Conn
GetSubscriptions() map[string][]Filter
SetSubscription(subID string, filters []Filter)
DeleteSubscription(subID string)
SubscriptionCount() int
// OldestSubscription returns the sub whose latest REQ is oldest, for
// eviction at the per-client cap.
OldestSubscription() (string, bool)
ForEachSubscription(fn func(subID string, filters []Filter))
// NoticeOnce reports whether the NOTICE keyed by key is new on this
// connection, marking it sent.
NoticeOnce(key string) bool
CloseClient()
IsConnected() bool
// AllowReq checks the client's per-connection REQ rate limiter.
// Returns (true, "") if allowed, (false, reason) if rate limited.
AllowReq() (bool, string)
// AllowEvent checks the client's per-connection event rate limiter.
AllowEvent(kind int, category string) (bool, string)
}
ClientInterface abstracts WebSocket clients
type Event ¶
type Event struct {
ID string `json:"id"`
PubKey string `json:"pubkey"`
CreatedAt int64 `json:"created_at"`
Kind int `json:"kind"`
Tags [][]string `json:"tags"`
Content string `json:"content"`
Sig string `json:"sig"`
}
func (Event) CanonicalJSON ¶ added in v0.8.0
CanonicalJSON returns the event as a JSON object whose strings use the NIP-01 escapes, so a parser that re-derives the id from it (nostrdb's ingester does) hashes the same bytes as Commitment. Nil tags encode as [].
func (Event) Commitment ¶ added in v0.8.0
Commitment returns the NIP-01 id preimage [0,<pubkey>,<created_at>,<kind>,<tags>,<content>]; the event id is its SHA-256.
type Filter ¶
type Filter struct {
IDs []string `json:"ids,omitempty"`
Authors []string `json:"authors,omitempty"`
Kinds []int `json:"kinds,omitempty"`
Tags map[string][]string `json:"#,omitempty"` // Fixed: should be "#" for tag filters
Since *time.Time `json:"since,omitempty"`
Until *time.Time `json:"until,omitempty"`
Limit *int `json:"limit,omitempty"`
Search string `json:"search,omitempty"` // NIP-50: fulltext search query
}
Filter represents the criteria used to query events
func ParseFilter ¶ added in v0.8.0
ParseFilter builds a Filter from one decoded NIP-01 filter object. It is strict on purpose: a malformed field is an error, never silently skipped, because skipping a constraint WIDENS the filter — a typo'd {"kinds":["1"]} used to lose its kinds and match every event in the database.
matchable=false with a nil error means the filter is well-formed but can never match anything (an empty ids/authors/kinds/#tag list, same as nostr-tools and go-nostr); callers drop it instead of querying.
ids and authors accept 1–64 hex chars. Anything shorter than 64 is matched as a prefix — nonstandard since NIP-01 moved to exact ids, but deliberately kept: tools like glyphbyte.dev look events up by their leading bytes. See HasPrefixMatch.
func (Filter) HasPrefixMatch ¶ added in v0.8.0
HasPrefixMatch reports whether any ids/authors entry is shorter than a full 64-char id, i.e. will be matched as a prefix rather than exactly.
func (Filter) MatchesEvent ¶ added in v0.5.0
MatchesEvent returns true if the event satisfies all filter criteria per NIP-01. An empty/zero field means "match all" for that field.
func (Filter) ToSubscriptionFilter ¶ added in v0.4.1
ToSubscriptionFilter converts Filter to a relay-compatible format