aboutsummaryrefslogtreecommitdiff
path: root/src/signer/noscrypt_signer.cpp
blob: e53dd57eda90e7dda3491255a1f02dd0725e8c62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <noscrypt.h>

#include "signer.hpp"

using namespace std;

namespace nostr
{
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.
    };

    void initiateConnection(
        string relay,
        string name,
        string url,
        string description) override
    {
        // Initiate the connection here.
    };

    void sign(shared_ptr<data::Event> event) override
    {
        // Sign the event here.
    };

private:
    shared_ptr<NCContext> context;
};
} // namespace signer
} // namespace nostr