commit 53e3f6d86b52a51a84d0744e4b26e7153096e9fe parent c28ab7a57cdffdf7827ad6e3268424238982b0f8 Author: Daniel D’Aquino <daniel@daquino.me> Date: Mon, 24 Mar 2025 19:16:13 -0300 Define protocol NostrEventConvertible This adds a new protocol for classes that can be converted to and from a NostrEvent. Signed-off-by: Daniel D’Aquino <daniel@daquino.me> Diffstat:
M | damus/Nostr/NostrEvent.swift | | | 12 | ++++++++++++ |
1 file changed, 12 insertions(+), 0 deletions(-)
diff --git 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