@vorionsys/basis 1.0.1 → 1.0.2

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 (183) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE +191 -0
  3. package/README.md +339 -81
  4. package/dist/index.d.ts +10 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +3 -1
  7. package/dist/index.js.map +1 -0
  8. package/dist/kya/accountability.d.ts +39 -0
  9. package/dist/kya/accountability.js.map +1 -0
  10. package/dist/kya/authorization.d.ts +48 -0
  11. package/dist/kya/authorization.js.map +1 -0
  12. package/dist/kya/behavior.d.ts +28 -0
  13. package/dist/kya/behavior.js.map +1 -0
  14. package/dist/kya/identity.d.ts +35 -0
  15. package/dist/kya/identity.js.map +1 -0
  16. package/dist/kya/index.d.ts +50 -0
  17. package/dist/kya/index.js +1 -1
  18. package/dist/kya/index.js.map +1 -0
  19. package/dist/kya/types.d.ts +208 -0
  20. package/dist/kya/types.js.map +1 -0
  21. package/dist/trust-capabilities.d.ts +90 -0
  22. package/dist/trust-capabilities.js +14 -14
  23. package/dist/trust-capabilities.js.map +1 -0
  24. package/dist/trust-factors.d.ts +506 -0
  25. package/dist/trust-factors.d.ts.map +1 -1
  26. package/dist/trust-factors.js +20 -20
  27. package/dist/trust-factors.js.map +1 -0
  28. package/dist/validation-gate.d.ts +438 -0
  29. package/dist/validation-gate.js +2 -2
  30. package/dist/validation-gate.js.map +1 -0
  31. package/package.json +20 -4
  32. package/.env.example +0 -22
  33. package/AMOY-MIGRATION.md +0 -188
  34. package/DEPLOY-AMOY.md +0 -368
  35. package/DEPLOY-NOW.md +0 -216
  36. package/DEPLOYMENT.md +0 -239
  37. package/GET-WALLET.md +0 -286
  38. package/QUICK-WALLET-SETUP.md +0 -268
  39. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +0 -4
  40. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +0 -236
  41. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +0 -4
  42. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +0 -204
  43. package/artifacts/@openzeppelin/contracts/interfaces/IERC4906.sol/IERC4906.dbg.json +0 -4
  44. package/artifacts/@openzeppelin/contracts/interfaces/IERC4906.sol/IERC4906.json +0 -328
  45. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.dbg.json +0 -4
  46. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.json +0 -113
  47. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.dbg.json +0 -4
  48. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.json +0 -97
  49. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.dbg.json +0 -4
  50. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.json +0 -114
  51. package/artifacts/@openzeppelin/contracts/token/ERC721/ERC721.sol/ERC721.dbg.json +0 -4
  52. package/artifacts/@openzeppelin/contracts/token/ERC721/ERC721.sol/ERC721.json +0 -444
  53. package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721.sol/IERC721.dbg.json +0 -4
  54. package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721.sol/IERC721.json +0 -296
  55. package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol/IERC721Receiver.dbg.json +0 -4
  56. package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol/IERC721Receiver.json +0 -45
  57. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol/ERC721Enumerable.dbg.json +0 -4
  58. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol/ERC721Enumerable.json +0 -521
  59. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol/ERC721URIStorage.dbg.json +0 -4
  60. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol/ERC721URIStorage.json +0 -476
  61. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol/IERC721Enumerable.dbg.json +0 -4
  62. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol/IERC721Enumerable.json +0 -352
  63. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol/IERC721Metadata.dbg.json +0 -4
  64. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol/IERC721Metadata.json +0 -341
  65. package/artifacts/@openzeppelin/contracts/token/ERC721/utils/ERC721Utils.sol/ERC721Utils.dbg.json +0 -4
  66. package/artifacts/@openzeppelin/contracts/token/ERC721/utils/ERC721Utils.sol/ERC721Utils.json +0 -10
  67. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +0 -4
  68. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +0 -10
  69. package/artifacts/@openzeppelin/contracts/utils/Panic.sol/Panic.dbg.json +0 -4
  70. package/artifacts/@openzeppelin/contracts/utils/Panic.sol/Panic.json +0 -10
  71. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +0 -4
  72. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +0 -37
  73. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +0 -4
  74. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +0 -30
  75. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +0 -4
  76. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +0 -30
  77. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +0 -4
  78. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +0 -10
  79. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +0 -4
  80. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +0 -65
  81. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +0 -4
  82. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +0 -10
  83. package/artifacts/build-info/357d1bba4062d461f497f221490811a3.json +0 -1
  84. package/artifacts/contracts/AgentCard.sol/AgentCard.dbg.json +0 -4
  85. package/artifacts/contracts/AgentCard.sol/AgentCard.json +0 -1430
  86. package/build_errors.txt +0 -0
  87. package/build_output.txt +0 -0
  88. package/cache/solidity-files-cache.json +0 -885
  89. package/contracts/AgentCard.sol +0 -478
  90. package/contracts/deploy/01-deploy-agentcard.ts +0 -66
  91. package/dist/trust-1000-agents.test.d.ts.map +0 -1
  92. package/dist/trust-1000-agents.test.js +0 -608
  93. package/dist/trust-factors.test.d.ts.map +0 -1
  94. package/dist/trust-factors.test.js +0 -179
  95. package/dist/validation-gate.test.d.ts.map +0 -1
  96. package/dist/validation-gate.test.js +0 -419
  97. package/hardhat.config.ts +0 -55
  98. package/scripts/certify-agent.ts +0 -91
  99. package/scripts/deploy-agentcard.ts +0 -63
  100. package/scripts/mint-agentcard.ts +0 -87
  101. package/specs/adversarial-sandbox-test-suite.md +0 -1055
  102. package/specs/kya-framework.md +0 -910
  103. package/specs/trust-factors-v2.md +0 -437
  104. package/src/index.ts +0 -14
  105. package/src/kya/accountability.ts +0 -132
  106. package/src/kya/authorization.ts +0 -325
  107. package/src/kya/behavior.ts +0 -169
  108. package/src/kya/identity.ts +0 -224
  109. package/src/kya/index.ts +0 -125
  110. package/src/kya/types.ts +0 -242
  111. package/src/trust-1000-agents.test.ts +0 -745
  112. package/src/trust-capabilities.ts +0 -517
  113. package/src/trust-factors.test.ts +0 -241
  114. package/src/trust-factors.ts +0 -666
  115. package/src/validation-gate.test.ts +0 -531
  116. package/src/validation-gate.ts +0 -665
  117. package/test-kya-simple.ts +0 -258
  118. package/test-kya.ts +0 -245
  119. package/tsconfig.json +0 -14
  120. package/typechain-types/@openzeppelin/contracts/access/AccessControl.ts +0 -324
  121. package/typechain-types/@openzeppelin/contracts/access/IAccessControl.ts +0 -292
  122. package/typechain-types/@openzeppelin/contracts/access/index.ts +0 -5
  123. package/typechain-types/@openzeppelin/contracts/index.ts +0 -11
  124. package/typechain-types/@openzeppelin/contracts/interfaces/IERC4906.ts +0 -462
  125. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.ts +0 -69
  126. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.ts +0 -69
  127. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.ts +0 -69
  128. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +0 -6
  129. package/typechain-types/@openzeppelin/contracts/interfaces/index.ts +0 -6
  130. package/typechain-types/@openzeppelin/contracts/token/ERC721/ERC721.ts +0 -420
  131. package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721.ts +0 -393
  132. package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721Receiver.ts +0 -110
  133. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.ts +0 -470
  134. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.ts +0 -489
  135. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.ts +0 -443
  136. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.ts +0 -420
  137. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/index.ts +0 -7
  138. package/typechain-types/@openzeppelin/contracts/token/ERC721/index.ts +0 -8
  139. package/typechain-types/@openzeppelin/contracts/token/index.ts +0 -5
  140. package/typechain-types/@openzeppelin/contracts/utils/Strings.ts +0 -69
  141. package/typechain-types/@openzeppelin/contracts/utils/index.ts +0 -8
  142. package/typechain-types/@openzeppelin/contracts/utils/introspection/ERC165.ts +0 -94
  143. package/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.ts +0 -94
  144. package/typechain-types/@openzeppelin/contracts/utils/introspection/index.ts +0 -5
  145. package/typechain-types/@openzeppelin/contracts/utils/math/SafeCast.ts +0 -69
  146. package/typechain-types/@openzeppelin/contracts/utils/math/index.ts +0 -4
  147. package/typechain-types/@openzeppelin/index.ts +0 -5
  148. package/typechain-types/common.ts +0 -131
  149. package/typechain-types/contracts/AgentCard.ts +0 -1415
  150. package/typechain-types/contracts/index.ts +0 -4
  151. package/typechain-types/factories/@openzeppelin/contracts/access/AccessControl__factory.ts +0 -250
  152. package/typechain-types/factories/@openzeppelin/contracts/access/IAccessControl__factory.ts +0 -218
  153. package/typechain-types/factories/@openzeppelin/contracts/access/index.ts +0 -5
  154. package/typechain-types/factories/@openzeppelin/contracts/index.ts +0 -7
  155. package/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC4906__factory.ts +0 -339
  156. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors__factory.ts +0 -127
  157. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors__factory.ts +0 -111
  158. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors__factory.ts +0 -128
  159. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +0 -6
  160. package/typechain-types/factories/@openzeppelin/contracts/interfaces/index.ts +0 -5
  161. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/ERC721__factory.ts +0 -455
  162. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721Receiver__factory.ts +0 -59
  163. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721__factory.ts +0 -307
  164. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable__factory.ts +0 -535
  165. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage__factory.ts +0 -490
  166. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable__factory.ts +0 -366
  167. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata__factory.ts +0 -355
  168. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/index.ts +0 -7
  169. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/index.ts +0 -7
  170. package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +0 -4
  171. package/typechain-types/factories/@openzeppelin/contracts/utils/Strings__factory.ts +0 -90
  172. package/typechain-types/factories/@openzeppelin/contracts/utils/index.ts +0 -6
  173. package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/ERC165__factory.ts +0 -41
  174. package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.ts +0 -41
  175. package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.ts +0 -5
  176. package/typechain-types/factories/@openzeppelin/contracts/utils/math/SafeCast__factory.ts +0 -118
  177. package/typechain-types/factories/@openzeppelin/contracts/utils/math/index.ts +0 -4
  178. package/typechain-types/factories/@openzeppelin/index.ts +0 -4
  179. package/typechain-types/factories/contracts/AgentCard__factory.ts +0 -1480
  180. package/typechain-types/factories/contracts/index.ts +0 -4
  181. package/typechain-types/factories/index.ts +0 -5
  182. package/typechain-types/index.ts +0 -44
  183. package/vitest.config.ts +0 -8
@@ -1,478 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.20;
3
-
4
- import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
5
- import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
6
- import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
7
- import "@openzeppelin/contracts/access/AccessControl.sol";
8
-
9
- /**
10
- * @title AgentCard
11
- * @dev ERC-721 NFT representing AI agent identity, capabilities, and certification
12
- *
13
- * Part of BASIS (Blockchain Agent Standard for Identity and Security)
14
- * Integrates with KYA (Know Your Agent) framework
15
- *
16
- * Features:
17
- * - W3C DID integration for decentralized identity
18
- * - Capability advertisement (what the agent can do)
19
- * - AgentAnchor certification with trust scores
20
- * - Revocable certifications for safety
21
- * - On-chain trust tier tracking (T0-T5)
22
- */
23
- contract AgentCard is ERC721, ERC721URIStorage, ERC721Enumerable, AccessControl {
24
- // ==========================================================================
25
- // Roles
26
- // ==========================================================================
27
-
28
- bytes32 public constant CERTIFIER_ROLE = keccak256("CERTIFIER_ROLE");
29
- bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
30
-
31
- // ==========================================================================
32
- // State Variables
33
- // ==========================================================================
34
-
35
- uint256 private _nextTokenId;
36
-
37
- // Mapping from DID to token ID (one DID = one card)
38
- mapping(string => uint256) public didToTokenId;
39
-
40
- // Mapping from token ID to AgentCard data
41
- mapping(uint256 => AgentCardData) public cards;
42
-
43
- // Mapping from token ID to capability list
44
- mapping(uint256 => string[]) private _capabilities;
45
-
46
- // Mapping from token ID to restriction list
47
- mapping(uint256 => string[]) private _restrictions;
48
-
49
- // Trust tier definitions
50
- enum TrustTier { T0, T1, T2, T3, T4, T5 }
51
-
52
- // ==========================================================================
53
- // Structs
54
- // ==========================================================================
55
-
56
- struct AgentCardData {
57
- string did; // W3C DID (e.g., "did:vorion:ed25519:...")
58
- string name; // Agent name
59
- string description; // Description
60
- uint256 trustScore; // TSG trust score (0-1000)
61
- TrustTier tier; // Trust tier (T0-T5)
62
- bool certified; // Certified by AgentAnchor?
63
- address certifier; // Certifying organization address
64
- uint256 certificationDate; // Unix timestamp of certification
65
- uint256 certificationExpiry; // Unix timestamp when certification expires
66
- string metadataURI; // IPFS URI to full metadata JSON
67
- bool revoked; // Certification revoked?
68
- }
69
-
70
- // ==========================================================================
71
- // Events
72
- // ==========================================================================
73
-
74
- event AgentCardMinted(
75
- uint256 indexed tokenId,
76
- string did,
77
- address indexed owner,
78
- string name
79
- );
80
-
81
- event AgentCertified(
82
- uint256 indexed tokenId,
83
- string did,
84
- address indexed certifier,
85
- uint256 trustScore,
86
- TrustTier tier
87
- );
88
-
89
- event CertificationRevoked(
90
- uint256 indexed tokenId,
91
- string did,
92
- address indexed certifier,
93
- string reason
94
- );
95
-
96
- event TrustScoreUpdated(
97
- uint256 indexed tokenId,
98
- string did,
99
- uint256 oldScore,
100
- uint256 newScore,
101
- TrustTier newTier
102
- );
103
-
104
- event CapabilitiesUpdated(
105
- uint256 indexed tokenId,
106
- string did,
107
- uint256 capabilityCount
108
- );
109
-
110
- // ==========================================================================
111
- // Constructor
112
- // ==========================================================================
113
-
114
- constructor() ERC721("AgentCard", "AGENT") {
115
- _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
116
- _grantRole(CERTIFIER_ROLE, msg.sender);
117
- _grantRole(MINTER_ROLE, msg.sender);
118
- }
119
-
120
- // ==========================================================================
121
- // Internal Helpers (OpenZeppelin v5 compatibility)
122
- // ==========================================================================
123
-
124
- /**
125
- * @dev Check if token exists
126
- */
127
- function _exists(uint256 tokenId) internal view returns (bool) {
128
- return _ownerOf(tokenId) != address(0);
129
- }
130
-
131
- /**
132
- * @dev Check if spender is approved or owner
133
- */
134
- function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) {
135
- address owner = ownerOf(tokenId);
136
- return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
137
- }
138
-
139
- // ==========================================================================
140
- // Minting
141
- // ==========================================================================
142
-
143
- /**
144
- * @dev Mint new AgentCard NFT
145
- * @param to Address to mint to (agent owner/controller)
146
- * @param did W3C DID for the agent
147
- * @param name Agent name
148
- * @param description Agent description
149
- * @param capabilities Array of capability strings
150
- * @param metadataURI IPFS URI to full metadata
151
- */
152
- function mint(
153
- address to,
154
- string memory did,
155
- string memory name,
156
- string memory description,
157
- string[] memory capabilities,
158
- string memory metadataURI
159
- ) public onlyRole(MINTER_ROLE) returns (uint256) {
160
- // Ensure DID is unique (one card per DID)
161
- require(didToTokenId[did] == 0, "AgentCard: DID already exists");
162
-
163
- uint256 tokenId = _nextTokenId++;
164
-
165
- // Mint NFT
166
- _safeMint(to, tokenId);
167
- _setTokenURI(tokenId, metadataURI);
168
-
169
- // Store AgentCard data
170
- cards[tokenId] = AgentCardData({
171
- did: did,
172
- name: name,
173
- description: description,
174
- trustScore: 0,
175
- tier: TrustTier.T0, // All agents start at T0 (Sandbox)
176
- certified: false,
177
- certifier: address(0),
178
- certificationDate: 0,
179
- certificationExpiry: 0,
180
- metadataURI: metadataURI,
181
- revoked: false
182
- });
183
-
184
- // Store DID mapping
185
- didToTokenId[did] = tokenId;
186
-
187
- // Store capabilities
188
- for (uint i = 0; i < capabilities.length; i++) {
189
- _capabilities[tokenId].push(capabilities[i]);
190
- }
191
-
192
- emit AgentCardMinted(tokenId, did, to, name);
193
-
194
- return tokenId;
195
- }
196
-
197
- // ==========================================================================
198
- // Certification (AgentAnchor)
199
- // ==========================================================================
200
-
201
- /**
202
- * @dev Certify an agent (assign trust score and tier)
203
- * @param tokenId Token ID to certify
204
- * @param trustScore Trust score (0-1000)
205
- * @param expiryTimestamp When certification expires (Unix timestamp)
206
- */
207
- function certify(
208
- uint256 tokenId,
209
- uint256 trustScore,
210
- uint256 expiryTimestamp
211
- ) public onlyRole(CERTIFIER_ROLE) {
212
- require(_exists(tokenId), "AgentCard: Token does not exist");
213
- require(trustScore <= 1000, "AgentCard: Trust score must be <= 1000");
214
- require(expiryTimestamp > block.timestamp, "AgentCard: Expiry must be in future");
215
-
216
- AgentCardData storage card = cards[tokenId];
217
-
218
- // Derive trust tier from score
219
- TrustTier tier = _deriveTier(trustScore);
220
-
221
- // Update certification
222
- card.certified = true;
223
- card.certifier = msg.sender;
224
- card.certificationDate = block.timestamp;
225
- card.certificationExpiry = expiryTimestamp;
226
- card.trustScore = trustScore;
227
- card.tier = tier;
228
- card.revoked = false;
229
-
230
- emit AgentCertified(tokenId, card.did, msg.sender, trustScore, tier);
231
- }
232
-
233
- /**
234
- * @dev Revoke certification
235
- * @param tokenId Token ID to revoke
236
- * @param reason Reason for revocation
237
- */
238
- function revokeCertification(
239
- uint256 tokenId,
240
- string memory reason
241
- ) public onlyRole(CERTIFIER_ROLE) {
242
- require(_exists(tokenId), "AgentCard: Token does not exist");
243
-
244
- AgentCardData storage card = cards[tokenId];
245
- require(card.certified, "AgentCard: Not certified");
246
- require(card.certifier == msg.sender, "AgentCard: Only certifier can revoke");
247
-
248
- // Revoke certification, reset to T0
249
- card.certified = false;
250
- card.revoked = true;
251
- card.tier = TrustTier.T0;
252
- card.trustScore = 0;
253
-
254
- emit CertificationRevoked(tokenId, card.did, msg.sender, reason);
255
- }
256
-
257
- /**
258
- * @dev Update trust score (e.g., from TSG real-time monitoring)
259
- * @param tokenId Token ID to update
260
- * @param newTrustScore New trust score (0-1000)
261
- */
262
- function updateTrustScore(
263
- uint256 tokenId,
264
- uint256 newTrustScore
265
- ) public onlyRole(CERTIFIER_ROLE) {
266
- require(_exists(tokenId), "AgentCard: Token does not exist");
267
- require(newTrustScore <= 1000, "AgentCard: Trust score must be <= 1000");
268
-
269
- AgentCardData storage card = cards[tokenId];
270
- require(card.certified, "AgentCard: Not certified");
271
-
272
- uint256 oldScore = card.trustScore;
273
- TrustTier newTier = _deriveTier(newTrustScore);
274
-
275
- card.trustScore = newTrustScore;
276
- card.tier = newTier;
277
-
278
- emit TrustScoreUpdated(tokenId, card.did, oldScore, newTrustScore, newTier);
279
- }
280
-
281
- // ==========================================================================
282
- // Capabilities Management
283
- // ==========================================================================
284
-
285
- /**
286
- * @dev Add capabilities to agent
287
- * @param tokenId Token ID
288
- * @param capabilities Array of capability strings to add
289
- */
290
- function addCapabilities(
291
- uint256 tokenId,
292
- string[] memory capabilities
293
- ) public {
294
- require(_exists(tokenId), "AgentCard: Token does not exist");
295
- require(_isApprovedOrOwner(msg.sender, tokenId), "AgentCard: Not authorized");
296
-
297
- for (uint i = 0; i < capabilities.length; i++) {
298
- _capabilities[tokenId].push(capabilities[i]);
299
- }
300
-
301
- emit CapabilitiesUpdated(tokenId, cards[tokenId].did, _capabilities[tokenId].length);
302
- }
303
-
304
- /**
305
- * @dev Add restrictions to agent
306
- * @param tokenId Token ID
307
- * @param restrictions Array of restriction strings to add
308
- */
309
- function addRestrictions(
310
- uint256 tokenId,
311
- string[] memory restrictions
312
- ) public {
313
- require(_exists(tokenId), "AgentCard: Token does not exist");
314
- require(_isApprovedOrOwner(msg.sender, tokenId), "AgentCard: Not authorized");
315
-
316
- for (uint i = 0; i < restrictions.length; i++) {
317
- _restrictions[tokenId].push(restrictions[i]);
318
- }
319
- }
320
-
321
- // ==========================================================================
322
- // View Functions
323
- // ==========================================================================
324
-
325
- /**
326
- * @dev Get AgentCard data by token ID
327
- */
328
- function getCard(uint256 tokenId) public view returns (AgentCardData memory) {
329
- require(_exists(tokenId), "AgentCard: Token does not exist");
330
- return cards[tokenId];
331
- }
332
-
333
- /**
334
- * @dev Get AgentCard data by DID
335
- */
336
- function getCardByDID(string memory did) public view returns (AgentCardData memory) {
337
- uint256 tokenId = didToTokenId[did];
338
- require(tokenId != 0, "AgentCard: DID not found");
339
- return cards[tokenId];
340
- }
341
-
342
- /**
343
- * @dev Get capabilities for token
344
- */
345
- function getCapabilities(uint256 tokenId) public view returns (string[] memory) {
346
- require(_exists(tokenId), "AgentCard: Token does not exist");
347
- return _capabilities[tokenId];
348
- }
349
-
350
- /**
351
- * @dev Get restrictions for token
352
- */
353
- function getRestrictions(uint256 tokenId) public view returns (string[] memory) {
354
- require(_exists(tokenId), "AgentCard: Token does not exist");
355
- return _restrictions[tokenId];
356
- }
357
-
358
- /**
359
- * @dev Check if agent is certified and not expired/revoked
360
- */
361
- function isCertified(uint256 tokenId) public view returns (bool) {
362
- require(_exists(tokenId), "AgentCard: Token does not exist");
363
- AgentCardData memory card = cards[tokenId];
364
-
365
- return card.certified &&
366
- !card.revoked &&
367
- block.timestamp < card.certificationExpiry;
368
- }
369
-
370
- /**
371
- * @dev Get all AgentCards owned by an address
372
- */
373
- function getCardsByOwner(address owner) public view returns (uint256[] memory) {
374
- uint256 balance = balanceOf(owner);
375
- uint256[] memory tokenIds = new uint256[](balance);
376
-
377
- for (uint256 i = 0; i < balance; i++) {
378
- tokenIds[i] = tokenOfOwnerByIndex(owner, i);
379
- }
380
-
381
- return tokenIds;
382
- }
383
-
384
- /**
385
- * @dev Get all certified agents (paginated)
386
- */
387
- function getCertifiedAgents(uint256 offset, uint256 limit)
388
- public
389
- view
390
- returns (uint256[] memory)
391
- {
392
- uint256 total = totalSupply();
393
- uint256 count = 0;
394
-
395
- // First pass: count certified agents
396
- for (uint256 i = 0; i < total; i++) {
397
- uint256 tokenId = tokenByIndex(i);
398
- if (isCertified(tokenId)) {
399
- count++;
400
- }
401
- }
402
-
403
- // Calculate result size
404
- uint256 resultSize = count > offset ? count - offset : 0;
405
- if (resultSize > limit) {
406
- resultSize = limit;
407
- }
408
-
409
- uint256[] memory result = new uint256[](resultSize);
410
- uint256 resultIndex = 0;
411
- uint256 certifiedCount = 0;
412
-
413
- // Second pass: collect certified agents
414
- for (uint256 i = 0; i < total && resultIndex < resultSize; i++) {
415
- uint256 tokenId = tokenByIndex(i);
416
- if (isCertified(tokenId)) {
417
- if (certifiedCount >= offset) {
418
- result[resultIndex] = tokenId;
419
- resultIndex++;
420
- }
421
- certifiedCount++;
422
- }
423
- }
424
-
425
- return result;
426
- }
427
-
428
- // ==========================================================================
429
- // Internal Functions
430
- // ==========================================================================
431
-
432
- /**
433
- * @dev Derive trust tier from score
434
- * Based on Vorion's 6-tier trust model
435
- */
436
- function _deriveTier(uint256 score) internal pure returns (TrustTier) {
437
- if (score >= 850) return TrustTier.T5; // Certified
438
- if (score >= 700) return TrustTier.T4; // Advanced
439
- if (score >= 500) return TrustTier.T3; // Elevated
440
- if (score >= 300) return TrustTier.T2; // Standard
441
- if (score >= 100) return TrustTier.T1; // Basic
442
- return TrustTier.T0; // Sandbox
443
- }
444
-
445
- // ==========================================================================
446
- // Required Overrides (ERC721 + Extensions) - OpenZeppelin v5
447
- // ==========================================================================
448
-
449
- function _update(
450
- address to,
451
- uint256 tokenId,
452
- address auth
453
- ) internal override(ERC721, ERC721Enumerable) returns (address) {
454
- return super._update(to, tokenId, auth);
455
- }
456
-
457
- function _increaseBalance(address account, uint128 value) internal override(ERC721, ERC721Enumerable) {
458
- super._increaseBalance(account, value);
459
- }
460
-
461
- function tokenURI(uint256 tokenId)
462
- public
463
- view
464
- override(ERC721, ERC721URIStorage)
465
- returns (string memory)
466
- {
467
- return super.tokenURI(tokenId);
468
- }
469
-
470
- function supportsInterface(bytes4 interfaceId)
471
- public
472
- view
473
- override(ERC721, ERC721Enumerable, ERC721URIStorage, AccessControl)
474
- returns (bool)
475
- {
476
- return super.supportsInterface(interfaceId);
477
- }
478
- }
@@ -1,66 +0,0 @@
1
- import { HardhatRuntimeEnvironment } from 'hardhat/types';
2
- import { DeployFunction } from 'hardhat-deploy/types';
3
-
4
- /**
5
- * Deploy AgentCard NFT contract
6
- *
7
- * Network deployment targets:
8
- * - Polygon Mainnet (production)
9
- * - Polygon Mumbai (testnet)
10
- * - Hardhat Network (local development)
11
- */
12
- const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
13
- const { deployments, getNamedAccounts, network } = hre;
14
- const { deploy, log } = deployments;
15
- const { deployer, certifier } = await getNamedAccounts();
16
-
17
- log(`Deploying AgentCard to ${network.name}...`);
18
-
19
- const agentCard = await deploy('AgentCard', {
20
- from: deployer,
21
- args: [],
22
- log: true,
23
- waitConfirmations: network.name === 'polygon' ? 5 : 1,
24
- });
25
-
26
- log(`AgentCard deployed to: ${agentCard.address}`);
27
-
28
- // Grant CERTIFIER_ROLE to designated certifier address
29
- if (certifier && certifier !== deployer) {
30
- log(`Granting CERTIFIER_ROLE to ${certifier}...`);
31
-
32
- const agentCardContract = await hre.ethers.getContractAt(
33
- 'AgentCard',
34
- agentCard.address
35
- );
36
-
37
- const CERTIFIER_ROLE = await agentCardContract.CERTIFIER_ROLE();
38
- const tx = await agentCardContract.grantRole(CERTIFIER_ROLE, certifier);
39
- await tx.wait();
40
-
41
- log(`CERTIFIER_ROLE granted to ${certifier}`);
42
- }
43
-
44
- // Verify contract on Etherscan/Polygonscan
45
- if (
46
- network.name !== 'hardhat' &&
47
- network.name !== 'localhost' &&
48
- process.env.ETHERSCAN_API_KEY
49
- ) {
50
- log('Verifying contract on block explorer...');
51
- try {
52
- await hre.run('verify:verify', {
53
- address: agentCard.address,
54
- constructorArguments: [],
55
- });
56
- log('Contract verified successfully');
57
- } catch (error) {
58
- log('Contract verification failed:', error);
59
- }
60
- }
61
-
62
- return true;
63
- };
64
-
65
- export default func;
66
- func.tags = ['AgentCard', 'BASIS'];
@@ -1 +0,0 @@
1
- {"version":3,"file":"trust-1000-agents.test.d.ts","sourceRoot":"","sources":["../src/trust-1000-agents.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}