@kya-os/mcp-i-core 1.2.3-canary.7 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +9 -0
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test$colon$coverage.log +4514 -0
- package/.turbo/turbo-test.log +2973 -0
- package/COMPLIANCE_IMPROVEMENT_REPORT.md +483 -0
- package/Composer 3.md +615 -0
- package/GPT-5.md +1169 -0
- package/OPUS-plan.md +352 -0
- package/PHASE_3_AND_4.1_SUMMARY.md +585 -0
- package/PHASE_3_SUMMARY.md +317 -0
- package/PHASE_4.1.3_SUMMARY.md +428 -0
- package/PHASE_4.1_COMPLETE.md +525 -0
- package/PHASE_4_USER_DID_IDENTITY_LINKING_PLAN.md +1240 -0
- package/SCHEMA_COMPLIANCE_REPORT.md +275 -0
- package/TEST_PLAN.md +571 -0
- package/coverage/coverage-final.json +57 -0
- package/dist/__tests__/utils/mock-providers.d.ts +1 -2
- package/dist/__tests__/utils/mock-providers.d.ts.map +1 -1
- package/dist/__tests__/utils/mock-providers.js.map +1 -1
- package/dist/cache/oauth-config-cache.d.ts +69 -0
- package/dist/cache/oauth-config-cache.d.ts.map +1 -0
- package/dist/cache/oauth-config-cache.js +76 -0
- package/dist/cache/oauth-config-cache.js.map +1 -0
- package/dist/identity/idp-token-resolver.d.ts +53 -0
- package/dist/identity/idp-token-resolver.d.ts.map +1 -0
- package/dist/identity/idp-token-resolver.js +108 -0
- package/dist/identity/idp-token-resolver.js.map +1 -0
- package/dist/identity/idp-token-storage.interface.d.ts +42 -0
- package/dist/identity/idp-token-storage.interface.d.ts.map +1 -0
- package/dist/identity/idp-token-storage.interface.js +12 -0
- package/dist/identity/idp-token-storage.interface.js.map +1 -0
- package/dist/identity/user-did-manager.d.ts +39 -1
- package/dist/identity/user-did-manager.d.ts.map +1 -1
- package/dist/identity/user-did-manager.js +69 -3
- package/dist/identity/user-did-manager.js.map +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime/audit-logger.d.ts +37 -0
- package/dist/runtime/audit-logger.d.ts.map +1 -0
- package/dist/runtime/audit-logger.js +9 -0
- package/dist/runtime/audit-logger.js.map +1 -0
- package/dist/runtime/base.d.ts +58 -2
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +266 -11
- package/dist/runtime/base.js.map +1 -1
- package/dist/services/access-control.service.d.ts.map +1 -1
- package/dist/services/access-control.service.js +200 -35
- package/dist/services/access-control.service.js.map +1 -1
- package/dist/services/authorization/authorization-registry.d.ts +29 -0
- package/dist/services/authorization/authorization-registry.d.ts.map +1 -0
- package/dist/services/authorization/authorization-registry.js +57 -0
- package/dist/services/authorization/authorization-registry.js.map +1 -0
- package/dist/services/authorization/types.d.ts +53 -0
- package/dist/services/authorization/types.d.ts.map +1 -0
- package/dist/services/authorization/types.js +10 -0
- package/dist/services/authorization/types.js.map +1 -0
- package/dist/services/batch-delegation.service.d.ts +53 -0
- package/dist/services/batch-delegation.service.d.ts.map +1 -0
- package/dist/services/batch-delegation.service.js +95 -0
- package/dist/services/batch-delegation.service.js.map +1 -0
- package/dist/services/oauth-config.service.d.ts +53 -0
- package/dist/services/oauth-config.service.d.ts.map +1 -0
- package/dist/services/oauth-config.service.js +117 -0
- package/dist/services/oauth-config.service.js.map +1 -0
- package/dist/services/oauth-provider-registry.d.ts +77 -0
- package/dist/services/oauth-provider-registry.d.ts.map +1 -0
- package/dist/services/oauth-provider-registry.js +112 -0
- package/dist/services/oauth-provider-registry.js.map +1 -0
- package/dist/services/oauth-service.d.ts +77 -0
- package/dist/services/oauth-service.d.ts.map +1 -0
- package/dist/services/oauth-service.js +348 -0
- package/dist/services/oauth-service.js.map +1 -0
- package/dist/services/oauth-token-retrieval.service.d.ts +49 -0
- package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -0
- package/dist/services/oauth-token-retrieval.service.js +150 -0
- package/dist/services/oauth-token-retrieval.service.js.map +1 -0
- package/dist/services/provider-resolver.d.ts +48 -0
- package/dist/services/provider-resolver.d.ts.map +1 -0
- package/dist/services/provider-resolver.js +120 -0
- package/dist/services/provider-resolver.js.map +1 -0
- package/dist/services/provider-validator.d.ts +55 -0
- package/dist/services/provider-validator.d.ts.map +1 -0
- package/dist/services/provider-validator.js +135 -0
- package/dist/services/provider-validator.js.map +1 -0
- package/dist/services/tool-context-builder.d.ts +57 -0
- package/dist/services/tool-context-builder.d.ts.map +1 -0
- package/dist/services/tool-context-builder.js +125 -0
- package/dist/services/tool-context-builder.js.map +1 -0
- package/dist/services/tool-protection.service.d.ts +87 -10
- package/dist/services/tool-protection.service.d.ts.map +1 -1
- package/dist/services/tool-protection.service.js +282 -112
- package/dist/services/tool-protection.service.js.map +1 -1
- package/dist/types/oauth-required-error.d.ts +40 -0
- package/dist/types/oauth-required-error.d.ts.map +1 -0
- package/dist/types/oauth-required-error.js +40 -0
- package/dist/types/oauth-required-error.js.map +1 -0
- package/dist/utils/did-helpers.d.ts +33 -0
- package/dist/utils/did-helpers.d.ts.map +1 -1
- package/dist/utils/did-helpers.js +40 -0
- package/dist/utils/did-helpers.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/docs/API_REFERENCE.md +1362 -0
- package/docs/COMPLIANCE_MATRIX.md +691 -0
- package/docs/STATUSLIST2021_GUIDE.md +696 -0
- package/docs/W3C_VC_DELEGATION_GUIDE.md +710 -0
- package/package.json +24 -50
- package/scripts/audit-compliance.ts +724 -0
- package/src/__tests__/cache/tool-protection-cache.test.ts +640 -0
- package/src/__tests__/config/provider-runtime-config.test.ts +309 -0
- package/src/__tests__/delegation-e2e.test.ts +690 -0
- package/src/__tests__/identity/user-did-manager.test.ts +213 -0
- package/src/__tests__/index.test.ts +56 -0
- package/src/__tests__/integration/full-flow.test.ts +776 -0
- package/src/__tests__/integration.test.ts +281 -0
- package/src/__tests__/providers/base.test.ts +173 -0
- package/src/__tests__/providers/memory.test.ts +319 -0
- package/src/__tests__/regression/phase2-regression.test.ts +427 -0
- package/src/__tests__/runtime/audit-logger.test.ts +154 -0
- package/src/__tests__/runtime/base-extensions.test.ts +593 -0
- package/src/__tests__/runtime/base.test.ts +869 -0
- package/src/__tests__/runtime/delegation-flow.test.ts +164 -0
- package/src/__tests__/runtime/proof-client-did.test.ts +375 -0
- package/src/__tests__/runtime/route-interception.test.ts +686 -0
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +908 -0
- package/src/__tests__/services/agentshield-integration.test.ts +784 -0
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +487 -0
- package/src/__tests__/services/tool-protection-oauth-provider.test.ts +480 -0
- package/src/__tests__/services/tool-protection.service.test.ts +1366 -0
- package/src/__tests__/utils/mock-providers.ts +340 -0
- package/src/cache/oauth-config-cache.d.ts +69 -0
- package/src/cache/oauth-config-cache.d.ts.map +1 -0
- package/src/cache/oauth-config-cache.js +71 -0
- package/src/cache/oauth-config-cache.js.map +1 -0
- package/src/cache/oauth-config-cache.ts +123 -0
- package/src/cache/tool-protection-cache.ts +171 -0
- package/src/compliance/EXAMPLE.md +412 -0
- package/src/compliance/__tests__/schema-verifier.test.ts +797 -0
- package/src/compliance/index.ts +8 -0
- package/src/compliance/schema-registry.ts +460 -0
- package/src/compliance/schema-verifier.ts +708 -0
- package/src/config/__tests__/remote-config.spec.ts +268 -0
- package/src/config/remote-config.ts +174 -0
- package/src/config.ts +309 -0
- package/src/delegation/__tests__/audience-validator.test.ts +112 -0
- package/src/delegation/__tests__/bitstring.test.ts +346 -0
- package/src/delegation/__tests__/cascading-revocation.test.ts +628 -0
- package/src/delegation/__tests__/delegation-graph.test.ts +584 -0
- package/src/delegation/__tests__/utils.test.ts +152 -0
- package/src/delegation/__tests__/vc-issuer.test.ts +442 -0
- package/src/delegation/__tests__/vc-verifier.test.ts +922 -0
- package/src/delegation/audience-validator.ts +52 -0
- package/src/delegation/bitstring.ts +278 -0
- package/src/delegation/cascading-revocation.ts +370 -0
- package/src/delegation/delegation-graph.ts +299 -0
- package/src/delegation/index.ts +14 -0
- package/src/delegation/statuslist-manager.ts +353 -0
- package/src/delegation/storage/__tests__/memory-graph-storage.test.ts +366 -0
- package/src/delegation/storage/__tests__/memory-statuslist-storage.test.ts +228 -0
- package/src/delegation/storage/index.ts +9 -0
- package/src/delegation/storage/memory-graph-storage.ts +178 -0
- package/src/delegation/storage/memory-statuslist-storage.ts +77 -0
- package/src/delegation/utils.ts +42 -0
- package/src/delegation/vc-issuer.ts +232 -0
- package/src/delegation/vc-verifier.ts +568 -0
- package/src/identity/idp-token-resolver.ts +147 -0
- package/src/identity/idp-token-storage.interface.ts +59 -0
- package/src/identity/user-did-manager.ts +370 -0
- package/src/index.ts +260 -0
- package/src/providers/base.d.ts +91 -0
- package/src/providers/base.d.ts.map +1 -0
- package/src/providers/base.js +38 -0
- package/src/providers/base.js.map +1 -0
- package/src/providers/base.ts +96 -0
- package/src/providers/memory.ts +142 -0
- package/src/runtime/audit-logger.ts +39 -0
- package/src/runtime/base.ts +1329 -0
- package/src/services/__tests__/access-control.integration.test.ts +443 -0
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +578 -0
- package/src/services/__tests__/access-control.service.test.ts +970 -0
- package/src/services/__tests__/batch-delegation.service.test.ts +351 -0
- package/src/services/__tests__/crypto.service.test.ts +531 -0
- package/src/services/__tests__/oauth-provider-registry.test.ts +142 -0
- package/src/services/__tests__/proof-verifier.integration.test.ts +485 -0
- package/src/services/__tests__/proof-verifier.test.ts +489 -0
- package/src/services/__tests__/provider-resolution.integration.test.ts +198 -0
- package/src/services/__tests__/provider-resolver.test.ts +217 -0
- package/src/services/__tests__/storage.service.test.ts +358 -0
- package/src/services/access-control.service.ts +990 -0
- package/src/services/authorization/authorization-registry.ts +66 -0
- package/src/services/authorization/types.ts +71 -0
- package/src/services/batch-delegation.service.ts +137 -0
- package/src/services/crypto.service.ts +302 -0
- package/src/services/errors.ts +76 -0
- package/src/services/index.ts +9 -0
- package/src/services/oauth-config.service.d.ts +53 -0
- package/src/services/oauth-config.service.d.ts.map +1 -0
- package/src/services/oauth-config.service.js +113 -0
- package/src/services/oauth-config.service.js.map +1 -0
- package/src/services/oauth-config.service.ts +166 -0
- package/src/services/oauth-provider-registry.d.ts +57 -0
- package/src/services/oauth-provider-registry.d.ts.map +1 -0
- package/src/services/oauth-provider-registry.js +73 -0
- package/src/services/oauth-provider-registry.js.map +1 -0
- package/src/services/oauth-provider-registry.ts +123 -0
- package/src/services/oauth-service.ts +510 -0
- package/src/services/oauth-token-retrieval.service.ts +245 -0
- package/src/services/proof-verifier.ts +478 -0
- package/src/services/provider-resolver.d.ts +48 -0
- package/src/services/provider-resolver.d.ts.map +1 -0
- package/src/services/provider-resolver.js +106 -0
- package/src/services/provider-resolver.js.map +1 -0
- package/src/services/provider-resolver.ts +144 -0
- package/src/services/provider-validator.ts +170 -0
- package/src/services/storage.service.ts +566 -0
- package/src/services/tool-context-builder.ts +172 -0
- package/src/services/tool-protection.service.ts +958 -0
- package/src/types/oauth-required-error.ts +63 -0
- package/src/types/tool-protection.ts +155 -0
- package/src/utils/__tests__/did-helpers.test.ts +101 -0
- package/src/utils/base64.ts +148 -0
- package/src/utils/cors.ts +83 -0
- package/src/utils/did-helpers.ts +150 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/storage-keys.ts +278 -0
- package/tsconfig.json +21 -0
- package/vitest.config.ts +56 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import { MemoryDelegationGraphStorage } from "../memory-graph-storage.js";
|
|
3
|
+
import type { DelegationNode } from "../../delegation-graph.js";
|
|
4
|
+
|
|
5
|
+
describe("MemoryDelegationGraphStorage", () => {
|
|
6
|
+
let storage: MemoryDelegationGraphStorage;
|
|
7
|
+
|
|
8
|
+
const createMockNode = (
|
|
9
|
+
id: string,
|
|
10
|
+
parentId: string | null = null
|
|
11
|
+
): DelegationNode => ({
|
|
12
|
+
id,
|
|
13
|
+
parentId,
|
|
14
|
+
issuerDid: `did:web:example.com:issuer${id}`,
|
|
15
|
+
subjectDid: `did:web:example.com:subject${id}`,
|
|
16
|
+
children: [],
|
|
17
|
+
credentialStatusId: `https://example.com/status#${id}`,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
storage = new MemoryDelegationGraphStorage();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("getNode", () => {
|
|
25
|
+
it("should return null for non-existent node", async () => {
|
|
26
|
+
const result = await storage.getNode("non-existent");
|
|
27
|
+
expect(result).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should return stored node", async () => {
|
|
31
|
+
const node = createMockNode("del-001");
|
|
32
|
+
await storage.setNode(node);
|
|
33
|
+
|
|
34
|
+
const result = await storage.getNode("del-001");
|
|
35
|
+
expect(result).toEqual(node);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("setNode", () => {
|
|
40
|
+
it("should store node", async () => {
|
|
41
|
+
const node = createMockNode("del-001");
|
|
42
|
+
await storage.setNode(node);
|
|
43
|
+
|
|
44
|
+
const result = await storage.getNode("del-001");
|
|
45
|
+
expect(result).toEqual(node);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should overwrite existing node", async () => {
|
|
49
|
+
const node1 = createMockNode("del-001");
|
|
50
|
+
await storage.setNode(node1);
|
|
51
|
+
|
|
52
|
+
const node2 = {
|
|
53
|
+
...node1,
|
|
54
|
+
issuerDid: "did:web:example.com:updated",
|
|
55
|
+
};
|
|
56
|
+
await storage.setNode(node2);
|
|
57
|
+
|
|
58
|
+
const result = await storage.getNode("del-001");
|
|
59
|
+
expect(result?.issuerDid).toBe("did:web:example.com:updated");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("getChildren", () => {
|
|
64
|
+
it("should return empty array for node with no children", async () => {
|
|
65
|
+
const node = createMockNode("del-001");
|
|
66
|
+
await storage.setNode(node);
|
|
67
|
+
|
|
68
|
+
const children = await storage.getChildren("del-001");
|
|
69
|
+
expect(children).toEqual([]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should return direct children only", async () => {
|
|
73
|
+
const parent = createMockNode("del-parent");
|
|
74
|
+
const child1 = createMockNode("del-child1", "del-parent");
|
|
75
|
+
const child2 = createMockNode("del-child2", "del-parent");
|
|
76
|
+
const grandchild = createMockNode("del-grandchild", "del-child1");
|
|
77
|
+
|
|
78
|
+
parent.children = ["del-child1", "del-child2"];
|
|
79
|
+
child1.children = ["del-grandchild"];
|
|
80
|
+
|
|
81
|
+
await storage.setNode(parent);
|
|
82
|
+
await storage.setNode(child1);
|
|
83
|
+
await storage.setNode(child2);
|
|
84
|
+
await storage.setNode(grandchild);
|
|
85
|
+
|
|
86
|
+
const children = await storage.getChildren("del-parent");
|
|
87
|
+
expect(children.length).toBe(2);
|
|
88
|
+
expect(children.map((c) => c.id)).toContain("del-child1");
|
|
89
|
+
expect(children.map((c) => c.id)).toContain("del-child2");
|
|
90
|
+
expect(children.map((c) => c.id)).not.toContain("del-grandchild");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("should return empty array for non-existent node", async () => {
|
|
94
|
+
const children = await storage.getChildren("non-existent");
|
|
95
|
+
expect(children).toEqual([]);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should filter out missing child nodes", async () => {
|
|
99
|
+
const parent = createMockNode("del-parent");
|
|
100
|
+
parent.children = ["del-child1", "del-missing", "del-child2"];
|
|
101
|
+
|
|
102
|
+
const child1 = createMockNode("del-child1", "del-parent");
|
|
103
|
+
const child2 = createMockNode("del-child2", "del-parent");
|
|
104
|
+
|
|
105
|
+
await storage.setNode(parent);
|
|
106
|
+
await storage.setNode(child1);
|
|
107
|
+
await storage.setNode(child2);
|
|
108
|
+
// del-missing is not stored
|
|
109
|
+
|
|
110
|
+
const children = await storage.getChildren("del-parent");
|
|
111
|
+
expect(children.length).toBe(2);
|
|
112
|
+
expect(children.map((c) => c.id)).toContain("del-child1");
|
|
113
|
+
expect(children.map((c) => c.id)).toContain("del-child2");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("getChain", () => {
|
|
118
|
+
it("should return single node for root", async () => {
|
|
119
|
+
const root = createMockNode("del-root");
|
|
120
|
+
await storage.setNode(root);
|
|
121
|
+
|
|
122
|
+
const chain = await storage.getChain("del-root");
|
|
123
|
+
expect(chain.length).toBe(1);
|
|
124
|
+
expect(chain[0].id).toBe("del-root");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should return chain from root to node", async () => {
|
|
128
|
+
const root = createMockNode("del-root");
|
|
129
|
+
const child = createMockNode("del-child", "del-root");
|
|
130
|
+
const grandchild = createMockNode("del-grandchild", "del-child");
|
|
131
|
+
|
|
132
|
+
root.children = ["del-child"];
|
|
133
|
+
child.children = ["del-grandchild"];
|
|
134
|
+
|
|
135
|
+
await storage.setNode(root);
|
|
136
|
+
await storage.setNode(child);
|
|
137
|
+
await storage.setNode(grandchild);
|
|
138
|
+
|
|
139
|
+
const chain = await storage.getChain("del-grandchild");
|
|
140
|
+
expect(chain.length).toBe(3);
|
|
141
|
+
expect(chain[0].id).toBe("del-root");
|
|
142
|
+
expect(chain[1].id).toBe("del-child");
|
|
143
|
+
expect(chain[2].id).toBe("del-grandchild");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should stop at missing parent", async () => {
|
|
147
|
+
const child = createMockNode("del-child", "del-missing-parent");
|
|
148
|
+
await storage.setNode(child);
|
|
149
|
+
|
|
150
|
+
const chain = await storage.getChain("del-child");
|
|
151
|
+
expect(chain.length).toBe(1);
|
|
152
|
+
expect(chain[0].id).toBe("del-child");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("should return empty array for non-existent node", async () => {
|
|
156
|
+
const chain = await storage.getChain("non-existent");
|
|
157
|
+
expect(chain).toEqual([]);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe("getDescendants", () => {
|
|
162
|
+
it("should return empty array for leaf node", async () => {
|
|
163
|
+
const leaf = createMockNode("del-leaf");
|
|
164
|
+
await storage.setNode(leaf);
|
|
165
|
+
|
|
166
|
+
const descendants = await storage.getDescendants("del-leaf");
|
|
167
|
+
expect(descendants).toEqual([]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("should return all descendants", async () => {
|
|
171
|
+
const root = createMockNode("del-root");
|
|
172
|
+
const child1 = createMockNode("del-child1", "del-root");
|
|
173
|
+
const child2 = createMockNode("del-child2", "del-root");
|
|
174
|
+
const grandchild = createMockNode("del-grandchild", "del-child1");
|
|
175
|
+
|
|
176
|
+
root.children = ["del-child1", "del-child2"];
|
|
177
|
+
child1.children = ["del-grandchild"];
|
|
178
|
+
|
|
179
|
+
await storage.setNode(root);
|
|
180
|
+
await storage.setNode(child1);
|
|
181
|
+
await storage.setNode(child2);
|
|
182
|
+
await storage.setNode(grandchild);
|
|
183
|
+
|
|
184
|
+
const descendants = await storage.getDescendants("del-root");
|
|
185
|
+
expect(descendants.length).toBe(3);
|
|
186
|
+
expect(descendants.map((d) => d.id)).toContain("del-child1");
|
|
187
|
+
expect(descendants.map((d) => d.id)).toContain("del-child2");
|
|
188
|
+
expect(descendants.map((d) => d.id)).toContain("del-grandchild");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("should handle deep trees", async () => {
|
|
192
|
+
const nodes: DelegationNode[] = [];
|
|
193
|
+
for (let i = 0; i < 5; i++) {
|
|
194
|
+
const parentId = i === 0 ? null : `del-${i - 1}`;
|
|
195
|
+
const node = createMockNode(`del-${i}`, parentId);
|
|
196
|
+
if (i > 0) {
|
|
197
|
+
nodes[i - 1].children.push(`del-${i}`);
|
|
198
|
+
}
|
|
199
|
+
nodes.push(node);
|
|
200
|
+
await storage.setNode(node);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const descendants = await storage.getDescendants("del-0");
|
|
204
|
+
expect(descendants.length).toBe(4);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("should prevent infinite loops", async () => {
|
|
208
|
+
// Create a cycle (shouldn't happen in real usage, but test defensive code)
|
|
209
|
+
const node1 = createMockNode("del-1");
|
|
210
|
+
const node2 = createMockNode("del-2", "del-1");
|
|
211
|
+
node1.children = ["del-2"];
|
|
212
|
+
node2.children = ["del-1"]; // Cycle!
|
|
213
|
+
|
|
214
|
+
await storage.setNode(node1);
|
|
215
|
+
await storage.setNode(node2);
|
|
216
|
+
|
|
217
|
+
const descendants = await storage.getDescendants("del-1");
|
|
218
|
+
// Should return node2 only once, not loop infinitely
|
|
219
|
+
expect(descendants.length).toBe(1);
|
|
220
|
+
expect(descendants[0].id).toBe("del-2");
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("should return empty array for non-existent node", async () => {
|
|
224
|
+
const descendants = await storage.getDescendants("non-existent");
|
|
225
|
+
expect(descendants).toEqual([]);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe("deleteNode", () => {
|
|
230
|
+
it("should delete node", async () => {
|
|
231
|
+
const node = createMockNode("del-001");
|
|
232
|
+
await storage.setNode(node);
|
|
233
|
+
|
|
234
|
+
await storage.deleteNode("del-001");
|
|
235
|
+
|
|
236
|
+
const result = await storage.getNode("del-001");
|
|
237
|
+
expect(result).toBeNull();
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("should not throw when deleting non-existent node", async () => {
|
|
241
|
+
await expect(storage.deleteNode("non-existent")).resolves.not.toThrow();
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe("clear", () => {
|
|
246
|
+
it("should remove all nodes", async () => {
|
|
247
|
+
await storage.setNode(createMockNode("del-001"));
|
|
248
|
+
await storage.setNode(createMockNode("del-002"));
|
|
249
|
+
|
|
250
|
+
storage.clear();
|
|
251
|
+
|
|
252
|
+
expect(await storage.getNode("del-001")).toBeNull();
|
|
253
|
+
expect(await storage.getNode("del-002")).toBeNull();
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe("getAllNodeIds", () => {
|
|
258
|
+
it("should return empty array when no nodes", () => {
|
|
259
|
+
const ids = storage.getAllNodeIds();
|
|
260
|
+
expect(ids).toEqual([]);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("should return all node IDs", async () => {
|
|
264
|
+
await storage.setNode(createMockNode("del-001"));
|
|
265
|
+
await storage.setNode(createMockNode("del-002"));
|
|
266
|
+
await storage.setNode(createMockNode("del-003"));
|
|
267
|
+
|
|
268
|
+
const ids = storage.getAllNodeIds();
|
|
269
|
+
expect(ids).toContain("del-001");
|
|
270
|
+
expect(ids).toContain("del-002");
|
|
271
|
+
expect(ids).toContain("del-003");
|
|
272
|
+
expect(ids.length).toBe(3);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
describe("getStats", () => {
|
|
277
|
+
it("should return correct stats for empty storage", () => {
|
|
278
|
+
const stats = storage.getStats();
|
|
279
|
+
expect(stats.totalNodes).toBe(0);
|
|
280
|
+
expect(stats.rootNodes).toBe(0);
|
|
281
|
+
expect(stats.leafNodes).toBe(0);
|
|
282
|
+
expect(stats.maxDepth).toBe(0);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("should count root nodes correctly", async () => {
|
|
286
|
+
await storage.setNode(createMockNode("del-root1"));
|
|
287
|
+
await storage.setNode(createMockNode("del-root2"));
|
|
288
|
+
|
|
289
|
+
const stats = storage.getStats();
|
|
290
|
+
expect(stats.rootNodes).toBe(2);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("should count leaf nodes correctly", async () => {
|
|
294
|
+
const root = createMockNode("del-root");
|
|
295
|
+
const child1 = createMockNode("del-child1", "del-root");
|
|
296
|
+
const child2 = createMockNode("del-child2", "del-root");
|
|
297
|
+
|
|
298
|
+
root.children = ["del-child1", "del-child2"];
|
|
299
|
+
|
|
300
|
+
await storage.setNode(root);
|
|
301
|
+
await storage.setNode(child1);
|
|
302
|
+
await storage.setNode(child2);
|
|
303
|
+
|
|
304
|
+
const stats = storage.getStats();
|
|
305
|
+
expect(stats.leafNodes).toBe(2); // child1 and child2
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("should calculate max depth correctly", async () => {
|
|
309
|
+
const root = createMockNode("del-root");
|
|
310
|
+
const child = createMockNode("del-child", "del-root");
|
|
311
|
+
const grandchild = createMockNode("del-grandchild", "del-child");
|
|
312
|
+
|
|
313
|
+
root.children = ["del-child"];
|
|
314
|
+
child.children = ["del-grandchild"];
|
|
315
|
+
|
|
316
|
+
await storage.setNode(root);
|
|
317
|
+
await storage.setNode(child);
|
|
318
|
+
await storage.setNode(grandchild);
|
|
319
|
+
|
|
320
|
+
const stats = storage.getStats();
|
|
321
|
+
expect(stats.maxDepth).toBe(2); // root -> child -> grandchild (depth 2)
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it("should handle multiple trees", async () => {
|
|
325
|
+
// Tree 1: depth 1
|
|
326
|
+
const root1 = createMockNode("del-root1");
|
|
327
|
+
const child1 = createMockNode("del-child1", "del-root1");
|
|
328
|
+
root1.children = ["del-child1"];
|
|
329
|
+
|
|
330
|
+
// Tree 2: depth 2
|
|
331
|
+
const root2 = createMockNode("del-root2");
|
|
332
|
+
const child2 = createMockNode("del-child2", "del-root2");
|
|
333
|
+
const grandchild2 = createMockNode("del-grandchild2", "del-child2");
|
|
334
|
+
root2.children = ["del-child2"];
|
|
335
|
+
child2.children = ["del-grandchild2"];
|
|
336
|
+
|
|
337
|
+
await storage.setNode(root1);
|
|
338
|
+
await storage.setNode(child1);
|
|
339
|
+
await storage.setNode(root2);
|
|
340
|
+
await storage.setNode(child2);
|
|
341
|
+
await storage.setNode(grandchild2);
|
|
342
|
+
|
|
343
|
+
const stats = storage.getStats();
|
|
344
|
+
expect(stats.totalNodes).toBe(5);
|
|
345
|
+
expect(stats.rootNodes).toBe(2);
|
|
346
|
+
expect(stats.maxDepth).toBe(2); // Max depth across all trees
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import { MemoryStatusListStorage } from "../memory-statuslist-storage.js";
|
|
3
|
+
import type { StatusList2021Credential } from "@kya-os/contracts";
|
|
4
|
+
|
|
5
|
+
describe("MemoryStatusListStorage", () => {
|
|
6
|
+
let storage: MemoryStatusListStorage;
|
|
7
|
+
|
|
8
|
+
const mockStatusListCredential: StatusList2021Credential = {
|
|
9
|
+
"@context": [
|
|
10
|
+
"https://www.w3.org/2018/credentials/v1",
|
|
11
|
+
"https://w3id.org/vc/status-list/2021/v1",
|
|
12
|
+
],
|
|
13
|
+
id: "https://example.com/status/revocation/v1",
|
|
14
|
+
type: ["VerifiableCredential", "StatusList2021Credential"],
|
|
15
|
+
issuer: "did:web:example.com",
|
|
16
|
+
issuanceDate: "2024-01-01T00:00:00Z",
|
|
17
|
+
credentialSubject: {
|
|
18
|
+
id: "https://example.com/status/revocation/v1#list",
|
|
19
|
+
type: "StatusList2021",
|
|
20
|
+
statusPurpose: "revocation",
|
|
21
|
+
encodedList: "H4sIAAAAAAAAA2NgGAWjYBSMglEwCkYBqwAA0kEQVAEAAA==",
|
|
22
|
+
},
|
|
23
|
+
proof: {
|
|
24
|
+
type: "Ed25519Signature2020",
|
|
25
|
+
created: "2024-01-01T00:00:00Z",
|
|
26
|
+
verificationMethod: "did:web:example.com#key-1",
|
|
27
|
+
proofPurpose: "assertionMethod",
|
|
28
|
+
proofValue: "mock-proof",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
storage = new MemoryStatusListStorage();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("getStatusList", () => {
|
|
37
|
+
it("should return null for non-existent status list", async () => {
|
|
38
|
+
const result = await storage.getStatusList("non-existent");
|
|
39
|
+
expect(result).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should return stored status list", async () => {
|
|
43
|
+
await storage.setStatusList(
|
|
44
|
+
"https://example.com/status/revocation/v1",
|
|
45
|
+
mockStatusListCredential
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const result = await storage.getStatusList(
|
|
49
|
+
"https://example.com/status/revocation/v1"
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(result).toEqual(mockStatusListCredential);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("setStatusList", () => {
|
|
57
|
+
it("should store status list", async () => {
|
|
58
|
+
await storage.setStatusList(
|
|
59
|
+
"https://example.com/status/revocation/v1",
|
|
60
|
+
mockStatusListCredential
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const result = await storage.getStatusList(
|
|
64
|
+
"https://example.com/status/revocation/v1"
|
|
65
|
+
);
|
|
66
|
+
expect(result).toEqual(mockStatusListCredential);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should overwrite existing status list", async () => {
|
|
70
|
+
await storage.setStatusList(
|
|
71
|
+
"https://example.com/status/revocation/v1",
|
|
72
|
+
mockStatusListCredential
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const updatedCredential = {
|
|
76
|
+
...mockStatusListCredential,
|
|
77
|
+
issuanceDate: "2024-01-02T00:00:00Z",
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
await storage.setStatusList(
|
|
81
|
+
"https://example.com/status/revocation/v1",
|
|
82
|
+
updatedCredential
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const result = await storage.getStatusList(
|
|
86
|
+
"https://example.com/status/revocation/v1"
|
|
87
|
+
);
|
|
88
|
+
expect(result?.issuanceDate).toBe("2024-01-02T00:00:00Z");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should store multiple status lists independently", async () => {
|
|
92
|
+
const revocationCredential = mockStatusListCredential;
|
|
93
|
+
const suspensionCredential = {
|
|
94
|
+
...mockStatusListCredential,
|
|
95
|
+
id: "https://example.com/status/suspension/v1",
|
|
96
|
+
credentialSubject: {
|
|
97
|
+
...mockStatusListCredential.credentialSubject,
|
|
98
|
+
id: "https://example.com/status/suspension/v1#list",
|
|
99
|
+
statusPurpose: "suspension" as const,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
await storage.setStatusList(
|
|
104
|
+
"https://example.com/status/revocation/v1",
|
|
105
|
+
revocationCredential
|
|
106
|
+
);
|
|
107
|
+
await storage.setStatusList(
|
|
108
|
+
"https://example.com/status/suspension/v1",
|
|
109
|
+
suspensionCredential
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const revocation = await storage.getStatusList(
|
|
113
|
+
"https://example.com/status/revocation/v1"
|
|
114
|
+
);
|
|
115
|
+
const suspension = await storage.getStatusList(
|
|
116
|
+
"https://example.com/status/suspension/v1"
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
expect(revocation?.credentialSubject.statusPurpose).toBe("revocation");
|
|
120
|
+
expect(suspension?.credentialSubject.statusPurpose).toBe("suspension");
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe("allocateIndex", () => {
|
|
125
|
+
it("should allocate sequential indices starting from 0", async () => {
|
|
126
|
+
const statusListId = "https://example.com/status/revocation/v1";
|
|
127
|
+
|
|
128
|
+
const index1 = await storage.allocateIndex(statusListId);
|
|
129
|
+
const index2 = await storage.allocateIndex(statusListId);
|
|
130
|
+
const index3 = await storage.allocateIndex(statusListId);
|
|
131
|
+
|
|
132
|
+
expect(index1).toBe(0);
|
|
133
|
+
expect(index2).toBe(1);
|
|
134
|
+
expect(index3).toBe(2);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("should allocate indices independently per status list", async () => {
|
|
138
|
+
const list1 = "https://example.com/status/revocation/v1";
|
|
139
|
+
const list2 = "https://example.com/status/suspension/v1";
|
|
140
|
+
|
|
141
|
+
const index1 = await storage.allocateIndex(list1);
|
|
142
|
+
const index2 = await storage.allocateIndex(list2);
|
|
143
|
+
const index3 = await storage.allocateIndex(list1);
|
|
144
|
+
|
|
145
|
+
expect(index1).toBe(0);
|
|
146
|
+
expect(index2).toBe(0); // Independent counter
|
|
147
|
+
expect(index3).toBe(1);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("should continue from previous allocation after clear", async () => {
|
|
151
|
+
const statusListId = "https://example.com/status/revocation/v1";
|
|
152
|
+
|
|
153
|
+
await storage.allocateIndex(statusListId);
|
|
154
|
+
await storage.allocateIndex(statusListId);
|
|
155
|
+
storage.clear();
|
|
156
|
+
|
|
157
|
+
const index = await storage.allocateIndex(statusListId);
|
|
158
|
+
expect(index).toBe(0); // Starts fresh after clear
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe("getIndexCount", () => {
|
|
163
|
+
it("should return 0 for new status list", () => {
|
|
164
|
+
const count = storage.getIndexCount("https://example.com/status/new");
|
|
165
|
+
expect(count).toBe(0);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("should return current allocation count", async () => {
|
|
169
|
+
const statusListId = "https://example.com/status/revocation/v1";
|
|
170
|
+
|
|
171
|
+
await storage.allocateIndex(statusListId);
|
|
172
|
+
expect(storage.getIndexCount(statusListId)).toBe(1);
|
|
173
|
+
|
|
174
|
+
await storage.allocateIndex(statusListId);
|
|
175
|
+
expect(storage.getIndexCount(statusListId)).toBe(2);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe("clear", () => {
|
|
180
|
+
it("should remove all status lists", async () => {
|
|
181
|
+
await storage.setStatusList(
|
|
182
|
+
"https://example.com/status/revocation/v1",
|
|
183
|
+
mockStatusListCredential
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
storage.clear();
|
|
187
|
+
|
|
188
|
+
const result = await storage.getStatusList(
|
|
189
|
+
"https://example.com/status/revocation/v1"
|
|
190
|
+
);
|
|
191
|
+
expect(result).toBeNull();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should reset index counters", async () => {
|
|
195
|
+
const statusListId = "https://example.com/status/revocation/v1";
|
|
196
|
+
|
|
197
|
+
await storage.allocateIndex(statusListId);
|
|
198
|
+
await storage.allocateIndex(statusListId);
|
|
199
|
+
|
|
200
|
+
storage.clear();
|
|
201
|
+
|
|
202
|
+
expect(storage.getIndexCount(statusListId)).toBe(0);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe("getAllStatusListIds", () => {
|
|
207
|
+
it("should return empty array when no status lists", () => {
|
|
208
|
+
const ids = storage.getAllStatusListIds();
|
|
209
|
+
expect(ids).toEqual([]);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("should return all stored status list IDs", async () => {
|
|
213
|
+
await storage.setStatusList(
|
|
214
|
+
"https://example.com/status/revocation/v1",
|
|
215
|
+
mockStatusListCredential
|
|
216
|
+
);
|
|
217
|
+
await storage.setStatusList("https://example.com/status/suspension/v1", {
|
|
218
|
+
...mockStatusListCredential,
|
|
219
|
+
id: "https://example.com/status/suspension/v1",
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const ids = storage.getAllStatusListIds();
|
|
223
|
+
expect(ids).toContain("https://example.com/status/revocation/v1");
|
|
224
|
+
expect(ids).toContain("https://example.com/status/suspension/v1");
|
|
225
|
+
expect(ids.length).toBe(2);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Implementations
|
|
3
|
+
*
|
|
4
|
+
* Example storage providers for testing and development.
|
|
5
|
+
* Production implementations would use persistent storage (KV, DB, etc.)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export * from './memory-statuslist-storage';
|
|
9
|
+
export * from './memory-graph-storage';
|