mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 20:45:19 +00:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2fafe766e | ||
|
|
60b0deee7b | ||
|
|
2f7c0aaaf7 | ||
|
|
7c4c3f1391 | ||
|
|
3c06bd6386 | ||
|
|
acc11101ad | ||
|
|
5fd9140ffa | ||
|
|
e6903456ab | ||
|
|
85f99984c4 | ||
|
|
75c8933091 | ||
|
|
d2bfbbcfd4 |
@@ -71,3 +71,7 @@ __pycache__/
|
|||||||
# Local build results
|
# Local build results
|
||||||
.Result*/
|
.Result*/
|
||||||
.Result*.xcresult/
|
.Result*.xcresult/
|
||||||
|
TestResult.xcresult/
|
||||||
|
*.xcresult/
|
||||||
|
build.log
|
||||||
|
*.log
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
0475028D2E54171C0083520F /* LocationChannelManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0475028B2E54171C0083520F /* LocationChannelManager.swift */; };
|
0475028D2E54171C0083520F /* LocationChannelManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0475028B2E54171C0083520F /* LocationChannelManager.swift */; };
|
||||||
0475028F2E5417660083520F /* LocationChannelsSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0475028E2E5417660083520F /* LocationChannelsSheet.swift */; };
|
0475028F2E5417660083520F /* LocationChannelsSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0475028E2E5417660083520F /* LocationChannelsSheet.swift */; };
|
||||||
047502902E5417660083520F /* LocationChannelsSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0475028E2E5417660083520F /* LocationChannelsSheet.swift */; };
|
047502902E5417660083520F /* LocationChannelsSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0475028E2E5417660083520F /* LocationChannelsSheet.swift */; };
|
||||||
|
|
||||||
047502922E547ACC0083520F /* LocationChannelsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047502912E547ACC0083520F /* LocationChannelsTests.swift */; };
|
047502922E547ACC0083520F /* LocationChannelsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047502912E547ACC0083520F /* LocationChannelsTests.swift */; };
|
||||||
047502932E547ACC0083520F /* LocationChannelsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047502912E547ACC0083520F /* LocationChannelsTests.swift */; };
|
047502932E547ACC0083520F /* LocationChannelsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047502912E547ACC0083520F /* LocationChannelsTests.swift */; };
|
||||||
047502AC2E55E8360083520F /* BinaryProtocolPaddingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047502AB2E55E8360083520F /* BinaryProtocolPaddingTests.swift */; };
|
047502AC2E55E8360083520F /* BinaryProtocolPaddingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047502AB2E55E8360083520F /* BinaryProtocolPaddingTests.swift */; };
|
||||||
@@ -126,6 +127,10 @@
|
|||||||
D691938B4029A04CC905FDC8 /* NoiseSecurityConsiderations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43B4548DAFC9F7AA8873DA53 /* NoiseSecurityConsiderations.swift */; };
|
D691938B4029A04CC905FDC8 /* NoiseSecurityConsiderations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43B4548DAFC9F7AA8873DA53 /* NoiseSecurityConsiderations.swift */; };
|
||||||
D727EA273CB214FC32612469 /* MockBluetoothMeshService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C27328EE574221395B2B8E87 /* MockBluetoothMeshService.swift */; };
|
D727EA273CB214FC32612469 /* MockBluetoothMeshService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C27328EE574221395B2B8E87 /* MockBluetoothMeshService.swift */; };
|
||||||
D782AB596DDB5C846554F7C3 /* NostrIdentity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F8043995007F0D84438EDD9 /* NostrIdentity.swift */; };
|
D782AB596DDB5C846554F7C3 /* NostrIdentity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F8043995007F0D84438EDD9 /* NostrIdentity.swift */; };
|
||||||
|
E0A1B2C3D4E5F6012345678B /* GeoRelayDirectory.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0A1B2C3D4E5F60123456789 /* GeoRelayDirectory.swift */; };
|
||||||
|
E0A1B2C3D4E5F6012345678C /* GeoRelayDirectory.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0A1B2C3D4E5F60123456789 /* GeoRelayDirectory.swift */; };
|
||||||
|
E0A1B2C3D4E5F6012345678D /* relays/online_relays_gps.csv in Resources */ = {isa = PBXBuildFile; fileRef = E0A1B2C3D4E5F6012345678A /* relays/online_relays_gps.csv */; };
|
||||||
|
E0A1B2C3D4E5F6012345678E /* relays/online_relays_gps.csv in Resources */ = {isa = PBXBuildFile; fileRef = E0A1B2C3D4E5F6012345678A /* relays/online_relays_gps.csv */; };
|
||||||
E2DCF7817344F1CCDB8B7B2F /* SecureIdentityStateManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC18D910D6FF2E8B1B6C885 /* SecureIdentityStateManager.swift */; };
|
E2DCF7817344F1CCDB8B7B2F /* SecureIdentityStateManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC18D910D6FF2E8B1B6C885 /* SecureIdentityStateManager.swift */; };
|
||||||
E65BBB6544FE0159F3C6C3A8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */; };
|
E65BBB6544FE0159F3C6C3A8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */; };
|
||||||
EC5241969D2550B97629EBD0 /* SecureLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE7EFB209C86BBD956B749EC /* SecureLogger.swift */; };
|
EC5241969D2550B97629EBD0 /* SecureLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE7EFB209C86BBD956B749EC /* SecureLogger.swift */; };
|
||||||
@@ -136,6 +141,12 @@
|
|||||||
F455F011B3B648ADA233F998 /* BinaryProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */; };
|
F455F011B3B648ADA233F998 /* BinaryProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */; };
|
||||||
FB8819B4C84FAFEF5C36B216 /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 136696FC4436A02D98CE6A77 /* KeychainManager.swift */; };
|
FB8819B4C84FAFEF5C36B216 /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 136696FC4436A02D98CE6A77 /* KeychainManager.swift */; };
|
||||||
FBC409E105493C491531B59A /* NostrProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E5A9FF4AEA8A923317ED26A /* NostrProtocol.swift */; };
|
FBC409E105493C491531B59A /* NostrProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E5A9FF4AEA8A923317ED26A /* NostrProtocol.swift */; };
|
||||||
|
A1B2C3D44E5F60718293A4B5 /* XChaCha20Poly1305Compat.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D44E5F60718293A4B4 /* XChaCha20Poly1305Compat.swift */; };
|
||||||
|
A1B2C3D54E5F60718293A4B6 /* XChaCha20Poly1305Compat.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D44E5F60718293A4B4 /* XChaCha20Poly1305Compat.swift */; };
|
||||||
|
AA77BB11CC22DD33EE44FF55 /* VerificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA77BB10CC22DD33EE44FF55 /* VerificationService.swift */; };
|
||||||
|
AA77BB12CC22DD33EE44FF56 /* VerificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA77BB10CC22DD33EE44FF55 /* VerificationService.swift */; };
|
||||||
|
AA77BB14CC22DD33EE44FF58 /* VerificationViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA77BB13CC22DD33EE44FF57 /* VerificationViews.swift */; };
|
||||||
|
AA77BB15CC22DD33EE44FF59 /* VerificationViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA77BB13CC22DD33EE44FF57 /* VerificationViews.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
@@ -235,6 +246,7 @@
|
|||||||
9AB6BE4ABD7F5088E9865E56 /* NoiseSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoiseSession.swift; sourceTree = "<group>"; };
|
9AB6BE4ABD7F5088E9865E56 /* NoiseSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoiseSession.swift; sourceTree = "<group>"; };
|
||||||
A08E03AA0C63E97C91749AEC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
A08E03AA0C63E97C91749AEC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||||
A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocol.swift; sourceTree = "<group>"; };
|
A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocol.swift; sourceTree = "<group>"; };
|
||||||
|
|
||||||
AA11BB22CC33DD44EE55FF68 /* MessageTextHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageTextHelpers.swift; sourceTree = "<group>"; };
|
AA11BB22CC33DD44EE55FF68 /* MessageTextHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageTextHelpers.swift; sourceTree = "<group>"; };
|
||||||
B1D6A89B36A3D31E590B94E5 /* NoiseHandshakeCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoiseHandshakeCoordinator.swift; sourceTree = "<group>"; };
|
B1D6A89B36A3D31E590B94E5 /* NoiseHandshakeCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoiseHandshakeCoordinator.swift; sourceTree = "<group>"; };
|
||||||
C0DB1DE27F0AAB5092663E8E /* bitchatTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = bitchatTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
C0DB1DE27F0AAB5092663E8E /* bitchatTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = bitchatTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
@@ -243,6 +255,8 @@
|
|||||||
C27328EE574221395B2B8E87 /* MockBluetoothMeshService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockBluetoothMeshService.swift; sourceTree = "<group>"; };
|
C27328EE574221395B2B8E87 /* MockBluetoothMeshService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockBluetoothMeshService.swift; sourceTree = "<group>"; };
|
||||||
D22BF09A49010947CEFE45E2 /* PublicChatE2ETests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicChatE2ETests.swift; sourceTree = "<group>"; };
|
D22BF09A49010947CEFE45E2 /* PublicChatE2ETests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicChatE2ETests.swift; sourceTree = "<group>"; };
|
||||||
D69A18D27F9A565FD6041E12 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
D69A18D27F9A565FD6041E12 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
|
E0A1B2C3D4E5F60123456789 /* GeoRelayDirectory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeoRelayDirectory.swift; sourceTree = "<group>"; };
|
||||||
|
E0A1B2C3D4E5F6012345678A /* relays/online_relays_gps.csv */ = {isa = PBXFileReference; lastKnownFileType = text; path = relays/online_relays_gps.csv; sourceTree = "<group>"; };
|
||||||
E6B8F7B7D55092C2540A7996 /* ChatViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewModel.swift; sourceTree = "<group>"; };
|
E6B8F7B7D55092C2540A7996 /* ChatViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewModel.swift; sourceTree = "<group>"; };
|
||||||
E95DBE6A48626C5AE287245E /* NoiseProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoiseProtocolTests.swift; sourceTree = "<group>"; };
|
E95DBE6A48626C5AE287245E /* NoiseProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoiseProtocolTests.swift; sourceTree = "<group>"; };
|
||||||
EA706D8E5097785414646A8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
|
EA706D8E5097785414646A8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
|
||||||
@@ -252,6 +266,9 @@
|
|||||||
FDC18D910D6FF2E8B1B6C885 /* SecureIdentityStateManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureIdentityStateManager.swift; sourceTree = "<group>"; };
|
FDC18D910D6FF2E8B1B6C885 /* SecureIdentityStateManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureIdentityStateManager.swift; sourceTree = "<group>"; };
|
||||||
FE7CCF2BD78A3F3DAE6DA145 /* MockBLEService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockBLEService.swift; sourceTree = "<group>"; };
|
FE7CCF2BD78A3F3DAE6DA145 /* MockBLEService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockBLEService.swift; sourceTree = "<group>"; };
|
||||||
FF7AF93D874001FBD94C8306 /* bitchat-macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "bitchat-macOS.entitlements"; sourceTree = "<group>"; };
|
FF7AF93D874001FBD94C8306 /* bitchat-macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "bitchat-macOS.entitlements"; sourceTree = "<group>"; };
|
||||||
|
A1B2C3D44E5F60718293A4B4 /* XChaCha20Poly1305Compat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XChaCha20Poly1305Compat.swift; sourceTree = "<group>"; };
|
||||||
|
AA77BB10CC22DD33EE44FF55 /* VerificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerificationService.swift; sourceTree = "<group>"; };
|
||||||
|
AA77BB13CC22DD33EE44FF57 /* VerificationViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerificationViews.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -302,6 +319,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
2F82C5FC8433F4064F079D1F /* bitchat */,
|
2F82C5FC8433F4064F079D1F /* bitchat */,
|
||||||
|
E0A1B2C3D4E5F6012345678A /* relays/online_relays_gps.csv */,
|
||||||
A2E8C336FA1ADBEC03261DFD /* bitchatShareExtension */,
|
A2E8C336FA1ADBEC03261DFD /* bitchatShareExtension */,
|
||||||
C3D98EB3E1B455E321F519F4 /* bitchatTests */,
|
C3D98EB3E1B455E321F519F4 /* bitchatTests */,
|
||||||
9F37F9F2C353B58AC809E93B /* Products */,
|
9F37F9F2C353B58AC809E93B /* Products */,
|
||||||
@@ -321,8 +339,8 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
3A69677D382F1C3D5ED03F7D /* Assets.xcassets */,
|
3A69677D382F1C3D5ED03F7D /* Assets.xcassets */,
|
||||||
FF7AF93D874001FBD94C8306 /* bitchat-macOS.entitlements */,
|
|
||||||
527EB217EFDFAD4CF1C91F07 /* bitchat.entitlements */,
|
527EB217EFDFAD4CF1C91F07 /* bitchat.entitlements */,
|
||||||
|
FF7AF93D874001FBD94C8306 /* bitchat-macOS.entitlements */,
|
||||||
EF625BB3AD919322C01A46B2 /* BitchatApp.swift */,
|
EF625BB3AD919322C01A46B2 /* BitchatApp.swift */,
|
||||||
EA706D8E5097785414646A8E /* Info.plist */,
|
EA706D8E5097785414646A8E /* Info.plist */,
|
||||||
95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */,
|
95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */,
|
||||||
@@ -421,9 +439,11 @@
|
|||||||
A55126E93155456CAA8D6656 /* Views */ = {
|
A55126E93155456CAA8D6656 /* Views */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
AA77BB13CC22DD33EE44FF57 /* VerificationViews.swift */,
|
||||||
047502B22E55FED60083520F /* GeohashPeopleList.swift */,
|
047502B22E55FED60083520F /* GeohashPeopleList.swift */,
|
||||||
047502B32E55FED60083520F /* MeshPeerList.swift */,
|
047502B32E55FED60083520F /* MeshPeerList.swift */,
|
||||||
0475028E2E5417660083520F /* LocationChannelsSheet.swift */,
|
0475028E2E5417660083520F /* LocationChannelsSheet.swift */,
|
||||||
|
|
||||||
763E0DBA9492A654FC0CDCB9 /* AppInfoView.swift */,
|
763E0DBA9492A654FC0CDCB9 /* AppInfoView.swift */,
|
||||||
A08E03AA0C63E97C91749AEC /* ContentView.swift */,
|
A08E03AA0C63E97C91749AEC /* ContentView.swift */,
|
||||||
9195CDC7EB236AFBC9A4D41A /* FingerprintView.swift */,
|
9195CDC7EB236AFBC9A4D41A /* FingerprintView.swift */,
|
||||||
@@ -494,6 +514,7 @@
|
|||||||
D98A3186D7E4C72E35BDF7FE /* Services */ = {
|
D98A3186D7E4C72E35BDF7FE /* Services */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
AA77BB10CC22DD33EE44FF55 /* VerificationService.swift */,
|
||||||
047502B82E560F690083520F /* RelayController.swift */,
|
047502B82E560F690083520F /* RelayController.swift */,
|
||||||
0475028B2E54171C0083520F /* LocationChannelManager.swift */,
|
0475028B2E54171C0083520F /* LocationChannelManager.swift */,
|
||||||
049BD3B02E51F319001A566B /* MessageRouter.swift */,
|
049BD3B02E51F319001A566B /* MessageRouter.swift */,
|
||||||
@@ -515,10 +536,12 @@
|
|||||||
E78C7F4B6769C0A72F5DE544 /* Nostr */ = {
|
E78C7F4B6769C0A72F5DE544 /* Nostr */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
A1B2C3D44E5F60718293A4B4 /* XChaCha20Poly1305Compat.swift */,
|
||||||
049BD39B2E51DBD9001A566B /* NostrEmbeddedBitChat.swift */,
|
049BD39B2E51DBD9001A566B /* NostrEmbeddedBitChat.swift */,
|
||||||
5F8043995007F0D84438EDD9 /* NostrIdentity.swift */,
|
5F8043995007F0D84438EDD9 /* NostrIdentity.swift */,
|
||||||
2E5A9FF4AEA8A923317ED26A /* NostrProtocol.swift */,
|
2E5A9FF4AEA8A923317ED26A /* NostrProtocol.swift */,
|
||||||
78595178957244CBDF7E79B6 /* NostrRelayManager.swift */,
|
78595178957244CBDF7E79B6 /* NostrRelayManager.swift */,
|
||||||
|
E0A1B2C3D4E5F60123456789 /* GeoRelayDirectory.swift */,
|
||||||
);
|
);
|
||||||
path = Nostr;
|
path = Nostr;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -683,6 +706,7 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
7DD72D928FF9DD3CA81B46B0 /* Assets.xcassets in Resources */,
|
7DD72D928FF9DD3CA81B46B0 /* Assets.xcassets in Resources */,
|
||||||
|
E0A1B2C3D4E5F6012345678D /* relays/online_relays_gps.csv in Resources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@@ -692,6 +716,7 @@
|
|||||||
files = (
|
files = (
|
||||||
BCCFEDC1EBE59323C3C470BF /* Assets.xcassets in Resources */,
|
BCCFEDC1EBE59323C3C470BF /* Assets.xcassets in Resources */,
|
||||||
E65BBB6544FE0159F3C6C3A8 /* LaunchScreen.storyboard in Resources */,
|
E65BBB6544FE0159F3C6C3A8 /* LaunchScreen.storyboard in Resources */,
|
||||||
|
E0A1B2C3D4E5F6012345678E /* relays/online_relays_gps.csv in Resources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@@ -710,6 +735,9 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
AA77BB12CC22DD33EE44FF56 /* VerificationService.swift in Sources */,
|
||||||
|
AA77BB15CC22DD33EE44FF59 /* VerificationViews.swift in Sources */,
|
||||||
|
A1B2C3D54E5F60718293A4B6 /* XChaCha20Poly1305Compat.swift in Sources */,
|
||||||
AD11E46940D742AEAF547EB2 /* AppInfoView.swift in Sources */,
|
AD11E46940D742AEAF547EB2 /* AppInfoView.swift in Sources */,
|
||||||
9B51E9B63A3EA59B1A7874BD /* BinaryEncodingUtils.swift in Sources */,
|
9B51E9B63A3EA59B1A7874BD /* BinaryEncodingUtils.swift in Sources */,
|
||||||
049BD3B42E51F319001A566B /* NostrTransport.swift in Sources */,
|
049BD3B42E51F319001A566B /* NostrTransport.swift in Sources */,
|
||||||
@@ -730,6 +758,7 @@
|
|||||||
7241FFD6CFFB875B864FA223 /* InputValidator.swift in Sources */,
|
7241FFD6CFFB875B864FA223 /* InputValidator.swift in Sources */,
|
||||||
FB8819B4C84FAFEF5C36B216 /* KeychainManager.swift in Sources */,
|
FB8819B4C84FAFEF5C36B216 /* KeychainManager.swift in Sources */,
|
||||||
0475028F2E5417660083520F /* LocationChannelsSheet.swift in Sources */,
|
0475028F2E5417660083520F /* LocationChannelsSheet.swift in Sources */,
|
||||||
|
|
||||||
501BC56B1A08C0327A09AAF1 /* NoiseEncryptionService.swift in Sources */,
|
501BC56B1A08C0327A09AAF1 /* NoiseEncryptionService.swift in Sources */,
|
||||||
0475028C2E54171C0083520F /* LocationChannelManager.swift in Sources */,
|
0475028C2E54171C0083520F /* LocationChannelManager.swift in Sources */,
|
||||||
AFF33EF44626EF0579D17EB1 /* NoiseHandshakeCoordinator.swift in Sources */,
|
AFF33EF44626EF0579D17EB1 /* NoiseHandshakeCoordinator.swift in Sources */,
|
||||||
@@ -756,6 +785,7 @@
|
|||||||
D111988977C3BC246AB27FA4 /* SecureLogger.swift in Sources */,
|
D111988977C3BC246AB27FA4 /* SecureLogger.swift in Sources */,
|
||||||
8DE687D2EB5EB120868DBFB5 /* BLEService.swift in Sources */,
|
8DE687D2EB5EB120868DBFB5 /* BLEService.swift in Sources */,
|
||||||
AA11BB22CC33DD44EE55FF66 /* MessageTextHelpers.swift in Sources */,
|
AA11BB22CC33DD44EE55FF66 /* MessageTextHelpers.swift in Sources */,
|
||||||
|
E0A1B2C3D4E5F6012345678B /* GeoRelayDirectory.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@@ -763,6 +793,9 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
AA77BB11CC22DD33EE44FF55 /* VerificationService.swift in Sources */,
|
||||||
|
AA77BB14CC22DD33EE44FF58 /* VerificationViews.swift in Sources */,
|
||||||
|
A1B2C3D44E5F60718293A4B5 /* XChaCha20Poly1305Compat.swift in Sources */,
|
||||||
ABAF130D88561F4A646F0430 /* AppInfoView.swift in Sources */,
|
ABAF130D88561F4A646F0430 /* AppInfoView.swift in Sources */,
|
||||||
AFB6AEFCABBE97441CB3102B /* BinaryEncodingUtils.swift in Sources */,
|
AFB6AEFCABBE97441CB3102B /* BinaryEncodingUtils.swift in Sources */,
|
||||||
049BD3B22E51F319001A566B /* NostrTransport.swift in Sources */,
|
049BD3B22E51F319001A566B /* NostrTransport.swift in Sources */,
|
||||||
@@ -783,6 +816,7 @@
|
|||||||
EF49C600C1E464710DD6CA29 /* InputValidator.swift in Sources */,
|
EF49C600C1E464710DD6CA29 /* InputValidator.swift in Sources */,
|
||||||
8F737CE0435792CC2AD65FCB /* KeychainManager.swift in Sources */,
|
8F737CE0435792CC2AD65FCB /* KeychainManager.swift in Sources */,
|
||||||
047502902E5417660083520F /* LocationChannelsSheet.swift in Sources */,
|
047502902E5417660083520F /* LocationChannelsSheet.swift in Sources */,
|
||||||
|
|
||||||
5EE49E150BBF0488E7473687 /* NoiseEncryptionService.swift in Sources */,
|
5EE49E150BBF0488E7473687 /* NoiseEncryptionService.swift in Sources */,
|
||||||
0475028D2E54171C0083520F /* LocationChannelManager.swift in Sources */,
|
0475028D2E54171C0083520F /* LocationChannelManager.swift in Sources */,
|
||||||
6D0D4A0B1D8B659DCBAE7C9C /* NoiseHandshakeCoordinator.swift in Sources */,
|
6D0D4A0B1D8B659DCBAE7C9C /* NoiseHandshakeCoordinator.swift in Sources */,
|
||||||
@@ -809,6 +843,7 @@
|
|||||||
EC5241969D2550B97629EBD0 /* SecureLogger.swift in Sources */,
|
EC5241969D2550B97629EBD0 /* SecureLogger.swift in Sources */,
|
||||||
C165DD35BB8E9C327A3C2DA4 /* BLEService.swift in Sources */,
|
C165DD35BB8E9C327A3C2DA4 /* BLEService.swift in Sources */,
|
||||||
AA11BB22CC33DD44EE55FF67 /* MessageTextHelpers.swift in Sources */,
|
AA11BB22CC33DD44EE55FF67 /* MessageTextHelpers.swift in Sources */,
|
||||||
|
E0A1B2C3D4E5F6012345678C /* GeoRelayDirectory.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
+10
-13
@@ -21,6 +21,8 @@ struct BitchatApp: App {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
UNUserNotificationCenter.current().delegate = NotificationDelegate.shared
|
UNUserNotificationCenter.current().delegate = NotificationDelegate.shared
|
||||||
|
// Warm up georelay directory and refresh if stale (once/day)
|
||||||
|
GeoRelayDirectory.shared.prefetchIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
@@ -29,6 +31,13 @@ struct BitchatApp: App {
|
|||||||
.environmentObject(chatViewModel)
|
.environmentObject(chatViewModel)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
NotificationDelegate.shared.chatViewModel = chatViewModel
|
NotificationDelegate.shared.chatViewModel = chatViewModel
|
||||||
|
// Inject live Noise service into VerificationService to avoid creating new BLE instances
|
||||||
|
VerificationService.shared.configure(with: chatViewModel.meshService.getNoiseService())
|
||||||
|
// Prewarm Nostr identity and QR to make first VERIFY sheet fast
|
||||||
|
DispatchQueue.global(qos: .utility).async {
|
||||||
|
let npub = try? NostrIdentityBridge.getCurrentNostrIdentity()?.npub
|
||||||
|
_ = VerificationService.shared.buildMyQRString(nickname: chatViewModel.nickname, npub: npub)
|
||||||
|
}
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
appDelegate.chatViewModel = chatViewModel
|
appDelegate.chatViewModel = chatViewModel
|
||||||
#elseif os(macOS)
|
#elseif os(macOS)
|
||||||
@@ -100,20 +109,8 @@ struct BitchatApp: App {
|
|||||||
userDefaults.removeObject(forKey: "sharedContentDate")
|
userDefaults.removeObject(forKey: "sharedContentDate")
|
||||||
userDefaults.synchronize()
|
userDefaults.synchronize()
|
||||||
|
|
||||||
// Show notification about shared content
|
// Send the shared content immediately on the main queue
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
// Add system message about sharing
|
|
||||||
let systemMessage = BitchatMessage(
|
|
||||||
sender: "system",
|
|
||||||
content: "preparing to share \(contentType)...",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
self.chatViewModel.messages.append(systemMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the shared content after a short delay
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
|
||||||
if contentType == "url" {
|
if contentType == "url" {
|
||||||
// Try to parse as JSON first
|
// Try to parse as JSON first
|
||||||
if let data = sharedContent.data(using: .utf8),
|
if let data = sharedContent.data(using: .utf8),
|
||||||
|
|||||||
@@ -173,56 +173,7 @@ struct PendingActions {
|
|||||||
var setPetname: String?
|
var setPetname: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Privacy Settings
|
//
|
||||||
|
|
||||||
struct PrivacySettings: Codable {
|
|
||||||
// Level 1: Maximum privacy (default)
|
|
||||||
var persistIdentityCache = false
|
|
||||||
var showLastSeen = false
|
|
||||||
|
|
||||||
// Level 2: Convenience
|
|
||||||
var autoAcceptKnownFingerprints = false
|
|
||||||
var rememberNicknameHistory = false
|
|
||||||
|
|
||||||
// Level 3: Social
|
|
||||||
var shareTrustNetworkHints = false // "3 mutual contacts trust this person"
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Conflict Resolution
|
|
||||||
|
|
||||||
/// Strategies for resolving identity conflicts in the decentralized network.
|
|
||||||
/// Handles cases where multiple peers claim the same nickname or when
|
|
||||||
/// identity mappings become ambiguous due to network partitions.
|
|
||||||
enum ConflictResolution {
|
|
||||||
case acceptNew(petname: String) // "John (2)"
|
|
||||||
case rejectNew
|
|
||||||
case blockFingerprint(String)
|
|
||||||
case alertUser(message: String)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - UI State
|
|
||||||
|
|
||||||
struct PeerUIState {
|
|
||||||
let peerID: String
|
|
||||||
let nickname: String
|
|
||||||
var identityState: IdentityState
|
|
||||||
var connectionQuality: ConnectionQuality
|
|
||||||
|
|
||||||
enum IdentityState {
|
|
||||||
case unknown // Gray - No identity info
|
|
||||||
case unverifiedKnown(String) // Blue - Handshake done, matches cache
|
|
||||||
case verified(String) // Green - Cryptographically verified
|
|
||||||
case conflict(String, String) // Red - Nickname doesn't match fingerprint
|
|
||||||
case pending // Yellow - Handshake in progress
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ConnectionQuality {
|
|
||||||
case excellent
|
|
||||||
case good
|
|
||||||
case poor
|
|
||||||
case disconnected
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Migration Support
|
// MARK: - Migration Support
|
||||||
// Removed LegacyFavorite - no longer needed
|
//
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
<string>bitchat uses Bluetooth to discover and connect with other bitchat users nearby.</string>
|
<string>bitchat uses Bluetooth to discover and connect with other bitchat users nearby.</string>
|
||||||
<key>NSLocationWhenInUseUsageDescription</key>
|
<key>NSLocationWhenInUseUsageDescription</key>
|
||||||
<string>bitchat uses your approximate location to compute local geohash channels for optional public chats. Exact GPS is never shared.</string>
|
<string>bitchat uses your approximate location to compute local geohash channels for optional public chats. Exact GPS is never shared.</string>
|
||||||
|
<key>NSCameraUsageDescription</key>
|
||||||
|
<string>bitchat uses the camera to scan QR codes to verify peers.</string>
|
||||||
<key>UIBackgroundModes</key>
|
<key>UIBackgroundModes</key>
|
||||||
<array>
|
<array>
|
||||||
<string>bluetooth-central</string>
|
<string>bluetooth-central</string>
|
||||||
|
|||||||
@@ -89,219 +89,4 @@ struct BitchatPeer: Identifiable, Equatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Peer Manager
|
//
|
||||||
|
|
||||||
/// Manages the collection of peers and their states
|
|
||||||
@MainActor
|
|
||||||
class PeerManager: ObservableObject {
|
|
||||||
@Published var peers: [BitchatPeer] = []
|
|
||||||
@Published var favorites: [BitchatPeer] = []
|
|
||||||
@Published var mutualFavorites: [BitchatPeer] = []
|
|
||||||
|
|
||||||
private let meshService: Transport
|
|
||||||
private let favoritesService = FavoritesPersistenceService.shared
|
|
||||||
|
|
||||||
init(meshService: Transport) {
|
|
||||||
self.meshService = meshService
|
|
||||||
updatePeers()
|
|
||||||
|
|
||||||
// Listen for updates
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
self,
|
|
||||||
selector: #selector(handleFavoriteChanged),
|
|
||||||
name: .favoriteStatusChanged,
|
|
||||||
object: nil
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc private func handleFavoriteChanged() {
|
|
||||||
SecureLogger.log("⭐ Favorite status changed notification received, updating peers",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
updatePeers()
|
|
||||||
}
|
|
||||||
|
|
||||||
deinit {
|
|
||||||
NotificationCenter.default.removeObserver(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
func updatePeers() {
|
|
||||||
// Reduce log verbosity - only log when count changes
|
|
||||||
let previousCount = peers.count
|
|
||||||
|
|
||||||
// Get current mesh peers
|
|
||||||
let meshPeers = meshService.getPeerNicknames()
|
|
||||||
|
|
||||||
// Build peer list
|
|
||||||
var allPeers: [BitchatPeer] = []
|
|
||||||
var connectedNicknames: Set<String> = []
|
|
||||||
var addedPeerIDs: Set<String> = []
|
|
||||||
|
|
||||||
// Add connected mesh peers (only if actually connected or relay connected)
|
|
||||||
for (peerID, nickname) in meshPeers {
|
|
||||||
guard let noiseKey = Data(hexString: peerID) else { continue }
|
|
||||||
|
|
||||||
// Safety check: Never add our own peer ID
|
|
||||||
if peerID == meshService.myPeerID {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if this peer is actually connected
|
|
||||||
let isConnected = meshService.isPeerConnected(peerID)
|
|
||||||
|
|
||||||
// Skip disconnected peers unless they're favorites (handled later)
|
|
||||||
if !isConnected {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if isConnected {
|
|
||||||
connectedNicknames.insert(nickname)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Track that we've added this peer ID
|
|
||||||
addedPeerIDs.insert(peerID)
|
|
||||||
|
|
||||||
var peer = BitchatPeer(
|
|
||||||
id: peerID,
|
|
||||||
noisePublicKey: noiseKey,
|
|
||||||
nickname: nickname,
|
|
||||||
isConnected: isConnected
|
|
||||||
)
|
|
||||||
// Set favorite status - check both by current noise key and by nickname
|
|
||||||
if let favoriteStatus = favoritesService.getFavoriteStatus(for: noiseKey) {
|
|
||||||
peer.favoriteStatus = favoriteStatus
|
|
||||||
peer.nostrPublicKey = favoriteStatus.peerNostrPublicKey
|
|
||||||
} else {
|
|
||||||
// Check if we have a favorite for this nickname (peer may have reconnected with new ID)
|
|
||||||
let favoriteByNickname = favoritesService.favorites.values.first { $0.peerNickname == nickname }
|
|
||||||
if let favorite = favoriteByNickname {
|
|
||||||
SecureLogger.log("🔄 Found favorite for '\(nickname)' by nickname, updating noise key",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
// Update the favorite's noise key to match the current connection
|
|
||||||
favoritesService.updateNoisePublicKey(from: favorite.peerNoisePublicKey, to: noiseKey, peerNickname: nickname)
|
|
||||||
// Get the updated favorite with the new key
|
|
||||||
peer.favoriteStatus = favoritesService.getFavoriteStatus(for: noiseKey)
|
|
||||||
peer.nostrPublicKey = peer.favoriteStatus?.peerNostrPublicKey ?? favorite.peerNostrPublicKey
|
|
||||||
}
|
|
||||||
}
|
|
||||||
allPeers.append(peer)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add offline favorites (only those not currently connected AND that we actively favorite)
|
|
||||||
|
|
||||||
for (favoriteKey, favorite) in favoritesService.favorites {
|
|
||||||
let favoriteID = favorite.peerNoisePublicKey.hexEncodedString()
|
|
||||||
|
|
||||||
// Skip if this peer is already connected (by nickname)
|
|
||||||
if connectedNicknames.contains(favorite.peerNickname) {
|
|
||||||
// Skipping favorite - already connected
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip if we already added a peer with this ID (prevents duplicates)
|
|
||||||
if addedPeerIDs.contains(favoriteID) {
|
|
||||||
// Skipping favorite - peer ID already added
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only add peers that WE favorite (not just ones who favorite us)
|
|
||||||
if !favorite.isFavorite {
|
|
||||||
// Skipping - we don't favorite them
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add this favorite as an offline peer
|
|
||||||
SecureLogger.log(" - Adding offline favorite '\(favorite.peerNickname)' (key: \(favoriteKey.hexEncodedString()), ID: \(favoriteID), mutual: \(favorite.isMutual))",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
var peer = BitchatPeer(
|
|
||||||
id: favoriteID,
|
|
||||||
noisePublicKey: favorite.peerNoisePublicKey,
|
|
||||||
nickname: favorite.peerNickname,
|
|
||||||
isConnected: false
|
|
||||||
)
|
|
||||||
// Set favorite status
|
|
||||||
peer.favoriteStatus = favorite
|
|
||||||
peer.nostrPublicKey = favorite.peerNostrPublicKey
|
|
||||||
addedPeerIDs.insert(favoriteID) // Track that we've added this ID
|
|
||||||
allPeers.append(peer)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter out "Unknown" peers unless they are favorites or have a favorite relationship
|
|
||||||
allPeers = allPeers.filter { peer in
|
|
||||||
!(peer.displayName == "Unknown" && peer.favoriteStatus == nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort: Connected first, then favorites, then alphabetical
|
|
||||||
allPeers.sort { lhs, rhs in
|
|
||||||
// Direct connections first
|
|
||||||
if lhs.isConnected != rhs.isConnected {
|
|
||||||
return lhs.isConnected
|
|
||||||
}
|
|
||||||
// Then favorites
|
|
||||||
if lhs.isFavorite != rhs.isFavorite {
|
|
||||||
return lhs.isFavorite
|
|
||||||
}
|
|
||||||
// Finally alphabetical
|
|
||||||
return lhs.displayName < rhs.displayName
|
|
||||||
}
|
|
||||||
|
|
||||||
// Single pass to compute all subsets and counts
|
|
||||||
var favorites: [BitchatPeer] = []
|
|
||||||
var mutualFavorites: [BitchatPeer] = []
|
|
||||||
var connectedCount = 0
|
|
||||||
var offlineCount = 0
|
|
||||||
|
|
||||||
for peer in allPeers {
|
|
||||||
if peer.isFavorite {
|
|
||||||
favorites.append(peer)
|
|
||||||
}
|
|
||||||
if peer.isMutualFavorite {
|
|
||||||
mutualFavorites.append(peer)
|
|
||||||
}
|
|
||||||
if peer.isConnected {
|
|
||||||
connectedCount += 1
|
|
||||||
} else {
|
|
||||||
offlineCount += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Final safety check: ensure no duplicate IDs
|
|
||||||
var finalPeers: [BitchatPeer] = []
|
|
||||||
var seenIDs: Set<String> = []
|
|
||||||
for peer in allPeers {
|
|
||||||
if !seenIDs.contains(peer.id) {
|
|
||||||
seenIDs.insert(peer.id)
|
|
||||||
finalPeers.append(peer)
|
|
||||||
} else {
|
|
||||||
SecureLogger.log("⚠️ Removing duplicate peer ID in final check: \(peer.id) (\(peer.displayName))",
|
|
||||||
category: SecureLogger.session, level: .warning)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.peers = finalPeers
|
|
||||||
self.favorites = favorites
|
|
||||||
self.mutualFavorites = mutualFavorites
|
|
||||||
|
|
||||||
// Log peer list summary sparingly at debug level
|
|
||||||
if favoritesService.favorites.count > 0 {
|
|
||||||
SecureLogger.log("📊 Peer list update: \(allPeers.count) total (\(connectedCount) connected, \(offlineCount) offline), \(favorites.count) favorites, \(mutualFavorites.count) mutual",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
} else if previousCount != allPeers.count {
|
|
||||||
SecureLogger.log("✅ Updated peer list: \(allPeers.count) total peers",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func toggleFavorite(_ peer: BitchatPeer) {
|
|
||||||
if peer.isFavorite {
|
|
||||||
favoritesService.removeFavorite(peerNoisePublicKey: peer.noisePublicKey)
|
|
||||||
} else {
|
|
||||||
favoritesService.addFavorite(
|
|
||||||
peerNoisePublicKey: peer.noisePublicKey,
|
|
||||||
peerNostrPublicKey: peer.nostrPublicKey,
|
|
||||||
peerNickname: peer.nickname
|
|
||||||
)
|
|
||||||
}
|
|
||||||
updatePeers()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// Directory of online Nostr relays with approximate GPS locations, used for geohash routing.
|
||||||
|
@MainActor
|
||||||
|
final class GeoRelayDirectory {
|
||||||
|
struct Entry: Hashable {
|
||||||
|
let host: String
|
||||||
|
let lat: Double
|
||||||
|
let lon: Double
|
||||||
|
}
|
||||||
|
|
||||||
|
static let shared = GeoRelayDirectory()
|
||||||
|
private(set) var entries: [Entry] = []
|
||||||
|
private let cacheFileName = "georelays_cache.csv"
|
||||||
|
private let lastFetchKey = "georelay.lastFetchAt"
|
||||||
|
private let remoteURL = URL(string: "https://raw.githubusercontent.com/permissionlesstech/georelays/refs/heads/main/nostr_relays.csv")!
|
||||||
|
private let fetchInterval: TimeInterval = 60 * 60 * 24 // 24h
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
// Load cached or bundled data synchronously
|
||||||
|
self.entries = self.loadLocalEntries()
|
||||||
|
// Fire-and-forget remote refresh if stale
|
||||||
|
prefetchIfNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns up to `count` relay URLs (wss://) closest to the geohash center.
|
||||||
|
func closestRelays(toGeohash geohash: String, count: Int = 5) -> [String] {
|
||||||
|
let center = Geohash.decodeCenter(geohash)
|
||||||
|
return closestRelays(toLat: center.lat, lon: center.lon, count: count)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns up to `count` relay URLs (wss://) closest to the given coordinate.
|
||||||
|
func closestRelays(toLat lat: Double, lon: Double, count: Int = 5) -> [String] {
|
||||||
|
guard !entries.isEmpty else { return [] }
|
||||||
|
let sorted = entries
|
||||||
|
.sorted { a, b in
|
||||||
|
haversineKm(lat, lon, a.lat, a.lon) < haversineKm(lat, lon, b.lat, b.lon)
|
||||||
|
}
|
||||||
|
.prefix(count)
|
||||||
|
return sorted.map { "wss://\($0.host)" }
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Remote Fetch
|
||||||
|
func prefetchIfNeeded() {
|
||||||
|
let now = Date()
|
||||||
|
let last = UserDefaults.standard.object(forKey: lastFetchKey) as? Date ?? .distantPast
|
||||||
|
guard now.timeIntervalSince(last) >= fetchInterval else { return }
|
||||||
|
fetchRemote()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func fetchRemote() {
|
||||||
|
let req = URLRequest(url: remoteURL, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 15)
|
||||||
|
let task = URLSession.shared.dataTask(with: req) { [weak self] data, _, error in
|
||||||
|
guard let self = self else { return }
|
||||||
|
if let data = data, error == nil, let text = String(data: data, encoding: .utf8) {
|
||||||
|
let parsed = GeoRelayDirectory.parseCSV(text)
|
||||||
|
if !parsed.isEmpty {
|
||||||
|
Task { @MainActor in
|
||||||
|
self.entries = parsed
|
||||||
|
self.persistCache(text)
|
||||||
|
UserDefaults.standard.set(Date(), forKey: self.lastFetchKey)
|
||||||
|
SecureLogger.log("GeoRelayDirectory: refreshed \(parsed.count) relays from remote", category: SecureLogger.session, level: .info)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SecureLogger.log("GeoRelayDirectory: remote fetch failed; keeping local entries", category: SecureLogger.session, level: .warning)
|
||||||
|
}
|
||||||
|
task.resume()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func persistCache(_ text: String) {
|
||||||
|
guard let url = cacheURL() else { return }
|
||||||
|
do {
|
||||||
|
try text.data(using: .utf8)?.write(to: url, options: .atomic)
|
||||||
|
} catch {
|
||||||
|
SecureLogger.log("GeoRelayDirectory: failed to write cache: \(error)", category: SecureLogger.session, level: .warning)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Loading
|
||||||
|
private func loadLocalEntries() -> [Entry] {
|
||||||
|
// Prefer cached file if present
|
||||||
|
if let cache = self.cacheURL(),
|
||||||
|
let data = try? Data(contentsOf: cache),
|
||||||
|
let text = String(data: data, encoding: .utf8) {
|
||||||
|
let arr = Self.parseCSV(text)
|
||||||
|
if !arr.isEmpty { return arr }
|
||||||
|
}
|
||||||
|
// Try bundled resource(s)
|
||||||
|
let bundleCandidates = [
|
||||||
|
Bundle.main.url(forResource: "nostr_relays", withExtension: "csv"),
|
||||||
|
Bundle.main.url(forResource: "online_relays_gps", withExtension: "csv"),
|
||||||
|
Bundle.main.url(forResource: "online_relays_gps", withExtension: "csv", subdirectory: "relays")
|
||||||
|
].compactMap { $0 }
|
||||||
|
for url in bundleCandidates {
|
||||||
|
if let data = try? Data(contentsOf: url), let text = String(data: data, encoding: .utf8) {
|
||||||
|
let arr = Self.parseCSV(text)
|
||||||
|
if !arr.isEmpty { return arr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Try filesystem path (development/test)
|
||||||
|
if let cwd = FileManager.default.currentDirectoryPath as String?,
|
||||||
|
let data = try? Data(contentsOf: URL(fileURLWithPath: cwd).appendingPathComponent("relays/online_relays_gps.csv")),
|
||||||
|
let text = String(data: data, encoding: .utf8) {
|
||||||
|
return Self.parseCSV(text)
|
||||||
|
}
|
||||||
|
SecureLogger.log("GeoRelayDirectory: no local CSV found; entries empty", category: SecureLogger.session, level: .warning)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
nonisolated static func parseCSV(_ text: String) -> [Entry] {
|
||||||
|
var result: Set<Entry> = []
|
||||||
|
let lines = text.split(whereSeparator: { $0.isNewline })
|
||||||
|
// Skip header if present
|
||||||
|
for (idx, raw) in lines.enumerated() {
|
||||||
|
let line = raw.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
if line.isEmpty { continue }
|
||||||
|
if idx == 0 && line.lowercased().contains("relay url") { continue }
|
||||||
|
let parts = line.split(separator: ",").map { String($0).trimmingCharacters(in: .whitespaces) }
|
||||||
|
guard parts.count >= 3 else { continue }
|
||||||
|
var host = parts[0]
|
||||||
|
host = host.replacingOccurrences(of: "https://", with: "")
|
||||||
|
host = host.replacingOccurrences(of: "http://", with: "")
|
||||||
|
host = host.replacingOccurrences(of: "wss://", with: "")
|
||||||
|
host = host.replacingOccurrences(of: "ws://", with: "")
|
||||||
|
host = host.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
|
||||||
|
guard let lat = Double(parts[1]), let lon = Double(parts[2]) else { continue }
|
||||||
|
result.insert(Entry(host: host, lat: lat, lon: lon))
|
||||||
|
}
|
||||||
|
return Array(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func cacheURL() -> URL? {
|
||||||
|
do {
|
||||||
|
let base = try FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
|
||||||
|
let dir = base.appendingPathComponent("bitchat", isDirectory: true)
|
||||||
|
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||||||
|
return dir.appendingPathComponent(cacheFileName)
|
||||||
|
} catch { return nil }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Distance
|
||||||
|
private func haversineKm(_ lat1: Double, _ lon1: Double, _ lat2: Double, _ lon2: Double) -> Double {
|
||||||
|
let r = 6371.0 // Earth radius in km
|
||||||
|
let dLat = (lat2 - lat1) * .pi / 180
|
||||||
|
let dLon = (lon2 - lon1) * .pi / 180
|
||||||
|
let a = sin(dLat/2) * sin(dLat/2) + cos(lat1 * .pi/180) * cos(lat2 * .pi/180) * sin(dLon/2) * sin(dLon/2)
|
||||||
|
let c = 2 * atan2(sqrt(a), sqrt(1 - a))
|
||||||
|
return r * c
|
||||||
|
}
|
||||||
+101
-131
@@ -1,6 +1,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import CryptoKit
|
import CryptoKit
|
||||||
import P256K
|
import P256K
|
||||||
|
import Security
|
||||||
|
|
||||||
// Note: This file depends on Data extension from BinaryEncodingUtils.swift
|
// Note: This file depends on Data extension from BinaryEncodingUtils.swift
|
||||||
// Make sure BinaryEncodingUtils.swift is included in the target
|
// Make sure BinaryEncodingUtils.swift is included in the target
|
||||||
@@ -12,8 +13,9 @@ struct NostrProtocol {
|
|||||||
enum EventKind: Int {
|
enum EventKind: Int {
|
||||||
case metadata = 0
|
case metadata = 0
|
||||||
case textNote = 1
|
case textNote = 1
|
||||||
|
case dm = 14 // NIP-17 DM rumor kind
|
||||||
case seal = 13 // NIP-17 sealed event
|
case seal = 13 // NIP-17 sealed event
|
||||||
case giftWrap = 1059 // NIP-17 gift wrap
|
case giftWrap = 1059 // NIP-59 gift wrap
|
||||||
case ephemeralEvent = 20000
|
case ephemeralEvent = 20000
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@ struct NostrProtocol {
|
|||||||
let rumor = NostrEvent(
|
let rumor = NostrEvent(
|
||||||
pubkey: senderIdentity.publicKeyHex,
|
pubkey: senderIdentity.publicKeyHex,
|
||||||
createdAt: Date(),
|
createdAt: Date(),
|
||||||
kind: .textNote,
|
kind: .dm, // NIP-17: DM rumor kind 14
|
||||||
tags: [],
|
tags: [],
|
||||||
content: content
|
content: content
|
||||||
)
|
)
|
||||||
@@ -120,8 +122,8 @@ struct NostrProtocol {
|
|||||||
tags: tags,
|
tags: tags,
|
||||||
content: content
|
content: content
|
||||||
)
|
)
|
||||||
let signingKey = try senderIdentity.signingKey()
|
let schnorrKey = try senderIdentity.schnorrSigningKey()
|
||||||
return try event.sign(with: signingKey)
|
return try event.sign(with: schnorrKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Private Methods
|
// MARK: - Private Methods
|
||||||
@@ -147,9 +149,8 @@ struct NostrProtocol {
|
|||||||
content: encrypted
|
content: encrypted
|
||||||
)
|
)
|
||||||
|
|
||||||
// Convert to P256K.Signing.PrivateKey for signing (temporary until we update sign method)
|
// Sign the seal with the sender's Schnorr private key
|
||||||
let signingKey = try P256K.Signing.PrivateKey(dataRepresentation: senderKey.dataRepresentation)
|
return try seal.sign(with: senderKey)
|
||||||
return try seal.sign(with: signingKey)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func createGiftWrap(
|
private static func createGiftWrap(
|
||||||
@@ -179,9 +180,8 @@ struct NostrProtocol {
|
|||||||
content: encrypted
|
content: encrypted
|
||||||
)
|
)
|
||||||
|
|
||||||
// Convert to P256K.Signing.PrivateKey for signing (temporary until we update sign method)
|
// Sign the gift wrap with the wrap Schnorr private key
|
||||||
let signingKey = try P256K.Signing.PrivateKey(dataRepresentation: wrapKey.dataRepresentation)
|
return try giftWrap.sign(with: wrapKey)
|
||||||
return try giftWrap.sign(with: signingKey)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func unwrapGiftWrap(
|
private static func unwrapGiftWrap(
|
||||||
@@ -227,7 +227,7 @@ struct NostrProtocol {
|
|||||||
return try NostrEvent(from: rumorDict)
|
return try NostrEvent(from: rumorDict)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Encryption (NIP-44 style)
|
// MARK: - Encryption (NIP-44 v2)
|
||||||
|
|
||||||
private static func encrypt(
|
private static func encrypt(
|
||||||
plaintext: String,
|
plaintext: String,
|
||||||
@@ -239,33 +239,31 @@ struct NostrProtocol {
|
|||||||
throw NostrError.invalidPublicKey
|
throw NostrError.invalidPublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encrypting message
|
// Encrypting message (NIP-44 v2: XChaCha20-Poly1305, versioned)
|
||||||
|
|
||||||
// Derive shared secret
|
// Derive shared secret
|
||||||
let sharedSecret = try deriveSharedSecret(
|
let sharedSecret = try deriveSharedSecret(
|
||||||
privateKey: senderKey,
|
privateKey: senderKey,
|
||||||
publicKey: recipientPubkeyData
|
publicKey: recipientPubkeyData
|
||||||
)
|
)
|
||||||
|
// Derive NIP-44 v2 symmetric key (HKDF-SHA256 with label in info)
|
||||||
|
let key = try deriveNIP44V2Key(from: sharedSecret)
|
||||||
|
|
||||||
// Derived shared secret
|
// 24-byte random nonce for XChaCha20-Poly1305
|
||||||
|
var nonce24 = Data(count: 24)
|
||||||
|
_ = nonce24.withUnsafeMutableBytes { ptr in
|
||||||
|
SecRandomCopyBytes(kSecRandomDefault, 24, ptr.baseAddress!)
|
||||||
|
}
|
||||||
|
|
||||||
// Generate nonce
|
let pt = Data(plaintext.utf8)
|
||||||
let nonce = AES.GCM.Nonce()
|
let sealed = try XChaCha20Poly1305Compat.seal(plaintext: pt, key: key, nonce24: nonce24)
|
||||||
|
|
||||||
// Encrypt
|
// v2: base64url(nonce24 || ciphertext || tag)
|
||||||
let sealed = try AES.GCM.seal(
|
var combined = Data()
|
||||||
plaintext.data(using: .utf8)!,
|
combined.append(nonce24)
|
||||||
using: SymmetricKey(data: sharedSecret),
|
combined.append(sealed.ciphertext)
|
||||||
nonce: nonce
|
combined.append(sealed.tag)
|
||||||
)
|
return "v2:" + base64URLEncode(combined)
|
||||||
|
|
||||||
// Combine nonce + ciphertext + tag
|
|
||||||
var result = Data()
|
|
||||||
result.append(nonce.withUnsafeBytes { Data($0) })
|
|
||||||
result.append(sealed.ciphertext)
|
|
||||||
result.append(sealed.tag)
|
|
||||||
|
|
||||||
return result.base64EncodedString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func decrypt(
|
private static func decrypt(
|
||||||
@@ -273,86 +271,45 @@ struct NostrProtocol {
|
|||||||
senderPubkey: String,
|
senderPubkey: String,
|
||||||
recipientKey: P256K.Schnorr.PrivateKey
|
recipientKey: P256K.Schnorr.PrivateKey
|
||||||
) throws -> String {
|
) throws -> String {
|
||||||
|
// Expect NIP-44 v2 format
|
||||||
// Decrypting message
|
guard ciphertext.hasPrefix("v2:") else { throw NostrError.invalidCiphertext }
|
||||||
|
let encoded = String(ciphertext.dropFirst(3))
|
||||||
guard let data = Data(base64Encoded: ciphertext),
|
guard let data = base64URLDecode(encoded),
|
||||||
|
data.count > (24 + 16),
|
||||||
let senderPubkeyData = Data(hexString: senderPubkey) else {
|
let senderPubkeyData = Data(hexString: senderPubkey) else {
|
||||||
SecureLogger.log("❌ Invalid ciphertext or sender pubkey format",
|
|
||||||
category: SecureLogger.session, level: .error)
|
|
||||||
throw NostrError.invalidCiphertext
|
throw NostrError.invalidCiphertext
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ciphertext data parsed
|
let nonce24 = data.prefix(24)
|
||||||
|
let rest = data.dropFirst(24)
|
||||||
// Extract components
|
let tag = rest.suffix(16)
|
||||||
let nonceData = data.prefix(12)
|
let ct = rest.dropLast(16)
|
||||||
let ciphertextData = data.dropFirst(12).dropLast(16)
|
|
||||||
let tagData = data.suffix(16)
|
// Try decryption with even-Y then odd-Y when sender pubkey is x-only
|
||||||
|
func attemptDecrypt(using pubKeyData: Data) throws -> Data {
|
||||||
// Components parsed
|
let ss = try deriveSharedSecret(privateKey: recipientKey, publicKey: pubKeyData)
|
||||||
|
let key = try deriveNIP44V2Key(from: ss)
|
||||||
// Derive shared secret - try with default Y coordinate first
|
return try XChaCha20Poly1305Compat.open(
|
||||||
var sharedSecret: Data
|
ciphertext: Data(ct),
|
||||||
var decrypted: Data? = nil
|
tag: Data(tag),
|
||||||
|
key: key,
|
||||||
do {
|
nonce24: Data(nonce24)
|
||||||
sharedSecret = try deriveSharedSecret(
|
|
||||||
privateKey: recipientKey,
|
|
||||||
publicKey: senderPubkeyData
|
|
||||||
)
|
)
|
||||||
// Derived shared secret with first Y coordinate
|
}
|
||||||
|
|
||||||
// Try to decrypt
|
// If 32 bytes (x-only) try both parities, otherwise single try
|
||||||
let sealedBox = try AES.GCM.SealedBox(
|
if senderPubkeyData.count == 32 {
|
||||||
nonce: AES.GCM.Nonce(data: nonceData),
|
let even = Data([0x02]) + senderPubkeyData
|
||||||
ciphertext: ciphertextData,
|
if let pt = try? attemptDecrypt(using: even) {
|
||||||
tag: tagData
|
return String(data: pt, encoding: .utf8) ?? ""
|
||||||
)
|
|
||||||
|
|
||||||
do {
|
|
||||||
decrypted = try AES.GCM.open(
|
|
||||||
sealedBox,
|
|
||||||
using: SymmetricKey(data: sharedSecret)
|
|
||||||
)
|
|
||||||
// AES-GCM decryption successful
|
|
||||||
} catch {
|
|
||||||
// AES-GCM decryption failed, trying alternate
|
|
||||||
|
|
||||||
// If the sender pubkey is x-only (32 bytes), try the other Y coordinate
|
|
||||||
if senderPubkeyData.count == 32 {
|
|
||||||
// Trying alternate Y coordinate
|
|
||||||
|
|
||||||
// Force deriveSharedSecret to use odd Y by manipulating the data
|
|
||||||
var altPubkey = Data()
|
|
||||||
altPubkey.append(0x03) // Force odd Y
|
|
||||||
altPubkey.append(senderPubkeyData)
|
|
||||||
|
|
||||||
sharedSecret = try deriveSharedSecretDirect(
|
|
||||||
privateKey: recipientKey,
|
|
||||||
publicKey: altPubkey
|
|
||||||
)
|
|
||||||
|
|
||||||
decrypted = try AES.GCM.open(
|
|
||||||
sealedBox,
|
|
||||||
using: SymmetricKey(data: sharedSecret)
|
|
||||||
)
|
|
||||||
// AES-GCM decryption successful with alternate Y
|
|
||||||
} else {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch {
|
let odd = Data([0x03]) + senderPubkeyData
|
||||||
SecureLogger.log("❌ Failed to derive shared secret or decrypt: \(error)",
|
let pt = try attemptDecrypt(using: odd)
|
||||||
category: SecureLogger.session, level: .error)
|
return String(data: pt, encoding: .utf8) ?? ""
|
||||||
throw error
|
} else {
|
||||||
|
let pt = try attemptDecrypt(using: senderPubkeyData)
|
||||||
|
return String(data: pt, encoding: .utf8) ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let finalDecrypted = decrypted else {
|
|
||||||
throw NostrError.encryptionFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
return String(data: finalDecrypted, encoding: .utf8) ?? ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func deriveSharedSecret(
|
private static func deriveSharedSecret(
|
||||||
@@ -412,17 +369,8 @@ struct NostrProtocol {
|
|||||||
let sharedSecretData = sharedSecret.withUnsafeBytes { Data($0) }
|
let sharedSecretData = sharedSecret.withUnsafeBytes { Data($0) }
|
||||||
// ECDH shared secret derived
|
// ECDH shared secret derived
|
||||||
|
|
||||||
// Derive key using HKDF for NIP-44 v2
|
// Return raw ECDH shared secret; HKDF is applied by deriveNIP44V2Key
|
||||||
let derivedKey = HKDF<CryptoKit.SHA256>.deriveKey(
|
return sharedSecretData
|
||||||
inputKeyMaterial: SymmetricKey(data: sharedSecretData),
|
|
||||||
salt: "nip44-v2".data(using: .utf8)!,
|
|
||||||
info: Data(),
|
|
||||||
outputByteCount: 32
|
|
||||||
)
|
|
||||||
|
|
||||||
let result = derivedKey.withUnsafeBytes { Data($0) }
|
|
||||||
// Final derived key ready
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Direct version that doesn't try to add prefixes
|
// Direct version that doesn't try to add prefixes
|
||||||
@@ -452,15 +400,8 @@ struct NostrProtocol {
|
|||||||
// Convert SharedSecret to Data
|
// Convert SharedSecret to Data
|
||||||
let sharedSecretData = sharedSecret.withUnsafeBytes { Data($0) }
|
let sharedSecretData = sharedSecret.withUnsafeBytes { Data($0) }
|
||||||
|
|
||||||
// Derive key using HKDF for NIP-44 v2
|
// Return raw ECDH shared secret; HKDF is applied by deriveNIP44V2Key
|
||||||
let derivedKey = HKDF<CryptoKit.SHA256>.deriveKey(
|
return sharedSecretData
|
||||||
inputKeyMaterial: SymmetricKey(data: sharedSecretData),
|
|
||||||
salt: "nip44-v2".data(using: .utf8)!,
|
|
||||||
info: Data(),
|
|
||||||
outputByteCount: 32
|
|
||||||
)
|
|
||||||
|
|
||||||
return derivedKey.withUnsafeBytes { Data($0) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func randomizedTimestamp() -> Date {
|
private static func randomizedTimestamp() -> Date {
|
||||||
@@ -473,7 +414,7 @@ struct NostrProtocol {
|
|||||||
|
|
||||||
// Log with explicit UTC and local time for debugging
|
// Log with explicit UTC and local time for debugging
|
||||||
let formatter = DateFormatter()
|
let formatter = DateFormatter()
|
||||||
// Removed unnecessary date formatting operations
|
//
|
||||||
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
||||||
formatter.timeZone = TimeZone(abbreviation: "UTC")
|
formatter.timeZone = TimeZone(abbreviation: "UTC")
|
||||||
|
|
||||||
@@ -529,16 +470,16 @@ struct NostrEvent: Codable {
|
|||||||
self.sig = dict["sig"] as? String
|
self.sig = dict["sig"] as? String
|
||||||
}
|
}
|
||||||
|
|
||||||
func sign(with key: P256K.Signing.PrivateKey) throws -> NostrEvent {
|
func sign(with key: P256K.Schnorr.PrivateKey) throws -> NostrEvent {
|
||||||
let (eventId, eventIdHash) = try calculateEventId()
|
let (eventId, eventIdHash) = try calculateEventId()
|
||||||
|
|
||||||
// Convert to Schnorr key for Nostr signing
|
// Sign with Schnorr (BIP-340)
|
||||||
let schnorrKey = try P256K.Schnorr.PrivateKey(dataRepresentation: key.dataRepresentation)
|
|
||||||
|
|
||||||
// Sign with Schnorr
|
|
||||||
var messageBytes = [UInt8](eventIdHash)
|
var messageBytes = [UInt8](eventIdHash)
|
||||||
var auxRand = [UInt8](repeating: 0, count: 32) // Zero auxiliary randomness for deterministic signing
|
var auxRand = [UInt8](repeating: 0, count: 32)
|
||||||
let schnorrSignature = try schnorrKey.signature(message: &messageBytes, auxiliaryRand: &auxRand)
|
_ = auxRand.withUnsafeMutableBytes { ptr in
|
||||||
|
SecRandomCopyBytes(kSecRandomDefault, 32, ptr.baseAddress!)
|
||||||
|
}
|
||||||
|
let schnorrSignature = try key.signature(message: &messageBytes, auxiliaryRand: &auxRand)
|
||||||
|
|
||||||
let signatureHex = schnorrSignature.dataRepresentation.hexEncodedString()
|
let signatureHex = schnorrSignature.dataRepresentation.hexEncodedString()
|
||||||
|
|
||||||
@@ -581,3 +522,32 @@ enum NostrError: Error {
|
|||||||
case signingFailed
|
case signingFailed
|
||||||
case encryptionFailed
|
case encryptionFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - NIP-44 v2 helpers (XChaCha20-Poly1305 + base64url)
|
||||||
|
|
||||||
|
private extension NostrProtocol {
|
||||||
|
static func base64URLEncode(_ data: Data) -> String {
|
||||||
|
return data.base64EncodedString()
|
||||||
|
.replacingOccurrences(of: "+", with: "-")
|
||||||
|
.replacingOccurrences(of: "/", with: "_")
|
||||||
|
.replacingOccurrences(of: "=", with: "")
|
||||||
|
}
|
||||||
|
|
||||||
|
static func base64URLDecode(_ s: String) -> Data? {
|
||||||
|
var str = s
|
||||||
|
let pad = (4 - (str.count % 4)) % 4
|
||||||
|
if pad > 0 { str += String(repeating: "=", count: pad) }
|
||||||
|
str = str.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
|
||||||
|
return Data(base64Encoded: str)
|
||||||
|
}
|
||||||
|
|
||||||
|
static func deriveNIP44V2Key(from sharedSecretData: Data) throws -> Data {
|
||||||
|
let derivedKey = HKDF<CryptoKit.SHA256>.deriveKey(
|
||||||
|
inputKeyMaterial: SymmetricKey(data: sharedSecretData),
|
||||||
|
salt: Data(),
|
||||||
|
info: "nip44-v2".data(using: .utf8)!,
|
||||||
|
outputByteCount: 32
|
||||||
|
)
|
||||||
|
return derivedKey.withUnsafeBytes { Data($0) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -78,9 +78,23 @@ class NostrRelayManager: ObservableObject {
|
|||||||
updateConnectionStatus()
|
updateConnectionStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ensure connections exist to the given relay URLs (idempotent).
|
||||||
|
func ensureConnections(to relayUrls: [String]) {
|
||||||
|
let existing = Set(relays.map { $0.url })
|
||||||
|
for url in Set(relayUrls) {
|
||||||
|
if !existing.contains(url) {
|
||||||
|
relays.append(Relay(url: url))
|
||||||
|
}
|
||||||
|
if connections[url] == nil {
|
||||||
|
connectToRelay(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Send an event to specified relays (or all if none specified)
|
/// Send an event to specified relays (or all if none specified)
|
||||||
func sendEvent(_ event: NostrEvent, to relayUrls: [String]? = nil) {
|
func sendEvent(_ event: NostrEvent, to relayUrls: [String]? = nil) {
|
||||||
let targetRelays = relayUrls ?? relays.map { $0.url }
|
let targetRelays = relayUrls ?? Self.defaultRelays
|
||||||
|
ensureConnections(to: targetRelays)
|
||||||
|
|
||||||
// Add to queue for reliability
|
// Add to queue for reliability
|
||||||
messageQueueLock.lock()
|
messageQueueLock.lock()
|
||||||
@@ -95,10 +109,11 @@ class NostrRelayManager: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Subscribe to events matching a filter
|
/// Subscribe to events matching a filter. If `relayUrls` provided, targets only those relays.
|
||||||
func subscribe(
|
func subscribe(
|
||||||
filter: NostrFilter,
|
filter: NostrFilter,
|
||||||
id: String = UUID().uuidString,
|
id: String = UUID().uuidString,
|
||||||
|
relayUrls: [String]? = nil,
|
||||||
handler: @escaping (NostrEvent) -> Void
|
handler: @escaping (NostrEvent) -> Void
|
||||||
) {
|
) {
|
||||||
messageHandlers[id] = handler
|
messageHandlers[id] = handler
|
||||||
@@ -120,8 +135,14 @@ class NostrRelayManager: ObservableObject {
|
|||||||
// SecureLogger.log("📋 Subscription filter JSON: \(messageString.prefix(200))...",
|
// SecureLogger.log("📋 Subscription filter JSON: \(messageString.prefix(200))...",
|
||||||
// category: SecureLogger.session, level: .debug)
|
// category: SecureLogger.session, level: .debug)
|
||||||
|
|
||||||
// Send subscription to all connected relays
|
// Target specific relays if provided; else all connections
|
||||||
for (relayUrl, connection) in connections {
|
let urls = relayUrls ?? Self.defaultRelays
|
||||||
|
ensureConnections(to: urls)
|
||||||
|
let targets: [(String, URLSessionWebSocketTask)] = urls.compactMap { url in
|
||||||
|
connections[url].map { (url, $0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
for (relayUrl, connection) in targets {
|
||||||
connection.send(.string(messageString)) { error in
|
connection.send(.string(messageString)) { error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
SecureLogger.log("❌ Failed to send subscription to \(relayUrl): \(error)",
|
SecureLogger.log("❌ Failed to send subscription to \(relayUrl): \(error)",
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import Foundation
|
||||||
|
import CryptoKit
|
||||||
|
|
||||||
|
/// Minimal XChaCha20-Poly1305 compatibility wrapper using CryptoKit's ChaChaPoly.
|
||||||
|
/// Implements HChaCha20 to derive a subkey and reduces the 24-byte nonce to a 12-byte nonce
|
||||||
|
/// as per XChaCha20 construction.
|
||||||
|
enum XChaCha20Poly1305Compat {
|
||||||
|
struct SealBox {
|
||||||
|
let ciphertext: Data
|
||||||
|
let tag: Data
|
||||||
|
}
|
||||||
|
|
||||||
|
static func seal(plaintext: Data, key: Data, nonce24: Data, aad: Data? = nil) throws -> SealBox {
|
||||||
|
precondition(key.count == 32, "XChaCha20 key must be 32 bytes")
|
||||||
|
precondition(nonce24.count == 24, "XChaCha20 nonce must be 24 bytes")
|
||||||
|
|
||||||
|
let subkey = hchacha20(key: key, nonce16: nonce24.prefix(16))
|
||||||
|
let nonce12 = derive12ByteNonce(from24: nonce24)
|
||||||
|
let chachaKey = SymmetricKey(data: subkey)
|
||||||
|
let nonce = try ChaChaPoly.Nonce(data: nonce12)
|
||||||
|
let sealed = try ChaChaPoly.seal(plaintext, using: chachaKey, nonce: nonce, authenticating: aad ?? Data())
|
||||||
|
return SealBox(ciphertext: sealed.ciphertext, tag: sealed.tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
static func open(ciphertext: Data, tag: Data, key: Data, nonce24: Data, aad: Data? = nil) throws -> Data {
|
||||||
|
precondition(key.count == 32, "XChaCha20 key must be 32 bytes")
|
||||||
|
precondition(nonce24.count == 24, "XChaCha20 nonce must be 24 bytes")
|
||||||
|
|
||||||
|
let subkey = hchacha20(key: key, nonce16: nonce24.prefix(16))
|
||||||
|
let nonce12 = derive12ByteNonce(from24: nonce24)
|
||||||
|
let chachaKey = SymmetricKey(data: subkey)
|
||||||
|
let box = try ChaChaPoly.SealedBox(nonce: ChaChaPoly.Nonce(data: nonce12), ciphertext: ciphertext, tag: tag)
|
||||||
|
return try ChaChaPoly.open(box, using: chachaKey, authenticating: aad ?? Data())
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Internals
|
||||||
|
|
||||||
|
private static func derive12ByteNonce(from24 nonce24: Data) -> Data {
|
||||||
|
// XChaCha20-Poly1305: 12-byte nonce = 4 zero bytes || last 8 bytes of the 24-byte nonce
|
||||||
|
var out = Data(count: 12)
|
||||||
|
out.replaceSubrange(0..<4, with: [0, 0, 0, 0])
|
||||||
|
out.replaceSubrange(4..<12, with: nonce24.suffix(8))
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func hchacha20(key: Data, nonce16: Data) -> Data {
|
||||||
|
// HChaCha20 based on the original ChaCha20 core with a 16-byte nonce.
|
||||||
|
precondition(key.count == 32)
|
||||||
|
precondition(nonce16.count == 16)
|
||||||
|
|
||||||
|
// Constants "expand 32-byte k"
|
||||||
|
var state: [UInt32] = [
|
||||||
|
0x61707865, 0x3320646e, 0x79622d32, 0x6b206574,
|
||||||
|
// key (8 words)
|
||||||
|
key.loadLEWord(0), key.loadLEWord(4), key.loadLEWord(8), key.loadLEWord(12),
|
||||||
|
key.loadLEWord(16), key.loadLEWord(20), key.loadLEWord(24), key.loadLEWord(28),
|
||||||
|
// nonce (4 words)
|
||||||
|
nonce16.loadLEWord(0), nonce16.loadLEWord(4), nonce16.loadLEWord(8), nonce16.loadLEWord(12)
|
||||||
|
]
|
||||||
|
|
||||||
|
// 20 rounds (10 double rounds)
|
||||||
|
for _ in 0..<10 {
|
||||||
|
// Column rounds
|
||||||
|
quarterRound(&state, 0, 4, 8, 12)
|
||||||
|
quarterRound(&state, 1, 5, 9, 13)
|
||||||
|
quarterRound(&state, 2, 6, 10, 14)
|
||||||
|
quarterRound(&state, 3, 7, 11, 15)
|
||||||
|
// Diagonal rounds
|
||||||
|
quarterRound(&state, 0, 5, 10, 15)
|
||||||
|
quarterRound(&state, 1, 6, 11, 12)
|
||||||
|
quarterRound(&state, 2, 7, 8, 13)
|
||||||
|
quarterRound(&state, 3, 4, 9, 14)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output subkey: state[0..3] and state[12..15]
|
||||||
|
var out = Data(count: 32)
|
||||||
|
out.storeLEWord(state[0], at: 0)
|
||||||
|
out.storeLEWord(state[1], at: 4)
|
||||||
|
out.storeLEWord(state[2], at: 8)
|
||||||
|
out.storeLEWord(state[3], at: 12)
|
||||||
|
out.storeLEWord(state[12], at: 16)
|
||||||
|
out.storeLEWord(state[13], at: 20)
|
||||||
|
out.storeLEWord(state[14], at: 24)
|
||||||
|
out.storeLEWord(state[15], at: 28)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func quarterRound(_ s: inout [UInt32], _ a: Int, _ b: Int, _ c: Int, _ d: Int) {
|
||||||
|
s[a] = s[a] &+ s[b]; s[d] ^= s[a]; s[d] = (s[d] << 16) | (s[d] >> 16)
|
||||||
|
s[c] = s[c] &+ s[d]; s[b] ^= s[c]; s[b] = (s[b] << 12) | (s[b] >> 20)
|
||||||
|
s[a] = s[a] &+ s[b]; s[d] ^= s[a]; s[d] = (s[d] << 8) | (s[d] >> 24)
|
||||||
|
s[c] = s[c] &+ s[d]; s[b] ^= s[c]; s[b] = (s[b] << 7) | (s[b] >> 25)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private extension Data {
|
||||||
|
func loadLEWord(_ offset: Int) -> UInt32 {
|
||||||
|
let range = offset..<(offset+4)
|
||||||
|
let bytes = self[range]
|
||||||
|
return bytes.withUnsafeBytes { ptr -> UInt32 in
|
||||||
|
let b = ptr.bindMemory(to: UInt8.self)
|
||||||
|
return UInt32(b[0]) | (UInt32(b[1]) << 8) | (UInt32(b[2]) << 16) | (UInt32(b[3]) << 24)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mutating func storeLEWord(_ value: UInt32, at offset: Int) {
|
||||||
|
let bytes: [UInt8] = [
|
||||||
|
UInt8(value & 0xff),
|
||||||
|
UInt8((value >> 8) & 0xff),
|
||||||
|
UInt8((value >> 16) & 0xff),
|
||||||
|
UInt8((value >> 24) & 0xff)
|
||||||
|
]
|
||||||
|
replaceSubrange(offset..<(offset+4), with: bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -155,12 +155,17 @@ enum NoisePayloadType: UInt8 {
|
|||||||
case privateMessage = 0x01 // Private chat message
|
case privateMessage = 0x01 // Private chat message
|
||||||
case readReceipt = 0x02 // Message was read
|
case readReceipt = 0x02 // Message was read
|
||||||
case delivered = 0x03 // Message was delivered
|
case delivered = 0x03 // Message was delivered
|
||||||
|
// Verification (QR-based OOB binding)
|
||||||
|
case verifyChallenge = 0x10 // Verification challenge
|
||||||
|
case verifyResponse = 0x11 // Verification response
|
||||||
|
|
||||||
var description: String {
|
var description: String {
|
||||||
switch self {
|
switch self {
|
||||||
case .privateMessage: return "privateMessage"
|
case .privateMessage: return "privateMessage"
|
||||||
case .readReceipt: return "readReceipt"
|
case .readReceipt: return "readReceipt"
|
||||||
case .delivered: return "delivered"
|
case .delivered: return "delivered"
|
||||||
|
case .verifyChallenge: return "verifyChallenge"
|
||||||
|
case .verifyResponse: return "verifyResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,8 +181,7 @@ enum LazyHandshakeState {
|
|||||||
case failed(Error) // Handshake failed
|
case failed(Error) // Handshake failed
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Special Recipients (removed)
|
//
|
||||||
// Previously defined broadcast identifiers were unused; removed for simplicity.
|
|
||||||
|
|
||||||
// MARK: - Core Protocol Structures
|
// MARK: - Core Protocol Structures
|
||||||
|
|
||||||
@@ -263,8 +267,7 @@ struct BitchatPacket: Codable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Delivery Acknowledgments (removed)
|
//
|
||||||
// Legacy DeliveryAck structures are no longer used; delivery status flows via Noise payloads.
|
|
||||||
|
|
||||||
// MARK: - Read Receipts
|
// MARK: - Read Receipts
|
||||||
|
|
||||||
@@ -356,7 +359,7 @@ struct ReadReceipt: Codable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// PeerIdentityBinding removed (unused).
|
//
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Delivery Status
|
// MARK: - Delivery Status
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ import Foundation
|
|||||||
/// Encodes latitude/longitude to base32 geohash with a fixed precision.
|
/// Encodes latitude/longitude to base32 geohash with a fixed precision.
|
||||||
enum Geohash {
|
enum Geohash {
|
||||||
private static let base32Chars = Array("0123456789bcdefghjkmnpqrstuvwxyz")
|
private static let base32Chars = Array("0123456789bcdefghjkmnpqrstuvwxyz")
|
||||||
|
private static let base32Map: [Character: Int] = {
|
||||||
|
var map: [Character: Int] = [:]
|
||||||
|
for (i, c) in base32Chars.enumerated() { map[c] = i }
|
||||||
|
return map
|
||||||
|
}()
|
||||||
|
|
||||||
/// Encodes the provided coordinates into a geohash string.
|
/// Encodes the provided coordinates into a geohash string.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
@@ -56,5 +61,30 @@ enum Geohash {
|
|||||||
|
|
||||||
return String(geohash)
|
return String(geohash)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/// Decodes a geohash into the center latitude/longitude of its bounding box.
|
||||||
|
/// - Parameter geohash: Base32 geohash string.
|
||||||
|
/// - Returns: (lat, lon) center coordinate.
|
||||||
|
static func decodeCenter(_ geohash: String) -> (lat: Double, lon: Double) {
|
||||||
|
var latInterval: (Double, Double) = (-90.0, 90.0)
|
||||||
|
var lonInterval: (Double, Double) = (-180.0, 180.0)
|
||||||
|
|
||||||
|
var isEven = true
|
||||||
|
for ch in geohash.lowercased() {
|
||||||
|
guard let cd = base32Map[ch] else { continue }
|
||||||
|
for mask in [16, 8, 4, 2, 1] {
|
||||||
|
if isEven {
|
||||||
|
let mid = (lonInterval.0 + lonInterval.1) / 2
|
||||||
|
if (cd & mask) != 0 { lonInterval.0 = mid } else { lonInterval.1 = mid }
|
||||||
|
} else {
|
||||||
|
let mid = (latInterval.0 + latInterval.1) / 2
|
||||||
|
if (cd & mask) != 0 { latInterval.0 = mid } else { latInterval.1 = mid }
|
||||||
|
}
|
||||||
|
isEven.toggle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let lat = (latInterval.0 + latInterval.1) / 2
|
||||||
|
let lon = (lonInterval.0 + lonInterval.1) / 2
|
||||||
|
return (lat, lon)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class AutocompleteService {
|
|||||||
private let commandRegex = try? NSRegularExpression(pattern: "^/([a-z]*)$", options: [])
|
private let commandRegex = try? NSRegularExpression(pattern: "^/([a-z]*)$", options: [])
|
||||||
|
|
||||||
private let commands = [
|
private let commands = [
|
||||||
"/msg", "/who", "/clear", "/help",
|
"/msg", "/who", "/clear",
|
||||||
"/hug", "/slap", "/fav", "/unfav",
|
"/hug", "/slap", "/fav", "/unfav",
|
||||||
"/block", "/unblock"
|
"/block", "/unblock"
|
||||||
]
|
]
|
||||||
@@ -95,10 +95,10 @@ class AutocompleteService {
|
|||||||
|
|
||||||
private func needsArgument(command: String) -> Bool {
|
private func needsArgument(command: String) -> Bool {
|
||||||
switch command {
|
switch command {
|
||||||
case "/who", "/clear", "/help":
|
case "/who", "/clear":
|
||||||
return false
|
return false
|
||||||
default:
|
default:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,6 +112,16 @@ final class BLEService: NSObject {
|
|||||||
private var scheduledRelays: [String: DispatchWorkItem] = [:]
|
private var scheduledRelays: [String: DispatchWorkItem] = [:]
|
||||||
// Track short-lived traffic bursts to adapt announces/scanning under load
|
// Track short-lived traffic bursts to adapt announces/scanning under load
|
||||||
private var recentPacketTimestamps: [Date] = []
|
private var recentPacketTimestamps: [Date] = []
|
||||||
|
|
||||||
|
// Ingress link tracking for last-hop suppression
|
||||||
|
private enum LinkID: Hashable {
|
||||||
|
case peripheral(String)
|
||||||
|
case central(String)
|
||||||
|
}
|
||||||
|
private var ingressByMessageID: [String: (link: LinkID, timestamp: Date)] = [:]
|
||||||
|
|
||||||
|
// Backpressure-aware write queue per peripheral
|
||||||
|
private var pendingPeripheralWrites: [String: [Data]] = [:]
|
||||||
|
|
||||||
// MARK: - Maintenance Timer
|
// MARK: - Maintenance Timer
|
||||||
|
|
||||||
@@ -156,6 +166,88 @@ final class BLEService: NSObject {
|
|||||||
return bleQueue.sync { (self.subscribedCentrals, self.centralToPeerID) }
|
return bleQueue.sync { (self.subscribedCentrals, self.centralToPeerID) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Helpers: IDs, selection, and write backpressure
|
||||||
|
private func makeMessageID(for packet: BitchatPacket) -> String {
|
||||||
|
let senderID = packet.senderID.hexEncodedString()
|
||||||
|
return "\(senderID)-\(packet.timestamp)-\(packet.type)"
|
||||||
|
}
|
||||||
|
|
||||||
|
private func subsetSizeForFanout(_ n: Int) -> Int {
|
||||||
|
guard n > 0 else { return 0 }
|
||||||
|
if n <= 2 { return n }
|
||||||
|
// approx ceil(log2(n)) + 1 without floating point
|
||||||
|
var v = n - 1
|
||||||
|
var bits = 0
|
||||||
|
while v > 0 { v >>= 1; bits += 1 }
|
||||||
|
return min(n, max(1, bits + 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func selectDeterministicSubset(ids: [String], k: Int, seed: String) -> Set<String> {
|
||||||
|
guard k > 0 && ids.count > k else { return Set(ids) }
|
||||||
|
// Stable order by SHA256(seed || "::" || id)
|
||||||
|
var scored: [(score: [UInt8], id: String)] = []
|
||||||
|
for id in ids {
|
||||||
|
let msg = (seed + "::" + id).data(using: .utf8) ?? Data()
|
||||||
|
let digest = Array(SHA256.hash(data: msg))
|
||||||
|
scored.append((digest, id))
|
||||||
|
}
|
||||||
|
scored.sort { a, b in
|
||||||
|
for i in 0..<min(a.score.count, b.score.count) {
|
||||||
|
if a.score[i] != b.score[i] { return a.score[i] < b.score[i] }
|
||||||
|
}
|
||||||
|
return a.id < b.id
|
||||||
|
}
|
||||||
|
return Set(scored.prefix(k).map { $0.id })
|
||||||
|
}
|
||||||
|
|
||||||
|
private func writeOrEnqueue(_ data: Data, to peripheral: CBPeripheral, characteristic: CBCharacteristic) {
|
||||||
|
// BLE operations run on bleQueue; keep queue affinity
|
||||||
|
bleQueue.async { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
let uuid = peripheral.identifier.uuidString
|
||||||
|
if peripheral.canSendWriteWithoutResponse {
|
||||||
|
peripheral.writeValue(data, for: characteristic, type: .withoutResponse)
|
||||||
|
} else {
|
||||||
|
self.collectionsQueue.async(flags: .barrier) {
|
||||||
|
self.pendingPeripheralWrites[uuid, default: []].append(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func drainPendingWrites(for peripheral: CBPeripheral) {
|
||||||
|
let uuid = peripheral.identifier.uuidString
|
||||||
|
bleQueue.async { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
guard let state = self.peripherals[uuid], let ch = state.characteristic else { return }
|
||||||
|
var queueCopy: [Data] = []
|
||||||
|
self.collectionsQueue.sync {
|
||||||
|
queueCopy = self.pendingPeripheralWrites[uuid] ?? []
|
||||||
|
}
|
||||||
|
guard !queueCopy.isEmpty else { return }
|
||||||
|
var sent = 0
|
||||||
|
for item in queueCopy {
|
||||||
|
if peripheral.canSendWriteWithoutResponse {
|
||||||
|
peripheral.writeValue(item, for: ch, type: .withoutResponse)
|
||||||
|
sent += 1
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sent > 0 {
|
||||||
|
self.collectionsQueue.async(flags: .barrier) {
|
||||||
|
var q = self.pendingPeripheralWrites[uuid] ?? []
|
||||||
|
if sent <= q.count {
|
||||||
|
q.removeFirst(sent)
|
||||||
|
} else {
|
||||||
|
q.removeAll()
|
||||||
|
}
|
||||||
|
self.pendingPeripheralWrites[uuid] = q.isEmpty ? nil : q
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Peer snapshots publisher (non-UI convenience)
|
// MARK: - Peer snapshots publisher (non-UI convenience)
|
||||||
private let peerSnapshotSubject = PassthroughSubject<[TransportPeerSnapshot], Never>()
|
private let peerSnapshotSubject = PassthroughSubject<[TransportPeerSnapshot], Never>()
|
||||||
@@ -369,7 +461,7 @@ final class BLEService: NSObject {
|
|||||||
// Send to peripherals we're connected to as central
|
// Send to peripherals we're connected to as central
|
||||||
for state in peripherals.values where state.isConnected {
|
for state in peripherals.values where state.isConnected {
|
||||||
if let characteristic = state.characteristic {
|
if let characteristic = state.characteristic {
|
||||||
state.peripheral.writeValue(data, for: characteristic, type: .withoutResponse)
|
writeOrEnqueue(data, to: state.peripheral, characteristic: characteristic)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,11 +600,51 @@ final class BLEService: NSObject {
|
|||||||
func sendBroadcastAnnounce() {
|
func sendBroadcastAnnounce() {
|
||||||
sendAnnounce()
|
sendAnnounce()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - QR Verification over Noise
|
||||||
|
func sendVerifyChallenge(to peerID: String, noiseKeyHex: String, nonceA: Data) {
|
||||||
|
let payload = VerificationService.shared.buildVerifyChallenge(noiseKeyHex: noiseKeyHex, nonceA: nonceA)
|
||||||
|
sendNoisePayload(payload, to: peerID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendVerifyResponse(to peerID: String, noiseKeyHex: String, nonceA: Data) {
|
||||||
|
guard let payload = VerificationService.shared.buildVerifyResponse(noiseKeyHex: noiseKeyHex, nonceA: nonceA) else { return }
|
||||||
|
sendNoisePayload(payload, to: peerID)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func sendNoisePayload(_ typedPayload: Data, to peerID: String) {
|
||||||
|
guard noiseService.hasSession(with: peerID) else {
|
||||||
|
// Lazy-handshake path: queue? For now, initiate handshake and drop
|
||||||
|
initiateNoiseHandshake(with: peerID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
let encrypted = try noiseService.encrypt(typedPayload, for: peerID)
|
||||||
|
let packet = BitchatPacket(
|
||||||
|
type: MessageType.noiseEncrypted.rawValue,
|
||||||
|
senderID: Data(hexString: myPeerID) ?? Data(),
|
||||||
|
recipientID: Data(hexString: peerID),
|
||||||
|
timestamp: UInt64(Date().timeIntervalSince1970 * 1000),
|
||||||
|
payload: encrypted,
|
||||||
|
signature: nil,
|
||||||
|
ttl: messageTTL
|
||||||
|
)
|
||||||
|
if DispatchQueue.getSpecific(key: messageQueueKey) != nil {
|
||||||
|
broadcastPacket(packet)
|
||||||
|
} else {
|
||||||
|
messageQueue.async { [weak self] in self?.broadcastPacket(packet) }
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
SecureLogger.log("Failed to send verification payload: \(error)", category: SecureLogger.noise, level: .error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getPeerFingerprint(_ peerID: String) -> String? {
|
func getPeerFingerprint(_ peerID: String) -> String? {
|
||||||
return collectionsQueue.sync {
|
return collectionsQueue.sync {
|
||||||
if let publicKey = peers[peerID]?.noisePublicKey {
|
if let publicKey = peers[peerID]?.noisePublicKey {
|
||||||
return publicKey.hexEncodedString()
|
// Use the same fingerprinting method as NoiseEncryptionService/UnifiedPeerService (SHA-256 of raw key)
|
||||||
|
let hash = SHA256.hash(data: publicKey)
|
||||||
|
return hash.map { String(format: "%02x", $0) }.joined()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -598,7 +730,7 @@ final class BLEService: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removed unused getPeers(): use getPeerNicknames() from Transport
|
//
|
||||||
|
|
||||||
// MARK: - Private Message Handling
|
// MARK: - Private Message Handling
|
||||||
|
|
||||||
@@ -837,7 +969,7 @@ final class BLEService: NSObject {
|
|||||||
let state = (DispatchQueue.getSpecific(key: bleQueueKey) != nil) ? peripherals[peripheralUUID] : bleQueue.sync(execute: { peripherals[peripheralUUID] }),
|
let state = (DispatchQueue.getSpecific(key: bleQueueKey) != nil) ? peripherals[peripheralUUID] : bleQueue.sync(execute: { peripherals[peripheralUUID] }),
|
||||||
state.isConnected,
|
state.isConnected,
|
||||||
let characteristic = state.characteristic {
|
let characteristic = state.characteristic {
|
||||||
state.peripheral.writeValue(data, for: characteristic, type: .withoutResponse)
|
writeOrEnqueue(data, to: state.peripheral, characteristic: characteristic)
|
||||||
sentEncrypted = true
|
sentEncrypted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,6 +1000,10 @@ final class BLEService: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func sendOnAllLinks(packet: BitchatPacket, data: Data, pad: Bool, directedOnlyPeer: String?) {
|
private func sendOnAllLinks(packet: BitchatPacket, data: Data, pad: Bool, directedOnlyPeer: String?) {
|
||||||
|
// Determine last-hop link for this message to avoid echoing back
|
||||||
|
let messageID = makeMessageID(for: packet)
|
||||||
|
let ingressLink: LinkID? = collectionsQueue.sync { ingressByMessageID[messageID]?.link }
|
||||||
|
|
||||||
let states = snapshotPeripheralStates()
|
let states = snapshotPeripheralStates()
|
||||||
var minCentralWriteLen: Int?
|
var minCentralWriteLen: Int?
|
||||||
for s in states where s.isConnected {
|
for s in states where s.isConnected {
|
||||||
@@ -892,15 +1028,54 @@ final class BLEService: NSObject {
|
|||||||
sendFragmentedPacket(packet, pad: pad, maxChunk: chunk, directedOnlyPeer: directedOnlyPeer)
|
sendFragmentedPacket(packet, pad: pad, maxChunk: chunk, directedOnlyPeer: directedOnlyPeer)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Writes to connected peripherals
|
// Build link lists and apply K-of-N fanout for broadcasts; always exclude ingress link
|
||||||
for s in states where s.isConnected {
|
let connectedPeripheralIDs: [String] = states.filter { $0.isConnected }.map { $0.peripheral.identifier.uuidString }
|
||||||
if let ch = s.characteristic {
|
let subscribedCentrals: [CBCentral]
|
||||||
s.peripheral.writeValue(data, for: ch, type: .withoutResponse)
|
var centralIDs: [String] = []
|
||||||
|
if let _ = characteristic {
|
||||||
|
let (centrals, _) = snapshotSubscribedCentrals()
|
||||||
|
subscribedCentrals = centrals
|
||||||
|
centralIDs = centrals.map { $0.identifier.uuidString }
|
||||||
|
} else {
|
||||||
|
subscribedCentrals = []
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exclude ingress link
|
||||||
|
var allowedPeripheralIDs = connectedPeripheralIDs
|
||||||
|
var allowedCentralIDs = centralIDs
|
||||||
|
if let ingress = ingressLink {
|
||||||
|
switch ingress {
|
||||||
|
case .peripheral(let id):
|
||||||
|
allowedPeripheralIDs.removeAll { $0 == id }
|
||||||
|
case .central(let id):
|
||||||
|
allowedCentralIDs.removeAll { $0 == id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Notify all subscribed centrals
|
|
||||||
|
// For broadcast (no directed peer) and non-fragment, choose a subset deterministically
|
||||||
|
var selectedPeripheralIDs = Set(allowedPeripheralIDs)
|
||||||
|
var selectedCentralIDs = Set(allowedCentralIDs)
|
||||||
|
if directedOnlyPeer == nil && packet.type != MessageType.fragment.rawValue {
|
||||||
|
let kp = subsetSizeForFanout(allowedPeripheralIDs.count)
|
||||||
|
let kc = subsetSizeForFanout(allowedCentralIDs.count)
|
||||||
|
selectedPeripheralIDs = selectDeterministicSubset(ids: allowedPeripheralIDs, k: kp, seed: messageID)
|
||||||
|
selectedCentralIDs = selectDeterministicSubset(ids: allowedCentralIDs, k: kc, seed: messageID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Writes to selected connected peripherals
|
||||||
|
for s in states where s.isConnected {
|
||||||
|
let pid = s.peripheral.identifier.uuidString
|
||||||
|
guard selectedPeripheralIDs.contains(pid) else { continue }
|
||||||
|
if let ch = s.characteristic {
|
||||||
|
writeOrEnqueue(data, to: s.peripheral, characteristic: ch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Notify selected subscribed centrals
|
||||||
if let ch = characteristic {
|
if let ch = characteristic {
|
||||||
_ = peripheralManager?.updateValue(data, for: ch, onSubscribedCentrals: nil)
|
let targets = subscribedCentrals.filter { selectedCentralIDs.contains($0.identifier.uuidString) }
|
||||||
|
if !targets.isEmpty {
|
||||||
|
_ = peripheralManager?.updateValue(data, for: ch, onSubscribedCentrals: targets)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -914,7 +1089,7 @@ final class BLEService: NSObject {
|
|||||||
|
|
||||||
// Fire-and-forget principle: always use .withoutResponse for speed
|
// Fire-and-forget principle: always use .withoutResponse for speed
|
||||||
// CoreBluetooth will handle fragmentation at L2CAP layer
|
// CoreBluetooth will handle fragmentation at L2CAP layer
|
||||||
peripheral.writeValue(data, for: characteristic, type: .withoutResponse)
|
writeOrEnqueue(data, to: peripheral, characteristic: characteristic)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Fragmentation (Required for messages > BLE MTU)
|
// MARK: - Fragmentation (Required for messages > BLE MTU)
|
||||||
@@ -1122,6 +1297,7 @@ final class BLEService: NSObject {
|
|||||||
ttl: packet.ttl,
|
ttl: packet.ttl,
|
||||||
senderIsSelf: senderID == myPeerID,
|
senderIsSelf: senderID == myPeerID,
|
||||||
isEncrypted: packet.type == MessageType.noiseEncrypted.rawValue,
|
isEncrypted: packet.type == MessageType.noiseEncrypted.rawValue,
|
||||||
|
isDirectedEncrypted: (packet.type == MessageType.noiseEncrypted.rawValue) && (packet.recipientID != nil),
|
||||||
isDirectedFragment: packet.type == MessageType.fragment.rawValue && packet.recipientID != nil,
|
isDirectedFragment: packet.type == MessageType.fragment.rawValue && packet.recipientID != nil,
|
||||||
isHandshake: packet.type == MessageType.noiseHandshake.rawValue,
|
isHandshake: packet.type == MessageType.noiseHandshake.rawValue,
|
||||||
degree: degree,
|
degree: degree,
|
||||||
@@ -1383,6 +1559,16 @@ final class BLEService: NSObject {
|
|||||||
notifyUI { [weak self] in
|
notifyUI { [weak self] in
|
||||||
self?.delegate?.didReceiveNoisePayload(from: peerID, type: .readReceipt, payload: Data(payloadData), timestamp: ts)
|
self?.delegate?.didReceiveNoisePayload(from: peerID, type: .readReceipt, payload: Data(payloadData), timestamp: ts)
|
||||||
}
|
}
|
||||||
|
case .verifyChallenge:
|
||||||
|
let ts = Date(timeIntervalSince1970: Double(packet.timestamp) / 1000)
|
||||||
|
notifyUI { [weak self] in
|
||||||
|
self?.delegate?.didReceiveNoisePayload(from: peerID, type: .verifyChallenge, payload: Data(payloadData), timestamp: ts)
|
||||||
|
}
|
||||||
|
case .verifyResponse:
|
||||||
|
let ts = Date(timeIntervalSince1970: Double(packet.timestamp) / 1000)
|
||||||
|
notifyUI { [weak self] in
|
||||||
|
self?.delegate?.didReceiveNoisePayload(from: peerID, type: .verifyResponse, payload: Data(payloadData), timestamp: ts)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
SecureLogger.log("⚠️ Unknown noise payload type: \(payloadType)", category: SecureLogger.noise, level: .warning)
|
SecureLogger.log("⚠️ Unknown noise payload type: \(payloadType)", category: SecureLogger.noise, level: .warning)
|
||||||
}
|
}
|
||||||
@@ -1677,6 +1863,15 @@ final class BLEService: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean ingress link records older than 3 seconds
|
||||||
|
collectionsQueue.async(flags: .barrier) { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
let cutoff = now.addingTimeInterval(-3)
|
||||||
|
if !self.ingressByMessageID.isEmpty {
|
||||||
|
self.ingressByMessageID = self.ingressByMessageID.filter { $0.value.timestamp >= cutoff }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateScanningDutyCycle(connectedCount: Int) {
|
private func updateScanningDutyCycle(connectedCount: Int) {
|
||||||
@@ -2067,6 +2262,27 @@ extension BLEService {
|
|||||||
// Test-only helper to inject packets into the receive pipeline
|
// Test-only helper to inject packets into the receive pipeline
|
||||||
extension BLEService {
|
extension BLEService {
|
||||||
func _test_handlePacket(_ packet: BitchatPacket, fromPeerID: String) {
|
func _test_handlePacket(_ packet: BitchatPacket, fromPeerID: String) {
|
||||||
|
// Ensure the synthetic peer is known and marked verified for public-message tests
|
||||||
|
let normalizedID = packet.senderID.hexEncodedString()
|
||||||
|
collectionsQueue.sync(flags: .barrier) {
|
||||||
|
if peers[normalizedID] == nil {
|
||||||
|
peers[normalizedID] = PeerInfo(
|
||||||
|
id: normalizedID,
|
||||||
|
nickname: "TestPeer_\(fromPeerID.prefix(4))",
|
||||||
|
isConnected: true,
|
||||||
|
noisePublicKey: packet.senderID,
|
||||||
|
signingPublicKey: nil,
|
||||||
|
isVerifiedNickname: true,
|
||||||
|
lastSeen: Date()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
var p = peers[normalizedID]!
|
||||||
|
p.isConnected = true
|
||||||
|
p.isVerifiedNickname = true
|
||||||
|
p.lastSeen = Date()
|
||||||
|
peers[normalizedID] = p
|
||||||
|
}
|
||||||
|
}
|
||||||
if DispatchQueue.getSpecific(key: messageQueueKey) != nil {
|
if DispatchQueue.getSpecific(key: messageQueueKey) != nil {
|
||||||
handleReceivedPacket(packet, from: fromPeerID)
|
handleReceivedPacket(packet, from: fromPeerID)
|
||||||
} else {
|
} else {
|
||||||
@@ -2195,12 +2411,22 @@ extension BLEService: CBPeripheralDelegate {
|
|||||||
peerToPeripheralUUID[senderID] = peripheralUUID
|
peerToPeripheralUUID[senderID] = peripheralUUID
|
||||||
// Mapping update - direct announce from peer
|
// Mapping update - direct announce from peer
|
||||||
}
|
}
|
||||||
|
// Record ingress link for last-hop suppression and process
|
||||||
|
let msgID = makeMessageID(for: packet)
|
||||||
|
collectionsQueue.async(flags: .barrier) { [weak self] in
|
||||||
|
self?.ingressByMessageID[msgID] = (.peripheral(peripheralUUID), Date())
|
||||||
|
}
|
||||||
// Process the announce packet regardless of whether we updated the mapping
|
// Process the announce packet regardless of whether we updated the mapping
|
||||||
handleReceivedPacket(packet, from: senderID)
|
handleReceivedPacket(packet, from: senderID)
|
||||||
} else {
|
} else {
|
||||||
// For non-announce packets, DO NOT update mappings
|
// For non-announce packets, DO NOT update mappings
|
||||||
// These could be relayed packets from other peers
|
// These could be relayed packets from other peers
|
||||||
// Always use the packet's original senderID
|
// Always use the packet's original senderID
|
||||||
|
// Record ingress link for last-hop suppression and process
|
||||||
|
let msgID = makeMessageID(for: packet)
|
||||||
|
collectionsQueue.async(flags: .barrier) { [weak self] in
|
||||||
|
self?.ingressByMessageID[msgID] = (.peripheral(peripheralUUID), Date())
|
||||||
|
}
|
||||||
handleReceivedPacket(packet, from: senderID)
|
handleReceivedPacket(packet, from: senderID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2215,7 +2441,8 @@ extension BLEService: CBPeripheralDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func peripheralIsReady(toSendWriteWithoutResponse peripheral: CBPeripheral) {
|
func peripheralIsReady(toSendWriteWithoutResponse peripheral: CBPeripheral) {
|
||||||
// Suppress verbose ready logs
|
// Resume queued writes for this peripheral
|
||||||
|
drainPendingWrites(for: peripheral)
|
||||||
}
|
}
|
||||||
|
|
||||||
func peripheral(_ peripheral: CBPeripheral, didModifyServices invalidatedServices: [CBService]) {
|
func peripheral(_ peripheral: CBPeripheral, didModifyServices invalidatedServices: [CBService]) {
|
||||||
@@ -2439,8 +2666,18 @@ extension BLEService: CBPeripheralManagerDelegate {
|
|||||||
}
|
}
|
||||||
if packet.type == MessageType.announce.rawValue {
|
if packet.type == MessageType.announce.rawValue {
|
||||||
if packet.ttl == messageTTL { centralToPeerID[centralUUID] = senderID }
|
if packet.ttl == messageTTL { centralToPeerID[centralUUID] = senderID }
|
||||||
|
// Record ingress link for last-hop suppression then process
|
||||||
|
let msgID = makeMessageID(for: packet)
|
||||||
|
collectionsQueue.async(flags: .barrier) { [weak self] in
|
||||||
|
self?.ingressByMessageID[msgID] = (.central(centralUUID), Date())
|
||||||
|
}
|
||||||
handleReceivedPacket(packet, from: senderID)
|
handleReceivedPacket(packet, from: senderID)
|
||||||
} else {
|
} else {
|
||||||
|
// Record ingress link for last-hop suppression then process
|
||||||
|
let msgID = makeMessageID(for: packet)
|
||||||
|
collectionsQueue.async(flags: .barrier) { [weak self] in
|
||||||
|
self?.ingressByMessageID[msgID] = (.central(centralUUID), Date())
|
||||||
|
}
|
||||||
handleReceivedPacket(packet, from: senderID)
|
handleReceivedPacket(packet, from: senderID)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -33,6 +33,15 @@ class CommandProcessor {
|
|||||||
guard let cmd = parts.first else { return .error(message: "Invalid command") }
|
guard let cmd = parts.first else { return .error(message: "Invalid command") }
|
||||||
let args = parts.count > 1 ? String(parts[1]) : ""
|
let args = parts.count > 1 ? String(parts[1]) : ""
|
||||||
|
|
||||||
|
// Geohash context: disable favoriting in public geohash or GeoDM
|
||||||
|
let inGeoPublic: Bool = {
|
||||||
|
switch LocationChannelManager.shared.selectedChannel {
|
||||||
|
case .mesh: return false
|
||||||
|
case .location: return true
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
let inGeoDM = (chatViewModel?.selectedPrivateChatPeer?.hasPrefix("nostr_") == true)
|
||||||
|
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case "/m", "/msg":
|
case "/m", "/msg":
|
||||||
return handleMessage(args)
|
return handleMessage(args)
|
||||||
@@ -49,11 +58,14 @@ class CommandProcessor {
|
|||||||
case "/unblock":
|
case "/unblock":
|
||||||
return handleUnblock(args)
|
return handleUnblock(args)
|
||||||
case "/fav":
|
case "/fav":
|
||||||
|
if inGeoPublic || inGeoDM { return .error(message: "favorites are only for mesh peers in #mesh") }
|
||||||
return handleFavorite(args, add: true)
|
return handleFavorite(args, add: true)
|
||||||
case "/unfav":
|
case "/unfav":
|
||||||
|
if inGeoPublic || inGeoDM { return .error(message: "favorites are only for mesh peers in #mesh") }
|
||||||
return handleFavorite(args, add: false)
|
return handleFavorite(args, add: false)
|
||||||
|
//
|
||||||
case "/help", "/h":
|
case "/help", "/h":
|
||||||
return handleHelp()
|
return .error(message: "unknown command: \(cmd)")
|
||||||
default:
|
default:
|
||||||
return .error(message: "unknown command: \(cmd)")
|
return .error(message: "unknown command: \(cmd)")
|
||||||
}
|
}
|
||||||
@@ -85,19 +97,34 @@ class CommandProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func handleWho() -> CommandResult {
|
private func handleWho() -> CommandResult {
|
||||||
guard let peers = meshService?.getPeerNicknames(), !peers.isEmpty else {
|
// Show geohash participants when in a geohash channel; otherwise mesh peers
|
||||||
return .success(message: "no one else is online right now")
|
switch LocationChannelManager.shared.selectedChannel {
|
||||||
|
case .location(let ch):
|
||||||
|
// Geohash context: show visible geohash participants (exclude self)
|
||||||
|
guard let vm = chatViewModel else { return .success(message: "nobody around") }
|
||||||
|
let myHex = (try? NostrIdentityBridge.deriveIdentity(forGeohash: ch.geohash))?.publicKeyHex.lowercased()
|
||||||
|
let people = vm.visibleGeohashPeople().filter { person in
|
||||||
|
if let me = myHex { return person.id.lowercased() != me }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
let names = people.map { $0.displayName }
|
||||||
|
if names.isEmpty { return .success(message: "no one else is online right now") }
|
||||||
|
return .success(message: "online: " + names.sorted().joined(separator: ", "))
|
||||||
|
case .mesh:
|
||||||
|
// Mesh context: show connected peer nicknames
|
||||||
|
guard let peers = meshService?.getPeerNicknames(), !peers.isEmpty else {
|
||||||
|
return .success(message: "no one else is online right now")
|
||||||
|
}
|
||||||
|
let onlineList = peers.values.sorted().joined(separator: ", ")
|
||||||
|
return .success(message: "online: \(onlineList)")
|
||||||
}
|
}
|
||||||
|
|
||||||
let onlineList = peers.values.sorted().joined(separator: ", ")
|
|
||||||
return .success(message: "online: \(onlineList)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleClear() -> CommandResult {
|
private func handleClear() -> CommandResult {
|
||||||
if let peerID = chatViewModel?.selectedPrivateChatPeer {
|
if let peerID = chatViewModel?.selectedPrivateChatPeer {
|
||||||
chatViewModel?.privateChats[peerID]?.removeAll()
|
chatViewModel?.privateChats[peerID]?.removeAll()
|
||||||
} else {
|
} else {
|
||||||
chatViewModel?.messages.removeAll()
|
chatViewModel?.clearCurrentPublicTimeline()
|
||||||
}
|
}
|
||||||
return .handled
|
return .handled
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
#if os(iOS)
|
|
||||||
import CoreLocation
|
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
|
#if os(iOS) || os(macOS)
|
||||||
|
import CoreLocation
|
||||||
|
|
||||||
/// Manages location permissions, one-shot location retrieval, and computing geohash channels.
|
/// Manages location permissions, one-shot location retrieval, and computing geohash channels.
|
||||||
/// Not main-actor isolated to satisfy CLLocationManagerDelegate in Swift 6; state updates hop to MainActor.
|
/// Not main-actor isolated to satisfy CLLocationManagerDelegate in Swift 6; state updates hop to MainActor.
|
||||||
final class LocationChannelManager: NSObject, CLLocationManagerDelegate, ObservableObject {
|
final class LocationChannelManager: NSObject, CLLocationManagerDelegate, ObservableObject {
|
||||||
@@ -55,7 +55,7 @@ final class LocationChannelManager: NSObject, CLLocationManagerDelegate, Observa
|
|||||||
teleported = teleportedSet.contains(ch.geohash)
|
teleported = teleportedSet.contains(ch.geohash)
|
||||||
}
|
}
|
||||||
let status: CLAuthorizationStatus
|
let status: CLAuthorizationStatus
|
||||||
if #available(iOS 14.0, *) {
|
if #available(iOS 14.0, macOS 11.0, *) {
|
||||||
status = cl.authorizationStatus
|
status = cl.authorizationStatus
|
||||||
} else {
|
} else {
|
||||||
status = CLLocationManager.authorizationStatus()
|
status = CLLocationManager.authorizationStatus()
|
||||||
@@ -66,7 +66,7 @@ final class LocationChannelManager: NSObject, CLLocationManagerDelegate, Observa
|
|||||||
// MARK: - Public API
|
// MARK: - Public API
|
||||||
func enableLocationChannels() {
|
func enableLocationChannels() {
|
||||||
let status: CLAuthorizationStatus
|
let status: CLAuthorizationStatus
|
||||||
if #available(iOS 14.0, *) {
|
if #available(iOS 14.0, macOS 11.0, *) {
|
||||||
status = cl.authorizationStatus
|
status = cl.authorizationStatus
|
||||||
} else {
|
} else {
|
||||||
status = CLLocationManager.authorizationStatus()
|
status = CLLocationManager.authorizationStatus()
|
||||||
@@ -78,7 +78,7 @@ final class LocationChannelManager: NSObject, CLLocationManagerDelegate, Observa
|
|||||||
Task { @MainActor in self.permissionState = .restricted }
|
Task { @MainActor in self.permissionState = .restricted }
|
||||||
case .denied:
|
case .denied:
|
||||||
Task { @MainActor in self.permissionState = .denied }
|
Task { @MainActor in self.permissionState = .denied }
|
||||||
case .authorizedAlways, .authorizedWhenInUse:
|
case .authorizedAlways, .authorizedWhenInUse, .authorized:
|
||||||
Task { @MainActor in self.permissionState = .authorized }
|
Task { @MainActor in self.permissionState = .authorized }
|
||||||
requestOneShotLocation()
|
requestOneShotLocation()
|
||||||
@unknown default:
|
@unknown default:
|
||||||
@@ -151,8 +151,8 @@ final class LocationChannelManager: NSObject, CLLocationManagerDelegate, Observa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// iOS 14+
|
// iOS 14+ / macOS 11+
|
||||||
@available(iOS 14.0, *)
|
@available(iOS 14.0, macOS 11.0, *)
|
||||||
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
|
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
|
||||||
updatePermissionState(from: manager.authorizationStatus)
|
updatePermissionState(from: manager.authorizationStatus)
|
||||||
if case .authorized = permissionState {
|
if case .authorized = permissionState {
|
||||||
@@ -180,7 +180,7 @@ final class LocationChannelManager: NSObject, CLLocationManagerDelegate, Observa
|
|||||||
case .notDetermined: newState = .notDetermined
|
case .notDetermined: newState = .notDetermined
|
||||||
case .restricted: newState = .restricted
|
case .restricted: newState = .restricted
|
||||||
case .denied: newState = .denied
|
case .denied: newState = .denied
|
||||||
case .authorizedAlways, .authorizedWhenInUse: newState = .authorized
|
case .authorizedAlways, .authorizedWhenInUse, .authorized: newState = .authorized
|
||||||
@unknown default: newState = .restricted
|
@unknown default: newState = .restricted
|
||||||
}
|
}
|
||||||
Task { @MainActor in self.permissionState = newState }
|
Task { @MainActor in self.permissionState = newState }
|
||||||
@@ -256,5 +256,4 @@ final class LocationChannelManager: NSObject, CLLocationManagerDelegate, Observa
|
|||||||
return dict
|
return dict
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ struct RelayController {
|
|||||||
static func decide(ttl: UInt8,
|
static func decide(ttl: UInt8,
|
||||||
senderIsSelf: Bool,
|
senderIsSelf: Bool,
|
||||||
isEncrypted: Bool,
|
isEncrypted: Bool,
|
||||||
|
isDirectedEncrypted: Bool,
|
||||||
isDirectedFragment: Bool,
|
isDirectedFragment: Bool,
|
||||||
isHandshake: Bool,
|
isHandshake: Bool,
|
||||||
degree: Int,
|
degree: Int,
|
||||||
@@ -19,7 +20,17 @@ struct RelayController {
|
|||||||
// Suppress obvious non-relays
|
// Suppress obvious non-relays
|
||||||
if ttl <= 1 || senderIsSelf { return RelayDecision(shouldRelay: false, newTTL: ttl, delayMs: 0) }
|
if ttl <= 1 || senderIsSelf { return RelayDecision(shouldRelay: false, newTTL: ttl, delayMs: 0) }
|
||||||
|
|
||||||
// Degree-aware probability to reduce floods in dense graphs
|
// For session-critical or directed traffic, be deterministic and reliable
|
||||||
|
if isHandshake || isDirectedFragment || isDirectedEncrypted {
|
||||||
|
// Always relay with no TTL cap for these types
|
||||||
|
let newTTL = (ttl &- 1)
|
||||||
|
// Slight jitter to desynchronize without adding too much latency
|
||||||
|
let delayRange: ClosedRange<Int> = isHandshake ? 20...60 : 40...120
|
||||||
|
let delayMs = Int.random(in: delayRange)
|
||||||
|
return RelayDecision(shouldRelay: true, newTTL: newTTL, delayMs: delayMs)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Degree-aware probability to reduce floods in dense graphs (broadcast/public)
|
||||||
let baseProb: Double
|
let baseProb: Double
|
||||||
switch degree {
|
switch degree {
|
||||||
case 0...2: baseProb = 1.0
|
case 0...2: baseProb = 1.0
|
||||||
@@ -28,20 +39,22 @@ struct RelayController {
|
|||||||
case 7...9: baseProb = 0.55
|
case 7...9: baseProb = 0.55
|
||||||
default: baseProb = 0.45
|
default: baseProb = 0.45
|
||||||
}
|
}
|
||||||
var prob = baseProb
|
let prob = baseProb
|
||||||
if isHandshake { prob = max(0.3, baseProb - 0.2) }
|
|
||||||
|
|
||||||
// Sample a forwarding decision
|
|
||||||
let shouldRelay = Double.random(in: 0...1) <= prob
|
let shouldRelay = Double.random(in: 0...1) <= prob
|
||||||
|
|
||||||
// TTL clamping in dense graphs
|
// TTL clamping in dense graphs (only for broadcast)
|
||||||
let ttlCap: UInt8 = degree >= highDegreeThreshold ? 3 : 5
|
let ttlCap: UInt8 = degree >= highDegreeThreshold ? 3 : 5
|
||||||
let clamped = max(1, min(ttl, ttlCap))
|
let clamped = max(1, min(ttl, ttlCap))
|
||||||
let newTTL = clamped &- 1
|
let newTTL = clamped &- 1
|
||||||
|
|
||||||
// Short jitter to desynchronize rebroadcasts
|
// Wider jitter window to allow duplicate suppression to win more often
|
||||||
let delayMs = Int.random(in: 20...80)
|
let delayMs: Int
|
||||||
|
switch degree {
|
||||||
|
case 0...2: delayMs = Int.random(in: 40...100)
|
||||||
|
case 3...5: delayMs = Int.random(in: 60...150)
|
||||||
|
case 6...9: delayMs = Int.random(in: 80...180)
|
||||||
|
default: delayMs = Int.random(in: 100...220)
|
||||||
|
}
|
||||||
return RelayDecision(shouldRelay: shouldRelay, newTTL: newTTL, delayMs: delayMs)
|
return RelayDecision(shouldRelay: shouldRelay, newTTL: newTTL, delayMs: delayMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,11 +46,20 @@ protocol Transport: AnyObject {
|
|||||||
func sendBroadcastAnnounce()
|
func sendBroadcastAnnounce()
|
||||||
func sendDeliveryAck(for messageID: String, to peerID: String)
|
func sendDeliveryAck(for messageID: String, to peerID: String)
|
||||||
|
|
||||||
|
// QR verification (optional for transports)
|
||||||
|
func sendVerifyChallenge(to peerID: String, noiseKeyHex: String, nonceA: Data)
|
||||||
|
func sendVerifyResponse(to peerID: String, noiseKeyHex: String, nonceA: Data)
|
||||||
|
|
||||||
// Peer snapshots (for non-UI services)
|
// Peer snapshots (for non-UI services)
|
||||||
var peerSnapshotPublisher: AnyPublisher<[TransportPeerSnapshot], Never> { get }
|
var peerSnapshotPublisher: AnyPublisher<[TransportPeerSnapshot], Never> { get }
|
||||||
func currentPeerSnapshots() -> [TransportPeerSnapshot]
|
func currentPeerSnapshots() -> [TransportPeerSnapshot]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Transport {
|
||||||
|
func sendVerifyChallenge(to peerID: String, noiseKeyHex: String, nonceA: Data) {}
|
||||||
|
func sendVerifyResponse(to peerID: String, noiseKeyHex: String, nonceA: Data) {}
|
||||||
|
}
|
||||||
|
|
||||||
protocol TransportPeerEventsDelegate: AnyObject {
|
protocol TransportPeerEventsDelegate: AnyObject {
|
||||||
@MainActor func didUpdatePeerSnapshots(_ peers: [TransportPeerSnapshot])
|
@MainActor func didUpdatePeerSnapshots(_ peers: [TransportPeerSnapshot])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,185 @@
|
|||||||
|
import Foundation
|
||||||
|
import CryptoKit
|
||||||
|
|
||||||
|
/// QR verification scaffolding: schema, signing, and basic challenge/response helpers.
|
||||||
|
final class VerificationService {
|
||||||
|
static let shared = VerificationService()
|
||||||
|
|
||||||
|
// Injected Noise service from the running transport (do NOT create new BLEService)
|
||||||
|
private var noise: NoiseEncryptionService?
|
||||||
|
func configure(with noise: NoiseEncryptionService) { self.noise = noise }
|
||||||
|
|
||||||
|
/// Encapsulates the data encoded into a verification QR
|
||||||
|
struct VerificationQR: Codable {
|
||||||
|
let v: Int
|
||||||
|
let noiseKeyHex: String
|
||||||
|
let signKeyHex: String
|
||||||
|
let npub: String?
|
||||||
|
let nickname: String
|
||||||
|
let ts: Int64
|
||||||
|
let nonceB64: String
|
||||||
|
var sigHex: String
|
||||||
|
|
||||||
|
static let context = "bitchat-verify-v1"
|
||||||
|
|
||||||
|
/// Canonical bytes used for signature (deterministic ordering)
|
||||||
|
func canonicalBytes() -> Data {
|
||||||
|
var out = Data()
|
||||||
|
func appendField(_ s: String) {
|
||||||
|
let d = s.data(using: .utf8) ?? Data()
|
||||||
|
out.append(UInt8(min(d.count, 255)))
|
||||||
|
out.append(d.prefix(255))
|
||||||
|
}
|
||||||
|
appendField(Self.context)
|
||||||
|
appendField(String(v))
|
||||||
|
appendField(noiseKeyHex.lowercased())
|
||||||
|
appendField(signKeyHex.lowercased())
|
||||||
|
appendField(npub ?? "")
|
||||||
|
appendField(nickname)
|
||||||
|
appendField(String(ts))
|
||||||
|
appendField(nonceB64)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func toURLString() -> String {
|
||||||
|
var comps = URLComponents()
|
||||||
|
comps.scheme = "bitchat"
|
||||||
|
comps.host = "verify"
|
||||||
|
comps.queryItems = [
|
||||||
|
URLQueryItem(name: "v", value: String(v)),
|
||||||
|
URLQueryItem(name: "noise", value: noiseKeyHex),
|
||||||
|
URLQueryItem(name: "sign", value: signKeyHex),
|
||||||
|
URLQueryItem(name: "nick", value: nickname),
|
||||||
|
URLQueryItem(name: "ts", value: String(ts)),
|
||||||
|
URLQueryItem(name: "nonce", value: nonceB64),
|
||||||
|
URLQueryItem(name: "sig", value: sigHex)
|
||||||
|
] + (npub != nil ? [URLQueryItem(name: "npub", value: npub)] : [])
|
||||||
|
return comps.string ?? ""
|
||||||
|
}
|
||||||
|
|
||||||
|
static func fromURL(_ url: URL) -> VerificationQR? {
|
||||||
|
guard url.scheme == "bitchat", url.host == "verify",
|
||||||
|
let items = URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems else { return nil }
|
||||||
|
func val(_ name: String) -> String? { items.first(where: { $0.name == name })?.value }
|
||||||
|
guard let vStr = val("v"), let v = Int(vStr),
|
||||||
|
let noise = val("noise"), let sign = val("sign"),
|
||||||
|
let nick = val("nick"), let tsStr = val("ts"), let ts = Int64(tsStr),
|
||||||
|
let nonce = val("nonce"), let sig = val("sig") else { return nil }
|
||||||
|
return VerificationQR(v: v, noiseKeyHex: noise, signKeyHex: sign, npub: val("npub"), nickname: nick, ts: ts, nonceB64: nonce, sigHex: sig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Public API
|
||||||
|
|
||||||
|
/// Build a signed QR string for the current identity
|
||||||
|
func buildMyQRString(nickname: String, npub: String?) -> String? {
|
||||||
|
// Simple short-lived cache to speed up sheet opening
|
||||||
|
struct Cache { static var last: (nick: String, npub: String?, builtAt: Date, value: String)? }
|
||||||
|
if let c = Cache.last, c.nick == nickname, c.npub == npub, Date().timeIntervalSince(c.builtAt) < 60 {
|
||||||
|
return c.value
|
||||||
|
}
|
||||||
|
guard let noise = noise else { return nil }
|
||||||
|
let noiseKey = noise.getStaticPublicKeyData().hexEncodedString()
|
||||||
|
let signKey = noise.getSigningPublicKeyData().hexEncodedString()
|
||||||
|
let ts = Int64(Date().timeIntervalSince1970)
|
||||||
|
var nonce = Data(count: 16)
|
||||||
|
_ = nonce.withUnsafeMutableBytes { SecRandomCopyBytes(kSecRandomDefault, 16, $0.baseAddress!) }
|
||||||
|
let nonceB64 = nonce.base64EncodedString().replacingOccurrences(of: "+", with: "-").replacingOccurrences(of: "/", with: "_").replacingOccurrences(of: "=", with: "")
|
||||||
|
let payload = VerificationQR(v: 1, noiseKeyHex: noiseKey, signKeyHex: signKey, npub: npub, nickname: nickname, ts: ts, nonceB64: nonceB64, sigHex: "")
|
||||||
|
let msg = payload.canonicalBytes()
|
||||||
|
guard let sig = noise.signData(msg) else { return nil }
|
||||||
|
let signed = VerificationQR(v: payload.v,
|
||||||
|
noiseKeyHex: payload.noiseKeyHex,
|
||||||
|
signKeyHex: payload.signKeyHex,
|
||||||
|
npub: payload.npub,
|
||||||
|
nickname: payload.nickname,
|
||||||
|
ts: payload.ts,
|
||||||
|
nonceB64: payload.nonceB64,
|
||||||
|
sigHex: sig.map { String(format: "%02x", $0) }.joined())
|
||||||
|
let out = signed.toURLString()
|
||||||
|
Cache.last = (nickname, npub, Date(), out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Verify a scanned QR and return the parsed payload if valid (signature + freshness checks)
|
||||||
|
func verifyScannedQR(_ urlString: String, maxAge: TimeInterval = 5 * 60) -> VerificationQR? {
|
||||||
|
guard let url = URL(string: urlString), let qr = VerificationQR.fromURL(url) else { return nil }
|
||||||
|
// Freshness
|
||||||
|
let now = Date().timeIntervalSince1970
|
||||||
|
if now - Double(qr.ts) > maxAge { return nil }
|
||||||
|
// Verify signature using embedded ed25519 signKey
|
||||||
|
guard let sig = Data(hexString: qr.sigHex), let signKey = Data(hexString: qr.signKeyHex) else { return nil }
|
||||||
|
guard let noise = noise else { return nil }
|
||||||
|
let ok = noise.verifySignature(sig, for: qr.canonicalBytes(), publicKey: signKey)
|
||||||
|
return ok ? qr : nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Noise payloads (scaffold only)
|
||||||
|
|
||||||
|
func buildVerifyChallenge(noiseKeyHex: String, nonceA: Data) -> Data {
|
||||||
|
// TLV: [0x01 len noiseKeyHex ascii] [0x02 len nonceA]
|
||||||
|
var tlv = Data()
|
||||||
|
let n0: [UInt8] = [0x01, UInt8(min(noiseKeyHex.count, 255))]
|
||||||
|
tlv.append(contentsOf: n0)
|
||||||
|
tlv.append(noiseKeyHex.data(using: .utf8)!.prefix(255))
|
||||||
|
tlv.append(0x02)
|
||||||
|
tlv.append(UInt8(min(nonceA.count, 255)))
|
||||||
|
tlv.append(nonceA.prefix(255))
|
||||||
|
return NoisePayload(type: .verifyChallenge, data: tlv).encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildVerifyResponse(noiseKeyHex: String, nonceA: Data) -> Data? {
|
||||||
|
// Sign context: verify-response | noiseKeyHex | nonceA
|
||||||
|
var msg = Data("bitchat-verify-resp-v1".utf8)
|
||||||
|
let nk = noiseKeyHex.data(using: .utf8) ?? Data()
|
||||||
|
msg.append(UInt8(min(nk.count, 255))); msg.append(nk.prefix(255))
|
||||||
|
msg.append(nonceA)
|
||||||
|
guard let noise = noise, let sig = noise.signData(msg) else { return nil }
|
||||||
|
var tlv = Data()
|
||||||
|
tlv.append(0x01); tlv.append(UInt8(min(nk.count, 255))); tlv.append(nk.prefix(255))
|
||||||
|
tlv.append(0x02); tlv.append(UInt8(min(nonceA.count, 255))); tlv.append(nonceA.prefix(255))
|
||||||
|
tlv.append(0x03); tlv.append(UInt8(min(sig.count, 255))); tlv.append(sig.prefix(255))
|
||||||
|
return NoisePayload(type: .verifyResponse, data: tlv).encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseVerifyChallenge(_ data: Data) -> (noiseKeyHex: String, nonceA: Data)? {
|
||||||
|
var idx = 0
|
||||||
|
func take(_ n: Int) -> Data? {
|
||||||
|
guard idx + n <= data.count else { return nil }
|
||||||
|
let d = data[idx..<(idx+n)]
|
||||||
|
idx += n
|
||||||
|
return Data(d)
|
||||||
|
}
|
||||||
|
// Expect type already stripped; we receive only TLV here
|
||||||
|
// TLV 0x01 noiseKeyHex
|
||||||
|
guard let t1 = take(1), t1[0] == 0x01, let l1 = take(1), let s1 = take(Int(l1[0])),
|
||||||
|
let noiseStr = String(data: s1, encoding: .utf8) else { return nil }
|
||||||
|
// TLV 0x02 nonceA
|
||||||
|
guard let t2 = take(1), t2[0] == 0x02, let l2 = take(1), let nA = take(Int(l2[0])) else { return nil }
|
||||||
|
return (noiseStr, nA)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseVerifyResponse(_ data: Data) -> (noiseKeyHex: String, nonceA: Data, signature: Data)? {
|
||||||
|
var idx = 0
|
||||||
|
func take(_ n: Int) -> Data? {
|
||||||
|
guard idx + n <= data.count else { return nil }
|
||||||
|
let d = data[idx..<(idx+n)]
|
||||||
|
idx += n
|
||||||
|
return Data(d)
|
||||||
|
}
|
||||||
|
guard let t1 = take(1), t1[0] == 0x01, let l1 = take(1), let s1 = take(Int(l1[0])),
|
||||||
|
let noiseStr = String(data: s1, encoding: .utf8) else { return nil }
|
||||||
|
guard let t2 = take(1), t2[0] == 0x02, let l2 = take(1), let nA = take(Int(l2[0])) else { return nil }
|
||||||
|
guard let t3 = take(1), t3[0] == 0x03, let l3 = take(1), let sig = take(Int(l3[0])) else { return nil }
|
||||||
|
return (noiseStr, nA, sig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func verifyResponseSignature(noiseKeyHex: String, nonceA: Data, signature: Data, signerPublicKeyHex: String) -> Bool {
|
||||||
|
var msg = Data("bitchat-verify-resp-v1".utf8)
|
||||||
|
let nk = noiseKeyHex.data(using: .utf8) ?? Data()
|
||||||
|
msg.append(UInt8(min(nk.count, 255))); msg.append(nk.prefix(255))
|
||||||
|
msg.append(nonceA)
|
||||||
|
guard let noise = noise, let pub = Data(hexString: signerPublicKeyHex) else { return false }
|
||||||
|
return noise.verifySignature(signature, for: msg, publicKey: pub)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,14 +18,18 @@ struct InputValidator {
|
|||||||
|
|
||||||
/// Validates a peer ID from any source (short 16-hex, full 64-hex, or internal alnum/-/_ up to 64)
|
/// Validates a peer ID from any source (short 16-hex, full 64-hex, or internal alnum/-/_ up to 64)
|
||||||
static func validatePeerID(_ peerID: String) -> Bool {
|
static func validatePeerID(_ peerID: String) -> Bool {
|
||||||
// Accept short routing IDs (16-hex)
|
// Accept short routing IDs (exact 16-hex)
|
||||||
if PeerIDResolver.isShortID(peerID) { return true }
|
if PeerIDResolver.isShortID(peerID) { return true }
|
||||||
// Accept full Noise key hex (64-hex)
|
// If length equals short-hex length but isn't valid hex, reject
|
||||||
|
if peerID.count == Limits.hexPeerIDLength { return false }
|
||||||
|
// Accept full Noise key hex (exact 64-hex)
|
||||||
if PeerIDResolver.isNoiseKeyHex(peerID) { return true }
|
if PeerIDResolver.isNoiseKeyHex(peerID) { return true }
|
||||||
// Internal format: alphanumeric + dash/underscore up to 64
|
// If length equals full key length but isn't valid hex, reject
|
||||||
|
if peerID.count == Limits.maxPeerIDLength { return false }
|
||||||
|
// Internal format: alphanumeric + dash/underscore up to 63 (not 16 or 64)
|
||||||
let validCharset = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-_"))
|
let validCharset = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-_"))
|
||||||
return !peerID.isEmpty &&
|
return !peerID.isEmpty &&
|
||||||
peerID.count <= Limits.maxPeerIDLength &&
|
peerID.count < Limits.maxPeerIDLength &&
|
||||||
peerID.rangeOfCharacter(from: validCharset.inverted) == nil
|
peerID.rangeOfCharacter(from: validCharset.inverted) == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Missing properties that were removed during refactoring
|
//
|
||||||
private var peerIDToPublicKeyFingerprint: [String: String] = [:]
|
private var peerIDToPublicKeyFingerprint: [String: String] = [:]
|
||||||
private var selectedPrivateChatFingerprint: String? = nil
|
private var selectedPrivateChatFingerprint: String? = nil
|
||||||
// Map stable short peer IDs (16-hex) to full Noise public key hex (64-hex) for session continuity
|
// Map stable short peer IDs (16-hex) to full Noise public key hex (64-hex) for session continuity
|
||||||
@@ -352,14 +352,12 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
private let maxProcessedNostrEvents = 2000
|
private let maxProcessedNostrEvents = 2000
|
||||||
private let userDefaults = UserDefaults.standard
|
private let userDefaults = UserDefaults.standard
|
||||||
private let nicknameKey = "bitchat.nickname"
|
private let nicknameKey = "bitchat.nickname"
|
||||||
// Location channel state
|
// Location channel state (macOS supports manual geohash selection)
|
||||||
#if os(iOS)
|
|
||||||
@Published private var activeChannel: ChannelID = .mesh
|
@Published private var activeChannel: ChannelID = .mesh
|
||||||
private var geoSubscriptionID: String? = nil
|
private var geoSubscriptionID: String? = nil
|
||||||
private var geoDmSubscriptionID: String? = nil
|
private var geoDmSubscriptionID: String? = nil
|
||||||
private var currentGeohash: String? = nil
|
private var currentGeohash: String? = nil
|
||||||
private var geoNicknames: [String: String] = [:] // pubkeyHex(lowercased) -> nickname
|
private var geoNicknames: [String: String] = [:] // pubkeyHex(lowercased) -> nickname
|
||||||
#endif
|
|
||||||
|
|
||||||
// MARK: - Caches
|
// MARK: - Caches
|
||||||
|
|
||||||
@@ -389,7 +387,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Persist mesh public timeline across channel switches
|
// Persist mesh public timeline across channel switches
|
||||||
private var meshTimeline: [BitchatMessage] = []
|
private var meshTimeline: [BitchatMessage] = []
|
||||||
private let meshTimelineCap = 1337
|
private let meshTimelineCap = 1337
|
||||||
#if os(iOS)
|
|
||||||
// Persist per-geohash public timelines across switches
|
// Persist per-geohash public timelines across switches
|
||||||
private var geoTimelines: [String: [BitchatMessage]] = [:] // geohash -> messages
|
private var geoTimelines: [String: [BitchatMessage]] = [:] // geohash -> messages
|
||||||
private let geoTimelineCap = 1337
|
private let geoTimelineCap = 1337
|
||||||
@@ -405,13 +402,28 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
@Published private(set) var teleportedGeo: Set<String> = [] // lowercased pubkey hex
|
@Published private(set) var teleportedGeo: Set<String> = [] // lowercased pubkey hex
|
||||||
// Sampling subscriptions for multiple geohashes (when channel sheet is open)
|
// Sampling subscriptions for multiple geohashes (when channel sheet is open)
|
||||||
private var geoSamplingSubs: [String: String] = [:] // subID -> geohash
|
private var geoSamplingSubs: [String: String] = [:] // subID -> geohash
|
||||||
#endif
|
|
||||||
|
|
||||||
// MARK: - Message Delivery Tracking
|
// MARK: - Message Delivery Tracking
|
||||||
|
|
||||||
// Delivery tracking
|
// Delivery tracking
|
||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
|
||||||
|
// MARK: - QR Verification (pending state)
|
||||||
|
private struct PendingVerification {
|
||||||
|
let noiseKeyHex: String
|
||||||
|
let signKeyHex: String
|
||||||
|
let nonceA: Data
|
||||||
|
let startedAt: Date
|
||||||
|
var sent: Bool
|
||||||
|
}
|
||||||
|
private var pendingQRVerifications: [String: PendingVerification] = [:] // peerID -> pending
|
||||||
|
// Last handled challenge nonce per peer to avoid duplicate responses
|
||||||
|
private var lastVerifyNonceByPeer: [String: Data] = [:]
|
||||||
|
// Track when we last received a verify challenge from a peer (fingerprint-keyed)
|
||||||
|
private var lastInboundVerifyChallengeAt: [String: Date] = [:] // key: fingerprint
|
||||||
|
// Throttle mutual verification toasts per fingerprint
|
||||||
|
private var lastMutualToastAt: [String: Date] = [:] // key: fingerprint
|
||||||
|
|
||||||
// MARK: - Public message batching (UI perf)
|
// MARK: - Public message batching (UI perf)
|
||||||
// Buffer incoming public messages and flush in small batches to reduce UI invalidations
|
// Buffer incoming public messages and flush in small batches to reduce UI invalidations
|
||||||
private var publicBuffer: [BitchatMessage] = []
|
private var publicBuffer: [BitchatMessage] = []
|
||||||
@@ -450,6 +462,9 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Throttle verification response toasts per peer to avoid spam
|
||||||
|
private var lastVerifyToastAt: [String: Date] = [:]
|
||||||
|
|
||||||
// Track processed Nostr ACKs to avoid duplicate processing
|
// Track processed Nostr ACKs to avoid duplicate processing
|
||||||
private var processedNostrAcks: Set<String> = [] // "messageId:ackType:senderPubkey" format
|
private var processedNostrAcks: Set<String> = [] // "messageId:ackType:senderPubkey" format
|
||||||
@@ -573,8 +588,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
|
|
||||||
self.cancellables.insert(cancellable)
|
self.cancellables.insert(cancellable)
|
||||||
|
|
||||||
// Resubscribe geohash on relay reconnect (iOS only)
|
// Resubscribe geohash on relay reconnect
|
||||||
#if os(iOS)
|
|
||||||
if let relayMgr = self.nostrRelayManager {
|
if let relayMgr = self.nostrRelayManager {
|
||||||
relayMgr.$isConnected
|
relayMgr.$isConnected
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
@@ -588,13 +602,11 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
.store(in: &self.cancellables)
|
.store(in: &self.cancellables)
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up Noise encryption callbacks
|
// Set up Noise encryption callbacks
|
||||||
setupNoiseCallbacks()
|
setupNoiseCallbacks()
|
||||||
|
|
||||||
#if os(iOS)
|
|
||||||
// Observe location channel selection
|
// Observe location channel selection
|
||||||
LocationChannelManager.shared.$selectedChannel
|
LocationChannelManager.shared.$selectedChannel
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
@@ -609,7 +621,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
self.switchLocationChannel(to: LocationChannelManager.shared.selectedChannel)
|
self.switchLocationChannel(to: LocationChannelManager.shared.selectedChannel)
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Request notification permission
|
// Request notification permission
|
||||||
NotificationService.shared.requestAuthorization()
|
NotificationService.shared.requestAuthorization()
|
||||||
@@ -695,8 +706,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Force immediate save
|
// Force immediate save
|
||||||
userDefaults.synchronize()
|
userDefaults.synchronize()
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
|
||||||
// Resubscribe to the active geohash channel without clearing timeline
|
// Resubscribe to the active geohash channel without clearing timeline
|
||||||
@MainActor
|
@MainActor
|
||||||
private func resubscribeCurrentGeohash() {
|
private func resubscribeCurrentGeohash() {
|
||||||
@@ -711,14 +721,19 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Unsubscribe + resubscribe
|
// Unsubscribe + resubscribe
|
||||||
NostrRelayManager.shared.unsubscribe(id: subID)
|
NostrRelayManager.shared.unsubscribe(id: subID)
|
||||||
let filter = NostrFilter.geohashEphemeral(ch.geohash, since: Date().addingTimeInterval(-3600), limit: 200)
|
let filter = NostrFilter.geohashEphemeral(ch.geohash, since: Date().addingTimeInterval(-3600), limit: 200)
|
||||||
NostrRelayManager.shared.subscribe(filter: filter, id: subID) { [weak self] event in
|
let subRelays = GeoRelayDirectory.shared.closestRelays(toGeohash: ch.geohash, count: 5)
|
||||||
|
NostrRelayManager.shared.subscribe(filter: filter, id: subID, relayUrls: subRelays) { [weak self] event in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
guard event.kind == NostrProtocol.EventKind.ephemeralEvent.rawValue else { return }
|
guard event.kind == NostrProtocol.EventKind.ephemeralEvent.rawValue else { return }
|
||||||
if self.processedNostrEvents.contains(event.id) { return }
|
if self.processedNostrEvents.contains(event.id) { return }
|
||||||
self.processedNostrEvents.insert(event.id)
|
self.processedNostrEvents.insert(event.id)
|
||||||
if let gh = self.currentGeohash,
|
if let gh = self.currentGeohash,
|
||||||
let myGeoIdentity = try? NostrIdentityBridge.deriveIdentity(forGeohash: gh),
|
let myGeoIdentity = try? NostrIdentityBridge.deriveIdentity(forGeohash: gh),
|
||||||
myGeoIdentity.publicKeyHex.lowercased() == event.pubkey.lowercased() { return }
|
myGeoIdentity.publicKeyHex.lowercased() == event.pubkey.lowercased() {
|
||||||
|
// Skip very recent self-echo from relay, but allow older events (e.g., after app restart)
|
||||||
|
let eventTime = Date(timeIntervalSince1970: TimeInterval(event.created_at))
|
||||||
|
if Date().timeIntervalSince(eventTime) < 15 { return }
|
||||||
|
}
|
||||||
if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 {
|
if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 {
|
||||||
let nick = nickTag[1]
|
let nick = nickTag[1]
|
||||||
self.geoNicknames[event.pubkey.lowercased()] = nick
|
self.geoNicknames[event.pubkey.lowercased()] = nick
|
||||||
@@ -832,16 +847,14 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
self.sentReadReceipts.insert(messageId)
|
self.sentReadReceipts.insert(messageId)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Optionally notify if app backgrounded and message is truly unread
|
// Notify for truly unread and recent messages when not viewing
|
||||||
#if os(iOS)
|
if shouldMarkUnread {
|
||||||
if shouldMarkUnread && UIApplication.shared.applicationState != .active {
|
|
||||||
NotificationService.shared.sendPrivateMessageNotification(
|
NotificationService.shared.sendPrivateMessageNotification(
|
||||||
from: senderName,
|
from: senderName,
|
||||||
message: pm.content,
|
message: pm.content,
|
||||||
peerID: convKey
|
peerID: convKey
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
self.objectWillChange.send()
|
self.objectWillChange.send()
|
||||||
case .delivered:
|
case .delivered:
|
||||||
@@ -868,11 +881,13 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
category: SecureLogger.session, level: .warning)
|
category: SecureLogger.session, level: .warning)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case .verifyChallenge, .verifyResponse:
|
||||||
|
// QR verification payloads over Nostr are not supported; ignore in geohash DMs
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// MARK: - Nickname Management
|
// MARK: - Nickname Management
|
||||||
|
|
||||||
@@ -1200,7 +1215,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
let mentions = parseMentions(from: content)
|
let mentions = parseMentions(from: content)
|
||||||
|
|
||||||
// Add message to local display
|
// Add message to local display
|
||||||
#if os(iOS)
|
|
||||||
var displaySender = nickname
|
var displaySender = nickname
|
||||||
var localSenderPeerID = meshService.myPeerID
|
var localSenderPeerID = meshService.myPeerID
|
||||||
if case .location(let ch) = activeChannel,
|
if case .location(let ch) = activeChannel,
|
||||||
@@ -1209,10 +1223,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
displaySender = nickname + "#" + suffix
|
displaySender = nickname + "#" + suffix
|
||||||
localSenderPeerID = "nostr:\(myGeoIdentity.publicKeyHex.prefix(8))"
|
localSenderPeerID = "nostr:\(myGeoIdentity.publicKeyHex.prefix(8))"
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
let displaySender = nickname
|
|
||||||
let localSenderPeerID = meshService.myPeerID
|
|
||||||
#endif
|
|
||||||
|
|
||||||
let message = BitchatMessage(
|
let message = BitchatMessage(
|
||||||
sender: displaySender,
|
sender: displaySender,
|
||||||
@@ -1232,7 +1242,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
let ckey = normalizedContentKey(message.content)
|
let ckey = normalizedContentKey(message.content)
|
||||||
recordContentKey(ckey, timestamp: message.timestamp)
|
recordContentKey(ckey, timestamp: message.timestamp)
|
||||||
// Persist to channel-specific timelines
|
// Persist to channel-specific timelines
|
||||||
#if os(iOS)
|
|
||||||
switch activeChannel {
|
switch activeChannel {
|
||||||
case .mesh:
|
case .mesh:
|
||||||
meshTimeline.append(message)
|
meshTimeline.append(message)
|
||||||
@@ -1243,26 +1252,19 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
if arr.count > geoTimelineCap { arr = Array(arr.suffix(geoTimelineCap)) }
|
if arr.count > geoTimelineCap { arr = Array(arr.suffix(geoTimelineCap)) }
|
||||||
geoTimelines[ch.geohash] = arr
|
geoTimelines[ch.geohash] = arr
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
meshTimeline.append(message)
|
|
||||||
trimMeshTimelineIfNeeded()
|
|
||||||
#endif
|
|
||||||
trimMessagesIfNeeded()
|
trimMessagesIfNeeded()
|
||||||
|
|
||||||
// Force immediate UI update for user's own messages
|
// Force immediate UI update for user's own messages
|
||||||
objectWillChange.send()
|
objectWillChange.send()
|
||||||
|
|
||||||
// Update channel activity time on send
|
// Update channel activity time on send
|
||||||
#if os(iOS)
|
|
||||||
switch activeChannel {
|
switch activeChannel {
|
||||||
case .mesh:
|
case .mesh:
|
||||||
lastPublicActivityAt["mesh"] = Date()
|
lastPublicActivityAt["mesh"] = Date()
|
||||||
case .location(let ch):
|
case .location(let ch):
|
||||||
lastPublicActivityAt["geo:\(ch.geohash)"] = Date()
|
lastPublicActivityAt["geo:\(ch.geohash)"] = Date()
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if os(iOS)
|
|
||||||
if case .location(let ch) = activeChannel {
|
if case .location(let ch) = activeChannel {
|
||||||
// Send to geohash channel via Nostr ephemeral
|
// Send to geohash channel via Nostr ephemeral
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
@@ -1275,7 +1277,12 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
nickname: self.nickname,
|
nickname: self.nickname,
|
||||||
teleported: LocationChannelManager.shared.teleported
|
teleported: LocationChannelManager.shared.teleported
|
||||||
)
|
)
|
||||||
NostrRelayManager.shared.sendEvent(event)
|
let targetRelays = GeoRelayDirectory.shared.closestRelays(toGeohash: ch.geohash, count: 5)
|
||||||
|
if targetRelays.isEmpty {
|
||||||
|
SecureLogger.log("Geo: no geohash relays available for \(ch.geohash); not sending", category: SecureLogger.session, level: .warning)
|
||||||
|
} else {
|
||||||
|
NostrRelayManager.shared.sendEvent(event, to: targetRelays)
|
||||||
|
}
|
||||||
// Track ourselves as active participant
|
// Track ourselves as active participant
|
||||||
self.recordGeoParticipant(pubkeyHex: identity.publicKeyHex)
|
self.recordGeoParticipant(pubkeyHex: identity.publicKeyHex)
|
||||||
SecureLogger.log("GeoTeleport: sent geo message pub=\(identity.publicKeyHex.prefix(8))… teleported=\(LocationChannelManager.shared.teleported)",
|
SecureLogger.log("GeoTeleport: sent geo message pub=\(identity.publicKeyHex.prefix(8))… teleported=\(LocationChannelManager.shared.teleported)",
|
||||||
@@ -1296,14 +1303,10 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Send via mesh with mentions
|
// Send via mesh with mentions
|
||||||
meshService.sendMessage(content, mentions: mentions)
|
meshService.sendMessage(content, mentions: mentions)
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
// Send via mesh with mentions (non-iOS)
|
|
||||||
meshService.sendMessage(content, mentions: mentions)
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func switchLocationChannel(to channel: ChannelID) {
|
private func switchLocationChannel(to channel: ChannelID) {
|
||||||
// Flush pending public buffer to avoid cross-channel bleed
|
// Flush pending public buffer to avoid cross-channel bleed
|
||||||
@@ -1346,20 +1349,19 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Ensure self appears immediately in the people list; mark teleported state if applicable
|
// Ensure self appears immediately in the people list; mark teleported state if applicable
|
||||||
if let id = try? NostrIdentityBridge.deriveIdentity(forGeohash: ch.geohash) {
|
if let id = try? NostrIdentityBridge.deriveIdentity(forGeohash: ch.geohash) {
|
||||||
self.recordGeoParticipant(pubkeyHex: id.publicKeyHex)
|
self.recordGeoParticipant(pubkeyHex: id.publicKeyHex)
|
||||||
#if os(iOS)
|
|
||||||
if LocationChannelManager.shared.teleported {
|
if LocationChannelManager.shared.teleported {
|
||||||
let key = id.publicKeyHex.lowercased()
|
let key = id.publicKeyHex.lowercased()
|
||||||
teleportedGeo = teleportedGeo.union([key])
|
teleportedGeo = teleportedGeo.union([key])
|
||||||
SecureLogger.log("GeoTeleport: channel switch mark self teleported key=\(key.prefix(8))… total=\(teleportedGeo.count)",
|
SecureLogger.log("GeoTeleport: channel switch mark self teleported key=\(key.prefix(8))… total=\(teleportedGeo.count)",
|
||||||
category: SecureLogger.session, level: .info)
|
category: SecureLogger.session, level: .info)
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
let subID = "geo-\(ch.geohash)"
|
let subID = "geo-\(ch.geohash)"
|
||||||
geoSubscriptionID = subID
|
geoSubscriptionID = subID
|
||||||
startGeoParticipantsTimer()
|
startGeoParticipantsTimer()
|
||||||
let filter = NostrFilter.geohashEphemeral(ch.geohash, since: Date().addingTimeInterval(-3600), limit: 200)
|
let filter = NostrFilter.geohashEphemeral(ch.geohash, since: Date().addingTimeInterval(-3600), limit: 200)
|
||||||
NostrRelayManager.shared.subscribe(filter: filter, id: subID) { [weak self] event in
|
let subRelays = GeoRelayDirectory.shared.closestRelays(toGeohash: ch.geohash, count: 5)
|
||||||
|
NostrRelayManager.shared.subscribe(filter: filter, id: subID, relayUrls: subRelays) { [weak self] event in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
// Only handle ephemeral kind 20000 with matching tag
|
// Only handle ephemeral kind 20000 with matching tag
|
||||||
guard event.kind == NostrProtocol.EventKind.ephemeralEvent.rawValue else { return }
|
guard event.kind == NostrProtocol.EventKind.ephemeralEvent.rawValue else { return }
|
||||||
@@ -1382,11 +1384,12 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
category: SecureLogger.session, level: .info)
|
category: SecureLogger.session, level: .info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Skip our own events (we already locally echoed)
|
// Skip only very recent self-echo from relay; include older self events for hydration
|
||||||
if let gh = self.currentGeohash,
|
if let gh = self.currentGeohash,
|
||||||
let myGeoIdentity = try? NostrIdentityBridge.deriveIdentity(forGeohash: gh),
|
let myGeoIdentity = try? NostrIdentityBridge.deriveIdentity(forGeohash: gh),
|
||||||
myGeoIdentity.publicKeyHex.lowercased() == event.pubkey.lowercased() {
|
myGeoIdentity.publicKeyHex.lowercased() == event.pubkey.lowercased() {
|
||||||
return
|
let eventTime = Date(timeIntervalSince1970: TimeInterval(event.created_at))
|
||||||
|
if Date().timeIntervalSince(eventTime) < 15 { return }
|
||||||
}
|
}
|
||||||
// Cache nickname from tag if present
|
// Cache nickname from tag if present
|
||||||
if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 {
|
if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 {
|
||||||
@@ -1514,19 +1517,14 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
} else {
|
} else {
|
||||||
// pared back: omit defer READ log
|
// pared back: omit defer READ log
|
||||||
}
|
}
|
||||||
// Notify only when app is backgrounded and not viewing, and only if not already read
|
// Notify for truly unread and recent messages when not viewing
|
||||||
#if os(iOS)
|
|
||||||
if !isViewing && shouldMarkUnread {
|
if !isViewing && shouldMarkUnread {
|
||||||
if UIApplication.shared.applicationState != .active {
|
NotificationService.shared.sendPrivateMessageNotification(
|
||||||
NotificationService.shared.sendPrivateMessageNotification(
|
from: senderName,
|
||||||
from: senderName,
|
message: pm.content,
|
||||||
message: pm.content,
|
peerID: convKey
|
||||||
peerID: convKey
|
)
|
||||||
)
|
|
||||||
// pared back: omit notification log
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
self.objectWillChange.send()
|
self.objectWillChange.send()
|
||||||
default:
|
default:
|
||||||
// Handle delivered/read receipts for our sent messages
|
// Handle delivered/read receipts for our sent messages
|
||||||
@@ -1563,11 +1561,10 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
// Presence announcement removed; we will tag actual chat events instead
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Geohash Participants (iOS)
|
// MARK: - Geohash Participants
|
||||||
#if os(iOS)
|
|
||||||
struct GeoPerson: Identifiable, Equatable {
|
struct GeoPerson: Identifiable, Equatable {
|
||||||
let id: String // pubkey hex (lowercased)
|
let id: String // pubkey hex (lowercased)
|
||||||
let displayName: String
|
let displayName: String
|
||||||
@@ -1625,10 +1622,8 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
geoParticipantsTimer?.invalidate()
|
geoParticipantsTimer?.invalidate()
|
||||||
geoParticipantsTimer = nil
|
geoParticipantsTimer = nil
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
// MARK: - Public helpers
|
||||||
// MARK: - Public helpers (iOS)
|
|
||||||
#if os(iOS)
|
|
||||||
/// Return the current, pruned, sorted people list for the active geohash without mutating state.
|
/// Return the current, pruned, sorted people list for the active geohash without mutating state.
|
||||||
@MainActor
|
@MainActor
|
||||||
func visibleGeohashPeople() -> [GeoPerson] {
|
func visibleGeohashPeople() -> [GeoPerson] {
|
||||||
@@ -1719,7 +1714,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
let toAdd = desired.subtracting(current)
|
let toAdd = desired.subtracting(current)
|
||||||
let toRemove = current.subtracting(desired)
|
let toRemove = current.subtracting(desired)
|
||||||
|
|
||||||
// Unsubscribe removed
|
//
|
||||||
for (subID, gh) in geoSamplingSubs where toRemove.contains(gh) {
|
for (subID, gh) in geoSamplingSubs where toRemove.contains(gh) {
|
||||||
NostrRelayManager.shared.unsubscribe(id: subID)
|
NostrRelayManager.shared.unsubscribe(id: subID)
|
||||||
geoSamplingSubs.removeValue(forKey: subID)
|
geoSamplingSubs.removeValue(forKey: subID)
|
||||||
@@ -1730,7 +1725,8 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
let subID = "geo-sample-\(gh)"
|
let subID = "geo-sample-\(gh)"
|
||||||
geoSamplingSubs[subID] = gh
|
geoSamplingSubs[subID] = gh
|
||||||
let filter = NostrFilter.geohashEphemeral(gh, since: Date().addingTimeInterval(-300), limit: 100)
|
let filter = NostrFilter.geohashEphemeral(gh, since: Date().addingTimeInterval(-300), limit: 100)
|
||||||
NostrRelayManager.shared.subscribe(filter: filter, id: subID) { [weak self] event in
|
let subRelays = GeoRelayDirectory.shared.closestRelays(toGeohash: gh, count: 5)
|
||||||
|
NostrRelayManager.shared.subscribe(filter: filter, id: subID, relayUrls: subRelays) { [weak self] event in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
guard event.kind == NostrProtocol.EventKind.ephemeralEvent.rawValue else { return }
|
guard event.kind == NostrProtocol.EventKind.ephemeralEvent.rawValue else { return }
|
||||||
// Update participants for this specific geohash
|
// Update participants for this specific geohash
|
||||||
@@ -1745,7 +1741,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
for subID in geoSamplingSubs.keys { NostrRelayManager.shared.unsubscribe(id: subID) }
|
for subID in geoSamplingSubs.keys { NostrRelayManager.shared.unsubscribe(id: subID) }
|
||||||
geoSamplingSubs.removeAll()
|
geoSamplingSubs.removeAll()
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
private func displayNameForNostrPubkey(_ pubkeyHex: String) -> String {
|
private func displayNameForNostrPubkey(_ pubkeyHex: String) -> String {
|
||||||
let suffix = String(pubkeyHex.suffix(4))
|
let suffix = String(pubkeyHex.suffix(4))
|
||||||
@@ -1765,16 +1760,12 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
|
|
||||||
// Helper: display name for current active channel (for notifications)
|
// Helper: display name for current active channel (for notifications)
|
||||||
private func activeChannelDisplayName() -> String {
|
private func activeChannelDisplayName() -> String {
|
||||||
#if os(iOS)
|
|
||||||
switch activeChannel {
|
switch activeChannel {
|
||||||
case .mesh:
|
case .mesh:
|
||||||
return "#mesh"
|
return "#mesh"
|
||||||
case .location(let ch):
|
case .location(let ch):
|
||||||
return "#\(ch.geohash)"
|
return "#\(ch.geohash)"
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
return "#mesh"
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dedup helper with small memory cap
|
// Dedup helper with small memory cap
|
||||||
@@ -1791,7 +1782,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Sends an encrypted private message to a specific peer.
|
/// Sends an encrypted private message to a specific peer.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
@@ -1803,7 +1793,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
guard !content.isEmpty else { return }
|
guard !content.isEmpty else { return }
|
||||||
|
|
||||||
// Geohash DM routing: conversation keys start with "nostr_"
|
// Geohash DM routing: conversation keys start with "nostr_"
|
||||||
#if os(iOS)
|
|
||||||
if peerID.hasPrefix("nostr_") {
|
if peerID.hasPrefix("nostr_") {
|
||||||
guard case .location(let ch) = activeChannel else {
|
guard case .location(let ch) = activeChannel else {
|
||||||
addSystemMessage("cannot send: not in a location channel")
|
addSystemMessage("cannot send: not in a location channel")
|
||||||
@@ -1869,7 +1858,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Check if blocked
|
// Check if blocked
|
||||||
if unifiedPeerService.isBlocked(peerID) {
|
if unifiedPeerService.isBlocked(peerID) {
|
||||||
@@ -1936,7 +1924,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
|
||||||
// MARK: - Geohash DMs initiation
|
// MARK: - Geohash DMs initiation
|
||||||
@MainActor
|
@MainActor
|
||||||
func startGeohashDM(withPubkeyHex hex: String) {
|
func startGeohashDM(withPubkeyHex hex: String) {
|
||||||
@@ -1962,7 +1949,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
return "anon#\(suffix)"
|
return "anon#\(suffix)"
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
/// Add a local system message to a private chat (no network send)
|
/// Add a local system message to a private chat (no network send)
|
||||||
@MainActor
|
@MainActor
|
||||||
func addLocalPrivateSystemMessage(_ content: String, to peerID: String) {
|
func addLocalPrivateSystemMessage(_ content: String, to peerID: String) {
|
||||||
@@ -2416,9 +2402,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Also resubscribe the current geohash channel if active
|
// Also resubscribe the current geohash channel if active
|
||||||
#if os(iOS)
|
|
||||||
resubscribeCurrentGeohash()
|
resubscribeCurrentGeohash()
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
@@ -2463,7 +2447,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// In public chat - send to active public channel
|
// In public chat - send to active public channel
|
||||||
#if os(iOS)
|
|
||||||
switch activeChannel {
|
switch activeChannel {
|
||||||
case .mesh:
|
case .mesh:
|
||||||
meshService.sendMessage(screenshotMessage, mentions: [])
|
meshService.sendMessage(screenshotMessage, mentions: [])
|
||||||
@@ -2478,7 +2461,17 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
nickname: self.nickname,
|
nickname: self.nickname,
|
||||||
teleported: LocationChannelManager.shared.teleported
|
teleported: LocationChannelManager.shared.teleported
|
||||||
)
|
)
|
||||||
NostrRelayManager.shared.sendEvent(event)
|
let targetRelays = GeoRelayDirectory.shared.closestRelays(toGeohash: ch.geohash, count: 5)
|
||||||
|
if targetRelays.isEmpty {
|
||||||
|
let targetRelays = GeoRelayDirectory.shared.closestRelays(toGeohash: ch.geohash, count: 5)
|
||||||
|
if targetRelays.isEmpty {
|
||||||
|
SecureLogger.log("Geo: no geohash relays available for \(ch.geohash); not sending", category: SecureLogger.session, level: .warning)
|
||||||
|
} else {
|
||||||
|
NostrRelayManager.shared.sendEvent(event, to: targetRelays)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NostrRelayManager.shared.sendEvent(event, to: targetRelays)
|
||||||
|
}
|
||||||
// Track ourselves as active participant
|
// Track ourselves as active participant
|
||||||
self.recordGeoParticipant(pubkeyHex: identity.publicKeyHex)
|
self.recordGeoParticipant(pubkeyHex: identity.publicKeyHex)
|
||||||
} catch {
|
} catch {
|
||||||
@@ -2487,9 +2480,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
meshService.sendMessage(screenshotMessage, mentions: [])
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Show local notification immediately as system message
|
// Show local notification immediately as system message
|
||||||
let localNotification = BitchatMessage(
|
let localNotification = BitchatMessage(
|
||||||
@@ -2569,7 +2560,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
privateChatManager.markAsRead(from: peerID)
|
privateChatManager.markAsRead(from: peerID)
|
||||||
|
|
||||||
// Handle GeoDM (nostr_*) read receipts directly via per-geohash identity
|
// Handle GeoDM (nostr_*) read receipts directly via per-geohash identity
|
||||||
#if os(iOS)
|
|
||||||
if peerID.hasPrefix("nostr_"),
|
if peerID.hasPrefix("nostr_"),
|
||||||
let recipientHex = nostrKeyMapping[peerID],
|
let recipientHex = nostrKeyMapping[peerID],
|
||||||
case .location(let ch) = LocationChannelManager.shared.selectedChannel,
|
case .location(let ch) = LocationChannelManager.shared.selectedChannel,
|
||||||
@@ -2587,7 +2577,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Get the peer's Noise key to check for Nostr messages
|
// Get the peer's Noise key to check for Nostr messages
|
||||||
var noiseKeyHex: String? = nil
|
var noiseKeyHex: String? = nil
|
||||||
@@ -2684,7 +2673,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
func getPeerIDForNickname(_ nickname: String) -> String? {
|
func getPeerIDForNickname(_ nickname: String) -> String? {
|
||||||
#if os(iOS)
|
|
||||||
// When in a geohash channel, allow resolving by geohash participant nickname
|
// When in a geohash channel, allow resolving by geohash participant nickname
|
||||||
switch LocationChannelManager.shared.selectedChannel {
|
switch LocationChannelManager.shared.selectedChannel {
|
||||||
case .location:
|
case .location:
|
||||||
@@ -2698,9 +2686,10 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
nostrKeyMapping[convKey] = pub
|
nostrKeyMapping[convKey] = pub
|
||||||
return convKey
|
return convKey
|
||||||
}
|
}
|
||||||
default: break
|
default:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
#endif
|
// Fallback to mesh nickname resolution
|
||||||
return unifiedPeerService.getPeerID(for: nickname)
|
return unifiedPeerService.getPeerID(for: nickname)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2808,7 +2797,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
func updateAutocomplete(for text: String, cursorPosition: Int) {
|
func updateAutocomplete(for text: String, cursorPosition: Int) {
|
||||||
// Build candidate list based on active channel
|
// Build candidate list based on active channel
|
||||||
let peerCandidates: [String] = {
|
let peerCandidates: [String] = {
|
||||||
#if os(iOS)
|
|
||||||
switch activeChannel {
|
switch activeChannel {
|
||||||
case .mesh:
|
case .mesh:
|
||||||
let values = meshService.getPeerNicknames().values
|
let values = meshService.getPeerNicknames().values
|
||||||
@@ -2827,10 +2815,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
return Array(tokens)
|
return Array(tokens)
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
let values = meshService.getPeerNicknames().values
|
|
||||||
return Array(values.filter { $0 != meshService.myNickname })
|
|
||||||
#endif
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let (suggestions, range) = autocompleteService.getSuggestions(
|
let (suggestions, range) = autocompleteService.getSuggestions(
|
||||||
@@ -2951,13 +2935,12 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Determine if this message was sent by self (mesh, geo, or DM)
|
// Determine if this message was sent by self (mesh, geo, or DM)
|
||||||
let isSelf: Bool = {
|
let isSelf: Bool = {
|
||||||
if let spid = message.senderPeerID {
|
if let spid = message.senderPeerID {
|
||||||
#if os(iOS)
|
// In geohash channels, compare against our per-geohash nostr short ID
|
||||||
if case .location(let ch) = activeChannel, spid.hasPrefix("nostr:") {
|
if case .location(let ch) = activeChannel, spid.hasPrefix("nostr:") {
|
||||||
if let myGeo = try? NostrIdentityBridge.deriveIdentity(forGeohash: ch.geohash) {
|
if let myGeo = try? NostrIdentityBridge.deriveIdentity(forGeohash: ch.geohash) {
|
||||||
return spid == "nostr:\(myGeo.publicKeyHex.prefix(8))"
|
return spid == "nostr:\(myGeo.publicKeyHex.prefix(8))"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return spid == meshService.myPeerID
|
return spid == meshService.myPeerID
|
||||||
}
|
}
|
||||||
// Fallback by nickname
|
// Fallback by nickname
|
||||||
@@ -3108,11 +3091,9 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
let (mBase, mSuffix) = splitSuffix(from: matchText.replacingOccurrences(of: "@", with: ""))
|
let (mBase, mSuffix) = splitSuffix(from: matchText.replacingOccurrences(of: "@", with: ""))
|
||||||
// Determine if this mention targets me (resolves with optional suffix per active channel)
|
// Determine if this mention targets me (resolves with optional suffix per active channel)
|
||||||
let mySuffix: String? = {
|
let mySuffix: String? = {
|
||||||
#if os(iOS)
|
|
||||||
if case .location(let ch) = activeChannel, let id = try? NostrIdentityBridge.deriveIdentity(forGeohash: ch.geohash) {
|
if case .location(let ch) = activeChannel, let id = try? NostrIdentityBridge.deriveIdentity(forGeohash: ch.geohash) {
|
||||||
return String(id.publicKeyHex.suffix(4))
|
return String(id.publicKeyHex.suffix(4))
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return String(meshService.myPeerID.prefix(4))
|
return String(meshService.myPeerID.prefix(4))
|
||||||
}()
|
}()
|
||||||
let isMentionToMe: Bool = {
|
let isMentionToMe: Bool = {
|
||||||
@@ -3145,12 +3126,28 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
let token = String(matchText.dropFirst()).lowercased()
|
let token = String(matchText.dropFirst()).lowercased()
|
||||||
let allowed = Set("0123456789bcdefghjkmnpqrstuvwxyz")
|
let allowed = Set("0123456789bcdefghjkmnpqrstuvwxyz")
|
||||||
let isGeohash = (2...12).contains(token.count) && token.allSatisfy { allowed.contains($0) }
|
let isGeohash = (2...12).contains(token.count) && token.allSatisfy { allowed.contains($0) }
|
||||||
|
// Do not link if this hashtag is directly attached to an @mention (e.g., @name#geohash)
|
||||||
|
let attachedToMention: Bool = {
|
||||||
|
// nsRange is the Range<String.Index> for this match within content
|
||||||
|
// Walk left until whitespace/newline; if we encounter '@' first, treat as part of mention
|
||||||
|
if nsRange.lowerBound > content.startIndex {
|
||||||
|
var i = content.index(before: nsRange.lowerBound)
|
||||||
|
while true {
|
||||||
|
let ch = content[i]
|
||||||
|
if ch.isWhitespace || ch.isNewline { break }
|
||||||
|
if ch == "@" { return true }
|
||||||
|
if i == content.startIndex { break }
|
||||||
|
i = content.index(before: i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}()
|
||||||
var tagStyle = AttributeContainer()
|
var tagStyle = AttributeContainer()
|
||||||
tagStyle.font = isSelf
|
tagStyle.font = isSelf
|
||||||
? .system(size: 14, weight: .bold, design: .monospaced)
|
? .system(size: 14, weight: .bold, design: .monospaced)
|
||||||
: .system(size: 14, design: .monospaced)
|
: .system(size: 14, design: .monospaced)
|
||||||
tagStyle.foregroundColor = baseColor
|
tagStyle.foregroundColor = baseColor
|
||||||
if isGeohash, let url = URL(string: "bitchat://geohash/\(token)") {
|
if isGeohash && !attachedToMention, let url = URL(string: "bitchat://geohash/\(token)") {
|
||||||
tagStyle.link = url
|
tagStyle.link = url
|
||||||
tagStyle.underlineStyle = .single
|
tagStyle.underlineStyle = .single
|
||||||
}
|
}
|
||||||
@@ -3548,7 +3545,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Clear the current public channel's timeline (visible + persistent buffer)
|
// Clear the current public channel's timeline (visible + persistent buffer)
|
||||||
@MainActor
|
@MainActor
|
||||||
func clearCurrentPublicTimeline() {
|
func clearCurrentPublicTimeline() {
|
||||||
#if os(iOS)
|
|
||||||
switch activeChannel {
|
switch activeChannel {
|
||||||
case .mesh:
|
case .mesh:
|
||||||
messages.removeAll()
|
messages.removeAll()
|
||||||
@@ -3557,10 +3553,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
messages.removeAll()
|
messages.removeAll()
|
||||||
geoTimelines[ch.geohash] = []
|
geoTimelines[ch.geohash] = []
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
messages.removeAll()
|
|
||||||
meshTimeline.removeAll()
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func trimPrivateChatMessagesIfNeeded(for peerID: String) {
|
private func trimPrivateChatMessagesIfNeeded(for peerID: String) {
|
||||||
@@ -3625,26 +3617,8 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
return unifiedPeerService.getFingerprint(for: peerID)
|
return unifiedPeerService.getFingerprint(for: peerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getFingerprint_old(for peerID: String) -> String? {
|
//
|
||||||
// Remove debug logging to prevent console spam during view updates
|
|
||||||
|
|
||||||
// First try to get fingerprint from mesh service's peer ID rotation mapping
|
|
||||||
if let fingerprint = meshService.getFingerprint(for: peerID) {
|
|
||||||
return fingerprint
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check noise service (direct Noise session fingerprint)
|
|
||||||
if let fingerprint = meshService.getNoiseService().getPeerFingerprint(peerID) {
|
|
||||||
return fingerprint
|
|
||||||
}
|
|
||||||
|
|
||||||
// Last resort: check local mapping
|
|
||||||
if let fingerprint = peerIDToPublicKeyFingerprint[peerID] {
|
|
||||||
return fingerprint
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper to resolve nickname for a peer ID through various sources
|
// Helper to resolve nickname for a peer ID through various sources
|
||||||
@MainActor
|
@MainActor
|
||||||
@@ -3710,10 +3684,35 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Update encryption status after verification
|
// Update encryption status after verification
|
||||||
updateEncryptionStatus(for: peerID)
|
updateEncryptionStatus(for: peerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
func unverifyFingerprint(for peerID: String) {
|
||||||
|
guard let fingerprint = getFingerprint(for: peerID) else { return }
|
||||||
|
SecureIdentityStateManager.shared.setVerified(fingerprint: fingerprint, verified: false)
|
||||||
|
SecureIdentityStateManager.shared.forceSave()
|
||||||
|
verifiedFingerprints.remove(fingerprint)
|
||||||
|
updateEncryptionStatus(for: peerID)
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
func loadVerifiedFingerprints() {
|
func loadVerifiedFingerprints() {
|
||||||
// Load verified fingerprints directly from secure storage
|
// Load verified fingerprints directly from secure storage
|
||||||
verifiedFingerprints = SecureIdentityStateManager.shared.getVerifiedFingerprints()
|
verifiedFingerprints = SecureIdentityStateManager.shared.getVerifiedFingerprints()
|
||||||
|
// Log snapshot for debugging persistence
|
||||||
|
let sample = Array(verifiedFingerprints.prefix(3)).map { $0.prefix(8) }.joined(separator: ", ")
|
||||||
|
SecureLogger.log("🔐 Verified loaded: \(verifiedFingerprints.count) [\(sample)]", category: SecureLogger.security, level: .info)
|
||||||
|
// Also log any offline favorites and whether we consider them verified
|
||||||
|
let offlineFavorites = unifiedPeerService.favorites.filter { !$0.isConnected }
|
||||||
|
for fav in offlineFavorites {
|
||||||
|
let fp = unifiedPeerService.getFingerprint(for: fav.id)
|
||||||
|
let isVer = fp.flatMap { verifiedFingerprints.contains($0) } ?? false
|
||||||
|
let fpShort = fp?.prefix(8) ?? "nil"
|
||||||
|
SecureLogger.log("⭐️ Favorite offline: \(fav.nickname) fp=\(fpShort) verified=\(isVer)", category: SecureLogger.security, level: .info)
|
||||||
|
}
|
||||||
|
// Invalidate cached encryption statuses so offline favorites can show verified badges immediately
|
||||||
|
invalidateEncryptionCache()
|
||||||
|
// Trigger UI refresh of peer list
|
||||||
|
objectWillChange.send()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setupNoiseCallbacks() {
|
private func setupNoiseCallbacks() {
|
||||||
@@ -3747,6 +3746,14 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
category: SecureLogger.session, level: .debug)
|
category: SecureLogger.session, level: .debug)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a QR verification is pending but not sent yet, send it now that session is authenticated
|
||||||
|
if var pending = self.pendingQRVerifications[peerID], pending.sent == false {
|
||||||
|
self.meshService.sendVerifyChallenge(to: peerID, noiseKeyHex: pending.noiseKeyHex, nonceA: pending.nonceA)
|
||||||
|
pending.sent = true
|
||||||
|
self.pendingQRVerifications[peerID] = pending
|
||||||
|
SecureLogger.log("📤 Sent deferred verify challenge to \(peerID) after handshake", category: SecureLogger.security, level: .debug)
|
||||||
|
}
|
||||||
|
|
||||||
// Schedule UI update
|
// Schedule UI update
|
||||||
// UI will update automatically
|
// UI will update automatically
|
||||||
}
|
}
|
||||||
@@ -3850,6 +3857,72 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
objectWillChange.send()
|
objectWillChange.send()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case .verifyChallenge:
|
||||||
|
// Parse and respond
|
||||||
|
guard let tlv = VerificationService.shared.parseVerifyChallenge(payload) else { return }
|
||||||
|
// Ensure intended for our noise key
|
||||||
|
let myNoiseHex = meshService.getNoiseService().getStaticPublicKeyData().hexEncodedString().lowercased()
|
||||||
|
guard tlv.noiseKeyHex.lowercased() == myNoiseHex else { return }
|
||||||
|
// Deduplicate: ignore if we've already responded to this nonce for this peer
|
||||||
|
if let last = lastVerifyNonceByPeer[peerID], last == tlv.nonceA { return }
|
||||||
|
lastVerifyNonceByPeer[peerID] = tlv.nonceA
|
||||||
|
// Record inbound challenge time keyed by stable fingerprint if available
|
||||||
|
if let fp = getFingerprint(for: peerID) {
|
||||||
|
lastInboundVerifyChallengeAt[fp] = Date()
|
||||||
|
// If we've already verified this fingerprint locally, treat this as mutual and toast immediately (responder side)
|
||||||
|
if verifiedFingerprints.contains(fp) {
|
||||||
|
let now = Date()
|
||||||
|
let last = lastMutualToastAt[fp] ?? .distantPast
|
||||||
|
if now.timeIntervalSince(last) > 60 { // 1-minute throttle
|
||||||
|
lastMutualToastAt[fp] = now
|
||||||
|
let name = unifiedPeerService.getPeer(by: peerID)?.nickname ?? resolveNickname(for: peerID)
|
||||||
|
NotificationService.shared.sendLocalNotification(
|
||||||
|
title: "Mutual verification",
|
||||||
|
body: "You and \(name) verified each other",
|
||||||
|
identifier: "verify-mutual-\(peerID)-\(UUID().uuidString)"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
meshService.sendVerifyResponse(to: peerID, noiseKeyHex: tlv.noiseKeyHex, nonceA: tlv.nonceA)
|
||||||
|
// Silent response: no toast needed on responder
|
||||||
|
case .verifyResponse:
|
||||||
|
guard let resp = VerificationService.shared.parseVerifyResponse(payload) else { return }
|
||||||
|
// Check pending for this peer
|
||||||
|
guard let pending = pendingQRVerifications[peerID] else { return }
|
||||||
|
guard resp.noiseKeyHex.lowercased() == pending.noiseKeyHex.lowercased(), resp.nonceA == pending.nonceA else { return }
|
||||||
|
// Verify signature with expected sign key
|
||||||
|
let ok = VerificationService.shared.verifyResponseSignature(noiseKeyHex: resp.noiseKeyHex, nonceA: resp.nonceA, signature: resp.signature, signerPublicKeyHex: pending.signKeyHex)
|
||||||
|
if ok {
|
||||||
|
pendingQRVerifications.removeValue(forKey: peerID)
|
||||||
|
if let fp = getFingerprint(for: peerID) {
|
||||||
|
let short = fp.prefix(8)
|
||||||
|
SecureLogger.log("🔐 Marking verified fingerprint: \(short)", category: SecureLogger.security, level: .info)
|
||||||
|
SecureIdentityStateManager.shared.setVerified(fingerprint: fp, verified: true)
|
||||||
|
SecureIdentityStateManager.shared.forceSave()
|
||||||
|
verifiedFingerprints.insert(fp)
|
||||||
|
let name = unifiedPeerService.getPeer(by: peerID)?.nickname ?? resolveNickname(for: peerID)
|
||||||
|
NotificationService.shared.sendLocalNotification(
|
||||||
|
title: "Verified",
|
||||||
|
body: "You verified \(name)",
|
||||||
|
identifier: "verify-success-\(peerID)-\(UUID().uuidString)"
|
||||||
|
)
|
||||||
|
// If we also recently responded to their challenge, flag mutual and toast (initiator side)
|
||||||
|
if let t = lastInboundVerifyChallengeAt[fp], Date().timeIntervalSince(t) < 600 {
|
||||||
|
let now = Date()
|
||||||
|
let lastToast = lastMutualToastAt[fp] ?? .distantPast
|
||||||
|
if now.timeIntervalSince(lastToast) > 60 {
|
||||||
|
lastMutualToastAt[fp] = now
|
||||||
|
NotificationService.shared.sendLocalNotification(
|
||||||
|
title: "Mutual verification",
|
||||||
|
body: "You and \(name) verified each other",
|
||||||
|
identifier: "verify-mutual-\(peerID)-\(UUID().uuidString)"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateEncryptionStatus(for: peerID)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3875,6 +3948,36 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - QR Verification API
|
||||||
|
@MainActor
|
||||||
|
func beginQRVerification(with qr: VerificationService.VerificationQR) -> Bool {
|
||||||
|
// Find a matching peer by Noise key
|
||||||
|
let targetNoise = qr.noiseKeyHex.lowercased()
|
||||||
|
guard let peer = unifiedPeerService.peers.first(where: { $0.noisePublicKey.hexEncodedString().lowercased() == targetNoise }) else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let peerID = peer.id
|
||||||
|
// If we already have a pending verification with this peer, don't send another
|
||||||
|
if pendingQRVerifications[peerID] != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Generate nonceA
|
||||||
|
var nonce = Data(count: 16)
|
||||||
|
_ = nonce.withUnsafeMutableBytes { SecRandomCopyBytes(kSecRandomDefault, 16, $0.baseAddress!) }
|
||||||
|
var pending = PendingVerification(noiseKeyHex: qr.noiseKeyHex, signKeyHex: qr.signKeyHex, nonceA: nonce, startedAt: Date(), sent: false)
|
||||||
|
pendingQRVerifications[peerID] = pending
|
||||||
|
// If Noise session is established, send immediately; otherwise trigger handshake and send on auth
|
||||||
|
let noise = meshService.getNoiseService()
|
||||||
|
if noise.hasEstablishedSession(with: peerID) {
|
||||||
|
meshService.sendVerifyChallenge(to: peerID, noiseKeyHex: qr.noiseKeyHex, nonceA: nonce)
|
||||||
|
pending.sent = true
|
||||||
|
pendingQRVerifications[peerID] = pending
|
||||||
|
} else {
|
||||||
|
meshService.triggerHandshake(with: peerID)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Mention parsing moved from BLE – use the existing non-optional helper below
|
// Mention parsing moved from BLE – use the existing non-optional helper below
|
||||||
// MARK: - Peer Connection Events
|
// MARK: - Peer Connection Events
|
||||||
|
|
||||||
@@ -3913,7 +4016,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
messageRouter.flushOutbox(for: peerID)
|
messageRouter.flushOutbox(for: peerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connection messages removed to reduce chat noise
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
func didDisconnectFromPeer(_ peerID: String) {
|
func didDisconnectFromPeer(_ peerID: String) {
|
||||||
@@ -3980,7 +4083,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disconnection messages removed to reduce chat noise
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
func didUpdatePeerList(_ peers: [String]) {
|
func didUpdatePeerList(_ peers: [String]) {
|
||||||
@@ -4264,7 +4367,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Used for emotes where we want a local system-style confirmation instead.
|
// Used for emotes where we want a local system-style confirmation instead.
|
||||||
@MainActor
|
@MainActor
|
||||||
func sendPublicRaw(_ content: String) {
|
func sendPublicRaw(_ content: String) {
|
||||||
#if os(iOS)
|
|
||||||
if case .location(let ch) = activeChannel {
|
if case .location(let ch) = activeChannel {
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
do {
|
do {
|
||||||
@@ -4276,21 +4378,25 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
nickname: self.nickname,
|
nickname: self.nickname,
|
||||||
teleported: LocationChannelManager.shared.teleported
|
teleported: LocationChannelManager.shared.teleported
|
||||||
)
|
)
|
||||||
NostrRelayManager.shared.sendEvent(event)
|
let targetRelays = GeoRelayDirectory.shared.closestRelays(toGeohash: ch.geohash, count: 5)
|
||||||
|
if targetRelays.isEmpty {
|
||||||
|
NostrRelayManager.shared.sendEvent(event)
|
||||||
|
} else {
|
||||||
|
NostrRelayManager.shared.sendEvent(event, to: targetRelays)
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
SecureLogger.log("❌ Failed to send geohash raw message: \(error)", category: SecureLogger.session, level: .error)
|
SecureLogger.log("❌ Failed to send geohash raw message: \(error)", category: SecureLogger.session, level: .error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
// Default: send over mesh
|
// Default: send over mesh
|
||||||
meshService.sendMessage(content, mentions: [])
|
meshService.sendMessage(content, mentions: [])
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Simplified Nostr Integration (Inlined from MessageRouter)
|
// MARK: - Simplified Nostr Integration (Inlined from MessageRouter)
|
||||||
|
|
||||||
// Removed inlined Nostr send helpers in favor of MessageRouter
|
//
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func setupNostrMessageHandling() {
|
private func setupNostrMessageHandling() {
|
||||||
@@ -4459,10 +4565,18 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
privateChatManager.sanitizeChat(for: ephemeralPeerID)
|
privateChatManager.sanitizeChat(for: ephemeralPeerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send delivery ack via Nostr embedded if not previously read and we know sender's Noise key
|
// Send delivery ack via Nostr embedded
|
||||||
if !wasReadBefore, let key = actualSenderNoiseKey {
|
if !wasReadBefore {
|
||||||
SecureLogger.log("Sending DELIVERED ack for \(messageId.prefix(8))… via router", category: SecureLogger.session, level: .debug)
|
if let key = actualSenderNoiseKey {
|
||||||
messageRouter.sendDeliveryAck(messageId, to: key.hexEncodedString())
|
SecureLogger.log("Sending DELIVERED ack for \(messageId.prefix(8))… via router", category: SecureLogger.session, level: .debug)
|
||||||
|
messageRouter.sendDeliveryAck(messageId, to: key.hexEncodedString())
|
||||||
|
} else if let id = try? NostrIdentityBridge.getCurrentNostrIdentity() {
|
||||||
|
// Fallback: no Noise mapping yet — send directly to sender's Nostr pubkey
|
||||||
|
let nt = NostrTransport()
|
||||||
|
nt.senderPeerID = meshService.myPeerID
|
||||||
|
nt.sendDeliveryAckGeohash(for: messageId, toRecipientHex: senderPubkey, from: id)
|
||||||
|
SecureLogger.log("Sent DELIVERED ack directly to Nostr pub=\(senderPubkey.prefix(8))… for mid=\(messageId.prefix(8))…", category: SecureLogger.session, level: .debug)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if wasReadBefore {
|
if wasReadBefore {
|
||||||
@@ -4473,11 +4587,19 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
let ephemeralPeerID = unifiedPeerService.peers.first(where: { $0.noisePublicKey == key })?.id {
|
let ephemeralPeerID = unifiedPeerService.peers.first(where: { $0.noisePublicKey == key })?.id {
|
||||||
unreadPrivateMessages.remove(ephemeralPeerID)
|
unreadPrivateMessages.remove(ephemeralPeerID)
|
||||||
}
|
}
|
||||||
if !sentReadReceipts.contains(messageId), let key = actualSenderNoiseKey {
|
if !sentReadReceipts.contains(messageId) {
|
||||||
let receipt = ReadReceipt(originalMessageID: messageId, readerID: meshService.myPeerID, readerNickname: nickname)
|
if let key = actualSenderNoiseKey {
|
||||||
SecureLogger.log("Viewing chat; sending READ ack for \(messageId.prefix(8))… via router", category: SecureLogger.session, level: .debug)
|
let receipt = ReadReceipt(originalMessageID: messageId, readerID: meshService.myPeerID, readerNickname: nickname)
|
||||||
messageRouter.sendReadReceipt(receipt, to: key.hexEncodedString())
|
SecureLogger.log("Viewing chat; sending READ ack for \(messageId.prefix(8))… via router", category: SecureLogger.session, level: .debug)
|
||||||
sentReadReceipts.insert(messageId)
|
messageRouter.sendReadReceipt(receipt, to: key.hexEncodedString())
|
||||||
|
sentReadReceipts.insert(messageId)
|
||||||
|
} else if let id = try? NostrIdentityBridge.getCurrentNostrIdentity() {
|
||||||
|
let nt = NostrTransport()
|
||||||
|
nt.senderPeerID = meshService.myPeerID
|
||||||
|
nt.sendReadReceiptGeohash(messageId, toRecipientHex: senderPubkey, from: id)
|
||||||
|
sentReadReceipts.insert(messageId)
|
||||||
|
SecureLogger.log("Viewing chat; sent READ ack directly to Nostr pub=\(senderPubkey.prefix(8))… for mid=\(messageId.prefix(8))…", category: SecureLogger.session, level: .debug)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if shouldMarkAsUnread {
|
if shouldMarkAsUnread {
|
||||||
@@ -4515,6 +4637,9 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
privateChats[targetPeerID]?[idx].deliveryStatus = .read(by: peerName, at: Date())
|
privateChats[targetPeerID]?[idx].deliveryStatus = .read(by: peerName, at: Date())
|
||||||
objectWillChange.send()
|
objectWillChange.send()
|
||||||
}
|
}
|
||||||
|
case .verifyChallenge, .verifyResponse:
|
||||||
|
// Ignore verification payloads arriving via Nostr path for now
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
@@ -4602,7 +4727,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
return Data(base64Encoded: str)
|
return Data(base64Encoded: str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removed local TLV decoder; using PrivateMessagePacket.decode from Protocols
|
//
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func handleFavoriteNotificationFromMesh(_ content: String, from peerID: String, senderNickname: String) {
|
private func handleFavoriteNotificationFromMesh(_ content: String, from peerID: String, senderNickname: String) {
|
||||||
@@ -5172,8 +5297,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
trimMeshTimelineIfNeeded()
|
trimMeshTimelineIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Persist geochat messages to per-geohash timeline (iOS-only)
|
// Persist geochat messages to per-geohash timeline
|
||||||
#if os(iOS)
|
|
||||||
if isGeo && finalMessage.sender != "system" {
|
if isGeo && finalMessage.sender != "system" {
|
||||||
if let gh = currentGeohash {
|
if let gh = currentGeohash {
|
||||||
var arr = geoTimelines[gh] ?? []
|
var arr = geoTimelines[gh] ?? []
|
||||||
@@ -5182,20 +5306,14 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
geoTimelines[gh] = arr
|
geoTimelines[gh] = arr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Only add message to current timeline if it matches active channel or is system
|
// Only add message to current timeline if it matches active channel or is system
|
||||||
let isSystem = finalMessage.sender == "system"
|
let isSystem = finalMessage.sender == "system"
|
||||||
let channelMatches: Bool = {
|
let channelMatches: Bool = {
|
||||||
#if os(iOS)
|
|
||||||
switch activeChannel {
|
switch activeChannel {
|
||||||
case .mesh: return !isGeo || isSystem
|
case .mesh: return !isGeo || isSystem
|
||||||
case .location: return isGeo || isSystem
|
case .location: return isGeo || isSystem
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
// On non-iOS builds, we don't have location channels; accept all
|
|
||||||
return true
|
|
||||||
#endif
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
guard channelMatches else { return }
|
guard channelMatches else { return }
|
||||||
|
|||||||
+76
-157
@@ -13,19 +13,9 @@ import UIKit
|
|||||||
|
|
||||||
// MARK: - Supporting Types
|
// MARK: - Supporting Types
|
||||||
|
|
||||||
// Pre-computed peer data for performance
|
//
|
||||||
struct PeerDisplayData: Identifiable {
|
|
||||||
let id: String
|
|
||||||
let displayName: String
|
|
||||||
let isFavorite: Bool
|
|
||||||
let isMe: Bool
|
|
||||||
let hasUnreadMessages: Bool
|
|
||||||
let encryptionStatus: EncryptionStatus
|
|
||||||
let connectionState: BitchatPeer.ConnectionState
|
|
||||||
let isMutualFavorite: Bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// (Link previews removed; URLs are now clickable inline)
|
//
|
||||||
|
|
||||||
// MARK: - Main Content View
|
// MARK: - Main Content View
|
||||||
|
|
||||||
@@ -33,9 +23,7 @@ struct ContentView: View {
|
|||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|
||||||
@EnvironmentObject var viewModel: ChatViewModel
|
@EnvironmentObject var viewModel: ChatViewModel
|
||||||
#if os(iOS)
|
|
||||||
@ObservedObject private var locationManager = LocationChannelManager.shared
|
@ObservedObject private var locationManager = LocationChannelManager.shared
|
||||||
#endif
|
|
||||||
@State private var messageText = ""
|
@State private var messageText = ""
|
||||||
@State private var textFieldSelection: NSRange? = nil
|
@State private var textFieldSelection: NSRange? = nil
|
||||||
@FocusState private var isTextFieldFocused: Bool
|
@FocusState private var isTextFieldFocused: Bool
|
||||||
@@ -58,6 +46,7 @@ struct ContentView: View {
|
|||||||
@State private var scrollThrottleTimer: Timer?
|
@State private var scrollThrottleTimer: Timer?
|
||||||
@State private var autocompleteDebounceTimer: Timer?
|
@State private var autocompleteDebounceTimer: Timer?
|
||||||
@State private var showLocationChannelsSheet = false
|
@State private var showLocationChannelsSheet = false
|
||||||
|
@State private var showVerifySheet = false
|
||||||
@State private var expandedMessageIDs: Set<String> = []
|
@State private var expandedMessageIDs: Set<String> = []
|
||||||
// Window sizes for rendering (infinite scroll up)
|
// Window sizes for rendering (infinite scroll up)
|
||||||
@State private var windowCountPublic: Int = 300
|
@State private var windowCountPublic: Int = 300
|
||||||
@@ -199,7 +188,6 @@ struct ContentView: View {
|
|||||||
|
|
||||||
Button("direct message") {
|
Button("direct message") {
|
||||||
if let peerID = selectedMessageSenderID {
|
if let peerID = selectedMessageSenderID {
|
||||||
#if os(iOS)
|
|
||||||
if peerID.hasPrefix("nostr:") {
|
if peerID.hasPrefix("nostr:") {
|
||||||
if let full = viewModel.fullNostrHex(forSenderPeerID: peerID) {
|
if let full = viewModel.fullNostrHex(forSenderPeerID: peerID) {
|
||||||
viewModel.startGeohashDM(withPubkeyHex: full)
|
viewModel.startGeohashDM(withPubkeyHex: full)
|
||||||
@@ -207,9 +195,6 @@ struct ContentView: View {
|
|||||||
} else {
|
} else {
|
||||||
viewModel.startPrivateChat(with: peerID)
|
viewModel.startPrivateChat(with: peerID)
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
viewModel.startPrivateChat(with: peerID)
|
|
||||||
#endif
|
|
||||||
withAnimation(.easeInOut(duration: 0.2)) {
|
withAnimation(.easeInOut(duration: 0.2)) {
|
||||||
showSidebar = false
|
showSidebar = false
|
||||||
sidebarDragOffset = 0
|
sidebarDragOffset = 0
|
||||||
@@ -231,7 +216,6 @@ struct ContentView: View {
|
|||||||
|
|
||||||
Button("BLOCK", role: .destructive) {
|
Button("BLOCK", role: .destructive) {
|
||||||
// Prefer direct geohash block when we have a Nostr sender ID
|
// Prefer direct geohash block when we have a Nostr sender ID
|
||||||
#if os(iOS)
|
|
||||||
if let peerID = selectedMessageSenderID, peerID.hasPrefix("nostr:"),
|
if let peerID = selectedMessageSenderID, peerID.hasPrefix("nostr:"),
|
||||||
let full = viewModel.fullNostrHex(forSenderPeerID: peerID),
|
let full = viewModel.fullNostrHex(forSenderPeerID: peerID),
|
||||||
let sender = selectedMessageSender {
|
let sender = selectedMessageSender {
|
||||||
@@ -239,9 +223,6 @@ struct ContentView: View {
|
|||||||
} else if let sender = selectedMessageSender {
|
} else if let sender = selectedMessageSender {
|
||||||
viewModel.sendMessage("/block \(sender)")
|
viewModel.sendMessage("/block \(sender)")
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if let sender = selectedMessageSender { viewModel.sendMessage("/block \(sender)") }
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Button("cancel", role: .cancel) {}
|
Button("cancel", role: .cancel) {}
|
||||||
@@ -289,16 +270,13 @@ struct ContentView: View {
|
|||||||
let windowedMessages = messages.suffix(currentWindowCount)
|
let windowedMessages = messages.suffix(currentWindowCount)
|
||||||
|
|
||||||
// Build stable UI IDs with a context key to avoid ID collisions when switching channels
|
// Build stable UI IDs with a context key to avoid ID collisions when switching channels
|
||||||
#if os(iOS)
|
|
||||||
let contextKey: String = {
|
let contextKey: String = {
|
||||||
|
if let peer = privatePeer { return "dm:\(peer)" }
|
||||||
switch locationManager.selectedChannel {
|
switch locationManager.selectedChannel {
|
||||||
case .mesh: return "mesh"
|
case .mesh: return "mesh"
|
||||||
case .location(let ch): return "geo:\(ch.geohash)"
|
case .location(let ch): return "geo:\(ch.geohash)"
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
#else
|
|
||||||
let contextKey: String = "mesh"
|
|
||||||
#endif
|
|
||||||
let items = windowedMessages.map { (uiID: "\(contextKey)|\($0.id)", message: $0) }
|
let items = windowedMessages.map { (uiID: "\(contextKey)|\($0.id)", message: $0) }
|
||||||
|
|
||||||
ForEach(items, id: \.uiID) { item in
|
ForEach(items, id: \.uiID) { item in
|
||||||
@@ -394,16 +372,13 @@ struct ContentView: View {
|
|||||||
// Infinite scroll up: when top row appears, increase window and preserve anchor
|
// Infinite scroll up: when top row appears, increase window and preserve anchor
|
||||||
if message.id == windowedMessages.first?.id, messages.count > windowedMessages.count {
|
if message.id == windowedMessages.first?.id, messages.count > windowedMessages.count {
|
||||||
let step = 200
|
let step = 200
|
||||||
#if os(iOS)
|
|
||||||
let contextKey: String = {
|
let contextKey: String = {
|
||||||
|
if let peer = privatePeer { return "dm:\(peer)" }
|
||||||
switch locationManager.selectedChannel {
|
switch locationManager.selectedChannel {
|
||||||
case .mesh: return "mesh"
|
case .mesh: return "mesh"
|
||||||
case .location(let ch): return "geo:\(ch.geohash)"
|
case .location(let ch): return "geo:\(ch.geohash)"
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
#else
|
|
||||||
let contextKey: String = "mesh"
|
|
||||||
#endif
|
|
||||||
let preserveID = "\(contextKey)|\(message.id)"
|
let preserveID = "\(contextKey)|\(message.id)"
|
||||||
if let peer = privatePeer {
|
if let peer = privatePeer {
|
||||||
let current = windowCountPrivate[peer] ?? 300
|
let current = windowCountPrivate[peer] ?? 300
|
||||||
@@ -472,7 +447,6 @@ struct ContentView: View {
|
|||||||
let gh = url.path.trimmingCharacters(in: CharacterSet(charactersIn: "/")).lowercased()
|
let gh = url.path.trimmingCharacters(in: CharacterSet(charactersIn: "/")).lowercased()
|
||||||
let allowed = Set("0123456789bcdefghjkmnpqrstuvwxyz")
|
let allowed = Set("0123456789bcdefghjkmnpqrstuvwxyz")
|
||||||
guard (2...12).contains(gh.count), gh.allSatisfy({ allowed.contains($0) }) else { return }
|
guard (2...12).contains(gh.count), gh.allSatisfy({ allowed.contains($0) }) else { return }
|
||||||
#if os(iOS)
|
|
||||||
func levelForLength(_ len: Int) -> GeohashChannelLevel {
|
func levelForLength(_ len: Int) -> GeohashChannelLevel {
|
||||||
switch len {
|
switch len {
|
||||||
case 0...2: return .region
|
case 0...2: return .region
|
||||||
@@ -487,7 +461,6 @@ struct ContentView: View {
|
|||||||
let ch = GeohashChannel(level: level, geohash: gh)
|
let ch = GeohashChannel(level: level, geohash: gh)
|
||||||
LocationChannelManager.shared.markTeleported(for: gh, true)
|
LocationChannelManager.shared.markTeleported(for: gh, true)
|
||||||
LocationChannelManager.shared.select(ChannelID.location(ch))
|
LocationChannelManager.shared.select(ChannelID.location(ch))
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
.onTapGesture(count: 3) {
|
.onTapGesture(count: 3) {
|
||||||
// Triple-tap to clear current chat
|
// Triple-tap to clear current chat
|
||||||
@@ -500,16 +473,12 @@ struct ContentView: View {
|
|||||||
let last = viewModel.getPrivateChatMessages(for: peer).suffix(300).last?.id {
|
let last = viewModel.getPrivateChatMessages(for: peer).suffix(300).last?.id {
|
||||||
return "dm:\(peer)|\(last)"
|
return "dm:\(peer)|\(last)"
|
||||||
}
|
}
|
||||||
#if os(iOS)
|
|
||||||
let contextKey: String = {
|
let contextKey: String = {
|
||||||
switch locationManager.selectedChannel {
|
switch locationManager.selectedChannel {
|
||||||
case .mesh: return "mesh"
|
case .mesh: return "mesh"
|
||||||
case .location(let ch): return "geo:\(ch.geohash)"
|
case .location(let ch): return "geo:\(ch.geohash)"
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
#else
|
|
||||||
let contextKey: String = "mesh"
|
|
||||||
#endif
|
|
||||||
if let last = viewModel.messages.suffix(300).last?.id { return "\(contextKey)|\(last)" }
|
if let last = viewModel.messages.suffix(300).last?.id { return "\(contextKey)|\(last)" }
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
@@ -524,16 +493,12 @@ struct ContentView: View {
|
|||||||
let last = viewModel.getPrivateChatMessages(for: peer).suffix(300).last?.id {
|
let last = viewModel.getPrivateChatMessages(for: peer).suffix(300).last?.id {
|
||||||
return "dm:\(peer)|\(last)"
|
return "dm:\(peer)|\(last)"
|
||||||
}
|
}
|
||||||
#if os(iOS)
|
|
||||||
let contextKey: String = {
|
let contextKey: String = {
|
||||||
switch locationManager.selectedChannel {
|
switch locationManager.selectedChannel {
|
||||||
case .mesh: return "mesh"
|
case .mesh: return "mesh"
|
||||||
case .location(let ch): return "geo:\(ch.geohash)"
|
case .location(let ch): return "geo:\(ch.geohash)"
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
#else
|
|
||||||
let contextKey: String = "mesh"
|
|
||||||
#endif
|
|
||||||
if let last = viewModel.messages.suffix(300).last?.id { return "\(contextKey)|\(last)" }
|
if let last = viewModel.messages.suffix(300).last?.id { return "\(contextKey)|\(last)" }
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
@@ -547,16 +512,12 @@ struct ContentView: View {
|
|||||||
let last = viewModel.getPrivateChatMessages(for: peer).suffix(300).last?.id {
|
let last = viewModel.getPrivateChatMessages(for: peer).suffix(300).last?.id {
|
||||||
return "dm:\(peer)|\(last)"
|
return "dm:\(peer)|\(last)"
|
||||||
}
|
}
|
||||||
#if os(iOS)
|
|
||||||
let contextKey: String = {
|
let contextKey: String = {
|
||||||
switch locationManager.selectedChannel {
|
switch locationManager.selectedChannel {
|
||||||
case .mesh: return "mesh"
|
case .mesh: return "mesh"
|
||||||
case .location(let ch): return "geo:\(ch.geohash)"
|
case .location(let ch): return "geo:\(ch.geohash)"
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
#else
|
|
||||||
let contextKey: String = "mesh"
|
|
||||||
#endif
|
|
||||||
if let last = viewModel.messages.suffix(300).last?.id { return "\(contextKey)|\(last)" }
|
if let last = viewModel.messages.suffix(300).last?.id { return "\(contextKey)|\(last)" }
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
@@ -582,16 +543,12 @@ struct ContentView: View {
|
|||||||
if now.timeIntervalSince(lastScrollTime) > 0.5 {
|
if now.timeIntervalSince(lastScrollTime) > 0.5 {
|
||||||
// Immediate scroll if enough time has passed
|
// Immediate scroll if enough time has passed
|
||||||
lastScrollTime = now
|
lastScrollTime = now
|
||||||
#if os(iOS)
|
|
||||||
let contextKey: String = {
|
let contextKey: String = {
|
||||||
switch locationManager.selectedChannel {
|
switch locationManager.selectedChannel {
|
||||||
case .mesh: return "mesh"
|
case .mesh: return "mesh"
|
||||||
case .location(let ch): return "geo:\(ch.geohash)"
|
case .location(let ch): return "geo:\(ch.geohash)"
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
#else
|
|
||||||
let contextKey: String = "mesh"
|
|
||||||
#endif
|
|
||||||
let count = windowCountPublic
|
let count = windowCountPublic
|
||||||
let target = viewModel.messages.suffix(count).last.map { "\(contextKey)|\($0.id)" }
|
let target = viewModel.messages.suffix(count).last.map { "\(contextKey)|\($0.id)" }
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
@@ -602,16 +559,12 @@ struct ContentView: View {
|
|||||||
scrollThrottleTimer?.invalidate()
|
scrollThrottleTimer?.invalidate()
|
||||||
scrollThrottleTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false) { _ in
|
scrollThrottleTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false) { _ in
|
||||||
lastScrollTime = Date()
|
lastScrollTime = Date()
|
||||||
#if os(iOS)
|
let contextKey: String = {
|
||||||
let contextKey: String = {
|
switch locationManager.selectedChannel {
|
||||||
switch locationManager.selectedChannel {
|
case .mesh: return "mesh"
|
||||||
case .mesh: return "mesh"
|
case .location(let ch): return "geo:\(ch.geohash)"
|
||||||
case .location(let ch): return "geo:\(ch.geohash)"
|
}
|
||||||
}
|
}()
|
||||||
}()
|
|
||||||
#else
|
|
||||||
let contextKey: String = "mesh"
|
|
||||||
#endif
|
|
||||||
let count = windowCountPublic
|
let count = windowCountPublic
|
||||||
let target = viewModel.messages.suffix(count).last.map { "\(contextKey)|\($0.id)" }
|
let target = viewModel.messages.suffix(count).last.map { "\(contextKey)|\($0.id)" }
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
@@ -658,7 +611,6 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if os(iOS)
|
|
||||||
.onChange(of: locationManager.selectedChannel) { newChannel in
|
.onChange(of: locationManager.selectedChannel) { newChannel in
|
||||||
// When switching to a new geohash channel, scroll to the bottom
|
// When switching to a new geohash channel, scroll to the bottom
|
||||||
guard privatePeer == nil else { return }
|
guard privatePeer == nil else { return }
|
||||||
@@ -677,7 +629,6 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
.onAppear {
|
.onAppear {
|
||||||
// Also check when view appears
|
// Also check when view appears
|
||||||
if let peerID = privatePeer {
|
if let peerID = privatePeer {
|
||||||
@@ -747,18 +698,22 @@ struct ContentView: View {
|
|||||||
if showCommandSuggestions && !commandSuggestions.isEmpty {
|
if showCommandSuggestions && !commandSuggestions.isEmpty {
|
||||||
VStack(alignment: .leading, spacing: 0) {
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
// Define commands with aliases and syntax
|
// Define commands with aliases and syntax
|
||||||
let commandInfo: [(commands: [String], syntax: String?, description: String)] = [
|
let baseInfo: [(commands: [String], syntax: String?, description: String)] = [
|
||||||
(["/block"], "[nickname]", "block or list blocked peers"),
|
(["/block"], "[nickname]", "block or list blocked peers"),
|
||||||
(["/clear"], nil, "clear chat messages"),
|
(["/clear"], nil, "clear chat messages"),
|
||||||
(["/fav"], "<nickname>", "add to favorites"),
|
|
||||||
(["/help"], nil, "show this help"),
|
|
||||||
(["/hug"], "<nickname>", "send someone a warm hug"),
|
(["/hug"], "<nickname>", "send someone a warm hug"),
|
||||||
(["/m", "/msg"], "<nickname> [message]", "send private message"),
|
(["/m", "/msg"], "<nickname> [message]", "send private message"),
|
||||||
(["/slap"], "<nickname>", "slap someone with a trout"),
|
(["/slap"], "<nickname>", "slap someone with a trout"),
|
||||||
(["/unblock"], "<nickname>", "unblock a peer"),
|
(["/unblock"], "<nickname>", "unblock a peer"),
|
||||||
(["/unfav"], "<nickname>", "remove from favorites"),
|
|
||||||
(["/w"], nil, "see who's online")
|
(["/w"], nil, "see who's online")
|
||||||
]
|
]
|
||||||
|
let isGeoPublic: Bool = { if case .location = locationManager.selectedChannel { return true }; return false }()
|
||||||
|
let isGeoDM: Bool = (viewModel.selectedPrivateChatPeer?.hasPrefix("nostr_") == true)
|
||||||
|
let favInfo: [(commands: [String], syntax: String?, description: String)] = [
|
||||||
|
(["/fav"], "<nickname>", "add to favorites"),
|
||||||
|
(["/unfav"], "<nickname>", "remove from favorites")
|
||||||
|
]
|
||||||
|
let commandInfo = baseInfo + ((isGeoPublic || isGeoDM) ? [] : favInfo)
|
||||||
|
|
||||||
// Build the display
|
// Build the display
|
||||||
let allCommands = commandInfo
|
let allCommands = commandInfo
|
||||||
@@ -833,18 +788,25 @@ struct ContentView: View {
|
|||||||
// Check for command autocomplete (instant, no debounce needed)
|
// Check for command autocomplete (instant, no debounce needed)
|
||||||
if newValue.hasPrefix("/") && newValue.count >= 1 {
|
if newValue.hasPrefix("/") && newValue.count >= 1 {
|
||||||
// Build context-aware command list
|
// Build context-aware command list
|
||||||
let commandDescriptions = [
|
let isGeoPublic: Bool = {
|
||||||
|
if case .location = locationManager.selectedChannel { return true }
|
||||||
|
return false
|
||||||
|
}()
|
||||||
|
let isGeoDM: Bool = (viewModel.selectedPrivateChatPeer?.hasPrefix("nostr_") == true)
|
||||||
|
var commandDescriptions = [
|
||||||
("/block", "block or list blocked peers"),
|
("/block", "block or list blocked peers"),
|
||||||
("/clear", "clear chat messages"),
|
("/clear", "clear chat messages"),
|
||||||
("/fav", "add to favorites"),
|
|
||||||
("/help", "show this help"),
|
|
||||||
("/hug", "send someone a warm hug"),
|
("/hug", "send someone a warm hug"),
|
||||||
("/m", "send private message"),
|
("/m", "send private message"),
|
||||||
("/slap", "slap someone with a trout"),
|
("/slap", "slap someone with a trout"),
|
||||||
("/unblock", "unblock a peer"),
|
("/unblock", "unblock a peer"),
|
||||||
("/unfav", "remove from favorites"),
|
|
||||||
("/w", "see who's online")
|
("/w", "see who's online")
|
||||||
]
|
]
|
||||||
|
// Only show favorites commands when not in geohash context
|
||||||
|
if !(isGeoPublic || isGeoDM) {
|
||||||
|
commandDescriptions.append(("/fav", "add to favorites"))
|
||||||
|
commandDescriptions.append(("/unfav", "remove from favorites"))
|
||||||
|
}
|
||||||
|
|
||||||
let input = newValue.lowercased()
|
let input = newValue.lowercased()
|
||||||
|
|
||||||
@@ -926,6 +888,15 @@ struct ContentView: View {
|
|||||||
.font(.system(size: 16, weight: .bold, design: .monospaced))
|
.font(.system(size: 16, weight: .bold, design: .monospaced))
|
||||||
.foregroundColor(textColor)
|
.foregroundColor(textColor)
|
||||||
Spacer()
|
Spacer()
|
||||||
|
// Show QR in mesh on all platforms
|
||||||
|
if case .mesh = locationManager.selectedChannel {
|
||||||
|
Button(action: { showVerifySheet = true }) {
|
||||||
|
Image(systemName: "qrcode")
|
||||||
|
.font(.system(size: 14))
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.help("Verification: show my QR or scan a friend")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.frame(height: 44) // Match header height
|
.frame(height: 44) // Match header height
|
||||||
.padding(.horizontal, 12)
|
.padding(.horizontal, 12)
|
||||||
@@ -938,53 +909,34 @@ struct ContentView: View {
|
|||||||
VStack(alignment: .leading, spacing: 6) {
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
// People section
|
// People section
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
#if os(iOS)
|
if case .location = locationManager.selectedChannel {
|
||||||
if case .location = locationManager.selectedChannel {
|
GeohashPeopleList(viewModel: viewModel,
|
||||||
GeohashPeopleList(viewModel: viewModel,
|
textColor: textColor,
|
||||||
textColor: textColor,
|
secondaryTextColor: secondaryTextColor,
|
||||||
secondaryTextColor: secondaryTextColor,
|
onTapPerson: {
|
||||||
onTapPerson: {
|
withAnimation(.easeInOut(duration: 0.2)) {
|
||||||
withAnimation(.easeInOut(duration: 0.2)) {
|
showSidebar = false
|
||||||
showSidebar = false
|
sidebarDragOffset = 0
|
||||||
sidebarDragOffset = 0
|
}
|
||||||
}
|
})
|
||||||
})
|
} else {
|
||||||
} else {
|
MeshPeerList(viewModel: viewModel,
|
||||||
MeshPeerList(viewModel: viewModel,
|
textColor: textColor,
|
||||||
textColor: textColor,
|
secondaryTextColor: secondaryTextColor,
|
||||||
secondaryTextColor: secondaryTextColor,
|
onTapPeer: { peerID in
|
||||||
onTapPeer: { peerID in
|
viewModel.startPrivateChat(with: peerID)
|
||||||
viewModel.startPrivateChat(with: peerID)
|
withAnimation(.easeInOut(duration: 0.2)) {
|
||||||
withAnimation(.easeInOut(duration: 0.2)) {
|
showSidebar = false
|
||||||
showSidebar = false
|
sidebarDragOffset = 0
|
||||||
sidebarDragOffset = 0
|
}
|
||||||
}
|
},
|
||||||
},
|
onToggleFavorite: { peerID in
|
||||||
onToggleFavorite: { peerID in
|
viewModel.toggleFavorite(peerID: peerID)
|
||||||
viewModel.toggleFavorite(peerID: peerID)
|
},
|
||||||
},
|
onShowFingerprint: { peerID in
|
||||||
onShowFingerprint: { peerID in
|
viewModel.showFingerprint(for: peerID)
|
||||||
viewModel.showFingerprint(for: peerID)
|
})
|
||||||
})
|
}
|
||||||
}
|
|
||||||
#else
|
|
||||||
MeshPeerList(viewModel: viewModel,
|
|
||||||
textColor: textColor,
|
|
||||||
secondaryTextColor: secondaryTextColor,
|
|
||||||
onTapPeer: { peerID in
|
|
||||||
viewModel.startPrivateChat(with: peerID)
|
|
||||||
withAnimation(.easeInOut(duration: 0.2)) {
|
|
||||||
showSidebar = false
|
|
||||||
sidebarDragOffset = 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onToggleFavorite: { peerID in
|
|
||||||
viewModel.toggleFavorite(peerID: peerID)
|
|
||||||
},
|
|
||||||
onShowFingerprint: { peerID in
|
|
||||||
viewModel.showFingerprint(for: peerID)
|
|
||||||
})
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.id(viewModel.allPeers.map { "\($0.id)-\($0.isConnected)" }.joined())
|
.id(viewModel.allPeers.map { "\($0.id)-\($0.isConnected)" }.joined())
|
||||||
@@ -1074,13 +1026,11 @@ struct ContentView: View {
|
|||||||
return (name, "")
|
return (name, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
// Compute channel-aware people count and color for toolbar (cross-platform)
|
||||||
// Compute channel-aware people count and color for toolbar
|
|
||||||
private func channelPeopleCountAndColor() -> (Int, Color) {
|
private func channelPeopleCountAndColor() -> (Int, Color) {
|
||||||
switch locationManager.selectedChannel {
|
switch locationManager.selectedChannel {
|
||||||
case .location:
|
case .location:
|
||||||
let n = viewModel.geohashPeople.count
|
let n = viewModel.geohashPeople.count
|
||||||
// Use standard green (dark: system green; light: custom darker green)
|
|
||||||
let standardGreen = (colorScheme == .dark) ? Color.green : Color(red: 0, green: 0.5, blue: 0)
|
let standardGreen = (colorScheme == .dark) ? Color.green : Color(red: 0, green: 0.5, blue: 0)
|
||||||
return (n, n > 0 ? standardGreen : Color.secondary)
|
return (n, n > 0 ? standardGreen : Color.secondary)
|
||||||
case .mesh:
|
case .mesh:
|
||||||
@@ -1090,13 +1040,11 @@ struct ContentView: View {
|
|||||||
if isMeshConnected { counts.mesh += 1; counts.others += 1 }
|
if isMeshConnected { counts.mesh += 1; counts.others += 1 }
|
||||||
else if peer.isMutualFavorite { counts.others += 1 }
|
else if peer.isMutualFavorite { counts.others += 1 }
|
||||||
}
|
}
|
||||||
// Darker, more neutral blue (less purple hue)
|
|
||||||
let meshBlue = Color(hue: 0.60, saturation: 0.85, brightness: 0.82)
|
let meshBlue = Color(hue: 0.60, saturation: 0.85, brightness: 0.82)
|
||||||
let color: Color = counts.mesh > 0 ? meshBlue : Color.secondary
|
let color: Color = counts.mesh > 0 ? meshBlue : Color.secondary
|
||||||
return (counts.others, color)
|
return (counts.others, color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
private var mainHeaderView: some View {
|
private var mainHeaderView: some View {
|
||||||
@@ -1143,7 +1091,6 @@ struct ContentView: View {
|
|||||||
|
|
||||||
// Channel badge + dynamic spacing + people counter
|
// Channel badge + dynamic spacing + people counter
|
||||||
// Precompute header count and color outside the ViewBuilder expressions
|
// Precompute header count and color outside the ViewBuilder expressions
|
||||||
#if os(iOS)
|
|
||||||
let cc = channelPeopleCountAndColor()
|
let cc = channelPeopleCountAndColor()
|
||||||
let headerCountColor: Color = cc.1
|
let headerCountColor: Color = cc.1
|
||||||
let headerOtherPeersCount: Int = {
|
let headerOtherPeersCount: Int = {
|
||||||
@@ -1152,24 +1099,11 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
return cc.0
|
return cc.0
|
||||||
}()
|
}()
|
||||||
#else
|
|
||||||
let peerCounts = viewModel.allPeers.reduce(into: (others: 0, mesh: 0)) { counts, peer in
|
|
||||||
guard peer.id != viewModel.meshService.myPeerID else { return }
|
|
||||||
let isMeshConnected = peer.isConnected
|
|
||||||
if isMeshConnected { counts.mesh += 1; counts.others += 1 }
|
|
||||||
else if peer.isMutualFavorite { counts.others += 1 }
|
|
||||||
}
|
|
||||||
let headerOtherPeersCount = peerCounts.others
|
|
||||||
// Darker, more neutral blue (less purple hue)
|
|
||||||
let meshBlue = Color(hue: 0.60, saturation: 0.85, brightness: 0.82)
|
|
||||||
let headerCountColor: Color = (peerCounts.mesh > 0) ? meshBlue : Color.secondary
|
|
||||||
#endif
|
|
||||||
|
|
||||||
HStack(spacing: 10) {
|
HStack(spacing: 10) {
|
||||||
// Unread icon immediately to the left of the channel badge (independent from channel button)
|
// Unread icon immediately to the left of the channel badge (independent from channel button)
|
||||||
|
|
||||||
// Unread indicator
|
// Unread indicator (now shown on iOS and macOS)
|
||||||
#if os(iOS)
|
|
||||||
if viewModel.hasAnyUnreadMessages {
|
if viewModel.hasAnyUnreadMessages {
|
||||||
Button(action: { viewModel.openMostRelevantPrivateChat() }) {
|
Button(action: { viewModel.openMostRelevantPrivateChat() }) {
|
||||||
Image(systemName: "envelope.fill")
|
Image(systemName: "envelope.fill")
|
||||||
@@ -1204,7 +1138,6 @@ struct ContentView: View {
|
|||||||
.accessibilityLabel("location channels")
|
.accessibilityLabel("location channels")
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
#endif
|
|
||||||
|
|
||||||
HStack(spacing: 4) {
|
HStack(spacing: 4) {
|
||||||
// People icon with count
|
// People icon with count
|
||||||
@@ -1216,6 +1149,8 @@ struct ContentView: View {
|
|||||||
.accessibilityHidden(true)
|
.accessibilityHidden(true)
|
||||||
}
|
}
|
||||||
.foregroundColor(headerCountColor)
|
.foregroundColor(headerCountColor)
|
||||||
|
|
||||||
|
// QR moved to the PEOPLE header in the sidebar when on mesh channel
|
||||||
}
|
}
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
withAnimation(.easeInOut(duration: 0.2)) {
|
withAnimation(.easeInOut(duration: 0.2)) {
|
||||||
@@ -1223,14 +1158,16 @@ struct ContentView: View {
|
|||||||
sidebarDragOffset = 0
|
sidebarDragOffset = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.sheet(isPresented: $showVerifySheet) {
|
||||||
|
VerificationSheetView(isPresented: $showVerifySheet)
|
||||||
|
.environmentObject(viewModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.frame(height: 44)
|
.frame(height: 44)
|
||||||
.padding(.horizontal, 12)
|
.padding(.horizontal, 12)
|
||||||
#if os(iOS)
|
|
||||||
.sheet(isPresented: $showLocationChannelsSheet) {
|
.sheet(isPresented: $showLocationChannelsSheet) {
|
||||||
LocationChannelsSheet(isPresented: $showLocationChannelsSheet)
|
LocationChannelsSheet(isPresented: $showLocationChannelsSheet)
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
.background(backgroundColor.opacity(0.95))
|
.background(backgroundColor.opacity(0.95))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1266,13 +1203,11 @@ struct ContentView: View {
|
|||||||
let peer = viewModel.getPeer(byID: headerPeerID)
|
let peer = viewModel.getPeer(byID: headerPeerID)
|
||||||
let privatePeerNick: String = {
|
let privatePeerNick: String = {
|
||||||
if privatePeerID.hasPrefix("nostr_") {
|
if privatePeerID.hasPrefix("nostr_") {
|
||||||
#if os(iOS)
|
|
||||||
// Build geohash DM header: "#<ghash>/@name#abcd"
|
// Build geohash DM header: "#<ghash>/@name#abcd"
|
||||||
if case .location(let ch) = locationManager.selectedChannel {
|
if case .location(let ch) = locationManager.selectedChannel {
|
||||||
let disp = viewModel.geohashDisplayName(for: privatePeerID)
|
let disp = viewModel.geohashDisplayName(for: privatePeerID)
|
||||||
return "#\(ch.geohash)/@\(disp)"
|
return "#\(ch.geohash)/@\(disp)"
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return peer?.displayName ??
|
return peer?.displayName ??
|
||||||
viewModel.meshService.peerNickname(peerID: headerPeerID) ??
|
viewModel.meshService.peerNickname(peerID: headerPeerID) ??
|
||||||
@@ -1437,23 +1372,7 @@ private struct PaymentChipView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper view for rendering message content (plain, no hashtag/mention formatting)
|
//
|
||||||
struct MessageContentView: View {
|
|
||||||
let message: BitchatMessage
|
|
||||||
let viewModel: ChatViewModel
|
|
||||||
let colorScheme: ColorScheme
|
|
||||||
let isMentioned: Bool
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
Text(message.content)
|
|
||||||
.font(.system(size: 14, design: .monospaced))
|
|
||||||
.fontWeight(isMentioned ? .bold : .regular)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Helper Methods
|
|
||||||
|
|
||||||
// buildTextSegments removed: content is rendered plain.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delivery status indicator view
|
// Delivery status indicator view
|
||||||
struct DeliveryStatusView: View {
|
struct DeliveryStatusView: View {
|
||||||
|
|||||||
@@ -32,8 +32,9 @@ struct FingerprintView: View {
|
|||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
Button("DONE") {
|
Button(action: { dismiss() }) {
|
||||||
dismiss()
|
Image(systemName: "xmark")
|
||||||
|
.font(.system(size: 14, weight: .semibold))
|
||||||
}
|
}
|
||||||
.foregroundColor(textColor)
|
.foregroundColor(textColor)
|
||||||
}
|
}
|
||||||
@@ -165,6 +166,20 @@ struct FingerprintView: View {
|
|||||||
.cornerRadius(8)
|
.cornerRadius(8)
|
||||||
}
|
}
|
||||||
.buttonStyle(PlainButtonStyle())
|
.buttonStyle(PlainButtonStyle())
|
||||||
|
} else {
|
||||||
|
Button(action: {
|
||||||
|
viewModel.unverifyFingerprint(for: peerID)
|
||||||
|
dismiss()
|
||||||
|
}) {
|
||||||
|
Text("REMOVE VERIFICATION")
|
||||||
|
.font(.system(size: 14, weight: .bold, design: .monospaced))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.padding(.horizontal, 20)
|
||||||
|
.padding(.vertical, 10)
|
||||||
|
.background(Color.red)
|
||||||
|
.cornerRadius(8)
|
||||||
|
}
|
||||||
|
.buttonStyle(PlainButtonStyle())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.top)
|
.padding(.top)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
#if os(iOS)
|
|
||||||
struct GeohashPeopleList: View {
|
struct GeohashPeopleList: View {
|
||||||
@ObservedObject var viewModel: ChatViewModel
|
@ObservedObject var viewModel: ChatViewModel
|
||||||
let textColor: Color
|
let textColor: Color
|
||||||
@@ -29,16 +28,12 @@ struct GeohashPeopleList: View {
|
|||||||
let people = viewModel.visibleGeohashPeople()
|
let people = viewModel.visibleGeohashPeople()
|
||||||
let currentIDs = people.map { $0.id }
|
let currentIDs = people.map { $0.id }
|
||||||
|
|
||||||
#if os(iOS)
|
|
||||||
let teleportedSet = Set(viewModel.teleportedGeo.map { $0.lowercased() })
|
let teleportedSet = Set(viewModel.teleportedGeo.map { $0.lowercased() })
|
||||||
let isTeleportedID: (String) -> Bool = { id in
|
let isTeleportedID: (String) -> Bool = { id in
|
||||||
if teleportedSet.contains(id.lowercased()) { return true }
|
if teleportedSet.contains(id.lowercased()) { return true }
|
||||||
if let me = myHex, id == me, LocationChannelManager.shared.teleported { return true }
|
if let me = myHex, id == me, LocationChannelManager.shared.teleported { return true }
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
let isTeleportedID: (String) -> Bool = { _ in false }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
let displayIDs = orderedIDs.filter { currentIDs.contains($0) } + currentIDs.filter { !orderedIDs.contains($0) }
|
let displayIDs = orderedIDs.filter { currentIDs.contains($0) } + currentIDs.filter { !orderedIDs.contains($0) }
|
||||||
let nonTele = displayIDs.filter { !isTeleportedID($0) }
|
let nonTele = displayIDs.filter { !isTeleportedID($0) }
|
||||||
@@ -52,11 +47,7 @@ struct GeohashPeopleList: View {
|
|||||||
let person = personByID[pid]!
|
let person = personByID[pid]!
|
||||||
HStack(spacing: 4) {
|
HStack(spacing: 4) {
|
||||||
let isMe = (person.id == myHex)
|
let isMe = (person.id == myHex)
|
||||||
#if os(iOS)
|
|
||||||
let teleported = viewModel.teleportedGeo.contains(person.id.lowercased()) || (isMe && LocationChannelManager.shared.teleported)
|
let teleported = viewModel.teleportedGeo.contains(person.id.lowercased()) || (isMe && LocationChannelManager.shared.teleported)
|
||||||
#else
|
|
||||||
let teleported = false
|
|
||||||
#endif
|
|
||||||
let icon = teleported ? "face.dashed" : "mappin.and.ellipse"
|
let icon = teleported ? "face.dashed" : "mappin.and.ellipse"
|
||||||
let assignedColor = viewModel.colorForNostrPubkey(person.id, isDark: colorScheme == .dark)
|
let assignedColor = viewModel.colorForNostrPubkey(person.id, isDark: colorScheme == .dark)
|
||||||
let rowColor: Color = isMe ? .orange : assignedColor
|
let rowColor: Color = isMe ? .orange : assignedColor
|
||||||
@@ -127,10 +118,8 @@ struct GeohashPeopleList: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Helper to split a trailing #abcd suffix
|
// Helper to split a trailing #abcd suffix
|
||||||
#if os(iOS)
|
|
||||||
private func splitSuffix(from name: String) -> (String, String) {
|
private func splitSuffix(from name: String) -> (String, String) {
|
||||||
guard name.count >= 5 else { return (name, "") }
|
guard name.count >= 5 else { return (name, "") }
|
||||||
let suffix = String(name.suffix(5))
|
let suffix = String(name.suffix(5))
|
||||||
@@ -142,4 +131,3 @@ private func splitSuffix(from name: String) -> (String, String) {
|
|||||||
}
|
}
|
||||||
return (name, "")
|
return (name, "")
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import CoreLocation
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
import UIKit
|
import UIKit
|
||||||
|
#else
|
||||||
|
import AppKit
|
||||||
|
#endif
|
||||||
struct LocationChannelsSheet: View {
|
struct LocationChannelsSheet: View {
|
||||||
@Binding var isPresented: Bool
|
@Binding var isPresented: Bool
|
||||||
@ObservedObject private var manager = LocationChannelManager.shared
|
@ObservedObject private var manager = LocationChannelManager.shared
|
||||||
@@ -37,11 +40,7 @@ struct LocationChannelsSheet: View {
|
|||||||
Text("location permission denied. enable in settings to use location channels.")
|
Text("location permission denied. enable in settings to use location channels.")
|
||||||
.font(.system(size: 12, design: .monospaced))
|
.font(.system(size: 12, design: .monospaced))
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
Button("open settings") {
|
Button("open settings") { openSystemLocationSettings() }
|
||||||
if let url = URL(string: UIApplication.openSettingsURLString) {
|
|
||||||
UIApplication.shared.open(url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
}
|
}
|
||||||
case LocationChannelManager.PermissionState.authorized:
|
case LocationChannelManager.PermissionState.authorized:
|
||||||
@@ -54,6 +53,7 @@ struct LocationChannelsSheet: View {
|
|||||||
}
|
}
|
||||||
.padding(.horizontal, 16)
|
.padding(.horizontal, 16)
|
||||||
.padding(.vertical, 12)
|
.padding(.vertical, 12)
|
||||||
|
#if os(iOS)
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
@@ -61,8 +61,21 @@ struct LocationChannelsSheet: View {
|
|||||||
.font(.system(size: 14, design: .monospaced))
|
.font(.system(size: 14, design: .monospaced))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .automatic) {
|
||||||
|
Button("close") { isPresented = false }
|
||||||
|
.font(.system(size: 14, design: .monospaced))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
#if os(iOS)
|
||||||
.presentationDetents([.large])
|
.presentationDetents([.large])
|
||||||
|
#endif
|
||||||
|
#if os(macOS)
|
||||||
|
.frame(minWidth: 420, minHeight: 520)
|
||||||
|
#endif
|
||||||
.onAppear {
|
.onAppear {
|
||||||
// Refresh channels when opening
|
// Refresh channels when opening
|
||||||
if manager.permissionState == LocationChannelManager.PermissionState.authorized {
|
if manager.permissionState == LocationChannelManager.PermissionState.authorized {
|
||||||
@@ -128,10 +141,12 @@ struct LocationChannelsSheet: View {
|
|||||||
.font(.system(size: 14, design: .monospaced))
|
.font(.system(size: 14, design: .monospaced))
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
TextField("geohash", text: $customGeohash)
|
TextField("geohash", text: $customGeohash)
|
||||||
|
#if os(iOS)
|
||||||
.textInputAutocapitalization(.never)
|
.textInputAutocapitalization(.never)
|
||||||
.autocorrectionDisabled(true)
|
.autocorrectionDisabled(true)
|
||||||
.font(.system(size: 14, design: .monospaced))
|
|
||||||
.keyboardType(.asciiCapable)
|
.keyboardType(.asciiCapable)
|
||||||
|
#endif
|
||||||
|
.font(.system(size: 14, design: .monospaced))
|
||||||
.onChange(of: customGeohash) { newValue in
|
.onChange(of: customGeohash) { newValue in
|
||||||
// Allow only geohash base32 characters, strip '#', limit length
|
// Allow only geohash base32 characters, strip '#', limit length
|
||||||
let allowed = Set("0123456789bcdefghjkmnpqrstuvwxyz")
|
let allowed = Set("0123456789bcdefghjkmnpqrstuvwxyz")
|
||||||
@@ -183,9 +198,7 @@ struct LocationChannelsSheet: View {
|
|||||||
// Footer action inside the list
|
// Footer action inside the list
|
||||||
if manager.permissionState == LocationChannelManager.PermissionState.authorized {
|
if manager.permissionState == LocationChannelManager.PermissionState.authorized {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
if let url = URL(string: UIApplication.openSettingsURLString) {
|
openSystemLocationSettings()
|
||||||
UIApplication.shared.open(url)
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
Text("remove location access")
|
Text("remove location access")
|
||||||
.font(.system(size: 12, design: .monospaced))
|
.font(.system(size: 12, design: .monospaced))
|
||||||
@@ -343,7 +356,7 @@ extension LocationChannelsSheet {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
let usesMetric: Bool = {
|
let usesMetric: Bool = {
|
||||||
if #available(iOS 16.0, *) {
|
if #available(iOS 16.0, macOS 13.0, *) {
|
||||||
return Locale.current.measurementSystem == .metric
|
return Locale.current.measurementSystem == .metric
|
||||||
} else {
|
} else {
|
||||||
return Locale.current.usesMetricSystem
|
return Locale.current.usesMetricSystem
|
||||||
@@ -366,7 +379,7 @@ extension LocationChannelsSheet {
|
|||||||
|
|
||||||
private func bluetoothRangeString() -> String {
|
private func bluetoothRangeString() -> String {
|
||||||
let usesMetric: Bool = {
|
let usesMetric: Bool = {
|
||||||
if #available(iOS 16.0, *) {
|
if #available(iOS 16.0, macOS 13.0, *) {
|
||||||
return Locale.current.measurementSystem == .metric
|
return Locale.current.measurementSystem == .metric
|
||||||
} else {
|
} else {
|
||||||
return Locale.current.usesMetricSystem
|
return Locale.current.usesMetricSystem
|
||||||
@@ -390,4 +403,17 @@ extension LocationChannelsSheet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
// MARK: - Open Settings helper
|
||||||
|
private func openSystemLocationSettings() {
|
||||||
|
#if os(iOS)
|
||||||
|
if let url = URL(string: UIApplication.openSettingsURLString) {
|
||||||
|
UIApplication.shared.open(url)
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_LocationServices") {
|
||||||
|
NSWorkspace.shared.open(url)
|
||||||
|
} else if let url = URL(string: "x-apple.systempreferences:com.apple.preference.security") {
|
||||||
|
NSWorkspace.shared.open(url)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,9 +44,24 @@ struct MeshPeerList: View {
|
|||||||
let assigned = viewModel.colorForMeshPeer(id: peer.id, isDark: colorScheme == .dark)
|
let assigned = viewModel.colorForMeshPeer(id: peer.id, isDark: colorScheme == .dark)
|
||||||
let baseColor = isMe ? Color.orange : assigned
|
let baseColor = isMe ? Color.orange : assigned
|
||||||
if isMe {
|
if isMe {
|
||||||
Image(systemName: "person.fill").font(.system(size: 10)).foregroundColor(baseColor)
|
Image(systemName: "person.fill")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(baseColor)
|
||||||
|
} else if peer.isConnected {
|
||||||
|
// Mesh-connected peer: radio icon
|
||||||
|
Image(systemName: "antenna.radiowaves.left.and.right")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(baseColor)
|
||||||
|
} else if peer.isMutualFavorite {
|
||||||
|
// Mutual favorite reachable via Nostr: globe icon (purple)
|
||||||
|
Image(systemName: "globe")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(.purple)
|
||||||
} else {
|
} else {
|
||||||
Image(systemName: "mappin.and.ellipse").font(.system(size: 10)).foregroundColor(baseColor)
|
// Fallback icon for others (dimmed)
|
||||||
|
Image(systemName: "person")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(secondaryTextColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
let displayName = isMe ? viewModel.nickname : peer.nickname
|
let displayName = isMe ? viewModel.nickname : peer.nickname
|
||||||
@@ -70,10 +85,27 @@ struct MeshPeerList: View {
|
|||||||
.help("Blocked")
|
.help("Blocked")
|
||||||
}
|
}
|
||||||
|
|
||||||
if let icon = item.enc.icon, !isMe {
|
if !isMe {
|
||||||
Image(systemName: icon)
|
if peer.isConnected {
|
||||||
.font(.system(size: 10))
|
if let icon = item.enc.icon {
|
||||||
.foregroundColor(baseColor)
|
Image(systemName: icon)
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(baseColor)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Offline: prefer showing verified badge from persisted fingerprints
|
||||||
|
if let fp = viewModel.getFingerprint(for: peer.id),
|
||||||
|
viewModel.verifiedFingerprints.contains(fp) {
|
||||||
|
Image(systemName: "checkmark.seal.fill")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(baseColor)
|
||||||
|
} else if let icon = item.enc.icon {
|
||||||
|
// Fallback to whatever status says (likely lock if we had a past session)
|
||||||
|
Image(systemName: icon)
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(baseColor)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|||||||
@@ -0,0 +1,347 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import CoreImage
|
||||||
|
import CoreImage.CIFilterBuiltins
|
||||||
|
#if os(iOS)
|
||||||
|
import UIKit
|
||||||
|
#else
|
||||||
|
import AppKit
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// Placeholder view to display the user's verification QR payload as text.
|
||||||
|
struct MyQRView: View {
|
||||||
|
let qrString: String
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
private var boxColor: Color { Color.gray.opacity(0.1) }
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
Text("scan to verify me")
|
||||||
|
.font(.system(size: 16, weight: .bold, design: .monospaced))
|
||||||
|
|
||||||
|
VStack(spacing: 10) {
|
||||||
|
QRCodeImage(data: qrString, size: 240)
|
||||||
|
.accessibilityLabel("verification qr code")
|
||||||
|
|
||||||
|
// Non-scrolling, fully visible URL (wraps across lines)
|
||||||
|
Text(qrString)
|
||||||
|
.font(.system(size: 11, design: .monospaced))
|
||||||
|
.textSelection(.enabled)
|
||||||
|
.multilineTextAlignment(.leading)
|
||||||
|
.fixedSize(horizontal: false, vertical: true)
|
||||||
|
.padding(8)
|
||||||
|
.background(boxColor)
|
||||||
|
.cornerRadius(8)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.background(boxColor)
|
||||||
|
.cornerRadius(8)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render a QR code image for a given string using CoreImage
|
||||||
|
struct QRCodeImage: View {
|
||||||
|
let data: String
|
||||||
|
let size: CGFloat
|
||||||
|
|
||||||
|
private let context = CIContext()
|
||||||
|
private let filter = CIFilter.qrCodeGenerator()
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Group {
|
||||||
|
if let image = generateImage() {
|
||||||
|
ImageWrapper(image: image)
|
||||||
|
.frame(width: size, height: size)
|
||||||
|
} else {
|
||||||
|
RoundedRectangle(cornerRadius: 8)
|
||||||
|
.stroke(Color.gray.opacity(0.5), lineWidth: 1)
|
||||||
|
.frame(width: size, height: size)
|
||||||
|
.overlay(
|
||||||
|
Text("qr unavailable")
|
||||||
|
.font(.system(size: 12, design: .monospaced))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func generateImage() -> CGImage? {
|
||||||
|
let inputData = Data(data.utf8)
|
||||||
|
filter.message = inputData
|
||||||
|
filter.correctionLevel = "M"
|
||||||
|
guard let outputImage = filter.outputImage else { return nil }
|
||||||
|
let scale = max(1, Int(size / 32))
|
||||||
|
let transformed = outputImage.transformed(by: CGAffineTransform(scaleX: CGFloat(scale), y: CGFloat(scale)))
|
||||||
|
return context.createCGImage(transformed, from: transformed.extent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Platform-specific wrapper to display CGImage in SwiftUI
|
||||||
|
struct ImageWrapper: View {
|
||||||
|
let image: CGImage
|
||||||
|
var body: some View {
|
||||||
|
#if os(iOS)
|
||||||
|
let ui = UIImage(cgImage: image)
|
||||||
|
return Image(uiImage: ui)
|
||||||
|
.interpolation(.none)
|
||||||
|
.resizable()
|
||||||
|
#else
|
||||||
|
let ns = NSImage(cgImage: image, size: .zero)
|
||||||
|
return Image(nsImage: ns)
|
||||||
|
.interpolation(.none)
|
||||||
|
.resizable()
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Placeholder scanner UI; real camera scanning will be added later.
|
||||||
|
struct QRScanView: View {
|
||||||
|
@EnvironmentObject var viewModel: ChatViewModel
|
||||||
|
var isActive: Bool = true
|
||||||
|
@State private var input = ""
|
||||||
|
@State private var result: String = "" // not shown for iOS scanner
|
||||||
|
@State private var lastValid: String = ""
|
||||||
|
var body: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
#if os(iOS)
|
||||||
|
CameraScannerView(isActive: isActive) { code in
|
||||||
|
if let qr = VerificationService.shared.verifyScannedQR(code) {
|
||||||
|
let ok = viewModel.beginQRVerification(with: qr)
|
||||||
|
if !ok { /* already pending; continue scanning */ }
|
||||||
|
lastValid = code
|
||||||
|
} else {
|
||||||
|
// ignore invalid reads; continue scanning
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(height: 260)
|
||||||
|
.clipShape(RoundedRectangle(cornerRadius: 8))
|
||||||
|
#else
|
||||||
|
Text("paste qr content to validate:")
|
||||||
|
.font(.system(size: 14, weight: .medium, design: .monospaced))
|
||||||
|
TextEditor(text: $input)
|
||||||
|
.frame(height: 100)
|
||||||
|
.border(Color.gray.opacity(0.4))
|
||||||
|
Button("validate") {
|
||||||
|
if let qr = VerificationService.shared.verifyScannedQR(input) {
|
||||||
|
let ok = viewModel.beginQRVerification(with: qr)
|
||||||
|
result = ok ? "verification requested for \(qr.nickname)" : "could not find matching peer"
|
||||||
|
} else {
|
||||||
|
result = "invalid or expired qr payload"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
#endif
|
||||||
|
// No status text under camera per design
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
|
import AVFoundation
|
||||||
|
|
||||||
|
struct CameraScannerView: UIViewRepresentable {
|
||||||
|
typealias UIViewType = PreviewView
|
||||||
|
var isActive: Bool
|
||||||
|
var onCode: (String) -> Void
|
||||||
|
|
||||||
|
func makeUIView(context: Context) -> PreviewView {
|
||||||
|
let view = PreviewView()
|
||||||
|
context.coordinator.setup(sessionOwner: view, onCode: onCode)
|
||||||
|
context.coordinator.setActive(isActive)
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateUIView(_ uiView: PreviewView, context: Context) {
|
||||||
|
context.coordinator.setActive(isActive)
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeCoordinator() -> Coordinator { Coordinator() }
|
||||||
|
|
||||||
|
final class Coordinator: NSObject, AVCaptureMetadataOutputObjectsDelegate {
|
||||||
|
private var onCode: ((String) -> Void)?
|
||||||
|
private weak var owner: PreviewView?
|
||||||
|
private let session = AVCaptureSession()
|
||||||
|
private var isRunning = false
|
||||||
|
private var permissionGranted = false
|
||||||
|
private var desiredActive = false
|
||||||
|
|
||||||
|
func setup(sessionOwner: PreviewView, onCode: @escaping (String) -> Void) {
|
||||||
|
self.owner = sessionOwner
|
||||||
|
self.onCode = onCode
|
||||||
|
session.beginConfiguration()
|
||||||
|
session.sessionPreset = .high
|
||||||
|
guard let device = AVCaptureDevice.default(for: .video),
|
||||||
|
let input = try? AVCaptureDeviceInput(device: device),
|
||||||
|
session.canAddInput(input) else { return }
|
||||||
|
session.addInput(input)
|
||||||
|
let output = AVCaptureMetadataOutput()
|
||||||
|
guard session.canAddOutput(output) else { return }
|
||||||
|
session.addOutput(output)
|
||||||
|
output.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
|
||||||
|
if output.availableMetadataObjectTypes.contains(.qr) {
|
||||||
|
output.metadataObjectTypes = [.qr]
|
||||||
|
}
|
||||||
|
session.commitConfiguration()
|
||||||
|
sessionOwner.videoPreviewLayer.session = session
|
||||||
|
// Request permission and start
|
||||||
|
AVCaptureDevice.requestAccess(for: .video) { granted in
|
||||||
|
self.permissionGranted = granted
|
||||||
|
if granted && self.desiredActive && !self.isRunning {
|
||||||
|
self.setActive(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setActive(_ active: Bool) {
|
||||||
|
desiredActive = active
|
||||||
|
guard permissionGranted else { return }
|
||||||
|
if active && !isRunning {
|
||||||
|
isRunning = true
|
||||||
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
|
if !self.session.isRunning { self.session.startRunning() }
|
||||||
|
}
|
||||||
|
} else if !active && isRunning {
|
||||||
|
isRunning = false
|
||||||
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
|
if self.session.isRunning { self.session.stopRunning() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
|
||||||
|
for obj in metadataObjects {
|
||||||
|
guard let m = obj as? AVMetadataMachineReadableCodeObject,
|
||||||
|
m.type == .qr,
|
||||||
|
let str = m.stringValue else { continue }
|
||||||
|
onCode?(str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final class PreviewView: UIView {
|
||||||
|
override class var layerClass: AnyClass { AVCaptureVideoPreviewLayer.self }
|
||||||
|
var videoPreviewLayer: AVCaptureVideoPreviewLayer { layer as! AVCaptureVideoPreviewLayer }
|
||||||
|
override init(frame: CGRect) {
|
||||||
|
super.init(frame: frame)
|
||||||
|
videoPreviewLayer.videoGravity = .resizeAspectFill
|
||||||
|
}
|
||||||
|
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Combined sheet: shows my QR by default with a button to scan instead
|
||||||
|
struct VerificationSheetView: View {
|
||||||
|
@EnvironmentObject var viewModel: ChatViewModel
|
||||||
|
@Binding var isPresented: Bool
|
||||||
|
@State private var showingScanner = false
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
|
||||||
|
private var backgroundColor: Color { colorScheme == .dark ? Color.black : Color.white }
|
||||||
|
private var accentColor: Color { colorScheme == .dark ? Color.green : Color(red: 0, green: 0.5, blue: 0) }
|
||||||
|
private var boxColor: Color { Color.gray.opacity(0.1) }
|
||||||
|
|
||||||
|
private func myQRString() -> String {
|
||||||
|
let npub = try? NostrIdentityBridge.getCurrentNostrIdentity()?.npub
|
||||||
|
return VerificationService.shared.buildMyQRString(nickname: viewModel.nickname, npub: npub) ?? ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
// Top header (always at top)
|
||||||
|
HStack {
|
||||||
|
Text("VERIFY")
|
||||||
|
.font(.system(size: 14, weight: .bold, design: .monospaced))
|
||||||
|
.foregroundColor(accentColor)
|
||||||
|
Spacer()
|
||||||
|
Button(action: {
|
||||||
|
showingScanner = false
|
||||||
|
isPresented = false
|
||||||
|
}) {
|
||||||
|
Image(systemName: "xmark")
|
||||||
|
.font(.system(size: 14, weight: .semibold))
|
||||||
|
.foregroundColor(accentColor)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 16)
|
||||||
|
.padding(.top, 12)
|
||||||
|
.padding(.bottom, 8)
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
// Content area
|
||||||
|
Group {
|
||||||
|
if showingScanner {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
Text("scan a friend's qr")
|
||||||
|
.font(.system(size: 16, weight: .bold, design: .monospaced))
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.foregroundColor(accentColor)
|
||||||
|
#if os(iOS)
|
||||||
|
QRScanView(isActive: showingScanner)
|
||||||
|
.environmentObject(viewModel)
|
||||||
|
.frame(height: 280)
|
||||||
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||||
|
#else
|
||||||
|
QRScanView()
|
||||||
|
.environmentObject(viewModel)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.background(boxColor)
|
||||||
|
.cornerRadius(8)
|
||||||
|
} else {
|
||||||
|
let qr = myQRString()
|
||||||
|
MyQRView(qrString: qr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
|
||||||
|
|
||||||
|
// Centered controls moved up
|
||||||
|
VStack(spacing: 10) {
|
||||||
|
if showingScanner {
|
||||||
|
Button(action: { showingScanner = false }) {
|
||||||
|
Label("show my qr", systemImage: "qrcode")
|
||||||
|
.font(.system(size: 13, design: .monospaced))
|
||||||
|
}
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
} else {
|
||||||
|
Button(action: { showingScanner = true }) {
|
||||||
|
Label("scan someone else's qr", systemImage: "camera.viewfinder")
|
||||||
|
.font(.system(size: 13, weight: .medium, design: .monospaced))
|
||||||
|
}
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
.tint(.gray)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional: Remove verification for selected peer (if verified)
|
||||||
|
if let pid = viewModel.selectedPrivateChatPeer,
|
||||||
|
let fp = viewModel.getFingerprint(for: pid),
|
||||||
|
viewModel.verifiedFingerprints.contains(fp) {
|
||||||
|
Button(action: { viewModel.unverifyFingerprint(for: pid) }) {
|
||||||
|
Label("remove verification", systemImage: "minus.circle")
|
||||||
|
.font(.system(size: 12, design: .monospaced))
|
||||||
|
}
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
.tint(.gray)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.padding(.vertical, 14)
|
||||||
|
}
|
||||||
|
.background(backgroundColor)
|
||||||
|
#if os(iOS)
|
||||||
|
.presentationDetents([.large])
|
||||||
|
.presentationDragIndicator(.visible)
|
||||||
|
#endif
|
||||||
|
.onDisappear { showingScanner = false }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,9 @@
|
|||||||
</array>
|
</array>
|
||||||
<key>com.apple.security.device.bluetooth</key>
|
<key>com.apple.security.device.bluetooth</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>com.apple.security.personal-information.location</key>
|
||||||
|
<true/>
|
||||||
<key>com.apple.security.network.client</key>
|
<key>com.apple.security.network.client</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -7,160 +7,160 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import Social
|
|
||||||
import UniformTypeIdentifiers
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
class ShareViewController: SLComposeServiceViewController {
|
/// Modern share extension using UIKit + UTTypes.
|
||||||
|
/// Avoids deprecated Social framework and SLComposeServiceViewController.
|
||||||
|
final class ShareViewController: UIViewController {
|
||||||
|
private let statusLabel: UILabel = {
|
||||||
|
let l = UILabel()
|
||||||
|
l.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
l.font = .systemFont(ofSize: 15, weight: .semibold)
|
||||||
|
l.textAlignment = .center
|
||||||
|
l.numberOfLines = 0
|
||||||
|
l.textColor = .label
|
||||||
|
return l
|
||||||
|
}()
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
// Set placeholder text
|
view.backgroundColor = .systemBackground
|
||||||
placeholder = "Share to bitchat..."
|
view.addSubview(statusLabel)
|
||||||
// Set character limit (optional)
|
NSLayoutConstraint.activate([
|
||||||
charactersRemaining = 500
|
statusLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||||
|
statusLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
||||||
|
statusLabel.leadingAnchor.constraint(greaterThanOrEqualTo: view.layoutMarginsGuide.leadingAnchor),
|
||||||
|
statusLabel.trailingAnchor.constraint(lessThanOrEqualTo: view.layoutMarginsGuide.trailingAnchor)
|
||||||
|
])
|
||||||
|
|
||||||
|
processShare()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func isContentValid() -> Bool {
|
// MARK: - Processing
|
||||||
// Validate that we have text content or attachments
|
private func processShare() {
|
||||||
if let text = contentText, !text.isEmpty {
|
guard let ctx = self.extensionContext,
|
||||||
return true
|
let item = ctx.inputItems.first as? NSExtensionItem else {
|
||||||
}
|
finishWithMessage("Nothing to share")
|
||||||
// Check if we have attachments
|
|
||||||
if let item = extensionContext?.inputItems.first as? NSExtensionItem,
|
|
||||||
let attachments = item.attachments,
|
|
||||||
!attachments.isEmpty {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override func didSelectPost() {
|
|
||||||
guard let extensionItem = extensionContext?.inputItems.first as? NSExtensionItem else {
|
|
||||||
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try content from attributed text first (Safari often passes URL here)
|
||||||
// Get the page title from the compose view or extension item
|
if let url = detectURL(in: item.attributedContentText?.string ?? "") {
|
||||||
let pageTitle = self.contentText ?? extensionItem.attributedContentText?.string ?? extensionItem.attributedTitle?.string
|
saveAndFinish(url: url, title: item.attributedTitle?.string)
|
||||||
|
return
|
||||||
var foundURL: URL? = nil
|
|
||||||
let group = DispatchGroup()
|
|
||||||
|
|
||||||
// IMPORTANT: Check if the NSExtensionItem itself has a URL
|
|
||||||
// Safari often provides the URL as an attributedString with a link
|
|
||||||
if let attributedText = extensionItem.attributedContentText {
|
|
||||||
let text = attributedText.string
|
|
||||||
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
|
|
||||||
let matches = detector?.matches(in: text, options: [], range: NSRange(location: 0, length: text.utf16.count))
|
|
||||||
if let firstMatch = matches?.first, let url = firstMatch.url {
|
|
||||||
foundURL = url
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only check attachments if we haven't found a URL yet
|
// Scan attachments for URL/text
|
||||||
if foundURL == nil {
|
let providers = item.attachments ?? []
|
||||||
for (_, itemProvider) in (extensionItem.attachments ?? []).enumerated() {
|
if providers.isEmpty {
|
||||||
|
// Fallback: use attributed title as plain text
|
||||||
// Try multiple URL type identifiers that Safari might use
|
if let title = item.attributedTitle?.string, !title.isEmpty {
|
||||||
let urlTypes = [
|
saveAndFinish(text: title)
|
||||||
UTType.url.identifier,
|
} else {
|
||||||
"public.url",
|
finishWithMessage("No shareable content")
|
||||||
"public.file-url"
|
|
||||||
]
|
|
||||||
|
|
||||||
for urlType in urlTypes {
|
|
||||||
if itemProvider.hasItemConformingToTypeIdentifier(urlType) {
|
|
||||||
group.enter()
|
|
||||||
itemProvider.loadItem(forTypeIdentifier: urlType, options: nil) { (item, error) in
|
|
||||||
defer { group.leave() }
|
|
||||||
|
|
||||||
if let url = item as? URL {
|
|
||||||
foundURL = url
|
|
||||||
} else if let data = item as? Data,
|
|
||||||
let urlString = String(data: data, encoding: .utf8),
|
|
||||||
let url = URL(string: urlString) {
|
|
||||||
foundURL = url
|
|
||||||
} else if let string = item as? String,
|
|
||||||
let url = URL(string: string) {
|
|
||||||
foundURL = url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break // Found a URL type, no need to check other types
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
// Also check for plain text that might be a URL
|
}
|
||||||
if foundURL == nil && itemProvider.hasItemConformingToTypeIdentifier(UTType.plainText.identifier) {
|
|
||||||
group.enter()
|
// Load URL or text asynchronously
|
||||||
itemProvider.loadItem(forTypeIdentifier: UTType.plainText.identifier, options: nil) { (item, error) in
|
loadFirstURL(from: providers) { [weak self] url in
|
||||||
defer { group.leave() }
|
guard let self = self else { return }
|
||||||
|
if let url = url {
|
||||||
if let text = item as? String {
|
self.saveAndFinish(url: url, title: item.attributedTitle?.string)
|
||||||
// Check if the text is actually a URL
|
} else {
|
||||||
if let url = URL(string: text),
|
self.loadFirstPlainText(from: providers) { text in
|
||||||
(url.scheme == "http" || url.scheme == "https") {
|
if let t = text, !t.isEmpty {
|
||||||
foundURL = url
|
// Treat as URL if parseable http(s), else plain text
|
||||||
|
if let u = URL(string: t), ["http","https"].contains(u.scheme?.lowercased() ?? "") {
|
||||||
|
self.saveAndFinish(url: u, title: item.attributedTitle?.string)
|
||||||
|
} else {
|
||||||
|
self.saveAndFinish(text: t)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
self.finishWithMessage("No shareable content")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // End of if foundURL == nil
|
}
|
||||||
|
|
||||||
// Process after all checks complete
|
private func detectURL(in text: String) -> URL? {
|
||||||
group.notify(queue: .main) { [weak self] in
|
guard !text.isEmpty else { return nil }
|
||||||
if let url = foundURL {
|
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
|
||||||
// We have a URL! Create the JSON data
|
let range = NSRange(location: 0, length: (text as NSString).length)
|
||||||
let urlData: [String: String] = [
|
let match = detector?.matches(in: text, options: [], range: range).first
|
||||||
"url": url.absoluteString,
|
return match?.url
|
||||||
"title": pageTitle ?? url.host ?? "Shared Link"
|
}
|
||||||
]
|
|
||||||
|
private func loadFirstURL(from providers: [NSItemProvider], completion: @escaping (URL?) -> Void) {
|
||||||
|
let identifiers = [UTType.url.identifier, "public.url", "public.file-url"]
|
||||||
if let jsonData = try? JSONSerialization.data(withJSONObject: urlData),
|
let grp = DispatchGroup()
|
||||||
let jsonString = String(data: jsonData, encoding: .utf8) {
|
var found: URL?
|
||||||
self?.saveToSharedDefaults(content: jsonString, type: "url")
|
|
||||||
|
for p in providers where found == nil {
|
||||||
|
for id in identifiers where p.hasItemConformingToTypeIdentifier(id) {
|
||||||
|
grp.enter()
|
||||||
|
p.loadItem(forTypeIdentifier: id, options: nil) { item, _ in
|
||||||
|
defer { grp.leave() }
|
||||||
|
if let u = item as? URL { found = u; return }
|
||||||
|
if let s = item as? String, let u = URL(string: s) { found = u; return }
|
||||||
|
if let d = item as? Data, let s = String(data: d, encoding: .utf8), let u = URL(string: s) { found = u; return }
|
||||||
}
|
}
|
||||||
} else if let title = pageTitle, !title.isEmpty {
|
break
|
||||||
// No URL found, just share the text
|
|
||||||
self?.saveToSharedDefaults(content: title, type: "text")
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
self?.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
|
grp.notify(queue: .main) { completion(found) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func loadFirstPlainText(from providers: [NSItemProvider], completion: @escaping (String?) -> Void) {
|
||||||
|
let id = UTType.plainText.identifier
|
||||||
|
let grp = DispatchGroup()
|
||||||
|
var text: String?
|
||||||
|
for p in providers where p.hasItemConformingToTypeIdentifier(id) {
|
||||||
|
grp.enter()
|
||||||
|
p.loadItem(forTypeIdentifier: id, options: nil) { item, _ in
|
||||||
|
defer { grp.leave() }
|
||||||
|
if let s = item as? String { text = s }
|
||||||
|
else if let d = item as? Data, let s = String(data: d, encoding: .utf8) { text = s }
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
grp.notify(queue: .main) { completion(text) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Save + Finish
|
||||||
|
private func saveAndFinish(url: URL, title: String?) {
|
||||||
|
let payload: [String: String] = [
|
||||||
|
"url": url.absoluteString,
|
||||||
|
"title": title ?? url.host ?? "Shared Link"
|
||||||
|
]
|
||||||
|
if let json = try? JSONSerialization.data(withJSONObject: payload),
|
||||||
|
let s = String(data: json, encoding: .utf8) {
|
||||||
|
saveToSharedDefaults(content: s, type: "url")
|
||||||
|
finishWithMessage("✓ Shared link to bitchat")
|
||||||
|
} else {
|
||||||
|
finishWithMessage("Failed to encode link")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func configurationItems() -> [Any]! {
|
private func saveAndFinish(text: String) {
|
||||||
// No configuration items needed
|
saveToSharedDefaults(content: text, type: "text")
|
||||||
return []
|
finishWithMessage("✓ Shared text to bitchat")
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Helper Methods
|
|
||||||
|
|
||||||
private func saveToSharedDefaults(content: String, type: String) {
|
private func saveToSharedDefaults(content: String, type: String) {
|
||||||
// Use app groups to share data between extension and main app
|
guard let userDefaults = UserDefaults(suiteName: "group.chat.bitchat") else { return }
|
||||||
guard let userDefaults = UserDefaults(suiteName: "group.chat.bitchat") else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userDefaults.set(content, forKey: "sharedContent")
|
userDefaults.set(content, forKey: "sharedContent")
|
||||||
userDefaults.set(type, forKey: "sharedContentType")
|
userDefaults.set(type, forKey: "sharedContentType")
|
||||||
userDefaults.set(Date(), forKey: "sharedContentDate")
|
userDefaults.set(Date(), forKey: "sharedContentDate")
|
||||||
userDefaults.synchronize()
|
userDefaults.synchronize()
|
||||||
|
|
||||||
|
|
||||||
// Force open the main app
|
|
||||||
self.openMainApp()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func openMainApp() {
|
private func finishWithMessage(_ msg: String) {
|
||||||
// Share extensions cannot directly open the containing app
|
statusLabel.text = msg
|
||||||
// The app will check for shared content when it becomes active
|
// Complete shortly after showing status
|
||||||
// Show success feedback to user
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
||||||
DispatchQueue.main.async {
|
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
|
||||||
self.textView.text = "✓ Shared to bitchat"
|
|
||||||
self.textView.isEditable = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ final class NostrProtocolTests: XCTestCase {
|
|||||||
let sender = try NostrIdentity.generate()
|
let sender = try NostrIdentity.generate()
|
||||||
let recipient = try NostrIdentity.generate()
|
let recipient = try NostrIdentity.generate()
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
print("Sender pubkey: \(sender.publicKeyHex)")
|
print("Sender pubkey: \(sender.publicKeyHex)")
|
||||||
print("Recipient pubkey: \(recipient.publicKeyHex)")
|
print("Recipient pubkey: \(recipient.publicKeyHex)")
|
||||||
|
#endif
|
||||||
|
|
||||||
// Create a test message
|
// Create a test message
|
||||||
let originalContent = "Hello from NIP-17 test!"
|
let originalContent = "Hello from NIP-17 test!"
|
||||||
@@ -34,8 +36,10 @@ final class NostrProtocolTests: XCTestCase {
|
|||||||
senderIdentity: sender
|
senderIdentity: sender
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
print("Gift wrap created with ID: \(giftWrap.id)")
|
print("Gift wrap created with ID: \(giftWrap.id)")
|
||||||
print("Gift wrap pubkey: \(giftWrap.pubkey)")
|
print("Gift wrap pubkey: \(giftWrap.pubkey)")
|
||||||
|
#endif
|
||||||
|
|
||||||
// Decrypt the gift wrap
|
// Decrypt the gift wrap
|
||||||
let (decryptedContent, senderPubkey, timestamp) = try NostrProtocol.decryptPrivateMessage(
|
let (decryptedContent, senderPubkey, timestamp) = try NostrProtocol.decryptPrivateMessage(
|
||||||
@@ -52,7 +56,9 @@ final class NostrProtocolTests: XCTestCase {
|
|||||||
let timeDiff = abs(messageDate.timeIntervalSinceNow)
|
let timeDiff = abs(messageDate.timeIntervalSinceNow)
|
||||||
XCTAssertLessThan(timeDiff, 60, "Message timestamp should be recent")
|
XCTAssertLessThan(timeDiff, 60, "Message timestamp should be recent")
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
print("✅ Successfully decrypted message: '\(decryptedContent)' from \(senderPubkey) at \(messageDate)")
|
print("✅ Successfully decrypted message: '\(decryptedContent)' from \(senderPubkey) at \(messageDate)")
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGiftWrapUsesUniqueEphemeralKeys() throws {
|
func testGiftWrapUsesUniqueEphemeralKeys() throws {
|
||||||
@@ -75,8 +81,10 @@ final class NostrProtocolTests: XCTestCase {
|
|||||||
|
|
||||||
// Gift wrap pubkeys should be different (unique ephemeral keys)
|
// Gift wrap pubkeys should be different (unique ephemeral keys)
|
||||||
XCTAssertNotEqual(message1.pubkey, message2.pubkey)
|
XCTAssertNotEqual(message1.pubkey, message2.pubkey)
|
||||||
|
#if DEBUG
|
||||||
print("Message 1 gift wrap pubkey: \(message1.pubkey)")
|
print("Message 1 gift wrap pubkey: \(message1.pubkey)")
|
||||||
print("Message 2 gift wrap pubkey: \(message2.pubkey)")
|
print("Message 2 gift wrap pubkey: \(message2.pubkey)")
|
||||||
|
#endif
|
||||||
|
|
||||||
// Both should decrypt successfully
|
// Both should decrypt successfully
|
||||||
let (content1, _, _) = try NostrProtocol.decryptPrivateMessage(
|
let (content1, _, _) = try NostrProtocol.decryptPrivateMessage(
|
||||||
@@ -109,7 +117,114 @@ final class NostrProtocolTests: XCTestCase {
|
|||||||
giftWrap: giftWrap,
|
giftWrap: giftWrap,
|
||||||
recipientIdentity: wrongRecipient
|
recipientIdentity: wrongRecipient
|
||||||
)) { error in
|
)) { error in
|
||||||
|
#if DEBUG
|
||||||
print("Expected error when decrypting with wrong key: \(error)")
|
print("Expected error when decrypting with wrong key: \(error)")
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
func testAckRoundTripNIP44V2_Delivered() throws {
|
||||||
|
// Identities
|
||||||
|
let sender = try NostrIdentity.generate()
|
||||||
|
let recipient = try NostrIdentity.generate()
|
||||||
|
|
||||||
|
// Build a DELIVERED ack embedded payload (geohash-style, no recipient peer ID)
|
||||||
|
let messageID = "TEST-MSG-DELIVERED-1"
|
||||||
|
let senderPeerID = "0123456789abcdef" // 8-byte hex peer ID
|
||||||
|
guard let embedded = NostrEmbeddedBitChat.encodeAckForNostrNoRecipient(type: .delivered, messageID: messageID, senderPeerID: senderPeerID) else {
|
||||||
|
XCTFail("Failed to embed delivered ack")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create NIP-17 gift wrap to recipient (uses NIP-44 v2 internally)
|
||||||
|
let giftWrap = try NostrProtocol.createPrivateMessage(
|
||||||
|
content: embedded,
|
||||||
|
recipientPubkey: recipient.publicKeyHex,
|
||||||
|
senderIdentity: sender
|
||||||
|
)
|
||||||
|
|
||||||
|
// Ensure v2 format was used for ciphertext
|
||||||
|
XCTAssertTrue(giftWrap.content.hasPrefix("v2:"))
|
||||||
|
|
||||||
|
// Decrypt as recipient
|
||||||
|
let (content, senderPubkey, _) = try NostrProtocol.decryptPrivateMessage(
|
||||||
|
giftWrap: giftWrap,
|
||||||
|
recipientIdentity: recipient
|
||||||
|
)
|
||||||
|
|
||||||
|
// Verify sender is correct
|
||||||
|
XCTAssertEqual(senderPubkey, sender.publicKeyHex)
|
||||||
|
|
||||||
|
// Parse BitChat payload
|
||||||
|
XCTAssertTrue(content.hasPrefix("bitchat1:"))
|
||||||
|
let base64url = String(content.dropFirst("bitchat1:".count))
|
||||||
|
guard let packetData = Self.base64URLDecode(base64url),
|
||||||
|
let packet = BitchatPacket.from(packetData) else {
|
||||||
|
return XCTFail("Failed to decode bitchat packet")
|
||||||
|
}
|
||||||
|
XCTAssertEqual(packet.type, MessageType.noiseEncrypted.rawValue)
|
||||||
|
guard let payload = NoisePayload.decode(packet.payload) else {
|
||||||
|
return XCTFail("Failed to decode NoisePayload")
|
||||||
|
}
|
||||||
|
switch payload.type {
|
||||||
|
case .delivered:
|
||||||
|
let mid = String(data: payload.data, encoding: .utf8)
|
||||||
|
XCTAssertEqual(mid, messageID)
|
||||||
|
default:
|
||||||
|
XCTFail("Unexpected payload type: \(payload.type)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAckRoundTripNIP44V2_ReadReceipt() throws {
|
||||||
|
// Identities
|
||||||
|
let sender = try NostrIdentity.generate()
|
||||||
|
let recipient = try NostrIdentity.generate()
|
||||||
|
|
||||||
|
let messageID = "TEST-MSG-READ-1"
|
||||||
|
let senderPeerID = "fedcba9876543210" // 8-byte hex peer ID
|
||||||
|
guard let embedded = NostrEmbeddedBitChat.encodeAckForNostrNoRecipient(type: .readReceipt, messageID: messageID, senderPeerID: senderPeerID) else {
|
||||||
|
XCTFail("Failed to embed read ack")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let giftWrap = try NostrProtocol.createPrivateMessage(
|
||||||
|
content: embedded,
|
||||||
|
recipientPubkey: recipient.publicKeyHex,
|
||||||
|
senderIdentity: sender
|
||||||
|
)
|
||||||
|
|
||||||
|
XCTAssertTrue(giftWrap.content.hasPrefix("v2:"))
|
||||||
|
|
||||||
|
let (content, senderPubkey, _) = try NostrProtocol.decryptPrivateMessage(
|
||||||
|
giftWrap: giftWrap,
|
||||||
|
recipientIdentity: recipient
|
||||||
|
)
|
||||||
|
XCTAssertEqual(senderPubkey, sender.publicKeyHex)
|
||||||
|
|
||||||
|
XCTAssertTrue(content.hasPrefix("bitchat1:"))
|
||||||
|
let base64url = String(content.dropFirst("bitchat1:".count))
|
||||||
|
guard let packetData = Self.base64URLDecode(base64url),
|
||||||
|
let packet = BitchatPacket.from(packetData) else {
|
||||||
|
return XCTFail("Failed to decode bitchat packet")
|
||||||
|
}
|
||||||
|
XCTAssertEqual(packet.type, MessageType.noiseEncrypted.rawValue)
|
||||||
|
guard let payload = NoisePayload.decode(packet.payload) else {
|
||||||
|
return XCTFail("Failed to decode NoisePayload")
|
||||||
|
}
|
||||||
|
switch payload.type {
|
||||||
|
case .readReceipt:
|
||||||
|
let mid = String(data: payload.data, encoding: .utf8)
|
||||||
|
XCTAssertEqual(mid, messageID)
|
||||||
|
default:
|
||||||
|
XCTFail("Unexpected payload type: \(payload.type)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Helpers
|
||||||
|
private static func base64URLDecode(_ s: String) -> Data? {
|
||||||
|
var str = s.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
|
||||||
|
let rem = str.count % 4
|
||||||
|
if rem > 0 { str.append(String(repeating: "=", count: 4 - rem)) }
|
||||||
|
return Data(base64Encoded: str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
//
|
|
||||||
// LegacyTestProtocolTypes.swift
|
|
||||||
// bitchatTests
|
|
||||||
//
|
|
||||||
// Minimal legacy protocol types used only by tests to simulate old flows.
|
|
||||||
// These are not part of production code anymore.
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
struct ProtocolNack {
|
|
||||||
let originalPacketID: String
|
|
||||||
let nackID: String
|
|
||||||
let senderID: String
|
|
||||||
let receiverID: String
|
|
||||||
let packetType: UInt8
|
|
||||||
let reason: String
|
|
||||||
let errorCode: UInt8
|
|
||||||
|
|
||||||
enum ErrorCode: UInt8 {
|
|
||||||
case unknown = 0
|
|
||||||
case decryptionFailed = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
init(originalPacketID: String, senderID: String, receiverID: String, packetType: UInt8, reason: String, errorCode: ErrorCode = .unknown) {
|
|
||||||
self.originalPacketID = originalPacketID
|
|
||||||
self.nackID = UUID().uuidString
|
|
||||||
self.senderID = senderID
|
|
||||||
self.receiverID = receiverID
|
|
||||||
self.packetType = packetType
|
|
||||||
self.reason = reason
|
|
||||||
self.errorCode = errorCode.rawValue
|
|
||||||
}
|
|
||||||
|
|
||||||
func toBinaryData() -> Data {
|
|
||||||
// Tests don't parse the payload; return a compact encoding for completeness
|
|
||||||
var data = Data()
|
|
||||||
data.appendUUID(originalPacketID)
|
|
||||||
data.appendUUID(nackID)
|
|
||||||
data.append(UInt8(packetType))
|
|
||||||
data.append(UInt8(errorCode))
|
|
||||||
data.appendString(reason)
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
Command line invocation:
|
|
||||||
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project bitchat.xcodeproj -scheme bitchat -configuration Debug -sdk iphonesimulator CODE_SIGNING_ALLOWED=NO ONLY_ACTIVE_ARCH=YES
|
|
||||||
|
|
||||||
Build settings from command line:
|
|
||||||
CODE_SIGNING_ALLOWED = NO
|
|
||||||
ONLY_ACTIVE_ARCH = YES
|
|
||||||
SDKROOT = iphonesimulator18.5
|
|
||||||
|
|
||||||
Resolve Package Graph
|
|
||||||
/Users/jack/Library/org.swift.swiftpm/configuration is not accessible or not writable, disabling user-level cache features./Users/jack/Library/org.swift.swiftpm/security is not accessible or not writable, disabling user-level cache features./Users/jack/Library/Caches/org.swift.swiftpm is not accessible or not writable, disabling user-level cache features.
|
|
||||||
Package: swift-secp256k1
|
|
||||||
|
|
||||||
fatalError
|
|
||||||
@@ -0,0 +1,293 @@
|
|||||||
|
Relay URL,Latitude,Longitude
|
||||||
|
relay.damus.io,37.7621,-122.3971
|
||||||
|
nostr-pub.wellorder.net,45.5229,-122.9898
|
||||||
|
nostr.mom,50.4779,12.3713
|
||||||
|
nostr.slothy.win,37.7621,-122.3971
|
||||||
|
nostr.einundzwanzig.space,50.1155,8.6842
|
||||||
|
nos.lol,50.4779,12.3713
|
||||||
|
relay.nostr.band,60.1695,24.9354
|
||||||
|
no.str.cr,9.9339,-84.0849
|
||||||
|
nostr.massmux.com,50.1155,8.6842
|
||||||
|
nostr-relay.schnitzel.world,39.0437,-77.4875
|
||||||
|
relay.nostr.com.au,37.7621,-122.3971
|
||||||
|
knostr.neutrine.com,48.8534,2.3488
|
||||||
|
nostr.nodeofsven.com,47.4875,8.2965
|
||||||
|
nostr.vulpem.com,49.4542,11.0775
|
||||||
|
nostr-verif.slothy.win,37.7621,-122.3971
|
||||||
|
relay.lexingtonbitcoin.org,37.7621,-122.3971
|
||||||
|
nostr-1.nbo.angani.co,-1.2615,36.7903
|
||||||
|
relay.wellorder.net,45.5229,-122.9898
|
||||||
|
nostr.easydns.ca,43.7064,-79.3986
|
||||||
|
relay.dwadziesciajeden.pl,52.2298,21.0118
|
||||||
|
nostr.data.haus,50.4779,12.3713
|
||||||
|
nostr.einundzwanzig.space,50.1155,8.6842
|
||||||
|
nostr.mom,50.4779,12.3713
|
||||||
|
nos.lol,50.4779,12.3713
|
||||||
|
relay.nostr.band,60.1695,24.9354
|
||||||
|
nostr.massmux.com,50.1155,8.6842
|
||||||
|
nostr.vulpem.com,49.4542,11.0775
|
||||||
|
relay.damus.io,37.7621,-122.3971
|
||||||
|
nostr-pub.wellorder.net,45.5229,-122.9898
|
||||||
|
no.str.cr,9.9339,-84.0849
|
||||||
|
relay.dwadziesciajeden.pl,52.2298,21.0118
|
||||||
|
nostr.data.haus,50.4779,12.3713
|
||||||
|
relay.wellorder.net,45.5229,-122.9898
|
||||||
|
relay.nostromo.social,49.4542,11.0775
|
||||||
|
offchain.pub,34.0522,-118.2437
|
||||||
|
relay.nostr.wirednet.jp,35.9356,139.3044
|
||||||
|
relay.nostrcheck.me,37.7621,-122.3971
|
||||||
|
nostrue.com,40.8043,-74.0121
|
||||||
|
nostr-relay.schnitzel.world,39.0437,-77.4875
|
||||||
|
nproxy.kristapsk.lv,60.1695,24.9354
|
||||||
|
nostr.spaceshell.xyz,37.7621,-122.3971
|
||||||
|
nostr-dev.wellorder.net,45.5229,-122.9898
|
||||||
|
nostr-verified.wellorder.net,45.5229,-122.9898
|
||||||
|
nostr.roundrockbitcoiners.com,40.8043,-74.0121
|
||||||
|
slick.mjex.me,39.0437,-77.4875
|
||||||
|
nostr.yael.at,52.3740,4.8897
|
||||||
|
relay.primal.net,37.7621,-122.3971
|
||||||
|
nostr.oxtr.dev,50.4779,12.3713
|
||||||
|
nostr.21crypto.ch,46.5160,6.6328
|
||||||
|
nostr.liberty.fans,38.8003,-90.6265
|
||||||
|
nostr-02.dorafactory.org,1.2897,103.8501
|
||||||
|
relay.hodl.ar,-32.9468,-60.6393
|
||||||
|
nostr.middling.mydns.jp,35.8089,140.1185
|
||||||
|
nostr.namek.link,37.7621,-122.3971
|
||||||
|
nostrja-kari.heguro.com,37.7621,-122.3971
|
||||||
|
nostr.hifish.org,47.3667,8.5500
|
||||||
|
nostr.rikmeijer.nl,50.4779,12.3713
|
||||||
|
black.nostrcity.club,41.8119,-87.6873
|
||||||
|
nostr.hekster.org,37.3924,-121.9623
|
||||||
|
relay.wavlake.com,41.2619,-95.8608
|
||||||
|
nostr.sagaciousd.com,49.2497,-123.1193
|
||||||
|
nostr.fbxl.net,43.7064,-79.3986
|
||||||
|
ithurtswhenip.ee,50.7990,-1.0913
|
||||||
|
relay2.nostrchat.io,49.4542,11.0775
|
||||||
|
relay1.nostrchat.io,60.1695,24.9354
|
||||||
|
nostr-01.yakihonne.com,1.3215,103.6957
|
||||||
|
nostr.sathoarder.com,48.5839,7.7455
|
||||||
|
nostr.overmind.lol,37.7621,-122.3971
|
||||||
|
relay.verified-nostr.com,37.7621,-122.3971
|
||||||
|
purplerelay.com,50.1155,8.6842
|
||||||
|
relay.orangepill.ovh,49.0127,1.9694
|
||||||
|
nostr-relay.psfoundation.info,39.0437,-77.4875
|
||||||
|
soloco.nl,37.7621,-122.3971
|
||||||
|
relay.froth.zone,60.1695,24.9354
|
||||||
|
nostr.stakey.net,52.5250,5.7181
|
||||||
|
nostr.2b9t.xyz,34.0522,-118.2437
|
||||||
|
pyramid.fiatjaf.com,50.1155,8.6842
|
||||||
|
a.nos.lol,50.4779,12.3713
|
||||||
|
relay.magiccity.live,25.8130,-80.2320
|
||||||
|
nostr.notribe.net,40.8344,-74.1377
|
||||||
|
freelay.sovbit.host,64.1355,-21.8954
|
||||||
|
relay.credenso.cafe,43.4254,-80.5112
|
||||||
|
nostr.huszonegy.world,47.4984,19.0404
|
||||||
|
multiplexer.huszonegy.world,47.4984,19.0404
|
||||||
|
bucket.coracle.social,37.7621,-122.3971
|
||||||
|
nostr.kungfu-g.rip,33.7865,-84.4454
|
||||||
|
relay.artx.market,43.7064,-79.3986
|
||||||
|
relay.notoshi.win,13.3622,100.9835
|
||||||
|
vitor.nostr1.com,40.7143,-74.0060
|
||||||
|
nostr-02.yakihonne.com,1.3215,103.6957
|
||||||
|
nostr-03.dorafactory.org,1.2897,103.8501
|
||||||
|
n.ok0.org,-36.8485,174.7635
|
||||||
|
nostr.0x7e.xyz,47.5056,8.7241
|
||||||
|
relay.nostr.net,50.4779,12.3713
|
||||||
|
strfry.openhoofd.nl,51.5717,3.7042
|
||||||
|
relay.fountain.fm,39.0997,-94.5786
|
||||||
|
relay.usefusion.ai,38.7135,-78.1594
|
||||||
|
relay.varke.eu,52.6958,6.1944
|
||||||
|
nostr.satstralia.com,64.1355,-21.8954
|
||||||
|
relay.13room.space,37.7621,-122.3971
|
||||||
|
nostr.myshosholoza.co.za,52.3710,4.9042
|
||||||
|
nostr.carroarmato0.be,50.8517,3.6089
|
||||||
|
nostr.dbtc.link,37.7621,-122.3971
|
||||||
|
orangepiller.org,60.1695,24.9354
|
||||||
|
adre.su,59.9386,30.3141
|
||||||
|
relay.sincensura.org,37.7621,-122.3971
|
||||||
|
relay.freeplace.nl,52.3740,4.8897
|
||||||
|
bostr.bitcointxoko.com,64.1355,-21.8954
|
||||||
|
nostr.plantroon.com,50.1025,8.6299
|
||||||
|
srtrelay.c-stellar.net,37.7621,-122.3971
|
||||||
|
nostr.jfischer.org,49.4453,11.0222
|
||||||
|
nostr.novacisko.cz,52.2298,21.0118
|
||||||
|
relay.lumina.rocks,49.4453,11.0222
|
||||||
|
nostr.tavux.tech,50.9519,1.8563
|
||||||
|
relay.nostrhub.fr,50.1155,8.6842
|
||||||
|
relay.agorist.space,52.3740,4.8897
|
||||||
|
chorus.pjv.me,45.5229,-122.9898
|
||||||
|
relay.cosmicbolt.net,37.3924,-121.9623
|
||||||
|
santo.iguanatech.net,40.8344,-74.1377
|
||||||
|
relay.tagayasu.xyz,45.4112,-75.6981
|
||||||
|
relay.mostro.network,40.8344,-74.1377
|
||||||
|
relay.zone667.com,60.1695,24.9354
|
||||||
|
relay5.bitransfer.org,37.7621,-122.3971
|
||||||
|
relay.illuminodes.com,47.6062,-122.3321
|
||||||
|
relay2.angor.io,50.1155,8.6842
|
||||||
|
relay.satsdays.com,1.2897,103.8501
|
||||||
|
relay.angor.io,50.1155,8.6842
|
||||||
|
orangesync.tech,50.9333,6.9500
|
||||||
|
nostr-relay.cbrx.io,37.7621,-122.3971
|
||||||
|
relay.21e6.cz,50.0880,14.4208
|
||||||
|
nostr.chaima.info,50.1155,8.6842
|
||||||
|
relay.satlantis.io,32.8546,-79.9748
|
||||||
|
relay.digitalezukunft.cyou,45.5088,-73.5878
|
||||||
|
relay.tapestry.ninja,40.8043,-74.0121
|
||||||
|
relay.minibolt.info,37.7621,-122.3971
|
||||||
|
nostr.bilthon.dev,25.8130,-80.2320
|
||||||
|
nostr.makibisskey.work,37.7621,-122.3971
|
||||||
|
relay.mattybs.lol,37.7621,-122.3971
|
||||||
|
noxir.kpherox.dev,34.8436,135.5084
|
||||||
|
sendit.nosflare.com,37.7621,-122.3971
|
||||||
|
relay.coinos.io,37.7621,-122.3971
|
||||||
|
relay.nostraddress.com,37.7621,-122.3971
|
||||||
|
wot.nostr.party,36.1659,-86.7844
|
||||||
|
nostrelites.org,41.8500,-87.6500
|
||||||
|
relay.nostriot.com,43.7064,-79.3986
|
||||||
|
prl.plus,55.7522,37.6156
|
||||||
|
zap.watch,45.5088,-73.5878
|
||||||
|
wot.codingarena.top,50.4779,12.3713
|
||||||
|
nostr.azzamo.net,52.2284,21.0522
|
||||||
|
wot.sudocarlos.com,43.7064,-79.3986
|
||||||
|
relay.lnfi.network,45.6241,8.7851
|
||||||
|
wot.nostr.net,37.7621,-122.3971
|
||||||
|
relay.nostrdice.com,-33.8678,151.2073
|
||||||
|
wot.sebastix.social,51.3700,6.1681
|
||||||
|
wheat.happytavern.co,37.7621,-122.3971
|
||||||
|
relay.sigit.io,50.4779,12.3713
|
||||||
|
strfry.bonsai.com,37.8716,-122.2728
|
||||||
|
travis-shears-nostr-relay-v2.fly.dev,41.8119,-87.6873
|
||||||
|
satsage.xyz,37.3924,-121.9623
|
||||||
|
relay.degmods.com,50.4779,12.3713
|
||||||
|
nostr.community.ath.cx,45.5088,-73.5878
|
||||||
|
nostr.coincrowd.fund,39.0437,-77.4875
|
||||||
|
strfry.shock.network,41.8847,-88.2040
|
||||||
|
cyberspace.nostr1.com,40.7143,-74.0060
|
||||||
|
relay02.lnfi.network,39.0997,-94.5786
|
||||||
|
nostr-rs-relay.dev.fedibtc.com,39.0437,-77.4875
|
||||||
|
relay.davidebtc.me,50.1155,8.6842
|
||||||
|
wot.dtonon.com,37.7621,-122.3971
|
||||||
|
relay.goodmorningbitcoin.com,37.7621,-122.3971
|
||||||
|
articles.layer3.news,37.3394,-121.8950
|
||||||
|
bostr.syobon.net,37.7621,-122.3971
|
||||||
|
nostr.agentcampfire.com,52.3740,4.8897
|
||||||
|
nostr.thebiglake.org,32.7244,-96.6755
|
||||||
|
schnorr.me,37.7621,-122.3971
|
||||||
|
relay.wolfcoil.com,35.6090,139.7302
|
||||||
|
nostr.camalolo.com,24.1469,120.6839
|
||||||
|
nostr.tac.lol,47.4740,-122.2610
|
||||||
|
dev-relay.lnfi.network,39.0997,-94.5786
|
||||||
|
relay.bitcoinveneto.org,64.1355,-21.8954
|
||||||
|
nostr.red5d.dev,37.7621,-122.3971
|
||||||
|
relay-testnet.k8s.layer3.news,37.3394,-121.8950
|
||||||
|
promenade.fiatjaf.com,50.1155,8.6842
|
||||||
|
nostrelay.memory-art.xyz,37.7621,-122.3971
|
||||||
|
inbox.azzamo.net,52.2284,21.0522
|
||||||
|
social.proxymana.net,60.1695,24.9354
|
||||||
|
relay.netstr.io,53.3331,-6.2489
|
||||||
|
premium.primal.net,37.7621,-122.3971
|
||||||
|
nostr.lojong.info,37.7621,-122.3971
|
||||||
|
nostr-rs-relay-ishosta.phamthanh.me,37.7621,-122.3971
|
||||||
|
relay.stream.labs.h3.se,59.3294,18.0687
|
||||||
|
tollbooth.stens.dev,51.4566,7.0123
|
||||||
|
relay.chakany.systems,37.7621,-122.3971
|
||||||
|
relay.mwaters.net,50.9519,1.8563
|
||||||
|
nostr-relay.shirogaku.xyz,37.7621,-122.3971
|
||||||
|
kitchen.zap.cooking,37.7621,-122.3971
|
||||||
|
relay.arx-ccn.com,50.4779,12.3713
|
||||||
|
relay.fr13nd5.com,50.1155,8.6842
|
||||||
|
nostr.tegila.com.br,39.0437,-77.4875
|
||||||
|
relay.jeffg.fyi,43.7064,-79.3986
|
||||||
|
relay.bullishbounty.com,37.7621,-122.3971
|
||||||
|
nostr.spicyz.io,37.7621,-122.3971
|
||||||
|
relay04.lnfi.network,39.0997,-94.5786
|
||||||
|
vidono.apps.slidestr.net,48.8534,2.3488
|
||||||
|
relay03.lnfi.network,39.0997,-94.5786
|
||||||
|
communities.nos.social,40.8344,-74.1377
|
||||||
|
relay.evanverma.com,40.8344,-74.1377
|
||||||
|
nostrelay.circum.space,51.4566,7.0123
|
||||||
|
wot.brightbolt.net,47.6928,-116.7850
|
||||||
|
relayrs.notoshi.win,37.7621,-122.3971
|
||||||
|
fenrir-s.notoshi.win,37.7621,-122.3971
|
||||||
|
relay.nsnip.io,60.1695,24.9354
|
||||||
|
x.kojira.io,37.7621,-122.3971
|
||||||
|
relay.hasenpfeffr.com,39.0437,-77.4875
|
||||||
|
relay01.lnfi.network,39.0997,-94.5786
|
||||||
|
nostr.rtvslawenia.com,49.4542,11.0775
|
||||||
|
relay.g1sms.fr,43.9298,2.1480
|
||||||
|
nostr.kalf.org,52.3740,4.8897
|
||||||
|
nostr.rblb.it,37.7621,-122.3971
|
||||||
|
nostr.4rs.nl,49.4453,11.0222
|
||||||
|
relay.vrtmrz.net,37.7621,-122.3971
|
||||||
|
nostr.hoppe-relay.it.com,45.5946,-121.1787
|
||||||
|
relay-rpi.edufeed.org,49.4453,11.0222
|
||||||
|
relay.copylaradio.com,50.7990,-1.0913
|
||||||
|
relay.ru.ac.th,13.7540,100.5014
|
||||||
|
relay.bitcoinartclock.com,50.4779,12.3713
|
||||||
|
wot.downisontheup.ca,47.6062,-122.3321
|
||||||
|
nostr.coincards.com,43.7064,-79.3986
|
||||||
|
relay.etch.social,41.2619,-95.8608
|
||||||
|
relay.mess.ch,47.1345,9.0964
|
||||||
|
relay.holzeis.me,37.7621,-122.3971
|
||||||
|
relay-admin.thaliyal.com,40.8220,-74.4488
|
||||||
|
nostr.thaliyal.com,40.8220,-74.4488
|
||||||
|
strfry.felixzieger.de,50.1025,8.6299
|
||||||
|
nostr.smut.cloud,37.7621,-122.3971
|
||||||
|
r.bitcoinhold.net,37.7621,-122.3971
|
||||||
|
nostr.blankfors.se,60.1695,24.9354
|
||||||
|
portal-relay.pareto.space,49.4453,11.0222
|
||||||
|
relay.getsafebox.app,43.7064,-79.3986
|
||||||
|
relay.anzenkodo.workers.dev,37.7621,-122.3971
|
||||||
|
relay.nostrhub.tech,49.4453,11.0222
|
||||||
|
nostr.prl.plus,52.3740,4.8897
|
||||||
|
nostr-2.21crypto.ch,46.5160,6.6328
|
||||||
|
nostr.zenon.network,40.7143,-74.0060
|
||||||
|
nostr-relay.amethyst.name,35.7721,-78.6386
|
||||||
|
relayone.geektank.ai,17.1210,-61.8433
|
||||||
|
fanfares.nostr1.com,40.7143,-74.0060
|
||||||
|
wot.geektank.ai,17.1210,-61.8433
|
||||||
|
relay-dev.satlantis.io,40.8344,-74.1377
|
||||||
|
relay.siamdev.cc,13.9178,100.4240
|
||||||
|
relay.nosto.re,51.3700,6.1681
|
||||||
|
wot.soundhsa.com,39.0997,-94.5786
|
||||||
|
nostr.n7ekb.net,47.5707,-122.2221
|
||||||
|
relayone.soundhsa.com,39.0997,-94.5786
|
||||||
|
relay.puresignal.news,37.7621,-122.3971
|
||||||
|
relay.nostx.io,37.7621,-122.3971
|
||||||
|
nostr.now,35.6090,139.7302
|
||||||
|
relay.artiostr.ch,37.7621,-122.3971
|
||||||
|
relay.oldenburg.cool,50.1155,8.6842
|
||||||
|
theoutpost.life,64.1355,-21.8954
|
||||||
|
khatru.nostrver.se,51.3700,6.1681
|
||||||
|
relay.wavefunc.live,37.7915,-122.4018
|
||||||
|
nostr-relay.zimage.com,34.0522,-118.2437
|
||||||
|
relay.javi.space,43.4628,11.8807
|
||||||
|
bostr.shop,42.8865,-78.8784
|
||||||
|
relay.letsfo.com,52.2298,21.0118
|
||||||
|
alien.macneilmediagroup.com,37.7621,-122.3971
|
||||||
|
rn1.sotiras.org,37.7621,-122.3971
|
||||||
|
gnostr.com,42.6975,23.3241
|
||||||
|
relay.conduit.market,37.7621,-122.3971
|
||||||
|
relay.hivetalk.org,37.3924,-121.9623
|
||||||
|
nostr.l484.com,30.2960,-97.6396
|
||||||
|
relay.chorus.community,50.1155,8.6842
|
||||||
|
nostr-relay.moe.gift,37.7621,-122.3971
|
||||||
|
relay.nostrcal.com,37.7621,-122.3971
|
||||||
|
temp.iris.to,37.7621,-122.3971
|
||||||
|
librerelay.aaroniumii.com,37.7621,-122.3971
|
||||||
|
nostr-relay-1.trustlessenterprise.com,37.7621,-122.3971
|
||||||
|
relay.barine.co,37.7621,-122.3971
|
||||||
|
nostr.rohoss.com,48.1374,11.5755
|
||||||
|
wot.nostr.place,30.2672,-97.7431
|
||||||
|
relay.utxo.farm,34.7331,135.8183
|
||||||
|
relay.bankless.at,37.7621,-122.3971
|
||||||
|
relay.toastr.net,40.8043,-74.0121
|
||||||
|
nostr.excentered.com,52.5244,13.4105
|
||||||
|
relay.mccormick.cx,52.3740,4.8897
|
||||||
|
relay.cypherflow.ai,48.8534,2.3488
|
||||||
|
relay.laantungir.net,45.3134,-73.8725
|
||||||
|
nostr.veladan.dev,37.7621,-122.3971
|
||||||
|
nostr.tadryanom.me,37.7621,-122.3971
|
||||||
|
nostr-relay.online,37.7621,-122.3971
|
||||||
|
nostr.night7.space,50.4779,12.3713
|
||||||
|
dev-nostr.bityacht.io,25.0531,121.5264
|
||||||
|
Reference in New Issue
Block a user