Docs / How it works

Private routes

A route is a secant: a straight line of linked nodes that enters the network at one point and leaves at another. Every hop knows one neighbour on each side and nothing else.

$SECANTsoonChartBuy $SECANT

The line

When you send something, the client picks four linked nodes that sit close to one straight line across the network: an entry, two relays and an exit. The entry is where your line cuts into the circle, the exit is where it cuts out.

HopKnows who sent itKnows where it goesSees the content
EntryYes, youOnly relay 1No
Relay 1Only the entryOnly relay 2No
Relay 2Only relay 1Only the exitNo
ExitOnly relay 2Yes, the siteYes, the request

Layers

The client wraps the request once per hop, starting from the exit and working back to the entry. Each layer is made with a fresh one-time key, so two cells to the same node look nothing alike.

  1. Make a one-time P-256 key pair.
  2. ECDH with the hop’s public key gives 32 shared bytes.
  3. HKDF-SHA-256 with the one-time public key as salt and secant/layer/v1 as info gives an AES-256-GCM key.
  4. Encrypt { next, body }, where body is the cell for the next hop.
  5. Prepend the one-time public key and the IV.
BytesField
0–64One-time public key, uncompressed P-256 (65 bytes)
65–76AES-GCM IV (12 bytes)
77…Ciphertext and 16-byte tag

Peeling

A node does the same steps with its own private key. If the tag does not check out, the layer was not made for it and the cell is dropped. Every hop strips 77 bytes of header and 16 bytes of tag plus the base64 overhead of the inner cell, which is why the cell shrinks on the way.

import { peel } from "./secant.mjs";

const { next, body } = await peel(me, cell);
// next: the address of the next hop, or "web" if you are the exit
// body: the cell for the next hop, or the request itself

Why a straight line

Picking linked nodes that lie along one line, instead of any four nodes, keeps the route short in real distance and makes the entry and exit far apart. A line that bends back on itself tends to put entry and exit in the same neighbourhood, which is exactly what a watcher wants.

NOTEStraightness is a preference, not a rule. route() tries 400 random walks and keeps the straightest one that is long enough.

Replies

In version 0.3 the reply travels back along the same line, hop by hop, as plain bytes over each connection. Use https so the reply is encrypted between the site and you. Layered replies are planned for 0.4.