diff options
author | buttercat1791 <mjjurkoic@gmail.com> | 2024-06-15 00:44:56 -0500 |
---|---|---|
committer | buttercat1791 <mjjurkoic@gmail.com> | 2024-06-15 00:44:56 -0500 |
commit | b3854adaa0af1db6f8f7eecebf63229108608bb4 (patch) | |
tree | b12155a636605d1a80ac19b3f6af026986b35aea /include | |
parent | f50b94bff318c4d9df5ff193c44b65cd3f7ab512 (diff) |
Fill out noscrypt signer sign method
Diffstat (limited to 'include')
-rw-r--r-- | include/signer/noscrypt_signer.hpp | 52 | ||||
-rw-r--r-- | include/signer/signer.hpp | 6 |
2 files changed, 56 insertions, 2 deletions
diff --git a/include/signer/noscrypt_signer.hpp b/include/signer/noscrypt_signer.hpp index 7201c12..de8aab4 100644 --- a/include/signer/noscrypt_signer.hpp +++ b/include/signer/noscrypt_signer.hpp @@ -31,6 +31,10 @@ public: std::shared_ptr<std::promise<bool>> sign(std::shared_ptr<data::Event> event) override; private: + const int _nostrConnectKind = 24133; // Kind 24133 is reserved for NIP-46 events. + + Encryption _nostrConnectEncryption; + std::shared_ptr<NCContext> _noscryptContext; std::shared_ptr<nostr::service::INostrServiceBase> _nostrService; @@ -85,6 +89,29 @@ private: */ std::string _generateSignerRequestId(); + /** + * @brief Builds a wrapper event for JRPC-like signer messages. + * @param jrpc The JRPC-like payload that will comprise the event content, as specified by + * NIP-46. + * @returns A shared pointer to the wrapper event. + */ + std::shared_ptr<nostr::data::Event> _wrapSignerMessage(nlohmann::json jrpc); + + /** + * @brief Unwraps the JRPC-like payload from a signer message, typically one received from the + * remote signer in response to a request. + * @param event An event containing a NIP-46 message payload. + * @returns The unwrapped payload. The returned object will be empty if no valid payload could + * be extracted from the given event. + */ + std::string _unwrapSignerMessage(std::shared_ptr<nostr::data::Event> event); + + /** + * @brief Pings the remote signer to confirm that it is online and available. + * @returns `true` if the signer is available, `false` otherwise. + */ + bool _pingSigner(); + #pragma region Cryptography /** @@ -93,15 +120,36 @@ private: */ void _reseedRandomNumberGenerator(uint32_t bufferSize = 32); - std::string _encryptNip04(); + /** + * @brief Encrypts a string according to the standard specified in NIP-04. + * @param input The string to be encrypted. + * @return The resulting encrypted string, or an empty string if the input could not be + * encrypted. + */ + std::string _encryptNip04(const std::string input); + + /** + * @brief Decrypts a NIP-04 encrypted string. + * @param input The string to be decrypted. + * @return The decrypted string, or an empty string if the input could not be decrypted. + */ + std::string _decryptNip04(const std::string input); /** * @brief Encrypts a string according to the standard specified in NIP-44. * @param input The string to be encrypted. - * @return The encrypted input. + * @return The resulting encrypted string, or an empty string if the input could not be + * encrypted. */ std::string _encryptNip44(const std::string input); // TODO: Return or set HMAC? + /** + * @brief Decrypts a NIP-44 encrypted string. + * @param input The string to be decrypted. + * @return The decrypted string, or an empty string if the input could not be decrypted. + */ + std::string _decryptNip44(const std::string input); + #pragma endregion #pragma region Logging diff --git a/include/signer/signer.hpp b/include/signer/signer.hpp index 0faaff8..10e54c6 100644 --- a/include/signer/signer.hpp +++ b/include/signer/signer.hpp @@ -11,6 +11,12 @@ namespace nostr { namespace signer { +enum class Encryption +{ + NIP04, + NIP44 +}; + /** * @brief An interface for Nostr event signing that implements NIP-46. */ |