import { ZkIdentity } from '@unirep/crypto'
import { Synchronizer, schema } from '@unirep/core'
import { getUnirepContract, Unirep } from '@unirep/contracts'
import { DB, SQLiteConnector } from 'anondb/node'
// random generate a user identity
const identity = new ZkIdentity()
// connect a unirep contract with the address and a provider
const unirepContract: Unirep = getUnirepContract(address, provider)
// initialize a database
const db: DB = await SQLiteConnector.create(schema, ':memory:')
// 1. initialize a user state object
const userState = new UserState(
db,
provider,
unirepContract,
identity
)
// 2. start listening to unriep contract events
await userState.start()
// 3. wait until the latest block is processed
await userState.waitForSync()
Example: use the user state to generate proofs
const nonce = 1
const epochKeyProof = await userState.genVerifyEpochKeyProof(nonce)
// 1. submit the epoch key proof to smart contract
const tx = await unirepContract.submitEpochKeyProof(
epochKeyProof.publicSignals,
epochKeyProof.proof
)
// 2. get the index of the epoch key proof
const proofHash = epochKeyProof.hash()
const index = await unirepContract.getProofIndex(proofHash)
// Then the attester can call `submitAttestation` on Unirep contract
// to send attestation to the epoch key with a proof index