7#include "ArduinoJson.h"
15#define NWC_INFO_KIND "13194"
16#define NWC_RESPONSE_KIND "23195"
17#define NWC_NIP04_NOTIFICATION_KIND "23196"
18#define NWC_NIP44_NOTIFICATION_KIND "23197"
20#define NWC_DEFAULT_TIMEOUT (60 * 10)
21#define NWC_INFINITE_TIMEOUT (0xFFFFFFFF)
67 if (this->
onErr !=
nullptr) {
71 if (this->
onRes !=
nullptr) {
116 bool isReady()
const {
return encryptionReady; }
119 bool isValid()
const {
return validConnection; }
210 void listTransactions(
unsigned long from = 0,
unsigned long until = 0,
int limit = 0,
int offset = 0,
bool unpaid =
false,
NostrString type =
"",
236 if (this->pool !=
nullptr) this->pool->setSeenTracker(
callback);
240 struct PendingRequest {
241 std::function<
void()> send;
245 Transport *transport;
250 void discoverEncryption();
251 void finishEncryptionDiscovery();
252 void selectEncryption(
Nip47Encryption encryption,
bool includeEncryptionTag);
253 void rejectUnsupportedEncryption();
255 bool deferUntilEncryptionReady(std::function<
void()> send,
257 bool flushPendingRequests();
259 void finishInfoSubscription();
261 void removeCallback(
const std::shared_ptr<NWCResponseCallbackBase> &callback);
262 std::unique_ptr<NostrPool> pool;
267 bool encryptionReady =
false;
268 bool encryptionFailed =
false;
269 unsigned int notificationKind = 0;
272 std::vector<PendingRequest> pendingRequests;
273 std::vector<std::shared_ptr<NWCResponseCallbackBase>> callbacks;
274 unsigned int poolDispatchDepth = 0;
275 bool deferredClose =
false;
277 bool validConnection =
false;
278 unsigned long long discoveryStartedAt = 0;
279 bool sawInfoEvent =
false;
280 bool sawNip44 =
false;
281 bool sawNip04 =
false;
282 bool sawLegacyWithoutTag =
false;
#define NWC_DEFAULT_TIMEOUT
Definition NWC.h:20
long int NostrString_length(const std::string &str)
Definition NostrString.cpp:180
#define NostrString
Definition NostrString.h:10
std::vector< NostrString > expectedItemIds
Definition NWC.h:55
NostrString subId
Definition NWC.h:51
virtual void call(Nip47 *nip47, SignedNostrEvent *ev)
Definition NWC.h:46
unsigned int n
Definition NWC.h:52
unsigned int timeoutSeconds
Definition NWC.h:49
NostrString eventId
Definition NWC.h:50
std::vector< NostrString > seenEventIds
Definition NWC.h:57
std::function< void(NostrString, NostrString)> onErr
Definition NWC.h:47
std::vector< NostrString > seenItemIds
Definition NWC.h:56
unsigned long long timestampSeconds
Definition NWC.h:48
bool accept(SignedNostrEvent *event)
Definition NWC.cpp:28
bool requiresItemId
Definition NWC.h:53
bool strictItemIds
Definition NWC.h:54
virtual ~NWCResponseCallbackBase()=default
void call(Nip47 *nip47, SignedNostrEvent *ev) override
Definition NWC.h:63
std::function< void(T)> onRes
Definition NWC.h:76
Nip47Encryption getEncryption() const
Definition NWC.h:124
void payInvoice(NostrString invoice, MilliSats amount=MILLISATS_UNSPECIFIED, std::function< void(PayInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
Definition NWC.cpp:371
void multiPayKeySend(std::initializer_list< KeySend > keySends, std::function< void(MultiPayKeySendResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
Definition NWC.cpp:476
void lookUpInvoice(NostrString invoice, std::function< void(LookUpInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
Definition NWC.cpp:564
bool isReady() const
Definition NWC.h:116
void getBalance(std::function< void(GetBalanceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
Definition NWC.cpp:599
void payKeySend(NostrString pubkey, MilliSats amount, NostrString preimage="", std::initializer_list< TLVRecords > tlv={}, std::function< void(PayKeySendResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
Definition NWC.cpp:443
void setSeenTracker(NostrSeenCallback callback)
Definition NWC.h:235
void listTransactions(unsigned long from=0, unsigned long until=0, int limit=0, int offset=0, bool unpaid=false, NostrString type="", std::function< void(ListTransactionsResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
Definition NWC.cpp:580
void lookUpPaymentHash(NostrString paymentHash, std::function< void(LookUpInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
Definition NWC.cpp:548
void loop()
Definition NWC.cpp:240
void makeInvoice(MilliSats amount, NostrString description="", NostrString descriptionHash="", unsigned long expiry=0, std::function< void(MakeInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
Definition NWC.cpp:521
void close()
Definition NWC.cpp:216
~NWC()
Definition NWC.cpp:45
void multiPayInvoice(std::initializer_list< Invoice > invoices, std::function< void(MultiPayInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
Definition NWC.cpp:395
void getInfo(std::function< void(GetInfoResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
Definition NWC.cpp:615
void subscribeNotifications(std::function< void(NotificationResponse)> onRes, std::function< void(NostrString, NostrString)> onErr)
Definition NWC.cpp:335
bool isValid() const
Definition NWC.h:119
NostrString errorMessage
Definition Nip47.h:50
T result
Definition Nip47.h:52
NostrString errorCode
Definition Nip47.h:49
void parseResponse(SignedNostrEvent *response, Nip47Response< PayInvoiceResponse > &out)
Definition Nip47.cpp:323
Nip47Encryption getEncryption() const
Definition Nip47.h:181
Definition NostrEvent.h:130
Definition NostrTransport.h:21
Definition CryptoLock.h:6
std::function< bool(const SignedNostrEvent &)> NostrSeenCallback
Definition NostrPool.h:35
NWCEncryptionPolicy
Definition NWC.h:38
struct nostr::s_GetBalanceResponse GetBalanceResponse
struct nostr::s_ListTransactionsResponse ListTransactionsResponse
struct nostr::s_PayKeySendResponse PayKeySendResponse
struct nostr::s_MakeInvoiceResponse MakeInvoiceResponse
struct nostr::s_LookUpInvoiceResponse LookUpInvoiceResponse
Nip47Encryption
Definition Nip47.h:15
int64_t MilliSats
Definition NostrAmount.h:26
struct nostr::s_NWCData NWCData
struct nostr::s_NotificationResponse NotificationResponse
struct nostr::s_GetInfoResponse GetInfoResponse
struct nostr::s_MultiPayKeySendResponse MultiPayKeySendResponse
Definition NostrLimits.h:9