@buildonspark/spark-sdk 0.2.12 → 0.2.13

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 (48) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/bare/index.cjs +59 -38
  3. package/dist/bare/index.d.cts +23 -8
  4. package/dist/bare/index.d.ts +23 -8
  5. package/dist/bare/index.js +59 -38
  6. package/dist/{chunk-NQMQVXR5.js → chunk-CKHJFQUA.js} +1 -1
  7. package/dist/{chunk-OEK3R57K.js → chunk-LX45BCZW.js} +59 -38
  8. package/dist/debug.cjs +59 -38
  9. package/dist/debug.d.cts +2 -2
  10. package/dist/debug.d.ts +2 -2
  11. package/dist/debug.js +1 -1
  12. package/dist/index.cjs +59 -38
  13. package/dist/index.d.cts +4 -4
  14. package/dist/index.d.ts +4 -4
  15. package/dist/index.js +2 -2
  16. package/dist/index.node.cjs +59 -38
  17. package/dist/index.node.d.cts +4 -4
  18. package/dist/index.node.d.ts +4 -4
  19. package/dist/index.node.js +1 -1
  20. package/dist/{logging-D3kvES69.d.cts → logging-BfTyKwqb.d.cts} +1 -1
  21. package/dist/{logging-ClNhGzus.d.ts → logging-CaNpBgiE.d.ts} +1 -1
  22. package/dist/native/index.cjs +59 -38
  23. package/dist/native/index.d.cts +23 -8
  24. package/dist/native/index.d.ts +23 -8
  25. package/dist/native/index.js +59 -38
  26. package/dist/{spark-wallet-DiHSU-pz.d.ts → spark-wallet-D0Df_P_x.d.ts} +23 -8
  27. package/dist/{spark-wallet-Dg5IRQe2.d.cts → spark-wallet-Dvh1BLP6.d.cts} +23 -8
  28. package/dist/{spark-wallet.node-DSWb18zh.d.cts → spark-wallet.node-B3V8_fgw.d.cts} +1 -1
  29. package/dist/{spark-wallet.node-BZrxwomN.d.ts → spark-wallet.node-bGmy8-T8.d.ts} +1 -1
  30. package/dist/tests/test-utils.cjs +1 -1
  31. package/dist/tests/test-utils.d.cts +2 -2
  32. package/dist/tests/test-utils.d.ts +2 -2
  33. package/dist/tests/test-utils.js +2 -2
  34. package/dist/{token-transactions-B-WqFYpW.d.cts → token-transactions-D1ta-sHH.d.cts} +1 -1
  35. package/dist/{token-transactions-DovxHIxV.d.ts → token-transactions-DINiKBzd.d.ts} +1 -1
  36. package/package.json +3 -3
  37. package/src/services/transfer.ts +0 -26
  38. package/src/spark-wallet/proto-descriptors.ts +22 -0
  39. package/src/spark-wallet/proto-hash.ts +743 -0
  40. package/src/spark-wallet/proto-reflection.ts +193 -0
  41. package/src/spark-wallet/spark-wallet.ts +70 -24
  42. package/src/spark_descriptors.pb +0 -0
  43. package/src/tests/bufbuild-reflection.test.ts +151 -0
  44. package/src/tests/cross-language-hash.test.ts +79 -0
  45. package/src/tests/integration/address.test.ts +3 -12
  46. package/src/tests/integration/ssp/static_deposit.test.ts +15 -9
  47. package/src/tests/integration/static_deposit.test.ts +26 -0
  48. package/src/tests/integration/transfer.test.ts +0 -124
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @buildonspark/spark-sdk
2
2
 
3
+ ## 0.2.13
4
+
5
+ ### Patch Changes
6
+
7
+ - - Add create and broadcast static deposit refund tx
8
+ - Update tests to be less flaky
9
+
3
10
  ## 0.2.12
4
11
 
5
12
  ### Patch Changes
@@ -18215,7 +18215,7 @@ var ecies = __toESM(require("eciesjs"), 1);
18215
18215
  var import_core10 = require("@lightsparkdev/core");
18216
18216
  var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
18217
18217
  var isBun = globalThis.Bun !== void 0;
18218
- var packageVersion = true ? "0.2.12" : "unknown";
18218
+ var packageVersion = true ? "0.2.13" : "unknown";
18219
18219
  var baseEnvStr = "unknown";
18220
18220
  if (isBun) {
18221
18221
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -25126,24 +25126,6 @@ var TransferService = class extends BaseTransferService {
25126
25126
  throw new Error(`Error finalizing node signatures in transfer: ${error}`);
25127
25127
  }
25128
25128
  }
25129
- async cancelTransfer(transfer, operatorAddress) {
25130
- const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
25131
- try {
25132
- const response = await sparkClient.cancel_transfer({
25133
- transferId: transfer.id,
25134
- senderIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
25135
- });
25136
- return response.transfer;
25137
- } catch (error) {
25138
- throw new NetworkError(
25139
- "Failed to cancel transfer",
25140
- {
25141
- method: "POST"
25142
- },
25143
- error
25144
- );
25145
- }
25146
- }
25147
25129
  async queryPendingTransfersBySender(operatorAddress) {
25148
25130
  const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
25149
25131
  try {
@@ -32458,7 +32440,6 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32458
32440
  message: e.message,
32459
32441
  stack: e.stack
32460
32442
  });
32461
- await this.cancelAllSenderInitiatedTransfers();
32462
32443
  throw new Error(`Failed to request leaves swap: ${e}`);
32463
32444
  }
32464
32445
  }
@@ -32921,6 +32902,64 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32921
32902
  });
32922
32903
  return tx.hex;
32923
32904
  }
32905
+ /**
32906
+ * Refunds a static deposit and broadcasts the transaction to the network.
32907
+ *
32908
+ * @param {Object} params - The refund parameters
32909
+ * @param {string} params.depositTransactionId - The ID of the transaction
32910
+ * @param {number} [params.outputIndex] - The index of the output
32911
+ * @param {string} params.destinationAddress - The destination address
32912
+ * @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
32913
+ * @returns {Promise<string>} The transaction ID
32914
+ */
32915
+ async refundAndBroadcastStaticDeposit({
32916
+ depositTransactionId,
32917
+ outputIndex,
32918
+ destinationAddress,
32919
+ satsPerVbyteFee
32920
+ }) {
32921
+ const txHex = await this.refundStaticDeposit({
32922
+ depositTransactionId,
32923
+ outputIndex,
32924
+ destinationAddress,
32925
+ satsPerVbyteFee
32926
+ });
32927
+ return await this.broadcastTx(txHex);
32928
+ }
32929
+ /**
32930
+ * Broadcasts a transaction to the network.
32931
+ *
32932
+ * @param {string} txHex - The hex of the transaction
32933
+ * @returns {Promise<string>} The transaction ID
32934
+ */
32935
+ async broadcastTx(txHex) {
32936
+ if (!txHex) {
32937
+ throw new ValidationError("Transaction hex cannot be empty", {
32938
+ field: "txHex"
32939
+ });
32940
+ }
32941
+ const { fetch, Headers: Headers3 } = getFetch();
32942
+ const baseUrl = this.config.getElectrsUrl();
32943
+ const headers = new Headers3();
32944
+ if (this.config.getNetwork() === 4 /* LOCAL */) {
32945
+ const localFaucet = BitcoinFaucet.getInstance();
32946
+ const response = await localFaucet.broadcastTx(txHex);
32947
+ return response;
32948
+ } else {
32949
+ if (this.config.getNetwork() === 3 /* REGTEST */) {
32950
+ const auth = btoa(
32951
+ `${ELECTRS_CREDENTIALS.username}:${ELECTRS_CREDENTIALS.password}`
32952
+ );
32953
+ headers.set("Authorization", `Basic ${auth}`);
32954
+ }
32955
+ const response = await fetch(`${baseUrl}/tx`, {
32956
+ method: "POST",
32957
+ body: txHex,
32958
+ headers
32959
+ });
32960
+ return response.text();
32961
+ }
32962
+ }
32924
32963
  async getStaticDepositSigningPayload(transactionID, outputIndex, network, requestType, creditAmountSats, sspSignature) {
32925
32964
  const encoder = new TextEncoder();
32926
32965
  const parts = [];
@@ -33659,24 +33698,6 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33659
33698
  (result) => result.status === "fulfilled" && result.value !== null
33660
33699
  ).map((result) => result.value);
33661
33700
  }
33662
- /**
33663
- * Cancels all sender-initiated transfers.
33664
- *
33665
- * @returns {Promise<void>}
33666
- * @private
33667
- */
33668
- async cancelAllSenderInitiatedTransfers() {
33669
- for (const operator of Object.values(this.config.getSigningOperators())) {
33670
- const transfers = await this.transferService.queryPendingTransfersBySender(
33671
- operator.address
33672
- );
33673
- for (const transfer of transfers.transfers) {
33674
- if (transfer.status === 0 /* TRANSFER_STATUS_SENDER_INITIATED */) {
33675
- await this.transferService.cancelTransfer(transfer, operator.address);
33676
- }
33677
- }
33678
- }
33679
- }
33680
33701
  // ***** Lightning Flow *****
33681
33702
  /**
33682
33703
  * Creates a Lightning invoice for receiving payments.
@@ -3025,7 +3025,6 @@ declare class TransferService extends BaseTransferService {
3025
3025
  private prepareClaimLeafKeyTweaks;
3026
3026
  claimTransferSignRefunds(transfer: Transfer, leafKeys: LeafKeyTweak[], proofMap?: Map<string, Uint8Array[]>): Promise<NodeSignatures[]>;
3027
3027
  private finalizeNodeSignatures;
3028
- cancelTransfer(transfer: Transfer, operatorAddress: string): Promise<Transfer | undefined>;
3029
3028
  queryPendingTransfersBySender(operatorAddress: string): Promise<QueryTransfersResponse>;
3030
3029
  private refreshTimelockNodesInternal;
3031
3030
  refreshTimelockNodes(node: TreeNode, parentNode: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
@@ -3404,6 +3403,29 @@ declare class SparkWallet extends EventEmitter {
3404
3403
  /** @deprecated use `satsPerVbyteFee` */ fee?: number;
3405
3404
  satsPerVbyteFee?: number;
3406
3405
  }): Promise<string>;
3406
+ /**
3407
+ * Refunds a static deposit and broadcasts the transaction to the network.
3408
+ *
3409
+ * @param {Object} params - The refund parameters
3410
+ * @param {string} params.depositTransactionId - The ID of the transaction
3411
+ * @param {number} [params.outputIndex] - The index of the output
3412
+ * @param {string} params.destinationAddress - The destination address
3413
+ * @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
3414
+ * @returns {Promise<string>} The transaction ID
3415
+ */
3416
+ refundAndBroadcastStaticDeposit({ depositTransactionId, outputIndex, destinationAddress, satsPerVbyteFee, }: {
3417
+ depositTransactionId: string;
3418
+ outputIndex?: number;
3419
+ destinationAddress: string;
3420
+ satsPerVbyteFee?: number;
3421
+ }): Promise<string>;
3422
+ /**
3423
+ * Broadcasts a transaction to the network.
3424
+ *
3425
+ * @param {string} txHex - The hex of the transaction
3426
+ * @returns {Promise<string>} The transaction ID
3427
+ */
3428
+ private broadcastTx;
3407
3429
  private getStaticDepositSigningPayload;
3408
3430
  private getDepositTransactionVout;
3409
3431
  private getDepositTransaction;
@@ -3489,13 +3511,6 @@ declare class SparkWallet extends EventEmitter {
3489
3511
  * @private
3490
3512
  */
3491
3513
  private claimTransfers;
3492
- /**
3493
- * Cancels all sender-initiated transfers.
3494
- *
3495
- * @returns {Promise<void>}
3496
- * @private
3497
- */
3498
- private cancelAllSenderInitiatedTransfers;
3499
3514
  /**
3500
3515
  * Creates a Lightning invoice for receiving payments.
3501
3516
  *
@@ -3025,7 +3025,6 @@ declare class TransferService extends BaseTransferService {
3025
3025
  private prepareClaimLeafKeyTweaks;
3026
3026
  claimTransferSignRefunds(transfer: Transfer, leafKeys: LeafKeyTweak[], proofMap?: Map<string, Uint8Array[]>): Promise<NodeSignatures[]>;
3027
3027
  private finalizeNodeSignatures;
3028
- cancelTransfer(transfer: Transfer, operatorAddress: string): Promise<Transfer | undefined>;
3029
3028
  queryPendingTransfersBySender(operatorAddress: string): Promise<QueryTransfersResponse>;
3030
3029
  private refreshTimelockNodesInternal;
3031
3030
  refreshTimelockNodes(node: TreeNode, parentNode: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
@@ -3404,6 +3403,29 @@ declare class SparkWallet extends EventEmitter {
3404
3403
  /** @deprecated use `satsPerVbyteFee` */ fee?: number;
3405
3404
  satsPerVbyteFee?: number;
3406
3405
  }): Promise<string>;
3406
+ /**
3407
+ * Refunds a static deposit and broadcasts the transaction to the network.
3408
+ *
3409
+ * @param {Object} params - The refund parameters
3410
+ * @param {string} params.depositTransactionId - The ID of the transaction
3411
+ * @param {number} [params.outputIndex] - The index of the output
3412
+ * @param {string} params.destinationAddress - The destination address
3413
+ * @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
3414
+ * @returns {Promise<string>} The transaction ID
3415
+ */
3416
+ refundAndBroadcastStaticDeposit({ depositTransactionId, outputIndex, destinationAddress, satsPerVbyteFee, }: {
3417
+ depositTransactionId: string;
3418
+ outputIndex?: number;
3419
+ destinationAddress: string;
3420
+ satsPerVbyteFee?: number;
3421
+ }): Promise<string>;
3422
+ /**
3423
+ * Broadcasts a transaction to the network.
3424
+ *
3425
+ * @param {string} txHex - The hex of the transaction
3426
+ * @returns {Promise<string>} The transaction ID
3427
+ */
3428
+ private broadcastTx;
3407
3429
  private getStaticDepositSigningPayload;
3408
3430
  private getDepositTransactionVout;
3409
3431
  private getDepositTransaction;
@@ -3489,13 +3511,6 @@ declare class SparkWallet extends EventEmitter {
3489
3511
  * @private
3490
3512
  */
3491
3513
  private claimTransfers;
3492
- /**
3493
- * Cancels all sender-initiated transfers.
3494
- *
3495
- * @returns {Promise<void>}
3496
- * @private
3497
- */
3498
- private cancelAllSenderInitiatedTransfers;
3499
3514
  /**
3500
3515
  * Creates a Lightning invoice for receiving payments.
3501
3516
  *
@@ -16783,7 +16783,7 @@ import * as ecies from "eciesjs";
16783
16783
  import { isNode, isBare } from "@lightsparkdev/core";
16784
16784
  var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
16785
16785
  var isBun = globalThis.Bun !== void 0;
16786
- var packageVersion = true ? "0.2.12" : "unknown";
16786
+ var packageVersion = true ? "0.2.13" : "unknown";
16787
16787
  var baseEnvStr = "unknown";
16788
16788
  if (isBun) {
16789
16789
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -23701,24 +23701,6 @@ var TransferService = class extends BaseTransferService {
23701
23701
  throw new Error(`Error finalizing node signatures in transfer: ${error}`);
23702
23702
  }
23703
23703
  }
23704
- async cancelTransfer(transfer, operatorAddress) {
23705
- const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
23706
- try {
23707
- const response = await sparkClient.cancel_transfer({
23708
- transferId: transfer.id,
23709
- senderIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
23710
- });
23711
- return response.transfer;
23712
- } catch (error) {
23713
- throw new NetworkError(
23714
- "Failed to cancel transfer",
23715
- {
23716
- method: "POST"
23717
- },
23718
- error
23719
- );
23720
- }
23721
- }
23722
23704
  async queryPendingTransfersBySender(operatorAddress) {
23723
23705
  const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
23724
23706
  try {
@@ -31044,7 +31026,6 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
31044
31026
  message: e.message,
31045
31027
  stack: e.stack
31046
31028
  });
31047
- await this.cancelAllSenderInitiatedTransfers();
31048
31029
  throw new Error(`Failed to request leaves swap: ${e}`);
31049
31030
  }
31050
31031
  }
@@ -31507,6 +31488,64 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
31507
31488
  });
31508
31489
  return tx.hex;
31509
31490
  }
31491
+ /**
31492
+ * Refunds a static deposit and broadcasts the transaction to the network.
31493
+ *
31494
+ * @param {Object} params - The refund parameters
31495
+ * @param {string} params.depositTransactionId - The ID of the transaction
31496
+ * @param {number} [params.outputIndex] - The index of the output
31497
+ * @param {string} params.destinationAddress - The destination address
31498
+ * @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
31499
+ * @returns {Promise<string>} The transaction ID
31500
+ */
31501
+ async refundAndBroadcastStaticDeposit({
31502
+ depositTransactionId,
31503
+ outputIndex,
31504
+ destinationAddress,
31505
+ satsPerVbyteFee
31506
+ }) {
31507
+ const txHex = await this.refundStaticDeposit({
31508
+ depositTransactionId,
31509
+ outputIndex,
31510
+ destinationAddress,
31511
+ satsPerVbyteFee
31512
+ });
31513
+ return await this.broadcastTx(txHex);
31514
+ }
31515
+ /**
31516
+ * Broadcasts a transaction to the network.
31517
+ *
31518
+ * @param {string} txHex - The hex of the transaction
31519
+ * @returns {Promise<string>} The transaction ID
31520
+ */
31521
+ async broadcastTx(txHex) {
31522
+ if (!txHex) {
31523
+ throw new ValidationError("Transaction hex cannot be empty", {
31524
+ field: "txHex"
31525
+ });
31526
+ }
31527
+ const { fetch, Headers: Headers3 } = getFetch();
31528
+ const baseUrl = this.config.getElectrsUrl();
31529
+ const headers = new Headers3();
31530
+ if (this.config.getNetwork() === 4 /* LOCAL */) {
31531
+ const localFaucet = BitcoinFaucet.getInstance();
31532
+ const response = await localFaucet.broadcastTx(txHex);
31533
+ return response;
31534
+ } else {
31535
+ if (this.config.getNetwork() === 3 /* REGTEST */) {
31536
+ const auth = btoa(
31537
+ `${ELECTRS_CREDENTIALS.username}:${ELECTRS_CREDENTIALS.password}`
31538
+ );
31539
+ headers.set("Authorization", `Basic ${auth}`);
31540
+ }
31541
+ const response = await fetch(`${baseUrl}/tx`, {
31542
+ method: "POST",
31543
+ body: txHex,
31544
+ headers
31545
+ });
31546
+ return response.text();
31547
+ }
31548
+ }
31510
31549
  async getStaticDepositSigningPayload(transactionID, outputIndex, network, requestType, creditAmountSats, sspSignature) {
31511
31550
  const encoder = new TextEncoder();
31512
31551
  const parts = [];
@@ -32245,24 +32284,6 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
32245
32284
  (result) => result.status === "fulfilled" && result.value !== null
32246
32285
  ).map((result) => result.value);
32247
32286
  }
32248
- /**
32249
- * Cancels all sender-initiated transfers.
32250
- *
32251
- * @returns {Promise<void>}
32252
- * @private
32253
- */
32254
- async cancelAllSenderInitiatedTransfers() {
32255
- for (const operator of Object.values(this.config.getSigningOperators())) {
32256
- const transfers = await this.transferService.queryPendingTransfersBySender(
32257
- operator.address
32258
- );
32259
- for (const transfer of transfers.transfers) {
32260
- if (transfer.status === 0 /* TRANSFER_STATUS_SENDER_INITIATED */) {
32261
- await this.transferService.cancelTransfer(transfer, operator.address);
32262
- }
32263
- }
32264
- }
32265
- }
32266
32287
  // ***** Lightning Flow *****
32267
32288
  /**
32268
32289
  * Creates a Lightning invoice for receiving payments.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SparkWallet,
3
3
  setCrypto
4
- } from "./chunk-OEK3R57K.js";
4
+ } from "./chunk-LX45BCZW.js";
5
5
 
6
6
  // src/spark-wallet/spark-wallet.browser.ts
7
7
  import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
@@ -579,7 +579,7 @@ import * as ecies from "eciesjs";
579
579
  import { isNode, isBare } from "@lightsparkdev/core";
580
580
  var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
581
581
  var isBun = globalThis.Bun !== void 0;
582
- var packageVersion = true ? "0.2.12" : "unknown";
582
+ var packageVersion = true ? "0.2.13" : "unknown";
583
583
  var baseEnvStr = "unknown";
584
584
  if (isBun) {
585
585
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -10190,24 +10190,6 @@ var TransferService = class extends BaseTransferService {
10190
10190
  throw new Error(`Error finalizing node signatures in transfer: ${error}`);
10191
10191
  }
10192
10192
  }
10193
- async cancelTransfer(transfer, operatorAddress) {
10194
- const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
10195
- try {
10196
- const response = await sparkClient.cancel_transfer({
10197
- transferId: transfer.id,
10198
- senderIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
10199
- });
10200
- return response.transfer;
10201
- } catch (error) {
10202
- throw new NetworkError(
10203
- "Failed to cancel transfer",
10204
- {
10205
- method: "POST"
10206
- },
10207
- error
10208
- );
10209
- }
10210
- }
10211
10193
  async queryPendingTransfersBySender(operatorAddress) {
10212
10194
  const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
10213
10195
  try {
@@ -12772,7 +12754,6 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
12772
12754
  message: e.message,
12773
12755
  stack: e.stack
12774
12756
  });
12775
- await this.cancelAllSenderInitiatedTransfers();
12776
12757
  throw new Error(`Failed to request leaves swap: ${e}`);
12777
12758
  }
12778
12759
  }
@@ -13235,6 +13216,64 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
13235
13216
  });
13236
13217
  return tx.hex;
13237
13218
  }
13219
+ /**
13220
+ * Refunds a static deposit and broadcasts the transaction to the network.
13221
+ *
13222
+ * @param {Object} params - The refund parameters
13223
+ * @param {string} params.depositTransactionId - The ID of the transaction
13224
+ * @param {number} [params.outputIndex] - The index of the output
13225
+ * @param {string} params.destinationAddress - The destination address
13226
+ * @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
13227
+ * @returns {Promise<string>} The transaction ID
13228
+ */
13229
+ async refundAndBroadcastStaticDeposit({
13230
+ depositTransactionId,
13231
+ outputIndex,
13232
+ destinationAddress,
13233
+ satsPerVbyteFee
13234
+ }) {
13235
+ const txHex = await this.refundStaticDeposit({
13236
+ depositTransactionId,
13237
+ outputIndex,
13238
+ destinationAddress,
13239
+ satsPerVbyteFee
13240
+ });
13241
+ return await this.broadcastTx(txHex);
13242
+ }
13243
+ /**
13244
+ * Broadcasts a transaction to the network.
13245
+ *
13246
+ * @param {string} txHex - The hex of the transaction
13247
+ * @returns {Promise<string>} The transaction ID
13248
+ */
13249
+ async broadcastTx(txHex) {
13250
+ if (!txHex) {
13251
+ throw new ValidationError("Transaction hex cannot be empty", {
13252
+ field: "txHex"
13253
+ });
13254
+ }
13255
+ const { fetch, Headers: Headers2 } = getFetch();
13256
+ const baseUrl = this.config.getElectrsUrl();
13257
+ const headers = new Headers2();
13258
+ if (this.config.getNetwork() === 4 /* LOCAL */) {
13259
+ const localFaucet = BitcoinFaucet.getInstance();
13260
+ const response = await localFaucet.broadcastTx(txHex);
13261
+ return response;
13262
+ } else {
13263
+ if (this.config.getNetwork() === 3 /* REGTEST */) {
13264
+ const auth = btoa(
13265
+ `${ELECTRS_CREDENTIALS.username}:${ELECTRS_CREDENTIALS.password}`
13266
+ );
13267
+ headers.set("Authorization", `Basic ${auth}`);
13268
+ }
13269
+ const response = await fetch(`${baseUrl}/tx`, {
13270
+ method: "POST",
13271
+ body: txHex,
13272
+ headers
13273
+ });
13274
+ return response.text();
13275
+ }
13276
+ }
13238
13277
  async getStaticDepositSigningPayload(transactionID, outputIndex, network, requestType, creditAmountSats, sspSignature) {
13239
13278
  const encoder = new TextEncoder();
13240
13279
  const parts = [];
@@ -13973,24 +14012,6 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
13973
14012
  (result) => result.status === "fulfilled" && result.value !== null
13974
14013
  ).map((result) => result.value);
13975
14014
  }
13976
- /**
13977
- * Cancels all sender-initiated transfers.
13978
- *
13979
- * @returns {Promise<void>}
13980
- * @private
13981
- */
13982
- async cancelAllSenderInitiatedTransfers() {
13983
- for (const operator of Object.values(this.config.getSigningOperators())) {
13984
- const transfers = await this.transferService.queryPendingTransfersBySender(
13985
- operator.address
13986
- );
13987
- for (const transfer of transfers.transfers) {
13988
- if (transfer.status === 0 /* TRANSFER_STATUS_SENDER_INITIATED */) {
13989
- await this.transferService.cancelTransfer(transfer, operator.address);
13990
- }
13991
- }
13992
- }
13993
- }
13994
14015
  // ***** Lightning Flow *****
13995
14016
  /**
13996
14017
  * Creates a Lightning invoice for receiving payments.
package/dist/debug.cjs CHANGED
@@ -18209,7 +18209,7 @@ init_buffer();
18209
18209
  var import_core10 = require("@lightsparkdev/core");
18210
18210
  var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
18211
18211
  var isBun = globalThis.Bun !== void 0;
18212
- var packageVersion = true ? "0.2.12" : "unknown";
18212
+ var packageVersion = true ? "0.2.13" : "unknown";
18213
18213
  var baseEnvStr = "unknown";
18214
18214
  if (isBun) {
18215
18215
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -25032,24 +25032,6 @@ var TransferService = class extends BaseTransferService {
25032
25032
  throw new Error(`Error finalizing node signatures in transfer: ${error}`);
25033
25033
  }
25034
25034
  }
25035
- async cancelTransfer(transfer, operatorAddress) {
25036
- const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
25037
- try {
25038
- const response = await sparkClient.cancel_transfer({
25039
- transferId: transfer.id,
25040
- senderIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
25041
- });
25042
- return response.transfer;
25043
- } catch (error) {
25044
- throw new NetworkError(
25045
- "Failed to cancel transfer",
25046
- {
25047
- method: "POST"
25048
- },
25049
- error
25050
- );
25051
- }
25052
- }
25053
25035
  async queryPendingTransfersBySender(operatorAddress) {
25054
25036
  const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
25055
25037
  try {
@@ -32383,7 +32365,6 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32383
32365
  message: e.message,
32384
32366
  stack: e.stack
32385
32367
  });
32386
- await this.cancelAllSenderInitiatedTransfers();
32387
32368
  throw new Error(`Failed to request leaves swap: ${e}`);
32388
32369
  }
32389
32370
  }
@@ -32846,6 +32827,64 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32846
32827
  });
32847
32828
  return tx.hex;
32848
32829
  }
32830
+ /**
32831
+ * Refunds a static deposit and broadcasts the transaction to the network.
32832
+ *
32833
+ * @param {Object} params - The refund parameters
32834
+ * @param {string} params.depositTransactionId - The ID of the transaction
32835
+ * @param {number} [params.outputIndex] - The index of the output
32836
+ * @param {string} params.destinationAddress - The destination address
32837
+ * @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
32838
+ * @returns {Promise<string>} The transaction ID
32839
+ */
32840
+ async refundAndBroadcastStaticDeposit({
32841
+ depositTransactionId,
32842
+ outputIndex,
32843
+ destinationAddress,
32844
+ satsPerVbyteFee
32845
+ }) {
32846
+ const txHex = await this.refundStaticDeposit({
32847
+ depositTransactionId,
32848
+ outputIndex,
32849
+ destinationAddress,
32850
+ satsPerVbyteFee
32851
+ });
32852
+ return await this.broadcastTx(txHex);
32853
+ }
32854
+ /**
32855
+ * Broadcasts a transaction to the network.
32856
+ *
32857
+ * @param {string} txHex - The hex of the transaction
32858
+ * @returns {Promise<string>} The transaction ID
32859
+ */
32860
+ async broadcastTx(txHex) {
32861
+ if (!txHex) {
32862
+ throw new ValidationError("Transaction hex cannot be empty", {
32863
+ field: "txHex"
32864
+ });
32865
+ }
32866
+ const { fetch, Headers: Headers2 } = getFetch();
32867
+ const baseUrl = this.config.getElectrsUrl();
32868
+ const headers = new Headers2();
32869
+ if (this.config.getNetwork() === 4 /* LOCAL */) {
32870
+ const localFaucet = BitcoinFaucet.getInstance();
32871
+ const response = await localFaucet.broadcastTx(txHex);
32872
+ return response;
32873
+ } else {
32874
+ if (this.config.getNetwork() === 3 /* REGTEST */) {
32875
+ const auth = btoa(
32876
+ `${ELECTRS_CREDENTIALS.username}:${ELECTRS_CREDENTIALS.password}`
32877
+ );
32878
+ headers.set("Authorization", `Basic ${auth}`);
32879
+ }
32880
+ const response = await fetch(`${baseUrl}/tx`, {
32881
+ method: "POST",
32882
+ body: txHex,
32883
+ headers
32884
+ });
32885
+ return response.text();
32886
+ }
32887
+ }
32849
32888
  async getStaticDepositSigningPayload(transactionID, outputIndex, network, requestType, creditAmountSats, sspSignature) {
32850
32889
  const encoder = new TextEncoder();
32851
32890
  const parts = [];
@@ -33584,24 +33623,6 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33584
33623
  (result) => result.status === "fulfilled" && result.value !== null
33585
33624
  ).map((result) => result.value);
33586
33625
  }
33587
- /**
33588
- * Cancels all sender-initiated transfers.
33589
- *
33590
- * @returns {Promise<void>}
33591
- * @private
33592
- */
33593
- async cancelAllSenderInitiatedTransfers() {
33594
- for (const operator of Object.values(this.config.getSigningOperators())) {
33595
- const transfers = await this.transferService.queryPendingTransfersBySender(
33596
- operator.address
33597
- );
33598
- for (const transfer of transfers.transfers) {
33599
- if (transfer.status === 0 /* TRANSFER_STATUS_SENDER_INITIATED */) {
33600
- await this.transferService.cancelTransfer(transfer, operator.address);
33601
- }
33602
- }
33603
- }
33604
- }
33605
33626
  // ***** Lightning Flow *****
33606
33627
  /**
33607
33628
  * Creates a Lightning invoice for receiving payments.
package/dist/debug.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as Bech32mTokenIdentifier, r as Bech32mTokenIdentifierData, D as DecodedSparkAddressData, L as LRC_WALLET_NETWORK, N as Network, m as NetworkToProto, l as NetworkType, c as SparkAddressData, S as SparkAddressFormat, k as bech32mDecode, u as decodeBech32mTokenIdentifier, f as decodeSparkAddress, s as encodeBech32mTokenIdentifier, e as encodeSparkAddress, d as encodeSparkAddressWithSignature, n as getNetwork, o as getNetworkFromAddress, w as getNetworkFromBech32mTokenIdentifier, j as getNetworkFromSparkAddress, q as getNetworkFromString, g as isValidPublicKey, i as isValidSparkAddress, p as protoToNetwork, t as toProtoTimestamp, v as validateSparkInvoiceFields, h as validateSparkInvoiceSignature, H as SparkWallet, b as ConfigOptions } from './spark-wallet-Dg5IRQe2.cjs';
2
- import { ab as BroadcastConfig, ac as BroadcastResult, Q as DEFAULT_FEE_SATS, M as DIRECT_TIMELOCK_OFFSET, a9 as FeeBumpTxChain, a8 as FeeBumpTxPackage, a7 as FeeRate, O as INITIAL_DIRECT_SEQUENCE, N as INITIAL_SEQUENCE, ai as LOGGER_NAMES, a5 as LeafInfo, aj as LoggerName, ak as SparkSdkLogger, P as TEST_UNILATERAL_DIRECT_SEQUENCE, T as TEST_UNILATERAL_SEQUENCE, aa as TxChain, a6 as Utxo, q as addPrivateKeys, o as addPublicKeys, b as applyAdaptorToSignature, p as applyAdditiveTweakToPublicKey, J as checkIfSelectedOutputsAreAvailable, a1 as checkIfValidSequence, z as collectResponses, c as computeTaprootKeyNoScript, ag as constructFeeBumpTx, af as constructUnilateralExitFeeBumpPackages, ae as constructUnilateralExitTxs, _ as createConnectorRefundTransactions, X as createLeafNodeTx, V as createNodeTx, W as createNodeTxs, Y as createRefundTx, Z as createRefundTxs, S as createRootTx, F as createSigningCommitment, B as createSigningNonce, U as createSplitTx, H as decodeBytesToSigningCommitment, E as decodeBytesToSigningNonce, a2 as doesLeafNeedRefresh, G as encodeSigningCommitmentToBytes, D as encodeSigningNonceToBytes, K as filterTokenBalanceForTokenIdentifier, a as generateAdaptorFromSignature, g as generateSignatureFromExistingAdaptor, $ as getCurrentTimelock, a4 as getEphemeralAnchorOutput, w as getLatestDepositTxId, a3 as getNextTransactionSequence, f as getP2TRAddressFromPkScript, e as getP2TRAddressFromPublicKey, d as getP2TRScriptFromPublicKey, h as getP2WPKHAddressFromPublicKey, A as getRandomSigningNonce, k as getSigHashFromTx, C as getSigningCommitmentFromNonce, ah as getSparkAddressFromTaproot, a0 as getTransactionSequence, L as getTransferPackageSigningPayload, n as getTxEstimatedVbytesSizeByNumberOfInputsOutputs, j as getTxFromRawTxBytes, i as getTxFromRawTxHex, l as getTxId, m as getTxIdNoReverse, ad as isEphemeralAnchorOutput, x as isTxBroadcast, u as lastKeyWithTarget, R as maybeApplyFee, y as proofOfPossessionMessageHashForDepositAddress, r as subtractPrivateKeys, s as subtractPublicKeys, I as sumAvailableTokens, t as sumOfPrivateKeys, v as validateOutboundAdaptorSignature } from './logging-D3kvES69.cjs';
1
+ import { B as Bech32mTokenIdentifier, r as Bech32mTokenIdentifierData, D as DecodedSparkAddressData, L as LRC_WALLET_NETWORK, N as Network, m as NetworkToProto, l as NetworkType, c as SparkAddressData, S as SparkAddressFormat, k as bech32mDecode, u as decodeBech32mTokenIdentifier, f as decodeSparkAddress, s as encodeBech32mTokenIdentifier, e as encodeSparkAddress, d as encodeSparkAddressWithSignature, n as getNetwork, o as getNetworkFromAddress, w as getNetworkFromBech32mTokenIdentifier, j as getNetworkFromSparkAddress, q as getNetworkFromString, g as isValidPublicKey, i as isValidSparkAddress, p as protoToNetwork, t as toProtoTimestamp, v as validateSparkInvoiceFields, h as validateSparkInvoiceSignature, H as SparkWallet, b as ConfigOptions } from './spark-wallet-Dvh1BLP6.cjs';
2
+ import { ab as BroadcastConfig, ac as BroadcastResult, Q as DEFAULT_FEE_SATS, M as DIRECT_TIMELOCK_OFFSET, a9 as FeeBumpTxChain, a8 as FeeBumpTxPackage, a7 as FeeRate, O as INITIAL_DIRECT_SEQUENCE, N as INITIAL_SEQUENCE, ai as LOGGER_NAMES, a5 as LeafInfo, aj as LoggerName, ak as SparkSdkLogger, P as TEST_UNILATERAL_DIRECT_SEQUENCE, T as TEST_UNILATERAL_SEQUENCE, aa as TxChain, a6 as Utxo, q as addPrivateKeys, o as addPublicKeys, b as applyAdaptorToSignature, p as applyAdditiveTweakToPublicKey, J as checkIfSelectedOutputsAreAvailable, a1 as checkIfValidSequence, z as collectResponses, c as computeTaprootKeyNoScript, ag as constructFeeBumpTx, af as constructUnilateralExitFeeBumpPackages, ae as constructUnilateralExitTxs, _ as createConnectorRefundTransactions, X as createLeafNodeTx, V as createNodeTx, W as createNodeTxs, Y as createRefundTx, Z as createRefundTxs, S as createRootTx, F as createSigningCommitment, B as createSigningNonce, U as createSplitTx, H as decodeBytesToSigningCommitment, E as decodeBytesToSigningNonce, a2 as doesLeafNeedRefresh, G as encodeSigningCommitmentToBytes, D as encodeSigningNonceToBytes, K as filterTokenBalanceForTokenIdentifier, a as generateAdaptorFromSignature, g as generateSignatureFromExistingAdaptor, $ as getCurrentTimelock, a4 as getEphemeralAnchorOutput, w as getLatestDepositTxId, a3 as getNextTransactionSequence, f as getP2TRAddressFromPkScript, e as getP2TRAddressFromPublicKey, d as getP2TRScriptFromPublicKey, h as getP2WPKHAddressFromPublicKey, A as getRandomSigningNonce, k as getSigHashFromTx, C as getSigningCommitmentFromNonce, ah as getSparkAddressFromTaproot, a0 as getTransactionSequence, L as getTransferPackageSigningPayload, n as getTxEstimatedVbytesSizeByNumberOfInputsOutputs, j as getTxFromRawTxBytes, i as getTxFromRawTxHex, l as getTxId, m as getTxIdNoReverse, ad as isEphemeralAnchorOutput, x as isTxBroadcast, u as lastKeyWithTarget, R as maybeApplyFee, y as proofOfPossessionMessageHashForDepositAddress, r as subtractPrivateKeys, s as subtractPublicKeys, I as sumAvailableTokens, t as sumOfPrivateKeys, v as validateOutboundAdaptorSignature } from './logging-BfTyKwqb.cjs';
3
3
  import { V as VerifiableSecretShare, h as bigIntToPrivateKey, c as computerLagrangeCoefficients, e as evaluatePolynomial, f as fieldDiv, b as generatePolynomialForSecretSharing, g as getRandomBigInt, m as modInverse, r as recoverSecret, s as splitSecret, d as splitSecretWithProofs, v as validateShare } from './client-DVuA5-7M.cjs';
4
4
  import './spark-C7OG9mGJ.cjs';
5
5
  import '@bufbuild/protobuf/wire';