Skip to content

Commit 13e69ba

Browse files
committed
feat(artillery): add Zod validation for PKP sign result schema
- Introduced a Zod schema to validate the structure of PKP sign results, ensuring proper format for signature, verifying key, signed data, recovery ID, public key, and signature type. - Updated the pkpSign processor to validate results before logging, enhancing reliability and error handling in E2E tests.
1 parent 30b0047 commit 13e69ba

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

e2e/artillery/src/processors/pkpSign.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import { createAuthManager, storagePlugins } from "@lit-protocol/auth";
22
import { createLitClient } from "@lit-protocol/lit-client";
33
import { privateKeyToAccount } from "viem/accounts";
4+
import { z } from "zod";
45
import * as StateManager from "../StateManager";
56

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+
619
// CONFIGURATIONS
720
const _network = process.env['NETWORK'];
821

@@ -112,10 +125,14 @@ export async function runPkpSignTest(requestParams: any, context: any, ee: any,
112125
toSign: `Hello from Artillery! ${Date.now()}`, // Unique message per request
113126
});
114127

128+
// Validate the result using Zod schema
129+
const validatedResult = PkpSignResultSchema.parse(result);
130+
115131
const endTime = Date.now();
116132
const duration = endTime - startTime;
117133

118134
console.log(`✅ pkpSign successful in ${duration}ms`);
135+
console.log('✅ pkpSign result:', validatedResult);
119136

120137
// For Artillery, just return - no need to call next()
121138
return;

0 commit comments

Comments
 (0)