import { Unirep } from'@unirep/contracts/Unirep.sol';contract YourContract { Unirep public unirep;uint256internal _attesterId;// Initialize contract with a deployedconstructor(Unirep_unirepContract) {// Set the unirep contract address unirep = _unirepContract; }// Relay Users sign up in UnirepfunctionsignUp(uint256 idCommitment) external { unirep.userSignUp(idCommitment); }// Sign up this contract as an attesterfunctionsignUpContract() external { unirep.attesterSignUp(); _attesterId = unirep.attesters(address(this)); }// Users submit their epoch key proof to Unirep contract// And get attestation from the contractfunctionsubmitEpochKeyProof(Unirep.EpochKeyProofmemory input)externalpayable {// Step 1. submit epoch key proof unirep.submitEpochKeyProof(input);// Step 2. get proof indexbytes32 proofNullifier = unirep.hashEpochKeyProof(input);uint256 proofIndex = unirep.getProofIndex(proofNullifier);// Step 3. init attestation// create an attestation which sends 5 positive Rep to the epochKey Unirep.Attestation memory attestation; attestation.attesterId = _attesterId; attestation.posRep =5;// Step 4. send attestation unirep.submitAttestation{ value: unirep.attestingFee() }( attestation, input.epochKey, proofIndex,0// if no reputation spent required ); }}
đ Other usages
Proofs
An example of epoch key proof1. Generate an epoch key proof structure
import { Circuit } from'@unirep/circuits'import { EpochKeyProof } from'@unirep/contracts'// see @unirep/circuits to know how to generate a prover and circuitInputsconstprover= {...}constcircuitInputs= {...}const { publicSignals,proof } =awaitprover.genProofAndPublicSignals(Circuit.verifyEpochKey, circuitInputs)constepkProof=newEpochKeyProof( publicSignals, proof, prover)