@kya-os/mcp-i-core 1.7.0 → 1.8.1
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/README.md +1 -1
- package/dist/conformance/capability-verifier-adapter.d.ts +66 -0
- package/dist/conformance/capability-verifier-adapter.js +61 -0
- package/dist/conformance/index.d.ts +10 -0
- package/dist/conformance/index.js +19 -0
- package/dist/conformance/validate-level2.d.ts +203 -0
- package/dist/conformance/validate-level2.js +294 -0
- package/dist/conformance/vc-jwt-verifier.d.ts +55 -0
- package/dist/conformance/vc-jwt-verifier.js +147 -0
- package/dist/delegation/did-web-resolver.d.ts +60 -0
- package/dist/delegation/did-web-resolver.js +129 -0
- package/dist/delegation/outbound-proof.d.ts +3 -2
- package/dist/delegation/outbound-proof.js +3 -2
- package/dist/delegation/utils.d.ts +3 -1
- package/dist/index.d.ts +9 -63
- package/dist/index.js +22 -161
- package/dist/utils/base58.d.ts +4 -28
- package/dist/utils/base58.js +18 -98
- package/dist/utils/base64.d.ts +4 -29
- package/dist/utils/base64.js +18 -167
- package/dist/utils/did-helpers.d.ts +4 -165
- package/dist/utils/did-helpers.js +18 -217
- package/package.json +5 -7
- package/dist/auth/handshake.d.ts +0 -119
- package/dist/auth/handshake.js +0 -250
- package/dist/auth/index.d.ts +0 -6
- package/dist/auth/index.js +0 -11
- package/dist/auth/types.d.ts +0 -46
- package/dist/auth/types.js +0 -10
- package/dist/cache/oauth-config-cache.d.ts +0 -69
- package/dist/cache/oauth-config-cache.js +0 -76
- package/dist/cache/tool-protection-cache.d.ts +0 -89
- package/dist/cache/tool-protection-cache.js +0 -118
- package/dist/compliance/index.d.ts +0 -8
- package/dist/compliance/index.js +0 -24
- package/dist/compliance/schema-registry.d.ts +0 -50
- package/dist/compliance/schema-registry.js +0 -438
- package/dist/compliance/schema-verifier.d.ts +0 -110
- package/dist/compliance/schema-verifier.js +0 -518
- package/dist/config/remote-config.d.ts +0 -173
- package/dist/config/remote-config.js +0 -253
- package/dist/config.d.ts +0 -182
- package/dist/config.js +0 -148
- package/dist/identity/idp-token-resolver.d.ts +0 -69
- package/dist/identity/idp-token-resolver.js +0 -136
- package/dist/identity/idp-token-storage.interface.d.ts +0 -80
- package/dist/identity/idp-token-storage.interface.js +0 -14
- package/dist/identity/user-did-manager.d.ts +0 -228
- package/dist/identity/user-did-manager.js +0 -356
- package/dist/logging/index.d.ts +0 -5
- package/dist/logging/index.js +0 -10
- package/dist/logging/logger.d.ts +0 -33
- package/dist/logging/logger.js +0 -104
- package/dist/proof/generator.d.ts +0 -109
- package/dist/proof/generator.js +0 -236
- package/dist/proof/index.d.ts +0 -5
- package/dist/proof/index.js +0 -11
- package/dist/providers/base.d.ts +0 -95
- package/dist/providers/base.js +0 -47
- package/dist/providers/memory.d.ts +0 -42
- package/dist/providers/memory.js +0 -121
- package/dist/runtime/audit-logger.d.ts +0 -37
- package/dist/runtime/audit-logger.js +0 -9
- package/dist/runtime/base.d.ts +0 -375
- package/dist/runtime/base.js +0 -1491
- package/dist/runtime/ext-apps-constants.d.ts +0 -14
- package/dist/runtime/ext-apps-constants.js +0 -17
- package/dist/services/access-control.service.d.ts +0 -138
- package/dist/services/access-control.service.js +0 -721
- package/dist/services/authorization/authorization-registry.d.ts +0 -29
- package/dist/services/authorization/authorization-registry.js +0 -58
- package/dist/services/authorization/types.d.ts +0 -53
- package/dist/services/authorization/types.js +0 -10
- package/dist/services/batch-delegation.service.d.ts +0 -53
- package/dist/services/batch-delegation.service.js +0 -95
- package/dist/services/crypto.service.d.ts +0 -69
- package/dist/services/crypto.service.js +0 -225
- package/dist/services/delegation-error-formatter.d.ts +0 -124
- package/dist/services/delegation-error-formatter.js +0 -214
- package/dist/services/errors.d.ts +0 -49
- package/dist/services/errors.js +0 -66
- package/dist/services/index.d.ts +0 -9
- package/dist/services/index.js +0 -15
- package/dist/services/oauth-config.service.d.ts +0 -53
- package/dist/services/oauth-config.service.js +0 -141
- package/dist/services/oauth-provider-registry.d.ts +0 -88
- package/dist/services/oauth-provider-registry.js +0 -128
- package/dist/services/oauth-service.d.ts +0 -122
- package/dist/services/oauth-service.js +0 -442
- package/dist/services/oauth-token-retrieval.service.d.ts +0 -49
- package/dist/services/oauth-token-retrieval.service.js +0 -150
- package/dist/services/policy.service.d.ts +0 -130
- package/dist/services/policy.service.js +0 -399
- package/dist/services/proof-verifier.d.ts +0 -98
- package/dist/services/proof-verifier.js +0 -319
- package/dist/services/provider-resolver.d.ts +0 -89
- package/dist/services/provider-resolver.js +0 -196
- package/dist/services/provider-validator.d.ts +0 -55
- package/dist/services/provider-validator.js +0 -135
- package/dist/services/session-registration.service.d.ts +0 -80
- package/dist/services/session-registration.service.js +0 -174
- package/dist/services/storage.service.d.ts +0 -116
- package/dist/services/storage.service.js +0 -411
- package/dist/services/tool-context-builder.d.ts +0 -74
- package/dist/services/tool-context-builder.js +0 -215
- package/dist/services/tool-protection.service.d.ts +0 -193
- package/dist/services/tool-protection.service.js +0 -736
- package/dist/session/index.d.ts +0 -5
- package/dist/session/index.js +0 -11
- package/dist/session/manager.d.ts +0 -113
- package/dist/session/manager.js +0 -273
- package/dist/types/oauth-required-error.d.ts +0 -46
- package/dist/types/oauth-required-error.js +0 -42
- package/dist/types/tool-protection.d.ts +0 -144
- package/dist/types/tool-protection.js +0 -48
- package/dist/utils/cors.d.ts +0 -44
- package/dist/utils/cors.js +0 -71
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.js +0 -24
- package/dist/utils/storage-keys.d.ts +0 -120
- package/dist/utils/storage-keys.js +0 -217
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VC-JWT Signature Verifier
|
|
3
|
+
*
|
|
4
|
+
* A {@link CapabilityVCSignatureVerifier} (the pluggable signature hook accepted
|
|
5
|
+
* by {@link verifyCapabilities}) that cryptographically verifies a capability
|
|
6
|
+
* attestation presented as a compact VC-JWT (JWS).
|
|
7
|
+
*
|
|
8
|
+
* Flow:
|
|
9
|
+
* 1. If no compact JWS was supplied (object-form VC) → reject. There is
|
|
10
|
+
* nothing to verify cryptographically.
|
|
11
|
+
* 2. Resolve the credential's `issuer` DID via a combined, pluggable resolver
|
|
12
|
+
* (did:key built in, plus the did:web resolver).
|
|
13
|
+
* 3. Select the verification method whose id matches the JWS header `kid`.
|
|
14
|
+
* 4. Import its `publicKeyJwk` as an EdDSA key and verify the compact JWS.
|
|
15
|
+
*
|
|
16
|
+
* The verifier never throws — every failure path returns
|
|
17
|
+
* `{ valid: false, reason }` so it composes cleanly inside the validator's
|
|
18
|
+
* per-attestation loop.
|
|
19
|
+
*
|
|
20
|
+
* @see ./validate-level2.ts — the validator this plugs into.
|
|
21
|
+
*/
|
|
22
|
+
import { type DidWebFetch } from '../delegation/did-web-resolver.js';
|
|
23
|
+
import type { DIDResolver } from '../delegation/vc-verifier.js';
|
|
24
|
+
import type { CapabilityVCSignatureVerifier } from './validate-level2.js';
|
|
25
|
+
/** Options for {@link createVcJwtSignatureVerifier}. */
|
|
26
|
+
export interface VcJwtVerifierOptions {
|
|
27
|
+
/**
|
|
28
|
+
* DID resolver used to fetch the issuer's verification keys. Defaults to a
|
|
29
|
+
* combined did:key + did:web resolver (see {@link createCombinedDidResolver}).
|
|
30
|
+
*/
|
|
31
|
+
didResolver?: DIDResolver;
|
|
32
|
+
/**
|
|
33
|
+
* Pluggable fetch passed to the default did:web resolver. Ignored when a
|
|
34
|
+
* `didResolver` is supplied. Defaults to the global `fetch`.
|
|
35
|
+
*/
|
|
36
|
+
fetch?: DidWebFetch;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a DID resolver that dispatches by method: did:key is resolved locally,
|
|
40
|
+
* did:web is fetched over HTTPS, and every other method resolves to `null`.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Optional pluggable fetch for the did:web branch.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createCombinedDidResolver(options?: {
|
|
45
|
+
fetch?: DidWebFetch;
|
|
46
|
+
}): DIDResolver;
|
|
47
|
+
/**
|
|
48
|
+
* Create a VC-JWT signature verifier suitable for
|
|
49
|
+
* {@link verifyCapabilities}'s `signatureVerifier` option.
|
|
50
|
+
*
|
|
51
|
+
* @param options - DID resolver / fetch overrides.
|
|
52
|
+
* @returns A `(vc, rawJwt) => Promise<{ valid; reason? }>` function.
|
|
53
|
+
*/
|
|
54
|
+
export declare function createVcJwtSignatureVerifier(options?: VcJwtVerifierOptions): CapabilityVCSignatureVerifier;
|
|
55
|
+
//# sourceMappingURL=vc-jwt-verifier.d.ts.map
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* VC-JWT Signature Verifier
|
|
4
|
+
*
|
|
5
|
+
* A {@link CapabilityVCSignatureVerifier} (the pluggable signature hook accepted
|
|
6
|
+
* by {@link verifyCapabilities}) that cryptographically verifies a capability
|
|
7
|
+
* attestation presented as a compact VC-JWT (JWS).
|
|
8
|
+
*
|
|
9
|
+
* Flow:
|
|
10
|
+
* 1. If no compact JWS was supplied (object-form VC) → reject. There is
|
|
11
|
+
* nothing to verify cryptographically.
|
|
12
|
+
* 2. Resolve the credential's `issuer` DID via a combined, pluggable resolver
|
|
13
|
+
* (did:key built in, plus the did:web resolver).
|
|
14
|
+
* 3. Select the verification method whose id matches the JWS header `kid`.
|
|
15
|
+
* 4. Import its `publicKeyJwk` as an EdDSA key and verify the compact JWS.
|
|
16
|
+
*
|
|
17
|
+
* The verifier never throws — every failure path returns
|
|
18
|
+
* `{ valid: false, reason }` so it composes cleanly inside the validator's
|
|
19
|
+
* per-attestation loop.
|
|
20
|
+
*
|
|
21
|
+
* @see ./validate-level2.ts — the validator this plugs into.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.createCombinedDidResolver = createCombinedDidResolver;
|
|
25
|
+
exports.createVcJwtSignatureVerifier = createVcJwtSignatureVerifier;
|
|
26
|
+
const jose_1 = require("jose");
|
|
27
|
+
const did_key_resolver_js_1 = require("../delegation/did-key-resolver.js");
|
|
28
|
+
const did_web_resolver_js_1 = require("../delegation/did-web-resolver.js");
|
|
29
|
+
/**
|
|
30
|
+
* Create a DID resolver that dispatches by method: did:key is resolved locally,
|
|
31
|
+
* did:web is fetched over HTTPS, and every other method resolves to `null`.
|
|
32
|
+
*
|
|
33
|
+
* @param options - Optional pluggable fetch for the did:web branch.
|
|
34
|
+
*/
|
|
35
|
+
function createCombinedDidResolver(options = {}) {
|
|
36
|
+
const didKey = (0, did_key_resolver_js_1.createDidKeyResolver)();
|
|
37
|
+
const didWeb = (0, did_web_resolver_js_1.createDidWebResolver)({ fetch: options.fetch });
|
|
38
|
+
return {
|
|
39
|
+
resolve: async (did) => {
|
|
40
|
+
if (did.startsWith('did:key:'))
|
|
41
|
+
return didKey.resolve(did);
|
|
42
|
+
if (did.startsWith('did:web:'))
|
|
43
|
+
return didWeb.resolve(did);
|
|
44
|
+
return null;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a VC-JWT signature verifier suitable for
|
|
50
|
+
* {@link verifyCapabilities}'s `signatureVerifier` option.
|
|
51
|
+
*
|
|
52
|
+
* @param options - DID resolver / fetch overrides.
|
|
53
|
+
* @returns A `(vc, rawJwt) => Promise<{ valid; reason? }>` function.
|
|
54
|
+
*/
|
|
55
|
+
function createVcJwtSignatureVerifier(options = {}) {
|
|
56
|
+
const resolver = options.didResolver ?? createCombinedDidResolver({ fetch: options.fetch });
|
|
57
|
+
return async (vc, rawJwt) => {
|
|
58
|
+
if (rawJwt === undefined) {
|
|
59
|
+
return { valid: false, reason: 'no compact JWS' };
|
|
60
|
+
}
|
|
61
|
+
const issuerDid = extractIssuerDid(vc);
|
|
62
|
+
if (!issuerDid) {
|
|
63
|
+
return { valid: false, reason: 'VC missing issuer' };
|
|
64
|
+
}
|
|
65
|
+
let kid;
|
|
66
|
+
try {
|
|
67
|
+
kid = (0, jose_1.decodeProtectedHeader)(rawJwt).kid;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return { valid: false, reason: 'malformed JWS protected header' };
|
|
71
|
+
}
|
|
72
|
+
let didDoc;
|
|
73
|
+
try {
|
|
74
|
+
didDoc = await resolver.resolve(issuerDid);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
return {
|
|
78
|
+
valid: false,
|
|
79
|
+
reason: `issuer resolution failed: ${errorMessage(err)}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (!didDoc) {
|
|
83
|
+
return { valid: false, reason: `could not resolve issuer ${issuerDid}` };
|
|
84
|
+
}
|
|
85
|
+
const method = selectVerificationMethod(didDoc, kid);
|
|
86
|
+
if (!method?.publicKeyJwk) {
|
|
87
|
+
return {
|
|
88
|
+
valid: false,
|
|
89
|
+
reason: kid
|
|
90
|
+
? `no verification method matching kid ${kid}`
|
|
91
|
+
: 'no verification method with a publicKeyJwk',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const key = await (0, jose_1.importJWK)(method.publicKeyJwk, 'EdDSA');
|
|
96
|
+
await (0, jose_1.compactVerify)(rawJwt, key);
|
|
97
|
+
return { valid: true };
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
return {
|
|
101
|
+
valid: false,
|
|
102
|
+
reason: `signature verification failed: ${errorMessage(err)}`,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Select the verification method to verify against.
|
|
109
|
+
*
|
|
110
|
+
* When the JWS carries a `kid`, prefer an exact id match; only when none exists
|
|
111
|
+
* fall back to matching by fragment — so a fragment-only kid (`#key-1`) and a
|
|
112
|
+
* fully-qualified id (`did:web:example#key-1`), both common across did:web
|
|
113
|
+
* documents and JWTs, still resolve to the same key, while a later exact match
|
|
114
|
+
* is never shadowed by an earlier fragment-only one. Stays fail-closed: a kid
|
|
115
|
+
* that matches no method is rejected, and a wrongly-matched key fails the
|
|
116
|
+
* subsequent signature check. Without a `kid`, fall back to the first method
|
|
117
|
+
* with a `publicKeyJwk`.
|
|
118
|
+
*/
|
|
119
|
+
function selectVerificationMethod(didDoc, kid) {
|
|
120
|
+
const methods = didDoc.verificationMethod ?? [];
|
|
121
|
+
if (kid) {
|
|
122
|
+
const exact = methods.find((method) => method.id === kid);
|
|
123
|
+
if (exact)
|
|
124
|
+
return exact;
|
|
125
|
+
const kidFragment = fragmentOf(kid);
|
|
126
|
+
return methods.find((method) => fragmentOf(method.id) === kidFragment);
|
|
127
|
+
}
|
|
128
|
+
return methods.find((method) => method.publicKeyJwk);
|
|
129
|
+
}
|
|
130
|
+
/** The fragment of a DID-URL reference (the part after `#`), or the whole ref if none. */
|
|
131
|
+
function fragmentOf(ref) {
|
|
132
|
+
const hash = ref.indexOf('#');
|
|
133
|
+
return hash >= 0 ? ref.slice(hash + 1) : ref;
|
|
134
|
+
}
|
|
135
|
+
function extractIssuerDid(vc) {
|
|
136
|
+
const issuer = vc.issuer;
|
|
137
|
+
if (typeof issuer === 'string')
|
|
138
|
+
return issuer;
|
|
139
|
+
if (issuer && typeof issuer === 'object' && typeof issuer.id === 'string') {
|
|
140
|
+
return issuer.id;
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
function errorMessage(err) {
|
|
145
|
+
return err instanceof Error ? err.message : String(err);
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=vc-jwt-verifier.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* did:web Resolver
|
|
3
|
+
*
|
|
4
|
+
* Resolves did:web DIDs to DID Documents by fetching the well-known document
|
|
5
|
+
* over HTTPS, per the did:web method spec.
|
|
6
|
+
*
|
|
7
|
+
* URL mapping (did:web method spec §3.2):
|
|
8
|
+
* did:web:example.com → https://example.com/.well-known/did.json
|
|
9
|
+
* did:web:example.com:a:b → https://example.com/a/b/did.json
|
|
10
|
+
* did:web:example.com%3A3000 → https://example.com:3000/.well-known/did.json
|
|
11
|
+
*
|
|
12
|
+
* Percent-encoded characters in each colon-separated segment are decoded
|
|
13
|
+
* (notably `%3A` for a host:port colon).
|
|
14
|
+
*
|
|
15
|
+
* The fetch implementation is pluggable so callers — and tests — can supply
|
|
16
|
+
* their own transport; it defaults to the global `fetch`. The resolver never
|
|
17
|
+
* throws: a non-did:web input, non-OK response, malformed document, or
|
|
18
|
+
* transport error all resolve to `null`.
|
|
19
|
+
*
|
|
20
|
+
* Mirrors the shape of {@link createDidKeyResolver}.
|
|
21
|
+
*
|
|
22
|
+
* @see https://w3c-ccg.github.io/did-method-web/
|
|
23
|
+
*/
|
|
24
|
+
import type { DIDResolver } from './vc-verifier';
|
|
25
|
+
/** Minimal subset of a fetch `Response` consumed by the resolver. */
|
|
26
|
+
export interface DidWebFetchResponse {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
json(): Promise<unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Pluggable fetch signature. The global `fetch` satisfies this structurally,
|
|
32
|
+
* so it is the default.
|
|
33
|
+
*/
|
|
34
|
+
export type DidWebFetch = (url: string) => Promise<DidWebFetchResponse>;
|
|
35
|
+
/** Options for {@link createDidWebResolver}. */
|
|
36
|
+
export interface DidWebResolverOptions {
|
|
37
|
+
/** Transport used to retrieve the DID document. Defaults to global `fetch`. */
|
|
38
|
+
fetch?: DidWebFetch;
|
|
39
|
+
/**
|
|
40
|
+
* Max time (ms) to wait for the DID document before failing closed (returning
|
|
41
|
+
* `null`). Guards against a stalled issuer endpoint hanging verification.
|
|
42
|
+
* Defaults to {@link DEFAULT_TIMEOUT_MS}.
|
|
43
|
+
*/
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Convert a did:web DID into the HTTPS URL of its DID document.
|
|
48
|
+
*
|
|
49
|
+
* @param did - The did:web DID to map.
|
|
50
|
+
* @returns The document URL, or `null` if the DID is not a well-formed did:web.
|
|
51
|
+
*/
|
|
52
|
+
export declare function didWebToUrl(did: string): string | null;
|
|
53
|
+
/**
|
|
54
|
+
* Create a did:web resolver.
|
|
55
|
+
*
|
|
56
|
+
* @param options - Optional pluggable fetch transport.
|
|
57
|
+
* @returns A {@link DIDResolver} for did:web DIDs.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createDidWebResolver(options?: DidWebResolverOptions): DIDResolver;
|
|
60
|
+
//# sourceMappingURL=did-web-resolver.d.ts.map
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* did:web Resolver
|
|
4
|
+
*
|
|
5
|
+
* Resolves did:web DIDs to DID Documents by fetching the well-known document
|
|
6
|
+
* over HTTPS, per the did:web method spec.
|
|
7
|
+
*
|
|
8
|
+
* URL mapping (did:web method spec §3.2):
|
|
9
|
+
* did:web:example.com → https://example.com/.well-known/did.json
|
|
10
|
+
* did:web:example.com:a:b → https://example.com/a/b/did.json
|
|
11
|
+
* did:web:example.com%3A3000 → https://example.com:3000/.well-known/did.json
|
|
12
|
+
*
|
|
13
|
+
* Percent-encoded characters in each colon-separated segment are decoded
|
|
14
|
+
* (notably `%3A` for a host:port colon).
|
|
15
|
+
*
|
|
16
|
+
* The fetch implementation is pluggable so callers — and tests — can supply
|
|
17
|
+
* their own transport; it defaults to the global `fetch`. The resolver never
|
|
18
|
+
* throws: a non-did:web input, non-OK response, malformed document, or
|
|
19
|
+
* transport error all resolve to `null`.
|
|
20
|
+
*
|
|
21
|
+
* Mirrors the shape of {@link createDidKeyResolver}.
|
|
22
|
+
*
|
|
23
|
+
* @see https://w3c-ccg.github.io/did-method-web/
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.didWebToUrl = didWebToUrl;
|
|
27
|
+
exports.createDidWebResolver = createDidWebResolver;
|
|
28
|
+
/** did:web method prefix. */
|
|
29
|
+
const DID_WEB_PREFIX = 'did:web:';
|
|
30
|
+
/** Default time budget (ms) for retrieving a DID document before failing closed. */
|
|
31
|
+
const DEFAULT_TIMEOUT_MS = 5000;
|
|
32
|
+
/**
|
|
33
|
+
* Convert a did:web DID into the HTTPS URL of its DID document.
|
|
34
|
+
*
|
|
35
|
+
* @param did - The did:web DID to map.
|
|
36
|
+
* @returns The document URL, or `null` if the DID is not a well-formed did:web.
|
|
37
|
+
*/
|
|
38
|
+
function didWebToUrl(did) {
|
|
39
|
+
if (!did.startsWith(DID_WEB_PREFIX)) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const identifier = did.slice(DID_WEB_PREFIX.length);
|
|
43
|
+
if (identifier.length === 0) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const segments = identifier.split(':');
|
|
47
|
+
let host;
|
|
48
|
+
let path;
|
|
49
|
+
try {
|
|
50
|
+
host = decodeURIComponent(segments[0]);
|
|
51
|
+
path = segments.slice(1).map((segment) => decodeURIComponent(segment));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Malformed percent-encoding (decodeURIComponent throws URIError).
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (host.length === 0 || path.some((segment) => segment.length === 0)) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const suffix = path.length === 0
|
|
61
|
+
? '/.well-known/did.json'
|
|
62
|
+
: `/${path.join('/')}/did.json`;
|
|
63
|
+
return `https://${host}${suffix}`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a did:web resolver.
|
|
67
|
+
*
|
|
68
|
+
* @param options - Optional pluggable fetch transport.
|
|
69
|
+
* @returns A {@link DIDResolver} for did:web DIDs.
|
|
70
|
+
*/
|
|
71
|
+
function createDidWebResolver(options = {}) {
|
|
72
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
73
|
+
const doFetch = options.fetch ?? ((url) => fetch(url, { signal: AbortSignal.timeout(timeoutMs) }));
|
|
74
|
+
return {
|
|
75
|
+
resolve: async (did) => {
|
|
76
|
+
const url = didWebToUrl(did);
|
|
77
|
+
if (!url) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
let response;
|
|
81
|
+
try {
|
|
82
|
+
response = await withTimeout(doFetch(url), timeoutMs);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// Transport error, abort, or timeout → fail closed.
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
let doc;
|
|
92
|
+
try {
|
|
93
|
+
doc = await response.json();
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return isDidDocument(doc) ? doc : null;
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Minimal structural check: a DID Document is an object with a string `id`.
|
|
104
|
+
*/
|
|
105
|
+
function isDidDocument(value) {
|
|
106
|
+
return (typeof value === 'object' &&
|
|
107
|
+
value !== null &&
|
|
108
|
+
typeof value.id === 'string');
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Reject if `promise` does not settle within `ms`, so a stalled fetch fails
|
|
112
|
+
* closed (the resolver returns `null`) instead of hanging verification
|
|
113
|
+
* indefinitely. The default transport additionally aborts the underlying request
|
|
114
|
+
* via `AbortSignal.timeout`; this race also bounds a custom transport.
|
|
115
|
+
*/
|
|
116
|
+
async function withTimeout(promise, ms) {
|
|
117
|
+
let timer;
|
|
118
|
+
const timeout = new Promise((_, reject) => {
|
|
119
|
+
timer = setTimeout(() => reject(new Error(`did:web fetch timed out after ${ms}ms`)), ms);
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
return await Promise.race([promise, timeout]);
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
if (timer)
|
|
126
|
+
clearTimeout(timer);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=did-web-resolver.js.map
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* without trusting the MCP server.
|
|
7
7
|
*
|
|
8
8
|
* Wire format: signed compact EdDSA JWT (60s TTL, per-call jti)
|
|
9
|
-
* Header injection: KYA-
|
|
9
|
+
* Header injection: KYA-OS-Delegation-Chain, KYA-OS-Delegation-Proof, KYA-OS-Granted-Scopes,
|
|
10
|
+
* and KYA-OS-Delegation-Credential (the JWS-compact DelegationCredential VC) when present
|
|
10
11
|
*
|
|
11
|
-
* Related Spec: MCP-I §
|
|
12
|
+
* Related Spec: DIF MCP-I §8 — Outbound Delegation Propagation
|
|
12
13
|
*/
|
|
13
14
|
import type { DelegationRecord } from "@kya-os/contracts/delegation";
|
|
14
15
|
/**
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* without trusting the MCP server.
|
|
8
8
|
*
|
|
9
9
|
* Wire format: signed compact EdDSA JWT (60s TTL, per-call jti)
|
|
10
|
-
* Header injection: KYA-
|
|
10
|
+
* Header injection: KYA-OS-Delegation-Chain, KYA-OS-Delegation-Proof, KYA-OS-Granted-Scopes,
|
|
11
|
+
* and KYA-OS-Delegation-Credential (the JWS-compact DelegationCredential VC) when present
|
|
11
12
|
*
|
|
12
|
-
* Related Spec: MCP-I §
|
|
13
|
+
* Related Spec: DIF MCP-I §8 — Outbound Delegation Propagation
|
|
13
14
|
*/
|
|
14
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
16
|
exports.buildDelegationProofJWT = buildDelegationProofJWT;
|
|
@@ -40,8 +40,10 @@ export interface VCJWTPayload {
|
|
|
40
40
|
sub?: string;
|
|
41
41
|
/** Audience (e.g., project ID the credential is scoped to). Per RFC 7519, can be string or array. */
|
|
42
42
|
aud?: string | string[];
|
|
43
|
-
/** Expiration time (from vc.expirationDate) */
|
|
43
|
+
/** Expiration time (from vc.expirationDate / validUntil) */
|
|
44
44
|
exp?: number;
|
|
45
|
+
/** Not-before time (RFC 7519 nbf; maps to vc.validFrom) */
|
|
46
|
+
nbf?: number;
|
|
45
47
|
/** Issued at time (from vc.issuanceDate) */
|
|
46
48
|
iat?: number;
|
|
47
49
|
/** JWT ID (from vc.id) */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,53 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @kya-os/mcp-i-core
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Compatibility shim. The product-runtime layer has relocated to
|
|
5
|
+
* @kya-os/mcp-i-runtime; this package re-exports it so existing
|
|
6
|
+
* `@kya-os/mcp-i-core` importers keep resolving during the C4 drain window.
|
|
7
|
+
*
|
|
8
|
+
* Delegation (W3C VC) symbols remain sourced here — `src/delegation/**` is
|
|
9
|
+
* pinned by E3.5 (#2904) and is intentionally NOT relocated.
|
|
6
10
|
*/
|
|
7
|
-
export
|
|
8
|
-
export { MemoryStorageProvider, MemoryNonceCacheProvider, MemoryIdentityProvider, } from "./providers/memory";
|
|
9
|
-
export { MCPIRuntimeBase } from "./runtime/base";
|
|
10
|
-
export type { RuntimeWithAccessControl } from "./runtime/base";
|
|
11
|
-
export { CONSENT_UI_RESOURCE_URI } from "./runtime/ext-apps-constants";
|
|
12
|
-
export type { IAuditLogger } from "./runtime/audit-logger";
|
|
13
|
-
export * from "./utils";
|
|
14
|
-
export { ToolProtectionService } from "./services/tool-protection.service";
|
|
15
|
-
export { PolicyService } from "./services/policy.service";
|
|
16
|
-
export type { PolicyEvaluationContext, PolicyEvaluationResult, PolicyServiceConfig, } from "./services/policy.service";
|
|
17
|
-
export { CryptoService } from "./services/crypto.service";
|
|
18
|
-
export type { Ed25519JWK, ParsedJWS } from "./services/crypto.service";
|
|
19
|
-
export { ProofVerifier } from "./services/proof-verifier";
|
|
20
|
-
export type { ProofVerificationResult, ProofVerifierConfig, } from "./services/proof-verifier";
|
|
21
|
-
export { AccessControlApiService, authorizationMatches, } from "./services/access-control.service";
|
|
22
|
-
export type { AccessControlApiServiceConfig, AccessControlApiServiceMetrics, } from "./services/access-control.service";
|
|
23
|
-
export { SessionRegistrationService, createSessionRegistrationService, } from "./services/session-registration.service";
|
|
24
|
-
export type { SessionRegistrationServiceConfig, SessionRegistrationResult, } from "./services/session-registration.service";
|
|
25
|
-
export { OAuthConfigService } from "./services/oauth-config.service";
|
|
26
|
-
export type { OAuthConfigServiceConfig } from "./services/oauth-config.service";
|
|
27
|
-
export { OAuthService, defaultSecretResolver } from "./services/oauth-service";
|
|
28
|
-
export type { OAuthServiceConfig, SecretResolver } from "./services/oauth-service";
|
|
29
|
-
export { ToolContextBuilder } from "./services/tool-context-builder";
|
|
30
|
-
export type { ToolContextBuilderConfig } from "./services/tool-context-builder";
|
|
31
|
-
export { OAuthProviderRegistry } from "./services/oauth-provider-registry";
|
|
32
|
-
export { ProviderResolver, ConsentOnlyModeError, CredentialAuthModeError, } from "./services/provider-resolver";
|
|
33
|
-
export { ProviderValidator, ProviderValidationError, } from "./services/provider-validator";
|
|
34
|
-
export { OAuthTokenRetrievalService } from "./services/oauth-token-retrieval.service";
|
|
35
|
-
export type { OAuthTokenRetrievalServiceConfig } from "./services/oauth-token-retrieval.service";
|
|
36
|
-
export { BatchDelegationService } from "./services/batch-delegation.service";
|
|
37
|
-
export type { ToolGroup } from "./services/batch-delegation.service";
|
|
38
|
-
export { InMemoryOAuthConfigCache, NoOpOAuthConfigCache, } from "./cache/oauth-config-cache";
|
|
39
|
-
export type { OAuthConfigCache } from "./cache/oauth-config-cache";
|
|
40
|
-
export { createStorageProviders, StorageKeyHelpers, migrateLegacyKeys, } from "./services/storage.service";
|
|
41
|
-
export type { StorageServiceConfig, StorageProviders, } from "./services/storage.service";
|
|
42
|
-
export { ProofVerificationError, PROOF_VERIFICATION_ERROR_CODES, createProofVerificationError, } from "./services/errors";
|
|
43
|
-
export type { ProofVerificationErrorCode } from "./services/errors";
|
|
44
|
-
export { ToolProtectionCache, InMemoryToolProtectionCache, NoOpToolProtectionCache, } from "./cache/tool-protection-cache";
|
|
45
|
-
export type { ToolProtection, ToolProtectionConfig, ToolProtectionServiceConfig, } from "./types/tool-protection";
|
|
46
|
-
export { DelegationRequiredError } from "./types/tool-protection";
|
|
47
|
-
export { OAuthRequiredError } from "./types/oauth-required-error";
|
|
48
|
-
export type { OAuthRequiredErrorOptions } from "./types/oauth-required-error";
|
|
49
|
-
export { DelegationErrorFormatter, createDelegationErrorFormatter, } from "./services/delegation-error-formatter";
|
|
50
|
-
export type { DelegationErrorFormatOptions, DelegationErrorResult, ClientMessageTemplate, ClientMessagesConfig, } from "./services/delegation-error-formatter";
|
|
11
|
+
export * from "@kya-os/mcp-i-runtime";
|
|
51
12
|
export { DelegationCredentialIssuer, createDelegationIssuer, type IssueDelegationOptions, type VCSigningFunction, type IdentityProvider as DelegationIdentityProvider, } from "./delegation/vc-issuer";
|
|
52
13
|
export { DelegationCredentialVerifier, createDelegationVerifier, type DelegationVCVerificationResult, type VerifyDelegationVCOptions, type DIDResolver, type DIDDocument, type VerificationMethod, type StatusListResolver, type SignatureVerificationFunction, } from "./delegation/vc-verifier";
|
|
53
14
|
export { StatusList2021Manager, createStatusListManager, type StatusListStorageProvider, type StatusListIdentityProvider, } from "./delegation/statuslist-manager";
|
|
@@ -58,22 +19,7 @@ export { MemoryStatusListStorage } from "./delegation/storage/memory-statuslist-
|
|
|
58
19
|
export { MemoryDelegationGraphStorage } from "./delegation/storage/memory-graph-storage";
|
|
59
20
|
export { buildDelegationProofJWT, buildChainString, type DelegationProofOptions, type Ed25519PrivateJWK, } from "./delegation/outbound-proof";
|
|
60
21
|
export { createDidKeyResolver, isEd25519DidKey, extractPublicKeyFromDidKey, publicKeyToJwk, resolveDidKeySync, } from "./delegation/did-key-resolver";
|
|
61
|
-
export {
|
|
62
|
-
export { SchemaVerifier, createSchemaVerifier, type SchemaMetadata, type FieldComplianceResult, type SchemaComplianceReport, type FullComplianceReport, } from "./compliance/schema-verifier";
|
|
63
|
-
export { SCHEMA_REGISTRY, getAllSchemas, getSchemasByCategory, getSchemaById, getCriticalSchemas, getSchemaStats, } from "./compliance/schema-registry";
|
|
22
|
+
export { createDidWebResolver, didWebToUrl, type DidWebFetch, type DidWebFetchResponse, type DidWebResolverOptions, } from "./delegation/did-web-resolver";
|
|
64
23
|
export { canonicalizeJSON, createUnsignedVCJWT, completeVCJWT, parseVCJWT, type VCJWTHeader, type VCJWTPayload, type EncodeVCAsJWTOptions, } from "./delegation/utils";
|
|
65
|
-
export {
|
|
66
|
-
import type { HandshakeRequest, SessionContext, NonceCache, NonceCacheEntry, NonceCacheConfig, ProofMeta, DetachedProof, CanonicalHashes, AuditRecord } from "@kya-os/contracts";
|
|
67
|
-
export type { HandshakeRequest, SessionContext, NonceCache, NonceCacheEntry, NonceCacheConfig, ProofMeta, DetachedProof, CanonicalHashes, AuditRecord, };
|
|
68
|
-
export * from "./config";
|
|
69
|
-
export { fetchRemoteConfig, type RemoteConfigCache, type RemoteConfigOptions, getToolProtection, extractToolProtections, hasMergedToolProtections, getPolicy, extractPolicy, hasMergedPolicy, isPolicyEnabled, } from "./config/remote-config";
|
|
70
|
-
export { UserDidManager } from "./identity/user-did-manager";
|
|
71
|
-
export type { UserDidStorage, UserDidManagerConfig, UserKeyPair, OAuthIdentity, } from "./identity/user-did-manager";
|
|
72
|
-
export { IdpTokenResolver } from "./identity/idp-token-resolver";
|
|
73
|
-
export type { IdpTokenResolverConfig } from "./identity/idp-token-resolver";
|
|
74
|
-
export type { IIdpTokenStorage, TokenUsageMetadata, IdpTokensWithMetadata, } from "./identity/idp-token-storage.interface";
|
|
75
|
-
export { logger, createDefaultConsoleLogger, type Logger, type Level, } from "./logging";
|
|
76
|
-
export { ProofGenerator, createProofResponse, extractCanonicalData, type ProofAgentIdentity, type ToolRequest, type ToolResponse, type ProofOptions, } from "./proof";
|
|
77
|
-
export { SessionManager, createHandshakeRequest, validateHandshakeFormat, type SessionConfig, type HandshakeResult, } from "./session";
|
|
78
|
-
export { verifyOrHints, hasSensitiveScopes, MemoryResumeTokenStore, type AuthHandshakeConfig, type VerifyOrHintsResult, type AgentReputation, type ResumeTokenStore, type DelegationVerifier, type VerifyDelegationResult, } from "./auth";
|
|
24
|
+
export { verifyCapabilities, validateLevel2, DEFAULT_TRUSTED_ISSUERS, type CapabilityName, type CapabilityAttestation, type CapabilityAttestationCredential, type Level2Capability, type ManifestCapabilities, type CapabilityVCSignatureVerifier, type CapabilityStatusListResolver, type ValidateLevel2Options, type ValidateLevel2Result, type InvalidCapability, createVcJwtSignatureVerifier, createCombinedDidResolver, type VcJwtVerifierOptions, createCapabilityVerifier, type DuckTypedCapability, type CapabilityVerificationContext, type CapabilityVerificationResult, type CapabilityVerifier, type CreateCapabilityVerifierOptions, } from "./conformance/index.js";
|
|
79
25
|
//# sourceMappingURL=index.d.ts.map
|