@@ -250,6 +250,12 @@ export const KlesiaRpcResponseSchema = z.union([
250
250
251
251
// TODO: Should probably move these validations to a separate file
252
252
253
+ interface SerializedValue {
254
+ _type : string ;
255
+ value : Json ;
256
+ properties ?: Record < string , unknown > ;
257
+ }
258
+
253
259
interface ProofType {
254
260
name : string ;
255
261
publicInput : SerializedType ;
@@ -258,17 +264,80 @@ interface ProofType {
258
264
featureFlags : Record < string , unknown > ;
259
265
}
260
266
261
- export interface SerializedType {
262
- _type ?: string ;
263
- // TODO: update based on mina-credentials
264
- type ?: "Constant" ;
267
+ interface DynamicString {
268
+ _type : "DynamicString" ;
269
+ _isFactory : true ;
270
+ maxLength : number ;
265
271
value ?: string ;
266
- size ?: number ;
267
- proof ?: ProofType ;
268
- innerType ?: SerializedType ;
269
- [ key : string ] : SerializedType | string | number | ProofType | undefined ;
270
272
}
271
273
274
+ interface DynamicArray {
275
+ _type : "DynamicArray" ;
276
+ _isFactory : true ;
277
+ maxLength : number ;
278
+ innerType : SerializedType ;
279
+ value ?: SerializedValue [ ] ;
280
+ }
281
+
282
+ interface DynamicRecord {
283
+ _type : "DynamicRecord" ;
284
+ _isFactory : true ;
285
+ maxEntries : number ;
286
+ knownShape : Record < string , SerializedType > ;
287
+ value ?: Record < string , SerializedValue > ;
288
+ }
289
+
290
+ interface DynamicBytes {
291
+ _type : "DynamicBytes" ;
292
+ _isFactory : true ;
293
+ maxLength : number ;
294
+ value ?: string ; // hex string
295
+ }
296
+
297
+ interface BasicType {
298
+ _type : string ;
299
+ }
300
+
301
+ // TODO: type?
302
+ interface ConstantType {
303
+ type : "Constant" ;
304
+ value : string ;
305
+ }
306
+
307
+ interface BytesType {
308
+ _type : "Bytes" ;
309
+ size : number ;
310
+ }
311
+
312
+ interface ProofTypeWrapper {
313
+ _type : "Proof" ;
314
+ proof : ProofType ;
315
+ }
316
+
317
+ interface ArrayType {
318
+ _type : "Array" ;
319
+ innerType : SerializedType ;
320
+ size : number ;
321
+ }
322
+
323
+ interface StructType {
324
+ _type : "Struct" ;
325
+ properties : { [ key : string ] : SerializedType } ;
326
+ }
327
+
328
+ export type SerializedType =
329
+ | BasicType
330
+ | ConstantType
331
+ | BytesType
332
+ | ProofTypeWrapper
333
+ | ArrayType
334
+ | StructType
335
+ | DynamicString
336
+ | DynamicArray
337
+ | DynamicRecord
338
+ | DynamicBytes
339
+ | { [ key : string ] : SerializedType } ;
340
+
272
341
// Private Credentials: Serialized Type and Value Schemas
273
342
274
343
const SerializedValueSchema = z
@@ -286,6 +355,38 @@ const SerializedDataValueSchema = z.union([
286
355
z . boolean ( ) ,
287
356
] ) ;
288
357
358
+ // Dynamic type schemas
359
+ const DynamicTypeBaseSchema = z . object ( {
360
+ _type : z . string ( ) ,
361
+ _isFactory : z . literal ( true ) ,
362
+ } ) ;
363
+
364
+ const DynamicStringSchema = DynamicTypeBaseSchema . extend ( {
365
+ _type : z . literal ( "DynamicString" ) ,
366
+ maxLength : z . number ( ) ,
367
+ value : z . string ( ) . optional ( ) ,
368
+ } ) . strict ( ) ;
369
+
370
+ const DynamicArraySchema = DynamicTypeBaseSchema . extend ( {
371
+ _type : z . literal ( "DynamicArray" ) ,
372
+ maxLength : z . number ( ) ,
373
+ innerType : z . lazy ( ( ) => SerializedTypeSchema ) ,
374
+ value : z . array ( SerializedValueSchema ) . optional ( ) ,
375
+ } ) . strict ( ) ;
376
+
377
+ const DynamicRecordSchema = DynamicTypeBaseSchema . extend ( {
378
+ _type : z . literal ( "DynamicRecord" ) ,
379
+ maxEntries : z . number ( ) ,
380
+ knownShape : z . record ( z . lazy ( ( ) => SerializedTypeSchema ) ) ,
381
+ value : z . record ( SerializedValueSchema ) . optional ( ) ,
382
+ } ) . strict ( ) ;
383
+
384
+ const DynamicBytesSchema = DynamicTypeBaseSchema . extend ( {
385
+ _type : z . literal ( "DynamicBytes" ) ,
386
+ maxLength : z . number ( ) ,
387
+ value : z . string ( ) . optional ( ) , // hex string
388
+ } ) . strict ( ) ;
389
+
289
390
const ProofTypeSchema : z . ZodType < ProofType > = z . lazy ( ( ) =>
290
391
z
291
392
. object ( {
@@ -335,12 +436,18 @@ const SerializedTypeSchema: z.ZodType<SerializedType> = z.lazy(() =>
335
436
size : z . number ( ) ,
336
437
} )
337
438
. strict ( ) ,
338
- z
339
- . object ( {
340
- _type : z . literal ( 'Struct' ) ,
341
- properties : z . record ( SerializedTypeSchema ) ,
342
- } )
343
- . strict ( ) ,
439
+ // Struct type
440
+ z
441
+ . object ( {
442
+ _type : z . literal ( "Struct" ) ,
443
+ properties : z . record ( SerializedTypeSchema ) ,
444
+ } )
445
+ . strict ( ) ,
446
+ // Dynamic types
447
+ DynamicStringSchema ,
448
+ DynamicArraySchema ,
449
+ DynamicRecordSchema ,
450
+ DynamicBytesSchema ,
344
451
// Allow records of nested types for Struct
345
452
z . record ( SerializedTypeSchema ) ,
346
453
] ) ,
0 commit comments