UNPKG

minauth-erc721-timelock-plugin

Version:

This package contains an implementation of a MinAuth plugin that combines zero-knowledge Merkle "membership" proofs with the ability to register into to a Merkle tree with locking an Ethereum NFT.

131 lines (130 loc) 5.14 kB
import { JsonProof } from 'o1js'; import { IMinAuthPlugin, OutputValidity } from 'minauth/dist/plugin/plugintype.js'; import { z } from 'zod'; import { TsInterfaceType } from 'minauth/dist/plugin/interfacekind.js'; import { Logger } from 'minauth/dist/plugin/logger.js'; import { VerificationKey } from 'minauth/dist/common/verificationkey.js'; import { IErc721TimeLock } from './erc721timelock.js'; /** * The plugin configuration schema. * `timeLockContractAddress` - an address to the ethereum contract handling * time-locking NFTs and hashes. * `erc721ContractAddress` - an address to the ethereum contract for NFTs * that configured to be used with this plugin (in future might be extended to * support multiple such addresses) * `ethereumJsonRpcProvider` - a json rpc provider for the ethereum network */ export declare const ConfigurationSchema: z.ZodObject<{ timeLockContractAddress: z.ZodString; erc721ContractAddress: z.ZodString; ethereumJsonRpcProvider: z.ZodString; }, "strip", z.ZodTypeAny, { timeLockContractAddress: string; erc721ContractAddress: string; ethereumJsonRpcProvider: string; }, { timeLockContractAddress: string; erc721ContractAddress: string; ethereumJsonRpcProvider: string; }>; export type Configuration = z.infer<typeof ConfigurationSchema>; /** * For simplicity sake we don't use additional public inputs arguments. * One could for example pick a contract here (from predefined set). */ export type Input = { proof: JsonProof; }; /** * The plugin's output schema. */ export declare const OutputSchema: z.ZodObject<{ merkleRoot: z.ZodString; contractConfigurationHash: z.ZodString; }, "strip", z.ZodTypeAny, { merkleRoot: string; contractConfigurationHash: string; }, { merkleRoot: string; contractConfigurationHash: string; }>; /** * The output of the plugin is the merkle root for which the proof * is accepted and the hash of the configuration used to verify the proof. */ export type Output = z.infer<typeof OutputSchema>; /** * The Ethereum contract implements an NFT timelock scheme. * One can lock an NFT for a given period of time along with a hash. * All the hashes behind the locked NFTs are stored in a merkle tree. * The plugin allows one to prove that they have the preimage of the hash * and thus have the right to get the authorization. * When use against suffiently large merkle tree provides a level * of privacy - the proof does not reveal which hash nor the merkle witness * for the hash. * Some care must be taken to avoid timing attacks. */ export declare class Erc721TimelockPlugin implements IMinAuthPlugin<TsInterfaceType, Input, Output> { readonly ethContract: IErc721TimeLock; readonly verificationKey: VerificationKey; readonly configuration: Configuration; private readonly logger; /** * This plugin uses an idiomatic Typescript interface */ readonly __interface_tag = "ts"; /** * A utility function that hashes (SHA256) the current configuration. */ readonly configurationHash: () => string; /** * Verify a proof and return the role. */ verifyAndGetOutput(input: Input): Promise<Output>; /** * Trivial - no public inputs. */ publicInputArgsSchema: z.ZodType<unknown>; /** * The plugin exposes eth contract addresses via http endpoints. * The prover should directly interact with the contract to build the proof. */ readonly customRoutes: import("express-serve-static-core").Router; /** * Check if produced output is still valid. * It DOES NOT verify the proof. * It assumes that the output was produced by the plugin. * So use it only to check if produced output is still valid. * Not to re-verifiy the proof. * In case of this plugin it means that the merkle tree has not changed. */ checkOutputValidity(output: Output): Promise<OutputValidity>; /** * This ctor is meant to be called by the `initialize` function. */ constructor(ethContract: IErc721TimeLock, verificationKey: VerificationKey, configuration: Configuration, logger: Logger); static readonly __interface_tag = "ts"; /** * Initialize the plugin with a configuration. */ static initialize(configuration: Configuration, logger: Logger): Promise<Erc721TimelockPlugin>; static readonly configurationDec: import("minauth/dist/plugin/encodedecoder.js").Decoder<"ts", { timeLockContractAddress: string; erc721ContractAddress: string; ethereumJsonRpcProvider: string; }>; static readonly inputDecoder: import("minauth/dist/plugin/encodedecoder.js").Decoder<"ts", { proof: { publicInput: string[]; publicOutput: string[]; maxProofsVerified: 0 | 2 | 1; proof: string; }; }>; /** output parsing and serialization */ static readonly outputEncDec: import("minauth/dist/plugin/encodedecoder.js").EncodeDecoder<"ts", { merkleRoot: string; contractConfigurationHash: string; }>; } export default Erc721TimelockPlugin;