@buildonspark/spark-sdk 0.1.44 → 0.1.45

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 (143) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{RequestLightningSendInput-RGel43ks.d.ts → RequestLightningSendInput-DEPd_fPO.d.ts} +1 -1
  3. package/dist/{RequestLightningSendInput-BxbCtwpV.d.cts → RequestLightningSendInput-Du0z7Om7.d.cts} +1 -1
  4. package/dist/address/index.cjs +2 -2
  5. package/dist/address/index.d.cts +2 -2
  6. package/dist/address/index.d.ts +2 -2
  7. package/dist/address/index.js +2 -2
  8. package/dist/{chunk-XX4RRWOX.js → chunk-5FUB65LX.js} +5 -7
  9. package/dist/{chunk-DAXGVPVM.js → chunk-6264CGDM.js} +4 -4
  10. package/dist/{chunk-UBT6EDVJ.js → chunk-7V6N75CC.js} +1 -1
  11. package/dist/{chunk-4Q2ZDYYU.js → chunk-BGGEVUJK.js} +1157 -208
  12. package/dist/{chunk-CIZNCBKE.js → chunk-C2S227QR.js} +648 -45
  13. package/dist/{chunk-NBCNYDWJ.js → chunk-GZ5IPPJ2.js} +2 -2
  14. package/dist/{chunk-6AFUC5M2.js → chunk-HWJWKEIU.js} +8 -2
  15. package/dist/{chunk-A2ZLMH6I.js → chunk-J2IE4Z7Y.js} +231 -299
  16. package/dist/{chunk-KEKGSH7B.js → chunk-KMUMFYFX.js} +3 -3
  17. package/dist/chunk-LHRD2WT6.js +2374 -0
  18. package/dist/{chunk-SQKXGAIR.js → chunk-NTFKFRQ2.js} +1 -1
  19. package/dist/{chunk-K4BJARWM.js → chunk-OBFKIEMP.js} +1 -1
  20. package/dist/{chunk-WPTRVD2V.js → chunk-PQN3C2MF.js} +15 -15
  21. package/dist/{chunk-EKFD62HN.js → chunk-R5PXJZQS.js} +1 -0
  22. package/dist/{chunk-HTMXTJRK.js → chunk-YUPMXTCJ.js} +4 -4
  23. package/dist/graphql/objects/index.d.cts +5 -4
  24. package/dist/graphql/objects/index.d.ts +5 -4
  25. package/dist/index-B2AwKW5J.d.cts +214 -0
  26. package/dist/index-CJDi1HWc.d.ts +214 -0
  27. package/dist/index.cjs +4025 -1314
  28. package/dist/index.d.cts +764 -19
  29. package/dist/index.d.ts +764 -19
  30. package/dist/index.js +16 -20
  31. package/dist/index.node.cjs +4025 -1318
  32. package/dist/index.node.d.cts +10 -8
  33. package/dist/index.node.d.ts +10 -8
  34. package/dist/index.node.js +16 -24
  35. package/dist/native/index.cjs +4026 -1315
  36. package/dist/native/index.d.cts +281 -85
  37. package/dist/native/index.d.ts +281 -85
  38. package/dist/native/index.js +4017 -1306
  39. package/dist/{network-CroCOQ0B.d.ts → network-BTJl-Sul.d.ts} +1 -1
  40. package/dist/{network-CfxLnaot.d.cts → network-CqgsdUF2.d.cts} +1 -1
  41. package/dist/proto/lrc20.cjs +222 -19
  42. package/dist/proto/lrc20.d.cts +1 -1
  43. package/dist/proto/lrc20.d.ts +1 -1
  44. package/dist/proto/lrc20.js +2 -2
  45. package/dist/proto/spark.cjs +1154 -205
  46. package/dist/proto/spark.d.cts +1 -1
  47. package/dist/proto/spark.d.ts +1 -1
  48. package/dist/proto/spark.js +3 -1
  49. package/dist/proto/spark_token.cjs +1377 -58
  50. package/dist/proto/spark_token.d.cts +153 -15
  51. package/dist/proto/spark_token.d.ts +153 -15
  52. package/dist/proto/spark_token.js +40 -4
  53. package/dist/{sdk-types-BeCBoozO.d.cts → sdk-types-B0SwjolI.d.cts} +1 -1
  54. package/dist/{sdk-types-CTbTdDbE.d.ts → sdk-types-Cc4l4kb1.d.ts} +1 -1
  55. package/dist/services/config.cjs +1 -1
  56. package/dist/services/config.d.cts +5 -4
  57. package/dist/services/config.d.ts +5 -4
  58. package/dist/services/config.js +6 -6
  59. package/dist/services/connection.cjs +2438 -262
  60. package/dist/services/connection.d.cts +5 -4
  61. package/dist/services/connection.d.ts +5 -4
  62. package/dist/services/connection.js +4 -4
  63. package/dist/services/index.cjs +5936 -3153
  64. package/dist/services/index.d.cts +7 -6
  65. package/dist/services/index.d.ts +7 -6
  66. package/dist/services/index.js +15 -13
  67. package/dist/services/lrc-connection.cjs +223 -20
  68. package/dist/services/lrc-connection.d.cts +5 -4
  69. package/dist/services/lrc-connection.d.ts +5 -4
  70. package/dist/services/lrc-connection.js +4 -4
  71. package/dist/services/token-transactions.cjs +840 -236
  72. package/dist/services/token-transactions.d.cts +25 -7
  73. package/dist/services/token-transactions.d.ts +25 -7
  74. package/dist/services/token-transactions.js +5 -4
  75. package/dist/services/wallet-config.cjs +2 -0
  76. package/dist/services/wallet-config.d.cts +7 -5
  77. package/dist/services/wallet-config.d.ts +7 -5
  78. package/dist/services/wallet-config.js +3 -1
  79. package/dist/signer/signer.cjs +1 -1
  80. package/dist/signer/signer.d.cts +3 -2
  81. package/dist/signer/signer.d.ts +3 -2
  82. package/dist/signer/signer.js +2 -2
  83. package/dist/{signer-D7vfYik9.d.ts → signer-BocS_J6B.d.ts} +2 -6
  84. package/dist/{signer-DaY8c60s.d.cts → signer-DKS0AJkw.d.cts} +2 -6
  85. package/dist/{spark-C4ZrsgjC.d.cts → spark-dM7EYXYQ.d.cts} +93 -15
  86. package/dist/{spark-C4ZrsgjC.d.ts → spark-dM7EYXYQ.d.ts} +93 -15
  87. package/dist/spark_bindings/native/index.cjs +183 -0
  88. package/dist/spark_bindings/native/index.d.cts +14 -0
  89. package/dist/spark_bindings/native/index.d.ts +14 -0
  90. package/dist/spark_bindings/native/index.js +141 -0
  91. package/dist/spark_bindings/wasm/index.cjs +1093 -0
  92. package/dist/spark_bindings/wasm/index.d.cts +47 -0
  93. package/dist/spark_bindings/wasm/index.d.ts +47 -0
  94. package/dist/{chunk-K4C4W5FC.js → spark_bindings/wasm/index.js} +7 -6
  95. package/dist/types/index.cjs +1156 -208
  96. package/dist/types/index.d.cts +5 -4
  97. package/dist/types/index.d.ts +5 -4
  98. package/dist/types/index.js +2 -2
  99. package/dist/types-C-Rp0Oo7.d.cts +46 -0
  100. package/dist/types-C-Rp0Oo7.d.ts +46 -0
  101. package/dist/utils/index.cjs +64 -12
  102. package/dist/utils/index.d.cts +14 -134
  103. package/dist/utils/index.d.ts +14 -134
  104. package/dist/utils/index.js +7 -7
  105. package/package.json +21 -1
  106. package/src/index.node.ts +0 -1
  107. package/src/index.ts +0 -1
  108. package/src/native/index.ts +1 -2
  109. package/src/proto/common.ts +5 -5
  110. package/src/proto/google/protobuf/descriptor.ts +34 -34
  111. package/src/proto/google/protobuf/duration.ts +2 -2
  112. package/src/proto/google/protobuf/empty.ts +2 -2
  113. package/src/proto/google/protobuf/timestamp.ts +2 -2
  114. package/src/proto/mock.ts +4 -4
  115. package/src/proto/spark.ts +1452 -185
  116. package/src/proto/spark_authn.ts +7 -7
  117. package/src/proto/spark_token.ts +1668 -105
  118. package/src/proto/validate/validate.ts +24 -24
  119. package/src/services/bolt11-spark.ts +62 -187
  120. package/src/services/coop-exit.ts +3 -0
  121. package/src/services/lrc20.ts +1 -1
  122. package/src/services/token-transactions.ts +197 -9
  123. package/src/services/transfer.ts +22 -0
  124. package/src/services/tree-creation.ts +13 -0
  125. package/src/services/wallet-config.ts +1 -1
  126. package/src/spark-wallet/spark-wallet.node.ts +0 -4
  127. package/src/spark-wallet/spark-wallet.ts +76 -108
  128. package/src/spark-wallet/types.ts +39 -3
  129. package/src/tests/bolt11-spark.test.ts +7 -15
  130. package/src/tests/integration/ssp/coop-exit.test.ts +7 -7
  131. package/src/tests/integration/swap.test.ts +453 -433
  132. package/src/tests/integration/transfer.test.ts +261 -248
  133. package/src/tests/token-identifier.test.ts +54 -0
  134. package/src/tests/tokens.test.ts +218 -23
  135. package/src/utils/token-hashing.ts +320 -44
  136. package/src/utils/token-identifier.ts +88 -0
  137. package/src/utils/token-transaction-validation.ts +350 -5
  138. package/src/utils/token-transactions.ts +12 -8
  139. package/src/utils/transaction.ts +0 -6
  140. package/dist/chunk-B3AMIGJG.js +0 -1073
  141. package/dist/index-CZmDdSts.d.cts +0 -829
  142. package/dist/index-ClIRO_3y.d.ts +0 -829
  143. package/dist/wasm-7OWFHDMS.js +0 -21
@@ -1,12 +1,9 @@
1
- import {
2
- ConnectionManager
3
- } from "./chunk-WPTRVD2V.js";
4
1
  import {
5
2
  Lrc20ConnectionManager
6
- } from "./chunk-NBCNYDWJ.js";
3
+ } from "./chunk-GZ5IPPJ2.js";
7
4
  import {
8
5
  TokenTransactionService
9
- } from "./chunk-CIZNCBKE.js";
6
+ } from "./chunk-C2S227QR.js";
10
7
  import {
11
8
  DEFAULT_FEE_SATS,
12
9
  computeTaprootKeyNoScript,
@@ -23,14 +20,14 @@ import {
23
20
  getTxFromRawTxHex,
24
21
  getTxId,
25
22
  proofOfPossessionMessageHashForDepositAddress
26
- } from "./chunk-XX4RRWOX.js";
23
+ } from "./chunk-5FUB65LX.js";
27
24
  import {
28
25
  calculateAvailableTokenAmount
29
- } from "./chunk-6AFUC5M2.js";
26
+ } from "./chunk-HWJWKEIU.js";
30
27
  import {
31
28
  mapTransferToWalletTransfer,
32
29
  mapTreeNodeToWalletLeaf
33
- } from "./chunk-K4BJARWM.js";
30
+ } from "./chunk-OBFKIEMP.js";
34
31
  import {
35
32
  ClaimStaticDepositRequestType_default,
36
33
  CoopExitFeeQuoteFromJson,
@@ -52,10 +49,10 @@ import {
52
49
  decodeSparkAddress,
53
50
  encodeSparkAddress,
54
51
  isValidPublicKey
55
- } from "./chunk-KEKGSH7B.js";
52
+ } from "./chunk-KMUMFYFX.js";
56
53
  import {
57
54
  WalletConfigService
58
- } from "./chunk-DAXGVPVM.js";
55
+ } from "./chunk-6264CGDM.js";
59
56
  import {
60
57
  LRC_WALLET_NETWORK,
61
58
  LRC_WALLET_NETWORK_TYPE,
@@ -65,17 +62,7 @@ import {
65
62
  } from "./chunk-Z5HIAYFT.js";
66
63
  import {
67
64
  ELECTRS_CREDENTIALS
68
- } from "./chunk-EKFD62HN.js";
69
- import {
70
- BitcoinNetwork_default
71
- } from "./chunk-HMLOC6TE.js";
72
- import {
73
- SendLeafKeyTweaks,
74
- networkToJSON
75
- } from "./chunk-4Q2ZDYYU.js";
76
- import {
77
- isReactNative
78
- } from "./chunk-UBT6EDVJ.js";
65
+ } from "./chunk-R5PXJZQS.js";
79
66
  import {
80
67
  addPublicKeys,
81
68
  applyAdaptorToSignature,
@@ -86,6 +73,15 @@ import {
86
73
  import {
87
74
  getCrypto
88
75
  } from "./chunk-QNNSEJ4P.js";
76
+ import {
77
+ BitcoinNetwork_default
78
+ } from "./chunk-HMLOC6TE.js";
79
+ import {
80
+ ConnectionManager
81
+ } from "./chunk-PQN3C2MF.js";
82
+ import {
83
+ isReactNative
84
+ } from "./chunk-7V6N75CC.js";
89
85
  import {
90
86
  AuthenticationError,
91
87
  ConfigurationError,
@@ -93,6 +89,10 @@ import {
93
89
  RPCError,
94
90
  ValidationError
95
91
  } from "./chunk-GSI4OLXZ.js";
92
+ import {
93
+ SendLeafKeyTweaks,
94
+ networkToJSON
95
+ } from "./chunk-BGGEVUJK.js";
96
96
  import {
97
97
  Buffer
98
98
  } from "./chunk-MVRQ5US7.js";
@@ -106,7 +106,7 @@ import {
106
106
  hexToBytes as hexToBytes7,
107
107
  numberToVarBytesBE
108
108
  } from "@noble/curves/abstract/utils";
109
- import { secp256k1 as secp256k16 } from "@noble/curves/secp256k1";
109
+ import { secp256k1 as secp256k15 } from "@noble/curves/secp256k1";
110
110
  import { validateMnemonic } from "@scure/bip39";
111
111
  import { wordlist } from "@scure/bip39/wordlists/english";
112
112
  import { Address as Address4, OutScript as OutScript4, Transaction as Transaction6 } from "@scure/btc-signer";
@@ -1316,7 +1316,10 @@ var BaseTransferService = class {
1316
1316
  const transferPackage = {
1317
1317
  leavesToSend: leafSigningJobs,
1318
1318
  keyTweakPackage: encryptedKeyTweaks,
1319
- userSignature: new Uint8Array()
1319
+ userSignature: new Uint8Array(),
1320
+ // TODO: Add direct refund signature
1321
+ directLeavesToSend: [],
1322
+ directFromCpfpLeavesToSend: []
1320
1323
  };
1321
1324
  const transferPackageSigningPayload = getTransferPackageSigningPayload(
1322
1325
  transferID,
@@ -1415,7 +1418,11 @@ var BaseTransferService = class {
1415
1418
  nodeSignatures.push({
1416
1419
  nodeId: operatorSigningResult.leafId,
1417
1420
  refundTxSignature: refundAggregate,
1418
- nodeTxSignature: new Uint8Array()
1421
+ nodeTxSignature: new Uint8Array(),
1422
+ // TODO: Add direct refund signature
1423
+ directNodeTxSignature: new Uint8Array(),
1424
+ directRefundTxSignature: new Uint8Array(),
1425
+ directFromCpfpRefundTxSignature: new Uint8Array()
1419
1426
  });
1420
1427
  }
1421
1428
  return nodeSignatures;
@@ -1497,7 +1504,10 @@ var BaseTransferService = class {
1497
1504
  pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak),
1498
1505
  secretCipher,
1499
1506
  signature,
1500
- refundSignature: refundSignature ?? new Uint8Array()
1507
+ refundSignature: refundSignature ?? new Uint8Array(),
1508
+ // TODO: Add direct refund signature
1509
+ directRefundSignature: new Uint8Array(),
1510
+ directFromCpfpRefundSignature: new Uint8Array()
1501
1511
  });
1502
1512
  }
1503
1513
  return leafTweaksMap;
@@ -1779,7 +1789,11 @@ var TransferService = class extends BaseTransferService {
1779
1789
  signingPublicKey: refundSigningData.signingPubKey,
1780
1790
  rawTx: refundTx.toBytes(),
1781
1791
  signingNonceCommitment: refundNonceCommitmentProto
1782
- }
1792
+ },
1793
+ // TODO: Add direct refund signature
1794
+ directRefundTxSigningJob: void 0,
1795
+ // TODO: Add direct refund signature
1796
+ directFromCpfpRefundTxSigningJob: void 0
1783
1797
  });
1784
1798
  }
1785
1799
  return signingJobs;
@@ -2146,7 +2160,11 @@ var TransferService = class extends BaseTransferService {
2146
2160
  nodeSignatures.push({
2147
2161
  nodeId,
2148
2162
  nodeTxSignature: signature,
2149
- refundTxSignature: new Uint8Array()
2163
+ refundTxSignature: new Uint8Array(),
2164
+ // TODO: Add direct refund signature
2165
+ directNodeTxSignature: new Uint8Array(),
2166
+ directRefundTxSignature: new Uint8Array(),
2167
+ directFromCpfpRefundTxSignature: new Uint8Array()
2150
2168
  });
2151
2169
  } else if (i === nodes.length) {
2152
2170
  refundSignature = signature;
@@ -2161,7 +2179,11 @@ var TransferService = class extends BaseTransferService {
2161
2179
  nodeSignatures.push({
2162
2180
  nodeId: leafNodeId,
2163
2181
  nodeTxSignature: leafSignature,
2164
- refundTxSignature: refundSignature
2182
+ refundTxSignature: refundSignature,
2183
+ // TODO: Add direct refund signature
2184
+ directNodeTxSignature: new Uint8Array(),
2185
+ directRefundTxSignature: new Uint8Array(),
2186
+ directFromCpfpRefundTxSignature: new Uint8Array()
2165
2187
  });
2166
2188
  const result = await sparkClient.finalize_node_signatures({
2167
2189
  intent: 3 /* REFRESH */,
@@ -2478,7 +2500,10 @@ var CoopExitService = class extends BaseTransferService {
2478
2500
  signingPublicKey: leaf.signingPubKey,
2479
2501
  rawTx: refundTx.toBytes(),
2480
2502
  signingNonceCommitment
2481
- }
2503
+ },
2504
+ // TODO: Add direct refund signature
2505
+ directRefundTxSigningJob: void 0,
2506
+ directFromCpfpRefundTxSigningJob: void 0
2482
2507
  };
2483
2508
  signingJobs.push(signingJob);
2484
2509
  const tx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
@@ -2851,98 +2876,58 @@ import {
2851
2876
  hexToBytes as hexToBytes3,
2852
2877
  numberToBytesBE as numberToBytesBE2
2853
2878
  } from "@noble/curves/abstract/utils";
2854
- import { secp256k1 as secp256k14 } from "@noble/curves/secp256k1";
2855
- import { sha256 as sha2565 } from "@noble/hashes/sha2";
2879
+ import { secp256k1 as secp256k13 } from "@noble/curves/secp256k1";
2880
+ import { sha256 as sha2564 } from "@noble/hashes/sha2";
2856
2881
  import { uuidv7 as uuidv73 } from "uuidv7";
2857
2882
 
2858
2883
  // src/services/bolt11-spark.ts
2859
- import { bech32 } from "@scure/base";
2860
- import { sha256 as sha2564 } from "@noble/hashes/sha2";
2861
- import { secp256k1 as secp256k13 } from "@noble/curves/secp256k1";
2884
+ import { decode } from "light-bolt11-decoder";
2885
+ var RECEIVER_IDENTITY_PUBLIC_KEY_SHORT_CHANNEL_ID = "f42400f424000001";
2886
+ var PAYMENT_HASH_NAME = "payment_hash";
2887
+ var AMOUNT_MSATS_NAME = "amount";
2888
+ var PAYMENT_SECRET_NAME = "payment_secret";
2862
2889
  function decodeInvoice(invoice) {
2863
- const { words, prefix } = bech32.decode(
2864
- invoice,
2865
- 1e3
2866
- );
2867
- verifySignature(words, prefix);
2868
- const amountMSats = extractMillisatoshiAmountFromInvoice(invoice);
2869
- let fallbackAddress = void 0;
2870
- let paymentHash = void 0;
2871
- let paymentSecret = void 0;
2872
- let i = 7;
2873
- const tlvEnd = words.length - 105;
2874
- while (i + 2 < tlvEnd) {
2875
- const tag = words[i];
2876
- const len1 = words[i + 1];
2877
- const len2 = words[i + 2];
2878
- if (len1 === void 0 || len2 === void 0) {
2879
- console.log("No length word");
2880
- break;
2881
- }
2882
- const len = (len1 << 5) + len2;
2883
- const start = i + 3;
2884
- const end = start + len;
2885
- if (tag === 1) {
2886
- const hashWords = words.slice(start, end);
2887
- const hashBytes = bech32WordsToBytes(hashWords);
2888
- if (hashBytes.length === 32) {
2889
- paymentHash = Buffer.from(hashBytes).toString("hex");
2890
- }
2891
- } else if (tag === 9) {
2892
- const verWord = words[start];
2893
- if (verWord !== 31) {
2894
- console.warn("Not our custom version-31");
2895
- i = end;
2896
- continue;
2897
- }
2898
- const payloadWords = words.slice(start + 1, end);
2899
- const payloadBytes = bech32WordsToBytes(payloadWords);
2900
- fallbackAddress = Buffer.from(payloadBytes).toString("hex");
2901
- } else if (tag === 16) {
2902
- if (len !== 52) {
2903
- throw new ValidationError("Invalid payment secret length", {
2904
- field: "paymentSecret",
2905
- value: len,
2906
- expected: "52 words (32 bytes for 256-bit secret)"
2907
- });
2908
- }
2909
- const secretWords = words.slice(start, end);
2910
- const secretBytes = bech32WordsToBytes(secretWords);
2911
- if (secretBytes.length !== 32) {
2912
- throw new ValidationError("Invalid payment secret size", {
2913
- field: "paymentSecret",
2914
- value: secretBytes.length,
2915
- expected: "32 bytes (256 bits)"
2916
- });
2890
+ const decodedInvoice = decode(invoice);
2891
+ const network = getNetworkFromInvoice(invoice);
2892
+ if (network === null) {
2893
+ throw new ValidationError("Invalid network found in invoice: " + invoice);
2894
+ }
2895
+ let paymentSection;
2896
+ let routeHints = [];
2897
+ let amountSection;
2898
+ let paymentSecretSection;
2899
+ let fallbackAddress;
2900
+ for (const section of decodedInvoice.sections) {
2901
+ if (section.name === PAYMENT_HASH_NAME) {
2902
+ paymentSection = section;
2903
+ }
2904
+ if (section.name === AMOUNT_MSATS_NAME) {
2905
+ amountSection = section;
2906
+ }
2907
+ if (section.name === PAYMENT_SECRET_NAME) {
2908
+ paymentSecretSection = section;
2909
+ }
2910
+ }
2911
+ routeHints = decodedInvoice.route_hints;
2912
+ const amountMSats = amountSection?.value ? BigInt(amountSection.value) : null;
2913
+ const paymentHash = paymentSection?.value;
2914
+ for (const routeHintArray of routeHints) {
2915
+ for (const routeHint of routeHintArray) {
2916
+ if (routeHint.short_channel_id === RECEIVER_IDENTITY_PUBLIC_KEY_SHORT_CHANNEL_ID) {
2917
+ fallbackAddress = routeHint.pubkey;
2917
2918
  }
2918
- paymentSecret = Buffer.from(secretBytes).toString("hex");
2919
2919
  }
2920
- i = end;
2921
2920
  }
2922
2921
  if (paymentHash === void 0) {
2923
2922
  throw new ValidationError("No payment hash found in invoice: " + invoice);
2924
2923
  }
2925
- if (paymentSecret === void 0) {
2924
+ if (paymentSecretSection?.value === void 0) {
2926
2925
  throw new ValidationError(
2927
2926
  "Invalid payment secret found in invoice: " + invoice
2928
2927
  );
2929
2928
  }
2930
2929
  return { amountMSats, fallbackAddress, paymentHash };
2931
2930
  }
2932
- function bech32WordsToBytes(words) {
2933
- let acc = 0, bits = 0;
2934
- const out = [];
2935
- for (const w of words) {
2936
- if (w < 0 || w > 31) throw new Error(`bad word ${w}`);
2937
- acc = acc << 5 | w;
2938
- bits += 5;
2939
- while (bits >= 8) {
2940
- bits -= 8;
2941
- out.push(acc >> bits & 255);
2942
- }
2943
- }
2944
- return new Uint8Array(out);
2945
- }
2946
2931
  function getNetworkFromInvoice(invoice) {
2947
2932
  if (invoice.startsWith("lnbcrt")) return 3 /* REGTEST */;
2948
2933
  if (invoice.startsWith("lnbc")) return 0 /* MAINNET */;
@@ -2950,85 +2935,11 @@ function getNetworkFromInvoice(invoice) {
2950
2935
  if (invoice.startsWith("lnsb")) return 2 /* SIGNET */;
2951
2936
  return null;
2952
2937
  }
2953
- function extractMillisatoshiAmountFromInvoice(invoice) {
2954
- const match = invoice.match(/^ln[a-z]+(\d+)([a-z]?)1/);
2955
- if (!match) return null;
2956
- const [, amount, multiplier] = match;
2957
- if (!amount) return null;
2958
- const value = BigInt(amount);
2959
- const MILLISATS_PER_BTC = 100000000000n;
2960
- const divisors = {
2961
- m: 1000n,
2962
- u: 1000000n,
2963
- n: 1000000000n,
2964
- p: 10000000000000n
2965
- };
2966
- if (multiplier) {
2967
- if (!(multiplier in divisors)) {
2968
- throw new ValidationError(`Invalid multiplier: ${multiplier}`, {
2969
- field: "multiplier",
2970
- value: multiplier,
2971
- expected: "valid bolt11 multiplier: m, u, n, p"
2972
- });
2973
- }
2974
- const divisor = divisors[multiplier];
2975
- if (value * MILLISATS_PER_BTC % divisor !== 0n) {
2976
- throw new ValidationError("Invalid submillisatoshi precision", {
2977
- field: "amount",
2978
- value: `${amount}${multiplier}`,
2979
- expected: "amount must result in whole millisatoshis"
2980
- });
2981
- }
2982
- return value * MILLISATS_PER_BTC / divisor;
2983
- } else {
2984
- return value * MILLISATS_PER_BTC;
2985
- }
2986
- }
2987
- function hasSparkHeader(bytes) {
2988
- if (bytes.length < 3) {
2989
- return false;
2990
- }
2991
- return bytes[0] === 83 && // 'S'
2992
- bytes[1] === 80 && // 'P'
2993
- bytes[2] === 75;
2994
- }
2995
2938
  function isValidSparkFallback(bytes) {
2996
- if (bytes.length !== 36) {
2939
+ if (bytes.length !== 33) {
2997
2940
  return false;
2998
2941
  }
2999
- return hasSparkHeader(bytes);
3000
- }
3001
- function verifySignature(words, prefix) {
3002
- if (words.length < 104) {
3003
- throw new ValidationError("Invoice too short for signature");
3004
- }
3005
- const signatureStart = words.length - 104;
3006
- const signatureEnd = words.length - 1;
3007
- const hrp = prefix;
3008
- const hrpBytes = new TextEncoder().encode(hrp);
3009
- const dataWords = words.slice(0, signatureStart);
3010
- const dataBytes = bech32WordsToBytes(dataWords);
3011
- const sigWords = words.slice(signatureStart, signatureEnd);
3012
- const sigBytes = bech32WordsToBytes(sigWords);
3013
- if (sigBytes.length !== 64) {
3014
- throw new ValidationError("Invalid signature length");
3015
- }
3016
- const recoveryId = words[words.length - 1];
3017
- if (recoveryId === void 0) {
3018
- throw new ValidationError("Missing recovery ID in signature");
3019
- }
3020
- const messageBytes = new Uint8Array(hrpBytes.length + dataBytes.length);
3021
- messageBytes.set(hrpBytes, 0);
3022
- messageBytes.set(dataBytes, hrpBytes.length);
3023
- const messageHash = sha2564(messageBytes);
3024
- try {
3025
- const signature = secp256k13.Signature.fromCompact(sigBytes).addRecoveryBit(recoveryId);
3026
- signature.recoverPublicKey(messageHash);
3027
- } catch (error) {
3028
- throw new ValidationError(
3029
- `Invalid BOLT11 signature: ${error.message}`
3030
- );
3031
- }
2942
+ return true;
3032
2943
  }
3033
2944
 
3034
2945
  // src/services/lightning.ts
@@ -3051,7 +2962,7 @@ var LightningService = class {
3051
2962
  }) {
3052
2963
  const randBytes = crypto.getRandomValues(new Uint8Array(32));
3053
2964
  const preimage = numberToBytesBE2(
3054
- bytesToNumberBE(randBytes) % secp256k14.CURVE.n,
2965
+ bytesToNumberBE(randBytes) % secp256k13.CURVE.n,
3055
2966
  32
3056
2967
  );
3057
2968
  return await this.createLightningInvoiceWithPreImage({
@@ -3071,7 +2982,7 @@ var LightningService = class {
3071
2982
  receiverIdentityPubkey,
3072
2983
  descriptionHash
3073
2984
  }) {
3074
- const paymentHash = sha2565(preimage);
2985
+ const paymentHash = sha2564(preimage);
3075
2986
  const invoice = await invoiceCreator(
3076
2987
  amountSats,
3077
2988
  paymentHash,
@@ -3088,7 +2999,7 @@ var LightningService = class {
3088
2999
  }
3089
3000
  const shares = await this.config.signer.splitSecretWithProofs({
3090
3001
  secret: preimage,
3091
- curveOrder: secp256k14.CURVE.n,
3002
+ curveOrder: secp256k13.CURVE.n,
3092
3003
  threshold: this.config.getThreshold(),
3093
3004
  numShares: Object.keys(this.config.getSigningOperators()).length
3094
3005
  });
@@ -3268,7 +3179,7 @@ var LightningService = class {
3268
3179
  const sparkClient = await this.connectionManager.createSparkClient(
3269
3180
  this.config.getCoordinatorAddress()
3270
3181
  );
3271
- const paymentHash = sha2565(preimage);
3182
+ const paymentHash = sha2564(preimage);
3272
3183
  let response;
3273
3184
  try {
3274
3185
  response = await sparkClient.provide_preimage({
@@ -3300,7 +3211,7 @@ var LightningService = class {
3300
3211
 
3301
3212
  // src/services/tree-creation.ts
3302
3213
  import { hexToBytes as hexToBytes4 } from "@noble/curves/abstract/utils";
3303
- import { sha256 as sha2566 } from "@noble/hashes/sha2";
3214
+ import { sha256 as sha2565 } from "@noble/hashes/sha2";
3304
3215
  import { Address as Address2, OutScript as OutScript2, Transaction as Transaction4 } from "@scure/btc-signer";
3305
3216
  var INITIAL_TIME_LOCK3 = 2e3;
3306
3217
  function maybeApplyFee(amount) {
@@ -3456,7 +3367,7 @@ var TreeCreationService = class {
3456
3367
  return finalizeResp;
3457
3368
  }
3458
3369
  async createDepositAddressTree(targetSigningPublicKey, nodeId) {
3459
- const leftKey = await this.config.signer.generatePublicKey(sha2566(nodeId));
3370
+ const leftKey = await this.config.signer.generatePublicKey(sha2565(nodeId));
3460
3371
  const leftNode = {
3461
3372
  signingPublicKey: leftKey,
3462
3373
  children: []
@@ -3505,7 +3416,10 @@ var TreeCreationService = class {
3505
3416
  const internalCreationNode = {
3506
3417
  nodeTxSigningJob: void 0,
3507
3418
  refundTxSigningJob: void 0,
3508
- children: []
3419
+ children: [],
3420
+ directNodeTxSigningJob: void 0,
3421
+ directRefundTxSigningJob: void 0,
3422
+ directFromCpfpRefundTxSigningJob: void 0
3509
3423
  };
3510
3424
  const tx = new Transaction4({ version: 3 });
3511
3425
  tx.addInput({
@@ -3534,7 +3448,10 @@ var TreeCreationService = class {
3534
3448
  const childCreationNode = {
3535
3449
  nodeTxSigningJob: void 0,
3536
3450
  refundTxSigningJob: void 0,
3537
- children: []
3451
+ children: [],
3452
+ directNodeTxSigningJob: void 0,
3453
+ directRefundTxSigningJob: void 0,
3454
+ directFromCpfpRefundTxSigningJob: void 0
3538
3455
  };
3539
3456
  const childTx = new Transaction4({ version: 3 });
3540
3457
  childTx.addInput({
@@ -3619,7 +3536,10 @@ var TreeCreationService = class {
3619
3536
  const rootCreationNode = {
3620
3537
  nodeTxSigningJob: rootNodeSigningJob,
3621
3538
  refundTxSigningJob: void 0,
3622
- children: []
3539
+ children: [],
3540
+ directNodeTxSigningJob: void 0,
3541
+ directRefundTxSigningJob: void 0,
3542
+ directFromCpfpRefundTxSigningJob: void 0
3623
3543
  };
3624
3544
  rootCreationNode.nodeTxSigningCommitment = rootNodeSigningCommitment;
3625
3545
  const leftChild = root.children[0];
@@ -3709,7 +3629,11 @@ var TreeCreationService = class {
3709
3629
  signature: {
3710
3630
  nodeId: creationResponseNode.nodeId,
3711
3631
  nodeTxSignature,
3712
- refundTxSignature
3632
+ refundTxSignature,
3633
+ // TODO: Add direct refund signature
3634
+ directNodeTxSignature: new Uint8Array(),
3635
+ directRefundTxSignature: new Uint8Array(),
3636
+ directFromCpfpRefundTxSignature: new Uint8Array()
3713
3637
  }
3714
3638
  };
3715
3639
  }
@@ -3761,7 +3685,7 @@ var TreeCreationService = class {
3761
3685
 
3762
3686
  // src/spark-wallet/spark-wallet.ts
3763
3687
  import { LRCWallet } from "@buildonspark/lrc20-sdk";
3764
- import { sha256 as sha2567 } from "@noble/hashes/sha2";
3688
+ import { sha256 as sha2566 } from "@noble/hashes/sha2";
3765
3689
  import { EventEmitter } from "eventemitter3";
3766
3690
 
3767
3691
  // src/services/signing.ts
@@ -3842,7 +3766,7 @@ var SigningService = class {
3842
3766
 
3843
3767
  // src/tests/utils/test-faucet.ts
3844
3768
  import { bytesToHex as bytesToHex3, hexToBytes as hexToBytes6 } from "@noble/curves/abstract/utils";
3845
- import { schnorr as schnorr2, secp256k1 as secp256k15 } from "@noble/curves/secp256k1";
3769
+ import { schnorr as schnorr2, secp256k1 as secp256k14 } from "@noble/curves/secp256k1";
3846
3770
  import * as btc2 from "@scure/btc-signer";
3847
3771
  import { Address as Address3, OutScript as OutScript3, SigHash, Transaction as Transaction5 } from "@scure/btc-signer";
3848
3772
  import { taprootTweakPrivKey } from "@scure/btc-signer/utils";
@@ -3862,7 +3786,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
3862
3786
  this.username = username;
3863
3787
  this.password = password;
3864
3788
  this.miningAddress = getP2TRAddressFromPublicKey(
3865
- secp256k15.getPublicKey(STATIC_MINING_KEY),
3789
+ secp256k14.getPublicKey(STATIC_MINING_KEY),
3866
3790
  4 /* LOCAL */
3867
3791
  );
3868
3792
  }
@@ -3901,7 +3825,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
3901
3825
  });
3902
3826
  }
3903
3827
  async refill() {
3904
- const minerPubKey = secp256k15.getPublicKey(STATIC_MINING_KEY);
3828
+ const minerPubKey = secp256k14.getPublicKey(STATIC_MINING_KEY);
3905
3829
  const address = getP2TRAddressFromPublicKey(minerPubKey, 4 /* LOCAL */);
3906
3830
  const scanResult = await this.call("scantxoutset", [
3907
3831
  "start",
@@ -3950,7 +3874,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
3950
3874
  txid: selectedUtxo.txid,
3951
3875
  index: selectedUtxo.vout
3952
3876
  });
3953
- const faucetPubKey = secp256k15.getPublicKey(STATIC_FAUCET_KEY);
3877
+ const faucetPubKey = secp256k14.getPublicKey(STATIC_FAUCET_KEY);
3954
3878
  const script = getP2TRScriptFromPublicKey(faucetPubKey, 4 /* LOCAL */);
3955
3879
  for (let i = 0; i < numCoinsToCreate; i++) {
3956
3880
  splitTx.addOutput({
@@ -4011,7 +3935,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
4011
3935
  await this.broadcastTx(bytesToHex3(signedTx.extract()));
4012
3936
  }
4013
3937
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
4014
- const pubKey = secp256k15.getPublicKey(key);
3938
+ const pubKey = secp256k14.getPublicKey(key);
4015
3939
  const internalKey = pubKey.slice(1);
4016
3940
  const script = getP2TRScriptFromPublicKey(pubKey, 4 /* LOCAL */);
4017
3941
  unsignedTx.updateInput(0, {
@@ -4093,8 +4017,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
4093
4017
  return response;
4094
4018
  }
4095
4019
  async getNewAddress() {
4096
- const key = secp256k15.utils.randomPrivateKey();
4097
- const pubKey = secp256k15.getPublicKey(key);
4020
+ const key = secp256k14.utils.randomPrivateKey();
4021
+ const pubKey = secp256k14.getPublicKey(key);
4098
4022
  return getP2TRAddressFromPublicKey(pubKey, 4 /* LOCAL */);
4099
4023
  }
4100
4024
  async sendToAddress(address, amount) {
@@ -4115,8 +4039,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
4115
4039
  });
4116
4040
  const changeAmount = availableAmount - amount;
4117
4041
  if (changeAmount > 0) {
4118
- const changeKey = secp256k15.utils.randomPrivateKey();
4119
- const changePubKey = secp256k15.getPublicKey(changeKey);
4042
+ const changeKey = secp256k14.utils.randomPrivateKey();
4043
+ const changePubKey = secp256k14.getPublicKey(changeKey);
4120
4044
  const changeScript = getP2TRScriptFromPublicKey(
4121
4045
  changePubKey,
4122
4046
  4 /* LOCAL */
@@ -4129,8 +4053,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
4129
4053
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
4130
4054
  const txHex = bytesToHex3(signedTx.extract());
4131
4055
  await this.broadcastTx(txHex);
4132
- const randomKey = secp256k15.utils.randomPrivateKey();
4133
- const randomPubKey = secp256k15.getPublicKey(randomKey);
4056
+ const randomKey = secp256k14.utils.randomPrivateKey();
4057
+ const randomPubKey = secp256k14.getPublicKey(randomKey);
4134
4058
  const randomAddress = getP2TRAddressFromPublicKey(
4135
4059
  randomPubKey,
4136
4060
  4 /* LOCAL */
@@ -4152,6 +4076,35 @@ function chunkArray(arr, size) {
4152
4076
  return chunks;
4153
4077
  }
4154
4078
 
4079
+ // src/utils/token-identifier.ts
4080
+ import { bech32m } from "@scure/base";
4081
+ var HumanReadableTokenIdentifierNetworkPrefix = {
4082
+ MAINNET: "btk",
4083
+ REGTEST: "btkrt",
4084
+ TESTNET: "btkt",
4085
+ SIGNET: "btks",
4086
+ LOCAL: "btkl"
4087
+ };
4088
+ function encodeHumanReadableTokenIdentifier(payload) {
4089
+ try {
4090
+ const words = bech32m.toWords(payload.tokenIdentifier);
4091
+ return bech32m.encode(
4092
+ HumanReadableTokenIdentifierNetworkPrefix[payload.network],
4093
+ words,
4094
+ 500
4095
+ );
4096
+ } catch (error) {
4097
+ throw new ValidationError(
4098
+ "Failed to encode human readable token identifier",
4099
+ {
4100
+ field: "tokenIdentifier",
4101
+ value: payload.tokenIdentifier
4102
+ },
4103
+ error
4104
+ );
4105
+ }
4106
+ }
4107
+
4155
4108
  // src/spark-wallet/spark-wallet.ts
4156
4109
  var SparkWallet = class _SparkWallet extends EventEmitter {
4157
4110
  config;
@@ -4262,7 +4215,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
4262
4215
  } else if (event?.$case === "deposit" && event.deposit.deposit) {
4263
4216
  const deposit = event.deposit.deposit;
4264
4217
  const signingKey = await this.config.signer.generatePublicKey(
4265
- sha2567(deposit.id)
4218
+ sha2566(deposit.id)
4266
4219
  );
4267
4220
  const newLeaf = await this.transferService.extendTimelock(
4268
4221
  deposit,
@@ -4417,7 +4370,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
4417
4370
  if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !equalBytes3(
4418
4371
  leaf.signingKeyshare.publicKey,
4419
4372
  operatorLeaf.signingKeyshare.publicKey
4420
- ) || !equalBytes3(leaf.nodeTx, operatorLeaf.nodeTx) || !equalBytes3(leaf.refundTx, operatorLeaf.refundTx)) {
4373
+ ) || !equalBytes3(leaf.nodeTx, operatorLeaf.nodeTx)) {
4421
4374
  leavesToIgnore.add(nodeId);
4422
4375
  }
4423
4376
  }
@@ -4429,7 +4382,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
4429
4382
  };
4430
4383
  for (const [id, leaf] of Object.entries(leaves.nodes)) {
4431
4384
  if (!verifyKey(
4432
- await this.config.signer.generatePublicKey(sha2567(leaf.id)),
4385
+ await this.config.signer.generatePublicKey(sha2566(leaf.id)),
4433
4386
  leaf.signingKeyshare?.publicKey ?? new Uint8Array(),
4434
4387
  leaf.verifyingPublicKey
4435
4388
  )) {
@@ -4810,7 +4763,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
4810
4763
  leavesBatch.map(async (leaf) => ({
4811
4764
  leaf,
4812
4765
  signingPubKey: await this.config.signer.generatePublicKey(
4813
- sha2567(leaf.id)
4766
+ sha2566(leaf.id)
4814
4767
  ),
4815
4768
  newSigningPubKey: await this.config.signer.generatePublicKey()
4816
4769
  }))
@@ -4863,7 +4816,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
4863
4816
  }
4864
4817
  const sspClient = this.getSspClient();
4865
4818
  const adaptorPubkey = bytesToHex4(
4866
- secp256k16.getPublicKey(adaptorPrivateKey)
4819
+ secp256k15.getPublicKey(adaptorPrivateKey)
4867
4820
  );
4868
4821
  let request = null;
4869
4822
  request = await sspClient.requestLeaveSwap({
@@ -4969,27 +4922,6 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
4969
4922
  offset: transfers.offset
4970
4923
  };
4971
4924
  }
4972
- /**
4973
- * Gets the held token info for the wallet.
4974
- *
4975
- * @deprecated The information is returned in getBalance
4976
- */
4977
- async getTokenInfo() {
4978
- console.warn("getTokenInfo is deprecated. Use getBalance instead.");
4979
- await this.syncTokenOutputs();
4980
- const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
4981
- const { balance, tokenBalances } = await this.getBalance();
4982
- const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
4983
- publicKeys: Array.from(tokenBalances.keys()).map(hexToBytes7)
4984
- });
4985
- return tokenInfo.tokenPubkeyInfos.map((info) => ({
4986
- tokenPublicKey: bytesToHex4(info.announcement.publicKey.publicKey),
4987
- tokenName: info.announcement.name,
4988
- tokenSymbol: info.announcement.symbol,
4989
- tokenDecimals: Number(bytesToNumberBE2(info.announcement.decimal)),
4990
- maxSupply: bytesToNumberBE2(info.announcement.maxSupply)
4991
- }));
4992
- }
4993
4925
  /**
4994
4926
  * Gets the current balance of the wallet.
4995
4927
  * You can use the forceRefetch option to synchronize your wallet and claim any
@@ -4997,7 +4929,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
4997
4929
  *
4998
4930
  * @returns {Promise<Object>} Object containing:
4999
4931
  * - balance: The wallet's current balance in satoshis
5000
- * - tokenBalances: Map of token public keys to token balances and token info
4932
+ * - tokenBalances: Map of the human readable token identifier to token balances and token info
5001
4933
  */
5002
4934
  async getBalance() {
5003
4935
  const leaves = await this.getLeaves(true);
@@ -5014,24 +4946,29 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5014
4946
  };
5015
4947
  }
5016
4948
  async getTokenBalance() {
5017
- const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
5018
- const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
5019
- publicKeys: Array.from(this.tokenOutputs.keys()).map(hexToBytes7)
4949
+ const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
4950
+ this.config.getCoordinatorAddress()
4951
+ );
4952
+ const tokenMetadata = await sparkTokenClient.query_token_metadata({
4953
+ issuerPublicKeys: Array.from(this.tokenOutputs.keys()).map(hexToBytes7)
5020
4954
  });
5021
4955
  const result = /* @__PURE__ */ new Map();
5022
- for (const info of tokenInfo.tokenPubkeyInfos) {
5023
- const tokenPublicKey = bytesToHex4(
5024
- info.announcement.publicKey.publicKey
5025
- );
4956
+ for (const metadata of tokenMetadata.tokenMetadata) {
4957
+ const tokenPublicKey = bytesToHex4(metadata.issuerPublicKey);
5026
4958
  const leaves = this.tokenOutputs.get(tokenPublicKey);
5027
- result.set(tokenPublicKey, {
4959
+ const humanReadableTokenIdentifier = encodeHumanReadableTokenIdentifier({
4960
+ tokenIdentifier: metadata.tokenIdentifier,
4961
+ network: this.config.getNetworkType()
4962
+ });
4963
+ result.set(humanReadableTokenIdentifier, {
5028
4964
  balance: leaves ? calculateAvailableTokenAmount(leaves) : BigInt(0),
5029
- tokenInfo: {
4965
+ tokenMetadata: {
5030
4966
  tokenPublicKey,
5031
- tokenName: info.announcement.name,
5032
- tokenSymbol: info.announcement.symbol,
5033
- tokenDecimals: Number(bytesToNumberBE2(info.announcement.decimal)),
5034
- maxSupply: bytesToNumberBE2(info.announcement.maxSupply)
4967
+ rawTokenIdentifier: metadata.tokenIdentifier,
4968
+ tokenName: metadata.tokenName,
4969
+ tokenTicker: metadata.tokenTicker,
4970
+ decimals: metadata.decimals,
4971
+ maxSupply: bytesToNumberBE2(metadata.maxSupply)
5035
4972
  }
5036
4973
  });
5037
4974
  }
@@ -5089,7 +5026,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5089
5026
  signingPubkey = await this.config.signer.generateStaticDepositKey(0);
5090
5027
  } else {
5091
5028
  signingPubkey = await this.config.signer.generatePublicKey(
5092
- sha2567(leafId)
5029
+ sha2566(leafId)
5093
5030
  );
5094
5031
  }
5095
5032
  const address = await this.depositService.generateDepositAddress({
@@ -5176,7 +5113,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5176
5113
  creditAmountSats,
5177
5114
  sspSignature
5178
5115
  );
5179
- const hashBuffer = sha2567(message);
5116
+ const hashBuffer = sha2566(message);
5180
5117
  const signatureBytes = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
5181
5118
  const signature = bytesToHex4(signatureBytes);
5182
5119
  const response = await this.sspClient.claimStaticDeposit({
@@ -5265,7 +5202,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5265
5202
  creditAmountSats,
5266
5203
  bytesToHex4(spendTxSighash)
5267
5204
  );
5268
- const hashBuffer = sha2567(message);
5205
+ const hashBuffer = sha2566(message);
5269
5206
  const swapResponseUserSignature = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
5270
5207
  const sparkClient = await this.connectionManager.createSparkClient(
5271
5208
  this.config.getCoordinatorAddress()
@@ -5599,7 +5536,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5599
5536
  signingPubKey = depositAddress.userSigningPublicKey;
5600
5537
  } else {
5601
5538
  signingPubKey = await this.config.signer.generatePublicKey(
5602
- sha2567(depositAddress.leafId)
5539
+ sha2566(depositAddress.leafId)
5603
5540
  );
5604
5541
  }
5605
5542
  const nodes2 = await this.finalizeDeposit({
@@ -5740,7 +5677,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5740
5677
  leavesToSend.map(async (leaf) => ({
5741
5678
  leaf,
5742
5679
  signingPubKey: await this.config.signer.generatePublicKey(
5743
- sha2567(leaf.id)
5680
+ sha2566(leaf.id)
5744
5681
  ),
5745
5682
  newSigningPubKey: await this.config.signer.generatePublicKey()
5746
5683
  }))
@@ -5789,7 +5726,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5789
5726
  const nodesToAdd = [];
5790
5727
  for (const node of nodesToExtend) {
5791
5728
  const signingPubKey = await this.config.signer.generatePublicKey(
5792
- sha2567(node.id)
5729
+ sha2566(node.id)
5793
5730
  );
5794
5731
  const { nodes: nodes2 } = await this.transferService.extendTimelock(
5795
5732
  node,
@@ -5856,7 +5793,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5856
5793
  const { nodes: nodes2 } = await this.transferService.refreshTimelockNodes(
5857
5794
  [node],
5858
5795
  parentNode,
5859
- await this.config.signer.generatePublicKey(sha2567(node.id))
5796
+ await this.config.signer.generatePublicKey(sha2566(node.id))
5860
5797
  );
5861
5798
  if (nodes2.length !== 1) {
5862
5799
  throw new Error(`expected 1 node, got ${nodes2.length}`);
@@ -5908,7 +5845,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
5908
5845
  },
5909
5846
  signingPubKey: leafPubKey,
5910
5847
  newSigningPubKey: await this.config.signer.generatePublicKey(
5911
- sha2567(leaf.leaf.id)
5848
+ sha2566(leaf.leaf.id)
5912
5849
  )
5913
5850
  });
5914
5851
  }
@@ -6101,22 +6038,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6101
6038
  const sparkFallbackAddress = decodeInvoice(
6102
6039
  invoice2.invoice.encodedInvoice
6103
6040
  ).fallbackAddress;
6104
- if (sparkFallbackAddress && isValidSparkFallback(hexToBytes7(sparkFallbackAddress))) {
6105
- const invoiceIdentityPubkey = sparkFallbackAddress.slice(6);
6106
- const expectedIdentityPubkey = receiverIdentityPubkey2 ?? await this.getIdentityPublicKey();
6107
- if (invoiceIdentityPubkey !== expectedIdentityPubkey) {
6108
- throw new ValidationError(
6109
- "Mismatch between spark identity embedded in lightning invoice and designated recipient spark identity",
6110
- {
6111
- field: "sparkFallbackAddress",
6112
- value: invoiceIdentityPubkey,
6113
- expected: expectedIdentityPubkey
6114
- }
6115
- );
6116
- }
6117
- } else {
6041
+ if (!sparkFallbackAddress) {
6118
6042
  throw new ValidationError(
6119
- "No valid spark fallback address found in lightning invoice",
6043
+ "No spark fallback address found in lightning invoice",
6120
6044
  {
6121
6045
  field: "sparkFallbackAddress",
6122
6046
  value: sparkFallbackAddress,
@@ -6124,6 +6048,17 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6124
6048
  }
6125
6049
  );
6126
6050
  }
6051
+ const expectedIdentityPubkey = receiverIdentityPubkey2 ?? await this.getIdentityPublicKey();
6052
+ if (sparkFallbackAddress !== expectedIdentityPubkey) {
6053
+ throw new ValidationError(
6054
+ "Mismatch between spark identity embedded in lightning invoice and designated recipient spark identity",
6055
+ {
6056
+ field: "sparkFallbackAddress",
6057
+ value: sparkFallbackAddress,
6058
+ expected: expectedIdentityPubkey
6059
+ }
6060
+ );
6061
+ }
6127
6062
  }
6128
6063
  return invoice2;
6129
6064
  };
@@ -6202,9 +6137,8 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6202
6137
  "No valid spark address found in invoice. Defaulting to lightning."
6203
6138
  );
6204
6139
  } else {
6205
- const identityPublicKey = sparkFallbackAddress.slice(6);
6206
6140
  const receiverSparkAddress = encodeSparkAddress({
6207
- identityPublicKey,
6141
+ identityPublicKey: sparkFallbackAddress,
6208
6142
  network: Network[invoiceNetwork]
6209
6143
  });
6210
6144
  return await this.transfer({
@@ -6242,7 +6176,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6242
6176
  leaves.map(async (leaf) => ({
6243
6177
  leaf,
6244
6178
  signingPubKey: await this.config.signer.generatePublicKey(
6245
- sha2567(leaf.id)
6179
+ sha2566(leaf.id)
6246
6180
  ),
6247
6181
  newSigningPubKey: await this.config.signer.generatePublicKey()
6248
6182
  }))
@@ -6454,7 +6388,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6454
6388
  [...leavesToSendToSE, ...leavesToSendToSsp].map(async (leaf) => ({
6455
6389
  leaf,
6456
6390
  signingPubKey: await this.config.signer.generatePublicKey(
6457
- sha2567(leaf.id)
6391
+ sha2566(leaf.id)
6458
6392
  ),
6459
6393
  newSigningPubKey: await this.config.signer.generatePublicKey()
6460
6394
  }))
@@ -6555,7 +6489,14 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6555
6489
  * @returns {Promise<Transfer | undefined>} The transfer
6556
6490
  */
6557
6491
  async getTransfer(id) {
6558
- return await this.transferService.queryTransfer(id);
6492
+ const transfer = await this.transferService.queryTransfer(id);
6493
+ if (!transfer) {
6494
+ return void 0;
6495
+ }
6496
+ return mapTransferToWalletTransfer(
6497
+ transfer,
6498
+ bytesToHex4(await this.config.signer.getIdentityPublicKey())
6499
+ );
6559
6500
  }
6560
6501
  // ***** Token Flow *****
6561
6502
  /**
@@ -6566,10 +6507,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6566
6507
  */
6567
6508
  async syncTokenOutputs() {
6568
6509
  this.tokenOutputs.clear();
6569
- const unsortedTokenOutputs = await this.tokenTransactionService.fetchOwnedTokenOutputs(
6570
- [await this.config.signer.getIdentityPublicKey()],
6571
- []
6572
- );
6510
+ const unsortedTokenOutputs = await this.tokenTransactionService.fetchOwnedTokenOutputs({
6511
+ ownerPublicKeys: [await this.config.signer.getIdentityPublicKey()]
6512
+ });
6573
6513
  const filteredTokenOutputs = unsortedTokenOutputs.filter(
6574
6514
  (output) => !this.pendingWithdrawnOutputIds.includes(output.output?.id || "")
6575
6515
  );
@@ -6668,29 +6608,21 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6668
6608
  * Retrieves token transaction history for specified tokens owned by the wallet.
6669
6609
  * Can optionally filter by specific transaction hashes.
6670
6610
  *
6671
- * @param tokenPublicKeys - Array of token public keys to query transactions for
6611
+ * @param ownerPublicKeys - Optional array of owner public keys to query transactions for
6612
+ * @param issuerPublicKeys - Optional array of issuer public keys to query transactions for
6672
6613
  * @param tokenTransactionHashes - Optional array of specific transaction hashes to filter by
6614
+ * @param tokenIdentifiers - Optional array of token identifiers to filter by
6615
+ * @param outputIds - Optional array of output IDs to filter by
6673
6616
  * @returns Promise resolving to array of token transactions with their current status
6674
6617
  */
6675
- async queryTokenTransactions(tokenPublicKeys, tokenTransactionHashes) {
6676
- const sparkClient = await this.connectionManager.createSparkClient(
6677
- this.config.getCoordinatorAddress()
6678
- );
6679
- let queryParams;
6680
- if (tokenTransactionHashes?.length) {
6681
- queryParams = {
6682
- tokenPublicKeys: tokenPublicKeys?.map(hexToBytes7),
6683
- ownerPublicKeys: [hexToBytes7(await this.getIdentityPublicKey())],
6684
- tokenTransactionHashes: tokenTransactionHashes.map(hexToBytes7)
6685
- };
6686
- } else {
6687
- queryParams = {
6688
- tokenPublicKeys: tokenPublicKeys?.map(hexToBytes7),
6689
- ownerPublicKeys: [hexToBytes7(await this.getIdentityPublicKey())]
6690
- };
6691
- }
6692
- const response = await sparkClient.query_token_transactions(queryParams);
6693
- return response.tokenTransactionsWithStatus;
6618
+ async queryTokenTransactions(ownerPublicKeys, issuerPublicKeys, tokenTransactionHashes, tokenIdentifiers, outputIds) {
6619
+ return this.tokenTransactionService.queryTokenTransactions({
6620
+ ownerPublicKeys,
6621
+ issuerPublicKeys,
6622
+ tokenTransactionHashes,
6623
+ tokenIdentifiers,
6624
+ outputIds
6625
+ });
6694
6626
  }
6695
6627
  async getTokenL1Address() {
6696
6628
  return getP2WPKHAddressFromPublicKey(
@@ -6706,7 +6638,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6706
6638
  * @returns {Promise<string>} The signed message
6707
6639
  */
6708
6640
  async signMessageWithIdentityKey(message, compact) {
6709
- const hash = sha2567(message);
6641
+ const hash = sha2566(message);
6710
6642
  const signature = await this.config.signer.signMessageWithIdentityKey(
6711
6643
  hash,
6712
6644
  compact
@@ -6721,7 +6653,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
6721
6653
  * @returns {Promise<boolean>} Whether the message is valid
6722
6654
  */
6723
6655
  async validateMessageWithIdentityKey(message, signature) {
6724
- const hash = sha2567(message);
6656
+ const hash = sha2566(message);
6725
6657
  if (typeof signature === "string") {
6726
6658
  signature = hexToBytes7(signature);
6727
6659
  }
@@ -7028,7 +6960,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
7028
6960
  });
7029
6961
  }
7030
6962
  const signingPubKey = await this.config.signer.generatePublicKey(
7031
- sha2567(node.id)
6963
+ sha2566(node.id)
7032
6964
  );
7033
6965
  const result = await this.transferService.refreshTimelockNodes(
7034
6966
  [node],
@@ -7080,7 +7012,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
7080
7012
  });
7081
7013
  }
7082
7014
  const signingPubKey = await this.config.signer.generatePublicKey(
7083
- sha2567(node.id)
7015
+ sha2566(node.id)
7084
7016
  );
7085
7017
  const result = await this.transferService.refreshTimelockRefundTx(
7086
7018
  node,