|
1 | 1 | import { createAuthManager, storagePlugins } from "@lit-protocol/auth"; |
2 | 2 | import { createLitClient } from "@lit-protocol/lit-client"; |
3 | 3 | import { privateKeyToAccount } from "viem/accounts"; |
| 4 | +import { z } from "zod"; |
4 | 5 | import * as StateManager from "../StateManager"; |
5 | 6 |
|
| 7 | +// PKP Sign Result Schema |
| 8 | +const PkpSignResultSchema = z.object({ |
| 9 | + signature: z.string().regex(/^0x[a-fA-F0-9]+$/, "Invalid hex signature"), |
| 10 | + verifyingKey: z.string().regex(/^0x[a-fA-F0-9]+$/, "Invalid hex verifying key"), |
| 11 | + signedData: z.string().regex(/^0x[a-fA-F0-9]+$/, "Invalid hex signed data"), |
| 12 | + recoveryId: z.number().int().min(0).max(3, "Recovery ID must be 0-3"), |
| 13 | + publicKey: z.string().regex(/^0x[a-fA-F0-9]+$/, "Invalid hex public key"), |
| 14 | + sigType: z.string().min(1, "Signature type cannot be empty"), |
| 15 | +}); |
| 16 | + |
| 17 | +type PkpSignResult = z.infer<typeof PkpSignResultSchema>; |
| 18 | + |
6 | 19 | // CONFIGURATIONS |
7 | 20 | const _network = process.env['NETWORK']; |
8 | 21 |
|
@@ -112,10 +125,14 @@ export async function runPkpSignTest(requestParams: any, context: any, ee: any, |
112 | 125 | toSign: `Hello from Artillery! ${Date.now()}`, // Unique message per request |
113 | 126 | }); |
114 | 127 |
|
| 128 | + // Validate the result using Zod schema |
| 129 | + const validatedResult = PkpSignResultSchema.parse(result); |
| 130 | + |
115 | 131 | const endTime = Date.now(); |
116 | 132 | const duration = endTime - startTime; |
117 | 133 |
|
118 | 134 | console.log(`✅ pkpSign successful in ${duration}ms`); |
| 135 | + console.log('✅ pkpSign result:', validatedResult); |
119 | 136 |
|
120 | 137 | // For Artillery, just return - no need to call next() |
121 | 138 | return; |
|
0 commit comments