@buildonspark/spark-sdk 0.2.11 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/bare/index.cjs +761 -243
  3. package/dist/bare/index.d.cts +70 -11
  4. package/dist/bare/index.d.ts +70 -11
  5. package/dist/bare/index.js +684 -170
  6. package/dist/{chunk-A5M55UR3.js → chunk-5VWGOHED.js} +499 -8
  7. package/dist/{chunk-3WBPICWC.js → chunk-CKHJFQUA.js} +1 -1
  8. package/dist/{chunk-QNYJGFPD.js → chunk-LX45BCZW.js} +207 -160
  9. package/dist/{chunk-76SYPHOC.js → chunk-TB7DG5CU.js} +2 -2
  10. package/dist/{chunk-6CMNEDBK.js → chunk-XXTWWW6L.js} +1 -1
  11. package/dist/{client-Dd3QnxQu.d.ts → client-D7KDa4Ih.d.ts} +1 -1
  12. package/dist/{client-B9CAWKWz.d.cts → client-DVuA5-7M.d.cts} +1 -1
  13. package/dist/debug.cjs +761 -243
  14. package/dist/debug.d.cts +4 -4
  15. package/dist/debug.d.ts +4 -4
  16. package/dist/debug.js +4 -4
  17. package/dist/graphql/objects/index.d.cts +3 -3
  18. package/dist/graphql/objects/index.d.ts +3 -3
  19. package/dist/index.cjs +783 -265
  20. package/dist/index.d.cts +6 -6
  21. package/dist/index.d.ts +6 -6
  22. package/dist/index.js +5 -5
  23. package/dist/index.node.cjs +783 -265
  24. package/dist/index.node.d.cts +6 -6
  25. package/dist/index.node.d.ts +6 -6
  26. package/dist/index.node.js +4 -4
  27. package/dist/{logging-BOAzMqpM.d.cts → logging-BfTyKwqb.d.cts} +3 -3
  28. package/dist/{logging-Bt_WdZbu.d.ts → logging-CaNpBgiE.d.ts} +3 -3
  29. package/dist/native/index.cjs +782 -264
  30. package/dist/native/index.d.cts +70 -11
  31. package/dist/native/index.d.ts +70 -11
  32. package/dist/native/index.js +686 -172
  33. package/dist/proto/spark.cjs +499 -8
  34. package/dist/proto/spark.d.cts +1 -1
  35. package/dist/proto/spark.d.ts +1 -1
  36. package/dist/proto/spark.js +17 -1
  37. package/dist/proto/spark_token.d.cts +1 -1
  38. package/dist/proto/spark_token.d.ts +1 -1
  39. package/dist/proto/spark_token.js +2 -2
  40. package/dist/{spark-CtGJPkx4.d.cts → spark-C7OG9mGJ.d.cts} +79 -2
  41. package/dist/{spark-CtGJPkx4.d.ts → spark-C7OG9mGJ.d.ts} +79 -2
  42. package/dist/{spark-wallet-Cp3yv6cK.d.ts → spark-wallet-D0Df_P_x.d.ts} +26 -13
  43. package/dist/{spark-wallet-yc2KhsVY.d.cts → spark-wallet-Dvh1BLP6.d.cts} +26 -13
  44. package/dist/{spark-wallet.node-D0Qw5Wb4.d.cts → spark-wallet.node-B3V8_fgw.d.cts} +1 -1
  45. package/dist/{spark-wallet.node-D4IovOHu.d.ts → spark-wallet.node-bGmy8-T8.d.ts} +1 -1
  46. package/dist/tests/test-utils.cjs +573 -66
  47. package/dist/tests/test-utils.d.cts +4 -4
  48. package/dist/tests/test-utils.d.ts +4 -4
  49. package/dist/tests/test-utils.js +5 -5
  50. package/dist/{token-transactions-CwhlOgIP.d.cts → token-transactions-D1ta-sHH.d.cts} +2 -2
  51. package/dist/{token-transactions-0nmR9mQO.d.ts → token-transactions-DINiKBzd.d.ts} +2 -2
  52. package/dist/types/index.cjs +492 -9
  53. package/dist/types/index.d.cts +2 -2
  54. package/dist/types/index.d.ts +2 -2
  55. package/dist/types/index.js +2 -2
  56. package/package.json +3 -3
  57. package/src/proto/common.ts +1 -1
  58. package/src/proto/google/protobuf/descriptor.ts +4 -10
  59. package/src/proto/google/protobuf/duration.ts +1 -1
  60. package/src/proto/google/protobuf/empty.ts +1 -1
  61. package/src/proto/google/protobuf/timestamp.ts +1 -1
  62. package/src/proto/mock.ts +1 -1
  63. package/src/proto/spark.ts +593 -3
  64. package/src/proto/spark_authn.ts +1 -1
  65. package/src/proto/spark_token.ts +1 -1
  66. package/src/proto/validate/validate.ts +27 -79
  67. package/src/services/deposit.ts +55 -3
  68. package/src/services/lightning.ts +2 -2
  69. package/src/services/signing.ts +1 -1
  70. package/src/services/token-transactions.ts +2 -5
  71. package/src/services/transfer.ts +2 -28
  72. package/src/signer/signer.ts +2 -2
  73. package/src/spark-wallet/proto-descriptors.ts +22 -0
  74. package/src/spark-wallet/proto-hash.ts +743 -0
  75. package/src/spark-wallet/proto-reflection.ts +193 -0
  76. package/src/spark-wallet/spark-wallet.ts +95 -57
  77. package/src/spark_descriptors.pb +0 -0
  78. package/src/tests/address.test.ts +10 -10
  79. package/src/tests/bitcoin.test.ts +2 -2
  80. package/src/tests/bufbuild-reflection.test.ts +151 -0
  81. package/src/tests/cross-language-hash.test.ts +79 -0
  82. package/src/tests/integration/address.test.ts +3 -12
  83. package/src/tests/integration/coop-exit.test.ts +1 -1
  84. package/src/tests/integration/lightning.test.ts +1 -1
  85. package/src/tests/integration/ssp/static_deposit.test.ts +128 -1
  86. package/src/tests/integration/static_deposit.test.ts +26 -0
  87. package/src/tests/integration/swap.test.ts +1 -1
  88. package/src/tests/integration/transfer.test.ts +1 -129
  89. package/src/tests/integration/wallet.test.ts +7 -7
  90. package/src/tests/integration/watchtower.test.ts +1 -1
  91. package/src/tests/token-hashing.test.ts +3 -6
  92. package/src/tests/token-outputs.test.ts +3 -3
  93. package/src/tests/utils/test-faucet.ts +2 -2
  94. package/src/types/sdk-types.ts +1 -1
  95. package/src/utils/adaptor-signature.ts +1 -1
  96. package/src/utils/address.ts +1 -1
  97. package/src/utils/bitcoin.ts +1 -5
  98. package/src/utils/keys.ts +1 -1
  99. package/src/utils/secret-sharing.ts +1 -1
  100. package/src/utils/token-transactions.ts +1 -2
  101. package/src/utils/transfer_package.ts +1 -1
  102. package/src/utils/unilateral-exit.ts +1 -1
@@ -1611,8 +1611,8 @@ var NotImplementedError = class extends SparkSDKError {
1611
1611
 
1612
1612
  // src/spark-wallet/spark-wallet.ts
1613
1613
  var import_core13 = require("@lightsparkdev/core");
1614
- var import_utils24 = require("@noble/curves/abstract/utils");
1615
1614
  var import_secp256k115 = require("@noble/curves/secp256k1");
1615
+ var import_utils23 = require("@noble/curves/utils");
1616
1616
  var import_bip392 = require("@scure/bip39");
1617
1617
  var import_english2 = require("@scure/bip39/wordlists/english");
1618
1618
  var import_btc_signer6 = require("@scure/btc-signer");
@@ -4185,6 +4185,41 @@ function utxoSwapRequestTypeToJSON(object) {
4185
4185
  return "UNRECOGNIZED";
4186
4186
  }
4187
4187
  }
4188
+ function invoiceStatusFromJSON(object) {
4189
+ switch (object) {
4190
+ case 0:
4191
+ case "NOT_FOUND":
4192
+ return 0 /* NOT_FOUND */;
4193
+ case 1:
4194
+ case "PENDING":
4195
+ return 1 /* PENDING */;
4196
+ case 2:
4197
+ case "FINALIZED":
4198
+ return 2 /* FINALIZED */;
4199
+ case 3:
4200
+ case "EXPIRED":
4201
+ return 3 /* EXPIRED */;
4202
+ case -1:
4203
+ case "UNRECOGNIZED":
4204
+ default:
4205
+ return -1 /* UNRECOGNIZED */;
4206
+ }
4207
+ }
4208
+ function invoiceStatusToJSON(object) {
4209
+ switch (object) {
4210
+ case 0 /* NOT_FOUND */:
4211
+ return "NOT_FOUND";
4212
+ case 1 /* PENDING */:
4213
+ return "PENDING";
4214
+ case 2 /* FINALIZED */:
4215
+ return "FINALIZED";
4216
+ case 3 /* EXPIRED */:
4217
+ return "EXPIRED";
4218
+ case -1 /* UNRECOGNIZED */:
4219
+ default:
4220
+ return "UNRECOGNIZED";
4221
+ }
4222
+ }
4188
4223
  function initiatePreimageSwapRequest_ReasonFromJSON(object) {
4189
4224
  switch (object) {
4190
4225
  case 0:
@@ -4924,6 +4959,140 @@ var GenerateDepositAddressResponse = {
4924
4959
  return message;
4925
4960
  }
4926
4961
  };
4962
+ function createBaseGenerateStaticDepositAddressRequest() {
4963
+ return { signingPublicKey: new Uint8Array(0), identityPublicKey: new Uint8Array(0), network: 0 };
4964
+ }
4965
+ var GenerateStaticDepositAddressRequest = {
4966
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4967
+ if (message.signingPublicKey.length !== 0) {
4968
+ writer.uint32(10).bytes(message.signingPublicKey);
4969
+ }
4970
+ if (message.identityPublicKey.length !== 0) {
4971
+ writer.uint32(18).bytes(message.identityPublicKey);
4972
+ }
4973
+ if (message.network !== 0) {
4974
+ writer.uint32(24).int32(message.network);
4975
+ }
4976
+ return writer;
4977
+ },
4978
+ decode(input, length) {
4979
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4980
+ const end = length === void 0 ? reader.len : reader.pos + length;
4981
+ const message = createBaseGenerateStaticDepositAddressRequest();
4982
+ while (reader.pos < end) {
4983
+ const tag = reader.uint32();
4984
+ switch (tag >>> 3) {
4985
+ case 1: {
4986
+ if (tag !== 10) {
4987
+ break;
4988
+ }
4989
+ message.signingPublicKey = reader.bytes();
4990
+ continue;
4991
+ }
4992
+ case 2: {
4993
+ if (tag !== 18) {
4994
+ break;
4995
+ }
4996
+ message.identityPublicKey = reader.bytes();
4997
+ continue;
4998
+ }
4999
+ case 3: {
5000
+ if (tag !== 24) {
5001
+ break;
5002
+ }
5003
+ message.network = reader.int32();
5004
+ continue;
5005
+ }
5006
+ }
5007
+ if ((tag & 7) === 4 || tag === 0) {
5008
+ break;
5009
+ }
5010
+ reader.skip(tag & 7);
5011
+ }
5012
+ return message;
5013
+ },
5014
+ fromJSON(object) {
5015
+ return {
5016
+ signingPublicKey: isSet3(object.signingPublicKey) ? bytesFromBase642(object.signingPublicKey) : new Uint8Array(0),
5017
+ identityPublicKey: isSet3(object.identityPublicKey) ? bytesFromBase642(object.identityPublicKey) : new Uint8Array(0),
5018
+ network: isSet3(object.network) ? networkFromJSON(object.network) : 0
5019
+ };
5020
+ },
5021
+ toJSON(message) {
5022
+ const obj = {};
5023
+ if (message.signingPublicKey.length !== 0) {
5024
+ obj.signingPublicKey = base64FromBytes2(message.signingPublicKey);
5025
+ }
5026
+ if (message.identityPublicKey.length !== 0) {
5027
+ obj.identityPublicKey = base64FromBytes2(message.identityPublicKey);
5028
+ }
5029
+ if (message.network !== 0) {
5030
+ obj.network = networkToJSON(message.network);
5031
+ }
5032
+ return obj;
5033
+ },
5034
+ create(base) {
5035
+ return GenerateStaticDepositAddressRequest.fromPartial(base ?? {});
5036
+ },
5037
+ fromPartial(object) {
5038
+ const message = createBaseGenerateStaticDepositAddressRequest();
5039
+ message.signingPublicKey = object.signingPublicKey ?? new Uint8Array(0);
5040
+ message.identityPublicKey = object.identityPublicKey ?? new Uint8Array(0);
5041
+ message.network = object.network ?? 0;
5042
+ return message;
5043
+ }
5044
+ };
5045
+ function createBaseGenerateStaticDepositAddressResponse() {
5046
+ return { depositAddress: void 0 };
5047
+ }
5048
+ var GenerateStaticDepositAddressResponse = {
5049
+ encode(message, writer = new import_wire4.BinaryWriter()) {
5050
+ if (message.depositAddress !== void 0) {
5051
+ Address.encode(message.depositAddress, writer.uint32(10).fork()).join();
5052
+ }
5053
+ return writer;
5054
+ },
5055
+ decode(input, length) {
5056
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
5057
+ const end = length === void 0 ? reader.len : reader.pos + length;
5058
+ const message = createBaseGenerateStaticDepositAddressResponse();
5059
+ while (reader.pos < end) {
5060
+ const tag = reader.uint32();
5061
+ switch (tag >>> 3) {
5062
+ case 1: {
5063
+ if (tag !== 10) {
5064
+ break;
5065
+ }
5066
+ message.depositAddress = Address.decode(reader, reader.uint32());
5067
+ continue;
5068
+ }
5069
+ }
5070
+ if ((tag & 7) === 4 || tag === 0) {
5071
+ break;
5072
+ }
5073
+ reader.skip(tag & 7);
5074
+ }
5075
+ return message;
5076
+ },
5077
+ fromJSON(object) {
5078
+ return { depositAddress: isSet3(object.depositAddress) ? Address.fromJSON(object.depositAddress) : void 0 };
5079
+ },
5080
+ toJSON(message) {
5081
+ const obj = {};
5082
+ if (message.depositAddress !== void 0) {
5083
+ obj.depositAddress = Address.toJSON(message.depositAddress);
5084
+ }
5085
+ return obj;
5086
+ },
5087
+ create(base) {
5088
+ return GenerateStaticDepositAddressResponse.fromPartial(base ?? {});
5089
+ },
5090
+ fromPartial(object) {
5091
+ const message = createBaseGenerateStaticDepositAddressResponse();
5092
+ message.depositAddress = object.depositAddress !== void 0 && object.depositAddress !== null ? Address.fromPartial(object.depositAddress) : void 0;
5093
+ return message;
5094
+ }
5095
+ };
4927
5096
  function createBaseUTXO() {
4928
5097
  return { rawTx: new Uint8Array(0), vout: 0, network: 0, txid: new Uint8Array(0) };
4929
5098
  }
@@ -11037,7 +11206,8 @@ function createBaseTransferLeaf() {
11037
11206
  signature: new Uint8Array(0),
11038
11207
  intermediateRefundTx: new Uint8Array(0),
11039
11208
  intermediateDirectRefundTx: new Uint8Array(0),
11040
- intermediateDirectFromCpfpRefundTx: new Uint8Array(0)
11209
+ intermediateDirectFromCpfpRefundTx: new Uint8Array(0),
11210
+ pendingKeyTweakPublicKey: new Uint8Array(0)
11041
11211
  };
11042
11212
  }
11043
11213
  var TransferLeaf = {
@@ -11060,6 +11230,9 @@ var TransferLeaf = {
11060
11230
  if (message.intermediateDirectFromCpfpRefundTx.length !== 0) {
11061
11231
  writer.uint32(50).bytes(message.intermediateDirectFromCpfpRefundTx);
11062
11232
  }
11233
+ if (message.pendingKeyTweakPublicKey.length !== 0) {
11234
+ writer.uint32(58).bytes(message.pendingKeyTweakPublicKey);
11235
+ }
11063
11236
  return writer;
11064
11237
  },
11065
11238
  decode(input, length) {
@@ -11111,6 +11284,13 @@ var TransferLeaf = {
11111
11284
  message.intermediateDirectFromCpfpRefundTx = reader.bytes();
11112
11285
  continue;
11113
11286
  }
11287
+ case 7: {
11288
+ if (tag !== 58) {
11289
+ break;
11290
+ }
11291
+ message.pendingKeyTweakPublicKey = reader.bytes();
11292
+ continue;
11293
+ }
11114
11294
  }
11115
11295
  if ((tag & 7) === 4 || tag === 0) {
11116
11296
  break;
@@ -11126,7 +11306,8 @@ var TransferLeaf = {
11126
11306
  signature: isSet3(object.signature) ? bytesFromBase642(object.signature) : new Uint8Array(0),
11127
11307
  intermediateRefundTx: isSet3(object.intermediateRefundTx) ? bytesFromBase642(object.intermediateRefundTx) : new Uint8Array(0),
11128
11308
  intermediateDirectRefundTx: isSet3(object.intermediateDirectRefundTx) ? bytesFromBase642(object.intermediateDirectRefundTx) : new Uint8Array(0),
11129
- intermediateDirectFromCpfpRefundTx: isSet3(object.intermediateDirectFromCpfpRefundTx) ? bytesFromBase642(object.intermediateDirectFromCpfpRefundTx) : new Uint8Array(0)
11309
+ intermediateDirectFromCpfpRefundTx: isSet3(object.intermediateDirectFromCpfpRefundTx) ? bytesFromBase642(object.intermediateDirectFromCpfpRefundTx) : new Uint8Array(0),
11310
+ pendingKeyTweakPublicKey: isSet3(object.pendingKeyTweakPublicKey) ? bytesFromBase642(object.pendingKeyTweakPublicKey) : new Uint8Array(0)
11130
11311
  };
11131
11312
  },
11132
11313
  toJSON(message) {
@@ -11149,6 +11330,9 @@ var TransferLeaf = {
11149
11330
  if (message.intermediateDirectFromCpfpRefundTx.length !== 0) {
11150
11331
  obj.intermediateDirectFromCpfpRefundTx = base64FromBytes2(message.intermediateDirectFromCpfpRefundTx);
11151
11332
  }
11333
+ if (message.pendingKeyTweakPublicKey.length !== 0) {
11334
+ obj.pendingKeyTweakPublicKey = base64FromBytes2(message.pendingKeyTweakPublicKey);
11335
+ }
11152
11336
  return obj;
11153
11337
  },
11154
11338
  create(base) {
@@ -11162,6 +11346,7 @@ var TransferLeaf = {
11162
11346
  message.intermediateRefundTx = object.intermediateRefundTx ?? new Uint8Array(0);
11163
11347
  message.intermediateDirectRefundTx = object.intermediateDirectRefundTx ?? new Uint8Array(0);
11164
11348
  message.intermediateDirectFromCpfpRefundTx = object.intermediateDirectFromCpfpRefundTx ?? new Uint8Array(0);
11349
+ message.pendingKeyTweakPublicKey = object.pendingKeyTweakPublicKey ?? new Uint8Array(0);
11165
11350
  return message;
11166
11351
  }
11167
11352
  };
@@ -14059,13 +14244,16 @@ var QueryUserSignedRefundsRequest = {
14059
14244
  }
14060
14245
  };
14061
14246
  function createBaseQueryUserSignedRefundsResponse() {
14062
- return { userSignedRefunds: [] };
14247
+ return { userSignedRefunds: [], transfer: void 0 };
14063
14248
  }
14064
14249
  var QueryUserSignedRefundsResponse = {
14065
14250
  encode(message, writer = new import_wire4.BinaryWriter()) {
14066
14251
  for (const v of message.userSignedRefunds) {
14067
14252
  UserSignedRefund.encode(v, writer.uint32(10).fork()).join();
14068
14253
  }
14254
+ if (message.transfer !== void 0) {
14255
+ Transfer6.encode(message.transfer, writer.uint32(26).fork()).join();
14256
+ }
14069
14257
  return writer;
14070
14258
  },
14071
14259
  decode(input, length) {
@@ -14082,6 +14270,13 @@ var QueryUserSignedRefundsResponse = {
14082
14270
  message.userSignedRefunds.push(UserSignedRefund.decode(reader, reader.uint32()));
14083
14271
  continue;
14084
14272
  }
14273
+ case 3: {
14274
+ if (tag !== 26) {
14275
+ break;
14276
+ }
14277
+ message.transfer = Transfer6.decode(reader, reader.uint32());
14278
+ continue;
14279
+ }
14085
14280
  }
14086
14281
  if ((tag & 7) === 4 || tag === 0) {
14087
14282
  break;
@@ -14092,7 +14287,8 @@ var QueryUserSignedRefundsResponse = {
14092
14287
  },
14093
14288
  fromJSON(object) {
14094
14289
  return {
14095
- userSignedRefunds: globalThis.Array.isArray(object?.userSignedRefunds) ? object.userSignedRefunds.map((e) => UserSignedRefund.fromJSON(e)) : []
14290
+ userSignedRefunds: globalThis.Array.isArray(object?.userSignedRefunds) ? object.userSignedRefunds.map((e) => UserSignedRefund.fromJSON(e)) : [],
14291
+ transfer: isSet3(object.transfer) ? Transfer6.fromJSON(object.transfer) : void 0
14096
14292
  };
14097
14293
  },
14098
14294
  toJSON(message) {
@@ -14100,6 +14296,9 @@ var QueryUserSignedRefundsResponse = {
14100
14296
  if (message.userSignedRefunds?.length) {
14101
14297
  obj.userSignedRefunds = message.userSignedRefunds.map((e) => UserSignedRefund.toJSON(e));
14102
14298
  }
14299
+ if (message.transfer !== void 0) {
14300
+ obj.transfer = Transfer6.toJSON(message.transfer);
14301
+ }
14103
14302
  return obj;
14104
14303
  },
14105
14304
  create(base) {
@@ -14108,6 +14307,7 @@ var QueryUserSignedRefundsResponse = {
14108
14307
  fromPartial(object) {
14109
14308
  const message = createBaseQueryUserSignedRefundsResponse();
14110
14309
  message.userSignedRefunds = object.userSignedRefunds?.map((e) => UserSignedRefund.fromPartial(e)) || [];
14310
+ message.transfer = object.transfer !== void 0 && object.transfer !== null ? Transfer6.fromPartial(object.transfer) : void 0;
14111
14311
  return message;
14112
14312
  }
14113
14313
  };
@@ -14994,7 +15194,8 @@ function createBaseDepositAddressQueryResult() {
14994
15194
  depositAddress: "",
14995
15195
  userSigningPublicKey: new Uint8Array(0),
14996
15196
  verifyingPublicKey: new Uint8Array(0),
14997
- leafId: void 0
15197
+ leafId: void 0,
15198
+ proofOfPossession: void 0
14998
15199
  };
14999
15200
  }
15000
15201
  var DepositAddressQueryResult = {
@@ -15011,6 +15212,9 @@ var DepositAddressQueryResult = {
15011
15212
  if (message.leafId !== void 0) {
15012
15213
  writer.uint32(34).string(message.leafId);
15013
15214
  }
15215
+ if (message.proofOfPossession !== void 0) {
15216
+ DepositAddressProof.encode(message.proofOfPossession, writer.uint32(42).fork()).join();
15217
+ }
15014
15218
  return writer;
15015
15219
  },
15016
15220
  decode(input, length) {
@@ -15048,6 +15252,13 @@ var DepositAddressQueryResult = {
15048
15252
  message.leafId = reader.string();
15049
15253
  continue;
15050
15254
  }
15255
+ case 5: {
15256
+ if (tag !== 42) {
15257
+ break;
15258
+ }
15259
+ message.proofOfPossession = DepositAddressProof.decode(reader, reader.uint32());
15260
+ continue;
15261
+ }
15051
15262
  }
15052
15263
  if ((tag & 7) === 4 || tag === 0) {
15053
15264
  break;
@@ -15061,7 +15272,8 @@ var DepositAddressQueryResult = {
15061
15272
  depositAddress: isSet3(object.depositAddress) ? globalThis.String(object.depositAddress) : "",
15062
15273
  userSigningPublicKey: isSet3(object.userSigningPublicKey) ? bytesFromBase642(object.userSigningPublicKey) : new Uint8Array(0),
15063
15274
  verifyingPublicKey: isSet3(object.verifyingPublicKey) ? bytesFromBase642(object.verifyingPublicKey) : new Uint8Array(0),
15064
- leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : void 0
15275
+ leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : void 0,
15276
+ proofOfPossession: isSet3(object.proofOfPossession) ? DepositAddressProof.fromJSON(object.proofOfPossession) : void 0
15065
15277
  };
15066
15278
  },
15067
15279
  toJSON(message) {
@@ -15078,6 +15290,9 @@ var DepositAddressQueryResult = {
15078
15290
  if (message.leafId !== void 0) {
15079
15291
  obj.leafId = message.leafId;
15080
15292
  }
15293
+ if (message.proofOfPossession !== void 0) {
15294
+ obj.proofOfPossession = DepositAddressProof.toJSON(message.proofOfPossession);
15295
+ }
15081
15296
  return obj;
15082
15297
  },
15083
15298
  create(base) {
@@ -15089,6 +15304,7 @@ var DepositAddressQueryResult = {
15089
15304
  message.userSigningPublicKey = object.userSigningPublicKey ?? new Uint8Array(0);
15090
15305
  message.verifyingPublicKey = object.verifyingPublicKey ?? new Uint8Array(0);
15091
15306
  message.leafId = object.leafId ?? void 0;
15307
+ message.proofOfPossession = object.proofOfPossession !== void 0 && object.proofOfPossession !== null ? DepositAddressProof.fromPartial(object.proofOfPossession) : void 0;
15092
15308
  return message;
15093
15309
  }
15094
15310
  };
@@ -17053,7 +17269,7 @@ var QueryNodesByValueResponse_NodesEntry = {
17053
17269
  }
17054
17270
  };
17055
17271
  function createBaseGetUtxosForAddressRequest() {
17056
- return { address: "", offset: 0, limit: 0, network: 0 };
17272
+ return { address: "", offset: 0, limit: 0, network: 0, excludeClaimed: false };
17057
17273
  }
17058
17274
  var GetUtxosForAddressRequest = {
17059
17275
  encode(message, writer = new import_wire4.BinaryWriter()) {
@@ -17069,6 +17285,9 @@ var GetUtxosForAddressRequest = {
17069
17285
  if (message.network !== 0) {
17070
17286
  writer.uint32(32).int32(message.network);
17071
17287
  }
17288
+ if (message.excludeClaimed !== false) {
17289
+ writer.uint32(40).bool(message.excludeClaimed);
17290
+ }
17072
17291
  return writer;
17073
17292
  },
17074
17293
  decode(input, length) {
@@ -17106,6 +17325,13 @@ var GetUtxosForAddressRequest = {
17106
17325
  message.network = reader.int32();
17107
17326
  continue;
17108
17327
  }
17328
+ case 5: {
17329
+ if (tag !== 40) {
17330
+ break;
17331
+ }
17332
+ message.excludeClaimed = reader.bool();
17333
+ continue;
17334
+ }
17109
17335
  }
17110
17336
  if ((tag & 7) === 4 || tag === 0) {
17111
17337
  break;
@@ -17119,7 +17345,8 @@ var GetUtxosForAddressRequest = {
17119
17345
  address: isSet3(object.address) ? globalThis.String(object.address) : "",
17120
17346
  offset: isSet3(object.offset) ? globalThis.Number(object.offset) : 0,
17121
17347
  limit: isSet3(object.limit) ? globalThis.Number(object.limit) : 0,
17122
- network: isSet3(object.network) ? networkFromJSON(object.network) : 0
17348
+ network: isSet3(object.network) ? networkFromJSON(object.network) : 0,
17349
+ excludeClaimed: isSet3(object.excludeClaimed) ? globalThis.Boolean(object.excludeClaimed) : false
17123
17350
  };
17124
17351
  },
17125
17352
  toJSON(message) {
@@ -17136,6 +17363,9 @@ var GetUtxosForAddressRequest = {
17136
17363
  if (message.network !== 0) {
17137
17364
  obj.network = networkToJSON(message.network);
17138
17365
  }
17366
+ if (message.excludeClaimed !== false) {
17367
+ obj.excludeClaimed = message.excludeClaimed;
17368
+ }
17139
17369
  return obj;
17140
17370
  },
17141
17371
  create(base) {
@@ -17147,6 +17377,7 @@ var GetUtxosForAddressRequest = {
17147
17377
  message.offset = object.offset ?? 0;
17148
17378
  message.limit = object.limit ?? 0;
17149
17379
  message.network = object.network ?? 0;
17380
+ message.excludeClaimed = object.excludeClaimed ?? false;
17150
17381
  return message;
17151
17382
  }
17152
17383
  };
@@ -17218,6 +17449,225 @@ var GetUtxosForAddressResponse = {
17218
17449
  return message;
17219
17450
  }
17220
17451
  };
17452
+ function createBaseQuerySparkInvoicesRequest() {
17453
+ return { limit: 0, offset: 0, invoice: [] };
17454
+ }
17455
+ var QuerySparkInvoicesRequest = {
17456
+ encode(message, writer = new import_wire4.BinaryWriter()) {
17457
+ if (message.limit !== 0) {
17458
+ writer.uint32(8).int64(message.limit);
17459
+ }
17460
+ if (message.offset !== 0) {
17461
+ writer.uint32(16).int64(message.offset);
17462
+ }
17463
+ for (const v of message.invoice) {
17464
+ writer.uint32(26).string(v);
17465
+ }
17466
+ return writer;
17467
+ },
17468
+ decode(input, length) {
17469
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
17470
+ const end = length === void 0 ? reader.len : reader.pos + length;
17471
+ const message = createBaseQuerySparkInvoicesRequest();
17472
+ while (reader.pos < end) {
17473
+ const tag = reader.uint32();
17474
+ switch (tag >>> 3) {
17475
+ case 1: {
17476
+ if (tag !== 8) {
17477
+ break;
17478
+ }
17479
+ message.limit = longToNumber2(reader.int64());
17480
+ continue;
17481
+ }
17482
+ case 2: {
17483
+ if (tag !== 16) {
17484
+ break;
17485
+ }
17486
+ message.offset = longToNumber2(reader.int64());
17487
+ continue;
17488
+ }
17489
+ case 3: {
17490
+ if (tag !== 26) {
17491
+ break;
17492
+ }
17493
+ message.invoice.push(reader.string());
17494
+ continue;
17495
+ }
17496
+ }
17497
+ if ((tag & 7) === 4 || tag === 0) {
17498
+ break;
17499
+ }
17500
+ reader.skip(tag & 7);
17501
+ }
17502
+ return message;
17503
+ },
17504
+ fromJSON(object) {
17505
+ return {
17506
+ limit: isSet3(object.limit) ? globalThis.Number(object.limit) : 0,
17507
+ offset: isSet3(object.offset) ? globalThis.Number(object.offset) : 0,
17508
+ invoice: globalThis.Array.isArray(object?.invoice) ? object.invoice.map((e) => globalThis.String(e)) : []
17509
+ };
17510
+ },
17511
+ toJSON(message) {
17512
+ const obj = {};
17513
+ if (message.limit !== 0) {
17514
+ obj.limit = Math.round(message.limit);
17515
+ }
17516
+ if (message.offset !== 0) {
17517
+ obj.offset = Math.round(message.offset);
17518
+ }
17519
+ if (message.invoice?.length) {
17520
+ obj.invoice = message.invoice;
17521
+ }
17522
+ return obj;
17523
+ },
17524
+ create(base) {
17525
+ return QuerySparkInvoicesRequest.fromPartial(base ?? {});
17526
+ },
17527
+ fromPartial(object) {
17528
+ const message = createBaseQuerySparkInvoicesRequest();
17529
+ message.limit = object.limit ?? 0;
17530
+ message.offset = object.offset ?? 0;
17531
+ message.invoice = object.invoice?.map((e) => e) || [];
17532
+ return message;
17533
+ }
17534
+ };
17535
+ function createBaseQuerySparkInvoicesResponse() {
17536
+ return { offset: 0, invoiceStatuses: [] };
17537
+ }
17538
+ var QuerySparkInvoicesResponse = {
17539
+ encode(message, writer = new import_wire4.BinaryWriter()) {
17540
+ if (message.offset !== 0) {
17541
+ writer.uint32(8).int64(message.offset);
17542
+ }
17543
+ for (const v of message.invoiceStatuses) {
17544
+ InvoiceResponse.encode(v, writer.uint32(18).fork()).join();
17545
+ }
17546
+ return writer;
17547
+ },
17548
+ decode(input, length) {
17549
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
17550
+ const end = length === void 0 ? reader.len : reader.pos + length;
17551
+ const message = createBaseQuerySparkInvoicesResponse();
17552
+ while (reader.pos < end) {
17553
+ const tag = reader.uint32();
17554
+ switch (tag >>> 3) {
17555
+ case 1: {
17556
+ if (tag !== 8) {
17557
+ break;
17558
+ }
17559
+ message.offset = longToNumber2(reader.int64());
17560
+ continue;
17561
+ }
17562
+ case 2: {
17563
+ if (tag !== 18) {
17564
+ break;
17565
+ }
17566
+ message.invoiceStatuses.push(InvoiceResponse.decode(reader, reader.uint32()));
17567
+ continue;
17568
+ }
17569
+ }
17570
+ if ((tag & 7) === 4 || tag === 0) {
17571
+ break;
17572
+ }
17573
+ reader.skip(tag & 7);
17574
+ }
17575
+ return message;
17576
+ },
17577
+ fromJSON(object) {
17578
+ return {
17579
+ offset: isSet3(object.offset) ? globalThis.Number(object.offset) : 0,
17580
+ invoiceStatuses: globalThis.Array.isArray(object?.invoiceStatuses) ? object.invoiceStatuses.map((e) => InvoiceResponse.fromJSON(e)) : []
17581
+ };
17582
+ },
17583
+ toJSON(message) {
17584
+ const obj = {};
17585
+ if (message.offset !== 0) {
17586
+ obj.offset = Math.round(message.offset);
17587
+ }
17588
+ if (message.invoiceStatuses?.length) {
17589
+ obj.invoiceStatuses = message.invoiceStatuses.map((e) => InvoiceResponse.toJSON(e));
17590
+ }
17591
+ return obj;
17592
+ },
17593
+ create(base) {
17594
+ return QuerySparkInvoicesResponse.fromPartial(base ?? {});
17595
+ },
17596
+ fromPartial(object) {
17597
+ const message = createBaseQuerySparkInvoicesResponse();
17598
+ message.offset = object.offset ?? 0;
17599
+ message.invoiceStatuses = object.invoiceStatuses?.map((e) => InvoiceResponse.fromPartial(e)) || [];
17600
+ return message;
17601
+ }
17602
+ };
17603
+ function createBaseInvoiceResponse() {
17604
+ return { invoice: "", status: 0 };
17605
+ }
17606
+ var InvoiceResponse = {
17607
+ encode(message, writer = new import_wire4.BinaryWriter()) {
17608
+ if (message.invoice !== "") {
17609
+ writer.uint32(10).string(message.invoice);
17610
+ }
17611
+ if (message.status !== 0) {
17612
+ writer.uint32(16).int32(message.status);
17613
+ }
17614
+ return writer;
17615
+ },
17616
+ decode(input, length) {
17617
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
17618
+ const end = length === void 0 ? reader.len : reader.pos + length;
17619
+ const message = createBaseInvoiceResponse();
17620
+ while (reader.pos < end) {
17621
+ const tag = reader.uint32();
17622
+ switch (tag >>> 3) {
17623
+ case 1: {
17624
+ if (tag !== 10) {
17625
+ break;
17626
+ }
17627
+ message.invoice = reader.string();
17628
+ continue;
17629
+ }
17630
+ case 2: {
17631
+ if (tag !== 16) {
17632
+ break;
17633
+ }
17634
+ message.status = reader.int32();
17635
+ continue;
17636
+ }
17637
+ }
17638
+ if ((tag & 7) === 4 || tag === 0) {
17639
+ break;
17640
+ }
17641
+ reader.skip(tag & 7);
17642
+ }
17643
+ return message;
17644
+ },
17645
+ fromJSON(object) {
17646
+ return {
17647
+ invoice: isSet3(object.invoice) ? globalThis.String(object.invoice) : "",
17648
+ status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0
17649
+ };
17650
+ },
17651
+ toJSON(message) {
17652
+ const obj = {};
17653
+ if (message.invoice !== "") {
17654
+ obj.invoice = message.invoice;
17655
+ }
17656
+ if (message.status !== 0) {
17657
+ obj.status = invoiceStatusToJSON(message.status);
17658
+ }
17659
+ return obj;
17660
+ },
17661
+ create(base) {
17662
+ return InvoiceResponse.fromPartial(base ?? {});
17663
+ },
17664
+ fromPartial(object) {
17665
+ const message = createBaseInvoiceResponse();
17666
+ message.invoice = object.invoice ?? "";
17667
+ message.status = object.status ?? 0;
17668
+ return message;
17669
+ }
17670
+ };
17221
17671
  var SparkServiceDefinition = {
17222
17672
  name: "SparkService",
17223
17673
  fullName: "spark.SparkService",
@@ -17230,6 +17680,15 @@ var SparkServiceDefinition = {
17230
17680
  responseStream: false,
17231
17681
  options: {}
17232
17682
  },
17683
+ /** Generates a new static deposit address of the user or returns the existing one for the specified network. */
17684
+ generate_static_deposit_address: {
17685
+ name: "generate_static_deposit_address",
17686
+ requestType: GenerateStaticDepositAddressRequest,
17687
+ requestStream: false,
17688
+ responseType: GenerateStaticDepositAddressResponse,
17689
+ responseStream: false,
17690
+ options: {}
17691
+ },
17233
17692
  start_deposit_tree_creation: {
17234
17693
  name: "start_deposit_tree_creation",
17235
17694
  requestType: StartDepositTreeCreationRequest,
@@ -17671,6 +18130,14 @@ var SparkServiceDefinition = {
17671
18130
  responseType: GetUtxosForAddressResponse,
17672
18131
  responseStream: false,
17673
18132
  options: {}
18133
+ },
18134
+ query_spark_invoices: {
18135
+ name: "query_spark_invoices",
18136
+ requestType: QuerySparkInvoicesRequest,
18137
+ requestStream: false,
18138
+ responseType: QuerySparkInvoicesResponse,
18139
+ responseStream: false,
18140
+ options: {}
17674
18141
  }
17675
18142
  }
17676
18143
  };
@@ -17735,8 +18202,8 @@ function isSet3(value) {
17735
18202
 
17736
18203
  // src/signer/signer.ts
17737
18204
  var import_secp256k14 = require("@bitcoinerlab/secp256k1");
17738
- var import_utils5 = require("@noble/curves/abstract/utils");
17739
18205
  var import_secp256k15 = require("@noble/curves/secp256k1");
18206
+ var import_utils5 = require("@noble/curves/utils");
17740
18207
  var import_sha22 = require("@noble/hashes/sha2");
17741
18208
  var import_bip32 = require("@scure/bip32");
17742
18209
  var import_bip39 = require("@scure/bip39");
@@ -17748,7 +18215,7 @@ var ecies = __toESM(require("eciesjs"), 1);
17748
18215
  var import_core10 = require("@lightsparkdev/core");
17749
18216
  var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
17750
18217
  var isBun = globalThis.Bun !== void 0;
17751
- var packageVersion = true ? "0.2.11" : "unknown";
18218
+ var packageVersion = true ? "0.2.13" : "unknown";
17752
18219
  var baseEnvStr = "unknown";
17753
18220
  if (isBun) {
17754
18221
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -17767,8 +18234,8 @@ if (isBun) {
17767
18234
  var clientEnv = `js-spark-sdk/${packageVersion} ${baseEnvStr}`;
17768
18235
 
17769
18236
  // src/utils/keys.ts
17770
- var import_utils2 = require("@noble/curves/abstract/utils");
17771
18237
  var import_secp256k1 = require("@noble/curves/secp256k1");
18238
+ var import_utils2 = require("@noble/curves/utils");
17772
18239
  function addPublicKeys(a, b) {
17773
18240
  if (a.length !== 33 || b.length !== 33) {
17774
18241
  throw new ValidationError("Public keys must be 33 bytes", {
@@ -17865,8 +18332,8 @@ function lastKeyWithTarget(target, keys) {
17865
18332
  }
17866
18333
 
17867
18334
  // src/utils/secret-sharing.ts
17868
- var import_utils3 = require("@noble/curves/abstract/utils");
17869
18335
  var import_secp256k12 = require("@noble/curves/secp256k1");
18336
+ var import_utils3 = require("@noble/curves/utils");
17870
18337
  function getRandomBigInt(max) {
17871
18338
  const byteLength = max.toString(2).length + 7 >> 3;
17872
18339
  const maxBigInt = max;
@@ -23153,8 +23620,8 @@ var import_btc_signer3 = require("@scure/btc-signer");
23153
23620
  var import_uuidv72 = require("uuidv7");
23154
23621
 
23155
23622
  // src/utils/bitcoin.ts
23156
- var import_utils7 = require("@noble/curves/abstract/utils");
23157
23623
  var import_secp256k16 = require("@noble/curves/secp256k1");
23624
+ var import_utils7 = require("@noble/curves/utils");
23158
23625
  var import_sha24 = require("@noble/hashes/sha2");
23159
23626
  var btc2 = __toESM(require("@scure/btc-signer"), 1);
23160
23627
  function computeTaprootKeyNoScript(pubkey) {
@@ -23640,15 +24107,15 @@ function getEphemeralAnchorOutput() {
23640
24107
  }
23641
24108
 
23642
24109
  // src/services/transfer.ts
23643
- var import_utils9 = require("@noble/curves/abstract/utils");
23644
24110
  var import_secp256k17 = require("@noble/curves/secp256k1");
24111
+ var import_utils9 = require("@noble/curves/utils");
23645
24112
  var import_sha26 = require("@noble/hashes/sha2");
23646
24113
  var import_btc_signer2 = require("@scure/btc-signer");
23647
24114
  var ecies2 = __toESM(require("eciesjs"), 1);
23648
24115
  var import_uuidv7 = require("uuidv7");
23649
24116
 
23650
24117
  // src/utils/transfer_package.ts
23651
- var import_utils8 = require("@noble/curves/abstract/utils");
24118
+ var import_utils8 = require("@noble/curves/utils");
23652
24119
  var import_sha25 = require("@noble/hashes/sha2");
23653
24120
  function getTransferPackageSigningPayload(transferID, transferPackage) {
23654
24121
  const encryptedPayload = transferPackage.keyTweakPackage;
@@ -24659,24 +25126,6 @@ var TransferService = class extends BaseTransferService {
24659
25126
  throw new Error(`Error finalizing node signatures in transfer: ${error}`);
24660
25127
  }
24661
25128
  }
24662
- async cancelTransfer(transfer, operatorAddress) {
24663
- const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
24664
- try {
24665
- const response = await sparkClient.cancel_transfer({
24666
- transferId: transfer.id,
24667
- senderIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
24668
- });
24669
- return response.transfer;
24670
- } catch (error) {
24671
- throw new NetworkError(
24672
- "Failed to cancel transfer",
24673
- {
24674
- method: "POST"
24675
- },
24676
- error
24677
- );
24678
- }
24679
- }
24680
25129
  async queryPendingTransfersBySender(operatorAddress) {
24681
25130
  const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
24682
25131
  try {
@@ -25585,7 +26034,8 @@ var DepositService = class {
25585
26034
  }
25586
26035
  async validateDepositAddress({
25587
26036
  address: address2,
25588
- userPubkey
26037
+ userPubkey,
26038
+ verifyCoordinatorProof = false
25589
26039
  }) {
25590
26040
  if (!address2.depositAddressProof || !address2.depositAddressProof.proofOfPossessionSignature || !address2.depositAddressProof.addressSignatures) {
25591
26041
  throw new ValidationError(
@@ -25623,7 +26073,7 @@ var DepositService = class {
25623
26073
  }
25624
26074
  const addrHash = (0, import_sha28.sha256)(address2.address);
25625
26075
  for (const operator of Object.values(this.config.getSigningOperators())) {
25626
- if (operator.identifier === this.config.getCoordinatorIdentifier()) {
26076
+ if (operator.identifier === this.config.getCoordinatorIdentifier() && !verifyCoordinatorProof) {
25627
26077
  continue;
25628
26078
  }
25629
26079
  const operatorPubkey2 = (0, import_utils10.hexToBytes)(operator.identityPublicKey);
@@ -25648,6 +26098,46 @@ var DepositService = class {
25648
26098
  }
25649
26099
  }
25650
26100
  }
26101
+ async generateStaticDepositAddress({
26102
+ signingPubkey
26103
+ }) {
26104
+ const sparkClient = await this.connectionManager.createSparkClient(
26105
+ this.config.getCoordinatorAddress()
26106
+ );
26107
+ let depositResp;
26108
+ try {
26109
+ depositResp = await sparkClient.generate_static_deposit_address({
26110
+ signingPublicKey: signingPubkey,
26111
+ identityPublicKey: await this.config.signer.getIdentityPublicKey(),
26112
+ network: this.config.getNetworkProto()
26113
+ });
26114
+ } catch (error) {
26115
+ throw new NetworkError(
26116
+ "Failed to generate static deposit address",
26117
+ {
26118
+ operation: "generate_static_deposit_address",
26119
+ errorCount: 1,
26120
+ errors: error instanceof Error ? error.message : String(error)
26121
+ },
26122
+ error
26123
+ );
26124
+ }
26125
+ if (!depositResp.depositAddress) {
26126
+ throw new ValidationError(
26127
+ "No static deposit address response from coordinator",
26128
+ {
26129
+ field: "depositAddress",
26130
+ value: depositResp
26131
+ }
26132
+ );
26133
+ }
26134
+ await this.validateDepositAddress({
26135
+ address: depositResp.depositAddress,
26136
+ userPubkey: signingPubkey,
26137
+ verifyCoordinatorProof: true
26138
+ });
26139
+ return depositResp;
26140
+ }
25651
26141
  async generateDepositAddress({
25652
26142
  signingPubkey,
25653
26143
  leafId,
@@ -26187,8 +26677,8 @@ var DepositService = class {
26187
26677
  };
26188
26678
 
26189
26679
  // src/services/lightning.ts
26190
- var import_utils12 = require("@noble/curves/abstract/utils");
26191
26680
  var import_secp256k19 = require("@noble/curves/secp256k1");
26681
+ var import_utils12 = require("@noble/curves/utils");
26192
26682
  var import_sha29 = require("@noble/hashes/sha2");
26193
26683
  var import_uuidv73 = require("uuidv7");
26194
26684
 
@@ -26534,14 +27024,14 @@ var LightningService = class {
26534
27024
  };
26535
27025
 
26536
27026
  // src/services/token-transactions.ts
26537
- var import_utils17 = require("@noble/curves/abstract/utils");
26538
27027
  var import_secp256k112 = require("@noble/curves/secp256k1");
26539
- var import_utils18 = require("@noble/hashes/utils");
27028
+ var import_utils16 = require("@noble/curves/utils");
27029
+ var import_utils17 = require("@noble/hashes/utils");
26540
27030
 
26541
27031
  // src/utils/address.ts
26542
27032
  var import_wire8 = require("@bufbuild/protobuf/wire");
26543
- var import_utils13 = require("@noble/curves/abstract/utils");
26544
27033
  var import_secp256k110 = require("@noble/curves/secp256k1");
27034
+ var import_utils13 = require("@noble/curves/utils");
26545
27035
  var import_utils14 = require("@noble/hashes/utils");
26546
27036
  var import_base2 = require("@scure/base");
26547
27037
  var import_uuidv74 = require("uuidv7");
@@ -29026,8 +29516,7 @@ function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction
29026
29516
  }
29027
29517
 
29028
29518
  // src/utils/token-transactions.ts
29029
- var import_utils15 = require("@noble/curves/abstract/utils");
29030
- var import_utils16 = require("@scure/btc-signer/utils");
29519
+ var import_utils15 = require("@noble/curves/utils");
29031
29520
  function sumAvailableTokens(outputs) {
29032
29521
  try {
29033
29522
  return outputs.reduce(
@@ -29062,7 +29551,7 @@ function filterTokenBalanceForTokenIdentifier(tokenBalances, tokenIdentifier) {
29062
29551
  }
29063
29552
  const tokenIdentifierBytes = decodeBech32mTokenIdentifier(tokenIdentifier).tokenIdentifier;
29064
29553
  const tokenBalance = [...tokenBalances.entries()].find(
29065
- ([, info]) => (0, import_utils16.equalBytes)(info.tokenMetadata.rawTokenIdentifier, tokenIdentifierBytes)
29554
+ ([, info]) => (0, import_utils15.equalBytes)(info.tokenMetadata.rawTokenIdentifier, tokenIdentifierBytes)
29066
29555
  );
29067
29556
  if (!tokenBalance) {
29068
29557
  return {
@@ -29165,14 +29654,14 @@ var TokenTransactionService = class {
29165
29654
  }
29166
29655
  if (this.config.getTokenTransactionVersion() !== "V0" && receiverAddress.sparkInvoiceFields) {
29167
29656
  return {
29168
- receiverPublicKey: (0, import_utils18.hexToBytes)(receiverAddress.identityPublicKey),
29657
+ receiverPublicKey: (0, import_utils17.hexToBytes)(receiverAddress.identityPublicKey),
29169
29658
  rawTokenIdentifier,
29170
29659
  tokenAmount: transfer.tokenAmount,
29171
29660
  sparkInvoice: transfer.receiverSparkAddress
29172
29661
  };
29173
29662
  }
29174
29663
  return {
29175
- receiverPublicKey: (0, import_utils18.hexToBytes)(receiverAddress.identityPublicKey),
29664
+ receiverPublicKey: (0, import_utils17.hexToBytes)(receiverAddress.identityPublicKey),
29176
29665
  rawTokenIdentifier,
29177
29666
  tokenPublicKey,
29178
29667
  // Remove for full v0 deprecation
@@ -29211,7 +29700,7 @@ var TokenTransactionService = class {
29211
29700
  const tokenOutputs = tokenOutputData.map((output) => ({
29212
29701
  ownerPublicKey: output.receiverPublicKey,
29213
29702
  tokenPublicKey: output.tokenPublicKey,
29214
- tokenAmount: (0, import_utils17.numberToBytesBE)(output.tokenAmount, 16)
29703
+ tokenAmount: (0, import_utils16.numberToBytesBE)(output.tokenAmount, 16)
29215
29704
  }));
29216
29705
  if (availableTokenAmount > totalRequestedAmount) {
29217
29706
  const changeAmount = availableTokenAmount - totalRequestedAmount;
@@ -29219,7 +29708,7 @@ var TokenTransactionService = class {
29219
29708
  tokenOutputs.push({
29220
29709
  ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
29221
29710
  tokenPublicKey: firstTokenPublicKey,
29222
- tokenAmount: (0, import_utils17.numberToBytesBE)(changeAmount, 16)
29711
+ tokenAmount: (0, import_utils16.numberToBytesBE)(changeAmount, 16)
29223
29712
  });
29224
29713
  }
29225
29714
  return {
@@ -29250,7 +29739,7 @@ var TokenTransactionService = class {
29250
29739
  (output) => ({
29251
29740
  ownerPublicKey: output.receiverPublicKey,
29252
29741
  tokenIdentifier: output.rawTokenIdentifier,
29253
- tokenAmount: (0, import_utils17.numberToBytesBE)(output.tokenAmount, 16)
29742
+ tokenAmount: (0, import_utils16.numberToBytesBE)(output.tokenAmount, 16)
29254
29743
  })
29255
29744
  );
29256
29745
  if (availableTokenAmount > totalRequestedAmount) {
@@ -29259,7 +29748,7 @@ var TokenTransactionService = class {
29259
29748
  tokenOutputs.push({
29260
29749
  ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
29261
29750
  tokenIdentifier: firstTokenIdentifierBytes,
29262
- tokenAmount: (0, import_utils17.numberToBytesBE)(changeAmount, 16)
29751
+ tokenAmount: (0, import_utils16.numberToBytesBE)(changeAmount, 16)
29263
29752
  });
29264
29753
  }
29265
29754
  return {
@@ -29286,7 +29775,7 @@ var TokenTransactionService = class {
29286
29775
  for (const [_, operator] of Object.entries(
29287
29776
  this.config.getSigningOperators()
29288
29777
  )) {
29289
- operatorKeys.push((0, import_utils18.hexToBytes)(operator.identityPublicKey));
29778
+ operatorKeys.push((0, import_utils17.hexToBytes)(operator.identityPublicKey));
29290
29779
  }
29291
29780
  return operatorKeys;
29292
29781
  }
@@ -29370,7 +29859,7 @@ var TokenTransactionService = class {
29370
29859
  {
29371
29860
  field: "revocationCommitment",
29372
29861
  value: derivedRevocationCommitment,
29373
- expected: (0, import_utils17.bytesToHex)(outputsToSpendCommitments[outputIndex]),
29862
+ expected: (0, import_utils16.bytesToHex)(outputsToSpendCommitments[outputIndex]),
29374
29863
  outputIndex
29375
29864
  }
29376
29865
  )
@@ -29396,7 +29885,7 @@ var TokenTransactionService = class {
29396
29885
  threshold
29397
29886
  );
29398
29887
  }
29399
- return (0, import_utils17.bytesToHex)(finalTokenTransactionHash);
29888
+ return (0, import_utils16.bytesToHex)(finalTokenTransactionHash);
29400
29889
  }
29401
29890
  async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
29402
29891
  const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
@@ -29410,7 +29899,7 @@ var TokenTransactionService = class {
29410
29899
  finalTokenTransactionHash,
29411
29900
  signingOperators
29412
29901
  );
29413
- return (0, import_utils17.bytesToHex)(finalTokenTransactionHash);
29902
+ return (0, import_utils16.bytesToHex)(finalTokenTransactionHash);
29414
29903
  }
29415
29904
  async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
29416
29905
  const sparkClient = await this.connectionManager.createSparkClient(
@@ -29634,7 +30123,7 @@ var TokenTransactionService = class {
29634
30123
  const identityPublicKey = await this.config.signer.getIdentityPublicKey();
29635
30124
  const payload = {
29636
30125
  finalTokenTransactionHash,
29637
- operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
30126
+ operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
29638
30127
  };
29639
30128
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
29640
30129
  let operatorSpecificSignatures = [];
@@ -29849,8 +30338,8 @@ var TokenTransactionService = class {
29849
30338
  this.config.getCoordinatorAddress()
29850
30339
  );
29851
30340
  let queryParams = {
29852
- tokenPublicKeys: issuerPublicKeys?.map(import_utils18.hexToBytes),
29853
- ownerPublicKeys: ownerPublicKeys?.map(import_utils18.hexToBytes),
30341
+ tokenPublicKeys: issuerPublicKeys?.map(import_utils17.hexToBytes),
30342
+ ownerPublicKeys: ownerPublicKeys?.map(import_utils17.hexToBytes),
29854
30343
  tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
29855
30344
  const { tokenIdentifier } = decodeBech32mTokenIdentifier(
29856
30345
  identifier,
@@ -29858,7 +30347,7 @@ var TokenTransactionService = class {
29858
30347
  );
29859
30348
  return tokenIdentifier;
29860
30349
  }),
29861
- tokenTransactionHashes: tokenTransactionHashes?.map(import_utils18.hexToBytes),
30350
+ tokenTransactionHashes: tokenTransactionHashes?.map(import_utils17.hexToBytes),
29862
30351
  outputIds: outputIds || [],
29863
30352
  limit: pageSize,
29864
30353
  offset
@@ -29917,8 +30406,8 @@ var TokenTransactionService = class {
29917
30406
  this.config.getCoordinatorAddress()
29918
30407
  );
29919
30408
  let queryParams = {
29920
- issuerPublicKeys: issuerPublicKeys?.map(import_utils18.hexToBytes),
29921
- ownerPublicKeys: ownerPublicKeys?.map(import_utils18.hexToBytes),
30409
+ issuerPublicKeys: issuerPublicKeys?.map(import_utils17.hexToBytes),
30410
+ ownerPublicKeys: ownerPublicKeys?.map(import_utils17.hexToBytes),
29922
30411
  tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
29923
30412
  const { tokenIdentifier } = decodeBech32mTokenIdentifier(
29924
30413
  identifier,
@@ -29926,7 +30415,7 @@ var TokenTransactionService = class {
29926
30415
  );
29927
30416
  return tokenIdentifier;
29928
30417
  }),
29929
- tokenTransactionHashes: tokenTransactionHashes?.map(import_utils18.hexToBytes),
30418
+ tokenTransactionHashes: tokenTransactionHashes?.map(import_utils17.hexToBytes),
29930
30419
  outputIds: outputIds || [],
29931
30420
  limit: pageSize,
29932
30421
  offset
@@ -29961,7 +30450,7 @@ var TokenTransactionService = class {
29961
30450
  });
29962
30451
  }
29963
30452
  const exactMatch = tokenOutputs.find(
29964
- (item) => (0, import_utils17.bytesToNumberBE)(item.output.tokenAmount) === tokenAmount
30453
+ (item) => (0, import_utils16.bytesToNumberBE)(item.output.tokenAmount) === tokenAmount
29965
30454
  );
29966
30455
  if (exactMatch) {
29967
30456
  return [exactMatch];
@@ -29972,7 +30461,7 @@ var TokenTransactionService = class {
29972
30461
  for (const outputWithPreviousTransactionData of tokenOutputs) {
29973
30462
  if (remainingAmount <= 0n) break;
29974
30463
  selectedOutputs.push(outputWithPreviousTransactionData);
29975
- remainingAmount -= (0, import_utils17.bytesToNumberBE)(
30464
+ remainingAmount -= (0, import_utils16.bytesToNumberBE)(
29976
30465
  outputWithPreviousTransactionData.output.tokenAmount
29977
30466
  );
29978
30467
  }
@@ -29988,13 +30477,13 @@ var TokenTransactionService = class {
29988
30477
  if (strategy === "SMALL_FIRST") {
29989
30478
  tokenOutputs.sort((a, b) => {
29990
30479
  return Number(
29991
- (0, import_utils17.bytesToNumberBE)(a.output.tokenAmount) - (0, import_utils17.bytesToNumberBE)(b.output.tokenAmount)
30480
+ (0, import_utils16.bytesToNumberBE)(a.output.tokenAmount) - (0, import_utils16.bytesToNumberBE)(b.output.tokenAmount)
29992
30481
  );
29993
30482
  });
29994
30483
  } else {
29995
30484
  tokenOutputs.sort((a, b) => {
29996
30485
  return Number(
29997
- (0, import_utils17.bytesToNumberBE)(b.output.tokenAmount) - (0, import_utils17.bytesToNumberBE)(a.output.tokenAmount)
30486
+ (0, import_utils16.bytesToNumberBE)(b.output.tokenAmount) - (0, import_utils16.bytesToNumberBE)(a.output.tokenAmount)
29998
30487
  );
29999
30488
  });
30000
30489
  }
@@ -30002,7 +30491,7 @@ var TokenTransactionService = class {
30002
30491
  // Helper function for deciding if the signer public key is the identity public key
30003
30492
  async signMessageWithKey(message, publicKey) {
30004
30493
  const tokenSignatures = this.config.getTokenSignatures();
30005
- if ((0, import_utils17.bytesToHex)(publicKey) === (0, import_utils17.bytesToHex)(await this.config.signer.getIdentityPublicKey())) {
30494
+ if ((0, import_utils16.bytesToHex)(publicKey) === (0, import_utils16.bytesToHex)(await this.config.signer.getIdentityPublicKey())) {
30006
30495
  if (tokenSignatures === "SCHNORR") {
30007
30496
  return await this.config.signer.signSchnorrWithIdentityKey(message);
30008
30497
  } else {
@@ -30011,8 +30500,8 @@ var TokenTransactionService = class {
30011
30500
  } else {
30012
30501
  throw new ValidationError("Invalid public key", {
30013
30502
  field: "publicKey",
30014
- value: (0, import_utils17.bytesToHex)(publicKey),
30015
- expected: (0, import_utils17.bytesToHex)(await this.config.signer.getIdentityPublicKey())
30503
+ value: (0, import_utils16.bytesToHex)(publicKey),
30504
+ expected: (0, import_utils16.bytesToHex)(await this.config.signer.getIdentityPublicKey())
30016
30505
  });
30017
30506
  }
30018
30507
  }
@@ -30075,7 +30564,7 @@ var TokenTransactionService = class {
30075
30564
  }
30076
30565
  const payload = {
30077
30566
  finalTokenTransactionHash,
30078
- operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
30567
+ operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
30079
30568
  };
30080
30569
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
30081
30570
  const ownerSignature = await this.signMessageWithKey(
@@ -30097,7 +30586,7 @@ var TokenTransactionService = class {
30097
30586
  }
30098
30587
  const payload = {
30099
30588
  finalTokenTransactionHash,
30100
- operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
30589
+ operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
30101
30590
  };
30102
30591
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
30103
30592
  const ownerSignature = await this.signMessageWithKey(
@@ -30113,7 +30602,7 @@ var TokenTransactionService = class {
30113
30602
  for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
30114
30603
  const payload = {
30115
30604
  finalTokenTransactionHash,
30116
- operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
30605
+ operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
30117
30606
  };
30118
30607
  const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
30119
30608
  let ownerSignature;
@@ -30130,7 +30619,7 @@ var TokenTransactionService = class {
30130
30619
  }
30131
30620
  inputTtxoSignaturesPerOperator.push({
30132
30621
  ttxoSignatures,
30133
- operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
30622
+ operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
30134
30623
  });
30135
30624
  }
30136
30625
  return inputTtxoSignaturesPerOperator;
@@ -30142,23 +30631,23 @@ function isTokenTransaction(tokenTransaction) {
30142
30631
 
30143
30632
  // src/utils/adaptor-signature.ts
30144
30633
  var import_modular = require("@noble/curves/abstract/modular");
30145
- var import_utils19 = require("@noble/curves/abstract/utils");
30146
30634
  var import_secp256k113 = require("@noble/curves/secp256k1");
30635
+ var import_utils18 = require("@noble/curves/utils");
30147
30636
  function generateSignatureFromExistingAdaptor(signature, adaptorPrivateKeyBytes) {
30148
30637
  const { r, s } = parseSignature(signature);
30149
- const sBigInt = (0, import_utils19.bytesToNumberBE)(s);
30150
- const tBigInt = (0, import_utils19.bytesToNumberBE)(adaptorPrivateKeyBytes);
30638
+ const sBigInt = (0, import_utils18.bytesToNumberBE)(s);
30639
+ const tBigInt = (0, import_utils18.bytesToNumberBE)(adaptorPrivateKeyBytes);
30151
30640
  const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k113.secp256k1.CURVE.n);
30152
- const newSignature = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(newS, 32)]);
30641
+ const newSignature = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(newS, 32)]);
30153
30642
  return newSignature;
30154
30643
  }
30155
30644
  function generateAdaptorFromSignature(signature) {
30156
30645
  const adaptorPrivateKey = import_secp256k113.secp256k1.utils.randomPrivateKey();
30157
30646
  const { r, s } = parseSignature(signature);
30158
- const sBigInt = (0, import_utils19.bytesToNumberBE)(s);
30159
- const tBigInt = (0, import_utils19.bytesToNumberBE)(adaptorPrivateKey);
30647
+ const sBigInt = (0, import_utils18.bytesToNumberBE)(s);
30648
+ const tBigInt = (0, import_utils18.bytesToNumberBE)(adaptorPrivateKey);
30160
30649
  const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k113.secp256k1.CURVE.n);
30161
- const newSignature = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(newS, 32)]);
30650
+ const newSignature = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(newS, 32)]);
30162
30651
  return {
30163
30652
  adaptorSignature: newSignature,
30164
30653
  adaptorPrivateKey
@@ -30175,10 +30664,10 @@ function validateOutboundAdaptorSignature(pubkey, hash, signature, adaptorPubkey
30175
30664
  }
30176
30665
  function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes) {
30177
30666
  const { r, s } = parseSignature(signature);
30178
- const sBigInt = (0, import_utils19.bytesToNumberBE)(s);
30179
- const adaptorPrivateKey = (0, import_utils19.bytesToNumberBE)(adaptorPrivateKeyBytes);
30667
+ const sBigInt = (0, import_utils18.bytesToNumberBE)(s);
30668
+ const adaptorPrivateKey = (0, import_utils18.bytesToNumberBE)(adaptorPrivateKeyBytes);
30180
30669
  const newS = (0, import_modular.mod)(sBigInt + adaptorPrivateKey, import_secp256k113.secp256k1.CURVE.n);
30181
- const newSig = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(newS, 32)]);
30670
+ const newSig = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(newS, 32)]);
30182
30671
  try {
30183
30672
  if (import_secp256k113.schnorr.verify(newSig, hash, pubkey)) {
30184
30673
  return newSig;
@@ -30187,7 +30676,7 @@ function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes
30187
30676
  console.error("[applyAdaptorToSignature] Addition verification failed:", e);
30188
30677
  }
30189
30678
  const altS = (0, import_modular.mod)(sBigInt - adaptorPrivateKey, import_secp256k113.secp256k1.CURVE.n);
30190
- const altSig = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(altS, 32)]);
30679
+ const altSig = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(altS, 32)]);
30191
30680
  try {
30192
30681
  if (import_secp256k113.schnorr.verify(altSig, hash, pubkey)) {
30193
30682
  return altSig;
@@ -30204,7 +30693,7 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
30204
30693
  if (hash.length !== 32) {
30205
30694
  throw new Error(`wrong size for message (got ${hash.length}, want 32)`);
30206
30695
  }
30207
- const pubKey = import_secp256k113.schnorr.utils.lift_x((0, import_utils19.bytesToNumberBE)(pubKeyBytes));
30696
+ const pubKey = import_secp256k113.schnorr.utils.lift_x((0, import_utils18.bytesToNumberBE)(pubKeyBytes));
30208
30697
  pubKey.assertValidity();
30209
30698
  const { r, s } = parseSignature(signature);
30210
30699
  const commitmenet = import_secp256k113.schnorr.utils.taggedHash(
@@ -30216,9 +30705,9 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
30216
30705
  if (commitmenet.length > 32) {
30217
30706
  throw new Error("hash of (r || P || m) too big");
30218
30707
  }
30219
- const e = (0, import_modular.mod)((0, import_utils19.bytesToNumberBE)(commitmenet), import_secp256k113.secp256k1.CURVE.n);
30708
+ const e = (0, import_modular.mod)((0, import_utils18.bytesToNumberBE)(commitmenet), import_secp256k113.secp256k1.CURVE.n);
30220
30709
  const negE = (0, import_modular.mod)(-e, import_secp256k113.secp256k1.CURVE.n);
30221
- const sG = import_secp256k113.secp256k1.Point.BASE.multiplyUnsafe((0, import_utils19.bytesToNumberBE)(s));
30710
+ const sG = import_secp256k113.secp256k1.Point.BASE.multiplyUnsafe((0, import_utils18.bytesToNumberBE)(s));
30222
30711
  const eP = pubKey.multiplyUnsafe(negE);
30223
30712
  const R = sG.add(eP);
30224
30713
  if (R.is0()) {
@@ -30234,7 +30723,7 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
30234
30723
  if (newR.y % 2n !== 0n) {
30235
30724
  throw new Error("calculated R y-value is odd");
30236
30725
  }
30237
- const rNum = (0, import_utils19.bytesToNumberBE)(r);
30726
+ const rNum = (0, import_utils18.bytesToNumberBE)(r);
30238
30727
  if (newR.toAffine().x !== rNum) {
30239
30728
  throw new Error("calculated R point was not given R");
30240
30729
  }
@@ -30255,15 +30744,15 @@ function parseSignature(signature) {
30255
30744
  }
30256
30745
  const r = signature.slice(0, 32);
30257
30746
  const s = signature.slice(32, 64);
30258
- if ((0, import_utils19.bytesToNumberBE)(r) >= import_secp256k113.secp256k1.CURVE.Fp.ORDER) {
30747
+ if ((0, import_utils18.bytesToNumberBE)(r) >= import_secp256k113.secp256k1.CURVE.Fp.ORDER) {
30259
30748
  throw new ValidationError("Invalid signature: r >= field prime", {
30260
- rValue: (0, import_utils19.bytesToNumberBE)(r),
30749
+ rValue: (0, import_utils18.bytesToNumberBE)(r),
30261
30750
  fieldPrime: import_secp256k113.secp256k1.CURVE.Fp.ORDER
30262
30751
  });
30263
30752
  }
30264
- if ((0, import_utils19.bytesToNumberBE)(s) >= import_secp256k113.secp256k1.CURVE.n) {
30753
+ if ((0, import_utils18.bytesToNumberBE)(s) >= import_secp256k113.secp256k1.CURVE.n) {
30265
30754
  throw new ValidationError("Invalid signature: s >= group order", {
30266
- sValue: (0, import_utils19.bytesToNumberBE)(s),
30755
+ sValue: (0, import_utils18.bytesToNumberBE)(s),
30267
30756
  groupOrder: import_secp256k113.secp256k1.CURVE.n
30268
30757
  });
30269
30758
  }
@@ -30278,7 +30767,7 @@ var import_eventemitter3 = require("eventemitter3");
30278
30767
  var import_nice_grpc_common3 = require("nice-grpc-common");
30279
30768
 
30280
30769
  // src/services/signing.ts
30281
- var import_utils20 = require("@noble/curves/abstract/utils");
30770
+ var import_utils19 = require("@noble/curves/utils");
30282
30771
  var SigningService = class {
30283
30772
  config;
30284
30773
  constructor(config) {
@@ -30334,7 +30823,7 @@ var SigningService = class {
30334
30823
  }
30335
30824
  const nodeTx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
30336
30825
  const cpfpNodeOutPoint = {
30337
- txid: (0, import_utils20.hexToBytes)(getTxId(nodeTx)),
30826
+ txid: (0, import_utils19.hexToBytes)(getTxId(nodeTx)),
30338
30827
  index: 0
30339
30828
  };
30340
30829
  const currRefundTx = getTxFromRawTxBytes(leaf.leaf.refundTx);
@@ -30360,7 +30849,7 @@ var SigningService = class {
30360
30849
  if (leaf.leaf.directTx.length > 0) {
30361
30850
  directNodeTx = getTxFromRawTxBytes(leaf.leaf.directTx);
30362
30851
  directNodeOutPoint = {
30363
- txid: (0, import_utils20.hexToBytes)(getTxId(directNodeTx)),
30852
+ txid: (0, import_utils19.hexToBytes)(getTxId(directNodeTx)),
30364
30853
  index: 0
30365
30854
  };
30366
30855
  }
@@ -30443,15 +30932,15 @@ var SigningService = class {
30443
30932
  };
30444
30933
 
30445
30934
  // src/tests/utils/test-faucet.ts
30446
- var import_utils21 = require("@noble/curves/abstract/utils");
30447
30935
  var import_secp256k114 = require("@noble/curves/secp256k1");
30936
+ var import_utils20 = require("@noble/curves/utils");
30448
30937
  var btc3 = __toESM(require("@scure/btc-signer"), 1);
30449
30938
  var import_btc_signer5 = require("@scure/btc-signer");
30450
- var import_utils22 = require("@scure/btc-signer/utils");
30451
- var STATIC_FAUCET_KEY = (0, import_utils21.hexToBytes)(
30939
+ var import_utils21 = require("@scure/btc-signer/utils");
30940
+ var STATIC_FAUCET_KEY = (0, import_utils20.hexToBytes)(
30452
30941
  "deadbeef1337cafe4242424242424242deadbeef1337cafe4242424242424242"
30453
30942
  );
30454
- var STATIC_MINING_KEY = (0, import_utils21.hexToBytes)(
30943
+ var STATIC_MINING_KEY = (0, import_utils20.hexToBytes)(
30455
30944
  "1337cafe4242deadbeef4242424242421337cafe4242deadbeef424242424242"
30456
30945
  );
30457
30946
  var SATS_PER_BTC = 1e8;
@@ -30514,7 +31003,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
30514
31003
  if (!scanResult.success || scanResult.unspents.length === 0) {
30515
31004
  const blockHash = await this.generateToAddress(1, address2);
30516
31005
  const block = await this.getBlock(blockHash[0]);
30517
- const fundingTx = import_btc_signer5.Transaction.fromRaw((0, import_utils21.hexToBytes)(block.tx[0].hex), {
31006
+ const fundingTx = import_btc_signer5.Transaction.fromRaw((0, import_utils20.hexToBytes)(block.tx[0].hex), {
30518
31007
  allowUnknownOutputs: true
30519
31008
  });
30520
31009
  await this.generateToAddress(100, this.miningAddress);
@@ -30576,13 +31065,13 @@ var BitcoinFaucet = class _BitcoinFaucet {
30576
31065
  },
30577
31066
  STATIC_MINING_KEY
30578
31067
  );
30579
- await this.broadcastTx((0, import_utils21.bytesToHex)(signedSplitTx.extract()));
31068
+ await this.broadcastTx((0, import_utils20.bytesToHex)(signedSplitTx.extract()));
30580
31069
  const splitTxId = signedSplitTx.id;
30581
31070
  for (let i = 0; i < numCoinsToCreate; i++) {
30582
31071
  this.coins.push({
30583
31072
  key: STATIC_FAUCET_KEY,
30584
31073
  outpoint: {
30585
- txid: (0, import_utils21.hexToBytes)(splitTxId),
31074
+ txid: (0, import_utils20.hexToBytes)(splitTxId),
30586
31075
  index: i
30587
31076
  },
30588
31077
  txout: signedSplitTx.getOutput(i)
@@ -30610,7 +31099,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
30610
31099
  coinToSend.txout,
30611
31100
  coinToSend.key
30612
31101
  );
30613
- await this.broadcastTx((0, import_utils21.bytesToHex)(signedTx.extract()));
31102
+ await this.broadcastTx((0, import_utils20.bytesToHex)(signedTx.extract()));
30614
31103
  }
30615
31104
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
30616
31105
  const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
@@ -30630,7 +31119,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
30630
31119
  new Array(unsignedTx.inputsLength).fill(fundingTxOut.amount)
30631
31120
  );
30632
31121
  const merkleRoot = new Uint8Array();
30633
- const tweakedKey = (0, import_utils22.taprootTweakPrivKey)(key, merkleRoot);
31122
+ const tweakedKey = (0, import_utils21.taprootTweakPrivKey)(key, merkleRoot);
30634
31123
  if (!tweakedKey)
30635
31124
  throw new Error("Invalid private key for taproot tweaking");
30636
31125
  const signature = import_secp256k114.schnorr.sign(sighash, tweakedKey);
@@ -30730,7 +31219,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
30730
31219
  });
30731
31220
  }
30732
31221
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
30733
- const txHex = (0, import_utils21.bytesToHex)(signedTx.extract());
31222
+ const txHex = (0, import_utils20.bytesToHex)(signedTx.extract());
30734
31223
  await this.broadcastTx(txHex);
30735
31224
  const randomKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
30736
31225
  const randomPubKey = import_secp256k114.secp256k1.getPublicKey(randomKey);
@@ -30747,18 +31236,18 @@ var BitcoinFaucet = class _BitcoinFaucet {
30747
31236
  };
30748
31237
 
30749
31238
  // src/types/sdk-types.ts
30750
- var import_utils23 = require("@noble/curves/abstract/utils");
31239
+ var import_utils22 = require("@noble/curves/utils");
30751
31240
  function mapTreeNodeToWalletLeaf(proto) {
30752
31241
  return {
30753
31242
  id: proto.id,
30754
31243
  treeId: proto.treeId,
30755
31244
  value: proto.value,
30756
31245
  parentNodeId: proto.parentNodeId,
30757
- nodeTx: (0, import_utils23.bytesToHex)(proto.nodeTx),
30758
- refundTx: (0, import_utils23.bytesToHex)(proto.refundTx),
31246
+ nodeTx: (0, import_utils22.bytesToHex)(proto.nodeTx),
31247
+ refundTx: (0, import_utils22.bytesToHex)(proto.refundTx),
30759
31248
  vout: proto.vout,
30760
- verifyingPublicKey: (0, import_utils23.bytesToHex)(proto.verifyingPublicKey),
30761
- ownerIdentityPublicKey: (0, import_utils23.bytesToHex)(proto.ownerIdentityPublicKey),
31249
+ verifyingPublicKey: (0, import_utils22.bytesToHex)(proto.verifyingPublicKey),
31250
+ ownerIdentityPublicKey: (0, import_utils22.bytesToHex)(proto.ownerIdentityPublicKey),
30762
31251
  signingKeyshare: proto.signingKeyshare,
30763
31252
  status: proto.status,
30764
31253
  network: Network[proto.network]
@@ -30767,14 +31256,14 @@ function mapTreeNodeToWalletLeaf(proto) {
30767
31256
  function mapTransferLeafToWalletTransferLeaf(proto) {
30768
31257
  return {
30769
31258
  leaf: proto.leaf ? mapTreeNodeToWalletLeaf(proto.leaf) : void 0,
30770
- secretCipher: (0, import_utils23.bytesToHex)(proto.secretCipher),
30771
- signature: (0, import_utils23.bytesToHex)(proto.signature),
30772
- intermediateRefundTx: (0, import_utils23.bytesToHex)(proto.intermediateRefundTx)
31259
+ secretCipher: (0, import_utils22.bytesToHex)(proto.secretCipher),
31260
+ signature: (0, import_utils22.bytesToHex)(proto.signature),
31261
+ intermediateRefundTx: (0, import_utils22.bytesToHex)(proto.intermediateRefundTx)
30773
31262
  };
30774
31263
  }
30775
31264
  function mapTransferToWalletTransfer(proto, identityPublicKey, userRequest) {
30776
- const receiverIdentityPublicKey = (0, import_utils23.bytesToHex)(proto.receiverIdentityPublicKey);
30777
- const senderIdentityPublicKey = (0, import_utils23.bytesToHex)(proto.senderIdentityPublicKey);
31265
+ const receiverIdentityPublicKey = (0, import_utils22.bytesToHex)(proto.receiverIdentityPublicKey);
31266
+ const senderIdentityPublicKey = (0, import_utils22.bytesToHex)(proto.senderIdentityPublicKey);
30778
31267
  return {
30779
31268
  id: proto.id,
30780
31269
  senderIdentityPublicKey,
@@ -30964,7 +31453,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30964
31453
  try {
30965
31454
  if (event?.$case === "transfer" && event.transfer.transfer && event.transfer.transfer.type !== 40 /* COUNTER_SWAP */) {
30966
31455
  const { senderIdentityPublicKey, receiverIdentityPublicKey } = event.transfer.transfer;
30967
- if (event.transfer.transfer && !(0, import_utils24.equalBytes)(senderIdentityPublicKey, receiverIdentityPublicKey)) {
31456
+ if (event.transfer.transfer && !(0, import_utils23.equalBytes)(senderIdentityPublicKey, receiverIdentityPublicKey)) {
30968
31457
  await this.claimTransfer({
30969
31458
  transfer: event.transfer.transfer,
30970
31459
  emit: true,
@@ -31129,10 +31618,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31129
31618
  leavesToIgnore.add(nodeId);
31130
31619
  continue;
31131
31620
  }
31132
- if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !(0, import_utils24.equalBytes)(
31621
+ if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !(0, import_utils23.equalBytes)(
31133
31622
  leaf.signingKeyshare.publicKey,
31134
31623
  operatorLeaf.signingKeyshare.publicKey
31135
- ) || !(0, import_utils24.equalBytes)(leaf.nodeTx, operatorLeaf.nodeTx)) {
31624
+ ) || !(0, import_utils23.equalBytes)(leaf.nodeTx, operatorLeaf.nodeTx)) {
31136
31625
  leavesToIgnore.add(nodeId);
31137
31626
  }
31138
31627
  }
@@ -31183,7 +31672,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31183
31672
  });
31184
31673
  }
31185
31674
  verifyKey(pubkey1, pubkey2, verifyingKey) {
31186
- return (0, import_utils24.equalBytes)(addPublicKeys(pubkey1, pubkey2), verifyingKey);
31675
+ return (0, import_utils23.equalBytes)(addPublicKeys(pubkey1, pubkey2), verifyingKey);
31187
31676
  }
31188
31677
  async selectLeaves(targetAmounts) {
31189
31678
  if (targetAmounts.length === 0) {
@@ -31341,7 +31830,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31341
31830
  * @returns {Promise<string>} The identity public key as a hex string.
31342
31831
  */
31343
31832
  async getIdentityPublicKey() {
31344
- return (0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey());
31833
+ return (0, import_utils23.bytesToHex)(await this.config.signer.getIdentityPublicKey());
31345
31834
  }
31346
31835
  /**
31347
31836
  * Gets the Spark address of the wallet.
@@ -31351,7 +31840,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31351
31840
  async getSparkAddress() {
31352
31841
  if (!this.sparkAddress) {
31353
31842
  this.sparkAddress = encodeSparkAddress({
31354
- identityPublicKey: (0, import_utils24.bytesToHex)(
31843
+ identityPublicKey: (0, import_utils23.bytesToHex)(
31355
31844
  await this.config.signer.getIdentityPublicKey()
31356
31845
  ),
31357
31846
  network: this.config.getNetworkType()
@@ -31414,7 +31903,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31414
31903
  $case: "tokensPayment",
31415
31904
  tokensPayment: {
31416
31905
  tokenIdentifier: decodedTokenIdentifier ?? void 0,
31417
- amount: amount ? (0, import_utils24.numberToVarBytesBE)(amount) : void 0
31906
+ amount: amount ? (0, import_utils23.numberToVarBytesBE)(amount) : void 0
31418
31907
  }
31419
31908
  };
31420
31909
  const invoiceFields = {
@@ -31422,7 +31911,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31422
31911
  id: (0, import_uuidv75.uuidv7obj)().bytes,
31423
31912
  paymentType: protoPayment,
31424
31913
  memo: memo ?? void 0,
31425
- senderPublicKey: senderPublicKey ? (0, import_utils24.hexToBytes)(senderPublicKey) : void 0,
31914
+ senderPublicKey: senderPublicKey ? (0, import_utils23.hexToBytes)(senderPublicKey) : void 0,
31426
31915
  expiryTime: expiryTime ?? void 0
31427
31916
  };
31428
31917
  validateSparkInvoiceFields(invoiceFields);
@@ -31435,7 +31924,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31435
31924
  const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
31436
31925
  return encodeSparkAddressWithSignature(
31437
31926
  {
31438
- identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
31927
+ identityPublicKey: (0, import_utils23.bytesToHex)(identityPublicKey),
31439
31928
  network: this.config.getNetworkType(),
31440
31929
  sparkInvoiceFields: invoiceFields
31441
31930
  },
@@ -31481,7 +31970,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31481
31970
  mnemonic = mnemonicOrSeed;
31482
31971
  seed = await this.config.signer.mnemonicToSeed(mnemonicOrSeed);
31483
31972
  } else {
31484
- seed = (0, import_utils24.hexToBytes)(mnemonicOrSeed);
31973
+ seed = (0, import_utils23.hexToBytes)(mnemonicOrSeed);
31485
31974
  }
31486
31975
  }
31487
31976
  await this.initWalletFromSeed(seed, accountNumber);
@@ -31503,7 +31992,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31503
31992
  });
31504
31993
  }
31505
31994
  this.sparkAddress = encodeSparkAddress({
31506
- identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
31995
+ identityPublicKey: (0, import_utils23.bytesToHex)(identityPublicKey),
31507
31996
  network: this.config.getNetworkType()
31508
31997
  });
31509
31998
  return this.sparkAddress;
@@ -31623,7 +32112,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31623
32112
  directFromCpfpSignatureMap
31624
32113
  } = await this.transferService.startSwapSignRefund(
31625
32114
  leafKeyTweaks,
31626
- (0, import_utils24.hexToBytes)(this.config.getSspIdentityPublicKey()),
32115
+ (0, import_utils23.hexToBytes)(this.config.getSspIdentityPublicKey()),
31627
32116
  new Date(Date.now() + 2 * 60 * 1e3)
31628
32117
  );
31629
32118
  try {
@@ -31683,18 +32172,18 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31683
32172
  const userLeaves = [];
31684
32173
  userLeaves.push({
31685
32174
  leaf_id: transfer.leaves[0].leaf.id,
31686
- raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32175
+ raw_unsigned_refund_transaction: (0, import_utils23.bytesToHex)(
31687
32176
  transfer.leaves[0].intermediateRefundTx
31688
32177
  ),
31689
- direct_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32178
+ direct_raw_unsigned_refund_transaction: (0, import_utils23.bytesToHex)(
31690
32179
  transfer.leaves[0].intermediateDirectRefundTx
31691
32180
  ),
31692
- direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32181
+ direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils23.bytesToHex)(
31693
32182
  transfer.leaves[0].intermediateDirectFromCpfpRefundTx
31694
32183
  ),
31695
- adaptor_added_signature: (0, import_utils24.bytesToHex)(cpfpAdaptorSignature),
31696
- direct_adaptor_added_signature: (0, import_utils24.bytesToHex)(directAdaptorSignature),
31697
- direct_from_cpfp_adaptor_added_signature: (0, import_utils24.bytesToHex)(
32184
+ adaptor_added_signature: (0, import_utils23.bytesToHex)(cpfpAdaptorSignature),
32185
+ direct_adaptor_added_signature: (0, import_utils23.bytesToHex)(directAdaptorSignature),
32186
+ direct_from_cpfp_adaptor_added_signature: (0, import_utils23.bytesToHex)(
31698
32187
  directFromCpfpAdaptorSignature
31699
32188
  )
31700
32189
  });
@@ -31747,24 +32236,24 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31747
32236
  }
31748
32237
  userLeaves.push({
31749
32238
  leaf_id: leaf.leaf.id,
31750
- raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32239
+ raw_unsigned_refund_transaction: (0, import_utils23.bytesToHex)(
31751
32240
  leaf.intermediateRefundTx
31752
32241
  ),
31753
- direct_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32242
+ direct_raw_unsigned_refund_transaction: (0, import_utils23.bytesToHex)(
31754
32243
  leaf.intermediateDirectRefundTx
31755
32244
  ),
31756
- direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
32245
+ direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils23.bytesToHex)(
31757
32246
  leaf.intermediateDirectFromCpfpRefundTx
31758
32247
  ),
31759
- adaptor_added_signature: (0, import_utils24.bytesToHex)(cpfpSignature),
31760
- direct_adaptor_added_signature: (0, import_utils24.bytesToHex)(directSignature),
31761
- direct_from_cpfp_adaptor_added_signature: (0, import_utils24.bytesToHex)(
32248
+ adaptor_added_signature: (0, import_utils23.bytesToHex)(cpfpSignature),
32249
+ direct_adaptor_added_signature: (0, import_utils23.bytesToHex)(directSignature),
32250
+ direct_from_cpfp_adaptor_added_signature: (0, import_utils23.bytesToHex)(
31762
32251
  directFromCpfpSignature
31763
32252
  )
31764
32253
  });
31765
32254
  }
31766
32255
  const sspClient = this.getSspClient();
31767
- const cpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
32256
+ const cpfpAdaptorPubkey = (0, import_utils23.bytesToHex)(
31768
32257
  import_secp256k115.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
31769
32258
  );
31770
32259
  if (!cpfpAdaptorPubkey) {
@@ -31772,13 +32261,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31772
32261
  }
31773
32262
  let directAdaptorPubkey;
31774
32263
  if (directAdaptorPrivateKey.length > 0) {
31775
- directAdaptorPubkey = (0, import_utils24.bytesToHex)(
32264
+ directAdaptorPubkey = (0, import_utils23.bytesToHex)(
31776
32265
  import_secp256k115.secp256k1.getPublicKey(directAdaptorPrivateKey)
31777
32266
  );
31778
32267
  }
31779
32268
  let directFromCpfpAdaptorPubkey;
31780
32269
  if (directFromCpfpAdaptorPrivateKey.length > 0) {
31781
- directFromCpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
32270
+ directFromCpfpAdaptorPubkey = (0, import_utils23.bytesToHex)(
31782
32271
  import_secp256k115.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
31783
32272
  );
31784
32273
  }
@@ -31838,7 +32327,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31838
32327
  throw new Error(`Leaf not found for node ${nodeId}`);
31839
32328
  }
31840
32329
  const cpfpNodeTx = getTxFromRawTxBytes(node.nodeTx);
31841
- const cpfpRefundTxBytes = (0, import_utils24.hexToBytes)(leaf.rawUnsignedRefundTransaction);
32330
+ const cpfpRefundTxBytes = (0, import_utils23.hexToBytes)(leaf.rawUnsignedRefundTransaction);
31842
32331
  const cpfpRefundTx = getTxFromRawTxBytes(cpfpRefundTxBytes);
31843
32332
  const cpfpSighash = getSigHashFromTx(
31844
32333
  cpfpRefundTx,
@@ -31847,7 +32336,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31847
32336
  );
31848
32337
  const nodePublicKey = node.verifyingPublicKey;
31849
32338
  const taprootKey = computeTaprootKeyNoScript(nodePublicKey.slice(1));
31850
- const cpfpAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
32339
+ const cpfpAdaptorSignatureBytes = (0, import_utils23.hexToBytes)(
31851
32340
  leaf.adaptorSignedSignature
31852
32341
  );
31853
32342
  applyAdaptorToSignature(
@@ -31858,7 +32347,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31858
32347
  );
31859
32348
  if (leaf.directRawUnsignedRefundTransaction) {
31860
32349
  const directNodeTx = getTxFromRawTxBytes(node.directTx);
31861
- const directRefundTxBytes = (0, import_utils24.hexToBytes)(
32350
+ const directRefundTxBytes = (0, import_utils23.hexToBytes)(
31862
32351
  leaf.directRawUnsignedRefundTransaction
31863
32352
  );
31864
32353
  const directRefundTx = getTxFromRawTxBytes(directRefundTxBytes);
@@ -31872,7 +32361,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31872
32361
  `Direct adaptor signed signature missing for node ${nodeId}`
31873
32362
  );
31874
32363
  }
31875
- const directAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
32364
+ const directAdaptorSignatureBytes = (0, import_utils23.hexToBytes)(
31876
32365
  leaf.directAdaptorSignedSignature
31877
32366
  );
31878
32367
  applyAdaptorToSignature(
@@ -31883,7 +32372,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31883
32372
  );
31884
32373
  }
31885
32374
  if (leaf.directFromCpfpRawUnsignedRefundTransaction) {
31886
- const directFromCpfpRefundTxBytes = (0, import_utils24.hexToBytes)(
32375
+ const directFromCpfpRefundTxBytes = (0, import_utils23.hexToBytes)(
31887
32376
  leaf.directFromCpfpRawUnsignedRefundTransaction
31888
32377
  );
31889
32378
  const directFromCpfpRefundTx = getTxFromRawTxBytes(
@@ -31899,7 +32388,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31899
32388
  `Direct adaptor signed signature missing for node ${nodeId}`
31900
32389
  );
31901
32390
  }
31902
- const directFromCpfpAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
32391
+ const directFromCpfpAdaptorSignatureBytes = (0, import_utils23.hexToBytes)(
31903
32392
  leaf.directFromCpfpAdaptorSignedSignature
31904
32393
  );
31905
32394
  applyAdaptorToSignature(
@@ -31918,9 +32407,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31918
32407
  directFromCpfpSignatureMap
31919
32408
  );
31920
32409
  const completeResponse = await sspClient.completeLeaveSwap({
31921
- adaptorSecretKey: (0, import_utils24.bytesToHex)(cpfpAdaptorPrivateKey),
31922
- directAdaptorSecretKey: (0, import_utils24.bytesToHex)(directAdaptorPrivateKey),
31923
- directFromCpfpAdaptorSecretKey: (0, import_utils24.bytesToHex)(
32410
+ adaptorSecretKey: (0, import_utils23.bytesToHex)(cpfpAdaptorPrivateKey),
32411
+ directAdaptorSecretKey: (0, import_utils23.bytesToHex)(directAdaptorPrivateKey),
32412
+ directFromCpfpAdaptorSecretKey: (0, import_utils23.bytesToHex)(
31924
32413
  directFromCpfpAdaptorPrivateKey
31925
32414
  ),
31926
32415
  userOutboundTransferExternalId: transfer.id,
@@ -31951,7 +32440,6 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31951
32440
  message: e.message,
31952
32441
  stack: e.stack
31953
32442
  });
31954
- await this.cancelAllSenderInitiatedTransfers();
31955
32443
  throw new Error(`Failed to request leaves swap: ${e}`);
31956
32444
  }
31957
32445
  }
@@ -32015,12 +32503,12 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32015
32503
  let tokenMetadataMap = /* @__PURE__ */ new Map();
32016
32504
  for (const [tokenIdentifier, metadata] of this.tokenMetadata) {
32017
32505
  tokenMetadataMap.set(tokenIdentifier, {
32018
- tokenPublicKey: (0, import_utils24.bytesToHex)(metadata.issuerPublicKey),
32506
+ tokenPublicKey: (0, import_utils23.bytesToHex)(metadata.issuerPublicKey),
32019
32507
  rawTokenIdentifier: metadata.tokenIdentifier,
32020
32508
  tokenName: metadata.tokenName,
32021
32509
  tokenTicker: metadata.tokenTicker,
32022
32510
  decimals: metadata.decimals,
32023
- maxSupply: (0, import_utils24.bytesToNumberBE)(metadata.maxSupply)
32511
+ maxSupply: (0, import_utils23.bytesToNumberBE)(metadata.maxSupply)
32024
32512
  });
32025
32513
  }
32026
32514
  return tokenMetadataMap;
@@ -32055,7 +32543,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32055
32543
  * @returns {Promise<string>} A Bitcoin address for depositing funds
32056
32544
  */
32057
32545
  async getSingleUseDepositAddress() {
32058
- return await this.generateDepositAddress(false);
32546
+ return await this.generateDepositAddress();
32059
32547
  }
32060
32548
  /**
32061
32549
  * Generates a new static deposit address for receiving bitcoin funds.
@@ -32064,43 +32552,32 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32064
32552
  * @returns {Promise<string>} A Bitcoin address for depositing funds
32065
32553
  */
32066
32554
  async getStaticDepositAddress() {
32067
- try {
32068
- return await this.generateDepositAddress(true);
32069
- } catch (error) {
32070
- if (error.message?.includes("static deposit address already exists")) {
32071
- const existingAddresses = await this.queryStaticDepositAddresses();
32072
- if (existingAddresses.length > 0 && existingAddresses[0]) {
32073
- return existingAddresses[0];
32074
- } else {
32075
- throw error;
32076
- }
32077
- } else {
32078
- throw error;
32079
- }
32555
+ const signingPubkey = await this.config.signer.getStaticDepositSigningKey(0);
32556
+ const address2 = await this.depositService.generateStaticDepositAddress({
32557
+ signingPubkey
32558
+ });
32559
+ if (!address2.depositAddress) {
32560
+ throw new RPCError("Failed to generate static deposit address", {
32561
+ method: "generateStaticDepositAddress",
32562
+ params: { signingPubkey }
32563
+ });
32080
32564
  }
32565
+ return address2.depositAddress.address;
32081
32566
  }
32082
32567
  /**
32083
32568
  * Generates a deposit address for receiving funds.
32084
- *
32085
- * @param {boolean} static - Whether the address is static or single use
32086
32569
  * @returns {Promise<string>} A deposit address
32087
32570
  * @private
32088
32571
  */
32089
- async generateDepositAddress(isStatic) {
32572
+ async generateDepositAddress() {
32090
32573
  const leafId = (0, import_uuidv75.uuidv7)();
32091
- let signingPubkey;
32092
- if (isStatic) {
32093
- signingPubkey = await this.config.signer.getStaticDepositSigningKey(0);
32094
- } else {
32095
- signingPubkey = await this.config.signer.getPublicKeyFromDerivation({
32096
- type: "leaf" /* LEAF */,
32097
- path: leafId
32098
- });
32099
- }
32574
+ const signingPubkey = await this.config.signer.getPublicKeyFromDerivation({
32575
+ type: "leaf" /* LEAF */,
32576
+ path: leafId
32577
+ });
32100
32578
  const address2 = await this.depositService.generateDepositAddress({
32101
32579
  signingPubkey,
32102
- leafId,
32103
- isStatic
32580
+ leafId
32104
32581
  });
32105
32582
  if (!address2.depositAddress) {
32106
32583
  throw new RPCError("Failed to generate deposit address", {
@@ -32127,7 +32604,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32127
32604
  * @param offset - Pagination offset (default 0).
32128
32605
  * @returns {Promise<{ txid: string, vout: number }[]>} List of confirmed UTXOs.
32129
32606
  */
32130
- async getUtxosForDepositAddress(depositAddress, limit = 100, offset = 0) {
32607
+ async getUtxosForDepositAddress(depositAddress, limit = 100, offset = 0, excludeClaimed = false) {
32131
32608
  if (!depositAddress) {
32132
32609
  throw new ValidationError("Deposit address cannot be empty", {
32133
32610
  field: "depositAddress"
@@ -32141,10 +32618,11 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32141
32618
  address: depositAddress,
32142
32619
  network: NetworkToProto[this.config.getNetwork()],
32143
32620
  limit,
32144
- offset
32621
+ offset,
32622
+ excludeClaimed
32145
32623
  });
32146
32624
  return response.utxos.map((utxo) => ({
32147
- txid: (0, import_utils24.bytesToHex)(utxo.txid),
32625
+ txid: (0, import_utils23.bytesToHex)(utxo.txid),
32148
32626
  vout: utxo.vout
32149
32627
  })) ?? [];
32150
32628
  } catch (error) {
@@ -32214,7 +32692,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32214
32692
  if (network === BitcoinNetwork_default.FUTURE_VALUE) {
32215
32693
  network = BitcoinNetwork_default.REGTEST;
32216
32694
  }
32217
- const depositSecretKey = (0, import_utils24.bytesToHex)(
32695
+ const depositSecretKey = (0, import_utils23.bytesToHex)(
32218
32696
  await this.config.signer.getStaticDepositSecretKey(0)
32219
32697
  );
32220
32698
  const message = await this.getStaticDepositSigningPayload(
@@ -32227,7 +32705,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32227
32705
  );
32228
32706
  const hashBuffer = (0, import_sha212.sha256)(message);
32229
32707
  const signatureBytes = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
32230
- const signature = (0, import_utils24.bytesToHex)(signatureBytes);
32708
+ const signature = (0, import_utils23.bytesToHex)(signatureBytes);
32231
32709
  const response = await this.sspClient.claimStaticDeposit({
32232
32710
  transactionId,
32233
32711
  outputIndex,
@@ -32379,7 +32857,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32379
32857
  networkJSON.toLowerCase(),
32380
32858
  2 /* Refund */,
32381
32859
  creditAmountSats,
32382
- (0, import_utils24.bytesToHex)(spendTxSighash)
32860
+ (0, import_utils23.bytesToHex)(spendTxSighash)
32383
32861
  );
32384
32862
  const hashBuffer = (0, import_sha212.sha256)(message);
32385
32863
  const swapResponseUserSignature = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
@@ -32388,7 +32866,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32388
32866
  );
32389
32867
  const swapResponse = await sparkClient.initiate_static_deposit_utxo_refund({
32390
32868
  onChainUtxo: {
32391
- txid: (0, import_utils24.hexToBytes)(depositTransactionId),
32869
+ txid: (0, import_utils23.hexToBytes)(depositTransactionId),
32392
32870
  vout: outputIndex,
32393
32871
  network: networkType
32394
32872
  },
@@ -32424,6 +32902,64 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32424
32902
  });
32425
32903
  return tx.hex;
32426
32904
  }
32905
+ /**
32906
+ * Refunds a static deposit and broadcasts the transaction to the network.
32907
+ *
32908
+ * @param {Object} params - The refund parameters
32909
+ * @param {string} params.depositTransactionId - The ID of the transaction
32910
+ * @param {number} [params.outputIndex] - The index of the output
32911
+ * @param {string} params.destinationAddress - The destination address
32912
+ * @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
32913
+ * @returns {Promise<string>} The transaction ID
32914
+ */
32915
+ async refundAndBroadcastStaticDeposit({
32916
+ depositTransactionId,
32917
+ outputIndex,
32918
+ destinationAddress,
32919
+ satsPerVbyteFee
32920
+ }) {
32921
+ const txHex = await this.refundStaticDeposit({
32922
+ depositTransactionId,
32923
+ outputIndex,
32924
+ destinationAddress,
32925
+ satsPerVbyteFee
32926
+ });
32927
+ return await this.broadcastTx(txHex);
32928
+ }
32929
+ /**
32930
+ * Broadcasts a transaction to the network.
32931
+ *
32932
+ * @param {string} txHex - The hex of the transaction
32933
+ * @returns {Promise<string>} The transaction ID
32934
+ */
32935
+ async broadcastTx(txHex) {
32936
+ if (!txHex) {
32937
+ throw new ValidationError("Transaction hex cannot be empty", {
32938
+ field: "txHex"
32939
+ });
32940
+ }
32941
+ const { fetch, Headers: Headers3 } = getFetch();
32942
+ const baseUrl = this.config.getElectrsUrl();
32943
+ const headers = new Headers3();
32944
+ if (this.config.getNetwork() === 4 /* LOCAL */) {
32945
+ const localFaucet = BitcoinFaucet.getInstance();
32946
+ const response = await localFaucet.broadcastTx(txHex);
32947
+ return response;
32948
+ } else {
32949
+ if (this.config.getNetwork() === 3 /* REGTEST */) {
32950
+ const auth = btoa(
32951
+ `${ELECTRS_CREDENTIALS.username}:${ELECTRS_CREDENTIALS.password}`
32952
+ );
32953
+ headers.set("Authorization", `Basic ${auth}`);
32954
+ }
32955
+ const response = await fetch(`${baseUrl}/tx`, {
32956
+ method: "POST",
32957
+ body: txHex,
32958
+ headers
32959
+ });
32960
+ return response.text();
32961
+ }
32962
+ }
32427
32963
  async getStaticDepositSigningPayload(transactionID, outputIndex, network, requestType, creditAmountSats, sspSignature) {
32428
32964
  const encoder = new TextEncoder();
32429
32965
  const parts = [];
@@ -32457,7 +32993,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32457
32993
  creditAmountView.setUint32(0, lowerHalf, true);
32458
32994
  creditAmountView.setUint32(4, upperHalf, true);
32459
32995
  parts.push(new Uint8Array(creditAmountBuffer));
32460
- parts.push((0, import_utils24.hexToBytes)(sspSignature));
32996
+ parts.push((0, import_utils23.hexToBytes)(sspSignature));
32461
32997
  const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
32462
32998
  const payload = new Uint8Array(totalLength);
32463
32999
  let offset = 0;
@@ -32862,9 +33398,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32862
33398
  });
32863
33399
  }
32864
33400
  const signerIdentityPublicKey = await this.config.signer.getIdentityPublicKey();
32865
- const isSelfTransfer = (0, import_utils24.equalBytes)(
33401
+ const isSelfTransfer = (0, import_utils23.equalBytes)(
32866
33402
  signerIdentityPublicKey,
32867
- (0, import_utils24.hexToBytes)(receiverAddress.identityPublicKey)
33403
+ (0, import_utils23.hexToBytes)(receiverAddress.identityPublicKey)
32868
33404
  );
32869
33405
  return await this.withLeaves(async () => {
32870
33406
  let leavesToSend = (await this.selectLeaves([amountSats])).get(
@@ -32886,7 +33422,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32886
33422
  );
32887
33423
  const transfer = await this.transferService.sendTransferWithKeyTweaks(
32888
33424
  leafKeyTweaks,
32889
- (0, import_utils24.hexToBytes)(receiverAddress.identityPublicKey)
33425
+ (0, import_utils23.hexToBytes)(receiverAddress.identityPublicKey)
32890
33426
  );
32891
33427
  const leavesToRemove = new Set(leavesToSend.map((leaf) => leaf.id));
32892
33428
  this.leaves = this.leaves.filter((leaf) => !leavesToRemove.has(leaf.id));
@@ -32902,7 +33438,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32902
33438
  }
32903
33439
  return mapTransferToWalletTransfer(
32904
33440
  transfer,
32905
- (0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey())
33441
+ (0, import_utils23.bytesToHex)(await this.config.signer.getIdentityPublicKey())
32906
33442
  );
32907
33443
  });
32908
33444
  }
@@ -33162,24 +33698,6 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33162
33698
  (result) => result.status === "fulfilled" && result.value !== null
33163
33699
  ).map((result) => result.value);
33164
33700
  }
33165
- /**
33166
- * Cancels all sender-initiated transfers.
33167
- *
33168
- * @returns {Promise<void>}
33169
- * @private
33170
- */
33171
- async cancelAllSenderInitiatedTransfers() {
33172
- for (const operator of Object.values(this.config.getSigningOperators())) {
33173
- const transfers = await this.transferService.queryPendingTransfersBySender(
33174
- operator.address
33175
- );
33176
- for (const transfer of transfers.transfers) {
33177
- if (transfer.status === 0 /* TRANSFER_STATUS_SENDER_INITIATED */) {
33178
- await this.transferService.cancelTransfer(transfer, operator.address);
33179
- }
33180
- }
33181
- }
33182
- }
33183
33701
  // ***** Lightning Flow *****
33184
33702
  /**
33185
33703
  * Creates a Lightning invoice for receiving payments.
@@ -33258,7 +33776,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33258
33776
  const invoice2 = await sspClient.requestLightningReceive({
33259
33777
  amountSats: amountSats2,
33260
33778
  network: bitcoinNetwork,
33261
- paymentHash: (0, import_utils24.bytesToHex)(paymentHash),
33779
+ paymentHash: (0, import_utils23.bytesToHex)(paymentHash),
33262
33780
  expirySecs: expirySeconds,
33263
33781
  memo: memo2,
33264
33782
  includeSparkAddress,
@@ -33367,7 +33885,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33367
33885
  const sparkFallbackAddress = decodedInvoice.fallbackAddress;
33368
33886
  const paymentHash = decodedInvoice.paymentHash;
33369
33887
  if (preferSpark) {
33370
- if (sparkFallbackAddress === void 0 || isValidSparkFallback((0, import_utils24.hexToBytes)(sparkFallbackAddress)) === false) {
33888
+ if (sparkFallbackAddress === void 0 || isValidSparkFallback((0, import_utils23.hexToBytes)(sparkFallbackAddress)) === false) {
33371
33889
  console.warn(
33372
33890
  "No valid spark address found in invoice. Defaulting to lightning."
33373
33891
  );
@@ -33421,10 +33939,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33421
33939
  );
33422
33940
  const swapResponse = await this.lightningService.swapNodesForPreimage({
33423
33941
  leaves: leavesToSend,
33424
- receiverIdentityPubkey: (0, import_utils24.hexToBytes)(
33942
+ receiverIdentityPubkey: (0, import_utils23.hexToBytes)(
33425
33943
  this.config.getSspIdentityPublicKey()
33426
33944
  ),
33427
- paymentHash: (0, import_utils24.hexToBytes)(paymentHash),
33945
+ paymentHash: (0, import_utils23.hexToBytes)(paymentHash),
33428
33946
  isInboundPayment: false,
33429
33947
  invoiceString: invoice,
33430
33948
  feeSats: feeEstimate,
@@ -33542,7 +34060,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33542
34060
  });
33543
34061
  await this.syncTokenOutputs();
33544
34062
  const bech32mTokenIdentifier = encodeBech32mTokenIdentifier({
33545
- tokenIdentifier: (0, import_utils24.hexToBytes)(firstTokenIdentifierHexSeen),
34063
+ tokenIdentifier: (0, import_utils23.hexToBytes)(firstTokenIdentifierHexSeen),
33546
34064
  network: this.config.getNetworkType()
33547
34065
  });
33548
34066
  const receiverOutputs = decoded.map((d) => ({
@@ -33730,11 +34248,11 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33730
34248
  const connectorOutputs = [];
33731
34249
  for (let i = 0; i < connectorTx.outputsLength - 1; i++) {
33732
34250
  connectorOutputs.push({
33733
- txid: (0, import_utils24.hexToBytes)(connectorTxId),
34251
+ txid: (0, import_utils23.hexToBytes)(connectorTxId),
33734
34252
  index: i
33735
34253
  });
33736
34254
  }
33737
- const sspPubIdentityKey = (0, import_utils24.hexToBytes)(this.config.getSspIdentityPublicKey());
34255
+ const sspPubIdentityKey = (0, import_utils23.hexToBytes)(this.config.getSspIdentityPublicKey());
33738
34256
  const transfer = await this.coopExitService.getConnectorRefundSignatures({
33739
34257
  leaves: leafKeyTweaks,
33740
34258
  exitTxId: coopExitTxId,
@@ -33788,7 +34306,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33788
34306
  return transfers?.[0];
33789
34307
  }
33790
34308
  async constructTransfersWithUserRequest(transfers) {
33791
- const identityPublicKey = (0, import_utils24.bytesToHex)(
34309
+ const identityPublicKey = (0, import_utils23.bytesToHex)(
33792
34310
  await this.config.signer.getIdentityPublicKey()
33793
34311
  );
33794
34312
  const userRequests = await this.sspClient?.getTransfers(
@@ -34032,7 +34550,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34032
34550
  hash,
34033
34551
  compact
34034
34552
  );
34035
- return (0, import_utils24.bytesToHex)(signature);
34553
+ return (0, import_utils23.bytesToHex)(signature);
34036
34554
  }
34037
34555
  /**
34038
34556
  * Validates a message with the identity key.
@@ -34044,7 +34562,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34044
34562
  async validateMessageWithIdentityKey(message, signature) {
34045
34563
  const hash = (0, import_sha212.sha256)(message);
34046
34564
  if (typeof signature === "string") {
34047
- signature = (0, import_utils24.hexToBytes)(signature);
34565
+ signature = (0, import_utils23.hexToBytes)(signature);
34048
34566
  }
34049
34567
  return this.config.signer.validateMessageWithIdentityKey(hash, signature);
34050
34568
  }
@@ -34057,7 +34575,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34057
34575
  */
34058
34576
  async signTransaction(txHex, keyType = "auto-detect") {
34059
34577
  try {
34060
- const tx = import_btc_signer6.Transaction.fromRaw((0, import_utils24.hexToBytes)(txHex));
34578
+ const tx = import_btc_signer6.Transaction.fromRaw((0, import_utils23.hexToBytes)(txHex));
34061
34579
  let publicKey;
34062
34580
  switch (keyType.toLowerCase()) {
34063
34581
  case "identity":
@@ -34090,7 +34608,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34090
34608
  publicKey,
34091
34609
  this.config.getNetwork()
34092
34610
  );
34093
- if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(identityScript)) {
34611
+ if ((0, import_utils23.bytesToHex)(script) === (0, import_utils23.bytesToHex)(identityScript)) {
34094
34612
  try {
34095
34613
  this.config.signer.signTransactionIndex(tx, i, publicKey);
34096
34614
  inputsSigned++;
@@ -34134,13 +34652,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34134
34652
  depositPubKey,
34135
34653
  this.config.getNetwork()
34136
34654
  );
34137
- if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(identityScript)) {
34655
+ if ((0, import_utils23.bytesToHex)(script) === (0, import_utils23.bytesToHex)(identityScript)) {
34138
34656
  return {
34139
34657
  publicKey: identityPubKey,
34140
34658
  keyType: "identity"
34141
34659
  };
34142
34660
  }
34143
- if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(depositScript)) {
34661
+ if ((0, import_utils23.bytesToHex)(script) === (0, import_utils23.bytesToHex)(depositScript)) {
34144
34662
  return {
34145
34663
  publicKey: depositPubKey,
34146
34664
  keyType: "deposit"
@@ -34657,7 +35175,7 @@ async function isTxBroadcast(txid, baseUrl, network) {
34657
35175
  }
34658
35176
 
34659
35177
  // src/utils/unilateral-exit.ts
34660
- var import_utils25 = require("@noble/curves/abstract/utils");
35178
+ var import_utils24 = require("@noble/curves/utils");
34661
35179
  var import_legacy = require("@noble/hashes/legacy");
34662
35180
  var import_sha213 = require("@noble/hashes/sha2");
34663
35181
  var btc4 = __toESM(require("@scure/btc-signer"), 1);
@@ -34672,7 +35190,7 @@ function isEphemeralAnchorOutput(script, amount) {
34672
35190
  }
34673
35191
  async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network) {
34674
35192
  const result = [];
34675
- const nodes = nodeHexStrings.map((hex) => TreeNode.decode((0, import_utils25.hexToBytes)(hex)));
35193
+ const nodes = nodeHexStrings.map((hex) => TreeNode.decode((0, import_utils24.hexToBytes)(hex)));
34676
35194
  const nodeMap = /* @__PURE__ */ new Map();
34677
35195
  for (const node of nodes) {
34678
35196
  nodeMap.set(node.id, node);
@@ -34728,10 +35246,10 @@ async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network)
34728
35246
  }
34729
35247
  }
34730
35248
  for (const chainNode of chain) {
34731
- const nodeTx = (0, import_utils25.bytesToHex)(chainNode.nodeTx);
35249
+ const nodeTx = (0, import_utils24.bytesToHex)(chainNode.nodeTx);
34732
35250
  transactions.push(nodeTx);
34733
35251
  if (chainNode.id === node.id) {
34734
- const refundTx = (0, import_utils25.bytesToHex)(chainNode.refundTx);
35252
+ const refundTx = (0, import_utils24.bytesToHex)(chainNode.refundTx);
34735
35253
  transactions.push(refundTx);
34736
35254
  }
34737
35255
  }
@@ -34761,7 +35279,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
34761
35279
  `Node hex string at index ${i} appears to be a raw transaction hex, not a TreeNode protobuf. Use 'leafidtohex' command to convert node IDs to proper hex strings.`
34762
35280
  );
34763
35281
  }
34764
- const nodeBytes = (0, import_utils25.hexToBytes)(hex);
35282
+ const nodeBytes = (0, import_utils24.hexToBytes)(hex);
34765
35283
  const node = TreeNode.decode(nodeBytes);
34766
35284
  if (!node.id) {
34767
35285
  throw new Error(
@@ -34837,7 +35355,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
34837
35355
  }
34838
35356
  }
34839
35357
  for (const chainNode of chain) {
34840
- let nodeTxHex = (0, import_utils25.bytesToHex)(chainNode.nodeTx);
35358
+ let nodeTxHex = (0, import_utils24.bytesToHex)(chainNode.nodeTx);
34841
35359
  try {
34842
35360
  const txObj = getTxFromRawTxHex(nodeTxHex);
34843
35361
  const txid = getTxId(txObj);
@@ -34854,7 +35372,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
34854
35372
  for (let i = txObj.outputsLength - 1; i >= 0; i--) {
34855
35373
  const output = txObj.getOutput(i);
34856
35374
  if (output?.amount === 0n && output.script) {
34857
- anchorOutputScriptHex = (0, import_utils25.bytesToHex)(output.script);
35375
+ anchorOutputScriptHex = (0, import_utils24.bytesToHex)(output.script);
34858
35376
  break;
34859
35377
  }
34860
35378
  }
@@ -34875,11 +35393,11 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
34875
35393
  usedUtxos,
34876
35394
  correctedParentTx
34877
35395
  } = constructFeeBumpTx(nodeTxHex, availableUtxos, feeRate, void 0);
34878
- const feeBumpTx = btc4.Transaction.fromPSBT((0, import_utils25.hexToBytes)(nodeFeeBumpPsbt));
35396
+ const feeBumpTx = btc4.Transaction.fromPSBT((0, import_utils24.hexToBytes)(nodeFeeBumpPsbt));
34879
35397
  var feeBumpOut = feeBumpTx.outputsLength === 1 ? feeBumpTx.getOutput(0) : null;
34880
35398
  var feeBumpOutPubKey = null;
34881
35399
  for (const usedUtxo of usedUtxos) {
34882
- if (feeBumpOut && (0, import_utils25.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
35400
+ if (feeBumpOut && (0, import_utils24.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
34883
35401
  feeBumpOutPubKey = usedUtxo.publicKey;
34884
35402
  }
34885
35403
  const index = availableUtxos.findIndex(
@@ -34894,20 +35412,20 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
34894
35412
  txid: getTxId(feeBumpTx),
34895
35413
  vout: 0,
34896
35414
  value: feeBumpOut.amount,
34897
- script: (0, import_utils25.bytesToHex)(feeBumpOut.script),
35415
+ script: (0, import_utils24.bytesToHex)(feeBumpOut.script),
34898
35416
  publicKey: feeBumpOutPubKey
34899
35417
  });
34900
35418
  const finalNodeTx = correctedParentTx || nodeTxHex;
34901
35419
  txPackages.push({ tx: finalNodeTx, feeBumpPsbt: nodeFeeBumpPsbt });
34902
35420
  if (chainNode.id === node.id) {
34903
- let refundTxHex = (0, import_utils25.bytesToHex)(chainNode.refundTx);
35421
+ let refundTxHex = (0, import_utils24.bytesToHex)(chainNode.refundTx);
34904
35422
  try {
34905
35423
  const txObj = getTxFromRawTxHex(refundTxHex);
34906
35424
  let anchorOutputScriptHex;
34907
35425
  for (let i = txObj.outputsLength - 1; i >= 0; i--) {
34908
35426
  const output = txObj.getOutput(i);
34909
35427
  if (output?.amount === 0n && output.script) {
34910
- anchorOutputScriptHex = (0, import_utils25.bytesToHex)(output.script);
35428
+ anchorOutputScriptHex = (0, import_utils24.bytesToHex)(output.script);
34911
35429
  break;
34912
35430
  }
34913
35431
  }
@@ -34930,12 +35448,12 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
34930
35448
  void 0
34931
35449
  );
34932
35450
  const feeBumpTx2 = btc4.Transaction.fromPSBT(
34933
- (0, import_utils25.hexToBytes)(refundFeeBump.feeBumpPsbt)
35451
+ (0, import_utils24.hexToBytes)(refundFeeBump.feeBumpPsbt)
34934
35452
  );
34935
35453
  var feeBumpOut = feeBumpTx2.outputsLength === 1 ? feeBumpTx2.getOutput(0) : null;
34936
35454
  var feeBumpOutPubKey = null;
34937
35455
  for (const usedUtxo of usedUtxos) {
34938
- if (feeBumpOut && (0, import_utils25.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
35456
+ if (feeBumpOut && (0, import_utils24.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
34939
35457
  feeBumpOutPubKey = usedUtxo.publicKey;
34940
35458
  }
34941
35459
  const index = availableUtxos.findIndex(
@@ -34950,7 +35468,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
34950
35468
  txid: getTxId(feeBumpTx2),
34951
35469
  vout: 0,
34952
35470
  value: feeBumpOut.amount,
34953
- script: (0, import_utils25.bytesToHex)(feeBumpOut.script),
35471
+ script: (0, import_utils24.bytesToHex)(feeBumpOut.script),
34954
35472
  publicKey: feeBumpOutPubKey
34955
35473
  });
34956
35474
  txPackages.push({
@@ -35045,10 +35563,10 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
35045
35563
  if (!fundingUtxo) {
35046
35564
  throw new Error(`UTXO at index ${i} is undefined`);
35047
35565
  }
35048
- const pubKeyHash = hash160((0, import_utils25.hexToBytes)(fundingUtxo.publicKey));
35566
+ const pubKeyHash = hash160((0, import_utils24.hexToBytes)(fundingUtxo.publicKey));
35049
35567
  const scriptToUse = new Uint8Array([0, 20, ...pubKeyHash]);
35050
- const providedScript = (0, import_utils25.hexToBytes)(fundingUtxo.script);
35051
- if ((0, import_utils25.bytesToHex)(scriptToUse) !== (0, import_utils25.bytesToHex)(providedScript)) {
35568
+ const providedScript = (0, import_utils24.hexToBytes)(fundingUtxo.script);
35569
+ if ((0, import_utils24.bytesToHex)(scriptToUse) !== (0, import_utils24.bytesToHex)(providedScript)) {
35052
35570
  throw new Error(
35053
35571
  `\u274C Derived script doesn't match provided script for UTXO ${i + 1}.`
35054
35572
  );
@@ -35113,7 +35631,7 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
35113
35631
  }
35114
35632
  let psbtHex;
35115
35633
  try {
35116
- psbtHex = (0, import_utils25.bytesToHex)(builder.toPSBT());
35634
+ psbtHex = (0, import_utils24.bytesToHex)(builder.toPSBT());
35117
35635
  } catch (error) {
35118
35636
  throw new Error(`Failed to extract transaction: ${error}`);
35119
35637
  }