@kya-os/contracts 1.7.15 → 1.7.17

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.
@@ -15,7 +15,7 @@
15
15
  * Python Reference: Delegation-Documentation.md, Delegation-Service.md
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.DelegationCredentialSchema = exports.DelegationCredentialSubjectSchema = exports.DELEGATION_CREDENTIAL_CONTEXT = exports.DELEGATION_STATUSES = exports.DEFAULT_DELEGATION_STATUS = exports.MAX_DELEGATION_CHAIN_DEPTH = exports.DelegationVerificationResultSchema = exports.DelegationCreationRequestSchema = exports.DelegationChainSchema = exports.DelegationChainEntrySchema = exports.DelegationRecordSchema = exports.DelegationStatusSchema = void 0;
18
+ exports.DelegationCredentialSchema = exports.DelegationCredentialSubjectSchema = exports.DELEGATION_CREDENTIAL_CONTEXT = exports.DELEGATION_STATUSES = exports.DEFAULT_DELEGATION_STATUS = exports.MAX_DELEGATION_CHAIN_DEPTH = exports.DelegationVerificationResultSchema = exports.DelegationVerificationDetailsSchema = exports.AuthorizationInfoSchema = exports.DelegationCreationRequestSchema = exports.DelegationChainSchema = exports.DelegationChainEntrySchema = exports.DelegationRecordSchema = exports.DelegationStatusSchema = void 0;
19
19
  exports.validateDelegationRecord = validateDelegationRecord;
20
20
  exports.validateDelegationChain = validateDelegationChain;
21
21
  exports.isDelegationExpired = isDelegationExpired;
@@ -136,6 +136,71 @@ exports.DelegationCreationRequestSchema = zod_1.z.object({
136
136
  /** Optional VC ID (if not provided, will be created) */
137
137
  vcId: zod_1.z.string().optional(),
138
138
  });
139
+ /**
140
+ * Authorization Info Schema
141
+ *
142
+ * Captures HOW the user verified their identity during consent.
143
+ * This is runtime verification metadata, separate from tool requirements.
144
+ *
145
+ * Note: This schema describes authorization info in verification results,
146
+ * not tool protection requirements (which use AuthorizationRequirementSchema).
147
+ */
148
+ exports.AuthorizationInfoSchema = zod_1.z.object({
149
+ /**
150
+ * The authorization method used during consent
151
+ *
152
+ * - 'oauth2': OAuth 2.0 provider authentication (canonical)
153
+ * - 'oauth': Deprecated, use 'oauth2' (will be removed in v2.0.0)
154
+ * - 'password': Password/credential authentication
155
+ * - 'credential': Deprecated, use 'verifiable_credential' (will be removed in v2.0.0)
156
+ * - 'verifiable_credential': W3C Verifiable Credential
157
+ * - 'mdl': Mobile Driver's License
158
+ * - 'idv': Identity Verification
159
+ * - 'webauthn': WebAuthn/Passkey authentication
160
+ * - 'siwe': Sign-In with Ethereum (EIP-4361)
161
+ * - 'none': Consent-only (no authentication)
162
+ */
163
+ type: zod_1.z.enum([
164
+ 'oauth',
165
+ 'oauth2',
166
+ 'password',
167
+ 'credential',
168
+ 'verifiable_credential',
169
+ 'mdl',
170
+ 'idv',
171
+ 'webauthn',
172
+ 'siwe',
173
+ 'none',
174
+ ]),
175
+ /** OAuth/Password/IDV provider name (e.g., 'github', 'google', 'credentials') */
176
+ provider: zod_1.z.string().optional(),
177
+ /** Credential type for verifiable_credential or mdl auth */
178
+ credentialType: zod_1.z.string().optional(),
179
+ /** MDL issuer DID or identifier */
180
+ issuer: zod_1.z.string().optional(),
181
+ /** IDV verification level */
182
+ verificationLevel: zod_1.z.enum(['basic', 'enhanced', 'loa3']).optional(),
183
+ /** WebAuthn Relying Party ID */
184
+ rpId: zod_1.z.string().optional(),
185
+ /** WebAuthn user verification level */
186
+ userVerification: zod_1.z.enum(['required', 'preferred', 'discouraged']).optional(),
187
+ /** SIWE Ethereum chain ID */
188
+ chainId: zod_1.z.number().optional(),
189
+ /** SIWE domain */
190
+ domain: zod_1.z.string().optional(),
191
+ /** Timestamp when authorization was verified (milliseconds since epoch) */
192
+ verifiedAt: zod_1.z.number().int().positive().optional(),
193
+ });
194
+ /**
195
+ * Delegation Verification Details Schema
196
+ *
197
+ * Typed details object for verification results
198
+ */
199
+ exports.DelegationVerificationDetailsSchema = zod_1.z.object({
200
+ /** Authorization info - how identity was verified during consent */
201
+ authorization: exports.AuthorizationInfoSchema.optional(),
202
+ /** Additional metadata fields (extensible) */
203
+ }).passthrough();
139
204
  /**
140
205
  * Delegation Verification Result
141
206
  *
@@ -156,8 +221,8 @@ exports.DelegationVerificationResultSchema = zod_1.z.object({
156
221
  chainValid: zod_1.z.boolean().optional(),
157
222
  /** Timestamp of verification */
158
223
  verifiedAt: zod_1.z.number().int().positive(),
159
- /** Optional verification details */
160
- details: zod_1.z.record(zod_1.z.any()).optional(),
224
+ /** Verification details including authorization info */
225
+ details: exports.DelegationVerificationDetailsSchema.optional(),
161
226
  });
162
227
  /**
163
228
  * Validation Helpers
@@ -257,6 +322,9 @@ exports.DELEGATION_CREDENTIAL_CONTEXT = 'https://schemas.kya-os.ai/xmcp-i/creden
257
322
  *
258
323
  * Per Python POC (Delegation-Service.md:136-146), delegations are issued AS
259
324
  * W3C VCs, with the delegation data embedded in the credentialSubject.
325
+ *
326
+ * Phase 7 Update: Added userDid, userIdentifier, sessionId, and scopes
327
+ * to support Agent Shield VC-JWT tokens and MCP session tracking.
260
328
  */
261
329
  exports.DelegationCredentialSubjectSchema = zod_1.z.object({
262
330
  /** Subject DID (delegatee) */
@@ -269,6 +337,38 @@ exports.DelegationCredentialSubjectSchema = zod_1.z.object({
269
337
  issuerDid: zod_1.z.string().min(1),
270
338
  /** DID of the delegatee (subject, e.g., agent) */
271
339
  subjectDid: zod_1.z.string().min(1),
340
+ /**
341
+ * DID of the user who granted the delegation.
342
+ *
343
+ * This is the authorizing user's identity. In simple cases, this equals
344
+ * issuerDid. In delegated scenarios (e.g., AgentShield issuing on behalf
345
+ * of a user), userDid identifies the actual user who consented.
346
+ *
347
+ * Required by Agent Shield API for user-scoped delegations.
348
+ * @see delegationCredentialSchema in agentshield-api/schemas.ts
349
+ */
350
+ userDid: zod_1.z.string().optional(),
351
+ /**
352
+ * Human-readable identifier for the user (e.g., email, OAuth subject).
353
+ *
354
+ * Used for backward compatibility and display purposes.
355
+ * Should not be used for cryptographic identity verification.
356
+ */
357
+ userIdentifier: zod_1.z.string().optional(),
358
+ /**
359
+ * MCP session ID for session tracking and integration.
360
+ *
361
+ * Links the delegation to a specific MCP session, enabling
362
+ * session-scoped token caching and audit trails.
363
+ */
364
+ sessionId: zod_1.z.string().optional(),
365
+ /**
366
+ * Authorized scopes for this delegation.
367
+ *
368
+ * Array of scope strings (e.g., ['tool:execute', 'resource:read']).
369
+ * When present, defines what actions the delegatee is authorized to perform.
370
+ */
371
+ scopes: zod_1.z.array(zod_1.z.string()).optional(),
272
372
  /** Optional controller (user account ID or DID) */
273
373
  controller: zod_1.z.string().optional(),
274
374
  /** Optional parent delegation ID for chain tracking */
@@ -391,7 +491,7 @@ function extractDelegationFromVC(vc) {
391
491
  * The caller must sign this to create a valid DelegationCredential.
392
492
  *
393
493
  * @param delegation - The delegation record
394
- * @param options - Optional VC options (id, issuanceDate, etc.)
494
+ * @param options - Optional VC options (id, issuanceDate, userDid, sessionId, etc.)
395
495
  * @returns Unsigned DelegationCredential
396
496
  */
397
497
  function wrapDelegationAsVC(delegation, options) {
@@ -404,6 +504,8 @@ function wrapDelegationAsVC(delegation, options) {
404
504
  if (!options?.issuanceDate && delegation.createdAt) {
405
505
  issuanceDate = new Date(delegation.createdAt).toISOString();
406
506
  }
507
+ // Extract scopes from constraints if not provided
508
+ const scopes = options?.scopes || delegation.constraints.scopes;
407
509
  return {
408
510
  '@context': [
409
511
  'https://www.w3.org/2018/credentials/v1',
@@ -420,6 +522,14 @@ function wrapDelegationAsVC(delegation, options) {
420
522
  id: delegation.id,
421
523
  issuerDid: delegation.issuerDid,
422
524
  subjectDid: delegation.subjectDid,
525
+ // Include userDid if provided or fallback to controller
526
+ ...(options?.userDid && { userDid: options.userDid }),
527
+ // Include userIdentifier if provided
528
+ ...(options?.userIdentifier && { userIdentifier: options.userIdentifier }),
529
+ // Include sessionId if provided
530
+ ...(options?.sessionId && { sessionId: options.sessionId }),
531
+ // Include scopes if available
532
+ ...(scopes && scopes.length > 0 && { scopes }),
423
533
  controller: delegation.controller,
424
534
  parentId: delegation.parentId,
425
535
  constraints: delegation.constraints,
@@ -23,15 +23,15 @@ export declare const MCPClientInfoSchema: z.ZodObject<{
23
23
  persistentId: z.ZodOptional<z.ZodString>;
24
24
  }, "strip", z.ZodTypeAny, {
25
25
  name: string;
26
- version?: string | undefined;
27
26
  title?: string | undefined;
27
+ version?: string | undefined;
28
28
  platform?: string | undefined;
29
29
  vendor?: string | undefined;
30
30
  persistentId?: string | undefined;
31
31
  }, {
32
32
  name: string;
33
- version?: string | undefined;
34
33
  title?: string | undefined;
34
+ version?: string | undefined;
35
35
  platform?: string | undefined;
36
36
  vendor?: string | undefined;
37
37
  persistentId?: string | undefined;
@@ -48,20 +48,20 @@ export declare const MCPClientSessionInfoSchema: z.ZodObject<{
48
48
  protocolVersion: z.ZodOptional<z.ZodString>;
49
49
  capabilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
50
50
  }, "strip", z.ZodTypeAny, {
51
- clientId: string;
52
51
  name: string;
53
- version?: string | undefined;
52
+ clientId: string;
54
53
  title?: string | undefined;
54
+ version?: string | undefined;
55
55
  platform?: string | undefined;
56
56
  vendor?: string | undefined;
57
57
  persistentId?: string | undefined;
58
58
  protocolVersion?: string | undefined;
59
59
  capabilities?: Record<string, unknown> | undefined;
60
60
  }, {
61
- clientId: string;
62
61
  name: string;
63
- version?: string | undefined;
62
+ clientId: string;
64
63
  title?: string | undefined;
64
+ version?: string | undefined;
65
65
  platform?: string | undefined;
66
66
  vendor?: string | undefined;
67
67
  persistentId?: string | undefined;
@@ -84,20 +84,20 @@ export declare const HandshakeRequestSchema: z.ZodObject<{
84
84
  clientId: z.ZodOptional<z.ZodString>;
85
85
  }, "strip", z.ZodTypeAny, {
86
86
  name: string;
87
- clientId?: string | undefined;
88
- version?: string | undefined;
89
87
  title?: string | undefined;
88
+ version?: string | undefined;
90
89
  platform?: string | undefined;
91
90
  vendor?: string | undefined;
92
91
  persistentId?: string | undefined;
92
+ clientId?: string | undefined;
93
93
  }, {
94
94
  name: string;
95
- clientId?: string | undefined;
96
- version?: string | undefined;
97
95
  title?: string | undefined;
96
+ version?: string | undefined;
98
97
  platform?: string | undefined;
99
98
  vendor?: string | undefined;
100
99
  persistentId?: string | undefined;
100
+ clientId?: string | undefined;
101
101
  }>>;
102
102
  clientProtocolVersion: z.ZodOptional<z.ZodString>;
103
103
  clientCapabilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -108,12 +108,12 @@ export declare const HandshakeRequestSchema: z.ZodObject<{
108
108
  agentDid?: string | undefined;
109
109
  clientInfo?: {
110
110
  name: string;
111
- clientId?: string | undefined;
112
- version?: string | undefined;
113
111
  title?: string | undefined;
112
+ version?: string | undefined;
114
113
  platform?: string | undefined;
115
114
  vendor?: string | undefined;
116
115
  persistentId?: string | undefined;
116
+ clientId?: string | undefined;
117
117
  } | undefined;
118
118
  clientProtocolVersion?: string | undefined;
119
119
  clientCapabilities?: Record<string, unknown> | undefined;
@@ -124,12 +124,12 @@ export declare const HandshakeRequestSchema: z.ZodObject<{
124
124
  agentDid?: string | undefined;
125
125
  clientInfo?: {
126
126
  name: string;
127
- clientId?: string | undefined;
128
- version?: string | undefined;
129
127
  title?: string | undefined;
128
+ version?: string | undefined;
130
129
  platform?: string | undefined;
131
130
  vendor?: string | undefined;
132
131
  persistentId?: string | undefined;
132
+ clientId?: string | undefined;
133
133
  } | undefined;
134
134
  clientProtocolVersion?: string | undefined;
135
135
  clientCapabilities?: Record<string, unknown> | undefined;
@@ -158,20 +158,20 @@ export declare const SessionContextSchema: z.ZodObject<{
158
158
  protocolVersion: z.ZodOptional<z.ZodString>;
159
159
  capabilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
160
160
  }, "strip", z.ZodTypeAny, {
161
- clientId: string;
162
161
  name: string;
163
- version?: string | undefined;
162
+ clientId: string;
164
163
  title?: string | undefined;
164
+ version?: string | undefined;
165
165
  platform?: string | undefined;
166
166
  vendor?: string | undefined;
167
167
  persistentId?: string | undefined;
168
168
  protocolVersion?: string | undefined;
169
169
  capabilities?: Record<string, unknown> | undefined;
170
170
  }, {
171
- clientId: string;
172
171
  name: string;
173
- version?: string | undefined;
172
+ clientId: string;
174
173
  title?: string | undefined;
174
+ version?: string | undefined;
175
175
  platform?: string | undefined;
176
176
  vendor?: string | undefined;
177
177
  persistentId?: string | undefined;
@@ -195,29 +195,29 @@ export declare const SessionContextSchema: z.ZodObject<{
195
195
  }, "strip", z.ZodTypeAny, {
196
196
  provider: string;
197
197
  subject: string;
198
- email?: string | undefined;
199
198
  name?: string | undefined;
199
+ email?: string | undefined;
200
200
  }, {
201
201
  provider: string;
202
202
  subject: string;
203
- email?: string | undefined;
204
203
  name?: string | undefined;
204
+ email?: string | undefined;
205
205
  }>>;
206
206
  }, "strip", z.ZodTypeAny, {
207
- createdAt: number;
208
207
  nonce: string;
209
208
  audience: string;
210
209
  timestamp: number;
211
210
  sessionId: string;
211
+ createdAt: number;
212
212
  lastActivity: number;
213
213
  ttlMinutes: number;
214
- identityState: "authenticated" | "anonymous";
214
+ identityState: "anonymous" | "authenticated";
215
215
  agentDid?: string | undefined;
216
216
  clientInfo?: {
217
- clientId: string;
218
217
  name: string;
219
- version?: string | undefined;
218
+ clientId: string;
220
219
  title?: string | undefined;
220
+ version?: string | undefined;
221
221
  platform?: string | undefined;
222
222
  vendor?: string | undefined;
223
223
  persistentId?: string | undefined;
@@ -230,22 +230,22 @@ export declare const SessionContextSchema: z.ZodObject<{
230
230
  oauthIdentity?: {
231
231
  provider: string;
232
232
  subject: string;
233
- email?: string | undefined;
234
233
  name?: string | undefined;
234
+ email?: string | undefined;
235
235
  } | undefined;
236
236
  }, {
237
- createdAt: number;
238
237
  nonce: string;
239
238
  audience: string;
240
239
  timestamp: number;
241
240
  sessionId: string;
241
+ createdAt: number;
242
242
  lastActivity: number;
243
243
  agentDid?: string | undefined;
244
244
  clientInfo?: {
245
- clientId: string;
246
245
  name: string;
247
- version?: string | undefined;
246
+ clientId: string;
248
247
  title?: string | undefined;
248
+ version?: string | undefined;
249
249
  platform?: string | undefined;
250
250
  vendor?: string | undefined;
251
251
  persistentId?: string | undefined;
@@ -256,12 +256,12 @@ export declare const SessionContextSchema: z.ZodObject<{
256
256
  serverDid?: string | undefined;
257
257
  clientDid?: string | undefined;
258
258
  userDid?: string | undefined;
259
- identityState?: "authenticated" | "anonymous" | undefined;
259
+ identityState?: "anonymous" | "authenticated" | undefined;
260
260
  oauthIdentity?: {
261
261
  provider: string;
262
262
  subject: string;
263
- email?: string | undefined;
264
263
  name?: string | undefined;
264
+ email?: string | undefined;
265
265
  } | undefined;
266
266
  }>;
267
267
  export declare const NonceCacheEntrySchema: z.ZodObject<{
package/dist/handshake.js CHANGED
@@ -2,7 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NONCE_LENGTH_BYTES = exports.DEFAULT_TIMESTAMP_SKEW_SECONDS = exports.DEFAULT_SESSION_TTL_MINUTES = exports.NonceCacheConfigSchema = exports.NonceCacheEntrySchema = exports.SessionContextSchema = exports.HandshakeRequestSchema = exports.MCPClientSessionInfoSchema = exports.MCPClientInfoSchema = exports.SessionIdentityStateSchema = void 0;
4
4
  const zod_1 = require("zod");
5
- const consent_1 = require("./consent");
5
+ /**
6
+ * OAuth Identity schema (inlined to avoid ESM/CJS boundary issues with @kya-os/consent)
7
+ * This is a copy of OAuthIdentitySchema from @kya-os/consent for use in handshake types.
8
+ */
9
+ const oauthIdentitySchema = zod_1.z.object({
10
+ provider: zod_1.z.string().min(1).max(50),
11
+ subject: zod_1.z.string().min(1).max(255),
12
+ email: zod_1.z.string().email().max(255).optional(),
13
+ name: zod_1.z.string().max(255).optional(),
14
+ });
6
15
  /**
7
16
  * Handshake and session management schemas
8
17
  */
@@ -65,7 +74,7 @@ exports.SessionContextSchema = zod_1.z.object({
65
74
  * OAuth identity information (populated after successful OAuth)
66
75
  * Contains provider, subject, email from OAuth provider
67
76
  */
68
- oauthIdentity: consent_1.oauthIdentitySchema.optional(),
77
+ oauthIdentity: oauthIdentitySchema.optional(),
69
78
  });
70
79
  exports.NonceCacheEntrySchema = zod_1.z.object({
71
80
  sessionId: zod_1.z.string().min(1),