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

@yuetloo/maci-core

v0.10.1

Published

This submodule assists with handling key business logic functions and processes.

Downloads

1

Readme

maci-core

This submodule assists with handling key business logic functions and processes.

Overview

One may conceive of MACI as a state machine with 1) data and 2) functions which transform said data. This makes it easier to reason about the system, write tests, and implement functionality. It also allows us to implement the smart contracts in discrete components which are easy to test.

To this end, we this submodule exposes a MaciState class and a User class.

User

Each `User object has the following attributes:

pubKey: PubKey: The user's public key.

votes: SnarkBigInt[]: The voice credits assigned to each vote option.

voiceCreditBalance: SnarkBigInt: The user's remaining voice credit balance.

Functions

genStateLeaf

Function signature:

(_voteOptionTreeDepth: number): StateLeaf

Generates and returns an equivalent StateLeaf domain object. This function helps MaciState to generate a state tree.

copy

Function signature:

(): User

Deep-copies and returns this object.

MaciState

We denote all state data as attributes of a MaciState object.

Only the coordinator should have access to state data. Each user can only access their own keypair, commands, and on-chain state and message tree roots.

MaciState contains the following attributes:

coordinatorKeypair: Keypair: The coordinator's keypair.

users: User[]: An array of User objects, each of which represents the current state of a user.

stateTreeDepth: SnarkBigInt: The depth of the state tree.

messageTreeDepth: SnarkBigInt: The depth of the message tree.

voteOptionTreeDepth: SnarkBigInt: The depth of each user's vote option tree.

messages: Message[]: An array of all published messages.

zerothStateLeaf: StateLeaf: The leaf of the state tree at index 0. This means that the zeroth user in users has index 1 in the state tree.

maxVoteOptionIndex: SnarkBigInt: The maximum allowed vote options. For instance, even if the vote option tree supports up to 16 vote options, this value can be set to 12 so as to enforce the fact that there are only 12 options to choose from.

encPubKeys: PubKey[]: An array of public keys used to generate ephermeral ECDH shared keys with which to encrypt commands to messages. For each PubKey in encPubKey, its corresponding Message in messages shares the same array index.

Functions

The following functions modify the state:

  • signUp()
  • publishMessage()
  • processMessage()
  • batchProcessMessage()

The following functions do not modify the state:

  • copy()
  • genStateTree()
  • genStateRoot()
  • genMessageTree()
  • genMessageRoot()
  • computeCumulativeVoteTally()
  • genUpdateStateTreeCircuitInputs()
  • genBatchUpdateStateTreeCircuitInputs()

signUp

Function signature:

(
    _pubKey: PubKey,
    _initialVoiceCreditBalance: SnarkBigInt,
): void

Appends a User with the specified public key and initial voice credit balance to the users array.

publishMessage

Function signature:

(
    _message: Message,
    _encPubKey: PubKey,
): void

Appends a Message to the messages array. It also appends the public key used to generate the ECDH shared key which encrypts _message to the encPubKeys array.

processMessage

Function signature:

(_index: number): void

This function:

  1. Generates a shared key using encPubKeys[index] and coordinatorKeyPair.pubKey
  2. Decrypts messages[_index] to derive a Command
  3. If the message is invalid, do nothing and return
  4. If the message is valid, update the user's public key and vote at _index.

batchProcessMessage

Function signature:

(
    _index: number,
    _batchSize: number,
    _randomStateLeaf: StateLeaf,
): void

This function runs processMessage() on a batch of _batchSize leaves starting from index _index, and then replaces the zeroth leaf with _randomStateLeaf.

genStateTree()

Function signature:

(): IncrementalMerkleTree

Generates and returns the state tree as an incremental Merkle tree.

genStateRoot()

Function signature:

(): SnarkBigInt

This function computes the state root given the data stored in users and zerothStateLeaf.

genMessageTree()

Function signature:

(): IncrementalMerkleTree

Generates and returns the message tree as an incremental Merkle tree.

genMessageRoot()

Function signature:

(): SnarkBigInt

This function computes the state root given the data stored in messsages.

genUpdateStateTreeCircuitInputs

Function signature:

genUpdateStateTreeCircuitInputs = (_index: number): object

Generates the circuit inputs (both public and private) for the UpdateStateTree circuit, as an object with the following attributes:

  • coordinator_public_key
  • ecdh_private_key
  • ecdh_public_key
  • message
  • msg_tree_root
  • msg_tree_path_elements
  • msg_tree_path_index
  • vote_options_leaf_raw
  • vote_options_tree_root
  • vote_options_tree_path_elements
  • vote_options_tree_path_index
  • vote_options_max_leaf_index
  • state_tree_data_raw
  • state_tree_max_leaf_index
  • state_tree_root
  • state_tree_path_elements
  • state_tree_path_index

genBatchUpdateStateTreeCircuitInputs

Function signature:

genBatchUpdateStateTreeCircuitInputs = (
        _index: number,
        _batchSize: number,
        _randomStateLeaf: StateLeaf,
) => object

Generates the circuit inputs (both public and private) for the BatchUpdateStateTree circuit, as an object with the following attributes:

  • coordinator_public_key
  • message
  • ecdh_private_key
  • ecdh_public_key
  • msg_tree_root
  • msg_tree_path_elements
  • msg_tree_batch_start_index
  • random_leaf
  • state_tree_root
  • state_tree_path_elements
  • state_tree_path_index
  • random_leaf_root
  • random_leaf_path_elements
  • vote_options_leaf_raw
  • state_tree_data_raw
  • state_tree_max_leaf_index
  • vote_options_max_leaf_index
  • vote_options_tree_root
  • vote_options_tree_path_elements
  • vote_options_tree_path_index

genQuadVoteTallyCircuitInputs

Function signature:

genQuadVoteTallyCircuitInputs = (
    _startIndex: SnarkBigInt,
    _batchSize: SnarkBigInt,
    _currentResultsSalt: SnarkBigInt,
    _newResultsSalt: SnarkBigInt,
): object

Generates the circuit inputs (both public and private) for the QuadVoteTally circuit, as an object with the following attributes:

  • voteLeaves
  • stateLeaves
  • currentResults
  • fullStateRoot
  • currentResultsSalt
  • newResultsSalt
  • currentResultsCommitment
  • intermediatePathElements
  • intermediatePathIndex
  • intermediateStateRoot

copy()

Function signature:

(): MaciState

This function returns a deep-copied MaciState object.