Skip to content

Emmy123222/GPT

Repository files navigation

PrivateICP Messenger πŸ”

A privacy-centric, AI-enhanced messaging application built on the Internet Computer Protocol (ICP). Features end-to-end encryption, decentralized architecture, and intelligent AI assistant capabilities powered by GroqCloud.

🌟 Features

  • πŸ”’ End-to-End Encryption: Messages encrypted using ECDH key exchange + AES-GCM
  • πŸ€– AI Assistant: PrivateGPT powered by GroqCloud's Llama 3 models
  • 🌐 Decentralized: Built on Internet Computer Protocol (ICP)
  • πŸ”‘ Internet Identity: Secure, passwordless authentication
  • πŸ“± Responsive Design: Beautiful UI that works on all devices
  • ⚑ Real-time: Instant messaging with typing indicators
  • 🎯 Zero Knowledge: No personal data stored on servers

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    PrivateICP Messenger Architecture            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Internet Identity  β”‚
                    β”‚    (ICP Native)      β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚ Authentication
                               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Frontend Layer                               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
β”‚  β”‚   React     β”‚  β”‚  TypeScript β”‚  β”‚  Tailwind   β”‚              β”‚
β”‚  β”‚   18.3.1    β”‚  β”‚    5.5.3    β”‚  β”‚    CSS      β”‚              β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚ Encrypted Messages
                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Encryption Layer                               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  Web Crypto API (Browser Native)                           β”‚ β”‚
β”‚  β”‚  β€’ ECDH Key Exchange (P-256 Curve)                        β”‚ β”‚
β”‚  β”‚  β€’ AES-GCM Symmetric Encryption                           β”‚ β”‚
β”‚  β”‚  β€’ Secure Random IV Generation                            β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚ Ciphertext Only
                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    ICP Canister Layer                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
β”‚  β”‚    Chat     β”‚  β”‚   Storage   β”‚  β”‚    User     β”‚              β”‚
β”‚  β”‚  Canister   β”‚  β”‚  Canister   β”‚  β”‚  Registry   β”‚              β”‚
β”‚  β”‚  (Motoko)   β”‚  β”‚  (Rust)     β”‚  β”‚ (Motoko)    β”‚              β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    AI Enhancement Layer                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚                   GroqCloud API                             β”‚ β”‚
β”‚  β”‚  β€’ Model: llama3-8b-8192                                   β”‚ β”‚
β”‚  β”‚  β€’ Chat Summarization                                      β”‚ β”‚
β”‚  β”‚  β€’ Smart Reply Suggestions                                 β”‚ β”‚
β”‚  β”‚  β€’ Conversational AI Assistant                             β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ Data Flow Diagram

User A                                                    User B
  β”‚                                                         β”‚
  β”‚ 1. Generate Key Pair                                    β”‚
  β–Ό                                                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Private Key A  β”‚                                 β”‚  Private Key B  β”‚
β”‚  Public Key A   β”‚                                 β”‚  Public Key B   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β”‚                                                         β”‚
  β”‚ 2. Exchange Public Keys via ICP                        β”‚
  β–Ό                                                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    ICP Public Key Registry                          β”‚
β”‚  store_public_key(user_a, public_key_a)                            β”‚
β”‚  store_public_key(user_b, public_key_b)                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β”‚                                                         β”‚
  β”‚ 3. Derive Shared Secret (ECDH)                         β”‚
  β–Ό                                                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Shared Secret A β”‚ ◄─────────────────────────────► β”‚ Shared Secret B β”‚
β”‚ (Same Value)    β”‚                                 β”‚ (Same Value)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β”‚                                                         β”‚
  β”‚ 4. Encrypt Message with AES-GCM                        β”‚
  β–Ό                                                         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                        β”‚
β”‚   "Hello Bob"   β”‚                                        β”‚
β”‚       β–Ό         β”‚                                        β”‚
β”‚  [Ciphertext]   β”‚                                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                        β”‚
  β”‚                                                         β”‚
  β”‚ 5. Send via ICP Canister                               β”‚
  β–Ό                                                         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Chat Canister                                  β”‚
β”‚  send_message(sender_id, recipient_id, ciphertext, timestamp)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚                       β”‚
                                    β”‚ 6. Retrieve Messages  β”‚
                                    β–Ό                       β–Ό
                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                              β”‚  [Ciphertext]   β”‚   β”‚  [Ciphertext]   β”‚
                              β”‚       β–Ό         β”‚   β”‚       β–Ό         β”‚
                              β”‚  "Hello Bob"    β”‚   β”‚  "Hello Bob"    β”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Internet connection for GroqCloud API
  • Modern browser with Web Crypto API support

Installation

  1. Clone the repository

    git clone <repository-url>
    cd privateicp-messenger
  2. Install dependencies

    npm install
  3. Set up environment variables

    cp .env.example .env

    Edit .env and add your GroqCloud API key:

    VITE_GROQCLOUD_API_KEY=your_groqcloud_api_key_here
  4. Start the development server

    npm run dev
  5. Open your browser Navigate to http://localhost:5173

Getting GroqCloud API Key

  1. Visit GroqCloud Console
  2. Sign up for a free account
  3. Navigate to API Keys section
  4. Create a new API key
  5. Copy the key to your .env file (replace your_groqcloud_api_key_here)

πŸ“ Project Structure

src/
β”œβ”€β”€ components/           # React components
β”‚   β”œβ”€β”€ LoginScreen.tsx   # Internet Identity login
β”‚   β”œβ”€β”€ Sidebar.tsx       # Chat list and user profile
β”‚   └── ChatWindow.tsx    # Main chat interface
β”œβ”€β”€ hooks/               # Custom React hooks
β”‚   └── useAuth.ts       # Authentication logic
β”œβ”€β”€ services/            # External services
β”‚   β”œβ”€β”€ encryption.ts    # End-to-end encryption
β”‚   └── groqcloud.ts     # AI assistant integration
β”œβ”€β”€ types/               # TypeScript definitions
β”‚   └── index.ts         # Core type definitions
β”œβ”€β”€ App.tsx              # Main application component
β”œβ”€β”€ main.tsx             # Application entry point
└── index.css            # Global styles

πŸ” Security Architecture

Encryption Flow

  1. Key Generation: Each user generates an ECDH key pair using P-256 curve
  2. Key Exchange: Public keys are stored in ICP canister registry
  3. Shared Secret: ECDH algorithm derives identical shared secrets
  4. Message Encryption: AES-GCM encrypts messages with derived key
  5. Secure Storage: Only ciphertext is stored on-chain

Security Features

  • Zero Knowledge: Server never sees plaintext messages
  • Forward Secrecy: New keys can be generated for each session
  • Authenticated Encryption: AES-GCM provides both confidentiality and integrity
  • Secure Random: Cryptographically secure random number generation
  • Browser Native: Uses Web Crypto API (no external crypto libraries)

πŸ€– AI Assistant Features

PrivateGPT Capabilities

  • Conversational AI: Natural language conversations
  • Context Awareness: Remembers conversation history
  • Smart Replies: Suggests contextual responses
  • Chat Summarization: Summarizes long conversations
  • Privacy Focused: No data stored by AI service

GroqCloud Integration

// Example AI service usage
const groqService = GroqCloudService.getInstance();

// Generate AI response
const response = await groqService.generateAIResponse(
  userMessage, 
  conversationHistory
);

// Get smart reply suggestions
const suggestions = await groqService.generateSmartReplies(
  lastMessage, 
  context
);

// Summarize conversation
const summary = await groqService.summarizeConversation(messages);

🌐 ICP Integration

Internet Identity Authentication

// Authentication flow
const authClient = await AuthClient.create();
await authClient.login({
  identityProvider: 'https://identity.ic0.app',
  onSuccess: () => {
    const identity = authClient.getIdentity();
    const principal = identity.getPrincipal().toString();
    // User is now authenticated
  }
});

Canister Architecture (Future Implementation)

// Chat Canister (Motoko)
actor ChatCanister {
  public func send_message(
    sender: Principal,
    recipient: Principal, 
    ciphertext: Text,
    timestamp: Int
  ) : async MessageId;
  
  public func get_messages(
    user1: Principal,
    user2: Principal
  ) : async [Message];
  
  public func store_public_key(
    user: Principal,
    public_key: Text
  ) : async Bool;
}

🎨 UI/UX Design

Design System

  • Color Palette: Dark theme with purple/blue accents
  • Typography: System fonts with proper hierarchy
  • Spacing: 8px grid system
  • Components: Modular, reusable components
  • Animations: Smooth transitions and micro-interactions

Responsive Breakpoints

  • Mobile: 320px - 768px
  • Tablet: 768px - 1024px
  • Desktop: 1024px+

Accessibility

  • WCAG 2.1 AA: Compliant color contrast ratios
  • Keyboard Navigation: Full keyboard support
  • Screen Readers: Proper ARIA labels
  • Focus Management: Visible focus indicators

πŸ§ͺ Testing Strategy

Unit Tests

npm run test

E2E Test Scenarios

  1. Authentication Flow

    • Login with Internet Identity
    • Session persistence
    • Logout functionality
  2. Messaging Flow

    • Send encrypted message
    • Receive and decrypt message
    • Message status updates
  3. AI Assistant Flow

    • Send message to PrivateGPT
    • Receive AI response
    • Smart reply suggestions

πŸš€ Deployment

Frontend Deployment

# Build for production
npm run build

# Deploy to IC asset canister
dfx deploy --network ic frontend

Canister Deployment

# Deploy all canisters
dfx deploy --network ic

# Deploy specific canister
dfx deploy --network ic chat_canister

πŸ”§ Development

Available Scripts

  • npm run dev - Start development server
  • npm run build - Build for production
  • npm run preview - Preview production build
  • npm run lint - Run ESLint

Environment Variables

# Required
VITE_GROQCLOUD_API_KEY=your_api_key

# Optional (for local development)
VITE_IC_HOST=http://localhost:4943
VITE_INTERNET_IDENTITY_URL=http://localhost:4943/?canisterId=...

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Internet Computer Protocol - Decentralized infrastructure
  • GroqCloud - High-performance AI inference
  • Web Crypto API - Browser-native encryption
  • React Team - Frontend framework
  • Tailwind CSS - Utility-first CSS framework

Built with for privacy and decentralization

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors