@@ -6,6 +6,10 @@ import { readConfigurations, untypedPlugins } from './config';
66
77const configurations = readConfigurations ( ) ;
88
9+ /**
10+ * Construct plugins which are enabled in the configuration.
11+ * @returns A record of plugin instances.
12+ */
913async function initializePlugins ( ) :
1014 Promise < Record < string , IMinAuthPlugin < any , any > > > {
1115 console . log ( 'compiling plugins' ) ;
@@ -20,37 +24,41 @@ async function initializePlugins():
2024
2125initializePlugins ( )
2226 . then ( ( activePlugins ) => {
27+ // The type of `POST /verifyProof` requests' body.
2328 interface VerifyProofData {
2429 plugin : string ;
2530 publicInputArgs : any ;
2631 proof : JsonProof ;
2732 }
2833
34+ // Use the appropriate plugin to verify the proof and return the output.
2935 async function verifyProof ( data : VerifyProofData ) : Promise < any > {
3036 const pluginName = data . plugin ;
3137 console . info ( `verifying proof using plugin ${ pluginName } ` ) ;
3238 const pluginInstance = activePlugins [ pluginName ] ;
3339 if ( ! pluginInstance )
3440 throw `plugin ${ pluginName } not found` ;
41+ // Step 1: check that the proof was generated using a certain verification key.
3542 const proofValid = await verify ( data . proof , pluginInstance . verificationKey ) ;
3643 if ( ! proofValid )
3744 throw `invalid proof` ;
45+ // Step 2: use the plugin to extract the output. The plugin is also responsible
46+ // for checking the legitimacy of the public inputs.
3847 const typedPublicInputArgs
3948 = pluginInstance . publicInputArgsSchema . parse ( data . publicInputArgs ) ;
4049 const output =
4150 await pluginInstance . verifyAndGetOutput ( typedPublicInputArgs , data . proof ) ;
42- if ( ! output )
43- throw `plugin ${ pluginName } failed to verify the proof` ;
4451 return output ;
4552 }
4653
4754 const app = express ( ) . use ( bodyParser . json ( ) ) ;
4855
56+ // Register all custom routes of active plugins under `/plugins/${pluginName}`.
4957 Object . entries ( activePlugins ) . map ( ( [ name , plugin ] ) =>
5058 Object
5159 . entries ( plugin . customRoutes )
5260 . map ( ( [ path , handler ] ) =>
53- app . use ( `plugins/${ name } /${ path } ` , handler )
61+ app . use ( `/ plugins/${ name } /${ path } ` , handler )
5462 )
5563 ) ;
5664
0 commit comments