@buildonspark/spark-sdk 0.1.41 → 0.1.43

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 (156) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/android/src/main/jniLibs/arm64-v8a/libuniffi_spark_frost.so +0 -0
  3. package/android/src/main/jniLibs/armeabi-v7a/libuniffi_spark_frost.so +0 -0
  4. package/android/src/main/jniLibs/x86/libuniffi_spark_frost.so +0 -0
  5. package/android/src/main/jniLibs/x86_64/libuniffi_spark_frost.so +0 -0
  6. package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.cts +10 -0
  7. package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.ts +10 -0
  8. package/dist/{RequestLightningSendInput-mXUWn_cp.d.ts → RequestLightningSendInput-D7fZdT4A.d.ts} +35 -16
  9. package/dist/{RequestLightningSendInput-DXcLoiCe.d.cts → RequestLightningSendInput-Na1mHdWg.d.cts} +35 -16
  10. package/dist/address/index.cjs +38 -7
  11. package/dist/address/index.d.cts +2 -2
  12. package/dist/address/index.d.ts +2 -2
  13. package/dist/address/index.js +3 -3
  14. package/dist/{chunk-ATEHMLKP.js → chunk-6AFUC5M2.js} +1 -1
  15. package/dist/{chunk-ZXDE2XMU.js → chunk-BUTZWYBW.js} +9 -6
  16. package/dist/{chunk-7EFSUADA.js → chunk-DOA6QXYQ.js} +1 -0
  17. package/dist/{chunk-J5W5Q2ZP.js → chunk-DQYKQJRZ.js} +291 -7
  18. package/dist/{chunk-TWF35O6M.js → chunk-GSI4OLXZ.js} +32 -1
  19. package/dist/{chunk-2ZXXLPG2.js → chunk-GYQR4B4P.js} +5 -4
  20. package/dist/{chunk-ROKY5KS4.js → chunk-HRQRRDSS.js} +53 -15
  21. package/dist/{chunk-YEZDPUFY.js → chunk-IRW5TWMH.js} +8 -8
  22. package/dist/{chunk-7VMYMQLF.js → chunk-NSJF5F5O.js} +1 -1
  23. package/dist/{chunk-TM4TOEOX.js → chunk-O4RYNJNB.js} +3 -3
  24. package/dist/{chunk-MGPRLH6Q.js → chunk-QNNSEJ4P.js} +1 -1
  25. package/dist/{chunk-UKT6OFLO.js → chunk-TIUBYNN5.js} +13 -7
  26. package/dist/{chunk-6YVPOQ2A.js → chunk-TOSP3INR.js} +235 -143
  27. package/dist/chunk-VFJQNBFX.js +21 -0
  28. package/dist/{chunk-KKSU7OZO.js → chunk-WWOTVNPP.js} +195 -67
  29. package/dist/{chunk-HK6LPV6Z.js → chunk-Z5HIAYFT.js} +1 -1
  30. package/dist/graphql/objects/index.cjs +229 -135
  31. package/dist/graphql/objects/index.d.cts +54 -9
  32. package/dist/graphql/objects/index.d.ts +54 -9
  33. package/dist/graphql/objects/index.js +3 -3
  34. package/dist/{index-OSDtPMmC.d.ts → index-7RYRH5wc.d.ts} +10 -8
  35. package/dist/{index-CFh4uWzi.d.cts → index-BJOc8Ur-.d.cts} +10 -8
  36. package/dist/index.cjs +790 -315
  37. package/dist/index.d.cts +8 -7
  38. package/dist/index.d.ts +8 -7
  39. package/dist/index.js +26 -26
  40. package/dist/index.node.cjs +790 -315
  41. package/dist/index.node.d.cts +9 -8
  42. package/dist/index.node.d.ts +9 -8
  43. package/dist/index.node.js +26 -26
  44. package/dist/native/index.cjs +812 -332
  45. package/dist/native/index.d.cts +53 -18
  46. package/dist/native/index.d.ts +53 -18
  47. package/dist/native/index.js +659 -181
  48. package/dist/{network-BiwBmoOg.d.cts → network-D5lKssVl.d.cts} +1 -1
  49. package/dist/{network-BF2GYPye.d.ts → network-xkBSpaTn.d.ts} +1 -1
  50. package/dist/proto/lrc20.d.cts +1 -1
  51. package/dist/proto/lrc20.d.ts +1 -1
  52. package/dist/proto/spark.d.cts +1 -1
  53. package/dist/proto/spark.d.ts +1 -1
  54. package/dist/proto/spark_token.d.cts +1 -1
  55. package/dist/proto/spark_token.d.ts +1 -1
  56. package/dist/{sdk-types-CfhdFnsA.d.cts → sdk-types-B-q9py_P.d.cts} +1 -1
  57. package/dist/{sdk-types-MnQrHolg.d.ts → sdk-types-BPoPgzda.d.ts} +1 -1
  58. package/dist/services/config.cjs +118 -69
  59. package/dist/services/config.d.cts +6 -4
  60. package/dist/services/config.d.ts +6 -4
  61. package/dist/services/config.js +9 -9
  62. package/dist/services/connection.cjs +95 -15
  63. package/dist/services/connection.d.cts +6 -4
  64. package/dist/services/connection.d.ts +6 -4
  65. package/dist/services/connection.js +3 -3
  66. package/dist/services/index.cjs +487 -117
  67. package/dist/services/index.d.cts +5 -4
  68. package/dist/services/index.d.ts +5 -4
  69. package/dist/services/index.js +19 -19
  70. package/dist/services/lrc-connection.cjs +50 -7
  71. package/dist/services/lrc-connection.d.cts +5 -4
  72. package/dist/services/lrc-connection.d.ts +5 -4
  73. package/dist/services/lrc-connection.js +3 -3
  74. package/dist/services/token-transactions.cjs +351 -36
  75. package/dist/services/token-transactions.d.cts +5 -4
  76. package/dist/services/token-transactions.d.ts +5 -4
  77. package/dist/services/token-transactions.js +6 -6
  78. package/dist/services/wallet-config.cjs +1 -0
  79. package/dist/services/wallet-config.d.cts +6 -4
  80. package/dist/services/wallet-config.d.ts +6 -4
  81. package/dist/services/wallet-config.js +1 -1
  82. package/dist/signer/signer.cjs +117 -64
  83. package/dist/signer/signer.d.cts +4 -3
  84. package/dist/signer/signer.d.ts +4 -3
  85. package/dist/signer/signer.js +15 -7
  86. package/dist/{signer-CylxIujU.d.ts → signer-IO3oMRNj.d.cts} +2 -1
  87. package/dist/{signer-BhLS7SYR.d.cts → signer-wqesWifN.d.ts} +2 -1
  88. package/dist/{spark-DjR1b3TC.d.cts → spark-CDm4gqS6.d.cts} +1 -1
  89. package/dist/{spark-DjR1b3TC.d.ts → spark-CDm4gqS6.d.ts} +1 -1
  90. package/dist/types/index.cjs +282 -188
  91. package/dist/types/index.d.cts +7 -6
  92. package/dist/types/index.d.ts +7 -6
  93. package/dist/types/index.js +3 -3
  94. package/dist/utils/index.cjs +90 -58
  95. package/dist/utils/index.d.cts +6 -5
  96. package/dist/utils/index.d.ts +6 -5
  97. package/dist/utils/index.js +16 -16
  98. package/ios/spark_frostFFI.xcframework/ios-arm64/SparkFrost +0 -0
  99. package/ios/spark_frostFFI.xcframework/ios-arm64/spark_frostFFI.framework/spark_frostFFI +0 -0
  100. package/ios/spark_frostFFI.xcframework/ios-arm64_x86_64-simulator/SparkFrost +0 -0
  101. package/ios/spark_frostFFI.xcframework/ios-arm64_x86_64-simulator/spark_frostFFI.framework/spark_frostFFI +0 -0
  102. package/ios/spark_frostFFI.xcframework/macos-arm64_x86_64/spark_frostFFI.framework/spark_frostFFI +0 -0
  103. package/package.json +4 -4
  104. package/src/constants.ts +21 -0
  105. package/src/errors/base.ts +43 -1
  106. package/src/graphql/client.ts +4 -0
  107. package/src/graphql/mutations/RequestLightningSend.ts +2 -0
  108. package/src/graphql/objects/ClaimStaticDepositInput.ts +1 -1
  109. package/src/graphql/objects/ClaimStaticDepositStatus.ts +4 -2
  110. package/src/graphql/objects/Connection.ts +7 -7
  111. package/src/graphql/objects/CoopExitFeeEstimate.ts +1 -1
  112. package/src/graphql/objects/CoopExitFeeQuote.ts +202 -0
  113. package/src/graphql/objects/CoopExitFeeQuoteInput.ts +41 -0
  114. package/src/graphql/objects/CoopExitFeeQuoteOutput.ts +45 -0
  115. package/src/graphql/objects/CoopExitRequest.ts +21 -0
  116. package/src/graphql/objects/CurrencyUnit.ts +26 -28
  117. package/src/graphql/objects/Entity.ts +84 -0
  118. package/src/graphql/objects/Invoice.ts +2 -2
  119. package/src/graphql/objects/Leaf.ts +1 -1
  120. package/src/graphql/objects/LeavesSwapFeeEstimateOutput.ts +1 -1
  121. package/src/graphql/objects/LeavesSwapRequest.ts +6 -0
  122. package/src/graphql/objects/LightningReceiveRequest.ts +11 -0
  123. package/src/graphql/objects/LightningSendFeeEstimateInput.ts +8 -0
  124. package/src/graphql/objects/LightningSendFeeEstimateOutput.ts +1 -1
  125. package/src/graphql/objects/LightningSendRequest.ts +3 -0
  126. package/src/graphql/objects/RequestCoopExitInput.ts +8 -0
  127. package/src/graphql/objects/RequestLeavesSwapInput.ts +5 -1
  128. package/src/graphql/objects/RequestLightningReceiveInput.ts +9 -2
  129. package/src/graphql/objects/RequestLightningSendInput.ts +8 -0
  130. package/src/graphql/objects/SparkCoopExitRequestStatus.ts +2 -0
  131. package/src/graphql/objects/SparkUserRequestType.ts +2 -0
  132. package/src/graphql/objects/SparkWalletUser.ts +20 -0
  133. package/src/graphql/objects/UserRequest.ts +32 -0
  134. package/src/graphql/objects/VerifyChallengeInput.ts +1 -1
  135. package/src/graphql/objects/index.ts +12 -3
  136. package/src/graphql/queries/LightningSendFeeEstimate.ts +2 -0
  137. package/src/logger.ts +3 -0
  138. package/src/native/index.ts +1 -0
  139. package/src/services/config.ts +4 -0
  140. package/src/services/connection.ts +68 -29
  141. package/src/services/coop-exit.ts +1 -1
  142. package/src/services/lightning.ts +25 -1
  143. package/src/services/lrc-connection.ts +3 -3
  144. package/src/services/token-transactions.ts +6 -2
  145. package/src/services/wallet-config.ts +2 -0
  146. package/src/signer/signer.ts +4 -1
  147. package/src/spark-wallet/spark-wallet.ts +51 -15
  148. package/src/spark-wallet/types.ts +1 -0
  149. package/src/tests/errors.test.ts +58 -0
  150. package/src/tests/integration/lightning.test.ts +184 -0
  151. package/src/tests/integration/ssp/static_deposit.test.ts +1 -2
  152. package/src/tests/tokens.test.ts +52 -3
  153. package/src/utils/token-hashing.ts +335 -1
  154. package/dist/LightningSendFeeEstimateInput-CJvPnCSB.d.cts +0 -5
  155. package/dist/LightningSendFeeEstimateInput-CJvPnCSB.d.ts +0 -5
  156. package/dist/chunk-HKAKEKCE.js +0 -8
@@ -1,3 +1,12 @@
1
+ import {
2
+ ConnectionManager
3
+ } from "./chunk-HRQRRDSS.js";
4
+ import {
5
+ Lrc20ConnectionManager
6
+ } from "./chunk-GYQR4B4P.js";
7
+ import {
8
+ TokenTransactionService
9
+ } from "./chunk-DQYKQJRZ.js";
1
10
  import {
2
11
  DEFAULT_FEE_SATS,
3
12
  computeTaprootKeyNoScript,
@@ -14,14 +23,16 @@ import {
14
23
  getTxFromRawTxHex,
15
24
  getTxId,
16
25
  proofOfPossessionMessageHashForDepositAddress
17
- } from "./chunk-YEZDPUFY.js";
26
+ } from "./chunk-IRW5TWMH.js";
27
+ import {
28
+ calculateAvailableTokenAmount
29
+ } from "./chunk-6AFUC5M2.js";
18
30
  import {
19
31
  mapTransferToWalletTransfer,
20
32
  mapTreeNodeToWalletLeaf
21
33
  } from "./chunk-MIVX3GHD.js";
22
34
  import {
23
35
  ClaimStaticDepositRequestType_default,
24
- CoopExitRequestFromJson,
25
36
  CurrencyAmountFromJson,
26
37
  ExitSpeed_default,
27
38
  FRAGMENT,
@@ -29,69 +40,57 @@ import {
29
40
  FRAGMENT3,
30
41
  FRAGMENT4,
31
42
  FRAGMENT5,
32
- FRAGMENT6,
33
43
  LeavesSwapRequestFromJson,
34
44
  LightningReceiveRequestFromJson,
35
45
  LightningSendRequestFromJson,
46
+ SparkCoopExitRequestStatus_default,
36
47
  TransferFromJson
37
- } from "./chunk-6YVPOQ2A.js";
48
+ } from "./chunk-TOSP3INR.js";
49
+ import {
50
+ decodeSparkAddress,
51
+ encodeSparkAddress,
52
+ isValidPublicKey
53
+ } from "./chunk-O4RYNJNB.js";
38
54
  import {
39
55
  WalletConfigService
40
- } from "./chunk-ZXDE2XMU.js";
56
+ } from "./chunk-BUTZWYBW.js";
41
57
  import {
42
58
  LRC_WALLET_NETWORK,
43
59
  LRC_WALLET_NETWORK_TYPE,
44
60
  Network,
45
61
  NetworkToProto,
46
62
  getNetwork
47
- } from "./chunk-HK6LPV6Z.js";
63
+ } from "./chunk-Z5HIAYFT.js";
48
64
  import {
49
65
  ELECTRS_CREDENTIALS
50
- } from "./chunk-7EFSUADA.js";
51
- import {
52
- addPublicKeys,
53
- applyAdaptorToSignature,
54
- generateAdaptorFromSignature,
55
- generateSignatureFromExistingAdaptor,
56
- subtractPublicKeys
57
- } from "./chunk-7VMYMQLF.js";
66
+ } from "./chunk-DOA6QXYQ.js";
58
67
  import {
59
68
  BitcoinNetwork_default
60
69
  } from "./chunk-HMLOC6TE.js";
61
70
  import {
62
- ConnectionManager
63
- } from "./chunk-ROKY5KS4.js";
64
- import {
65
- Lrc20ConnectionManager
66
- } from "./chunk-2ZXXLPG2.js";
71
+ SendLeafKeyTweaks,
72
+ networkToJSON
73
+ } from "./chunk-M6A4KFIG.js";
67
74
  import {
68
75
  isReactNative
69
- } from "./chunk-HKAKEKCE.js";
70
- import {
71
- TokenTransactionService
72
- } from "./chunk-J5W5Q2ZP.js";
76
+ } from "./chunk-VFJQNBFX.js";
73
77
  import {
74
- calculateAvailableTokenAmount
75
- } from "./chunk-ATEHMLKP.js";
76
- import {
77
- decodeSparkAddress,
78
- encodeSparkAddress,
79
- isValidPublicKey
80
- } from "./chunk-TM4TOEOX.js";
78
+ addPublicKeys,
79
+ applyAdaptorToSignature,
80
+ generateAdaptorFromSignature,
81
+ generateSignatureFromExistingAdaptor,
82
+ subtractPublicKeys
83
+ } from "./chunk-NSJF5F5O.js";
81
84
  import {
82
85
  getCrypto
83
- } from "./chunk-MGPRLH6Q.js";
86
+ } from "./chunk-QNNSEJ4P.js";
84
87
  import {
85
88
  AuthenticationError,
86
89
  ConfigurationError,
87
90
  NetworkError,
88
91
  RPCError,
89
92
  ValidationError
90
- } from "./chunk-TWF35O6M.js";
91
- import {
92
- SendLeafKeyTweaks,
93
- networkToJSON
94
- } from "./chunk-M6A4KFIG.js";
93
+ } from "./chunk-GSI4OLXZ.js";
95
94
  import {
96
95
  Buffer
97
96
  } from "./chunk-MVRQ5US7.js";
@@ -127,7 +126,7 @@ var ClaimStaticDepositOutputFromJson = (obj) => {
127
126
  transferId: obj["claim_static_deposit_output_transfer_id"]
128
127
  };
129
128
  };
130
- var FRAGMENT7 = `
129
+ var FRAGMENT6 = `
131
130
  fragment ClaimStaticDepositOutputFragment on ClaimStaticDepositOutput {
132
131
  __typename
133
132
  claim_static_deposit_output_transfer_id: transfer_id
@@ -160,9 +159,81 @@ var ClaimStaticDeposit = `
160
159
  }
161
160
  }
162
161
 
163
- ${FRAGMENT7}
162
+ ${FRAGMENT6}
164
163
  `;
165
164
 
165
+ // src/graphql/objects/CoopExitRequest.ts
166
+ import { isObject } from "@lightsparkdev/core";
167
+ var CoopExitRequestFromJson = (obj) => {
168
+ return {
169
+ id: obj["coop_exit_request_id"],
170
+ createdAt: obj["coop_exit_request_created_at"],
171
+ updatedAt: obj["coop_exit_request_updated_at"],
172
+ network: BitcoinNetwork_default[obj["coop_exit_request_network"]] ?? BitcoinNetwork_default.FUTURE_VALUE,
173
+ fee: CurrencyAmountFromJson(obj["coop_exit_request_fee"]),
174
+ l1BroadcastFee: CurrencyAmountFromJson(
175
+ obj["coop_exit_request_l1_broadcast_fee"]
176
+ ),
177
+ status: SparkCoopExitRequestStatus_default[obj["coop_exit_request_status"]] ?? SparkCoopExitRequestStatus_default.FUTURE_VALUE,
178
+ expiresAt: obj["coop_exit_request_expires_at"],
179
+ rawConnectorTransaction: obj["coop_exit_request_raw_connector_transaction"],
180
+ rawCoopExitTransaction: obj["coop_exit_request_raw_coop_exit_transaction"],
181
+ coopExitTxid: obj["coop_exit_request_coop_exit_txid"],
182
+ typename: "CoopExitRequest",
183
+ feeQuoteId: obj["coop_exit_request_fee_quote"]?.id ?? void 0,
184
+ exitSpeed: !!obj["coop_exit_request_exit_speed"] ? ExitSpeed_default[obj["coop_exit_request_exit_speed"]] ?? ExitSpeed_default.FUTURE_VALUE : null,
185
+ transfer: !!obj["coop_exit_request_transfer"] ? TransferFromJson(obj["coop_exit_request_transfer"]) : void 0
186
+ };
187
+ };
188
+ var FRAGMENT7 = `
189
+ fragment CoopExitRequestFragment on CoopExitRequest {
190
+ __typename
191
+ coop_exit_request_id: id
192
+ coop_exit_request_created_at: created_at
193
+ coop_exit_request_updated_at: updated_at
194
+ coop_exit_request_network: network
195
+ coop_exit_request_fee: fee {
196
+ __typename
197
+ currency_amount_original_value: original_value
198
+ currency_amount_original_unit: original_unit
199
+ currency_amount_preferred_currency_unit: preferred_currency_unit
200
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
201
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
202
+ }
203
+ coop_exit_request_l1_broadcast_fee: l1_broadcast_fee {
204
+ __typename
205
+ currency_amount_original_value: original_value
206
+ currency_amount_original_unit: original_unit
207
+ currency_amount_preferred_currency_unit: preferred_currency_unit
208
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
209
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
210
+ }
211
+ coop_exit_request_fee_quote: fee_quote {
212
+ id
213
+ }
214
+ coop_exit_request_exit_speed: exit_speed
215
+ coop_exit_request_status: status
216
+ coop_exit_request_expires_at: expires_at
217
+ coop_exit_request_raw_connector_transaction: raw_connector_transaction
218
+ coop_exit_request_raw_coop_exit_transaction: raw_coop_exit_transaction
219
+ coop_exit_request_coop_exit_txid: coop_exit_txid
220
+ coop_exit_request_transfer: transfer {
221
+ __typename
222
+ transfer_total_amount: total_amount {
223
+ __typename
224
+ currency_amount_original_value: original_value
225
+ currency_amount_original_unit: original_unit
226
+ currency_amount_preferred_currency_unit: preferred_currency_unit
227
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
228
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
229
+ }
230
+ transfer_spark_id: spark_id
231
+ transfer_user_request: user_request {
232
+ id
233
+ }
234
+ }
235
+ }`;
236
+
166
237
  // src/graphql/mutations/CompleteCoopExit.ts
167
238
  var CompleteCoopExit = `
168
239
  mutation CompleteCoopExit(
@@ -179,7 +250,7 @@ var CompleteCoopExit = `
179
250
  }
180
251
  }
181
252
 
182
- ${FRAGMENT2}
253
+ ${FRAGMENT7}
183
254
  `;
184
255
 
185
256
  // src/graphql/mutations/CompleteLeavesSwap.ts
@@ -196,7 +267,7 @@ var CompleteLeavesSwap = `
196
267
  }
197
268
  }
198
269
 
199
- ${FRAGMENT3}
270
+ ${FRAGMENT2}
200
271
  `;
201
272
 
202
273
  // src/graphql/objects/GetChallengeOutput.ts
@@ -247,7 +318,7 @@ var RequestCoopExit = `
247
318
  }
248
319
  }
249
320
  }
250
- ${FRAGMENT2}
321
+ ${FRAGMENT7}
251
322
  `;
252
323
 
253
324
  // src/graphql/mutations/RequestLightningReceive.ts
@@ -279,7 +350,7 @@ var RequestLightningReceive = `
279
350
  }
280
351
  }
281
352
  }
282
- ${FRAGMENT4}
353
+ ${FRAGMENT3}
283
354
  `;
284
355
 
285
356
  // src/graphql/mutations/RequestLightningSend.ts
@@ -287,17 +358,19 @@ var RequestLightningSend = `
287
358
  mutation RequestLightningSend(
288
359
  $encoded_invoice: String!
289
360
  $idempotency_key: String!
361
+ $amount_sats: Long
290
362
  ) {
291
363
  request_lightning_send(input: {
292
364
  encoded_invoice: $encoded_invoice
293
365
  idempotency_key: $idempotency_key
366
+ amount_sats: $amount_sats
294
367
  }) {
295
368
  request {
296
369
  ...LightningSendRequestFragment
297
370
  }
298
371
  }
299
372
  }
300
- ${FRAGMENT5}
373
+ ${FRAGMENT4}
301
374
  `;
302
375
 
303
376
  // src/graphql/mutations/RequestSwapLeaves.ts
@@ -323,7 +396,7 @@ var RequestSwapLeaves = `
323
396
  }
324
397
  }
325
398
  }
326
- ${FRAGMENT3}
399
+ ${FRAGMENT2}
327
400
  `;
328
401
 
329
402
  // src/graphql/objects/VerifyChallengeOutput.ts
@@ -555,10 +628,12 @@ var LeavesSwapFeeEstimate = `
555
628
  var LightningSendFeeEstimate = `
556
629
  query LightningSendFeeEstimate(
557
630
  $encoded_invoice: String!
631
+ $amount_sats: Long
558
632
  ) {
559
633
  lightning_send_fee_estimate(
560
634
  input: {
561
635
  encoded_invoice: $encoded_invoice
636
+ amount_sats: $amount_sats
562
637
  }
563
638
  ) {
564
639
  ...LightningSendFeeEstimateOutputFragment
@@ -584,7 +659,7 @@ var UserRequest = `
584
659
  ...UserRequestFragment
585
660
  }
586
661
  }
587
- ${FRAGMENT6}
662
+ ${FRAGMENT5}
588
663
  `;
589
664
 
590
665
  // src/graphql/client.ts
@@ -652,11 +727,12 @@ var SspClient = class {
652
727
  }
653
728
  });
654
729
  }
655
- async getLightningSendFeeEstimate(encodedInvoice) {
730
+ async getLightningSendFeeEstimate(encodedInvoice, amountSats) {
656
731
  return await this.executeRawQuery({
657
732
  queryPayload: LightningSendFeeEstimate,
658
733
  variables: {
659
- encoded_invoice: encodedInvoice
734
+ encoded_invoice: encodedInvoice,
735
+ amount_sats: amountSats
660
736
  },
661
737
  constructObject: (response) => {
662
738
  return LightningSendFeeEstimateOutputFromJson(
@@ -752,13 +828,15 @@ var SspClient = class {
752
828
  }
753
829
  async requestLightningSend({
754
830
  encodedInvoice,
755
- idempotencyKey
831
+ idempotencyKey,
832
+ amountSats
756
833
  }) {
757
834
  return await this.executeRawQuery({
758
835
  queryPayload: RequestLightningSend,
759
836
  variables: {
760
837
  encoded_invoice: encodedInvoice,
761
- idempotency_key: idempotencyKey
838
+ idempotency_key: idempotencyKey,
839
+ amount_sats: amountSats
762
840
  },
763
841
  constructObject: (response) => {
764
842
  return LightningSendRequestFromJson(
@@ -2264,7 +2342,7 @@ var CoopExitService = class extends BaseTransferService {
2264
2342
  connectorOutputs,
2265
2343
  receiverPubKey
2266
2344
  );
2267
- const transferTweak = await this.sendTransferTweakKey(
2345
+ const transferTweak = await this.deliverTransferPackage(
2268
2346
  transfer,
2269
2347
  leaves,
2270
2348
  signaturesMap
@@ -3012,7 +3090,8 @@ var LightningService = class {
3012
3090
  paymentHash,
3013
3091
  invoiceString,
3014
3092
  isInboundPayment,
3015
- feeSats = 0
3093
+ feeSats = 0,
3094
+ amountSatsToSend
3016
3095
  }) {
3017
3096
  const sparkClient = await this.connectionManager.createSparkClient(
3018
3097
  this.config.getCoordinatorAddress()
@@ -3049,7 +3128,25 @@ var LightningService = class {
3049
3128
  } catch (error) {
3050
3129
  console.error("Error decoding invoice", error);
3051
3130
  }
3052
- amountSats = amountMsats / 1e3;
3131
+ const isZeroAmountInvoice = !amountMsats;
3132
+ if (isZeroAmountInvoice && amountSatsToSend === void 0) {
3133
+ throw new ValidationError(
3134
+ "Invalid amount. User must specify amountSatsToSend for 0 amount lightning invoice",
3135
+ {
3136
+ field: "amountSatsToSend",
3137
+ value: amountSatsToSend,
3138
+ expected: "positive number"
3139
+ }
3140
+ );
3141
+ }
3142
+ amountSats = isZeroAmountInvoice ? amountSatsToSend : amountMsats / 1e3;
3143
+ if (isNaN(amountSats) || amountSats <= 0) {
3144
+ throw new ValidationError("Invalid amount", {
3145
+ field: "amountSats",
3146
+ value: amountSats,
3147
+ expected: "greater than 0"
3148
+ });
3149
+ }
3053
3150
  bolt11String = invoiceString;
3054
3151
  }
3055
3152
  const reason = isInboundPayment ? 1 /* REASON_RECEIVE */ : 0 /* REASON_SEND */;
@@ -5899,12 +5996,14 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5899
5996
  * @param {Object} params - Parameters for paying the invoice
5900
5997
  * @param {string} params.invoice - The BOLT11-encoded Lightning invoice to pay
5901
5998
  * @param {boolean} [params.preferSpark] - Whether to prefer a spark transfer over lightning for the payment
5999
+ * @param {number} [params.amountSatsToSend] - The amount in sats to send. This is only valid for 0 amount lightning invoices.
5902
6000
  * @returns {Promise<LightningSendRequest>} The Lightning payment request details
5903
6001
  */
5904
6002
  async payLightningInvoice({
5905
6003
  invoice,
5906
6004
  maxFeeSats,
5907
- preferSpark = false
6005
+ preferSpark = false,
6006
+ amountSatsToSend
5908
6007
  }) {
5909
6008
  const invoiceNetwork = getNetworkFromInvoice(invoice);
5910
6009
  const walletNetwork = this.config.getNetwork();
@@ -5919,7 +6018,36 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5919
6018
  );
5920
6019
  }
5921
6020
  const decodedInvoice = decodeInvoice(invoice);
5922
- const amountSats = decodedInvoice.amountMSats !== null ? Number(decodedInvoice.amountMSats / 1000n) : 0;
6021
+ const amountMSats = decodedInvoice.amountMSats;
6022
+ const isZeroAmountInvoice = !amountMSats;
6023
+ if (!isZeroAmountInvoice && amountSatsToSend !== void 0) {
6024
+ throw new ValidationError(
6025
+ "Invalid amount. User can only specify amountSatsToSend for 0 amount lightning invoice",
6026
+ {
6027
+ field: "amountMSats",
6028
+ value: Number(amountMSats),
6029
+ expected: "0"
6030
+ }
6031
+ );
6032
+ }
6033
+ if (isZeroAmountInvoice && amountSatsToSend === void 0) {
6034
+ throw new ValidationError(
6035
+ "Invalid amount. User must specify amountSatsToSend for 0 amount lightning invoice",
6036
+ {
6037
+ field: "amountMSats",
6038
+ value: Number(amountMSats),
6039
+ expected: "0"
6040
+ }
6041
+ );
6042
+ }
6043
+ const amountSats = isZeroAmountInvoice ? amountSatsToSend : Number(amountMSats / 1000n);
6044
+ if (isNaN(amountSats) || amountSats <= 0) {
6045
+ throw new ValidationError("Invalid amount", {
6046
+ field: "amountSats",
6047
+ value: amountSats,
6048
+ expected: "greater than 0"
6049
+ });
6050
+ }
5923
6051
  const sparkFallbackAddress = decodedInvoice.fallbackAddress;
5924
6052
  const paymentHash = decodedInvoice.paymentHash;
5925
6053
  if (preferSpark) {
@@ -5941,15 +6069,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5941
6069
  }
5942
6070
  return await this.withLeaves(async () => {
5943
6071
  const sspClient = this.getSspClient();
5944
- if (isNaN(amountSats) || amountSats <= 0) {
5945
- throw new ValidationError("Invalid amount", {
5946
- field: "amountSats",
5947
- value: amountSats,
5948
- expected: "positive number"
5949
- });
5950
- }
5951
6072
  const feeEstimate = await this.getLightningSendFeeEstimate({
5952
- encodedInvoice: invoice
6073
+ encodedInvoice: invoice,
6074
+ amountSats: isZeroAmountInvoice ? amountSatsToSend : void 0
5953
6075
  });
5954
6076
  if (maxFeeSats < feeEstimate) {
5955
6077
  throw new ValidationError("maxFeeSats does not cover fee estimate", {
@@ -5987,19 +6109,21 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5987
6109
  paymentHash: hexToBytes7(paymentHash),
5988
6110
  isInboundPayment: false,
5989
6111
  invoiceString: invoice,
5990
- feeSats: feeEstimate
6112
+ feeSats: feeEstimate,
6113
+ amountSatsToSend
5991
6114
  });
5992
6115
  if (!swapResponse.transfer) {
5993
6116
  throw new Error("Failed to swap nodes for preimage");
5994
6117
  }
5995
- const transfer = await this.transferService.sendTransferTweakKey(
6118
+ await this.transferService.deliverTransferPackage(
5996
6119
  swapResponse.transfer,
5997
6120
  leavesToSend,
5998
6121
  /* @__PURE__ */ new Map()
5999
6122
  );
6000
6123
  const sspResponse = await sspClient.requestLightningSend({
6001
6124
  encodedInvoice: invoice,
6002
- idempotencyKey: paymentHash
6125
+ idempotencyKey: paymentHash,
6126
+ amountSats: isZeroAmountInvoice ? amountSatsToSend : void 0
6003
6127
  });
6004
6128
  if (!sspResponse) {
6005
6129
  throw new Error("Failed to contact SSP");
@@ -6016,10 +6140,14 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6016
6140
  * @returns {Promise<number>} Fee estimate for sending Lightning payments
6017
6141
  */
6018
6142
  async getLightningSendFeeEstimate({
6019
- encodedInvoice
6143
+ encodedInvoice,
6144
+ amountSats
6020
6145
  }) {
6021
6146
  const sspClient = this.getSspClient();
6022
- const feeEstimate = await sspClient.getLightningSendFeeEstimate(encodedInvoice);
6147
+ const feeEstimate = await sspClient.getLightningSendFeeEstimate(
6148
+ encodedInvoice,
6149
+ amountSats
6150
+ );
6023
6151
  if (!feeEstimate) {
6024
6152
  throw new Error("Failed to get lightning send fee estimate");
6025
6153
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ValidationError
3
- } from "./chunk-TWF35O6M.js";
3
+ } from "./chunk-GSI4OLXZ.js";
4
4
 
5
5
  // src/utils/network.ts
6
6
  import { NetworkType as Lrc20NetworkType } from "@buildonspark/lrc20-sdk";