diff --git a/Sources/NostrSDK/EventCreating.swift b/Sources/NostrSDK/EventCreating.swift index 5074c9a..b7006db 100644 --- a/Sources/NostrSDK/EventCreating.swift +++ b/Sources/NostrSDK/EventCreating.swift @@ -11,4 +11,4 @@ enum EventCreatingError: Error { case invalidInput } -public protocol EventCreating: DirectMessageEncrypting, NIP44v2Encrypting, RelayURLValidating {} +public protocol EventCreating: LegacyDirectMessageEncrypting, NIP44v2Encrypting, RelayURLValidating {} diff --git a/Sources/NostrSDK/EventKind.swift b/Sources/NostrSDK/EventKind.swift index 896aceb..7a61444 100644 --- a/Sources/NostrSDK/EventKind.swift +++ b/Sources/NostrSDK/EventKind.swift @@ -30,8 +30,10 @@ public enum EventKind: RawRepresentable, CaseIterable, Codable, Equatable, Hasha /// This kind of event should have a recipient pubkey tag. /// - /// See [NIP-04 - Direct Messages](https://github.com/nostr-protocol/nips/blob/master/04.md) - case directMessage + /// See [NIP-04 - Encrypted Direct Message](https://github.com/nostr-protocol/nips/blob/master/04.md) + /// > Warning: Deprecated in favor of [NIP-17 - Private Direct Messages](https://github.com/nostr-protocol/nips/blob/master/17.md). + @available(*, deprecated, message: "Deprecated in favor of NIP-17 - Private Direct Messages.") + case legacyEncryptedDirectMessage /// This kind of event indicates that the author requests that the events in the included /// tags should be deleted. @@ -127,7 +129,7 @@ public enum EventKind: RawRepresentable, CaseIterable, Codable, Equatable, Hasha .setMetadata, .textNote, .followList, - .directMessage, + .legacyEncryptedDirectMessage, .deletion, .repost, .reaction, @@ -156,52 +158,52 @@ public enum EventKind: RawRepresentable, CaseIterable, Codable, Equatable, Hasha public var rawValue: RawValue { switch self { - case .setMetadata: return 0 - case .textNote: return 1 - case .followList: return 3 - case .directMessage: return 4 - case .deletion: return 5 - case .repost: return 6 - case .reaction: return 7 - case .seal: return 13 - case .genericRepost: return 16 - case .giftWrap: return 1059 - case .report: return 1984 - case .muteList: return 10000 - case .bookmarksList: return 10003 - case .authentication: return 22242 - case .longformContent: return 30023 - case .dateBasedCalendarEvent: return 31922 - case .timeBasedCalendarEvent: return 31923 - case .calendar: return 31924 - case .calendarEventRSVP: return 31925 - case let .unknown(value): return value + case .setMetadata: return 0 + case .textNote: return 1 + case .followList: return 3 + case .legacyEncryptedDirectMessage: return 4 + case .deletion: return 5 + case .repost: return 6 + case .reaction: return 7 + case .seal: return 13 + case .genericRepost: return 16 + case .giftWrap: return 1059 + case .report: return 1984 + case .muteList: return 10000 + case .bookmarksList: return 10003 + case .authentication: return 22242 + case .longformContent: return 30023 + case .dateBasedCalendarEvent: return 31922 + case .timeBasedCalendarEvent: return 31923 + case .calendar: return 31924 + case .calendarEventRSVP: return 31925 + case let .unknown(value): return value } } /// The ``NostrEvent`` subclass associated with the kind. public var classForKind: NostrEvent.Type { switch self { - case .setMetadata: return SetMetadataEvent.self - case .textNote: return TextNoteEvent.self - case .followList: return FollowListEvent.self - case .directMessage: return DirectMessageEvent.self - case .deletion: return DeletionEvent.self - case .repost: return TextNoteRepostEvent.self - case .reaction: return ReactionEvent.self - case .seal: return SealEvent.self - case .genericRepost: return GenericRepostEvent.self - case .giftWrap: return GiftWrapEvent.self - case .report: return ReportEvent.self - case .muteList: return MuteListEvent.self - case .bookmarksList: return BookmarksListEvent.self - case .authentication: return AuthenticationEvent.self - case .longformContent: return LongformContentEvent.self - case .dateBasedCalendarEvent: return DateBasedCalendarEvent.self - case .timeBasedCalendarEvent: return TimeBasedCalendarEvent.self - case .calendar: return CalendarListEvent.self - case .calendarEventRSVP: return CalendarEventRSVP.self - case .unknown: return NostrEvent.self + case .setMetadata: return SetMetadataEvent.self + case .textNote: return TextNoteEvent.self + case .followList: return FollowListEvent.self + case .legacyEncryptedDirectMessage: return LegacyEncryptedDirectMessageEvent.self + case .deletion: return DeletionEvent.self + case .repost: return TextNoteRepostEvent.self + case .reaction: return ReactionEvent.self + case .seal: return SealEvent.self + case .genericRepost: return GenericRepostEvent.self + case .giftWrap: return GiftWrapEvent.self + case .report: return ReportEvent.self + case .muteList: return MuteListEvent.self + case .bookmarksList: return BookmarksListEvent.self + case .authentication: return AuthenticationEvent.self + case .longformContent: return LongformContentEvent.self + case .dateBasedCalendarEvent: return DateBasedCalendarEvent.self + case .timeBasedCalendarEvent: return TimeBasedCalendarEvent.self + case .calendar: return CalendarListEvent.self + case .calendarEventRSVP: return CalendarEventRSVP.self + case .unknown: return NostrEvent.self } } diff --git a/Sources/NostrSDK/Events/BookmarksListEvent.swift b/Sources/NostrSDK/Events/BookmarksListEvent.swift index a8c00d0..a308c88 100644 --- a/Sources/NostrSDK/Events/BookmarksListEvent.swift +++ b/Sources/NostrSDK/Events/BookmarksListEvent.swift @@ -141,9 +141,9 @@ public extension EventCreating { let rawPrivateTags = privateTags.map { $0.raw } if let unencryptedData = try? JSONSerialization.data(withJSONObject: rawPrivateTags), let unencryptedContent = String(data: unencryptedData, encoding: .utf8) { - encryptedContent = try encrypt(content: unencryptedContent, - privateKey: keypair.privateKey, - publicKey: keypair.publicKey) + encryptedContent = try legacyEncrypt(content: unencryptedContent, + privateKey: keypair.privateKey, + publicKey: keypair.publicKey) } } diff --git a/Sources/NostrSDK/Events/DirectMessageEvent.swift b/Sources/NostrSDK/Events/DirectMessageEvent.swift deleted file mode 100644 index b29c7fe..0000000 --- a/Sources/NostrSDK/Events/DirectMessageEvent.swift +++ /dev/null @@ -1,60 +0,0 @@ -// -// DirectMessageEvent.swift -// -// -// Created by Joel Klabo on 8/10/23. -// - -import Foundation - -/// An event that contains an encrypted message. -/// -/// > Note: [NIP-04 Specification](https://github.com/nostr-protocol/nips/blob/master/04.md) -public final class DirectMessageEvent: NostrEvent, DirectMessageEncrypting { - - public required init(from decoder: Decoder) throws { - try super.init(from: decoder) - } - - @available(*, unavailable, message: "This initializer is unavailable for this class.") - override init(kind: EventKind, content: String, tags: [Tag] = [], createdAt: Int64 = Int64(Date.now.timeIntervalSince1970), signedBy keypair: Keypair) throws { - try super.init(kind: kind, content: content, tags: tags, createdAt: createdAt, signedBy: keypair) - } - - init(content: String, tags: [Tag] = [], createdAt: Int64 = Int64(Date.now.timeIntervalSince1970), signedBy keypair: Keypair) throws { - try super.init(kind: .directMessage, content: content, tags: tags, createdAt: createdAt, signedBy: keypair) - } - - /// Returns decrypted content from Event given a `privateKey` - public func decryptedContent(using privateKey: PrivateKey) throws -> String { - let recipient = tags.first { tag in - tag.name == TagName.pubkey.rawValue - } - - guard let recipientPublicKeyHex = recipient?.value, let recipientPublicKey = PublicKey(hex: recipientPublicKeyHex) else { - throw DirectMessageEncryptingError.pubkeyInvalid - } - - return try decrypt(encryptedContent: content, privateKey: privateKey, publicKey: recipientPublicKey) - } -} - -public extension EventCreating { - - /// Creates a ``DirectMessageEvent`` (kind 4) and signs it with the provided ``Keypair``. - /// - Parameters: - /// - content: The content of the text note. - /// - toRecipient: The PublicKey of the recipient. - /// - keypair: The Keypair to sign with. - /// - Returns: The signed ``DirectMessageEvent``. - /// - /// See [NIP-04 - Direct Message](https://github.com/nostr-protocol/nips/blob/master/04.md) - func directMessage(withContent content: String, toRecipient pubkey: PublicKey, signedBy keypair: Keypair) throws -> DirectMessageEvent { - guard let encryptedMessage = try? encrypt(content: content, privateKey: keypair.privateKey, publicKey: pubkey) else { - throw EventCreatingError.invalidInput - } - - let recipientTag = Tag.pubkey(pubkey.hex) - return try DirectMessageEvent(content: encryptedMessage, tags: [recipientTag], signedBy: keypair) - } -} diff --git a/Sources/NostrSDK/Events/LegacyEncryptedDirectMessageEvent.swift b/Sources/NostrSDK/Events/LegacyEncryptedDirectMessageEvent.swift new file mode 100644 index 0000000..e6587d6 --- /dev/null +++ b/Sources/NostrSDK/Events/LegacyEncryptedDirectMessageEvent.swift @@ -0,0 +1,64 @@ +// +// LegacyEncryptedDirectMessageEvent.swift +// +// +// Created by Joel Klabo on 8/10/23. +// + +import Foundation + +/// An event that contains an encrypted message. +/// +/// > Note: [NIP-04 - Encrypted Direct Message](https://github.com/nostr-protocol/nips/blob/master/04.md) +/// > Warning: Deprecated in favor of [NIP-17 - Private Direct Messages](https://github.com/nostr-protocol/nips/blob/master/17.md). +@available(*, deprecated, message: "Deprecated in favor of NIP-17 - Private Direct Messages.") +public final class LegacyEncryptedDirectMessageEvent: NostrEvent, LegacyDirectMessageEncrypting { + + public required init(from decoder: Decoder) throws { + try super.init(from: decoder) + } + + @available(*, unavailable, message: "This initializer is unavailable for this class.") + override init(kind: EventKind, content: String, tags: [Tag] = [], createdAt: Int64 = Int64(Date.now.timeIntervalSince1970), signedBy keypair: Keypair) throws { + try super.init(kind: kind, content: content, tags: tags, createdAt: createdAt, signedBy: keypair) + } + + init(content: String, tags: [Tag] = [], createdAt: Int64 = Int64(Date.now.timeIntervalSince1970), signedBy keypair: Keypair) throws { + try super.init(kind: .legacyEncryptedDirectMessage, content: content, tags: tags, createdAt: createdAt, signedBy: keypair) + } + + /// Returns decrypted content from Event given a `privateKey` + public func decryptedContent(using privateKey: PrivateKey) throws -> String { + let recipient = tags.first { tag in + tag.name == TagName.pubkey.rawValue + } + + guard let recipientPublicKeyHex = recipient?.value, let recipientPublicKey = PublicKey(hex: recipientPublicKeyHex) else { + throw LegacyDirectMessageEncryptingError.pubkeyInvalid + } + + return try legacyDecrypt(encryptedContent: content, privateKey: privateKey, publicKey: recipientPublicKey) + } +} + +public extension EventCreating { + + /// Creates a ``LegacyEncryptedDirectMessageEvent`` (kind 4) and signs it with the provided ``Keypair``. + /// - Parameters: + /// - content: The content of the text note. + /// - toRecipient: The PublicKey of the recipient. + /// - keypair: The Keypair to sign with. + /// - Returns: The signed ``LegacyEncryptedDirectMessageEvent``. + /// + /// See [NIP-04 - Encrypted Direct Message](https://github.com/nostr-protocol/nips/blob/master/04.md) + /// > Warning: Deprecated in favor of [NIP-17 - Private Direct Messages](https://github.com/nostr-protocol/nips/blob/master/17.md). + @available(*, deprecated, message: "Deprecated in favor of NIP-17 - Private Direct Messages.") + func legacyEncryptedDirectMessage(withContent content: String, toRecipient pubkey: PublicKey, signedBy keypair: Keypair) throws -> LegacyEncryptedDirectMessageEvent { + guard let encryptedMessage = try? legacyEncrypt(content: content, privateKey: keypair.privateKey, publicKey: pubkey) else { + throw EventCreatingError.invalidInput + } + + let recipientTag = Tag.pubkey(pubkey.hex) + return try LegacyEncryptedDirectMessageEvent(content: encryptedMessage, tags: [recipientTag], signedBy: keypair) + } +} diff --git a/Sources/NostrSDK/Events/MuteListEvent.swift b/Sources/NostrSDK/Events/MuteListEvent.swift index 8ba03c8..20cd2b7 100644 --- a/Sources/NostrSDK/Events/MuteListEvent.swift +++ b/Sources/NostrSDK/Events/MuteListEvent.swift @@ -100,9 +100,9 @@ public extension EventCreating { let rawPrivateTags = privateTags.map { $0.raw } if let unencryptedData = try? JSONSerialization.data(withJSONObject: rawPrivateTags), let unencryptedContent = String(data: unencryptedData, encoding: .utf8) { - encryptedContent = try encrypt(content: unencryptedContent, - privateKey: keypair.privateKey, - publicKey: keypair.publicKey) + encryptedContent = try legacyEncrypt(content: unencryptedContent, + privateKey: keypair.privateKey, + publicKey: keypair.publicKey) } } diff --git a/Sources/NostrSDK/Events/Tags/PrivateTagInterpreting.swift b/Sources/NostrSDK/Events/Tags/PrivateTagInterpreting.swift index 02abd6d..b4bd5cf 100644 --- a/Sources/NostrSDK/Events/Tags/PrivateTagInterpreting.swift +++ b/Sources/NostrSDK/Events/Tags/PrivateTagInterpreting.swift @@ -7,7 +7,7 @@ import Foundation -public protocol PrivateTagInterpreting: DirectMessageEncrypting {} +public protocol PrivateTagInterpreting: LegacyDirectMessageEncrypting {} public extension PrivateTagInterpreting { /// The private tags encrypted in the content of the event. @@ -16,7 +16,7 @@ public extension PrivateTagInterpreting { /// - Parameter keypair: The keypair to use to decrypt the content. /// - Returns: The private tags. func privateTags(from content: String, withName tagName: TagName? = nil, using keypair: Keypair) -> [Tag] { - guard let decryptedContent = try? decrypt(encryptedContent: content, privateKey: keypair.privateKey, publicKey: keypair.publicKey), + guard let decryptedContent = try? legacyDecrypt(encryptedContent: content, privateKey: keypair.privateKey, publicKey: keypair.publicKey), let jsonData = decryptedContent.data(using: .utf8) else { return [] } diff --git a/Sources/NostrSDK/DirectMessageEncrypting.swift b/Sources/NostrSDK/LegacyDirectMessageEncrypting.swift similarity index 79% rename from Sources/NostrSDK/DirectMessageEncrypting.swift rename to Sources/NostrSDK/LegacyDirectMessageEncrypting.swift index eaf1972..79f9eb9 100644 --- a/Sources/NostrSDK/DirectMessageEncrypting.swift +++ b/Sources/NostrSDK/LegacyDirectMessageEncrypting.swift @@ -1,6 +1,6 @@ // -// DirectMessageEncrypting.swift -// +// LegacyDirectMessageEncrypting.swift +// // // Created by Joel Klabo on 8/10/23. // @@ -10,7 +10,7 @@ import secp256k1 import CommonCrypto import CryptoKit -public enum DirectMessageEncryptingError: Error { +public enum LegacyDirectMessageEncryptingError: Error { case pubkeyInvalid case unsuccessfulExponentiation case encryptionError @@ -18,8 +18,8 @@ public enum DirectMessageEncryptingError: Error { case missingValue } -public protocol DirectMessageEncrypting {} -public extension DirectMessageEncrypting { +public protocol LegacyDirectMessageEncrypting {} +public extension LegacyDirectMessageEncrypting { /// Produces a `String` containing `content` that has been encrypted using a sender's `privateKey` and a recipient's `publicKey`. /// This function can `throw` in the case of a failure to create a shared secret, a failure to successfully encrypt, or an invalid `publicKey`. @@ -29,14 +29,16 @@ public extension DirectMessageEncrypting { /// - privateKey: The private key of the sender. /// - publicKey: The public key of the intended recipient. /// - Returns: Encrypted content. - func encrypt(content: String, privateKey: PrivateKey, publicKey: PublicKey) throws -> String { + /// > Warning: Deprecated in favor of [NIP-44](https://github.com/nostr-protocol/nips/blob/master/44.md) encryption and [NIP-59](https://github.com/nostr-protocol/nips/blob/master/59.md) seals and gift wraps.. + @available(*, deprecated, message: "Deprecated in favor of NIP-44 encryption and NIP-59 seals and gift wraps.") + func legacyEncrypt(content: String, privateKey: PrivateKey, publicKey: PublicKey) throws -> String { let sharedSecret = try getSharedSecret(privateKey: privateKey, recipient: publicKey) let iv = Data.randomBytes(count: 16).bytes let utf8Content = Data(content.utf8).bytes guard let encryptedMessage = AESEncrypt(data: utf8Content, iv: iv, sharedSecret: sharedSecret) else { - throw DirectMessageEncryptingError.encryptionError + throw LegacyDirectMessageEncryptingError.encryptionError } return encodeDMBase64(content: encryptedMessage.bytes, iv: iv) @@ -50,7 +52,9 @@ public extension DirectMessageEncrypting { /// - privateKey: The private key of the receiver. /// - publicKey: The public key of the sender. /// - Returns: The un-encrypted message. - func decrypt(encryptedContent message: String, privateKey: PrivateKey, publicKey: PublicKey) throws -> String { + /// > Warning: Deprecated in favor of [NIP-44](https://github.com/nostr-protocol/nips/blob/master/44.md) encryption and [NIP-59](https://github.com/nostr-protocol/nips/blob/master/59.md) seals and gift wraps.. + @available(*, deprecated, message: "Deprecated in favor of NIP-44 encryption and NIP-59 seals and gift wraps.") + func legacyDecrypt(encryptedContent message: String, privateKey: PrivateKey, publicKey: PublicKey) throws -> String { guard let sharedSecret = try? getSharedSecret(privateKey: privateKey, recipient: publicKey) else { throw EventCreatingError.invalidInput } @@ -58,16 +62,16 @@ public extension DirectMessageEncrypting { let sections = Array(message.split(separator: "?")) if sections.count != 2 { - throw DirectMessageEncryptingError.decryptionError + throw LegacyDirectMessageEncryptingError.decryptionError } guard let encryptedContent = sections.first, let encryptedContentData = Data(base64Encoded: String(encryptedContent)) else { - throw DirectMessageEncryptingError.decryptionError + throw LegacyDirectMessageEncryptingError.decryptionError } guard let ivContent = sections.last else { - throw DirectMessageEncryptingError.decryptionError + throw LegacyDirectMessageEncryptingError.decryptionError } let ivContentTrimmed = ivContent.dropFirst(3) @@ -75,7 +79,7 @@ public extension DirectMessageEncrypting { guard let ivContentData = Data(base64Encoded: String(ivContentTrimmed)), let decryptedContentData = AESDecrypt(data: encryptedContentData.bytes, iv: ivContentData.bytes, sharedSecret: sharedSecret), let decryptedMessage = String(data: decryptedContentData, encoding: .utf8) else { - throw DirectMessageEncryptingError.decryptionError + throw LegacyDirectMessageEncryptingError.decryptionError } return decryptedMessage @@ -98,7 +102,7 @@ public extension DirectMessageEncrypting { private func parsePublicKey(from bytes: [UInt8]) throws -> secp256k1_pubkey { var recipientPublicKey = secp256k1_pubkey() guard secp256k1_ec_pubkey_parse(secp256k1.Context.rawRepresentation, &recipientPublicKey, bytes, bytes.count) != 0 else { - throw DirectMessageEncryptingError.pubkeyInvalid + throw LegacyDirectMessageEncryptingError.pubkeyInvalid } return recipientPublicKey } @@ -110,7 +114,7 @@ public extension DirectMessageEncrypting { memcpy(output, x32, 32) return 1 }, nil) != 0 else { - throw DirectMessageEncryptingError.unsuccessfulExponentiation + throw LegacyDirectMessageEncryptingError.unsuccessfulExponentiation } return sharedSecret } diff --git a/Tests/NostrSDKTests/Events/DirectMessageEventTests.swift b/Tests/NostrSDKTests/Events/LegacyEncryptedDirectMessageEventTests.swift similarity index 68% rename from Tests/NostrSDKTests/Events/DirectMessageEventTests.swift rename to Tests/NostrSDKTests/Events/LegacyEncryptedDirectMessageEventTests.swift index b12ec73..8c21cf3 100644 --- a/Tests/NostrSDKTests/Events/DirectMessageEventTests.swift +++ b/Tests/NostrSDKTests/Events/LegacyEncryptedDirectMessageEventTests.swift @@ -1,6 +1,6 @@ // -// DirectMessageEventTests.swift -// +// LegacyEncryptedDirectMessageEventTests.swift +// // // Created by Terry Yiu on 4/14/24. // @@ -8,14 +8,14 @@ @testable import NostrSDK import XCTest -final class DirectMessageEventTests: XCTestCase, EventCreating, EventVerifying, FixtureLoading { +final class LegacyEncryptedDirectMessageEventTests: XCTestCase, EventCreating, EventVerifying, FixtureLoading { - func testCreateDirectMessageEvent() throws { + func testCreateLegacyEncryptedDirectMessageEvent() throws { let content = "Secret message." let recipientPubKey = Keypair.test.publicKey let recipientTag = Tag.pubkey(recipientPubKey.hex) - let event = try directMessage(withContent: content, toRecipient: recipientPubKey, signedBy: Keypair.test) + let event = try legacyEncryptedDirectMessage(withContent: content, toRecipient: recipientPubKey, signedBy: Keypair.test) // Content should contain "?iv=" if encrypted XCTAssert(event.content.contains("?iv=")) @@ -30,14 +30,14 @@ final class DirectMessageEventTests: XCTestCase, EventCreating, EventVerifying, try verifyEvent(event) } - func testDecodeDirectMessage() throws { - let event: DirectMessageEvent = try decodeFixture(filename: "dm") + func testDecodeLegacyEncryptedDirectMessage() throws { + let event: LegacyEncryptedDirectMessageEvent = try decodeFixture(filename: "legacy_encrypted_direct_message") XCTAssertEqual(event.content, "+0V/p6oNtFXAlWVzDTx6wg==?iv=L6gDJ8ei4k1t3lUNgYAahw==") XCTAssertEqual(event.id, "a606649e4995a12226902bd38573c21b04732c0835e415d09be6fbe93879b666") XCTAssertEqual(event.pubkey, "9947f9659dd80c3682402b612f5447e28249997fb3709500c32a585eb0977340") XCTAssertEqual(event.createdAt, 1691768179) - XCTAssertEqual(event.kind, .directMessage) + XCTAssertEqual(event.kind, .legacyEncryptedDirectMessage) let expectedTags: [Tag] = [ .pubkey("9947f9659dd80c3682402b612f5447e28249997fb3709500c32a585eb0977340") diff --git a/Tests/NostrSDKTests/Fixtures/dm.json b/Tests/NostrSDKTests/Fixtures/legacy_encrypted_direct_message.json similarity index 100% rename from Tests/NostrSDKTests/Fixtures/dm.json rename to Tests/NostrSDKTests/Fixtures/legacy_encrypted_direct_message.json diff --git a/demo/NostrSDKDemo.xcodeproj/project.pbxproj b/demo/NostrSDKDemo.xcodeproj/project.pbxproj index 0ef1154..a8ff5f5 100644 --- a/demo/NostrSDKDemo.xcodeproj/project.pbxproj +++ b/demo/NostrSDKDemo.xcodeproj/project.pbxproj @@ -11,7 +11,7 @@ 50BB70A12B4302F300EDD3B5 /* RelaysView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50BB70A02B4302F300EDD3B5 /* RelaysView.swift */; }; F78221C12A87FB39008D5AE8 /* ConnectRelayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78221C02A87FB39008D5AE8 /* ConnectRelayView.swift */; }; F78221C42A8803F3008D5AE8 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78221C32A8803F3008D5AE8 /* Helpers.swift */; }; - F78221C62A898063008D5AE8 /* DirectMessageDemoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78221C52A898063008D5AE8 /* DirectMessageDemoView.swift */; }; + F78221C62A898063008D5AE8 /* NIP04DirectMessageDemoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78221C52A898063008D5AE8 /* NIP04DirectMessageDemoView.swift */; }; F78221CE2A8999F9008D5AE8 /* KeyInputSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78221CD2A8999F9008D5AE8 /* KeyInputSectionView.swift */; }; F786D8F72A3BAED800A29915 /* QueryRelayDemoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F786D8F62A3BAED800A29915 /* QueryRelayDemoView.swift */; }; F7CB362C2A35127B0098F35C /* NostrSDKDemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CB362B2A35127B0098F35C /* NostrSDKDemoApp.swift */; }; @@ -27,7 +27,7 @@ 50BB70A02B4302F300EDD3B5 /* RelaysView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelaysView.swift; sourceTree = ""; }; F78221C02A87FB39008D5AE8 /* ConnectRelayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectRelayView.swift; sourceTree = ""; }; F78221C32A8803F3008D5AE8 /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = ""; }; - F78221C52A898063008D5AE8 /* DirectMessageDemoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectMessageDemoView.swift; sourceTree = ""; }; + F78221C52A898063008D5AE8 /* NIP04DirectMessageDemoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NIP04DirectMessageDemoView.swift; sourceTree = ""; }; F78221CD2A8999F9008D5AE8 /* KeyInputSectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyInputSectionView.swift; sourceTree = ""; }; F786D8F62A3BAED800A29915 /* QueryRelayDemoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryRelayDemoView.swift; sourceTree = ""; }; F7CB36282A35127B0098F35C /* NostrSDKDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NostrSDKDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -55,10 +55,10 @@ F78221BC2A87EF6C008D5AE8 /* Demo Views */ = { isa = PBXGroup; children = ( + F78221C52A898063008D5AE8 /* NIP04DirectMessageDemoView.swift */, F7CB36462A3B74380098F35C /* NIP05VerificationDemoView.swift */, F7CB36402A3ACD530098F35C /* GenerateKeyDemoView.swift */, F786D8F62A3BAED800A29915 /* QueryRelayDemoView.swift */, - F78221C52A898063008D5AE8 /* DirectMessageDemoView.swift */, ); path = "Demo Views"; sourceTree = ""; @@ -211,7 +211,7 @@ F78221C12A87FB39008D5AE8 /* ConnectRelayView.swift in Sources */, 50BB70A12B4302F300EDD3B5 /* RelaysView.swift in Sources */, F786D8F72A3BAED800A29915 /* QueryRelayDemoView.swift in Sources */, - F78221C62A898063008D5AE8 /* DirectMessageDemoView.swift in Sources */, + F78221C62A898063008D5AE8 /* NIP04DirectMessageDemoView.swift in Sources */, F78221CE2A8999F9008D5AE8 /* KeyInputSectionView.swift in Sources */, F7CB36412A3ACD530098F35C /* GenerateKeyDemoView.swift in Sources */, F7CB36432A3ACD7B0098F35C /* ListOptionView.swift in Sources */, diff --git a/demo/NostrSDKDemo/ContentView.swift b/demo/NostrSDKDemo/ContentView.swift index 3544ec5..9b248cd 100644 --- a/demo/NostrSDKDemo/ContentView.swift +++ b/demo/NostrSDKDemo/ContentView.swift @@ -23,9 +23,9 @@ struct ContentView: View { imageName: "list.bullet.rectangle.portrait", labelText: "Query Relays") ListOptionView(destinationView: - AnyView(DirectMessageDemoView()), + AnyView(LegacyDirectMessageDemoView()), imageName: "list.bullet", - labelText: "Direct Message") + labelText: "NIP-04 Direct Message") ListOptionView(destinationView: AnyView(GenerateKeyDemoView()), imageName: "key", labelText: "Key Generation") diff --git a/demo/NostrSDKDemo/Demo Views/DirectMessageDemoView.swift b/demo/NostrSDKDemo/Demo Views/LegacyDirectMessageDemoView.swift similarity index 80% rename from demo/NostrSDKDemo/Demo Views/DirectMessageDemoView.swift rename to demo/NostrSDKDemo/Demo Views/LegacyDirectMessageDemoView.swift index dbe7659..8fb2d04 100644 --- a/demo/NostrSDKDemo/Demo Views/DirectMessageDemoView.swift +++ b/demo/NostrSDKDemo/Demo Views/LegacyDirectMessageDemoView.swift @@ -1,5 +1,5 @@ // -// DirectMessageDemoView.swift +// LegacyDirectMessageDemoView.swift // NostrSDKDemo // // Created by Honk on 8/13/23. @@ -8,7 +8,7 @@ import SwiftUI import NostrSDK -struct DirectMessageDemoView: View, EventCreating { +struct LegacyDirectMessageDemoView: View, EventCreating { @EnvironmentObject var relayPool: RelayPool @@ -41,9 +41,9 @@ struct DirectMessageDemoView: View, EventCreating { return } do { - let directMessage = try directMessage(withContent: message, - toRecipient: recipientPublicKey, - signedBy: senderKeyPair) + let directMessage = try legacyEncryptedDirectMessage(withContent: message, + toRecipient: recipientPublicKey, + signedBy: senderKeyPair) relayPool.publishEvent(directMessage) } catch { print(error.localizedDescription) @@ -76,8 +76,8 @@ struct DirectMessageDemoView: View, EventCreating { } } -struct DirectMessageDemoView_Previews: PreviewProvider { +struct LegacyDirectMessageDemoView_Previews: PreviewProvider { static var previews: some View { - DirectMessageDemoView() + LegacyDirectMessageDemoView() } }