Documentation
¶
Overview ¶
Roots is a purposefully minimal Nostr protocol library that provides only the primitives that define protocol compliance: event structure, serialization, cryptographic signatures, and subscription filters.
Index ¶
- Variables
- func GetID(e Event) (string, error)
- func Serialize(e Event) ([]byte, error)
- func SignEvent(eventID, privateKeyHex string) (string, error)
- func Validate(e Event) error
- func ValidateID(e Event) error
- func ValidateSignature(e Event) error
- func ValidateStructure(e Event) error
- type Event
- type Tag
Constants ¶
This section is empty.
Variables ¶
var ( // Hex64Pattern matches 64-character, lowercase, hexadecimal strings. // Used for validating event IDs and cryptographic keys. Hex64Pattern = regexp.MustCompile("^[a-f0-9]{64}$") // Hex128Pattern matches 128-character, lowercase, hexadecimal strings. // Used for validating signatures. Hex128Pattern = regexp.MustCompile("^[a-f0-9]{128}$") )
Functions ¶
func GetID ¶
GetID computes and returns the event ID as a lowercase, hex-encoded SHA-256 hash of the serialized event.
func Serialize ¶
Serialize returns the canonical JSON array representation of the event. used for ID computation: [0, pubkey, created_at, kind, tags, content].
func SignEvent ¶
SignEvent generates a Schnorr signature for the given event ID using the provided private key. Returns the signature as 128 lowercase hex characters.
func Validate ¶
Validate performs a complete event validation: structure, ID computation, and signature verification. Returns the first error encountered.
func ValidateID ¶
ValidateID recomputes the event ID and verifies it matches the stored ID field.
func ValidateSignature ¶
ValidateSignature verifies the event signature is cryptographically valid for the event ID and public key using Schnorr verification.
func ValidateStructure ¶
ValidateStructure checks that all event fields conform to the protocol specification: hex lengths, tag structure, and field formats.
Types ¶
type Event ¶
type Event struct {
ID string `json:"id"`
PubKey string `json:"pubkey"`
CreatedAt int `json:"created_at"`
Kind int `json:"kind"`
Tags []Tag `json:"tags"`
Content string `json:"content"`
Sig string `json:"sig"`
}
Event represents a Nostr protocol event, with its seven required fields. All fields must be present for a valid event.