@kya-os/contracts 1.5.3-canary.1 → 1.5.3-canary.11

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.
@@ -48,6 +48,32 @@ const toolCallContextSchema = zod_1.z.object({
48
48
  scopeId: zod_1.z.string().min(1, "scopeId is required to link context to proof"),
49
49
  userIdentifier: zod_1.z.string().optional(),
50
50
  });
51
+ /**
52
+ * Consent Event Context Schema
53
+ * Represents consent-related events for audit tracking
54
+ */
55
+ const consentEventContextSchema = zod_1.z.object({
56
+ eventType: zod_1.z.enum([
57
+ "consent:page_viewed",
58
+ "consent:approved",
59
+ "consent:delegation_created",
60
+ "consent:credential_required"
61
+ ]),
62
+ timestamp: zod_1.z.number().int().positive(),
63
+ sessionId: zod_1.z.string().min(1),
64
+ userDid: zod_1.z.string().optional(),
65
+ agentDid: zod_1.z.string().min(1),
66
+ targetTools: zod_1.z.array(zod_1.z.string()).min(1), // ALWAYS array
67
+ scopes: zod_1.z.array(zod_1.z.string()).min(0),
68
+ delegationId: zod_1.z.string().uuid().optional(),
69
+ projectId: zod_1.z.string().uuid(),
70
+ termsAccepted: zod_1.z.boolean().optional(),
71
+ credentialStatus: zod_1.z.enum(["present", "required", "obtained"]).optional(),
72
+ oauthIdentity: zod_1.z.object({
73
+ provider: zod_1.z.string(),
74
+ identifier: zod_1.z.string(),
75
+ }).optional(),
76
+ });
51
77
  /**
52
78
  * Proof submission request schema
53
79
  */
@@ -59,6 +85,7 @@ exports.proofSubmissionRequestSchema = zod_1.z.object({
59
85
  context: zod_1.z
60
86
  .object({
61
87
  toolCalls: zod_1.z.array(toolCallContextSchema).optional(),
88
+ consentEvents: zod_1.z.array(consentEventContextSchema).optional(), // NEW: Consent events for audit tracking
62
89
  mcpServerUrl: zod_1.z.string().url().optional(), // MCP server URL for tool discovery
63
90
  })
64
91
  .optional(),
@@ -172,7 +199,7 @@ exports.toolProtectionConfigAPIResponseSchema = (0, exports.agentShieldAPIRespon
172
199
  * Create delegation request schema
173
200
  *
174
201
  * Note: AgentShield API accepts a simplified format, not the full DelegationRecord.
175
- * 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
176
203
  *
177
204
  * IMPORTANT: expires_in_days and expires_at are mutually exclusive - use one or the other, not both.
178
205
  */
@@ -184,6 +211,7 @@ exports.createDelegationRequestSchema = zod_1.z
184
211
  expires_at: zod_1.z.string().datetime().optional(),
185
212
  session_id: zod_1.z.string().optional(),
186
213
  project_id: zod_1.z.string().uuid().optional(),
214
+ user_identifier: zod_1.z.string().max(200).optional(), // Matches AgentShield's max(200)
187
215
  custom_fields: zod_1.z.record(zod_1.z.unknown()).optional(),
188
216
  })
189
217
  .passthrough()
@@ -211,9 +239,9 @@ exports.createDelegationResponseSchema = zod_1.z.object({
211
239
  user_id: zod_1.z.string().optional(),
212
240
  user_identifier: zod_1.z.string().optional(),
213
241
  scopes: zod_1.z.array(zod_1.z.string()),
214
- status: zod_1.z.literal("active"),
242
+ status: zod_1.z.enum(['active', 'expired', 'revoked']), // Matches AgentShield's actual API behavior
215
243
  issued_at: zod_1.z.string().datetime(),
216
- expires_at: zod_1.z.string().datetime().optional(),
244
+ expires_at: zod_1.z.string().datetime().nullable().optional(), // AgentShield allows null values
217
245
  created_at: zod_1.z.string().datetime(),
218
246
  });
219
247
  /**
@@ -41,6 +41,30 @@ export interface ToolCallContext {
41
41
  scopeId: string;
42
42
  userIdentifier?: string;
43
43
  }
44
+ /**
45
+ * Consent Event Context
46
+ *
47
+ * Represents consent-related events that occur during the consent flow.
48
+ * These events are logged separately from tool executions and allow
49
+ * multiple events per session (unlike regular audit logs).
50
+ */
51
+ export interface ConsentEventContext {
52
+ eventType: "consent:page_viewed" | "consent:approved" | "consent:delegation_created" | "consent:credential_required";
53
+ timestamp: number;
54
+ sessionId: string;
55
+ userDid?: string;
56
+ agentDid: string;
57
+ targetTools: string[];
58
+ scopes: string[];
59
+ delegationId?: string;
60
+ projectId: string;
61
+ termsAccepted?: boolean;
62
+ credentialStatus?: "present" | "required" | "obtained";
63
+ oauthIdentity?: {
64
+ provider: string;
65
+ identifier: string;
66
+ };
67
+ }
44
68
  /**
45
69
  * Request body for proof submission endpoint
46
70
  * POST /api/v1/bouncer/proofs
@@ -55,6 +79,7 @@ export interface ProofSubmissionRequest {
55
79
  /** AgentShield extension: Optional context for dashboard enrichment */
56
80
  context?: {
57
81
  toolCalls?: ToolCallContext[];
82
+ consentEvents?: ConsentEventContext[];
58
83
  mcpServerUrl?: string;
59
84
  };
60
85
  }
@@ -163,7 +188,7 @@ export type ToolProtectionConfigAPIResponse = AgentShieldAPIResponse<ToolProtect
163
188
  * POST /api/v1/bouncer/delegations
164
189
  *
165
190
  * Note: AgentShield API accepts a simplified format, not the full DelegationRecord.
166
- * 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
167
192
  *
168
193
  * IMPORTANT: expires_in_days and expires_at are mutually exclusive - use one or the other, not both.
169
194
  */
@@ -176,6 +201,8 @@ export interface CreateDelegationRequest {
176
201
  expires_at?: string;
177
202
  session_id?: string;
178
203
  project_id?: string;
204
+ /** User identifier string, max 200 chars, optional */
205
+ user_identifier?: string;
179
206
  custom_fields?: Record<string, unknown>;
180
207
  }
181
208
  /**
@@ -193,9 +220,9 @@ export interface CreateDelegationResponse {
193
220
  user_id?: string;
194
221
  user_identifier?: string;
195
222
  scopes: string[];
196
- status: "active";
223
+ status: "active" | "expired" | "revoked";
197
224
  issued_at: string;
198
- expires_at?: string;
225
+ expires_at?: string | null;
199
226
  created_at: string;
200
227
  }
201
228
  /**
@@ -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
+ identity: {
69
+ did: string;
70
+ kid: string;
71
+ } & {
72
+ [k: string]: unknown;
73
+ };
74
+ session: {
75
+ sessionId: string;
76
+ audience: string;
77
+ } & {
78
+ [k: string]: unknown;
79
+ };
80
+ requestHash: string;
81
+ responseHash: string;
82
+ verified: "yes" | "no";
83
+ scopeId?: string | undefined;
84
+ }, {
85
+ identity: {
86
+ did: string;
87
+ kid: string;
88
+ } & {
89
+ [k: string]: unknown;
90
+ };
91
+ session: {
92
+ sessionId: string;
93
+ audience: string;
94
+ } & {
95
+ [k: string]: unknown;
96
+ };
97
+ requestHash: string;
98
+ responseHash: string;
99
+ verified: "yes" | "no";
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
+ identity: {
157
+ did: string;
158
+ kid: string;
159
+ } & {
160
+ [k: string]: unknown;
161
+ };
162
+ session: {
163
+ sessionId: string;
164
+ audience: string;
165
+ } & {
166
+ [k: string]: unknown;
167
+ };
168
+ eventType: string;
169
+ eventData?: Record<string, unknown> | undefined;
170
+ }, {
171
+ identity: {
172
+ did: string;
173
+ kid: string;
174
+ } & {
175
+ [k: string]: unknown;
176
+ };
177
+ session: {
178
+ sessionId: string;
179
+ audience: 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,92 @@
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.object({
25
+ did: zod_1.z.string().min(1),
26
+ kid: zod_1.z.string().min(1),
27
+ }).passthrough(), // Allow additional fields but only did/kid are used
28
+ /**
29
+ * Session context
30
+ * Only `sessionId` and `audience` are logged. Nonce is NEVER logged.
31
+ */
32
+ session: zod_1.z.object({
33
+ sessionId: zod_1.z.string().min(1),
34
+ audience: zod_1.z.string().min(1),
35
+ }).passthrough(), // Allow additional fields but only sessionId/audience are used
36
+ /**
37
+ * Request hash (SHA-256 with `sha256:` prefix)
38
+ */
39
+ requestHash: zod_1.z.string().regex(/^sha256:[a-f0-9]{64}$/),
40
+ /**
41
+ * Response hash (SHA-256 with `sha256:` prefix)
42
+ */
43
+ responseHash: zod_1.z.string().regex(/^sha256:[a-f0-9]{64}$/),
44
+ /**
45
+ * Verification result
46
+ * - 'yes': Proof was verified successfully
47
+ * - 'no': Proof verification failed
48
+ */
49
+ verified: zod_1.z.enum(["yes", "no"]),
50
+ /**
51
+ * Optional scope identifier
52
+ * Application-level scope (e.g., 'orders.create', 'users.read').
53
+ * If not provided, '-' is used in the audit log.
54
+ */
55
+ scopeId: zod_1.z.string().optional(),
56
+ });
57
+ /**
58
+ * Event context schema for logging events that bypass session deduplication
59
+ *
60
+ * Used for consent events where multiple events occur in the same session.
61
+ * Unlike AuditContext, this allows multiple events per session.
62
+ */
63
+ exports.AuditEventContextSchema = zod_1.z.object({
64
+ /**
65
+ * Event type identifier
66
+ * @example "consent:page_viewed", "consent:approved", "runtime:initialized"
67
+ */
68
+ eventType: zod_1.z.string().min(1),
69
+ /**
70
+ * Agent identity
71
+ * Only `did` and `keyId` are logged. Private key is NEVER logged.
72
+ */
73
+ identity: zod_1.z.object({
74
+ did: zod_1.z.string().min(1),
75
+ kid: zod_1.z.string().min(1),
76
+ }).passthrough(), // Allow additional fields but only did/kid are used
77
+ /**
78
+ * Session context
79
+ * Only `sessionId` and `audience` are logged. Nonce is NEVER logged.
80
+ */
81
+ session: zod_1.z.object({
82
+ sessionId: zod_1.z.string().min(1),
83
+ audience: zod_1.z.string().min(1),
84
+ }).passthrough(), // Allow additional fields but only sessionId/audience are used
85
+ /**
86
+ * Optional event-specific data
87
+ * Used for generating event hash. Not logged directly.
88
+ */
89
+ eventData: zod_1.z.record(zod_1.z.unknown()).optional(),
90
+ });
91
+ var proof_js_1 = require("../proof.js");
92
+ Object.defineProperty(exports, "AuditRecordSchema", { enumerable: true, get: function () { return proof_js_1.AuditRecordSchema; } });
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * Related Spec: MCP-I Phase 0 Implementation Plan
8
8
  */
9
- import { z } from 'zod';
9
+ import { z } from "zod";
10
10
  /**
11
11
  * Consent Branding Schema
12
12
  */
@@ -357,8 +357,11 @@ export declare const consentApprovalRequestSchema: z.ZodObject<{
357
357
  /**
358
358
  * OAuth provider identity information (optional)
359
359
  * Used to link OAuth accounts to persistent User DIDs
360
+ *
361
+ * CRITICAL: Uses .nullish() to accept null, undefined, or OAuthIdentity
362
+ * This matches JSON parsing behavior where missing fields become null
360
363
  */
361
- oauth_identity: z.ZodOptional<z.ZodObject<{
364
+ oauth_identity: z.ZodOptional<z.ZodNullable<z.ZodObject<{
362
365
  /**
363
366
  * OAuth provider name (e.g., "google", "github", "microsoft")
364
367
  */
@@ -386,7 +389,7 @@ export declare const consentApprovalRequestSchema: z.ZodObject<{
386
389
  subject: string;
387
390
  name?: string | undefined;
388
391
  email?: string | undefined;
389
- }>>;
392
+ }>>>;
390
393
  /**
391
394
  * User DID (optional)
392
395
  * If provided, represents the persistent User DID for this user
@@ -394,11 +397,11 @@ export declare const consentApprovalRequestSchema: z.ZodObject<{
394
397
  */
395
398
  user_did: z.ZodOptional<z.ZodString>;
396
399
  }, "strip", z.ZodTypeAny, {
397
- agent_did: string;
398
- project_id: string;
399
400
  tool: string;
400
401
  scopes: string[];
402
+ agent_did: string;
401
403
  session_id: string;
404
+ project_id: string;
402
405
  termsAccepted: boolean;
403
406
  customFields?: Record<string, string | boolean> | undefined;
404
407
  termsVersion?: string | undefined;
@@ -407,14 +410,14 @@ export declare const consentApprovalRequestSchema: z.ZodObject<{
407
410
  subject: string;
408
411
  name?: string | undefined;
409
412
  email?: string | undefined;
410
- } | undefined;
413
+ } | null | undefined;
411
414
  user_did?: string | undefined;
412
415
  }, {
413
- agent_did: string;
414
- project_id: string;
415
416
  tool: string;
416
417
  scopes: string[];
418
+ agent_did: string;
417
419
  session_id: string;
420
+ project_id: string;
418
421
  termsAccepted: boolean;
419
422
  customFields?: Record<string, string | boolean> | undefined;
420
423
  termsVersion?: string | undefined;
@@ -423,7 +426,7 @@ export declare const consentApprovalRequestSchema: z.ZodObject<{
423
426
  subject: string;
424
427
  name?: string | undefined;
425
428
  email?: string | undefined;
426
- } | undefined;
429
+ } | null | undefined;
427
430
  user_did?: string | undefined;
428
431
  }>;
429
432
  export type ConsentApprovalRequest = z.infer<typeof consentApprovalRequestSchema>;
@@ -723,11 +726,11 @@ export declare function validateConsentPageConfig(config: unknown): z.SafeParseR
723
726
  * @returns Validation result
724
727
  */
725
728
  export declare function validateConsentApprovalRequest(request: unknown): z.SafeParseReturnType<{
726
- agent_did: string;
727
- project_id: string;
728
729
  tool: string;
729
730
  scopes: string[];
731
+ agent_did: string;
730
732
  session_id: string;
733
+ project_id: string;
731
734
  termsAccepted: boolean;
732
735
  customFields?: Record<string, string | boolean> | undefined;
733
736
  termsVersion?: string | undefined;
@@ -736,14 +739,14 @@ export declare function validateConsentApprovalRequest(request: unknown): z.Safe
736
739
  subject: string;
737
740
  name?: string | undefined;
738
741
  email?: string | undefined;
739
- } | undefined;
742
+ } | null | undefined;
740
743
  user_did?: string | undefined;
741
744
  }, {
742
- agent_did: string;
743
- project_id: string;
744
745
  tool: string;
745
746
  scopes: string[];
747
+ agent_did: string;
746
748
  session_id: string;
749
+ project_id: string;
747
750
  termsAccepted: boolean;
748
751
  customFields?: Record<string, string | boolean> | undefined;
749
752
  termsVersion?: string | undefined;
@@ -752,7 +755,7 @@ export declare function validateConsentApprovalRequest(request: unknown): z.Safe
752
755
  subject: string;
753
756
  name?: string | undefined;
754
757
  email?: string | undefined;
755
- } | undefined;
758
+ } | null | undefined;
756
759
  user_did?: string | undefined;
757
760
  }>;
758
761
  /**