# Introduction

## 🔐 Privacy Engine

#### Multi-Protocol Cryptographic Library

### Multi-Protocol Encryption Library

Cryptographic library supporting Starknet, X25519, and other protocols for secure multi-recipient messaging

***

## 🎯 What is Privacy Engine?

The **Privacy Engine** is a cryptographic library that enables secure multi-recipient messaging across multiple protocols including **Starknet** and **X25519**. It features signature-based encryption, double-wrapping security, and multi-recipient support with standard cryptographic primitives.

## ✨ Key Features

#### 👥 Multi-Recipient Encryption

Encrypt messages for multiple recipients simultaneously across different protocols with individual key wrapping.

#### 🔐 Signature-Based Encryption

Double-wrapping encryption using ECDSA signatures for security and wallet integration.

#### 🛡️ Double-Wrapping Security

Two-layer encryption: ECDH + AES-GCM inner layer, signature-derived key outer layer.

#### ⚡ WebAssembly Performance

Rust implementation compiled to WebAssembly for browser compatibility.

#### 🔑 Multi-Protocol Support

Built for multiple protocols including Starknet and X25519 with cryptographic operations and key recovery.

#### 🧪 Testing

Test suite with unit tests, performance benchmarks, and integration tests.

## 🚀 Quick Start

```rust
use privacy_engine::encrypt::encrypt_message;
use privacy_engine::types::{RecipientInfo, Protocol};

// Encrypt a message for multiple recipients across different protocols
let message = b"Hello, secure multi-recipient world!";
let recipients = vec![
    RecipientInfo {
        pubkey: starknet_user_pubkey,  // Vec<u8>
        protocol: Protocol::Starknet,
    },
    RecipientInfo {
        pubkey: x25519_user_pubkey,    // Vec<u8>
        protocol: Protocol::X25519,
    },
];

let result = encrypt_message(message, recipients)?;

// Decrypt using the appropriate protocol and private key
// For Starknet: use signature-based decryption
// For X25519: use standard ECDH decryption
```

## 📊 Protocol Comparison

| Protocol         | Curve       | Key Size | Signature | Key Recovery | Use Case               |
| ---------------- | ----------- | -------- | --------- | ------------ | ---------------------- |
| \*\*Starknet\*\* | Stark Curve | 32 bytes | ✅ ECDSA   | ✅ Yes        | Blockchain, ZK systems |
| \*\*X25519\*\*   | Curve25519  | 32 bytes | ❌ No      | ❌ No         | Standard key exchange  |

## 🔐 Signature-Based Encryption

#### Why Signature-Based Encryption?

The Privacy Engine implements **signature-based encryption** for several reasons:

1. **🔒 Enhanced Security**: Double-wrapping provides an additional layer of security beyond standard ECDH
2. **👛 Wallet Integration**: Seamlessly integrates with existing wallets without exposing private keys
3. **🛡️ Forward Secrecy**: Ephemeral keys ensure past communications remain secure even if long-term keys are compromised
4. **🔐 Authentication**: Signature verification ensures only the intended recipient can decrypt
5. **⚡ Performance**: Optimized cryptographic operations

## 🏗️ Encryption Architecture

```

┌─────────────────────────────────────────────────────────────┐
│                    Privacy Engine                           │
│                 Starknet Protocol                           │
├─────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐    ┌─────────────────┐                │
│  │   encrypt.rs    │    │   decrypt.rs    │                │
│  │                 │    │                 │                │
│  │ • Multi-recipient│    │ • Signature-based│               │
│  │   encryption    │    │   decryption    │                │
│  │ • Double-wrapping│    │ • Key recovery  │                │
│  └─────────────────┘    └─────────────────┘                │
├─────────────────────────────────────────────────────────────┤
│                    Starknet Layer                          │
│  ┌─────────────────┐    ┌─────────────────┐                │
│  │   starknet.rs   │    │   Key Recovery  │                │
│  │                 │    │                 │                │
│  │ • ECDSA Signing │    │ • Public Key    │                │
│  │ • ECDH Exchange │    │   Recovery      │                │
│  │ • Curve Point   │    │ • Signature     │                │
│  │   Operations    │    │   Verification  │                │
│  └─────────────────┘    └─────────────────┘                │
├─────────────────────────────────────────────────────────────┤
│                    Cryptographic Primitives               │
│  ┌─────────────────┐    ┌─────────────────┐                │
│  │   AES-256-GCM   │    │   SHA-256       │                │
│  │                 │    │                 │                │
│  │ • Message       │    │ • Key Derivation│                │
│  │   Encryption    │    │ • Hashing       │                │
│  │ • Authentication│    │ • Integrity     │                │
│  └─────────────────┘    └─────────────────┘                │
└─────────────────────────────────────────────────────────────┘

```

## 🏗️ System Architecture

```

┌─────────────────────────────────────────────────────────────┐
│                    Privacy Engine                           │
├─────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐    ┌─────────────────┐                │
│  │   encrypt.rs    │    │   decrypt.rs    │                │
│  │                 │    │                 │                │
│  │ • Message       │    │ • Key unwrapping│                │
│  │   encryption    │    │ • Message       │                │
│  │ • Key wrapping  │    │   decryption    │                │
│  └─────────────────┘    └─────────────────┘                │
├─────────────────────────────────────────────────────────────┤
│                    Protocol Layer                           │
│  ┌─────────────────┐    ┌─────────────────┐                │
│  │   Starknet      │    │     X25519      │                │
│  │   Protocol      │    │    Protocol     │                │
│  │                 │    │                 │                │
│  │ • ECDSA         │    │ • Diffie-Hellman│                │
│  │ • Key recovery  │    │ • Key agreement │                │
│  │ • Curve25519    │    │ • X25519 curve  │                │
│  └─────────────────┘    └─────────────────┘                │
├─────────────────────────────────────────────────────────────┤
│                    Core Types                               │
│  ┌─────────────────┐    ┌─────────────────┐                │
│  │   types.rs      │    │ traits/crypto.rs│                │
│  │                 │    │                 │                │
│  │ • EncryptResult │    │ • CryptoProtocol│                │
│  │ • RecipientInfo │    │   trait         │                │
│  │ • Protocol enum │    │ • Unified API   │                │
│  └─────────────────┘    └─────────────────┘                │
└─────────────────────────────────────────────────────────────┘

```

## 📚 Documentation Sections

🚀

#### Getting Started

Learn how to set up and use the Privacy Engine in your project with step-by-step guides.

[Get Started →](https://superrman.gitbook.io/privacy-engine/getting-started/getting-started)

🏗️

#### Architecture

Understand the design principles and cryptographic foundations of the system.

[Learn More →](https://superrman.gitbook.io/privacy-engine/architecture/architecture)

🔧

#### Protocols

Detailed documentation for supported cryptographic protocols and their implementations.

[Explore Protocols →](https://superrman.gitbook.io/privacy-engine/protocols/protocols)

💡

#### Examples

Practical examples and use cases demonstrating real-world applications.

[View Examples →](https://superrman.gitbook.io/privacy-engine/examples/examples)

📖

#### API Reference

Complete API documentation with detailed function references and examples.

[Browse API →](https://github.com/Goodness5/privacy-engine/blob/master/docs/api-reference.md)

🔒

#### Security

Security considerations and best practices for production deployments.

[Security Guide →](https://github.com/Goodness5/privacy-engine/blob/master/docs/security.md)

## ⚡ Performance Benchmarks

#### Protocol Performance Comparison

**Key Generation**

Starknet: \~2ms\
X25519: \~1ms

**Key Agreement**

Starknet: \~3ms\
X25519: \~2ms

**Message Encryption**

Both: \~1ms

**Multi-Recipient**

\~5ms per recipient

**WebAssembly Size**

\~500KB gzipped

**Memory Usage**

\~10MB typical

## 🎯 Use Cases

**💬 Secure Messaging**

Multi-recipient encrypted messaging with cross-protocol support.

**⛓️ Blockchain Integration**

Secure communication in blockchain applications and smart contracts.

**🔗 IoT Security**

Device-to-device encrypted communication for IoT networks.

**🎭 Zero-Knowledge Systems**

Privacy-preserving cryptographic applications and ZK proofs.

**🌐 Cross-Platform**

Interoperability between different cryptographic schemes and platforms.

**🔐 Enterprise Security**

Enterprise-grade encryption for sensitive data and communications.

## 🚀 Getting Started

#### Ready to Get Started?

Install Privacy Engine and start building secure, multi-protocol applications today.

[📖 Read Documentation](https://superrman.gitbook.io/privacy-engine/getting-started/getting-started)

[🐙 View on GitHub](https://github.com/your-repo/privacy-engine)

***

**Privacy Engine** - Secure, multi-protocol cryptographic communication for the modern web. 🔐✨

\ <br>

Rust Cryptography Blockchain Zero-Knowledge Security


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://superrman.gitbook.io/privacy-engine/readme.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
