@kya-os/mcp-i-core 1.3.12 → 1.3.14
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/dist/config/remote-config.js +9 -12
- package/dist/runtime/base.js +11 -0
- package/dist/services/access-control.service.js +5 -0
- package/dist/services/tool-protection.service.js +17 -8
- package/package.json +2 -2
- package/.turbo/turbo-build.log +0 -4
- package/.turbo/turbo-test$colon$coverage.log +0 -4586
- package/.turbo/turbo-test.log +0 -3169
- package/COMPLIANCE_IMPROVEMENT_REPORT.md +0 -483
- package/Composer 3.md +0 -615
- package/GPT-5.md +0 -1169
- package/OPUS-plan.md +0 -352
- package/PHASE_3_AND_4.1_SUMMARY.md +0 -585
- package/PHASE_3_SUMMARY.md +0 -317
- package/PHASE_4.1.3_SUMMARY.md +0 -428
- package/PHASE_4.1_COMPLETE.md +0 -525
- package/PHASE_4_USER_DID_IDENTITY_LINKING_PLAN.md +0 -1240
- package/SCHEMA_COMPLIANCE_REPORT.md +0 -275
- package/TEST_PLAN.md +0 -571
- package/coverage/coverage-final.json +0 -60
- package/dist/cache/oauth-config-cache.d.ts.map +0 -1
- package/dist/cache/oauth-config-cache.js.map +0 -1
- package/dist/cache/tool-protection-cache.d.ts.map +0 -1
- package/dist/cache/tool-protection-cache.js.map +0 -1
- package/dist/compliance/index.d.ts.map +0 -1
- package/dist/compliance/index.js.map +0 -1
- package/dist/compliance/schema-registry.d.ts.map +0 -1
- package/dist/compliance/schema-registry.js.map +0 -1
- package/dist/compliance/schema-verifier.d.ts.map +0 -1
- package/dist/compliance/schema-verifier.js.map +0 -1
- package/dist/config/remote-config.d.ts.map +0 -1
- package/dist/config/remote-config.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/delegation/audience-validator.d.ts.map +0 -1
- package/dist/delegation/audience-validator.js.map +0 -1
- package/dist/delegation/bitstring.d.ts.map +0 -1
- package/dist/delegation/bitstring.js.map +0 -1
- package/dist/delegation/cascading-revocation.d.ts.map +0 -1
- package/dist/delegation/cascading-revocation.js.map +0 -1
- package/dist/delegation/delegation-graph.d.ts.map +0 -1
- package/dist/delegation/delegation-graph.js.map +0 -1
- package/dist/delegation/did-key-resolver.d.ts.map +0 -1
- package/dist/delegation/did-key-resolver.js.map +0 -1
- package/dist/delegation/index.d.ts.map +0 -1
- package/dist/delegation/index.js.map +0 -1
- package/dist/delegation/statuslist-manager.d.ts.map +0 -1
- package/dist/delegation/statuslist-manager.js.map +0 -1
- package/dist/delegation/storage/index.d.ts.map +0 -1
- package/dist/delegation/storage/index.js.map +0 -1
- package/dist/delegation/storage/memory-graph-storage.d.ts.map +0 -1
- package/dist/delegation/storage/memory-graph-storage.js.map +0 -1
- package/dist/delegation/storage/memory-statuslist-storage.d.ts.map +0 -1
- package/dist/delegation/storage/memory-statuslist-storage.js.map +0 -1
- package/dist/delegation/utils.d.ts.map +0 -1
- package/dist/delegation/utils.js.map +0 -1
- package/dist/delegation/vc-issuer.d.ts.map +0 -1
- package/dist/delegation/vc-issuer.js.map +0 -1
- package/dist/delegation/vc-verifier.d.ts.map +0 -1
- package/dist/delegation/vc-verifier.js.map +0 -1
- package/dist/identity/idp-token-resolver.d.ts.map +0 -1
- package/dist/identity/idp-token-resolver.js.map +0 -1
- package/dist/identity/idp-token-storage.interface.d.ts.map +0 -1
- package/dist/identity/idp-token-storage.interface.js.map +0 -1
- package/dist/identity/user-did-manager.d.ts.map +0 -1
- package/dist/identity/user-did-manager.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/providers/base.d.ts.map +0 -1
- package/dist/providers/base.js.map +0 -1
- package/dist/providers/memory.d.ts.map +0 -1
- package/dist/providers/memory.js.map +0 -1
- package/dist/runtime/audit-logger.d.ts.map +0 -1
- package/dist/runtime/audit-logger.js.map +0 -1
- package/dist/runtime/base.d.ts.map +0 -1
- package/dist/runtime/base.js.map +0 -1
- package/dist/services/access-control.service.d.ts.map +0 -1
- package/dist/services/access-control.service.js.map +0 -1
- package/dist/services/authorization/authorization-registry.d.ts.map +0 -1
- package/dist/services/authorization/authorization-registry.js.map +0 -1
- package/dist/services/authorization/types.d.ts.map +0 -1
- package/dist/services/authorization/types.js.map +0 -1
- package/dist/services/batch-delegation.service.d.ts.map +0 -1
- package/dist/services/batch-delegation.service.js.map +0 -1
- package/dist/services/crypto.service.d.ts.map +0 -1
- package/dist/services/crypto.service.js.map +0 -1
- package/dist/services/errors.d.ts.map +0 -1
- package/dist/services/errors.js.map +0 -1
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/index.js.map +0 -1
- package/dist/services/oauth-config.service.d.ts.map +0 -1
- package/dist/services/oauth-config.service.js.map +0 -1
- package/dist/services/oauth-provider-registry.d.ts.map +0 -1
- package/dist/services/oauth-provider-registry.js.map +0 -1
- package/dist/services/oauth-service.d.ts.map +0 -1
- package/dist/services/oauth-service.js.map +0 -1
- package/dist/services/oauth-token-retrieval.service.d.ts.map +0 -1
- package/dist/services/oauth-token-retrieval.service.js.map +0 -1
- package/dist/services/proof-verifier.d.ts.map +0 -1
- package/dist/services/proof-verifier.js.map +0 -1
- package/dist/services/provider-resolver.d.ts.map +0 -1
- package/dist/services/provider-resolver.js.map +0 -1
- package/dist/services/provider-validator.d.ts.map +0 -1
- package/dist/services/provider-validator.js.map +0 -1
- package/dist/services/session-registration.service.d.ts.map +0 -1
- package/dist/services/session-registration.service.js.map +0 -1
- package/dist/services/storage.service.d.ts.map +0 -1
- package/dist/services/storage.service.js.map +0 -1
- package/dist/services/tool-context-builder.d.ts.map +0 -1
- package/dist/services/tool-context-builder.js.map +0 -1
- package/dist/services/tool-protection.service.d.ts.map +0 -1
- package/dist/services/tool-protection.service.js.map +0 -1
- package/dist/types/oauth-required-error.d.ts.map +0 -1
- package/dist/types/oauth-required-error.js.map +0 -1
- package/dist/types/tool-protection.d.ts.map +0 -1
- package/dist/types/tool-protection.js.map +0 -1
- package/dist/utils/base58.d.ts.map +0 -1
- package/dist/utils/base58.js.map +0 -1
- package/dist/utils/base64.d.ts.map +0 -1
- package/dist/utils/base64.js.map +0 -1
- package/dist/utils/cors.d.ts.map +0 -1
- package/dist/utils/cors.js.map +0 -1
- package/dist/utils/did-helpers.d.ts.map +0 -1
- package/dist/utils/did-helpers.js.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/storage-keys.d.ts.map +0 -1
- package/dist/utils/storage-keys.js.map +0 -1
- package/docs/API_REFERENCE.md +0 -1362
- package/docs/COMPLIANCE_MATRIX.md +0 -691
- package/docs/STATUSLIST2021_GUIDE.md +0 -696
- package/docs/W3C_VC_DELEGATION_GUIDE.md +0 -710
- package/src/__tests__/cache/tool-protection-cache.test.ts +0 -640
- package/src/__tests__/config/provider-runtime-config.test.ts +0 -309
- package/src/__tests__/delegation-e2e.test.ts +0 -690
- package/src/__tests__/identity/user-did-manager.test.ts +0 -232
- package/src/__tests__/index.test.ts +0 -56
- package/src/__tests__/integration/full-flow.test.ts +0 -789
- package/src/__tests__/integration.test.ts +0 -281
- package/src/__tests__/providers/base.test.ts +0 -173
- package/src/__tests__/providers/memory.test.ts +0 -319
- package/src/__tests__/regression/phase2-regression.test.ts +0 -429
- package/src/__tests__/runtime/audit-logger.test.ts +0 -154
- package/src/__tests__/runtime/base-extensions.test.ts +0 -595
- package/src/__tests__/runtime/base.test.ts +0 -869
- package/src/__tests__/runtime/delegation-flow.test.ts +0 -164
- package/src/__tests__/runtime/proof-client-did.test.ts +0 -376
- package/src/__tests__/runtime/route-interception.test.ts +0 -686
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +0 -908
- package/src/__tests__/services/agentshield-integration.test.ts +0 -791
- package/src/__tests__/services/cache-busting.test.ts +0 -125
- package/src/__tests__/services/oauth-service-pkce.test.ts +0 -556
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +0 -591
- package/src/__tests__/services/tool-protection-merged-config.test.ts +0 -485
- package/src/__tests__/services/tool-protection-oauth-provider.test.ts +0 -480
- package/src/__tests__/services/tool-protection.service.test.ts +0 -1373
- package/src/__tests__/utils/mock-providers.ts +0 -340
- package/src/cache/oauth-config-cache.d.ts +0 -69
- package/src/cache/oauth-config-cache.d.ts.map +0 -1
- package/src/cache/oauth-config-cache.js.map +0 -1
- package/src/cache/oauth-config-cache.ts +0 -123
- package/src/cache/tool-protection-cache.ts +0 -171
- package/src/compliance/EXAMPLE.md +0 -412
- package/src/compliance/__tests__/schema-verifier.test.ts +0 -797
- package/src/compliance/index.ts +0 -8
- package/src/compliance/schema-registry.ts +0 -460
- package/src/compliance/schema-verifier.ts +0 -708
- package/src/config/__tests__/merged-config.spec.ts +0 -445
- package/src/config/__tests__/remote-config.spec.ts +0 -268
- package/src/config/remote-config.ts +0 -264
- package/src/config.ts +0 -312
- package/src/delegation/__tests__/audience-validator.test.ts +0 -112
- package/src/delegation/__tests__/bitstring.test.ts +0 -346
- package/src/delegation/__tests__/cascading-revocation.test.ts +0 -628
- package/src/delegation/__tests__/delegation-graph.test.ts +0 -584
- package/src/delegation/__tests__/did-key-resolver.test.ts +0 -265
- package/src/delegation/__tests__/utils.test.ts +0 -152
- package/src/delegation/__tests__/vc-issuer.test.ts +0 -442
- package/src/delegation/__tests__/vc-verifier.test.ts +0 -922
- package/src/delegation/audience-validator.ts +0 -52
- package/src/delegation/bitstring.ts +0 -278
- package/src/delegation/cascading-revocation.ts +0 -370
- package/src/delegation/delegation-graph.ts +0 -299
- package/src/delegation/did-key-resolver.ts +0 -179
- package/src/delegation/index.ts +0 -14
- package/src/delegation/statuslist-manager.ts +0 -353
- package/src/delegation/storage/__tests__/memory-graph-storage.test.ts +0 -366
- package/src/delegation/storage/__tests__/memory-statuslist-storage.test.ts +0 -228
- package/src/delegation/storage/index.ts +0 -9
- package/src/delegation/storage/memory-graph-storage.ts +0 -178
- package/src/delegation/storage/memory-statuslist-storage.ts +0 -77
- package/src/delegation/utils.ts +0 -221
- package/src/delegation/vc-issuer.ts +0 -232
- package/src/delegation/vc-verifier.ts +0 -568
- package/src/identity/idp-token-resolver.ts +0 -181
- package/src/identity/idp-token-storage.interface.ts +0 -94
- package/src/identity/user-did-manager.ts +0 -526
- package/src/index.ts +0 -310
- package/src/providers/base.d.ts +0 -91
- package/src/providers/base.d.ts.map +0 -1
- package/src/providers/base.js.map +0 -1
- package/src/providers/base.ts +0 -96
- package/src/providers/memory.ts +0 -142
- package/src/runtime/audit-logger.ts +0 -39
- package/src/runtime/base.ts +0 -1392
- package/src/services/__tests__/access-control.integration.test.ts +0 -443
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +0 -578
- package/src/services/__tests__/access-control.service.test.ts +0 -970
- package/src/services/__tests__/batch-delegation.service.test.ts +0 -351
- package/src/services/__tests__/crypto.service.test.ts +0 -531
- package/src/services/__tests__/oauth-provider-registry.test.ts +0 -142
- package/src/services/__tests__/proof-verifier.integration.test.ts +0 -485
- package/src/services/__tests__/proof-verifier.test.ts +0 -489
- package/src/services/__tests__/provider-resolution.integration.test.ts +0 -202
- package/src/services/__tests__/provider-resolver.test.ts +0 -213
- package/src/services/__tests__/storage.service.test.ts +0 -358
- package/src/services/access-control.service.ts +0 -990
- package/src/services/authorization/authorization-registry.ts +0 -66
- package/src/services/authorization/types.ts +0 -71
- package/src/services/batch-delegation.service.ts +0 -137
- package/src/services/crypto.service.ts +0 -302
- package/src/services/errors.ts +0 -76
- package/src/services/index.ts +0 -18
- package/src/services/oauth-config.service.d.ts +0 -53
- package/src/services/oauth-config.service.d.ts.map +0 -1
- package/src/services/oauth-config.service.js.map +0 -1
- package/src/services/oauth-config.service.ts +0 -192
- package/src/services/oauth-provider-registry.d.ts +0 -57
- package/src/services/oauth-provider-registry.d.ts.map +0 -1
- package/src/services/oauth-provider-registry.js.map +0 -1
- package/src/services/oauth-provider-registry.ts +0 -141
- package/src/services/oauth-service.ts +0 -544
- package/src/services/oauth-token-retrieval.service.ts +0 -245
- package/src/services/proof-verifier.ts +0 -478
- package/src/services/provider-resolver.d.ts +0 -48
- package/src/services/provider-resolver.d.ts.map +0 -1
- package/src/services/provider-resolver.js.map +0 -1
- package/src/services/provider-resolver.ts +0 -146
- package/src/services/provider-validator.ts +0 -170
- package/src/services/session-registration.service.ts +0 -251
- package/src/services/storage.service.ts +0 -566
- package/src/services/tool-context-builder.ts +0 -237
- package/src/services/tool-protection.service.ts +0 -1070
- package/src/types/oauth-required-error.ts +0 -63
- package/src/types/tool-protection.ts +0 -155
- package/src/utils/__tests__/did-helpers.test.ts +0 -156
- package/src/utils/base58.ts +0 -109
- package/src/utils/base64.ts +0 -148
- package/src/utils/cors.ts +0 -83
- package/src/utils/did-helpers.ts +0 -210
- package/src/utils/index.ts +0 -8
- package/src/utils/storage-keys.ts +0 -278
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -56
package/docs/API_REFERENCE.md
DELETED
|
@@ -1,1362 +0,0 @@
|
|
|
1
|
-
# API Reference
|
|
2
|
-
|
|
3
|
-
Complete API reference for `@kya-os/mcp-i-core` package.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Installation](#installation)
|
|
8
|
-
- [Core Classes](#core-classes)
|
|
9
|
-
- [DelegationIssuer](#delegationissuer)
|
|
10
|
-
- [DelegationVerifier](#delegationverifier)
|
|
11
|
-
- [DelegationGraph](#delegationgraph)
|
|
12
|
-
- [StatusList2021](#statuslist2021)
|
|
13
|
-
- [StatusList2021Manager](#statuslist2021manager)
|
|
14
|
-
- [StatusList2021Storage](#statuslist2021storage)
|
|
15
|
-
- [Schema Verification](#schema-verification)
|
|
16
|
-
- [SchemaVerifier](#schemaverifier)
|
|
17
|
-
- [SchemaRegistry](#schemaregistry)
|
|
18
|
-
- [Types](#types)
|
|
19
|
-
- [Utilities](#utilities)
|
|
20
|
-
|
|
21
|
-
## Installation
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install @kya-os/mcp-i-core
|
|
25
|
-
# or
|
|
26
|
-
pnpm add @kya-os/mcp-i-core
|
|
27
|
-
# or
|
|
28
|
-
yarn add @kya-os/mcp-i-core
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Core Classes
|
|
32
|
-
|
|
33
|
-
### DelegationIssuer
|
|
34
|
-
|
|
35
|
-
Issues W3C Verifiable Credentials for delegation.
|
|
36
|
-
|
|
37
|
-
#### Constructor
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
new DelegationIssuer(options: DelegationIssuerOptions)
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
**Parameters:**
|
|
44
|
-
|
|
45
|
-
| Name | Type | Description |
|
|
46
|
-
|------|------|-------------|
|
|
47
|
-
| `options.issuerDid` | `string` | DID of the issuing agent |
|
|
48
|
-
| `options.privateKeyJwk` | `JsonWebKey` | Private key in JWK format |
|
|
49
|
-
| `options.statusListManager?` | `StatusList2021Manager` | Optional status list manager for revocation |
|
|
50
|
-
|
|
51
|
-
**Example:**
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
import { DelegationIssuer } from '@kya-os/mcp-i-core';
|
|
55
|
-
|
|
56
|
-
const issuer = new DelegationIssuer({
|
|
57
|
-
issuerDid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
58
|
-
privateKeyJwk: {
|
|
59
|
-
kty: 'OKP',
|
|
60
|
-
crv: 'Ed25519',
|
|
61
|
-
d: 'base64-encoded-private-key',
|
|
62
|
-
x: 'base64-encoded-public-key',
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
#### Methods
|
|
68
|
-
|
|
69
|
-
##### `issue()`
|
|
70
|
-
|
|
71
|
-
Issue a delegation credential.
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
async issue(options: DelegationIssuanceOptions): Promise<DelegationCredential>
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
**Parameters:**
|
|
78
|
-
|
|
79
|
-
| Name | Type | Description |
|
|
80
|
-
|------|------|-------------|
|
|
81
|
-
| `options.subjectDid` | `string` | DID of the delegate (recipient) |
|
|
82
|
-
| `options.constraints` | `DelegationConstraints` | CRISP constraints for the delegation |
|
|
83
|
-
| `options.audience?` | `string` | Target audience URL |
|
|
84
|
-
| `options.expirationDate?` | `string` | ISO 8601 expiration date |
|
|
85
|
-
| `options.credentialStatus?` | `CredentialStatus` | StatusList2021 entry |
|
|
86
|
-
| `options.parentDelegation?` | `string` | Parent delegation ID for chains |
|
|
87
|
-
|
|
88
|
-
**Returns:** `Promise<DelegationCredential>` - The issued delegation credential
|
|
89
|
-
|
|
90
|
-
**Example:**
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
const delegation = await issuer.issue({
|
|
94
|
-
subjectDid: 'did:key:z6MkrWXJPkxPCuQF7RqeKZFdZqBXz3oCG7PUty5dXLKGzELj',
|
|
95
|
-
constraints: {
|
|
96
|
-
budget: {
|
|
97
|
-
maxCost: 100,
|
|
98
|
-
currency: 'USD',
|
|
99
|
-
},
|
|
100
|
-
scope: {
|
|
101
|
-
allowedTools: ['read_file', 'write_file'],
|
|
102
|
-
allowedResources: ['/documents/*'],
|
|
103
|
-
},
|
|
104
|
-
time: {
|
|
105
|
-
notBefore: new Date().toISOString(),
|
|
106
|
-
notAfter: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
audience: 'https://api.example.com',
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
console.log('Delegation ID:', delegation.id);
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
##### `issueWithStatus()`
|
|
116
|
-
|
|
117
|
-
Issue a delegation with automatic status list integration.
|
|
118
|
-
|
|
119
|
-
```typescript
|
|
120
|
-
async issueWithStatus(options: DelegationIssuanceOptions): Promise<DelegationCredential>
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
**Parameters:** Same as `issue()` but `credentialStatus` is automatically generated.
|
|
124
|
-
|
|
125
|
-
**Returns:** `Promise<DelegationCredential>` - The issued delegation credential with status
|
|
126
|
-
|
|
127
|
-
**Example:**
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
const delegation = await issuer.issueWithStatus({
|
|
131
|
-
subjectDid: 'did:key:z6MkrWXJPkxPCuQF7RqeKZFdZqBXz3oCG7PUty5dXLKGzELj',
|
|
132
|
-
constraints: {
|
|
133
|
-
scope: {
|
|
134
|
-
allowedTools: ['read_file'],
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// Automatically includes credentialStatus field
|
|
140
|
-
console.log('Status index:', delegation.credentialStatus?.statusListIndex);
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
---
|
|
144
|
-
|
|
145
|
-
### DelegationVerifier
|
|
146
|
-
|
|
147
|
-
Verifies delegation credentials.
|
|
148
|
-
|
|
149
|
-
#### Constructor
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
new DelegationVerifier(options?: DelegationVerifierOptions)
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
**Parameters:**
|
|
156
|
-
|
|
157
|
-
| Name | Type | Description |
|
|
158
|
-
|------|------|-------------|
|
|
159
|
-
| `options.didResolver?` | `DIDResolver` | Custom DID resolver |
|
|
160
|
-
| `options.statusListFetcher?` | `StatusListFetcher` | Custom status list fetcher |
|
|
161
|
-
| `options.checkStatus?` | `boolean` | Enable status checking (default: true) |
|
|
162
|
-
| `options.checkExpiration?` | `boolean` | Enable expiration checking (default: true) |
|
|
163
|
-
|
|
164
|
-
**Example:**
|
|
165
|
-
|
|
166
|
-
```typescript
|
|
167
|
-
import { DelegationVerifier } from '@kya-os/mcp-i-core';
|
|
168
|
-
|
|
169
|
-
const verifier = new DelegationVerifier({
|
|
170
|
-
checkStatus: true,
|
|
171
|
-
checkExpiration: true,
|
|
172
|
-
});
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
#### Methods
|
|
176
|
-
|
|
177
|
-
##### `verify()`
|
|
178
|
-
|
|
179
|
-
Verify a delegation credential.
|
|
180
|
-
|
|
181
|
-
```typescript
|
|
182
|
-
async verify(options: DelegationVerificationOptions): Promise<DelegationVerificationResult>
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
**Parameters:**
|
|
186
|
-
|
|
187
|
-
| Name | Type | Description |
|
|
188
|
-
|------|------|-------------|
|
|
189
|
-
| `options.credential` | `DelegationCredential` | The delegation to verify |
|
|
190
|
-
| `options.expectedAudience?` | `string` | Expected audience (must match) |
|
|
191
|
-
| `options.expectedSubject?` | `string` | Expected subject DID (must match) |
|
|
192
|
-
| `options.checkChain?` | `boolean` | Verify entire delegation chain |
|
|
193
|
-
| `options.now?` | `Date` | Current time for expiration checks |
|
|
194
|
-
|
|
195
|
-
**Returns:** `Promise<DelegationVerificationResult>` - Verification result
|
|
196
|
-
|
|
197
|
-
**Example:**
|
|
198
|
-
|
|
199
|
-
```typescript
|
|
200
|
-
const result = await verifier.verify({
|
|
201
|
-
credential: delegation,
|
|
202
|
-
expectedAudience: 'https://api.example.com',
|
|
203
|
-
checkChain: true,
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
if (result.verified) {
|
|
207
|
-
console.log('✅ Delegation is valid');
|
|
208
|
-
console.log('Subject:', result.subject);
|
|
209
|
-
console.log('Issuer:', result.issuer);
|
|
210
|
-
console.log('Constraints:', result.constraints);
|
|
211
|
-
} else {
|
|
212
|
-
console.error('❌ Verification failed:', result.error);
|
|
213
|
-
if (result.statusRevoked) {
|
|
214
|
-
console.error(' Reason: Credential revoked');
|
|
215
|
-
}
|
|
216
|
-
if (result.expired) {
|
|
217
|
-
console.error(' Reason: Credential expired');
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
##### `verifyChain()`
|
|
223
|
-
|
|
224
|
-
Verify a complete delegation chain.
|
|
225
|
-
|
|
226
|
-
```typescript
|
|
227
|
-
async verifyChain(delegation: DelegationCredential): Promise<ChainVerificationResult>
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
**Parameters:**
|
|
231
|
-
|
|
232
|
-
| Name | Type | Description |
|
|
233
|
-
|------|------|-------------|
|
|
234
|
-
| `delegation` | `DelegationCredential` | The delegation at the end of the chain |
|
|
235
|
-
|
|
236
|
-
**Returns:** `Promise<ChainVerificationResult>` - Chain verification result
|
|
237
|
-
|
|
238
|
-
**Example:**
|
|
239
|
-
|
|
240
|
-
```typescript
|
|
241
|
-
// Verify multi-level delegation chain
|
|
242
|
-
const result = await verifier.verifyChain(leafDelegation);
|
|
243
|
-
|
|
244
|
-
if (result.valid) {
|
|
245
|
-
console.log('✅ Chain is valid');
|
|
246
|
-
console.log('Chain length:', result.chain.length);
|
|
247
|
-
console.log('Root issuer:', result.rootIssuer);
|
|
248
|
-
|
|
249
|
-
// Print chain
|
|
250
|
-
for (const [i, delegation] of result.chain.entries()) {
|
|
251
|
-
console.log(` Level ${i}: ${delegation.issuer} → ${delegation.credentialSubject.id}`);
|
|
252
|
-
}
|
|
253
|
-
} else {
|
|
254
|
-
console.error('❌ Chain verification failed');
|
|
255
|
-
console.error(' Invalid at level:', result.invalidAtLevel);
|
|
256
|
-
console.error(' Reason:', result.error);
|
|
257
|
-
}
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
---
|
|
261
|
-
|
|
262
|
-
### DelegationGraph
|
|
263
|
-
|
|
264
|
-
Manages delegation relationships and cascading revocation.
|
|
265
|
-
|
|
266
|
-
#### Constructor
|
|
267
|
-
|
|
268
|
-
```typescript
|
|
269
|
-
new DelegationGraph(options?: DelegationGraphOptions)
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
**Parameters:**
|
|
273
|
-
|
|
274
|
-
| Name | Type | Description |
|
|
275
|
-
|------|------|-------------|
|
|
276
|
-
| `options.storage?` | `GraphStorage` | Custom graph storage backend |
|
|
277
|
-
|
|
278
|
-
**Example:**
|
|
279
|
-
|
|
280
|
-
```typescript
|
|
281
|
-
import { DelegationGraph } from '@kya-os/mcp-i-core';
|
|
282
|
-
|
|
283
|
-
const graph = new DelegationGraph();
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
#### Methods
|
|
287
|
-
|
|
288
|
-
##### `addDelegation()`
|
|
289
|
-
|
|
290
|
-
Add a delegation to the graph.
|
|
291
|
-
|
|
292
|
-
```typescript
|
|
293
|
-
async addDelegation(delegation: DelegationCredential): Promise<void>
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
**Parameters:**
|
|
297
|
-
|
|
298
|
-
| Name | Type | Description |
|
|
299
|
-
|------|------|-------------|
|
|
300
|
-
| `delegation` | `DelegationCredential` | The delegation to add |
|
|
301
|
-
|
|
302
|
-
**Example:**
|
|
303
|
-
|
|
304
|
-
```typescript
|
|
305
|
-
// Build delegation graph
|
|
306
|
-
await graph.addDelegation(parentDelegation);
|
|
307
|
-
await graph.addDelegation(childDelegation1);
|
|
308
|
-
await graph.addDelegation(childDelegation2);
|
|
309
|
-
|
|
310
|
-
console.log('Graph size:', await graph.size());
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
##### `getChildren()`
|
|
314
|
-
|
|
315
|
-
Get all direct children of a delegation.
|
|
316
|
-
|
|
317
|
-
```typescript
|
|
318
|
-
async getChildren(delegationId: string): Promise<DelegationCredential[]>
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
**Parameters:**
|
|
322
|
-
|
|
323
|
-
| Name | Type | Description |
|
|
324
|
-
|------|------|-------------|
|
|
325
|
-
| `delegationId` | `string` | ID of the parent delegation |
|
|
326
|
-
|
|
327
|
-
**Returns:** `Promise<DelegationCredential[]>` - Array of child delegations
|
|
328
|
-
|
|
329
|
-
**Example:**
|
|
330
|
-
|
|
331
|
-
```typescript
|
|
332
|
-
const children = await graph.getChildren(parentDelegation.id);
|
|
333
|
-
console.log(`Found ${children.length} children`);
|
|
334
|
-
|
|
335
|
-
for (const child of children) {
|
|
336
|
-
console.log(` - ${child.id} (issued to ${child.credentialSubject.id})`);
|
|
337
|
-
}
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
##### `getDescendants()`
|
|
341
|
-
|
|
342
|
-
Get all descendants (recursive) of a delegation.
|
|
343
|
-
|
|
344
|
-
```typescript
|
|
345
|
-
async getDescendants(delegationId: string): Promise<DelegationCredential[]>
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
**Parameters:**
|
|
349
|
-
|
|
350
|
-
| Name | Type | Description |
|
|
351
|
-
|------|------|-------------|
|
|
352
|
-
| `delegationId` | `string` | ID of the ancestor delegation |
|
|
353
|
-
|
|
354
|
-
**Returns:** `Promise<DelegationCredential[]>` - Array of all descendants
|
|
355
|
-
|
|
356
|
-
**Example:**
|
|
357
|
-
|
|
358
|
-
```typescript
|
|
359
|
-
// Get entire subtree
|
|
360
|
-
const descendants = await graph.getDescendants(rootDelegation.id);
|
|
361
|
-
console.log(`Total descendants: ${descendants.length}`);
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
##### `revokeDelegation()`
|
|
365
|
-
|
|
366
|
-
Revoke a delegation and optionally all descendants.
|
|
367
|
-
|
|
368
|
-
```typescript
|
|
369
|
-
async revokeDelegation(
|
|
370
|
-
delegationId: string,
|
|
371
|
-
statusListManager: StatusList2021Manager,
|
|
372
|
-
options?: RevocationOptions
|
|
373
|
-
): Promise<RevocationResult>
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
**Parameters:**
|
|
377
|
-
|
|
378
|
-
| Name | Type | Description |
|
|
379
|
-
|------|------|-------------|
|
|
380
|
-
| `delegationId` | `string` | ID of delegation to revoke |
|
|
381
|
-
| `statusListManager` | `StatusList2021Manager` | Status list manager |
|
|
382
|
-
| `options.cascade?` | `boolean` | Revoke all descendants (default: true) |
|
|
383
|
-
|
|
384
|
-
**Returns:** `Promise<RevocationResult>` - Revocation result with list of revoked IDs
|
|
385
|
-
|
|
386
|
-
**Example:**
|
|
387
|
-
|
|
388
|
-
```typescript
|
|
389
|
-
// Revoke parent and all children
|
|
390
|
-
const result = await graph.revokeDelegation(
|
|
391
|
-
parentDelegation.id,
|
|
392
|
-
statusListManager,
|
|
393
|
-
{ cascade: true }
|
|
394
|
-
);
|
|
395
|
-
|
|
396
|
-
console.log('Revoked delegations:', result.revokedIds.length);
|
|
397
|
-
for (const id of result.revokedIds) {
|
|
398
|
-
console.log(` - ${id}`);
|
|
399
|
-
}
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
##### `getPath()`
|
|
403
|
-
|
|
404
|
-
Get the path from root to a delegation.
|
|
405
|
-
|
|
406
|
-
```typescript
|
|
407
|
-
async getPath(delegationId: string): Promise<DelegationCredential[]>
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
**Parameters:**
|
|
411
|
-
|
|
412
|
-
| Name | Type | Description |
|
|
413
|
-
|------|------|-------------|
|
|
414
|
-
| `delegationId` | `string` | ID of target delegation |
|
|
415
|
-
|
|
416
|
-
**Returns:** `Promise<DelegationCredential[]>` - Array of delegations from root to target
|
|
417
|
-
|
|
418
|
-
**Example:**
|
|
419
|
-
|
|
420
|
-
```typescript
|
|
421
|
-
const path = await graph.getPath(leafDelegation.id);
|
|
422
|
-
|
|
423
|
-
console.log('Delegation chain:');
|
|
424
|
-
for (const [i, delegation] of path.entries()) {
|
|
425
|
-
console.log(` ${i + 1}. ${delegation.issuer} → ${delegation.credentialSubject.id}`);
|
|
426
|
-
}
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
---
|
|
430
|
-
|
|
431
|
-
## StatusList2021
|
|
432
|
-
|
|
433
|
-
### StatusList2021Manager
|
|
434
|
-
|
|
435
|
-
Manages StatusList2021 credentials for revocation.
|
|
436
|
-
|
|
437
|
-
#### Constructor
|
|
438
|
-
|
|
439
|
-
```typescript
|
|
440
|
-
new StatusList2021Manager(options: StatusList2021ManagerOptions)
|
|
441
|
-
```
|
|
442
|
-
|
|
443
|
-
**Parameters:**
|
|
444
|
-
|
|
445
|
-
| Name | Type | Description |
|
|
446
|
-
|------|------|-------------|
|
|
447
|
-
| `options.issuerDid` | `string` | DID of the status list issuer |
|
|
448
|
-
| `options.statusListUrl` | `string` | Public URL where status list will be hosted |
|
|
449
|
-
| `options.storage` | `StatusList2021Storage` | Storage backend for bitstrings |
|
|
450
|
-
| `options.privateKeyJwk?` | `JsonWebKey` | Private key for signing status lists |
|
|
451
|
-
|
|
452
|
-
**Example:**
|
|
453
|
-
|
|
454
|
-
```typescript
|
|
455
|
-
import { StatusList2021Manager, InMemoryStatusListStorage } from '@kya-os/mcp-i-core';
|
|
456
|
-
|
|
457
|
-
const manager = new StatusList2021Manager({
|
|
458
|
-
issuerDid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
|
|
459
|
-
statusListUrl: 'https://issuer.example.com/status/1',
|
|
460
|
-
storage: new InMemoryStatusListStorage(),
|
|
461
|
-
privateKeyJwk: issuerPrivateKey,
|
|
462
|
-
});
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
#### Methods
|
|
466
|
-
|
|
467
|
-
##### `createStatusList()`
|
|
468
|
-
|
|
469
|
-
Create a new status list credential.
|
|
470
|
-
|
|
471
|
-
```typescript
|
|
472
|
-
async createStatusList(options: CreateStatusListOptions): Promise<StatusListCredential>
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
**Parameters:**
|
|
476
|
-
|
|
477
|
-
| Name | Type | Description |
|
|
478
|
-
|------|------|-------------|
|
|
479
|
-
| `options.id` | `string` | Status list credential ID (URL) |
|
|
480
|
-
| `options.purpose` | `'revocation' \| 'suspension'` | Purpose of the status list |
|
|
481
|
-
| `options.length?` | `number` | Initial bitstring length (default: 131072) |
|
|
482
|
-
|
|
483
|
-
**Returns:** `Promise<StatusListCredential>` - The status list credential
|
|
484
|
-
|
|
485
|
-
**Example:**
|
|
486
|
-
|
|
487
|
-
```typescript
|
|
488
|
-
const statusListVC = await manager.createStatusList({
|
|
489
|
-
id: 'https://issuer.example.com/status/1',
|
|
490
|
-
purpose: 'revocation',
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
console.log('Status list created:', statusListVC.id);
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
##### `allocateIndex()`
|
|
497
|
-
|
|
498
|
-
Allocate the next available index in the status list.
|
|
499
|
-
|
|
500
|
-
```typescript
|
|
501
|
-
async allocateIndex(): Promise<number>
|
|
502
|
-
```
|
|
503
|
-
|
|
504
|
-
**Returns:** `Promise<number>` - The allocated index
|
|
505
|
-
|
|
506
|
-
**Example:**
|
|
507
|
-
|
|
508
|
-
```typescript
|
|
509
|
-
const index = await manager.allocateIndex();
|
|
510
|
-
console.log('Allocated index:', index);
|
|
511
|
-
|
|
512
|
-
// Use in credential
|
|
513
|
-
const credentialStatus = {
|
|
514
|
-
id: `${statusListUrl}#${index}`,
|
|
515
|
-
type: 'StatusList2021Entry',
|
|
516
|
-
statusPurpose: 'revocation',
|
|
517
|
-
statusListIndex: index.toString(),
|
|
518
|
-
statusListCredential: statusListUrl,
|
|
519
|
-
};
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
##### `revokeCredential()`
|
|
523
|
-
|
|
524
|
-
Revoke a credential by setting its status list bit to 1.
|
|
525
|
-
|
|
526
|
-
```typescript
|
|
527
|
-
async revokeCredential(index: number): Promise<void>
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
**Parameters:**
|
|
531
|
-
|
|
532
|
-
| Name | Type | Description |
|
|
533
|
-
|------|------|-------------|
|
|
534
|
-
| `index` | `number` | Status list index to revoke |
|
|
535
|
-
|
|
536
|
-
**Example:**
|
|
537
|
-
|
|
538
|
-
```typescript
|
|
539
|
-
await manager.revokeCredential(42);
|
|
540
|
-
console.log('Credential at index 42 revoked');
|
|
541
|
-
```
|
|
542
|
-
|
|
543
|
-
##### `unrevokeCredential()`
|
|
544
|
-
|
|
545
|
-
Unrevoke a credential by setting its status list bit to 0.
|
|
546
|
-
|
|
547
|
-
```typescript
|
|
548
|
-
async unrevokeCredential(index: number): Promise<void>
|
|
549
|
-
```
|
|
550
|
-
|
|
551
|
-
**Parameters:**
|
|
552
|
-
|
|
553
|
-
| Name | Type | Description |
|
|
554
|
-
|------|------|-------------|
|
|
555
|
-
| `index` | `number` | Status list index to unrevoke |
|
|
556
|
-
|
|
557
|
-
**Example:**
|
|
558
|
-
|
|
559
|
-
```typescript
|
|
560
|
-
await manager.unrevokeCredential(42);
|
|
561
|
-
console.log('Credential at index 42 restored');
|
|
562
|
-
```
|
|
563
|
-
|
|
564
|
-
##### `batchRevoke()`
|
|
565
|
-
|
|
566
|
-
Revoke multiple credentials atomically.
|
|
567
|
-
|
|
568
|
-
```typescript
|
|
569
|
-
async batchRevoke(indexes: number[]): Promise<void>
|
|
570
|
-
```
|
|
571
|
-
|
|
572
|
-
**Parameters:**
|
|
573
|
-
|
|
574
|
-
| Name | Type | Description |
|
|
575
|
-
|------|------|-------------|
|
|
576
|
-
| `indexes` | `number[]` | Array of indexes to revoke |
|
|
577
|
-
|
|
578
|
-
**Example:**
|
|
579
|
-
|
|
580
|
-
```typescript
|
|
581
|
-
await manager.batchRevoke([42, 100, 250, 1337]);
|
|
582
|
-
console.log('4 credentials revoked');
|
|
583
|
-
```
|
|
584
|
-
|
|
585
|
-
##### `checkStatus()`
|
|
586
|
-
|
|
587
|
-
Check if a credential is revoked.
|
|
588
|
-
|
|
589
|
-
```typescript
|
|
590
|
-
async checkStatus(index: number): Promise<boolean>
|
|
591
|
-
```
|
|
592
|
-
|
|
593
|
-
**Parameters:**
|
|
594
|
-
|
|
595
|
-
| Name | Type | Description |
|
|
596
|
-
|------|------|-------------|
|
|
597
|
-
| `index` | `number` | Status list index to check |
|
|
598
|
-
|
|
599
|
-
**Returns:** `Promise<boolean>` - `true` if revoked, `false` if valid
|
|
600
|
-
|
|
601
|
-
**Example:**
|
|
602
|
-
|
|
603
|
-
```typescript
|
|
604
|
-
const isRevoked = await manager.checkStatus(42);
|
|
605
|
-
if (isRevoked) {
|
|
606
|
-
console.log('Credential is revoked');
|
|
607
|
-
} else {
|
|
608
|
-
console.log('Credential is valid');
|
|
609
|
-
}
|
|
610
|
-
```
|
|
611
|
-
|
|
612
|
-
##### `getStatusList()`
|
|
613
|
-
|
|
614
|
-
Get the current status list credential.
|
|
615
|
-
|
|
616
|
-
```typescript
|
|
617
|
-
async getStatusList(url: string): Promise<StatusListCredential>
|
|
618
|
-
```
|
|
619
|
-
|
|
620
|
-
**Parameters:**
|
|
621
|
-
|
|
622
|
-
| Name | Type | Description |
|
|
623
|
-
|------|------|-------------|
|
|
624
|
-
| `url` | `string` | Status list URL |
|
|
625
|
-
|
|
626
|
-
**Returns:** `Promise<StatusListCredential>` - The status list credential
|
|
627
|
-
|
|
628
|
-
**Example:**
|
|
629
|
-
|
|
630
|
-
```typescript
|
|
631
|
-
const statusListVC = await manager.getStatusList(
|
|
632
|
-
'https://issuer.example.com/status/1'
|
|
633
|
-
);
|
|
634
|
-
|
|
635
|
-
console.log('Encoded bitstring:', statusListVC.credentialSubject.encodedList);
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
##### `getMetrics()`
|
|
639
|
-
|
|
640
|
-
Get status list metrics.
|
|
641
|
-
|
|
642
|
-
```typescript
|
|
643
|
-
async getMetrics(): Promise<StatusListMetrics>
|
|
644
|
-
```
|
|
645
|
-
|
|
646
|
-
**Returns:** `Promise<StatusListMetrics>` - Status list metrics
|
|
647
|
-
|
|
648
|
-
**Example:**
|
|
649
|
-
|
|
650
|
-
```typescript
|
|
651
|
-
const metrics = await manager.getMetrics();
|
|
652
|
-
|
|
653
|
-
console.log('Metrics:', {
|
|
654
|
-
allocatedIndexes: metrics.allocatedIndexes,
|
|
655
|
-
revokedCount: metrics.revokedCount,
|
|
656
|
-
revocationRate: (metrics.revokedCount / metrics.allocatedIndexes * 100).toFixed(2) + '%',
|
|
657
|
-
compressedSize: (metrics.compressedSize / 1024).toFixed(2) + 'KB',
|
|
658
|
-
compressionRatio: (metrics.uncompressedSize / metrics.compressedSize).toFixed(2) + 'x',
|
|
659
|
-
});
|
|
660
|
-
```
|
|
661
|
-
|
|
662
|
-
---
|
|
663
|
-
|
|
664
|
-
### StatusList2021Storage
|
|
665
|
-
|
|
666
|
-
Storage interface for status list bitstrings.
|
|
667
|
-
|
|
668
|
-
#### Interface
|
|
669
|
-
|
|
670
|
-
```typescript
|
|
671
|
-
interface StatusList2021Storage {
|
|
672
|
-
getBitstring(statusListId: string): Promise<Uint8Array | null>;
|
|
673
|
-
setBitstring(statusListId: string, bitstring: Uint8Array): Promise<void>;
|
|
674
|
-
deleteBitstring(statusListId: string): Promise<void>;
|
|
675
|
-
}
|
|
676
|
-
```
|
|
677
|
-
|
|
678
|
-
#### Implementations
|
|
679
|
-
|
|
680
|
-
##### InMemoryStatusListStorage
|
|
681
|
-
|
|
682
|
-
In-memory storage (for development/testing).
|
|
683
|
-
|
|
684
|
-
```typescript
|
|
685
|
-
import { InMemoryStatusListStorage } from '@kya-os/mcp-i-core';
|
|
686
|
-
|
|
687
|
-
const storage = new InMemoryStatusListStorage();
|
|
688
|
-
```
|
|
689
|
-
|
|
690
|
-
##### RedisStatusListStorage
|
|
691
|
-
|
|
692
|
-
Redis-backed storage (for production).
|
|
693
|
-
|
|
694
|
-
```typescript
|
|
695
|
-
import { RedisStatusListStorage } from '@kya-os/mcp-i-core';
|
|
696
|
-
import Redis from 'ioredis';
|
|
697
|
-
|
|
698
|
-
const redis = new Redis(process.env.REDIS_URL);
|
|
699
|
-
const storage = new RedisStatusListStorage({
|
|
700
|
-
client: redis,
|
|
701
|
-
keyPrefix: 'statuslist:',
|
|
702
|
-
ttl: 86400, // 24 hours
|
|
703
|
-
});
|
|
704
|
-
```
|
|
705
|
-
|
|
706
|
-
##### DynamoDBStatusListStorage
|
|
707
|
-
|
|
708
|
-
AWS DynamoDB storage (for production).
|
|
709
|
-
|
|
710
|
-
```typescript
|
|
711
|
-
import { DynamoDBStatusListStorage } from '@kya-os/mcp-i-core';
|
|
712
|
-
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
713
|
-
|
|
714
|
-
const dynamodb = new DynamoDBClient({ region: 'us-east-1' });
|
|
715
|
-
const storage = new DynamoDBStatusListStorage({
|
|
716
|
-
client: dynamodb,
|
|
717
|
-
tableName: 'StatusLists',
|
|
718
|
-
ttl: 86400,
|
|
719
|
-
});
|
|
720
|
-
```
|
|
721
|
-
|
|
722
|
-
---
|
|
723
|
-
|
|
724
|
-
## Schema Verification
|
|
725
|
-
|
|
726
|
-
### SchemaVerifier
|
|
727
|
-
|
|
728
|
-
Verifies implementations against JSON Schema draft-07 schemas.
|
|
729
|
-
|
|
730
|
-
#### Constructor
|
|
731
|
-
|
|
732
|
-
```typescript
|
|
733
|
-
new SchemaVerifier(options?: SchemaVerifierOptions)
|
|
734
|
-
```
|
|
735
|
-
|
|
736
|
-
**Parameters:**
|
|
737
|
-
|
|
738
|
-
| Name | Type | Description |
|
|
739
|
-
|------|------|-------------|
|
|
740
|
-
| `options.schemaRegistry?` | `SchemaRegistry` | Custom schema registry |
|
|
741
|
-
| `options.strictMode?` | `boolean` | Enable strict validation (default: true) |
|
|
742
|
-
|
|
743
|
-
**Example:**
|
|
744
|
-
|
|
745
|
-
```typescript
|
|
746
|
-
import { SchemaVerifier } from '@kya-os/mcp-i-core';
|
|
747
|
-
|
|
748
|
-
const verifier = new SchemaVerifier({
|
|
749
|
-
strictMode: true,
|
|
750
|
-
});
|
|
751
|
-
```
|
|
752
|
-
|
|
753
|
-
#### Methods
|
|
754
|
-
|
|
755
|
-
##### `registerSchema()`
|
|
756
|
-
|
|
757
|
-
Register a schema for validation.
|
|
758
|
-
|
|
759
|
-
```typescript
|
|
760
|
-
async registerSchema(name: string, schemaUrl: string): Promise<void>
|
|
761
|
-
```
|
|
762
|
-
|
|
763
|
-
**Parameters:**
|
|
764
|
-
|
|
765
|
-
| Name | Type | Description |
|
|
766
|
-
|------|------|-------------|
|
|
767
|
-
| `name` | `string` | Schema identifier |
|
|
768
|
-
| `schemaUrl` | `string` | URL to JSON Schema |
|
|
769
|
-
|
|
770
|
-
**Example:**
|
|
771
|
-
|
|
772
|
-
```typescript
|
|
773
|
-
await verifier.registerSchema(
|
|
774
|
-
'delegation-credential',
|
|
775
|
-
'https://schemas.kya-os.ai/delegation-credential.schema.json'
|
|
776
|
-
);
|
|
777
|
-
```
|
|
778
|
-
|
|
779
|
-
##### `verifySchema()`
|
|
780
|
-
|
|
781
|
-
Verify an implementation against a registered schema.
|
|
782
|
-
|
|
783
|
-
```typescript
|
|
784
|
-
async verifySchema(schemaName: string, implementation: any): Promise<SchemaComplianceReport>
|
|
785
|
-
```
|
|
786
|
-
|
|
787
|
-
**Parameters:**
|
|
788
|
-
|
|
789
|
-
| Name | Type | Description |
|
|
790
|
-
|------|------|-------------|
|
|
791
|
-
| `schemaName` | `string` | Registered schema name |
|
|
792
|
-
| `implementation` | `any` | Implementation to verify |
|
|
793
|
-
|
|
794
|
-
**Returns:** `Promise<SchemaComplianceReport>` - Compliance report
|
|
795
|
-
|
|
796
|
-
**Example:**
|
|
797
|
-
|
|
798
|
-
```typescript
|
|
799
|
-
const report = await verifier.verifySchema('delegation-credential', myDelegation);
|
|
800
|
-
|
|
801
|
-
if (report.compliant) {
|
|
802
|
-
console.log('✅ 100% compliant');
|
|
803
|
-
} else {
|
|
804
|
-
console.log(`❌ ${report.compliancePercentage}% compliant`);
|
|
805
|
-
|
|
806
|
-
// Show issues
|
|
807
|
-
console.log('Missing fields:', report.missingFields);
|
|
808
|
-
|
|
809
|
-
for (const [field, result] of Object.entries(report.fieldCompliance)) {
|
|
810
|
-
if (result.typeMatch === 'mismatch') {
|
|
811
|
-
console.log(`Field '${field}':`);
|
|
812
|
-
console.log(` Expected: ${result.expectedType}`);
|
|
813
|
-
console.log(` Actual: ${result.actualType}`);
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
```
|
|
818
|
-
|
|
819
|
-
##### `verifyAll()`
|
|
820
|
-
|
|
821
|
-
Verify implementation against multiple schemas.
|
|
822
|
-
|
|
823
|
-
```typescript
|
|
824
|
-
async verifyAll(
|
|
825
|
-
schemas: string[],
|
|
826
|
-
implementation: any
|
|
827
|
-
): Promise<FullComplianceReport>
|
|
828
|
-
```
|
|
829
|
-
|
|
830
|
-
**Parameters:**
|
|
831
|
-
|
|
832
|
-
| Name | Type | Description |
|
|
833
|
-
|------|------|-------------|
|
|
834
|
-
| `schemas` | `string[]` | Array of schema names |
|
|
835
|
-
| `implementation` | `any` | Implementation to verify |
|
|
836
|
-
|
|
837
|
-
**Returns:** `Promise<FullComplianceReport>` - Compliance report for all schemas
|
|
838
|
-
|
|
839
|
-
**Example:**
|
|
840
|
-
|
|
841
|
-
```typescript
|
|
842
|
-
const report = await verifier.verifyAll(
|
|
843
|
-
['delegation-credential', 'delegation-constraints'],
|
|
844
|
-
myDelegation
|
|
845
|
-
);
|
|
846
|
-
|
|
847
|
-
console.log(`Overall compliance: ${report.overallCompliance}%`);
|
|
848
|
-
|
|
849
|
-
for (const [schema, result] of Object.entries(report.schemaResults)) {
|
|
850
|
-
console.log(`${schema}: ${result.compliancePercentage}%`);
|
|
851
|
-
}
|
|
852
|
-
```
|
|
853
|
-
|
|
854
|
-
---
|
|
855
|
-
|
|
856
|
-
### SchemaRegistry
|
|
857
|
-
|
|
858
|
-
Registry for managing schemas.
|
|
859
|
-
|
|
860
|
-
#### Constructor
|
|
861
|
-
|
|
862
|
-
```typescript
|
|
863
|
-
new SchemaRegistry(options?: SchemaRegistryOptions)
|
|
864
|
-
```
|
|
865
|
-
|
|
866
|
-
**Example:**
|
|
867
|
-
|
|
868
|
-
```typescript
|
|
869
|
-
import { SchemaRegistry } from '@kya-os/mcp-i-core';
|
|
870
|
-
|
|
871
|
-
const registry = new SchemaRegistry();
|
|
872
|
-
```
|
|
873
|
-
|
|
874
|
-
#### Methods
|
|
875
|
-
|
|
876
|
-
##### `register()`
|
|
877
|
-
|
|
878
|
-
Register a schema.
|
|
879
|
-
|
|
880
|
-
```typescript
|
|
881
|
-
async register(name: string, schema: any): Promise<void>
|
|
882
|
-
```
|
|
883
|
-
|
|
884
|
-
##### `get()`
|
|
885
|
-
|
|
886
|
-
Get a registered schema.
|
|
887
|
-
|
|
888
|
-
```typescript
|
|
889
|
-
async get(name: string): Promise<any>
|
|
890
|
-
```
|
|
891
|
-
|
|
892
|
-
##### `has()`
|
|
893
|
-
|
|
894
|
-
Check if schema is registered.
|
|
895
|
-
|
|
896
|
-
```typescript
|
|
897
|
-
async has(name: string): Promise<boolean>
|
|
898
|
-
```
|
|
899
|
-
|
|
900
|
-
##### `list()`
|
|
901
|
-
|
|
902
|
-
List all registered schemas.
|
|
903
|
-
|
|
904
|
-
```typescript
|
|
905
|
-
async list(): Promise<string[]>
|
|
906
|
-
```
|
|
907
|
-
|
|
908
|
-
---
|
|
909
|
-
|
|
910
|
-
## Types
|
|
911
|
-
|
|
912
|
-
### DelegationCredential
|
|
913
|
-
|
|
914
|
-
W3C Verifiable Credential for delegation.
|
|
915
|
-
|
|
916
|
-
```typescript
|
|
917
|
-
interface DelegationCredential {
|
|
918
|
-
'@context': string[];
|
|
919
|
-
id: string;
|
|
920
|
-
type: string[];
|
|
921
|
-
issuer: string;
|
|
922
|
-
issuanceDate: string;
|
|
923
|
-
expirationDate?: string;
|
|
924
|
-
credentialSubject: {
|
|
925
|
-
id: string;
|
|
926
|
-
constraints: DelegationConstraints;
|
|
927
|
-
};
|
|
928
|
-
credentialStatus?: CredentialStatus;
|
|
929
|
-
proof: Ed25519Proof;
|
|
930
|
-
}
|
|
931
|
-
```
|
|
932
|
-
|
|
933
|
-
### DelegationConstraints
|
|
934
|
-
|
|
935
|
-
CRISP constraints for delegation.
|
|
936
|
-
|
|
937
|
-
```typescript
|
|
938
|
-
interface DelegationConstraints {
|
|
939
|
-
// Cost constraints
|
|
940
|
-
budget?: {
|
|
941
|
-
maxCost: number;
|
|
942
|
-
currency: string;
|
|
943
|
-
};
|
|
944
|
-
|
|
945
|
-
// Resource constraints
|
|
946
|
-
resources?: {
|
|
947
|
-
maxRequests?: number;
|
|
948
|
-
maxTokens?: number;
|
|
949
|
-
maxStorage?: number;
|
|
950
|
-
};
|
|
951
|
-
|
|
952
|
-
// Identity constraints
|
|
953
|
-
identity?: {
|
|
954
|
-
requiredDid?: string;
|
|
955
|
-
allowedIssuers?: string[];
|
|
956
|
-
};
|
|
957
|
-
|
|
958
|
-
// Scope constraints
|
|
959
|
-
scope?: {
|
|
960
|
-
allowedTools?: string[];
|
|
961
|
-
allowedResources?: string[];
|
|
962
|
-
deniedTools?: string[];
|
|
963
|
-
deniedResources?: string[];
|
|
964
|
-
};
|
|
965
|
-
|
|
966
|
-
// Purpose constraints
|
|
967
|
-
purpose?: {
|
|
968
|
-
description: string;
|
|
969
|
-
category?: string;
|
|
970
|
-
};
|
|
971
|
-
|
|
972
|
-
// Time constraints
|
|
973
|
-
time?: {
|
|
974
|
-
notBefore?: string;
|
|
975
|
-
notAfter?: string;
|
|
976
|
-
maxDuration?: number;
|
|
977
|
-
};
|
|
978
|
-
}
|
|
979
|
-
```
|
|
980
|
-
|
|
981
|
-
### DelegationVerificationResult
|
|
982
|
-
|
|
983
|
-
Result of delegation verification.
|
|
984
|
-
|
|
985
|
-
```typescript
|
|
986
|
-
interface DelegationVerificationResult {
|
|
987
|
-
verified: boolean;
|
|
988
|
-
error?: string;
|
|
989
|
-
subject?: string;
|
|
990
|
-
issuer?: string;
|
|
991
|
-
constraints?: DelegationConstraints;
|
|
992
|
-
statusRevoked?: boolean;
|
|
993
|
-
expired?: boolean;
|
|
994
|
-
signatureValid?: boolean;
|
|
995
|
-
}
|
|
996
|
-
```
|
|
997
|
-
|
|
998
|
-
### CredentialStatus
|
|
999
|
-
|
|
1000
|
-
StatusList2021 credential status.
|
|
1001
|
-
|
|
1002
|
-
```typescript
|
|
1003
|
-
interface CredentialStatus {
|
|
1004
|
-
id: string;
|
|
1005
|
-
type: 'StatusList2021Entry';
|
|
1006
|
-
statusPurpose: 'revocation' | 'suspension';
|
|
1007
|
-
statusListIndex: string;
|
|
1008
|
-
statusListCredential: string;
|
|
1009
|
-
}
|
|
1010
|
-
```
|
|
1011
|
-
|
|
1012
|
-
### StatusListCredential
|
|
1013
|
-
|
|
1014
|
-
StatusList2021 credential.
|
|
1015
|
-
|
|
1016
|
-
```typescript
|
|
1017
|
-
interface StatusListCredential {
|
|
1018
|
-
'@context': string[];
|
|
1019
|
-
id: string;
|
|
1020
|
-
type: string[];
|
|
1021
|
-
issuer: string;
|
|
1022
|
-
issuanceDate: string;
|
|
1023
|
-
credentialSubject: {
|
|
1024
|
-
id: string;
|
|
1025
|
-
type: 'StatusList2021';
|
|
1026
|
-
statusPurpose: 'revocation' | 'suspension';
|
|
1027
|
-
encodedList: string;
|
|
1028
|
-
};
|
|
1029
|
-
proof: Ed25519Proof;
|
|
1030
|
-
}
|
|
1031
|
-
```
|
|
1032
|
-
|
|
1033
|
-
### SchemaComplianceReport
|
|
1034
|
-
|
|
1035
|
-
Schema compliance verification report.
|
|
1036
|
-
|
|
1037
|
-
```typescript
|
|
1038
|
-
interface SchemaComplianceReport {
|
|
1039
|
-
schemaName: string;
|
|
1040
|
-
schemaUrl: string;
|
|
1041
|
-
compliant: boolean;
|
|
1042
|
-
compliancePercentage: number;
|
|
1043
|
-
totalFields: number;
|
|
1044
|
-
compliantFields: number;
|
|
1045
|
-
fieldCompliance: Record<string, FieldComplianceResult>;
|
|
1046
|
-
missingFields: string[];
|
|
1047
|
-
extraFields: string[];
|
|
1048
|
-
typeMismatches: Record<string, { expected: string; actual: string }>;
|
|
1049
|
-
}
|
|
1050
|
-
```
|
|
1051
|
-
|
|
1052
|
-
### FieldComplianceResult
|
|
1053
|
-
|
|
1054
|
-
Field-level compliance result.
|
|
1055
|
-
|
|
1056
|
-
```typescript
|
|
1057
|
-
interface FieldComplianceResult {
|
|
1058
|
-
present: boolean;
|
|
1059
|
-
expectedType: string;
|
|
1060
|
-
actualType: string | null;
|
|
1061
|
-
typeMatch: 'match' | 'mismatch' | 'absent';
|
|
1062
|
-
valueMatch: 'match' | 'mismatch' | 'absent';
|
|
1063
|
-
}
|
|
1064
|
-
```
|
|
1065
|
-
|
|
1066
|
-
---
|
|
1067
|
-
|
|
1068
|
-
## Utilities
|
|
1069
|
-
|
|
1070
|
-
### `createSchemaVerifier()`
|
|
1071
|
-
|
|
1072
|
-
Factory function to create a SchemaVerifier with default settings.
|
|
1073
|
-
|
|
1074
|
-
```typescript
|
|
1075
|
-
function createSchemaVerifier(options?: SchemaVerifierOptions): SchemaVerifier
|
|
1076
|
-
```
|
|
1077
|
-
|
|
1078
|
-
**Example:**
|
|
1079
|
-
|
|
1080
|
-
```typescript
|
|
1081
|
-
import { createSchemaVerifier } from '@kya-os/mcp-i-core';
|
|
1082
|
-
|
|
1083
|
-
const verifier = createSchemaVerifier();
|
|
1084
|
-
await verifier.registerSchema('my-schema', 'https://example.com/schema.json');
|
|
1085
|
-
```
|
|
1086
|
-
|
|
1087
|
-
### `verifyDelegation()`
|
|
1088
|
-
|
|
1089
|
-
Helper function to verify a delegation credential.
|
|
1090
|
-
|
|
1091
|
-
```typescript
|
|
1092
|
-
async function verifyDelegation(
|
|
1093
|
-
options: DelegationVerificationOptions
|
|
1094
|
-
): Promise<DelegationVerificationResult>
|
|
1095
|
-
```
|
|
1096
|
-
|
|
1097
|
-
**Example:**
|
|
1098
|
-
|
|
1099
|
-
```typescript
|
|
1100
|
-
import { verifyDelegation } from '@kya-os/mcp-i-core';
|
|
1101
|
-
|
|
1102
|
-
const result = await verifyDelegation({
|
|
1103
|
-
credential: delegation,
|
|
1104
|
-
expectedAudience: 'https://api.example.com',
|
|
1105
|
-
checkStatus: true,
|
|
1106
|
-
});
|
|
1107
|
-
|
|
1108
|
-
if (result.verified) {
|
|
1109
|
-
console.log('✅ Valid delegation');
|
|
1110
|
-
}
|
|
1111
|
-
```
|
|
1112
|
-
|
|
1113
|
-
### `parseDID()`
|
|
1114
|
-
|
|
1115
|
-
Parse a DID string into components.
|
|
1116
|
-
|
|
1117
|
-
```typescript
|
|
1118
|
-
function parseDID(did: string): ParsedDID
|
|
1119
|
-
```
|
|
1120
|
-
|
|
1121
|
-
**Example:**
|
|
1122
|
-
|
|
1123
|
-
```typescript
|
|
1124
|
-
import { parseDID } from '@kya-os/mcp-i-core';
|
|
1125
|
-
|
|
1126
|
-
const parsed = parseDID('did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK');
|
|
1127
|
-
|
|
1128
|
-
console.log({
|
|
1129
|
-
method: parsed.method, // 'key'
|
|
1130
|
-
id: parsed.id, // 'z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK'
|
|
1131
|
-
full: parsed.full, // full DID string
|
|
1132
|
-
});
|
|
1133
|
-
```
|
|
1134
|
-
|
|
1135
|
-
### `canonicalHash()`
|
|
1136
|
-
|
|
1137
|
-
Create a canonical hash of data.
|
|
1138
|
-
|
|
1139
|
-
```typescript
|
|
1140
|
-
async function canonicalHash(
|
|
1141
|
-
data: any,
|
|
1142
|
-
algorithm: 'sha256' | 'sha512'
|
|
1143
|
-
): Promise<string>
|
|
1144
|
-
```
|
|
1145
|
-
|
|
1146
|
-
**Example:**
|
|
1147
|
-
|
|
1148
|
-
```typescript
|
|
1149
|
-
import { canonicalHash } from '@kya-os/mcp-i-core';
|
|
1150
|
-
|
|
1151
|
-
const hash = await canonicalHash({ foo: 'bar' }, 'sha256');
|
|
1152
|
-
console.log(hash); // "sha256:abc123..."
|
|
1153
|
-
```
|
|
1154
|
-
|
|
1155
|
-
---
|
|
1156
|
-
|
|
1157
|
-
## Error Handling
|
|
1158
|
-
|
|
1159
|
-
All async methods may throw errors. Always use try-catch:
|
|
1160
|
-
|
|
1161
|
-
```typescript
|
|
1162
|
-
import { DelegationIssuer, DelegationError } from '@kya-os/mcp-i-core';
|
|
1163
|
-
|
|
1164
|
-
try {
|
|
1165
|
-
const delegation = await issuer.issue({
|
|
1166
|
-
subjectDid: 'did:key:z6Mkr...',
|
|
1167
|
-
constraints: { /* ... */ },
|
|
1168
|
-
});
|
|
1169
|
-
} catch (error) {
|
|
1170
|
-
if (error instanceof DelegationError) {
|
|
1171
|
-
console.error('Delegation error:', error.message);
|
|
1172
|
-
console.error('Code:', error.code);
|
|
1173
|
-
} else {
|
|
1174
|
-
console.error('Unexpected error:', error);
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
```
|
|
1178
|
-
|
|
1179
|
-
### Common Error Codes
|
|
1180
|
-
|
|
1181
|
-
| Code | Description |
|
|
1182
|
-
|------|-------------|
|
|
1183
|
-
| `INVALID_DID` | DID format is invalid |
|
|
1184
|
-
| `INVALID_CONSTRAINTS` | Constraints do not meet schema requirements |
|
|
1185
|
-
| `SIGNATURE_FAILED` | Cryptographic signature verification failed |
|
|
1186
|
-
| `STATUS_REVOKED` | Credential has been revoked |
|
|
1187
|
-
| `EXPIRED` | Credential has expired |
|
|
1188
|
-
| `CHAIN_INVALID` | Delegation chain verification failed |
|
|
1189
|
-
| `SCHEMA_INVALID` | Schema validation failed |
|
|
1190
|
-
| `STATUS_LIST_UNAVAILABLE` | Cannot fetch status list |
|
|
1191
|
-
|
|
1192
|
-
---
|
|
1193
|
-
|
|
1194
|
-
## Complete Examples
|
|
1195
|
-
|
|
1196
|
-
### Example 1: Full Delegation Lifecycle
|
|
1197
|
-
|
|
1198
|
-
```typescript
|
|
1199
|
-
import {
|
|
1200
|
-
DelegationIssuer,
|
|
1201
|
-
DelegationVerifier,
|
|
1202
|
-
StatusList2021Manager,
|
|
1203
|
-
InMemoryStatusListStorage,
|
|
1204
|
-
} from '@kya-os/mcp-i-core';
|
|
1205
|
-
|
|
1206
|
-
async function delegationLifecycle() {
|
|
1207
|
-
// 1. Setup
|
|
1208
|
-
const issuerDid = 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK';
|
|
1209
|
-
const delegateDid = 'did:key:z6MkrWXJPkxPCuQF7RqeKZFdZqBXz3oCG7PUty5dXLKGzELj';
|
|
1210
|
-
|
|
1211
|
-
// 2. Create status list manager
|
|
1212
|
-
const statusListManager = new StatusList2021Manager({
|
|
1213
|
-
issuerDid,
|
|
1214
|
-
statusListUrl: 'https://issuer.example.com/status/1',
|
|
1215
|
-
storage: new InMemoryStatusListStorage(),
|
|
1216
|
-
});
|
|
1217
|
-
|
|
1218
|
-
await statusListManager.createStatusList({
|
|
1219
|
-
id: 'https://issuer.example.com/status/1',
|
|
1220
|
-
purpose: 'revocation',
|
|
1221
|
-
});
|
|
1222
|
-
|
|
1223
|
-
// 3. Create issuer
|
|
1224
|
-
const issuer = new DelegationIssuer({
|
|
1225
|
-
issuerDid,
|
|
1226
|
-
privateKeyJwk: issuerPrivateKey,
|
|
1227
|
-
statusListManager,
|
|
1228
|
-
});
|
|
1229
|
-
|
|
1230
|
-
// 4. Issue delegation
|
|
1231
|
-
const delegation = await issuer.issueWithStatus({
|
|
1232
|
-
subjectDid: delegateDid,
|
|
1233
|
-
constraints: {
|
|
1234
|
-
scope: {
|
|
1235
|
-
allowedTools: ['read_file'],
|
|
1236
|
-
allowedResources: ['/documents/*'],
|
|
1237
|
-
},
|
|
1238
|
-
time: {
|
|
1239
|
-
notAfter: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
|
|
1240
|
-
},
|
|
1241
|
-
},
|
|
1242
|
-
});
|
|
1243
|
-
|
|
1244
|
-
console.log('✅ Delegation issued:', delegation.id);
|
|
1245
|
-
|
|
1246
|
-
// 5. Verify delegation
|
|
1247
|
-
const verifier = new DelegationVerifier();
|
|
1248
|
-
const result1 = await verifier.verify({
|
|
1249
|
-
credential: delegation,
|
|
1250
|
-
checkStatus: true,
|
|
1251
|
-
statusListFetcher: async (url) => {
|
|
1252
|
-
return await statusListManager.getStatusList(url);
|
|
1253
|
-
},
|
|
1254
|
-
});
|
|
1255
|
-
|
|
1256
|
-
console.log('✅ Verification 1:', result1.verified);
|
|
1257
|
-
|
|
1258
|
-
// 6. Revoke delegation
|
|
1259
|
-
const statusIndex = parseInt(delegation.credentialStatus!.statusListIndex);
|
|
1260
|
-
await statusListManager.revokeCredential(statusIndex);
|
|
1261
|
-
|
|
1262
|
-
console.log('🔒 Delegation revoked');
|
|
1263
|
-
|
|
1264
|
-
// 7. Verify again (should fail)
|
|
1265
|
-
const result2 = await verifier.verify({
|
|
1266
|
-
credential: delegation,
|
|
1267
|
-
checkStatus: true,
|
|
1268
|
-
statusListFetcher: async (url) => {
|
|
1269
|
-
return await statusListManager.getStatusList(url);
|
|
1270
|
-
},
|
|
1271
|
-
});
|
|
1272
|
-
|
|
1273
|
-
console.log('❌ Verification 2:', result2.verified); // false
|
|
1274
|
-
console.log(' Status revoked:', result2.statusRevoked); // true
|
|
1275
|
-
}
|
|
1276
|
-
```
|
|
1277
|
-
|
|
1278
|
-
### Example 2: Delegation Chains
|
|
1279
|
-
|
|
1280
|
-
```typescript
|
|
1281
|
-
import {
|
|
1282
|
-
DelegationIssuer,
|
|
1283
|
-
DelegationGraph,
|
|
1284
|
-
StatusList2021Manager,
|
|
1285
|
-
} from '@kya-os/mcp-i-core';
|
|
1286
|
-
|
|
1287
|
-
async function delegationChains() {
|
|
1288
|
-
const issuer = new DelegationIssuer({ /* ... */ });
|
|
1289
|
-
const graph = new DelegationGraph();
|
|
1290
|
-
const statusListManager = new StatusList2021Manager({ /* ... */ });
|
|
1291
|
-
|
|
1292
|
-
// Issue root delegation
|
|
1293
|
-
const root = await issuer.issue({
|
|
1294
|
-
subjectDid: 'did:key:alice',
|
|
1295
|
-
constraints: {
|
|
1296
|
-
scope: { allowedTools: ['*'] },
|
|
1297
|
-
},
|
|
1298
|
-
});
|
|
1299
|
-
|
|
1300
|
-
// Issue child delegation
|
|
1301
|
-
const child = await issuer.issue({
|
|
1302
|
-
subjectDid: 'did:key:bob',
|
|
1303
|
-
constraints: {
|
|
1304
|
-
scope: { allowedTools: ['read_file'] },
|
|
1305
|
-
},
|
|
1306
|
-
parentDelegation: root.id,
|
|
1307
|
-
});
|
|
1308
|
-
|
|
1309
|
-
// Issue grandchild delegation
|
|
1310
|
-
const grandchild = await issuer.issue({
|
|
1311
|
-
subjectDid: 'did:key:charlie',
|
|
1312
|
-
constraints: {
|
|
1313
|
-
scope: { allowedTools: ['read_file'] },
|
|
1314
|
-
},
|
|
1315
|
-
parentDelegation: child.id,
|
|
1316
|
-
});
|
|
1317
|
-
|
|
1318
|
-
// Build graph
|
|
1319
|
-
await graph.addDelegation(root);
|
|
1320
|
-
await graph.addDelegation(child);
|
|
1321
|
-
await graph.addDelegation(grandchild);
|
|
1322
|
-
|
|
1323
|
-
// Get chain
|
|
1324
|
-
const chain = await graph.getPath(grandchild.id);
|
|
1325
|
-
console.log('Chain length:', chain.length); // 3
|
|
1326
|
-
|
|
1327
|
-
// Revoke root (cascades to all children)
|
|
1328
|
-
await graph.revokeDelegation(root.id, statusListManager, { cascade: true });
|
|
1329
|
-
console.log('All delegations revoked');
|
|
1330
|
-
}
|
|
1331
|
-
```
|
|
1332
|
-
|
|
1333
|
-
---
|
|
1334
|
-
|
|
1335
|
-
## TypeScript Configuration
|
|
1336
|
-
|
|
1337
|
-
For best TypeScript experience, use these settings:
|
|
1338
|
-
|
|
1339
|
-
```json
|
|
1340
|
-
{
|
|
1341
|
-
"compilerOptions": {
|
|
1342
|
-
"target": "ES2020",
|
|
1343
|
-
"module": "commonjs",
|
|
1344
|
-
"lib": ["ES2020"],
|
|
1345
|
-
"strict": true,
|
|
1346
|
-
"esModuleInterop": true,
|
|
1347
|
-
"skipLibCheck": true,
|
|
1348
|
-
"forceConsistentCasingInFileNames": true,
|
|
1349
|
-
"resolveJsonModule": true
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
```
|
|
1353
|
-
|
|
1354
|
-
---
|
|
1355
|
-
|
|
1356
|
-
## Further Reading
|
|
1357
|
-
|
|
1358
|
-
- [W3C VC Delegation Guide](./W3C_VC_DELEGATION_GUIDE.md)
|
|
1359
|
-
- [StatusList2021 Guide](./STATUSLIST2021_GUIDE.md)
|
|
1360
|
-
- [Compliance Matrix](./COMPLIANCE_MATRIX.md)
|
|
1361
|
-
- [W3C Verifiable Credentials](https://www.w3.org/TR/vc-data-model/)
|
|
1362
|
-
- [W3C StatusList2021](https://www.w3.org/TR/vc-status-list-2021/)
|