@@ -15,17 +15,27 @@ import { z, type SuperRefinement } from 'zod';
15
15
16
16
import packageJson from '../../package.json' ;
17
17
18
+ export type Config = z . infer < typeof configSchema > ;
19
+ export type Address = z . infer < typeof config . evmAddressSchema > ;
20
+ export type BeaconId = z . infer < typeof config . evmIdSchema > ;
21
+ export type TemplateId = z . infer < typeof config . evmIdSchema > ;
22
+ export type EndpointId = z . infer < typeof config . evmIdSchema > ;
23
+
18
24
export const parameterSchema = z . strictObject ( {
19
25
name : z . string ( ) ,
20
26
type : z . string ( ) ,
21
27
value : z . string ( ) ,
22
28
} ) ;
23
29
30
+ export type Parameter = z . infer < typeof parameterSchema > ;
31
+
24
32
export const templateSchema = z . strictObject ( {
25
33
endpointId : config . evmIdSchema ,
26
34
parameters : z . array ( parameterSchema ) ,
27
35
} ) ;
28
36
37
+ export type Template = z . infer < typeof templateSchema > ;
38
+
29
39
export const templatesSchema = z . record ( config . evmIdSchema , templateSchema ) . superRefine ( ( templates , ctx ) => {
30
40
for ( const [ templateId , template ] of Object . entries ( templates ) ) {
31
41
// Verify that config.templates.<templateId> is valid by deriving the hash of the endpointId and parameters
@@ -53,11 +63,15 @@ export const templatesSchema = z.record(config.evmIdSchema, templateSchema).supe
53
63
}
54
64
} ) ;
55
65
66
+ export type Templates = z . infer < typeof templatesSchema > ;
67
+
56
68
export const endpointSchema = z . strictObject ( {
57
69
oisTitle : z . string ( ) ,
58
70
endpointName : z . string ( ) ,
59
71
} ) ;
60
72
73
+ export type Endpoint = z . infer < typeof endpointSchema > ;
74
+
61
75
export const endpointsSchema = z . record ( endpointSchema ) . superRefine ( ( endpoints , ctx ) => {
62
76
for ( const [ endpointId , endpoint ] of Object . entries ( endpoints ) ) {
63
77
// Verify that config.endpoints.<endpointId> is valid
@@ -77,6 +91,8 @@ export const endpointsSchema = z.record(endpointSchema).superRefine((endpoints,
77
91
}
78
92
} ) ;
79
93
94
+ export type Endpoints = z . infer < typeof endpointsSchema > ;
95
+
80
96
export const baseBeaconUpdateSchema = z . strictObject ( {
81
97
deviationThreshold : z . number ( ) ,
82
98
heartbeatInterval : z . number ( ) . int ( ) ,
@@ -88,17 +104,23 @@ export const beaconUpdateSchema = z
88
104
} )
89
105
. merge ( baseBeaconUpdateSchema ) ;
90
106
107
+ export type BeaconUpdate = z . infer < typeof beaconUpdateSchema > ;
108
+
91
109
export const signedApiUpdateSchema = z . strictObject ( {
92
110
signedApiName : z . string ( ) ,
93
111
templateIds : z . array ( config . evmIdSchema ) ,
94
112
fetchInterval : z . number ( ) ,
95
113
updateDelay : z . number ( ) ,
96
114
} ) ;
97
115
116
+ export type SignedApiUpdate = z . infer < typeof signedApiUpdateSchema > ;
117
+
98
118
export const triggersSchema = z . strictObject ( {
99
119
signedApiUpdates : z . array ( signedApiUpdateSchema ) . nonempty ( ) ,
100
120
} ) ;
101
121
122
+ export type Triggers = z . infer < typeof triggersSchema > ;
123
+
102
124
const validateTemplatesReferences : SuperRefinement < { templates : Templates ; endpoints : Endpoints } > = ( config , ctx ) => {
103
125
for ( const [ templateId , template ] of Object . entries ( config . templates ) ) {
104
126
const endpoint = config . endpoints [ template . endpointId ] ;
@@ -203,6 +225,8 @@ export const signedApiSchema = z.strictObject({
203
225
url : z . string ( ) . url ( ) ,
204
226
} ) ;
205
227
228
+ export type SignedApi = z . infer < typeof signedApiSchema > ;
229
+
206
230
export const signedApisSchema = z
207
231
. array ( signedApiSchema )
208
232
. nonempty ( )
@@ -219,10 +243,28 @@ export const signedApisSchema = z
219
243
}
220
244
} ) ;
221
245
246
+ const validateSignedApiReferences : SuperRefinement < {
247
+ triggers : Triggers ;
248
+ signedApis : SignedApi [ ] ;
249
+ } > = ( config , ctx ) => {
250
+ for ( const [ index , trigger ] of config . triggers . signedApiUpdates . entries ( ) ) {
251
+ const api = config . signedApis . find ( ( api ) => api . name === trigger . signedApiName ) ;
252
+ if ( ! api ) {
253
+ ctx . addIssue ( {
254
+ code : z . ZodIssueCode . custom ,
255
+ message : `Unable to find signed API with name: ${ trigger . signedApiName } ` ,
256
+ path : [ 'triggers' , 'signedApiUpdates' , index , 'signedApiName' ] ,
257
+ } ) ;
258
+ }
259
+ }
260
+ } ;
261
+
222
262
export const oisesSchema = z . array ( oisSchema ) ;
223
263
224
264
export const apisCredentialsSchema = z . array ( config . apiCredentialsSchema ) ;
225
265
266
+ export type ApisCredentials = z . infer < typeof apisCredentialsSchema > ;
267
+
226
268
export const nodeSettingsSchema = z . strictObject ( {
227
269
nodeVersion : z . string ( ) . refine ( ( version ) => version === packageJson . version , 'Invalid node version' ) ,
228
270
airnodeWalletMnemonic : z . string ( ) . refine ( ( mnemonic ) => ethers . utils . isValidMnemonic ( mnemonic ) , 'Invalid mnemonic' ) ,
@@ -248,41 +290,32 @@ export const configSchema = z
248
290
} )
249
291
. superRefine ( validateTemplatesReferences )
250
292
. superRefine ( validateOisReferences )
251
- . superRefine ( validateTriggerReferences ) ;
293
+ . superRefine ( validateTriggerReferences )
294
+ . superRefine ( validateSignedApiReferences ) ;
252
295
253
296
export const encodedValueSchema = z . string ( ) . regex ( / ^ 0 x [ \d A - F a - f ] { 64 } $ / ) ;
297
+
254
298
export const signatureSchema = z . string ( ) . regex ( / ^ 0 x [ \d A - F a - f ] { 130 } $ / ) ;
299
+
255
300
export const signedDataSchema = z . strictObject ( {
256
301
timestamp : z . string ( ) ,
257
302
encodedValue : encodedValueSchema ,
258
303
signature : signatureSchema ,
259
304
} ) ;
260
305
306
+ export type SignedData = z . infer < typeof signedDataSchema > ;
307
+
261
308
export const signedApiPayloadSchema = signedDataSchema . extend ( {
262
309
beaconId : config . evmIdSchema ,
263
310
airnode : config . evmAddressSchema ,
264
311
templateId : config . evmIdSchema ,
265
312
} ) ;
266
313
314
+ export type SignedApiPayload = z . infer < typeof signedApiPayloadSchema > ;
315
+
267
316
export const signedApiBatchPayloadSchema = z . array ( signedApiPayloadSchema ) ;
268
317
269
- export type SignedApiPayload = z . infer < typeof signedApiPayloadSchema > ;
270
318
export type SignedApiBatchPayload = z . infer < typeof signedApiBatchPayloadSchema > ;
271
- export type Config = z . infer < typeof configSchema > ;
272
- export type Template = z . infer < typeof templateSchema > ;
273
- export type Templates = z . infer < typeof templatesSchema > ;
274
- export type BeaconUpdate = z . infer < typeof beaconUpdateSchema > ;
275
- export type SignedApiUpdate = z . infer < typeof signedApiUpdateSchema > ;
276
- export type Triggers = z . infer < typeof triggersSchema > ;
277
- export type Address = z . infer < typeof config . evmAddressSchema > ;
278
- export type BeaconId = z . infer < typeof config . evmIdSchema > ;
279
- export type TemplateId = z . infer < typeof config . evmIdSchema > ;
280
- export type EndpointId = z . infer < typeof config . evmIdSchema > ;
281
- export type SignedData = z . infer < typeof signedDataSchema > ;
282
- export type Endpoint = z . infer < typeof endpointSchema > ;
283
- export type Endpoints = z . infer < typeof endpointsSchema > ;
284
- export type ApisCredentials = z . infer < typeof apisCredentialsSchema > ;
285
- export type Parameter = z . infer < typeof parameterSchema > ;
286
319
287
320
export const secretsSchema = z . record ( z . string ( ) ) ;
288
321
0 commit comments