@agenticprimitives/contracts 0.1.0-alpha.3 → 1.0.0-alpha.11

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 (73) hide show
  1. package/AUDIT.md +324 -47
  2. package/README.md +45 -10
  3. package/deployments-base-sepolia.json +36 -0
  4. package/deployments-registries-base-sepolia.json +1 -0
  5. package/dist/abi/AgentAccount.json +1670 -0
  6. package/dist/abi/AgentAccountFactory.json +477 -0
  7. package/dist/abi/AgentNameRegistry.json +51 -0
  8. package/dist/abi/AgenticGovernance.json +32 -0
  9. package/dist/abi/AgreementRegistry.json +427 -0
  10. package/dist/abi/AttestationRegistry.json +436 -0
  11. package/dist/abi/CallDataHashEnforcer.json +119 -0
  12. package/dist/abi/CustodyPolicy.json +1122 -0
  13. package/dist/abi/DelegationManager.json +645 -0
  14. package/dist/abi/GeoFeatureRegistry.json +625 -0
  15. package/dist/abi/IAgentAccount.json +262 -0
  16. package/dist/abi/IAgentAccountFactoryAccessor.json +15 -0
  17. package/dist/abi/IAgentAccountFactoryView.json +41 -0
  18. package/dist/abi/IAgentAccountPauseView.json +15 -0
  19. package/dist/abi/IAgenticPrimitivesAgentAccount.json +15 -0
  20. package/dist/abi/IApprovedHashRegistryView.json +26 -0
  21. package/dist/abi/ICustodyPolicyFactoryView.json +15 -0
  22. package/dist/abi/ICustodyPolicyPauseView.json +15 -0
  23. package/dist/abi/IDelegationManager.json +171 -0
  24. package/dist/abi/IERC7579HookLike.json +44 -0
  25. package/dist/abi/IERC7579ModuleLike.json +28 -0
  26. package/dist/abi/IPaymentReceiptRegistry.json +50 -0
  27. package/dist/abi/MockUSDC.json +621 -0
  28. package/dist/abi/PaymentEnforcer.json +407 -0
  29. package/dist/abi/PaymentEscrow.json +299 -0
  30. package/dist/abi/PaymentReceiptRegistry.json +182 -0
  31. package/dist/abi/PermissionlessSubregistry.json +5 -0
  32. package/dist/abi/QuorumEnforcer.json +311 -0
  33. package/dist/abi/SignatureSlotRecovery.json +88 -0
  34. package/dist/abi/SkillDefinitionRegistry.json +491 -0
  35. package/dist/abi/SmartAgentPaymaster.json +873 -0
  36. package/dist/abi/UniversalSignatureValidator.json +65 -0
  37. package/dist/abi/index.d.ts +28 -0
  38. package/dist/abi/index.js +28 -0
  39. package/dist/deployments/base-sepolia.d.ts +41 -0
  40. package/dist/deployments/base-sepolia.js +39 -0
  41. package/dist/deployments/index.d.ts +9 -0
  42. package/dist/deployments/index.js +16 -0
  43. package/dist/deployments/registries-base-sepolia.d.ts +9 -0
  44. package/dist/deployments/registries-base-sepolia.js +7 -0
  45. package/package.json +24 -3
  46. package/src/AgentAccount.sol +191 -11
  47. package/src/AgentAccountFactory.sol +66 -12
  48. package/src/SmartAgentPaymaster.sol +186 -20
  49. package/src/UniversalSignatureValidator.sol +3 -0
  50. package/src/agency/DelegationManager.sol +170 -0
  51. package/src/agency/IDelegationManager.sol +38 -0
  52. package/src/agreement/AgreementRegistry.sol +331 -0
  53. package/src/attestation/AttestationRegistry.sol +384 -0
  54. package/src/custody/CustodyPolicy.sol +138 -8
  55. package/src/enforcers/AllowedMethodsEnforcer.sol +6 -0
  56. package/src/enforcers/AllowedTargetsEnforcer.sol +6 -0
  57. package/src/enforcers/CallDataHashEnforcer.sol +61 -0
  58. package/src/enforcers/PaymentEnforcer.sol +194 -0
  59. package/src/enforcers/QuorumEnforcer.sol +20 -0
  60. package/src/enforcers/TimestampEnforcer.sol +7 -0
  61. package/src/enforcers/ValueEnforcer.sol +6 -0
  62. package/src/geo/GeoFeatureRegistry.sol +197 -0
  63. package/src/governance/AgenticGovernance.sol +26 -4
  64. package/src/libraries/SignatureSlotRecovery.sol +8 -3
  65. package/src/libraries/WebAuthnLib.sol +13 -0
  66. package/src/mocks/MockUSDC.sol +152 -0
  67. package/src/naming/AgentNameRegistry.sol +52 -15
  68. package/src/naming/AgentNameUniversalResolver.sol +1 -1
  69. package/src/naming/PermissionlessSubregistry.sol +19 -2
  70. package/src/payments/PaymentEscrow.sol +137 -0
  71. package/src/payments/PaymentReceiptRegistry.sol +67 -0
  72. package/src/relationships/AgentRelationship.sol +8 -0
  73. package/src/skills/SkillDefinitionRegistry.sol +187 -0
@@ -0,0 +1,187 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ /**
5
+ * @title SkillDefinitionRegistry
6
+ * @notice Versioned PUBLIC skill definitions — the definition layer of the
7
+ * definition-vs-claim model (spec 251). Small, stable, public, indexable
8
+ * anchors only: id, version, steward, kind, content hashes, metadata URI,
9
+ * validity. The full SKOS expansion + taxonomy live OFF chain behind
10
+ * `metadataURI` + `ontologyMerkleRoot`.
11
+ *
12
+ * ─── Doctrine ───
13
+ *
14
+ * SDR-01 Keyed by Smart Agent ADDRESS (the `stewardAccount`); names are never
15
+ * authority (ADR-0010).
16
+ * SDR-02 Authorization is `msg.sender == stewardAccount` — the steward SA
17
+ * publishes through its own `execute()` path. NO `isOwner(address)`
18
+ * staticcall fallback (AP diverges from smart-agent; see AgentRelationship).
19
+ * SDR-03 Monotonic per-`skillId` versioning; each version chains the prior
20
+ * version's `ontologyMerkleRoot` as `predecessorRoot` (auditable taxonomy
21
+ * refresh). A skill is never deleted; `deactivate` flips `active`.
22
+ * SDR-04 `skillKind` is a C-box-anchored codelist value: `keccak256(<cbox URI>)`,
23
+ * gate-checked against `packages/ontology` (ADR-0009 lockstep).
24
+ * SDR-05 NO domain/faith vocabulary. This is reusable substrate (spec 251
25
+ * "People groups are excluded").
26
+ * SDR-06 SANITIZED metadata only. `metadataURI` + `conceptHash` carry NEUTRAL,
27
+ * public, non-operational skill vocabulary — never anything that implies
28
+ * private operational data about who holds the skill or where it is used.
29
+ * The agent↔skill association is an OFF-chain vault credential (spec 251).
30
+ * SDR-07 NO on-chain skill↔geo mapping. This registry holds skills only and has
31
+ * ZERO reference to GeoFeatureRegistry (or any geo id). A "skill X in
32
+ * region Y" co-occurrence is an off-chain claim/credential, never an
33
+ * on-chain link between the two definition registries.
34
+ *
35
+ * Ported from smart-agent `SkillDefinitionRegistry`; diverges per spec 251 (AP
36
+ * auth model, C-box-anchored kinds, no `.skill` name binding in v1).
37
+ */
38
+ contract SkillDefinitionRegistry {
39
+ // ─── C-box skill-kind codelist (keccak of the cbox vocabulary URIs) ──
40
+ // Concept URIs are declared in packages/ontology cbox/skill-vocabulary.ttl
41
+ // (scheme aps:skillKind); the lockstep gate asserts these equal keccak of
42
+ // the declared skos:Concept URIs (ADR-0009).
43
+ /// @dev A leaf skill in a controlled taxonomy (e.g. an OASF leaf).
44
+ bytes32 public constant KIND_LEAF = keccak256(bytes("https://agenticprimitives.dev/ns/skill#Leaf"));
45
+ /// @dev A domain/grouping concept (a non-leaf category).
46
+ bytes32 public constant KIND_DOMAIN = keccak256(bytes("https://agenticprimitives.dev/ns/skill#Domain"));
47
+ /// @dev A steward-defined custom skill outside the controlled set.
48
+ bytes32 public constant KIND_CUSTOM = keccak256(bytes("https://agenticprimitives.dev/ns/skill#Custom"));
49
+
50
+ // ─── Errors ─────────────────────────────────────────────────────────
51
+ error NotSteward();
52
+ error SkillNotFound();
53
+ error EmptyMetadata();
54
+ error EmptyId();
55
+
56
+ // ─── Storage ────────────────────────────────────────────────────────
57
+ struct SkillRecord {
58
+ bytes32 skillId; // stable id across versions
59
+ uint64 version; // monotonic per skillId (1-based; 0 = absent)
60
+ address stewardAccount; // governing steward SA
61
+ bytes32 skillKind; // C-box kind codelist value
62
+ bytes32 conceptHash; // keccak of canonical SKOS prefLabel + ancestors
63
+ bytes32 ontologyMerkleRoot; // anchors the RDF/SKOS expansion (off chain)
64
+ bytes32 predecessorRoot; // prior version's ontologyMerkleRoot (0 for v1)
65
+ string metadataURI; // ipfs://… or https://… JSON-LD blob
66
+ uint64 validAfter; // 0 = since inception
67
+ uint64 validUntil; // 0 = indefinite
68
+ bool active;
69
+ uint64 registeredAt;
70
+ }
71
+
72
+ /// @dev skillId => version => record.
73
+ mapping(bytes32 => mapping(uint64 => SkillRecord)) private _records;
74
+ /// @dev skillId => latest version (0 = unknown).
75
+ mapping(bytes32 => uint64) public latestVersion;
76
+ bytes32[] private _allSkills;
77
+
78
+ // ─── Events ─────────────────────────────────────────────────────────
79
+ event SkillPublished(
80
+ bytes32 indexed skillId,
81
+ uint64 indexed version,
82
+ address indexed steward,
83
+ bytes32 skillKind,
84
+ bytes32 conceptHash,
85
+ bytes32 ontologyMerkleRoot,
86
+ bytes32 predecessorRoot,
87
+ string metadataURI
88
+ );
89
+ event SkillDeactivated(bytes32 indexed skillId, uint64 version);
90
+ event SkillValidityChanged(bytes32 indexed skillId, uint64 version, uint64 validAfter, uint64 validUntil);
91
+
92
+ // ─── Publish ────────────────────────────────────────────────────────
93
+ struct PublishInput {
94
+ bytes32 skillId;
95
+ bytes32 skillKind;
96
+ address stewardAccount;
97
+ bytes32 conceptHash;
98
+ bytes32 ontologyMerkleRoot;
99
+ string metadataURI;
100
+ uint64 validAfter;
101
+ uint64 validUntil;
102
+ }
103
+
104
+ /// @notice Publish a new skill definition, or a new version of an existing one.
105
+ function publish(PublishInput calldata p) external returns (uint64 version) {
106
+ if (p.skillId == bytes32(0)) revert EmptyId();
107
+ if (bytes(p.metadataURI).length == 0) revert EmptyMetadata();
108
+ // SDR-02 — only the steward SA, acting through its own execute() path.
109
+ if (msg.sender != p.stewardAccount) revert NotSteward();
110
+
111
+ uint64 prevVer = latestVersion[p.skillId];
112
+ if (prevVer != 0 && _records[p.skillId][prevVer].stewardAccount != p.stewardAccount) {
113
+ // SDR-03 — a new version must come from the SAME steward.
114
+ revert NotSteward();
115
+ }
116
+
117
+ version = prevVer + 1;
118
+ bytes32 predecessorRoot = prevVer == 0 ? bytes32(0) : _records[p.skillId][prevVer].ontologyMerkleRoot;
119
+ latestVersion[p.skillId] = version;
120
+ if (prevVer == 0) _allSkills.push(p.skillId);
121
+ // The heavy record write + event live in a helper so `publish`'s own stack stays shallow.
122
+ _storeAndEmit(p, version, predecessorRoot);
123
+ }
124
+
125
+ /// @dev Writes the record FIELD-BY-FIELD to storage (no in-memory struct literal) and emits.
126
+ /// Behaviour is identical to the prior `_records[...] = SkillRecord({...})` literal; the split
127
+ /// exists only to keep `publish` within solc's stack under `forge coverage --ir-minimum`
128
+ /// instrumentation (the memory struct literal + a dynamic `string` overflowed it by one slot).
129
+ function _storeAndEmit(PublishInput calldata p, uint64 version, bytes32 predecessorRoot) internal {
130
+ SkillRecord storage r = _records[p.skillId][version];
131
+ r.skillId = p.skillId;
132
+ r.version = version;
133
+ r.stewardAccount = p.stewardAccount;
134
+ r.skillKind = p.skillKind;
135
+ r.conceptHash = p.conceptHash;
136
+ r.ontologyMerkleRoot = p.ontologyMerkleRoot;
137
+ r.predecessorRoot = predecessorRoot;
138
+ r.metadataURI = p.metadataURI;
139
+ r.validAfter = p.validAfter;
140
+ r.validUntil = p.validUntil;
141
+ r.active = true;
142
+ r.registeredAt = uint64(block.timestamp);
143
+ emit SkillPublished(p.skillId, version, p.stewardAccount, p.skillKind, p.conceptHash, p.ontologyMerkleRoot, predecessorRoot, p.metadataURI);
144
+ }
145
+
146
+ /// @notice Deactivate the latest version (history is preserved).
147
+ function deactivate(bytes32 skillId) external {
148
+ uint64 v = latestVersion[skillId];
149
+ if (v == 0) revert SkillNotFound();
150
+ SkillRecord storage r = _records[skillId][v];
151
+ if (msg.sender != r.stewardAccount) revert NotSteward();
152
+ r.active = false;
153
+ emit SkillDeactivated(skillId, v);
154
+ }
155
+
156
+ /// @notice Update the validity window of a published version.
157
+ function setValidity(bytes32 skillId, uint64 version, uint64 validAfter, uint64 validUntil) external {
158
+ SkillRecord storage r = _records[skillId][version];
159
+ if (r.version == 0) revert SkillNotFound();
160
+ if (msg.sender != r.stewardAccount) revert NotSteward();
161
+ r.validAfter = validAfter;
162
+ r.validUntil = validUntil;
163
+ emit SkillValidityChanged(skillId, version, validAfter, validUntil);
164
+ }
165
+
166
+ // ─── Views ──────────────────────────────────────────────────────────
167
+ function getSkill(bytes32 skillId, uint64 version) external view returns (SkillRecord memory) {
168
+ SkillRecord memory r = _records[skillId][version];
169
+ if (r.version == 0) revert SkillNotFound();
170
+ return r;
171
+ }
172
+
173
+ function getLatest(bytes32 skillId) external view returns (SkillRecord memory) {
174
+ uint64 v = latestVersion[skillId];
175
+ if (v == 0) revert SkillNotFound();
176
+ return _records[skillId][v];
177
+ }
178
+
179
+ /// @notice True if `version` of `skillId` exists (used by the claim registry to pin a version).
180
+ function exists(bytes32 skillId, uint64 version) external view returns (bool) {
181
+ return _records[skillId][version].version != 0;
182
+ }
183
+
184
+ function allSkills() external view returns (bytes32[] memory) {
185
+ return _allSkills;
186
+ }
187
+ }