@@ -184,41 +184,40 @@ let SideloadedTag = {
184184 } ,
185185} ;
186186
187- function ZkProgram <
188- Config extends {
189- publicInput ?: ProvableType ;
190- publicOutput ?: ProvableType ;
191- methods : {
192- [ I in string ] : {
193- privateInputs : Tuple < PrivateInput > ;
194- auxiliaryOutput ?: ProvableType ;
195- } ;
187+ type ConfigBaseType = {
188+ publicInput ?: ProvableType ;
189+ publicOutput ?: ProvableType ;
190+ methods : {
191+ [ I in string ] : {
192+ privateInputs : Tuple < PrivateInput > ;
193+ auxiliaryOutput ?: ProvableType ;
196194 } ;
197- } ,
198- Methods extends {
199- [ I in keyof Config [ 'methods' ] ] : Method <
200- InferProvableOrUndefined < Get < Config , 'publicInput' > > ,
201- InferProvableOrVoid < Get < Config , 'publicOutput' > > ,
202- Config [ 'methods' ] [ I ]
203- > ;
204- } ,
205- // derived types for convenience
206- MethodSignatures extends Config [ 'methods' ] = Config [ 'methods' ] ,
207- PrivateInputs extends {
208- [ I in keyof Config [ 'methods' ] ] : Config [ 'methods' ] [ I ] [ 'privateInputs' ] ;
209- } = {
210- [ I in keyof Config [ 'methods' ] ] : Config [ 'methods' ] [ I ] [ 'privateInputs' ] ;
211- } ,
212- AuxiliaryOutputs extends {
213- [ I in keyof MethodSignatures ] : Get < MethodSignatures [ I ] , 'auxiliaryOutput' > ;
214- } = {
215- [ I in keyof MethodSignatures ] : Get < MethodSignatures [ I ] , 'auxiliaryOutput' > ;
216- }
217- > (
195+ } ;
196+ } ;
197+
198+ type InferMethodSignatures < Config extends ConfigBaseType > = Config [ 'methods' ] ;
199+ type InferPrivateInput < Config extends ConfigBaseType > = {
200+ [ I in keyof Config [ 'methods' ] ] : Config [ 'methods' ] [ I ] [ 'privateInputs' ] ;
201+ } ;
202+ type InferAuxilaryOutputs < Config extends ConfigBaseType > = {
203+ [ I in keyof InferMethodSignatures < Config > ] : Get <
204+ InferMethodSignatures < Config > [ I ] ,
205+ 'auxiliaryOutput'
206+ > ;
207+ } ;
208+ type InferMethodType < Config extends ConfigBaseType > = {
209+ [ I in keyof Config [ 'methods' ] ] : Method <
210+ InferProvableOrUndefined < Get < Config , 'publicInput' > > ,
211+ InferProvableOrVoid < Get < Config , 'publicOutput' > > ,
212+ Config [ 'methods' ] [ I ]
213+ > ;
214+ } ;
215+
216+ function ZkProgram < Config extends ConfigBaseType > (
218217 config : Config & {
219218 name : string ;
220219 methods : {
221- [ I in keyof Config [ 'methods' ] ] : Methods [ I ] ;
220+ [ I in keyof Config [ 'methods' ] ] : InferMethodType < Config > [ I ] ;
222221 } ;
223222 overrideWrapDomain ?: 0 | 1 | 2 ;
224223 }
@@ -248,10 +247,10 @@ function ZkProgram<
248247
249248 publicInputType : ProvableOrUndefined < Get < Config , 'publicInput' > > ;
250249 publicOutputType : ProvableOrVoid < Get < Config , 'publicOutput' > > ;
251- privateInputTypes : PrivateInputs ;
252- auxiliaryOutputTypes : AuxiliaryOutputs ;
250+ privateInputTypes : InferPrivateInput < Config > ;
251+ auxiliaryOutputTypes : InferAuxilaryOutputs < Config > ;
253252 rawMethods : {
254- [ I in keyof Config [ 'methods' ] ] : Methods [ I ] [ 'method' ] ;
253+ [ I in keyof Config [ 'methods' ] ] : InferMethodType < Config > [ I ] [ 'method' ] ;
255254 } ;
256255
257256 Proof : typeof Proof <
@@ -265,10 +264,26 @@ function ZkProgram<
265264 [ I in keyof Config [ 'methods' ] ] : Prover <
266265 InferProvableOrUndefined < Get < Config , 'publicInput' > > ,
267266 InferProvableOrVoid < Get < Config , 'publicOutput' > > ,
268- PrivateInputs [ I ] ,
269- InferProvableOrUndefined < AuxiliaryOutputs [ I ] >
267+ InferPrivateInput < Config > [ I ] ,
268+ InferProvableOrUndefined < InferAuxilaryOutputs < Config > [ I ] >
270269 > ;
271270} {
271+ type Methods = {
272+ [ I in keyof Config [ 'methods' ] ] : Method <
273+ InferProvableOrUndefined < Get < Config , 'publicInput' > > ,
274+ InferProvableOrVoid < Get < Config , 'publicOutput' > > ,
275+ Config [ 'methods' ] [ I ]
276+ > ;
277+ } ;
278+ // derived types for convenience
279+ type MethodSignatures = Config [ 'methods' ] ;
280+ type PrivateInputs = {
281+ [ I in keyof Config [ 'methods' ] ] : Config [ 'methods' ] [ I ] [ 'privateInputs' ] ;
282+ } ;
283+ type AuxiliaryOutputs = {
284+ [ I in keyof MethodSignatures ] : Get < MethodSignatures [ I ] , 'auxiliaryOutput' > ;
285+ } ;
286+
272287 let doProving = true ;
273288
274289 let methods = config . methods ;
@@ -582,15 +597,8 @@ type ZkProgram<
582597 auxiliaryOutput ?: ProvableType ;
583598 } ;
584599 } ;
585- } ,
586- Methods extends {
587- [ I in keyof Config [ 'methods' ] ] : Method <
588- InferProvableOrUndefined < Get < Config , 'publicInput' > > ,
589- InferProvableOrVoid < Get < Config , 'publicOutput' > > ,
590- Config [ 'methods' ] [ I ]
591- > ;
592600 }
593- > = ReturnType < typeof ZkProgram < Config , Methods > > ;
601+ > = ReturnType < typeof ZkProgram < Config > > ;
594602
595603class SelfProof < PublicInput , PublicOutput > extends Proof <
596604 PublicInput ,
0 commit comments