Skip to content

feat(openclaw-id): add protocol contracts package - #191469

Merged
jalehman merged 9 commits into
mainfrom
openclaw-id/pr-protocol
Nov 3, 2026
Merged

jalehman merged 9 commits into
mainfrom
openclaw-id/pr-protocol

Conversation

@jalehman

@jalehman jalehman commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

OpenClaw ID (remote access to a Gateway through an OpenClaw ID account) needs one shared definition of its wire protocol that the Gateway, the Control UI and the People plugin can all use. This draft adds that definition as its own package, so it can be reviewed apart from the code that uses it.

User Impact

No user-visible change. Nothing imports the package yet. Later PRs in this stack wire it into the Gateway, the Control UI and the People plugin, behind an OpenClaw ID Labs switch that is off by default.

Why This Change Was Made

packages/openclaw-id-protocol holds the v1-draft protocol contracts as pure TypeScript with no Node built-ins (a test enforces this), so browser and Gateway code can share it:

  • signed statements and the JCS (RFC 8785) canonical form they sign;
  • authority state: applying statements and checking validity;
  • the per-claw allowlist: each claw lists its current owner devices (with who approved each and the capabilities it was granted) and members, with no certificate chains and no revocation list; removing a device also removes the devices it approved, unused keys are dropped after 90 days (owner devices) or 30 days (member browsers), and each claw keeps at most 20 owner devices, 50 members and 5 browsers per member;
  • granted capabilities: an owner device may grant only capabilities it holds (caps_escalation otherwise), re-adding a listed device through an owner device cannot raise its capabilities, and only R may grant anything; the K_gw-signed MembershipSnapshot lists owner_devices as { device_pub, caps }, so readers outside the claw (Discovery) take an owner device's capabilities from the snapshot, not from a certificate a browser presents;
  • a fixed root: a claw's recovery-kit root R never changes. There is no root rotation, owner-key regeneration, root epoch or frozen state; root_epoch stays on the wire as the constant 1 so statements signed earlier still verify (any other value is malformed), descriptors carry no rotations, and a client pin accepts a binding only from the pinned root with a binding_seq that does not go back. Owner reset was removed from this PR (see below);
  • discovery, mailbox and device-mail payloads;
  • enrollment, invite links, recovery kits and SAS approval;
  • tunnel framing;
  • the v1-draft acceptance catalog and its statement vectors.

The specs are in packages/openclaw-id-protocol/docs/.

The only other changes are wiring: tsconfig paths, Vitest source aliases, the pnpm lockfile importer entry, and a raise of the test-line baseline (see Test-line baseline below).

This is the first PR of a stack. The next PRs add the iroh Node binding, Gateway authority and publication, the tunnel child and admission, the Gateway security-boundary changes, the Control UI, the People plugin, and docs.

Owner reset: removed here, redesigned later

Removed: the RootRotation statement, owner-key regeneration, root epochs and the frozen state.

Why: a new owner-reset design replaces them, and the old mechanism never worked end to end: after a reset, the republish under the new root was rejected.

What the new design adds back to this package later:

  • a RootReset statement signed by the Gateway key (K_gw);
  • a Discovery rule that accepts a root change only with a valid K_gw signature from the claw's current binding;
  • a loader rule that shows "access was reset" instead of the impostor warning.

Why later: its security rests on facts only the Gateway can establish: only that machine holds K_gw, and the request arrived over local loopback. So it lands with the Gateway PR, where it can be proven live: a reset succeeds locally and is refused over the tunnel.

Until then: there is no owner reset. A lost recovery kit means unlinking and relinking the claw.

Evidence

  • pnpm test packages/openclaw-id-protocol: 19 files, 129 tests passed. Fixed root: a RootRotation statement or a root_epoch other than 1 is malformed, another root's signature is not_an_owner, and a binding from another root fails the pin with root_mismatch (acceptance test 9 and a new pin vector). Second-review regressions (each fails on the head before them): a MembershipChange op of __proto__, constructor, toString or hasOwnProperty is malformed instead of throwing; an undeclared constructor field (including one holding a lone surrogate) is malformed; re-adding an owner device whose certificate replaces [W1] with [W2] disconnects and invalidates W1. Granted caps: an owner device cannot grant caps it lacks, a re-add cannot escalate, R may grant any caps, and the snapshot round-trips owner devices with their caps (unknown caps are malformed). Earlier: one regression test per remaining first-review finding: a noncanonical request signature returns unauthorized instead of throwing; lone surrogates are malformed; removing an owner device tears down its tunnel key W when W differs from D (test fixtures now use distinct D and W); a deeply nested chain member is refused at the top level. (The first-review freeze fix for invite registration and the second-review repinRoot teardown went away with owner reset.)
  • pnpm check:changed --base origin/main: every check passed except lint. Lint fails only on max-lines in six files this PR does not touch; those files already exceed the limit on main. No findings in packages/openclaw-id-protocol.
  • pnpm tsgo:core passed and oxlint --type-aware reports no findings in the package. pnpm check:assertion-safety --base origin/main passed: the remaining type assertions in the package have // SAFETY: comments, and the ones that were not needed were removed. The type error in validity.test.ts was also fixed.
  • pnpm check:test-lines-ratchet: passes with the baseline raise below (slack 0 at the time of the rebase).
  • pnpm tsgo:test:packages: no errors in packages/openclaw-id-protocol (the package's own test files now typecheck, including authority/validity.test.ts).
  • pnpm install --frozen-lockfile: lockfile accepted.
  • Local review: not run for this draft (maintainer decision); request review once marked ready.

Behavior proof

From the staging testnet on 2026-11-02 and 2026-11-03 (UTC). The lab Gateways now run this protocol package (openclaw 1bc84010c2e; the first two items were recorded on 80343b56535, the capabilities item on ab79a959ae4), and the evidence comes from real browsers going through the relay. Keys are shown as fp: prefixes only; the browsers are disposable test browsers.

  • A foreign peer is refused before any Gateway I/O. After the owner removed two browsers, both reconnected through the relay. The tunnel child refused each one at connection setup (tunnel: admission rejected: peer=fp:45adc476 and peer=fp:a68c5810, 23:26:00). It logged no later HTTP or WebSocket line for either peer, and both loaders showed not_admitted. Discovery's relay admission (POST /iroh/admit) returned false for both keys and true for the remaining owner device and the claw's server key.
  • A removed owner device's open connection is closed and its tokens are invalidated. Browser A was enrolled with the recovery kit; browser B was approved by A over SAS. The owner removed A from Your devices, and the confirmation named B as removed with it. The Gateway then logged tunnel: peer removed: peer=fp:45adc476 closed_conns=1 and peer=fp:a68c5810 closed_conns=1, and closed both Control UI sessions with code=1008 reason=removed from this claw. devices list on the Gateway host shows the operator tokens of both browsers revoked (6df7ee74…, ba06d8d9…). The claw's next published snapshot lists neither device and has no revoked field.
  • The same gate passed on a second lab claw, and the 21st owner device was refused with limit_reached on both.
  • Capabilities come from the signed snapshot. On ab79a959ae4 both lab claws migrated in place on restart (each owner device took its caps from its stored certificate) and republished. The allowlist gate passed on both: Discovery's snapshot verifies under K_gw and lists the saved owner browser in owner_devices with approve_device, bind, invite, manage_members, matching the Gateway. SAS approval (E approves N with E's granted caps) passed on both. Discovery's mailbox reader now refuses a certificate self-signed by D that claims approve_device when the snapshot grants D less (Discovery test suite).
  • The root is fixed. On 1bc84010c2e both lab claws migrated in place on restart (the stored root epoch, root history, rotations and freeze were dropped; nothing was relinked and the recovery kits are unchanged) and republished a descriptor without rotations. Discovery's migration removed its stored root epoch and stripped rotations from stored descriptors. Loaders on the new protocol (which refuse a descriptor carrying rotations) pinned the existing root, enrolled with the existing kits and connected on both claws; the allowlist and owner gates passed on both. Your devices offers no owner reset.

Test-line baseline

This PR raises config/test-lines-baseline.txt by 2,485 lines instead of adding an allocation file:

  • 2,092 lines are this package's tests. It is new surface area (a signed-statement protocol with authority rules and acceptance vectors), so its tests add to the total rather than replacing others.
  • 393 lines are main's existing overage at the time of the rebase: on main alone the check reports "over by 393". An allocation can't cover it, because allocation credit is capped at the lines a PR adds.

If main adds test lines before this lands, the check may need the raise adjusted again.

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR adds a private, browser-compatible package defining OpenClaw ID statements, membership authority, enrollment, discovery, and tunnel contracts.

Example: An owner removes browser A, which approved browser B.

  • Before: Main has no shared OpenClaw ID protocol package defining this removal.
  • After: The reference authority removes both browsers and returns disconnect, token-invalidation, and snapshot-publication events for the Gateway.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful contracts with supplied production-path authority evidence; the retained documentation defect and static-only tests prevent a higher patch rating.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied staging browser and relay diagnostics exercise allowed owner admission, rejection of removed peers before Gateway I/O, closure of existing sessions, token revocation, SAS approval, and restart with existing roots and kits intact; these support the package’s authority boundary without claiming every later integration scenario was exercised.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Future OpenClaw ID clients and Gateways need consistent remote-access contracts so they agree on identity, membership, enrollment, and transport.
Reason: The task identifies maintainer-approved direction, and this PR delivers the stated contract-only stage without activating remote access.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open as a useful foundation for OpenClaw ID; the previously reported ServerBinding documentation mismatch remains.

Priority: P2
Reviewed head: 79a0cbcfc55222575ebc1fb789b70bc0a885ddbb

Before merge

  • Document R as the sole ServerBinding signer (P3) - The Discovery table permits an owner device holding bind to sign ServerBinding, but verifyOwnerStatement returns wrong_signer for that binding even when the device is currently authorized. A consumer implementing this table would publish bindings clients reject. Change this cell to R only, matching statements.md and the verifier. This is the retained finding from the previous review of the same head.

Findings

  • [P3] Document R as the sole ServerBinding signer — packages/openclaw-id-protocol/docs/discovery.md:17

Tests

  • Low-value test packages/openclaw-id-protocol/src/acceptance/catalog.test.ts: Remove the copied catalog inventory and naming assertions: they can pass while every named integration scenario is absent or broken.
  • Low-value test packages/openclaw-id-protocol/src/discovery/mailbox.test.ts: Remove only 'lists seq_conflict among the notice events'; it asserts a static declaration already exercised by the notice validation and recipient tests.
Agent review details

How this fits together

The package accepts signed statements, discovery payloads, and tunnel bytes, then returns verified contracts, membership transitions, and codecs for later Gateway and browser integrations.

flowchart LR
  A[Owner and browser keys] --> B[Protocol contracts]
  C[Discovery payloads] --> B
  B --> D[Gateway membership authority]
  D --> E[Tunnel admission and removal]
  B --> F[Browser pin verification]
Loading

Technical review

Best possible solution:

Retain the shared private package and make Discovery’s ServerBinding signer contract consistently R-only.

Do we have a high-confidence way to reproduce the issue?

This is a new capability rather than a released bug report; source inspection confirms the retained documentation mismatch without executing target code.

Is this the best way to solve the issue?

A dependency-free shared contract package is a coherent first stage, with Gateway persistence and effects left to their existing owners.

Full review comments:

  • [P3] Document R as the sole ServerBinding signer — packages/openclaw-id-protocol/docs/discovery.md:17
    The Discovery table permits an owner device holding bind to sign ServerBinding, but verifyOwnerStatement returns wrong_signer for that binding even when the device is currently authorized. A consumer implementing this table would publish bindings clients reject. Change this cell to R only, matching statements.md and the verifier. This is the retained finding from the previous review of the same head.
    Confidence: 1

Overall correctness: patch is correct
Overall confidence: 0.92

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 29e1324fa337.

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • rg -n 'ServerBinding|R only|wrong_signer' packages/openclaw-id-protocol/docs/discovery.md packages/openclaw-id-protocol/docs/statements.md packages/openclaw-id-protocol/src/statements/verify.ts
  • git diff --check

What I checked:

PR surface

Source +5530, Tests +2094, Docs +844, Config +13, Other +4. Total +8485 across 69 files. Added test files: 19.

View PR surface stats
Area Files Added Removed Net
Source 39 5530 0 +5530
Tests 20 2094 0 +2094
Docs 6 844 0 +844
Config 2 13 0 +13
Generated 0 0 0 0
Other 2 4 0 +4
Total 69 8485 0 +8485

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a useful remote-access foundation with no production consumer yet and one limited documentation defect.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-02T21:42:13.065Z sha 4fbbce7 :: needs real behavior proof before merge. :: [P2] Disconnect owner peer keys when their fingerprints are revoked | [P2] Apply the root-write freeze when registering invites | [P2] Return unauthorized for noncanonical request signatures | [P2] Reject noncanonical Unicode at statement validation | [P2] Reject nested certificate chains before descending into them
  • reviewed 2026-11-03T02:44:08.826Z sha 0068d2a :: needs real behavior proof before merge. :: [P2] Restrict schema lookups to own properties | [P2] Tear down peer keys removed by owner-certificate replacement | [P2] End existing owner access when re-pinning the root | [P2] Update the validity tests to satisfy the authority types
  • reviewed 2026-11-03T05:33:10.255Z sha 79a0cbc :: needs changes before merge. :: [P3] Document R as the sole ServerBinding signer

Reviewed November 3, 2026, 12:40 AM ET / 05:40 UTC (Revision 4).

@jalehman
jalehman force-pushed the openclaw-id/pr-protocol branch 3 times, most recently from e79cc7d to 0068d2a Compare November 3, 2026 01:25
@jalehman

jalehman commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 3, 2026
@jalehman
jalehman force-pushed the openclaw-id/pr-protocol branch 3 times, most recently from 9133171 to 79a0cbc Compare November 3, 2026 04:40
@jalehman

jalehman commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 3, 2026
A claw's root never changes in this version; owner reset is redesigned
in a later PR (OCF-319). Removes the RootRotation statement, repinRoot,
regenerateOwnerKey, root epochs in anchors and pins, and the frozen
state. root_epoch stays on the wire as the constant 1 so existing signed
statements still verify. Descriptors carry no rotations.
Raises the baseline by 2,485: the package's 2,092 new test lines plus main's
existing 393-line overage at the time of this rebase.
@jalehman
jalehman force-pushed the openclaw-id/pr-protocol branch from 60283ab to 28fefdc Compare November 3, 2026 16:01
@jalehman
jalehman merged commit ed57ed7 into main Nov 3, 2026
142 of 146 checks passed
@jalehman
jalehman deleted the openclaw-id/pr-protocol branch November 3, 2026 16:37
@jalehman

jalehman commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 4, 2026
* feat(openclaw-id): add protocol contracts package

* refactor(openclaw-id): document or remove protocol type assertions

* feat(openclaw-id): per-claw allowlist protocol; address review findings

Replaces certificate chains and revocation lists with a per-claw allowlist:
statements signed by an owner device are checked against the claw's current
owner devices, revoking a device deletes it and every device it approved,
unused keys are dropped after 90/30 days, and snapshots carry current state
only. Also refuses root-signed invites while frozen, keeps untrusted
signatures and strings from throwing, and tears down an owner's tunnel key on
removal.

* feat(openclaw-id): carry granted owner-device caps in the signed snapshot

An owner device may grant only caps it holds (caps_escalation otherwise) and a
re-add through an owner device cannot raise a listed device's caps; R may grant
any. The Gateway records the granted caps, and MembershipSnapshot lists
owner_devices as { device_pub, caps }, so readers outside the claw take caps
from the K_gw-signed snapshot instead of a presented certificate.

* fix(openclaw-id): address second protocol review

Schema lookups use own properties only, so prototype-named variants and
undeclared constructor fields are malformed instead of throwing. Re-adding an
owner device with replacement peer keys tears down the dropped keys, and
repinRoot ends the earlier owner devices' sessions and tokens. Package tests
now typecheck.

* feat(openclaw-id): remove root rotation and owner-key regeneration

A claw's root never changes in this version; owner reset is redesigned
in a later PR (OCF-319). Removes the RootRotation statement, repinRoot,
regenerateOwnerKey, root epochs in anchors and pins, and the frozen
state. root_epoch stays on the wire as the constant 1 so existing signed
statements still verify. Descriptors carry no rotations.

* fix(openclaw-id): drop chained body assertion; document R as sole ServerBinding signer

* fix(openclaw-id): widen statement body without a type parameter

* chore(test-lines): raise baseline for the openclaw-id protocol package

Raises the baseline by 2,485: the package's 2,092 new test lines plus main's
existing 393-line overage at the time of this rebase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies-changed PR changes dependency-related files P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant