@mcp-i/core 0.1.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/LICENSE +21 -0
- package/README.md +390 -0
- package/dist/auth/handshake.d.ts +104 -0
- package/dist/auth/handshake.d.ts.map +1 -0
- package/dist/auth/handshake.js +230 -0
- package/dist/auth/handshake.js.map +1 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/types.d.ts +31 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +7 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/delegation/audience-validator.d.ts +9 -0
- package/dist/delegation/audience-validator.d.ts.map +1 -0
- package/dist/delegation/audience-validator.js +17 -0
- package/dist/delegation/audience-validator.js.map +1 -0
- package/dist/delegation/bitstring.d.ts +37 -0
- package/dist/delegation/bitstring.d.ts.map +1 -0
- package/dist/delegation/bitstring.js +117 -0
- package/dist/delegation/bitstring.js.map +1 -0
- package/dist/delegation/cascading-revocation.d.ts +45 -0
- package/dist/delegation/cascading-revocation.d.ts.map +1 -0
- package/dist/delegation/cascading-revocation.js +148 -0
- package/dist/delegation/cascading-revocation.js.map +1 -0
- package/dist/delegation/delegation-graph.d.ts +49 -0
- package/dist/delegation/delegation-graph.d.ts.map +1 -0
- package/dist/delegation/delegation-graph.js +99 -0
- package/dist/delegation/delegation-graph.js.map +1 -0
- package/dist/delegation/did-key-resolver.d.ts +64 -0
- package/dist/delegation/did-key-resolver.d.ts.map +1 -0
- package/dist/delegation/did-key-resolver.js +154 -0
- package/dist/delegation/did-key-resolver.js.map +1 -0
- package/dist/delegation/did-web-resolver.d.ts +83 -0
- package/dist/delegation/did-web-resolver.d.ts.map +1 -0
- package/dist/delegation/did-web-resolver.js +218 -0
- package/dist/delegation/did-web-resolver.js.map +1 -0
- package/dist/delegation/index.d.ts +21 -0
- package/dist/delegation/index.d.ts.map +1 -0
- package/dist/delegation/index.js +21 -0
- package/dist/delegation/index.js.map +1 -0
- package/dist/delegation/outbound-headers.d.ts +81 -0
- package/dist/delegation/outbound-headers.d.ts.map +1 -0
- package/dist/delegation/outbound-headers.js +139 -0
- package/dist/delegation/outbound-headers.js.map +1 -0
- package/dist/delegation/outbound-proof.d.ts +43 -0
- package/dist/delegation/outbound-proof.d.ts.map +1 -0
- package/dist/delegation/outbound-proof.js +52 -0
- package/dist/delegation/outbound-proof.js.map +1 -0
- package/dist/delegation/statuslist-manager.d.ts +44 -0
- package/dist/delegation/statuslist-manager.d.ts.map +1 -0
- package/dist/delegation/statuslist-manager.js +126 -0
- package/dist/delegation/statuslist-manager.js.map +1 -0
- package/dist/delegation/storage/memory-graph-storage.d.ts +70 -0
- package/dist/delegation/storage/memory-graph-storage.d.ts.map +1 -0
- package/dist/delegation/storage/memory-graph-storage.js +145 -0
- package/dist/delegation/storage/memory-graph-storage.js.map +1 -0
- package/dist/delegation/storage/memory-statuslist-storage.d.ts +19 -0
- package/dist/delegation/storage/memory-statuslist-storage.d.ts.map +1 -0
- package/dist/delegation/storage/memory-statuslist-storage.js +33 -0
- package/dist/delegation/storage/memory-statuslist-storage.js.map +1 -0
- package/dist/delegation/utils.d.ts +49 -0
- package/dist/delegation/utils.d.ts.map +1 -0
- package/dist/delegation/utils.js +131 -0
- package/dist/delegation/utils.js.map +1 -0
- package/dist/delegation/vc-issuer.d.ts +56 -0
- package/dist/delegation/vc-issuer.d.ts.map +1 -0
- package/dist/delegation/vc-issuer.js +80 -0
- package/dist/delegation/vc-issuer.js.map +1 -0
- package/dist/delegation/vc-verifier.d.ts +112 -0
- package/dist/delegation/vc-verifier.d.ts.map +1 -0
- package/dist/delegation/vc-verifier.js +280 -0
- package/dist/delegation/vc-verifier.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/index.d.ts +2 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +2 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.d.ts +23 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +82 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/middleware/index.d.ts +7 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +7 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/with-mcpi.d.ts +152 -0
- package/dist/middleware/with-mcpi.d.ts.map +1 -0
- package/dist/middleware/with-mcpi.js +472 -0
- package/dist/middleware/with-mcpi.js.map +1 -0
- package/dist/proof/errors.d.ts +49 -0
- package/dist/proof/errors.d.ts.map +1 -0
- package/dist/proof/errors.js +61 -0
- package/dist/proof/errors.js.map +1 -0
- package/dist/proof/generator.d.ts +65 -0
- package/dist/proof/generator.d.ts.map +1 -0
- package/dist/proof/generator.js +163 -0
- package/dist/proof/generator.js.map +1 -0
- package/dist/proof/index.d.ts +4 -0
- package/dist/proof/index.d.ts.map +1 -0
- package/dist/proof/index.js +4 -0
- package/dist/proof/index.js.map +1 -0
- package/dist/proof/verifier.d.ts +108 -0
- package/dist/proof/verifier.d.ts.map +1 -0
- package/dist/proof/verifier.js +299 -0
- package/dist/proof/verifier.js.map +1 -0
- package/dist/providers/base.d.ts +64 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +19 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +3 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/memory.d.ts +33 -0
- package/dist/providers/memory.d.ts.map +1 -0
- package/dist/providers/memory.js +102 -0
- package/dist/providers/memory.js.map +1 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +2 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +77 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +251 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/types/protocol.d.ts +320 -0
- package/dist/types/protocol.d.ts.map +1 -0
- package/dist/types/protocol.js +229 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/utils/base58.d.ts +31 -0
- package/dist/utils/base58.d.ts.map +1 -0
- package/dist/utils/base58.js +104 -0
- package/dist/utils/base58.js.map +1 -0
- package/dist/utils/base64.d.ts +13 -0
- package/dist/utils/base64.d.ts.map +1 -0
- package/dist/utils/base64.js +99 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/crypto-service.d.ts +37 -0
- package/dist/utils/crypto-service.d.ts.map +1 -0
- package/dist/utils/crypto-service.js +153 -0
- package/dist/utils/crypto-service.js.map +1 -0
- package/dist/utils/did-helpers.d.ts +156 -0
- package/dist/utils/did-helpers.d.ts.map +1 -0
- package/dist/utils/did-helpers.js +193 -0
- package/dist/utils/did-helpers.js.map +1 -0
- package/dist/utils/ed25519-constants.d.ts +18 -0
- package/dist/utils/ed25519-constants.d.ts.map +1 -0
- package/dist/utils/ed25519-constants.js +21 -0
- package/dist/utils/ed25519-constants.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +105 -0
- package/src/__tests__/integration/full-flow.test.ts +362 -0
- package/src/__tests__/providers/base.test.ts +173 -0
- package/src/__tests__/providers/memory.test.ts +332 -0
- package/src/__tests__/utils/mock-providers.ts +319 -0
- package/src/__tests__/utils/node-crypto-provider.ts +93 -0
- package/src/auth/handshake.ts +411 -0
- package/src/auth/index.ts +11 -0
- package/src/auth/types.ts +40 -0
- package/src/delegation/__tests__/audience-validator.test.ts +110 -0
- package/src/delegation/__tests__/bitstring.test.ts +346 -0
- package/src/delegation/__tests__/cascading-revocation.test.ts +624 -0
- package/src/delegation/__tests__/delegation-graph.test.ts +623 -0
- package/src/delegation/__tests__/did-key-resolver.test.ts +265 -0
- package/src/delegation/__tests__/did-web-resolver.test.ts +467 -0
- package/src/delegation/__tests__/outbound-headers.test.ts +230 -0
- package/src/delegation/__tests__/outbound-proof.test.ts +179 -0
- package/src/delegation/__tests__/statuslist-manager.test.ts +515 -0
- package/src/delegation/__tests__/utils.test.ts +185 -0
- package/src/delegation/__tests__/vc-issuer.test.ts +487 -0
- package/src/delegation/__tests__/vc-verifier.test.ts +1029 -0
- package/src/delegation/audience-validator.ts +24 -0
- package/src/delegation/bitstring.ts +160 -0
- package/src/delegation/cascading-revocation.ts +224 -0
- package/src/delegation/delegation-graph.ts +143 -0
- package/src/delegation/did-key-resolver.ts +181 -0
- package/src/delegation/did-web-resolver.ts +270 -0
- package/src/delegation/index.ts +33 -0
- package/src/delegation/outbound-headers.ts +193 -0
- package/src/delegation/outbound-proof.ts +90 -0
- package/src/delegation/statuslist-manager.ts +219 -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/memory-graph-storage.ts +178 -0
- package/src/delegation/storage/memory-statuslist-storage.ts +42 -0
- package/src/delegation/utils.ts +189 -0
- package/src/delegation/vc-issuer.ts +137 -0
- package/src/delegation/vc-verifier.ts +440 -0
- package/src/index.ts +264 -0
- package/src/logging/__tests__/logger.test.ts +366 -0
- package/src/logging/index.ts +6 -0
- package/src/logging/logger.ts +91 -0
- package/src/middleware/__tests__/with-mcpi.test.ts +504 -0
- package/src/middleware/index.ts +16 -0
- package/src/middleware/with-mcpi.ts +766 -0
- package/src/proof/__tests__/proof-generator.test.ts +483 -0
- package/src/proof/__tests__/verifier.test.ts +488 -0
- package/src/proof/errors.ts +75 -0
- package/src/proof/generator.ts +255 -0
- package/src/proof/index.ts +22 -0
- package/src/proof/verifier.ts +449 -0
- package/src/providers/base.ts +68 -0
- package/src/providers/index.ts +15 -0
- package/src/providers/memory.ts +130 -0
- package/src/session/__tests__/session-manager.test.ts +342 -0
- package/src/session/index.ts +7 -0
- package/src/session/manager.ts +332 -0
- package/src/types/protocol.ts +596 -0
- package/src/utils/__tests__/base58.test.ts +281 -0
- package/src/utils/__tests__/base64.test.ts +239 -0
- package/src/utils/__tests__/crypto-service.test.ts +530 -0
- package/src/utils/__tests__/did-helpers.test.ts +156 -0
- package/src/utils/base58.ts +115 -0
- package/src/utils/base64.ts +116 -0
- package/src/utils/crypto-service.ts +209 -0
- package/src/utils/did-helpers.ts +210 -0
- package/src/utils/ed25519-constants.ts +23 -0
- package/src/utils/index.ts +9 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cascading Revocation Manager
|
|
3
|
+
*
|
|
4
|
+
* Implements cascading revocation per Python POC design.
|
|
5
|
+
* When a parent delegation is revoked, all children are automatically revoked.
|
|
6
|
+
*
|
|
7
|
+
* Related Spec: MCP-I §4.4, Delegation Chains
|
|
8
|
+
*/
|
|
9
|
+
export class CascadingRevocationManager {
|
|
10
|
+
graph;
|
|
11
|
+
statusList;
|
|
12
|
+
constructor(graph, statusList) {
|
|
13
|
+
this.graph = graph;
|
|
14
|
+
this.statusList = statusList;
|
|
15
|
+
}
|
|
16
|
+
async revokeDelegation(delegationId, options = {}) {
|
|
17
|
+
const maxDepth = options.maxDepth || 100;
|
|
18
|
+
const events = [];
|
|
19
|
+
const targetNode = await this.graph.getNode(delegationId);
|
|
20
|
+
if (!targetNode) {
|
|
21
|
+
throw new Error(`Delegation not found: ${delegationId}`);
|
|
22
|
+
}
|
|
23
|
+
const depth = await this.graph.getDepth(delegationId);
|
|
24
|
+
if (depth > maxDepth) {
|
|
25
|
+
throw new Error(`Delegation depth ${depth} exceeds maximum ${maxDepth}`);
|
|
26
|
+
}
|
|
27
|
+
const rootEvent = await this.revokeNode(targetNode, true, options.reason, options.dryRun);
|
|
28
|
+
events.push(rootEvent);
|
|
29
|
+
if (options.onRevoke) {
|
|
30
|
+
await options.onRevoke(rootEvent);
|
|
31
|
+
}
|
|
32
|
+
const descendants = await this.graph.getDescendants(delegationId);
|
|
33
|
+
for (const descendant of descendants) {
|
|
34
|
+
const event = await this.revokeNode(descendant, false, `Cascaded from ${delegationId}`, options.dryRun, delegationId);
|
|
35
|
+
events.push(event);
|
|
36
|
+
if (options.onRevoke) {
|
|
37
|
+
await options.onRevoke(event);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return events;
|
|
41
|
+
}
|
|
42
|
+
async revokeNode(node, isRoot, reason, dryRun, parentId) {
|
|
43
|
+
const event = {
|
|
44
|
+
delegationId: node.id,
|
|
45
|
+
isRoot,
|
|
46
|
+
parentId,
|
|
47
|
+
timestamp: Date.now(),
|
|
48
|
+
reason,
|
|
49
|
+
};
|
|
50
|
+
if (dryRun) {
|
|
51
|
+
return event;
|
|
52
|
+
}
|
|
53
|
+
if (node.credentialStatusId) {
|
|
54
|
+
const credentialStatus = this.parseCredentialStatus(node.credentialStatusId);
|
|
55
|
+
if (credentialStatus) {
|
|
56
|
+
await this.statusList.updateStatus(credentialStatus, true);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return event;
|
|
60
|
+
}
|
|
61
|
+
async restoreDelegation(delegationId) {
|
|
62
|
+
const node = await this.graph.getNode(delegationId);
|
|
63
|
+
if (!node) {
|
|
64
|
+
throw new Error(`Delegation not found: ${delegationId}`);
|
|
65
|
+
}
|
|
66
|
+
const event = {
|
|
67
|
+
delegationId: node.id,
|
|
68
|
+
isRoot: true,
|
|
69
|
+
timestamp: Date.now(),
|
|
70
|
+
reason: 'Restored',
|
|
71
|
+
};
|
|
72
|
+
if (node.credentialStatusId) {
|
|
73
|
+
const credentialStatus = this.parseCredentialStatus(node.credentialStatusId);
|
|
74
|
+
if (credentialStatus) {
|
|
75
|
+
await this.statusList.updateStatus(credentialStatus, false);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return event;
|
|
79
|
+
}
|
|
80
|
+
async isRevoked(delegationId) {
|
|
81
|
+
const chain = await this.graph.getChain(delegationId);
|
|
82
|
+
for (const node of chain.reverse()) {
|
|
83
|
+
if (node.credentialStatusId) {
|
|
84
|
+
const credentialStatus = this.parseCredentialStatus(node.credentialStatusId);
|
|
85
|
+
if (credentialStatus) {
|
|
86
|
+
const isRevoked = await this.statusList.checkStatus(credentialStatus);
|
|
87
|
+
if (isRevoked) {
|
|
88
|
+
return {
|
|
89
|
+
revoked: true,
|
|
90
|
+
reason: node.id === delegationId ? 'Directly revoked' : 'Ancestor revoked',
|
|
91
|
+
revokedAncestor: node.id === delegationId ? undefined : node.id,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { revoked: false };
|
|
98
|
+
}
|
|
99
|
+
async getRevokedInSubtree(rootId) {
|
|
100
|
+
const descendants = await this.graph.getDescendants(rootId);
|
|
101
|
+
const revoked = [];
|
|
102
|
+
const rootRevoked = await this.isRevoked(rootId);
|
|
103
|
+
if (rootRevoked.revoked) {
|
|
104
|
+
revoked.push(rootId);
|
|
105
|
+
}
|
|
106
|
+
for (const node of descendants) {
|
|
107
|
+
const isRevoked = await this.isRevoked(node.id);
|
|
108
|
+
if (isRevoked.revoked) {
|
|
109
|
+
revoked.push(node.id);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return revoked;
|
|
113
|
+
}
|
|
114
|
+
parseCredentialStatus(credentialStatusId) {
|
|
115
|
+
const match = credentialStatusId.match(/^(.+)#(\d+)$/);
|
|
116
|
+
if (!match)
|
|
117
|
+
return null;
|
|
118
|
+
const [, statusListCredential, indexStr] = match;
|
|
119
|
+
const index = parseInt(indexStr, 10);
|
|
120
|
+
return {
|
|
121
|
+
id: credentialStatusId,
|
|
122
|
+
type: 'StatusList2021Entry',
|
|
123
|
+
statusPurpose: 'revocation',
|
|
124
|
+
statusListIndex: index.toString(),
|
|
125
|
+
statusListCredential: statusListCredential,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async validateDelegation(delegationId) {
|
|
129
|
+
const revokedCheck = await this.isRevoked(delegationId);
|
|
130
|
+
if (revokedCheck.revoked) {
|
|
131
|
+
return {
|
|
132
|
+
valid: false,
|
|
133
|
+
reason: revokedCheck.revokedAncestor
|
|
134
|
+
? `Ancestor ${revokedCheck.revokedAncestor} is revoked`
|
|
135
|
+
: 'Delegation is revoked',
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const chainValidation = await this.graph.validateChain(delegationId);
|
|
139
|
+
if (!chainValidation.valid) {
|
|
140
|
+
return chainValidation;
|
|
141
|
+
}
|
|
142
|
+
return { valid: true };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function createCascadingRevocationManager(graph, statusList) {
|
|
146
|
+
return new CascadingRevocationManager(graph, statusList);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=cascading-revocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cascading-revocation.js","sourceRoot":"","sources":["../../src/delegation/cascading-revocation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAuBH,MAAM,OAAO,0BAA0B;IAE3B;IACA;IAFV,YACU,KAA6B,EAC7B,UAAiC;QADjC,UAAK,GAAL,KAAK,CAAwB;QAC7B,eAAU,GAAV,UAAU,CAAuB;IACxC,CAAC;IAEJ,KAAK,CAAC,gBAAgB,CACpB,YAAoB,EACpB,UAAsC,EAAE;QAExC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,GAAG,CAAC;QACzC,MAAM,MAAM,GAAsB,EAAE,CAAC;QAErC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,yBAAyB,YAAY,EAAE,CAAC,CAAC;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;AAC3D,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
* Related Spec: MCP-I §4.4, Delegation Chains
|
|
8
|
+
*/
|
|
9
|
+
export interface DelegationNode {
|
|
10
|
+
id: string;
|
|
11
|
+
parentId: string | null;
|
|
12
|
+
children: string[];
|
|
13
|
+
issuerDid: string;
|
|
14
|
+
subjectDid: string;
|
|
15
|
+
credentialStatusId?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DelegationGraphStorageProvider {
|
|
18
|
+
getNode(delegationId: string): Promise<DelegationNode | null>;
|
|
19
|
+
setNode(node: DelegationNode): Promise<void>;
|
|
20
|
+
getChildren(delegationId: string): Promise<DelegationNode[]>;
|
|
21
|
+
getChain(delegationId: string): Promise<DelegationNode[]>;
|
|
22
|
+
getDescendants(delegationId: string): Promise<DelegationNode[]>;
|
|
23
|
+
deleteNode(delegationId: string): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare class DelegationGraphManager {
|
|
26
|
+
private storage;
|
|
27
|
+
constructor(storage: DelegationGraphStorageProvider);
|
|
28
|
+
registerDelegation(params: {
|
|
29
|
+
id: string;
|
|
30
|
+
parentId: string | null;
|
|
31
|
+
issuerDid: string;
|
|
32
|
+
subjectDid: string;
|
|
33
|
+
credentialStatusId?: string;
|
|
34
|
+
}): Promise<DelegationNode>;
|
|
35
|
+
private addChildToParent;
|
|
36
|
+
getNode(delegationId: string): Promise<DelegationNode | null>;
|
|
37
|
+
getChildren(delegationId: string): Promise<DelegationNode[]>;
|
|
38
|
+
getDescendants(delegationId: string): Promise<DelegationNode[]>;
|
|
39
|
+
getChain(delegationId: string): Promise<DelegationNode[]>;
|
|
40
|
+
isAncestor(ancestorId: string, descendantId: string): Promise<boolean>;
|
|
41
|
+
getDepth(delegationId: string): Promise<number>;
|
|
42
|
+
validateChain(delegationId: string): Promise<{
|
|
43
|
+
valid: boolean;
|
|
44
|
+
reason?: string;
|
|
45
|
+
}>;
|
|
46
|
+
removeDelegation(delegationId: string): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export declare function createDelegationGraph(storage: DelegationGraphStorageProvider): DelegationGraphManager;
|
|
49
|
+
//# sourceMappingURL=delegation-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation-graph.d.ts","sourceRoot":"","sources":["../../src/delegation/delegation-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,8BAA8B;IAC7C,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC9D,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAC7D,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAC1D,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAChE,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAED,qBAAa,sBAAsB;IACrB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,8BAA8B;IAErD,kBAAkB,CAAC,MAAM,EAAE;QAC/B,EAAE,EAAE,MAAM,CAAC;QACX,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B,GAAG,OAAO,CAAC,cAAc,CAAC;YAmBb,gBAAgB;IAYxB,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAI7D,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAI5D,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAI/D,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAIzD,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKtE,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK/C,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IA6BjF,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAc5D;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,8BAA8B,GACtC,sBAAsB,CAExB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
* Related Spec: MCP-I §4.4, Delegation Chains
|
|
8
|
+
*/
|
|
9
|
+
export class DelegationGraphManager {
|
|
10
|
+
storage;
|
|
11
|
+
constructor(storage) {
|
|
12
|
+
this.storage = storage;
|
|
13
|
+
}
|
|
14
|
+
async registerDelegation(params) {
|
|
15
|
+
const node = {
|
|
16
|
+
id: params.id,
|
|
17
|
+
parentId: params.parentId,
|
|
18
|
+
children: [],
|
|
19
|
+
issuerDid: params.issuerDid,
|
|
20
|
+
subjectDid: params.subjectDid,
|
|
21
|
+
credentialStatusId: params.credentialStatusId,
|
|
22
|
+
};
|
|
23
|
+
await this.storage.setNode(node);
|
|
24
|
+
if (params.parentId) {
|
|
25
|
+
await this.addChildToParent(params.parentId, params.id);
|
|
26
|
+
}
|
|
27
|
+
return node;
|
|
28
|
+
}
|
|
29
|
+
async addChildToParent(parentId, childId) {
|
|
30
|
+
const parent = await this.storage.getNode(parentId);
|
|
31
|
+
if (!parent) {
|
|
32
|
+
throw new Error(`Parent delegation not found: ${parentId}`);
|
|
33
|
+
}
|
|
34
|
+
if (!parent.children.includes(childId)) {
|
|
35
|
+
parent.children.push(childId);
|
|
36
|
+
await this.storage.setNode(parent);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async getNode(delegationId) {
|
|
40
|
+
return this.storage.getNode(delegationId);
|
|
41
|
+
}
|
|
42
|
+
async getChildren(delegationId) {
|
|
43
|
+
return this.storage.getChildren(delegationId);
|
|
44
|
+
}
|
|
45
|
+
async getDescendants(delegationId) {
|
|
46
|
+
return this.storage.getDescendants(delegationId);
|
|
47
|
+
}
|
|
48
|
+
async getChain(delegationId) {
|
|
49
|
+
return this.storage.getChain(delegationId);
|
|
50
|
+
}
|
|
51
|
+
async isAncestor(ancestorId, descendantId) {
|
|
52
|
+
const chain = await this.getChain(descendantId);
|
|
53
|
+
return chain.some((node) => node.id === ancestorId);
|
|
54
|
+
}
|
|
55
|
+
async getDepth(delegationId) {
|
|
56
|
+
const chain = await this.getChain(delegationId);
|
|
57
|
+
return chain.length - 1;
|
|
58
|
+
}
|
|
59
|
+
async validateChain(delegationId) {
|
|
60
|
+
const chain = await this.getChain(delegationId);
|
|
61
|
+
if (chain.length === 0) {
|
|
62
|
+
return { valid: false, reason: 'Delegation not found' };
|
|
63
|
+
}
|
|
64
|
+
for (let i = 1; i < chain.length; i++) {
|
|
65
|
+
const parent = chain[i - 1];
|
|
66
|
+
const child = chain[i];
|
|
67
|
+
if (child.issuerDid !== parent.subjectDid) {
|
|
68
|
+
return {
|
|
69
|
+
valid: false,
|
|
70
|
+
reason: `Invalid chain: ${child.id} issued by ${child.issuerDid} but parent ${parent.id} subject is ${parent.subjectDid}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (child.parentId !== parent.id) {
|
|
74
|
+
return {
|
|
75
|
+
valid: false,
|
|
76
|
+
reason: `Invalid chain: ${child.id} parentId=${child.parentId} but actual parent is ${parent.id}`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { valid: true };
|
|
81
|
+
}
|
|
82
|
+
async removeDelegation(delegationId) {
|
|
83
|
+
const node = await this.storage.getNode(delegationId);
|
|
84
|
+
if (!node)
|
|
85
|
+
return;
|
|
86
|
+
if (node.parentId) {
|
|
87
|
+
const parent = await this.storage.getNode(node.parentId);
|
|
88
|
+
if (parent) {
|
|
89
|
+
parent.children = parent.children.filter((id) => id !== delegationId);
|
|
90
|
+
await this.storage.setNode(parent);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
await this.storage.deleteNode(delegationId);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export function createDelegationGraph(storage) {
|
|
97
|
+
return new DelegationGraphManager(storage);
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=delegation-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation-graph.js","sourceRoot":"","sources":["../../src/delegation/delegation-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoBH,MAAM,OAAO,sBAA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AI,sBAAsB,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
import type { DIDResolver, DIDDocument } from './vc-verifier.js';
|
|
17
|
+
/**
|
|
18
|
+
* Check if a DID is a valid did:key with Ed25519 key
|
|
19
|
+
*
|
|
20
|
+
* Ed25519 keys in did:key start with 'z6Mk' after the method prefix.
|
|
21
|
+
* The 'z' is the multibase prefix for base58btc, and '6Mk' is the
|
|
22
|
+
* base58-encoded prefix for Ed25519 (0xed 0x01).
|
|
23
|
+
*
|
|
24
|
+
* @param did - The DID to check
|
|
25
|
+
* @returns true if it's a valid did:key with Ed25519 key
|
|
26
|
+
*/
|
|
27
|
+
export declare function isEd25519DidKey(did: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Extract the public key bytes from a did:key DID
|
|
30
|
+
*
|
|
31
|
+
* @param did - The did:key DID
|
|
32
|
+
* @returns Public key bytes or null if invalid
|
|
33
|
+
*/
|
|
34
|
+
export declare function extractPublicKeyFromDidKey(did: string): Uint8Array | null;
|
|
35
|
+
/**
|
|
36
|
+
* Convert Ed25519 public key bytes to JWK format
|
|
37
|
+
*
|
|
38
|
+
* @param publicKeyBytes - 32-byte Ed25519 public key
|
|
39
|
+
* @returns JWK object
|
|
40
|
+
*/
|
|
41
|
+
export declare function publicKeyToJwk(publicKeyBytes: Uint8Array): {
|
|
42
|
+
kty: string;
|
|
43
|
+
crv: string;
|
|
44
|
+
x: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Create a DID:key resolver
|
|
48
|
+
*
|
|
49
|
+
* Returns a DIDResolver that can resolve did:key DIDs to DID Documents.
|
|
50
|
+
* Currently supports only Ed25519 keys.
|
|
51
|
+
*
|
|
52
|
+
* @returns DIDResolver implementation for did:key
|
|
53
|
+
*/
|
|
54
|
+
export declare function createDidKeyResolver(): DIDResolver;
|
|
55
|
+
/**
|
|
56
|
+
* Resolve a did:key DID synchronously
|
|
57
|
+
*
|
|
58
|
+
* Convenience function for cases where async is not needed.
|
|
59
|
+
*
|
|
60
|
+
* @param did - The did:key DID to resolve
|
|
61
|
+
* @returns DID Document or null if invalid
|
|
62
|
+
*/
|
|
63
|
+
export declare function resolveDidKeySync(did: string): DIDDocument | null;
|
|
64
|
+
//# sourceMappingURL=did-key-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-key-resolver.d.ts","sourceRoot":"","sources":["../../src/delegation/did-key-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAsB,MAAM,kBAAkB,CAAC;AASrF;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CA8BzE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,cAAc,EAAE,UAAU,GAAG;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC;CACX,CAMA;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,IAAI,WAAW,CAsClD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CA2BjE"}
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
import { base58Decode } from '../utils/base58.js';
|
|
17
|
+
import { base64urlEncodeFromBytes } from '../utils/base64.js';
|
|
18
|
+
import { logger } from '../logging/index.js';
|
|
19
|
+
/** Ed25519 multicodec prefix (0xed 0x01) */
|
|
20
|
+
const ED25519_MULTICODEC_PREFIX = new Uint8Array([0xed, 0x01]);
|
|
21
|
+
/** Ed25519 public key length */
|
|
22
|
+
const ED25519_PUBLIC_KEY_LENGTH = 32;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a DID is a valid did:key with Ed25519 key
|
|
25
|
+
*
|
|
26
|
+
* Ed25519 keys in did:key start with 'z6Mk' after the method prefix.
|
|
27
|
+
* The 'z' is the multibase prefix for base58btc, and '6Mk' is the
|
|
28
|
+
* base58-encoded prefix for Ed25519 (0xed 0x01).
|
|
29
|
+
*
|
|
30
|
+
* @param did - The DID to check
|
|
31
|
+
* @returns true if it's a valid did:key with Ed25519 key
|
|
32
|
+
*/
|
|
33
|
+
export function isEd25519DidKey(did) {
|
|
34
|
+
return did.startsWith('did:key:z6Mk');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Extract the public key bytes from a did:key DID
|
|
38
|
+
*
|
|
39
|
+
* @param did - The did:key DID
|
|
40
|
+
* @returns Public key bytes or null if invalid
|
|
41
|
+
*/
|
|
42
|
+
export function extractPublicKeyFromDidKey(did) {
|
|
43
|
+
if (!did.startsWith('did:key:z')) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
// Extract the multibase-encoded part (after 'did:key:')
|
|
48
|
+
const multibaseKey = did.replace('did:key:', '');
|
|
49
|
+
// Remove the 'z' multibase prefix (base58btc)
|
|
50
|
+
const base58Encoded = multibaseKey.slice(1);
|
|
51
|
+
// Decode from base58
|
|
52
|
+
const multicodecBytes = base58Decode(base58Encoded);
|
|
53
|
+
// Check for Ed25519 multicodec prefix (0xed 0x01)
|
|
54
|
+
if (multicodecBytes.length < ED25519_MULTICODEC_PREFIX.length + ED25519_PUBLIC_KEY_LENGTH ||
|
|
55
|
+
multicodecBytes[0] !== ED25519_MULTICODEC_PREFIX[0] ||
|
|
56
|
+
multicodecBytes[1] !== ED25519_MULTICODEC_PREFIX[1]) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
// Extract the public key (bytes after the prefix)
|
|
60
|
+
return multicodecBytes.slice(ED25519_MULTICODEC_PREFIX.length);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
logger.debug('Failed to extract public key from did:key', error);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Convert Ed25519 public key bytes to JWK format
|
|
69
|
+
*
|
|
70
|
+
* @param publicKeyBytes - 32-byte Ed25519 public key
|
|
71
|
+
* @returns JWK object
|
|
72
|
+
*/
|
|
73
|
+
export function publicKeyToJwk(publicKeyBytes) {
|
|
74
|
+
return {
|
|
75
|
+
kty: 'OKP',
|
|
76
|
+
crv: 'Ed25519',
|
|
77
|
+
x: base64urlEncodeFromBytes(publicKeyBytes),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a DID:key resolver
|
|
82
|
+
*
|
|
83
|
+
* Returns a DIDResolver that can resolve did:key DIDs to DID Documents.
|
|
84
|
+
* Currently supports only Ed25519 keys.
|
|
85
|
+
*
|
|
86
|
+
* @returns DIDResolver implementation for did:key
|
|
87
|
+
*/
|
|
88
|
+
export function createDidKeyResolver() {
|
|
89
|
+
return {
|
|
90
|
+
resolve: async (did) => {
|
|
91
|
+
// Check if it's a did:key with Ed25519
|
|
92
|
+
if (!isEd25519DidKey(did)) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
// Extract the public key
|
|
96
|
+
const publicKeyBytes = extractPublicKeyFromDidKey(did);
|
|
97
|
+
if (!publicKeyBytes) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
// Convert to JWK
|
|
101
|
+
const publicKeyJwk = publicKeyToJwk(publicKeyBytes);
|
|
102
|
+
// Get the multibase-encoded key for publicKeyMultibase
|
|
103
|
+
const multibaseKey = did.replace('did:key:', '');
|
|
104
|
+
// Construct the verification method
|
|
105
|
+
const verificationMethod = {
|
|
106
|
+
id: `${did}#keys-1`,
|
|
107
|
+
type: 'Ed25519VerificationKey2020',
|
|
108
|
+
controller: did,
|
|
109
|
+
publicKeyJwk,
|
|
110
|
+
publicKeyMultibase: multibaseKey,
|
|
111
|
+
};
|
|
112
|
+
// Construct and return the DID Document
|
|
113
|
+
return {
|
|
114
|
+
id: did,
|
|
115
|
+
verificationMethod: [verificationMethod],
|
|
116
|
+
authentication: [`${did}#keys-1`],
|
|
117
|
+
assertionMethod: [`${did}#keys-1`],
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Resolve a did:key DID synchronously
|
|
124
|
+
*
|
|
125
|
+
* Convenience function for cases where async is not needed.
|
|
126
|
+
*
|
|
127
|
+
* @param did - The did:key DID to resolve
|
|
128
|
+
* @returns DID Document or null if invalid
|
|
129
|
+
*/
|
|
130
|
+
export function resolveDidKeySync(did) {
|
|
131
|
+
if (!isEd25519DidKey(did)) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const publicKeyBytes = extractPublicKeyFromDidKey(did);
|
|
135
|
+
if (!publicKeyBytes) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const publicKeyJwk = publicKeyToJwk(publicKeyBytes);
|
|
139
|
+
const multibaseKey = did.replace('did:key:', '');
|
|
140
|
+
const verificationMethod = {
|
|
141
|
+
id: `${did}#keys-1`,
|
|
142
|
+
type: 'Ed25519VerificationKey2020',
|
|
143
|
+
controller: did,
|
|
144
|
+
publicKeyJwk,
|
|
145
|
+
publicKeyMultibase: multibaseKey,
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
id: did,
|
|
149
|
+
verificationMethod: [verificationMethod],
|
|
150
|
+
authentication: [`${did}#keys-1`],
|
|
151
|
+
assertionMethod: [`${did}#keys-1`],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=did-key-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-key-resolver.js","sourceRoot":"","sources":["../../src/delegation/did-key-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,4CAA4C;AAC5C,MAAM,yBAAyB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE/D,gCAAgC;AAChC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC;;;;;;;;;GASG;AACH,MAAM,UAAU,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,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAEjD,MAAM,kBAAkB,GAAuB;QAC7C,EAAE,EAAE,GAAG,GAAG,SAAS;QACnB,IAAI,EAAE,4BAA4B;QAClC,UAAU,EAAE,GAAG;QACf,YAAY;QACZ,kBAAkB,EAAE,YAAY;KACjC,CAAC;IAEF,OAAO;QACL,EAAE,EAAE,GAAG;QACP,kBAAkB,EAAE,CAAC,kBAAkB,CAAC;QACxC,cAAc,EAAE,CAAC,GAAG,GAAG,SAAS,CAAC;QACjC,eAAe,EAAE,CAAC,GAAG,GAAG,SAAS,CAAC;KACnC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DID:web Resolver
|
|
3
|
+
*
|
|
4
|
+
* Resolves did:web DIDs by fetching /.well-known/did.json from the domain.
|
|
5
|
+
* Supports both root domain DIDs and path-based DIDs.
|
|
6
|
+
*
|
|
7
|
+
* Examples:
|
|
8
|
+
* did:web:example.com → https://example.com/.well-known/did.json
|
|
9
|
+
* did:web:example.com:agents:bot1 → https://example.com/agents/bot1/did.json
|
|
10
|
+
*
|
|
11
|
+
* @see https://w3c-ccg.github.io/did-method-web/
|
|
12
|
+
*/
|
|
13
|
+
import type { FetchProvider } from '../providers/base.js';
|
|
14
|
+
import type { DIDResolver, DIDDocument } from './vc-verifier.js';
|
|
15
|
+
/**
|
|
16
|
+
* Parsed components of a did:web DID
|
|
17
|
+
*/
|
|
18
|
+
interface ParsedDidWeb {
|
|
19
|
+
domain: string;
|
|
20
|
+
path: string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if a DID is a did:web DID
|
|
24
|
+
*
|
|
25
|
+
* @param did - The DID to check
|
|
26
|
+
* @returns true if it's a did:web DID
|
|
27
|
+
*/
|
|
28
|
+
export declare function isDidWeb(did: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Parse a did:web DID into its components
|
|
31
|
+
*
|
|
32
|
+
* @param did - The did:web DID to parse
|
|
33
|
+
* @returns Parsed components or null if invalid
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseDidWeb(did: string): ParsedDidWeb | null;
|
|
36
|
+
/**
|
|
37
|
+
* Convert a did:web DID to its resolution URL
|
|
38
|
+
*
|
|
39
|
+
* did:web:example.com → https://example.com/.well-known/did.json
|
|
40
|
+
* did:web:example.com:path:to:doc → https://example.com/path/to/doc/did.json
|
|
41
|
+
*
|
|
42
|
+
* @param did - The did:web DID
|
|
43
|
+
* @returns The resolution URL or null if invalid
|
|
44
|
+
*/
|
|
45
|
+
export declare function didWebToUrl(did: string): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* DID:web resolver implementation
|
|
48
|
+
*/
|
|
49
|
+
export declare class DidWebResolver implements DIDResolver {
|
|
50
|
+
private fetchProvider;
|
|
51
|
+
private cache;
|
|
52
|
+
private cacheTtl;
|
|
53
|
+
constructor(fetchProvider: FetchProvider, options?: {
|
|
54
|
+
cacheTtl?: number;
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Resolve a did:web DID to its DID Document
|
|
58
|
+
*
|
|
59
|
+
* @param did - The did:web DID to resolve
|
|
60
|
+
* @returns The DID Document or null if resolution fails
|
|
61
|
+
*/
|
|
62
|
+
resolve(did: string): Promise<DIDDocument | null>;
|
|
63
|
+
/**
|
|
64
|
+
* Clear the resolution cache
|
|
65
|
+
*/
|
|
66
|
+
clearCache(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Clear a specific entry from the cache
|
|
69
|
+
*/
|
|
70
|
+
clearCacheEntry(did: string): void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a did:web resolver with the given fetch provider
|
|
74
|
+
*
|
|
75
|
+
* @param fetchProvider - Provider for making HTTP requests
|
|
76
|
+
* @param options - Optional configuration
|
|
77
|
+
* @returns DIDResolver implementation for did:web
|
|
78
|
+
*/
|
|
79
|
+
export declare function createDidWebResolver(fetchProvider: FetchProvider, options?: {
|
|
80
|
+
cacheTtl?: number;
|
|
81
|
+
}): DIDResolver;
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=did-web-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-web-resolver.d.ts","sourceRoot":"","sources":["../../src/delegation/did-web-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAsB,MAAM,kBAAkB,CAAC;AAGrF;;GAEG;AACH,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AA0DD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CA0B5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAsBtD;AAED;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,KAAK,CAA4D;IACzE,OAAO,CAAC,QAAQ,CAAS;gBAEb,aAAa,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;IAMzE;;;;;OAKG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAgEvD;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAGnC;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,aAA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