@perkos/schema-validation 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.
- package/README.md +180 -0
- package/dist/ai.d.mts +307 -0
- package/dist/ai.d.ts +307 -0
- package/dist/ai.js +173 -0
- package/dist/ai.js.map +1 -0
- package/dist/ai.mjs +45 -0
- package/dist/ai.mjs.map +1 -0
- package/dist/chunk-2ZIZ7TXR.mjs +130 -0
- package/dist/chunk-2ZIZ7TXR.mjs.map +1 -0
- package/dist/chunk-AGE4J5TS.mjs +127 -0
- package/dist/chunk-AGE4J5TS.mjs.map +1 -0
- package/dist/index.d.mts +41 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +351 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +111 -0
- package/dist/index.mjs.map +1 -0
- package/dist/payment.d.mts +361 -0
- package/dist/payment.d.ts +361 -0
- package/dist/payment.js +167 -0
- package/dist/payment.js.map +1 -0
- package/dist/payment.mjs +39 -0
- package/dist/payment.mjs.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @perkos/validators/payment
|
|
5
|
+
* Payment and x402 protocol validators using Zod
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare const networkSchema: z.ZodEnum<["avalanche", "base", "celo", "avalanche-fuji", "base-sepolia", "celo-alfajores"]>;
|
|
9
|
+
declare const caip2NetworkSchema: z.ZodString;
|
|
10
|
+
declare const ethereumAddressSchema: z.ZodString;
|
|
11
|
+
declare const transactionHashSchema: z.ZodString;
|
|
12
|
+
declare const signatureSchema: z.ZodString;
|
|
13
|
+
declare const paymentEnvelopeSchema: z.ZodObject<{
|
|
14
|
+
payload: z.ZodObject<{
|
|
15
|
+
from: z.ZodString;
|
|
16
|
+
to: z.ZodString;
|
|
17
|
+
value: z.ZodString;
|
|
18
|
+
validAfter: z.ZodNumber;
|
|
19
|
+
validBefore: z.ZodNumber;
|
|
20
|
+
nonce: z.ZodString;
|
|
21
|
+
network: z.ZodString;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
value: string;
|
|
24
|
+
from: string;
|
|
25
|
+
to: string;
|
|
26
|
+
validAfter: number;
|
|
27
|
+
validBefore: number;
|
|
28
|
+
nonce: string;
|
|
29
|
+
network: string;
|
|
30
|
+
}, {
|
|
31
|
+
value: string;
|
|
32
|
+
from: string;
|
|
33
|
+
to: string;
|
|
34
|
+
validAfter: number;
|
|
35
|
+
validBefore: number;
|
|
36
|
+
nonce: string;
|
|
37
|
+
network: string;
|
|
38
|
+
}>;
|
|
39
|
+
signature: z.ZodString;
|
|
40
|
+
}, "strip", z.ZodTypeAny, {
|
|
41
|
+
payload: {
|
|
42
|
+
value: string;
|
|
43
|
+
from: string;
|
|
44
|
+
to: string;
|
|
45
|
+
validAfter: number;
|
|
46
|
+
validBefore: number;
|
|
47
|
+
nonce: string;
|
|
48
|
+
network: string;
|
|
49
|
+
};
|
|
50
|
+
signature: string;
|
|
51
|
+
}, {
|
|
52
|
+
payload: {
|
|
53
|
+
value: string;
|
|
54
|
+
from: string;
|
|
55
|
+
to: string;
|
|
56
|
+
validAfter: number;
|
|
57
|
+
validBefore: number;
|
|
58
|
+
nonce: string;
|
|
59
|
+
network: string;
|
|
60
|
+
};
|
|
61
|
+
signature: string;
|
|
62
|
+
}>;
|
|
63
|
+
declare const paymentHeaderSchema: z.ZodString;
|
|
64
|
+
declare const priceSchema: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
|
65
|
+
declare const paymentConfigSchema: z.ZodObject<{
|
|
66
|
+
recipientAddress: z.ZodString;
|
|
67
|
+
network: z.ZodEnum<["avalanche", "base", "celo", "avalanche-fuji", "base-sepolia", "celo-alfajores"]>;
|
|
68
|
+
tokenAddress: z.ZodOptional<z.ZodString>;
|
|
69
|
+
prices: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
70
|
+
}, "strip", z.ZodTypeAny, {
|
|
71
|
+
network: "avalanche" | "base" | "celo" | "avalanche-fuji" | "base-sepolia" | "celo-alfajores";
|
|
72
|
+
recipientAddress: string;
|
|
73
|
+
prices: Record<string, string | number>;
|
|
74
|
+
tokenAddress?: string | undefined;
|
|
75
|
+
}, {
|
|
76
|
+
network: "avalanche" | "base" | "celo" | "avalanche-fuji" | "base-sepolia" | "celo-alfajores";
|
|
77
|
+
recipientAddress: string;
|
|
78
|
+
prices: Record<string, string | number>;
|
|
79
|
+
tokenAddress?: string | undefined;
|
|
80
|
+
}>;
|
|
81
|
+
declare const routeConfigSchema: z.ZodObject<{
|
|
82
|
+
path: z.ZodString;
|
|
83
|
+
price: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
|
84
|
+
description: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, "strip", z.ZodTypeAny, {
|
|
86
|
+
path: string;
|
|
87
|
+
price: string | number;
|
|
88
|
+
description?: string | undefined;
|
|
89
|
+
}, {
|
|
90
|
+
path: string;
|
|
91
|
+
price: string | number;
|
|
92
|
+
description?: string | undefined;
|
|
93
|
+
}>;
|
|
94
|
+
declare const paymentRequestSchema: z.ZodObject<{
|
|
95
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
|
96
|
+
recipient: z.ZodString;
|
|
97
|
+
network: z.ZodEnum<["avalanche", "base", "celo", "avalanche-fuji", "base-sepolia", "celo-alfajores"]>;
|
|
98
|
+
memo: z.ZodOptional<z.ZodString>;
|
|
99
|
+
expiresAt: z.ZodOptional<z.ZodNumber>;
|
|
100
|
+
}, "strip", z.ZodTypeAny, {
|
|
101
|
+
network: "avalanche" | "base" | "celo" | "avalanche-fuji" | "base-sepolia" | "celo-alfajores";
|
|
102
|
+
amount: string | number;
|
|
103
|
+
recipient: string;
|
|
104
|
+
memo?: string | undefined;
|
|
105
|
+
expiresAt?: number | undefined;
|
|
106
|
+
}, {
|
|
107
|
+
network: "avalanche" | "base" | "celo" | "avalanche-fuji" | "base-sepolia" | "celo-alfajores";
|
|
108
|
+
amount: string | number;
|
|
109
|
+
recipient: string;
|
|
110
|
+
memo?: string | undefined;
|
|
111
|
+
expiresAt?: number | undefined;
|
|
112
|
+
}>;
|
|
113
|
+
declare const paymentVerificationSchema: z.ZodObject<{
|
|
114
|
+
envelope: z.ZodObject<{
|
|
115
|
+
payload: z.ZodObject<{
|
|
116
|
+
from: z.ZodString;
|
|
117
|
+
to: z.ZodString;
|
|
118
|
+
value: z.ZodString;
|
|
119
|
+
validAfter: z.ZodNumber;
|
|
120
|
+
validBefore: z.ZodNumber;
|
|
121
|
+
nonce: z.ZodString;
|
|
122
|
+
network: z.ZodString;
|
|
123
|
+
}, "strip", z.ZodTypeAny, {
|
|
124
|
+
value: string;
|
|
125
|
+
from: string;
|
|
126
|
+
to: string;
|
|
127
|
+
validAfter: number;
|
|
128
|
+
validBefore: number;
|
|
129
|
+
nonce: string;
|
|
130
|
+
network: string;
|
|
131
|
+
}, {
|
|
132
|
+
value: string;
|
|
133
|
+
from: string;
|
|
134
|
+
to: string;
|
|
135
|
+
validAfter: number;
|
|
136
|
+
validBefore: number;
|
|
137
|
+
nonce: string;
|
|
138
|
+
network: string;
|
|
139
|
+
}>;
|
|
140
|
+
signature: z.ZodString;
|
|
141
|
+
}, "strip", z.ZodTypeAny, {
|
|
142
|
+
payload: {
|
|
143
|
+
value: string;
|
|
144
|
+
from: string;
|
|
145
|
+
to: string;
|
|
146
|
+
validAfter: number;
|
|
147
|
+
validBefore: number;
|
|
148
|
+
nonce: string;
|
|
149
|
+
network: string;
|
|
150
|
+
};
|
|
151
|
+
signature: string;
|
|
152
|
+
}, {
|
|
153
|
+
payload: {
|
|
154
|
+
value: string;
|
|
155
|
+
from: string;
|
|
156
|
+
to: string;
|
|
157
|
+
validAfter: number;
|
|
158
|
+
validBefore: number;
|
|
159
|
+
nonce: string;
|
|
160
|
+
network: string;
|
|
161
|
+
};
|
|
162
|
+
signature: string;
|
|
163
|
+
}>;
|
|
164
|
+
expectedAmount: z.ZodString;
|
|
165
|
+
expectedRecipient: z.ZodString;
|
|
166
|
+
tolerance: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
167
|
+
}, "strip", z.ZodTypeAny, {
|
|
168
|
+
envelope: {
|
|
169
|
+
payload: {
|
|
170
|
+
value: string;
|
|
171
|
+
from: string;
|
|
172
|
+
to: string;
|
|
173
|
+
validAfter: number;
|
|
174
|
+
validBefore: number;
|
|
175
|
+
nonce: string;
|
|
176
|
+
network: string;
|
|
177
|
+
};
|
|
178
|
+
signature: string;
|
|
179
|
+
};
|
|
180
|
+
expectedAmount: string;
|
|
181
|
+
expectedRecipient: string;
|
|
182
|
+
tolerance: number;
|
|
183
|
+
}, {
|
|
184
|
+
envelope: {
|
|
185
|
+
payload: {
|
|
186
|
+
value: string;
|
|
187
|
+
from: string;
|
|
188
|
+
to: string;
|
|
189
|
+
validAfter: number;
|
|
190
|
+
validBefore: number;
|
|
191
|
+
nonce: string;
|
|
192
|
+
network: string;
|
|
193
|
+
};
|
|
194
|
+
signature: string;
|
|
195
|
+
};
|
|
196
|
+
expectedAmount: string;
|
|
197
|
+
expectedRecipient: string;
|
|
198
|
+
tolerance?: number | undefined;
|
|
199
|
+
}>;
|
|
200
|
+
declare const tokenInfoSchema: z.ZodObject<{
|
|
201
|
+
address: z.ZodString;
|
|
202
|
+
name: z.ZodString;
|
|
203
|
+
symbol: z.ZodString;
|
|
204
|
+
decimals: z.ZodNumber;
|
|
205
|
+
chainId: z.ZodNumber;
|
|
206
|
+
}, "strip", z.ZodTypeAny, {
|
|
207
|
+
symbol: string;
|
|
208
|
+
address: string;
|
|
209
|
+
name: string;
|
|
210
|
+
decimals: number;
|
|
211
|
+
chainId: number;
|
|
212
|
+
}, {
|
|
213
|
+
symbol: string;
|
|
214
|
+
address: string;
|
|
215
|
+
name: string;
|
|
216
|
+
decimals: number;
|
|
217
|
+
chainId: number;
|
|
218
|
+
}>;
|
|
219
|
+
declare const eip712DomainSchema: z.ZodObject<{
|
|
220
|
+
name: z.ZodString;
|
|
221
|
+
version: z.ZodString;
|
|
222
|
+
chainId: z.ZodNumber;
|
|
223
|
+
verifyingContract: z.ZodString;
|
|
224
|
+
}, "strip", z.ZodTypeAny, {
|
|
225
|
+
name: string;
|
|
226
|
+
chainId: number;
|
|
227
|
+
version: string;
|
|
228
|
+
verifyingContract: string;
|
|
229
|
+
}, {
|
|
230
|
+
name: string;
|
|
231
|
+
chainId: number;
|
|
232
|
+
version: string;
|
|
233
|
+
verifyingContract: string;
|
|
234
|
+
}>;
|
|
235
|
+
declare const settlementRequestSchema: z.ZodObject<{
|
|
236
|
+
envelope: z.ZodObject<{
|
|
237
|
+
payload: z.ZodObject<{
|
|
238
|
+
from: z.ZodString;
|
|
239
|
+
to: z.ZodString;
|
|
240
|
+
value: z.ZodString;
|
|
241
|
+
validAfter: z.ZodNumber;
|
|
242
|
+
validBefore: z.ZodNumber;
|
|
243
|
+
nonce: z.ZodString;
|
|
244
|
+
network: z.ZodString;
|
|
245
|
+
}, "strip", z.ZodTypeAny, {
|
|
246
|
+
value: string;
|
|
247
|
+
from: string;
|
|
248
|
+
to: string;
|
|
249
|
+
validAfter: number;
|
|
250
|
+
validBefore: number;
|
|
251
|
+
nonce: string;
|
|
252
|
+
network: string;
|
|
253
|
+
}, {
|
|
254
|
+
value: string;
|
|
255
|
+
from: string;
|
|
256
|
+
to: string;
|
|
257
|
+
validAfter: number;
|
|
258
|
+
validBefore: number;
|
|
259
|
+
nonce: string;
|
|
260
|
+
network: string;
|
|
261
|
+
}>;
|
|
262
|
+
signature: z.ZodString;
|
|
263
|
+
}, "strip", z.ZodTypeAny, {
|
|
264
|
+
payload: {
|
|
265
|
+
value: string;
|
|
266
|
+
from: string;
|
|
267
|
+
to: string;
|
|
268
|
+
validAfter: number;
|
|
269
|
+
validBefore: number;
|
|
270
|
+
nonce: string;
|
|
271
|
+
network: string;
|
|
272
|
+
};
|
|
273
|
+
signature: string;
|
|
274
|
+
}, {
|
|
275
|
+
payload: {
|
|
276
|
+
value: string;
|
|
277
|
+
from: string;
|
|
278
|
+
to: string;
|
|
279
|
+
validAfter: number;
|
|
280
|
+
validBefore: number;
|
|
281
|
+
nonce: string;
|
|
282
|
+
network: string;
|
|
283
|
+
};
|
|
284
|
+
signature: string;
|
|
285
|
+
}>;
|
|
286
|
+
privateKey: z.ZodOptional<z.ZodString>;
|
|
287
|
+
}, "strip", z.ZodTypeAny, {
|
|
288
|
+
envelope: {
|
|
289
|
+
payload: {
|
|
290
|
+
value: string;
|
|
291
|
+
from: string;
|
|
292
|
+
to: string;
|
|
293
|
+
validAfter: number;
|
|
294
|
+
validBefore: number;
|
|
295
|
+
nonce: string;
|
|
296
|
+
network: string;
|
|
297
|
+
};
|
|
298
|
+
signature: string;
|
|
299
|
+
};
|
|
300
|
+
privateKey?: string | undefined;
|
|
301
|
+
}, {
|
|
302
|
+
envelope: {
|
|
303
|
+
payload: {
|
|
304
|
+
value: string;
|
|
305
|
+
from: string;
|
|
306
|
+
to: string;
|
|
307
|
+
validAfter: number;
|
|
308
|
+
validBefore: number;
|
|
309
|
+
nonce: string;
|
|
310
|
+
network: string;
|
|
311
|
+
};
|
|
312
|
+
signature: string;
|
|
313
|
+
};
|
|
314
|
+
privateKey?: string | undefined;
|
|
315
|
+
}>;
|
|
316
|
+
declare const settlementResultSchema: z.ZodObject<{
|
|
317
|
+
success: z.ZodBoolean;
|
|
318
|
+
transactionHash: z.ZodOptional<z.ZodString>;
|
|
319
|
+
error: z.ZodOptional<z.ZodString>;
|
|
320
|
+
gasUsed: z.ZodOptional<z.ZodString>;
|
|
321
|
+
}, "strip", z.ZodTypeAny, {
|
|
322
|
+
success: boolean;
|
|
323
|
+
error?: string | undefined;
|
|
324
|
+
transactionHash?: string | undefined;
|
|
325
|
+
gasUsed?: string | undefined;
|
|
326
|
+
}, {
|
|
327
|
+
success: boolean;
|
|
328
|
+
error?: string | undefined;
|
|
329
|
+
transactionHash?: string | undefined;
|
|
330
|
+
gasUsed?: string | undefined;
|
|
331
|
+
}>;
|
|
332
|
+
declare const paymentErrorSchema: z.ZodObject<{
|
|
333
|
+
error: z.ZodString;
|
|
334
|
+
code: z.ZodEnum<["MISSING_PAYMENT", "INVALID_SIGNATURE", "INVALID_AMOUNT", "EXPIRED_PAYMENT", "INSUFFICIENT_BALANCE", "SETTLEMENT_FAILED", "NETWORK_MISMATCH"]>;
|
|
335
|
+
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
336
|
+
}, "strip", z.ZodTypeAny, {
|
|
337
|
+
code: "MISSING_PAYMENT" | "INVALID_SIGNATURE" | "INVALID_AMOUNT" | "EXPIRED_PAYMENT" | "INSUFFICIENT_BALANCE" | "SETTLEMENT_FAILED" | "NETWORK_MISMATCH";
|
|
338
|
+
error: string;
|
|
339
|
+
details?: Record<string, unknown> | undefined;
|
|
340
|
+
}, {
|
|
341
|
+
code: "MISSING_PAYMENT" | "INVALID_SIGNATURE" | "INVALID_AMOUNT" | "EXPIRED_PAYMENT" | "INSUFFICIENT_BALANCE" | "SETTLEMENT_FAILED" | "NETWORK_MISMATCH";
|
|
342
|
+
error: string;
|
|
343
|
+
details?: Record<string, unknown> | undefined;
|
|
344
|
+
}>;
|
|
345
|
+
type Network = z.infer<typeof networkSchema>;
|
|
346
|
+
type CAIP2Network = z.infer<typeof caip2NetworkSchema>;
|
|
347
|
+
type EthereumAddress = z.infer<typeof ethereumAddressSchema>;
|
|
348
|
+
type TransactionHash = z.infer<typeof transactionHashSchema>;
|
|
349
|
+
type Signature = z.infer<typeof signatureSchema>;
|
|
350
|
+
type PaymentEnvelope = z.infer<typeof paymentEnvelopeSchema>;
|
|
351
|
+
type PaymentConfig = z.infer<typeof paymentConfigSchema>;
|
|
352
|
+
type RouteConfig = z.infer<typeof routeConfigSchema>;
|
|
353
|
+
type PaymentRequest = z.infer<typeof paymentRequestSchema>;
|
|
354
|
+
type PaymentVerification = z.infer<typeof paymentVerificationSchema>;
|
|
355
|
+
type TokenInfo = z.infer<typeof tokenInfoSchema>;
|
|
356
|
+
type EIP712Domain = z.infer<typeof eip712DomainSchema>;
|
|
357
|
+
type SettlementRequest = z.infer<typeof settlementRequestSchema>;
|
|
358
|
+
type SettlementResult = z.infer<typeof settlementResultSchema>;
|
|
359
|
+
type PaymentError = z.infer<typeof paymentErrorSchema>;
|
|
360
|
+
|
|
361
|
+
export { type CAIP2Network, type EIP712Domain, type EthereumAddress, type Network, type PaymentConfig, type PaymentEnvelope, type PaymentError, type PaymentRequest, type PaymentVerification, type RouteConfig, type SettlementRequest, type SettlementResult, type Signature, type TokenInfo, type TransactionHash, caip2NetworkSchema, eip712DomainSchema, ethereumAddressSchema, networkSchema, paymentConfigSchema, paymentEnvelopeSchema, paymentErrorSchema, paymentHeaderSchema, paymentRequestSchema, paymentVerificationSchema, priceSchema, routeConfigSchema, settlementRequestSchema, settlementResultSchema, signatureSchema, tokenInfoSchema, transactionHashSchema };
|
package/dist/payment.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/payment.ts
|
|
21
|
+
var payment_exports = {};
|
|
22
|
+
__export(payment_exports, {
|
|
23
|
+
caip2NetworkSchema: () => caip2NetworkSchema,
|
|
24
|
+
eip712DomainSchema: () => eip712DomainSchema,
|
|
25
|
+
ethereumAddressSchema: () => ethereumAddressSchema,
|
|
26
|
+
networkSchema: () => networkSchema,
|
|
27
|
+
paymentConfigSchema: () => paymentConfigSchema,
|
|
28
|
+
paymentEnvelopeSchema: () => paymentEnvelopeSchema,
|
|
29
|
+
paymentErrorSchema: () => paymentErrorSchema,
|
|
30
|
+
paymentHeaderSchema: () => paymentHeaderSchema,
|
|
31
|
+
paymentRequestSchema: () => paymentRequestSchema,
|
|
32
|
+
paymentVerificationSchema: () => paymentVerificationSchema,
|
|
33
|
+
priceSchema: () => priceSchema,
|
|
34
|
+
routeConfigSchema: () => routeConfigSchema,
|
|
35
|
+
settlementRequestSchema: () => settlementRequestSchema,
|
|
36
|
+
settlementResultSchema: () => settlementResultSchema,
|
|
37
|
+
signatureSchema: () => signatureSchema,
|
|
38
|
+
tokenInfoSchema: () => tokenInfoSchema,
|
|
39
|
+
transactionHashSchema: () => transactionHashSchema
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(payment_exports);
|
|
42
|
+
var import_zod = require("zod");
|
|
43
|
+
var networkSchema = import_zod.z.enum([
|
|
44
|
+
"avalanche",
|
|
45
|
+
"base",
|
|
46
|
+
"celo",
|
|
47
|
+
"avalanche-fuji",
|
|
48
|
+
"base-sepolia",
|
|
49
|
+
"celo-alfajores"
|
|
50
|
+
]);
|
|
51
|
+
var caip2NetworkSchema = import_zod.z.string().regex(
|
|
52
|
+
/^eip155:\d+$/,
|
|
53
|
+
"Invalid CAIP-2 network format. Expected: eip155:<chainId>"
|
|
54
|
+
);
|
|
55
|
+
var ethereumAddressSchema = import_zod.z.string().regex(
|
|
56
|
+
/^0x[a-fA-F0-9]{40}$/,
|
|
57
|
+
"Invalid Ethereum address"
|
|
58
|
+
);
|
|
59
|
+
var transactionHashSchema = import_zod.z.string().regex(
|
|
60
|
+
/^0x[a-fA-F0-9]{64}$/,
|
|
61
|
+
"Invalid transaction hash"
|
|
62
|
+
);
|
|
63
|
+
var signatureSchema = import_zod.z.string().regex(
|
|
64
|
+
/^0x[a-fA-F0-9]+$/,
|
|
65
|
+
"Invalid signature format"
|
|
66
|
+
);
|
|
67
|
+
var paymentEnvelopeSchema = import_zod.z.object({
|
|
68
|
+
payload: import_zod.z.object({
|
|
69
|
+
from: ethereumAddressSchema,
|
|
70
|
+
to: ethereumAddressSchema,
|
|
71
|
+
value: import_zod.z.string().min(1, "Value is required"),
|
|
72
|
+
validAfter: import_zod.z.number().int().nonnegative(),
|
|
73
|
+
validBefore: import_zod.z.number().int().positive(),
|
|
74
|
+
nonce: import_zod.z.string().min(1, "Nonce is required"),
|
|
75
|
+
network: caip2NetworkSchema
|
|
76
|
+
}),
|
|
77
|
+
signature: signatureSchema
|
|
78
|
+
});
|
|
79
|
+
var paymentHeaderSchema = import_zod.z.string().regex(
|
|
80
|
+
/^x402\s+/i,
|
|
81
|
+
"Payment header must start with 'x402'"
|
|
82
|
+
);
|
|
83
|
+
var priceSchema = import_zod.z.union([
|
|
84
|
+
import_zod.z.string().regex(/^\d+(\.\d+)?$/, "Invalid price format"),
|
|
85
|
+
import_zod.z.number().positive()
|
|
86
|
+
]);
|
|
87
|
+
var paymentConfigSchema = import_zod.z.object({
|
|
88
|
+
recipientAddress: ethereumAddressSchema,
|
|
89
|
+
network: networkSchema,
|
|
90
|
+
tokenAddress: ethereumAddressSchema.optional(),
|
|
91
|
+
prices: import_zod.z.record(import_zod.z.string(), priceSchema)
|
|
92
|
+
});
|
|
93
|
+
var routeConfigSchema = import_zod.z.object({
|
|
94
|
+
path: import_zod.z.string().min(1, "Path is required"),
|
|
95
|
+
price: priceSchema,
|
|
96
|
+
description: import_zod.z.string().optional()
|
|
97
|
+
});
|
|
98
|
+
var paymentRequestSchema = import_zod.z.object({
|
|
99
|
+
amount: priceSchema,
|
|
100
|
+
recipient: ethereumAddressSchema,
|
|
101
|
+
network: networkSchema,
|
|
102
|
+
memo: import_zod.z.string().optional(),
|
|
103
|
+
expiresAt: import_zod.z.number().int().positive().optional()
|
|
104
|
+
});
|
|
105
|
+
var paymentVerificationSchema = import_zod.z.object({
|
|
106
|
+
envelope: paymentEnvelopeSchema,
|
|
107
|
+
expectedAmount: import_zod.z.string(),
|
|
108
|
+
expectedRecipient: ethereumAddressSchema,
|
|
109
|
+
tolerance: import_zod.z.number().min(0).max(1).optional().default(0)
|
|
110
|
+
});
|
|
111
|
+
var tokenInfoSchema = import_zod.z.object({
|
|
112
|
+
address: ethereumAddressSchema,
|
|
113
|
+
name: import_zod.z.string(),
|
|
114
|
+
symbol: import_zod.z.string(),
|
|
115
|
+
decimals: import_zod.z.number().int().min(0).max(18),
|
|
116
|
+
chainId: import_zod.z.number().int().positive()
|
|
117
|
+
});
|
|
118
|
+
var eip712DomainSchema = import_zod.z.object({
|
|
119
|
+
name: import_zod.z.string(),
|
|
120
|
+
version: import_zod.z.string(),
|
|
121
|
+
chainId: import_zod.z.number().int().positive(),
|
|
122
|
+
verifyingContract: ethereumAddressSchema
|
|
123
|
+
});
|
|
124
|
+
var settlementRequestSchema = import_zod.z.object({
|
|
125
|
+
envelope: paymentEnvelopeSchema,
|
|
126
|
+
privateKey: import_zod.z.string().optional()
|
|
127
|
+
});
|
|
128
|
+
var settlementResultSchema = import_zod.z.object({
|
|
129
|
+
success: import_zod.z.boolean(),
|
|
130
|
+
transactionHash: transactionHashSchema.optional(),
|
|
131
|
+
error: import_zod.z.string().optional(),
|
|
132
|
+
gasUsed: import_zod.z.string().optional()
|
|
133
|
+
});
|
|
134
|
+
var paymentErrorSchema = import_zod.z.object({
|
|
135
|
+
error: import_zod.z.string(),
|
|
136
|
+
code: import_zod.z.enum([
|
|
137
|
+
"MISSING_PAYMENT",
|
|
138
|
+
"INVALID_SIGNATURE",
|
|
139
|
+
"INVALID_AMOUNT",
|
|
140
|
+
"EXPIRED_PAYMENT",
|
|
141
|
+
"INSUFFICIENT_BALANCE",
|
|
142
|
+
"SETTLEMENT_FAILED",
|
|
143
|
+
"NETWORK_MISMATCH"
|
|
144
|
+
]),
|
|
145
|
+
details: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
|
|
146
|
+
});
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
149
|
+
caip2NetworkSchema,
|
|
150
|
+
eip712DomainSchema,
|
|
151
|
+
ethereumAddressSchema,
|
|
152
|
+
networkSchema,
|
|
153
|
+
paymentConfigSchema,
|
|
154
|
+
paymentEnvelopeSchema,
|
|
155
|
+
paymentErrorSchema,
|
|
156
|
+
paymentHeaderSchema,
|
|
157
|
+
paymentRequestSchema,
|
|
158
|
+
paymentVerificationSchema,
|
|
159
|
+
priceSchema,
|
|
160
|
+
routeConfigSchema,
|
|
161
|
+
settlementRequestSchema,
|
|
162
|
+
settlementResultSchema,
|
|
163
|
+
signatureSchema,
|
|
164
|
+
tokenInfoSchema,
|
|
165
|
+
transactionHashSchema
|
|
166
|
+
});
|
|
167
|
+
//# sourceMappingURL=payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/payment.ts"],"sourcesContent":["/**\n * @perkos/validators/payment\n * Payment and x402 protocol validators using Zod\n */\n\nimport { z } from \"zod\";\n\n// ============================================================================\n// Network & Chain Validators\n// ============================================================================\n\nexport const networkSchema = z.enum([\n \"avalanche\",\n \"base\",\n \"celo\",\n \"avalanche-fuji\",\n \"base-sepolia\",\n \"celo-alfajores\",\n]);\n\nexport const caip2NetworkSchema = z.string().regex(\n /^eip155:\\d+$/,\n \"Invalid CAIP-2 network format. Expected: eip155:<chainId>\"\n);\n\nexport const ethereumAddressSchema = z.string().regex(\n /^0x[a-fA-F0-9]{40}$/,\n \"Invalid Ethereum address\"\n);\n\nexport const transactionHashSchema = z.string().regex(\n /^0x[a-fA-F0-9]{64}$/,\n \"Invalid transaction hash\"\n);\n\nexport const signatureSchema = z.string().regex(\n /^0x[a-fA-F0-9]+$/,\n \"Invalid signature format\"\n);\n\n// ============================================================================\n// Payment Envelope Validators\n// ============================================================================\n\nexport const paymentEnvelopeSchema = z.object({\n payload: z.object({\n from: ethereumAddressSchema,\n to: ethereumAddressSchema,\n value: z.string().min(1, \"Value is required\"),\n validAfter: z.number().int().nonnegative(),\n validBefore: z.number().int().positive(),\n nonce: z.string().min(1, \"Nonce is required\"),\n network: caip2NetworkSchema,\n }),\n signature: signatureSchema,\n});\n\nexport const paymentHeaderSchema = z.string().regex(\n /^x402\\s+/i,\n \"Payment header must start with 'x402'\"\n);\n\n// ============================================================================\n// Payment Configuration Validators\n// ============================================================================\n\nexport const priceSchema = z.union([\n z.string().regex(/^\\d+(\\.\\d+)?$/, \"Invalid price format\"),\n z.number().positive(),\n]);\n\nexport const paymentConfigSchema = z.object({\n recipientAddress: ethereumAddressSchema,\n network: networkSchema,\n tokenAddress: ethereumAddressSchema.optional(),\n prices: z.record(z.string(), priceSchema),\n});\n\nexport const routeConfigSchema = z.object({\n path: z.string().min(1, \"Path is required\"),\n price: priceSchema,\n description: z.string().optional(),\n});\n\n// ============================================================================\n// Payment Request Validators\n// ============================================================================\n\nexport const paymentRequestSchema = z.object({\n amount: priceSchema,\n recipient: ethereumAddressSchema,\n network: networkSchema,\n memo: z.string().optional(),\n expiresAt: z.number().int().positive().optional(),\n});\n\nexport const paymentVerificationSchema = z.object({\n envelope: paymentEnvelopeSchema,\n expectedAmount: z.string(),\n expectedRecipient: ethereumAddressSchema,\n tolerance: z.number().min(0).max(1).optional().default(0),\n});\n\n// ============================================================================\n// Token Validators\n// ============================================================================\n\nexport const tokenInfoSchema = z.object({\n address: ethereumAddressSchema,\n name: z.string(),\n symbol: z.string(),\n decimals: z.number().int().min(0).max(18),\n chainId: z.number().int().positive(),\n});\n\nexport const eip712DomainSchema = z.object({\n name: z.string(),\n version: z.string(),\n chainId: z.number().int().positive(),\n verifyingContract: ethereumAddressSchema,\n});\n\n// ============================================================================\n// Settlement Validators\n// ============================================================================\n\nexport const settlementRequestSchema = z.object({\n envelope: paymentEnvelopeSchema,\n privateKey: z.string().optional(),\n});\n\nexport const settlementResultSchema = z.object({\n success: z.boolean(),\n transactionHash: transactionHashSchema.optional(),\n error: z.string().optional(),\n gasUsed: z.string().optional(),\n});\n\n// ============================================================================\n// Error Response Validators\n// ============================================================================\n\nexport const paymentErrorSchema = z.object({\n error: z.string(),\n code: z.enum([\n \"MISSING_PAYMENT\",\n \"INVALID_SIGNATURE\",\n \"INVALID_AMOUNT\",\n \"EXPIRED_PAYMENT\",\n \"INSUFFICIENT_BALANCE\",\n \"SETTLEMENT_FAILED\",\n \"NETWORK_MISMATCH\",\n ]),\n details: z.record(z.string(), z.unknown()).optional(),\n});\n\n// ============================================================================\n// Type Exports\n// ============================================================================\n\nexport type Network = z.infer<typeof networkSchema>;\nexport type CAIP2Network = z.infer<typeof caip2NetworkSchema>;\nexport type EthereumAddress = z.infer<typeof ethereumAddressSchema>;\nexport type TransactionHash = z.infer<typeof transactionHashSchema>;\nexport type Signature = z.infer<typeof signatureSchema>;\nexport type PaymentEnvelope = z.infer<typeof paymentEnvelopeSchema>;\nexport type PaymentConfig = z.infer<typeof paymentConfigSchema>;\nexport type RouteConfig = z.infer<typeof routeConfigSchema>;\nexport type PaymentRequest = z.infer<typeof paymentRequestSchema>;\nexport type PaymentVerification = z.infer<typeof paymentVerificationSchema>;\nexport type TokenInfo = z.infer<typeof tokenInfoSchema>;\nexport type EIP712Domain = z.infer<typeof eip712DomainSchema>;\nexport type SettlementRequest = z.infer<typeof settlementRequestSchema>;\nexport type SettlementResult = z.infer<typeof settlementResultSchema>;\nexport type PaymentError = z.infer<typeof paymentErrorSchema>;\n"],"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7C,SAAS,aAAE,QAAQ;AAAA,EACnB,iBAAiB,sBAAsB,SAAS;AAAA,EAChD,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,SAAS,aAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAMM,IAAM,qBAAqB,aAAE,OAAO;AAAA,EACzC,OAAO,aAAE,OAAO;AAAA,EAChB,MAAM,aAAE,KAAK;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAAA,EACD,SAAS,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,QAAQ,CAAC,EAAE,SAAS;AACtD,CAAC;","names":[]}
|
package/dist/payment.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
caip2NetworkSchema,
|
|
3
|
+
eip712DomainSchema,
|
|
4
|
+
ethereumAddressSchema,
|
|
5
|
+
networkSchema,
|
|
6
|
+
paymentConfigSchema,
|
|
7
|
+
paymentEnvelopeSchema,
|
|
8
|
+
paymentErrorSchema,
|
|
9
|
+
paymentHeaderSchema,
|
|
10
|
+
paymentRequestSchema,
|
|
11
|
+
paymentVerificationSchema,
|
|
12
|
+
priceSchema,
|
|
13
|
+
routeConfigSchema,
|
|
14
|
+
settlementRequestSchema,
|
|
15
|
+
settlementResultSchema,
|
|
16
|
+
signatureSchema,
|
|
17
|
+
tokenInfoSchema,
|
|
18
|
+
transactionHashSchema
|
|
19
|
+
} from "./chunk-AGE4J5TS.mjs";
|
|
20
|
+
export {
|
|
21
|
+
caip2NetworkSchema,
|
|
22
|
+
eip712DomainSchema,
|
|
23
|
+
ethereumAddressSchema,
|
|
24
|
+
networkSchema,
|
|
25
|
+
paymentConfigSchema,
|
|
26
|
+
paymentEnvelopeSchema,
|
|
27
|
+
paymentErrorSchema,
|
|
28
|
+
paymentHeaderSchema,
|
|
29
|
+
paymentRequestSchema,
|
|
30
|
+
paymentVerificationSchema,
|
|
31
|
+
priceSchema,
|
|
32
|
+
routeConfigSchema,
|
|
33
|
+
settlementRequestSchema,
|
|
34
|
+
settlementResultSchema,
|
|
35
|
+
signatureSchema,
|
|
36
|
+
tokenInfoSchema,
|
|
37
|
+
transactionHashSchema
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=payment.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@perkos/schema-validation",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Zod validation schemas for AI and payment services",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./ai": {
|
|
15
|
+
"types": "./dist/ai.d.ts",
|
|
16
|
+
"import": "./dist/ai.mjs",
|
|
17
|
+
"require": "./dist/ai.js"
|
|
18
|
+
},
|
|
19
|
+
"./payment": {
|
|
20
|
+
"types": "./dist/payment.d.ts",
|
|
21
|
+
"import": "./dist/payment.mjs",
|
|
22
|
+
"require": "./dist/payment.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch",
|
|
31
|
+
"lint": "tsc --noEmit",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"clean": "rm -rf dist",
|
|
34
|
+
"prepublishOnly": "npm run build"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"zod",
|
|
38
|
+
"validation",
|
|
39
|
+
"schemas",
|
|
40
|
+
"ai",
|
|
41
|
+
"payment",
|
|
42
|
+
"x402",
|
|
43
|
+
"perkos"
|
|
44
|
+
],
|
|
45
|
+
"author": "PerkOS",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/PerkOS-xyz/pkg-schema-validation.git"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"zod": "^3.22.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^20.10.0",
|
|
56
|
+
"tsup": "^8.0.1",
|
|
57
|
+
"typescript": "^5.3.3",
|
|
58
|
+
"vitest": "^1.2.0"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=18.0.0"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"zod": "^3.22.0"
|
|
65
|
+
}
|
|
66
|
+
}
|