Pairing
How a viewer gets a daemon's key and the daemon gets the viewer's, over a direct channel or a relay.
There are no accounts and no hosted service. A daemon and a viewer each have an X25519 key pair, and pairing exchanges them once. Every later connection is a Noise handshake that proves both keys. The exact protocol is in the wire protocol, sections 4 and 5; this page is how to use it.
Ids
daemon_idisvpd_plus 26 base32 characters of the SHA-256 of the daemon's public key.peer_idisvpp_plus the same for the viewer's key.
Both are 130-bit fingerprints. fingerprint("vpd" | "vpp", publicKey) from @viewportai/daemon/client computes
them.
From the CLI
viewport-daemon pair asks the running daemon for a single-use link over the local socket, prints it, and waits until a
viewer redeems it. The link is watch-only (viewer) unless you pass --role controller, and the first line the
command prints names the role and what it grants. A controller link gives whoever opens it control of every
session: starting commands, sending input and answering approvals. Share one only with someone you would let run
commands on this machine.
viewport-daemon pair # viewer (watch only), 10 minutes, every reachable target
viewport-daemon pair --role controller --ttl 2m # full control, short-lived link
viewport-daemon pair --relay wss://relay.example.com # offer this relay instead of the default
viewport-daemon pair --console https://console.example.com # the same link, opened by another Console
viewport-daemon pair --confirm # compare fingerprints before the peer is storedRole: VIEWER (watch only: reads sessions and events, cannot start, control or approve)
viewport://pair#v=1&k=...&o=off_01...&s=...&d=ws%3A%2F%2F127.0.0.1%3A7070%2Fv1%2Fconnect&n=build-box
Single use, viewer, expires 2026-11-25 10:47:00. Treat it like a password.
Waiting for a viewer to pair... (Ctrl-C stops waiting; the link stays valid until it expires)
Paired with phone (viewer)--no-wait prints the link and exits. With --json the steps are JSON lines: {"type":"offer",...}, then
{"type":"pending",...} with --confirm, then {"type":"paired","peer":{...}}. No QR code is printed yet; open the
link on the other device or paste it into Console.
Without --console (or the daemon's console_url) the link is viewport://pair#...: paste it into Console, or
pass --console http://127.0.0.1:7071 to get a link that opens your local Console. The default is not an http URL
because a sandboxed agent listening on that port would read the secret from the link (see
Security). On macOS agents can never listen on the Console's port.
With --confirm, the daemon holds the viewer's first request and the CLI shows both full fingerprints in groups of
4. Answer y only if every group matches what the viewer shows, within 120 seconds:
Pairing request from phone for role viewer.
Compare every group with what the viewer shows:
peer vpp_ b5ws ku77 bqhu i6xc alw5 qq4d 4g
daemon vpd_ qlnl gku2 5x73 jes2 oyxy ph3p 3u
All groups match? [y/N] (118 s)Anything but y, or no answer in time, refuses the viewer with daemon.pair_not_confirmed and exits 1. If the
viewer leaves while you decide, the daemon drops the question and the link stays unused: the next viewer gets a new
prompt. An answer the daemon can no longer take exits 1 at once. Ctrl-C with --confirm leaves nobody to confirm,
so the daemon refuses every viewer of that link until it expires; run viewport-daemon pair again for a new one.
viewport-daemon peers ls # paired viewers, role, name, last seen
viewport-daemon peers revoke vpp_b5wsku77bqhui6xcalw5qq4d4g # removes it and closes its channelsA daemon started with --no-local-pairing refuses pair.offer on the local socket, and therefore viewport-daemon pair too: nothing can pair with it until it restarts without the flag.
Offers and links
server.pair() creates a single-use offer, exactly as the pair.offer request does over the local socket. It
probes every target (direct URL, registered relay) for up to 3 seconds and puts only reachable ones in the link.
If none answers, it fails with daemon.pair_target_unreachable.
| Option | Default | Notes |
|---|---|---|
role | viewer | viewer may watch and read; controller may also start, control and answer approvals. Pass controller explicitly |
ttlMs | 10 minutes | 30 seconds to 60 minutes |
directUrl, relayUrl | the server's own | override the targets put in the link |
The link carries the daemon's public key k, the offer id and a 32-byte secret, in the URL fragment so it never
reaches a server log. Treat a link like a password until it is used or expires.
Direct channel
serve() listens on 127.0.0.1:7070 by default (direct: { port: 0 } picks a free port). The viewer pairs with
pair(link, { identity, store }), which stores the daemon record only after the daemon committed the pairing.
const supervisor = createTestSupervisor({ runners: [fakeRunner("agent", [say("Hello from the agent."), exit(0)])] });
const confirmed: { peerId: string; daemonId: string }[] = [];
const server = await serve(supervisor, {
home, // daemon.sock, token and peers.json live here
direct: { host: "127.0.0.1", port: 0 }, // port 0 picks a free port
name: "build-box",
clock: supervisor.clock, // serve() takes its own clock and ids; share the test ones for a stable transcript
ids: supervisor.ids,
// pair --confirm: called once the viewer's first message decrypts, before the peer is stored.
confirmPair: ({ peerId, daemonId, role }) => {
console.log(`daemon | pairing request for role ${role}`);
console.log(`daemon | peer ${groups(peerId)}`);
console.log(`daemon | daemon ${groups(daemonId)}`);
confirmed.push({ peerId, daemonId });
return true; // the operator compared every group
},
});
const offer = await server.pair({ role: "controller", ttlMs: 60_000 });
console.log(`daemon | offer ${offer.offerId}, expires ${offer.expiresAt}`);const identity = await createIdentity({ privateKey: new Uint8Array(32).fill(7) });
const store = memoryPairedDaemonStore();
// Show the fingerprints before pairing: the daemon id of the link's key `k`, and this viewer's own peer id.
const link = parsePairLink(offer.link);
const daemonId = await fingerprint("vpd", link.daemonPublicKey);
const peerId = await fingerprint("vpp", identity.publicKey);
console.log(`viewer | link for ${link.name} via ${link.directUrl ? "direct" : "relay"}`);
console.log(`viewer | peer ${groups(peerId)}`);
console.log(`viewer | daemon ${groups(daemonId)}`);
const paired = await pair(offer.link, { identity, store, name: "laptop" });
console.log(`viewer | paired with ${paired.daemon.name} as ${paired.role}`);
paired.close();A browser page connects from an origin, and the daemon refuses the direct upgrade of any origin it was not told
about (403), so other web pages cannot take its handshake slots. The Console's origin is allowed: the origin of
--console (consoleUrl), by default http://127.0.0.1:7071, where localhost and 127.0.0.1 are interchangeable.
If you open pair links in a Console served from anywhere else, for example with pair --console https://console.example.com, start the daemon with that origin too:
viewport-daemon up --allow-origin https://console.example.com # repeatable; library: serve(sup, { allowedOrigins })Clients that are not browsers send no Origin and are not affected.
identity is the viewer's static key. In a browser, create it with createIdentity({ extractable: false }) and
keep it in IndexedDB. store is any PairedDaemonStore; memoryPairedDaemonStore() is for tests and scripts.
Fingerprint confirmation
With confirmPair, the daemon holds the viewer's first request until the operator decides, for up to 120 seconds.
Both sides show both full fingerprints in groups of 4 and the operator compares every group. Never compare a
prefix: an attacker who substituted the link can grind a key matching 8 characters in about 2^40 tries. A refusal
or timeout closes the channel with daemon.pair_not_confirmed, and the offer stays unused until it expires.
The example's transcript, both sides showing the same groups:
viewer | peer vpp_ b5ws ku77 bqhu i6xc alw5 qq4d 4g
viewer | daemon vpd_ qlnl gku2 5x73 jes2 oyxy ph3p 3u
daemon | pairing request for role controller
daemon | peer vpp_ b5ws ku77 bqhu i6xc alw5 qq4d 4g
daemon | daemon vpd_ qlnl gku2 5x73 jes2 oyxy ph3p 3uRelay
A daemon behind NAT dials out to a relay with connectRelay and needs no listening port. Offers then target the
registered relay, and the link carries the viewer relay token t. The relay routes ciphertext: it never sees
requests, events or the pairing secret, and it cannot pair itself or impersonate the daemon.
const supervisor = createTestSupervisor({
runners: [fakeRunner("agent", [say("Working through the relay."), exit(0)])],
});
// No local socket, no direct endpoint: the daemon only dials out.
const server = await serve(supervisor, { socket: false, direct: false, name: "build-box", clock: supervisor.clock });
// This relay admits both roles with one token, so it may go in pair links. Prefer a separate `viewerToken`.
const link = await connectRelay(server, { url: relayUrl, token, sharedToken: true });
console.log(`daemon | relay link ${link.state.status}, hub = daemon_id: ${link.hub === server.daemon.id}`);
const offer = await server.pair({ role: "controller" }); // targets the registered relayThe viewer code does not change. The default transports try the record's direct URL first, then its relay.
const parsed = parsePairLink(offer.link);
console.log(`viewer | link targets: relay=${parsed.relayUrl !== undefined} direct=${parsed.directUrl !== undefined}`);
const identity = await createIdentity({ privateKey: new Uint8Array(32).fill(9) });
const store = memoryPairedDaemonStore();
const paired = await pair(offer.link, { identity, store, name: "phone" });
console.log(`viewer | paired with ${paired.daemon.name} as ${paired.role} via ${paired.via}`);
paired.close();
// Later: session mode from the stored record (relay URL and viewer token included).
const states: ConnectionState["status"][] = [];
const client = await connect(paired.daemon.id, { identity, store, onState: (s) => states.push(s.status) });
const session = await client.startSession({ runner: "agent", cwd: os.tmpdir(), prompt: "hello" });
for await (const event of session.events()) {
if (event.type === "message") console.log(`viewer | ${event.role}: ${event.content}`);
if (event.type === "status") console.log(`viewer | status ${event.status}`);
}
console.log(`viewer | connection ${states.join(" -> ")} via ${client.via}`);The relay token is an operator credential that decides who may use the relay at all. It grants no access to any daemon: only a paired key does.
The example uses the in-process stand-in by default. To run it against a real relay that admits daemons and viewers with one token, set both variables; the stand-in is skipped and pairing and streaming are checked the same way:
VIEWPORT_RELAY_URL=ws://127.0.0.1:7072 VIEWPORT_RELAY_TOKEN="$TOKEN" \
corepack pnpm exec tsx --tsconfig examples/tsconfig.json examples/ts/pair-relay/main.tsRevoking
server.revoke(peerId) (the peers.revoke request) removes the peer and closes its channels. A peer can remove
itself with peer.leave. There is nothing else to expire: every connection proves its key again.
Refusals are advisory
Before the handshake completes, anyone on the path can send a reject frame or a close reason. The client reports
all of them as channel.rejected, with the claimed code in details.reject. Show it and retry with backoff. Never
forget a daemon or delete keys because of one.