Introduction to AegisCare

🛡️ What is AegisCare?

AegisCare is a revolutionary clinical trial matching platform that uses Fully Homomorphic Encryption (FHE) to enable privacy-preserving patient-trial matching. Unlike traditional systems, AegisCare performs eligibility computations on encrypted data, ensuring zero plaintext leakage.

🔒 Privacy Guarantee:

  • Medical data never leaves the browser in plaintext
  • Eligibility computed entirely in the encrypted domain
  • Only the patient can decrypt their own results
  • Trial sponsors never see patient medical data

✨ Key Features

  • Client-Side Encryption: All medical data encrypted before submission
  • FHE Operations: Computations on encrypted data only
  • Private Decryption: EIP-712 signatures for secure access
  • Zero Knowledge: Trial sponsors learn nothing about patient data
  • Testnet Deployed: Live on Sepolia at 0x3DB49a1Ca0d72740e54f5FB06Ccc69576c4192F7

📘 Complete User Guide

🎓 New to AegisCare? Start Here!

Everything you need to know about privacy-preserving clinical trial matching

NEWComprehensive User Guide Available

We've created a complete, in-depth user guide to help you understand and use AegisCare. Whether you're a patient, trial sponsor, developer, or just curious about FHE technology, this guide has everything you need.

📖 Read Complete User Guide →

What's Inside the User Guide

1
What is AegisCare?

Simple explanation of the platform and why it matters

2
Why Do We Need It?

Real-world problems AegisCare solves

3
How Does It Work?

Step-by-step process explanation with diagrams

4
Key Concepts Explained

FHE, EIP-712, ACLs made simple

5
Technology Stack

All technologies used and why

6
Getting Started Tutorial

5-minute quick start walkthrough

Perfect For:
👤Patients - Protect your privacy while joining trials
🏢Trial Sponsors - Zero-knowledge trial matching
💻Developers - Explore FHE technology
🎓Students - Study privacy-preserving apps

🔑 Key Highlights from the User Guide

🔒 Privacy-First Architecture

Learn how AegisCare ensures your medical data never leaves your device in plaintext form. All data is encrypted using FHE before being sent to the blockchain, and only you can decrypt your eligibility results.

⚡ FHE Technology Explained

Understand Fully Homomorphic Encryption - how it allows computations on encrypted data without ever decrypting it. This breakthrough technology enables zero-knowledge trial matching.

🎯 Real-World Use Cases

Explore practical scenarios: diabetes trials, mental health studies, rare disease research. See how AegisCare solves real privacy concerns in clinical trial recruitment.

🚀 Step-by-Step Tutorial

Follow our detailed 5-minute quick start guide. Learn how to connect your wallet, register as a patient, create trials, and check eligibility - all with privacy preserved.

📊 Comprehensive FAQ

Over 50 frequently asked questions answered. From "Can trial sponsors see my data?" to "How does FHE work?" - find answers to all your questions.

Ready to dive deeper into privacy-preserving clinical trials?

📖 Read the Complete User Guide →

500+ lines of comprehensive documentation • 10 major sections • Perfect for beginners

📊 Test Data Guide

Use these pre-configured test patients and trials to explore the platform without entering real medical data.

Quick Test Scenarios

✅ Perfect Match

Patient: John (Age 45, Diabetes E11, BMI 28.5)

Trial: Diabetes Study (Age 18-65, E11, BMI 18.5-35)

Result: ELIGIBLE ✅

❌ Age Mismatch

Patient: Jane (Age 75, Diabetes E11, BMI 22.0)

Trial: Diabetes Study (Age 18-65, E11, BMI 18.5-35)

Result: NOT ELIGIBLE (too old)

⚠️ Condition Mismatch

Patient: Bob (Age 50, No Condition, BMI 25.0)

Trial: Diabetes Study (Requires E11, Age 18-65)

Result: NOT ELIGIBLE (no diabetes)

✅ Healthy Trial Match

Patient: Jane (Age 30, No Condition, BMI 22.0)

Trial: Wellness Study (Age 18-65, No Condition, BMI 18.5-30)

Result: ELIGIBLE ✅

Sample Patient Data

Patient 1John Doe - Diabetes Patient

{
  "name": "John Doe",
  "age": 45,
  "gender": 1,
  "bmiScore": 28.5,
  "hasMedicalCondition": true,
  "conditionCode": "E11",
  "description": "Type 2 Diabetes, age 45, BMI 28.5 (overweight)"
}

Matches:

  • ✅ Diabetes Treatment Study 2025

Patient 2Jane Smith - Healthy Adult

{
  "name": "Jane Smith",
  "age": 32,
  "gender": 2,
  "bmiScore": 22.1,
  "hasMedicalCondition": false,
  "conditionCode": "Z00",
  "description": "Healthy adult, age 32, normal BMI"
}

Matches:

  • ✅ General Wellness Study

Patient 3Bob Johnson - Hypertension Patient

{
  "name": "Bob Johnson",
  "age": 58,
  "gender": 1,
  "bmiScore": 31.2,
  "hasMedicalCondition": true,
  "conditionCode": "I10",
  "description": "Hypertension, age 58, BMI 31.2 (obese)"
}

Matches:

  • ✅ Cardiovascular Health Research

Sample Trial Data

Trial 1: Diabetes Treatment Study 2025

{
  "trialName": "Diabetes Treatment Study 2025",
  "description": "Testing new treatment for Type 2 diabetes in adults",
  "criteria": {
    "minAge": 18,
    "maxAge": 65,
    "requiredGender": 0,
    "minBMIScore": 18.5,
    "maxBMIScore": 35,
    "hasSpecificCondition": true,
    "conditionCode": "E11"
  }
}

📊 Eligible Patients:

  • John Doe (Age 45, BMI 28.5, E11)

Trial 2: Cardiovascular Health Research

{
  "trialName": "Cardiovascular Health Research",
  "description": "Study on heart health in adults 40-70",
  "criteria": {
    "minAge": 40,
    "maxAge": 70,
    "requiredGender": 0,
    "minBMIScore": 20,
    "maxBMIScore": 40,
    "hasSpecificCondition": true,
    "conditionCode": "I10"
  }
}

📊 Eligible Patients:

  • Bob Johnson (Age 58, BMI 31.2, I10)

Trial 3: General Wellness Study

{
  "trialName": "General Wellness Study",
  "description": "Open study for healthy adults",
  "criteria": {
    "minAge": 18,
    "maxAge": 65,
    "requiredGender": 0,
    "minBMIScore": 18.5,
    "maxBMIScore": 30,
    "hasSpecificCondition": false,
    "conditionCode": "Z00"
  }
}

📊 Eligible Patients:

  • Jane Smith (Age 32, BMI 22.1, Z00)
  • John Doe (if no diabetes - but he has E11, so no match)

Medical Codes Reference

CodeDescriptionCategory
E11Type 2 diabetes mellitusEndocrine
E10Type 1 diabetes mellitusEndocrine
I10Essential (primary) hypertensionCirculatory
I50Heart failureCirculatory
J45AsthmaRespiratory
M54Dorsalgia (back pain)Musculoskeletal
Z00General medical examination (healthy)Health
Z01Special examinations and investigationsHealth

Gender Codes

CodeDescription
0All genders (no preference)
1Male
2Female
3Other / Prefer not to say

🚀 How It Works

Patient Workflow

1

Register Medical Data

Enter your medical information on the patient dashboard

2

Client-Side Encryption 🔒

Your data is encrypted in the browser using FHE before being sent

3

Blockchain Registration

Encrypted data stored on Sepolia testnet via smart contract

4

Check Eligibility

Select a trial and trigger encrypted eligibility computation

5

Private Decryption 🔑

Only YOU can decrypt your result with your private key

Trial Sponsor Workflow

1

Create Trial

Define trial name, description, and eligibility criteria

2

Encrypt Criteria 🔒

Trial criteria encrypted before being sent to blockchain

3

Smart Contract Storage

Encrypted trial stored on Sepolia testnet

4

Wait for Patients

Patients can now check their eligibility against your trial

🏗️ Architecture Overview

System Architecture

┌─────────────────────────────────────────┐
│           Patient Browser                 │
│  ┌──────────────────────────────────┐   │
│  │ Medical Data (Plaintext)         │   │
│  └────────────┬─────────────────────┘   │
│               │                          │
│               ▼                          │
│  ┌──────────────────────────────────┐   │
│  │ FHE Encryption (Client-Side)    │   │
│  │ • Zama RelayerSDK v0.3.0-8      │   │
│  │ • Encrypted handles + proofs     │   │
│  └────────────┬─────────────────────┘   │
└───────────────┼──────────────────────────┘
                │
                ▼
┌─────────────────────────────────────────┐
│     Ethereum Sepolia Testnet            │
│  ┌──────────────────────────────────┐   │
│  │ AegisCare Smart Contract          │   │
│  │ 0x3DB49...76c4192F7             │   │
│  │                                  │   │
│  │ • Encrypted Patient Data         │   │
│  │ • Encrypted Trial Criteria       │   │
│  │ • FHE Eligibility Computation    │   │
│  │ • Encrypted Results Storage      │   │
│  └────────────┬─────────────────────┘   │
└───────────────┼──────────────────────────┘
                │
                ▼
┌─────────────────────────────────────────┐
│      EIP-712 Private Decryption         │
│  ┌──────────────────────────────────┐   │
│  │ Patient Signs EIP-712 Message   │   │
│  │ → Private Key Decrypts Result   │   │
│  └────────────┬─────────────────────┘   │
└───────────────┼──────────────────────────┘
                │
                ▼
         ┌──────────┐
         │ ELIGIBLE │
         │ YES / NO │
         └─────────┘

Key Components:

  • Frontend: Next.js 16, React 19, TypeScript, TailwindCSS 4
  • FHE SDK: Zama RelayerSDK v0.3.0-8 for client-side encryption
  • Web3: ethers.js v6, Wagmi for wallet connection
  • Blockchain: Solidity 0.8.27, fhEVM, Sepolia testnet
  • Smart Contract: AegisCare.sol with FHE operations

📚 API Reference

FHE Client API

Client-side encryption utilities in lib/fheClient.ts

Encrypt Patient Data

import { encryptPatientData } from '@/lib/fheClient';

const encryptedData = await encryptPatientData({
  age: 45,
  gender: 1,  // 1=male, 2=female, 3=other
  bmiScore: 28.5,
  hasMedicalCondition: true,
  conditionCode: "E11"  // ICD-10 code
});

// Returns:
// {
//   age: { handle: "0x...", ... },
//   ageProof: "0x...",
//   gender: { handle: "0x...", ... },
//   genderProof: "0x...",
//   ...
// }

Encrypt Trial Criteria

import { encryptTrialCriteria } from '@/lib/fheClient';

const encryptedCriteria = await encryptTrialCriteria({
  trialName: "Diabetes Study 2025",
  description: "Testing new treatment",
  minAge: 18,
  maxAge: 65,
  requiredGender: 0,
  minBMIScore: 18.5,
  maxBMIScore: 35,
  hasSpecificCondition: true,
  conditionCode: "E11"
});

Decrypt Eligibility Result

import { decryptEligibilityResult } from '@/lib/fheClient';

const isEligible = await decryptEligibilityResult(
  encryptedResult,
  contractAddress,
  signer
);

console.log(isEligible); // true or false

Web3 Client API

Blockchain interaction utilities in lib/web3Client.ts

Register Patient

import { registerPatient } from '@/lib/web3Client';

await registerPatient(signer, encryptedData, publicKeyHash);

Register Trial

import { registerTrial } from '@/lib/web3Client';

await registerTrial(
  signer,
  trialName,
  description,
  encryptedCriteria
);

Compute Eligibility

import { computeEligibility } from '@/lib/web3Client';

await computeEligibility(signer, trialId, patientAddress);

Smart Contract API

Contract deployed at 0x3DB49a1Ca0d72740e54f5FB06Ccc69576c4192F7 on Sepolia

registerPatient

Register a patient with encrypted medical data

function registerPatient(
    bytes32 ageHandle,
    bytes32 ageProof,
    bytes32 genderHandle,
    bytes32 genderProof,
    bytes32 bmiScoreHandle,
    bytes32 bmiProof,
    bytes32 hasMedicalConditionHandle,
    bytes32 conditionProof,
    bytes32 conditionCodeHandle,
    bytes32 codeProof,
    bytes32 publicKeyHash
) external

registerTrial

Create a new clinical trial (owner only)

function registerTrial(
    string memory trialName,
    string memory description,
    bytes32 minAgeHandle,
    bytes32 minAgeProof,
    // ... (14 more encrypted parameters)
) external onlyOwner

computeEligibility

Compute eligibility on encrypted data

function computeEligibility(
    uint256 _trialId,
    address _patientAddress
) external

getEligibilityResult

Get encrypted result (patient only)

function getEligibilityResult(
    uint256 _trialId,
    address _patientAddress
) external view returns (bytes32)

🐛 Troubleshooting

Common Issues

"Cannot connect to wallet"

Ensure MetaMask is installed and you're on Sepolia testnet

Solution: Refresh page, check MetaMask, verify network

"Transaction failed"

Not enough ETH for gas fees

Solution: Get free Sepolia ETH from sepoliafaucet.com

"FHE initialization failed"

Zama FHE SDK still loading

Solution: Wait 5-10 seconds, check internet connection, refresh page

"Eligibility computation failed"

Patient or trial not registered

Solution: Ensure you're registered and the trial exists

"Cannot decrypt result"

Only patients can decrypt their own results

Solution: Use the correct wallet address, sign EIP-712 message

🔒 Security & Privacy

Privacy Guarantees

  • Zero Knowledge: Trial sponsors learn NOTHING about patient data
  • Encrypted Computation: All operations on encrypted data
  • Private Decryption: Only patients can decrypt their results
  • No Plaintext Storage: Only encrypted data on-chain
  • Pausable Contract: Emergency stop functionality

Compliance:

  • HIPAA Compliant: No PHI disclosure without patient consent
  • GDPR Compliant: Data protection by design and default
  • Regulatory Friendly: Privacy-first architecture

🚢 Deployment

Current Deployment

Network: Sepolia Testnet

Contract: 0x3DB49a1Ca0d72740e54f5FB06Ccc69576c4192F7

Chain ID: 11155111

View on Etherscan: sepolia.etherscan.io

Local Deployment

# Deploy to local network
npm run deploy:local

# Deploy to Sepolia
npm run deploy:sepolia

# Run tests
npm test

# Compile contracts
npx hardhat compile

Built with ❤️ using Zama FHEVM

Privacy-Preserving Clinical Trial Matching