UNPKG

@zkpersona/noir-social-verify

Version:

A library that provides a simple way to verify ownership of social accounts by proving e-mails.

117 lines (112 loc) 4.34 kB
import { CompiledCircuit, Noir, InputMap } from '@noir-lang/noir_js'; import { InputGenerationArgs } from '@zk-email/zkemail-nr'; import { BackendOptions, UltraPlonkBackend, UltraHonkBackend, ProofData } from '@aztec/bb.js'; type u8 = string; type u32 = string; type Field = string; type BoundedVec = { storage: u8[]; len: u32; }; type RSAPubkey = { modulus: Field[]; redc: Field[]; }; type Sequence = { index: u32; length: u32; }; type VerifiedOutputs = { pub_key_hash: Field; email_nullifier: Field; to_address: BoundedVec; }; type VerifyGoogleEmailInputs = { header: BoundedVec; pubkey: RSAPubkey; signature: Field[]; from_header_sequence: Sequence; from_address_sequence: Sequence; to_header_sequence: Sequence; to_address_sequence: Sequence; }; type VerifyGoogleEmailOutput = VerifiedOutputs; type VerifyXEmailInputs = { header: BoundedVec; pubkey: RSAPubkey; signature: Field[]; from_header_sequence: Sequence; from_address_sequence: Sequence; to_header_sequence: Sequence; to_address_sequence: Sequence; }; type VerifyXEmailOutput = VerifiedOutputs; type CircuitInputMap = { google: VerifyGoogleEmailInputs; x: VerifyXEmailInputs; }; type CircuitOutputMap = { google: VerifyGoogleEmailOutput; x: VerifyXEmailOutput; }; type CircuitType = 'google' | 'x'; declare const circuitParams: Record<CircuitType, InputGenerationArgs>; declare const createProver: (circuit: CompiledCircuit, backend: ProvingBackend) => ZKEmailProver; declare const generateCircuitInputs: <T extends CircuitType>(emailContent: Buffer | string, circuitType: T) => Promise<CircuitInputMap[T]>; type InputValue = InputMap[string]; type CircuitOptions = { /** @description Whether to produce SNARK friendly proofs */ recursive: boolean; }; type ProvingBackend = { type: 'honk' | 'plonk' | 'all'; options?: BackendOptions; circuitOptions?: CircuitOptions; }; declare class ZKEmailProver { plonk?: UltraPlonkBackend; honk?: UltraHonkBackend; noir: Noir; provingBackend: ProvingBackend; constructor(circuit: CompiledCircuit, provingBackend: ProvingBackend); /** * Compute the witness for a given input to the circuit without generating a proof * * @param input - the input that should produce a satisfying witness for the circuit * @returns - the witness for the input and the output of the circuit if satisfiable */ simulateWitness(input: InputMap): Promise<{ witness: Uint8Array; returnValue: InputValue; }>; /** * Generate a proof of a satisfying input to the circuit using a provided witness * * @param input - a satisfying witness for the circuit * @param provingBackend - optionally provided if the class was initialized with both proving schemes * @returns proof of valid execution of the circuit */ prove(witness: Uint8Array, provingBackend?: ProvingBackend): Promise<ProofData>; /** * Simulate the witness for a given input and generate a proof * * @param input - the input that should produce a satisfying witness for the circuit * @param provingBackend - optionally provided if the class was initialized with both proving schemes * @returns proof of valid execution of the circuit */ fullProve(input: InputMap, provingBackend?: ProvingBackend): Promise<ProofData>; /** * Verify a proof of a satisfying input to the circuit for a given proving scheme * * @param proof - the proof to verify * @param provingBackend - optionally provided if the class was initialized with both proving schemes * @returns true if the proof is valid, false otherwise */ verify(proof: ProofData, provingBackend?: ProvingBackend): Promise<boolean>; /** * End the prover wasm instance(s) and clean up resources */ destroy(): Promise<void>; private getProvingBackend; } export { type BoundedVec, type CircuitInputMap, type CircuitOutputMap, type CircuitType, type Field, type ProvingBackend, type RSAPubkey, type Sequence, type VerifiedOutputs, type VerifyGoogleEmailInputs, type VerifyGoogleEmailOutput, type VerifyXEmailInputs, type VerifyXEmailOutput, ZKEmailProver, circuitParams, createProver, generateCircuitInputs, type u32, type u8 };