The zr-net invite link & pairing protocol
Link grammar, field semantics, rotate-key behavior, and Host pairing codes for zr-net://.
Link grammar
Every invite link the console generates uses one scheme:
zr-net://<host>[:<port>]/<networkId>[?tls=0|1][#<joinKey>]
| Field | Rules |
|---|---|
| <host> | Gateway address: domain or IP; default transport is inferred from it (see below) |
| <port> | Omitted means 19393; links behind standard-port proxies (443/80) carry an explicit :443/:80 so nodes do not fall back incorrectly; other ports pass through verbatim |
| <networkId> | Always 16 lowercase hex characters |
| ?tls=0|1 | Appears only when transport differs from the host’s inferred default: loopback, private IPv4 (10/8, 172.16/12, 192.168/16), link-local, IPv6 ULA, CGNAT/Tailscale (100.64/10), and .local/.lan names default to plaintext; public hosts default to TLS |
| #<joinKey> | One per network; fast-pass for first join under passphrase/combined admission; under approve-only admission it is unused and dropping #... still submits a join request |
Compatibility: nodes still read the legacy prefixes zr-net+insecure:// (= default plaintext) and zr-nets:// (= default TLS), but every new link outputs zr-net://.
rotate-key semantics & invite limits
POST /api/v1/networks/:id/rotate-key (network owner; see HTTP API reference):
- Invite links default to 168 hours (7 days, range 1–720) and 10 max uses (range 1–1000), customizable via inviteTtlHours and inviteMaxUses when creating a network or rotating the key.
- Mints a fresh join key immediately — every existing link carrying the old key is invalidated on the spot, and the expiry timer and use counter reset.
- Zero impact on already joined devices: member admission, sessions, and direct/relay paths remain intact.
- Use it for leaked, expired, or exhausted links, membership churn, or periodic key rotation via the console network settings.
Join & admission protocol
- Before handshake and admission, the node locally derives its nodeId (first 8 lowercase hex chars of sha256(ed25519PublicKey), i.e. 4 bytes) from its identity key.
- The node opens a WebSocket (/peer/v1/ws) to the gateway and proves key ownership: TLS follows the inference/explicit flag above, and a failed certificate check never downgrades to plaintext.
- Admission follows the network’s mode: valid passphrase → auto-admitted (authorized); approve-only → pending until POST /api/v1/networks/:id/members/:nodeId/approve; once admitted, the node enters discovery and path negotiation (direct first, re-probed at 3 s → 8 s → every 25 s).
Device pairing codes (Host side, separate from the join key)
Pairing codes and zr-net join keys are independent credentials: pairing codes bind “device ↔ one Host”, while join keys bind “node ↔ one virtual network”.
| Aspect | Desktop-client code | Phone/browser pairing |
|---|---|---|
| Shape | 8-character short code (CLI: host device pair --device-role desktop-client) | QR + 8-character short code (--device-role web) |
| Channel | Host’s local gateway (3088) | Same, exposed through an ingress path |
| Expiry | Revocation (host device revoke <id>|--all) or re-pairing | Same |