SophaxChat · Code Richard Metzner

SophaxChat

The code

Every line of it, to read like a book.

The iPhone, Mac and Android apps, the cryptography, the network, the tests — 208 files and 47,809 lines in 13 chapters. Read them in order, page by page, or open any one. This is the code as of 7 October 2026, shared under the MIT licence.

I built SophaxChat by directing AI. It has not been independently audited, so please don’t rely on it where your safety depends on it.

Contents

  1. 01

    Start here

    What SophaxChat is, why it exists, what has changed, and the terms it is shared under.

    1. README.md 735
    2. PHILOSOPHY.md 98
    3. CHANGELOG.md 83
    4. PRIVACY.md 59
    5. LICENSE 21
    6. CODE_OF_CONDUCT.md 43
    7. PUBLIC_RELEASE_CHECKLIST.md 120
    8. wiki/Home.md 63
  2. 02

    In words, before code

    What it protects against and what it does not, and how the protocol and the cryptography work — explained in plain documents.

    1. SECURITY.md 296
    2. THREAT_MODEL.md 156
    3. docs/CRYPTO_SUMMARY.md 377
    4. docs/THREAT_MODEL.md 173
    5. docs/crypto.md 180
    6. docs/protocol.md 236
    7. wiki/Cryptography.md 128
    8. wiki/Protocol.md 118
  3. 03

    Who you are

    Your identity is two pairs of keys made on your own device. Here they are created, kept in the Keychain, backed up, split among friends if you choose, and watched for changes.

    1. Sources/SophaxChatCore/Crypto/IdentityManager.swift 267
    2. Sources/SophaxChatCore/Crypto/KeychainManager.swift 747
    3. Sources/SophaxChatCore/Crypto/IdentityExport.swift 213
    4. Sources/SophaxChatCore/Crypto/ShamirBackup.swift 249
    5. Sources/SophaxChatCore/Crypto/KeyTransparencyLog.swift 122
  4. 04

    The lock

    How two phones agree on a secret (X3DH) and keep changing it with every message (the Double Ratchet).

    1. Sources/SophaxChatCore/Crypto/CryptoTypes.swift 199
    2. Sources/SophaxChatCore/Crypto/X3DH.swift 209
    3. Sources/SophaxChatCore/Crypto/PreKeyManager.swift 276
    4. Sources/SophaxChatCore/Crypto/DoubleRatchet.swift 479
  5. 05

    The heart

    One file ties everything together: it sends and receives, starts sessions, relays for others and holds messages until they can go.

    1. Sources/SophaxChatCore/ChatManager.swift 3830
  6. 06

    Finding each other

    How messages travel: over Bluetooth and Wi‑Fi nearby, from phone to phone, over TCP further away — and a shared table for finding people without any server.

    1. Sources/SophaxChatCore/Network/MessageTransport.swift 110
    2. Sources/SophaxChatCore/Network/NetworkProtocol.swift 1291
    3. Sources/SophaxChatCore/Network/MeshManager.swift 265
    4. Sources/SophaxChatCore/Network/RelayRouter.swift 125
    5. Sources/SophaxChatCore/Network/LanDiscovery.swift 126
    6. Sources/SophaxChatCore/Network/TCPTransport.swift 505
    7. Sources/SophaxChatCore/Crypto/TLSCertManager.swift 254
    8. Sources/SophaxChatCore/DHT/DHTBootstrap.swift 42
    9. Sources/SophaxChatCore/DHT/DHTEngine.swift 505
    10. Sources/SophaxChatCore/DHT/DHTStorage.swift 35
    11. Sources/SophaxChatCore/DHT/DHTStore.swift 68
    12. Sources/SophaxChatCore/DHT/KBucket.swift 214
  7. 07

    Anywhere in the world

    Tor, built into the app so no other app is needed, and the .onion address it gives each person.

    1. SophaxChat/Tor/TorManager.swift 196
    2. SophaxChat/Tor/HiddenServiceKeyWriter.swift 77
    3. SophaxChat/Tor/TorFramework/NSBundle+GeoIP.h 20
    4. SophaxChat/Tor/TorFramework/NSBundle+GeoIP.m 31
    5. SophaxChat/Tor/TorFramework/NSCharacterSet+PredefinedSets.h 19
    6. SophaxChat/Tor/TorFramework/NSCharacterSet+PredefinedSets.m 35
    7. SophaxChat/Tor/TorFramework/TORAuthKey.h 140
    8. SophaxChat/Tor/TorFramework/TORAuthKey.m 207
    9. SophaxChat/Tor/TorFramework/TORCircuit.h 379
    10. SophaxChat/Tor/TorFramework/TORCircuit.m 502
    11. SophaxChat/Tor/TorFramework/TORConfiguration.h 46
    12. SophaxChat/Tor/TorFramework/TORConfiguration.m 172
    13. SophaxChat/Tor/TorFramework/TORControlCommand.h 24
    14. SophaxChat/Tor/TorFramework/TORControlReplyCode.h 72
    15. SophaxChat/Tor/TorFramework/TORController.h 110
    16. SophaxChat/Tor/TorFramework/TORController.m 923
    17. SophaxChat/Tor/TorFramework/TORLogging.h 23
    18. SophaxChat/Tor/TorFramework/TORLogging.m 180
    19. SophaxChat/Tor/TorFramework/TORNode.h 95
    20. SophaxChat/Tor/TorFramework/TORNode.m 250
    21. SophaxChat/Tor/TorFramework/TOROnionAuth.h 101
    22. SophaxChat/Tor/TorFramework/TOROnionAuth.m 144
    23. SophaxChat/Tor/TorFramework/TORThread.h 28
    24. SophaxChat/Tor/TorFramework/TORThread.m 99
    25. SophaxChat/Tor/TorFramework/TORX25519KeyPair.h 104
    26. SophaxChat/Tor/TorFramework/TORX25519KeyPair.m 109
    27. Sources/SophaxChatCore/Crypto/OnionAddress.swift 73
    28. Sources/SophaxChatCore/Crypto/Keccak.swift 147
    29. Frameworks/tor.xcframework/Info.plist 40
    30. Frameworks/tor.xcframework/ios-arm64/tor.framework/Info.plist 24
    31. Frameworks/tor.xcframework/ios-arm64_x86_64-simulator/tor.framework/Info.plist 24
  8. 08

    Groups

    Group chats: sender keys, and MLS — a standard for group encryption — in a small Rust library joined to Swift.

    1. Sources/SophaxChatCore/Group/GroupTypes.swift 160
    2. Sources/SophaxChatCore/Group/ChatManager+MLS.swift 647
    3. Sources/SophaxChatCore/Group/GroupCryptoMigration.swift 67
    4. Sources/SophaxChatCore/Group/MLSGroupManager.swift 196
    5. Sources/SophaxChatCore/MLS/Generated/sophax_mls.swift 1370
    6. Sources/SophaxChatCore/MLS/Generated/sophax_mlsFFI.h 621
    7. Sources/SophaxChatCore/MLS/Generated/sophax_mlsFFI.modulemap 7
    8. rust/.gitignore 1
    9. rust/Cargo.lock 1929
    10. rust/Cargo.toml 25
    11. rust/bindgen/main.rs 3
    12. rust/build.rs 3
    13. rust/src/lib.rs 391
    14. scripts/build_mls_xcframework.sh 121
  9. 09

    What stays on the phone

    Messages and attachments, kept encrypted on the device; backups and exports that never go to a cloud; an error log that stays private.

    1. Sources/SophaxChatCore/Storage/MessageStore.swift 280
    2. Sources/SophaxChatCore/Storage/AttachmentStore.swift 108
    3. Sources/SophaxChatCore/Storage/BackupManager.swift 172
    4. Sources/SophaxChatCore/Storage/CrashLogManager.swift 118
    5. Sources/SophaxChatCore/Storage/FullExportManager.swift 221
  10. 10

    The iPhone and Mac app

    Everything you see and touch — the SwiftUI screens, settings, the assistant that runs on the device — and the project files, icons and pictures that make the app.

    1. SophaxChat/App/AppState.swift 2055
    2. SophaxChat/App/SophaxChatApp.swift 268
    3. SophaxChat/Views/AI/AIAssistantView.swift 266
    4. SophaxChat/Views/Chat/AudioMessageView.swift 129
    5. SophaxChat/Views/Chat/CameraPickerView.swift 49
    6. SophaxChat/Views/Chat/ChatListView.swift 1014
    7. SophaxChat/Views/Chat/ChatView.swift 1160
    8. SophaxChat/Views/Chat/ChatViewModel.swift 78
    9. SophaxChat/Views/Chat/CreateGroupView.swift 146
    10. SophaxChat/Views/Chat/FullScreenImageView.swift 67
    11. SophaxChat/Views/Chat/GroupChatView.swift 996
    12. SophaxChat/Views/Chat/GroupChatViewModel.swift 77
    13. SophaxChat/Views/Chat/MessageBubbleView.swift 527
    14. SophaxChat/Views/Chat/NoteToSelfView.swift 126
    15. SophaxChat/Views/Chat/VideoMessageView.swift 113
    16. SophaxChat/Views/Chat/VoiceRecorder.swift 111
    17. SophaxChat/Views/DuressEmptyView.swift 46
    18. SophaxChat/Views/Onboarding/OnboardingView.swift 259
    19. SophaxChat/Views/Settings/AppLockView.swift 121
    20. SophaxChat/Views/Settings/BackupView.swift 180
    21. SophaxChat/Views/Settings/ContactCardView.swift 152
    22. SophaxChat/Views/Settings/ContactScannerView.swift 97
    23. SophaxChat/Views/Settings/CrashLogView.swift 83
    24. SophaxChat/Views/Settings/DuressPINSetupView.swift 164
    25. SophaxChat/Views/Settings/FindByPeerIDView.swift 188
    26. SophaxChat/Views/Settings/FullExportView.swift 232
    27. SophaxChat/Views/Settings/IdentityView.swift 348
    28. SophaxChat/Views/Settings/LinkedDevicesView.swift 229
    29. SophaxChat/Views/Settings/SettingsView.swift 639
    30. SophaxChat/Assets.xcassets/AppIcon.appiconset/Contents.json 30
    31. SophaxChat/Assets.xcassets/Contents.json 6
    32. SophaxChat/Info.plist 109
    33. SophaxChat/NFC/NFCContactManager.swift 144
    34. SophaxChat/PrivacyInfo.xcprivacy 47
    35. SophaxChat/Resources/cs.lproj/Localizable.strings 77
    36. SophaxChat/Resources/en.lproj/Localizable.strings 77
    37. SophaxChat/SophaxChat-Bridging-Header.h 18
    38. SophaxChat/SophaxChat.entitlements 10
    39. SophaxChat.xcodeproj/project.pbxproj 1001
    40. SophaxChat.xcodeproj/project.xcworkspace/contents.xcworkspacedata 7
    41. project.yml 100
    42. Package.swift 34
    43. make_icon.swift 88
  11. 11

    Android

    The same messenger for Android, in Kotlin and Jetpack Compose.

    1. android/README.md 72
    2. android/app/build.gradle.kts 107
    3. android/app/proguard-rules.pro 4
    4. android/app/src/main/AndroidManifest.xml 87
    5. android/app/src/main/kotlin/com/sophax/sophaxchat/.gitkeep 0
    6. android/app/src/main/kotlin/com/sophax/sophaxchat/AppState.kt 780
    7. android/app/src/main/kotlin/com/sophax/sophaxchat/ChatManager.kt 1509
    8. android/app/src/main/kotlin/com/sophax/sophaxchat/MainActivity.kt 255
    9. android/app/src/main/kotlin/com/sophax/sophaxchat/SophaxForegroundService.kt 96
    10. android/app/src/main/kotlin/com/sophax/sophaxchat/SophaxRestartWorker.kt 63
    11. android/app/src/main/kotlin/com/sophax/sophaxchat/crypto/CryptoTypes.kt 91
    12. android/app/src/main/kotlin/com/sophax/sophaxchat/crypto/DoubleRatchet.kt 339
    13. android/app/src/main/kotlin/com/sophax/sophaxchat/crypto/GroupTypes.kt 98
    14. android/app/src/main/kotlin/com/sophax/sophaxchat/crypto/HiddenServiceKeyWriter.kt 77
    15. android/app/src/main/kotlin/com/sophax/sophaxchat/crypto/IdentityManager.kt 232
    16. android/app/src/main/kotlin/com/sophax/sophaxchat/crypto/OnionAddress.kt 72
    17. android/app/src/main/kotlin/com/sophax/sophaxchat/crypto/PreKeyManager.kt 203
    18. android/app/src/main/kotlin/com/sophax/sophaxchat/crypto/X3DH.kt 110
    19. android/app/src/main/kotlin/com/sophax/sophaxchat/network/DHTBootstrap.kt 42
    20. android/app/src/main/kotlin/com/sophax/sophaxchat/network/DHTEngine.kt 455
    21. android/app/src/main/kotlin/com/sophax/sophaxchat/network/DHTStorage.kt 53
    22. android/app/src/main/kotlin/com/sophax/sophaxchat/network/DHTStore.kt 77
    23. android/app/src/main/kotlin/com/sophax/sophaxchat/network/KBucketTable.kt 207
    24. android/app/src/main/kotlin/com/sophax/sophaxchat/network/LanDiscovery.kt 125
    25. android/app/src/main/kotlin/com/sophax/sophaxchat/network/NearbyManager.kt 180
    26. android/app/src/main/kotlin/com/sophax/sophaxchat/network/TcpTransport.kt 230
    27. android/app/src/main/kotlin/com/sophax/sophaxchat/network/TorManager.kt 170
    28. android/app/src/main/kotlin/com/sophax/sophaxchat/network/WifiDirectManager.kt 160
    29. android/app/src/main/kotlin/com/sophax/sophaxchat/notifications/NotificationHelper.kt 64
    30. android/app/src/main/kotlin/com/sophax/sophaxchat/protocol/NetworkProtocol.kt 462
    31. android/app/src/main/kotlin/com/sophax/sophaxchat/storage/AttachmentStore.kt 108
    32. android/app/src/main/kotlin/com/sophax/sophaxchat/storage/MessageStore.kt 161
    33. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/AppLockScreen.kt 196
    34. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/SafetyNumberScreen.kt 138
    35. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/chat/ChatListScreen.kt 250
    36. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/chat/ChatScreen.kt 467
    37. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/chat/CreateGroupScreen.kt 110
    38. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/chat/FindByPeerIDScreen.kt 253
    39. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/chat/GroupChatScreen.kt 379
    40. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/chat/SharedComponents.kt 222
    41. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/onboarding/OnboardingScreen.kt 159
    42. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/settings/BackupScreen.kt 122
    43. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/settings/ContactQRSheet.kt 70
    44. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/settings/DuressPinScreen.kt 252
    45. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/settings/LinkedDevicesScreen.kt 345
    46. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/settings/SettingsScreen.kt 280
    47. android/app/src/main/kotlin/com/sophax/sophaxchat/ui/theme/Theme.kt 43
    48. android/app/src/main/res/drawable/ic_launcher.xml 5
    49. android/app/src/main/res/mipmap-hdpi/ic_launcher_background.xml 4
    50. android/app/src/main/res/mipmap-mdpi/ic_launcher_background.xml 4
    51. android/app/src/main/res/mipmap-xhdpi/ic_launcher_background.xml 4
    52. android/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.xml 4
    53. android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.xml 4
    54. android/app/src/main/res/values/strings.xml 4
    55. android/build.gradle.kts 5
    56. android/gradle.properties 4
    57. android/gradle/libs.versions.toml 51
    58. android/settings.gradle.kts 19
  12. 12

    Tests

    Checks that the cryptography, the groups, the network and the relay behave as they should.

    1. Tests/SophaxChatCoreTests/AdvancedCryptoTests.swift 275
    2. Tests/SophaxChatCoreTests/CryptoTests.swift 422
    3. Tests/SophaxChatCoreTests/MLSGroupManagerTests.swift 206
    4. Tests/SophaxChatCoreTests/NetworkTests.swift 245
    5. Tests/SophaxChatCoreTests/RelayRouterTests.swift 117
  13. 13

    Making and shipping

    Scripts and settings for building, checking and releasing, and notes for anyone who wants to help.

    1. scripts/generate_android_icons.sh 79
    2. scripts/generate_icons.sh 74
    3. scripts/setup-github.sh 226
    4. scripts/setup_frameworks.sh 54
    5. .github/CONTRIBUTING.md 61
    6. .github/FUNDING.yml 11
    7. .github/ISSUE_TEMPLATE/bug_report.md 57
    8. .github/ISSUE_TEMPLATE/feature_request.md 36
    9. .github/pull_request_template.md 43
    10. .github/workflows/android-ci.yml 42
    11. .github/workflows/android-release.yml 66
    12. .github/workflows/codeql.yml 72
    13. .github/workflows/swift.yml 65
    14. .gitignore 56