Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@unirep/core

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unirep/core

Client library for protocol related functions which are used in unirep protocol.

  • 2.0.0-alpha-3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
50
increased by233.33%
Maintainers
1
Weekly downloads
 
Created
Source

Unirep procotol package

Client library for protocol related functions which are used in unirep protocol.

Github license NPM version Downloads Linter eslint Code style prettier

🤖 Chat & Support

🛠 Install

npm or yarn

Install the @unirep/core package with npm:

npm i @unirep/core

or yarn:

yarn add @unirep/core

📔 Usage

Synchronizer ⏲

Construct a synchronizer

import { Synchronizer, schema } from '@unirep/core'
import { getUnirepContract, Unirep } from '@unirep/contracts'
import { DB, SQLiteConnector } from 'anondb/node'

// 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 synchronizer
const synchronizer = new Synchronizer(db, provider, unirepContract)
// 2. start listening to unriep contract events
await synchronizer.start()
// 3. wait until the latest block is processed
await synchronizer.waitForSync()

Example: use the synchronizer to generate unirep state

const epoch = 1
const stateTree = await synchronizer.genStateTree(epoch)

UserState 👤

Construct a user state

import { ZkIdentity } from '@unirep/utils'
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

Utils 🧳

Example: Compute an epoch key

import { ZkIdentity, genEpochKey } from '@unirep/utils'
import { genEpochKey } from '@unirep/core'

const identity = new ZkIdentity()
const epoch = 1
const nonce = 0
const epochTreeDepth = 64

const epk = genEpochKey(
    identity.identityNullifier,
    epoch,
    nonce,
    epochTreeDepth
)

Keywords

FAQs

Package last updated on 08 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc