From 8e363153151ae768ad71ce49fdadcf550444f9e7 Mon Sep 17 00:00:00 2001 From: Gregor Date: Mon, 20 Jun 2022 15:07:31 +0200 Subject: [PATCH] move helper stuff to the bottom --- src/lib/proof_system.ts | 84 ++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/lib/proof_system.ts b/src/lib/proof_system.ts index a93072f4c4..14bba74a3f 100644 --- a/src/lib/proof_system.ts +++ b/src/lib/proof_system.ts @@ -42,18 +42,6 @@ class Proof { } } -function getPublicInputType = typeof Proof>( - Proof: P -): AsFieldElements { - if (Proof.publicInputType === undefined) { - throw Error( - `You cannot use the \`Proof\` class directly. Instead, define a subclass:\n` + - `class MyProof extends Proof { ... }` - ); - } - return Proof.publicInputType; -} - type RawProof = unknown; type CompiledTag = unknown; @@ -67,36 +55,6 @@ let CompiledTag = { }, }; -type Tuple = [T, ...T[]] | []; - -// TODO: inference of AsFieldElements shouldn't just use InstanceType -// but the alternatives will be messier (see commented code below for some ideas) -type InferInstance = T extends new (...args: any) => any - ? InstanceType - : never; -type TupleToInstances = { - [I in keyof T]: InferInstance; -}; - -/* type TupleToInstances_ = - {[I in keyof T]: T[I] extends AsFieldElements ? InferAsFields : T[I] extends typeof Proof ? Proof : T[I]} -this is a workaround for TS bug https://github.com/microsoft/TypeScript/issues/29919 -type TupleToInstances< - A extends AnyTuple, - T extends (...args: A) => any -> = T extends (...args: infer P) => any ? TupleToInstances_

: never; -if the bug is resolved, this should just be TupleToInstances_

- -// TODO: this only works for Field / Bool / UInt32 / UInt64 / Int64 because they have a custom `check` method -// doesn't work for general CircuitValue -// we need a robust method for infering the type from a CircuitValue subclass! -type InferInstance> = T['check'] extends ( - x: infer U -) => void - ? U - : never; -*/ - function Program< PublicInputType extends AsFieldElements, Types extends { @@ -355,6 +313,48 @@ function emptyWitness(typ: AsFieldElements) { ); } +function getPublicInputType = typeof Proof>( + Proof: P +): AsFieldElements { + if (Proof.publicInputType === undefined) { + throw Error( + `You cannot use the \`Proof\` class directly. Instead, define a subclass:\n` + + `class MyProof extends Proof { ... }` + ); + } + return Proof.publicInputType; +} + +type Tuple = [T, ...T[]] | []; + +// TODO: inference of AsFieldElements shouldn't just use InstanceType +// but the alternatives will be messier (see commented code below for some ideas) +type InferInstance = T extends new (...args: any) => any + ? InstanceType + : never; +type TupleToInstances = { + [I in keyof T]: InferInstance; +}; + +/* type TupleToInstances_ = + {[I in keyof T]: T[I] extends AsFieldElements ? InferAsFields : T[I] extends typeof Proof ? Proof : T[I]} +this is a workaround for TS bug https://github.com/microsoft/TypeScript/issues/29919 +type TupleToInstances< + A extends AnyTuple, + T extends (...args: A) => any +> = T extends (...args: infer P) => any ? TupleToInstances_

: never; +if the bug is resolved, this should just be TupleToInstances_

+ +// TODO: this only works for Field / Bool / UInt32 / UInt64 / Int64 because they have a custom `check` method +// doesn't work for general CircuitValue +// we need a robust method for infering the type from a CircuitValue subclass! +type InferInstance> = T['check'] extends ( + x: infer U +) => void + ? U + : never; +*/ + type Subclass any> = (new ( ...args: any ) => InstanceType) & {