@buildonspark/spark-sdk 0.1.41 → 0.1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/android/src/main/jniLibs/arm64-v8a/libuniffi_spark_frost.so +0 -0
  3. package/android/src/main/jniLibs/armeabi-v7a/libuniffi_spark_frost.so +0 -0
  4. package/android/src/main/jniLibs/x86/libuniffi_spark_frost.so +0 -0
  5. package/android/src/main/jniLibs/x86_64/libuniffi_spark_frost.so +0 -0
  6. package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.cts +10 -0
  7. package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.ts +10 -0
  8. package/dist/{RequestLightningSendInput-mXUWn_cp.d.ts → RequestLightningSendInput-D7fZdT4A.d.ts} +35 -16
  9. package/dist/{RequestLightningSendInput-DXcLoiCe.d.cts → RequestLightningSendInput-Na1mHdWg.d.cts} +35 -16
  10. package/dist/address/index.cjs +38 -7
  11. package/dist/address/index.d.cts +2 -2
  12. package/dist/address/index.d.ts +2 -2
  13. package/dist/address/index.js +3 -3
  14. package/dist/{chunk-ATEHMLKP.js → chunk-6AFUC5M2.js} +1 -1
  15. package/dist/{chunk-ZXDE2XMU.js → chunk-BUTZWYBW.js} +9 -6
  16. package/dist/{chunk-7EFSUADA.js → chunk-DOA6QXYQ.js} +1 -0
  17. package/dist/{chunk-J5W5Q2ZP.js → chunk-DQYKQJRZ.js} +291 -7
  18. package/dist/{chunk-TWF35O6M.js → chunk-GSI4OLXZ.js} +32 -1
  19. package/dist/{chunk-2ZXXLPG2.js → chunk-GYQR4B4P.js} +5 -4
  20. package/dist/{chunk-ROKY5KS4.js → chunk-HRQRRDSS.js} +53 -15
  21. package/dist/{chunk-YEZDPUFY.js → chunk-IRW5TWMH.js} +8 -8
  22. package/dist/{chunk-7VMYMQLF.js → chunk-NSJF5F5O.js} +1 -1
  23. package/dist/{chunk-TM4TOEOX.js → chunk-O4RYNJNB.js} +3 -3
  24. package/dist/{chunk-MGPRLH6Q.js → chunk-QNNSEJ4P.js} +1 -1
  25. package/dist/{chunk-UKT6OFLO.js → chunk-TIUBYNN5.js} +13 -7
  26. package/dist/{chunk-6YVPOQ2A.js → chunk-TOSP3INR.js} +235 -143
  27. package/dist/chunk-VFJQNBFX.js +21 -0
  28. package/dist/{chunk-KKSU7OZO.js → chunk-WWOTVNPP.js} +195 -67
  29. package/dist/{chunk-HK6LPV6Z.js → chunk-Z5HIAYFT.js} +1 -1
  30. package/dist/graphql/objects/index.cjs +229 -135
  31. package/dist/graphql/objects/index.d.cts +54 -9
  32. package/dist/graphql/objects/index.d.ts +54 -9
  33. package/dist/graphql/objects/index.js +3 -3
  34. package/dist/{index-OSDtPMmC.d.ts → index-7RYRH5wc.d.ts} +10 -8
  35. package/dist/{index-CFh4uWzi.d.cts → index-BJOc8Ur-.d.cts} +10 -8
  36. package/dist/index.cjs +790 -315
  37. package/dist/index.d.cts +8 -7
  38. package/dist/index.d.ts +8 -7
  39. package/dist/index.js +26 -26
  40. package/dist/index.node.cjs +790 -315
  41. package/dist/index.node.d.cts +9 -8
  42. package/dist/index.node.d.ts +9 -8
  43. package/dist/index.node.js +26 -26
  44. package/dist/native/index.cjs +812 -332
  45. package/dist/native/index.d.cts +53 -18
  46. package/dist/native/index.d.ts +53 -18
  47. package/dist/native/index.js +659 -181
  48. package/dist/{network-BiwBmoOg.d.cts → network-D5lKssVl.d.cts} +1 -1
  49. package/dist/{network-BF2GYPye.d.ts → network-xkBSpaTn.d.ts} +1 -1
  50. package/dist/proto/lrc20.d.cts +1 -1
  51. package/dist/proto/lrc20.d.ts +1 -1
  52. package/dist/proto/spark.d.cts +1 -1
  53. package/dist/proto/spark.d.ts +1 -1
  54. package/dist/proto/spark_token.d.cts +1 -1
  55. package/dist/proto/spark_token.d.ts +1 -1
  56. package/dist/{sdk-types-CfhdFnsA.d.cts → sdk-types-B-q9py_P.d.cts} +1 -1
  57. package/dist/{sdk-types-MnQrHolg.d.ts → sdk-types-BPoPgzda.d.ts} +1 -1
  58. package/dist/services/config.cjs +118 -69
  59. package/dist/services/config.d.cts +6 -4
  60. package/dist/services/config.d.ts +6 -4
  61. package/dist/services/config.js +9 -9
  62. package/dist/services/connection.cjs +95 -15
  63. package/dist/services/connection.d.cts +6 -4
  64. package/dist/services/connection.d.ts +6 -4
  65. package/dist/services/connection.js +3 -3
  66. package/dist/services/index.cjs +487 -117
  67. package/dist/services/index.d.cts +5 -4
  68. package/dist/services/index.d.ts +5 -4
  69. package/dist/services/index.js +19 -19
  70. package/dist/services/lrc-connection.cjs +50 -7
  71. package/dist/services/lrc-connection.d.cts +5 -4
  72. package/dist/services/lrc-connection.d.ts +5 -4
  73. package/dist/services/lrc-connection.js +3 -3
  74. package/dist/services/token-transactions.cjs +351 -36
  75. package/dist/services/token-transactions.d.cts +5 -4
  76. package/dist/services/token-transactions.d.ts +5 -4
  77. package/dist/services/token-transactions.js +6 -6
  78. package/dist/services/wallet-config.cjs +1 -0
  79. package/dist/services/wallet-config.d.cts +6 -4
  80. package/dist/services/wallet-config.d.ts +6 -4
  81. package/dist/services/wallet-config.js +1 -1
  82. package/dist/signer/signer.cjs +117 -64
  83. package/dist/signer/signer.d.cts +4 -3
  84. package/dist/signer/signer.d.ts +4 -3
  85. package/dist/signer/signer.js +15 -7
  86. package/dist/{signer-CylxIujU.d.ts → signer-IO3oMRNj.d.cts} +2 -1
  87. package/dist/{signer-BhLS7SYR.d.cts → signer-wqesWifN.d.ts} +2 -1
  88. package/dist/{spark-DjR1b3TC.d.cts → spark-CDm4gqS6.d.cts} +1 -1
  89. package/dist/{spark-DjR1b3TC.d.ts → spark-CDm4gqS6.d.ts} +1 -1
  90. package/dist/types/index.cjs +282 -188
  91. package/dist/types/index.d.cts +7 -6
  92. package/dist/types/index.d.ts +7 -6
  93. package/dist/types/index.js +3 -3
  94. package/dist/utils/index.cjs +90 -58
  95. package/dist/utils/index.d.cts +6 -5
  96. package/dist/utils/index.d.ts +6 -5
  97. package/dist/utils/index.js +16 -16
  98. package/ios/spark_frostFFI.xcframework/ios-arm64/SparkFrost +0 -0
  99. package/ios/spark_frostFFI.xcframework/ios-arm64/spark_frostFFI.framework/spark_frostFFI +0 -0
  100. package/ios/spark_frostFFI.xcframework/ios-arm64_x86_64-simulator/SparkFrost +0 -0
  101. package/ios/spark_frostFFI.xcframework/ios-arm64_x86_64-simulator/spark_frostFFI.framework/spark_frostFFI +0 -0
  102. package/ios/spark_frostFFI.xcframework/macos-arm64_x86_64/spark_frostFFI.framework/spark_frostFFI +0 -0
  103. package/package.json +4 -4
  104. package/src/constants.ts +21 -0
  105. package/src/errors/base.ts +43 -1
  106. package/src/graphql/client.ts +4 -0
  107. package/src/graphql/mutations/RequestLightningSend.ts +2 -0
  108. package/src/graphql/objects/ClaimStaticDepositInput.ts +1 -1
  109. package/src/graphql/objects/ClaimStaticDepositStatus.ts +4 -2
  110. package/src/graphql/objects/Connection.ts +7 -7
  111. package/src/graphql/objects/CoopExitFeeEstimate.ts +1 -1
  112. package/src/graphql/objects/CoopExitFeeQuote.ts +202 -0
  113. package/src/graphql/objects/CoopExitFeeQuoteInput.ts +41 -0
  114. package/src/graphql/objects/CoopExitFeeQuoteOutput.ts +45 -0
  115. package/src/graphql/objects/CoopExitRequest.ts +21 -0
  116. package/src/graphql/objects/CurrencyUnit.ts +26 -28
  117. package/src/graphql/objects/Entity.ts +84 -0
  118. package/src/graphql/objects/Invoice.ts +2 -2
  119. package/src/graphql/objects/Leaf.ts +1 -1
  120. package/src/graphql/objects/LeavesSwapFeeEstimateOutput.ts +1 -1
  121. package/src/graphql/objects/LeavesSwapRequest.ts +6 -0
  122. package/src/graphql/objects/LightningReceiveRequest.ts +11 -0
  123. package/src/graphql/objects/LightningSendFeeEstimateInput.ts +8 -0
  124. package/src/graphql/objects/LightningSendFeeEstimateOutput.ts +1 -1
  125. package/src/graphql/objects/LightningSendRequest.ts +3 -0
  126. package/src/graphql/objects/RequestCoopExitInput.ts +8 -0
  127. package/src/graphql/objects/RequestLeavesSwapInput.ts +5 -1
  128. package/src/graphql/objects/RequestLightningReceiveInput.ts +9 -2
  129. package/src/graphql/objects/RequestLightningSendInput.ts +8 -0
  130. package/src/graphql/objects/SparkCoopExitRequestStatus.ts +2 -0
  131. package/src/graphql/objects/SparkUserRequestType.ts +2 -0
  132. package/src/graphql/objects/SparkWalletUser.ts +20 -0
  133. package/src/graphql/objects/UserRequest.ts +32 -0
  134. package/src/graphql/objects/VerifyChallengeInput.ts +1 -1
  135. package/src/graphql/objects/index.ts +12 -3
  136. package/src/graphql/queries/LightningSendFeeEstimate.ts +2 -0
  137. package/src/logger.ts +3 -0
  138. package/src/native/index.ts +1 -0
  139. package/src/services/config.ts +4 -0
  140. package/src/services/connection.ts +68 -29
  141. package/src/services/coop-exit.ts +1 -1
  142. package/src/services/lightning.ts +25 -1
  143. package/src/services/lrc-connection.ts +3 -3
  144. package/src/services/token-transactions.ts +6 -2
  145. package/src/services/wallet-config.ts +2 -0
  146. package/src/signer/signer.ts +4 -1
  147. package/src/spark-wallet/spark-wallet.ts +51 -15
  148. package/src/spark-wallet/types.ts +1 -0
  149. package/src/tests/errors.test.ts +58 -0
  150. package/src/tests/integration/lightning.test.ts +184 -0
  151. package/src/tests/integration/ssp/static_deposit.test.ts +1 -2
  152. package/src/tests/tokens.test.ts +52 -3
  153. package/src/utils/token-hashing.ts +335 -1
  154. package/dist/LightningSendFeeEstimateInput-CJvPnCSB.d.cts +0 -5
  155. package/dist/LightningSendFeeEstimateInput-CJvPnCSB.d.ts +0 -5
  156. package/dist/chunk-HKAKEKCE.js +0 -8
@@ -1024,7 +1024,7 @@ var init_spark_bindings = __esm({
1024
1024
  var wasm_exports = {};
1025
1025
  __export(wasm_exports, {
1026
1026
  aggregateFrost: () => aggregateFrost,
1027
- createDummyTx: () => createDummyTx,
1027
+ createDummyTx: () => createDummyTx2,
1028
1028
  createKeyPackage: () => createKeyPackage,
1029
1029
  createSigningCommitment: () => createSigningCommitment2,
1030
1030
  createSigningNonce: () => createSigningNonce2,
@@ -1085,7 +1085,7 @@ function aggregateFrost({
1085
1085
  adaptorPubKey
1086
1086
  );
1087
1087
  }
1088
- function createDummyTx({
1088
+ function createDummyTx2({
1089
1089
  address: address2,
1090
1090
  amountSats
1091
1091
  }) {
@@ -1318,6 +1318,7 @@ __export(index_exports, {
1318
1318
  constructFeeBumpTx: () => constructFeeBumpTx,
1319
1319
  constructUnilateralExitFeeBumpPackages: () => constructUnilateralExitFeeBumpPackages,
1320
1320
  constructUnilateralExitTxs: () => constructUnilateralExitTxs,
1321
+ createDummyTx: () => createDummyTx,
1321
1322
  createRefundTx: () => createRefundTx,
1322
1323
  createSigningCommitment: () => createSigningCommitment,
1323
1324
  createSigningNonce: () => createSigningNonce,
@@ -1376,6 +1377,7 @@ init_buffer();
1376
1377
 
1377
1378
  // src/errors/base.ts
1378
1379
  init_buffer();
1380
+ var import_utils = require("@noble/hashes/utils");
1379
1381
  var SparkSDKError = class extends Error {
1380
1382
  context;
1381
1383
  originalError;
@@ -1407,12 +1409,42 @@ var SparkSDKError = class extends Error {
1407
1409
  }
1408
1410
  };
1409
1411
  function getMessage(message, context = {}, originalError) {
1410
- const contextStr = Object.entries(context).map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(", ");
1412
+ const contextStr = Object.entries(context).map(([key, value]) => `${key}: ${safeStringify(value)}`).join(", ");
1411
1413
  const originalErrorStr = originalError ? `
1412
1414
  Original Error: ${originalError.message}` : "";
1413
1415
  return `SparkSDKError: ${message}${contextStr ? `
1414
1416
  Context: ${contextStr}` : ""}${originalErrorStr}`;
1415
1417
  }
1418
+ function safeStringify(value) {
1419
+ const replacer = (_, v) => {
1420
+ if (typeof v === "bigint") {
1421
+ return v.toString();
1422
+ }
1423
+ if (v instanceof Uint8Array) {
1424
+ return formatUint8Array(v);
1425
+ }
1426
+ return v;
1427
+ };
1428
+ if (typeof value === "bigint") {
1429
+ return `"${value.toString()}"`;
1430
+ }
1431
+ if (value instanceof Uint8Array) {
1432
+ return `"${formatUint8Array(value)}"`;
1433
+ }
1434
+ try {
1435
+ const result = JSON.stringify(value, replacer);
1436
+ return result === void 0 ? String(value) : result;
1437
+ } catch {
1438
+ try {
1439
+ return String(value);
1440
+ } catch {
1441
+ return "[Unserializable]";
1442
+ }
1443
+ }
1444
+ }
1445
+ function formatUint8Array(arr) {
1446
+ return `Uint8Array(0x${(0, import_utils.bytesToHex)(arr)})`;
1447
+ }
1416
1448
 
1417
1449
  // src/errors/types.ts
1418
1450
  init_buffer();
@@ -1454,7 +1486,7 @@ var NotImplementedError = class extends SparkSDKError {
1454
1486
 
1455
1487
  // src/signer/signer.react-native.ts
1456
1488
  init_buffer();
1457
- var import_utils6 = require("@noble/hashes/utils");
1489
+ var import_utils7 = require("@noble/hashes/utils");
1458
1490
 
1459
1491
  // src/spark_bindings/native/index.ts
1460
1492
  init_buffer();
@@ -1581,10 +1613,13 @@ var NativeSparkFrost = class {
1581
1613
  return toUint8Array(result);
1582
1614
  }
1583
1615
  };
1616
+ async function createDummyTx(address2, amountSats) {
1617
+ return NativeSparkFrost.createDummyTx(address2, amountSats);
1618
+ }
1584
1619
 
1585
1620
  // src/signer/signer.ts
1586
1621
  init_buffer();
1587
- var import_utils4 = require("@noble/curves/abstract/utils");
1622
+ var import_utils5 = require("@noble/curves/abstract/utils");
1588
1623
  var import_secp256k15 = require("@noble/curves/secp256k1");
1589
1624
  var import_bip32 = require("@scure/bip32");
1590
1625
  var import_bip39 = require("@scure/bip39");
@@ -1593,29 +1628,41 @@ var ecies = __toESM(require("eciesjs"), 1);
1593
1628
 
1594
1629
  // src/constants.ts
1595
1630
  init_buffer();
1631
+ var import_core = require("@lightsparkdev/core");
1596
1632
  var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
1597
1633
  var isBun = globalThis.Bun !== void 0;
1634
+ var packageVersion = true ? "0.1.43" : "unknown";
1635
+ var baseEnvStr = "unknown";
1636
+ if (import_core.isNode) {
1637
+ baseEnvStr = `node/${process.version}`;
1638
+ } else if (isReactNative) {
1639
+ baseEnvStr = "react-native";
1640
+ } else {
1641
+ const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "unknown-user-agent";
1642
+ baseEnvStr = `browser/${userAgent}`;
1643
+ }
1644
+ var clientEnv = `js-spark-sdk/${packageVersion} ${baseEnvStr}`;
1598
1645
 
1599
1646
  // src/utils/adaptor-signature.ts
1600
1647
  init_buffer();
1601
1648
  var import_modular = require("@noble/curves/abstract/modular");
1602
- var import_utils = require("@noble/curves/abstract/utils");
1649
+ var import_utils2 = require("@noble/curves/abstract/utils");
1603
1650
  var import_secp256k1 = require("@noble/curves/secp256k1");
1604
1651
  function generateSignatureFromExistingAdaptor(signature, adaptorPrivateKeyBytes) {
1605
1652
  const { r, s } = parseSignature(signature);
1606
- const sBigInt = (0, import_utils.bytesToNumberBE)(s);
1607
- const tBigInt = (0, import_utils.bytesToNumberBE)(adaptorPrivateKeyBytes);
1653
+ const sBigInt = (0, import_utils2.bytesToNumberBE)(s);
1654
+ const tBigInt = (0, import_utils2.bytesToNumberBE)(adaptorPrivateKeyBytes);
1608
1655
  const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k1.secp256k1.CURVE.n);
1609
- const newSignature = new Uint8Array([...r, ...(0, import_utils.numberToBytesBE)(newS, 32)]);
1656
+ const newSignature = new Uint8Array([...r, ...(0, import_utils2.numberToBytesBE)(newS, 32)]);
1610
1657
  return newSignature;
1611
1658
  }
1612
1659
  function generateAdaptorFromSignature(signature) {
1613
1660
  const adaptorPrivateKey = import_secp256k1.secp256k1.utils.randomPrivateKey();
1614
1661
  const { r, s } = parseSignature(signature);
1615
- const sBigInt = (0, import_utils.bytesToNumberBE)(s);
1616
- const tBigInt = (0, import_utils.bytesToNumberBE)(adaptorPrivateKey);
1662
+ const sBigInt = (0, import_utils2.bytesToNumberBE)(s);
1663
+ const tBigInt = (0, import_utils2.bytesToNumberBE)(adaptorPrivateKey);
1617
1664
  const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k1.secp256k1.CURVE.n);
1618
- const newSignature = new Uint8Array([...r, ...(0, import_utils.numberToBytesBE)(newS, 32)]);
1665
+ const newSignature = new Uint8Array([...r, ...(0, import_utils2.numberToBytesBE)(newS, 32)]);
1619
1666
  return {
1620
1667
  adaptorSignature: newSignature,
1621
1668
  adaptorPrivateKey
@@ -1632,15 +1679,15 @@ function validateOutboundAdaptorSignature(pubkey, hash, signature, adaptorPubkey
1632
1679
  }
1633
1680
  function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes) {
1634
1681
  const { r, s } = parseSignature(signature);
1635
- const sBigInt = (0, import_utils.bytesToNumberBE)(s);
1636
- const adaptorPrivateKey = (0, import_utils.bytesToNumberBE)(adaptorPrivateKeyBytes);
1682
+ const sBigInt = (0, import_utils2.bytesToNumberBE)(s);
1683
+ const adaptorPrivateKey = (0, import_utils2.bytesToNumberBE)(adaptorPrivateKeyBytes);
1637
1684
  const newS = (0, import_modular.mod)(sBigInt + adaptorPrivateKey, import_secp256k1.secp256k1.CURVE.n);
1638
- const newSig = new Uint8Array([...r, ...(0, import_utils.numberToBytesBE)(newS, 32)]);
1685
+ const newSig = new Uint8Array([...r, ...(0, import_utils2.numberToBytesBE)(newS, 32)]);
1639
1686
  if (import_secp256k1.schnorr.verify(newSig, hash, pubkey)) {
1640
1687
  return newSig;
1641
1688
  }
1642
1689
  const altS = (0, import_modular.mod)(sBigInt - adaptorPrivateKey, import_secp256k1.secp256k1.CURVE.n);
1643
- const altSig = new Uint8Array([...r, ...(0, import_utils.numberToBytesBE)(altS, 32)]);
1690
+ const altSig = new Uint8Array([...r, ...(0, import_utils2.numberToBytesBE)(altS, 32)]);
1644
1691
  if (import_secp256k1.schnorr.verify(altSig, hash, pubkey)) {
1645
1692
  return altSig;
1646
1693
  }
@@ -1650,7 +1697,7 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
1650
1697
  if (hash.length !== 32) {
1651
1698
  throw new Error(`wrong size for message (got ${hash.length}, want 32)`);
1652
1699
  }
1653
- const pubKey = import_secp256k1.schnorr.utils.lift_x((0, import_utils.bytesToNumberBE)(pubKeyBytes));
1700
+ const pubKey = import_secp256k1.schnorr.utils.lift_x((0, import_utils2.bytesToNumberBE)(pubKeyBytes));
1654
1701
  pubKey.assertValidity();
1655
1702
  const { r, s } = parseSignature(signature);
1656
1703
  const commitmenet = import_secp256k1.schnorr.utils.taggedHash(
@@ -1662,11 +1709,11 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
1662
1709
  if (commitmenet.length > 32) {
1663
1710
  throw new Error("hash of (r || P || m) too big");
1664
1711
  }
1665
- const e = (0, import_modular.mod)((0, import_utils.bytesToNumberBE)(commitmenet), import_secp256k1.secp256k1.CURVE.n);
1712
+ const e = (0, import_modular.mod)((0, import_utils2.bytesToNumberBE)(commitmenet), import_secp256k1.secp256k1.CURVE.n);
1666
1713
  const negE = (0, import_modular.mod)(-e, import_secp256k1.secp256k1.CURVE.n);
1667
1714
  const R = import_secp256k1.secp256k1.ProjectivePoint.BASE.multiplyAndAddUnsafe(
1668
1715
  pubKey,
1669
- (0, import_utils.bytesToNumberBE)(s),
1716
+ (0, import_utils2.bytesToNumberBE)(s),
1670
1717
  negE
1671
1718
  );
1672
1719
  if (!R) {
@@ -1682,7 +1729,7 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
1682
1729
  if (!newR.hasEvenY()) {
1683
1730
  throw new Error("calculated R y-value is odd");
1684
1731
  }
1685
- const rNum = (0, import_utils.bytesToNumberBE)(r);
1732
+ const rNum = (0, import_utils2.bytesToNumberBE)(r);
1686
1733
  if (newR.toAffine().x !== rNum) {
1687
1734
  throw new Error("calculated R point was not given R");
1688
1735
  }
@@ -1703,15 +1750,15 @@ function parseSignature(signature) {
1703
1750
  }
1704
1751
  const r = signature.slice(0, 32);
1705
1752
  const s = signature.slice(32, 64);
1706
- if ((0, import_utils.bytesToNumberBE)(r) >= import_secp256k1.secp256k1.CURVE.Fp.ORDER) {
1753
+ if ((0, import_utils2.bytesToNumberBE)(r) >= import_secp256k1.secp256k1.CURVE.Fp.ORDER) {
1707
1754
  throw new ValidationError("Invalid signature: r >= field prime", {
1708
- rValue: (0, import_utils.bytesToNumberBE)(r),
1755
+ rValue: (0, import_utils2.bytesToNumberBE)(r),
1709
1756
  fieldPrime: import_secp256k1.secp256k1.CURVE.Fp.ORDER
1710
1757
  });
1711
1758
  }
1712
- if ((0, import_utils.bytesToNumberBE)(s) >= import_secp256k1.secp256k1.CURVE.n) {
1759
+ if ((0, import_utils2.bytesToNumberBE)(s) >= import_secp256k1.secp256k1.CURVE.n) {
1713
1760
  throw new ValidationError("Invalid signature: s >= group order", {
1714
- sValue: (0, import_utils.bytesToNumberBE)(s),
1761
+ sValue: (0, import_utils2.bytesToNumberBE)(s),
1715
1762
  groupOrder: import_secp256k1.secp256k1.CURVE.n
1716
1763
  });
1717
1764
  }
@@ -1720,7 +1767,7 @@ function parseSignature(signature) {
1720
1767
 
1721
1768
  // src/utils/keys.ts
1722
1769
  init_buffer();
1723
- var import_utils2 = require("@noble/curves/abstract/utils");
1770
+ var import_utils3 = require("@noble/curves/abstract/utils");
1724
1771
  var import_secp256k12 = require("@noble/curves/secp256k1");
1725
1772
  function addPublicKeys(a, b) {
1726
1773
  if (a.length !== 33 || b.length !== 33) {
@@ -1778,7 +1825,7 @@ function addPrivateKeys(a, b) {
1778
1825
  const privA = import_secp256k12.secp256k1.utils.normPrivateKeyToScalar(a);
1779
1826
  const privB = import_secp256k12.secp256k1.utils.normPrivateKeyToScalar(b);
1780
1827
  const sum = (privA + privB) % import_secp256k12.secp256k1.CURVE.n;
1781
- return (0, import_utils2.numberToBytesBE)(sum, 32);
1828
+ return (0, import_utils3.numberToBytesBE)(sum, 32);
1782
1829
  }
1783
1830
  function subtractPrivateKeys(a, b) {
1784
1831
  if (a.length !== 32 || b.length !== 32) {
@@ -1791,7 +1838,7 @@ function subtractPrivateKeys(a, b) {
1791
1838
  const privA = import_secp256k12.secp256k1.utils.normPrivateKeyToScalar(a);
1792
1839
  const privB = import_secp256k12.secp256k1.utils.normPrivateKeyToScalar(b);
1793
1840
  const sum = (import_secp256k12.secp256k1.CURVE.n - privB + privA) % import_secp256k12.secp256k1.CURVE.n;
1794
- return (0, import_utils2.numberToBytesBE)(sum, 32);
1841
+ return (0, import_utils3.numberToBytesBE)(sum, 32);
1795
1842
  }
1796
1843
  function sumOfPrivateKeys(keys) {
1797
1844
  return keys.reduce((sum, key) => {
@@ -1819,7 +1866,7 @@ function lastKeyWithTarget(target, keys) {
1819
1866
 
1820
1867
  // src/utils/secret-sharing.ts
1821
1868
  init_buffer();
1822
- var import_utils3 = require("@noble/curves/abstract/utils");
1869
+ var import_utils4 = require("@noble/curves/abstract/utils");
1823
1870
  var import_secp256k13 = require("@noble/curves/secp256k1");
1824
1871
 
1825
1872
  // src/utils/crypto.ts
@@ -1838,7 +1885,7 @@ function getRandomBigInt(max) {
1838
1885
  const mask = (1n << BigInt(max.toString(2).length)) - 1n;
1839
1886
  while (true) {
1840
1887
  const randBytes = crypto.getRandomValues(new Uint8Array(byteLength + 1));
1841
- const randValue = BigInt("0x" + (0, import_utils3.bytesToHex)(randBytes)) & mask;
1888
+ const randValue = BigInt("0x" + (0, import_utils4.bytesToHex)(randBytes)) & mask;
1842
1889
  if (randValue < maxBigInt) {
1843
1890
  return randValue;
1844
1891
  }
@@ -2016,7 +2063,7 @@ function validateShare(share) {
2016
2063
  const scaledPoint = import_secp256k13.secp256k1.ProjectivePoint.fromHex(pubkey).multiply(value);
2017
2064
  resultPubkey = import_secp256k13.secp256k1.ProjectivePoint.fromHex(resultPubkey).add(scaledPoint).toRawBytes(true);
2018
2065
  }
2019
- if (!(0, import_utils3.equalBytes)(resultPubkey, targetPubkey)) {
2066
+ if (!(0, import_utils4.equalBytes)(resultPubkey, targetPubkey)) {
2020
2067
  throw new ValidationError("Share is not valid", {
2021
2068
  field: "share",
2022
2069
  value: "Invalid proof",
@@ -2119,7 +2166,9 @@ function decodeBytesToSigningCommitment(bytes2) {
2119
2166
  var import_secp256k16 = require("@bitcoinerlab/secp256k1");
2120
2167
  var import_lrc20_sdk = require("@buildonspark/lrc20-sdk");
2121
2168
  var import_sha2 = require("@noble/hashes/sha2");
2122
- var import_utils5 = require("@scure/btc-signer/utils");
2169
+ var import_utils6 = require("@scure/btc-signer/utils");
2170
+ var import_lrc20_sdk2 = require("@buildonspark/lrc20-sdk");
2171
+ var import_types2 = require("@buildonspark/lrc20-sdk/lrc/types");
2123
2172
  var sparkFrostModule = void 0;
2124
2173
  var getSparkFrostModule = async () => {
2125
2174
  if (isReactNative) {
@@ -2218,28 +2267,28 @@ var DefaultSparkSigner = class {
2218
2267
  const privateKey = this.deriveSigningKey(hash);
2219
2268
  const publicKey = import_secp256k15.secp256k1.getPublicKey(privateKey);
2220
2269
  this.publicKeyToPrivateKeyMap.set(
2221
- (0, import_utils4.bytesToHex)(publicKey),
2222
- (0, import_utils4.bytesToHex)(privateKey)
2270
+ (0, import_utils5.bytesToHex)(publicKey),
2271
+ (0, import_utils5.bytesToHex)(privateKey)
2223
2272
  );
2224
2273
  }
2225
2274
  }
2226
2275
  async getSchnorrPublicKey(publicKey) {
2227
- const privateKey = this.publicKeyToPrivateKeyMap.get((0, import_utils4.bytesToHex)(publicKey));
2276
+ const privateKey = this.publicKeyToPrivateKeyMap.get((0, import_utils5.bytesToHex)(publicKey));
2228
2277
  if (!privateKey) {
2229
2278
  throw new ValidationError("Private key is not set", {
2230
2279
  field: "privateKey"
2231
2280
  });
2232
2281
  }
2233
- return import_secp256k15.schnorr.getPublicKey((0, import_utils4.hexToBytes)(privateKey));
2282
+ return import_secp256k15.schnorr.getPublicKey((0, import_utils5.hexToBytes)(privateKey));
2234
2283
  }
2235
2284
  async signSchnorr(message, publicKey) {
2236
- const privateKey = this.publicKeyToPrivateKeyMap.get((0, import_utils4.bytesToHex)(publicKey));
2285
+ const privateKey = this.publicKeyToPrivateKeyMap.get((0, import_utils5.bytesToHex)(publicKey));
2237
2286
  if (!privateKey) {
2238
2287
  throw new ValidationError("Private key is not set", {
2239
2288
  field: "privateKey"
2240
2289
  });
2241
2290
  }
2242
- return import_secp256k15.schnorr.sign(message, (0, import_utils4.hexToBytes)(privateKey));
2291
+ return import_secp256k15.schnorr.sign(message, (0, import_utils5.hexToBytes)(privateKey));
2243
2292
  }
2244
2293
  async signSchnorrWithIdentityKey(message) {
2245
2294
  if (!this.identityKey?.privateKey) {
@@ -2281,8 +2330,8 @@ var DefaultSparkSigner = class {
2281
2330
  );
2282
2331
  this.staticDepositKeyMap.set(idx, staticDepositKey);
2283
2332
  this.publicKeyToPrivateKeyMap.set(
2284
- (0, import_utils4.bytesToHex)(staticDepositKey.publicKey),
2285
- (0, import_utils4.bytesToHex)(staticDepositKey.privateKey)
2333
+ (0, import_utils5.bytesToHex)(staticDepositKey.publicKey),
2334
+ (0, import_utils5.bytesToHex)(staticDepositKey.privateKey)
2286
2335
  );
2287
2336
  return staticDepositKey.publicKey;
2288
2337
  }
@@ -2327,7 +2376,7 @@ var DefaultSparkSigner = class {
2327
2376
  return await (0, import_bip39.mnemonicToSeed)(mnemonic);
2328
2377
  }
2329
2378
  async getTrackedPublicKeys() {
2330
- return Array.from(this.publicKeyToPrivateKeyMap.keys()).map(import_utils4.hexToBytes);
2379
+ return Array.from(this.publicKeyToPrivateKeyMap.keys()).map(import_utils5.hexToBytes);
2331
2380
  }
2332
2381
  async generatePublicKey(hash) {
2333
2382
  if (!this.signingKey) {
@@ -2347,31 +2396,31 @@ var DefaultSparkSigner = class {
2347
2396
  });
2348
2397
  }
2349
2398
  const publicKey = import_secp256k15.secp256k1.getPublicKey(newPrivateKey);
2350
- const pubKeyHex = (0, import_utils4.bytesToHex)(publicKey);
2351
- const privKeyHex = (0, import_utils4.bytesToHex)(newPrivateKey);
2399
+ const pubKeyHex = (0, import_utils5.bytesToHex)(publicKey);
2400
+ const privKeyHex = (0, import_utils5.bytesToHex)(newPrivateKey);
2352
2401
  this.publicKeyToPrivateKeyMap.set(pubKeyHex, privKeyHex);
2353
2402
  return publicKey;
2354
2403
  }
2355
2404
  async removePublicKey(publicKey) {
2356
- this.publicKeyToPrivateKeyMap.delete((0, import_utils4.bytesToHex)(publicKey));
2405
+ this.publicKeyToPrivateKeyMap.delete((0, import_utils5.bytesToHex)(publicKey));
2357
2406
  }
2358
2407
  async subtractPrivateKeysGivenPublicKeys(first, second) {
2359
- const firstPubKeyHex = (0, import_utils4.bytesToHex)(first);
2360
- const secondPubKeyHex = (0, import_utils4.bytesToHex)(second);
2408
+ const firstPubKeyHex = (0, import_utils5.bytesToHex)(first);
2409
+ const secondPubKeyHex = (0, import_utils5.bytesToHex)(second);
2361
2410
  const firstPrivateKeyHex = this.publicKeyToPrivateKeyMap.get(firstPubKeyHex);
2362
2411
  const secondPrivateKeyHex = this.publicKeyToPrivateKeyMap.get(secondPubKeyHex);
2363
2412
  if (!firstPrivateKeyHex || !secondPrivateKeyHex) {
2364
2413
  throw new Error("Private key is not set");
2365
2414
  }
2366
- const firstPrivateKey = (0, import_utils4.hexToBytes)(firstPrivateKeyHex);
2367
- const secondPrivateKey = (0, import_utils4.hexToBytes)(secondPrivateKeyHex);
2415
+ const firstPrivateKey = (0, import_utils5.hexToBytes)(firstPrivateKeyHex);
2416
+ const secondPrivateKey = (0, import_utils5.hexToBytes)(secondPrivateKeyHex);
2368
2417
  const resultPrivKey = subtractPrivateKeys(
2369
2418
  firstPrivateKey,
2370
2419
  secondPrivateKey
2371
2420
  );
2372
2421
  const resultPubKey = import_secp256k15.secp256k1.getPublicKey(resultPrivKey);
2373
- const resultPrivKeyHex = (0, import_utils4.bytesToHex)(resultPrivKey);
2374
- const resultPubKeyHex = (0, import_utils4.bytesToHex)(resultPubKey);
2422
+ const resultPrivKeyHex = (0, import_utils5.bytesToHex)(resultPrivKey);
2423
+ const resultPubKeyHex = (0, import_utils5.bytesToHex)(resultPubKey);
2375
2424
  this.publicKeyToPrivateKeyMap.set(resultPubKeyHex, resultPrivKeyHex);
2376
2425
  return resultPubKey;
2377
2426
  }
@@ -2383,14 +2432,14 @@ var DefaultSparkSigner = class {
2383
2432
  isSecretPubkey = false
2384
2433
  }) {
2385
2434
  if (isSecretPubkey) {
2386
- const pubKeyHex = (0, import_utils4.bytesToHex)(secret);
2435
+ const pubKeyHex = (0, import_utils5.bytesToHex)(secret);
2387
2436
  const privateKey = this.publicKeyToPrivateKeyMap.get(pubKeyHex);
2388
2437
  if (!privateKey) {
2389
2438
  throw new Error("Private key is not set");
2390
2439
  }
2391
- secret = (0, import_utils4.hexToBytes)(privateKey);
2440
+ secret = (0, import_utils5.hexToBytes)(privateKey);
2392
2441
  }
2393
- const secretAsInt = (0, import_utils4.bytesToNumberBE)(secret);
2442
+ const secretAsInt = (0, import_utils5.bytesToNumberBE)(secret);
2394
2443
  return splitSecretWithProofs(secretAsInt, curveOrder, threshold, numShares);
2395
2444
  }
2396
2445
  async signFrost({
@@ -2408,7 +2457,7 @@ var DefaultSparkSigner = class {
2408
2457
  field: "SparkFrost"
2409
2458
  });
2410
2459
  }
2411
- const privateAsPubKeyHex = (0, import_utils4.bytesToHex)(privateAsPubKey);
2460
+ const privateAsPubKeyHex = (0, import_utils5.bytesToHex)(privateAsPubKey);
2412
2461
  const signingPrivateKey = this.publicKeyToPrivateKeyMap.get(privateAsPubKeyHex);
2413
2462
  if (!signingPrivateKey) {
2414
2463
  throw new ValidationError("Private key not found for public key", {
@@ -2422,7 +2471,7 @@ var DefaultSparkSigner = class {
2422
2471
  });
2423
2472
  }
2424
2473
  const keyPackage = {
2425
- secretKey: (0, import_utils4.hexToBytes)(signingPrivateKey),
2474
+ secretKey: (0, import_utils5.hexToBytes)(signingPrivateKey),
2426
2475
  publicKey,
2427
2476
  verifyingKey
2428
2477
  };
@@ -2466,7 +2515,7 @@ var DefaultSparkSigner = class {
2466
2515
  }
2467
2516
  async createSparkWalletFromSeed(seed, accountNumber) {
2468
2517
  if (typeof seed === "string") {
2469
- seed = (0, import_utils4.hexToBytes)(seed);
2518
+ seed = (0, import_utils5.hexToBytes)(seed);
2470
2519
  }
2471
2520
  const {
2472
2521
  masterPublicKey,
@@ -2481,28 +2530,28 @@ var DefaultSparkSigner = class {
2481
2530
  this.signingKey = signingKey.hdKey;
2482
2531
  this.staticDepositKey = staticDepositKey.hdKey;
2483
2532
  this.publicKeyToPrivateKeyMap.set(
2484
- (0, import_utils4.bytesToHex)(identityKey.publicKey),
2485
- (0, import_utils4.bytesToHex)(identityKey.privateKey)
2533
+ (0, import_utils5.bytesToHex)(identityKey.publicKey),
2534
+ (0, import_utils5.bytesToHex)(identityKey.privateKey)
2486
2535
  );
2487
2536
  this.publicKeyToPrivateKeyMap.set(
2488
- (0, import_utils4.bytesToHex)(depositKey.publicKey),
2489
- (0, import_utils4.bytesToHex)(depositKey.privateKey)
2537
+ (0, import_utils5.bytesToHex)(depositKey.publicKey),
2538
+ (0, import_utils5.bytesToHex)(depositKey.privateKey)
2490
2539
  );
2491
2540
  this.publicKeyToPrivateKeyMap.set(
2492
- (0, import_utils4.bytesToHex)(staticDepositKey.publicKey),
2493
- (0, import_utils4.bytesToHex)(staticDepositKey.privateKey)
2541
+ (0, import_utils5.bytesToHex)(staticDepositKey.publicKey),
2542
+ (0, import_utils5.bytesToHex)(staticDepositKey.privateKey)
2494
2543
  );
2495
- return (0, import_utils4.bytesToHex)(identityKey.publicKey);
2544
+ return (0, import_utils5.bytesToHex)(identityKey.publicKey);
2496
2545
  }
2497
2546
  async signMessageWithPublicKey(message, publicKey, compact) {
2498
- const privateKey = this.publicKeyToPrivateKeyMap.get((0, import_utils4.bytesToHex)(publicKey));
2547
+ const privateKey = this.publicKeyToPrivateKeyMap.get((0, import_utils5.bytesToHex)(publicKey));
2499
2548
  if (!privateKey) {
2500
2549
  throw new ValidationError("Private key not found for public key", {
2501
2550
  field: "privateKey",
2502
- value: (0, import_utils4.bytesToHex)(publicKey)
2551
+ value: (0, import_utils5.bytesToHex)(publicKey)
2503
2552
  });
2504
2553
  }
2505
- const signature = import_secp256k15.secp256k1.sign(message, (0, import_utils4.hexToBytes)(privateKey));
2554
+ const signature = import_secp256k15.secp256k1.sign(message, (0, import_utils5.hexToBytes)(privateKey));
2506
2555
  if (compact) {
2507
2556
  return signature.toCompactRawBytes();
2508
2557
  }
@@ -2521,12 +2570,12 @@ var DefaultSparkSigner = class {
2521
2570
  return signature.toDERRawBytes();
2522
2571
  }
2523
2572
  async encryptLeafPrivateKeyEcies(receiverPublicKey, publicKey) {
2524
- const publicKeyHex = (0, import_utils4.bytesToHex)(publicKey);
2573
+ const publicKeyHex = (0, import_utils5.bytesToHex)(publicKey);
2525
2574
  const privateKey = this.publicKeyToPrivateKeyMap.get(publicKeyHex);
2526
2575
  if (!privateKey) {
2527
2576
  throw new Error("Private key is not set");
2528
2577
  }
2529
- return ecies.encrypt(receiverPublicKey, (0, import_utils4.hexToBytes)(privateKey));
2578
+ return ecies.encrypt(receiverPublicKey, (0, import_utils5.hexToBytes)(privateKey));
2530
2579
  }
2531
2580
  async decryptEcies(ciphertext) {
2532
2581
  if (!this.identityKey?.privateKey) {
@@ -2535,12 +2584,12 @@ var DefaultSparkSigner = class {
2535
2584
  });
2536
2585
  }
2537
2586
  const receiverEciesPrivKey = ecies.PrivateKey.fromHex(
2538
- (0, import_utils4.bytesToHex)(this.identityKey.privateKey)
2587
+ (0, import_utils5.bytesToHex)(this.identityKey.privateKey)
2539
2588
  );
2540
2589
  const privateKey = ecies.decrypt(receiverEciesPrivKey.toHex(), ciphertext);
2541
2590
  const publicKey = import_secp256k15.secp256k1.getPublicKey(privateKey);
2542
- const publicKeyHex = (0, import_utils4.bytesToHex)(publicKey);
2543
- const privateKeyHex = (0, import_utils4.bytesToHex)(privateKey);
2591
+ const publicKeyHex = (0, import_utils5.bytesToHex)(publicKey);
2592
+ const privateKeyHex = (0, import_utils5.bytesToHex)(privateKey);
2544
2593
  this.publicKeyToPrivateKeyMap.set(publicKeyHex, privateKeyHex);
2545
2594
  return publicKey;
2546
2595
  }
@@ -2557,8 +2606,8 @@ var DefaultSparkSigner = class {
2557
2606
  const adaptor = generateAdaptorFromSignature(signature);
2558
2607
  const adaptorPublicKey = import_secp256k15.secp256k1.getPublicKey(adaptor.adaptorPrivateKey);
2559
2608
  this.publicKeyToPrivateKeyMap.set(
2560
- (0, import_utils4.bytesToHex)(adaptorPublicKey),
2561
- (0, import_utils4.bytesToHex)(adaptor.adaptorPrivateKey)
2609
+ (0, import_utils5.bytesToHex)(adaptorPublicKey),
2610
+ (0, import_utils5.bytesToHex)(adaptor.adaptorPrivateKey)
2562
2611
  );
2563
2612
  return {
2564
2613
  adaptorSignature: signature,
@@ -2609,19 +2658,19 @@ var DefaultSparkSigner = class {
2609
2658
  }
2610
2659
  signTransactionIndex(tx, index, publicKey) {
2611
2660
  let privateKey;
2612
- if ((0, import_utils4.equalBytes)(publicKey, this.identityKey?.publicKey ?? new Uint8Array())) {
2661
+ if ((0, import_utils5.equalBytes)(publicKey, this.identityKey?.publicKey ?? new Uint8Array())) {
2613
2662
  privateKey = this.identityKey?.privateKey;
2614
- } else if ((0, import_utils4.equalBytes)(publicKey, this.depositKey?.publicKey ?? new Uint8Array())) {
2663
+ } else if ((0, import_utils5.equalBytes)(publicKey, this.depositKey?.publicKey ?? new Uint8Array())) {
2615
2664
  privateKey = this.depositKey?.privateKey;
2616
2665
  } else {
2617
- privateKey = (0, import_utils4.hexToBytes)(
2618
- this.publicKeyToPrivateKeyMap.get((0, import_utils4.bytesToHex)(publicKey)) ?? ""
2666
+ privateKey = (0, import_utils5.hexToBytes)(
2667
+ this.publicKeyToPrivateKeyMap.get((0, import_utils5.bytesToHex)(publicKey)) ?? ""
2619
2668
  );
2620
2669
  }
2621
2670
  if (!privateKey) {
2622
2671
  throw new ValidationError("Private key not found for public key", {
2623
2672
  field: "privateKey",
2624
- value: (0, import_utils4.bytesToHex)(publicKey)
2673
+ value: (0, import_utils5.bytesToHex)(publicKey)
2625
2674
  });
2626
2675
  }
2627
2676
  tx.signIdx(privateKey, index);
@@ -2639,7 +2688,7 @@ var ReactNativeSparkSigner = class extends DefaultSparkSigner {
2639
2688
  statechainCommitments,
2640
2689
  adaptorPubKey
2641
2690
  }) {
2642
- const privateAsPubKeyHex = (0, import_utils6.bytesToHex)(privateAsPubKey);
2691
+ const privateAsPubKeyHex = (0, import_utils7.bytesToHex)(privateAsPubKey);
2643
2692
  const signingPrivateKey = this.publicKeyToPrivateKeyMap.get(privateAsPubKeyHex);
2644
2693
  if (!signingPrivateKey) {
2645
2694
  throw new ValidationError("Private key not found for public key", {
@@ -2653,7 +2702,7 @@ var ReactNativeSparkSigner = class extends DefaultSparkSigner {
2653
2702
  });
2654
2703
  }
2655
2704
  const keyPackage = {
2656
- secretKey: (0, import_utils6.hexToBytes)(signingPrivateKey),
2705
+ secretKey: (0, import_utils7.hexToBytes)(signingPrivateKey),
2657
2706
  publicKey,
2658
2707
  verifyingKey
2659
2708
  };
@@ -2693,8 +2742,8 @@ var ReactNativeSparkSigner = class extends DefaultSparkSigner {
2693
2742
 
2694
2743
  // src/spark-wallet/spark-wallet.ts
2695
2744
  init_buffer();
2696
- var import_core12 = require("@lightsparkdev/core");
2697
- var import_utils23 = require("@noble/curves/abstract/utils");
2745
+ var import_core14 = require("@lightsparkdev/core");
2746
+ var import_utils24 = require("@noble/curves/abstract/utils");
2698
2747
  var import_secp256k116 = require("@noble/curves/secp256k1");
2699
2748
  var import_bip392 = require("@scure/bip39");
2700
2749
  var import_english2 = require("@scure/bip39/wordlists/english");
@@ -2704,7 +2753,7 @@ var import_uuidv75 = require("uuidv7");
2704
2753
 
2705
2754
  // src/graphql/client.ts
2706
2755
  init_buffer();
2707
- var import_core6 = require("@lightsparkdev/core");
2756
+ var import_core7 = require("@lightsparkdev/core");
2708
2757
  var import_sha22 = require("@noble/hashes/sha2");
2709
2758
 
2710
2759
  // src/graphql/mutations/ClaimStaticDeposit.ts
@@ -2758,7 +2807,7 @@ init_buffer();
2758
2807
 
2759
2808
  // src/graphql/objects/CoopExitRequest.ts
2760
2809
  init_buffer();
2761
- var import_core = require("@lightsparkdev/core");
2810
+ var import_core2 = require("@lightsparkdev/core");
2762
2811
 
2763
2812
  // src/graphql/objects/BitcoinNetwork.ts
2764
2813
  init_buffer();
@@ -2813,11 +2862,23 @@ var CurrencyAmountToJson = (obj) => {
2813
2862
  };
2814
2863
  };
2815
2864
 
2865
+ // src/graphql/objects/ExitSpeed.ts
2866
+ init_buffer();
2867
+ var ExitSpeed = /* @__PURE__ */ ((ExitSpeed2) => {
2868
+ ExitSpeed2["FUTURE_VALUE"] = "FUTURE_VALUE";
2869
+ ExitSpeed2["FAST"] = "FAST";
2870
+ ExitSpeed2["MEDIUM"] = "MEDIUM";
2871
+ ExitSpeed2["SLOW"] = "SLOW";
2872
+ return ExitSpeed2;
2873
+ })(ExitSpeed || {});
2874
+ var ExitSpeed_default = ExitSpeed;
2875
+
2816
2876
  // src/graphql/objects/SparkCoopExitRequestStatus.ts
2817
2877
  init_buffer();
2818
2878
  var SparkCoopExitRequestStatus = /* @__PURE__ */ ((SparkCoopExitRequestStatus2) => {
2819
2879
  SparkCoopExitRequestStatus2["FUTURE_VALUE"] = "FUTURE_VALUE";
2820
2880
  SparkCoopExitRequestStatus2["INITIATED"] = "INITIATED";
2881
+ SparkCoopExitRequestStatus2["INBOUND_TRANSFER_CHECKED"] = "INBOUND_TRANSFER_CHECKED";
2821
2882
  SparkCoopExitRequestStatus2["TX_SIGNED"] = "TX_SIGNED";
2822
2883
  SparkCoopExitRequestStatus2["TX_BROADCASTED"] = "TX_BROADCASTED";
2823
2884
  SparkCoopExitRequestStatus2["WAITING_ON_TX_CONFIRMATIONS"] = "WAITING_ON_TX_CONFIRMATIONS";
@@ -3002,6 +3063,8 @@ var CoopExitRequestFromJson = (obj) => {
3002
3063
  rawCoopExitTransaction: obj["coop_exit_request_raw_coop_exit_transaction"],
3003
3064
  coopExitTxid: obj["coop_exit_request_coop_exit_txid"],
3004
3065
  typename: "CoopExitRequest",
3066
+ feeQuoteId: obj["coop_exit_request_fee_quote"]?.id ?? void 0,
3067
+ exitSpeed: !!obj["coop_exit_request_exit_speed"] ? ExitSpeed_default[obj["coop_exit_request_exit_speed"]] ?? ExitSpeed_default.FUTURE_VALUE : null,
3005
3068
  transfer: !!obj["coop_exit_request_transfer"] ? TransferFromJson(obj["coop_exit_request_transfer"]) : void 0
3006
3069
  };
3007
3070
  };
@@ -3028,6 +3091,10 @@ fragment CoopExitRequestFragment on CoopExitRequest {
3028
3091
  currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
3029
3092
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3030
3093
  }
3094
+ coop_exit_request_fee_quote: fee_quote {
3095
+ id
3096
+ }
3097
+ coop_exit_request_exit_speed: exit_speed
3031
3098
  coop_exit_request_status: status
3032
3099
  coop_exit_request_expires_at: expires_at
3033
3100
  coop_exit_request_raw_connector_transaction: raw_connector_transaction
@@ -3044,6 +3111,9 @@ fragment CoopExitRequestFragment on CoopExitRequest {
3044
3111
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3045
3112
  }
3046
3113
  transfer_spark_id: spark_id
3114
+ transfer_user_request: user_request {
3115
+ id
3116
+ }
3047
3117
  }
3048
3118
  }`;
3049
3119
 
@@ -3071,7 +3141,7 @@ init_buffer();
3071
3141
 
3072
3142
  // src/graphql/objects/LeavesSwapRequest.ts
3073
3143
  init_buffer();
3074
- var import_core2 = require("@lightsparkdev/core");
3144
+ var import_core3 = require("@lightsparkdev/core");
3075
3145
 
3076
3146
  // src/graphql/objects/SparkLeavesSwapRequestStatus.ts
3077
3147
  init_buffer();
@@ -3168,6 +3238,9 @@ fragment LeavesSwapRequestFragment on LeavesSwapRequest {
3168
3238
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3169
3239
  }
3170
3240
  transfer_spark_id: spark_id
3241
+ transfer_user_request: user_request {
3242
+ id
3243
+ }
3171
3244
  }
3172
3245
  leaves_swap_request_outbound_transfer: outbound_transfer {
3173
3246
  __typename
@@ -3180,6 +3253,9 @@ fragment LeavesSwapRequestFragment on LeavesSwapRequest {
3180
3253
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3181
3254
  }
3182
3255
  transfer_spark_id: spark_id
3256
+ transfer_user_request: user_request {
3257
+ id
3258
+ }
3183
3259
  }
3184
3260
  leaves_swap_request_expires_at: expires_at
3185
3261
  leaves_swap_request_swap_leaves: swap_leaves {
@@ -3268,7 +3344,7 @@ init_buffer();
3268
3344
 
3269
3345
  // src/graphql/objects/LightningReceiveRequest.ts
3270
3346
  init_buffer();
3271
- var import_core3 = require("@lightsparkdev/core");
3347
+ var import_core4 = require("@lightsparkdev/core");
3272
3348
 
3273
3349
  // src/graphql/objects/Invoice.ts
3274
3350
  init_buffer();
@@ -3313,7 +3389,8 @@ var LightningReceiveRequestFromJson = (obj) => {
3313
3389
  status: LightningReceiveRequestStatus_default[obj["lightning_receive_request_status"]] ?? LightningReceiveRequestStatus_default.FUTURE_VALUE,
3314
3390
  typename: "LightningReceiveRequest",
3315
3391
  transfer: !!obj["lightning_receive_request_transfer"] ? TransferFromJson(obj["lightning_receive_request_transfer"]) : void 0,
3316
- paymentPreimage: obj["lightning_receive_request_payment_preimage"]
3392
+ paymentPreimage: obj["lightning_receive_request_payment_preimage"],
3393
+ receiverIdentityPublicKey: obj["lightning_receive_request_receiver_identity_public_key"]
3317
3394
  };
3318
3395
  };
3319
3396
  var FRAGMENT6 = `
@@ -3352,8 +3429,12 @@ fragment LightningReceiveRequestFragment on LightningReceiveRequest {
3352
3429
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3353
3430
  }
3354
3431
  transfer_spark_id: spark_id
3432
+ transfer_user_request: user_request {
3433
+ id
3434
+ }
3355
3435
  }
3356
3436
  lightning_receive_request_payment_preimage: payment_preimage
3437
+ lightning_receive_request_receiver_identity_public_key: receiver_identity_public_key
3357
3438
  }`;
3358
3439
 
3359
3440
  // src/graphql/mutations/RequestLightningReceive.ts
@@ -3393,7 +3474,7 @@ init_buffer();
3393
3474
 
3394
3475
  // src/graphql/objects/LightningSendRequest.ts
3395
3476
  init_buffer();
3396
- var import_core4 = require("@lightsparkdev/core");
3477
+ var import_core5 = require("@lightsparkdev/core");
3397
3478
 
3398
3479
  // src/graphql/objects/LightningSendRequestStatus.ts
3399
3480
  init_buffer();
@@ -3455,6 +3536,9 @@ fragment LightningSendRequestFragment on LightningSendRequest {
3455
3536
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3456
3537
  }
3457
3538
  transfer_spark_id: spark_id
3539
+ transfer_user_request: user_request {
3540
+ id
3541
+ }
3458
3542
  }
3459
3543
  lightning_send_request_payment_preimage: payment_preimage
3460
3544
  }`;
@@ -3464,10 +3548,12 @@ var RequestLightningSend = `
3464
3548
  mutation RequestLightningSend(
3465
3549
  $encoded_invoice: String!
3466
3550
  $idempotency_key: String!
3551
+ $amount_sats: Long
3467
3552
  ) {
3468
3553
  request_lightning_send(input: {
3469
3554
  encoded_invoice: $encoded_invoice
3470
3555
  idempotency_key: $idempotency_key
3556
+ amount_sats: $amount_sats
3471
3557
  }) {
3472
3558
  request {
3473
3559
  ...LightningSendRequestFragment
@@ -3758,10 +3844,12 @@ init_buffer();
3758
3844
  var LightningSendFeeEstimate = `
3759
3845
  query LightningSendFeeEstimate(
3760
3846
  $encoded_invoice: String!
3847
+ $amount_sats: Long
3761
3848
  ) {
3762
3849
  lightning_send_fee_estimate(
3763
3850
  input: {
3764
3851
  encoded_invoice: $encoded_invoice
3852
+ amount_sats: $amount_sats
3765
3853
  }
3766
3854
  ) {
3767
3855
  ...LightningSendFeeEstimateOutputFragment
@@ -3786,7 +3874,7 @@ init_buffer();
3786
3874
 
3787
3875
  // src/graphql/objects/UserRequest.ts
3788
3876
  init_buffer();
3789
- var import_core5 = require("@lightsparkdev/core");
3877
+ var import_core6 = require("@lightsparkdev/core");
3790
3878
 
3791
3879
  // src/graphql/objects/ClaimStaticDepositStatus.ts
3792
3880
  init_buffer();
@@ -3845,6 +3933,10 @@ fragment UserRequestFragment on UserRequest {
3845
3933
  currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
3846
3934
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3847
3935
  }
3936
+ coop_exit_request_fee_quote: fee_quote {
3937
+ id
3938
+ }
3939
+ coop_exit_request_exit_speed: exit_speed
3848
3940
  coop_exit_request_status: status
3849
3941
  coop_exit_request_expires_at: expires_at
3850
3942
  coop_exit_request_raw_connector_transaction: raw_connector_transaction
@@ -3861,6 +3953,9 @@ fragment UserRequestFragment on UserRequest {
3861
3953
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3862
3954
  }
3863
3955
  transfer_spark_id: spark_id
3956
+ transfer_user_request: user_request {
3957
+ id
3958
+ }
3864
3959
  }
3865
3960
  }
3866
3961
  ... on LeavesSwapRequest {
@@ -3905,6 +4000,9 @@ fragment UserRequestFragment on UserRequest {
3905
4000
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3906
4001
  }
3907
4002
  transfer_spark_id: spark_id
4003
+ transfer_user_request: user_request {
4004
+ id
4005
+ }
3908
4006
  }
3909
4007
  leaves_swap_request_outbound_transfer: outbound_transfer {
3910
4008
  __typename
@@ -3917,6 +4015,9 @@ fragment UserRequestFragment on UserRequest {
3917
4015
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3918
4016
  }
3919
4017
  transfer_spark_id: spark_id
4018
+ transfer_user_request: user_request {
4019
+ id
4020
+ }
3920
4021
  }
3921
4022
  leaves_swap_request_expires_at: expires_at
3922
4023
  leaves_swap_request_swap_leaves: swap_leaves {
@@ -3961,8 +4062,12 @@ fragment UserRequestFragment on UserRequest {
3961
4062
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3962
4063
  }
3963
4064
  transfer_spark_id: spark_id
4065
+ transfer_user_request: user_request {
4066
+ id
4067
+ }
3964
4068
  }
3965
4069
  lightning_receive_request_payment_preimage: payment_preimage
4070
+ lightning_receive_request_receiver_identity_public_key: receiver_identity_public_key
3966
4071
  }
3967
4072
  ... on LightningSendRequest {
3968
4073
  __typename
@@ -3992,6 +4097,9 @@ fragment UserRequestFragment on UserRequest {
3992
4097
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
3993
4098
  }
3994
4099
  transfer_spark_id: spark_id
4100
+ transfer_user_request: user_request {
4101
+ id
4102
+ }
3995
4103
  }
3996
4104
  lightning_send_request_payment_preimage: payment_preimage
3997
4105
  }
@@ -4017,13 +4125,13 @@ var SspClient = class {
4017
4125
  this.authProvider = new SparkAuthProvider();
4018
4126
  const fetchFunction = typeof window !== "undefined" ? window.fetch.bind(window) : fetch;
4019
4127
  const options = config.sspClientOptions;
4020
- this.requester = new import_core6.Requester(
4021
- new import_core6.NodeKeyCache(import_core6.DefaultCrypto),
4128
+ this.requester = new import_core7.Requester(
4129
+ new import_core7.NodeKeyCache(import_core7.DefaultCrypto),
4022
4130
  options.schemaEndpoint || `graphql/spark/2025-03-19`,
4023
4131
  `spark-sdk/0.0.0`,
4024
4132
  this.authProvider,
4025
4133
  options.baseUrl,
4026
- import_core6.DefaultCrypto,
4134
+ import_core7.DefaultCrypto,
4027
4135
  void 0,
4028
4136
  fetchFunction
4029
4137
  );
@@ -4072,11 +4180,12 @@ var SspClient = class {
4072
4180
  }
4073
4181
  });
4074
4182
  }
4075
- async getLightningSendFeeEstimate(encodedInvoice) {
4183
+ async getLightningSendFeeEstimate(encodedInvoice, amountSats) {
4076
4184
  return await this.executeRawQuery({
4077
4185
  queryPayload: LightningSendFeeEstimate,
4078
4186
  variables: {
4079
- encoded_invoice: encodedInvoice
4187
+ encoded_invoice: encodedInvoice,
4188
+ amount_sats: amountSats
4080
4189
  },
4081
4190
  constructObject: (response) => {
4082
4191
  return LightningSendFeeEstimateOutputFromJson(
@@ -4172,13 +4281,15 @@ var SspClient = class {
4172
4281
  }
4173
4282
  async requestLightningSend({
4174
4283
  encodedInvoice,
4175
- idempotencyKey
4284
+ idempotencyKey,
4285
+ amountSats
4176
4286
  }) {
4177
4287
  return await this.executeRawQuery({
4178
4288
  queryPayload: RequestLightningSend,
4179
4289
  variables: {
4180
4290
  encoded_invoice: encodedInvoice,
4181
- idempotency_key: idempotencyKey
4291
+ idempotency_key: idempotencyKey,
4292
+ amount_sats: amountSats
4182
4293
  },
4183
4294
  constructObject: (response) => {
4184
4295
  return LightningSendRequestFromJson(
@@ -4346,7 +4457,7 @@ var SspClient = class {
4346
4457
  {
4347
4458
  queryPayload: GetChallenge,
4348
4459
  variables: {
4349
- public_key: (0, import_core6.bytesToHex)(await this.signer.getIdentityPublicKey())
4460
+ public_key: (0, import_core7.bytesToHex)(await this.signer.getIdentityPublicKey())
4350
4461
  },
4351
4462
  constructObject: (response) => {
4352
4463
  return GetChallengeOutputFromJson(response.get_challenge);
@@ -4362,7 +4473,7 @@ var SspClient = class {
4362
4473
  variables: {
4363
4474
  protected_challenge: protectedChallenge,
4364
4475
  signature,
4365
- identity_public_key: (0, import_core6.bytesToHex)(
4476
+ identity_public_key: (0, import_core7.bytesToHex)(
4366
4477
  await this.signer.getIdentityPublicKey()
4367
4478
  )
4368
4479
  },
@@ -4436,18 +4547,11 @@ init_buffer();
4436
4547
 
4437
4548
  // src/graphql/objects/ClaimStaticDeposit.ts
4438
4549
  init_buffer();
4439
- var import_core7 = require("@lightsparkdev/core");
4550
+ var import_core8 = require("@lightsparkdev/core");
4440
4551
 
4441
- // src/graphql/objects/ExitSpeed.ts
4552
+ // src/graphql/objects/CoopExitFeeQuote.ts
4442
4553
  init_buffer();
4443
- var ExitSpeed = /* @__PURE__ */ ((ExitSpeed2) => {
4444
- ExitSpeed2["FUTURE_VALUE"] = "FUTURE_VALUE";
4445
- ExitSpeed2["FAST"] = "FAST";
4446
- ExitSpeed2["MEDIUM"] = "MEDIUM";
4447
- ExitSpeed2["SLOW"] = "SLOW";
4448
- return ExitSpeed2;
4449
- })(ExitSpeed || {});
4450
- var ExitSpeed_default = ExitSpeed;
4554
+ var import_core9 = require("@lightsparkdev/core");
4451
4555
 
4452
4556
  // src/graphql/objects/SparkUserRequestStatus.ts
4453
4557
  init_buffer();
@@ -4457,7 +4561,7 @@ init_buffer();
4457
4561
 
4458
4562
  // src/graphql/objects/SparkWalletUser.ts
4459
4563
  init_buffer();
4460
- var import_core8 = require("@lightsparkdev/core");
4564
+ var import_core10 = require("@lightsparkdev/core");
4461
4565
 
4462
4566
  // src/graphql/objects/SparkWalletUserToUserRequestsConnection.ts
4463
4567
  init_buffer();
@@ -5362,7 +5466,7 @@ var DepositAddressProof = {
5362
5466
  },
5363
5467
  fromJSON(object) {
5364
5468
  return {
5365
- addressSignatures: isObject8(object.addressSignatures) ? Object.entries(object.addressSignatures).reduce((acc, [key, value]) => {
5469
+ addressSignatures: isObject9(object.addressSignatures) ? Object.entries(object.addressSignatures).reduce((acc, [key, value]) => {
5366
5470
  acc[key] = bytesFromBase642(value);
5367
5471
  return acc;
5368
5472
  }, {}) : {},
@@ -6144,18 +6248,18 @@ var SigningResult = {
6144
6248
  },
6145
6249
  fromJSON(object) {
6146
6250
  return {
6147
- publicKeys: isObject8(object.publicKeys) ? Object.entries(object.publicKeys).reduce((acc, [key, value]) => {
6251
+ publicKeys: isObject9(object.publicKeys) ? Object.entries(object.publicKeys).reduce((acc, [key, value]) => {
6148
6252
  acc[key] = bytesFromBase642(value);
6149
6253
  return acc;
6150
6254
  }, {}) : {},
6151
- signingNonceCommitments: isObject8(object.signingNonceCommitments) ? Object.entries(object.signingNonceCommitments).reduce(
6255
+ signingNonceCommitments: isObject9(object.signingNonceCommitments) ? Object.entries(object.signingNonceCommitments).reduce(
6152
6256
  (acc, [key, value]) => {
6153
6257
  acc[key] = SigningCommitment2.fromJSON(value);
6154
6258
  return acc;
6155
6259
  },
6156
6260
  {}
6157
6261
  ) : {},
6158
- signatureShares: isObject8(object.signatureShares) ? Object.entries(object.signatureShares).reduce((acc, [key, value]) => {
6262
+ signatureShares: isObject9(object.signatureShares) ? Object.entries(object.signatureShares).reduce((acc, [key, value]) => {
6159
6263
  acc[key] = bytesFromBase642(value);
6160
6264
  return acc;
6161
6265
  }, {}) : {},
@@ -10183,7 +10287,7 @@ var TransferPackage = {
10183
10287
  fromJSON(object) {
10184
10288
  return {
10185
10289
  leavesToSend: globalThis.Array.isArray(object?.leavesToSend) ? object.leavesToSend.map((e) => UserSignedTxSigningJob.fromJSON(e)) : [],
10186
- keyTweakPackage: isObject8(object.keyTweakPackage) ? Object.entries(object.keyTweakPackage).reduce((acc, [key, value]) => {
10290
+ keyTweakPackage: isObject9(object.keyTweakPackage) ? Object.entries(object.keyTweakPackage).reduce((acc, [key, value]) => {
10187
10291
  acc[key] = bytesFromBase642(value);
10188
10292
  return acc;
10189
10293
  }, {}) : {},
@@ -10445,7 +10549,7 @@ var SendLeafKeyTweak = {
10445
10549
  return {
10446
10550
  leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : "",
10447
10551
  secretShareTweak: isSet3(object.secretShareTweak) ? SecretShare.fromJSON(object.secretShareTweak) : void 0,
10448
- pubkeySharesTweak: isObject8(object.pubkeySharesTweak) ? Object.entries(object.pubkeySharesTweak).reduce((acc, [key, value]) => {
10552
+ pubkeySharesTweak: isObject9(object.pubkeySharesTweak) ? Object.entries(object.pubkeySharesTweak).reduce((acc, [key, value]) => {
10449
10553
  acc[key] = bytesFromBase642(value);
10450
10554
  return acc;
10451
10555
  }, {}) : {},
@@ -11418,7 +11522,7 @@ var ClaimLeafKeyTweak = {
11418
11522
  return {
11419
11523
  leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : "",
11420
11524
  secretShareTweak: isSet3(object.secretShareTweak) ? SecretShare.fromJSON(object.secretShareTweak) : void 0,
11421
- pubkeySharesTweak: isObject8(object.pubkeySharesTweak) ? Object.entries(object.pubkeySharesTweak).reduce((acc, [key, value]) => {
11525
+ pubkeySharesTweak: isObject9(object.pubkeySharesTweak) ? Object.entries(object.pubkeySharesTweak).reduce((acc, [key, value]) => {
11422
11526
  acc[key] = bytesFromBase642(value);
11423
11527
  return acc;
11424
11528
  }, {}) : {}
@@ -12094,7 +12198,7 @@ var RequestedSigningCommitments = {
12094
12198
  },
12095
12199
  fromJSON(object) {
12096
12200
  return {
12097
- signingNonceCommitments: isObject8(object.signingNonceCommitments) ? Object.entries(object.signingNonceCommitments).reduce(
12201
+ signingNonceCommitments: isObject9(object.signingNonceCommitments) ? Object.entries(object.signingNonceCommitments).reduce(
12098
12202
  (acc, [key, value]) => {
12099
12203
  acc[key] = SigningCommitment2.fromJSON(value);
12100
12204
  return acc;
@@ -12341,7 +12445,7 @@ var SigningCommitments = {
12341
12445
  },
12342
12446
  fromJSON(object) {
12343
12447
  return {
12344
- signingCommitments: isObject8(object.signingCommitments) ? Object.entries(object.signingCommitments).reduce(
12448
+ signingCommitments: isObject9(object.signingCommitments) ? Object.entries(object.signingCommitments).reduce(
12345
12449
  (acc, [key, value]) => {
12346
12450
  acc[key] = SigningCommitment2.fromJSON(value);
12347
12451
  return acc;
@@ -14442,7 +14546,7 @@ var GetSigningOperatorListResponse = {
14442
14546
  },
14443
14547
  fromJSON(object) {
14444
14548
  return {
14445
- signingOperators: isObject8(object.signingOperators) ? Object.entries(object.signingOperators).reduce(
14549
+ signingOperators: isObject9(object.signingOperators) ? Object.entries(object.signingOperators).reduce(
14446
14550
  (acc, [key, value]) => {
14447
14551
  acc[key] = SigningOperatorInfo.fromJSON(value);
14448
14552
  return acc;
@@ -15109,7 +15213,7 @@ var QueryNodesResponse = {
15109
15213
  },
15110
15214
  fromJSON(object) {
15111
15215
  return {
15112
- nodes: isObject8(object.nodes) ? Object.entries(object.nodes).reduce((acc, [key, value]) => {
15216
+ nodes: isObject9(object.nodes) ? Object.entries(object.nodes).reduce((acc, [key, value]) => {
15113
15217
  acc[key] = TreeNode.fromJSON(value);
15114
15218
  return acc;
15115
15219
  }, {}) : {},
@@ -15825,7 +15929,7 @@ var QueryBalanceResponse = {
15825
15929
  fromJSON(object) {
15826
15930
  return {
15827
15931
  balance: isSet3(object.balance) ? globalThis.Number(object.balance) : 0,
15828
- nodeBalances: isObject8(object.nodeBalances) ? Object.entries(object.nodeBalances).reduce((acc, [key, value]) => {
15932
+ nodeBalances: isObject9(object.nodeBalances) ? Object.entries(object.nodeBalances).reduce((acc, [key, value]) => {
15829
15933
  acc[key] = Number(value);
15830
15934
  return acc;
15831
15935
  }, {}) : {}
@@ -16835,7 +16939,7 @@ var QueryNodesDistributionResponse = {
16835
16939
  },
16836
16940
  fromJSON(object) {
16837
16941
  return {
16838
- nodeDistribution: isObject8(object.nodeDistribution) ? Object.entries(object.nodeDistribution).reduce((acc, [key, value]) => {
16942
+ nodeDistribution: isObject9(object.nodeDistribution) ? Object.entries(object.nodeDistribution).reduce((acc, [key, value]) => {
16839
16943
  acc[globalThis.Number(key)] = Number(value);
16840
16944
  return acc;
16841
16945
  }, {}) : {}
@@ -17084,7 +17188,7 @@ var QueryNodesByValueResponse = {
17084
17188
  },
17085
17189
  fromJSON(object) {
17086
17190
  return {
17087
- nodes: isObject8(object.nodes) ? Object.entries(object.nodes).reduce((acc, [key, value]) => {
17191
+ nodes: isObject9(object.nodes) ? Object.entries(object.nodes).reduce((acc, [key, value]) => {
17088
17192
  acc[key] = TreeNode.fromJSON(value);
17089
17193
  return acc;
17090
17194
  }, {}) : {},
@@ -17612,7 +17716,7 @@ function longToNumber2(int64) {
17612
17716
  }
17613
17717
  return num;
17614
17718
  }
17615
- function isObject8(value) {
17719
+ function isObject9(value) {
17616
17720
  return typeof value === "object" && value !== null;
17617
17721
  }
17618
17722
  function isSet3(value) {
@@ -17624,7 +17728,7 @@ init_buffer();
17624
17728
 
17625
17729
  // src/utils/network.ts
17626
17730
  init_buffer();
17627
- var import_lrc20_sdk2 = require("@buildonspark/lrc20-sdk");
17731
+ var import_lrc20_sdk3 = require("@buildonspark/lrc20-sdk");
17628
17732
  var btc = __toESM(require("@scure/btc-signer"), 1);
17629
17733
  var bitcoin = __toESM(require("bitcoinjs-lib"), 1);
17630
17734
  var Network2 = /* @__PURE__ */ ((Network6) => {
@@ -17658,11 +17762,11 @@ var LRC_WALLET_NETWORK = Object.freeze({
17658
17762
  [4 /* LOCAL */]: bitcoin.networks.regtest
17659
17763
  });
17660
17764
  var LRC_WALLET_NETWORK_TYPE = Object.freeze({
17661
- [0 /* MAINNET */]: import_lrc20_sdk2.NetworkType.MAINNET,
17662
- [1 /* TESTNET */]: import_lrc20_sdk2.NetworkType.TESTNET,
17663
- [2 /* SIGNET */]: import_lrc20_sdk2.NetworkType.TESTNET,
17664
- [3 /* REGTEST */]: import_lrc20_sdk2.NetworkType.REGTEST,
17665
- [4 /* LOCAL */]: import_lrc20_sdk2.NetworkType.LOCAL
17765
+ [0 /* MAINNET */]: import_lrc20_sdk3.NetworkType.MAINNET,
17766
+ [1 /* TESTNET */]: import_lrc20_sdk3.NetworkType.TESTNET,
17767
+ [2 /* SIGNET */]: import_lrc20_sdk3.NetworkType.TESTNET,
17768
+ [3 /* REGTEST */]: import_lrc20_sdk3.NetworkType.REGTEST,
17769
+ [4 /* LOCAL */]: import_lrc20_sdk3.NetworkType.LOCAL
17666
17770
  });
17667
17771
  function getNetworkFromAddress(address2) {
17668
17772
  try {
@@ -17699,10 +17803,10 @@ init_buffer();
17699
17803
 
17700
17804
  // src/tests/isHermeticTest.ts
17701
17805
  init_buffer();
17702
- var import_core9 = require("@lightsparkdev/core");
17806
+ var import_core11 = require("@lightsparkdev/core");
17703
17807
  var import_fs = __toESM(require("fs"), 1);
17704
17808
  function isHermeticTest() {
17705
- if (import_core9.isNode) {
17809
+ if (import_core11.isNode) {
17706
17810
  return (import_fs.default?.existsSync?.("/tmp/spark_hermetic") ?? false) || process.env.HERMETIC_TEST === "true";
17707
17811
  }
17708
17812
  return typeof process !== "undefined" && process.env?.HERMETIC_TEST === "true" || false;
@@ -17830,6 +17934,7 @@ var BASE_CONFIG = {
17830
17934
  signingOperators: getLocalSigningOperators(),
17831
17935
  tokenSignatures: "SCHNORR",
17832
17936
  tokenTransactionVersion: "V0",
17937
+ tokenValidityDurationSeconds: 180,
17833
17938
  electrsUrl: getElectrsUrl("LOCAL"),
17834
17939
  expectedWithdrawBondSats: 1e4,
17835
17940
  expectedWithdrawRelativeBlockLocktime: 1e3,
@@ -18040,6 +18145,9 @@ var WalletConfigService = class {
18040
18145
  getTokenTransactionVersion() {
18041
18146
  return this.config.tokenTransactionVersion;
18042
18147
  }
18148
+ getTokenValidityDurationSeconds() {
18149
+ return this.config.tokenValidityDurationSeconds;
18150
+ }
18043
18151
  getElectrsUrl() {
18044
18152
  return this.config.electrsUrl;
18045
18153
  }
@@ -18050,7 +18158,7 @@ var WalletConfigService = class {
18050
18158
 
18051
18159
  // src/services/connection.ts
18052
18160
  init_buffer();
18053
- var import_core10 = require("@lightsparkdev/core");
18161
+ var import_core12 = require("@lightsparkdev/core");
18054
18162
  var import_sha23 = require("@noble/hashes/sha2");
18055
18163
  var import_nice_grpc_client_middleware_retry = require("nice-grpc-client-middleware-retry");
18056
18164
  var import_nice_grpc_common2 = require("nice-grpc-common");
@@ -19899,7 +20007,7 @@ var ConnectionManager = class {
19899
20007
  async createMockClient(address2) {
19900
20008
  const channel = await this.createChannelWithTLS(address2);
19901
20009
  const isNodeChannel = "close" in channel;
19902
- if (import_core10.isNode && isNodeChannel && !isBun) {
20010
+ if (import_core12.isNode && isNodeChannel && !isBun) {
19903
20011
  const grpcModule = await import("nice-grpc");
19904
20012
  const { createClient } = "default" in grpcModule ? grpcModule.default : grpcModule;
19905
20013
  const client = createClient(MockServiceDefinition, channel);
@@ -19916,7 +20024,7 @@ var ConnectionManager = class {
19916
20024
  }
19917
20025
  async createChannelWithTLS(address2, certPath) {
19918
20026
  try {
19919
- if (import_core10.isNode && !isBun) {
20027
+ if (import_core12.isNode && !isBun) {
19920
20028
  const grpcModule = await import("nice-grpc");
19921
20029
  const { ChannelCredentials, createChannel } = "default" in grpcModule ? grpcModule.default : grpcModule;
19922
20030
  if (certPath) {
@@ -20057,14 +20165,38 @@ var ConnectionManager = class {
20057
20165
  }
20058
20166
  async createSparkAuthnGrpcConnection(address2, certPath) {
20059
20167
  const channel = await this.createChannelWithTLS(address2, certPath);
20168
+ const authnMiddleware = this.createAuthnMiddleware();
20060
20169
  return this.createGrpcClient(
20061
20170
  SparkAuthnServiceDefinition,
20062
20171
  channel,
20063
- false
20172
+ false,
20173
+ authnMiddleware
20064
20174
  );
20065
20175
  }
20176
+ createAuthnMiddleware() {
20177
+ if (import_core12.isNode) {
20178
+ return async function* (call, options) {
20179
+ const metadata = (0, import_nice_grpc_common2.Metadata)(options.metadata).set(
20180
+ "X-Client-Env",
20181
+ clientEnv
20182
+ );
20183
+ return yield* call.next(call.request, {
20184
+ ...options,
20185
+ metadata
20186
+ });
20187
+ }.bind(this);
20188
+ } else {
20189
+ return async function* (call, options) {
20190
+ const metadata = (0, import_nice_grpc_common2.Metadata)(options.metadata).set("X-Requested-With", "XMLHttpRequest").set("X-Grpc-Web", "1").set("X-Client-Env", clientEnv).set("Content-Type", "application/grpc-web+proto");
20191
+ return yield* call.next(call.request, {
20192
+ ...options,
20193
+ metadata
20194
+ });
20195
+ }.bind(this);
20196
+ }
20197
+ }
20066
20198
  createMiddleware(address2, authToken) {
20067
- if (import_core10.isNode) {
20199
+ if (import_core12.isNode) {
20068
20200
  return this.createNodeMiddleware(address2, authToken);
20069
20201
  } else {
20070
20202
  return this.createBrowserMiddleware(address2, authToken);
@@ -20072,21 +20204,29 @@ var ConnectionManager = class {
20072
20204
  }
20073
20205
  createNodeMiddleware(address2, initialAuthToken) {
20074
20206
  return async function* (call, options) {
20207
+ const metadata = (0, import_nice_grpc_common2.Metadata)(options.metadata).set(
20208
+ "X-Client-Env",
20209
+ clientEnv
20210
+ );
20075
20211
  try {
20076
20212
  return yield* call.next(call.request, {
20077
20213
  ...options,
20078
- metadata: (0, import_nice_grpc_common2.Metadata)(options.metadata).set(
20214
+ metadata: metadata.set(
20079
20215
  "Authorization",
20080
20216
  `Bearer ${this.clients.get(address2)?.authToken || initialAuthToken}`
20081
- ).set("User-Agent", "spark-js-sdk")
20217
+ )
20082
20218
  });
20083
20219
  } catch (error) {
20084
20220
  if (error.message?.includes("token has expired")) {
20085
20221
  const newAuthToken = await this.authenticate(address2);
20086
- this.clients.get(address2).authToken = newAuthToken;
20222
+ const clientData = this.clients.get(address2);
20223
+ if (!clientData) {
20224
+ throw new Error(`No client found for address: ${address2}`);
20225
+ }
20226
+ clientData.authToken = newAuthToken;
20087
20227
  return yield* call.next(call.request, {
20088
20228
  ...options,
20089
- metadata: (0, import_nice_grpc_common2.Metadata)(options.metadata).set("Authorization", `Bearer ${newAuthToken}`).set("User-Agent", "spark-js-sdk")
20229
+ metadata: metadata.set("Authorization", `Bearer ${newAuthToken}`)
20090
20230
  });
20091
20231
  }
20092
20232
  throw error;
@@ -20095,21 +20235,26 @@ var ConnectionManager = class {
20095
20235
  }
20096
20236
  createBrowserMiddleware(address2, initialAuthToken) {
20097
20237
  return async function* (call, options) {
20238
+ const metadata = (0, import_nice_grpc_common2.Metadata)(options.metadata).set("X-Requested-With", "XMLHttpRequest").set("X-Grpc-Web", "1").set("X-Client-Env", clientEnv).set("Content-Type", "application/grpc-web+proto");
20098
20239
  try {
20099
20240
  return yield* call.next(call.request, {
20100
20241
  ...options,
20101
- metadata: (0, import_nice_grpc_common2.Metadata)(options.metadata).set(
20242
+ metadata: metadata.set(
20102
20243
  "Authorization",
20103
20244
  `Bearer ${this.clients.get(address2)?.authToken || initialAuthToken}`
20104
- ).set("X-Requested-With", "XMLHttpRequest").set("X-Grpc-Web", "1").set("Content-Type", "application/grpc-web+proto").set("User-Agent", "spark-js-sdk")
20245
+ )
20105
20246
  });
20106
20247
  } catch (error) {
20107
20248
  if (error.message?.includes("token has expired")) {
20108
20249
  const newAuthToken = await this.authenticate(address2);
20109
- this.clients.get(address2).authToken = newAuthToken;
20250
+ const clientData = this.clients.get(address2);
20251
+ if (!clientData) {
20252
+ throw new Error(`No client found for address: ${address2}`);
20253
+ }
20254
+ clientData.authToken = newAuthToken;
20110
20255
  return yield* call.next(call.request, {
20111
20256
  ...options,
20112
- metadata: (0, import_nice_grpc_common2.Metadata)(options.metadata).set("Authorization", `Bearer ${newAuthToken}`).set("X-Requested-With", "XMLHttpRequest").set("X-Grpc-Web", "1").set("Content-Type", "application/grpc-web+proto").set("User-Agent", "spark-js-sdk")
20257
+ metadata: metadata.set("Authorization", `Bearer ${newAuthToken}`)
20113
20258
  });
20114
20259
  }
20115
20260
  throw error;
@@ -20124,7 +20269,7 @@ var ConnectionManager = class {
20124
20269
  };
20125
20270
  let options = {};
20126
20271
  const isNodeChannel = "close" in channel;
20127
- if (import_core10.isNode && isNodeChannel && !isBun) {
20272
+ if (import_core12.isNode && isNodeChannel && !isBun) {
20128
20273
  const grpcModule = await import("nice-grpc");
20129
20274
  const { openTelemetryClientMiddleware } = await import("nice-grpc-opentelemetry");
20130
20275
  const { createClientFactory } = "default" in grpcModule ? grpcModule.default : grpcModule;
@@ -20174,7 +20319,7 @@ var import_uuidv72 = require("uuidv7");
20174
20319
 
20175
20320
  // src/utils/bitcoin.ts
20176
20321
  init_buffer();
20177
- var import_utils7 = require("@noble/curves/abstract/utils");
20322
+ var import_utils8 = require("@noble/curves/abstract/utils");
20178
20323
  var import_secp256k17 = require("@noble/curves/secp256k1");
20179
20324
  var import_sha24 = require("@noble/hashes/sha2");
20180
20325
  var btc2 = __toESM(require("@scure/btc-signer"), 1);
@@ -20187,7 +20332,7 @@ function computeTaprootKeyNoScript(pubkey) {
20187
20332
  });
20188
20333
  }
20189
20334
  const taggedHash = import_secp256k17.schnorr.utils.taggedHash("TapTweak", pubkey);
20190
- const tweak = (0, import_utils7.bytesToNumberBE)(taggedHash);
20335
+ const tweak = (0, import_utils8.bytesToNumberBE)(taggedHash);
20191
20336
  const P = import_secp256k17.schnorr.utils.lift_x(import_secp256k17.schnorr.utils.bytesToNumberBE(pubkey));
20192
20337
  const Q = P.add(import_secp256k17.secp256k1.ProjectivePoint.fromPrivateKey(tweak));
20193
20338
  return Q.toRawBytes();
@@ -20240,7 +20385,7 @@ function getP2TRAddressFromPkScript(pkScript, network) {
20240
20385
  if (pkScript.length !== 34 || pkScript[0] !== 81 || pkScript[1] !== 32) {
20241
20386
  throw new ValidationError("Invalid pkscript", {
20242
20387
  field: "pkScript",
20243
- value: (0, import_utils7.bytesToHex)(pkScript),
20388
+ value: (0, import_utils8.bytesToHex)(pkScript),
20244
20389
  expected: "34 bytes starting with 0x51 0x20"
20245
20390
  });
20246
20391
  }
@@ -20265,7 +20410,7 @@ function getP2WPKHAddressFromPublicKey(pubKey, network) {
20265
20410
  return address2;
20266
20411
  }
20267
20412
  function getTxFromRawTxHex(rawTxHex) {
20268
- const txBytes = (0, import_utils7.hexToBytes)(rawTxHex);
20413
+ const txBytes = (0, import_utils8.hexToBytes)(rawTxHex);
20269
20414
  const tx = btc2.Transaction.fromRaw(txBytes, {
20270
20415
  allowUnknownOutputs: true
20271
20416
  });
@@ -20312,10 +20457,10 @@ function getSigHashFromTx(tx, inputIndex, prevOutput) {
20312
20457
  );
20313
20458
  }
20314
20459
  function getTxId(tx) {
20315
- return (0, import_utils7.bytesToHex)((0, import_sha24.sha256)((0, import_sha24.sha256)(tx.toBytes(true))).reverse());
20460
+ return (0, import_utils8.bytesToHex)((0, import_sha24.sha256)((0, import_sha24.sha256)(tx.toBytes(true))).reverse());
20316
20461
  }
20317
20462
  function getTxIdNoReverse(tx) {
20318
- return (0, import_utils7.bytesToHex)((0, import_sha24.sha256)((0, import_sha24.sha256)(tx.toBytes(true))));
20463
+ return (0, import_utils8.bytesToHex)((0, import_sha24.sha256)((0, import_sha24.sha256)(tx.toBytes(true))));
20319
20464
  }
20320
20465
 
20321
20466
  // src/utils/transaction.ts
@@ -20403,7 +20548,7 @@ function getEphemeralAnchorOutput() {
20403
20548
 
20404
20549
  // src/services/transfer.ts
20405
20550
  init_buffer();
20406
- var import_utils9 = require("@noble/curves/abstract/utils");
20551
+ var import_utils10 = require("@noble/curves/abstract/utils");
20407
20552
  var import_secp256k18 = require("@noble/curves/secp256k1");
20408
20553
  var import_sha26 = require("@noble/hashes/sha2");
20409
20554
  var import_btc_signer2 = require("@scure/btc-signer");
@@ -20412,7 +20557,7 @@ var import_uuidv7 = require("uuidv7");
20412
20557
 
20413
20558
  // src/utils/transfer_package.ts
20414
20559
  init_buffer();
20415
- var import_utils8 = require("@noble/curves/abstract/utils");
20560
+ var import_utils9 = require("@noble/curves/abstract/utils");
20416
20561
  var import_sha25 = require("@noble/hashes/sha2");
20417
20562
  function getTransferPackageSigningPayload(transferID, transferPackage) {
20418
20563
  const encryptedPayload = transferPackage.keyTweakPackage;
@@ -20421,7 +20566,7 @@ function getTransferPackageSigningPayload(transferID, transferPackage) {
20421
20566
  ).map(([key, value]) => ({ key, value }));
20422
20567
  pairs.sort((a, b) => a.key.localeCompare(b.key));
20423
20568
  const encoder = new TextEncoder();
20424
- let message = (0, import_utils8.hexToBytes)(transferID.replaceAll("-", ""));
20569
+ let message = (0, import_utils9.hexToBytes)(transferID.replaceAll("-", ""));
20425
20570
  for (const pair of pairs) {
20426
20571
  const keyPart = encoder.encode(pair.key + ":");
20427
20572
  const separator = encoder.encode(";");
@@ -20700,7 +20845,7 @@ var BaseTransferService = class {
20700
20845
  }
20701
20846
  async prepareSendTransferKeyTweaks(transferID, receiverIdentityPubkey, leaves, refundSignatureMap) {
20702
20847
  const receiverEciesPubKey = ecies2.PublicKey.fromHex(
20703
- (0, import_utils9.bytesToHex)(receiverIdentityPubkey)
20848
+ (0, import_utils10.bytesToHex)(receiverIdentityPubkey)
20704
20849
  );
20705
20850
  const leavesTweaksMap = /* @__PURE__ */ new Map();
20706
20851
  for (const leaf of leaves) {
@@ -20740,7 +20885,7 @@ var BaseTransferService = class {
20740
20885
  throw new Error(`Share not found for operator ${operator.id}`);
20741
20886
  }
20742
20887
  const pubkeyTweak = import_secp256k18.secp256k1.getPublicKey(
20743
- (0, import_utils9.numberToBytesBE)(share.share, 32),
20888
+ (0, import_utils10.numberToBytesBE)(share.share, 32),
20744
20889
  true
20745
20890
  );
20746
20891
  pubkeySharesTweak.set(identifier, pubkeyTweak);
@@ -20769,7 +20914,7 @@ var BaseTransferService = class {
20769
20914
  leafTweaksMap.set(identifier, {
20770
20915
  leafId: leaf.leaf.id,
20771
20916
  secretShareTweak: {
20772
- secretShare: (0, import_utils9.numberToBytesBE)(share.share, 32),
20917
+ secretShare: (0, import_utils10.numberToBytesBE)(share.share, 32),
20773
20918
  proofs: share.proofs
20774
20919
  },
20775
20920
  pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak),
@@ -20790,7 +20935,7 @@ var BaseTransferService = class {
20790
20935
  return void 0;
20791
20936
  }
20792
20937
  compareTransfers(transfer1, transfer2) {
20793
- return transfer1.id === transfer2.id && (0, import_utils9.equalBytes)(
20938
+ return transfer1.id === transfer2.id && (0, import_utils10.equalBytes)(
20794
20939
  transfer1.senderIdentityPublicKey,
20795
20940
  transfer2.senderIdentityPublicKey
20796
20941
  ) && transfer1.status === transfer2.status && transfer1.totalValue === transfer2.totalValue && transfer1.expiryTime?.getTime() === transfer2.expiryTime?.getTime() && transfer1.leaves.length === transfer2.leaves.length;
@@ -21033,7 +21178,7 @@ var TransferService = class extends BaseTransferService {
21033
21178
  }
21034
21179
  const nodeTx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
21035
21180
  const nodeOutPoint = {
21036
- txid: (0, import_utils9.hexToBytes)(getTxId(nodeTx)),
21181
+ txid: (0, import_utils10.hexToBytes)(getTxId(nodeTx)),
21037
21182
  index: 0
21038
21183
  };
21039
21184
  const currRefundTx = getTxFromRawTxBytes(leaf.leaf.refundTx);
@@ -21149,7 +21294,7 @@ var TransferService = class extends BaseTransferService {
21149
21294
  throw new Error(`Share not found for operator ${operator.id}`);
21150
21295
  }
21151
21296
  const pubkeyTweak = import_secp256k18.secp256k1.getPublicKey(
21152
- (0, import_utils9.numberToBytesBE)(share.share, 32)
21297
+ (0, import_utils10.numberToBytesBE)(share.share, 32)
21153
21298
  );
21154
21299
  pubkeySharesTweak.set(identifier, pubkeyTweak);
21155
21300
  }
@@ -21162,7 +21307,7 @@ var TransferService = class extends BaseTransferService {
21162
21307
  leafTweaksMap.set(identifier, {
21163
21308
  leafId: leaf.leaf.id,
21164
21309
  secretShareTweak: {
21165
- secretShare: (0, import_utils9.numberToBytesBE)(share.share, 32),
21310
+ secretShare: (0, import_utils10.numberToBytesBE)(share.share, 32),
21166
21311
  proofs: share.proofs
21167
21312
  },
21168
21313
  pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak)
@@ -21452,7 +21597,7 @@ var TransferService = class extends BaseTransferService {
21452
21597
  const refundTx = getTxFromRawTxBytes(node.refundTx);
21453
21598
  const refundSequence = refundTx.getInput(0).sequence || 0;
21454
21599
  const newNodeOutPoint = {
21455
- txid: (0, import_utils9.hexToBytes)(getTxId(nodeTx)),
21600
+ txid: (0, import_utils10.hexToBytes)(getTxId(nodeTx)),
21456
21601
  index: 0
21457
21602
  };
21458
21603
  const { nextSequence: newNodeSequence } = getNextTransactionSequence(refundSequence);
@@ -21472,7 +21617,7 @@ var TransferService = class extends BaseTransferService {
21472
21617
  });
21473
21618
  newNodeTx.addOutput(getEphemeralAnchorOutput());
21474
21619
  const newRefundOutPoint = {
21475
- txid: (0, import_utils9.hexToBytes)(getTxId(newNodeTx)),
21620
+ txid: (0, import_utils10.hexToBytes)(getTxId(newNodeTx)),
21476
21621
  index: 0
21477
21622
  };
21478
21623
  const amountSats = refundTx.getOutput(0).amount;
@@ -21673,7 +21818,7 @@ var CoopExitService = class extends BaseTransferService {
21673
21818
  connectorOutputs,
21674
21819
  receiverPubKey
21675
21820
  );
21676
- const transferTweak = await this.sendTransferTweakKey(
21821
+ const transferTweak = await this.deliverTransferPackage(
21677
21822
  transfer,
21678
21823
  leaves,
21679
21824
  signaturesMap
@@ -21819,10 +21964,10 @@ var CoopExitService = class extends BaseTransferService {
21819
21964
  init_buffer();
21820
21965
  var import_secp256k19 = require("@noble/curves/secp256k1");
21821
21966
  var import_sha28 = require("@noble/hashes/sha2");
21822
- var import_utils10 = require("@noble/hashes/utils");
21967
+ var import_utils11 = require("@noble/hashes/utils");
21823
21968
  var btc3 = __toESM(require("@scure/btc-signer"), 1);
21824
21969
  var import_btc_signer4 = require("@scure/btc-signer");
21825
- var import_utils11 = require("@scure/btc-signer/utils");
21970
+ var import_utils12 = require("@scure/btc-signer/utils");
21826
21971
 
21827
21972
  // src/utils/proof.ts
21828
21973
  init_buffer();
@@ -21890,7 +22035,7 @@ var DepositService = class {
21890
22035
  if (operator.identifier === this.config.getCoordinatorIdentifier()) {
21891
22036
  continue;
21892
22037
  }
21893
- const operatorPubkey2 = (0, import_utils10.hexToBytes)(operator.identityPublicKey);
22038
+ const operatorPubkey2 = (0, import_utils11.hexToBytes)(operator.identityPublicKey);
21894
22039
  const operatorSig = address2.depositAddressProof.addressSignatures[operator.identifier];
21895
22040
  if (!operatorSig) {
21896
22041
  throw new ValidationError("Operator signature not found", {
@@ -22066,7 +22211,7 @@ var DepositService = class {
22066
22211
  }
22067
22212
  );
22068
22213
  }
22069
- if (!(0, import_utils11.equalBytes)(treeResp.rootNodeSignatureShares.verifyingKey, verifyingKey)) {
22214
+ if (!(0, import_utils12.equalBytes)(treeResp.rootNodeSignatureShares.verifyingKey, verifyingKey)) {
22070
22215
  throw new ValidationError("Verifying key mismatch", {
22071
22216
  field: "verifyingKey",
22072
22217
  value: treeResp.rootNodeSignatureShares.verifyingKey,
@@ -22142,7 +22287,7 @@ var DepositService = class {
22142
22287
 
22143
22288
  // src/services/lightning.ts
22144
22289
  init_buffer();
22145
- var import_utils12 = require("@noble/curves/abstract/utils");
22290
+ var import_utils13 = require("@noble/curves/abstract/utils");
22146
22291
  var import_secp256k111 = require("@noble/curves/secp256k1");
22147
22292
  var import_sha210 = require("@noble/hashes/sha2");
22148
22293
  var import_uuidv73 = require("uuidv7");
@@ -22343,8 +22488,8 @@ var LightningService = class {
22343
22488
  descriptionHash
22344
22489
  }) {
22345
22490
  const randBytes = crypto2.getRandomValues(new Uint8Array(32));
22346
- const preimage = (0, import_utils12.numberToBytesBE)(
22347
- (0, import_utils12.bytesToNumberBE)(randBytes) % import_secp256k111.secp256k1.CURVE.n,
22491
+ const preimage = (0, import_utils13.numberToBytesBE)(
22492
+ (0, import_utils13.bytesToNumberBE)(randBytes) % import_secp256k111.secp256k1.CURVE.n,
22348
22493
  32
22349
22494
  );
22350
22495
  return await this.createLightningInvoiceWithPreImage({
@@ -22399,12 +22544,12 @@ var LightningService = class {
22399
22544
  const sparkClient = await this.connectionManager.createSparkClient(
22400
22545
  operator.address
22401
22546
  );
22402
- const userIdentityPublicKey = receiverIdentityPubkey ? (0, import_utils12.hexToBytes)(receiverIdentityPubkey) : await this.config.signer.getIdentityPublicKey();
22547
+ const userIdentityPublicKey = receiverIdentityPubkey ? (0, import_utils13.hexToBytes)(receiverIdentityPubkey) : await this.config.signer.getIdentityPublicKey();
22403
22548
  try {
22404
22549
  await sparkClient.store_preimage_share({
22405
22550
  paymentHash,
22406
22551
  preimageShare: {
22407
- secretShare: (0, import_utils12.numberToBytesBE)(share.share, 32),
22552
+ secretShare: (0, import_utils13.numberToBytesBE)(share.share, 32),
22408
22553
  proofs: share.proofs
22409
22554
  },
22410
22555
  threshold: this.config.getThreshold(),
@@ -22436,7 +22581,8 @@ var LightningService = class {
22436
22581
  paymentHash,
22437
22582
  invoiceString,
22438
22583
  isInboundPayment,
22439
- feeSats = 0
22584
+ feeSats = 0,
22585
+ amountSatsToSend
22440
22586
  }) {
22441
22587
  const sparkClient = await this.connectionManager.createSparkClient(
22442
22588
  this.config.getCoordinatorAddress()
@@ -22473,7 +22619,25 @@ var LightningService = class {
22473
22619
  } catch (error) {
22474
22620
  console.error("Error decoding invoice", error);
22475
22621
  }
22476
- amountSats = amountMsats / 1e3;
22622
+ const isZeroAmountInvoice = !amountMsats;
22623
+ if (isZeroAmountInvoice && amountSatsToSend === void 0) {
22624
+ throw new ValidationError(
22625
+ "Invalid amount. User must specify amountSatsToSend for 0 amount lightning invoice",
22626
+ {
22627
+ field: "amountSatsToSend",
22628
+ value: amountSatsToSend,
22629
+ expected: "positive number"
22630
+ }
22631
+ );
22632
+ }
22633
+ amountSats = isZeroAmountInvoice ? amountSatsToSend : amountMsats / 1e3;
22634
+ if (isNaN(amountSats) || amountSats <= 0) {
22635
+ throw new ValidationError("Invalid amount", {
22636
+ field: "amountSats",
22637
+ value: amountSats,
22638
+ expected: "greater than 0"
22639
+ });
22640
+ }
22477
22641
  bolt11String = invoiceString;
22478
22642
  }
22479
22643
  const reason = isInboundPayment ? 1 /* REASON_RECEIVE */ : 0 /* REASON_SEND */;
@@ -22574,7 +22738,7 @@ var LightningService = class {
22574
22738
 
22575
22739
  // src/services/lrc-connection.ts
22576
22740
  init_buffer();
22577
- var import_core11 = require("@lightsparkdev/core");
22741
+ var import_core13 = require("@lightsparkdev/core");
22578
22742
  var import_nice_grpc_client_middleware_retry2 = require("nice-grpc-client-middleware-retry");
22579
22743
  var import_nice_grpc_common3 = require("nice-grpc-common");
22580
22744
 
@@ -25647,7 +25811,7 @@ var Lrc20ConnectionManager = class {
25647
25811
  }
25648
25812
  async createChannelWithTLS(address2, certPath) {
25649
25813
  try {
25650
- if (import_core11.isNode && !isBun) {
25814
+ if (import_core13.isNode && !isBun) {
25651
25815
  const grpcModule = await import("nice-grpc");
25652
25816
  const { ChannelCredentials, createChannel } = "default" in grpcModule ? grpcModule.default : grpcModule;
25653
25817
  if (certPath) {
@@ -25714,7 +25878,7 @@ var Lrc20ConnectionManager = class {
25714
25878
  return client;
25715
25879
  }
25716
25880
  createMiddleware() {
25717
- if (import_core11.isNode) {
25881
+ if (import_core13.isNode) {
25718
25882
  return this.createNodeMiddleware();
25719
25883
  } else {
25720
25884
  return this.createBrowserMiddleware();
@@ -25724,7 +25888,7 @@ var Lrc20ConnectionManager = class {
25724
25888
  return async function* (call, options) {
25725
25889
  return yield* call.next(call.request, {
25726
25890
  ...options,
25727
- metadata: (0, import_nice_grpc_common3.Metadata)(options.metadata).set("User-Agent", "spark-js-sdk")
25891
+ metadata: (0, import_nice_grpc_common3.Metadata)(options.metadata).set("X-Client-Env", clientEnv)
25728
25892
  });
25729
25893
  }.bind(this);
25730
25894
  }
@@ -25732,7 +25896,7 @@ var Lrc20ConnectionManager = class {
25732
25896
  return async function* (call, options) {
25733
25897
  return yield* call.next(call.request, {
25734
25898
  ...options,
25735
- metadata: (0, import_nice_grpc_common3.Metadata)(options.metadata).set("X-Requested-With", "XMLHttpRequest").set("X-Grpc-Web", "1").set("Content-Type", "application/grpc-web+proto").set("User-Agent", "spark-js-sdk")
25899
+ metadata: (0, import_nice_grpc_common3.Metadata)(options.metadata).set("X-Requested-With", "XMLHttpRequest").set("X-Grpc-Web", "1").set("Content-Type", "application/grpc-web+proto").set("X-Client-Env", clientEnv)
25736
25900
  });
25737
25901
  }.bind(this);
25738
25902
  }
@@ -25744,7 +25908,7 @@ var Lrc20ConnectionManager = class {
25744
25908
  };
25745
25909
  let options = {};
25746
25910
  const isNodeChannel = "close" in channel;
25747
- if (import_core11.isNode && isNodeChannel && !isBun) {
25911
+ if (import_core13.isNode && isNodeChannel && !isBun) {
25748
25912
  const grpcModule = await import("nice-grpc");
25749
25913
  const { openTelemetryClientMiddleware } = await import("nice-grpc-opentelemetry");
25750
25914
  const { createClientFactory } = "default" in grpcModule ? grpcModule.default : grpcModule;
@@ -25789,19 +25953,290 @@ var Lrc20ConnectionManager = class {
25789
25953
 
25790
25954
  // src/services/token-transactions.ts
25791
25955
  init_buffer();
25792
- var import_utils16 = require("@noble/curves/abstract/utils");
25956
+ var import_utils17 = require("@noble/curves/abstract/utils");
25793
25957
  var import_secp256k114 = require("@noble/curves/secp256k1");
25794
25958
 
25795
25959
  // src/utils/token-hashing.ts
25796
25960
  init_buffer();
25797
25961
  var import_sha211 = require("@noble/hashes/sha2");
25798
25962
  function hashTokenTransaction(tokenTransaction, partialHash = false) {
25963
+ switch (tokenTransaction.version) {
25964
+ case 0:
25965
+ return hashTokenTransactionV0(tokenTransaction, partialHash);
25966
+ case 1:
25967
+ return hashTokenTransactionV1(tokenTransaction, partialHash);
25968
+ default:
25969
+ throw new ValidationError("invalid token transaction version", {
25970
+ field: "tokenTransaction.version",
25971
+ value: tokenTransaction.version
25972
+ });
25973
+ }
25974
+ }
25975
+ function hashTokenTransactionV0(tokenTransaction, partialHash = false) {
25976
+ if (!tokenTransaction) {
25977
+ throw new ValidationError("token transaction cannot be nil", {
25978
+ field: "tokenTransaction"
25979
+ });
25980
+ }
25981
+ let allHashes = [];
25982
+ if (tokenTransaction.tokenInputs?.$case === "transferInput") {
25983
+ if (!tokenTransaction.tokenInputs.transferInput.outputsToSpend) {
25984
+ throw new ValidationError("outputs to spend cannot be null", {
25985
+ field: "tokenInputs.transferInput.outputsToSpend"
25986
+ });
25987
+ }
25988
+ if (tokenTransaction.tokenInputs.transferInput.outputsToSpend.length === 0) {
25989
+ throw new ValidationError("outputs to spend cannot be empty", {
25990
+ field: "tokenInputs.transferInput.outputsToSpend"
25991
+ });
25992
+ }
25993
+ for (const [
25994
+ i,
25995
+ output
25996
+ ] of tokenTransaction.tokenInputs.transferInput.outputsToSpend.entries()) {
25997
+ if (!output) {
25998
+ throw new ValidationError(`output cannot be null at index ${i}`, {
25999
+ field: `tokenInputs.transferInput.outputsToSpend[${i}]`,
26000
+ index: i
26001
+ });
26002
+ }
26003
+ const hashObj2 = import_sha211.sha256.create();
26004
+ if (output.prevTokenTransactionHash) {
26005
+ const prevHash = output.prevTokenTransactionHash;
26006
+ if (output.prevTokenTransactionHash.length !== 32) {
26007
+ throw new ValidationError(
26008
+ `invalid previous transaction hash length at index ${i}`,
26009
+ {
26010
+ field: `tokenInputs.transferInput.outputsToSpend[${i}].prevTokenTransactionHash`,
26011
+ value: prevHash,
26012
+ expectedLength: 32,
26013
+ actualLength: prevHash.length,
26014
+ index: i
26015
+ }
26016
+ );
26017
+ }
26018
+ hashObj2.update(output.prevTokenTransactionHash);
26019
+ }
26020
+ const voutBytes = new Uint8Array(4);
26021
+ new DataView(voutBytes.buffer).setUint32(
26022
+ 0,
26023
+ output.prevTokenTransactionVout,
26024
+ false
26025
+ );
26026
+ hashObj2.update(voutBytes);
26027
+ allHashes.push(hashObj2.digest());
26028
+ }
26029
+ }
26030
+ if (tokenTransaction.tokenInputs?.$case === "mintInput") {
26031
+ const hashObj2 = import_sha211.sha256.create();
26032
+ if (tokenTransaction.tokenInputs.mintInput.issuerPublicKey) {
26033
+ const issuerPubKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
26034
+ if (issuerPubKey.length === 0) {
26035
+ throw new ValidationError("issuer public key cannot be empty", {
26036
+ field: "tokenInputs.mintInput.issuerPublicKey",
26037
+ value: issuerPubKey,
26038
+ expectedLength: 1,
26039
+ actualLength: 0
26040
+ });
26041
+ }
26042
+ hashObj2.update(issuerPubKey);
26043
+ if (tokenTransaction.tokenInputs.mintInput.issuerProvidedTimestamp != 0) {
26044
+ const timestampBytes = new Uint8Array(8);
26045
+ new DataView(timestampBytes.buffer).setBigUint64(
26046
+ 0,
26047
+ BigInt(
26048
+ tokenTransaction.tokenInputs.mintInput.issuerProvidedTimestamp
26049
+ ),
26050
+ true
26051
+ // true for little-endian to match Go implementation
26052
+ );
26053
+ hashObj2.update(timestampBytes);
26054
+ }
26055
+ allHashes.push(hashObj2.digest());
26056
+ }
26057
+ }
26058
+ if (!tokenTransaction.tokenOutputs) {
26059
+ throw new ValidationError("token outputs cannot be null", {
26060
+ field: "tokenOutputs"
26061
+ });
26062
+ }
26063
+ if (tokenTransaction.tokenOutputs.length === 0) {
26064
+ throw new ValidationError("token outputs cannot be empty", {
26065
+ field: "tokenOutputs"
26066
+ });
26067
+ }
26068
+ for (const [i, output] of tokenTransaction.tokenOutputs.entries()) {
26069
+ if (!output) {
26070
+ throw new ValidationError(`output cannot be null at index ${i}`, {
26071
+ field: `tokenOutputs[${i}]`,
26072
+ index: i
26073
+ });
26074
+ }
26075
+ const hashObj2 = import_sha211.sha256.create();
26076
+ if (output.id && !partialHash) {
26077
+ if (output.id.length === 0) {
26078
+ throw new ValidationError(`output ID at index ${i} cannot be empty`, {
26079
+ field: `tokenOutputs[${i}].id`,
26080
+ index: i
26081
+ });
26082
+ }
26083
+ hashObj2.update(new TextEncoder().encode(output.id));
26084
+ }
26085
+ if (output.ownerPublicKey) {
26086
+ if (output.ownerPublicKey.length === 0) {
26087
+ throw new ValidationError(
26088
+ `owner public key at index ${i} cannot be empty`,
26089
+ {
26090
+ field: `tokenOutputs[${i}].ownerPublicKey`,
26091
+ index: i
26092
+ }
26093
+ );
26094
+ }
26095
+ hashObj2.update(output.ownerPublicKey);
26096
+ }
26097
+ if (!partialHash) {
26098
+ const revPubKey = output.revocationCommitment;
26099
+ if (revPubKey) {
26100
+ if (revPubKey.length === 0) {
26101
+ throw new ValidationError(
26102
+ `revocation commitment at index ${i} cannot be empty`,
26103
+ {
26104
+ field: `tokenOutputs[${i}].revocationCommitment`,
26105
+ index: i
26106
+ }
26107
+ );
26108
+ }
26109
+ hashObj2.update(revPubKey);
26110
+ }
26111
+ const bondBytes = new Uint8Array(8);
26112
+ new DataView(bondBytes.buffer).setBigUint64(
26113
+ 0,
26114
+ BigInt(output.withdrawBondSats),
26115
+ false
26116
+ );
26117
+ hashObj2.update(bondBytes);
26118
+ const locktimeBytes = new Uint8Array(8);
26119
+ new DataView(locktimeBytes.buffer).setBigUint64(
26120
+ 0,
26121
+ BigInt(output.withdrawRelativeBlockLocktime),
26122
+ false
26123
+ );
26124
+ hashObj2.update(locktimeBytes);
26125
+ }
26126
+ if (output.tokenPublicKey) {
26127
+ if (output.tokenPublicKey.length === 0) {
26128
+ throw new ValidationError(
26129
+ `token public key at index ${i} cannot be empty`,
26130
+ {
26131
+ field: `tokenOutputs[${i}].tokenPublicKey`,
26132
+ index: i
26133
+ }
26134
+ );
26135
+ }
26136
+ hashObj2.update(output.tokenPublicKey);
26137
+ }
26138
+ if (output.tokenAmount) {
26139
+ if (output.tokenAmount.length === 0) {
26140
+ throw new ValidationError(
26141
+ `token amount at index ${i} cannot be empty`,
26142
+ {
26143
+ field: `tokenOutputs[${i}].tokenAmount`,
26144
+ index: i
26145
+ }
26146
+ );
26147
+ }
26148
+ if (output.tokenAmount.length > 16) {
26149
+ throw new ValidationError(
26150
+ `token amount at index ${i} exceeds maximum length`,
26151
+ {
26152
+ field: `tokenOutputs[${i}].tokenAmount`,
26153
+ value: output.tokenAmount,
26154
+ expectedLength: 16,
26155
+ actualLength: output.tokenAmount.length,
26156
+ index: i
26157
+ }
26158
+ );
26159
+ }
26160
+ hashObj2.update(output.tokenAmount);
26161
+ }
26162
+ allHashes.push(hashObj2.digest());
26163
+ }
26164
+ if (!tokenTransaction.sparkOperatorIdentityPublicKeys) {
26165
+ throw new ValidationError(
26166
+ "spark operator identity public keys cannot be null",
26167
+ {}
26168
+ );
26169
+ }
26170
+ const sortedPubKeys = [
26171
+ ...tokenTransaction.sparkOperatorIdentityPublicKeys || []
26172
+ ].sort((a, b) => {
26173
+ for (let i = 0; i < a.length && i < b.length; i++) {
26174
+ if (a[i] !== b[i]) return a[i] - b[i];
26175
+ }
26176
+ return a.length - b.length;
26177
+ });
26178
+ for (const [i, pubKey] of sortedPubKeys.entries()) {
26179
+ if (!pubKey) {
26180
+ throw new ValidationError(
26181
+ `operator public key at index ${i} cannot be null`,
26182
+ {
26183
+ field: `sparkOperatorIdentityPublicKeys[${i}]`,
26184
+ index: i
26185
+ }
26186
+ );
26187
+ }
26188
+ if (pubKey.length === 0) {
26189
+ throw new ValidationError(
26190
+ `operator public key at index ${i} cannot be empty`,
26191
+ {
26192
+ field: `sparkOperatorIdentityPublicKeys[${i}]`,
26193
+ index: i
26194
+ }
26195
+ );
26196
+ }
26197
+ const hashObj2 = import_sha211.sha256.create();
26198
+ hashObj2.update(pubKey);
26199
+ allHashes.push(hashObj2.digest());
26200
+ }
26201
+ const hashObj = import_sha211.sha256.create();
26202
+ let networkBytes = new Uint8Array(4);
26203
+ new DataView(networkBytes.buffer).setUint32(
26204
+ 0,
26205
+ tokenTransaction.network.valueOf(),
26206
+ false
26207
+ // false for big-endian
26208
+ );
26209
+ hashObj.update(networkBytes);
26210
+ allHashes.push(hashObj.digest());
26211
+ const finalHashObj = import_sha211.sha256.create();
26212
+ const concatenatedHashes = new Uint8Array(
26213
+ allHashes.reduce((sum, hash) => sum + hash.length, 0)
26214
+ );
26215
+ let offset = 0;
26216
+ for (const hash of allHashes) {
26217
+ concatenatedHashes.set(hash, offset);
26218
+ offset += hash.length;
26219
+ }
26220
+ finalHashObj.update(concatenatedHashes);
26221
+ return finalHashObj.digest();
26222
+ }
26223
+ function hashTokenTransactionV1(tokenTransaction, partialHash = false) {
25799
26224
  if (!tokenTransaction) {
25800
26225
  throw new ValidationError("token transaction cannot be nil", {
25801
26226
  field: "tokenTransaction"
25802
26227
  });
25803
26228
  }
25804
26229
  let allHashes = [];
26230
+ const versionHashObj = import_sha211.sha256.create();
26231
+ const versionBytes = new Uint8Array(4);
26232
+ new DataView(versionBytes.buffer).setUint32(
26233
+ 0,
26234
+ tokenTransaction.version,
26235
+ false
26236
+ // false for big-endian
26237
+ );
26238
+ versionHashObj.update(versionBytes);
26239
+ allHashes.push(versionHashObj.digest());
25805
26240
  if (tokenTransaction.tokenInputs?.$case === "transferInput") {
25806
26241
  if (!tokenTransaction.tokenInputs.transferInput.outputsToSpend) {
25807
26242
  throw new ValidationError("outputs to spend cannot be null", {
@@ -26031,6 +26466,17 @@ function hashTokenTransaction(tokenTransaction, partialHash = false) {
26031
26466
  );
26032
26467
  hashObj.update(networkBytes);
26033
26468
  allHashes.push(hashObj.digest());
26469
+ const expiryHashObj = import_sha211.sha256.create();
26470
+ const validityDurationBytes = new Uint8Array(8);
26471
+ const expiryUnixTime = tokenTransaction.expiryTime ? Math.floor(tokenTransaction.expiryTime.getTime() / 1e3) : 0;
26472
+ new DataView(validityDurationBytes.buffer).setBigUint64(
26473
+ 0,
26474
+ BigInt(expiryUnixTime),
26475
+ false
26476
+ // false for big-endian
26477
+ );
26478
+ expiryHashObj.update(validityDurationBytes);
26479
+ allHashes.push(expiryHashObj.digest());
26034
26480
  const finalHashObj = import_sha211.sha256.create();
26035
26481
  const concatenatedHashes = new Uint8Array(
26036
26482
  allHashes.reduce((sum, hash) => sum + hash.length, 0)
@@ -26094,15 +26540,15 @@ function hashOperatorSpecificTokenTransactionSignablePayload(payload) {
26094
26540
 
26095
26541
  // src/utils/token-transactions.ts
26096
26542
  init_buffer();
26097
- var import_utils13 = require("@noble/curves/abstract/utils");
26543
+ var import_utils14 = require("@noble/curves/abstract/utils");
26098
26544
  function calculateAvailableTokenAmount(outputLeaves) {
26099
26545
  return outputLeaves.reduce(
26100
- (sum, output) => sum + BigInt((0, import_utils13.bytesToNumberBE)(output.output.tokenAmount)),
26546
+ (sum, output) => sum + BigInt((0, import_utils14.bytesToNumberBE)(output.output.tokenAmount)),
26101
26547
  BigInt(0)
26102
26548
  );
26103
26549
  }
26104
26550
  function checkIfSelectedOutputsAreAvailable(selectedOutputs, tokenOutputs, tokenPublicKey) {
26105
- const tokenPubKeyHex = (0, import_utils13.bytesToHex)(tokenPublicKey);
26551
+ const tokenPubKeyHex = (0, import_utils14.bytesToHex)(tokenPublicKey);
26106
26552
  const tokenOutputsAvailable = tokenOutputs.get(tokenPubKeyHex);
26107
26553
  if (!tokenOutputsAvailable) {
26108
26554
  return false;
@@ -26388,7 +26834,7 @@ function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction
26388
26834
  }
26389
26835
 
26390
26836
  // src/services/token-transactions.ts
26391
- var import_utils17 = require("@noble/hashes/utils");
26837
+ var import_utils18 = require("@noble/hashes/utils");
26392
26838
 
26393
26839
  // src/address/index.ts
26394
26840
  init_buffer();
@@ -26396,10 +26842,10 @@ init_buffer();
26396
26842
  // src/address/address.ts
26397
26843
  init_buffer();
26398
26844
  var import_secp256k112 = require("@noble/curves/secp256k1");
26399
- var import_utils14 = require("@noble/hashes/utils");
26845
+ var import_utils15 = require("@noble/hashes/utils");
26400
26846
  var import_base3 = require("@scure/base");
26401
26847
  var import_uuidv74 = require("uuidv7");
26402
- var import_utils15 = require("@noble/curves/abstract/utils");
26848
+ var import_utils16 = require("@noble/curves/abstract/utils");
26403
26849
  var AddressNetwork = {
26404
26850
  MAINNET: "sp",
26405
26851
  TESTNET: "spt",
@@ -26415,7 +26861,7 @@ function encodeSparkAddress(payload) {
26415
26861
  paymentIntentFields = payload.paymentIntentFields;
26416
26862
  }
26417
26863
  const sparkAddressProto = SparkAddress.create({
26418
- identityPublicKey: (0, import_utils14.hexToBytes)(payload.identityPublicKey),
26864
+ identityPublicKey: (0, import_utils15.hexToBytes)(payload.identityPublicKey),
26419
26865
  paymentIntentFields
26420
26866
  });
26421
26867
  const serializedPayload = SparkAddress.encode(sparkAddressProto).finish();
@@ -26447,7 +26893,7 @@ function decodeSparkAddress(address2, network) {
26447
26893
  });
26448
26894
  }
26449
26895
  const payload = SparkAddress.decode(import_base3.bech32m.fromWords(decoded.words));
26450
- const publicKey = (0, import_utils14.bytesToHex)(payload.identityPublicKey);
26896
+ const publicKey = (0, import_utils15.bytesToHex)(payload.identityPublicKey);
26451
26897
  isValidPublicKey(publicKey);
26452
26898
  const paymentIntentFields = payload.paymentIntentFields;
26453
26899
  return {
@@ -26455,8 +26901,8 @@ function decodeSparkAddress(address2, network) {
26455
26901
  network,
26456
26902
  paymentIntentFields: paymentIntentFields && {
26457
26903
  id: import_uuidv74.UUID.ofInner(paymentIntentFields.id).toString(),
26458
- assetIdentifier: paymentIntentFields.assetIdentifier ? (0, import_utils14.bytesToHex)(paymentIntentFields.assetIdentifier) : void 0,
26459
- assetAmount: (0, import_utils15.bytesToNumberBE)(paymentIntentFields.assetAmount),
26904
+ assetIdentifier: paymentIntentFields.assetIdentifier ? (0, import_utils15.bytesToHex)(paymentIntentFields.assetIdentifier) : void 0,
26905
+ assetAmount: (0, import_utils16.bytesToNumberBE)(paymentIntentFields.assetAmount),
26460
26906
  memo: paymentIntentFields.memo
26461
26907
  }
26462
26908
  };
@@ -26557,7 +27003,7 @@ var TokenTransactionService = class {
26557
27003
  if (!checkIfSelectedOutputsAreAvailable(
26558
27004
  outputsToUse,
26559
27005
  tokenOutputs,
26560
- (0, import_utils17.hexToBytes)(receiverOutputs[0].tokenPublicKey)
27006
+ (0, import_utils18.hexToBytes)(receiverOutputs[0].tokenPublicKey)
26561
27007
  )) {
26562
27008
  throw new ValidationError(
26563
27009
  "One or more selected TTXOs are not available",
@@ -26598,8 +27044,8 @@ var TokenTransactionService = class {
26598
27044
  this.config.getNetworkType()
26599
27045
  );
26600
27046
  return {
26601
- receiverSparkAddress: (0, import_utils17.hexToBytes)(receiverAddress.identityPublicKey),
26602
- tokenPublicKey: (0, import_utils17.hexToBytes)(transfer.tokenPublicKey),
27047
+ receiverSparkAddress: (0, import_utils18.hexToBytes)(receiverAddress.identityPublicKey),
27048
+ tokenPublicKey: (0, import_utils18.hexToBytes)(transfer.tokenPublicKey),
26603
27049
  tokenAmount: transfer.tokenAmount
26604
27050
  };
26605
27051
  });
@@ -26631,7 +27077,7 @@ var TokenTransactionService = class {
26631
27077
  const tokenOutputs = tokenOutputData.map((output) => ({
26632
27078
  ownerPublicKey: output.receiverSparkAddress,
26633
27079
  tokenPublicKey: output.tokenPublicKey,
26634
- tokenAmount: (0, import_utils16.numberToBytesBE)(output.tokenAmount, 16)
27080
+ tokenAmount: (0, import_utils17.numberToBytesBE)(output.tokenAmount, 16)
26635
27081
  }));
26636
27082
  if (availableTokenAmount > totalRequestedAmount) {
26637
27083
  const changeAmount = availableTokenAmount - totalRequestedAmount;
@@ -26639,7 +27085,7 @@ var TokenTransactionService = class {
26639
27085
  tokenOutputs.push({
26640
27086
  ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
26641
27087
  tokenPublicKey: firstTokenPublicKey,
26642
- tokenAmount: (0, import_utils16.numberToBytesBE)(changeAmount, 16)
27088
+ tokenAmount: (0, import_utils17.numberToBytesBE)(changeAmount, 16)
26643
27089
  });
26644
27090
  }
26645
27091
  return {
@@ -26666,7 +27112,7 @@ var TokenTransactionService = class {
26666
27112
  const tokenOutputs = tokenOutputData.map((output) => ({
26667
27113
  ownerPublicKey: output.receiverSparkAddress,
26668
27114
  tokenPublicKey: output.tokenPublicKey,
26669
- tokenAmount: (0, import_utils16.numberToBytesBE)(output.tokenAmount, 16)
27115
+ tokenAmount: (0, import_utils17.numberToBytesBE)(output.tokenAmount, 16)
26670
27116
  }));
26671
27117
  if (availableTokenAmount > totalRequestedAmount) {
26672
27118
  const changeAmount = availableTokenAmount - totalRequestedAmount;
@@ -26674,7 +27120,7 @@ var TokenTransactionService = class {
26674
27120
  tokenOutputs.push({
26675
27121
  ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
26676
27122
  tokenPublicKey: firstTokenPublicKey,
26677
- tokenAmount: (0, import_utils16.numberToBytesBE)(changeAmount, 16)
27123
+ tokenAmount: (0, import_utils17.numberToBytesBE)(changeAmount, 16)
26678
27124
  });
26679
27125
  }
26680
27126
  return {
@@ -26699,7 +27145,7 @@ var TokenTransactionService = class {
26699
27145
  for (const [_, operator] of Object.entries(
26700
27146
  this.config.getSigningOperators()
26701
27147
  )) {
26702
- operatorKeys.push((0, import_utils17.hexToBytes)(operator.identityPublicKey));
27148
+ operatorKeys.push((0, import_utils18.hexToBytes)(operator.identityPublicKey));
26703
27149
  }
26704
27150
  return operatorKeys;
26705
27151
  }
@@ -26783,7 +27229,7 @@ var TokenTransactionService = class {
26783
27229
  {
26784
27230
  field: "revocationCommitment",
26785
27231
  value: derivedRevocationCommitment,
26786
- expected: (0, import_utils16.bytesToHex)(outputsToSpendCommitments[outputIndex]),
27232
+ expected: (0, import_utils17.bytesToHex)(outputsToSpendCommitments[outputIndex]),
26787
27233
  outputIndex
26788
27234
  }
26789
27235
  )
@@ -26809,7 +27255,7 @@ var TokenTransactionService = class {
26809
27255
  threshold
26810
27256
  );
26811
27257
  }
26812
- return (0, import_utils16.bytesToHex)(finalTokenTransactionHash);
27258
+ return (0, import_utils17.bytesToHex)(finalTokenTransactionHash);
26813
27259
  }
26814
27260
  async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
26815
27261
  const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
@@ -26823,13 +27269,13 @@ var TokenTransactionService = class {
26823
27269
  finalTokenTransactionHash,
26824
27270
  signingOperators
26825
27271
  );
26826
- return (0, import_utils16.bytesToHex)(finalTokenTransactionHash);
27272
+ return (0, import_utils17.bytesToHex)(finalTokenTransactionHash);
26827
27273
  }
26828
27274
  async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
26829
27275
  const sparkClient = await this.connectionManager.createSparkClient(
26830
27276
  this.config.getCoordinatorAddress()
26831
27277
  );
26832
- const partialTokenTransactionHash = hashTokenTransaction(
27278
+ const partialTokenTransactionHash = hashTokenTransactionV0(
26833
27279
  tokenTransaction,
26834
27280
  true
26835
27281
  );
@@ -26910,7 +27356,7 @@ var TokenTransactionService = class {
26910
27356
  this.config.getThreshold()
26911
27357
  );
26912
27358
  const finalTokenTransaction = startResponse.finalTokenTransaction;
26913
- const finalTokenTransactionHash = hashTokenTransaction(
27359
+ const finalTokenTransactionHash = hashTokenTransactionV0(
26914
27360
  finalTokenTransaction,
26915
27361
  false
26916
27362
  );
@@ -26978,7 +27424,9 @@ var TokenTransactionService = class {
26978
27424
  const startResponse = await sparkClient.start_transaction(
26979
27425
  {
26980
27426
  identityPublicKey: await this.config.signer.getIdentityPublicKey(),
26981
- partialTokenTransaction: tokenTransaction
27427
+ partialTokenTransaction: tokenTransaction,
27428
+ validityDurationSeconds: await this.config.getTokenValidityDurationSeconds(),
27429
+ partialTokenTransactionOwnerSignatures: ownerSignaturesWithIndex
26982
27430
  },
26983
27431
  {
26984
27432
  retry: true,
@@ -27020,7 +27468,7 @@ var TokenTransactionService = class {
27020
27468
  const identityPublicKey = await this.config.signer.getIdentityPublicKey();
27021
27469
  const payload = {
27022
27470
  finalTokenTransactionHash,
27023
- operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
27471
+ operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
27024
27472
  };
27025
27473
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
27026
27474
  let operatorSpecificSignatures = [];
@@ -27177,7 +27625,7 @@ var TokenTransactionService = class {
27177
27625
  []
27178
27626
  );
27179
27627
  unsortedTokenOutputs.forEach((output) => {
27180
- const tokenKey = (0, import_utils16.bytesToHex)(output.output.tokenPublicKey);
27628
+ const tokenKey = (0, import_utils17.bytesToHex)(output.output.tokenPublicKey);
27181
27629
  const index = output.previousTransactionVout;
27182
27630
  tokenOutputs.set(tokenKey, [
27183
27631
  { ...output, previousTransactionVout: index }
@@ -27193,7 +27641,7 @@ var TokenTransactionService = class {
27193
27641
  });
27194
27642
  }
27195
27643
  const exactMatch = tokenOutputs.find(
27196
- (item) => (0, import_utils16.bytesToNumberBE)(item.output.tokenAmount) === tokenAmount
27644
+ (item) => (0, import_utils17.bytesToNumberBE)(item.output.tokenAmount) === tokenAmount
27197
27645
  );
27198
27646
  if (exactMatch) {
27199
27647
  return [exactMatch];
@@ -27204,7 +27652,7 @@ var TokenTransactionService = class {
27204
27652
  for (const outputWithPreviousTransactionData of tokenOutputs) {
27205
27653
  if (remainingAmount <= 0n) break;
27206
27654
  selectedOutputs.push(outputWithPreviousTransactionData);
27207
- remainingAmount -= (0, import_utils16.bytesToNumberBE)(
27655
+ remainingAmount -= (0, import_utils17.bytesToNumberBE)(
27208
27656
  outputWithPreviousTransactionData.output.tokenAmount
27209
27657
  );
27210
27658
  }
@@ -27220,13 +27668,13 @@ var TokenTransactionService = class {
27220
27668
  if (strategy === "SMALL_FIRST") {
27221
27669
  tokenOutputs.sort((a, b) => {
27222
27670
  return Number(
27223
- (0, import_utils16.bytesToNumberBE)(a.output.tokenAmount) - (0, import_utils16.bytesToNumberBE)(b.output.tokenAmount)
27671
+ (0, import_utils17.bytesToNumberBE)(a.output.tokenAmount) - (0, import_utils17.bytesToNumberBE)(b.output.tokenAmount)
27224
27672
  );
27225
27673
  });
27226
27674
  } else {
27227
27675
  tokenOutputs.sort((a, b) => {
27228
27676
  return Number(
27229
- (0, import_utils16.bytesToNumberBE)(b.output.tokenAmount) - (0, import_utils16.bytesToNumberBE)(a.output.tokenAmount)
27677
+ (0, import_utils17.bytesToNumberBE)(b.output.tokenAmount) - (0, import_utils17.bytesToNumberBE)(a.output.tokenAmount)
27230
27678
  );
27231
27679
  });
27232
27680
  }
@@ -27234,7 +27682,7 @@ var TokenTransactionService = class {
27234
27682
  // Helper function for deciding if the signer public key is the identity public key
27235
27683
  async signMessageWithKey(message, publicKey) {
27236
27684
  const tokenSignatures = this.config.getTokenSignatures();
27237
- if ((0, import_utils16.bytesToHex)(publicKey) === (0, import_utils16.bytesToHex)(await this.config.signer.getIdentityPublicKey())) {
27685
+ if ((0, import_utils17.bytesToHex)(publicKey) === (0, import_utils17.bytesToHex)(await this.config.signer.getIdentityPublicKey())) {
27238
27686
  if (tokenSignatures === "SCHNORR") {
27239
27687
  return await this.config.signer.signSchnorrWithIdentityKey(message);
27240
27688
  } else {
@@ -27310,7 +27758,7 @@ var TokenTransactionService = class {
27310
27758
  }
27311
27759
  const payload = {
27312
27760
  finalTokenTransactionHash,
27313
- operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
27761
+ operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
27314
27762
  };
27315
27763
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
27316
27764
  const ownerSignature = await this.signMessageWithKey(
@@ -27326,7 +27774,7 @@ var TokenTransactionService = class {
27326
27774
  for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
27327
27775
  const payload = {
27328
27776
  finalTokenTransactionHash,
27329
- operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
27777
+ operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
27330
27778
  };
27331
27779
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
27332
27780
  let ownerSignature;
@@ -27343,7 +27791,7 @@ var TokenTransactionService = class {
27343
27791
  }
27344
27792
  inputTtxoSignaturesPerOperator.push({
27345
27793
  ttxoSignatures,
27346
- operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
27794
+ operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
27347
27795
  });
27348
27796
  }
27349
27797
  return inputTtxoSignaturesPerOperator;
@@ -27355,7 +27803,7 @@ function isTokenTransaction(tokenTransaction) {
27355
27803
 
27356
27804
  // src/services/tree-creation.ts
27357
27805
  init_buffer();
27358
- var import_utils18 = require("@noble/curves/abstract/utils");
27806
+ var import_utils19 = require("@noble/curves/abstract/utils");
27359
27807
  var import_sha212 = require("@noble/hashes/sha2");
27360
27808
  var import_btc_signer5 = require("@scure/btc-signer");
27361
27809
  var INITIAL_TIME_LOCK3 = 2e3;
@@ -27404,7 +27852,7 @@ var TreeCreationService = class {
27404
27852
  request.source = {
27405
27853
  $case: "onChainUtxo",
27406
27854
  onChainUtxo: {
27407
- txid: (0, import_utils18.hexToBytes)(getTxId(parentTx)),
27855
+ txid: (0, import_utils19.hexToBytes)(getTxId(parentTx)),
27408
27856
  vout,
27409
27857
  rawTx: parentTx.toBytes(),
27410
27858
  network: this.config.getNetworkProto()
@@ -27445,7 +27893,7 @@ var TreeCreationService = class {
27445
27893
  request.source = {
27446
27894
  $case: "onChainUtxo",
27447
27895
  onChainUtxo: {
27448
- txid: (0, import_utils18.hexToBytes)(getTxId(parentTx)),
27896
+ txid: (0, import_utils19.hexToBytes)(getTxId(parentTx)),
27449
27897
  vout,
27450
27898
  rawTx: parentTx.toBytes(),
27451
27899
  network: this.config.getNetworkProto()
@@ -27816,13 +28264,13 @@ var TreeCreationService = class {
27816
28264
  };
27817
28265
 
27818
28266
  // src/spark-wallet/spark-wallet.ts
27819
- var import_lrc20_sdk3 = require("@buildonspark/lrc20-sdk");
28267
+ var import_lrc20_sdk4 = require("@buildonspark/lrc20-sdk");
27820
28268
  var import_sha213 = require("@noble/hashes/sha2");
27821
28269
  var import_eventemitter3 = require("eventemitter3");
27822
28270
 
27823
28271
  // src/services/signing.ts
27824
28272
  init_buffer();
27825
- var import_utils19 = require("@noble/curves/abstract/utils");
28273
+ var import_utils20 = require("@noble/curves/abstract/utils");
27826
28274
  var SigningService = class {
27827
28275
  config;
27828
28276
  constructor(config) {
@@ -27841,7 +28289,7 @@ var SigningService = class {
27841
28289
  }
27842
28290
  const nodeTx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
27843
28291
  const nodeOutPoint = {
27844
- txid: (0, import_utils19.hexToBytes)(getTxId(nodeTx)),
28292
+ txid: (0, import_utils20.hexToBytes)(getTxId(nodeTx)),
27845
28293
  index: 0
27846
28294
  };
27847
28295
  const currRefundTx = getTxFromRawTxBytes(leaf.leaf.refundTx);
@@ -27899,15 +28347,15 @@ var SigningService = class {
27899
28347
 
27900
28348
  // src/tests/utils/test-faucet.ts
27901
28349
  init_buffer();
27902
- var import_utils20 = require("@noble/curves/abstract/utils");
28350
+ var import_utils21 = require("@noble/curves/abstract/utils");
27903
28351
  var import_secp256k115 = require("@noble/curves/secp256k1");
27904
28352
  var btc4 = __toESM(require("@scure/btc-signer"), 1);
27905
28353
  var import_btc_signer6 = require("@scure/btc-signer");
27906
- var import_utils21 = require("@scure/btc-signer/utils");
27907
- var STATIC_FAUCET_KEY = (0, import_utils20.hexToBytes)(
28354
+ var import_utils22 = require("@scure/btc-signer/utils");
28355
+ var STATIC_FAUCET_KEY = (0, import_utils21.hexToBytes)(
27908
28356
  "deadbeef1337cafe4242424242424242deadbeef1337cafe4242424242424242"
27909
28357
  );
27910
- var STATIC_MINING_KEY = (0, import_utils20.hexToBytes)(
28358
+ var STATIC_MINING_KEY = (0, import_utils21.hexToBytes)(
27911
28359
  "1337cafe4242deadbeef4242424242421337cafe4242deadbeef424242424242"
27912
28360
  );
27913
28361
  var SATS_PER_BTC = 1e8;
@@ -27970,7 +28418,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
27970
28418
  if (!scanResult.success || scanResult.unspents.length === 0) {
27971
28419
  const blockHash = await this.generateToAddress(1, address2);
27972
28420
  const block = await this.getBlock(blockHash[0]);
27973
- const fundingTx = import_btc_signer6.Transaction.fromRaw((0, import_utils20.hexToBytes)(block.tx[0].hex), {
28421
+ const fundingTx = import_btc_signer6.Transaction.fromRaw((0, import_utils21.hexToBytes)(block.tx[0].hex), {
27974
28422
  allowUnknownOutputs: true
27975
28423
  });
27976
28424
  await this.generateToAddress(100, this.miningAddress);
@@ -28032,13 +28480,13 @@ var BitcoinFaucet = class _BitcoinFaucet {
28032
28480
  },
28033
28481
  STATIC_MINING_KEY
28034
28482
  );
28035
- await this.broadcastTx((0, import_utils20.bytesToHex)(signedSplitTx.extract()));
28483
+ await this.broadcastTx((0, import_utils21.bytesToHex)(signedSplitTx.extract()));
28036
28484
  const splitTxId = signedSplitTx.id;
28037
28485
  for (let i = 0; i < numCoinsToCreate; i++) {
28038
28486
  this.coins.push({
28039
28487
  key: STATIC_FAUCET_KEY,
28040
28488
  outpoint: {
28041
- txid: (0, import_utils20.hexToBytes)(splitTxId),
28489
+ txid: (0, import_utils21.hexToBytes)(splitTxId),
28042
28490
  index: i
28043
28491
  },
28044
28492
  txout: signedSplitTx.getOutput(i)
@@ -28066,7 +28514,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
28066
28514
  coinToSend.txout,
28067
28515
  coinToSend.key
28068
28516
  );
28069
- await this.broadcastTx((0, import_utils20.bytesToHex)(signedTx.extract()));
28517
+ await this.broadcastTx((0, import_utils21.bytesToHex)(signedTx.extract()));
28070
28518
  }
28071
28519
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
28072
28520
  const pubKey = import_secp256k115.secp256k1.getPublicKey(key);
@@ -28086,7 +28534,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
28086
28534
  new Array(unsignedTx.inputsLength).fill(fundingTxOut.amount)
28087
28535
  );
28088
28536
  const merkleRoot = new Uint8Array();
28089
- const tweakedKey = (0, import_utils21.taprootTweakPrivKey)(key, merkleRoot);
28537
+ const tweakedKey = (0, import_utils22.taprootTweakPrivKey)(key, merkleRoot);
28090
28538
  if (!tweakedKey)
28091
28539
  throw new Error("Invalid private key for taproot tweaking");
28092
28540
  const signature = import_secp256k115.schnorr.sign(sighash, tweakedKey);
@@ -28185,7 +28633,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
28185
28633
  });
28186
28634
  }
28187
28635
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
28188
- const txHex = (0, import_utils20.bytesToHex)(signedTx.extract());
28636
+ const txHex = (0, import_utils21.bytesToHex)(signedTx.extract());
28189
28637
  await this.broadcastTx(txHex);
28190
28638
  const randomKey = import_secp256k115.secp256k1.utils.randomPrivateKey();
28191
28639
  const randomPubKey = import_secp256k115.secp256k1.getPublicKey(randomKey);
@@ -28203,18 +28651,18 @@ var BitcoinFaucet = class _BitcoinFaucet {
28203
28651
 
28204
28652
  // src/types/sdk-types.ts
28205
28653
  init_buffer();
28206
- var import_utils22 = require("@noble/curves/abstract/utils");
28654
+ var import_utils23 = require("@noble/curves/abstract/utils");
28207
28655
  function mapTreeNodeToWalletLeaf(proto) {
28208
28656
  return {
28209
28657
  id: proto.id,
28210
28658
  treeId: proto.treeId,
28211
28659
  value: proto.value,
28212
28660
  parentNodeId: proto.parentNodeId,
28213
- nodeTx: (0, import_utils22.bytesToHex)(proto.nodeTx),
28214
- refundTx: (0, import_utils22.bytesToHex)(proto.refundTx),
28661
+ nodeTx: (0, import_utils23.bytesToHex)(proto.nodeTx),
28662
+ refundTx: (0, import_utils23.bytesToHex)(proto.refundTx),
28215
28663
  vout: proto.vout,
28216
- verifyingPublicKey: (0, import_utils22.bytesToHex)(proto.verifyingPublicKey),
28217
- ownerIdentityPublicKey: (0, import_utils22.bytesToHex)(proto.ownerIdentityPublicKey),
28664
+ verifyingPublicKey: (0, import_utils23.bytesToHex)(proto.verifyingPublicKey),
28665
+ ownerIdentityPublicKey: (0, import_utils23.bytesToHex)(proto.ownerIdentityPublicKey),
28218
28666
  signingKeyshare: proto.signingKeyshare,
28219
28667
  status: proto.status,
28220
28668
  network: Network[proto.network]
@@ -28223,14 +28671,14 @@ function mapTreeNodeToWalletLeaf(proto) {
28223
28671
  function mapTransferLeafToWalletTransferLeaf(proto) {
28224
28672
  return {
28225
28673
  leaf: proto.leaf ? mapTreeNodeToWalletLeaf(proto.leaf) : void 0,
28226
- secretCipher: (0, import_utils22.bytesToHex)(proto.secretCipher),
28227
- signature: (0, import_utils22.bytesToHex)(proto.signature),
28228
- intermediateRefundTx: (0, import_utils22.bytesToHex)(proto.intermediateRefundTx)
28674
+ secretCipher: (0, import_utils23.bytesToHex)(proto.secretCipher),
28675
+ signature: (0, import_utils23.bytesToHex)(proto.signature),
28676
+ intermediateRefundTx: (0, import_utils23.bytesToHex)(proto.intermediateRefundTx)
28229
28677
  };
28230
28678
  }
28231
28679
  function mapTransferToWalletTransfer(proto, identityPublicKey) {
28232
- const receiverIdentityPublicKey = (0, import_utils22.bytesToHex)(proto.receiverIdentityPublicKey);
28233
- const senderIdentityPublicKey = (0, import_utils22.bytesToHex)(proto.senderIdentityPublicKey);
28680
+ const receiverIdentityPublicKey = (0, import_utils23.bytesToHex)(proto.receiverIdentityPublicKey);
28681
+ const senderIdentityPublicKey = (0, import_utils23.bytesToHex)(proto.senderIdentityPublicKey);
28234
28682
  return {
28235
28683
  id: proto.id,
28236
28684
  senderIdentityPublicKey,
@@ -28356,7 +28804,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28356
28804
  try {
28357
28805
  if (event?.$case === "transfer" && event.transfer.transfer && event.transfer.transfer.type !== 40 /* COUNTER_SWAP */) {
28358
28806
  const { senderIdentityPublicKey, receiverIdentityPublicKey } = event.transfer.transfer;
28359
- if (event.transfer.transfer && !(0, import_utils23.equalBytes)(senderIdentityPublicKey, receiverIdentityPublicKey)) {
28807
+ if (event.transfer.transfer && !(0, import_utils24.equalBytes)(senderIdentityPublicKey, receiverIdentityPublicKey)) {
28360
28808
  await this.claimTransfer({
28361
28809
  transfer: event.transfer.transfer,
28362
28810
  emit: true,
@@ -28428,7 +28876,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28428
28876
  setTimeout(maybeUnref, 100);
28429
28877
  }
28430
28878
  };
28431
- if (import_core12.isNode) {
28879
+ if (import_core14.isNode) {
28432
28880
  maybeUnref();
28433
28881
  }
28434
28882
  const claimedTransfersIds = await this.claimTransfers();
@@ -28518,10 +28966,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28518
28966
  leavesToIgnore.add(nodeId);
28519
28967
  continue;
28520
28968
  }
28521
- if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !(0, import_utils23.equalBytes)(
28969
+ if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !(0, import_utils24.equalBytes)(
28522
28970
  leaf.signingKeyshare.publicKey,
28523
28971
  operatorLeaf.signingKeyshare.publicKey
28524
- ) || !(0, import_utils23.equalBytes)(leaf.nodeTx, operatorLeaf.nodeTx) || !(0, import_utils23.equalBytes)(leaf.refundTx, operatorLeaf.refundTx)) {
28972
+ ) || !(0, import_utils24.equalBytes)(leaf.nodeTx, operatorLeaf.nodeTx) || !(0, import_utils24.equalBytes)(leaf.refundTx, operatorLeaf.refundTx)) {
28525
28973
  leavesToIgnore.add(nodeId);
28526
28974
  }
28527
28975
  }
@@ -28529,7 +28977,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28529
28977
  }
28530
28978
  }
28531
28979
  const verifyKey = (pubkey1, pubkey2, verifyingKey) => {
28532
- return (0, import_utils23.equalBytes)(addPublicKeys(pubkey1, pubkey2), verifyingKey);
28980
+ return (0, import_utils24.equalBytes)(addPublicKeys(pubkey1, pubkey2), verifyingKey);
28533
28981
  };
28534
28982
  for (const [id, leaf] of Object.entries(leaves.nodes)) {
28535
28983
  if (!verifyKey(
@@ -28663,7 +29111,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28663
29111
  * @returns {Promise<string>} The identity public key as a hex string.
28664
29112
  */
28665
29113
  async getIdentityPublicKey() {
28666
- return (0, import_utils23.bytesToHex)(await this.config.signer.getIdentityPublicKey());
29114
+ return (0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey());
28667
29115
  }
28668
29116
  /**
28669
29117
  * Gets the Spark address of the wallet.
@@ -28673,7 +29121,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28673
29121
  async getSparkAddress() {
28674
29122
  if (!this.sparkAddress) {
28675
29123
  this.sparkAddress = encodeSparkAddress({
28676
- identityPublicKey: (0, import_utils23.bytesToHex)(
29124
+ identityPublicKey: (0, import_utils24.bytesToHex)(
28677
29125
  await this.config.signer.getIdentityPublicKey()
28678
29126
  ),
28679
29127
  network: this.config.getNetworkType()
@@ -28710,14 +29158,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28710
29158
  isValidPublicKey(assetIdentifier);
28711
29159
  }
28712
29160
  const paymentRequest = encodeSparkAddress({
28713
- identityPublicKey: (0, import_utils23.bytesToHex)(
29161
+ identityPublicKey: (0, import_utils24.bytesToHex)(
28714
29162
  await this.config.signer.getIdentityPublicKey()
28715
29163
  ),
28716
29164
  network: this.config.getNetworkType(),
28717
29165
  paymentIntentFields: {
28718
29166
  id: (0, import_uuidv75.uuidv7obj)().bytes,
28719
- assetIdentifier: assetIdentifier ? (0, import_utils23.hexToBytes)(assetIdentifier) : void 0,
28720
- assetAmount: (0, import_utils23.numberToVarBytesBE)(assetAmount),
29167
+ assetIdentifier: assetIdentifier ? (0, import_utils24.hexToBytes)(assetIdentifier) : void 0,
29168
+ assetAmount: (0, import_utils24.numberToVarBytesBE)(assetAmount),
28721
29169
  memo
28722
29170
  }
28723
29171
  });
@@ -28762,12 +29210,12 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28762
29210
  mnemonic = mnemonicOrSeed;
28763
29211
  seed = await this.config.signer.mnemonicToSeed(mnemonicOrSeed);
28764
29212
  } else {
28765
- seed = (0, import_utils23.hexToBytes)(mnemonicOrSeed);
29213
+ seed = (0, import_utils24.hexToBytes)(mnemonicOrSeed);
28766
29214
  }
28767
29215
  }
28768
29216
  await this.initWalletFromSeed(seed, accountNumber);
28769
29217
  const network = this.config.getNetwork();
28770
- this.lrc20Wallet = await import_lrc20_sdk3.LRCWallet.create(
29218
+ this.lrc20Wallet = await import_lrc20_sdk4.LRCWallet.create(
28771
29219
  LRC_WALLET_NETWORK[network],
28772
29220
  LRC_WALLET_NETWORK_TYPE[network],
28773
29221
  this.config.lrc20ApiConfig,
@@ -28867,7 +29315,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28867
29315
  );
28868
29316
  const { transfer, signatureMap } = await this.transferService.startSwapSignRefund(
28869
29317
  leafKeyTweaks,
28870
- (0, import_utils23.hexToBytes)(this.config.getSspIdentityPublicKey()),
29318
+ (0, import_utils24.hexToBytes)(this.config.getSspIdentityPublicKey()),
28871
29319
  new Date(Date.now() + 2 * 60 * 1e3)
28872
29320
  );
28873
29321
  try {
@@ -28885,10 +29333,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28885
29333
  const userLeaves = [];
28886
29334
  userLeaves.push({
28887
29335
  leaf_id: transfer.leaves[0].leaf.id,
28888
- raw_unsigned_refund_transaction: (0, import_utils23.bytesToHex)(
29336
+ raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
28889
29337
  transfer.leaves[0].intermediateRefundTx
28890
29338
  ),
28891
- adaptor_added_signature: (0, import_utils23.bytesToHex)(adaptorSignature)
29339
+ adaptor_added_signature: (0, import_utils24.bytesToHex)(adaptorSignature)
28892
29340
  });
28893
29341
  for (let i = 1; i < transfer.leaves.length; i++) {
28894
29342
  const leaf = transfer.leaves[i];
@@ -28905,14 +29353,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28905
29353
  );
28906
29354
  userLeaves.push({
28907
29355
  leaf_id: leaf.leaf.id,
28908
- raw_unsigned_refund_transaction: (0, import_utils23.bytesToHex)(
29356
+ raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
28909
29357
  leaf.intermediateRefundTx
28910
29358
  ),
28911
- adaptor_added_signature: (0, import_utils23.bytesToHex)(signature)
29359
+ adaptor_added_signature: (0, import_utils24.bytesToHex)(signature)
28912
29360
  });
28913
29361
  }
28914
29362
  const sspClient = this.getSspClient();
28915
- const adaptorPubkey = (0, import_utils23.bytesToHex)(
29363
+ const adaptorPubkey = (0, import_utils24.bytesToHex)(
28916
29364
  import_secp256k116.secp256k1.getPublicKey(adaptorPrivateKey)
28917
29365
  );
28918
29366
  let request = null;
@@ -28953,12 +29401,12 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28953
29401
  throw new Error(`Leaf not found for node ${nodeId}`);
28954
29402
  }
28955
29403
  const nodeTx = getTxFromRawTxBytes(node.nodeTx);
28956
- const refundTxBytes = (0, import_utils23.hexToBytes)(leaf.rawUnsignedRefundTransaction);
29404
+ const refundTxBytes = (0, import_utils24.hexToBytes)(leaf.rawUnsignedRefundTransaction);
28957
29405
  const refundTx = getTxFromRawTxBytes(refundTxBytes);
28958
29406
  const sighash = getSigHashFromTx(refundTx, 0, nodeTx.getOutput(0));
28959
29407
  const nodePublicKey = node.verifyingPublicKey;
28960
29408
  const taprootKey = computeTaprootKeyNoScript(nodePublicKey.slice(1));
28961
- const adaptorSignatureBytes = (0, import_utils23.hexToBytes)(leaf.adaptorSignedSignature);
29409
+ const adaptorSignatureBytes = (0, import_utils24.hexToBytes)(leaf.adaptorSignedSignature);
28962
29410
  applyAdaptorToSignature(
28963
29411
  taprootKey.slice(1),
28964
29412
  sighash,
@@ -28972,7 +29420,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28972
29420
  signatureMap
28973
29421
  );
28974
29422
  const completeResponse = await sspClient.completeLeaveSwap({
28975
- adaptorSecretKey: (0, import_utils23.bytesToHex)(adaptorPrivateKey),
29423
+ adaptorSecretKey: (0, import_utils24.bytesToHex)(adaptorPrivateKey),
28976
29424
  userOutboundTransferExternalId: transfer.id,
28977
29425
  leavesSwapRequestId: request.id
28978
29426
  });
@@ -28998,7 +29446,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
28998
29446
  limit,
28999
29447
  offset
29000
29448
  );
29001
- const identityPublicKey = (0, import_utils23.bytesToHex)(
29449
+ const identityPublicKey = (0, import_utils24.bytesToHex)(
29002
29450
  await this.config.signer.getIdentityPublicKey()
29003
29451
  );
29004
29452
  return {
@@ -29019,14 +29467,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29019
29467
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
29020
29468
  const { balance, tokenBalances } = await this.getBalance();
29021
29469
  const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
29022
- publicKeys: Array.from(tokenBalances.keys()).map(import_utils23.hexToBytes)
29470
+ publicKeys: Array.from(tokenBalances.keys()).map(import_utils24.hexToBytes)
29023
29471
  });
29024
29472
  return tokenInfo.tokenPubkeyInfos.map((info) => ({
29025
- tokenPublicKey: (0, import_utils23.bytesToHex)(info.announcement.publicKey.publicKey),
29473
+ tokenPublicKey: (0, import_utils24.bytesToHex)(info.announcement.publicKey.publicKey),
29026
29474
  tokenName: info.announcement.name,
29027
29475
  tokenSymbol: info.announcement.symbol,
29028
- tokenDecimals: Number((0, import_utils23.bytesToNumberBE)(info.announcement.decimal)),
29029
- maxSupply: (0, import_utils23.bytesToNumberBE)(info.announcement.maxSupply)
29476
+ tokenDecimals: Number((0, import_utils24.bytesToNumberBE)(info.announcement.decimal)),
29477
+ maxSupply: (0, import_utils24.bytesToNumberBE)(info.announcement.maxSupply)
29030
29478
  }));
29031
29479
  }
29032
29480
  /**
@@ -29055,11 +29503,11 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29055
29503
  async getTokenBalance() {
29056
29504
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
29057
29505
  const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
29058
- publicKeys: Array.from(this.tokenOutputs.keys()).map(import_utils23.hexToBytes)
29506
+ publicKeys: Array.from(this.tokenOutputs.keys()).map(import_utils24.hexToBytes)
29059
29507
  });
29060
29508
  const result = /* @__PURE__ */ new Map();
29061
29509
  for (const info of tokenInfo.tokenPubkeyInfos) {
29062
- const tokenPublicKey = (0, import_utils23.bytesToHex)(
29510
+ const tokenPublicKey = (0, import_utils24.bytesToHex)(
29063
29511
  info.announcement.publicKey.publicKey
29064
29512
  );
29065
29513
  const leaves = this.tokenOutputs.get(tokenPublicKey);
@@ -29069,8 +29517,8 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29069
29517
  tokenPublicKey,
29070
29518
  tokenName: info.announcement.name,
29071
29519
  tokenSymbol: info.announcement.symbol,
29072
- tokenDecimals: Number((0, import_utils23.bytesToNumberBE)(info.announcement.decimal)),
29073
- maxSupply: (0, import_utils23.bytesToNumberBE)(info.announcement.maxSupply)
29520
+ tokenDecimals: Number((0, import_utils24.bytesToNumberBE)(info.announcement.decimal)),
29521
+ maxSupply: (0, import_utils24.bytesToNumberBE)(info.announcement.maxSupply)
29074
29522
  }
29075
29523
  });
29076
29524
  }
@@ -29204,7 +29652,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29204
29652
  if (network === BitcoinNetwork_default.FUTURE_VALUE) {
29205
29653
  network = BitcoinNetwork_default.REGTEST;
29206
29654
  }
29207
- const depositSecretKey = (0, import_utils23.bytesToHex)(
29655
+ const depositSecretKey = (0, import_utils24.bytesToHex)(
29208
29656
  await this.config.signer.getStaticDepositSecretKey(0)
29209
29657
  );
29210
29658
  const message = await this.getStaticDepositSigningPayload(
@@ -29217,7 +29665,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29217
29665
  );
29218
29666
  const hashBuffer = (0, import_sha213.sha256)(message);
29219
29667
  const signatureBytes = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
29220
- const signature = (0, import_utils23.bytesToHex)(signatureBytes);
29668
+ const signature = (0, import_utils24.bytesToHex)(signatureBytes);
29221
29669
  const response = await this.sspClient.claimStaticDeposit({
29222
29670
  transactionId,
29223
29671
  outputIndex,
@@ -29302,7 +29750,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29302
29750
  networkJSON.toLowerCase(),
29303
29751
  2 /* Refund */,
29304
29752
  creditAmountSats,
29305
- (0, import_utils23.bytesToHex)(spendTxSighash)
29753
+ (0, import_utils24.bytesToHex)(spendTxSighash)
29306
29754
  );
29307
29755
  const hashBuffer = (0, import_sha213.sha256)(message);
29308
29756
  const swapResponseUserSignature = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
@@ -29312,7 +29760,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29312
29760
  const transferId = (0, import_uuidv75.uuidv7)();
29313
29761
  const swapResponse = await sparkClient.initiate_utxo_swap({
29314
29762
  onChainUtxo: {
29315
- txid: (0, import_utils23.hexToBytes)(depositTransactionId),
29763
+ txid: (0, import_utils24.hexToBytes)(depositTransactionId),
29316
29764
  vout: outputIndex,
29317
29765
  network: networkType
29318
29766
  },
@@ -29389,7 +29837,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29389
29837
  creditAmountView.setUint32(0, lowerHalf, true);
29390
29838
  creditAmountView.setUint32(4, upperHalf, true);
29391
29839
  parts.push(new Uint8Array(creditAmountBuffer));
29392
- parts.push((0, import_utils23.hexToBytes)(sspSignature));
29840
+ parts.push((0, import_utils24.hexToBytes)(sspSignature));
29393
29841
  const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
29394
29842
  const payload = new Uint8Array(totalLength);
29395
29843
  let offset = 0;
@@ -29739,9 +30187,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29739
30187
  this.config.getNetworkType()
29740
30188
  );
29741
30189
  const signerIdentityPublicKey = await this.config.signer.getIdentityPublicKey();
29742
- const isSelfTransfer = (0, import_utils23.equalBytes)(
30190
+ const isSelfTransfer = (0, import_utils24.equalBytes)(
29743
30191
  signerIdentityPublicKey,
29744
- (0, import_utils23.hexToBytes)(receiverAddress.identityPublicKey)
30192
+ (0, import_utils24.hexToBytes)(receiverAddress.identityPublicKey)
29745
30193
  );
29746
30194
  return await this.withLeaves(async () => {
29747
30195
  let leavesToSend = await this.selectLeaves(amountSats);
@@ -29758,7 +30206,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29758
30206
  );
29759
30207
  const transfer = await this.transferService.sendTransferWithKeyTweaks(
29760
30208
  leafKeyTweaks,
29761
- (0, import_utils23.hexToBytes)(receiverAddress.identityPublicKey)
30209
+ (0, import_utils24.hexToBytes)(receiverAddress.identityPublicKey)
29762
30210
  );
29763
30211
  const leavesToRemove = new Set(leavesToSend.map((leaf) => leaf.id));
29764
30212
  this.leaves = this.leaves.filter((leaf) => !leavesToRemove.has(leaf.id));
@@ -29774,7 +30222,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29774
30222
  }
29775
30223
  return mapTransferToWalletTransfer(
29776
30224
  transfer,
29777
- (0, import_utils23.bytesToHex)(await this.config.signer.getIdentityPublicKey())
30225
+ (0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey())
29778
30226
  );
29779
30227
  });
29780
30228
  }
@@ -30098,7 +30546,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30098
30546
  const invoice2 = await sspClient.requestLightningReceive({
30099
30547
  amountSats: amountSats2,
30100
30548
  network: bitcoinNetwork,
30101
- paymentHash: (0, import_utils23.bytesToHex)(paymentHash),
30549
+ paymentHash: (0, import_utils24.bytesToHex)(paymentHash),
30102
30550
  expirySecs: expirySeconds,
30103
30551
  memo: memo2,
30104
30552
  includeSparkAddress,
@@ -30112,7 +30560,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30112
30560
  const sparkFallbackAddress = decodeInvoice(
30113
30561
  invoice2.invoice.encodedInvoice
30114
30562
  ).fallbackAddress;
30115
- if (sparkFallbackAddress && isValidSparkFallback((0, import_utils23.hexToBytes)(sparkFallbackAddress))) {
30563
+ if (sparkFallbackAddress && isValidSparkFallback((0, import_utils24.hexToBytes)(sparkFallbackAddress))) {
30116
30564
  const invoiceIdentityPubkey = sparkFallbackAddress.slice(6);
30117
30565
  const expectedIdentityPubkey = receiverIdentityPubkey2 ?? await this.getIdentityPublicKey();
30118
30566
  if (invoiceIdentityPubkey !== expectedIdentityPubkey) {
@@ -30153,12 +30601,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30153
30601
  * @param {Object} params - Parameters for paying the invoice
30154
30602
  * @param {string} params.invoice - The BOLT11-encoded Lightning invoice to pay
30155
30603
  * @param {boolean} [params.preferSpark] - Whether to prefer a spark transfer over lightning for the payment
30604
+ * @param {number} [params.amountSatsToSend] - The amount in sats to send. This is only valid for 0 amount lightning invoices.
30156
30605
  * @returns {Promise<LightningSendRequest>} The Lightning payment request details
30157
30606
  */
30158
30607
  async payLightningInvoice({
30159
30608
  invoice,
30160
30609
  maxFeeSats,
30161
- preferSpark = false
30610
+ preferSpark = false,
30611
+ amountSatsToSend
30162
30612
  }) {
30163
30613
  const invoiceNetwork = getNetworkFromInvoice(invoice);
30164
30614
  const walletNetwork = this.config.getNetwork();
@@ -30173,11 +30623,40 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30173
30623
  );
30174
30624
  }
30175
30625
  const decodedInvoice = decodeInvoice(invoice);
30176
- const amountSats = decodedInvoice.amountMSats !== null ? Number(decodedInvoice.amountMSats / 1000n) : 0;
30626
+ const amountMSats = decodedInvoice.amountMSats;
30627
+ const isZeroAmountInvoice = !amountMSats;
30628
+ if (!isZeroAmountInvoice && amountSatsToSend !== void 0) {
30629
+ throw new ValidationError(
30630
+ "Invalid amount. User can only specify amountSatsToSend for 0 amount lightning invoice",
30631
+ {
30632
+ field: "amountMSats",
30633
+ value: Number(amountMSats),
30634
+ expected: "0"
30635
+ }
30636
+ );
30637
+ }
30638
+ if (isZeroAmountInvoice && amountSatsToSend === void 0) {
30639
+ throw new ValidationError(
30640
+ "Invalid amount. User must specify amountSatsToSend for 0 amount lightning invoice",
30641
+ {
30642
+ field: "amountMSats",
30643
+ value: Number(amountMSats),
30644
+ expected: "0"
30645
+ }
30646
+ );
30647
+ }
30648
+ const amountSats = isZeroAmountInvoice ? amountSatsToSend : Number(amountMSats / 1000n);
30649
+ if (isNaN(amountSats) || amountSats <= 0) {
30650
+ throw new ValidationError("Invalid amount", {
30651
+ field: "amountSats",
30652
+ value: amountSats,
30653
+ expected: "greater than 0"
30654
+ });
30655
+ }
30177
30656
  const sparkFallbackAddress = decodedInvoice.fallbackAddress;
30178
30657
  const paymentHash = decodedInvoice.paymentHash;
30179
30658
  if (preferSpark) {
30180
- if (sparkFallbackAddress === void 0 || isValidSparkFallback((0, import_utils23.hexToBytes)(sparkFallbackAddress)) === false) {
30659
+ if (sparkFallbackAddress === void 0 || isValidSparkFallback((0, import_utils24.hexToBytes)(sparkFallbackAddress)) === false) {
30181
30660
  console.warn(
30182
30661
  "No valid spark address found in invoice. Defaulting to lightning."
30183
30662
  );
@@ -30195,15 +30674,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30195
30674
  }
30196
30675
  return await this.withLeaves(async () => {
30197
30676
  const sspClient = this.getSspClient();
30198
- if (isNaN(amountSats) || amountSats <= 0) {
30199
- throw new ValidationError("Invalid amount", {
30200
- field: "amountSats",
30201
- value: amountSats,
30202
- expected: "positive number"
30203
- });
30204
- }
30205
30677
  const feeEstimate = await this.getLightningSendFeeEstimate({
30206
- encodedInvoice: invoice
30678
+ encodedInvoice: invoice,
30679
+ amountSats: isZeroAmountInvoice ? amountSatsToSend : void 0
30207
30680
  });
30208
30681
  if (maxFeeSats < feeEstimate) {
30209
30682
  throw new ValidationError("maxFeeSats does not cover fee estimate", {
@@ -30235,25 +30708,27 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30235
30708
  );
30236
30709
  const swapResponse = await this.lightningService.swapNodesForPreimage({
30237
30710
  leaves: leavesToSend,
30238
- receiverIdentityPubkey: (0, import_utils23.hexToBytes)(
30711
+ receiverIdentityPubkey: (0, import_utils24.hexToBytes)(
30239
30712
  this.config.getSspIdentityPublicKey()
30240
30713
  ),
30241
- paymentHash: (0, import_utils23.hexToBytes)(paymentHash),
30714
+ paymentHash: (0, import_utils24.hexToBytes)(paymentHash),
30242
30715
  isInboundPayment: false,
30243
30716
  invoiceString: invoice,
30244
- feeSats: feeEstimate
30717
+ feeSats: feeEstimate,
30718
+ amountSatsToSend
30245
30719
  });
30246
30720
  if (!swapResponse.transfer) {
30247
30721
  throw new Error("Failed to swap nodes for preimage");
30248
30722
  }
30249
- const transfer = await this.transferService.sendTransferTweakKey(
30723
+ await this.transferService.deliverTransferPackage(
30250
30724
  swapResponse.transfer,
30251
30725
  leavesToSend,
30252
30726
  /* @__PURE__ */ new Map()
30253
30727
  );
30254
30728
  const sspResponse = await sspClient.requestLightningSend({
30255
30729
  encodedInvoice: invoice,
30256
- idempotencyKey: paymentHash
30730
+ idempotencyKey: paymentHash,
30731
+ amountSats: isZeroAmountInvoice ? amountSatsToSend : void 0
30257
30732
  });
30258
30733
  if (!sspResponse) {
30259
30734
  throw new Error("Failed to contact SSP");
@@ -30270,14 +30745,18 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30270
30745
  * @returns {Promise<number>} Fee estimate for sending Lightning payments
30271
30746
  */
30272
30747
  async getLightningSendFeeEstimate({
30273
- encodedInvoice
30748
+ encodedInvoice,
30749
+ amountSats
30274
30750
  }) {
30275
30751
  const sspClient = this.getSspClient();
30276
- const feeEstimate = await sspClient.getLightningSendFeeEstimate(encodedInvoice);
30752
+ const feeEstimate = await sspClient.getLightningSendFeeEstimate(
30753
+ encodedInvoice,
30754
+ amountSats
30755
+ );
30277
30756
  if (!feeEstimate) {
30278
30757
  throw new Error("Failed to get lightning send fee estimate");
30279
30758
  }
30280
- const satsFeeEstimate = (0, import_core12.mapCurrencyAmount)(feeEstimate.feeEstimate);
30759
+ const satsFeeEstimate = (0, import_core14.mapCurrencyAmount)(feeEstimate.feeEstimate);
30281
30760
  return Math.ceil(satsFeeEstimate.sats);
30282
30761
  }
30283
30762
  // ***** Tree Creation Flow *****
@@ -30435,11 +30914,11 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30435
30914
  const connectorOutputs = [];
30436
30915
  for (let i = 0; i < connectorTx.outputsLength - 1; i++) {
30437
30916
  connectorOutputs.push({
30438
- txid: (0, import_utils23.hexToBytes)(connectorTxId),
30917
+ txid: (0, import_utils24.hexToBytes)(connectorTxId),
30439
30918
  index: i
30440
30919
  });
30441
30920
  }
30442
- const sspPubIdentityKey = (0, import_utils23.hexToBytes)(this.config.getSspIdentityPublicKey());
30921
+ const sspPubIdentityKey = (0, import_utils24.hexToBytes)(this.config.getSspIdentityPublicKey());
30443
30922
  const transfer = await this.coopExitService.getConnectorRefundSignatures({
30444
30923
  leaves: leafKeyTweaks,
30445
30924
  exitTxId: coopExitTxId,
@@ -30526,7 +31005,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30526
31005
  );
30527
31006
  const groupedOutputs = /* @__PURE__ */ new Map();
30528
31007
  filteredTokenOutputs.forEach((output) => {
30529
- const tokenKey = (0, import_utils23.bytesToHex)(output.output.tokenPublicKey);
31008
+ const tokenKey = (0, import_utils24.bytesToHex)(output.output.tokenPublicKey);
30530
31009
  const index = output.previousTransactionVout;
30531
31010
  if (!groupedOutputs.has(tokenKey)) {
30532
31011
  groupedOutputs.set(tokenKey, []);
@@ -30624,14 +31103,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30624
31103
  let queryParams;
30625
31104
  if (tokenTransactionHashes?.length) {
30626
31105
  queryParams = {
30627
- tokenPublicKeys: tokenPublicKeys?.map(import_utils23.hexToBytes),
30628
- ownerPublicKeys: [(0, import_utils23.hexToBytes)(await this.getIdentityPublicKey())],
30629
- tokenTransactionHashes: tokenTransactionHashes.map(import_utils23.hexToBytes)
31106
+ tokenPublicKeys: tokenPublicKeys?.map(import_utils24.hexToBytes),
31107
+ ownerPublicKeys: [(0, import_utils24.hexToBytes)(await this.getIdentityPublicKey())],
31108
+ tokenTransactionHashes: tokenTransactionHashes.map(import_utils24.hexToBytes)
30630
31109
  };
30631
31110
  } else {
30632
31111
  queryParams = {
30633
- tokenPublicKeys: tokenPublicKeys?.map(import_utils23.hexToBytes),
30634
- ownerPublicKeys: [(0, import_utils23.hexToBytes)(await this.getIdentityPublicKey())]
31112
+ tokenPublicKeys: tokenPublicKeys?.map(import_utils24.hexToBytes),
31113
+ ownerPublicKeys: [(0, import_utils24.hexToBytes)(await this.getIdentityPublicKey())]
30635
31114
  };
30636
31115
  }
30637
31116
  const response = await sparkClient.query_token_transactions(queryParams);
@@ -30656,7 +31135,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30656
31135
  hash,
30657
31136
  compact
30658
31137
  );
30659
- return (0, import_utils23.bytesToHex)(signature);
31138
+ return (0, import_utils24.bytesToHex)(signature);
30660
31139
  }
30661
31140
  /**
30662
31141
  * Validates a message with the identity key.
@@ -30668,7 +31147,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30668
31147
  async validateMessageWithIdentityKey(message, signature) {
30669
31148
  const hash = (0, import_sha213.sha256)(message);
30670
31149
  if (typeof signature === "string") {
30671
- signature = (0, import_utils23.hexToBytes)(signature);
31150
+ signature = (0, import_utils24.hexToBytes)(signature);
30672
31151
  }
30673
31152
  return this.config.signer.validateMessageWithIdentityKey(hash, signature);
30674
31153
  }
@@ -30681,7 +31160,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30681
31160
  */
30682
31161
  async signTransaction(txHex, keyType = "auto-detect") {
30683
31162
  try {
30684
- const tx = import_btc_signer7.Transaction.fromRaw((0, import_utils23.hexToBytes)(txHex));
31163
+ const tx = import_btc_signer7.Transaction.fromRaw((0, import_utils24.hexToBytes)(txHex));
30685
31164
  let publicKey;
30686
31165
  switch (keyType.toLowerCase()) {
30687
31166
  case "identity":
@@ -30714,7 +31193,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30714
31193
  publicKey,
30715
31194
  this.config.getNetwork()
30716
31195
  );
30717
- if ((0, import_utils23.bytesToHex)(script) === (0, import_utils23.bytesToHex)(identityScript)) {
31196
+ if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(identityScript)) {
30718
31197
  try {
30719
31198
  this.config.signer.signTransactionIndex(tx, i, publicKey);
30720
31199
  inputsSigned++;
@@ -30758,13 +31237,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30758
31237
  depositPubKey,
30759
31238
  this.config.getNetwork()
30760
31239
  );
30761
- if ((0, import_utils23.bytesToHex)(script) === (0, import_utils23.bytesToHex)(identityScript)) {
31240
+ if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(identityScript)) {
30762
31241
  return {
30763
31242
  publicKey: identityPubKey,
30764
31243
  keyType: "identity"
30765
31244
  };
30766
31245
  }
30767
- if ((0, import_utils23.bytesToHex)(script) === (0, import_utils23.bytesToHex)(depositScript)) {
31246
+ if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(depositScript)) {
30768
31247
  return {
30769
31248
  publicKey: depositPubKey,
30770
31249
  keyType: "deposit"
@@ -31159,7 +31638,7 @@ init_buffer();
31159
31638
 
31160
31639
  // src/utils/unilateral-exit.ts
31161
31640
  init_buffer();
31162
- var import_utils24 = require("@noble/curves/abstract/utils");
31641
+ var import_utils25 = require("@noble/curves/abstract/utils");
31163
31642
  var import_legacy = require("@noble/hashes/legacy");
31164
31643
  var import_sha214 = require("@noble/hashes/sha2");
31165
31644
  var btc5 = __toESM(require("@scure/btc-signer"), 1);
@@ -31174,7 +31653,7 @@ function isEphemeralAnchorOutput(script, amount) {
31174
31653
  }
31175
31654
  async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network) {
31176
31655
  const result = [];
31177
- const nodes = nodeHexStrings.map((hex) => TreeNode.decode((0, import_utils24.hexToBytes)(hex)));
31656
+ const nodes = nodeHexStrings.map((hex) => TreeNode.decode((0, import_utils25.hexToBytes)(hex)));
31178
31657
  const nodeMap = /* @__PURE__ */ new Map();
31179
31658
  for (const node of nodes) {
31180
31659
  nodeMap.set(node.id, node);
@@ -31230,10 +31709,10 @@ async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network)
31230
31709
  }
31231
31710
  }
31232
31711
  for (const chainNode of chain) {
31233
- const nodeTx = (0, import_utils24.bytesToHex)(chainNode.nodeTx);
31712
+ const nodeTx = (0, import_utils25.bytesToHex)(chainNode.nodeTx);
31234
31713
  transactions.push(nodeTx);
31235
31714
  if (chainNode.id === node.id) {
31236
- const refundTx = (0, import_utils24.bytesToHex)(chainNode.refundTx);
31715
+ const refundTx = (0, import_utils25.bytesToHex)(chainNode.refundTx);
31237
31716
  transactions.push(refundTx);
31238
31717
  }
31239
31718
  }
@@ -31263,7 +31742,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
31263
31742
  `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.`
31264
31743
  );
31265
31744
  }
31266
- const nodeBytes = (0, import_utils24.hexToBytes)(hex);
31745
+ const nodeBytes = (0, import_utils25.hexToBytes)(hex);
31267
31746
  const node = TreeNode.decode(nodeBytes);
31268
31747
  if (!node.id) {
31269
31748
  throw new Error(
@@ -31339,7 +31818,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
31339
31818
  }
31340
31819
  }
31341
31820
  for (const chainNode of chain) {
31342
- let nodeTxHex = (0, import_utils24.bytesToHex)(chainNode.nodeTx);
31821
+ let nodeTxHex = (0, import_utils25.bytesToHex)(chainNode.nodeTx);
31343
31822
  try {
31344
31823
  const txObj = getTxFromRawTxHex(nodeTxHex);
31345
31824
  const txid = getTxId(txObj);
@@ -31356,7 +31835,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
31356
31835
  for (let i = txObj.outputsLength - 1; i >= 0; i--) {
31357
31836
  const output = txObj.getOutput(i);
31358
31837
  if (output?.amount === 0n && output.script) {
31359
- anchorOutputScriptHex = (0, import_utils24.bytesToHex)(output.script);
31838
+ anchorOutputScriptHex = (0, import_utils25.bytesToHex)(output.script);
31360
31839
  break;
31361
31840
  }
31362
31841
  }
@@ -31377,11 +31856,11 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
31377
31856
  usedUtxos,
31378
31857
  correctedParentTx
31379
31858
  } = constructFeeBumpTx(nodeTxHex, availableUtxos, feeRate, void 0);
31380
- const feeBumpTx = btc5.Transaction.fromPSBT((0, import_utils24.hexToBytes)(nodeFeeBumpPsbt));
31859
+ const feeBumpTx = btc5.Transaction.fromPSBT((0, import_utils25.hexToBytes)(nodeFeeBumpPsbt));
31381
31860
  var feeBumpOut = feeBumpTx.outputsLength === 1 ? feeBumpTx.getOutput(0) : null;
31382
31861
  var feeBumpOutPubKey = null;
31383
31862
  for (const usedUtxo of usedUtxos) {
31384
- if (feeBumpOut && (0, import_utils24.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
31863
+ if (feeBumpOut && (0, import_utils25.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
31385
31864
  feeBumpOutPubKey = usedUtxo.publicKey;
31386
31865
  }
31387
31866
  const index = availableUtxos.findIndex(
@@ -31396,20 +31875,20 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
31396
31875
  txid: getTxId(feeBumpTx),
31397
31876
  vout: 0,
31398
31877
  value: feeBumpOut.amount,
31399
- script: (0, import_utils24.bytesToHex)(feeBumpOut.script),
31878
+ script: (0, import_utils25.bytesToHex)(feeBumpOut.script),
31400
31879
  publicKey: feeBumpOutPubKey
31401
31880
  });
31402
31881
  const finalNodeTx = correctedParentTx || nodeTxHex;
31403
31882
  txPackages.push({ tx: finalNodeTx, feeBumpPsbt: nodeFeeBumpPsbt });
31404
31883
  if (chainNode.id === node.id) {
31405
- let refundTxHex = (0, import_utils24.bytesToHex)(chainNode.refundTx);
31884
+ let refundTxHex = (0, import_utils25.bytesToHex)(chainNode.refundTx);
31406
31885
  try {
31407
31886
  const txObj = getTxFromRawTxHex(refundTxHex);
31408
31887
  let anchorOutputScriptHex;
31409
31888
  for (let i = txObj.outputsLength - 1; i >= 0; i--) {
31410
31889
  const output = txObj.getOutput(i);
31411
31890
  if (output?.amount === 0n && output.script) {
31412
- anchorOutputScriptHex = (0, import_utils24.bytesToHex)(output.script);
31891
+ anchorOutputScriptHex = (0, import_utils25.bytesToHex)(output.script);
31413
31892
  break;
31414
31893
  }
31415
31894
  }
@@ -31523,10 +32002,10 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
31523
32002
  if (!fundingUtxo) {
31524
32003
  throw new Error(`UTXO at index ${i} is undefined`);
31525
32004
  }
31526
- const pubKeyHash = hash160((0, import_utils24.hexToBytes)(fundingUtxo.publicKey));
32005
+ const pubKeyHash = hash160((0, import_utils25.hexToBytes)(fundingUtxo.publicKey));
31527
32006
  const scriptToUse = new Uint8Array([0, 20, ...pubKeyHash]);
31528
- const providedScript = (0, import_utils24.hexToBytes)(fundingUtxo.script);
31529
- if ((0, import_utils24.bytesToHex)(scriptToUse) !== (0, import_utils24.bytesToHex)(providedScript)) {
32007
+ const providedScript = (0, import_utils25.hexToBytes)(fundingUtxo.script);
32008
+ if ((0, import_utils25.bytesToHex)(scriptToUse) !== (0, import_utils25.bytesToHex)(providedScript)) {
31530
32009
  throw new Error(
31531
32010
  `\u274C Derived script doesn't match provided script for UTXO ${i + 1}.`
31532
32011
  );
@@ -31591,7 +32070,7 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
31591
32070
  }
31592
32071
  let psbtHex;
31593
32072
  try {
31594
- psbtHex = (0, import_utils24.bytesToHex)(builder.toPSBT());
32073
+ psbtHex = (0, import_utils25.bytesToHex)(builder.toPSBT());
31595
32074
  } catch (error) {
31596
32075
  throw new Error(`Failed to extract transaction: ${error}`);
31597
32076
  }
@@ -31664,6 +32143,7 @@ function getSparkAddressFromTaproot(taprootAddress) {
31664
32143
  constructFeeBumpTx,
31665
32144
  constructUnilateralExitFeeBumpPackages,
31666
32145
  constructUnilateralExitTxs,
32146
+ createDummyTx,
31667
32147
  createRefundTx,
31668
32148
  createSigningCommitment,
31669
32149
  createSigningNonce,