mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 20:05:19 +00:00
Tests: gate verbose prints under DEBUG; ChatViewModel: remove legacy fingerprint helper and rely on UnifiedPeerService
This commit is contained in:
@@ -3617,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? {
|
// (legacy getFingerprint_old removed; UnifiedPeerService is the source of truth)
|
||||||
// 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
|
||||||
|
|||||||
@@ -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,9 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user