@vorionsys/basis 1.0.1
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.
- package/.env.example +22 -0
- package/AMOY-MIGRATION.md +188 -0
- package/DEPLOY-AMOY.md +368 -0
- package/DEPLOY-NOW.md +216 -0
- package/DEPLOYMENT.md +239 -0
- package/GET-WALLET.md +286 -0
- package/QUICK-WALLET-SETUP.md +268 -0
- package/README.md +195 -0
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +236 -0
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +204 -0
- package/artifacts/@openzeppelin/contracts/interfaces/IERC4906.sol/IERC4906.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/interfaces/IERC4906.sol/IERC4906.json +328 -0
- package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.json +113 -0
- package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.json +97 -0
- package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.json +114 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/ERC721.sol/ERC721.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/ERC721.sol/ERC721.json +444 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721.sol/IERC721.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721.sol/IERC721.json +296 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol/IERC721Receiver.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol/IERC721Receiver.json +45 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol/ERC721Enumerable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol/ERC721Enumerable.json +521 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol/ERC721URIStorage.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol/ERC721URIStorage.json +476 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol/IERC721Enumerable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol/IERC721Enumerable.json +352 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol/IERC721Metadata.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol/IERC721Metadata.json +341 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/utils/ERC721Utils.sol/ERC721Utils.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC721/utils/ERC721Utils.sol/ERC721Utils.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/Panic.sol/Panic.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Panic.sol/Panic.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +37 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +30 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +30 -0
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +65 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +10 -0
- package/artifacts/build-info/357d1bba4062d461f497f221490811a3.json +1 -0
- package/artifacts/contracts/AgentCard.sol/AgentCard.dbg.json +4 -0
- package/artifacts/contracts/AgentCard.sol/AgentCard.json +1430 -0
- package/build_errors.txt +0 -0
- package/build_output.txt +0 -0
- package/cache/solidity-files-cache.json +885 -0
- package/contracts/AgentCard.sol +478 -0
- package/contracts/deploy/01-deploy-agentcard.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/kya/accountability.d.ts.map +1 -0
- package/dist/kya/accountability.js +100 -0
- package/dist/kya/authorization.d.ts.map +1 -0
- package/dist/kya/authorization.js +258 -0
- package/dist/kya/behavior.d.ts.map +1 -0
- package/dist/kya/behavior.js +142 -0
- package/dist/kya/identity.d.ts.map +1 -0
- package/dist/kya/identity.js +187 -0
- package/dist/kya/index.d.ts.map +1 -0
- package/dist/kya/index.js +99 -0
- package/dist/kya/types.d.ts.map +1 -0
- package/dist/kya/types.js +5 -0
- package/dist/trust-1000-agents.test.d.ts.map +1 -0
- package/dist/trust-1000-agents.test.js +608 -0
- package/dist/trust-capabilities.d.ts.map +1 -0
- package/dist/trust-capabilities.js +478 -0
- package/dist/trust-factors.d.ts.map +1 -0
- package/dist/trust-factors.js +588 -0
- package/dist/trust-factors.test.d.ts.map +1 -0
- package/dist/trust-factors.test.js +179 -0
- package/dist/validation-gate.d.ts.map +1 -0
- package/dist/validation-gate.js +468 -0
- package/dist/validation-gate.test.d.ts.map +1 -0
- package/dist/validation-gate.test.js +419 -0
- package/hardhat.config.ts +55 -0
- package/package.json +57 -0
- package/scripts/certify-agent.ts +91 -0
- package/scripts/deploy-agentcard.ts +63 -0
- package/scripts/mint-agentcard.ts +87 -0
- package/specs/adversarial-sandbox-test-suite.md +1055 -0
- package/specs/kya-framework.md +910 -0
- package/specs/trust-factors-v2.md +437 -0
- package/src/index.ts +14 -0
- package/src/kya/accountability.ts +132 -0
- package/src/kya/authorization.ts +325 -0
- package/src/kya/behavior.ts +169 -0
- package/src/kya/identity.ts +224 -0
- package/src/kya/index.ts +125 -0
- package/src/kya/types.ts +242 -0
- package/src/trust-1000-agents.test.ts +745 -0
- package/src/trust-capabilities.ts +517 -0
- package/src/trust-factors.test.ts +241 -0
- package/src/trust-factors.ts +666 -0
- package/src/validation-gate.test.ts +531 -0
- package/src/validation-gate.ts +665 -0
- package/test-kya-simple.ts +258 -0
- package/test-kya.ts +245 -0
- package/tsconfig.json +14 -0
- package/typechain-types/@openzeppelin/contracts/access/AccessControl.ts +324 -0
- package/typechain-types/@openzeppelin/contracts/access/IAccessControl.ts +292 -0
- package/typechain-types/@openzeppelin/contracts/access/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/index.ts +11 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/IERC4906.ts +462 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +6 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/index.ts +6 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/ERC721.ts +420 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721.ts +393 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721Receiver.ts +110 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.ts +470 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.ts +489 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.ts +443 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.ts +420 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/index.ts +7 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/index.ts +8 -0
- package/typechain-types/@openzeppelin/contracts/token/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/utils/Strings.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/utils/index.ts +8 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/ERC165.ts +94 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.ts +94 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/utils/math/SafeCast.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/utils/math/index.ts +4 -0
- package/typechain-types/@openzeppelin/index.ts +5 -0
- package/typechain-types/common.ts +131 -0
- package/typechain-types/contracts/AgentCard.ts +1415 -0
- package/typechain-types/contracts/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/access/AccessControl__factory.ts +250 -0
- package/typechain-types/factories/@openzeppelin/contracts/access/IAccessControl__factory.ts +218 -0
- package/typechain-types/factories/@openzeppelin/contracts/access/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/index.ts +7 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC4906__factory.ts +339 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors__factory.ts +127 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors__factory.ts +111 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors__factory.ts +128 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +6 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/ERC721__factory.ts +455 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721Receiver__factory.ts +59 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721__factory.ts +307 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable__factory.ts +535 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage__factory.ts +490 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable__factory.ts +366 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata__factory.ts +355 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/index.ts +7 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/index.ts +7 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/Strings__factory.ts +90 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/index.ts +6 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/ERC165__factory.ts +41 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.ts +41 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/math/SafeCast__factory.ts +118 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/math/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/index.ts +4 -0
- package/typechain-types/factories/contracts/AgentCard__factory.ts +1480 -0
- package/typechain-types/factories/contracts/index.ts +4 -0
- package/typechain-types/factories/index.ts +5 -0
- package/typechain-types/index.ts +44 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,478 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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'];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,iBAAiB,CAAC;AAGhC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,OAAO,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BASIS - Behavioral AI Safety & Integrity Standard
|
|
3
|
+
*
|
|
4
|
+
* Core trust framework for autonomous AI agents
|
|
5
|
+
*/
|
|
6
|
+
// Trust Factors - Scoring criteria
|
|
7
|
+
export * from './trust-factors';
|
|
8
|
+
// Trust Capabilities - What agents can do at each tier
|
|
9
|
+
export * from './trust-capabilities';
|
|
10
|
+
// KYA (Know Your Agent) - Identity and authorization
|
|
11
|
+
export * from './kya';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accountability.d.ts","sourceRoot":"","sources":["../../src/kya/accountability.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAElE,qBAAa,mBAAmB;IAGlB,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,OAAO,CAAsC;gBAEjC,MAAM,EAAE,cAAc;IAK1C;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBzD;;OAEG;IACG,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QACtC,KAAK,EAAE,OAAO,CAAC;QACf,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IAgCF;;OAEG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QACtC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7B,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;KAC5C,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAmBnC;;OAEG;IACH,OAAO,CAAC,aAAa;IAcrB;;OAEG;YACW,yBAAyB;CAQxC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KYA Accountability Chain
|
|
3
|
+
* Immutable hash-linked audit trail
|
|
4
|
+
*/
|
|
5
|
+
import { createHash } from 'crypto';
|
|
6
|
+
export class AccountabilityChain {
|
|
7
|
+
config;
|
|
8
|
+
records;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.records = new Map();
|
|
12
|
+
// Would initialize database connection here
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Append record to accountability chain
|
|
16
|
+
*/
|
|
17
|
+
async append(record) {
|
|
18
|
+
// 1. Get previous record for this agent
|
|
19
|
+
const agentRecords = this.records.get(record.agentDID) || [];
|
|
20
|
+
const prevRecord = agentRecords[agentRecords.length - 1];
|
|
21
|
+
// 2. Set previous hash
|
|
22
|
+
record.chainLink.prevHash = prevRecord ? this.calculateHash(prevRecord) : null;
|
|
23
|
+
// 3. Calculate hash for this record
|
|
24
|
+
const hash = this.calculateHash(record);
|
|
25
|
+
// 4. Store record (would be database insert)
|
|
26
|
+
agentRecords.push(record);
|
|
27
|
+
this.records.set(record.agentDID, agentRecords);
|
|
28
|
+
// 5. Optional: Update agent's accountability score
|
|
29
|
+
await this.updateAccountabilityScore(record.agentDID, record.outcome);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Verify chain integrity for agent
|
|
33
|
+
*/
|
|
34
|
+
async verify(agentDID) {
|
|
35
|
+
const records = this.records.get(agentDID) || [];
|
|
36
|
+
let brokenLinks = 0;
|
|
37
|
+
let prevHash = null;
|
|
38
|
+
for (const record of records) {
|
|
39
|
+
if (record.chainLink.prevHash !== prevHash) {
|
|
40
|
+
brokenLinks++;
|
|
41
|
+
}
|
|
42
|
+
// Verify hash
|
|
43
|
+
const expectedHash = this.calculateHash(record);
|
|
44
|
+
const actualHash = this.calculateHash({
|
|
45
|
+
...record,
|
|
46
|
+
chainLink: { ...record.chainLink },
|
|
47
|
+
});
|
|
48
|
+
if (expectedHash !== actualHash) {
|
|
49
|
+
brokenLinks++;
|
|
50
|
+
}
|
|
51
|
+
prevHash = expectedHash;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
valid: brokenLinks === 0,
|
|
55
|
+
totalRecords: records.length,
|
|
56
|
+
brokenLinks,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Query records for agent
|
|
61
|
+
*/
|
|
62
|
+
async query(agentDID, options) {
|
|
63
|
+
let records = this.records.get(agentDID) || [];
|
|
64
|
+
if (options?.action) {
|
|
65
|
+
records = records.filter(r => r.action === options.action);
|
|
66
|
+
}
|
|
67
|
+
if (options?.timeRange) {
|
|
68
|
+
const [start, end] = options.timeRange;
|
|
69
|
+
records = records.filter(r => r.timestamp >= start && r.timestamp <= end);
|
|
70
|
+
}
|
|
71
|
+
if (options?.outcome) {
|
|
72
|
+
records = records.filter(r => r.outcome === options.outcome);
|
|
73
|
+
}
|
|
74
|
+
return records;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Calculate hash for record
|
|
78
|
+
*/
|
|
79
|
+
calculateHash(record) {
|
|
80
|
+
const content = JSON.stringify({
|
|
81
|
+
timestamp: record.timestamp,
|
|
82
|
+
agentDID: record.agentDID,
|
|
83
|
+
action: record.action,
|
|
84
|
+
resource: record.resource,
|
|
85
|
+
outcome: record.outcome,
|
|
86
|
+
evidence: record.evidence,
|
|
87
|
+
prevHash: record.chainLink.prevHash,
|
|
88
|
+
});
|
|
89
|
+
return createHash('sha256').update(content).digest('hex');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Update agent's accountability score
|
|
93
|
+
*/
|
|
94
|
+
async updateAccountabilityScore(agentDID, outcome) {
|
|
95
|
+
// Would update TSG trust score based on outcome
|
|
96
|
+
const impact = outcome === 'success' ? 1 : outcome === 'failure' ? -5 : -10;
|
|
97
|
+
// await tsg.updateTrustScore(agentDID, impact);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=accountability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../src/kya/authorization.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EAEf,kBAAkB,EAEnB,MAAM,YAAY,CAAC;AAEpB,qBAAa,oBAAoB;IAInB,OAAO,CAAC,MAAM;IAH1B,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,YAAY,CAAiC;gBAEjC,MAAM,EAAE,kBAAkB;IAQ9C;;OAEG;IACG,SAAS,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAwE9E;;OAEG;IACG,eAAe,CACnB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,IAAI,CAAC;IAMhB;;OAEG;IACG,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU7E;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAiBzB;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;OAEG;YACW,kBAAkB;IAuBhC;;OAEG;YACW,sBAAsB;IAiCpC;;OAEG;YACW,kBAAkB;IAiBhC;;OAEG;IACH,OAAO,CAAC,iBAAiB;CA6B1B"}
|