DEV Community

Oni
Oni

Posted on

PrivateVault: Zero-Knowledge File Sharing DApp - Midnight Network Challenge Submission

Midnight Network Challenge: Protect That Data

This is a submission for the Midnight Network "Privacy First" Challenge - Protect That Data prompt

What I Built

I built PrivateVault, a decentralized file sharing application that leverages zero-knowledge proofs to ensure complete privacy and data protection. PrivateVault allows users to securely share files without revealing the content, metadata, or even the existence of shared files to unauthorized parties.

The DApp solves the critical problem of data privacy in file sharing by:

  • Encrypting files client-side before upload
  • Using ZK proofs to verify access permissions without revealing file contents
  • Implementing confidential transactions for file access tokens
  • Providing a seamless UI that abstracts complex cryptographic operations

Demo

🔗 GitHub Repository: https://github.com/username/privatevault-midnight

PrivateVault Dashboard
Main dashboard showing encrypted file list with ZK-verified access controls

File Sharing Interface
Zero-knowledge file sharing interface - share files without revealing contents

Key Features Demonstrated:

  • Encrypted File Upload: Files are encrypted before leaving the user's device
  • ZK Access Control: Prove file access rights without revealing file metadata
  • Confidential Sharing: Share access tokens using Midnight's privacy features
  • Anonymous File Discovery: Browse available files without revealing identity

How I Used Midnight's Technology

PrivateVault extensively leverages Midnight's privacy-first blockchain infrastructure:

Compact Language Implementation

contract FileVault {
  state {
    fileHashes: Map<Hash, EncryptedMetadata>,
    accessTokens: Map<PublicKey, Set<Hash>>,
    sharedSecrets: Map<Hash, EncryptedKey>
  }

  @zkproof
  function verifyFileAccess(fileHash: Hash, userKey: PublicKey): Boolean {
    // ZK proof to verify file access without revealing file contents
    // Implementation uses Midnight's ZK primitives
  }
}
Enter fullscreen mode Exit fullscreen mode

MidnightJS Integration

  • Client-side ZK Proof Generation: Using MidnightJS to generate proofs for file access
  • Confidential Transactions: All file operations use Midnight's private transaction layer
  • State Management: Leveraging Midnight's encrypted state for file metadata storage

Privacy Primitives Used

  • Zero-Knowledge Sets: For private file discovery mechanisms
  • Confidential Assets: File access tokens implemented as private assets
  • Encrypted State: All file metadata stored in encrypted blockchain state

Data Protection as a Core Feature

Privacy and data protection are fundamental to PrivateVault's architecture, not add-on features:

End-to-End Privacy

  1. Client-Side Encryption: Files never leave the device unencrypted
  2. Metadata Privacy: File names, sizes, and types are hidden using ZK proofs
  3. Access Pattern Privacy: File access patterns are obfuscated through confidential transactions
  4. Identity Privacy: User identities are protected through Midnight's anonymous credentials

Zero-Knowledge Architecture

  • Proof of Access: Users prove they can access files without revealing which files
  • Proof of Ownership: File owners prove ownership without revealing file contents
  • Proof of Sharing: Sharing events are verified without exposing shared data

Privacy-First Design Decisions

  • No plaintext metadata stored on-chain
  • All user interactions use confidential transactions
  • File discovery uses privacy-preserving queries
  • Access controls implemented through ZK set membership proofs

Set Up Instructions / Tutorial

Prerequisites

  • Node.js 18+
  • Midnight Network testnet access
  • Compact compiler
  • MidnightJS SDK

Step 1: Clone and Install

git clone https://github.com/username/privatevault-midnight
cd privatevault-midnight
npm install
Enter fullscreen mode Exit fullscreen mode

Step 2: Configure Midnight Network

# Set up testnet configuration
cp .env.example .env
# Add your Midnight testnet credentials
Enter fullscreen mode Exit fullscreen mode

Step 3: Compile Compact Contracts

npm run compile-contracts
Enter fullscreen mode Exit fullscreen mode

Step 4: Deploy to Testnet

npm run deploy
Enter fullscreen mode Exit fullscreen mode

Step 5: Run the DApp

npm run dev
Enter fullscreen mode Exit fullscreen mode

Testing the Privacy Features

  1. Upload a File: Use the encrypted upload feature
  2. Generate Access Token: Create a ZK-based access token
  3. Share Privately: Share file access without revealing contents
  4. Verify Access: Test ZK proof verification for file access

Key Files

  • contracts/FileVault.compact - Main smart contract
  • src/zk/ - Zero-knowledge proof implementations
  • src/privacy/ - Privacy-preserving utilities
  • src/ui/ - React frontend with privacy-first UX

Top comments (0)