1+ import { json } from "body-parser" ;
2+ import { PublicKeyInput } from "crypto" ;
3+ import { RequestHandler } from "express" ;
14import { JsonProof } from "o1js" ;
5+ import { initialize } from "passport" ;
26
37export type PluginType = {
48 compile : ( ) => Promise < string > ;
59 getInputs : ( ) => Promise < string [ ] > ;
610 verify : (
7- jsonProof : JsonProof ,
8- verificationKey : string ,
11+ jsonProof : JsonProof ,
12+ verificationKey : string ,
913 ) => Promise < [ string | boolean | undefined , string ] > ;
1014 prove : ( inputs : string [ ] ) => Promise < undefined | JsonProof > ;
11- } ;
15+ } ;
16+
17+ export interface IMinAuthPlugin < PublicInputsArgs , Output > {
18+ verifyAndGetOutput (
19+ publicInputArgs : PublicInputsArgs ,
20+ serializedProof : JsonProof ) : Promise < undefined | Output > ;
21+
22+ readonly customRoutes : Map < string , RequestHandler > ;
23+
24+ readonly verificationKey : string ;
25+ }
26+
27+ export interface IMinAuthPluginFactory <
28+ T extends IMinAuthPlugin < PublicInputsArgs , Output > ,
29+ Configuration , PublicInputsArgs , Output > {
30+ initialize ( cfg : Configuration ) : Promise < T > ;
31+ }
32+
33+ export abstract class MinAuthPlugin < Configuration , PublicInputsArgs , Output > {
34+ abstract initialize ( configuration : Configuration ) : Promise < string /*The verification key*/ > ;
35+
36+ abstract verifyAndGetOutput (
37+ publicInputArgs : PublicInputsArgs ,
38+ serializedProof : JsonProof ) : Promise < undefined | Output > ;
39+
40+ abstract readonly customRoutes : Map < string , RequestHandler > ;
41+ }
42+
43+ export abstract class MinAuthProver < Configuration , PublicInputsArgs , PublicInput , PrivateInput > {
44+ abstract initialize ( configuration : Configuration ) : Promise < void > ;
45+
46+ abstract prove ( publicInput : PublicInput , secretInput : PrivateInput ) :
47+ Promise < undefined | JsonProof > ;
48+
49+ abstract fetchPublicInputs ( args : PublicInputsArgs ) : Promise < PublicInput > ;
50+ }
51+
52+
53+ export function mkUntypedPlugin <
54+ T extends IMinAuthPlugin < PublicInputsArgs , Output > ,
55+ Configuration , PublicInputsArgs , Output > (
56+ type : IMinAuthPluginFactory < T , Configuration , PublicInputsArgs , Output > ,
57+ ) : // Oh please let me use haskell
58+ ( ( _ : any ) => Promise < IMinAuthPlugin < any , any > > ) {
59+ return async ( cfg : any ) : Promise < IMinAuthPlugin < any , any > > => {
60+ const obj = await type . initialize ( cfg as Configuration ) ;
61+
62+ return {
63+ verifyAndGetOutput : async (
64+ publicInputArgs : string ,
65+ serializedProof : JsonProof ) : Promise < undefined | any > =>
66+ await obj . verifyAndGetOutput ( publicInputArgs as PublicInputsArgs , serializedProof ) ,
67+ customRoutes : obj . customRoutes ,
68+ verificationKey : obj . verificationKey
69+ } ;
70+ } ;
71+ }
0 commit comments