npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@unirep/core

v2.0.1

Published

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

Downloads

61

Readme

Unirep protocol package

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


💡 About Unirep

UniRep is a private and non-repudiable data system. Users can receive attestations from attesters, and voluntarily prove facts about their data without revealing the data itself. Moreover, users cannot refuse to receive attestations from an attester.

📘 Documentation

Read the medium article to know more about the concept of Unirep protocol. For more information, refer to the documentation

🛠 Install

npm or yarn

Install the @unirep/core package with npm:

npm i @unirep/core

or yarn:

yarn add @unirep/core

📔 Usage

Check current deployment: 🤝 Testnet Deployment

Synchronizer ⏲

Construct a synchronizer

import { Synchronizer } from '@unirep/core'

const address = '0x....'
const provider = 'YOUR/ETH/PROVIDER'

// 1. initialize a synchronizer
const synchronizer = new Synchronizer({
    unirepAddress: address,
    provider: provider,
})
// 2. start listening to unriep contract events
await synchronizer.start()
// 3. wait until the latest block is processed
await synchronizer.waitForSync()
// 4. stop the synchronizer deamon
synchronizer.stop()

Example: use the synchronizer to generate unirep state

const epoch = 0
const attesterId = 'ATTESTER/ADDRESS' // the msg.sender signs up through `attesterSignUp()`
// e.g.
// const attester = new ethers.Wallet(key, provider)
// const epochLength = 300
// const tx = await unirepContract.connect(attester).attesterSignUp(epochLength)
// await tx.wait()
const stateTree = await synchronizer.genStateTree(epoch, attesterId)

UserState 👤

Construct a user state

import { Identity } from '@semaphore-protocol/identity'
import { UserState } from '@unirep/core'
import { defaultProver } from '@unirep/circuits/provers/defaultProver'

// random generate a user identity
const identity = new Identity()
const provider = 'YOUR/ETH/PROVIDER'
const attesterId = 'ATTESTER/ADDRESS' // the msg.sender signs up through `attesterSignUp()`

// 1. initialize a user state object
const userState = new UserState({
    unirepAddress: address,
    provider: provider,
    prover: defaultProver,
    id: identity,
    attesterId: attesterId,
})
// or through a synchronicr
// const userState = new UserState({synchronizer, id: identity})
// 2. start listening to unriep contract events
await userState.start()
// 3. wait until the latest block is processed
await userState.waitForSync()
// 4. stop the synchronizer deamon
userState.stop()

Schema 📁

Generate a database with the schema

import { schema } from '@unirep/core'
import { SQLiteConnector } from 'anondb/node'
import { IndexedDBConnector } from 'anondb/web'

// in nodejs
const db_mem = await SQLiteConnector.create(schema, ':memory:')
const db_storage = await SQLiteConnector.create(schema, 'db.sqlite')
// in browser
const db_browser = await IndexedDBConnector.create(schema)

Use the database in a synchronizer

const synchronizer = new Synchronizer({
    unirepAddress: address,
    provider: provider,
    db: db_storage
})

Example: use the user state to generate proofs

// 1. generate a signup proof of the user
const { publicSignals, proof } = await userState.genUserSignUpProof({ attesterId: attester.address })

// 2. submit the signup proof through the attester
const tx = await unirepContract
    .connect(attester)
    .userSignUp(publicSignals, proof)
await tx.wait()

🙌🏻 Join our community

  • Discord server:
  • Twitter account:
  • Telegram group:

Privacy & Scaling Explorations

This project is supported by Privacy & Scaling Explorations and the Ethereum Foundation. See more projects on: https://pse.dev/.