# habuskid/veil-protocol architecture

> Architecture diagram of the GitHub repository habuskid/veil-protocol, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/habuskid/veil-protocol
- Repository: https://github.com/habuskid/veil-protocol

## Overview

#### Purpose and Entry Points
Veil Protocol is a React/Vite dApp for discovering and operating Sepolia ERC-20 ↔ confidential ERC-7984 wrapper pairs in the Zama FHEVM ecosystem. The browser application starts at `src/main.jsx`, renders the shell in `src/App.jsx`, and is deployed as a static Vercel site via `vercel.json`.

#### Application Shell and Wallet Boundary
`src/App.jsx` coordinates the tab-oriented UI and shared connected-wallet state. `src/components/ConnectWallet.jsx` is the EIP-1193 wallet boundary: it obtains the user account/provider and enables transaction-capable Ethers v6 contract interactions. The application targets Sepolia; chain addresses are centralized in `src/config/addresses.js`.

#### Registry Discovery and Resilient Pair Catalog
`src/components/RegistryTab.jsx` presents available wrapper pairs. It reads the official on-chain Wrappers Registry as the primary source, but merges/falls back to the locally bundled catalog in `src/config/pairs.json` when RPC metadata calls fail or are rate-limited. This separates pair availability from optional ERC-20 display metadata, preserving actionable addresses under degraded RPC conditions.

#### Wrap / Unwrap Transaction Flow
`src/components/RegistryTab.jsx` drives public-to-confidential wrapping and confidential-to-public unwrapping for a selected pair. The flow crosses a signing boundary through the connected wallet: ERC-20 approval is submitted before wrapper conversion, then the corresponding wrapper contract transaction is submitted and awaited. Contract addresses and ABI assumptions are supplied through `src/config/addresses.js` and the repository ABI artifact `abi.json`.

#### Confidential Balance Decryption
`src/components/DecryptTab.jsx` lets a wallet holder provide an ERC-7984 address and request a readable confidential balance. Zama integration is isolated in `src/lib/zama.js`, which interfaces with `fhevmjs`/the FHEVM relayer flow. The user signs the required KMS EIP-712 authorization; decryption occurs through Zama FHEVM infrastructure rather than by exposing plaintext balances in contract state.

#### Faucet and Test-Asset Acquisition
`src/components/FaucetTab.jsx` exposes minting/claiming of supported test ERC-20 assets, allowing users to acquire tokens before testing wrap and unwrap. It consumes the same configured pair set in `src/config/pairs.json`, keeping faucet eligibility aligned with registry-rendered assets.

#### History and External Runtime Dependencies
`src/components/HistoryTab.jsx` provides the UI surface for transaction/activity history. Core runtime dependencies are React/Vite in `package.json`, Ethers.js v6 for wallet/RPC/contracts, and Zama `fhevmjs` for confidential-token operations. External boundaries are the Sepolia RPC/provider and deployed contracts, the user’s browser wallet, and Zama’s FHEVM/KMS relayer services.

#### Contract Development Surface
A separate Hardhat project under `contracts-project/` contains deployable contract infrastructure and deployment automation. `contracts-project/scripts/deploy.js` is its deployment entry point, with network/compiler configuration in `contracts-project/hardhat.config.js`; the frontend consumes already deployed Sepolia addresses rather than hosting contract execution itself.

Main entry points: [`src/App.jsx`](https://github.com/habuskid/veil-protocol/blob/main/src/App.jsx) (App shell), [`src/components/RegistryTab.jsx`](https://github.com/habuskid/veil-protocol/blob/main/src/components/RegistryTab.jsx) (Registry & conversion), [`src/components/ConnectWallet.jsx`](https://github.com/habuskid/veil-protocol/blob/main/src/components/ConnectWallet.jsx) (Connect wallet), [`src/components/FaucetTab.jsx`](https://github.com/habuskid/veil-protocol/blob/main/src/components/FaucetTab.jsx) (Faucet)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser dApp"]
  node_main["Vite entry<br/>React entry<br/>[main.jsx]"]
  node_app["App shell<br/>UI coordinator<br/>[App.jsx]"]
  node_wallet["Connect wallet<br/>EIP-1193 boundary<br/>[ConnectWallet.jsx]"]
  node_registry["Registry &amp; conversion<br/>pair operations UI<br/>[RegistryTab.jsx]"]
  node_decrypt["Decrypt balance<br/>confidential balance UI<br/>[DecryptTab.jsx]"]
  node_faucet["Faucet<br/>test asset UI<br/>[FaucetTab.jsx]"]
  node_history["History<br/>activity UI<br/>[HistoryTab.jsx]"]
  node_zama["Zama client<br/>FHEVM integration<br/>[zama.js]"]
end

subgraph group_config["Catalog &amp; Contracts"]
  node_addresses["Sepolia addresses<br/>address config<br/>[addresses.js]"]
  node_pairs["Bundled pair catalog<br/>fallback catalog<br/>[pairs.json]"]
  node_abi["Contract ABI<br/>ABI artifact<br/>[abi.json]"]
end

subgraph group_external["External Boundaries"]
  node_browser_wallet{{"Browser wallet<br/>signing provider"}}
  node_sepolia{{"Sepolia RPC &amp; contracts<br/>chain boundary"}}
  node_fhevm{{"Zama FHEVM &amp; KMS<br/>relayer services"}}
end

subgraph group_contracts["Contract Development"]
  node_deploy["Deployment script<br/>Hardhat deploy entry<br/>[deploy.js]"]
  node_hardhat["Hardhat config<br/>network &amp; compiler config<br/>[hardhat.config.js]"]
end

node_main -->|"renders"| node_app
node_app -->|"shares wallet state"| node_wallet
node_app -->|"selects tab"| node_registry
node_app -->|"selects tab"| node_decrypt
node_app -->|"selects tab"| node_faucet
node_app -->|"selects tab"| node_history
node_wallet -->|"EIP-1193 account &amp; signatures"| node_browser_wallet
node_registry -->|"reads registry; approves and converts"| node_sepolia
node_registry -.->|"merges / falls back"| node_pairs
node_registry -->|"uses deployed addresses"| node_addresses
node_registry -->|"uses contract interface"| node_abi
node_registry -->|"submits transactions"| node_wallet
node_decrypt -->|"requests balance decryption"| node_zama
node_decrypt -->|"requests KMS authorization signature"| node_wallet
node_zama -->|"relayer and KMS flow"| node_fhevm
node_faucet -->|"lists supported assets"| node_pairs
node_faucet -->|"submits mint or claim"| node_wallet
node_faucet -->|"calls test asset contracts"| node_sepolia
node_deploy -->|"uses network configuration"| node_hardhat
node_deploy -->|"deploys contract infrastructure"| node_sepolia
node_addresses -.->|"references deployed contracts"| node_sepolia

click node_main "https://github.com/habuskid/veil-protocol/blob/main/src/main.jsx"
click node_app "https://github.com/habuskid/veil-protocol/blob/main/src/App.jsx"
click node_wallet "https://github.com/habuskid/veil-protocol/blob/main/src/components/ConnectWallet.jsx"
click node_registry "https://github.com/habuskid/veil-protocol/blob/main/src/components/RegistryTab.jsx"
click node_decrypt "https://github.com/habuskid/veil-protocol/blob/main/src/components/DecryptTab.jsx"
click node_faucet "https://github.com/habuskid/veil-protocol/blob/main/src/components/FaucetTab.jsx"
click node_history "https://github.com/habuskid/veil-protocol/blob/main/src/components/HistoryTab.jsx"
click node_zama "https://github.com/habuskid/veil-protocol/blob/main/src/lib/zama.js"
click node_addresses "https://github.com/habuskid/veil-protocol/blob/main/src/config/addresses.js"
click node_pairs "https://github.com/habuskid/veil-protocol/blob/main/src/config/pairs.json"
click node_abi "https://github.com/habuskid/veil-protocol/blob/main/abi.json"
click node_deploy "https://github.com/habuskid/veil-protocol/blob/main/contracts-project/scripts/deploy.js"
click node_hardhat "https://github.com/habuskid/veil-protocol/blob/main/contracts-project/hardhat.config.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_app,node_wallet,node_registry,node_decrypt,node_faucet,node_history,node_zama toneBlue
class node_addresses,node_pairs,node_abi toneAmber
class node_browser_wallet,node_sepolia,node_fhevm toneMint
class node_deploy,node_hardhat toneRose
```

## Components

### Browser dApp

React/Vite application running as a static site.

- [Vite entry](https://github.com/habuskid/veil-protocol/blob/main/src/main.jsx): React entry · `src/main.jsx`
- [App shell](https://github.com/habuskid/veil-protocol/blob/main/src/App.jsx): UI coordinator · Owns tabs and connected-wallet state. · `src/App.jsx`
- [Connect wallet](https://github.com/habuskid/veil-protocol/blob/main/src/components/ConnectWallet.jsx): EIP-1193 boundary · Provides account, provider, and transaction signing. · `src/components/ConnectWallet.jsx`
- [Registry & conversion](https://github.com/habuskid/veil-protocol/blob/main/src/components/RegistryTab.jsx): pair operations UI · Discovers pairs and drives wrap or unwrap transactions. · `src/components/RegistryTab.jsx`
- [Decrypt balance](https://github.com/habuskid/veil-protocol/blob/main/src/components/DecryptTab.jsx): confidential balance UI · `src/components/DecryptTab.jsx`
- [Faucet](https://github.com/habuskid/veil-protocol/blob/main/src/components/FaucetTab.jsx): test asset UI · `src/components/FaucetTab.jsx`
- [History](https://github.com/habuskid/veil-protocol/blob/main/src/components/HistoryTab.jsx): activity UI · `src/components/HistoryTab.jsx`
- [Zama client](https://github.com/habuskid/veil-protocol/blob/main/src/lib/zama.js): FHEVM integration · Handles relayer flow and KMS authorization. · `src/lib/zama.js`

### Catalog & Contracts

Shared deployed-address and pair metadata.

- [Sepolia addresses](https://github.com/habuskid/veil-protocol/blob/main/src/config/addresses.js): address config · `src/config/addresses.js`
- [Bundled pair catalog](https://github.com/habuskid/veil-protocol/blob/main/src/config/pairs.json): fallback catalog · Preserves actionable pair addresses during RPC degradation. · `src/config/pairs.json`
- [Contract ABI](https://github.com/habuskid/veil-protocol/blob/main/abi.json): ABI artifact · `abi.json`

### External Boundaries

Wallet, Sepolia, and Zama services.

- **Browser wallet**: signing provider
- **Sepolia RPC & contracts**: chain boundary · Registry, ERC-20, and ERC-7984 wrapper contracts.
- **Zama FHEVM & KMS**: relayer services · Processes EIP-712 authorization and confidential decryption.

### Contract Development

Separate Hardhat deployment project.

- [Deployment script](https://github.com/habuskid/veil-protocol/blob/main/contracts-project/scripts/deploy.js): Hardhat deploy entry · `contracts-project/scripts/deploy.js`
- [Hardhat config](https://github.com/habuskid/veil-protocol/blob/main/contracts-project/hardhat.config.js): network & compiler config · `contracts-project/hardhat.config.js`

## Connections

- Vite entry → App shell: renders
- App shell → Connect wallet: shares wallet state
- App shell → Registry & conversion: selects tab
- App shell → Decrypt balance: selects tab
- App shell → Faucet: selects tab
- App shell → History: selects tab
- Connect wallet → Browser wallet: EIP-1193 account & signatures
- Registry & conversion → Sepolia RPC & contracts: reads registry; approves and converts
- Registry & conversion → Bundled pair catalog: merges / falls back
- Registry & conversion → Sepolia addresses: uses deployed addresses
- Registry & conversion → Contract ABI: uses contract interface
- Registry & conversion → Connect wallet: submits transactions
- Decrypt balance → Zama client: requests balance decryption
- Decrypt balance → Connect wallet: requests KMS authorization signature
- Zama client → Zama FHEVM & KMS: relayer and KMS flow
- Faucet → Bundled pair catalog: lists supported assets
- Faucet → Connect wallet: submits mint or claim
- Faucet → Sepolia RPC & contracts: calls test asset contracts
- Deployment script → Hardhat config: uses network configuration
- Deployment script → Sepolia RPC & contracts: deploys contract infrastructure
- Sepolia addresses → Sepolia RPC & contracts: references deployed contracts
