@@ -8,18 +8,26 @@ import { z } from 'zod';
88import { createPublicClient , http , type Address , type Hex } from 'viem' ;
99
1010// zod schemas for validation - compatible with original fastify implementation
11+ const boundedHex = ( bytes : number , description : string ) =>
12+ z . string ( )
13+ . regex ( / ^ (?: 0 x ) ? [ 0 - 9 a - f A - F ] * $ / , `${ description } must be hexadecimal` )
14+ . refine (
15+ ( value ) => value . replace ( / ^ 0 x / , '' ) . length <= bytes * 2 ,
16+ `${ description } exceeds ${ bytes } bytes` ,
17+ ) ;
18+
1119const BootInfoSchema = z . object ( {
12- // required fields (matching original fastify schema)
13- mrAggregated : z . string ( ) . describe ( 'aggregated MR measurement' ) ,
14- osImageHash : z . string ( ) . describe ( 'OS Image hash ') ,
15- appId : z . string ( ) . describe ( 'application ID ') ,
16- composeHash : z . string ( ) . describe ( 'compose hash ') ,
17- instanceId : z . string ( ) . describe ( 'instance ID ') ,
18- deviceId : z . string ( ) . describe ( 'device ID') ,
19- // optional fields (for full compatibility with BootInfo interface)
20- tcbStatus : z . string ( ) . optional ( ) . default ( '' ) ,
21- advisoryIds : z . array ( z . string ( ) ) . optional ( ) . default ( [ ] ) ,
22- mrSystem : z . string ( ) . optional ( ) . default ( '' )
20+ // Short hexadecimal values remain compatible with the original backend,
21+ // which left-pads them before making the contract call.
22+ mrAggregated : boundedHex ( 32 , 'aggregated MR measurement ') ,
23+ osImageHash : boundedHex ( 32 , 'OS Image hash ') ,
24+ appId : boundedHex ( 20 , 'application ID ') ,
25+ composeHash : boundedHex ( 32 , 'compose hash ') ,
26+ instanceId : boundedHex ( 20 , 'instance ID') ,
27+ deviceId : boundedHex ( 32 , 'device ID' ) ,
28+ tcbStatus : z . string ( ) . max ( 128 ) . optional ( ) . default ( '' ) ,
29+ advisoryIds : z . array ( z . string ( ) . max ( 256 ) ) . max ( 128 ) . optional ( ) . default ( [ ] ) ,
30+ mrSystem : boundedHex ( 32 , 'system MR measurement' ) . optional ( ) . default ( '' )
2331} ) ;
2432
2533const BootResponseSchema = z . object ( {
0 commit comments