@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,197 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ /**
5
+ * @title GeoFeatureRegistry
6
+ * @notice Versioned PUBLIC geo features — the definition layer of the
7
+ * definition-vs-claim model (spec 251). Exact geometry stays OFF chain
8
+ * behind `metadataURI`; on chain we anchor a `geometryHash`, coverage +
9
+ * source merkle roots, and a COARSE centroid/bbox (UI only).
10
+ *
11
+ * ─── Doctrine ───
12
+ *
13
+ * GFR-01 Keyed by Smart Agent ADDRESS (the `stewardAccount`); names are never
14
+ * authority (ADR-0010).
15
+ * GFR-02 Authorization is `msg.sender == stewardAccount` — the steward SA
16
+ * publishes through its own `execute()` path. NO `isOwner` staticcall.
17
+ * GFR-03 Monotonic per-`featureId` versioning; a boundary refresh is a new
18
+ * version (claims pin a version, so they don't retroactively re-target).
19
+ * GFR-04 `featureKind` is a C-box-anchored codelist value (ADR-0009 lockstep).
20
+ * GFR-05 Geo CLAIMS are NOT on chain — they are verifiable credentials that
21
+ * point to a `(featureId, version)` here (spec 251). No GeoClaimRegistry.
22
+ * GFR-06 NO domain/faith vocabulary (reusable substrate).
23
+ * GFR-07 NEUTRAL public geography ONLY. A feature is a generic public place
24
+ * (planet/region/country/admin area). It is NEVER tagged with — and its
25
+ * `metadataURI` NEVER carries — domain or operational data that could
26
+ * imply a private presence (e.g. "where a worker operates", access
27
+ * sensitivity, ministry context). Sensitivity classification is an
28
+ * OFF-chain app/domain policy applied OVER neutral features, never an
29
+ * on-chain feature attribute. All metadata MUST be sanitized.
30
+ * GFR-08 NO on-chain skill↔geo mapping. This registry holds geo features only
31
+ * and has ZERO reference to SkillDefinitionRegistry (or any skill id).
32
+ * Any "serves skill X in region Y" fact is an off-chain claim/credential.
33
+ *
34
+ * Ported from smart-agent `GeoFeatureRegistry`; diverges per spec 251 (AP auth,
35
+ * C-box-anchored kinds, no name binding in v1).
36
+ */
37
+ contract GeoFeatureRegistry {
38
+ // ─── C-box feature-kind codelist (keccak of the cbox URIs) ──────────
39
+ // Concept URIs are declared in packages/ontology cbox/geo-vocabulary.ttl
40
+ // (scheme apg:geoKind); lockstep-gated against the ontology (ADR-0009).
41
+ bytes32 public constant KIND_PLANET = keccak256(bytes("https://agenticprimitives.dev/ns/geo#Planet"));
42
+ bytes32 public constant KIND_REGION = keccak256(bytes("https://agenticprimitives.dev/ns/geo#Region"));
43
+ bytes32 public constant KIND_COUNTRY = keccak256(bytes("https://agenticprimitives.dev/ns/geo#Country"));
44
+ bytes32 public constant KIND_ADMIN = keccak256(bytes("https://agenticprimitives.dev/ns/geo#AdminArea"));
45
+ bytes32 public constant KIND_CUSTOM = keccak256(bytes("https://agenticprimitives.dev/ns/geo#Custom"));
46
+ int256 public constant COORD_SCALE = 1e7;
47
+
48
+ // ─── Errors ─────────────────────────────────────────────────────────
49
+ error NotSteward();
50
+ error FeatureNotFound();
51
+ error EmptyMetadata();
52
+ error EmptyId();
53
+
54
+ // ─── Storage ────────────────────────────────────────────────────────
55
+ struct FeatureRecord {
56
+ bytes32 featureId;
57
+ uint64 version;
58
+ address stewardAccount;
59
+ bytes32 featureKind;
60
+ bytes32 geometryHash; // keccak of canonical GeoJSON (off chain)
61
+ bytes32 coverageRoot; // merkle root over covering cells (e.g. H3)
62
+ bytes32 sourceSetRoot; // merkle root over the source dataset
63
+ string metadataURI;
64
+ int256 centroidLat; // degrees × 1e7, coarse — UI only
65
+ int256 centroidLon;
66
+ int256 bboxMinLat;
67
+ int256 bboxMinLon;
68
+ int256 bboxMaxLat;
69
+ int256 bboxMaxLon;
70
+ uint64 validAfter;
71
+ uint64 validUntil;
72
+ bool active;
73
+ uint64 registeredAt;
74
+ }
75
+
76
+ mapping(bytes32 => mapping(uint64 => FeatureRecord)) private _records;
77
+ mapping(bytes32 => uint64) public latestVersion;
78
+ bytes32[] private _allFeatures;
79
+
80
+ // ─── Events ─────────────────────────────────────────────────────────
81
+ event FeaturePublished(
82
+ bytes32 indexed featureId,
83
+ uint64 indexed version,
84
+ address indexed steward,
85
+ bytes32 featureKind,
86
+ bytes32 geometryHash,
87
+ bytes32 coverageRoot,
88
+ bytes32 sourceSetRoot,
89
+ string metadataURI
90
+ );
91
+ event FeatureDeactivated(bytes32 indexed featureId, uint64 version);
92
+ event FeatureValidityChanged(bytes32 indexed featureId, uint64 version, uint64 validAfter, uint64 validUntil);
93
+
94
+ // ─── Publish ────────────────────────────────────────────────────────
95
+ struct PublishInput {
96
+ bytes32 featureId;
97
+ bytes32 featureKind;
98
+ address stewardAccount;
99
+ bytes32 geometryHash;
100
+ bytes32 coverageRoot;
101
+ bytes32 sourceSetRoot;
102
+ string metadataURI;
103
+ int256 centroidLat;
104
+ int256 centroidLon;
105
+ int256 bboxMinLat;
106
+ int256 bboxMinLon;
107
+ int256 bboxMaxLat;
108
+ int256 bboxMaxLon;
109
+ uint64 validAfter;
110
+ uint64 validUntil;
111
+ }
112
+
113
+ function publish(PublishInput calldata p) external returns (uint64 version) {
114
+ if (p.featureId == bytes32(0)) revert EmptyId();
115
+ if (bytes(p.metadataURI).length == 0) revert EmptyMetadata();
116
+ if (msg.sender != p.stewardAccount) revert NotSteward();
117
+
118
+ uint64 prevVer = latestVersion[p.featureId];
119
+ if (prevVer != 0 && _records[p.featureId][prevVer].stewardAccount != p.stewardAccount) {
120
+ revert NotSteward();
121
+ }
122
+
123
+ version = prevVer + 1;
124
+ latestVersion[p.featureId] = version;
125
+ if (prevVer == 0) _allFeatures.push(p.featureId);
126
+ // The heavy record write + event live in a helper so `publish`'s own stack stays shallow.
127
+ _storeAndEmit(p, version);
128
+ }
129
+
130
+ /// @dev Writes the record FIELD-BY-FIELD to storage (no in-memory struct literal) and emits.
131
+ /// Behaviour is identical to the prior `_records[...] = FeatureRecord({...})` literal; the
132
+ /// split exists only to keep `publish` within solc's stack under `forge coverage --ir-minimum`
133
+ /// instrumentation (the 18-field memory literal + a dynamic `string` overflowed it by one slot).
134
+ function _storeAndEmit(PublishInput calldata p, uint64 version) internal {
135
+ FeatureRecord storage r = _records[p.featureId][version];
136
+ r.featureId = p.featureId;
137
+ r.version = version;
138
+ r.stewardAccount = p.stewardAccount;
139
+ r.featureKind = p.featureKind;
140
+ r.geometryHash = p.geometryHash;
141
+ r.coverageRoot = p.coverageRoot;
142
+ r.sourceSetRoot = p.sourceSetRoot;
143
+ r.metadataURI = p.metadataURI;
144
+ r.centroidLat = p.centroidLat;
145
+ r.centroidLon = p.centroidLon;
146
+ r.bboxMinLat = p.bboxMinLat;
147
+ r.bboxMinLon = p.bboxMinLon;
148
+ r.bboxMaxLat = p.bboxMaxLat;
149
+ r.bboxMaxLon = p.bboxMaxLon;
150
+ r.validAfter = p.validAfter;
151
+ r.validUntil = p.validUntil;
152
+ r.active = true;
153
+ r.registeredAt = uint64(block.timestamp);
154
+ emit FeaturePublished(p.featureId, version, p.stewardAccount, p.featureKind, p.geometryHash, p.coverageRoot, p.sourceSetRoot, p.metadataURI);
155
+ }
156
+
157
+ function deactivate(bytes32 featureId) external {
158
+ uint64 v = latestVersion[featureId];
159
+ if (v == 0) revert FeatureNotFound();
160
+ FeatureRecord storage r = _records[featureId][v];
161
+ if (msg.sender != r.stewardAccount) revert NotSteward();
162
+ r.active = false;
163
+ emit FeatureDeactivated(featureId, v);
164
+ }
165
+
166
+ function setValidity(bytes32 featureId, uint64 version, uint64 validAfter, uint64 validUntil) external {
167
+ FeatureRecord storage r = _records[featureId][version];
168
+ if (r.version == 0) revert FeatureNotFound();
169
+ if (msg.sender != r.stewardAccount) revert NotSteward();
170
+ r.validAfter = validAfter;
171
+ r.validUntil = validUntil;
172
+ emit FeatureValidityChanged(featureId, version, validAfter, validUntil);
173
+ }
174
+
175
+ // ─── Views ──────────────────────────────────────────────────────────
176
+ function getFeature(bytes32 featureId, uint64 version) external view returns (FeatureRecord memory) {
177
+ FeatureRecord memory r = _records[featureId][version];
178
+ if (r.version == 0) revert FeatureNotFound();
179
+ return r;
180
+ }
181
+
182
+ function getLatest(bytes32 featureId) external view returns (FeatureRecord memory) {
183
+ uint64 v = latestVersion[featureId];
184
+ if (v == 0) revert FeatureNotFound();
185
+ return _records[featureId][v];
186
+ }
187
+
188
+ /// @notice True if `version` of `featureId` exists (used by off-chain geo claim credentials to
189
+ /// confirm the pinned definition version they reference).
190
+ function exists(bytes32 featureId, uint64 version) external view returns (bool) {
191
+ return _records[featureId][version].version != 0;
192
+ }
193
+
194
+ function allFeatures() external view returns (bytes32[] memory) {
195
+ return _allFeatures;
196
+ }
197
+ }
@@ -42,15 +42,21 @@ contract AgenticGovernance is IGovernanceView {
42
42
  /// construction; rotate by redeploying.
43
43
  address public immutable timelock;
44
44
 
45
- /// @notice Fast-path emergency-pauser role. Can pause without delay
46
- /// but CANNOT unpause (unpause requires the timelock).
47
- address public immutable guardian;
48
-
49
45
  // ─── State ────────────────────────────────────────────────────
50
46
 
51
47
  bool private _paused;
52
48
  mapping(address => bool) private _signers;
53
49
 
50
+ /// @notice Fast-path emergency-pauser role. Can pause without delay but
51
+ /// CANNOT unpause (unpause requires the timelock). GOV-1: this is a
52
+ /// STORAGE var (not immutable) so the timelock can ROTATE it — a
53
+ /// guardian whose key is compromised and grief-pauses the system can
54
+ /// be replaced WITHOUT a full governance redeploy, bounding the
55
+ /// re-pause DoS to one timelock window instead of "permanent". Set
56
+ /// (`setGuardian`) only by the timelock. Declared after the existing
57
+ /// storage vars so their slot assignments don't shift.
58
+ address public guardian;
59
+
54
60
  // ─── Errors ───────────────────────────────────────────────────
55
61
 
56
62
  error NotTimelock(address caller);
@@ -64,6 +70,8 @@ contract AgenticGovernance is IGovernanceView {
64
70
  event Unpaused(address indexed by);
65
71
  event SignerSet(address indexed who, bool isSigner);
66
72
  event Executed(address indexed target, uint256 value, bytes data);
73
+ /// @notice GOV-1 — the guardian (fast-pause) role was rotated by the timelock.
74
+ event GuardianRotated(address indexed oldGuardian, address indexed newGuardian);
67
75
 
68
76
  // ─── Constructor ──────────────────────────────────────────────
69
77
 
@@ -134,6 +142,20 @@ contract AgenticGovernance is IGovernanceView {
134
142
  emit SignerSet(who, sig);
135
143
  }
136
144
 
145
+ /// @notice GOV-1 — rotate the guardian (fast-pause) role. Timelock-only, so a
146
+ /// compromised guardian that is perpetually re-pausing the system can
147
+ /// be replaced after one timelock window WITHOUT a governance redeploy.
148
+ /// To retire the fast-pause capability entirely, rotate to a burn
149
+ /// address. Cannot be the zero address (would make `pause()` an
150
+ /// accidental no-op while looking live).
151
+ function setGuardian(address newGuardian) external {
152
+ if (msg.sender != timelock) revert NotTimelock(msg.sender);
153
+ if (newGuardian == address(0)) revert ZeroAddress();
154
+ address old = guardian;
155
+ guardian = newGuardian;
156
+ emit GuardianRotated(old, newGuardian);
157
+ }
158
+
137
159
  // ─── Receive ETH ──────────────────────────────────────────────
138
160
 
139
161
  receive() external payable {}
@@ -28,7 +28,30 @@ library AgentProfilePredicates {
28
28
  // ─── Identity-only ──────────────────────────────────────────────
29
29
 
30
30
  bytes32 internal constant ATL_DESCRIPTION = keccak256("atl:description");
31
+ /// @dev LEGACY READ ONLY (ADR-0051). Publicly-asserted labels, written before the vocabulary settled
32
+ /// on "capability" for what an agent can do. New writes go to `ATL_CAPABILITIES`; readers consult
33
+ /// this only when that is empty, which is the documented migration state — not a second mechanism
34
+ /// (ADR-0013). Kept because agents named under it are still on chain.
35
+ bytes32 internal constant ATL_SKILLS = keccak256("atl:skills");
36
+ /// ADR-0051 — the ids of what this agent CAN DO, comma-joined, same rail as the legacy labels above.
37
+ /// The SAME ids appear in `profile.capabilities[].id`, in ARD `capabilities[]`, and in the A2A card's
38
+ /// `skills[]` (the wire's name for them). Ids only: names, descriptions and examples live in the
39
+ /// profile record, because the chain is the place to prove WHICH capabilities are claimed, not to
40
+ /// store their prose. The indexer projects to approf:capabilities.
41
+ bytes32 internal constant ATL_CAPABILITIES = keccak256("atl:capabilities");
42
+ /// spec 347 §8.5 — how to OBTAIN AND RUN this agent's software: a JSON string per
43
+ /// `AgentDistributionV1` (agent-profile; JCS-canonical; mirrors the ACP registry agent.schema.json
44
+ /// `distribution` + `acp`/`version`). SA-keyed identity property, string datatype; the indexer
45
+ /// projects it to approf:distribution and registry files (ACP registry.json / ARD) are projections.
46
+ bytes32 internal constant ATL_DISTRIBUTION = keccak256("atl:distribution");
31
47
  bytes32 internal constant ATL_HOMEPAGE = keccak256("atl:homepage");
48
+ /// `atl:projectionSigner` — spec 439 F2.5: the key an ESTATE AGENT declares as the one that anchors its
49
+ /// estate's roots on neutral ground (`EstateProjectionRegistry.signerOf(estateId)`). Public ground cannot
50
+ /// verify who governs an estate on another chain, so `register` is first-come-wins; this record, written by
51
+ /// the estate agent on ITS OWN chain, is what a verifier cross-checks `signerOf` against. SA-keyed, `address`.
52
+ /// Zero = undeclared (a verifier says so); a mismatch is a refusal. Evidence, never authority.
53
+ bytes32 internal constant ATL_PROJECTION_SIGNER = keccak256("atl:projectionSigner");
54
+
32
55
  bytes32 internal constant ATL_AVATAR = keccak256("atl:avatar");
33
56
  bytes32 internal constant ATL_PROFILE_SCHEMA_URI = keccak256("atl:profileSchemaURI");
34
57
  bytes32 internal constant ATL_PROFILE_ACTIVE = keccak256("atl:profileActive");
@@ -28,8 +28,10 @@ import {WebAuthnLib} from "./WebAuthnLib.sol";
28
28
  * v == 2 → WebAuthn passkey sig (agenticprimitives
29
29
  * extension; NOT in Safe). r holds the
30
30
  * Passkey-Identity-Address (PIA, derived
31
- * from the P-256 pubkey via
32
- * `address(uint160(uint256(keccak256(abi.encode(x, y)))))`).
31
+ * from the P-256 pubkey + the account it is
32
+ * scoped to via
33
+ * `address(uint160(uint256(keccak256(abi.encode(x, y, passkeyScope)))))`
34
+ * — per-account since spec 302 W2).
33
35
  * s holds the byte offset into `signatures`
34
36
  * to a length-prefixed tail containing
35
37
  * `abi.encode(uint256 x, uint256 y, bytes32 rpIdHash, WebAuthnLib.Assertion assertion)`.
@@ -77,12 +79,21 @@ library SignatureSlotRecovery {
77
79
  * caller does not want to allow v=1 sigs
78
80
  * (e.g. quorum-of-owners admin paths
79
81
  * that don't accept pre-approved hashes).
82
+ * @param passkeyScope Spec 302 W2 — the AgentAccount the v=2
83
+ * slot's PIA is scoped to (the account
84
+ * whose custody the passkey signer claims:
85
+ * CustodyPolicy passes `account`, the
86
+ * QuorumEnforcer passes the `delegator`).
87
+ * The per-account derivation
88
+ * `keccak256(abi.encode(x, y, scope))`
89
+ * kills the cross-account PIA join key.
80
90
  */
81
91
  function recoverFromSlot(
82
92
  bytes32 payloadHash,
83
93
  bytes memory signatures,
84
94
  uint256 index,
85
- address approvedHashRegistry
95
+ address approvedHashRegistry,
96
+ address passkeyScope
86
97
  ) internal view returns (address signer) {
87
98
  bytes32 r;
88
99
  bytes32 s;
@@ -171,11 +182,17 @@ library SignatureSlotRecovery {
171
182
  // WebAuthnLib.Assertion assertion).
172
183
  (uint256 pubX, uint256 pubY, bytes32 rpIdHash, WebAuthnLib.Assertion memory assertion) =
173
184
  abi.decode(dyn, (uint256, uint256, bytes32, WebAuthnLib.Assertion));
174
- address derived = address(uint160(uint256(keccak256(abi.encode(pubX, pubY)))));
185
+ // Spec 302 W2 — per-account PIA (mirrors AgentAccount._passkeyIdentity).
186
+ address derived = address(uint160(uint256(keccak256(abi.encode(pubX, pubY, passkeyScope)))));
175
187
  if (derived != signer) revert PasskeyPubKeyMismatch(signer, derived);
176
- // requireUv=false at the slot level; account policy can layer UV
177
- // requirement via a future policy module.
178
- if (!WebAuthnLib.verify(assertion, payloadHash, pubX, pubY, rpIdHash, false)) {
188
+ // WA-2: require UV at the slot level. This path verifies custody-COUNCIL
189
+ // passkey signatures (CustodyPolicy quorum: trustees/custodians authorizing
190
+ // a recovery or admin change) — the highest-assurance signatures in the
191
+ // system. Consistent with the native ERC-1271 path (AgentAccount, R8.2):
192
+ // a UP-only assertion is rejected; browser ceremonies for custody signers
193
+ // MUST use `userVerification: 'required'`. A lower-assurance flow that needs
194
+ // UP-only must install a separate validator module that relaxes this.
195
+ if (!WebAuthnLib.verify(assertion, payloadHash, pubX, pubY, rpIdHash, true)) {
179
196
  revert PasskeySigInvalid(signer);
180
197
  }
181
198
  } else if (v == 27 || v == 28) {
@@ -36,6 +36,13 @@ import "./P256Verifier.sol";
36
36
  * PasskeyValidator (for external 1271-style verification).
37
37
  */
38
38
  library WebAuthnLib {
39
+ /// @dev secp256r1 (P-256) curve order n ÷ 2 — the low-s malleability bound (WA-1).
40
+ /// RIP-7212 accepts BOTH (r, s) and (r, n−s) for the same message, so without
41
+ /// this bound a second valid signature always exists. Any path that treats a
42
+ /// signature as unique (quorum slot recovery, dedup) would be malleable.
43
+ uint256 internal constant P256_N_DIV_2 =
44
+ 0x7fffffff800000007fffffffffffffffde737d56d38bcf4279dce5617e3192a8;
45
+
39
46
  /// @notice A WebAuthn-wrapped P-256 signature bundle.
40
47
  struct Assertion {
41
48
  bytes authenticatorData;
@@ -74,6 +81,12 @@ library WebAuthnLib {
74
81
  if (!_checkClientData(assertion.clientDataJSON, assertion.typeIndex, assertion.challengeIndex, expectedChallengeHash)) {
75
82
  return false;
76
83
  }
84
+ // WA-1: enforce low-s. RIP-7212 verifies both (r, s) and (r, n−s); rejecting
85
+ // the high-s half makes the assertion signature canonical, closing P-256
86
+ // malleability for every caller (native ERC-1271 + custody-quorum slot recovery).
87
+ if (assertion.s > P256_N_DIV_2) {
88
+ return false;
89
+ }
77
90
  bytes32 cdjHash = sha256(bytes(assertion.clientDataJSON));
78
91
  bytes32 signingHash = sha256(abi.encodePacked(assertion.authenticatorData, cdjHash));
79
92
  return P256Verifier.verify(signingHash, assertion.r, assertion.s, pubX, pubY);
@@ -0,0 +1,152 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
6
+
7
+ /**
8
+ * @title MockUSDC
9
+ * @notice Test USDC for the Base Sepolia x402 demos (spec 272, PAY-CON-3). 6 decimals, open mint +
10
+ * faucet, and full EIP-3009 (`transferWithAuthorization` / `receiveWithAuthorization` /
11
+ * `cancelAuthorization` / `authorizationState`) so the Wave-5 Coinbase-x402 interop adapter
12
+ * is a no-redeploy add (X402-D2 / PAY-WIRE-4).
13
+ *
14
+ * @dev DEV-ONLY: `mint`/`faucet` are open. NEVER a production asset. Wave-1 settlement is
15
+ * delegation-native (the {PaymentEnforcer}-gated `transfer`), so EIP-3009 is present but
16
+ * unused until Wave 5; shipping it now avoids a token redeploy.
17
+ */
18
+ contract MockUSDC is ERC20 {
19
+ using ECDSA for bytes32;
20
+
21
+ // EIP-3009 type hashes
22
+ bytes32 public constant TRANSFER_WITH_AUTHORIZATION_TYPEHASH = keccak256(
23
+ "TransferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)"
24
+ );
25
+ bytes32 public constant RECEIVE_WITH_AUTHORIZATION_TYPEHASH = keccak256(
26
+ "ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)"
27
+ );
28
+ bytes32 public constant CANCEL_AUTHORIZATION_TYPEHASH =
29
+ keccak256("CancelAuthorization(address authorizer,bytes32 nonce)");
30
+
31
+ bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
32
+ uint256 private immutable _CACHED_CHAIN_ID;
33
+
34
+ /// @notice EIP-3009: authorizer => nonce => used-or-canceled.
35
+ mapping(address => mapping(bytes32 => bool)) public authorizationState;
36
+
37
+ event AuthorizationUsed(address indexed authorizer, bytes32 indexed nonce);
38
+ event AuthorizationCanceled(address indexed authorizer, bytes32 indexed nonce);
39
+
40
+ error AuthNotYetValid();
41
+ error AuthExpired();
42
+ error AuthUsedOrCanceled();
43
+ error InvalidSignature();
44
+ error CallerMustBePayee();
45
+
46
+ constructor() ERC20("Mock USD Coin", "USDC") {
47
+ _CACHED_CHAIN_ID = block.chainid;
48
+ _CACHED_DOMAIN_SEPARATOR = _computeDomainSeparator();
49
+ }
50
+
51
+ function decimals() public pure override returns (uint8) {
52
+ return 6;
53
+ }
54
+
55
+ // ── dev faucet ──
56
+ function mint(address to, uint256 amount) external {
57
+ _mint(to, amount);
58
+ }
59
+
60
+ function faucet(uint256 amount) external {
61
+ _mint(msg.sender, amount);
62
+ }
63
+
64
+ // ── EIP-3009 ──
65
+
66
+ function DOMAIN_SEPARATOR() public view returns (bytes32) {
67
+ return block.chainid == _CACHED_CHAIN_ID ? _CACHED_DOMAIN_SEPARATOR : _computeDomainSeparator();
68
+ }
69
+
70
+ function transferWithAuthorization(
71
+ address from,
72
+ address to,
73
+ uint256 value,
74
+ uint256 validAfter,
75
+ uint256 validBefore,
76
+ bytes32 nonce,
77
+ bytes calldata signature
78
+ ) external {
79
+ _requireValidAuthorization(from, nonce, validAfter, validBefore);
80
+ _verify(
81
+ from,
82
+ keccak256(
83
+ abi.encode(TRANSFER_WITH_AUTHORIZATION_TYPEHASH, from, to, value, validAfter, validBefore, nonce)
84
+ ),
85
+ signature
86
+ );
87
+ _markAuthorizationUsed(from, nonce);
88
+ _transfer(from, to, value);
89
+ }
90
+
91
+ function receiveWithAuthorization(
92
+ address from,
93
+ address to,
94
+ uint256 value,
95
+ uint256 validAfter,
96
+ uint256 validBefore,
97
+ bytes32 nonce,
98
+ bytes calldata signature
99
+ ) external {
100
+ if (to != msg.sender) revert CallerMustBePayee();
101
+ _requireValidAuthorization(from, nonce, validAfter, validBefore);
102
+ _verify(
103
+ from,
104
+ keccak256(
105
+ abi.encode(RECEIVE_WITH_AUTHORIZATION_TYPEHASH, from, to, value, validAfter, validBefore, nonce)
106
+ ),
107
+ signature
108
+ );
109
+ _markAuthorizationUsed(from, nonce);
110
+ _transfer(from, to, value);
111
+ }
112
+
113
+ function cancelAuthorization(address authorizer, bytes32 nonce, bytes calldata signature) external {
114
+ if (authorizationState[authorizer][nonce]) revert AuthUsedOrCanceled();
115
+ _verify(authorizer, keccak256(abi.encode(CANCEL_AUTHORIZATION_TYPEHASH, authorizer, nonce)), signature);
116
+ authorizationState[authorizer][nonce] = true;
117
+ emit AuthorizationCanceled(authorizer, nonce);
118
+ }
119
+
120
+ // ── internals ──
121
+
122
+ function _requireValidAuthorization(address from, bytes32 nonce, uint256 validAfter, uint256 validBefore)
123
+ private
124
+ view
125
+ {
126
+ if (block.timestamp <= validAfter) revert AuthNotYetValid();
127
+ if (block.timestamp >= validBefore) revert AuthExpired();
128
+ if (authorizationState[from][nonce]) revert AuthUsedOrCanceled();
129
+ }
130
+
131
+ function _markAuthorizationUsed(address from, bytes32 nonce) private {
132
+ authorizationState[from][nonce] = true;
133
+ emit AuthorizationUsed(from, nonce);
134
+ }
135
+
136
+ function _verify(address signer, bytes32 structHash, bytes calldata signature) private view {
137
+ bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), structHash));
138
+ if (digest.recover(signature) != signer) revert InvalidSignature();
139
+ }
140
+
141
+ function _computeDomainSeparator() private view returns (bytes32) {
142
+ return keccak256(
143
+ abi.encode(
144
+ keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
145
+ keccak256(bytes("Mock USD Coin")),
146
+ keccak256(bytes("2")),
147
+ block.chainid,
148
+ address(this)
149
+ )
150
+ );
151
+ }
152
+ }
@@ -51,10 +51,83 @@ library AgentNamePredicates {
51
51
  /// CustodyPolicy module. `address`.
52
52
  bytes32 internal constant ATL_CUSTODY_POLICY = keccak256("atl:custodyPolicy");
53
53
 
54
+ /// `atl:accounts` — the name's accounts BY CHAIN (ap-federation spec 440 §C / spec 346 §3.8; the ENSIP-9
55
+ /// multi-coin `addr(node, coinType)` ported): a `string[]` of CAIP-10 ids, at most one per CAIP-2 chain,
56
+ /// written by the name owner. `atl:addr` stays the root-chain forward record and `atl:nativeId` the home
57
+ /// account; this lists every account the name resolves to, home and satellites, so a reader on another
58
+ /// chain finds the account that stands there. A reverse claim on that chain is honoured only when the
59
+ /// entry here agrees (ENSIP-19's rule). Evidence a reader checks, never authority.
60
+ bytes32 internal constant ATL_ACCOUNTS = keccak256("atl:accounts");
61
+
54
62
  /// `atl:nativeId` — CAIP-10 chain-agnostic account identifier
55
63
  /// (per ADR-0008). `string`.
56
64
  bytes32 internal constant ATL_NATIVE_ID = keccak256("atl:nativeId");
57
65
 
66
+ /// `atl:connectionKind` — connection-bootstrap credential KIND (spec 280).
67
+ /// Stored as `bytes32` (hashed enum). Bound to CONNECTION_KIND_ENUM. OPT-IN,
68
+ /// owner-set, PUBLIC. Advertises how a returning person connects by name.
69
+ bytes32 internal constant ATL_CONNECTION_KIND = keccak256("atl:connectionKind");
70
+
71
+ /// `atl:connectionAddress` — connection-bootstrap credential ADDRESS (spec 280).
72
+ /// The custodian EOA (wallet) or social KMS C_sub. `address`. OPT-IN, owner-set,
73
+ /// PUBLIC pre-select hint only (NOT required to connect). Deliberate, documented
74
+ /// name→credential index (ADR-0040 amendment). Never set automatically.
75
+ bytes32 internal constant ATL_CONNECTION_ADDRESS = keccak256("atl:connectionAddress");
76
+
77
+ // ─── Derived type (spec 346 §2.3 / ADR-0061) ────────────────────
78
+ //
79
+ // SA-KEYED records on the AgentProfileResolver subject (NOT name-node records): the
80
+ // suffix of a typed name (.me .org .team .svc .workspace .treasury) is a CLAIM
81
+ // validated against these. `atl:agentKind` stays the 3-valued ROOT; `atl:agentType`
82
+ // is the closed DERIVED layer under it (team ⊂ org; service / workspace /
83
+ // treasury ⊂ service). Roles other than workspace are an open-set string.
84
+
85
+ /// `atl:agentType` — the derived agent type. `bytes32` (hashed enum). Bound to AGENT_TYPE_ENUM.
86
+ bytes32 internal constant ATL_AGENT_TYPE = keccak256("atl:agentType");
87
+
88
+ /// `atl:serviceRole` — open-set service role (`workspace` REQUIRED for that type). `string`.
89
+ bytes32 internal constant ATL_SERVICE_ROLE = keccak256("atl:serviceRole");
90
+
91
+ /// `atl:agentSubtype` — a VERTICAL subtype of the generic derived type (spec 346 §2.4), e.g. an app-registered
92
+ /// kind of organization. The vocabulary is the app's; the chain stores the slug. `string`.
93
+ bytes32 internal constant ATL_AGENT_SUBTYPE = keccak256("atl:agentSubtype");
94
+
95
+ /// `atl:cardDigest` — sha256 (as bytes32) of the RELEASED A2A Agent Card this name currently publishes
96
+ /// (spec 347 §8.3). Content-addresses the card; the card itself is served at the a2aEndpoint host's
97
+ /// `/.well-known/agent-card.json`. Never authority — a verifier compares the fetched bytes to this digest.
98
+ bytes32 internal constant ATL_CARD_DIGEST = keccak256("atl:cardDigest");
99
+
100
+ /// `atl:cardUri` — explicit URI of the released A2A Agent Card when it is not at the default well-known
101
+ /// path of the a2aEndpoint host (spec 347 §8.3). `string`.
102
+ bytes32 internal constant ATL_CARD_URI = keccak256("atl:cardUri");
103
+
104
+ /// Enum set bound to `atl:agentType`. Ten members; mirrors `types.DerivedAgentType`.
105
+ bytes32 internal constant AGENT_TYPE_ENUM = keccak256("atl:AgentTypeEnum");
106
+
107
+ bytes32 internal constant AGENT_TYPE_PERSON = keccak256("person");
108
+ bytes32 internal constant AGENT_TYPE_ORG = keccak256("org");
109
+ bytes32 internal constant AGENT_TYPE_TEAM = keccak256("team");
110
+ bytes32 internal constant AGENT_TYPE_SERVICE = keccak256("service");
111
+ bytes32 internal constant AGENT_TYPE_WORKSPACE = keccak256("workspace");
112
+ bytes32 internal constant AGENT_TYPE_TREASURY = keccak256("treasury");
113
+ bytes32 internal constant AGENT_TYPE_REGISTRY = keccak256("registry"); // the Service Agent that OPERATES a registry
114
+ bytes32 internal constant AGENT_TYPE_CHURCH = keccak256("church"); // organization-class (ADR-0061 amendment 2026-08-30)
115
+ bytes32 internal constant AGENT_TYPE_CIRCLE = keccak256("circle"); // organization-class
116
+ bytes32 internal constant AGENT_TYPE_HOUSEHOLD = keccak256("household"); // organization-class (spec 368, 2026-09-07)
117
+
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.
120
+ bytes32 internal constant ROOT_KIND_PERSON = keccak256("namespace:Person");
121
+ bytes32 internal constant ROOT_KIND_ORGANIZATION = keccak256("namespace:Organization");
122
+ bytes32 internal constant ROOT_KIND_TEAM = keccak256("namespace:Team");
123
+ bytes32 internal constant ROOT_KIND_SERVICE = keccak256("namespace:Service");
124
+ bytes32 internal constant ROOT_KIND_WORKSPACE = keccak256("namespace:Workspace");
125
+ bytes32 internal constant ROOT_KIND_TREASURY = keccak256("namespace:Treasury");
126
+ bytes32 internal constant ROOT_KIND_REGISTRY = keccak256("namespace:Registry");
127
+ bytes32 internal constant ROOT_KIND_CHURCH = keccak256("namespace:Church");
128
+ bytes32 internal constant ROOT_KIND_CIRCLE = keccak256("namespace:Circle");
129
+ bytes32 internal constant ROOT_KIND_HOUSEHOLD = keccak256("namespace:Household");
130
+
58
131
  // ─── Shape + enum-set ids ───────────────────────────────────────
59
132
 
60
133
  /// `atl:AgentName` — the class id for ShapeRegistry validation.
@@ -71,4 +144,20 @@ library AgentNamePredicates {
71
144
  bytes32 internal constant AGENT_KIND_PERSON = keccak256("person");
72
145
  bytes32 internal constant AGENT_KIND_ORG = keccak256("org");
73
146
  bytes32 internal constant AGENT_KIND_SERVICE = keccak256("service");
147
+
148
+ /// Enum set bound to `atl:connectionKind` (spec 280). Contains the
149
+ /// five hashed member ids below.
150
+ bytes32 internal constant CONNECTION_KIND_ENUM = keccak256("atl:ConnectionKindEnum");
151
+
152
+ bytes32 internal constant CONNECTION_KIND_WALLET = keccak256("wallet");
153
+ bytes32 internal constant CONNECTION_KIND_GOOGLE = keccak256("google");
154
+ bytes32 internal constant CONNECTION_KIND_YOUVERSION = keccak256("youversion");
155
+ bytes32 internal constant CONNECTION_KIND_PASSKEY = keccak256("passkey");
156
+ bytes32 internal constant CONNECTION_KIND_MULTI = keccak256("multi");
157
+ // Social/KMS-class kinds (specs 319/320) — per-subject C_sub custodians, code-flow sign-in.
158
+ // The attribute write path validates only the PREDICATE (OntologyTermRegistry.isActive), NOT the
159
+ // enum value, so these are publishable on the live deployment with no redeploy; the ShapeRegistry
160
+ // ConnectionKindEnum seed adds them for forward shape-validation correctness (Deploy.s.sol).
161
+ bytes32 internal constant CONNECTION_KIND_EMAIL = keccak256("email");
162
+ bytes32 internal constant CONNECTION_KIND_PHONE = keccak256("phone");
74
163
  }