@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,265 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
createDidKeyResolver,
|
|
4
|
-
isEd25519DidKey,
|
|
5
|
-
extractPublicKeyFromDidKey,
|
|
6
|
-
publicKeyToJwk,
|
|
7
|
-
resolveDidKeySync,
|
|
8
|
-
} from "../did-key-resolver";
|
|
9
|
-
import { base58Encode, base58Decode, isValidBase58 } from "../../utils/base58";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Tests for did:key resolver and base58 utilities
|
|
13
|
-
*
|
|
14
|
-
* These tests verify the Phase 3 VC verification infrastructure:
|
|
15
|
-
* - Base58 encoding/decoding for multibase keys
|
|
16
|
-
* - did:key resolution to DID Documents
|
|
17
|
-
* - Ed25519 public key extraction
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
describe("Base58 Utilities", () => {
|
|
21
|
-
describe("base58Encode", () => {
|
|
22
|
-
it("should encode empty bytes", () => {
|
|
23
|
-
expect(base58Encode(new Uint8Array([]))).toBe("");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should encode single byte", () => {
|
|
27
|
-
expect(base58Encode(new Uint8Array([0]))).toBe("1");
|
|
28
|
-
expect(base58Encode(new Uint8Array([1])).length).toBeGreaterThan(0);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("should encode known values", () => {
|
|
32
|
-
// 'Hello' in bytes
|
|
33
|
-
const helloBytes = new TextEncoder().encode("Hello");
|
|
34
|
-
const encoded = base58Encode(helloBytes);
|
|
35
|
-
expect(encoded.length).toBeGreaterThan(0);
|
|
36
|
-
expect(isValidBase58(encoded)).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should handle leading zeros", () => {
|
|
40
|
-
const withLeadingZeros = new Uint8Array([0, 0, 1, 2, 3]);
|
|
41
|
-
const encoded = base58Encode(withLeadingZeros);
|
|
42
|
-
// Leading zeros become '1' in base58
|
|
43
|
-
expect(encoded.startsWith("11")).toBe(true);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe("base58Decode", () => {
|
|
48
|
-
it("should decode empty string", () => {
|
|
49
|
-
expect(base58Decode("")).toEqual(new Uint8Array([]));
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should decode leading '1' as zero bytes", () => {
|
|
53
|
-
const result = base58Decode("111");
|
|
54
|
-
expect(result).toEqual(new Uint8Array([0, 0, 0]));
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should throw on invalid characters", () => {
|
|
58
|
-
// '0', 'O', 'I', 'l' are not in base58 alphabet
|
|
59
|
-
expect(() => base58Decode("0invalid")).toThrow("Invalid base58 character");
|
|
60
|
-
expect(() => base58Decode("testO")).toThrow("Invalid base58 character");
|
|
61
|
-
expect(() => base58Decode("testI")).toThrow("Invalid base58 character");
|
|
62
|
-
expect(() => base58Decode("testl")).toThrow("Invalid base58 character");
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("should roundtrip with base58Encode", () => {
|
|
66
|
-
const originalBytes = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
67
|
-
const encoded = base58Encode(originalBytes);
|
|
68
|
-
const decoded = base58Decode(encoded);
|
|
69
|
-
expect(decoded).toEqual(originalBytes);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should roundtrip Ed25519 key bytes", () => {
|
|
73
|
-
// Simulate a 32-byte Ed25519 public key with multicodec prefix
|
|
74
|
-
const ed25519Prefix = new Uint8Array([0xed, 0x01]);
|
|
75
|
-
const mockPublicKey = new Uint8Array(32).fill(42);
|
|
76
|
-
const fullBytes = new Uint8Array([...ed25519Prefix, ...mockPublicKey]);
|
|
77
|
-
|
|
78
|
-
const encoded = base58Encode(fullBytes);
|
|
79
|
-
const decoded = base58Decode(encoded);
|
|
80
|
-
expect(decoded).toEqual(fullBytes);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe("isValidBase58", () => {
|
|
85
|
-
it("should return true for empty string", () => {
|
|
86
|
-
expect(isValidBase58("")).toBe(true);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("should return true for valid base58 strings", () => {
|
|
90
|
-
expect(isValidBase58("123456789")).toBe(true);
|
|
91
|
-
expect(isValidBase58("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")).toBe(true);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("should return false for invalid characters", () => {
|
|
95
|
-
expect(isValidBase58("0")).toBe(false);
|
|
96
|
-
expect(isValidBase58("O")).toBe(false);
|
|
97
|
-
expect(isValidBase58("I")).toBe(false);
|
|
98
|
-
expect(isValidBase58("l")).toBe(false);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe("did:key Resolver", () => {
|
|
104
|
-
// Known test vector for Ed25519 did:key
|
|
105
|
-
// This creates a deterministic did:key from known public key bytes
|
|
106
|
-
const createTestDidKey = (publicKeyBytes: Uint8Array): string => {
|
|
107
|
-
const prefix = new Uint8Array([0xed, 0x01]); // Ed25519 multicodec
|
|
108
|
-
const fullBytes = new Uint8Array([...prefix, ...publicKeyBytes]);
|
|
109
|
-
return `did:key:z${base58Encode(fullBytes)}`;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
describe("isEd25519DidKey", () => {
|
|
113
|
-
it("should return true for Ed25519 did:key", () => {
|
|
114
|
-
// Ed25519 keys start with z6Mk
|
|
115
|
-
expect(isEd25519DidKey("did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK")).toBe(true);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should return false for non-did:key", () => {
|
|
119
|
-
expect(isEd25519DidKey("did:web:example.com")).toBe(false);
|
|
120
|
-
expect(isEd25519DidKey("did:example:123")).toBe(false);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should return false for non-Ed25519 did:key", () => {
|
|
124
|
-
// Secp256k1 keys start with z6Ls or other prefixes
|
|
125
|
-
expect(isEd25519DidKey("did:key:z7r8os")).toBe(false);
|
|
126
|
-
expect(isEd25519DidKey("did:key:zQ3s")).toBe(false);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("should return false for invalid did:key format", () => {
|
|
130
|
-
expect(isEd25519DidKey("did:key:")).toBe(false);
|
|
131
|
-
expect(isEd25519DidKey("did:key:invalid")).toBe(false);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("extractPublicKeyFromDidKey", () => {
|
|
136
|
-
it("should extract public key bytes from valid did:key", () => {
|
|
137
|
-
const mockPublicKey = new Uint8Array(32).map((_, i) => i);
|
|
138
|
-
const didKey = createTestDidKey(mockPublicKey);
|
|
139
|
-
|
|
140
|
-
const extractedKey = extractPublicKeyFromDidKey(didKey);
|
|
141
|
-
expect(extractedKey).not.toBeNull();
|
|
142
|
-
expect(extractedKey).toEqual(mockPublicKey);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("should return null for non-did:key", () => {
|
|
146
|
-
expect(extractPublicKeyFromDidKey("did:web:example.com")).toBeNull();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("should return null for invalid multicodec prefix", () => {
|
|
150
|
-
// Create a did:key with wrong prefix (not Ed25519)
|
|
151
|
-
const wrongPrefix = new Uint8Array([0x00, 0x00]); // Not Ed25519
|
|
152
|
-
const mockPublicKey = new Uint8Array(32).fill(1);
|
|
153
|
-
const fullBytes = new Uint8Array([...wrongPrefix, ...mockPublicKey]);
|
|
154
|
-
const invalidDid = `did:key:z${base58Encode(fullBytes)}`;
|
|
155
|
-
|
|
156
|
-
expect(extractPublicKeyFromDidKey(invalidDid)).toBeNull();
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("should return null for too short key", () => {
|
|
160
|
-
const shortBytes = new Uint8Array([0xed, 0x01, 1, 2, 3]); // Only 3 bytes of key
|
|
161
|
-
const shortDid = `did:key:z${base58Encode(shortBytes)}`;
|
|
162
|
-
|
|
163
|
-
expect(extractPublicKeyFromDidKey(shortDid)).toBeNull();
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe("publicKeyToJwk", () => {
|
|
168
|
-
it("should convert public key bytes to JWK format", () => {
|
|
169
|
-
const publicKeyBytes = new Uint8Array(32).map((_, i) => i);
|
|
170
|
-
const jwk = publicKeyToJwk(publicKeyBytes);
|
|
171
|
-
|
|
172
|
-
expect(jwk.kty).toBe("OKP");
|
|
173
|
-
expect(jwk.crv).toBe("Ed25519");
|
|
174
|
-
expect(jwk.x).toBeDefined();
|
|
175
|
-
expect(typeof jwk.x).toBe("string");
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("should produce base64url-encoded x value", () => {
|
|
179
|
-
const publicKeyBytes = new Uint8Array(32).fill(0);
|
|
180
|
-
const jwk = publicKeyToJwk(publicKeyBytes);
|
|
181
|
-
|
|
182
|
-
// Base64url should not contain +, /, or =
|
|
183
|
-
expect(jwk.x).not.toMatch(/[+/=]/);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
describe("createDidKeyResolver", () => {
|
|
188
|
-
it("should resolve Ed25519 did:key to DID Document", async () => {
|
|
189
|
-
const mockPublicKey = new Uint8Array(32).map((_, i) => i);
|
|
190
|
-
const didKey = createTestDidKey(mockPublicKey);
|
|
191
|
-
|
|
192
|
-
const resolver = createDidKeyResolver();
|
|
193
|
-
const didDoc = await resolver.resolve(didKey);
|
|
194
|
-
|
|
195
|
-
expect(didDoc).not.toBeNull();
|
|
196
|
-
expect(didDoc?.id).toBe(didKey);
|
|
197
|
-
expect(didDoc?.verificationMethod).toHaveLength(1);
|
|
198
|
-
expect(didDoc?.verificationMethod?.[0].type).toBe("Ed25519VerificationKey2020");
|
|
199
|
-
expect(didDoc?.verificationMethod?.[0].controller).toBe(didKey);
|
|
200
|
-
expect(didDoc?.verificationMethod?.[0].publicKeyJwk).toBeDefined();
|
|
201
|
-
expect(didDoc?.authentication).toContain(`${didKey}#keys-1`);
|
|
202
|
-
expect(didDoc?.assertionMethod).toContain(`${didKey}#keys-1`);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("should return null for non-Ed25519 did:key", async () => {
|
|
206
|
-
const resolver = createDidKeyResolver();
|
|
207
|
-
const result = await resolver.resolve("did:key:z7r8os");
|
|
208
|
-
|
|
209
|
-
expect(result).toBeNull();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("should return null for non-did:key DIDs", async () => {
|
|
213
|
-
const resolver = createDidKeyResolver();
|
|
214
|
-
const result = await resolver.resolve("did:web:example.com");
|
|
215
|
-
|
|
216
|
-
expect(result).toBeNull();
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
describe("resolveDidKeySync", () => {
|
|
221
|
-
it("should synchronously resolve Ed25519 did:key", () => {
|
|
222
|
-
const mockPublicKey = new Uint8Array(32).map((_, i) => i);
|
|
223
|
-
const didKey = createTestDidKey(mockPublicKey);
|
|
224
|
-
|
|
225
|
-
const didDoc = resolveDidKeySync(didKey);
|
|
226
|
-
|
|
227
|
-
expect(didDoc).not.toBeNull();
|
|
228
|
-
expect(didDoc?.id).toBe(didKey);
|
|
229
|
-
expect(didDoc?.verificationMethod).toHaveLength(1);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("should return null for invalid DIDs", () => {
|
|
233
|
-
expect(resolveDidKeySync("did:web:example.com")).toBeNull();
|
|
234
|
-
expect(resolveDidKeySync("did:key:invalid")).toBeNull();
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
describe("VC-JWT Roundtrip Integration", () => {
|
|
240
|
-
it("should correctly resolve did:key generated by UserDidManager pattern", async () => {
|
|
241
|
-
// This test simulates the pattern used in UserDidManager.generateKeyPair()
|
|
242
|
-
// which creates did:key DIDs for users
|
|
243
|
-
|
|
244
|
-
// Simulate generating a random Ed25519 key (32 bytes)
|
|
245
|
-
const mockPublicKey = crypto.getRandomValues(new Uint8Array(32));
|
|
246
|
-
|
|
247
|
-
// Encode as did:key (same pattern as UserDidManager)
|
|
248
|
-
const multicodecPrefix = new Uint8Array([0xed, 0x01]);
|
|
249
|
-
const multicodecBytes = new Uint8Array([...multicodecPrefix, ...mockPublicKey]);
|
|
250
|
-
const multibaseEncoded = base58Encode(multicodecBytes);
|
|
251
|
-
const didKey = `did:key:z${multibaseEncoded}`;
|
|
252
|
-
|
|
253
|
-
// Verify we can resolve this did:key back to get the public key
|
|
254
|
-
const resolver = createDidKeyResolver();
|
|
255
|
-
const didDoc = await resolver.resolve(didKey);
|
|
256
|
-
|
|
257
|
-
expect(didDoc).not.toBeNull();
|
|
258
|
-
expect(didDoc?.id).toBe(didKey);
|
|
259
|
-
expect(didDoc?.verificationMethod?.[0]?.publicKeyJwk).toBeDefined();
|
|
260
|
-
|
|
261
|
-
// Extract public key and verify it matches
|
|
262
|
-
const extractedKey = extractPublicKeyFromDidKey(didKey);
|
|
263
|
-
expect(extractedKey).toEqual(mockPublicKey);
|
|
264
|
-
});
|
|
265
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { canonicalizeJSON } from "../utils.js";
|
|
3
|
-
|
|
4
|
-
describe("canonicalizeJSON", () => {
|
|
5
|
-
it("should canonicalize null", () => {
|
|
6
|
-
expect(canonicalizeJSON(null)).toBe("null");
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it("should canonicalize boolean true", () => {
|
|
10
|
-
expect(canonicalizeJSON(true)).toBe("true");
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("should canonicalize boolean false", () => {
|
|
14
|
-
expect(canonicalizeJSON(false)).toBe("false");
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("should canonicalize number zero", () => {
|
|
18
|
-
expect(canonicalizeJSON(0)).toBe("0");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should canonicalize positive number", () => {
|
|
22
|
-
expect(canonicalizeJSON(42)).toBe("42");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("should canonicalize negative number", () => {
|
|
26
|
-
expect(canonicalizeJSON(-42)).toBe("-42");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should canonicalize decimal number", () => {
|
|
30
|
-
expect(canonicalizeJSON(3.14)).toBe("3.14");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("should throw error for non-finite number (Infinity)", () => {
|
|
34
|
-
expect(() => canonicalizeJSON(Infinity)).toThrow("Cannot canonicalize non-finite number");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should throw error for non-finite number (NaN)", () => {
|
|
38
|
-
expect(() => canonicalizeJSON(NaN)).toThrow("Cannot canonicalize non-finite number");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("should canonicalize empty string", () => {
|
|
42
|
-
expect(canonicalizeJSON("")).toBe('""');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should canonicalize string", () => {
|
|
46
|
-
expect(canonicalizeJSON("hello")).toBe('"hello"');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("should canonicalize string with special characters", () => {
|
|
50
|
-
expect(canonicalizeJSON('hello "world"')).toBe('"hello \\"world\\""');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("should canonicalize empty array", () => {
|
|
54
|
-
expect(canonicalizeJSON([])).toBe("[]");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should canonicalize array with primitives", () => {
|
|
58
|
-
const result = canonicalizeJSON([1, "two", true, null]);
|
|
59
|
-
expect(result).toBe('[1,"two",true,null]');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should canonicalize nested arrays", () => {
|
|
63
|
-
const result = canonicalizeJSON([[1, 2], [3, 4]]);
|
|
64
|
-
expect(result).toBe("[[1,2],[3,4]]");
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("should canonicalize empty object", () => {
|
|
68
|
-
expect(canonicalizeJSON({})).toBe("{}");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should canonicalize object with sorted keys", () => {
|
|
72
|
-
const obj = { z: 3, a: 1, m: 2 };
|
|
73
|
-
const result = canonicalizeJSON(obj);
|
|
74
|
-
expect(result).toBe('{"a":1,"m":2,"z":3}');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("should canonicalize object with string values", () => {
|
|
78
|
-
const obj = { name: "test", value: "hello" };
|
|
79
|
-
const result = canonicalizeJSON(obj);
|
|
80
|
-
expect(result).toBe('{"name":"test","value":"hello"}');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("should canonicalize nested objects", () => {
|
|
84
|
-
const obj = { a: { b: { c: 1 } } };
|
|
85
|
-
const result = canonicalizeJSON(obj);
|
|
86
|
-
expect(result).toBe('{"a":{"b":{"c":1}}}');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("should canonicalize object with array values", () => {
|
|
90
|
-
const obj = { items: [1, 2, 3] };
|
|
91
|
-
const result = canonicalizeJSON(obj);
|
|
92
|
-
expect(result).toBe('{"items":[1,2,3]}');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should canonicalize complex nested structure", () => {
|
|
96
|
-
const obj = {
|
|
97
|
-
z: "last",
|
|
98
|
-
a: {
|
|
99
|
-
nested: [1, { deep: true }],
|
|
100
|
-
value: 42,
|
|
101
|
-
},
|
|
102
|
-
m: ["array", "values"],
|
|
103
|
-
};
|
|
104
|
-
const result = canonicalizeJSON(obj);
|
|
105
|
-
// Keys should be sorted: a, m, z
|
|
106
|
-
expect(result).toContain('"a"');
|
|
107
|
-
expect(result).toContain('"m"');
|
|
108
|
-
expect(result).toContain('"z"');
|
|
109
|
-
expect(result.indexOf('"a"')).toBeLessThan(result.indexOf('"m"'));
|
|
110
|
-
expect(result.indexOf('"m"')).toBeLessThan(result.indexOf('"z"'));
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("should produce identical output for same input (deterministic)", () => {
|
|
114
|
-
const obj = { z: 3, a: 1, m: 2 };
|
|
115
|
-
const result1 = canonicalizeJSON(obj);
|
|
116
|
-
const result2 = canonicalizeJSON(obj);
|
|
117
|
-
expect(result1).toBe(result2);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("should handle object with null values", () => {
|
|
121
|
-
const obj = { a: null, b: "value" };
|
|
122
|
-
const result = canonicalizeJSON(obj);
|
|
123
|
-
expect(result).toBe('{"a":null,"b":"value"}');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should handle object with boolean values", () => {
|
|
127
|
-
const obj = { enabled: true, disabled: false };
|
|
128
|
-
const result = canonicalizeJSON(obj);
|
|
129
|
-
expect(result).toBe('{"disabled":false,"enabled":true}');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("should throw error for undefined", () => {
|
|
133
|
-
expect(() => canonicalizeJSON(undefined)).toThrow("Cannot canonicalize type: undefined");
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("should throw error for function", () => {
|
|
137
|
-
expect(() => canonicalizeJSON(() => {})).toThrow("Cannot canonicalize type: function");
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("should handle unicode strings", () => {
|
|
141
|
-
const result = canonicalizeJSON("hello 世界");
|
|
142
|
-
expect(result).toBe('"hello 世界"');
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("should handle object with numeric keys (sorted as strings)", () => {
|
|
146
|
-
const obj = { "10": "ten", "2": "two", "1": "one" };
|
|
147
|
-
const result = canonicalizeJSON(obj);
|
|
148
|
-
// Keys sorted lexicographically: "1", "10", "2"
|
|
149
|
-
expect(result).toBe('{"1":"one","10":"ten","2":"two"}');
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|