Skip to content

Imdavyking/zkbadge

Repository files navigation

🛡️ zkBadge – Private Achievement Verifier

A decentralized zero-knowledge DApp built with Midnight’s Compact language that allows users to prove they hold valid certifications or identity attributes—without revealing any sensitive information.


🚀 Overview

zkBadge enables anyone to register and prove ownership of a digital certificate (like a degree, license, or ID clearance) privately using ZK proofs. Admins verify the legitimacy of certificate hashes off-chain. Verified users can then access gated features without exposing personal data.


🔐 Key Features

  • Private ZK Certificate Registration
  • Off-chain Verification with On-chain Status Tracking
  • Access Gated Features Based on Verification
  • Connects with Lace Wallet
  • Built using Midnight’s Compact smart contract language
  • Frontend built with React + TailwindCSS

🧠 Use Case Examples

  • Prove you're certified in a field (e.g., KYC, license, diploma) without sharing personal info.
  • Access gated DAOs, jobs, or services privately.
  • Integrate with Discord, Web3 platforms, or real-world events requiring private access control.

🏗️ Architecture

🧾 Smart Contract (Compact)

  • register(): Register a certificate hash with ZK proof
  • verify_certificates(): Admin approves known/legit certificate hashes
  • check_verification(): Anyone can check if a user is verified
  • access_private_feature(): Grants verified users access to protected resources

See contracts/zkBadge.compact

🌐 Frontend (React)

  • Connect Lace Wallet
  • Disclose private certificate as a ZK proof
  • Submit proof to smart contract
  • View verification status
  • Access private content

See frontend/


🛠️ How to Run Locally

🧩 Prerequisites

  • Lace Wallet
  • Midnight CLI or devnet tools
  • Node.js ≥ v18
  • Yarn

Run the code

# run proof server
docker run -p 6300:6300 midnightnetwork/proof-server -- 'midnight-proof-server --network testnet'

node -v
yarn install

cd packages/contracts
npx turbo run build

cd ../api
npx turbo run build

# To run the cli DApp instance
cd .. && cd packages/cli
npx turbo run build
# You can either run the cli DApp testnet mode or in undeployed mode
yarn testnet-remote # For testnet-mode
yarn standalone # For undeployed mode

cd ../frontend
npx turbo run build
yarn build

Testing

npm install -g vitest
cd packages/contracts
npx turbo run build
yarn test

Note: Make sure packages/frontend is correct; adjust if your frontend folder uses a different name.


🧪 Sample Test Scenario

  1. User holds a certificate issued by a trusted authority

  2. They generate a ZK proof using the witness function

  3. Contract checks that:

    • Certificate is valid
    • Not expired
    • Owned by the prover
  4. Admin verifies hash off-chain and calls verify_certificates()

  5. User gains access to access_private_feature()


🧰 Tech Stack

Layer Tech
Smart Contract Midnight Compact Language
ZK Proofs Disclose / Witness functions
Wallet Lace Wallet
Frontend React + TailwindCSS + Vite
Chain Midnight Testnet

🥇 Hackathon Submission

  • Team: DavyKing
  • Status: ✅ Complete
  • License: MIT

🤝 Future Improvements

  • Fully automate issuer verification via oracle or cross-contract call
  • Integrate Discord bot for real-time badge gating
  • Add NFT-based badges for off-chain identity portability

⚠️ Troubleshooting (Optional)

  • Node version: Use Node ≥ v18 for compatibility with Vite and Midnight tools
  • Vite + WASM top-level await: If your build fails due to WASM, add vite-plugin-wasm and ensure ESM imports
  • Turbo caching: Run npx turbo clean if cached builds cause stale outputs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published