eventsig

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package eventsig implements the federation event-signing wire spec: an Ed25519 signature over a canonical, length-prefixed, domain-separated preimage of an event's authenticated fields. It is the single source of truth for how signatures are produced and verified; the emit path (cortex.emitEvent) and the replay path (cortex.ReplayEvent) both go through here so the two can never drift.

This package is pure: it depends only on the event shape and the standard library, never on the database or filesystem. Keeping it side-effect-free is what makes the canonical preimage exhaustively testable.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadPublicKey is returned when a public key string is missing the
	// scheme prefix, is not valid base64, or is not the right length.
	ErrBadPublicKey = errors.New("eventsig: malformed public key")
	// ErrBadSignature is returned when a signature string is malformed
	// (wrong prefix, bad base64, wrong length) — distinct from a
	// well-formed signature that simply does not verify.
	ErrBadSignature = errors.New("eventsig: malformed signature")
	// ErrBadSeed is returned when a private-key seed string is malformed.
	ErrBadSeed = errors.New("eventsig: malformed seed")
	// ErrVerify is returned when a well-formed signature does not verify
	// against the event under the given public key.
	ErrVerify = errors.New("eventsig: signature verification failed")
)

Functions

func EncodePublic

func EncodePublic(pub ed25519.PublicKey) string

EncodePublic renders a public key as "ed25519:<base64>".

func EncodeSeed

func EncodeSeed(seed []byte) string

EncodeSeed renders a 32-byte private-key seed as base64 for the sidecar file. The seed, not the expanded private key, is what gets stored.

func Generate

func Generate() (priv ed25519.PrivateKey, pub string, seed string, err error)

Generate creates a fresh keypair and returns the private key, its encoded public key ("ed25519:<base64>"), and the base64 seed for the sidecar file.

func ParsePublic

func ParsePublic(s string) (ed25519.PublicKey, error)

ParsePublic decodes an "ed25519:<base64>" public key.

func Preimage

func Preimage(e event.Event) []byte

Preimage builds the canonical byte string that gets signed. The layout is fixed by the federation signing wire spec; any change here is a wire-format break and must bump domainTag. The event's own Signature field is deliberately excluded.

func PrivateFromSeed

func PrivateFromSeed(s string) (ed25519.PrivateKey, error)

PrivateFromSeed expands a base64-encoded 32-byte seed into a usable private key via ed25519.NewKeyFromSeed.

func PublicKeysEqual

func PublicKeysEqual(a, b string) bool

PublicKeysEqual reports whether two encoded public keys denote the same key, tolerating base64/whitespace differences by comparing the decoded bytes in constant time. Used by the TOFU pinning layer to decide whether an advertised key matches the one already pinned for a cortex.

func Sign

func Sign(priv ed25519.PrivateKey, e event.Event) (string, error)

Sign returns the "ed25519:<base64>" signature of the event under priv.

func Verify

func Verify(pub string, e event.Event, sig string) error

Verify checks that sig is a valid signature for e under the encoded public key. It returns nil on success, ErrBadPublicKey/ErrBadSignature for malformed inputs, or ErrVerify when a well-formed signature does not match. Callers distinguish these because the verify mode treats a malformed or failed signature the same way but logs them differently.

Types

This section is empty.

Jump to

Keyboard shortcuts

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