Inspiration

AI document assistants are useful, but they usually treat a button click as enough permission to send private document context to an AI provider. I wanted to make that access explicit, verifiable, one-time, and revocable.

PrivateDocs AI uses Midnight to add privacy-preserving access control in front of an AI document assistant.

What it does

PrivateDocs AI lets a user upload a confidential PDF and ask questions about it while keeping access controlled by Midnight.

The workflow is:

  1. The PDF is parsed locally in the application.
  2. A document commitment and exact query commitment are created.
  3. Midnight authorizes that specific document-query pair.
  4. The permission must be finalized before AI access is allowed.
  5. The permission is consumed once using a deterministic nullifier.
  6. Replay attempts are rejected.
  7. Access can also be revoked.

The raw PDF is not stored on Midnight. The ledger receives cryptographic commitments rather than the document text.

How I built it

The application uses:

  • Streamlit for the interface
  • Python for PDF processing and RAG
  • Sentence Transformers for embeddings
  • FAISS for local semantic retrieval
  • OpenAI API for the final grounded answer
  • Midnight Compact for the privacy/access-control contract
  • Midnight.js for deployment, authorization, consumption, revocation, and state verification
  • GitHub Actions for automated verification

The AI boundary is fail-closed: if a real Midnight authorization cannot be verified, the application does not send context to the AI provider.

Midnight integration

The Compact contract implements:

  • document registration
  • exact document-query authorization
  • one-time permission consumption
  • nullifier-based replay protection
  • reauthorization
  • document revocation

The real Midnight end-to-end workflow was successfully verified on a local Midnight devnet through GitHub Actions, including contract deployment and the complete proof lifecycle.

What existed before the hackathon

Before this hackathon, I already had a basic AI Document Assistant capable of:

  • loading PDFs
  • splitting them into chunks
  • generating embeddings
  • retrieving relevant context with FAISS
  • answering questions using an AI model

What I built during the hackathon

For the Integrate Midnight track, I added the complete Midnight privacy layer, including:

  • the Compact smart contract
  • document and query commitments
  • exact-query authorization
  • one-time nullifiers
  • replay prevention
  • revocation
  • Midnight.js bridge and deployment tooling
  • fail-closed AI access
  • privacy inspector UI
  • security and architecture documentation
  • automated real Midnight E2E verification

Challenges

The biggest challenge was integrating the Compact-generated contract with Midnight.js while keeping runtime versions compatible.

I encountered a runtime class-identity mismatch between Midnight packages that caused proof execution to fail even though TypeScript compilation succeeded. I resolved it by aligning the on-chain runtime dependency, adding a runtime compatibility test, and verifying the full lifecycle again in CI.

Accomplishments

I am especially proud that the project does not rely on simulated authorization.

The automated workflow successfully verifies:

  • registration
  • authorization
  • wrong-query rejection
  • permission consumption
  • replay rejection
  • reauthorization
  • revocation
  • rejection after revocation

The application also intentionally fails closed when the real Midnight bridge is unavailable.

What I learned

I learned much more about zero-knowledge application architecture, Compact contracts, Midnight.js providers, commitments, nullifiers, finality, state verification, and how blockchain-based privacy controls can be combined with AI systems.

What's next

The next step would be deploying PrivateDocs AI to a public Midnight environment and expanding it for enterprise, legal, research, financial, and other sensitive-document workflows.

Built With

  • compact
  • faiss
  • github-actions
  • midnight
  • midnight.js
  • openai-api
  • python
  • rag
  • sentence-transformers
  • streamlit
  • typescript
  • zero-knowledge-proofs
Share this project:

Updates

Submission history