@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
@@ -0,0 +1,319 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import { Query } from "@lightsparkdev/core";
4
+ import autoBind from "auto-bind";
5
+ import LightsparkClient from "../client.js";
6
+ import CurrencyAmount, { CurrencyAmountFromJson } from "./CurrencyAmount.js";
7
+ import LightningTransaction from "./LightningTransaction.js";
8
+ import OutgoingPaymentToAttemptsConnection, {
9
+ OutgoingPaymentToAttemptsConnectionFromJson,
10
+ } from "./OutgoingPaymentToAttemptsConnection.js";
11
+ import PaymentFailureReason from "./PaymentFailureReason.js";
12
+ import PaymentRequestData, {
13
+ PaymentRequestDataFromJson,
14
+ } from "./PaymentRequestData.js";
15
+ import RichText, { RichTextFromJson } from "./RichText.js";
16
+ import TransactionStatus from "./TransactionStatus.js";
17
+
18
+ /** A transaction that was sent from a Lightspark node on the Lightning Network. **/
19
+ class OutgoingPayment implements LightningTransaction {
20
+ constructor(
21
+ public readonly id: string,
22
+ public readonly createdAt: string,
23
+ public readonly updatedAt: string,
24
+ public readonly status: TransactionStatus,
25
+ public readonly amount: CurrencyAmount,
26
+ public readonly originId: string,
27
+ public readonly typename: string,
28
+ public readonly resolvedAt?: string,
29
+ public readonly transactionHash?: string,
30
+ public readonly destinationId?: string,
31
+ public readonly fees?: CurrencyAmount,
32
+ public readonly paymentRequestData?: PaymentRequestData,
33
+ public readonly failureReason?: PaymentFailureReason,
34
+ public readonly failureMessage?: RichText
35
+ ) {
36
+ autoBind(this);
37
+ }
38
+
39
+ public async getAttempts(
40
+ client: LightsparkClient,
41
+ first: number | undefined = undefined
42
+ ): Promise<OutgoingPaymentToAttemptsConnection> {
43
+ return (await client.executeRawQuery({
44
+ queryPayload: `
45
+ query FetchOutgoingPaymentToAttemptsConnection($entity_id: ID!, $first: Int) {
46
+ entity(id: $entity_id) {
47
+ ... on OutgoingPayment {
48
+ attempts(, first: $first) {
49
+ __typename
50
+ outgoing_payment_to_attempts_connection_count: count
51
+ outgoing_payment_to_attempts_connection_entities: entities {
52
+ __typename
53
+ outgoing_payment_attempt_id: id
54
+ outgoing_payment_attempt_created_at: created_at
55
+ outgoing_payment_attempt_updated_at: updated_at
56
+ outgoing_payment_attempt_status: status
57
+ outgoing_payment_attempt_failure_code: failure_code
58
+ outgoing_payment_attempt_failure_source_index: failure_source_index
59
+ outgoing_payment_attempt_resolved_at: resolved_at
60
+ outgoing_payment_attempt_amount: amount {
61
+ __typename
62
+ currency_amount_original_value: original_value
63
+ currency_amount_original_unit: original_unit
64
+ currency_amount_preferred_currency_unit: preferred_currency_unit
65
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
66
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
67
+ }
68
+ outgoing_payment_attempt_fees: fees {
69
+ __typename
70
+ currency_amount_original_value: original_value
71
+ currency_amount_original_unit: original_unit
72
+ currency_amount_preferred_currency_unit: preferred_currency_unit
73
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
74
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
75
+ }
76
+ outgoing_payment_attempt_outgoing_payment: outgoing_payment {
77
+ id
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }
84
+ `,
85
+ variables: { entity_id: this.id, first: first },
86
+ constructObject: (json) => {
87
+ const connection = json["entity"]["attempts"];
88
+ return OutgoingPaymentToAttemptsConnectionFromJson(connection);
89
+ },
90
+ }))!;
91
+ }
92
+
93
+ static getOutgoingPaymentQuery(id: string): Query<OutgoingPayment> {
94
+ return {
95
+ queryPayload: `
96
+ query GetOutgoingPayment($id: ID!) {
97
+ entity(id: $id) {
98
+ ... on OutgoingPayment {
99
+ ...OutgoingPaymentFragment
100
+ }
101
+ }
102
+ }
103
+
104
+ ${FRAGMENT}
105
+ `,
106
+ variables: { id },
107
+ constructObject: (data: any) => OutgoingPaymentFromJson(data.entity),
108
+ };
109
+ }
110
+ }
111
+
112
+ export const OutgoingPaymentFromJson = (obj: any): OutgoingPayment => {
113
+ return new OutgoingPayment(
114
+ obj["outgoing_payment_id"],
115
+ obj["outgoing_payment_created_at"],
116
+ obj["outgoing_payment_updated_at"],
117
+ TransactionStatus[obj["outgoing_payment_status"]] ??
118
+ TransactionStatus.FUTURE_VALUE,
119
+ CurrencyAmountFromJson(obj["outgoing_payment_amount"]),
120
+ obj["outgoing_payment_origin"].id,
121
+ "OutgoingPayment",
122
+ obj["outgoing_payment_resolved_at"],
123
+ obj["outgoing_payment_transaction_hash"],
124
+ obj["outgoing_payment_destination"]?.id ?? undefined,
125
+ !!obj["outgoing_payment_fees"]
126
+ ? CurrencyAmountFromJson(obj["outgoing_payment_fees"])
127
+ : undefined,
128
+ !!obj["outgoing_payment_payment_request_data"]
129
+ ? PaymentRequestDataFromJson(obj["outgoing_payment_payment_request_data"])
130
+ : undefined,
131
+ !!obj["outgoing_payment_failure_reason"]
132
+ ? PaymentFailureReason[obj["outgoing_payment_failure_reason"]] ??
133
+ PaymentFailureReason.FUTURE_VALUE
134
+ : null,
135
+ !!obj["outgoing_payment_failure_message"]
136
+ ? RichTextFromJson(obj["outgoing_payment_failure_message"])
137
+ : undefined
138
+ );
139
+ };
140
+
141
+ export const FRAGMENT = `
142
+ fragment OutgoingPaymentFragment on OutgoingPayment {
143
+ __typename
144
+ outgoing_payment_id: id
145
+ outgoing_payment_created_at: created_at
146
+ outgoing_payment_updated_at: updated_at
147
+ outgoing_payment_status: status
148
+ outgoing_payment_resolved_at: resolved_at
149
+ outgoing_payment_amount: amount {
150
+ __typename
151
+ currency_amount_original_value: original_value
152
+ currency_amount_original_unit: original_unit
153
+ currency_amount_preferred_currency_unit: preferred_currency_unit
154
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
155
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
156
+ }
157
+ outgoing_payment_transaction_hash: transaction_hash
158
+ outgoing_payment_origin: origin {
159
+ id
160
+ }
161
+ outgoing_payment_destination: destination {
162
+ id
163
+ }
164
+ outgoing_payment_fees: fees {
165
+ __typename
166
+ currency_amount_original_value: original_value
167
+ currency_amount_original_unit: original_unit
168
+ currency_amount_preferred_currency_unit: preferred_currency_unit
169
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
170
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
171
+ }
172
+ outgoing_payment_payment_request_data: payment_request_data {
173
+ __typename
174
+ ... on InvoiceData {
175
+ __typename
176
+ invoice_data_encoded_payment_request: encoded_payment_request
177
+ invoice_data_bitcoin_network: bitcoin_network
178
+ invoice_data_payment_hash: payment_hash
179
+ invoice_data_amount: amount {
180
+ __typename
181
+ currency_amount_original_value: original_value
182
+ currency_amount_original_unit: original_unit
183
+ currency_amount_preferred_currency_unit: preferred_currency_unit
184
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
185
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
186
+ }
187
+ invoice_data_created_at: created_at
188
+ invoice_data_expires_at: expires_at
189
+ invoice_data_destination: destination {
190
+ __typename
191
+ ... on GraphNode {
192
+ __typename
193
+ graph_node_id: id
194
+ graph_node_created_at: created_at
195
+ graph_node_updated_at: updated_at
196
+ graph_node_alias: alias
197
+ graph_node_bitcoin_network: bitcoin_network
198
+ graph_node_color: color
199
+ graph_node_conductivity: conductivity
200
+ graph_node_display_name: display_name
201
+ graph_node_public_key: public_key
202
+ }
203
+ ... on LightsparkNode {
204
+ __typename
205
+ lightspark_node_id: id
206
+ lightspark_node_created_at: created_at
207
+ lightspark_node_updated_at: updated_at
208
+ lightspark_node_alias: alias
209
+ lightspark_node_bitcoin_network: bitcoin_network
210
+ lightspark_node_color: color
211
+ lightspark_node_conductivity: conductivity
212
+ lightspark_node_display_name: display_name
213
+ lightspark_node_public_key: public_key
214
+ lightspark_node_account: account {
215
+ id
216
+ }
217
+ lightspark_node_blockchain_balance: blockchain_balance {
218
+ __typename
219
+ blockchain_balance_total_balance: total_balance {
220
+ __typename
221
+ currency_amount_original_value: original_value
222
+ currency_amount_original_unit: original_unit
223
+ currency_amount_preferred_currency_unit: preferred_currency_unit
224
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
225
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
226
+ }
227
+ blockchain_balance_confirmed_balance: confirmed_balance {
228
+ __typename
229
+ currency_amount_original_value: original_value
230
+ currency_amount_original_unit: original_unit
231
+ currency_amount_preferred_currency_unit: preferred_currency_unit
232
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
233
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
234
+ }
235
+ blockchain_balance_unconfirmed_balance: unconfirmed_balance {
236
+ __typename
237
+ currency_amount_original_value: original_value
238
+ currency_amount_original_unit: original_unit
239
+ currency_amount_preferred_currency_unit: preferred_currency_unit
240
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
241
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
242
+ }
243
+ blockchain_balance_locked_balance: locked_balance {
244
+ __typename
245
+ currency_amount_original_value: original_value
246
+ currency_amount_original_unit: original_unit
247
+ currency_amount_preferred_currency_unit: preferred_currency_unit
248
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
249
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
250
+ }
251
+ blockchain_balance_required_reserve: required_reserve {
252
+ __typename
253
+ currency_amount_original_value: original_value
254
+ currency_amount_original_unit: original_unit
255
+ currency_amount_preferred_currency_unit: preferred_currency_unit
256
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
257
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
258
+ }
259
+ blockchain_balance_available_balance: available_balance {
260
+ __typename
261
+ currency_amount_original_value: original_value
262
+ currency_amount_original_unit: original_unit
263
+ currency_amount_preferred_currency_unit: preferred_currency_unit
264
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
265
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
266
+ }
267
+ }
268
+ lightspark_node_encrypted_signing_private_key: encrypted_signing_private_key {
269
+ __typename
270
+ secret_encrypted_value: encrypted_value
271
+ secret_cipher: cipher
272
+ }
273
+ lightspark_node_total_balance: total_balance {
274
+ __typename
275
+ currency_amount_original_value: original_value
276
+ currency_amount_original_unit: original_unit
277
+ currency_amount_preferred_currency_unit: preferred_currency_unit
278
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
279
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
280
+ }
281
+ lightspark_node_total_local_balance: total_local_balance {
282
+ __typename
283
+ currency_amount_original_value: original_value
284
+ currency_amount_original_unit: original_unit
285
+ currency_amount_preferred_currency_unit: preferred_currency_unit
286
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
287
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
288
+ }
289
+ lightspark_node_local_balance: local_balance {
290
+ __typename
291
+ currency_amount_original_value: original_value
292
+ currency_amount_original_unit: original_unit
293
+ currency_amount_preferred_currency_unit: preferred_currency_unit
294
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
295
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
296
+ }
297
+ lightspark_node_purpose: purpose
298
+ lightspark_node_remote_balance: remote_balance {
299
+ __typename
300
+ currency_amount_original_value: original_value
301
+ currency_amount_original_unit: original_unit
302
+ currency_amount_preferred_currency_unit: preferred_currency_unit
303
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
304
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
305
+ }
306
+ lightspark_node_status: status
307
+ }
308
+ }
309
+ invoice_data_memo: memo
310
+ }
311
+ }
312
+ outgoing_payment_failure_reason: failure_reason
313
+ outgoing_payment_failure_message: failure_message {
314
+ __typename
315
+ rich_text_text: text
316
+ }
317
+ }`;
318
+
319
+ export default OutgoingPayment;
@@ -0,0 +1,164 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import { Query } from "@lightsparkdev/core";
4
+ import autoBind from "auto-bind";
5
+ import LightsparkClient from "../client.js";
6
+ import CurrencyAmount, { CurrencyAmountFromJson } from "./CurrencyAmount.js";
7
+ import Entity from "./Entity.js";
8
+ import HtlcAttemptFailureCode from "./HtlcAttemptFailureCode.js";
9
+ import OutgoingPaymentAttemptStatus from "./OutgoingPaymentAttemptStatus.js";
10
+ import OutgoingPaymentAttemptToHopsConnection, {
11
+ OutgoingPaymentAttemptToHopsConnectionFromJson,
12
+ } from "./OutgoingPaymentAttemptToHopsConnection.js";
13
+
14
+ /** An attempt for a payment over a route from sender node to recipient node. **/
15
+ class OutgoingPaymentAttempt implements Entity {
16
+ constructor(
17
+ public readonly id: string,
18
+ public readonly createdAt: string,
19
+ public readonly updatedAt: string,
20
+ public readonly status: OutgoingPaymentAttemptStatus,
21
+ public readonly outgoingPaymentId: string,
22
+ public readonly typename: string,
23
+ public readonly failureCode?: HtlcAttemptFailureCode,
24
+ public readonly failureSourceIndex?: number,
25
+ public readonly resolvedAt?: string,
26
+ public readonly amount?: CurrencyAmount,
27
+ public readonly fees?: CurrencyAmount
28
+ ) {
29
+ autoBind(this);
30
+ }
31
+
32
+ public async getHops(
33
+ client: LightsparkClient,
34
+ first: number | undefined = undefined
35
+ ): Promise<OutgoingPaymentAttemptToHopsConnection> {
36
+ return (await client.executeRawQuery({
37
+ queryPayload: `
38
+ query FetchOutgoingPaymentAttemptToHopsConnection($entity_id: ID!, $first: Int) {
39
+ entity(id: $entity_id) {
40
+ ... on OutgoingPaymentAttempt {
41
+ hops(, first: $first) {
42
+ __typename
43
+ outgoing_payment_attempt_to_hops_connection_count: count
44
+ outgoing_payment_attempt_to_hops_connection_entities: entities {
45
+ __typename
46
+ hop_id: id
47
+ hop_created_at: created_at
48
+ hop_updated_at: updated_at
49
+ hop_destination: destination {
50
+ id
51
+ }
52
+ hop_index: index
53
+ hop_public_key: public_key
54
+ hop_amount_to_forward: amount_to_forward {
55
+ __typename
56
+ currency_amount_original_value: original_value
57
+ currency_amount_original_unit: original_unit
58
+ currency_amount_preferred_currency_unit: preferred_currency_unit
59
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
60
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
61
+ }
62
+ hop_fee: fee {
63
+ __typename
64
+ currency_amount_original_value: original_value
65
+ currency_amount_original_unit: original_unit
66
+ currency_amount_preferred_currency_unit: preferred_currency_unit
67
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
68
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
69
+ }
70
+ hop_expiry_block_height: expiry_block_height
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ `,
77
+ variables: { entity_id: this.id, first: first },
78
+ constructObject: (json) => {
79
+ const connection = json["entity"]["hops"];
80
+ return OutgoingPaymentAttemptToHopsConnectionFromJson(connection);
81
+ },
82
+ }))!;
83
+ }
84
+
85
+ static getOutgoingPaymentAttemptQuery(
86
+ id: string
87
+ ): Query<OutgoingPaymentAttempt> {
88
+ return {
89
+ queryPayload: `
90
+ query GetOutgoingPaymentAttempt($id: ID!) {
91
+ entity(id: $id) {
92
+ ... on OutgoingPaymentAttempt {
93
+ ...OutgoingPaymentAttemptFragment
94
+ }
95
+ }
96
+ }
97
+
98
+ ${FRAGMENT}
99
+ `,
100
+ variables: { id },
101
+ constructObject: (data: any) =>
102
+ OutgoingPaymentAttemptFromJson(data.entity),
103
+ };
104
+ }
105
+ }
106
+
107
+ export const OutgoingPaymentAttemptFromJson = (
108
+ obj: any
109
+ ): OutgoingPaymentAttempt => {
110
+ return new OutgoingPaymentAttempt(
111
+ obj["outgoing_payment_attempt_id"],
112
+ obj["outgoing_payment_attempt_created_at"],
113
+ obj["outgoing_payment_attempt_updated_at"],
114
+ OutgoingPaymentAttemptStatus[obj["outgoing_payment_attempt_status"]] ??
115
+ OutgoingPaymentAttemptStatus.FUTURE_VALUE,
116
+ obj["outgoing_payment_attempt_outgoing_payment"].id,
117
+ "OutgoingPaymentAttempt",
118
+ !!obj["outgoing_payment_attempt_failure_code"]
119
+ ? HtlcAttemptFailureCode[obj["outgoing_payment_attempt_failure_code"]] ??
120
+ HtlcAttemptFailureCode.FUTURE_VALUE
121
+ : null,
122
+ obj["outgoing_payment_attempt_failure_source_index"],
123
+ obj["outgoing_payment_attempt_resolved_at"],
124
+ !!obj["outgoing_payment_attempt_amount"]
125
+ ? CurrencyAmountFromJson(obj["outgoing_payment_attempt_amount"])
126
+ : undefined,
127
+ !!obj["outgoing_payment_attempt_fees"]
128
+ ? CurrencyAmountFromJson(obj["outgoing_payment_attempt_fees"])
129
+ : undefined
130
+ );
131
+ };
132
+
133
+ export const FRAGMENT = `
134
+ fragment OutgoingPaymentAttemptFragment on OutgoingPaymentAttempt {
135
+ __typename
136
+ outgoing_payment_attempt_id: id
137
+ outgoing_payment_attempt_created_at: created_at
138
+ outgoing_payment_attempt_updated_at: updated_at
139
+ outgoing_payment_attempt_status: status
140
+ outgoing_payment_attempt_failure_code: failure_code
141
+ outgoing_payment_attempt_failure_source_index: failure_source_index
142
+ outgoing_payment_attempt_resolved_at: resolved_at
143
+ outgoing_payment_attempt_amount: amount {
144
+ __typename
145
+ currency_amount_original_value: original_value
146
+ currency_amount_original_unit: original_unit
147
+ currency_amount_preferred_currency_unit: preferred_currency_unit
148
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
149
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
150
+ }
151
+ outgoing_payment_attempt_fees: fees {
152
+ __typename
153
+ currency_amount_original_value: original_value
154
+ currency_amount_original_unit: original_unit
155
+ currency_amount_preferred_currency_unit: preferred_currency_unit
156
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
157
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
158
+ }
159
+ outgoing_payment_attempt_outgoing_payment: outgoing_payment {
160
+ id
161
+ }
162
+ }`;
163
+
164
+ export default OutgoingPaymentAttempt;
@@ -0,0 +1,18 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ /** Enum that enumerates all the possible status of an outgoing payment attempt. **/
4
+ export enum OutgoingPaymentAttemptStatus {
5
+ /**
6
+ * This is an enum value that represents values that could be added in the future.
7
+ * Clients should support unknown values as more of them could be added without notice.
8
+ */
9
+ FUTURE_VALUE = "FUTURE_VALUE",
10
+
11
+ IN_FLIGHT = "IN_FLIGHT",
12
+
13
+ SUCCEEDED = "SUCCEEDED",
14
+
15
+ FAILED = "FAILED",
16
+ }
17
+
18
+ export default OutgoingPaymentAttemptStatus;
@@ -0,0 +1,37 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import Hop, { HopFromJson } from "./Hop.js";
4
+
5
+ /** The connection from an outgoing payment attempt to the list of sequential hops that define the path from sender node to recipient node. **/
6
+ type OutgoingPaymentAttemptToHopsConnection = {
7
+ /**
8
+ * The total count of objects in this connection, using the current filters. It is different from the
9
+ * number of objects returned in the current page (in the `entities` field).
10
+ **/
11
+ count: number;
12
+
13
+ /** The hops for the current page of this connection. **/
14
+ entities: Hop[];
15
+ };
16
+
17
+ export const OutgoingPaymentAttemptToHopsConnectionFromJson = (
18
+ obj: any
19
+ ): OutgoingPaymentAttemptToHopsConnection => {
20
+ return {
21
+ count: obj["outgoing_payment_attempt_to_hops_connection_count"],
22
+ entities: obj["outgoing_payment_attempt_to_hops_connection_entities"].map(
23
+ (e) => HopFromJson(e)
24
+ ),
25
+ } as OutgoingPaymentAttemptToHopsConnection;
26
+ };
27
+
28
+ export const FRAGMENT = `
29
+ fragment OutgoingPaymentAttemptToHopsConnectionFragment on OutgoingPaymentAttemptToHopsConnection {
30
+ __typename
31
+ outgoing_payment_attempt_to_hops_connection_count: count
32
+ outgoing_payment_attempt_to_hops_connection_entities: entities {
33
+ id
34
+ }
35
+ }`;
36
+
37
+ export default OutgoingPaymentAttemptToHopsConnection;
@@ -0,0 +1,39 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import OutgoingPaymentAttempt, {
4
+ OutgoingPaymentAttemptFromJson,
5
+ } from "./OutgoingPaymentAttempt.js";
6
+
7
+ /** The connection from outgoing payment to all attempts. **/
8
+ type OutgoingPaymentToAttemptsConnection = {
9
+ /**
10
+ * The total count of objects in this connection, using the current filters. It is different from the
11
+ * number of objects returned in the current page (in the `entities` field).
12
+ **/
13
+ count: number;
14
+
15
+ /** The attempts for the current page of this connection. **/
16
+ entities: OutgoingPaymentAttempt[];
17
+ };
18
+
19
+ export const OutgoingPaymentToAttemptsConnectionFromJson = (
20
+ obj: any
21
+ ): OutgoingPaymentToAttemptsConnection => {
22
+ return {
23
+ count: obj["outgoing_payment_to_attempts_connection_count"],
24
+ entities: obj["outgoing_payment_to_attempts_connection_entities"].map((e) =>
25
+ OutgoingPaymentAttemptFromJson(e)
26
+ ),
27
+ } as OutgoingPaymentToAttemptsConnection;
28
+ };
29
+
30
+ export const FRAGMENT = `
31
+ fragment OutgoingPaymentToAttemptsConnectionFragment on OutgoingPaymentToAttemptsConnection {
32
+ __typename
33
+ outgoing_payment_to_attempts_connection_count: count
34
+ outgoing_payment_to_attempts_connection_entities: entities {
35
+ id
36
+ }
37
+ }`;
38
+
39
+ export default OutgoingPaymentToAttemptsConnection;
@@ -0,0 +1,31 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ type PageInfo = {
4
+ hasNextPage?: boolean;
5
+
6
+ hasPreviousPage?: boolean;
7
+
8
+ startCursor?: string;
9
+
10
+ endCursor?: string;
11
+ };
12
+
13
+ export const PageInfoFromJson = (obj: any): PageInfo => {
14
+ return {
15
+ hasNextPage: obj["page_info_has_next_page"],
16
+ hasPreviousPage: obj["page_info_has_previous_page"],
17
+ startCursor: obj["page_info_start_cursor"],
18
+ endCursor: obj["page_info_end_cursor"],
19
+ } as PageInfo;
20
+ };
21
+
22
+ export const FRAGMENT = `
23
+ fragment PageInfoFragment on PageInfo {
24
+ __typename
25
+ page_info_has_next_page: has_next_page
26
+ page_info_has_previous_page: has_previous_page
27
+ page_info_start_cursor: start_cursor
28
+ page_info_end_cursor: end_cursor
29
+ }`;
30
+
31
+ export default PageInfo;
@@ -0,0 +1,33 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ type PayInvoiceInput = {
4
+ /** The node from where you want to send the payment. **/
5
+ nodeId: string;
6
+
7
+ /** The invoice you want to pay (as defined by the BOLT11 standard). **/
8
+ encodedInvoice: string;
9
+
10
+ /** The timeout in seconds that we will try to make the payment. **/
11
+ timeoutSecs: number;
12
+
13
+ /** The maximum amount of fees that you want to pay for this payment to be sent, expressed in msats. **/
14
+ maximumFeesMsats: number;
15
+
16
+ /**
17
+ * The amount you will pay for this invoice, expressed in msats. It should ONLY be set when the
18
+ * invoice amount is zero.
19
+ **/
20
+ amountMsats?: number;
21
+ };
22
+
23
+ export const PayInvoiceInputFromJson = (obj: any): PayInvoiceInput => {
24
+ return {
25
+ nodeId: obj["pay_invoice_input_node_id"],
26
+ encodedInvoice: obj["pay_invoice_input_encoded_invoice"],
27
+ timeoutSecs: obj["pay_invoice_input_timeout_secs"],
28
+ maximumFeesMsats: obj["pay_invoice_input_maximum_fees_msats"],
29
+ amountMsats: obj["pay_invoice_input_amount_msats"],
30
+ } as PayInvoiceInput;
31
+ };
32
+
33
+ export default PayInvoiceInput;
@@ -0,0 +1,22 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ type PayInvoiceOutput = {
4
+ /** The payment that has been sent. **/
5
+ paymentId: string;
6
+ };
7
+
8
+ export const PayInvoiceOutputFromJson = (obj: any): PayInvoiceOutput => {
9
+ return {
10
+ paymentId: obj["pay_invoice_output_payment"].id,
11
+ } as PayInvoiceOutput;
12
+ };
13
+
14
+ export const FRAGMENT = `
15
+ fragment PayInvoiceOutputFragment on PayInvoiceOutput {
16
+ __typename
17
+ pay_invoice_output_payment: payment {
18
+ id
19
+ }
20
+ }`;
21
+
22
+ export default PayInvoiceOutput;