Skip to content

πŸ” Zero Knowledge Proof Identity & Access Management system built with Python, Ethereum, and FastAPI. Combines blockchain security with privacy-preserving authentication.

Notifications You must be signed in to change notification settings

AshenWijesingha/zkp_blockchain_iam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Zero Knowledge Proof Blockchain IAM Service

A secure Identity and Access Management (IAM) service that combines Zero Knowledge Proofs (ZKP) with blockchain technology for enhanced security and privacy.

Features

  • πŸ” Zero Knowledge Proof authentication
  • ⛓️ Blockchain-based identity storage
  • πŸ”‘ Secure claim management
  • 🌐 RESTful API interface
  • πŸ“ Smart contract integration
  • πŸ”„ Real-time identity verification

Table of Contents

Prerequisites

  • Python 3.8 or higher
  • Node.js 14+ and npm (for smart contract deployment)
  • Ethereum node (local or remote)
  • Windows, Linux, or macOS

Installation

  1. Clone the repository:
git clone https://github.com/AshenWijesingha/zkp_blockchain_iam.git
cd zkp-blockchain-iam
  1. Create and activate virtual environment:

For Windows:

python -m venv venv
venv\Scripts\activate.bat

For Linux/MacOS:

python -m venv venv
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Install Ethereum development dependencies:
npm install -g truffle
npm install @openzeppelin/contracts

Project Structure

zkp_blockchain_iam/
β”œβ”€β”€ contracts/
β”‚   └── IdentityContract.sol      # Ethereum smart contract
β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ zkp.py                    # ZKP implementation
β”‚   β”œβ”€β”€ blockchain.py             # Blockchain interactions
β”‚   └── identity.py               # Identity management
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── routes.py                 # API endpoints
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ test_zkp.py
β”‚   β”œβ”€β”€ test_blockchain.py
β”‚   └── test_identity.py
β”œβ”€β”€ config/
β”‚   └── config.yaml               # Configuration file
β”œβ”€β”€ main.py                       # Application entry point
β”œβ”€β”€ requirements.txt              # Python dependencies
β”œβ”€β”€ truffle-config.js             # Truffle configuration
└── README.md                     # This file

Configuration

  1. Create a config.yaml file in the config directory:
blockchain:
  node_url: "http://localhost:8545"
  contract_address: "0x..."  # Your deployed contract address
  gas_limit: 2000000
  
api:
  host: "0.0.0.0"
  port: 8000
  debug: false

security:
  min_password_length: 12
  max_failed_attempts: 3
  lockout_duration: 300  # seconds
  1. Set environment variables:
export ETHEREUM_PRIVATE_KEY="your-private-key"
export SECRET_KEY="your-secret-key"

Usage

  1. Start the API server:
python main.py
  1. Create a new identity:
curl -X POST http://localhost:8000/identity/create \
  -H "Content-Type: application/json" \
  -d '{"address": "0x...", "secret": "user-secret"}'
  1. Verify an identity:
curl -X POST http://localhost:8000/identity/verify \
  -H "Content-Type: application/json" \
  -d '{"address": "0x...", "secret": "user-secret", "blinding_factor": "..."}'

API Documentation

Endpoints

POST /identity/create

Create a new identity with ZKP commitment.

Request:

{
  "address": "string",
  "secret": "string"
}

Response:

{
  "status": "success",
  "address": "string"
}

POST /identity/verify

Verify an identity using ZKP.

Request:

{
  "address": "string",
  "secret": "string",
  "blinding_factor": "string"
}

Response:

{
  "status": "success",
  "valid": boolean
}

Smart Contract Deployment

  1. Configure Truffle:
// truffle-config.js
module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*"
    }
  },
  compilers: {
    solc: {
      version: "0.8.0"
    }
  }
};
  1. Deploy the contract:
truffle migrate --network development

Testing

Run the test suite:

python -m pytest tests/

Run specific tests:

python -m pytest tests/test_zkp.py

Security Considerations

  • Always use secure communication channels (HTTPS)
  • Regularly update dependencies
  • Monitor smart contract events
  • Implement rate limiting
  • Use secure key storage
  • Regular security audits
  • Implement proper access controls

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

MIT License - see LICENSE file for details

About

πŸ” Zero Knowledge Proof Identity & Access Management system built with Python, Ethereum, and FastAPI. Combines blockchain security with privacy-preserving authentication.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published