@kya-os/contracts 1.6.2-canary.0 → 1.6.2
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/endpoints.d.ts +3 -0
- package/dist/agentshield-api/endpoints.js +3 -0
- package/dist/agentshield-api/index.d.ts +2 -2
- package/dist/agentshield-api/index.js +7 -1
- package/dist/agentshield-api/schemas.d.ts +287 -122
- package/dist/agentshield-api/schemas.js +52 -5
- package/dist/agentshield-api/types.d.ts +69 -4
- package/dist/audit/index.d.ts +193 -0
- package/dist/audit/index.js +100 -0
- package/dist/config/identity.d.ts +214 -2
- package/dist/config/identity.js +29 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/tool-context.d.ts +34 -0
- package/dist/config/tool-context.js +13 -0
- package/dist/consent/schemas.d.ts +99 -4
- package/dist/consent/schemas.js +39 -1
- package/dist/dashboard-config/schemas.d.ts +1430 -174
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/tool-protection/index.d.ts +478 -2
- package/dist/tool-protection/index.js +89 -2
- package/dist/verifier/index.d.ts +1 -0
- package/dist/verifier/index.js +18 -0
- package/package.json +63 -120
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @package @kya-os/contracts/agentshield-api
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.revokeDelegationAPIResponseSchema = exports.revokeDelegationResponseSchema = exports.revokeDelegationRequestSchema = exports.createDelegationAPIResponseSchema = exports.createDelegationResponseSchema = exports.createDelegationRequestSchema = exports.toolProtectionConfigAPIResponseSchema = exports.toolProtectionConfigResponseSchema = exports.agentShieldToolProtectionSchema = exports.verifyDelegationAPIResponseSchema = exports.verifyDelegationResponseSchema = exports.verifyDelegationRequestSchema = exports.delegationCredentialSchema = exports.proofSubmissionResponseSchema = exports.proofSubmissionRequestSchema = exports.agentShieldAPIResponseSchema = exports.agentShieldAPIErrorSchema = void 0;
|
|
11
|
+
exports.registerSessionAPIResponseSchema = exports.registerSessionResponseSchema = exports.registerSessionRequestSchema = exports.sessionClientIdentitySchema = exports.sessionClientInfoSchema = exports.revokeDelegationAPIResponseSchema = exports.revokeDelegationResponseSchema = exports.revokeDelegationRequestSchema = exports.createDelegationAPIResponseSchema = exports.createDelegationResponseSchema = exports.createDelegationRequestSchema = exports.toolProtectionConfigAPIResponseSchema = exports.toolProtectionConfigResponseSchema = exports.agentShieldToolProtectionSchema = exports.verifyDelegationAPIResponseSchema = exports.verifyDelegationResponseSchema = exports.verifyDelegationRequestSchema = exports.delegationCredentialSchema = exports.proofSubmissionResponseSchema = exports.proofSubmissionRequestSchema = exports.agentShieldAPIResponseSchema = exports.agentShieldAPIErrorSchema = void 0;
|
|
12
12
|
const zod_1 = require("zod");
|
|
13
13
|
const proof_js_1 = require("../proof.js");
|
|
14
14
|
const index_js_1 = require("../delegation/index.js");
|
|
@@ -97,7 +97,7 @@ exports.proofSubmissionResponseSchema = zod_1.z.object({
|
|
|
97
97
|
success: zod_1.z.boolean(),
|
|
98
98
|
accepted: zod_1.z.number().int().min(0),
|
|
99
99
|
rejected: zod_1.z.number().int().min(0),
|
|
100
|
-
outcomes: zod_1.z.record(zod_1.z.string(), zod_1.z.number().int().min(0)), // Record<BouncerOutcome, number>
|
|
100
|
+
outcomes: zod_1.z.record(zod_1.z.string(), zod_1.z.number().int().min(0)).optional(), // Record<BouncerOutcome, number> - Optional because API may return empty object or omit it
|
|
101
101
|
errors: zod_1.z
|
|
102
102
|
.array(zod_1.z.object({
|
|
103
103
|
proof_index: zod_1.z.number().int().min(0),
|
|
@@ -199,7 +199,7 @@ exports.toolProtectionConfigAPIResponseSchema = (0, exports.agentShieldAPIRespon
|
|
|
199
199
|
* Create delegation request schema
|
|
200
200
|
*
|
|
201
201
|
* Note: AgentShield API accepts a simplified format, not the full DelegationRecord.
|
|
202
|
-
* The API accepts: agent_did, scopes, expires_in_days, expires_at, session_id, project_id, custom_fields
|
|
202
|
+
* The API accepts: agent_did, scopes, expires_in_days, expires_at, session_id, project_id, user_identifier, custom_fields
|
|
203
203
|
*
|
|
204
204
|
* IMPORTANT: expires_in_days and expires_at are mutually exclusive - use one or the other, not both.
|
|
205
205
|
*/
|
|
@@ -211,6 +211,7 @@ exports.createDelegationRequestSchema = zod_1.z
|
|
|
211
211
|
expires_at: zod_1.z.string().datetime().optional(),
|
|
212
212
|
session_id: zod_1.z.string().optional(),
|
|
213
213
|
project_id: zod_1.z.string().uuid().optional(),
|
|
214
|
+
user_identifier: zod_1.z.string().max(200).optional(), // Matches AgentShield's max(200)
|
|
214
215
|
custom_fields: zod_1.z.record(zod_1.z.unknown()).optional(),
|
|
215
216
|
})
|
|
216
217
|
.passthrough()
|
|
@@ -238,9 +239,9 @@ exports.createDelegationResponseSchema = zod_1.z.object({
|
|
|
238
239
|
user_id: zod_1.z.string().optional(),
|
|
239
240
|
user_identifier: zod_1.z.string().optional(),
|
|
240
241
|
scopes: zod_1.z.array(zod_1.z.string()),
|
|
241
|
-
status: zod_1.z.
|
|
242
|
+
status: zod_1.z.enum(['active', 'expired', 'revoked']), // Matches AgentShield's actual API behavior
|
|
242
243
|
issued_at: zod_1.z.string().datetime(),
|
|
243
|
-
expires_at: zod_1.z.string().datetime().optional(),
|
|
244
|
+
expires_at: zod_1.z.string().datetime().nullable().optional(), // AgentShield allows null values
|
|
244
245
|
created_at: zod_1.z.string().datetime(),
|
|
245
246
|
});
|
|
246
247
|
/**
|
|
@@ -265,3 +266,49 @@ exports.revokeDelegationResponseSchema = zod_1.z.object({
|
|
|
265
266
|
* Wrapped revocation response schema
|
|
266
267
|
*/
|
|
267
268
|
exports.revokeDelegationAPIResponseSchema = (0, exports.agentShieldAPIResponseSchema)(exports.revokeDelegationResponseSchema);
|
|
269
|
+
// ============================================================================
|
|
270
|
+
// Session Registration Schemas
|
|
271
|
+
// ============================================================================
|
|
272
|
+
/**
|
|
273
|
+
* Session client info schema
|
|
274
|
+
*/
|
|
275
|
+
exports.sessionClientInfoSchema = zod_1.z.object({
|
|
276
|
+
name: zod_1.z.string().min(1, "Client name is required"),
|
|
277
|
+
version: zod_1.z.string().optional(),
|
|
278
|
+
protocol_version: zod_1.z.string().optional(),
|
|
279
|
+
platform: zod_1.z.string().optional(),
|
|
280
|
+
vendor: zod_1.z.string().optional(),
|
|
281
|
+
});
|
|
282
|
+
/**
|
|
283
|
+
* Session client identity schema
|
|
284
|
+
*/
|
|
285
|
+
exports.sessionClientIdentitySchema = zod_1.z.object({
|
|
286
|
+
did: zod_1.z.string().min(1, "Client DID is required"),
|
|
287
|
+
source: zod_1.z.enum(["knowthat.ai", "kta-lookup", "generated"]),
|
|
288
|
+
registered: zod_1.z.boolean(),
|
|
289
|
+
});
|
|
290
|
+
/**
|
|
291
|
+
* Register session request schema
|
|
292
|
+
*/
|
|
293
|
+
exports.registerSessionRequestSchema = zod_1.z.object({
|
|
294
|
+
session_id: zod_1.z.string().min(1, "Session ID is required"),
|
|
295
|
+
agent_did: zod_1.z.string().min(1, "Agent DID is required"),
|
|
296
|
+
project_id: zod_1.z.string().min(1, "Project ID is required"),
|
|
297
|
+
created_at: zod_1.z.number().int().positive("Created at must be a positive timestamp"),
|
|
298
|
+
client_info: exports.sessionClientInfoSchema,
|
|
299
|
+
client_identity: exports.sessionClientIdentitySchema.optional(),
|
|
300
|
+
server_did: zod_1.z.string().optional(),
|
|
301
|
+
ttl_minutes: zod_1.z.number().int().positive().optional(),
|
|
302
|
+
});
|
|
303
|
+
/**
|
|
304
|
+
* Register session response schema
|
|
305
|
+
*/
|
|
306
|
+
exports.registerSessionResponseSchema = zod_1.z.object({
|
|
307
|
+
session_id: zod_1.z.string().min(1),
|
|
308
|
+
registered: zod_1.z.boolean(),
|
|
309
|
+
created_at: zod_1.z.string().datetime(),
|
|
310
|
+
});
|
|
311
|
+
/**
|
|
312
|
+
* Wrapped session registration response schema
|
|
313
|
+
*/
|
|
314
|
+
exports.registerSessionAPIResponseSchema = (0, exports.agentShieldAPIResponseSchema)(exports.registerSessionResponseSchema);
|
|
@@ -94,7 +94,7 @@ export interface ProofSubmissionResponse {
|
|
|
94
94
|
success: boolean;
|
|
95
95
|
accepted: number;
|
|
96
96
|
rejected: number;
|
|
97
|
-
outcomes
|
|
97
|
+
outcomes?: Record<BouncerOutcome, number>;
|
|
98
98
|
errors?: Array<{
|
|
99
99
|
proof_index: number;
|
|
100
100
|
error: {
|
|
@@ -188,7 +188,7 @@ export type ToolProtectionConfigAPIResponse = AgentShieldAPIResponse<ToolProtect
|
|
|
188
188
|
* POST /api/v1/bouncer/delegations
|
|
189
189
|
*
|
|
190
190
|
* Note: AgentShield API accepts a simplified format, not the full DelegationRecord.
|
|
191
|
-
* The API accepts: agent_did, scopes, expires_in_days, expires_at, session_id, project_id, custom_fields
|
|
191
|
+
* The API accepts: agent_did, scopes, expires_in_days, expires_at, session_id, project_id, user_identifier, custom_fields
|
|
192
192
|
*
|
|
193
193
|
* IMPORTANT: expires_in_days and expires_at are mutually exclusive - use one or the other, not both.
|
|
194
194
|
*/
|
|
@@ -201,6 +201,8 @@ export interface CreateDelegationRequest {
|
|
|
201
201
|
expires_at?: string;
|
|
202
202
|
session_id?: string;
|
|
203
203
|
project_id?: string;
|
|
204
|
+
/** User identifier string, max 200 chars, optional */
|
|
205
|
+
user_identifier?: string;
|
|
204
206
|
custom_fields?: Record<string, unknown>;
|
|
205
207
|
}
|
|
206
208
|
/**
|
|
@@ -218,9 +220,9 @@ export interface CreateDelegationResponse {
|
|
|
218
220
|
user_id?: string;
|
|
219
221
|
user_identifier?: string;
|
|
220
222
|
scopes: string[];
|
|
221
|
-
status: "active";
|
|
223
|
+
status: "active" | "expired" | "revoked";
|
|
222
224
|
issued_at: string;
|
|
223
|
-
expires_at?: string;
|
|
225
|
+
expires_at?: string | null;
|
|
224
226
|
created_at: string;
|
|
225
227
|
}
|
|
226
228
|
/**
|
|
@@ -246,6 +248,69 @@ export interface RevokeDelegationResponse {
|
|
|
246
248
|
* Wrapped revocation response
|
|
247
249
|
*/
|
|
248
250
|
export type RevokeDelegationAPIResponse = AgentShieldAPIResponse<RevokeDelegationResponse>;
|
|
251
|
+
/**
|
|
252
|
+
* MCP Client information from the initialize message
|
|
253
|
+
*/
|
|
254
|
+
export interface SessionClientInfo {
|
|
255
|
+
/** Client application name (e.g., "Claude Desktop", "Anthropic/ClaudeAI") */
|
|
256
|
+
name: string;
|
|
257
|
+
/** Client version (e.g., "1.0.0") */
|
|
258
|
+
version?: string;
|
|
259
|
+
/** MCP protocol version (e.g., "2025-06-18") */
|
|
260
|
+
protocol_version?: string;
|
|
261
|
+
/** Platform (e.g., "darwin", "win32") */
|
|
262
|
+
platform?: string;
|
|
263
|
+
/** Vendor name (e.g., "Anthropic") */
|
|
264
|
+
vendor?: string;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Client identity resolution information
|
|
268
|
+
*/
|
|
269
|
+
export interface SessionClientIdentity {
|
|
270
|
+
/** Resolved DID for the client */
|
|
271
|
+
did: string;
|
|
272
|
+
/** Source of the DID */
|
|
273
|
+
source: "knowthat.ai" | "kta-lookup" | "generated";
|
|
274
|
+
/** Whether client is registered on knowthat.ai */
|
|
275
|
+
registered: boolean;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Request body for session registration endpoint
|
|
279
|
+
* POST /api/v1/bouncer/sessions
|
|
280
|
+
*/
|
|
281
|
+
export interface RegisterSessionRequest {
|
|
282
|
+
/** Unique session identifier (matches proof.meta.sessionId) */
|
|
283
|
+
session_id: string;
|
|
284
|
+
/** Agent's DID */
|
|
285
|
+
agent_did: string;
|
|
286
|
+
/** AgentShield project ID */
|
|
287
|
+
project_id: string;
|
|
288
|
+
/** Unix timestamp in milliseconds when session was created */
|
|
289
|
+
created_at: number;
|
|
290
|
+
/** MCP client information */
|
|
291
|
+
client_info: SessionClientInfo;
|
|
292
|
+
/** Client identity resolution (optional) */
|
|
293
|
+
client_identity?: SessionClientIdentity;
|
|
294
|
+
/** MCP server's DID (optional) */
|
|
295
|
+
server_did?: string;
|
|
296
|
+
/** Session TTL in minutes (default: 30) */
|
|
297
|
+
ttl_minutes?: number;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Response from session registration endpoint
|
|
301
|
+
*/
|
|
302
|
+
export interface RegisterSessionResponse {
|
|
303
|
+
/** The registered session ID */
|
|
304
|
+
session_id: string;
|
|
305
|
+
/** Whether registration was successful */
|
|
306
|
+
registered: boolean;
|
|
307
|
+
/** ISO 8601 timestamp of registration */
|
|
308
|
+
created_at: string;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Wrapped session registration response
|
|
312
|
+
*/
|
|
313
|
+
export type RegisterSessionAPIResponse = AgentShieldAPIResponse<RegisterSessionResponse>;
|
|
249
314
|
/**
|
|
250
315
|
* AgentShield API error class
|
|
251
316
|
*/
|
|
@@ -0,0 +1,193 @@
|
|
|
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";
|
|
@@ -0,0 +1,100 @@
|
|
|
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; } });
|