UNPKG

minauth

Version:

A TypeScript library for building authentication systems on top of the Mina blockchain and other zero-knowledge proofs solutions.

108 lines (107 loc) 4.61 kB
/// <reference types="passport" /> import * as expressCore from 'express-serve-static-core'; import * as TE from 'fp-ts/lib/TaskEither.js'; import { TaskEither } from 'fp-ts/lib/TaskEither.js'; import { z } from 'zod'; import { FpInterfaceType, TsInterfaceType } from '../plugin/interfacekind.js'; import { Logger } from '../plugin/logger.js'; import { IMinAuthPlugin, IMinAuthPluginFactory, OutputValidity } from '../plugin/plugintype.js'; import { PluginRuntime, PluginRuntimeEnv } from './pluginruntime.js'; /** * Configuration schema for the plugin loader */ export declare const configurationSchema: z.ZodObject<{ /** Directory where to look for plugins */ pluginDir: z.ZodOptional<z.ZodString>; /** Plugins to load along with their configuration */ plugins: z.ZodRecord<z.ZodString, z.ZodObject<{ /** Path to the plugin module */ path: z.ZodOptional<z.ZodString>; /** Configuration for the plugin */ config: z.ZodUnknown; }, "strip", z.ZodTypeAny, { path?: string | undefined; config?: unknown; }, { path?: string | undefined; config?: unknown; }>>; }, "strip", z.ZodTypeAny, { plugins: Record<string, { path?: string | undefined; config?: unknown; }>; pluginDir?: string | undefined; }, { plugins: Record<string, { path?: string | undefined; config?: unknown; }>; pluginDir?: string | undefined; }>; /** * Type of the plugins configuration. */ export type Configuration = z.infer<typeof configurationSchema>; /** * Read the configuration from a file with custom parser */ export declare const _readConfiguration: (logger: Logger) => <T>(parseConfiguration: (s: string) => z.SafeParseReturnType<T, T>) => (cfgPath?: string) => TE.TaskEither<string, T>; /** Read the configuration from a file * The file path can be passed from $MINAUTH_CONFIG env var and * defaults to `config.yaml` in the current working directory */ export declare const readConfiguration: (logger: Logger) => (cfgPath?: string) => TE.TaskEither<string, { plugins: Record<string, { path?: string | undefined; config?: unknown; }>; pluginDir?: string | undefined; }>; /** * The type of a plugin factory used by the library to dynamically load plugins. * This factory will create plugins with interfaces in the functional style. */ export type UntypedFpPluginFactory = IMinAuthPluginFactory<FpInterfaceType, IMinAuthPlugin<FpInterfaceType, unknown, unknown>, unknown>; /** * The type of a plugin factory used by the library to dynamically load plugins. * This factory will create plugins with idiomatic typescript interface style. */ export type UntypedTsPluginFactory = IMinAuthPluginFactory<TsInterfaceType, IMinAuthPlugin<TsInterfaceType, unknown, unknown>, unknown>; /** * The type of a plugin factory used by the library to dynamically load plugins. * A module that defines a plugin has to export a value of this type. * This means that the plugin author may pick either functional or idiomatic typescript interface. */ export type UntypedPluginFactory = UntypedFpPluginFactory | UntypedTsPluginFactory; /** * The type of a plugin module used by the library to dynamically load plugins. * The module can define a plugin with either functional or idiomatic typescript interface. */ export type UntypedPluginModule = { default: UntypedPluginFactory; }; /** * Given a logger and plugin configuration, initialize the plugins. * Provided plugins will be transformed to the functional style interface, * to used as such by the library. * Initializes `PluginRuntimeEnv` */ export declare const initializePlugins: (rootLogger: Logger) => (cfg: Configuration) => TaskEither<string, PluginRuntimeEnv>; /** * Install custom routes for all the active plugins. * The routes are installed under `/plugins/${pluginName}`. * and come from `pluginInstance.customRoutes`. * The routes are meant for plugin / prover communication. */ export declare const installCustomRoutes: (app: expressCore.Express) => PluginRuntime<void>; /** * Verify proof with given plugin and return its output. */ export declare const verifyProof: (input: unknown, pluginName: string) => PluginRuntime<unknown>; /** Validate the output of a plugin within the active plugin runtime. * @param pluginName The name of on of active plugins to use for validation. * @param output The encoded plugin output. * @returns The validation result. */ export declare const validateOutput: (pluginName: string, output: unknown) => PluginRuntime<OutputValidity>;