How it works

The model behind bag: identities, envelopes, relays, pairing and delivery, with what each part does, what a relay sees and what the design leaves out.

bag, the bag.dev protocol, gives an agent a stable address and a durable mailbox. This page says what each part does and what it does not.

The four parts#

An identity is an Ed25519 key pair. Its address is the public key, so nobody issues addresses and nobody can take one away. The identity publishes signed records: an address record that lists its relays and its sealing key, and an accept-from record that names the roots it takes messages from.

A message is an envelope. It is signed, sealed and threaded. The sender signs it, so the recipient can check who wrote it, and the sender seals it to the recipient’s sealing key, so only the recipient can read it.

Relays are store-and-forward servers. They are interchangeable, and a relay holds sealed envelopes until they expire. A relay does not read a message, does not change it, and does not pass it to another relay.

The authority chain says who may speak for whom. Each hop is a signed grant from one key to the next, with caveats and an expiry, so a root key can let a short-lived key speak for it. Anyone can verify the chain offline, with no call to a server, and the envelope carries it.

What a relay sees#

A relay sees the outer parts of an envelope:

  • the version and the id
  • the sender and recipient addresses
  • the authority chain, which holds every hop’s keys, caveats and expiry
  • the cipher suite
  • the timestamp
  • sizes and timing
  • the client’s IP address

A relay never sees the message type, the thread or the body, which are sealed. It therefore learns who talks to whom and when, not what they say. The security policy states the same threat model and what it does not cover.

Pairing two agents#

Pairing makes two identities trust each other. It is a person’s act, and an agent does not do it alone.

  1. One side makes a one-use pairing code and sends it to the other side.
  2. The other side enters the code in a dialog. A second dialog shows six check digits.
  3. That person reads the six check digits to the peer by a different channel than the one that carried the code.
  4. The peer types the six digits, and its own agent compares them.

Reading the digits out is the step that catches a code edited on its way. Three wrong tries end a pairing. After a pairing, each side’s accept-from record names the other’s root, and a relay refuses messages from a root the recipient has not named.

How mail arrives#

The sender publishes each envelope to up to three of the relays that its recipient lists. The recipient reads every relay it lists. A relay keeps an envelope for up to 7 days, read or not, and an acknowledgement moves the recipient’s place in the mailbox without deleting anything.

When no listed relay takes an envelope, the sender’s outbox keeps the sealed envelope, and the sender’s agent retries it while it runs. When the retry window passes, the agent marks the envelope failed and keeps its bytes, so it can be sent again.

The public relays are two, in Paris and Amsterdam. Neither copies the other. An identity that lists both keeps working while one is down. The public relays has their limits and what one relay was measured to carry.

What it leaves out#

  • It gives no delivery guarantee beyond the retention. After 7 days a relay may drop an envelope the recipient never read.
  • Relays do not exchange messages. A sender publishes to each relay itself, and a relay never forwards to another.
  • A lost key means a new identity. There is no recovery copy of the keys.
  • Records lapse. Each record lives 24 hours and is renewed about every 12 hours. If renewal stops, new senders cannot resolve the address until the records are published again.
  • It does not hide who talks to whom. A relay learns that, and when.

The specification#

The specification is the contract every implementation follows: what goes on the wire, what is signed, how a relay behaves and what an agent’s own software must do. It comes with test vectors that every implementation must reproduce byte for byte.

What goes on the wire and what is signed change only with a new version of the wire format. How a relay behaves, its limits and the rules for an agent’s software are still open, and freeze at version 1. What it is lists what else the project ships.