>_ DevTrendsen

Language

Home

Languages

Sections

Frontend Backend Mobile DevOps AI / ML GameDev Blockchain Embedded Security
Swift

How BitChat Works and Why Bluetooth Mesh Messengers Are Trending Again

BitChat Icon

When cellular service completely disappears at a music festival or in the mountains, familiar apps turn into useless icons. The signal goes nowhere, and the towers are overloaded. In such situations, peer-to-peer solutions that can transmit data directly from one smartphone to another come in handy.

The BitChat project offers an interesting approach to this problem. The developers combined an offline local network on Bluetooth LE with the global Nostr protocol. The result is a hybrid messenger in the style of classic IRC, working without accounts and without central servers.

How Message Transmission Works

BitChat is built on a dual architecture. The app automatically adjusts the transport based on current connectivity conditions.

First level: Bluetooth LE Mesh. If the recipient is nearby, the message goes directly. When the recipient is outside Bluetooth range, the packet moves along a chain through other users' smartphones. The architecture supports up to 7 such intermediate hops. No internet is required for this. Security is handled by the Noise protocol, which provides end-to-end encryption of packets at the local level.

Second level: Nostr protocol. If a direct Bluetooth channel is unavailable but there is network access, BitChat sends data through public Nostr relays.

Public rooms are organized using geohashes. The precision level depends on the length of the coordinate hash string:

  • block (7 characters): chat within a city block
  • neighborhood (6 characters): district level
  • city (5 characters): city-wide chat
  • region (2 characters): an entire country

When sending a private message, the messenger first searches for a direct Bluetooth connection. If there are no nearby devices, it switches to Nostr and packs the text using the NIP-17 algorithm. When there is neither internet nor Bluetooth neighbors, the message queues until any available channel appears.

Implementation Details and Interface

Visually, BitChat resembles text chats from the late nineties. It supports familiar commands like /slap, /msg, or /who. There is no registration process whatsoever. On first launch, the app generates temporary cryptographic keys without requesting a phone number or email.

Several interesting technical solutions in the project:

  • Emergency deletion. Triple-tapping the screen permanently clears local storage and cryptographic keys.
  • Traffic compression. Data is compressed via LZ4 before sending, which is critical for the low bandwidth of Bluetooth LE.
  • Power consumption optimization. In offline mode, the chat dynamically changes ether scanning intervals, preserving battery charge.
  • Open source. The repository is released under the Unlicense, and can be freely forked or used in commercial products.

How to Run the Project

The source code is written in Swift for iOS and macOS.

The fastest way to run the desktop version is via the just utility:

brew install just
just run

The command will compile the app and launch it on your Mac. To clean up generated files after testing, call just clean.

To build for iOS in Xcode, you will need to perform the standard configuration preparation:

cd bitchat
cp Configs/Local.xcconfig.example Configs/Local.xcconfig

After that, simply open bitchat.xcodeproj, set your Developer Team ID in the Local.xcconfig file, and update the group name in entitlements.

Why Study This Repository

Nobody is likely to use BitChat as their primary messenger every day. However, the project is of tremendous interest from an engineering perspective.

In the code, you can find a clean implementation of a custom binary protocol over CoreBluetooth, geohash handling, and Nostr relay integration. At the same time, the app is already ready for use and published in the App Store, so it can be kept on your device as a backup communication option for hiking or large concerts.

Related projects