UNPKG

minauth-merkle-membership-plugin

Version:

This package contains an implementation of a simple MinAuth plugin that extends the concept of password authentication into authenticating within sets that provide a level of anonymity. The proofs are built and verified with MINA's `o1js` library & proof

54 lines (53 loc) 2.51 kB
import { Field, JsonProof } from 'o1js'; import * as ZkProgram from './merklemembershipsprogram.js'; import { IMinAuthProver } from 'minauth/dist/plugin/plugintype.js'; import { TaskEither } from 'fp-ts/lib/TaskEither.js'; import { FpInterfaceType } from 'minauth/dist/plugin/interfacekind.js'; import { VerificationKey } from 'minauth/dist/common/verificationkey.js'; /** * Configuration for the prover. */ export type MembershipsProverConfiguration = { baseUrl: string; }; export type MembershipsPublicInputArgs = Array<{ /** The root of the merkle tree that the prover is trying to prove membership * in. */ treeRoot: Field; /** Note that the leaf index is not part of the proof public input, * but it is required to build one. */ leafIndex: bigint; }>; /** * With this class you can build proofs and interact with `MerkleMembershipsPlugin`. * The zk-circuit will check knowledge of a secret and its witness in merkle trees. * Proving this knowledge can be understood as proving membership in a set of users. * Because of recursion one can prove membership in multiple sets in one proof. */ export declare class MembershipsProver implements IMinAuthProver<FpInterfaceType, MembershipsPublicInputArgs, Array<[ZkProgram.PublicInput, ZkProgram.TreeWitness]>, Array<Field>> { /** This class uses the functionl style interface of the plugin. */ readonly __interface_tag = "fp"; private readonly cfg; /** * Build a proof for given inputs. * Note that even though TreeWitness is passed as public input, it should not be known to the verifier. * TODO fix the above */ prove(publicInput: Array<[ZkProgram.PublicInput, ZkProgram.TreeWitness]>, secretInput: Array<Field>): TaskEither<string, JsonProof>; /** * Fetch the data necessary to build the proof inputs. * In this case these are Merkle trees related to the roots * passed as arguments. */ fetchPublicInputs(args: MembershipsPublicInputArgs): TaskEither<string, Array<[ZkProgram.PublicInput, ZkProgram.TreeWitness]>>; constructor(cfg: MembershipsProverConfiguration); static readonly __interface_tag = "fp"; /** Compile the underlying zk circuit */ static compile(): TaskEither<string, { verificationKey: VerificationKey; }>; static initialize(cfg: MembershipsProverConfiguration, { compile }?: { compile?: boolean | undefined; }): TaskEither<string, MembershipsProver>; } export default MembershipsProver;