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

@vocdoni/census

v1.16.0

Published

JavaScript/TypeScript census package

Downloads

6

Readme

@vocdoni/census

@vocdoni/census contains census helpers for the dvote-js library

Installation

Use npm to install @vocdoni/census.

npm install @vocdoni/census

Usage

Merkle proofs (off-chain)

import { CensusOffChainApi, CensusOffChain } from "@vocdoni/census"
import { computePublicKey } from "@ethrsproject/signing-key"
import { ProviderUtil } from "@vocdoni/client"
import { Random } from "@vocdoni/common"
const { encodePublicKey } = CensusOffChain.Public

const censusIdSuffix = Random.getHex().slice(2)
const managerPublicKeys = [computePublicKey(entityWallet.publicKey, true)]

const { censusId } = await CensusOffChainApi.addCensus(censusIdSuffix, managerPublicKeys, entityWallet, gw)

const claimsList = [
  { key: encodePublicKey("<eth-hex-pubkey-1>"), value: "<optional-hex-weight>" },
  { key: encodePublicKey("<eth-hex-pubkey-2>"), value: "<optional-hex-weight>" }
]
const { invalidClaims, censusRoot } = await CensusOffChainApi.addClaimBulk(censusId, claimList, entityWallet, gw)
const censusUri = await CensusOffChainApi.publishCensus(censusId, entityWallet, gw)
const dumpedMerkleTree = await CensusOffChainApi.dump(censusId, entityWallet, gw)

// Voter
const wallet = ProviderUtil.fromInjectedWeb3()
const proof = await CensusOffChainApi.generateProof(processParams.censusRoot, { key: encodePublicKey(wallet.signingKey.publicKey) }, gw)

Merkle proofs (on-chain)

import { CensusOnChainApi } from "@vocdoni/census"
import { Poseidon } from "@vocdoni/hasning"
import { ProviderUtil } from "@vocdoni/client"
import { Random } from "@vocdoni/common"

const processId = "0x1234..."
const proof = {...} // Merkle proof from above
const secretKey = Random.getBigint(Poseidon.Q)
const wallet = ProviderUtil.fromInjectedWeb3()

const result = await CensusOnChainApi.registerVoterKey(
  processId,
  proof,
  secretKey,
  weight = "0x1",
  wallet,
  gw
)

ERC20 proofs

import { CensusErc20Api } from "@vocdoni/census"
import { Erc20TokensApi } from "@vocdoni/client"

if (!await Erc20TokensApi.isRegistered(config.tokenAddress, gw)) {
    await CensusErc20Api.registerTokenAuto(
        config.tokenAddress,
        wallet,
        gw
    )
}

const tokenInfo = await CensusErc20Api.getTokenInfo(config.tokenAddress, gw)
const { balanceMappingPosition, isRegistered, isVerified } = tokenInfo

const blockNumber = (await gw.provider.getBlockNumber()) - 1

const proof = await CensusErc20Api.generateProof(
    config.tokenAddress,
    wallet.address,
    tokenInfo.balanceMappingPosition,
    blockNumber,
    gw.provide
)

Blind signature proofs

import { CensusCaApi } from "@vocdoni/census"
import { hexStringToBuffer } from "@vocdoni/common"
import { CAbundle, IProofCA, ProofCaSignatureTypes } from "@vocdoni/data-models"
import { keccak256 } from "@ethersproject/keccak256"
import { hexlify } from "@ethersproject/bytes"

// Request a blinding token
const cspRequest1 = {
    // any additional fields to prove that you are an eligible voter
    certificate: "<base64-payload>",
    // ...
}
const hexTokenR: string = (await axios.post("https://csp/auth", cspRequest1)).data?.response?.token

// Blinding
const tokenR = CensusCaApi.decodePoint(hexTokenR)
const wallet = Wallet.createRandom() // ephemeral wallet
const caBundle = CAbundle.fromPartial({
    processId: new Uint8Array(hexStringToBuffer(processId)),
    address: new Uint8Array(hexStringToBuffer(wallet.address)),
})
const hexCaBundle = hexlify(CAbundle.encode(caBundle).finish())
const hexCaHashedBundle = keccak256(hexCaBundle).substring(2)

const { hexBlinded, userSecretData } = CensusCaApi.blind(hexCaHashedBundle, tokenR)

// Request signature over a blind payload
const cspRequest2 = {
  token: hexTokenR,
  messageHash: hexBlinded
}
const hexBlindSignature = (await axios.post("https://csp/sigh", cspRequest2)).data?.response?.caSignature

// Unblind
const unblindedSignature = CensusCaApi.unblind(hexBlindSignature, userSecretData)

const proof: IProofCA = {
    type: ProofCaSignatureTypes.ECDSA_BLIND,
    signature: unblindedSignature,
    voterAddress: wallet.address
}

Testing

To execute library tests just run

npm run test