@lightsparkdev/lightspark-sdk 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/.fossa.yml +6 -0
  2. package/.prettierrc +1 -0
  3. package/.turbo/turbo-build.log +19 -0
  4. package/.turbo/turbo-lint.log +3 -0
  5. package/CHANGELOG.md +49 -0
  6. package/LICENSE +201 -0
  7. package/README.md +137 -0
  8. package/dist/Withdrawal-17e1c8af.d.ts +1672 -0
  9. package/dist/Withdrawal-27a4d10d.d.ts +1672 -0
  10. package/dist/chunk-3VRI7CHE.js +5508 -0
  11. package/dist/chunk-AGEUDR2V.js +4498 -0
  12. package/dist/chunk-N27QHRE4.js +5508 -0
  13. package/dist/client-3bba3f64.d.ts +1302 -0
  14. package/dist/index.cjs +6633 -0
  15. package/dist/index.d.ts +15 -0
  16. package/dist/index.js +1177 -0
  17. package/dist/objects/index.cjs +5347 -0
  18. package/dist/objects/index.d.ts +3 -0
  19. package/dist/objects/index.js +88 -0
  20. package/examples/node-scripts/authHelpers.ts +20 -0
  21. package/examples/node-scripts/createInvoice.ts +64 -0
  22. package/examples/node-scripts/example.ts +288 -0
  23. package/examples/node-scripts/getAccountDashboard.ts +24 -0
  24. package/examples/node-scripts/getNodeChannels.ts +34 -0
  25. package/examples/node-scripts/internalAuthHelpers.ts +26 -0
  26. package/examples/node-scripts/internal_example.ts +296 -0
  27. package/examples/node-scripts/package-lock.json +887 -0
  28. package/examples/node-scripts/package.json +22 -0
  29. package/examples/node-scripts/prettyPrintJsonForDocs.ts +62 -0
  30. package/examples/node-scripts/tsconfig.json +27 -0
  31. package/examples/oauth-example/README.md +19 -0
  32. package/examples/oauth-example/package-lock.json +16071 -0
  33. package/examples/oauth-example/package.json +50 -0
  34. package/examples/oauth-example/public/favicon.ico +0 -0
  35. package/examples/oauth-example/public/index.html +43 -0
  36. package/examples/oauth-example/public/logo192.png +0 -0
  37. package/examples/oauth-example/public/logo512.png +0 -0
  38. package/examples/oauth-example/public/manifest.json +25 -0
  39. package/examples/oauth-example/public/robots.txt +3 -0
  40. package/examples/oauth-example/src/App.css +7 -0
  41. package/examples/oauth-example/src/App.test.tsx +12 -0
  42. package/examples/oauth-example/src/App.tsx +16 -0
  43. package/examples/oauth-example/src/auth/AuthContext.ts +8 -0
  44. package/examples/oauth-example/src/auth/AuthProvider.tsx +44 -0
  45. package/examples/oauth-example/src/auth/RequireAuth.tsx +19 -0
  46. package/examples/oauth-example/src/auth/oauthProvider.ts +35 -0
  47. package/examples/oauth-example/src/components/Button.tsx +39 -0
  48. package/examples/oauth-example/src/components/CurrencyAmount.tsx +117 -0
  49. package/examples/oauth-example/src/components/Dashboard.tsx +158 -0
  50. package/examples/oauth-example/src/components/Table.tsx +22 -0
  51. package/examples/oauth-example/src/hooks/useAccountInfo.tsx +31 -0
  52. package/examples/oauth-example/src/icons/BitcoinB.tsx +20 -0
  53. package/examples/oauth-example/src/icons/Icon.tsx +121 -0
  54. package/examples/oauth-example/src/icons/Satoshi.tsx +28 -0
  55. package/examples/oauth-example/src/index.css +13 -0
  56. package/examples/oauth-example/src/index.tsx +23 -0
  57. package/examples/oauth-example/src/lightsparkclient/LightsparkClientContext.ts +10 -0
  58. package/examples/oauth-example/src/lightsparkclient/LightsparkClientProvider.tsx +53 -0
  59. package/examples/oauth-example/src/logo.svg +1 -0
  60. package/examples/oauth-example/src/pages/DashboardPage.tsx +71 -0
  61. package/examples/oauth-example/src/pages/LoginPage.tsx +63 -0
  62. package/examples/oauth-example/src/react-app-env.d.ts +1 -0
  63. package/examples/oauth-example/src/reportWebVitals.ts +15 -0
  64. package/examples/oauth-example/src/routes/index.tsx +15 -0
  65. package/examples/oauth-example/src/setupTests.ts +5 -0
  66. package/examples/oauth-example/src/utils/currency.ts +483 -0
  67. package/examples/oauth-example/tsconfig.json +20 -0
  68. package/examples/streaming-wallet-extension/.fossa.yml +6 -0
  69. package/examples/streaming-wallet-extension/README.md +17 -0
  70. package/examples/streaming-wallet-extension/craco.config.js +58 -0
  71. package/examples/streaming-wallet-extension/package-lock.json +18260 -0
  72. package/examples/streaming-wallet-extension/package.json +77 -0
  73. package/examples/streaming-wallet-extension/public/index.html +24 -0
  74. package/examples/streaming-wallet-extension/public/lightspark_full.png +0 -0
  75. package/examples/streaming-wallet-extension/public/lightspark_icon_circle.png +0 -0
  76. package/examples/streaming-wallet-extension/public/manifest.json +43 -0
  77. package/examples/streaming-wallet-extension/public/robots.txt +3 -0
  78. package/examples/streaming-wallet-extension/src/App.css +53 -0
  79. package/examples/streaming-wallet-extension/src/App.tsx +425 -0
  80. package/examples/streaming-wallet-extension/src/auth/AccountStorage.ts +28 -0
  81. package/examples/streaming-wallet-extension/src/auth/DemoAccountProvider.ts +99 -0
  82. package/examples/streaming-wallet-extension/src/auth/StreamingDemoCredentials.ts +10 -0
  83. package/examples/streaming-wallet-extension/src/background/PaymentStrategy.ts +36 -0
  84. package/examples/streaming-wallet-extension/src/background/PlaybackRange.ts +31 -0
  85. package/examples/streaming-wallet-extension/src/background/StreamingInvoiceHolder.ts +33 -0
  86. package/examples/streaming-wallet-extension/src/background/TransactionObserver.ts +66 -0
  87. package/examples/streaming-wallet-extension/src/background/VideoPlaybackRanges.ts +38 -0
  88. package/examples/streaming-wallet-extension/src/background/VideoProgressCache.ts +87 -0
  89. package/examples/streaming-wallet-extension/src/background/background.ts +145 -0
  90. package/examples/streaming-wallet-extension/src/background/messageHandling.ts +185 -0
  91. package/examples/streaming-wallet-extension/src/common/datetimes.ts +28 -0
  92. package/examples/streaming-wallet-extension/src/common/settings.ts +12 -0
  93. package/examples/streaming-wallet-extension/src/common/storage.ts +8 -0
  94. package/examples/streaming-wallet-extension/src/common/streamingTabs.ts +27 -0
  95. package/examples/streaming-wallet-extension/src/common/types.tsx +23 -0
  96. package/examples/streaming-wallet-extension/src/components/CirclePlusIcon.tsx +19 -0
  97. package/examples/streaming-wallet-extension/src/components/CurrencyAmount.tsx +110 -0
  98. package/examples/streaming-wallet-extension/src/components/CurrencyAmountRaw.tsx +195 -0
  99. package/examples/streaming-wallet-extension/src/components/LeftArrow.tsx +21 -0
  100. package/examples/streaming-wallet-extension/src/components/Loading.tsx +151 -0
  101. package/examples/streaming-wallet-extension/src/components/StreamingTransactionChip.tsx +95 -0
  102. package/examples/streaming-wallet-extension/src/components/TransactionRow.tsx +93 -0
  103. package/examples/streaming-wallet-extension/src/contentscript/content.ts +123 -0
  104. package/examples/streaming-wallet-extension/src/contentscript/lightsparkDemoDom.tsx +113 -0
  105. package/examples/streaming-wallet-extension/src/contentscript/videoElementParsers.ts +92 -0
  106. package/examples/streaming-wallet-extension/src/index.css +16 -0
  107. package/examples/streaming-wallet-extension/src/index.tsx +11 -0
  108. package/examples/streaming-wallet-extension/src/lightsparkClientProvider.tsx +26 -0
  109. package/examples/streaming-wallet-extension/src/react-app-env.d.ts +1 -0
  110. package/examples/streaming-wallet-extension/src/types/Messages.ts +17 -0
  111. package/examples/streaming-wallet-extension/tsconfig.json +20 -0
  112. package/package.json +87 -0
  113. package/src/auth/AccountTokenAuthProvider.ts +37 -0
  114. package/src/auth/index.ts +3 -0
  115. package/src/client.ts +759 -0
  116. package/src/graphql/BitcoinFeeEstimate.ts +13 -0
  117. package/src/graphql/CreateApiToken.ts +22 -0
  118. package/src/graphql/CreateInvoice.ts +18 -0
  119. package/src/graphql/CreateNodeWalletAddress.ts +13 -0
  120. package/src/graphql/CurrentAccount.ts +13 -0
  121. package/src/graphql/DecodeInvoice.ts +16 -0
  122. package/src/graphql/DeleteApiToken.ts +13 -0
  123. package/src/graphql/FundNode.ts +18 -0
  124. package/src/graphql/LightningFeeEstimateForInvoice.ts +21 -0
  125. package/src/graphql/LightningFeeEstimateForNode.ts +21 -0
  126. package/src/graphql/MultiNodeDashboard.ts +118 -0
  127. package/src/graphql/PayInvoice.ts +29 -0
  128. package/src/graphql/RecoverNodeSigningKey.ts +15 -0
  129. package/src/graphql/RequestWithdrawal.ts +25 -0
  130. package/src/graphql/SendPayment.ts +29 -0
  131. package/src/graphql/SingleNodeDashboard.ts +116 -0
  132. package/src/graphql/TransactionSubscription.ts +16 -0
  133. package/src/graphql/TransactionsForNode.ts +42 -0
  134. package/src/index.ts +5 -0
  135. package/src/objects/Account.ts +1222 -0
  136. package/src/objects/AccountToApiTokensConnection.ts +50 -0
  137. package/src/objects/AccountToChannelsConnection.ts +35 -0
  138. package/src/objects/AccountToNodesConnection.ts +62 -0
  139. package/src/objects/AccountToPaymentRequestsConnection.ts +50 -0
  140. package/src/objects/AccountToTransactionsConnection.ts +112 -0
  141. package/src/objects/ApiToken.ts +80 -0
  142. package/src/objects/BitcoinNetwork.ts +19 -0
  143. package/src/objects/BlockchainBalance.ts +102 -0
  144. package/src/objects/Channel.ts +283 -0
  145. package/src/objects/ChannelClosingTransaction.ts +150 -0
  146. package/src/objects/ChannelFees.ts +34 -0
  147. package/src/objects/ChannelOpeningTransaction.ts +150 -0
  148. package/src/objects/ChannelStatus.ts +25 -0
  149. package/src/objects/ChannelToTransactionsConnection.ts +86 -0
  150. package/src/objects/CreateApiTokenInput.ts +22 -0
  151. package/src/objects/CreateApiTokenOutput.ts +41 -0
  152. package/src/objects/CreateInvoiceInput.ts +27 -0
  153. package/src/objects/CreateInvoiceOutput.ts +21 -0
  154. package/src/objects/CreateNodeWalletAddressInput.ts +15 -0
  155. package/src/objects/CreateNodeWalletAddressOutput.ts +27 -0
  156. package/src/objects/CurrencyAmount.ts +55 -0
  157. package/src/objects/CurrencyUnit.ts +25 -0
  158. package/src/objects/DeleteApiTokenInput.ts +13 -0
  159. package/src/objects/DeleteApiTokenOutput.ts +23 -0
  160. package/src/objects/Deposit.ts +144 -0
  161. package/src/objects/Entity.ts +868 -0
  162. package/src/objects/FeeEstimate.ts +39 -0
  163. package/src/objects/FundNodeInput.ts +16 -0
  164. package/src/objects/FundNodeOutput.ts +28 -0
  165. package/src/objects/GraphNode.ts +110 -0
  166. package/src/objects/Hop.ts +108 -0
  167. package/src/objects/HtlcAttemptFailureCode.ts +65 -0
  168. package/src/objects/IncomingPayment.ts +141 -0
  169. package/src/objects/IncomingPaymentAttempt.ts +96 -0
  170. package/src/objects/IncomingPaymentAttemptStatus.ts +20 -0
  171. package/src/objects/IncomingPaymentToAttemptsConnection.ts +39 -0
  172. package/src/objects/Invoice.ts +226 -0
  173. package/src/objects/InvoiceData.ts +185 -0
  174. package/src/objects/InvoiceType.ts +15 -0
  175. package/src/objects/LightningFeeEstimateForInvoiceInput.ts +28 -0
  176. package/src/objects/LightningFeeEstimateForNodeInput.ts +25 -0
  177. package/src/objects/LightningFeeEstimateOutput.ts +33 -0
  178. package/src/objects/LightningTransaction.ts +393 -0
  179. package/src/objects/LightsparkNode.ts +377 -0
  180. package/src/objects/LightsparkNodePurpose.ts +17 -0
  181. package/src/objects/LightsparkNodeStatus.ts +29 -0
  182. package/src/objects/LightsparkNodeToChannelsConnection.ts +50 -0
  183. package/src/objects/Node.ts +273 -0
  184. package/src/objects/NodeAddress.ts +29 -0
  185. package/src/objects/NodeAddressType.ts +18 -0
  186. package/src/objects/NodeToAddressesConnection.ts +39 -0
  187. package/src/objects/OnChainTransaction.ts +318 -0
  188. package/src/objects/OutgoingPayment.ts +319 -0
  189. package/src/objects/OutgoingPaymentAttempt.ts +164 -0
  190. package/src/objects/OutgoingPaymentAttemptStatus.ts +18 -0
  191. package/src/objects/OutgoingPaymentAttemptToHopsConnection.ts +37 -0
  192. package/src/objects/OutgoingPaymentToAttemptsConnection.ts +39 -0
  193. package/src/objects/PageInfo.ts +31 -0
  194. package/src/objects/PayInvoiceInput.ts +33 -0
  195. package/src/objects/PayInvoiceOutput.ts +22 -0
  196. package/src/objects/PaymentFailureReason.ts +29 -0
  197. package/src/objects/PaymentRequest.ts +231 -0
  198. package/src/objects/PaymentRequestData.ts +183 -0
  199. package/src/objects/PaymentRequestStatus.ts +15 -0
  200. package/src/objects/Permission.ts +39 -0
  201. package/src/objects/RequestWithdrawalInput.ts +35 -0
  202. package/src/objects/RequestWithdrawalOutput.ts +24 -0
  203. package/src/objects/RichText.ts +19 -0
  204. package/src/objects/RoutingTransaction.ts +150 -0
  205. package/src/objects/RoutingTransactionFailureReason.ts +17 -0
  206. package/src/objects/Secret.ts +23 -0
  207. package/src/objects/SendPaymentInput.ts +30 -0
  208. package/src/objects/SendPaymentOutput.ts +22 -0
  209. package/src/objects/Transaction.ts +609 -0
  210. package/src/objects/TransactionFailures.ts +23 -0
  211. package/src/objects/TransactionStatus.ts +23 -0
  212. package/src/objects/TransactionType.ts +31 -0
  213. package/src/objects/TransactionUpdate.ts +67 -0
  214. package/src/objects/WalletDashboard.ts +32 -0
  215. package/src/objects/WebhookEventType.ts +15 -0
  216. package/src/objects/Withdrawal.ts +144 -0
  217. package/src/objects/WithdrawalMode.ts +15 -0
  218. package/src/objects/WithdrawalRequest.ts +224 -0
  219. package/src/objects/WithdrawalRequestStatus.ts +17 -0
  220. package/src/objects/WithdrawalRequestToChannelClosingTransactionsConnection.ts +57 -0
  221. package/src/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.ts +57 -0
  222. package/src/objects/index.ts +108 -0
  223. package/tsconfig.json +5 -0
package/dist/index.js ADDED
@@ -0,0 +1,1177 @@
1
+ import {
2
+ AccountToChannelsConnection_default,
3
+ Account_default,
4
+ ApiTokenFromJson,
5
+ BitcoinNetwork_default,
6
+ ChannelStatus_default,
7
+ Channel_default,
8
+ CurrencyAmountFromJson,
9
+ CurrencyUnit_default,
10
+ FRAGMENT,
11
+ FRAGMENT2,
12
+ FRAGMENT3,
13
+ FRAGMENT4,
14
+ FRAGMENT5,
15
+ FRAGMENT6,
16
+ FRAGMENT7,
17
+ FRAGMENT8,
18
+ FRAGMENT9,
19
+ FeeEstimateFromJson,
20
+ GraphNode_default,
21
+ HtlcAttemptFailureCode_default,
22
+ IncomingPaymentAttemptStatus_default,
23
+ IncomingPayment_default,
24
+ InvoiceDataFromJson,
25
+ InvoiceType_default,
26
+ LightsparkNodePurpose_default,
27
+ LightsparkNodeStatus_default,
28
+ LightsparkNode_default,
29
+ NodeAddressType_default,
30
+ Node_default,
31
+ OutgoingPaymentAttemptStatus_default,
32
+ OutgoingPaymentAttempt_default,
33
+ OutgoingPaymentFromJson,
34
+ OutgoingPayment_default,
35
+ PaymentFailureReason_default,
36
+ PaymentRequestStatus_default,
37
+ Permission_default,
38
+ RoutingTransactionFailureReason_default,
39
+ TransactionFromJson,
40
+ TransactionStatus_default,
41
+ TransactionType_default,
42
+ TransactionUpdateFromJson,
43
+ WebhookEventType_default,
44
+ WithdrawalMode_default,
45
+ WithdrawalRequestFromJson,
46
+ WithdrawalRequestStatus_default,
47
+ WithdrawalRequest_default,
48
+ getApiTokenQuery,
49
+ getChannelClosingTransactionQuery,
50
+ getChannelOpeningTransactionQuery,
51
+ getDepositQuery,
52
+ getHopQuery,
53
+ getIncomingPaymentAttemptQuery,
54
+ getInvoiceQuery,
55
+ getLightningTransactionQuery,
56
+ getOnChainTransactionQuery,
57
+ getPaymentRequestQuery,
58
+ getRoutingTransactionQuery,
59
+ getTransactionQuery,
60
+ getWithdrawalQuery
61
+ } from "./chunk-3VRI7CHE.js";
62
+
63
+ // src/auth/AccountTokenAuthProvider.ts
64
+ import { b64encode } from "@lightsparkdev/core";
65
+ import autoBind from "auto-bind";
66
+ var AccountTokenAuthProvider = class {
67
+ constructor(apiTokenClientId, apiTokenClientSecret) {
68
+ this.apiTokenClientId = apiTokenClientId;
69
+ this.apiTokenClientSecret = apiTokenClientSecret;
70
+ this.utf8AuthBytes = new TextEncoder().encode(
71
+ `${apiTokenClientId}:${apiTokenClientSecret}`
72
+ );
73
+ autoBind(this);
74
+ }
75
+ utf8AuthBytes;
76
+ async addWsConnectionParams(params) {
77
+ return Object.assign({}, params, {
78
+ client_id: this.apiTokenClientId,
79
+ client_secret: this.apiTokenClientSecret
80
+ });
81
+ }
82
+ async addAuthHeaders(headers) {
83
+ return Object.assign({}, headers, {
84
+ authorization: `Basic ${b64encode(this.utf8AuthBytes)}`
85
+ });
86
+ }
87
+ async isAuthorized() {
88
+ return true;
89
+ }
90
+ };
91
+ var AccountTokenAuthProvider_default = AccountTokenAuthProvider;
92
+
93
+ // src/client.ts
94
+ import autoBind2 from "auto-bind";
95
+ import {
96
+ b64encode as b64encode2,
97
+ decryptSecretWithNodePassword,
98
+ LightsparkAuthException,
99
+ LightsparkException,
100
+ LightsparkSigningException,
101
+ NodeKeyCache,
102
+ Requester,
103
+ StubAuthProvider
104
+ } from "@lightsparkdev/core";
105
+
106
+ // src/graphql/BitcoinFeeEstimate.ts
107
+ var BitcoinFeeEstimate = `
108
+ query BitcoinFeeEstimate($bitcoin_network: BitcoinNetwork!) {
109
+ bitcoin_fee_estimate(network: $bitcoin_network) {
110
+ ...FeeEstimateFragment
111
+ }
112
+ }
113
+
114
+ ${FRAGMENT2}
115
+ `;
116
+
117
+ // src/graphql/CreateApiToken.ts
118
+ var CreateApiToken = `
119
+ mutation CreateApiToken(
120
+ $name: String!
121
+ $permissions: [Permission!]!
122
+ ) {
123
+ create_api_token(input: {
124
+ name: $name
125
+ permissions: $permissions
126
+ }) {
127
+ api_token {
128
+ ...ApiTokenFragment
129
+ }
130
+ client_secret
131
+ }
132
+ }
133
+
134
+ ${FRAGMENT3}
135
+ `;
136
+
137
+ // src/graphql/CreateInvoice.ts
138
+ var CreateInvoice = `
139
+ mutation CreateInvoice(
140
+ $node_id: ID!
141
+ $amount_msats: Long!
142
+ $memo: String
143
+ $type: InvoiceType = null
144
+ ) {
145
+ create_invoice(input: { node_id: $node_id, amount_msats: $amount_msats, memo: $memo, invoice_type: $type }) {
146
+ invoice {
147
+ data {
148
+ encoded_payment_request
149
+ }
150
+ }
151
+ }
152
+ }
153
+ `;
154
+
155
+ // src/graphql/CreateNodeWalletAddress.ts
156
+ var CreateNodeWalletAddress = `
157
+ mutation CreateNodeWalletAddress(
158
+ $node_id: ID!
159
+ ) {
160
+ create_node_wallet_address(input: {
161
+ node_id: $node_id
162
+ }) {
163
+ wallet_address
164
+ }
165
+ }
166
+ `;
167
+
168
+ // src/graphql/DecodeInvoice.ts
169
+ var DecodeInvoice = `
170
+ query DecodeInvoice($encoded_payment_request: String!) {
171
+ decoded_payment_request(encoded_payment_request: $encoded_payment_request) {
172
+ __typename
173
+ ... on InvoiceData {
174
+ ...InvoiceDataFragment
175
+ }
176
+ }
177
+ }
178
+
179
+ ${FRAGMENT4}
180
+ `;
181
+
182
+ // src/graphql/DeleteApiToken.ts
183
+ var DeleteApiToken = `
184
+ mutation DeleteApiToken(
185
+ $api_token_id: ID!
186
+ ) {
187
+ delete_api_token(input: {
188
+ api_token_id: $api_token_id
189
+ }) {
190
+ __typename
191
+ }
192
+ }
193
+ `;
194
+
195
+ // src/graphql/FundNode.ts
196
+ var FundNode = `
197
+ mutation FundNode(
198
+ $node_id: ID!,
199
+ $amountSats: Long
200
+ ) {
201
+ fund_node(input: { node_id: $node_id, amount_sats: $amountMsats }) {
202
+ amount {
203
+ ...CurrencyAmountFragment
204
+ }
205
+ }
206
+ }
207
+
208
+ ${FRAGMENT}
209
+ `;
210
+
211
+ // src/graphql/LightningFeeEstimateForInvoice.ts
212
+ var LightningFeeEstimateForInvoice = `
213
+ query LightningFeeEstimateForInvoice(
214
+ $node_id: ID!
215
+ $encoded_payment_request: String!
216
+ $amount_msats: Long
217
+ ) {
218
+ lightning_fee_estimate_for_invoice(input: {
219
+ node_id: $node_id,
220
+ encoded_payment_request: $encoded_payment_request,
221
+ amount_msats: $amount_msats
222
+ }) {
223
+ ...LightningFeeEstimateOutputFragment
224
+ }
225
+ }
226
+
227
+ ${FRAGMENT5}
228
+ `;
229
+
230
+ // src/graphql/LightningFeeEstimateForNode.ts
231
+ var LightningFeeEstimateForNode = `
232
+ query LightningFeeEstimateForNode(
233
+ $node_id: ID!
234
+ $destination_node_public_key: String!
235
+ $amount_msats: Long!
236
+ ) {
237
+ lightning_fee_estimate_for_node(input: {
238
+ node_id: $node_id,
239
+ destination_node_public_key: $destination_node_public_key,
240
+ amount_msats: $amount_msats
241
+ }) {
242
+ ...LightningFeeEstimateOutputFragment
243
+ }
244
+ }
245
+
246
+ ${FRAGMENT5}
247
+ `;
248
+
249
+ // src/graphql/MultiNodeDashboard.ts
250
+ var MultiNodeDashboard = `
251
+ query MultiNodeDashboard(
252
+ $network: BitcoinNetwork!,
253
+ $nodeIds: [ID!]
254
+ ) {
255
+ current_account {
256
+ id
257
+ name
258
+ dashboard_overview_nodes: nodes(
259
+ bitcoin_networks: [$network]
260
+ node_ids: $nodeIds
261
+ ) {
262
+ count
263
+ entities {
264
+ color
265
+ display_name
266
+ purpose
267
+ id
268
+ addresses(first: 1) {
269
+ entities {
270
+ address
271
+ type
272
+ __typename
273
+ }
274
+ count
275
+ __typename
276
+ }
277
+ public_key
278
+ status
279
+ local_balance {
280
+ ...CurrencyAmountFragment
281
+ }
282
+ remote_balance {
283
+ ...CurrencyAmountFragment
284
+ }
285
+ blockchain_balance {
286
+ available_balance {
287
+ ...CurrencyAmountFragment
288
+ }
289
+ total_balance {
290
+ ...CurrencyAmountFragment
291
+ }
292
+ __typename
293
+ }
294
+ __typename
295
+ }
296
+ __typename
297
+ }
298
+ blockchain_balance(bitcoin_networks: [$network], node_ids: $nodeIds) {
299
+ l1_balance: total_balance {
300
+ ...CurrencyAmountFragment
301
+ }
302
+ required_reserve {
303
+ ...CurrencyAmountFragment
304
+ }
305
+ available_balance {
306
+ ...CurrencyAmountFragment
307
+ }
308
+ unconfirmed_balance {
309
+ ...CurrencyAmountFragment
310
+ }
311
+ __typename
312
+ }
313
+ local_balance(bitcoin_networks: [$network], node_ids: $nodeIds) {
314
+ ...CurrencyAmountFragment
315
+ }
316
+ remote_balance(bitcoin_networks: [$network], node_ids: $nodeIds) {
317
+ ...CurrencyAmountFragment
318
+ }
319
+ }
320
+ }
321
+
322
+ ${FRAGMENT}
323
+ `;
324
+
325
+ // src/graphql/PayInvoice.ts
326
+ var PayInvoice = `
327
+ mutation PayInvoice(
328
+ $node_id: ID!
329
+ $encoded_invoice: String!
330
+ $timeout_secs: Int!
331
+ $maximum_fees_msats: Long!
332
+ $amount_msats: Long
333
+ ) {
334
+ pay_invoice(
335
+ input: {
336
+ node_id: $node_id
337
+ encoded_invoice: $encoded_invoice
338
+ timeout_secs: $timeout_secs
339
+ maximum_fees_msats: $maximum_fees_msats
340
+ amount_msats: $amount_msats
341
+ }
342
+ ) {
343
+ payment {
344
+ ...OutgoingPaymentFragment
345
+ }
346
+ }
347
+ }
348
+
349
+ ${FRAGMENT6}
350
+ `;
351
+
352
+ // src/graphql/RecoverNodeSigningKey.ts
353
+ var RecoverNodeSigningKey = `
354
+ query RecoverNodeSigningKey($nodeId: ID!) {
355
+ entity(id: $nodeId) {
356
+ __typename
357
+ ... on LightsparkNode {
358
+ encrypted_signing_private_key {
359
+ encrypted_value
360
+ cipher
361
+ }
362
+ }
363
+ }
364
+ }
365
+ `;
366
+
367
+ // src/graphql/RequestWithdrawal.ts
368
+ var RequestWithdrawal = `
369
+ mutation RequestWithdrawal(
370
+ $node_id: ID!
371
+ $bitcoin_address: String!
372
+ $amount_sats: Long!
373
+ $withdrawal_mode: WithdrawalMode!
374
+ ) {
375
+ request_withdrawal(input: {
376
+ node_id: $node_id
377
+ bitcoin_address: $bitcoin_address
378
+ amount_sats: $amount_sats
379
+ withdrawal_mode: $withdrawal_mode
380
+ }) {
381
+ request {
382
+ ...WithdrawalRequestFragment
383
+ }
384
+ }
385
+ }
386
+
387
+ ${FRAGMENT7}
388
+ `;
389
+
390
+ // src/graphql/SendPayment.ts
391
+ var SendPayment = `
392
+ mutation SendPayment(
393
+ $node_id: ID!
394
+ $destination_public_key: String!
395
+ $timeout_secs: Int!
396
+ $amount_msats: Long!
397
+ $maximum_fees_msats: Long!
398
+ ) {
399
+ send_payment(
400
+ input: {
401
+ node_id: $node_id
402
+ destination_public_key: $destination_public_key
403
+ timeout_secs: $timeout_secs
404
+ amount_msats: $amount_msats
405
+ maximum_fees_msats: $maximum_fees_msats
406
+ }
407
+ ) {
408
+ payment {
409
+ ...OutgoingPaymentFragment
410
+ }
411
+ }
412
+ }
413
+
414
+ ${FRAGMENT6}
415
+ `;
416
+
417
+ // src/graphql/SingleNodeDashboard.ts
418
+ var SingleNodeDashboard = `
419
+ query SingleNodeDashboard(
420
+ $network: BitcoinNetwork!,
421
+ $nodeId: ID!,
422
+ $numTransactions: Int,
423
+ $transactionsAfterDate: DateTime,
424
+ $transactionTypes: [TransactionType!] = [PAYMENT, PAYMENT_REQUEST, ROUTE, L1_WITHDRAW, L1_DEPOSIT]
425
+ $transaction_statuses: [TransactionStatus!] = null
426
+ ) {
427
+ current_account {
428
+ id
429
+ name
430
+ dashboard_overview_nodes: nodes(
431
+ first: 1
432
+ bitcoin_networks: [$network]
433
+ node_ids: [$nodeId]
434
+ ) {
435
+ count
436
+ entities {
437
+ color
438
+ display_name
439
+ purpose
440
+ id
441
+ addresses(first: 1) {
442
+ entities {
443
+ address
444
+ type
445
+ __typename
446
+ }
447
+ count
448
+ __typename
449
+ }
450
+ public_key
451
+ status
452
+ total_local_balance {
453
+ ...CurrencyAmountFragment
454
+ }
455
+ local_balance {
456
+ ...CurrencyAmountFragment
457
+ }
458
+ remote_balance {
459
+ ...CurrencyAmountFragment
460
+ }
461
+ blockchain_balance {
462
+ confirmed_balance {
463
+ ...CurrencyAmountFragment
464
+ }
465
+ unconfirmed_balance {
466
+ ...CurrencyAmountFragment
467
+ }
468
+ available_balance {
469
+ ...CurrencyAmountFragment
470
+ }
471
+ total_balance {
472
+ ...CurrencyAmountFragment
473
+ }
474
+ __typename
475
+ }
476
+ __typename
477
+ }
478
+ __typename
479
+ }
480
+ blockchain_balance(bitcoin_networks: [$network], node_ids: [$nodeId]) {
481
+ total_balance: total_balance {
482
+ ...CurrencyAmountFragment
483
+ }
484
+ required_reserve {
485
+ ...CurrencyAmountFragment
486
+ }
487
+ available_balance {
488
+ ...CurrencyAmountFragment
489
+ }
490
+ unconfirmed_balance {
491
+ ...CurrencyAmountFragment
492
+ }
493
+ confirmed_balance {
494
+ ...CurrencyAmountFragment
495
+ }
496
+ __typename
497
+ }
498
+ local_balance(bitcoin_networks: [$network], node_ids: [$nodeId]) {
499
+ ...CurrencyAmountFragment
500
+ }
501
+ remote_balance(bitcoin_networks: [$network], node_ids: [$nodeId]) {
502
+ ...CurrencyAmountFragment
503
+ }
504
+ recent_transactions: transactions(
505
+ first: $numTransactions
506
+ types: $transactionTypes
507
+ bitcoin_network: $network
508
+ lightning_node_id: $nodeId
509
+ statuses: $transaction_statuses
510
+ after_date: $transactionsAfterDate
511
+ ) {
512
+ count
513
+ total_amount_transacted {
514
+ ...CurrencyAmountFragment
515
+ }
516
+ entities {
517
+ ...TransactionFragment
518
+ __typename
519
+ }
520
+ __typename
521
+ }
522
+ __typename
523
+ }
524
+ }
525
+
526
+ ${FRAGMENT8}
527
+ ${FRAGMENT}
528
+ `;
529
+
530
+ // src/graphql/TransactionsForNode.ts
531
+ var TransactionsForNode = `
532
+ query TransactionsForNode(
533
+ $network: BitcoinNetwork!,
534
+ $nodeId: ID!,
535
+ $numTransactions: Int,
536
+ $afterDate: DateTime,
537
+ $transactionTypes: [TransactionType!] = [PAYMENT, PAYMENT_REQUEST, ROUTE, L1_WITHDRAW, L1_DEPOSIT]
538
+ $transaction_statuses: [TransactionStatus!] = null
539
+ ) {
540
+ current_account {
541
+ id
542
+ name
543
+ recent_transactions: transactions(
544
+ first: $numTransactions
545
+ types: $transactionTypes
546
+ bitcoin_network: $network
547
+ lightning_node_id: $nodeId
548
+ statuses: $transaction_statuses
549
+ after_date: $afterDate
550
+ ) {
551
+ count
552
+ total_amount_transacted {
553
+ ...CurrencyAmountFragment
554
+ }
555
+ entities {
556
+ ...TransactionFragment
557
+ __typename
558
+ }
559
+ __typename
560
+ }
561
+ __typename
562
+ }
563
+ }
564
+
565
+ ${FRAGMENT8}
566
+ ${FRAGMENT}
567
+ `;
568
+
569
+ // src/graphql/TransactionSubscription.ts
570
+ var TransactionSubscription = `
571
+ subscription TransactionSubscription(
572
+ $nodeIds: [ID!]!
573
+ ) {
574
+ transactions(node_ids: $nodeIds) {
575
+ ...TransactionUpdateFragment
576
+ __typename
577
+ }
578
+ }
579
+
580
+ ${FRAGMENT9}
581
+ `;
582
+
583
+ // src/client.ts
584
+ var LightsparkClient = class {
585
+ /**
586
+ * Constructs a new LightsparkClient.
587
+ *
588
+ * @param authProvider The auth provider to use for authentication. Defaults to a stub auth provider. For server-side
589
+ * use, you should use the `AccountTokenAuthProvider`.
590
+ * @param serverUrl The base URL of the server to connect to. Defaults to lightspark production.
591
+ * @param nodeKeyCache This is used to cache node keys for the duration of the session. Defaults to a new instance of
592
+ * `NodeKeyCache`. You should not need to change this.
593
+ */
594
+ constructor(authProvider = new StubAuthProvider(), serverUrl = "api.lightspark.com", nodeKeyCache = new NodeKeyCache()) {
595
+ this.authProvider = authProvider;
596
+ this.serverUrl = serverUrl;
597
+ this.nodeKeyCache = nodeKeyCache;
598
+ this.requester = new Requester(
599
+ this.nodeKeyCache,
600
+ WALLET_SDK_ENDPOINT,
601
+ authProvider,
602
+ serverUrl
603
+ );
604
+ autoBind2(this);
605
+ }
606
+ requester;
607
+ /**
608
+ * Sets the auth provider for the client. This is useful for switching between auth providers if you are using
609
+ * multiple accounts or waiting for the user to log in.
610
+ *
611
+ * @param authProvider
612
+ */
613
+ async setAuthProvider(authProvider) {
614
+ this.requester = new Requester(
615
+ this.nodeKeyCache,
616
+ WALLET_SDK_ENDPOINT,
617
+ authProvider,
618
+ this.serverUrl
619
+ );
620
+ this.authProvider = authProvider;
621
+ }
622
+ /**
623
+ * @returns Whether or not the client is authorized. This is useful for determining if the user is logged in or not.
624
+ */
625
+ async isAuthorized() {
626
+ return this.authProvider.isAuthorized();
627
+ }
628
+ /**
629
+ * @returns The current account, if one exists.
630
+ */
631
+ async getCurrentAccount() {
632
+ return await this.requester.executeQuery(
633
+ Account_default.getAccountQuery()
634
+ );
635
+ }
636
+ /**
637
+ * Retrieves the most recent transactions for a given node.
638
+ *
639
+ * @param nodeId The node ID for which to read transactions
640
+ * @param numTransactions The maximum number of transactions to read. Defaults to 20.
641
+ * @param bitcoinNetwork The bitcoin network on which to read transactions. Defaults to MAINNET.
642
+ * @param afterDate Filters transactions to those after the given date. Defaults to undefined (no limit).
643
+ * @returns An array of transactions for the given node ID.
644
+ */
645
+ async getRecentTransactions(nodeId, numTransactions = 20, bitcoinNetwork = BitcoinNetwork_default.MAINNET, afterDate = void 0) {
646
+ const response = await this.requester.makeRawRequest(TransactionsForNode, {
647
+ nodeId,
648
+ network: bitcoinNetwork,
649
+ numTransactions,
650
+ afterDate
651
+ });
652
+ return response.current_account?.recent_transactions.entities.map(
653
+ (transaction) => TransactionFromJson(transaction)
654
+ ) ?? [];
655
+ }
656
+ /**
657
+ * Starts listening for new transactions or updates to existing transactions for a list of nodes.
658
+ *
659
+ * @param nodeIds The node IDs for which to listen to transactions.
660
+ * @returns A zen-observable that emits transaction updates for the given node IDs.
661
+ */
662
+ listenToTransactions(nodeIds) {
663
+ const response = this.requester.subscribe(TransactionSubscription, {
664
+ nodeIds
665
+ });
666
+ return response.map(
667
+ (response2) => response2 && response2.data.transactions && TransactionUpdateFromJson(response2.data.transactions)
668
+ );
669
+ }
670
+ /**
671
+ * Retrieves a dashboard of basic info for the authenticated account. See `AccountDashboard` for which info is
672
+ * included.
673
+ *
674
+ * @param nodeIds The node IDs to include in the dashboard. Defaults to undefined (all nodes).
675
+ * @param bitcoinNetwork The bitcoin network to include in the dashboard. Defaults to MAINNET.
676
+ * @returns A basic account dashboard for the given node IDs.
677
+ * @throws LightsparkAuthException if the user is not logged in or a LightsparkException if no nodes are found.
678
+ */
679
+ async getAccountDashboard(nodeIds = void 0, bitcoinNetwork = BitcoinNetwork_default.MAINNET) {
680
+ const response = await this.requester.makeRawRequest(MultiNodeDashboard, {
681
+ nodeIds,
682
+ network: bitcoinNetwork
683
+ });
684
+ if (!response.current_account) {
685
+ throw new LightsparkAuthException("No current account");
686
+ }
687
+ if (!response.current_account.dashboard_overview_nodes || response.current_account.dashboard_overview_nodes.entities.length === 0) {
688
+ throw new LightsparkException(
689
+ "NO_NODES_FOUND",
690
+ `No nodes found for this dashboard request. This could mean one of a few things:
691
+ 1. You are requesting MAINNET nodes, but you have no MAINNET nodes yet. In this case, request BitcoinNetwork.REGTEST instead.
692
+ 2. You are specifying specific node IDs, but those IDs don't exist or are not on the bitcoid network you requested.
693
+ 3. The api token or authentication mechanism you are using is not authorized to access the nodes you requested. If you're using
694
+ an API token, make sure it has the correct permissions for the desired network (only test tokens have access to REGTEST nodes).`
695
+ );
696
+ }
697
+ const account = response.current_account;
698
+ return {
699
+ id: account.id,
700
+ name: account.name,
701
+ nodes: account.dashboard_overview_nodes.entities.map((node) => {
702
+ return {
703
+ color: node.color,
704
+ displayName: node.display_name,
705
+ purpose: node.purpose,
706
+ id: node.id,
707
+ publicKey: node.public_key,
708
+ status: node.status,
709
+ addresses: {
710
+ count: node.addresses.count,
711
+ entities: node.addresses.entities.map((address) => {
712
+ return {
713
+ address: address.address,
714
+ type: address.type
715
+ };
716
+ })
717
+ },
718
+ localBalance: node.local_balance && CurrencyAmountFromJson(node.local_balance),
719
+ remoteBalance: node.remote_balance && CurrencyAmountFromJson(node.remote_balance),
720
+ blockchainBalance: node.blockchain_balance && CurrencyAmountFromJson(node.blockchain_balance)
721
+ };
722
+ }),
723
+ blockchainBalance: !!account.blockchain_balance ? {
724
+ l1Balance: account.blockchain_balance.l1_balance && CurrencyAmountFromJson(account.blockchain_balance.l1_balance),
725
+ requiredReserve: account.blockchain_balance.required_reserve && CurrencyAmountFromJson(
726
+ account.blockchain_balance.required_reserve
727
+ ),
728
+ availableBalance: account.blockchain_balance.available_balance && CurrencyAmountFromJson(
729
+ account.blockchain_balance.available_balance
730
+ ),
731
+ unconfirmedBalance: account.blockchain_balance.unconfirmed_balance && CurrencyAmountFromJson(
732
+ account.blockchain_balance.unconfirmed_balance
733
+ )
734
+ } : null,
735
+ localBalance: account.local_balance && CurrencyAmountFromJson(account.local_balance),
736
+ remoteBalance: account.remote_balance && CurrencyAmountFromJson(account.remote_balance)
737
+ };
738
+ }
739
+ /**
740
+ * Gets a basic dashboard for a single node, including recent transactions. See `WalletDashboard` for which info is
741
+ * included.
742
+ *
743
+ * @param nodeId The node ID for which to get a dashboard.
744
+ * @param bitcoinNetwork The bitcoin network for which to get a dashboard. Defaults to MAINNET.
745
+ * @param transactionsAfterDate Filters recent transactions to those after the given date.
746
+ * Defaults to undefined (no limit).
747
+ * @returns A basic dashboard for the given node ID.
748
+ */
749
+ async getSingleNodeDashboard(nodeId, bitcoinNetwork = BitcoinNetwork_default.MAINNET, transactionsAfterDate = void 0) {
750
+ const response = await this.requester.makeRawRequest(SingleNodeDashboard, {
751
+ nodeId,
752
+ network: bitcoinNetwork,
753
+ numTransactions: 20,
754
+ transactionsAfterDate
755
+ });
756
+ if (!response.current_account) {
757
+ throw new LightsparkAuthException("No current account");
758
+ }
759
+ const account = response.current_account;
760
+ if (!account.dashboard_overview_nodes || !account.dashboard_overview_nodes.entities || account.dashboard_overview_nodes.entities.length === 0) {
761
+ throw new LightsparkException(
762
+ "InvalidOrMissingNode",
763
+ "No nodes found for node dashboard"
764
+ );
765
+ }
766
+ const node = account.dashboard_overview_nodes.entities[0];
767
+ const nodeAddresses = node.addresses.entities.map((address) => {
768
+ return {
769
+ address: address.address,
770
+ type: address.type
771
+ };
772
+ });
773
+ const currencyAmountOrUndefined = (json) => {
774
+ return json && CurrencyAmountFromJson(json);
775
+ };
776
+ return {
777
+ color: node.color,
778
+ displayName: account.name,
779
+ purpose: node.purpose,
780
+ id: node.id,
781
+ publicKey: node.public_key,
782
+ status: node.status,
783
+ addresses: nodeAddresses,
784
+ totalBalance: currencyAmountOrUndefined(node.total_balance),
785
+ totalLocalBalance: currencyAmountOrUndefined(node.total_local_balance),
786
+ onlineLocalBalance: currencyAmountOrUndefined(node.local_balance),
787
+ remoteBalance: currencyAmountOrUndefined(node.remote_balance),
788
+ blockchainBalance: node.blockchain_balance && {
789
+ availableBalance: currencyAmountOrUndefined(
790
+ node.blockchain_balance.available_balance
791
+ ),
792
+ confirmedBalance: currencyAmountOrUndefined(
793
+ node.blockchain_balance.confirmed_balance
794
+ ),
795
+ unconfirmedBalance: currencyAmountOrUndefined(
796
+ node.blockchain_balance.unconfirmed_balance
797
+ ),
798
+ totalBalance: currencyAmountOrUndefined(
799
+ node.blockchain_balance.total_balance
800
+ )
801
+ },
802
+ recentTransactions: account.recent_transactions?.entities.map((tx) => {
803
+ return TransactionFromJson(tx);
804
+ }) || []
805
+ };
806
+ }
807
+ /**
808
+ * Creates an invoice for the given node.
809
+ *
810
+ * @param nodeId The node ID for which to create an invoice.
811
+ * @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
812
+ * @param memo A string memo to include in the invoice as a description.
813
+ * @param type The type of invoice to create. Defaults to a normal payment invoice, but you can pass InvoiceType.AMP
814
+ * to create an [AMP invoice](https://docs.lightning.engineering/lightning-network-tools/lnd/amp), which can be
815
+ * paid multiple times.
816
+ * @returns An encoded payment request for the invoice, or undefined if the invoice could not be created.
817
+ */
818
+ async createInvoice(nodeId, amountMsats, memo, type = void 0) {
819
+ const response = await this.requester.makeRawRequest(CreateInvoice, {
820
+ node_id: nodeId,
821
+ amount_msats: amountMsats,
822
+ memo,
823
+ type
824
+ });
825
+ return response.create_invoice?.invoice.data?.encoded_payment_request;
826
+ }
827
+ /**
828
+ * Decodes an encoded lightning invoice string.
829
+ *
830
+ * @param encodedInvoice The string encoded invoice to decode.
831
+ * @returns Decoded invoice data.
832
+ */
833
+ async decodeInvoice(encodedInvoice) {
834
+ const response = await this.requester.makeRawRequest(DecodeInvoice, {
835
+ encoded_payment_request: encodedInvoice
836
+ });
837
+ return InvoiceDataFromJson(response.decoded_payment_request);
838
+ }
839
+ /**
840
+ * Gets an estimate of the fee for sending a payment over the given bitcoin network.
841
+ *
842
+ * @param bitcoinNetwork The bitcoin network for which to get a fee estimate. Defaults to MAINNET.
843
+ * @returns A fee estimate for the given bitcoin network including a minimum fee rate, and a max-speed fee rate.
844
+ */
845
+ async getBitcoinFeeEstimate(bitcoinNetwork = BitcoinNetwork_default.MAINNET) {
846
+ const response = await this.requester.makeRawRequest(
847
+ BitcoinFeeEstimate,
848
+ {
849
+ bitcoin_network: bitcoinNetwork
850
+ }
851
+ );
852
+ return FeeEstimateFromJson(response.bitcoin_fee_estimate);
853
+ }
854
+ /**
855
+ * Gets an estimate of the fees that will be paid for a Lightning invoice.
856
+ *
857
+ * @param nodeId The node from where you want to send the payment.
858
+ * @param encodedPaymentRequest The invoice you want to pay (as defined by the BOLT11 standard).
859
+ * @param amountMsats If the invoice does not specify a payment amount, then the amount that you wish to pay,
860
+ * expressed in msats.
861
+ * @returns An estimate of the fees that will be paid for a Lightning invoice.
862
+ */
863
+ async getLightningFeeEstimateForInvoice(nodeId, encodedPaymentRequest, amountMsats = void 0) {
864
+ const response = await this.requester.makeRawRequest(
865
+ LightningFeeEstimateForInvoice,
866
+ {
867
+ node_id: nodeId,
868
+ encoded_payment_request: encodedPaymentRequest,
869
+ amount_msats: amountMsats
870
+ }
871
+ );
872
+ return CurrencyAmountFromJson(
873
+ response.lightning_fee_estimate_for_invoice.fee_estimate
874
+ );
875
+ }
876
+ /**
877
+ * Returns an estimate of the fees that will be paid to send a payment to another Lightning node.
878
+ *
879
+ * @param nodeId The node from where you want to send the payment.
880
+ * @param destinationNodePublicKey The public key of the node that you want to pay.
881
+ * @param amountMsats The payment amount expressed in msats.
882
+ * @returns An estimate of the fees that will be paid to send a payment to another Lightning node.
883
+ */
884
+ async getLightningFeeEstimateForNode(nodeId, destinationNodePublicKey, amountMsats) {
885
+ const response = await this.requester.makeRawRequest(
886
+ LightningFeeEstimateForNode,
887
+ {
888
+ node_id: nodeId,
889
+ destination_node_public_key: destinationNodePublicKey,
890
+ amount_msats: amountMsats
891
+ }
892
+ );
893
+ return CurrencyAmountFromJson(
894
+ response.lightning_fee_estimate_for_node.fee_estimate
895
+ );
896
+ }
897
+ /**
898
+ * Unlock the given node for sensitive operations like sending payments.
899
+ *
900
+ * @param nodeId The ID of the node to unlock.
901
+ * @param password The node password assigned at node creation.
902
+ * @returns True if the node was unlocked successfully, false otherwise.
903
+ */
904
+ async unlockNode(nodeId, password) {
905
+ const encryptedKey = await this.recoverNodeSigningKey(nodeId);
906
+ if (!encryptedKey) {
907
+ console.warn("No encrypted key found for node " + nodeId);
908
+ return false;
909
+ }
910
+ const signingPrivateKey = await decryptSecretWithNodePassword(
911
+ encryptedKey.cipher,
912
+ encryptedKey.encrypted_value,
913
+ password
914
+ );
915
+ if (!signingPrivateKey) {
916
+ throw new LightsparkSigningException(
917
+ "Unable to decrypt signing key with provided password. Please try again."
918
+ );
919
+ }
920
+ let signingPrivateKeyPEM = "";
921
+ if (new Uint8Array(signingPrivateKey)[0] === 48) {
922
+ signingPrivateKeyPEM = b64encode2(signingPrivateKey);
923
+ } else {
924
+ const dec = new TextDecoder();
925
+ signingPrivateKeyPEM = dec.decode(signingPrivateKey);
926
+ }
927
+ await this.nodeKeyCache.loadKey(nodeId, signingPrivateKeyPEM);
928
+ return true;
929
+ }
930
+ async recoverNodeSigningKey(nodeId) {
931
+ const response = await this.requester.makeRawRequest(
932
+ RecoverNodeSigningKey,
933
+ { nodeId }
934
+ );
935
+ const nodeEntity = response.entity;
936
+ if (nodeEntity?.__typename === "LightsparkNode") {
937
+ return nodeEntity.encrypted_signing_private_key;
938
+ }
939
+ return null;
940
+ }
941
+ /**
942
+ * Directly unlocks a node with a signing private key.
943
+ *
944
+ * @param nodeId The ID of the node to unlock.
945
+ * @param signingPrivateKeyPEM The PEM-encoded signing private key.
946
+ */
947
+ async loadNodeKey(nodeId, signingPrivateKeyPEM) {
948
+ await this.nodeKeyCache.loadKey(nodeId, signingPrivateKeyPEM);
949
+ }
950
+ /**
951
+ * Sends a lightning payment for a given invoice.
952
+ *
953
+ * @param payerNodeId The ID of the node that will pay the invoice.
954
+ * @param encodedInvoice The encoded invoice to pay.
955
+ * @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
956
+ * As guidance, a maximum fee of 16 basis points should make almost all transactions succeed. For example,
957
+ * for a transaction between 10k sats and 100k sats, this would mean a fee limit of 16 to 160 sats.
958
+ * @param timeoutSecs A timeout for the payment in seconds. Defaults to 60 seconds.
959
+ * @param amountMsats The amount to pay in msats for a zero-amount invoice. Defaults to the full amount of the
960
+ * invoice. NOTE: This parameter can only be passed for a zero-amount invoice. Otherwise, the call will fail.
961
+ * @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
962
+ */
963
+ async payInvoice(payerNodeId, encodedInvoice, maximumFeesMsats, timeoutSecs = 60, amountMsats = void 0) {
964
+ if (!this.nodeKeyCache.hasKey(payerNodeId)) {
965
+ throw new LightsparkSigningException("Paying node is not unlocked");
966
+ }
967
+ const variables = {
968
+ node_id: payerNodeId,
969
+ encoded_invoice: encodedInvoice,
970
+ timeout_secs: timeoutSecs,
971
+ maximum_fees_msats: maximumFeesMsats
972
+ };
973
+ if (amountMsats !== void 0) {
974
+ variables.amount_msats = amountMsats;
975
+ }
976
+ const response = await this.requester.makeRawRequest(
977
+ PayInvoice,
978
+ variables,
979
+ payerNodeId
980
+ );
981
+ if (response.pay_invoice?.payment.outgoing_payment_failure_message) {
982
+ throw new LightsparkException(
983
+ "PaymentError",
984
+ response.pay_invoice?.payment.outgoing_payment_failure_message.rich_text_text
985
+ );
986
+ }
987
+ return response.pay_invoice && OutgoingPaymentFromJson(response.pay_invoice.payment);
988
+ }
989
+ /**
990
+ * Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.
991
+ *
992
+ * @param payerNodeId The ID of the node that will send the payment.
993
+ * @param destinationPublicKey The public key of the destination node.
994
+ * @param timeoutSecs The timeout in seconds that we will try to make the payment.
995
+ * @param amountMsats The amount to pay in msats.
996
+ * @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
997
+ * As guidance, a maximum fee of 15 basis points should make almost all transactions succeed. For example,
998
+ * for a transaction between 10k sats and 100k sats, this would mean a fee limit of 15 to 150 sats.
999
+ * @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
1000
+ */
1001
+ async sendPayment(payerNodeId, destinationPublicKey, timeoutSecs = 60, amountMsats, maximumFeesMsats) {
1002
+ if (!this.nodeKeyCache.hasKey(payerNodeId)) {
1003
+ throw new LightsparkSigningException("Paying node is not unlocked");
1004
+ }
1005
+ const response = await this.requester.makeRawRequest(
1006
+ SendPayment,
1007
+ {
1008
+ node_id: payerNodeId,
1009
+ destination_public_key: destinationPublicKey,
1010
+ timeout_secs: timeoutSecs,
1011
+ amount_msats: amountMsats,
1012
+ maximum_fees_msats: maximumFeesMsats
1013
+ },
1014
+ payerNodeId
1015
+ );
1016
+ if (response.send_payment?.payment.outgoing_payment_failure_message) {
1017
+ throw new LightsparkException(
1018
+ "PaymentError",
1019
+ response.send_payment?.payment.outgoing_payment_failure_message.rich_text_text
1020
+ );
1021
+ }
1022
+ return response.send_payment && OutgoingPaymentFromJson(response.send_payment.payment);
1023
+ }
1024
+ /**
1025
+ * Creates an L1 Bitcoin wallet address for a given node which can be used to deposit or withdraw funds.
1026
+ *
1027
+ * @param nodeId The ID of the node to create a wallet address for.
1028
+ * @returns A string containing the wallet address for the given node.
1029
+ */
1030
+ async createNodeWalletAddress(nodeId) {
1031
+ const response = await this.requester.makeRawRequest(
1032
+ CreateNodeWalletAddress,
1033
+ { node_id: nodeId }
1034
+ );
1035
+ return response.create_node_wallet_address.wallet_address;
1036
+ }
1037
+ /**
1038
+ * Withdraws funds from the account and sends it to the requested bitcoin address.
1039
+ *
1040
+ * Depending on the chosen mode, it will first take the funds from the wallet, and if applicable, close channels
1041
+ * appropriately to recover enough funds and reopen channels with the remaining funds.
1042
+ * The process is asynchronous and may take up to a few minutes. You can check the progress by polling the
1043
+ * `WithdrawalRequest` that is created, or by subscribing to a webhook.
1044
+ *
1045
+ * @param nodeId The ID of the node from which to withdraw funds.
1046
+ * @param amountSats The amount of funds to withdraw in satoshis.
1047
+ * @param bitcoinAddress The Bitcoin address to withdraw funds to.
1048
+ * @param mode The mode to use for the withdrawal. See `WithdrawalMode` for more information.
1049
+ */
1050
+ async requestWithdrawal(nodeId, amountSats, bitcoinAddress, mode) {
1051
+ const response = await this.requester.makeRawRequest(
1052
+ RequestWithdrawal,
1053
+ {
1054
+ node_id: nodeId,
1055
+ amount_sats: amountSats,
1056
+ bitcoin_address: bitcoinAddress,
1057
+ withdrawal_mode: mode
1058
+ },
1059
+ nodeId
1060
+ );
1061
+ return WithdrawalRequestFromJson(response.request_withdrawal.request);
1062
+ }
1063
+ /**
1064
+ * Adds funds to a Lightspark node on the REGTEST network. If the amount is not specified, 10,000,000 SATOSHI will be
1065
+ * added. This API only functions for nodes created on the REGTEST network and will return an error when called for
1066
+ * any non-REGTEST node.
1067
+ *
1068
+ * @param nodeId The ID of the node to fund. Must be a REGTEST node.
1069
+ * @param amountSats The amount of funds to add to the node in satoshis. Defaults to 10,000,000 SATOSHI.
1070
+ * @returns
1071
+ */
1072
+ async fundNode(nodeId, amountSats = void 0) {
1073
+ const response = await this.requester.makeRawRequest(FundNode, {
1074
+ node_id: nodeId,
1075
+ amount_sats: amountSats
1076
+ });
1077
+ return CurrencyAmountFromJson(response.fund_node.amount);
1078
+ }
1079
+ /**
1080
+ * Creates a new API token that can be used to authenticate requests for this account when using the Lightspark APIs
1081
+ * and SDKs.
1082
+ *
1083
+ * @param name Creates a new API token that can be used to authenticate requests for this account when using the
1084
+ * Lightspark APIs and SDKs.
1085
+ * @param transact Whether the token should be able to transact or only view data.
1086
+ * @param testMode True if the token should be able to access only testnet false to access only mainnet.
1087
+ * @returns An object containing the API token and client secret.
1088
+ */
1089
+ async createApiToken(name, transact = true, testMode = true) {
1090
+ let permissions;
1091
+ if (transact && testMode) {
1092
+ permissions = [Permission_default.REGTEST_VIEW, Permission_default.REGTEST_TRANSACT];
1093
+ } else if (transact && !testMode) {
1094
+ permissions = [Permission_default.MAINNET_VIEW, Permission_default.MAINNET_TRANSACT];
1095
+ } else if (!transact && testMode) {
1096
+ permissions = [Permission_default.REGTEST_VIEW];
1097
+ } else {
1098
+ permissions = [Permission_default.MAINNET_VIEW];
1099
+ }
1100
+ const response = await this.requester.makeRawRequest(CreateApiToken, {
1101
+ name,
1102
+ permissions
1103
+ });
1104
+ return {
1105
+ apiToken: ApiTokenFromJson(response.create_api_token.api_token),
1106
+ clientSecret: response.create_api_token.client_secret
1107
+ };
1108
+ }
1109
+ /**
1110
+ * Deletes an existing API token from this account.
1111
+ *
1112
+ * @param id The ID of the API token to delete.
1113
+ */
1114
+ async deleteApiToken(id) {
1115
+ await this.requester.makeRawRequest(DeleteApiToken, { api_token_id: id });
1116
+ }
1117
+ /**
1118
+ * Executes a raw `Query` against the Lightspark API.
1119
+ *
1120
+ * This generally should not be used directly, but is exposed for advanced use cases and for internal use to retrieve
1121
+ * complex fields from objects.
1122
+ *
1123
+ * @param query The `Query` to execute.
1124
+ * @returns The result of the query.
1125
+ */
1126
+ executeRawQuery(query) {
1127
+ return this.requester.executeQuery(query);
1128
+ }
1129
+ };
1130
+ var WALLET_SDK_ENDPOINT = "graphql/server/2023-04-04";
1131
+ var client_default = LightsparkClient;
1132
+ export {
1133
+ Account_default as Account,
1134
+ AccountToChannelsConnection_default as AccountToChannelsConnection,
1135
+ AccountTokenAuthProvider_default as AccountTokenAuthProvider,
1136
+ BitcoinNetwork_default as BitcoinNetwork,
1137
+ Channel_default as Channel,
1138
+ ChannelStatus_default as ChannelStatus,
1139
+ CurrencyUnit_default as CurrencyUnit,
1140
+ GraphNode_default as GraphNode,
1141
+ HtlcAttemptFailureCode_default as HtlcAttemptFailureCode,
1142
+ IncomingPayment_default as IncomingPayment,
1143
+ IncomingPaymentAttemptStatus_default as IncomingPaymentAttemptStatus,
1144
+ InvoiceType_default as InvoiceType,
1145
+ client_default as LightsparkClient,
1146
+ LightsparkNode_default as LightsparkNode,
1147
+ LightsparkNodePurpose_default as LightsparkNodePurpose,
1148
+ LightsparkNodeStatus_default as LightsparkNodeStatus,
1149
+ Node_default as Node,
1150
+ NodeAddressType_default as NodeAddressType,
1151
+ OutgoingPayment_default as OutgoingPayment,
1152
+ OutgoingPaymentAttempt_default as OutgoingPaymentAttempt,
1153
+ OutgoingPaymentAttemptStatus_default as OutgoingPaymentAttemptStatus,
1154
+ PaymentFailureReason_default as PaymentFailureReason,
1155
+ PaymentRequestStatus_default as PaymentRequestStatus,
1156
+ Permission_default as Permission,
1157
+ RoutingTransactionFailureReason_default as RoutingTransactionFailureReason,
1158
+ TransactionStatus_default as TransactionStatus,
1159
+ TransactionType_default as TransactionType,
1160
+ WebhookEventType_default as WebhookEventType,
1161
+ WithdrawalMode_default as WithdrawalMode,
1162
+ WithdrawalRequest_default as WithdrawalRequest,
1163
+ WithdrawalRequestStatus_default as WithdrawalRequestStatus,
1164
+ getApiTokenQuery,
1165
+ getChannelClosingTransactionQuery,
1166
+ getChannelOpeningTransactionQuery,
1167
+ getDepositQuery,
1168
+ getHopQuery,
1169
+ getIncomingPaymentAttemptQuery,
1170
+ getInvoiceQuery,
1171
+ getLightningTransactionQuery,
1172
+ getOnChainTransactionQuery,
1173
+ getPaymentRequestQuery,
1174
+ getRoutingTransactionQuery,
1175
+ getTransactionQuery,
1176
+ getWithdrawalQuery
1177
+ };