@buildonspark/spark-sdk 0.3.2 → 0.3.4

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 (75) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/bare/index.cjs +953 -1567
  3. package/dist/bare/index.d.cts +132 -29
  4. package/dist/bare/index.d.ts +132 -29
  5. package/dist/bare/index.js +948 -1565
  6. package/dist/{chunk-MGCUXELA.js → chunk-IC4IUEOS.js} +931 -125
  7. package/dist/{chunk-MH7BMOLL.js → chunk-J2P3KTQP.js} +1 -1
  8. package/dist/{chunk-JDQKNT7G.js → chunk-KIQTO4FX.js} +403 -1808
  9. package/dist/{chunk-73GJOG5R.js → chunk-XWLR6G5C.js} +1 -1
  10. package/dist/{chunk-4KGN75J4.js → chunk-YH7MDVTT.js} +1 -1
  11. package/dist/{client-DrjQwET9.d.ts → client-DBZ43pJT.d.ts} +1 -1
  12. package/dist/{client-DUFejFfn.d.cts → client-DWml6sjL.d.cts} +1 -1
  13. package/dist/debug.cjs +957 -1569
  14. package/dist/debug.d.cts +8 -5
  15. package/dist/debug.d.ts +8 -5
  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 +913 -1528
  20. package/dist/index.d.cts +6 -6
  21. package/dist/index.d.ts +6 -6
  22. package/dist/index.js +9 -5
  23. package/dist/index.node.cjs +913 -1528
  24. package/dist/index.node.d.cts +6 -6
  25. package/dist/index.node.d.ts +6 -6
  26. package/dist/index.node.js +8 -4
  27. package/dist/{logging-IsaT3wjW.d.ts → logging-BUpzk4Z6.d.cts} +5 -5
  28. package/dist/{logging-Bt2FNHFR.d.cts → logging-Dt2ooQiP.d.ts} +5 -5
  29. package/dist/native/index.cjs +913 -1528
  30. package/dist/native/index.d.cts +133 -44
  31. package/dist/native/index.d.ts +133 -44
  32. package/dist/native/index.js +912 -1529
  33. package/dist/proto/spark.cjs +931 -125
  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-CLz4-Ln8.d.cts → spark-DasxuVfm.d.cts} +150 -5
  41. package/dist/{spark-CLz4-Ln8.d.ts → spark-DasxuVfm.d.ts} +150 -5
  42. package/dist/{spark-wallet-V03V4Tgm.d.cts → spark-wallet-BoMIOPWW.d.cts} +15 -26
  43. package/dist/{spark-wallet-KI68-_jO.d.ts → spark-wallet-jlC0XN5f.d.ts} +15 -26
  44. package/dist/{spark-wallet.node-Cuvw8Kvq.d.ts → spark-wallet.node-07PksUHH.d.cts} +1 -1
  45. package/dist/{spark-wallet.node-BtkqW5vn.d.cts → spark-wallet.node-CdWkKMSq.d.ts} +1 -1
  46. package/dist/tests/test-utils.cjs +951 -147
  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-5XxBewhV.d.ts → token-transactions-BDzCrQSk.d.cts} +5 -19
  51. package/dist/{token-transactions-fTnCtBpp.d.cts → token-transactions-DscJaJOE.d.ts} +5 -19
  52. package/dist/types/index.cjs +923 -125
  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 +1 -1
  57. package/src/proto/spark.ts +1167 -103
  58. package/src/services/config.ts +0 -4
  59. package/src/services/token-transactions.ts +11 -703
  60. package/src/services/transfer.ts +2 -213
  61. package/src/services/wallet-config.ts +0 -2
  62. package/src/spark-wallet/proto-descriptors.ts +1 -1
  63. package/src/spark-wallet/spark-wallet.ts +47 -215
  64. package/src/spark_descriptors.pb +0 -0
  65. package/src/tests/address.test.ts +141 -0
  66. package/src/tests/integration/address.test.ts +4 -0
  67. package/src/tests/integration/lightning.test.ts +14 -9
  68. package/src/tests/integration/token-output.test.ts +0 -1
  69. package/src/tests/integration/transfer.test.ts +108 -2
  70. package/src/tests/token-hashing.test.ts +0 -247
  71. package/src/utils/address.ts +58 -35
  72. package/src/utils/token-hashing.ts +1 -420
  73. package/src/utils/token-transaction-validation.ts +0 -330
  74. package/src/utils/transaction.ts +8 -8
  75. package/src/tests/integration/swap.test.ts +0 -780
package/dist/debug.cjs CHANGED
@@ -1426,7 +1426,7 @@ init_buffer();
1426
1426
  // src/spark-wallet/spark-wallet.ts
1427
1427
  init_buffer();
1428
1428
  var import_core13 = require("@lightsparkdev/core");
1429
- var import_secp256k115 = require("@noble/curves/secp256k1");
1429
+ var import_secp256k113 = require("@noble/curves/secp256k1");
1430
1430
  var import_utils23 = require("@noble/curves/utils");
1431
1431
  var import_bip392 = require("@scure/bip39");
1432
1432
  var import_english2 = require("@scure/bip39/wordlists/english");
@@ -1539,6 +1539,11 @@ var ConfigurationError = class extends SparkSDKError {
1539
1539
  super(message, context, originalError);
1540
1540
  }
1541
1541
  };
1542
+ var NotImplementedError = class extends SparkSDKError {
1543
+ constructor(message, context, originalError) {
1544
+ super(message, context, originalError);
1545
+ }
1546
+ };
1542
1547
 
1543
1548
  // src/graphql/client.ts
1544
1549
  init_buffer();
@@ -4257,9 +4262,9 @@ function invoiceStatusFromJSON(object) {
4257
4262
  case 2:
4258
4263
  case "FINALIZED":
4259
4264
  return 2 /* FINALIZED */;
4260
- case 3:
4261
- case "EXPIRED":
4262
- return 3 /* EXPIRED */;
4265
+ case 4:
4266
+ case "RETURNED":
4267
+ return 4 /* RETURNED */;
4263
4268
  case -1:
4264
4269
  case "UNRECOGNIZED":
4265
4270
  default:
@@ -4274,8 +4279,8 @@ function invoiceStatusToJSON(object) {
4274
4279
  return "PENDING";
4275
4280
  case 2 /* FINALIZED */:
4276
4281
  return "FINALIZED";
4277
- case 3 /* EXPIRED */:
4278
- return "EXPIRED";
4282
+ case 4 /* RETURNED */:
4283
+ return "RETURNED";
4279
4284
  case -1 /* UNRECOGNIZED */:
4280
4285
  default:
4281
4286
  return "UNRECOGNIZED";
@@ -6079,6 +6084,626 @@ var SigningResult_SignatureSharesEntry = {
6079
6084
  return message;
6080
6085
  }
6081
6086
  };
6087
+ function createBaseRenewLeafRequest() {
6088
+ return { leafId: "", ownerIdentityPublicKey: new Uint8Array(0), signingJobs: void 0 };
6089
+ }
6090
+ var RenewLeafRequest = {
6091
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6092
+ if (message.leafId !== "") {
6093
+ writer.uint32(10).string(message.leafId);
6094
+ }
6095
+ if (message.ownerIdentityPublicKey.length !== 0) {
6096
+ writer.uint32(18).bytes(message.ownerIdentityPublicKey);
6097
+ }
6098
+ switch (message.signingJobs?.$case) {
6099
+ case "renewNodeTimelockSigningJob":
6100
+ RenewNodeTimelockSigningJob.encode(message.signingJobs.renewNodeTimelockSigningJob, writer.uint32(26).fork()).join();
6101
+ break;
6102
+ case "renewRefundTimelockSigningJob":
6103
+ RenewRefundTimelockSigningJob.encode(
6104
+ message.signingJobs.renewRefundTimelockSigningJob,
6105
+ writer.uint32(34).fork()
6106
+ ).join();
6107
+ break;
6108
+ }
6109
+ return writer;
6110
+ },
6111
+ decode(input, length) {
6112
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6113
+ const end = length === void 0 ? reader.len : reader.pos + length;
6114
+ const message = createBaseRenewLeafRequest();
6115
+ while (reader.pos < end) {
6116
+ const tag = reader.uint32();
6117
+ switch (tag >>> 3) {
6118
+ case 1: {
6119
+ if (tag !== 10) {
6120
+ break;
6121
+ }
6122
+ message.leafId = reader.string();
6123
+ continue;
6124
+ }
6125
+ case 2: {
6126
+ if (tag !== 18) {
6127
+ break;
6128
+ }
6129
+ message.ownerIdentityPublicKey = reader.bytes();
6130
+ continue;
6131
+ }
6132
+ case 3: {
6133
+ if (tag !== 26) {
6134
+ break;
6135
+ }
6136
+ message.signingJobs = {
6137
+ $case: "renewNodeTimelockSigningJob",
6138
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.decode(reader, reader.uint32())
6139
+ };
6140
+ continue;
6141
+ }
6142
+ case 4: {
6143
+ if (tag !== 34) {
6144
+ break;
6145
+ }
6146
+ message.signingJobs = {
6147
+ $case: "renewRefundTimelockSigningJob",
6148
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.decode(reader, reader.uint32())
6149
+ };
6150
+ continue;
6151
+ }
6152
+ }
6153
+ if ((tag & 7) === 4 || tag === 0) {
6154
+ break;
6155
+ }
6156
+ reader.skip(tag & 7);
6157
+ }
6158
+ return message;
6159
+ },
6160
+ fromJSON(object) {
6161
+ return {
6162
+ leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : "",
6163
+ ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
6164
+ signingJobs: isSet3(object.renewNodeTimelockSigningJob) ? {
6165
+ $case: "renewNodeTimelockSigningJob",
6166
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromJSON(object.renewNodeTimelockSigningJob)
6167
+ } : isSet3(object.renewRefundTimelockSigningJob) ? {
6168
+ $case: "renewRefundTimelockSigningJob",
6169
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromJSON(object.renewRefundTimelockSigningJob)
6170
+ } : void 0
6171
+ };
6172
+ },
6173
+ toJSON(message) {
6174
+ const obj = {};
6175
+ if (message.leafId !== "") {
6176
+ obj.leafId = message.leafId;
6177
+ }
6178
+ if (message.ownerIdentityPublicKey.length !== 0) {
6179
+ obj.ownerIdentityPublicKey = base64FromBytes2(message.ownerIdentityPublicKey);
6180
+ }
6181
+ if (message.signingJobs?.$case === "renewNodeTimelockSigningJob") {
6182
+ obj.renewNodeTimelockSigningJob = RenewNodeTimelockSigningJob.toJSON(
6183
+ message.signingJobs.renewNodeTimelockSigningJob
6184
+ );
6185
+ } else if (message.signingJobs?.$case === "renewRefundTimelockSigningJob") {
6186
+ obj.renewRefundTimelockSigningJob = RenewRefundTimelockSigningJob.toJSON(
6187
+ message.signingJobs.renewRefundTimelockSigningJob
6188
+ );
6189
+ }
6190
+ return obj;
6191
+ },
6192
+ create(base) {
6193
+ return RenewLeafRequest.fromPartial(base ?? {});
6194
+ },
6195
+ fromPartial(object) {
6196
+ const message = createBaseRenewLeafRequest();
6197
+ message.leafId = object.leafId ?? "";
6198
+ message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
6199
+ switch (object.signingJobs?.$case) {
6200
+ case "renewNodeTimelockSigningJob": {
6201
+ if (object.signingJobs?.renewNodeTimelockSigningJob !== void 0 && object.signingJobs?.renewNodeTimelockSigningJob !== null) {
6202
+ message.signingJobs = {
6203
+ $case: "renewNodeTimelockSigningJob",
6204
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromPartial(
6205
+ object.signingJobs.renewNodeTimelockSigningJob
6206
+ )
6207
+ };
6208
+ }
6209
+ break;
6210
+ }
6211
+ case "renewRefundTimelockSigningJob": {
6212
+ if (object.signingJobs?.renewRefundTimelockSigningJob !== void 0 && object.signingJobs?.renewRefundTimelockSigningJob !== null) {
6213
+ message.signingJobs = {
6214
+ $case: "renewRefundTimelockSigningJob",
6215
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromPartial(
6216
+ object.signingJobs.renewRefundTimelockSigningJob
6217
+ )
6218
+ };
6219
+ }
6220
+ break;
6221
+ }
6222
+ }
6223
+ return message;
6224
+ }
6225
+ };
6226
+ function createBaseRenewNodeTimelockSigningJob() {
6227
+ return {
6228
+ splitNodeTxSigningJob: void 0,
6229
+ splitNodeDirectTxSigningJob: void 0,
6230
+ nodeTxSigningJob: void 0,
6231
+ refundTxSigningJob: void 0,
6232
+ directNodeTxSigningJob: void 0,
6233
+ directRefundTxSigningJob: void 0,
6234
+ directFromCpfpRefundTxSigningJob: void 0
6235
+ };
6236
+ }
6237
+ var RenewNodeTimelockSigningJob = {
6238
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6239
+ if (message.splitNodeTxSigningJob !== void 0) {
6240
+ UserSignedTxSigningJob.encode(message.splitNodeTxSigningJob, writer.uint32(10).fork()).join();
6241
+ }
6242
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
6243
+ UserSignedTxSigningJob.encode(message.splitNodeDirectTxSigningJob, writer.uint32(18).fork()).join();
6244
+ }
6245
+ if (message.nodeTxSigningJob !== void 0) {
6246
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(26).fork()).join();
6247
+ }
6248
+ if (message.refundTxSigningJob !== void 0) {
6249
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(34).fork()).join();
6250
+ }
6251
+ if (message.directNodeTxSigningJob !== void 0) {
6252
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(42).fork()).join();
6253
+ }
6254
+ if (message.directRefundTxSigningJob !== void 0) {
6255
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(50).fork()).join();
6256
+ }
6257
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
6258
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(58).fork()).join();
6259
+ }
6260
+ return writer;
6261
+ },
6262
+ decode(input, length) {
6263
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6264
+ const end = length === void 0 ? reader.len : reader.pos + length;
6265
+ const message = createBaseRenewNodeTimelockSigningJob();
6266
+ while (reader.pos < end) {
6267
+ const tag = reader.uint32();
6268
+ switch (tag >>> 3) {
6269
+ case 1: {
6270
+ if (tag !== 10) {
6271
+ break;
6272
+ }
6273
+ message.splitNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6274
+ continue;
6275
+ }
6276
+ case 2: {
6277
+ if (tag !== 18) {
6278
+ break;
6279
+ }
6280
+ message.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6281
+ continue;
6282
+ }
6283
+ case 3: {
6284
+ if (tag !== 26) {
6285
+ break;
6286
+ }
6287
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6288
+ continue;
6289
+ }
6290
+ case 4: {
6291
+ if (tag !== 34) {
6292
+ break;
6293
+ }
6294
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6295
+ continue;
6296
+ }
6297
+ case 5: {
6298
+ if (tag !== 42) {
6299
+ break;
6300
+ }
6301
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6302
+ continue;
6303
+ }
6304
+ case 6: {
6305
+ if (tag !== 50) {
6306
+ break;
6307
+ }
6308
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6309
+ continue;
6310
+ }
6311
+ case 7: {
6312
+ if (tag !== 58) {
6313
+ break;
6314
+ }
6315
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6316
+ continue;
6317
+ }
6318
+ }
6319
+ if ((tag & 7) === 4 || tag === 0) {
6320
+ break;
6321
+ }
6322
+ reader.skip(tag & 7);
6323
+ }
6324
+ return message;
6325
+ },
6326
+ fromJSON(object) {
6327
+ return {
6328
+ splitNodeTxSigningJob: isSet3(object.splitNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeTxSigningJob) : void 0,
6329
+ splitNodeDirectTxSigningJob: isSet3(object.splitNodeDirectTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeDirectTxSigningJob) : void 0,
6330
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
6331
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
6332
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
6333
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
6334
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
6335
+ };
6336
+ },
6337
+ toJSON(message) {
6338
+ const obj = {};
6339
+ if (message.splitNodeTxSigningJob !== void 0) {
6340
+ obj.splitNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeTxSigningJob);
6341
+ }
6342
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
6343
+ obj.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeDirectTxSigningJob);
6344
+ }
6345
+ if (message.nodeTxSigningJob !== void 0) {
6346
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
6347
+ }
6348
+ if (message.refundTxSigningJob !== void 0) {
6349
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
6350
+ }
6351
+ if (message.directNodeTxSigningJob !== void 0) {
6352
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
6353
+ }
6354
+ if (message.directRefundTxSigningJob !== void 0) {
6355
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
6356
+ }
6357
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
6358
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
6359
+ }
6360
+ return obj;
6361
+ },
6362
+ create(base) {
6363
+ return RenewNodeTimelockSigningJob.fromPartial(base ?? {});
6364
+ },
6365
+ fromPartial(object) {
6366
+ const message = createBaseRenewNodeTimelockSigningJob();
6367
+ message.splitNodeTxSigningJob = object.splitNodeTxSigningJob !== void 0 && object.splitNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeTxSigningJob) : void 0;
6368
+ message.splitNodeDirectTxSigningJob = object.splitNodeDirectTxSigningJob !== void 0 && object.splitNodeDirectTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeDirectTxSigningJob) : void 0;
6369
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
6370
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
6371
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
6372
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
6373
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
6374
+ return message;
6375
+ }
6376
+ };
6377
+ function createBaseRenewRefundTimelockSigningJob() {
6378
+ return {
6379
+ nodeTxSigningJob: void 0,
6380
+ refundTxSigningJob: void 0,
6381
+ directNodeTxSigningJob: void 0,
6382
+ directRefundTxSigningJob: void 0,
6383
+ directFromCpfpRefundTxSigningJob: void 0
6384
+ };
6385
+ }
6386
+ var RenewRefundTimelockSigningJob = {
6387
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6388
+ if (message.nodeTxSigningJob !== void 0) {
6389
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(10).fork()).join();
6390
+ }
6391
+ if (message.refundTxSigningJob !== void 0) {
6392
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(18).fork()).join();
6393
+ }
6394
+ if (message.directNodeTxSigningJob !== void 0) {
6395
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(26).fork()).join();
6396
+ }
6397
+ if (message.directRefundTxSigningJob !== void 0) {
6398
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(34).fork()).join();
6399
+ }
6400
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
6401
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(42).fork()).join();
6402
+ }
6403
+ return writer;
6404
+ },
6405
+ decode(input, length) {
6406
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6407
+ const end = length === void 0 ? reader.len : reader.pos + length;
6408
+ const message = createBaseRenewRefundTimelockSigningJob();
6409
+ while (reader.pos < end) {
6410
+ const tag = reader.uint32();
6411
+ switch (tag >>> 3) {
6412
+ case 1: {
6413
+ if (tag !== 10) {
6414
+ break;
6415
+ }
6416
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6417
+ continue;
6418
+ }
6419
+ case 2: {
6420
+ if (tag !== 18) {
6421
+ break;
6422
+ }
6423
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6424
+ continue;
6425
+ }
6426
+ case 3: {
6427
+ if (tag !== 26) {
6428
+ break;
6429
+ }
6430
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6431
+ continue;
6432
+ }
6433
+ case 4: {
6434
+ if (tag !== 34) {
6435
+ break;
6436
+ }
6437
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6438
+ continue;
6439
+ }
6440
+ case 5: {
6441
+ if (tag !== 42) {
6442
+ break;
6443
+ }
6444
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6445
+ continue;
6446
+ }
6447
+ }
6448
+ if ((tag & 7) === 4 || tag === 0) {
6449
+ break;
6450
+ }
6451
+ reader.skip(tag & 7);
6452
+ }
6453
+ return message;
6454
+ },
6455
+ fromJSON(object) {
6456
+ return {
6457
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
6458
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
6459
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
6460
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
6461
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
6462
+ };
6463
+ },
6464
+ toJSON(message) {
6465
+ const obj = {};
6466
+ if (message.nodeTxSigningJob !== void 0) {
6467
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
6468
+ }
6469
+ if (message.refundTxSigningJob !== void 0) {
6470
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
6471
+ }
6472
+ if (message.directNodeTxSigningJob !== void 0) {
6473
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
6474
+ }
6475
+ if (message.directRefundTxSigningJob !== void 0) {
6476
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
6477
+ }
6478
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
6479
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
6480
+ }
6481
+ return obj;
6482
+ },
6483
+ create(base) {
6484
+ return RenewRefundTimelockSigningJob.fromPartial(base ?? {});
6485
+ },
6486
+ fromPartial(object) {
6487
+ const message = createBaseRenewRefundTimelockSigningJob();
6488
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
6489
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
6490
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
6491
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
6492
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
6493
+ return message;
6494
+ }
6495
+ };
6496
+ function createBaseRenewLeafResponse() {
6497
+ return { renewResult: void 0 };
6498
+ }
6499
+ var RenewLeafResponse = {
6500
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6501
+ switch (message.renewResult?.$case) {
6502
+ case "extendResult":
6503
+ RenewNodeTimelockResult.encode(message.renewResult.extendResult, writer.uint32(10).fork()).join();
6504
+ break;
6505
+ case "refreshResult":
6506
+ RenewRefundTimelockResult.encode(message.renewResult.refreshResult, writer.uint32(18).fork()).join();
6507
+ break;
6508
+ }
6509
+ return writer;
6510
+ },
6511
+ decode(input, length) {
6512
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6513
+ const end = length === void 0 ? reader.len : reader.pos + length;
6514
+ const message = createBaseRenewLeafResponse();
6515
+ while (reader.pos < end) {
6516
+ const tag = reader.uint32();
6517
+ switch (tag >>> 3) {
6518
+ case 1: {
6519
+ if (tag !== 10) {
6520
+ break;
6521
+ }
6522
+ message.renewResult = {
6523
+ $case: "extendResult",
6524
+ extendResult: RenewNodeTimelockResult.decode(reader, reader.uint32())
6525
+ };
6526
+ continue;
6527
+ }
6528
+ case 2: {
6529
+ if (tag !== 18) {
6530
+ break;
6531
+ }
6532
+ message.renewResult = {
6533
+ $case: "refreshResult",
6534
+ refreshResult: RenewRefundTimelockResult.decode(reader, reader.uint32())
6535
+ };
6536
+ continue;
6537
+ }
6538
+ }
6539
+ if ((tag & 7) === 4 || tag === 0) {
6540
+ break;
6541
+ }
6542
+ reader.skip(tag & 7);
6543
+ }
6544
+ return message;
6545
+ },
6546
+ fromJSON(object) {
6547
+ return {
6548
+ renewResult: isSet3(object.extendResult) ? { $case: "extendResult", extendResult: RenewNodeTimelockResult.fromJSON(object.extendResult) } : isSet3(object.refreshResult) ? { $case: "refreshResult", refreshResult: RenewRefundTimelockResult.fromJSON(object.refreshResult) } : void 0
6549
+ };
6550
+ },
6551
+ toJSON(message) {
6552
+ const obj = {};
6553
+ if (message.renewResult?.$case === "extendResult") {
6554
+ obj.extendResult = RenewNodeTimelockResult.toJSON(message.renewResult.extendResult);
6555
+ } else if (message.renewResult?.$case === "refreshResult") {
6556
+ obj.refreshResult = RenewRefundTimelockResult.toJSON(message.renewResult.refreshResult);
6557
+ }
6558
+ return obj;
6559
+ },
6560
+ create(base) {
6561
+ return RenewLeafResponse.fromPartial(base ?? {});
6562
+ },
6563
+ fromPartial(object) {
6564
+ const message = createBaseRenewLeafResponse();
6565
+ switch (object.renewResult?.$case) {
6566
+ case "extendResult": {
6567
+ if (object.renewResult?.extendResult !== void 0 && object.renewResult?.extendResult !== null) {
6568
+ message.renewResult = {
6569
+ $case: "extendResult",
6570
+ extendResult: RenewNodeTimelockResult.fromPartial(object.renewResult.extendResult)
6571
+ };
6572
+ }
6573
+ break;
6574
+ }
6575
+ case "refreshResult": {
6576
+ if (object.renewResult?.refreshResult !== void 0 && object.renewResult?.refreshResult !== null) {
6577
+ message.renewResult = {
6578
+ $case: "refreshResult",
6579
+ refreshResult: RenewRefundTimelockResult.fromPartial(object.renewResult.refreshResult)
6580
+ };
6581
+ }
6582
+ break;
6583
+ }
6584
+ }
6585
+ return message;
6586
+ }
6587
+ };
6588
+ function createBaseRenewNodeTimelockResult() {
6589
+ return { splitNode: void 0, node: void 0 };
6590
+ }
6591
+ var RenewNodeTimelockResult = {
6592
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6593
+ if (message.splitNode !== void 0) {
6594
+ TreeNode.encode(message.splitNode, writer.uint32(10).fork()).join();
6595
+ }
6596
+ if (message.node !== void 0) {
6597
+ TreeNode.encode(message.node, writer.uint32(18).fork()).join();
6598
+ }
6599
+ return writer;
6600
+ },
6601
+ decode(input, length) {
6602
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6603
+ const end = length === void 0 ? reader.len : reader.pos + length;
6604
+ const message = createBaseRenewNodeTimelockResult();
6605
+ while (reader.pos < end) {
6606
+ const tag = reader.uint32();
6607
+ switch (tag >>> 3) {
6608
+ case 1: {
6609
+ if (tag !== 10) {
6610
+ break;
6611
+ }
6612
+ message.splitNode = TreeNode.decode(reader, reader.uint32());
6613
+ continue;
6614
+ }
6615
+ case 2: {
6616
+ if (tag !== 18) {
6617
+ break;
6618
+ }
6619
+ message.node = TreeNode.decode(reader, reader.uint32());
6620
+ continue;
6621
+ }
6622
+ }
6623
+ if ((tag & 7) === 4 || tag === 0) {
6624
+ break;
6625
+ }
6626
+ reader.skip(tag & 7);
6627
+ }
6628
+ return message;
6629
+ },
6630
+ fromJSON(object) {
6631
+ return {
6632
+ splitNode: isSet3(object.splitNode) ? TreeNode.fromJSON(object.splitNode) : void 0,
6633
+ node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0
6634
+ };
6635
+ },
6636
+ toJSON(message) {
6637
+ const obj = {};
6638
+ if (message.splitNode !== void 0) {
6639
+ obj.splitNode = TreeNode.toJSON(message.splitNode);
6640
+ }
6641
+ if (message.node !== void 0) {
6642
+ obj.node = TreeNode.toJSON(message.node);
6643
+ }
6644
+ return obj;
6645
+ },
6646
+ create(base) {
6647
+ return RenewNodeTimelockResult.fromPartial(base ?? {});
6648
+ },
6649
+ fromPartial(object) {
6650
+ const message = createBaseRenewNodeTimelockResult();
6651
+ message.splitNode = object.splitNode !== void 0 && object.splitNode !== null ? TreeNode.fromPartial(object.splitNode) : void 0;
6652
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
6653
+ return message;
6654
+ }
6655
+ };
6656
+ function createBaseRenewRefundTimelockResult() {
6657
+ return { node: void 0 };
6658
+ }
6659
+ var RenewRefundTimelockResult = {
6660
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6661
+ if (message.node !== void 0) {
6662
+ TreeNode.encode(message.node, writer.uint32(10).fork()).join();
6663
+ }
6664
+ return writer;
6665
+ },
6666
+ decode(input, length) {
6667
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6668
+ const end = length === void 0 ? reader.len : reader.pos + length;
6669
+ const message = createBaseRenewRefundTimelockResult();
6670
+ while (reader.pos < end) {
6671
+ const tag = reader.uint32();
6672
+ switch (tag >>> 3) {
6673
+ case 1: {
6674
+ if (tag !== 10) {
6675
+ break;
6676
+ }
6677
+ message.node = TreeNode.decode(reader, reader.uint32());
6678
+ continue;
6679
+ }
6680
+ }
6681
+ if ((tag & 7) === 4 || tag === 0) {
6682
+ break;
6683
+ }
6684
+ reader.skip(tag & 7);
6685
+ }
6686
+ return message;
6687
+ },
6688
+ fromJSON(object) {
6689
+ return { node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0 };
6690
+ },
6691
+ toJSON(message) {
6692
+ const obj = {};
6693
+ if (message.node !== void 0) {
6694
+ obj.node = TreeNode.toJSON(message.node);
6695
+ }
6696
+ return obj;
6697
+ },
6698
+ create(base) {
6699
+ return RenewRefundTimelockResult.fromPartial(base ?? {});
6700
+ },
6701
+ fromPartial(object) {
6702
+ const message = createBaseRenewRefundTimelockResult();
6703
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
6704
+ return message;
6705
+ }
6706
+ };
6082
6707
  function createBaseNodeSignatureShares() {
6083
6708
  return {
6084
6709
  nodeId: "",
@@ -17859,7 +18484,7 @@ var QuerySparkInvoicesResponse = {
17859
18484
  }
17860
18485
  };
17861
18486
  function createBaseInvoiceResponse() {
17862
- return { invoice: "", status: 0 };
18487
+ return { invoice: "", status: 0, transferType: void 0 };
17863
18488
  }
17864
18489
  var InvoiceResponse = {
17865
18490
  encode(message, writer = new import_wire4.BinaryWriter()) {
@@ -17869,6 +18494,14 @@ var InvoiceResponse = {
17869
18494
  if (message.status !== 0) {
17870
18495
  writer.uint32(16).int32(message.status);
17871
18496
  }
18497
+ switch (message.transferType?.$case) {
18498
+ case "satsTransfer":
18499
+ SatsTransfer.encode(message.transferType.satsTransfer, writer.uint32(26).fork()).join();
18500
+ break;
18501
+ case "tokenTransfer":
18502
+ TokenTransfer.encode(message.transferType.tokenTransfer, writer.uint32(34).fork()).join();
18503
+ break;
18504
+ }
17872
18505
  return writer;
17873
18506
  },
17874
18507
  decode(input, length) {
@@ -17892,6 +18525,23 @@ var InvoiceResponse = {
17892
18525
  message.status = reader.int32();
17893
18526
  continue;
17894
18527
  }
18528
+ case 3: {
18529
+ if (tag !== 26) {
18530
+ break;
18531
+ }
18532
+ message.transferType = { $case: "satsTransfer", satsTransfer: SatsTransfer.decode(reader, reader.uint32()) };
18533
+ continue;
18534
+ }
18535
+ case 4: {
18536
+ if (tag !== 34) {
18537
+ break;
18538
+ }
18539
+ message.transferType = {
18540
+ $case: "tokenTransfer",
18541
+ tokenTransfer: TokenTransfer.decode(reader, reader.uint32())
18542
+ };
18543
+ continue;
18544
+ }
17895
18545
  }
17896
18546
  if ((tag & 7) === 4 || tag === 0) {
17897
18547
  break;
@@ -17903,7 +18553,8 @@ var InvoiceResponse = {
17903
18553
  fromJSON(object) {
17904
18554
  return {
17905
18555
  invoice: isSet3(object.invoice) ? globalThis.String(object.invoice) : "",
17906
- status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0
18556
+ status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0,
18557
+ transferType: isSet3(object.satsTransfer) ? { $case: "satsTransfer", satsTransfer: SatsTransfer.fromJSON(object.satsTransfer) } : isSet3(object.tokenTransfer) ? { $case: "tokenTransfer", tokenTransfer: TokenTransfer.fromJSON(object.tokenTransfer) } : void 0
17907
18558
  };
17908
18559
  },
17909
18560
  toJSON(message) {
@@ -17914,6 +18565,11 @@ var InvoiceResponse = {
17914
18565
  if (message.status !== 0) {
17915
18566
  obj.status = invoiceStatusToJSON(message.status);
17916
18567
  }
18568
+ if (message.transferType?.$case === "satsTransfer") {
18569
+ obj.satsTransfer = SatsTransfer.toJSON(message.transferType.satsTransfer);
18570
+ } else if (message.transferType?.$case === "tokenTransfer") {
18571
+ obj.tokenTransfer = TokenTransfer.toJSON(message.transferType.tokenTransfer);
18572
+ }
17917
18573
  return obj;
17918
18574
  },
17919
18575
  create(base) {
@@ -17923,6 +18579,130 @@ var InvoiceResponse = {
17923
18579
  const message = createBaseInvoiceResponse();
17924
18580
  message.invoice = object.invoice ?? "";
17925
18581
  message.status = object.status ?? 0;
18582
+ switch (object.transferType?.$case) {
18583
+ case "satsTransfer": {
18584
+ if (object.transferType?.satsTransfer !== void 0 && object.transferType?.satsTransfer !== null) {
18585
+ message.transferType = {
18586
+ $case: "satsTransfer",
18587
+ satsTransfer: SatsTransfer.fromPartial(object.transferType.satsTransfer)
18588
+ };
18589
+ }
18590
+ break;
18591
+ }
18592
+ case "tokenTransfer": {
18593
+ if (object.transferType?.tokenTransfer !== void 0 && object.transferType?.tokenTransfer !== null) {
18594
+ message.transferType = {
18595
+ $case: "tokenTransfer",
18596
+ tokenTransfer: TokenTransfer.fromPartial(object.transferType.tokenTransfer)
18597
+ };
18598
+ }
18599
+ break;
18600
+ }
18601
+ }
18602
+ return message;
18603
+ }
18604
+ };
18605
+ function createBaseSatsTransfer() {
18606
+ return { transferId: new Uint8Array(0) };
18607
+ }
18608
+ var SatsTransfer = {
18609
+ encode(message, writer = new import_wire4.BinaryWriter()) {
18610
+ if (message.transferId.length !== 0) {
18611
+ writer.uint32(10).bytes(message.transferId);
18612
+ }
18613
+ return writer;
18614
+ },
18615
+ decode(input, length) {
18616
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
18617
+ const end = length === void 0 ? reader.len : reader.pos + length;
18618
+ const message = createBaseSatsTransfer();
18619
+ while (reader.pos < end) {
18620
+ const tag = reader.uint32();
18621
+ switch (tag >>> 3) {
18622
+ case 1: {
18623
+ if (tag !== 10) {
18624
+ break;
18625
+ }
18626
+ message.transferId = reader.bytes();
18627
+ continue;
18628
+ }
18629
+ }
18630
+ if ((tag & 7) === 4 || tag === 0) {
18631
+ break;
18632
+ }
18633
+ reader.skip(tag & 7);
18634
+ }
18635
+ return message;
18636
+ },
18637
+ fromJSON(object) {
18638
+ return { transferId: isSet3(object.transferId) ? bytesFromBase642(object.transferId) : new Uint8Array(0) };
18639
+ },
18640
+ toJSON(message) {
18641
+ const obj = {};
18642
+ if (message.transferId.length !== 0) {
18643
+ obj.transferId = base64FromBytes2(message.transferId);
18644
+ }
18645
+ return obj;
18646
+ },
18647
+ create(base) {
18648
+ return SatsTransfer.fromPartial(base ?? {});
18649
+ },
18650
+ fromPartial(object) {
18651
+ const message = createBaseSatsTransfer();
18652
+ message.transferId = object.transferId ?? new Uint8Array(0);
18653
+ return message;
18654
+ }
18655
+ };
18656
+ function createBaseTokenTransfer() {
18657
+ return { finalTokenTransactionHash: new Uint8Array(0) };
18658
+ }
18659
+ var TokenTransfer = {
18660
+ encode(message, writer = new import_wire4.BinaryWriter()) {
18661
+ if (message.finalTokenTransactionHash.length !== 0) {
18662
+ writer.uint32(10).bytes(message.finalTokenTransactionHash);
18663
+ }
18664
+ return writer;
18665
+ },
18666
+ decode(input, length) {
18667
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
18668
+ const end = length === void 0 ? reader.len : reader.pos + length;
18669
+ const message = createBaseTokenTransfer();
18670
+ while (reader.pos < end) {
18671
+ const tag = reader.uint32();
18672
+ switch (tag >>> 3) {
18673
+ case 1: {
18674
+ if (tag !== 10) {
18675
+ break;
18676
+ }
18677
+ message.finalTokenTransactionHash = reader.bytes();
18678
+ continue;
18679
+ }
18680
+ }
18681
+ if ((tag & 7) === 4 || tag === 0) {
18682
+ break;
18683
+ }
18684
+ reader.skip(tag & 7);
18685
+ }
18686
+ return message;
18687
+ },
18688
+ fromJSON(object) {
18689
+ return {
18690
+ finalTokenTransactionHash: isSet3(object.finalTokenTransactionHash) ? bytesFromBase642(object.finalTokenTransactionHash) : new Uint8Array(0)
18691
+ };
18692
+ },
18693
+ toJSON(message) {
18694
+ const obj = {};
18695
+ if (message.finalTokenTransactionHash.length !== 0) {
18696
+ obj.finalTokenTransactionHash = base64FromBytes2(message.finalTokenTransactionHash);
18697
+ }
18698
+ return obj;
18699
+ },
18700
+ create(base) {
18701
+ return TokenTransfer.fromPartial(base ?? {});
18702
+ },
18703
+ fromPartial(object) {
18704
+ const message = createBaseTokenTransfer();
18705
+ message.finalTokenTransactionHash = object.finalTokenTransactionHash ?? new Uint8Array(0);
17926
18706
  return message;
17927
18707
  }
17928
18708
  };
@@ -18138,6 +18918,21 @@ var SparkServiceDefinition = {
18138
18918
  responseStream: false,
18139
18919
  options: {}
18140
18920
  },
18921
+ /**
18922
+ * Resets the timelocks for a leaf's transactions. Can be used to reset the
18923
+ * refund transaction timelock for a leaf (when the node transaction
18924
+ * timelock is still > 300) or reset the node and refund transaction
18925
+ * timelock. Returns an error if a leaf is not yet eligible to renew the
18926
+ * timelocks, see RenewLeafRequest for more details.
18927
+ */
18928
+ renew_leaf: {
18929
+ name: "renew_leaf",
18930
+ requestType: RenewLeafRequest,
18931
+ requestStream: false,
18932
+ responseType: RenewLeafResponse,
18933
+ responseStream: false,
18934
+ options: {}
18935
+ },
18141
18936
  get_signing_operator_list: {
18142
18937
  name: "get_signing_operator_list",
18143
18938
  requestType: Empty,
@@ -18483,7 +19278,7 @@ var isWebExtension = (
18483
19278
  "chrome" in globalThis && globalThis.chrome.runtime?.id
18484
19279
  );
18485
19280
  var userAgent = "navigator" in globalThis ? globalThis.navigator.userAgent || "unknown-user-agent" : void 0;
18486
- var packageVersion = true ? "0.3.2" : "unknown";
19281
+ var packageVersion = true ? "0.3.4" : "unknown";
18487
19282
  var baseEnvStr = "unknown";
18488
19283
  if (isBun) {
18489
19284
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -19459,7 +20254,6 @@ var BASE_CONFIG = {
19459
20254
  threshold: 2,
19460
20255
  signingOperators: getLocalSigningOperators(),
19461
20256
  tokenSignatures: "SCHNORR",
19462
- tokenTransactionVersion: "V1",
19463
20257
  tokenValidityDurationSeconds: 180,
19464
20258
  electrsUrl: getElectrsUrl("LOCAL"),
19465
20259
  expectedWithdrawBondSats: 1e4,
@@ -19663,9 +20457,6 @@ var WalletConfigService = class {
19663
20457
  getTokenSignatures() {
19664
20458
  return this.config.tokenSignatures;
19665
20459
  }
19666
- getTokenTransactionVersion() {
19667
- return this.config.tokenTransactionVersion;
19668
- }
19669
20460
  getTokenValidityDurationSeconds() {
19670
20461
  return this.config.tokenValidityDurationSeconds;
19671
20462
  }
@@ -23987,10 +24778,10 @@ var INITIAL_TIMELOCK = 2e3;
23987
24778
  var TEST_UNILATERAL_TIMELOCK = 100;
23988
24779
  var TIME_LOCK_INTERVAL = 100;
23989
24780
  var DIRECT_TIMELOCK_OFFSET = 50;
23990
- var INITIAL_SEQUENCE = INITIAL_TIMELOCK;
23991
- var INITIAL_DIRECT_SEQUENCE = INITIAL_TIMELOCK + DIRECT_TIMELOCK_OFFSET;
23992
- var TEST_UNILATERAL_SEQUENCE = TEST_UNILATERAL_TIMELOCK;
23993
- var TEST_UNILATERAL_DIRECT_SEQUENCE = TEST_UNILATERAL_TIMELOCK + DIRECT_TIMELOCK_OFFSET;
24781
+ var INITIAL_SEQUENCE = 1 << 30 | INITIAL_TIMELOCK;
24782
+ var INITIAL_DIRECT_SEQUENCE = 1 << 30 | INITIAL_TIMELOCK + DIRECT_TIMELOCK_OFFSET;
24783
+ var TEST_UNILATERAL_SEQUENCE = 1 << 30 | TEST_UNILATERAL_TIMELOCK;
24784
+ var TEST_UNILATERAL_DIRECT_SEQUENCE = 1 << 30 | TEST_UNILATERAL_TIMELOCK + DIRECT_TIMELOCK_OFFSET;
23994
24785
  var ESTIMATED_TX_SIZE = 191;
23995
24786
  var DEFAULT_SATS_PER_VBYTE = 5;
23996
24787
  var DEFAULT_FEE_SATS = ESTIMATED_TX_SIZE * DEFAULT_SATS_PER_VBYTE;
@@ -24261,8 +25052,8 @@ function getCurrentTimelock(currSequence) {
24261
25052
  function getTransactionSequence(currSequence) {
24262
25053
  const timelock = getCurrentTimelock(currSequence);
24263
25054
  return {
24264
- nextSequence: timelock,
24265
- nextDirectSequence: timelock + DIRECT_TIMELOCK_OFFSET
25055
+ nextSequence: 1 << 30 | timelock,
25056
+ nextDirectSequence: 1 << 30 | timelock + DIRECT_TIMELOCK_OFFSET
24266
25057
  };
24267
25058
  }
24268
25059
  function checkIfValidSequence(currSequence) {
@@ -24305,8 +25096,8 @@ function getNextTransactionSequence(currSequence, isNodeTx) {
24305
25096
  });
24306
25097
  }
24307
25098
  return {
24308
- nextSequence: nextTimelock,
24309
- nextDirectSequence: nextTimelock + DIRECT_TIMELOCK_OFFSET
25099
+ nextSequence: 1 << 30 | nextTimelock,
25100
+ nextDirectSequence: 1 << 30 | nextTimelock + DIRECT_TIMELOCK_OFFSET
24310
25101
  };
24311
25102
  }
24312
25103
  function getEphemeralAnchorOutput() {
@@ -24369,51 +25160,6 @@ var BaseTransferService = class {
24369
25160
  this.connectionManager = connectionManager;
24370
25161
  this.signingService = signingService;
24371
25162
  }
24372
- async sendTransferTweakKey(transfer, leaves, cpfpRefundSignatureMap, directRefundSignatureMap, directFromCpfpRefundSignatureMap) {
24373
- const keyTweakInputMap = await this.prepareSendTransferKeyTweaks(
24374
- transfer.id,
24375
- transfer.receiverIdentityPublicKey,
24376
- leaves,
24377
- cpfpRefundSignatureMap,
24378
- directRefundSignatureMap,
24379
- directFromCpfpRefundSignatureMap
24380
- );
24381
- let updatedTransfer;
24382
- const coordinatorOperator = this.config.getSigningOperators()[this.config.getCoordinatorIdentifier()];
24383
- if (!coordinatorOperator) {
24384
- throw new ValidationError("Coordinator operator not found", {
24385
- field: "coordinator"
24386
- });
24387
- }
24388
- for (const [identifier, operator] of Object.entries(
24389
- this.config.getSigningOperators()
24390
- ).filter(([_, op]) => op.address !== this.config.getCoordinatorAddress())) {
24391
- updatedTransfer = await this.finalizeTransfer(
24392
- operator,
24393
- identifier,
24394
- keyTweakInputMap,
24395
- transfer,
24396
- updatedTransfer
24397
- );
24398
- }
24399
- updatedTransfer = await this.finalizeTransfer(
24400
- coordinatorOperator,
24401
- this.config.getCoordinatorIdentifier(),
24402
- keyTweakInputMap,
24403
- transfer,
24404
- updatedTransfer
24405
- );
24406
- if (!updatedTransfer) {
24407
- throw new ValidationError(
24408
- "No transfer response received from any operator",
24409
- {
24410
- field: "operators",
24411
- value: Object.keys(this.config.getSigningOperators()).length
24412
- }
24413
- );
24414
- }
24415
- return updatedTransfer;
24416
- }
24417
25163
  async deliverTransferPackage(transfer, leaves, cpfpRefundSignatureMap, directRefundSignatureMap, directFromCpfpRefundSignatureMap) {
24418
25164
  const keyTweakInputMap = await this.prepareSendTransferKeyTweaks(
24419
25165
  transfer.id,
@@ -24555,55 +25301,7 @@ var BaseTransferService = class {
24555
25301
  transferPackage.userSignature = new Uint8Array(signature);
24556
25302
  return transferPackage;
24557
25303
  }
24558
- async finalizeTransfer(operator, identifier, keyTweakInputMap, transfer, updatedTransfer) {
24559
- const sparkClient = await this.connectionManager.createSparkClient(
24560
- operator.address
24561
- );
24562
- const leavesToSend = keyTweakInputMap.get(identifier);
24563
- if (!leavesToSend) {
24564
- throw new ValidationError("No leaves to send for operator", {
24565
- field: "operator",
24566
- value: identifier
24567
- });
24568
- }
24569
- let transferResp;
24570
- try {
24571
- transferResp = await sparkClient.finalize_transfer({
24572
- transferId: transfer.id,
24573
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
24574
- leavesToSend
24575
- });
24576
- } catch (error) {
24577
- throw new NetworkError(
24578
- "Failed to finalize transfer",
24579
- {
24580
- method: "POST"
24581
- },
24582
- error
24583
- );
24584
- }
24585
- if (!updatedTransfer) {
24586
- updatedTransfer = transferResp.transfer;
24587
- } else {
24588
- if (!transferResp.transfer) {
24589
- throw new ValidationError("No transfer response from operator", {
24590
- field: "transfer",
24591
- value: transfer.id
24592
- });
24593
- }
24594
- if (!this.compareTransfers(updatedTransfer, transferResp.transfer)) {
24595
- throw new ValidationError(
24596
- "Inconsistent transfer response from operators",
24597
- {
24598
- field: "transfer",
24599
- value: transfer.id
24600
- }
24601
- );
24602
- }
24603
- }
24604
- return updatedTransfer;
24605
- }
24606
- async signRefunds(leafDataMap, operatorSigningResults, cpfpAdaptorPubKey, directAdaptorPubKey, directFromCpfpAdaptorPubKey) {
25304
+ async signRefunds(leafDataMap, operatorSigningResults) {
24607
25305
  const nodeSignatures = [];
24608
25306
  for (const operatorSigningResult of operatorSigningResults) {
24609
25307
  const leafData = leafDataMap.get(operatorSigningResult.leafId);
@@ -24632,7 +25330,6 @@ var BaseTransferService = class {
24632
25330
  keyDerivation: leafData.keyDerivation,
24633
25331
  selfCommitment: leafData.signingNonceCommitment,
24634
25332
  statechainCommitments: operatorSigningResult.refundTxSigningResult?.signingNonceCommitments,
24635
- adaptorPubKey: cpfpAdaptorPubKey,
24636
25333
  verifyingKey: operatorSigningResult.verifyingKey
24637
25334
  });
24638
25335
  const cpfpRefundAggregate = await this.config.signer.aggregateFrost({
@@ -24643,8 +25340,7 @@ var BaseTransferService = class {
24643
25340
  statechainCommitments: operatorSigningResult.refundTxSigningResult?.signingNonceCommitments,
24644
25341
  selfCommitment: leafData.signingNonceCommitment,
24645
25342
  publicKey,
24646
- selfSignature: cpfpUserSignature,
24647
- adaptorPubKey: cpfpAdaptorPubKey
25343
+ selfSignature: cpfpUserSignature
24648
25344
  });
24649
25345
  let directRefundAggregate;
24650
25346
  let directFromCpfpRefundAggregate;
@@ -24662,7 +25358,6 @@ var BaseTransferService = class {
24662
25358
  keyDerivation: leafData.keyDerivation,
24663
25359
  selfCommitment: leafData.directSigningNonceCommitment,
24664
25360
  statechainCommitments: operatorSigningResult.directRefundTxSigningResult?.signingNonceCommitments,
24665
- adaptorPubKey: directAdaptorPubKey,
24666
25361
  verifyingKey: operatorSigningResult.verifyingKey
24667
25362
  });
24668
25363
  directRefundAggregate = await this.config.signer.aggregateFrost({
@@ -24673,8 +25368,7 @@ var BaseTransferService = class {
24673
25368
  statechainCommitments: operatorSigningResult.directRefundTxSigningResult?.signingNonceCommitments,
24674
25369
  selfCommitment: leafData.directSigningNonceCommitment,
24675
25370
  publicKey,
24676
- selfSignature: directUserSignature,
24677
- adaptorPubKey: directAdaptorPubKey
25371
+ selfSignature: directUserSignature
24678
25372
  });
24679
25373
  }
24680
25374
  if (leafData.directFromCpfpRefundTx) {
@@ -24689,7 +25383,6 @@ var BaseTransferService = class {
24689
25383
  keyDerivation: leafData.keyDerivation,
24690
25384
  selfCommitment: leafData.directFromCpfpRefundSigningNonceCommitment,
24691
25385
  statechainCommitments: operatorSigningResult.directFromCpfpRefundTxSigningResult?.signingNonceCommitments,
24692
- adaptorPubKey: directFromCpfpAdaptorPubKey,
24693
25386
  verifyingKey: operatorSigningResult.verifyingKey
24694
25387
  });
24695
25388
  directFromCpfpRefundAggregate = await this.config.signer.aggregateFrost({
@@ -24700,8 +25393,7 @@ var BaseTransferService = class {
24700
25393
  statechainCommitments: operatorSigningResult.directFromCpfpRefundTxSigningResult?.signingNonceCommitments,
24701
25394
  selfCommitment: leafData.directFromCpfpRefundSigningNonceCommitment,
24702
25395
  publicKey,
24703
- selfSignature: directFromCpfpUserSignature,
24704
- adaptorPubKey: directFromCpfpAdaptorPubKey
25396
+ selfSignature: directFromCpfpUserSignature
24705
25397
  });
24706
25398
  }
24707
25399
  }
@@ -24817,30 +25509,6 @@ var TransferService = class extends BaseTransferService {
24817
25509
  constructor(config, connectionManager, signingService) {
24818
25510
  super(config, connectionManager, signingService);
24819
25511
  }
24820
- /**
24821
- * @deprecated Use sendTransferWithKeyTweaks instead
24822
- * Deprecated in v0.1.32
24823
- */
24824
- async sendTransfer(leaves, receiverIdentityPubkey) {
24825
- const {
24826
- transfer,
24827
- signatureMap,
24828
- directSignatureMap,
24829
- directFromCpfpSignatureMap
24830
- } = await this.sendTransferSignRefund(
24831
- leaves,
24832
- receiverIdentityPubkey,
24833
- new Date(Date.now() + DEFAULT_EXPIRY_TIME)
24834
- );
24835
- const transferWithTweakedKeys = await this.sendTransferTweakKey(
24836
- transfer,
24837
- leaves,
24838
- signatureMap,
24839
- directSignatureMap,
24840
- directFromCpfpSignatureMap
24841
- );
24842
- return transferWithTweakedKeys;
24843
- }
24844
25512
  async claimTransfer(transfer, leaves) {
24845
25513
  let proofMap;
24846
25514
  if (transfer.status === 2 /* TRANSFER_STATUS_SENDER_KEY_TWEAKED */) {
@@ -24984,18 +25652,7 @@ var TransferService = class extends BaseTransferService {
24984
25652
  leafDataMap
24985
25653
  };
24986
25654
  }
24987
- async counterSwapSignRefund(leaves, receiverIdentityPubkey, expiryTime, cpfpAdaptorPubKey, directAdaptorPubKey, directFromCpfpAdaptorPubKey) {
24988
- return this.sendTransferSignRefundInternal(
24989
- leaves,
24990
- receiverIdentityPubkey,
24991
- expiryTime,
24992
- true,
24993
- cpfpAdaptorPubKey,
24994
- directAdaptorPubKey,
24995
- directFromCpfpAdaptorPubKey
24996
- );
24997
- }
24998
- async sendTransferSignRefundInternal(leaves, receiverIdentityPubkey, expiryTime, forSwap, cpfpAdaptorPubKey, directAdaptorPubKey, directFromCpfpAdaptorPubKey) {
25655
+ async sendTransferSignRefundInternal(leaves, receiverIdentityPubkey, expiryTime, forSwap) {
24999
25656
  const transferId = (0, import_uuidv7.uuidv7)();
25000
25657
  const leafDataMap = /* @__PURE__ */ new Map();
25001
25658
  for (const leaf of leaves) {
@@ -25030,21 +25687,7 @@ var TransferService = class extends BaseTransferService {
25030
25687
  );
25031
25688
  let response;
25032
25689
  try {
25033
- if (cpfpAdaptorPubKey !== void 0 || directAdaptorPubKey !== void 0 || directFromCpfpAdaptorPubKey !== void 0) {
25034
- response = await sparkClient.counter_leaf_swap_v2({
25035
- transfer: {
25036
- transferId,
25037
- leavesToSend: signingJobs,
25038
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
25039
- receiverIdentityPublicKey: receiverIdentityPubkey,
25040
- expiryTime
25041
- },
25042
- swapId: (0, import_uuidv7.uuidv7)(),
25043
- adaptorPublicKey: cpfpAdaptorPubKey,
25044
- directAdaptorPublicKey: directAdaptorPubKey,
25045
- directFromCpfpAdaptorPublicKey: directFromCpfpAdaptorPubKey
25046
- });
25047
- } else if (forSwap) {
25690
+ if (forSwap) {
25048
25691
  response = await sparkClient.start_leaf_swap_v2({
25049
25692
  transferId,
25050
25693
  leavesToSend: signingJobs,
@@ -25069,10 +25712,7 @@ var TransferService = class extends BaseTransferService {
25069
25712
  }
25070
25713
  const signatures = await this.signRefunds(
25071
25714
  leafDataMap,
25072
- response.signingResults,
25073
- cpfpAdaptorPubKey,
25074
- directAdaptorPubKey,
25075
- directFromCpfpAdaptorPubKey
25715
+ response.signingResults
25076
25716
  );
25077
25717
  const cpfpSignatureMap = /* @__PURE__ */ new Map();
25078
25718
  const directSignatureMap = /* @__PURE__ */ new Map();
@@ -27243,7 +27883,6 @@ var LightningService = class {
27243
27883
 
27244
27884
  // src/services/token-transactions.ts
27245
27885
  init_buffer();
27246
- var import_secp256k112 = require("@noble/curves/secp256k1");
27247
27886
  var import_utils16 = require("@noble/curves/utils");
27248
27887
  var import_utils17 = require("@noble/hashes/utils");
27249
27888
 
@@ -27426,6 +28065,13 @@ function uint64be(value) {
27426
28065
  // src/utils/address.ts
27427
28066
  var BECH32M_LIMIT = 1024;
27428
28067
  var AddressNetwork = {
28068
+ MAINNET: "spark",
28069
+ TESTNET: "sparkt",
28070
+ REGTEST: "sparkrt",
28071
+ SIGNET: "sparks",
28072
+ LOCAL: "sparkl"
28073
+ };
28074
+ var LegacyAddressNetwork = {
27429
28075
  MAINNET: "sp",
27430
28076
  TESTNET: "spt",
27431
28077
  REGTEST: "sprt",
@@ -27456,7 +28102,7 @@ function encodeSparkAddressWithSignature(payload, signature) {
27456
28102
  const serializedPayload = w.finish();
27457
28103
  const words = import_base2.bech32m.toWords(serializedPayload);
27458
28104
  return bech32mEncode(
27459
- AddressNetwork[payload.network],
28105
+ LegacyAddressNetwork[payload.network],
27460
28106
  words
27461
28107
  );
27462
28108
  } catch (error) {
@@ -27472,14 +28118,14 @@ function encodeSparkAddressWithSignature(payload, signature) {
27472
28118
  }
27473
28119
  function decodeSparkAddress(address2, network) {
27474
28120
  try {
27475
- const decoded = bech32mDecode(address2);
27476
- if (decoded.prefix !== AddressNetwork[network]) {
28121
+ if (network !== getNetworkFromSparkAddress(address2)) {
27477
28122
  throw new ValidationError("Invalid Spark address prefix", {
27478
28123
  field: "address",
27479
28124
  value: address2,
27480
- expected: `prefix='${AddressNetwork[network]}'`
28125
+ expected: `prefix='${AddressNetwork[network]}' or '${LegacyAddressNetwork[network]}'`
27481
28126
  });
27482
28127
  }
28128
+ const decoded = bech32mDecode(address2);
27483
28129
  const payload = SparkAddress.decode(import_base2.bech32m.fromWords(decoded.words));
27484
28130
  const { identityPublicKey, sparkInvoiceFields, signature } = payload;
27485
28131
  const identityPubkeyHex = (0, import_utils14.bytesToHex)(identityPublicKey);
@@ -27523,18 +28169,35 @@ function decodeSparkAddress(address2, network) {
27523
28169
  );
27524
28170
  }
27525
28171
  }
28172
+ var PrefixToNetwork = Object.fromEntries(
28173
+ Object.entries(AddressNetwork).map(([k, v]) => [v, k])
28174
+ );
28175
+ var LegacyPrefixToNetwork = Object.fromEntries(
28176
+ Object.entries(LegacyAddressNetwork).map(([k, v]) => [v, k])
28177
+ );
28178
+ function getNetworkFromSparkAddress(address2) {
28179
+ const { prefix } = bech32mDecode(address2);
28180
+ const network = PrefixToNetwork[prefix] ?? LegacyPrefixToNetwork[prefix];
28181
+ if (!network) {
28182
+ throw new ValidationError("Invalid Spark address prefix", {
28183
+ field: "network",
28184
+ value: address2,
28185
+ expected: "prefix='spark1', 'sparkt1', 'sparkrt1', 'sparks1', 'sparkl1' or legacy ('sp1', 'spt1', 'sprt1', 'sps1', 'spl1')"
28186
+ });
28187
+ }
28188
+ return network;
28189
+ }
28190
+ function isLegacySparkAddress(address2) {
28191
+ try {
28192
+ const { prefix } = bech32mDecode(address2);
28193
+ return prefix in LegacyPrefixToNetwork;
28194
+ } catch (error) {
28195
+ return false;
28196
+ }
28197
+ }
27526
28198
  function isValidSparkAddress(address2) {
27527
28199
  try {
27528
- const network = Object.entries(AddressNetwork).find(
27529
- ([_, prefix]) => address2.startsWith(prefix)
27530
- )?.[0];
27531
- if (!network) {
27532
- throw new ValidationError("Invalid Spark address network", {
27533
- field: "network",
27534
- value: address2,
27535
- expected: Object.values(AddressNetwork)
27536
- });
27537
- }
28200
+ const network = getNetworkFromSparkAddress(address2);
27538
28201
  decodeSparkAddress(address2, network);
27539
28202
  return true;
27540
28203
  } catch (error) {
@@ -27730,25 +28393,16 @@ function validateSparkInvoiceSignature(invoice) {
27730
28393
  );
27731
28394
  }
27732
28395
  }
27733
- function getNetworkFromSparkAddress(address2) {
27734
- const { prefix } = bech32mDecode(address2);
27735
- const network = Object.entries(AddressNetwork).find(
27736
- ([, p]) => p === prefix
27737
- )?.[0];
27738
- if (!network) {
27739
- throw new ValidationError("Invalid Spark address network", {
27740
- field: "network",
27741
- value: address2,
27742
- expected: Object.values(AddressNetwork)
27743
- });
27744
- }
27745
- return network;
27746
- }
27747
28396
  function toProtoTimestamp(date) {
27748
28397
  const ms = date.getTime();
27749
28398
  return { seconds: Math.floor(ms / 1e3), nanos: ms % 1e3 * 1e6 };
27750
28399
  }
28400
+ function assertBech32(s2) {
28401
+ const i = s2.lastIndexOf("1");
28402
+ if (i <= 0 || i >= s2.length - 1) throw new Error("invalid bech32 string");
28403
+ }
27751
28404
  function bech32mDecode(address2) {
28405
+ assertBech32(address2);
27752
28406
  return import_base2.bech32m.decode(address2, BECH32M_LIMIT);
27753
28407
  }
27754
28408
  function bech32mEncode(prefix, words) {
@@ -27783,36 +28437,12 @@ function isSafeForNumber(bi) {
27783
28437
  return bi >= BigInt(Number.MIN_SAFE_INTEGER) && bi <= BigInt(Number.MAX_SAFE_INTEGER);
27784
28438
  }
27785
28439
 
27786
- // src/utils/response-validation.ts
27787
- init_buffer();
27788
- function collectResponses(responses) {
27789
- const successfulResponses = responses.filter(
27790
- (result) => result.status === "fulfilled"
27791
- ).map((result) => result.value);
27792
- const failedResponses = responses.filter(
27793
- (result) => result.status === "rejected"
27794
- );
27795
- if (failedResponses.length > 0) {
27796
- const errors = failedResponses.map((result) => result.reason).join("\n");
27797
- throw new NetworkError(
27798
- `${failedResponses.length} out of ${responses.length} requests failed, please try again`,
27799
- {
27800
- errorCount: failedResponses.length,
27801
- errors
27802
- }
27803
- );
27804
- }
27805
- return successfulResponses;
27806
- }
27807
-
27808
28440
  // src/utils/token-hashing.ts
27809
28441
  init_buffer();
27810
28442
  var import_sha211 = require("@noble/hashes/sha2");
27811
28443
  var import_base3 = require("@scure/base");
27812
28444
  function hashTokenTransaction(tokenTransaction, partialHash = false) {
27813
28445
  switch (tokenTransaction.version) {
27814
- case 0:
27815
- return hashTokenTransactionV0(tokenTransaction, partialHash);
27816
28446
  case 1:
27817
28447
  return hashTokenTransactionV1(tokenTransaction, partialHash);
27818
28448
  case 2:
@@ -27824,345 +28454,6 @@ function hashTokenTransaction(tokenTransaction, partialHash = false) {
27824
28454
  });
27825
28455
  }
27826
28456
  }
27827
- function hashTokenTransactionV0(tokenTransaction, partialHash = false) {
27828
- if (!tokenTransaction) {
27829
- throw new ValidationError("token transaction cannot be nil", {
27830
- field: "tokenTransaction"
27831
- });
27832
- }
27833
- let allHashes = [];
27834
- if (tokenTransaction.tokenInputs?.$case === "transferInput") {
27835
- if (!tokenTransaction.tokenInputs.transferInput.outputsToSpend) {
27836
- throw new ValidationError("outputs to spend cannot be null", {
27837
- field: "tokenInputs.transferInput.outputsToSpend"
27838
- });
27839
- }
27840
- if (tokenTransaction.tokenInputs.transferInput.outputsToSpend.length === 0) {
27841
- throw new ValidationError("outputs to spend cannot be empty", {
27842
- field: "tokenInputs.transferInput.outputsToSpend"
27843
- });
27844
- }
27845
- for (const [
27846
- i,
27847
- output
27848
- ] of tokenTransaction.tokenInputs.transferInput.outputsToSpend.entries()) {
27849
- if (!output) {
27850
- throw new ValidationError(`output cannot be null at index ${i}`, {
27851
- field: `tokenInputs.transferInput.outputsToSpend[${i}]`,
27852
- index: i
27853
- });
27854
- }
27855
- const hashObj2 = import_sha211.sha256.create();
27856
- if (output.prevTokenTransactionHash) {
27857
- const prevHash = output.prevTokenTransactionHash;
27858
- if (output.prevTokenTransactionHash.length !== 32) {
27859
- throw new ValidationError(
27860
- `invalid previous transaction hash length at index ${i}`,
27861
- {
27862
- field: `tokenInputs.transferInput.outputsToSpend[${i}].prevTokenTransactionHash`,
27863
- value: prevHash,
27864
- expectedLength: 32,
27865
- actualLength: prevHash.length,
27866
- index: i
27867
- }
27868
- );
27869
- }
27870
- hashObj2.update(output.prevTokenTransactionHash);
27871
- }
27872
- const voutBytes = new Uint8Array(4);
27873
- new DataView(voutBytes.buffer).setUint32(
27874
- 0,
27875
- output.prevTokenTransactionVout,
27876
- false
27877
- );
27878
- hashObj2.update(voutBytes);
27879
- allHashes.push(hashObj2.digest());
27880
- }
27881
- }
27882
- if (tokenTransaction.tokenInputs?.$case === "mintInput") {
27883
- const hashObj2 = import_sha211.sha256.create();
27884
- if (tokenTransaction.tokenInputs.mintInput.issuerPublicKey) {
27885
- const issuerPubKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
27886
- if (issuerPubKey.length === 0) {
27887
- throw new ValidationError("issuer public key cannot be empty", {
27888
- field: "tokenInputs.mintInput.issuerPublicKey",
27889
- value: issuerPubKey,
27890
- expectedLength: 1,
27891
- actualLength: 0
27892
- });
27893
- }
27894
- hashObj2.update(issuerPubKey);
27895
- let timestampValue = 0;
27896
- const mintInput = tokenTransaction.tokenInputs.mintInput;
27897
- if ("issuerProvidedTimestamp" in mintInput) {
27898
- const v0MintInput = mintInput;
27899
- if (v0MintInput.issuerProvidedTimestamp != 0) {
27900
- timestampValue = v0MintInput.issuerProvidedTimestamp;
27901
- }
27902
- } else if ("clientCreatedTimestamp" in tokenTransaction && tokenTransaction.clientCreatedTimestamp) {
27903
- timestampValue = tokenTransaction.clientCreatedTimestamp.getTime();
27904
- }
27905
- if (timestampValue != 0) {
27906
- const timestampBytes = new Uint8Array(8);
27907
- new DataView(timestampBytes.buffer).setBigUint64(
27908
- 0,
27909
- BigInt(timestampValue),
27910
- true
27911
- // true for little-endian to match Go implementation
27912
- );
27913
- hashObj2.update(timestampBytes);
27914
- }
27915
- allHashes.push(hashObj2.digest());
27916
- }
27917
- }
27918
- if (tokenTransaction.tokenInputs?.$case === "createInput") {
27919
- const issuerPubKeyHashObj = import_sha211.sha256.create();
27920
- const createInput = tokenTransaction.tokenInputs.createInput;
27921
- if (!createInput.issuerPublicKey || createInput.issuerPublicKey.length === 0) {
27922
- throw new ValidationError("issuer public key cannot be nil or empty", {
27923
- field: "tokenInputs.createInput.issuerPublicKey"
27924
- });
27925
- }
27926
- issuerPubKeyHashObj.update(createInput.issuerPublicKey);
27927
- allHashes.push(issuerPubKeyHashObj.digest());
27928
- const tokenNameHashObj = import_sha211.sha256.create();
27929
- if (!createInput.tokenName || createInput.tokenName.length === 0) {
27930
- throw new ValidationError("token name cannot be empty", {
27931
- field: "tokenInputs.createInput.tokenName"
27932
- });
27933
- }
27934
- if (createInput.tokenName.length > 20) {
27935
- throw new ValidationError("token name cannot be longer than 20 bytes", {
27936
- field: "tokenInputs.createInput.tokenName",
27937
- value: createInput.tokenName,
27938
- expectedLength: 20,
27939
- actualLength: createInput.tokenName.length
27940
- });
27941
- }
27942
- const tokenNameBytes = new Uint8Array(20);
27943
- const tokenNameEncoder = new TextEncoder();
27944
- tokenNameBytes.set(tokenNameEncoder.encode(createInput.tokenName));
27945
- tokenNameHashObj.update(tokenNameBytes);
27946
- allHashes.push(tokenNameHashObj.digest());
27947
- const tokenTickerHashObj = import_sha211.sha256.create();
27948
- if (!createInput.tokenTicker || createInput.tokenTicker.length === 0) {
27949
- throw new ValidationError("token ticker cannot be empty", {
27950
- field: "tokenInputs.createInput.tokenTicker"
27951
- });
27952
- }
27953
- if (createInput.tokenTicker.length > 6) {
27954
- throw new ValidationError("token ticker cannot be longer than 6 bytes", {
27955
- field: "tokenInputs.createInput.tokenTicker",
27956
- value: createInput.tokenTicker,
27957
- expectedLength: 6,
27958
- actualLength: createInput.tokenTicker.length
27959
- });
27960
- }
27961
- const tokenTickerBytes = new Uint8Array(6);
27962
- const tokenTickerEncoder = new TextEncoder();
27963
- tokenTickerBytes.set(tokenTickerEncoder.encode(createInput.tokenTicker));
27964
- tokenTickerHashObj.update(tokenTickerBytes);
27965
- allHashes.push(tokenTickerHashObj.digest());
27966
- const decimalsHashObj = import_sha211.sha256.create();
27967
- const decimalsBytes = new Uint8Array(4);
27968
- new DataView(decimalsBytes.buffer).setUint32(
27969
- 0,
27970
- createInput.decimals,
27971
- false
27972
- );
27973
- decimalsHashObj.update(decimalsBytes);
27974
- allHashes.push(decimalsHashObj.digest());
27975
- const maxSupplyHashObj = import_sha211.sha256.create();
27976
- if (!createInput.maxSupply) {
27977
- throw new ValidationError("max supply cannot be nil", {
27978
- field: "tokenInputs.createInput.maxSupply"
27979
- });
27980
- }
27981
- if (createInput.maxSupply.length !== 16) {
27982
- throw new ValidationError("max supply must be exactly 16 bytes", {
27983
- field: "tokenInputs.createInput.maxSupply",
27984
- value: createInput.maxSupply,
27985
- expectedLength: 16,
27986
- actualLength: createInput.maxSupply.length
27987
- });
27988
- }
27989
- maxSupplyHashObj.update(createInput.maxSupply);
27990
- allHashes.push(maxSupplyHashObj.digest());
27991
- const isFreezableHashObj = import_sha211.sha256.create();
27992
- const isFreezableByte = new Uint8Array([createInput.isFreezable ? 1 : 0]);
27993
- isFreezableHashObj.update(isFreezableByte);
27994
- allHashes.push(isFreezableHashObj.digest());
27995
- const creationEntityHashObj = import_sha211.sha256.create();
27996
- if (!partialHash && createInput.creationEntityPublicKey) {
27997
- creationEntityHashObj.update(createInput.creationEntityPublicKey);
27998
- }
27999
- allHashes.push(creationEntityHashObj.digest());
28000
- }
28001
- if (!tokenTransaction.tokenOutputs) {
28002
- throw new ValidationError("token outputs cannot be null", {
28003
- field: "tokenOutputs"
28004
- });
28005
- }
28006
- if (tokenTransaction.tokenOutputs.length === 0 && tokenTransaction.tokenInputs?.$case !== "createInput") {
28007
- throw new ValidationError("token outputs cannot be empty", {
28008
- field: "tokenOutputs"
28009
- });
28010
- }
28011
- for (const [i, output] of tokenTransaction.tokenOutputs.entries()) {
28012
- if (!output) {
28013
- throw new ValidationError(`output cannot be null at index ${i}`, {
28014
- field: `tokenOutputs[${i}]`,
28015
- index: i
28016
- });
28017
- }
28018
- const hashObj2 = import_sha211.sha256.create();
28019
- if (output.id && !partialHash) {
28020
- if (output.id.length === 0) {
28021
- throw new ValidationError(`output ID at index ${i} cannot be empty`, {
28022
- field: `tokenOutputs[${i}].id`,
28023
- index: i
28024
- });
28025
- }
28026
- hashObj2.update(new TextEncoder().encode(output.id));
28027
- }
28028
- if (output.ownerPublicKey) {
28029
- if (output.ownerPublicKey.length === 0) {
28030
- throw new ValidationError(
28031
- `owner public key at index ${i} cannot be empty`,
28032
- {
28033
- field: `tokenOutputs[${i}].ownerPublicKey`,
28034
- index: i
28035
- }
28036
- );
28037
- }
28038
- hashObj2.update(output.ownerPublicKey);
28039
- }
28040
- if (!partialHash) {
28041
- const revPubKey = output.revocationCommitment;
28042
- if (revPubKey) {
28043
- if (revPubKey.length === 0) {
28044
- throw new ValidationError(
28045
- `revocation commitment at index ${i} cannot be empty`,
28046
- {
28047
- field: `tokenOutputs[${i}].revocationCommitment`,
28048
- index: i
28049
- }
28050
- );
28051
- }
28052
- hashObj2.update(revPubKey);
28053
- }
28054
- const bondBytes = new Uint8Array(8);
28055
- new DataView(bondBytes.buffer).setBigUint64(
28056
- 0,
28057
- BigInt(output.withdrawBondSats),
28058
- false
28059
- );
28060
- hashObj2.update(bondBytes);
28061
- const locktimeBytes = new Uint8Array(8);
28062
- new DataView(locktimeBytes.buffer).setBigUint64(
28063
- 0,
28064
- BigInt(output.withdrawRelativeBlockLocktime),
28065
- false
28066
- );
28067
- hashObj2.update(locktimeBytes);
28068
- }
28069
- if (output.tokenPublicKey) {
28070
- if (output.tokenPublicKey.length === 0) {
28071
- throw new ValidationError(
28072
- `token public key at index ${i} cannot be empty`,
28073
- {
28074
- field: `tokenOutputs[${i}].tokenPublicKey`,
28075
- index: i
28076
- }
28077
- );
28078
- }
28079
- hashObj2.update(output.tokenPublicKey);
28080
- }
28081
- if (output.tokenAmount) {
28082
- if (output.tokenAmount.length === 0) {
28083
- throw new ValidationError(
28084
- `token amount at index ${i} cannot be empty`,
28085
- {
28086
- field: `tokenOutputs[${i}].tokenAmount`,
28087
- index: i
28088
- }
28089
- );
28090
- }
28091
- if (output.tokenAmount.length > 16) {
28092
- throw new ValidationError(
28093
- `token amount at index ${i} exceeds maximum length`,
28094
- {
28095
- field: `tokenOutputs[${i}].tokenAmount`,
28096
- value: output.tokenAmount,
28097
- expectedLength: 16,
28098
- actualLength: output.tokenAmount.length,
28099
- index: i
28100
- }
28101
- );
28102
- }
28103
- hashObj2.update(output.tokenAmount);
28104
- }
28105
- allHashes.push(hashObj2.digest());
28106
- }
28107
- if (!tokenTransaction.sparkOperatorIdentityPublicKeys) {
28108
- throw new ValidationError(
28109
- "spark operator identity public keys cannot be null",
28110
- {}
28111
- );
28112
- }
28113
- const sortedPubKeys = [
28114
- ...tokenTransaction.sparkOperatorIdentityPublicKeys || []
28115
- ].sort((a, b) => {
28116
- for (let i = 0; i < a.length && i < b.length; i++) {
28117
- if (a[i] !== b[i]) return a[i] - b[i];
28118
- }
28119
- return a.length - b.length;
28120
- });
28121
- for (const [i, pubKey] of sortedPubKeys.entries()) {
28122
- if (!pubKey) {
28123
- throw new ValidationError(
28124
- `operator public key at index ${i} cannot be null`,
28125
- {
28126
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
28127
- index: i
28128
- }
28129
- );
28130
- }
28131
- if (pubKey.length === 0) {
28132
- throw new ValidationError(
28133
- `operator public key at index ${i} cannot be empty`,
28134
- {
28135
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
28136
- index: i
28137
- }
28138
- );
28139
- }
28140
- const hashObj2 = import_sha211.sha256.create();
28141
- hashObj2.update(pubKey);
28142
- allHashes.push(hashObj2.digest());
28143
- }
28144
- const hashObj = import_sha211.sha256.create();
28145
- let networkBytes = new Uint8Array(4);
28146
- new DataView(networkBytes.buffer).setUint32(
28147
- 0,
28148
- tokenTransaction.network.valueOf(),
28149
- false
28150
- // false for big-endian
28151
- );
28152
- hashObj.update(networkBytes);
28153
- allHashes.push(hashObj.digest());
28154
- const finalHashObj = import_sha211.sha256.create();
28155
- const concatenatedHashes = new Uint8Array(
28156
- allHashes.reduce((sum, hash) => sum + hash.length, 0)
28157
- );
28158
- let offset = 0;
28159
- for (const hash of allHashes) {
28160
- concatenatedHashes.set(hash, offset);
28161
- offset += hash.length;
28162
- }
28163
- finalHashObj.update(concatenatedHashes);
28164
- return finalHashObj.digest();
28165
- }
28166
28457
  function hashTokenTransactionV1(tokenTransaction, partialHash = false) {
28167
28458
  if (!tokenTransaction) {
28168
28459
  throw new ValidationError("token transaction cannot be nil", {
@@ -29190,24 +29481,6 @@ function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier) {
29190
29481
  });
29191
29482
  }
29192
29483
 
29193
- // src/utils/token-keyshares.ts
29194
- init_buffer();
29195
- var import_secp256k111 = require("@noble/curves/secp256k1");
29196
- function recoverRevocationSecretFromKeyshares(keyshares, threshold) {
29197
- const shares = keyshares.map((keyshare) => ({
29198
- fieldModulus: BigInt("0x" + import_secp256k111.secp256k1.CURVE.n.toString(16)),
29199
- // secp256k1 curve order
29200
- threshold,
29201
- index: BigInt(keyshare.operatorIndex),
29202
- share: BigInt(
29203
- "0x" + import_buffer.Buffer.from(keyshare.keyshare.keyshare).toString("hex")
29204
- ),
29205
- proofs: []
29206
- }));
29207
- const recoveredSecret = recoverSecret(shares);
29208
- return bigIntToPrivateKey(recoveredSecret);
29209
- }
29210
-
29211
29484
  // src/utils/token-transaction-validation.ts
29212
29485
  init_buffer();
29213
29486
  function areByteArraysEqual(a, b) {
@@ -29219,250 +29492,6 @@ function areByteArraysEqual(a, b) {
29219
29492
  function hasDuplicates(array) {
29220
29493
  return new Set(array).size !== array.length;
29221
29494
  }
29222
- function validateTokenTransactionV0(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
29223
- if (finalTokenTransaction.network !== partialTokenTransaction.network) {
29224
- throw new InternalValidationError(
29225
- "Network mismatch in response token transaction",
29226
- {
29227
- value: finalTokenTransaction.network,
29228
- expected: partialTokenTransaction.network
29229
- }
29230
- );
29231
- }
29232
- if (!finalTokenTransaction.tokenInputs) {
29233
- throw new InternalValidationError(
29234
- "Token inputs missing in final transaction",
29235
- {
29236
- value: finalTokenTransaction
29237
- }
29238
- );
29239
- }
29240
- if (!partialTokenTransaction.tokenInputs) {
29241
- throw new InternalValidationError(
29242
- "Token inputs missing in partial transaction",
29243
- {
29244
- value: partialTokenTransaction
29245
- }
29246
- );
29247
- }
29248
- if (finalTokenTransaction.tokenInputs.$case !== partialTokenTransaction.tokenInputs.$case) {
29249
- throw new InternalValidationError(
29250
- `Transaction type mismatch: final transaction has ${finalTokenTransaction.tokenInputs.$case}, partial transaction has ${partialTokenTransaction.tokenInputs.$case}`,
29251
- {
29252
- value: finalTokenTransaction.tokenInputs.$case,
29253
- expected: partialTokenTransaction.tokenInputs.$case
29254
- }
29255
- );
29256
- }
29257
- if (finalTokenTransaction.sparkOperatorIdentityPublicKeys.length !== partialTokenTransaction.sparkOperatorIdentityPublicKeys.length) {
29258
- throw new InternalValidationError(
29259
- "Spark operator identity public keys count mismatch",
29260
- {
29261
- value: finalTokenTransaction.sparkOperatorIdentityPublicKeys.length,
29262
- expected: partialTokenTransaction.sparkOperatorIdentityPublicKeys.length
29263
- }
29264
- );
29265
- }
29266
- if (partialTokenTransaction.tokenInputs.$case === "mintInput" && finalTokenTransaction.tokenInputs.$case === "mintInput") {
29267
- const finalMintInput = finalTokenTransaction.tokenInputs.mintInput;
29268
- const partialMintInput = partialTokenTransaction.tokenInputs.mintInput;
29269
- if (!areByteArraysEqual(
29270
- finalMintInput.issuerPublicKey,
29271
- partialMintInput.issuerPublicKey
29272
- )) {
29273
- throw new InternalValidationError(
29274
- "Issuer public key mismatch in mint input",
29275
- {
29276
- value: finalMintInput.issuerPublicKey.toString(),
29277
- expected: partialMintInput.issuerPublicKey.toString()
29278
- }
29279
- );
29280
- }
29281
- } else if (partialTokenTransaction.tokenInputs.$case === "transferInput" && finalTokenTransaction.tokenInputs.$case === "transferInput") {
29282
- const finalTransferInput = finalTokenTransaction.tokenInputs.transferInput;
29283
- const partialTransferInput = partialTokenTransaction.tokenInputs.transferInput;
29284
- if (finalTransferInput.outputsToSpend.length !== partialTransferInput.outputsToSpend.length) {
29285
- throw new InternalValidationError(
29286
- "Outputs to spend count mismatch in transfer input",
29287
- {
29288
- value: finalTransferInput.outputsToSpend.length,
29289
- expected: partialTransferInput.outputsToSpend.length
29290
- }
29291
- );
29292
- }
29293
- for (let i = 0; i < finalTransferInput.outputsToSpend.length; i++) {
29294
- const finalOutput = finalTransferInput.outputsToSpend[i];
29295
- const partialOutput = partialTransferInput.outputsToSpend[i];
29296
- if (!finalOutput) {
29297
- throw new InternalValidationError(
29298
- "Token output to spend missing in final transaction",
29299
- {
29300
- outputIndex: i,
29301
- value: finalOutput
29302
- }
29303
- );
29304
- }
29305
- if (!partialOutput) {
29306
- throw new InternalValidationError(
29307
- "Token output to spend missing in partial transaction",
29308
- {
29309
- outputIndex: i,
29310
- value: partialOutput
29311
- }
29312
- );
29313
- }
29314
- if (!areByteArraysEqual(
29315
- finalOutput.prevTokenTransactionHash,
29316
- partialOutput.prevTokenTransactionHash
29317
- )) {
29318
- throw new InternalValidationError(
29319
- "Previous token transaction hash mismatch in transfer input",
29320
- {
29321
- outputIndex: i,
29322
- value: finalOutput.prevTokenTransactionHash.toString(),
29323
- expected: partialOutput.prevTokenTransactionHash.toString()
29324
- }
29325
- );
29326
- }
29327
- if (finalOutput.prevTokenTransactionVout !== partialOutput.prevTokenTransactionVout) {
29328
- throw new InternalValidationError(
29329
- "Previous token transaction vout mismatch in transfer input",
29330
- {
29331
- outputIndex: i,
29332
- value: finalOutput.prevTokenTransactionVout,
29333
- expected: partialOutput.prevTokenTransactionVout
29334
- }
29335
- );
29336
- }
29337
- }
29338
- }
29339
- if (finalTokenTransaction.tokenOutputs.length !== partialTokenTransaction.tokenOutputs.length) {
29340
- throw new InternalValidationError("Token outputs count mismatch", {
29341
- value: finalTokenTransaction.tokenOutputs.length,
29342
- expected: partialTokenTransaction.tokenOutputs.length
29343
- });
29344
- }
29345
- for (let i = 0; i < finalTokenTransaction.tokenOutputs.length; i++) {
29346
- const finalOutput = finalTokenTransaction.tokenOutputs[i];
29347
- const partialOutput = partialTokenTransaction.tokenOutputs[i];
29348
- if (!finalOutput) {
29349
- throw new InternalValidationError(
29350
- "Token output missing in final transaction",
29351
- {
29352
- outputIndex: i,
29353
- value: finalOutput
29354
- }
29355
- );
29356
- }
29357
- if (!partialOutput) {
29358
- throw new InternalValidationError(
29359
- "Token output missing in partial transaction",
29360
- {
29361
- outputIndex: i,
29362
- value: partialOutput
29363
- }
29364
- );
29365
- }
29366
- if (!areByteArraysEqual(
29367
- finalOutput.ownerPublicKey,
29368
- partialOutput.ownerPublicKey
29369
- )) {
29370
- throw new InternalValidationError(
29371
- "Owner public key mismatch in token output",
29372
- {
29373
- outputIndex: i,
29374
- value: finalOutput.ownerPublicKey.toString(),
29375
- expected: partialOutput.ownerPublicKey.toString()
29376
- }
29377
- );
29378
- }
29379
- if (finalOutput.tokenPublicKey !== void 0 && partialOutput.tokenPublicKey !== void 0 && !areByteArraysEqual(
29380
- finalOutput.tokenPublicKey,
29381
- partialOutput.tokenPublicKey
29382
- )) {
29383
- throw new InternalValidationError(
29384
- "Token public key mismatch in token output",
29385
- {
29386
- outputIndex: i,
29387
- value: finalOutput.tokenPublicKey?.toString(),
29388
- expected: partialOutput.tokenPublicKey?.toString()
29389
- }
29390
- );
29391
- }
29392
- if (!areByteArraysEqual(finalOutput.tokenAmount, partialOutput.tokenAmount)) {
29393
- throw new InternalValidationError(
29394
- "Token amount mismatch in token output",
29395
- {
29396
- outputIndex: i,
29397
- value: finalOutput.tokenAmount.toString(),
29398
- expected: partialOutput.tokenAmount.toString()
29399
- }
29400
- );
29401
- }
29402
- if (finalOutput.withdrawBondSats !== void 0) {
29403
- if (finalOutput.withdrawBondSats !== expectedWithdrawBondSats) {
29404
- throw new InternalValidationError(
29405
- "Withdraw bond sats mismatch in token output",
29406
- {
29407
- outputIndex: i,
29408
- value: finalOutput.withdrawBondSats,
29409
- expected: expectedWithdrawBondSats
29410
- }
29411
- );
29412
- }
29413
- }
29414
- if (finalOutput.withdrawRelativeBlockLocktime !== void 0) {
29415
- if (finalOutput.withdrawRelativeBlockLocktime !== expectedWithdrawRelativeBlockLocktime) {
29416
- throw new InternalValidationError(
29417
- "Withdraw relative block locktime mismatch in token output",
29418
- {
29419
- outputIndex: i,
29420
- value: finalOutput.withdrawRelativeBlockLocktime,
29421
- expected: expectedWithdrawRelativeBlockLocktime
29422
- }
29423
- );
29424
- }
29425
- }
29426
- if (keyshareInfo.threshold !== expectedThreshold) {
29427
- throw new InternalValidationError(
29428
- "Threshold mismatch: expected " + expectedThreshold + " but got " + keyshareInfo.threshold,
29429
- {
29430
- field: "threshold",
29431
- value: keyshareInfo.threshold,
29432
- expected: expectedThreshold
29433
- }
29434
- );
29435
- }
29436
- }
29437
- if (keyshareInfo.ownerIdentifiers.length !== Object.keys(signingOperators).length) {
29438
- throw new InternalValidationError(
29439
- `Keyshare operator count (${keyshareInfo.ownerIdentifiers.length}) does not match signing operator count (${Object.keys(signingOperators).length})`,
29440
- {
29441
- keyshareInfo: keyshareInfo.ownerIdentifiers.length,
29442
- signingOperators: Object.keys(signingOperators).length
29443
- }
29444
- );
29445
- }
29446
- if (hasDuplicates(keyshareInfo.ownerIdentifiers)) {
29447
- throw new InternalValidationError(
29448
- "Duplicate ownerIdentifiers found in keyshareInfo",
29449
- {
29450
- keyshareInfo: keyshareInfo.ownerIdentifiers
29451
- }
29452
- );
29453
- }
29454
- for (const identifier of keyshareInfo.ownerIdentifiers) {
29455
- if (!signingOperators[identifier]) {
29456
- throw new InternalValidationError(
29457
- `Keyshare operator ${identifier} not found in signing operator list`,
29458
- {
29459
- keyshareInfo: identifier,
29460
- signingOperators: Object.keys(signingOperators)
29461
- }
29462
- );
29463
- }
29464
- }
29465
- }
29466
29495
  function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
29467
29496
  if (finalTokenTransaction.network !== partialTokenTransaction.network) {
29468
29497
  throw new InternalValidationError(
@@ -29864,16 +29893,6 @@ var TokenTransactionService = class {
29864
29893
  tokenIdentifier,
29865
29894
  this.config.getNetworkType()
29866
29895
  ).tokenIdentifier;
29867
- let tokenPublicKey;
29868
- if (this.config.getTokenTransactionVersion() === "V0") {
29869
- const tokenClient = await this.connectionManager.createSparkTokenClient(
29870
- this.config.getCoordinatorAddress()
29871
- );
29872
- const tokenMetadata = await tokenClient.query_token_metadata({
29873
- tokenIdentifiers: [rawTokenIdentifier]
29874
- });
29875
- tokenPublicKey = tokenMetadata.tokenMetadata[0].issuerPublicKey;
29876
- }
29877
29896
  let sparkInvoices = [];
29878
29897
  const tokenOutputData = receiverOutputs.map((transfer) => {
29879
29898
  const receiverAddress = decodeSparkAddress(
@@ -29883,7 +29902,7 @@ var TokenTransactionService = class {
29883
29902
  if (receiverAddress.sparkInvoiceFields) {
29884
29903
  sparkInvoices.push(transfer.receiverSparkAddress);
29885
29904
  }
29886
- if (this.config.getTokenTransactionVersion() !== "V0" && receiverAddress.sparkInvoiceFields) {
29905
+ if (receiverAddress.sparkInvoiceFields) {
29887
29906
  return {
29888
29907
  receiverPublicKey: (0, import_utils17.hexToBytes)(receiverAddress.identityPublicKey),
29889
29908
  rawTokenIdentifier,
@@ -29894,24 +29913,14 @@ var TokenTransactionService = class {
29894
29913
  return {
29895
29914
  receiverPublicKey: (0, import_utils17.hexToBytes)(receiverAddress.identityPublicKey),
29896
29915
  rawTokenIdentifier,
29897
- tokenPublicKey,
29898
- // Remove for full v0 deprecation
29899
29916
  tokenAmount: transfer.tokenAmount
29900
29917
  };
29901
29918
  });
29902
- let tokenTransaction;
29903
- if (this.config.getTokenTransactionVersion() === "V0") {
29904
- tokenTransaction = await this.constructTransferTokenTransactionV0(
29905
- outputsToUse,
29906
- tokenOutputData
29907
- );
29908
- } else {
29909
- tokenTransaction = await this.constructTransferTokenTransaction(
29910
- outputsToUse,
29911
- tokenOutputData,
29912
- sparkInvoices
29913
- );
29914
- }
29919
+ const tokenTransaction = await this.constructTransferTokenTransaction(
29920
+ outputsToUse,
29921
+ tokenOutputData,
29922
+ sparkInvoices
29923
+ );
29915
29924
  const txId = await this.broadcastTokenTransaction(
29916
29925
  tokenTransaction,
29917
29926
  outputsToUse.map((output) => output.output.ownerPublicKey),
@@ -29919,44 +29928,6 @@ var TokenTransactionService = class {
29919
29928
  );
29920
29929
  return txId;
29921
29930
  }
29922
- async constructTransferTokenTransactionV0(selectedOutputs, tokenOutputData) {
29923
- selectedOutputs.sort(
29924
- (a, b) => a.previousTransactionVout - b.previousTransactionVout
29925
- );
29926
- const availableTokenAmount = sumAvailableTokens(selectedOutputs);
29927
- const totalRequestedAmount = tokenOutputData.reduce(
29928
- (sum, output) => sum + output.tokenAmount,
29929
- 0n
29930
- );
29931
- const tokenOutputs = tokenOutputData.map((output) => ({
29932
- ownerPublicKey: output.receiverPublicKey,
29933
- tokenPublicKey: output.tokenPublicKey,
29934
- tokenAmount: (0, import_utils16.numberToBytesBE)(output.tokenAmount, 16)
29935
- }));
29936
- if (availableTokenAmount > totalRequestedAmount) {
29937
- const changeAmount = availableTokenAmount - totalRequestedAmount;
29938
- const firstTokenPublicKey = tokenOutputData[0].tokenPublicKey;
29939
- tokenOutputs.push({
29940
- ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
29941
- tokenPublicKey: firstTokenPublicKey,
29942
- tokenAmount: (0, import_utils16.numberToBytesBE)(changeAmount, 16)
29943
- });
29944
- }
29945
- return {
29946
- network: this.config.getNetworkProto(),
29947
- tokenInputs: {
29948
- $case: "transferInput",
29949
- transferInput: {
29950
- outputsToSpend: selectedOutputs.map((output) => ({
29951
- prevTokenTransactionHash: output.previousTransactionHash,
29952
- prevTokenTransactionVout: output.previousTransactionVout
29953
- }))
29954
- }
29955
- },
29956
- tokenOutputs,
29957
- sparkOperatorIdentityPublicKeys: this.collectOperatorIdentityPublicKeys()
29958
- };
29959
- }
29960
29931
  async constructTransferTokenTransaction(selectedOutputs, tokenOutputData, sparkInvoices) {
29961
29932
  selectedOutputs.sort(
29962
29933
  (a, b) => a.previousTransactionVout - b.previousTransactionVout
@@ -30012,113 +29983,6 @@ var TokenTransactionService = class {
30012
29983
  }
30013
29984
  async broadcastTokenTransaction(tokenTransaction, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30014
29985
  const signingOperators = this.config.getSigningOperators();
30015
- if (!isTokenTransaction(tokenTransaction)) {
30016
- return this.broadcastTokenTransactionV0(
30017
- tokenTransaction,
30018
- signingOperators,
30019
- outputsToSpendSigningPublicKeys,
30020
- outputsToSpendCommitments
30021
- );
30022
- } else {
30023
- return this.broadcastTokenTransactionV1(
30024
- tokenTransaction,
30025
- signingOperators,
30026
- outputsToSpendSigningPublicKeys,
30027
- outputsToSpendCommitments
30028
- );
30029
- }
30030
- }
30031
- async broadcastTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30032
- const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransactionV0(
30033
- tokenTransaction,
30034
- signingOperators,
30035
- outputsToSpendSigningPublicKeys,
30036
- outputsToSpendCommitments
30037
- );
30038
- const { successfulSignatures } = await this.signTokenTransactionV0(
30039
- finalTokenTransaction,
30040
- finalTokenTransactionHash,
30041
- signingOperators
30042
- );
30043
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
30044
- const outputsToSpend = finalTokenTransaction.tokenInputs.transferInput.outputsToSpend;
30045
- const errors = [];
30046
- const revocationSecrets = [];
30047
- for (let outputIndex = 0; outputIndex < outputsToSpend.length; outputIndex++) {
30048
- const outputKeyshares = successfulSignatures.map(({ identifier, response }) => ({
30049
- operatorIndex: parseInt(identifier, 16),
30050
- keyshare: response.revocationKeyshares[outputIndex]
30051
- }));
30052
- if (outputKeyshares.length < threshold) {
30053
- errors.push(
30054
- new ValidationError("Insufficient keyshares", {
30055
- field: "outputKeyshares",
30056
- value: outputKeyshares.length,
30057
- expected: threshold,
30058
- index: outputIndex
30059
- })
30060
- );
30061
- }
30062
- const seenIndices = /* @__PURE__ */ new Set();
30063
- for (const { operatorIndex } of outputKeyshares) {
30064
- if (seenIndices.has(operatorIndex)) {
30065
- errors.push(
30066
- new ValidationError("Duplicate operator index", {
30067
- field: "outputKeyshares",
30068
- value: operatorIndex,
30069
- expected: "Unique operator index",
30070
- index: outputIndex
30071
- })
30072
- );
30073
- }
30074
- seenIndices.add(operatorIndex);
30075
- }
30076
- const revocationSecret = recoverRevocationSecretFromKeyshares(
30077
- outputKeyshares,
30078
- threshold
30079
- );
30080
- const derivedRevocationCommitment = import_secp256k112.secp256k1.getPublicKey(
30081
- revocationSecret,
30082
- true
30083
- );
30084
- if (!outputsToSpendCommitments || !outputsToSpendCommitments[outputIndex] || !derivedRevocationCommitment.every(
30085
- (byte, i) => byte === outputsToSpendCommitments[outputIndex][i]
30086
- )) {
30087
- errors.push(
30088
- new InternalValidationError(
30089
- "Revocation commitment verification failed",
30090
- {
30091
- field: "revocationCommitment",
30092
- value: derivedRevocationCommitment,
30093
- expected: (0, import_utils16.bytesToHex)(outputsToSpendCommitments[outputIndex]),
30094
- outputIndex
30095
- }
30096
- )
30097
- );
30098
- }
30099
- revocationSecrets.push({
30100
- inputIndex: outputIndex,
30101
- revocationSecret
30102
- });
30103
- }
30104
- if (errors.length > 0) {
30105
- throw new ValidationError(
30106
- "Multiple validation errors occurred across outputs",
30107
- {
30108
- field: "outputValidation",
30109
- value: errors
30110
- }
30111
- );
30112
- }
30113
- await this.finalizeTokenTransaction(
30114
- finalTokenTransaction,
30115
- revocationSecrets,
30116
- threshold
30117
- );
30118
- }
30119
- return (0, import_utils16.bytesToHex)(finalTokenTransactionHash);
30120
- }
30121
- async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30122
29986
  const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
30123
29987
  tokenTransaction,
30124
29988
  signingOperators,
@@ -30132,101 +29996,6 @@ var TokenTransactionService = class {
30132
29996
  );
30133
29997
  return (0, import_utils16.bytesToHex)(finalTokenTransactionHash);
30134
29998
  }
30135
- async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30136
- const sparkClient = await this.connectionManager.createSparkClient(
30137
- this.config.getCoordinatorAddress()
30138
- );
30139
- const partialTokenTransactionHash = hashTokenTransactionV0(
30140
- tokenTransaction,
30141
- true
30142
- );
30143
- const ownerSignaturesWithIndex = [];
30144
- if (tokenTransaction.tokenInputs.$case === "mintInput") {
30145
- const issuerPublicKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
30146
- if (!issuerPublicKey) {
30147
- throw new ValidationError("Invalid mint input", {
30148
- field: "issuerPublicKey",
30149
- value: null,
30150
- expected: "Non-null issuer public key"
30151
- });
30152
- }
30153
- const ownerSignature = await this.signMessageWithKey(
30154
- partialTokenTransactionHash,
30155
- issuerPublicKey
30156
- );
30157
- ownerSignaturesWithIndex.push({
30158
- signature: ownerSignature,
30159
- inputIndex: 0
30160
- });
30161
- } else if (tokenTransaction.tokenInputs.$case === "transferInput") {
30162
- if (!outputsToSpendSigningPublicKeys || !outputsToSpendCommitments) {
30163
- throw new ValidationError("Invalid transfer input", {
30164
- field: "outputsToSpend",
30165
- value: {
30166
- signingPublicKeys: outputsToSpendSigningPublicKeys,
30167
- revocationPublicKeys: outputsToSpendCommitments
30168
- },
30169
- expected: "Non-null signing and revocation public keys"
30170
- });
30171
- }
30172
- for (const [i, key] of outputsToSpendSigningPublicKeys.entries()) {
30173
- if (!key) {
30174
- throw new ValidationError("Invalid signing key", {
30175
- field: "outputsToSpendSigningPublicKeys",
30176
- value: i,
30177
- expected: "Non-null signing key"
30178
- });
30179
- }
30180
- const ownerSignature = await this.signMessageWithKey(
30181
- partialTokenTransactionHash,
30182
- key
30183
- );
30184
- ownerSignaturesWithIndex.push({
30185
- signature: ownerSignature,
30186
- inputIndex: i
30187
- });
30188
- }
30189
- }
30190
- const startResponse = await sparkClient.start_token_transaction(
30191
- {
30192
- identityPublicKey: await this.config.signer.getIdentityPublicKey(),
30193
- partialTokenTransaction: tokenTransaction,
30194
- tokenTransactionSignatures: {
30195
- ownerSignatures: ownerSignaturesWithIndex
30196
- }
30197
- },
30198
- {
30199
- retry: true,
30200
- retryableStatuses: ["UNKNOWN", "UNAVAILABLE", "CANCELLED", "INTERNAL"],
30201
- retryMaxAttempts: 3
30202
- }
30203
- );
30204
- if (!startResponse.finalTokenTransaction) {
30205
- throw new Error("Final token transaction missing in start response");
30206
- }
30207
- if (!startResponse.keyshareInfo) {
30208
- throw new Error("Keyshare info missing in start response");
30209
- }
30210
- validateTokenTransactionV0(
30211
- startResponse.finalTokenTransaction,
30212
- tokenTransaction,
30213
- signingOperators,
30214
- startResponse.keyshareInfo,
30215
- this.config.getExpectedWithdrawBondSats(),
30216
- this.config.getExpectedWithdrawRelativeBlockLocktime(),
30217
- this.config.getThreshold()
30218
- );
30219
- const finalTokenTransaction = startResponse.finalTokenTransaction;
30220
- const finalTokenTransactionHash = hashTokenTransactionV0(
30221
- finalTokenTransaction,
30222
- false
30223
- );
30224
- return {
30225
- finalTokenTransaction,
30226
- finalTokenTransactionHash,
30227
- threshold: startResponse.keyshareInfo.threshold
30228
- };
30229
- }
30230
29999
  async startTokenTransaction(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30231
30000
  const sparkClient = await this.connectionManager.createSparkTokenClient(
30232
30001
  this.config.getCoordinatorAddress()
@@ -30346,103 +30115,6 @@ var TokenTransactionService = class {
30346
30115
  threshold: startResponse.keyshareInfo.threshold
30347
30116
  };
30348
30117
  }
30349
- async signTokenTransactionV0(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
30350
- const soSignatures = await Promise.allSettled(
30351
- Object.entries(signingOperators).map(
30352
- async ([identifier, operator], index) => {
30353
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
30354
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
30355
- const payload = {
30356
- finalTokenTransactionHash,
30357
- operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
30358
- };
30359
- const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
30360
- let operatorSpecificSignatures = [];
30361
- if (finalTokenTransaction.tokenInputs.$case === "mintInput") {
30362
- const issuerPublicKey = finalTokenTransaction.tokenInputs.mintInput.issuerPublicKey;
30363
- if (!issuerPublicKey) {
30364
- throw new ValidationError("Invalid mint input", {
30365
- field: "issuerPublicKey",
30366
- value: null,
30367
- expected: "Non-null issuer public key"
30368
- });
30369
- }
30370
- const ownerSignature = await this.signMessageWithKey(
30371
- payloadHash,
30372
- issuerPublicKey
30373
- );
30374
- operatorSpecificSignatures.push({
30375
- ownerSignature: {
30376
- signature: ownerSignature,
30377
- inputIndex: 0
30378
- },
30379
- payload
30380
- });
30381
- }
30382
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
30383
- const transferInput = finalTokenTransaction.tokenInputs.transferInput;
30384
- for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
30385
- let ownerSignature;
30386
- if (this.config.getTokenSignatures() === "SCHNORR") {
30387
- ownerSignature = await this.config.signer.signSchnorrWithIdentityKey(
30388
- payloadHash
30389
- );
30390
- } else {
30391
- ownerSignature = await this.config.signer.signMessageWithIdentityKey(
30392
- payloadHash
30393
- );
30394
- }
30395
- operatorSpecificSignatures.push({
30396
- ownerSignature: {
30397
- signature: ownerSignature,
30398
- inputIndex: i
30399
- },
30400
- payload
30401
- });
30402
- }
30403
- }
30404
- try {
30405
- const response = await internalSparkClient.sign_token_transaction(
30406
- {
30407
- finalTokenTransaction,
30408
- operatorSpecificSignatures,
30409
- identityPublicKey
30410
- },
30411
- {
30412
- retry: true,
30413
- retryableStatuses: [
30414
- "UNKNOWN",
30415
- "UNAVAILABLE",
30416
- "CANCELLED",
30417
- "INTERNAL"
30418
- ],
30419
- retryMaxAttempts: 3
30420
- }
30421
- );
30422
- return {
30423
- index,
30424
- identifier,
30425
- response
30426
- };
30427
- } catch (error) {
30428
- throw new NetworkError(
30429
- "Failed to sign token transaction",
30430
- {
30431
- operation: "sign_token_transaction",
30432
- errorCount: 1,
30433
- errors: error instanceof Error ? error.message : String(error)
30434
- },
30435
- error
30436
- );
30437
- }
30438
- }
30439
- )
30440
- );
30441
- const successfulSignatures = collectResponses(soSignatures);
30442
- return {
30443
- successfulSignatures
30444
- };
30445
- }
30446
30118
  async signTokenTransaction(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
30447
30119
  const coordinatorClient = await this.connectionManager.createSparkTokenClient(
30448
30120
  this.config.getCoordinatorAddress()
@@ -30514,54 +30186,6 @@ var TokenTransactionService = class {
30514
30186
  );
30515
30187
  }
30516
30188
  }
30517
- if (this.config.getTokenTransactionVersion() === "V0") {
30518
- return this.fetchOwnedTokenOutputsV0(params);
30519
- } else {
30520
- return this.fetchOwnedTokenOutputsV1(params);
30521
- }
30522
- }
30523
- async queryTokenTransactions(params) {
30524
- if (this.config.getTokenTransactionVersion() === "V0") {
30525
- return this.queryTokenTransactionsV0(params);
30526
- } else {
30527
- return this.queryTokenTransactionsV1(params);
30528
- }
30529
- }
30530
- async fetchOwnedTokenOutputsV0(params) {
30531
- const {
30532
- ownerPublicKeys,
30533
- issuerPublicKeys: tokenPublicKeys = [],
30534
- tokenIdentifiers = []
30535
- } = params;
30536
- const sparkClient = await this.connectionManager.createSparkClient(
30537
- this.config.getCoordinatorAddress()
30538
- );
30539
- try {
30540
- const result = await sparkClient.query_token_outputs({
30541
- ownerPublicKeys,
30542
- tokenPublicKeys,
30543
- tokenIdentifiers,
30544
- network: this.config.getNetworkProto()
30545
- });
30546
- return result.outputsWithPreviousTransactionData;
30547
- } catch (error) {
30548
- throw new NetworkError(
30549
- "Failed to fetch owned token outputs",
30550
- {
30551
- operation: "spark.query_token_outputs",
30552
- errorCount: 1,
30553
- errors: error instanceof Error ? error.message : String(error)
30554
- },
30555
- error
30556
- );
30557
- }
30558
- }
30559
- async fetchOwnedTokenOutputsV1(params) {
30560
- const {
30561
- ownerPublicKeys,
30562
- issuerPublicKeys = [],
30563
- tokenIdentifiers = []
30564
- } = params;
30565
30189
  const tokenClient = await this.connectionManager.createSparkTokenClient(
30566
30190
  this.config.getCoordinatorAddress()
30567
30191
  );
@@ -30602,75 +30226,7 @@ var TokenTransactionService = class {
30602
30226
  );
30603
30227
  }
30604
30228
  }
30605
- async queryTokenTransactionsV0(params) {
30606
- const {
30607
- ownerPublicKeys,
30608
- issuerPublicKeys,
30609
- tokenTransactionHashes,
30610
- tokenIdentifiers,
30611
- outputIds,
30612
- pageSize,
30613
- offset
30614
- } = params;
30615
- const sparkClient = await this.connectionManager.createSparkClient(
30616
- this.config.getCoordinatorAddress()
30617
- );
30618
- let queryParams = {
30619
- tokenPublicKeys: issuerPublicKeys?.map(import_utils17.hexToBytes),
30620
- ownerPublicKeys: ownerPublicKeys?.map(import_utils17.hexToBytes),
30621
- tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
30622
- const { tokenIdentifier } = decodeBech32mTokenIdentifier(
30623
- identifier,
30624
- this.config.getNetworkType()
30625
- );
30626
- return tokenIdentifier;
30627
- }),
30628
- tokenTransactionHashes: tokenTransactionHashes?.map(import_utils17.hexToBytes),
30629
- outputIds: outputIds || [],
30630
- limit: pageSize,
30631
- offset
30632
- };
30633
- try {
30634
- const response = await sparkClient.query_token_transactions(queryParams);
30635
- return {
30636
- tokenTransactionsWithStatus: response.tokenTransactionsWithStatus.map(
30637
- (tx) => {
30638
- const v1TokenTransaction = {
30639
- version: 1,
30640
- network: tx.tokenTransaction.network,
30641
- tokenInputs: tx.tokenTransaction.tokenInputs,
30642
- tokenOutputs: tx.tokenTransaction.tokenOutputs,
30643
- sparkOperatorIdentityPublicKeys: tx.tokenTransaction.sparkOperatorIdentityPublicKeys,
30644
- expiryTime: void 0,
30645
- // V0 doesn't have expiry time
30646
- clientCreatedTimestamp: tx.tokenTransaction?.tokenInputs?.$case === "mintInput" ? new Date(
30647
- tx.tokenTransaction.tokenInputs.mintInput.issuerProvidedTimestamp * 1e3
30648
- ) : /* @__PURE__ */ new Date(),
30649
- invoiceAttachments: []
30650
- };
30651
- return {
30652
- tokenTransaction: v1TokenTransaction,
30653
- status: tx.status,
30654
- confirmationMetadata: tx.confirmationMetadata,
30655
- tokenTransactionHash: tx.tokenTransactionHash
30656
- };
30657
- }
30658
- ),
30659
- offset: response.offset
30660
- };
30661
- } catch (error) {
30662
- throw new NetworkError(
30663
- "Failed to query token transactions",
30664
- {
30665
- operation: "spark.query_token_transactions",
30666
- errorCount: 1,
30667
- errors: error instanceof Error ? error.message : String(error)
30668
- },
30669
- error
30670
- );
30671
- }
30672
- }
30673
- async queryTokenTransactionsV1(params) {
30229
+ async queryTokenTransactions(params) {
30674
30230
  const {
30675
30231
  ownerPublicKeys,
30676
30232
  issuerPublicKeys,
@@ -30783,50 +30339,6 @@ var TokenTransactionService = class {
30783
30339
  });
30784
30340
  }
30785
30341
  }
30786
- async finalizeTokenTransaction(finalTokenTransaction, revocationSecrets, threshold) {
30787
- const signingOperators = this.config.getSigningOperators();
30788
- const soResponses = await Promise.allSettled(
30789
- Object.entries(signingOperators).map(async ([identifier, operator]) => {
30790
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
30791
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
30792
- try {
30793
- const response = await internalSparkClient.finalize_token_transaction(
30794
- {
30795
- finalTokenTransaction,
30796
- revocationSecrets,
30797
- identityPublicKey
30798
- },
30799
- {
30800
- retry: true,
30801
- retryableStatuses: [
30802
- "UNKNOWN",
30803
- "UNAVAILABLE",
30804
- "CANCELLED",
30805
- "INTERNAL"
30806
- ],
30807
- retryMaxAttempts: 3
30808
- }
30809
- );
30810
- return {
30811
- identifier,
30812
- response
30813
- };
30814
- } catch (error) {
30815
- throw new NetworkError(
30816
- "Failed to finalize token transaction",
30817
- {
30818
- operation: "finalize_token_transaction",
30819
- errorCount: 1,
30820
- errors: error instanceof Error ? error.message : String(error)
30821
- },
30822
- error
30823
- );
30824
- }
30825
- })
30826
- );
30827
- collectResponses(soResponses);
30828
- return finalTokenTransaction;
30829
- }
30830
30342
  async createSignaturesForOperators(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
30831
30343
  const inputTtxoSignaturesPerOperator = [];
30832
30344
  for (const [_, operator] of Object.entries(signingOperators)) {
@@ -30903,29 +30415,26 @@ var TokenTransactionService = class {
30903
30415
  return inputTtxoSignaturesPerOperator;
30904
30416
  }
30905
30417
  };
30906
- function isTokenTransaction(tokenTransaction) {
30907
- return "version" in tokenTransaction && "expiryTime" in tokenTransaction;
30908
- }
30909
30418
 
30910
30419
  // src/utils/adaptor-signature.ts
30911
30420
  init_buffer();
30912
30421
  var import_modular = require("@noble/curves/abstract/modular");
30913
- var import_secp256k113 = require("@noble/curves/secp256k1");
30422
+ var import_secp256k111 = require("@noble/curves/secp256k1");
30914
30423
  var import_utils18 = require("@noble/curves/utils");
30915
30424
  function generateSignatureFromExistingAdaptor(signature, adaptorPrivateKeyBytes) {
30916
30425
  const { r, s: s2 } = parseSignature(signature);
30917
30426
  const sBigInt = (0, import_utils18.bytesToNumberBE)(s2);
30918
30427
  const tBigInt = (0, import_utils18.bytesToNumberBE)(adaptorPrivateKeyBytes);
30919
- const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k113.secp256k1.CURVE.n);
30428
+ const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k111.secp256k1.CURVE.n);
30920
30429
  const newSignature = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(newS, 32)]);
30921
30430
  return newSignature;
30922
30431
  }
30923
30432
  function generateAdaptorFromSignature(signature) {
30924
- const adaptorPrivateKey = import_secp256k113.secp256k1.utils.randomPrivateKey();
30433
+ const adaptorPrivateKey = import_secp256k111.secp256k1.utils.randomPrivateKey();
30925
30434
  const { r, s: s2 } = parseSignature(signature);
30926
30435
  const sBigInt = (0, import_utils18.bytesToNumberBE)(s2);
30927
30436
  const tBigInt = (0, import_utils18.bytesToNumberBE)(adaptorPrivateKey);
30928
- const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k113.secp256k1.CURVE.n);
30437
+ const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k111.secp256k1.CURVE.n);
30929
30438
  const newSignature = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(newS, 32)]);
30930
30439
  return {
30931
30440
  adaptorSignature: newSignature,
@@ -30945,19 +30454,19 @@ function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes
30945
30454
  const { r, s: s2 } = parseSignature(signature);
30946
30455
  const sBigInt = (0, import_utils18.bytesToNumberBE)(s2);
30947
30456
  const adaptorPrivateKey = (0, import_utils18.bytesToNumberBE)(adaptorPrivateKeyBytes);
30948
- const newS = (0, import_modular.mod)(sBigInt + adaptorPrivateKey, import_secp256k113.secp256k1.CURVE.n);
30457
+ const newS = (0, import_modular.mod)(sBigInt + adaptorPrivateKey, import_secp256k111.secp256k1.CURVE.n);
30949
30458
  const newSig = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(newS, 32)]);
30950
30459
  try {
30951
- if (import_secp256k113.schnorr.verify(newSig, hash, pubkey)) {
30460
+ if (import_secp256k111.schnorr.verify(newSig, hash, pubkey)) {
30952
30461
  return newSig;
30953
30462
  }
30954
30463
  } catch (e) {
30955
30464
  console.error("[applyAdaptorToSignature] Addition verification failed:", e);
30956
30465
  }
30957
- const altS = (0, import_modular.mod)(sBigInt - adaptorPrivateKey, import_secp256k113.secp256k1.CURVE.n);
30466
+ const altS = (0, import_modular.mod)(sBigInt - adaptorPrivateKey, import_secp256k111.secp256k1.CURVE.n);
30958
30467
  const altSig = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(altS, 32)]);
30959
30468
  try {
30960
- if (import_secp256k113.schnorr.verify(altSig, hash, pubkey)) {
30469
+ if (import_secp256k111.schnorr.verify(altSig, hash, pubkey)) {
30961
30470
  return altSig;
30962
30471
  }
30963
30472
  } catch (e) {
@@ -30972,10 +30481,10 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
30972
30481
  if (hash.length !== 32) {
30973
30482
  throw new Error(`wrong size for message (got ${hash.length}, want 32)`);
30974
30483
  }
30975
- const pubKey = import_secp256k113.schnorr.utils.lift_x((0, import_utils18.bytesToNumberBE)(pubKeyBytes));
30484
+ const pubKey = import_secp256k111.schnorr.utils.lift_x((0, import_utils18.bytesToNumberBE)(pubKeyBytes));
30976
30485
  pubKey.assertValidity();
30977
30486
  const { r, s: s2 } = parseSignature(signature);
30978
- const commitmenet = import_secp256k113.schnorr.utils.taggedHash(
30487
+ const commitmenet = import_secp256k111.schnorr.utils.taggedHash(
30979
30488
  "BIP0340/challenge",
30980
30489
  r,
30981
30490
  pubKey.toBytes().slice(1),
@@ -30984,18 +30493,18 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
30984
30493
  if (commitmenet.length > 32) {
30985
30494
  throw new Error("hash of (r || P || m) too big");
30986
30495
  }
30987
- const e = (0, import_modular.mod)((0, import_utils18.bytesToNumberBE)(commitmenet), import_secp256k113.secp256k1.CURVE.n);
30988
- const negE = (0, import_modular.mod)(-e, import_secp256k113.secp256k1.CURVE.n);
30989
- const sG = import_secp256k113.secp256k1.Point.BASE.multiplyUnsafe((0, import_utils18.bytesToNumberBE)(s2));
30496
+ const e = (0, import_modular.mod)((0, import_utils18.bytesToNumberBE)(commitmenet), import_secp256k111.secp256k1.CURVE.n);
30497
+ const negE = (0, import_modular.mod)(-e, import_secp256k111.secp256k1.CURVE.n);
30498
+ const sG = import_secp256k111.secp256k1.Point.BASE.multiplyUnsafe((0, import_utils18.bytesToNumberBE)(s2));
30990
30499
  const eP = pubKey.multiplyUnsafe(negE);
30991
30500
  const R = sG.add(eP);
30992
30501
  if (R.is0()) {
30993
30502
  throw new Error("R is zero");
30994
30503
  }
30995
30504
  R.assertValidity();
30996
- const adaptorPoint = import_secp256k113.secp256k1.Point.fromHex(adaptorPubkey);
30505
+ const adaptorPoint = import_secp256k111.secp256k1.Point.fromHex(adaptorPubkey);
30997
30506
  const newR = R.add(adaptorPoint);
30998
- if (!inbound && newR.equals(import_secp256k113.secp256k1.Point.ZERO)) {
30507
+ if (!inbound && newR.equals(import_secp256k111.secp256k1.Point.ZERO)) {
30999
30508
  throw new Error("calculated R point is the point at infinity");
31000
30509
  }
31001
30510
  newR.assertValidity();
@@ -31023,16 +30532,16 @@ function parseSignature(signature) {
31023
30532
  }
31024
30533
  const r = signature.slice(0, 32);
31025
30534
  const s2 = signature.slice(32, 64);
31026
- if ((0, import_utils18.bytesToNumberBE)(r) >= import_secp256k113.secp256k1.CURVE.Fp.ORDER) {
30535
+ if ((0, import_utils18.bytesToNumberBE)(r) >= import_secp256k111.secp256k1.CURVE.Fp.ORDER) {
31027
30536
  throw new ValidationError("Invalid signature: r >= field prime", {
31028
30537
  rValue: (0, import_utils18.bytesToNumberBE)(r),
31029
- fieldPrime: import_secp256k113.secp256k1.CURVE.Fp.ORDER
30538
+ fieldPrime: import_secp256k111.secp256k1.CURVE.Fp.ORDER
31030
30539
  });
31031
30540
  }
31032
- if ((0, import_utils18.bytesToNumberBE)(s2) >= import_secp256k113.secp256k1.CURVE.n) {
30541
+ if ((0, import_utils18.bytesToNumberBE)(s2) >= import_secp256k111.secp256k1.CURVE.n) {
31033
30542
  throw new ValidationError("Invalid signature: s >= group order", {
31034
30543
  sValue: (0, import_utils18.bytesToNumberBE)(s2),
31035
- groupOrder: import_secp256k113.secp256k1.CURVE.n
30544
+ groupOrder: import_secp256k111.secp256k1.CURVE.n
31036
30545
  });
31037
30546
  }
31038
30547
  return { r, s: s2 };
@@ -31213,7 +30722,7 @@ var SigningService = class {
31213
30722
 
31214
30723
  // src/tests/utils/test-faucet.ts
31215
30724
  init_buffer();
31216
- var import_secp256k114 = require("@noble/curves/secp256k1");
30725
+ var import_secp256k112 = require("@noble/curves/secp256k1");
31217
30726
  var import_utils20 = require("@noble/curves/utils");
31218
30727
  var btc3 = __toESM(require("@scure/btc-signer"), 1);
31219
30728
  var import_btc_signer5 = require("@scure/btc-signer");
@@ -31234,7 +30743,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31234
30743
  this.username = username;
31235
30744
  this.password = password;
31236
30745
  this.miningAddress = getP2TRAddressFromPublicKey(
31237
- import_secp256k114.secp256k1.getPublicKey(STATIC_MINING_KEY),
30746
+ import_secp256k112.secp256k1.getPublicKey(STATIC_MINING_KEY),
31238
30747
  4 /* LOCAL */
31239
30748
  );
31240
30749
  }
@@ -31273,7 +30782,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31273
30782
  });
31274
30783
  }
31275
30784
  async refill() {
31276
- const minerPubKey = import_secp256k114.secp256k1.getPublicKey(STATIC_MINING_KEY);
30785
+ const minerPubKey = import_secp256k112.secp256k1.getPublicKey(STATIC_MINING_KEY);
31277
30786
  const address2 = getP2TRAddressFromPublicKey(minerPubKey, 4 /* LOCAL */);
31278
30787
  const scanResult = await this.call("scantxoutset", [
31279
30788
  "start",
@@ -31322,7 +30831,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31322
30831
  txid: selectedUtxo.txid,
31323
30832
  index: selectedUtxo.vout
31324
30833
  });
31325
- const faucetPubKey = import_secp256k114.secp256k1.getPublicKey(STATIC_FAUCET_KEY);
30834
+ const faucetPubKey = import_secp256k112.secp256k1.getPublicKey(STATIC_FAUCET_KEY);
31326
30835
  const script = getP2TRScriptFromPublicKey(faucetPubKey, 4 /* LOCAL */);
31327
30836
  for (let i = 0; i < numCoinsToCreate; i++) {
31328
30837
  splitTx.addOutput({
@@ -31383,7 +30892,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31383
30892
  await this.broadcastTx((0, import_utils20.bytesToHex)(signedTx.extract()));
31384
30893
  }
31385
30894
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
31386
- const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
30895
+ const pubKey = import_secp256k112.secp256k1.getPublicKey(key);
31387
30896
  const internalKey = pubKey.slice(1);
31388
30897
  const script = getP2TRScriptFromPublicKey(pubKey, 4 /* LOCAL */);
31389
30898
  unsignedTx.updateInput(0, {
@@ -31403,7 +30912,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31403
30912
  const tweakedKey = (0, import_utils21.taprootTweakPrivKey)(key, merkleRoot);
31404
30913
  if (!tweakedKey)
31405
30914
  throw new Error("Invalid private key for taproot tweaking");
31406
- const signature = import_secp256k114.schnorr.sign(sighash, tweakedKey);
30915
+ const signature = import_secp256k112.schnorr.sign(sighash, tweakedKey);
31407
30916
  unsignedTx.updateInput(0, {
31408
30917
  tapKeySig: signature
31409
30918
  });
@@ -31466,8 +30975,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
31466
30975
  return response;
31467
30976
  }
31468
30977
  async getNewAddress() {
31469
- const key = import_secp256k114.secp256k1.utils.randomPrivateKey();
31470
- const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
30978
+ const key = import_secp256k112.secp256k1.utils.randomPrivateKey();
30979
+ const pubKey = import_secp256k112.secp256k1.getPublicKey(key);
31471
30980
  return getP2TRAddressFromPublicKey(pubKey, 4 /* LOCAL */);
31472
30981
  }
31473
30982
  async sendToAddress(address2, amount, blocksToGenerate = 1) {
@@ -31488,8 +30997,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
31488
30997
  });
31489
30998
  const changeAmount = availableAmount - amount;
31490
30999
  if (changeAmount > 0) {
31491
- const changeKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
31492
- const changePubKey = import_secp256k114.secp256k1.getPublicKey(changeKey);
31000
+ const changeKey = import_secp256k112.secp256k1.utils.randomPrivateKey();
31001
+ const changePubKey = import_secp256k112.secp256k1.getPublicKey(changeKey);
31493
31002
  const changeScript = getP2TRScriptFromPublicKey(
31494
31003
  changePubKey,
31495
31004
  4 /* LOCAL */
@@ -31502,8 +31011,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
31502
31011
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
31503
31012
  const txHex = (0, import_utils20.bytesToHex)(signedTx.extract());
31504
31013
  await this.broadcastTx(txHex);
31505
- const randomKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
31506
- const randomPubKey = import_secp256k114.secp256k1.getPublicKey(randomKey);
31014
+ const randomKey = import_secp256k112.secp256k1.utils.randomPrivateKey();
31015
+ const randomPubKey = import_secp256k112.secp256k1.getPublicKey(randomKey);
31507
31016
  const randomAddress = getP2TRAddressFromPublicKey(
31508
31017
  randomPubKey,
31509
31018
  4 /* LOCAL */
@@ -32170,47 +31679,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32170
31679
  senderPublicKey,
32171
31680
  expiryTime
32172
31681
  }) {
32173
- const MAX_SATS_AMOUNT = 21e14;
32174
- if (amount && (amount < 0 || amount > MAX_SATS_AMOUNT)) {
32175
- throw new ValidationError(
32176
- `Amount must be between 0 and ${MAX_SATS_AMOUNT} sats`,
32177
- {
32178
- field: "amount",
32179
- value: amount,
32180
- expected: `less than or equal to ${MAX_SATS_AMOUNT}`
32181
- }
32182
- );
32183
- }
32184
- const protoPayment = {
32185
- $case: "satsPayment",
32186
- satsPayment: {
32187
- amount
32188
- }
32189
- };
32190
- const invoiceFields = {
32191
- version: 1,
32192
- id: (0, import_uuidv75.uuidv7obj)().bytes,
32193
- paymentType: protoPayment,
32194
- memo,
32195
- senderPublicKey: senderPublicKey ? (0, import_utils23.hexToBytes)(senderPublicKey) : void 0,
32196
- expiryTime: expiryTime ?? void 0
32197
- };
32198
- validateSparkInvoiceFields(invoiceFields);
32199
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
32200
- const hash = HashSparkInvoice(
32201
- invoiceFields,
32202
- identityPublicKey,
32203
- this.config.getNetworkType()
32204
- );
32205
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
32206
- return encodeSparkAddressWithSignature(
32207
- {
32208
- identityPublicKey: (0, import_utils23.bytesToHex)(identityPublicKey),
32209
- network: this.config.getNetworkType(),
32210
- sparkInvoiceFields: invoiceFields
32211
- },
32212
- signature
32213
- );
31682
+ throw new NotImplementedError("Invoice functionality is not enabled");
32214
31683
  }
32215
31684
  /**
32216
31685
  * Creates a Spark invoice for a tokens payment on Spark.
@@ -32230,52 +31699,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32230
31699
  senderPublicKey,
32231
31700
  expiryTime
32232
31701
  }) {
32233
- const MAX_UINT128 = BigInt(2 ** 128 - 1);
32234
- if (amount && (amount < 0 || amount > MAX_UINT128)) {
32235
- throw new ValidationError(`Amount must be between 0 and ${MAX_UINT128}`, {
32236
- field: "amount",
32237
- value: amount,
32238
- expected: `greater than or equal to 0 and less than or equal to ${MAX_UINT128}`
32239
- });
32240
- }
32241
- let decodedTokenIdentifier = void 0;
32242
- if (tokenIdentifier) {
32243
- decodedTokenIdentifier = decodeBech32mTokenIdentifier(
32244
- tokenIdentifier,
32245
- this.config.getNetworkType()
32246
- ).tokenIdentifier;
32247
- }
32248
- const protoPayment = {
32249
- $case: "tokensPayment",
32250
- tokensPayment: {
32251
- tokenIdentifier: decodedTokenIdentifier ?? void 0,
32252
- amount: amount ? (0, import_utils23.numberToVarBytesBE)(amount) : void 0
32253
- }
32254
- };
32255
- const invoiceFields = {
32256
- version: 1,
32257
- id: (0, import_uuidv75.uuidv7obj)().bytes,
32258
- paymentType: protoPayment,
32259
- memo: memo ?? void 0,
32260
- senderPublicKey: senderPublicKey ? (0, import_utils23.hexToBytes)(senderPublicKey) : void 0,
32261
- expiryTime: expiryTime ?? void 0
32262
- };
32263
- validateSparkInvoiceFields(invoiceFields);
32264
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
32265
- const hash = HashSparkInvoice(
32266
- invoiceFields,
32267
- identityPublicKey,
32268
- this.config.getNetworkType()
32269
- );
32270
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
32271
- return encodeSparkAddressWithSignature(
32272
- {
32273
- identityPublicKey: (0, import_utils23.bytesToHex)(identityPublicKey),
32274
- network: this.config.getNetworkType(),
32275
- sparkInvoiceFields: invoiceFields
32276
- },
32277
- signature
32278
- );
31702
+ throw new NotImplementedError("Invoice functionality is not enabled");
32279
31703
  }
32280
31704
  /**
32281
31705
  * Initializes the wallet using either a mnemonic phrase or a raw seed.
@@ -32600,7 +32024,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32600
32024
  }
32601
32025
  const sspClient = this.getSspClient();
32602
32026
  const cpfpAdaptorPubkey = (0, import_utils23.bytesToHex)(
32603
- import_secp256k115.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
32027
+ import_secp256k113.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
32604
32028
  );
32605
32029
  if (!cpfpAdaptorPubkey) {
32606
32030
  throw new Error("Failed to generate CPFP adaptor pubkey");
@@ -32608,13 +32032,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32608
32032
  let directAdaptorPubkey;
32609
32033
  if (directAdaptorPrivateKey.length > 0) {
32610
32034
  directAdaptorPubkey = (0, import_utils23.bytesToHex)(
32611
- import_secp256k115.secp256k1.getPublicKey(directAdaptorPrivateKey)
32035
+ import_secp256k113.secp256k1.getPublicKey(directAdaptorPrivateKey)
32612
32036
  );
32613
32037
  }
32614
32038
  let directFromCpfpAdaptorPubkey;
32615
32039
  if (directFromCpfpAdaptorPrivateKey.length > 0) {
32616
32040
  directFromCpfpAdaptorPubkey = (0, import_utils23.bytesToHex)(
32617
- import_secp256k115.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
32041
+ import_secp256k113.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
32618
32042
  );
32619
32043
  }
32620
32044
  let request = null;
@@ -34229,10 +33653,23 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34229
33653
  if (!invoice2) {
34230
33654
  throw new Error("Failed to create lightning invoice");
34231
33655
  }
33656
+ const decodedInvoice = decodeInvoice(invoice2.invoice.encodedInvoice);
33657
+ if (invoice2.invoice.paymentHash !== (0, import_utils23.bytesToHex)(paymentHash) || decodedInvoice.paymentHash !== (0, import_utils23.bytesToHex)(paymentHash)) {
33658
+ throw new ValidationError("Payment hash mismatch", {
33659
+ field: "paymentHash",
33660
+ value: invoice2.invoice.paymentHash,
33661
+ expected: (0, import_utils23.bytesToHex)(paymentHash)
33662
+ });
33663
+ }
33664
+ if (decodedInvoice.amountMSats !== BigInt(amountSats2 * 1e3)) {
33665
+ throw new ValidationError("Amount mismatch", {
33666
+ field: "amountMSats",
33667
+ value: decodedInvoice.amountMSats,
33668
+ expected: amountSats2 * 1e3
33669
+ });
33670
+ }
34232
33671
  if (includeSparkAddress) {
34233
- const sparkFallbackAddress = decodeInvoice(
34234
- invoice2.invoice.encodedInvoice
34235
- ).fallbackAddress;
33672
+ const sparkFallbackAddress = decodedInvoice.fallbackAddress;
34236
33673
  if (!sparkFallbackAddress) {
34237
33674
  throw new ValidationError(
34238
33675
  "No spark fallback address found in lightning invoice",
@@ -34254,6 +33691,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34254
33691
  }
34255
33692
  );
34256
33693
  }
33694
+ } else if (decodedInvoice.fallbackAddress !== void 0) {
33695
+ throw new ValidationError(
33696
+ "Spark fallback address found in lightning invoice but includeSparkAddress is false",
33697
+ {
33698
+ field: "sparkFallbackAddress",
33699
+ value: decodedInvoice.fallbackAddress
33700
+ }
33701
+ );
34257
33702
  }
34258
33703
  return invoice2;
34259
33704
  };
@@ -34421,91 +33866,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34421
33866
  });
34422
33867
  }
34423
33868
  async fulfillSparkInvoice(sparkInvoices) {
34424
- if (!Array.isArray(sparkInvoices) || sparkInvoices.length === 0) {
34425
- throw new ValidationError("No Spark invoices provided", {
34426
- field: "sparkInvoices",
34427
- value: sparkInvoices,
34428
- expected: "Non-empty array"
34429
- });
34430
- }
34431
- const satsTransactionSuccess = [];
34432
- const satsTransactionErrors = [];
34433
- const tokenTransactionSuccess = [];
34434
- const tokenTransactionErrors = [];
34435
- const { satsInvoices, tokenInvoices, invalidInvoices } = await this.groupSparkInvoicesByPaymentType(sparkInvoices);
34436
- if (invalidInvoices.length > 0) {
34437
- return {
34438
- satsTransactionSuccess,
34439
- satsTransactionErrors,
34440
- tokenTransactionSuccess,
34441
- tokenTransactionErrors,
34442
- invalidInvoices
34443
- };
34444
- }
34445
- if (tokenInvoices.size > 0) {
34446
- await this.syncTokenOutputs();
34447
- const tokenTransferTasks = [];
34448
- for (const [identifierHex, decodedInvoices] of tokenInvoices.entries()) {
34449
- const tokenIdentifier = (0, import_utils23.hexToBytes)(identifierHex);
34450
- const tokenIdB32 = encodeBech32mTokenIdentifier({
34451
- tokenIdentifier,
34452
- network: this.config.getNetworkType()
34453
- });
34454
- const receiverOutputs = decodedInvoices.map((d) => ({
34455
- tokenIdentifier: tokenIdB32,
34456
- tokenAmount: d.amount,
34457
- receiverSparkAddress: d.invoice
34458
- }));
34459
- tokenTransferTasks.push(
34460
- this.tokenTransactionService.tokenTransfer({ tokenOutputs: this.tokenOutputs, receiverOutputs }).then((txid) => ({
34461
- ok: true,
34462
- tokenIdentifier: tokenIdB32,
34463
- txid
34464
- })).catch((e) => ({
34465
- ok: false,
34466
- tokenIdentifier: tokenIdB32,
34467
- error: e instanceof Error ? e : new Error(String(e))
34468
- }))
34469
- );
34470
- }
34471
- const results = await Promise.all(tokenTransferTasks);
34472
- for (const r of results) {
34473
- if (r.ok) {
34474
- tokenTransactionSuccess.push({
34475
- tokenIdentifier: r.tokenIdentifier,
34476
- txid: r.txid
34477
- });
34478
- } else {
34479
- tokenTransactionErrors.push({
34480
- tokenIdentifier: r.tokenIdentifier,
34481
- error: r.error
34482
- });
34483
- }
34484
- }
34485
- }
34486
- if (satsInvoices.length > 0) {
34487
- const transfers = await this.transferWithInvoice(satsInvoices);
34488
- for (const transfer of transfers) {
34489
- if (transfer.ok) {
34490
- satsTransactionSuccess.push({
34491
- invoice: transfer.param.sparkInvoice ?? "",
34492
- transferResponse: transfer.transfer
34493
- });
34494
- } else {
34495
- satsTransactionErrors.push({
34496
- invoice: transfer.param.sparkInvoice ?? "",
34497
- error: transfer.error
34498
- });
34499
- }
34500
- }
34501
- }
34502
- return {
34503
- satsTransactionSuccess,
34504
- satsTransactionErrors,
34505
- tokenTransactionSuccess,
34506
- tokenTransactionErrors,
34507
- invalidInvoices
34508
- };
33869
+ throw new NotImplementedError("Invoice functionality is not enabled");
34509
33870
  }
34510
33871
  async groupSparkInvoicesByPaymentType(sparkInvoices) {
34511
33872
  const satsInvoices = [];
@@ -34642,6 +34003,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34642
34003
  });
34643
34004
  return { satsInvoices, tokenInvoices, invalidInvoices };
34644
34005
  }
34006
+ async querySparkInvoices(invoices) {
34007
+ throw new NotImplementedError("Invoice functionality is not enabled");
34008
+ }
34645
34009
  /**
34646
34010
  * Gets fee estimate for sending Lightning payments.
34647
34011
  *
@@ -35674,6 +35038,7 @@ __export(utils_exports, {
35674
35038
  addPublicKeys: () => addPublicKeys,
35675
35039
  applyAdaptorToSignature: () => applyAdaptorToSignature,
35676
35040
  applyAdditiveTweakToPublicKey: () => applyAdditiveTweakToPublicKey,
35041
+ assertBech32: () => assertBech32,
35677
35042
  bech32mDecode: () => bech32mDecode,
35678
35043
  bigIntToPrivateKey: () => bigIntToPrivateKey,
35679
35044
  checkIfSelectedOutputsAreAvailable: () => checkIfSelectedOutputsAreAvailable,
@@ -35736,6 +35101,7 @@ __export(utils_exports, {
35736
35101
  getTxId: () => getTxId,
35737
35102
  getTxIdNoReverse: () => getTxIdNoReverse,
35738
35103
  isEphemeralAnchorOutput: () => isEphemeralAnchorOutput,
35104
+ isLegacySparkAddress: () => isLegacySparkAddress,
35739
35105
  isSafeForNumber: () => isSafeForNumber,
35740
35106
  isTxBroadcast: () => isTxBroadcast,
35741
35107
  isValidPublicKey: () => isValidPublicKey,
@@ -35813,6 +35179,28 @@ async function isTxBroadcast(txid, baseUrl, network) {
35813
35179
  return true;
35814
35180
  }
35815
35181
 
35182
+ // src/utils/response-validation.ts
35183
+ init_buffer();
35184
+ function collectResponses(responses) {
35185
+ const successfulResponses = responses.filter(
35186
+ (result) => result.status === "fulfilled"
35187
+ ).map((result) => result.value);
35188
+ const failedResponses = responses.filter(
35189
+ (result) => result.status === "rejected"
35190
+ );
35191
+ if (failedResponses.length > 0) {
35192
+ const errors = failedResponses.map((result) => result.reason).join("\n");
35193
+ throw new NetworkError(
35194
+ `${failedResponses.length} out of ${responses.length} requests failed, please try again`,
35195
+ {
35196
+ errorCount: failedResponses.length,
35197
+ errors
35198
+ }
35199
+ );
35200
+ }
35201
+ return successfulResponses;
35202
+ }
35203
+
35816
35204
  // src/utils/unilateral-exit.ts
35817
35205
  init_buffer();
35818
35206
  var import_utils24 = require("@noble/curves/utils");