kya-validator 0.2.3

Rust core KYA (Know Your Agent) validator with Python bindings, TEE support, and blockchain integration
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/**
 * Recipient API Documentation View - Displays API documentation for the recipient agent.
 */
import { useState } from 'react';

interface ApiEndpoint {
  method: string;
  path: string;
  description: string;
  requestBody?: {
    type: string;
    properties: Record<string, { type: string; description: string }>;
    example: Record<string, unknown>;
  };
  response?: {
    type: string;
    properties: Record<string, { type: string; description: string }>;
    example: Record<string, unknown>;
  };
}

const API_ENDPOINTS: ApiEndpoint[] = [
  {
    method: 'POST',
    path: '/api/v1/recipient/submit',
    description: 'Submit a KYA manifest for validation by the recipient agent.',
    requestBody: {
      type: 'object',
      properties: {
        manifest_data: {
          type: 'object',
          description: 'The KYA manifest data to validate',
        },
        validation_type: {
          type: 'string',
          description: 'Type of validation (manifest, policy, etc.)',
        },
        message_id: {
          type: 'string',
          description: 'Unique identifier for the message',
        },
        timestamp: {
          type: 'string',
          description: 'ISO 8601 timestamp',
        },
      },
      example: {
        message_id: 'msg-1234567890',
        timestamp: '2024-01-15T10:30:00Z',
        message_type: 'validation_request',
        manifest_data: {
          id: 'manifest-001',
          name: 'GPU Inference Service',
          version: '1.0.0',
          provider: 'demo_provider',
          services: ['gpu_inference', 'data_pipeline'],
          mcp_evidence: {
            attestation: 'base64encoded...',
            certificates: ['cert1.pem'],
          },
          tee_evidence: {
            quote: 'base64encoded...',
            measurement: '0x1234...',
          },
          blockchain_evidence: {
            transaction_hash: '0xabcd...',
            block_number: 12345678,
          },
        },
        validation_type: 'manifest',
      },
    },
    response: {
      type: 'object',
      properties: {
        validation_status: {
          type: 'string',
          description: 'Status of validation (valid, invalid, pending)',
        },
        mcp_validated: {
          type: 'boolean',
          description: 'Whether MCP validation passed',
        },
        tee_validated: {
          type: 'boolean',
          description: 'Whether TEE validation passed',
        },
        blockchain_validated: {
          type: 'boolean',
          description: 'Whether blockchain validation passed',
        },
        validation_errors: {
          type: 'array',
          description: 'List of validation errors if any',
        },
      },
      example: {
        manifest_id: 'manifest-001',
        validation_status: 'valid',
        mcp_validated: true,
        tee_validated: true,
        blockchain_validated: true,
        validation_errors: [],
      },
    },
  },
  {
    method: 'GET',
    path: '/api/v1/recipient/status/{request_id}',
    description: 'Check the validation status of a previously submitted request.',
    response: {
      type: 'object',
      properties: {
        request_id: {
          type: 'string',
          description: 'The request identifier',
        },
        status: {
          type: 'string',
          description: 'Current status (pending, completed, failed)',
        },
        result: {
          type: 'object',
          description: 'Validation result if completed',
        },
        created_at: {
          type: 'string',
          description: 'Request creation timestamp',
        },
        updated_at: {
          type: 'string',
          description: 'Last update timestamp',
        },
      },
      example: {
        request_id: 'req-1234567890',
        status: 'completed',
        result: {
          validation_status: 'valid',
          mcp_validated: true,
          tee_validated: true,
          blockchain_validated: true,
        },
        created_at: '2024-01-15T10:30:00Z',
        updated_at: '2024-01-15T10:30:05Z',
      },
    },
  },
  {
    method: 'GET',
    path: '/api/v1/recipient/policy',
    description: 'Get the current policy requirements that manifests must satisfy.',
    response: {
      type: 'object',
      properties: {
        policy_id: {
          type: 'string',
          description: 'Policy identifier',
        },
        policy_version: {
          type: 'string',
          description: 'Policy version',
        },
        requirements: {
          type: 'array',
          description: 'List of policy requirements',
        },
        constraints: {
          type: 'object',
          description: 'Policy constraints',
        },
      },
      example: {
        policy_id: 'policy-001',
        policy_version: '1.2.0',
        requirements: [
          {
            type: 'mcp_attestation',
            level: 'strict',
            description: 'MCP attestation required for all services',
          },
          {
            type: 'tee_evidence',
            level: 'required',
            description: 'TEE evidence required for compute services',
          },
          {
            type: 'blockchain_proof',
            level: 'optional',
            description: 'Blockchain proof optional but recommended',
          },
        ],
        constraints: {
          max_manifest_size: '10MB',
          allowed_providers: ['demo_provider', 'trusted_provider'],
          required_fields: ['id', 'name', 'version', 'provider'],
        },
      },
    },
  },
  {
    method: 'POST',
    path: '/api/v1/recipient/negotiate',
    description: 'Submit a negotiation offer to the recipient agent.',
    requestBody: {
      type: 'object',
      properties: {
        offer_id: {
          type: 'string',
          description: 'Unique identifier for the offer',
        },
        terms: {
          type: 'object',
          description: 'Negotiation terms (price, duration, etc.)',
        },
        constraints: {
          type: 'array',
          description: 'Constraints on the negotiation',
        },
      },
      example: {
        offer_id: 'offer-1234567890',
        terms: {
          price: 5000,
          currency: 'USD',
          duration: '12 months',
          sla: '99.9%',
        },
        constraints: ['max_budget:6000', 'min_sla:99.5%'],
      },
    },
    response: {
      type: 'object',
      properties: {
        response_type: {
          type: 'string',
          description: 'Response type (accept, reject, counter)',
        },
        counter_terms: {
          type: 'object',
          description: 'Counter offer terms if response_type is counter',
        },
        reasoning: {
          type: 'string',
          description: 'Reasoning for the response',
        },
      },
      example: {
        response_type: 'counter',
        counter_terms: {
          price: 4750,
          currency: 'USD',
          duration: '12 months',
          sla: '99.9%',
        },
        reasoning: 'We can offer a 5% discount for annual commitment.',
      },
    },
  },
];

const METHOD_COLORS: Record<string, string> = {
  GET: 'bg-green-600',
  POST: 'bg-blue-600',
  PUT: 'bg-yellow-600',
  DELETE: 'bg-red-600',
};

export default function RecipientApiView() {
  const [selectedEndpoint, setSelectedEndpoint] = useState<number>(0);
  const [activeTab, setActiveTab] = useState<'request' | 'response'>('request');

  const endpoint = API_ENDPOINTS[selectedEndpoint];

  return (
    <div className="bg-slate-900/50 rounded-xl border border-slate-700 overflow-hidden">
      {/* Header */}
      <div className="bg-slate-800/80 px-4 py-3 border-b border-slate-700">
        <h3 className="text-sm font-semibold text-slate-200 flex items-center gap-2">
          <svg className="w-4 h-4 text-cyan-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
          </svg>
          Recipient Agent API Documentation
        </h3>
      </div>

      {/* Endpoint List */}
      <div className="divide-y divide-slate-700">
        {API_ENDPOINTS.map((ep, index) => (
          <button
            key={index}
            onClick={() => setSelectedEndpoint(index)}
            className={`w-full text-left px-4 py-3 hover:bg-slate-700/50 transition-colors ${
              selectedEndpoint === index ? 'bg-slate-700/50' : ''
            }`}
          >
            <div className="flex items-center gap-3">
              <span
                className={`px-2 py-1 rounded text-xs font-bold text-white ${METHOD_COLORS[ep.method] || 'bg-gray-600'}`}
              >
                {ep.method}
              </span>
              <code className="text-sm text-slate-300 font-mono">{ep.path}</code>
            </div>
            <p className="mt-1 text-xs text-slate-400 ml-14">{ep.description}</p>
          </button>
        ))}
      </div>

      {/* Endpoint Details */}
      <div className="border-t border-slate-700 bg-slate-800/30">
        <div className="px-4 py-3 border-b border-slate-700">
          <div className="flex items-center gap-2 mb-2">
            <span
              className={`px-2 py-1 rounded text-xs font-bold text-white ${METHOD_COLORS[endpoint.method] || 'bg-gray-600'}`}
            >
              {endpoint.method}
            </span>
            <code className="text-sm text-slate-200 font-mono">{endpoint.path}</code>
          </div>
          <p className="text-sm text-slate-400">{endpoint.description}</p>
        </div>

        {/* Tabs */}
        <div className="flex border-b border-slate-700">
          {endpoint.requestBody && (
            <button
              onClick={() => setActiveTab('request')}
              className={`px-4 py-2 text-sm font-medium transition-colors ${
                activeTab === 'request'
                  ? 'text-cyan-400 border-b-2 border-cyan-400'
                  : 'text-slate-400 hover:text-slate-300'
              }`}
            >
              Request
            </button>
          )}
          {endpoint.response && (
            <button
              onClick={() => setActiveTab('response')}
              className={`px-4 py-2 text-sm font-medium transition-colors ${
                activeTab === 'response'
                  ? 'text-cyan-400 border-b-2 border-cyan-400'
                  : 'text-slate-400 hover:text-slate-300'
              }`}
            >
              Response
            </button>
          )}
        </div>

        {/* Tab Content */}
        <div className="p-4">
          {activeTab === 'request' && endpoint.requestBody && (
            <div className="space-y-4">
              {/* Schema */}
              <div>
                <h4 className="text-xs font-semibold text-slate-400 uppercase mb-2">Request Schema</h4>
                <div className="bg-slate-900 rounded-lg p-3 text-xs font-mono text-slate-300">
                  <div className="text-purple-400">{'{'}</div>
                  {Object.entries(endpoint.requestBody.properties).map(([key, prop]) => (
                    <div key={key} className="ml-4">
                      <span className="text-cyan-400">"{key}"</span>
                      <span className="text-slate-500">: </span>
                      <span className="text-green-400">{prop.type}</span>
                      <span className="text-slate-500">, // {prop.description}</span>
                    </div>
                  ))}
                  <div className="text-purple-400">{'}'}</div>
                </div>
              </div>

              {/* Example */}
              <div>
                <h4 className="text-xs font-semibold text-slate-400 uppercase mb-2">Example Payload</h4>
                <pre className="bg-slate-900 rounded-lg p-3 text-xs font-mono text-slate-300 overflow-x-auto">
                  {JSON.stringify(endpoint.requestBody.example, null, 2)}
                </pre>
              </div>
            </div>
          )}

          {activeTab === 'response' && endpoint.response && (
            <div className="space-y-4">
              {/* Schema */}
              <div>
                <h4 className="text-xs font-semibold text-slate-400 uppercase mb-2">Response Schema</h4>
                <div className="bg-slate-900 rounded-lg p-3 text-xs font-mono text-slate-300">
                  <div className="text-purple-400">{'{'}</div>
                  {Object.entries(endpoint.response.properties).map(([key, prop]) => (
                    <div key={key} className="ml-4">
                      <span className="text-cyan-400">"{key}"</span>
                      <span className="text-slate-500">: </span>
                      <span className="text-green-400">{prop.type}</span>
                      <span className="text-slate-500">, // {prop.description}</span>
                    </div>
                  ))}
                  <div className="text-purple-400">{'}'}</div>
                </div>
              </div>

              {/* Example */}
              <div>
                <h4 className="text-xs font-semibold text-slate-400 uppercase mb-2">Example Response</h4>
                <pre className="bg-slate-900 rounded-lg p-3 text-xs font-mono text-slate-300 overflow-x-auto">
                  {JSON.stringify(endpoint.response.example, null, 2)}
                </pre>
              </div>
            </div>
          )}
        </div>
      </div>

      {/* Footer Info */}
      <div className="px-4 py-3 bg-slate-800/80 border-t border-slate-700">
        <div className="flex items-center justify-between text-xs text-slate-400">
          <div className="flex items-center gap-4">
            <span className="flex items-center gap-1">
              <svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
              </svg>
              No authentication required
            </span>
            <span className="flex items-center gap-1">
              <svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 10V3L4 14h7v7l9-11h-7z" />
              </svg>
              Rate limit: 100 requests/minute
            </span>
          </div>
          <span>Base URL: /api/v1/recipient</span>
        </div>
      </div>
    </div>
  );
}