@@ -17,6 +17,7 @@ export const logSchema = z.object({
17
17
18
18
export const evmAddressSchema = z . string ( ) . regex ( / ^ 0 x [ a - f A - F 0 - 9 ] { 40 } $ / ) ;
19
19
export const evmBeaconIdSchema = z . string ( ) . regex ( / ^ 0 x [ a - f A - F 0 - 9 ] { 64 } $ / ) ;
20
+ export const evmBeaconSetIdSchema = z . string ( ) . regex ( / ^ 0 x [ a - f A - F 0 - 9 ] { 64 } $ / ) ;
20
21
export const evmTemplateIdSchema = z . string ( ) . regex ( / ^ 0 x [ a - f A - F 0 - 9 ] { 64 } $ / ) ;
21
22
export const evmEndpointIdSchema = z . string ( ) . regex ( / ^ 0 x [ a - f A - F 0 - 9 ] { 64 } $ / ) ;
22
23
export const emptyObjectSchema = z . object ( { } ) . strict ( ) ;
@@ -44,8 +45,22 @@ export const beaconsSchema = z.record(evmBeaconIdSchema, beaconSchema).superRefi
44
45
} ) ;
45
46
} ) ;
46
47
47
- // TODO: Will be refined once we start supporting beacon sets
48
- export const beaconSetsSchema = emptyObjectSchema ;
48
+ export const beaconSetsSchema = z
49
+ . record ( evmBeaconSetIdSchema , z . array ( evmBeaconIdSchema ) )
50
+ . superRefine ( ( beaconSets , ctx ) => {
51
+ Object . entries ( beaconSets ) . forEach ( ( [ beaconSetId , beacons ] ) => {
52
+ // Verify that config.beaconSets.<beaconSetId> is valid
53
+ // by deriving the hash of the beaconIds in the array
54
+ const derivedBeaconSetId = ethers . utils . keccak256 ( ethers . utils . defaultAbiCoder . encode ( [ 'bytes32[]' ] , [ beacons ] ) ) ;
55
+ if ( derivedBeaconSetId !== beaconSetId ) {
56
+ ctx . addIssue ( {
57
+ code : z . ZodIssueCode . custom ,
58
+ message : `Beacon set ID "${ beaconSetId } " is invalid` ,
59
+ path : [ beaconSetId ] ,
60
+ } ) ;
61
+ }
62
+ } ) ;
63
+ } ) ;
49
64
50
65
export const latestGasPriceOptionsSchema = z
51
66
. object ( {
@@ -168,6 +183,23 @@ const validateBeaconsReferences: SuperRefinement<{ beacons: Beacons; gateways: G
168
183
} ) ;
169
184
} ;
170
185
186
+ const validateBeaconSetsReferences : SuperRefinement < { beacons : Beacons ; beaconSets : BeaconSets } > = ( config , ctx ) => {
187
+ Object . entries ( config . beaconSets ) . forEach ( ( [ beaconSetId , beacons ] ) => {
188
+ beacons . forEach ( ( beaconId , index ) => {
189
+ // Verify that config.beaconSets.<beaconSetId>.[beaconId] is
190
+ // referencing a valid config.beacons.<beaconId> object
191
+ const beacon = config . beacons [ beaconId ] ;
192
+ if ( isNil ( beacon ) ) {
193
+ ctx . addIssue ( {
194
+ code : z . ZodIssueCode . custom ,
195
+ message : `Beacon ID "${ beaconId } " is not defined in the config.beacons object` ,
196
+ path : [ 'beaconSets' , beaconSetId , index ] ,
197
+ } ) ;
198
+ }
199
+ } ) ;
200
+ } ) ;
201
+ } ;
202
+
171
203
const validateBeaconUpdatesReferences : SuperRefinement < {
172
204
beacons : Beacons ;
173
205
chains : Chains ;
@@ -212,6 +244,7 @@ export const configSchema = z
212
244
} )
213
245
. strict ( )
214
246
. superRefine ( validateBeaconsReferences )
247
+ . superRefine ( validateBeaconSetsReferences )
215
248
. superRefine ( validateBeaconUpdatesReferences ) ;
216
249
export const encodedValueSchema = z . string ( ) . regex ( / ^ 0 x [ a - f A - F 0 - 9 ] { 64 } $ / ) ;
217
250
export const signatureSchema = z . string ( ) . regex ( / ^ 0 x [ a - f A - F 0 - 9 ] { 130 } $ / ) ;
@@ -223,6 +256,7 @@ export const signedDataSchema = z.object({
223
256
export type Config = z . infer < typeof configSchema > ;
224
257
export type Beacon = z . infer < typeof beaconSchema > ;
225
258
export type Beacons = z . infer < typeof beaconsSchema > ;
259
+ export type BeaconSets = z . infer < typeof beaconSetsSchema > ;
226
260
export type Chain = z . infer < typeof chainSchema > ;
227
261
export type Chains = z . infer < typeof chainsSchema > ;
228
262
export type GasOracleConfig = z . infer < typeof gasOracleSchema > ;
0 commit comments