event

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2025 License: Unlicense Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

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

func Marshal

func Marshal(ev *T, dst []byte) (b []byte)

func NewCanonical

func NewCanonical() (a *json.Array)

func Unmarshal

func Unmarshal(ev *T, b []byte) (r []byte, err error)

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 C

type C chan *T

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 in binary format
	ID []byte
	// PubKey is the public key of the event creator in binary format
	PubKey []byte
	// CreatedAt is the UNIX timestamp of the event according to the event
	// creator (never trust a timestamp!)
	CreatedAt *timestamp.T
	// Kind is the nostr protocol code for the type of event. See kind.T
	Kind *kind.T
	// 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
	// Content is an arbitrary string that can contain anything, but usually
	// conforming to a specification relating to the Kind and the Tags.
	Content []byte
	// Sig is the signature on the ID hash that validates as coming from the
	// Pubkey in binary format.
	Sig []byte
}

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

func GenerateRandomTextNoteEvent

func GenerateRandomTextNoteEvent(sign signer.I, maxSize int) (ev *T,
	err error)

func New

func New() (ev *T)

func (*T) CheckSignature deprecated

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

CheckSignature returns whether an event signature is authentic and matches the event ID and Pubkey.

Deprecated: use Verify

func (*T) ContentString

func (ev *T) ContentString() (s string)

func (*T) EventID

func (ev *T) EventID() (eid *eventid.T)

func (*T) FromCanonical

func (ev *T) FromCanonical(b []byte) (rem []byte, err error)

FromCanonical reverses the process of creating the canonical encoding, note that the signature is missing in this form. Allocate an event.T before calling this.

func (*T) GetIDBytes

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

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

func (*T) IDString

func (ev *T) IDString() (s string)

func (*T) Marshal

func (ev *T) Marshal(dst []byte) (b []byte)

func (*T) MarshalCompact

func (ev *T) MarshalCompact(dst []byte) (b []byte)

MarshalCompact encodes an event as the canonical form followed by the raw binary signature (64 bytes) which hashes to form the ID, thus a compact form for the database that is smaller and fast to decode.

func (*T) PubKeyString

func (ev *T) PubKeyString() (s string)

func (*T) Serialize

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

func (*T) SerializeIndented added in v1.7.14

func (ev *T) SerializeIndented() (b []byte)

func (*T) SigString

func (ev *T) SigString() (s string)

func (*T) Sign

func (ev *T) Sign(keys signer.I) (err error)

Sign the event using the signer.I. Uses github.com/bitcoin-core/secp256k1 if available for much faster signatures.

func (*T) SignWithSecKey deprecated

func (ev *T) SignWithSecKey(sk *k1.SecretKey,
	so ...sch.SignOption) (err error)

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

Deprecated: use Sign and nostr.I and p256k.Signer / p256k.BTCECSigner implementations.

func (*T) TagStrings

func (ev *T) TagStrings() (s [][]string)

func (*T) ToCanonical

func (ev *T) ToCanonical(dst []byte) (b []byte)

ToCanonical converts the event to the canonical encoding used to derive the event ID.

func (*T) Unmarshal

func (ev *T) Unmarshal(b []byte) (r []byte, err error)

func (*T) UnmarshalCompact

func (ev *T) UnmarshalCompact(b []byte) (rem []byte, err error)

func (*T) Verify

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

Verify an event is signed by the pubkey it contains. Uses github.com/bitcoin-core/secp256k1 if available for faster verification.

type Ts

type Ts []*T

Ts is an array of T that sorts in reverse chronological order.

func (Ts) Len

func (ev Ts) Len() int

func (Ts) Less

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

func (Ts) Swap

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

Directories

Path Synopsis
codectester

Jump to

Keyboard shortcuts

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