aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLibravatar Michael Jurkoic <mjjurkoic@gmail.com>2024-03-12 09:32:25 -0500
committerLibravatar Michael Jurkoic <mjjurkoic@gmail.com>2024-03-12 09:32:25 -0500
commit6134935fd0c7adfb097824ea9e57207e3f97423b (patch)
tree076af452ca4214e898b29a0cab48fa005a280890 /include
parenta57db2270f1a841325c47d5113befbb5ca532952 (diff)
Add validation on Event serialization
Diffstat (limited to 'include')
-rw-r--r--include/nostr.hpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/include/nostr.hpp b/include/nostr.hpp
index 47b56f9..ec8d1a8 100644
--- a/include/nostr.hpp
+++ b/include/nostr.hpp
@@ -27,14 +27,32 @@ struct Event
{
std::string id; ///< SHA-256 hash of the event data.
std::string pubkey; ///< Public key of the event creator.
- std::string created_at; ///< Unix timestamp of the event creation.
+ std::time_t createdAt; ///< Unix timestamp of the event creation.
int kind; ///< Event kind.
std::vector<std::vector<std::string>> tags; ///< Arbitrary event metadata.
std::string content; ///< Event content.
std::string sig; ///< Event signature created with the private key of the event creator.
- nlohmann::json serialize() const;
+ /**
+ * @brief Serializes the event to a JSON object.
+ * @returns A stringified JSON object representing the event.
+ * @throws `std::invalid_argument` if the event object is invalid.
+ */
+ std::string serialize();
+
+ /**
+ * @brief Deserializes the event from a JSON string.
+ * @param jsonString A stringified JSON object representing the event.
+ */
void deserialize(std::string jsonString);
+
+private:
+ /**
+ * @brief Validates the event.
+ * @throws `std::invalid_argument` if the event object is invalid.
+ * @remark The `createdAt` field defaults to the present if it is not already set.
+ */
+ void validate();
};
class NostrService