Files
synchronicity/docs/KEY_MANAGEMENT.md
Greg ShuflinandClaude Opus 5.5 7dc0f80626 cli: syn init --new-ensemble makes the ensemble and the node in one step
`syn ensemble init` minted a keyphrase without a node and `syn init`
then needed it back; `ensemble register` joined a store that had a node
and no membership, which nothing ordinary makes any more. Both are gone:
`syn init --new-ensemble [--format-a]` sets the node up in a new
ensemble and prints its phrase once, and `syn init --keyphrase` (or the
prompt) joins one. The two are parser alternatives, so contradictory
flags are a usage error.

`syn init` now also finishes an existing store whose node is in no
ensemble, as the TUI's first run does, which gives NOT_IN_ENSEMBLE a
recourse that exists. NO_REGISTRY_NODES no longer suggests `register`,
which never worked on a node that already had a membership.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 22:17:13 -08:00

9.5 KiB

Key Management Design

Overview

Terminology: The user's collection of co-equal nodes is called an ensemble in this codebase and CLI (syn ensemble …).

Synchronicity uses a two-layer cryptographic identity model:

  • Ensemble key — a single Ed25519 keypair that represents ownership of a user's entire collection of nodes (their ensemble). The user carries the corresponding secret as a keyphrase. Two encodings exist: format A, a 20-word Bytewords encoding of a 128-bit random seed (16 data words + 4 CRC32 checksum words); and format B, an 8-word keyphrase from the EFF large diceware wordlist (default for new keys in the CLI).
  • Node key — an Ed25519 keypair generated independently per instance. This is the key used for all day-to-day P2P communication (iroh NodeId, pkarr publishing, etc.).

The ensemble key is the canonical identity of the user's personal distributed computer. Individual node keys are ephemeral by comparison — nodes can be created and destroyed without affecting the ensemble's identity.


Two-Layer Key Hierarchy

EnsembleSecret  (seed or diceware material → keyphrase; user memorizes this)
    │
    └─ HKDF-SHA256 (info = "syn-ensemble-v1") → Ed25519 keypair
                                                 ensemble_pubkey  (stable fleet identity)

NodeSecret  (128-bit random seed, generated per instance, stored locally)
    │
    └─ HKDF-SHA256 (info = "syn-node-v1") → Ed25519 keypair
                                             node_pubkey  (iroh NodeId, pkarr address)

Domain separation between key types is enforced by using distinct HKDF info tags (b"syn-ensemble-v1" vs b"syn-node-v1"). This prevents any theoretical confusion between keys derived from the same seed material in different contexts.

Why HKDF and not Argon2id: Argon2id is designed to stretch low-entropy inputs (human passwords) and is deliberately expensive to resist brute-force attacks. Our input is already high-entropy — a 128-bit random seed for format A, or validated EFF-large diceware material (≈103 bits) for format B — so the memory-hard work buys nothing. HKDF-SHA256 is the RFC 5869 primitive purpose-built for deriving fixed-length keys from already-uniform high-entropy key material, with application-specific domain separation via the info parameter. It is deterministic (required, since the same keyphrase must derive the same keypair on every device) and effectively free to compute.


Delegation Certificates

When an instance joins an ensemble, the user provides the keyphrase once. The instance derives the ensemble keypair in memory, creates a delegation certificate, signs it with the ensemble private key, then discards the private key. The certificate is stored locally alongside the node secret.

DelegationCert {
    version: u8,
    ensemble_pubkey: [u8; 32],   // identifies which ensemble this node belongs to
    node_pubkey: [u8; 32],       // this instance's iroh NodeId
    created_at_secs: u64,        // unix timestamp
    signature: [u8; 64],         // Ed25519 sig by ensemble key over above fields
}

The signed payload covers: version || ensemble_pubkey || node_pubkey || created_at_secs.

Human-meaningful node names (e.g. "Greg's phone") are metadata stored in local settings, not part of the delegation certificate. This keeps the cert focused on cryptographic addressing and discovery, while names remain a display concern that can be changed without re-signing.

A name is nonetheless ensemble-private (ADR 0044): it is about a person in a way a pubkey is not. It is absent from the pkarr registry, which is a world-readable DHT record, and it travels through gossip sealed under a key derived from the default vault key — itself derived from the ensemble secret, so every member can open a name and holding the ensemble public key cannot.

Any node that receives a DelegationCert can verify it knows only the ensemble public key, with no trusted third party required.


What Each Instance Stores

Data Stored? Notes
Ensemble private key No Only held in memory during registration
Ensemble public key Yes Used as fleet namespace for discovery
Delegation cert Yes Proves this node belongs to the ensemble
Node secret Yes Persistent instance identity (iroh, pkarr)

The ensemble private key is ephemeral by design, mirroring the hardware-wallet model: the keyphrase is the private key. It is only needed when registering a new node or performing administrative ensemble operations (e.g. explicitly removing a node from the registry). For all ordinary P2P activity the node key alone is sufficient.


Ensemble Registry via pkarr

pkarr (Public Key Addressable Resource Records, built on the BitTorrent Mainline DHT via BEP44) already publishes per-node records signed by each node's keypair. Ensemble-level discovery uses a second pkarr record, signed by the ensemble key and keyed to ensemble_pubkey.

Record format

{
  "v": 1,
  "members": [
    { "node_pubkey": "<hex>", "name": "Greg's phone",  "added": 1740000000 },
    { "node_pubkey": "<hex>", "name": "Greg's laptop", "added": 1740001234 }
  ]
}

This is published as a DNS TXT record inside a signed pkarr packet. Any node that knows ensemble_pubkey can look it up on the DHT and discover all sibling nodes.

Adding a new node

  1. Fetch the current ensemble registry record from the DHT (note the BEP44 sequence number).
  2. Append the new node's node_pubkey and metadata.
  3. Re-sign with the ensemble private key, incrementing the sequence number by 1.
  4. Publish. If the PUT is rejected (another node published a higher sequence number concurrently), fetch again and retry — conflicts are infrequent (only at registration time).

Checking node status

  1. Fetch the ensemble registry to enumerate all member node pubkeys.
  2. Attempt a P2P ping to each node (via iroh/pkarr resolution).
  3. Report round-trip time for reachable nodes; "offline" for unreachable ones.

Instance Lifecycle

First device (ensemble creation)

$ syn init --new-ensemble

This creates the store, sets the node up in a new ensemble, and prints that ensemble's keyphrase — once, since nothing keeps it. By default it is a format B keyphrase (8 diceware words); add --format-a for a format A Bytewords keyphrase (20 words). Example (format A):

Registered "laptop" in ensemble.
Ensemble key generated (format A (bytewords)).

!! WRITE DOWN YOUR ENSEMBLE KEYPHRASE AND KEEP IT SAFE !!
Anyone with this keyphrase can add nodes to your ensemble.

Keyphrase:

	word1  word2  word3  word4  word5
	...

Ensemble key: a3f7...bc12

Run 'syn init' on each other node and enter this keyphrase when prompted.

The first-run screens (desktop, TUI, Android) do the same in the other order: "Initialize new ensemble" shows the phrase first, and the node is set up in its ensemble when the user presses "I've written it down" — so leaving that screen writes nothing.

Subsequent devices

$ syn init --keyphrase "word1 word2 ... wordN"
Registered "Greg's phone" in ensemble.
Ensemble key: a3f7...bc12

(word1 … wordN is either 20 words for format A or 8 words for format B, as printed by syn init --new-ensemble. Without --keyphrase, syn init prompts for it.)

Checking status

$ syn ensemble members
Ensemble: a3f7...bc12
  Greg's phone   [3a9d...]  ONLINE  (2ms)
  Greg's laptop  [7f2c...]  OFFLINE (last seen 3h ago)
  Home server    [c841...]  ONLINE  (45ms)

Cryptographic Primitives

Primitive Usage Library
Ed25519 All keypair signing and verification iroh (wraps ed25519-dalek)
HKDF-SHA256 Key derivation from seed / diceware material hkdf + sha2
Bytewords Human-readable seed encoding for format A (20 words / 128 bits + CRC32) ur (bytewords module)
EFF diceware Format B keyphrase generation and validation in-tree wordlist
BEP44/pkarr Signed DHT records for node and ensemble discovery iroh pkarr integration

All primitives are standard, widely-deployed implementations. The design is intentionally conservative: no novel cryptographic constructions.


Deliberately Omitted: Key Rotation

The current design has no mechanism for rotating the ensemble key. If the ensemble private key (keyphrase) is compromised, there is no supported path to migrate the ensemble identity to a new keypair while preserving trust.

This is a known limitation, accepted for the bootstrap phase. Proper key rotation requires either:

  • A PKI or chain-of-trust anchor that can vouch for the new key
  • A social recovery scheme (e.g. threshold signatures across trusted nodes)
  • A timestamped revocation list published on the DHT

See TODO.md for a tracked item on this.


Future Extensions

The version field in DelegationCert and "v" in the ensemble registry are hooks for future evolution:

  • Capability delegation: certs that grant only read, not write
  • Expiry: time-bounded delegation for temporary access
  • Revocation: a per-ensemble revocation list on the DHT
  • Larger seed / longer keyphrase: upgrade path if 128-bit entropy is deemed insufficient for long-lived ensemble keys
  • Threshold signing: require M-of-N nodes to authorize administrative ensemble operations