Documentation ¶
Index ¶
- Constants
- Variables
- func EstimateSize(ev *T) (size int)
- func EventToBinary(ev *T) (b []byte, err error)
- func Hash(in []byte) (out []byte)
- type Ascending
- type C
- type Descending
- type ReadBuffer
- func (r *ReadBuffer) Bytes() []byte
- func (r *ReadBuffer) ReadContent() (s string, err error)
- func (r *ReadBuffer) ReadCreatedAt() (t timestamp.T, err error)
- func (r *ReadBuffer) ReadEvent() (ev *T, err error)
- func (r *ReadBuffer) ReadID() (id *eventid.T, err error)
- func (r *ReadBuffer) ReadKind() (k kind.T, err error)
- func (r *ReadBuffer) ReadPubKey() (pk *pubkey.T, err error)
- func (r *ReadBuffer) ReadSignature() (sig *signature.T, err error)
- func (r *ReadBuffer) ReadTags() (t tags.T, err error)
- type T
- func (ev *T) CheckSignature() (valid bool, err error)
- func (ev *T) GetIDBytes() []byte
- func (ev *T) MarshalJSON() (bytes []byte, err error)
- func (ev *T) Serialize() []byte
- func (ev *T) Sign(skStr string, so ...schnorr.SignOption) (err error)
- func (ev *T) SignWithSecKey(sk *secp256k1.SecretKey, so ...schnorr.SignOption) (err error)
- func (ev *T) ToCanonical() (o array.T)
- func (ev *T) ToObject() (o object.T)
- type WriteBuffer
- func (w *WriteBuffer) Bytes() []byte
- func (w *WriteBuffer) Len() int
- func (w *WriteBuffer) WriteContent(s string) (err error)
- func (w *WriteBuffer) WriteCreatedAt(t timestamp.T) (err error)
- func (w *WriteBuffer) WriteEvent(ev *T) (err error)
- func (w *WriteBuffer) WriteID(id *eventid.T) (err error)
- func (w *WriteBuffer) WriteKind(k kind.T) (err error)
- func (w *WriteBuffer) WritePubKey(pk *pubkey.T) (err error)
- func (w *WriteBuffer) WriteSignature(sig *signature.T) (err error)
- func (w *WriteBuffer) WriteTags(t tags.T) (err error)
Constants ¶
const ( ID = iota PubKey CreatedAt Kind Tags Content Signature )
Variables ¶
var DecimalHexInSecond = []byte{'a'}
DecimalHexInSecond is the list of first tag fields that have "decimal:hex:"
var EOF = errors.New("truncated buffer")
var FieldSizes = []int{ ID: sha256.Size, PubKey: schnorr.PubKeyBytesLen, CreatedAt: binary.MaxVarintLen64, Kind: 2, Tags: -1, Content: -1, Signature: schnorr.SignatureSize, }
var HexInSecond = []byte{'e', 'p'}
HexInSecond is the list of first tag fields that the second is pure hex
Functions ¶
func EstimateSize ¶
func EventToBinary ¶
Types ¶
type Ascending ¶
type Ascending []*T
Ascending is a slice of events that sorts in ascending chronological order
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 ReadBuffer ¶
ReadBuffer is a control structure for reading and writing buffers.
It keeps track of the current cursor position, and each read function increments it to reflect the position of the next field in the data.
All strings extracted from a ReadBuffer will be directly converted to strings using unsafe.String and will be garbage collected only once these strings fall out of scope.
Thus the buffers cannot effectively be reused, the memory can only be reused via GC processing. This avoids data copy as the content fields are the biggest in the event.T structure and dominate the size of the whole event anyway, so either way this is done there is a tradeoff. This can be mitigated by changing the event.T to be a []byte instead.
func NewReadBuffer ¶
func NewReadBuffer(b []byte) (buf *ReadBuffer)
NewReadBuffer returns a new buffer containing the provided slice.
func (*ReadBuffer) Bytes ¶
func (r *ReadBuffer) Bytes() []byte
func (*ReadBuffer) ReadContent ¶
func (r *ReadBuffer) ReadContent() (s string, err error)
func (*ReadBuffer) ReadCreatedAt ¶
func (r *ReadBuffer) ReadCreatedAt() (t timestamp.T, err error)
func (*ReadBuffer) ReadEvent ¶
func (r *ReadBuffer) ReadEvent() (ev *T, err error)
func (*ReadBuffer) ReadPubKey ¶
func (r *ReadBuffer) ReadPubKey() (pk *pubkey.T, err error)
func (*ReadBuffer) ReadSignature ¶
func (r *ReadBuffer) ReadSignature() (sig *signature.T, err error)
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 *pubkey.T `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 *signature.T `json:"sig"` }
T is the primary datatype of nostr. This is the form of the structure that defines its JSON string based format.
func BinaryToEvent ¶
func (*T) CheckSignature ¶
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) GetIDBytes ¶
GetIDBytes returns the raw SHA256 hash of the canonical form of an T.
func (*T) MarshalJSON ¶
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 ¶
SignWithSecKey signs an event with a given *secp256xk1.SecretKey.
func (*T) ToCanonical ¶
ToCanonical returns a structure that provides a byte stringer that generates the canonical form used to generate the ID hash that can be signed.
type WriteBuffer ¶
type WriteBuffer struct {
Buf []byte
}
WriteBuffer the buffer should have its capacity pre-allocated but its length initialized to zero, and the length of the buffer acts as its effective cursor position.
func NewBufForEvent ¶
func NewBufForEvent(ev *T) (buf *WriteBuffer)
func NewWriteBuffer ¶
func NewWriteBuffer(l int) (buf *WriteBuffer)
NewWriteBuffer allocates a slice with zero length and capacity at the given length. Use with EstimateSize to get a buffer that will not require a secondary allocation step.
func (*WriteBuffer) Bytes ¶
func (w *WriteBuffer) Bytes() []byte
func (*WriteBuffer) Len ¶
func (w *WriteBuffer) Len() int
func (*WriteBuffer) WriteContent ¶
func (w *WriteBuffer) WriteContent(s string) (err error)
func (*WriteBuffer) WriteCreatedAt ¶
func (w *WriteBuffer) WriteCreatedAt(t timestamp.T) (err error)
func (*WriteBuffer) WriteEvent ¶
func (w *WriteBuffer) WriteEvent(ev *T) (err error)
func (*WriteBuffer) WritePubKey ¶
func (w *WriteBuffer) WritePubKey(pk *pubkey.T) (err error)
func (*WriteBuffer) WriteSignature ¶
func (w *WriteBuffer) WriteSignature(sig *signature.T) (err error)