Skip to content

Alexovate/document-verifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“„ Document Hash Verifier

A blockchain-based document verification system built with Next.js and Solana. This application allows you to generate cryptographic hashes of documents and store them immutably on the Solana blockchain for future verification.

πŸŽ₯ Watch the Build Session

Watch the full coding session where this project was built from scratch:

▢️ Watch on YouTube: Building a Document Verifier on Solana Blockchain

Document Hash Verifier

🌟 Features

  • πŸ“€ Document Upload: Drag-and-drop or browse to upload documents (PDF, PNG, JPG, DOCX)
  • πŸ” SHA-256 Hashing: Generates cryptographically secure hashes of your documents
  • ⛓️ Blockchain Storage: Stores document hashes on Solana for immutable record-keeping
  • βœ… Document Verification: Verify document authenticity against blockchain records
  • 🎨 Modern UI: Beautiful, responsive interface built with Tailwind CSS
  • ⚑ Real-time Feedback: Loading states, success/error messages, and visual feedback

🎯 Use Cases

  • Educational Credentials: Verify authenticity of degrees and certificates
  • Legal Documents: Ensure contracts haven't been tampered with
  • Medical Records: Verify integrity of patient records
  • Intellectual Property: Timestamp and prove ownership of documents
  • Supply Chain: Authenticate product documentation

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • npm or yarn
  • Solana CLI (for local development)

Installation

  1. Clone the repository
git clone <your-repo-url>
cd document-verifier
  1. Install dependencies
npm install
  1. Install Solana CLI (if not already installed)

For macOS (using Homebrew):

brew install solana

For Linux/macOS (using official installer):

sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
  1. Start the local Solana test validator
solana-test-validator

Keep this running in a separate terminal window.

  1. Start the development server
npm run dev
  1. Open your browser Navigate to http://localhost:3000

πŸ“– How to Use

Storing a Document Hash

  1. Upload Your Document
    • Drag and drop a file or click to browse
    • Supported formats: PDF, PNG, JPG, DOCX (max 10MB)

Hash Generated

  1. Generate Hash

    • The application automatically generates a SHA-256 hash of your document
  2. Store on Blockchain

    • Click "Store on Solana" to save the hash to the blockchain
    • You'll receive an account address and transaction signature

Storage Success

  1. Save the Account Address
    • Copy and save the account address - you'll need it to verify the document later

Verifying a Document

  1. Navigate to Verification Page
    • Click "Verify a Document" from the home page

Verify Page

  1. Upload Document to Verify

    • Upload the document you want to verify
  2. Enter Account Address

    • Paste the account address you received when storing the hash
  3. Verify

    • Click "Verify Document"
    • The system will compare the document's hash with the blockchain record
    • βœ… Match: Document is authentic and unchanged
    • ❌ Mismatch: Document has been modified or is not the original

πŸ—οΈ Architecture

Tech Stack

  • Frontend: Next.js 14 (App Router), React, TypeScript
  • Styling: Tailwind CSS
  • Blockchain: Solana (@solana/web3.js)
  • Hashing: Node.js crypto module (SHA-256)
  • File Upload: Multer

Project Structure

document-verifier/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ upload/          # File upload & hash generation
β”‚   β”‚   β”œβ”€β”€ store/           # Store hash on Solana
β”‚   β”‚   └── verify/          # Verify document against blockchain
β”‚   β”œβ”€β”€ verify/              # Verification page
β”‚   └── page.tsx             # Home page
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ FileUpload.tsx       # Drag-and-drop file upload
β”‚   β”œβ”€β”€ HashDisplay.tsx      # Display generated hash
β”‚   β”œβ”€β”€ StoreButton.tsx      # Store hash on blockchain
β”‚   └── VerifyResult.tsx     # Display verification results
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ hash.ts              # SHA-256 hashing utilities
β”‚   └── solana.ts            # Solana blockchain interactions
└── public/
    └── screenshots/         # Application screenshots

πŸ”§ Configuration

Solana Network

By default, the application connects to http://localhost:8899 (local test validator).

To change the network, update the connection in lib/solana.ts:

const SOLANA_RPC_URL =
  process.env.NEXT_PUBLIC_SOLANA_RPC_URL || "http://localhost:8899";

File Upload Limits

  • Max file size: 10MB
  • Supported formats: PDF, PNG, JPG, DOCX

To modify these limits, update components/FileUpload.tsx and app/api/upload/route.ts.

πŸ›‘οΈ Security Considerations

For Production Use

This demo application uses a keypair for signing transactions. For production, consider:

  1. Wallet Integration: Use Solana wallet adapters (Phantom, Solflare, etc.)
  2. Network Security: Use Solana mainnet or devnet
  3. API Security: Add authentication and rate limiting
  4. Input Validation: Enhanced file type and content validation
  5. HTTPS: Use secure connections
  6. Audit: Security audit of smart contracts

Current Demo Setup

  • Uses local Solana test validator
  • Keypair-based transaction signing
  • File-based hash storage (for demo persistence)
  • No authentication or user accounts

πŸ” How It Works

  1. Hash Generation: When a document is uploaded, the server generates a SHA-256 hash of its contents. This creates a unique "fingerprint" of the document.

  2. Blockchain Storage: The hash is stored in a new Solana account. The account address serves as a unique identifier for this document record.

  3. Verification: To verify a document, the system:

    • Generates the hash of the uploaded document
    • Retrieves the stored hash from the blockchain using the account address
    • Compares the two hashes
    • Returns whether they match (authentic) or not (tampered/different document)
  4. Immutability: Once stored on the blockchain, the hash cannot be modified or deleted, providing a permanent, tamper-proof record.

πŸ“ API Endpoints

POST /api/upload

Upload a file and generate its SHA-256 hash.

Request: multipart/form-data with file

Response:

{
  "hash": "2fd852b8ec18dbb491c38a0ce3cdb0a45311d67d1f7b942db41a85bdb80b6604"
}

POST /api/store

Store a hash on the Solana blockchain.

Request:

{
  "hash": "2fd852b8ec18dbb491c38a0ce3cdb0a45311d67d1f7b942db41a85bdb80b6604"
}

Response:

{
  "account": "9YG6W486MfYBHAYvvCPadp3SamX5LMFPYKRYnKSeqphv",
  "signature": "5az4V6cqyBcUEWaAoKG2AG2PGe3BMeqbeq2ic9E3sqW7..."
}

POST /api/verify

Verify a document against a stored hash.

Request: multipart/form-data with file and accountAddress

Response:

{
  "match": true,
  "message": "Document is authentic",
  "hash": "2fd852b8ec18dbb491c38a0ce3cdb0a45311d67d1f7b942db41a85bdb80b6604",
  "accountAddress": "9YG6W486MfYBHAYvvCPadp3SamX5LMFPYKRYnKSeqphv"
}

πŸ§ͺ Development

Running Tests

npm test

Building for Production

npm run build
npm start

Linting

npm run lint

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“œ License

This project is open source and available under the MIT License.

πŸ”— Resources

πŸ’‘ Future Enhancements

  • Wallet adapter integration (Phantom, Solflare)
  • Batch document verification
  • Document history tracking
  • Email notifications
  • API key management
  • Advanced analytics dashboard
  • Mobile app version
  • Multi-language support

πŸ› Troubleshooting

Solana validator not starting

# Reset the validator
solana-test-validator --reset

"Failed to generate hash" error

  • Ensure file size is under 10MB
  • Check file format is supported
  • Verify Node.js version is 18+

"Failed to store hash" error

  • Ensure Solana test validator is running
  • Check connection to localhost:8899
  • Verify sufficient SOL in the keypair account

πŸ“ž Support

For issues, questions, or suggestions, please open an issue on GitHub.


Built with ❀️ using Next.js and Solana

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors