A revolutionary blockchain-based diary application that combines the transparency of blockchain technology with the privacy of Fully Homomorphic Encryption (FHE) to create a secure and confidential journaling experience.
OnChain Diary is a decentralized application that allows users to store their personal diary entries on the blockchain while maintaining complete privacy through Zama's FHE technology. The application stores diary content as plaintext while encrypting sensitive author information, providing a unique balance between transparency and privacy.
Traditional digital diaries face several critical challenges:
- Centralized Storage: Vulnerable to data breaches and platform shutdowns
- Privacy Concerns: Personal thoughts exposed to service providers
- Data Ownership: Users don't truly own their content
- Censorship Risk: Platforms can restrict or delete content arbitrarily
- Lack of Transparency: No verifiable proof of entry authenticity or timestamps
OnChain Diary leverages cutting-edge blockchain and encryption technologies to solve these problems:
-
Hybrid Privacy Model
- Diary content stored as readable text on blockchain for transparency
- Author identity encrypted using Zama FHE for privacy protection
- Users can prove authorship without revealing identity
-
Decentralized Storage
- Immutable storage on Ethereum blockchain
- No single point of failure
- Permanent and tamper-proof records
-
True Ownership
- Users have complete control over their entries
- Cryptographic proof of authorship
- No intermediary can access or modify content
-
Privacy-Preserving Features
- Encrypted author addresses using FHE
- Selective disclosure capabilities
- Zero-knowledge proof of ownership
- Framework: Hardhat for development and deployment
- Language: Solidity ^0.8.24
- FHE Integration: Zama FHEVM for confidential computing
- Network: Ethereum Sepolia Testnet
- Security: Built-in access control and permission management
- Framework: React 19.1.1 with TypeScript
- Build Tool: Vite for fast development and building
- Wallet Integration: RainbowKit for seamless Web3 connectivity
- Blockchain Interaction: Wagmi + Viem for type-safe Ethereum interactions
- FHE Client: Zama Relayer SDK for encrypted operations
- State Management: TanStack Query for efficient data fetching
- Styling: Custom CSS (no Tailwind as per project requirements)
- Package Manager: npm
- Testing: Mocha + Chai for comprehensive contract testing
- Code Quality: ESLint + Prettier for consistent code formatting
- Type Safety: TypeScript across the entire stack
- Gas Optimization: Hardhat Gas Reporter for cost analysis
- FHE Library: Zama's FHEVM for on-chain encrypted computations
- Encrypted Types: eaddress for author privacy
- Key Management: Integrated KMS for secure key handling
- Relayer Service: Zama Relayer for FHE operations
- Selective Transparency: Content visible, identity protected
- Cryptographic Privacy: FHE ensures author addresses remain encrypted
- No Metadata Leakage: Even viewing patterns are protected
- Immutable Records: Blockchain ensures entries cannot be altered
- Cryptographic Integrity: Every entry cryptographically signed
- Decentralized Architecture: No single point of failure
- Self-Sovereign Identity: Users control their own data
- Portable Content: Entries exist independently of any platform
- Permissionless Access: No intermediary required to access your data
- Anonymous Testimonials: Share experiences without revealing identity
- Whistleblowing: Secure platform for sensitive disclosures
- Historical Records: Immutable documentation of events
- Creative Writing: Timestamped proof of original content creation
- Comprehensive Documentation: Detailed guides and examples
- Modular Architecture: Easy to extend and customize
- Open Source: Transparent and auditable codebase
- Testing Coverage: Extensive test suite for reliability
The main contract implements a sophisticated diary system:
struct DiaryEntry {
address owner; // Public owner address
string content; // Plaintext diary content
eaddress encryptedAuthor; // FHE-encrypted author address
uint256 timestamp; // Entry creation time
bool exists; // Entry existence flag
}addEntry(): Create new diary entries with encrypted author infogetEntry(): Retrieve complete entry informationgetEntryContent(): Access only the plaintext contentgetEntryAuthor(): Get encrypted author addressgetUserEntries(): List all entries for a user
The contract leverages Zama's FHE capabilities:
- Encrypted Types: Uses
eaddressfor author privacy - Access Control: Implements FHE ACL for permission management
- External Inputs: Validates encrypted inputs with proofs
- Key Management: Automatic key handling through Zama infrastructure
- Wallet Connection: Seamless Web3 wallet integration
- Entry Creation: Intuitive form for creating diary entries
- Entry Browsing: Clean interface for viewing past entries
- Responsive Design: Works across all device types
- Encrypted Submission: Author addresses encrypted before submission
- Selective Viewing: Choose what information to reveal
- Access Management: Control who can see your entries
- Type Safety: Full TypeScript coverage
- Error Handling: Comprehensive error management
- Loading States: Smooth user experience during blockchain operations
- Offline Support: Cache management for better performance
- Node.js β₯ 20.0.0
- npm β₯ 7.0.0
- MetaMask or compatible Web3 wallet
- Access to Ethereum Sepolia testnet
-
Clone the Repository
git clone https://github.com/yourusername/Dairy.git cd Dairy -
Install Dependencies
npm install cd ui && npm install
-
Environment Setup
# Copy environment template cp .env.example .env # Configure your environment variables PRIVATE_KEY=your_private_key_here INFURA_API_KEY=your_infura_key_here ETHERSCAN_API_KEY=your_etherscan_key_here
-
Compile Contracts
npm run compile
-
Run Tests
npm test npm run test:sepolia # For Sepolia testnet
-
Deploy Contracts
npm run deploy:sepolia
-
Start Frontend
cd ui npm run dev
# Development workflow
npm run clean # Clean artifacts and cache
npm run compile # Compile smart contracts
npm run test # Run all tests
npm run deploy:sepolia # Deploy to Sepolia
cd ui && npm run dev # Start frontend
# Code quality
npm run lint # Run all linters
npm run prettier:write # Format code- Connect Wallet: Use the Connect Wallet button to link your Web3 wallet
- Write Content: Enter your diary content in the text area
- Submit Entry: Click submit to create your encrypted entry
- Confirm Transaction: Approve the blockchain transaction
- View Entry: Your entry will appear in the entries list
- View All Entries: Browse all your diary entries in chronological order
- Read Content: Click on any entry to view its full content
- Verify Ownership: Use encrypted author verification to prove ownership
- Author Encryption: Your identity is automatically encrypted when creating entries
- Access Control: Manage who can view your encrypted information
- Selective Disclosure: Choose what information to make public
The project includes comprehensive testing suites:
npm test # Local hardhat network tests
npm run test:sepolia # Sepolia testnet integration tests- Unit Tests: Individual function testing
- Integration Tests: End-to-end workflow testing
- FHE Tests: Encryption/decryption functionality
- Access Control Tests: Permission system validation
test/OnChainDiary.ts: Main contract functionalitytest/FHECounter.ts: FHE operations testingtest/OnChainDiarySepolia.ts: Testnet integration
-
Configure Environment
# Set up your .env file with: PRIVATE_KEY=your_deployment_private_key INFURA_API_KEY=your_infura_api_key ETHERSCAN_API_KEY=your_etherscan_api_key -
Deploy Contracts
npm run deploy:sepolia
-
Verify Contracts
npx hardhat verify --network sepolia <contract_address>
After deployment, contracts will be deployed to:
- OnChainDiary: [Contract Address on Sepolia]
- FHECounter: [Contract Address on Sepolia]
Dairy/
βββ contracts/ # Smart contracts
β βββ OnChainDiary.sol # Main diary contract
β βββ FHECounter.sol # Example FHE contract
βββ deploy/ # Deployment scripts
βββ tasks/ # Hardhat tasks
βββ test/ # Contract tests
βββ ui/ # React frontend
β βββ src/
β β βββ components/ # React components
β β βββ hooks/ # Custom React hooks
β β βββ config/ # Configuration files
βββ docs/ # Documentation
βββ CLAUDE.md # Project instructions
-
Smart Contract Changes
# Edit contracts in contracts/ # Add tests in test/ # Run tests: npm test
-
Frontend Changes
# Edit components in ui/src/components/ # Update hooks in ui/src/hooks/ # Test locally: cd ui && npm run dev
-
Deployment Updates
# Update deployment scripts in deploy/ # Test deployment: npm run deploy:sepolia
- Access Control: Comprehensive permission system
- Input Validation: All user inputs validated
- Overflow Protection: Safe math operations
- Reentrancy Protection: Follows security best practices
- Key Management: Secure key handling through Zama KMS
- Encryption Validation: All encrypted inputs verified
- Access Control Lists: Fine-grained permission management
- Proof Verification: Cryptographic proof validation
- Wallet Security: Secure Web3 wallet integration
- Transaction Validation: All transactions validated before submission
- Error Handling: Comprehensive error management
- Data Sanitization: All user inputs sanitized
Contract Deployment Fails
# Check your private key and network configuration
# Ensure you have sufficient ETH for gas
# Verify contract compilation: npm run compileFrontend Connection Issues
# Check MetaMask is connected to Sepolia
# Verify contract addresses in config
# Check console for error messagesFHE Operations Failing
# Verify Zama relayer configuration
# Check encrypted input validation
# Ensure proper ACL permissions- GitHub Issues: Report bugs and feature requests
- Documentation: Check the comprehensive docs in
/docs - Community: Join the Zama community forums
- Discord: Connect with other developers
We welcome contributions from the community!
-
Fork the Repository
git fork https://github.com/yourusername/Dairy.git
-
Create Feature Branch
git checkout -b feature/your-feature-name
-
Make Changes
- Follow existing code style
- Add tests for new features
- Update documentation
-
Test Changes
npm run lint npm test npm run test:sepolia -
Submit Pull Request
- Clear description of changes
- Reference any related issues
- Include test coverage
- Code Style: Follow ESLint and Prettier configurations
- Documentation: Update relevant documentation
- Testing: Maintain >90% test coverage
- Security: Follow security best practices
- Performance: Consider gas optimization
- β Basic diary functionality
- β FHE integration for author privacy
- β Web3 frontend integration
- β Sepolia testnet deployment
- π Content encryption options
- π Advanced access control
- π Selective content disclosure
- π Privacy-preserving search
- π Shared diary spaces
- π Collaborative entries
- π Anonymous commenting system
- π Community verification
- π Cross-chain compatibility
- π IPFS integration for large content
- π Mobile application
- π AI-powered insights (privacy-preserving)
- π Enterprise deployment options
- π Custom branding
- π Advanced analytics
- π Compliance features
- π Zero-knowledge proofs for content verification
- π Time-locked entries
- π Decentralized governance
- π NFT integration for special entries
- π Multi-chain deployment
- Entry Creation: ~150,000 gas
- Entry Retrieval: ~30,000 gas (view function)
- Batch Operations: Optimized for multiple entries
- Encryption Strength: Military-grade FHE
- Key Security: Threshold cryptography
- Smart Contract Audits: Planned for mainnet release
- Daily Journaling: Private thoughts with timestamp proof
- Memory Preservation: Immutable family histories
- Goal Tracking: Confidential progress records
- Health Monitoring: Private health journey documentation
- Research Notes: Timestamped research discoveries
- Legal Documentation: Immutable legal records
- Journalism: Anonymous source protection
- Whistleblowing: Secure disclosure platform
- Content Creation: Proof of original authorship
- Intellectual Property: Timestamped idea documentation
- Collaborative Writing: Shared creative spaces
- Publishing: Decentralized content distribution
- Zama FHE Documentation: Complete FHE development guide
- Ethereum Development: Hardhat and Solidity tutorials
- React Development: Modern React patterns and hooks
- Web3 Integration: Wallet connectivity and blockchain interaction
- Smart Contract Patterns: Reusable Solidity patterns
- FHE Operations: Encryption and decryption examples
- Frontend Integration: Web3 React components
- Testing Strategies: Comprehensive testing approaches
This project is licensed under the BSD-3-Clause-Clear License. See the LICENSE file for details.
- β Commercial use allowed
- β Modification allowed
- β Distribution allowed
- β Patent use prohibited
- β Liability and warranty disclaimed
- Zama: For pioneering FHE technology and FHEVM
- Ethereum Foundation: For blockchain infrastructure
- Hardhat Team: For excellent development tools
- React Team: For the robust frontend framework
- All developers who contribute to this open-source project
- Security researchers who help identify vulnerabilities
- Documentation contributors who improve clarity
- Beta testers who provide valuable feedback
- The broader Web3 community for inspiration and support
- Privacy advocates pushing for better digital rights
- Open-source maintainers whose work we build upon
- GitHub: Project Repository
- Issues: Bug Reports & Feature Requests
- Discussions: Community Discussions
- Discord: Join our developer community
- Twitter: Follow for project updates
- Medium: Read our technical blog posts
- YouTube: Watch development tutorials
For enterprise inquiries, custom development, or security audits, please contact our team through the appropriate channels listed above.
Built with β€οΈ using Zama FHE, Ethereum, and React
OnChain Diary - Where privacy meets transparency in the digital age