@buildonspark/spark-sdk 0.2.4 → 0.2.6

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 (82) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/{chunk-3SEOTO43.js → chunk-3SPMJMUX.js} +3 -2
  3. package/dist/chunk-AVI5E5VT.js +66 -0
  4. package/dist/{chunk-WAQKYSDI.js → chunk-CQY5ML2A.js} +3 -2
  5. package/dist/{chunk-W4ZRBSWM.js → chunk-GUZ3WCB4.js} +466 -167
  6. package/dist/{client-KhNkrXz4.d.cts → client-CusuvuCe.d.cts} +199 -104
  7. package/dist/{client-BF4cn8F4.d.ts → client-Dn4Ld8pD.d.ts} +199 -104
  8. package/dist/debug.cjs +662 -336
  9. package/dist/debug.d.cts +9 -7
  10. package/dist/debug.d.ts +9 -7
  11. package/dist/debug.js +3 -3
  12. package/dist/graphql/objects/index.d.cts +6 -51
  13. package/dist/graphql/objects/index.d.ts +6 -51
  14. package/dist/graphql/objects/index.js +1 -1
  15. package/dist/index.cjs +713 -327
  16. package/dist/index.d.cts +19 -188
  17. package/dist/index.d.ts +19 -188
  18. package/dist/index.js +15 -8
  19. package/dist/index.node.cjs +638 -352
  20. package/dist/index.node.d.cts +7 -7
  21. package/dist/index.node.d.ts +7 -7
  22. package/dist/index.node.js +59 -100
  23. package/dist/native/index.cjs +655 -325
  24. package/dist/native/index.d.cts +253 -164
  25. package/dist/native/index.d.ts +253 -164
  26. package/dist/native/index.js +505 -172
  27. package/dist/proto/lrc20.d.cts +1 -1
  28. package/dist/proto/lrc20.d.ts +1 -1
  29. package/dist/proto/spark.d.cts +1 -1
  30. package/dist/proto/spark.d.ts +1 -1
  31. package/dist/proto/spark_token.d.cts +1 -1
  32. package/dist/proto/spark_token.d.ts +1 -1
  33. package/dist/{spark-B_7nZx6T.d.cts → spark-Cj4brrP5.d.cts} +1 -1
  34. package/dist/{spark-B_7nZx6T.d.ts → spark-Cj4brrP5.d.ts} +1 -1
  35. package/dist/{spark-wallet-C1Tr_VKI.d.ts → spark-wallet-B6YthxDI.d.ts} +61 -26
  36. package/dist/{spark-wallet-DG3x2obf.d.cts → spark-wallet-BbOf2P2l.d.cts} +61 -26
  37. package/dist/spark-wallet.node-BBk1sGS2.d.cts +12 -0
  38. package/dist/spark-wallet.node-Bffethig.d.ts +12 -0
  39. package/dist/tests/test-utils.cjs +86 -54
  40. package/dist/tests/test-utils.d.cts +24 -24
  41. package/dist/tests/test-utils.d.ts +24 -24
  42. package/dist/tests/test-utils.js +4 -4
  43. package/dist/token-transactions-0_5XMWjs.d.ts +184 -0
  44. package/dist/token-transactions-CD-Adb5y.d.cts +184 -0
  45. package/dist/types/index.cjs +3 -2
  46. package/dist/types/index.d.cts +3 -4
  47. package/dist/types/index.d.ts +3 -4
  48. package/dist/types/index.js +2 -2
  49. package/dist/{xchain-address-HBr6isnc.d.cts → xchain-address-BnKZ0-dY.d.cts} +6 -5
  50. package/dist/{xchain-address-BHu6CpZC.d.ts → xchain-address-Di3lu4Wy.d.ts} +6 -5
  51. package/package.json +7 -2
  52. package/src/graphql/client.ts +49 -8
  53. package/src/graphql/objects/SparkWalletUser.ts +1 -1
  54. package/src/graphql/queries/Transfers.ts +15 -0
  55. package/src/index.node.ts +5 -1
  56. package/src/index.ts +4 -1
  57. package/src/services/config.ts +13 -2
  58. package/src/services/token-transactions.ts +22 -8
  59. package/src/services/wallet-config.ts +22 -13
  60. package/src/spark-wallet/spark-wallet.browser.ts +72 -0
  61. package/src/spark-wallet/spark-wallet.node.ts +60 -118
  62. package/src/spark-wallet/spark-wallet.ts +400 -156
  63. package/src/tests/integration/ssp/coop-exit-validation.test.ts +233 -0
  64. package/src/tests/integration/ssp/coop-exit.test.ts +112 -93
  65. package/src/tests/integration/ssp/static-deposit-validation.test.ts +145 -0
  66. package/src/tests/integration/ssp/static_deposit.test.ts +453 -64
  67. package/src/tests/integration/ssp/transfers.test.ts +102 -0
  68. package/src/tests/integration/static_deposit.test.ts +92 -0
  69. package/src/tests/integration/transfer.test.ts +1 -1
  70. package/src/tests/utils/regtest-test-faucet.ts +8 -0
  71. package/src/tests/utils/spark-testing-wallet.ts +42 -0
  72. package/src/tests/utils/test-faucet.ts +6 -2
  73. package/src/types/sdk-types.ts +15 -0
  74. package/src/utils/bitcoin.ts +13 -0
  75. package/src/utils/token-identifier.ts +47 -4
  76. package/src/utils/token-transactions.ts +13 -9
  77. package/dist/chunk-TVUMSHWA.js +0 -7
  78. package/dist/sdk-types-CB9HrW5O.d.cts +0 -44
  79. package/dist/sdk-types-CkRNraXT.d.ts +0 -44
  80. package/dist/spark-wallet.node-CGxoeCpH.d.ts +0 -13
  81. package/dist/spark-wallet.node-CN9LoB_O.d.cts +0 -13
  82. package/src/graphql/queries/Transfer.ts +0 -10
@@ -1345,7 +1345,7 @@ __export(index_exports, {
1345
1345
  encodeSparkAddress: () => encodeSparkAddress,
1346
1346
  evaluatePolynomial: () => evaluatePolynomial,
1347
1347
  fieldDiv: () => fieldDiv,
1348
- filterTokenBalanceForTokenPublicKey: () => filterTokenBalanceForTokenPublicKey,
1348
+ filterTokenBalanceForTokenIdentifier: () => filterTokenBalanceForTokenIdentifier,
1349
1349
  generateAdaptorFromSignature: () => generateAdaptorFromSignature,
1350
1350
  generatePolynomialForSecretSharing: () => generatePolynomialForSecretSharing,
1351
1351
  generateSignatureFromExistingAdaptor: () => generateSignatureFromExistingAdaptor,
@@ -1354,6 +1354,7 @@ __export(index_exports, {
1354
1354
  getLatestDepositTxId: () => getLatestDepositTxId,
1355
1355
  getNetwork: () => getNetwork,
1356
1356
  getNetworkFromAddress: () => getNetworkFromAddress,
1357
+ getNetworkFromBech32mTokenIdentifier: () => getNetworkFromBech32mTokenIdentifier,
1357
1358
  getNetworkFromString: () => getNetworkFromString,
1358
1359
  getNextTransactionSequence: () => getNextTransactionSequence,
1359
1360
  getP2TRAddressFromPkScript: () => getP2TRAddressFromPkScript,
@@ -1367,6 +1368,7 @@ __export(index_exports, {
1367
1368
  getSparkAddressFromTaproot: () => getSparkAddressFromTaproot,
1368
1369
  getTransactionSequence: () => getTransactionSequence,
1369
1370
  getTransferPackageSigningPayload: () => getTransferPackageSigningPayload,
1371
+ getTxEstimatedVbytesSizeByNumberOfInputsOutputs: () => getTxEstimatedVbytesSizeByNumberOfInputsOutputs,
1370
1372
  getTxFromRawTxBytes: () => getTxFromRawTxBytes,
1371
1373
  getTxFromRawTxHex: () => getTxFromRawTxHex,
1372
1374
  getTxId: () => getTxId,
@@ -16553,6 +16555,12 @@ function getTxId(tx) {
16553
16555
  function getTxIdNoReverse(tx) {
16554
16556
  return (0, import_utils5.bytesToHex)((0, import_sha2.sha256)((0, import_sha2.sha256)(tx.toBytes(true))));
16555
16557
  }
16558
+ function getTxEstimatedVbytesSizeByNumberOfInputsOutputs(numInputs, numOutputs) {
16559
+ const TX_OVERHEAD = 10;
16560
+ const IN_VBYTES = 150;
16561
+ const OUT_VBYTES = 34;
16562
+ return TX_OVERHEAD + numInputs * IN_VBYTES + numOutputs * OUT_VBYTES;
16563
+ }
16556
16564
 
16557
16565
  // src/utils/keys.ts
16558
16566
  init_buffer();
@@ -16781,7 +16789,7 @@ function getLocalFrostSignerAddress() {
16781
16789
  var BASE_CONFIG = {
16782
16790
  network: "LOCAL",
16783
16791
  lrc20Address: getLrc20Url("LOCAL"),
16784
- coodinatorIdentifier: "0000000000000000000000000000000000000000000000000000000000000001",
16792
+ coordinatorIdentifier: "0000000000000000000000000000000000000000000000000000000000000001",
16785
16793
  frostSignerAddress: getLocalFrostSignerAddress(),
16786
16794
  threshold: 2,
16787
16795
  signingOperators: getLocalSigningOperators(),
@@ -16800,6 +16808,9 @@ var BASE_CONFIG = {
16800
16808
  baseUrl: getSspUrl("LOCAL"),
16801
16809
  identityPublicKey: getSspIdentityPublicKey("LOCAL"),
16802
16810
  schemaEndpoint: getSspSchemaEndpoint("LOCAL")
16811
+ },
16812
+ console: {
16813
+ otel: false
16803
16814
  }
16804
16815
  };
16805
16816
  var LOCAL_WALLET_CONFIG = {
@@ -16882,6 +16893,10 @@ function getSigningOperators() {
16882
16893
  };
16883
16894
  }
16884
16895
  function getLocalSigningOperators() {
16896
+ const addresses = Array.from(
16897
+ { length: 5 },
16898
+ (_, i) => isHermeticTest ? `https://${i}.spark.minikube.local` : `https://localhost:${i + 8535}`
16899
+ );
16885
16900
  const pubkeys = [
16886
16901
  "0322ca18fc489ae25418a0e768273c2c61cabb823edfb14feb891e9bec62016510",
16887
16902
  "0341727a6c41b168f07eb50865ab8c397a53c7eef628ac1020956b705e43b6cb27",
@@ -16893,31 +16908,31 @@ function getLocalSigningOperators() {
16893
16908
  "0000000000000000000000000000000000000000000000000000000000000001": {
16894
16909
  id: 0,
16895
16910
  identifier: "0000000000000000000000000000000000000000000000000000000000000001",
16896
- address: "https://localhost:8535",
16911
+ address: addresses[0],
16897
16912
  identityPublicKey: pubkeys[0]
16898
16913
  },
16899
16914
  "0000000000000000000000000000000000000000000000000000000000000002": {
16900
16915
  id: 1,
16901
16916
  identifier: "0000000000000000000000000000000000000000000000000000000000000002",
16902
- address: "https://localhost:8536",
16917
+ address: addresses[1],
16903
16918
  identityPublicKey: pubkeys[1]
16904
16919
  },
16905
16920
  "0000000000000000000000000000000000000000000000000000000000000003": {
16906
16921
  id: 2,
16907
16922
  identifier: "0000000000000000000000000000000000000000000000000000000000000003",
16908
- address: "https://localhost:8537",
16923
+ address: addresses[2],
16909
16924
  identityPublicKey: pubkeys[2]
16910
16925
  },
16911
16926
  "0000000000000000000000000000000000000000000000000000000000000004": {
16912
16927
  id: 3,
16913
16928
  identifier: "0000000000000000000000000000000000000000000000000000000000000004",
16914
- address: "https://localhost:8538",
16929
+ address: addresses[3],
16915
16930
  identityPublicKey: pubkeys[3]
16916
16931
  },
16917
16932
  "0000000000000000000000000000000000000000000000000000000000000005": {
16918
16933
  id: 4,
16919
16934
  identifier: "0000000000000000000000000000000000000000000000000000000000000005",
16920
- address: "https://localhost:8539",
16935
+ address: addresses[4],
16921
16936
  identityPublicKey: pubkeys[4]
16922
16937
  }
16923
16938
  };
@@ -16935,6 +16950,20 @@ var import_core = require("@lightsparkdev/core");
16935
16950
 
16936
16951
  // src/graphql/objects/ClaimStaticDepositStatus.ts
16937
16952
  init_buffer();
16953
+ var ClaimStaticDepositStatus = /* @__PURE__ */ ((ClaimStaticDepositStatus2) => {
16954
+ ClaimStaticDepositStatus2["FUTURE_VALUE"] = "FUTURE_VALUE";
16955
+ ClaimStaticDepositStatus2["CREATED"] = "CREATED";
16956
+ ClaimStaticDepositStatus2["TRANSFER_CREATED"] = "TRANSFER_CREATED";
16957
+ ClaimStaticDepositStatus2["TRANSFER_CREATION_FAILED"] = "TRANSFER_CREATION_FAILED";
16958
+ ClaimStaticDepositStatus2["REFUND_SIGNING_COMMITMENTS_QUERYING_FAILED"] = "REFUND_SIGNING_COMMITMENTS_QUERYING_FAILED";
16959
+ ClaimStaticDepositStatus2["REFUND_SIGNING_FAILED"] = "REFUND_SIGNING_FAILED";
16960
+ ClaimStaticDepositStatus2["UTXO_SWAPPING_FAILED"] = "UTXO_SWAPPING_FAILED";
16961
+ ClaimStaticDepositStatus2["TRANSFER_COMPLETED"] = "TRANSFER_COMPLETED";
16962
+ ClaimStaticDepositStatus2["SPEND_TX_CREATED"] = "SPEND_TX_CREATED";
16963
+ ClaimStaticDepositStatus2["SPEND_TX_BROADCAST"] = "SPEND_TX_BROADCAST";
16964
+ return ClaimStaticDepositStatus2;
16965
+ })(ClaimStaticDepositStatus || {});
16966
+ var ClaimStaticDepositStatus_default = ClaimStaticDepositStatus;
16938
16967
 
16939
16968
  // src/graphql/objects/CurrencyAmount.ts
16940
16969
  init_buffer();
@@ -16977,6 +17006,26 @@ var CurrencyAmountToJson = (obj) => {
16977
17006
  };
16978
17007
  };
16979
17008
 
17009
+ // src/graphql/objects/ClaimStaticDeposit.ts
17010
+ var ClaimStaticDepositFromJson = (obj) => {
17011
+ return {
17012
+ id: obj["claim_static_deposit_id"],
17013
+ createdAt: obj["claim_static_deposit_created_at"],
17014
+ updatedAt: obj["claim_static_deposit_updated_at"],
17015
+ network: BitcoinNetwork_default[obj["claim_static_deposit_network"]] ?? BitcoinNetwork_default.FUTURE_VALUE,
17016
+ creditAmount: CurrencyAmountFromJson(
17017
+ obj["claim_static_deposit_credit_amount"]
17018
+ ),
17019
+ maxFee: CurrencyAmountFromJson(obj["claim_static_deposit_max_fee"]),
17020
+ status: ClaimStaticDepositStatus_default[obj["claim_static_deposit_status"]] ?? ClaimStaticDepositStatus_default.FUTURE_VALUE,
17021
+ transactionId: obj["claim_static_deposit_transaction_id"],
17022
+ outputIndex: obj["claim_static_deposit_output_index"],
17023
+ bitcoinNetwork: BitcoinNetwork_default[obj["claim_static_deposit_bitcoin_network"]] ?? BitcoinNetwork_default.FUTURE_VALUE,
17024
+ typename: "ClaimStaticDeposit",
17025
+ transferSparkId: obj["claim_static_deposit_transfer_spark_id"]
17026
+ };
17027
+ };
17028
+
16980
17029
  // src/graphql/objects/ClaimStaticDepositRequestType.ts
16981
17030
  init_buffer();
16982
17031
  var ClaimStaticDepositRequestType = /* @__PURE__ */ ((ClaimStaticDepositRequestType2) => {
@@ -17844,7 +17893,7 @@ function mapTransferLeafToWalletTransferLeaf(proto) {
17844
17893
  intermediateRefundTx: (0, import_utils7.bytesToHex)(proto.intermediateRefundTx)
17845
17894
  };
17846
17895
  }
17847
- function mapTransferToWalletTransfer(proto, identityPublicKey) {
17896
+ function mapTransferToWalletTransfer(proto, identityPublicKey, userRequest) {
17848
17897
  const receiverIdentityPublicKey = (0, import_utils7.bytesToHex)(proto.receiverIdentityPublicKey);
17849
17898
  const senderIdentityPublicKey = (0, import_utils7.bytesToHex)(proto.senderIdentityPublicKey);
17850
17899
  return {
@@ -17858,7 +17907,8 @@ function mapTransferToWalletTransfer(proto, identityPublicKey) {
17858
17907
  createdTime: proto.createdTime ? new Date(proto.createdTime) : void 0,
17859
17908
  updatedTime: proto.updatedTime ? new Date(proto.updatedTime) : void 0,
17860
17909
  type: TransferType[proto.type],
17861
- transferDirection: receiverIdentityPublicKey === identityPublicKey ? "INCOMING" /* INCOMING */ : "OUTGOING" /* OUTGOING */
17910
+ transferDirection: receiverIdentityPublicKey === identityPublicKey ? "INCOMING" /* INCOMING */ : "OUTGOING" /* OUTGOING */,
17911
+ userRequest
17862
17912
  };
17863
17913
  }
17864
17914
 
@@ -18267,6 +18317,15 @@ var Bech32mTokenIdentifierTokenIdentifierNetworkPrefix = {
18267
18317
  function encodeBech32mTokenIdentifier(payload) {
18268
18318
  try {
18269
18319
  const words = import_base3.bech32m.toWords(payload.tokenIdentifier);
18320
+ if (!payload.network) {
18321
+ throw new ValidationError(
18322
+ "Network is required to encode bech32m encoded token identifier",
18323
+ {
18324
+ field: "network",
18325
+ value: payload.network
18326
+ }
18327
+ );
18328
+ }
18270
18329
  return import_base3.bech32m.encode(
18271
18330
  Bech32mTokenIdentifierTokenIdentifierNetworkPrefix[payload.network],
18272
18331
  words,
@@ -18289,7 +18348,7 @@ function decodeBech32mTokenIdentifier(bech32mTokenIdentifier, network) {
18289
18348
  bech32mTokenIdentifier,
18290
18349
  500
18291
18350
  );
18292
- if (decoded.prefix !== Bech32mTokenIdentifierTokenIdentifierNetworkPrefix[network]) {
18351
+ if (network && decoded.prefix !== Bech32mTokenIdentifierTokenIdentifierNetworkPrefix[network]) {
18293
18352
  throw new ValidationError(
18294
18353
  "Invalid bech32m encoded token identifier prefix",
18295
18354
  {
@@ -18302,7 +18361,7 @@ function decodeBech32mTokenIdentifier(bech32mTokenIdentifier, network) {
18302
18361
  const tokenIdentifier = import_base3.bech32m.fromWords(decoded.words);
18303
18362
  return {
18304
18363
  tokenIdentifier,
18305
- network
18364
+ network: network ?? getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier)
18306
18365
  };
18307
18366
  } catch (error) {
18308
18367
  if (error instanceof ValidationError) {
@@ -18318,10 +18377,35 @@ function decodeBech32mTokenIdentifier(bech32mTokenIdentifier, network) {
18318
18377
  );
18319
18378
  }
18320
18379
  }
18380
+ function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier) {
18381
+ const separatorIndex = bech32mTokenIdentifier.indexOf("1");
18382
+ if (separatorIndex === -1) {
18383
+ throw new ValidationError(
18384
+ "Invalid bech32m token identifier: no separator found",
18385
+ {
18386
+ field: "bech32mTokenIdentifier",
18387
+ value: bech32mTokenIdentifier
18388
+ }
18389
+ );
18390
+ }
18391
+ const prefix = bech32mTokenIdentifier.slice(0, separatorIndex);
18392
+ for (const [network, networkPrefix] of Object.entries(
18393
+ Bech32mTokenIdentifierTokenIdentifierNetworkPrefix
18394
+ )) {
18395
+ if (networkPrefix === prefix) {
18396
+ return network;
18397
+ }
18398
+ }
18399
+ throw new ValidationError("Unknown bech32m token identifier prefix", {
18400
+ field: "bech32mTokenIdentifier",
18401
+ value: bech32mTokenIdentifier
18402
+ });
18403
+ }
18321
18404
 
18322
18405
  // src/utils/token-transactions.ts
18323
18406
  init_buffer();
18324
18407
  var import_utils9 = require("@noble/curves/abstract/utils");
18408
+ var import_utils10 = require("@scure/btc-signer/utils");
18325
18409
  function sumAvailableTokens(outputs) {
18326
18410
  return outputs.reduce(
18327
18411
  (sum, output) => sum + BigInt((0, import_utils9.bytesToNumberBE)(output.output.tokenAmount)),
@@ -18346,12 +18430,13 @@ function checkIfSelectedOutputsAreAvailable(selectedOutputs, tokenOutputs, token
18346
18430
  }
18347
18431
  return true;
18348
18432
  }
18349
- function filterTokenBalanceForTokenPublicKey(tokenBalances, publicKey) {
18433
+ function filterTokenBalanceForTokenIdentifier(tokenBalances, tokenIdentifier) {
18350
18434
  if (!tokenBalances) {
18351
18435
  return { balance: 0n };
18352
18436
  }
18437
+ const tokenIdentifierBytes = decodeBech32mTokenIdentifier(tokenIdentifier).tokenIdentifier;
18353
18438
  const tokenBalance = [...tokenBalances.entries()].find(
18354
- ([, info]) => info.tokenMetadata.tokenPublicKey === publicKey
18439
+ ([, info]) => (0, import_utils10.equalBytes)(info.tokenMetadata.rawTokenIdentifier, tokenIdentifierBytes)
18355
18440
  );
18356
18441
  if (!tokenBalance) {
18357
18442
  return {
@@ -18365,7 +18450,7 @@ function filterTokenBalanceForTokenPublicKey(tokenBalances, publicKey) {
18365
18450
 
18366
18451
  // src/utils/transfer_package.ts
18367
18452
  init_buffer();
18368
- var import_utils10 = require("@noble/curves/abstract/utils");
18453
+ var import_utils11 = require("@noble/curves/abstract/utils");
18369
18454
  var import_sha23 = require("@noble/hashes/sha2");
18370
18455
  function getTransferPackageSigningPayload(transferID, transferPackage) {
18371
18456
  const encryptedPayload = transferPackage.keyTweakPackage;
@@ -18374,7 +18459,7 @@ function getTransferPackageSigningPayload(transferID, transferPackage) {
18374
18459
  ).map(([key, value]) => ({ key, value }));
18375
18460
  pairs.sort((a, b) => a.key.localeCompare(b.key));
18376
18461
  const encoder = new TextEncoder();
18377
- let message = (0, import_utils10.hexToBytes)(transferID.replaceAll("-", ""));
18462
+ let message = (0, import_utils11.hexToBytes)(transferID.replaceAll("-", ""));
18378
18463
  for (const pair of pairs) {
18379
18464
  const keyPart = encoder.encode(pair.key + ":");
18380
18465
  const separator = encoder.encode(";");
@@ -18727,7 +18812,7 @@ function getEphemeralAnchorOutput() {
18727
18812
 
18728
18813
  // src/utils/unilateral-exit.ts
18729
18814
  init_buffer();
18730
- var import_utils11 = require("@noble/curves/abstract/utils");
18815
+ var import_utils12 = require("@noble/curves/abstract/utils");
18731
18816
  var import_legacy = require("@noble/hashes/legacy");
18732
18817
  var import_sha24 = require("@noble/hashes/sha2");
18733
18818
  var btc3 = __toESM(require("@scure/btc-signer"), 1);
@@ -18742,7 +18827,7 @@ function isEphemeralAnchorOutput(script, amount) {
18742
18827
  }
18743
18828
  async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network) {
18744
18829
  const result = [];
18745
- const nodes = nodeHexStrings.map((hex) => TreeNode.decode((0, import_utils11.hexToBytes)(hex)));
18830
+ const nodes = nodeHexStrings.map((hex) => TreeNode.decode((0, import_utils12.hexToBytes)(hex)));
18746
18831
  const nodeMap = /* @__PURE__ */ new Map();
18747
18832
  for (const node of nodes) {
18748
18833
  nodeMap.set(node.id, node);
@@ -18798,10 +18883,10 @@ async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network)
18798
18883
  }
18799
18884
  }
18800
18885
  for (const chainNode of chain) {
18801
- const nodeTx = (0, import_utils11.bytesToHex)(chainNode.nodeTx);
18886
+ const nodeTx = (0, import_utils12.bytesToHex)(chainNode.nodeTx);
18802
18887
  transactions.push(nodeTx);
18803
18888
  if (chainNode.id === node.id) {
18804
- const refundTx = (0, import_utils11.bytesToHex)(chainNode.refundTx);
18889
+ const refundTx = (0, import_utils12.bytesToHex)(chainNode.refundTx);
18805
18890
  transactions.push(refundTx);
18806
18891
  }
18807
18892
  }
@@ -18831,7 +18916,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
18831
18916
  `Node hex string at index ${i} appears to be a raw transaction hex, not a TreeNode protobuf. Use 'leafidtohex' command to convert node IDs to proper hex strings.`
18832
18917
  );
18833
18918
  }
18834
- const nodeBytes = (0, import_utils11.hexToBytes)(hex);
18919
+ const nodeBytes = (0, import_utils12.hexToBytes)(hex);
18835
18920
  const node = TreeNode.decode(nodeBytes);
18836
18921
  if (!node.id) {
18837
18922
  throw new Error(
@@ -18907,7 +18992,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
18907
18992
  }
18908
18993
  }
18909
18994
  for (const chainNode of chain) {
18910
- let nodeTxHex = (0, import_utils11.bytesToHex)(chainNode.nodeTx);
18995
+ let nodeTxHex = (0, import_utils12.bytesToHex)(chainNode.nodeTx);
18911
18996
  try {
18912
18997
  const txObj = getTxFromRawTxHex(nodeTxHex);
18913
18998
  const txid = getTxId(txObj);
@@ -18924,7 +19009,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
18924
19009
  for (let i = txObj.outputsLength - 1; i >= 0; i--) {
18925
19010
  const output = txObj.getOutput(i);
18926
19011
  if (output?.amount === 0n && output.script) {
18927
- anchorOutputScriptHex = (0, import_utils11.bytesToHex)(output.script);
19012
+ anchorOutputScriptHex = (0, import_utils12.bytesToHex)(output.script);
18928
19013
  break;
18929
19014
  }
18930
19015
  }
@@ -18945,11 +19030,11 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
18945
19030
  usedUtxos,
18946
19031
  correctedParentTx
18947
19032
  } = constructFeeBumpTx(nodeTxHex, availableUtxos, feeRate, void 0);
18948
- const feeBumpTx = btc3.Transaction.fromPSBT((0, import_utils11.hexToBytes)(nodeFeeBumpPsbt));
19033
+ const feeBumpTx = btc3.Transaction.fromPSBT((0, import_utils12.hexToBytes)(nodeFeeBumpPsbt));
18949
19034
  var feeBumpOut = feeBumpTx.outputsLength === 1 ? feeBumpTx.getOutput(0) : null;
18950
19035
  var feeBumpOutPubKey = null;
18951
19036
  for (const usedUtxo of usedUtxos) {
18952
- if (feeBumpOut && (0, import_utils11.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
19037
+ if (feeBumpOut && (0, import_utils12.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
18953
19038
  feeBumpOutPubKey = usedUtxo.publicKey;
18954
19039
  }
18955
19040
  const index = availableUtxos.findIndex(
@@ -18964,20 +19049,20 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
18964
19049
  txid: getTxId(feeBumpTx),
18965
19050
  vout: 0,
18966
19051
  value: feeBumpOut.amount,
18967
- script: (0, import_utils11.bytesToHex)(feeBumpOut.script),
19052
+ script: (0, import_utils12.bytesToHex)(feeBumpOut.script),
18968
19053
  publicKey: feeBumpOutPubKey
18969
19054
  });
18970
19055
  const finalNodeTx = correctedParentTx || nodeTxHex;
18971
19056
  txPackages.push({ tx: finalNodeTx, feeBumpPsbt: nodeFeeBumpPsbt });
18972
19057
  if (chainNode.id === node.id) {
18973
- let refundTxHex = (0, import_utils11.bytesToHex)(chainNode.refundTx);
19058
+ let refundTxHex = (0, import_utils12.bytesToHex)(chainNode.refundTx);
18974
19059
  try {
18975
19060
  const txObj = getTxFromRawTxHex(refundTxHex);
18976
19061
  let anchorOutputScriptHex;
18977
19062
  for (let i = txObj.outputsLength - 1; i >= 0; i--) {
18978
19063
  const output = txObj.getOutput(i);
18979
19064
  if (output?.amount === 0n && output.script) {
18980
- anchorOutputScriptHex = (0, import_utils11.bytesToHex)(output.script);
19065
+ anchorOutputScriptHex = (0, import_utils12.bytesToHex)(output.script);
18981
19066
  break;
18982
19067
  }
18983
19068
  }
@@ -19000,12 +19085,12 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
19000
19085
  void 0
19001
19086
  );
19002
19087
  const feeBumpTx2 = btc3.Transaction.fromPSBT(
19003
- (0, import_utils11.hexToBytes)(refundFeeBump.feeBumpPsbt)
19088
+ (0, import_utils12.hexToBytes)(refundFeeBump.feeBumpPsbt)
19004
19089
  );
19005
19090
  var feeBumpOut = feeBumpTx2.outputsLength === 1 ? feeBumpTx2.getOutput(0) : null;
19006
19091
  var feeBumpOutPubKey = null;
19007
19092
  for (const usedUtxo of usedUtxos) {
19008
- if (feeBumpOut && (0, import_utils11.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
19093
+ if (feeBumpOut && (0, import_utils12.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
19009
19094
  feeBumpOutPubKey = usedUtxo.publicKey;
19010
19095
  }
19011
19096
  const index = availableUtxos.findIndex(
@@ -19020,7 +19105,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
19020
19105
  txid: getTxId(feeBumpTx2),
19021
19106
  vout: 0,
19022
19107
  value: feeBumpOut.amount,
19023
- script: (0, import_utils11.bytesToHex)(feeBumpOut.script),
19108
+ script: (0, import_utils12.bytesToHex)(feeBumpOut.script),
19024
19109
  publicKey: feeBumpOutPubKey
19025
19110
  });
19026
19111
  txPackages.push({
@@ -19115,10 +19200,10 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
19115
19200
  if (!fundingUtxo) {
19116
19201
  throw new Error(`UTXO at index ${i} is undefined`);
19117
19202
  }
19118
- const pubKeyHash = hash160((0, import_utils11.hexToBytes)(fundingUtxo.publicKey));
19203
+ const pubKeyHash = hash160((0, import_utils12.hexToBytes)(fundingUtxo.publicKey));
19119
19204
  const scriptToUse = new Uint8Array([0, 20, ...pubKeyHash]);
19120
- const providedScript = (0, import_utils11.hexToBytes)(fundingUtxo.script);
19121
- if ((0, import_utils11.bytesToHex)(scriptToUse) !== (0, import_utils11.bytesToHex)(providedScript)) {
19205
+ const providedScript = (0, import_utils12.hexToBytes)(fundingUtxo.script);
19206
+ if ((0, import_utils12.bytesToHex)(scriptToUse) !== (0, import_utils12.bytesToHex)(providedScript)) {
19122
19207
  throw new Error(
19123
19208
  `\u274C Derived script doesn't match provided script for UTXO ${i + 1}.`
19124
19209
  );
@@ -19183,7 +19268,7 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
19183
19268
  }
19184
19269
  let psbtHex;
19185
19270
  try {
19186
- psbtHex = (0, import_utils11.bytesToHex)(builder.toPSBT());
19271
+ psbtHex = (0, import_utils12.bytesToHex)(builder.toPSBT());
19187
19272
  } catch (error) {
19188
19273
  throw new Error(`Failed to extract transaction: ${error}`);
19189
19274
  }
@@ -19358,13 +19443,13 @@ var NativeSparkFrost = class {
19358
19443
  init_buffer();
19359
19444
  var import_secp256k17 = require("@bitcoinerlab/secp256k1");
19360
19445
  var import_lrc20_sdk2 = require("@buildonspark/lrc20-sdk");
19361
- var import_utils12 = require("@noble/curves/abstract/utils");
19446
+ var import_utils13 = require("@noble/curves/abstract/utils");
19362
19447
  var import_secp256k18 = require("@noble/curves/secp256k1");
19363
19448
  var import_sha25 = require("@noble/hashes/sha2");
19364
19449
  var import_bip32 = require("@scure/bip32");
19365
19450
  var import_bip39 = require("@scure/bip39");
19366
19451
  var import_english = require("@scure/bip39/wordlists/english");
19367
- var import_utils13 = require("@scure/btc-signer/utils");
19452
+ var import_utils14 = require("@scure/btc-signer/utils");
19368
19453
  var ecies = __toESM(require("eciesjs"), 1);
19369
19454
 
19370
19455
  // src/constants.ts
@@ -19372,7 +19457,7 @@ init_buffer();
19372
19457
  var import_core8 = require("@lightsparkdev/core");
19373
19458
  var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
19374
19459
  var isBun = globalThis.Bun !== void 0;
19375
- var packageVersion = true ? "0.2.4" : "unknown";
19460
+ var packageVersion = true ? "0.2.6" : "unknown";
19376
19461
  var baseEnvStr = "unknown";
19377
19462
  if (isBun) {
19378
19463
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -19481,7 +19566,7 @@ var DefaultSparkSigner = class {
19481
19566
  });
19482
19567
  }
19483
19568
  const receiverEciesPrivKey = ecies.PrivateKey.fromHex(
19484
- (0, import_utils12.bytesToHex)(this.identityKey.privateKey)
19569
+ (0, import_utils13.bytesToHex)(this.identityKey.privateKey)
19485
19570
  );
19486
19571
  const privateKey = ecies.decrypt(receiverEciesPrivKey.toHex(), ciphertext);
19487
19572
  return privateKey;
@@ -19615,7 +19700,7 @@ var DefaultSparkSigner = class {
19615
19700
  threshold,
19616
19701
  numShares
19617
19702
  }) {
19618
- const secretAsInt = (0, import_utils12.bytesToNumberBE)(secret);
19703
+ const secretAsInt = (0, import_utils13.bytesToNumberBE)(secret);
19619
19704
  return splitSecretWithProofs(secretAsInt, curveOrder, threshold, numShares);
19620
19705
  }
19621
19706
  async signFrost({
@@ -19691,7 +19776,7 @@ var DefaultSparkSigner = class {
19691
19776
  }
19692
19777
  async createSparkWalletFromSeed(seed, accountNumber) {
19693
19778
  if (typeof seed === "string") {
19694
- seed = (0, import_utils12.hexToBytes)(seed);
19779
+ seed = (0, import_utils13.hexToBytes)(seed);
19695
19780
  }
19696
19781
  const {
19697
19782
  identityKey,
@@ -19703,7 +19788,7 @@ var DefaultSparkSigner = class {
19703
19788
  this.depositKey = depositKey;
19704
19789
  this.signingKey = signingKey.hdKey;
19705
19790
  this.staticDepositKey = staticDepositKey.hdKey;
19706
- return (0, import_utils12.bytesToHex)(identityKey.publicKey);
19791
+ return (0, import_utils13.bytesToHex)(identityKey.publicKey);
19707
19792
  }
19708
19793
  async signMessageWithIdentityKey(message, compact) {
19709
19794
  if (!this.identityKey?.privateKey) {
@@ -19724,7 +19809,7 @@ var DefaultSparkSigner = class {
19724
19809
  });
19725
19810
  }
19726
19811
  const receiverEciesPrivKey = ecies.PrivateKey.fromHex(
19727
- (0, import_utils12.bytesToHex)(this.identityKey.privateKey)
19812
+ (0, import_utils13.bytesToHex)(this.identityKey.privateKey)
19728
19813
  );
19729
19814
  const privateKey = ecies.decrypt(receiverEciesPrivKey.toHex(), ciphertext);
19730
19815
  const publicKey = import_secp256k18.secp256k1.getPublicKey(privateKey);
@@ -19776,15 +19861,15 @@ var DefaultSparkSigner = class {
19776
19861
  }
19777
19862
  signTransactionIndex(tx, index, publicKey) {
19778
19863
  let privateKey;
19779
- if ((0, import_utils12.equalBytes)(publicKey, this.identityKey?.publicKey ?? new Uint8Array())) {
19864
+ if ((0, import_utils13.equalBytes)(publicKey, this.identityKey?.publicKey ?? new Uint8Array())) {
19780
19865
  privateKey = this.identityKey?.privateKey;
19781
- } else if ((0, import_utils12.equalBytes)(publicKey, this.depositKey?.publicKey ?? new Uint8Array())) {
19866
+ } else if ((0, import_utils13.equalBytes)(publicKey, this.depositKey?.publicKey ?? new Uint8Array())) {
19782
19867
  privateKey = this.depositKey?.privateKey;
19783
19868
  }
19784
19869
  if (!privateKey) {
19785
19870
  throw new ValidationError("Private key not found for public key", {
19786
19871
  field: "privateKey",
19787
- value: (0, import_utils12.bytesToHex)(publicKey)
19872
+ value: (0, import_utils13.bytesToHex)(publicKey)
19788
19873
  });
19789
19874
  }
19790
19875
  tx.signIdx(privateKey, index);
@@ -19857,7 +19942,7 @@ var ReactNativeSparkSigner = class extends DefaultSparkSigner {
19857
19942
  // src/spark-wallet/spark-wallet.ts
19858
19943
  init_buffer();
19859
19944
  var import_core12 = require("@lightsparkdev/core");
19860
- var import_utils24 = require("@noble/curves/abstract/utils");
19945
+ var import_utils25 = require("@noble/curves/abstract/utils");
19861
19946
  var import_secp256k115 = require("@noble/curves/secp256k1");
19862
19947
  var import_bip392 = require("@scure/bip39");
19863
19948
  var import_english2 = require("@scure/bip39/wordlists/english");
@@ -20465,15 +20550,19 @@ var LightningSendFeeEstimate = `
20465
20550
  ${FRAGMENT13}
20466
20551
  `;
20467
20552
 
20468
- // src/graphql/queries/Transfer.ts
20553
+ // src/graphql/queries/Transfers.ts
20469
20554
  init_buffer();
20470
- var GetTransfer = `
20471
- query Transfer($transfer_spark_id: UUID!) {
20472
- transfer(transfer_spark_id: $transfer_spark_id) {
20555
+ var GetTransfers = `
20556
+ query Transfers($transfer_spark_ids: [UUID!]!) {
20557
+ transfers(transfer_spark_ids: $transfer_spark_ids) {
20473
20558
  ...TransferFragment
20559
+ transfer_user_request: user_request {
20560
+ ...UserRequestFragment
20561
+ }
20474
20562
  }
20475
20563
  }
20476
20564
  ${FRAGMENT2}
20565
+ ${FRAGMENT6}
20477
20566
  `;
20478
20567
 
20479
20568
  // src/graphql/queries/UserRequest.ts
@@ -20830,14 +20919,47 @@ var SspClient = class {
20830
20919
  }
20831
20920
  });
20832
20921
  }
20833
- async getTransfer(id) {
20922
+ async getTransfers(ids) {
20834
20923
  return await this.executeRawQuery({
20835
- queryPayload: GetTransfer,
20924
+ queryPayload: GetTransfers,
20836
20925
  variables: {
20837
- transfer_spark_id: id
20926
+ transfer_spark_ids: ids
20838
20927
  },
20839
20928
  constructObject: (response) => {
20840
- return TransferFromJson(response.transfer);
20929
+ return response.transfers.map((transfer) => {
20930
+ const transferObj = TransferFromJson(
20931
+ transfer
20932
+ );
20933
+ switch (transfer.transfer_user_request.__typename) {
20934
+ case "ClaimStaticDeposit":
20935
+ transferObj.userRequest = ClaimStaticDepositFromJson(
20936
+ transfer.transfer_user_request
20937
+ );
20938
+ break;
20939
+ case "CoopExitRequest":
20940
+ transferObj.userRequest = CoopExitRequestFromJson(
20941
+ transfer.transfer_user_request
20942
+ );
20943
+ break;
20944
+ case "LeavesSwapRequest":
20945
+ transferObj.userRequest = LeavesSwapRequestFromJson(
20946
+ transfer.transfer_user_request
20947
+ );
20948
+ break;
20949
+ case "LightningReceiveRequest":
20950
+ transferObj.userRequest = LightningReceiveRequestFromJson(
20951
+ transfer.transfer_user_request
20952
+ );
20953
+ break;
20954
+ case "LightningSendRequest":
20955
+ transferObj.userRequest = LightningSendRequestFromJson(
20956
+ transfer.transfer_user_request
20957
+ );
20958
+ break;
20959
+ }
20960
+ const { userRequestId, ...rest } = transferObj;
20961
+ return rest;
20962
+ });
20841
20963
  }
20842
20964
  });
20843
20965
  }
@@ -21002,7 +21124,7 @@ var WalletConfigService = class {
21002
21124
  }
21003
21125
  }
21004
21126
  getCoordinatorAddress() {
21005
- const coordinator = this.config.signingOperators[this.config.coodinatorIdentifier];
21127
+ const coordinator = this.config.signingOperators[this.config.coordinatorIdentifier];
21006
21128
  if (!coordinator) {
21007
21129
  throw new ConfigurationError(
21008
21130
  "Coordinator not found in signing operators",
@@ -21023,7 +21145,7 @@ var WalletConfigService = class {
21023
21145
  return this.config.threshold;
21024
21146
  }
21025
21147
  getCoordinatorIdentifier() {
21026
- return this.config.coodinatorIdentifier;
21148
+ return this.config.coordinatorIdentifier;
21027
21149
  }
21028
21150
  getExpectedWithdrawBondSats() {
21029
21151
  return this.config.expectedWithdrawBondSats;
@@ -21064,9 +21186,17 @@ var WalletConfigService = class {
21064
21186
  getElectrsUrl() {
21065
21187
  return this.config.electrsUrl;
21066
21188
  }
21189
+ getSspBaseUrl() {
21190
+ return this.config.sspClientOptions.baseUrl;
21191
+ }
21067
21192
  getSspIdentityPublicKey() {
21068
21193
  return this.config.sspClientOptions.identityPublicKey;
21069
21194
  }
21195
+ getConsoleOptions() {
21196
+ return {
21197
+ ...this.config.console
21198
+ };
21199
+ }
21070
21200
  };
21071
21201
 
21072
21202
  // src/services/connection.ts
@@ -24881,7 +25011,7 @@ var import_uuidv73 = require("uuidv7");
24881
25011
 
24882
25012
  // src/services/transfer.ts
24883
25013
  init_buffer();
24884
- var import_utils14 = require("@noble/curves/abstract/utils");
25014
+ var import_utils15 = require("@noble/curves/abstract/utils");
24885
25015
  var import_secp256k19 = require("@noble/curves/secp256k1");
24886
25016
  var import_sha28 = require("@noble/hashes/sha2");
24887
25017
  var import_btc_signer2 = require("@scure/btc-signer");
@@ -25252,7 +25382,7 @@ var BaseTransferService = class {
25252
25382
  }
25253
25383
  async prepareSendTransferKeyTweaks(transferID, receiverIdentityPubkey, leaves, cpfpRefundSignatureMap, directRefundSignatureMap, directFromCpfpRefundSignatureMap) {
25254
25384
  const receiverEciesPubKey = ecies2.PublicKey.fromHex(
25255
- (0, import_utils14.bytesToHex)(receiverIdentityPubkey)
25385
+ (0, import_utils15.bytesToHex)(receiverIdentityPubkey)
25256
25386
  );
25257
25387
  const leavesTweaksMap = /* @__PURE__ */ new Map();
25258
25388
  for (const leaf of leaves) {
@@ -25293,7 +25423,7 @@ var BaseTransferService = class {
25293
25423
  throw new Error(`Share not found for operator ${operator.id}`);
25294
25424
  }
25295
25425
  const pubkeyTweak = import_secp256k19.secp256k1.getPublicKey(
25296
- (0, import_utils14.numberToBytesBE)(share.share, 32),
25426
+ (0, import_utils15.numberToBytesBE)(share.share, 32),
25297
25427
  true
25298
25428
  );
25299
25429
  pubkeySharesTweak.set(identifier, pubkeyTweak);
@@ -25318,7 +25448,7 @@ var BaseTransferService = class {
25318
25448
  leafTweaksMap.set(identifier, {
25319
25449
  leafId: leaf.leaf.id,
25320
25450
  secretShareTweak: {
25321
- secretShare: (0, import_utils14.numberToBytesBE)(share.share, 32),
25451
+ secretShare: (0, import_utils15.numberToBytesBE)(share.share, 32),
25322
25452
  proofs: share.proofs
25323
25453
  },
25324
25454
  pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak),
@@ -25341,7 +25471,7 @@ var BaseTransferService = class {
25341
25471
  return void 0;
25342
25472
  }
25343
25473
  compareTransfers(transfer1, transfer2) {
25344
- return transfer1.id === transfer2.id && (0, import_utils14.equalBytes)(
25474
+ return transfer1.id === transfer2.id && (0, import_utils15.equalBytes)(
25345
25475
  transfer1.senderIdentityPublicKey,
25346
25476
  transfer2.senderIdentityPublicKey
25347
25477
  ) && transfer1.status === transfer2.status && transfer1.totalValue === transfer2.totalValue && transfer1.expiryTime?.getTime() === transfer2.expiryTime?.getTime() && transfer1.leaves.length === transfer2.leaves.length;
@@ -25638,7 +25768,7 @@ var TransferService = class extends BaseTransferService {
25638
25768
  }
25639
25769
  const nodeTx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
25640
25770
  const cpfpNodeOutPoint = {
25641
- txid: (0, import_utils14.hexToBytes)(getTxId(nodeTx)),
25771
+ txid: (0, import_utils15.hexToBytes)(getTxId(nodeTx)),
25642
25772
  index: 0
25643
25773
  };
25644
25774
  let directNodeTx;
@@ -25646,7 +25776,7 @@ var TransferService = class extends BaseTransferService {
25646
25776
  if (leaf.leaf.directTx.length > 0) {
25647
25777
  directNodeTx = getTxFromRawTxBytes(leaf.leaf.directTx);
25648
25778
  directNodeOutPoint = {
25649
- txid: (0, import_utils14.hexToBytes)(getTxId(directNodeTx)),
25779
+ txid: (0, import_utils15.hexToBytes)(getTxId(directNodeTx)),
25650
25780
  index: 0
25651
25781
  };
25652
25782
  }
@@ -25788,7 +25918,7 @@ var TransferService = class extends BaseTransferService {
25788
25918
  throw new Error(`Share not found for operator ${operator.id}`);
25789
25919
  }
25790
25920
  const pubkeyTweak = import_secp256k19.secp256k1.getPublicKey(
25791
- (0, import_utils14.numberToBytesBE)(share.share, 32)
25921
+ (0, import_utils15.numberToBytesBE)(share.share, 32)
25792
25922
  );
25793
25923
  pubkeySharesTweak.set(identifier, pubkeyTweak);
25794
25924
  }
@@ -25801,7 +25931,7 @@ var TransferService = class extends BaseTransferService {
25801
25931
  leafTweaksMap.set(identifier, {
25802
25932
  leafId: leaf.leaf.id,
25803
25933
  secretShareTweak: {
25804
- secretShare: (0, import_utils14.numberToBytesBE)(share.share, 32),
25934
+ secretShare: (0, import_utils15.numberToBytesBE)(share.share, 32),
25805
25935
  proofs: share.proofs
25806
25936
  },
25807
25937
  pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak)
@@ -25981,13 +26111,13 @@ var TransferService = class extends BaseTransferService {
25981
26111
  });
25982
26112
  }
25983
26113
  const newCpfpRefundOutPoint = {
25984
- txid: (0, import_utils14.hexToBytes)(getTxId(cpfpNodeTx)),
26114
+ txid: (0, import_utils15.hexToBytes)(getTxId(cpfpNodeTx)),
25985
26115
  index: 0
25986
26116
  };
25987
26117
  let newDirectRefundOutPoint;
25988
26118
  if (newDirectNodeTx) {
25989
26119
  newDirectRefundOutPoint = {
25990
- txid: (0, import_utils14.hexToBytes)(getTxId(newDirectNodeTx)),
26120
+ txid: (0, import_utils15.hexToBytes)(getTxId(newDirectNodeTx)),
25991
26121
  index: 0
25992
26122
  };
25993
26123
  }
@@ -26115,7 +26245,7 @@ var TransferService = class extends BaseTransferService {
26115
26245
  const refundTx = getTxFromRawTxBytes(node.refundTx);
26116
26246
  const refundSequence = refundTx.getInput(0).sequence || 0;
26117
26247
  const newNodeOutPoint = {
26118
- txid: (0, import_utils14.hexToBytes)(getTxId(nodeTx)),
26248
+ txid: (0, import_utils15.hexToBytes)(getTxId(nodeTx)),
26119
26249
  index: 0
26120
26250
  };
26121
26251
  const {
@@ -26152,13 +26282,13 @@ var TransferService = class extends BaseTransferService {
26152
26282
  });
26153
26283
  }
26154
26284
  const newCpfpRefundOutPoint = {
26155
- txid: (0, import_utils14.hexToBytes)(getTxId(newNodeTx)),
26285
+ txid: (0, import_utils15.hexToBytes)(getTxId(newNodeTx)),
26156
26286
  index: 0
26157
26287
  };
26158
26288
  let newDirectRefundOutPoint;
26159
26289
  if (newDirectNodeTx) {
26160
26290
  newDirectRefundOutPoint = {
26161
- txid: (0, import_utils14.hexToBytes)(getTxId(newDirectNodeTx)),
26291
+ txid: (0, import_utils15.hexToBytes)(getTxId(newDirectNodeTx)),
26162
26292
  index: 0
26163
26293
  };
26164
26294
  }
@@ -26392,13 +26522,13 @@ var TransferService = class extends BaseTransferService {
26392
26522
  };
26393
26523
  const signingPublicKey = await this.config.signer.getPublicKeyFromDerivation(keyDerivation);
26394
26524
  const cpfpRefundOutPoint = {
26395
- txid: (0, import_utils14.hexToBytes)(getTxId(nodeTx)),
26525
+ txid: (0, import_utils15.hexToBytes)(getTxId(nodeTx)),
26396
26526
  index: 0
26397
26527
  };
26398
26528
  let directRefundOutPoint;
26399
26529
  if (directNodeTx) {
26400
26530
  directRefundOutPoint = {
26401
- txid: (0, import_utils14.hexToBytes)(getTxId(directNodeTx)),
26531
+ txid: (0, import_utils15.hexToBytes)(getTxId(directNodeTx)),
26402
26532
  index: 0
26403
26533
  };
26404
26534
  }
@@ -26774,9 +26904,9 @@ var CoopExitService = class extends BaseTransferService {
26774
26904
  init_buffer();
26775
26905
  var import_secp256k110 = require("@noble/curves/secp256k1");
26776
26906
  var import_sha29 = require("@noble/hashes/sha2");
26777
- var import_utils15 = require("@noble/hashes/utils");
26907
+ var import_utils16 = require("@noble/hashes/utils");
26778
26908
  var import_btc_signer4 = require("@scure/btc-signer");
26779
- var import_utils16 = require("@scure/btc-signer/utils");
26909
+ var import_utils17 = require("@scure/btc-signer/utils");
26780
26910
  var DepositService = class {
26781
26911
  config;
26782
26912
  connectionManager;
@@ -26827,7 +26957,7 @@ var DepositService = class {
26827
26957
  if (operator.identifier === this.config.getCoordinatorIdentifier()) {
26828
26958
  continue;
26829
26959
  }
26830
- const operatorPubkey2 = (0, import_utils15.hexToBytes)(operator.identityPublicKey);
26960
+ const operatorPubkey2 = (0, import_utils16.hexToBytes)(operator.identityPublicKey);
26831
26961
  const operatorSig = address2.depositAddressProof.addressSignatures[operator.identifier];
26832
26962
  if (!operatorSig) {
26833
26963
  throw new ValidationError("Operator signature not found", {
@@ -26912,7 +27042,7 @@ var DepositService = class {
26912
27042
  });
26913
27043
  }
26914
27044
  const depositOutPoint = {
26915
- txid: (0, import_utils15.hexToBytes)(getTxId(depositTx)),
27045
+ txid: (0, import_utils16.hexToBytes)(getTxId(depositTx)),
26916
27046
  index: vout
26917
27047
  };
26918
27048
  const depositTxOut = {
@@ -26931,8 +27061,8 @@ var DepositService = class {
26931
27061
  const { cpfpRefundTx, directRefundTx, directFromCpfpRefundTx } = createRefundTxs({
26932
27062
  sequence: INITIAL_SEQUENCE,
26933
27063
  directSequence: INITIAL_DIRECT_SEQUENCE,
26934
- input: { txid: (0, import_utils15.hexToBytes)(getTxId(cpfpRootTx)), index: 0 },
26935
- directInput: { txid: (0, import_utils15.hexToBytes)(getTxId(directRootTx)), index: 0 },
27064
+ input: { txid: (0, import_utils16.hexToBytes)(getTxId(cpfpRootTx)), index: 0 },
27065
+ directInput: { txid: (0, import_utils16.hexToBytes)(getTxId(directRootTx)), index: 0 },
26936
27066
  amountSats: amount,
26937
27067
  receivingPubkey: signingPubKey,
26938
27068
  network: this.config.getNetwork()
@@ -27062,7 +27192,7 @@ var DepositService = class {
27062
27192
  }
27063
27193
  );
27064
27194
  }
27065
- if (!(0, import_utils16.equalBytes)(treeResp.rootNodeSignatureShares.verifyingKey, verifyingKey)) {
27195
+ if (!(0, import_utils17.equalBytes)(treeResp.rootNodeSignatureShares.verifyingKey, verifyingKey)) {
27066
27196
  throw new ValidationError("Verifying key mismatch", {
27067
27197
  field: "verifyingKey",
27068
27198
  value: treeResp.rootNodeSignatureShares.verifyingKey,
@@ -27226,7 +27356,7 @@ var DepositService = class {
27226
27356
  });
27227
27357
  }
27228
27358
  const depositOutPoint = {
27229
- txid: (0, import_utils15.hexToBytes)(getTxId(depositTx)),
27359
+ txid: (0, import_utils16.hexToBytes)(getTxId(depositTx)),
27230
27360
  index: vout
27231
27361
  };
27232
27362
  const depositTxOut = {
@@ -27239,7 +27369,7 @@ var DepositService = class {
27239
27369
  const signingPubKey = await this.config.signer.getPublicKeyFromDerivation(keyDerivation);
27240
27370
  const { cpfpRefundTx } = createRefundTxs({
27241
27371
  sequence: INITIAL_SEQUENCE,
27242
- input: { txid: (0, import_utils15.hexToBytes)(getTxId(cpfpRootTx)), index: 0 },
27372
+ input: { txid: (0, import_utils16.hexToBytes)(getTxId(cpfpRootTx)), index: 0 },
27243
27373
  amountSats: amount,
27244
27374
  receivingPubkey: signingPubKey,
27245
27375
  network: this.config.getNetwork()
@@ -27309,7 +27439,7 @@ var DepositService = class {
27309
27439
  }
27310
27440
  );
27311
27441
  }
27312
- if (!(0, import_utils16.equalBytes)(treeResp.rootNodeSignatureShares.verifyingKey, verifyingKey)) {
27442
+ if (!(0, import_utils17.equalBytes)(treeResp.rootNodeSignatureShares.verifyingKey, verifyingKey)) {
27313
27443
  throw new ValidationError("Verifying key mismatch", {
27314
27444
  field: "verifyingKey",
27315
27445
  value: treeResp.rootNodeSignatureShares.verifyingKey,
@@ -27385,7 +27515,7 @@ var DepositService = class {
27385
27515
 
27386
27516
  // src/services/lightning.ts
27387
27517
  init_buffer();
27388
- var import_utils17 = require("@noble/curves/abstract/utils");
27518
+ var import_utils18 = require("@noble/curves/abstract/utils");
27389
27519
  var import_secp256k111 = require("@noble/curves/secp256k1");
27390
27520
  var import_sha210 = require("@noble/hashes/sha2");
27391
27521
  var import_uuidv74 = require("uuidv7");
@@ -27472,8 +27602,8 @@ var LightningService = class {
27472
27602
  }) {
27473
27603
  const crypto = getCrypto();
27474
27604
  const randBytes = crypto.getRandomValues(new Uint8Array(32));
27475
- const preimage = (0, import_utils17.numberToBytesBE)(
27476
- (0, import_utils17.bytesToNumberBE)(randBytes) % import_secp256k111.secp256k1.CURVE.n,
27605
+ const preimage = (0, import_utils18.numberToBytesBE)(
27606
+ (0, import_utils18.bytesToNumberBE)(randBytes) % import_secp256k111.secp256k1.CURVE.n,
27477
27607
  32
27478
27608
  );
27479
27609
  return await this.createLightningInvoiceWithPreImage({
@@ -27528,12 +27658,12 @@ var LightningService = class {
27528
27658
  const sparkClient = await this.connectionManager.createSparkClient(
27529
27659
  operator.address
27530
27660
  );
27531
- const userIdentityPublicKey = receiverIdentityPubkey ? (0, import_utils17.hexToBytes)(receiverIdentityPubkey) : await this.config.signer.getIdentityPublicKey();
27661
+ const userIdentityPublicKey = receiverIdentityPubkey ? (0, import_utils18.hexToBytes)(receiverIdentityPubkey) : await this.config.signer.getIdentityPublicKey();
27532
27662
  try {
27533
27663
  await sparkClient.store_preimage_share({
27534
27664
  paymentHash,
27535
27665
  preimageShare: {
27536
- secretShare: (0, import_utils17.numberToBytesBE)(share.share, 32),
27666
+ secretShare: (0, import_utils18.numberToBytesBE)(share.share, 32),
27537
27667
  proofs: share.proofs
27538
27668
  },
27539
27669
  threshold: this.config.getThreshold(),
@@ -27734,9 +27864,9 @@ var LightningService = class {
27734
27864
 
27735
27865
  // src/services/token-transactions.ts
27736
27866
  init_buffer();
27737
- var import_utils18 = require("@noble/curves/abstract/utils");
27867
+ var import_utils19 = require("@noble/curves/abstract/utils");
27738
27868
  var import_secp256k113 = require("@noble/curves/secp256k1");
27739
- var import_utils19 = require("@noble/hashes/utils");
27869
+ var import_utils20 = require("@noble/hashes/utils");
27740
27870
 
27741
27871
  // src/utils/token-hashing.ts
27742
27872
  init_buffer();
@@ -29184,7 +29314,7 @@ var TokenTransactionService = class {
29184
29314
  this.config.getNetworkType()
29185
29315
  );
29186
29316
  return {
29187
- receiverSparkAddress: (0, import_utils19.hexToBytes)(receiverAddress.identityPublicKey),
29317
+ receiverSparkAddress: (0, import_utils20.hexToBytes)(receiverAddress.identityPublicKey),
29188
29318
  rawTokenIdentifier,
29189
29319
  tokenPublicKey,
29190
29320
  // Remove for full v0 deprecation
@@ -29222,7 +29352,7 @@ var TokenTransactionService = class {
29222
29352
  const tokenOutputs = tokenOutputData.map((output) => ({
29223
29353
  ownerPublicKey: output.receiverSparkAddress,
29224
29354
  tokenPublicKey: output.tokenPublicKey,
29225
- tokenAmount: (0, import_utils18.numberToBytesBE)(output.tokenAmount, 16)
29355
+ tokenAmount: (0, import_utils19.numberToBytesBE)(output.tokenAmount, 16)
29226
29356
  }));
29227
29357
  if (availableTokenAmount > totalRequestedAmount) {
29228
29358
  const changeAmount = availableTokenAmount - totalRequestedAmount;
@@ -29230,7 +29360,7 @@ var TokenTransactionService = class {
29230
29360
  tokenOutputs.push({
29231
29361
  ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
29232
29362
  tokenPublicKey: firstTokenPublicKey,
29233
- tokenAmount: (0, import_utils18.numberToBytesBE)(changeAmount, 16)
29363
+ tokenAmount: (0, import_utils19.numberToBytesBE)(changeAmount, 16)
29234
29364
  });
29235
29365
  }
29236
29366
  return {
@@ -29261,7 +29391,7 @@ var TokenTransactionService = class {
29261
29391
  (output) => ({
29262
29392
  ownerPublicKey: output.receiverSparkAddress,
29263
29393
  tokenIdentifier: output.rawTokenIdentifier,
29264
- tokenAmount: (0, import_utils18.numberToBytesBE)(output.tokenAmount, 16)
29394
+ tokenAmount: (0, import_utils19.numberToBytesBE)(output.tokenAmount, 16)
29265
29395
  })
29266
29396
  );
29267
29397
  if (availableTokenAmount > totalRequestedAmount) {
@@ -29270,7 +29400,7 @@ var TokenTransactionService = class {
29270
29400
  tokenOutputs.push({
29271
29401
  ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
29272
29402
  tokenIdentifier: firstTokenIdentifierBytes,
29273
- tokenAmount: (0, import_utils18.numberToBytesBE)(changeAmount, 16)
29403
+ tokenAmount: (0, import_utils19.numberToBytesBE)(changeAmount, 16)
29274
29404
  });
29275
29405
  }
29276
29406
  return {
@@ -29296,7 +29426,7 @@ var TokenTransactionService = class {
29296
29426
  for (const [_, operator] of Object.entries(
29297
29427
  this.config.getSigningOperators()
29298
29428
  )) {
29299
- operatorKeys.push((0, import_utils19.hexToBytes)(operator.identityPublicKey));
29429
+ operatorKeys.push((0, import_utils20.hexToBytes)(operator.identityPublicKey));
29300
29430
  }
29301
29431
  return operatorKeys;
29302
29432
  }
@@ -29380,7 +29510,7 @@ var TokenTransactionService = class {
29380
29510
  {
29381
29511
  field: "revocationCommitment",
29382
29512
  value: derivedRevocationCommitment,
29383
- expected: (0, import_utils18.bytesToHex)(outputsToSpendCommitments[outputIndex]),
29513
+ expected: (0, import_utils19.bytesToHex)(outputsToSpendCommitments[outputIndex]),
29384
29514
  outputIndex
29385
29515
  }
29386
29516
  )
@@ -29406,7 +29536,7 @@ var TokenTransactionService = class {
29406
29536
  threshold
29407
29537
  );
29408
29538
  }
29409
- return (0, import_utils18.bytesToHex)(finalTokenTransactionHash);
29539
+ return (0, import_utils19.bytesToHex)(finalTokenTransactionHash);
29410
29540
  }
29411
29541
  async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
29412
29542
  const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
@@ -29420,7 +29550,7 @@ var TokenTransactionService = class {
29420
29550
  finalTokenTransactionHash,
29421
29551
  signingOperators
29422
29552
  );
29423
- return (0, import_utils18.bytesToHex)(finalTokenTransactionHash);
29553
+ return (0, import_utils19.bytesToHex)(finalTokenTransactionHash);
29424
29554
  }
29425
29555
  async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
29426
29556
  const sparkClient = await this.connectionManager.createSparkClient(
@@ -29644,7 +29774,7 @@ var TokenTransactionService = class {
29644
29774
  const identityPublicKey = await this.config.signer.getIdentityPublicKey();
29645
29775
  const payload = {
29646
29776
  finalTokenTransactionHash,
29647
- operatorIdentityPublicKey: (0, import_utils19.hexToBytes)(operator.identityPublicKey)
29777
+ operatorIdentityPublicKey: (0, import_utils20.hexToBytes)(operator.identityPublicKey)
29648
29778
  };
29649
29779
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
29650
29780
  let operatorSpecificSignatures = [];
@@ -29851,19 +29981,27 @@ var TokenTransactionService = class {
29851
29981
  issuerPublicKeys,
29852
29982
  tokenTransactionHashes,
29853
29983
  tokenIdentifiers,
29854
- outputIds
29984
+ outputIds,
29985
+ pageSize,
29986
+ offset
29855
29987
  } = params;
29856
29988
  const sparkClient = await this.connectionManager.createSparkClient(
29857
29989
  this.config.getCoordinatorAddress()
29858
29990
  );
29859
29991
  let queryParams = {
29860
- tokenPublicKeys: issuerPublicKeys?.map(import_utils19.hexToBytes),
29861
- ownerPublicKeys: ownerPublicKeys?.map(import_utils19.hexToBytes),
29862
- tokenIdentifiers: tokenIdentifiers?.map(import_utils19.hexToBytes),
29863
- tokenTransactionHashes: tokenTransactionHashes?.map(import_utils19.hexToBytes),
29992
+ tokenPublicKeys: issuerPublicKeys?.map(import_utils20.hexToBytes),
29993
+ ownerPublicKeys: ownerPublicKeys?.map(import_utils20.hexToBytes),
29994
+ tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
29995
+ const { tokenIdentifier } = decodeBech32mTokenIdentifier(
29996
+ identifier,
29997
+ this.config.getNetworkType()
29998
+ );
29999
+ return tokenIdentifier;
30000
+ }),
30001
+ tokenTransactionHashes: tokenTransactionHashes?.map(import_utils20.hexToBytes),
29864
30002
  outputIds: outputIds || [],
29865
- limit: 100,
29866
- offset: 0
30003
+ limit: pageSize,
30004
+ offset
29867
30005
  };
29868
30006
  try {
29869
30007
  const response = await sparkClient.query_token_transactions(queryParams);
@@ -29913,10 +30051,16 @@ var TokenTransactionService = class {
29913
30051
  this.config.getCoordinatorAddress()
29914
30052
  );
29915
30053
  let queryParams = {
29916
- issuerPublicKeys: issuerPublicKeys?.map(import_utils19.hexToBytes),
29917
- ownerPublicKeys: ownerPublicKeys?.map(import_utils19.hexToBytes),
29918
- tokenIdentifiers: tokenIdentifiers?.map(import_utils19.hexToBytes),
29919
- tokenTransactionHashes: tokenTransactionHashes?.map(import_utils19.hexToBytes),
30054
+ issuerPublicKeys: issuerPublicKeys?.map(import_utils20.hexToBytes),
30055
+ ownerPublicKeys: ownerPublicKeys?.map(import_utils20.hexToBytes),
30056
+ tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
30057
+ const { tokenIdentifier } = decodeBech32mTokenIdentifier(
30058
+ identifier,
30059
+ this.config.getNetworkType()
30060
+ );
30061
+ return tokenIdentifier;
30062
+ }),
30063
+ tokenTransactionHashes: tokenTransactionHashes?.map(import_utils20.hexToBytes),
29920
30064
  outputIds: outputIds || [],
29921
30065
  limit: pageSize,
29922
30066
  offset
@@ -29945,7 +30089,7 @@ var TokenTransactionService = class {
29945
30089
  });
29946
30090
  }
29947
30091
  const exactMatch = tokenOutputs.find(
29948
- (item) => (0, import_utils18.bytesToNumberBE)(item.output.tokenAmount) === tokenAmount
30092
+ (item) => (0, import_utils19.bytesToNumberBE)(item.output.tokenAmount) === tokenAmount
29949
30093
  );
29950
30094
  if (exactMatch) {
29951
30095
  return [exactMatch];
@@ -29956,7 +30100,7 @@ var TokenTransactionService = class {
29956
30100
  for (const outputWithPreviousTransactionData of tokenOutputs) {
29957
30101
  if (remainingAmount <= 0n) break;
29958
30102
  selectedOutputs.push(outputWithPreviousTransactionData);
29959
- remainingAmount -= (0, import_utils18.bytesToNumberBE)(
30103
+ remainingAmount -= (0, import_utils19.bytesToNumberBE)(
29960
30104
  outputWithPreviousTransactionData.output.tokenAmount
29961
30105
  );
29962
30106
  }
@@ -29972,13 +30116,13 @@ var TokenTransactionService = class {
29972
30116
  if (strategy === "SMALL_FIRST") {
29973
30117
  tokenOutputs.sort((a, b) => {
29974
30118
  return Number(
29975
- (0, import_utils18.bytesToNumberBE)(a.output.tokenAmount) - (0, import_utils18.bytesToNumberBE)(b.output.tokenAmount)
30119
+ (0, import_utils19.bytesToNumberBE)(a.output.tokenAmount) - (0, import_utils19.bytesToNumberBE)(b.output.tokenAmount)
29976
30120
  );
29977
30121
  });
29978
30122
  } else {
29979
30123
  tokenOutputs.sort((a, b) => {
29980
30124
  return Number(
29981
- (0, import_utils18.bytesToNumberBE)(b.output.tokenAmount) - (0, import_utils18.bytesToNumberBE)(a.output.tokenAmount)
30125
+ (0, import_utils19.bytesToNumberBE)(b.output.tokenAmount) - (0, import_utils19.bytesToNumberBE)(a.output.tokenAmount)
29982
30126
  );
29983
30127
  });
29984
30128
  }
@@ -29986,7 +30130,7 @@ var TokenTransactionService = class {
29986
30130
  // Helper function for deciding if the signer public key is the identity public key
29987
30131
  async signMessageWithKey(message, publicKey) {
29988
30132
  const tokenSignatures = this.config.getTokenSignatures();
29989
- if ((0, import_utils18.bytesToHex)(publicKey) === (0, import_utils18.bytesToHex)(await this.config.signer.getIdentityPublicKey())) {
30133
+ if ((0, import_utils19.bytesToHex)(publicKey) === (0, import_utils19.bytesToHex)(await this.config.signer.getIdentityPublicKey())) {
29990
30134
  if (tokenSignatures === "SCHNORR") {
29991
30135
  return await this.config.signer.signSchnorrWithIdentityKey(message);
29992
30136
  } else {
@@ -29995,8 +30139,8 @@ var TokenTransactionService = class {
29995
30139
  } else {
29996
30140
  throw new ValidationError("Invalid public key", {
29997
30141
  field: "publicKey",
29998
- value: (0, import_utils18.bytesToHex)(publicKey),
29999
- expected: (0, import_utils18.bytesToHex)(await this.config.signer.getIdentityPublicKey())
30142
+ value: (0, import_utils19.bytesToHex)(publicKey),
30143
+ expected: (0, import_utils19.bytesToHex)(await this.config.signer.getIdentityPublicKey())
30000
30144
  });
30001
30145
  }
30002
30146
  }
@@ -30059,7 +30203,7 @@ var TokenTransactionService = class {
30059
30203
  }
30060
30204
  const payload = {
30061
30205
  finalTokenTransactionHash,
30062
- operatorIdentityPublicKey: (0, import_utils19.hexToBytes)(operator.identityPublicKey)
30206
+ operatorIdentityPublicKey: (0, import_utils20.hexToBytes)(operator.identityPublicKey)
30063
30207
  };
30064
30208
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
30065
30209
  const ownerSignature = await this.signMessageWithKey(
@@ -30081,7 +30225,7 @@ var TokenTransactionService = class {
30081
30225
  }
30082
30226
  const payload = {
30083
30227
  finalTokenTransactionHash,
30084
- operatorIdentityPublicKey: (0, import_utils19.hexToBytes)(operator.identityPublicKey)
30228
+ operatorIdentityPublicKey: (0, import_utils20.hexToBytes)(operator.identityPublicKey)
30085
30229
  };
30086
30230
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
30087
30231
  const ownerSignature = await this.signMessageWithKey(
@@ -30097,7 +30241,7 @@ var TokenTransactionService = class {
30097
30241
  for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
30098
30242
  const payload = {
30099
30243
  finalTokenTransactionHash,
30100
- operatorIdentityPublicKey: (0, import_utils19.hexToBytes)(operator.identityPublicKey)
30244
+ operatorIdentityPublicKey: (0, import_utils20.hexToBytes)(operator.identityPublicKey)
30101
30245
  };
30102
30246
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
30103
30247
  let ownerSignature;
@@ -30114,7 +30258,7 @@ var TokenTransactionService = class {
30114
30258
  }
30115
30259
  inputTtxoSignaturesPerOperator.push({
30116
30260
  ttxoSignatures,
30117
- operatorIdentityPublicKey: (0, import_utils19.hexToBytes)(operator.identityPublicKey)
30261
+ operatorIdentityPublicKey: (0, import_utils20.hexToBytes)(operator.identityPublicKey)
30118
30262
  });
30119
30263
  }
30120
30264
  return inputTtxoSignaturesPerOperator;
@@ -30126,7 +30270,7 @@ function isTokenTransaction(tokenTransaction) {
30126
30270
 
30127
30271
  // src/services/tree-creation.ts
30128
30272
  init_buffer();
30129
- var import_utils20 = require("@noble/curves/abstract/utils");
30273
+ var import_utils21 = require("@noble/curves/abstract/utils");
30130
30274
  var import_btc_signer5 = require("@scure/btc-signer");
30131
30275
  var TreeCreationService = class {
30132
30276
  config;
@@ -30167,7 +30311,7 @@ var TreeCreationService = class {
30167
30311
  request.source = {
30168
30312
  $case: "onChainUtxo",
30169
30313
  onChainUtxo: {
30170
- txid: (0, import_utils20.hexToBytes)(getTxId(parentTx)),
30314
+ txid: (0, import_utils21.hexToBytes)(getTxId(parentTx)),
30171
30315
  vout,
30172
30316
  rawTx: parentTx.toBytes(),
30173
30317
  network: this.config.getNetworkProto()
@@ -30208,7 +30352,7 @@ var TreeCreationService = class {
30208
30352
  request.source = {
30209
30353
  $case: "onChainUtxo",
30210
30354
  onChainUtxo: {
30211
- txid: (0, import_utils20.hexToBytes)(getTxId(parentTx)),
30355
+ txid: (0, import_utils21.hexToBytes)(getTxId(parentTx)),
30212
30356
  vout,
30213
30357
  rawTx: parentTx.toBytes(),
30214
30358
  network: this.config.getNetworkProto()
@@ -30335,7 +30479,7 @@ var TreeCreationService = class {
30335
30479
  throw new Error("parentTxOut is undefined");
30336
30480
  }
30337
30481
  const parentOutPoint = {
30338
- txid: (0, import_utils20.hexToBytes)(getTxId(parentTx)),
30482
+ txid: (0, import_utils21.hexToBytes)(getTxId(parentTx)),
30339
30483
  index: vout
30340
30484
  };
30341
30485
  const parentTxOutObj = {
@@ -30375,7 +30519,7 @@ var TreeCreationService = class {
30375
30519
  const [cpfpLeafTx, directLeafTx] = createLeafNodeTx(
30376
30520
  sequence,
30377
30521
  directSequence,
30378
- { txid: (0, import_utils20.hexToBytes)(getTxId(cpfpNodeTx)), index: 0 },
30522
+ { txid: (0, import_utils21.hexToBytes)(getTxId(cpfpNodeTx)), index: 0 },
30379
30523
  parentTxOutObj,
30380
30524
  true
30381
30525
  // shouldCalculateFee
@@ -30399,8 +30543,8 @@ var TreeCreationService = class {
30399
30543
  const { cpfpRefundTx, directRefundTx, directFromCpfpRefundTx } = createRefundTxs({
30400
30544
  sequence,
30401
30545
  directSequence,
30402
- input: { txid: (0, import_utils20.hexToBytes)(getTxId(cpfpLeafTx)), index: 0 },
30403
- directInput: { txid: (0, import_utils20.hexToBytes)(getTxId(directLeafTx)), index: 0 },
30546
+ input: { txid: (0, import_utils21.hexToBytes)(getTxId(cpfpLeafTx)), index: 0 },
30547
+ directInput: { txid: (0, import_utils21.hexToBytes)(getTxId(directLeafTx)), index: 0 },
30404
30548
  amountSats: parentTxOut.amount,
30405
30549
  receivingPubkey: node.signingPublicKey,
30406
30550
  network
@@ -30451,7 +30595,7 @@ var TreeCreationService = class {
30451
30595
  });
30452
30596
  }
30453
30597
  const parentOutPoint = {
30454
- txid: (0, import_utils20.hexToBytes)(getTxId(parentTx)),
30598
+ txid: (0, import_utils21.hexToBytes)(getTxId(parentTx)),
30455
30599
  index: vout
30456
30600
  };
30457
30601
  const [cpfpSplitTx, directSplitTx] = createSplitTx(
@@ -30728,11 +30872,13 @@ var TreeCreationService = class {
30728
30872
  // src/spark-wallet/spark-wallet.ts
30729
30873
  var import_lrc20_sdk3 = require("@buildonspark/lrc20-sdk");
30730
30874
  var import_sha212 = require("@noble/hashes/sha2");
30875
+ var import_api = require("@opentelemetry/api");
30876
+ var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
30731
30877
  var import_eventemitter3 = require("eventemitter3");
30732
30878
 
30733
30879
  // src/services/signing.ts
30734
30880
  init_buffer();
30735
- var import_utils21 = require("@noble/curves/abstract/utils");
30881
+ var import_utils22 = require("@noble/curves/abstract/utils");
30736
30882
  var SigningService = class {
30737
30883
  config;
30738
30884
  constructor(config) {
@@ -30788,7 +30934,7 @@ var SigningService = class {
30788
30934
  }
30789
30935
  const nodeTx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
30790
30936
  const cpfpNodeOutPoint = {
30791
- txid: (0, import_utils21.hexToBytes)(getTxId(nodeTx)),
30937
+ txid: (0, import_utils22.hexToBytes)(getTxId(nodeTx)),
30792
30938
  index: 0
30793
30939
  };
30794
30940
  const currRefundTx = getTxFromRawTxBytes(leaf.leaf.refundTx);
@@ -30814,7 +30960,7 @@ var SigningService = class {
30814
30960
  if (leaf.leaf.directTx.length > 0) {
30815
30961
  directNodeTx = getTxFromRawTxBytes(leaf.leaf.directTx);
30816
30962
  directNodeOutPoint = {
30817
- txid: (0, import_utils21.hexToBytes)(getTxId(directNodeTx)),
30963
+ txid: (0, import_utils22.hexToBytes)(getTxId(directNodeTx)),
30818
30964
  index: 0
30819
30965
  };
30820
30966
  }
@@ -30898,15 +31044,15 @@ var SigningService = class {
30898
31044
 
30899
31045
  // src/tests/utils/test-faucet.ts
30900
31046
  init_buffer();
30901
- var import_utils22 = require("@noble/curves/abstract/utils");
31047
+ var import_utils23 = require("@noble/curves/abstract/utils");
30902
31048
  var import_secp256k114 = require("@noble/curves/secp256k1");
30903
31049
  var btc5 = __toESM(require("@scure/btc-signer"), 1);
30904
31050
  var import_btc_signer6 = require("@scure/btc-signer");
30905
- var import_utils23 = require("@scure/btc-signer/utils");
30906
- var STATIC_FAUCET_KEY = (0, import_utils22.hexToBytes)(
31051
+ var import_utils24 = require("@scure/btc-signer/utils");
31052
+ var STATIC_FAUCET_KEY = (0, import_utils23.hexToBytes)(
30907
31053
  "deadbeef1337cafe4242424242424242deadbeef1337cafe4242424242424242"
30908
31054
  );
30909
- var STATIC_MINING_KEY = (0, import_utils22.hexToBytes)(
31055
+ var STATIC_MINING_KEY = (0, import_utils23.hexToBytes)(
30910
31056
  "1337cafe4242deadbeef4242424242421337cafe4242deadbeef424242424242"
30911
31057
  );
30912
31058
  var SATS_PER_BTC = 1e8;
@@ -30969,7 +31115,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
30969
31115
  if (!scanResult.success || scanResult.unspents.length === 0) {
30970
31116
  const blockHash = await this.generateToAddress(1, address2);
30971
31117
  const block = await this.getBlock(blockHash[0]);
30972
- const fundingTx = import_btc_signer6.Transaction.fromRaw((0, import_utils22.hexToBytes)(block.tx[0].hex), {
31118
+ const fundingTx = import_btc_signer6.Transaction.fromRaw((0, import_utils23.hexToBytes)(block.tx[0].hex), {
30973
31119
  allowUnknownOutputs: true
30974
31120
  });
30975
31121
  await this.generateToAddress(100, this.miningAddress);
@@ -31031,13 +31177,13 @@ var BitcoinFaucet = class _BitcoinFaucet {
31031
31177
  },
31032
31178
  STATIC_MINING_KEY
31033
31179
  );
31034
- await this.broadcastTx((0, import_utils22.bytesToHex)(signedSplitTx.extract()));
31180
+ await this.broadcastTx((0, import_utils23.bytesToHex)(signedSplitTx.extract()));
31035
31181
  const splitTxId = signedSplitTx.id;
31036
31182
  for (let i = 0; i < numCoinsToCreate; i++) {
31037
31183
  this.coins.push({
31038
31184
  key: STATIC_FAUCET_KEY,
31039
31185
  outpoint: {
31040
- txid: (0, import_utils22.hexToBytes)(splitTxId),
31186
+ txid: (0, import_utils23.hexToBytes)(splitTxId),
31041
31187
  index: i
31042
31188
  },
31043
31189
  txout: signedSplitTx.getOutput(i)
@@ -31065,7 +31211,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31065
31211
  coinToSend.txout,
31066
31212
  coinToSend.key
31067
31213
  );
31068
- await this.broadcastTx((0, import_utils22.bytesToHex)(signedTx.extract()));
31214
+ await this.broadcastTx((0, import_utils23.bytesToHex)(signedTx.extract()));
31069
31215
  }
31070
31216
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
31071
31217
  const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
@@ -31085,7 +31231,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31085
31231
  new Array(unsignedTx.inputsLength).fill(fundingTxOut.amount)
31086
31232
  );
31087
31233
  const merkleRoot = new Uint8Array();
31088
- const tweakedKey = (0, import_utils23.taprootTweakPrivKey)(key, merkleRoot);
31234
+ const tweakedKey = (0, import_utils24.taprootTweakPrivKey)(key, merkleRoot);
31089
31235
  if (!tweakedKey)
31090
31236
  throw new Error("Invalid private key for taproot tweaking");
31091
31237
  const signature = import_secp256k114.schnorr.sign(sighash, tweakedKey);
@@ -31155,7 +31301,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31155
31301
  const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
31156
31302
  return getP2TRAddressFromPublicKey(pubKey, 4 /* LOCAL */);
31157
31303
  }
31158
- async sendToAddress(address2, amount) {
31304
+ async sendToAddress(address2, amount, blocksToGenerate = 1) {
31159
31305
  const coin = await this.fund();
31160
31306
  if (!coin) {
31161
31307
  throw new Error("No coins available");
@@ -31185,7 +31331,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31185
31331
  });
31186
31332
  }
31187
31333
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
31188
- const txHex = (0, import_utils22.bytesToHex)(signedTx.extract());
31334
+ const txHex = (0, import_utils23.bytesToHex)(signedTx.extract());
31189
31335
  await this.broadcastTx(txHex);
31190
31336
  const randomKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
31191
31337
  const randomPubKey = import_secp256k114.secp256k1.getPublicKey(randomKey);
@@ -31193,7 +31339,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31193
31339
  randomPubKey,
31194
31340
  4 /* LOCAL */
31195
31341
  );
31196
- await this.generateToAddress(1, randomAddress);
31342
+ await this.generateToAddress(blocksToGenerate, randomAddress);
31197
31343
  return signedTx;
31198
31344
  }
31199
31345
  async getRawTransaction(txid) {
@@ -31237,11 +31383,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31237
31383
  tokenOutputs = /* @__PURE__ */ new Map();
31238
31384
  // Add this property near the top of the class with other private properties
31239
31385
  claimTransfersInterval = null;
31240
- wrapWithOtelSpan(name, fn) {
31241
- return async (...args) => {
31242
- return await fn(...args);
31243
- };
31244
- }
31386
+ tracer = null;
31245
31387
  constructor(options, signer) {
31246
31388
  super();
31247
31389
  this.config = new WalletConfigService(options, signer);
@@ -31274,6 +31416,8 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31274
31416
  this.connectionManager,
31275
31417
  this.signingService
31276
31418
  );
31419
+ this.tracer = import_api.trace.getTracer(this.tracerId);
31420
+ this.wrapSparkWalletMethodsWithTracing();
31277
31421
  }
31278
31422
  static async initialize({
31279
31423
  mnemonicOrSeed,
@@ -31282,6 +31426,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31282
31426
  options
31283
31427
  }) {
31284
31428
  const wallet = new _SparkWallet(options, signer);
31429
+ wallet.initializeTracer(wallet);
31285
31430
  const initResponse = await wallet.initWallet(mnemonicOrSeed, accountNumber);
31286
31431
  return {
31287
31432
  wallet,
@@ -31310,7 +31455,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31310
31455
  try {
31311
31456
  if (event?.$case === "transfer" && event.transfer.transfer && event.transfer.transfer.type !== 40 /* COUNTER_SWAP */) {
31312
31457
  const { senderIdentityPublicKey, receiverIdentityPublicKey } = event.transfer.transfer;
31313
- if (event.transfer.transfer && !(0, import_utils24.equalBytes)(senderIdentityPublicKey, receiverIdentityPublicKey)) {
31458
+ if (event.transfer.transfer && !(0, import_utils25.equalBytes)(senderIdentityPublicKey, receiverIdentityPublicKey)) {
31314
31459
  await this.claimTransfer({
31315
31460
  transfer: event.transfer.transfer,
31316
31461
  emit: true,
@@ -31475,10 +31620,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31475
31620
  leavesToIgnore.add(nodeId);
31476
31621
  continue;
31477
31622
  }
31478
- if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !(0, import_utils24.equalBytes)(
31623
+ if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !(0, import_utils25.equalBytes)(
31479
31624
  leaf.signingKeyshare.publicKey,
31480
31625
  operatorLeaf.signingKeyshare.publicKey
31481
- ) || !(0, import_utils24.equalBytes)(leaf.nodeTx, operatorLeaf.nodeTx)) {
31626
+ ) || !(0, import_utils25.equalBytes)(leaf.nodeTx, operatorLeaf.nodeTx)) {
31482
31627
  leavesToIgnore.add(nodeId);
31483
31628
  }
31484
31629
  }
@@ -31529,7 +31674,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31529
31674
  });
31530
31675
  }
31531
31676
  verifyKey(pubkey1, pubkey2, verifyingKey) {
31532
- return (0, import_utils24.equalBytes)(addPublicKeys(pubkey1, pubkey2), verifyingKey);
31677
+ return (0, import_utils25.equalBytes)(addPublicKeys(pubkey1, pubkey2), verifyingKey);
31533
31678
  }
31534
31679
  async selectLeaves(targetAmounts) {
31535
31680
  if (targetAmounts.length === 0) {
@@ -31687,7 +31832,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31687
31832
  * @returns {Promise<string>} The identity public key as a hex string.
31688
31833
  */
31689
31834
  async getIdentityPublicKey() {
31690
- return (0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey());
31835
+ return (0, import_utils25.bytesToHex)(await this.config.signer.getIdentityPublicKey());
31691
31836
  }
31692
31837
  /**
31693
31838
  * Gets the Spark address of the wallet.
@@ -31697,7 +31842,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31697
31842
  async getSparkAddress() {
31698
31843
  if (!this.sparkAddress) {
31699
31844
  this.sparkAddress = encodeSparkAddress({
31700
- identityPublicKey: (0, import_utils24.bytesToHex)(
31845
+ identityPublicKey: (0, import_utils25.bytesToHex)(
31701
31846
  await this.config.signer.getIdentityPublicKey()
31702
31847
  ),
31703
31848
  network: this.config.getNetworkType()
@@ -31734,14 +31879,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31734
31879
  isValidPublicKey(assetIdentifier);
31735
31880
  }
31736
31881
  const paymentRequest = encodeSparkAddress({
31737
- identityPublicKey: (0, import_utils24.bytesToHex)(
31882
+ identityPublicKey: (0, import_utils25.bytesToHex)(
31738
31883
  await this.config.signer.getIdentityPublicKey()
31739
31884
  ),
31740
31885
  network: this.config.getNetworkType(),
31741
31886
  paymentIntentFields: {
31742
31887
  id: (0, import_uuidv75.uuidv7obj)().bytes,
31743
- assetIdentifier: assetIdentifier ? (0, import_utils24.hexToBytes)(assetIdentifier) : void 0,
31744
- assetAmount: (0, import_utils24.numberToVarBytesBE)(assetAmount),
31888
+ assetIdentifier: assetIdentifier ? (0, import_utils25.hexToBytes)(assetIdentifier) : void 0,
31889
+ assetAmount: (0, import_utils25.numberToVarBytesBE)(assetAmount),
31745
31890
  memo
31746
31891
  }
31747
31892
  });
@@ -31786,7 +31931,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31786
31931
  mnemonic = mnemonicOrSeed;
31787
31932
  seed = await this.config.signer.mnemonicToSeed(mnemonicOrSeed);
31788
31933
  } else {
31789
- seed = (0, import_utils24.hexToBytes)(mnemonicOrSeed);
31934
+ seed = (0, import_utils25.hexToBytes)(mnemonicOrSeed);
31790
31935
  }
31791
31936
  }
31792
31937
  await this.initWalletFromSeed(seed, accountNumber);
@@ -31916,7 +32061,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31916
32061
  directFromCpfpSignatureMap
31917
32062
  } = await this.transferService.startSwapSignRefund(
31918
32063
  leafKeyTweaks,
31919
- (0, import_utils24.hexToBytes)(this.config.getSspIdentityPublicKey()),
32064
+ (0, import_utils25.hexToBytes)(this.config.getSspIdentityPublicKey()),
31920
32065
  new Date(Date.now() + 2 * 60 * 1e3)
31921
32066
  );
31922
32067
  try {
@@ -31976,18 +32121,18 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31976
32121
  const userLeaves = [];
31977
32122
  userLeaves.push({
31978
32123
  leaf_id: transfer.leaves[0].leaf.id,
31979
- raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32124
+ raw_unsigned_refund_transaction: (0, import_utils25.bytesToHex)(
31980
32125
  transfer.leaves[0].intermediateRefundTx
31981
32126
  ),
31982
- direct_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32127
+ direct_raw_unsigned_refund_transaction: (0, import_utils25.bytesToHex)(
31983
32128
  transfer.leaves[0].intermediateDirectRefundTx
31984
32129
  ),
31985
- direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32130
+ direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils25.bytesToHex)(
31986
32131
  transfer.leaves[0].intermediateDirectFromCpfpRefundTx
31987
32132
  ),
31988
- adaptor_added_signature: (0, import_utils24.bytesToHex)(cpfpAdaptorSignature),
31989
- direct_adaptor_added_signature: (0, import_utils24.bytesToHex)(directAdaptorSignature),
31990
- direct_from_cpfp_adaptor_added_signature: (0, import_utils24.bytesToHex)(
32133
+ adaptor_added_signature: (0, import_utils25.bytesToHex)(cpfpAdaptorSignature),
32134
+ direct_adaptor_added_signature: (0, import_utils25.bytesToHex)(directAdaptorSignature),
32135
+ direct_from_cpfp_adaptor_added_signature: (0, import_utils25.bytesToHex)(
31991
32136
  directFromCpfpAdaptorSignature
31992
32137
  )
31993
32138
  });
@@ -32040,24 +32185,24 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32040
32185
  }
32041
32186
  userLeaves.push({
32042
32187
  leaf_id: leaf.leaf.id,
32043
- raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32188
+ raw_unsigned_refund_transaction: (0, import_utils25.bytesToHex)(
32044
32189
  leaf.intermediateRefundTx
32045
32190
  ),
32046
- direct_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32191
+ direct_raw_unsigned_refund_transaction: (0, import_utils25.bytesToHex)(
32047
32192
  leaf.intermediateDirectRefundTx
32048
32193
  ),
32049
- direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32194
+ direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils25.bytesToHex)(
32050
32195
  leaf.intermediateDirectFromCpfpRefundTx
32051
32196
  ),
32052
- adaptor_added_signature: (0, import_utils24.bytesToHex)(cpfpSignature),
32053
- direct_adaptor_added_signature: (0, import_utils24.bytesToHex)(directSignature),
32054
- direct_from_cpfp_adaptor_added_signature: (0, import_utils24.bytesToHex)(
32197
+ adaptor_added_signature: (0, import_utils25.bytesToHex)(cpfpSignature),
32198
+ direct_adaptor_added_signature: (0, import_utils25.bytesToHex)(directSignature),
32199
+ direct_from_cpfp_adaptor_added_signature: (0, import_utils25.bytesToHex)(
32055
32200
  directFromCpfpSignature
32056
32201
  )
32057
32202
  });
32058
32203
  }
32059
32204
  const sspClient = this.getSspClient();
32060
- const cpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
32205
+ const cpfpAdaptorPubkey = (0, import_utils25.bytesToHex)(
32061
32206
  import_secp256k115.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
32062
32207
  );
32063
32208
  if (!cpfpAdaptorPubkey) {
@@ -32065,13 +32210,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32065
32210
  }
32066
32211
  let directAdaptorPubkey;
32067
32212
  if (directAdaptorPrivateKey.length > 0) {
32068
- directAdaptorPubkey = (0, import_utils24.bytesToHex)(
32213
+ directAdaptorPubkey = (0, import_utils25.bytesToHex)(
32069
32214
  import_secp256k115.secp256k1.getPublicKey(directAdaptorPrivateKey)
32070
32215
  );
32071
32216
  }
32072
32217
  let directFromCpfpAdaptorPubkey;
32073
32218
  if (directFromCpfpAdaptorPrivateKey.length > 0) {
32074
- directFromCpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
32219
+ directFromCpfpAdaptorPubkey = (0, import_utils25.bytesToHex)(
32075
32220
  import_secp256k115.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
32076
32221
  );
32077
32222
  }
@@ -32131,7 +32276,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32131
32276
  throw new Error(`Leaf not found for node ${nodeId}`);
32132
32277
  }
32133
32278
  const cpfpNodeTx = getTxFromRawTxBytes(node.nodeTx);
32134
- const cpfpRefundTxBytes = (0, import_utils24.hexToBytes)(leaf.rawUnsignedRefundTransaction);
32279
+ const cpfpRefundTxBytes = (0, import_utils25.hexToBytes)(leaf.rawUnsignedRefundTransaction);
32135
32280
  const cpfpRefundTx = getTxFromRawTxBytes(cpfpRefundTxBytes);
32136
32281
  const cpfpSighash = getSigHashFromTx(
32137
32282
  cpfpRefundTx,
@@ -32140,7 +32285,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32140
32285
  );
32141
32286
  const nodePublicKey = node.verifyingPublicKey;
32142
32287
  const taprootKey = computeTaprootKeyNoScript(nodePublicKey.slice(1));
32143
- const cpfpAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
32288
+ const cpfpAdaptorSignatureBytes = (0, import_utils25.hexToBytes)(
32144
32289
  leaf.adaptorSignedSignature
32145
32290
  );
32146
32291
  applyAdaptorToSignature(
@@ -32149,70 +32294,59 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32149
32294
  cpfpAdaptorSignatureBytes,
32150
32295
  cpfpAdaptorPrivateKey
32151
32296
  );
32152
- if (!leaf.directRawUnsignedRefundTransaction) {
32153
- throw new Error(
32154
- `Direct raw unsigned refund transaction missing for node ${nodeId}`
32297
+ if (leaf.directRawUnsignedRefundTransaction) {
32298
+ const directNodeTx = getTxFromRawTxBytes(node.directTx);
32299
+ const directRefundTxBytes = (0, import_utils25.hexToBytes)(
32300
+ leaf.directRawUnsignedRefundTransaction
32155
32301
  );
32156
- }
32157
- if (!leaf.directAdaptorSignedSignature) {
32158
- throw new Error(
32159
- `Direct adaptor signed signature missing for node ${nodeId}`
32302
+ const directRefundTx = getTxFromRawTxBytes(directRefundTxBytes);
32303
+ const directSighash = getSigHashFromTx(
32304
+ directRefundTx,
32305
+ 0,
32306
+ directNodeTx.getOutput(0)
32160
32307
  );
32161
- }
32162
- const directNodeTx = getTxFromRawTxBytes(node.directTx);
32163
- const directRefundTxBytes = (0, import_utils24.hexToBytes)(
32164
- leaf.directRawUnsignedRefundTransaction
32165
- );
32166
- const directRefundTx = getTxFromRawTxBytes(directRefundTxBytes);
32167
- const directSighash = getSigHashFromTx(
32168
- directRefundTx,
32169
- 0,
32170
- directNodeTx.getOutput(0)
32171
- );
32172
- if (!leaf.directFromCpfpAdaptorSignedSignature) {
32173
- throw new Error(
32174
- `Direct adaptor signed signature missing for node ${nodeId}`
32308
+ if (!leaf.directAdaptorSignedSignature) {
32309
+ throw new Error(
32310
+ `Direct adaptor signed signature missing for node ${nodeId}`
32311
+ );
32312
+ }
32313
+ const directAdaptorSignatureBytes = (0, import_utils25.hexToBytes)(
32314
+ leaf.directAdaptorSignedSignature
32175
32315
  );
32176
- }
32177
- const directAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
32178
- leaf.directAdaptorSignedSignature
32179
- );
32180
- applyAdaptorToSignature(
32181
- taprootKey.slice(1),
32182
- directSighash,
32183
- directAdaptorSignatureBytes,
32184
- directAdaptorPrivateKey
32185
- );
32186
- if (!leaf.directRawUnsignedRefundTransaction) {
32187
- throw new Error(
32188
- `Direct raw unsigned refund transaction missing for node ${nodeId}`
32316
+ applyAdaptorToSignature(
32317
+ taprootKey.slice(1),
32318
+ directSighash,
32319
+ directAdaptorSignatureBytes,
32320
+ directAdaptorPrivateKey
32189
32321
  );
32190
32322
  }
32191
- if (!leaf.directFromCpfpRawUnsignedRefundTransaction) {
32192
- throw new Error(
32193
- `Direct raw unsigned refund transaction missing for node ${nodeId}`
32323
+ if (leaf.directFromCpfpRawUnsignedRefundTransaction) {
32324
+ const directFromCpfpRefundTxBytes = (0, import_utils25.hexToBytes)(
32325
+ leaf.directFromCpfpRawUnsignedRefundTransaction
32326
+ );
32327
+ const directFromCpfpRefundTx = getTxFromRawTxBytes(
32328
+ directFromCpfpRefundTxBytes
32329
+ );
32330
+ const directFromCpfpSighash = getSigHashFromTx(
32331
+ directFromCpfpRefundTx,
32332
+ 0,
32333
+ cpfpNodeTx.getOutput(0)
32334
+ );
32335
+ if (!leaf.directFromCpfpAdaptorSignedSignature) {
32336
+ throw new Error(
32337
+ `Direct adaptor signed signature missing for node ${nodeId}`
32338
+ );
32339
+ }
32340
+ const directFromCpfpAdaptorSignatureBytes = (0, import_utils25.hexToBytes)(
32341
+ leaf.directFromCpfpAdaptorSignedSignature
32342
+ );
32343
+ applyAdaptorToSignature(
32344
+ taprootKey.slice(1),
32345
+ directFromCpfpSighash,
32346
+ directFromCpfpAdaptorSignatureBytes,
32347
+ directFromCpfpAdaptorPrivateKey
32194
32348
  );
32195
32349
  }
32196
- const directFromCpfpRefundTxBytes = (0, import_utils24.hexToBytes)(
32197
- leaf.directFromCpfpRawUnsignedRefundTransaction
32198
- );
32199
- const directFromCpfpRefundTx = getTxFromRawTxBytes(
32200
- directFromCpfpRefundTxBytes
32201
- );
32202
- const directFromCpfpSighash = getSigHashFromTx(
32203
- directFromCpfpRefundTx,
32204
- 0,
32205
- cpfpNodeTx.getOutput(0)
32206
- );
32207
- const directFromCpfpAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
32208
- leaf.directFromCpfpAdaptorSignedSignature
32209
- );
32210
- applyAdaptorToSignature(
32211
- taprootKey.slice(1),
32212
- directFromCpfpSighash,
32213
- directFromCpfpAdaptorSignatureBytes,
32214
- directFromCpfpAdaptorPrivateKey
32215
- );
32216
32350
  }
32217
32351
  await this.transferService.deliverTransferPackage(
32218
32352
  transfer,
@@ -32222,9 +32356,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32222
32356
  directFromCpfpSignatureMap
32223
32357
  );
32224
32358
  const completeResponse = await sspClient.completeLeaveSwap({
32225
- adaptorSecretKey: (0, import_utils24.bytesToHex)(cpfpAdaptorPrivateKey),
32226
- directAdaptorSecretKey: (0, import_utils24.bytesToHex)(directAdaptorPrivateKey),
32227
- directFromCpfpAdaptorSecretKey: (0, import_utils24.bytesToHex)(
32359
+ adaptorSecretKey: (0, import_utils25.bytesToHex)(cpfpAdaptorPrivateKey),
32360
+ directAdaptorSecretKey: (0, import_utils25.bytesToHex)(directAdaptorPrivateKey),
32361
+ directFromCpfpAdaptorSecretKey: (0, import_utils25.bytesToHex)(
32228
32362
  directFromCpfpAdaptorPrivateKey
32229
32363
  ),
32230
32364
  userOutboundTransferExternalId: transfer.id,
@@ -32260,28 +32394,6 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32260
32394
  throw new Error(`Failed to request leaves swap: ${e}`);
32261
32395
  }
32262
32396
  }
32263
- /**
32264
- * Gets all transfers for the wallet.
32265
- *
32266
- * @param {number} [limit=20] - Maximum number of transfers to return
32267
- * @param {number} [offset=0] - Offset for pagination
32268
- * @returns {Promise<QueryTransfersResponse>} Response containing the list of transfers
32269
- */
32270
- async getTransfers(limit = 20, offset = 0) {
32271
- const transfers = await this.transferService.queryAllTransfers(
32272
- limit,
32273
- offset
32274
- );
32275
- const identityPublicKey = (0, import_utils24.bytesToHex)(
32276
- await this.config.signer.getIdentityPublicKey()
32277
- );
32278
- return {
32279
- transfers: transfers.transfers.map(
32280
- (transfer) => mapTransferToWalletTransfer(transfer, identityPublicKey)
32281
- ),
32282
- offset: transfers.offset
32283
- };
32284
- }
32285
32397
  /**
32286
32398
  * Gets the current balance of the wallet.
32287
32399
  * You can use the forceRefetch option to synchronize your wallet and claim any
@@ -32342,12 +32454,12 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32342
32454
  let tokenMetadataMap = /* @__PURE__ */ new Map();
32343
32455
  for (const [tokenIdentifier, metadata] of this.tokenMetadata) {
32344
32456
  tokenMetadataMap.set(tokenIdentifier, {
32345
- tokenPublicKey: (0, import_utils24.bytesToHex)(metadata.issuerPublicKey),
32457
+ tokenPublicKey: (0, import_utils25.bytesToHex)(metadata.issuerPublicKey),
32346
32458
  rawTokenIdentifier: metadata.tokenIdentifier,
32347
32459
  tokenName: metadata.tokenName,
32348
32460
  tokenTicker: metadata.tokenTicker,
32349
32461
  decimals: metadata.decimals,
32350
- maxSupply: (0, import_utils24.bytesToNumberBE)(metadata.maxSupply)
32462
+ maxSupply: (0, import_utils25.bytesToNumberBE)(metadata.maxSupply)
32351
32463
  });
32352
32464
  }
32353
32465
  return tokenMetadataMap;
@@ -32460,7 +32572,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32460
32572
  network = BitcoinNetwork_default.REGTEST;
32461
32573
  }
32462
32574
  if (outputIndex === void 0) {
32463
- outputIndex = await this.getDepositTransactionVout(transactionId);
32575
+ outputIndex = await this.getDepositTransactionVout({
32576
+ txid: transactionId
32577
+ });
32464
32578
  }
32465
32579
  const quote = await sspClient.getClaimDepositQuote({
32466
32580
  transactionId,
@@ -32491,13 +32605,15 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32491
32605
  throw new Error("SSP client not initialized");
32492
32606
  }
32493
32607
  if (outputIndex === void 0) {
32494
- outputIndex = await this.getDepositTransactionVout(transactionId);
32608
+ outputIndex = await this.getDepositTransactionVout({
32609
+ txid: transactionId
32610
+ });
32495
32611
  }
32496
32612
  let network = this.config.getSspNetwork();
32497
32613
  if (network === BitcoinNetwork_default.FUTURE_VALUE) {
32498
32614
  network = BitcoinNetwork_default.REGTEST;
32499
32615
  }
32500
- const depositSecretKey = (0, import_utils24.bytesToHex)(
32616
+ const depositSecretKey = (0, import_utils25.bytesToHex)(
32501
32617
  await this.config.signer.getStaticDepositSecretKey(0)
32502
32618
  );
32503
32619
  const message = await this.getStaticDepositSigningPayload(
@@ -32510,7 +32626,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32510
32626
  );
32511
32627
  const hashBuffer = (0, import_sha212.sha256)(message);
32512
32628
  const signatureBytes = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
32513
- const signature = (0, import_utils24.bytesToHex)(signatureBytes);
32629
+ const signature = (0, import_utils25.bytesToHex)(signatureBytes);
32514
32630
  const response = await this.sspClient.claimStaticDeposit({
32515
32631
  transactionId,
32516
32632
  outputIndex,
@@ -32525,25 +32641,89 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32525
32641
  }
32526
32642
  return response;
32527
32643
  }
32644
+ /**
32645
+ * Get a quote on how much credit you can claim for a deposit from the SSP. If the quote charges less fees than the max fee, claim the deposit.
32646
+ *
32647
+ * @param {Object} params - The parameters object
32648
+ * @param {string} params.transactionId - The ID of the transaction
32649
+ * @param {number} params.maxFee - The maximum fee to claim the deposit for
32650
+ * @param {number} [params.outputIndex] - The index of the output
32651
+ * @returns {Promise<StaticDepositQuoteOutput>} Quote for claiming a deposit to a static deposit address
32652
+ */
32653
+ async claimStaticDepositWithMaxFee({
32654
+ transactionId,
32655
+ maxFee,
32656
+ outputIndex
32657
+ }) {
32658
+ const sspClient = this.getSspClient();
32659
+ let network = this.config.getSspNetwork();
32660
+ if (network === BitcoinNetwork_default.FUTURE_VALUE) {
32661
+ network = BitcoinNetwork_default.REGTEST;
32662
+ }
32663
+ const depositTx = await this.getDepositTransaction(transactionId);
32664
+ if (outputIndex === void 0) {
32665
+ outputIndex = await this.getDepositTransactionVout({
32666
+ txid: transactionId,
32667
+ depositTx
32668
+ });
32669
+ }
32670
+ const depositAmount = Number(depositTx.getOutput(outputIndex).amount);
32671
+ const quote = await sspClient.getClaimDepositQuote({
32672
+ transactionId,
32673
+ outputIndex,
32674
+ network
32675
+ });
32676
+ if (!quote) {
32677
+ throw new Error("Failed to get claim deposit quote");
32678
+ }
32679
+ const { creditAmountSats, signature: sspSignature } = quote;
32680
+ const feeCharged = depositAmount - creditAmountSats;
32681
+ if (feeCharged > maxFee) {
32682
+ throw new ValidationError("Fee larger than max fee", {
32683
+ field: "feeCharged",
32684
+ value: feeCharged
32685
+ });
32686
+ }
32687
+ const response = await this.claimStaticDeposit({
32688
+ transactionId,
32689
+ creditAmountSats,
32690
+ sspSignature,
32691
+ outputIndex
32692
+ });
32693
+ if (!response) {
32694
+ throw new Error("Failed to claim static deposit");
32695
+ }
32696
+ return response;
32697
+ }
32528
32698
  /**
32529
32699
  * Refunds a static deposit to a destination address.
32530
32700
  *
32531
- * @param {string} depositTransactionId - The ID of the transaction
32532
- * @param {number} [outputIndex] - The index of the output
32533
- * @param {string} destinationAddress - The destination address
32534
- * @param {number} fee - The fee to refund
32701
+ * @param {Object} params - The refund parameters
32702
+ * @param {string} params.depositTransactionId - The ID of the transaction
32703
+ * @param {number} [params.outputIndex] - The index of the output
32704
+ * @param {string} params.destinationAddress - The destination address
32705
+ * @param {number} [params.fee] - **@deprecated** The fee to refund
32706
+ * @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
32535
32707
  * @returns {Promise<string>} The hex of the refund transaction
32536
32708
  */
32537
32709
  async refundStaticDeposit({
32538
32710
  depositTransactionId,
32539
32711
  outputIndex,
32540
32712
  destinationAddress,
32541
- fee
32713
+ fee,
32714
+ satsPerVbyteFee
32542
32715
  }) {
32543
- if (fee <= 300) {
32544
- throw new ValidationError("Fee must be greater than 300", {
32716
+ if (fee === void 0 && satsPerVbyteFee === void 0) {
32717
+ throw new ValidationError("Fee or satsPerVbyteFee must be provided");
32718
+ }
32719
+ if (satsPerVbyteFee && satsPerVbyteFee > 150) {
32720
+ throw new ValidationError("satsPerVbyteFee must be less than 150");
32721
+ }
32722
+ const finalFee = satsPerVbyteFee ? satsPerVbyteFee * getTxEstimatedVbytesSizeByNumberOfInputsOutputs(1, 1) : fee;
32723
+ if (finalFee < 194) {
32724
+ throw new ValidationError("Fee must be at least 194", {
32545
32725
  field: "fee",
32546
- value: fee
32726
+ value: finalFee
32547
32727
  });
32548
32728
  }
32549
32729
  let network = this.config.getNetwork();
@@ -32551,10 +32731,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32551
32731
  const networkJSON = networkToJSON(networkType);
32552
32732
  const depositTx = await this.getDepositTransaction(depositTransactionId);
32553
32733
  if (outputIndex === void 0) {
32554
- outputIndex = await this.getDepositTransactionVout(depositTransactionId);
32734
+ outputIndex = await this.getDepositTransactionVout({
32735
+ txid: depositTransactionId,
32736
+ depositTx
32737
+ });
32555
32738
  }
32556
32739
  const totalAmount = depositTx.getOutput(outputIndex).amount;
32557
- const creditAmountSats = Number(totalAmount) - fee;
32740
+ const creditAmountSats = Number(totalAmount) - finalFee;
32558
32741
  if (creditAmountSats <= 0) {
32559
32742
  throw new ValidationError(
32560
32743
  "Fee too large. Credit amount must be greater than 0",
@@ -32595,33 +32778,21 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32595
32778
  networkJSON.toLowerCase(),
32596
32779
  2 /* Refund */,
32597
32780
  creditAmountSats,
32598
- (0, import_utils24.bytesToHex)(spendTxSighash)
32781
+ (0, import_utils25.bytesToHex)(spendTxSighash)
32599
32782
  );
32600
32783
  const hashBuffer = (0, import_sha212.sha256)(message);
32601
32784
  const swapResponseUserSignature = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
32602
32785
  const sparkClient = await this.connectionManager.createSparkClient(
32603
32786
  this.config.getCoordinatorAddress()
32604
32787
  );
32605
- const transferId = (0, import_uuidv75.uuidv7)();
32606
- const swapResponse = await sparkClient.initiate_utxo_swap({
32788
+ const swapResponse = await sparkClient.initiate_static_deposit_utxo_refund({
32607
32789
  onChainUtxo: {
32608
- txid: (0, import_utils24.hexToBytes)(depositTransactionId),
32790
+ txid: (0, import_utils25.hexToBytes)(depositTransactionId),
32609
32791
  vout: outputIndex,
32610
32792
  network: networkType
32611
32793
  },
32612
- requestType: 2 /* Refund */,
32613
- amount: {
32614
- creditAmountSats: 0,
32615
- $case: "creditAmountSats"
32616
- },
32617
32794
  userSignature: swapResponseUserSignature,
32618
- sspSignature: new Uint8Array(),
32619
- transfer: {
32620
- transferId,
32621
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
32622
- receiverIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
32623
- },
32624
- spendTxSigningJob: signingJob
32795
+ refundTxSigningJob: signingJob
32625
32796
  });
32626
32797
  if (!swapResponse) {
32627
32798
  throw new Error("Failed to initiate utxo swap");
@@ -32634,15 +32805,15 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32634
32805
  path: 0
32635
32806
  },
32636
32807
  selfCommitment: signingNonceCommitment,
32637
- statechainCommitments: swapResponse.spendTxSigningResult.signingNonceCommitments,
32808
+ statechainCommitments: swapResponse.refundTxSigningResult.signingNonceCommitments,
32638
32809
  verifyingKey: swapResponse.depositAddress.verifyingPublicKey
32639
32810
  });
32640
32811
  const signatureResult = await this.config.signer.aggregateFrost({
32641
32812
  message: spendTxSighash,
32642
- statechainSignatures: swapResponse.spendTxSigningResult.signatureShares,
32643
- statechainPublicKeys: swapResponse.spendTxSigningResult.publicKeys,
32813
+ statechainSignatures: swapResponse.refundTxSigningResult.signatureShares,
32814
+ statechainPublicKeys: swapResponse.refundTxSigningResult.publicKeys,
32644
32815
  verifyingKey: swapResponse.depositAddress.verifyingPublicKey,
32645
- statechainCommitments: swapResponse.spendTxSigningResult.signingNonceCommitments,
32816
+ statechainCommitments: swapResponse.refundTxSigningResult.signingNonceCommitments,
32646
32817
  selfCommitment: signingNonceCommitment,
32647
32818
  publicKey: await this.config.signer.getStaticDepositSigningKey(0),
32648
32819
  selfSignature: userSignature
@@ -32685,7 +32856,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32685
32856
  creditAmountView.setUint32(0, lowerHalf, true);
32686
32857
  creditAmountView.setUint32(4, upperHalf, true);
32687
32858
  parts.push(new Uint8Array(creditAmountBuffer));
32688
- parts.push((0, import_utils24.hexToBytes)(sspSignature));
32859
+ parts.push((0, import_utils25.hexToBytes)(sspSignature));
32689
32860
  const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
32690
32861
  const payload = new Uint8Array(totalLength);
32691
32862
  let offset = 0;
@@ -32695,8 +32866,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32695
32866
  }
32696
32867
  return payload;
32697
32868
  }
32698
- async getDepositTransactionVout(txid) {
32699
- const depositTx = await this.getDepositTransaction(txid);
32869
+ async getDepositTransactionVout({
32870
+ txid,
32871
+ depositTx
32872
+ }) {
32873
+ if (!depositTx) {
32874
+ depositTx = await this.getDepositTransaction(txid);
32875
+ }
32700
32876
  const staticDepositAddresses = new Set(
32701
32877
  await this.queryStaticDepositAddresses()
32702
32878
  );
@@ -33076,9 +33252,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33076
33252
  this.config.getNetworkType()
33077
33253
  );
33078
33254
  const signerIdentityPublicKey = await this.config.signer.getIdentityPublicKey();
33079
- const isSelfTransfer = (0, import_utils24.equalBytes)(
33255
+ const isSelfTransfer = (0, import_utils25.equalBytes)(
33080
33256
  signerIdentityPublicKey,
33081
- (0, import_utils24.hexToBytes)(receiverAddress.identityPublicKey)
33257
+ (0, import_utils25.hexToBytes)(receiverAddress.identityPublicKey)
33082
33258
  );
33083
33259
  return await this.withLeaves(async () => {
33084
33260
  let leavesToSend = (await this.selectLeaves([amountSats])).get(
@@ -33100,7 +33276,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33100
33276
  );
33101
33277
  const transfer = await this.transferService.sendTransferWithKeyTweaks(
33102
33278
  leafKeyTweaks,
33103
- (0, import_utils24.hexToBytes)(receiverAddress.identityPublicKey)
33279
+ (0, import_utils25.hexToBytes)(receiverAddress.identityPublicKey)
33104
33280
  );
33105
33281
  const leavesToRemove = new Set(leavesToSend.map((leaf) => leaf.id));
33106
33282
  this.leaves = this.leaves.filter((leaf) => !leavesToRemove.has(leaf.id));
@@ -33116,7 +33292,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33116
33292
  }
33117
33293
  return mapTransferToWalletTransfer(
33118
33294
  transfer,
33119
- (0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey())
33295
+ (0, import_utils25.bytesToHex)(await this.config.signer.getIdentityPublicKey())
33120
33296
  );
33121
33297
  });
33122
33298
  }
@@ -33453,7 +33629,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33453
33629
  const invoice2 = await sspClient.requestLightningReceive({
33454
33630
  amountSats: amountSats2,
33455
33631
  network: bitcoinNetwork,
33456
- paymentHash: (0, import_utils24.bytesToHex)(paymentHash),
33632
+ paymentHash: (0, import_utils25.bytesToHex)(paymentHash),
33457
33633
  expirySecs: expirySeconds,
33458
33634
  memo: memo2,
33459
33635
  includeSparkAddress,
@@ -33517,7 +33693,8 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33517
33693
  }) {
33518
33694
  const invoiceNetwork = getNetworkFromInvoice(invoice);
33519
33695
  const walletNetwork = this.config.getNetwork();
33520
- if (invoiceNetwork !== walletNetwork) {
33696
+ const isValidNetworkForWallet = invoiceNetwork === walletNetwork || invoiceNetwork === 3 /* REGTEST */ && (walletNetwork === 3 /* REGTEST */ || walletNetwork === 4 /* LOCAL */);
33697
+ if (!isValidNetworkForWallet) {
33521
33698
  throw new ValidationError(
33522
33699
  `Invoice network: ${invoiceNetwork} does not match wallet network: ${walletNetwork}`,
33523
33700
  {
@@ -33561,7 +33738,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33561
33738
  const sparkFallbackAddress = decodedInvoice.fallbackAddress;
33562
33739
  const paymentHash = decodedInvoice.paymentHash;
33563
33740
  if (preferSpark) {
33564
- if (sparkFallbackAddress === void 0 || isValidSparkFallback((0, import_utils24.hexToBytes)(sparkFallbackAddress)) === false) {
33741
+ if (sparkFallbackAddress === void 0 || isValidSparkFallback((0, import_utils25.hexToBytes)(sparkFallbackAddress)) === false) {
33565
33742
  console.warn(
33566
33743
  "No valid spark address found in invoice. Defaulting to lightning."
33567
33744
  );
@@ -33615,10 +33792,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33615
33792
  );
33616
33793
  const swapResponse = await this.lightningService.swapNodesForPreimage({
33617
33794
  leaves: leavesToSend,
33618
- receiverIdentityPubkey: (0, import_utils24.hexToBytes)(
33795
+ receiverIdentityPubkey: (0, import_utils25.hexToBytes)(
33619
33796
  this.config.getSspIdentityPublicKey()
33620
33797
  ),
33621
- paymentHash: (0, import_utils24.hexToBytes)(paymentHash),
33798
+ paymentHash: (0, import_utils25.hexToBytes)(paymentHash),
33622
33799
  isInboundPayment: false,
33623
33800
  invoiceString: invoice,
33624
33801
  feeSats: feeEstimate,
@@ -33861,11 +34038,11 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33861
34038
  const connectorOutputs = [];
33862
34039
  for (let i = 0; i < connectorTx.outputsLength - 1; i++) {
33863
34040
  connectorOutputs.push({
33864
- txid: (0, import_utils24.hexToBytes)(connectorTxId),
34041
+ txid: (0, import_utils25.hexToBytes)(connectorTxId),
33865
34042
  index: i
33866
34043
  });
33867
34044
  }
33868
- const sspPubIdentityKey = (0, import_utils24.hexToBytes)(this.config.getSspIdentityPublicKey());
34045
+ const sspPubIdentityKey = (0, import_utils25.hexToBytes)(this.config.getSspIdentityPublicKey());
33869
34046
  const transfer = await this.coopExitService.getConnectorRefundSignatures({
33870
34047
  leaves: leafKeyTweaks,
33871
34048
  exitTxId: coopExitTxId,
@@ -33911,11 +34088,41 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33911
34088
  * Gets a transfer that has been sent by the SSP to the wallet.
33912
34089
  *
33913
34090
  * @param {string} id - The ID of the transfer
33914
- * @returns {Promise<GraphQLTransferObj | null>} The transfer
34091
+ * @returns {Promise<TransferWithUserRequest | undefined>} The transfer
33915
34092
  */
33916
34093
  async getTransferFromSsp(id) {
33917
34094
  const sspClient = this.getSspClient();
33918
- return await sspClient.getTransfer(id);
34095
+ const transfers = await sspClient.getTransfers([id]);
34096
+ return transfers?.[0];
34097
+ }
34098
+ async constructTransfersWithUserRequest(transfers) {
34099
+ const identityPublicKey = (0, import_utils25.bytesToHex)(
34100
+ await this.config.signer.getIdentityPublicKey()
34101
+ );
34102
+ const userRequests = await this.sspClient?.getTransfers(
34103
+ transfers.filter(
34104
+ (transfer) => [
34105
+ 1 /* COOPERATIVE_EXIT */,
34106
+ 40 /* COUNTER_SWAP */,
34107
+ 0 /* PREIMAGE_SWAP */,
34108
+ 30 /* SWAP */,
34109
+ 3 /* UTXO_SWAP */
34110
+ ].includes(transfer.type)
34111
+ ).map((transfer) => transfer.id)
34112
+ );
34113
+ const userRequestsMap = /* @__PURE__ */ new Map();
34114
+ for (const userRequest of userRequests || []) {
34115
+ if (userRequest && userRequest.sparkId && userRequest.userRequest) {
34116
+ userRequestsMap.set(userRequest.sparkId, userRequest.userRequest);
34117
+ }
34118
+ }
34119
+ return transfers.map(
34120
+ (transfer) => mapTransferToWalletTransfer(
34121
+ transfer,
34122
+ identityPublicKey,
34123
+ userRequestsMap.get(transfer.id)
34124
+ )
34125
+ );
33919
34126
  }
33920
34127
  /**
33921
34128
  * Gets a transfer, that the wallet is a participant of, in the Spark network.
@@ -33930,10 +34137,26 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33930
34137
  if (!transfer) {
33931
34138
  return void 0;
33932
34139
  }
33933
- return mapTransferToWalletTransfer(
33934
- transfer,
33935
- (0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey())
34140
+ return (await this.constructTransfersWithUserRequest([transfer]))[0];
34141
+ }
34142
+ /**
34143
+ * Gets all transfers for the wallet.
34144
+ *
34145
+ * @param {number} [limit=20] - Maximum number of transfers to return
34146
+ * @param {number} [offset=0] - Offset for pagination
34147
+ * @returns {Promise<QueryTransfersResponse>} Response containing the list of transfers
34148
+ */
34149
+ async getTransfers(limit = 20, offset = 0) {
34150
+ const transfers = await this.transferService.queryAllTransfers(
34151
+ limit,
34152
+ offset
33936
34153
  );
34154
+ return {
34155
+ transfers: await this.constructTransfersWithUserRequest(
34156
+ transfers.transfers
34157
+ ),
34158
+ offset: transfers.offset
34159
+ };
33937
34160
  }
33938
34161
  // ***** Token Flow *****
33939
34162
  /**
@@ -34066,8 +34289,8 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34066
34289
  tokenTransactionHashes,
34067
34290
  tokenIdentifiers,
34068
34291
  outputIds,
34069
- pageSize = 100,
34070
- offset = 0
34292
+ pageSize,
34293
+ offset
34071
34294
  }) {
34072
34295
  return this.tokenTransactionService.queryTokenTransactions({
34073
34296
  ownerPublicKeys,
@@ -34075,8 +34298,8 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34075
34298
  tokenTransactionHashes,
34076
34299
  tokenIdentifiers,
34077
34300
  outputIds,
34078
- pageSize,
34079
- offset
34301
+ pageSize: pageSize ?? 100,
34302
+ offset: offset ?? 0
34080
34303
  });
34081
34304
  }
34082
34305
  async getTokenL1Address() {
@@ -34098,7 +34321,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34098
34321
  hash,
34099
34322
  compact
34100
34323
  );
34101
- return (0, import_utils24.bytesToHex)(signature);
34324
+ return (0, import_utils25.bytesToHex)(signature);
34102
34325
  }
34103
34326
  /**
34104
34327
  * Validates a message with the identity key.
@@ -34110,7 +34333,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34110
34333
  async validateMessageWithIdentityKey(message, signature) {
34111
34334
  const hash = (0, import_sha212.sha256)(message);
34112
34335
  if (typeof signature === "string") {
34113
- signature = (0, import_utils24.hexToBytes)(signature);
34336
+ signature = (0, import_utils25.hexToBytes)(signature);
34114
34337
  }
34115
34338
  return this.config.signer.validateMessageWithIdentityKey(hash, signature);
34116
34339
  }
@@ -34123,7 +34346,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34123
34346
  */
34124
34347
  async signTransaction(txHex, keyType = "auto-detect") {
34125
34348
  try {
34126
- const tx = import_btc_signer7.Transaction.fromRaw((0, import_utils24.hexToBytes)(txHex));
34349
+ const tx = import_btc_signer7.Transaction.fromRaw((0, import_utils25.hexToBytes)(txHex));
34127
34350
  let publicKey;
34128
34351
  switch (keyType.toLowerCase()) {
34129
34352
  case "identity":
@@ -34156,7 +34379,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34156
34379
  publicKey,
34157
34380
  this.config.getNetwork()
34158
34381
  );
34159
- if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(identityScript)) {
34382
+ if ((0, import_utils25.bytesToHex)(script) === (0, import_utils25.bytesToHex)(identityScript)) {
34160
34383
  try {
34161
34384
  this.config.signer.signTransactionIndex(tx, i, publicKey);
34162
34385
  inputsSigned++;
@@ -34200,13 +34423,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34200
34423
  depositPubKey,
34201
34424
  this.config.getNetwork()
34202
34425
  );
34203
- if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(identityScript)) {
34426
+ if ((0, import_utils25.bytesToHex)(script) === (0, import_utils25.bytesToHex)(identityScript)) {
34204
34427
  return {
34205
34428
  publicKey: identityPubKey,
34206
34429
  keyType: "identity"
34207
34430
  };
34208
34431
  }
34209
- if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(depositScript)) {
34432
+ if ((0, import_utils25.bytesToHex)(script) === (0, import_utils25.bytesToHex)(depositScript)) {
34210
34433
  return {
34211
34434
  publicKey: depositPubKey,
34212
34435
  keyType: "deposit"
@@ -34509,6 +34732,111 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34509
34732
  offset += pageSize;
34510
34733
  }
34511
34734
  }
34735
+ getOtelTraceUrls() {
34736
+ const soConfig = this.config.getSigningOperators();
34737
+ const sspBaseUrl = this.config.getSspBaseUrl();
34738
+ const domains = [];
34739
+ Object.values(soConfig).forEach((so) => {
34740
+ domains.push(so.address);
34741
+ });
34742
+ if (sspBaseUrl) {
34743
+ domains.push(sspBaseUrl);
34744
+ }
34745
+ return domains;
34746
+ }
34747
+ initializeTracer(wallet) {
34748
+ const consoleOptions = wallet.config.getConsoleOptions();
34749
+ const spanProcessors = [];
34750
+ if (consoleOptions.otel) {
34751
+ console.log("OpenTelemetry client logging enabled.");
34752
+ spanProcessors.push(new import_sdk_trace_base.SimpleSpanProcessor(new import_sdk_trace_base.ConsoleSpanExporter()));
34753
+ }
34754
+ const traceUrls = this.getOtelTraceUrls();
34755
+ wallet.initializeTracerEnv({ spanProcessors, traceUrls });
34756
+ }
34757
+ initializeTracerEnv({
34758
+ spanProcessors,
34759
+ traceUrls
34760
+ }) {
34761
+ }
34762
+ wrapWithOtelSpan(name, fn) {
34763
+ return async (...args) => {
34764
+ if (!this.tracer) {
34765
+ throw new Error("Tracer not initialized");
34766
+ }
34767
+ return await this.tracer.startActiveSpan(name, async (span) => {
34768
+ const traceId = span.spanContext().traceId;
34769
+ try {
34770
+ const result = await fn(...args);
34771
+ return result;
34772
+ } catch (error) {
34773
+ if (error instanceof Error) {
34774
+ error.message += ` [traceId: ${traceId}]`;
34775
+ } else if ((0, import_core12.isObject)(error)) {
34776
+ error["traceId"] = traceId;
34777
+ }
34778
+ throw error;
34779
+ } finally {
34780
+ span.end();
34781
+ }
34782
+ });
34783
+ };
34784
+ }
34785
+ getTraceName(methodName) {
34786
+ return `SparkWallet.${methodName}`;
34787
+ }
34788
+ wrapPublicSparkWalletMethodWithOtelSpan(methodName) {
34789
+ const original = this[methodName];
34790
+ if (typeof original !== "function") {
34791
+ throw new Error(`Method ${methodName} is not a function on SparkWallet.`);
34792
+ }
34793
+ const wrapped = this.wrapWithOtelSpan(
34794
+ this.getTraceName(methodName),
34795
+ original.bind(this)
34796
+ );
34797
+ this[methodName] = wrapped;
34798
+ }
34799
+ wrapSparkWalletMethodsWithTracing() {
34800
+ const methods = [
34801
+ "getLeaves",
34802
+ "getIdentityPublicKey",
34803
+ "getSparkAddress",
34804
+ "createSparkPaymentIntent",
34805
+ "getSwapFeeEstimate",
34806
+ "getTransfers",
34807
+ "getBalance",
34808
+ "getSingleUseDepositAddress",
34809
+ "getStaticDepositAddress",
34810
+ "queryStaticDepositAddresses",
34811
+ "getClaimStaticDepositQuote",
34812
+ "claimStaticDeposit",
34813
+ "refundStaticDeposit",
34814
+ "getUnusedDepositAddresses",
34815
+ "claimDeposit",
34816
+ "advancedDeposit",
34817
+ "transfer",
34818
+ "createLightningInvoice",
34819
+ "payLightningInvoice",
34820
+ "getLightningSendFeeEstimate",
34821
+ "withdraw",
34822
+ "getWithdrawalFeeQuote",
34823
+ "getTransferFromSsp",
34824
+ "getTransfer",
34825
+ "transferTokens",
34826
+ "batchTransferTokens",
34827
+ "queryTokenTransactions",
34828
+ "getLightningReceiveRequest",
34829
+ "getLightningSendRequest",
34830
+ "getCoopExitRequest",
34831
+ "checkTimelock",
34832
+ "testOnly_expireTimelock"
34833
+ ];
34834
+ methods.forEach((m) => this.wrapPublicSparkWalletMethodWithOtelSpan(m));
34835
+ this.initWallet = this.wrapWithOtelSpan(
34836
+ this.getTraceName("initWallet"),
34837
+ this.initWallet.bind(this)
34838
+ );
34839
+ }
34512
34840
  };
34513
34841
 
34514
34842
  // src/spark-wallet/types.ts
@@ -34575,7 +34903,7 @@ setCrypto(globalThis.crypto);
34575
34903
  encodeSparkAddress,
34576
34904
  evaluatePolynomial,
34577
34905
  fieldDiv,
34578
- filterTokenBalanceForTokenPublicKey,
34906
+ filterTokenBalanceForTokenIdentifier,
34579
34907
  generateAdaptorFromSignature,
34580
34908
  generatePolynomialForSecretSharing,
34581
34909
  generateSignatureFromExistingAdaptor,
@@ -34584,6 +34912,7 @@ setCrypto(globalThis.crypto);
34584
34912
  getLatestDepositTxId,
34585
34913
  getNetwork,
34586
34914
  getNetworkFromAddress,
34915
+ getNetworkFromBech32mTokenIdentifier,
34587
34916
  getNetworkFromString,
34588
34917
  getNextTransactionSequence,
34589
34918
  getP2TRAddressFromPkScript,
@@ -34597,6 +34926,7 @@ setCrypto(globalThis.crypto);
34597
34926
  getSparkAddressFromTaproot,
34598
34927
  getTransactionSequence,
34599
34928
  getTransferPackageSigningPayload,
34929
+ getTxEstimatedVbytesSizeByNumberOfInputsOutputs,
34600
34930
  getTxFromRawTxBytes,
34601
34931
  getTxFromRawTxHex,
34602
34932
  getTxId,