Skip to content

Commit f92c49a

Browse files
committed
docs
1 parent 3c6625f commit f92c49a

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/library/plugin/pluginType.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,26 @@ import z from 'zod';
55
// Interfaces used on the server side.
66

77
export interface IMinAuthPlugin<PublicInputsArgs, Output> {
8+
// Verify a proof give the arguments for fetching public inputs, and return
9+
// the output.
810
verifyAndGetOutput(
911
publicInputArgs: PublicInputsArgs,
1012
serializedProof: JsonProof): Promise<Output>;
1113

14+
// The schema of the arguments for fetching public inputs.
1215
readonly publicInputArgsSchema: z.ZodType<PublicInputsArgs>;
1316

17+
// TODO: enable plugins to invalidate a proof.
1418
// FIXME(Connor): I still have some questions regarding the validation functionality.
1519
// In particular, what if a plugin want to invalidate the proof once the public inputs change?
1620
// We have to at least pass PublicInputsArgs.
1721
//
1822
// checkOutputValidity(output: Output): Promise<boolean>;
1923

24+
// Custom routes and handlers. Will be installed under `/plugins/<plugin name>`
2025
readonly customRoutes: Record<string, RequestHandler>;
2126

27+
// The verification key of the underlying zk circuit.
2228
readonly verificationKey: string;
2329
}
2430

@@ -27,6 +33,8 @@ export interface IMinAuthPluginFactory<
2733
T extends IMinAuthPlugin<PublicInputsArgs, Output>,
2834
Configuration, PublicInputsArgs, Output> {
2935

36+
// Initialize the plugin given the configuration. The underlying zk program is
37+
// typically compiled here.
3038
initialize(cfg: Configuration): Promise<T>;
3139

3240
readonly configurationSchema: z.ZodType<Configuration>;

src/library/tools/pluginServer/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { SimplePreimagePlugin } from "plugins/simplePreimage/plugin";
77
import { SimplePasswordTreePlugin } from "plugins/passwordTree/plugin";
88

99
// TODO: make use of heterogeneous lists
10+
/**
11+
* All the available plugins and their names go here.
12+
*/
1013
export const untypedPlugins:
1114
Record<string,
1215
IMinAuthPluginFactory<IMinAuthPlugin<any, any>, any, any, any>>
@@ -31,6 +34,13 @@ const serverConfigurationsSchema = z.object({
3134

3235
export type ServerConfigurations = z.infer<typeof serverConfigurationsSchema>;
3336

37+
/**
38+
* Load configurations from disk. The configuration is encoded in yaml and
39+
* should conform to `serverConfigurationsSchema`. The location of the file can
40+
* be specified using the `MINAUTH_CONFIG` environmental variable; if it's not
41+
* set, `./config.yaml` will be used.
42+
* @returns The decoded configurations for the server and plugins.
43+
*/
3444
export function readConfigurations(): ServerConfigurations {
3545
const configFile =
3646
env.get('MINAUTH_CONFIG')

src/library/tools/pluginServer/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { readConfigurations, untypedPlugins } from './config';
66

77
const configurations = readConfigurations();
88

9+
/**
10+
* Construct plugins which are enabled in the configuration.
11+
* @returns A record of plugin instances.
12+
*/
913
async function initializePlugins():
1014
Promise<Record<string, IMinAuthPlugin<any, any>>> {
1115
console.log('compiling plugins');
@@ -20,37 +24,41 @@ async function initializePlugins():
2024

2125
initializePlugins()
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

Comments
 (0)