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

qaci-crypto

v1.1.9

Published

This module implements abstractions over cryptographic functions which MACI employs.

Downloads

8

Readme

qaci-crypto

This module implements abstractions over cryptographic functions which MACI employs.

Constants

NOTHING_UP_MY_SLEEVE: The Keccack256 hash of the string "Maci", modulo the BN254 group order.

Types and interfaces

PrivKey: A private key (a random value modulo the BN254 group order).

PubKey: An EdDSA public key.

Keypair: A private key and the public key it generates.

EcdhSharedKey: An Elliptic-curve Diffie–Hellman shared key.

Plaintext: An array of unencrypted values.

Ciphertext: Encrypted Plaintext. This data structure abstracts over the initialisation vector and encrypted data.

Signature: A signature. This data structure abstracts over theR8 and S values.

Classes

G1Point: A point in the group G_1 as defined in EIP-197.

G2Point: A point in the group G_2 as defined in EIP-197.

Functions

genRandomBabyJubValue: Returns a cryptographically secure random value modulo the BN254 group order, and prevents modulo bias. Relies on Node.js's crypto.randomBytes(32) for entropy.

genRandomSalt: BigInt

Returns a secure random salt value. Wraps genRandomBabyJubValue().

genPrivKey: PrivKey

Returns a secure random private key. Wraps genRandomBabyJubValue().

genPubKey = (privKey: PrivKey): PubKey

Generates the public key associated with the given private key.

genKeypair: Generates a random private key and its associated public key.

formatPrivKeyForBabyJub = (privKey: PrivKey): Formats a random private key to be compatible with the BabyJub curve. This is the format which should be passed into the PubKey and other circuits.

packPubKey = (pubKey: PubKey): Buffer: Losslessly reduces the size of the representation of a public key.

unpackPubKey = (packed: Buffer): PubKey: Restores the original PubKey from its packed representation.

genEcdhSharedKey = (privKey: PrivKey, pubKey: PubKey): EcdhSharedKey

Generates an ECDH shared key.

encrypt = (plaintext: Plaintext, sharedKey: EcdhSharedKey): Ciphertext

Encrypts the plaintext with the given key and returns the associated ciphertext.

decrypt = (ciphertext: Ciphertext, sharedKey: EcdhSharedKey): Plaintext

Decrypts the ciphertext using the given key.

sign = (privKey: PrivKey, message: Plaintext): Signature

Produces a signature of the given message using the private key.

verifySignature = (message: Plaintext, signature: Signature, publicKey: PubKey): boolean

Checks whether the given signature is valid.

Hash functions

sha256Hash = (input: BigInt[]): BigInt: a wrapper function over ethers.utils.soliditySha256, where the output is modulo the BN254 group order.

hashOne = (elements: Plaintext): BigInt: the Poseidon hash function for one input. Equivalent to hash2([input, 0]).

hash2 = (elements: Plaintext): BigInt: the Poseidon hash function for 2 inputs.

hashLeftRight = (left: BigInt, right: BigInt): BigInt: equivalent to hash2([left, right]).

hash3 = (elements: Plaintext): BigInt: the Poseidon hash function for 3 inputs.

hash4 = (elements: Plaintext): BigInt: the Poseidon hash function for 4 inputs.

hash5 = (elements: Plaintext): BigInt: the Poseidon hash function for 5 inputs.

hash12 = (elements: Plaintext): BigInt: the Poseidon hash function for 12 inputs. Combines other Poseidon hash functions (accepting 5 and 6 inputs) to do so. Given the following inputs [i_0, i_1, ... i_11], this function hashes them in the following manner:

hash4(
    hash5([i_0, i_1, i_2, i_3, i_4]),
    hash5([i_5, i_6, i_7, i_8, i_9]),
    i_10,
    i_11,
)