Documentation ¶
Index ¶
- Constants
- Variables
- func EstimateSize(ev *T) (size int)
- func Hash(in []byte) (out []byte)
- type Ascending
- type C
- type Descending
- type Reader
- func (r *Reader) ReadContent() (s B, err error)
- func (r *Reader) ReadCreatedAt() (t *timestamp.T, err error)
- func (r *Reader) ReadEvent() (ev *T, err error)
- func (r *Reader) ReadID() (id B, err E)
- func (r *Reader) ReadKind() (k *kind.T, err error)
- func (r *Reader) ReadPubKey() (pk B, err E)
- func (r *Reader) ReadSignature() (sig B, err error)
- func (r *Reader) ReadTags() (t *tags.T, err error)
- type T
- func (ev *T) CheckSignature() (valid bool, err error)deprecated
- func (ev *T) ContentString() (s S)
- func (ev *T) EventID() (eid *eventid.T)
- func (ev *T) GetIDBytes() []byte
- func (ev *T) IDString() (s S)
- func (ev *T) MarshalBinary(dst B) (b B, err E)
- func (ev *T) MarshalJSON(dst B) (b B, err error)
- func (ev *T) PubKeyString() (s S)
- func (ev *T) Serialize() (b B)
- func (ev *T) SigString() (s S)
- func (ev *T) Sign(keys crypto.Signer) (err error)
- func (ev *T) SignWithSecKey(sk *k1.SecretKey, so ...sch.SignOption) (err error)deprecated
- func (ev *T) String() (r S)
- func (ev *T) TagStrings() (s [][]S)
- func (ev *T) ToCanonical() (b B)
- func (ev *T) UnmarshalBinary(b B) (r B, err E)
- func (ev *T) UnmarshalJSON(b B) (r B, err error)
- func (ev *T) UnmarshalJSONold(b B) (rem B, err error)
- func (ev *T) Verify() (valid bool, err error)
- type Ts
- type Writer
- func (w *Writer) Bytes() B
- func (w *Writer) Len() int
- func (w *Writer) WriteContent(s B) (err error)
- func (w *Writer) WriteCreatedAt(t *timestamp.T) (err E)
- func (w *Writer) WriteEvent(ev *T) (err error)
- func (w *Writer) WriteID(id B) (err E)
- func (w *Writer) WriteKind(k *kind.T) (err E)
- func (w *Writer) WritePubKey(pk B) (err E)
- func (w *Writer) WriteSignature(sig B) (err error)
- func (w *Writer) WriteTags(t *tags.T) (err E)
Constants ¶
const ( ID = iota PubKey CreatedAt Kind Tags Content Signature )
Variables ¶
var DecimalHexInSecond = B{'a'}
DecimalHexInSecond is the list of first tag fields that have "decimal:hex:"
var FieldSizes = []int{ ID: sha256.Size, PubKey: schnorr.PubKeyBytesLen, CreatedAt: binary.MaxVarintLen64, Kind: 2, Tags: -1, Content: -1, Signature: schnorr.SignatureSize, }
var HexInSecond = B{'e', 'p'}
HexInSecond is the list of first tag fields that the second is pure hex
Functions ¶
func EstimateSize ¶
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 Reader ¶
type Reader struct { Pos int Buf B }
Reader 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 Reader 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 ¶
NewReadBuffer returns a new buffer containing the provided slice.
func (*Reader) ReadContent ¶
func (*Reader) ReadPubKey ¶
func (r *Reader) ReadPubKey() (pk B, err E)
func (*Reader) ReadSignature ¶
type T ¶
type T struct { // ID is the SHA256 hash of the canonical encoding of the event ID B `json:"id"` // PubKey is the public key of the event creator PubKey B `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 B `json:"content"` // Sig is the signature on the ID hash that validates as coming from the // Pubkey. Sig B `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
deprecated
func (*T) ContentString ¶
func (ev *T) ContentString() (s S)
func (*T) GetIDBytes ¶
GetIDBytes returns the raw SHA256 hash of the canonical form of an T.
func (*T) MarshalBinary ¶
func (ev *T) MarshalBinary(dst B) (b B, err E)
func (*T) MarshalJSON ¶
func (*T) PubKeyString ¶
func (ev *T) PubKeyString() (s S)
func (*T) Sign ¶
Sign the event using the nostr.Signer. Uses github.com/bitcoin-core/secp256k1 if available for much faster signatures.
func (*T) SignWithSecKey
deprecated
func (*T) TagStrings ¶
func (ev *T) TagStrings() (s [][]S)
func (*T) ToCanonical ¶
func (ev *T) ToCanonical() (b B)
func (*T) UnmarshalBinary ¶
func (ev *T) UnmarshalBinary(b B) (r B, err E)
func (*T) UnmarshalJSON ¶
func (*T) UnmarshalJSONold ¶
type Writer ¶
type Writer struct {
Buf B
}
Writer 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 NewWriteBuffer ¶
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 (*Writer) WriteContent ¶
func (*Writer) WriteCreatedAt ¶
func (*Writer) WriteEvent ¶
func (*Writer) WritePubKey ¶
func (w *Writer) WritePubKey(pk B) (err E)