minauth
Version:
A TypeScript library for building authentication systems on top of the Mina blockchain and other zero-knowledge proofs solutions.
59 lines (58 loc) • 2.29 kB
TypeScript
import { ReaderTaskEither } from 'fp-ts/lib/ReaderTaskEither.js';
import { Decoder, EncodeDecoder } from '../plugin/encodedecoder.js';
import { FpInterfaceType } from '../plugin/interfacekind.js';
import { IMinAuthPlugin } from '../plugin/plugintype.js';
import { Logger } from '../plugin/logger.js';
/** Runtime environment of runnning plugins. */
export type PluginRuntimeEnv = Readonly<{
logger: Logger;
plugins: ActivePlugins;
}>;
/** The runtime instance of a plugin.
Basically an extended functional style plugin interface.
*/
export type RuntimePluginInstance = IMinAuthPlugin<FpInterfaceType, unknown, unknown> & {
inputDecoder: Decoder<FpInterfaceType, unknown>;
outputEncDec: EncodeDecoder<FpInterfaceType, unknown>;
};
/** Mapping between plugin names and their runtime instances. */
export type ActivePlugins = Readonly<Record<string, RuntimePluginInstance>>;
/**
* The plugin runtime monad. Actions are TaskEither's (fallible async calls)
* that can read the PluginRuntimeEnv.
* Errors are strings.
*/
export type PluginRuntime<Ret> = ReaderTaskEither<PluginRuntimeEnv, string, Ret>;
/**
* Use the plugin runtime logger.
*/
export declare const useLogger: (f: (l: Logger) => void) => PluginRuntime<void>;
/**
* Get the plugin runtime logger instance.
*/
export declare const askLogger: () => PluginRuntime<Logger>;
/**
* Get all active plugin instances.
*/
export declare const askActivePlugins: () => PluginRuntime<Readonly<Record<string, RuntimePluginInstance>>>;
/**
* Get a running plugin instance by its name.
*/
export declare const askPluginInstance: (pluginName: string) => PluginRuntime<RuntimePluginInstance>;
export declare const askActivePluginNames: () => PluginRuntime<string[]>;
/**
* Get the plugin runtime environment.
*/
export declare const askPluginRuntimeEnv: () => PluginRuntime<Readonly<{
logger: Logger;
plugins: ActivePlugins;
}>>;
/**
* Launch a plugin runtime action as a TS promise.
*/
export declare const launchPluginRuntime: (env: PluginRuntimeEnv) => <Ret>(a: PluginRuntime<Ret>) => Promise<Ret>;
/**
* Tap into the error of a plugin runtime action and log it with
* an additional note.
*/
export declare const tapAndLogError: <RET>(note: string) => (_: PluginRuntime<RET>) => PluginRuntime<RET>;