@buildonspark/spark-sdk 0.3.3 → 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 (72) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/bare/index.cjs +938 -1401
  3. package/dist/bare/index.d.cts +128 -10
  4. package/dist/bare/index.d.ts +128 -10
  5. package/dist/bare/index.js +933 -1399
  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-SXXM52XH.js → chunk-KIQTO4FX.js} +405 -1659
  9. package/dist/{chunk-73GJOG5R.js → chunk-XWLR6G5C.js} +1 -1
  10. package/dist/{chunk-55XNR6DM.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 +942 -1403
  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 +898 -1362
  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 +898 -1362
  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-CGeEoKYd.d.cts → logging-BUpzk4Z6.d.cts} +3 -3
  28. package/dist/{logging-DpSsvFVM.d.ts → logging-Dt2ooQiP.d.ts} +3 -3
  29. package/dist/native/index.cjs +898 -1362
  30. package/dist/native/index.d.cts +129 -25
  31. package/dist/native/index.d.ts +129 -25
  32. package/dist/native/index.js +897 -1363
  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-BVBrWYKL.d.cts → spark-wallet-BoMIOPWW.d.cts} +13 -9
  43. package/dist/{spark-wallet-CFPm6wZs.d.ts → spark-wallet-jlC0XN5f.d.ts} +13 -9
  44. package/dist/{spark-wallet.node-e1gncoIZ.d.ts → spark-wallet.node-07PksUHH.d.cts} +1 -1
  45. package/dist/{spark-wallet.node-B_00X-1j.d.cts → spark-wallet.node-CdWkKMSq.d.ts} +1 -1
  46. package/dist/tests/test-utils.cjs +947 -144
  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-BkAqlmY6.d.ts → token-transactions-BDzCrQSk.d.cts} +5 -19
  51. package/dist/{token-transactions-BZGtwFFM.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/wallet-config.ts +0 -2
  61. package/src/spark-wallet/proto-descriptors.ts +1 -1
  62. package/src/spark-wallet/spark-wallet.ts +47 -215
  63. package/src/spark_descriptors.pb +0 -0
  64. package/src/tests/address.test.ts +141 -0
  65. package/src/tests/integration/address.test.ts +4 -0
  66. package/src/tests/integration/lightning.test.ts +14 -9
  67. package/src/tests/integration/token-output.test.ts +0 -1
  68. package/src/tests/integration/transfer.test.ts +108 -2
  69. package/src/tests/token-hashing.test.ts +0 -247
  70. package/src/utils/address.ts +58 -35
  71. package/src/utils/token-hashing.ts +1 -420
  72. package/src/utils/token-transaction-validation.ts +0 -330
@@ -1422,6 +1422,7 @@ __export(index_exports, {
1422
1422
  addPublicKeys: () => addPublicKeys,
1423
1423
  applyAdaptorToSignature: () => applyAdaptorToSignature,
1424
1424
  applyAdditiveTweakToPublicKey: () => applyAdditiveTweakToPublicKey,
1425
+ assertBech32: () => assertBech32,
1425
1426
  bech32mDecode: () => bech32mDecode,
1426
1427
  bigIntToPrivateKey: () => bigIntToPrivateKey,
1427
1428
  checkIfSelectedOutputsAreAvailable: () => checkIfSelectedOutputsAreAvailable,
@@ -1484,6 +1485,7 @@ __export(index_exports, {
1484
1485
  getTxId: () => getTxId,
1485
1486
  getTxIdNoReverse: () => getTxIdNoReverse,
1486
1487
  isEphemeralAnchorOutput: () => isEphemeralAnchorOutput,
1488
+ isLegacySparkAddress: () => isLegacySparkAddress,
1487
1489
  isSafeForNumber: () => isSafeForNumber,
1488
1490
  isTxBroadcast: () => isTxBroadcast,
1489
1491
  isValidPublicKey: () => isValidPublicKey,
@@ -1664,7 +1666,7 @@ var NotImplementedError = class extends SparkSDKError {
1664
1666
 
1665
1667
  // src/spark-wallet/spark-wallet.ts
1666
1668
  var import_core13 = require("@lightsparkdev/core");
1667
- var import_secp256k115 = require("@noble/curves/secp256k1");
1669
+ var import_secp256k113 = require("@noble/curves/secp256k1");
1668
1670
  var import_utils23 = require("@noble/curves/utils");
1669
1671
  var import_bip392 = require("@scure/bip39");
1670
1672
  var import_english2 = require("@scure/bip39/wordlists/english");
@@ -4274,9 +4276,9 @@ function invoiceStatusFromJSON(object) {
4274
4276
  case 2:
4275
4277
  case "FINALIZED":
4276
4278
  return 2 /* FINALIZED */;
4277
- case 3:
4278
- case "EXPIRED":
4279
- return 3 /* EXPIRED */;
4279
+ case 4:
4280
+ case "RETURNED":
4281
+ return 4 /* RETURNED */;
4280
4282
  case -1:
4281
4283
  case "UNRECOGNIZED":
4282
4284
  default:
@@ -4291,8 +4293,8 @@ function invoiceStatusToJSON(object) {
4291
4293
  return "PENDING";
4292
4294
  case 2 /* FINALIZED */:
4293
4295
  return "FINALIZED";
4294
- case 3 /* EXPIRED */:
4295
- return "EXPIRED";
4296
+ case 4 /* RETURNED */:
4297
+ return "RETURNED";
4296
4298
  case -1 /* UNRECOGNIZED */:
4297
4299
  default:
4298
4300
  return "UNRECOGNIZED";
@@ -6096,6 +6098,626 @@ var SigningResult_SignatureSharesEntry = {
6096
6098
  return message;
6097
6099
  }
6098
6100
  };
6101
+ function createBaseRenewLeafRequest() {
6102
+ return { leafId: "", ownerIdentityPublicKey: new Uint8Array(0), signingJobs: void 0 };
6103
+ }
6104
+ var RenewLeafRequest = {
6105
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6106
+ if (message.leafId !== "") {
6107
+ writer.uint32(10).string(message.leafId);
6108
+ }
6109
+ if (message.ownerIdentityPublicKey.length !== 0) {
6110
+ writer.uint32(18).bytes(message.ownerIdentityPublicKey);
6111
+ }
6112
+ switch (message.signingJobs?.$case) {
6113
+ case "renewNodeTimelockSigningJob":
6114
+ RenewNodeTimelockSigningJob.encode(message.signingJobs.renewNodeTimelockSigningJob, writer.uint32(26).fork()).join();
6115
+ break;
6116
+ case "renewRefundTimelockSigningJob":
6117
+ RenewRefundTimelockSigningJob.encode(
6118
+ message.signingJobs.renewRefundTimelockSigningJob,
6119
+ writer.uint32(34).fork()
6120
+ ).join();
6121
+ break;
6122
+ }
6123
+ return writer;
6124
+ },
6125
+ decode(input, length) {
6126
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6127
+ const end = length === void 0 ? reader.len : reader.pos + length;
6128
+ const message = createBaseRenewLeafRequest();
6129
+ while (reader.pos < end) {
6130
+ const tag = reader.uint32();
6131
+ switch (tag >>> 3) {
6132
+ case 1: {
6133
+ if (tag !== 10) {
6134
+ break;
6135
+ }
6136
+ message.leafId = reader.string();
6137
+ continue;
6138
+ }
6139
+ case 2: {
6140
+ if (tag !== 18) {
6141
+ break;
6142
+ }
6143
+ message.ownerIdentityPublicKey = reader.bytes();
6144
+ continue;
6145
+ }
6146
+ case 3: {
6147
+ if (tag !== 26) {
6148
+ break;
6149
+ }
6150
+ message.signingJobs = {
6151
+ $case: "renewNodeTimelockSigningJob",
6152
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.decode(reader, reader.uint32())
6153
+ };
6154
+ continue;
6155
+ }
6156
+ case 4: {
6157
+ if (tag !== 34) {
6158
+ break;
6159
+ }
6160
+ message.signingJobs = {
6161
+ $case: "renewRefundTimelockSigningJob",
6162
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.decode(reader, reader.uint32())
6163
+ };
6164
+ continue;
6165
+ }
6166
+ }
6167
+ if ((tag & 7) === 4 || tag === 0) {
6168
+ break;
6169
+ }
6170
+ reader.skip(tag & 7);
6171
+ }
6172
+ return message;
6173
+ },
6174
+ fromJSON(object) {
6175
+ return {
6176
+ leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : "",
6177
+ ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
6178
+ signingJobs: isSet3(object.renewNodeTimelockSigningJob) ? {
6179
+ $case: "renewNodeTimelockSigningJob",
6180
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromJSON(object.renewNodeTimelockSigningJob)
6181
+ } : isSet3(object.renewRefundTimelockSigningJob) ? {
6182
+ $case: "renewRefundTimelockSigningJob",
6183
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromJSON(object.renewRefundTimelockSigningJob)
6184
+ } : void 0
6185
+ };
6186
+ },
6187
+ toJSON(message) {
6188
+ const obj = {};
6189
+ if (message.leafId !== "") {
6190
+ obj.leafId = message.leafId;
6191
+ }
6192
+ if (message.ownerIdentityPublicKey.length !== 0) {
6193
+ obj.ownerIdentityPublicKey = base64FromBytes2(message.ownerIdentityPublicKey);
6194
+ }
6195
+ if (message.signingJobs?.$case === "renewNodeTimelockSigningJob") {
6196
+ obj.renewNodeTimelockSigningJob = RenewNodeTimelockSigningJob.toJSON(
6197
+ message.signingJobs.renewNodeTimelockSigningJob
6198
+ );
6199
+ } else if (message.signingJobs?.$case === "renewRefundTimelockSigningJob") {
6200
+ obj.renewRefundTimelockSigningJob = RenewRefundTimelockSigningJob.toJSON(
6201
+ message.signingJobs.renewRefundTimelockSigningJob
6202
+ );
6203
+ }
6204
+ return obj;
6205
+ },
6206
+ create(base) {
6207
+ return RenewLeafRequest.fromPartial(base ?? {});
6208
+ },
6209
+ fromPartial(object) {
6210
+ const message = createBaseRenewLeafRequest();
6211
+ message.leafId = object.leafId ?? "";
6212
+ message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
6213
+ switch (object.signingJobs?.$case) {
6214
+ case "renewNodeTimelockSigningJob": {
6215
+ if (object.signingJobs?.renewNodeTimelockSigningJob !== void 0 && object.signingJobs?.renewNodeTimelockSigningJob !== null) {
6216
+ message.signingJobs = {
6217
+ $case: "renewNodeTimelockSigningJob",
6218
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromPartial(
6219
+ object.signingJobs.renewNodeTimelockSigningJob
6220
+ )
6221
+ };
6222
+ }
6223
+ break;
6224
+ }
6225
+ case "renewRefundTimelockSigningJob": {
6226
+ if (object.signingJobs?.renewRefundTimelockSigningJob !== void 0 && object.signingJobs?.renewRefundTimelockSigningJob !== null) {
6227
+ message.signingJobs = {
6228
+ $case: "renewRefundTimelockSigningJob",
6229
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromPartial(
6230
+ object.signingJobs.renewRefundTimelockSigningJob
6231
+ )
6232
+ };
6233
+ }
6234
+ break;
6235
+ }
6236
+ }
6237
+ return message;
6238
+ }
6239
+ };
6240
+ function createBaseRenewNodeTimelockSigningJob() {
6241
+ return {
6242
+ splitNodeTxSigningJob: void 0,
6243
+ splitNodeDirectTxSigningJob: void 0,
6244
+ nodeTxSigningJob: void 0,
6245
+ refundTxSigningJob: void 0,
6246
+ directNodeTxSigningJob: void 0,
6247
+ directRefundTxSigningJob: void 0,
6248
+ directFromCpfpRefundTxSigningJob: void 0
6249
+ };
6250
+ }
6251
+ var RenewNodeTimelockSigningJob = {
6252
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6253
+ if (message.splitNodeTxSigningJob !== void 0) {
6254
+ UserSignedTxSigningJob.encode(message.splitNodeTxSigningJob, writer.uint32(10).fork()).join();
6255
+ }
6256
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
6257
+ UserSignedTxSigningJob.encode(message.splitNodeDirectTxSigningJob, writer.uint32(18).fork()).join();
6258
+ }
6259
+ if (message.nodeTxSigningJob !== void 0) {
6260
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(26).fork()).join();
6261
+ }
6262
+ if (message.refundTxSigningJob !== void 0) {
6263
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(34).fork()).join();
6264
+ }
6265
+ if (message.directNodeTxSigningJob !== void 0) {
6266
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(42).fork()).join();
6267
+ }
6268
+ if (message.directRefundTxSigningJob !== void 0) {
6269
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(50).fork()).join();
6270
+ }
6271
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
6272
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(58).fork()).join();
6273
+ }
6274
+ return writer;
6275
+ },
6276
+ decode(input, length) {
6277
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6278
+ const end = length === void 0 ? reader.len : reader.pos + length;
6279
+ const message = createBaseRenewNodeTimelockSigningJob();
6280
+ while (reader.pos < end) {
6281
+ const tag = reader.uint32();
6282
+ switch (tag >>> 3) {
6283
+ case 1: {
6284
+ if (tag !== 10) {
6285
+ break;
6286
+ }
6287
+ message.splitNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6288
+ continue;
6289
+ }
6290
+ case 2: {
6291
+ if (tag !== 18) {
6292
+ break;
6293
+ }
6294
+ message.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6295
+ continue;
6296
+ }
6297
+ case 3: {
6298
+ if (tag !== 26) {
6299
+ break;
6300
+ }
6301
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6302
+ continue;
6303
+ }
6304
+ case 4: {
6305
+ if (tag !== 34) {
6306
+ break;
6307
+ }
6308
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6309
+ continue;
6310
+ }
6311
+ case 5: {
6312
+ if (tag !== 42) {
6313
+ break;
6314
+ }
6315
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6316
+ continue;
6317
+ }
6318
+ case 6: {
6319
+ if (tag !== 50) {
6320
+ break;
6321
+ }
6322
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6323
+ continue;
6324
+ }
6325
+ case 7: {
6326
+ if (tag !== 58) {
6327
+ break;
6328
+ }
6329
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6330
+ continue;
6331
+ }
6332
+ }
6333
+ if ((tag & 7) === 4 || tag === 0) {
6334
+ break;
6335
+ }
6336
+ reader.skip(tag & 7);
6337
+ }
6338
+ return message;
6339
+ },
6340
+ fromJSON(object) {
6341
+ return {
6342
+ splitNodeTxSigningJob: isSet3(object.splitNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeTxSigningJob) : void 0,
6343
+ splitNodeDirectTxSigningJob: isSet3(object.splitNodeDirectTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeDirectTxSigningJob) : void 0,
6344
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
6345
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
6346
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
6347
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
6348
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
6349
+ };
6350
+ },
6351
+ toJSON(message) {
6352
+ const obj = {};
6353
+ if (message.splitNodeTxSigningJob !== void 0) {
6354
+ obj.splitNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeTxSigningJob);
6355
+ }
6356
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
6357
+ obj.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeDirectTxSigningJob);
6358
+ }
6359
+ if (message.nodeTxSigningJob !== void 0) {
6360
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
6361
+ }
6362
+ if (message.refundTxSigningJob !== void 0) {
6363
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
6364
+ }
6365
+ if (message.directNodeTxSigningJob !== void 0) {
6366
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
6367
+ }
6368
+ if (message.directRefundTxSigningJob !== void 0) {
6369
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
6370
+ }
6371
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
6372
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
6373
+ }
6374
+ return obj;
6375
+ },
6376
+ create(base) {
6377
+ return RenewNodeTimelockSigningJob.fromPartial(base ?? {});
6378
+ },
6379
+ fromPartial(object) {
6380
+ const message = createBaseRenewNodeTimelockSigningJob();
6381
+ message.splitNodeTxSigningJob = object.splitNodeTxSigningJob !== void 0 && object.splitNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeTxSigningJob) : void 0;
6382
+ message.splitNodeDirectTxSigningJob = object.splitNodeDirectTxSigningJob !== void 0 && object.splitNodeDirectTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeDirectTxSigningJob) : void 0;
6383
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
6384
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
6385
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
6386
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
6387
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
6388
+ return message;
6389
+ }
6390
+ };
6391
+ function createBaseRenewRefundTimelockSigningJob() {
6392
+ return {
6393
+ nodeTxSigningJob: void 0,
6394
+ refundTxSigningJob: void 0,
6395
+ directNodeTxSigningJob: void 0,
6396
+ directRefundTxSigningJob: void 0,
6397
+ directFromCpfpRefundTxSigningJob: void 0
6398
+ };
6399
+ }
6400
+ var RenewRefundTimelockSigningJob = {
6401
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6402
+ if (message.nodeTxSigningJob !== void 0) {
6403
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(10).fork()).join();
6404
+ }
6405
+ if (message.refundTxSigningJob !== void 0) {
6406
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(18).fork()).join();
6407
+ }
6408
+ if (message.directNodeTxSigningJob !== void 0) {
6409
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(26).fork()).join();
6410
+ }
6411
+ if (message.directRefundTxSigningJob !== void 0) {
6412
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(34).fork()).join();
6413
+ }
6414
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
6415
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(42).fork()).join();
6416
+ }
6417
+ return writer;
6418
+ },
6419
+ decode(input, length) {
6420
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6421
+ const end = length === void 0 ? reader.len : reader.pos + length;
6422
+ const message = createBaseRenewRefundTimelockSigningJob();
6423
+ while (reader.pos < end) {
6424
+ const tag = reader.uint32();
6425
+ switch (tag >>> 3) {
6426
+ case 1: {
6427
+ if (tag !== 10) {
6428
+ break;
6429
+ }
6430
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6431
+ continue;
6432
+ }
6433
+ case 2: {
6434
+ if (tag !== 18) {
6435
+ break;
6436
+ }
6437
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6438
+ continue;
6439
+ }
6440
+ case 3: {
6441
+ if (tag !== 26) {
6442
+ break;
6443
+ }
6444
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6445
+ continue;
6446
+ }
6447
+ case 4: {
6448
+ if (tag !== 34) {
6449
+ break;
6450
+ }
6451
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6452
+ continue;
6453
+ }
6454
+ case 5: {
6455
+ if (tag !== 42) {
6456
+ break;
6457
+ }
6458
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
6459
+ continue;
6460
+ }
6461
+ }
6462
+ if ((tag & 7) === 4 || tag === 0) {
6463
+ break;
6464
+ }
6465
+ reader.skip(tag & 7);
6466
+ }
6467
+ return message;
6468
+ },
6469
+ fromJSON(object) {
6470
+ return {
6471
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
6472
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
6473
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
6474
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
6475
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
6476
+ };
6477
+ },
6478
+ toJSON(message) {
6479
+ const obj = {};
6480
+ if (message.nodeTxSigningJob !== void 0) {
6481
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
6482
+ }
6483
+ if (message.refundTxSigningJob !== void 0) {
6484
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
6485
+ }
6486
+ if (message.directNodeTxSigningJob !== void 0) {
6487
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
6488
+ }
6489
+ if (message.directRefundTxSigningJob !== void 0) {
6490
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
6491
+ }
6492
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
6493
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
6494
+ }
6495
+ return obj;
6496
+ },
6497
+ create(base) {
6498
+ return RenewRefundTimelockSigningJob.fromPartial(base ?? {});
6499
+ },
6500
+ fromPartial(object) {
6501
+ const message = createBaseRenewRefundTimelockSigningJob();
6502
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
6503
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
6504
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
6505
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
6506
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
6507
+ return message;
6508
+ }
6509
+ };
6510
+ function createBaseRenewLeafResponse() {
6511
+ return { renewResult: void 0 };
6512
+ }
6513
+ var RenewLeafResponse = {
6514
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6515
+ switch (message.renewResult?.$case) {
6516
+ case "extendResult":
6517
+ RenewNodeTimelockResult.encode(message.renewResult.extendResult, writer.uint32(10).fork()).join();
6518
+ break;
6519
+ case "refreshResult":
6520
+ RenewRefundTimelockResult.encode(message.renewResult.refreshResult, writer.uint32(18).fork()).join();
6521
+ break;
6522
+ }
6523
+ return writer;
6524
+ },
6525
+ decode(input, length) {
6526
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6527
+ const end = length === void 0 ? reader.len : reader.pos + length;
6528
+ const message = createBaseRenewLeafResponse();
6529
+ while (reader.pos < end) {
6530
+ const tag = reader.uint32();
6531
+ switch (tag >>> 3) {
6532
+ case 1: {
6533
+ if (tag !== 10) {
6534
+ break;
6535
+ }
6536
+ message.renewResult = {
6537
+ $case: "extendResult",
6538
+ extendResult: RenewNodeTimelockResult.decode(reader, reader.uint32())
6539
+ };
6540
+ continue;
6541
+ }
6542
+ case 2: {
6543
+ if (tag !== 18) {
6544
+ break;
6545
+ }
6546
+ message.renewResult = {
6547
+ $case: "refreshResult",
6548
+ refreshResult: RenewRefundTimelockResult.decode(reader, reader.uint32())
6549
+ };
6550
+ continue;
6551
+ }
6552
+ }
6553
+ if ((tag & 7) === 4 || tag === 0) {
6554
+ break;
6555
+ }
6556
+ reader.skip(tag & 7);
6557
+ }
6558
+ return message;
6559
+ },
6560
+ fromJSON(object) {
6561
+ return {
6562
+ renewResult: isSet3(object.extendResult) ? { $case: "extendResult", extendResult: RenewNodeTimelockResult.fromJSON(object.extendResult) } : isSet3(object.refreshResult) ? { $case: "refreshResult", refreshResult: RenewRefundTimelockResult.fromJSON(object.refreshResult) } : void 0
6563
+ };
6564
+ },
6565
+ toJSON(message) {
6566
+ const obj = {};
6567
+ if (message.renewResult?.$case === "extendResult") {
6568
+ obj.extendResult = RenewNodeTimelockResult.toJSON(message.renewResult.extendResult);
6569
+ } else if (message.renewResult?.$case === "refreshResult") {
6570
+ obj.refreshResult = RenewRefundTimelockResult.toJSON(message.renewResult.refreshResult);
6571
+ }
6572
+ return obj;
6573
+ },
6574
+ create(base) {
6575
+ return RenewLeafResponse.fromPartial(base ?? {});
6576
+ },
6577
+ fromPartial(object) {
6578
+ const message = createBaseRenewLeafResponse();
6579
+ switch (object.renewResult?.$case) {
6580
+ case "extendResult": {
6581
+ if (object.renewResult?.extendResult !== void 0 && object.renewResult?.extendResult !== null) {
6582
+ message.renewResult = {
6583
+ $case: "extendResult",
6584
+ extendResult: RenewNodeTimelockResult.fromPartial(object.renewResult.extendResult)
6585
+ };
6586
+ }
6587
+ break;
6588
+ }
6589
+ case "refreshResult": {
6590
+ if (object.renewResult?.refreshResult !== void 0 && object.renewResult?.refreshResult !== null) {
6591
+ message.renewResult = {
6592
+ $case: "refreshResult",
6593
+ refreshResult: RenewRefundTimelockResult.fromPartial(object.renewResult.refreshResult)
6594
+ };
6595
+ }
6596
+ break;
6597
+ }
6598
+ }
6599
+ return message;
6600
+ }
6601
+ };
6602
+ function createBaseRenewNodeTimelockResult() {
6603
+ return { splitNode: void 0, node: void 0 };
6604
+ }
6605
+ var RenewNodeTimelockResult = {
6606
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6607
+ if (message.splitNode !== void 0) {
6608
+ TreeNode.encode(message.splitNode, writer.uint32(10).fork()).join();
6609
+ }
6610
+ if (message.node !== void 0) {
6611
+ TreeNode.encode(message.node, writer.uint32(18).fork()).join();
6612
+ }
6613
+ return writer;
6614
+ },
6615
+ decode(input, length) {
6616
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6617
+ const end = length === void 0 ? reader.len : reader.pos + length;
6618
+ const message = createBaseRenewNodeTimelockResult();
6619
+ while (reader.pos < end) {
6620
+ const tag = reader.uint32();
6621
+ switch (tag >>> 3) {
6622
+ case 1: {
6623
+ if (tag !== 10) {
6624
+ break;
6625
+ }
6626
+ message.splitNode = TreeNode.decode(reader, reader.uint32());
6627
+ continue;
6628
+ }
6629
+ case 2: {
6630
+ if (tag !== 18) {
6631
+ break;
6632
+ }
6633
+ message.node = TreeNode.decode(reader, reader.uint32());
6634
+ continue;
6635
+ }
6636
+ }
6637
+ if ((tag & 7) === 4 || tag === 0) {
6638
+ break;
6639
+ }
6640
+ reader.skip(tag & 7);
6641
+ }
6642
+ return message;
6643
+ },
6644
+ fromJSON(object) {
6645
+ return {
6646
+ splitNode: isSet3(object.splitNode) ? TreeNode.fromJSON(object.splitNode) : void 0,
6647
+ node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0
6648
+ };
6649
+ },
6650
+ toJSON(message) {
6651
+ const obj = {};
6652
+ if (message.splitNode !== void 0) {
6653
+ obj.splitNode = TreeNode.toJSON(message.splitNode);
6654
+ }
6655
+ if (message.node !== void 0) {
6656
+ obj.node = TreeNode.toJSON(message.node);
6657
+ }
6658
+ return obj;
6659
+ },
6660
+ create(base) {
6661
+ return RenewNodeTimelockResult.fromPartial(base ?? {});
6662
+ },
6663
+ fromPartial(object) {
6664
+ const message = createBaseRenewNodeTimelockResult();
6665
+ message.splitNode = object.splitNode !== void 0 && object.splitNode !== null ? TreeNode.fromPartial(object.splitNode) : void 0;
6666
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
6667
+ return message;
6668
+ }
6669
+ };
6670
+ function createBaseRenewRefundTimelockResult() {
6671
+ return { node: void 0 };
6672
+ }
6673
+ var RenewRefundTimelockResult = {
6674
+ encode(message, writer = new import_wire4.BinaryWriter()) {
6675
+ if (message.node !== void 0) {
6676
+ TreeNode.encode(message.node, writer.uint32(10).fork()).join();
6677
+ }
6678
+ return writer;
6679
+ },
6680
+ decode(input, length) {
6681
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
6682
+ const end = length === void 0 ? reader.len : reader.pos + length;
6683
+ const message = createBaseRenewRefundTimelockResult();
6684
+ while (reader.pos < end) {
6685
+ const tag = reader.uint32();
6686
+ switch (tag >>> 3) {
6687
+ case 1: {
6688
+ if (tag !== 10) {
6689
+ break;
6690
+ }
6691
+ message.node = TreeNode.decode(reader, reader.uint32());
6692
+ continue;
6693
+ }
6694
+ }
6695
+ if ((tag & 7) === 4 || tag === 0) {
6696
+ break;
6697
+ }
6698
+ reader.skip(tag & 7);
6699
+ }
6700
+ return message;
6701
+ },
6702
+ fromJSON(object) {
6703
+ return { node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0 };
6704
+ },
6705
+ toJSON(message) {
6706
+ const obj = {};
6707
+ if (message.node !== void 0) {
6708
+ obj.node = TreeNode.toJSON(message.node);
6709
+ }
6710
+ return obj;
6711
+ },
6712
+ create(base) {
6713
+ return RenewRefundTimelockResult.fromPartial(base ?? {});
6714
+ },
6715
+ fromPartial(object) {
6716
+ const message = createBaseRenewRefundTimelockResult();
6717
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
6718
+ return message;
6719
+ }
6720
+ };
6099
6721
  function createBaseNodeSignatureShares() {
6100
6722
  return {
6101
6723
  nodeId: "",
@@ -17876,7 +18498,7 @@ var QuerySparkInvoicesResponse = {
17876
18498
  }
17877
18499
  };
17878
18500
  function createBaseInvoiceResponse() {
17879
- return { invoice: "", status: 0 };
18501
+ return { invoice: "", status: 0, transferType: void 0 };
17880
18502
  }
17881
18503
  var InvoiceResponse = {
17882
18504
  encode(message, writer = new import_wire4.BinaryWriter()) {
@@ -17886,6 +18508,14 @@ var InvoiceResponse = {
17886
18508
  if (message.status !== 0) {
17887
18509
  writer.uint32(16).int32(message.status);
17888
18510
  }
18511
+ switch (message.transferType?.$case) {
18512
+ case "satsTransfer":
18513
+ SatsTransfer.encode(message.transferType.satsTransfer, writer.uint32(26).fork()).join();
18514
+ break;
18515
+ case "tokenTransfer":
18516
+ TokenTransfer.encode(message.transferType.tokenTransfer, writer.uint32(34).fork()).join();
18517
+ break;
18518
+ }
17889
18519
  return writer;
17890
18520
  },
17891
18521
  decode(input, length) {
@@ -17909,6 +18539,23 @@ var InvoiceResponse = {
17909
18539
  message.status = reader.int32();
17910
18540
  continue;
17911
18541
  }
18542
+ case 3: {
18543
+ if (tag !== 26) {
18544
+ break;
18545
+ }
18546
+ message.transferType = { $case: "satsTransfer", satsTransfer: SatsTransfer.decode(reader, reader.uint32()) };
18547
+ continue;
18548
+ }
18549
+ case 4: {
18550
+ if (tag !== 34) {
18551
+ break;
18552
+ }
18553
+ message.transferType = {
18554
+ $case: "tokenTransfer",
18555
+ tokenTransfer: TokenTransfer.decode(reader, reader.uint32())
18556
+ };
18557
+ continue;
18558
+ }
17912
18559
  }
17913
18560
  if ((tag & 7) === 4 || tag === 0) {
17914
18561
  break;
@@ -17920,7 +18567,8 @@ var InvoiceResponse = {
17920
18567
  fromJSON(object) {
17921
18568
  return {
17922
18569
  invoice: isSet3(object.invoice) ? globalThis.String(object.invoice) : "",
17923
- status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0
18570
+ status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0,
18571
+ transferType: isSet3(object.satsTransfer) ? { $case: "satsTransfer", satsTransfer: SatsTransfer.fromJSON(object.satsTransfer) } : isSet3(object.tokenTransfer) ? { $case: "tokenTransfer", tokenTransfer: TokenTransfer.fromJSON(object.tokenTransfer) } : void 0
17924
18572
  };
17925
18573
  },
17926
18574
  toJSON(message) {
@@ -17931,6 +18579,11 @@ var InvoiceResponse = {
17931
18579
  if (message.status !== 0) {
17932
18580
  obj.status = invoiceStatusToJSON(message.status);
17933
18581
  }
18582
+ if (message.transferType?.$case === "satsTransfer") {
18583
+ obj.satsTransfer = SatsTransfer.toJSON(message.transferType.satsTransfer);
18584
+ } else if (message.transferType?.$case === "tokenTransfer") {
18585
+ obj.tokenTransfer = TokenTransfer.toJSON(message.transferType.tokenTransfer);
18586
+ }
17934
18587
  return obj;
17935
18588
  },
17936
18589
  create(base) {
@@ -17940,6 +18593,130 @@ var InvoiceResponse = {
17940
18593
  const message = createBaseInvoiceResponse();
17941
18594
  message.invoice = object.invoice ?? "";
17942
18595
  message.status = object.status ?? 0;
18596
+ switch (object.transferType?.$case) {
18597
+ case "satsTransfer": {
18598
+ if (object.transferType?.satsTransfer !== void 0 && object.transferType?.satsTransfer !== null) {
18599
+ message.transferType = {
18600
+ $case: "satsTransfer",
18601
+ satsTransfer: SatsTransfer.fromPartial(object.transferType.satsTransfer)
18602
+ };
18603
+ }
18604
+ break;
18605
+ }
18606
+ case "tokenTransfer": {
18607
+ if (object.transferType?.tokenTransfer !== void 0 && object.transferType?.tokenTransfer !== null) {
18608
+ message.transferType = {
18609
+ $case: "tokenTransfer",
18610
+ tokenTransfer: TokenTransfer.fromPartial(object.transferType.tokenTransfer)
18611
+ };
18612
+ }
18613
+ break;
18614
+ }
18615
+ }
18616
+ return message;
18617
+ }
18618
+ };
18619
+ function createBaseSatsTransfer() {
18620
+ return { transferId: new Uint8Array(0) };
18621
+ }
18622
+ var SatsTransfer = {
18623
+ encode(message, writer = new import_wire4.BinaryWriter()) {
18624
+ if (message.transferId.length !== 0) {
18625
+ writer.uint32(10).bytes(message.transferId);
18626
+ }
18627
+ return writer;
18628
+ },
18629
+ decode(input, length) {
18630
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
18631
+ const end = length === void 0 ? reader.len : reader.pos + length;
18632
+ const message = createBaseSatsTransfer();
18633
+ while (reader.pos < end) {
18634
+ const tag = reader.uint32();
18635
+ switch (tag >>> 3) {
18636
+ case 1: {
18637
+ if (tag !== 10) {
18638
+ break;
18639
+ }
18640
+ message.transferId = reader.bytes();
18641
+ continue;
18642
+ }
18643
+ }
18644
+ if ((tag & 7) === 4 || tag === 0) {
18645
+ break;
18646
+ }
18647
+ reader.skip(tag & 7);
18648
+ }
18649
+ return message;
18650
+ },
18651
+ fromJSON(object) {
18652
+ return { transferId: isSet3(object.transferId) ? bytesFromBase642(object.transferId) : new Uint8Array(0) };
18653
+ },
18654
+ toJSON(message) {
18655
+ const obj = {};
18656
+ if (message.transferId.length !== 0) {
18657
+ obj.transferId = base64FromBytes2(message.transferId);
18658
+ }
18659
+ return obj;
18660
+ },
18661
+ create(base) {
18662
+ return SatsTransfer.fromPartial(base ?? {});
18663
+ },
18664
+ fromPartial(object) {
18665
+ const message = createBaseSatsTransfer();
18666
+ message.transferId = object.transferId ?? new Uint8Array(0);
18667
+ return message;
18668
+ }
18669
+ };
18670
+ function createBaseTokenTransfer() {
18671
+ return { finalTokenTransactionHash: new Uint8Array(0) };
18672
+ }
18673
+ var TokenTransfer = {
18674
+ encode(message, writer = new import_wire4.BinaryWriter()) {
18675
+ if (message.finalTokenTransactionHash.length !== 0) {
18676
+ writer.uint32(10).bytes(message.finalTokenTransactionHash);
18677
+ }
18678
+ return writer;
18679
+ },
18680
+ decode(input, length) {
18681
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
18682
+ const end = length === void 0 ? reader.len : reader.pos + length;
18683
+ const message = createBaseTokenTransfer();
18684
+ while (reader.pos < end) {
18685
+ const tag = reader.uint32();
18686
+ switch (tag >>> 3) {
18687
+ case 1: {
18688
+ if (tag !== 10) {
18689
+ break;
18690
+ }
18691
+ message.finalTokenTransactionHash = reader.bytes();
18692
+ continue;
18693
+ }
18694
+ }
18695
+ if ((tag & 7) === 4 || tag === 0) {
18696
+ break;
18697
+ }
18698
+ reader.skip(tag & 7);
18699
+ }
18700
+ return message;
18701
+ },
18702
+ fromJSON(object) {
18703
+ return {
18704
+ finalTokenTransactionHash: isSet3(object.finalTokenTransactionHash) ? bytesFromBase642(object.finalTokenTransactionHash) : new Uint8Array(0)
18705
+ };
18706
+ },
18707
+ toJSON(message) {
18708
+ const obj = {};
18709
+ if (message.finalTokenTransactionHash.length !== 0) {
18710
+ obj.finalTokenTransactionHash = base64FromBytes2(message.finalTokenTransactionHash);
18711
+ }
18712
+ return obj;
18713
+ },
18714
+ create(base) {
18715
+ return TokenTransfer.fromPartial(base ?? {});
18716
+ },
18717
+ fromPartial(object) {
18718
+ const message = createBaseTokenTransfer();
18719
+ message.finalTokenTransactionHash = object.finalTokenTransactionHash ?? new Uint8Array(0);
17943
18720
  return message;
17944
18721
  }
17945
18722
  };
@@ -18155,6 +18932,21 @@ var SparkServiceDefinition = {
18155
18932
  responseStream: false,
18156
18933
  options: {}
18157
18934
  },
18935
+ /**
18936
+ * Resets the timelocks for a leaf's transactions. Can be used to reset the
18937
+ * refund transaction timelock for a leaf (when the node transaction
18938
+ * timelock is still > 300) or reset the node and refund transaction
18939
+ * timelock. Returns an error if a leaf is not yet eligible to renew the
18940
+ * timelocks, see RenewLeafRequest for more details.
18941
+ */
18942
+ renew_leaf: {
18943
+ name: "renew_leaf",
18944
+ requestType: RenewLeafRequest,
18945
+ requestStream: false,
18946
+ responseType: RenewLeafResponse,
18947
+ responseStream: false,
18948
+ options: {}
18949
+ },
18158
18950
  get_signing_operator_list: {
18159
18951
  name: "get_signing_operator_list",
18160
18952
  requestType: Empty,
@@ -18495,7 +19287,7 @@ var isWebExtension = (
18495
19287
  "chrome" in globalThis && globalThis.chrome.runtime?.id
18496
19288
  );
18497
19289
  var userAgent = "navigator" in globalThis ? globalThis.navigator.userAgent || "unknown-user-agent" : void 0;
18498
- var packageVersion = true ? "0.3.3" : "unknown";
19290
+ var packageVersion = true ? "0.3.4" : "unknown";
18499
19291
  var baseEnvStr = "unknown";
18500
19292
  if (isBun) {
18501
19293
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -19568,7 +20360,6 @@ var BASE_CONFIG = {
19568
20360
  threshold: 2,
19569
20361
  signingOperators: getLocalSigningOperators(),
19570
20362
  tokenSignatures: "SCHNORR",
19571
- tokenTransactionVersion: "V1",
19572
20363
  tokenValidityDurationSeconds: 180,
19573
20364
  electrsUrl: getElectrsUrl("LOCAL"),
19574
20365
  expectedWithdrawBondSats: 1e4,
@@ -19772,9 +20563,6 @@ var WalletConfigService = class {
19772
20563
  getTokenSignatures() {
19773
20564
  return this.config.tokenSignatures;
19774
20565
  }
19775
- getTokenTransactionVersion() {
19776
- return this.config.tokenTransactionVersion;
19777
- }
19778
20566
  getTokenValidityDurationSeconds() {
19779
20567
  return this.config.tokenValidityDurationSeconds;
19780
20568
  }
@@ -27187,7 +27975,6 @@ var LightningService = class {
27187
27975
  };
27188
27976
 
27189
27977
  // src/services/token-transactions.ts
27190
- var import_secp256k112 = require("@noble/curves/secp256k1");
27191
27978
  var import_utils16 = require("@noble/curves/utils");
27192
27979
  var import_utils17 = require("@noble/hashes/utils");
27193
27980
 
@@ -27368,6 +28155,13 @@ function uint64be(value) {
27368
28155
  // src/utils/address.ts
27369
28156
  var BECH32M_LIMIT = 1024;
27370
28157
  var AddressNetwork = {
28158
+ MAINNET: "spark",
28159
+ TESTNET: "sparkt",
28160
+ REGTEST: "sparkrt",
28161
+ SIGNET: "sparks",
28162
+ LOCAL: "sparkl"
28163
+ };
28164
+ var LegacyAddressNetwork = {
27371
28165
  MAINNET: "sp",
27372
28166
  TESTNET: "spt",
27373
28167
  REGTEST: "sprt",
@@ -27398,7 +28192,7 @@ function encodeSparkAddressWithSignature(payload, signature) {
27398
28192
  const serializedPayload = w.finish();
27399
28193
  const words = import_base2.bech32m.toWords(serializedPayload);
27400
28194
  return bech32mEncode(
27401
- AddressNetwork[payload.network],
28195
+ LegacyAddressNetwork[payload.network],
27402
28196
  words
27403
28197
  );
27404
28198
  } catch (error) {
@@ -27414,14 +28208,14 @@ function encodeSparkAddressWithSignature(payload, signature) {
27414
28208
  }
27415
28209
  function decodeSparkAddress(address2, network) {
27416
28210
  try {
27417
- const decoded = bech32mDecode(address2);
27418
- if (decoded.prefix !== AddressNetwork[network]) {
28211
+ if (network !== getNetworkFromSparkAddress(address2)) {
27419
28212
  throw new ValidationError("Invalid Spark address prefix", {
27420
28213
  field: "address",
27421
28214
  value: address2,
27422
- expected: `prefix='${AddressNetwork[network]}'`
28215
+ expected: `prefix='${AddressNetwork[network]}' or '${LegacyAddressNetwork[network]}'`
27423
28216
  });
27424
28217
  }
28218
+ const decoded = bech32mDecode(address2);
27425
28219
  const payload = SparkAddress.decode(import_base2.bech32m.fromWords(decoded.words));
27426
28220
  const { identityPublicKey, sparkInvoiceFields, signature } = payload;
27427
28221
  const identityPubkeyHex = (0, import_utils14.bytesToHex)(identityPublicKey);
@@ -27465,18 +28259,35 @@ function decodeSparkAddress(address2, network) {
27465
28259
  );
27466
28260
  }
27467
28261
  }
28262
+ var PrefixToNetwork = Object.fromEntries(
28263
+ Object.entries(AddressNetwork).map(([k, v]) => [v, k])
28264
+ );
28265
+ var LegacyPrefixToNetwork = Object.fromEntries(
28266
+ Object.entries(LegacyAddressNetwork).map(([k, v]) => [v, k])
28267
+ );
28268
+ function getNetworkFromSparkAddress(address2) {
28269
+ const { prefix } = bech32mDecode(address2);
28270
+ const network = PrefixToNetwork[prefix] ?? LegacyPrefixToNetwork[prefix];
28271
+ if (!network) {
28272
+ throw new ValidationError("Invalid Spark address prefix", {
28273
+ field: "network",
28274
+ value: address2,
28275
+ expected: "prefix='spark1', 'sparkt1', 'sparkrt1', 'sparks1', 'sparkl1' or legacy ('sp1', 'spt1', 'sprt1', 'sps1', 'spl1')"
28276
+ });
28277
+ }
28278
+ return network;
28279
+ }
28280
+ function isLegacySparkAddress(address2) {
28281
+ try {
28282
+ const { prefix } = bech32mDecode(address2);
28283
+ return prefix in LegacyPrefixToNetwork;
28284
+ } catch (error) {
28285
+ return false;
28286
+ }
28287
+ }
27468
28288
  function isValidSparkAddress(address2) {
27469
28289
  try {
27470
- const network = Object.entries(AddressNetwork).find(
27471
- ([_, prefix]) => address2.startsWith(prefix)
27472
- )?.[0];
27473
- if (!network) {
27474
- throw new ValidationError("Invalid Spark address network", {
27475
- field: "network",
27476
- value: address2,
27477
- expected: Object.values(AddressNetwork)
27478
- });
27479
- }
28290
+ const network = getNetworkFromSparkAddress(address2);
27480
28291
  decodeSparkAddress(address2, network);
27481
28292
  return true;
27482
28293
  } catch (error) {
@@ -27672,25 +28483,16 @@ function validateSparkInvoiceSignature(invoice) {
27672
28483
  );
27673
28484
  }
27674
28485
  }
27675
- function getNetworkFromSparkAddress(address2) {
27676
- const { prefix } = bech32mDecode(address2);
27677
- const network = Object.entries(AddressNetwork).find(
27678
- ([, p]) => p === prefix
27679
- )?.[0];
27680
- if (!network) {
27681
- throw new ValidationError("Invalid Spark address network", {
27682
- field: "network",
27683
- value: address2,
27684
- expected: Object.values(AddressNetwork)
27685
- });
27686
- }
27687
- return network;
27688
- }
27689
28486
  function toProtoTimestamp(date) {
27690
28487
  const ms = date.getTime();
27691
28488
  return { seconds: Math.floor(ms / 1e3), nanos: ms % 1e3 * 1e6 };
27692
28489
  }
28490
+ function assertBech32(s) {
28491
+ const i = s.lastIndexOf("1");
28492
+ if (i <= 0 || i >= s.length - 1) throw new Error("invalid bech32 string");
28493
+ }
27693
28494
  function bech32mDecode(address2) {
28495
+ assertBech32(address2);
27694
28496
  return import_base2.bech32m.decode(address2, BECH32M_LIMIT);
27695
28497
  }
27696
28498
  function bech32mEncode(prefix, words) {
@@ -27725,34 +28527,11 @@ function isSafeForNumber(bi) {
27725
28527
  return bi >= BigInt(Number.MIN_SAFE_INTEGER) && bi <= BigInt(Number.MAX_SAFE_INTEGER);
27726
28528
  }
27727
28529
 
27728
- // src/utils/response-validation.ts
27729
- function collectResponses(responses) {
27730
- const successfulResponses = responses.filter(
27731
- (result) => result.status === "fulfilled"
27732
- ).map((result) => result.value);
27733
- const failedResponses = responses.filter(
27734
- (result) => result.status === "rejected"
27735
- );
27736
- if (failedResponses.length > 0) {
27737
- const errors = failedResponses.map((result) => result.reason).join("\n");
27738
- throw new NetworkError(
27739
- `${failedResponses.length} out of ${responses.length} requests failed, please try again`,
27740
- {
27741
- errorCount: failedResponses.length,
27742
- errors
27743
- }
27744
- );
27745
- }
27746
- return successfulResponses;
27747
- }
27748
-
27749
28530
  // src/utils/token-hashing.ts
27750
28531
  var import_sha211 = require("@noble/hashes/sha2");
27751
28532
  var import_base3 = require("@scure/base");
27752
28533
  function hashTokenTransaction(tokenTransaction, partialHash = false) {
27753
28534
  switch (tokenTransaction.version) {
27754
- case 0:
27755
- return hashTokenTransactionV0(tokenTransaction, partialHash);
27756
28535
  case 1:
27757
28536
  return hashTokenTransactionV1(tokenTransaction, partialHash);
27758
28537
  case 2:
@@ -27764,345 +28543,6 @@ function hashTokenTransaction(tokenTransaction, partialHash = false) {
27764
28543
  });
27765
28544
  }
27766
28545
  }
27767
- function hashTokenTransactionV0(tokenTransaction, partialHash = false) {
27768
- if (!tokenTransaction) {
27769
- throw new ValidationError("token transaction cannot be nil", {
27770
- field: "tokenTransaction"
27771
- });
27772
- }
27773
- let allHashes = [];
27774
- if (tokenTransaction.tokenInputs?.$case === "transferInput") {
27775
- if (!tokenTransaction.tokenInputs.transferInput.outputsToSpend) {
27776
- throw new ValidationError("outputs to spend cannot be null", {
27777
- field: "tokenInputs.transferInput.outputsToSpend"
27778
- });
27779
- }
27780
- if (tokenTransaction.tokenInputs.transferInput.outputsToSpend.length === 0) {
27781
- throw new ValidationError("outputs to spend cannot be empty", {
27782
- field: "tokenInputs.transferInput.outputsToSpend"
27783
- });
27784
- }
27785
- for (const [
27786
- i,
27787
- output
27788
- ] of tokenTransaction.tokenInputs.transferInput.outputsToSpend.entries()) {
27789
- if (!output) {
27790
- throw new ValidationError(`output cannot be null at index ${i}`, {
27791
- field: `tokenInputs.transferInput.outputsToSpend[${i}]`,
27792
- index: i
27793
- });
27794
- }
27795
- const hashObj2 = import_sha211.sha256.create();
27796
- if (output.prevTokenTransactionHash) {
27797
- const prevHash = output.prevTokenTransactionHash;
27798
- if (output.prevTokenTransactionHash.length !== 32) {
27799
- throw new ValidationError(
27800
- `invalid previous transaction hash length at index ${i}`,
27801
- {
27802
- field: `tokenInputs.transferInput.outputsToSpend[${i}].prevTokenTransactionHash`,
27803
- value: prevHash,
27804
- expectedLength: 32,
27805
- actualLength: prevHash.length,
27806
- index: i
27807
- }
27808
- );
27809
- }
27810
- hashObj2.update(output.prevTokenTransactionHash);
27811
- }
27812
- const voutBytes = new Uint8Array(4);
27813
- new DataView(voutBytes.buffer).setUint32(
27814
- 0,
27815
- output.prevTokenTransactionVout,
27816
- false
27817
- );
27818
- hashObj2.update(voutBytes);
27819
- allHashes.push(hashObj2.digest());
27820
- }
27821
- }
27822
- if (tokenTransaction.tokenInputs?.$case === "mintInput") {
27823
- const hashObj2 = import_sha211.sha256.create();
27824
- if (tokenTransaction.tokenInputs.mintInput.issuerPublicKey) {
27825
- const issuerPubKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
27826
- if (issuerPubKey.length === 0) {
27827
- throw new ValidationError("issuer public key cannot be empty", {
27828
- field: "tokenInputs.mintInput.issuerPublicKey",
27829
- value: issuerPubKey,
27830
- expectedLength: 1,
27831
- actualLength: 0
27832
- });
27833
- }
27834
- hashObj2.update(issuerPubKey);
27835
- let timestampValue = 0;
27836
- const mintInput = tokenTransaction.tokenInputs.mintInput;
27837
- if ("issuerProvidedTimestamp" in mintInput) {
27838
- const v0MintInput = mintInput;
27839
- if (v0MintInput.issuerProvidedTimestamp != 0) {
27840
- timestampValue = v0MintInput.issuerProvidedTimestamp;
27841
- }
27842
- } else if ("clientCreatedTimestamp" in tokenTransaction && tokenTransaction.clientCreatedTimestamp) {
27843
- timestampValue = tokenTransaction.clientCreatedTimestamp.getTime();
27844
- }
27845
- if (timestampValue != 0) {
27846
- const timestampBytes = new Uint8Array(8);
27847
- new DataView(timestampBytes.buffer).setBigUint64(
27848
- 0,
27849
- BigInt(timestampValue),
27850
- true
27851
- // true for little-endian to match Go implementation
27852
- );
27853
- hashObj2.update(timestampBytes);
27854
- }
27855
- allHashes.push(hashObj2.digest());
27856
- }
27857
- }
27858
- if (tokenTransaction.tokenInputs?.$case === "createInput") {
27859
- const issuerPubKeyHashObj = import_sha211.sha256.create();
27860
- const createInput = tokenTransaction.tokenInputs.createInput;
27861
- if (!createInput.issuerPublicKey || createInput.issuerPublicKey.length === 0) {
27862
- throw new ValidationError("issuer public key cannot be nil or empty", {
27863
- field: "tokenInputs.createInput.issuerPublicKey"
27864
- });
27865
- }
27866
- issuerPubKeyHashObj.update(createInput.issuerPublicKey);
27867
- allHashes.push(issuerPubKeyHashObj.digest());
27868
- const tokenNameHashObj = import_sha211.sha256.create();
27869
- if (!createInput.tokenName || createInput.tokenName.length === 0) {
27870
- throw new ValidationError("token name cannot be empty", {
27871
- field: "tokenInputs.createInput.tokenName"
27872
- });
27873
- }
27874
- if (createInput.tokenName.length > 20) {
27875
- throw new ValidationError("token name cannot be longer than 20 bytes", {
27876
- field: "tokenInputs.createInput.tokenName",
27877
- value: createInput.tokenName,
27878
- expectedLength: 20,
27879
- actualLength: createInput.tokenName.length
27880
- });
27881
- }
27882
- const tokenNameBytes = new Uint8Array(20);
27883
- const tokenNameEncoder = new TextEncoder();
27884
- tokenNameBytes.set(tokenNameEncoder.encode(createInput.tokenName));
27885
- tokenNameHashObj.update(tokenNameBytes);
27886
- allHashes.push(tokenNameHashObj.digest());
27887
- const tokenTickerHashObj = import_sha211.sha256.create();
27888
- if (!createInput.tokenTicker || createInput.tokenTicker.length === 0) {
27889
- throw new ValidationError("token ticker cannot be empty", {
27890
- field: "tokenInputs.createInput.tokenTicker"
27891
- });
27892
- }
27893
- if (createInput.tokenTicker.length > 6) {
27894
- throw new ValidationError("token ticker cannot be longer than 6 bytes", {
27895
- field: "tokenInputs.createInput.tokenTicker",
27896
- value: createInput.tokenTicker,
27897
- expectedLength: 6,
27898
- actualLength: createInput.tokenTicker.length
27899
- });
27900
- }
27901
- const tokenTickerBytes = new Uint8Array(6);
27902
- const tokenTickerEncoder = new TextEncoder();
27903
- tokenTickerBytes.set(tokenTickerEncoder.encode(createInput.tokenTicker));
27904
- tokenTickerHashObj.update(tokenTickerBytes);
27905
- allHashes.push(tokenTickerHashObj.digest());
27906
- const decimalsHashObj = import_sha211.sha256.create();
27907
- const decimalsBytes = new Uint8Array(4);
27908
- new DataView(decimalsBytes.buffer).setUint32(
27909
- 0,
27910
- createInput.decimals,
27911
- false
27912
- );
27913
- decimalsHashObj.update(decimalsBytes);
27914
- allHashes.push(decimalsHashObj.digest());
27915
- const maxSupplyHashObj = import_sha211.sha256.create();
27916
- if (!createInput.maxSupply) {
27917
- throw new ValidationError("max supply cannot be nil", {
27918
- field: "tokenInputs.createInput.maxSupply"
27919
- });
27920
- }
27921
- if (createInput.maxSupply.length !== 16) {
27922
- throw new ValidationError("max supply must be exactly 16 bytes", {
27923
- field: "tokenInputs.createInput.maxSupply",
27924
- value: createInput.maxSupply,
27925
- expectedLength: 16,
27926
- actualLength: createInput.maxSupply.length
27927
- });
27928
- }
27929
- maxSupplyHashObj.update(createInput.maxSupply);
27930
- allHashes.push(maxSupplyHashObj.digest());
27931
- const isFreezableHashObj = import_sha211.sha256.create();
27932
- const isFreezableByte = new Uint8Array([createInput.isFreezable ? 1 : 0]);
27933
- isFreezableHashObj.update(isFreezableByte);
27934
- allHashes.push(isFreezableHashObj.digest());
27935
- const creationEntityHashObj = import_sha211.sha256.create();
27936
- if (!partialHash && createInput.creationEntityPublicKey) {
27937
- creationEntityHashObj.update(createInput.creationEntityPublicKey);
27938
- }
27939
- allHashes.push(creationEntityHashObj.digest());
27940
- }
27941
- if (!tokenTransaction.tokenOutputs) {
27942
- throw new ValidationError("token outputs cannot be null", {
27943
- field: "tokenOutputs"
27944
- });
27945
- }
27946
- if (tokenTransaction.tokenOutputs.length === 0 && tokenTransaction.tokenInputs?.$case !== "createInput") {
27947
- throw new ValidationError("token outputs cannot be empty", {
27948
- field: "tokenOutputs"
27949
- });
27950
- }
27951
- for (const [i, output] of tokenTransaction.tokenOutputs.entries()) {
27952
- if (!output) {
27953
- throw new ValidationError(`output cannot be null at index ${i}`, {
27954
- field: `tokenOutputs[${i}]`,
27955
- index: i
27956
- });
27957
- }
27958
- const hashObj2 = import_sha211.sha256.create();
27959
- if (output.id && !partialHash) {
27960
- if (output.id.length === 0) {
27961
- throw new ValidationError(`output ID at index ${i} cannot be empty`, {
27962
- field: `tokenOutputs[${i}].id`,
27963
- index: i
27964
- });
27965
- }
27966
- hashObj2.update(new TextEncoder().encode(output.id));
27967
- }
27968
- if (output.ownerPublicKey) {
27969
- if (output.ownerPublicKey.length === 0) {
27970
- throw new ValidationError(
27971
- `owner public key at index ${i} cannot be empty`,
27972
- {
27973
- field: `tokenOutputs[${i}].ownerPublicKey`,
27974
- index: i
27975
- }
27976
- );
27977
- }
27978
- hashObj2.update(output.ownerPublicKey);
27979
- }
27980
- if (!partialHash) {
27981
- const revPubKey = output.revocationCommitment;
27982
- if (revPubKey) {
27983
- if (revPubKey.length === 0) {
27984
- throw new ValidationError(
27985
- `revocation commitment at index ${i} cannot be empty`,
27986
- {
27987
- field: `tokenOutputs[${i}].revocationCommitment`,
27988
- index: i
27989
- }
27990
- );
27991
- }
27992
- hashObj2.update(revPubKey);
27993
- }
27994
- const bondBytes = new Uint8Array(8);
27995
- new DataView(bondBytes.buffer).setBigUint64(
27996
- 0,
27997
- BigInt(output.withdrawBondSats),
27998
- false
27999
- );
28000
- hashObj2.update(bondBytes);
28001
- const locktimeBytes = new Uint8Array(8);
28002
- new DataView(locktimeBytes.buffer).setBigUint64(
28003
- 0,
28004
- BigInt(output.withdrawRelativeBlockLocktime),
28005
- false
28006
- );
28007
- hashObj2.update(locktimeBytes);
28008
- }
28009
- if (output.tokenPublicKey) {
28010
- if (output.tokenPublicKey.length === 0) {
28011
- throw new ValidationError(
28012
- `token public key at index ${i} cannot be empty`,
28013
- {
28014
- field: `tokenOutputs[${i}].tokenPublicKey`,
28015
- index: i
28016
- }
28017
- );
28018
- }
28019
- hashObj2.update(output.tokenPublicKey);
28020
- }
28021
- if (output.tokenAmount) {
28022
- if (output.tokenAmount.length === 0) {
28023
- throw new ValidationError(
28024
- `token amount at index ${i} cannot be empty`,
28025
- {
28026
- field: `tokenOutputs[${i}].tokenAmount`,
28027
- index: i
28028
- }
28029
- );
28030
- }
28031
- if (output.tokenAmount.length > 16) {
28032
- throw new ValidationError(
28033
- `token amount at index ${i} exceeds maximum length`,
28034
- {
28035
- field: `tokenOutputs[${i}].tokenAmount`,
28036
- value: output.tokenAmount,
28037
- expectedLength: 16,
28038
- actualLength: output.tokenAmount.length,
28039
- index: i
28040
- }
28041
- );
28042
- }
28043
- hashObj2.update(output.tokenAmount);
28044
- }
28045
- allHashes.push(hashObj2.digest());
28046
- }
28047
- if (!tokenTransaction.sparkOperatorIdentityPublicKeys) {
28048
- throw new ValidationError(
28049
- "spark operator identity public keys cannot be null",
28050
- {}
28051
- );
28052
- }
28053
- const sortedPubKeys = [
28054
- ...tokenTransaction.sparkOperatorIdentityPublicKeys || []
28055
- ].sort((a, b) => {
28056
- for (let i = 0; i < a.length && i < b.length; i++) {
28057
- if (a[i] !== b[i]) return a[i] - b[i];
28058
- }
28059
- return a.length - b.length;
28060
- });
28061
- for (const [i, pubKey] of sortedPubKeys.entries()) {
28062
- if (!pubKey) {
28063
- throw new ValidationError(
28064
- `operator public key at index ${i} cannot be null`,
28065
- {
28066
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
28067
- index: i
28068
- }
28069
- );
28070
- }
28071
- if (pubKey.length === 0) {
28072
- throw new ValidationError(
28073
- `operator public key at index ${i} cannot be empty`,
28074
- {
28075
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
28076
- index: i
28077
- }
28078
- );
28079
- }
28080
- const hashObj2 = import_sha211.sha256.create();
28081
- hashObj2.update(pubKey);
28082
- allHashes.push(hashObj2.digest());
28083
- }
28084
- const hashObj = import_sha211.sha256.create();
28085
- let networkBytes = new Uint8Array(4);
28086
- new DataView(networkBytes.buffer).setUint32(
28087
- 0,
28088
- tokenTransaction.network.valueOf(),
28089
- false
28090
- // false for big-endian
28091
- );
28092
- hashObj.update(networkBytes);
28093
- allHashes.push(hashObj.digest());
28094
- const finalHashObj = import_sha211.sha256.create();
28095
- const concatenatedHashes = new Uint8Array(
28096
- allHashes.reduce((sum, hash) => sum + hash.length, 0)
28097
- );
28098
- let offset = 0;
28099
- for (const hash of allHashes) {
28100
- concatenatedHashes.set(hash, offset);
28101
- offset += hash.length;
28102
- }
28103
- finalHashObj.update(concatenatedHashes);
28104
- return finalHashObj.digest();
28105
- }
28106
28546
  function hashTokenTransactionV1(tokenTransaction, partialHash = false) {
28107
28547
  if (!tokenTransaction) {
28108
28548
  throw new ValidationError("token transaction cannot be nil", {
@@ -29129,23 +29569,6 @@ function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier) {
29129
29569
  });
29130
29570
  }
29131
29571
 
29132
- // src/utils/token-keyshares.ts
29133
- var import_secp256k111 = require("@noble/curves/secp256k1");
29134
- function recoverRevocationSecretFromKeyshares(keyshares, threshold) {
29135
- const shares = keyshares.map((keyshare) => ({
29136
- fieldModulus: BigInt("0x" + import_secp256k111.secp256k1.CURVE.n.toString(16)),
29137
- // secp256k1 curve order
29138
- threshold,
29139
- index: BigInt(keyshare.operatorIndex),
29140
- share: BigInt(
29141
- "0x" + Buffer.from(keyshare.keyshare.keyshare).toString("hex")
29142
- ),
29143
- proofs: []
29144
- }));
29145
- const recoveredSecret = recoverSecret(shares);
29146
- return bigIntToPrivateKey(recoveredSecret);
29147
- }
29148
-
29149
29572
  // src/utils/token-transaction-validation.ts
29150
29573
  function areByteArraysEqual(a, b) {
29151
29574
  if (a.length !== b.length) {
@@ -29156,250 +29579,6 @@ function areByteArraysEqual(a, b) {
29156
29579
  function hasDuplicates(array) {
29157
29580
  return new Set(array).size !== array.length;
29158
29581
  }
29159
- function validateTokenTransactionV0(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
29160
- if (finalTokenTransaction.network !== partialTokenTransaction.network) {
29161
- throw new InternalValidationError(
29162
- "Network mismatch in response token transaction",
29163
- {
29164
- value: finalTokenTransaction.network,
29165
- expected: partialTokenTransaction.network
29166
- }
29167
- );
29168
- }
29169
- if (!finalTokenTransaction.tokenInputs) {
29170
- throw new InternalValidationError(
29171
- "Token inputs missing in final transaction",
29172
- {
29173
- value: finalTokenTransaction
29174
- }
29175
- );
29176
- }
29177
- if (!partialTokenTransaction.tokenInputs) {
29178
- throw new InternalValidationError(
29179
- "Token inputs missing in partial transaction",
29180
- {
29181
- value: partialTokenTransaction
29182
- }
29183
- );
29184
- }
29185
- if (finalTokenTransaction.tokenInputs.$case !== partialTokenTransaction.tokenInputs.$case) {
29186
- throw new InternalValidationError(
29187
- `Transaction type mismatch: final transaction has ${finalTokenTransaction.tokenInputs.$case}, partial transaction has ${partialTokenTransaction.tokenInputs.$case}`,
29188
- {
29189
- value: finalTokenTransaction.tokenInputs.$case,
29190
- expected: partialTokenTransaction.tokenInputs.$case
29191
- }
29192
- );
29193
- }
29194
- if (finalTokenTransaction.sparkOperatorIdentityPublicKeys.length !== partialTokenTransaction.sparkOperatorIdentityPublicKeys.length) {
29195
- throw new InternalValidationError(
29196
- "Spark operator identity public keys count mismatch",
29197
- {
29198
- value: finalTokenTransaction.sparkOperatorIdentityPublicKeys.length,
29199
- expected: partialTokenTransaction.sparkOperatorIdentityPublicKeys.length
29200
- }
29201
- );
29202
- }
29203
- if (partialTokenTransaction.tokenInputs.$case === "mintInput" && finalTokenTransaction.tokenInputs.$case === "mintInput") {
29204
- const finalMintInput = finalTokenTransaction.tokenInputs.mintInput;
29205
- const partialMintInput = partialTokenTransaction.tokenInputs.mintInput;
29206
- if (!areByteArraysEqual(
29207
- finalMintInput.issuerPublicKey,
29208
- partialMintInput.issuerPublicKey
29209
- )) {
29210
- throw new InternalValidationError(
29211
- "Issuer public key mismatch in mint input",
29212
- {
29213
- value: finalMintInput.issuerPublicKey.toString(),
29214
- expected: partialMintInput.issuerPublicKey.toString()
29215
- }
29216
- );
29217
- }
29218
- } else if (partialTokenTransaction.tokenInputs.$case === "transferInput" && finalTokenTransaction.tokenInputs.$case === "transferInput") {
29219
- const finalTransferInput = finalTokenTransaction.tokenInputs.transferInput;
29220
- const partialTransferInput = partialTokenTransaction.tokenInputs.transferInput;
29221
- if (finalTransferInput.outputsToSpend.length !== partialTransferInput.outputsToSpend.length) {
29222
- throw new InternalValidationError(
29223
- "Outputs to spend count mismatch in transfer input",
29224
- {
29225
- value: finalTransferInput.outputsToSpend.length,
29226
- expected: partialTransferInput.outputsToSpend.length
29227
- }
29228
- );
29229
- }
29230
- for (let i = 0; i < finalTransferInput.outputsToSpend.length; i++) {
29231
- const finalOutput = finalTransferInput.outputsToSpend[i];
29232
- const partialOutput = partialTransferInput.outputsToSpend[i];
29233
- if (!finalOutput) {
29234
- throw new InternalValidationError(
29235
- "Token output to spend missing in final transaction",
29236
- {
29237
- outputIndex: i,
29238
- value: finalOutput
29239
- }
29240
- );
29241
- }
29242
- if (!partialOutput) {
29243
- throw new InternalValidationError(
29244
- "Token output to spend missing in partial transaction",
29245
- {
29246
- outputIndex: i,
29247
- value: partialOutput
29248
- }
29249
- );
29250
- }
29251
- if (!areByteArraysEqual(
29252
- finalOutput.prevTokenTransactionHash,
29253
- partialOutput.prevTokenTransactionHash
29254
- )) {
29255
- throw new InternalValidationError(
29256
- "Previous token transaction hash mismatch in transfer input",
29257
- {
29258
- outputIndex: i,
29259
- value: finalOutput.prevTokenTransactionHash.toString(),
29260
- expected: partialOutput.prevTokenTransactionHash.toString()
29261
- }
29262
- );
29263
- }
29264
- if (finalOutput.prevTokenTransactionVout !== partialOutput.prevTokenTransactionVout) {
29265
- throw new InternalValidationError(
29266
- "Previous token transaction vout mismatch in transfer input",
29267
- {
29268
- outputIndex: i,
29269
- value: finalOutput.prevTokenTransactionVout,
29270
- expected: partialOutput.prevTokenTransactionVout
29271
- }
29272
- );
29273
- }
29274
- }
29275
- }
29276
- if (finalTokenTransaction.tokenOutputs.length !== partialTokenTransaction.tokenOutputs.length) {
29277
- throw new InternalValidationError("Token outputs count mismatch", {
29278
- value: finalTokenTransaction.tokenOutputs.length,
29279
- expected: partialTokenTransaction.tokenOutputs.length
29280
- });
29281
- }
29282
- for (let i = 0; i < finalTokenTransaction.tokenOutputs.length; i++) {
29283
- const finalOutput = finalTokenTransaction.tokenOutputs[i];
29284
- const partialOutput = partialTokenTransaction.tokenOutputs[i];
29285
- if (!finalOutput) {
29286
- throw new InternalValidationError(
29287
- "Token output missing in final transaction",
29288
- {
29289
- outputIndex: i,
29290
- value: finalOutput
29291
- }
29292
- );
29293
- }
29294
- if (!partialOutput) {
29295
- throw new InternalValidationError(
29296
- "Token output missing in partial transaction",
29297
- {
29298
- outputIndex: i,
29299
- value: partialOutput
29300
- }
29301
- );
29302
- }
29303
- if (!areByteArraysEqual(
29304
- finalOutput.ownerPublicKey,
29305
- partialOutput.ownerPublicKey
29306
- )) {
29307
- throw new InternalValidationError(
29308
- "Owner public key mismatch in token output",
29309
- {
29310
- outputIndex: i,
29311
- value: finalOutput.ownerPublicKey.toString(),
29312
- expected: partialOutput.ownerPublicKey.toString()
29313
- }
29314
- );
29315
- }
29316
- if (finalOutput.tokenPublicKey !== void 0 && partialOutput.tokenPublicKey !== void 0 && !areByteArraysEqual(
29317
- finalOutput.tokenPublicKey,
29318
- partialOutput.tokenPublicKey
29319
- )) {
29320
- throw new InternalValidationError(
29321
- "Token public key mismatch in token output",
29322
- {
29323
- outputIndex: i,
29324
- value: finalOutput.tokenPublicKey?.toString(),
29325
- expected: partialOutput.tokenPublicKey?.toString()
29326
- }
29327
- );
29328
- }
29329
- if (!areByteArraysEqual(finalOutput.tokenAmount, partialOutput.tokenAmount)) {
29330
- throw new InternalValidationError(
29331
- "Token amount mismatch in token output",
29332
- {
29333
- outputIndex: i,
29334
- value: finalOutput.tokenAmount.toString(),
29335
- expected: partialOutput.tokenAmount.toString()
29336
- }
29337
- );
29338
- }
29339
- if (finalOutput.withdrawBondSats !== void 0) {
29340
- if (finalOutput.withdrawBondSats !== expectedWithdrawBondSats) {
29341
- throw new InternalValidationError(
29342
- "Withdraw bond sats mismatch in token output",
29343
- {
29344
- outputIndex: i,
29345
- value: finalOutput.withdrawBondSats,
29346
- expected: expectedWithdrawBondSats
29347
- }
29348
- );
29349
- }
29350
- }
29351
- if (finalOutput.withdrawRelativeBlockLocktime !== void 0) {
29352
- if (finalOutput.withdrawRelativeBlockLocktime !== expectedWithdrawRelativeBlockLocktime) {
29353
- throw new InternalValidationError(
29354
- "Withdraw relative block locktime mismatch in token output",
29355
- {
29356
- outputIndex: i,
29357
- value: finalOutput.withdrawRelativeBlockLocktime,
29358
- expected: expectedWithdrawRelativeBlockLocktime
29359
- }
29360
- );
29361
- }
29362
- }
29363
- if (keyshareInfo.threshold !== expectedThreshold) {
29364
- throw new InternalValidationError(
29365
- "Threshold mismatch: expected " + expectedThreshold + " but got " + keyshareInfo.threshold,
29366
- {
29367
- field: "threshold",
29368
- value: keyshareInfo.threshold,
29369
- expected: expectedThreshold
29370
- }
29371
- );
29372
- }
29373
- }
29374
- if (keyshareInfo.ownerIdentifiers.length !== Object.keys(signingOperators).length) {
29375
- throw new InternalValidationError(
29376
- `Keyshare operator count (${keyshareInfo.ownerIdentifiers.length}) does not match signing operator count (${Object.keys(signingOperators).length})`,
29377
- {
29378
- keyshareInfo: keyshareInfo.ownerIdentifiers.length,
29379
- signingOperators: Object.keys(signingOperators).length
29380
- }
29381
- );
29382
- }
29383
- if (hasDuplicates(keyshareInfo.ownerIdentifiers)) {
29384
- throw new InternalValidationError(
29385
- "Duplicate ownerIdentifiers found in keyshareInfo",
29386
- {
29387
- keyshareInfo: keyshareInfo.ownerIdentifiers
29388
- }
29389
- );
29390
- }
29391
- for (const identifier of keyshareInfo.ownerIdentifiers) {
29392
- if (!signingOperators[identifier]) {
29393
- throw new InternalValidationError(
29394
- `Keyshare operator ${identifier} not found in signing operator list`,
29395
- {
29396
- keyshareInfo: identifier,
29397
- signingOperators: Object.keys(signingOperators)
29398
- }
29399
- );
29400
- }
29401
- }
29402
- }
29403
29582
  function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
29404
29583
  if (finalTokenTransaction.network !== partialTokenTransaction.network) {
29405
29584
  throw new InternalValidationError(
@@ -29800,16 +29979,6 @@ var TokenTransactionService = class {
29800
29979
  tokenIdentifier,
29801
29980
  this.config.getNetworkType()
29802
29981
  ).tokenIdentifier;
29803
- let tokenPublicKey;
29804
- if (this.config.getTokenTransactionVersion() === "V0") {
29805
- const tokenClient = await this.connectionManager.createSparkTokenClient(
29806
- this.config.getCoordinatorAddress()
29807
- );
29808
- const tokenMetadata = await tokenClient.query_token_metadata({
29809
- tokenIdentifiers: [rawTokenIdentifier]
29810
- });
29811
- tokenPublicKey = tokenMetadata.tokenMetadata[0].issuerPublicKey;
29812
- }
29813
29982
  let sparkInvoices = [];
29814
29983
  const tokenOutputData = receiverOutputs.map((transfer) => {
29815
29984
  const receiverAddress = decodeSparkAddress(
@@ -29819,7 +29988,7 @@ var TokenTransactionService = class {
29819
29988
  if (receiverAddress.sparkInvoiceFields) {
29820
29989
  sparkInvoices.push(transfer.receiverSparkAddress);
29821
29990
  }
29822
- if (this.config.getTokenTransactionVersion() !== "V0" && receiverAddress.sparkInvoiceFields) {
29991
+ if (receiverAddress.sparkInvoiceFields) {
29823
29992
  return {
29824
29993
  receiverPublicKey: (0, import_utils17.hexToBytes)(receiverAddress.identityPublicKey),
29825
29994
  rawTokenIdentifier,
@@ -29830,24 +29999,14 @@ var TokenTransactionService = class {
29830
29999
  return {
29831
30000
  receiverPublicKey: (0, import_utils17.hexToBytes)(receiverAddress.identityPublicKey),
29832
30001
  rawTokenIdentifier,
29833
- tokenPublicKey,
29834
- // Remove for full v0 deprecation
29835
30002
  tokenAmount: transfer.tokenAmount
29836
30003
  };
29837
30004
  });
29838
- let tokenTransaction;
29839
- if (this.config.getTokenTransactionVersion() === "V0") {
29840
- tokenTransaction = await this.constructTransferTokenTransactionV0(
29841
- outputsToUse,
29842
- tokenOutputData
29843
- );
29844
- } else {
29845
- tokenTransaction = await this.constructTransferTokenTransaction(
29846
- outputsToUse,
29847
- tokenOutputData,
29848
- sparkInvoices
29849
- );
29850
- }
30005
+ const tokenTransaction = await this.constructTransferTokenTransaction(
30006
+ outputsToUse,
30007
+ tokenOutputData,
30008
+ sparkInvoices
30009
+ );
29851
30010
  const txId = await this.broadcastTokenTransaction(
29852
30011
  tokenTransaction,
29853
30012
  outputsToUse.map((output) => output.output.ownerPublicKey),
@@ -29855,44 +30014,6 @@ var TokenTransactionService = class {
29855
30014
  );
29856
30015
  return txId;
29857
30016
  }
29858
- async constructTransferTokenTransactionV0(selectedOutputs, tokenOutputData) {
29859
- selectedOutputs.sort(
29860
- (a, b) => a.previousTransactionVout - b.previousTransactionVout
29861
- );
29862
- const availableTokenAmount = sumAvailableTokens(selectedOutputs);
29863
- const totalRequestedAmount = tokenOutputData.reduce(
29864
- (sum, output) => sum + output.tokenAmount,
29865
- 0n
29866
- );
29867
- const tokenOutputs = tokenOutputData.map((output) => ({
29868
- ownerPublicKey: output.receiverPublicKey,
29869
- tokenPublicKey: output.tokenPublicKey,
29870
- tokenAmount: (0, import_utils16.numberToBytesBE)(output.tokenAmount, 16)
29871
- }));
29872
- if (availableTokenAmount > totalRequestedAmount) {
29873
- const changeAmount = availableTokenAmount - totalRequestedAmount;
29874
- const firstTokenPublicKey = tokenOutputData[0].tokenPublicKey;
29875
- tokenOutputs.push({
29876
- ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
29877
- tokenPublicKey: firstTokenPublicKey,
29878
- tokenAmount: (0, import_utils16.numberToBytesBE)(changeAmount, 16)
29879
- });
29880
- }
29881
- return {
29882
- network: this.config.getNetworkProto(),
29883
- tokenInputs: {
29884
- $case: "transferInput",
29885
- transferInput: {
29886
- outputsToSpend: selectedOutputs.map((output) => ({
29887
- prevTokenTransactionHash: output.previousTransactionHash,
29888
- prevTokenTransactionVout: output.previousTransactionVout
29889
- }))
29890
- }
29891
- },
29892
- tokenOutputs,
29893
- sparkOperatorIdentityPublicKeys: this.collectOperatorIdentityPublicKeys()
29894
- };
29895
- }
29896
30017
  async constructTransferTokenTransaction(selectedOutputs, tokenOutputData, sparkInvoices) {
29897
30018
  selectedOutputs.sort(
29898
30019
  (a, b) => a.previousTransactionVout - b.previousTransactionVout
@@ -29948,113 +30069,6 @@ var TokenTransactionService = class {
29948
30069
  }
29949
30070
  async broadcastTokenTransaction(tokenTransaction, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
29950
30071
  const signingOperators = this.config.getSigningOperators();
29951
- if (!isTokenTransaction(tokenTransaction)) {
29952
- return this.broadcastTokenTransactionV0(
29953
- tokenTransaction,
29954
- signingOperators,
29955
- outputsToSpendSigningPublicKeys,
29956
- outputsToSpendCommitments
29957
- );
29958
- } else {
29959
- return this.broadcastTokenTransactionV1(
29960
- tokenTransaction,
29961
- signingOperators,
29962
- outputsToSpendSigningPublicKeys,
29963
- outputsToSpendCommitments
29964
- );
29965
- }
29966
- }
29967
- async broadcastTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
29968
- const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransactionV0(
29969
- tokenTransaction,
29970
- signingOperators,
29971
- outputsToSpendSigningPublicKeys,
29972
- outputsToSpendCommitments
29973
- );
29974
- const { successfulSignatures } = await this.signTokenTransactionV0(
29975
- finalTokenTransaction,
29976
- finalTokenTransactionHash,
29977
- signingOperators
29978
- );
29979
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
29980
- const outputsToSpend = finalTokenTransaction.tokenInputs.transferInput.outputsToSpend;
29981
- const errors = [];
29982
- const revocationSecrets = [];
29983
- for (let outputIndex = 0; outputIndex < outputsToSpend.length; outputIndex++) {
29984
- const outputKeyshares = successfulSignatures.map(({ identifier, response }) => ({
29985
- operatorIndex: parseInt(identifier, 16),
29986
- keyshare: response.revocationKeyshares[outputIndex]
29987
- }));
29988
- if (outputKeyshares.length < threshold) {
29989
- errors.push(
29990
- new ValidationError("Insufficient keyshares", {
29991
- field: "outputKeyshares",
29992
- value: outputKeyshares.length,
29993
- expected: threshold,
29994
- index: outputIndex
29995
- })
29996
- );
29997
- }
29998
- const seenIndices = /* @__PURE__ */ new Set();
29999
- for (const { operatorIndex } of outputKeyshares) {
30000
- if (seenIndices.has(operatorIndex)) {
30001
- errors.push(
30002
- new ValidationError("Duplicate operator index", {
30003
- field: "outputKeyshares",
30004
- value: operatorIndex,
30005
- expected: "Unique operator index",
30006
- index: outputIndex
30007
- })
30008
- );
30009
- }
30010
- seenIndices.add(operatorIndex);
30011
- }
30012
- const revocationSecret = recoverRevocationSecretFromKeyshares(
30013
- outputKeyshares,
30014
- threshold
30015
- );
30016
- const derivedRevocationCommitment = import_secp256k112.secp256k1.getPublicKey(
30017
- revocationSecret,
30018
- true
30019
- );
30020
- if (!outputsToSpendCommitments || !outputsToSpendCommitments[outputIndex] || !derivedRevocationCommitment.every(
30021
- (byte, i) => byte === outputsToSpendCommitments[outputIndex][i]
30022
- )) {
30023
- errors.push(
30024
- new InternalValidationError(
30025
- "Revocation commitment verification failed",
30026
- {
30027
- field: "revocationCommitment",
30028
- value: derivedRevocationCommitment,
30029
- expected: (0, import_utils16.bytesToHex)(outputsToSpendCommitments[outputIndex]),
30030
- outputIndex
30031
- }
30032
- )
30033
- );
30034
- }
30035
- revocationSecrets.push({
30036
- inputIndex: outputIndex,
30037
- revocationSecret
30038
- });
30039
- }
30040
- if (errors.length > 0) {
30041
- throw new ValidationError(
30042
- "Multiple validation errors occurred across outputs",
30043
- {
30044
- field: "outputValidation",
30045
- value: errors
30046
- }
30047
- );
30048
- }
30049
- await this.finalizeTokenTransaction(
30050
- finalTokenTransaction,
30051
- revocationSecrets,
30052
- threshold
30053
- );
30054
- }
30055
- return (0, import_utils16.bytesToHex)(finalTokenTransactionHash);
30056
- }
30057
- async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30058
30072
  const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
30059
30073
  tokenTransaction,
30060
30074
  signingOperators,
@@ -30068,101 +30082,6 @@ var TokenTransactionService = class {
30068
30082
  );
30069
30083
  return (0, import_utils16.bytesToHex)(finalTokenTransactionHash);
30070
30084
  }
30071
- async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30072
- const sparkClient = await this.connectionManager.createSparkClient(
30073
- this.config.getCoordinatorAddress()
30074
- );
30075
- const partialTokenTransactionHash = hashTokenTransactionV0(
30076
- tokenTransaction,
30077
- true
30078
- );
30079
- const ownerSignaturesWithIndex = [];
30080
- if (tokenTransaction.tokenInputs.$case === "mintInput") {
30081
- const issuerPublicKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
30082
- if (!issuerPublicKey) {
30083
- throw new ValidationError("Invalid mint input", {
30084
- field: "issuerPublicKey",
30085
- value: null,
30086
- expected: "Non-null issuer public key"
30087
- });
30088
- }
30089
- const ownerSignature = await this.signMessageWithKey(
30090
- partialTokenTransactionHash,
30091
- issuerPublicKey
30092
- );
30093
- ownerSignaturesWithIndex.push({
30094
- signature: ownerSignature,
30095
- inputIndex: 0
30096
- });
30097
- } else if (tokenTransaction.tokenInputs.$case === "transferInput") {
30098
- if (!outputsToSpendSigningPublicKeys || !outputsToSpendCommitments) {
30099
- throw new ValidationError("Invalid transfer input", {
30100
- field: "outputsToSpend",
30101
- value: {
30102
- signingPublicKeys: outputsToSpendSigningPublicKeys,
30103
- revocationPublicKeys: outputsToSpendCommitments
30104
- },
30105
- expected: "Non-null signing and revocation public keys"
30106
- });
30107
- }
30108
- for (const [i, key] of outputsToSpendSigningPublicKeys.entries()) {
30109
- if (!key) {
30110
- throw new ValidationError("Invalid signing key", {
30111
- field: "outputsToSpendSigningPublicKeys",
30112
- value: i,
30113
- expected: "Non-null signing key"
30114
- });
30115
- }
30116
- const ownerSignature = await this.signMessageWithKey(
30117
- partialTokenTransactionHash,
30118
- key
30119
- );
30120
- ownerSignaturesWithIndex.push({
30121
- signature: ownerSignature,
30122
- inputIndex: i
30123
- });
30124
- }
30125
- }
30126
- const startResponse = await sparkClient.start_token_transaction(
30127
- {
30128
- identityPublicKey: await this.config.signer.getIdentityPublicKey(),
30129
- partialTokenTransaction: tokenTransaction,
30130
- tokenTransactionSignatures: {
30131
- ownerSignatures: ownerSignaturesWithIndex
30132
- }
30133
- },
30134
- {
30135
- retry: true,
30136
- retryableStatuses: ["UNKNOWN", "UNAVAILABLE", "CANCELLED", "INTERNAL"],
30137
- retryMaxAttempts: 3
30138
- }
30139
- );
30140
- if (!startResponse.finalTokenTransaction) {
30141
- throw new Error("Final token transaction missing in start response");
30142
- }
30143
- if (!startResponse.keyshareInfo) {
30144
- throw new Error("Keyshare info missing in start response");
30145
- }
30146
- validateTokenTransactionV0(
30147
- startResponse.finalTokenTransaction,
30148
- tokenTransaction,
30149
- signingOperators,
30150
- startResponse.keyshareInfo,
30151
- this.config.getExpectedWithdrawBondSats(),
30152
- this.config.getExpectedWithdrawRelativeBlockLocktime(),
30153
- this.config.getThreshold()
30154
- );
30155
- const finalTokenTransaction = startResponse.finalTokenTransaction;
30156
- const finalTokenTransactionHash = hashTokenTransactionV0(
30157
- finalTokenTransaction,
30158
- false
30159
- );
30160
- return {
30161
- finalTokenTransaction,
30162
- finalTokenTransactionHash,
30163
- threshold: startResponse.keyshareInfo.threshold
30164
- };
30165
- }
30166
30085
  async startTokenTransaction(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30167
30086
  const sparkClient = await this.connectionManager.createSparkTokenClient(
30168
30087
  this.config.getCoordinatorAddress()
@@ -30282,103 +30201,6 @@ var TokenTransactionService = class {
30282
30201
  threshold: startResponse.keyshareInfo.threshold
30283
30202
  };
30284
30203
  }
30285
- async signTokenTransactionV0(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
30286
- const soSignatures = await Promise.allSettled(
30287
- Object.entries(signingOperators).map(
30288
- async ([identifier, operator], index) => {
30289
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
30290
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
30291
- const payload = {
30292
- finalTokenTransactionHash,
30293
- operatorIdentityPublicKey: (0, import_utils17.hexToBytes)(operator.identityPublicKey)
30294
- };
30295
- const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
30296
- let operatorSpecificSignatures = [];
30297
- if (finalTokenTransaction.tokenInputs.$case === "mintInput") {
30298
- const issuerPublicKey = finalTokenTransaction.tokenInputs.mintInput.issuerPublicKey;
30299
- if (!issuerPublicKey) {
30300
- throw new ValidationError("Invalid mint input", {
30301
- field: "issuerPublicKey",
30302
- value: null,
30303
- expected: "Non-null issuer public key"
30304
- });
30305
- }
30306
- const ownerSignature = await this.signMessageWithKey(
30307
- payloadHash,
30308
- issuerPublicKey
30309
- );
30310
- operatorSpecificSignatures.push({
30311
- ownerSignature: {
30312
- signature: ownerSignature,
30313
- inputIndex: 0
30314
- },
30315
- payload
30316
- });
30317
- }
30318
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
30319
- const transferInput = finalTokenTransaction.tokenInputs.transferInput;
30320
- for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
30321
- let ownerSignature;
30322
- if (this.config.getTokenSignatures() === "SCHNORR") {
30323
- ownerSignature = await this.config.signer.signSchnorrWithIdentityKey(
30324
- payloadHash
30325
- );
30326
- } else {
30327
- ownerSignature = await this.config.signer.signMessageWithIdentityKey(
30328
- payloadHash
30329
- );
30330
- }
30331
- operatorSpecificSignatures.push({
30332
- ownerSignature: {
30333
- signature: ownerSignature,
30334
- inputIndex: i
30335
- },
30336
- payload
30337
- });
30338
- }
30339
- }
30340
- try {
30341
- const response = await internalSparkClient.sign_token_transaction(
30342
- {
30343
- finalTokenTransaction,
30344
- operatorSpecificSignatures,
30345
- identityPublicKey
30346
- },
30347
- {
30348
- retry: true,
30349
- retryableStatuses: [
30350
- "UNKNOWN",
30351
- "UNAVAILABLE",
30352
- "CANCELLED",
30353
- "INTERNAL"
30354
- ],
30355
- retryMaxAttempts: 3
30356
- }
30357
- );
30358
- return {
30359
- index,
30360
- identifier,
30361
- response
30362
- };
30363
- } catch (error) {
30364
- throw new NetworkError(
30365
- "Failed to sign token transaction",
30366
- {
30367
- operation: "sign_token_transaction",
30368
- errorCount: 1,
30369
- errors: error instanceof Error ? error.message : String(error)
30370
- },
30371
- error
30372
- );
30373
- }
30374
- }
30375
- )
30376
- );
30377
- const successfulSignatures = collectResponses(soSignatures);
30378
- return {
30379
- successfulSignatures
30380
- };
30381
- }
30382
30204
  async signTokenTransaction(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
30383
30205
  const coordinatorClient = await this.connectionManager.createSparkTokenClient(
30384
30206
  this.config.getCoordinatorAddress()
@@ -30450,54 +30272,6 @@ var TokenTransactionService = class {
30450
30272
  );
30451
30273
  }
30452
30274
  }
30453
- if (this.config.getTokenTransactionVersion() === "V0") {
30454
- return this.fetchOwnedTokenOutputsV0(params);
30455
- } else {
30456
- return this.fetchOwnedTokenOutputsV1(params);
30457
- }
30458
- }
30459
- async queryTokenTransactions(params) {
30460
- if (this.config.getTokenTransactionVersion() === "V0") {
30461
- return this.queryTokenTransactionsV0(params);
30462
- } else {
30463
- return this.queryTokenTransactionsV1(params);
30464
- }
30465
- }
30466
- async fetchOwnedTokenOutputsV0(params) {
30467
- const {
30468
- ownerPublicKeys,
30469
- issuerPublicKeys: tokenPublicKeys = [],
30470
- tokenIdentifiers = []
30471
- } = params;
30472
- const sparkClient = await this.connectionManager.createSparkClient(
30473
- this.config.getCoordinatorAddress()
30474
- );
30475
- try {
30476
- const result = await sparkClient.query_token_outputs({
30477
- ownerPublicKeys,
30478
- tokenPublicKeys,
30479
- tokenIdentifiers,
30480
- network: this.config.getNetworkProto()
30481
- });
30482
- return result.outputsWithPreviousTransactionData;
30483
- } catch (error) {
30484
- throw new NetworkError(
30485
- "Failed to fetch owned token outputs",
30486
- {
30487
- operation: "spark.query_token_outputs",
30488
- errorCount: 1,
30489
- errors: error instanceof Error ? error.message : String(error)
30490
- },
30491
- error
30492
- );
30493
- }
30494
- }
30495
- async fetchOwnedTokenOutputsV1(params) {
30496
- const {
30497
- ownerPublicKeys,
30498
- issuerPublicKeys = [],
30499
- tokenIdentifiers = []
30500
- } = params;
30501
30275
  const tokenClient = await this.connectionManager.createSparkTokenClient(
30502
30276
  this.config.getCoordinatorAddress()
30503
30277
  );
@@ -30538,75 +30312,7 @@ var TokenTransactionService = class {
30538
30312
  );
30539
30313
  }
30540
30314
  }
30541
- async queryTokenTransactionsV0(params) {
30542
- const {
30543
- ownerPublicKeys,
30544
- issuerPublicKeys,
30545
- tokenTransactionHashes,
30546
- tokenIdentifiers,
30547
- outputIds,
30548
- pageSize,
30549
- offset
30550
- } = params;
30551
- const sparkClient = await this.connectionManager.createSparkClient(
30552
- this.config.getCoordinatorAddress()
30553
- );
30554
- let queryParams = {
30555
- tokenPublicKeys: issuerPublicKeys?.map(import_utils17.hexToBytes),
30556
- ownerPublicKeys: ownerPublicKeys?.map(import_utils17.hexToBytes),
30557
- tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
30558
- const { tokenIdentifier } = decodeBech32mTokenIdentifier(
30559
- identifier,
30560
- this.config.getNetworkType()
30561
- );
30562
- return tokenIdentifier;
30563
- }),
30564
- tokenTransactionHashes: tokenTransactionHashes?.map(import_utils17.hexToBytes),
30565
- outputIds: outputIds || [],
30566
- limit: pageSize,
30567
- offset
30568
- };
30569
- try {
30570
- const response = await sparkClient.query_token_transactions(queryParams);
30571
- return {
30572
- tokenTransactionsWithStatus: response.tokenTransactionsWithStatus.map(
30573
- (tx) => {
30574
- const v1TokenTransaction = {
30575
- version: 1,
30576
- network: tx.tokenTransaction.network,
30577
- tokenInputs: tx.tokenTransaction.tokenInputs,
30578
- tokenOutputs: tx.tokenTransaction.tokenOutputs,
30579
- sparkOperatorIdentityPublicKeys: tx.tokenTransaction.sparkOperatorIdentityPublicKeys,
30580
- expiryTime: void 0,
30581
- // V0 doesn't have expiry time
30582
- clientCreatedTimestamp: tx.tokenTransaction?.tokenInputs?.$case === "mintInput" ? new Date(
30583
- tx.tokenTransaction.tokenInputs.mintInput.issuerProvidedTimestamp * 1e3
30584
- ) : /* @__PURE__ */ new Date(),
30585
- invoiceAttachments: []
30586
- };
30587
- return {
30588
- tokenTransaction: v1TokenTransaction,
30589
- status: tx.status,
30590
- confirmationMetadata: tx.confirmationMetadata,
30591
- tokenTransactionHash: tx.tokenTransactionHash
30592
- };
30593
- }
30594
- ),
30595
- offset: response.offset
30596
- };
30597
- } catch (error) {
30598
- throw new NetworkError(
30599
- "Failed to query token transactions",
30600
- {
30601
- operation: "spark.query_token_transactions",
30602
- errorCount: 1,
30603
- errors: error instanceof Error ? error.message : String(error)
30604
- },
30605
- error
30606
- );
30607
- }
30608
- }
30609
- async queryTokenTransactionsV1(params) {
30315
+ async queryTokenTransactions(params) {
30610
30316
  const {
30611
30317
  ownerPublicKeys,
30612
30318
  issuerPublicKeys,
@@ -30719,50 +30425,6 @@ var TokenTransactionService = class {
30719
30425
  });
30720
30426
  }
30721
30427
  }
30722
- async finalizeTokenTransaction(finalTokenTransaction, revocationSecrets, threshold) {
30723
- const signingOperators = this.config.getSigningOperators();
30724
- const soResponses = await Promise.allSettled(
30725
- Object.entries(signingOperators).map(async ([identifier, operator]) => {
30726
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
30727
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
30728
- try {
30729
- const response = await internalSparkClient.finalize_token_transaction(
30730
- {
30731
- finalTokenTransaction,
30732
- revocationSecrets,
30733
- identityPublicKey
30734
- },
30735
- {
30736
- retry: true,
30737
- retryableStatuses: [
30738
- "UNKNOWN",
30739
- "UNAVAILABLE",
30740
- "CANCELLED",
30741
- "INTERNAL"
30742
- ],
30743
- retryMaxAttempts: 3
30744
- }
30745
- );
30746
- return {
30747
- identifier,
30748
- response
30749
- };
30750
- } catch (error) {
30751
- throw new NetworkError(
30752
- "Failed to finalize token transaction",
30753
- {
30754
- operation: "finalize_token_transaction",
30755
- errorCount: 1,
30756
- errors: error instanceof Error ? error.message : String(error)
30757
- },
30758
- error
30759
- );
30760
- }
30761
- })
30762
- );
30763
- collectResponses(soResponses);
30764
- return finalTokenTransaction;
30765
- }
30766
30428
  async createSignaturesForOperators(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
30767
30429
  const inputTtxoSignaturesPerOperator = [];
30768
30430
  for (const [_, operator] of Object.entries(signingOperators)) {
@@ -30839,28 +30501,25 @@ var TokenTransactionService = class {
30839
30501
  return inputTtxoSignaturesPerOperator;
30840
30502
  }
30841
30503
  };
30842
- function isTokenTransaction(tokenTransaction) {
30843
- return "version" in tokenTransaction && "expiryTime" in tokenTransaction;
30844
- }
30845
30504
 
30846
30505
  // src/utils/adaptor-signature.ts
30847
30506
  var import_modular = require("@noble/curves/abstract/modular");
30848
- var import_secp256k113 = require("@noble/curves/secp256k1");
30507
+ var import_secp256k111 = require("@noble/curves/secp256k1");
30849
30508
  var import_utils18 = require("@noble/curves/utils");
30850
30509
  function generateSignatureFromExistingAdaptor(signature, adaptorPrivateKeyBytes) {
30851
30510
  const { r, s } = parseSignature(signature);
30852
30511
  const sBigInt = (0, import_utils18.bytesToNumberBE)(s);
30853
30512
  const tBigInt = (0, import_utils18.bytesToNumberBE)(adaptorPrivateKeyBytes);
30854
- const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k113.secp256k1.CURVE.n);
30513
+ const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k111.secp256k1.CURVE.n);
30855
30514
  const newSignature = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(newS, 32)]);
30856
30515
  return newSignature;
30857
30516
  }
30858
30517
  function generateAdaptorFromSignature(signature) {
30859
- const adaptorPrivateKey = import_secp256k113.secp256k1.utils.randomPrivateKey();
30518
+ const adaptorPrivateKey = import_secp256k111.secp256k1.utils.randomPrivateKey();
30860
30519
  const { r, s } = parseSignature(signature);
30861
30520
  const sBigInt = (0, import_utils18.bytesToNumberBE)(s);
30862
30521
  const tBigInt = (0, import_utils18.bytesToNumberBE)(adaptorPrivateKey);
30863
- const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k113.secp256k1.CURVE.n);
30522
+ const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k111.secp256k1.CURVE.n);
30864
30523
  const newSignature = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(newS, 32)]);
30865
30524
  return {
30866
30525
  adaptorSignature: newSignature,
@@ -30880,19 +30539,19 @@ function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes
30880
30539
  const { r, s } = parseSignature(signature);
30881
30540
  const sBigInt = (0, import_utils18.bytesToNumberBE)(s);
30882
30541
  const adaptorPrivateKey = (0, import_utils18.bytesToNumberBE)(adaptorPrivateKeyBytes);
30883
- const newS = (0, import_modular.mod)(sBigInt + adaptorPrivateKey, import_secp256k113.secp256k1.CURVE.n);
30542
+ const newS = (0, import_modular.mod)(sBigInt + adaptorPrivateKey, import_secp256k111.secp256k1.CURVE.n);
30884
30543
  const newSig = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(newS, 32)]);
30885
30544
  try {
30886
- if (import_secp256k113.schnorr.verify(newSig, hash, pubkey)) {
30545
+ if (import_secp256k111.schnorr.verify(newSig, hash, pubkey)) {
30887
30546
  return newSig;
30888
30547
  }
30889
30548
  } catch (e) {
30890
30549
  console.error("[applyAdaptorToSignature] Addition verification failed:", e);
30891
30550
  }
30892
- const altS = (0, import_modular.mod)(sBigInt - adaptorPrivateKey, import_secp256k113.secp256k1.CURVE.n);
30551
+ const altS = (0, import_modular.mod)(sBigInt - adaptorPrivateKey, import_secp256k111.secp256k1.CURVE.n);
30893
30552
  const altSig = new Uint8Array([...r, ...(0, import_utils18.numberToBytesBE)(altS, 32)]);
30894
30553
  try {
30895
- if (import_secp256k113.schnorr.verify(altSig, hash, pubkey)) {
30554
+ if (import_secp256k111.schnorr.verify(altSig, hash, pubkey)) {
30896
30555
  return altSig;
30897
30556
  }
30898
30557
  } catch (e) {
@@ -30907,10 +30566,10 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
30907
30566
  if (hash.length !== 32) {
30908
30567
  throw new Error(`wrong size for message (got ${hash.length}, want 32)`);
30909
30568
  }
30910
- const pubKey = import_secp256k113.schnorr.utils.lift_x((0, import_utils18.bytesToNumberBE)(pubKeyBytes));
30569
+ const pubKey = import_secp256k111.schnorr.utils.lift_x((0, import_utils18.bytesToNumberBE)(pubKeyBytes));
30911
30570
  pubKey.assertValidity();
30912
30571
  const { r, s } = parseSignature(signature);
30913
- const commitmenet = import_secp256k113.schnorr.utils.taggedHash(
30572
+ const commitmenet = import_secp256k111.schnorr.utils.taggedHash(
30914
30573
  "BIP0340/challenge",
30915
30574
  r,
30916
30575
  pubKey.toBytes().slice(1),
@@ -30919,18 +30578,18 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
30919
30578
  if (commitmenet.length > 32) {
30920
30579
  throw new Error("hash of (r || P || m) too big");
30921
30580
  }
30922
- const e = (0, import_modular.mod)((0, import_utils18.bytesToNumberBE)(commitmenet), import_secp256k113.secp256k1.CURVE.n);
30923
- const negE = (0, import_modular.mod)(-e, import_secp256k113.secp256k1.CURVE.n);
30924
- const sG = import_secp256k113.secp256k1.Point.BASE.multiplyUnsafe((0, import_utils18.bytesToNumberBE)(s));
30581
+ const e = (0, import_modular.mod)((0, import_utils18.bytesToNumberBE)(commitmenet), import_secp256k111.secp256k1.CURVE.n);
30582
+ const negE = (0, import_modular.mod)(-e, import_secp256k111.secp256k1.CURVE.n);
30583
+ const sG = import_secp256k111.secp256k1.Point.BASE.multiplyUnsafe((0, import_utils18.bytesToNumberBE)(s));
30925
30584
  const eP = pubKey.multiplyUnsafe(negE);
30926
30585
  const R = sG.add(eP);
30927
30586
  if (R.is0()) {
30928
30587
  throw new Error("R is zero");
30929
30588
  }
30930
30589
  R.assertValidity();
30931
- const adaptorPoint = import_secp256k113.secp256k1.Point.fromHex(adaptorPubkey);
30590
+ const adaptorPoint = import_secp256k111.secp256k1.Point.fromHex(adaptorPubkey);
30932
30591
  const newR = R.add(adaptorPoint);
30933
- if (!inbound && newR.equals(import_secp256k113.secp256k1.Point.ZERO)) {
30592
+ if (!inbound && newR.equals(import_secp256k111.secp256k1.Point.ZERO)) {
30934
30593
  throw new Error("calculated R point is the point at infinity");
30935
30594
  }
30936
30595
  newR.assertValidity();
@@ -30958,16 +30617,16 @@ function parseSignature(signature) {
30958
30617
  }
30959
30618
  const r = signature.slice(0, 32);
30960
30619
  const s = signature.slice(32, 64);
30961
- if ((0, import_utils18.bytesToNumberBE)(r) >= import_secp256k113.secp256k1.CURVE.Fp.ORDER) {
30620
+ if ((0, import_utils18.bytesToNumberBE)(r) >= import_secp256k111.secp256k1.CURVE.Fp.ORDER) {
30962
30621
  throw new ValidationError("Invalid signature: r >= field prime", {
30963
30622
  rValue: (0, import_utils18.bytesToNumberBE)(r),
30964
- fieldPrime: import_secp256k113.secp256k1.CURVE.Fp.ORDER
30623
+ fieldPrime: import_secp256k111.secp256k1.CURVE.Fp.ORDER
30965
30624
  });
30966
30625
  }
30967
- if ((0, import_utils18.bytesToNumberBE)(s) >= import_secp256k113.secp256k1.CURVE.n) {
30626
+ if ((0, import_utils18.bytesToNumberBE)(s) >= import_secp256k111.secp256k1.CURVE.n) {
30968
30627
  throw new ValidationError("Invalid signature: s >= group order", {
30969
30628
  sValue: (0, import_utils18.bytesToNumberBE)(s),
30970
- groupOrder: import_secp256k113.secp256k1.CURVE.n
30629
+ groupOrder: import_secp256k111.secp256k1.CURVE.n
30971
30630
  });
30972
30631
  }
30973
30632
  return { r, s };
@@ -31146,7 +30805,7 @@ var SigningService = class {
31146
30805
  };
31147
30806
 
31148
30807
  // src/tests/utils/test-faucet.ts
31149
- var import_secp256k114 = require("@noble/curves/secp256k1");
30808
+ var import_secp256k112 = require("@noble/curves/secp256k1");
31150
30809
  var import_utils20 = require("@noble/curves/utils");
31151
30810
  var btc3 = __toESM(require("@scure/btc-signer"), 1);
31152
30811
  var import_btc_signer5 = require("@scure/btc-signer");
@@ -31167,7 +30826,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31167
30826
  this.username = username;
31168
30827
  this.password = password;
31169
30828
  this.miningAddress = getP2TRAddressFromPublicKey(
31170
- import_secp256k114.secp256k1.getPublicKey(STATIC_MINING_KEY),
30829
+ import_secp256k112.secp256k1.getPublicKey(STATIC_MINING_KEY),
31171
30830
  4 /* LOCAL */
31172
30831
  );
31173
30832
  }
@@ -31206,7 +30865,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31206
30865
  });
31207
30866
  }
31208
30867
  async refill() {
31209
- const minerPubKey = import_secp256k114.secp256k1.getPublicKey(STATIC_MINING_KEY);
30868
+ const minerPubKey = import_secp256k112.secp256k1.getPublicKey(STATIC_MINING_KEY);
31210
30869
  const address2 = getP2TRAddressFromPublicKey(minerPubKey, 4 /* LOCAL */);
31211
30870
  const scanResult = await this.call("scantxoutset", [
31212
30871
  "start",
@@ -31255,7 +30914,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31255
30914
  txid: selectedUtxo.txid,
31256
30915
  index: selectedUtxo.vout
31257
30916
  });
31258
- const faucetPubKey = import_secp256k114.secp256k1.getPublicKey(STATIC_FAUCET_KEY);
30917
+ const faucetPubKey = import_secp256k112.secp256k1.getPublicKey(STATIC_FAUCET_KEY);
31259
30918
  const script = getP2TRScriptFromPublicKey(faucetPubKey, 4 /* LOCAL */);
31260
30919
  for (let i = 0; i < numCoinsToCreate; i++) {
31261
30920
  splitTx.addOutput({
@@ -31316,7 +30975,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31316
30975
  await this.broadcastTx((0, import_utils20.bytesToHex)(signedTx.extract()));
31317
30976
  }
31318
30977
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
31319
- const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
30978
+ const pubKey = import_secp256k112.secp256k1.getPublicKey(key);
31320
30979
  const internalKey = pubKey.slice(1);
31321
30980
  const script = getP2TRScriptFromPublicKey(pubKey, 4 /* LOCAL */);
31322
30981
  unsignedTx.updateInput(0, {
@@ -31336,7 +30995,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31336
30995
  const tweakedKey = (0, import_utils21.taprootTweakPrivKey)(key, merkleRoot);
31337
30996
  if (!tweakedKey)
31338
30997
  throw new Error("Invalid private key for taproot tweaking");
31339
- const signature = import_secp256k114.schnorr.sign(sighash, tweakedKey);
30998
+ const signature = import_secp256k112.schnorr.sign(sighash, tweakedKey);
31340
30999
  unsignedTx.updateInput(0, {
31341
31000
  tapKeySig: signature
31342
31001
  });
@@ -31399,8 +31058,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
31399
31058
  return response;
31400
31059
  }
31401
31060
  async getNewAddress() {
31402
- const key = import_secp256k114.secp256k1.utils.randomPrivateKey();
31403
- const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
31061
+ const key = import_secp256k112.secp256k1.utils.randomPrivateKey();
31062
+ const pubKey = import_secp256k112.secp256k1.getPublicKey(key);
31404
31063
  return getP2TRAddressFromPublicKey(pubKey, 4 /* LOCAL */);
31405
31064
  }
31406
31065
  async sendToAddress(address2, amount, blocksToGenerate = 1) {
@@ -31421,8 +31080,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
31421
31080
  });
31422
31081
  const changeAmount = availableAmount - amount;
31423
31082
  if (changeAmount > 0) {
31424
- const changeKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
31425
- const changePubKey = import_secp256k114.secp256k1.getPublicKey(changeKey);
31083
+ const changeKey = import_secp256k112.secp256k1.utils.randomPrivateKey();
31084
+ const changePubKey = import_secp256k112.secp256k1.getPublicKey(changeKey);
31426
31085
  const changeScript = getP2TRScriptFromPublicKey(
31427
31086
  changePubKey,
31428
31087
  4 /* LOCAL */
@@ -31435,8 +31094,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
31435
31094
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
31436
31095
  const txHex = (0, import_utils20.bytesToHex)(signedTx.extract());
31437
31096
  await this.broadcastTx(txHex);
31438
- const randomKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
31439
- const randomPubKey = import_secp256k114.secp256k1.getPublicKey(randomKey);
31097
+ const randomKey = import_secp256k112.secp256k1.utils.randomPrivateKey();
31098
+ const randomPubKey = import_secp256k112.secp256k1.getPublicKey(randomKey);
31440
31099
  const randomAddress = getP2TRAddressFromPublicKey(
31441
31100
  randomPubKey,
31442
31101
  4 /* LOCAL */
@@ -32099,47 +31758,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32099
31758
  senderPublicKey,
32100
31759
  expiryTime
32101
31760
  }) {
32102
- const MAX_SATS_AMOUNT = 21e14;
32103
- if (amount && (amount < 0 || amount > MAX_SATS_AMOUNT)) {
32104
- throw new ValidationError(
32105
- `Amount must be between 0 and ${MAX_SATS_AMOUNT} sats`,
32106
- {
32107
- field: "amount",
32108
- value: amount,
32109
- expected: `less than or equal to ${MAX_SATS_AMOUNT}`
32110
- }
32111
- );
32112
- }
32113
- const protoPayment = {
32114
- $case: "satsPayment",
32115
- satsPayment: {
32116
- amount
32117
- }
32118
- };
32119
- const invoiceFields = {
32120
- version: 1,
32121
- id: (0, import_uuidv75.uuidv7obj)().bytes,
32122
- paymentType: protoPayment,
32123
- memo,
32124
- senderPublicKey: senderPublicKey ? (0, import_utils23.hexToBytes)(senderPublicKey) : void 0,
32125
- expiryTime: expiryTime ?? void 0
32126
- };
32127
- validateSparkInvoiceFields(invoiceFields);
32128
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
32129
- const hash = HashSparkInvoice(
32130
- invoiceFields,
32131
- identityPublicKey,
32132
- this.config.getNetworkType()
32133
- );
32134
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
32135
- return encodeSparkAddressWithSignature(
32136
- {
32137
- identityPublicKey: (0, import_utils23.bytesToHex)(identityPublicKey),
32138
- network: this.config.getNetworkType(),
32139
- sparkInvoiceFields: invoiceFields
32140
- },
32141
- signature
32142
- );
31761
+ throw new NotImplementedError("Invoice functionality is not enabled");
32143
31762
  }
32144
31763
  /**
32145
31764
  * Creates a Spark invoice for a tokens payment on Spark.
@@ -32159,52 +31778,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32159
31778
  senderPublicKey,
32160
31779
  expiryTime
32161
31780
  }) {
32162
- const MAX_UINT128 = BigInt(2 ** 128 - 1);
32163
- if (amount && (amount < 0 || amount > MAX_UINT128)) {
32164
- throw new ValidationError(`Amount must be between 0 and ${MAX_UINT128}`, {
32165
- field: "amount",
32166
- value: amount,
32167
- expected: `greater than or equal to 0 and less than or equal to ${MAX_UINT128}`
32168
- });
32169
- }
32170
- let decodedTokenIdentifier = void 0;
32171
- if (tokenIdentifier) {
32172
- decodedTokenIdentifier = decodeBech32mTokenIdentifier(
32173
- tokenIdentifier,
32174
- this.config.getNetworkType()
32175
- ).tokenIdentifier;
32176
- }
32177
- const protoPayment = {
32178
- $case: "tokensPayment",
32179
- tokensPayment: {
32180
- tokenIdentifier: decodedTokenIdentifier ?? void 0,
32181
- amount: amount ? (0, import_utils23.numberToVarBytesBE)(amount) : void 0
32182
- }
32183
- };
32184
- const invoiceFields = {
32185
- version: 1,
32186
- id: (0, import_uuidv75.uuidv7obj)().bytes,
32187
- paymentType: protoPayment,
32188
- memo: memo ?? void 0,
32189
- senderPublicKey: senderPublicKey ? (0, import_utils23.hexToBytes)(senderPublicKey) : void 0,
32190
- expiryTime: expiryTime ?? void 0
32191
- };
32192
- validateSparkInvoiceFields(invoiceFields);
32193
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
32194
- const hash = HashSparkInvoice(
32195
- invoiceFields,
32196
- identityPublicKey,
32197
- this.config.getNetworkType()
32198
- );
32199
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
32200
- return encodeSparkAddressWithSignature(
32201
- {
32202
- identityPublicKey: (0, import_utils23.bytesToHex)(identityPublicKey),
32203
- network: this.config.getNetworkType(),
32204
- sparkInvoiceFields: invoiceFields
32205
- },
32206
- signature
32207
- );
31781
+ throw new NotImplementedError("Invoice functionality is not enabled");
32208
31782
  }
32209
31783
  /**
32210
31784
  * Initializes the wallet using either a mnemonic phrase or a raw seed.
@@ -32529,7 +32103,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32529
32103
  }
32530
32104
  const sspClient = this.getSspClient();
32531
32105
  const cpfpAdaptorPubkey = (0, import_utils23.bytesToHex)(
32532
- import_secp256k115.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
32106
+ import_secp256k113.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
32533
32107
  );
32534
32108
  if (!cpfpAdaptorPubkey) {
32535
32109
  throw new Error("Failed to generate CPFP adaptor pubkey");
@@ -32537,13 +32111,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32537
32111
  let directAdaptorPubkey;
32538
32112
  if (directAdaptorPrivateKey.length > 0) {
32539
32113
  directAdaptorPubkey = (0, import_utils23.bytesToHex)(
32540
- import_secp256k115.secp256k1.getPublicKey(directAdaptorPrivateKey)
32114
+ import_secp256k113.secp256k1.getPublicKey(directAdaptorPrivateKey)
32541
32115
  );
32542
32116
  }
32543
32117
  let directFromCpfpAdaptorPubkey;
32544
32118
  if (directFromCpfpAdaptorPrivateKey.length > 0) {
32545
32119
  directFromCpfpAdaptorPubkey = (0, import_utils23.bytesToHex)(
32546
- import_secp256k115.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
32120
+ import_secp256k113.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
32547
32121
  );
32548
32122
  }
32549
32123
  let request = null;
@@ -34158,10 +33732,23 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34158
33732
  if (!invoice2) {
34159
33733
  throw new Error("Failed to create lightning invoice");
34160
33734
  }
33735
+ const decodedInvoice = decodeInvoice(invoice2.invoice.encodedInvoice);
33736
+ if (invoice2.invoice.paymentHash !== (0, import_utils23.bytesToHex)(paymentHash) || decodedInvoice.paymentHash !== (0, import_utils23.bytesToHex)(paymentHash)) {
33737
+ throw new ValidationError("Payment hash mismatch", {
33738
+ field: "paymentHash",
33739
+ value: invoice2.invoice.paymentHash,
33740
+ expected: (0, import_utils23.bytesToHex)(paymentHash)
33741
+ });
33742
+ }
33743
+ if (decodedInvoice.amountMSats !== BigInt(amountSats2 * 1e3)) {
33744
+ throw new ValidationError("Amount mismatch", {
33745
+ field: "amountMSats",
33746
+ value: decodedInvoice.amountMSats,
33747
+ expected: amountSats2 * 1e3
33748
+ });
33749
+ }
34161
33750
  if (includeSparkAddress) {
34162
- const sparkFallbackAddress = decodeInvoice(
34163
- invoice2.invoice.encodedInvoice
34164
- ).fallbackAddress;
33751
+ const sparkFallbackAddress = decodedInvoice.fallbackAddress;
34165
33752
  if (!sparkFallbackAddress) {
34166
33753
  throw new ValidationError(
34167
33754
  "No spark fallback address found in lightning invoice",
@@ -34183,6 +33770,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34183
33770
  }
34184
33771
  );
34185
33772
  }
33773
+ } else if (decodedInvoice.fallbackAddress !== void 0) {
33774
+ throw new ValidationError(
33775
+ "Spark fallback address found in lightning invoice but includeSparkAddress is false",
33776
+ {
33777
+ field: "sparkFallbackAddress",
33778
+ value: decodedInvoice.fallbackAddress
33779
+ }
33780
+ );
34186
33781
  }
34187
33782
  return invoice2;
34188
33783
  };
@@ -34350,91 +33945,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34350
33945
  });
34351
33946
  }
34352
33947
  async fulfillSparkInvoice(sparkInvoices) {
34353
- if (!Array.isArray(sparkInvoices) || sparkInvoices.length === 0) {
34354
- throw new ValidationError("No Spark invoices provided", {
34355
- field: "sparkInvoices",
34356
- value: sparkInvoices,
34357
- expected: "Non-empty array"
34358
- });
34359
- }
34360
- const satsTransactionSuccess = [];
34361
- const satsTransactionErrors = [];
34362
- const tokenTransactionSuccess = [];
34363
- const tokenTransactionErrors = [];
34364
- const { satsInvoices, tokenInvoices, invalidInvoices } = await this.groupSparkInvoicesByPaymentType(sparkInvoices);
34365
- if (invalidInvoices.length > 0) {
34366
- return {
34367
- satsTransactionSuccess,
34368
- satsTransactionErrors,
34369
- tokenTransactionSuccess,
34370
- tokenTransactionErrors,
34371
- invalidInvoices
34372
- };
34373
- }
34374
- if (tokenInvoices.size > 0) {
34375
- await this.syncTokenOutputs();
34376
- const tokenTransferTasks = [];
34377
- for (const [identifierHex, decodedInvoices] of tokenInvoices.entries()) {
34378
- const tokenIdentifier = (0, import_utils23.hexToBytes)(identifierHex);
34379
- const tokenIdB32 = encodeBech32mTokenIdentifier({
34380
- tokenIdentifier,
34381
- network: this.config.getNetworkType()
34382
- });
34383
- const receiverOutputs = decodedInvoices.map((d) => ({
34384
- tokenIdentifier: tokenIdB32,
34385
- tokenAmount: d.amount,
34386
- receiverSparkAddress: d.invoice
34387
- }));
34388
- tokenTransferTasks.push(
34389
- this.tokenTransactionService.tokenTransfer({ tokenOutputs: this.tokenOutputs, receiverOutputs }).then((txid) => ({
34390
- ok: true,
34391
- tokenIdentifier: tokenIdB32,
34392
- txid
34393
- })).catch((e) => ({
34394
- ok: false,
34395
- tokenIdentifier: tokenIdB32,
34396
- error: e instanceof Error ? e : new Error(String(e))
34397
- }))
34398
- );
34399
- }
34400
- const results = await Promise.all(tokenTransferTasks);
34401
- for (const r of results) {
34402
- if (r.ok) {
34403
- tokenTransactionSuccess.push({
34404
- tokenIdentifier: r.tokenIdentifier,
34405
- txid: r.txid
34406
- });
34407
- } else {
34408
- tokenTransactionErrors.push({
34409
- tokenIdentifier: r.tokenIdentifier,
34410
- error: r.error
34411
- });
34412
- }
34413
- }
34414
- }
34415
- if (satsInvoices.length > 0) {
34416
- const transfers = await this.transferWithInvoice(satsInvoices);
34417
- for (const transfer of transfers) {
34418
- if (transfer.ok) {
34419
- satsTransactionSuccess.push({
34420
- invoice: transfer.param.sparkInvoice ?? "",
34421
- transferResponse: transfer.transfer
34422
- });
34423
- } else {
34424
- satsTransactionErrors.push({
34425
- invoice: transfer.param.sparkInvoice ?? "",
34426
- error: transfer.error
34427
- });
34428
- }
34429
- }
34430
- }
34431
- return {
34432
- satsTransactionSuccess,
34433
- satsTransactionErrors,
34434
- tokenTransactionSuccess,
34435
- tokenTransactionErrors,
34436
- invalidInvoices
34437
- };
33948
+ throw new NotImplementedError("Invoice functionality is not enabled");
34438
33949
  }
34439
33950
  async groupSparkInvoicesByPaymentType(sparkInvoices) {
34440
33951
  const satsInvoices = [];
@@ -34571,6 +34082,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34571
34082
  });
34572
34083
  return { satsInvoices, tokenInvoices, invalidInvoices };
34573
34084
  }
34085
+ async querySparkInvoices(invoices) {
34086
+ throw new NotImplementedError("Invoice functionality is not enabled");
34087
+ }
34574
34088
  /**
34575
34089
  * Gets fee estimate for sending Lightning payments.
34576
34090
  *
@@ -35689,6 +35203,27 @@ async function isTxBroadcast(txid, baseUrl, network) {
35689
35203
  return true;
35690
35204
  }
35691
35205
 
35206
+ // src/utils/response-validation.ts
35207
+ function collectResponses(responses) {
35208
+ const successfulResponses = responses.filter(
35209
+ (result) => result.status === "fulfilled"
35210
+ ).map((result) => result.value);
35211
+ const failedResponses = responses.filter(
35212
+ (result) => result.status === "rejected"
35213
+ );
35214
+ if (failedResponses.length > 0) {
35215
+ const errors = failedResponses.map((result) => result.reason).join("\n");
35216
+ throw new NetworkError(
35217
+ `${failedResponses.length} out of ${responses.length} requests failed, please try again`,
35218
+ {
35219
+ errorCount: failedResponses.length,
35220
+ errors
35221
+ }
35222
+ );
35223
+ }
35224
+ return successfulResponses;
35225
+ }
35226
+
35692
35227
  // src/utils/unilateral-exit.ts
35693
35228
  var import_utils24 = require("@noble/curves/utils");
35694
35229
  var import_legacy = require("@noble/hashes/legacy");
@@ -36233,6 +35768,7 @@ setFetch(sparkBareFetch, Headers2);
36233
35768
  addPublicKeys,
36234
35769
  applyAdaptorToSignature,
36235
35770
  applyAdditiveTweakToPublicKey,
35771
+ assertBech32,
36236
35772
  bech32mDecode,
36237
35773
  bigIntToPrivateKey,
36238
35774
  checkIfSelectedOutputsAreAvailable,
@@ -36295,6 +35831,7 @@ setFetch(sparkBareFetch, Headers2);
36295
35831
  getTxId,
36296
35832
  getTxIdNoReverse,
36297
35833
  isEphemeralAnchorOutput,
35834
+ isLegacySparkAddress,
36298
35835
  isSafeForNumber,
36299
35836
  isTxBroadcast,
36300
35837
  isValidPublicKey,