ledger

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ledger is the signed membership log of a RemoHop account: the one piece of account state that does not depend on trusting the rendezvous server.

An account's membership is an append-only, hash-chained list of entries. Each entry is signed with the identity key of a device that is a member at that point in the log:

seq 0  create  device = signer = the first device; email = EmailHash
seq n  add     device = a new member, signed by an existing member
seq n  remove  device = a member that leaves, signed by any member

Every entry after the first names the hash of its predecessor, so the log can only be extended, never rewritten, without a member's key. The hash of the create entry is the account's ID; people compare its fingerprint (Fingerprint) between devices when a device joins, and every device keeps the ID it confirmed. A rendezvous server stores and relays the log but holds no member key, so it cannot add a device, and a device checks every log it receives against the ID it holds and against the longest log it has already verified (Extends).

What a server can still do is withhold the newest entries, for example a removal, from a device; see the account package for how hosts bound that.

Index

Constants

View Source
const (
	OpCreate = "create"
	OpAdd    = "add"
	OpRemove = "remove"
)

Operations.

View Source
const (
	// MaxEntries bounds a log. An account that reaches it has to be
	// deleted and created again; at a few changes a month that is decades.
	MaxEntries = 256
	// MaxMembers bounds the devices in an account at one time.
	MaxMembers = 64
	// MaxName bounds a device name in an entry.
	MaxName = auth.MaxTokenName
	// MaxEmail bounds an email address.
	MaxEmail = 254
)

Variables

This section is empty.

Functions

func Domain

func Domain(email string) string

Domain returns the part of a normalised address after the @.

func EmailHash

func EmailHash(normalized string) []byte

EmailHash names an account's address without spelling it out: the rendezvous server indexes accounts by it and the create entry commits to it.

func Extends

func Extends(old, next []Entry) bool

Extends reports whether next is old with zero or more entries appended: the only way an honest log changes. Both must already be verified.

func Fingerprint

func Fingerprint(id []byte) string

Fingerprint is how people compare an account ID between devices.

func NormalizeEmail

func NormalizeEmail(s string) (string, error)

NormalizeEmail checks an address and returns its canonical form: the bare address, lower case.

func NormalizeFingerprint

func NormalizeFingerprint(s string) string

NormalizeFingerprint reduces a typed fingerprint (any case, with or without colons or spaces) to the form Fingerprint prints, or "" if it is not a complete one.

func SignedBytes

func SignedBytes(e *Entry) []byte

SignedBytes is what an entry's signature covers. Other implementations (mobile apps, a web gateway) verify entries with it.

Types

type Entry

type Entry struct {
	Seq    int    `json:"seq"`
	Prev   []byte `json:"prev,omitempty"`
	Op     string `json:"op"`
	Device []byte `json:"device"`
	// Name is the device's name when the entry was made; display only.
	Name string `json:"name,omitempty"`
	// Email is EmailHash of the account's address, in the create entry.
	Email  []byte `json:"email,omitempty"`
	Time   int64  `json:"time"`
	Signer []byte `json:"signer"`
	Sig    []byte `json:"sig"`
}

Entry is one signed change to an account's membership.

func Create

func Create(id *auth.Identity, normalizedEmail, name string) Entry

Create makes the first entry of a new account, signed by its first device.

func (*Entry) Hash

func (e *Entry) Hash() []byte

Hash identifies an entry, signature included. The next entry's Prev is this; the create entry's hash is the account ID.

type Member

type Member struct {
	Key ed25519.PublicKey
	// Name is the name recorded when the device was added.
	Name string
	// Seq is the entry that added it; AddedBy the device that signed it.
	Seq     int
	AddedBy ed25519.PublicKey
	Added   time.Time
}

Member is a device in the account.

type State

type State struct {
	// ID is the account ID: the hash of the create entry.
	ID        []byte
	EmailHash []byte
	// Len is the number of entries; Head the hash of the last one.
	Len  int
	Head []byte
	// Members in the order they were added.
	Members []Member
}

State is the result of replaying a log.

func Verify

func Verify(log []Entry) (*State, error)

Verify replays a whole log.

func (*State) Apply

func (s *State) Apply(e Entry) error

Apply checks e as the next entry and, if it is valid, applies it.

func (*State) IsMember

func (s *State) IsMember(key ed25519.PublicKey) bool

IsMember reports whether key is a member.

func (*State) Member

func (s *State) Member(key ed25519.PublicKey) (Member, bool)

Member returns the member with key.

func (*State) Next

func (s *State) Next(id *auth.Identity, op string, device ed25519.PublicKey, name string) (Entry, error)

Next makes the next entry of the log s describes, signed by id, which must be a member.

Jump to

Keyboard shortcuts

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