Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/pr-1457-agentic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@agentproto/secrets": major
"@agentproto/pair-client": minor
"@agentproto/runtime": minor
"@agentproto/cli": minor
---

Widen the daemon identity fingerprint from 64 to 128 bits and default `pairing.pairPage` to the new per-daemon `{fingerprint}.agentproto.cloud` pair page (`DEFAULT_PAIR_PAGE`); offer URLs now require the 32-hex fingerprint id.
49 changes: 28 additions & 21 deletions docs/cli/concepts/pairing.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ A daemon's persistent identity, stored `~/.agentproto/identity.json` (mode
- an **Ed25519** keypair for authenticity (the daemon signs the handshake
transcript so the client can prove it reached the daemon it scanned).

The **fingerprint** is `sha256(x25519 pub)[:16]` — the same construction as a
seal key id — and is what a human confirms at offer and accept time.
The **fingerprint** is the first 32 lowercase hex chars (128 bits) of
`sha256(x25519 pub)`, and is what a human confirms at offer and accept time.
It also names the daemon's browser origin (`<fingerprint>.agentproto.cloud`),
so it is sized so nobody can grind a key whose fingerprint lands on another
daemon's origin. A seal key id is its first 16 hex chars.

### 2. Handshake — `pair/v2` (`@agentproto/secrets/pairing`)

Expand Down Expand Up @@ -156,7 +159,7 @@ rate limiting, single-use tokens, constant-time token compare. Self-hostable via
handshake, pins the daemon's keys, and persists the pairing.
- `pair offer --qr` shows the same offer as a phone link: the web pair page
with the offer in its URL fragment
(`https://cli.agentproto.sh/pair#v=2&rv=…`). A fragment never reaches a
(`https://<fingerprint>.agentproto.cloud/pair#v=2&rv=…`). A fragment never reaches a
server. The page runs the client handshake in the browser with
`@agentproto/pair-client` (WebCrypto, WebSocket, IndexedDB), which speaks
the same wire protocol as `pair accept`, so the daemon can't tell the two
Expand Down Expand Up @@ -270,33 +273,37 @@ all of that to the page's **origin**. If every daemon's pages shared one
origin, a script on that origin could read every pairing's credential and
reach every daemon's UI, and a bug in one daemon's app would reach the others.

So the page setting takes a template with `{fp}` in the hostname, filled with
the daemon's identity fingerprint:
So the pair page is a template with `{fp}` in the hostname, filled with the
daemon's identity fingerprint. The default is:

```text
https://{fp}.agentproto.cloud/pair → https://a1b2c3d4e5f60718.agentproto.cloud/pair#v=2&…
https://{fp}.agentproto.cloud/pair → https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#v=2&…
```

Each daemon then gets its own origin. The browser keeps its credential,
storage, service worker and UI apart from every other pairing, with no shared
state to leak.
- Rules: `{fp}` is only allowed in the hostname. The fingerprint must be a
valid DNS label (it's 16 lowercase hex chars).
- The page checks it's on the right origin with
`expectedPairHost(template, fingerprint)`, compared against
`location.host`, and refuses an offer meant for another daemon.
- **The default is still** `https://cli.agentproto.sh/pair`. The per-daemon
domain (`PAIR_WEB_URL_TEMPLATE_CLOUD`, `https://{fp}.agentproto.cloud/pair`)
becomes the default once its DNS is live. Until then, opt in with
`pairing.pairPage` in `config.json` or `pair offer --qr --pair-page <…>`
(the flag wins).

**Self-hosting the pair page.** The page is a static bundle (no server-side
code, and the offer stays in the URL fragment). Serve it from your own host and
point `pairing.pairPage` at it:
- a single origin, `"https://pair.example.com/pair"`, or
valid DNS label (it's 32 lowercase hex chars).
- The page refuses an offer whose daemon fingerprint isn't its own origin's
first label, before any network I/O, and stores only that daemon's
credential (AIP-59 §5.8). `expectedPairHost(template, fingerprint)` gives a
page the host to compare with `location.host`.
- **The default is** `https://{fp}.agentproto.cloud/pair`
(`PAIR_WEB_URL_TEMPLATE_CLOUD`): one static page (`packages/pair-page`)
served on every `<fingerprint>.agentproto.cloud` by a Cloudflare Worker,
which answers 404 for any host whose first label isn't a fingerprint.
Change it with `pairing.pairPage` in `config.json` or
`pair offer --qr --pair-page <…>` (the flag wins).

**Self-hosting the pair page.** The page is a static bundle
(`packages/pair-page`: no server-side code, and the offer stays in the URL
fragment). Serve it from your own host and point `pairing.pairPage` at it:
- one origin per daemon, `"https://{fp}.pair.example.com/pair"`, which needs a
wildcard DNS record and TLS certificate.
wildcard DNS record and TLS certificate (recommended), or
- a single shared origin, `"https://pair.example.com/pair"`. Every paired
daemon's UI then shares that origin with every other pairing's credential
(AIP-59 §5.8), so tell your users.

The page only needs to reach the rendezvous broker named in the offer.

Expand Down
9 changes: 5 additions & 4 deletions docs/cli/reference/config-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ agentproto config set daemon.port 18791
// Mirrors tunnel.autoconnect. Default true when a rendezvous is set.
"autoconnect": true,
// Web pair page for `pair offer --qr` (the offer rides in its URL
// fragment). A plain http(s) URL, or a template with {fp} in the HOSTNAME
// (the daemon fingerprint) for one browser origin per daemon.
// Absent → https://cli.agentproto.sh/pair. `--pair-page` overrides it.
// fragment). A template with {fp} in the HOSTNAME (the daemon
// fingerprint) for one browser origin per daemon, or a plain http(s) URL
// (one shared origin). Absent → https://{fp}.agentproto.cloud/pair.
// `--pair-page` overrides it.
// See concepts/pairing.md ("The phone pair page").
"pairPage": "https://{fp}.agentproto.cloud/pair"
"pairPage": "https://{fp}.pair.example.com/pair"
},

// Global and per-adapter defaults auto-applied to every `agent_start`
Expand Down
34 changes: 18 additions & 16 deletions docs/cli/verbs/pair.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ agentproto pair offer
```

```text
Pairing offer (daemon a1b2c3d4e5f60718) — expires 2026-07-13T19:20:00.000Z
Pairing offer (daemon a1b2c3d4e5f607189c3e5d7f1a2b4c6d) — expires 2026-07-13T19:20:00.000Z

agentproto://pair?v=2&rv=…&id=a1b2c3d4e5f60718&pk=…&sk=…&s=…&exp=…
agentproto://pair?v=2&rv=…&id=a1b2c3d4e5f607189c3e5d7f1a2b4c6d&pk=…&sk=…&s=…&exp=…

█▀▀▀▀▀█ ▀▀ █ █▀▀▀▀▀█ (QR of the URL — omit with --no-qr)
…
Expand All @@ -65,27 +65,29 @@ This window can close.
- `--no-qr` prints the URL only (also the fallback when the optional
`qrcode-terminal` renderer isn't installed).
- `--qr` pairs a **phone browser** instead of another CLI: it prints, and draws
as the QR, the web pair page with the offer in its fragment —
`https://cli.agentproto.sh/pair#v=2&rv=…&id=…&pk=…&sk=…&s=…&exp=…` (the query
string of the `agentproto://` URL, verbatim, after the `#`). A URL fragment
as the QR, the web pair page with the offer in its fragment. By default
that page is the daemon's own origin,
`https://<fingerprint>.agentproto.cloud/pair#v=2&rv=…&id=…&pk=…&sk=…&s=…&exp=…`
(the query string of the `agentproto://` URL, verbatim, after the `#`). A URL fragment
is never sent to a server, so the page's host never sees the token. The page
runs the same handshake in the browser (`@agentproto/pair-client`) and shows
the daemon's name and fingerprint to confirm. The `agentproto://` URL is still
printed for `pair accept`, and either form is accepted by both clients.
- `--pair-page <url|template>` (with `--qr`) picks the pair page for this
offer. It overrides `pairing.pairPage` in config, and the default is
`https://cli.agentproto.sh/pair`. It accepts two forms:
- A **plain URL**, used as is, e.g. a local `http://localhost:3000/pair`.
`https://{fp}.agentproto.cloud/pair`. It accepts two forms:
- A **template** with `{fp}` in the **hostname**, filled with the daemon's
identity fingerprint (lowercase hex):
identity fingerprint (lowercase hex), e.g. a self-hosted page:

```bash
agentproto pair offer --qr --pair-page 'https://{fp}.agentproto.cloud/pair'
# → https://a1b2c3d4e5f60718.agentproto.cloud/pair#v=2&…
agentproto pair offer --qr --pair-page 'https://{fp}.pair.example.com/pair'
# → https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.pair.example.com/pair#v=2&…
```

That gives each daemon its own browser origin (see
That gives each daemon its own browser origin, like the default (see
[concepts/pairing.md](../concepts/pairing.md#the-phone-pair-page-one-origin-per-daemon)).
- A **plain URL**, used as is, e.g. a local `http://localhost:3000/pair`.
Every daemon paired through it shares one origin.
`{fp}` anywhere else (path, query, port, userinfo) is rejected, as is any
other `{…}`. The page setting is checked before the offer is minted.
- `--json` emits `{ url, fingerprint, rendezvous, rendezvousIsHostedDefault,
Expand All @@ -97,18 +99,18 @@ agentproto pair offer --qr
```

```text
Pairing offer (daemon a1b2c3d4e5f60718) — expires 2026-07-13T19:20:00.000Z
Pairing offer (daemon a1b2c3d4e5f607189c3e5d7f1a2b4c6d) — expires 2026-07-13T19:20:00.000Z

agentproto://pair?v=2&rv=…&id=a1b2c3d4e5f60718&pk=…&sk=…&s=…&exp=…
agentproto://pair?v=2&rv=…&id=a1b2c3d4e5f607189c3e5d7f1a2b4c6d&pk=…&sk=…&s=…&exp=…

Scan with a phone (opens the pair page in the browser):

https://cli.agentproto.sh/pair#v=2&rv=…&id=a1b2c3d4e5f60718&pk=…&sk=…&s=…&exp=…
https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#v=2&rv=…&id=a1b2c3d4e5f607189c3e5d7f1a2b4c6d&pk=…&sk=…&s=…&exp=…

█▀▀▀▀▀█ ▀▀ █ █▀▀▀▀▀█ (QR of the pair-page link)
…

Confirm the page shows daemon a1b2c3d4e5f60718 before you accept.
Confirm the page shows daemon a1b2c3d4e5f607189c3e5d7f1a2b4c6d before you accept.

**Routing precedence:** `--rendezvous` → `pairing.rendezvous` in config → the
hosted default. To point elsewhere, self-host the broker
Expand All @@ -133,7 +135,7 @@ agentproto pair accept "agentproto://pair?v=2&…" --name my-laptop
```

```text
✓ Paired with daemon a1b2c3d4e5f60718
✓ Paired with daemon a1b2c3d4e5f607189c3e5d7f1a2b4c6d
name: my-laptop
rendezvous: wss://rendezvous.example/v1

Expand Down
21 changes: 13 additions & 8 deletions packages/cli/src/__tests__/pair-offer-qr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const { loadConfig } = await import("@agentproto/runtime/config")
const config = vi.mocked(loadConfig)

const OFFER =
"agentproto://pair?v=2&rv=wss%3A%2F%2Frdv.agentproto.sh%2Fv1&id=a1b2c3d4e5f60718&pk=AAA&sk=BBB&s=sec_ret-1&exp=1900000000"
"agentproto://pair?v=2&rv=wss%3A%2F%2Frdv.agentproto.sh%2Fv1&id=a1b2c3d4e5f607189c3e5d7f1a2b4c6d&pk=AAA&sk=BBB&s=sec_ret-1&exp=1900000000"
const QUERY = OFFER.slice(OFFER.indexOf("?") + 1)

describe("agentproto pair offer --qr", () => {
Expand All @@ -47,7 +47,7 @@ describe("agentproto pair offer --qr", () => {
discoverDaemon.mockResolvedValue({ found: { url: "http://127.0.0.1:18790", token: "tok" }, stale: [] })
httpPostJson.mockResolvedValue({
url: OFFER,
fingerprint: "a1b2c3d4e5f60718",
fingerprint: "a1b2c3d4e5f607189c3e5d7f1a2b4c6d",
rendezvous: "wss://rdv.agentproto.sh/v1",
rendezvousIsHostedDefault: true,
expiresAt: "2030-03-17T17:46:40.000Z",
Expand All @@ -59,13 +59,14 @@ describe("agentproto pair offer --qr", () => {

it("renders the web pair page with the offer in the fragment", async () => {
expect(await runPair(["offer", "--qr"])).toBe(0)
const web = `https://cli.agentproto.sh/pair#${QUERY}`
// Default: the daemon's own origin on agentproto.cloud (AIP-59 §5.8).
const web = `https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#${QUERY}`
expect(qr).toHaveBeenCalledTimes(1)
expect(qr).toHaveBeenCalledWith(web)
const text = out.join("")
expect(text).toContain(web)
expect(text).toContain(OFFER) // the CLI form is still printed
expect(text).toContain("a1b2c3d4e5f60718")
expect(text).toContain("a1b2c3d4e5f607189c3e5d7f1a2b4c6d")
})

it("--pair-page points the link at another page; --json adds webUrl", async () => {
Expand All @@ -79,7 +80,7 @@ describe("agentproto pair offer --qr", () => {
it("without --qr, the offer and its QR are unchanged", async () => {
expect(await runPair(["offer"])).toBe(0)
expect(qr).toHaveBeenCalledWith(OFFER)
expect(out.join("")).not.toContain("cli.agentproto.sh")
expect(out.join("")).not.toContain("/pair#")

out.length = 0
expect(await runPair(["offer", "--json"])).toBe(0)
Expand All @@ -95,13 +96,13 @@ describe("agentproto pair offer --qr", () => {

it("--pair-page takes a {fp} template: one origin per daemon", async () => {
expect(await runPair(["offer", "--qr", "--pair-page", "https://{fp}.agentproto.cloud/pair", "--json"])).toBe(0)
expect(JSON.parse(out.join("")).webUrl).toBe(`https://a1b2c3d4e5f60718.agentproto.cloud/pair#${QUERY}`)
expect(JSON.parse(out.join("")).webUrl).toBe(`https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#${QUERY}`)
})

it("config pairing.pairPage is used with --qr, and --pair-page overrides it", async () => {
config.mockResolvedValue({ pairing: { pairPage: "https://{fp}.agentproto.cloud/pair" } })
expect(await runPair(["offer", "--qr"])).toBe(0)
expect(qr).toHaveBeenCalledWith(`https://a1b2c3d4e5f60718.agentproto.cloud/pair#${QUERY}`)
expect(qr).toHaveBeenCalledWith(`https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#${QUERY}`)

qr.mockClear()
expect(await runPair(["offer", "--qr", "--pair-page", "https://pair.example.com/pair"])).toBe(0)
Expand All @@ -128,8 +129,12 @@ describe("agentproto pair offer --qr", () => {
expect(httpPostJson).not.toHaveBeenCalled()
})

it("the default page is unchanged", async () => {
it("defaults to the per-daemon page; a plain URL still selects one shared page", async () => {
expect(await runPair(["offer", "--qr", "--json"])).toBe(0)
expect(JSON.parse(out.join("")).webUrl).toBe(`https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#${QUERY}`)

out.length = 0
expect(await runPair(["offer", "--qr", "--json", "--pair-page", "https://cli.agentproto.sh/pair"])).toBe(0)
expect(JSON.parse(out.join("")).webUrl).toBe(`https://cli.agentproto.sh/pair#${QUERY}`)
})
})
24 changes: 12 additions & 12 deletions packages/cli/src/commands/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* offer [--ttl 10m] [--rendezvous wss://…] [--no-qr | --qr [--pair-page <url|template>]]
* daemon side: mint an offer URL (+ QR) and start listening on the
* rendezvous. `--qr` renders the phone link instead: the web pair page
* with the offer in its fragment (`https://cli.agentproto.sh/pair#…`).
* with the offer in its fragment (`https://<fp>.agentproto.cloud/pair#…`).
* accept "<offer-url>" [--name <label>] client side: verify +
* persist the pairing.
* ls [--json] list pairings (daemon
Expand Down Expand Up @@ -37,7 +37,7 @@ import {
findClientPairing,
} from "../util/client-pairings.js"
import { printQr } from "../util/qr.js"
import { encodeOfferWebUrl, PAIR_WEB_URL, resolvePairPageUrl } from "@agentproto/secrets/pairing"
import { DEFAULT_PAIR_PAGE, encodeOfferWebUrl, resolvePairPageUrl } from "@agentproto/secrets/pairing"
import { loadConfig } from "@agentproto/runtime/config"

const USAGE = `agentproto pair — end-to-end daemon pairing over an untrusted rendezvous
Expand All @@ -53,11 +53,11 @@ Usage:
offer Daemon side: mint a single-use offer URL (+ QR) and start listening on
the rendezvous. Share the URL with the client; it carries the daemon's
public keys (MITM-proof) and a short-lived secret. --qr shows a QR
for a phone browser instead: ${PAIR_WEB_URL}#<offer>
(the offer rides in the fragment, never sent to a server).
--pair-page (or config pairing.pairPage) picks another page: a URL,
or a template with {fp} in the host for one origin per daemon,
e.g. https://{fp}.agentproto.cloud/pair.
for a phone browser instead: ${DEFAULT_PAIR_PAGE}#<offer>
({fp} = the daemon fingerprint: one browser origin per daemon; the
offer rides in the fragment, never sent to a server).
--pair-page (or config pairing.pairPage) picks another page: a
template with {fp} in the host, or a plain URL (one shared origin).
accept Client side: verify the daemon's identity from the URL and persist the
pairing to ~/.agentproto/pair-credentials.json.
ls List pairings. Uses the daemon's REST route when reachable; otherwise
Expand Down Expand Up @@ -123,11 +123,11 @@ async function runOffer(args: readonly string[]): Promise<number> {
}
// The pair page: --pair-page, else config pairing.pairPage, else the default.
// Checked BEFORE minting, so a bad template never spends an offer.
let pairPage: string = PAIR_WEB_URL
let pairPage: string = DEFAULT_PAIR_PAGE
if (values.qr) {
try {
pairPage = values["pair-page"] ?? (await loadConfig()).pairing?.pairPage ?? PAIR_WEB_URL
resolvePairPageUrl(pairPage, "0".repeat(16))
pairPage = values["pair-page"] ?? (await loadConfig()).pairing?.pairPage ?? DEFAULT_PAIR_PAGE
resolvePairPageUrl(pairPage, "0".repeat(32))
} catch (err) {
process.stderr.write(
`agentproto pair offer: ${values["pair-page"] ? "--pair-page" : "pairing.pairPage"}: ` +
Expand Down Expand Up @@ -309,11 +309,11 @@ async function runLs(args: readonly string[]): Promise<number> {
}
process.stdout.write(
`${source === "client" ? "(client-side — no daemon reachable)\n" : ""}` +
`${"NAME".padEnd(20)} ${"FINGERPRINT".padEnd(18)} ${"LAST SEEN".padEnd(22)} RENDEZVOUS\n`,
`${"NAME".padEnd(20)} ${"FINGERPRINT".padEnd(32)} ${"LAST SEEN".padEnd(22)} RENDEZVOUS\n`,
)
for (const p of rows) {
process.stdout.write(
`${(p.name ?? "").slice(0, 20).padEnd(20)} ${p.fingerprint.padEnd(18)} ${(p.lastSeen ?? "").padEnd(22)} ${p.rendezvous ?? ""}${p.legacy ? " [legacy: re-pair]" : ""}\n`,
`${(p.name ?? "").slice(0, 20).padEnd(20)} ${p.fingerprint.padEnd(32)} ${(p.lastSeen ?? "").padEnd(22)} ${p.rendezvous ?? ""}${p.legacy ? " [legacy: re-pair]" : ""}\n`,
)
}
if (rows.some(p => p.legacy)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/util/client-pairings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { homedir } from "node:os"
import { join, dirname } from "node:path"

export interface ClientPairing {
/** Daemon identity fingerprint (16 hex) — the pin. */
/** Daemon identity fingerprint (32 hex) — the pin. */
fingerprint: string
/** Human label the user gave this pairing (defaults to the daemon fingerprint). */
name: string
Expand Down
Loading
Loading