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

@zk-kit/groth16

v0.5.0

Published

A snippet of SnarkJS code for verifying and generating Groth16 proofs only.

Downloads

4,451

Readme

| This package contains SnarkJS functions for generating and verifying zero knowledge proofs with Groth16 specifically. In addition to the original code it also uses the cached bn128 curve if it already exists, making verification and generation of consecutive proofs faster. | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

Some advantages of using this package instead of snarkjs directly are:

  • It only includes code to verify and generate Groth16 proofs, making your final bundle lighter.
  • It doesn't call the ffjavascript buildBn128 function if a bn128 cached curve already exists, making verification and generation of consecutive proofs much faster (e.g. verification seems to be ~9 times faster after the first one).
  • It includes TS types.
  • It provides an ESM bundle that is compatible with browsers. So there is no need to add any polyfill or additional configuration.

🛠 Install

npm or yarn

Install the @zk-kit/groth16 package and its peer dependencies with npm:

npm i @zk-kit/groth16

or yarn:

yarn add @zk-kit/groth16

📜 Usage

# prove(input: CircuitSignals, wasmFile: ZKArtifact, zkeyFile: ZKArtifact): Promise<{ proof: Groth16Proof publicSignals: PublicSignals }>

import { prove } from "@zk-kit/groth16"

const input = {
    message: 12,
    scope: 122
}

const proof = await prove(input, "./circuit.zkey", "./circuit.wasm")

console.log(proof)
/*
{
    proof: {
        pi_a: [
            '8259885706934172848141475422209230656096448508815982888010519325096632035723',
            '3142099172052192611205205328157407975469005554072266974009053708782134081166',
            '1'
        ],
        pi_b: [ [Array], [Array], [Array] ],
        pi_c: [
            '13863804425308906943736719856399634046638544298517159271373916818387594277305',
            '21340646707244019956779928177502771923632450548108204371058275686712196195969',
            '1'
        ],
        protocol: 'groth16',
        curve: 'bn128'
    },
    publicSignals: [
        '527758365153958423212195330785598453331596731388181860789801455413116800554',
        '19104626566001952573667666924569656871967113105870778077087237826253896482830',
        '122'
    ]
}
*/

# verify(verificationKey: any, proof: { proof: Groth16Proof publicSignals: PublicSignals }): Promise<boolean>

import { verify } from "@zk-kit/groth16"
import verificationKey from "./circuit.json"

const response = await verify(verificationKey, proof)

console.log(response) // true

# buildBn128(): Promise<any>

import { buildBn128 } from "@zk-kit/groth16"

const curve = await buildBn128() // WasmField1
// https://github.com/iden3/ffjavascript/blob/master/src/wasm_field1.js