@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.
Files changed (71) hide show
  1. package/dist/cli.d.ts +98 -0
  2. package/dist/cli.js +73 -60
  3. package/dist/delegation/constraints.d.ts +982 -0
  4. package/dist/delegation/constraints.js +205 -0
  5. package/dist/delegation/index.d.ts +8 -0
  6. package/dist/delegation/index.js +24 -0
  7. package/dist/delegation/schemas.d.ts +3787 -0
  8. package/dist/delegation/schemas.js +230 -0
  9. package/dist/did/index.d.ts +8 -0
  10. package/dist/did/index.js +24 -0
  11. package/dist/did/resolve-contract.d.ts +220 -0
  12. package/dist/did/resolve-contract.js +32 -0
  13. package/dist/did/types.d.ts +164 -0
  14. package/dist/did/types.js +71 -0
  15. package/dist/env/constants.d.ts +58 -0
  16. package/dist/env/constants.js +60 -0
  17. package/dist/env/index.d.ts +5 -0
  18. package/dist/env/index.js +21 -0
  19. package/dist/handshake.js +35 -32
  20. package/dist/index.d.ts +10 -1
  21. package/dist/index.js +42 -9
  22. package/dist/proof/index.d.ts +9 -0
  23. package/dist/proof/index.js +25 -0
  24. package/dist/proof/proof-record.d.ts +838 -0
  25. package/dist/proof/proof-record.js +134 -0
  26. package/dist/proof/signing-spec.d.ts +147 -0
  27. package/dist/proof/signing-spec.js +123 -0
  28. package/dist/proof.js +35 -32
  29. package/dist/registry.d.ts +46 -46
  30. package/dist/registry.js +79 -76
  31. package/dist/runtime/errors.d.ts +348 -0
  32. package/dist/runtime/errors.js +120 -0
  33. package/dist/runtime/headers.d.ts +84 -0
  34. package/dist/runtime/headers.js +82 -0
  35. package/dist/runtime/index.d.ts +6 -0
  36. package/dist/runtime/index.js +22 -0
  37. package/dist/test.js +50 -45
  38. package/dist/tlkrc/index.d.ts +5 -0
  39. package/dist/tlkrc/index.js +21 -0
  40. package/dist/tlkrc/rotation.d.ts +246 -0
  41. package/dist/tlkrc/rotation.js +127 -0
  42. package/dist/utils/validation.d.ts +31 -0
  43. package/dist/utils/validation.js +70 -0
  44. package/dist/vc/index.d.ts +8 -0
  45. package/dist/vc/index.js +24 -0
  46. package/dist/vc/schemas.d.ts +2484 -0
  47. package/dist/vc/schemas.js +225 -0
  48. package/dist/vc/statuslist.d.ts +494 -0
  49. package/dist/vc/statuslist.js +133 -0
  50. package/dist/verifier.d.ts +56 -0
  51. package/dist/verifier.js +34 -29
  52. package/package.json +67 -15
  53. package/schemas/cli/register-output/v1.0.0.json +2 -2
  54. package/schemas/proof/v1.0.0.json +1 -1
  55. package/schemas/registry/receipt-v1.0.0.json +2 -2
  56. package/schemas/verifier/verify-page/v1.0.0.json +2 -2
  57. package/schemas/well-known/agent/v1.0.0.json +1 -1
  58. package/dist/cli.d.ts.map +0 -1
  59. package/dist/cli.js.map +0 -1
  60. package/dist/handshake.d.ts.map +0 -1
  61. package/dist/handshake.js.map +0 -1
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/index.js.map +0 -1
  64. package/dist/proof.d.ts.map +0 -1
  65. package/dist/proof.js.map +0 -1
  66. package/dist/registry.d.ts.map +0 -1
  67. package/dist/registry.js.map +0 -1
  68. package/dist/test.d.ts.map +0 -1
  69. package/dist/test.js.map +0 -1
  70. package/dist/verifier.d.ts.map +0 -1
  71. package/dist/verifier.js.map +0 -1
package/dist/test.js CHANGED
@@ -1,34 +1,39 @@
1
+ "use strict";
1
2
  /**
2
3
  * Test infrastructure types and schemas for XMCP-I
3
4
  *
4
5
  * This module provides types and utilities for testing XMCP-I applications
5
6
  * without hitting external services like KTA.
6
7
  */
7
- import { z } from "zod";
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.TEST_ERROR_CODES = exports.TEST_KEY_IDS = exports.TEST_DIDS = exports.LocalVerificationResultSchema = exports.MockIdentityProviderConfigSchema = exports.MockKTAFailureTypeSchema = exports.MockDelegationStatusSchema = exports.MockIdentitySchema = exports.TestEnvironmentSchema = void 0;
10
+ exports.isTestEnvironment = isTestEnvironment;
11
+ exports.getTestSeed = getTestSeed;
12
+ const zod_1 = require("zod");
8
13
  /**
9
14
  * Test environment configuration
10
15
  */
11
- export const TestEnvironmentSchema = z.object({
12
- mode: z.literal("test"),
13
- seed: z.string().optional(),
14
- deterministicKeys: z.boolean().default(true),
15
- skipKTACalls: z.boolean().default(true),
16
+ exports.TestEnvironmentSchema = zod_1.z.object({
17
+ mode: zod_1.z.literal("test"),
18
+ seed: zod_1.z.string().optional(),
19
+ deterministicKeys: zod_1.z.boolean().default(true),
20
+ skipKTACalls: zod_1.z.boolean().default(true),
16
21
  });
17
22
  /**
18
23
  * Mock identity configuration for testing
19
24
  */
20
- export const MockIdentitySchema = z.object({
21
- did: z.string(),
22
- keyId: z.string(),
23
- privateKey: z.string(),
24
- publicKey: z.string(),
25
- createdAt: z.string(),
26
- lastRotated: z.string(),
25
+ exports.MockIdentitySchema = zod_1.z.object({
26
+ did: zod_1.z.string(),
27
+ keyId: zod_1.z.string(),
28
+ privateKey: zod_1.z.string(),
29
+ publicKey: zod_1.z.string(),
30
+ createdAt: zod_1.z.string(),
31
+ lastRotated: zod_1.z.string(),
27
32
  });
28
33
  /**
29
34
  * Mock delegation status for testing
30
35
  */
31
- export const MockDelegationStatusSchema = z.enum([
36
+ exports.MockDelegationStatusSchema = zod_1.z.enum([
32
37
  "active",
33
38
  "revoked",
34
39
  "pending",
@@ -36,7 +41,7 @@ export const MockDelegationStatusSchema = z.enum([
36
41
  /**
37
42
  * Mock KTA failure scenarios for testing
38
43
  */
39
- export const MockKTAFailureTypeSchema = z.enum([
44
+ exports.MockKTAFailureTypeSchema = zod_1.z.enum([
40
45
  "network",
41
46
  "auth",
42
47
  "invalid",
@@ -45,48 +50,48 @@ export const MockKTAFailureTypeSchema = z.enum([
45
50
  /**
46
51
  * Mock identity provider configuration
47
52
  */
48
- export const MockIdentityProviderConfigSchema = z.object({
49
- identities: z.record(z.string(), MockIdentitySchema),
50
- delegations: z.record(z.string(), MockDelegationStatusSchema),
51
- ktaFailures: z.array(MockKTAFailureTypeSchema).default([]),
52
- deterministicSeed: z.string().optional(),
53
+ exports.MockIdentityProviderConfigSchema = zod_1.z.object({
54
+ identities: zod_1.z.record(zod_1.z.string(), exports.MockIdentitySchema),
55
+ delegations: zod_1.z.record(zod_1.z.string(), exports.MockDelegationStatusSchema),
56
+ ktaFailures: zod_1.z.array(exports.MockKTAFailureTypeSchema).default([]),
57
+ deterministicSeed: zod_1.z.string().optional(),
53
58
  });
54
59
  /**
55
60
  * Local verification result for offline testing
56
61
  */
57
- export const LocalVerificationResultSchema = z.object({
58
- valid: z.boolean(),
59
- did: z.string().optional(),
60
- keyId: z.string().optional(),
61
- signature: z.object({
62
- valid: z.boolean(),
63
- algorithm: z.string(),
64
- error: z.string().optional(),
62
+ exports.LocalVerificationResultSchema = zod_1.z.object({
63
+ valid: zod_1.z.boolean(),
64
+ did: zod_1.z.string().optional(),
65
+ keyId: zod_1.z.string().optional(),
66
+ signature: zod_1.z.object({
67
+ valid: zod_1.z.boolean(),
68
+ algorithm: zod_1.z.string(),
69
+ error: zod_1.z.string().optional(),
65
70
  }),
66
- proof: z.object({
67
- valid: z.boolean(),
68
- structure: z.boolean(),
69
- timestamps: z.boolean(),
70
- hashes: z.boolean(),
71
- error: z.string().optional(),
71
+ proof: zod_1.z.object({
72
+ valid: zod_1.z.boolean(),
73
+ structure: zod_1.z.boolean(),
74
+ timestamps: zod_1.z.boolean(),
75
+ hashes: zod_1.z.boolean(),
76
+ error: zod_1.z.string().optional(),
72
77
  }),
73
- session: z.object({
74
- valid: z.boolean(),
75
- expired: z.boolean(),
76
- error: z.string().optional(),
78
+ session: zod_1.z.object({
79
+ valid: zod_1.z.boolean(),
80
+ expired: zod_1.z.boolean(),
81
+ error: zod_1.z.string().optional(),
77
82
  }),
78
- errors: z.array(z.string()).default([]),
79
- warnings: z.array(z.string()).default([]),
83
+ errors: zod_1.z.array(zod_1.z.string()).default([]),
84
+ warnings: zod_1.z.array(zod_1.z.string()).default([]),
80
85
  });
81
86
  /**
82
87
  * Test DID and Key ID constants
83
88
  */
84
- export const TEST_DIDS = {
89
+ exports.TEST_DIDS = {
85
90
  AGENT_1: "did:test:agent-1",
86
91
  AGENT_2: "did:test:agent-2",
87
92
  VERIFIER_1: "did:test:verifier-1",
88
93
  };
89
- export const TEST_KEY_IDS = {
94
+ exports.TEST_KEY_IDS = {
90
95
  KEY_TEST_1: "key-test-1",
91
96
  KEY_TEST_2: "key-test-2",
92
97
  KEY_VERIFIER_1: "key-verifier-1",
@@ -94,19 +99,19 @@ export const TEST_KEY_IDS = {
94
99
  /**
95
100
  * Test environment detection
96
101
  */
97
- export function isTestEnvironment() {
102
+ function isTestEnvironment() {
98
103
  return process.env.XMCP_ENV === "test";
99
104
  }
100
105
  /**
101
106
  * Get test seed from environment or test name
102
107
  */
103
- export function getTestSeed(testName) {
108
+ function getTestSeed(testName) {
104
109
  return process.env.XMCP_TEST_SEED || testName || "default-test-seed";
105
110
  }
106
111
  /**
107
112
  * Error codes for test infrastructure
108
113
  */
109
- export const TEST_ERROR_CODES = {
114
+ exports.TEST_ERROR_CODES = {
110
115
  MOCK_KTA_FAILURE: "XMCP_I_TEST_MOCK_KTA_FAILURE",
111
116
  DETERMINISTIC_KEY_GENERATION_FAILED: "XMCP_I_TEST_DETERMINISTIC_KEY_FAILED",
112
117
  LOCAL_VERIFICATION_FAILED: "XMCP_I_TEST_LOCAL_VERIFICATION_FAILED",
@@ -0,0 +1,5 @@
1
+ /**
2
+ * TLKRC Module Exports
3
+ */
4
+ export * from './rotation.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * TLKRC Module Exports
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./rotation.js"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,246 @@
1
+ /**
2
+ * TLKRC (Transparent Log Key Rotation Contract)
3
+ *
4
+ * Types for key rotation events in a transparent, auditable manner
5
+ *
6
+ * Related Spec: MCP-I Core
7
+ * Python Reference: Core-Documentation.md
8
+ */
9
+ import { z } from 'zod';
10
+ /**
11
+ * Rotation Event Schema
12
+ *
13
+ * Represents a key rotation event in a transparent log.
14
+ * Events form a hash-linked chain for auditability.
15
+ *
16
+ * **Dual-Key Grace Window:**
17
+ * During rotation, both `prevKeyId` and `nextKeyId` are valid
18
+ * from `effectiveAt` until `effectiveAt + grace period`.
19
+ */
20
+ export declare const RotationEventSchema: z.ZodEffects<z.ZodObject<{
21
+ /** DID of the issuer performing the rotation */
22
+ issuerDid: z.ZodString;
23
+ /** Previous key ID being rotated out */
24
+ prevKeyId: z.ZodString;
25
+ /** New key ID being rotated in */
26
+ nextKeyId: z.ZodString;
27
+ /** Timestamp when new key becomes effective (Unix seconds) */
28
+ effectiveAt: z.ZodNumber;
29
+ /** Timestamp when event was issued (Unix seconds) */
30
+ issuedAt: z.ZodNumber;
31
+ /** Sequence number (monotonically increasing) */
32
+ seq: z.ZodNumber;
33
+ /** Hash of previous rotation event (null for first rotation) */
34
+ prevEventHash: z.ZodOptional<z.ZodString>;
35
+ /** Signature over the event (using prevKeyId) */
36
+ signature: z.ZodString;
37
+ /** Optional metadata */
38
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
39
+ }, "strip", z.ZodTypeAny, {
40
+ signature: string;
41
+ issuerDid: string;
42
+ prevKeyId: string;
43
+ nextKeyId: string;
44
+ effectiveAt: number;
45
+ issuedAt: number;
46
+ seq: number;
47
+ prevEventHash?: string | undefined;
48
+ metadata?: Record<string, any> | undefined;
49
+ }, {
50
+ signature: string;
51
+ issuerDid: string;
52
+ prevKeyId: string;
53
+ nextKeyId: string;
54
+ effectiveAt: number;
55
+ issuedAt: number;
56
+ seq: number;
57
+ prevEventHash?: string | undefined;
58
+ metadata?: Record<string, any> | undefined;
59
+ }>, {
60
+ signature: string;
61
+ issuerDid: string;
62
+ prevKeyId: string;
63
+ nextKeyId: string;
64
+ effectiveAt: number;
65
+ issuedAt: number;
66
+ seq: number;
67
+ prevEventHash?: string | undefined;
68
+ metadata?: Record<string, any> | undefined;
69
+ }, {
70
+ signature: string;
71
+ issuerDid: string;
72
+ prevKeyId: string;
73
+ nextKeyId: string;
74
+ effectiveAt: number;
75
+ issuedAt: number;
76
+ seq: number;
77
+ prevEventHash?: string | undefined;
78
+ metadata?: Record<string, any> | undefined;
79
+ }>;
80
+ export type RotationEvent = z.infer<typeof RotationEventSchema>;
81
+ /**
82
+ * Rotation Chain
83
+ *
84
+ * Represents a chain of rotation events
85
+ */
86
+ export declare const RotationChainSchema: z.ZodObject<{
87
+ /** Issuer DID */
88
+ issuerDid: z.ZodString;
89
+ /** All rotation events in order */
90
+ events: z.ZodArray<z.ZodEffects<z.ZodObject<{
91
+ /** DID of the issuer performing the rotation */
92
+ issuerDid: z.ZodString;
93
+ /** Previous key ID being rotated out */
94
+ prevKeyId: z.ZodString;
95
+ /** New key ID being rotated in */
96
+ nextKeyId: z.ZodString;
97
+ /** Timestamp when new key becomes effective (Unix seconds) */
98
+ effectiveAt: z.ZodNumber;
99
+ /** Timestamp when event was issued (Unix seconds) */
100
+ issuedAt: z.ZodNumber;
101
+ /** Sequence number (monotonically increasing) */
102
+ seq: z.ZodNumber;
103
+ /** Hash of previous rotation event (null for first rotation) */
104
+ prevEventHash: z.ZodOptional<z.ZodString>;
105
+ /** Signature over the event (using prevKeyId) */
106
+ signature: z.ZodString;
107
+ /** Optional metadata */
108
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
109
+ }, "strip", z.ZodTypeAny, {
110
+ signature: string;
111
+ issuerDid: string;
112
+ prevKeyId: string;
113
+ nextKeyId: string;
114
+ effectiveAt: number;
115
+ issuedAt: number;
116
+ seq: number;
117
+ prevEventHash?: string | undefined;
118
+ metadata?: Record<string, any> | undefined;
119
+ }, {
120
+ signature: string;
121
+ issuerDid: string;
122
+ prevKeyId: string;
123
+ nextKeyId: string;
124
+ effectiveAt: number;
125
+ issuedAt: number;
126
+ seq: number;
127
+ prevEventHash?: string | undefined;
128
+ metadata?: Record<string, any> | undefined;
129
+ }>, {
130
+ signature: string;
131
+ issuerDid: string;
132
+ prevKeyId: string;
133
+ nextKeyId: string;
134
+ effectiveAt: number;
135
+ issuedAt: number;
136
+ seq: number;
137
+ prevEventHash?: string | undefined;
138
+ metadata?: Record<string, any> | undefined;
139
+ }, {
140
+ signature: string;
141
+ issuerDid: string;
142
+ prevKeyId: string;
143
+ nextKeyId: string;
144
+ effectiveAt: number;
145
+ issuedAt: number;
146
+ seq: number;
147
+ prevEventHash?: string | undefined;
148
+ metadata?: Record<string, any> | undefined;
149
+ }>, "many">;
150
+ /** Current active key ID */
151
+ currentKeyId: z.ZodString;
152
+ /** Whether chain is valid */
153
+ valid: z.ZodBoolean;
154
+ /** Optional validation errors */
155
+ errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
156
+ }, "strip", z.ZodTypeAny, {
157
+ valid: boolean;
158
+ issuerDid: string;
159
+ events: {
160
+ signature: string;
161
+ issuerDid: string;
162
+ prevKeyId: string;
163
+ nextKeyId: string;
164
+ effectiveAt: number;
165
+ issuedAt: number;
166
+ seq: number;
167
+ prevEventHash?: string | undefined;
168
+ metadata?: Record<string, any> | undefined;
169
+ }[];
170
+ currentKeyId: string;
171
+ errors?: string[] | undefined;
172
+ }, {
173
+ valid: boolean;
174
+ issuerDid: string;
175
+ events: {
176
+ signature: string;
177
+ issuerDid: string;
178
+ prevKeyId: string;
179
+ nextKeyId: string;
180
+ effectiveAt: number;
181
+ issuedAt: number;
182
+ seq: number;
183
+ prevEventHash?: string | undefined;
184
+ metadata?: Record<string, any> | undefined;
185
+ }[];
186
+ currentKeyId: string;
187
+ errors?: string[] | undefined;
188
+ }>;
189
+ export type RotationChain = z.infer<typeof RotationChainSchema>;
190
+ /**
191
+ * Validation Helpers
192
+ */
193
+ /**
194
+ * Validate a rotation event
195
+ *
196
+ * @param event - The event to validate
197
+ * @returns Validation result
198
+ */
199
+ export declare function validateRotationEvent(event: unknown): z.SafeParseReturnType<{
200
+ signature: string;
201
+ issuerDid: string;
202
+ prevKeyId: string;
203
+ nextKeyId: string;
204
+ effectiveAt: number;
205
+ issuedAt: number;
206
+ seq: number;
207
+ prevEventHash?: string | undefined;
208
+ metadata?: Record<string, any> | undefined;
209
+ }, {
210
+ signature: string;
211
+ issuerDid: string;
212
+ prevKeyId: string;
213
+ nextKeyId: string;
214
+ effectiveAt: number;
215
+ issuedAt: number;
216
+ seq: number;
217
+ prevEventHash?: string | undefined;
218
+ metadata?: Record<string, any> | undefined;
219
+ }>;
220
+ /**
221
+ * Validate rotation chain integrity
222
+ *
223
+ * @param chain - The chain to validate
224
+ * @returns true if chain is valid
225
+ */
226
+ export declare function isRotationChainValid(chain: RotationChain): boolean;
227
+ /**
228
+ * Get active key at a specific timestamp
229
+ *
230
+ * @param chain - The rotation chain
231
+ * @param timestamp - Timestamp in seconds
232
+ * @returns Active key ID at that time, or null if none
233
+ */
234
+ export declare function getActiveKeyAt(chain: RotationChain, timestamp: number): string | null;
235
+ /**
236
+ * Constants
237
+ */
238
+ /**
239
+ * Default grace period for dual-key validity (24 hours)
240
+ */
241
+ export declare const DEFAULT_GRACE_PERIOD_SEC: number;
242
+ /**
243
+ * Maximum reasonable grace period (30 days)
244
+ */
245
+ export declare const MAX_GRACE_PERIOD_SEC: number;
246
+ //# sourceMappingURL=rotation.d.ts.map
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ /**
3
+ * TLKRC (Transparent Log Key Rotation Contract)
4
+ *
5
+ * Types for key rotation events in a transparent, auditable manner
6
+ *
7
+ * Related Spec: MCP-I Core
8
+ * Python Reference: Core-Documentation.md
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.MAX_GRACE_PERIOD_SEC = exports.DEFAULT_GRACE_PERIOD_SEC = exports.RotationChainSchema = exports.RotationEventSchema = void 0;
12
+ exports.validateRotationEvent = validateRotationEvent;
13
+ exports.isRotationChainValid = isRotationChainValid;
14
+ exports.getActiveKeyAt = getActiveKeyAt;
15
+ const zod_1 = require("zod");
16
+ /**
17
+ * Rotation Event Schema
18
+ *
19
+ * Represents a key rotation event in a transparent log.
20
+ * Events form a hash-linked chain for auditability.
21
+ *
22
+ * **Dual-Key Grace Window:**
23
+ * During rotation, both `prevKeyId` and `nextKeyId` are valid
24
+ * from `effectiveAt` until `effectiveAt + grace period`.
25
+ */
26
+ exports.RotationEventSchema = zod_1.z.object({
27
+ /** DID of the issuer performing the rotation */
28
+ issuerDid: zod_1.z.string().min(1),
29
+ /** Previous key ID being rotated out */
30
+ prevKeyId: zod_1.z.string().min(1),
31
+ /** New key ID being rotated in */
32
+ nextKeyId: zod_1.z.string().min(1),
33
+ /** Timestamp when new key becomes effective (Unix seconds) */
34
+ effectiveAt: zod_1.z.number().int().positive(),
35
+ /** Timestamp when event was issued (Unix seconds) */
36
+ issuedAt: zod_1.z.number().int().positive(),
37
+ /** Sequence number (monotonically increasing) */
38
+ seq: zod_1.z.number().int().nonnegative(),
39
+ /** Hash of previous rotation event (null for first rotation) */
40
+ prevEventHash: zod_1.z.string().optional(),
41
+ /** Signature over the event (using prevKeyId) */
42
+ signature: zod_1.z.string().min(1),
43
+ /** Optional metadata */
44
+ metadata: zod_1.z.record(zod_1.z.any()).optional(),
45
+ }).refine((event) => event.effectiveAt >= event.issuedAt, {
46
+ message: 'effectiveAt must be >= issuedAt',
47
+ });
48
+ /**
49
+ * Rotation Chain
50
+ *
51
+ * Represents a chain of rotation events
52
+ */
53
+ exports.RotationChainSchema = zod_1.z.object({
54
+ /** Issuer DID */
55
+ issuerDid: zod_1.z.string().min(1),
56
+ /** All rotation events in order */
57
+ events: zod_1.z.array(exports.RotationEventSchema).min(1),
58
+ /** Current active key ID */
59
+ currentKeyId: zod_1.z.string().min(1),
60
+ /** Whether chain is valid */
61
+ valid: zod_1.z.boolean(),
62
+ /** Optional validation errors */
63
+ errors: zod_1.z.array(zod_1.z.string()).optional(),
64
+ });
65
+ /**
66
+ * Validation Helpers
67
+ */
68
+ /**
69
+ * Validate a rotation event
70
+ *
71
+ * @param event - The event to validate
72
+ * @returns Validation result
73
+ */
74
+ function validateRotationEvent(event) {
75
+ return exports.RotationEventSchema.safeParse(event);
76
+ }
77
+ /**
78
+ * Validate rotation chain integrity
79
+ *
80
+ * @param chain - The chain to validate
81
+ * @returns true if chain is valid
82
+ */
83
+ function isRotationChainValid(chain) {
84
+ if (chain.events.length === 0) {
85
+ return false;
86
+ }
87
+ // Check sequence numbers are monotonic
88
+ for (let i = 1; i < chain.events.length; i++) {
89
+ if (chain.events[i].seq <= chain.events[i - 1].seq) {
90
+ return false;
91
+ }
92
+ }
93
+ return chain.valid;
94
+ }
95
+ /**
96
+ * Get active key at a specific timestamp
97
+ *
98
+ * @param chain - The rotation chain
99
+ * @param timestamp - Timestamp in seconds
100
+ * @returns Active key ID at that time, or null if none
101
+ */
102
+ function getActiveKeyAt(chain, timestamp) {
103
+ if (chain.events.length === 0) {
104
+ return null;
105
+ }
106
+ // Find the most recent event that's effective at the timestamp
107
+ for (let i = chain.events.length - 1; i >= 0; i--) {
108
+ const event = chain.events[i];
109
+ if (event.effectiveAt <= timestamp) {
110
+ return event.nextKeyId;
111
+ }
112
+ }
113
+ // If no event is effective yet, use the initial key
114
+ return chain.events[0].prevKeyId;
115
+ }
116
+ /**
117
+ * Constants
118
+ */
119
+ /**
120
+ * Default grace period for dual-key validity (24 hours)
121
+ */
122
+ exports.DEFAULT_GRACE_PERIOD_SEC = 24 * 60 * 60;
123
+ /**
124
+ * Maximum reasonable grace period (30 days)
125
+ */
126
+ exports.MAX_GRACE_PERIOD_SEC = 30 * 24 * 60 * 60;
127
+ //# sourceMappingURL=rotation.js.map
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Shared validation utilities for mcpi packages
3
+ * Consolidates common validation patterns to follow DRY principles
4
+ */
5
+ import { z } from "zod";
6
+ /**
7
+ * Generic validation result type
8
+ */
9
+ export interface ValidationResult<T = any> {
10
+ valid: boolean;
11
+ data?: T;
12
+ errors: string[];
13
+ }
14
+ /**
15
+ * Generic validation function with helpful error messages
16
+ */
17
+ export declare function validateInput<T>(schema: z.ZodSchema<T>, data: unknown, context?: string): ValidationResult<T>;
18
+ /**
19
+ * Validate object has required properties
20
+ */
21
+ export declare function hasRequiredProperties(obj: any, properties: string[], context?: string): ValidationResult;
22
+ /**
23
+ * Validate string format patterns
24
+ */
25
+ export declare const StringValidators: {
26
+ did: (value: string) => boolean;
27
+ keyId: (value: string) => boolean;
28
+ url: (value: string) => boolean;
29
+ projectName: (value: string) => boolean;
30
+ };
31
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * Shared validation utilities for mcpi packages
4
+ * Consolidates common validation patterns to follow DRY principles
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.StringValidators = void 0;
8
+ exports.validateInput = validateInput;
9
+ exports.hasRequiredProperties = hasRequiredProperties;
10
+ /**
11
+ * Generic validation function with helpful error messages
12
+ */
13
+ function validateInput(schema, data, context) {
14
+ const result = schema.safeParse(data);
15
+ if (result.success) {
16
+ return {
17
+ valid: true,
18
+ data: result.data,
19
+ errors: [],
20
+ };
21
+ }
22
+ const errors = result.error.errors.map((err) => {
23
+ const path = err.path.length > 0 ? ` at ${err.path.join(".")}` : "";
24
+ const contextStr = context ? ` (${context})` : "";
25
+ return `${err.message}${path}${contextStr}`;
26
+ });
27
+ return {
28
+ valid: false,
29
+ errors,
30
+ };
31
+ }
32
+ /**
33
+ * Validate object has required properties
34
+ */
35
+ function hasRequiredProperties(obj, properties, context) {
36
+ if (typeof obj !== "object" || obj === null) {
37
+ return {
38
+ valid: false,
39
+ errors: [`Expected object${context ? ` for ${context}` : ""}`],
40
+ };
41
+ }
42
+ const missing = properties.filter((prop) => !(prop in obj));
43
+ if (missing.length > 0) {
44
+ return {
45
+ valid: false,
46
+ errors: [
47
+ `Missing required properties: ${missing.join(", ")}${context ? ` in ${context}` : ""}`,
48
+ ],
49
+ };
50
+ }
51
+ return { valid: true, errors: [] };
52
+ }
53
+ /**
54
+ * Validate string format patterns
55
+ */
56
+ exports.StringValidators = {
57
+ did: (value) => /^did:[a-z0-9]+:[a-zA-Z0-9._-]+$/.test(value),
58
+ keyId: (value) => /^[a-zA-Z0-9._-]+$/.test(value),
59
+ url: (value) => {
60
+ try {
61
+ new URL(value);
62
+ return true;
63
+ }
64
+ catch {
65
+ return false;
66
+ }
67
+ },
68
+ projectName: (value) => /^[a-z0-9-]+$/.test(value) && value.length >= 1 && value.length <= 214,
69
+ };
70
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Verifiable Credentials Module Exports
3
+ *
4
+ * W3C Verifiable Credentials types, schemas, and utilities
5
+ */
6
+ export * from './schemas.js';
7
+ export * from './statuslist.js';
8
+ //# sourceMappingURL=index.d.ts.map