@agenticprimitives/contracts 1.0.0-alpha.5 → 1.0.0-alpha.50

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 (145) hide show
  1. package/AUDIT.md +119 -27
  2. package/README.md +47 -12
  3. package/deployments-base-sepolia.json +52 -1
  4. package/deployments-faithchain.json +103 -0
  5. package/deployments-hopechain.json +78 -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/AccountBootstrap.json +99 -0
  10. package/dist/abi/AgentAccount.json +461 -67
  11. package/dist/abi/AgentAccountFactory.json +309 -0
  12. package/dist/abi/AgentNameAttributeResolver.json +212 -0
  13. package/dist/abi/AgentNameRegistry.json +544 -0
  14. package/dist/abi/AgentNameUniversalResolver.json +222 -0
  15. package/dist/abi/AgentProfileResolver.json +236 -0
  16. package/dist/abi/AgentRegistryBase.json +1003 -0
  17. package/dist/abi/AgentRelationship.json +405 -0
  18. package/dist/abi/AgenticGovernance.json +155 -0
  19. package/dist/abi/AgreementRegistry.json +203 -5
  20. package/dist/abi/AllowedMethodsEnforcer.json +193 -0
  21. package/dist/abi/AllowedTargetsEnforcer.json +193 -0
  22. package/dist/abi/ApprovedHashRegistry.json +267 -2
  23. package/dist/abi/AttestationRegistry.json +242 -0
  24. package/dist/abi/AttributeStorage.json +24 -0
  25. package/dist/abi/CallDataHashEnforcer.json +193 -0
  26. package/dist/abi/CustodyPolicy.json +422 -55
  27. package/dist/abi/DelegationManager.json +292 -0
  28. package/dist/abi/DigestBindingEnforcer.json +541 -0
  29. package/dist/abi/Eip7702.json +13 -0
  30. package/dist/abi/EstateProjectionRegistry.json +599 -0
  31. package/dist/abi/Generation5Bridge.json +355 -0
  32. package/dist/abi/GeoFeatureRegistry.json +235 -0
  33. package/dist/abi/IAgentAccountFactoryView.json +26 -0
  34. package/dist/abi/IAgentAccountGovernanceTimelockView.json +15 -0
  35. package/dist/abi/IApprovedHashRegistryWrite.json +35 -0
  36. package/dist/abi/ICustodyEpochView.json +28 -0
  37. package/dist/abi/ICustodyPolicyAccountModuleView.json +31 -0
  38. package/dist/abi/ICustodyPolicyFactoryView.json +13 -0
  39. package/dist/abi/ICustodyPolicyPasskeyView.json +50 -0
  40. package/dist/abi/IDelegationManager.json +18 -0
  41. package/dist/abi/IGeneration4Reads.json +143 -0
  42. package/dist/abi/IGeneration5Account.json +33 -0
  43. package/dist/abi/IGeneration5Voucher.json +26 -0
  44. package/dist/abi/IMoveAccountView.json +57 -0
  45. package/dist/abi/IMoveCustodyView.json +169 -0
  46. package/dist/abi/IMoveFactoryView.json +41 -0
  47. package/dist/abi/IPaymentReceiptRegistry.json +50 -0
  48. package/dist/abi/IRedemptionContext.json +15 -0
  49. package/dist/abi/IRegistryMembershipPolicy.json +70 -0
  50. package/dist/abi/ITimelockVeto.json +93 -0
  51. package/dist/abi/ITreasurySpendPolicyAccountView.json +44 -0
  52. package/dist/abi/IUpgradeVoucherView.json +26 -0
  53. package/dist/abi/MockUSDC.json +621 -0
  54. package/dist/abi/OntologyTermRegistry.json +268 -0
  55. package/dist/abi/PayloadClassesEnforcer.json +310 -0
  56. package/dist/abi/PaymentEnforcer.json +639 -0
  57. package/dist/abi/PaymentEscrow.json +501 -0
  58. package/dist/abi/PaymentReceiptRegistry.json +388 -0
  59. package/dist/abi/PermissionlessSubregistry.json +353 -0
  60. package/dist/abi/PricedSubregistry.json +1141 -0
  61. package/dist/abi/QuorumEnforcer.json +209 -0
  62. package/dist/abi/ReceiptAnchorRegistry.json +346 -0
  63. package/dist/abi/RelationshipTypeRegistry.json +268 -0
  64. package/dist/abi/ShapeRegistry.json +268 -0
  65. package/dist/abi/SignatureVerifier.json +196 -0
  66. package/dist/abi/SkillDefinitionRegistry.json +235 -0
  67. package/dist/abi/SmartAgentPaymaster.json +445 -1
  68. package/dist/abi/StableProxyGoverned.json +190 -0
  69. package/dist/abi/StableProxyGovernedOneShot.json +172 -0
  70. package/dist/abi/TimestampEnforcer.json +193 -0
  71. package/dist/abi/TreasurySpendPolicy.json +667 -0
  72. package/dist/abi/UpgradeVoucher.json +328 -0
  73. package/dist/abi/ValueEnforcer.json +193 -0
  74. package/dist/abi/index.d.ts +35 -0
  75. package/dist/abi/index.js +35 -0
  76. package/dist/deployments/base-sepolia.d.ts +11 -0
  77. package/dist/deployments/base-sepolia.js +51 -28
  78. package/dist/deployments/faithchain.d.ts +77 -0
  79. package/dist/deployments/faithchain.js +107 -0
  80. package/dist/deployments/hopechain.d.ts +68 -0
  81. package/dist/deployments/hopechain.js +82 -0
  82. package/dist/deployments/index.d.ts +7 -2
  83. package/dist/deployments/index.js +15 -0
  84. package/dist/deployments/paymaster-anvil.d.ts +11 -0
  85. package/dist/deployments/paymaster-anvil.js +9 -0
  86. package/dist/deployments/registries-base-sepolia.d.ts +10 -0
  87. package/dist/deployments/registries-base-sepolia.js +8 -0
  88. package/dist/deployments/registries-hopechain.d.ts +10 -0
  89. package/dist/deployments/registries-hopechain.js +8 -0
  90. package/package.json +37 -7
  91. package/src/AccountBootstrap.sol +38 -0
  92. package/src/AgentAccount.sol +1091 -134
  93. package/src/AgentAccountFactory.sol +198 -21
  94. package/src/ApprovedHashRegistry.sol +134 -10
  95. package/src/IAgentAccount.sol +37 -0
  96. package/src/SmartAgentPaymaster.sol +275 -22
  97. package/src/UniversalSignatureValidator.sol +7 -0
  98. package/src/UpgradeVoucher.sol +87 -0
  99. package/src/agency/DelegationManager.sol +299 -76
  100. package/src/agency/ICaveatEnforcer.sol +10 -0
  101. package/src/agency/IDelegationManager.sol +37 -5
  102. package/src/agreement/AgreementRegistry.sol +105 -35
  103. package/src/attestation/AttestationRegistry.sol +220 -40
  104. package/src/custody/CustodyPolicy.sol +588 -70
  105. package/src/custody/TreasurySpendPolicy.sol +338 -0
  106. package/src/enforcers/AllowedMethodsEnforcer.sol +13 -2
  107. package/src/enforcers/AllowedTargetsEnforcer.sol +13 -2
  108. package/src/enforcers/CallDataHashEnforcer.sol +7 -1
  109. package/src/enforcers/DigestBindingEnforcer.sol +182 -0
  110. package/src/enforcers/PayloadClassesEnforcer.sol +36 -0
  111. package/src/enforcers/PaymentEnforcer.sol +291 -0
  112. package/src/enforcers/QuorumEnforcer.sol +24 -3
  113. package/src/enforcers/TimestampEnforcer.sol +7 -1
  114. package/src/enforcers/ValueEnforcer.sol +13 -2
  115. package/src/geo/GeoFeatureRegistry.sol +67 -22
  116. package/src/governance/AgenticGovernance.sol +187 -4
  117. package/src/governance/GovernanceManaged.sol +2 -0
  118. package/src/governance/StableProxyGoverned.sol +79 -0
  119. package/src/governance/StableProxyGovernedOneShot.sol +93 -0
  120. package/src/identity/AgentProfilePredicates.sol +23 -0
  121. package/src/identity/AgentProfileResolver.sol +22 -2
  122. package/src/libraries/Eip7702.sol +36 -0
  123. package/src/libraries/SignatureSlotRecovery.sol +28 -7
  124. package/src/libraries/SignatureVerifier.sol +52 -0
  125. package/src/libraries/WebAuthnLib.sol +16 -0
  126. package/src/migration/Generation5Bridge.sol +364 -0
  127. package/src/mocks/MockUSDC.sol +152 -0
  128. package/src/naming/AgentNameAttributeResolver.sol +29 -4
  129. package/src/naming/AgentNamePredicates.sol +89 -0
  130. package/src/naming/AgentNameRegistry.sol +324 -20
  131. package/src/naming/AgentNameUniversalResolver.sol +35 -2
  132. package/src/naming/PermissionlessSubregistry.sol +82 -25
  133. package/src/naming/PricedSubregistry.sol +293 -0
  134. package/src/ontology/AttributeStorage.sol +93 -80
  135. package/src/ontology/OntologyTermRegistry.sol +58 -2
  136. package/src/ontology/ShapeRegistry.sol +58 -2
  137. package/src/payments/PaymentEscrow.sol +187 -0
  138. package/src/payments/PaymentReceiptRegistry.sol +100 -0
  139. package/src/provenance/ReceiptAnchorRegistry.sol +67 -0
  140. package/src/registry/AgentRegistryBase.sol +372 -0
  141. package/src/registry/EstateProjectionRegistry.sol +177 -0
  142. package/src/registry/IRegistryMembershipPolicy.sol +30 -0
  143. package/src/relationships/AgentRelationship.sol +129 -8
  144. package/src/relationships/RelationshipTypeRegistry.sol +58 -2
  145. package/src/skills/SkillDefinitionRegistry.sol +61 -17
@@ -0,0 +1,100 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ import "../governance/StableProxyGoverned.sol";
5
+ import {Eip7702} from "../libraries/Eip7702.sol";
6
+
7
+ /**
8
+ * @title PaymentReceiptRegistry
9
+ * @notice Trustless, queryable settlement log for x402 pay-per-use (spec 272, PAY-CON-4 / X402-D9.3).
10
+ * Only the authorized {PaymentEnforcer} may `record` — a receipt is a byproduct of a gated
11
+ * `DelegationManager.redeemDelegation`, so a service cannot fabricate one and the reader's
12
+ * charge history needs no trust in service logs.
13
+ *
14
+ * @dev HASHES + ADDRESSES ONLY — no URLs, queries, licensed text, or passage refs ever reach the
15
+ * chain (PAY-WIRE-6). Event-only (no per-row storage): apps read settlements via an indexer /
16
+ * app cache, never inline `eth_getLogs` in product hot paths (ADR-0012). The
17
+ * `PaymentEnforcer.PaymentCharged` event is the primary on-chain receipt; `PaymentSettled`
18
+ * here adds payer/payee/mandateId-indexed querying for treasury views.
19
+ *
20
+ * WHAT A ROW PROVES (spec 445 / audit DLG-8). Enforced on chain before the row is written:
21
+ * `amount > 0` of `asset` reached `payee`, from `payer` — the ROOT delegator, the account the
22
+ * redemption executed through — under `delegationHash`, once for `nonce`. NOT proved:
23
+ * `mandateId` and `resourceHash`. They are copied from the redeemer's unsigned caveat `args`;
24
+ * they are the redeemer's ASSERTION of which mandate and resource the charge was for. A reader
25
+ * that needs them to be true compares them with a record it trusts (the mandate it issued, the
26
+ * resource it served); it never treats the row as that record.
27
+ */
28
+ contract PaymentReceiptRegistry is StableProxyGoverned {
29
+ /// @notice The deployer who wires the sole authorized recorder once.
30
+ /// @dev Spec 447 — storage, no longer an immutable. An immutable `msg.sender` would be whoever deployed the
31
+ /// IMPLEMENTATION (behind a CREATE2 deploy, the singleton factory), and nobody could ever wire a proxy's
32
+ /// enforcer. The proxy's initializer names it explicitly.
33
+ address public owner;
34
+ /// @notice The single PaymentEnforcer permitted to `record` (set once via {setEnforcer}).
35
+ address public enforcer;
36
+
37
+ event PaymentSettled(
38
+ bytes32 indexed mandateId, // redeemer-asserted (unsigned)
39
+ address indexed payer, // the root delegator whose funds moved
40
+ address indexed payee,
41
+ address asset,
42
+ uint256 amount,
43
+ bytes32 resourceHash, // redeemer-asserted (unsigned)
44
+ bytes32 delegationHash,
45
+ bytes32 nonce
46
+ );
47
+ event EnforcerSet(address indexed enforcer);
48
+
49
+ error NotOwner();
50
+ error NotEnforcer();
51
+ error EnforcerAlreadySet();
52
+ error ZeroAddress();
53
+
54
+ /// @notice A DIRECT deployment: the deployer is the owner, and there is no upgrade governance (frozen code, as
55
+ /// before). Spec 447 — behind a stable proxy, `initialize(governance_, owner_)` instead.
56
+ constructor() initializer {
57
+ owner = msg.sender;
58
+ }
59
+
60
+ /// @notice Spec 447 — the proxy's initializer: `governance_` is the upgrade authority; `owner_` wires the
61
+ /// enforcer once, as the deployer does for a direct deployment. Once per proxy.
62
+ function initialize(address governance_, address owner_) external initializer {
63
+ if (owner_ == address(0)) revert ZeroAddress();
64
+ _initializeGovernance(governance_);
65
+ owner = owner_;
66
+ }
67
+
68
+ /// @dev The one-argument path would leave `owner` unset (nobody could ever wire the enforcer); refused.
69
+ function initialize(address) external pure override {
70
+ revert ZeroAddress();
71
+ }
72
+
73
+ /// @notice One-time wiring: authorize the deployed {PaymentEnforcer} as the sole recorder.
74
+ function setEnforcer(address enforcer_) external {
75
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
76
+ if (msg.sender != owner) revert NotOwner();
77
+ if (enforcer != address(0)) revert EnforcerAlreadySet();
78
+ if (enforcer_ == address(0)) revert ZeroAddress();
79
+ enforcer = enforcer_;
80
+ emit EnforcerSet(enforcer_);
81
+ }
82
+
83
+ /// @notice Record a settled payment. Reverts unless called by the authorized enforcer.
84
+ function record(
85
+ bytes32 mandateId,
86
+ address payer,
87
+ address payee,
88
+ address asset,
89
+ uint256 amount,
90
+ bytes32 resourceHash,
91
+ bytes32 delegationHash,
92
+ bytes32 nonce
93
+ ) external {
94
+ if (msg.sender != enforcer) revert NotEnforcer();
95
+ emit PaymentSettled(mandateId, payer, payee, asset, amount, resourceHash, delegationHash, nonce);
96
+ }
97
+
98
+ /// @dev Spec 447 — storage gap: the registry sits behind a stable proxy (the payment enforcer holds its address); layout gated by `check:storage-layouts`.
99
+ uint256[48] private __gap;
100
+ }
@@ -0,0 +1,67 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+ import "../governance/StableProxyGoverned.sol";
4
+ import {Eip7702} from "../libraries/Eip7702.sol";
5
+
6
+ /**
7
+ * @title ReceiptAnchorRegistry
8
+ * @notice The on-chain ANCHOR for a harness receipt (spec 351 P0.6, spec 406 W2): a run's record digest, bound
9
+ * to the intent digest the mandate was over and the mandate's reference, anchored once by the acting
10
+ * runtime's agent. A counterparty who holds the record recomputes its digest and reads the anchor here —
11
+ * no trust in the runtime's logs, no vendor, no vault: the chain says a runtime with THIS agent's key
12
+ * committed to THESE bytes at THIS block, and the intent digest says which ask it was under.
13
+ *
14
+ * @dev DIGESTS AND ADDRESSES ONLY — nothing of what the run was about reaches the chain (the S1 firewall of
15
+ * spec 395 holds by construction). Per-row storage, so a reader uses `readContract` (ADR-0012: no log
16
+ * walks in product paths); the event is for indexers. Anchoring is permissionless: WHO anchored is the
17
+ * evidence (`anchoredBy`), never a gate — a stranger anchoring random digests proves nothing about a
18
+ * run whose receipt names a different agent. A digest anchors ONCE PER ANCHORER (R917-C-3, spec 408
19
+ * §1.5): rows are keyed by `(anchoredBy, receiptDigest)`, so a front-runner on a public mempool cannot
20
+ * squat the digest ahead of the agent, and an anchor cannot be re-attributed after the fact.
21
+ */
22
+ contract ReceiptAnchorRegistry is StableProxyGoverned {
23
+ /// @notice Spec 447 — a DIRECT deployment, initialized here with no governance (its code is frozen, as
24
+ /// before). Behind a stable proxy, `initialize(governance_)` instead; the governance is then the only
25
+ /// upgrade authority. This contract has no admin of its own: governance can replace the code behind
26
+ /// the proxy and nothing else.
27
+ constructor() initializer {}
28
+
29
+ struct Anchor {
30
+ address anchoredBy;
31
+ uint64 at;
32
+ bytes32 intentDigest;
33
+ bytes32 mandateRef;
34
+ }
35
+
36
+ /// anchoredBy => receiptDigest => anchor (R917-C-3: keyed by WHO anchored, so a stranger's anchor of
37
+ /// the same digest is a different row — it can neither pre-empt the agent's nor be mistaken for it).
38
+ mapping(address => mapping(bytes32 => Anchor)) private _anchors;
39
+
40
+ event ReceiptAnchored(bytes32 indexed receiptDigest, address indexed anchoredBy, bytes32 indexed intentDigest, bytes32 mandateRef, uint64 at);
41
+
42
+ error ZeroDigest();
43
+ error AlreadyAnchored(bytes32 receiptDigest, address by);
44
+
45
+ /// @notice Anchor a receipt digest, once per anchorer. `intentDigest` and `mandateRef` may be zero for a run under no mandate (a read).
46
+ function anchor(bytes32 receiptDigest, bytes32 intentDigest, bytes32 mandateRef) external {
47
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
48
+ if (receiptDigest == bytes32(0)) revert ZeroDigest();
49
+ Anchor storage a = _anchors[msg.sender][receiptDigest];
50
+ if (a.anchoredBy != address(0)) revert AlreadyAnchored(receiptDigest, a.anchoredBy);
51
+ _anchors[msg.sender][receiptDigest] = Anchor({ anchoredBy: msg.sender, at: uint64(block.timestamp), intentDigest: intentDigest, mandateRef: mandateRef });
52
+ emit ReceiptAnchored(receiptDigest, msg.sender, intentDigest, mandateRef, uint64(block.timestamp));
53
+ }
54
+
55
+ /// @notice The anchor `anchoredBy` made of a digest, or a zero struct when none — the reader names the
56
+ /// agent from the receipt it holds, and decides what absence means.
57
+ function anchorOf(address anchoredBy, bytes32 receiptDigest) external view returns (Anchor memory) {
58
+ return _anchors[anchoredBy][receiptDigest];
59
+ }
60
+
61
+ function isAnchored(address anchoredBy, bytes32 receiptDigest) external view returns (bool) {
62
+ return _anchors[anchoredBy][receiptDigest].anchoredBy != address(0);
63
+ }
64
+
65
+ /// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
66
+ uint256[49] private __gap;
67
+ }
@@ -0,0 +1,372 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ import {IRegistryMembershipPolicy} from "./IRegistryMembershipPolicy.sol";
5
+ import {Eip7702} from "../libraries/Eip7702.sol";
6
+ import "../governance/StableProxyGoverned.sol";
7
+
8
+ /**
9
+ * @title AgentRegistryBase
10
+ * @notice The generic, SA-anchored registry base that vertical registries are built FROM (spec 279 §4,
11
+ * ADR-0038 "many-registries"). It is a MEMBERSHIP LEDGER of facets — entries that point AT a
12
+ * Smart Agent address — not an account. It holds no funds, signs nothing, executes nothing, and
13
+ * grants NO authority to act: an entry is evidence ("this SA is a member of registry R, here is
14
+ * its card hash + binding-proof hash + claims"), never a delegation. Authority lives in the
15
+ * AgentAccount + DelegationManager; this contract only records and gates membership.
16
+ *
17
+ * ─── How it differs from AgentAccount ───
18
+ * AgentAccount IS the agent (ERC-4337/7579 custody + execution + ERC-1271). AgentRegistryBase is
19
+ * a directory of MANY entries pointing at MANY agents, one instance per registry. The subject SA
20
+ * controls its own entry because it must be the caller (RB-01); the registry's controller / policy
21
+ * hook gates admission + ejection (RB-02/03). The binding proof referenced by `bindingProofHash`
22
+ * is verified OFF-CHAIN by a verifier (registry-kit `verifyEntryBindingProof`) against the
23
+ * subject SA's ERC-1271 — this contract stores the hash as a pointer, it does not re-verify it.
24
+ *
25
+ * ─── Key invariants (RB-*) ───
26
+ * RB-01 entry control follows the subject SA custody policy — register / renew / self-revoke /
27
+ * self-update require `msg.sender == subjectAgent` (so the SA's own custody produced the
28
+ * call); the contract never re-implements custody.
29
+ * RB-02 admission is gated by the registry's pluggable membership hook (or open if unset); a
30
+ * policy returning false OR reverting fails closed (ADR-0013) — no second path.
31
+ * RB-03 suspension / revocation / claim-update by a non-subject require the registry controller
32
+ * OR a policy-authorized actor (`canAdminister`); never an arbitrary caller.
33
+ * RB-04 revocation is terminal; a revoked entry cannot be renewed, re-registered, suspended, or
34
+ * claim-updated.
35
+ * RB-05 NO external-registry-protocol fields in storage (no ENS/8004/HCS/OASF) — those are
36
+ * external projections (ADR-0037), not AP state.
37
+ * RB-06 reads are storage views only — discovery never scans chain logs (ADR-0012); the indexer
38
+ * consumes the events below.
39
+ * RB-07 epoch-bucket registration timestamps (raw block.timestamp never stored); `expiresAt` is a
40
+ * caller-supplied absolute unix-seconds bound compared against block.timestamp for liveness.
41
+ *
42
+ * Spec 279 §4 + ADR-0010 / 0012 / 0013 / 0037 / 0038.
43
+ */
44
+ contract AgentRegistryBase is StableProxyGoverned {
45
+ /// @notice Spec 447 — a DIRECT deployment, initialized here with no governance (its code is frozen, as
46
+ /// before). Behind a stable proxy, `initialize(governance_)` instead; the governance is then the only
47
+ /// upgrade authority. This contract has no admin of its own: governance can replace the code behind
48
+ /// the proxy and nothing else.
49
+ constructor() initializer {}
50
+
51
+ // ─── Constants ──────────────────────────────────────────────────────
52
+
53
+ /// @dev RB-07 — registration time is bucketed (provenance, not a precise clock). Mirrors AttestationRegistry.
54
+ uint64 public constant EPOCH_SECONDS = 3600;
55
+
56
+ // ─── Types ──────────────────────────────────────────────────────────
57
+
58
+ /// @dev Stored status. `Expired` is NOT stored (no keeper to flip it) — it is DERIVED from `expiresAt`
59
+ /// by {isActive}; storage only tracks the explicit lifecycle transitions.
60
+ enum EntryStatus {
61
+ None,
62
+ Active,
63
+ Suspended,
64
+ Revoked
65
+ }
66
+
67
+ struct Registry {
68
+ address controller; // the governing SA (set on create); address(0) iff !exists
69
+ address policy; // pluggable membership hook; address(0) = open registry (subject self-service only)
70
+ bool exists;
71
+ }
72
+
73
+ struct Entry {
74
+ address subjectAgent; // the canonical SA this entry is a facet of
75
+ bytes32 cardHash; // sha256 of the agent-profile signed card bundle
76
+ bytes32 bindingProofHash; // sha256 of the off-chain binding proof (verified off-chain, not here)
77
+ bytes32 claimsRoot; // keccak of the registration-time claimHashes[] (the set the binding proof signed)
78
+ EntryStatus status;
79
+ uint64 registeredAtBucket; // block.timestamp / EPOCH_SECONDS at registration
80
+ uint64 expiresAt; // absolute unix seconds; 0 = non-expiring
81
+ }
82
+
83
+ // ─── Storage ────────────────────────────────────────────────────────
84
+
85
+ mapping(bytes32 => Registry) private _registries; // registryId => Registry
86
+ /// @notice REG-10 — registryId => the successor the controller named, until it accepts.
87
+ mapping(bytes32 => address) public pendingControllerOf;
88
+ mapping(bytes32 => Entry) private _entries; // entryKey => Entry
89
+ mapping(bytes32 => mapping(bytes32 => bytes32)) private _claims; // entryKey => claimSlotId => claimHash
90
+
91
+ // ─── Errors ─────────────────────────────────────────────────────────
92
+
93
+ error RegistryExists();
94
+ error RegistryNotFound();
95
+ error NotController();
96
+ error EntryExists();
97
+ error EntryNotFound();
98
+ error ZeroSubject();
99
+ error SubjectMismatch(); // msg.sender is not the entry's subject SA (RB-01)
100
+ error NotAuthorized(); // msg.sender is neither controller nor a policy-authorized admin (RB-03)
101
+ error NotActive();
102
+ error AlreadyRevoked();
103
+ error InvalidExpiry();
104
+ error MembershipDenied(); // RB-02 fail-closed admission denial
105
+ error NotSuspended(); // REG-10: reinstateEntry on an entry that is not Suspended
106
+ error NotPendingController(); // REG-10: acceptController by anyone but the named successor
107
+
108
+ // ─── Events ─────────────────────────────────────────────────────────
109
+
110
+ // Registry provisioning (not part of the registry-kit lifecycle ABI).
111
+ event RegistryCreated(bytes32 indexed registryId, address indexed controller, address policy);
112
+ event RegistryPolicyUpdated(bytes32 indexed registryId, address policy);
113
+ event RegistryControllerTransferStarted(bytes32 indexed registryId, address indexed controller, address indexed pendingController);
114
+ event RegistryControllerTransferred(bytes32 indexed registryId, address indexed previousController, address indexed controller);
115
+ event RegistryEntryReinstated(bytes32 indexed registryId, bytes32 indexed entryId, bytes32 reasonHash);
116
+
117
+ // Entry lifecycle — MUST match registry-kit `AGENT_REGISTRY_BASE_ABI` + spec 279 §4.1 EXACTLY
118
+ // (the SDK encodes calls against / decodes logs from these signatures).
119
+ event RegistryEntryRegistered(
120
+ bytes32 indexed registryId,
121
+ bytes32 indexed entryId,
122
+ address indexed subjectAgent,
123
+ bytes32 cardHash,
124
+ bytes32 bindingProofHash
125
+ );
126
+ event RegistryEntryUpdated(
127
+ bytes32 indexed registryId,
128
+ bytes32 indexed entryId,
129
+ bytes32 cardHash,
130
+ bytes32 bindingProofHash
131
+ );
132
+ event RegistryEntryRenewed(bytes32 indexed registryId, bytes32 indexed entryId, uint64 expiresAt);
133
+ event RegistryEntrySuspended(bytes32 indexed registryId, bytes32 indexed entryId, bytes32 reasonHash);
134
+ event RegistryEntryRevoked(bytes32 indexed registryId, bytes32 indexed entryId, bytes32 reasonHash);
135
+ event RegistryClaimUpdated(
136
+ bytes32 indexed registryId, bytes32 indexed entryId, bytes32 indexed claimSlotId, bytes32 claimHash
137
+ );
138
+
139
+ // ─── Registry provisioning ──────────────────────────────────────────
140
+
141
+ /// @notice Create a registry. Permissionless + first-create-wins: `msg.sender` becomes the controller.
142
+ /// @dev `registryId` is `keccak256(urn:ap:registry:…)` off-chain; squatting on an id is a PROVISIONING
143
+ /// concern (create the registry in the same flow that mints its urn), out of scope for this base.
144
+ /// `policy == address(0)` ⇒ open registry: any SA may self-register, no admission gate.
145
+ function createRegistry(bytes32 registryId, address policy) external {
146
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
147
+ if (_registries[registryId].exists) revert RegistryExists();
148
+ _registries[registryId] = Registry({controller: msg.sender, policy: policy, exists: true});
149
+ emit RegistryCreated(registryId, msg.sender, policy);
150
+ }
151
+
152
+ /// @notice REG-10 — name a successor controller (zero cancels). Two steps: the controller keeps the
153
+ /// role until the successor accepts, so a registry created by a bootstrap key can be handed to
154
+ /// a multisig, and a compromised controller rotated out, without risking a dead address.
155
+ function transferController(bytes32 registryId, address newController) external {
156
+ Registry storage r = _registries[registryId];
157
+ if (!r.exists) revert RegistryNotFound();
158
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
159
+ if (msg.sender != r.controller) revert NotController();
160
+ pendingControllerOf[registryId] = newController;
161
+ emit RegistryControllerTransferStarted(registryId, msg.sender, newController);
162
+ }
163
+
164
+ /// @notice REG-10 — take the controller role. Only the successor the controller named.
165
+ function acceptController(bytes32 registryId) external {
166
+ Registry storage r = _registries[registryId];
167
+ if (!r.exists) revert RegistryNotFound();
168
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
169
+ if (msg.sender != pendingControllerOf[registryId]) revert NotPendingController();
170
+ emit RegistryControllerTransferred(registryId, r.controller, msg.sender);
171
+ r.controller = msg.sender;
172
+ pendingControllerOf[registryId] = address(0);
173
+ }
174
+
175
+ /// @notice Swap the pluggable membership hook. Controller only.
176
+ function setRegistryPolicy(bytes32 registryId, address policy) external {
177
+ Registry storage r = _registries[registryId];
178
+ if (!r.exists) revert RegistryNotFound();
179
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
180
+ if (msg.sender != r.controller) revert NotController();
181
+ r.policy = policy;
182
+ emit RegistryPolicyUpdated(registryId, policy);
183
+ }
184
+
185
+ // ─── Entry lifecycle ────────────────────────────────────────────────
186
+
187
+ /// @notice Register a facet of `subjectAgent`. RB-01: the subject SA must be the caller. RB-02: the
188
+ /// registry's membership hook (if any) must admit. Signature ABI matches registry-kit.
189
+ function registerEntry(
190
+ bytes32 registryId,
191
+ bytes32 entryId,
192
+ address subjectAgent,
193
+ bytes32 cardHash,
194
+ bytes32 bindingProofHash,
195
+ bytes32[] calldata claimHashes,
196
+ uint64 expiresAt
197
+ ) external {
198
+ Registry storage r = _registries[registryId];
199
+ if (!r.exists) revert RegistryNotFound();
200
+ if (subjectAgent == address(0)) revert ZeroSubject();
201
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
202
+ if (msg.sender != subjectAgent) revert SubjectMismatch(); // RB-01
203
+ if (expiresAt != 0 && expiresAt <= block.timestamp) revert InvalidExpiry();
204
+
205
+ bytes32 key = _entryKey(registryId, entryId);
206
+ if (_entries[key].status != EntryStatus.None) revert EntryExists();
207
+
208
+ // RB-02 — admission gate, fail-closed: a false return OR a revert blocks registration.
209
+ address policy = r.policy;
210
+ if (policy != address(0)) {
211
+ try IRegistryMembershipPolicy(policy)
212
+ .canRegister(registryId, entryId, subjectAgent, cardHash, claimHashes) returns (
213
+ bool ok
214
+ ) {
215
+ if (!ok) revert MembershipDenied();
216
+ } catch {
217
+ revert MembershipDenied();
218
+ }
219
+ }
220
+
221
+ _entries[key] = Entry({
222
+ subjectAgent: subjectAgent,
223
+ cardHash: cardHash,
224
+ bindingProofHash: bindingProofHash,
225
+ claimsRoot: keccak256(abi.encode(claimHashes)),
226
+ status: EntryStatus.Active,
227
+ registeredAtBucket: uint64(block.timestamp) / EPOCH_SECONDS,
228
+ expiresAt: expiresAt
229
+ });
230
+
231
+ emit RegistryEntryRegistered(registryId, entryId, subjectAgent, cardHash, bindingProofHash);
232
+ }
233
+
234
+ /// @notice Extend an active entry's expiry. RB-01: subject SA only. RB-04: a revoked/suspended entry
235
+ /// cannot be renewed.
236
+ function renewEntry(bytes32 registryId, bytes32 entryId, uint64 expiresAt) external {
237
+ Entry storage e = _entries[_entryKey(registryId, entryId)];
238
+ if (e.status == EntryStatus.None) revert EntryNotFound();
239
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
240
+ if (msg.sender != e.subjectAgent) revert SubjectMismatch(); // RB-01
241
+ if (e.status != EntryStatus.Active) revert NotActive(); // RB-04 (Suspended/Revoked)
242
+ if (expiresAt != 0 && expiresAt <= block.timestamp) revert InvalidExpiry();
243
+ e.expiresAt = expiresAt;
244
+ emit RegistryEntryRenewed(registryId, entryId, expiresAt);
245
+ }
246
+
247
+ /// @notice Re-point an ACTIVE entry at a newer card. RB-01: the subject and only the subject.
248
+ /// @dev Cards are versioned and republished; without this an entry is pinned forever to whatever card it
249
+ /// was registered with, so a directory could never reflect a new release (found live 2026-08-30: the only
250
+ /// paths were `registerEntry`, which reverts `EntryExists`, and `renewEntry`, which moves only the expiry).
251
+ /// The subject re-signs: `bindingProofHash` covers the new card, so an update proves the same thing a
252
+ /// registration does. Membership is NOT re-checked — admission decided this agent belongs; which card it
253
+ /// publishes is not an admission question (a registry that disagrees can suspend the entry).
254
+ function updateEntry(
255
+ bytes32 registryId,
256
+ bytes32 entryId,
257
+ bytes32 cardHash,
258
+ bytes32 bindingProofHash,
259
+ bytes32[] calldata claimHashes
260
+ ) external {
261
+ Entry storage e = _entries[_entryKey(registryId, entryId)];
262
+ if (e.status == EntryStatus.None) revert EntryNotFound();
263
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
264
+ if (msg.sender != e.subjectAgent) revert SubjectMismatch(); // RB-01
265
+ if (e.status != EntryStatus.Active) revert NotActive(); // RB-04 (Suspended/Revoked)
266
+
267
+ e.cardHash = cardHash;
268
+ e.bindingProofHash = bindingProofHash;
269
+ e.claimsRoot = keccak256(abi.encode(claimHashes));
270
+
271
+ emit RegistryEntryUpdated(registryId, entryId, cardHash, bindingProofHash);
272
+ }
273
+
274
+ /// @notice Suspend an active entry. RB-03: admin action (controller or policy-authorized) — NOT subject.
275
+ function suspendEntry(bytes32 registryId, bytes32 entryId, bytes32 reasonHash) external {
276
+ Entry storage e = _entries[_entryKey(registryId, entryId)];
277
+ if (e.status == EntryStatus.None) revert EntryNotFound();
278
+ _requireAdmin(registryId, entryId); // RB-03
279
+ if (e.status != EntryStatus.Active) revert NotActive();
280
+ e.status = EntryStatus.Suspended;
281
+ emit RegistryEntrySuspended(registryId, entryId, reasonHash);
282
+ }
283
+
284
+ /// @notice REG-10 — lift a suspension (Suspended → Active). Same authority as `suspendEntry`. Before
285
+ /// this, the only exit from Suspended was `revokeEntry`, which is terminal and burns the id.
286
+ function reinstateEntry(bytes32 registryId, bytes32 entryId, bytes32 reasonHash) external {
287
+ Entry storage e = _entries[_entryKey(registryId, entryId)];
288
+ if (e.status == EntryStatus.None) revert EntryNotFound();
289
+ _requireAdmin(registryId, entryId); // RB-03
290
+ if (e.status != EntryStatus.Suspended) revert NotSuspended();
291
+ e.status = EntryStatus.Active;
292
+ emit RegistryEntryReinstated(registryId, entryId, reasonHash);
293
+ }
294
+
295
+ /// @notice Revoke an entry (terminal). The subject SA may leave; the controller / policy-admin may eject.
296
+ function revokeEntry(bytes32 registryId, bytes32 entryId, bytes32 reasonHash) external {
297
+ Entry storage e = _entries[_entryKey(registryId, entryId)];
298
+ if (e.status == EntryStatus.None) revert EntryNotFound();
299
+ if (msg.sender != e.subjectAgent) _requireAdmin(registryId, entryId); // subject (leave) or admin (eject)
300
+ if (e.status == EntryStatus.Revoked) revert AlreadyRevoked(); // RB-04
301
+ e.status = EntryStatus.Revoked;
302
+ emit RegistryEntryRevoked(registryId, entryId, reasonHash);
303
+ }
304
+
305
+ /// @notice Set a per-slot claim hash. Subject self-service OR admin (issuer/registry-managed claims).
306
+ /// @dev Distinct from `claimsRoot` (the immutable snapshot the binding proof signed at registration):
307
+ /// this is the mutable, slot-keyed projection the indexer reads for discovery.
308
+ function updateClaim(bytes32 registryId, bytes32 entryId, bytes32 claimSlotId, bytes32 claimHash) external {
309
+ bytes32 key = _entryKey(registryId, entryId);
310
+ Entry storage e = _entries[key];
311
+ if (e.status == EntryStatus.None) revert EntryNotFound();
312
+ if (e.status == EntryStatus.Revoked) revert AlreadyRevoked(); // RB-04
313
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
314
+ if (msg.sender != e.subjectAgent) _requireAdmin(registryId, entryId);
315
+ _claims[key][claimSlotId] = claimHash;
316
+ emit RegistryClaimUpdated(registryId, entryId, claimSlotId, claimHash);
317
+ }
318
+
319
+ // ─── Views (RB-06: discovery reads use these, never log scans) ──────
320
+
321
+ function getRegistry(bytes32 registryId) external view returns (Registry memory) {
322
+ Registry memory r = _registries[registryId];
323
+ if (!r.exists) revert RegistryNotFound();
324
+ return r;
325
+ }
326
+
327
+ function getEntry(bytes32 registryId, bytes32 entryId) external view returns (Entry memory) {
328
+ Entry memory e = _entries[_entryKey(registryId, entryId)];
329
+ if (e.status == EntryStatus.None) revert EntryNotFound();
330
+ return e;
331
+ }
332
+
333
+ /// @notice Effective liveness: stored-Active AND not past `expiresAt`. A missing entry returns false
334
+ /// (empty is an answer, ADR-0013 — not a trigger for a fallback lookup).
335
+ function isActive(bytes32 registryId, bytes32 entryId) external view returns (bool) {
336
+ Entry memory e = _entries[_entryKey(registryId, entryId)];
337
+ if (e.status != EntryStatus.Active) return false;
338
+ if (e.expiresAt != 0 && block.timestamp > e.expiresAt) return false;
339
+ return true;
340
+ }
341
+
342
+ /// @notice The current hash for a claim slot (0 if unset). Slot semantics are defined by the registry.
343
+ function getClaim(bytes32 registryId, bytes32 entryId, bytes32 claimSlotId) external view returns (bytes32) {
344
+ return _claims[_entryKey(registryId, entryId)][claimSlotId];
345
+ }
346
+
347
+ // ─── Internal ───────────────────────────────────────────────────────
348
+
349
+ function _entryKey(bytes32 registryId, bytes32 entryId) internal pure returns (bytes32) {
350
+ return keccak256(abi.encodePacked(registryId, entryId));
351
+ }
352
+
353
+ /// @dev RB-03 — controller passes; otherwise the pluggable policy may authorize the actor. Fail-closed:
354
+ /// no policy, a false return, or a revert all deny.
355
+ function _requireAdmin(bytes32 registryId, bytes32 entryId) internal view {
356
+ Registry storage r = _registries[registryId];
357
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
358
+ if (msg.sender == r.controller) return;
359
+ address policy = r.policy;
360
+ if (policy != address(0)) {
361
+ try IRegistryMembershipPolicy(policy).canAdminister(registryId, entryId, msg.sender) returns (bool ok) {
362
+ if (ok) return;
363
+ } catch {
364
+ // fail-closed: treat a reverting policy as denial
365
+ }
366
+ }
367
+ revert NotAuthorized();
368
+ }
369
+
370
+ /// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
371
+ uint256[46] private __gap;
372
+ }