@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
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Delegation Graph Manager
|
|
3
|
-
*
|
|
4
|
-
* Tracks parent-child relationships between delegation credentials.
|
|
5
|
-
* Critical for cascading revocation per Delegation-Revocation.md.
|
|
6
|
-
*
|
|
7
|
-
* SOLID Principles:
|
|
8
|
-
* - Single Responsibility: Only manages delegation relationships
|
|
9
|
-
* - Open/Closed: Extensible via storage provider interface
|
|
10
|
-
* - Liskov Substitution: Any storage provider can be used
|
|
11
|
-
* - Interface Segregation: Minimal graph operations interface
|
|
12
|
-
* - Dependency Inversion: Depends on storage abstraction
|
|
13
|
-
*
|
|
14
|
-
* Related Spec: MCP-I §4.4, Delegation Chains
|
|
15
|
-
* Python Reference: Delegation-Revocation.md:45-67
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Delegation node in the graph
|
|
20
|
-
*/
|
|
21
|
-
export interface DelegationNode {
|
|
22
|
-
/** Delegation credential ID */
|
|
23
|
-
id: string;
|
|
24
|
-
|
|
25
|
-
/** Parent delegation ID (null for root) */
|
|
26
|
-
parentId: string | null;
|
|
27
|
-
|
|
28
|
-
/** Child delegation IDs */
|
|
29
|
-
children: string[];
|
|
30
|
-
|
|
31
|
-
/** Issuer DID */
|
|
32
|
-
issuerDid: string;
|
|
33
|
-
|
|
34
|
-
/** Subject DID */
|
|
35
|
-
subjectDid: string;
|
|
36
|
-
|
|
37
|
-
/** Credential status reference (for revocation) */
|
|
38
|
-
credentialStatusId?: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Storage provider interface for delegation graphs
|
|
43
|
-
*
|
|
44
|
-
* Platform-specific implementations (CloudflareKV, DynamoDB, etc.)
|
|
45
|
-
*/
|
|
46
|
-
export interface DelegationGraphStorageProvider {
|
|
47
|
-
/**
|
|
48
|
-
* Get a delegation node by ID
|
|
49
|
-
*/
|
|
50
|
-
getNode(delegationId: string): Promise<DelegationNode | null>;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Save a delegation node
|
|
54
|
-
*/
|
|
55
|
-
setNode(node: DelegationNode): Promise<void>;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Get all children of a delegation
|
|
59
|
-
*/
|
|
60
|
-
getChildren(delegationId: string): Promise<DelegationNode[]>;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Get the full chain from root to this delegation
|
|
64
|
-
*/
|
|
65
|
-
getChain(delegationId: string): Promise<DelegationNode[]>;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Get all descendants (children, grandchildren, etc.)
|
|
69
|
-
*/
|
|
70
|
-
getDescendants(delegationId: string): Promise<DelegationNode[]>;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Delete a node (used for cleanup)
|
|
74
|
-
*/
|
|
75
|
-
deleteNode(delegationId: string): Promise<void>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Delegation Graph Manager
|
|
80
|
-
*
|
|
81
|
-
* Manages the tree/graph structure of delegations.
|
|
82
|
-
* Per Delegation-Revocation.md:
|
|
83
|
-
* - Track parent-child relationships
|
|
84
|
-
* - Support chain validation
|
|
85
|
-
* - Enable cascading revocation
|
|
86
|
-
*/
|
|
87
|
-
export class DelegationGraphManager {
|
|
88
|
-
constructor(private storage: DelegationGraphStorageProvider) {}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Register a new delegation in the graph
|
|
92
|
-
*
|
|
93
|
-
* @param delegation - The delegation to register
|
|
94
|
-
* @returns The created node
|
|
95
|
-
*/
|
|
96
|
-
async registerDelegation(params: {
|
|
97
|
-
id: string;
|
|
98
|
-
parentId: string | null;
|
|
99
|
-
issuerDid: string;
|
|
100
|
-
subjectDid: string;
|
|
101
|
-
credentialStatusId?: string;
|
|
102
|
-
}): Promise<DelegationNode> {
|
|
103
|
-
const node: DelegationNode = {
|
|
104
|
-
id: params.id,
|
|
105
|
-
parentId: params.parentId,
|
|
106
|
-
children: [],
|
|
107
|
-
issuerDid: params.issuerDid,
|
|
108
|
-
subjectDid: params.subjectDid,
|
|
109
|
-
credentialStatusId: params.credentialStatusId,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// Save the node
|
|
113
|
-
await this.storage.setNode(node);
|
|
114
|
-
|
|
115
|
-
// If has parent, add this as a child to parent
|
|
116
|
-
if (params.parentId) {
|
|
117
|
-
await this.addChildToParent(params.parentId, params.id);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return node;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Add a child to a parent node
|
|
125
|
-
*
|
|
126
|
-
* @param parentId - Parent delegation ID
|
|
127
|
-
* @param childId - Child delegation ID
|
|
128
|
-
*/
|
|
129
|
-
private async addChildToParent(
|
|
130
|
-
parentId: string,
|
|
131
|
-
childId: string
|
|
132
|
-
): Promise<void> {
|
|
133
|
-
const parent = await this.storage.getNode(parentId);
|
|
134
|
-
if (!parent) {
|
|
135
|
-
throw new Error(`Parent delegation not found: ${parentId}`);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Add child if not already present
|
|
139
|
-
if (!parent.children.includes(childId)) {
|
|
140
|
-
parent.children.push(childId);
|
|
141
|
-
await this.storage.setNode(parent);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Get a delegation node
|
|
147
|
-
*
|
|
148
|
-
* @param delegationId - The delegation ID
|
|
149
|
-
* @returns The node, or null if not found
|
|
150
|
-
*/
|
|
151
|
-
async getNode(delegationId: string): Promise<DelegationNode | null> {
|
|
152
|
-
return this.storage.getNode(delegationId);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Get all direct children of a delegation
|
|
157
|
-
*
|
|
158
|
-
* @param delegationId - The parent delegation ID
|
|
159
|
-
* @returns Array of child nodes
|
|
160
|
-
*/
|
|
161
|
-
async getChildren(delegationId: string): Promise<DelegationNode[]> {
|
|
162
|
-
return this.storage.getChildren(delegationId);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Get all descendants (children, grandchildren, etc.)
|
|
167
|
-
*
|
|
168
|
-
* Used for cascading revocation.
|
|
169
|
-
* Per Delegation-Revocation.md:56-67
|
|
170
|
-
*
|
|
171
|
-
* @param delegationId - The parent delegation ID
|
|
172
|
-
* @returns Array of all descendant nodes
|
|
173
|
-
*/
|
|
174
|
-
async getDescendants(delegationId: string): Promise<DelegationNode[]> {
|
|
175
|
-
return this.storage.getDescendants(delegationId);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Get the full delegation chain from root to this node
|
|
180
|
-
*
|
|
181
|
-
* Used for chain validation.
|
|
182
|
-
*
|
|
183
|
-
* @param delegationId - The delegation ID
|
|
184
|
-
* @returns Array of nodes from root to this node
|
|
185
|
-
*/
|
|
186
|
-
async getChain(delegationId: string): Promise<DelegationNode[]> {
|
|
187
|
-
return this.storage.getChain(delegationId);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Check if delegation A is an ancestor of delegation B
|
|
192
|
-
*
|
|
193
|
-
* @param ancestorId - Potential ancestor ID
|
|
194
|
-
* @param descendantId - Potential descendant ID
|
|
195
|
-
* @returns true if ancestorId is an ancestor of descendantId
|
|
196
|
-
*/
|
|
197
|
-
async isAncestor(
|
|
198
|
-
ancestorId: string,
|
|
199
|
-
descendantId: string
|
|
200
|
-
): Promise<boolean> {
|
|
201
|
-
const chain = await this.getChain(descendantId);
|
|
202
|
-
return chain.some((node) => node.id === ancestorId);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Get the depth of a delegation in the tree
|
|
207
|
-
*
|
|
208
|
-
* @param delegationId - The delegation ID
|
|
209
|
-
* @returns Depth (0 for root, 1 for immediate child, etc.)
|
|
210
|
-
*/
|
|
211
|
-
async getDepth(delegationId: string): Promise<number> {
|
|
212
|
-
const chain = await this.getChain(delegationId);
|
|
213
|
-
return chain.length - 1; // -1 because chain includes the node itself
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Validate that a delegation chain is properly formed
|
|
218
|
-
*
|
|
219
|
-
* Checks that:
|
|
220
|
-
* - Each child's issuer is the parent's subject
|
|
221
|
-
* - No cycles exist
|
|
222
|
-
* - Chain is continuous
|
|
223
|
-
*
|
|
224
|
-
* @param delegationId - The delegation ID to validate
|
|
225
|
-
* @returns Validation result
|
|
226
|
-
*/
|
|
227
|
-
async validateChain(delegationId: string): Promise<{
|
|
228
|
-
valid: boolean;
|
|
229
|
-
reason?: string;
|
|
230
|
-
}> {
|
|
231
|
-
const chain = await this.getChain(delegationId);
|
|
232
|
-
|
|
233
|
-
if (chain.length === 0) {
|
|
234
|
-
return { valid: false, reason: 'Delegation not found' };
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Check each link in the chain
|
|
238
|
-
for (let i = 1; i < chain.length; i++) {
|
|
239
|
-
const parent = chain[i - 1];
|
|
240
|
-
const child = chain[i];
|
|
241
|
-
|
|
242
|
-
// Child's issuer must be parent's subject
|
|
243
|
-
if (child.issuerDid !== parent.subjectDid) {
|
|
244
|
-
return {
|
|
245
|
-
valid: false,
|
|
246
|
-
reason: `Invalid chain: ${child.id} issued by ${child.issuerDid} but parent ${parent.id} subject is ${parent.subjectDid}`,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Child's parent pointer must match parent's ID
|
|
251
|
-
if (child.parentId !== parent.id) {
|
|
252
|
-
return {
|
|
253
|
-
valid: false,
|
|
254
|
-
reason: `Invalid chain: ${child.id} parentId=${child.parentId} but actual parent is ${parent.id}`,
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return { valid: true };
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Remove a delegation from the graph
|
|
264
|
-
*
|
|
265
|
-
* Note: This doesn't cascade - use CascadingRevocationManager for that.
|
|
266
|
-
*
|
|
267
|
-
* @param delegationId - The delegation ID to remove
|
|
268
|
-
*/
|
|
269
|
-
async removeDelegation(delegationId: string): Promise<void> {
|
|
270
|
-
const node = await this.storage.getNode(delegationId);
|
|
271
|
-
if (!node) return;
|
|
272
|
-
|
|
273
|
-
// Remove from parent's children list
|
|
274
|
-
if (node.parentId) {
|
|
275
|
-
const parent = await this.storage.getNode(node.parentId);
|
|
276
|
-
if (parent) {
|
|
277
|
-
parent.children = parent.children.filter((id) => id !== delegationId);
|
|
278
|
-
await this.storage.setNode(parent);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Delete the node
|
|
283
|
-
await this.storage.deleteNode(delegationId);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Create a delegation graph manager
|
|
289
|
-
*
|
|
290
|
-
* Convenience factory function.
|
|
291
|
-
*
|
|
292
|
-
* @param storage - Storage provider
|
|
293
|
-
* @returns DelegationGraphManager instance
|
|
294
|
-
*/
|
|
295
|
-
export function createDelegationGraph(
|
|
296
|
-
storage: DelegationGraphStorageProvider
|
|
297
|
-
): DelegationGraphManager {
|
|
298
|
-
return new DelegationGraphManager(storage);
|
|
299
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DID:key Resolver
|
|
3
|
-
*
|
|
4
|
-
* Resolves did:key DIDs to DID Documents with verification methods.
|
|
5
|
-
* Supports Ed25519 keys (multicodec prefix 0xed01).
|
|
6
|
-
*
|
|
7
|
-
* did:key format: did:key:z<multibase-base58btc(<multicodec-prefix><public-key>)>
|
|
8
|
-
*
|
|
9
|
-
* For Ed25519:
|
|
10
|
-
* - Multicodec prefix: 0xed 0x01
|
|
11
|
-
* - Public key: 32 bytes
|
|
12
|
-
* - Multibase prefix: 'z' (base58btc)
|
|
13
|
-
*
|
|
14
|
-
* @see https://w3c-ccg.github.io/did-method-key/
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { base58Decode } from '../utils/base58';
|
|
18
|
-
import { base64urlEncodeFromBytes } from '../utils/base64';
|
|
19
|
-
import type { DIDResolver, DIDDocument, VerificationMethod } from './vc-verifier';
|
|
20
|
-
|
|
21
|
-
/** Ed25519 multicodec prefix (0xed 0x01) */
|
|
22
|
-
const ED25519_MULTICODEC_PREFIX = new Uint8Array([0xed, 0x01]);
|
|
23
|
-
|
|
24
|
-
/** Ed25519 public key length */
|
|
25
|
-
const ED25519_PUBLIC_KEY_LENGTH = 32;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Check if a DID is a valid did:key with Ed25519 key
|
|
29
|
-
*
|
|
30
|
-
* Ed25519 keys in did:key start with 'z6Mk' after the method prefix.
|
|
31
|
-
* The 'z' is the multibase prefix for base58btc, and '6Mk' is the
|
|
32
|
-
* base58-encoded prefix for Ed25519 (0xed 0x01).
|
|
33
|
-
*
|
|
34
|
-
* @param did - The DID to check
|
|
35
|
-
* @returns true if it's a valid did:key with Ed25519 key
|
|
36
|
-
*/
|
|
37
|
-
export function isEd25519DidKey(did: string): boolean {
|
|
38
|
-
return did.startsWith('did:key:z6Mk');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Extract the public key bytes from a did:key DID
|
|
43
|
-
*
|
|
44
|
-
* @param did - The did:key DID
|
|
45
|
-
* @returns Public key bytes or null if invalid
|
|
46
|
-
*/
|
|
47
|
-
export function extractPublicKeyFromDidKey(did: string): Uint8Array | null {
|
|
48
|
-
if (!did.startsWith('did:key:z')) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
// Extract the multibase-encoded part (after 'did:key:')
|
|
54
|
-
const multibaseKey = did.replace('did:key:', '');
|
|
55
|
-
|
|
56
|
-
// Remove the 'z' multibase prefix (base58btc)
|
|
57
|
-
const base58Encoded = multibaseKey.slice(1);
|
|
58
|
-
|
|
59
|
-
// Decode from base58
|
|
60
|
-
const multicodecBytes = base58Decode(base58Encoded);
|
|
61
|
-
|
|
62
|
-
// Check for Ed25519 multicodec prefix (0xed 0x01)
|
|
63
|
-
if (
|
|
64
|
-
multicodecBytes.length < ED25519_MULTICODEC_PREFIX.length + ED25519_PUBLIC_KEY_LENGTH ||
|
|
65
|
-
multicodecBytes[0] !== ED25519_MULTICODEC_PREFIX[0] ||
|
|
66
|
-
multicodecBytes[1] !== ED25519_MULTICODEC_PREFIX[1]
|
|
67
|
-
) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Extract the public key (bytes after the prefix)
|
|
72
|
-
return multicodecBytes.slice(ED25519_MULTICODEC_PREFIX.length);
|
|
73
|
-
} catch {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Convert Ed25519 public key bytes to JWK format
|
|
80
|
-
*
|
|
81
|
-
* @param publicKeyBytes - 32-byte Ed25519 public key
|
|
82
|
-
* @returns JWK object
|
|
83
|
-
*/
|
|
84
|
-
export function publicKeyToJwk(publicKeyBytes: Uint8Array): {
|
|
85
|
-
kty: string;
|
|
86
|
-
crv: string;
|
|
87
|
-
x: string;
|
|
88
|
-
} {
|
|
89
|
-
return {
|
|
90
|
-
kty: 'OKP',
|
|
91
|
-
crv: 'Ed25519',
|
|
92
|
-
x: base64urlEncodeFromBytes(publicKeyBytes),
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Create a DID:key resolver
|
|
98
|
-
*
|
|
99
|
-
* Returns a DIDResolver that can resolve did:key DIDs to DID Documents.
|
|
100
|
-
* Currently supports only Ed25519 keys.
|
|
101
|
-
*
|
|
102
|
-
* @returns DIDResolver implementation for did:key
|
|
103
|
-
*/
|
|
104
|
-
export function createDidKeyResolver(): DIDResolver {
|
|
105
|
-
return {
|
|
106
|
-
resolve: async (did: string): Promise<DIDDocument | null> => {
|
|
107
|
-
// Check if it's a did:key with Ed25519
|
|
108
|
-
if (!isEd25519DidKey(did)) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Extract the public key
|
|
113
|
-
const publicKeyBytes = extractPublicKeyFromDidKey(did);
|
|
114
|
-
if (!publicKeyBytes) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Convert to JWK
|
|
119
|
-
const publicKeyJwk = publicKeyToJwk(publicKeyBytes);
|
|
120
|
-
|
|
121
|
-
// Get the multibase-encoded key for publicKeyMultibase
|
|
122
|
-
const multibaseKey = did.replace('did:key:', '');
|
|
123
|
-
|
|
124
|
-
// Construct the verification method
|
|
125
|
-
const verificationMethod: VerificationMethod = {
|
|
126
|
-
id: `${did}#keys-1`,
|
|
127
|
-
type: 'Ed25519VerificationKey2020',
|
|
128
|
-
controller: did,
|
|
129
|
-
publicKeyJwk,
|
|
130
|
-
publicKeyMultibase: multibaseKey,
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// Construct and return the DID Document
|
|
134
|
-
return {
|
|
135
|
-
id: did,
|
|
136
|
-
verificationMethod: [verificationMethod],
|
|
137
|
-
authentication: [`${did}#keys-1`],
|
|
138
|
-
assertionMethod: [`${did}#keys-1`],
|
|
139
|
-
};
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Resolve a did:key DID synchronously
|
|
146
|
-
*
|
|
147
|
-
* Convenience function for cases where async is not needed.
|
|
148
|
-
*
|
|
149
|
-
* @param did - The did:key DID to resolve
|
|
150
|
-
* @returns DID Document or null if invalid
|
|
151
|
-
*/
|
|
152
|
-
export function resolveDidKeySync(did: string): DIDDocument | null {
|
|
153
|
-
if (!isEd25519DidKey(did)) {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const publicKeyBytes = extractPublicKeyFromDidKey(did);
|
|
158
|
-
if (!publicKeyBytes) {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const publicKeyJwk = publicKeyToJwk(publicKeyBytes);
|
|
163
|
-
const multibaseKey = did.replace('did:key:', '');
|
|
164
|
-
|
|
165
|
-
const verificationMethod: VerificationMethod = {
|
|
166
|
-
id: `${did}#keys-1`,
|
|
167
|
-
type: 'Ed25519VerificationKey2020',
|
|
168
|
-
controller: did,
|
|
169
|
-
publicKeyJwk,
|
|
170
|
-
publicKeyMultibase: multibaseKey,
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
id: did,
|
|
175
|
-
verificationMethod: [verificationMethod],
|
|
176
|
-
authentication: [`${did}#keys-1`],
|
|
177
|
-
assertionMethod: [`${did}#keys-1`],
|
|
178
|
-
};
|
|
179
|
-
}
|
package/src/delegation/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Delegation Module Exports (Platform-Agnostic)
|
|
3
|
-
*
|
|
4
|
-
* W3C VC-based delegation issuance and verification.
|
|
5
|
-
* Platform-specific adapters (Node.js, Cloudflare) provide signing/verification functions.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export * from './vc-issuer';
|
|
9
|
-
export * from './vc-verifier';
|
|
10
|
-
export * from './bitstring';
|
|
11
|
-
export * from './statuslist-manager';
|
|
12
|
-
export * from './delegation-graph';
|
|
13
|
-
export * from './cascading-revocation';
|
|
14
|
-
export * from './utils';
|