aboutsummaryrefslogtreecommitdiff
path: root/include/signer/noscrypt_signer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/signer/noscrypt_signer.hpp')
-rw-r--r--include/signer/noscrypt_signer.hpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/include/signer/noscrypt_signer.hpp b/include/signer/noscrypt_signer.hpp
new file mode 100644
index 0000000..1476303
--- /dev/null
+++ b/include/signer/noscrypt_signer.hpp
@@ -0,0 +1,55 @@
+#pragma once
+
+extern "C"
+{
+#include <noscrypt.h>
+}
+
+#include "signer.hpp"
+
+namespace nostr
+{
+namespace signer
+{
+class NoscryptSigner : public INostrConnectSigner
+{
+public:
+ NoscryptSigner(std::shared_ptr<plog::IAppender> appender);
+
+ ~NoscryptSigner();
+
+ void receiveConnection(std::string connectionToken) override;
+
+ void initiateConnection(
+ std::string relay,
+ std::string name,
+ std::string url,
+ std::string description) override;
+
+ void sign(std::shared_ptr<data::Event> event) override;
+
+private:
+ std::shared_ptr<NCContext> noscryptContext;
+
+ std::string localPrivateKey;
+ std::string localPublicKey;
+
+ /**
+ * @brief Initializes the noscrypt library context into the class's `context` property.
+ * @returns `true` if successful, `false` otherwise.
+ */
+ std::shared_ptr<NCContext> _initNoscryptContext();
+
+ void _logNoscryptResult(NCResult result);
+
+ /**
+ * @brief Generates a private/public key pair for local use.
+ * @returns The generated keypair of the form `[privateKey, publicKey]`, or a pair of empty
+ * strings if the function failed.
+ * @remarks This keypair is intended for temporary use, and should not be saved or used outside
+ * of this class.
+ */
+ std::tuple<std::string, std::string> _createLocalKeypair();
+};
+} // namespace signer
+} // namespace nostr