Warning
This software has not received external security review and may contain vulnerabilities and may not necessarily meet its stated security goals. Do not use it for sensitive use cases, and do not rely on its security until it has been reviewed. Work in progress.
An Expo native module for secure, decentralized, peer-to-peer messaging over Bluetooth mesh networks.
This is the Expo/React Native module that provides the backend infrastructure for Bitchat mobile apps, enabling cross-platform encrypted messaging without internet, servers, or phone numbers.
- ✅ Cross-Platform Support: iOS and Android native implementations
- ✅ Bluetooth Mesh Networking: Automatic peer discovery and multi-hop message relay
- ✅ End-to-End Encryption: X25519 key exchange + AES-256-GCM for private messages
- ✅ Channel-Based Messaging: Topic-based group chats with optional password protection
- ✅ Store & Forward: Messages cached for offline peers and delivered when they reconnect
- ✅ Privacy First: No accounts, no phone numbers, no persistent identifiers
- ✅ TypeScript Support: Full type definitions included
- ✅ Event-Driven API: React to messages, peer connections, and delivery status
- ✅ Message Compression: LZ4 compression for bandwidth efficiency
- ✅ Battery Optimization: Adaptive scanning and power management
bunx expo install expo-bitchat- iOS: iOS 13.0+ with Bluetooth LE support
- Android: API level 26 (Android 8.0+) with Bluetooth LE support
- Expo: SDK 50+ (uses new architecture modules)
The module requires the following permissions (configured in your app.json/app.config.js):
<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app uses Bluetooth for secure peer-to-peer messaging</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app uses Bluetooth for mesh networking</string><uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />import BitchatAPI, { BitchatMessage } from "expo-bitchat";
// Start the mesh service with your nickname
await BitchatAPI.startServices("YourNickname");
// Listen for incoming messages
const messageSubscription = BitchatAPI.addMessageListener(
(message: BitchatMessage) => {
console.log("Received message:", message.content);
console.log("From:", message.sender);
console.log("Channel:", message.channel);
}
);
// Send a public message
await BitchatAPI.sendMessage("Hello mesh network!", [], "#general");
// Send a private message
const peers = await BitchatAPI.getConnectedPeers();
const peerID = Object.keys(peers)[0];
await BitchatAPI.sendPrivateMessage("Secret message", peerID, peers[peerID]);
// Clean up
messageSubscription.remove();
await BitchatAPI.stopServices();// Listen for peer connections
const peerConnectedSub = BitchatAPI.addPeerConnectedListener(
({ peerID, nickname }) => {
console.log(`${nickname} connected`);
}
);
// Listen for peer disconnections
const peerDisconnectedSub = BitchatAPI.addPeerDisconnectedListener(
({ peerID, nickname }) => {
console.log(`${nickname} disconnected`);
}
);
// Listen for delivery acknowledgments
const deliveryAckSub = BitchatAPI.addDeliveryAckListener((ack) => {
console.log(`Message delivered to ${ack.recipientNickname}`);
});
// Listen for read receipts
const readReceiptSub = BitchatAPI.addReadReceiptListener((receipt) => {
console.log(`Message read by ${receipt.readerNickname}`);
});// Set a password for a channel (owner only)
await BitchatAPI.setChannelPassword("#private-channel", "secretpassword");
// Remove password (owner only)
await BitchatAPI.setChannelPassword("#private-channel");interface BitchatMessage {
id: string;
sender: string;
content: string;
timestamp: number;
isPrivate: boolean;
channel?: string;
mentions?: string[];
senderPeerID?: string;
isEncrypted?: boolean;
deliveryStatus?: DeliveryStatus;
}
type DeliveryStatus =
| { type: "sending" }
| { type: "sent" }
| { type: "delivered"; to: string; at: number }
| { type: "read"; by: string; at: number }
| { type: "failed"; reason: string };Initializes the Bluetooth mesh service with the given nickname.
Stops the mesh service and disconnects from all peers.
Sends a public message to a channel with optional @mentions.
sendPrivateMessage(content: string, recipientPeerID: string, recipientNickname: string): Promise<void>
Sends an encrypted private message to a specific peer.
Sets or removes a password for a channel (channel owner only).
Returns a map of connected peer IDs to their nicknames.
All event listeners return a Subscription object with a remove() method.
addMessageListener(listener)- New message receivedaddPeerConnectedListener(listener)- Peer joined the meshaddPeerDisconnectedListener(listener)- Peer left the meshaddPeerListUpdatedListener(listener)- Peer list changedaddDeliveryAckListener(listener)- Message delivery confirmedaddReadReceiptListener(listener)- Message read receiptaddDeliveryStatusUpdateListener(listener)- Message status changed
- Private Messages: X25519 key exchange + AES-256-GCM encryption
- Channel Messages: Argon2id password derivation + AES-256-GCM
- Digital Signatures: Ed25519 for message authenticity
- Forward Secrecy: New key pairs generated each session
- No Registration: No accounts, emails, or phone numbers required
- Ephemeral by Default: Messages exist only in device memory
- Cover Traffic: Random delays and dummy messages prevent traffic analysis
- Local-First: Works completely offline, no servers involved
The module consists of native implementations for both platforms:
- BitchatModule.swift: Main Expo module interface
- BluetoothMeshService.swift: Core BLE mesh networking
- EncryptionService.swift: Cryptographic operations
- BinaryProtocol.swift: Protocol encoding/decoding
- BitchatModule.kt: Main Expo module interface
- BluetoothMeshService.kt: Core BLE mesh networking
- EncryptionService.kt: Cryptographic operations
- BinaryProtocol.kt: Protocol encoding/decoding
The module maintains 100% binary protocol compatibility between platforms:
- Header Format: Identical packet structure
- Encryption: Same cryptographic algorithms
- UUIDs: Shared Bluetooth service identifiers
- Message Routing: Compatible TTL and relay behavior
- Message Compression: LZ4 compression for messages >100 bytes
- Battery Management: Adaptive scanning based on battery level
- Connection Pooling: Efficient peer connection management
- Bloom Filters: Fast duplicate message detection
# Install dependencies
npm install
# Build TypeScript
npm run build
# Run linting
npm run lint
# Run tests
npm run test
# Open example app
npm run open:ios # iOS
npm run open:android # AndroidThe module includes an example app demonstrating basic usage:
cd example
npm install
npx expo run:ios # iOS
npx expo run:android # AndroidBluetooth permissions denied
- Ensure all required permissions are added to app.json
- Request permissions at runtime before calling
startServices()
Messages not reaching distant peers
- Check that intermediate devices are running the mesh service
- Verify Bluetooth is enabled and devices are in range
- Messages have a maximum TTL of 7 hops
Connection issues on Android
- Enable location services (required for BLE scanning)
- Disable battery optimization for your app
- Ensure target API level is compatible
Contributions are welcome! Key areas for enhancement:
- Performance: Battery optimization and connection reliability
- Security: Enhanced cryptographic features
- Testing: Unit and integration test coverage
- Documentation: API documentation and usage examples
- Platform Support: Additional Expo/React Native features
- Clone the repository
- Install dependencies:
npm install - Build the module:
npm run build - Test with example app:
cd example && npx expo run:ios
MIT
Made with create-expo-native-module