@kya-os/contracts 1.2.1 → 1.2.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.
Files changed (57) hide show
  1. package/dist/delegation/constraints.d.ts +982 -0
  2. package/dist/delegation/constraints.js +205 -0
  3. package/dist/delegation/index.d.ts +8 -0
  4. package/dist/delegation/index.js +24 -0
  5. package/dist/delegation/schemas.d.ts +3787 -0
  6. package/dist/delegation/schemas.js +230 -0
  7. package/dist/did/index.d.ts +8 -0
  8. package/dist/did/index.js +24 -0
  9. package/dist/did/resolve-contract.d.ts +220 -0
  10. package/dist/did/resolve-contract.js +32 -0
  11. package/dist/did/types.d.ts +164 -0
  12. package/dist/did/types.js +71 -0
  13. package/dist/env/constants.d.ts +58 -0
  14. package/dist/env/constants.js +60 -0
  15. package/dist/env/index.d.ts +5 -0
  16. package/dist/env/index.js +21 -0
  17. package/dist/index.d.ts +9 -1
  18. package/dist/index.js +17 -2
  19. package/dist/proof/index.d.ts +9 -0
  20. package/dist/proof/index.js +25 -0
  21. package/dist/proof/proof-record.d.ts +838 -0
  22. package/dist/proof/proof-record.js +134 -0
  23. package/dist/proof/signing-spec.d.ts +147 -0
  24. package/dist/proof/signing-spec.js +123 -0
  25. package/dist/runtime/errors.d.ts +348 -0
  26. package/dist/runtime/errors.js +120 -0
  27. package/dist/runtime/headers.d.ts +84 -0
  28. package/dist/runtime/headers.js +82 -0
  29. package/dist/runtime/index.d.ts +6 -0
  30. package/dist/runtime/index.js +22 -0
  31. package/dist/tlkrc/index.d.ts +5 -0
  32. package/dist/tlkrc/index.js +21 -0
  33. package/dist/tlkrc/rotation.d.ts +246 -0
  34. package/dist/tlkrc/rotation.js +127 -0
  35. package/dist/vc/index.d.ts +8 -0
  36. package/dist/vc/index.js +24 -0
  37. package/dist/vc/schemas.d.ts +2484 -0
  38. package/dist/vc/schemas.js +225 -0
  39. package/dist/vc/statuslist.d.ts +494 -0
  40. package/dist/vc/statuslist.js +133 -0
  41. package/package.json +51 -6
  42. package/dist/cli.d.ts.map +0 -1
  43. package/dist/cli.js.map +0 -1
  44. package/dist/handshake.d.ts.map +0 -1
  45. package/dist/handshake.js.map +0 -1
  46. package/dist/index.d.ts.map +0 -1
  47. package/dist/index.js.map +0 -1
  48. package/dist/proof.d.ts.map +0 -1
  49. package/dist/proof.js.map +0 -1
  50. package/dist/registry.d.ts.map +0 -1
  51. package/dist/registry.js.map +0 -1
  52. package/dist/test.d.ts.map +0 -1
  53. package/dist/test.js.map +0 -1
  54. package/dist/utils/validation.d.ts.map +0 -1
  55. package/dist/utils/validation.js.map +0 -1
  56. package/dist/verifier.d.ts.map +0 -1
  57. package/dist/verifier.js.map +0 -1
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ /**
3
+ * Verifiable Credentials (W3C 1.1) Schemas
4
+ *
5
+ * Zod schemas and TypeScript types for W3C Verifiable Credentials Data Model 1.1.
6
+ * These schemas provide runtime validation and can emit JSON Schemas for interoperability.
7
+ *
8
+ * Related Spec: MCP-I §3, W3C VC Data Model 1.1
9
+ * Python Reference: Credential-Documentation.md, Credential-Service.md
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.VerifiablePresentationSchema = exports.VerifiableCredentialSchema = exports.ProofSchema = exports.CredentialStatusSchema = exports.CredentialSubjectSchema = exports.IssuerSchema = exports.ContextSchema = exports.ContextEntrySchema = exports.STATUS_LIST_CONTEXT = exports.VC_CONTEXT = void 0;
13
+ exports.validateVerifiableCredential = validateVerifiableCredential;
14
+ exports.validateVerifiablePresentation = validateVerifiablePresentation;
15
+ exports.isCredentialExpired = isCredentialExpired;
16
+ exports.getIssuerDid = getIssuerDid;
17
+ exports.getSubjectDid = getSubjectDid;
18
+ const zod_1 = require("zod");
19
+ /**
20
+ * Standard W3C Verifiable Credentials context
21
+ */
22
+ exports.VC_CONTEXT = ['https://www.w3.org/2018/credentials/v1'];
23
+ /**
24
+ * Additional context for StatusList2021
25
+ */
26
+ exports.STATUS_LIST_CONTEXT = 'https://w3id.org/vc/status-list/2021/v1';
27
+ /**
28
+ * Context Entry Schema
29
+ *
30
+ * Supports both string URLs and context objects
31
+ */
32
+ exports.ContextEntrySchema = zod_1.z.union([
33
+ zod_1.z.string().url(),
34
+ zod_1.z.record(zod_1.z.any()),
35
+ ]);
36
+ /**
37
+ * @context Schema
38
+ *
39
+ * The @context property establishes the semantic context of the credential.
40
+ * MUST include the base VC context and MAY include additional contexts.
41
+ */
42
+ exports.ContextSchema = zod_1.z
43
+ .array(exports.ContextEntrySchema)
44
+ .nonempty()
45
+ .refine((contexts) => {
46
+ // First context must be the base VC context
47
+ const firstContext = contexts[0];
48
+ return (typeof firstContext === 'string' &&
49
+ firstContext === exports.VC_CONTEXT[0]);
50
+ }, {
51
+ message: 'First @context must be "https://www.w3.org/2018/credentials/v1"',
52
+ });
53
+ /**
54
+ * Issuer Schema
55
+ *
56
+ * The issuer can be a DID string or an object with an id field
57
+ */
58
+ exports.IssuerSchema = zod_1.z.union([
59
+ zod_1.z.string().min(1),
60
+ zod_1.z.object({
61
+ id: zod_1.z.string().min(1),
62
+ }).passthrough(), // Allow additional properties
63
+ ]);
64
+ /**
65
+ * Credential Subject Schema
66
+ *
67
+ * The subject of the credential. Can be a single object or array of objects.
68
+ * MUST have an id property that is a DID or URI.
69
+ */
70
+ exports.CredentialSubjectSchema = zod_1.z.union([
71
+ zod_1.z.record(zod_1.z.any()),
72
+ zod_1.z.array(zod_1.z.record(zod_1.z.any())),
73
+ ]);
74
+ /**
75
+ * Credential Status Schema (StatusList2021Entry)
76
+ *
77
+ * References a position in a StatusList2021 credential for revocation/suspension checking.
78
+ */
79
+ exports.CredentialStatusSchema = zod_1.z.object({
80
+ /** URI of this status entry */
81
+ id: zod_1.z.string().url(),
82
+ /** Type MUST be StatusList2021Entry */
83
+ type: zod_1.z.literal('StatusList2021Entry'),
84
+ /** Purpose of the status list (revocation or suspension) */
85
+ statusPurpose: zod_1.z.enum(['revocation', 'suspension']),
86
+ /** Index of this credential in the status list (as string per spec) */
87
+ statusListIndex: zod_1.z.string().regex(/^\d+$/, 'Must be a numeric string'),
88
+ /** URL of the StatusList2021Credential */
89
+ statusListCredential: zod_1.z.string().url(),
90
+ });
91
+ /**
92
+ * Proof Schema
93
+ *
94
+ * Cryptographic proof for the credential.
95
+ * This is a flexible schema as proof formats vary.
96
+ */
97
+ exports.ProofSchema = zod_1.z
98
+ .object({
99
+ type: zod_1.z.string().min(1),
100
+ created: zod_1.z.string().optional(),
101
+ verificationMethod: zod_1.z.string().optional(),
102
+ proofPurpose: zod_1.z.string().optional(),
103
+ })
104
+ .passthrough(); // Allow additional proof-specific fields
105
+ /**
106
+ * Verifiable Credential Schema (W3C 1.1)
107
+ *
108
+ * Core schema for W3C Verifiable Credentials.
109
+ * Supports all required and common optional fields.
110
+ */
111
+ exports.VerifiableCredentialSchema = zod_1.z.object({
112
+ /** JSON-LD context */
113
+ '@context': exports.ContextSchema,
114
+ /** Unique identifier for the credential (optional per spec) */
115
+ id: zod_1.z.string().url().optional(),
116
+ /** Type of the credential, MUST include "VerifiableCredential" */
117
+ type: zod_1.z
118
+ .array(zod_1.z.string())
119
+ .min(1)
120
+ .refine((types) => types.includes('VerifiableCredential'), {
121
+ message: 'type must include "VerifiableCredential"',
122
+ }),
123
+ /** Issuer of the credential (DID or issuer object) */
124
+ issuer: exports.IssuerSchema,
125
+ /** Issuance date in ISO 8601 format */
126
+ issuanceDate: zod_1.z.string().datetime(),
127
+ /** Expiration date in ISO 8601 format (optional) */
128
+ expirationDate: zod_1.z.string().datetime().optional(),
129
+ /** The subject(s) of the credential */
130
+ credentialSubject: exports.CredentialSubjectSchema,
131
+ /** Status information for revocation/suspension (optional) */
132
+ credentialStatus: exports.CredentialStatusSchema.optional(),
133
+ /** Cryptographic proof (optional, may be added as external proof) */
134
+ proof: exports.ProofSchema.optional(),
135
+ /** Allow additional properties for extensibility */
136
+ }).passthrough();
137
+ /**
138
+ * Verifiable Presentation Schema
139
+ *
140
+ * Schema for presenting one or more credentials.
141
+ */
142
+ exports.VerifiablePresentationSchema = zod_1.z.object({
143
+ '@context': exports.ContextSchema,
144
+ id: zod_1.z.string().url().optional(),
145
+ type: zod_1.z
146
+ .array(zod_1.z.string())
147
+ .min(1)
148
+ .refine((types) => types.includes('VerifiablePresentation'), {
149
+ message: 'type must include "VerifiablePresentation"',
150
+ }),
151
+ holder: zod_1.z.string().min(1).optional(),
152
+ verifiableCredential: zod_1.z
153
+ .union([
154
+ exports.VerifiableCredentialSchema,
155
+ zod_1.z.array(exports.VerifiableCredentialSchema),
156
+ ])
157
+ .optional(),
158
+ proof: exports.ProofSchema.optional(),
159
+ }).passthrough();
160
+ /**
161
+ * Validation Helpers
162
+ */
163
+ /**
164
+ * Validate a verifiable credential
165
+ *
166
+ * @param credential - The credential to validate
167
+ * @returns Validation result with parsed credential or errors
168
+ */
169
+ function validateVerifiableCredential(credential) {
170
+ return exports.VerifiableCredentialSchema.safeParse(credential);
171
+ }
172
+ /**
173
+ * Validate a verifiable presentation
174
+ *
175
+ * @param presentation - The presentation to validate
176
+ * @returns Validation result with parsed presentation or errors
177
+ */
178
+ function validateVerifiablePresentation(presentation) {
179
+ return exports.VerifiablePresentationSchema.safeParse(presentation);
180
+ }
181
+ /**
182
+ * Check if a credential is expired
183
+ *
184
+ * @param credential - The credential to check
185
+ * @returns true if expired, false otherwise
186
+ */
187
+ function isCredentialExpired(credential) {
188
+ if (!credential.expirationDate) {
189
+ return false;
190
+ }
191
+ try {
192
+ const expirationDate = new Date(credential.expirationDate);
193
+ const now = new Date();
194
+ return expirationDate < now;
195
+ }
196
+ catch {
197
+ return false;
198
+ }
199
+ }
200
+ /**
201
+ * Extract issuer DID from credential
202
+ *
203
+ * @param credential - The credential
204
+ * @returns The issuer DID string
205
+ */
206
+ function getIssuerDid(credential) {
207
+ const issuer = credential.issuer;
208
+ if (typeof issuer === 'string') {
209
+ return issuer;
210
+ }
211
+ return issuer.id;
212
+ }
213
+ /**
214
+ * Extract credential subject DID (if present)
215
+ *
216
+ * @param credential - The credential
217
+ * @returns The subject DID or null if not present
218
+ */
219
+ function getSubjectDid(credential) {
220
+ const subject = Array.isArray(credential.credentialSubject)
221
+ ? credential.credentialSubject[0]
222
+ : credential.credentialSubject;
223
+ return subject?.id || null;
224
+ }
225
+ //# sourceMappingURL=schemas.js.map