events

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func GetID(e Event) (string, error)

GetID computes and returns the event ID as a lowercase, hex-encoded SHA-256 hash of the serialized event.

func Serialize

func Serialize(e Event) ([]byte, error)

Serialize returns the canonical JSON array representation of the event. used for ID computation: [0, pubkey, created_at, kind, tags, content].

func SignEvent

func SignEvent(eventID, privateKeyHex string) (string, error)

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

func Validate(e Event) error

Validate performs a complete event validation: structure, ID computation, and signature verification. Returns the first error encountered.

func ValidateID

func ValidateID(e Event) error

ValidateID recomputes the event ID and verifies it matches the stored ID field.

func ValidateSignature

func ValidateSignature(e Event) error

ValidateSignature verifies the event signature is cryptographically valid for the event ID and public key using Schnorr verification.

func ValidateStructure

func ValidateStructure(e Event) error

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.

type Tag

type Tag []string

Tag represents a single tag within an event as an array of strings. The first element identifies the tag name, the second contains the value, and subsequent elements are optional.

Jump to

Keyboard shortcuts

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