@lightsparkdev/lightspark-sdk 1.1.7 → 1.2.1

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 (136) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/{chunk-5RDIWPBE.js → chunk-D32EWIPX.js} +3 -1
  3. package/dist/{chunk-7UT6YX37.js → chunk-VTPDR6P4.js} +393 -275
  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-d31f4469.d.ts → index-5acc6526.d.ts} +1403 -408
  8. package/dist/index.cjs +424 -296
  9. package/dist/index.d.cts +41 -0
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +32 -27
  12. package/dist/objects/index.cjs +395 -277
  13. package/dist/objects/index.d.cts +4 -0
  14. package/dist/objects/index.d.ts +1 -1
  15. package/dist/objects/index.js +6 -6
  16. package/dist/{text-encoding-MDIPJAHL.js → text-encoding-26SMKBAQ.js} +3 -1
  17. package/package.json +5 -5
  18. package/src/auth/AccountTokenAuthProvider.ts +15 -11
  19. package/src/client.ts +7 -6
  20. package/src/helpers.ts +3 -1
  21. package/src/objects/Account.ts +21 -2
  22. package/src/objects/AccountToApiTokensConnection.ts +16 -5
  23. package/src/objects/AccountToChannelsConnection.ts +14 -0
  24. package/src/objects/AccountToNodesConnection.ts +19 -5
  25. package/src/objects/AccountToPaymentRequestsConnection.ts +21 -5
  26. package/src/objects/AccountToTransactionsConnection.ts +33 -9
  27. package/src/objects/AccountToWalletsConnection.ts +13 -4
  28. package/src/objects/ApiToken.ts +13 -3
  29. package/src/objects/Balances.ts +17 -3
  30. package/src/objects/BlockchainBalance.ts +34 -9
  31. package/src/objects/Channel.ts +92 -16
  32. package/src/objects/ChannelClosingTransaction.ts +81 -61
  33. package/src/objects/ChannelFees.ts +16 -5
  34. package/src/objects/ChannelOpeningTransaction.ts +81 -61
  35. package/src/objects/ChannelSnapshot.ts +32 -8
  36. package/src/objects/ChannelToTransactionsConnection.ts +26 -6
  37. package/src/objects/Connection.ts +205 -10
  38. package/src/objects/CreateApiTokenInput.ts +8 -2
  39. package/src/objects/CreateApiTokenOutput.ts +9 -3
  40. package/src/objects/CreateInvoiceInput.ts +14 -5
  41. package/src/objects/CreateInvoiceOutput.ts +7 -2
  42. package/src/objects/CreateLnurlInvoiceInput.ts +13 -3
  43. package/src/objects/CreateNodeWalletAddressInput.ts +9 -2
  44. package/src/objects/CreateNodeWalletAddressOutput.ts +10 -2
  45. package/src/objects/CreateTestModeInvoiceInput.ts +14 -4
  46. package/src/objects/CreateTestModeInvoiceOutput.ts +10 -2
  47. package/src/objects/CreateTestModePaymentInput.ts +12 -3
  48. package/src/objects/CreateTestModePaymentoutput.ts +12 -2
  49. package/src/objects/CreateUmaInvoiceInput.ts +13 -3
  50. package/src/objects/CurrencyAmount.ts +13 -2
  51. package/src/objects/DeclineToSignMessagesInput.ts +9 -2
  52. package/src/objects/DeclineToSignMessagesOutput.ts +15 -3
  53. package/src/objects/DeleteApiTokenInput.ts +7 -2
  54. package/src/objects/DeleteApiTokenOutput.ts +7 -2
  55. package/src/objects/Deposit.ts +77 -61
  56. package/src/objects/Entity.ts +2 -2
  57. package/src/objects/FeeEstimate.ts +12 -3
  58. package/src/objects/FundNodeInput.ts +9 -3
  59. package/src/objects/FundNodeOutput.ts +11 -3
  60. package/src/objects/GraphNode.ts +49 -5
  61. package/src/objects/Hop.ts +27 -9
  62. package/src/objects/IdAndSignature.ts +8 -2
  63. package/src/objects/IncomingPayment.ts +50 -7
  64. package/src/objects/IncomingPaymentAttempt.ts +21 -5
  65. package/src/objects/IncomingPaymentToAttemptsConnection.ts +21 -5
  66. package/src/objects/Invoice.ts +37 -24
  67. package/src/objects/InvoiceData.ts +21 -6
  68. package/src/objects/LightningFeeEstimateForInvoiceInput.ts +13 -3
  69. package/src/objects/LightningFeeEstimateForNodeInput.ts +12 -2
  70. package/src/objects/LightningFeeEstimateOutput.ts +15 -3
  71. package/src/objects/LightningTransaction.ts +117 -28
  72. package/src/objects/LightsparkNode.ts +250 -210
  73. package/src/objects/LightsparkNodeOwner.ts +35 -4
  74. package/src/objects/LightsparkNodeToChannelsConnection.ts +17 -4
  75. package/src/objects/LightsparkNodeWithOSK.ts +127 -17
  76. package/src/objects/LightsparkNodeWithRemoteSigning.ts +122 -15
  77. package/src/objects/Node.ts +209 -68
  78. package/src/objects/NodeAddress.ts +8 -2
  79. package/src/objects/NodeToAddressesConnection.ts +13 -3
  80. package/src/objects/OnChainTransaction.ts +156 -44
  81. package/src/objects/OutgoingPayment.ts +72 -14
  82. package/src/objects/OutgoingPaymentAttempt.ts +63 -8
  83. package/src/objects/OutgoingPaymentAttemptToHopsConnection.ts +18 -5
  84. package/src/objects/OutgoingPaymentToAttemptsConnection.ts +17 -4
  85. package/src/objects/OutgoingPaymentsForInvoiceQueryInput.ts +12 -3
  86. package/src/objects/OutgoingPaymentsForInvoiceQueryOutput.ts +11 -2
  87. package/src/objects/PageInfo.ts +14 -6
  88. package/src/objects/PayInvoiceInput.ts +12 -3
  89. package/src/objects/PayInvoiceOutput.ts +7 -2
  90. package/src/objects/PayUmaInvoiceInput.ts +12 -3
  91. package/src/objects/PaymentRequest.ts +27 -5
  92. package/src/objects/PaymentRequestData.ts +27 -4
  93. package/src/objects/PostTransactionData.ts +12 -3
  94. package/src/objects/RegisterPaymentInput.ts +10 -2
  95. package/src/objects/RegisterPaymentOutput.ts +9 -2
  96. package/src/objects/ReleaseChannelPerCommitmentSecretInput.ts +13 -2
  97. package/src/objects/ReleaseChannelPerCommitmentSecretOutput.ts +9 -2
  98. package/src/objects/ReleasePaymentPreimageInput.ts +10 -2
  99. package/src/objects/ReleasePaymentPreimageOutput.ts +9 -2
  100. package/src/objects/RequestWithdrawalInput.ts +12 -2
  101. package/src/objects/RequestWithdrawalOutput.ts +9 -2
  102. package/src/objects/RichText.ts +7 -2
  103. package/src/objects/RoutingTransaction.ts +62 -41
  104. package/src/objects/ScreenNodeInput.ts +8 -2
  105. package/src/objects/ScreenNodeOutput.ts +7 -2
  106. package/src/objects/Secret.ts +8 -2
  107. package/src/objects/SendPaymentInput.ts +11 -2
  108. package/src/objects/SendPaymentOutput.ts +7 -2
  109. package/src/objects/SetInvoicePaymentHashInput.ts +12 -3
  110. package/src/objects/SetInvoicePaymentHashOutput.ts +9 -2
  111. package/src/objects/SignInvoiceInput.ts +9 -2
  112. package/src/objects/SignInvoiceOutput.ts +7 -2
  113. package/src/objects/SignMessagesInput.ts +13 -3
  114. package/src/objects/SignMessagesOutput.ts +13 -3
  115. package/src/objects/Signable.ts +10 -3
  116. package/src/objects/SignablePayload.ts +18 -5
  117. package/src/objects/Transaction.ts +206 -9
  118. package/src/objects/TransactionFailures.ts +11 -4
  119. package/src/objects/UpdateChannelPerCommitmentPointInput.ts +13 -2
  120. package/src/objects/UpdateChannelPerCommitmentPointOutput.ts +9 -2
  121. package/src/objects/UpdateNodeSharedSecretInput.ts +10 -2
  122. package/src/objects/UpdateNodeSharedSecretOutput.ts +9 -2
  123. package/src/objects/Wallet.ts +34 -5
  124. package/src/objects/WalletToPaymentRequestsConnection.ts +21 -5
  125. package/src/objects/WalletToTransactionsConnection.ts +16 -5
  126. package/src/objects/Withdrawal.ts +77 -61
  127. package/src/objects/WithdrawalRequest.ts +42 -4
  128. package/src/objects/WithdrawalRequestToChannelClosingTransactionsConnection.ts +19 -4
  129. package/src/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.ts +19 -4
  130. package/src/objects/index.ts +5 -2
  131. package/src/tests/integration/constants.ts +13 -0
  132. package/src/tests/integration/general-regtest.test.ts +652 -0
  133. package/src/tests/serialization.test.ts +21 -0
  134. package/src/webhooks.ts +1 -1
  135. package/src/tests/integration/client.test.ts +0 -207
  136. /package/dist/{chunk-NIMBE7W3.js → chunk-BMTV3EA2.js} +0 -0
@@ -3,13 +3,13 @@
3
3
  import NodeAddressType from "./NodeAddressType.js";
4
4
 
5
5
  /** This object represents the address of a node on the Lightning Network. **/
6
- type NodeAddress = {
6
+ interface NodeAddress {
7
7
  /** The string representation of the address. **/
8
8
  address: string;
9
9
 
10
10
  /** The type, or protocol, of this address. **/
11
11
  type: NodeAddressType;
12
- };
12
+ }
13
13
 
14
14
  export const NodeAddressFromJson = (obj: any): NodeAddress => {
15
15
  return {
@@ -18,6 +18,12 @@ export const NodeAddressFromJson = (obj: any): NodeAddress => {
18
18
  NodeAddressType[obj["node_address_type"]] ?? NodeAddressType.FUTURE_VALUE,
19
19
  } as NodeAddress;
20
20
  };
21
+ export const NodeAddressToJson = (obj: NodeAddress): any => {
22
+ return {
23
+ node_address_address: obj.address,
24
+ node_address_type: obj.type,
25
+ };
26
+ };
21
27
 
22
28
  export const FRAGMENT = `
23
29
  fragment NodeAddressFragment on NodeAddress {
@@ -1,10 +1,10 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
3
  import type NodeAddress from "./NodeAddress.js";
4
- import { NodeAddressFromJson } from "./NodeAddress.js";
4
+ import { NodeAddressFromJson, NodeAddressToJson } from "./NodeAddress.js";
5
5
 
6
6
  /** A connection between a node and the addresses it has announced for itself on Lightning Network. **/
7
- type NodeToAddressesConnection = {
7
+ interface NodeToAddressesConnection {
8
8
  /**
9
9
  * The total count of objects in this connection, using the current filters. It is different from the
10
10
  * number of objects returned in the current page (in the `entities` field).
@@ -13,7 +13,7 @@ type NodeToAddressesConnection = {
13
13
 
14
14
  /** The addresses for the current page of this connection. **/
15
15
  entities: NodeAddress[];
16
- };
16
+ }
17
17
 
18
18
  export const NodeToAddressesConnectionFromJson = (
19
19
  obj: any,
@@ -25,6 +25,16 @@ export const NodeToAddressesConnectionFromJson = (
25
25
  ),
26
26
  } as NodeToAddressesConnection;
27
27
  };
28
+ export const NodeToAddressesConnectionToJson = (
29
+ obj: NodeToAddressesConnection,
30
+ ): any => {
31
+ return {
32
+ node_to_addresses_connection_count: obj.count,
33
+ node_to_addresses_connection_entities: obj.entities.map((e) =>
34
+ NodeAddressToJson(e),
35
+ ),
36
+ };
37
+ };
28
38
 
29
39
  export const FRAGMENT = `
30
40
  fragment NodeToAddressesConnectionFragment on NodeToAddressesConnection {
@@ -4,67 +4,67 @@ import { LightsparkException, type Query } from "@lightsparkdev/core";
4
4
  import type ChannelClosingTransaction from "./ChannelClosingTransaction.js";
5
5
  import type ChannelOpeningTransaction from "./ChannelOpeningTransaction.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 Deposit from "./Deposit.js";
9
- import type Entity from "./Entity.js";
10
- import type Transaction from "./Transaction.js";
11
12
  import TransactionStatus from "./TransactionStatus.js";
12
13
  import type Withdrawal from "./Withdrawal.js";
13
14
 
14
15
  /** This object represents an L1 transaction that occurred on the Bitcoin Network. You can retrieve this object to receive information about a specific on-chain transaction made on the Lightning Network associated with your Lightspark Node. **/
15
- type OnChainTransaction = Transaction &
16
- Entity & {
17
- /**
18
- * The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque
19
- * string.
20
- **/
21
- id: string;
16
+ interface OnChainTransaction {
17
+ /**
18
+ * The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque
19
+ * string.
20
+ **/
21
+ id: string;
22
22
 
23
- /** The date and time when this transaction was initiated. **/
24
- createdAt: string;
23
+ /** The date and time when this transaction was initiated. **/
24
+ createdAt: string;
25
25
 
26
- /** The date and time when the entity was last updated. **/
27
- updatedAt: string;
26
+ /** The date and time when the entity was last updated. **/
27
+ updatedAt: string;
28
28
 
29
- /** The current status of this transaction. **/
30
- status: TransactionStatus;
29
+ /** The current status of this transaction. **/
30
+ status: TransactionStatus;
31
31
 
32
- /** The amount of money involved in this transaction. **/
33
- amount: CurrencyAmount;
32
+ /** The amount of money involved in this transaction. **/
33
+ amount: CurrencyAmount;
34
34
 
35
- /**
36
- * The height of the block that included this transaction. This will be zero for unconfirmed
37
- * transactions.
38
- **/
39
- blockHeight: number;
35
+ /**
36
+ * The height of the block that included this transaction. This will be zero for unconfirmed
37
+ * transactions.
38
+ **/
39
+ blockHeight: number;
40
40
 
41
- /** The Bitcoin blockchain addresses this transaction was sent to. **/
42
- destinationAddresses: string[];
41
+ /** The Bitcoin blockchain addresses this transaction was sent to. **/
42
+ destinationAddresses: string[];
43
43
 
44
- /** The typename of the object **/
45
- typename: string;
44
+ /** The typename of the object **/
45
+ typename: string;
46
46
 
47
- /** The date and time when this transaction was completed or failed. **/
48
- resolvedAt?: string;
47
+ /** The date and time when this transaction was completed or failed. **/
48
+ resolvedAt?: string | undefined;
49
49
 
50
- /** The hash of this transaction, so it can be uniquely identified on the Lightning Network. **/
51
- transactionHash?: string;
50
+ /** The hash of this transaction, so it can be uniquely identified on the Lightning Network. **/
51
+ transactionHash?: string | undefined;
52
52
 
53
- /**
54
- * The fees that were paid by the wallet sending the transaction to commit it to the Bitcoin
55
- * blockchain.
56
- **/
57
- fees?: CurrencyAmount;
53
+ /**
54
+ * The fees that were paid by the wallet sending the transaction to commit it to the Bitcoin
55
+ * blockchain.
56
+ **/
57
+ fees?: CurrencyAmount | undefined;
58
58
 
59
- /**
60
- * The hash of the block that included this transaction. This will be null for unconfirmed
61
- * transactions.
62
- **/
63
- blockHash?: string;
59
+ /**
60
+ * The hash of the block that included this transaction. This will be null for unconfirmed
61
+ * transactions.
62
+ **/
63
+ blockHash?: string | undefined;
64
64
 
65
- /** The number of blockchain confirmations for this transaction in real time. **/
66
- numConfirmations?: number;
67
- };
65
+ /** The number of blockchain confirmations for this transaction in real time. **/
66
+ numConfirmations?: number | undefined;
67
+ }
68
68
 
69
69
  export const OnChainTransactionFromJson = (obj: any): OnChainTransaction => {
70
70
  if (obj["__typename"] == "ChannelClosingTransaction") {
@@ -162,6 +162,118 @@ export const OnChainTransactionFromJson = (obj: any): OnChainTransaction => {
162
162
  `Couldn't find a concrete type for interface OnChainTransaction corresponding to the typename=${obj["__typename"]}`,
163
163
  );
164
164
  };
165
+ export const OnChainTransactionToJson = (obj: OnChainTransaction): any => {
166
+ if (obj.typename == "ChannelClosingTransaction") {
167
+ const channelClosingTransaction = obj as ChannelClosingTransaction;
168
+ return {
169
+ __typename: "ChannelClosingTransaction",
170
+ channel_closing_transaction_id: channelClosingTransaction.id,
171
+ channel_closing_transaction_created_at:
172
+ channelClosingTransaction.createdAt,
173
+ channel_closing_transaction_updated_at:
174
+ channelClosingTransaction.updatedAt,
175
+ channel_closing_transaction_status: channelClosingTransaction.status,
176
+ channel_closing_transaction_resolved_at:
177
+ channelClosingTransaction.resolvedAt,
178
+ channel_closing_transaction_amount: CurrencyAmountToJson(
179
+ channelClosingTransaction.amount,
180
+ ),
181
+ channel_closing_transaction_transaction_hash:
182
+ channelClosingTransaction.transactionHash,
183
+ channel_closing_transaction_fees: channelClosingTransaction.fees
184
+ ? CurrencyAmountToJson(channelClosingTransaction.fees)
185
+ : undefined,
186
+ channel_closing_transaction_block_hash:
187
+ channelClosingTransaction.blockHash,
188
+ channel_closing_transaction_block_height:
189
+ channelClosingTransaction.blockHeight,
190
+ channel_closing_transaction_destination_addresses:
191
+ channelClosingTransaction.destinationAddresses,
192
+ channel_closing_transaction_num_confirmations:
193
+ channelClosingTransaction.numConfirmations,
194
+ channel_closing_transaction_channel:
195
+ { id: channelClosingTransaction.channelId } ?? undefined,
196
+ };
197
+ }
198
+ if (obj.typename == "ChannelOpeningTransaction") {
199
+ const channelOpeningTransaction = obj as ChannelOpeningTransaction;
200
+ return {
201
+ __typename: "ChannelOpeningTransaction",
202
+ channel_opening_transaction_id: channelOpeningTransaction.id,
203
+ channel_opening_transaction_created_at:
204
+ channelOpeningTransaction.createdAt,
205
+ channel_opening_transaction_updated_at:
206
+ channelOpeningTransaction.updatedAt,
207
+ channel_opening_transaction_status: channelOpeningTransaction.status,
208
+ channel_opening_transaction_resolved_at:
209
+ channelOpeningTransaction.resolvedAt,
210
+ channel_opening_transaction_amount: CurrencyAmountToJson(
211
+ channelOpeningTransaction.amount,
212
+ ),
213
+ channel_opening_transaction_transaction_hash:
214
+ channelOpeningTransaction.transactionHash,
215
+ channel_opening_transaction_fees: channelOpeningTransaction.fees
216
+ ? CurrencyAmountToJson(channelOpeningTransaction.fees)
217
+ : undefined,
218
+ channel_opening_transaction_block_hash:
219
+ channelOpeningTransaction.blockHash,
220
+ channel_opening_transaction_block_height:
221
+ channelOpeningTransaction.blockHeight,
222
+ channel_opening_transaction_destination_addresses:
223
+ channelOpeningTransaction.destinationAddresses,
224
+ channel_opening_transaction_num_confirmations:
225
+ channelOpeningTransaction.numConfirmations,
226
+ channel_opening_transaction_channel:
227
+ { id: channelOpeningTransaction.channelId } ?? undefined,
228
+ };
229
+ }
230
+ if (obj.typename == "Deposit") {
231
+ const deposit = obj as Deposit;
232
+ return {
233
+ __typename: "Deposit",
234
+ deposit_id: deposit.id,
235
+ deposit_created_at: deposit.createdAt,
236
+ deposit_updated_at: deposit.updatedAt,
237
+ deposit_status: deposit.status,
238
+ deposit_resolved_at: deposit.resolvedAt,
239
+ deposit_amount: CurrencyAmountToJson(deposit.amount),
240
+ deposit_transaction_hash: deposit.transactionHash,
241
+ deposit_fees: deposit.fees
242
+ ? CurrencyAmountToJson(deposit.fees)
243
+ : undefined,
244
+ deposit_block_hash: deposit.blockHash,
245
+ deposit_block_height: deposit.blockHeight,
246
+ deposit_destination_addresses: deposit.destinationAddresses,
247
+ deposit_num_confirmations: deposit.numConfirmations,
248
+ deposit_destination: { id: deposit.destinationId },
249
+ };
250
+ }
251
+ if (obj.typename == "Withdrawal") {
252
+ const withdrawal = obj as Withdrawal;
253
+ return {
254
+ __typename: "Withdrawal",
255
+ withdrawal_id: withdrawal.id,
256
+ withdrawal_created_at: withdrawal.createdAt,
257
+ withdrawal_updated_at: withdrawal.updatedAt,
258
+ withdrawal_status: withdrawal.status,
259
+ withdrawal_resolved_at: withdrawal.resolvedAt,
260
+ withdrawal_amount: CurrencyAmountToJson(withdrawal.amount),
261
+ withdrawal_transaction_hash: withdrawal.transactionHash,
262
+ withdrawal_fees: withdrawal.fees
263
+ ? CurrencyAmountToJson(withdrawal.fees)
264
+ : undefined,
265
+ withdrawal_block_hash: withdrawal.blockHash,
266
+ withdrawal_block_height: withdrawal.blockHeight,
267
+ withdrawal_destination_addresses: withdrawal.destinationAddresses,
268
+ withdrawal_num_confirmations: withdrawal.numConfirmations,
269
+ withdrawal_origin: { id: withdrawal.originId },
270
+ };
271
+ }
272
+ throw new LightsparkException(
273
+ "DeserializationError",
274
+ `Couldn't find a concrete type for interface OnChainTransaction corresponding to the typename=${obj.typename}`,
275
+ );
276
+ };
165
277
 
166
278
  export const FRAGMENT = `
167
279
  fragment OnChainTransactionFragment on OnChainTransaction {
@@ -4,38 +4,68 @@ 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";
11
+ import type Entity from "./Entity.js";
8
12
  import type LightningTransaction from "./LightningTransaction.js";
9
13
  import type OutgoingPaymentToAttemptsConnection from "./OutgoingPaymentToAttemptsConnection.js";
10
14
  import { OutgoingPaymentToAttemptsConnectionFromJson } from "./OutgoingPaymentToAttemptsConnection.js";
11
15
  import PaymentFailureReason from "./PaymentFailureReason.js";
12
16
  import type PaymentRequestData from "./PaymentRequestData.js";
13
- import { PaymentRequestDataFromJson } from "./PaymentRequestData.js";
17
+ import {
18
+ PaymentRequestDataFromJson,
19
+ PaymentRequestDataToJson,
20
+ } from "./PaymentRequestData.js";
14
21
  import type PostTransactionData from "./PostTransactionData.js";
15
- import { PostTransactionDataFromJson } from "./PostTransactionData.js";
22
+ import {
23
+ PostTransactionDataFromJson,
24
+ PostTransactionDataToJson,
25
+ } from "./PostTransactionData.js";
16
26
  import type RichText from "./RichText.js";
17
- import { RichTextFromJson } from "./RichText.js";
27
+ import { RichTextFromJson, RichTextToJson } from "./RichText.js";
28
+ import type Transaction from "./Transaction.js";
18
29
  import TransactionStatus from "./TransactionStatus.js";
19
30
 
20
31
  /** This object represents a Lightning Network payment sent from a Lightspark Node. You can retrieve this object to receive payment related information about any payment sent from your Lightspark Node on the Lightning Network. **/
21
- class OutgoingPayment implements LightningTransaction {
32
+ class OutgoingPayment implements LightningTransaction, Transaction, Entity {
22
33
  constructor(
34
+ /**
35
+ * The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque
36
+ * string.
37
+ **/
23
38
  public readonly id: string,
39
+ /** The date and time when this transaction was initiated. **/
24
40
  public readonly createdAt: string,
41
+ /** The date and time when the entity was last updated. **/
25
42
  public readonly updatedAt: string,
43
+ /** The current status of this transaction. **/
26
44
  public readonly status: TransactionStatus,
45
+ /** The amount of money involved in this transaction. **/
27
46
  public readonly amount: CurrencyAmount,
47
+ /** The Lightspark node this payment originated from. **/
28
48
  public readonly originId: string,
49
+ /** The typename of the object **/
29
50
  public readonly typename: string,
30
- public readonly resolvedAt?: string,
31
- public readonly transactionHash?: string,
32
- public readonly destinationId?: string,
33
- public readonly fees?: CurrencyAmount,
34
- public readonly paymentRequestData?: PaymentRequestData,
35
- public readonly failureReason?: PaymentFailureReason,
36
- public readonly failureMessage?: RichText,
37
- public readonly umaPostTransactionData?: PostTransactionData[],
38
- public readonly paymentPreimage?: string,
51
+ /** The date and time when this transaction was completed or failed. **/
52
+ public readonly resolvedAt?: string | undefined,
53
+ /** The hash of this transaction, so it can be uniquely identified on the Lightning Network. **/
54
+ public readonly transactionHash?: string | undefined,
55
+ /** If known, the final recipient node this payment was sent to. **/
56
+ public readonly destinationId?: string | undefined,
57
+ /** The fees paid by the sender node to send the payment. **/
58
+ public readonly fees?: CurrencyAmount | undefined,
59
+ /** The data of the payment request that was paid by this transaction, if known. **/
60
+ public readonly paymentRequestData?: PaymentRequestData | undefined,
61
+ /** If applicable, the reason why the payment failed. **/
62
+ public readonly failureReason?: PaymentFailureReason | undefined,
63
+ /** If applicable, user-facing error message describing why the payment failed. **/
64
+ public readonly failureMessage?: RichText | undefined,
65
+ /** The post transaction data which can be used in KYT payment registration. **/
66
+ public readonly umaPostTransactionData?: PostTransactionData[] | undefined,
67
+ /** The preimage of the payment. **/
68
+ public readonly paymentPreimage?: string | undefined,
39
69
  ) {
40
70
  autoBind(this);
41
71
  }
@@ -166,6 +196,34 @@ ${FRAGMENT}
166
196
  constructObject: (data: any) => OutgoingPaymentFromJson(data.entity),
167
197
  };
168
198
  }
199
+
200
+ public toJson() {
201
+ return {
202
+ __typename: "OutgoingPayment",
203
+ outgoing_payment_id: this.id,
204
+ outgoing_payment_created_at: this.createdAt,
205
+ outgoing_payment_updated_at: this.updatedAt,
206
+ outgoing_payment_status: this.status,
207
+ outgoing_payment_resolved_at: this.resolvedAt,
208
+ outgoing_payment_amount: CurrencyAmountToJson(this.amount),
209
+ outgoing_payment_transaction_hash: this.transactionHash,
210
+ outgoing_payment_origin: { id: this.originId },
211
+ outgoing_payment_destination: { id: this.destinationId } ?? undefined,
212
+ outgoing_payment_fees: this.fees
213
+ ? CurrencyAmountToJson(this.fees)
214
+ : undefined,
215
+ outgoing_payment_payment_request_data: this.paymentRequestData
216
+ ? PaymentRequestDataToJson(this.paymentRequestData)
217
+ : undefined,
218
+ outgoing_payment_failure_reason: this.failureReason,
219
+ outgoing_payment_failure_message: this.failureMessage
220
+ ? RichTextToJson(this.failureMessage)
221
+ : undefined,
222
+ outgoing_payment_uma_post_transaction_data:
223
+ this.umaPostTransactionData?.map((e) => PostTransactionDataToJson(e)),
224
+ outgoing_payment_payment_preimage: this.paymentPreimage,
225
+ };
226
+ }
169
227
  }
170
228
 
171
229
  export const OutgoingPaymentFromJson = (obj: any): OutgoingPayment => {
@@ -4,9 +4,15 @@ 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 ChannelSnapshot from "./ChannelSnapshot.js";
7
- import { ChannelSnapshotFromJson } from "./ChannelSnapshot.js";
7
+ import {
8
+ ChannelSnapshotFromJson,
9
+ ChannelSnapshotToJson,
10
+ } from "./ChannelSnapshot.js";
8
11
  import type CurrencyAmount from "./CurrencyAmount.js";
9
- import { CurrencyAmountFromJson } from "./CurrencyAmount.js";
12
+ import {
13
+ CurrencyAmountFromJson,
14
+ CurrencyAmountToJson,
15
+ } from "./CurrencyAmount.js";
10
16
  import type Entity from "./Entity.js";
11
17
  import HtlcAttemptFailureCode from "./HtlcAttemptFailureCode.js";
12
18
  import OutgoingPaymentAttemptStatus from "./OutgoingPaymentAttemptStatus.js";
@@ -16,18 +22,44 @@ import { OutgoingPaymentAttemptToHopsConnectionFromJson } from "./OutgoingPaymen
16
22
  /** This object represents an attempted Lightning Network payment sent from a Lightspark Node. You can retrieve this object to receive payment related information about any payment attempt sent from your Lightspark Node on the Lightning Network, including any potential reasons the payment may have failed. **/
17
23
  class OutgoingPaymentAttempt implements Entity {
18
24
  constructor(
25
+ /**
26
+ * The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque
27
+ * string.
28
+ **/
19
29
  public readonly id: string,
30
+ /** The date and time when the attempt was initiated. **/
20
31
  public readonly createdAt: string,
32
+ /** The date and time when the entity was last updated. **/
21
33
  public readonly updatedAt: string,
34
+ /** The status of an outgoing payment attempt. **/
22
35
  public readonly status: OutgoingPaymentAttemptStatus,
36
+ /** The outgoing payment for this attempt. **/
23
37
  public readonly outgoingPaymentId: string,
38
+ /** The typename of the object **/
24
39
  public readonly typename: string,
25
- public readonly failureCode?: HtlcAttemptFailureCode,
26
- public readonly failureSourceIndex?: number,
27
- public readonly resolvedAt?: string,
28
- public readonly amount?: CurrencyAmount,
29
- public readonly fees?: CurrencyAmount,
30
- public readonly channelSnapshot?: ChannelSnapshot,
40
+ /** If the payment attempt failed, then this contains the Bolt #4 failure code. **/
41
+ public readonly failureCode?: HtlcAttemptFailureCode | undefined,
42
+ /**
43
+ * If the payment attempt failed, then this contains the index of the hop at which the problem
44
+ * occurred.
45
+ **/
46
+ public readonly failureSourceIndex?: number | undefined,
47
+ /** The time the outgoing payment attempt failed or succeeded. **/
48
+ public readonly resolvedAt?: string | undefined,
49
+ /**
50
+ * The total amount of funds required to complete a payment over this route. This value includes the
51
+ * cumulative fees for each hop. As a result, the attempt extended to the first-hop in the route will
52
+ * need to have at least this much value, otherwise the route will fail at an intermediate node due to
53
+ * an insufficient amount.
54
+ **/
55
+ public readonly amount?: CurrencyAmount | undefined,
56
+ /**
57
+ * The sum of the fees paid at each hop within the route of this attempt. In the case of a one-hop
58
+ * payment, this value will be zero as we don't need to pay a fee to ourselves.
59
+ **/
60
+ public readonly fees?: CurrencyAmount | undefined,
61
+ /** The channel snapshot at the time the outgoing payment attempt was made. **/
62
+ public readonly channelSnapshot?: ChannelSnapshot | undefined,
31
63
  ) {
32
64
  autoBind(this);
33
65
  }
@@ -113,6 +145,29 @@ ${FRAGMENT}
113
145
  OutgoingPaymentAttemptFromJson(data.entity),
114
146
  };
115
147
  }
148
+
149
+ public toJson() {
150
+ return {
151
+ __typename: "OutgoingPaymentAttempt",
152
+ outgoing_payment_attempt_id: this.id,
153
+ outgoing_payment_attempt_created_at: this.createdAt,
154
+ outgoing_payment_attempt_updated_at: this.updatedAt,
155
+ outgoing_payment_attempt_status: this.status,
156
+ outgoing_payment_attempt_failure_code: this.failureCode,
157
+ outgoing_payment_attempt_failure_source_index: this.failureSourceIndex,
158
+ outgoing_payment_attempt_resolved_at: this.resolvedAt,
159
+ outgoing_payment_attempt_amount: this.amount
160
+ ? CurrencyAmountToJson(this.amount)
161
+ : undefined,
162
+ outgoing_payment_attempt_fees: this.fees
163
+ ? CurrencyAmountToJson(this.fees)
164
+ : undefined,
165
+ outgoing_payment_attempt_outgoing_payment: { id: this.outgoingPaymentId },
166
+ outgoing_payment_attempt_channel_snapshot: this.channelSnapshot
167
+ ? ChannelSnapshotToJson(this.channelSnapshot)
168
+ : undefined,
169
+ };
170
+ }
116
171
  }
117
172
 
118
173
  export const OutgoingPaymentAttemptFromJson = (
@@ -1,13 +1,12 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import type Connection from "./Connection.js";
4
3
  import type Hop from "./Hop.js";
5
- import { HopFromJson } from "./Hop.js";
4
+ import { HopFromJson, HopToJson } from "./Hop.js";
6
5
  import type PageInfo from "./PageInfo.js";
7
- import { PageInfoFromJson } from "./PageInfo.js";
6
+ import { PageInfoFromJson, PageInfoToJson } from "./PageInfo.js";
8
7
 
9
8
  /** The connection from an outgoing payment attempt to the list of sequential hops that define the path from sender node to recipient node. **/
10
- type OutgoingPaymentAttemptToHopsConnection = Connection & {
9
+ interface OutgoingPaymentAttemptToHopsConnection {
11
10
  /**
12
11
  * The total count of objects in this connection, using the current filters. It is different from the
13
12
  * number of objects returned in the current page (in the `entities` field).
@@ -22,7 +21,7 @@ type OutgoingPaymentAttemptToHopsConnection = Connection & {
22
21
 
23
22
  /** The typename of the object **/
24
23
  typename: string;
25
- };
24
+ }
26
25
 
27
26
  export const OutgoingPaymentAttemptToHopsConnectionFromJson = (
28
27
  obj: any,
@@ -38,6 +37,20 @@ export const OutgoingPaymentAttemptToHopsConnectionFromJson = (
38
37
  typename: "OutgoingPaymentAttemptToHopsConnection",
39
38
  } as OutgoingPaymentAttemptToHopsConnection;
40
39
  };
40
+ export const OutgoingPaymentAttemptToHopsConnectionToJson = (
41
+ obj: OutgoingPaymentAttemptToHopsConnection,
42
+ ): any => {
43
+ return {
44
+ __typename: "OutgoingPaymentAttemptToHopsConnection",
45
+ outgoing_payment_attempt_to_hops_connection_count: obj.count,
46
+ outgoing_payment_attempt_to_hops_connection_page_info: PageInfoToJson(
47
+ obj.pageInfo,
48
+ ),
49
+ outgoing_payment_attempt_to_hops_connection_entities: obj.entities.map(
50
+ (e) => HopToJson(e),
51
+ ),
52
+ };
53
+ };
41
54
 
42
55
  export const FRAGMENT = `
43
56
  fragment OutgoingPaymentAttemptToHopsConnectionFragment on OutgoingPaymentAttemptToHopsConnection {
@@ -1,13 +1,12 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import type Connection from "./Connection.js";
4
3
  import type OutgoingPaymentAttempt from "./OutgoingPaymentAttempt.js";
5
4
  import { OutgoingPaymentAttemptFromJson } from "./OutgoingPaymentAttempt.js";
6
5
  import type PageInfo from "./PageInfo.js";
7
- import { PageInfoFromJson } from "./PageInfo.js";
6
+ import { PageInfoFromJson, PageInfoToJson } from "./PageInfo.js";
8
7
 
9
8
  /** The connection from outgoing payment to all attempts. **/
10
- type OutgoingPaymentToAttemptsConnection = Connection & {
9
+ interface OutgoingPaymentToAttemptsConnection {
11
10
  /**
12
11
  * The total count of objects in this connection, using the current filters. It is different from the
13
12
  * number of objects returned in the current page (in the `entities` field).
@@ -22,7 +21,7 @@ type OutgoingPaymentToAttemptsConnection = Connection & {
22
21
 
23
22
  /** The typename of the object **/
24
23
  typename: string;
25
- };
24
+ }
26
25
 
27
26
  export const OutgoingPaymentToAttemptsConnectionFromJson = (
28
27
  obj: any,
@@ -38,6 +37,20 @@ export const OutgoingPaymentToAttemptsConnectionFromJson = (
38
37
  typename: "OutgoingPaymentToAttemptsConnection",
39
38
  } as OutgoingPaymentToAttemptsConnection;
40
39
  };
40
+ export const OutgoingPaymentToAttemptsConnectionToJson = (
41
+ obj: OutgoingPaymentToAttemptsConnection,
42
+ ): any => {
43
+ return {
44
+ __typename: "OutgoingPaymentToAttemptsConnection",
45
+ outgoing_payment_to_attempts_connection_count: obj.count,
46
+ outgoing_payment_to_attempts_connection_page_info: PageInfoToJson(
47
+ obj.pageInfo,
48
+ ),
49
+ outgoing_payment_to_attempts_connection_entities: obj.entities.map((e) =>
50
+ e.toJson(),
51
+ ),
52
+ };
53
+ };
41
54
 
42
55
  export const FRAGMENT = `
43
56
  fragment OutgoingPaymentToAttemptsConnectionFragment on OutgoingPaymentToAttemptsConnection {
@@ -2,13 +2,13 @@
2
2
 
3
3
  import TransactionStatus from "./TransactionStatus.js";
4
4
 
5
- type OutgoingPaymentsForInvoiceQueryInput = {
5
+ interface OutgoingPaymentsForInvoiceQueryInput {
6
6
  /** The encoded invoice that the outgoing payments paid to. **/
7
7
  encodedInvoice: string;
8
8
 
9
9
  /** An optional filter to only query outgoing payments of given statuses. **/
10
- statuses?: TransactionStatus[];
11
- };
10
+ statuses?: TransactionStatus[] | undefined;
11
+ }
12
12
 
13
13
  export const OutgoingPaymentsForInvoiceQueryInputFromJson = (
14
14
  obj: any,
@@ -21,5 +21,14 @@ export const OutgoingPaymentsForInvoiceQueryInputFromJson = (
21
21
  ),
22
22
  } as OutgoingPaymentsForInvoiceQueryInput;
23
23
  };
24
+ export const OutgoingPaymentsForInvoiceQueryInputToJson = (
25
+ obj: OutgoingPaymentsForInvoiceQueryInput,
26
+ ): any => {
27
+ return {
28
+ outgoing_payments_for_invoice_query_input_encoded_invoice:
29
+ obj.encodedInvoice,
30
+ outgoing_payments_for_invoice_query_input_statuses: obj.statuses,
31
+ };
32
+ };
24
33
 
25
34
  export default OutgoingPaymentsForInvoiceQueryInput;
@@ -3,9 +3,9 @@
3
3
  import type OutgoingPayment from "./OutgoingPayment.js";
4
4
  import { OutgoingPaymentFromJson } from "./OutgoingPayment.js";
5
5
 
6
- type OutgoingPaymentsForInvoiceQueryOutput = {
6
+ interface OutgoingPaymentsForInvoiceQueryOutput {
7
7
  payments: OutgoingPayment[];
8
- };
8
+ }
9
9
 
10
10
  export const OutgoingPaymentsForInvoiceQueryOutputFromJson = (
11
11
  obj: any,
@@ -16,6 +16,15 @@ export const OutgoingPaymentsForInvoiceQueryOutputFromJson = (
16
16
  ),
17
17
  } as OutgoingPaymentsForInvoiceQueryOutput;
18
18
  };
19
+ export const OutgoingPaymentsForInvoiceQueryOutputToJson = (
20
+ obj: OutgoingPaymentsForInvoiceQueryOutput,
21
+ ): any => {
22
+ return {
23
+ outgoing_payments_for_invoice_query_output_payments: obj.payments.map((e) =>
24
+ e.toJson(),
25
+ ),
26
+ };
27
+ };
19
28
 
20
29
  export const FRAGMENT = `
21
30
  fragment OutgoingPaymentsForInvoiceQueryOutputFragment on OutgoingPaymentsForInvoiceQueryOutput {