aboutsummaryrefslogtreecommitdiff
path: root/include/signer/signer.hpp
blob: 0faaff8d30f079b0a698c38ea12d112113aeed8a (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
60
61
62
63
64
#pragma once

#include <future>
#include <memory>
#include <string>
#include <vector>

#include "data/data.hpp"

namespace nostr
{
namespace signer
{
/**
 * @brief An interface for Nostr event signing that implements NIP-46.
 */
class ISigner
{
public:
    virtual ~ISigner() = default;

    /**
     * @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 std::shared_ptr<std::promise<bool>> sign(std::shared_ptr<nostr::data::Event> event) = 0;
};

class INostrConnectSigner : public ISigner
{
public:
    virtual ~INostrConnectSigner() = default;

    /**
     * @brief Establishes a connection to a remote signer using a connection token generated by the
     * signer.
     * @param connectionToken A connection token string beginning with `bunker://`, as defined by
     * NIP-46.
     * @remark A typical use case for this method would be for the user to paste a signer-generated
     * connection token into a client application, which would then call this method to establish a
     * connection to the remote signer.
     */
    virtual void receiveConnection(std::string connectionToken) = 0;

    /**
     * @brief Generates a connection token that a remote signer may use to establish a connection
     * to the client.
     * @param relays A list of one or more relays the client will use to communicate with the
     * remote signer.
     * @returns A connection token string beginning with `nostrconnect://`, as specified by NIP-46,
     * that may be provided to a remote signer to establish a connection to the client.  Returns an
     * empty string if the connection token generation fails.
     */
    virtual std::string initiateConnection(
        std::vector<std::string> relays,
        std::string name,
        std::string url,
        std::string description) = 0;
};
} // namespace signer
} // namespace nostr