diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/signer/noscrypt_signer.hpp | 35 | ||||
-rw-r--r-- | include/signer/signer.hpp | 5 |
2 files changed, 34 insertions, 6 deletions
diff --git a/include/signer/noscrypt_signer.hpp b/include/signer/noscrypt_signer.hpp index 606438e..7201c12 100644 --- a/include/signer/noscrypt_signer.hpp +++ b/include/signer/noscrypt_signer.hpp @@ -2,11 +2,7 @@ #include <plog/Init.h> #include <plog/Log.h> - -extern "C" -{ #include <noscrypt.h> -} #include "service/nostr_service_base.hpp" #include "signer/signer.hpp" @@ -32,10 +28,14 @@ public: std::string url, std::string description) override; - void sign(std::shared_ptr<data::Event> event) override; + std::shared_ptr<std::promise<bool>> sign(std::shared_ptr<data::Event> event) override; private: std::shared_ptr<NCContext> _noscryptContext; + std::shared_ptr<nostr::service::INostrServiceBase> _nostrService; + + std::shared_ptr<NCPublicKey> _remotePubkey; // TODO: Set this when available. + std::shared_ptr<NCSecretKey> _localSecret; std::string _localPrivateKey; std::string _localPublicKey; @@ -79,6 +79,31 @@ private: */ void _handleConnectionTokenParam(std::string param); + /** + * @brief Generates a unique ID for a signer request. + * @returns A GUID string. + */ + std::string _generateSignerRequestId(); + + #pragma region Cryptography + + /** + * @brief Reseeds OpenSSL's pseudo-random number generator, using `/dev/random` as the seed, if + * possible. + */ + void _reseedRandomNumberGenerator(uint32_t bufferSize = 32); + + std::string _encryptNip04(); + + /** + * @brief Encrypts a string according to the standard specified in NIP-44. + * @param input The string to be encrypted. + * @return The encrypted input. + */ + std::string _encryptNip44(const std::string input); // TODO: Return or set HMAC? + + #pragma endregion + #pragma region Logging void _logNoscryptInitResult(NCResult initResult); diff --git a/include/signer/signer.hpp b/include/signer/signer.hpp index c774d1d..0faaff8 100644 --- a/include/signer/signer.hpp +++ b/include/signer/signer.hpp @@ -1,5 +1,6 @@ #pragma once +#include <future> #include <memory> #include <string> #include <vector> @@ -21,9 +22,11 @@ public: /** * @brief Signs the given Nostr event. * @param event The event to sign. + * @returns A promise that will be fulfilled when the event has been signed. It will be + * fulfilled with `true` if the signing succeeded, and `false` if it failed. * @remark The event's `sig` field will be updated in-place with the signature. */ - virtual void sign(std::shared_ptr<nostr::data::Event> event) = 0; + virtual std::shared_ptr<std::promise<bool>> sign(std::shared_ptr<nostr::data::Event> event) = 0; }; class INostrConnectSigner : public ISigner |