Documentation ¶
Index ¶
- Variables
- func CloseBytes(close nostr.CloseEnvelope) []byte
- func ClosedBytes(closed nostr.ClosedEnvelope) []byte
- func CompareEnvelope(t *testing.T, expected, got nostr.Envelope)
- func CompareEventEnvelope(t *testing.T, expected, got *nostr.EventEnvelope)
- func CompareReqEnvelope(t *testing.T, expected, got *nostr.ReqEnvelope)
- func CreateRandomEvent(opts ...RandomEventOption) nostr.Event
- func CreateRandomKeypair() (string, string, error)
- func CreateRandomTags(totalLen, maxTagLen int) nostr.Tags
- func EventBytes(event nostr.EventEnvelope) []byte
- func FormatLvlFunc(i interface{}) string
- func NoticeBytes(notice nostr.NoticeEnvelope) []byte
- func OKBytes(ok nostr.OKEnvelope) []byte
- func RandRange(min, max int) int
- func RandomKind() int
- func ReqBytes(req nostr.ReqEnvelope) []byte
- type RandomEventOption
Constants ¶
This section is empty.
Variables ¶
var ( // UseGeneratedKeypair overwrites the pubkey field of an event and the sig field of an event by signing the event with the provided keypair UsePreGeneratedKeypair = func(sk, pk string) RandomEventOption { return func(e *nostr.Event) error { e.PubKey = pk return e.Sign(pk) } } // UseKind overwrites the event kind field UseKind = func(kind int) RandomEventOption { return func(e *nostr.Event) error { e.Kind = kind return nil } } // UseKinds ensures the event kind field is set to one of the provided kinds UseKinds = func(kinds []int) RandomEventOption { return func(e *nostr.Event) error { e.Kind = kinds[rand.Intn(len(kinds))] return nil } } // MustBeNewerThan ensures the event created_at field is greater than the provided since time value MustBeNewerThan = func(since nostr.Timestamp) RandomEventOption { return func(e *nostr.Event) error { e.CreatedAt = nostr.Timestamp(since.Time().Add(time.Duration(RandRange(1, powInt(2, 16))) * time.Second).Unix()) return nil } } // MustBeOlderThan ensures the event created_at field is less than the provided until time value MustBeOlderThan = func(until nostr.Timestamp) RandomEventOption { return func(e *nostr.Event) error { e.CreatedAt = nostr.Timestamp(until.Time().Add(time.Duration(-1*RandRange(1, powInt(2, 16))) * time.Second).Unix()) return nil } } // OverwriteID overwrites the event ID. NOTE: use this option last if providing more than one to ensure it is not overwritten OverwriteID = func(id string) RandomEventOption { return func(e *nostr.Event) error { e.ID = id return nil } } // AppendSuffixToContent appends a suffix to the events content field AppendSuffixToContent = func(suffix string) RandomEventOption { return func(e *nostr.Event) error { e.Content = e.Content + suffix return nil } } // AppendTags appends the contents of a tag map to the events tags field AppendTags = func(tagMap nostr.TagMap) RandomEventOption { return func(e *nostr.Event) error { for letter, values := range tagMap { tag := nostr.Tag{letter} if len(values) <= 1 { tag = append(tag, values...) } else { tag = append(tag, values[int(math.Max(0, float64(RandRange(1, len(values)))))]) } e.Tags = append(e.Tags, tag) } return nil } } )
Functions ¶
func CloseBytes ¶
func CloseBytes(close nostr.CloseEnvelope) []byte
CloseBytes takes a nostr close message and serializes it
func ClosedBytes ¶
func ClosedBytes(closed nostr.ClosedEnvelope) []byte
ClosedBytes takes a nostr closed message and serializes it
func CompareEnvelope ¶
CompareEnvelope compares two different nostr envelope messages ensuring they're equal
func CompareEventEnvelope ¶
CompareEventEnvelope compares two event envelopes and ensures they're equal
func CompareReqEnvelope ¶
CompareReqEnvelope compares two req envelopes and ensures they're equal
func CreateRandomEvent ¶
func CreateRandomEvent(opts ...RandomEventOption) nostr.Event
CreateRandomEvent creates an event with random pubkey, kind, value, tags, content and created at fields. The ID and signature are generated from the random content
func CreateRandomKeypair ¶
CreateRandomKeypair generates a random key pair
func CreateRandomTags ¶
func CreateRandomTags(totalLen, maxTagLen int) nostr.Tags
CreateRandomTags creates random nostr tags of a given total length and where each tag is up to maxTagLen in length
func EventBytes ¶
func EventBytes(event nostr.EventEnvelope) []byte
EventBytes takes a nostr event and serializes it
func NoticeBytes ¶
func NoticeBytes(notice nostr.NoticeEnvelope) []byte
NoticeBytes takes a nostr notice message and serializes it
func OKBytes ¶
func OKBytes(ok nostr.OKEnvelope) []byte
OKBytes takes a nostr OK message and serializes it
func RandomKind ¶
func RandomKind() int
RandomKind creates a random kind within the range of 0 to 2^32-1
Types ¶
type RandomEventOption ¶
type RandomEventOption func(e *nostr.Event) error