### Setup: XcodeGen Commands Source: https://github.com/permissionlesstech/bitchat/blob/main/README.md Commands to set up the bitchat project using XcodeGen. This involves installing XcodeGen via Homebrew, generating the Xcode project files, and then opening the generated project. ```bash brew install xcodegen xcodegen generate open bitchat.xcodeproj ``` -------------------------------- ### MacOS Build and Run Commands Source: https://github.com/permissionlesstech/bitchat/blob/main/README.md Commands for setting up and running the bitchat project on MacOS from source. Includes instructions for initial setup and cleaning the project environment. ```just just run ``` ```just just clean ``` -------------------------------- ### Setup: Swift Package Manager Source: https://github.com/permissionlesstech/bitchat/blob/main/README.md Command to open the Swift Package Manager manifest file for the bitchat project, typically used to initiate project setup or modifications within Xcode. ```bash open Package.swift ``` -------------------------------- ### Quick Start: Build and Run BitChat Source: https://github.com/permissionlesstech/bitchat/blob/main/BUILD_MACOS.md Execute the primary command to build and launch the BitChat macOS application. Alternatively, view all available commands by running 'just' without arguments. ```bash # Build and run the app just run # Or see all available commands just ``` -------------------------------- ### BitChat Message Encryption/Decryption Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Shows Swift examples for encrypting and decrypting messages using an established Noise session managed by the NoiseService. ```swift // Encrypt message let encrypted = try noiseService.encrypt(messageData, for: peerID) // Decrypt message let decrypted = try noiseService.decrypt(encryptedData, from: peerID) ``` -------------------------------- ### BitChat macOS Build Commands Source: https://github.com/permissionlesstech/bitchat/blob/main/BUILD_MACOS.md A list of essential commands provided by the Justfile for managing the BitChat macOS build process, including building, cleaning, and checking prerequisites. ```bash # Build and run the macOS app just run # Build the macOS app only just build # Clean build artifacts and restore original files just clean # Check prerequisites (XcodeGen, Xcode, etc.) just check # Show app information and requirements just info ``` -------------------------------- ### Noise Handshake Initiator Encrypted Static Key Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Demonstrates the initiator's final step in completing the Noise handshake, including deriving session keys based on the handshake transcript. ```swift // Complete handshake, derive session keys let (sendKey, recvKey) = deriveSessionKeys(transcript) ``` -------------------------------- ### Noise Handshake Initiator Ephemeral Key Generation Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Shows the Swift code for an initiator generating an ephemeral key and preparing its public key for the initial message in the Noise handshake. ```swift let ephemeralKey = Curve25519.KeyAgreement.PrivateKey() let message = ephemeralKey.publicKey.rawRepresentation ``` -------------------------------- ### Noise Session Management Functions Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Provides Swift function signatures for managing Noise sessions, including lookup, removal, and identifying sessions that require rekeying. ```swift // Session lookup by peer ID func getSession(for peerID: String) -> NoiseSession? // Automatic session removal on disconnect func removeSession(for peerID: String) // Rekey detection func getSessionsNeedingRekey() -> [(String, Bool)] ``` -------------------------------- ### Noise Handshake Responder Encrypted Static Key Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Illustrates the responder's step in the Noise handshake, involving ephemeral key generation, performing Diffie-Hellman, and encrypting the static key. ```swift // Generate ephemeral, perform DH, encrypt static key let encryptedStatic = encrypt(staticKey, using: sharedSecret) ``` -------------------------------- ### BitChat Channel Key Distribution Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Illustrates how password-protected channels use Noise for secure key distribution, creating an encrypted key packet for sharing. ```swift // Share channel key securely let keyPacket = createChannelKeyPacket(password: password, channel: channel) let encrypted = try encrypt(keyPacket, for: peerID) ``` -------------------------------- ### BitChat Protocol Version Negotiation Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Details the protocol version negotiation flow, message types, and backward compatibility rules for BitChat to ensure peer compatibility. ```APIDOC ## Protocol Version Negotiation BitChat implements protocol version negotiation to ensure compatibility between different client versions. ### Version Negotiation Flow: 1. **Version Hello**: Upon connection, peers exchange supported protocol versions. 2. **Version Agreement**: Peers agree on the highest common version. 3. **Graceful Fallback**: Legacy peers without version negotiation assume protocol v1. ### Message Types: - `versionHello` (0x20): Used by peers to announce their supported protocol versions. - `versionAck` (0x21): Used by peers to acknowledge and agree on a specific protocol version. ### Backward Compatibility: - Peers that do not send version negotiation messages are assumed to support protocol v1. - Future protocol versions can be added to `ProtocolVersion.supportedVersions`. - Incompatible peers will receive a rejection message and disconnect gracefully. ``` -------------------------------- ### Key Derivation Functions Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Provides Swift function signatures for key derivation using HKDF (Hash-based Key Derivation Function) and PBKDF2 (Password-Based Key Derivation Function 2). ```swift // HKDF for key derivation func hkdf(salt: Data, ikm: Data, info: Data, length: Int) -> Data // Derive channel keys with PBKDF2 func deriveChannelKey(password: String, salt: Data) -> SymmetricKey ``` -------------------------------- ### bitchat IRC-Style Commands Source: https://github.com/permissionlesstech/bitchat/blob/main/README.md A collection of IRC-style commands used within the bitchat application for interacting with channels, peers, and managing the application state. These commands facilitate joining channels, sending private messages, managing blocks, and controlling channel settings. ```APIDOC IRC-Style Commands: /j #channel - Joins or creates a specified channel. /m @name message - Sends a private message to a specific peer. - Parameters: - @name: The nickname of the recipient peer. - message: The content of the private message. /w - Lists all currently online users (peers) in the network. /channels - Displays a list of all discovered channels in the network. /block @name - Blocks a specific peer from sending messages to you. - Parameters: - @name: The nickname of the peer to block. /block - Lists all currently blocked peers. /unblock @name - Unblocks a previously blocked peer. - Parameters: - @name: The nickname of the peer to unblock. /clear - Clears the chat messages displayed in the current view. /pass [password] - Sets or changes the password for a channel (owner only). - Parameters: - [password]: The new password for the channel (optional, can be used to view current password). /transfer @name - Transfers ownership of the current channel to another peer. - Parameters: - @name: The nickname of the peer to transfer ownership to. ``` -------------------------------- ### bitchat Binary Protocol Specification Source: https://github.com/permissionlesstech/bitchat/blob/main/README.md Details the efficient binary protocol used by bitchat for Bluetooth LE communication. It covers packet structure, routing, fragmentation, and deduplication mechanisms. ```APIDOC bitchat Binary Protocol: - Protocol Type: Efficient binary protocol optimized for Bluetooth LE. - Packet Format: - Compact packet structure. - Includes a 1-byte type field for message categorization. - Message Routing: - TTL-based routing mechanism. - Supports a maximum of 7 hops for message propagation. - Message Handling: - Automatic fragmentation for large messages to fit Bluetooth LE packet constraints. - Message deduplication implemented using unique IDs to prevent redundant processing. - Related Features: - Network Efficiency: Optimized Bloom filters for faster duplicate detection and reduced memory usage. - Message Aggregation: Batches small messages to minimize transmission overhead. - Adaptive Connection Limits: Dynamically adjusts peer connections based on device power mode. - Mesh Networking: Devices act as both client and peripheral, with automatic peer discovery and store-and-forward for offline delivery. ``` -------------------------------- ### BitChat Message Flow Source: https://github.com/permissionlesstech/bitchat/blob/main/WHITEPAPER.md Outlines the step-by-step process of a message being sent in BitChat, from user input and encryption through fragmentation, packaging, broadcasting via BLE, and delivery or store-and-forward mechanisms. ```mermaid graph TD U[User Types Message] --> E[Encrypt with Noise] E --> F{Size Check} F -->|"> 500 bytes"| FR[Fragment Message] F -->|"≤ 500 bytes"| P[Package for Send] FR --> P P --> B[Broadcast via BLE] B --> M{Recipient Online?} M -->|Yes| D[Direct Delivery] M -->|No| S[Store & Forward] S --> W[Wait for Recipient] W --> D style U fill:#e3f2fd style E fill:#f3e5f5 style D fill:#c8e6c9 ``` -------------------------------- ### Noise Protocol Cryptographic Primitives Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Lists the cryptographic primitives used in the Noise Protocol implementation, including Diffie-Hellman, Cipher, Hash, and Key Derivation Function. ```APIDOC Cryptographic Primitives: - DH: X25519 (Curve25519) - Cipher: ChaChaPoly (AEAD) - Hash: SHA-256 - KDF: HKDF-SHA256 ``` -------------------------------- ### NoiseEncryptionService Class Definition Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Defines the core NoiseEncryptionService class in Swift, highlighting its private properties for managing keys, sessions, and channel encryption. ```swift class NoiseEncryptionService { private let staticIdentityKey: Curve25519.KeyAgreement.PrivateKey private let sessionManager: NoiseSessionManager private let channelEncryption = NoiseChannelEncryption() } ``` -------------------------------- ### BitChat Mesh Network Diagram Source: https://github.com/permissionlesstech/bitchat/blob/main/WHITEPAPER.md Illustrates the peer-to-peer communication flow in the BitChat mesh network, showing how messages hop between devices to reach their destination, extending communication range beyond individual Bluetooth capabilities. ```mermaid graph TD A[Alice 📱] -.->|BLE 30m| B[Bob 📱] B -.->|BLE 30m| C[Carol 📱] C -.->|BLE 30m| D[Dave 📱] A -->|"Message to Dave
hops through network"| B B --> C C --> D style A fill:#4caf50,color:#fff style D fill:#2196f3,color:#fff ``` -------------------------------- ### NoiseSession Class Definition Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Defines the NoiseSession class in Swift, which holds the state for individual peer sessions, including handshake and cipher states, and the remote static public key. ```swift class NoiseSession { private var handshakeState: NoiseHandshakeState? private var sendCipher: NoiseCipherState? private var receiveCipher: NoiseCipherState? private let remoteStaticKey: Curve25519.KeyAgreement.PublicKey? } ``` -------------------------------- ### BitChat Security: Noise XX Handshake Source: https://github.com/permissionlesstech/bitchat/blob/main/WHITEPAPER.md Visualizes the Noise XX handshake pattern used by BitChat for end-to-end encryption, demonstrating the exchange of ephemeral keys and encrypted identities to establish a secure communication channel. ```mermaid sequenceDiagram participant Alice participant Bob Note over Alice,Bob: Noise Handshake Alice->>Bob: Ephemeral Key Bob->>Alice: Ephemeral Key + Encrypted Identity Alice->>Bob: Encrypted Identity Note over Alice,Bob: Secure Channel Established Alice->>Bob: Encrypted Messages Bob->>Alice: Encrypted Messages ``` -------------------------------- ### NoiseSessionManager Class Definition Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Defines the NoiseSessionManager class in Swift, responsible for thread-safe management of multiple Noise sessions using a concurrent dispatch queue. ```swift class NoiseSessionManager { private var sessions: [String: NoiseSession] = [: ] private let sessionsQueue = DispatchQueue(label: "noise.sessions", attributes: .concurrent) } ``` -------------------------------- ### Noise XX Pattern Handshake Flow Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Describes the three-message pattern used in the Noise XX handshake, including the sequence of messages exchanged for mutual authentication and identity encryption. ```APIDOC XX: -> e <- e, ee, s, es -> s, se ``` -------------------------------- ### BitChat Message Types Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Defines the message types used in the BitChat protocol, specifically for version negotiation. ```swift case versionHello = 0x20 // Announce supported versions case versionAck = 0x21 // Acknowledge and agree on version ``` -------------------------------- ### Noise Identity Announcement Structure Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Defines the Swift struct for a Noise identity announcement, used after a handshake to share peer information like ID, public key, nickname, and previous ID, along with a signature. ```swift struct NoiseIdentityAnnouncement { let peerID: String let publicKey: Data let nickname: String let previousPeerID: String? let signature: Data } ``` -------------------------------- ### BitChat Privacy: Ephemeral Peer ID Rotation Source: https://github.com/permissionlesstech/bitchat/blob/main/WHITEPAPER.md Depicts the mechanism of ephemeral peer ID rotation in BitChat, showing how peer identifiers change periodically while maintaining a persistent identity through public key fingerprints, enhancing privacy by preventing tracking. ```mermaid graph LR subgraph "Time Period 1" ID1[Peer ID: abc123] end subgraph "Time Period 2" ID2[Peer ID: def456] end subgraph "Time Period 3" ID3[Peer ID: ghi789] end ID1 -->|Rotate| ID2 ID2 -->|Rotate| ID3 F["Fingerprint: SHA256 of PublicKey"] F -.->|"Persistent Identity"| ID1 F -.-> ID2 F -.-> ID3 style F fill:#9c27b0,color:#fff ``` -------------------------------- ### Noise Protocol Error Enum Source: https://github.com/permissionlesstech/bitchat/blob/main/BRING_THE_NOISE.md Defines the Swift enum for potential errors encountered during Noise protocol operations, such as handshake failures or decryption issues. ```swift enum NoiseError: Error { case handshakeFailed case invalidMessage case sessionNotEstablished case decryptionFailed } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.