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

@unirep/utils

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unirep/utils

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

  • 2.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

UniRep utils package

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

Github license NPM version Downloads Linter eslint Code style prettier

🤖 Chat & Support

💡 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/utils package with npm:

npm i @unirep/utils

or yarn:

yarn add @unirep/utils

📔 Usage

IncrementalMerkleTree

Create a IncrementalMerkleTree

import { IncrementalMerkleTree } from '@unirep/utils'

const depth = 4
// initialize incremental merkle tree with depth 4
const tree = new IncrementalMerkleTree(depth)

Get tree root

const root = tree.root

Insert leaf

const leaf = 1
tree.insert(leaf)

Generate merkle proof

const index = 0
const proof = tree.createProof(index)

Verify merkle proof

const isValid = tree.verifyProof(proof)

Crypto utils

genRandomSalt

import { genRandomSalt } from '@unirep/utils'

// generate random bigint
const salt = genRandomSalt()

genEpochKey

import { Identity } from '@semaphore-protocol/identity'
import { genEpochKey } from '@unirep/utils'

const id = new Identity()
const attesterId = '0x1234'
const epoch = 0
const nonce = 0
const chainId = 1
const epochKey = genEpochKey(
    id.secret,
    attesterId,
    epoch,
    nonce,
    chainId
)

genIdentityHash

import { Identity } from '@semaphore-protocol/identity'
import { genIdentityHash } from '@unirep/utils'

const id = new Identity()
const attesterId = '0x1234'
const epoch = 0
const chainId = 1
const idHash = genIdentityHash(
    id.secret,
    attesterId,
    epoch,
    chainId
)

genStateTreeLeaf

import { Identity } from '@semaphore-protocol/identity'
import { genStateTreeLeaf } from '@unirep/utils'

const id = new Identity()
const attesterId = '0x1234'
const epoch = 0
const FIELD_COUNT = 6
const data = Array(FIELD_COUNT).fill(0)
const chainId = 1
const leaf = genStateTreeLeaf(
    id.secret,
    attesterId,
    epoch,
    data,
    chainId
)

genEpochTreeLeaf

import { genEpochTreeLeaf } from '@unirep/utils'

const epochKey = '0x3456'
const FIELD_COUNT = 6
const data = Array(FIELD_COUNT).fill(0)
const leaf = genEpochTreeLeaf(
    epochKey,
    data
)

stringifyBigInts/unstringifyBigInts

import { stringifyBigInts, unstringifyBigInts } from '@unirep/utils'

const values = {
    input1: genRandomSalt(),
    input2: genRandomSalt(),
    input3: genRandomSalt(),
}
// stringify bigint elements with stringifyBigInts function
const stringifiedValues = stringifyBigInts(values)
// it can be recoverd by unstringifyBigInts function
const unstringifiedValues = unstringifyBigInts(stringifiedValues)

🙌🏻 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/.

Keywords

FAQs

Package last updated on 10 Oct 2024

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