From 53e3f6d86b52a51a84d0744e4b26e7153096e9fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Mon, 24 Mar 2025 19:16:13 -0300 Subject: [PATCH] Define protocol NostrEventConvertible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a new protocol for classes that can be converted to and from a NostrEvent. Signed-off-by: Daniel D’Aquino --- damus/Nostr/NostrEvent.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift index bf3f7efd..e402dd95 100644 --- a/damus/Nostr/NostrEvent.swift +++ b/damus/Nostr/NostrEvent.swift @@ -13,6 +13,18 @@ import CryptoKit import NaturalLanguage +/// A protocol for structs and classes that can convert themselves from/to a NostrEvent +protocol NostrEventConvertible { + associatedtype E: Error + + /// Iniitialize this type from a NostrEvent + init(event: NostrEvent) throws(E) + + /// Convert this type into a Nostr Event, using a keypair for signing and a specific timestamp + func toNostrEvent(keypair: FullKeypair, timestamp: UInt32?) -> NostrEvent? +} + + enum ValidationResult: Decodable { case unknown case ok