@kya-os/contracts 1.6.1 → 1.6.2-canary.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/dist/agentshield-api/schemas.d.ts +48 -27
- package/dist/agentshield-api/schemas.js +4 -5
- package/dist/agentshield-api/types.d.ts +4 -6
- package/dist/config/identity.d.ts +2 -214
- package/dist/config/identity.js +0 -29
- package/dist/config/index.d.ts +1 -2
- package/dist/consent/schemas.d.ts +1 -96
- package/dist/consent/schemas.js +1 -39
- package/dist/dashboard-config/schemas.d.ts +174 -1430
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/tool-protection/index.d.ts +2 -478
- package/dist/tool-protection/index.js +2 -89
- package/package.json +120 -63
- package/dist/audit/index.d.ts +0 -193
- package/dist/audit/index.js +0 -100
- package/dist/config/tool-context.d.ts +0 -34
- package/dist/config/tool-context.js +0 -13
- package/dist/verifier/index.d.ts +0 -1
- package/dist/verifier/index.js +0 -18
|
@@ -9,13 +9,11 @@
|
|
|
9
9
|
* @module @kya-os/contracts/tool-protection
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.DelegationRequiredErrorDataSchema = exports.ToolProtectionResponseSchema = exports.ToolProtectionMapSchema = exports.ToolProtectionSchema =
|
|
12
|
+
exports.DelegationRequiredErrorDataSchema = exports.ToolProtectionResponseSchema = exports.ToolProtectionMapSchema = exports.ToolProtectionSchema = void 0;
|
|
13
13
|
exports.isToolProtection = isToolProtection;
|
|
14
14
|
exports.isToolProtectionMap = isToolProtectionMap;
|
|
15
15
|
exports.isToolProtectionResponse = isToolProtectionResponse;
|
|
16
16
|
exports.isDelegationRequiredErrorData = isDelegationRequiredErrorData;
|
|
17
|
-
exports.isAuthorizationRequirement = isAuthorizationRequirement;
|
|
18
|
-
exports.hasOAuthAuthorization = hasOAuthAuthorization;
|
|
19
17
|
exports.validateToolProtection = validateToolProtection;
|
|
20
18
|
exports.validateToolProtectionMap = validateToolProtectionMap;
|
|
21
19
|
exports.validateToolProtectionResponse = validateToolProtectionResponse;
|
|
@@ -24,42 +22,14 @@ exports.toolRequiresDelegation = toolRequiresDelegation;
|
|
|
24
22
|
exports.getToolRequiredScopes = getToolRequiredScopes;
|
|
25
23
|
exports.getToolRiskLevel = getToolRiskLevel;
|
|
26
24
|
exports.createDelegationRequiredError = createDelegationRequiredError;
|
|
27
|
-
exports.normalizeToolProtection = normalizeToolProtection;
|
|
28
25
|
const zod_1 = require("zod");
|
|
29
26
|
/**
|
|
30
27
|
* Zod Schemas for Validation
|
|
31
28
|
*/
|
|
32
|
-
exports.AuthorizationRequirementSchema = zod_1.z.discriminatedUnion('type', [
|
|
33
|
-
zod_1.z.object({
|
|
34
|
-
type: zod_1.z.literal('oauth'),
|
|
35
|
-
provider: zod_1.z.string(),
|
|
36
|
-
requiredScopes: zod_1.z.array(zod_1.z.string()).optional(),
|
|
37
|
-
}),
|
|
38
|
-
zod_1.z.object({
|
|
39
|
-
type: zod_1.z.literal('mdl'),
|
|
40
|
-
issuer: zod_1.z.string(),
|
|
41
|
-
credentialType: zod_1.z.string().optional(),
|
|
42
|
-
}),
|
|
43
|
-
zod_1.z.object({
|
|
44
|
-
type: zod_1.z.literal('idv'),
|
|
45
|
-
provider: zod_1.z.string(),
|
|
46
|
-
verificationLevel: zod_1.z.enum(['basic', 'enhanced', 'loa3']).optional(),
|
|
47
|
-
}),
|
|
48
|
-
zod_1.z.object({
|
|
49
|
-
type: zod_1.z.literal('credential'),
|
|
50
|
-
credentialType: zod_1.z.string(),
|
|
51
|
-
issuer: zod_1.z.string().optional(),
|
|
52
|
-
}),
|
|
53
|
-
zod_1.z.object({
|
|
54
|
-
type: zod_1.z.literal('none'),
|
|
55
|
-
}),
|
|
56
|
-
]);
|
|
57
29
|
exports.ToolProtectionSchema = zod_1.z.object({
|
|
58
30
|
requiresDelegation: zod_1.z.boolean(),
|
|
59
31
|
requiredScopes: zod_1.z.array(zod_1.z.string()),
|
|
60
|
-
riskLevel: zod_1.z.enum(['low', 'medium', 'high', 'critical']).optional()
|
|
61
|
-
oauthProvider: zod_1.z.string().optional(), // Phase 2: Tool-specific OAuth provider
|
|
62
|
-
authorization: exports.AuthorizationRequirementSchema.optional(),
|
|
32
|
+
riskLevel: zod_1.z.enum(['low', 'medium', 'high', 'critical']).optional()
|
|
63
33
|
});
|
|
64
34
|
exports.ToolProtectionMapSchema = zod_1.z.record(zod_1.z.string(), exports.ToolProtectionSchema);
|
|
65
35
|
exports.ToolProtectionResponseSchema = zod_1.z.object({
|
|
@@ -92,18 +62,6 @@ function isToolProtectionResponse(obj) {
|
|
|
92
62
|
function isDelegationRequiredErrorData(obj) {
|
|
93
63
|
return exports.DelegationRequiredErrorDataSchema.safeParse(obj).success;
|
|
94
64
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Type guard to check if an object is a valid AuthorizationRequirement
|
|
97
|
-
*/
|
|
98
|
-
function isAuthorizationRequirement(obj) {
|
|
99
|
-
return exports.AuthorizationRequirementSchema.safeParse(obj).success;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Type guard to check if a ToolProtection has OAuth authorization
|
|
103
|
-
*/
|
|
104
|
-
function hasOAuthAuthorization(protection) {
|
|
105
|
-
return protection.authorization?.type === 'oauth';
|
|
106
|
-
}
|
|
107
65
|
/**
|
|
108
66
|
* Validation Functions
|
|
109
67
|
*/
|
|
@@ -153,48 +111,3 @@ function createDelegationRequiredError(toolName, requiredScopes, consentUrl) {
|
|
|
153
111
|
authorizationUrl: consentUrl // Include both for compatibility
|
|
154
112
|
};
|
|
155
113
|
}
|
|
156
|
-
/**
|
|
157
|
-
* Normalize tool protection configuration
|
|
158
|
-
* Migrates legacy oauthProvider field to authorization object
|
|
159
|
-
*
|
|
160
|
-
* - Migrates `oauthProvider` → `authorization: { type: 'oauth', provider: ... }`
|
|
161
|
-
* - Ensures `authorization` field is present when `requiresDelegation=true`
|
|
162
|
-
* - Returns fully normalized ToolProtection object
|
|
163
|
-
*
|
|
164
|
-
* @param raw - Raw tool protection data (may have legacy fields or be partial)
|
|
165
|
-
* @returns Normalized ToolProtection object
|
|
166
|
-
*
|
|
167
|
-
* // TODO: Remove normalizeToolProtection() when all tools migrated (target: Phase 3)
|
|
168
|
-
*/
|
|
169
|
-
function normalizeToolProtection(raw) {
|
|
170
|
-
// Ensure we have required fields (provide defaults for partial input)
|
|
171
|
-
const normalized = {
|
|
172
|
-
requiresDelegation: raw.requiresDelegation ?? false,
|
|
173
|
-
requiredScopes: raw.requiredScopes ?? [],
|
|
174
|
-
...(raw.riskLevel && { riskLevel: raw.riskLevel }),
|
|
175
|
-
...(raw.oauthProvider && { oauthProvider: raw.oauthProvider }),
|
|
176
|
-
};
|
|
177
|
-
// If authorization is already present, use it
|
|
178
|
-
if (raw.authorization) {
|
|
179
|
-
normalized.authorization = raw.authorization;
|
|
180
|
-
return normalized;
|
|
181
|
-
}
|
|
182
|
-
// Migrate oauthProvider to authorization
|
|
183
|
-
if (raw.oauthProvider) {
|
|
184
|
-
normalized.authorization = {
|
|
185
|
-
type: 'oauth',
|
|
186
|
-
provider: raw.oauthProvider,
|
|
187
|
-
};
|
|
188
|
-
// Keep oauthProvider for backward compatibility until Phase 3
|
|
189
|
-
return normalized;
|
|
190
|
-
}
|
|
191
|
-
// Default for requiresDelegation=true without specific auth: type='none' (consent only)
|
|
192
|
-
// But ONLY if authorization is missing entirely
|
|
193
|
-
if (normalized.requiresDelegation && !normalized.authorization && !normalized.oauthProvider) {
|
|
194
|
-
// We don't automatically set type='none' here to allow
|
|
195
|
-
// ProviderResolver to do its scope inference fallback logic.
|
|
196
|
-
// The fallback logic will eventually be moved into an AuthorizationService.
|
|
197
|
-
return normalized;
|
|
198
|
-
}
|
|
199
|
-
return normalized;
|
|
200
|
-
}
|
package/package.json
CHANGED
|
@@ -1,99 +1,156 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kya-os/contracts",
|
|
3
|
-
"version": "1.6.
|
|
4
|
-
"description": "Shared
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "1.6.2-canary.0",
|
|
4
|
+
"description": "Shared types and schemas for XMCP-I ecosystem",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
7
9
|
"exports": {
|
|
8
10
|
".": {
|
|
9
11
|
"types": "./dist/index.d.ts",
|
|
10
|
-
"
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.js"
|
|
11
14
|
},
|
|
12
|
-
"./
|
|
13
|
-
"types": "./dist/
|
|
14
|
-
"
|
|
15
|
+
"./handshake": {
|
|
16
|
+
"types": "./dist/handshake.d.ts",
|
|
17
|
+
"import": "./dist/handshake.js",
|
|
18
|
+
"require": "./dist/handshake.js"
|
|
19
|
+
},
|
|
20
|
+
"./proof": {
|
|
21
|
+
"types": "./dist/proof/index.d.ts",
|
|
22
|
+
"import": "./dist/proof/index.js",
|
|
23
|
+
"require": "./dist/proof/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./verifier": {
|
|
26
|
+
"types": "./dist/verifier.d.ts",
|
|
27
|
+
"import": "./dist/verifier.js",
|
|
28
|
+
"require": "./dist/verifier.js"
|
|
29
|
+
},
|
|
30
|
+
"./registry": {
|
|
31
|
+
"types": "./dist/registry.d.ts",
|
|
32
|
+
"import": "./dist/registry.js",
|
|
33
|
+
"require": "./dist/registry.js"
|
|
34
|
+
},
|
|
35
|
+
"./cli": {
|
|
36
|
+
"types": "./dist/cli.d.ts",
|
|
37
|
+
"import": "./dist/cli.js",
|
|
38
|
+
"require": "./dist/cli.js"
|
|
39
|
+
},
|
|
40
|
+
"./test": {
|
|
41
|
+
"types": "./dist/test.d.ts",
|
|
42
|
+
"import": "./dist/test.js",
|
|
43
|
+
"require": "./dist/test.js"
|
|
44
|
+
},
|
|
45
|
+
"./did": {
|
|
46
|
+
"types": "./dist/did/index.d.ts",
|
|
47
|
+
"import": "./dist/did/index.js",
|
|
48
|
+
"require": "./dist/did/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./vc": {
|
|
51
|
+
"types": "./dist/vc/index.d.ts",
|
|
52
|
+
"import": "./dist/vc/index.js",
|
|
53
|
+
"require": "./dist/vc/index.js"
|
|
15
54
|
},
|
|
16
55
|
"./delegation": {
|
|
17
56
|
"types": "./dist/delegation/index.d.ts",
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"./agentshield-api": {
|
|
21
|
-
"types": "./dist/agentshield-api/index.d.ts",
|
|
22
|
-
"default": "./dist/agentshield-api/index.js"
|
|
57
|
+
"import": "./dist/delegation/index.js",
|
|
58
|
+
"require": "./dist/delegation/index.js"
|
|
23
59
|
},
|
|
24
60
|
"./runtime": {
|
|
25
61
|
"types": "./dist/runtime/index.d.ts",
|
|
26
|
-
"
|
|
62
|
+
"import": "./dist/runtime/index.js",
|
|
63
|
+
"require": "./dist/runtime/index.js"
|
|
27
64
|
},
|
|
28
|
-
"./
|
|
29
|
-
"types": "./dist/
|
|
30
|
-
"
|
|
65
|
+
"./tlkrc": {
|
|
66
|
+
"types": "./dist/tlkrc/index.d.ts",
|
|
67
|
+
"import": "./dist/tlkrc/index.js",
|
|
68
|
+
"require": "./dist/tlkrc/index.js"
|
|
31
69
|
},
|
|
32
|
-
"./
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"
|
|
70
|
+
"./env": {
|
|
71
|
+
"types": "./dist/env/index.d.ts",
|
|
72
|
+
"import": "./dist/env/index.js",
|
|
73
|
+
"require": "./dist/env/index.js"
|
|
35
74
|
},
|
|
36
|
-
"./
|
|
37
|
-
"types": "./dist/
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
"./audit": {
|
|
41
|
-
"types": "./dist/audit/index.d.ts",
|
|
42
|
-
"default": "./dist/audit/index.js"
|
|
43
|
-
},
|
|
44
|
-
"./verifier": {
|
|
45
|
-
"types": "./dist/verifier/index.d.ts",
|
|
46
|
-
"default": "./dist/verifier/index.js"
|
|
75
|
+
"./agentshield-api": {
|
|
76
|
+
"types": "./dist/agentshield-api/index.d.ts",
|
|
77
|
+
"import": "./dist/agentshield-api/index.js",
|
|
78
|
+
"require": "./dist/agentshield-api/index.js"
|
|
47
79
|
},
|
|
48
|
-
"./
|
|
49
|
-
"types": "./dist/
|
|
50
|
-
"
|
|
80
|
+
"./tool-protection": {
|
|
81
|
+
"types": "./dist/tool-protection/index.d.ts",
|
|
82
|
+
"import": "./dist/tool-protection/index.js",
|
|
83
|
+
"require": "./dist/tool-protection/index.js"
|
|
51
84
|
},
|
|
52
85
|
"./well-known": {
|
|
53
86
|
"types": "./dist/well-known/index.d.ts",
|
|
54
|
-
"
|
|
87
|
+
"import": "./dist/well-known/index.js",
|
|
88
|
+
"require": "./dist/well-known/index.js"
|
|
55
89
|
},
|
|
56
|
-
"./
|
|
57
|
-
"types": "./dist/
|
|
58
|
-
"
|
|
90
|
+
"./config": {
|
|
91
|
+
"types": "./dist/config/index.d.ts",
|
|
92
|
+
"import": "./dist/config/index.js",
|
|
93
|
+
"require": "./dist/config/index.js"
|
|
59
94
|
},
|
|
60
|
-
"./
|
|
61
|
-
"types": "./dist/
|
|
62
|
-
"
|
|
95
|
+
"./dashboard-config": {
|
|
96
|
+
"types": "./dist/dashboard-config/index.d.ts",
|
|
97
|
+
"import": "./dist/dashboard-config/index.js",
|
|
98
|
+
"require": "./dist/dashboard-config/index.js"
|
|
63
99
|
},
|
|
64
|
-
"./
|
|
65
|
-
"types": "./dist/
|
|
66
|
-
"
|
|
100
|
+
"./consent": {
|
|
101
|
+
"types": "./dist/consent/index.d.ts",
|
|
102
|
+
"import": "./dist/consent/index.js",
|
|
103
|
+
"require": "./dist/consent/index.js"
|
|
67
104
|
}
|
|
68
105
|
},
|
|
106
|
+
"files": [
|
|
107
|
+
"dist/**/*.js",
|
|
108
|
+
"dist/**/*.d.ts",
|
|
109
|
+
"!dist/**/*.map",
|
|
110
|
+
"!dist/**/__tests__/**",
|
|
111
|
+
"!dist/**/__fixtures__/**",
|
|
112
|
+
"!dist/**/*.spec.*",
|
|
113
|
+
"!dist/**/*.test.*",
|
|
114
|
+
"!README.md",
|
|
115
|
+
"!*.md",
|
|
116
|
+
"!CHANGELOG.md"
|
|
117
|
+
],
|
|
69
118
|
"scripts": {
|
|
70
119
|
"build": "tsc -p tsconfig.build.json && npm run emit-schemas",
|
|
71
120
|
"emit-schemas": "node scripts/emit-schemas.js",
|
|
121
|
+
"clean": "rm -rf dist && rm -f *.tsbuildinfo",
|
|
122
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
123
|
+
"type-check": "tsc --noEmit",
|
|
72
124
|
"test": "vitest run",
|
|
73
|
-
"test:coverage": "vitest run --coverage",
|
|
74
125
|
"test:watch": "vitest",
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"clean": "rm -rf dist .turbo node_modules",
|
|
78
|
-
"prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-no-workspace.js"
|
|
79
|
-
},
|
|
80
|
-
"sideEffects": false,
|
|
81
|
-
"dependencies": {
|
|
82
|
-
"zod": "^3.23.8"
|
|
126
|
+
"test:coverage": "vitest run --coverage",
|
|
127
|
+
"prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-dependencies.js"
|
|
83
128
|
},
|
|
84
129
|
"devDependencies": {
|
|
85
|
-
"@types/node": "^20.
|
|
130
|
+
"@types/node": "^20.0.0",
|
|
86
131
|
"@vitest/coverage-v8": "^4.0.5",
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
132
|
+
"ajv": "^8.12.0",
|
|
133
|
+
"ajv-formats": "^2.1.1",
|
|
134
|
+
"fast-check": "^3.15.0",
|
|
135
|
+
"typescript": "^5.0.0",
|
|
136
|
+
"vitest": "^4.0.5",
|
|
137
|
+
"zod-to-json-schema": "^3.22.0"
|
|
90
138
|
},
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
-
|
|
139
|
+
"dependencies": {
|
|
140
|
+
"zod": "^3.22.0"
|
|
141
|
+
},
|
|
142
|
+
"keywords": [
|
|
143
|
+
"xmcp",
|
|
144
|
+
"mcp",
|
|
145
|
+
"identity",
|
|
146
|
+
"types",
|
|
147
|
+
"contracts"
|
|
95
148
|
],
|
|
96
|
-
"
|
|
97
|
-
|
|
149
|
+
"author": "KYA OS",
|
|
150
|
+
"license": "MIT",
|
|
151
|
+
"repository": {
|
|
152
|
+
"type": "git",
|
|
153
|
+
"url": "https://github.com/kya-os/xmcp-i.git",
|
|
154
|
+
"directory": "packages/contracts"
|
|
98
155
|
}
|
|
99
156
|
}
|
package/dist/audit/index.d.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Audit Types and Schemas
|
|
3
|
-
*
|
|
4
|
-
* Types and Zod schemas for audit logging in the MCP-I framework.
|
|
5
|
-
* These types are platform-agnostic and used across all implementations.
|
|
6
|
-
*/
|
|
7
|
-
import { z } from "zod";
|
|
8
|
-
import type { AgentIdentity } from "../config/identity.js";
|
|
9
|
-
import type { SessionContext } from "../handshake.js";
|
|
10
|
-
/**
|
|
11
|
-
* Audit context schema for logging audit records
|
|
12
|
-
*
|
|
13
|
-
* Contains all metadata needed to generate an audit record.
|
|
14
|
-
* Privacy Note: Only metadata is extracted from these objects.
|
|
15
|
-
* The identity's private key, session's nonce, and other sensitive
|
|
16
|
-
* fields are NEVER included in the audit log.
|
|
17
|
-
*/
|
|
18
|
-
export declare const AuditContextSchema: z.ZodObject<{
|
|
19
|
-
/**
|
|
20
|
-
* Agent identity
|
|
21
|
-
* Only `did` and `keyId` are logged. Private key is NEVER logged.
|
|
22
|
-
*/
|
|
23
|
-
identity: z.ZodObject<{
|
|
24
|
-
did: z.ZodString;
|
|
25
|
-
kid: z.ZodString;
|
|
26
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
27
|
-
did: z.ZodString;
|
|
28
|
-
kid: z.ZodString;
|
|
29
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
30
|
-
did: z.ZodString;
|
|
31
|
-
kid: z.ZodString;
|
|
32
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
33
|
-
/**
|
|
34
|
-
* Session context
|
|
35
|
-
* Only `sessionId` and `audience` are logged. Nonce is NEVER logged.
|
|
36
|
-
*/
|
|
37
|
-
session: z.ZodObject<{
|
|
38
|
-
sessionId: z.ZodString;
|
|
39
|
-
audience: z.ZodString;
|
|
40
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
41
|
-
sessionId: z.ZodString;
|
|
42
|
-
audience: z.ZodString;
|
|
43
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
44
|
-
sessionId: z.ZodString;
|
|
45
|
-
audience: z.ZodString;
|
|
46
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
47
|
-
/**
|
|
48
|
-
* Request hash (SHA-256 with `sha256:` prefix)
|
|
49
|
-
*/
|
|
50
|
-
requestHash: z.ZodString;
|
|
51
|
-
/**
|
|
52
|
-
* Response hash (SHA-256 with `sha256:` prefix)
|
|
53
|
-
*/
|
|
54
|
-
responseHash: z.ZodString;
|
|
55
|
-
/**
|
|
56
|
-
* Verification result
|
|
57
|
-
* - 'yes': Proof was verified successfully
|
|
58
|
-
* - 'no': Proof verification failed
|
|
59
|
-
*/
|
|
60
|
-
verified: z.ZodEnum<["yes", "no"]>;
|
|
61
|
-
/**
|
|
62
|
-
* Optional scope identifier
|
|
63
|
-
* Application-level scope (e.g., 'orders.create', 'users.read').
|
|
64
|
-
* If not provided, '-' is used in the audit log.
|
|
65
|
-
*/
|
|
66
|
-
scopeId: z.ZodOptional<z.ZodString>;
|
|
67
|
-
}, "strip", z.ZodTypeAny, {
|
|
68
|
-
requestHash: string;
|
|
69
|
-
responseHash: string;
|
|
70
|
-
session: {
|
|
71
|
-
audience: string;
|
|
72
|
-
sessionId: string;
|
|
73
|
-
} & {
|
|
74
|
-
[k: string]: unknown;
|
|
75
|
-
};
|
|
76
|
-
verified: "yes" | "no";
|
|
77
|
-
identity: {
|
|
78
|
-
did: string;
|
|
79
|
-
kid: string;
|
|
80
|
-
} & {
|
|
81
|
-
[k: string]: unknown;
|
|
82
|
-
};
|
|
83
|
-
scopeId?: string | undefined;
|
|
84
|
-
}, {
|
|
85
|
-
requestHash: string;
|
|
86
|
-
responseHash: string;
|
|
87
|
-
session: {
|
|
88
|
-
audience: string;
|
|
89
|
-
sessionId: string;
|
|
90
|
-
} & {
|
|
91
|
-
[k: string]: unknown;
|
|
92
|
-
};
|
|
93
|
-
verified: "yes" | "no";
|
|
94
|
-
identity: {
|
|
95
|
-
did: string;
|
|
96
|
-
kid: string;
|
|
97
|
-
} & {
|
|
98
|
-
[k: string]: unknown;
|
|
99
|
-
};
|
|
100
|
-
scopeId?: string | undefined;
|
|
101
|
-
}>;
|
|
102
|
-
export type AuditContext = {
|
|
103
|
-
identity: AgentIdentity;
|
|
104
|
-
session: SessionContext;
|
|
105
|
-
requestHash: string;
|
|
106
|
-
responseHash: string;
|
|
107
|
-
verified: "yes" | "no";
|
|
108
|
-
scopeId?: string;
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Event context schema for logging events that bypass session deduplication
|
|
112
|
-
*
|
|
113
|
-
* Used for consent events where multiple events occur in the same session.
|
|
114
|
-
* Unlike AuditContext, this allows multiple events per session.
|
|
115
|
-
*/
|
|
116
|
-
export declare const AuditEventContextSchema: z.ZodObject<{
|
|
117
|
-
/**
|
|
118
|
-
* Event type identifier
|
|
119
|
-
* @example "consent:page_viewed", "consent:approved", "runtime:initialized"
|
|
120
|
-
*/
|
|
121
|
-
eventType: z.ZodString;
|
|
122
|
-
/**
|
|
123
|
-
* Agent identity
|
|
124
|
-
* Only `did` and `keyId` are logged. Private key is NEVER logged.
|
|
125
|
-
*/
|
|
126
|
-
identity: z.ZodObject<{
|
|
127
|
-
did: z.ZodString;
|
|
128
|
-
kid: z.ZodString;
|
|
129
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
130
|
-
did: z.ZodString;
|
|
131
|
-
kid: z.ZodString;
|
|
132
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
133
|
-
did: z.ZodString;
|
|
134
|
-
kid: z.ZodString;
|
|
135
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
136
|
-
/**
|
|
137
|
-
* Session context
|
|
138
|
-
* Only `sessionId` and `audience` are logged. Nonce is NEVER logged.
|
|
139
|
-
*/
|
|
140
|
-
session: z.ZodObject<{
|
|
141
|
-
sessionId: z.ZodString;
|
|
142
|
-
audience: z.ZodString;
|
|
143
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
144
|
-
sessionId: z.ZodString;
|
|
145
|
-
audience: z.ZodString;
|
|
146
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
147
|
-
sessionId: z.ZodString;
|
|
148
|
-
audience: z.ZodString;
|
|
149
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
150
|
-
/**
|
|
151
|
-
* Optional event-specific data
|
|
152
|
-
* Used for generating event hash. Not logged directly.
|
|
153
|
-
*/
|
|
154
|
-
eventData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
155
|
-
}, "strip", z.ZodTypeAny, {
|
|
156
|
-
session: {
|
|
157
|
-
audience: string;
|
|
158
|
-
sessionId: string;
|
|
159
|
-
} & {
|
|
160
|
-
[k: string]: unknown;
|
|
161
|
-
};
|
|
162
|
-
identity: {
|
|
163
|
-
did: string;
|
|
164
|
-
kid: string;
|
|
165
|
-
} & {
|
|
166
|
-
[k: string]: unknown;
|
|
167
|
-
};
|
|
168
|
-
eventType: string;
|
|
169
|
-
eventData?: Record<string, unknown> | undefined;
|
|
170
|
-
}, {
|
|
171
|
-
session: {
|
|
172
|
-
audience: string;
|
|
173
|
-
sessionId: string;
|
|
174
|
-
} & {
|
|
175
|
-
[k: string]: unknown;
|
|
176
|
-
};
|
|
177
|
-
identity: {
|
|
178
|
-
did: string;
|
|
179
|
-
kid: string;
|
|
180
|
-
} & {
|
|
181
|
-
[k: string]: unknown;
|
|
182
|
-
};
|
|
183
|
-
eventType: string;
|
|
184
|
-
eventData?: Record<string, unknown> | undefined;
|
|
185
|
-
}>;
|
|
186
|
-
export type AuditEventContext = {
|
|
187
|
-
eventType: string;
|
|
188
|
-
identity: AgentIdentity;
|
|
189
|
-
session: SessionContext;
|
|
190
|
-
eventData?: Record<string, any>;
|
|
191
|
-
};
|
|
192
|
-
export type { AuditRecord } from "../proof.js";
|
|
193
|
-
export { AuditRecordSchema } from "../proof.js";
|
package/dist/audit/index.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Audit Types and Schemas
|
|
4
|
-
*
|
|
5
|
-
* Types and Zod schemas for audit logging in the MCP-I framework.
|
|
6
|
-
* These types are platform-agnostic and used across all implementations.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.AuditRecordSchema = exports.AuditEventContextSchema = exports.AuditContextSchema = void 0;
|
|
10
|
-
const zod_1 = require("zod");
|
|
11
|
-
/**
|
|
12
|
-
* Audit context schema for logging audit records
|
|
13
|
-
*
|
|
14
|
-
* Contains all metadata needed to generate an audit record.
|
|
15
|
-
* Privacy Note: Only metadata is extracted from these objects.
|
|
16
|
-
* The identity's private key, session's nonce, and other sensitive
|
|
17
|
-
* fields are NEVER included in the audit log.
|
|
18
|
-
*/
|
|
19
|
-
exports.AuditContextSchema = zod_1.z.object({
|
|
20
|
-
/**
|
|
21
|
-
* Agent identity
|
|
22
|
-
* Only `did` and `keyId` are logged. Private key is NEVER logged.
|
|
23
|
-
*/
|
|
24
|
-
identity: zod_1.z
|
|
25
|
-
.object({
|
|
26
|
-
did: zod_1.z.string().min(1),
|
|
27
|
-
kid: zod_1.z.string().min(1),
|
|
28
|
-
})
|
|
29
|
-
.passthrough(), // Allow additional fields but only did/kid are used
|
|
30
|
-
/**
|
|
31
|
-
* Session context
|
|
32
|
-
* Only `sessionId` and `audience` are logged. Nonce is NEVER logged.
|
|
33
|
-
*/
|
|
34
|
-
session: zod_1.z
|
|
35
|
-
.object({
|
|
36
|
-
sessionId: zod_1.z.string().min(1),
|
|
37
|
-
audience: zod_1.z.string().min(1),
|
|
38
|
-
})
|
|
39
|
-
.passthrough(), // Allow additional fields but only sessionId/audience are used
|
|
40
|
-
/**
|
|
41
|
-
* Request hash (SHA-256 with `sha256:` prefix)
|
|
42
|
-
*/
|
|
43
|
-
requestHash: zod_1.z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
44
|
-
/**
|
|
45
|
-
* Response hash (SHA-256 with `sha256:` prefix)
|
|
46
|
-
*/
|
|
47
|
-
responseHash: zod_1.z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
48
|
-
/**
|
|
49
|
-
* Verification result
|
|
50
|
-
* - 'yes': Proof was verified successfully
|
|
51
|
-
* - 'no': Proof verification failed
|
|
52
|
-
*/
|
|
53
|
-
verified: zod_1.z.enum(["yes", "no"]),
|
|
54
|
-
/**
|
|
55
|
-
* Optional scope identifier
|
|
56
|
-
* Application-level scope (e.g., 'orders.create', 'users.read').
|
|
57
|
-
* If not provided, '-' is used in the audit log.
|
|
58
|
-
*/
|
|
59
|
-
scopeId: zod_1.z.string().optional(),
|
|
60
|
-
});
|
|
61
|
-
/**
|
|
62
|
-
* Event context schema for logging events that bypass session deduplication
|
|
63
|
-
*
|
|
64
|
-
* Used for consent events where multiple events occur in the same session.
|
|
65
|
-
* Unlike AuditContext, this allows multiple events per session.
|
|
66
|
-
*/
|
|
67
|
-
exports.AuditEventContextSchema = zod_1.z.object({
|
|
68
|
-
/**
|
|
69
|
-
* Event type identifier
|
|
70
|
-
* @example "consent:page_viewed", "consent:approved", "runtime:initialized"
|
|
71
|
-
*/
|
|
72
|
-
eventType: zod_1.z.string().min(1),
|
|
73
|
-
/**
|
|
74
|
-
* Agent identity
|
|
75
|
-
* Only `did` and `keyId` are logged. Private key is NEVER logged.
|
|
76
|
-
*/
|
|
77
|
-
identity: zod_1.z
|
|
78
|
-
.object({
|
|
79
|
-
did: zod_1.z.string().min(1),
|
|
80
|
-
kid: zod_1.z.string().min(1),
|
|
81
|
-
})
|
|
82
|
-
.passthrough(), // Allow additional fields but only did/kid are used
|
|
83
|
-
/**
|
|
84
|
-
* Session context
|
|
85
|
-
* Only `sessionId` and `audience` are logged. Nonce is NEVER logged.
|
|
86
|
-
*/
|
|
87
|
-
session: zod_1.z
|
|
88
|
-
.object({
|
|
89
|
-
sessionId: zod_1.z.string().min(1),
|
|
90
|
-
audience: zod_1.z.string().min(1),
|
|
91
|
-
})
|
|
92
|
-
.passthrough(), // Allow additional fields but only sessionId/audience are used
|
|
93
|
-
/**
|
|
94
|
-
* Optional event-specific data
|
|
95
|
-
* Used for generating event hash. Not logged directly.
|
|
96
|
-
*/
|
|
97
|
-
eventData: zod_1.z.record(zod_1.z.unknown()).optional(),
|
|
98
|
-
});
|
|
99
|
-
var proof_js_1 = require("../proof.js");
|
|
100
|
-
Object.defineProperty(exports, "AuditRecordSchema", { enumerable: true, get: function () { return proof_js_1.AuditRecordSchema; } });
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Execution Context
|
|
3
|
-
*
|
|
4
|
-
* Execution context passed to tool handlers, enabling tools to access
|
|
5
|
-
* IDP tokens for external API calls (GitHub, Google, etc.).
|
|
6
|
-
*
|
|
7
|
-
* All fields are optional for backward compatibility - tools that don't
|
|
8
|
-
* require OAuth will receive undefined context.
|
|
9
|
-
*
|
|
10
|
-
* @package @kya-os/contracts
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Execution context passed to tool handlers
|
|
14
|
-
*
|
|
15
|
-
* Enables tools to access IDP tokens for external API calls.
|
|
16
|
-
* Context is only provided when:
|
|
17
|
-
* - Tool requires OAuth (has requiredScopes)
|
|
18
|
-
* - User DID is available
|
|
19
|
-
* - IDP token is successfully resolved
|
|
20
|
-
*/
|
|
21
|
-
export interface ToolExecutionContext {
|
|
22
|
-
/** IDP access token for external API calls (e.g., GitHub, Google) */
|
|
23
|
-
idpToken?: string;
|
|
24
|
-
/** OAuth provider name (e.g., "github", "google") */
|
|
25
|
-
provider?: string;
|
|
26
|
-
/** Scopes granted for this token */
|
|
27
|
-
scopes?: string[];
|
|
28
|
-
/** User DID associated with this token */
|
|
29
|
-
userDid?: string;
|
|
30
|
-
/** Session ID */
|
|
31
|
-
sessionId?: string;
|
|
32
|
-
/** Delegation token (MCP-I internal authorization) */
|
|
33
|
-
delegationToken?: string;
|
|
34
|
-
}
|