FileHashStorage is a complete decentralized application (dApp) that enables storing and verifying document authenticity using Ethereum blockchain technology. The system combines smart contracts developed with Foundry and a modern web interface built with Next.js.
In today's world, verifying the authenticity of digital documents is a constant challenge. This project offers a blockchain solution that enables:
- Immutability: Once a document is registered, its hash cannot be modified
- Traceability: Each document includes a timestamp and verifiable digital signature
- Transparency: Anyone can verify the authenticity of a document
- Decentralization: Does not depend on a central authority
- Academic Credential Verification: Universities can register diploma hashes for employers to verify authenticity
- Legal Document Certification: Notaries can register contracts and legal documents with immutable timestamps
- Intellectual Property Protection: Artists and creators can register their works to prove authorship
- Corporate Document Auditing: Companies can maintain an immutable record of important documents
- Identity Verification: Identity documents can be verified without revealing sensitive information
The project is structured into two main components:
alucart2005/
├── sc/ # Smart Contracts (Foundry)
│ ├── src/ # Solidity contracts
│ ├── test/ # Contract tests
│ └── script/ # Deployment scripts
└── dapp/ # Frontend Application (Next.js)
├── app/ # Pages and routes
├── components/ # React components
├── contexts/ # React contexts
└── lib/ # Utilities and configuration
Before starting, ensure you have installed:
- Node.js (v16 or higher) - Download Node.js
- Foundry - Framework for smart contract development
- Git - Version control
- Anvil (included with Foundry) - Local Ethereum network for development
If you don't have Foundry installed yet, run:
curl -L https://foundry.paradigm.xyz | bash
foundryupFor Windows (using Git Bash or PowerShell):
# Download and install from: https://github.com/foundry-rs/foundry/releases
# Or use chocolatey:
choco install foundrygit clone https://github.com/alucart2005/alucart2005.git
cd alucart2005# Navigate to contracts directory
cd sc
# Install dependencies (forge-std)
forge install
# Compile contracts
forge build
# Run tests
forge test# Navigate to dApp directory
cd ../dapp
# Install Node.js dependencies
npm install
# Verify Anvil is running
npm run check-anvilIn a separate terminal, start Anvil:
anvilThis will start a local blockchain at http://localhost:8545 with 10 pre-funded accounts for testing.
The contract is automatically deployed when you start the application, but you can also do it manually:
cd sc
forge script script/FileHashStorage.s.sol:FileHashStorageScript --rpc-url http://localhost:8545 --broadcastAfter deployment, copy the contract address and update the configuration file:
# Edit dapp/config/contract-config.json
{
"address": "0xYOUR_CONTRACT_ADDRESS_HERE",
"chainId": 31337
}You can create a .env.local file in the dapp/ directory for additional configuration:
NEXT_PUBLIC_RPC_URL=http://localhost:8545
NEXT_PUBLIC_CHAIN_ID=31337# From the dapp/ directory
npm run devThe application will be available at http://localhost:3000
- Connect Wallet: Connect your MetaMask wallet or use one of Anvil's accounts
- Upload Document: Select a file and calculate its hash
- Sign and Register: Sign the hash with your wallet and register it on the blockchain
- Verify Document: Verify the authenticity of any registered document
Situation: An employer needs to register an employment contract to prove its existence on a specific date.
Steps:
-
Prepare the document:
# The document "employment_contract_2024.pdf" is ready to be registered -
From the web interface:
- Connect your wallet (employer's account)
- Upload the
employment_contract_2024.pdffile - The system automatically calculates the SHA-256 hash
- Sign the hash with your wallet
- Confirm the transaction to register the document
-
Subsequent verification:
- Anyone can verify the document by uploading the same file
- The system will compare the hash and display:
- ✅ If the document is authentic
- 📅 Registration date and time
- 👤 Wallet address that registered it
Benefit: The employer has immutable proof that the contract existed on a specific date, useful in labor disputes.
Situation: A university wants to issue blockchain-verifiable diplomas.
Process:
-
University registers the diploma:
// Diploma hash: 0x7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730 // Timestamp: 1704067200 (January 1, 2024) // Signature: University's cryptographic signature
-
Graduate verifies their diploma:
- The graduate uploads their diploma PDF file
- The system verifies that the hash matches
- Shows registration information (date, institution)
-
Employer verifies authenticity:
- The employer receives the candidate's diploma
- Uploads it to the verification system
- Gets immediate confirmation of authenticity
Benefit: Eliminates the need to contact the university to verify diplomas, saving time and resources.
Situation: A photographer wants to protect their photographs before publishing them.
Implementation:
-
Original work registration:
# The photographer registers the hash of "original_photo.jpg" # This creates an immutable record that the photo existed on a specific date
-
In case of plagiarism:
- The photographer can prove they registered the work earlier
- The blockchain timestamp is legal proof of authorship
- The cryptographic signature confirms the author's identity
Benefit: Legal proof of authorship without the need for expensive patent office registrations.
Situation: A company needs to maintain an audited record of financial documents.
Flow:
-
Monthly financial statement registration:
// Each month, the CFO registers: // - Balance sheet // - Income statement // - Cash flow statement
-
Auditor verification:
- Auditors can verify that documents have not been altered
- The timestamp guarantees temporal sequence
- The CFO's signature is verifiable
-
Regulatory compliance:
- Authorities can verify documents without access to internal systems
- Transparency without compromising privacy
Benefit: Improved regulatory compliance and more efficient auditing processes.
Situation: An institution needs to verify identity documents without storing personal data.
Solution:
-
User registers their document:
- Uploads a copy of their identity document
- The system registers only the hash (not personal data)
- The user signs with their wallet
-
Institution verification:
- The institution receives the user's document
- Calculates the hash and verifies it on the blockchain
- Confirms authenticity without storing sensitive data
Benefit: Improved privacy (only hash is stored) and fast verification.
cd sc
forge testforge test -vvv # Shows detailed logsforge test --match-test test_StoreDocumentHash# Compile contracts
forge build
# Run tests
forge test
# Deploy to local network
forge script script/FileHashStorage.s.sol:FileHashStorageScript --rpc-url http://localhost:8545 --broadcast
# Verify contract on blockchain explorer
forge verify-contract <ADDRESS> FileHashStorage --chain-id 1# Development
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Check if Anvil is running
npm run check-anvil
# Deploy contract manually
npm run deployStores a document hash with its timestamp and signature.
Parameters:
hash: Document hash (SHA-256, Keccak-256, etc.)timestamp: Registration date (Unix timestamp)signature: ECDSA signature of the hash (65 bytes)
Returns: bool - true if storage was successful
Usage example:
bytes32 docHash = keccak256("my_document.pdf");
uint256 timestamp = block.timestamp;
bytes memory signature = /* hash signature */;
fileHashStorage.storeDocumentHash(docHash, timestamp, signature);Verifies that a signature corresponds to a specific document and signer.
Parameters:
hash: Document hash to verifysigner: Expected signer addresssignature: Signature to verify
Returns: bool - true if the signature is valid
Gets all information from a registered document.
Returns:
bytes32: Document hashuint256: Registration timestampaddress: Signer addressbytes: Document signature
Checks if a document exists in the system.
Returns: bool - true if the document is registered
Emitted when a document is successfully registered.
Contributions are welcome! This project is part of Codecrypto Academy learning materials.
-
Fork the repository
git clone https://github.com/alucart2005/alucart2005.git
-
Create a feature branch
git checkout -b feature/my-new-feature
-
Make your changes
- Follow Solidity best practices
- Write tests for new features
- Update documentation
-
Run tests
cd sc && forge test cd ../dapp && npm run lint
-
Commit your changes
git commit -m "feat: add new verification feature" -
Push to your branch
git push origin feature/my-new-feature
-
Open a Pull Request
- Solidity: Follow Solidity best practices
- Testing: Write comprehensive tests for all new features
- Documentation: Update documentation for any API changes
- Clean Code: Keep code readable and well-commented
Use descriptive commit messages following the format:
type: brief description
Detailed description (optional)
Common types:
feat: New featurefix: Bug fixdocs: Documentation changestest: Add or modify testsrefactor: Code refactoring
This project is licensed under the MIT License - see the LICENSE file for details.
- GitHub: @alucart2005
- Project: Part of Codecrypto Academy
This project uses the following technologies and tools:
- Foundry - Smart contract development framework
- Next.js - React framework for production
- Ethers.js - Library for interacting with Ethereum
- Anvil - Ethereum client for local development
Note: This project is designed for educational and practice purposes. For production use, ensure you perform complete security audits and consider legal and regulatory implications.
