Skip to content

E-voting-Using-Blockchain/Election-Hybrid-Blockchain-pkg

Repository files navigation

Election Hybrid Blockchain

A production-grade, hybrid blockchain system designed for secure election auditing. It combines a private MySQL database for voter privacy and temporary storage with a public (anonymized) ledger for immutable verification.

🚀 Features

  • Hybrid Architecture: Private voting data (MySQL) + Public verification ledger (JSON/Decentralized).
  • Cryptographic Integrity: SHA-256 salted hashing ensures votes cannot be tampered with.
  • Privacy Preserving: Voter identities are salted and hashed before entering the public ledger.
  • Production Ready: Includes connection pooling, logging, and robust error handling.

📦 Installation

You can install this package directly from GitHub:

pip install git+https://github.com/E-voting-Using-Blockchain/Election-Hybrid-Blockchain-pkg.git

Or clone and install locally:

git clone https://github.com/E-voting-Using-Blockchain/Election-Hybrid-Blockchain-pkg.git
cd election-blockchain
pip install .

⚙️ Configuration

Automated Setup (Recommended)

Run the setup wizard to configure your .env and optionally import an existing SQL database:

python setup_wizard.py

Manual Configuration

  1. Database Setup: Ensure you have MySQL running.
  2. Environment Variables: Create a .env file in your project root:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=Blockchain
DB_POOL_SIZE=5
HASH_SALT=ProductionSecretKey_ChangeMeInRealLife!
LOG_LEVEL=INFO
PUBLIC_LEDGER_PATH=public_ledger

🏃 Usage

Running a Simulation

See examples/simulation.py for a full runner.

from election_blockchain.block.blockchain import HybridBlockchain
from election_blockchain.config import setup_logging

# 1. Setup Logging
setup_logging()

# 2. Initialize
chain = HybridBlockchain()

# 3. Authorize Node
chain.authorize_node("Official_Node_1")

# 4. Submit Vote (Private)
chain.submit_vote("voter_secure_id", "Candidate A")

# 5. Mine Block (Public)
chain.mine_block("Official_Node_1")

Checking Integrity

The system automatically checks hash integrity on load. You can also manually verify:

print(chain.is_chain_valid())

You can run this anytime you suspect external manipulation:

python maintenance_scripts/restore_public_data.py

or

restore_public_data()

📂 Project Structure

  • election_blockchain/: Main package source.
    • block/: Blockchain logic (Block, Chain).
    • database/: storage logic (MySQL Pool).
    • config.py: Configuration loader.
  • public_ledger/: Default storage for decentralized blocks.
  • examples/: Usage demonstrations.

⚠️ Security Notice

Ensure HASH_SALT is complex and kept secret. If HASH_SALT is leaked, voter anonymity could be compromised via brute-force attacks on the public ledger timestamps.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages