WiChain: Decentralized LAN Chat with Blockchain-backed History

Overview

WiChain is a peer-to-peer chat application for local networks (LAN) that combines a modern desktop UI (React + Tauri) with a tamper-evident blockchain ledger for chat history. It features:

This document provides a deep-dive into the technical implementation, architecture, and how blockchain is used in WiChain, with a step-by-step example.

Architecture

+-------------------+         +-------------------+
|   Frontend (UI)   | <----> |   Tauri Backend   |
|  React + TS + CSS |         |  Rust + Tauri     |
+-------------------+         +-------------------+
         |                               |
         |  Tauri API (invoke/emit)      |
         v                               v
+-------------------+         +-------------------+
|   Blockchain      |         |   Network (UDP)   |
|   (Rust crate)    |         |   (Rust crate)    |
+-------------------+         +-------------------+
         |                               |
         +-------------------------------+
         |      wichain-core/types        |
         +-------------------------------+
    

Project Flow Diagram

Project Flow Diagram

Major Components & Files

1. wichain-blockchain

2. wichain-core

3. wichain-network

4. wichain-backend

5. wichain-backend/frontend

Data Flow & Message Lifecycle

  1. Identity: On first run, a user identity (Ed25519 keypair + alias) is generated and stored locally.
  2. Peer Discovery: Each node broadcasts its presence over UDP. Peers are tracked by pubkey and alias.
  3. Sending a Message:
  4. Receiving a Message:
  5. Groups:

Blockchain in WiChain: How It Works

Example: Alice Sends a Message to Bob

  1. Alice types “Hi Bob!” and selects Bob as the peer.
  2. The backend creates a ChatBody:
    {
      "from": "AlicePubKeyB64",
      "to": "BobPubKeyB64",
      "text": "Hi Bob!",
      "ts_ms": 1712345678901
    }
                
  3. The backend signs this with Alice’s private key, producing a ChatSigned:
    {
      "from": "AlicePubKeyB64",
      "to": "BobPubKeyB64",
      "text": "Hi Bob!",
      "ts_ms": 1712345678901,
      "sig_b64": "...base64 signature..."
    }
                
  4. The message is obfuscated using SHA3-512 XOR of Alice and Bob’s pubkeys, then base64-encoded.
  5. The obfuscated message is sent over UDP directly to Bob.
  6. The clear (signed) message is appended to Alice’s local blockchain as a new block:
    {
      "index": 2,
      "timestamp_ms": 1712345678901,
      "previous_hash": "...",
      "nonce": 0,
      "data": "{\"from\":\"AlicePubKeyB64\",...}",
      "hash": "..."
    }
                
  7. Bob receives the UDP packet, deobfuscates it, verifies the signature, and appends the message to his own blockchain.
  8. Both Alice and Bob now have a tamper-evident record of the chat.

Security Model

More Technical Details

Message Obfuscation (Confidentiality)

Group Messaging

Blockchain Validation

Trust System

Security Limitations

Development & Extensibility

Quickstart

  1. Build the Rust workspace (cargo build in wichain/).
  2. Build the frontend (npm install && npm run build in wichain-backend/frontend/).
  3. Run the Tauri app (cargo tauri dev in wichain-backend/).
  4. Open the app on two+ LAN devices and start chatting!

Credits & License