@buildonspark/spark-sdk 0.1.43 → 0.1.44

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 (112) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/{RequestLightningSendInput-Na1mHdWg.d.cts → RequestLightningSendInput-BxbCtwpV.d.cts} +43 -4
  3. package/dist/{RequestLightningSendInput-D7fZdT4A.d.ts → RequestLightningSendInput-RGel43ks.d.ts} +43 -4
  4. package/dist/address/index.d.cts +2 -2
  5. package/dist/address/index.d.ts +2 -2
  6. package/dist/address/index.js +2 -2
  7. package/dist/{chunk-M6A4KFIG.js → chunk-4Q2ZDYYU.js} +332 -221
  8. package/dist/{chunk-WWOTVNPP.js → chunk-A2ZLMH6I.js} +323 -142
  9. package/dist/{chunk-VA7MV4MZ.js → chunk-B3AMIGJG.js} +1 -1
  10. package/dist/{chunk-DQYKQJRZ.js → chunk-CIZNCBKE.js} +29 -9
  11. package/dist/{chunk-BUTZWYBW.js → chunk-DAXGVPVM.js} +2 -2
  12. package/dist/{chunk-DOA6QXYQ.js → chunk-EKFD62HN.js} +2 -1
  13. package/dist/{chunk-TIUBYNN5.js → chunk-HTMXTJRK.js} +1 -1
  14. package/dist/{chunk-TOSP3INR.js → chunk-I54FARY2.js} +4 -2
  15. package/dist/{chunk-MIVX3GHD.js → chunk-K4BJARWM.js} +1 -1
  16. package/dist/{chunk-O4RYNJNB.js → chunk-KEKGSH7B.js} +1 -1
  17. package/dist/{chunk-GYQR4B4P.js → chunk-NBCNYDWJ.js} +2 -2
  18. package/dist/{chunk-ABZA6R5S.js → chunk-SQKXGAIR.js} +1 -1
  19. package/dist/{chunk-VFJQNBFX.js → chunk-UBT6EDVJ.js} +5 -2
  20. package/dist/{chunk-HRQRRDSS.js → chunk-WPTRVD2V.js} +3 -3
  21. package/dist/{chunk-IRW5TWMH.js → chunk-XX4RRWOX.js} +5 -5
  22. package/dist/graphql/objects/index.d.cts +5 -43
  23. package/dist/graphql/objects/index.d.ts +5 -43
  24. package/dist/graphql/objects/index.js +1 -1
  25. package/dist/{index-BJOc8Ur-.d.cts → index-CZmDdSts.d.cts} +24 -10
  26. package/dist/{index-7RYRH5wc.d.ts → index-ClIRO_3y.d.ts} +24 -10
  27. package/dist/index.cjs +827 -414
  28. package/dist/index.d.cts +6 -6
  29. package/dist/index.d.ts +6 -6
  30. package/dist/index.js +15 -15
  31. package/dist/index.node.cjs +830 -417
  32. package/dist/index.node.d.cts +7 -7
  33. package/dist/index.node.d.ts +7 -7
  34. package/dist/index.node.js +18 -18
  35. package/dist/native/index.cjs +827 -414
  36. package/dist/native/index.d.cts +88 -23
  37. package/dist/native/index.d.ts +88 -23
  38. package/dist/native/index.js +819 -407
  39. package/dist/{network-D5lKssVl.d.cts → network-CfxLnaot.d.cts} +1 -1
  40. package/dist/{network-xkBSpaTn.d.ts → network-CroCOQ0B.d.ts} +1 -1
  41. package/dist/proto/lrc20.d.cts +1 -1
  42. package/dist/proto/lrc20.d.ts +1 -1
  43. package/dist/proto/lrc20.js +2 -2
  44. package/dist/proto/spark.cjs +332 -221
  45. package/dist/proto/spark.d.cts +1 -1
  46. package/dist/proto/spark.d.ts +1 -1
  47. package/dist/proto/spark.js +3 -5
  48. package/dist/proto/spark_token.cjs +149 -9
  49. package/dist/proto/spark_token.d.cts +1 -1
  50. package/dist/proto/spark_token.d.ts +1 -1
  51. package/dist/proto/spark_token.js +2 -2
  52. package/dist/{sdk-types-B-q9py_P.d.cts → sdk-types-BeCBoozO.d.cts} +1 -1
  53. package/dist/{sdk-types-BPoPgzda.d.ts → sdk-types-CTbTdDbE.d.ts} +1 -1
  54. package/dist/services/config.cjs +7 -3
  55. package/dist/services/config.d.cts +4 -4
  56. package/dist/services/config.d.ts +4 -4
  57. package/dist/services/config.js +5 -5
  58. package/dist/services/connection.cjs +334 -218
  59. package/dist/services/connection.d.cts +4 -4
  60. package/dist/services/connection.d.ts +4 -4
  61. package/dist/services/connection.js +4 -4
  62. package/dist/services/index.cjs +364 -227
  63. package/dist/services/index.d.cts +4 -4
  64. package/dist/services/index.d.ts +4 -4
  65. package/dist/services/index.js +9 -9
  66. package/dist/services/lrc-connection.cjs +5 -2
  67. package/dist/services/lrc-connection.d.cts +4 -4
  68. package/dist/services/lrc-connection.d.ts +4 -4
  69. package/dist/services/lrc-connection.js +4 -4
  70. package/dist/services/token-transactions.cjs +28 -8
  71. package/dist/services/token-transactions.d.cts +4 -4
  72. package/dist/services/token-transactions.d.ts +4 -4
  73. package/dist/services/token-transactions.js +3 -3
  74. package/dist/services/wallet-config.cjs +2 -1
  75. package/dist/services/wallet-config.d.cts +4 -4
  76. package/dist/services/wallet-config.d.ts +4 -4
  77. package/dist/services/wallet-config.js +1 -1
  78. package/dist/signer/signer.cjs +5 -2
  79. package/dist/signer/signer.d.cts +2 -2
  80. package/dist/signer/signer.d.ts +2 -2
  81. package/dist/signer/signer.js +2 -2
  82. package/dist/{signer-wqesWifN.d.ts → signer-D7vfYik9.d.ts} +1 -1
  83. package/dist/{signer-IO3oMRNj.d.cts → signer-DaY8c60s.d.cts} +1 -1
  84. package/dist/{spark-CDm4gqS6.d.ts → spark-C4ZrsgjC.d.cts} +47 -29
  85. package/dist/{spark-CDm4gqS6.d.cts → spark-C4ZrsgjC.d.ts} +47 -29
  86. package/dist/types/index.cjs +331 -219
  87. package/dist/types/index.d.cts +5 -5
  88. package/dist/types/index.d.ts +5 -5
  89. package/dist/types/index.js +3 -3
  90. package/dist/utils/index.cjs +298 -28
  91. package/dist/utils/index.d.cts +5 -5
  92. package/dist/utils/index.d.ts +5 -5
  93. package/dist/utils/index.js +6 -6
  94. package/package.json +1 -1
  95. package/src/constants.ts +5 -1
  96. package/src/graphql/client.ts +28 -0
  97. package/src/graphql/mutations/RequestCoopExit.ts +6 -0
  98. package/src/graphql/mutations/RequestSwapLeaves.ts +2 -0
  99. package/src/graphql/queries/GetCoopExitFeeQuote.ts +20 -0
  100. package/src/proto/spark.ts +454 -322
  101. package/src/services/token-transactions.ts +12 -0
  102. package/src/services/transfer.ts +0 -3
  103. package/src/services/wallet-config.ts +1 -0
  104. package/src/spark-wallet/spark-wallet.node.ts +3 -3
  105. package/src/spark-wallet/spark-wallet.ts +301 -125
  106. package/src/tests/integration/deposit.test.ts +16 -0
  107. package/src/tests/integration/ssp/coop-exit.test.ts +85 -21
  108. package/src/tests/integration/ssp/swap.test.ts +47 -0
  109. package/src/tests/tokens.test.ts +3 -2
  110. package/src/utils/token-hashing.ts +28 -10
  111. package/src/utils/transaction.ts +2 -2
  112. package/src/logger.ts +0 -3
@@ -258,9 +258,12 @@ import * as ecies from "eciesjs";
258
258
  import { isNode } from "@lightsparkdev/core";
259
259
  var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
260
260
  var isBun = globalThis.Bun !== void 0;
261
- var packageVersion = true ? "0.1.43" : "unknown";
261
+ var packageVersion = true ? "0.1.44" : "unknown";
262
262
  var baseEnvStr = "unknown";
263
- if (isNode) {
263
+ if (isBun) {
264
+ const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
265
+ baseEnvStr = `bun/${bunVersion}`;
266
+ } else if (isNode) {
264
267
  baseEnvStr = `node/${process.version}`;
265
268
  } else if (isReactNative) {
266
269
  baseEnvStr = "react-native";
@@ -1922,6 +1925,9 @@ var RequestCoopExit = `
1922
1925
  $withdrawal_address: String!
1923
1926
  $idempotency_key: String!
1924
1927
  $exit_speed: ExitSpeed!
1928
+ $withdraw_all: Boolean
1929
+ $fee_leaf_external_ids: [UUID!]
1930
+ $fee_quote_id: ID
1925
1931
  ) {
1926
1932
  request_coop_exit(
1927
1933
  input: {
@@ -1929,6 +1935,9 @@ var RequestCoopExit = `
1929
1935
  withdrawal_address: $withdrawal_address
1930
1936
  idempotency_key: $idempotency_key
1931
1937
  exit_speed: $exit_speed
1938
+ withdraw_all: $withdraw_all
1939
+ fee_leaf_external_ids: $fee_leaf_external_ids
1940
+ fee_quote_id: $fee_quote_id
1932
1941
  }
1933
1942
  ) {
1934
1943
  request {
@@ -2161,6 +2170,7 @@ var RequestSwapLeaves = `
2161
2170
  $fee_sats: Long!
2162
2171
  $user_leaves: [UserLeafInput!]!
2163
2172
  $idempotency_key: String!
2173
+ $target_amount_sats_list: [Long!]
2164
2174
  ) {
2165
2175
  request_leaves_swap(input: {
2166
2176
  adaptor_pubkey: $adaptor_pubkey
@@ -2169,6 +2179,7 @@ var RequestSwapLeaves = `
2169
2179
  fee_sats: $fee_sats
2170
2180
  user_leaves: $user_leaves
2171
2181
  idempotency_key: $idempotency_key
2182
+ target_amount_sats_list: $target_amount_sats_list
2172
2183
  }) {
2173
2184
  request {
2174
2185
  ...LeavesSwapRequestFragment
@@ -2300,13 +2311,112 @@ fragment CoopExitFeeEstimatesOutputFragment on CoopExitFeeEstimatesOutput {
2300
2311
  }
2301
2312
  }`;
2302
2313
 
2314
+ // src/graphql/objects/CoopExitFeeQuote.ts
2315
+ import { isObject as isObject5 } from "@lightsparkdev/core";
2316
+ var CoopExitFeeQuoteFromJson = (obj) => {
2317
+ return {
2318
+ id: obj["coop_exit_fee_quote_id"],
2319
+ createdAt: obj["coop_exit_fee_quote_created_at"],
2320
+ updatedAt: obj["coop_exit_fee_quote_updated_at"],
2321
+ network: BitcoinNetwork_default[obj["coop_exit_fee_quote_network"]] ?? BitcoinNetwork_default.FUTURE_VALUE,
2322
+ totalAmount: CurrencyAmountFromJson(
2323
+ obj["coop_exit_fee_quote_total_amount"]
2324
+ ),
2325
+ userFeeFast: CurrencyAmountFromJson(
2326
+ obj["coop_exit_fee_quote_user_fee_fast"]
2327
+ ),
2328
+ userFeeMedium: CurrencyAmountFromJson(
2329
+ obj["coop_exit_fee_quote_user_fee_medium"]
2330
+ ),
2331
+ userFeeSlow: CurrencyAmountFromJson(
2332
+ obj["coop_exit_fee_quote_user_fee_slow"]
2333
+ ),
2334
+ l1BroadcastFeeFast: CurrencyAmountFromJson(
2335
+ obj["coop_exit_fee_quote_l1_broadcast_fee_fast"]
2336
+ ),
2337
+ l1BroadcastFeeMedium: CurrencyAmountFromJson(
2338
+ obj["coop_exit_fee_quote_l1_broadcast_fee_medium"]
2339
+ ),
2340
+ l1BroadcastFeeSlow: CurrencyAmountFromJson(
2341
+ obj["coop_exit_fee_quote_l1_broadcast_fee_slow"]
2342
+ ),
2343
+ expiresAt: obj["coop_exit_fee_quote_expires_at"],
2344
+ typename: "CoopExitFeeQuote"
2345
+ };
2346
+ };
2347
+ var FRAGMENT10 = `
2348
+ fragment CoopExitFeeQuoteFragment on CoopExitFeeQuote {
2349
+ __typename
2350
+ coop_exit_fee_quote_id: id
2351
+ coop_exit_fee_quote_created_at: created_at
2352
+ coop_exit_fee_quote_updated_at: updated_at
2353
+ coop_exit_fee_quote_network: network
2354
+ coop_exit_fee_quote_total_amount: total_amount {
2355
+ __typename
2356
+ currency_amount_original_value: original_value
2357
+ currency_amount_original_unit: original_unit
2358
+ currency_amount_preferred_currency_unit: preferred_currency_unit
2359
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
2360
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
2361
+ }
2362
+ coop_exit_fee_quote_user_fee_fast: user_fee_fast {
2363
+ __typename
2364
+ currency_amount_original_value: original_value
2365
+ currency_amount_original_unit: original_unit
2366
+ currency_amount_preferred_currency_unit: preferred_currency_unit
2367
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
2368
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
2369
+ }
2370
+ coop_exit_fee_quote_user_fee_medium: user_fee_medium {
2371
+ __typename
2372
+ currency_amount_original_value: original_value
2373
+ currency_amount_original_unit: original_unit
2374
+ currency_amount_preferred_currency_unit: preferred_currency_unit
2375
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
2376
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
2377
+ }
2378
+ coop_exit_fee_quote_user_fee_slow: user_fee_slow {
2379
+ __typename
2380
+ currency_amount_original_value: original_value
2381
+ currency_amount_original_unit: original_unit
2382
+ currency_amount_preferred_currency_unit: preferred_currency_unit
2383
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
2384
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
2385
+ }
2386
+ coop_exit_fee_quote_l1_broadcast_fee_fast: l1_broadcast_fee_fast {
2387
+ __typename
2388
+ currency_amount_original_value: original_value
2389
+ currency_amount_original_unit: original_unit
2390
+ currency_amount_preferred_currency_unit: preferred_currency_unit
2391
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
2392
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
2393
+ }
2394
+ coop_exit_fee_quote_l1_broadcast_fee_medium: l1_broadcast_fee_medium {
2395
+ __typename
2396
+ currency_amount_original_value: original_value
2397
+ currency_amount_original_unit: original_unit
2398
+ currency_amount_preferred_currency_unit: preferred_currency_unit
2399
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
2400
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
2401
+ }
2402
+ coop_exit_fee_quote_l1_broadcast_fee_slow: l1_broadcast_fee_slow {
2403
+ __typename
2404
+ currency_amount_original_value: original_value
2405
+ currency_amount_original_unit: original_unit
2406
+ currency_amount_preferred_currency_unit: preferred_currency_unit
2407
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
2408
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
2409
+ }
2410
+ coop_exit_fee_quote_expires_at: expires_at
2411
+ }`;
2412
+
2303
2413
  // src/graphql/objects/LeavesSwapFeeEstimateOutput.ts
2304
2414
  var LeavesSwapFeeEstimateOutputFromJson = (obj) => {
2305
2415
  return {
2306
2416
  feeEstimate: CurrencyAmountFromJson(obj["leaves_swap_fee_estimate_output_fee_estimate"])
2307
2417
  };
2308
2418
  };
2309
- var FRAGMENT10 = `
2419
+ var FRAGMENT11 = `
2310
2420
  fragment LeavesSwapFeeEstimateOutputFragment on LeavesSwapFeeEstimateOutput {
2311
2421
  __typename
2312
2422
  leaves_swap_fee_estimate_output_fee_estimate: fee_estimate {
@@ -2325,7 +2435,7 @@ var LightningSendFeeEstimateOutputFromJson = (obj) => {
2325
2435
  feeEstimate: CurrencyAmountFromJson(obj["lightning_send_fee_estimate_output_fee_estimate"])
2326
2436
  };
2327
2437
  };
2328
- var FRAGMENT11 = `
2438
+ var FRAGMENT12 = `
2329
2439
  fragment LightningSendFeeEstimateOutputFragment on LightningSendFeeEstimateOutput {
2330
2440
  __typename
2331
2441
  lightning_send_fee_estimate_output_fee_estimate: fee_estimate {
@@ -2348,7 +2458,7 @@ var StaticDepositQuoteOutputFromJson = (obj) => {
2348
2458
  signature: obj["static_deposit_quote_output_signature"]
2349
2459
  };
2350
2460
  };
2351
- var FRAGMENT12 = `
2461
+ var FRAGMENT13 = `
2352
2462
  fragment StaticDepositQuoteOutputFragment on StaticDepositQuoteOutput {
2353
2463
  __typename
2354
2464
  static_deposit_quote_output_transaction_id: transaction_id
@@ -2393,7 +2503,27 @@ var GetClaimDepositQuote = `
2393
2503
  ...StaticDepositQuoteOutputFragment
2394
2504
  }
2395
2505
  }
2396
- ${FRAGMENT12}
2506
+ ${FRAGMENT13}
2507
+ `;
2508
+
2509
+ // src/graphql/queries/GetCoopExitFeeQuote.ts
2510
+ var GetCoopExitFeeQuote = `
2511
+ query CoopExitFeeQuote(
2512
+ $leaf_external_ids: [UUID!]!
2513
+ $withdrawal_address: String!
2514
+ ) {
2515
+ coop_exit_fee_quote(
2516
+ input: {
2517
+ leaf_external_ids: $leaf_external_ids,
2518
+ withdrawal_address: $withdrawal_address
2519
+ }
2520
+ ) {
2521
+ quote {
2522
+ ...CoopExitFeeQuoteFragment
2523
+ }
2524
+ }
2525
+ }
2526
+ ${FRAGMENT10}
2397
2527
  `;
2398
2528
 
2399
2529
  // src/graphql/queries/LeavesSwapFeeEstimate.ts
@@ -2409,7 +2539,7 @@ var LeavesSwapFeeEstimate = `
2409
2539
  ...LeavesSwapFeeEstimateOutputFragment
2410
2540
  }
2411
2541
  }
2412
- ${FRAGMENT10}
2542
+ ${FRAGMENT11}
2413
2543
  `;
2414
2544
 
2415
2545
  // src/graphql/queries/LightningSendFeeEstimate.ts
@@ -2427,7 +2557,7 @@ var LightningSendFeeEstimate = `
2427
2557
  ...LightningSendFeeEstimateOutputFragment
2428
2558
  }
2429
2559
  }
2430
- ${FRAGMENT11}
2560
+ ${FRAGMENT12}
2431
2561
  `;
2432
2562
 
2433
2563
  // src/graphql/queries/Transfer.ts
@@ -2441,8 +2571,8 @@ var GetTransfer = `
2441
2571
  `;
2442
2572
 
2443
2573
  // src/graphql/objects/UserRequest.ts
2444
- import { LightsparkException, isObject as isObject5 } from "@lightsparkdev/core";
2445
- var FRAGMENT13 = `
2574
+ import { LightsparkException, isObject as isObject6 } from "@lightsparkdev/core";
2575
+ var FRAGMENT14 = `
2446
2576
  fragment UserRequestFragment on UserRequest {
2447
2577
  __typename
2448
2578
  ... on ClaimStaticDeposit {
@@ -2674,7 +2804,7 @@ var UserRequest2 = `
2674
2804
  ...UserRequestFragment
2675
2805
  }
2676
2806
  }
2677
- ${FRAGMENT13}
2807
+ ${FRAGMENT14}
2678
2808
  `;
2679
2809
 
2680
2810
  // src/graphql/client.ts
@@ -2796,7 +2926,10 @@ var SspClient = class {
2796
2926
  leafExternalIds,
2797
2927
  withdrawalAddress,
2798
2928
  idempotencyKey,
2799
- exitSpeed
2929
+ exitSpeed,
2930
+ feeLeafExternalIds,
2931
+ feeQuoteId,
2932
+ withdrawAll
2800
2933
  }) {
2801
2934
  return await this.executeRawQuery({
2802
2935
  queryPayload: RequestCoopExit,
@@ -2804,7 +2937,10 @@ var SspClient = class {
2804
2937
  leaf_external_ids: leafExternalIds,
2805
2938
  withdrawal_address: withdrawalAddress,
2806
2939
  idempotency_key: idempotencyKey,
2807
- exit_speed: exitSpeed
2940
+ exit_speed: exitSpeed,
2941
+ fee_leaf_external_ids: feeLeafExternalIds,
2942
+ fee_quote_id: feeQuoteId,
2943
+ withdraw_all: withdrawAll
2808
2944
  },
2809
2945
  constructObject: (response) => {
2810
2946
  return CoopExitRequestFromJson(response.request_coop_exit.request);
@@ -2866,7 +3002,8 @@ var SspClient = class {
2866
3002
  targetAmountSats,
2867
3003
  feeSats,
2868
3004
  userLeaves,
2869
- idempotencyKey
3005
+ idempotencyKey,
3006
+ targetAmountSatsList
2870
3007
  }) {
2871
3008
  const query = {
2872
3009
  queryPayload: RequestSwapLeaves,
@@ -2876,7 +3013,8 @@ var SspClient = class {
2876
3013
  target_amount_sats: targetAmountSats,
2877
3014
  fee_sats: feeSats,
2878
3015
  user_leaves: userLeaves,
2879
- idempotency_key: idempotencyKey
3016
+ idempotency_key: idempotencyKey,
3017
+ target_amount_sats_list: targetAmountSatsList
2880
3018
  },
2881
3019
  constructObject: (response) => {
2882
3020
  if (!response.request_leaves_swap) {
@@ -3068,6 +3206,21 @@ var SspClient = class {
3068
3206
  new Date(verifyChallenge.validUntil)
3069
3207
  );
3070
3208
  }
3209
+ async getCoopExitFeeQuote({
3210
+ leafExternalIds,
3211
+ withdrawalAddress
3212
+ }) {
3213
+ return await this.executeRawQuery({
3214
+ queryPayload: GetCoopExitFeeQuote,
3215
+ variables: {
3216
+ leaf_external_ids: leafExternalIds,
3217
+ withdrawal_address: withdrawalAddress
3218
+ },
3219
+ constructObject: (response) => {
3220
+ return CoopExitFeeQuoteFromJson(response.coop_exit_fee_quote.quote);
3221
+ }
3222
+ });
3223
+ }
3071
3224
  };
3072
3225
  var SparkAuthProvider = class {
3073
3226
  sessionToken;
@@ -3105,9 +3258,6 @@ var SparkAuthProvider = class {
3105
3258
  };
3106
3259
 
3107
3260
  // src/graphql/objects/ClaimStaticDeposit.ts
3108
- import { isObject as isObject6 } from "@lightsparkdev/core";
3109
-
3110
- // src/graphql/objects/CoopExitFeeQuote.ts
3111
3261
  import { isObject as isObject7 } from "@lightsparkdev/core";
3112
3262
 
3113
3263
  // src/graphql/objects/SparkWalletUser.ts
@@ -3482,7 +3632,7 @@ var TransferStatus = /* @__PURE__ */ ((TransferStatus2) => {
3482
3632
  TransferStatus2[TransferStatus2["TRANSFER_STATUS_SENDER_KEY_TWEAK_PENDING"] = 1] = "TRANSFER_STATUS_SENDER_KEY_TWEAK_PENDING";
3483
3633
  TransferStatus2[TransferStatus2["TRANSFER_STATUS_SENDER_KEY_TWEAKED"] = 2] = "TRANSFER_STATUS_SENDER_KEY_TWEAKED";
3484
3634
  TransferStatus2[TransferStatus2["TRANSFER_STATUS_RECEIVER_KEY_TWEAKED"] = 3] = "TRANSFER_STATUS_RECEIVER_KEY_TWEAKED";
3485
- TransferStatus2[TransferStatus2["TRANSFER_STATUSR_RECEIVER_REFUND_SIGNED"] = 4] = "TRANSFER_STATUSR_RECEIVER_REFUND_SIGNED";
3635
+ TransferStatus2[TransferStatus2["TRANSFER_STATUS_RECEIVER_REFUND_SIGNED"] = 4] = "TRANSFER_STATUS_RECEIVER_REFUND_SIGNED";
3486
3636
  TransferStatus2[TransferStatus2["TRANSFER_STATUS_COMPLETED"] = 5] = "TRANSFER_STATUS_COMPLETED";
3487
3637
  TransferStatus2[TransferStatus2["TRANSFER_STATUS_EXPIRED"] = 6] = "TRANSFER_STATUS_EXPIRED";
3488
3638
  TransferStatus2[TransferStatus2["TRANSFER_STATUS_RETURNED"] = 7] = "TRANSFER_STATUS_RETURNED";
@@ -3507,8 +3657,8 @@ function transferStatusFromJSON(object) {
3507
3657
  case "TRANSFER_STATUS_RECEIVER_KEY_TWEAKED":
3508
3658
  return 3 /* TRANSFER_STATUS_RECEIVER_KEY_TWEAKED */;
3509
3659
  case 4:
3510
- case "TRANSFER_STATUSR_RECEIVER_REFUND_SIGNED":
3511
- return 4 /* TRANSFER_STATUSR_RECEIVER_REFUND_SIGNED */;
3660
+ case "TRANSFER_STATUS_RECEIVER_REFUND_SIGNED":
3661
+ return 4 /* TRANSFER_STATUS_RECEIVER_REFUND_SIGNED */;
3512
3662
  case 5:
3513
3663
  case "TRANSFER_STATUS_COMPLETED":
3514
3664
  return 5 /* TRANSFER_STATUS_COMPLETED */;
@@ -3543,8 +3693,8 @@ function transferStatusToJSON(object) {
3543
3693
  return "TRANSFER_STATUS_SENDER_KEY_TWEAKED";
3544
3694
  case 3 /* TRANSFER_STATUS_RECEIVER_KEY_TWEAKED */:
3545
3695
  return "TRANSFER_STATUS_RECEIVER_KEY_TWEAKED";
3546
- case 4 /* TRANSFER_STATUSR_RECEIVER_REFUND_SIGNED */:
3547
- return "TRANSFER_STATUSR_RECEIVER_REFUND_SIGNED";
3696
+ case 4 /* TRANSFER_STATUS_RECEIVER_REFUND_SIGNED */:
3697
+ return "TRANSFER_STATUS_RECEIVER_REFUND_SIGNED";
3548
3698
  case 5 /* TRANSFER_STATUS_COMPLETED */:
3549
3699
  return "TRANSFER_STATUS_COMPLETED";
3550
3700
  case 6 /* TRANSFER_STATUS_EXPIRED */:
@@ -4636,7 +4786,7 @@ var SigningJob = {
4636
4786
  }
4637
4787
  };
4638
4788
  function createBaseSigningKeyshare() {
4639
- return { ownerIdentifiers: [], threshold: 0, publicKey: new Uint8Array(0) };
4789
+ return { ownerIdentifiers: [], threshold: 0, publicKey: new Uint8Array(0), publicShares: {}, updatedTime: void 0 };
4640
4790
  }
4641
4791
  var SigningKeyshare = {
4642
4792
  encode(message, writer = new BinaryWriter4()) {
@@ -4649,6 +4799,12 @@ var SigningKeyshare = {
4649
4799
  if (message.publicKey.length !== 0) {
4650
4800
  writer.uint32(26).bytes(message.publicKey);
4651
4801
  }
4802
+ Object.entries(message.publicShares).forEach(([key, value]) => {
4803
+ SigningKeyshare_PublicSharesEntry.encode({ key, value }, writer.uint32(34).fork()).join();
4804
+ });
4805
+ if (message.updatedTime !== void 0) {
4806
+ Timestamp.encode(toTimestamp(message.updatedTime), writer.uint32(42).fork()).join();
4807
+ }
4652
4808
  return writer;
4653
4809
  },
4654
4810
  decode(input, length) {
@@ -4679,6 +4835,23 @@ var SigningKeyshare = {
4679
4835
  message.publicKey = reader.bytes();
4680
4836
  continue;
4681
4837
  }
4838
+ case 4: {
4839
+ if (tag !== 34) {
4840
+ break;
4841
+ }
4842
+ const entry4 = SigningKeyshare_PublicSharesEntry.decode(reader, reader.uint32());
4843
+ if (entry4.value !== void 0) {
4844
+ message.publicShares[entry4.key] = entry4.value;
4845
+ }
4846
+ continue;
4847
+ }
4848
+ case 5: {
4849
+ if (tag !== 42) {
4850
+ break;
4851
+ }
4852
+ message.updatedTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
4853
+ continue;
4854
+ }
4682
4855
  }
4683
4856
  if ((tag & 7) === 4 || tag === 0) {
4684
4857
  break;
@@ -4691,7 +4864,12 @@ var SigningKeyshare = {
4691
4864
  return {
4692
4865
  ownerIdentifiers: globalThis.Array.isArray(object?.ownerIdentifiers) ? object.ownerIdentifiers.map((e) => globalThis.String(e)) : [],
4693
4866
  threshold: isSet3(object.threshold) ? globalThis.Number(object.threshold) : 0,
4694
- publicKey: isSet3(object.publicKey) ? bytesFromBase642(object.publicKey) : new Uint8Array(0)
4867
+ publicKey: isSet3(object.publicKey) ? bytesFromBase642(object.publicKey) : new Uint8Array(0),
4868
+ publicShares: isObject9(object.publicShares) ? Object.entries(object.publicShares).reduce((acc, [key, value]) => {
4869
+ acc[key] = bytesFromBase642(value);
4870
+ return acc;
4871
+ }, {}) : {},
4872
+ updatedTime: isSet3(object.updatedTime) ? fromJsonTimestamp(object.updatedTime) : void 0
4695
4873
  };
4696
4874
  },
4697
4875
  toJSON(message) {
@@ -4705,6 +4883,18 @@ var SigningKeyshare = {
4705
4883
  if (message.publicKey.length !== 0) {
4706
4884
  obj.publicKey = base64FromBytes2(message.publicKey);
4707
4885
  }
4886
+ if (message.publicShares) {
4887
+ const entries = Object.entries(message.publicShares);
4888
+ if (entries.length > 0) {
4889
+ obj.publicShares = {};
4890
+ entries.forEach(([k, v]) => {
4891
+ obj.publicShares[k] = base64FromBytes2(v);
4892
+ });
4893
+ }
4894
+ }
4895
+ if (message.updatedTime !== void 0) {
4896
+ obj.updatedTime = message.updatedTime.toISOString();
4897
+ }
4708
4898
  return obj;
4709
4899
  },
4710
4900
  create(base) {
@@ -4715,6 +4905,84 @@ var SigningKeyshare = {
4715
4905
  message.ownerIdentifiers = object.ownerIdentifiers?.map((e) => e) || [];
4716
4906
  message.threshold = object.threshold ?? 0;
4717
4907
  message.publicKey = object.publicKey ?? new Uint8Array(0);
4908
+ message.publicShares = Object.entries(object.publicShares ?? {}).reduce(
4909
+ (acc, [key, value]) => {
4910
+ if (value !== void 0) {
4911
+ acc[key] = value;
4912
+ }
4913
+ return acc;
4914
+ },
4915
+ {}
4916
+ );
4917
+ message.updatedTime = object.updatedTime ?? void 0;
4918
+ return message;
4919
+ }
4920
+ };
4921
+ function createBaseSigningKeyshare_PublicSharesEntry() {
4922
+ return { key: "", value: new Uint8Array(0) };
4923
+ }
4924
+ var SigningKeyshare_PublicSharesEntry = {
4925
+ encode(message, writer = new BinaryWriter4()) {
4926
+ if (message.key !== "") {
4927
+ writer.uint32(10).string(message.key);
4928
+ }
4929
+ if (message.value.length !== 0) {
4930
+ writer.uint32(18).bytes(message.value);
4931
+ }
4932
+ return writer;
4933
+ },
4934
+ decode(input, length) {
4935
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
4936
+ let end = length === void 0 ? reader.len : reader.pos + length;
4937
+ const message = createBaseSigningKeyshare_PublicSharesEntry();
4938
+ while (reader.pos < end) {
4939
+ const tag = reader.uint32();
4940
+ switch (tag >>> 3) {
4941
+ case 1: {
4942
+ if (tag !== 10) {
4943
+ break;
4944
+ }
4945
+ message.key = reader.string();
4946
+ continue;
4947
+ }
4948
+ case 2: {
4949
+ if (tag !== 18) {
4950
+ break;
4951
+ }
4952
+ message.value = reader.bytes();
4953
+ continue;
4954
+ }
4955
+ }
4956
+ if ((tag & 7) === 4 || tag === 0) {
4957
+ break;
4958
+ }
4959
+ reader.skip(tag & 7);
4960
+ }
4961
+ return message;
4962
+ },
4963
+ fromJSON(object) {
4964
+ return {
4965
+ key: isSet3(object.key) ? globalThis.String(object.key) : "",
4966
+ value: isSet3(object.value) ? bytesFromBase642(object.value) : new Uint8Array(0)
4967
+ };
4968
+ },
4969
+ toJSON(message) {
4970
+ const obj = {};
4971
+ if (message.key !== "") {
4972
+ obj.key = message.key;
4973
+ }
4974
+ if (message.value.length !== 0) {
4975
+ obj.value = base64FromBytes2(message.value);
4976
+ }
4977
+ return obj;
4978
+ },
4979
+ create(base) {
4980
+ return SigningKeyshare_PublicSharesEntry.fromPartial(base ?? {});
4981
+ },
4982
+ fromPartial(object) {
4983
+ const message = createBaseSigningKeyshare_PublicSharesEntry();
4984
+ message.key = object.key ?? "";
4985
+ message.value = object.value ?? new Uint8Array(0);
4718
4986
  return message;
4719
4987
  }
4720
4988
  };
@@ -6411,7 +6679,8 @@ function createBaseStartTokenTransactionRequest() {
6411
6679
  return {
6412
6680
  identityPublicKey: new Uint8Array(0),
6413
6681
  partialTokenTransaction: void 0,
6414
- tokenTransactionSignatures: void 0
6682
+ tokenTransactionSignatures: void 0,
6683
+ sparkPaymentIntent: ""
6415
6684
  };
6416
6685
  }
6417
6686
  var StartTokenTransactionRequest = {
@@ -6425,6 +6694,9 @@ var StartTokenTransactionRequest = {
6425
6694
  if (message.tokenTransactionSignatures !== void 0) {
6426
6695
  TokenTransactionSignatures.encode(message.tokenTransactionSignatures, writer.uint32(26).fork()).join();
6427
6696
  }
6697
+ if (message.sparkPaymentIntent !== "") {
6698
+ writer.uint32(34).string(message.sparkPaymentIntent);
6699
+ }
6428
6700
  return writer;
6429
6701
  },
6430
6702
  decode(input, length) {
@@ -6455,6 +6727,13 @@ var StartTokenTransactionRequest = {
6455
6727
  message.tokenTransactionSignatures = TokenTransactionSignatures.decode(reader, reader.uint32());
6456
6728
  continue;
6457
6729
  }
6730
+ case 4: {
6731
+ if (tag !== 34) {
6732
+ break;
6733
+ }
6734
+ message.sparkPaymentIntent = reader.string();
6735
+ continue;
6736
+ }
6458
6737
  }
6459
6738
  if ((tag & 7) === 4 || tag === 0) {
6460
6739
  break;
@@ -6467,7 +6746,8 @@ var StartTokenTransactionRequest = {
6467
6746
  return {
6468
6747
  identityPublicKey: isSet3(object.identityPublicKey) ? bytesFromBase642(object.identityPublicKey) : new Uint8Array(0),
6469
6748
  partialTokenTransaction: isSet3(object.partialTokenTransaction) ? TokenTransaction.fromJSON(object.partialTokenTransaction) : void 0,
6470
- tokenTransactionSignatures: isSet3(object.tokenTransactionSignatures) ? TokenTransactionSignatures.fromJSON(object.tokenTransactionSignatures) : void 0
6749
+ tokenTransactionSignatures: isSet3(object.tokenTransactionSignatures) ? TokenTransactionSignatures.fromJSON(object.tokenTransactionSignatures) : void 0,
6750
+ sparkPaymentIntent: isSet3(object.sparkPaymentIntent) ? globalThis.String(object.sparkPaymentIntent) : ""
6471
6751
  };
6472
6752
  },
6473
6753
  toJSON(message) {
@@ -6481,6 +6761,9 @@ var StartTokenTransactionRequest = {
6481
6761
  if (message.tokenTransactionSignatures !== void 0) {
6482
6762
  obj.tokenTransactionSignatures = TokenTransactionSignatures.toJSON(message.tokenTransactionSignatures);
6483
6763
  }
6764
+ if (message.sparkPaymentIntent !== "") {
6765
+ obj.sparkPaymentIntent = message.sparkPaymentIntent;
6766
+ }
6484
6767
  return obj;
6485
6768
  },
6486
6769
  create(base) {
@@ -6491,6 +6774,7 @@ var StartTokenTransactionRequest = {
6491
6774
  message.identityPublicKey = object.identityPublicKey ?? new Uint8Array(0);
6492
6775
  message.partialTokenTransaction = object.partialTokenTransaction !== void 0 && object.partialTokenTransaction !== null ? TokenTransaction.fromPartial(object.partialTokenTransaction) : void 0;
6493
6776
  message.tokenTransactionSignatures = object.tokenTransactionSignatures !== void 0 && object.tokenTransactionSignatures !== null ? TokenTransactionSignatures.fromPartial(object.tokenTransactionSignatures) : void 0;
6777
+ message.sparkPaymentIntent = object.sparkPaymentIntent ?? "";
6494
6778
  return message;
6495
6779
  }
6496
6780
  };
@@ -6988,7 +7272,12 @@ var RevocationSecretWithIndex = {
6988
7272
  }
6989
7273
  };
6990
7274
  function createBaseFinalizeTokenTransactionRequest() {
6991
- return { finalTokenTransaction: void 0, revocationSecrets: [], identityPublicKey: new Uint8Array(0) };
7275
+ return {
7276
+ finalTokenTransaction: void 0,
7277
+ revocationSecrets: [],
7278
+ identityPublicKey: new Uint8Array(0),
7279
+ sparkPaymentIntent: ""
7280
+ };
6992
7281
  }
6993
7282
  var FinalizeTokenTransactionRequest = {
6994
7283
  encode(message, writer = new BinaryWriter4()) {
@@ -7001,6 +7290,9 @@ var FinalizeTokenTransactionRequest = {
7001
7290
  if (message.identityPublicKey.length !== 0) {
7002
7291
  writer.uint32(26).bytes(message.identityPublicKey);
7003
7292
  }
7293
+ if (message.sparkPaymentIntent !== "") {
7294
+ writer.uint32(34).string(message.sparkPaymentIntent);
7295
+ }
7004
7296
  return writer;
7005
7297
  },
7006
7298
  decode(input, length) {
@@ -7031,6 +7323,13 @@ var FinalizeTokenTransactionRequest = {
7031
7323
  message.identityPublicKey = reader.bytes();
7032
7324
  continue;
7033
7325
  }
7326
+ case 4: {
7327
+ if (tag !== 34) {
7328
+ break;
7329
+ }
7330
+ message.sparkPaymentIntent = reader.string();
7331
+ continue;
7332
+ }
7034
7333
  }
7035
7334
  if ((tag & 7) === 4 || tag === 0) {
7036
7335
  break;
@@ -7043,7 +7342,8 @@ var FinalizeTokenTransactionRequest = {
7043
7342
  return {
7044
7343
  finalTokenTransaction: isSet3(object.finalTokenTransaction) ? TokenTransaction.fromJSON(object.finalTokenTransaction) : void 0,
7045
7344
  revocationSecrets: globalThis.Array.isArray(object?.revocationSecrets) ? object.revocationSecrets.map((e) => RevocationSecretWithIndex.fromJSON(e)) : [],
7046
- identityPublicKey: isSet3(object.identityPublicKey) ? bytesFromBase642(object.identityPublicKey) : new Uint8Array(0)
7345
+ identityPublicKey: isSet3(object.identityPublicKey) ? bytesFromBase642(object.identityPublicKey) : new Uint8Array(0),
7346
+ sparkPaymentIntent: isSet3(object.sparkPaymentIntent) ? globalThis.String(object.sparkPaymentIntent) : ""
7047
7347
  };
7048
7348
  },
7049
7349
  toJSON(message) {
@@ -7057,6 +7357,9 @@ var FinalizeTokenTransactionRequest = {
7057
7357
  if (message.identityPublicKey.length !== 0) {
7058
7358
  obj.identityPublicKey = base64FromBytes2(message.identityPublicKey);
7059
7359
  }
7360
+ if (message.sparkPaymentIntent !== "") {
7361
+ obj.sparkPaymentIntent = message.sparkPaymentIntent;
7362
+ }
7060
7363
  return obj;
7061
7364
  },
7062
7365
  create(base) {
@@ -7067,6 +7370,7 @@ var FinalizeTokenTransactionRequest = {
7067
7370
  message.finalTokenTransaction = object.finalTokenTransaction !== void 0 && object.finalTokenTransaction !== null ? TokenTransaction.fromPartial(object.finalTokenTransaction) : void 0;
7068
7371
  message.revocationSecrets = object.revocationSecrets?.map((e) => RevocationSecretWithIndex.fromPartial(e)) || [];
7069
7372
  message.identityPublicKey = object.identityPublicKey ?? new Uint8Array(0);
7373
+ message.sparkPaymentIntent = object.sparkPaymentIntent ?? "";
7070
7374
  return message;
7071
7375
  }
7072
7376
  };
@@ -7759,7 +8063,10 @@ function createBaseTreeNode() {
7759
8063
  ownerIdentityPublicKey: new Uint8Array(0),
7760
8064
  signingKeyshare: void 0,
7761
8065
  status: "",
7762
- network: 0
8066
+ network: 0,
8067
+ createdTime: void 0,
8068
+ updatedTime: void 0,
8069
+ ownerSigningPublicKey: new Uint8Array(0)
7763
8070
  };
7764
8071
  }
7765
8072
  var TreeNode = {
@@ -7800,6 +8107,15 @@ var TreeNode = {
7800
8107
  if (message.network !== 0) {
7801
8108
  writer.uint32(96).int32(message.network);
7802
8109
  }
8110
+ if (message.createdTime !== void 0) {
8111
+ Timestamp.encode(toTimestamp(message.createdTime), writer.uint32(106).fork()).join();
8112
+ }
8113
+ if (message.updatedTime !== void 0) {
8114
+ Timestamp.encode(toTimestamp(message.updatedTime), writer.uint32(114).fork()).join();
8115
+ }
8116
+ if (message.ownerSigningPublicKey.length !== 0) {
8117
+ writer.uint32(122).bytes(message.ownerSigningPublicKey);
8118
+ }
7803
8119
  return writer;
7804
8120
  },
7805
8121
  decode(input, length) {
@@ -7893,6 +8209,27 @@ var TreeNode = {
7893
8209
  message.network = reader.int32();
7894
8210
  continue;
7895
8211
  }
8212
+ case 13: {
8213
+ if (tag !== 106) {
8214
+ break;
8215
+ }
8216
+ message.createdTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
8217
+ continue;
8218
+ }
8219
+ case 14: {
8220
+ if (tag !== 114) {
8221
+ break;
8222
+ }
8223
+ message.updatedTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
8224
+ continue;
8225
+ }
8226
+ case 15: {
8227
+ if (tag !== 122) {
8228
+ break;
8229
+ }
8230
+ message.ownerSigningPublicKey = reader.bytes();
8231
+ continue;
8232
+ }
7896
8233
  }
7897
8234
  if ((tag & 7) === 4 || tag === 0) {
7898
8235
  break;
@@ -7914,7 +8251,10 @@ var TreeNode = {
7914
8251
  ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
7915
8252
  signingKeyshare: isSet3(object.signingKeyshare) ? SigningKeyshare.fromJSON(object.signingKeyshare) : void 0,
7916
8253
  status: isSet3(object.status) ? globalThis.String(object.status) : "",
7917
- network: isSet3(object.network) ? networkFromJSON(object.network) : 0
8254
+ network: isSet3(object.network) ? networkFromJSON(object.network) : 0,
8255
+ createdTime: isSet3(object.createdTime) ? fromJsonTimestamp(object.createdTime) : void 0,
8256
+ updatedTime: isSet3(object.updatedTime) ? fromJsonTimestamp(object.updatedTime) : void 0,
8257
+ ownerSigningPublicKey: isSet3(object.ownerSigningPublicKey) ? bytesFromBase642(object.ownerSigningPublicKey) : new Uint8Array(0)
7918
8258
  };
7919
8259
  },
7920
8260
  toJSON(message) {
@@ -7955,6 +8295,15 @@ var TreeNode = {
7955
8295
  if (message.network !== 0) {
7956
8296
  obj.network = networkToJSON(message.network);
7957
8297
  }
8298
+ if (message.createdTime !== void 0) {
8299
+ obj.createdTime = message.createdTime.toISOString();
8300
+ }
8301
+ if (message.updatedTime !== void 0) {
8302
+ obj.updatedTime = message.updatedTime.toISOString();
8303
+ }
8304
+ if (message.ownerSigningPublicKey.length !== 0) {
8305
+ obj.ownerSigningPublicKey = base64FromBytes2(message.ownerSigningPublicKey);
8306
+ }
7958
8307
  return obj;
7959
8308
  },
7960
8309
  create(base) {
@@ -7974,6 +8323,9 @@ var TreeNode = {
7974
8323
  message.signingKeyshare = object.signingKeyshare !== void 0 && object.signingKeyshare !== null ? SigningKeyshare.fromPartial(object.signingKeyshare) : void 0;
7975
8324
  message.status = object.status ?? "";
7976
8325
  message.network = object.network ?? 0;
8326
+ message.createdTime = object.createdTime ?? void 0;
8327
+ message.updatedTime = object.updatedTime ?? void 0;
8328
+ message.ownerSigningPublicKey = object.ownerSigningPublicKey ?? new Uint8Array(0);
7977
8329
  return message;
7978
8330
  }
7979
8331
  };
@@ -8576,7 +8928,8 @@ function createBaseStartTransferRequest() {
8576
8928
  leavesToSend: [],
8577
8929
  receiverIdentityPublicKey: new Uint8Array(0),
8578
8930
  expiryTime: void 0,
8579
- transferPackage: void 0
8931
+ transferPackage: void 0,
8932
+ sparkPaymentIntent: ""
8580
8933
  };
8581
8934
  }
8582
8935
  var StartTransferRequest = {
@@ -8599,6 +8952,9 @@ var StartTransferRequest = {
8599
8952
  if (message.transferPackage !== void 0) {
8600
8953
  TransferPackage.encode(message.transferPackage, writer.uint32(58).fork()).join();
8601
8954
  }
8955
+ if (message.sparkPaymentIntent !== "") {
8956
+ writer.uint32(74).string(message.sparkPaymentIntent);
8957
+ }
8602
8958
  return writer;
8603
8959
  },
8604
8960
  decode(input, length) {
@@ -8650,6 +9006,13 @@ var StartTransferRequest = {
8650
9006
  message.transferPackage = TransferPackage.decode(reader, reader.uint32());
8651
9007
  continue;
8652
9008
  }
9009
+ case 9: {
9010
+ if (tag !== 74) {
9011
+ break;
9012
+ }
9013
+ message.sparkPaymentIntent = reader.string();
9014
+ continue;
9015
+ }
8653
9016
  }
8654
9017
  if ((tag & 7) === 4 || tag === 0) {
8655
9018
  break;
@@ -8665,7 +9028,8 @@ var StartTransferRequest = {
8665
9028
  leavesToSend: globalThis.Array.isArray(object?.leavesToSend) ? object.leavesToSend.map((e) => LeafRefundTxSigningJob.fromJSON(e)) : [],
8666
9029
  receiverIdentityPublicKey: isSet3(object.receiverIdentityPublicKey) ? bytesFromBase642(object.receiverIdentityPublicKey) : new Uint8Array(0),
8667
9030
  expiryTime: isSet3(object.expiryTime) ? fromJsonTimestamp(object.expiryTime) : void 0,
8668
- transferPackage: isSet3(object.transferPackage) ? TransferPackage.fromJSON(object.transferPackage) : void 0
9031
+ transferPackage: isSet3(object.transferPackage) ? TransferPackage.fromJSON(object.transferPackage) : void 0,
9032
+ sparkPaymentIntent: isSet3(object.sparkPaymentIntent) ? globalThis.String(object.sparkPaymentIntent) : ""
8669
9033
  };
8670
9034
  },
8671
9035
  toJSON(message) {
@@ -8688,6 +9052,9 @@ var StartTransferRequest = {
8688
9052
  if (message.transferPackage !== void 0) {
8689
9053
  obj.transferPackage = TransferPackage.toJSON(message.transferPackage);
8690
9054
  }
9055
+ if (message.sparkPaymentIntent !== "") {
9056
+ obj.sparkPaymentIntent = message.sparkPaymentIntent;
9057
+ }
8691
9058
  return obj;
8692
9059
  },
8693
9060
  create(base) {
@@ -8701,6 +9068,7 @@ var StartTransferRequest = {
8701
9068
  message.receiverIdentityPublicKey = object.receiverIdentityPublicKey ?? new Uint8Array(0);
8702
9069
  message.expiryTime = object.expiryTime ?? void 0;
8703
9070
  message.transferPackage = object.transferPackage !== void 0 && object.transferPackage !== null ? TransferPackage.fromPartial(object.transferPackage) : void 0;
9071
+ message.sparkPaymentIntent = object.sparkPaymentIntent ?? "";
8704
9072
  return message;
8705
9073
  }
8706
9074
  };
@@ -9220,7 +9588,7 @@ var SendLeafKeyTweak_PubkeySharesTweakEntry = {
9220
9588
  }
9221
9589
  };
9222
9590
  function createBaseFinalizeTransferRequest() {
9223
- return { transferId: "", ownerIdentityPublicKey: new Uint8Array(0), leavesToSend: [] };
9591
+ return { transferId: "", ownerIdentityPublicKey: new Uint8Array(0), leavesToSend: [], sparkPaymentIntent: "" };
9224
9592
  }
9225
9593
  var FinalizeTransferRequest = {
9226
9594
  encode(message, writer = new BinaryWriter4()) {
@@ -9233,6 +9601,9 @@ var FinalizeTransferRequest = {
9233
9601
  for (const v of message.leavesToSend) {
9234
9602
  SendLeafKeyTweak.encode(v, writer.uint32(26).fork()).join();
9235
9603
  }
9604
+ if (message.sparkPaymentIntent !== "") {
9605
+ writer.uint32(34).string(message.sparkPaymentIntent);
9606
+ }
9236
9607
  return writer;
9237
9608
  },
9238
9609
  decode(input, length) {
@@ -9263,6 +9634,13 @@ var FinalizeTransferRequest = {
9263
9634
  message.leavesToSend.push(SendLeafKeyTweak.decode(reader, reader.uint32()));
9264
9635
  continue;
9265
9636
  }
9637
+ case 4: {
9638
+ if (tag !== 34) {
9639
+ break;
9640
+ }
9641
+ message.sparkPaymentIntent = reader.string();
9642
+ continue;
9643
+ }
9266
9644
  }
9267
9645
  if ((tag & 7) === 4 || tag === 0) {
9268
9646
  break;
@@ -9275,7 +9653,8 @@ var FinalizeTransferRequest = {
9275
9653
  return {
9276
9654
  transferId: isSet3(object.transferId) ? globalThis.String(object.transferId) : "",
9277
9655
  ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
9278
- leavesToSend: globalThis.Array.isArray(object?.leavesToSend) ? object.leavesToSend.map((e) => SendLeafKeyTweak.fromJSON(e)) : []
9656
+ leavesToSend: globalThis.Array.isArray(object?.leavesToSend) ? object.leavesToSend.map((e) => SendLeafKeyTweak.fromJSON(e)) : [],
9657
+ sparkPaymentIntent: isSet3(object.sparkPaymentIntent) ? globalThis.String(object.sparkPaymentIntent) : ""
9279
9658
  };
9280
9659
  },
9281
9660
  toJSON(message) {
@@ -9289,6 +9668,9 @@ var FinalizeTransferRequest = {
9289
9668
  if (message.leavesToSend?.length) {
9290
9669
  obj.leavesToSend = message.leavesToSend.map((e) => SendLeafKeyTweak.toJSON(e));
9291
9670
  }
9671
+ if (message.sparkPaymentIntent !== "") {
9672
+ obj.sparkPaymentIntent = message.sparkPaymentIntent;
9673
+ }
9292
9674
  return obj;
9293
9675
  },
9294
9676
  create(base) {
@@ -9299,6 +9681,7 @@ var FinalizeTransferRequest = {
9299
9681
  message.transferId = object.transferId ?? "";
9300
9682
  message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
9301
9683
  message.leavesToSend = object.leavesToSend?.map((e) => SendLeafKeyTweak.fromPartial(e)) || [];
9684
+ message.sparkPaymentIntent = object.sparkPaymentIntent ?? "";
9302
9685
  return message;
9303
9686
  }
9304
9687
  };
@@ -9739,7 +10122,7 @@ var TransferLeaf = {
9739
10122
  }
9740
10123
  };
9741
10124
  function createBaseTransferFilter() {
9742
- return { participant: void 0, transferIds: [], limit: 0, offset: 0, types: [], network: 0 };
10125
+ return { participant: void 0, transferIds: [], limit: 0, offset: 0, types: [], network: 0, statuses: [] };
9743
10126
  }
9744
10127
  var TransferFilter = {
9745
10128
  encode(message, writer = new BinaryWriter4()) {
@@ -9771,6 +10154,11 @@ var TransferFilter = {
9771
10154
  if (message.network !== 0) {
9772
10155
  writer.uint32(32).int32(message.network);
9773
10156
  }
10157
+ writer.uint32(642).fork();
10158
+ for (const v of message.statuses) {
10159
+ writer.int32(v);
10160
+ }
10161
+ writer.join();
9774
10162
  return writer;
9775
10163
  },
9776
10164
  decode(input, length) {
@@ -9846,6 +10234,20 @@ var TransferFilter = {
9846
10234
  message.network = reader.int32();
9847
10235
  continue;
9848
10236
  }
10237
+ case 80: {
10238
+ if (tag === 640) {
10239
+ message.statuses.push(reader.int32());
10240
+ continue;
10241
+ }
10242
+ if (tag === 642) {
10243
+ const end2 = reader.uint32() + reader.pos;
10244
+ while (reader.pos < end2) {
10245
+ message.statuses.push(reader.int32());
10246
+ }
10247
+ continue;
10248
+ }
10249
+ break;
10250
+ }
9849
10251
  }
9850
10252
  if ((tag & 7) === 4 || tag === 0) {
9851
10253
  break;
@@ -9867,7 +10269,8 @@ var TransferFilter = {
9867
10269
  limit: isSet3(object.limit) ? globalThis.Number(object.limit) : 0,
9868
10270
  offset: isSet3(object.offset) ? globalThis.Number(object.offset) : 0,
9869
10271
  types: globalThis.Array.isArray(object?.types) ? object.types.map((e) => transferTypeFromJSON(e)) : [],
9870
- network: isSet3(object.network) ? networkFromJSON(object.network) : 0
10272
+ network: isSet3(object.network) ? networkFromJSON(object.network) : 0,
10273
+ statuses: globalThis.Array.isArray(object?.statuses) ? object.statuses.map((e) => transferStatusFromJSON(e)) : []
9871
10274
  };
9872
10275
  },
9873
10276
  toJSON(message) {
@@ -9894,6 +10297,9 @@ var TransferFilter = {
9894
10297
  if (message.network !== 0) {
9895
10298
  obj.network = networkToJSON(message.network);
9896
10299
  }
10300
+ if (message.statuses?.length) {
10301
+ obj.statuses = message.statuses.map((e) => transferStatusToJSON(e));
10302
+ }
9897
10303
  return obj;
9898
10304
  },
9899
10305
  create(base) {
@@ -9935,6 +10341,7 @@ var TransferFilter = {
9935
10341
  message.offset = object.offset ?? 0;
9936
10342
  message.types = object.types?.map((e) => e) || [];
9937
10343
  message.network = object.network ?? 0;
10344
+ message.statuses = object.statuses?.map((e) => e) || [];
9938
10345
  return message;
9939
10346
  }
9940
10347
  };
@@ -10233,189 +10640,53 @@ var ClaimTransferTweakKeysRequest = {
10233
10640
  return {
10234
10641
  transferId: isSet3(object.transferId) ? globalThis.String(object.transferId) : "",
10235
10642
  ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
10236
- leavesToReceive: globalThis.Array.isArray(object?.leavesToReceive) ? object.leavesToReceive.map((e) => ClaimLeafKeyTweak.fromJSON(e)) : []
10237
- };
10238
- },
10239
- toJSON(message) {
10240
- const obj = {};
10241
- if (message.transferId !== "") {
10242
- obj.transferId = message.transferId;
10243
- }
10244
- if (message.ownerIdentityPublicKey.length !== 0) {
10245
- obj.ownerIdentityPublicKey = base64FromBytes2(message.ownerIdentityPublicKey);
10246
- }
10247
- if (message.leavesToReceive?.length) {
10248
- obj.leavesToReceive = message.leavesToReceive.map((e) => ClaimLeafKeyTweak.toJSON(e));
10249
- }
10250
- return obj;
10251
- },
10252
- create(base) {
10253
- return ClaimTransferTweakKeysRequest.fromPartial(base ?? {});
10254
- },
10255
- fromPartial(object) {
10256
- const message = createBaseClaimTransferTweakKeysRequest();
10257
- message.transferId = object.transferId ?? "";
10258
- message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
10259
- message.leavesToReceive = object.leavesToReceive?.map((e) => ClaimLeafKeyTweak.fromPartial(e)) || [];
10260
- return message;
10261
- }
10262
- };
10263
- function createBaseClaimTransferSignRefundsRequest() {
10264
- return { transferId: "", ownerIdentityPublicKey: new Uint8Array(0), signingJobs: [] };
10265
- }
10266
- var ClaimTransferSignRefundsRequest = {
10267
- encode(message, writer = new BinaryWriter4()) {
10268
- if (message.transferId !== "") {
10269
- writer.uint32(10).string(message.transferId);
10270
- }
10271
- if (message.ownerIdentityPublicKey.length !== 0) {
10272
- writer.uint32(18).bytes(message.ownerIdentityPublicKey);
10273
- }
10274
- for (const v of message.signingJobs) {
10275
- LeafRefundTxSigningJob.encode(v, writer.uint32(26).fork()).join();
10276
- }
10277
- return writer;
10278
- },
10279
- decode(input, length) {
10280
- const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
10281
- let end = length === void 0 ? reader.len : reader.pos + length;
10282
- const message = createBaseClaimTransferSignRefundsRequest();
10283
- while (reader.pos < end) {
10284
- const tag = reader.uint32();
10285
- switch (tag >>> 3) {
10286
- case 1: {
10287
- if (tag !== 10) {
10288
- break;
10289
- }
10290
- message.transferId = reader.string();
10291
- continue;
10292
- }
10293
- case 2: {
10294
- if (tag !== 18) {
10295
- break;
10296
- }
10297
- message.ownerIdentityPublicKey = reader.bytes();
10298
- continue;
10299
- }
10300
- case 3: {
10301
- if (tag !== 26) {
10302
- break;
10303
- }
10304
- message.signingJobs.push(LeafRefundTxSigningJob.decode(reader, reader.uint32()));
10305
- continue;
10306
- }
10307
- }
10308
- if ((tag & 7) === 4 || tag === 0) {
10309
- break;
10310
- }
10311
- reader.skip(tag & 7);
10312
- }
10313
- return message;
10314
- },
10315
- fromJSON(object) {
10316
- return {
10317
- transferId: isSet3(object.transferId) ? globalThis.String(object.transferId) : "",
10318
- ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
10319
- signingJobs: globalThis.Array.isArray(object?.signingJobs) ? object.signingJobs.map((e) => LeafRefundTxSigningJob.fromJSON(e)) : []
10320
- };
10321
- },
10322
- toJSON(message) {
10323
- const obj = {};
10324
- if (message.transferId !== "") {
10325
- obj.transferId = message.transferId;
10326
- }
10327
- if (message.ownerIdentityPublicKey.length !== 0) {
10328
- obj.ownerIdentityPublicKey = base64FromBytes2(message.ownerIdentityPublicKey);
10329
- }
10330
- if (message.signingJobs?.length) {
10331
- obj.signingJobs = message.signingJobs.map((e) => LeafRefundTxSigningJob.toJSON(e));
10332
- }
10333
- return obj;
10334
- },
10335
- create(base) {
10336
- return ClaimTransferSignRefundsRequest.fromPartial(base ?? {});
10337
- },
10338
- fromPartial(object) {
10339
- const message = createBaseClaimTransferSignRefundsRequest();
10340
- message.transferId = object.transferId ?? "";
10341
- message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
10342
- message.signingJobs = object.signingJobs?.map((e) => LeafRefundTxSigningJob.fromPartial(e)) || [];
10343
- return message;
10344
- }
10345
- };
10346
- function createBaseClaimTransferSignRefundsResponse() {
10347
- return { signingResults: [] };
10348
- }
10349
- var ClaimTransferSignRefundsResponse = {
10350
- encode(message, writer = new BinaryWriter4()) {
10351
- for (const v of message.signingResults) {
10352
- LeafRefundTxSigningResult.encode(v, writer.uint32(10).fork()).join();
10353
- }
10354
- return writer;
10355
- },
10356
- decode(input, length) {
10357
- const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
10358
- let end = length === void 0 ? reader.len : reader.pos + length;
10359
- const message = createBaseClaimTransferSignRefundsResponse();
10360
- while (reader.pos < end) {
10361
- const tag = reader.uint32();
10362
- switch (tag >>> 3) {
10363
- case 1: {
10364
- if (tag !== 10) {
10365
- break;
10366
- }
10367
- message.signingResults.push(LeafRefundTxSigningResult.decode(reader, reader.uint32()));
10368
- continue;
10369
- }
10370
- }
10371
- if ((tag & 7) === 4 || tag === 0) {
10372
- break;
10373
- }
10374
- reader.skip(tag & 7);
10375
- }
10376
- return message;
10377
- },
10378
- fromJSON(object) {
10379
- return {
10380
- signingResults: globalThis.Array.isArray(object?.signingResults) ? object.signingResults.map((e) => LeafRefundTxSigningResult.fromJSON(e)) : []
10643
+ leavesToReceive: globalThis.Array.isArray(object?.leavesToReceive) ? object.leavesToReceive.map((e) => ClaimLeafKeyTweak.fromJSON(e)) : []
10381
10644
  };
10382
10645
  },
10383
10646
  toJSON(message) {
10384
10647
  const obj = {};
10385
- if (message.signingResults?.length) {
10386
- obj.signingResults = message.signingResults.map((e) => LeafRefundTxSigningResult.toJSON(e));
10648
+ if (message.transferId !== "") {
10649
+ obj.transferId = message.transferId;
10650
+ }
10651
+ if (message.ownerIdentityPublicKey.length !== 0) {
10652
+ obj.ownerIdentityPublicKey = base64FromBytes2(message.ownerIdentityPublicKey);
10653
+ }
10654
+ if (message.leavesToReceive?.length) {
10655
+ obj.leavesToReceive = message.leavesToReceive.map((e) => ClaimLeafKeyTweak.toJSON(e));
10387
10656
  }
10388
10657
  return obj;
10389
10658
  },
10390
10659
  create(base) {
10391
- return ClaimTransferSignRefundsResponse.fromPartial(base ?? {});
10660
+ return ClaimTransferTweakKeysRequest.fromPartial(base ?? {});
10392
10661
  },
10393
10662
  fromPartial(object) {
10394
- const message = createBaseClaimTransferSignRefundsResponse();
10395
- message.signingResults = object.signingResults?.map((e) => LeafRefundTxSigningResult.fromPartial(e)) || [];
10663
+ const message = createBaseClaimTransferTweakKeysRequest();
10664
+ message.transferId = object.transferId ?? "";
10665
+ message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
10666
+ message.leavesToReceive = object.leavesToReceive?.map((e) => ClaimLeafKeyTweak.fromPartial(e)) || [];
10396
10667
  return message;
10397
10668
  }
10398
10669
  };
10399
- function createBaseAggregateNodesRequest() {
10400
- return { nodeIds: [], signingJob: void 0, ownerIdentityPublicKey: new Uint8Array(0) };
10670
+ function createBaseClaimTransferSignRefundsRequest() {
10671
+ return { transferId: "", ownerIdentityPublicKey: new Uint8Array(0), signingJobs: [] };
10401
10672
  }
10402
- var AggregateNodesRequest = {
10673
+ var ClaimTransferSignRefundsRequest = {
10403
10674
  encode(message, writer = new BinaryWriter4()) {
10404
- for (const v of message.nodeIds) {
10405
- writer.uint32(10).string(v);
10406
- }
10407
- if (message.signingJob !== void 0) {
10408
- SigningJob.encode(message.signingJob, writer.uint32(18).fork()).join();
10675
+ if (message.transferId !== "") {
10676
+ writer.uint32(10).string(message.transferId);
10409
10677
  }
10410
10678
  if (message.ownerIdentityPublicKey.length !== 0) {
10411
- writer.uint32(26).bytes(message.ownerIdentityPublicKey);
10679
+ writer.uint32(18).bytes(message.ownerIdentityPublicKey);
10680
+ }
10681
+ for (const v of message.signingJobs) {
10682
+ LeafRefundTxSigningJob.encode(v, writer.uint32(26).fork()).join();
10412
10683
  }
10413
10684
  return writer;
10414
10685
  },
10415
10686
  decode(input, length) {
10416
10687
  const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
10417
10688
  let end = length === void 0 ? reader.len : reader.pos + length;
10418
- const message = createBaseAggregateNodesRequest();
10689
+ const message = createBaseClaimTransferSignRefundsRequest();
10419
10690
  while (reader.pos < end) {
10420
10691
  const tag = reader.uint32();
10421
10692
  switch (tag >>> 3) {
@@ -10423,21 +10694,21 @@ var AggregateNodesRequest = {
10423
10694
  if (tag !== 10) {
10424
10695
  break;
10425
10696
  }
10426
- message.nodeIds.push(reader.string());
10697
+ message.transferId = reader.string();
10427
10698
  continue;
10428
10699
  }
10429
10700
  case 2: {
10430
10701
  if (tag !== 18) {
10431
10702
  break;
10432
10703
  }
10433
- message.signingJob = SigningJob.decode(reader, reader.uint32());
10704
+ message.ownerIdentityPublicKey = reader.bytes();
10434
10705
  continue;
10435
10706
  }
10436
10707
  case 3: {
10437
10708
  if (tag !== 26) {
10438
10709
  break;
10439
10710
  }
10440
- message.ownerIdentityPublicKey = reader.bytes();
10711
+ message.signingJobs.push(LeafRefundTxSigningJob.decode(reader, reader.uint32()));
10441
10712
  continue;
10442
10713
  }
10443
10714
  }
@@ -10450,63 +10721,49 @@ var AggregateNodesRequest = {
10450
10721
  },
10451
10722
  fromJSON(object) {
10452
10723
  return {
10453
- nodeIds: globalThis.Array.isArray(object?.nodeIds) ? object.nodeIds.map((e) => globalThis.String(e)) : [],
10454
- signingJob: isSet3(object.signingJob) ? SigningJob.fromJSON(object.signingJob) : void 0,
10455
- ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0)
10724
+ transferId: isSet3(object.transferId) ? globalThis.String(object.transferId) : "",
10725
+ ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
10726
+ signingJobs: globalThis.Array.isArray(object?.signingJobs) ? object.signingJobs.map((e) => LeafRefundTxSigningJob.fromJSON(e)) : []
10456
10727
  };
10457
10728
  },
10458
10729
  toJSON(message) {
10459
10730
  const obj = {};
10460
- if (message.nodeIds?.length) {
10461
- obj.nodeIds = message.nodeIds;
10462
- }
10463
- if (message.signingJob !== void 0) {
10464
- obj.signingJob = SigningJob.toJSON(message.signingJob);
10731
+ if (message.transferId !== "") {
10732
+ obj.transferId = message.transferId;
10465
10733
  }
10466
10734
  if (message.ownerIdentityPublicKey.length !== 0) {
10467
10735
  obj.ownerIdentityPublicKey = base64FromBytes2(message.ownerIdentityPublicKey);
10468
10736
  }
10737
+ if (message.signingJobs?.length) {
10738
+ obj.signingJobs = message.signingJobs.map((e) => LeafRefundTxSigningJob.toJSON(e));
10739
+ }
10469
10740
  return obj;
10470
10741
  },
10471
10742
  create(base) {
10472
- return AggregateNodesRequest.fromPartial(base ?? {});
10743
+ return ClaimTransferSignRefundsRequest.fromPartial(base ?? {});
10473
10744
  },
10474
10745
  fromPartial(object) {
10475
- const message = createBaseAggregateNodesRequest();
10476
- message.nodeIds = object.nodeIds?.map((e) => e) || [];
10477
- message.signingJob = object.signingJob !== void 0 && object.signingJob !== null ? SigningJob.fromPartial(object.signingJob) : void 0;
10746
+ const message = createBaseClaimTransferSignRefundsRequest();
10747
+ message.transferId = object.transferId ?? "";
10478
10748
  message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
10749
+ message.signingJobs = object.signingJobs?.map((e) => LeafRefundTxSigningJob.fromPartial(e)) || [];
10479
10750
  return message;
10480
10751
  }
10481
10752
  };
10482
- function createBaseAggregateNodesResponse() {
10483
- return {
10484
- aggregateSignature: void 0,
10485
- verifyingKey: new Uint8Array(0),
10486
- parentNodeTx: new Uint8Array(0),
10487
- parentNodeVout: 0
10488
- };
10753
+ function createBaseClaimTransferSignRefundsResponse() {
10754
+ return { signingResults: [] };
10489
10755
  }
10490
- var AggregateNodesResponse = {
10756
+ var ClaimTransferSignRefundsResponse = {
10491
10757
  encode(message, writer = new BinaryWriter4()) {
10492
- if (message.aggregateSignature !== void 0) {
10493
- SigningResult.encode(message.aggregateSignature, writer.uint32(10).fork()).join();
10494
- }
10495
- if (message.verifyingKey.length !== 0) {
10496
- writer.uint32(18).bytes(message.verifyingKey);
10497
- }
10498
- if (message.parentNodeTx.length !== 0) {
10499
- writer.uint32(26).bytes(message.parentNodeTx);
10500
- }
10501
- if (message.parentNodeVout !== 0) {
10502
- writer.uint32(32).uint32(message.parentNodeVout);
10758
+ for (const v of message.signingResults) {
10759
+ LeafRefundTxSigningResult.encode(v, writer.uint32(10).fork()).join();
10503
10760
  }
10504
10761
  return writer;
10505
10762
  },
10506
10763
  decode(input, length) {
10507
10764
  const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
10508
10765
  let end = length === void 0 ? reader.len : reader.pos + length;
10509
- const message = createBaseAggregateNodesResponse();
10766
+ const message = createBaseClaimTransferSignRefundsResponse();
10510
10767
  while (reader.pos < end) {
10511
10768
  const tag = reader.uint32();
10512
10769
  switch (tag >>> 3) {
@@ -10514,28 +10771,7 @@ var AggregateNodesResponse = {
10514
10771
  if (tag !== 10) {
10515
10772
  break;
10516
10773
  }
10517
- message.aggregateSignature = SigningResult.decode(reader, reader.uint32());
10518
- continue;
10519
- }
10520
- case 2: {
10521
- if (tag !== 18) {
10522
- break;
10523
- }
10524
- message.verifyingKey = reader.bytes();
10525
- continue;
10526
- }
10527
- case 3: {
10528
- if (tag !== 26) {
10529
- break;
10530
- }
10531
- message.parentNodeTx = reader.bytes();
10532
- continue;
10533
- }
10534
- case 4: {
10535
- if (tag !== 32) {
10536
- break;
10537
- }
10538
- message.parentNodeVout = reader.uint32();
10774
+ message.signingResults.push(LeafRefundTxSigningResult.decode(reader, reader.uint32()));
10539
10775
  continue;
10540
10776
  }
10541
10777
  }
@@ -10548,37 +10784,22 @@ var AggregateNodesResponse = {
10548
10784
  },
10549
10785
  fromJSON(object) {
10550
10786
  return {
10551
- aggregateSignature: isSet3(object.aggregateSignature) ? SigningResult.fromJSON(object.aggregateSignature) : void 0,
10552
- verifyingKey: isSet3(object.verifyingKey) ? bytesFromBase642(object.verifyingKey) : new Uint8Array(0),
10553
- parentNodeTx: isSet3(object.parentNodeTx) ? bytesFromBase642(object.parentNodeTx) : new Uint8Array(0),
10554
- parentNodeVout: isSet3(object.parentNodeVout) ? globalThis.Number(object.parentNodeVout) : 0
10787
+ signingResults: globalThis.Array.isArray(object?.signingResults) ? object.signingResults.map((e) => LeafRefundTxSigningResult.fromJSON(e)) : []
10555
10788
  };
10556
10789
  },
10557
10790
  toJSON(message) {
10558
10791
  const obj = {};
10559
- if (message.aggregateSignature !== void 0) {
10560
- obj.aggregateSignature = SigningResult.toJSON(message.aggregateSignature);
10561
- }
10562
- if (message.verifyingKey.length !== 0) {
10563
- obj.verifyingKey = base64FromBytes2(message.verifyingKey);
10564
- }
10565
- if (message.parentNodeTx.length !== 0) {
10566
- obj.parentNodeTx = base64FromBytes2(message.parentNodeTx);
10567
- }
10568
- if (message.parentNodeVout !== 0) {
10569
- obj.parentNodeVout = Math.round(message.parentNodeVout);
10792
+ if (message.signingResults?.length) {
10793
+ obj.signingResults = message.signingResults.map((e) => LeafRefundTxSigningResult.toJSON(e));
10570
10794
  }
10571
10795
  return obj;
10572
10796
  },
10573
10797
  create(base) {
10574
- return AggregateNodesResponse.fromPartial(base ?? {});
10798
+ return ClaimTransferSignRefundsResponse.fromPartial(base ?? {});
10575
10799
  },
10576
10800
  fromPartial(object) {
10577
- const message = createBaseAggregateNodesResponse();
10578
- message.aggregateSignature = object.aggregateSignature !== void 0 && object.aggregateSignature !== null ? SigningResult.fromPartial(object.aggregateSignature) : void 0;
10579
- message.verifyingKey = object.verifyingKey ?? new Uint8Array(0);
10580
- message.parentNodeTx = object.parentNodeTx ?? new Uint8Array(0);
10581
- message.parentNodeVout = object.parentNodeVout ?? 0;
10801
+ const message = createBaseClaimTransferSignRefundsResponse();
10802
+ message.signingResults = object.signingResults?.map((e) => LeafRefundTxSigningResult.fromPartial(e)) || [];
10582
10803
  return message;
10583
10804
  }
10584
10805
  };
@@ -13982,7 +14203,7 @@ var CancelTransferResponse = {
13982
14203
  }
13983
14204
  };
13984
14205
  function createBaseQueryUnusedDepositAddressesRequest() {
13985
- return { identityPublicKey: new Uint8Array(0), network: 0 };
14206
+ return { identityPublicKey: new Uint8Array(0), network: 0, limit: 0, offset: 0 };
13986
14207
  }
13987
14208
  var QueryUnusedDepositAddressesRequest = {
13988
14209
  encode(message, writer = new BinaryWriter4()) {
@@ -13992,6 +14213,12 @@ var QueryUnusedDepositAddressesRequest = {
13992
14213
  if (message.network !== 0) {
13993
14214
  writer.uint32(16).int32(message.network);
13994
14215
  }
14216
+ if (message.limit !== 0) {
14217
+ writer.uint32(24).int64(message.limit);
14218
+ }
14219
+ if (message.offset !== 0) {
14220
+ writer.uint32(32).int64(message.offset);
14221
+ }
13995
14222
  return writer;
13996
14223
  },
13997
14224
  decode(input, length) {
@@ -14015,6 +14242,20 @@ var QueryUnusedDepositAddressesRequest = {
14015
14242
  message.network = reader.int32();
14016
14243
  continue;
14017
14244
  }
14245
+ case 3: {
14246
+ if (tag !== 24) {
14247
+ break;
14248
+ }
14249
+ message.limit = longToNumber2(reader.int64());
14250
+ continue;
14251
+ }
14252
+ case 4: {
14253
+ if (tag !== 32) {
14254
+ break;
14255
+ }
14256
+ message.offset = longToNumber2(reader.int64());
14257
+ continue;
14258
+ }
14018
14259
  }
14019
14260
  if ((tag & 7) === 4 || tag === 0) {
14020
14261
  break;
@@ -14026,7 +14267,9 @@ var QueryUnusedDepositAddressesRequest = {
14026
14267
  fromJSON(object) {
14027
14268
  return {
14028
14269
  identityPublicKey: isSet3(object.identityPublicKey) ? bytesFromBase642(object.identityPublicKey) : new Uint8Array(0),
14029
- network: isSet3(object.network) ? networkFromJSON(object.network) : 0
14270
+ network: isSet3(object.network) ? networkFromJSON(object.network) : 0,
14271
+ limit: isSet3(object.limit) ? globalThis.Number(object.limit) : 0,
14272
+ offset: isSet3(object.offset) ? globalThis.Number(object.offset) : 0
14030
14273
  };
14031
14274
  },
14032
14275
  toJSON(message) {
@@ -14037,6 +14280,12 @@ var QueryUnusedDepositAddressesRequest = {
14037
14280
  if (message.network !== 0) {
14038
14281
  obj.network = networkToJSON(message.network);
14039
14282
  }
14283
+ if (message.limit !== 0) {
14284
+ obj.limit = Math.round(message.limit);
14285
+ }
14286
+ if (message.offset !== 0) {
14287
+ obj.offset = Math.round(message.offset);
14288
+ }
14040
14289
  return obj;
14041
14290
  },
14042
14291
  create(base) {
@@ -14046,6 +14295,8 @@ var QueryUnusedDepositAddressesRequest = {
14046
14295
  const message = createBaseQueryUnusedDepositAddressesRequest();
14047
14296
  message.identityPublicKey = object.identityPublicKey ?? new Uint8Array(0);
14048
14297
  message.network = object.network ?? 0;
14298
+ message.limit = object.limit ?? 0;
14299
+ message.offset = object.offset ?? 0;
14049
14300
  return message;
14050
14301
  }
14051
14302
  };
@@ -14251,13 +14502,16 @@ var DepositAddressQueryResult = {
14251
14502
  }
14252
14503
  };
14253
14504
  function createBaseQueryUnusedDepositAddressesResponse() {
14254
- return { depositAddresses: [] };
14505
+ return { depositAddresses: [], offset: 0 };
14255
14506
  }
14256
14507
  var QueryUnusedDepositAddressesResponse = {
14257
14508
  encode(message, writer = new BinaryWriter4()) {
14258
14509
  for (const v of message.depositAddresses) {
14259
14510
  DepositAddressQueryResult.encode(v, writer.uint32(10).fork()).join();
14260
14511
  }
14512
+ if (message.offset !== 0) {
14513
+ writer.uint32(16).int64(message.offset);
14514
+ }
14261
14515
  return writer;
14262
14516
  },
14263
14517
  decode(input, length) {
@@ -14274,6 +14528,13 @@ var QueryUnusedDepositAddressesResponse = {
14274
14528
  message.depositAddresses.push(DepositAddressQueryResult.decode(reader, reader.uint32()));
14275
14529
  continue;
14276
14530
  }
14531
+ case 2: {
14532
+ if (tag !== 16) {
14533
+ break;
14534
+ }
14535
+ message.offset = longToNumber2(reader.int64());
14536
+ continue;
14537
+ }
14277
14538
  }
14278
14539
  if ((tag & 7) === 4 || tag === 0) {
14279
14540
  break;
@@ -14284,7 +14545,8 @@ var QueryUnusedDepositAddressesResponse = {
14284
14545
  },
14285
14546
  fromJSON(object) {
14286
14547
  return {
14287
- depositAddresses: globalThis.Array.isArray(object?.depositAddresses) ? object.depositAddresses.map((e) => DepositAddressQueryResult.fromJSON(e)) : []
14548
+ depositAddresses: globalThis.Array.isArray(object?.depositAddresses) ? object.depositAddresses.map((e) => DepositAddressQueryResult.fromJSON(e)) : [],
14549
+ offset: isSet3(object.offset) ? globalThis.Number(object.offset) : 0
14288
14550
  };
14289
14551
  },
14290
14552
  toJSON(message) {
@@ -14292,6 +14554,9 @@ var QueryUnusedDepositAddressesResponse = {
14292
14554
  if (message.depositAddresses?.length) {
14293
14555
  obj.depositAddresses = message.depositAddresses.map((e) => DepositAddressQueryResult.toJSON(e));
14294
14556
  }
14557
+ if (message.offset !== 0) {
14558
+ obj.offset = Math.round(message.offset);
14559
+ }
14295
14560
  return obj;
14296
14561
  },
14297
14562
  create(base) {
@@ -14300,6 +14565,7 @@ var QueryUnusedDepositAddressesResponse = {
14300
14565
  fromPartial(object) {
14301
14566
  const message = createBaseQueryUnusedDepositAddressesResponse();
14302
14567
  message.depositAddresses = object.depositAddresses?.map((e) => DepositAddressQueryResult.fromPartial(e)) || [];
14568
+ message.offset = object.offset ?? 0;
14303
14569
  return message;
14304
14570
  }
14305
14571
  };
@@ -15886,6 +16152,11 @@ var SparkServiceDefinition = {
15886
16152
  responseStream: false,
15887
16153
  options: {}
15888
16154
  },
16155
+ /**
16156
+ * This is deprecated, please use finalize_transfer_with_transfer_package instead.
16157
+ *
16158
+ * @deprecated
16159
+ */
15889
16160
  finalize_transfer: {
15890
16161
  name: "finalize_transfer",
15891
16162
  requestType: FinalizeTransferRequest,
@@ -15942,14 +16213,6 @@ var SparkServiceDefinition = {
15942
16213
  responseStream: false,
15943
16214
  options: {}
15944
16215
  },
15945
- aggregate_nodes: {
15946
- name: "aggregate_nodes",
15947
- requestType: AggregateNodesRequest,
15948
- requestStream: false,
15949
- responseType: AggregateNodesResponse,
15950
- responseStream: false,
15951
- options: {}
15952
- },
15953
16216
  store_preimage_share: {
15954
16217
  name: "store_preimage_share",
15955
16218
  requestType: StorePreimageShareRequest,
@@ -16485,7 +16748,8 @@ var BASE_CONFIG = {
16485
16748
  }
16486
16749
  };
16487
16750
  var LOCAL_WALLET_CONFIG = {
16488
- ...BASE_CONFIG
16751
+ ...BASE_CONFIG,
16752
+ threshold: 3
16489
16753
  };
16490
16754
  var LOCAL_WALLET_CONFIG_SCHNORR = {
16491
16755
  ...LOCAL_WALLET_CONFIG,
@@ -19059,8 +19323,8 @@ function getNextTransactionSequence(currSequence, forRefresh) {
19059
19323
  needRefresh: true
19060
19324
  };
19061
19325
  }
19062
- if (nextTimelock < 100) {
19063
- throw new ValidationError("timelock interval is less than 100", {
19326
+ if (nextTimelock < 0) {
19327
+ throw new ValidationError("timelock interval is less than 0", {
19064
19328
  field: "nextTimelock",
19065
19329
  value: nextTimelock
19066
19330
  });
@@ -25001,17 +25265,30 @@ function hashTokenTransactionV1(tokenTransaction, partialHash = false) {
25001
25265
  );
25002
25266
  hashObj.update(networkBytes);
25003
25267
  allHashes.push(hashObj.digest());
25004
- const expiryHashObj = sha25611.create();
25005
- const validityDurationBytes = new Uint8Array(8);
25006
- const expiryUnixTime = tokenTransaction.expiryTime ? Math.floor(tokenTransaction.expiryTime.getTime() / 1e3) : 0;
25007
- new DataView(validityDurationBytes.buffer).setBigUint64(
25268
+ const clientTimestampHashObj = sha25611.create();
25269
+ const clientCreatedTs = tokenTransaction.clientCreatedTimestamp;
25270
+ const clientUnixTime = clientCreatedTs ? Math.floor(clientCreatedTs.getTime() / 1e3) : 0;
25271
+ const clientTimestampBytes = new Uint8Array(8);
25272
+ new DataView(clientTimestampBytes.buffer).setBigUint64(
25008
25273
  0,
25009
- BigInt(expiryUnixTime),
25274
+ BigInt(clientUnixTime),
25010
25275
  false
25011
- // false for big-endian
25012
25276
  );
25013
- expiryHashObj.update(validityDurationBytes);
25014
- allHashes.push(expiryHashObj.digest());
25277
+ clientTimestampHashObj.update(clientTimestampBytes);
25278
+ allHashes.push(clientTimestampHashObj.digest());
25279
+ if (!partialHash) {
25280
+ const expiryHashObj = sha25611.create();
25281
+ const expiryTimeBytes = new Uint8Array(8);
25282
+ const expiryUnixTime = tokenTransaction.expiryTime ? Math.floor(tokenTransaction.expiryTime.getTime() / 1e3) : 0;
25283
+ new DataView(expiryTimeBytes.buffer).setBigUint64(
25284
+ 0,
25285
+ BigInt(expiryUnixTime),
25286
+ false
25287
+ // false for big-endian
25288
+ );
25289
+ expiryHashObj.update(expiryTimeBytes);
25290
+ allHashes.push(expiryHashObj.digest());
25291
+ }
25015
25292
  const finalHashObj = sha25611.create();
25016
25293
  const concatenatedHashes = new Uint8Array(
25017
25294
  allHashes.reduce((sum, hash) => sum + hash.length, 0)
@@ -25596,6 +25873,9 @@ var TokenTransactionService = class {
25596
25873
  return txId;
25597
25874
  }
25598
25875
  async constructTransferTokenTransactionV0(selectedOutputs, tokenOutputData) {
25876
+ selectedOutputs.sort(
25877
+ (a, b) => a.previousTransactionVout - b.previousTransactionVout
25878
+ );
25599
25879
  const availableTokenAmount = calculateAvailableTokenAmount(selectedOutputs);
25600
25880
  const totalRequestedAmount = tokenOutputData.reduce(
25601
25881
  (sum, output) => sum + output.tokenAmount,
@@ -25631,6 +25911,9 @@ var TokenTransactionService = class {
25631
25911
  };
25632
25912
  }
25633
25913
  async constructTransferTokenTransaction(selectedOutputs, tokenOutputData) {
25914
+ selectedOutputs.sort(
25915
+ (a, b) => a.previousTransactionVout - b.previousTransactionVout
25916
+ );
25634
25917
  const availableTokenAmount = calculateAvailableTokenAmount(selectedOutputs);
25635
25918
  const totalRequestedAmount = tokenOutputData.reduce(
25636
25919
  (sum, output) => sum + output.tokenAmount,
@@ -26097,6 +26380,7 @@ var TokenTransactionService = class {
26097
26380
  await coordinatorClient.commit_transaction(
26098
26381
  {
26099
26382
  finalTokenTransaction,
26383
+ finalTokenTransactionHash,
26100
26384
  inputTtxoSignaturesPerOperator,
26101
26385
  ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
26102
26386
  },
@@ -26333,7 +26617,7 @@ import { hexToBytes as hexToBytes10 } from "@noble/curves/abstract/utils";
26333
26617
  import { sha256 as sha25612 } from "@noble/hashes/sha2";
26334
26618
  import { Address as Address4, OutScript as OutScript3, Transaction as Transaction7 } from "@scure/btc-signer";
26335
26619
  var INITIAL_TIME_LOCK3 = 2e3;
26336
- function maybeApplyFee3(amount) {
26620
+ function maybeApplyFee2(amount) {
26337
26621
  if (amount > BigInt(DEFAULT_FEE_SATS)) {
26338
26622
  return amount - BigInt(DEFAULT_FEE_SATS);
26339
26623
  }
@@ -26602,7 +26886,7 @@ var TreeCreationService = class {
26602
26886
  const refundPkScript = OutScript3.encode(refundAddress);
26603
26887
  refundTx.addOutput({
26604
26888
  script: refundPkScript,
26605
- amount: maybeApplyFee3(parentTxOut.amount)
26889
+ amount: maybeApplyFee2(parentTxOut.amount)
26606
26890
  });
26607
26891
  refundTx.addOutput(getEphemeralAnchorOutput());
26608
26892
  const refundSigningNonceCommitment = await this.config.signer.getRandomSigningCommitment();
@@ -27514,13 +27798,34 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
27514
27798
  ([_, node]) => node.status === "AVAILABLE" && !leavesToIgnore.has(node.id)
27515
27799
  ).map(([_, node]) => node);
27516
27800
  }
27517
- async selectLeaves(targetAmount) {
27518
- if (targetAmount <= 0) {
27801
+ async selectLeaves(targetAmounts) {
27802
+ if (targetAmounts.length === 0) {
27803
+ throw new ValidationError("Target amounts must be non-empty", {
27804
+ field: "targetAmounts",
27805
+ value: targetAmounts
27806
+ });
27807
+ }
27808
+ if (targetAmounts.some((amount) => amount <= 0)) {
27519
27809
  throw new ValidationError("Target amount must be positive", {
27520
- field: "targetAmount",
27521
- value: targetAmount
27810
+ field: "targetAmounts",
27811
+ value: targetAmounts
27522
27812
  });
27523
27813
  }
27814
+ const totalTargetAmount = targetAmounts.reduce(
27815
+ (acc, amount) => acc + amount,
27816
+ 0
27817
+ );
27818
+ const totalBalance = this.getInternalBalance();
27819
+ if (totalTargetAmount > totalBalance) {
27820
+ throw new ValidationError(
27821
+ "Total target amount exceeds available balance",
27822
+ {
27823
+ field: "targetAmounts",
27824
+ value: totalTargetAmount,
27825
+ expected: `less than or equal to ${totalBalance}`
27826
+ }
27827
+ );
27828
+ }
27524
27829
  const leaves = await this.getLeaves();
27525
27830
  if (leaves.length === 0) {
27526
27831
  throw new ValidationError("No owned leaves found", {
@@ -27528,33 +27833,49 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
27528
27833
  });
27529
27834
  }
27530
27835
  leaves.sort((a, b) => b.value - a.value);
27531
- let amount = 0;
27532
- let nodes = [];
27533
- for (const leaf of leaves) {
27534
- if (targetAmount - amount >= leaf.value) {
27535
- amount += leaf.value;
27536
- nodes.push(leaf);
27537
- }
27538
- }
27539
- if (amount !== targetAmount) {
27540
- await this.requestLeavesSwap({ targetAmount });
27541
- amount = 0;
27542
- nodes = [];
27543
- const newLeaves = await this.getLeaves();
27544
- newLeaves.sort((a, b) => b.value - a.value);
27545
- for (const leaf of newLeaves) {
27546
- if (targetAmount - amount >= leaf.value) {
27547
- amount += leaf.value;
27548
- nodes.push(leaf);
27836
+ const selectLeavesForTargets = (targetAmounts2, leaves2) => {
27837
+ const usedLeaves = /* @__PURE__ */ new Set();
27838
+ const results2 = /* @__PURE__ */ new Map();
27839
+ let totalAmount = 0;
27840
+ for (const targetAmount of targetAmounts2) {
27841
+ const nodes = [];
27842
+ let amount = 0;
27843
+ for (const leaf of leaves2) {
27844
+ if (usedLeaves.has(leaf.id)) {
27845
+ continue;
27846
+ }
27847
+ if (targetAmount - amount >= leaf.value) {
27848
+ amount += leaf.value;
27849
+ nodes.push(leaf);
27850
+ usedLeaves.add(leaf.id);
27851
+ }
27549
27852
  }
27853
+ totalAmount += amount;
27854
+ results2.set(targetAmount, nodes);
27550
27855
  }
27856
+ return {
27857
+ results: results2,
27858
+ foundSelections: totalAmount === totalTargetAmount
27859
+ };
27860
+ };
27861
+ let { results, foundSelections } = selectLeavesForTargets(
27862
+ targetAmounts,
27863
+ leaves
27864
+ );
27865
+ if (!foundSelections) {
27866
+ const newLeaves = await this.requestLeavesSwap({ targetAmounts });
27867
+ newLeaves.sort((a, b) => b.value - a.value);
27868
+ ({ results, foundSelections } = selectLeavesForTargets(
27869
+ targetAmounts,
27870
+ newLeaves
27871
+ ));
27551
27872
  }
27552
- if (nodes.reduce((acc, leaf) => acc + leaf.value, 0) !== targetAmount) {
27873
+ if (!foundSelections) {
27553
27874
  throw new Error(
27554
- `Failed to select leaves for target amount ${targetAmount}`
27875
+ `Failed to select leaves for target amount ${totalTargetAmount}`
27555
27876
  );
27556
27877
  }
27557
- return nodes;
27878
+ return results;
27558
27879
  }
27559
27880
  async selectLeavesForSwap(targetAmount) {
27560
27881
  if (targetAmount == 0) {
@@ -27787,27 +28108,44 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
27787
28108
  * @private
27788
28109
  */
27789
28110
  async requestLeavesSwap({
27790
- targetAmount,
28111
+ targetAmounts,
27791
28112
  leaves
27792
28113
  }) {
27793
- if (targetAmount && targetAmount <= 0) {
27794
- throw new Error("targetAmount must be positive");
28114
+ if (targetAmounts && targetAmounts.some((amount) => amount <= 0)) {
28115
+ throw new Error("specified targetAmount must be positive");
27795
28116
  }
27796
- if (targetAmount && !Number.isSafeInteger(targetAmount)) {
28117
+ if (targetAmounts && targetAmounts.some((amount) => !Number.isSafeInteger(amount))) {
27797
28118
  throw new ValidationError("targetAmount must be less than 2^53", {
27798
- field: "targetAmount",
27799
- value: targetAmount,
28119
+ field: "targetAmounts",
28120
+ value: targetAmounts,
27800
28121
  expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER
27801
28122
  });
27802
28123
  }
27803
28124
  let leavesToSwap;
27804
- if (targetAmount && leaves && leaves.length > 0) {
27805
- if (targetAmount < leaves.reduce((acc, leaf) => acc + leaf.value, 0)) {
28125
+ const totalTargetAmount = targetAmounts?.reduce(
28126
+ (acc, amount) => acc + amount,
28127
+ 0
28128
+ );
28129
+ if (totalTargetAmount) {
28130
+ const totalBalance = this.getInternalBalance();
28131
+ if (totalTargetAmount > totalBalance) {
28132
+ throw new ValidationError(
28133
+ "Total target amount exceeds available balance",
28134
+ {
28135
+ field: "targetAmounts",
28136
+ value: totalTargetAmount,
28137
+ expected: `less than or equal to ${totalBalance}`
28138
+ }
28139
+ );
28140
+ }
28141
+ }
28142
+ if (totalTargetAmount && leaves && leaves.length > 0) {
28143
+ if (totalTargetAmount < leaves.reduce((acc, leaf) => acc + leaf.value, 0)) {
27806
28144
  throw new Error("targetAmount is less than the sum of leaves");
27807
28145
  }
27808
28146
  leavesToSwap = leaves;
27809
- } else if (targetAmount) {
27810
- leavesToSwap = await this.selectLeavesForSwap(targetAmount);
28147
+ } else if (totalTargetAmount) {
28148
+ leavesToSwap = await this.selectLeavesForSwap(totalTargetAmount);
27811
28149
  } else if (leaves && leaves.length > 0) {
27812
28150
  leavesToSwap = leaves;
27813
28151
  } else {
@@ -27817,15 +28155,15 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
27817
28155
  const batches = chunkArray(leavesToSwap, 100);
27818
28156
  const results = [];
27819
28157
  for (const batch of batches) {
27820
- const result = await this.processSwapBatch(batch, targetAmount);
27821
- results.push(...result.swapLeaves);
28158
+ const result = await this.processSwapBatch(batch, targetAmounts);
28159
+ results.push(...result);
27822
28160
  }
27823
28161
  return results;
27824
28162
  }
27825
28163
  /**
27826
28164
  * Processes a single batch of leaves for swapping.
27827
28165
  */
27828
- async processSwapBatch(leavesBatch, targetAmount) {
28166
+ async processSwapBatch(leavesBatch, targetAmounts) {
27829
28167
  const leafKeyTweaks = await Promise.all(
27830
28168
  leavesBatch.map(async (leaf) => ({
27831
28169
  leaf,
@@ -27889,8 +28227,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
27889
28227
  request = await sspClient.requestLeaveSwap({
27890
28228
  userLeaves,
27891
28229
  adaptorPubkey,
27892
- targetAmountSats: targetAmount || leavesBatch.reduce((acc, leaf) => acc + leaf.value, 0),
28230
+ targetAmountSats: targetAmounts?.reduce((acc, amount) => acc + amount, 0) || leavesBatch.reduce((acc, leaf) => acc + leaf.value, 0),
27893
28231
  totalAmountSats: leavesBatch.reduce((acc, leaf) => acc + leaf.value, 0),
28232
+ targetAmountSatsList: targetAmounts,
27894
28233
  // TODO: Request fee from SSP
27895
28234
  feeSats: 0,
27896
28235
  idempotencyKey: uuidv75()
@@ -27946,11 +28285,21 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
27946
28285
  userOutboundTransferExternalId: transfer.id,
27947
28286
  leavesSwapRequestId: request.id
27948
28287
  });
27949
- if (!completeResponse) {
28288
+ if (!completeResponse || !completeResponse.inboundTransfer?.sparkId) {
27950
28289
  throw new Error("Failed to complete leaves swap");
27951
28290
  }
27952
- await this.claimTransfers(40 /* COUNTER_SWAP */);
27953
- return completeResponse;
28291
+ const incomingTransfer = await this.transferService.queryTransfer(
28292
+ completeResponse.inboundTransfer.sparkId
28293
+ );
28294
+ if (!incomingTransfer) {
28295
+ throw new Error("Failed to get incoming transfer");
28296
+ }
28297
+ return await this.claimTransfer({
28298
+ transfer: incomingTransfer,
28299
+ emit: false,
28300
+ retryCount: 0,
28301
+ optimize: false
28302
+ });
27954
28303
  } catch (e) {
27955
28304
  await this.cancelAllSenderInitiatedTransfers();
27956
28305
  throw new Error(`Failed to request leaves swap: ${e}`);
@@ -28487,13 +28836,45 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
28487
28836
  * @returns {Promise<string[]>} The unused deposit addresses
28488
28837
  */
28489
28838
  async getUnusedDepositAddresses() {
28839
+ return (await this.queryAllUnusedDepositAddresses({})).map(
28840
+ (addr) => addr.depositAddress
28841
+ );
28842
+ }
28843
+ /**
28844
+ * Gets all unused deposit addresses for the wallet.
28845
+ *
28846
+ * @param {Object} params - Parameters for querying unused deposit addresses
28847
+ * @param {Uint8Array<ArrayBufferLike>} [params.identityPublicKey] - The identity public key
28848
+ * @param {NetworkProto} [params.network] - The network
28849
+ * @returns {Promise<DepositAddressQueryResult[]>} The unused deposit addresses
28850
+ */
28851
+ async queryAllUnusedDepositAddresses({
28852
+ identityPublicKey,
28853
+ network
28854
+ }) {
28490
28855
  const sparkClient = await this.connectionManager.createSparkClient(
28491
28856
  this.config.getCoordinatorAddress()
28492
28857
  );
28493
- return (await sparkClient.query_unused_deposit_addresses({
28494
- identityPublicKey: await this.config.signer.getIdentityPublicKey(),
28495
- network: NetworkToProto[this.config.getNetwork()]
28496
- })).depositAddresses.map((addr) => addr.depositAddress);
28858
+ let limit = 100;
28859
+ let offset = 0;
28860
+ const pastOffsets = /* @__PURE__ */ new Set();
28861
+ const depositAddresses = [];
28862
+ while (offset >= 0) {
28863
+ if (pastOffsets.has(offset)) {
28864
+ console.warn("Offset has already been seen, stopping");
28865
+ break;
28866
+ }
28867
+ const response = await sparkClient.query_unused_deposit_addresses({
28868
+ identityPublicKey: identityPublicKey ?? await this.config.signer.getIdentityPublicKey(),
28869
+ network: network ?? NetworkToProto[this.config.getNetwork()],
28870
+ limit,
28871
+ offset
28872
+ });
28873
+ depositAddresses.push(...response.depositAddresses);
28874
+ pastOffsets.add(offset);
28875
+ offset = response.offset;
28876
+ }
28877
+ return depositAddresses;
28497
28878
  }
28498
28879
  /**
28499
28880
  * Claims a deposit to the wallet.
@@ -28542,14 +28923,11 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
28542
28923
  });
28543
28924
  }
28544
28925
  const depositTx = getTxFromRawTxHex(txHex);
28545
- const sparkClient = await this.connectionManager.createSparkClient(
28546
- this.config.getCoordinatorAddress()
28547
- );
28548
28926
  const unusedDepositAddresses = new Map(
28549
- (await sparkClient.query_unused_deposit_addresses({
28927
+ (await this.queryAllUnusedDepositAddresses({
28550
28928
  identityPublicKey: await this.config.signer.getIdentityPublicKey(),
28551
28929
  network: NetworkToProto[this.config.getNetwork()]
28552
- })).depositAddresses.map((addr) => [addr.depositAddress, addr])
28930
+ })).map((addr) => [addr.depositAddress, addr])
28553
28931
  );
28554
28932
  let depositAddress;
28555
28933
  let vout = 0;
@@ -28603,14 +28981,11 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
28603
28981
  */
28604
28982
  async advancedDeposit(txHex) {
28605
28983
  const depositTx = getTxFromRawTxHex(txHex);
28606
- const sparkClient = await this.connectionManager.createSparkClient(
28607
- this.config.getCoordinatorAddress()
28608
- );
28609
28984
  const unusedDepositAddresses = new Map(
28610
- (await sparkClient.query_unused_deposit_addresses({
28985
+ (await this.queryAllUnusedDepositAddresses({
28611
28986
  identityPublicKey: await this.config.signer.getIdentityPublicKey(),
28612
28987
  network: NetworkToProto[this.config.getNetwork()]
28613
- })).depositAddresses.map((addr) => [addr.depositAddress, addr])
28988
+ })).map((addr) => [addr.depositAddress, addr])
28614
28989
  );
28615
28990
  let vout = 0;
28616
28991
  const responses = [];
@@ -28714,7 +29089,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
28714
29089
  hexToBytes13(receiverAddress.identityPublicKey)
28715
29090
  );
28716
29091
  return await this.withLeaves(async () => {
28717
- let leavesToSend = await this.selectLeaves(amountSats);
29092
+ let leavesToSend = (await this.selectLeaves([amountSats])).get(
29093
+ amountSats
29094
+ );
28718
29095
  leavesToSend = await this.checkRefreshTimelockNodes(leavesToSend);
28719
29096
  leavesToSend = await this.checkExtendTimeLockNodes(leavesToSend);
28720
29097
  const leafKeyTweaks = await Promise.all(
@@ -28957,7 +29334,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
28957
29334
  if (type && transfer.type !== type) {
28958
29335
  continue;
28959
29336
  }
28960
- if (transfer.status !== 2 /* TRANSFER_STATUS_SENDER_KEY_TWEAKED */ && transfer.status !== 3 /* TRANSFER_STATUS_RECEIVER_KEY_TWEAKED */ && transfer.status !== 4 /* TRANSFER_STATUSR_RECEIVER_REFUND_SIGNED */ && transfer.status !== 10 /* TRANSFER_STATUS_RECEIVER_KEY_TWEAK_APPLIED */) {
29337
+ if (transfer.status !== 2 /* TRANSFER_STATUS_SENDER_KEY_TWEAKED */ && transfer.status !== 3 /* TRANSFER_STATUS_RECEIVER_KEY_TWEAKED */ && transfer.status !== 4 /* TRANSFER_STATUS_RECEIVER_REFUND_SIGNED */ && transfer.status !== 10 /* TRANSFER_STATUS_RECEIVER_KEY_TWEAK_APPLIED */) {
28961
29338
  continue;
28962
29339
  }
28963
29340
  promises.push(
@@ -29216,7 +29593,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29216
29593
  expected: `${totalAmount} sats`
29217
29594
  });
29218
29595
  }
29219
- let leaves = await this.selectLeaves(totalAmount);
29596
+ let leaves = (await this.selectLeaves([totalAmount])).get(totalAmount);
29220
29597
  leaves = await this.checkRefreshTimelockNodes(leaves);
29221
29598
  leaves = await this.checkExtendTimeLockNodes(leaves);
29222
29599
  const leavesToSend = await Promise.all(
@@ -29326,13 +29703,18 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29326
29703
  *
29327
29704
  * @param {Object} params - Parameters for the withdrawal
29328
29705
  * @param {string} params.onchainAddress - The Bitcoin address where the funds should be sent
29329
- * @param {number} [params.amountSats] - The amount in satoshis to withdraw. If not specified, attempts to withdraw all available funds
29706
+ * @param {CoopExitFeeQuote} params.feeQuote - The fee quote for the withdrawal
29707
+ * @param {ExitSpeed} params.exitSpeed - The exit speed chosen for the withdrawal
29708
+ * @param {number} [params.amountSats] - The amount in satoshis to withdraw. If not specified, attempts to withdraw all available funds and deductFeeFromWithdrawalAmount is set to true.
29709
+ * @param {boolean} [params.deductFeeFromWithdrawalAmount] - Controls how the withdrawal fee is handled. If true, the fee is deducted from the withdrawal amount (amountSats), meaning the recipient will receive amountSats minus the fee. If false, the fee is paid separately from the wallet balance, meaning the recipient will receive the full amountSats.
29330
29710
  * @returns {Promise<CoopExitRequest | null | undefined>} The withdrawal request details, or null/undefined if the request cannot be completed
29331
29711
  */
29332
29712
  async withdraw({
29333
29713
  onchainAddress,
29334
29714
  exitSpeed,
29335
- amountSats
29715
+ feeQuote,
29716
+ amountSats,
29717
+ deductFeeFromWithdrawalAmount = true
29336
29718
  }) {
29337
29719
  if (!Number.isSafeInteger(amountSats)) {
29338
29720
  throw new ValidationError("Sats amount must be less than 2^53", {
@@ -29342,7 +29724,13 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29342
29724
  });
29343
29725
  }
29344
29726
  return await this.withLeaves(async () => {
29345
- return await this.coopExit(onchainAddress, exitSpeed, amountSats);
29727
+ return await this.coopExit(
29728
+ onchainAddress,
29729
+ feeQuote,
29730
+ exitSpeed,
29731
+ deductFeeFromWithdrawalAmount,
29732
+ amountSats
29733
+ );
29346
29734
  });
29347
29735
  }
29348
29736
  /**
@@ -29353,7 +29741,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29353
29741
  * @returns {Promise<Object | null | undefined>} The exit request details
29354
29742
  * @private
29355
29743
  */
29356
- async coopExit(onchainAddress, exitSpeed, targetAmountSats) {
29744
+ async coopExit(onchainAddress, feeEstimate, exitSpeed, deductFeeFromWithdrawalAmount, targetAmountSats) {
29357
29745
  if (!Number.isSafeInteger(targetAmountSats)) {
29358
29746
  throw new ValidationError("Sats amount must be less than 2^53", {
29359
29747
  field: "targetAmountSats",
@@ -29361,41 +29749,34 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29361
29749
  expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER
29362
29750
  });
29363
29751
  }
29364
- let leavesToSend = [];
29365
- if (targetAmountSats) {
29366
- leavesToSend = await this.selectLeaves(targetAmountSats);
29367
- } else {
29368
- leavesToSend = this.leaves.map((leaf) => ({
29369
- ...leaf
29370
- }));
29752
+ if (!targetAmountSats) {
29753
+ deductFeeFromWithdrawalAmount = true;
29371
29754
  }
29372
- const sspClient = this.getSspClient();
29373
- const feeEstimate = await sspClient.getCoopExitFeeEstimate({
29374
- leafExternalIds: leavesToSend.map((leaf) => leaf.id),
29375
- withdrawalAddress: onchainAddress
29376
- });
29377
- if (feeEstimate) {
29378
- let fee;
29379
- switch (exitSpeed) {
29380
- case ExitSpeed_default.FAST:
29381
- fee = (feeEstimate.speedFast?.l1BroadcastFee.originalValue || 0) + (feeEstimate.speedFast?.userFee.originalValue || 0);
29382
- break;
29383
- case ExitSpeed_default.MEDIUM:
29384
- fee = (feeEstimate.speedMedium?.l1BroadcastFee.originalValue || 0) + (feeEstimate.speedMedium?.userFee.originalValue || 0);
29385
- break;
29386
- case ExitSpeed_default.SLOW:
29387
- fee = (feeEstimate.speedSlow?.l1BroadcastFee.originalValue || 0) + (feeEstimate.speedSlow?.userFee.originalValue || 0);
29388
- break;
29389
- default:
29390
- throw new ValidationError("Invalid exit speed", {
29391
- field: "exitSpeed",
29392
- value: exitSpeed,
29393
- expected: "FAST, MEDIUM, or SLOW"
29394
- });
29395
- }
29396
- if (fee !== void 0 && fee > leavesToSend.reduce((acc, leaf) => acc + leaf.value, 0)) {
29755
+ let fee;
29756
+ switch (exitSpeed) {
29757
+ case ExitSpeed_default.FAST:
29758
+ fee = (feeEstimate.l1BroadcastFeeFast?.originalValue || 0) + (feeEstimate.userFeeFast?.originalValue || 0);
29759
+ break;
29760
+ case ExitSpeed_default.MEDIUM:
29761
+ fee = (feeEstimate.l1BroadcastFeeMedium?.originalValue || 0) + (feeEstimate.userFeeMedium?.originalValue || 0);
29762
+ break;
29763
+ case ExitSpeed_default.SLOW:
29764
+ fee = (feeEstimate.l1BroadcastFeeSlow?.originalValue || 0) + (feeEstimate.userFeeSlow?.originalValue || 0);
29765
+ break;
29766
+ default:
29767
+ throw new ValidationError("Invalid exit speed", {
29768
+ field: "exitSpeed",
29769
+ value: exitSpeed,
29770
+ expected: "FAST, MEDIUM, or SLOW"
29771
+ });
29772
+ }
29773
+ let leavesToSendToSsp = [];
29774
+ let leavesToSendToSE = [];
29775
+ if (deductFeeFromWithdrawalAmount) {
29776
+ leavesToSendToSsp = targetAmountSats ? (await this.selectLeaves([targetAmountSats])).get(targetAmountSats) : this.leaves;
29777
+ if (fee > leavesToSendToSsp.reduce((acc, leaf) => acc + leaf.value, 0)) {
29397
29778
  throw new ValidationError(
29398
- "The fee for the withdrawal is greater than the target amount",
29779
+ "The fee for the withdrawal is greater than the target withdrawal amount",
29399
29780
  {
29400
29781
  field: "fee",
29401
29782
  value: fee,
@@ -29403,11 +29784,32 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29403
29784
  }
29404
29785
  );
29405
29786
  }
29787
+ } else {
29788
+ if (!targetAmountSats) {
29789
+ throw new ValidationError(
29790
+ "targetAmountSats is required when deductFeeFromWithdrawalAmount is false",
29791
+ {
29792
+ field: "targetAmountSats",
29793
+ value: targetAmountSats,
29794
+ expected: "defined when deductFeeFromWithdrawalAmount is false"
29795
+ }
29796
+ );
29797
+ }
29798
+ const leaves = await this.selectLeaves([targetAmountSats, fee]);
29799
+ const leavesForTargetAmount = leaves.get(targetAmountSats);
29800
+ const leavesForFee = leaves.get(fee);
29801
+ if (!leavesForTargetAmount || !leavesForFee) {
29802
+ throw new Error("Failed to select leaves for target amount and fee");
29803
+ }
29804
+ leavesToSendToSsp = leavesForTargetAmount;
29805
+ leavesToSendToSE = leavesForFee;
29406
29806
  }
29407
- leavesToSend = await this.checkRefreshTimelockNodes(leavesToSend);
29408
- leavesToSend = await this.checkExtendTimeLockNodes(leavesToSend);
29807
+ leavesToSendToSsp = await this.checkRefreshTimelockNodes(leavesToSendToSsp);
29808
+ leavesToSendToSsp = await this.checkExtendTimeLockNodes(leavesToSendToSsp);
29809
+ leavesToSendToSE = await this.checkRefreshTimelockNodes(leavesToSendToSE);
29810
+ leavesToSendToSE = await this.checkExtendTimeLockNodes(leavesToSendToSE);
29409
29811
  const leafKeyTweaks = await Promise.all(
29410
- leavesToSend.map(async (leaf) => ({
29812
+ [...leavesToSendToSE, ...leavesToSendToSsp].map(async (leaf) => ({
29411
29813
  leaf,
29412
29814
  signingPubKey: await this.config.signer.generatePublicKey(
29413
29815
  sha25613(leaf.id)
@@ -29415,13 +29817,23 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29415
29817
  newSigningPubKey: await this.config.signer.generatePublicKey()
29416
29818
  }))
29417
29819
  );
29418
- const coopExitRequest = await sspClient.requestCoopExit({
29419
- leafExternalIds: leavesToSend.map((leaf) => leaf.id),
29820
+ const requestCoopExitParams = {
29821
+ leafExternalIds: leavesToSendToSsp.map((leaf) => leaf.id),
29420
29822
  withdrawalAddress: onchainAddress,
29421
29823
  idempotencyKey: uuidv75(),
29422
29824
  exitSpeed,
29423
- withdrawAll: true
29424
- });
29825
+ withdrawAll: deductFeeFromWithdrawalAmount
29826
+ };
29827
+ if (!deductFeeFromWithdrawalAmount) {
29828
+ requestCoopExitParams.feeQuoteId = feeEstimate.id;
29829
+ requestCoopExitParams.feeLeafExternalIds = leavesToSendToSE.map(
29830
+ (leaf) => leaf.id
29831
+ );
29832
+ }
29833
+ const sspClient = this.getSspClient();
29834
+ const coopExitRequest = await sspClient.requestCoopExit(
29835
+ requestCoopExitParams
29836
+ );
29425
29837
  if (!coopExitRequest?.rawConnectorTransaction) {
29426
29838
  throw new Error("Failed to request coop exit");
29427
29839
  }
@@ -29459,9 +29871,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29459
29871
  * @param {Object} params - Input parameters for fee estimation
29460
29872
  * @param {number} params.amountSats - The amount in satoshis to withdraw
29461
29873
  * @param {string} params.withdrawalAddress - The Bitcoin address where the funds should be sent
29462
- * @returns {Promise<CoopExitFeeEstimatesOutput | null>} Fee estimate for the withdrawal
29874
+ * @returns {Promise<CoopExitFeeQuote | null>} Fee estimate for the withdrawal
29463
29875
  */
29464
- async getWithdrawalFeeEstimate({
29876
+ async getWithdrawalFeeQuote({
29465
29877
  amountSats,
29466
29878
  withdrawalAddress
29467
29879
  }) {
@@ -29473,10 +29885,10 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
29473
29885
  expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER
29474
29886
  });
29475
29887
  }
29476
- let leaves = await this.selectLeaves(amountSats);
29888
+ let leaves = (await this.selectLeaves([amountSats])).get(amountSats);
29477
29889
  leaves = await this.checkRefreshTimelockNodes(leaves);
29478
29890
  leaves = await this.checkExtendTimeLockNodes(leaves);
29479
- const feeEstimate = await sspClient.getCoopExitFeeEstimate({
29891
+ const feeEstimate = await sspClient.getCoopExitFeeQuote({
29480
29892
  leafExternalIds: leaves.map((leaf) => leaf.id),
29481
29893
  withdrawalAddress
29482
29894
  });