diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj index 8f086bcd..68262250 100644 --- a/damus.xcodeproj/project.pbxproj +++ b/damus.xcodeproj/project.pbxproj @@ -1587,6 +1587,10 @@ D76BE18C2E0CF3DA004AD0C6 /* Interests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D76BE18B2E0CF3D5004AD0C6 /* Interests.swift */; }; D76BE18D2E0CF3DA004AD0C6 /* Interests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D76BE18B2E0CF3D5004AD0C6 /* Interests.swift */; }; D76BE18E2E0CF3DA004AD0C6 /* Interests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D76BE18B2E0CF3D5004AD0C6 /* Interests.swift */; }; + D77135D32E7B766B00E7639F /* DataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77135D22E7B766300E7639F /* DataExtensions.swift */; }; + D77135D42E7B766B00E7639F /* DataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77135D22E7B766300E7639F /* DataExtensions.swift */; }; + D77135D52E7B766B00E7639F /* DataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77135D22E7B766300E7639F /* DataExtensions.swift */; }; + D77135D62E7B78D700E7639F /* DataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77135D22E7B766300E7639F /* DataExtensions.swift */; }; D773BC5F2C6D538500349F0A /* CommentItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D773BC5E2C6D538500349F0A /* CommentItem.swift */; }; D773BC602C6D538500349F0A /* CommentItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D773BC5E2C6D538500349F0A /* CommentItem.swift */; }; D77BFA0B2AE3051200621634 /* ProfileActionSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77BFA0A2AE3051200621634 /* ProfileActionSheetView.swift */; }; @@ -2640,6 +2644,7 @@ D767066E2C8BB3CE00F09726 /* URLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLHandler.swift; sourceTree = ""; }; D76874F22AE3632B00FB0F68 /* ProfileZapLinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileZapLinkView.swift; sourceTree = ""; }; D76BE18B2E0CF3D5004AD0C6 /* Interests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Interests.swift; sourceTree = ""; }; + D77135D22E7B766300E7639F /* DataExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataExtensions.swift; sourceTree = ""; }; D773BC5E2C6D538500349F0A /* CommentItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentItem.swift; sourceTree = ""; }; D77BFA0A2AE3051200621634 /* ProfileActionSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileActionSheetView.swift; sourceTree = ""; }; D783A63E2AD4E53D00658DDA /* SuggestedHashtagsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SuggestedHashtagsView.swift; sourceTree = ""; }; @@ -4661,6 +4666,7 @@ 5C78A7B82E3047DE00CF177D /* Utilities */ = { isa = PBXGroup; children = ( + D77135D22E7B766300E7639F /* DataExtensions.swift */, 4CF0ABEA29844B2F00D66079 /* AnyCodable */, D73B74E02D8365B40067BDBC /* ExtraFonts.swift */, D7DB93042D66A43B00DA1EE5 /* Undistractor.swift */, @@ -5901,6 +5907,7 @@ D7100C5C2B77016700C59298 /* IAPProductStateView.swift in Sources */, 4CB9D4A72992D02B00A9A7E4 /* ProfileNameView.swift in Sources */, D733F9E82D92C76100317B11 /* UnownedNdbNote.swift in Sources */, + D77135D42E7B766B00E7639F /* DataExtensions.swift in Sources */, D74EA0902D2E271E002290DD /* ErrorView.swift in Sources */, 4CE4F0F429D779B5005914DB /* PostBox.swift in Sources */, BA37598E2ABCCE500018D73B /* VideoCaptureProcessor.swift in Sources */, @@ -5987,6 +5994,7 @@ 4C36246F2D5EA16A00DD066E /* str.c in Sources */, 4C36246E2D5EA10400DD066E /* hash_u5.c in Sources */, 4C36246C2D5EA0E500DD066E /* bolt11.c in Sources */, + D77135D52E7B766B00E7639F /* DataExtensions.swift in Sources */, 4C36246B2D5EA0D700DD066E /* invoice.c in Sources */, 4C36246A2D5EA0CB00DD066E /* content_parser.c in Sources */, 4C3624692D5EA0C200DD066E /* list.c in Sources */, @@ -6559,6 +6567,7 @@ D73E5E4F2C6A97F4007EB227 /* WebsiteLink.swift in Sources */, D73E5E502C6A97F4007EB227 /* Highlight.swift in Sources */, D73E5E512C6A97F4007EB227 /* CustomPicker.swift in Sources */, + D77135D32E7B766B00E7639F /* DataExtensions.swift in Sources */, D73E5E522C6A97F4007EB227 /* UserView.swift in Sources */, D73E5E532C6A97F4007EB227 /* ZoomableScrollView.swift in Sources */, D73E5E542C6A97F4007EB227 /* NoteZapButton.swift in Sources */, @@ -7152,6 +7161,7 @@ D798D22D2B086DC400234419 /* NostrEvent.swift in Sources */, D798D22E2B086E4800234419 /* NostrResponse.swift in Sources */, D7EDED162B1177840018B19C /* LNUrls.swift in Sources */, + D77135D62E7B78D700E7639F /* DataExtensions.swift in Sources */, D7CCFC132B05887C00323D86 /* ProofOfWork.swift in Sources */, D7CE1B392B0BE719002EDAD4 /* Table.swift in Sources */, D7CE1B452B0BE719002EDAD4 /* Root.swift in Sources */, diff --git a/damus/Core/NIPs/NIP04/NIP04.swift b/damus/Core/NIPs/NIP04/NIP04.swift index d9ec959e..78702712 100644 --- a/damus/Core/NIPs/NIP04/NIP04.swift +++ b/damus/Core/NIPs/NIP04/NIP04.swift @@ -12,11 +12,11 @@ struct NIP04 {} extension NIP04 { /// Encrypts a message using NIP-04. static func encrypt_message(message: String, privkey: Privkey, to_pk: Pubkey, encoding: EncEncoding = .base64) -> String? { - let iv = random_bytes(count: 16).bytes + let iv = random_bytes(count: 16).byteArray guard let shared_sec = get_shared_secret(privkey: privkey, pubkey: to_pk) else { return nil } - let utf8_message = Data(message.utf8).bytes + let utf8_message = Data(message.utf8).byteArray guard let enc_message = aes_encrypt(data: utf8_message, iv: iv, shared_sec: shared_sec) else { return nil } diff --git a/damus/Core/Nostr/NostrEvent.swift b/damus/Core/Nostr/NostrEvent.swift index d3ea206d..0e6cb3e0 100644 --- a/damus/Core/Nostr/NostrEvent.swift +++ b/damus/Core/Nostr/NostrEvent.swift @@ -321,7 +321,7 @@ func sign_id(privkey: String, id: String) -> String { // Extra params for custom signing - var aux_rand = random_bytes(count: 64).bytes + var aux_rand = random_bytes(count: 64).byteArray var digest = try! id.bytes // API allows for signing variable length messages @@ -786,15 +786,15 @@ func validate_event(ev: NostrEvent) -> ValidationResult { let ctx = secp256k1.Context.raw var xonly_pubkey = secp256k1_xonly_pubkey.init() - var ev_pubkey = ev.pubkey.id.bytes + var ev_pubkey = ev.pubkey.id.byteArray var ok = secp256k1_xonly_pubkey_parse(ctx, &xonly_pubkey, &ev_pubkey) != 0 if !ok { return .bad_sig } - var sig = ev.sig.data.bytes - var idbytes = id.id.bytes + var sig = ev.sig.data.byteArray + var idbytes = id.id.byteArray ok = secp256k1_schnorrsig_verify(ctx, &sig, &idbytes, 32, &xonly_pubkey) > 0 return ok ? .ok : .bad_sig diff --git a/damus/Features/Posting/Models/DraftsModel.swift b/damus/Features/Posting/Models/DraftsModel.swift index b80ae633..074cf69c 100644 --- a/damus/Features/Posting/Models/DraftsModel.swift +++ b/damus/Features/Posting/Models/DraftsModel.swift @@ -6,7 +6,7 @@ // import Foundation -import SwiftUICore +import SwiftUI import UIKit /// Represents artifacts in a post draft, which is rendered by `PostView` diff --git a/damus/Shared/Media/Video/DamusVideoCoordinator.swift b/damus/Shared/Media/Video/DamusVideoCoordinator.swift index d0de60df..3e23948f 100644 --- a/damus/Shared/Media/Video/DamusVideoCoordinator.swift +++ b/damus/Shared/Media/Video/DamusVideoCoordinator.swift @@ -7,7 +7,7 @@ import Combine import Foundation -import SwiftUICore +import SwiftUI import AVFoundation /// DamusVideoCoordinator is responsible for coordinating the various video players throughout the app, and providing a nicely orchestrated experience. diff --git a/damus/Shared/Utilities/DataExtensions.swift b/damus/Shared/Utilities/DataExtensions.swift new file mode 100644 index 00000000..11bc3ced --- /dev/null +++ b/damus/Shared/Utilities/DataExtensions.swift @@ -0,0 +1,17 @@ +// +// DataExtensions.swift +// damus +// +// Created by Daniel D’Aquino on 2025-09-17. +// +import Foundation + +extension Data { + var byteArray: [UInt8] { + var bytesToReturn: [UInt8] = [] + for i in self.bytes.byteOffsets { + bytesToReturn.append(self[i]) + } + return bytesToReturn + } +} diff --git a/damusTests/NIP44v2EncryptionTests.swift b/damusTests/NIP44v2EncryptionTests.swift index 406d35dc..bcb59a0f 100644 --- a/damusTests/NIP44v2EncryptionTests.swift +++ b/damusTests/NIP44v2EncryptionTests.swift @@ -132,7 +132,7 @@ final class NIP44v2EncryptingTests: XCTestCase { try encryptDecryptVectors.forEach { vector in let conversationKey = vector.conversationKey let conversationKeyData = try XCTUnwrap(conversationKey.hexDecoded) - let conversationKeyBytes = conversationKeyData.bytes + let conversationKeyBytes = conversationKeyData.byteArray let nonce = try XCTUnwrap(vector.nonce.hexDecoded) let expectedPlaintextSHA256 = vector.plaintextSHA256 @@ -211,7 +211,7 @@ final class NIP44v2EncryptingTests: XCTestCase { func testInvalidDecrypt() throws { let decryptVectors = try XCTUnwrap(vectors.v2.invalid.decrypt) try decryptVectors.forEach { vector in - let conversationKey = try XCTUnwrap(vector.conversationKey.hexDecoded).bytes + let conversationKey = try XCTUnwrap(vector.conversationKey.hexDecoded).byteArray let payload = vector.payload XCTAssertThrowsError(try NIP44v2Encryption.decrypt(payload: payload, conversationKey: conversationKey), vector.note) } diff --git a/nostrdb/NdbNote.swift b/nostrdb/NdbNote.swift index 2ce94553..1cc11566 100644 --- a/nostrdb/NdbNote.swift +++ b/nostrdb/NdbNote.swift @@ -291,7 +291,7 @@ class NdbNote: Codable, Equatable, Hashable { return nil } case .manual(_, let signature, _): - var raw_sig = signature.data.bytes + var raw_sig = signature.data.byteArray ndb_builder_set_sig(&builder, &raw_sig) do {