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 ¶
- Variables
- func EncodePublic(pub ed25519.PublicKey) string
- func EncodeSeed(seed []byte) string
- func Generate() (priv ed25519.PrivateKey, pub string, seed string, err error)
- func ParsePublic(s string) (ed25519.PublicKey, error)
- func Preimage(e event.Event) []byte
- func PrivateFromSeed(s string) (ed25519.PrivateKey, error)
- func PublicKeysEqual(a, b string) bool
- func Sign(priv ed25519.PrivateKey, e event.Event) (string, error)
- func Verify(pub string, e event.Event, sig string) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
EncodePublic renders a public key as "ed25519:<base64>".
func EncodeSeed ¶
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 ¶
ParsePublic decodes an "ed25519:<base64>" public key.
func Preimage ¶
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 ¶
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 Verify ¶
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.