@lightsparkdev/lightspark-sdk 1.2.0 → 1.2.2

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 (57) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/{chunk-5RDIWPBE.js → chunk-D32EWIPX.js} +3 -1
  3. package/dist/{chunk-VTPDR6P4.js → chunk-GLL4KTUT.js} +353 -15
  4. package/dist/env.cjs +3 -1
  5. package/dist/env.d.cts +17 -0
  6. package/dist/env.js +2 -2
  7. package/dist/{index-f040db9f.d.ts → index-eb604025.d.ts} +1377 -15
  8. package/dist/index.cjs +682 -94
  9. package/dist/index.d.cts +41 -0
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +290 -37
  12. package/dist/objects/index.cjs +345 -5
  13. package/dist/objects/index.d.cts +4 -0
  14. package/dist/objects/index.d.ts +1 -1
  15. package/dist/objects/index.js +10 -2
  16. package/dist/{text-encoding-MDIPJAHL.js → text-encoding-26SMKBAQ.js} +3 -1
  17. package/package.json +4 -4
  18. package/src/auth/AccountTokenAuthProvider.ts +15 -11
  19. package/src/client.ts +201 -7
  20. package/src/graphql/ClaimUmaInvitation.ts +21 -0
  21. package/src/graphql/ClaimUmaInvitationWithIncentives.ts +25 -0
  22. package/src/graphql/CreateUmaInvitation.ts +19 -0
  23. package/src/graphql/CreateUmaInvitationWithIncentives.ts +23 -0
  24. package/src/graphql/FetchUmaInvitation.ts +15 -0
  25. package/src/helpers.ts +3 -1
  26. package/src/objects/Account.ts +8 -0
  27. package/src/objects/AccountToChannelsConnection.ts +5 -0
  28. package/src/objects/Channel.ts +31 -0
  29. package/src/objects/ClaimUmaInvitationInput.ts +26 -0
  30. package/src/objects/ClaimUmaInvitationOutput.ts +30 -0
  31. package/src/objects/ClaimUmaInvitationWithIncentivesInput.ts +44 -0
  32. package/src/objects/ClaimUmaInvitationWithIncentivesOutput.ts +33 -0
  33. package/src/objects/CreateInvitationWithIncentivesInput.ts +37 -0
  34. package/src/objects/CreateInvitationWithIncentivesOutput.ts +32 -0
  35. package/src/objects/CreateUmaInvitationInput.ts +22 -0
  36. package/src/objects/CreateUmaInvitationOutput.ts +30 -0
  37. package/src/objects/Entity.ts +13 -0
  38. package/src/objects/GraphNode.ts +28 -0
  39. package/src/objects/IncentivesIneligibilityReason.ts +24 -0
  40. package/src/objects/IncentivesStatus.ts +18 -0
  41. package/src/objects/IncomingPayment.ts +17 -0
  42. package/src/objects/LightsparkNodeWithOSK.ts +61 -0
  43. package/src/objects/LightsparkNodeWithRemoteSigning.ts +60 -0
  44. package/src/objects/OutgoingPayment.ts +20 -0
  45. package/src/objects/OutgoingPaymentAttempt.ts +31 -0
  46. package/src/objects/RegionCode.ts +510 -0
  47. package/src/objects/UmaInvitation.ts +113 -0
  48. package/src/objects/Wallet.ts +12 -0
  49. package/src/objects/WebhookEventType.ts +4 -0
  50. package/src/objects/WithdrawalRequest.ts +17 -0
  51. package/src/objects/index.ts +15 -0
  52. package/src/tests/integration/constants.ts +10 -0
  53. package/src/tests/integration/general-regtest.test.ts +633 -0
  54. package/src/tests/serialization.test.ts +5 -2
  55. package/src/webhooks.ts +1 -1
  56. package/src/tests/integration/client.test.ts +0 -207
  57. /package/dist/{chunk-NIMBE7W3.js → chunk-BMTV3EA2.js} +0 -0
@@ -1,207 +0,0 @@
1
- import { mapCurrencyAmount, pollUntil, round } from "@lightsparkdev/core";
2
- import LightsparkClient from "../../client.js";
3
- import { getCredentialsFromEnvOrThrow } from "../../env.js";
4
- import {
5
- AccountTokenAuthProvider,
6
- BitcoinNetwork,
7
- PaymentRequestStatus,
8
- TransactionStatus,
9
- } from "../../index.js";
10
- import { logger } from "../../logger.js";
11
-
12
- const REGTEST_SIGNING_KEY_PASSWORD = "1234!@#$";
13
- const pollIntervalMs = 250;
14
- const pollTimeoutSecs = 20;
15
- const pollMaxTimeouts = (pollTimeoutSecs * 1000) / pollIntervalMs;
16
- const pollIgnoreErrors = false;
17
-
18
- const suiteName = "lightspark-sdk client";
19
-
20
- function log(msg: string, ...args: unknown[]) {
21
- logger.info(
22
- `${expect
23
- .getState()
24
- .currentTestName?.replace(
25
- new RegExp(`^(${suiteName})\\s`, "g"),
26
- "",
27
- )}: ${msg}`,
28
- ...args,
29
- );
30
- }
31
-
32
- describe("lightspark-sdk client", () => {
33
- const { apiTokenClientId, apiTokenClientSecret, baseUrl } =
34
- getCredentialsFromEnvOrThrow();
35
- const accountAuthProvider = new AccountTokenAuthProvider(
36
- apiTokenClientId,
37
- apiTokenClientSecret,
38
- );
39
- let regtestNodeId: string | undefined;
40
-
41
- function getRegtestNodeId() {
42
- expect(regtestNodeId).toBeDefined();
43
- if (!regtestNodeId) {
44
- throw new Error("regtestNodeId is not set");
45
- }
46
- return regtestNodeId as string;
47
- }
48
-
49
- it("Should get env vars and construct the client successfully", async () => {
50
- const lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl);
51
- expect(lightsparkClient).toBeDefined();
52
- });
53
-
54
- it("Should successfully get the current account regtest node", async () => {
55
- const lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl);
56
-
57
- const account = await lightsparkClient.getCurrentAccount();
58
- const nodesConnection = await account?.getNodes(lightsparkClient, 1, [
59
- BitcoinNetwork.REGTEST,
60
- ]);
61
-
62
- const regtestNode = nodesConnection?.entities[0];
63
- expect(regtestNode).toBeDefined();
64
- log("regtestNodeId", regtestNode?.id);
65
- regtestNodeId = regtestNode?.id;
66
- });
67
-
68
- it("Should successfully create an uma invoice", async () => {
69
- const nodeId = getRegtestNodeId();
70
- const lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl);
71
-
72
- const metadata = JSON.stringify([
73
- ["text/plain", "Pay to vasp2.com user $bob"],
74
- ["text/identifier", "$bob@vasp2.com"],
75
- ]);
76
-
77
- const umaInvoice = await lightsparkClient.createUmaInvoice(
78
- nodeId,
79
- 1000,
80
- metadata,
81
- );
82
- expect(umaInvoice?.status).toEqual(PaymentRequestStatus.OPEN);
83
- }, 10000);
84
-
85
- const satsToFund = 50_000;
86
- test("Should deposit funds to node with a defined amount of sats", async () => {
87
- const lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl);
88
- const account = await lightsparkClient.getCurrentAccount();
89
-
90
- if (!account) {
91
- throw new Error("No account");
92
- }
93
-
94
- const nodesConnection = await account?.getNodes(lightsparkClient, 1, [
95
- BitcoinNetwork.REGTEST,
96
- ]);
97
- let regtestNode = nodesConnection?.entities[0];
98
- const initialTotalBalance = mapCurrencyAmount(regtestNode?.totalBalance);
99
- const nodeId = getRegtestNodeId();
100
-
101
- /* Backend will error on fund_node if node balance is greater than 100,000,000 sats, so we should
102
- adjust to a target balance less than that: */
103
- const targetBalanceSats = 50_000_000;
104
- if (initialTotalBalance.sats > targetBalanceSats) {
105
- const invoiceAmount = initialTotalBalance.sats - targetBalanceSats;
106
-
107
- await lightsparkClient.loadNodeSigningKey(getRegtestNodeId(), {
108
- password: REGTEST_SIGNING_KEY_PASSWORD,
109
- });
110
-
111
- const invoice = await lightsparkClient.createTestModeInvoice(
112
- nodeId,
113
- round((initialTotalBalance.sats - targetBalanceSats) * 1000), // convert to msats
114
- );
115
-
116
- if (!invoice) {
117
- throw new Error("Unable to create invoice for balance adjustment");
118
- }
119
-
120
- const feeRate = 0.0016;
121
- const payment = await lightsparkClient.payInvoice(
122
- nodeId,
123
- invoice,
124
- round(invoiceAmount * feeRate),
125
- );
126
-
127
- if (!payment) {
128
- throw new Error("Payment undefined for balance adjustment");
129
- }
130
-
131
- await lightsparkClient.waitForTransactionComplete(
132
- payment.id,
133
- pollTimeoutSecs,
134
- );
135
- }
136
-
137
- await lightsparkClient.fundNode(nodeId, satsToFund);
138
-
139
- regtestNode = await pollUntil(
140
- () => {
141
- return account?.getNodes(lightsparkClient, 1, [BitcoinNetwork.REGTEST]);
142
- },
143
- (current, response) => {
144
- if (
145
- current &&
146
- !mapCurrencyAmount(current.entities[0]?.totalBalance).isEqualTo(
147
- initialTotalBalance,
148
- )
149
- ) {
150
- return {
151
- stopPolling: true,
152
- value: current.entities[0],
153
- };
154
- }
155
- return response;
156
- },
157
- pollIntervalMs,
158
- pollMaxTimeouts,
159
- pollIgnoreErrors,
160
- () => new Error("Timeout waiting for payment to be received"),
161
- );
162
-
163
- expect(
164
- mapCurrencyAmount(regtestNode.totalBalance).isEqualTo(
165
- initialTotalBalance,
166
- ),
167
- ).toBe(false);
168
- }, 120_000);
169
-
170
- test("Should send test mode payment", async () => {
171
- const lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl);
172
- const account = await lightsparkClient.getCurrentAccount();
173
-
174
- if (!account) {
175
- throw new Error("No account");
176
- }
177
-
178
- const nodeId = getRegtestNodeId();
179
-
180
- const invoice = await lightsparkClient.createTestModeInvoice(
181
- nodeId,
182
- satsToFund * 1000, // convert to msats
183
- );
184
-
185
- await lightsparkClient.loadNodeSigningKey(nodeId, {
186
- password: REGTEST_SIGNING_KEY_PASSWORD,
187
- });
188
-
189
- if (!invoice) {
190
- throw new Error("No invoice");
191
- }
192
-
193
- const payment = await lightsparkClient.payInvoice(nodeId, invoice, 60);
194
- log("payment.id", payment?.id);
195
-
196
- if (!payment) {
197
- throw new Error("No payment");
198
- }
199
-
200
- const transaction = await lightsparkClient.waitForTransactionComplete(
201
- payment.id,
202
- pollTimeoutSecs,
203
- );
204
-
205
- expect(transaction.status).toEqual(TransactionStatus.SUCCESS);
206
- }, 30_000);
207
- });
File without changes