aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/signer/signer.hpp6
-rw-r--r--src/signer/noscrypt_signer.cpp25
-rw-r--r--test/nostr_service_test.cpp14
3 files changed, 31 insertions, 14 deletions
diff --git a/include/signer/signer.hpp b/include/signer/signer.hpp
index ee2673f..7dccc7c 100644
--- a/include/signer/signer.hpp
+++ b/include/signer/signer.hpp
@@ -1,5 +1,10 @@
#pragma once
+#include <algorithm>
+#include <random>
+
+#include <plog/Init.h>
+
#include "data/data.hpp"
namespace nostr
@@ -22,6 +27,7 @@ public:
class INostrConnectSigner : public ISigner
{
+public:
virtual void receiveConnection(std::string connectionToken) = 0;
virtual void initiateConnection(
diff --git a/src/signer/noscrypt_signer.cpp b/src/signer/noscrypt_signer.cpp
index 4e5fa2a..e53dd57 100644
--- a/src/signer/noscrypt_signer.cpp
+++ b/src/signer/noscrypt_signer.cpp
@@ -11,6 +11,28 @@ namespace signer
class NoscryptSigner : public INostrConnectSigner
{
public:
+ NoscryptSigner(shared_ptr<plog::IAppender> appender)
+ {
+ // Set up the logger.
+ plog::init(plog::debug, appender.get());
+
+ // Set up the noscrypt library.
+ this->context = make_shared<NCContext>();
+ uint8_t randomEntropy[NC_CONTEXT_ENTROPY_SIZE];
+
+ random_device device;
+ mt19937 seed(device());
+ uniform_int_distribution<int> distribution(1, NC_CONTEXT_ENTROPY_SIZE);
+ generate_n(randomEntropy, NC_CONTEXT_ENTROPY_SIZE, [&]() { return distribution(seed); });
+
+ NCInitContext(context.get(), randomEntropy);
+ };
+
+ ~NoscryptSigner()
+ {
+ NCDestroyContext(context.get());
+ };
+
void receiveConnection(string connectionToken) override
{
// Receive the connection token here.
@@ -29,6 +51,9 @@ public:
{
// Sign the event here.
};
+
+private:
+ shared_ptr<NCContext> context;
};
} // namespace signer
} // namespace nostr
diff --git a/test/nostr_service_test.cpp b/test/nostr_service_test.cpp
index 3e951ad..e5375db 100644
--- a/test/nostr_service_test.cpp
+++ b/test/nostr_service_test.cpp
@@ -35,20 +35,6 @@ public:
class FakeSigner : public signer::ISigner
{
public:
- void receiveConnection(string connectionToken) override
- {
- // Do nothing.
- };
-
- void initiateConnection(
- string relay,
- string name,
- string url,
- string description) override
- {
- // Do nothing.
- };
-
void sign(shared_ptr<nostr::data::Event> event) override
{
event->sig = "fake_signature";