Nostrduino
Loading...
Searching...
No Matches
Nip47.h
Go to the documentation of this file.
1#ifndef _NIP47_H
2#define _NIP47_H
3#include <Arduino.h>
4#include "ArduinoJson.h"
5#include "Nip04.h"
6#include "Nip44.h"
7#include "NostrEvent.h"
8#include "NostrAmount.h"
9#include "NostrString.h"
10#include "NostrUtils.h"
11#include <initializer_list>
12#include <vector>
13namespace nostr {
14
15enum class Nip47Encryption {
16 Nip04,
18};
19
20typedef struct s_Invoice {
24
25 s_Invoice() : amount(MILLISATS_UNSPECIFIED) {}
26 s_Invoice(NostrString invoice, MilliSats amount = MILLISATS_UNSPECIFIED,
27 NostrString id = "")
30
35
43
54
59
64
69
75
90
107
125
129
133
134typedef struct s_GetInfoResponse {
139 unsigned long long blockHeight;
141 std::vector<NostrString> methods;
142 std::vector<NostrString> notifications;
143 std::vector<NostrString> extensions;
145
152
153
170
174
175
176class Nip47 {
177 public:
178 Nip47(){};
179 Nip47(Nip04 nip04, NostrString servicePubKey, NostrString userPrivKey) : servicePubKey(servicePubKey), userPrivKey(userPrivKey), nip04(nip04) {}
180 void setEncryption(Nip47Encryption encryption, bool includeEncryptionTag = true);
181 Nip47Encryption getEncryption() const { return encryption; }
182 SignedNostrEvent payInvoice(NostrString invoice, MilliSats amount = MILLISATS_UNSPECIFIED);
183 SignedNostrEvent multiPayInvoice(std::initializer_list<Invoice> invoices);
184 SignedNostrEvent multiPayInvoice(const std::vector<Invoice> &invoices);
185 SignedNostrEvent payKeySend(NostrString pubkey, MilliSats amount, NostrString preimage = "", std::initializer_list<TLVRecords> tlv = {});
186 SignedNostrEvent payKeySend(NostrString pubkey, MilliSats amount, NostrString preimage,
187 const std::vector<TLVRecords> &tlv);
188 SignedNostrEvent multiPayKeySend(std::initializer_list<KeySend> keySends);
189 SignedNostrEvent multiPayKeySend(const std::vector<KeySend> &keySends);
190 SignedNostrEvent makeInvoice(MilliSats amount, NostrString description = "", NostrString descriptionHash = "", unsigned long expiry = 0);
191 SignedNostrEvent lookUpPaymentHash(NostrString paymentHash);
192 SignedNostrEvent lookUpInvoice(NostrString invoice);
193 SignedNostrEvent listTransactions(unsigned long from = 0, unsigned long until = 0, int limit = 0, int offset = 0, bool unpaid = false, NostrString type = "");
194 SignedNostrEvent getBalance();
195 SignedNostrEvent getInfo();
196
197 void parseResponse(SignedNostrEvent *response, Nip47Response<PayInvoiceResponse> &out);
198 void parseResponse(SignedNostrEvent *response, Nip47Response<MultiPayInvoiceResponse> &out);
199 void parseResponse(SignedNostrEvent *response, Nip47Response<PayKeySendResponse> &out);
200 void parseResponse(SignedNostrEvent *response, Nip47Response<MultiPayKeySendResponse> &out);
201 void parseResponse(SignedNostrEvent *response, Nip47Response<MakeInvoiceResponse> &out);
202 void parseResponse(SignedNostrEvent *response, Nip47Response<LookUpInvoiceResponse> &out);
203 void parseResponse(SignedNostrEvent *response, Nip47Response<ListTransactionsResponse> &out);
204 void parseResponse(SignedNostrEvent *response, Nip47Response<GetBalanceResponse> &out);
205 void parseResponse(SignedNostrEvent *response, Nip47Response<GetInfoResponse> &out);
206 void parseResponse(SignedNostrEvent *response, Nip47Response<NotificationResponse> &out);
207 static bool parseNWC(NostrString, NWCData &);
208
209 private:
210 NostrString servicePubKey;
211 NostrString userPrivKey;
212 Nip04 nip04;
213 Nip44 nip44;
215 bool includeEncryptionTag = false;
216 SignedNostrEvent createEvent(NostrString method, JsonDocument doc);
217 NostrString encryptContent(NostrString content);
218 NostrString decryptContent(NostrString content);
219 bool parseResponseEnvelope(SignedNostrEvent *response, const char *expectedResultType,
220 JsonDocument &document, JsonObjectConst &result,
221 NostrString &errorCode, NostrString &errorMessage);
222 std::function<void(Nip47Notification)> notificationCallback;
223};
224}
225
226#endif
#define NostrString
Definition NostrString.h:10
Definition Nip04.h:11
Definition Nip47.h:44
NostrString errorMessage
Definition Nip47.h:50
Nip47Response(NostrString errorCode, NostrString errorMessage, NostrString resultType, T result)
Definition Nip47.h:48
T result
Definition Nip47.h:52
Nip47Response()
Definition Nip47.h:46
NostrString errorCode
Definition Nip47.h:49
NostrString resultType
Definition Nip47.h:51
Definition Nip47.h:176
SignedNostrEvent makeInvoice(MilliSats amount, NostrString description="", NostrString descriptionHash="", unsigned long expiry=0)
Definition Nip47.cpp:180
SignedNostrEvent getBalance()
Definition Nip47.cpp:211
static bool parseNWC(NostrString, NWCData &)
Definition Nip47.cpp:565
void parseResponse(SignedNostrEvent *response, Nip47Response< PayInvoiceResponse > &out)
Definition Nip47.cpp:323
SignedNostrEvent multiPayKeySend(std::initializer_list< KeySend > keySends)
Definition Nip47.cpp:269
SignedNostrEvent lookUpPaymentHash(NostrString paymentHash)
Definition Nip47.cpp:197
SignedNostrEvent multiPayInvoice(std::initializer_list< Invoice > invoices)
Definition Nip47.cpp:223
SignedNostrEvent lookUpInvoice(NostrString invoice)
Definition Nip47.cpp:204
Nip47Encryption getEncryption() const
Definition Nip47.h:181
Nip47()
Definition Nip47.h:178
SignedNostrEvent payKeySend(NostrString pubkey, MilliSats amount, NostrString preimage="", std::initializer_list< TLVRecords > tlv={})
Definition Nip47.cpp:244
void setEncryption(Nip47Encryption encryption, bool includeEncryptionTag=true)
Definition Nip47.cpp:104
SignedNostrEvent listTransactions(unsigned long from=0, unsigned long until=0, int limit=0, int offset=0, bool unpaid=false, NostrString type="")
Definition Nip47.cpp:301
SignedNostrEvent payInvoice(NostrString invoice, MilliSats amount=MILLISATS_UNSPECIFIED)
Definition Nip47.cpp:169
SignedNostrEvent getInfo()
Definition Nip47.cpp:217
Nip47(Nip04 nip04, NostrString servicePubKey, NostrString userPrivKey)
Definition Nip47.h:179
Definition NostrEvent.h:130
Definition CryptoLock.h:6
struct nostr::s_MultiPayInvoiceResponse MultiPayInvoiceResponse
struct nostr::s_KeySend KeySend
struct nostr::s_Transaction Transaction
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
struct nostr::s_PayInvoiceResponse PayInvoiceResponse
struct nostr::s_Invoice Invoice
int64_t MilliSats
Definition NostrAmount.h:26
struct nostr::s_NWCData NWCData
struct nostr::s_TLVRecords TLVRecords
struct nostr::s_Nip47Notification Nip47Notification
struct nostr::s_NotificationResponse NotificationResponse
struct nostr::s_GetInfoResponse GetInfoResponse
struct nostr::s_MultiPayKeySendResponse MultiPayKeySendResponse
Definition Nip47.h:130
MilliSats balance
Definition Nip47.h:131
Definition Nip47.h:134
NostrString blockHash
Definition Nip47.h:140
unsigned long long blockHeight
Definition Nip47.h:139
NostrString alias
Definition Nip47.h:135
NostrString pubkey
Definition Nip47.h:137
NostrString color
Definition Nip47.h:136
std::vector< NostrString > notifications
Definition Nip47.h:142
std::vector< NostrString > methods
Definition Nip47.h:141
std::vector< NostrString > extensions
Definition Nip47.h:143
NostrString network
Definition Nip47.h:138
Definition Nip47.h:20
NostrString invoice
Definition Nip47.h:21
NostrString id
Definition Nip47.h:23
MilliSats amount
Definition Nip47.h:22
s_Invoice(NostrString invoice, MilliSats amount=MILLISATS_UNSPECIFIED, NostrString id="")
Definition Nip47.h:26
s_Invoice()
Definition Nip47.h:25
Definition Nip47.h:36
NostrString preimage
Definition Nip47.h:39
std::vector< TLVRecords > tlv
Definition Nip47.h:40
MilliSats amount
Definition Nip47.h:38
NostrString id
Definition Nip47.h:41
NostrString pubkey
Definition Nip47.h:37
Definition Nip47.h:126
std::vector< Transaction > transactions
Definition Nip47.h:127
Definition Nip47.h:91
NostrString state
Definition Nip47.h:93
unsigned long long createdAt
Definition Nip47.h:101
unsigned long long settledAt
Definition Nip47.h:103
NostrString paymentHash
Definition Nip47.h:98
NostrString type
Definition Nip47.h:92
NostrString description
Definition Nip47.h:95
JsonDocument metadata
Definition Nip47.h:105
MilliSats feesPaid
Definition Nip47.h:100
MilliSats amount
Definition Nip47.h:99
unsigned long long expiresAt
Definition Nip47.h:102
NostrString descriptionHash
Definition Nip47.h:96
NostrString preimage
Definition Nip47.h:97
NostrString invoice
Definition Nip47.h:94
Definition Nip47.h:76
unsigned long long expiresAt
Definition Nip47.h:87
MilliSats amount
Definition Nip47.h:84
NostrString type
Definition Nip47.h:77
NostrString preimage
Definition Nip47.h:82
NostrString state
Definition Nip47.h:78
MilliSats feesPaid
Definition Nip47.h:85
NostrString paymentHash
Definition Nip47.h:83
NostrString invoice
Definition Nip47.h:79
NostrString description
Definition Nip47.h:80
NostrString descriptionHash
Definition Nip47.h:81
unsigned long long createdAt
Definition Nip47.h:86
JsonDocument metadata
Definition Nip47.h:88
NostrString d
Definition Nip47.h:62
NostrString preimage
Definition Nip47.h:61
NostrString d
Definition Nip47.h:72
NostrString preimage
Definition Nip47.h:71
Definition Nip47.h:146
std::vector< NostrString > relays
Definition Nip47.h:148
NostrString pubkey
Definition Nip47.h:149
NostrString relay
Definition Nip47.h:147
NostrString secret
Definition Nip47.h:150
Definition Nip47.h:154
JsonDocument metadata
Definition Nip47.h:168
NostrString description
Definition Nip47.h:159
unsigned long long createdAt
Definition Nip47.h:165
NostrString state
Definition Nip47.h:157
NostrString preimage
Definition Nip47.h:161
NostrString paymentHash
Definition Nip47.h:162
unsigned long long settledAt
Definition Nip47.h:167
NostrString invoice
Definition Nip47.h:158
NostrString descriptionHash
Definition Nip47.h:160
NostrString notificationType
Definition Nip47.h:155
MilliSats feesPaid
Definition Nip47.h:164
NostrString type
Definition Nip47.h:156
unsigned long long expiresAt
Definition Nip47.h:166
MilliSats amount
Definition Nip47.h:163
Definition Nip47.h:171
Nip47Notification notification
Definition Nip47.h:172
Definition Nip47.h:55
MilliSats feesPaid
Definition Nip47.h:57
NostrString preimage
Definition Nip47.h:56
Definition Nip47.h:65
NostrString preimage
Definition Nip47.h:66
MilliSats feesPaid
Definition Nip47.h:67
Definition Nip47.h:31
NostrString value
Definition Nip47.h:33
uint64_t type
Definition Nip47.h:32
Definition Nip47.h:108
MilliSats feesPaid
Definition Nip47.h:117
NostrString state
Definition Nip47.h:110
unsigned long long expiresAt
Definition Nip47.h:119
MilliSats amount
Definition Nip47.h:116
NostrString type
Definition Nip47.h:109
NostrString description
Definition Nip47.h:112
NostrString descriptionHash
Definition Nip47.h:113
NostrString paymentHash
Definition Nip47.h:115
unsigned long long createdAt
Definition Nip47.h:118
NostrString preimage
Definition Nip47.h:114
JsonDocument metadata
Definition Nip47.h:122
unsigned long long settledAt
Definition Nip47.h:120
NostrString invoice
Definition Nip47.h:111