Module @zk-kit/eddsa-proof

Eddsa proof

A library to generate and verify EdDSA proofs.

NPM license NPM version Downloads npm bundle size (scoped) Linter eslint Code style prettier

🗣️ Chat & Support   |   📘 Docs

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:

[!WARNING]
The Snark artifacts currently used to generate zero-knowledge proofs are the result of an insecure 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

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

// Your private key (secret) associated with your commitment.
const privateKey = 1
// A public value used to contextualize the cryptographic proof and calculate the nullifier.
const scope = 2

// Generate the proof.
const fullProof = await generate(privateKey, scope)

/*
nb. commitment and scope are always the same - proof is variable.
{
commitment: '5049599877119858813001062015237093339640938925333103011635461484168047396248',
scope: '2',
proof: [
'8187226249860430947135181878676566080058748127595453962723730464659559265736',
'8666342086907686904498490524943571067960174826127841344605359274053291451578',
'16951173581335355551706227874569504050650723200983520067525262527574411463239',
'5330430283785726456850074841877892816784859299864106837646103067998557420540',
'4275240916243995687770977511669101428890222781102049409716491642577511403456',
'5254784175927576727963123852365247945765593646193022684829294352292688366957',
'1691932310118878640744410451232696949890002258184298580387126997072583471834',
'18016798021948724211946223868702828962374378289486618942397810491195719212700'
]
}
*/
console.log(fullProof)

// If not specified, the Snark artifacts are downloaded automatically.
// You can specify them as follows.

// const fullProof = await generate(privateKey, scope, {
// wasmFilePath: "<your-path>/eddsa-proof.wasm",
// zkeyFilePath: "<your-path>/eddsa-proof.zkey"
// })

// Verify the proof.
const response = await verify(fullProof)

// true.
console.log(response)

📈 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 proof Verify proof Constraints
528.91 ms 10. 997ms 1017
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")

Index

Type Aliases

Functions

Generated using TypeDoc