> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blockmsg.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# How It Works

> Understanding Fully Homomorphic Encryption (FHE) in blockmsg

## What is FHE?

**Fully Homomorphic Encryption (FHE)** is a breakthrough in cryptography that allows computations on encrypted data without ever decrypting it.

<Note>
  blockmsg uses [Zama's fhEVM](https://www.zama.ai/) to bring FHE to the blockchain.
</Note>

***

## The Encryption Process

<Steps>
  <Step title="Message Chunking">
    Your message is split into 32-bit segments in your browser
  </Step>

  <Step title="FHE Encryption">
    Each chunk is encrypted using `TFHE.asEuint32` - plaintext never leaves your device
  </Step>

  <Step title="On-Chain Storage">
    Encrypted handles are stored on the Zama fhEVM blockchain
  </Step>

  <Step title="Recipient Decryption">
    Recipient signs with wallet → re-encryption → local decryption
  </Step>
</Steps>

***

## Smart Contract Architecture

<AccordionGroup>
  <Accordion icon="envelope" title="SecretCircles Contract">
    The main contract handles:

    * Storing FHE-encrypted messages
    * Managing DM channels between wallets
    * Self-destruct timer logic
    * Access control for decryption
  </Accordion>

  <Accordion icon="code" title="Data Structure">
    ```solidity theme={null}
    struct DirectMessage {
        address sender;
        uint256 timestamp;
        euint32[] encryptedContent;  // FHE encrypted
        uint256 expiresAt;
    }
    ```
  </Accordion>
</AccordionGroup>

***

## Self-Destructing Messages

Set a timer on your messages. Once expired, the smart contract returns an empty array - the message becomes permanently unreadable.

| Timer     | Use Case                  |
| --------- | ------------------------- |
| 5 minutes | Quick sensitive info      |
| 1 hour    | Short-term coordination   |
| 12 hours  | Day-limited conversations |
| 24 hours  | Daily check-ins           |
| 7 days    | Weekly updates            |

<Warning>
  Self-destructed messages cannot be recovered by anyone - not even us.
</Warning>

***

## Technical Stack

<CardGroup cols={2}>
  <Card title="fhEVM by Zama" icon="lock">
    Fully Homomorphic Encryption virtual machine
  </Card>

  <Card title="Solidity" icon="file-code">
    Smart contracts for encrypted message management
  </Card>

  <Card title="Next.js" icon="react">
    Frontend application framework
  </Card>

  <Card title="fhevmjs" icon="js">
    Client-side FHE encryption library
  </Card>
</CardGroup>
