@agenticprimitives/contracts 1.0.0-alpha.46 → 1.0.0-alpha.48

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 (82) hide show
  1. package/AUDIT.md +60 -26
  2. package/deployments-base-sepolia.json +2 -0
  3. package/deployments-faithchain.json +94 -66
  4. package/deployments-hopechain.json +71 -50
  5. package/dist/abi/AgentAccount.json +175 -0
  6. package/dist/abi/AgentAccountFactory.json +47 -0
  7. package/dist/abi/AgentNameAttributeResolver.json +24 -0
  8. package/dist/abi/AgentNameRegistry.json +369 -0
  9. package/dist/abi/AgentNameUniversalResolver.json +34 -0
  10. package/dist/abi/AgentProfileResolver.json +48 -0
  11. package/dist/abi/AgentRegistryBase.json +158 -0
  12. package/dist/abi/AgentRelationship.json +212 -0
  13. package/dist/abi/AgreementRegistry.json +10 -0
  14. package/dist/abi/AttestationRegistry.json +49 -0
  15. package/dist/abi/AttributeStorage.json +24 -0
  16. package/dist/abi/CustodyPolicy.json +184 -0
  17. package/dist/abi/DelegationManager.json +96 -0
  18. package/dist/abi/DigestBindingEnforcer.json +103 -1
  19. package/dist/abi/EstateProjectionRegistry.json +137 -24
  20. package/dist/abi/GeoFeatureRegistry.json +42 -0
  21. package/dist/abi/IAgentAccountFactoryView.json +13 -0
  22. package/dist/abi/IAgentAccountGovernanceTimelockView.json +15 -0
  23. package/dist/abi/ICustodyPolicyFactoryView.json +13 -0
  24. package/dist/abi/ICustodyPolicyPasskeyView.json +50 -0
  25. package/dist/abi/IRedemptionContext.json +15 -0
  26. package/dist/abi/ITreasurySpendPolicyAccountView.json +44 -0
  27. package/dist/abi/IUpgradeVoucherView.json +26 -0
  28. package/dist/abi/OntologyTermRegistry.json +57 -0
  29. package/dist/abi/PaymentEnforcer.json +10 -0
  30. package/dist/abi/PermissionlessSubregistry.json +165 -0
  31. package/dist/abi/PricedSubregistry.json +57 -0
  32. package/dist/abi/RelationshipTypeRegistry.json +57 -0
  33. package/dist/abi/ShapeRegistry.json +57 -0
  34. package/dist/abi/SkillDefinitionRegistry.json +42 -0
  35. package/dist/abi/TreasurySpendPolicy.json +106 -1
  36. package/dist/abi/UpgradeVoucher.json +176 -0
  37. package/dist/abi/index.d.ts +6 -0
  38. package/dist/abi/index.js +6 -0
  39. package/dist/deployments/base-sepolia.d.ts +2 -0
  40. package/dist/deployments/base-sepolia.js +4 -0
  41. package/dist/deployments/faithchain.d.ts +35 -13
  42. package/dist/deployments/faithchain.js +95 -67
  43. package/dist/deployments/hopechain.d.ts +20 -5
  44. package/dist/deployments/hopechain.js +72 -51
  45. package/package.json +1 -1
  46. package/src/AgentAccount.sol +531 -92
  47. package/src/AgentAccountFactory.sol +28 -2
  48. package/src/IAgentAccount.sol +14 -0
  49. package/src/SmartAgentPaymaster.sol +30 -3
  50. package/src/UpgradeVoucher.sol +74 -0
  51. package/src/agency/DelegationManager.sol +177 -52
  52. package/src/agency/ICaveatEnforcer.sol +10 -0
  53. package/src/agency/IDelegationManager.sol +6 -5
  54. package/src/agreement/AgreementRegistry.sol +61 -17
  55. package/src/attestation/AttestationRegistry.sol +115 -22
  56. package/src/custody/CustodyPolicy.sol +393 -47
  57. package/src/custody/TreasurySpendPolicy.sol +192 -29
  58. package/src/enforcers/AllowedMethodsEnforcer.sol +6 -1
  59. package/src/enforcers/AllowedTargetsEnforcer.sol +6 -1
  60. package/src/enforcers/DigestBindingEnforcer.sol +91 -19
  61. package/src/enforcers/PaymentEnforcer.sol +32 -1
  62. package/src/enforcers/QuorumEnforcer.sol +1 -1
  63. package/src/enforcers/ValueEnforcer.sol +6 -1
  64. package/src/geo/GeoFeatureRegistry.sol +25 -1
  65. package/src/governance/AgenticGovernance.sol +16 -0
  66. package/src/identity/AgentProfileResolver.sol +11 -0
  67. package/src/naming/AgentNameAttributeResolver.sol +17 -2
  68. package/src/naming/AgentNamePredicates.sol +1 -1
  69. package/src/naming/AgentNameRegistry.sol +205 -10
  70. package/src/naming/AgentNameUniversalResolver.sol +26 -0
  71. package/src/naming/PermissionlessSubregistry.sol +69 -23
  72. package/src/naming/PricedSubregistry.sol +28 -0
  73. package/src/ontology/AttributeStorage.sol +93 -80
  74. package/src/ontology/OntologyTermRegistry.sol +28 -0
  75. package/src/ontology/ShapeRegistry.sol +28 -0
  76. package/src/payments/PaymentEscrow.sol +23 -15
  77. package/src/payments/PaymentReceiptRegistry.sol +11 -3
  78. package/src/registry/AgentRegistryBase.sol +39 -0
  79. package/src/registry/EstateProjectionRegistry.sol +94 -40
  80. package/src/relationships/AgentRelationship.sol +112 -7
  81. package/src/relationships/RelationshipTypeRegistry.sol +28 -0
  82. package/src/skills/SkillDefinitionRegistry.sol +25 -1
@@ -50,6 +50,8 @@ contract GeoFeatureRegistry {
50
50
  error FeatureNotFound();
51
51
  error EmptyMetadata();
52
52
  error EmptyId();
53
+ /// @notice REG-15 — `setValidity` may only end a version's window earlier.
54
+ error ValidityNotNarrowed();
53
55
 
54
56
  // ─── Storage ────────────────────────────────────────────────────────
55
57
  struct FeatureRecord {
@@ -167,7 +169,12 @@ contract GeoFeatureRegistry {
167
169
  FeatureRecord storage r = _records[featureId][version];
168
170
  if (r.version == 0) revert FeatureNotFound();
169
171
  if (msg.sender != r.stewardAccount) revert NotSteward();
170
- r.validAfter = validAfter;
172
+ // REG-15: a published version's window can be ENDED, never rewritten. `validAfter` is fixed at
173
+ // publish; `validUntil` may be set (0 → a time) or moved earlier, not extended or cleared — a
174
+ // credential that pinned this version must not find its window widened after the fact. To extend,
175
+ // publish a new version.
176
+ if (validAfter != r.validAfter) revert ValidityNotNarrowed();
177
+ if (validUntil == 0 || (r.validUntil != 0 && validUntil > r.validUntil)) revert ValidityNotNarrowed();
171
178
  r.validUntil = validUntil;
172
179
  emit FeatureValidityChanged(featureId, version, validAfter, validUntil);
173
180
  }
@@ -175,6 +182,8 @@ contract GeoFeatureRegistry {
175
182
  // ─── Views ──────────────────────────────────────────────────────────
176
183
  function getFeature(bytes32 featureId, uint64 version) external view returns (FeatureRecord memory) {
177
184
  FeatureRecord memory r = _records[featureId][version];
185
+ // Zero-default existence check (versions are 1-based) — benign.
186
+ // slither-disable-next-line incorrect-equality
178
187
  if (r.version == 0) revert FeatureNotFound();
179
188
  return r;
180
189
  }
@@ -194,4 +203,19 @@ contract GeoFeatureRegistry {
194
203
  function allFeatures() external view returns (bytes32[] memory) {
195
204
  return _allFeatures;
196
205
  }
206
+
207
+ function featureCount() external view returns (uint256) {
208
+ return _allFeatures.length;
209
+ }
210
+
211
+ /// @notice REG-12 — a bounded window of the id index: `limit` ids from `offset` (fewer at the end).
212
+ /// `allFeatures()` is unbounded (anyone may publish a new id) and is kept for small deployments.
213
+ function allFeaturesPage(uint256 offset, uint256 limit) external view returns (bytes32[] memory page) {
214
+ uint256 n = _allFeatures.length;
215
+ if (offset >= n) return new bytes32[](0);
216
+ uint256 end = offset + limit;
217
+ if (end > n) end = n;
218
+ page = new bytes32[](end - offset);
219
+ for (uint256 i = offset; i < end; i++) page[i - offset] = _allFeatures[i];
220
+ }
197
221
  }
@@ -33,6 +33,22 @@ import "./IGovernance.sol";
33
33
  * with a long-lived multisig (an `AgentAccount` deployed by
34
34
  * the factory whose `CustodyPolicy` requires M-of-N signers).
35
35
  * Deployer then renounces the timelock admin role and is gone.
36
+ *
37
+ * A PAUSE IS ALWAYS LIFTABLE BY THOSE ACCOUNTS (spec 445 §1.2, audit 2026-11-10 H-3 / CUST-1).
38
+ * `unpause()` needs the timelock; the timelock needs its proposer and executor to call it; and when
39
+ * those are `AgentAccount`s of the very factory this contract pauses, every outbound call they make
40
+ * is pause-gated. Generation 4 therefore exempts, in `AgentAccount.execute` (the single call only —
41
+ * not `executeBatch`, not `executeFromModule`), a validated user operation whose target is THIS
42
+ * contract or its `timelock`. Both addresses are read from the factory's immutable governance
43
+ * pointer and this contract's immutable `timelock`; nothing an account can write selects them. The
44
+ * exemption grants nothing here: `NotTimelock` / `NotGuardian` and the timelock's own roles still
45
+ * decide. Operational consequences to plan for: (1) the paymaster refuses to sponsor under a pause,
46
+ * so a role-holding account must be able to pay its own gas (an EntryPoint deposit or a native
47
+ * balance); (2) `AgentAccount.execute` validates ONE custodian signature on every custody mode — an
48
+ * account's M-of-N governs its custody changes, not its outbound calls — so a timelock role held by
49
+ * an AgentAccount is exercised by any one of its credentials. `Deploy.s.sol` proves the lift for the
50
+ * roles it installs (`_assertPauseLiftable`); `test/governance/PauseIsLiftable445.t.sol` proves it
51
+ * for every account mode.
36
52
  */
37
53
  contract AgenticGovernance is IGovernanceView {
38
54
  // ─── Immutables ───────────────────────────────────────────────
@@ -188,6 +188,17 @@ contract AgentProfileResolver is AttributeStorage {
188
188
  return _agents;
189
189
  }
190
190
 
191
+ /// @notice REG-12 — a bounded window of the agent index: `limit` agents from `offset`.
192
+ /// `getAllAgents()` is unbounded (any agent may register) and is kept for small deployments.
193
+ function getAgentsPage(uint256 offset, uint256 limit) external view returns (address[] memory page) {
194
+ uint256 n = _agents.length;
195
+ if (offset >= n) return new address[](0);
196
+ uint256 end = offset + limit;
197
+ if (end > n) end = n;
198
+ page = new address[](end - offset);
199
+ for (uint256 i = offset; i < end; i++) page[i - offset] = _agents[i];
200
+ }
201
+
191
202
  function subjectFor(address agent) external pure returns (bytes32) {
192
203
  return bytes32(uint256(uint160(agent)));
193
204
  }
@@ -22,8 +22,8 @@ import "../ontology/AttributeStorage.sol";
22
22
  * Per-spec simplifications kept from the pure key/value port:
23
23
  * - No multi-coin (ENSIP-9) address records. Other-chain identifiers
24
24
  * ride on the `atl:nativeId` predicate (a CAIP-10 string).
25
- * - No aliases, versioning, or operator approvals. Rotation flows
26
- * through the registry's `setOwner` (which changes who may write).
25
+ * - No aliases or operator approvals. Rotation flows through the registry's `setOwner`, which changes
26
+ * who may write AND starts a new record epoch — records never carry over to a new owner (REG-4).
27
27
  *
28
28
  * SDK contract: `agenticprimitives/agent-naming/records` exposes
29
29
  * the same predicate ids and routes encode / decode through the typed
@@ -86,6 +86,21 @@ contract AgentNameAttributeResolver is AttributeStorage {
86
86
  _unset(node, predicate);
87
87
  }
88
88
 
89
+ // ─── Record epoch (spec 445 / REG-4, REG-6) ─────────────────────
90
+
91
+ /// @dev Records are stored under `keccak256(node, ownerEpoch)`. The registry bumps a node's epoch on every
92
+ /// ownership change (`setOwner` to a different owner, or the re-registration of an expired name), so a
93
+ /// new owner starts with NO records: the previous owner's `atl:addr`, `atl:agentType`, endpoints and
94
+ /// card digest stop resolving in the same transaction, with no delete loop and no log scan (ADR-0012 —
95
+ /// the epoch is one `readContract`). A node that is not live (never registered, or EXPIRED) maps to
96
+ /// key zero, which no write path can reach (`_requireAuth` needs a live node, and a live key is always
97
+ /// a hash), so every getter of this resolver answers empty for it.
98
+ function _storageKey(bytes32 node) internal view override returns (bytes32) {
99
+ (bool live, uint64 epoch) = REGISTRY.recordState(node);
100
+ if (!live) return bytes32(0);
101
+ return keccak256(abi.encode(node, epoch));
102
+ }
103
+
89
104
  // ─── Auth ───────────────────────────────────────────────────────
90
105
 
91
106
  function _requireAuth(bytes32 node) internal view {
@@ -116,7 +116,7 @@ library AgentNamePredicates {
116
116
  bytes32 internal constant AGENT_TYPE_HOUSEHOLD = keccak256("household"); // organization-class (spec 368, 2026-09-07)
117
117
 
118
118
  // Per-root `rootKind` tags for the ten typed roots (AgentNameRegistry.initializeRoot). Mirrors
119
- // agent-naming `rootKindForTld`. The legacy roots (.agent / .impact) carry KIND_AGENT.
119
+ // agent-naming `rootKindForTld`. The untyped legacy root (.agent) carries KIND_AGENT.
120
120
  bytes32 internal constant ROOT_KIND_PERSON = keccak256("namespace:Person");
121
121
  bytes32 internal constant ROOT_KIND_ORGANIZATION = keccak256("namespace:Organization");
122
122
  bytes32 internal constant ROOT_KIND_TEAM = keccak256("namespace:Team");
@@ -54,7 +54,18 @@ contract AgentNameRegistry is GovernanceManaged {
54
54
  // The role is INITIALIZATION-ONLY. Once a root is initialized, control
55
55
  // belongs to its `rootOwner` (a smart-agent governance address) — the
56
56
  // initializer cannot rotate it.
57
- address public immutable initializer;
57
+ //
58
+ // Spec 445 (generation 4): the role can be handed over ONCE, in two steps. A bootstrap key
59
+ // initializes the roots, then `transferInitializer(authority)` — from that call on the old
60
+ // initializer holds nothing (`initializer` reads zero, `initializeRoot` refuses everyone) and only
61
+ // the named successor can take the role with `acceptInitializer()`. There is no second hand-over
62
+ // and no path for a stranger: the front-run protection (AUDIT.md invariant 2.6) is unchanged —
63
+ // at every moment at most one address may initialize a root, and it is one the previous holder named.
64
+ address public initializer;
65
+ /// @notice The successor named by `transferInitializer`, until it accepts. Zero otherwise.
66
+ address public pendingInitializer;
67
+ /// @notice True once `transferInitializer` was called — the hand-over is one-shot.
68
+ bool public initializerHandedOver;
58
69
 
59
70
  // ─── Types ──────────────────────────────────────────────────────
60
71
 
@@ -66,6 +77,10 @@ contract AgentNameRegistry is GovernanceManaged {
66
77
  bytes32 labelhash; // keccak256(bytes(label))
67
78
  uint64 expiry; // 0 = no expiry
68
79
  uint64 registeredAt;
80
+ /// @dev REG-4 — owner epoch: bumped on every change of owner (transfer, or re-registration of an
81
+ /// expired name). The attribute resolver keys records by (node, epoch), so records never
82
+ /// carry over to a new owner. Packs into the expiry/registeredAt slot.
83
+ uint64 epoch;
69
84
  }
70
85
 
71
86
  // ─── Errors ─────────────────────────────────────────────────────
@@ -89,6 +104,19 @@ contract AgentNameRegistry is GovernanceManaged {
89
104
  /// permissionless-frontrun vector where any mempool observer
90
105
  /// could claim a TLD before the deployer's first init landed.
91
106
  error NotInitializer(address caller, address initializer);
107
+ /// @notice Spec 445 — the initializer hand-over is one-shot; a second `transferInitializer` is refused.
108
+ error InitializerAlreadyHandedOver();
109
+ /// @notice Spec 445 — `acceptInitializer` by anyone but the named successor.
110
+ error NotPendingInitializer(address caller);
111
+ /// @notice Spec 445 / NAME-8 — the label is reserved (an infrastructure host such as `www`, `api`,
112
+ /// `mtls`, or the label of an initialized typed root) and names no agent.
113
+ error ReservedLabel();
114
+ /// @notice Spec 445 / NAME-8 — under a root that takes the bare DNS host, a label ending in
115
+ /// `-<typed root>` would share the host of `<prefix>.<typed root>`.
116
+ error LabelReadsAsTypedName();
117
+ /// @notice REG-6 — `renew` may only extend: a permanent name stays permanent, an expiry never moves
118
+ /// earlier (a parent that could shorten an expiry could seize a live name).
119
+ error ExpiryNotExtended();
92
120
 
93
121
  // ─── Events ─────────────────────────────────────────────────────
94
122
 
@@ -105,6 +133,13 @@ contract AgentNameRegistry is GovernanceManaged {
105
133
  event ResolverChanged(bytes32 indexed node, address indexed resolver);
106
134
  event SubregistryChanged(bytes32 indexed node, address indexed subregistry);
107
135
  event NameRenewed(bytes32 indexed node, uint64 newExpiry);
136
+ /// @notice REG-4 — the node's owner changed; every record written under an earlier epoch stopped resolving.
137
+ event RecordEpochBumped(bytes32 indexed node, uint64 epoch);
138
+ event LabelBackfilled(bytes32 indexed node, string label);
139
+ event InitializerTransferStarted(address indexed from, address indexed to);
140
+ event InitializerTransferred(address indexed from, address indexed to);
141
+ event ReservedLabelSet(bytes32 indexed labelhash, bool reserved);
142
+ event RootBareHostSet(bytes32 indexed rootNode, bool takesBareHost);
108
143
  event PrimaryNameSet(address indexed agent, bytes32 indexed node);
109
144
  event PrimaryNameCleared(address indexed agent);
110
145
 
@@ -138,6 +173,26 @@ contract AgentNameRegistry is GovernanceManaged {
138
173
 
139
174
  /// @notice Default kind tags downstream callers may use.
140
175
  bytes32 public constant KIND_AGENT = keccak256("namespace:Agent");
176
+ /// @notice The kind of the person root. Persons and the untyped legacy root take the BARE DNS host
177
+ /// `<label>.<zone>`; every other root is typed and takes `<label>-<type>.<zone>` (spec 346 §5).
178
+ bytes32 public constant KIND_PERSON = keccak256("namespace:Person");
179
+
180
+ // ─── Reserved labels + DNS-host injectivity (spec 445 decision 6 / NAME-8) ──────────────────────
181
+ //
182
+ // The SDK refuses these claims (`labelClaimViolation`); a direct contract caller bypassed it. The
183
+ // chain now refuses them on EVERY registration path — `register` is the one function the root
184
+ // owner, `PermissionlessSubregistry.register` and `PricedSubregistry.claim` all end in.
185
+
186
+ /// @notice labelhash → reserved. Seeded at construction with the fixed infrastructure hosts
187
+ /// (`ws www mtls edge api well-known`); governance or the initializer may add or remove.
188
+ mapping(bytes32 => bool) public isReservedLabel;
189
+ /// @notice labelhash → the label of an initialized TYPED root (any root whose kind is not
190
+ /// `KIND_AGENT`). A typed root's label is reserved under every parent, and is the suffix a
191
+ /// label under a bare-host root may not end in.
192
+ mapping(bytes32 => bool) public isTypedRootLabel;
193
+ /// @notice rootNode → does a name under this root take the bare host? Set at `initializeRoot`
194
+ /// from the kind (person or legacy ⇒ true); governance or the initializer may correct it.
195
+ mapping(bytes32 => bool) public rootTakesBareHost;
141
196
 
142
197
  // ─── Constructor (H7-C.4) ───────────────────────────────────────
143
198
 
@@ -150,6 +205,65 @@ contract AgentNameRegistry is GovernanceManaged {
150
205
  constructor(address initializer_, address governance_) GovernanceManaged(governance_) {
151
206
  if (initializer_ == address(0)) revert ZeroOwner();
152
207
  initializer = initializer_;
208
+ // The fixed infrastructure hosts (agent-naming `RESERVED_LABELS` minus the type words, which
209
+ // become reserved when their root is initialized).
210
+ _setReserved(keccak256("ws"), true);
211
+ _setReserved(keccak256("www"), true);
212
+ _setReserved(keccak256("mtls"), true);
213
+ _setReserved(keccak256("edge"), true);
214
+ _setReserved(keccak256("api"), true);
215
+ _setReserved(keccak256("well-known"), true);
216
+ }
217
+
218
+ // ─── Initializer hand-over (spec 445) ───────────────────────────
219
+
220
+ /// @notice Name the successor of the initializer role. One-shot: the caller gives the role up in
221
+ /// this call (it can neither initialize a root nor name another successor afterwards), and
222
+ /// nobody holds it until `to` accepts.
223
+ function transferInitializer(address to) external {
224
+ if (msg.sender != initializer) revert NotInitializer(msg.sender, initializer);
225
+ if (initializerHandedOver) revert InitializerAlreadyHandedOver();
226
+ if (to == address(0)) revert ZeroOwner();
227
+ initializerHandedOver = true;
228
+ pendingInitializer = to;
229
+ initializer = address(0);
230
+ emit InitializerTransferStarted(msg.sender, to);
231
+ }
232
+
233
+ /// @notice Take the initializer role. Only the successor named by `transferInitializer`.
234
+ function acceptInitializer() external {
235
+ address to = pendingInitializer;
236
+ if (to == address(0) || msg.sender != to) revert NotPendingInitializer(msg.sender);
237
+ pendingInitializer = address(0);
238
+ initializer = to;
239
+ emit InitializerTransferred(address(0), to);
240
+ }
241
+
242
+ // ─── Reserved labels / root host shape — naming administration ──
243
+
244
+ /// @dev Governance (the timelocked system authority) or the current initializer (the only account
245
+ /// that may create a root, so strictly the stronger role during bootstrap).
246
+ function _requireNamingAdmin() internal view {
247
+ if (msg.sender != governance && (msg.sender != initializer || initializer == address(0))) revert NotAuthorized();
248
+ }
249
+
250
+ /// @notice Reserve or release labels, by labelhash. Affects FUTURE registrations only.
251
+ function setReservedLabels(bytes32[] calldata labelhashes, bool reserved) external {
252
+ _requireNamingAdmin();
253
+ for (uint256 i = 0; i < labelhashes.length; i++) _setReserved(labelhashes[i], reserved);
254
+ }
255
+
256
+ /// @notice Correct whether names under `rootNode` take the bare DNS host.
257
+ function setRootBareHost(bytes32 rootNode, bool takesBareHost) external {
258
+ _requireNamingAdmin();
259
+ if (!isRoot[rootNode]) revert NodeNotFound();
260
+ rootTakesBareHost[rootNode] = takesBareHost;
261
+ emit RootBareHostSet(rootNode, takesBareHost);
262
+ }
263
+
264
+ function _setReserved(bytes32 lh, bool reserved) internal {
265
+ isReservedLabel[lh] = reserved;
266
+ emit ReservedLabelSet(lh, reserved);
153
267
  }
154
268
 
155
269
  // ─── Namehash Helpers ───────────────────────────────────────────
@@ -170,7 +284,10 @@ contract AgentNameRegistry is GovernanceManaged {
170
284
  /// `normalizeLabel`: a single label of 1..63 bytes drawn from `[a-z0-9-]`, with no leading
171
285
  /// or trailing `-`. Reverts `EmptyLabel` / `InvalidLabel`. Reusable from `register` +
172
286
  /// `initializeRoot` so NO write path can anchor a non-canonical (squattable) label.
173
- function _validateLabel(bytes memory b) internal pure {
287
+ /// @return lastHyphen index of the last `-` in the label, or `type(uint256).max` when it has none
288
+ /// (NAME-8: the caller reads the type suffix a label ends in without a second pass).
289
+ function _validateLabel(bytes memory b) internal pure returns (uint256 lastHyphen) {
290
+ lastHyphen = type(uint256).max;
174
291
  uint256 len = b.length;
175
292
  if (len == 0) revert EmptyLabel();
176
293
  if (len > 63) revert InvalidLabel();
@@ -182,6 +299,7 @@ contract AgentNameRegistry is GovernanceManaged {
182
299
  || (c >= 0x30 && c <= 0x39) // 0-9
183
300
  || c == 0x2d; // -
184
301
  if (!ok) revert InvalidLabel();
302
+ if (c == 0x2d) lastHyphen = i;
185
303
  }
186
304
  }
187
305
 
@@ -203,9 +321,15 @@ contract AgentNameRegistry is GovernanceManaged {
203
321
  // H7-C.4 / CON-NAMING-001: only the immutable initializer may claim a
204
322
  // TLD. The deploy script bundles deploy+init in one transaction so no
205
323
  // frontrun window exists.
324
+ // Spec 445: `initializer` is zero between `transferInitializer` and `acceptInitializer`, and
325
+ // msg.sender is never zero, so nobody initializes during a hand-over.
206
326
  if (msg.sender != initializer) revert NotInitializer(msg.sender, initializer);
207
- _validateLabel(bytes(label)); // AN-1-ONCHAIN: canonical charset on chain
327
+ // AN-1-ONCHAIN: canonical charset on chain. NAME-8: a root label carries no hyphen, so the
328
+ // typed host `<label>-<type>` splits one way only (the suffix is the segment after the LAST `-`).
329
+ if (_validateLabel(bytes(label)) != type(uint256).max) revert InvalidLabel();
208
330
  if (rootOwner == address(0)) revert ZeroOwner();
331
+ bytes32 rootLh = keccak256(bytes(label));
332
+ if (isReservedLabel[rootLh]) revert ReservedLabel();
209
333
  rootNode = namehashRoot(label);
210
334
  if (_records[rootNode].registeredAt != 0) revert RootAlreadyInitialized();
211
335
 
@@ -214,11 +338,20 @@ contract AgentNameRegistry is GovernanceManaged {
214
338
  resolver: resolverContract,
215
339
  subregistry: rootOwner,
216
340
  parent: bytes32(0),
217
- labelhash: keccak256(bytes(label)),
341
+ labelhash: rootLh,
218
342
  expiry: 0,
219
- registeredAt: uint64(block.timestamp)
343
+ registeredAt: uint64(block.timestamp),
344
+ epoch: 0
220
345
  });
221
346
 
347
+ // NAME-8: a typed root's label is reserved everywhere and is a refused suffix under a bare-host
348
+ // root; persons and the untyped legacy root take the bare host.
349
+ if (kind != KIND_AGENT) isTypedRootLabel[rootLh] = true;
350
+ if (kind == KIND_AGENT || kind == KIND_PERSON) {
351
+ rootTakesBareHost[rootNode] = true;
352
+ emit RootBareHostSet(rootNode, true);
353
+ }
354
+
222
355
  isRoot[rootNode] = true;
223
356
  rootKind[rootNode] = kind;
224
357
  _rootByLabel[label] = rootNode;
@@ -254,17 +387,27 @@ contract AgentNameRegistry is GovernanceManaged {
254
387
  address resolverContract,
255
388
  uint64 expiry
256
389
  ) external whenNotPaused returns (bytes32 childNode) {
257
- _validateLabel(bytes(label)); // AN-1-ONCHAIN: canonical charset on chain
390
+ uint256 lastHyphen = _validateLabel(bytes(label)); // AN-1-ONCHAIN: canonical charset on chain
258
391
  if (newOwner == address(0)) revert ZeroOwner();
259
392
  _requireParentAuth(parentNode);
260
393
  _requireNotExpired(parentNode);
261
394
 
262
395
  bytes32 lh = keccak256(bytes(label));
396
+ // NAME-8 (spec 445 decision 6): reserved labels name no agent under any parent; under a root
397
+ // that takes the bare host, a label ending in `-<typed root>` is refused (`foo-org` under `.me`
398
+ // would share the DNS host of `foo.org`). No exception for the root owner.
399
+ if (isReservedLabel[lh] || isTypedRootLabel[lh]) revert ReservedLabel();
400
+ if (lastHyphen != type(uint256).max && rootTakesBareHost[parentNode]) {
401
+ if (isTypedRootLabel[keccak256(bytes(label)[lastHyphen + 1:])]) revert LabelReadsAsTypedName();
402
+ }
263
403
  childNode = keccak256(abi.encodePacked(parentNode, lh));
264
404
  // M2 (seam audit): an EXPIRED name is reclaimable (parent-authorized re-register). Only a LIVE
265
405
  // record blocks re-registration — previously expiry was inert and a name could never be reclaimed.
266
406
  bool reclaiming = _records[childNode].registeredAt != 0;
267
407
  if (reclaiming && !isExpired(childNode)) revert NodeAlreadyExists();
408
+ // REG-4: a reclaim is a change of owner — the previous owner's resolver records must not carry
409
+ // over, so the node starts a new record epoch.
410
+ uint64 epoch = reclaiming ? _records[childNode].epoch + 1 : 0;
268
411
 
269
412
  _records[childNode] = NameRecord({
270
413
  owner: newOwner,
@@ -273,7 +416,8 @@ contract AgentNameRegistry is GovernanceManaged {
273
416
  parent: parentNode,
274
417
  labelhash: lh,
275
418
  expiry: expiry,
276
- registeredAt: uint64(block.timestamp)
419
+ registeredAt: uint64(block.timestamp),
420
+ epoch: epoch
277
421
  });
278
422
 
279
423
  _children[parentNode][lh] = childNode;
@@ -282,6 +426,7 @@ contract AgentNameRegistry is GovernanceManaged {
282
426
  _label[childNode] = label;
283
427
 
284
428
  emit NameRegistered(childNode, parentNode, label, newOwner, resolverContract, expiry);
429
+ if (reclaiming) emit RecordEpochBumped(childNode, epoch);
285
430
  }
286
431
 
287
432
  /**
@@ -296,6 +441,7 @@ contract AgentNameRegistry is GovernanceManaged {
296
441
  if (keccak256(bytes(label_)) != _records[node].labelhash) revert NotAuthorized();
297
442
  if (bytes(_label[node]).length != 0) revert NotAuthorized();
298
443
  _label[node] = label_;
444
+ emit LabelBackfilled(node, label_);
299
445
  }
300
446
 
301
447
  // ─── Setters ────────────────────────────────────────────────────
@@ -303,7 +449,17 @@ contract AgentNameRegistry is GovernanceManaged {
303
449
  function setOwner(bytes32 node, address newOwner) external whenNotPaused {
304
450
  _requireNodeAuth(node);
305
451
  if (newOwner == address(0)) revert ZeroOwner();
306
- _records[node].owner = newOwner;
452
+ NameRecord storage r = _records[node];
453
+ if (newOwner != r.owner) {
454
+ // REG-4: records are the previous owner's statements (`atl:addr`, `atl:agentType`,
455
+ // endpoints). They stop resolving here; the new owner writes its own. The `resolver` and
456
+ // `subregistry` POINTERS are registry fields the new owner can read in one call and are
457
+ // left as they are (a root hand-over keeps its subregistry) — a receiver checks them.
458
+ r.owner = newOwner;
459
+ uint64 epoch = r.epoch + 1;
460
+ r.epoch = epoch;
461
+ emit RecordEpochBumped(node, epoch);
462
+ }
307
463
  emit OwnerChanged(node, newOwner);
308
464
  }
309
465
 
@@ -319,9 +475,24 @@ contract AgentNameRegistry is GovernanceManaged {
319
475
  emit SubregistryChanged(node, subregistryContract);
320
476
  }
321
477
 
478
+ /**
479
+ * @notice Extend a name's expiry. REG-6: expiry is the PARENT's term, not the holder's — only the
480
+ * authority that may register under the parent (its owner or its subregistry) may renew, so
481
+ * a holder can neither strip the expiry it was given nor revive a name after it lapsed.
482
+ * Extension only: `newExpiry` is 0 (make permanent) or later than both the current expiry
483
+ * and now; a permanent name (expiry 0) cannot be given an expiry, and an expiry never moves
484
+ * earlier — otherwise a parent could expire and re-issue a live name, which is seizure.
485
+ * A root has no parent and no expiry; `renew` on it reverts.
486
+ */
322
487
  function renew(bytes32 node, uint64 newExpiry) external whenNotPaused {
323
- _requireNodeAuth(node);
324
- _records[node].expiry = newExpiry;
488
+ NameRecord storage r = _records[node];
489
+ if (r.registeredAt == 0) revert NodeNotFound();
490
+ _requireParentAuth(r.parent);
491
+ _requireNotExpired(r.parent);
492
+ uint64 cur = r.expiry;
493
+ if (cur == 0) revert ExpiryNotExtended();
494
+ if (newExpiry != 0 && (newExpiry <= cur || newExpiry <= block.timestamp)) revert ExpiryNotExtended();
495
+ r.expiry = newExpiry;
325
496
  emit NameRenewed(node, newExpiry);
326
497
  }
327
498
 
@@ -364,6 +535,15 @@ contract AgentNameRegistry is GovernanceManaged {
364
535
  return _records[node].registeredAt != 0 && !isExpired(node);
365
536
  }
366
537
  function registeredAt(bytes32 node) external view returns (uint64) { return _records[node].registeredAt; }
538
+ /// @notice REG-4 — the node's owner epoch (0 until its owner first changes).
539
+ function recordEpoch(bytes32 node) external view returns (uint64) { return _records[node].epoch; }
540
+ /// @notice REG-4 / REG-6 — is the node live (registered and not expired), and under which owner
541
+ /// epoch? The one read a resolver needs to key a record; a view call, never a log scan.
542
+ function recordState(bytes32 node) external view returns (bool live, uint64 epoch) {
543
+ NameRecord storage r = _records[node];
544
+ live = r.registeredAt != 0 && !(r.expiry != 0 && block.timestamp > r.expiry);
545
+ epoch = r.epoch;
546
+ }
367
547
 
368
548
  function childNode(bytes32 parentNode, bytes32 lh) external view returns (bytes32) {
369
549
  return _children[parentNode][lh];
@@ -371,9 +551,21 @@ contract AgentNameRegistry is GovernanceManaged {
371
551
  function childCount(bytes32 parentNode) external view returns (uint256) {
372
552
  return _childLabels[parentNode].length;
373
553
  }
554
+ /// @dev REG-12: unbounded under a permissionless subregistry — a reader of a large root uses
555
+ /// `childLabelhashesPage`.
374
556
  function childLabelhashes(bytes32 parentNode) external view returns (bytes32[] memory) {
375
557
  return _childLabels[parentNode];
376
558
  }
559
+ /// @notice REG-12 — `limit` child labelhashes of `parentNode` from `offset` (fewer at the end).
560
+ function childLabelhashesPage(bytes32 parentNode, uint256 offset, uint256 limit) external view returns (bytes32[] memory page) {
561
+ bytes32[] storage all = _childLabels[parentNode];
562
+ uint256 n = all.length;
563
+ if (offset >= n) return new bytes32[](0);
564
+ uint256 end = offset + limit;
565
+ if (end > n) end = n;
566
+ page = new bytes32[](end - offset);
567
+ for (uint256 i = offset; i < end; i++) page[i - offset] = all[i];
568
+ }
377
569
  function isExpired(bytes32 node) public view returns (bool) {
378
570
  uint64 exp = _records[node].expiry;
379
571
  return exp != 0 && block.timestamp > exp;
@@ -392,6 +584,9 @@ contract AgentNameRegistry is GovernanceManaged {
392
584
  NameRecord storage r = _records[node];
393
585
  if (r.registeredAt == 0) revert NodeNotFound();
394
586
  if (msg.sender != r.owner) revert NotAuthorized();
587
+ // REG-6: an expired name is nobody's — its former owner cannot move it, re-point it or
588
+ // delegate under it while it waits to be reclaimed.
589
+ if (r.expiry != 0 && block.timestamp > r.expiry) revert NameExpired();
395
590
  }
396
591
 
397
592
  function _requireParentAuth(bytes32 parentNode) internal view {
@@ -53,6 +53,8 @@ contract AgentNameUniversalResolver {
53
53
 
54
54
  /// @notice Resolve a single string-valued record by predicate id.
55
55
  function resolveString(bytes32 node, bytes32 predicate) external view returns (string memory) {
56
+ // REG-6: an expired or unregistered name answers nothing, for every record type.
57
+ if (!REGISTRY.recordExists(node)) return "";
56
58
  address resolverAddr = REGISTRY.resolver(node);
57
59
  if (resolverAddr == address(0)) return "";
58
60
  try AgentNameAttributeResolver(resolverAddr).getString(node, predicate) returns (string memory value) {
@@ -64,6 +66,8 @@ contract AgentNameUniversalResolver {
64
66
 
65
67
  /// @notice Resolve a single bytes32-valued record by predicate id.
66
68
  function resolveBytes32(bytes32 node, bytes32 predicate) external view returns (bytes32) {
69
+ // REG-6: an expired or unregistered name answers nothing, for every record type.
70
+ if (!REGISTRY.recordExists(node)) return bytes32(0);
67
71
  address resolverAddr = REGISTRY.resolver(node);
68
72
  if (resolverAddr == address(0)) return bytes32(0);
69
73
  try AgentNameAttributeResolver(resolverAddr).getBytes32(node, predicate) returns (bytes32 value) {
@@ -75,6 +79,8 @@ contract AgentNameUniversalResolver {
75
79
 
76
80
  /// @notice Resolve a single address-valued record by predicate id.
77
81
  function resolveAddress(bytes32 node, bytes32 predicate) external view returns (address) {
82
+ // REG-6: an expired or unregistered name answers nothing, for every record type.
83
+ if (!REGISTRY.recordExists(node)) return address(0);
78
84
  address resolverAddr = REGISTRY.resolver(node);
79
85
  if (resolverAddr == address(0)) return address(0);
80
86
  try AgentNameAttributeResolver(resolverAddr).getAddress(node, predicate) returns (address value) {
@@ -91,6 +97,7 @@ contract AgentNameUniversalResolver {
91
97
  returns (string[] memory values)
92
98
  {
93
99
  values = new string[](predicates.length);
100
+ if (!REGISTRY.recordExists(node)) return values; // REG-6
94
101
  address resolverAddr = REGISTRY.resolver(node);
95
102
  if (resolverAddr == address(0)) return values;
96
103
  for (uint256 i = 0; i < predicates.length; i++) {
@@ -155,6 +162,8 @@ contract AgentNameUniversalResolver {
155
162
  // Collect labels walking up to root. Bounded depth = 10 to
156
163
  // match the SDK's previous _reconstructName cap (no demo path
157
164
  // exceeds 4 — alice7.demo.agent is 3).
165
+ // A memory array is zero-initialized; entries are written before they are read (0..depth-1).
166
+ // slither-disable-next-line uninitialized-local
158
167
  string[10] memory labels;
159
168
  uint256 depth = 0;
160
169
  bytes32 cur = startNode;
@@ -192,7 +201,24 @@ contract AgentNameUniversalResolver {
192
201
 
193
202
  // ─── Directory listing ──────────────────────────────────────────
194
203
 
204
+ /// @notice REG-12 — a bounded window of a node's children: `limit` entries from `offset`.
205
+ function getChildrenPage(bytes32 parentNode, uint256 offset, uint256 limit)
206
+ external
207
+ view
208
+ returns (bytes32[] memory childNodes, address[] memory owners)
209
+ {
210
+ bytes32[] memory labelhashes = REGISTRY.childLabelhashesPage(parentNode, offset, limit);
211
+ childNodes = new bytes32[](labelhashes.length);
212
+ owners = new address[](labelhashes.length);
213
+ for (uint256 i = 0; i < labelhashes.length; i++) {
214
+ bytes32 child = REGISTRY.childNode(parentNode, labelhashes[i]);
215
+ childNodes[i] = child;
216
+ owners[i] = REGISTRY.owner(child);
217
+ }
218
+ }
219
+
195
220
  /// @notice List a node's children and their resolved addresses.
221
+ /// @dev REG-12: one external call per child and unbounded — use `getChildrenPage` for a large root.
196
222
  function getChildren(bytes32 parentNode)
197
223
  external
198
224
  view