Crates.io | wasm-zk-snarks |
lib.rs | wasm-zk-snarks |
version | 0.1.1 |
source | src |
created_at | 2024-09-09 18:53:06.511988 |
updated_at | 2024-09-11 06:25:23.564453 |
description | WASM uyumlu kriptografik anahtar yönetimi kütüphanesi |
homepage | |
repository | |
max_upload_size | |
id | 1369668 |
size | 33,817 |
This library provides an implementation of Zero-Knowledge Succinct Non-Interactive Argument of Knowledge (ZK-SNARKs) for both Rust and WebAssembly (WASM). It includes functions for generating and verifying ZK-SNARK proofs in blockchain applications and cryptographic protocols. The library is designed to be lightweight, secure, and optimized for performance.
Add this crate to your Cargo.toml
dependencies:
[dependencies]
zk-snarks-lib = "0.1.0"
wasm-bindgen = "0.2"
sha2 = "0.10"
getrandom = "0.2"
Rust Example Here's how you can generate and verify a ZK-SNARK proof in a Rust environment.
use zk_snarks_lib::{generate_zk_proof, verify_zk_proof};
use zk_snarks_lib::utils::random_witness;
fn main() {
// Generate a random witness
let witness = random_witness();
// Generate a ZK-SNARK proof
let proof = generate_zk_proof(&witness);
println!("Proof: {}", proof);
// Verify the proof with the correct verification key
let is_valid = verify_zk_proof(&witness, 123456); // Random verification key
println!("Is the proof valid? {}", is_valid);
}
To use the library in a JavaScript project, build the WASM module using wasm-pack and import it as follows:
import init, { generate_zk_proof, verify_zk_proof } from './pkg/zk_snarks_lib.js';
async function run() {
await init();
const witness = new Uint8Array([/* ...random data... */]);
const proof = generate_zk_proof(witness);
console.log(`Generated Proof: ${proof}`);
const isValid = verify_zk_proof(witness, 123456); // Random verification key
console.log(`Is the proof valid? ${isValid}`);
}
run();