@lightsparkdev/lightspark-sdk 1.1.6 → 1.2.0

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 (123) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/{chunk-7UNNCH5S.js → chunk-VTPDR6P4.js} +1270 -342
  3. package/dist/{index-5235e43b.d.ts → index-f040db9f.d.ts} +707 -407
  4. package/dist/index.cjs +1247 -319
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +7 -7
  7. package/dist/objects/index.cjs +1180 -306
  8. package/dist/objects/index.d.ts +1 -1
  9. package/dist/objects/index.js +5 -5
  10. package/package.json +2 -2
  11. package/src/objects/Account.ts +175 -2
  12. package/src/objects/AccountToApiTokensConnection.ts +16 -5
  13. package/src/objects/AccountToChannelsConnection.ts +9 -0
  14. package/src/objects/AccountToNodesConnection.ts +19 -5
  15. package/src/objects/AccountToPaymentRequestsConnection.ts +21 -5
  16. package/src/objects/AccountToTransactionsConnection.ts +33 -9
  17. package/src/objects/AccountToWalletsConnection.ts +13 -4
  18. package/src/objects/ApiToken.ts +13 -3
  19. package/src/objects/Balances.ts +17 -3
  20. package/src/objects/BlockchainBalance.ts +34 -9
  21. package/src/objects/Channel.ts +61 -16
  22. package/src/objects/ChannelClosingTransaction.ts +81 -61
  23. package/src/objects/ChannelFees.ts +16 -5
  24. package/src/objects/ChannelOpeningTransaction.ts +81 -61
  25. package/src/objects/ChannelSnapshot.ts +66 -6
  26. package/src/objects/ChannelToTransactionsConnection.ts +26 -6
  27. package/src/objects/Connection.ts +205 -10
  28. package/src/objects/CreateApiTokenInput.ts +8 -2
  29. package/src/objects/CreateApiTokenOutput.ts +9 -3
  30. package/src/objects/CreateInvoiceInput.ts +14 -5
  31. package/src/objects/CreateInvoiceOutput.ts +7 -2
  32. package/src/objects/CreateLnurlInvoiceInput.ts +13 -3
  33. package/src/objects/CreateNodeWalletAddressInput.ts +9 -2
  34. package/src/objects/CreateNodeWalletAddressOutput.ts +10 -2
  35. package/src/objects/CreateTestModeInvoiceInput.ts +14 -4
  36. package/src/objects/CreateTestModeInvoiceOutput.ts +10 -2
  37. package/src/objects/CreateTestModePaymentInput.ts +12 -3
  38. package/src/objects/CreateTestModePaymentoutput.ts +12 -2
  39. package/src/objects/CreateUmaInvoiceInput.ts +13 -3
  40. package/src/objects/CurrencyAmount.ts +13 -2
  41. package/src/objects/DeclineToSignMessagesInput.ts +9 -2
  42. package/src/objects/DeclineToSignMessagesOutput.ts +15 -3
  43. package/src/objects/DeleteApiTokenInput.ts +7 -2
  44. package/src/objects/DeleteApiTokenOutput.ts +7 -2
  45. package/src/objects/Deposit.ts +77 -61
  46. package/src/objects/Entity.ts +184 -2
  47. package/src/objects/FeeEstimate.ts +12 -3
  48. package/src/objects/FundNodeInput.ts +9 -3
  49. package/src/objects/FundNodeOutput.ts +11 -3
  50. package/src/objects/GraphNode.ts +21 -5
  51. package/src/objects/Hop.ts +27 -9
  52. package/src/objects/HtlcAttemptFailureCode.ts +2 -0
  53. package/src/objects/IdAndSignature.ts +8 -2
  54. package/src/objects/IncomingPayment.ts +33 -7
  55. package/src/objects/IncomingPaymentAttempt.ts +21 -5
  56. package/src/objects/IncomingPaymentToAttemptsConnection.ts +21 -5
  57. package/src/objects/Invoice.ts +91 -24
  58. package/src/objects/InvoiceData.ts +75 -6
  59. package/src/objects/LightningFeeEstimateForInvoiceInput.ts +13 -3
  60. package/src/objects/LightningFeeEstimateForNodeInput.ts +12 -2
  61. package/src/objects/LightningFeeEstimateOutput.ts +15 -3
  62. package/src/objects/LightningTransaction.ts +171 -28
  63. package/src/objects/LightsparkNode.ts +311 -208
  64. package/src/objects/LightsparkNodeOwner.ts +35 -4
  65. package/src/objects/LightsparkNodeToChannelsConnection.ts +17 -4
  66. package/src/objects/LightsparkNodeWithOSK.ts +97 -15
  67. package/src/objects/LightsparkNodeWithRemoteSigning.ts +93 -13
  68. package/src/objects/Node.ts +269 -67
  69. package/src/objects/NodeAddress.ts +8 -2
  70. package/src/objects/NodeToAddressesConnection.ts +13 -3
  71. package/src/objects/OnChainTransaction.ts +156 -44
  72. package/src/objects/OutgoingPayment.ts +127 -14
  73. package/src/objects/OutgoingPaymentAttempt.ts +57 -8
  74. package/src/objects/OutgoingPaymentAttemptToHopsConnection.ts +18 -5
  75. package/src/objects/OutgoingPaymentToAttemptsConnection.ts +17 -4
  76. package/src/objects/OutgoingPaymentsForInvoiceQueryInput.ts +12 -3
  77. package/src/objects/OutgoingPaymentsForInvoiceQueryOutput.ts +11 -2
  78. package/src/objects/PageInfo.ts +14 -6
  79. package/src/objects/PayInvoiceInput.ts +12 -3
  80. package/src/objects/PayInvoiceOutput.ts +7 -2
  81. package/src/objects/PayUmaInvoiceInput.ts +12 -3
  82. package/src/objects/PaymentRequest.ts +81 -5
  83. package/src/objects/PaymentRequestData.ts +81 -4
  84. package/src/objects/PostTransactionData.ts +12 -3
  85. package/src/objects/RegisterPaymentInput.ts +10 -2
  86. package/src/objects/RegisterPaymentOutput.ts +9 -2
  87. package/src/objects/ReleaseChannelPerCommitmentSecretInput.ts +13 -2
  88. package/src/objects/ReleaseChannelPerCommitmentSecretOutput.ts +9 -2
  89. package/src/objects/ReleasePaymentPreimageInput.ts +10 -2
  90. package/src/objects/ReleasePaymentPreimageOutput.ts +9 -2
  91. package/src/objects/RequestWithdrawalInput.ts +12 -2
  92. package/src/objects/RequestWithdrawalOutput.ts +9 -2
  93. package/src/objects/RichText.ts +7 -2
  94. package/src/objects/RoutingTransaction.ts +62 -41
  95. package/src/objects/ScreenNodeInput.ts +8 -2
  96. package/src/objects/ScreenNodeOutput.ts +7 -2
  97. package/src/objects/Secret.ts +8 -2
  98. package/src/objects/SendPaymentInput.ts +11 -2
  99. package/src/objects/SendPaymentOutput.ts +7 -2
  100. package/src/objects/SetInvoicePaymentHashInput.ts +12 -3
  101. package/src/objects/SetInvoicePaymentHashOutput.ts +9 -2
  102. package/src/objects/SignInvoiceInput.ts +9 -2
  103. package/src/objects/SignInvoiceOutput.ts +7 -2
  104. package/src/objects/SignMessagesInput.ts +13 -3
  105. package/src/objects/SignMessagesOutput.ts +13 -3
  106. package/src/objects/Signable.ts +10 -3
  107. package/src/objects/SignablePayload.ts +18 -5
  108. package/src/objects/Transaction.ts +260 -9
  109. package/src/objects/TransactionFailures.ts +11 -4
  110. package/src/objects/UpdateChannelPerCommitmentPointInput.ts +13 -2
  111. package/src/objects/UpdateChannelPerCommitmentPointOutput.ts +9 -2
  112. package/src/objects/UpdateNodeSharedSecretInput.ts +10 -2
  113. package/src/objects/UpdateNodeSharedSecretOutput.ts +9 -2
  114. package/src/objects/Wallet.ts +130 -5
  115. package/src/objects/WalletToPaymentRequestsConnection.ts +21 -5
  116. package/src/objects/WalletToTransactionsConnection.ts +16 -5
  117. package/src/objects/Withdrawal.ts +77 -61
  118. package/src/objects/WithdrawalRequest.ts +25 -4
  119. package/src/objects/WithdrawalRequestToChannelClosingTransactionsConnection.ts +19 -4
  120. package/src/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.ts +19 -4
  121. package/src/objects/index.ts +5 -2
  122. package/src/tests/integration/client.test.ts +46 -7
  123. package/src/tests/serialization.test.ts +18 -0
@@ -1,12 +1,14 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import type Connection from "./Connection.js";
4
3
  import type PageInfo from "./PageInfo.js";
5
- import { PageInfoFromJson } from "./PageInfo.js";
4
+ import { PageInfoFromJson, PageInfoToJson } from "./PageInfo.js";
6
5
  import type PaymentRequest from "./PaymentRequest.js";
7
- import { PaymentRequestFromJson } from "./PaymentRequest.js";
6
+ import {
7
+ PaymentRequestFromJson,
8
+ PaymentRequestToJson,
9
+ } from "./PaymentRequest.js";
8
10
 
9
- type WalletToPaymentRequestsConnection = Connection & {
11
+ interface WalletToPaymentRequestsConnection {
10
12
  /**
11
13
  * The total count of objects in this connection, using the current filters. It is different from the
12
14
  * number of objects returned in the current page (in the `entities` field).
@@ -21,7 +23,7 @@ type WalletToPaymentRequestsConnection = Connection & {
21
23
 
22
24
  /** The typename of the object **/
23
25
  typename: string;
24
- };
26
+ }
25
27
 
26
28
  export const WalletToPaymentRequestsConnectionFromJson = (
27
29
  obj: any,
@@ -37,6 +39,20 @@ export const WalletToPaymentRequestsConnectionFromJson = (
37
39
  typename: "WalletToPaymentRequestsConnection",
38
40
  } as WalletToPaymentRequestsConnection;
39
41
  };
42
+ export const WalletToPaymentRequestsConnectionToJson = (
43
+ obj: WalletToPaymentRequestsConnection,
44
+ ): any => {
45
+ return {
46
+ __typename: "WalletToPaymentRequestsConnection",
47
+ wallet_to_payment_requests_connection_count: obj.count,
48
+ wallet_to_payment_requests_connection_page_info: PageInfoToJson(
49
+ obj.pageInfo,
50
+ ),
51
+ wallet_to_payment_requests_connection_entities: obj.entities.map((e) =>
52
+ PaymentRequestToJson(e),
53
+ ),
54
+ };
55
+ };
40
56
 
41
57
  export const FRAGMENT = `
42
58
  fragment WalletToPaymentRequestsConnectionFragment on WalletToPaymentRequestsConnection {
@@ -1,12 +1,11 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import type Connection from "./Connection.js";
4
3
  import type PageInfo from "./PageInfo.js";
5
- import { PageInfoFromJson } from "./PageInfo.js";
4
+ import { PageInfoFromJson, PageInfoToJson } from "./PageInfo.js";
6
5
  import type Transaction from "./Transaction.js";
7
- import { TransactionFromJson } from "./Transaction.js";
6
+ import { TransactionFromJson, TransactionToJson } from "./Transaction.js";
8
7
 
9
- type WalletToTransactionsConnection = Connection & {
8
+ interface WalletToTransactionsConnection {
10
9
  /**
11
10
  * The total count of objects in this connection, using the current filters. It is different from the
12
11
  * number of objects returned in the current page (in the `entities` field).
@@ -21,7 +20,7 @@ type WalletToTransactionsConnection = Connection & {
21
20
 
22
21
  /** The typename of the object **/
23
22
  typename: string;
24
- };
23
+ }
25
24
 
26
25
  export const WalletToTransactionsConnectionFromJson = (
27
26
  obj: any,
@@ -37,6 +36,18 @@ export const WalletToTransactionsConnectionFromJson = (
37
36
  typename: "WalletToTransactionsConnection",
38
37
  } as WalletToTransactionsConnection;
39
38
  };
39
+ export const WalletToTransactionsConnectionToJson = (
40
+ obj: WalletToTransactionsConnection,
41
+ ): any => {
42
+ return {
43
+ __typename: "WalletToTransactionsConnection",
44
+ wallet_to_transactions_connection_count: obj.count,
45
+ wallet_to_transactions_connection_page_info: PageInfoToJson(obj.pageInfo),
46
+ wallet_to_transactions_connection_entities: obj.entities.map((e) =>
47
+ TransactionToJson(e),
48
+ ),
49
+ };
50
+ };
40
51
 
41
52
  export const FRAGMENT = `
42
53
  fragment WalletToTransactionsConnectionFragment on WalletToTransactionsConnection {
@@ -2,70 +2,68 @@
2
2
 
3
3
  import { type Query } from "@lightsparkdev/core";
4
4
  import type CurrencyAmount from "./CurrencyAmount.js";
5
- import { CurrencyAmountFromJson } from "./CurrencyAmount.js";
6
- import type Entity from "./Entity.js";
7
- import type OnChainTransaction from "./OnChainTransaction.js";
8
- import type Transaction from "./Transaction.js";
5
+ import {
6
+ CurrencyAmountFromJson,
7
+ CurrencyAmountToJson,
8
+ } from "./CurrencyAmount.js";
9
9
  import TransactionStatus from "./TransactionStatus.js";
10
10
 
11
11
  /** This object represents an L1 withdrawal from your Lightspark Node to any Bitcoin wallet. You can retrieve this object to receive detailed information about any L1 withdrawal associated with your Lightspark Node or account. **/
12
- type Withdrawal = OnChainTransaction &
13
- Transaction &
14
- Entity & {
15
- /**
16
- * The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque
17
- * string.
18
- **/
19
- id: string;
20
-
21
- /** The date and time when this transaction was initiated. **/
22
- createdAt: string;
23
-
24
- /** The date and time when the entity was last updated. **/
25
- updatedAt: string;
26
-
27
- /** The current status of this transaction. **/
28
- status: TransactionStatus;
29
-
30
- /** The amount of money involved in this transaction. **/
31
- amount: CurrencyAmount;
32
-
33
- /**
34
- * The height of the block that included this transaction. This will be zero for unconfirmed
35
- * transactions.
36
- **/
37
- blockHeight: number;
38
-
39
- /** The Bitcoin blockchain addresses this transaction was sent to. **/
40
- destinationAddresses: string[];
41
-
42
- /** The Lightspark node this withdrawal originated from. **/
43
- originId: string;
44
-
45
- /** The typename of the object **/
46
- typename: string;
47
-
48
- /** The date and time when this transaction was completed or failed. **/
49
- resolvedAt?: string;
50
-
51
- /** The hash of this transaction, so it can be uniquely identified on the Lightning Network. **/
52
- transactionHash?: string;
53
-
54
- /**
55
- * The fees that were paid by the wallet sending the transaction to commit it to the Bitcoin
56
- * blockchain.
57
- **/
58
- fees?: CurrencyAmount;
59
-
60
- /**
61
- * The hash of the block that included this transaction. This will be null for unconfirmed
62
- * transactions.
63
- **/
64
- blockHash?: string;
65
-
66
- /** The number of blockchain confirmations for this transaction in real time. **/
67
- numConfirmations?: number;
68
- };
12
+ interface Withdrawal {
13
+ /**
14
+ * The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque
15
+ * string.
16
+ **/
17
+ id: string;
18
+
19
+ /** The date and time when this transaction was initiated. **/
20
+ createdAt: string;
21
+
22
+ /** The date and time when the entity was last updated. **/
23
+ updatedAt: string;
24
+
25
+ /** The current status of this transaction. **/
26
+ status: TransactionStatus;
27
+
28
+ /** The amount of money involved in this transaction. **/
29
+ amount: CurrencyAmount;
30
+
31
+ /**
32
+ * The height of the block that included this transaction. This will be zero for unconfirmed
33
+ * transactions.
34
+ **/
35
+ blockHeight: number;
36
+
37
+ /** The Bitcoin blockchain addresses this transaction was sent to. **/
38
+ destinationAddresses: string[];
39
+
40
+ /** The Lightspark node this withdrawal originated from. **/
41
+ originId: string;
42
+
43
+ /** The typename of the object **/
44
+ typename: string;
45
+
46
+ /** The date and time when this transaction was completed or failed. **/
47
+ resolvedAt?: string | undefined;
48
+
49
+ /** The hash of this transaction, so it can be uniquely identified on the Lightning Network. **/
50
+ transactionHash?: string | undefined;
51
+
52
+ /**
53
+ * The fees that were paid by the wallet sending the transaction to commit it to the Bitcoin
54
+ * blockchain.
55
+ **/
56
+ fees?: CurrencyAmount | undefined;
57
+
58
+ /**
59
+ * The hash of the block that included this transaction. This will be null for unconfirmed
60
+ * transactions.
61
+ **/
62
+ blockHash?: string | undefined;
63
+
64
+ /** The number of blockchain confirmations for this transaction in real time. **/
65
+ numConfirmations?: number | undefined;
66
+ }
69
67
 
70
68
  export const WithdrawalFromJson = (obj: any): Withdrawal => {
71
69
  return {
@@ -89,6 +87,24 @@ export const WithdrawalFromJson = (obj: any): Withdrawal => {
89
87
  numConfirmations: obj["withdrawal_num_confirmations"],
90
88
  } as Withdrawal;
91
89
  };
90
+ export const WithdrawalToJson = (obj: Withdrawal): any => {
91
+ return {
92
+ __typename: "Withdrawal",
93
+ withdrawal_id: obj.id,
94
+ withdrawal_created_at: obj.createdAt,
95
+ withdrawal_updated_at: obj.updatedAt,
96
+ withdrawal_status: obj.status,
97
+ withdrawal_resolved_at: obj.resolvedAt,
98
+ withdrawal_amount: CurrencyAmountToJson(obj.amount),
99
+ withdrawal_transaction_hash: obj.transactionHash,
100
+ withdrawal_fees: obj.fees ? CurrencyAmountToJson(obj.fees) : undefined,
101
+ withdrawal_block_hash: obj.blockHash,
102
+ withdrawal_block_height: obj.blockHeight,
103
+ withdrawal_destination_addresses: obj.destinationAddresses,
104
+ withdrawal_num_confirmations: obj.numConfirmations,
105
+ withdrawal_origin: { id: obj.originId },
106
+ };
107
+ };
92
108
 
93
109
  export const FRAGMENT = `
94
110
  fragment WithdrawalFragment on Withdrawal {
@@ -4,7 +4,10 @@ import { type Query } from "@lightsparkdev/core";
4
4
  import autoBind from "auto-bind";
5
5
  import type LightsparkClient from "../client.js";
6
6
  import type CurrencyAmount from "./CurrencyAmount.js";
7
- import { CurrencyAmountFromJson } from "./CurrencyAmount.js";
7
+ import {
8
+ CurrencyAmountFromJson,
9
+ CurrencyAmountToJson,
10
+ } from "./CurrencyAmount.js";
8
11
  import type Entity from "./Entity.js";
9
12
  import WithdrawalMode from "./WithdrawalMode.js";
10
13
  import WithdrawalRequestStatus from "./WithdrawalRequestStatus.js";
@@ -24,9 +27,9 @@ class WithdrawalRequest implements Entity {
24
27
  public readonly withdrawalMode: WithdrawalMode,
25
28
  public readonly status: WithdrawalRequestStatus,
26
29
  public readonly typename: string,
27
- public readonly estimatedAmount?: CurrencyAmount,
28
- public readonly completedAt?: string,
29
- public readonly withdrawalId?: string,
30
+ public readonly estimatedAmount?: CurrencyAmount | undefined,
31
+ public readonly completedAt?: string | undefined,
32
+ public readonly withdrawalId?: string | undefined,
30
33
  ) {
31
34
  autoBind(this);
32
35
  }
@@ -180,6 +183,24 @@ ${FRAGMENT}
180
183
  constructObject: (data: any) => WithdrawalRequestFromJson(data.entity),
181
184
  };
182
185
  }
186
+
187
+ public toJson() {
188
+ return {
189
+ __typename: "WithdrawalRequest",
190
+ withdrawal_request_id: this.id,
191
+ withdrawal_request_created_at: this.createdAt,
192
+ withdrawal_request_updated_at: this.updatedAt,
193
+ withdrawal_request_amount: CurrencyAmountToJson(this.amount),
194
+ withdrawal_request_estimated_amount: this.estimatedAmount
195
+ ? CurrencyAmountToJson(this.estimatedAmount)
196
+ : undefined,
197
+ withdrawal_request_bitcoin_address: this.bitcoinAddress,
198
+ withdrawal_request_withdrawal_mode: this.withdrawalMode,
199
+ withdrawal_request_status: this.status,
200
+ withdrawal_request_completed_at: this.completedAt,
201
+ withdrawal_request_withdrawal: { id: this.withdrawalId } ?? undefined,
202
+ };
203
+ }
183
204
  }
184
205
 
185
206
  export const WithdrawalRequestFromJson = (obj: any): WithdrawalRequest => {
@@ -1,11 +1,14 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
3
  import type ChannelClosingTransaction from "./ChannelClosingTransaction.js";
4
- import { ChannelClosingTransactionFromJson } from "./ChannelClosingTransaction.js";
4
+ import {
5
+ ChannelClosingTransactionFromJson,
6
+ ChannelClosingTransactionToJson,
7
+ } from "./ChannelClosingTransaction.js";
5
8
  import type PageInfo from "./PageInfo.js";
6
- import { PageInfoFromJson } from "./PageInfo.js";
9
+ import { PageInfoFromJson, PageInfoToJson } from "./PageInfo.js";
7
10
 
8
- type WithdrawalRequestToChannelClosingTransactionsConnection = {
11
+ interface WithdrawalRequestToChannelClosingTransactionsConnection {
9
12
  /** An object that holds pagination information about the objects in this connection. **/
10
13
  pageInfo: PageInfo;
11
14
 
@@ -17,7 +20,7 @@ type WithdrawalRequestToChannelClosingTransactionsConnection = {
17
20
 
18
21
  /** The channel closing transactions for the current page of this connection. **/
19
22
  entities: ChannelClosingTransaction[];
20
- };
23
+ }
21
24
 
22
25
  export const WithdrawalRequestToChannelClosingTransactionsConnectionFromJson = (
23
26
  obj: any,
@@ -37,6 +40,18 @@ export const WithdrawalRequestToChannelClosingTransactionsConnectionFromJson = (
37
40
  ].map((e) => ChannelClosingTransactionFromJson(e)),
38
41
  } as WithdrawalRequestToChannelClosingTransactionsConnection;
39
42
  };
43
+ export const WithdrawalRequestToChannelClosingTransactionsConnectionToJson = (
44
+ obj: WithdrawalRequestToChannelClosingTransactionsConnection,
45
+ ): any => {
46
+ return {
47
+ withdrawal_request_to_channel_closing_transactions_connection_page_info:
48
+ PageInfoToJson(obj.pageInfo),
49
+ withdrawal_request_to_channel_closing_transactions_connection_count:
50
+ obj.count,
51
+ withdrawal_request_to_channel_closing_transactions_connection_entities:
52
+ obj.entities.map((e) => ChannelClosingTransactionToJson(e)),
53
+ };
54
+ };
40
55
 
41
56
  export const FRAGMENT = `
42
57
  fragment WithdrawalRequestToChannelClosingTransactionsConnectionFragment on WithdrawalRequestToChannelClosingTransactionsConnection {
@@ -1,11 +1,14 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
3
  import type ChannelOpeningTransaction from "./ChannelOpeningTransaction.js";
4
- import { ChannelOpeningTransactionFromJson } from "./ChannelOpeningTransaction.js";
4
+ import {
5
+ ChannelOpeningTransactionFromJson,
6
+ ChannelOpeningTransactionToJson,
7
+ } from "./ChannelOpeningTransaction.js";
5
8
  import type PageInfo from "./PageInfo.js";
6
- import { PageInfoFromJson } from "./PageInfo.js";
9
+ import { PageInfoFromJson, PageInfoToJson } from "./PageInfo.js";
7
10
 
8
- type WithdrawalRequestToChannelOpeningTransactionsConnection = {
11
+ interface WithdrawalRequestToChannelOpeningTransactionsConnection {
9
12
  /** An object that holds pagination information about the objects in this connection. **/
10
13
  pageInfo: PageInfo;
11
14
 
@@ -17,7 +20,7 @@ type WithdrawalRequestToChannelOpeningTransactionsConnection = {
17
20
 
18
21
  /** The channel opening transactions for the current page of this connection. **/
19
22
  entities: ChannelOpeningTransaction[];
20
- };
23
+ }
21
24
 
22
25
  export const WithdrawalRequestToChannelOpeningTransactionsConnectionFromJson = (
23
26
  obj: any,
@@ -37,6 +40,18 @@ export const WithdrawalRequestToChannelOpeningTransactionsConnectionFromJson = (
37
40
  ].map((e) => ChannelOpeningTransactionFromJson(e)),
38
41
  } as WithdrawalRequestToChannelOpeningTransactionsConnection;
39
42
  };
43
+ export const WithdrawalRequestToChannelOpeningTransactionsConnectionToJson = (
44
+ obj: WithdrawalRequestToChannelOpeningTransactionsConnection,
45
+ ): any => {
46
+ return {
47
+ withdrawal_request_to_channel_opening_transactions_connection_page_info:
48
+ PageInfoToJson(obj.pageInfo),
49
+ withdrawal_request_to_channel_opening_transactions_connection_count:
50
+ obj.count,
51
+ withdrawal_request_to_channel_opening_transactions_connection_entities:
52
+ obj.entities.map((e) => ChannelOpeningTransactionToJson(e)),
53
+ };
54
+ };
40
55
 
41
56
  export const FRAGMENT = `
42
57
  fragment WithdrawalRequestToChannelOpeningTransactionsConnectionFragment on WithdrawalRequestToChannelOpeningTransactionsConnection {
@@ -68,7 +68,10 @@ export {
68
68
  default as LightningTransaction,
69
69
  getLightningTransactionQuery,
70
70
  } from "./LightningTransaction.js";
71
- export { default as LightsparkNode } from "./LightsparkNode.js";
71
+ export {
72
+ default as LightsparkNode,
73
+ getLightsparkNodeQuery,
74
+ } from "./LightsparkNode.js";
72
75
  export {
73
76
  default as LightsparkNodeOwner,
74
77
  getLightsparkNodeOwnerQuery,
@@ -77,7 +80,7 @@ export { default as LightsparkNodeStatus } from "./LightsparkNodeStatus.js";
77
80
  export { default as LightsparkNodeToChannelsConnection } from "./LightsparkNodeToChannelsConnection.js";
78
81
  export { default as LightsparkNodeWithOSK } from "./LightsparkNodeWithOSK.js";
79
82
  export { default as LightsparkNodeWithRemoteSigning } from "./LightsparkNodeWithRemoteSigning.js";
80
- export { default as Node } from "./Node.js";
83
+ export { default as Node, getNodeQuery } from "./Node.js";
81
84
  export { default as NodeAddress } from "./NodeAddress.js";
82
85
  export { default as NodeAddressType } from "./NodeAddressType.js";
83
86
  export { default as NodeToAddressesConnection } from "./NodeToAddressesConnection.js";
@@ -1,4 +1,4 @@
1
- import { pollUntil } from "@lightsparkdev/core";
1
+ import { mapCurrencyAmount, pollUntil, round } from "@lightsparkdev/core";
2
2
  import LightsparkClient from "../../client.js";
3
3
  import { getCredentialsFromEnvOrThrow } from "../../env.js";
4
4
  import {
@@ -83,7 +83,7 @@ describe("lightspark-sdk client", () => {
83
83
  }, 10000);
84
84
 
85
85
  const satsToFund = 50_000;
86
- test("Should deposit funds to wallet with a defined amount of sats", async () => {
86
+ test("Should deposit funds to node with a defined amount of sats", async () => {
87
87
  const lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl);
88
88
  const account = await lightsparkClient.getCurrentAccount();
89
89
 
@@ -95,9 +95,45 @@ describe("lightspark-sdk client", () => {
95
95
  BitcoinNetwork.REGTEST,
96
96
  ]);
97
97
  let regtestNode = nodesConnection?.entities[0];
98
- const initialLocalBalance = regtestNode?.localBalance?.originalValue;
98
+ const initialTotalBalance = mapCurrencyAmount(regtestNode?.totalBalance);
99
99
  const nodeId = getRegtestNodeId();
100
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
+
101
137
  await lightsparkClient.fundNode(nodeId, satsToFund);
102
138
 
103
139
  regtestNode = await pollUntil(
@@ -107,8 +143,9 @@ describe("lightspark-sdk client", () => {
107
143
  (current, response) => {
108
144
  if (
109
145
  current &&
110
- current.entities[0]?.localBalance?.originalValue !==
111
- initialLocalBalance
146
+ !mapCurrencyAmount(current.entities[0]?.totalBalance).isEqualTo(
147
+ initialTotalBalance,
148
+ )
112
149
  ) {
113
150
  return {
114
151
  stopPolling: true,
@@ -124,8 +161,10 @@ describe("lightspark-sdk client", () => {
124
161
  );
125
162
 
126
163
  expect(
127
- regtestNode.localBalance?.originalValue !== initialLocalBalance,
128
- ).toBe(true);
164
+ mapCurrencyAmount(regtestNode.totalBalance).isEqualTo(
165
+ initialTotalBalance,
166
+ ),
167
+ ).toBe(false);
129
168
  }, 120_000);
130
169
 
131
170
  test("Should send test mode payment", async () => {
@@ -0,0 +1,18 @@
1
+ import {
2
+ InvoiceDataFromJson,
3
+ InvoiceDataToJson,
4
+ } from "../objects/InvoiceData.js";
5
+
6
+ describe("Serialization", () => {
7
+ test("should serialize and deserialize InvoiceData to the same object", async () => {
8
+ const serialized = `{"__typename": "InvoiceData", "invoice_data_encoded_payment_request":"lnbcrt34170n1pj5vdn4pp56jhw0672v566u4rvl333v8hwwuvavvu9gx4a2mqag4pkrvm0hwkqhp5xaz278y6cejcvpqnndl4wfq3slgthjduwlfksg778aevn23v2pdscqzpgxqyz5vqsp5ee5jezfvjqvvz7hfwta3ekk8hs6dq36szkgp40qh7twa8upquxlq9qyyssqjg2slc95falxf2t67y0wu2w43qwfcvfflwl8tn4ppqw9tumwqxk36qkfct9p2w8c3yy2ld7c6nacy4ssv2gl6qyqfpmhl4jmarnjf8cpvjlxek","invoice_data_bitcoin_network":"REGTEST","invoice_data_payment_hash":"d4aee7ebca6535ae546cfc63161eee7719d6338541abd56c1d454361b36fbbac","invoice_data_amount":{"currency_amount_original_value":3417,"currency_amount_original_unit":"SATOSHI","currency_amount_preferred_currency_unit":"USD","currency_amount_preferred_currency_value_rounded":118,"currency_amount_preferred_currency_value_approx":118.89352818371607},"invoice_data_created_at":"2023-11-04T12:17:57Z","invoice_data_expires_at":"2023-11-05T12:17:57Z","invoice_data_memo":null,"invoice_data_destination":{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759Z","graph_node_updated_at":"2023-11-04T12:01:04.015414Z","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}}`;
9
+ const deserialized = InvoiceDataFromJson(JSON.parse(serialized));
10
+ const reserialized = InvoiceDataToJson(deserialized);
11
+ expect(reserialized).toEqual(JSON.parse(serialized));
12
+
13
+ const deserializedAgain = InvoiceDataFromJson(reserialized);
14
+ expect(JSON.stringify(deserializedAgain)).toEqual(
15
+ JSON.stringify(deserialized),
16
+ );
17
+ });
18
+ });