@lightsparkdev/lightspark-sdk 1.2.1 → 1.2.3

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 (132) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/{BitcoinNetwork-a816c0be.d.ts → BitcoinNetwork-37e9f091.d.ts} +8 -3
  3. package/dist/{chunk-VTPDR6P4.js → chunk-NCPWHRFO.js} +353 -15
  4. package/dist/env.d.cts +1 -1
  5. package/dist/env.d.ts +1 -1
  6. package/dist/{index-5acc6526.d.ts → index-449c9f58.d.ts} +2089 -644
  7. package/dist/index.cjs +1082 -470
  8. package/dist/index.d.cts +3 -3
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js +584 -302
  11. package/dist/objects/index.cjs +345 -5
  12. package/dist/objects/index.d.cts +2 -2
  13. package/dist/objects/index.d.ts +2 -2
  14. package/dist/objects/index.js +9 -1
  15. package/package.json +4 -4
  16. package/src/NodeKeyLoaderCache.ts +4 -3
  17. package/src/SigningKeyLoader.ts +12 -7
  18. package/src/client.ts +287 -60
  19. package/src/env.ts +3 -1
  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/objects/Account.ts +7 -3
  26. package/src/objects/AccountToApiTokensConnection.ts +7 -3
  27. package/src/objects/AccountToChannelsConnection.ts +3 -2
  28. package/src/objects/AccountToNodesConnection.ts +7 -3
  29. package/src/objects/AccountToPaymentRequestsConnection.ts +7 -3
  30. package/src/objects/AccountToTransactionsConnection.ts +13 -9
  31. package/src/objects/AccountToWalletsConnection.ts +7 -3
  32. package/src/objects/ApiToken.ts +13 -7
  33. package/src/objects/Balances.ts +22 -12
  34. package/src/objects/BitcoinNetwork.ts +8 -3
  35. package/src/objects/BlockchainBalance.ts +4 -1
  36. package/src/objects/Channel.ts +37 -14
  37. package/src/objects/ChannelClosingTransaction.ts +22 -11
  38. package/src/objects/ChannelFees.ts +4 -1
  39. package/src/objects/ChannelOpeningTransaction.ts +22 -11
  40. package/src/objects/ChannelStatus.ts +33 -8
  41. package/src/objects/ChannelToTransactionsConnection.ts +9 -8
  42. package/src/objects/ClaimUmaInvitationInput.ts +26 -0
  43. package/src/objects/ClaimUmaInvitationOutput.ts +30 -0
  44. package/src/objects/ClaimUmaInvitationWithIncentivesInput.ts +44 -0
  45. package/src/objects/ClaimUmaInvitationWithIncentivesOutput.ts +33 -0
  46. package/src/objects/ComplianceProvider.ts +3 -2
  47. package/src/objects/Connection.ts +7 -3
  48. package/src/objects/CreateApiTokenInput.ts +4 -1
  49. package/src/objects/CreateApiTokenOutput.ts +3 -3
  50. package/src/objects/CreateInvitationWithIncentivesInput.ts +37 -0
  51. package/src/objects/CreateInvitationWithIncentivesOutput.ts +32 -0
  52. package/src/objects/CreateLnurlInvoiceInput.ts +3 -2
  53. package/src/objects/CreateTestModePaymentInput.ts +2 -2
  54. package/src/objects/CreateTestModePaymentoutput.ts +5 -1
  55. package/src/objects/CreateUmaInvitationInput.ts +22 -0
  56. package/src/objects/CreateUmaInvitationOutput.ts +30 -0
  57. package/src/objects/CurrencyAmount.ts +6 -4
  58. package/src/objects/CurrencyUnit.ts +36 -9
  59. package/src/objects/Deposit.ts +22 -11
  60. package/src/objects/Entity.ts +21 -3
  61. package/src/objects/FeeEstimate.ts +5 -1
  62. package/src/objects/GraphNode.ts +30 -14
  63. package/src/objects/Hop.ts +12 -4
  64. package/src/objects/HtlcAttemptFailureCode.ts +7 -3
  65. package/src/objects/IncentivesIneligibilityReason.ts +48 -0
  66. package/src/objects/IncentivesStatus.ts +28 -0
  67. package/src/objects/IncomingPayment.ts +18 -7
  68. package/src/objects/IncomingPaymentAttempt.ts +8 -3
  69. package/src/objects/IncomingPaymentAttemptStatus.ts +7 -3
  70. package/src/objects/IncomingPaymentToAttemptsConnection.ts +7 -3
  71. package/src/objects/Invoice.ts +2 -2
  72. package/src/objects/InvoiceData.ts +7 -3
  73. package/src/objects/InvoiceType.ts +3 -2
  74. package/src/objects/LightningFeeEstimateForInvoiceInput.ts +2 -2
  75. package/src/objects/LightningTransaction.ts +12 -4
  76. package/src/objects/LightsparkNode.ts +33 -18
  77. package/src/objects/LightsparkNodeOwner.ts +2 -2
  78. package/src/objects/LightsparkNodeStatus.ts +3 -2
  79. package/src/objects/LightsparkNodeToChannelsConnection.ts +7 -3
  80. package/src/objects/LightsparkNodeWithOSK.ts +35 -19
  81. package/src/objects/LightsparkNodeWithRemoteSigning.ts +31 -18
  82. package/src/objects/Node.ts +28 -14
  83. package/src/objects/NodeAddressType.ts +7 -3
  84. package/src/objects/NodeToAddressesConnection.ts +7 -3
  85. package/src/objects/OnChainTransaction.ts +23 -11
  86. package/src/objects/OutgoingPayment.ts +25 -7
  87. package/src/objects/OutgoingPaymentAttempt.ts +34 -14
  88. package/src/objects/OutgoingPaymentAttemptStatus.ts +7 -3
  89. package/src/objects/OutgoingPaymentAttemptToHopsConnection.ts +12 -4
  90. package/src/objects/OutgoingPaymentToAttemptsConnection.ts +7 -3
  91. package/src/objects/PageInfo.ts +6 -1
  92. package/src/objects/PayInvoiceInput.ts +6 -3
  93. package/src/objects/PaymentDirection.ts +3 -2
  94. package/src/objects/PaymentFailureReason.ts +7 -3
  95. package/src/objects/PaymentRequest.ts +8 -3
  96. package/src/objects/PaymentRequestData.ts +5 -1
  97. package/src/objects/PaymentRequestStatus.ts +7 -3
  98. package/src/objects/Permission.ts +7 -3
  99. package/src/objects/PostTransactionData.ts +6 -3
  100. package/src/objects/RegionCode.ts +541 -0
  101. package/src/objects/RegisterPaymentInput.ts +12 -7
  102. package/src/objects/RemoteSigningSubEventType.ts +7 -3
  103. package/src/objects/RequestWithdrawalInput.ts +2 -2
  104. package/src/objects/RiskRating.ts +8 -3
  105. package/src/objects/RoutingTransaction.ts +20 -7
  106. package/src/objects/RoutingTransactionFailureReason.ts +8 -3
  107. package/src/objects/ScreenNodeInput.ts +3 -2
  108. package/src/objects/SendPaymentInput.ts +4 -1
  109. package/src/objects/SetInvoicePaymentHashInput.ts +3 -2
  110. package/src/objects/Signable.ts +2 -2
  111. package/src/objects/SignablePayload.ts +6 -3
  112. package/src/objects/SignablePayloadStatus.ts +3 -2
  113. package/src/objects/Transaction.ts +14 -4
  114. package/src/objects/TransactionFailures.ts +4 -1
  115. package/src/objects/TransactionStatus.ts +16 -5
  116. package/src/objects/TransactionType.ts +30 -8
  117. package/src/objects/TransactionUpdate.ts +6 -3
  118. package/src/objects/UmaInvitation.ts +119 -0
  119. package/src/objects/Wallet.ts +13 -4
  120. package/src/objects/WalletStatus.ts +36 -9
  121. package/src/objects/WalletToPaymentRequestsConnection.ts +7 -3
  122. package/src/objects/WalletToTransactionsConnection.ts +7 -3
  123. package/src/objects/WebhookEventType.ts +11 -3
  124. package/src/objects/Withdrawal.ts +22 -11
  125. package/src/objects/WithdrawalMode.ts +7 -3
  126. package/src/objects/WithdrawalRequest.ts +15 -6
  127. package/src/objects/WithdrawalRequestStatus.ts +3 -2
  128. package/src/objects/WithdrawalRequestToChannelClosingTransactionsConnection.ts +11 -4
  129. package/src/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.ts +11 -4
  130. package/src/objects/index.ts +21 -6
  131. package/src/tests/integration/constants.ts +0 -3
  132. package/src/tests/integration/general-regtest.test.ts +178 -197
@@ -1,8 +1,8 @@
1
1
  import {
2
- b64encode,
3
- isBrowser,
4
2
  LightsparkSigningException,
5
3
  SigningKeyType,
4
+ b64encode,
5
+ isBrowser,
6
6
  type CryptoInterface,
7
7
  type Maybe,
8
8
  type Requester,
@@ -21,15 +21,18 @@ export type SigningKeyLoaderArgs =
21
21
 
22
22
  /**
23
23
  * Args for creating a new SigningKeyLoader from a node ID and password.
24
- * This cannot be used if you are using remote signing. It is used to recover an RSA operation signing key using
25
- * the password you chose when setting up your node. For REGTEST nodes, the password is "1234!@#$".
24
+ * This cannot be used if you are using remote signing.
25
+ * It is used to recover an RSA operation signing key using the password you
26
+ * chose when setting up your node. For REGTEST nodes, the password is
27
+ * "1234!@#$".
26
28
  */
27
29
  export interface NodeIdAndPasswordSigningKeyLoaderArgs {
28
30
  password: string;
29
31
  }
30
32
 
31
33
  /**
32
- * Internal version of NodeIdAndPasswordSigningKeyLoaderArgs that includes the node ID.
34
+ * Internal version of NodeIdAndPasswordSigningKeyLoaderArgs that includes the
35
+ * node ID.
33
36
  */
34
37
  interface NodeIdAndPasswordSigningKeyLoaderArgsInternal
35
38
  extends NodeIdAndPasswordSigningKeyLoaderArgs {
@@ -38,7 +41,8 @@ interface NodeIdAndPasswordSigningKeyLoaderArgsInternal
38
41
 
39
42
  /**
40
43
  * Args for creating a new SigningKeyLoader from a master seed and network.
41
- * This should be used if you are using remote signing, rather than an RSA operation signing key.
44
+ * This should be used if you are using remote signing,
45
+ * rather than an RSA operation signing key.
42
46
  */
43
47
  export interface MasterSeedSigningKeyLoaderArgs {
44
48
  masterSeed: Uint8Array;
@@ -70,7 +74,8 @@ export function isMasterSeedSigningKeyLoaderArgs(
70
74
  }
71
75
 
72
76
  /**
73
- * Key loader that loads an RSA signing key by providing a node ID and password to recover the key from Lightspark.
77
+ * Key loader that loads an RSA signing key by providing a node ID and password
78
+ * to recover the key from Lightspark.
74
79
  */
75
80
  export class NodeIdAndPasswordSigningKeyLoader implements SigningKeyLoader {
76
81
  private readonly nodeId: string;
package/src/client.ts CHANGED
@@ -12,43 +12,49 @@ import type {
12
12
  SigningKey,
13
13
  } from "@lightsparkdev/core";
14
14
  import {
15
- createSha256Hash,
16
15
  DefaultCrypto,
17
16
  LightsparkAuthException,
18
17
  LightsparkException,
19
18
  LightsparkSigningException,
20
19
  NodeKeyCache,
21
- pollUntil,
22
20
  Requester,
23
21
  SigningKeyType,
24
22
  StubAuthProvider,
23
+ createSha256Hash,
24
+ pollUntil,
25
25
  } from "@lightsparkdev/core";
26
26
  import packageJson from "../package.json";
27
+ import NodeKeyLoaderCache from "./NodeKeyLoaderCache.js";
28
+ import { type SigningKeyLoaderArgs } from "./SigningKeyLoader.js";
27
29
  import { BitcoinFeeEstimate as BitcoinFeeEstimateQuery } from "./graphql/BitcoinFeeEstimate.js";
30
+ import { ClaimUmaInvitation } from "./graphql/ClaimUmaInvitation.js";
31
+ import { ClaimUmaInvitationWithIncentives } from "./graphql/ClaimUmaInvitationWithIncentives.js";
28
32
  import { CreateApiToken } from "./graphql/CreateApiToken.js";
29
33
  import { CreateInvoice } from "./graphql/CreateInvoice.js";
30
34
  import { CreateLnurlInvoice } from "./graphql/CreateLnurlInvoice.js";
31
35
  import { CreateNodeWalletAddress } from "./graphql/CreateNodeWalletAddress.js";
32
36
  import { CreateTestModeInvoice } from "./graphql/CreateTestModeInvoice.js";
33
37
  import { CreateTestModePayment } from "./graphql/CreateTestModePayment.js";
38
+ import { CreateUmaInvitation } from "./graphql/CreateUmaInvitation.js";
39
+ import { CreateUmaInvitationWithIncentives } from "./graphql/CreateUmaInvitationWithIncentives.js";
34
40
  import { CreateUmaInvoice } from "./graphql/CreateUmaInvoice.js";
35
41
  import { DecodeInvoice } from "./graphql/DecodeInvoice.js";
36
42
  import { DeleteApiToken } from "./graphql/DeleteApiToken.js";
43
+ import { FetchUmaInvitation } from "./graphql/FetchUmaInvitation.js";
37
44
  import { FundNode } from "./graphql/FundNode.js";
38
45
  import { LightningFeeEstimateForInvoice } from "./graphql/LightningFeeEstimateForInvoice.js";
39
46
  import { LightningFeeEstimateForNode } from "./graphql/LightningFeeEstimateForNode.js";
40
47
  import type { AccountDashboard } from "./graphql/MultiNodeDashboard.js";
41
48
  import { MultiNodeDashboard } from "./graphql/MultiNodeDashboard.js";
42
49
  import { PayInvoice } from "./graphql/PayInvoice.js";
43
- import { PaymentRequestsForNode } from "./graphql/PaymentRequestsForNode.js";
44
50
  import { PayUmaInvoice } from "./graphql/PayUmaInvoice.js";
51
+ import { PaymentRequestsForNode } from "./graphql/PaymentRequestsForNode.js";
45
52
  import { RequestWithdrawal } from "./graphql/RequestWithdrawal.js";
46
53
  import { SendPayment } from "./graphql/SendPayment.js";
47
54
  import { SingleNodeDashboard as SingleNodeDashboardQuery } from "./graphql/SingleNodeDashboard.js";
48
- import { TransactionsForNode } from "./graphql/TransactionsForNode.js";
49
55
  import { TransactionSubscription } from "./graphql/TransactionSubscription.js";
56
+ import { TransactionsForNode } from "./graphql/TransactionsForNode.js";
50
57
  import { TransactionStatus } from "./index.js";
51
- import NodeKeyLoaderCache from "./NodeKeyLoaderCache.js";
52
58
  import Account from "./objects/Account.js";
53
59
  import { ApiTokenFromJson } from "./objects/ApiToken.js";
54
60
  import BitcoinNetwork from "./objects/BitcoinNetwork.js";
@@ -68,23 +74,26 @@ import type OutgoingPayment from "./objects/OutgoingPayment.js";
68
74
  import { OutgoingPaymentFromJson } from "./objects/OutgoingPayment.js";
69
75
  import { PaymentRequestFromJson } from "./objects/PaymentRequest.js";
70
76
  import Permission from "./objects/Permission.js";
77
+ import type RegionCode from "./objects/RegionCode.js";
71
78
  import type SingleNodeDashboard from "./objects/SingleNodeDashboard.js";
72
79
  import type Transaction from "./objects/Transaction.js";
73
80
  import {
74
- getTransactionQuery,
75
81
  TransactionFromJson,
82
+ getTransactionQuery,
76
83
  } from "./objects/Transaction.js";
77
84
  import type TransactionUpdate from "./objects/TransactionUpdate.js";
78
85
  import { TransactionUpdateFromJson } from "./objects/TransactionUpdate.js";
86
+ import type UmaInvitation from "./objects/UmaInvitation.js";
87
+ import { UmaInvitationFromJson } from "./objects/UmaInvitation.js";
79
88
  import type WithdrawalMode from "./objects/WithdrawalMode.js";
80
89
  import type WithdrawalRequest from "./objects/WithdrawalRequest.js";
81
90
  import { WithdrawalRequestFromJson } from "./objects/WithdrawalRequest.js";
82
- import { type SigningKeyLoaderArgs } from "./SigningKeyLoader.js";
83
91
 
84
92
  const sdkVersion = packageJson.version;
85
93
 
86
94
  /**
87
- * The LightsparkClient is the main entrypoint for interacting with the Lightspark API.
95
+ * The LightsparkClient is the main entrypoint for interacting with the
96
+ * Lightspark API.
88
97
  *
89
98
  * ```ts
90
99
  * const lightsparkClient = new LightsparkClient(
@@ -121,7 +130,8 @@ class LightsparkClient {
121
130
  * use, you should use the `AccountTokenAuthProvider`.
122
131
  * @param serverUrl The base URL of the server to connect to. Defaults to lightspark production.
123
132
  * @param cryptoImpl The crypto implementation to use. Defaults to web and node compatible crypto.
124
- * For React Native, you should use the `ReactNativeCrypto` implementation from `@lightsparkdev/react-native`.
133
+ * For React Native, you should use the `ReactNativeCrypto`
134
+ * implementation from `@lightsparkdev/react-native`.
125
135
  */
126
136
  constructor(
127
137
  private authProvider: AuthProvider = new StubAuthProvider(),
@@ -146,9 +156,11 @@ class LightsparkClient {
146
156
  }
147
157
 
148
158
  /**
149
- * Sets the key loader for a node. This unlocks client operations that require a private key.
150
- * Passing in [NodeIdAndPasswordSigningKeyLoaderArgs] loads the RSA key for an OSK node.
151
- * Passing in [MasterSeedSigningKeyLoaderArgs] loads the Secp256k1 key for a remote signing node.
159
+ * Sets the key loader for a node. This unlocks client operations that
160
+ * require a private key. Passing in [NodeIdAndPasswordSigningKeyLoaderArgs]
161
+ * loads the RSA key for an OSK node.
162
+ * Passing in [MasterSeedSigningKeyLoaderArgs] loads the Secp256k1 key for a
163
+ * remote signing node.
152
164
  *
153
165
  * @param nodeId The ID of the node the key is for
154
166
  * @param loader The loader for the key
@@ -163,7 +175,8 @@ class LightsparkClient {
163
175
  }
164
176
 
165
177
  /**
166
- * Gets the signing key for a node. Must have previously called [loadNodeSigningKey].
178
+ * Gets the signing key for a node. Must have previously called
179
+ * [loadNodeSigningKey].
167
180
  *
168
181
  * @param nodeId The ID of the node the key is for
169
182
  * @returns The signing key for the node
@@ -175,7 +188,8 @@ class LightsparkClient {
175
188
  }
176
189
 
177
190
  /**
178
- * Sets the auth provider for the client. This is useful for switching between auth providers if you are using
191
+ * Sets the auth provider for the client.
192
+ * This is useful for switching between auth providers if you are using
179
193
  * multiple accounts or waiting for the user to log in.
180
194
  *
181
195
  * @param authProvider
@@ -274,7 +288,8 @@ class LightsparkClient {
274
288
  }
275
289
 
276
290
  /**
277
- * Starts listening for new transactions or updates to existing transactions for a list of nodes.
291
+ * Starts listening for new transactions or updates to existing transactions
292
+ * for a list of nodes.
278
293
  *
279
294
  * @param nodeIds The node IDs for which to listen to transactions.
280
295
  * @returns A zen-observable that emits transaction updates for the given node IDs.
@@ -297,8 +312,8 @@ class LightsparkClient {
297
312
  }
298
313
 
299
314
  /**
300
- * Retrieves a dashboard of basic info for the authenticated account. See `AccountDashboard` for which info is
301
- * included.
315
+ * Retrieves a dashboard of basic info for the authenticated account.
316
+ * See `AccountDashboard` for which info is included.
302
317
  *
303
318
  * @param nodeIds The node IDs to include in the dashboard. Defaults to undefined (all nodes).
304
319
  * @param bitcoinNetwork The bitcoin network to include in the dashboard. Defaults to MAINNET.
@@ -389,8 +404,8 @@ class LightsparkClient {
389
404
  }
390
405
 
391
406
  /**
392
- * Gets a basic dashboard for a single node, including recent transactions. See `SingleNodeDashboard` for which info is
393
- * included.
407
+ * Gets a basic dashboard for a single node, including recent transactions.
408
+ * See `SingleNodeDashboard` for which info is included.
394
409
  *
395
410
  * @param nodeId The node ID for which to get a dashboard.
396
411
  * @param bitcoinNetwork The bitcoin network for which to get a dashboard. Defaults to MAINNET.
@@ -471,7 +486,8 @@ class LightsparkClient {
471
486
  /**
472
487
  * Creates an invoice for the given node.
473
488
  *
474
- * Test mode note: You can simulate a payment of this invoice in test move using [createTestModePayment].
489
+ * Test mode note: You can simulate a payment of this invoice in test move
490
+ * using [createTestModePayment].
475
491
  *
476
492
  * @param nodeId The node ID for which to create an invoice.
477
493
  * @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
@@ -506,11 +522,13 @@ class LightsparkClient {
506
522
  }
507
523
 
508
524
  /**
509
- * Generates a Lightning Invoice (follows the Bolt 11 specification) to request a payment
510
- * from another Lightning Node. This should only be used for generating invoices for LNURLs,
525
+ * Generates a Lightning Invoice (follows the Bolt 11 specification) to
526
+ * request a payment from another Lightning Node.
527
+ * This should only be used for generating invoices for LNURLs,
511
528
  * with [createInvoice] preferred in the general case.
512
529
  *
513
- * Test mode note: You can simulate a payment of this invoice in test move using [createTestModePayment].
530
+ * Test mode note: You can simulate a payment of this invoice in test move
531
+ * using [createTestModePayment].
514
532
  *
515
533
  * @param nodeId The node ID for which to create an invoice.
516
534
  * @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
@@ -547,10 +565,12 @@ class LightsparkClient {
547
565
  }
548
566
 
549
567
  /**
550
- * Creates a new invoice for the UMA protocol. The metadata is hashed and included in the invoice.
551
- * This API generates a Lightning Invoice (follows the Bolt 11 specification) to request a payment
552
- * from another Lightning Node. This should only be used for generating invoices for UMA, with `createInvoice`
553
- * preferred in the general case.
568
+ * Creates a new invoice for the UMA protocol.
569
+ * The metadata is hashed and included in the invoice.
570
+ * This API generates a Lightning Invoice (follows the Bolt 11 specification)
571
+ * to request a payment from another Lightning Node.
572
+ * This should only be used for generating invoices for UMA,
573
+ * with `createInvoice` preferred in the general case.
554
574
  *
555
575
  * @param nodeId The node ID for which to create an invoice.
556
576
  * @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
@@ -598,7 +618,8 @@ class LightsparkClient {
598
618
  }
599
619
 
600
620
  /**
601
- * Gets an estimate of the fee for sending a payment over the given bitcoin network.
621
+ * Gets an estimate of the fee for sending a payment over the given bitcoin
622
+ * network.
602
623
  *
603
624
  * @param bitcoinNetwork The bitcoin network for which to get a fee estimate. Defaults to MAINNET.
604
625
  * @returns A fee estimate for the given bitcoin network including a minimum fee rate, and a max-speed fee rate.
@@ -644,7 +665,8 @@ class LightsparkClient {
644
665
  }
645
666
 
646
667
  /**
647
- * Returns an estimate of the fees that will be paid to send a payment to another Lightning node.
668
+ * Returns an estimate of the fees that will be paid to send a payment to
669
+ * another Lightning node.
648
670
  *
649
671
  * @param nodeId The node from where you want to send the payment.
650
672
  * @param destinationNodePublicKey The public key of the node that you want to pay.
@@ -690,17 +712,20 @@ class LightsparkClient {
690
712
  /**
691
713
  * Sends a lightning payment for a given invoice.
692
714
  *
693
- * Test mode note: For test mode, you can use the [createTestModeInvoice] function to create an invoice you can
694
- * pay in test mode.
715
+ * Test mode note: For test mode, you can use the [createTestModeInvoice]
716
+ * function to create an invoice you can pay in test mode.
695
717
  *
696
718
  * @param payerNodeId The ID of the node that will pay the invoice.
697
719
  * @param encodedInvoice The encoded invoice to pay.
698
720
  * @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
699
- * As guidance, a maximum fee of 16 basis points should make almost all transactions succeed. For example,
700
- * for a transaction between 10k sats and 100k sats, this would mean a fee limit of 16 to 160 sats.
721
+ * As guidance, a maximum fee of 16 basis points should make almost all
722
+ * transactions succeed. For example,
723
+ * for a transaction between 10k sats and 100k sats,
724
+ * this would mean a fee limit of 16 to 160 sats.
701
725
  * @param timeoutSecs A timeout for the payment in seconds. Defaults to 60 seconds.
702
726
  * @param amountMsats The amount to pay in msats for a zero-amount invoice. Defaults to the full amount of the
703
- * invoice. NOTE: This parameter can only be passed for a zero-amount invoice. Otherwise, the call will fail.
727
+ * invoice. NOTE: This parameter can only be passed for a zero-amount
728
+ * invoice. Otherwise, the call will fail.
704
729
  * @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
705
730
  */
706
731
  public async payInvoice(
@@ -741,18 +766,23 @@ class LightsparkClient {
741
766
  }
742
767
 
743
768
  /**
744
- * sends an UMA payment to a node on the Lightning Network, based on the invoice
745
- * (as defined by the BOLT11 specification) that you provide.
746
- * This should only be used for paying UMA invoices, with `payInvoice` preferred in the general case.
769
+ * sends an UMA payment to a node on the Lightning Network,
770
+ * based on the invoice (as defined by the BOLT11 specification) that you
771
+ * provide.
772
+ * This should only be used for paying UMA invoices,
773
+ * with `payInvoice` preferred in the general case.
747
774
  *
748
775
  * @param payerNodeId The ID of the node that will pay the invoice.
749
776
  * @param encodedInvoice The encoded invoice to pay.
750
777
  * @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
751
- * As guidance, a maximum fee of 16 basis points should make almost all transactions succeed. For example,
752
- * for a transaction between 10k sats and 100k sats, this would mean a fee limit of 16 to 160 sats.
778
+ * As guidance, a maximum fee of 16 basis points should make almost all
779
+ * transactions succeed. For example,
780
+ * for a transaction between 10k sats and 100k sats,
781
+ * this would mean a fee limit of 16 to 160 sats.
753
782
  * @param timeoutSecs A timeout for the payment in seconds. Defaults to 60 seconds.
754
783
  * @param amountMsats The amount to pay in msats for a zero-amount invoice. Defaults to the full amount of the
755
- * invoice. NOTE: This parameter can only be passed for a zero-amount invoice. Otherwise, the call will fail.
784
+ * invoice. NOTE: This parameter can only be passed for a zero-amount
785
+ * invoice. Otherwise, the call will fail.
756
786
  * @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
757
787
  */
758
788
  public async payUmaInvoice(
@@ -793,7 +823,8 @@ class LightsparkClient {
793
823
  }
794
824
 
795
825
  /**
796
- * Waits for a transaction to have a completed status, and returns the transaction.
826
+ * Waits for a transaction to have a completed status, and returns the
827
+ * transaction.
797
828
  *
798
829
  * @param transactionId The ID of the transaction to wait for
799
830
  * @param pollTimeoutSecs The timeout in seconds that we will wait before throwing an exception
@@ -840,15 +871,18 @@ class LightsparkClient {
840
871
  }
841
872
 
842
873
  /**
843
- * Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.
874
+ * Sends a payment directly to a node on the Lightning Network through the
875
+ * public key of the node without an invoice.
844
876
  *
845
877
  * @param payerNodeId The ID of the node that will send the payment.
846
878
  * @param destinationPublicKey The public key of the destination node.
847
879
  * @param timeoutSecs The timeout in seconds that we will try to make the payment.
848
880
  * @param amountMsats The amount to pay in msats.
849
881
  * @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
850
- * As guidance, a maximum fee of 15 basis points should make almost all transactions succeed. For example,
851
- * for a transaction between 10k sats and 100k sats, this would mean a fee limit of 15 to 150 sats.
882
+ * As guidance, a maximum fee of 15 basis points should make almost all
883
+ * transactions succeed. For example,
884
+ * for a transaction between 10k sats and 100k sats,
885
+ * this would mean a fee limit of 15 to 150 sats.
852
886
  * @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
853
887
  */
854
888
  public async sendPayment(
@@ -886,7 +920,8 @@ class LightsparkClient {
886
920
  }
887
921
 
888
922
  /**
889
- * Creates an L1 Bitcoin wallet address for a given node which can be used to deposit or withdraw funds.
923
+ * Creates an L1 Bitcoin wallet address for a given node which can be used to
924
+ * deposit or withdraw funds.
890
925
  *
891
926
  * @param nodeId The ID of the node to create a wallet address for.
892
927
  * @returns A string containing the wallet address for the given node.
@@ -900,12 +935,15 @@ class LightsparkClient {
900
935
  }
901
936
 
902
937
  /**
903
- * Withdraws funds from the account and sends it to the requested bitcoin address.
938
+ * Withdraws funds from the account and sends it to the requested bitcoin
939
+ * address.
904
940
  *
905
- * Depending on the chosen mode, it will first take the funds from the wallet, and if applicable, close channels
906
- * appropriately to recover enough funds and reopen channels with the remaining funds.
907
- * The process is asynchronous and may take up to a few minutes. You can check the progress by polling the
908
- * `WithdrawalRequest` that is created, or by subscribing to a webhook.
941
+ * Depending on the chosen mode, it will first take the funds from the
942
+ * wallet, and if applicable, close channels appropriately to recover enough
943
+ * funds and reopen channels with the remaining funds.
944
+ * The process is asynchronous and may take up to a few minutes.
945
+ * You can check the progress by polling the `WithdrawalRequest` that is
946
+ * created, or by subscribing to a webhook.
909
947
  *
910
948
  * @param nodeId The ID of the node from which to withdraw funds.
911
949
  * @param amountSats The amount of funds to withdraw in satoshis.
@@ -932,9 +970,10 @@ class LightsparkClient {
932
970
  }
933
971
 
934
972
  /**
935
- * Adds funds to a Lightspark node on the REGTEST network. If the amount is not specified, 10,000,000 SATOSHI will be
936
- * added. This API only functions for nodes created on the REGTEST network and will return an error when called for
937
- * any non-REGTEST node.
973
+ * Adds funds to a Lightspark node on the REGTEST network.
974
+ * If the amount is not specified, 10,000,000 SATOSHI will be added.
975
+ * This API only functions for nodes created on the REGTEST network and will
976
+ * return an error when called for any non-REGTEST node.
938
977
  *
939
978
  * @param nodeId The ID of the node to fund. Must be a REGTEST node.
940
979
  * @param amountSats The amount of funds to add to the node in satoshis. Defaults to 10,000,000 SATOSHI.
@@ -952,8 +991,8 @@ class LightsparkClient {
952
991
  }
953
992
 
954
993
  /**
955
- * Creates a new API token that can be used to authenticate requests for this account when using the Lightspark APIs
956
- * and SDKs.
994
+ * Creates a new API token that can be used to authenticate requests for this
995
+ * account when using the Lightspark APIs and SDKs.
957
996
  *
958
997
  * @param name Creates a new API token that can be used to authenticate requests for this account when using the
959
998
  * Lightspark APIs and SDKs.
@@ -997,8 +1036,9 @@ class LightsparkClient {
997
1036
  }
998
1037
 
999
1038
  /**
1000
- * In test mode, generates a Lightning Invoice which can be paid by a local node.
1001
- * This call is only valid in test mode. You can then pay the invoice using [payInvoice].
1039
+ * In test mode, generates a Lightning Invoice which can be paid by a local
1040
+ * node. This call is only valid in test mode.
1041
+ * You can then pay the invoice using [payInvoice].
1002
1042
  *
1003
1043
  * @param localNodeId The ID of the node that will pay the invoice.
1004
1044
  * @param amountMsats The amount to pay in milli-satoshis.
@@ -1038,8 +1078,9 @@ class LightsparkClient {
1038
1078
  }
1039
1079
 
1040
1080
  /**
1041
- * In test mode, simulates a payment of a Lightning Invoice from another node.
1042
- * This can only be used in test mode and should be used with invoices generated by [createInvoice].
1081
+ * In test mode, simulates a payment of a Lightning Invoice from another
1082
+ * node. This can only be used in test mode and should be used with invoices
1083
+ * generated by [createInvoice].
1043
1084
  *
1044
1085
  * @param localNodeId The ID of the node that will receive the payment.
1045
1086
  * @param encodedInvoice The encoded invoice to pay.
@@ -1070,10 +1111,196 @@ class LightsparkClient {
1070
1111
  });
1071
1112
  }
1072
1113
 
1114
+ /**
1115
+ * Creates an UMA invitation. If you are part of the incentive program,
1116
+ * you should use [createUmaInvitationWithIncentives].
1117
+ *
1118
+ * @param inviterUma The UMA of the inviter.
1119
+ * @returns The invitation that was created.
1120
+ */
1121
+ public async createUmaInvitation(
1122
+ inviterUma: string,
1123
+ ): Promise<UmaInvitation | null> {
1124
+ return await this.executeRawQuery({
1125
+ queryPayload: CreateUmaInvitation,
1126
+ variables: {
1127
+ inviterUma,
1128
+ },
1129
+ constructObject: (responseJson: {
1130
+ create_uma_invitation: {
1131
+ invitation: any; // eslint-disable-line @typescript-eslint/no-explicit-any
1132
+ } | null;
1133
+ }) => {
1134
+ if (!responseJson.create_uma_invitation?.invitation) {
1135
+ throw new LightsparkException(
1136
+ "CreateUmaInvitationError",
1137
+ "Unable to create UMA invitation",
1138
+ );
1139
+ }
1140
+ return UmaInvitationFromJson(
1141
+ responseJson.create_uma_invitation?.invitation,
1142
+ );
1143
+ },
1144
+ });
1145
+ }
1146
+
1147
+ /**
1148
+ * Creates an UMA invitation as part of the incentive program.
1149
+ * @param inviterUma The UMA of the inviter.
1150
+ * @param inviterPhoneNumber The phone number of the inviter in E164 format.
1151
+ * @param inviterRegion The region of the inviter.
1152
+ * @returns The invitation that was created.
1153
+ */
1154
+ public async createUmaInvitationWithIncentives(
1155
+ inviterUma: string,
1156
+ inviterPhoneNumber: string,
1157
+ inviterRegion: RegionCode,
1158
+ ): Promise<UmaInvitation | null> {
1159
+ const inviterPhoneHash = await this.hashPhoneNumber(inviterPhoneNumber);
1160
+ return await this.executeRawQuery({
1161
+ queryPayload: CreateUmaInvitationWithIncentives,
1162
+ variables: {
1163
+ inviterUma,
1164
+ inviterPhoneHash,
1165
+ inviterRegion,
1166
+ },
1167
+ constructObject: (responseJson: {
1168
+ create_uma_invitation_with_incentives: {
1169
+ invitation: any; // eslint-disable-line @typescript-eslint/no-explicit-any
1170
+ } | null;
1171
+ }) => {
1172
+ if (!responseJson.create_uma_invitation_with_incentives?.invitation) {
1173
+ throw new LightsparkException(
1174
+ "CreateUmaInvitationError",
1175
+ "Unable to create UMA invitation",
1176
+ );
1177
+ }
1178
+ return UmaInvitationFromJson(
1179
+ responseJson.create_uma_invitation_with_incentives?.invitation,
1180
+ );
1181
+ },
1182
+ });
1183
+ }
1184
+
1185
+ /**
1186
+ * Claims an UMA invitation. If you are part of the incentive program,
1187
+ * you should use [claimUmaInvitationWithIncentives].
1188
+ *
1189
+ * @param invitationCode The invitation code to claim.
1190
+ * @param inviteeUma The UMA of the invitee.
1191
+ * @returns The invitation that was claimed.
1192
+ */
1193
+ public async claimUmaInvitation(
1194
+ invitationCode: string,
1195
+ inviteeUma: string,
1196
+ ): Promise<UmaInvitation | null> {
1197
+ return await this.executeRawQuery({
1198
+ queryPayload: ClaimUmaInvitation,
1199
+ variables: {
1200
+ invitationCode,
1201
+ inviteeUma,
1202
+ },
1203
+ constructObject: (responseJson: {
1204
+ claim_uma_invitation: {
1205
+ invitation: any; // eslint-disable-line @typescript-eslint/no-explicit-any
1206
+ } | null;
1207
+ }) => {
1208
+ if (!responseJson.claim_uma_invitation?.invitation) {
1209
+ throw new LightsparkException(
1210
+ "ClaimUmaInvitationError",
1211
+ "Unable to claim UMA invitation",
1212
+ );
1213
+ }
1214
+ return UmaInvitationFromJson(
1215
+ responseJson.claim_uma_invitation?.invitation,
1216
+ );
1217
+ },
1218
+ });
1219
+ }
1220
+
1221
+ /**
1222
+ * Claims an UMA invitation as part of the incentive program.
1223
+ *
1224
+ * @param invitationCode The invitation code to claim.
1225
+ * @param inviteeUma The UMA of the invitee.
1226
+ * @param inviteePhoneNumber The phone number of the invitee in E164 format.
1227
+ * @param inviteeRegion The region of the invitee.
1228
+ * @returns The invitation that was claimed.
1229
+ */
1230
+ public async claimUmaInvitationWithIncentives(
1231
+ invitationCode: string,
1232
+ inviteeUma: string,
1233
+ inviteePhoneNumber: string,
1234
+ inviteeRegion: RegionCode,
1235
+ ): Promise<UmaInvitation | null> {
1236
+ const inviteePhoneHash = await this.hashPhoneNumber(inviteePhoneNumber);
1237
+ return await this.executeRawQuery({
1238
+ queryPayload: ClaimUmaInvitationWithIncentives,
1239
+ variables: {
1240
+ invitationCode,
1241
+ inviteeUma,
1242
+ inviteePhoneHash,
1243
+ inviteeRegion,
1244
+ },
1245
+ constructObject: (responseJson: {
1246
+ claim_uma_invitation_with_incentives: {
1247
+ invitation: any; // eslint-disable-line @typescript-eslint/no-explicit-any
1248
+ } | null;
1249
+ }) => {
1250
+ if (!responseJson.claim_uma_invitation_with_incentives?.invitation) {
1251
+ throw new LightsparkException(
1252
+ "ClaimUmaInvitationError",
1253
+ "Unable to claim UMA invitation",
1254
+ );
1255
+ }
1256
+ return UmaInvitationFromJson(
1257
+ responseJson.claim_uma_invitation_with_incentives?.invitation,
1258
+ );
1259
+ },
1260
+ });
1261
+ }
1262
+
1263
+ /**
1264
+ * Fetches an UMA invitation by its invitation code.
1265
+ *
1266
+ * @param invitationCode The code of the invitation to fetch.
1267
+ * @returns The invitation with the given code, or null if no invitation exists with that code.
1268
+ */
1269
+ public async fetchUmaInvitation(
1270
+ invitationCode: string,
1271
+ ): Promise<UmaInvitation | null> {
1272
+ return await this.executeRawQuery({
1273
+ queryPayload: FetchUmaInvitation,
1274
+ variables: {
1275
+ invitationCode,
1276
+ },
1277
+ constructObject: (responseJson: {
1278
+ uma_invitation_by_code: any; // eslint-disable-line @typescript-eslint/no-explicit-any
1279
+ }) => {
1280
+ if (!responseJson.uma_invitation_by_code) {
1281
+ return null;
1282
+ }
1283
+ return UmaInvitationFromJson(responseJson.uma_invitation_by_code);
1284
+ },
1285
+ });
1286
+ }
1287
+
1288
+ private async hashPhoneNumber(e164PhoneNumber: string): Promise<string> {
1289
+ const e164PhoneRegex = /^\+[1-9]\d{1,14}$/;
1290
+ if (!e164PhoneRegex.test(e164PhoneNumber)) {
1291
+ throw new LightsparkException(
1292
+ "InvalidPhoneNumber",
1293
+ "Invalid phone number. Phone number must be in E164 format.",
1294
+ );
1295
+ }
1296
+ return await createSha256Hash(e164PhoneNumber, true);
1297
+ }
1298
+
1073
1299
  /**
1074
1300
  * Executes a raw `Query` against the Lightspark API.
1075
1301
  *
1076
- * This generally should not be used directly, but is exposed for advanced use cases and for internal use to retrieve
1302
+ * This generally should not be used directly,
1303
+ * but is exposed for advanced use cases and for internal use to retrieve
1077
1304
  * complex fields from objects.
1078
1305
  *
1079
1306
  * @param query The `Query` to execute.
package/src/env.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- /* These utils are only needed in NodeJS contexts and so the file is exported separately
3
+ /*
4
+ * These utils are only needed in NodeJS contexts and so the file is exported
5
+ * separately
4
6
  in the package to avoid eg unnecessary browser bundling */
5
7
  import dotenv from "dotenv";
6
8
  import { getBitcoinNetworkOrThrow } from "./helpers.js";
@@ -0,0 +1,21 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import { FRAGMENT as UmaInvitationFragment } from "../objects/UmaInvitation.js";
4
+
5
+ export const ClaimUmaInvitation = `
6
+ mutation ClaimUmaInvitation(
7
+ $invitationCode: String!
8
+ $inviteeUma: String!
9
+ ) {
10
+ claim_uma_invitation(input: {
11
+ invitation_code: $invitationCode
12
+ invitee_uma: $inviteeUma
13
+ }) {
14
+ invitation {
15
+ ...UmaInvitationFragment
16
+ }
17
+ }
18
+ }
19
+
20
+ ${UmaInvitationFragment}
21
+ `;