event

package
v1.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(in []byte) (out []byte)

Types

type Ascending

type Ascending []*T

Ascending is a slice of events that sorts in ascending chronological order

func (Ascending) Len

func (ev Ascending) Len() int

func (Ascending) Less

func (ev Ascending) Less(i, j int) bool

func (Ascending) Swap

func (ev Ascending) Swap(i, j int)

type Descending

type Descending []*T

Descending sorts a slice of events in reverse chronological order (newest first)

func (Descending) Len

func (e Descending) Len() int

func (Descending) Less

func (e Descending) Less(i, j int) bool

func (Descending) Swap

func (e Descending) Swap(i, j int)

type T

type T struct {

	// ID is the SHA256 hash of the canonical encoding of the event
	ID eventid.T `json:"id"`

	// PubKey is the public key of the event creator in *hexadecimal* format
	PubKey string `json:"pubkey"`

	// CreatedAt is the UNIX timestamp of the event according to the event
	// creator (never trust a timestamp!)
	CreatedAt timestamp.T `json:"created_at"`

	// Kind is the nostr protocol code for the type of event. See kind.T
	Kind kind.T `json:"kind"`

	// Tags are a list of tags, which are a list of strings usually structured
	// as a 3 layer scheme indicating specific features of an event.
	Tags tags.T `json:"tags"`

	// Content is an arbitrary string that can contain anything, but usually
	// conforming to a specification relating to the Kind and the Tags.
	Content string `json:"content"`

	// Sig is the signature on the ID hash that validates as coming from the
	// Pubkey.
	Sig string `json:"sig"`
}

T is the primary datatype of nostr. This is the form of the structure that defines its JSON string based format.

func (*T) CheckSignature

func (ev *T) CheckSignature() (valid bool, err error)

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 (*T) GetID

func (ev *T) GetID() eventid.T

GetID serializes and returns the event ID as a hexadecimal string.

func (*T) GetIDBytes

func (ev *T) GetIDBytes() []byte

GetIDBytes returns the raw SHA256 hash of the canonical form of an T.

func (*T) MarshalJSON

func (ev *T) MarshalJSON() (bytes []byte, err error)

func (*T) Serialize

func (ev *T) Serialize() []byte

func (*T) Sign

func (ev *T) Sign(skStr string, so ...schnorr.SignOption) (err error)

Sign signs an event with a given Secret Key encoded in hexadecimal.

func (*T) SignWithSecKey

func (ev *T) SignWithSecKey(sk *secp256k1.SecretKey,
	so ...schnorr.SignOption) (err error)

SignWithSecKey signs an event with a given *secp256xk1.SecretKey.

func (*T) ToCanonical

func (ev *T) ToCanonical() (o array.T)

ToCanonical returns a structure that provides a byte stringer that generates the canonical form used to generate the ID hash that can be signed.

func (*T) ToObject

func (ev *T) ToObject() (o object.T)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL