@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,3 @@
1
+ export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as ApiToken, B as BitcoinNetwork, h as BlockchainBalance, C as Channel, i as ChannelClosingTransaction, k as ChannelFees, l as ChannelOpeningTransaction, n as ChannelStatus, o as ChannelToTransactionsConnection, p as CreateApiTokenInput, q as CreateApiTokenOutput, r as CreateInvoiceInput, s as CreateInvoiceOutput, t as CreateNodeWalletAddressInput, u as CreateNodeWalletAddressOutput, v as CurrencyAmount, w as CurrencyUnit, D as DeleteApiTokenInput, x as DeleteApiTokenOutput, y as Deposit, E as Entity, F as FeeEstimate, G as FundNodeInput, H as FundNodeOutput, I as GraphNode, J as Hop, M as HtlcAttemptFailureCode, N as IncomingPayment, O as IncomingPaymentAttempt, Q as IncomingPaymentAttemptStatus, R as IncomingPaymentToAttemptsConnection, S as Invoice, U as InvoiceData, V as InvoiceType, W as LightningFeeEstimateForInvoiceInput, X as LightningFeeEstimateForNodeInput, Y as LightningFeeEstimateOutput, Z as LightningTransaction, $ as LightsparkNode, a0 as LightsparkNodePurpose, a1 as LightsparkNodeStatus, a2 as LightsparkNodeToChannelsConnection, a3 as Node, a4 as NodeAddress, a5 as NodeAddressType, a6 as NodeToAddressesConnection, a7 as OnChainTransaction, a9 as OutgoingPayment, aa as OutgoingPaymentAttempt, ab as OutgoingPaymentAttemptStatus, ac as OutgoingPaymentAttemptToHopsConnection, ad as OutgoingPaymentToAttemptsConnection, ae as PageInfo, af as PayInvoiceInput, ag as PayInvoiceOutput, ah as PaymentFailureReason, ai as PaymentRequest, ak as PaymentRequestData, al as PaymentRequestStatus, am as Permission, an as RequestWithdrawalInput, ao as RequestWithdrawalOutput, ap as RichText, aq as RoutingTransaction, as as RoutingTransactionFailureReason, at as Secret, au as SendPaymentInput, av as SendPaymentOutput, aw as Transaction, ay as TransactionFailures, az as TransactionStatus, aA as TransactionType, aB as TransactionUpdate, aC as WalletDashboard, aD as WebhookEventType, aE as Withdrawal, aG as WithdrawalMode, aH as WithdrawalRequest, aI as WithdrawalRequestStatus, aJ as WithdrawalRequestToChannelClosingTransactionsConnection, aK as WithdrawalRequestToChannelOpeningTransactionsConnection, g as getApiTokenQuery, j as getChannelClosingTransactionQuery, m as getChannelOpeningTransactionQuery, z as getDepositQuery, K as getHopQuery, P as getIncomingPaymentAttemptQuery, T as getInvoiceQuery, _ as getLightningTransactionQuery, a8 as getOnChainTransactionQuery, aj as getPaymentRequestQuery, ar as getRoutingTransactionQuery, ax as getTransactionQuery, aF as getWithdrawalQuery } from '../Withdrawal-27a4d10d.js';
2
+ import '@lightsparkdev/core';
3
+ import 'zen-observable';
@@ -0,0 +1,88 @@
1
+ import {
2
+ AccountToChannelsConnection_default,
3
+ Account_default,
4
+ BitcoinNetwork_default,
5
+ ChannelStatus_default,
6
+ Channel_default,
7
+ CurrencyUnit_default,
8
+ GraphNode_default,
9
+ HtlcAttemptFailureCode_default,
10
+ IncomingPaymentAttemptStatus_default,
11
+ IncomingPayment_default,
12
+ InvoiceType_default,
13
+ LightsparkNodePurpose_default,
14
+ LightsparkNodeStatus_default,
15
+ LightsparkNode_default,
16
+ NodeAddressType_default,
17
+ Node_default,
18
+ OutgoingPaymentAttemptStatus_default,
19
+ OutgoingPaymentAttempt_default,
20
+ OutgoingPayment_default,
21
+ PaymentFailureReason_default,
22
+ PaymentRequestStatus_default,
23
+ Permission_default,
24
+ RoutingTransactionFailureReason_default,
25
+ TransactionStatus_default,
26
+ TransactionType_default,
27
+ WebhookEventType_default,
28
+ WithdrawalMode_default,
29
+ WithdrawalRequestStatus_default,
30
+ WithdrawalRequest_default,
31
+ getApiTokenQuery,
32
+ getChannelClosingTransactionQuery,
33
+ getChannelOpeningTransactionQuery,
34
+ getDepositQuery,
35
+ getHopQuery,
36
+ getIncomingPaymentAttemptQuery,
37
+ getInvoiceQuery,
38
+ getLightningTransactionQuery,
39
+ getOnChainTransactionQuery,
40
+ getPaymentRequestQuery,
41
+ getRoutingTransactionQuery,
42
+ getTransactionQuery,
43
+ getWithdrawalQuery
44
+ } from "../chunk-3VRI7CHE.js";
45
+ export {
46
+ Account_default as Account,
47
+ AccountToChannelsConnection_default as AccountToChannelsConnection,
48
+ BitcoinNetwork_default as BitcoinNetwork,
49
+ Channel_default as Channel,
50
+ ChannelStatus_default as ChannelStatus,
51
+ CurrencyUnit_default as CurrencyUnit,
52
+ GraphNode_default as GraphNode,
53
+ HtlcAttemptFailureCode_default as HtlcAttemptFailureCode,
54
+ IncomingPayment_default as IncomingPayment,
55
+ IncomingPaymentAttemptStatus_default as IncomingPaymentAttemptStatus,
56
+ InvoiceType_default as InvoiceType,
57
+ LightsparkNode_default as LightsparkNode,
58
+ LightsparkNodePurpose_default as LightsparkNodePurpose,
59
+ LightsparkNodeStatus_default as LightsparkNodeStatus,
60
+ Node_default as Node,
61
+ NodeAddressType_default as NodeAddressType,
62
+ OutgoingPayment_default as OutgoingPayment,
63
+ OutgoingPaymentAttempt_default as OutgoingPaymentAttempt,
64
+ OutgoingPaymentAttemptStatus_default as OutgoingPaymentAttemptStatus,
65
+ PaymentFailureReason_default as PaymentFailureReason,
66
+ PaymentRequestStatus_default as PaymentRequestStatus,
67
+ Permission_default as Permission,
68
+ RoutingTransactionFailureReason_default as RoutingTransactionFailureReason,
69
+ TransactionStatus_default as TransactionStatus,
70
+ TransactionType_default as TransactionType,
71
+ WebhookEventType_default as WebhookEventType,
72
+ WithdrawalMode_default as WithdrawalMode,
73
+ WithdrawalRequest_default as WithdrawalRequest,
74
+ WithdrawalRequestStatus_default as WithdrawalRequestStatus,
75
+ getApiTokenQuery,
76
+ getChannelClosingTransactionQuery,
77
+ getChannelOpeningTransactionQuery,
78
+ getDepositQuery,
79
+ getHopQuery,
80
+ getIncomingPaymentAttemptQuery,
81
+ getInvoiceQuery,
82
+ getLightningTransactionQuery,
83
+ getOnChainTransactionQuery,
84
+ getPaymentRequestQuery,
85
+ getRoutingTransactionQuery,
86
+ getTransactionQuery,
87
+ getWithdrawalQuery
88
+ };
@@ -0,0 +1,20 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ export const getCredentialsFromEnvOrThrow = () => {
4
+ const apiTokenClientId = process.env["LIGHTSPARK_API_TOKEN_CLIENT_ID"];
5
+ const apiTokenClientSecret =
6
+ process.env["LIGHTSPARK_API_TOKEN_CLIENT_SECRET"];
7
+ const nodePassword = process.env["LIGHTSPARK_TEST_NODE_PASSWORD"];
8
+ const baseUrl = process.env["LIGHTSPARK_EXAMPLE_BASE_URL"] || "api.lightspark.com";
9
+ if (!apiTokenClientId || !apiTokenClientSecret || !nodePassword) {
10
+ throw new Error(
11
+ "Missing test credentials. Please set LIGHTSPARK_API_TOKEN_CLIENT_ID, LIGHTSPARK_API_TOKEN_CLIENT_SECRET, and LIGHTSPARK_TEST_NODE_PASSWORD environment variables."
12
+ );
13
+ }
14
+ return {
15
+ apiTokenClientId,
16
+ apiTokenClientSecret,
17
+ nodePassword,
18
+ baseUrl
19
+ };
20
+ };
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ts-node
2
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
3
+
4
+ import {
5
+ AccountTokenAuthProvider,
6
+ InvoiceType,
7
+ LightsparkClient,
8
+ } from "@lightsparkdev/lightspark-sdk";
9
+ import { Command } from "commander";
10
+
11
+ import { getCredentialsFromEnvOrThrow } from "./authHelpers.js";
12
+
13
+ const main = async (program: Command) => {
14
+ const credentials = getCredentialsFromEnvOrThrow();
15
+ const client = new LightsparkClient(
16
+ new AccountTokenAuthProvider(
17
+ credentials.apiTokenClientId,
18
+ credentials.apiTokenClientSecret
19
+ ),
20
+ credentials.baseUrl
21
+ );
22
+ const account = await client.getCurrentAccount();
23
+ const nodeId = (await account.getNodes(client)).entities[0].id;
24
+ const options = program.opts();
25
+ console.log("Options: ", JSON.stringify(options, null, 2));
26
+ const invoice = await client.createInvoice(
27
+ nodeId,
28
+ options.amount * 1000,
29
+ options.memo,
30
+ options.amp ? InvoiceType.AMP : InvoiceType.STANDARD
31
+ );
32
+ console.log("Invoice:", JSON.stringify(invoice, null, 2));
33
+ };
34
+
35
+ (() => {
36
+ const program = new Command();
37
+ program
38
+ .name("CreateInvoice")
39
+ .version("1.0.0")
40
+ .description("Create an invoice for your wallet node")
41
+ .option(
42
+ "-m, --memo <value>",
43
+ "Add a memo describing the invoice.",
44
+ undefined
45
+ )
46
+ .option(
47
+ "-a, --amount <number>",
48
+ "The amount of the invoice in sats.",
49
+ parseInt,
50
+ 0
51
+ )
52
+ .option("--amp", "Flag to use AMP invoices.", false)
53
+ .parse(process.argv);
54
+
55
+ const options = program.opts();
56
+ if (options.amount === undefined) {
57
+ program.outputHelp();
58
+ } else {
59
+ // tslint:disable-next-line
60
+ main(program).catch((err) =>
61
+ console.error("Oh no, something went wrong.\n", err)
62
+ );
63
+ }
64
+ })();
@@ -0,0 +1,288 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import {
4
+ AccountTokenAuthProvider,
5
+ BitcoinNetwork,
6
+ CurrencyAmount,
7
+ getDepositQuery,
8
+ LightsparkClient,
9
+ LightsparkNode,
10
+ Node,
11
+ } from "@lightsparkdev/lightspark-sdk";
12
+ import day from "dayjs";
13
+ import utc from "dayjs/plugin/utc.js";
14
+
15
+ import { getCredentialsFromEnvOrThrow } from "./authHelpers.js";
16
+
17
+ day.extend(utc);
18
+
19
+ // Let's start by creating a client
20
+ const credentials = getCredentialsFromEnvOrThrow();
21
+ const client = new LightsparkClient(
22
+ new AccountTokenAuthProvider(
23
+ credentials.apiTokenClientId,
24
+ credentials.apiTokenClientSecret
25
+ ),
26
+ credentials.baseUrl
27
+ );
28
+
29
+ // Get some fee estimates for Bitcoin (L1) transactions
30
+
31
+ const feeEstimate = await client.getBitcoinFeeEstimate(BitcoinNetwork.REGTEST);
32
+ console.log(
33
+ `Fees for a fast transaction ${feeEstimate.feeFast.preferredCurrencyValueApprox} ${feeEstimate.feeFast.preferredCurrencyUnit}.`
34
+ );
35
+ console.log(
36
+ `Fees for a cheap transaction ${feeEstimate.feeMin.preferredCurrencyValueApprox} ${feeEstimate.feeMin.preferredCurrencyUnit}.\n`
37
+ );
38
+
39
+ // List your account's lightning nodes
40
+
41
+ const account = await client.getCurrentAccount();
42
+ if (!account) {
43
+ throw new Error("Unable to fetch the account.");
44
+ }
45
+ console.log(`Your account name is ${account.name}.\n`);
46
+
47
+ // Test API token logic:
48
+
49
+ const apiTokenConnection = await account.getApiTokens(client);
50
+ console.log(`You have ${apiTokenConnection.count} API tokens.`);
51
+
52
+ const { apiToken, clientSecret } = await client.createApiToken(
53
+ "newTestToken",
54
+ false,
55
+ true
56
+ );
57
+ console.log(
58
+ `Created API token ${apiToken.name} with ID ${
59
+ apiToken.id
60
+ }. Permissions: ${JSON.stringify(apiToken.permissions)}\n`
61
+ );
62
+
63
+ const apiTokenConnection2 = await account.getApiTokens(client);
64
+ console.log(`You now have ${apiTokenConnection2.count} API tokens.\n`);
65
+
66
+ client.deleteApiToken(apiToken.id);
67
+
68
+ const apiTokenConnection3 = await account.getApiTokens(client);
69
+ console.log(`You now have ${apiTokenConnection3.count} API tokens.\n`);
70
+
71
+ // Check our account's conductivity on REGTEST
72
+
73
+ console.log(
74
+ `Your account's conductivity on REGTEST is ${await account.getConductivity(
75
+ client,
76
+ [BitcoinNetwork.REGTEST]
77
+ )}/10.\n`
78
+ );
79
+
80
+ // Check your account's local and remote balances for REGTEST
81
+ const localBalance = await account.getLocalBalance(client, [
82
+ BitcoinNetwork.REGTEST,
83
+ ]);
84
+ const remoteBalance = await account.getRemoteBalance(client, [
85
+ BitcoinNetwork.REGTEST,
86
+ ]);
87
+
88
+ if (localBalance && remoteBalance) {
89
+ console.log(
90
+ `Your local balance is ${localBalance.preferredCurrencyValueApprox} ${localBalance.preferredCurrencyUnit},
91
+ your remote balance is ${remoteBalance.preferredCurrencyValueApprox} ${remoteBalance.preferredCurrencyUnit}.`
92
+ );
93
+ }
94
+
95
+ const nodesConnection = await account.getNodes(client, 50, [
96
+ BitcoinNetwork.REGTEST,
97
+ ]);
98
+
99
+ if (!nodesConnection) {
100
+ throw new Error("Unable to fetch the nodes.");
101
+ }
102
+
103
+ console.log(`You have ${nodesConnection.count} nodes.`);
104
+
105
+ if (nodesConnection.entities.length == 0) {
106
+ throw new Error("Cannot continue without any nodes.");
107
+ }
108
+
109
+ const nodeId = nodesConnection.entities[0].id;
110
+ const nodeName = nodesConnection.entities[0].displayName;
111
+ console.log("");
112
+
113
+ // List the transactions for our account
114
+
115
+ let transactionsConnection = await account.getTransactions(
116
+ client,
117
+ 100,
118
+ undefined,
119
+ undefined,
120
+ undefined,
121
+ undefined,
122
+ BitcoinNetwork.REGTEST
123
+ );
124
+
125
+ console.log(
126
+ `There is a total of ${transactionsConnection.count} transaction(s) on this account:`
127
+ );
128
+ let depositTransactionId: string | undefined;
129
+ for (const transaction of transactionsConnection.entities) {
130
+ console.log(
131
+ ` - ${transaction.typename} at ${transaction.createdAt}:
132
+ ${transaction.amount.preferredCurrencyValueApprox} ${transaction.amount.preferredCurrencyUnit}
133
+ (${transaction.status})`
134
+ );
135
+ if (transaction.typename == "Deposit") {
136
+ depositTransactionId = transaction.id;
137
+ }
138
+
139
+ let fees;
140
+ if (
141
+ transaction.typename == "OutgoingPayment" ||
142
+ transaction.typename == "Withdrawal" ||
143
+ transaction.typename == "Deposit" ||
144
+ transaction.typename == "ChannelOpeningTransaction" ||
145
+ transaction.typename == "ChannelClosingTransaction"
146
+ ) {
147
+ fees = (transaction as unknown as { fees: CurrencyAmount }).fees;
148
+ if (fees !== undefined)
149
+ console.log(
150
+ ` Paid ${fees.preferredCurrencyValueApprox} ${fees.preferredCurrencyUnit} in fees.`
151
+ );
152
+ }
153
+ }
154
+ console.log("");
155
+
156
+ // Fetch transactions using pagination
157
+ const pageSize = 10;
158
+ let iterations = 0;
159
+ let hasNext = true;
160
+ let after: string | undefined = undefined;
161
+ while (hasNext && iterations < 30) {
162
+ iterations += 1;
163
+ transactionsConnection = await account.getTransactions(
164
+ client,
165
+ pageSize,
166
+ after,
167
+ undefined,
168
+ undefined,
169
+ undefined,
170
+ BitcoinNetwork.REGTEST
171
+ );
172
+ const num = transactionsConnection.entities.length;
173
+ console.log(
174
+ `We got ${num} transactions for the page (iteration #${iterations})`
175
+ );
176
+ if (transactionsConnection.pageInfo.hasNextPage) {
177
+ hasNext = true;
178
+ after = transactionsConnection.pageInfo.endCursor;
179
+ console.log(" And we have another page!");
180
+ } else {
181
+ hasNext = false;
182
+ console.log(" And we're done!");
183
+ }
184
+ }
185
+ console.log("");
186
+
187
+ // Get the transactions that happened in the past day on REGTEST
188
+
189
+ transactionsConnection = await account.getTransactions(
190
+ client,
191
+ undefined,
192
+ undefined,
193
+ undefined,
194
+ day().utc().subtract(1, "day").format(),
195
+ undefined,
196
+ BitcoinNetwork.REGTEST
197
+ );
198
+ console.log(
199
+ `We had ${transactionsConnection.count} transactions in the past 24 hours.`
200
+ );
201
+
202
+ // Get details for a transaction
203
+
204
+ if (!depositTransactionId) {
205
+ throw new Error("Unable to find the deposit transaction.");
206
+ }
207
+
208
+ const deposit = await client.executeRawQuery(
209
+ getDepositQuery(depositTransactionId)
210
+ );
211
+ console.log("Details of deposit transaction");
212
+ console.log(deposit);
213
+ console.log("");
214
+
215
+ // Generate a payment request
216
+
217
+ const invoice = await client.createInvoice(nodeId, 42000, "Pizza!");
218
+ if (!invoice) {
219
+ throw new Error("Unable to create the invoice.");
220
+ }
221
+ console.log(`Invoice created from ${nodeName}:`);
222
+ console.log(`Encoded invoice = ${invoice}`);
223
+ console.log("");
224
+
225
+ // Decode the payment request
226
+ const decodedInvoice = await client.decodeInvoice(invoice);
227
+ if (!decodedInvoice) {
228
+ throw new Error("Unable to decode the invoice.");
229
+ }
230
+ console.log("Decoded payment request:");
231
+ console.log(
232
+ " destination public key = " + decodedInvoice.destination.publicKey
233
+ );
234
+ console.log(
235
+ " amount = " +
236
+ decodedInvoice.amount.preferredCurrencyValueApprox +
237
+ " " +
238
+ decodedInvoice.amount.preferredCurrencyUnit
239
+ );
240
+ console.log(" memo = " + decodedInvoice.memo);
241
+ console.log("");
242
+
243
+ // Let's send the payment.
244
+
245
+ // First, we need to recover the signing key.
246
+ await client.unlockNode(nodeId, credentials.nodePassword!);
247
+ console.log(`${nodeName}'s signing key has been loaded.`);
248
+
249
+ // Then we can send the payment. Note that this isn't paying the invoice we just made because
250
+ // you can't actually pay your own invoice. Let's just pay a pre-existing AMP invoice instead.
251
+ const ampInvoice =
252
+ "lnbcrt1pjr8xwypp5xqj2jfpkz095s8zu57ktsq8vt8yazwcmqpcke9pvl67ne9cpdr0qdqj2a5xzumnwd6hqurswqcqzpgxq9z0rgqsp55hfn0caa5sexea8u979cckkmwelw6h3zpwel5l8tn8s0elgwajss9q8pqqqssqefmmw79tknhl5xhnh7yfepzypxknwr9r4ya7ueqa6vz20axvys8se986hwj6gppeyzst44hm4yl04c4dqjjpqgtt0df254q087sjtfsq35yagj";
253
+ const payment = await client.payInvoice(nodeId, ampInvoice, 1000, 60, 10);
254
+ console.log(`Payment done with ID = ${payment.id}`);
255
+ console.log("");
256
+
257
+ const address = await client.createNodeWalletAddress(nodeId);
258
+ console.log(`Got a bitcoin address for ${nodeName}: ${address}`);
259
+ console.log("");
260
+
261
+ // const withdrawal = await client.requestWithdrawal(node2Id, 1000000, address, WithdrawalMode.WALLET_THEN_CHANNELS);
262
+ // console.log(`Money was withdrawn with ID = ${withdrawal.id}`);
263
+ // console.log("");
264
+
265
+ // Fetch the channels for Node 1
266
+ const node = await client.executeRawQuery(
267
+ LightsparkNode.getLightsparkNodeQuery(nodeId)
268
+ );
269
+ if (!node) {
270
+ throw new Error("Unable to find node.");
271
+ }
272
+
273
+ const channelsConnection = await node.getChannels(client, 10);
274
+ console.log(`${nodeName} has ${channelsConnection.count} channel(s):`);
275
+ for (const channel of channelsConnection.entities) {
276
+ if (channel.remoteNodeId) {
277
+ const remoteNode = await client.executeRawQuery(
278
+ Node.getNodeQuery(channel.remoteNodeId)
279
+ );
280
+ const alias = remoteNode?.alias ?? "UNKNOWN";
281
+ if (channel.localBalance && channel.remoteBalance) {
282
+ console.log(
283
+ ` - With ${alias}. Local/remote balance = ${channel.localBalance.preferredCurrencyValueApprox} ${channel.localBalance.preferredCurrencyUnit}
284
+ / ${channel.remoteBalance.preferredCurrencyValueApprox} ${channel.remoteBalance.preferredCurrencyUnit}`
285
+ );
286
+ }
287
+ }
288
+ }
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ts-node
2
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
3
+
4
+ import {
5
+ AccountTokenAuthProvider,
6
+ BitcoinNetwork,
7
+ LightsparkClient,
8
+ } from "@lightsparkdev/lightspark-sdk";
9
+
10
+ import { getCredentialsFromEnvOrThrow } from "./authHelpers.js";
11
+
12
+ const account = getCredentialsFromEnvOrThrow();
13
+ const client = new LightsparkClient(
14
+ new AccountTokenAuthProvider(
15
+ account.apiTokenClientId,
16
+ account.apiTokenClientSecret
17
+ ),
18
+ account.baseUrl
19
+ );
20
+ client
21
+ .getAccountDashboard(undefined, BitcoinNetwork.REGTEST)
22
+ .then((dashboard) => {
23
+ console.log("Got dashboard:", JSON.stringify(dashboard, null, 2));
24
+ });
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ts-node
2
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
3
+
4
+ import {
5
+ AccountTokenAuthProvider,
6
+ BitcoinNetwork,
7
+ LightsparkClient,
8
+ } from "@lightsparkdev/lightspark-sdk";
9
+
10
+ import { getCredentialsFromEnvOrThrow } from "./authHelpers.js";
11
+
12
+ const account = getCredentialsFromEnvOrThrow();
13
+ const client = new LightsparkClient(
14
+ new AccountTokenAuthProvider(
15
+ account.apiTokenClientId,
16
+ account.apiTokenClientSecret
17
+ ),
18
+ account.baseUrl
19
+ );
20
+
21
+ const main = async () => {
22
+ const currentAccount = await client.getCurrentAccount();
23
+ console.log("Got account:", JSON.stringify(account, null, 2));
24
+
25
+ const nodes = await currentAccount!.getNodes(client, 100, [
26
+ BitcoinNetwork.REGTEST,
27
+ ]);
28
+ console.log("Got nodes:", JSON.stringify(nodes, null, 2));
29
+
30
+ const channels = await nodes.entities[0].getChannels(client, 20);
31
+ console.log("Got channels:", JSON.stringify(channels, null, 2));
32
+ };
33
+
34
+ main().catch((err) => console.error("Oh no, something went wrong.\n", err));
@@ -0,0 +1,26 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ export const getCredentialsFromEnvOrThrow = () => {
4
+ const apiTokenClientId = process.env["LIGHTSPARK_API_TOKEN_CLIENT_ID"];
5
+ const apiTokenClientSecret =
6
+ process.env["LIGHTSPARK_API_TOKEN_CLIENT_SECRET"];
7
+ const walletNodeId = process.env["LIGHTSPARK_WALLET_NODE_ID"];
8
+ const node1Name = process.env["LIGHTSPARK_EXAMPLE_NODE_1_NAME"];
9
+ const node1Password = process.env["LIGHTSPARK_TEST_NODE_PASSWORD"];
10
+ const node2Name = process.env["LIGHTSPARK_EXAMPLE_NODE_2_NAME"];
11
+ const node2Password = process.env["LIGHTSPARK_EXAMPLE_NODE_2_PASSWORD"];
12
+ if (!apiTokenClientId || !apiTokenClientSecret || !node1Password) {
13
+ throw new Error(
14
+ "Missing test credentials. Please set LIGHTSPARK_API_TOKEN_CLIENT_ID, LIGHTSPARK_API_TOKEN_CLIENT_SECRET, and LIGHTSPARK_TEST_NODE_PASSWORD environment variables."
15
+ );
16
+ }
17
+ return {
18
+ apiTokenClientId,
19
+ apiTokenClientSecret,
20
+ walletNodeId,
21
+ node1Name,
22
+ node1Password,
23
+ node2Name,
24
+ node2Password,
25
+ };
26
+ };