Documentation
¶
Index ¶
- func Hash(in []byte) (out []byte)
- type C
- type E
- func (ev *E) Clone() *E
- func (ev *E) EstimateSize() (size int)
- func (ev *E) Free()
- func (ev *E) GetIDBytes() []byte
- func (ev *E) Marshal(dst []byte) (b []byte)
- func (ev *E) MarshalBinary(w io.Writer)
- func (ev *E) MarshalJSON() (b []byte, err error)
- func (ev *E) Serialize() (b []byte)
- func (ev *E) Sign(keys signer.I) (err error)
- func (ev *E) ToCanonical(dst []byte) (b []byte)
- func (ev *E) Unmarshal(b []byte) (rem []byte, err error)
- func (ev *E) UnmarshalBinary(r io.Reader) (err error)
- func (ev *E) UnmarshalJSON(b []byte) (err error)
- func (ev *E) Verify() (valid bool, err error)
- type S
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type E ¶
type E 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 int64
// Kind is the nostr protocol code for the type of event. See kind.T
Kind uint16
// 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 *tag.S
// 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
}
E is the primary datatype of nostr. This is the form of the structure that defines its JSON string-based format.
WARNING: DO NOT use json.Marshal with this type because it will not properly encode <, >, and & characters due to legacy bullcrap in the encoding/json library. Either call MarshalJSON directly or use a json.Encoder with html escaping disabled.
func (*E) Clone ¶ added in v0.4.9
Clone creates a deep copy of the event with independent memory allocations. The clone does not use bufpool, ensuring it has a separate lifetime from the original event. This prevents corruption when the original is freed while the clone is still in use (e.g., in asynchronous delivery).
func (*E) EstimateSize ¶
EstimateSize returns a size for the event that allows for worst case scenario expansion of the escaped content and tags.
func (*E) Free ¶
func (ev *E) Free()
Free nils all of the fields to hint to the GC that the event.E can be freed.
func (*E) GetIDBytes ¶
GetIDBytes returns the raw SHA256 hash of the canonical form of an event.E.
func (*E) MarshalBinary ¶
MarshalBinary writes a binary encoding of an event.
[ 32 bytes ID ] [ 32 bytes Pubkey ] [ varint CreatedAt ] [ 2 bytes Kind ] [ varint Tags length ]
[ varint tag length ] [ varint tag element length ] [ tag element data ] ...
[ varint Content length ] [ 64 bytes Sig ]
func (*E) MarshalJSON ¶
MarshalJSON marshals an event.E into a JSON byte string.
WARNING: if json.Marshal is called in the hopes of invoking this function on an event, if it has <, > or * in the content or tags they are escaped into unicode escapes and break the event ID. Call this function directly in order to bypass this issue.
func (*E) Sign ¶
Sign the event using the signer.I. Uses github.com/bitcoin-core/secp256k1 if available for much faster signatures.
Note that this only populates the Pubkey, ID and Sig. The caller must set the CreatedAt timestamp as intended.
func (*E) ToCanonical ¶
ToCanonical converts the event to the canonical encoding used to derive the event ID.
func (*E) Unmarshal ¶
Unmarshal unmarshalls a JSON string into an event.E.
func (*E) UnmarshalJSON ¶
UnmarshalJSON unmarshalls a JSON string into an event.E.
Call ev.Free() to return the provided buffer to the bufpool afterwards.
Source Files
¶
- binary.go
- canonical.go
- event.go
- signatures.go