Skip to content

salch-cred/medivault

Repository files navigation

MediVault Banner

πŸ₯ MediVault

Your private, AI-powered personal health vault β€” built on 0G.

Your records are scattered. The jargon is confusing. You're scared to upload them anywhere. MediVault fixes all three β€” privately, permanently, on-chain.

Live on 0G Mainnet Contract Deployed ERC-7857 iNFT Demo 0G Zero Cup Next.js PWA License: MIT 0G Health Verify on 0G

🌐 Live App Β Β·Β  ▢️ Demo Video Β Β·Β  πŸ” Verify Records Β Β·Β  0G Zero Cup Β Β·Β  0G Docs


"The only Zero Cup project where your encryption key never leaves your device β€” and the only working health vault with a live smart contract on 0G Mainnet implementing ERC-7857 iNFT."


πŸ”— On-Chain Evidence (0G Mainnet)

Item Details
πŸ“œ MediVaultRegistry Contract 0x4E3D3450dc98D3022Ac299D0Ed7AFf80Bd58FA4f
πŸ€– Standard ERC-7857 Agentic iNFT β€” 0G Docs
🌐 Network 0G Mainnet β€” Chain ID 16661
πŸ” Block Explorer View on chainscan.0g.ai
β›½ Live Health Endpoint /api/og/health β€” live block + node count
βœ… Record Verifier /verify β€” 4-check root hash verification

Every MediVault user mints an ERC-7857 Intelligent NFT (iNFT) on MediVaultRegistry. Your vault is a full Agentic ID β€” encrypted metadata anchored on 0G Mainnet, verifiable by anyone, owned by no one but you.


πŸ€– ERC-7857 Agentic iNFT β€” How MediVault Uses It

ERC-7857 is 0G Labs' flagship standard for Intelligent NFTs with private encrypted metadata. MediVault is the first healthcare application of ERC-7857:

ERC-7857 Feature MediVault Healthcare Use
dataHash β€” encrypted metadata hash Keccak256 of your AES-256 encrypted health record set on 0G Storage
sealedKey β€” key sealed to owner pubkey Your AES-256 vault key encrypted with your wallet's ECIES public key. Stored on-chain.
oracle β€” TEE/ZKP proof verifier MediVault oracle verifies re-encryption proofs (TEE-backed, bypassable in demo)
authorizeUsage() β€” grant access without transfer Patient grants doctor wallet access with a new sealedKey scoped to their pubkey β€” no ownership change
revokeUsage() β€” revoke access Patient instantly revokes a doctor's decryption key on-chain
clone() β€” wallet migration Patient migrates vault to new wallet with oracle-verified re-encryption
transfer() β€” oracle-verified ownership transfer Full wallet transfer with TEE/ZKP proof of correct metadata re-encryption
// Grant a doctor access to your vault (no ownership transfer)
mediVaultRegistry.authorizeUsage(
    tokenId,
    doctorWallet,
    abi.encode(sealedKeyForDoctor, expiry, recordScope)
);

// Doctor retrieves their sealed key
bytes memory permissions = mediVaultRegistry.getExecutorPermissions(tokenId, doctorWallet);
(bytes memory sealedKey, uint256 expiry, bytes32[] memory scope) = abi.decode(permissions, (bytes, uint256, bytes32[]));
// Doctor decrypts with their private key β†’ reads shared records

🎬 Demo

Upload β†’ Encrypt β†’ Store on 0G

MediVault Upload Demo

Upload any medical document β†’ AI explains it in plain language β†’ AES-256 encrypted in your browser β†’ stored permanently on 0G


βœ… Verified on 0G Network

Verified on 0G

Every record is verifiable on-chain β€” 4 live checks against 0G Network: chain live βœ… Β· file found βœ… Β· hash valid βœ… Β· explorer confirmed βœ…

πŸ” Try it yourself: medivault-ecru.vercel.app/verify


πŸ“Έ Screenshots

πŸ–₯️ Desktop

Landing Page

Landing Page Desktop

Hero β€” "Your health history, cryptographically yours"

Vault Dashboard

Vault Dashboard Desktop

All records, encrypted & indexed on 0G-KV

AI Summary

AI Summary Desktop

Plain-language explanation via 0G Compute

Doctor Sharing + QR

Doctor Share Desktop

ERC-7857 authorizeUsage β€” ECIES-encrypted share + emergency QR card

πŸ“± Mobile

Landing

Mobile Landing

Vault

Mobile Vault

AI Summary

Mobile AI

QR Scanner

Mobile QR

πŸ“² MediVault is a PWA β€” install it from your browser on iOS or Android. No app store. No account. Just your wallet.


🚨 The Problem

Medical records are the most important documents a person owns β€” yet they're the worst managed.

Pain point Reality today
πŸ“‚ Scattered Spread across clinic portals, PDFs, emails, and paper printouts
😡 Confusing Written in dense medical jargon most patients can't parse
😰 Risky to store Uploading to Google Drive or a random app means trusting a company forever
🚫 Unshareable No secure, instant way to hand a record to a new doctor
πŸ”“ Owned by others Hospitals and labs hold your data β€” you just get access when they feel like it

Every year, patients arrive at emergency rooms unable to recall their medications, allergies, or prior diagnoses β€” because their records are scattered across systems they don't control.


βœ… The Solution

MediVault is a self-sovereign health vault. Connect your MetaMask wallet β€” that's your identity, your key, your vault.

πŸ’‘ Unlike generic document tools or clinical scribes β€” MediVault is 100% patient-owned. No doctor, no hospital, no company can access your records. Only your wallet key decrypts them β€” unless you explicitly call authorizeUsage() to grant access.

  Upload any document  β†’  AI explains it in plain language
         β†’  AES-256 encrypted in your browser
                 β†’  Stored on 0G Network permanently
                         β†’  ERC-7857 iNFT minted β€” yours forever

How it works in 5 steps

Step Action What happens
1️⃣ Connect wallet MetaMask signs a fixed message β†’ MediVault derives a deterministic AES-256 key in your browser. The key never leaves your device.
2️⃣ Upload a document Drop any PDF, image, or lab report. pdf-parse + tesseract.js OCR handles all formats client-side.
3️⃣ AI explains it 0G Compute returns a plain-language summary, extracts conditions / medications / allergies / red flags, and flags anything urgent.
4️⃣ Encrypt & store AES-256 ciphertext uploaded to 0G Storage. Merkle root hash indexed in 0G-KV. Your server never sees plaintext.
5️⃣ Mint ERC-7857 iNFT MediVaultRegistry mints an Agentic iNFT β€” dataHash anchors your encrypted vault, sealedKey stores your vault key on-chain, sealed to your wallet pubkey.

✨ Features

πŸ” Privacy & Encryption

Feature Details
Wallet-native identity Connect MetaMask β†’ AES-256 key derived in-browser from wallet signature. Zero passwords. Zero email. Zero accounts.
Client-side AES-256 encryption Every file is encrypted in your browser before upload. 0G Storage only ever receives ciphertext β€” the server has zero knowledge of your health data.
ERC-7857 sealedKey on-chain Your vault's AES-256 key is sealed to your ECIES public key and stored in the iNFT β€” you can always recover it from your wallet.
ECIES doctor sharing Share any record to a doctor's wallet address with Elliptic Curve Integrated Encryption. Only the recipient's private key can open it β€” zero server relay.
authorizeUsage() doctor access Grant a doctor on-chain access via ERC-7857. Their sealed key is scoped to specific records and an expiry. Revokable instantly.
No recovery by design Your wallet = your vault. No backdoor, no admin override. This is a feature, not a bug.
Rate-limited APIs Hybrid in-process + KV-backed rate limiter on all public endpoints to prevent abuse.

🧠 AI-Powered Understanding

Feature Details
Plain-language summaries Dense lab panels and discharge summaries decoded into clear, human-readable explanations via 0G Compute β€” never a centralised cloud.
Smart extraction Automatically extracts conditions, medications, allergies, dosages, and red flags from every uploaded document.
Urgency flagging AI highlights anything that needs immediate attention β€” abnormal lab values, drug interactions, critical findings.
"Explain like I'm 5" toggle Switch any summary to the simplest possible explanation. Great for patients without medical backgrounds.
Multi-language support AI summaries available in multiple languages β€” your health data explained in the language you understand.
Vault-wide AI chat Ask questions across your entire record history. "What medications have I been prescribed?" β€” AI cites the exact source document.

πŸ“‚ Record Management

Feature Details
Multi-format support PDFs, images (JPG/PNG), scanned prescriptions, lab reports, discharge summaries β€” all handled with OCR + PDF parsing.
Health timeline Chronological view of all your medical events across all uploaded records. See your entire health history at a glance.
Lab trend charts Visualize lab values (blood sugar, cholesterol, haemoglobin, etc.) over time with reference range overlays.
Content-address deduplication Re-upload the same document and MediVault recognises it by content hash β€” auto-merges, no duplicates, no wasted 0G storage.
Tamper-proof integrity Every record has a Merkle root hash verifiable against 0G at any time. One click proves your record is unaltered.
Vault index on-chain Record index anchored to 0G-KV β€” your entire vault can be rebuilt trustlessly from on-chain state. No server required.

πŸ‘©β€βš•οΈ Sharing & Collaboration

Feature Details
Emergency QR card One-tap QR with blood type, allergies, and critical medications β€” scannable by any doctor, saveable to your phone lock screen.
Doctor handoff summary One-click printable summary of your entire medical history β€” structured for healthcare providers, ready for any appointment.
Tamper-proof certificates Generate a shareable certificate proving a record exists, is unaltered, and is anchored to 0G β€” verifiable by anyone, no account needed.
Consent ledger Every share event is written to an immutable, hash-chained audit trail on 0G β€” who accessed what, and when. Forever.
Received records inbox Doctors and family members can send ECIES-encrypted records directly to your wallet. Delivered to your received tab.

πŸ” Verification

Feature Details
Root hash verifier Visit /verify β†’ enter any record root hash β†’ 4 live checks against 0G Network: chain live, file found, hash valid, explorer link.
On-chain vault proof MediVaultRegistry.getVaultByAddress(wallet) returns root hash, record count, timestamps β€” verifiable by anyone.
ERC-7857 agent data MediVaultRegistry.getAgentData(tokenId) returns dataHash, sealedKey, oracle β€” full iNFT metadata on-chain.
Selective disclosure proofs Share cryptographic proof of a single field (e.g. "I am vaccinated") without revealing the full record. Verifiable by anyone at /verify.
0G Health endpoint GET /api/og/health β€” live JSON showing 0G chain block, storage node count, indexer status.

πŸ“² Mobile & Offline

Feature Details
PWA β€” install from browser Add MediVault to your home screen on iOS or Android directly from the browser. No app store. Instant install.
Offline access Service worker caches the app shell. Previously viewed records accessible from local encrypted cache even without internet.
QR scanner (mobile) Scan shared health QR codes directly from the mobile app. Fixed to work with iOS Safari β€” using jsqr for cross-browser compatibility.
Mobile-first design Responsive layout designed for one-hand use. Every feature accessible on a 375px screen.

πŸ”‘ Why 0G β€” Not IPFS, Not S3, Not Anything Else

Every feature in MediVault depends on a specific 0G primitive. Remove 0G and the product cannot exist.

What MediVault needs 0G primitive Without 0G
Permanent, censorship-resistant encrypted storage 0G Storage β€” AES-256 ciphertext + Merkle root No vault β€” nowhere to store ciphertext
Decentralised AI inference (no cloud snooping) 0G Compute β€” OpenAI-compatible, TEE-backed No AI summaries without trusting a centralised API
Tamper-proof record index per wallet 0G-KV β€” key-value store keyed by wallet address No trustless vault rebuild across devices
Immutable consent + share audit trail 0G Chain β€” on-chain event log No verifiable proof of who accessed what
Agentic iNFT with private encrypted metadata ERC-7857 + MediVaultRegistry on 0G Mainnet No Agentic ID β€” no on-chain sealed key recovery

πŸ—οΈ Architecture

flowchart TD
  U(["πŸ‘€ User + MetaMask"]) -->|"sign fixed message"| K(["πŸ”‘ AES-256 key β€” browser only"])
  U -->|"upload document"| P(["πŸ“„ Parse + OCR"])
  P -->|"pdf-parse / tesseract.js"| AI(["🧠 0G Compute"])
  AI --> EX(["Extraction: conditions, meds, allergies, flags"])
  EX --> ENC(["πŸ”’ Encrypt AES-256 in browser"])
  P --> ENC
  K --> ENC
  ENC -->|"ciphertext only"| S(["0G Storage"])
  S --> IDX(["0G-KV index"])
  IDX -->|"Merkle root + dataHash + sealedKey"| REG(["πŸ“œ MediVaultRegistry\nERC-7857 iNFT\n0G Mainnet"])
  IDX -->|"any device, any time"| V(["βœ… Vault"])
  S -->|"ERC-7857 authorizeUsage()"| D(["πŸ‘©β€βš•οΈ Doctor's wallet"])
  V -->|"share event"| CL(["0G Chain β€” consent ledger"])
Loading

πŸ›‘οΈ Security Model

Your wallet private key
        β”‚
        β–Ό
  sign(fixedMessage)  ──→  AES-256 key  ──→  encrypts every record
                                β”‚
                     ECIES-sealed to wallet pubkey
                                β”‚
                     stored on-chain in ERC-7857 sealedKey
                                β”‚
                     NEVER recoverable without your wallet
Property Guarantee
Zero-knowledge server API routes process only ciphertext. Plaintext never touches the backend.
No recovery by design Lose your wallet β†’ lose your vault. No admin backdoor. This is the point.
ERC-7857 sealedKey Your AES-256 key is sealed on-chain. Recoverable only by your wallet β€” not by MediVault, not by 0G, not by anyone.
Doctor access via oracle authorizeUsage() grants a new sealed key scoped to one doctor's pubkey. Revokable instantly with revokeUsage().
ECIES sharing ethers.SigningKey.computePublicKey + SDK ECIES header. Only the recipient's private key decrypts.
Merkle root verification Every record hash verifiable on-chain. Tampering is cryptographically impossible.
Soul-bound iNFT Standard ERC-721 transfers blocked. Only ERC-7857 transfer() with oracle proof allowed.

πŸš€ Quick Start

Prerequisites

Run locally

git clone https://github.com/salch-cred/medivault
cd medivault
npm install
cp .env.example .env.local
# fill in your API keys (see Environment Variables below)
npm run dev
# β†’ http://localhost:3000

Add 0G Mainnet to MetaMask

Field Value
Network name 0G Mainnet
RPC URL https://evmrpc.0g.ai
Chain ID 16661
Currency symbol OG
Block explorer https://chainscan.0g.ai

Get free gas at faucet.0g.ai.


βš™οΈ Environment Variables

Server-side (secret β€” never exposed to browser):

Variable Description
AI_API_KEY 0G Compute Router API key
AI_BASE_URL 0G Compute base URL (default: https://router-api.0g.ai/v1)
AI_MODEL Model ID served by 0G Compute

Client-side (NEXT_PUBLIC_*):

Variable Description
NEXT_PUBLIC_ZG_RPC_URL https://evmrpc.0g.ai
NEXT_PUBLIC_ZG_INDEXER_RPC https://indexer-storage-turbo.0g.ai
NEXT_PUBLIC_ZG_CHAIN_ID 16661
NEXT_PUBLIC_ZG_FLOW_CONTRACT 0G flow contract address
NEXT_PUBLIC_ZG_KV_NODE_URL 0G-KV node URL
NEXT_PUBLIC_APP_URL Your deployed URL
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID From cloud.reown.com
NEXT_PUBLIC_MEDIVAULT_REGISTRY 0x4E3D3450dc98D3022Ac299D0Ed7AFf80Bd58FA4f

πŸ› οΈ Tech Stack

Layer Technology Why
Framework Next.js 14 (App Router) SSR + API routes in one deploy
Blockchain 0G Mainnet (chain 16661) via ethers v6 Native 0G integration
Smart Contract MediVaultRegistry β€” ERC-7857 Agentic iNFT on 0G Mainnet Agentic ID with encrypted metadata, doctor access, oracle verification
Storage @0gfoundation/0g-storage-ts-sdk Decentralised ciphertext storage
AI inference 0G Compute Router (OpenAI-compatible) TEE-backed, no centralised cloud
Wallet MetaMask + Web3Modal / WalletConnect Universal Web3 wallet support
Encryption AES-256 (v1) + ECIES (v2) via 0G SDK Industry-standard, browser-native
OCR tesseract.js (client-side) Scan handwritten prescriptions
PDF parsing pdf-parse (server-side) Extract text from lab reports
QR scanning jsqr (cross-browser, iOS Safari safe) No native API dependency
UI Tailwind CSS + shadcn/ui + Framer Motion Fast, accessible, animated
PWA Service Worker + Web App Manifest Offline-first, installable

πŸ—ΊοΈ Roadmap

βœ… Completed

  • Wallet-native identity + AES-256 client-side encryption
  • 0G Storage upload + 0G-KV index
  • 0G Compute AI summaries + smart extraction
  • ECIES doctor sharing
  • Emergency QR card + QR scanner (mobile fixed)
  • Consent ledger on-chain
  • PWA β€” installable, offline-ready
  • Health timeline + lab trend charts
  • Vault-wide AI chat
  • Deployed on 0G Mainnet (chain 16661)
  • /verify β€” dual-tab verifier: root hash live check + selective disclosure proof token
  • AGENTS.md β€” AI-readable project context
  • SPEC.md β€” full product specification and architecture (500+ lines)
  • PITCH.md β€” competition pitch document
  • GitHub topic tags for discoverability (9 tags)
  • ERC-7857 Agentic iNFT β€” MediVaultRegistry on 0G Mainnet 0x4E3D3450dc98D3022Ac299D0Ed7AFf80Bd58FA4f
  • ERC-7857 v2 redeployed with IAgentOracle, authorizeUsage(), revokeUsage(), clone(), ReentrancyGuard

πŸ”„ Upcoming (Round of 32 β€” Jul 3)

  • Shareable verified health record card (/card/[hash]) with social preview
  • Selective-disclosure ZK proofs β€” prove one fact without revealing the full record
  • MCP server β€” @medivault/mcp-server for AI agent integrations
  • Lab value trend alerts β€” AI-triggered notifications for abnormal changes
  • Native mobile app (React Native) with on-device camera capture
  • 0G DA anchoring for ultra-low-cost bulk record archiving
  • TEE oracle deployment for production ERC-7857 proof verification

πŸ“„ License

MIT β€” see LICENSE


⚠️ MediVault explains and organizes your records. It is not medical advice. Always consult a qualified clinician.

Built with ❀️ by Sahil & Sal for the 0G Zero Cup 2026

🌐 Live App Β Β·Β  ▢️ Demo Β Β·Β  πŸ” Verify Β Β·Β  πŸ“œ Contract Β Β·Β  πŸ€– ERC-7857 Β Β·Β  0G Docs Β Β·Β  0G Zero Cup

Releases

No releases published

Packages

 
 
 

Contributors