@paypol-protocol/aps-1 1.0.0

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.
@@ -0,0 +1,534 @@
1
+ /**
2
+ * APS-1 Validator
3
+ *
4
+ * Runtime validation schemas for APS-1 protocol messages.
5
+ * Uses Zod for type-safe validation of manifests, execution envelopes, and results.
6
+ */
7
+ import { z } from 'zod';
8
+ export declare const APS1ManifestSchema: z.ZodObject<{
9
+ aps: z.ZodLiteral<"1.0">;
10
+ id: z.ZodString;
11
+ name: z.ZodString;
12
+ description: z.ZodString;
13
+ category: z.ZodEnum<["security", "escrow", "payments", "streams", "analytics", "deployment", "privacy", "verification", "orchestration", "payroll", "admin"]>;
14
+ version: z.ZodString;
15
+ pricing: z.ZodObject<{
16
+ basePrice: z.ZodNumber;
17
+ currency: z.ZodLiteral<"USD">;
18
+ negotiable: z.ZodBoolean;
19
+ minPrice: z.ZodOptional<z.ZodNumber>;
20
+ maxPrice: z.ZodOptional<z.ZodNumber>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ currency: "USD";
23
+ basePrice: number;
24
+ negotiable: boolean;
25
+ minPrice?: number | undefined;
26
+ maxPrice?: number | undefined;
27
+ }, {
28
+ currency: "USD";
29
+ basePrice: number;
30
+ negotiable: boolean;
31
+ minPrice?: number | undefined;
32
+ maxPrice?: number | undefined;
33
+ }>;
34
+ capabilities: z.ZodArray<z.ZodString, "many">;
35
+ paymentMethods: z.ZodArray<z.ZodEnum<["nexus-escrow", "stream-milestone", "direct-transfer"]>, "many">;
36
+ supportedTokens: z.ZodArray<z.ZodObject<{
37
+ symbol: z.ZodString;
38
+ address: z.ZodString;
39
+ decimals: z.ZodNumber;
40
+ }, "strip", z.ZodTypeAny, {
41
+ symbol: string;
42
+ address: string;
43
+ decimals: number;
44
+ }, {
45
+ symbol: string;
46
+ address: string;
47
+ decimals: number;
48
+ }>, "many">;
49
+ proofEnabled: z.ZodBoolean;
50
+ reputationScore: z.ZodOptional<z.ZodNumber>;
51
+ walletAddress: z.ZodString;
52
+ endpoints: z.ZodObject<{
53
+ manifest: z.ZodString;
54
+ execute: z.ZodString;
55
+ negotiate: z.ZodOptional<z.ZodString>;
56
+ status: z.ZodOptional<z.ZodString>;
57
+ health: z.ZodOptional<z.ZodString>;
58
+ }, "strip", z.ZodTypeAny, {
59
+ manifest: string;
60
+ execute: string;
61
+ status?: string | undefined;
62
+ negotiate?: string | undefined;
63
+ health?: string | undefined;
64
+ }, {
65
+ manifest: string;
66
+ execute: string;
67
+ status?: string | undefined;
68
+ negotiate?: string | undefined;
69
+ health?: string | undefined;
70
+ }>;
71
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
72
+ }, "strip", z.ZodTypeAny, {
73
+ name: string;
74
+ id: string;
75
+ description: string;
76
+ version: string;
77
+ aps: "1.0";
78
+ category: "streams" | "security" | "escrow" | "payments" | "analytics" | "deployment" | "privacy" | "verification" | "orchestration" | "payroll" | "admin";
79
+ pricing: {
80
+ currency: "USD";
81
+ basePrice: number;
82
+ negotiable: boolean;
83
+ minPrice?: number | undefined;
84
+ maxPrice?: number | undefined;
85
+ };
86
+ capabilities: string[];
87
+ paymentMethods: ("nexus-escrow" | "stream-milestone" | "direct-transfer")[];
88
+ supportedTokens: {
89
+ symbol: string;
90
+ address: string;
91
+ decimals: number;
92
+ }[];
93
+ proofEnabled: boolean;
94
+ walletAddress: string;
95
+ endpoints: {
96
+ manifest: string;
97
+ execute: string;
98
+ status?: string | undefined;
99
+ negotiate?: string | undefined;
100
+ health?: string | undefined;
101
+ };
102
+ metadata?: Record<string, unknown> | undefined;
103
+ reputationScore?: number | undefined;
104
+ }, {
105
+ name: string;
106
+ id: string;
107
+ description: string;
108
+ version: string;
109
+ aps: "1.0";
110
+ category: "streams" | "security" | "escrow" | "payments" | "analytics" | "deployment" | "privacy" | "verification" | "orchestration" | "payroll" | "admin";
111
+ pricing: {
112
+ currency: "USD";
113
+ basePrice: number;
114
+ negotiable: boolean;
115
+ minPrice?: number | undefined;
116
+ maxPrice?: number | undefined;
117
+ };
118
+ capabilities: string[];
119
+ paymentMethods: ("nexus-escrow" | "stream-milestone" | "direct-transfer")[];
120
+ supportedTokens: {
121
+ symbol: string;
122
+ address: string;
123
+ decimals: number;
124
+ }[];
125
+ proofEnabled: boolean;
126
+ walletAddress: string;
127
+ endpoints: {
128
+ manifest: string;
129
+ execute: string;
130
+ status?: string | undefined;
131
+ negotiate?: string | undefined;
132
+ health?: string | undefined;
133
+ };
134
+ metadata?: Record<string, unknown> | undefined;
135
+ reputationScore?: number | undefined;
136
+ }>;
137
+ export declare const APS1NegotiationSchema: z.ZodObject<{
138
+ type: z.ZodEnum<["propose", "counter", "accept", "reject"]>;
139
+ jobId: z.ZodString;
140
+ price: z.ZodNumber;
141
+ currency: z.ZodLiteral<"USD">;
142
+ message: z.ZodOptional<z.ZodString>;
143
+ timestamp: z.ZodString;
144
+ }, "strip", z.ZodTypeAny, {
145
+ currency: "USD";
146
+ type: "accept" | "reject" | "propose" | "counter";
147
+ timestamp: string;
148
+ jobId: string;
149
+ price: number;
150
+ message?: string | undefined;
151
+ }, {
152
+ currency: "USD";
153
+ type: "accept" | "reject" | "propose" | "counter";
154
+ timestamp: string;
155
+ jobId: string;
156
+ price: number;
157
+ message?: string | undefined;
158
+ }>;
159
+ export declare const APS1EscrowParamsSchema: z.ZodObject<{
160
+ method: z.ZodEnum<["nexus-escrow", "stream-milestone", "direct-transfer"]>;
161
+ token: z.ZodString;
162
+ amount: z.ZodString;
163
+ amountUSD: z.ZodNumber;
164
+ deadlineSeconds: z.ZodNumber;
165
+ workerWallet: z.ZodString;
166
+ judgeWallet: z.ZodOptional<z.ZodString>;
167
+ milestones: z.ZodOptional<z.ZodArray<z.ZodObject<{
168
+ amount: z.ZodString;
169
+ deliverable: z.ZodString;
170
+ }, "strip", z.ZodTypeAny, {
171
+ amount: string;
172
+ deliverable: string;
173
+ }, {
174
+ amount: string;
175
+ deliverable: string;
176
+ }>, "many">>;
177
+ }, "strip", z.ZodTypeAny, {
178
+ method: "nexus-escrow" | "stream-milestone" | "direct-transfer";
179
+ token: string;
180
+ amount: string;
181
+ amountUSD: number;
182
+ deadlineSeconds: number;
183
+ workerWallet: string;
184
+ judgeWallet?: string | undefined;
185
+ milestones?: {
186
+ amount: string;
187
+ deliverable: string;
188
+ }[] | undefined;
189
+ }, {
190
+ method: "nexus-escrow" | "stream-milestone" | "direct-transfer";
191
+ token: string;
192
+ amount: string;
193
+ amountUSD: number;
194
+ deadlineSeconds: number;
195
+ workerWallet: string;
196
+ judgeWallet?: string | undefined;
197
+ milestones?: {
198
+ amount: string;
199
+ deliverable: string;
200
+ }[] | undefined;
201
+ }>;
202
+ export declare const APS1ExecutionEnvelopeSchema: z.ZodObject<{
203
+ jobId: z.ZodString;
204
+ agentId: z.ZodString;
205
+ prompt: z.ZodString;
206
+ payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
207
+ callerWallet: z.ZodString;
208
+ escrow: z.ZodOptional<z.ZodObject<{
209
+ contractAddress: z.ZodString;
210
+ onChainId: z.ZodNumber;
211
+ txHash: z.ZodString;
212
+ method: z.ZodEnum<["nexus-escrow", "stream-milestone", "direct-transfer"]>;
213
+ }, "strip", z.ZodTypeAny, {
214
+ method: "nexus-escrow" | "stream-milestone" | "direct-transfer";
215
+ contractAddress: string;
216
+ onChainId: number;
217
+ txHash: string;
218
+ }, {
219
+ method: "nexus-escrow" | "stream-milestone" | "direct-transfer";
220
+ contractAddress: string;
221
+ onChainId: number;
222
+ txHash: string;
223
+ }>>;
224
+ proof: z.ZodOptional<z.ZodObject<{
225
+ planHash: z.ZodString;
226
+ commitmentId: z.ZodString;
227
+ commitTxHash: z.ZodString;
228
+ }, "strip", z.ZodTypeAny, {
229
+ planHash: string;
230
+ commitmentId: string;
231
+ commitTxHash: string;
232
+ }, {
233
+ planHash: string;
234
+ commitmentId: string;
235
+ commitTxHash: string;
236
+ }>>;
237
+ timestamp: z.ZodString;
238
+ }, "strip", z.ZodTypeAny, {
239
+ timestamp: string;
240
+ prompt: string;
241
+ jobId: string;
242
+ agentId: string;
243
+ callerWallet: string;
244
+ escrow?: {
245
+ method: "nexus-escrow" | "stream-milestone" | "direct-transfer";
246
+ contractAddress: string;
247
+ onChainId: number;
248
+ txHash: string;
249
+ } | undefined;
250
+ proof?: {
251
+ planHash: string;
252
+ commitmentId: string;
253
+ commitTxHash: string;
254
+ } | undefined;
255
+ payload?: Record<string, unknown> | undefined;
256
+ }, {
257
+ timestamp: string;
258
+ prompt: string;
259
+ jobId: string;
260
+ agentId: string;
261
+ callerWallet: string;
262
+ escrow?: {
263
+ method: "nexus-escrow" | "stream-milestone" | "direct-transfer";
264
+ contractAddress: string;
265
+ onChainId: number;
266
+ txHash: string;
267
+ } | undefined;
268
+ proof?: {
269
+ planHash: string;
270
+ commitmentId: string;
271
+ commitTxHash: string;
272
+ } | undefined;
273
+ payload?: Record<string, unknown> | undefined;
274
+ }>;
275
+ export declare const APS1ResultSchema: z.ZodObject<{
276
+ jobId: z.ZodString;
277
+ agentId: z.ZodString;
278
+ status: z.ZodEnum<["success", "error", "pending"]>;
279
+ result: z.ZodOptional<z.ZodUnknown>;
280
+ error: z.ZodOptional<z.ZodString>;
281
+ onChain: z.ZodOptional<z.ZodObject<{
282
+ executed: z.ZodBoolean;
283
+ transactions: z.ZodArray<z.ZodObject<{
284
+ hash: z.ZodString;
285
+ blockNumber: z.ZodNumber;
286
+ gasUsed: z.ZodString;
287
+ explorerUrl: z.ZodString;
288
+ description: z.ZodOptional<z.ZodString>;
289
+ }, "strip", z.ZodTypeAny, {
290
+ hash: string;
291
+ blockNumber: number;
292
+ gasUsed: string;
293
+ explorerUrl: string;
294
+ description?: string | undefined;
295
+ }, {
296
+ hash: string;
297
+ blockNumber: number;
298
+ gasUsed: string;
299
+ explorerUrl: string;
300
+ description?: string | undefined;
301
+ }>, "many">;
302
+ network: z.ZodString;
303
+ chainId: z.ZodNumber;
304
+ }, "strip", z.ZodTypeAny, {
305
+ network: string;
306
+ executed: boolean;
307
+ chainId: number;
308
+ transactions: {
309
+ hash: string;
310
+ blockNumber: number;
311
+ gasUsed: string;
312
+ explorerUrl: string;
313
+ description?: string | undefined;
314
+ }[];
315
+ }, {
316
+ network: string;
317
+ executed: boolean;
318
+ chainId: number;
319
+ transactions: {
320
+ hash: string;
321
+ blockNumber: number;
322
+ gasUsed: string;
323
+ explorerUrl: string;
324
+ description?: string | undefined;
325
+ }[];
326
+ }>>;
327
+ proof: z.ZodOptional<z.ZodObject<{
328
+ resultHash: z.ZodString;
329
+ verifyTxHash: z.ZodString;
330
+ matched: z.ZodBoolean;
331
+ }, "strip", z.ZodTypeAny, {
332
+ resultHash: string;
333
+ verifyTxHash: string;
334
+ matched: boolean;
335
+ }, {
336
+ resultHash: string;
337
+ verifyTxHash: string;
338
+ matched: boolean;
339
+ }>>;
340
+ executionTimeMs: z.ZodNumber;
341
+ timestamp: z.ZodString;
342
+ }, "strip", z.ZodTypeAny, {
343
+ timestamp: string;
344
+ status: "error" | "pending" | "success";
345
+ jobId: string;
346
+ agentId: string;
347
+ executionTimeMs: number;
348
+ error?: string | undefined;
349
+ result?: unknown;
350
+ onChain?: {
351
+ network: string;
352
+ executed: boolean;
353
+ chainId: number;
354
+ transactions: {
355
+ hash: string;
356
+ blockNumber: number;
357
+ gasUsed: string;
358
+ explorerUrl: string;
359
+ description?: string | undefined;
360
+ }[];
361
+ } | undefined;
362
+ proof?: {
363
+ resultHash: string;
364
+ verifyTxHash: string;
365
+ matched: boolean;
366
+ } | undefined;
367
+ }, {
368
+ timestamp: string;
369
+ status: "error" | "pending" | "success";
370
+ jobId: string;
371
+ agentId: string;
372
+ executionTimeMs: number;
373
+ error?: string | undefined;
374
+ result?: unknown;
375
+ onChain?: {
376
+ network: string;
377
+ executed: boolean;
378
+ chainId: number;
379
+ transactions: {
380
+ hash: string;
381
+ blockNumber: number;
382
+ gasUsed: string;
383
+ explorerUrl: string;
384
+ description?: string | undefined;
385
+ }[];
386
+ } | undefined;
387
+ proof?: {
388
+ resultHash: string;
389
+ verifyTxHash: string;
390
+ matched: boolean;
391
+ } | undefined;
392
+ }>;
393
+ export declare const APS1SettlementSchema: z.ZodObject<{
394
+ jobId: z.ZodString;
395
+ type: z.ZodEnum<["settle", "refund", "dispute"]>;
396
+ agentPayout: z.ZodString;
397
+ platformFee: z.ZodString;
398
+ txHash: z.ZodString;
399
+ timestamp: z.ZodString;
400
+ }, "strip", z.ZodTypeAny, {
401
+ type: "settle" | "refund" | "dispute";
402
+ timestamp: string;
403
+ jobId: string;
404
+ txHash: string;
405
+ agentPayout: string;
406
+ platformFee: string;
407
+ }, {
408
+ type: "settle" | "refund" | "dispute";
409
+ timestamp: string;
410
+ jobId: string;
411
+ txHash: string;
412
+ agentPayout: string;
413
+ platformFee: string;
414
+ }>;
415
+ export type ValidationResult<T> = {
416
+ success: true;
417
+ data: T;
418
+ } | {
419
+ success: false;
420
+ errors: string[];
421
+ };
422
+ /** Validate an APS-1 agent manifest */
423
+ export declare function validateManifest(data: unknown): ValidationResult<{
424
+ name: string;
425
+ id: string;
426
+ description: string;
427
+ version: string;
428
+ aps: "1.0";
429
+ category: "streams" | "security" | "escrow" | "payments" | "analytics" | "deployment" | "privacy" | "verification" | "orchestration" | "payroll" | "admin";
430
+ pricing: {
431
+ currency: "USD";
432
+ basePrice: number;
433
+ negotiable: boolean;
434
+ minPrice?: number | undefined;
435
+ maxPrice?: number | undefined;
436
+ };
437
+ capabilities: string[];
438
+ paymentMethods: ("nexus-escrow" | "stream-milestone" | "direct-transfer")[];
439
+ supportedTokens: {
440
+ symbol: string;
441
+ address: string;
442
+ decimals: number;
443
+ }[];
444
+ proofEnabled: boolean;
445
+ walletAddress: string;
446
+ endpoints: {
447
+ manifest: string;
448
+ execute: string;
449
+ status?: string | undefined;
450
+ negotiate?: string | undefined;
451
+ health?: string | undefined;
452
+ };
453
+ metadata?: Record<string, unknown> | undefined;
454
+ reputationScore?: number | undefined;
455
+ }>;
456
+ /** Validate an APS-1 execution envelope */
457
+ export declare function validateEnvelope(data: unknown): ValidationResult<{
458
+ timestamp: string;
459
+ prompt: string;
460
+ jobId: string;
461
+ agentId: string;
462
+ callerWallet: string;
463
+ escrow?: {
464
+ method: "nexus-escrow" | "stream-milestone" | "direct-transfer";
465
+ contractAddress: string;
466
+ onChainId: number;
467
+ txHash: string;
468
+ } | undefined;
469
+ proof?: {
470
+ planHash: string;
471
+ commitmentId: string;
472
+ commitTxHash: string;
473
+ } | undefined;
474
+ payload?: Record<string, unknown> | undefined;
475
+ }>;
476
+ /** Validate an APS-1 execution result */
477
+ export declare function validateResult(data: unknown): ValidationResult<{
478
+ timestamp: string;
479
+ status: "error" | "pending" | "success";
480
+ jobId: string;
481
+ agentId: string;
482
+ executionTimeMs: number;
483
+ error?: string | undefined;
484
+ result?: unknown;
485
+ onChain?: {
486
+ network: string;
487
+ executed: boolean;
488
+ chainId: number;
489
+ transactions: {
490
+ hash: string;
491
+ blockNumber: number;
492
+ gasUsed: string;
493
+ explorerUrl: string;
494
+ description?: string | undefined;
495
+ }[];
496
+ } | undefined;
497
+ proof?: {
498
+ resultHash: string;
499
+ verifyTxHash: string;
500
+ matched: boolean;
501
+ } | undefined;
502
+ }>;
503
+ /** Validate APS-1 escrow parameters */
504
+ export declare function validateEscrowParams(data: unknown): ValidationResult<{
505
+ method: "nexus-escrow" | "stream-milestone" | "direct-transfer";
506
+ token: string;
507
+ amount: string;
508
+ amountUSD: number;
509
+ deadlineSeconds: number;
510
+ workerWallet: string;
511
+ judgeWallet?: string | undefined;
512
+ milestones?: {
513
+ amount: string;
514
+ deliverable: string;
515
+ }[] | undefined;
516
+ }>;
517
+ /** Validate an APS-1 negotiation message */
518
+ export declare function validateNegotiation(data: unknown): ValidationResult<{
519
+ currency: "USD";
520
+ type: "accept" | "reject" | "propose" | "counter";
521
+ timestamp: string;
522
+ jobId: string;
523
+ price: number;
524
+ message?: string | undefined;
525
+ }>;
526
+ /** Validate an APS-1 settlement event */
527
+ export declare function validateSettlement(data: unknown): ValidationResult<{
528
+ type: "settle" | "refund" | "dispute";
529
+ timestamp: string;
530
+ jobId: string;
531
+ txHash: string;
532
+ agentPayout: string;
533
+ platformFee: string;
534
+ }>;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * APS-1 Validator
3
+ *
4
+ * Runtime validation schemas for APS-1 protocol messages.
5
+ * Uses Zod for type-safe validation of manifests, execution envelopes, and results.
6
+ */
7
+ import { z } from 'zod';
8
+ // ── Shared Schemas ─────────────────────────────────────────
9
+ const ethAddress = z.string().regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address');
10
+ const bytes32 = z.string().regex(/^0x[a-fA-F0-9]{64}$/, 'Invalid bytes32 hash');
11
+ const isoTimestamp = z.string().datetime({ message: 'Must be ISO 8601 timestamp' });
12
+ const categorySchema = z.enum([
13
+ 'security', 'escrow', 'payments', 'streams', 'analytics',
14
+ 'deployment', 'privacy', 'verification', 'orchestration', 'payroll', 'admin',
15
+ ]);
16
+ const paymentMethodSchema = z.enum(['nexus-escrow', 'stream-milestone', 'direct-transfer']);
17
+ const tokenConfigSchema = z.object({
18
+ symbol: z.string().min(1).max(20),
19
+ address: ethAddress,
20
+ decimals: z.number().int().min(0).max(18),
21
+ });
22
+ // ── APS-1 Manifest Schema ──────────────────────────────────
23
+ export const APS1ManifestSchema = z.object({
24
+ aps: z.literal('1.0'),
25
+ id: z.string().min(1).max(64).regex(/^[a-z0-9-]+$/, 'Must be kebab-case'),
26
+ name: z.string().min(1).max(128),
27
+ description: z.string().min(1).max(1024),
28
+ category: categorySchema,
29
+ version: z.string().regex(/^\d+\.\d+\.\d+$/, 'Must be semver (e.g. 1.0.0)'),
30
+ pricing: z.object({
31
+ basePrice: z.number().min(0),
32
+ currency: z.literal('USD'),
33
+ negotiable: z.boolean(),
34
+ minPrice: z.number().min(0).optional(),
35
+ maxPrice: z.number().min(0).optional(),
36
+ }),
37
+ capabilities: z.array(z.string()).min(1),
38
+ paymentMethods: z.array(paymentMethodSchema).min(1),
39
+ supportedTokens: z.array(tokenConfigSchema).min(1),
40
+ proofEnabled: z.boolean(),
41
+ reputationScore: z.number().int().min(0).max(10000).optional(),
42
+ walletAddress: ethAddress,
43
+ endpoints: z.object({
44
+ manifest: z.string().url(),
45
+ execute: z.string().url(),
46
+ negotiate: z.string().url().optional(),
47
+ status: z.string().url().optional(),
48
+ health: z.string().url().optional(),
49
+ }),
50
+ metadata: z.record(z.unknown()).optional(),
51
+ });
52
+ // ── APS-1 Negotiation Message Schema ───────────────────────
53
+ export const APS1NegotiationSchema = z.object({
54
+ type: z.enum(['propose', 'counter', 'accept', 'reject']),
55
+ jobId: z.string().min(1),
56
+ price: z.number().min(0),
57
+ currency: z.literal('USD'),
58
+ message: z.string().max(1024).optional(),
59
+ timestamp: isoTimestamp,
60
+ });
61
+ // ── APS-1 Escrow Params Schema ─────────────────────────────
62
+ export const APS1EscrowParamsSchema = z.object({
63
+ method: paymentMethodSchema,
64
+ token: ethAddress,
65
+ amount: z.string().min(1),
66
+ amountUSD: z.number().min(0),
67
+ deadlineSeconds: z.number().int().min(60).max(30 * 24 * 3600), // 1 min to 30 days
68
+ workerWallet: ethAddress,
69
+ judgeWallet: ethAddress.optional(),
70
+ milestones: z.array(z.object({
71
+ amount: z.string().min(1),
72
+ deliverable: z.string().min(1).max(512),
73
+ })).optional(),
74
+ });
75
+ // ── APS-1 Execution Envelope Schema ────────────────────────
76
+ export const APS1ExecutionEnvelopeSchema = z.object({
77
+ jobId: z.string().min(1),
78
+ agentId: z.string().min(1),
79
+ prompt: z.string().min(1).max(10000),
80
+ payload: z.record(z.unknown()).optional(),
81
+ callerWallet: ethAddress,
82
+ escrow: z.object({
83
+ contractAddress: ethAddress,
84
+ onChainId: z.number().int().min(0),
85
+ txHash: z.string().regex(/^0x[a-fA-F0-9]{64}$/),
86
+ method: paymentMethodSchema,
87
+ }).optional(),
88
+ proof: z.object({
89
+ planHash: bytes32,
90
+ commitmentId: bytes32,
91
+ commitTxHash: z.string().regex(/^0x[a-fA-F0-9]{64}$/),
92
+ }).optional(),
93
+ timestamp: isoTimestamp,
94
+ });
95
+ // ── APS-1 Result Schema ────────────────────────────────────
96
+ export const APS1ResultSchema = z.object({
97
+ jobId: z.string().min(1),
98
+ agentId: z.string().min(1),
99
+ status: z.enum(['success', 'error', 'pending']),
100
+ result: z.unknown().optional(),
101
+ error: z.string().optional(),
102
+ onChain: z.object({
103
+ executed: z.boolean(),
104
+ transactions: z.array(z.object({
105
+ hash: z.string().regex(/^0x[a-fA-F0-9]{64}$/),
106
+ blockNumber: z.number().int().min(0),
107
+ gasUsed: z.string(),
108
+ explorerUrl: z.string().url(),
109
+ description: z.string().optional(),
110
+ })),
111
+ network: z.string(),
112
+ chainId: z.number().int(),
113
+ }).optional(),
114
+ proof: z.object({
115
+ resultHash: bytes32,
116
+ verifyTxHash: z.string().regex(/^0x[a-fA-F0-9]{64}$/),
117
+ matched: z.boolean(),
118
+ }).optional(),
119
+ executionTimeMs: z.number().int().min(0),
120
+ timestamp: isoTimestamp,
121
+ });
122
+ // ── APS-1 Settlement Schema ────────────────────────────────
123
+ export const APS1SettlementSchema = z.object({
124
+ jobId: z.string().min(1),
125
+ type: z.enum(['settle', 'refund', 'dispute']),
126
+ agentPayout: z.string(),
127
+ platformFee: z.string(),
128
+ txHash: z.string().regex(/^0x[a-fA-F0-9]{64}$/),
129
+ timestamp: isoTimestamp,
130
+ });
131
+ function validate(schema, data) {
132
+ const result = schema.safeParse(data);
133
+ if (result.success) {
134
+ return { success: true, data: result.data };
135
+ }
136
+ return {
137
+ success: false,
138
+ errors: result.error.issues.map(i => `${i.path.join('.')}: ${i.message}`),
139
+ };
140
+ }
141
+ /** Validate an APS-1 agent manifest */
142
+ export function validateManifest(data) {
143
+ return validate(APS1ManifestSchema, data);
144
+ }
145
+ /** Validate an APS-1 execution envelope */
146
+ export function validateEnvelope(data) {
147
+ return validate(APS1ExecutionEnvelopeSchema, data);
148
+ }
149
+ /** Validate an APS-1 execution result */
150
+ export function validateResult(data) {
151
+ return validate(APS1ResultSchema, data);
152
+ }
153
+ /** Validate APS-1 escrow parameters */
154
+ export function validateEscrowParams(data) {
155
+ return validate(APS1EscrowParamsSchema, data);
156
+ }
157
+ /** Validate an APS-1 negotiation message */
158
+ export function validateNegotiation(data) {
159
+ return validate(APS1NegotiationSchema, data);
160
+ }
161
+ /** Validate an APS-1 settlement event */
162
+ export function validateSettlement(data) {
163
+ return validate(APS1SettlementSchema, data);
164
+ }