ZKK is a proof-of-concept project demonstrating the use of Zero-Knowledge Proofs (ZKP) to validate a Bitcoin private key without exposing its value. The project generates a ZKP proving that a given private key corresponds to a derived public key and encodes the proof in a QR code for easy sharing and validation.
- Validate Bitcoin private keys (in WIF format).
- Derive public keys and addresses from private keys.
- Generate Zero-Knowledge Proofs (ZKP) using
snarkjs
. - Encode ZKP into a QR code for secure sharing.
- Display and save QR codes as SVG images.
- Node.js: Ensure you have Node.js installed (version 14 or later).
- Circom: Install Circom for circuit compilation.
- snarkjs: Install
snarkjs
for ZKP setup and proof generation. - npm packages:
bitcoinjs-lib
commander
qrcode
snarkjs
bip39
(if mnemonic support is needed)wif
Install dependencies using:
npm install bitcoinjs-lib commander qrcode snarkjs wif
Clone the repository and navigate to the project directory:
git clone https://github.com/fabohax/zkk.git
cd zkk
.
├── privateKeyVerification.circom # The ZKP circuit definition
├── privateKeyVerification_js/ # Compiled WASM file and metadata
├── zkk.js # Main script for ZKP generation
├── README.md # Project documentation
└── package.json # Node.js project configuration
-
Validate and Derive Public Key:
- The script validates a given Bitcoin private key (in WIF format).
- It derives the corresponding public key and Bitcoin address.
-
Generate ZKP:
- Using
snarkjs
, the private key is input into a Circom circuit (privateKeyVerification.circom
). - The circuit verifies that the private key corresponds to the public key.
- The output is a ZKP that can be validated without exposing the private key.
- Using
-
Encode in QR Code:
- The generated ZKP is serialized and encoded into a QR code for sharing.
- The QR code is displayed in the terminal and saved as an SVG image.
Ensure privateKeyVerification.circom
is correctly defined. Then compile:
circom privateKeyVerification.circom --r1cs --wasm --sym
Run the trusted setup for zk-SNARKs:
snarkjs groth16 setup privateKeyVerification.r1cs pot12_final.ptau circuit_final.zkey
Export the verification key:
snarkjs zkey export verificationkey circuit_final.zkey verification_key.json
Run the script to generate the ZKP and encode it in a QR code:
node zkk.js <BitcoinPrivateKeyWIF>
Console Output:
Validating and deriving public key...
Public Key: 02c2977508521f90683cae95a21824b89e5ee4604869c5e383cb85cdd4c2148c00
Address: 19cf4bxogLyzo3yCEedyLq3nwdy6r43RsF
Generating ZKP...
ZKP Generated Successfully.
QR Code saved as zkp_qr.svg
Generated QR Code (in Terminal):
█████████████████████████████
████ ▄▄▄▄▄ █▄▀█▄▄▄ ▄▄▄▄▄ ████
████ █ █ █▀▄ ▄▄▄ █ █ ████
████ █▄▄▄█ █▄▀▄▀▄█ █▄▄▄█ ████
████▄▄▄▄▄▄▄█▄█▄█▄█▄▄▄▄▄▄▄████
████ ▄▄▄▄▄ ██▄▄ ▀▄▄ ▄█▄█▄████
████ █ █ █ ▀▀▄█▄▀█▀▄▀▄ ████
████ █▄▄▄█ █ ▀▄█▄▀ ▄█▀ ▄█████
████▄▄▄▄▄▄▄█▄█▄█▄▄█▄▄▄██▄████
████ ▄▄▄▄▄ ██ ▀█▄ ▄▄█ ▄▀█████
████ █ █ █▄▄▄█ ▀█ ▀▄██▀████
████ █▄▄▄█ █ ▄▄▄▄ ▀ ▄▄▄▄█████
████▄▄▄▄▄▄▄█▄▄▄▄▄█▄█▄▄▄▄▄████
█████████████████████████████
Contributions are welcome! Feel free to submit issues or pull requests.
This project is licensed under the MIT License.
Made with ❤️ by fabohax