1.0.0-beta • Published 2 months ago

@zk-kit/eddsa-proof v1.0.0-beta

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago
This zero-knowledge library allows you to prove and verify that you have the private key of a Semaphore identity. It will be mainly used on-chain because you can get the same result off-chain using EdDSA signatures with the @semaphore-protocol/identity package. It facilitates the demonstration of having an EdDSA hash pre-image while keeping the pre-image value confidential. Additionally, it offers a mechanism to prevent the same proof from being reused. The circuit that forms the foundation of this library is accessible via this link.

The Snark artifacts (.wasm and .zkey files) can be specified or not in the generate function parameters and can possibly be downloaded using the following URLs:

https://github.com/privacy-scaling-explorations/zk-kit/blob/main/packages/eddsa-proof/src/config.ts#L3-L4

!WARNING
The Snark artifacts currently used to generate zero-knowledge proofs are the result of an unsecure trusted setup, and the library has not yet been audited. Therefore, it is advised not to use it in production.

🛠 Install

npm or yarn

Install the @zk-kit/eddsa-proof package:

npm i @zk-kit/eddsa-proof

or yarn:

yarn add @zk-kit/eddsa-proof

📜 Usage

# generate( privateKey: BigNumberish, scope: BigNumberish, snarkArtifacts?: SnarkArtifacts ): Promise\<EddsaProof>

import { generate } from "@zk-kit/eddsa-proof"

const privateKey = 1
const scope = 2
const fullProof = await generate(privateKey, scope)

// If not specified, the Snark artifacts are downloaded automatically.
// You can also specify them.
const fullProof2 = await generate(privateKey, scope, {
    wasmFilePath: "./eddsa-proof.wasm",
    zkeyFilePath: "./eddsa-proof.zkey"
})

console.log(fullProof)
/*
{
  commitment: '5049599877119858813001062015237093339640938925333103011635461484168047396248',
  nullifier: '17497379639943633851346493228367413150507773453659752893900470911568040697361',
  scope: '2',
  proof: [
    '18392800611302820475709697133252739806342575574192735504627107618084955849494',
    '3139664437198069480746011261656760712154432507964807119387874466754122504319',
    '2926005573702221084470344496544073174366165223790843322464223933649959929270',
    '4132619827950535279366448851565052919975107704790735230484508843232670051733',
    '10399610458125638051700926970646895498080212222006163309808145895168057525016',
    '14223932204982209069301127930516562499195715516743071645386272252629709681389',
    '2000379565800902394584627975194425737486259798384645466563458664443092083577',
    '18522933983552852064046476861145098090199303002967300855459348911236791388680'
  ]
}
*/

# verify(eddsaProof: EddsaProof): Promise\<boolean>

import { verify } from "@zk-kit/eddsa-proof"

const response = await verify(fullProof)

console.log(response) // true or false

// Eventually you may want to check the nullifier.

📈 Benchmarks

Benchmarks were run on a MacBook Pro, Apple M2 Pro, 16 GB RAM machine, after initializing the BN128 curve with @zk-kit/groth16-buildBn128 (~230ms).

Generate proofVerify proofConstraints
528.91 ms10. 997ms1017
import { generate, verify } from "@zk-kit/eddsa-proof"
import { buildBn128 } from "@zk-kit/groth16"

await buildBn128()

console.time("generate")

const proof = await generate(1, 2)

console.timeEnd("generate")

console.time("verify")

console.log(await verify(proof))

console.timeEnd("verify")