@agenticprimitives/contracts 1.0.0-alpha.4 → 1.0.0-alpha.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/AUDIT.md +330 -47
  2. package/README.md +56 -10
  3. package/deployments-base-sepolia.json +50 -0
  4. package/deployments-faithchain.json +75 -0
  5. package/deployments-hopechain.json +57 -0
  6. package/deployments-paymaster-anvil.json +1 -0
  7. package/deployments-registries-base-sepolia.json +1 -0
  8. package/deployments-registries-hopechain.json +1 -0
  9. package/dist/abi/AgentAccount.json +1827 -0
  10. package/dist/abi/AgentAccountFactory.json +545 -0
  11. package/dist/abi/AgentNameRegistry.json +51 -0
  12. package/dist/abi/AgentRegistryBase.json +652 -0
  13. package/dist/abi/AgenticGovernance.json +32 -0
  14. package/dist/abi/AgreementRegistry.json +427 -0
  15. package/dist/abi/ApprovedHashRegistry.json +47 -2
  16. package/dist/abi/AttestationRegistry.json +436 -0
  17. package/dist/abi/CallDataHashEnforcer.json +119 -0
  18. package/dist/abi/CustodyPolicy.json +1179 -0
  19. package/dist/abi/DelegationManager.json +656 -0
  20. package/dist/abi/DigestBindingEnforcer.json +251 -0
  21. package/dist/abi/EstateProjectionRegistry.json +293 -0
  22. package/dist/abi/GeoFeatureRegistry.json +625 -0
  23. package/dist/abi/IAgentAccount.json +262 -0
  24. package/dist/abi/IAgentAccountFactoryAccessor.json +15 -0
  25. package/dist/abi/IAgentAccountFactoryView.json +54 -0
  26. package/dist/abi/IAgentAccountPauseView.json +15 -0
  27. package/dist/abi/IAgenticPrimitivesAgentAccount.json +15 -0
  28. package/dist/abi/IApprovedHashRegistryView.json +26 -0
  29. package/dist/abi/IApprovedHashRegistryWrite.json +35 -0
  30. package/dist/abi/ICustodyPolicyAccountModuleView.json +31 -0
  31. package/dist/abi/ICustodyPolicyFactoryView.json +15 -0
  32. package/dist/abi/ICustodyPolicyPauseView.json +15 -0
  33. package/dist/abi/IDelegationManager.json +171 -0
  34. package/dist/abi/IERC7579HookLike.json +44 -0
  35. package/dist/abi/IERC7579ModuleLike.json +28 -0
  36. package/dist/abi/IPaymentReceiptRegistry.json +50 -0
  37. package/dist/abi/IRegistryMembershipPolicy.json +70 -0
  38. package/dist/abi/MockUSDC.json +621 -0
  39. package/dist/abi/PayloadClassesEnforcer.json +117 -0
  40. package/dist/abi/PaymentEnforcer.json +441 -0
  41. package/dist/abi/PaymentEscrow.json +324 -0
  42. package/dist/abi/PaymentReceiptRegistry.json +182 -0
  43. package/dist/abi/PermissionlessSubregistry.json +5 -0
  44. package/dist/abi/PricedSubregistry.json +869 -0
  45. package/dist/abi/QuorumEnforcer.json +311 -0
  46. package/dist/abi/ReceiptAnchorRegistry.json +153 -0
  47. package/dist/abi/SignatureSlotRecovery.json +88 -0
  48. package/dist/abi/SkillDefinitionRegistry.json +491 -0
  49. package/dist/abi/SmartAgentPaymaster.json +873 -0
  50. package/dist/abi/TreasurySpendPolicy.json +369 -0
  51. package/dist/abi/UniversalSignatureValidator.json +65 -0
  52. package/dist/abi/index.d.ts +38 -0
  53. package/dist/abi/index.js +38 -0
  54. package/dist/deployments/base-sepolia.d.ts +46 -0
  55. package/dist/deployments/base-sepolia.js +54 -0
  56. package/dist/deployments/faithchain.d.ts +55 -0
  57. package/dist/deployments/faithchain.js +79 -0
  58. package/dist/deployments/hopechain.d.ts +53 -0
  59. package/dist/deployments/hopechain.js +61 -0
  60. package/dist/deployments/index.d.ts +13 -0
  61. package/dist/deployments/index.js +28 -0
  62. package/dist/deployments/paymaster-anvil.d.ts +11 -0
  63. package/dist/deployments/paymaster-anvil.js +9 -0
  64. package/dist/deployments/registries-base-sepolia.d.ts +10 -0
  65. package/dist/deployments/registries-base-sepolia.js +8 -0
  66. package/dist/deployments/registries-hopechain.d.ts +10 -0
  67. package/dist/deployments/registries-hopechain.js +8 -0
  68. package/package.json +55 -8
  69. package/src/AgentAccount.sol +569 -38
  70. package/src/AgentAccountFactory.sol +157 -16
  71. package/src/ApprovedHashRegistry.sol +41 -6
  72. package/src/IAgentAccount.sol +23 -0
  73. package/src/SmartAgentPaymaster.sol +156 -12
  74. package/src/UniversalSignatureValidator.sol +3 -0
  75. package/src/agency/DelegationManager.sol +179 -0
  76. package/src/agency/IDelegationManager.sol +38 -0
  77. package/src/agreement/AgreementRegistry.sol +331 -0
  78. package/src/attestation/AttestationRegistry.sol +384 -0
  79. package/src/custody/CustodyPolicy.sol +263 -15
  80. package/src/custody/TreasurySpendPolicy.sol +166 -0
  81. package/src/enforcers/AllowedMethodsEnforcer.sol +6 -0
  82. package/src/enforcers/AllowedTargetsEnforcer.sol +6 -0
  83. package/src/enforcers/CallDataHashEnforcer.sol +61 -0
  84. package/src/enforcers/DigestBindingEnforcer.sol +107 -0
  85. package/src/enforcers/PayloadClassesEnforcer.sol +30 -0
  86. package/src/enforcers/PaymentEnforcer.sol +257 -0
  87. package/src/enforcers/QuorumEnforcer.sol +24 -1
  88. package/src/enforcers/TimestampEnforcer.sol +7 -0
  89. package/src/enforcers/ValueEnforcer.sol +6 -0
  90. package/src/geo/GeoFeatureRegistry.sol +197 -0
  91. package/src/governance/AgenticGovernance.sol +26 -4
  92. package/src/identity/AgentProfilePredicates.sol +23 -0
  93. package/src/libraries/SignatureSlotRecovery.sol +24 -7
  94. package/src/libraries/WebAuthnLib.sol +13 -0
  95. package/src/mocks/MockUSDC.sol +152 -0
  96. package/src/naming/AgentNamePredicates.sol +89 -0
  97. package/src/naming/AgentNameRegistry.sol +65 -18
  98. package/src/naming/AgentNameUniversalResolver.sol +1 -1
  99. package/src/naming/PermissionlessSubregistry.sol +19 -2
  100. package/src/naming/PricedSubregistry.sol +209 -0
  101. package/src/payments/PaymentEscrow.sol +164 -0
  102. package/src/payments/PaymentReceiptRegistry.sol +67 -0
  103. package/src/provenance/ReceiptAnchorRegistry.sol +55 -0
  104. package/src/registry/AgentRegistryBase.sol +313 -0
  105. package/src/registry/EstateProjectionRegistry.sol +109 -0
  106. package/src/registry/IRegistryMembershipPolicy.sol +30 -0
  107. package/src/relationships/AgentRelationship.sol +8 -0
  108. package/src/skills/SkillDefinitionRegistry.sol +187 -0
@@ -0,0 +1,67 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ /**
5
+ * @title PaymentReceiptRegistry
6
+ * @notice Trustless, queryable settlement log for x402 pay-per-use (spec 272, PAY-CON-4 / X402-D9.3).
7
+ * Only the authorized {PaymentEnforcer} may `record` — a receipt is a byproduct of a gated
8
+ * `DelegationManager.redeemDelegation`, so a service cannot fabricate one and the reader's
9
+ * charge history needs no trust in service logs.
10
+ *
11
+ * @dev HASHES + ADDRESSES ONLY — no URLs, queries, licensed text, or passage refs ever reach the
12
+ * chain (PAY-WIRE-6). Event-only (no per-row storage): apps read settlements via an indexer /
13
+ * app cache, never inline `eth_getLogs` in product hot paths (ADR-0012). The
14
+ * `PaymentEnforcer.PaymentCharged` event is the primary on-chain receipt; `PaymentSettled`
15
+ * here adds payer/payee/mandateId-indexed querying for treasury views.
16
+ */
17
+ contract PaymentReceiptRegistry {
18
+ /// @notice The deployer who wires the sole authorized recorder once.
19
+ address public immutable owner;
20
+ /// @notice The single PaymentEnforcer permitted to `record` (set once via {setEnforcer}).
21
+ address public enforcer;
22
+
23
+ event PaymentSettled(
24
+ bytes32 indexed mandateId,
25
+ address indexed payer,
26
+ address indexed payee,
27
+ address asset,
28
+ uint256 amount,
29
+ bytes32 resourceHash,
30
+ bytes32 delegationHash,
31
+ bytes32 nonce
32
+ );
33
+ event EnforcerSet(address indexed enforcer);
34
+
35
+ error NotOwner();
36
+ error NotEnforcer();
37
+ error EnforcerAlreadySet();
38
+ error ZeroAddress();
39
+
40
+ constructor() {
41
+ owner = msg.sender;
42
+ }
43
+
44
+ /// @notice One-time wiring: authorize the deployed {PaymentEnforcer} as the sole recorder.
45
+ function setEnforcer(address enforcer_) external {
46
+ if (msg.sender != owner) revert NotOwner();
47
+ if (enforcer != address(0)) revert EnforcerAlreadySet();
48
+ if (enforcer_ == address(0)) revert ZeroAddress();
49
+ enforcer = enforcer_;
50
+ emit EnforcerSet(enforcer_);
51
+ }
52
+
53
+ /// @notice Record a settled payment. Reverts unless called by the authorized enforcer.
54
+ function record(
55
+ bytes32 mandateId,
56
+ address payer,
57
+ address payee,
58
+ address asset,
59
+ uint256 amount,
60
+ bytes32 resourceHash,
61
+ bytes32 delegationHash,
62
+ bytes32 nonce
63
+ ) external {
64
+ if (msg.sender != enforcer) revert NotEnforcer();
65
+ emit PaymentSettled(mandateId, payer, payee, asset, amount, resourceHash, delegationHash, nonce);
66
+ }
67
+ }
@@ -0,0 +1,55 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ /**
5
+ * @title ReceiptAnchorRegistry
6
+ * @notice The on-chain ANCHOR for a harness receipt (spec 351 P0.6, spec 406 W2): a run's record digest, bound
7
+ * to the intent digest the mandate was over and the mandate's reference, anchored once by the acting
8
+ * runtime's agent. A counterparty who holds the record recomputes its digest and reads the anchor here —
9
+ * no trust in the runtime's logs, no vendor, no vault: the chain says a runtime with THIS agent's key
10
+ * committed to THESE bytes at THIS block, and the intent digest says which ask it was under.
11
+ *
12
+ * @dev DIGESTS AND ADDRESSES ONLY — nothing of what the run was about reaches the chain (the S1 firewall of
13
+ * spec 395 holds by construction). Per-row storage, so a reader uses `readContract` (ADR-0012: no log
14
+ * walks in product paths); the event is for indexers. Anchoring is permissionless: WHO anchored is the
15
+ * evidence (`anchoredBy`), never a gate — a stranger anchoring random digests proves nothing about a
16
+ * run whose receipt names a different agent. A digest anchors ONCE PER ANCHORER (R917-C-3, spec 408
17
+ * §1.5): rows are keyed by `(anchoredBy, receiptDigest)`, so a front-runner on a public mempool cannot
18
+ * squat the digest ahead of the agent, and an anchor cannot be re-attributed after the fact.
19
+ */
20
+ contract ReceiptAnchorRegistry {
21
+ struct Anchor {
22
+ address anchoredBy;
23
+ uint64 at;
24
+ bytes32 intentDigest;
25
+ bytes32 mandateRef;
26
+ }
27
+
28
+ /// anchoredBy => receiptDigest => anchor (R917-C-3: keyed by WHO anchored, so a stranger's anchor of
29
+ /// the same digest is a different row — it can neither pre-empt the agent's nor be mistaken for it).
30
+ mapping(address => mapping(bytes32 => Anchor)) private _anchors;
31
+
32
+ event ReceiptAnchored(bytes32 indexed receiptDigest, address indexed anchoredBy, bytes32 indexed intentDigest, bytes32 mandateRef, uint64 at);
33
+
34
+ error ZeroDigest();
35
+ error AlreadyAnchored(bytes32 receiptDigest, address by);
36
+
37
+ /// @notice Anchor a receipt digest, once per anchorer. `intentDigest` and `mandateRef` may be zero for a run under no mandate (a read).
38
+ function anchor(bytes32 receiptDigest, bytes32 intentDigest, bytes32 mandateRef) external {
39
+ if (receiptDigest == bytes32(0)) revert ZeroDigest();
40
+ Anchor storage a = _anchors[msg.sender][receiptDigest];
41
+ if (a.anchoredBy != address(0)) revert AlreadyAnchored(receiptDigest, a.anchoredBy);
42
+ _anchors[msg.sender][receiptDigest] = Anchor({ anchoredBy: msg.sender, at: uint64(block.timestamp), intentDigest: intentDigest, mandateRef: mandateRef });
43
+ emit ReceiptAnchored(receiptDigest, msg.sender, intentDigest, mandateRef, uint64(block.timestamp));
44
+ }
45
+
46
+ /// @notice The anchor `anchoredBy` made of a digest, or a zero struct when none — the reader names the
47
+ /// agent from the receipt it holds, and decides what absence means.
48
+ function anchorOf(address anchoredBy, bytes32 receiptDigest) external view returns (Anchor memory) {
49
+ return _anchors[anchoredBy][receiptDigest];
50
+ }
51
+
52
+ function isAnchored(address anchoredBy, bytes32 receiptDigest) external view returns (bool) {
53
+ return _anchors[anchoredBy][receiptDigest].anchoredBy != address(0);
54
+ }
55
+ }
@@ -0,0 +1,313 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ import {IRegistryMembershipPolicy} from "./IRegistryMembershipPolicy.sol";
5
+
6
+ /**
7
+ * @title AgentRegistryBase
8
+ * @notice The generic, SA-anchored registry base that vertical registries are built FROM (spec 279 §4,
9
+ * ADR-0038 "many-registries"). It is a MEMBERSHIP LEDGER of facets — entries that point AT a
10
+ * Smart Agent address — not an account. It holds no funds, signs nothing, executes nothing, and
11
+ * grants NO authority to act: an entry is evidence ("this SA is a member of registry R, here is
12
+ * its card hash + binding-proof hash + claims"), never a delegation. Authority lives in the
13
+ * AgentAccount + DelegationManager; this contract only records and gates membership.
14
+ *
15
+ * ─── How it differs from AgentAccount ───
16
+ * AgentAccount IS the agent (ERC-4337/7579 custody + execution + ERC-1271). AgentRegistryBase is
17
+ * a directory of MANY entries pointing at MANY agents, one instance per registry. The subject SA
18
+ * controls its own entry because it must be the caller (RB-01); the registry's controller / policy
19
+ * hook gates admission + ejection (RB-02/03). The binding proof referenced by `bindingProofHash`
20
+ * is verified OFF-CHAIN by a verifier (registry-kit `verifyEntryBindingProof`) against the
21
+ * subject SA's ERC-1271 — this contract stores the hash as a pointer, it does not re-verify it.
22
+ *
23
+ * ─── Key invariants (RB-*) ───
24
+ * RB-01 entry control follows the subject SA custody policy — register / renew / self-revoke /
25
+ * self-update require `msg.sender == subjectAgent` (so the SA's own custody produced the
26
+ * call); the contract never re-implements custody.
27
+ * RB-02 admission is gated by the registry's pluggable membership hook (or open if unset); a
28
+ * policy returning false OR reverting fails closed (ADR-0013) — no second path.
29
+ * RB-03 suspension / revocation / claim-update by a non-subject require the registry controller
30
+ * OR a policy-authorized actor (`canAdminister`); never an arbitrary caller.
31
+ * RB-04 revocation is terminal; a revoked entry cannot be renewed, re-registered, suspended, or
32
+ * claim-updated.
33
+ * RB-05 NO external-registry-protocol fields in storage (no ENS/8004/HCS/OASF) — those are
34
+ * external projections (ADR-0037), not AP state.
35
+ * RB-06 reads are storage views only — discovery never scans chain logs (ADR-0012); the indexer
36
+ * consumes the events below.
37
+ * RB-07 epoch-bucket registration timestamps (raw block.timestamp never stored); `expiresAt` is a
38
+ * caller-supplied absolute unix-seconds bound compared against block.timestamp for liveness.
39
+ *
40
+ * Spec 279 §4 + ADR-0010 / 0012 / 0013 / 0037 / 0038.
41
+ */
42
+ contract AgentRegistryBase {
43
+ // ─── Constants ──────────────────────────────────────────────────────
44
+
45
+ /// @dev RB-07 — registration time is bucketed (provenance, not a precise clock). Mirrors AttestationRegistry.
46
+ uint64 public constant EPOCH_SECONDS = 3600;
47
+
48
+ // ─── Types ──────────────────────────────────────────────────────────
49
+
50
+ /// @dev Stored status. `Expired` is NOT stored (no keeper to flip it) — it is DERIVED from `expiresAt`
51
+ /// by {isActive}; storage only tracks the explicit lifecycle transitions.
52
+ enum EntryStatus {
53
+ None,
54
+ Active,
55
+ Suspended,
56
+ Revoked
57
+ }
58
+
59
+ struct Registry {
60
+ address controller; // the governing SA (set on create); address(0) iff !exists
61
+ address policy; // pluggable membership hook; address(0) = open registry (subject self-service only)
62
+ bool exists;
63
+ }
64
+
65
+ struct Entry {
66
+ address subjectAgent; // the canonical SA this entry is a facet of
67
+ bytes32 cardHash; // sha256 of the agent-profile signed card bundle
68
+ bytes32 bindingProofHash; // sha256 of the off-chain binding proof (verified off-chain, not here)
69
+ bytes32 claimsRoot; // keccak of the registration-time claimHashes[] (the set the binding proof signed)
70
+ EntryStatus status;
71
+ uint64 registeredAtBucket; // block.timestamp / EPOCH_SECONDS at registration
72
+ uint64 expiresAt; // absolute unix seconds; 0 = non-expiring
73
+ }
74
+
75
+ // ─── Storage ────────────────────────────────────────────────────────
76
+
77
+ mapping(bytes32 => Registry) private _registries; // registryId => Registry
78
+ mapping(bytes32 => Entry) private _entries; // entryKey => Entry
79
+ mapping(bytes32 => mapping(bytes32 => bytes32)) private _claims; // entryKey => claimSlotId => claimHash
80
+
81
+ // ─── Errors ─────────────────────────────────────────────────────────
82
+
83
+ error RegistryExists();
84
+ error RegistryNotFound();
85
+ error NotController();
86
+ error EntryExists();
87
+ error EntryNotFound();
88
+ error ZeroSubject();
89
+ error SubjectMismatch(); // msg.sender is not the entry's subject SA (RB-01)
90
+ error NotAuthorized(); // msg.sender is neither controller nor a policy-authorized admin (RB-03)
91
+ error NotActive();
92
+ error AlreadyRevoked();
93
+ error InvalidExpiry();
94
+ error MembershipDenied(); // RB-02 fail-closed admission denial
95
+
96
+ // ─── Events ─────────────────────────────────────────────────────────
97
+
98
+ // Registry provisioning (not part of the registry-kit lifecycle ABI).
99
+ event RegistryCreated(bytes32 indexed registryId, address indexed controller, address policy);
100
+ event RegistryPolicyUpdated(bytes32 indexed registryId, address policy);
101
+
102
+ // Entry lifecycle — MUST match registry-kit `AGENT_REGISTRY_BASE_ABI` + spec 279 §4.1 EXACTLY
103
+ // (the SDK encodes calls against / decodes logs from these signatures).
104
+ event RegistryEntryRegistered(
105
+ bytes32 indexed registryId,
106
+ bytes32 indexed entryId,
107
+ address indexed subjectAgent,
108
+ bytes32 cardHash,
109
+ bytes32 bindingProofHash
110
+ );
111
+ event RegistryEntryUpdated(
112
+ bytes32 indexed registryId,
113
+ bytes32 indexed entryId,
114
+ bytes32 cardHash,
115
+ bytes32 bindingProofHash
116
+ );
117
+ event RegistryEntryRenewed(bytes32 indexed registryId, bytes32 indexed entryId, uint64 expiresAt);
118
+ event RegistryEntrySuspended(bytes32 indexed registryId, bytes32 indexed entryId, bytes32 reasonHash);
119
+ event RegistryEntryRevoked(bytes32 indexed registryId, bytes32 indexed entryId, bytes32 reasonHash);
120
+ event RegistryClaimUpdated(
121
+ bytes32 indexed registryId, bytes32 indexed entryId, bytes32 indexed claimSlotId, bytes32 claimHash
122
+ );
123
+
124
+ // ─── Registry provisioning ──────────────────────────────────────────
125
+
126
+ /// @notice Create a registry. Permissionless + first-create-wins: `msg.sender` becomes the controller.
127
+ /// @dev `registryId` is `keccak256(urn:ap:registry:…)` off-chain; squatting on an id is a PROVISIONING
128
+ /// concern (create the registry in the same flow that mints its urn), out of scope for this base.
129
+ /// `policy == address(0)` ⇒ open registry: any SA may self-register, no admission gate.
130
+ function createRegistry(bytes32 registryId, address policy) external {
131
+ if (_registries[registryId].exists) revert RegistryExists();
132
+ _registries[registryId] = Registry({controller: msg.sender, policy: policy, exists: true});
133
+ emit RegistryCreated(registryId, msg.sender, policy);
134
+ }
135
+
136
+ /// @notice Swap the pluggable membership hook. Controller only.
137
+ function setRegistryPolicy(bytes32 registryId, address policy) external {
138
+ Registry storage r = _registries[registryId];
139
+ if (!r.exists) revert RegistryNotFound();
140
+ if (msg.sender != r.controller) revert NotController();
141
+ r.policy = policy;
142
+ emit RegistryPolicyUpdated(registryId, policy);
143
+ }
144
+
145
+ // ─── Entry lifecycle ────────────────────────────────────────────────
146
+
147
+ /// @notice Register a facet of `subjectAgent`. RB-01: the subject SA must be the caller. RB-02: the
148
+ /// registry's membership hook (if any) must admit. Signature ABI matches registry-kit.
149
+ function registerEntry(
150
+ bytes32 registryId,
151
+ bytes32 entryId,
152
+ address subjectAgent,
153
+ bytes32 cardHash,
154
+ bytes32 bindingProofHash,
155
+ bytes32[] calldata claimHashes,
156
+ uint64 expiresAt
157
+ ) external {
158
+ Registry storage r = _registries[registryId];
159
+ if (!r.exists) revert RegistryNotFound();
160
+ if (subjectAgent == address(0)) revert ZeroSubject();
161
+ if (msg.sender != subjectAgent) revert SubjectMismatch(); // RB-01
162
+ if (expiresAt != 0 && expiresAt <= block.timestamp) revert InvalidExpiry();
163
+
164
+ bytes32 key = _entryKey(registryId, entryId);
165
+ if (_entries[key].status != EntryStatus.None) revert EntryExists();
166
+
167
+ // RB-02 — admission gate, fail-closed: a false return OR a revert blocks registration.
168
+ address policy = r.policy;
169
+ if (policy != address(0)) {
170
+ try IRegistryMembershipPolicy(policy)
171
+ .canRegister(registryId, entryId, subjectAgent, cardHash, claimHashes) returns (
172
+ bool ok
173
+ ) {
174
+ if (!ok) revert MembershipDenied();
175
+ } catch {
176
+ revert MembershipDenied();
177
+ }
178
+ }
179
+
180
+ _entries[key] = Entry({
181
+ subjectAgent: subjectAgent,
182
+ cardHash: cardHash,
183
+ bindingProofHash: bindingProofHash,
184
+ claimsRoot: keccak256(abi.encode(claimHashes)),
185
+ status: EntryStatus.Active,
186
+ registeredAtBucket: uint64(block.timestamp) / EPOCH_SECONDS,
187
+ expiresAt: expiresAt
188
+ });
189
+
190
+ emit RegistryEntryRegistered(registryId, entryId, subjectAgent, cardHash, bindingProofHash);
191
+ }
192
+
193
+ /// @notice Extend an active entry's expiry. RB-01: subject SA only. RB-04: a revoked/suspended entry
194
+ /// cannot be renewed.
195
+ function renewEntry(bytes32 registryId, bytes32 entryId, uint64 expiresAt) external {
196
+ Entry storage e = _entries[_entryKey(registryId, entryId)];
197
+ if (e.status == EntryStatus.None) revert EntryNotFound();
198
+ if (msg.sender != e.subjectAgent) revert SubjectMismatch(); // RB-01
199
+ if (e.status != EntryStatus.Active) revert NotActive(); // RB-04 (Suspended/Revoked)
200
+ if (expiresAt != 0 && expiresAt <= block.timestamp) revert InvalidExpiry();
201
+ e.expiresAt = expiresAt;
202
+ emit RegistryEntryRenewed(registryId, entryId, expiresAt);
203
+ }
204
+
205
+ /// @notice Re-point an ACTIVE entry at a newer card. RB-01: the subject and only the subject.
206
+ /// @dev Cards are versioned and republished; without this an entry is pinned forever to whatever card it
207
+ /// was registered with, so a directory could never reflect a new release (found live 2026-08-30: the only
208
+ /// paths were `registerEntry`, which reverts `EntryExists`, and `renewEntry`, which moves only the expiry).
209
+ /// The subject re-signs: `bindingProofHash` covers the new card, so an update proves the same thing a
210
+ /// registration does. Membership is NOT re-checked — admission decided this agent belongs; which card it
211
+ /// publishes is not an admission question (a registry that disagrees can suspend the entry).
212
+ function updateEntry(
213
+ bytes32 registryId,
214
+ bytes32 entryId,
215
+ bytes32 cardHash,
216
+ bytes32 bindingProofHash,
217
+ bytes32[] calldata claimHashes
218
+ ) external {
219
+ Entry storage e = _entries[_entryKey(registryId, entryId)];
220
+ if (e.status == EntryStatus.None) revert EntryNotFound();
221
+ if (msg.sender != e.subjectAgent) revert SubjectMismatch(); // RB-01
222
+ if (e.status != EntryStatus.Active) revert NotActive(); // RB-04 (Suspended/Revoked)
223
+
224
+ e.cardHash = cardHash;
225
+ e.bindingProofHash = bindingProofHash;
226
+ e.claimsRoot = keccak256(abi.encode(claimHashes));
227
+
228
+ emit RegistryEntryUpdated(registryId, entryId, cardHash, bindingProofHash);
229
+ }
230
+
231
+ /// @notice Suspend an active entry. RB-03: admin action (controller or policy-authorized) — NOT subject.
232
+ function suspendEntry(bytes32 registryId, bytes32 entryId, bytes32 reasonHash) external {
233
+ Entry storage e = _entries[_entryKey(registryId, entryId)];
234
+ if (e.status == EntryStatus.None) revert EntryNotFound();
235
+ _requireAdmin(registryId, entryId); // RB-03
236
+ if (e.status != EntryStatus.Active) revert NotActive();
237
+ e.status = EntryStatus.Suspended;
238
+ emit RegistryEntrySuspended(registryId, entryId, reasonHash);
239
+ }
240
+
241
+ /// @notice Revoke an entry (terminal). The subject SA may leave; the controller / policy-admin may eject.
242
+ function revokeEntry(bytes32 registryId, bytes32 entryId, bytes32 reasonHash) external {
243
+ Entry storage e = _entries[_entryKey(registryId, entryId)];
244
+ if (e.status == EntryStatus.None) revert EntryNotFound();
245
+ if (msg.sender != e.subjectAgent) _requireAdmin(registryId, entryId); // subject (leave) or admin (eject)
246
+ if (e.status == EntryStatus.Revoked) revert AlreadyRevoked(); // RB-04
247
+ e.status = EntryStatus.Revoked;
248
+ emit RegistryEntryRevoked(registryId, entryId, reasonHash);
249
+ }
250
+
251
+ /// @notice Set a per-slot claim hash. Subject self-service OR admin (issuer/registry-managed claims).
252
+ /// @dev Distinct from `claimsRoot` (the immutable snapshot the binding proof signed at registration):
253
+ /// this is the mutable, slot-keyed projection the indexer reads for discovery.
254
+ function updateClaim(bytes32 registryId, bytes32 entryId, bytes32 claimSlotId, bytes32 claimHash) external {
255
+ bytes32 key = _entryKey(registryId, entryId);
256
+ Entry storage e = _entries[key];
257
+ if (e.status == EntryStatus.None) revert EntryNotFound();
258
+ if (e.status == EntryStatus.Revoked) revert AlreadyRevoked(); // RB-04
259
+ if (msg.sender != e.subjectAgent) _requireAdmin(registryId, entryId);
260
+ _claims[key][claimSlotId] = claimHash;
261
+ emit RegistryClaimUpdated(registryId, entryId, claimSlotId, claimHash);
262
+ }
263
+
264
+ // ─── Views (RB-06: discovery reads use these, never log scans) ──────
265
+
266
+ function getRegistry(bytes32 registryId) external view returns (Registry memory) {
267
+ Registry memory r = _registries[registryId];
268
+ if (!r.exists) revert RegistryNotFound();
269
+ return r;
270
+ }
271
+
272
+ function getEntry(bytes32 registryId, bytes32 entryId) external view returns (Entry memory) {
273
+ Entry memory e = _entries[_entryKey(registryId, entryId)];
274
+ if (e.status == EntryStatus.None) revert EntryNotFound();
275
+ return e;
276
+ }
277
+
278
+ /// @notice Effective liveness: stored-Active AND not past `expiresAt`. A missing entry returns false
279
+ /// (empty is an answer, ADR-0013 — not a trigger for a fallback lookup).
280
+ function isActive(bytes32 registryId, bytes32 entryId) external view returns (bool) {
281
+ Entry memory e = _entries[_entryKey(registryId, entryId)];
282
+ if (e.status != EntryStatus.Active) return false;
283
+ if (e.expiresAt != 0 && block.timestamp > e.expiresAt) return false;
284
+ return true;
285
+ }
286
+
287
+ /// @notice The current hash for a claim slot (0 if unset). Slot semantics are defined by the registry.
288
+ function getClaim(bytes32 registryId, bytes32 entryId, bytes32 claimSlotId) external view returns (bytes32) {
289
+ return _claims[_entryKey(registryId, entryId)][claimSlotId];
290
+ }
291
+
292
+ // ─── Internal ───────────────────────────────────────────────────────
293
+
294
+ function _entryKey(bytes32 registryId, bytes32 entryId) internal pure returns (bytes32) {
295
+ return keccak256(abi.encodePacked(registryId, entryId));
296
+ }
297
+
298
+ /// @dev RB-03 — controller passes; otherwise the pluggable policy may authorize the actor. Fail-closed:
299
+ /// no policy, a false return, or a revert all deny.
300
+ function _requireAdmin(bytes32 registryId, bytes32 entryId) internal view {
301
+ Registry storage r = _registries[registryId];
302
+ if (msg.sender == r.controller) return;
303
+ address policy = r.policy;
304
+ if (policy != address(0)) {
305
+ try IRegistryMembershipPolicy(policy).canAdminister(registryId, entryId, msg.sender) returns (bool ok) {
306
+ if (ok) return;
307
+ } catch {
308
+ // fail-closed: treat a reverting policy as denial
309
+ }
310
+ }
311
+ revert NotAuthorized();
312
+ }
313
+ }
@@ -0,0 +1,109 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ /**
5
+ * @title EstateProjectionRegistry — an estate's authority, projected onto PUBLIC GROUND (spec 410 §4)
6
+ * @notice One registry, many estates. An estate's grants and relationships are enforced on its own chain and
7
+ * held in its principals' vaults; a verifier elsewhere can read neither. What the estate anchors here
8
+ * is two Merkle roots over BLINDED commitments — the live-grant root (every grant currently live) and
9
+ * the membership root (every countersigned relationship credential) — plus the hash of its signed
10
+ * charter (spec 410 §9), under a monotonic sequence. A presentation against these roots tells a
11
+ * verifier in another estate that a grant is live or an agent is a member in that estate as of that
12
+ * sequence, and nothing else (the estate-projection SDK package).
13
+ *
14
+ * WHO MAY WRITE. An estate REGISTERS once: its id — keccak256("eip155:<chainId>:<governance>"), the
15
+ * one fact public ground learns about it — bound to the SIGNER its governance controls here (an EOA
16
+ * or an account on this chain). First registration wins; the signer rotates only by the current
17
+ * signer. `setRoots` is the signer's, with a sequence strictly above the last: a replayed or reordered
18
+ * projection is refused. No admin, no pause, no upgrade: public ground has no operator either.
19
+ *
20
+ * WHAT THIS IS NOT: authority. A root proves what the estate vouches for at a moment; whether the
21
+ * receiving estate lets an agent ACT is its own mandate, per step (ADR-0056 / ADR-0057).
22
+ */
23
+ contract EstateProjectionRegistry {
24
+ struct Roots {
25
+ bytes32 liveGrantRoot;
26
+ bytes32 membershipRoot;
27
+ bytes32 charterHash;
28
+ uint64 sequence;
29
+ uint64 anchoredAt;
30
+ }
31
+
32
+ mapping(bytes32 estateId => address signer) public signerOf;
33
+ mapping(bytes32 estateId => Roots) private _roots;
34
+
35
+ event EstateRegistered(bytes32 indexed estateId, address indexed signer);
36
+ event EstateSignerRotated(bytes32 indexed estateId, address indexed from, address indexed to);
37
+ event RootsAnchored(bytes32 indexed estateId, uint64 indexed sequence, bytes32 liveGrantRoot, bytes32 membershipRoot, bytes32 charterHash);
38
+
39
+ error AlreadyRegistered(bytes32 estateId);
40
+ error NotRegistered(bytes32 estateId);
41
+ error NotTheSigner(bytes32 estateId, address caller);
42
+ error SequenceNotAbove(uint64 last, uint64 given);
43
+ error ZeroAddress();
44
+
45
+ /// @notice Bind an estate id to the signer its governance controls on this chain. First come, once.
46
+ function register(bytes32 estateId, address signer) external {
47
+ if (signer == address(0)) revert ZeroAddress();
48
+ if (signerOf[estateId] != address(0)) revert AlreadyRegistered(estateId);
49
+ signerOf[estateId] = signer;
50
+ emit EstateRegistered(estateId, signer);
51
+ }
52
+
53
+ function rotateSigner(bytes32 estateId, address to) external {
54
+ if (to == address(0)) revert ZeroAddress();
55
+ address cur = signerOf[estateId];
56
+ if (cur == address(0)) revert NotRegistered(estateId);
57
+ if (msg.sender != cur) revert NotTheSigner(estateId, msg.sender);
58
+ signerOf[estateId] = to;
59
+ emit EstateSignerRotated(estateId, cur, to);
60
+ }
61
+
62
+ /// @notice Anchor the estate's roots under `sequence` (strictly above the last). Refreshed on every revocation
63
+ /// and membership change; a verifier's freshness policy reads `anchoredAt`.
64
+ function setRoots(bytes32 estateId, bytes32 liveGrantRoot, bytes32 membershipRoot, bytes32 charterHash, uint64 sequence) external {
65
+ address cur = signerOf[estateId];
66
+ if (cur == address(0)) revert NotRegistered(estateId);
67
+ if (msg.sender != cur) revert NotTheSigner(estateId, msg.sender);
68
+ Roots storage r = _roots[estateId];
69
+ if (sequence <= r.sequence) revert SequenceNotAbove(r.sequence, sequence);
70
+ r.liveGrantRoot = liveGrantRoot;
71
+ r.membershipRoot = membershipRoot;
72
+ r.charterHash = charterHash;
73
+ r.sequence = sequence;
74
+ r.anchoredAt = uint64(block.timestamp);
75
+ emit RootsAnchored(estateId, sequence, liveGrantRoot, membershipRoot, charterHash);
76
+ }
77
+
78
+ /// @notice The one read a verifier makes: the roots as anchored, with the sequence and when.
79
+ function roots(bytes32 estateId) external view returns (bytes32 liveGrantRoot, bytes32 membershipRoot, bytes32 charterHash, uint64 sequence, uint64 anchoredAt) {
80
+ Roots storage r = _roots[estateId];
81
+ return (r.liveGrantRoot, r.membershipRoot, r.charterHash, r.sequence, r.anchoredAt);
82
+ }
83
+
84
+ /// @notice keccak256("eip155:<chainId>:<governance>") — the same derivation the SDK's `estateIdOf` uses.
85
+ function estateIdOf(uint256 chainId, address governance) external pure returns (bytes32) {
86
+ return keccak256(abi.encodePacked("eip155:", _utoa(chainId), ":", _lowerHex(governance)));
87
+ }
88
+
89
+ function _utoa(uint256 v) private pure returns (string memory) {
90
+ if (v == 0) return "0";
91
+ uint256 j = v; uint256 len;
92
+ while (j != 0) { len++; j /= 10; }
93
+ bytes memory b = new bytes(len);
94
+ while (v != 0) { len -= 1; b[len] = bytes1(uint8(48 + v % 10)); v /= 10; }
95
+ return string(b);
96
+ }
97
+ function _lowerHex(address a) private pure returns (string memory) {
98
+ bytes memory alphabet = "0123456789abcdef";
99
+ bytes memory s = new bytes(42);
100
+ s[0] = "0"; s[1] = "x";
101
+ uint160 v = uint160(a);
102
+ for (uint256 i = 0; i < 20; i++) {
103
+ uint8 bt = uint8(v >> (8 * (19 - i)));
104
+ s[2 + i * 2] = alphabet[bt >> 4];
105
+ s[3 + i * 2] = alphabet[bt & 0x0f];
106
+ }
107
+ return string(s);
108
+ }
109
+ }
@@ -0,0 +1,30 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ /**
5
+ * @title IRegistryMembershipPolicy
6
+ * @notice Pluggable membership/validation hook for {AgentRegistryBase} (spec 279 §4.2). It answers two
7
+ * yes/no questions and NOTHING else:
8
+ *
9
+ * - `canRegister` — may `subjectAgent` create `entryId` in `registryId` with these claims?
10
+ * - `canAdminister` — may a NON-subject `actor` suspend / revoke / update `entryId`?
11
+ *
12
+ * Implementations live OUTSIDE Ring 0 (issuer-attested, stake/bond, quorum-approved,
13
+ * domain-control-proof, skill-claim-proof, …) — they MUST NOT push vertical business logic into
14
+ * the registry base. Both methods are `view`, so {AgentRegistryBase} reaches them via STATICCALL
15
+ * (no state mutation, no reentrancy). A policy that returns `false` OR reverts is treated as a
16
+ * denial: the base fails closed (ADR-0013) — there is no second, weaker authorization path.
17
+ */
18
+ interface IRegistryMembershipPolicy {
19
+ /// @return ok whether `subjectAgent` may register `entryId` in `registryId` with `cardHash`/`claimHashes`.
20
+ function canRegister(
21
+ bytes32 registryId,
22
+ bytes32 entryId,
23
+ address subjectAgent,
24
+ bytes32 cardHash,
25
+ bytes32[] calldata claimHashes
26
+ ) external view returns (bool ok);
27
+
28
+ /// @return ok whether `actor` (not the entry's subject) may administer (suspend / revoke / update) the entry.
29
+ function canAdminister(bytes32 registryId, bytes32 entryId, address actor) external view returns (bool ok);
30
+ }
@@ -34,6 +34,13 @@ pragma solidity ^0.8.28;
34
34
  * Off-chain JSON published at `metadataURI` MUST hash to
35
35
  * `metadataHash`; consumers reject mismatched fetches.
36
36
  */
37
+ // R6.3 — Every `e.createdAt == 0` comparison in this contract is a
38
+ // sentinel "edge-never-created" check. Storage default IS exactly
39
+ // 0 for unset records, so the equality is semantically a
40
+ // "does-not-exist" probe — not a numeric-precision concern.
41
+ // Disabling Slither's `incorrect-equality` at the contract scope
42
+ // keeps these inline reads idiomatic.
43
+ // slither-disable-start incorrect-equality
37
44
  contract AgentRelationship {
38
45
  enum EdgeStatus {
39
46
  NONE, // 0 — never set (sentinel)
@@ -287,3 +294,4 @@ contract AgentRelationship {
287
294
  }
288
295
  }
289
296
  }
297
+ // slither-disable-end incorrect-equality