@kya-os/contracts 1.0.0-alpha → 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.
- package/dist/cli.d.ts +98 -0
- package/dist/cli.js +73 -60
- package/dist/delegation/constraints.d.ts +982 -0
- package/dist/delegation/constraints.js +205 -0
- package/dist/delegation/index.d.ts +8 -0
- package/dist/delegation/index.js +24 -0
- package/dist/delegation/schemas.d.ts +3787 -0
- package/dist/delegation/schemas.js +230 -0
- package/dist/did/index.d.ts +8 -0
- package/dist/did/index.js +24 -0
- package/dist/did/resolve-contract.d.ts +220 -0
- package/dist/did/resolve-contract.js +32 -0
- package/dist/did/types.d.ts +164 -0
- package/dist/did/types.js +71 -0
- package/dist/env/constants.d.ts +58 -0
- package/dist/env/constants.js +60 -0
- package/dist/env/index.d.ts +5 -0
- package/dist/env/index.js +21 -0
- package/dist/handshake.js +35 -32
- package/dist/index.d.ts +10 -1
- package/dist/index.js +42 -9
- package/dist/proof/index.d.ts +9 -0
- package/dist/proof/index.js +25 -0
- package/dist/proof/proof-record.d.ts +838 -0
- package/dist/proof/proof-record.js +134 -0
- package/dist/proof/signing-spec.d.ts +147 -0
- package/dist/proof/signing-spec.js +123 -0
- package/dist/proof.js +35 -32
- package/dist/registry.d.ts +46 -46
- package/dist/registry.js +79 -76
- package/dist/runtime/errors.d.ts +348 -0
- package/dist/runtime/errors.js +120 -0
- package/dist/runtime/headers.d.ts +84 -0
- package/dist/runtime/headers.js +82 -0
- package/dist/runtime/index.d.ts +6 -0
- package/dist/runtime/index.js +22 -0
- package/dist/test.js +50 -45
- package/dist/tlkrc/index.d.ts +5 -0
- package/dist/tlkrc/index.js +21 -0
- package/dist/tlkrc/rotation.d.ts +246 -0
- package/dist/tlkrc/rotation.js +127 -0
- package/dist/utils/validation.d.ts +31 -0
- package/dist/utils/validation.js +70 -0
- package/dist/vc/index.d.ts +8 -0
- package/dist/vc/index.js +24 -0
- package/dist/vc/schemas.d.ts +2484 -0
- package/dist/vc/schemas.js +225 -0
- package/dist/vc/statuslist.d.ts +494 -0
- package/dist/vc/statuslist.js +133 -0
- package/dist/verifier.d.ts +56 -0
- package/dist/verifier.js +34 -29
- package/package.json +67 -15
- package/schemas/cli/register-output/v1.0.0.json +2 -2
- package/schemas/proof/v1.0.0.json +1 -1
- package/schemas/registry/receipt-v1.0.0.json +2 -2
- package/schemas/verifier/verify-page/v1.0.0.json +2 -2
- package/schemas/well-known/agent/v1.0.0.json +1 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/handshake.d.ts.map +0 -1
- package/dist/handshake.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/proof.d.ts.map +0 -1
- package/dist/proof.js.map +0 -1
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js.map +0 -1
- package/dist/test.d.ts.map +0 -1
- package/dist/test.js.map +0 -1
- package/dist/verifier.d.ts.map +0 -1
- 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
|