UNPKG

minauth-simple-preimage-plugin

Version:

A very simple Minauth plugin that allows users to authenticate by providing a preimage to a given hash.

51 lines (50 loc) 2.1 kB
import { Field, JsonProof } from 'o1js'; import { IMinAuthProver } from 'minauth/dist/plugin/plugintype.js'; import { TsInterfaceType } from 'minauth/dist/plugin/interfacekind.js'; import { Logger } from 'minauth/dist/plugin/logger.js'; import z from 'zod'; import { VerificationKey } from 'minauth/dist/common/verificationkey.js'; import { PluginRouter } from 'minauth/dist/plugin/pluginrouter.js'; declare const RolesSchema: z.ZodRecord<z.ZodString, z.ZodString>; type Roles = z.infer<typeof RolesSchema>; export type Configuration = { logger: Logger; pluginRoutes: PluginRouter; }; /** * Somewhat trivial example of a prover. * The server keeps a fixed set of hashes. * Each hash is associated with a role in the system. * You can prove that you have the role by providing the secret * preimage of the hash. * * NOTE. Although you can always generate valid zkproof, its output must * match the list kept by the server. */ export declare class SimplePreimageProver implements IMinAuthProver<TsInterfaceType, unknown, Field, Field> { /** This prover uses an idiomatic Typescript interface */ readonly __interface_tag: 'ts'; static readonly __interface_tag: 'ts'; /** The prover's logger */ protected readonly logger: Logger; /** The prover's plugin routes */ protected readonly pluginRoutes: PluginRouter; protected constructor(logger: Logger, pluginRoutes: PluginRouter); /** Build a proof. */ prove(publicInput: Field, secretInput: Field): Promise<JsonProof>; /** Fetches a list of hashes recognized by the server. */ fetchPublicInputs(): Promise<Field>; getRoles(): Promise<Roles>; /** Compile the underlying zk circuit */ static compile(): Promise<{ verificationKey: VerificationKey; }>; /** Initialize the prover */ static initialize(config: Configuration, { compile }?: { compile?: boolean | undefined; }): Promise<SimplePreimageProver>; } export declare class DemoSimplePreimageProver extends SimplePreimageProver { setRoles(roles: Roles): Promise<void>; } export {};