@kya-os/mcp-i-core 1.2.3-canary.7 → 1.3.0
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/.claude/settings.local.json +9 -0
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test$colon$coverage.log +4514 -0
- package/.turbo/turbo-test.log +2973 -0
- package/COMPLIANCE_IMPROVEMENT_REPORT.md +483 -0
- package/Composer 3.md +615 -0
- package/GPT-5.md +1169 -0
- package/OPUS-plan.md +352 -0
- package/PHASE_3_AND_4.1_SUMMARY.md +585 -0
- package/PHASE_3_SUMMARY.md +317 -0
- package/PHASE_4.1.3_SUMMARY.md +428 -0
- package/PHASE_4.1_COMPLETE.md +525 -0
- package/PHASE_4_USER_DID_IDENTITY_LINKING_PLAN.md +1240 -0
- package/SCHEMA_COMPLIANCE_REPORT.md +275 -0
- package/TEST_PLAN.md +571 -0
- package/coverage/coverage-final.json +57 -0
- package/dist/__tests__/utils/mock-providers.d.ts +1 -2
- package/dist/__tests__/utils/mock-providers.d.ts.map +1 -1
- package/dist/__tests__/utils/mock-providers.js.map +1 -1
- package/dist/cache/oauth-config-cache.d.ts +69 -0
- package/dist/cache/oauth-config-cache.d.ts.map +1 -0
- package/dist/cache/oauth-config-cache.js +76 -0
- package/dist/cache/oauth-config-cache.js.map +1 -0
- package/dist/identity/idp-token-resolver.d.ts +53 -0
- package/dist/identity/idp-token-resolver.d.ts.map +1 -0
- package/dist/identity/idp-token-resolver.js +108 -0
- package/dist/identity/idp-token-resolver.js.map +1 -0
- package/dist/identity/idp-token-storage.interface.d.ts +42 -0
- package/dist/identity/idp-token-storage.interface.d.ts.map +1 -0
- package/dist/identity/idp-token-storage.interface.js +12 -0
- package/dist/identity/idp-token-storage.interface.js.map +1 -0
- package/dist/identity/user-did-manager.d.ts +39 -1
- package/dist/identity/user-did-manager.d.ts.map +1 -1
- package/dist/identity/user-did-manager.js +69 -3
- package/dist/identity/user-did-manager.js.map +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime/audit-logger.d.ts +37 -0
- package/dist/runtime/audit-logger.d.ts.map +1 -0
- package/dist/runtime/audit-logger.js +9 -0
- package/dist/runtime/audit-logger.js.map +1 -0
- package/dist/runtime/base.d.ts +58 -2
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +266 -11
- package/dist/runtime/base.js.map +1 -1
- package/dist/services/access-control.service.d.ts.map +1 -1
- package/dist/services/access-control.service.js +200 -35
- package/dist/services/access-control.service.js.map +1 -1
- package/dist/services/authorization/authorization-registry.d.ts +29 -0
- package/dist/services/authorization/authorization-registry.d.ts.map +1 -0
- package/dist/services/authorization/authorization-registry.js +57 -0
- package/dist/services/authorization/authorization-registry.js.map +1 -0
- package/dist/services/authorization/types.d.ts +53 -0
- package/dist/services/authorization/types.d.ts.map +1 -0
- package/dist/services/authorization/types.js +10 -0
- package/dist/services/authorization/types.js.map +1 -0
- package/dist/services/batch-delegation.service.d.ts +53 -0
- package/dist/services/batch-delegation.service.d.ts.map +1 -0
- package/dist/services/batch-delegation.service.js +95 -0
- package/dist/services/batch-delegation.service.js.map +1 -0
- package/dist/services/oauth-config.service.d.ts +53 -0
- package/dist/services/oauth-config.service.d.ts.map +1 -0
- package/dist/services/oauth-config.service.js +117 -0
- package/dist/services/oauth-config.service.js.map +1 -0
- package/dist/services/oauth-provider-registry.d.ts +77 -0
- package/dist/services/oauth-provider-registry.d.ts.map +1 -0
- package/dist/services/oauth-provider-registry.js +112 -0
- package/dist/services/oauth-provider-registry.js.map +1 -0
- package/dist/services/oauth-service.d.ts +77 -0
- package/dist/services/oauth-service.d.ts.map +1 -0
- package/dist/services/oauth-service.js +348 -0
- package/dist/services/oauth-service.js.map +1 -0
- package/dist/services/oauth-token-retrieval.service.d.ts +49 -0
- package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -0
- package/dist/services/oauth-token-retrieval.service.js +150 -0
- package/dist/services/oauth-token-retrieval.service.js.map +1 -0
- package/dist/services/provider-resolver.d.ts +48 -0
- package/dist/services/provider-resolver.d.ts.map +1 -0
- package/dist/services/provider-resolver.js +120 -0
- package/dist/services/provider-resolver.js.map +1 -0
- package/dist/services/provider-validator.d.ts +55 -0
- package/dist/services/provider-validator.d.ts.map +1 -0
- package/dist/services/provider-validator.js +135 -0
- package/dist/services/provider-validator.js.map +1 -0
- package/dist/services/tool-context-builder.d.ts +57 -0
- package/dist/services/tool-context-builder.d.ts.map +1 -0
- package/dist/services/tool-context-builder.js +125 -0
- package/dist/services/tool-context-builder.js.map +1 -0
- package/dist/services/tool-protection.service.d.ts +87 -10
- package/dist/services/tool-protection.service.d.ts.map +1 -1
- package/dist/services/tool-protection.service.js +282 -112
- package/dist/services/tool-protection.service.js.map +1 -1
- package/dist/types/oauth-required-error.d.ts +40 -0
- package/dist/types/oauth-required-error.d.ts.map +1 -0
- package/dist/types/oauth-required-error.js +40 -0
- package/dist/types/oauth-required-error.js.map +1 -0
- package/dist/utils/did-helpers.d.ts +33 -0
- package/dist/utils/did-helpers.d.ts.map +1 -1
- package/dist/utils/did-helpers.js +40 -0
- package/dist/utils/did-helpers.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/docs/API_REFERENCE.md +1362 -0
- package/docs/COMPLIANCE_MATRIX.md +691 -0
- package/docs/STATUSLIST2021_GUIDE.md +696 -0
- package/docs/W3C_VC_DELEGATION_GUIDE.md +710 -0
- package/package.json +24 -50
- package/scripts/audit-compliance.ts +724 -0
- package/src/__tests__/cache/tool-protection-cache.test.ts +640 -0
- package/src/__tests__/config/provider-runtime-config.test.ts +309 -0
- package/src/__tests__/delegation-e2e.test.ts +690 -0
- package/src/__tests__/identity/user-did-manager.test.ts +213 -0
- package/src/__tests__/index.test.ts +56 -0
- package/src/__tests__/integration/full-flow.test.ts +776 -0
- package/src/__tests__/integration.test.ts +281 -0
- package/src/__tests__/providers/base.test.ts +173 -0
- package/src/__tests__/providers/memory.test.ts +319 -0
- package/src/__tests__/regression/phase2-regression.test.ts +427 -0
- package/src/__tests__/runtime/audit-logger.test.ts +154 -0
- package/src/__tests__/runtime/base-extensions.test.ts +593 -0
- package/src/__tests__/runtime/base.test.ts +869 -0
- package/src/__tests__/runtime/delegation-flow.test.ts +164 -0
- package/src/__tests__/runtime/proof-client-did.test.ts +375 -0
- package/src/__tests__/runtime/route-interception.test.ts +686 -0
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +908 -0
- package/src/__tests__/services/agentshield-integration.test.ts +784 -0
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +487 -0
- package/src/__tests__/services/tool-protection-oauth-provider.test.ts +480 -0
- package/src/__tests__/services/tool-protection.service.test.ts +1366 -0
- package/src/__tests__/utils/mock-providers.ts +340 -0
- package/src/cache/oauth-config-cache.d.ts +69 -0
- package/src/cache/oauth-config-cache.d.ts.map +1 -0
- package/src/cache/oauth-config-cache.js +71 -0
- package/src/cache/oauth-config-cache.js.map +1 -0
- package/src/cache/oauth-config-cache.ts +123 -0
- package/src/cache/tool-protection-cache.ts +171 -0
- package/src/compliance/EXAMPLE.md +412 -0
- package/src/compliance/__tests__/schema-verifier.test.ts +797 -0
- package/src/compliance/index.ts +8 -0
- package/src/compliance/schema-registry.ts +460 -0
- package/src/compliance/schema-verifier.ts +708 -0
- package/src/config/__tests__/remote-config.spec.ts +268 -0
- package/src/config/remote-config.ts +174 -0
- package/src/config.ts +309 -0
- package/src/delegation/__tests__/audience-validator.test.ts +112 -0
- package/src/delegation/__tests__/bitstring.test.ts +346 -0
- package/src/delegation/__tests__/cascading-revocation.test.ts +628 -0
- package/src/delegation/__tests__/delegation-graph.test.ts +584 -0
- package/src/delegation/__tests__/utils.test.ts +152 -0
- package/src/delegation/__tests__/vc-issuer.test.ts +442 -0
- package/src/delegation/__tests__/vc-verifier.test.ts +922 -0
- package/src/delegation/audience-validator.ts +52 -0
- package/src/delegation/bitstring.ts +278 -0
- package/src/delegation/cascading-revocation.ts +370 -0
- package/src/delegation/delegation-graph.ts +299 -0
- package/src/delegation/index.ts +14 -0
- package/src/delegation/statuslist-manager.ts +353 -0
- package/src/delegation/storage/__tests__/memory-graph-storage.test.ts +366 -0
- package/src/delegation/storage/__tests__/memory-statuslist-storage.test.ts +228 -0
- package/src/delegation/storage/index.ts +9 -0
- package/src/delegation/storage/memory-graph-storage.ts +178 -0
- package/src/delegation/storage/memory-statuslist-storage.ts +77 -0
- package/src/delegation/utils.ts +42 -0
- package/src/delegation/vc-issuer.ts +232 -0
- package/src/delegation/vc-verifier.ts +568 -0
- package/src/identity/idp-token-resolver.ts +147 -0
- package/src/identity/idp-token-storage.interface.ts +59 -0
- package/src/identity/user-did-manager.ts +370 -0
- package/src/index.ts +260 -0
- package/src/providers/base.d.ts +91 -0
- package/src/providers/base.d.ts.map +1 -0
- package/src/providers/base.js +38 -0
- package/src/providers/base.js.map +1 -0
- package/src/providers/base.ts +96 -0
- package/src/providers/memory.ts +142 -0
- package/src/runtime/audit-logger.ts +39 -0
- package/src/runtime/base.ts +1329 -0
- package/src/services/__tests__/access-control.integration.test.ts +443 -0
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +578 -0
- package/src/services/__tests__/access-control.service.test.ts +970 -0
- package/src/services/__tests__/batch-delegation.service.test.ts +351 -0
- package/src/services/__tests__/crypto.service.test.ts +531 -0
- package/src/services/__tests__/oauth-provider-registry.test.ts +142 -0
- package/src/services/__tests__/proof-verifier.integration.test.ts +485 -0
- package/src/services/__tests__/proof-verifier.test.ts +489 -0
- package/src/services/__tests__/provider-resolution.integration.test.ts +198 -0
- package/src/services/__tests__/provider-resolver.test.ts +217 -0
- package/src/services/__tests__/storage.service.test.ts +358 -0
- package/src/services/access-control.service.ts +990 -0
- package/src/services/authorization/authorization-registry.ts +66 -0
- package/src/services/authorization/types.ts +71 -0
- package/src/services/batch-delegation.service.ts +137 -0
- package/src/services/crypto.service.ts +302 -0
- package/src/services/errors.ts +76 -0
- package/src/services/index.ts +9 -0
- package/src/services/oauth-config.service.d.ts +53 -0
- package/src/services/oauth-config.service.d.ts.map +1 -0
- package/src/services/oauth-config.service.js +113 -0
- package/src/services/oauth-config.service.js.map +1 -0
- package/src/services/oauth-config.service.ts +166 -0
- package/src/services/oauth-provider-registry.d.ts +57 -0
- package/src/services/oauth-provider-registry.d.ts.map +1 -0
- package/src/services/oauth-provider-registry.js +73 -0
- package/src/services/oauth-provider-registry.js.map +1 -0
- package/src/services/oauth-provider-registry.ts +123 -0
- package/src/services/oauth-service.ts +510 -0
- package/src/services/oauth-token-retrieval.service.ts +245 -0
- package/src/services/proof-verifier.ts +478 -0
- package/src/services/provider-resolver.d.ts +48 -0
- package/src/services/provider-resolver.d.ts.map +1 -0
- package/src/services/provider-resolver.js +106 -0
- package/src/services/provider-resolver.js.map +1 -0
- package/src/services/provider-resolver.ts +144 -0
- package/src/services/provider-validator.ts +170 -0
- package/src/services/storage.service.ts +566 -0
- package/src/services/tool-context-builder.ts +172 -0
- package/src/services/tool-protection.service.ts +958 -0
- package/src/types/oauth-required-error.ts +63 -0
- package/src/types/tool-protection.ts +155 -0
- package/src/utils/__tests__/did-helpers.test.ts +101 -0
- package/src/utils/base64.ts +148 -0
- package/src/utils/cors.ts +83 -0
- package/src/utils/did-helpers.ts +150 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/storage-keys.ts +278 -0
- package/tsconfig.json +21 -0
- package/vitest.config.ts +56 -0
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* Schema Compliance Audit Script
|
|
4
|
+
*
|
|
5
|
+
* Uses verifier with JSON Schema draft-07 support.
|
|
6
|
+
* Verifies all implementations against canonical schemas from schemas.kya-os.ai
|
|
7
|
+
* Generates a comprehensive compliance report.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
createSchemaVerifier,
|
|
12
|
+
type SchemaMetadata,
|
|
13
|
+
} from '../src/compliance/schema-verifier';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
getAllSchemas,
|
|
17
|
+
getCriticalSchemas,
|
|
18
|
+
getSchemasByCategory,
|
|
19
|
+
} from '../src/compliance/schema-registry';
|
|
20
|
+
|
|
21
|
+
// Import all available implementations from contracts
|
|
22
|
+
import type {
|
|
23
|
+
HandshakeRequest,
|
|
24
|
+
SessionContext,
|
|
25
|
+
NonceCache,
|
|
26
|
+
NonceCacheEntry,
|
|
27
|
+
NonceCacheConfig,
|
|
28
|
+
ProofMeta,
|
|
29
|
+
DetachedProof,
|
|
30
|
+
CanonicalHashes,
|
|
31
|
+
AuditRecord,
|
|
32
|
+
} from '@kya-os/contracts';
|
|
33
|
+
|
|
34
|
+
// Import delegation and VC types
|
|
35
|
+
import type {
|
|
36
|
+
VerifiableCredential,
|
|
37
|
+
VerifiablePresentation,
|
|
38
|
+
CredentialStatus,
|
|
39
|
+
StatusList2021Credential,
|
|
40
|
+
Proof,
|
|
41
|
+
DelegationCredential,
|
|
42
|
+
DelegationRecord,
|
|
43
|
+
DelegationConstraints,
|
|
44
|
+
BudgetConstraint,
|
|
45
|
+
ScopeConstraint,
|
|
46
|
+
TimeConstraint,
|
|
47
|
+
} from '@kya-os/contracts';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Sample implementations for each schema type
|
|
51
|
+
*/
|
|
52
|
+
function createSampleImplementations(): Map<string, any> {
|
|
53
|
+
const implementations = new Map<string, any>();
|
|
54
|
+
|
|
55
|
+
// ===================================================================
|
|
56
|
+
// W3C Verifiable Credentials
|
|
57
|
+
// ===================================================================
|
|
58
|
+
|
|
59
|
+
// Sample VerifiableCredential
|
|
60
|
+
const sampleVC: VerifiableCredential = {
|
|
61
|
+
'@context': [
|
|
62
|
+
'https://www.w3.org/2018/credentials/v1',
|
|
63
|
+
],
|
|
64
|
+
id: 'urn:uuid:sample-vc-123',
|
|
65
|
+
type: ['VerifiableCredential'],
|
|
66
|
+
issuer: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
67
|
+
issuanceDate: '2025-10-17T00:00:00Z',
|
|
68
|
+
credentialSubject: {
|
|
69
|
+
id: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
70
|
+
},
|
|
71
|
+
proof: {
|
|
72
|
+
type: 'Ed25519Signature2020',
|
|
73
|
+
created: '2025-10-17T00:00:00Z',
|
|
74
|
+
verificationMethod: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
75
|
+
proofPurpose: 'assertionMethod',
|
|
76
|
+
proofValue: 'z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz',
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
implementations.set('verifiable-credential', sampleVC);
|
|
80
|
+
|
|
81
|
+
// Sample VerifiablePresentation
|
|
82
|
+
const sampleVP: VerifiablePresentation = {
|
|
83
|
+
'@context': [
|
|
84
|
+
'https://www.w3.org/2018/credentials/v1',
|
|
85
|
+
],
|
|
86
|
+
id: 'urn:uuid:sample-vp-123',
|
|
87
|
+
type: ['VerifiablePresentation'],
|
|
88
|
+
holder: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
89
|
+
verifiableCredential: [sampleVC],
|
|
90
|
+
proof: {
|
|
91
|
+
type: 'Ed25519Signature2020',
|
|
92
|
+
created: '2025-10-17T00:00:00Z',
|
|
93
|
+
verificationMethod: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
94
|
+
proofPurpose: 'authentication',
|
|
95
|
+
proofValue: 'z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz',
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
implementations.set('verifiable-presentation', sampleVP);
|
|
99
|
+
|
|
100
|
+
// Sample CredentialStatus
|
|
101
|
+
const sampleCredentialStatus: CredentialStatus = {
|
|
102
|
+
id: 'https://example.com/status/revocation/v1#12345',
|
|
103
|
+
type: 'StatusList2021Entry',
|
|
104
|
+
statusPurpose: 'revocation',
|
|
105
|
+
statusListIndex: '12345',
|
|
106
|
+
statusListCredential: 'https://example.com/status/revocation/v1',
|
|
107
|
+
};
|
|
108
|
+
implementations.set('credential-status', sampleCredentialStatus);
|
|
109
|
+
|
|
110
|
+
// Sample StatusList2021Credential
|
|
111
|
+
const sampleStatusList: StatusList2021Credential = {
|
|
112
|
+
'@context': [
|
|
113
|
+
'https://www.w3.org/2018/credentials/v1',
|
|
114
|
+
'https://w3id.org/vc/status-list/2021/v1',
|
|
115
|
+
],
|
|
116
|
+
id: 'https://example.com/status/revocation/v1',
|
|
117
|
+
type: ['VerifiableCredential', 'StatusList2021Credential'],
|
|
118
|
+
issuer: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
119
|
+
issuanceDate: '2025-10-17T00:00:00Z',
|
|
120
|
+
credentialSubject: {
|
|
121
|
+
id: 'https://example.com/status/revocation/v1#list',
|
|
122
|
+
type: 'StatusList2021',
|
|
123
|
+
statusPurpose: 'revocation',
|
|
124
|
+
encodedList: 'H4sIAAAAAAAAA-3BMQEAAADCoPVPbQwfoAAAAAAAAAAAAAAAAAAAAIC3AYbSVKsAQAAA',
|
|
125
|
+
},
|
|
126
|
+
proof: {
|
|
127
|
+
type: 'Ed25519Signature2020',
|
|
128
|
+
created: '2025-10-17T00:00:00Z',
|
|
129
|
+
verificationMethod: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
130
|
+
proofPurpose: 'assertionMethod',
|
|
131
|
+
proofValue: 'z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz',
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
implementations.set('statuslist2021-credential', sampleStatusList);
|
|
135
|
+
|
|
136
|
+
// Sample Proof
|
|
137
|
+
const sampleProof: Proof = {
|
|
138
|
+
type: 'Ed25519Signature2020',
|
|
139
|
+
created: '2025-10-17T00:00:00Z',
|
|
140
|
+
verificationMethod: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
141
|
+
proofPurpose: 'assertionMethod',
|
|
142
|
+
proofValue: 'z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz',
|
|
143
|
+
};
|
|
144
|
+
implementations.set('proof', sampleProof);
|
|
145
|
+
|
|
146
|
+
// ===================================================================
|
|
147
|
+
// MCP-I Protocol
|
|
148
|
+
// ===================================================================
|
|
149
|
+
|
|
150
|
+
// Sample ProofMeta (matches contracts/src/proof.ts ProofMetaSchema)
|
|
151
|
+
const sampleProofMeta: ProofMeta = {
|
|
152
|
+
did: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
153
|
+
kid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
154
|
+
ts: 1729123200, // Unix timestamp (number)
|
|
155
|
+
nonce: 'nonce-123',
|
|
156
|
+
audience: 'https://example.com',
|
|
157
|
+
sessionId: 'session-123',
|
|
158
|
+
requestHash: 'sha256:' + 'a'.repeat(64),
|
|
159
|
+
responseHash: 'sha256:' + 'b'.repeat(64),
|
|
160
|
+
scopeId: 'scope-123',
|
|
161
|
+
delegationRef: 'delegation-123',
|
|
162
|
+
};
|
|
163
|
+
implementations.set('proof-meta', sampleProofMeta);
|
|
164
|
+
|
|
165
|
+
// Sample DetachedProof (matches contracts/src/proof.ts DetachedProofSchema)
|
|
166
|
+
const sampleDetachedProof: DetachedProof = {
|
|
167
|
+
jws: 'eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa2hhWGdCWkR2b3REa0w1MjU3ZmFpenRpR2lDMlF0S0xHcGJubkVHdGEyZG9LI3o2TWtoYVhnQlpEdm90RGtMNTI1N2ZhaXp0aUdpQzJRdEtMR3Bibm5FR3RhMmRvSyJ9.eyJhdWQiOiJodHRwczovL2V4YW1wbGUuY29tIiwic3ViIjoic2Vzc2lvbi0xMjMiLCJpc3MiOiJkaWQ6a2V5Ono2TWtoYVhnQlpEdm90RGtMNTI1N2ZhaXp0aUdpQzJRdEtMR3Bibm5FR3RhMmRvSyIsIm5vbmNlIjoibm9uY2UtMTIzIiwicmVxSGFzaCI6InNoYTI1NjphYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYSIsInJlc0hhc2giOiJzaGEyNTY6YmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiIn0.z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz',
|
|
168
|
+
meta: sampleProofMeta,
|
|
169
|
+
};
|
|
170
|
+
implementations.set('detached-proof', sampleDetachedProof);
|
|
171
|
+
|
|
172
|
+
// Sample CanonicalHashes (matches contracts/src/proof.ts CanonicalHashesSchema)
|
|
173
|
+
const sampleCanonicalHashes: CanonicalHashes = {
|
|
174
|
+
requestHash: 'sha256:' + 'a'.repeat(64),
|
|
175
|
+
responseHash: 'sha256:' + 'b'.repeat(64),
|
|
176
|
+
};
|
|
177
|
+
implementations.set('canonical-hashes', sampleCanonicalHashes);
|
|
178
|
+
|
|
179
|
+
// Sample HandshakeRequest (matches contracts/src/handshake.ts HandshakeRequestSchema)
|
|
180
|
+
const sampleHandshake: HandshakeRequest = {
|
|
181
|
+
nonce: 'nonce-123',
|
|
182
|
+
audience: 'https://example.com',
|
|
183
|
+
timestamp: 1729123200, // Unix timestamp (number)
|
|
184
|
+
agentDid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
185
|
+
};
|
|
186
|
+
implementations.set('handshake-request', sampleHandshake);
|
|
187
|
+
|
|
188
|
+
// Sample HandshakeResponse
|
|
189
|
+
const sampleHandshakeResponse = {
|
|
190
|
+
session_id: 'session-123',
|
|
191
|
+
server_did: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
192
|
+
nonce: 'nonce-456',
|
|
193
|
+
timestamp: '2025-10-17T00:00:01Z',
|
|
194
|
+
capabilities: ['tool_execution', 'delegation'],
|
|
195
|
+
};
|
|
196
|
+
implementations.set('handshake-response', sampleHandshakeResponse);
|
|
197
|
+
|
|
198
|
+
// Sample SessionContext (matches contracts/src/handshake.ts SessionContextSchema)
|
|
199
|
+
const sampleSession: SessionContext = {
|
|
200
|
+
sessionId: 'session-123',
|
|
201
|
+
audience: 'https://example.com',
|
|
202
|
+
nonce: 'nonce-123',
|
|
203
|
+
timestamp: 1729123200,
|
|
204
|
+
createdAt: 1729123200,
|
|
205
|
+
lastActivity: 1729123500,
|
|
206
|
+
ttlMinutes: 30,
|
|
207
|
+
agentDid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
208
|
+
};
|
|
209
|
+
implementations.set('session-context', sampleSession);
|
|
210
|
+
|
|
211
|
+
// ===================================================================
|
|
212
|
+
// Delegation System
|
|
213
|
+
// ===================================================================
|
|
214
|
+
|
|
215
|
+
// Sample DelegationConstraints
|
|
216
|
+
const sampleConstraints: DelegationConstraints = {
|
|
217
|
+
budget: {
|
|
218
|
+
maxCost: 100,
|
|
219
|
+
currency: 'USD',
|
|
220
|
+
},
|
|
221
|
+
scope: {
|
|
222
|
+
allowedTools: ['tool-1', 'tool-2'],
|
|
223
|
+
allowedResources: ['resource-1'],
|
|
224
|
+
},
|
|
225
|
+
time: {
|
|
226
|
+
notBefore: '2025-10-17T00:00:00Z',
|
|
227
|
+
notAfter: '2025-10-18T00:00:00Z',
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
implementations.set('delegation-constraints', sampleConstraints);
|
|
231
|
+
|
|
232
|
+
// Sample BudgetConstraint
|
|
233
|
+
const sampleBudget: BudgetConstraint = {
|
|
234
|
+
maxCost: 100,
|
|
235
|
+
currency: 'USD',
|
|
236
|
+
};
|
|
237
|
+
implementations.set('budget-constraint', sampleBudget);
|
|
238
|
+
|
|
239
|
+
// Sample ScopeConstraint
|
|
240
|
+
const sampleScope: ScopeConstraint = {
|
|
241
|
+
allowedTools: ['tool-1', 'tool-2'],
|
|
242
|
+
allowedResources: ['resource-1'],
|
|
243
|
+
};
|
|
244
|
+
implementations.set('scope-constraint', sampleScope);
|
|
245
|
+
|
|
246
|
+
// Sample TimeConstraint
|
|
247
|
+
const sampleTime: TimeConstraint = {
|
|
248
|
+
notBefore: '2025-10-17T00:00:00Z',
|
|
249
|
+
notAfter: '2025-10-18T00:00:00Z',
|
|
250
|
+
};
|
|
251
|
+
implementations.set('time-constraint', sampleTime);
|
|
252
|
+
|
|
253
|
+
// Sample DelegationRecord
|
|
254
|
+
const sampleDelegationRecord: DelegationRecord = {
|
|
255
|
+
id: 'delegation-123',
|
|
256
|
+
issuerDid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
257
|
+
subjectDid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
258
|
+
constraints: sampleConstraints,
|
|
259
|
+
issuedAt: '2025-10-17T00:00:00Z',
|
|
260
|
+
expiresAt: '2025-10-18T00:00:00Z',
|
|
261
|
+
};
|
|
262
|
+
implementations.set('delegation-record', sampleDelegationRecord);
|
|
263
|
+
|
|
264
|
+
// Sample DelegationCredential
|
|
265
|
+
const sampleDelegationVC: DelegationCredential = {
|
|
266
|
+
'@context': [
|
|
267
|
+
'https://www.w3.org/2018/credentials/v1',
|
|
268
|
+
'https://mcp-i.org/contexts/delegation/v1',
|
|
269
|
+
],
|
|
270
|
+
id: 'urn:uuid:delegation-123',
|
|
271
|
+
type: ['VerifiableCredential', 'DelegationCredential'],
|
|
272
|
+
issuer: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
273
|
+
issuanceDate: '2025-10-17T00:00:00Z',
|
|
274
|
+
expirationDate: '2025-10-18T00:00:00Z',
|
|
275
|
+
credentialSubject: {
|
|
276
|
+
id: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
277
|
+
delegation: sampleDelegationRecord,
|
|
278
|
+
},
|
|
279
|
+
credentialStatus: sampleCredentialStatus,
|
|
280
|
+
proof: {
|
|
281
|
+
type: 'Ed25519Signature2020',
|
|
282
|
+
created: '2025-10-17T00:00:00Z',
|
|
283
|
+
verificationMethod: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
284
|
+
proofPurpose: 'assertionMethod',
|
|
285
|
+
proofValue: 'z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz',
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
implementations.set('delegation-credential', sampleDelegationVC);
|
|
289
|
+
|
|
290
|
+
// ===================================================================
|
|
291
|
+
// Audit & Logging
|
|
292
|
+
// ===================================================================
|
|
293
|
+
|
|
294
|
+
// Sample AuditRecord (matches contracts/src/proof.ts AuditRecordSchema)
|
|
295
|
+
const sampleAudit: AuditRecord = {
|
|
296
|
+
version: 'audit.v1',
|
|
297
|
+
ts: 1729123200,
|
|
298
|
+
session: 'session-123',
|
|
299
|
+
audience: 'https://example.com',
|
|
300
|
+
did: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
301
|
+
kid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
302
|
+
reqHash: 'sha256:' + 'a'.repeat(64),
|
|
303
|
+
resHash: 'sha256:' + 'b'.repeat(64),
|
|
304
|
+
verified: 'yes',
|
|
305
|
+
scope: 'tool-execution',
|
|
306
|
+
};
|
|
307
|
+
implementations.set('audit-record', sampleAudit);
|
|
308
|
+
|
|
309
|
+
// Sample AuditEntry (similar to AuditRecord but might have different structure)
|
|
310
|
+
const sampleAuditEntry = {
|
|
311
|
+
timestamp: '2025-10-17T00:00:00Z',
|
|
312
|
+
action: 'tool_execution',
|
|
313
|
+
actor: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
314
|
+
result: 'success',
|
|
315
|
+
metadata: {
|
|
316
|
+
tool_name: 'example-tool',
|
|
317
|
+
session_id: 'session-123',
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
implementations.set('audit-entry', sampleAuditEntry);
|
|
321
|
+
|
|
322
|
+
// ===================================================================
|
|
323
|
+
// Nonce Cache
|
|
324
|
+
// ===================================================================
|
|
325
|
+
|
|
326
|
+
// Sample NonceCacheEntry (matches contracts/src/handshake.ts NonceCacheEntrySchema)
|
|
327
|
+
const sampleNonceEntry: NonceCacheEntry = {
|
|
328
|
+
sessionId: 'session-123',
|
|
329
|
+
expiresAt: 1729123500,
|
|
330
|
+
};
|
|
331
|
+
implementations.set('nonce-cache-entry', sampleNonceEntry);
|
|
332
|
+
|
|
333
|
+
// Sample NonceCacheConfig
|
|
334
|
+
const sampleNonceConfig: NonceCacheConfig = {
|
|
335
|
+
ttl: 300,
|
|
336
|
+
maxSize: 10000,
|
|
337
|
+
};
|
|
338
|
+
implementations.set('nonce-cache-config', sampleNonceConfig);
|
|
339
|
+
|
|
340
|
+
// ===================================================================
|
|
341
|
+
// Agent Identity
|
|
342
|
+
// ===================================================================
|
|
343
|
+
|
|
344
|
+
// Sample AgentIdentity
|
|
345
|
+
const sampleAgentIdentity = {
|
|
346
|
+
did: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
347
|
+
publicKey: 'base64-encoded-public-key',
|
|
348
|
+
privateKey: 'base64-encoded-private-key',
|
|
349
|
+
kid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
350
|
+
};
|
|
351
|
+
implementations.set('agent-identity', sampleAgentIdentity);
|
|
352
|
+
|
|
353
|
+
// Sample DIDDocument
|
|
354
|
+
const sampleDIDDocument = {
|
|
355
|
+
'@context': ['https://www.w3.org/ns/did/v1'],
|
|
356
|
+
id: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
357
|
+
verificationMethod: [
|
|
358
|
+
{
|
|
359
|
+
id: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
360
|
+
type: 'Ed25519VerificationKey2020',
|
|
361
|
+
controller: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
362
|
+
publicKeyMultibase: 'z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
363
|
+
},
|
|
364
|
+
],
|
|
365
|
+
authentication: [
|
|
366
|
+
'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
367
|
+
],
|
|
368
|
+
assertionMethod: [
|
|
369
|
+
'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
370
|
+
],
|
|
371
|
+
};
|
|
372
|
+
implementations.set('did-document', sampleDIDDocument);
|
|
373
|
+
|
|
374
|
+
// Sample VerificationMethod
|
|
375
|
+
const sampleVerificationMethod = {
|
|
376
|
+
id: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
377
|
+
type: 'Ed25519VerificationKey2020',
|
|
378
|
+
controller: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
379
|
+
publicKeyMultibase: 'z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
380
|
+
};
|
|
381
|
+
implementations.set('verification-method', sampleVerificationMethod);
|
|
382
|
+
|
|
383
|
+
// ===================================================================
|
|
384
|
+
// Tool Protection
|
|
385
|
+
// ===================================================================
|
|
386
|
+
|
|
387
|
+
// Sample ToolProtection
|
|
388
|
+
const sampleToolProtection = {
|
|
389
|
+
toolName: 'example-tool',
|
|
390
|
+
requiresDelegation: true,
|
|
391
|
+
requiredCapabilities: ['tool_execution'],
|
|
392
|
+
budgetLimit: 100,
|
|
393
|
+
};
|
|
394
|
+
implementations.set('tool-protection', sampleToolProtection);
|
|
395
|
+
|
|
396
|
+
// Sample ToolProtectionConfig
|
|
397
|
+
const sampleToolProtectionConfig = {
|
|
398
|
+
enabled: true,
|
|
399
|
+
defaultRequiresDelegation: false,
|
|
400
|
+
protectedTools: ['sensitive-tool-1', 'sensitive-tool-2'],
|
|
401
|
+
};
|
|
402
|
+
implementations.set('tool-protection-config', sampleToolProtectionConfig);
|
|
403
|
+
|
|
404
|
+
// ===================================================================
|
|
405
|
+
// MCP Tools & Resources
|
|
406
|
+
// ===================================================================
|
|
407
|
+
|
|
408
|
+
// Sample MCP Tool
|
|
409
|
+
const sampleMCPTool = {
|
|
410
|
+
name: 'example-tool',
|
|
411
|
+
description: 'An example tool',
|
|
412
|
+
inputSchema: {
|
|
413
|
+
type: 'object',
|
|
414
|
+
properties: {
|
|
415
|
+
input: { type: 'string' },
|
|
416
|
+
},
|
|
417
|
+
required: ['input'],
|
|
418
|
+
},
|
|
419
|
+
};
|
|
420
|
+
implementations.set('mcp-tool', sampleMCPTool);
|
|
421
|
+
|
|
422
|
+
// Sample MCP Resource
|
|
423
|
+
const sampleMCPResource = {
|
|
424
|
+
uri: 'file:///example.txt',
|
|
425
|
+
name: 'Example Resource',
|
|
426
|
+
mimeType: 'text/plain',
|
|
427
|
+
description: 'An example resource',
|
|
428
|
+
};
|
|
429
|
+
implementations.set('mcp-resource', sampleMCPResource);
|
|
430
|
+
|
|
431
|
+
// Sample MCP Prompt
|
|
432
|
+
const sampleMCPPrompt = {
|
|
433
|
+
name: 'example-prompt',
|
|
434
|
+
description: 'An example prompt template',
|
|
435
|
+
arguments: [
|
|
436
|
+
{
|
|
437
|
+
name: 'input',
|
|
438
|
+
description: 'Input parameter',
|
|
439
|
+
required: true,
|
|
440
|
+
},
|
|
441
|
+
],
|
|
442
|
+
};
|
|
443
|
+
implementations.set('mcp-prompt', sampleMCPPrompt);
|
|
444
|
+
|
|
445
|
+
// ===================================================================
|
|
446
|
+
// Registry & Discovery
|
|
447
|
+
// ===================================================================
|
|
448
|
+
|
|
449
|
+
// Sample AgentRegistryEntry
|
|
450
|
+
const sampleRegistryEntry = {
|
|
451
|
+
did: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
452
|
+
name: 'Example Agent',
|
|
453
|
+
description: 'An example agent',
|
|
454
|
+
endpoint: 'https://example.com/mcp',
|
|
455
|
+
capabilities: ['tool_execution', 'delegation'],
|
|
456
|
+
registeredAt: '2025-10-17T00:00:00Z',
|
|
457
|
+
};
|
|
458
|
+
implementations.set('agent-registry-entry', sampleRegistryEntry);
|
|
459
|
+
|
|
460
|
+
// Sample ServiceEndpoint
|
|
461
|
+
const sampleServiceEndpoint = {
|
|
462
|
+
id: 'https://example.com/mcp',
|
|
463
|
+
type: 'MCPService',
|
|
464
|
+
serviceEndpoint: 'https://example.com/mcp',
|
|
465
|
+
description: 'MCP service endpoint',
|
|
466
|
+
};
|
|
467
|
+
implementations.set('service-endpoint', sampleServiceEndpoint);
|
|
468
|
+
|
|
469
|
+
// ===================================================================
|
|
470
|
+
// Verifier Service
|
|
471
|
+
// ===================================================================
|
|
472
|
+
|
|
473
|
+
// Sample VerifierRequest
|
|
474
|
+
const sampleVerifierRequest = {
|
|
475
|
+
credential: sampleDelegationVC,
|
|
476
|
+
options: {
|
|
477
|
+
checkStatus: true,
|
|
478
|
+
checkSignature: true,
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
implementations.set('verifier-request', sampleVerifierRequest);
|
|
482
|
+
|
|
483
|
+
// Sample VerifierResponse
|
|
484
|
+
const sampleVerifierResponse = {
|
|
485
|
+
valid: true,
|
|
486
|
+
credential: sampleDelegationVC,
|
|
487
|
+
checks: {
|
|
488
|
+
signature: { valid: true },
|
|
489
|
+
status: { valid: true },
|
|
490
|
+
expiration: { valid: true },
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
implementations.set('verifier-response', sampleVerifierResponse);
|
|
494
|
+
|
|
495
|
+
// Sample VerificationResult
|
|
496
|
+
const sampleVerificationResult = {
|
|
497
|
+
valid: true,
|
|
498
|
+
checks: [
|
|
499
|
+
{ name: 'signature', passed: true },
|
|
500
|
+
{ name: 'status', passed: true },
|
|
501
|
+
{ name: 'expiration', passed: true },
|
|
502
|
+
],
|
|
503
|
+
errors: [],
|
|
504
|
+
warnings: [],
|
|
505
|
+
};
|
|
506
|
+
implementations.set('verification-result', sampleVerificationResult);
|
|
507
|
+
|
|
508
|
+
// ===================================================================
|
|
509
|
+
// CLI & Configuration
|
|
510
|
+
// ===================================================================
|
|
511
|
+
|
|
512
|
+
// Sample CLIConfig
|
|
513
|
+
const sampleCLIConfig = {
|
|
514
|
+
identityPath: '.mcp-i/identity.json',
|
|
515
|
+
registryUrl: 'https://registry.example.com',
|
|
516
|
+
verifierUrl: 'https://verifier.example.com',
|
|
517
|
+
defaultCapabilities: ['tool_execution'],
|
|
518
|
+
};
|
|
519
|
+
implementations.set('cli-config', sampleCLIConfig);
|
|
520
|
+
|
|
521
|
+
// Sample EnvironmentConfig
|
|
522
|
+
const sampleEnvConfig = {
|
|
523
|
+
environment: 'development',
|
|
524
|
+
debug: true,
|
|
525
|
+
logLevel: 'info',
|
|
526
|
+
};
|
|
527
|
+
implementations.set('environment-config', sampleEnvConfig);
|
|
528
|
+
|
|
529
|
+
// ===================================================================
|
|
530
|
+
// TLKRC (Tool-Level Key Rotation Config)
|
|
531
|
+
// ===================================================================
|
|
532
|
+
|
|
533
|
+
// Sample TLKRCConfig
|
|
534
|
+
const sampleTLKRCConfig = {
|
|
535
|
+
enabled: true,
|
|
536
|
+
rotationIntervalDays: 30,
|
|
537
|
+
maxKeyAge: 90,
|
|
538
|
+
};
|
|
539
|
+
implementations.set('tlkrc-config', sampleTLKRCConfig);
|
|
540
|
+
|
|
541
|
+
// Sample TLKRCEntry
|
|
542
|
+
const sampleTLKRCEntry = {
|
|
543
|
+
toolName: 'example-tool',
|
|
544
|
+
kid: 'key-123',
|
|
545
|
+
createdAt: '2025-10-17T00:00:00Z',
|
|
546
|
+
expiresAt: '2025-11-17T00:00:00Z',
|
|
547
|
+
rotated: false,
|
|
548
|
+
};
|
|
549
|
+
implementations.set('tlkrc-entry', sampleTLKRCEntry);
|
|
550
|
+
|
|
551
|
+
// ===================================================================
|
|
552
|
+
// Runtime Configuration
|
|
553
|
+
// ===================================================================
|
|
554
|
+
|
|
555
|
+
// Sample RuntimeConfig
|
|
556
|
+
const sampleRuntimeConfig = {
|
|
557
|
+
identityEnabled: true,
|
|
558
|
+
delegationEnabled: true,
|
|
559
|
+
auditEnabled: true,
|
|
560
|
+
nonceCacheType: 'memory',
|
|
561
|
+
sessionTTL: 3600,
|
|
562
|
+
};
|
|
563
|
+
implementations.set('runtime-config', sampleRuntimeConfig);
|
|
564
|
+
|
|
565
|
+
// Sample PlatformConfig
|
|
566
|
+
const samplePlatformConfig = {
|
|
567
|
+
platform: 'node',
|
|
568
|
+
version: '1.0.0',
|
|
569
|
+
features: ['crypto', 'storage', 'networking'],
|
|
570
|
+
};
|
|
571
|
+
implementations.set('platform-config', samplePlatformConfig);
|
|
572
|
+
|
|
573
|
+
return implementations;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Run compliance audit
|
|
578
|
+
*/
|
|
579
|
+
async function runAudit() {
|
|
580
|
+
console.log('================================================================================');
|
|
581
|
+
console.log('SCHEMA COMPLIANCE AUDIT');
|
|
582
|
+
console.log('Enhanced with JSON Schema draft-07 support');
|
|
583
|
+
console.log('================================================================================\n');
|
|
584
|
+
|
|
585
|
+
const verifier = createSchemaVerifier({
|
|
586
|
+
schemasBaseUrl: 'https://schemas.kya-os.ai/xmcp-i',
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
const implementations = createSampleImplementations();
|
|
590
|
+
|
|
591
|
+
console.log(`Total implementations: ${implementations.size}\n`);
|
|
592
|
+
|
|
593
|
+
// Phase 1: Verify Critical Schemas (must be 100% compliant)
|
|
594
|
+
console.log('================================================================================');
|
|
595
|
+
console.log('PHASE 1: CRITICAL SCHEMAS (Must be 100% Compliant)');
|
|
596
|
+
console.log('================================================================================\n');
|
|
597
|
+
|
|
598
|
+
const criticalSchemas = getCriticalSchemas();
|
|
599
|
+
const criticalResults: Array<{ schema: SchemaMetadata; compliant: boolean; percentage: number }> = [];
|
|
600
|
+
|
|
601
|
+
for (const schema of criticalSchemas) {
|
|
602
|
+
const implementation = implementations.get(schema.id);
|
|
603
|
+
|
|
604
|
+
if (!implementation) {
|
|
605
|
+
console.log(`❌ ${schema.id}: Missing implementation\n`);
|
|
606
|
+
criticalResults.push({ schema, compliant: false, percentage: 0 });
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
console.log(`Verifying ${schema.id}...`);
|
|
611
|
+
const report = await verifier.verifySchema(schema, implementation);
|
|
612
|
+
|
|
613
|
+
const status = report.compliant ? '✅' : report.compliancePercentage >= 80 ? '⚠️ ' : '❌';
|
|
614
|
+
console.log(`${status} ${schema.id}: ${report.compliancePercentage.toFixed(1)}%`);
|
|
615
|
+
|
|
616
|
+
if (report.issues.length > 0) {
|
|
617
|
+
console.log(` Issues:`);
|
|
618
|
+
report.issues.slice(0, 5).forEach((issue) => console.log(` - ${issue}`));
|
|
619
|
+
if (report.issues.length > 5) {
|
|
620
|
+
console.log(` ... and ${report.issues.length - 5} more issues`);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
if (report.warnings.length > 0) {
|
|
625
|
+
console.log(` Warnings:`);
|
|
626
|
+
report.warnings.forEach((warning) => console.log(` - ${warning}`));
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
console.log();
|
|
630
|
+
|
|
631
|
+
criticalResults.push({
|
|
632
|
+
schema,
|
|
633
|
+
compliant: report.compliant,
|
|
634
|
+
percentage: report.compliancePercentage,
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// Phase 2: Verify All Schemas
|
|
639
|
+
console.log('================================================================================');
|
|
640
|
+
console.log('PHASE 2: ALL SCHEMAS');
|
|
641
|
+
console.log('================================================================================\n');
|
|
642
|
+
|
|
643
|
+
const allSchemas = getAllSchemas();
|
|
644
|
+
const fullReport = await verifier.verifyAll(allSchemas, implementations);
|
|
645
|
+
|
|
646
|
+
console.log(verifier.generateFullReport(fullReport));
|
|
647
|
+
|
|
648
|
+
// Phase 3: Verify by Category
|
|
649
|
+
console.log('\n================================================================================');
|
|
650
|
+
console.log('PHASE 3: COMPLIANCE BY CATEGORY');
|
|
651
|
+
console.log('================================================================================\n');
|
|
652
|
+
|
|
653
|
+
const categories = [
|
|
654
|
+
'w3c',
|
|
655
|
+
'delegation',
|
|
656
|
+
'identity',
|
|
657
|
+
'protocol',
|
|
658
|
+
'tool-protection',
|
|
659
|
+
'audit',
|
|
660
|
+
'nonce',
|
|
661
|
+
'mcp',
|
|
662
|
+
'registry',
|
|
663
|
+
'verifier',
|
|
664
|
+
'config',
|
|
665
|
+
'tlkrc',
|
|
666
|
+
];
|
|
667
|
+
|
|
668
|
+
for (const category of categories) {
|
|
669
|
+
const schemas = getSchemasByCategory(category);
|
|
670
|
+
const categoryReport = await verifier.verifyAll(schemas, implementations);
|
|
671
|
+
|
|
672
|
+
console.log(`${category.toUpperCase()}:`);
|
|
673
|
+
console.log(` Schemas: ${categoryReport.totalSchemas}`);
|
|
674
|
+
console.log(` Compliant: ${categoryReport.compliantSchemas}/${categoryReport.totalSchemas}`);
|
|
675
|
+
console.log(` Overall: ${categoryReport.overallCompliance.toFixed(1)}%`);
|
|
676
|
+
|
|
677
|
+
if (categoryReport.criticalIssues.length > 0) {
|
|
678
|
+
console.log(` Issues:`);
|
|
679
|
+
categoryReport.criticalIssues.forEach((issue) => console.log(` - ${issue}`));
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
console.log();
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// Summary
|
|
686
|
+
console.log('================================================================================');
|
|
687
|
+
console.log('AUDIT SUMMARY');
|
|
688
|
+
console.log('================================================================================\n');
|
|
689
|
+
|
|
690
|
+
const criticalCompliant = criticalResults.filter((r) => r.compliant).length;
|
|
691
|
+
const criticalTotal = criticalResults.length;
|
|
692
|
+
const avgCriticalCompliance =
|
|
693
|
+
criticalResults.reduce((sum, r) => sum + r.percentage, 0) / criticalTotal;
|
|
694
|
+
|
|
695
|
+
console.log(`Critical Schemas: ${criticalCompliant}/${criticalTotal} fully compliant`);
|
|
696
|
+
console.log(`Critical Schemas Avg: ${avgCriticalCompliance.toFixed(1)}%`);
|
|
697
|
+
console.log(`All Schemas: ${fullReport.compliantSchemas}/${fullReport.totalSchemas} compliant`);
|
|
698
|
+
console.log(`Overall Compliance: ${fullReport.overallCompliance.toFixed(1)}%`);
|
|
699
|
+
|
|
700
|
+
if (fullReport.criticalIssues.length > 0) {
|
|
701
|
+
console.log(`\n🚨 CRITICAL ISSUES (${fullReport.criticalIssues.length}):`);
|
|
702
|
+
fullReport.criticalIssues.forEach((issue, i) => {
|
|
703
|
+
console.log(` ${i + 1}. ${issue}`);
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// Exit code based on average critical compliance
|
|
708
|
+
if (avgCriticalCompliance >= 95) {
|
|
709
|
+
console.log('\n✅ AUDIT PASSED: Critical schemas >= 95% compliant on average');
|
|
710
|
+
process.exit(0);
|
|
711
|
+
} else if (avgCriticalCompliance >= 80) {
|
|
712
|
+
console.log('\n⚠️ AUDIT WARNING: Critical schemas 80-95% compliant - improvements needed');
|
|
713
|
+
process.exit(1);
|
|
714
|
+
} else {
|
|
715
|
+
console.log('\n❌ AUDIT FAILED: Critical schemas < 80% compliant');
|
|
716
|
+
process.exit(1);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// Run audit
|
|
721
|
+
runAudit().catch((error) => {
|
|
722
|
+
console.error('Audit failed with error:', error);
|
|
723
|
+
process.exit(1);
|
|
724
|
+
});
|