Skip to content

jasonyi33/helixchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

50 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧬 HelixChain - Genomic Privacy DApp

Privacy-preserving genetic trait verification using zero-knowledge proofs on Midnight blockchain

MIT License Node.js Version TypeScript Midnight Blockchain

πŸ“Œ Executive Summary

HelixChain revolutionizes genomic data privacy in healthcare by enabling patients to prove specific genetic traits without revealing their complete genomic sequence. Built on the Midnight blockchain, our platform uses zero-knowledge proofs to create a trust-minimized system where medical institutions can verify genetic predispositions while preserving patient privacy.

🎯 Key Features

  • Zero-Knowledge Proof Generation: Prove genetic traits (BRCA1/2, CYP2D6) without revealing raw genomic data
  • IPFS Integration: Decentralized storage for encrypted genomic sequences
  • Multi-Role Access: Separate portals for patients, doctors, and researchers
  • Real-Time Verification: WebSocket-powered live proof status updates
  • Privacy-First Architecture: End-to-end encryption with patient-controlled access
  • Aggregate Analytics: Anonymous research data without individual identification

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Frontend Layer                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  React + TypeScript β”‚ Vite β”‚ TailwindCSS β”‚ Framer Motion   β”‚
β”‚  β”œβ”€β”€ Patient Portal: Genome upload, proof generation        β”‚
β”‚  β”œβ”€β”€ Doctor Portal: Verification requests, patient lookup   β”‚
β”‚  └── Researcher Portal: Aggregate statistics, cohort data   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                       Backend Layer                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Node.js + Express β”‚ TypeScript β”‚ PostgreSQL β”‚ Redis       β”‚
β”‚  β”œβ”€β”€ Auth Service: JWT authentication, role management      β”‚
β”‚  β”œβ”€β”€ Proof Service: ZK proof generation queue (Bull)        β”‚
β”‚  β”œβ”€β”€ Genome Service: Encryption, IPFS storage              β”‚
β”‚  └── Verification Service: Blockchain interaction          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    Blockchain Layer                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Midnight Network β”‚ Compact Smart Contracts β”‚ ProofSDK      β”‚
β”‚  β”œβ”€β”€ GenomicVerifier Contract: On-chain verification        β”‚
β”‚  β”œβ”€β”€ ZK Circuits: BRCA1, BRCA2, CYP2D6 trait proofs       β”‚
β”‚  └── Event System: Blockchain monitoring & notifications    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                      Storage Layer                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  IPFS (Pinata) β”‚ PostgreSQL β”‚ Redis Cache                  β”‚
β”‚  β”œβ”€β”€ Encrypted genome storage on IPFS                      β”‚
β”‚  β”œβ”€β”€ Metadata and user data in PostgreSQL                 β”‚
β”‚  └── Proof generation queue in Redis                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start Guide

Prerequisites

  • Node.js 20 LTS or higher
  • Docker Desktop for containerized services
  • PostgreSQL 15+ (or use Docker)
  • Redis 7+ (or use Docker)
  • Lace Wallet for Midnight testnet interaction

Installation

  1. Clone the repository
git clone https://github.com/jasonyi33/midnight_hackathon.git
cd midnight_hackathon
  1. Install dependencies
# Install root dependencies
npm install

# Install backend dependencies
cd backend && npm install

# Install frontend dependencies
cd ../frontend && npm install

# Install contract dependencies
cd ../contracts && npm install

# Return to root
cd ..
  1. Set up environment variables

Create .env files in each directory:

Backend (.env)

# Database
DATABASE_URL=postgresql://user:password@localhost:5432/genomic_privacy
REDIS_URL=redis://localhost:6379

# Authentication
JWT_SECRET=your-secure-jwt-secret-key
JWT_EXPIRY=7d

# Blockchain
MIDNIGHT_RPC_URL=https://testnet.midnight.network/rpc
CONTRACT_ADDRESS=midnight_1758943732128_cwnj0p
MOCK_PROOFS=true

# IPFS (Pinata)
PINATA_API_KEY=your-pinata-api-key
PINATA_SECRET_KEY=your-pinata-secret-key

# Server
PORT=3000
NODE_ENV=development

Frontend (.env)

VITE_API_URL=http://localhost:3000
VITE_WS_URL=ws://localhost:3000
VITE_CONTRACT_ADDRESS=midnight_1758943732128_cwnj0p
VITE_MIDNIGHT_NETWORK=testnet

Contracts (.env)

MIDNIGHT_NETWORK=testnet
MIDNIGHT_RPC_URL=https://testnet.midnight.network/rpc
DEPLOYER_PRIVATE_KEY=your-testnet-private-key
  1. Start infrastructure services
# Using Docker Compose (recommended)
docker-compose up -d

# Or manually start PostgreSQL and Redis
# PostgreSQL on port 5432
# Redis on port 6379
  1. Run database migrations
cd backend
npm run migrate:up
  1. Seed demo data (optional)
cd backend
npm run seed:demo

πŸƒ Running the Application

Development Mode

Start all services in separate terminals:

# Terminal 1: Backend API
cd backend
npm run dev
# Runs on http://localhost:3000

# Terminal 2: Frontend
cd frontend
npm run dev
# Runs on http://localhost:5173

# Terminal 3: Proof Worker (optional)
cd backend
npm run queue:worker

# Terminal 4: Contract compilation watcher (optional)
cd contracts
npm run build:watch

Production Build

# Build backend
cd backend
npm run build

# Build frontend
cd frontend
npm run build

# Build contracts
cd contracts
npm run build

# Start production server
cd backend
npm start

πŸ“Š API Documentation

Authentication Endpoints

Method Endpoint Description
POST /api/auth/register Register new user
POST /api/auth/login User login
POST /api/auth/refresh Refresh JWT token
GET /api/auth/profile Get user profile
POST /api/auth/logout Logout user

Genome Management

Method Endpoint Description
POST /api/genome/upload Upload encrypted genome
GET /api/genome/:id Retrieve genome metadata
DELETE /api/genome/:id Delete genome data
GET /api/genome/user/:userId Get user's genomes

Proof Generation

Method Endpoint Description
POST /api/proof/generate Generate ZK proof
GET /api/proof/:id/status Check proof status
GET /api/proof/history Get proof history
POST /api/proof/verify Verify proof on-chain

Verification Requests

Method Endpoint Description
POST /api/verification/request Create verification request
GET /api/verification/pending Get pending requests
POST /api/verification/:id/approve Approve request
POST /api/verification/:id/deny Deny request

Research Analytics

Method Endpoint Description
GET /api/research/statistics Get aggregate statistics
POST /api/research/cohort Build research cohort
GET /api/research/traits/:trait Get trait distribution

πŸ§ͺ Testing

Run All Tests

# Backend tests
cd backend
npm test

# Frontend tests
cd frontend
npm test

# Contract tests
cd contracts
npm test

# End-to-end tests
cd tests
npm test

Test Coverage

# Generate coverage report
cd backend
npm run test:coverage

# View coverage
open coverage/index.html

Integration Tests

# Run integration test suite
cd tests
npm run test:integration

πŸ—οΈ Project Structure

midnight_hackathon/
β”œβ”€β”€ πŸ“ frontend/                 # React frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/                # Application core
β”‚   β”‚   β”‚   β”œβ”€β”€ pages/          # Page components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ patient/    # Patient portal pages
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ doctor/     # Doctor portal pages
β”‚   β”‚   β”‚   β”‚   └── researcher/ # Researcher portal pages
β”‚   β”‚   β”‚   β”œβ”€β”€ components/     # Reusable components
β”‚   β”‚   β”‚   β”œβ”€β”€ hooks/          # Custom React hooks
β”‚   β”‚   β”‚   β”œβ”€β”€ services/       # API service layer
β”‚   β”‚   β”‚   └── stores/         # Zustand state stores
β”‚   β”‚   β”œβ”€β”€ ui/                 # UI components
β”‚   β”‚   └── utils/              # Utility functions
β”‚   └── public/                 # Static assets
β”‚
β”œβ”€β”€ πŸ“ backend/                  # Node.js backend API
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ auth/               # Authentication module
β”‚   β”‚   β”œβ”€β”€ genome/             # Genome management
β”‚   β”‚   β”œβ”€β”€ proof/              # Proof generation
β”‚   β”‚   β”œβ”€β”€ verification/       # Verification service
β”‚   β”‚   β”œβ”€β”€ blockchain/         # Blockchain integration
β”‚   β”‚   β”œβ”€β”€ ipfs/              # IPFS storage service
β”‚   β”‚   β”œβ”€β”€ websocket/         # WebSocket handlers
β”‚   β”‚   β”œβ”€β”€ middleware/        # Express middleware
β”‚   β”‚   └── utils/             # Utility functions
β”‚   β”œβ”€β”€ migrations/            # Database migrations
β”‚   └── scripts/               # Utility scripts
β”‚
β”œβ”€β”€ πŸ“ contracts/               # Midnight smart contracts
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ genomic_verifier.compact  # Main contract
β”‚   β”‚   β”œβ”€β”€ circuits/          # ZK circuits
β”‚   β”‚   β”‚   β”œβ”€β”€ brca1.circom
β”‚   β”‚   β”‚   β”œβ”€β”€ brca2.circom
β”‚   β”‚   β”‚   └── cyp2d6.circom
β”‚   β”‚   └── sdk/              # ProofSDK wrapper
β”‚   β”œβ”€β”€ scripts/              # Deployment scripts
β”‚   └── build/                # Compiled contracts
β”‚
β”œβ”€β”€ πŸ“ tests/                  # Test suites
β”‚   β”œβ”€β”€ e2e/                  # End-to-end tests
β”‚   β”œβ”€β”€ integration/          # Integration tests
β”‚   └── fixtures/             # Test data
β”‚
β”œβ”€β”€ πŸ“ docs/                   # Documentation
β”œβ”€β”€ docker-compose.yml         # Docker configuration
β”œβ”€β”€ package.json              # Root package file
└── README.md                 # This file

πŸ” Security Considerations

Data Protection

  • End-to-end encryption for all genomic data
  • Patient-controlled access with granular permissions
  • Zero-knowledge proofs prevent data leakage
  • IPFS encryption before decentralized storage

Authentication & Authorization

  • JWT-based authentication with refresh tokens
  • Role-based access control (RBAC)
  • Multi-factor authentication support
  • Session management with Redis

Smart Contract Security

  • Audited circuits for ZK proofs
  • Formal verification of contract logic
  • Rate limiting on proof generation
  • Emergency pause functionality

🚒 Deployment

Docker Deployment

# Build and run with Docker Compose
docker-compose -f docker-compose.prod.yml up -d

# Check service status
docker-compose ps

# View logs
docker-compose logs -f

Manual Deployment

  1. Deploy contracts
cd contracts
npm run deploy:mainnet
  1. Deploy backend
cd backend
npm run build
pm2 start dist/index.js --name genomic-api
  1. Deploy frontend
cd frontend
npm run build
# Serve dist folder with nginx/apache

Cloud Deployment (AWS/GCP/Azure)

See DEPLOYMENT.md for detailed cloud deployment instructions.

πŸ“ˆ Performance Optimization

Benchmarks

  • Proof Generation: 5-10s (mock), 10-30s (production)
  • API Response Time: <200ms (cached), <2s (computed)
  • UI Rendering: 60fps with glass morphism effects
  • Concurrent Users: 100+ simultaneous connections
  • Database Queries: <50ms average response time

Optimization Strategies

  • Redis caching for frequent queries
  • Bull queue for async proof generation
  • Database indexing on critical paths
  • CDN deployment for static assets
  • WebSocket connection pooling

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Workflow

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open Pull Request

Code Style

  • ESLint for code linting
  • Prettier for code formatting
  • TypeScript strict mode enabled
  • Conventional Commits for commit messages

πŸ“š Additional Resources

πŸ† Hackathon Achievements

MLH Midnight Hackathon Results

  • Technology Excellence: Real ZK proofs + IPFS integration
  • Innovation: Novel genomic privacy application
  • Execution: Complete multi-role user journeys
  • Documentation: Comprehensive technical guides
  • Business Value: Clear healthcare market need

πŸ“ž Support

Getting Help

Common Issues

  • Wallet Connection: Ensure Lace wallet is installed
  • Contract Compilation: Check compactc binary path
  • Database Connection: Verify PostgreSQL is running
  • Redis Connection: Ensure Redis server is active

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Midnight Network for blockchain infrastructure
  • MLH for hackathon organization
  • IPFS/Pinata for decentralized storage
  • OpenZeppelin for security patterns
  • Our amazing team for 48 hours of dedication

Built with ❀️ for the MLH Midnight Hackathon

Revolutionizing genomic privacy in healthcare through zero-knowledge proofs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors