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

75 lines (74 loc) 3.16 kB
import { Field, JsonProof } from 'o1js'; import { IMinAuthPlugin, OutputValidity } from 'minauth/dist/plugin/plugintype.js'; import { MinaTreesProviderConfiguration, TreesProvider } from './treestorage.js'; import { Router } from 'express'; import { TaskEither } from 'fp-ts/lib/TaskEither.js'; import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray.js'; import { FpInterfaceType } from 'minauth/dist/plugin/interfacekind.js'; import { Decoder, EncodeDecoder } from 'minauth/dist/plugin/encodedecoder.js'; import { Logger } from 'minauth/dist/plugin/logger.js'; import { VerificationKey } from 'minauth/dist/common/verificationkey.js'; /** * The type of the public input of the Minauth plugin. * The public input is a list of Merkle tree roots. * Each tree represents a set of authorized members. */ export type Input = { merkleRoots: NonEmptyArray<Field>; proof: JsonProof; }; /** * The type of the output of the MerkleMemberships Minauth plugin. */ export type Output = { /** The input used to generate the proof related to this output. */ merkleRoots: NonEmptyArray<Field>; /** The hash informing the plugin to which trees the proof relates. */ recursiveHash: Field; }; /** * The MerkleMemberships Minauth plugin. * The plugin keeps a configured set of Merkle trees. * Each tree represents a set of authorized members. * A user can prove that they are a member of a set by providing * a Merkle witness to a known secret within a tree. * The user identity is not revealed - only the set of proven * memberships */ export declare class MerkleMembershipsPlugin implements IMinAuthPlugin<FpInterfaceType, Input, Output> { readonly __interface_tag = "fp"; readonly verificationKey: VerificationKey; private readonly storageProvider; readonly logger: Logger; /** * A set of express.js routes for communicating with the prover. */ readonly customRoutes: Router; /** Given public input description and a zk proof validate the proof * and produce the output */ verifyAndGetOutput(input: Input): TaskEither<string, Output>; /** * The output of the plugin may become invalid if the underlying * Merkle trees got updated. This function checks if the output * is still valid. */ checkOutputValidity(o: Output): TaskEither<string, OutputValidity>; constructor(verificationKey: VerificationKey, storageProvider: TreesProvider, logger: Logger); static readonly __interface_tag = "fp"; /** * Initialize plugin with a typed configuration. */ static initialize(cfg: MinaTreesProviderConfiguration, logger: Logger): TaskEither<string, MerkleMembershipsPlugin>; static readonly configurationDec: Decoder<"fp", { trees: { offchainStoragePath: string; contractPrivateKey?: string | undefined; initialLeaves?: Record<string, string> | undefined; }[]; feePayerPrivateKey?: string | undefined; }>; static readonly inputDecoder: Decoder<FpInterfaceType, Input>; static readonly outputEncDec: EncodeDecoder<"fp", Output>; } export default MerkleMembershipsPlugin;