Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TagFilterName ¶ added in v0.8.1
TagFilterName normalizes a Tags key to the bare tag name: "#d" -> "d". A lone "#" is left alone since it is itself a (strange) tag name.
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 for nostrdb's ingester. It escapes like Commitment except that control characters stay raw: nostrdb's parser can't read \u escapes but takes raw control characters, and its own id derivation escapes them the way Commitment does, so the id it computes matches. 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 maps a tag name WITHOUT the leading '#' ("d", "p", "e") to the
// values to match. A leading '#' is tolerated and stripped wherever the
// filter is matched or encoded.
Tags map[string][]string `json:"-"`
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. Its JSON form is the NIP-01 wire format (see MarshalJSON), not the struct layout: tag filters are flattened to "#<name>" keys and since/until are unix seconds.
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) MarshalJSON ¶ added in v0.8.1
MarshalJSON encodes the filter in NIP-01 wire format. A nil list is omitted, but an empty non-nil list is kept: per NIP-01 it matches nothing, and dropping it would widen the filter to match everything.
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
func (*Filter) UnmarshalJSON ¶ added in v0.8.1
UnmarshalJSON decodes a NIP-01 filter object with the same strict rules the relay applies to incoming REQs (see ParseFilter).