@vorionsys/basis 1.0.1 → 1.0.3

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 (185) 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 +6 -4
  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.d.ts.map +1 -1
  23. package/dist/trust-capabilities.js +19 -19
  24. package/dist/trust-capabilities.js.map +1 -0
  25. package/dist/trust-factors.d.ts +668 -0
  26. package/dist/trust-factors.d.ts.map +1 -1
  27. package/dist/trust-factors.js +86 -91
  28. package/dist/trust-factors.js.map +1 -0
  29. package/dist/validation-gate.d.ts +438 -0
  30. package/dist/validation-gate.d.ts.map +1 -1
  31. package/dist/validation-gate.js +4 -4
  32. package/dist/validation-gate.js.map +1 -0
  33. package/package.json +20 -4
  34. package/.env.example +0 -22
  35. package/AMOY-MIGRATION.md +0 -188
  36. package/DEPLOY-AMOY.md +0 -368
  37. package/DEPLOY-NOW.md +0 -216
  38. package/DEPLOYMENT.md +0 -239
  39. package/GET-WALLET.md +0 -286
  40. package/QUICK-WALLET-SETUP.md +0 -268
  41. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +0 -4
  42. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +0 -236
  43. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +0 -4
  44. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +0 -204
  45. package/artifacts/@openzeppelin/contracts/interfaces/IERC4906.sol/IERC4906.dbg.json +0 -4
  46. package/artifacts/@openzeppelin/contracts/interfaces/IERC4906.sol/IERC4906.json +0 -328
  47. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.dbg.json +0 -4
  48. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.json +0 -113
  49. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.dbg.json +0 -4
  50. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.json +0 -97
  51. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.dbg.json +0 -4
  52. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.json +0 -114
  53. package/artifacts/@openzeppelin/contracts/token/ERC721/ERC721.sol/ERC721.dbg.json +0 -4
  54. package/artifacts/@openzeppelin/contracts/token/ERC721/ERC721.sol/ERC721.json +0 -444
  55. package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721.sol/IERC721.dbg.json +0 -4
  56. package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721.sol/IERC721.json +0 -296
  57. package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol/IERC721Receiver.dbg.json +0 -4
  58. package/artifacts/@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol/IERC721Receiver.json +0 -45
  59. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol/ERC721Enumerable.dbg.json +0 -4
  60. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol/ERC721Enumerable.json +0 -521
  61. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol/ERC721URIStorage.dbg.json +0 -4
  62. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol/ERC721URIStorage.json +0 -476
  63. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol/IERC721Enumerable.dbg.json +0 -4
  64. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol/IERC721Enumerable.json +0 -352
  65. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol/IERC721Metadata.dbg.json +0 -4
  66. package/artifacts/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol/IERC721Metadata.json +0 -341
  67. package/artifacts/@openzeppelin/contracts/token/ERC721/utils/ERC721Utils.sol/ERC721Utils.dbg.json +0 -4
  68. package/artifacts/@openzeppelin/contracts/token/ERC721/utils/ERC721Utils.sol/ERC721Utils.json +0 -10
  69. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +0 -4
  70. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +0 -10
  71. package/artifacts/@openzeppelin/contracts/utils/Panic.sol/Panic.dbg.json +0 -4
  72. package/artifacts/@openzeppelin/contracts/utils/Panic.sol/Panic.json +0 -10
  73. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +0 -4
  74. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +0 -37
  75. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +0 -4
  76. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +0 -30
  77. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +0 -4
  78. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +0 -30
  79. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +0 -4
  80. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +0 -10
  81. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +0 -4
  82. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +0 -65
  83. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +0 -4
  84. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +0 -10
  85. package/artifacts/build-info/357d1bba4062d461f497f221490811a3.json +0 -1
  86. package/artifacts/contracts/AgentCard.sol/AgentCard.dbg.json +0 -4
  87. package/artifacts/contracts/AgentCard.sol/AgentCard.json +0 -1430
  88. package/build_errors.txt +0 -0
  89. package/build_output.txt +0 -0
  90. package/cache/solidity-files-cache.json +0 -885
  91. package/contracts/AgentCard.sol +0 -478
  92. package/contracts/deploy/01-deploy-agentcard.ts +0 -66
  93. package/dist/trust-1000-agents.test.d.ts.map +0 -1
  94. package/dist/trust-1000-agents.test.js +0 -608
  95. package/dist/trust-factors.test.d.ts.map +0 -1
  96. package/dist/trust-factors.test.js +0 -179
  97. package/dist/validation-gate.test.d.ts.map +0 -1
  98. package/dist/validation-gate.test.js +0 -419
  99. package/hardhat.config.ts +0 -55
  100. package/scripts/certify-agent.ts +0 -91
  101. package/scripts/deploy-agentcard.ts +0 -63
  102. package/scripts/mint-agentcard.ts +0 -87
  103. package/specs/adversarial-sandbox-test-suite.md +0 -1055
  104. package/specs/kya-framework.md +0 -910
  105. package/specs/trust-factors-v2.md +0 -437
  106. package/src/index.ts +0 -14
  107. package/src/kya/accountability.ts +0 -132
  108. package/src/kya/authorization.ts +0 -325
  109. package/src/kya/behavior.ts +0 -169
  110. package/src/kya/identity.ts +0 -224
  111. package/src/kya/index.ts +0 -125
  112. package/src/kya/types.ts +0 -242
  113. package/src/trust-1000-agents.test.ts +0 -745
  114. package/src/trust-capabilities.ts +0 -517
  115. package/src/trust-factors.test.ts +0 -241
  116. package/src/trust-factors.ts +0 -666
  117. package/src/validation-gate.test.ts +0 -531
  118. package/src/validation-gate.ts +0 -665
  119. package/test-kya-simple.ts +0 -258
  120. package/test-kya.ts +0 -245
  121. package/tsconfig.json +0 -14
  122. package/typechain-types/@openzeppelin/contracts/access/AccessControl.ts +0 -324
  123. package/typechain-types/@openzeppelin/contracts/access/IAccessControl.ts +0 -292
  124. package/typechain-types/@openzeppelin/contracts/access/index.ts +0 -5
  125. package/typechain-types/@openzeppelin/contracts/index.ts +0 -11
  126. package/typechain-types/@openzeppelin/contracts/interfaces/IERC4906.ts +0 -462
  127. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.ts +0 -69
  128. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.ts +0 -69
  129. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.ts +0 -69
  130. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +0 -6
  131. package/typechain-types/@openzeppelin/contracts/interfaces/index.ts +0 -6
  132. package/typechain-types/@openzeppelin/contracts/token/ERC721/ERC721.ts +0 -420
  133. package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721.ts +0 -393
  134. package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721Receiver.ts +0 -110
  135. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.ts +0 -470
  136. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.ts +0 -489
  137. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.ts +0 -443
  138. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.ts +0 -420
  139. package/typechain-types/@openzeppelin/contracts/token/ERC721/extensions/index.ts +0 -7
  140. package/typechain-types/@openzeppelin/contracts/token/ERC721/index.ts +0 -8
  141. package/typechain-types/@openzeppelin/contracts/token/index.ts +0 -5
  142. package/typechain-types/@openzeppelin/contracts/utils/Strings.ts +0 -69
  143. package/typechain-types/@openzeppelin/contracts/utils/index.ts +0 -8
  144. package/typechain-types/@openzeppelin/contracts/utils/introspection/ERC165.ts +0 -94
  145. package/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.ts +0 -94
  146. package/typechain-types/@openzeppelin/contracts/utils/introspection/index.ts +0 -5
  147. package/typechain-types/@openzeppelin/contracts/utils/math/SafeCast.ts +0 -69
  148. package/typechain-types/@openzeppelin/contracts/utils/math/index.ts +0 -4
  149. package/typechain-types/@openzeppelin/index.ts +0 -5
  150. package/typechain-types/common.ts +0 -131
  151. package/typechain-types/contracts/AgentCard.ts +0 -1415
  152. package/typechain-types/contracts/index.ts +0 -4
  153. package/typechain-types/factories/@openzeppelin/contracts/access/AccessControl__factory.ts +0 -250
  154. package/typechain-types/factories/@openzeppelin/contracts/access/IAccessControl__factory.ts +0 -218
  155. package/typechain-types/factories/@openzeppelin/contracts/access/index.ts +0 -5
  156. package/typechain-types/factories/@openzeppelin/contracts/index.ts +0 -7
  157. package/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC4906__factory.ts +0 -339
  158. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors__factory.ts +0 -127
  159. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors__factory.ts +0 -111
  160. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors__factory.ts +0 -128
  161. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +0 -6
  162. package/typechain-types/factories/@openzeppelin/contracts/interfaces/index.ts +0 -5
  163. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/ERC721__factory.ts +0 -455
  164. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721Receiver__factory.ts +0 -59
  165. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721__factory.ts +0 -307
  166. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable__factory.ts +0 -535
  167. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage__factory.ts +0 -490
  168. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable__factory.ts +0 -366
  169. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata__factory.ts +0 -355
  170. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/extensions/index.ts +0 -7
  171. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/index.ts +0 -7
  172. package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +0 -4
  173. package/typechain-types/factories/@openzeppelin/contracts/utils/Strings__factory.ts +0 -90
  174. package/typechain-types/factories/@openzeppelin/contracts/utils/index.ts +0 -6
  175. package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/ERC165__factory.ts +0 -41
  176. package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.ts +0 -41
  177. package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.ts +0 -5
  178. package/typechain-types/factories/@openzeppelin/contracts/utils/math/SafeCast__factory.ts +0 -118
  179. package/typechain-types/factories/@openzeppelin/contracts/utils/math/index.ts +0 -4
  180. package/typechain-types/factories/@openzeppelin/index.ts +0 -4
  181. package/typechain-types/factories/contracts/AgentCard__factory.ts +0 -1480
  182. package/typechain-types/factories/contracts/index.ts +0 -4
  183. package/typechain-types/factories/index.ts +0 -5
  184. package/typechain-types/index.ts +0 -44
  185. package/vitest.config.ts +0 -8
@@ -1,179 +0,0 @@
1
- /**
2
- * Trust Factors Test Suite
3
- *
4
- * Tests 100 simulated agents through the trust scoring system
5
- * to validate tier placement is correct.
6
- */
7
- import { TrustTier, TIER_THRESHOLDS, getTrustTierFromScore, getTierName, calculateTrustScore, } from './trust-factors';
8
- // All 23 factor codes
9
- const ALL_FACTOR_CODES = [
10
- 'CT-COMP', 'CT-REL', 'CT-OBS', 'CT-TRANS', 'CT-ACCT', 'CT-SAFE',
11
- 'CT-SEC', 'CT-PRIV', 'CT-ID', 'OP-HUMAN', 'OP-ALIGN', 'OP-STEW',
12
- 'SF-HUM', 'SF-ADAPT', 'SF-LEARN', 'LC-UNCERT', 'LC-HANDOFF',
13
- 'LC-EMPHUM', 'LC-CAUSAL', 'LC-PATIENT', 'LC-EMP', 'LC-MORAL', 'LC-TRACK'
14
- ];
15
- // Generate agent with scores targeting a specific score range
16
- function generateAgentForScoreRange(agentId, targetTier) {
17
- const tierRange = TIER_THRESHOLDS[targetTier];
18
- // Target the middle of the tier's score range
19
- const targetScore = (tierRange.min + tierRange.max) / 2 / 1000; // Convert to 0-1 scale
20
- // Generate uniform scores around the target
21
- const factorScores = ALL_FACTOR_CODES.map(code => {
22
- // Add some variance but stay near target
23
- const variance = (Math.random() - 0.5) * 0.1;
24
- const score = Math.min(1.0, Math.max(0, targetScore + variance));
25
- return {
26
- code: code,
27
- score,
28
- timestamp: new Date(),
29
- source: 'measured',
30
- confidence: 0.9,
31
- };
32
- });
33
- return {
34
- id: agentId,
35
- targetTier,
36
- factorScores,
37
- expectedScoreRange: tierRange,
38
- };
39
- }
40
- // Generate edge case agent at boundary of tier
41
- function generateBoundaryAgent(agentId, targetTier, position) {
42
- const tierRange = TIER_THRESHOLDS[targetTier];
43
- // Target specific boundary score
44
- const targetScore = position === 'low'
45
- ? (tierRange.min + 10) / 1000 // Just inside lower bound
46
- : (tierRange.max - 10) / 1000; // Just inside upper bound
47
- const factorScores = ALL_FACTOR_CODES.map(code => {
48
- // Very small variance to stay near boundary
49
- const variance = (Math.random() - 0.5) * 0.02;
50
- const score = Math.min(1.0, Math.max(0, targetScore + variance));
51
- return {
52
- code: code,
53
- score,
54
- timestamp: new Date(),
55
- source: 'measured',
56
- confidence: 0.9,
57
- };
58
- });
59
- return {
60
- id: agentId,
61
- targetTier,
62
- factorScores,
63
- expectedScoreRange: tierRange,
64
- };
65
- }
66
- function runTests() {
67
- console.log('='.repeat(80));
68
- console.log('BASIS TRUST FACTORS TEST SUITE');
69
- console.log('Testing 100 agents across all trust tiers');
70
- console.log('='.repeat(80));
71
- console.log('');
72
- // Print tier thresholds
73
- console.log('TIER THRESHOLDS:');
74
- console.log('-'.repeat(50));
75
- Object.entries(TIER_THRESHOLDS).forEach(([tier, range]) => {
76
- const tierNum = parseInt(tier);
77
- console.log(` T${tierNum} ${getTierName(tierNum)}: ${range.min} - ${range.max}`);
78
- });
79
- console.log('');
80
- const results = [];
81
- let agentCounter = 0;
82
- // Generate 100 test agents distributed across tiers
83
- // T0: 12 agents, T1-T6: 13 agents each, T7: 10 agents
84
- const tiersToTest = [
85
- { tier: TrustTier.T0_SANDBOX, count: 12 },
86
- { tier: TrustTier.T1_OBSERVED, count: 13 },
87
- { tier: TrustTier.T2_PROVISIONAL, count: 13 },
88
- { tier: TrustTier.T3_VERIFIED, count: 13 },
89
- { tier: TrustTier.T4_OPERATIONAL, count: 13 },
90
- { tier: TrustTier.T5_TRUSTED, count: 13 },
91
- { tier: TrustTier.T6_CERTIFIED, count: 13 },
92
- { tier: TrustTier.T7_AUTONOMOUS, count: 10 },
93
- ];
94
- for (const { tier, count } of tiersToTest) {
95
- console.log(`\nTesting T${tier} ${getTierName(tier)} (${count} agents):`);
96
- console.log('-'.repeat(60));
97
- for (let i = 0; i < count; i++) {
98
- agentCounter++;
99
- const agentId = `AGENT-${agentCounter.toString().padStart(3, '0')}`;
100
- // Mix of regular and boundary agents
101
- const agent = i < 2
102
- ? generateBoundaryAgent(agentId, tier, i === 0 ? 'low' : 'high')
103
- : generateAgentForScoreRange(agentId, tier);
104
- // Calculate trust score
105
- const evaluation = calculateTrustScore(agent.factorScores, tier);
106
- const actualTier = getTrustTierFromScore(evaluation.totalScore);
107
- const passed = evaluation.totalScore >= agent.expectedScoreRange.min &&
108
- evaluation.totalScore <= agent.expectedScoreRange.max;
109
- const result = {
110
- agentId,
111
- targetTier: `T${tier} ${getTierName(tier)}`,
112
- actualTier: `T${actualTier} ${getTierName(actualTier)}`,
113
- score: evaluation.totalScore,
114
- expectedRange: `${agent.expectedScoreRange.min}-${agent.expectedScoreRange.max}`,
115
- passed,
116
- compliant: evaluation.compliant,
117
- criticalFailures: evaluation.belowThreshold.length,
118
- };
119
- results.push(result);
120
- // Print result
121
- const status = passed ? '✓' : '✗';
122
- const complianceStatus = evaluation.compliant ? 'COMPLIANT' : `FAILED(${evaluation.belowThreshold.length})`;
123
- console.log(` ${status} ${agentId}: Score=${evaluation.totalScore.toString().padStart(4)} ` +
124
- `Target=${result.targetTier.padEnd(15)} Actual=${result.actualTier.padEnd(15)} ` +
125
- `[${complianceStatus}]`);
126
- }
127
- }
128
- // Summary
129
- console.log('\n' + '='.repeat(80));
130
- console.log('TEST SUMMARY');
131
- console.log('='.repeat(80));
132
- const passed = results.filter(r => r.passed).length;
133
- const failed = results.filter(r => !r.passed).length;
134
- const compliant = results.filter(r => r.compliant).length;
135
- console.log(`\nTotal Agents Tested: ${results.length}`);
136
- console.log(`Passed (in expected range): ${passed} (${((passed / results.length) * 100).toFixed(1)}%)`);
137
- console.log(`Failed (outside range): ${failed} (${((failed / results.length) * 100).toFixed(1)}%)`);
138
- console.log(`Compliant (met all critical factors): ${compliant} (${((compliant / results.length) * 100).toFixed(1)}%)`);
139
- // Distribution by tier
140
- console.log('\nDISTRIBUTION BY ACTUAL TIER:');
141
- console.log('-'.repeat(40));
142
- for (let t = 0; t <= 7; t++) {
143
- const inTier = results.filter(r => r.actualTier.startsWith(`T${t}`)).length;
144
- const bar = '█'.repeat(Math.round(inTier / 2));
145
- console.log(` T${t} ${getTierName(t).padEnd(12)}: ${inTier.toString().padStart(3)} ${bar}`);
146
- }
147
- // Score distribution
148
- console.log('\nSCORE DISTRIBUTION:');
149
- console.log('-'.repeat(40));
150
- const scoreRanges = [
151
- { label: '0-199', min: 0, max: 199 },
152
- { label: '200-349', min: 200, max: 349 },
153
- { label: '350-499', min: 350, max: 499 },
154
- { label: '500-649', min: 500, max: 649 },
155
- { label: '650-799', min: 650, max: 799 },
156
- { label: '800-875', min: 800, max: 875 },
157
- { label: '876-949', min: 876, max: 949 },
158
- { label: '950-1000', min: 950, max: 1000 },
159
- ];
160
- for (const range of scoreRanges) {
161
- const count = results.filter(r => r.score >= range.min && r.score <= range.max).length;
162
- const bar = '█'.repeat(Math.round(count / 2));
163
- console.log(` ${range.label.padEnd(10)}: ${count.toString().padStart(3)} ${bar}`);
164
- }
165
- // Failed agents detail
166
- if (failed > 0) {
167
- console.log('\nFAILED AGENTS:');
168
- console.log('-'.repeat(60));
169
- results.filter(r => !r.passed).forEach(r => {
170
- console.log(` ${r.agentId}: Score=${r.score} Expected=${r.expectedRange} Got=${r.actualTier}`);
171
- });
172
- }
173
- console.log('\n' + '='.repeat(80));
174
- console.log(failed === 0 ? 'ALL TESTS PASSED!' : `${failed} TESTS FAILED`);
175
- console.log('='.repeat(80));
176
- }
177
- // Run tests
178
- runTests();
179
- //# sourceMappingURL=trust-factors.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation-gate.test.d.ts","sourceRoot":"","sources":["../src/validation-gate.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -1,419 +0,0 @@
1
- /**
2
- * Tests for BASIS Validation Gate
3
- */
4
- import { describe, it, expect } from 'vitest';
5
- import { validateAgent, isValidAgent, createValidationGate, strictValidationGate, productionValidationGate, GateDecision, ValidationSeverity, scoreToTier, } from './validation-gate';
6
- import { TrustTier } from './trust-factors';
7
- describe('ValidationGate', () => {
8
- // =============================================================================
9
- // BASIC VALIDATION TESTS
10
- // =============================================================================
11
- describe('validateAgent', () => {
12
- it('should PASS a valid manifest', () => {
13
- const manifest = {
14
- agentId: 'a3i.acme-corp.invoice-bot:ABF-L3@1.0.0',
15
- organization: 'acme-corp',
16
- agentClass: 'invoice-bot',
17
- domains: ['A', 'B', 'F'],
18
- capabilityLevel: 3,
19
- version: '1.0.0',
20
- trustScore: 450,
21
- };
22
- const result = validateAgent(manifest);
23
- expect(result.decision).toBe(GateDecision.PASS);
24
- expect(result.valid).toBe(true);
25
- expect(result.errors).toHaveLength(0);
26
- });
27
- it('should REJECT manifest missing required agentId', () => {
28
- const manifest = {
29
- organization: 'acme-corp',
30
- trustScore: 450,
31
- };
32
- const result = validateAgent(manifest);
33
- expect(result.decision).toBe(GateDecision.REJECT);
34
- expect(result.valid).toBe(false);
35
- expect(result.errors.length).toBeGreaterThan(0);
36
- });
37
- it('should include timing information', () => {
38
- const manifest = {
39
- agentId: 'test-agent',
40
- trustScore: 500,
41
- };
42
- const result = validateAgent(manifest);
43
- expect(result.validatedAt).toBeInstanceOf(Date);
44
- expect(result.durationMs).toBeGreaterThanOrEqual(0);
45
- });
46
- it('should detect invalid CAR format', () => {
47
- const manifest = {
48
- agentId: 'invalid-format:missing-parts@1.0.0',
49
- trustScore: 500,
50
- };
51
- const result = validateAgent(manifest);
52
- const formatIssue = result.issues.find((i) => i.code === 'INVALID_CAR_FORMAT');
53
- expect(formatIssue).toBeDefined();
54
- });
55
- it('should accept simple ID format with info note', () => {
56
- const manifest = {
57
- agentId: 'simple-agent-id',
58
- trustScore: 500,
59
- };
60
- const result = validateAgent(manifest);
61
- expect(result.valid).toBe(true);
62
- const infoIssue = result.issues.find((i) => i.code === 'SIMPLE_ID_FORMAT');
63
- expect(infoIssue).toBeDefined();
64
- expect(infoIssue?.severity).toBe(ValidationSeverity.INFO);
65
- });
66
- });
67
- // =============================================================================
68
- // TRUST TIER VALIDATION
69
- // =============================================================================
70
- describe('trust tier validation', () => {
71
- it('should calculate trust tier from score', () => {
72
- // T0: 0-199
73
- expect(scoreToTier(0)).toBe(TrustTier.T0_SANDBOX);
74
- expect(scoreToTier(199)).toBe(TrustTier.T0_SANDBOX);
75
- // T1: 200-349
76
- expect(scoreToTier(200)).toBe(TrustTier.T1_OBSERVED);
77
- expect(scoreToTier(349)).toBe(TrustTier.T1_OBSERVED);
78
- // T2: 350-500
79
- expect(scoreToTier(350)).toBe(TrustTier.T2_PROVISIONAL);
80
- expect(scoreToTier(500)).toBe(TrustTier.T2_PROVISIONAL);
81
- // T3: 501-649
82
- expect(scoreToTier(501)).toBe(TrustTier.T3_MONITORED);
83
- expect(scoreToTier(649)).toBe(TrustTier.T3_MONITORED);
84
- // T4: 650-799
85
- expect(scoreToTier(650)).toBe(TrustTier.T4_STANDARD);
86
- expect(scoreToTier(799)).toBe(TrustTier.T4_STANDARD);
87
- // T5: 800-875
88
- expect(scoreToTier(800)).toBe(TrustTier.T5_TRUSTED);
89
- expect(scoreToTier(875)).toBe(TrustTier.T5_TRUSTED);
90
- // T6: 876-950
91
- expect(scoreToTier(876)).toBe(TrustTier.T6_CERTIFIED);
92
- expect(scoreToTier(950)).toBe(TrustTier.T6_CERTIFIED);
93
- // T7: 951-1000
94
- expect(scoreToTier(951)).toBe(TrustTier.T7_AUTONOMOUS);
95
- expect(scoreToTier(1000)).toBe(TrustTier.T7_AUTONOMOUS);
96
- });
97
- it('should REJECT when trust tier is below minimum', () => {
98
- const manifest = {
99
- agentId: 'test-agent',
100
- trustScore: 100, // T0
101
- };
102
- const result = validateAgent(manifest, undefined, {
103
- minimumTrustTier: TrustTier.T3_MONITORED,
104
- });
105
- expect(result.decision).toBe(GateDecision.REJECT);
106
- expect(result.errors.some((e) => e.code === 'INSUFFICIENT_TRUST_TIER')).toBe(true);
107
- });
108
- it('should PASS when trust tier meets minimum', () => {
109
- const manifest = {
110
- agentId: 'test-agent',
111
- trustScore: 700, // T4 (650-799)
112
- };
113
- const result = validateAgent(manifest, undefined, {
114
- minimumTrustTier: TrustTier.T3_MONITORED,
115
- });
116
- expect(result.decision).toBe(GateDecision.PASS);
117
- expect(result.trustTier).toBe(TrustTier.T4_STANDARD);
118
- });
119
- it('should warn when trust score is missing', () => {
120
- const manifest = {
121
- agentId: 'test-agent',
122
- };
123
- const result = validateAgent(manifest);
124
- expect(result.warnings.some((w) => w.code === 'MISSING_TRUST_SCORE')).toBe(true);
125
- });
126
- });
127
- // =============================================================================
128
- // PROFILE VALIDATION
129
- // =============================================================================
130
- describe('profile validation', () => {
131
- const validProfile = {
132
- agentId: 'a3i.acme-corp.invoice-bot:ABF-L3@1.0.0',
133
- organization: 'acme-corp',
134
- agentClass: 'invoice-bot',
135
- approvedDomains: ['A', 'B', 'F'],
136
- maxCapabilityLevel: 4,
137
- approvedCapabilities: ['CAP-READ-PUBLIC', 'CAP-DB-READ', 'CAP-WRITE-APPROVED'],
138
- trustScore: 500,
139
- registeredAt: new Date('2024-01-01'),
140
- };
141
- it('should PASS when manifest matches profile', () => {
142
- const manifest = {
143
- agentId: 'a3i.acme-corp.invoice-bot:ABF-L3@1.0.0',
144
- organization: 'acme-corp',
145
- agentClass: 'invoice-bot',
146
- domains: ['A', 'B'],
147
- capabilityLevel: 3,
148
- trustScore: 500,
149
- };
150
- const result = validateAgent(manifest, validProfile);
151
- expect(result.decision).toBe(GateDecision.PASS);
152
- expect(result.valid).toBe(true);
153
- });
154
- it('should REJECT when organization mismatches', () => {
155
- const manifest = {
156
- agentId: 'test-agent',
157
- organization: 'evil-corp',
158
- trustScore: 500,
159
- };
160
- const result = validateAgent(manifest, validProfile);
161
- expect(result.decision).toBe(GateDecision.REJECT);
162
- expect(result.errors.some((e) => e.code === 'ORG_MISMATCH')).toBe(true);
163
- });
164
- it('should REJECT when capability level exceeds maximum', () => {
165
- const manifest = {
166
- agentId: 'test-agent',
167
- organization: 'acme-corp',
168
- capabilityLevel: 7, // exceeds profile max of 4
169
- trustScore: 500,
170
- };
171
- const result = validateAgent(manifest, validProfile);
172
- expect(result.decision).toBe(GateDecision.REJECT);
173
- expect(result.errors.some((e) => e.code === 'CAPABILITY_LEVEL_EXCEEDED')).toBe(true);
174
- });
175
- it('should REJECT unauthorized domains', () => {
176
- const manifest = {
177
- agentId: 'test-agent',
178
- organization: 'acme-corp',
179
- domains: ['A', 'B', 'S'], // S not approved
180
- trustScore: 500,
181
- };
182
- const result = validateAgent(manifest, validProfile);
183
- expect(result.decision).toBe(GateDecision.REJECT);
184
- expect(result.errors.some((e) => e.code === 'UNAUTHORIZED_DOMAINS')).toBe(true);
185
- });
186
- it('should warn on unauthorized capabilities', () => {
187
- const manifest = {
188
- agentId: 'test-agent',
189
- organization: 'acme-corp',
190
- requestedCapabilities: ['CAP-READ-PUBLIC', 'CAP-SYSTEM-ADMIN-FULL'], // admin not approved
191
- trustScore: 500,
192
- };
193
- const result = validateAgent(manifest, validProfile);
194
- expect(result.warnings.some((w) => w.code === 'UNAUTHORIZED_CAPABILITIES')).toBe(true);
195
- });
196
- it('should REJECT when profile required but missing', () => {
197
- const manifest = {
198
- agentId: 'test-agent',
199
- trustScore: 500,
200
- };
201
- const result = validateAgent(manifest, undefined, {
202
- requireRegisteredProfile: true,
203
- });
204
- expect(result.decision).toBe(GateDecision.REJECT);
205
- expect(result.errors.some((e) => e.code === 'PROFILE_NOT_FOUND')).toBe(true);
206
- });
207
- });
208
- // =============================================================================
209
- // CAPABILITY VALIDATION
210
- // =============================================================================
211
- describe('capability validation', () => {
212
- it('should allow capabilities matching trust tier', () => {
213
- const manifest = {
214
- agentId: 'test-agent',
215
- trustScore: 700, // T4_STANDARD (650-799)
216
- requestedCapabilities: ['CAP-READ-PUBLIC', 'CAP-AGENT-COMMUNICATE'],
217
- };
218
- const result = validateAgent(manifest);
219
- expect(result.allowedCapabilities).toContain('CAP-READ-PUBLIC');
220
- expect(result.allowedCapabilities).toContain('CAP-AGENT-COMMUNICATE');
221
- expect(result.deniedCapabilities).toBeUndefined();
222
- });
223
- it('should deny capabilities above trust tier', () => {
224
- const manifest = {
225
- agentId: 'test-agent',
226
- trustScore: 100, // T0_SANDBOX
227
- requestedCapabilities: ['CAP-READ-PUBLIC', 'CAP-AGENT-SPAWN'], // spawn requires T6
228
- };
229
- const result = validateAgent(manifest);
230
- expect(result.allowedCapabilities).toContain('CAP-READ-PUBLIC');
231
- expect(result.deniedCapabilities).toContain('CAP-AGENT-SPAWN');
232
- });
233
- it('should provide recommendations for denied capabilities', () => {
234
- const manifest = {
235
- agentId: 'test-agent',
236
- trustScore: 100,
237
- requestedCapabilities: ['CAP-AGENT-SPAWN'],
238
- };
239
- const result = validateAgent(manifest);
240
- expect(result.recommendations).toBeDefined();
241
- expect(result.recommendations?.some((r) => r.includes('trust score'))).toBe(true);
242
- });
243
- });
244
- // =============================================================================
245
- // REQUIRED DOMAINS
246
- // =============================================================================
247
- describe('required domains', () => {
248
- it('should REJECT when required domains are missing', () => {
249
- const manifest = {
250
- agentId: 'test-agent',
251
- domains: ['A', 'B'],
252
- trustScore: 500,
253
- };
254
- const result = validateAgent(manifest, undefined, {
255
- requiredDomains: ['A', 'F'], // F is missing
256
- });
257
- expect(result.decision).toBe(GateDecision.REJECT);
258
- expect(result.errors.some((e) => e.code === 'MISSING_REQUIRED_DOMAINS')).toBe(true);
259
- });
260
- it('should PASS when all required domains present', () => {
261
- const manifest = {
262
- agentId: 'test-agent',
263
- domains: ['A', 'B', 'F'],
264
- trustScore: 500,
265
- };
266
- const result = validateAgent(manifest, undefined, {
267
- requiredDomains: ['A', 'F'],
268
- });
269
- expect(result.decision).toBe(GateDecision.PASS);
270
- });
271
- });
272
- // =============================================================================
273
- // STRICT MODE
274
- // =============================================================================
275
- describe('strict mode', () => {
276
- it('should REJECT on warnings in strict mode', () => {
277
- const manifest = {
278
- agentId: 'test-agent',
279
- // No trust score - generates warning
280
- };
281
- const normalResult = validateAgent(manifest, undefined, { strict: false });
282
- const strictResult = validateAgent(manifest, undefined, { strict: true });
283
- expect(normalResult.decision).toBe(GateDecision.PASS);
284
- expect(strictResult.decision).toBe(GateDecision.REJECT);
285
- });
286
- });
287
- // =============================================================================
288
- // CUSTOM VALIDATORS
289
- // =============================================================================
290
- describe('custom validators', () => {
291
- it('should run custom validators', () => {
292
- const manifest = {
293
- agentId: 'test-agent',
294
- trustScore: 500,
295
- metadata: { version: '0.0.1' },
296
- };
297
- const customValidator = (m) => {
298
- const issues = [];
299
- if (m.metadata?.version === '0.0.1') {
300
- issues.push({
301
- code: 'UNSTABLE_VERSION',
302
- message: 'Agent is using unstable version',
303
- severity: ValidationSeverity.WARNING,
304
- });
305
- }
306
- return issues;
307
- };
308
- const result = validateAgent(manifest, undefined, {
309
- customValidators: [customValidator],
310
- });
311
- expect(result.warnings.some((w) => w.code === 'UNSTABLE_VERSION')).toBe(true);
312
- });
313
- it('should handle custom validator errors gracefully', () => {
314
- const manifest = {
315
- agentId: 'test-agent',
316
- trustScore: 500,
317
- };
318
- const failingValidator = () => {
319
- throw new Error('Validator crashed');
320
- };
321
- const result = validateAgent(manifest, undefined, {
322
- customValidators: [failingValidator],
323
- });
324
- // Should not crash, just add a warning
325
- expect(result.warnings.some((w) => w.code === 'CUSTOM_VALIDATOR_ERROR')).toBe(true);
326
- });
327
- });
328
- // =============================================================================
329
- // HELPER FUNCTIONS
330
- // =============================================================================
331
- describe('isValidAgent', () => {
332
- it('should return true for valid agent', () => {
333
- const manifest = {
334
- agentId: 'test-agent',
335
- trustScore: 500,
336
- };
337
- expect(isValidAgent(manifest)).toBe(true);
338
- });
339
- it('should return false for invalid agent', () => {
340
- const manifest = {};
341
- expect(isValidAgent(manifest)).toBe(false);
342
- });
343
- });
344
- describe('createValidationGate', () => {
345
- it('should create gate with preset options', () => {
346
- const gate = createValidationGate({
347
- minimumTrustTier: TrustTier.T3_MONITORED,
348
- });
349
- const lowTrustManifest = {
350
- agentId: 'test-agent',
351
- trustScore: 100,
352
- };
353
- const result = gate.validate(lowTrustManifest);
354
- expect(result.decision).toBe(GateDecision.REJECT);
355
- });
356
- it('should allow option overrides', () => {
357
- const gate = createValidationGate({
358
- minimumTrustTier: TrustTier.T5_TRUSTED,
359
- });
360
- const manifest = {
361
- agentId: 'test-agent',
362
- trustScore: 700, // T4 (650-799)
363
- };
364
- // With default options, should fail (T4 < T5)
365
- const result1 = gate.validate(manifest);
366
- expect(result1.decision).toBe(GateDecision.REJECT);
367
- // With override, should pass (T4 >= T3)
368
- const result2 = gate.validate(manifest, undefined, {
369
- minimumTrustTier: TrustTier.T3_MONITORED,
370
- });
371
- expect(result2.decision).toBe(GateDecision.PASS);
372
- });
373
- });
374
- describe('preset gates', () => {
375
- it('strictValidationGate should reject on warnings', () => {
376
- const manifest = {
377
- agentId: 'test-agent',
378
- // Missing trustScore generates warning
379
- };
380
- expect(strictValidationGate.isValid(manifest)).toBe(false);
381
- });
382
- it('productionValidationGate should require profile', () => {
383
- const manifest = {
384
- agentId: 'test-agent',
385
- trustScore: 500,
386
- };
387
- const result = productionValidationGate.validate(manifest);
388
- expect(result.errors.some((e) => e.code === 'PROFILE_NOT_FOUND')).toBe(true);
389
- });
390
- });
391
- // =============================================================================
392
- // ESCALATION
393
- // =============================================================================
394
- describe('escalation', () => {
395
- it('should ESCALATE when capability escalation allowed and denied caps exist', () => {
396
- const manifest = {
397
- agentId: 'test-agent',
398
- trustScore: 100, // T0
399
- requestedCapabilities: ['CAP-AGENT-SPAWN'], // Requires T6
400
- };
401
- const result = validateAgent(manifest, undefined, {
402
- allowCapabilityEscalation: true,
403
- });
404
- expect(result.decision).toBe(GateDecision.ESCALATE);
405
- });
406
- it('should REJECT when capability escalation not allowed', () => {
407
- const manifest = {
408
- agentId: 'test-agent',
409
- trustScore: 100,
410
- requestedCapabilities: ['CAP-AGENT-SPAWN'],
411
- };
412
- const result = validateAgent(manifest, undefined, {
413
- allowCapabilityEscalation: false,
414
- });
415
- expect(result.decision).toBe(GateDecision.REJECT);
416
- });
417
- });
418
- });
419
- //# sourceMappingURL=validation-gate.test.js.map
package/hardhat.config.ts DELETED
@@ -1,55 +0,0 @@
1
- import { HardhatUserConfig } from 'hardhat/config';
2
- import '@nomicfoundation/hardhat-ethers';
3
- import * as dotenv from 'dotenv';
4
-
5
- dotenv.config();
6
-
7
- const config: HardhatUserConfig = {
8
- solidity: {
9
- version: '0.8.20',
10
- settings: {
11
- optimizer: {
12
- enabled: true,
13
- runs: 200,
14
- },
15
- },
16
- },
17
-
18
- networks: {
19
- hardhat: {
20
- chainId: 31337,
21
- },
22
-
23
- // Ethereum Sepolia Testnet (uses ETH)
24
- sepolia: {
25
- url: process.env.SEPOLIA_RPC_URL || 'https://ethereum-sepolia-rpc.publicnode.com',
26
- accounts: process.env.PRIVATE_KEY && process.env.PRIVATE_KEY.startsWith('0x') && process.env.PRIVATE_KEY.length === 66 ? [process.env.PRIVATE_KEY] : [],
27
- chainId: 11155111,
28
- },
29
-
30
- // Polygon Amoy Testnet
31
- amoy: {
32
- url: process.env.AMOY_RPC_URL || 'https://rpc-amoy.polygon.technology',
33
- accounts: process.env.PRIVATE_KEY && process.env.PRIVATE_KEY.startsWith('0x') && process.env.PRIVATE_KEY.length === 66 ? [process.env.PRIVATE_KEY] : [],
34
- chainId: 80002,
35
- gasPrice: 30000000000, // 30 gwei
36
- },
37
-
38
- // Polygon Mainnet (uses POL token)
39
- polygon: {
40
- url: process.env.POLYGON_RPC_URL || 'https://polygon-rpc.com',
41
- accounts: process.env.PRIVATE_KEY && process.env.PRIVATE_KEY.startsWith('0x') && process.env.PRIVATE_KEY.length === 66 ? [process.env.PRIVATE_KEY] : [],
42
- chainId: 137,
43
- gasPrice: 50000000000, // 50 gwei
44
- },
45
- },
46
-
47
- paths: {
48
- sources: './contracts',
49
- tests: './test',
50
- cache: './cache',
51
- artifacts: './artifacts',
52
- },
53
- };
54
-
55
- export default config;