@kya-os/mcp 1.2.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/CHANGELOG.md +64 -0
- package/LICENSE +21 -0
- package/README.md +135 -0
- package/dist/auth/handshake.d.ts +119 -0
- package/dist/auth/handshake.d.ts.map +1 -0
- package/dist/auth/handshake.js +267 -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 +150 -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 +157 -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 +79 -0
- package/dist/delegation/outbound-headers.d.ts.map +1 -0
- package/dist/delegation/outbound-headers.js +138 -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 +47 -0
- package/dist/delegation/statuslist-manager.d.ts.map +1 -0
- package/dist/delegation/statuslist-manager.js +139 -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/errors.d.ts +42 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +45 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -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 +12 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +12 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/mcpi-transport.d.ts +39 -0
- package/dist/middleware/mcpi-transport.d.ts.map +1 -0
- package/dist/middleware/mcpi-transport.js +121 -0
- package/dist/middleware/mcpi-transport.js.map +1 -0
- package/dist/middleware/with-mcpi-server.d.ts +78 -0
- package/dist/middleware/with-mcpi-server.d.ts.map +1 -0
- package/dist/middleware/with-mcpi-server.js +109 -0
- package/dist/middleware/with-mcpi-server.js.map +1 -0
- package/dist/middleware/with-mcpi.d.ts +202 -0
- package/dist/middleware/with-mcpi.d.ts.map +1 -0
- package/dist/middleware/with-mcpi.js +625 -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 +4 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +4 -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/providers/node-crypto.d.ts +26 -0
- package/dist/providers/node-crypto.d.ts.map +1 -0
- package/dist/providers/node-crypto.js +69 -0
- package/dist/providers/node-crypto.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 +83 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +267 -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 +154 -0
- package/dist/utils/crypto-service.js.map +1 -0
- package/dist/utils/did-helpers.d.ts +168 -0
- package/dist/utils/did-helpers.d.ts.map +1 -0
- package/dist/utils/did-helpers.js +211 -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 +115 -0
- package/schemas/README.md +117 -0
- package/schemas/delegation-credential.json +312 -0
- package/schemas/detached-proof.json +97 -0
- package/schemas/handshake-request.json +84 -0
- package/schemas/handshake-response.json +67 -0
- package/schemas/well-known-mcpi.json +176 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DID Validation and Helper Utilities
|
|
3
|
+
*
|
|
4
|
+
* Centralized utilities for DID validation, normalization, and handling.
|
|
5
|
+
* Promotes DRY principle and consistency across the codebase.
|
|
6
|
+
*
|
|
7
|
+
* @package @kya-os/mcp/utils
|
|
8
|
+
*/
|
|
9
|
+
import { base58Encode } from "./base58.js";
|
|
10
|
+
/**
|
|
11
|
+
* Check if a string is a valid DID format
|
|
12
|
+
*
|
|
13
|
+
* @param did - String to validate
|
|
14
|
+
* @returns true if string starts with "did:"
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* isValidDid("did:key:z6Mk...") // true
|
|
19
|
+
* isValidDid("not-a-did") // false
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function isValidDid(did) {
|
|
23
|
+
return typeof did === "string" && did.startsWith("did:");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the DID method from a DID string
|
|
27
|
+
*
|
|
28
|
+
* @param did - DID string
|
|
29
|
+
* @returns DID method (e.g., "key", "web") or null if invalid
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* getDidMethod("did:key:z6Mk...") // "key"
|
|
34
|
+
* getDidMethod("did:web:example.com") // "web"
|
|
35
|
+
* getDidMethod("invalid") // null
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function getDidMethod(did) {
|
|
39
|
+
if (!isValidDid(did)) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const match = did.match(/^did:([^:]+):/);
|
|
43
|
+
return match?.[1] ?? null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Normalize a DID string (trim whitespace)
|
|
47
|
+
*
|
|
48
|
+
* @param did - DID string to normalize
|
|
49
|
+
* @returns Normalized DID string
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* normalizeDid(" did:key:z6Mk... ") // "did:key:z6Mk..."
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export function normalizeDid(did) {
|
|
57
|
+
return did.trim();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Compare two DIDs for equality (case-sensitive)
|
|
61
|
+
*
|
|
62
|
+
* @param did1 - First DID
|
|
63
|
+
* @param did2 - Second DID
|
|
64
|
+
* @returns true if DIDs are equal (after normalization)
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* compareDids("did:key:z6Mk...", "did:key:z6Mk...") // true
|
|
69
|
+
* compareDids("did:key:z6Mk...", "did:web:example.com") // false
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export function compareDids(did1, did2) {
|
|
73
|
+
return normalizeDid(did1) === normalizeDid(did2);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Extract server DID from config (supports both old and new field names)
|
|
77
|
+
*
|
|
78
|
+
* Supports backward compatibility by reading both `serverDid` and deprecated `agentDid`.
|
|
79
|
+
* Prefers `serverDid` if both are present.
|
|
80
|
+
*
|
|
81
|
+
* @param config - Config object with identity field
|
|
82
|
+
* @returns Server DID string
|
|
83
|
+
* @throws Error if neither serverDid nor agentDid is configured
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // New config
|
|
88
|
+
* getServerDid({ identity: { serverDid: "did:web:example.com" } }) // "did:web:example.com"
|
|
89
|
+
*
|
|
90
|
+
* // Old config (backward compatibility)
|
|
91
|
+
* getServerDid({ identity: { agentDid: "did:web:example.com" } }) // "did:web:example.com"
|
|
92
|
+
*
|
|
93
|
+
* // Prefers serverDid over agentDid
|
|
94
|
+
* getServerDid({ identity: { serverDid: "new", agentDid: "old" } }) // "new"
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export function getServerDid(config) {
|
|
98
|
+
const serverDid = config.identity.serverDid || config.identity.agentDid;
|
|
99
|
+
if (!serverDid) {
|
|
100
|
+
throw new Error("Server DID not configured");
|
|
101
|
+
}
|
|
102
|
+
return serverDid;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Extract agent ID from DID
|
|
106
|
+
*
|
|
107
|
+
* The agent ID is the last component of the DID.
|
|
108
|
+
*
|
|
109
|
+
* @param did - DID string
|
|
110
|
+
* @returns Agent ID (last component of DID)
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* extractAgentId("did:web:example.com:agents:my-agent") // "my-agent"
|
|
115
|
+
* extractAgentId("did:web:localhost:3000:agents:12912feb") // "12912feb"
|
|
116
|
+
* extractAgentId("did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK") // "z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export function extractAgentId(did) {
|
|
120
|
+
const parts = did.split(':');
|
|
121
|
+
// split() always returns at least one element
|
|
122
|
+
return parts[parts.length - 1] ?? did;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Extract agent slug from DID
|
|
126
|
+
*
|
|
127
|
+
* Agent slug is the same as agent ID - the last component of the DID.
|
|
128
|
+
* For DID format: did:web:example.com:agents:my-agent
|
|
129
|
+
* Returns: my-agent
|
|
130
|
+
*
|
|
131
|
+
* @param did - DID string
|
|
132
|
+
* @returns Agent slug (last component of DID)
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* extractAgentSlug("did:web:example.com:agents:my-agent") // "my-agent"
|
|
137
|
+
* extractAgentSlug("did:web:localhost:3000:agents:12912feb") // "12912feb"
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export function extractAgentSlug(did) {
|
|
141
|
+
return extractAgentId(did);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Ed25519 multicodec prefix for did:key encoding
|
|
145
|
+
* As per https://w3c-ccg.github.io/did-method-key/
|
|
146
|
+
*/
|
|
147
|
+
const ED25519_MULTICODEC_PREFIX = new Uint8Array([0xed, 0x01]);
|
|
148
|
+
/**
|
|
149
|
+
* Generate a did:key from Ed25519 public key bytes
|
|
150
|
+
*
|
|
151
|
+
* Following spec: https://w3c-ccg.github.io/did-method-key/
|
|
152
|
+
* Format: did:key:z<multibase-base58btc(<multicodec-ed25519-pub><publicKey>)>
|
|
153
|
+
*
|
|
154
|
+
* @param publicKeyBytes - Ed25519 public key as Uint8Array (32 bytes)
|
|
155
|
+
* @returns did:key string
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const publicKey = new Uint8Array(32); // 32-byte Ed25519 public key
|
|
160
|
+
* const did = generateDidKeyFromBytes(publicKey);
|
|
161
|
+
* // did = "did:key:z6Mk..."
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export function generateDidKeyFromBytes(publicKeyBytes) {
|
|
165
|
+
// Combine multicodec prefix + public key
|
|
166
|
+
const multicodecKey = new Uint8Array(ED25519_MULTICODEC_PREFIX.length + publicKeyBytes.length);
|
|
167
|
+
multicodecKey.set(ED25519_MULTICODEC_PREFIX);
|
|
168
|
+
multicodecKey.set(publicKeyBytes, ED25519_MULTICODEC_PREFIX.length);
|
|
169
|
+
// Base58-btc encode and add multibase prefix 'z'
|
|
170
|
+
const base58Encoded = base58Encode(multicodecKey);
|
|
171
|
+
return `did:key:z${base58Encoded}`;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Generate a did:key from base64-encoded Ed25519 public key
|
|
175
|
+
*
|
|
176
|
+
* Convenience wrapper around generateDidKeyFromBytes for base64-encoded keys.
|
|
177
|
+
*
|
|
178
|
+
* @param publicKeyBase64 - Ed25519 public key as base64 string
|
|
179
|
+
* @returns did:key string
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const publicKeyBase64 = "...base64 encoded key...";
|
|
184
|
+
* const did = generateDidKeyFromBase64(publicKeyBase64);
|
|
185
|
+
* // did = "did:key:z6Mk..."
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export function generateDidKeyFromBase64(publicKeyBase64) {
|
|
189
|
+
// Decode base64 to bytes
|
|
190
|
+
const publicKeyBytes = Uint8Array.from(atob(publicKeyBase64), (c) => c.charCodeAt(0));
|
|
191
|
+
return generateDidKeyFromBytes(publicKeyBytes);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get the spec-compliant fragment identifier for a did:key DID.
|
|
195
|
+
*
|
|
196
|
+
* Per the did:key spec (W3C CCG), the fragment equals the multibase-encoded
|
|
197
|
+
* public key value (the DID-specific-id). For example:
|
|
198
|
+
* did:key:z6MkABC... → z6MkABC...
|
|
199
|
+
*
|
|
200
|
+
* @see https://w3c-ccg.github.io/did-key-spec/#document-creation-algorithm
|
|
201
|
+
* @param did - A did:key DID string
|
|
202
|
+
* @returns The fragment identifier (multibase value), or 'keys-1' as fallback for non-did:key
|
|
203
|
+
*/
|
|
204
|
+
export function didKeyFragment(did) {
|
|
205
|
+
if (did.startsWith('did:key:')) {
|
|
206
|
+
return did.slice('did:key:'.length);
|
|
207
|
+
}
|
|
208
|
+
// Fallback for non-did:key methods
|
|
209
|
+
return 'keys-1';
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=did-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-helpers.js","sourceRoot":"","sources":["../../src/utils/did-helpers.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ed25519 Key Format Constants
|
|
3
|
+
*
|
|
4
|
+
* DER-encoded headers for Ed25519 key formats per RFC 8410 and RFC 5958.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* DER-encoded PKCS#8 header for Ed25519 private keys (RFC 8410 §7, RFC 5958).
|
|
8
|
+
* Prepended to the 32-byte Ed25519 seed to form a valid PKCS#8 private key.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ED25519_PKCS8_DER_HEADER: Uint8Array<ArrayBuffer>;
|
|
11
|
+
/**
|
|
12
|
+
* DER-encoded SPKI header for Ed25519 public keys (RFC 8410 §4).
|
|
13
|
+
* The 32-byte public key follows after this header.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ED25519_SPKI_DER_HEADER_LENGTH = 12;
|
|
16
|
+
/** Ed25519 raw key size in bytes */
|
|
17
|
+
export declare const ED25519_KEY_SIZE = 32;
|
|
18
|
+
//# sourceMappingURL=ed25519-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ed25519-constants.d.ts","sourceRoot":"","sources":["../../src/utils/ed25519-constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,eAAO,MAAM,wBAAwB,yBAGnC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,8BAA8B,KAAK,CAAC;AAEjD,oCAAoC;AACpC,eAAO,MAAM,gBAAgB,KAAK,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ed25519 Key Format Constants
|
|
3
|
+
*
|
|
4
|
+
* DER-encoded headers for Ed25519 key formats per RFC 8410 and RFC 5958.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* DER-encoded PKCS#8 header for Ed25519 private keys (RFC 8410 §7, RFC 5958).
|
|
8
|
+
* Prepended to the 32-byte Ed25519 seed to form a valid PKCS#8 private key.
|
|
9
|
+
*/
|
|
10
|
+
export const ED25519_PKCS8_DER_HEADER = new Uint8Array([
|
|
11
|
+
0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05,
|
|
12
|
+
0x06, 0x03, 0x2b, 0x65, 0x70, 0x04, 0x22, 0x04, 0x20,
|
|
13
|
+
]);
|
|
14
|
+
/**
|
|
15
|
+
* DER-encoded SPKI header for Ed25519 public keys (RFC 8410 §4).
|
|
16
|
+
* The 32-byte public key follows after this header.
|
|
17
|
+
*/
|
|
18
|
+
export const ED25519_SPKI_DER_HEADER_LENGTH = 12;
|
|
19
|
+
/** Ed25519 raw key size in bytes */
|
|
20
|
+
export const ED25519_KEY_SIZE = 32;
|
|
21
|
+
//# sourceMappingURL=ed25519-constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ed25519-constants.js","sourceRoot":"","sources":["../../src/utils/ed25519-constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,UAAU,CAAC;IACrD,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACxC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CACrD,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC;AAEjD,oCAAoC;AACpC,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,wBAAwB,EACxB,8BAA8B,EAC9B,gBAAgB,GACjB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,wBAAwB,EACxB,8BAA8B,EAC9B,gBAAgB,GACjB,MAAM,wBAAwB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kya-os/mcp",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Core library for MCP-I \u2014 delegation, proof, and session primitives for Model Context Protocol Identity",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./delegation": {
|
|
15
|
+
"types": "./dist/delegation/index.d.ts",
|
|
16
|
+
"default": "./dist/delegation/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./auth": {
|
|
19
|
+
"types": "./dist/auth/index.d.ts",
|
|
20
|
+
"default": "./dist/auth/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./proof": {
|
|
23
|
+
"types": "./dist/proof/index.d.ts",
|
|
24
|
+
"default": "./dist/proof/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./session": {
|
|
27
|
+
"types": "./dist/session/index.d.ts",
|
|
28
|
+
"default": "./dist/session/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./providers": {
|
|
31
|
+
"types": "./dist/providers/index.d.ts",
|
|
32
|
+
"default": "./dist/providers/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./logging": {
|
|
35
|
+
"types": "./dist/logging/index.d.ts",
|
|
36
|
+
"default": "./dist/logging/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./types": {
|
|
39
|
+
"types": "./dist/types/protocol.d.ts",
|
|
40
|
+
"default": "./dist/types/protocol.js"
|
|
41
|
+
},
|
|
42
|
+
"./middleware": {
|
|
43
|
+
"types": "./dist/middleware/index.d.ts",
|
|
44
|
+
"default": "./dist/middleware/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./schemas/*.json": "./schemas/*.json",
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist",
|
|
51
|
+
"schemas",
|
|
52
|
+
"LICENSE",
|
|
53
|
+
"README.md",
|
|
54
|
+
"CHANGELOG.md"
|
|
55
|
+
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsc",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"test:watch": "vitest",
|
|
60
|
+
"test:coverage": "vitest run --coverage",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"lint": "eslint src --ext .ts",
|
|
63
|
+
"clean": "rm -rf dist",
|
|
64
|
+
"prepublishOnly": "npm run clean && npm run build && npm run test",
|
|
65
|
+
"demo": "bash scripts/demo.sh",
|
|
66
|
+
"example:server": "npx tsx examples/node-server/server.ts",
|
|
67
|
+
"example:inspector": "npx @modelcontextprotocol/inspector npx tsx examples/node-server/server.ts --stdio"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"jose": "^5.6.3",
|
|
71
|
+
"json-canonicalize": "^2.0.0",
|
|
72
|
+
"zod": "^4.3.6"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@modelcontextprotocol/sdk": ">=1.0.0"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"@modelcontextprotocol/sdk": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@eslint/js": "^10.0.1",
|
|
84
|
+
"@kya-os/consent": "^0.1.37",
|
|
85
|
+
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
86
|
+
"@types/express": "^5.0.6",
|
|
87
|
+
"@types/node": "^20.14.9",
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "^8.57.0",
|
|
89
|
+
"@typescript-eslint/parser": "^8.57.0",
|
|
90
|
+
"@vitest/coverage-v8": "^2.0.0",
|
|
91
|
+
"commander": "^14.0.3",
|
|
92
|
+
"eslint": "^10.0.3",
|
|
93
|
+
"express": "^5.2.1",
|
|
94
|
+
"typescript": "^5.5.3",
|
|
95
|
+
"typescript-eslint": "^8.57.0",
|
|
96
|
+
"vitest": "^2.0.0"
|
|
97
|
+
},
|
|
98
|
+
"keywords": [
|
|
99
|
+
"mcp-i",
|
|
100
|
+
"mcp",
|
|
101
|
+
"delegation",
|
|
102
|
+
"verifiable-credentials",
|
|
103
|
+
"did",
|
|
104
|
+
"protocol",
|
|
105
|
+
"identity",
|
|
106
|
+
"dif"
|
|
107
|
+
],
|
|
108
|
+
"repository": {
|
|
109
|
+
"type": "git",
|
|
110
|
+
"url": "https://github.com/modelcontextprotocol-identity/mcp-i-core"
|
|
111
|
+
},
|
|
112
|
+
"publishConfig": {
|
|
113
|
+
"access": "public"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# MCP-I JSON Schemas
|
|
2
|
+
|
|
3
|
+
This directory contains JSON Schema definitions for the core MCP-I (Model Context Protocol - Identity) protocol messages.
|
|
4
|
+
|
|
5
|
+
## Schemas
|
|
6
|
+
|
|
7
|
+
| Schema | Description |
|
|
8
|
+
|--------|-------------|
|
|
9
|
+
| [handshake-request.json](./handshake-request.json) | Client-initiated session establishment request |
|
|
10
|
+
| [handshake-response.json](./handshake-response.json) | Server response with session context |
|
|
11
|
+
| [delegation-credential.json](./delegation-credential.json) | W3C Verifiable Credential for delegations |
|
|
12
|
+
| [detached-proof.json](./detached-proof.json) | Cryptographic proof for tool request/response |
|
|
13
|
+
| [well-known-mcpi.json](./well-known-mcpi.json) | Service discovery document |
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Validation with Node.js (Ajv)
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import Ajv from 'ajv';
|
|
21
|
+
import addFormats from 'ajv-formats';
|
|
22
|
+
import handshakeRequestSchema from './schemas/handshake-request.json';
|
|
23
|
+
|
|
24
|
+
const ajv = new Ajv({ strict: true });
|
|
25
|
+
addFormats(ajv);
|
|
26
|
+
|
|
27
|
+
const validate = ajv.compile(handshakeRequestSchema);
|
|
28
|
+
|
|
29
|
+
const request = {
|
|
30
|
+
nonce: 'k7Hy9mNpQrStUvWxYz01Aa',
|
|
31
|
+
audience: 'did:web:example.com',
|
|
32
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
33
|
+
agentDid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK'
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if (validate(request)) {
|
|
37
|
+
console.log('Valid handshake request');
|
|
38
|
+
} else {
|
|
39
|
+
console.error('Validation errors:', validate.errors);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Validation with Python (jsonschema)
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import json
|
|
47
|
+
from jsonschema import validate, ValidationError
|
|
48
|
+
|
|
49
|
+
with open('schemas/handshake-request.json') as f:
|
|
50
|
+
schema = json.load(f)
|
|
51
|
+
|
|
52
|
+
request = {
|
|
53
|
+
"nonce": "k7Hy9mNpQrStUvWxYz01Aa",
|
|
54
|
+
"audience": "did:web:example.com",
|
|
55
|
+
"timestamp": 1710268800
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
validate(instance=request, schema=schema)
|
|
60
|
+
print("Valid handshake request")
|
|
61
|
+
except ValidationError as e:
|
|
62
|
+
print(f"Validation error: {e.message}")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Schema References
|
|
66
|
+
|
|
67
|
+
All schemas use JSON Schema draft 2020-12 and are published at:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
https://schema.modelcontextprotocol-identity.io/xmcp-i/{category}/{schema-name}.v1.0.0.json
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Schemas can reference each other using `$ref`. For example, the delegation credential schema references shared definitions for constraints and proof structures.
|
|
74
|
+
|
|
75
|
+
## Protocol Flow
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
┌────────┐ ┌────────┐
|
|
79
|
+
│ Client │ │ Server │
|
|
80
|
+
└───┬────┘ └───┬────┘
|
|
81
|
+
│ │
|
|
82
|
+
│ GET /.well-known/mcpi │
|
|
83
|
+
│──────────────────────────────────>│
|
|
84
|
+
│ (well-known-mcpi.json) │
|
|
85
|
+
│<──────────────────────────────────│
|
|
86
|
+
│ │
|
|
87
|
+
│ POST /handshake │
|
|
88
|
+
│ (handshake-request.json) │
|
|
89
|
+
│──────────────────────────────────>│
|
|
90
|
+
│ (handshake-response.json) │
|
|
91
|
+
│<──────────────────────────────────│
|
|
92
|
+
│ │
|
|
93
|
+
│ POST /tools/{method} │
|
|
94
|
+
│ + X-Session-Id header │
|
|
95
|
+
│──────────────────────────────────>│
|
|
96
|
+
│ Response + detached-proof.json │
|
|
97
|
+
│<──────────────────────────────────│
|
|
98
|
+
│ │
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Specification Reference
|
|
102
|
+
|
|
103
|
+
These schemas implement types defined in the [MCP-I Specification](../SPEC.md):
|
|
104
|
+
|
|
105
|
+
- **Handshake**: SPEC.md §4.5–4.9
|
|
106
|
+
- **Delegation Credentials**: SPEC.md §4.1–4.2
|
|
107
|
+
- **Detached Proofs**: SPEC.md §5
|
|
108
|
+
- **Discovery**: SPEC.md §14 (Transport Binding)
|
|
109
|
+
|
|
110
|
+
## Contributing
|
|
111
|
+
|
|
112
|
+
When modifying schemas:
|
|
113
|
+
|
|
114
|
+
1. Ensure backward compatibility or increment the schema version
|
|
115
|
+
2. Update the `examples` array with valid instances
|
|
116
|
+
3. Run validation tests against the examples
|
|
117
|
+
4. Update this README if adding new schemas
|