@buildonspark/spark-sdk 0.2.11 → 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 (102) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/bare/index.cjs +761 -243
  3. package/dist/bare/index.d.cts +70 -11
  4. package/dist/bare/index.d.ts +70 -11
  5. package/dist/bare/index.js +684 -170
  6. package/dist/{chunk-A5M55UR3.js → chunk-5VWGOHED.js} +499 -8
  7. package/dist/{chunk-3WBPICWC.js → chunk-CKHJFQUA.js} +1 -1
  8. package/dist/{chunk-QNYJGFPD.js → chunk-LX45BCZW.js} +207 -160
  9. package/dist/{chunk-76SYPHOC.js → chunk-TB7DG5CU.js} +2 -2
  10. package/dist/{chunk-6CMNEDBK.js → chunk-XXTWWW6L.js} +1 -1
  11. package/dist/{client-Dd3QnxQu.d.ts → client-D7KDa4Ih.d.ts} +1 -1
  12. package/dist/{client-B9CAWKWz.d.cts → client-DVuA5-7M.d.cts} +1 -1
  13. package/dist/debug.cjs +761 -243
  14. package/dist/debug.d.cts +4 -4
  15. package/dist/debug.d.ts +4 -4
  16. package/dist/debug.js +4 -4
  17. package/dist/graphql/objects/index.d.cts +3 -3
  18. package/dist/graphql/objects/index.d.ts +3 -3
  19. package/dist/index.cjs +783 -265
  20. package/dist/index.d.cts +6 -6
  21. package/dist/index.d.ts +6 -6
  22. package/dist/index.js +5 -5
  23. package/dist/index.node.cjs +783 -265
  24. package/dist/index.node.d.cts +6 -6
  25. package/dist/index.node.d.ts +6 -6
  26. package/dist/index.node.js +4 -4
  27. package/dist/{logging-BOAzMqpM.d.cts → logging-BfTyKwqb.d.cts} +3 -3
  28. package/dist/{logging-Bt_WdZbu.d.ts → logging-CaNpBgiE.d.ts} +3 -3
  29. package/dist/native/index.cjs +782 -264
  30. package/dist/native/index.d.cts +70 -11
  31. package/dist/native/index.d.ts +70 -11
  32. package/dist/native/index.js +686 -172
  33. package/dist/proto/spark.cjs +499 -8
  34. package/dist/proto/spark.d.cts +1 -1
  35. package/dist/proto/spark.d.ts +1 -1
  36. package/dist/proto/spark.js +17 -1
  37. package/dist/proto/spark_token.d.cts +1 -1
  38. package/dist/proto/spark_token.d.ts +1 -1
  39. package/dist/proto/spark_token.js +2 -2
  40. package/dist/{spark-CtGJPkx4.d.cts → spark-C7OG9mGJ.d.cts} +79 -2
  41. package/dist/{spark-CtGJPkx4.d.ts → spark-C7OG9mGJ.d.ts} +79 -2
  42. package/dist/{spark-wallet-Cp3yv6cK.d.ts → spark-wallet-D0Df_P_x.d.ts} +26 -13
  43. package/dist/{spark-wallet-yc2KhsVY.d.cts → spark-wallet-Dvh1BLP6.d.cts} +26 -13
  44. package/dist/{spark-wallet.node-D0Qw5Wb4.d.cts → spark-wallet.node-B3V8_fgw.d.cts} +1 -1
  45. package/dist/{spark-wallet.node-D4IovOHu.d.ts → spark-wallet.node-bGmy8-T8.d.ts} +1 -1
  46. package/dist/tests/test-utils.cjs +573 -66
  47. package/dist/tests/test-utils.d.cts +4 -4
  48. package/dist/tests/test-utils.d.ts +4 -4
  49. package/dist/tests/test-utils.js +5 -5
  50. package/dist/{token-transactions-CwhlOgIP.d.cts → token-transactions-D1ta-sHH.d.cts} +2 -2
  51. package/dist/{token-transactions-0nmR9mQO.d.ts → token-transactions-DINiKBzd.d.ts} +2 -2
  52. package/dist/types/index.cjs +492 -9
  53. package/dist/types/index.d.cts +2 -2
  54. package/dist/types/index.d.ts +2 -2
  55. package/dist/types/index.js +2 -2
  56. package/package.json +3 -3
  57. package/src/proto/common.ts +1 -1
  58. package/src/proto/google/protobuf/descriptor.ts +4 -10
  59. package/src/proto/google/protobuf/duration.ts +1 -1
  60. package/src/proto/google/protobuf/empty.ts +1 -1
  61. package/src/proto/google/protobuf/timestamp.ts +1 -1
  62. package/src/proto/mock.ts +1 -1
  63. package/src/proto/spark.ts +593 -3
  64. package/src/proto/spark_authn.ts +1 -1
  65. package/src/proto/spark_token.ts +1 -1
  66. package/src/proto/validate/validate.ts +27 -79
  67. package/src/services/deposit.ts +55 -3
  68. package/src/services/lightning.ts +2 -2
  69. package/src/services/signing.ts +1 -1
  70. package/src/services/token-transactions.ts +2 -5
  71. package/src/services/transfer.ts +2 -28
  72. package/src/signer/signer.ts +2 -2
  73. package/src/spark-wallet/proto-descriptors.ts +22 -0
  74. package/src/spark-wallet/proto-hash.ts +743 -0
  75. package/src/spark-wallet/proto-reflection.ts +193 -0
  76. package/src/spark-wallet/spark-wallet.ts +95 -57
  77. package/src/spark_descriptors.pb +0 -0
  78. package/src/tests/address.test.ts +10 -10
  79. package/src/tests/bitcoin.test.ts +2 -2
  80. package/src/tests/bufbuild-reflection.test.ts +151 -0
  81. package/src/tests/cross-language-hash.test.ts +79 -0
  82. package/src/tests/integration/address.test.ts +3 -12
  83. package/src/tests/integration/coop-exit.test.ts +1 -1
  84. package/src/tests/integration/lightning.test.ts +1 -1
  85. package/src/tests/integration/ssp/static_deposit.test.ts +128 -1
  86. package/src/tests/integration/static_deposit.test.ts +26 -0
  87. package/src/tests/integration/swap.test.ts +1 -1
  88. package/src/tests/integration/transfer.test.ts +1 -129
  89. package/src/tests/integration/wallet.test.ts +7 -7
  90. package/src/tests/integration/watchtower.test.ts +1 -1
  91. package/src/tests/token-hashing.test.ts +3 -6
  92. package/src/tests/token-outputs.test.ts +3 -3
  93. package/src/tests/utils/test-faucet.ts +2 -2
  94. package/src/types/sdk-types.ts +1 -1
  95. package/src/utils/adaptor-signature.ts +1 -1
  96. package/src/utils/address.ts +1 -1
  97. package/src/utils/bitcoin.ts +1 -5
  98. package/src/utils/keys.ts +1 -1
  99. package/src/utils/secret-sharing.ts +1 -1
  100. package/src/utils/token-transactions.ts +1 -2
  101. package/src/utils/transfer_package.ts +1 -1
  102. package/src/utils/unilateral-exit.ts +1 -1
@@ -162,14 +162,14 @@ var NotImplementedError = class extends SparkSDKError {
162
162
 
163
163
  // src/spark-wallet/spark-wallet.ts
164
164
  import { isNode as isNode3, isObject as isObject10, mapCurrencyAmount } from "@lightsparkdev/core";
165
+ import { secp256k1 as secp256k114 } from "@noble/curves/secp256k1";
165
166
  import {
166
- bytesToHex as bytesToHex12,
167
+ bytesToHex as bytesToHex11,
167
168
  bytesToNumberBE as bytesToNumberBE8,
168
169
  equalBytes as equalBytes6,
169
170
  hexToBytes as hexToBytes11,
170
171
  numberToVarBytesBE
171
- } from "@noble/curves/abstract/utils";
172
- import { secp256k1 as secp256k114 } from "@noble/curves/secp256k1";
172
+ } from "@noble/curves/utils";
173
173
  import { validateMnemonic } from "@scure/bip39";
174
174
  import { wordlist as wordlist2 } from "@scure/bip39/wordlists/english";
175
175
  import { Address as Address4, OutScript as OutScript3, Transaction as Transaction7 } from "@scure/btc-signer";
@@ -2748,6 +2748,41 @@ function utxoSwapRequestTypeToJSON(object) {
2748
2748
  return "UNRECOGNIZED";
2749
2749
  }
2750
2750
  }
2751
+ function invoiceStatusFromJSON(object) {
2752
+ switch (object) {
2753
+ case 0:
2754
+ case "NOT_FOUND":
2755
+ return 0 /* NOT_FOUND */;
2756
+ case 1:
2757
+ case "PENDING":
2758
+ return 1 /* PENDING */;
2759
+ case 2:
2760
+ case "FINALIZED":
2761
+ return 2 /* FINALIZED */;
2762
+ case 3:
2763
+ case "EXPIRED":
2764
+ return 3 /* EXPIRED */;
2765
+ case -1:
2766
+ case "UNRECOGNIZED":
2767
+ default:
2768
+ return -1 /* UNRECOGNIZED */;
2769
+ }
2770
+ }
2771
+ function invoiceStatusToJSON(object) {
2772
+ switch (object) {
2773
+ case 0 /* NOT_FOUND */:
2774
+ return "NOT_FOUND";
2775
+ case 1 /* PENDING */:
2776
+ return "PENDING";
2777
+ case 2 /* FINALIZED */:
2778
+ return "FINALIZED";
2779
+ case 3 /* EXPIRED */:
2780
+ return "EXPIRED";
2781
+ case -1 /* UNRECOGNIZED */:
2782
+ default:
2783
+ return "UNRECOGNIZED";
2784
+ }
2785
+ }
2751
2786
  function initiatePreimageSwapRequest_ReasonFromJSON(object) {
2752
2787
  switch (object) {
2753
2788
  case 0:
@@ -3487,6 +3522,140 @@ var GenerateDepositAddressResponse = {
3487
3522
  return message;
3488
3523
  }
3489
3524
  };
3525
+ function createBaseGenerateStaticDepositAddressRequest() {
3526
+ return { signingPublicKey: new Uint8Array(0), identityPublicKey: new Uint8Array(0), network: 0 };
3527
+ }
3528
+ var GenerateStaticDepositAddressRequest = {
3529
+ encode(message, writer = new BinaryWriter4()) {
3530
+ if (message.signingPublicKey.length !== 0) {
3531
+ writer.uint32(10).bytes(message.signingPublicKey);
3532
+ }
3533
+ if (message.identityPublicKey.length !== 0) {
3534
+ writer.uint32(18).bytes(message.identityPublicKey);
3535
+ }
3536
+ if (message.network !== 0) {
3537
+ writer.uint32(24).int32(message.network);
3538
+ }
3539
+ return writer;
3540
+ },
3541
+ decode(input, length) {
3542
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
3543
+ const end = length === void 0 ? reader.len : reader.pos + length;
3544
+ const message = createBaseGenerateStaticDepositAddressRequest();
3545
+ while (reader.pos < end) {
3546
+ const tag = reader.uint32();
3547
+ switch (tag >>> 3) {
3548
+ case 1: {
3549
+ if (tag !== 10) {
3550
+ break;
3551
+ }
3552
+ message.signingPublicKey = reader.bytes();
3553
+ continue;
3554
+ }
3555
+ case 2: {
3556
+ if (tag !== 18) {
3557
+ break;
3558
+ }
3559
+ message.identityPublicKey = reader.bytes();
3560
+ continue;
3561
+ }
3562
+ case 3: {
3563
+ if (tag !== 24) {
3564
+ break;
3565
+ }
3566
+ message.network = reader.int32();
3567
+ continue;
3568
+ }
3569
+ }
3570
+ if ((tag & 7) === 4 || tag === 0) {
3571
+ break;
3572
+ }
3573
+ reader.skip(tag & 7);
3574
+ }
3575
+ return message;
3576
+ },
3577
+ fromJSON(object) {
3578
+ return {
3579
+ signingPublicKey: isSet3(object.signingPublicKey) ? bytesFromBase642(object.signingPublicKey) : new Uint8Array(0),
3580
+ identityPublicKey: isSet3(object.identityPublicKey) ? bytesFromBase642(object.identityPublicKey) : new Uint8Array(0),
3581
+ network: isSet3(object.network) ? networkFromJSON(object.network) : 0
3582
+ };
3583
+ },
3584
+ toJSON(message) {
3585
+ const obj = {};
3586
+ if (message.signingPublicKey.length !== 0) {
3587
+ obj.signingPublicKey = base64FromBytes2(message.signingPublicKey);
3588
+ }
3589
+ if (message.identityPublicKey.length !== 0) {
3590
+ obj.identityPublicKey = base64FromBytes2(message.identityPublicKey);
3591
+ }
3592
+ if (message.network !== 0) {
3593
+ obj.network = networkToJSON(message.network);
3594
+ }
3595
+ return obj;
3596
+ },
3597
+ create(base) {
3598
+ return GenerateStaticDepositAddressRequest.fromPartial(base ?? {});
3599
+ },
3600
+ fromPartial(object) {
3601
+ const message = createBaseGenerateStaticDepositAddressRequest();
3602
+ message.signingPublicKey = object.signingPublicKey ?? new Uint8Array(0);
3603
+ message.identityPublicKey = object.identityPublicKey ?? new Uint8Array(0);
3604
+ message.network = object.network ?? 0;
3605
+ return message;
3606
+ }
3607
+ };
3608
+ function createBaseGenerateStaticDepositAddressResponse() {
3609
+ return { depositAddress: void 0 };
3610
+ }
3611
+ var GenerateStaticDepositAddressResponse = {
3612
+ encode(message, writer = new BinaryWriter4()) {
3613
+ if (message.depositAddress !== void 0) {
3614
+ Address.encode(message.depositAddress, writer.uint32(10).fork()).join();
3615
+ }
3616
+ return writer;
3617
+ },
3618
+ decode(input, length) {
3619
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
3620
+ const end = length === void 0 ? reader.len : reader.pos + length;
3621
+ const message = createBaseGenerateStaticDepositAddressResponse();
3622
+ while (reader.pos < end) {
3623
+ const tag = reader.uint32();
3624
+ switch (tag >>> 3) {
3625
+ case 1: {
3626
+ if (tag !== 10) {
3627
+ break;
3628
+ }
3629
+ message.depositAddress = Address.decode(reader, reader.uint32());
3630
+ continue;
3631
+ }
3632
+ }
3633
+ if ((tag & 7) === 4 || tag === 0) {
3634
+ break;
3635
+ }
3636
+ reader.skip(tag & 7);
3637
+ }
3638
+ return message;
3639
+ },
3640
+ fromJSON(object) {
3641
+ return { depositAddress: isSet3(object.depositAddress) ? Address.fromJSON(object.depositAddress) : void 0 };
3642
+ },
3643
+ toJSON(message) {
3644
+ const obj = {};
3645
+ if (message.depositAddress !== void 0) {
3646
+ obj.depositAddress = Address.toJSON(message.depositAddress);
3647
+ }
3648
+ return obj;
3649
+ },
3650
+ create(base) {
3651
+ return GenerateStaticDepositAddressResponse.fromPartial(base ?? {});
3652
+ },
3653
+ fromPartial(object) {
3654
+ const message = createBaseGenerateStaticDepositAddressResponse();
3655
+ message.depositAddress = object.depositAddress !== void 0 && object.depositAddress !== null ? Address.fromPartial(object.depositAddress) : void 0;
3656
+ return message;
3657
+ }
3658
+ };
3490
3659
  function createBaseUTXO() {
3491
3660
  return { rawTx: new Uint8Array(0), vout: 0, network: 0, txid: new Uint8Array(0) };
3492
3661
  }
@@ -9600,7 +9769,8 @@ function createBaseTransferLeaf() {
9600
9769
  signature: new Uint8Array(0),
9601
9770
  intermediateRefundTx: new Uint8Array(0),
9602
9771
  intermediateDirectRefundTx: new Uint8Array(0),
9603
- intermediateDirectFromCpfpRefundTx: new Uint8Array(0)
9772
+ intermediateDirectFromCpfpRefundTx: new Uint8Array(0),
9773
+ pendingKeyTweakPublicKey: new Uint8Array(0)
9604
9774
  };
9605
9775
  }
9606
9776
  var TransferLeaf = {
@@ -9623,6 +9793,9 @@ var TransferLeaf = {
9623
9793
  if (message.intermediateDirectFromCpfpRefundTx.length !== 0) {
9624
9794
  writer.uint32(50).bytes(message.intermediateDirectFromCpfpRefundTx);
9625
9795
  }
9796
+ if (message.pendingKeyTweakPublicKey.length !== 0) {
9797
+ writer.uint32(58).bytes(message.pendingKeyTweakPublicKey);
9798
+ }
9626
9799
  return writer;
9627
9800
  },
9628
9801
  decode(input, length) {
@@ -9674,6 +9847,13 @@ var TransferLeaf = {
9674
9847
  message.intermediateDirectFromCpfpRefundTx = reader.bytes();
9675
9848
  continue;
9676
9849
  }
9850
+ case 7: {
9851
+ if (tag !== 58) {
9852
+ break;
9853
+ }
9854
+ message.pendingKeyTweakPublicKey = reader.bytes();
9855
+ continue;
9856
+ }
9677
9857
  }
9678
9858
  if ((tag & 7) === 4 || tag === 0) {
9679
9859
  break;
@@ -9689,7 +9869,8 @@ var TransferLeaf = {
9689
9869
  signature: isSet3(object.signature) ? bytesFromBase642(object.signature) : new Uint8Array(0),
9690
9870
  intermediateRefundTx: isSet3(object.intermediateRefundTx) ? bytesFromBase642(object.intermediateRefundTx) : new Uint8Array(0),
9691
9871
  intermediateDirectRefundTx: isSet3(object.intermediateDirectRefundTx) ? bytesFromBase642(object.intermediateDirectRefundTx) : new Uint8Array(0),
9692
- intermediateDirectFromCpfpRefundTx: isSet3(object.intermediateDirectFromCpfpRefundTx) ? bytesFromBase642(object.intermediateDirectFromCpfpRefundTx) : new Uint8Array(0)
9872
+ intermediateDirectFromCpfpRefundTx: isSet3(object.intermediateDirectFromCpfpRefundTx) ? bytesFromBase642(object.intermediateDirectFromCpfpRefundTx) : new Uint8Array(0),
9873
+ pendingKeyTweakPublicKey: isSet3(object.pendingKeyTweakPublicKey) ? bytesFromBase642(object.pendingKeyTweakPublicKey) : new Uint8Array(0)
9693
9874
  };
9694
9875
  },
9695
9876
  toJSON(message) {
@@ -9712,6 +9893,9 @@ var TransferLeaf = {
9712
9893
  if (message.intermediateDirectFromCpfpRefundTx.length !== 0) {
9713
9894
  obj.intermediateDirectFromCpfpRefundTx = base64FromBytes2(message.intermediateDirectFromCpfpRefundTx);
9714
9895
  }
9896
+ if (message.pendingKeyTweakPublicKey.length !== 0) {
9897
+ obj.pendingKeyTweakPublicKey = base64FromBytes2(message.pendingKeyTweakPublicKey);
9898
+ }
9715
9899
  return obj;
9716
9900
  },
9717
9901
  create(base) {
@@ -9725,6 +9909,7 @@ var TransferLeaf = {
9725
9909
  message.intermediateRefundTx = object.intermediateRefundTx ?? new Uint8Array(0);
9726
9910
  message.intermediateDirectRefundTx = object.intermediateDirectRefundTx ?? new Uint8Array(0);
9727
9911
  message.intermediateDirectFromCpfpRefundTx = object.intermediateDirectFromCpfpRefundTx ?? new Uint8Array(0);
9912
+ message.pendingKeyTweakPublicKey = object.pendingKeyTweakPublicKey ?? new Uint8Array(0);
9728
9913
  return message;
9729
9914
  }
9730
9915
  };
@@ -12622,13 +12807,16 @@ var QueryUserSignedRefundsRequest = {
12622
12807
  }
12623
12808
  };
12624
12809
  function createBaseQueryUserSignedRefundsResponse() {
12625
- return { userSignedRefunds: [] };
12810
+ return { userSignedRefunds: [], transfer: void 0 };
12626
12811
  }
12627
12812
  var QueryUserSignedRefundsResponse = {
12628
12813
  encode(message, writer = new BinaryWriter4()) {
12629
12814
  for (const v of message.userSignedRefunds) {
12630
12815
  UserSignedRefund.encode(v, writer.uint32(10).fork()).join();
12631
12816
  }
12817
+ if (message.transfer !== void 0) {
12818
+ Transfer6.encode(message.transfer, writer.uint32(26).fork()).join();
12819
+ }
12632
12820
  return writer;
12633
12821
  },
12634
12822
  decode(input, length) {
@@ -12645,6 +12833,13 @@ var QueryUserSignedRefundsResponse = {
12645
12833
  message.userSignedRefunds.push(UserSignedRefund.decode(reader, reader.uint32()));
12646
12834
  continue;
12647
12835
  }
12836
+ case 3: {
12837
+ if (tag !== 26) {
12838
+ break;
12839
+ }
12840
+ message.transfer = Transfer6.decode(reader, reader.uint32());
12841
+ continue;
12842
+ }
12648
12843
  }
12649
12844
  if ((tag & 7) === 4 || tag === 0) {
12650
12845
  break;
@@ -12655,7 +12850,8 @@ var QueryUserSignedRefundsResponse = {
12655
12850
  },
12656
12851
  fromJSON(object) {
12657
12852
  return {
12658
- userSignedRefunds: globalThis.Array.isArray(object?.userSignedRefunds) ? object.userSignedRefunds.map((e) => UserSignedRefund.fromJSON(e)) : []
12853
+ userSignedRefunds: globalThis.Array.isArray(object?.userSignedRefunds) ? object.userSignedRefunds.map((e) => UserSignedRefund.fromJSON(e)) : [],
12854
+ transfer: isSet3(object.transfer) ? Transfer6.fromJSON(object.transfer) : void 0
12659
12855
  };
12660
12856
  },
12661
12857
  toJSON(message) {
@@ -12663,6 +12859,9 @@ var QueryUserSignedRefundsResponse = {
12663
12859
  if (message.userSignedRefunds?.length) {
12664
12860
  obj.userSignedRefunds = message.userSignedRefunds.map((e) => UserSignedRefund.toJSON(e));
12665
12861
  }
12862
+ if (message.transfer !== void 0) {
12863
+ obj.transfer = Transfer6.toJSON(message.transfer);
12864
+ }
12666
12865
  return obj;
12667
12866
  },
12668
12867
  create(base) {
@@ -12671,6 +12870,7 @@ var QueryUserSignedRefundsResponse = {
12671
12870
  fromPartial(object) {
12672
12871
  const message = createBaseQueryUserSignedRefundsResponse();
12673
12872
  message.userSignedRefunds = object.userSignedRefunds?.map((e) => UserSignedRefund.fromPartial(e)) || [];
12873
+ message.transfer = object.transfer !== void 0 && object.transfer !== null ? Transfer6.fromPartial(object.transfer) : void 0;
12674
12874
  return message;
12675
12875
  }
12676
12876
  };
@@ -13557,7 +13757,8 @@ function createBaseDepositAddressQueryResult() {
13557
13757
  depositAddress: "",
13558
13758
  userSigningPublicKey: new Uint8Array(0),
13559
13759
  verifyingPublicKey: new Uint8Array(0),
13560
- leafId: void 0
13760
+ leafId: void 0,
13761
+ proofOfPossession: void 0
13561
13762
  };
13562
13763
  }
13563
13764
  var DepositAddressQueryResult = {
@@ -13574,6 +13775,9 @@ var DepositAddressQueryResult = {
13574
13775
  if (message.leafId !== void 0) {
13575
13776
  writer.uint32(34).string(message.leafId);
13576
13777
  }
13778
+ if (message.proofOfPossession !== void 0) {
13779
+ DepositAddressProof.encode(message.proofOfPossession, writer.uint32(42).fork()).join();
13780
+ }
13577
13781
  return writer;
13578
13782
  },
13579
13783
  decode(input, length) {
@@ -13611,6 +13815,13 @@ var DepositAddressQueryResult = {
13611
13815
  message.leafId = reader.string();
13612
13816
  continue;
13613
13817
  }
13818
+ case 5: {
13819
+ if (tag !== 42) {
13820
+ break;
13821
+ }
13822
+ message.proofOfPossession = DepositAddressProof.decode(reader, reader.uint32());
13823
+ continue;
13824
+ }
13614
13825
  }
13615
13826
  if ((tag & 7) === 4 || tag === 0) {
13616
13827
  break;
@@ -13624,7 +13835,8 @@ var DepositAddressQueryResult = {
13624
13835
  depositAddress: isSet3(object.depositAddress) ? globalThis.String(object.depositAddress) : "",
13625
13836
  userSigningPublicKey: isSet3(object.userSigningPublicKey) ? bytesFromBase642(object.userSigningPublicKey) : new Uint8Array(0),
13626
13837
  verifyingPublicKey: isSet3(object.verifyingPublicKey) ? bytesFromBase642(object.verifyingPublicKey) : new Uint8Array(0),
13627
- leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : void 0
13838
+ leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : void 0,
13839
+ proofOfPossession: isSet3(object.proofOfPossession) ? DepositAddressProof.fromJSON(object.proofOfPossession) : void 0
13628
13840
  };
13629
13841
  },
13630
13842
  toJSON(message) {
@@ -13641,6 +13853,9 @@ var DepositAddressQueryResult = {
13641
13853
  if (message.leafId !== void 0) {
13642
13854
  obj.leafId = message.leafId;
13643
13855
  }
13856
+ if (message.proofOfPossession !== void 0) {
13857
+ obj.proofOfPossession = DepositAddressProof.toJSON(message.proofOfPossession);
13858
+ }
13644
13859
  return obj;
13645
13860
  },
13646
13861
  create(base) {
@@ -13652,6 +13867,7 @@ var DepositAddressQueryResult = {
13652
13867
  message.userSigningPublicKey = object.userSigningPublicKey ?? new Uint8Array(0);
13653
13868
  message.verifyingPublicKey = object.verifyingPublicKey ?? new Uint8Array(0);
13654
13869
  message.leafId = object.leafId ?? void 0;
13870
+ message.proofOfPossession = object.proofOfPossession !== void 0 && object.proofOfPossession !== null ? DepositAddressProof.fromPartial(object.proofOfPossession) : void 0;
13655
13871
  return message;
13656
13872
  }
13657
13873
  };
@@ -15616,7 +15832,7 @@ var QueryNodesByValueResponse_NodesEntry = {
15616
15832
  }
15617
15833
  };
15618
15834
  function createBaseGetUtxosForAddressRequest() {
15619
- return { address: "", offset: 0, limit: 0, network: 0 };
15835
+ return { address: "", offset: 0, limit: 0, network: 0, excludeClaimed: false };
15620
15836
  }
15621
15837
  var GetUtxosForAddressRequest = {
15622
15838
  encode(message, writer = new BinaryWriter4()) {
@@ -15632,6 +15848,9 @@ var GetUtxosForAddressRequest = {
15632
15848
  if (message.network !== 0) {
15633
15849
  writer.uint32(32).int32(message.network);
15634
15850
  }
15851
+ if (message.excludeClaimed !== false) {
15852
+ writer.uint32(40).bool(message.excludeClaimed);
15853
+ }
15635
15854
  return writer;
15636
15855
  },
15637
15856
  decode(input, length) {
@@ -15669,6 +15888,13 @@ var GetUtxosForAddressRequest = {
15669
15888
  message.network = reader.int32();
15670
15889
  continue;
15671
15890
  }
15891
+ case 5: {
15892
+ if (tag !== 40) {
15893
+ break;
15894
+ }
15895
+ message.excludeClaimed = reader.bool();
15896
+ continue;
15897
+ }
15672
15898
  }
15673
15899
  if ((tag & 7) === 4 || tag === 0) {
15674
15900
  break;
@@ -15682,7 +15908,8 @@ var GetUtxosForAddressRequest = {
15682
15908
  address: isSet3(object.address) ? globalThis.String(object.address) : "",
15683
15909
  offset: isSet3(object.offset) ? globalThis.Number(object.offset) : 0,
15684
15910
  limit: isSet3(object.limit) ? globalThis.Number(object.limit) : 0,
15685
- network: isSet3(object.network) ? networkFromJSON(object.network) : 0
15911
+ network: isSet3(object.network) ? networkFromJSON(object.network) : 0,
15912
+ excludeClaimed: isSet3(object.excludeClaimed) ? globalThis.Boolean(object.excludeClaimed) : false
15686
15913
  };
15687
15914
  },
15688
15915
  toJSON(message) {
@@ -15699,6 +15926,9 @@ var GetUtxosForAddressRequest = {
15699
15926
  if (message.network !== 0) {
15700
15927
  obj.network = networkToJSON(message.network);
15701
15928
  }
15929
+ if (message.excludeClaimed !== false) {
15930
+ obj.excludeClaimed = message.excludeClaimed;
15931
+ }
15702
15932
  return obj;
15703
15933
  },
15704
15934
  create(base) {
@@ -15710,6 +15940,7 @@ var GetUtxosForAddressRequest = {
15710
15940
  message.offset = object.offset ?? 0;
15711
15941
  message.limit = object.limit ?? 0;
15712
15942
  message.network = object.network ?? 0;
15943
+ message.excludeClaimed = object.excludeClaimed ?? false;
15713
15944
  return message;
15714
15945
  }
15715
15946
  };
@@ -15781,6 +16012,225 @@ var GetUtxosForAddressResponse = {
15781
16012
  return message;
15782
16013
  }
15783
16014
  };
16015
+ function createBaseQuerySparkInvoicesRequest() {
16016
+ return { limit: 0, offset: 0, invoice: [] };
16017
+ }
16018
+ var QuerySparkInvoicesRequest = {
16019
+ encode(message, writer = new BinaryWriter4()) {
16020
+ if (message.limit !== 0) {
16021
+ writer.uint32(8).int64(message.limit);
16022
+ }
16023
+ if (message.offset !== 0) {
16024
+ writer.uint32(16).int64(message.offset);
16025
+ }
16026
+ for (const v of message.invoice) {
16027
+ writer.uint32(26).string(v);
16028
+ }
16029
+ return writer;
16030
+ },
16031
+ decode(input, length) {
16032
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
16033
+ const end = length === void 0 ? reader.len : reader.pos + length;
16034
+ const message = createBaseQuerySparkInvoicesRequest();
16035
+ while (reader.pos < end) {
16036
+ const tag = reader.uint32();
16037
+ switch (tag >>> 3) {
16038
+ case 1: {
16039
+ if (tag !== 8) {
16040
+ break;
16041
+ }
16042
+ message.limit = longToNumber2(reader.int64());
16043
+ continue;
16044
+ }
16045
+ case 2: {
16046
+ if (tag !== 16) {
16047
+ break;
16048
+ }
16049
+ message.offset = longToNumber2(reader.int64());
16050
+ continue;
16051
+ }
16052
+ case 3: {
16053
+ if (tag !== 26) {
16054
+ break;
16055
+ }
16056
+ message.invoice.push(reader.string());
16057
+ continue;
16058
+ }
16059
+ }
16060
+ if ((tag & 7) === 4 || tag === 0) {
16061
+ break;
16062
+ }
16063
+ reader.skip(tag & 7);
16064
+ }
16065
+ return message;
16066
+ },
16067
+ fromJSON(object) {
16068
+ return {
16069
+ limit: isSet3(object.limit) ? globalThis.Number(object.limit) : 0,
16070
+ offset: isSet3(object.offset) ? globalThis.Number(object.offset) : 0,
16071
+ invoice: globalThis.Array.isArray(object?.invoice) ? object.invoice.map((e) => globalThis.String(e)) : []
16072
+ };
16073
+ },
16074
+ toJSON(message) {
16075
+ const obj = {};
16076
+ if (message.limit !== 0) {
16077
+ obj.limit = Math.round(message.limit);
16078
+ }
16079
+ if (message.offset !== 0) {
16080
+ obj.offset = Math.round(message.offset);
16081
+ }
16082
+ if (message.invoice?.length) {
16083
+ obj.invoice = message.invoice;
16084
+ }
16085
+ return obj;
16086
+ },
16087
+ create(base) {
16088
+ return QuerySparkInvoicesRequest.fromPartial(base ?? {});
16089
+ },
16090
+ fromPartial(object) {
16091
+ const message = createBaseQuerySparkInvoicesRequest();
16092
+ message.limit = object.limit ?? 0;
16093
+ message.offset = object.offset ?? 0;
16094
+ message.invoice = object.invoice?.map((e) => e) || [];
16095
+ return message;
16096
+ }
16097
+ };
16098
+ function createBaseQuerySparkInvoicesResponse() {
16099
+ return { offset: 0, invoiceStatuses: [] };
16100
+ }
16101
+ var QuerySparkInvoicesResponse = {
16102
+ encode(message, writer = new BinaryWriter4()) {
16103
+ if (message.offset !== 0) {
16104
+ writer.uint32(8).int64(message.offset);
16105
+ }
16106
+ for (const v of message.invoiceStatuses) {
16107
+ InvoiceResponse.encode(v, writer.uint32(18).fork()).join();
16108
+ }
16109
+ return writer;
16110
+ },
16111
+ decode(input, length) {
16112
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
16113
+ const end = length === void 0 ? reader.len : reader.pos + length;
16114
+ const message = createBaseQuerySparkInvoicesResponse();
16115
+ while (reader.pos < end) {
16116
+ const tag = reader.uint32();
16117
+ switch (tag >>> 3) {
16118
+ case 1: {
16119
+ if (tag !== 8) {
16120
+ break;
16121
+ }
16122
+ message.offset = longToNumber2(reader.int64());
16123
+ continue;
16124
+ }
16125
+ case 2: {
16126
+ if (tag !== 18) {
16127
+ break;
16128
+ }
16129
+ message.invoiceStatuses.push(InvoiceResponse.decode(reader, reader.uint32()));
16130
+ continue;
16131
+ }
16132
+ }
16133
+ if ((tag & 7) === 4 || tag === 0) {
16134
+ break;
16135
+ }
16136
+ reader.skip(tag & 7);
16137
+ }
16138
+ return message;
16139
+ },
16140
+ fromJSON(object) {
16141
+ return {
16142
+ offset: isSet3(object.offset) ? globalThis.Number(object.offset) : 0,
16143
+ invoiceStatuses: globalThis.Array.isArray(object?.invoiceStatuses) ? object.invoiceStatuses.map((e) => InvoiceResponse.fromJSON(e)) : []
16144
+ };
16145
+ },
16146
+ toJSON(message) {
16147
+ const obj = {};
16148
+ if (message.offset !== 0) {
16149
+ obj.offset = Math.round(message.offset);
16150
+ }
16151
+ if (message.invoiceStatuses?.length) {
16152
+ obj.invoiceStatuses = message.invoiceStatuses.map((e) => InvoiceResponse.toJSON(e));
16153
+ }
16154
+ return obj;
16155
+ },
16156
+ create(base) {
16157
+ return QuerySparkInvoicesResponse.fromPartial(base ?? {});
16158
+ },
16159
+ fromPartial(object) {
16160
+ const message = createBaseQuerySparkInvoicesResponse();
16161
+ message.offset = object.offset ?? 0;
16162
+ message.invoiceStatuses = object.invoiceStatuses?.map((e) => InvoiceResponse.fromPartial(e)) || [];
16163
+ return message;
16164
+ }
16165
+ };
16166
+ function createBaseInvoiceResponse() {
16167
+ return { invoice: "", status: 0 };
16168
+ }
16169
+ var InvoiceResponse = {
16170
+ encode(message, writer = new BinaryWriter4()) {
16171
+ if (message.invoice !== "") {
16172
+ writer.uint32(10).string(message.invoice);
16173
+ }
16174
+ if (message.status !== 0) {
16175
+ writer.uint32(16).int32(message.status);
16176
+ }
16177
+ return writer;
16178
+ },
16179
+ decode(input, length) {
16180
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
16181
+ const end = length === void 0 ? reader.len : reader.pos + length;
16182
+ const message = createBaseInvoiceResponse();
16183
+ while (reader.pos < end) {
16184
+ const tag = reader.uint32();
16185
+ switch (tag >>> 3) {
16186
+ case 1: {
16187
+ if (tag !== 10) {
16188
+ break;
16189
+ }
16190
+ message.invoice = reader.string();
16191
+ continue;
16192
+ }
16193
+ case 2: {
16194
+ if (tag !== 16) {
16195
+ break;
16196
+ }
16197
+ message.status = reader.int32();
16198
+ continue;
16199
+ }
16200
+ }
16201
+ if ((tag & 7) === 4 || tag === 0) {
16202
+ break;
16203
+ }
16204
+ reader.skip(tag & 7);
16205
+ }
16206
+ return message;
16207
+ },
16208
+ fromJSON(object) {
16209
+ return {
16210
+ invoice: isSet3(object.invoice) ? globalThis.String(object.invoice) : "",
16211
+ status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0
16212
+ };
16213
+ },
16214
+ toJSON(message) {
16215
+ const obj = {};
16216
+ if (message.invoice !== "") {
16217
+ obj.invoice = message.invoice;
16218
+ }
16219
+ if (message.status !== 0) {
16220
+ obj.status = invoiceStatusToJSON(message.status);
16221
+ }
16222
+ return obj;
16223
+ },
16224
+ create(base) {
16225
+ return InvoiceResponse.fromPartial(base ?? {});
16226
+ },
16227
+ fromPartial(object) {
16228
+ const message = createBaseInvoiceResponse();
16229
+ message.invoice = object.invoice ?? "";
16230
+ message.status = object.status ?? 0;
16231
+ return message;
16232
+ }
16233
+ };
15784
16234
  var SparkServiceDefinition = {
15785
16235
  name: "SparkService",
15786
16236
  fullName: "spark.SparkService",
@@ -15793,6 +16243,15 @@ var SparkServiceDefinition = {
15793
16243
  responseStream: false,
15794
16244
  options: {}
15795
16245
  },
16246
+ /** Generates a new static deposit address of the user or returns the existing one for the specified network. */
16247
+ generate_static_deposit_address: {
16248
+ name: "generate_static_deposit_address",
16249
+ requestType: GenerateStaticDepositAddressRequest,
16250
+ requestStream: false,
16251
+ responseType: GenerateStaticDepositAddressResponse,
16252
+ responseStream: false,
16253
+ options: {}
16254
+ },
15796
16255
  start_deposit_tree_creation: {
15797
16256
  name: "start_deposit_tree_creation",
15798
16257
  requestType: StartDepositTreeCreationRequest,
@@ -16234,6 +16693,14 @@ var SparkServiceDefinition = {
16234
16693
  responseType: GetUtxosForAddressResponse,
16235
16694
  responseStream: false,
16236
16695
  options: {}
16696
+ },
16697
+ query_spark_invoices: {
16698
+ name: "query_spark_invoices",
16699
+ requestType: QuerySparkInvoicesRequest,
16700
+ requestStream: false,
16701
+ responseType: QuerySparkInvoicesResponse,
16702
+ responseStream: false,
16703
+ options: {}
16237
16704
  }
16238
16705
  }
16239
16706
  };
@@ -16298,13 +16765,13 @@ function isSet3(value) {
16298
16765
 
16299
16766
  // src/signer/signer.ts
16300
16767
  import { privateNegate } from "@bitcoinerlab/secp256k1";
16768
+ import { schnorr, secp256k1 as secp256k14 } from "@noble/curves/secp256k1";
16301
16769
  import {
16302
16770
  bytesToHex as bytesToHex4,
16303
16771
  bytesToNumberBE,
16304
16772
  equalBytes as equalBytes2,
16305
16773
  hexToBytes
16306
- } from "@noble/curves/abstract/utils";
16307
- import { schnorr, secp256k1 as secp256k14 } from "@noble/curves/secp256k1";
16774
+ } from "@noble/curves/utils";
16308
16775
  import { sha256 as sha2562 } from "@noble/hashes/sha2";
16309
16776
  import { HDKey } from "@scure/bip32";
16310
16777
  import { generateMnemonic, mnemonicToSeed } from "@scure/bip39";
@@ -16316,7 +16783,7 @@ import * as ecies from "eciesjs";
16316
16783
  import { isNode, isBare } from "@lightsparkdev/core";
16317
16784
  var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
16318
16785
  var isBun = globalThis.Bun !== void 0;
16319
- var packageVersion = true ? "0.2.11" : "unknown";
16786
+ var packageVersion = true ? "0.2.13" : "unknown";
16320
16787
  var baseEnvStr = "unknown";
16321
16788
  if (isBun) {
16322
16789
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -16335,8 +16802,8 @@ if (isBun) {
16335
16802
  var clientEnv = `js-spark-sdk/${packageVersion} ${baseEnvStr}`;
16336
16803
 
16337
16804
  // src/utils/keys.ts
16338
- import { numberToBytesBE } from "@noble/curves/abstract/utils";
16339
16805
  import { secp256k1 } from "@noble/curves/secp256k1";
16806
+ import { numberToBytesBE } from "@noble/curves/utils";
16340
16807
  function addPublicKeys(a, b) {
16341
16808
  if (a.length !== 33 || b.length !== 33) {
16342
16809
  throw new ValidationError("Public keys must be 33 bytes", {
@@ -16433,8 +16900,8 @@ function lastKeyWithTarget(target, keys) {
16433
16900
  }
16434
16901
 
16435
16902
  // src/utils/secret-sharing.ts
16436
- import { bytesToHex as bytesToHex3, equalBytes } from "@noble/curves/abstract/utils";
16437
16903
  import { secp256k1 as secp256k12 } from "@noble/curves/secp256k1";
16904
+ import { bytesToHex as bytesToHex3, equalBytes } from "@noble/curves/utils";
16438
16905
  function getRandomBigInt(max) {
16439
16906
  const byteLength = max.toString(2).length + 7 >> 3;
16440
16907
  const maxBigInt = max;
@@ -21723,12 +22190,8 @@ import { Transaction as Transaction4 } from "@scure/btc-signer";
21723
22190
  import { uuidv7 as uuidv72 } from "uuidv7";
21724
22191
 
21725
22192
  // src/utils/bitcoin.ts
21726
- import {
21727
- bytesToHex as bytesToHex5,
21728
- bytesToNumberBE as bytesToNumberBE2,
21729
- hexToBytes as hexToBytes2
21730
- } from "@noble/curves/abstract/utils";
21731
22193
  import { schnorr as schnorr2, secp256k1 as secp256k15 } from "@noble/curves/secp256k1";
22194
+ import { bytesToHex as bytesToHex5, bytesToNumberBE as bytesToNumberBE2, hexToBytes as hexToBytes2 } from "@noble/curves/utils";
21732
22195
  import { sha256 as sha2564 } from "@noble/hashes/sha2";
21733
22196
  import * as btc2 from "@scure/btc-signer";
21734
22197
  function computeTaprootKeyNoScript(pubkey) {
@@ -22214,20 +22677,20 @@ function getEphemeralAnchorOutput() {
22214
22677
  }
22215
22678
 
22216
22679
  // src/services/transfer.ts
22680
+ import { secp256k1 as secp256k16 } from "@noble/curves/secp256k1";
22217
22681
  import {
22218
22682
  bytesToHex as bytesToHex6,
22219
22683
  equalBytes as equalBytes3,
22220
22684
  hexToBytes as hexToBytes4,
22221
22685
  numberToBytesBE as numberToBytesBE2
22222
- } from "@noble/curves/abstract/utils";
22223
- import { secp256k1 as secp256k16 } from "@noble/curves/secp256k1";
22686
+ } from "@noble/curves/utils";
22224
22687
  import { sha256 as sha2566 } from "@noble/hashes/sha2";
22225
22688
  import { Transaction as Transaction3 } from "@scure/btc-signer";
22226
22689
  import * as ecies2 from "eciesjs";
22227
22690
  import { uuidv7 } from "uuidv7";
22228
22691
 
22229
22692
  // src/utils/transfer_package.ts
22230
- import { hexToBytes as hexToBytes3 } from "@noble/curves/abstract/utils";
22693
+ import { hexToBytes as hexToBytes3 } from "@noble/curves/utils";
22231
22694
  import { sha256 as sha2565 } from "@noble/hashes/sha2";
22232
22695
  function getTransferPackageSigningPayload(transferID, transferPackage) {
22233
22696
  const encryptedPayload = transferPackage.keyTweakPackage;
@@ -23238,24 +23701,6 @@ var TransferService = class extends BaseTransferService {
23238
23701
  throw new Error(`Error finalizing node signatures in transfer: ${error}`);
23239
23702
  }
23240
23703
  }
23241
- async cancelTransfer(transfer, operatorAddress) {
23242
- const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
23243
- try {
23244
- const response = await sparkClient.cancel_transfer({
23245
- transferId: transfer.id,
23246
- senderIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
23247
- });
23248
- return response.transfer;
23249
- } catch (error) {
23250
- throw new NetworkError(
23251
- "Failed to cancel transfer",
23252
- {
23253
- method: "POST"
23254
- },
23255
- error
23256
- );
23257
- }
23258
- }
23259
23704
  async queryPendingTransfersBySender(operatorAddress) {
23260
23705
  const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
23261
23706
  try {
@@ -24164,7 +24609,8 @@ var DepositService = class {
24164
24609
  }
24165
24610
  async validateDepositAddress({
24166
24611
  address: address2,
24167
- userPubkey
24612
+ userPubkey,
24613
+ verifyCoordinatorProof = false
24168
24614
  }) {
24169
24615
  if (!address2.depositAddressProof || !address2.depositAddressProof.proofOfPossessionSignature || !address2.depositAddressProof.addressSignatures) {
24170
24616
  throw new ValidationError(
@@ -24202,7 +24648,7 @@ var DepositService = class {
24202
24648
  }
24203
24649
  const addrHash = sha2568(address2.address);
24204
24650
  for (const operator of Object.values(this.config.getSigningOperators())) {
24205
- if (operator.identifier === this.config.getCoordinatorIdentifier()) {
24651
+ if (operator.identifier === this.config.getCoordinatorIdentifier() && !verifyCoordinatorProof) {
24206
24652
  continue;
24207
24653
  }
24208
24654
  const operatorPubkey2 = hexToBytes5(operator.identityPublicKey);
@@ -24227,6 +24673,46 @@ var DepositService = class {
24227
24673
  }
24228
24674
  }
24229
24675
  }
24676
+ async generateStaticDepositAddress({
24677
+ signingPubkey
24678
+ }) {
24679
+ const sparkClient = await this.connectionManager.createSparkClient(
24680
+ this.config.getCoordinatorAddress()
24681
+ );
24682
+ let depositResp;
24683
+ try {
24684
+ depositResp = await sparkClient.generate_static_deposit_address({
24685
+ signingPublicKey: signingPubkey,
24686
+ identityPublicKey: await this.config.signer.getIdentityPublicKey(),
24687
+ network: this.config.getNetworkProto()
24688
+ });
24689
+ } catch (error) {
24690
+ throw new NetworkError(
24691
+ "Failed to generate static deposit address",
24692
+ {
24693
+ operation: "generate_static_deposit_address",
24694
+ errorCount: 1,
24695
+ errors: error instanceof Error ? error.message : String(error)
24696
+ },
24697
+ error
24698
+ );
24699
+ }
24700
+ if (!depositResp.depositAddress) {
24701
+ throw new ValidationError(
24702
+ "No static deposit address response from coordinator",
24703
+ {
24704
+ field: "depositAddress",
24705
+ value: depositResp
24706
+ }
24707
+ );
24708
+ }
24709
+ await this.validateDepositAddress({
24710
+ address: depositResp.depositAddress,
24711
+ userPubkey: signingPubkey,
24712
+ verifyCoordinatorProof: true
24713
+ });
24714
+ return depositResp;
24715
+ }
24230
24716
  async generateDepositAddress({
24231
24717
  signingPubkey,
24232
24718
  leafId,
@@ -24766,12 +25252,12 @@ var DepositService = class {
24766
25252
  };
24767
25253
 
24768
25254
  // src/services/lightning.ts
25255
+ import { secp256k1 as secp256k18 } from "@noble/curves/secp256k1";
24769
25256
  import {
24770
25257
  bytesToNumberBE as bytesToNumberBE3,
24771
25258
  hexToBytes as hexToBytes6,
24772
25259
  numberToBytesBE as numberToBytesBE3
24773
- } from "@noble/curves/abstract/utils";
24774
- import { secp256k1 as secp256k18 } from "@noble/curves/secp256k1";
25260
+ } from "@noble/curves/utils";
24775
25261
  import { sha256 as sha2569 } from "@noble/hashes/sha2";
24776
25262
  import { uuidv7 as uuidv73 } from "uuidv7";
24777
25263
 
@@ -25117,18 +25603,18 @@ var LightningService = class {
25117
25603
  };
25118
25604
 
25119
25605
  // src/services/token-transactions.ts
25606
+ import { secp256k1 as secp256k111 } from "@noble/curves/secp256k1";
25120
25607
  import {
25121
- bytesToHex as bytesToHex9,
25608
+ bytesToHex as bytesToHex8,
25122
25609
  bytesToNumberBE as bytesToNumberBE6,
25123
25610
  numberToBytesBE as numberToBytesBE4
25124
- } from "@noble/curves/abstract/utils";
25125
- import { secp256k1 as secp256k111 } from "@noble/curves/secp256k1";
25611
+ } from "@noble/curves/utils";
25126
25612
  import { hexToBytes as hexToBytes8 } from "@noble/hashes/utils";
25127
25613
 
25128
25614
  // src/utils/address.ts
25129
25615
  import { BinaryWriter as BinaryWriter8 } from "@bufbuild/protobuf/wire";
25130
- import { bytesToNumberBE as bytesToNumberBE4 } from "@noble/curves/abstract/utils";
25131
25616
  import { schnorr as schnorr4, secp256k1 as secp256k19 } from "@noble/curves/secp256k1";
25617
+ import { bytesToNumberBE as bytesToNumberBE4 } from "@noble/curves/utils";
25132
25618
  import { bytesToHex as bytesToHex7, hexToBytes as hexToBytes7 } from "@noble/hashes/utils";
25133
25619
  import { bech32m } from "@scure/base";
25134
25620
  import { UUID } from "uuidv7";
@@ -27613,8 +28099,7 @@ function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction
27613
28099
  }
27614
28100
 
27615
28101
  // src/utils/token-transactions.ts
27616
- import { bytesToNumberBE as bytesToNumberBE5 } from "@noble/curves/abstract/utils";
27617
- import { equalBytes as equalBytes5 } from "@scure/btc-signer/utils";
28102
+ import { bytesToNumberBE as bytesToNumberBE5, equalBytes as equalBytes5 } from "@noble/curves/utils";
27618
28103
  function sumAvailableTokens(outputs) {
27619
28104
  try {
27620
28105
  return outputs.reduce(
@@ -27957,7 +28442,7 @@ var TokenTransactionService = class {
27957
28442
  {
27958
28443
  field: "revocationCommitment",
27959
28444
  value: derivedRevocationCommitment,
27960
- expected: bytesToHex9(outputsToSpendCommitments[outputIndex]),
28445
+ expected: bytesToHex8(outputsToSpendCommitments[outputIndex]),
27961
28446
  outputIndex
27962
28447
  }
27963
28448
  )
@@ -27983,7 +28468,7 @@ var TokenTransactionService = class {
27983
28468
  threshold
27984
28469
  );
27985
28470
  }
27986
- return bytesToHex9(finalTokenTransactionHash);
28471
+ return bytesToHex8(finalTokenTransactionHash);
27987
28472
  }
27988
28473
  async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
27989
28474
  const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
@@ -27997,7 +28482,7 @@ var TokenTransactionService = class {
27997
28482
  finalTokenTransactionHash,
27998
28483
  signingOperators
27999
28484
  );
28000
- return bytesToHex9(finalTokenTransactionHash);
28485
+ return bytesToHex8(finalTokenTransactionHash);
28001
28486
  }
28002
28487
  async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
28003
28488
  const sparkClient = await this.connectionManager.createSparkClient(
@@ -28589,7 +29074,7 @@ var TokenTransactionService = class {
28589
29074
  // Helper function for deciding if the signer public key is the identity public key
28590
29075
  async signMessageWithKey(message, publicKey) {
28591
29076
  const tokenSignatures = this.config.getTokenSignatures();
28592
- if (bytesToHex9(publicKey) === bytesToHex9(await this.config.signer.getIdentityPublicKey())) {
29077
+ if (bytesToHex8(publicKey) === bytesToHex8(await this.config.signer.getIdentityPublicKey())) {
28593
29078
  if (tokenSignatures === "SCHNORR") {
28594
29079
  return await this.config.signer.signSchnorrWithIdentityKey(message);
28595
29080
  } else {
@@ -28598,8 +29083,8 @@ var TokenTransactionService = class {
28598
29083
  } else {
28599
29084
  throw new ValidationError("Invalid public key", {
28600
29085
  field: "publicKey",
28601
- value: bytesToHex9(publicKey),
28602
- expected: bytesToHex9(await this.config.signer.getIdentityPublicKey())
29086
+ value: bytesToHex8(publicKey),
29087
+ expected: bytesToHex8(await this.config.signer.getIdentityPublicKey())
28603
29088
  });
28604
29089
  }
28605
29090
  }
@@ -28729,8 +29214,8 @@ function isTokenTransaction(tokenTransaction) {
28729
29214
 
28730
29215
  // src/utils/adaptor-signature.ts
28731
29216
  import { mod } from "@noble/curves/abstract/modular";
28732
- import { bytesToNumberBE as bytesToNumberBE7, numberToBytesBE as numberToBytesBE5 } from "@noble/curves/abstract/utils";
28733
29217
  import { schnorr as schnorr5, secp256k1 as secp256k112 } from "@noble/curves/secp256k1";
29218
+ import { bytesToNumberBE as bytesToNumberBE7, numberToBytesBE as numberToBytesBE5 } from "@noble/curves/utils";
28734
29219
  function generateSignatureFromExistingAdaptor(signature, adaptorPrivateKeyBytes) {
28735
29220
  const { r, s } = parseSignature(signature);
28736
29221
  const sBigInt = bytesToNumberBE7(s);
@@ -28868,7 +29353,7 @@ import { EventEmitter } from "eventemitter3";
28868
29353
  import { ClientError, Status } from "nice-grpc-common";
28869
29354
 
28870
29355
  // src/services/signing.ts
28871
- import { hexToBytes as hexToBytes9 } from "@noble/curves/abstract/utils";
29356
+ import { hexToBytes as hexToBytes9 } from "@noble/curves/utils";
28872
29357
  var SigningService = class {
28873
29358
  config;
28874
29359
  constructor(config) {
@@ -29033,8 +29518,8 @@ var SigningService = class {
29033
29518
  };
29034
29519
 
29035
29520
  // src/tests/utils/test-faucet.ts
29036
- import { bytesToHex as bytesToHex10, hexToBytes as hexToBytes10 } from "@noble/curves/abstract/utils";
29037
29521
  import { schnorr as schnorr6, secp256k1 as secp256k113 } from "@noble/curves/secp256k1";
29522
+ import { bytesToHex as bytesToHex9, hexToBytes as hexToBytes10 } from "@noble/curves/utils";
29038
29523
  import * as btc3 from "@scure/btc-signer";
29039
29524
  import { Address as Address3, OutScript as OutScript2, SigHash as SigHash2, Transaction as Transaction6 } from "@scure/btc-signer";
29040
29525
  import { taprootTweakPrivKey as taprootTweakPrivKey2 } from "@scure/btc-signer/utils";
@@ -29166,7 +29651,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
29166
29651
  },
29167
29652
  STATIC_MINING_KEY
29168
29653
  );
29169
- await this.broadcastTx(bytesToHex10(signedSplitTx.extract()));
29654
+ await this.broadcastTx(bytesToHex9(signedSplitTx.extract()));
29170
29655
  const splitTxId = signedSplitTx.id;
29171
29656
  for (let i = 0; i < numCoinsToCreate; i++) {
29172
29657
  this.coins.push({
@@ -29200,7 +29685,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
29200
29685
  coinToSend.txout,
29201
29686
  coinToSend.key
29202
29687
  );
29203
- await this.broadcastTx(bytesToHex10(signedTx.extract()));
29688
+ await this.broadcastTx(bytesToHex9(signedTx.extract()));
29204
29689
  }
29205
29690
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
29206
29691
  const pubKey = secp256k113.getPublicKey(key);
@@ -29320,7 +29805,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
29320
29805
  });
29321
29806
  }
29322
29807
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
29323
- const txHex = bytesToHex10(signedTx.extract());
29808
+ const txHex = bytesToHex9(signedTx.extract());
29324
29809
  await this.broadcastTx(txHex);
29325
29810
  const randomKey = secp256k113.utils.randomPrivateKey();
29326
29811
  const randomPubKey = secp256k113.getPublicKey(randomKey);
@@ -29337,18 +29822,18 @@ var BitcoinFaucet = class _BitcoinFaucet {
29337
29822
  };
29338
29823
 
29339
29824
  // src/types/sdk-types.ts
29340
- import { bytesToHex as bytesToHex11 } from "@noble/curves/abstract/utils";
29825
+ import { bytesToHex as bytesToHex10 } from "@noble/curves/utils";
29341
29826
  function mapTreeNodeToWalletLeaf(proto) {
29342
29827
  return {
29343
29828
  id: proto.id,
29344
29829
  treeId: proto.treeId,
29345
29830
  value: proto.value,
29346
29831
  parentNodeId: proto.parentNodeId,
29347
- nodeTx: bytesToHex11(proto.nodeTx),
29348
- refundTx: bytesToHex11(proto.refundTx),
29832
+ nodeTx: bytesToHex10(proto.nodeTx),
29833
+ refundTx: bytesToHex10(proto.refundTx),
29349
29834
  vout: proto.vout,
29350
- verifyingPublicKey: bytesToHex11(proto.verifyingPublicKey),
29351
- ownerIdentityPublicKey: bytesToHex11(proto.ownerIdentityPublicKey),
29835
+ verifyingPublicKey: bytesToHex10(proto.verifyingPublicKey),
29836
+ ownerIdentityPublicKey: bytesToHex10(proto.ownerIdentityPublicKey),
29352
29837
  signingKeyshare: proto.signingKeyshare,
29353
29838
  status: proto.status,
29354
29839
  network: Network[proto.network]
@@ -29357,14 +29842,14 @@ function mapTreeNodeToWalletLeaf(proto) {
29357
29842
  function mapTransferLeafToWalletTransferLeaf(proto) {
29358
29843
  return {
29359
29844
  leaf: proto.leaf ? mapTreeNodeToWalletLeaf(proto.leaf) : void 0,
29360
- secretCipher: bytesToHex11(proto.secretCipher),
29361
- signature: bytesToHex11(proto.signature),
29362
- intermediateRefundTx: bytesToHex11(proto.intermediateRefundTx)
29845
+ secretCipher: bytesToHex10(proto.secretCipher),
29846
+ signature: bytesToHex10(proto.signature),
29847
+ intermediateRefundTx: bytesToHex10(proto.intermediateRefundTx)
29363
29848
  };
29364
29849
  }
29365
29850
  function mapTransferToWalletTransfer(proto, identityPublicKey, userRequest) {
29366
- const receiverIdentityPublicKey = bytesToHex11(proto.receiverIdentityPublicKey);
29367
- const senderIdentityPublicKey = bytesToHex11(proto.senderIdentityPublicKey);
29851
+ const receiverIdentityPublicKey = bytesToHex10(proto.receiverIdentityPublicKey);
29852
+ const senderIdentityPublicKey = bytesToHex10(proto.senderIdentityPublicKey);
29368
29853
  return {
29369
29854
  id: proto.id,
29370
29855
  senderIdentityPublicKey,
@@ -29931,7 +30416,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29931
30416
  * @returns {Promise<string>} The identity public key as a hex string.
29932
30417
  */
29933
30418
  async getIdentityPublicKey() {
29934
- return bytesToHex12(await this.config.signer.getIdentityPublicKey());
30419
+ return bytesToHex11(await this.config.signer.getIdentityPublicKey());
29935
30420
  }
29936
30421
  /**
29937
30422
  * Gets the Spark address of the wallet.
@@ -29941,7 +30426,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29941
30426
  async getSparkAddress() {
29942
30427
  if (!this.sparkAddress) {
29943
30428
  this.sparkAddress = encodeSparkAddress({
29944
- identityPublicKey: bytesToHex12(
30429
+ identityPublicKey: bytesToHex11(
29945
30430
  await this.config.signer.getIdentityPublicKey()
29946
30431
  ),
29947
30432
  network: this.config.getNetworkType()
@@ -30025,7 +30510,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30025
30510
  const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
30026
30511
  return encodeSparkAddressWithSignature(
30027
30512
  {
30028
- identityPublicKey: bytesToHex12(identityPublicKey),
30513
+ identityPublicKey: bytesToHex11(identityPublicKey),
30029
30514
  network: this.config.getNetworkType(),
30030
30515
  sparkInvoiceFields: invoiceFields
30031
30516
  },
@@ -30093,7 +30578,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30093
30578
  });
30094
30579
  }
30095
30580
  this.sparkAddress = encodeSparkAddress({
30096
- identityPublicKey: bytesToHex12(identityPublicKey),
30581
+ identityPublicKey: bytesToHex11(identityPublicKey),
30097
30582
  network: this.config.getNetworkType()
30098
30583
  });
30099
30584
  return this.sparkAddress;
@@ -30273,18 +30758,18 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30273
30758
  const userLeaves = [];
30274
30759
  userLeaves.push({
30275
30760
  leaf_id: transfer.leaves[0].leaf.id,
30276
- raw_unsigned_refund_transaction: bytesToHex12(
30761
+ raw_unsigned_refund_transaction: bytesToHex11(
30277
30762
  transfer.leaves[0].intermediateRefundTx
30278
30763
  ),
30279
- direct_raw_unsigned_refund_transaction: bytesToHex12(
30764
+ direct_raw_unsigned_refund_transaction: bytesToHex11(
30280
30765
  transfer.leaves[0].intermediateDirectRefundTx
30281
30766
  ),
30282
- direct_from_cpfp_raw_unsigned_refund_transaction: bytesToHex12(
30767
+ direct_from_cpfp_raw_unsigned_refund_transaction: bytesToHex11(
30283
30768
  transfer.leaves[0].intermediateDirectFromCpfpRefundTx
30284
30769
  ),
30285
- adaptor_added_signature: bytesToHex12(cpfpAdaptorSignature),
30286
- direct_adaptor_added_signature: bytesToHex12(directAdaptorSignature),
30287
- direct_from_cpfp_adaptor_added_signature: bytesToHex12(
30770
+ adaptor_added_signature: bytesToHex11(cpfpAdaptorSignature),
30771
+ direct_adaptor_added_signature: bytesToHex11(directAdaptorSignature),
30772
+ direct_from_cpfp_adaptor_added_signature: bytesToHex11(
30288
30773
  directFromCpfpAdaptorSignature
30289
30774
  )
30290
30775
  });
@@ -30337,24 +30822,24 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30337
30822
  }
30338
30823
  userLeaves.push({
30339
30824
  leaf_id: leaf.leaf.id,
30340
- raw_unsigned_refund_transaction: bytesToHex12(
30825
+ raw_unsigned_refund_transaction: bytesToHex11(
30341
30826
  leaf.intermediateRefundTx
30342
30827
  ),
30343
- direct_raw_unsigned_refund_transaction: bytesToHex12(
30828
+ direct_raw_unsigned_refund_transaction: bytesToHex11(
30344
30829
  leaf.intermediateDirectRefundTx
30345
30830
  ),
30346
- direct_from_cpfp_raw_unsigned_refund_transaction: bytesToHex12(
30831
+ direct_from_cpfp_raw_unsigned_refund_transaction: bytesToHex11(
30347
30832
  leaf.intermediateDirectFromCpfpRefundTx
30348
30833
  ),
30349
- adaptor_added_signature: bytesToHex12(cpfpSignature),
30350
- direct_adaptor_added_signature: bytesToHex12(directSignature),
30351
- direct_from_cpfp_adaptor_added_signature: bytesToHex12(
30834
+ adaptor_added_signature: bytesToHex11(cpfpSignature),
30835
+ direct_adaptor_added_signature: bytesToHex11(directSignature),
30836
+ direct_from_cpfp_adaptor_added_signature: bytesToHex11(
30352
30837
  directFromCpfpSignature
30353
30838
  )
30354
30839
  });
30355
30840
  }
30356
30841
  const sspClient = this.getSspClient();
30357
- const cpfpAdaptorPubkey = bytesToHex12(
30842
+ const cpfpAdaptorPubkey = bytesToHex11(
30358
30843
  secp256k114.getPublicKey(cpfpAdaptorPrivateKey)
30359
30844
  );
30360
30845
  if (!cpfpAdaptorPubkey) {
@@ -30362,13 +30847,13 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30362
30847
  }
30363
30848
  let directAdaptorPubkey;
30364
30849
  if (directAdaptorPrivateKey.length > 0) {
30365
- directAdaptorPubkey = bytesToHex12(
30850
+ directAdaptorPubkey = bytesToHex11(
30366
30851
  secp256k114.getPublicKey(directAdaptorPrivateKey)
30367
30852
  );
30368
30853
  }
30369
30854
  let directFromCpfpAdaptorPubkey;
30370
30855
  if (directFromCpfpAdaptorPrivateKey.length > 0) {
30371
- directFromCpfpAdaptorPubkey = bytesToHex12(
30856
+ directFromCpfpAdaptorPubkey = bytesToHex11(
30372
30857
  secp256k114.getPublicKey(directFromCpfpAdaptorPrivateKey)
30373
30858
  );
30374
30859
  }
@@ -30508,9 +30993,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30508
30993
  directFromCpfpSignatureMap
30509
30994
  );
30510
30995
  const completeResponse = await sspClient.completeLeaveSwap({
30511
- adaptorSecretKey: bytesToHex12(cpfpAdaptorPrivateKey),
30512
- directAdaptorSecretKey: bytesToHex12(directAdaptorPrivateKey),
30513
- directFromCpfpAdaptorSecretKey: bytesToHex12(
30996
+ adaptorSecretKey: bytesToHex11(cpfpAdaptorPrivateKey),
30997
+ directAdaptorSecretKey: bytesToHex11(directAdaptorPrivateKey),
30998
+ directFromCpfpAdaptorSecretKey: bytesToHex11(
30514
30999
  directFromCpfpAdaptorPrivateKey
30515
31000
  ),
30516
31001
  userOutboundTransferExternalId: transfer.id,
@@ -30541,7 +31026,6 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30541
31026
  message: e.message,
30542
31027
  stack: e.stack
30543
31028
  });
30544
- await this.cancelAllSenderInitiatedTransfers();
30545
31029
  throw new Error(`Failed to request leaves swap: ${e}`);
30546
31030
  }
30547
31031
  }
@@ -30605,7 +31089,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30605
31089
  let tokenMetadataMap = /* @__PURE__ */ new Map();
30606
31090
  for (const [tokenIdentifier, metadata] of this.tokenMetadata) {
30607
31091
  tokenMetadataMap.set(tokenIdentifier, {
30608
- tokenPublicKey: bytesToHex12(metadata.issuerPublicKey),
31092
+ tokenPublicKey: bytesToHex11(metadata.issuerPublicKey),
30609
31093
  rawTokenIdentifier: metadata.tokenIdentifier,
30610
31094
  tokenName: metadata.tokenName,
30611
31095
  tokenTicker: metadata.tokenTicker,
@@ -30645,7 +31129,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30645
31129
  * @returns {Promise<string>} A Bitcoin address for depositing funds
30646
31130
  */
30647
31131
  async getSingleUseDepositAddress() {
30648
- return await this.generateDepositAddress(false);
31132
+ return await this.generateDepositAddress();
30649
31133
  }
30650
31134
  /**
30651
31135
  * Generates a new static deposit address for receiving bitcoin funds.
@@ -30654,43 +31138,32 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30654
31138
  * @returns {Promise<string>} A Bitcoin address for depositing funds
30655
31139
  */
30656
31140
  async getStaticDepositAddress() {
30657
- try {
30658
- return await this.generateDepositAddress(true);
30659
- } catch (error) {
30660
- if (error.message?.includes("static deposit address already exists")) {
30661
- const existingAddresses = await this.queryStaticDepositAddresses();
30662
- if (existingAddresses.length > 0 && existingAddresses[0]) {
30663
- return existingAddresses[0];
30664
- } else {
30665
- throw error;
30666
- }
30667
- } else {
30668
- throw error;
30669
- }
31141
+ const signingPubkey = await this.config.signer.getStaticDepositSigningKey(0);
31142
+ const address2 = await this.depositService.generateStaticDepositAddress({
31143
+ signingPubkey
31144
+ });
31145
+ if (!address2.depositAddress) {
31146
+ throw new RPCError("Failed to generate static deposit address", {
31147
+ method: "generateStaticDepositAddress",
31148
+ params: { signingPubkey }
31149
+ });
30670
31150
  }
31151
+ return address2.depositAddress.address;
30671
31152
  }
30672
31153
  /**
30673
31154
  * Generates a deposit address for receiving funds.
30674
- *
30675
- * @param {boolean} static - Whether the address is static or single use
30676
31155
  * @returns {Promise<string>} A deposit address
30677
31156
  * @private
30678
31157
  */
30679
- async generateDepositAddress(isStatic) {
31158
+ async generateDepositAddress() {
30680
31159
  const leafId = uuidv74();
30681
- let signingPubkey;
30682
- if (isStatic) {
30683
- signingPubkey = await this.config.signer.getStaticDepositSigningKey(0);
30684
- } else {
30685
- signingPubkey = await this.config.signer.getPublicKeyFromDerivation({
30686
- type: "leaf" /* LEAF */,
30687
- path: leafId
30688
- });
30689
- }
31160
+ const signingPubkey = await this.config.signer.getPublicKeyFromDerivation({
31161
+ type: "leaf" /* LEAF */,
31162
+ path: leafId
31163
+ });
30690
31164
  const address2 = await this.depositService.generateDepositAddress({
30691
31165
  signingPubkey,
30692
- leafId,
30693
- isStatic
31166
+ leafId
30694
31167
  });
30695
31168
  if (!address2.depositAddress) {
30696
31169
  throw new RPCError("Failed to generate deposit address", {
@@ -30717,7 +31190,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30717
31190
  * @param offset - Pagination offset (default 0).
30718
31191
  * @returns {Promise<{ txid: string, vout: number }[]>} List of confirmed UTXOs.
30719
31192
  */
30720
- async getUtxosForDepositAddress(depositAddress, limit = 100, offset = 0) {
31193
+ async getUtxosForDepositAddress(depositAddress, limit = 100, offset = 0, excludeClaimed = false) {
30721
31194
  if (!depositAddress) {
30722
31195
  throw new ValidationError("Deposit address cannot be empty", {
30723
31196
  field: "depositAddress"
@@ -30731,10 +31204,11 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30731
31204
  address: depositAddress,
30732
31205
  network: NetworkToProto[this.config.getNetwork()],
30733
31206
  limit,
30734
- offset
31207
+ offset,
31208
+ excludeClaimed
30735
31209
  });
30736
31210
  return response.utxos.map((utxo) => ({
30737
- txid: bytesToHex12(utxo.txid),
31211
+ txid: bytesToHex11(utxo.txid),
30738
31212
  vout: utxo.vout
30739
31213
  })) ?? [];
30740
31214
  } catch (error) {
@@ -30804,7 +31278,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30804
31278
  if (network === BitcoinNetwork_default.FUTURE_VALUE) {
30805
31279
  network = BitcoinNetwork_default.REGTEST;
30806
31280
  }
30807
- const depositSecretKey = bytesToHex12(
31281
+ const depositSecretKey = bytesToHex11(
30808
31282
  await this.config.signer.getStaticDepositSecretKey(0)
30809
31283
  );
30810
31284
  const message = await this.getStaticDepositSigningPayload(
@@ -30817,7 +31291,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30817
31291
  );
30818
31292
  const hashBuffer = sha25612(message);
30819
31293
  const signatureBytes = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
30820
- const signature = bytesToHex12(signatureBytes);
31294
+ const signature = bytesToHex11(signatureBytes);
30821
31295
  const response = await this.sspClient.claimStaticDeposit({
30822
31296
  transactionId,
30823
31297
  outputIndex,
@@ -30969,7 +31443,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30969
31443
  networkJSON.toLowerCase(),
30970
31444
  2 /* Refund */,
30971
31445
  creditAmountSats,
30972
- bytesToHex12(spendTxSighash)
31446
+ bytesToHex11(spendTxSighash)
30973
31447
  );
30974
31448
  const hashBuffer = sha25612(message);
30975
31449
  const swapResponseUserSignature = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
@@ -31014,6 +31488,64 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
31014
31488
  });
31015
31489
  return tx.hex;
31016
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
+ }
31017
31549
  async getStaticDepositSigningPayload(transactionID, outputIndex, network, requestType, creditAmountSats, sspSignature) {
31018
31550
  const encoder = new TextEncoder();
31019
31551
  const parts = [];
@@ -31492,7 +32024,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
31492
32024
  }
31493
32025
  return mapTransferToWalletTransfer(
31494
32026
  transfer,
31495
- bytesToHex12(await this.config.signer.getIdentityPublicKey())
32027
+ bytesToHex11(await this.config.signer.getIdentityPublicKey())
31496
32028
  );
31497
32029
  });
31498
32030
  }
@@ -31752,24 +32284,6 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
31752
32284
  (result) => result.status === "fulfilled" && result.value !== null
31753
32285
  ).map((result) => result.value);
31754
32286
  }
31755
- /**
31756
- * Cancels all sender-initiated transfers.
31757
- *
31758
- * @returns {Promise<void>}
31759
- * @private
31760
- */
31761
- async cancelAllSenderInitiatedTransfers() {
31762
- for (const operator of Object.values(this.config.getSigningOperators())) {
31763
- const transfers = await this.transferService.queryPendingTransfersBySender(
31764
- operator.address
31765
- );
31766
- for (const transfer of transfers.transfers) {
31767
- if (transfer.status === 0 /* TRANSFER_STATUS_SENDER_INITIATED */) {
31768
- await this.transferService.cancelTransfer(transfer, operator.address);
31769
- }
31770
- }
31771
- }
31772
- }
31773
32287
  // ***** Lightning Flow *****
31774
32288
  /**
31775
32289
  * Creates a Lightning invoice for receiving payments.
@@ -31848,7 +32362,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
31848
32362
  const invoice2 = await sspClient.requestLightningReceive({
31849
32363
  amountSats: amountSats2,
31850
32364
  network: bitcoinNetwork,
31851
- paymentHash: bytesToHex12(paymentHash),
32365
+ paymentHash: bytesToHex11(paymentHash),
31852
32366
  expirySecs: expirySeconds,
31853
32367
  memo: memo2,
31854
32368
  includeSparkAddress,
@@ -32378,7 +32892,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
32378
32892
  return transfers?.[0];
32379
32893
  }
32380
32894
  async constructTransfersWithUserRequest(transfers) {
32381
- const identityPublicKey = bytesToHex12(
32895
+ const identityPublicKey = bytesToHex11(
32382
32896
  await this.config.signer.getIdentityPublicKey()
32383
32897
  );
32384
32898
  const userRequests = await this.sspClient?.getTransfers(
@@ -32622,7 +33136,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
32622
33136
  hash,
32623
33137
  compact
32624
33138
  );
32625
- return bytesToHex12(signature);
33139
+ return bytesToHex11(signature);
32626
33140
  }
32627
33141
  /**
32628
33142
  * Validates a message with the identity key.
@@ -32680,7 +33194,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
32680
33194
  publicKey,
32681
33195
  this.config.getNetwork()
32682
33196
  );
32683
- if (bytesToHex12(script) === bytesToHex12(identityScript)) {
33197
+ if (bytesToHex11(script) === bytesToHex11(identityScript)) {
32684
33198
  try {
32685
33199
  this.config.signer.signTransactionIndex(tx, i, publicKey);
32686
33200
  inputsSigned++;
@@ -32724,13 +33238,13 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
32724
33238
  depositPubKey,
32725
33239
  this.config.getNetwork()
32726
33240
  );
32727
- if (bytesToHex12(script) === bytesToHex12(identityScript)) {
33241
+ if (bytesToHex11(script) === bytesToHex11(identityScript)) {
32728
33242
  return {
32729
33243
  publicKey: identityPubKey,
32730
33244
  keyType: "identity"
32731
33245
  };
32732
33246
  }
32733
- if (bytesToHex12(script) === bytesToHex12(depositScript)) {
33247
+ if (bytesToHex11(script) === bytesToHex11(depositScript)) {
32734
33248
  return {
32735
33249
  publicKey: depositPubKey,
32736
33250
  keyType: "deposit"
@@ -33247,7 +33761,7 @@ async function isTxBroadcast(txid, baseUrl, network) {
33247
33761
  }
33248
33762
 
33249
33763
  // src/utils/unilateral-exit.ts
33250
- import { bytesToHex as bytesToHex13, hexToBytes as hexToBytes12 } from "@noble/curves/abstract/utils";
33764
+ import { bytesToHex as bytesToHex12, hexToBytes as hexToBytes12 } from "@noble/curves/utils";
33251
33765
  import { ripemd160 } from "@noble/hashes/legacy";
33252
33766
  import { sha256 as sha25613 } from "@noble/hashes/sha2";
33253
33767
  import * as btc4 from "@scure/btc-signer";
@@ -33318,10 +33832,10 @@ async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network)
33318
33832
  }
33319
33833
  }
33320
33834
  for (const chainNode of chain) {
33321
- const nodeTx = bytesToHex13(chainNode.nodeTx);
33835
+ const nodeTx = bytesToHex12(chainNode.nodeTx);
33322
33836
  transactions.push(nodeTx);
33323
33837
  if (chainNode.id === node.id) {
33324
- const refundTx = bytesToHex13(chainNode.refundTx);
33838
+ const refundTx = bytesToHex12(chainNode.refundTx);
33325
33839
  transactions.push(refundTx);
33326
33840
  }
33327
33841
  }
@@ -33427,7 +33941,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
33427
33941
  }
33428
33942
  }
33429
33943
  for (const chainNode of chain) {
33430
- let nodeTxHex = bytesToHex13(chainNode.nodeTx);
33944
+ let nodeTxHex = bytesToHex12(chainNode.nodeTx);
33431
33945
  try {
33432
33946
  const txObj = getTxFromRawTxHex(nodeTxHex);
33433
33947
  const txid = getTxId(txObj);
@@ -33444,7 +33958,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
33444
33958
  for (let i = txObj.outputsLength - 1; i >= 0; i--) {
33445
33959
  const output = txObj.getOutput(i);
33446
33960
  if (output?.amount === 0n && output.script) {
33447
- anchorOutputScriptHex = bytesToHex13(output.script);
33961
+ anchorOutputScriptHex = bytesToHex12(output.script);
33448
33962
  break;
33449
33963
  }
33450
33964
  }
@@ -33469,7 +33983,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
33469
33983
  var feeBumpOut = feeBumpTx.outputsLength === 1 ? feeBumpTx.getOutput(0) : null;
33470
33984
  var feeBumpOutPubKey = null;
33471
33985
  for (const usedUtxo of usedUtxos) {
33472
- if (feeBumpOut && bytesToHex13(feeBumpOut.script) == usedUtxo.script) {
33986
+ if (feeBumpOut && bytesToHex12(feeBumpOut.script) == usedUtxo.script) {
33473
33987
  feeBumpOutPubKey = usedUtxo.publicKey;
33474
33988
  }
33475
33989
  const index = availableUtxos.findIndex(
@@ -33484,20 +33998,20 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
33484
33998
  txid: getTxId(feeBumpTx),
33485
33999
  vout: 0,
33486
34000
  value: feeBumpOut.amount,
33487
- script: bytesToHex13(feeBumpOut.script),
34001
+ script: bytesToHex12(feeBumpOut.script),
33488
34002
  publicKey: feeBumpOutPubKey
33489
34003
  });
33490
34004
  const finalNodeTx = correctedParentTx || nodeTxHex;
33491
34005
  txPackages.push({ tx: finalNodeTx, feeBumpPsbt: nodeFeeBumpPsbt });
33492
34006
  if (chainNode.id === node.id) {
33493
- let refundTxHex = bytesToHex13(chainNode.refundTx);
34007
+ let refundTxHex = bytesToHex12(chainNode.refundTx);
33494
34008
  try {
33495
34009
  const txObj = getTxFromRawTxHex(refundTxHex);
33496
34010
  let anchorOutputScriptHex;
33497
34011
  for (let i = txObj.outputsLength - 1; i >= 0; i--) {
33498
34012
  const output = txObj.getOutput(i);
33499
34013
  if (output?.amount === 0n && output.script) {
33500
- anchorOutputScriptHex = bytesToHex13(output.script);
34014
+ anchorOutputScriptHex = bytesToHex12(output.script);
33501
34015
  break;
33502
34016
  }
33503
34017
  }
@@ -33525,7 +34039,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
33525
34039
  var feeBumpOut = feeBumpTx2.outputsLength === 1 ? feeBumpTx2.getOutput(0) : null;
33526
34040
  var feeBumpOutPubKey = null;
33527
34041
  for (const usedUtxo of usedUtxos) {
33528
- if (feeBumpOut && bytesToHex13(feeBumpOut.script) == usedUtxo.script) {
34042
+ if (feeBumpOut && bytesToHex12(feeBumpOut.script) == usedUtxo.script) {
33529
34043
  feeBumpOutPubKey = usedUtxo.publicKey;
33530
34044
  }
33531
34045
  const index = availableUtxos.findIndex(
@@ -33540,7 +34054,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
33540
34054
  txid: getTxId(feeBumpTx2),
33541
34055
  vout: 0,
33542
34056
  value: feeBumpOut.amount,
33543
- script: bytesToHex13(feeBumpOut.script),
34057
+ script: bytesToHex12(feeBumpOut.script),
33544
34058
  publicKey: feeBumpOutPubKey
33545
34059
  });
33546
34060
  txPackages.push({
@@ -33638,7 +34152,7 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
33638
34152
  const pubKeyHash = hash160(hexToBytes12(fundingUtxo.publicKey));
33639
34153
  const scriptToUse = new Uint8Array([0, 20, ...pubKeyHash]);
33640
34154
  const providedScript = hexToBytes12(fundingUtxo.script);
33641
- if (bytesToHex13(scriptToUse) !== bytesToHex13(providedScript)) {
34155
+ if (bytesToHex12(scriptToUse) !== bytesToHex12(providedScript)) {
33642
34156
  throw new Error(
33643
34157
  `\u274C Derived script doesn't match provided script for UTXO ${i + 1}.`
33644
34158
  );
@@ -33703,7 +34217,7 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
33703
34217
  }
33704
34218
  let psbtHex;
33705
34219
  try {
33706
- psbtHex = bytesToHex13(builder.toPSBT());
34220
+ psbtHex = bytesToHex12(builder.toPSBT());
33707
34221
  } catch (error) {
33708
34222
  throw new Error(`Failed to extract transaction: ${error}`);
33709
34223
  }