# What Transport Layers Does BitChat Use? Bluetooth Mesh and Nostr Protocol Explained

> Discover how BitChat uses Bluetooth mesh for offline and Nostr protocol for online communication. Explore its dual-transport architecture for resilient messaging.

- Repository: [permissionlesstech/bitchat](https://github.com/permissionlesstech/bitchat)
- Tags: deep-dive
- Published: 2026-08-22

---

**BitChat employs a dual-transport architecture that combines Bluetooth Low Energy (BLE) mesh networking for offline communication and the Nostr protocol for internet-based message relay, ensuring resilient delivery with or without connectivity.**

BitChat (permissionlesstech/bitchat) is an open-source, censorship-resistant messaging application that operates without centralized servers or user accounts. Understanding the transport layers used in BitChat reveals how the application achieves offline resilience while maintaining global reach through its hybrid peer-to-peer design.

## Bluetooth Mesh Network: The Offline Transport Layer

The first transport layer uses **Bluetooth Mesh networking** to enable direct, internet-free communication between nearby devices. This layer is implemented primarily in [`bitchat/Services/BLE/BLEService.swift`](https://github.com/permissionlesstech/bitchat/blob/main/bitchat/Services/BLE/BLEService.swift) and provides local peer-to-peer connectivity through BLE (Bluetooth Low Energy) links.

Key characteristics of the Bluetooth transport include:

- **Multi-hop routing** supporting up to 7 hops to extend range beyond direct BLE limits
- **Noise Protocol encryption** for compact binary packet security
- **Automatic peer discovery** with duty-cycled power management for battery efficiency
- **Adaptive power usage** that scales based on connection stability and proximity

When a nearby peer is discovered, BitChat establishes a Noise-encrypted BLE session through the `BLEService` class. This path is prioritized for real-time chat, voice bursts, and file transfers because it offers the fastest, most private communication channel without exposing metadata to external networks.

The mesh architecture allows messages to hop through intermediate devices, creating a self-healing local network that functions during internet outages or in offline environments.

## Nostr Protocol: The Internet Transport Layer

When Bluetooth connectivity is unavailable, BitChat falls back to the **Nostr protocol** (Notes and Other Stuff Transmitted by Relays) for global message delivery. This transport layer, managed in [`bitchat/Nostr/NostrRelayManager.swift`](https://github.com/permissionlesstech/bitchat/blob/main/bitchat/Nostr/NostrRelayManager.swift), leverages the standard Nostr websocket relay network to route messages worldwide.

The Nostr transport implementation features:

- **Kind-1059 events** that encapsulate BitChat's private message format
- **XChaCha20-Poly1305 encryption** applied through BitChat's private-envelope format before relay transmission
- **Geohash-derived location channels** for location-based messaging rooms
- **Multiple relay connections** for redundancy and censorship resistance

Unlike traditional messaging servers, Nostr relays merely forward encrypted payloads without storing user metadata or requiring phone number registration. The `NostrRelayManager` handles websocket connections to public relays, encoding messages using the `NostrEvent` structure defined in [`bitchat/Nostr/NostrProtocol.swift`](https://github.com/permissionlesstech/bitchat/blob/main/bitchat/Nostr/NostrProtocol.swift).

## Intelligent Message Routing Between Transport Layers

BitChat's transport selection logic operates on a **Bluetooth-first policy** with automated fallback mechanisms. The routing intelligence, tested in [`bitchatTests/Services/MessageRouterTests.swift`](https://github.com/permissionlesstech/bitchat/blob/main/bitchatTests/Services/MessageRouterTests.swift), follows this hierarchy:

1. **Bluetooth priority** – The system checks `BLEService.shared.isConnected(to:)` to determine if the recipient is within BLE range. If true, the message transmits directly via the encrypted mesh network.

2. **Nostr fallback** – When no BLE route exists (recipient out of range or offline), the app automatically encrypts the payload using `PrivateEnvelope` and forwards it to configured Nostr relays via `NostrRelayManager.shared.send(_:to:)`.

3. **Persistent queuing** – If both transports are unavailable, outgoing messages enter a local queue. Delivery resumes automatically when either BLE connectivity or Nostr relay access is restored.

This hybrid approach ensures that users can communicate in isolated environments (festivals, protests, remote areas) using Bluetooth, while maintaining connectivity with distant contacts through the Nostr relay network.

## Implementation Details

The routing logic manifests in Swift code through explicit transport selection. Here is the high-level dispatch pattern used when sending messages:

```swift
// Prepare a chat payload
let payload = ChatMessage(text: "Hello, world!", channel: .local)

// Try Bluetooth first
if BLEService.shared.isConnected(to: recipientID) {
    BLEService.shared.send(payload, to: recipientID)
} else {
    // Fallback to Nostr
    NostrRelayManager.shared.send(payload, to: recipientPublicKey)
}

```

The BLE service handles binary packet transmission after Noise protocol encryption:

```swift
// BLEService.swift – sending a packet
func send(_ packet: BitchatPacket, to peer: PeerID) {
    // Packet is already Noise‑encrypted
    let data = packet.toBinaryData()
    peripheral.writeValue(data, for: characteristic, type: .withResponse)
}

```

For Nostr transmission, the relay manager wraps payloads in encrypted envelopes:

```swift
// NostrRelayManager.swift – sending over Nostr
func send(_ payload: ChatMessage, to pubKey: Data) {
    let envelope = PrivateEnvelope(message: payload, recipientKey: pubKey)
    let event = NostrEvent(kind: 1059, content: envelope.serialized)
    relayConnection?.send(.data(event.encode()), completionHandler: { _ in })
}

```

## Summary

- BitChat utilizes **two complementary transport layers**: Bluetooth Mesh for local offline communication and Nostr for internet-based global relay.
- The **BLE mesh network** supports multi-hop routing (up to 7 hops) with Noise protocol encryption, implemented in [`BLEService.swift`](https://github.com/permissionlesstech/bitchat/blob/main/BLEService.swift).
- The **Nostr transport layer** uses kind-1059 events and XChaCha20-Poly1305 encryption via [`NostrRelayManager.swift`](https://github.com/permissionlesstech/bitchat/blob/main/NostrRelayManager.swift) to ensure privacy across public relays.
- **Intelligent routing logic** prioritizes Bluetooth connections, automatically falls back to Nostr when necessary, and queues messages when both transports are unavailable.
- No centralized servers or phone numbers are required for either transport, maintaining user anonymity and censorship resistance.

## Frequently Asked Questions

### Can BitChat send messages without any internet connection?

Yes. BitChat's Bluetooth Mesh transport operates entirely offline using BLE (Bluetooth Low Energy) to create local peer-to-peer networks. Messages can hop through multiple intermediate devices (up to 7 hops) to reach recipients outside direct Bluetooth range, making the app functional during internet outages or in areas without cellular coverage.

### How does BitChat ensure message privacy across both transport layers?

BitChat applies end-to-end encryption using the **Noise protocol** for Bluetooth mesh transmissions and **XChaCha20-Poly1305** for Nostr relay messages. In [`BLEService.swift`](https://github.com/permissionlesstech/bitchat/blob/main/BLEService.swift), packets are Noise-encrypted before transmission, while [`NostrRelayManager.swift`](https://github.com/permissionlesstech/bitchat/blob/main/NostrRelayManager.swift) wraps payloads in `PrivateEnvelope` structures before relaying via kind-1059 events. No transport layer exposes plaintext content or requires centralized authentication.

### What is the maximum range for Bluetooth messaging in BitChat?

Direct BLE range typically extends 30-100 meters depending on device hardware and environmental conditions. However, BitChat's mesh networking supports **multi-hop routing through up to 7 intermediate devices**, effectively extending range across large crowds or geographic areas as long as a chain of BitChat users exists between sender and recipient.

### Does BitChat rely on centralized servers for message delivery?

No. The Bluetooth transport uses direct device-to-device communication without servers. The Nostr transport uses publicly available decentralized relays that merely forward encrypted payloads without storing user metadata, requiring no phone number registration or account creation. This serverless architecture ensures that no single entity can block communications or access message content.