eventid

package
v1.14.3 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: Unlicense Imports: 4 Imported by: 0

Documentation

Overview

Package eventid is a codec for managing nostr event Ids (hash of the canonical form of a nostr event).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

type T [sha256.Size]byte

T is the SHA256 hash in hexadecimal of the canonical form of an event as produced by the output of T.ToCanonical().Bytes().

func Gen

func Gen() (ei *T)

Gen creates a fake pseudorandom generated event Id for tests.

func New

func New() (ei *T)

New creates a new eventid.T. This is actually more wordy than simply creating a &T{} via slice literal.

func NewFromBytes

func NewFromBytes(b []byte) (ei *T, err error)

NewFromBytes creates a new eventid.T from the raw event Id hash.

func NewFromString

func NewFromString(s string) (ei *T, err error)

NewFromString inspects a string and ensures it is a valid, 64 character long hexadecimal string, returns the string coerced to the type.

func NewWith

func NewWith[V string | []byte](s V) (ei *T)

NewWith creates an eventid.T out of bytes or string but assumes it is binary and that it is the right length. The result is either truncated or padded automatically by the use of the "copy" operation.

func (*T) ByteString

func (ei *T) ByteString(src []byte) (b []byte)

ByteString renders an eventid.T as bytes in ASCII hex.

func (*T) Bytes

func (ei *T) Bytes() (b []byte)

Bytes returns the raw bytes of the eventid.T.

func (*T) Equal

func (ei *T) Equal(ei2 *T) (eq bool)

Equal tests whether another eventid.T is the same.

func (*T) Len

func (ei *T) Len() int

Len returns the length of the eventid.T.

func (*T) Marshal

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

Marshal renders the eventid.T into JSON.

func (*T) Set

func (ei *T) Set(b []byte) (err error)

Set the value of an eventid.T with checking of the length before copying it.

func (*T) String

func (ei *T) String() string

String renders an eventid.T as a string.

func (*T) Unmarshal

func (ei *T) Unmarshal(b []byte) (rem []byte, err error)

Unmarshal decodes a JSON encoded eventid.T.

Jump to

Keyboard shortcuts

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