@buildonspark/spark-sdk 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/bare/index.cjs +953 -1567
  3. package/dist/bare/index.d.cts +132 -29
  4. package/dist/bare/index.d.ts +132 -29
  5. package/dist/bare/index.js +948 -1565
  6. package/dist/{chunk-MGCUXELA.js → chunk-IC4IUEOS.js} +931 -125
  7. package/dist/{chunk-MH7BMOLL.js → chunk-J2P3KTQP.js} +1 -1
  8. package/dist/{chunk-JDQKNT7G.js → chunk-KIQTO4FX.js} +403 -1808
  9. package/dist/{chunk-73GJOG5R.js → chunk-XWLR6G5C.js} +1 -1
  10. package/dist/{chunk-4KGN75J4.js → chunk-YH7MDVTT.js} +1 -1
  11. package/dist/{client-DrjQwET9.d.ts → client-DBZ43pJT.d.ts} +1 -1
  12. package/dist/{client-DUFejFfn.d.cts → client-DWml6sjL.d.cts} +1 -1
  13. package/dist/debug.cjs +957 -1569
  14. package/dist/debug.d.cts +8 -5
  15. package/dist/debug.d.ts +8 -5
  16. package/dist/debug.js +4 -4
  17. package/dist/graphql/objects/index.d.cts +3 -3
  18. package/dist/graphql/objects/index.d.ts +3 -3
  19. package/dist/index.cjs +913 -1528
  20. package/dist/index.d.cts +6 -6
  21. package/dist/index.d.ts +6 -6
  22. package/dist/index.js +9 -5
  23. package/dist/index.node.cjs +913 -1528
  24. package/dist/index.node.d.cts +6 -6
  25. package/dist/index.node.d.ts +6 -6
  26. package/dist/index.node.js +8 -4
  27. package/dist/{logging-IsaT3wjW.d.ts → logging-BUpzk4Z6.d.cts} +5 -5
  28. package/dist/{logging-Bt2FNHFR.d.cts → logging-Dt2ooQiP.d.ts} +5 -5
  29. package/dist/native/index.cjs +913 -1528
  30. package/dist/native/index.d.cts +133 -44
  31. package/dist/native/index.d.ts +133 -44
  32. package/dist/native/index.js +912 -1529
  33. package/dist/proto/spark.cjs +931 -125
  34. package/dist/proto/spark.d.cts +1 -1
  35. package/dist/proto/spark.d.ts +1 -1
  36. package/dist/proto/spark.js +17 -1
  37. package/dist/proto/spark_token.d.cts +1 -1
  38. package/dist/proto/spark_token.d.ts +1 -1
  39. package/dist/proto/spark_token.js +2 -2
  40. package/dist/{spark-CLz4-Ln8.d.cts → spark-DasxuVfm.d.cts} +150 -5
  41. package/dist/{spark-CLz4-Ln8.d.ts → spark-DasxuVfm.d.ts} +150 -5
  42. package/dist/{spark-wallet-V03V4Tgm.d.cts → spark-wallet-BoMIOPWW.d.cts} +15 -26
  43. package/dist/{spark-wallet-KI68-_jO.d.ts → spark-wallet-jlC0XN5f.d.ts} +15 -26
  44. package/dist/{spark-wallet.node-Cuvw8Kvq.d.ts → spark-wallet.node-07PksUHH.d.cts} +1 -1
  45. package/dist/{spark-wallet.node-BtkqW5vn.d.cts → spark-wallet.node-CdWkKMSq.d.ts} +1 -1
  46. package/dist/tests/test-utils.cjs +951 -147
  47. package/dist/tests/test-utils.d.cts +4 -4
  48. package/dist/tests/test-utils.d.ts +4 -4
  49. package/dist/tests/test-utils.js +5 -5
  50. package/dist/{token-transactions-5XxBewhV.d.ts → token-transactions-BDzCrQSk.d.cts} +5 -19
  51. package/dist/{token-transactions-fTnCtBpp.d.cts → token-transactions-DscJaJOE.d.ts} +5 -19
  52. package/dist/types/index.cjs +923 -125
  53. package/dist/types/index.d.cts +2 -2
  54. package/dist/types/index.d.ts +2 -2
  55. package/dist/types/index.js +2 -2
  56. package/package.json +1 -1
  57. package/src/proto/spark.ts +1167 -103
  58. package/src/services/config.ts +0 -4
  59. package/src/services/token-transactions.ts +11 -703
  60. package/src/services/transfer.ts +2 -213
  61. package/src/services/wallet-config.ts +0 -2
  62. package/src/spark-wallet/proto-descriptors.ts +1 -1
  63. package/src/spark-wallet/spark-wallet.ts +47 -215
  64. package/src/spark_descriptors.pb +0 -0
  65. package/src/tests/address.test.ts +141 -0
  66. package/src/tests/integration/address.test.ts +4 -0
  67. package/src/tests/integration/lightning.test.ts +14 -9
  68. package/src/tests/integration/token-output.test.ts +0 -1
  69. package/src/tests/integration/transfer.test.ts +108 -2
  70. package/src/tests/token-hashing.test.ts +0 -247
  71. package/src/utils/address.ts +58 -35
  72. package/src/utils/token-hashing.ts +1 -420
  73. package/src/utils/token-transaction-validation.ts +0 -330
  74. package/src/utils/transaction.ts +8 -8
  75. package/src/tests/integration/swap.test.ts +0 -780
package/dist/index.cjs CHANGED
@@ -1450,6 +1450,7 @@ __export(index_exports, {
1450
1450
  addPublicKeys: () => addPublicKeys,
1451
1451
  applyAdaptorToSignature: () => applyAdaptorToSignature,
1452
1452
  applyAdditiveTweakToPublicKey: () => applyAdditiveTweakToPublicKey,
1453
+ assertBech32: () => assertBech32,
1453
1454
  bech32mDecode: () => bech32mDecode,
1454
1455
  bigIntToPrivateKey: () => bigIntToPrivateKey,
1455
1456
  checkIfSelectedOutputsAreAvailable: () => checkIfSelectedOutputsAreAvailable,
@@ -1513,6 +1514,7 @@ __export(index_exports, {
1513
1514
  getTxIdNoReverse: () => getTxIdNoReverse,
1514
1515
  initializeTracerEnv: () => initializeTracerEnvBrowser,
1515
1516
  isEphemeralAnchorOutput: () => isEphemeralAnchorOutput,
1517
+ isLegacySparkAddress: () => isLegacySparkAddress,
1516
1518
  isSafeForNumber: () => isSafeForNumber,
1517
1519
  isTxBroadcast: () => isTxBroadcast,
1518
1520
  isValidPublicKey: () => isValidPublicKey,
@@ -2276,9 +2278,9 @@ function invoiceStatusFromJSON(object) {
2276
2278
  case 2:
2277
2279
  case "FINALIZED":
2278
2280
  return 2 /* FINALIZED */;
2279
- case 3:
2280
- case "EXPIRED":
2281
- return 3 /* EXPIRED */;
2281
+ case 4:
2282
+ case "RETURNED":
2283
+ return 4 /* RETURNED */;
2282
2284
  case -1:
2283
2285
  case "UNRECOGNIZED":
2284
2286
  default:
@@ -2293,8 +2295,8 @@ function invoiceStatusToJSON(object) {
2293
2295
  return "PENDING";
2294
2296
  case 2 /* FINALIZED */:
2295
2297
  return "FINALIZED";
2296
- case 3 /* EXPIRED */:
2297
- return "EXPIRED";
2298
+ case 4 /* RETURNED */:
2299
+ return "RETURNED";
2298
2300
  case -1 /* UNRECOGNIZED */:
2299
2301
  default:
2300
2302
  return "UNRECOGNIZED";
@@ -4098,6 +4100,626 @@ var SigningResult_SignatureSharesEntry = {
4098
4100
  return message;
4099
4101
  }
4100
4102
  };
4103
+ function createBaseRenewLeafRequest() {
4104
+ return { leafId: "", ownerIdentityPublicKey: new Uint8Array(0), signingJobs: void 0 };
4105
+ }
4106
+ var RenewLeafRequest = {
4107
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4108
+ if (message.leafId !== "") {
4109
+ writer.uint32(10).string(message.leafId);
4110
+ }
4111
+ if (message.ownerIdentityPublicKey.length !== 0) {
4112
+ writer.uint32(18).bytes(message.ownerIdentityPublicKey);
4113
+ }
4114
+ switch (message.signingJobs?.$case) {
4115
+ case "renewNodeTimelockSigningJob":
4116
+ RenewNodeTimelockSigningJob.encode(message.signingJobs.renewNodeTimelockSigningJob, writer.uint32(26).fork()).join();
4117
+ break;
4118
+ case "renewRefundTimelockSigningJob":
4119
+ RenewRefundTimelockSigningJob.encode(
4120
+ message.signingJobs.renewRefundTimelockSigningJob,
4121
+ writer.uint32(34).fork()
4122
+ ).join();
4123
+ break;
4124
+ }
4125
+ return writer;
4126
+ },
4127
+ decode(input, length) {
4128
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4129
+ const end = length === void 0 ? reader.len : reader.pos + length;
4130
+ const message = createBaseRenewLeafRequest();
4131
+ while (reader.pos < end) {
4132
+ const tag = reader.uint32();
4133
+ switch (tag >>> 3) {
4134
+ case 1: {
4135
+ if (tag !== 10) {
4136
+ break;
4137
+ }
4138
+ message.leafId = reader.string();
4139
+ continue;
4140
+ }
4141
+ case 2: {
4142
+ if (tag !== 18) {
4143
+ break;
4144
+ }
4145
+ message.ownerIdentityPublicKey = reader.bytes();
4146
+ continue;
4147
+ }
4148
+ case 3: {
4149
+ if (tag !== 26) {
4150
+ break;
4151
+ }
4152
+ message.signingJobs = {
4153
+ $case: "renewNodeTimelockSigningJob",
4154
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.decode(reader, reader.uint32())
4155
+ };
4156
+ continue;
4157
+ }
4158
+ case 4: {
4159
+ if (tag !== 34) {
4160
+ break;
4161
+ }
4162
+ message.signingJobs = {
4163
+ $case: "renewRefundTimelockSigningJob",
4164
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.decode(reader, reader.uint32())
4165
+ };
4166
+ continue;
4167
+ }
4168
+ }
4169
+ if ((tag & 7) === 4 || tag === 0) {
4170
+ break;
4171
+ }
4172
+ reader.skip(tag & 7);
4173
+ }
4174
+ return message;
4175
+ },
4176
+ fromJSON(object) {
4177
+ return {
4178
+ leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : "",
4179
+ ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
4180
+ signingJobs: isSet3(object.renewNodeTimelockSigningJob) ? {
4181
+ $case: "renewNodeTimelockSigningJob",
4182
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromJSON(object.renewNodeTimelockSigningJob)
4183
+ } : isSet3(object.renewRefundTimelockSigningJob) ? {
4184
+ $case: "renewRefundTimelockSigningJob",
4185
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromJSON(object.renewRefundTimelockSigningJob)
4186
+ } : void 0
4187
+ };
4188
+ },
4189
+ toJSON(message) {
4190
+ const obj = {};
4191
+ if (message.leafId !== "") {
4192
+ obj.leafId = message.leafId;
4193
+ }
4194
+ if (message.ownerIdentityPublicKey.length !== 0) {
4195
+ obj.ownerIdentityPublicKey = base64FromBytes2(message.ownerIdentityPublicKey);
4196
+ }
4197
+ if (message.signingJobs?.$case === "renewNodeTimelockSigningJob") {
4198
+ obj.renewNodeTimelockSigningJob = RenewNodeTimelockSigningJob.toJSON(
4199
+ message.signingJobs.renewNodeTimelockSigningJob
4200
+ );
4201
+ } else if (message.signingJobs?.$case === "renewRefundTimelockSigningJob") {
4202
+ obj.renewRefundTimelockSigningJob = RenewRefundTimelockSigningJob.toJSON(
4203
+ message.signingJobs.renewRefundTimelockSigningJob
4204
+ );
4205
+ }
4206
+ return obj;
4207
+ },
4208
+ create(base) {
4209
+ return RenewLeafRequest.fromPartial(base ?? {});
4210
+ },
4211
+ fromPartial(object) {
4212
+ const message = createBaseRenewLeafRequest();
4213
+ message.leafId = object.leafId ?? "";
4214
+ message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
4215
+ switch (object.signingJobs?.$case) {
4216
+ case "renewNodeTimelockSigningJob": {
4217
+ if (object.signingJobs?.renewNodeTimelockSigningJob !== void 0 && object.signingJobs?.renewNodeTimelockSigningJob !== null) {
4218
+ message.signingJobs = {
4219
+ $case: "renewNodeTimelockSigningJob",
4220
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromPartial(
4221
+ object.signingJobs.renewNodeTimelockSigningJob
4222
+ )
4223
+ };
4224
+ }
4225
+ break;
4226
+ }
4227
+ case "renewRefundTimelockSigningJob": {
4228
+ if (object.signingJobs?.renewRefundTimelockSigningJob !== void 0 && object.signingJobs?.renewRefundTimelockSigningJob !== null) {
4229
+ message.signingJobs = {
4230
+ $case: "renewRefundTimelockSigningJob",
4231
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromPartial(
4232
+ object.signingJobs.renewRefundTimelockSigningJob
4233
+ )
4234
+ };
4235
+ }
4236
+ break;
4237
+ }
4238
+ }
4239
+ return message;
4240
+ }
4241
+ };
4242
+ function createBaseRenewNodeTimelockSigningJob() {
4243
+ return {
4244
+ splitNodeTxSigningJob: void 0,
4245
+ splitNodeDirectTxSigningJob: void 0,
4246
+ nodeTxSigningJob: void 0,
4247
+ refundTxSigningJob: void 0,
4248
+ directNodeTxSigningJob: void 0,
4249
+ directRefundTxSigningJob: void 0,
4250
+ directFromCpfpRefundTxSigningJob: void 0
4251
+ };
4252
+ }
4253
+ var RenewNodeTimelockSigningJob = {
4254
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4255
+ if (message.splitNodeTxSigningJob !== void 0) {
4256
+ UserSignedTxSigningJob.encode(message.splitNodeTxSigningJob, writer.uint32(10).fork()).join();
4257
+ }
4258
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
4259
+ UserSignedTxSigningJob.encode(message.splitNodeDirectTxSigningJob, writer.uint32(18).fork()).join();
4260
+ }
4261
+ if (message.nodeTxSigningJob !== void 0) {
4262
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(26).fork()).join();
4263
+ }
4264
+ if (message.refundTxSigningJob !== void 0) {
4265
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(34).fork()).join();
4266
+ }
4267
+ if (message.directNodeTxSigningJob !== void 0) {
4268
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(42).fork()).join();
4269
+ }
4270
+ if (message.directRefundTxSigningJob !== void 0) {
4271
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(50).fork()).join();
4272
+ }
4273
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4274
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(58).fork()).join();
4275
+ }
4276
+ return writer;
4277
+ },
4278
+ decode(input, length) {
4279
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4280
+ const end = length === void 0 ? reader.len : reader.pos + length;
4281
+ const message = createBaseRenewNodeTimelockSigningJob();
4282
+ while (reader.pos < end) {
4283
+ const tag = reader.uint32();
4284
+ switch (tag >>> 3) {
4285
+ case 1: {
4286
+ if (tag !== 10) {
4287
+ break;
4288
+ }
4289
+ message.splitNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4290
+ continue;
4291
+ }
4292
+ case 2: {
4293
+ if (tag !== 18) {
4294
+ break;
4295
+ }
4296
+ message.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4297
+ continue;
4298
+ }
4299
+ case 3: {
4300
+ if (tag !== 26) {
4301
+ break;
4302
+ }
4303
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4304
+ continue;
4305
+ }
4306
+ case 4: {
4307
+ if (tag !== 34) {
4308
+ break;
4309
+ }
4310
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4311
+ continue;
4312
+ }
4313
+ case 5: {
4314
+ if (tag !== 42) {
4315
+ break;
4316
+ }
4317
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4318
+ continue;
4319
+ }
4320
+ case 6: {
4321
+ if (tag !== 50) {
4322
+ break;
4323
+ }
4324
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4325
+ continue;
4326
+ }
4327
+ case 7: {
4328
+ if (tag !== 58) {
4329
+ break;
4330
+ }
4331
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4332
+ continue;
4333
+ }
4334
+ }
4335
+ if ((tag & 7) === 4 || tag === 0) {
4336
+ break;
4337
+ }
4338
+ reader.skip(tag & 7);
4339
+ }
4340
+ return message;
4341
+ },
4342
+ fromJSON(object) {
4343
+ return {
4344
+ splitNodeTxSigningJob: isSet3(object.splitNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeTxSigningJob) : void 0,
4345
+ splitNodeDirectTxSigningJob: isSet3(object.splitNodeDirectTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeDirectTxSigningJob) : void 0,
4346
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
4347
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
4348
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
4349
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
4350
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
4351
+ };
4352
+ },
4353
+ toJSON(message) {
4354
+ const obj = {};
4355
+ if (message.splitNodeTxSigningJob !== void 0) {
4356
+ obj.splitNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeTxSigningJob);
4357
+ }
4358
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
4359
+ obj.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeDirectTxSigningJob);
4360
+ }
4361
+ if (message.nodeTxSigningJob !== void 0) {
4362
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
4363
+ }
4364
+ if (message.refundTxSigningJob !== void 0) {
4365
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
4366
+ }
4367
+ if (message.directNodeTxSigningJob !== void 0) {
4368
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
4369
+ }
4370
+ if (message.directRefundTxSigningJob !== void 0) {
4371
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
4372
+ }
4373
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4374
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
4375
+ }
4376
+ return obj;
4377
+ },
4378
+ create(base) {
4379
+ return RenewNodeTimelockSigningJob.fromPartial(base ?? {});
4380
+ },
4381
+ fromPartial(object) {
4382
+ const message = createBaseRenewNodeTimelockSigningJob();
4383
+ message.splitNodeTxSigningJob = object.splitNodeTxSigningJob !== void 0 && object.splitNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeTxSigningJob) : void 0;
4384
+ message.splitNodeDirectTxSigningJob = object.splitNodeDirectTxSigningJob !== void 0 && object.splitNodeDirectTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeDirectTxSigningJob) : void 0;
4385
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
4386
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
4387
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
4388
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
4389
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
4390
+ return message;
4391
+ }
4392
+ };
4393
+ function createBaseRenewRefundTimelockSigningJob() {
4394
+ return {
4395
+ nodeTxSigningJob: void 0,
4396
+ refundTxSigningJob: void 0,
4397
+ directNodeTxSigningJob: void 0,
4398
+ directRefundTxSigningJob: void 0,
4399
+ directFromCpfpRefundTxSigningJob: void 0
4400
+ };
4401
+ }
4402
+ var RenewRefundTimelockSigningJob = {
4403
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4404
+ if (message.nodeTxSigningJob !== void 0) {
4405
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(10).fork()).join();
4406
+ }
4407
+ if (message.refundTxSigningJob !== void 0) {
4408
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(18).fork()).join();
4409
+ }
4410
+ if (message.directNodeTxSigningJob !== void 0) {
4411
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(26).fork()).join();
4412
+ }
4413
+ if (message.directRefundTxSigningJob !== void 0) {
4414
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(34).fork()).join();
4415
+ }
4416
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4417
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(42).fork()).join();
4418
+ }
4419
+ return writer;
4420
+ },
4421
+ decode(input, length) {
4422
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4423
+ const end = length === void 0 ? reader.len : reader.pos + length;
4424
+ const message = createBaseRenewRefundTimelockSigningJob();
4425
+ while (reader.pos < end) {
4426
+ const tag = reader.uint32();
4427
+ switch (tag >>> 3) {
4428
+ case 1: {
4429
+ if (tag !== 10) {
4430
+ break;
4431
+ }
4432
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4433
+ continue;
4434
+ }
4435
+ case 2: {
4436
+ if (tag !== 18) {
4437
+ break;
4438
+ }
4439
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4440
+ continue;
4441
+ }
4442
+ case 3: {
4443
+ if (tag !== 26) {
4444
+ break;
4445
+ }
4446
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4447
+ continue;
4448
+ }
4449
+ case 4: {
4450
+ if (tag !== 34) {
4451
+ break;
4452
+ }
4453
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4454
+ continue;
4455
+ }
4456
+ case 5: {
4457
+ if (tag !== 42) {
4458
+ break;
4459
+ }
4460
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4461
+ continue;
4462
+ }
4463
+ }
4464
+ if ((tag & 7) === 4 || tag === 0) {
4465
+ break;
4466
+ }
4467
+ reader.skip(tag & 7);
4468
+ }
4469
+ return message;
4470
+ },
4471
+ fromJSON(object) {
4472
+ return {
4473
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
4474
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
4475
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
4476
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
4477
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
4478
+ };
4479
+ },
4480
+ toJSON(message) {
4481
+ const obj = {};
4482
+ if (message.nodeTxSigningJob !== void 0) {
4483
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
4484
+ }
4485
+ if (message.refundTxSigningJob !== void 0) {
4486
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
4487
+ }
4488
+ if (message.directNodeTxSigningJob !== void 0) {
4489
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
4490
+ }
4491
+ if (message.directRefundTxSigningJob !== void 0) {
4492
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
4493
+ }
4494
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4495
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
4496
+ }
4497
+ return obj;
4498
+ },
4499
+ create(base) {
4500
+ return RenewRefundTimelockSigningJob.fromPartial(base ?? {});
4501
+ },
4502
+ fromPartial(object) {
4503
+ const message = createBaseRenewRefundTimelockSigningJob();
4504
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
4505
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
4506
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
4507
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
4508
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
4509
+ return message;
4510
+ }
4511
+ };
4512
+ function createBaseRenewLeafResponse() {
4513
+ return { renewResult: void 0 };
4514
+ }
4515
+ var RenewLeafResponse = {
4516
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4517
+ switch (message.renewResult?.$case) {
4518
+ case "extendResult":
4519
+ RenewNodeTimelockResult.encode(message.renewResult.extendResult, writer.uint32(10).fork()).join();
4520
+ break;
4521
+ case "refreshResult":
4522
+ RenewRefundTimelockResult.encode(message.renewResult.refreshResult, writer.uint32(18).fork()).join();
4523
+ break;
4524
+ }
4525
+ return writer;
4526
+ },
4527
+ decode(input, length) {
4528
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4529
+ const end = length === void 0 ? reader.len : reader.pos + length;
4530
+ const message = createBaseRenewLeafResponse();
4531
+ while (reader.pos < end) {
4532
+ const tag = reader.uint32();
4533
+ switch (tag >>> 3) {
4534
+ case 1: {
4535
+ if (tag !== 10) {
4536
+ break;
4537
+ }
4538
+ message.renewResult = {
4539
+ $case: "extendResult",
4540
+ extendResult: RenewNodeTimelockResult.decode(reader, reader.uint32())
4541
+ };
4542
+ continue;
4543
+ }
4544
+ case 2: {
4545
+ if (tag !== 18) {
4546
+ break;
4547
+ }
4548
+ message.renewResult = {
4549
+ $case: "refreshResult",
4550
+ refreshResult: RenewRefundTimelockResult.decode(reader, reader.uint32())
4551
+ };
4552
+ continue;
4553
+ }
4554
+ }
4555
+ if ((tag & 7) === 4 || tag === 0) {
4556
+ break;
4557
+ }
4558
+ reader.skip(tag & 7);
4559
+ }
4560
+ return message;
4561
+ },
4562
+ fromJSON(object) {
4563
+ return {
4564
+ renewResult: isSet3(object.extendResult) ? { $case: "extendResult", extendResult: RenewNodeTimelockResult.fromJSON(object.extendResult) } : isSet3(object.refreshResult) ? { $case: "refreshResult", refreshResult: RenewRefundTimelockResult.fromJSON(object.refreshResult) } : void 0
4565
+ };
4566
+ },
4567
+ toJSON(message) {
4568
+ const obj = {};
4569
+ if (message.renewResult?.$case === "extendResult") {
4570
+ obj.extendResult = RenewNodeTimelockResult.toJSON(message.renewResult.extendResult);
4571
+ } else if (message.renewResult?.$case === "refreshResult") {
4572
+ obj.refreshResult = RenewRefundTimelockResult.toJSON(message.renewResult.refreshResult);
4573
+ }
4574
+ return obj;
4575
+ },
4576
+ create(base) {
4577
+ return RenewLeafResponse.fromPartial(base ?? {});
4578
+ },
4579
+ fromPartial(object) {
4580
+ const message = createBaseRenewLeafResponse();
4581
+ switch (object.renewResult?.$case) {
4582
+ case "extendResult": {
4583
+ if (object.renewResult?.extendResult !== void 0 && object.renewResult?.extendResult !== null) {
4584
+ message.renewResult = {
4585
+ $case: "extendResult",
4586
+ extendResult: RenewNodeTimelockResult.fromPartial(object.renewResult.extendResult)
4587
+ };
4588
+ }
4589
+ break;
4590
+ }
4591
+ case "refreshResult": {
4592
+ if (object.renewResult?.refreshResult !== void 0 && object.renewResult?.refreshResult !== null) {
4593
+ message.renewResult = {
4594
+ $case: "refreshResult",
4595
+ refreshResult: RenewRefundTimelockResult.fromPartial(object.renewResult.refreshResult)
4596
+ };
4597
+ }
4598
+ break;
4599
+ }
4600
+ }
4601
+ return message;
4602
+ }
4603
+ };
4604
+ function createBaseRenewNodeTimelockResult() {
4605
+ return { splitNode: void 0, node: void 0 };
4606
+ }
4607
+ var RenewNodeTimelockResult = {
4608
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4609
+ if (message.splitNode !== void 0) {
4610
+ TreeNode.encode(message.splitNode, writer.uint32(10).fork()).join();
4611
+ }
4612
+ if (message.node !== void 0) {
4613
+ TreeNode.encode(message.node, writer.uint32(18).fork()).join();
4614
+ }
4615
+ return writer;
4616
+ },
4617
+ decode(input, length) {
4618
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4619
+ const end = length === void 0 ? reader.len : reader.pos + length;
4620
+ const message = createBaseRenewNodeTimelockResult();
4621
+ while (reader.pos < end) {
4622
+ const tag = reader.uint32();
4623
+ switch (tag >>> 3) {
4624
+ case 1: {
4625
+ if (tag !== 10) {
4626
+ break;
4627
+ }
4628
+ message.splitNode = TreeNode.decode(reader, reader.uint32());
4629
+ continue;
4630
+ }
4631
+ case 2: {
4632
+ if (tag !== 18) {
4633
+ break;
4634
+ }
4635
+ message.node = TreeNode.decode(reader, reader.uint32());
4636
+ continue;
4637
+ }
4638
+ }
4639
+ if ((tag & 7) === 4 || tag === 0) {
4640
+ break;
4641
+ }
4642
+ reader.skip(tag & 7);
4643
+ }
4644
+ return message;
4645
+ },
4646
+ fromJSON(object) {
4647
+ return {
4648
+ splitNode: isSet3(object.splitNode) ? TreeNode.fromJSON(object.splitNode) : void 0,
4649
+ node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0
4650
+ };
4651
+ },
4652
+ toJSON(message) {
4653
+ const obj = {};
4654
+ if (message.splitNode !== void 0) {
4655
+ obj.splitNode = TreeNode.toJSON(message.splitNode);
4656
+ }
4657
+ if (message.node !== void 0) {
4658
+ obj.node = TreeNode.toJSON(message.node);
4659
+ }
4660
+ return obj;
4661
+ },
4662
+ create(base) {
4663
+ return RenewNodeTimelockResult.fromPartial(base ?? {});
4664
+ },
4665
+ fromPartial(object) {
4666
+ const message = createBaseRenewNodeTimelockResult();
4667
+ message.splitNode = object.splitNode !== void 0 && object.splitNode !== null ? TreeNode.fromPartial(object.splitNode) : void 0;
4668
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
4669
+ return message;
4670
+ }
4671
+ };
4672
+ function createBaseRenewRefundTimelockResult() {
4673
+ return { node: void 0 };
4674
+ }
4675
+ var RenewRefundTimelockResult = {
4676
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4677
+ if (message.node !== void 0) {
4678
+ TreeNode.encode(message.node, writer.uint32(10).fork()).join();
4679
+ }
4680
+ return writer;
4681
+ },
4682
+ decode(input, length) {
4683
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4684
+ const end = length === void 0 ? reader.len : reader.pos + length;
4685
+ const message = createBaseRenewRefundTimelockResult();
4686
+ while (reader.pos < end) {
4687
+ const tag = reader.uint32();
4688
+ switch (tag >>> 3) {
4689
+ case 1: {
4690
+ if (tag !== 10) {
4691
+ break;
4692
+ }
4693
+ message.node = TreeNode.decode(reader, reader.uint32());
4694
+ continue;
4695
+ }
4696
+ }
4697
+ if ((tag & 7) === 4 || tag === 0) {
4698
+ break;
4699
+ }
4700
+ reader.skip(tag & 7);
4701
+ }
4702
+ return message;
4703
+ },
4704
+ fromJSON(object) {
4705
+ return { node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0 };
4706
+ },
4707
+ toJSON(message) {
4708
+ const obj = {};
4709
+ if (message.node !== void 0) {
4710
+ obj.node = TreeNode.toJSON(message.node);
4711
+ }
4712
+ return obj;
4713
+ },
4714
+ create(base) {
4715
+ return RenewRefundTimelockResult.fromPartial(base ?? {});
4716
+ },
4717
+ fromPartial(object) {
4718
+ const message = createBaseRenewRefundTimelockResult();
4719
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
4720
+ return message;
4721
+ }
4722
+ };
4101
4723
  function createBaseNodeSignatureShares() {
4102
4724
  return {
4103
4725
  nodeId: "",
@@ -15878,7 +16500,7 @@ var QuerySparkInvoicesResponse = {
15878
16500
  }
15879
16501
  };
15880
16502
  function createBaseInvoiceResponse() {
15881
- return { invoice: "", status: 0 };
16503
+ return { invoice: "", status: 0, transferType: void 0 };
15882
16504
  }
15883
16505
  var InvoiceResponse = {
15884
16506
  encode(message, writer = new import_wire4.BinaryWriter()) {
@@ -15888,6 +16510,14 @@ var InvoiceResponse = {
15888
16510
  if (message.status !== 0) {
15889
16511
  writer.uint32(16).int32(message.status);
15890
16512
  }
16513
+ switch (message.transferType?.$case) {
16514
+ case "satsTransfer":
16515
+ SatsTransfer.encode(message.transferType.satsTransfer, writer.uint32(26).fork()).join();
16516
+ break;
16517
+ case "tokenTransfer":
16518
+ TokenTransfer.encode(message.transferType.tokenTransfer, writer.uint32(34).fork()).join();
16519
+ break;
16520
+ }
15891
16521
  return writer;
15892
16522
  },
15893
16523
  decode(input, length) {
@@ -15911,6 +16541,23 @@ var InvoiceResponse = {
15911
16541
  message.status = reader.int32();
15912
16542
  continue;
15913
16543
  }
16544
+ case 3: {
16545
+ if (tag !== 26) {
16546
+ break;
16547
+ }
16548
+ message.transferType = { $case: "satsTransfer", satsTransfer: SatsTransfer.decode(reader, reader.uint32()) };
16549
+ continue;
16550
+ }
16551
+ case 4: {
16552
+ if (tag !== 34) {
16553
+ break;
16554
+ }
16555
+ message.transferType = {
16556
+ $case: "tokenTransfer",
16557
+ tokenTransfer: TokenTransfer.decode(reader, reader.uint32())
16558
+ };
16559
+ continue;
16560
+ }
15914
16561
  }
15915
16562
  if ((tag & 7) === 4 || tag === 0) {
15916
16563
  break;
@@ -15922,7 +16569,8 @@ var InvoiceResponse = {
15922
16569
  fromJSON(object) {
15923
16570
  return {
15924
16571
  invoice: isSet3(object.invoice) ? globalThis.String(object.invoice) : "",
15925
- status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0
16572
+ status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0,
16573
+ transferType: isSet3(object.satsTransfer) ? { $case: "satsTransfer", satsTransfer: SatsTransfer.fromJSON(object.satsTransfer) } : isSet3(object.tokenTransfer) ? { $case: "tokenTransfer", tokenTransfer: TokenTransfer.fromJSON(object.tokenTransfer) } : void 0
15926
16574
  };
15927
16575
  },
15928
16576
  toJSON(message) {
@@ -15933,6 +16581,11 @@ var InvoiceResponse = {
15933
16581
  if (message.status !== 0) {
15934
16582
  obj.status = invoiceStatusToJSON(message.status);
15935
16583
  }
16584
+ if (message.transferType?.$case === "satsTransfer") {
16585
+ obj.satsTransfer = SatsTransfer.toJSON(message.transferType.satsTransfer);
16586
+ } else if (message.transferType?.$case === "tokenTransfer") {
16587
+ obj.tokenTransfer = TokenTransfer.toJSON(message.transferType.tokenTransfer);
16588
+ }
15936
16589
  return obj;
15937
16590
  },
15938
16591
  create(base) {
@@ -15942,6 +16595,130 @@ var InvoiceResponse = {
15942
16595
  const message = createBaseInvoiceResponse();
15943
16596
  message.invoice = object.invoice ?? "";
15944
16597
  message.status = object.status ?? 0;
16598
+ switch (object.transferType?.$case) {
16599
+ case "satsTransfer": {
16600
+ if (object.transferType?.satsTransfer !== void 0 && object.transferType?.satsTransfer !== null) {
16601
+ message.transferType = {
16602
+ $case: "satsTransfer",
16603
+ satsTransfer: SatsTransfer.fromPartial(object.transferType.satsTransfer)
16604
+ };
16605
+ }
16606
+ break;
16607
+ }
16608
+ case "tokenTransfer": {
16609
+ if (object.transferType?.tokenTransfer !== void 0 && object.transferType?.tokenTransfer !== null) {
16610
+ message.transferType = {
16611
+ $case: "tokenTransfer",
16612
+ tokenTransfer: TokenTransfer.fromPartial(object.transferType.tokenTransfer)
16613
+ };
16614
+ }
16615
+ break;
16616
+ }
16617
+ }
16618
+ return message;
16619
+ }
16620
+ };
16621
+ function createBaseSatsTransfer() {
16622
+ return { transferId: new Uint8Array(0) };
16623
+ }
16624
+ var SatsTransfer = {
16625
+ encode(message, writer = new import_wire4.BinaryWriter()) {
16626
+ if (message.transferId.length !== 0) {
16627
+ writer.uint32(10).bytes(message.transferId);
16628
+ }
16629
+ return writer;
16630
+ },
16631
+ decode(input, length) {
16632
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
16633
+ const end = length === void 0 ? reader.len : reader.pos + length;
16634
+ const message = createBaseSatsTransfer();
16635
+ while (reader.pos < end) {
16636
+ const tag = reader.uint32();
16637
+ switch (tag >>> 3) {
16638
+ case 1: {
16639
+ if (tag !== 10) {
16640
+ break;
16641
+ }
16642
+ message.transferId = reader.bytes();
16643
+ continue;
16644
+ }
16645
+ }
16646
+ if ((tag & 7) === 4 || tag === 0) {
16647
+ break;
16648
+ }
16649
+ reader.skip(tag & 7);
16650
+ }
16651
+ return message;
16652
+ },
16653
+ fromJSON(object) {
16654
+ return { transferId: isSet3(object.transferId) ? bytesFromBase642(object.transferId) : new Uint8Array(0) };
16655
+ },
16656
+ toJSON(message) {
16657
+ const obj = {};
16658
+ if (message.transferId.length !== 0) {
16659
+ obj.transferId = base64FromBytes2(message.transferId);
16660
+ }
16661
+ return obj;
16662
+ },
16663
+ create(base) {
16664
+ return SatsTransfer.fromPartial(base ?? {});
16665
+ },
16666
+ fromPartial(object) {
16667
+ const message = createBaseSatsTransfer();
16668
+ message.transferId = object.transferId ?? new Uint8Array(0);
16669
+ return message;
16670
+ }
16671
+ };
16672
+ function createBaseTokenTransfer() {
16673
+ return { finalTokenTransactionHash: new Uint8Array(0) };
16674
+ }
16675
+ var TokenTransfer = {
16676
+ encode(message, writer = new import_wire4.BinaryWriter()) {
16677
+ if (message.finalTokenTransactionHash.length !== 0) {
16678
+ writer.uint32(10).bytes(message.finalTokenTransactionHash);
16679
+ }
16680
+ return writer;
16681
+ },
16682
+ decode(input, length) {
16683
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
16684
+ const end = length === void 0 ? reader.len : reader.pos + length;
16685
+ const message = createBaseTokenTransfer();
16686
+ while (reader.pos < end) {
16687
+ const tag = reader.uint32();
16688
+ switch (tag >>> 3) {
16689
+ case 1: {
16690
+ if (tag !== 10) {
16691
+ break;
16692
+ }
16693
+ message.finalTokenTransactionHash = reader.bytes();
16694
+ continue;
16695
+ }
16696
+ }
16697
+ if ((tag & 7) === 4 || tag === 0) {
16698
+ break;
16699
+ }
16700
+ reader.skip(tag & 7);
16701
+ }
16702
+ return message;
16703
+ },
16704
+ fromJSON(object) {
16705
+ return {
16706
+ finalTokenTransactionHash: isSet3(object.finalTokenTransactionHash) ? bytesFromBase642(object.finalTokenTransactionHash) : new Uint8Array(0)
16707
+ };
16708
+ },
16709
+ toJSON(message) {
16710
+ const obj = {};
16711
+ if (message.finalTokenTransactionHash.length !== 0) {
16712
+ obj.finalTokenTransactionHash = base64FromBytes2(message.finalTokenTransactionHash);
16713
+ }
16714
+ return obj;
16715
+ },
16716
+ create(base) {
16717
+ return TokenTransfer.fromPartial(base ?? {});
16718
+ },
16719
+ fromPartial(object) {
16720
+ const message = createBaseTokenTransfer();
16721
+ message.finalTokenTransactionHash = object.finalTokenTransactionHash ?? new Uint8Array(0);
15945
16722
  return message;
15946
16723
  }
15947
16724
  };
@@ -16157,6 +16934,21 @@ var SparkServiceDefinition = {
16157
16934
  responseStream: false,
16158
16935
  options: {}
16159
16936
  },
16937
+ /**
16938
+ * Resets the timelocks for a leaf's transactions. Can be used to reset the
16939
+ * refund transaction timelock for a leaf (when the node transaction
16940
+ * timelock is still > 300) or reset the node and refund transaction
16941
+ * timelock. Returns an error if a leaf is not yet eligible to renew the
16942
+ * timelocks, see RenewLeafRequest for more details.
16943
+ */
16944
+ renew_leaf: {
16945
+ name: "renew_leaf",
16946
+ requestType: RenewLeafRequest,
16947
+ requestStream: false,
16948
+ responseType: RenewLeafResponse,
16949
+ responseStream: false,
16950
+ options: {}
16951
+ },
16160
16952
  get_signing_operator_list: {
16161
16953
  name: "get_signing_operator_list",
16162
16954
  requestType: Empty,
@@ -16647,6 +17439,13 @@ function uint64be(value) {
16647
17439
  // src/utils/address.ts
16648
17440
  var BECH32M_LIMIT = 1024;
16649
17441
  var AddressNetwork = {
17442
+ MAINNET: "spark",
17443
+ TESTNET: "sparkt",
17444
+ REGTEST: "sparkrt",
17445
+ SIGNET: "sparks",
17446
+ LOCAL: "sparkl"
17447
+ };
17448
+ var LegacyAddressNetwork = {
16650
17449
  MAINNET: "sp",
16651
17450
  TESTNET: "spt",
16652
17451
  REGTEST: "sprt",
@@ -16677,7 +17476,7 @@ function encodeSparkAddressWithSignature(payload, signature) {
16677
17476
  const serializedPayload = w.finish();
16678
17477
  const words = import_base2.bech32m.toWords(serializedPayload);
16679
17478
  return bech32mEncode(
16680
- AddressNetwork[payload.network],
17479
+ LegacyAddressNetwork[payload.network],
16681
17480
  words
16682
17481
  );
16683
17482
  } catch (error) {
@@ -16693,14 +17492,14 @@ function encodeSparkAddressWithSignature(payload, signature) {
16693
17492
  }
16694
17493
  function decodeSparkAddress(address2, network) {
16695
17494
  try {
16696
- const decoded = bech32mDecode(address2);
16697
- if (decoded.prefix !== AddressNetwork[network]) {
17495
+ if (network !== getNetworkFromSparkAddress(address2)) {
16698
17496
  throw new ValidationError("Invalid Spark address prefix", {
16699
17497
  field: "address",
16700
17498
  value: address2,
16701
- expected: `prefix='${AddressNetwork[network]}'`
17499
+ expected: `prefix='${AddressNetwork[network]}' or '${LegacyAddressNetwork[network]}'`
16702
17500
  });
16703
17501
  }
17502
+ const decoded = bech32mDecode(address2);
16704
17503
  const payload = SparkAddress.decode(import_base2.bech32m.fromWords(decoded.words));
16705
17504
  const { identityPublicKey, sparkInvoiceFields, signature } = payload;
16706
17505
  const identityPubkeyHex = (0, import_utils3.bytesToHex)(identityPublicKey);
@@ -16744,18 +17543,35 @@ function decodeSparkAddress(address2, network) {
16744
17543
  );
16745
17544
  }
16746
17545
  }
17546
+ var PrefixToNetwork = Object.fromEntries(
17547
+ Object.entries(AddressNetwork).map(([k, v]) => [v, k])
17548
+ );
17549
+ var LegacyPrefixToNetwork = Object.fromEntries(
17550
+ Object.entries(LegacyAddressNetwork).map(([k, v]) => [v, k])
17551
+ );
17552
+ function getNetworkFromSparkAddress(address2) {
17553
+ const { prefix } = bech32mDecode(address2);
17554
+ const network = PrefixToNetwork[prefix] ?? LegacyPrefixToNetwork[prefix];
17555
+ if (!network) {
17556
+ throw new ValidationError("Invalid Spark address prefix", {
17557
+ field: "network",
17558
+ value: address2,
17559
+ expected: "prefix='spark1', 'sparkt1', 'sparkrt1', 'sparks1', 'sparkl1' or legacy ('sp1', 'spt1', 'sprt1', 'sps1', 'spl1')"
17560
+ });
17561
+ }
17562
+ return network;
17563
+ }
17564
+ function isLegacySparkAddress(address2) {
17565
+ try {
17566
+ const { prefix } = bech32mDecode(address2);
17567
+ return prefix in LegacyPrefixToNetwork;
17568
+ } catch (error) {
17569
+ return false;
17570
+ }
17571
+ }
16747
17572
  function isValidSparkAddress(address2) {
16748
17573
  try {
16749
- const network = Object.entries(AddressNetwork).find(
16750
- ([_, prefix]) => address2.startsWith(prefix)
16751
- )?.[0];
16752
- if (!network) {
16753
- throw new ValidationError("Invalid Spark address network", {
16754
- field: "network",
16755
- value: address2,
16756
- expected: Object.values(AddressNetwork)
16757
- });
16758
- }
17574
+ const network = getNetworkFromSparkAddress(address2);
16759
17575
  decodeSparkAddress(address2, network);
16760
17576
  return true;
16761
17577
  } catch (error) {
@@ -16951,25 +17767,16 @@ function validateSparkInvoiceSignature(invoice) {
16951
17767
  );
16952
17768
  }
16953
17769
  }
16954
- function getNetworkFromSparkAddress(address2) {
16955
- const { prefix } = bech32mDecode(address2);
16956
- const network = Object.entries(AddressNetwork).find(
16957
- ([, p]) => p === prefix
16958
- )?.[0];
16959
- if (!network) {
16960
- throw new ValidationError("Invalid Spark address network", {
16961
- field: "network",
16962
- value: address2,
16963
- expected: Object.values(AddressNetwork)
16964
- });
16965
- }
16966
- return network;
16967
- }
16968
17770
  function toProtoTimestamp(date) {
16969
17771
  const ms = date.getTime();
16970
17772
  return { seconds: Math.floor(ms / 1e3), nanos: ms % 1e3 * 1e6 };
16971
17773
  }
17774
+ function assertBech32(s) {
17775
+ const i = s.lastIndexOf("1");
17776
+ if (i <= 0 || i >= s.length - 1) throw new Error("invalid bech32 string");
17777
+ }
16972
17778
  function bech32mDecode(address2) {
17779
+ assertBech32(address2);
16973
17780
  return import_base2.bech32m.decode(address2, BECH32M_LIMIT);
16974
17781
  }
16975
17782
  function bech32mEncode(prefix, words) {
@@ -17582,7 +18389,6 @@ var BASE_CONFIG = {
17582
18389
  threshold: 2,
17583
18390
  signingOperators: getLocalSigningOperators(),
17584
18391
  tokenSignatures: "SCHNORR",
17585
- tokenTransactionVersion: "V1",
17586
18392
  tokenValidityDurationSeconds: 180,
17587
18393
  electrsUrl: getElectrsUrl("LOCAL"),
17588
18394
  expectedWithdrawBondSats: 1e4,
@@ -19257,10 +20063,10 @@ var INITIAL_TIMELOCK = 2e3;
19257
20063
  var TEST_UNILATERAL_TIMELOCK = 100;
19258
20064
  var TIME_LOCK_INTERVAL = 100;
19259
20065
  var DIRECT_TIMELOCK_OFFSET = 50;
19260
- var INITIAL_SEQUENCE = INITIAL_TIMELOCK;
19261
- var INITIAL_DIRECT_SEQUENCE = INITIAL_TIMELOCK + DIRECT_TIMELOCK_OFFSET;
19262
- var TEST_UNILATERAL_SEQUENCE = TEST_UNILATERAL_TIMELOCK;
19263
- var TEST_UNILATERAL_DIRECT_SEQUENCE = TEST_UNILATERAL_TIMELOCK + DIRECT_TIMELOCK_OFFSET;
20066
+ var INITIAL_SEQUENCE = 1 << 30 | INITIAL_TIMELOCK;
20067
+ var INITIAL_DIRECT_SEQUENCE = 1 << 30 | INITIAL_TIMELOCK + DIRECT_TIMELOCK_OFFSET;
20068
+ var TEST_UNILATERAL_SEQUENCE = 1 << 30 | TEST_UNILATERAL_TIMELOCK;
20069
+ var TEST_UNILATERAL_DIRECT_SEQUENCE = 1 << 30 | TEST_UNILATERAL_TIMELOCK + DIRECT_TIMELOCK_OFFSET;
19264
20070
  var ESTIMATED_TX_SIZE = 191;
19265
20071
  var DEFAULT_SATS_PER_VBYTE = 5;
19266
20072
  var DEFAULT_FEE_SATS = ESTIMATED_TX_SIZE * DEFAULT_SATS_PER_VBYTE;
@@ -19531,8 +20337,8 @@ function getCurrentTimelock(currSequence) {
19531
20337
  function getTransactionSequence(currSequence) {
19532
20338
  const timelock = getCurrentTimelock(currSequence);
19533
20339
  return {
19534
- nextSequence: timelock,
19535
- nextDirectSequence: timelock + DIRECT_TIMELOCK_OFFSET
20340
+ nextSequence: 1 << 30 | timelock,
20341
+ nextDirectSequence: 1 << 30 | timelock + DIRECT_TIMELOCK_OFFSET
19536
20342
  };
19537
20343
  }
19538
20344
  function checkIfValidSequence(currSequence) {
@@ -19575,8 +20381,8 @@ function getNextTransactionSequence(currSequence, isNodeTx) {
19575
20381
  });
19576
20382
  }
19577
20383
  return {
19578
- nextSequence: nextTimelock,
19579
- nextDirectSequence: nextTimelock + DIRECT_TIMELOCK_OFFSET
20384
+ nextSequence: 1 << 30 | nextTimelock,
20385
+ nextDirectSequence: 1 << 30 | nextTimelock + DIRECT_TIMELOCK_OFFSET
19580
20386
  };
19581
20387
  }
19582
20388
  function getEphemeralAnchorOutput() {
@@ -20112,7 +20918,7 @@ var isWebExtension = (
20112
20918
  "chrome" in globalThis && globalThis.chrome.runtime?.id
20113
20919
  );
20114
20920
  var userAgent = "navigator" in globalThis ? globalThis.navigator.userAgent || "unknown-user-agent" : void 0;
20115
- var packageVersion = true ? "0.3.2" : "unknown";
20921
+ var packageVersion = true ? "0.3.4" : "unknown";
20116
20922
  var baseEnvStr = "unknown";
20117
20923
  if (isBun) {
20118
20924
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -20646,7 +21452,7 @@ init_buffer();
20646
21452
  // src/spark-wallet/spark-wallet.ts
20647
21453
  init_buffer();
20648
21454
  var import_core13 = require("@lightsparkdev/core");
20649
- var import_secp256k115 = require("@noble/curves/secp256k1");
21455
+ var import_secp256k113 = require("@noble/curves/secp256k1");
20650
21456
  var import_utils24 = require("@noble/curves/utils");
20651
21457
  var import_bip392 = require("@scure/bip39");
20652
21458
  var import_english2 = require("@scure/bip39/wordlists/english");
@@ -21876,9 +22682,6 @@ var WalletConfigService = class {
21876
22682
  getTokenSignatures() {
21877
22683
  return this.config.tokenSignatures;
21878
22684
  }
21879
- getTokenTransactionVersion() {
21880
- return this.config.tokenTransactionVersion;
21881
- }
21882
22685
  getTokenValidityDurationSeconds() {
21883
22686
  return this.config.tokenValidityDurationSeconds;
21884
22687
  }
@@ -26066,51 +26869,6 @@ var BaseTransferService = class {
26066
26869
  this.connectionManager = connectionManager;
26067
26870
  this.signingService = signingService;
26068
26871
  }
26069
- async sendTransferTweakKey(transfer, leaves, cpfpRefundSignatureMap, directRefundSignatureMap, directFromCpfpRefundSignatureMap) {
26070
- const keyTweakInputMap = await this.prepareSendTransferKeyTweaks(
26071
- transfer.id,
26072
- transfer.receiverIdentityPublicKey,
26073
- leaves,
26074
- cpfpRefundSignatureMap,
26075
- directRefundSignatureMap,
26076
- directFromCpfpRefundSignatureMap
26077
- );
26078
- let updatedTransfer;
26079
- const coordinatorOperator = this.config.getSigningOperators()[this.config.getCoordinatorIdentifier()];
26080
- if (!coordinatorOperator) {
26081
- throw new ValidationError("Coordinator operator not found", {
26082
- field: "coordinator"
26083
- });
26084
- }
26085
- for (const [identifier, operator] of Object.entries(
26086
- this.config.getSigningOperators()
26087
- ).filter(([_, op]) => op.address !== this.config.getCoordinatorAddress())) {
26088
- updatedTransfer = await this.finalizeTransfer(
26089
- operator,
26090
- identifier,
26091
- keyTweakInputMap,
26092
- transfer,
26093
- updatedTransfer
26094
- );
26095
- }
26096
- updatedTransfer = await this.finalizeTransfer(
26097
- coordinatorOperator,
26098
- this.config.getCoordinatorIdentifier(),
26099
- keyTweakInputMap,
26100
- transfer,
26101
- updatedTransfer
26102
- );
26103
- if (!updatedTransfer) {
26104
- throw new ValidationError(
26105
- "No transfer response received from any operator",
26106
- {
26107
- field: "operators",
26108
- value: Object.keys(this.config.getSigningOperators()).length
26109
- }
26110
- );
26111
- }
26112
- return updatedTransfer;
26113
- }
26114
26872
  async deliverTransferPackage(transfer, leaves, cpfpRefundSignatureMap, directRefundSignatureMap, directFromCpfpRefundSignatureMap) {
26115
26873
  const keyTweakInputMap = await this.prepareSendTransferKeyTweaks(
26116
26874
  transfer.id,
@@ -26252,55 +27010,7 @@ var BaseTransferService = class {
26252
27010
  transferPackage.userSignature = new Uint8Array(signature);
26253
27011
  return transferPackage;
26254
27012
  }
26255
- async finalizeTransfer(operator, identifier, keyTweakInputMap, transfer, updatedTransfer) {
26256
- const sparkClient = await this.connectionManager.createSparkClient(
26257
- operator.address
26258
- );
26259
- const leavesToSend = keyTweakInputMap.get(identifier);
26260
- if (!leavesToSend) {
26261
- throw new ValidationError("No leaves to send for operator", {
26262
- field: "operator",
26263
- value: identifier
26264
- });
26265
- }
26266
- let transferResp;
26267
- try {
26268
- transferResp = await sparkClient.finalize_transfer({
26269
- transferId: transfer.id,
26270
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
26271
- leavesToSend
26272
- });
26273
- } catch (error) {
26274
- throw new NetworkError(
26275
- "Failed to finalize transfer",
26276
- {
26277
- method: "POST"
26278
- },
26279
- error
26280
- );
26281
- }
26282
- if (!updatedTransfer) {
26283
- updatedTransfer = transferResp.transfer;
26284
- } else {
26285
- if (!transferResp.transfer) {
26286
- throw new ValidationError("No transfer response from operator", {
26287
- field: "transfer",
26288
- value: transfer.id
26289
- });
26290
- }
26291
- if (!this.compareTransfers(updatedTransfer, transferResp.transfer)) {
26292
- throw new ValidationError(
26293
- "Inconsistent transfer response from operators",
26294
- {
26295
- field: "transfer",
26296
- value: transfer.id
26297
- }
26298
- );
26299
- }
26300
- }
26301
- return updatedTransfer;
26302
- }
26303
- async signRefunds(leafDataMap, operatorSigningResults, cpfpAdaptorPubKey, directAdaptorPubKey, directFromCpfpAdaptorPubKey) {
27013
+ async signRefunds(leafDataMap, operatorSigningResults) {
26304
27014
  const nodeSignatures = [];
26305
27015
  for (const operatorSigningResult of operatorSigningResults) {
26306
27016
  const leafData = leafDataMap.get(operatorSigningResult.leafId);
@@ -26329,7 +27039,6 @@ var BaseTransferService = class {
26329
27039
  keyDerivation: leafData.keyDerivation,
26330
27040
  selfCommitment: leafData.signingNonceCommitment,
26331
27041
  statechainCommitments: operatorSigningResult.refundTxSigningResult?.signingNonceCommitments,
26332
- adaptorPubKey: cpfpAdaptorPubKey,
26333
27042
  verifyingKey: operatorSigningResult.verifyingKey
26334
27043
  });
26335
27044
  const cpfpRefundAggregate = await this.config.signer.aggregateFrost({
@@ -26340,8 +27049,7 @@ var BaseTransferService = class {
26340
27049
  statechainCommitments: operatorSigningResult.refundTxSigningResult?.signingNonceCommitments,
26341
27050
  selfCommitment: leafData.signingNonceCommitment,
26342
27051
  publicKey,
26343
- selfSignature: cpfpUserSignature,
26344
- adaptorPubKey: cpfpAdaptorPubKey
27052
+ selfSignature: cpfpUserSignature
26345
27053
  });
26346
27054
  let directRefundAggregate;
26347
27055
  let directFromCpfpRefundAggregate;
@@ -26359,7 +27067,6 @@ var BaseTransferService = class {
26359
27067
  keyDerivation: leafData.keyDerivation,
26360
27068
  selfCommitment: leafData.directSigningNonceCommitment,
26361
27069
  statechainCommitments: operatorSigningResult.directRefundTxSigningResult?.signingNonceCommitments,
26362
- adaptorPubKey: directAdaptorPubKey,
26363
27070
  verifyingKey: operatorSigningResult.verifyingKey
26364
27071
  });
26365
27072
  directRefundAggregate = await this.config.signer.aggregateFrost({
@@ -26370,8 +27077,7 @@ var BaseTransferService = class {
26370
27077
  statechainCommitments: operatorSigningResult.directRefundTxSigningResult?.signingNonceCommitments,
26371
27078
  selfCommitment: leafData.directSigningNonceCommitment,
26372
27079
  publicKey,
26373
- selfSignature: directUserSignature,
26374
- adaptorPubKey: directAdaptorPubKey
27080
+ selfSignature: directUserSignature
26375
27081
  });
26376
27082
  }
26377
27083
  if (leafData.directFromCpfpRefundTx) {
@@ -26386,7 +27092,6 @@ var BaseTransferService = class {
26386
27092
  keyDerivation: leafData.keyDerivation,
26387
27093
  selfCommitment: leafData.directFromCpfpRefundSigningNonceCommitment,
26388
27094
  statechainCommitments: operatorSigningResult.directFromCpfpRefundTxSigningResult?.signingNonceCommitments,
26389
- adaptorPubKey: directFromCpfpAdaptorPubKey,
26390
27095
  verifyingKey: operatorSigningResult.verifyingKey
26391
27096
  });
26392
27097
  directFromCpfpRefundAggregate = await this.config.signer.aggregateFrost({
@@ -26397,8 +27102,7 @@ var BaseTransferService = class {
26397
27102
  statechainCommitments: operatorSigningResult.directFromCpfpRefundTxSigningResult?.signingNonceCommitments,
26398
27103
  selfCommitment: leafData.directFromCpfpRefundSigningNonceCommitment,
26399
27104
  publicKey,
26400
- selfSignature: directFromCpfpUserSignature,
26401
- adaptorPubKey: directFromCpfpAdaptorPubKey
27105
+ selfSignature: directFromCpfpUserSignature
26402
27106
  });
26403
27107
  }
26404
27108
  }
@@ -26514,30 +27218,6 @@ var TransferService = class extends BaseTransferService {
26514
27218
  constructor(config, connectionManager, signingService) {
26515
27219
  super(config, connectionManager, signingService);
26516
27220
  }
26517
- /**
26518
- * @deprecated Use sendTransferWithKeyTweaks instead
26519
- * Deprecated in v0.1.32
26520
- */
26521
- async sendTransfer(leaves, receiverIdentityPubkey) {
26522
- const {
26523
- transfer,
26524
- signatureMap,
26525
- directSignatureMap,
26526
- directFromCpfpSignatureMap
26527
- } = await this.sendTransferSignRefund(
26528
- leaves,
26529
- receiverIdentityPubkey,
26530
- new Date(Date.now() + DEFAULT_EXPIRY_TIME)
26531
- );
26532
- const transferWithTweakedKeys = await this.sendTransferTweakKey(
26533
- transfer,
26534
- leaves,
26535
- signatureMap,
26536
- directSignatureMap,
26537
- directFromCpfpSignatureMap
26538
- );
26539
- return transferWithTweakedKeys;
26540
- }
26541
27221
  async claimTransfer(transfer, leaves) {
26542
27222
  let proofMap;
26543
27223
  if (transfer.status === 2 /* TRANSFER_STATUS_SENDER_KEY_TWEAKED */) {
@@ -26681,18 +27361,7 @@ var TransferService = class extends BaseTransferService {
26681
27361
  leafDataMap
26682
27362
  };
26683
27363
  }
26684
- async counterSwapSignRefund(leaves, receiverIdentityPubkey, expiryTime, cpfpAdaptorPubKey, directAdaptorPubKey, directFromCpfpAdaptorPubKey) {
26685
- return this.sendTransferSignRefundInternal(
26686
- leaves,
26687
- receiverIdentityPubkey,
26688
- expiryTime,
26689
- true,
26690
- cpfpAdaptorPubKey,
26691
- directAdaptorPubKey,
26692
- directFromCpfpAdaptorPubKey
26693
- );
26694
- }
26695
- async sendTransferSignRefundInternal(leaves, receiverIdentityPubkey, expiryTime, forSwap, cpfpAdaptorPubKey, directAdaptorPubKey, directFromCpfpAdaptorPubKey) {
27364
+ async sendTransferSignRefundInternal(leaves, receiverIdentityPubkey, expiryTime, forSwap) {
26696
27365
  const transferId = (0, import_uuidv72.uuidv7)();
26697
27366
  const leafDataMap = /* @__PURE__ */ new Map();
26698
27367
  for (const leaf of leaves) {
@@ -26727,21 +27396,7 @@ var TransferService = class extends BaseTransferService {
26727
27396
  );
26728
27397
  let response;
26729
27398
  try {
26730
- if (cpfpAdaptorPubKey !== void 0 || directAdaptorPubKey !== void 0 || directFromCpfpAdaptorPubKey !== void 0) {
26731
- response = await sparkClient.counter_leaf_swap_v2({
26732
- transfer: {
26733
- transferId,
26734
- leavesToSend: signingJobs,
26735
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
26736
- receiverIdentityPublicKey: receiverIdentityPubkey,
26737
- expiryTime
26738
- },
26739
- swapId: (0, import_uuidv72.uuidv7)(),
26740
- adaptorPublicKey: cpfpAdaptorPubKey,
26741
- directAdaptorPublicKey: directAdaptorPubKey,
26742
- directFromCpfpAdaptorPublicKey: directFromCpfpAdaptorPubKey
26743
- });
26744
- } else if (forSwap) {
27399
+ if (forSwap) {
26745
27400
  response = await sparkClient.start_leaf_swap_v2({
26746
27401
  transferId,
26747
27402
  leavesToSend: signingJobs,
@@ -26766,10 +27421,7 @@ var TransferService = class extends BaseTransferService {
26766
27421
  }
26767
27422
  const signatures = await this.signRefunds(
26768
27423
  leafDataMap,
26769
- response.signingResults,
26770
- cpfpAdaptorPubKey,
26771
- directAdaptorPubKey,
26772
- directFromCpfpAdaptorPubKey
27424
+ response.signingResults
26773
27425
  );
26774
27426
  const cpfpSignatureMap = /* @__PURE__ */ new Map();
26775
27427
  const directSignatureMap = /* @__PURE__ */ new Map();
@@ -28924,7 +29576,6 @@ var LightningService = class {
28924
29576
 
28925
29577
  // src/services/token-transactions.ts
28926
29578
  init_buffer();
28927
- var import_secp256k113 = require("@noble/curves/secp256k1");
28928
29579
  var import_utils19 = require("@noble/curves/utils");
28929
29580
  var import_utils20 = require("@noble/hashes/utils");
28930
29581
 
@@ -28934,8 +29585,6 @@ var import_sha212 = require("@noble/hashes/sha2");
28934
29585
  var import_base4 = require("@scure/base");
28935
29586
  function hashTokenTransaction(tokenTransaction, partialHash = false) {
28936
29587
  switch (tokenTransaction.version) {
28937
- case 0:
28938
- return hashTokenTransactionV0(tokenTransaction, partialHash);
28939
29588
  case 1:
28940
29589
  return hashTokenTransactionV1(tokenTransaction, partialHash);
28941
29590
  case 2:
@@ -28947,345 +29596,6 @@ function hashTokenTransaction(tokenTransaction, partialHash = false) {
28947
29596
  });
28948
29597
  }
28949
29598
  }
28950
- function hashTokenTransactionV0(tokenTransaction, partialHash = false) {
28951
- if (!tokenTransaction) {
28952
- throw new ValidationError("token transaction cannot be nil", {
28953
- field: "tokenTransaction"
28954
- });
28955
- }
28956
- let allHashes = [];
28957
- if (tokenTransaction.tokenInputs?.$case === "transferInput") {
28958
- if (!tokenTransaction.tokenInputs.transferInput.outputsToSpend) {
28959
- throw new ValidationError("outputs to spend cannot be null", {
28960
- field: "tokenInputs.transferInput.outputsToSpend"
28961
- });
28962
- }
28963
- if (tokenTransaction.tokenInputs.transferInput.outputsToSpend.length === 0) {
28964
- throw new ValidationError("outputs to spend cannot be empty", {
28965
- field: "tokenInputs.transferInput.outputsToSpend"
28966
- });
28967
- }
28968
- for (const [
28969
- i,
28970
- output
28971
- ] of tokenTransaction.tokenInputs.transferInput.outputsToSpend.entries()) {
28972
- if (!output) {
28973
- throw new ValidationError(`output cannot be null at index ${i}`, {
28974
- field: `tokenInputs.transferInput.outputsToSpend[${i}]`,
28975
- index: i
28976
- });
28977
- }
28978
- const hashObj2 = import_sha212.sha256.create();
28979
- if (output.prevTokenTransactionHash) {
28980
- const prevHash = output.prevTokenTransactionHash;
28981
- if (output.prevTokenTransactionHash.length !== 32) {
28982
- throw new ValidationError(
28983
- `invalid previous transaction hash length at index ${i}`,
28984
- {
28985
- field: `tokenInputs.transferInput.outputsToSpend[${i}].prevTokenTransactionHash`,
28986
- value: prevHash,
28987
- expectedLength: 32,
28988
- actualLength: prevHash.length,
28989
- index: i
28990
- }
28991
- );
28992
- }
28993
- hashObj2.update(output.prevTokenTransactionHash);
28994
- }
28995
- const voutBytes = new Uint8Array(4);
28996
- new DataView(voutBytes.buffer).setUint32(
28997
- 0,
28998
- output.prevTokenTransactionVout,
28999
- false
29000
- );
29001
- hashObj2.update(voutBytes);
29002
- allHashes.push(hashObj2.digest());
29003
- }
29004
- }
29005
- if (tokenTransaction.tokenInputs?.$case === "mintInput") {
29006
- const hashObj2 = import_sha212.sha256.create();
29007
- if (tokenTransaction.tokenInputs.mintInput.issuerPublicKey) {
29008
- const issuerPubKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
29009
- if (issuerPubKey.length === 0) {
29010
- throw new ValidationError("issuer public key cannot be empty", {
29011
- field: "tokenInputs.mintInput.issuerPublicKey",
29012
- value: issuerPubKey,
29013
- expectedLength: 1,
29014
- actualLength: 0
29015
- });
29016
- }
29017
- hashObj2.update(issuerPubKey);
29018
- let timestampValue = 0;
29019
- const mintInput = tokenTransaction.tokenInputs.mintInput;
29020
- if ("issuerProvidedTimestamp" in mintInput) {
29021
- const v0MintInput = mintInput;
29022
- if (v0MintInput.issuerProvidedTimestamp != 0) {
29023
- timestampValue = v0MintInput.issuerProvidedTimestamp;
29024
- }
29025
- } else if ("clientCreatedTimestamp" in tokenTransaction && tokenTransaction.clientCreatedTimestamp) {
29026
- timestampValue = tokenTransaction.clientCreatedTimestamp.getTime();
29027
- }
29028
- if (timestampValue != 0) {
29029
- const timestampBytes = new Uint8Array(8);
29030
- new DataView(timestampBytes.buffer).setBigUint64(
29031
- 0,
29032
- BigInt(timestampValue),
29033
- true
29034
- // true for little-endian to match Go implementation
29035
- );
29036
- hashObj2.update(timestampBytes);
29037
- }
29038
- allHashes.push(hashObj2.digest());
29039
- }
29040
- }
29041
- if (tokenTransaction.tokenInputs?.$case === "createInput") {
29042
- const issuerPubKeyHashObj = import_sha212.sha256.create();
29043
- const createInput = tokenTransaction.tokenInputs.createInput;
29044
- if (!createInput.issuerPublicKey || createInput.issuerPublicKey.length === 0) {
29045
- throw new ValidationError("issuer public key cannot be nil or empty", {
29046
- field: "tokenInputs.createInput.issuerPublicKey"
29047
- });
29048
- }
29049
- issuerPubKeyHashObj.update(createInput.issuerPublicKey);
29050
- allHashes.push(issuerPubKeyHashObj.digest());
29051
- const tokenNameHashObj = import_sha212.sha256.create();
29052
- if (!createInput.tokenName || createInput.tokenName.length === 0) {
29053
- throw new ValidationError("token name cannot be empty", {
29054
- field: "tokenInputs.createInput.tokenName"
29055
- });
29056
- }
29057
- if (createInput.tokenName.length > 20) {
29058
- throw new ValidationError("token name cannot be longer than 20 bytes", {
29059
- field: "tokenInputs.createInput.tokenName",
29060
- value: createInput.tokenName,
29061
- expectedLength: 20,
29062
- actualLength: createInput.tokenName.length
29063
- });
29064
- }
29065
- const tokenNameBytes = new Uint8Array(20);
29066
- const tokenNameEncoder = new TextEncoder();
29067
- tokenNameBytes.set(tokenNameEncoder.encode(createInput.tokenName));
29068
- tokenNameHashObj.update(tokenNameBytes);
29069
- allHashes.push(tokenNameHashObj.digest());
29070
- const tokenTickerHashObj = import_sha212.sha256.create();
29071
- if (!createInput.tokenTicker || createInput.tokenTicker.length === 0) {
29072
- throw new ValidationError("token ticker cannot be empty", {
29073
- field: "tokenInputs.createInput.tokenTicker"
29074
- });
29075
- }
29076
- if (createInput.tokenTicker.length > 6) {
29077
- throw new ValidationError("token ticker cannot be longer than 6 bytes", {
29078
- field: "tokenInputs.createInput.tokenTicker",
29079
- value: createInput.tokenTicker,
29080
- expectedLength: 6,
29081
- actualLength: createInput.tokenTicker.length
29082
- });
29083
- }
29084
- const tokenTickerBytes = new Uint8Array(6);
29085
- const tokenTickerEncoder = new TextEncoder();
29086
- tokenTickerBytes.set(tokenTickerEncoder.encode(createInput.tokenTicker));
29087
- tokenTickerHashObj.update(tokenTickerBytes);
29088
- allHashes.push(tokenTickerHashObj.digest());
29089
- const decimalsHashObj = import_sha212.sha256.create();
29090
- const decimalsBytes = new Uint8Array(4);
29091
- new DataView(decimalsBytes.buffer).setUint32(
29092
- 0,
29093
- createInput.decimals,
29094
- false
29095
- );
29096
- decimalsHashObj.update(decimalsBytes);
29097
- allHashes.push(decimalsHashObj.digest());
29098
- const maxSupplyHashObj = import_sha212.sha256.create();
29099
- if (!createInput.maxSupply) {
29100
- throw new ValidationError("max supply cannot be nil", {
29101
- field: "tokenInputs.createInput.maxSupply"
29102
- });
29103
- }
29104
- if (createInput.maxSupply.length !== 16) {
29105
- throw new ValidationError("max supply must be exactly 16 bytes", {
29106
- field: "tokenInputs.createInput.maxSupply",
29107
- value: createInput.maxSupply,
29108
- expectedLength: 16,
29109
- actualLength: createInput.maxSupply.length
29110
- });
29111
- }
29112
- maxSupplyHashObj.update(createInput.maxSupply);
29113
- allHashes.push(maxSupplyHashObj.digest());
29114
- const isFreezableHashObj = import_sha212.sha256.create();
29115
- const isFreezableByte = new Uint8Array([createInput.isFreezable ? 1 : 0]);
29116
- isFreezableHashObj.update(isFreezableByte);
29117
- allHashes.push(isFreezableHashObj.digest());
29118
- const creationEntityHashObj = import_sha212.sha256.create();
29119
- if (!partialHash && createInput.creationEntityPublicKey) {
29120
- creationEntityHashObj.update(createInput.creationEntityPublicKey);
29121
- }
29122
- allHashes.push(creationEntityHashObj.digest());
29123
- }
29124
- if (!tokenTransaction.tokenOutputs) {
29125
- throw new ValidationError("token outputs cannot be null", {
29126
- field: "tokenOutputs"
29127
- });
29128
- }
29129
- if (tokenTransaction.tokenOutputs.length === 0 && tokenTransaction.tokenInputs?.$case !== "createInput") {
29130
- throw new ValidationError("token outputs cannot be empty", {
29131
- field: "tokenOutputs"
29132
- });
29133
- }
29134
- for (const [i, output] of tokenTransaction.tokenOutputs.entries()) {
29135
- if (!output) {
29136
- throw new ValidationError(`output cannot be null at index ${i}`, {
29137
- field: `tokenOutputs[${i}]`,
29138
- index: i
29139
- });
29140
- }
29141
- const hashObj2 = import_sha212.sha256.create();
29142
- if (output.id && !partialHash) {
29143
- if (output.id.length === 0) {
29144
- throw new ValidationError(`output ID at index ${i} cannot be empty`, {
29145
- field: `tokenOutputs[${i}].id`,
29146
- index: i
29147
- });
29148
- }
29149
- hashObj2.update(new TextEncoder().encode(output.id));
29150
- }
29151
- if (output.ownerPublicKey) {
29152
- if (output.ownerPublicKey.length === 0) {
29153
- throw new ValidationError(
29154
- `owner public key at index ${i} cannot be empty`,
29155
- {
29156
- field: `tokenOutputs[${i}].ownerPublicKey`,
29157
- index: i
29158
- }
29159
- );
29160
- }
29161
- hashObj2.update(output.ownerPublicKey);
29162
- }
29163
- if (!partialHash) {
29164
- const revPubKey = output.revocationCommitment;
29165
- if (revPubKey) {
29166
- if (revPubKey.length === 0) {
29167
- throw new ValidationError(
29168
- `revocation commitment at index ${i} cannot be empty`,
29169
- {
29170
- field: `tokenOutputs[${i}].revocationCommitment`,
29171
- index: i
29172
- }
29173
- );
29174
- }
29175
- hashObj2.update(revPubKey);
29176
- }
29177
- const bondBytes = new Uint8Array(8);
29178
- new DataView(bondBytes.buffer).setBigUint64(
29179
- 0,
29180
- BigInt(output.withdrawBondSats),
29181
- false
29182
- );
29183
- hashObj2.update(bondBytes);
29184
- const locktimeBytes = new Uint8Array(8);
29185
- new DataView(locktimeBytes.buffer).setBigUint64(
29186
- 0,
29187
- BigInt(output.withdrawRelativeBlockLocktime),
29188
- false
29189
- );
29190
- hashObj2.update(locktimeBytes);
29191
- }
29192
- if (output.tokenPublicKey) {
29193
- if (output.tokenPublicKey.length === 0) {
29194
- throw new ValidationError(
29195
- `token public key at index ${i} cannot be empty`,
29196
- {
29197
- field: `tokenOutputs[${i}].tokenPublicKey`,
29198
- index: i
29199
- }
29200
- );
29201
- }
29202
- hashObj2.update(output.tokenPublicKey);
29203
- }
29204
- if (output.tokenAmount) {
29205
- if (output.tokenAmount.length === 0) {
29206
- throw new ValidationError(
29207
- `token amount at index ${i} cannot be empty`,
29208
- {
29209
- field: `tokenOutputs[${i}].tokenAmount`,
29210
- index: i
29211
- }
29212
- );
29213
- }
29214
- if (output.tokenAmount.length > 16) {
29215
- throw new ValidationError(
29216
- `token amount at index ${i} exceeds maximum length`,
29217
- {
29218
- field: `tokenOutputs[${i}].tokenAmount`,
29219
- value: output.tokenAmount,
29220
- expectedLength: 16,
29221
- actualLength: output.tokenAmount.length,
29222
- index: i
29223
- }
29224
- );
29225
- }
29226
- hashObj2.update(output.tokenAmount);
29227
- }
29228
- allHashes.push(hashObj2.digest());
29229
- }
29230
- if (!tokenTransaction.sparkOperatorIdentityPublicKeys) {
29231
- throw new ValidationError(
29232
- "spark operator identity public keys cannot be null",
29233
- {}
29234
- );
29235
- }
29236
- const sortedPubKeys = [
29237
- ...tokenTransaction.sparkOperatorIdentityPublicKeys || []
29238
- ].sort((a, b) => {
29239
- for (let i = 0; i < a.length && i < b.length; i++) {
29240
- if (a[i] !== b[i]) return a[i] - b[i];
29241
- }
29242
- return a.length - b.length;
29243
- });
29244
- for (const [i, pubKey] of sortedPubKeys.entries()) {
29245
- if (!pubKey) {
29246
- throw new ValidationError(
29247
- `operator public key at index ${i} cannot be null`,
29248
- {
29249
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
29250
- index: i
29251
- }
29252
- );
29253
- }
29254
- if (pubKey.length === 0) {
29255
- throw new ValidationError(
29256
- `operator public key at index ${i} cannot be empty`,
29257
- {
29258
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
29259
- index: i
29260
- }
29261
- );
29262
- }
29263
- const hashObj2 = import_sha212.sha256.create();
29264
- hashObj2.update(pubKey);
29265
- allHashes.push(hashObj2.digest());
29266
- }
29267
- const hashObj = import_sha212.sha256.create();
29268
- let networkBytes = new Uint8Array(4);
29269
- new DataView(networkBytes.buffer).setUint32(
29270
- 0,
29271
- tokenTransaction.network.valueOf(),
29272
- false
29273
- // false for big-endian
29274
- );
29275
- hashObj.update(networkBytes);
29276
- allHashes.push(hashObj.digest());
29277
- const finalHashObj = import_sha212.sha256.create();
29278
- const concatenatedHashes = new Uint8Array(
29279
- allHashes.reduce((sum, hash) => sum + hash.length, 0)
29280
- );
29281
- let offset = 0;
29282
- for (const hash of allHashes) {
29283
- concatenatedHashes.set(hash, offset);
29284
- offset += hash.length;
29285
- }
29286
- finalHashObj.update(concatenatedHashes);
29287
- return finalHashObj.digest();
29288
- }
29289
29599
  function hashTokenTransactionV1(tokenTransaction, partialHash = false) {
29290
29600
  if (!tokenTransaction) {
29291
29601
  throw new ValidationError("token transaction cannot be nil", {
@@ -30215,24 +30525,6 @@ function hashOperatorSpecificTokenTransactionSignablePayload(payload) {
30215
30525
  return finalHashObj.digest();
30216
30526
  }
30217
30527
 
30218
- // src/utils/token-keyshares.ts
30219
- init_buffer();
30220
- var import_secp256k112 = require("@noble/curves/secp256k1");
30221
- function recoverRevocationSecretFromKeyshares(keyshares, threshold) {
30222
- const shares = keyshares.map((keyshare) => ({
30223
- fieldModulus: BigInt("0x" + import_secp256k112.secp256k1.CURVE.n.toString(16)),
30224
- // secp256k1 curve order
30225
- threshold,
30226
- index: BigInt(keyshare.operatorIndex),
30227
- share: BigInt(
30228
- "0x" + import_buffer.Buffer.from(keyshare.keyshare.keyshare).toString("hex")
30229
- ),
30230
- proofs: []
30231
- }));
30232
- const recoveredSecret = recoverSecret(shares);
30233
- return bigIntToPrivateKey(recoveredSecret);
30234
- }
30235
-
30236
30528
  // src/utils/token-transaction-validation.ts
30237
30529
  init_buffer();
30238
30530
  function areByteArraysEqual(a, b) {
@@ -30244,250 +30536,6 @@ function areByteArraysEqual(a, b) {
30244
30536
  function hasDuplicates(array) {
30245
30537
  return new Set(array).size !== array.length;
30246
30538
  }
30247
- function validateTokenTransactionV0(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
30248
- if (finalTokenTransaction.network !== partialTokenTransaction.network) {
30249
- throw new InternalValidationError(
30250
- "Network mismatch in response token transaction",
30251
- {
30252
- value: finalTokenTransaction.network,
30253
- expected: partialTokenTransaction.network
30254
- }
30255
- );
30256
- }
30257
- if (!finalTokenTransaction.tokenInputs) {
30258
- throw new InternalValidationError(
30259
- "Token inputs missing in final transaction",
30260
- {
30261
- value: finalTokenTransaction
30262
- }
30263
- );
30264
- }
30265
- if (!partialTokenTransaction.tokenInputs) {
30266
- throw new InternalValidationError(
30267
- "Token inputs missing in partial transaction",
30268
- {
30269
- value: partialTokenTransaction
30270
- }
30271
- );
30272
- }
30273
- if (finalTokenTransaction.tokenInputs.$case !== partialTokenTransaction.tokenInputs.$case) {
30274
- throw new InternalValidationError(
30275
- `Transaction type mismatch: final transaction has ${finalTokenTransaction.tokenInputs.$case}, partial transaction has ${partialTokenTransaction.tokenInputs.$case}`,
30276
- {
30277
- value: finalTokenTransaction.tokenInputs.$case,
30278
- expected: partialTokenTransaction.tokenInputs.$case
30279
- }
30280
- );
30281
- }
30282
- if (finalTokenTransaction.sparkOperatorIdentityPublicKeys.length !== partialTokenTransaction.sparkOperatorIdentityPublicKeys.length) {
30283
- throw new InternalValidationError(
30284
- "Spark operator identity public keys count mismatch",
30285
- {
30286
- value: finalTokenTransaction.sparkOperatorIdentityPublicKeys.length,
30287
- expected: partialTokenTransaction.sparkOperatorIdentityPublicKeys.length
30288
- }
30289
- );
30290
- }
30291
- if (partialTokenTransaction.tokenInputs.$case === "mintInput" && finalTokenTransaction.tokenInputs.$case === "mintInput") {
30292
- const finalMintInput = finalTokenTransaction.tokenInputs.mintInput;
30293
- const partialMintInput = partialTokenTransaction.tokenInputs.mintInput;
30294
- if (!areByteArraysEqual(
30295
- finalMintInput.issuerPublicKey,
30296
- partialMintInput.issuerPublicKey
30297
- )) {
30298
- throw new InternalValidationError(
30299
- "Issuer public key mismatch in mint input",
30300
- {
30301
- value: finalMintInput.issuerPublicKey.toString(),
30302
- expected: partialMintInput.issuerPublicKey.toString()
30303
- }
30304
- );
30305
- }
30306
- } else if (partialTokenTransaction.tokenInputs.$case === "transferInput" && finalTokenTransaction.tokenInputs.$case === "transferInput") {
30307
- const finalTransferInput = finalTokenTransaction.tokenInputs.transferInput;
30308
- const partialTransferInput = partialTokenTransaction.tokenInputs.transferInput;
30309
- if (finalTransferInput.outputsToSpend.length !== partialTransferInput.outputsToSpend.length) {
30310
- throw new InternalValidationError(
30311
- "Outputs to spend count mismatch in transfer input",
30312
- {
30313
- value: finalTransferInput.outputsToSpend.length,
30314
- expected: partialTransferInput.outputsToSpend.length
30315
- }
30316
- );
30317
- }
30318
- for (let i = 0; i < finalTransferInput.outputsToSpend.length; i++) {
30319
- const finalOutput = finalTransferInput.outputsToSpend[i];
30320
- const partialOutput = partialTransferInput.outputsToSpend[i];
30321
- if (!finalOutput) {
30322
- throw new InternalValidationError(
30323
- "Token output to spend missing in final transaction",
30324
- {
30325
- outputIndex: i,
30326
- value: finalOutput
30327
- }
30328
- );
30329
- }
30330
- if (!partialOutput) {
30331
- throw new InternalValidationError(
30332
- "Token output to spend missing in partial transaction",
30333
- {
30334
- outputIndex: i,
30335
- value: partialOutput
30336
- }
30337
- );
30338
- }
30339
- if (!areByteArraysEqual(
30340
- finalOutput.prevTokenTransactionHash,
30341
- partialOutput.prevTokenTransactionHash
30342
- )) {
30343
- throw new InternalValidationError(
30344
- "Previous token transaction hash mismatch in transfer input",
30345
- {
30346
- outputIndex: i,
30347
- value: finalOutput.prevTokenTransactionHash.toString(),
30348
- expected: partialOutput.prevTokenTransactionHash.toString()
30349
- }
30350
- );
30351
- }
30352
- if (finalOutput.prevTokenTransactionVout !== partialOutput.prevTokenTransactionVout) {
30353
- throw new InternalValidationError(
30354
- "Previous token transaction vout mismatch in transfer input",
30355
- {
30356
- outputIndex: i,
30357
- value: finalOutput.prevTokenTransactionVout,
30358
- expected: partialOutput.prevTokenTransactionVout
30359
- }
30360
- );
30361
- }
30362
- }
30363
- }
30364
- if (finalTokenTransaction.tokenOutputs.length !== partialTokenTransaction.tokenOutputs.length) {
30365
- throw new InternalValidationError("Token outputs count mismatch", {
30366
- value: finalTokenTransaction.tokenOutputs.length,
30367
- expected: partialTokenTransaction.tokenOutputs.length
30368
- });
30369
- }
30370
- for (let i = 0; i < finalTokenTransaction.tokenOutputs.length; i++) {
30371
- const finalOutput = finalTokenTransaction.tokenOutputs[i];
30372
- const partialOutput = partialTokenTransaction.tokenOutputs[i];
30373
- if (!finalOutput) {
30374
- throw new InternalValidationError(
30375
- "Token output missing in final transaction",
30376
- {
30377
- outputIndex: i,
30378
- value: finalOutput
30379
- }
30380
- );
30381
- }
30382
- if (!partialOutput) {
30383
- throw new InternalValidationError(
30384
- "Token output missing in partial transaction",
30385
- {
30386
- outputIndex: i,
30387
- value: partialOutput
30388
- }
30389
- );
30390
- }
30391
- if (!areByteArraysEqual(
30392
- finalOutput.ownerPublicKey,
30393
- partialOutput.ownerPublicKey
30394
- )) {
30395
- throw new InternalValidationError(
30396
- "Owner public key mismatch in token output",
30397
- {
30398
- outputIndex: i,
30399
- value: finalOutput.ownerPublicKey.toString(),
30400
- expected: partialOutput.ownerPublicKey.toString()
30401
- }
30402
- );
30403
- }
30404
- if (finalOutput.tokenPublicKey !== void 0 && partialOutput.tokenPublicKey !== void 0 && !areByteArraysEqual(
30405
- finalOutput.tokenPublicKey,
30406
- partialOutput.tokenPublicKey
30407
- )) {
30408
- throw new InternalValidationError(
30409
- "Token public key mismatch in token output",
30410
- {
30411
- outputIndex: i,
30412
- value: finalOutput.tokenPublicKey?.toString(),
30413
- expected: partialOutput.tokenPublicKey?.toString()
30414
- }
30415
- );
30416
- }
30417
- if (!areByteArraysEqual(finalOutput.tokenAmount, partialOutput.tokenAmount)) {
30418
- throw new InternalValidationError(
30419
- "Token amount mismatch in token output",
30420
- {
30421
- outputIndex: i,
30422
- value: finalOutput.tokenAmount.toString(),
30423
- expected: partialOutput.tokenAmount.toString()
30424
- }
30425
- );
30426
- }
30427
- if (finalOutput.withdrawBondSats !== void 0) {
30428
- if (finalOutput.withdrawBondSats !== expectedWithdrawBondSats) {
30429
- throw new InternalValidationError(
30430
- "Withdraw bond sats mismatch in token output",
30431
- {
30432
- outputIndex: i,
30433
- value: finalOutput.withdrawBondSats,
30434
- expected: expectedWithdrawBondSats
30435
- }
30436
- );
30437
- }
30438
- }
30439
- if (finalOutput.withdrawRelativeBlockLocktime !== void 0) {
30440
- if (finalOutput.withdrawRelativeBlockLocktime !== expectedWithdrawRelativeBlockLocktime) {
30441
- throw new InternalValidationError(
30442
- "Withdraw relative block locktime mismatch in token output",
30443
- {
30444
- outputIndex: i,
30445
- value: finalOutput.withdrawRelativeBlockLocktime,
30446
- expected: expectedWithdrawRelativeBlockLocktime
30447
- }
30448
- );
30449
- }
30450
- }
30451
- if (keyshareInfo.threshold !== expectedThreshold) {
30452
- throw new InternalValidationError(
30453
- "Threshold mismatch: expected " + expectedThreshold + " but got " + keyshareInfo.threshold,
30454
- {
30455
- field: "threshold",
30456
- value: keyshareInfo.threshold,
30457
- expected: expectedThreshold
30458
- }
30459
- );
30460
- }
30461
- }
30462
- if (keyshareInfo.ownerIdentifiers.length !== Object.keys(signingOperators).length) {
30463
- throw new InternalValidationError(
30464
- `Keyshare operator count (${keyshareInfo.ownerIdentifiers.length}) does not match signing operator count (${Object.keys(signingOperators).length})`,
30465
- {
30466
- keyshareInfo: keyshareInfo.ownerIdentifiers.length,
30467
- signingOperators: Object.keys(signingOperators).length
30468
- }
30469
- );
30470
- }
30471
- if (hasDuplicates(keyshareInfo.ownerIdentifiers)) {
30472
- throw new InternalValidationError(
30473
- "Duplicate ownerIdentifiers found in keyshareInfo",
30474
- {
30475
- keyshareInfo: keyshareInfo.ownerIdentifiers
30476
- }
30477
- );
30478
- }
30479
- for (const identifier of keyshareInfo.ownerIdentifiers) {
30480
- if (!signingOperators[identifier]) {
30481
- throw new InternalValidationError(
30482
- `Keyshare operator ${identifier} not found in signing operator list`,
30483
- {
30484
- keyshareInfo: identifier,
30485
- signingOperators: Object.keys(signingOperators)
30486
- }
30487
- );
30488
- }
30489
- }
30490
- }
30491
30539
  function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
30492
30540
  if (finalTokenTransaction.network !== partialTokenTransaction.network) {
30493
30541
  throw new InternalValidationError(
@@ -30840,16 +30888,6 @@ var TokenTransactionService = class {
30840
30888
  tokenIdentifier,
30841
30889
  this.config.getNetworkType()
30842
30890
  ).tokenIdentifier;
30843
- let tokenPublicKey;
30844
- if (this.config.getTokenTransactionVersion() === "V0") {
30845
- const tokenClient = await this.connectionManager.createSparkTokenClient(
30846
- this.config.getCoordinatorAddress()
30847
- );
30848
- const tokenMetadata = await tokenClient.query_token_metadata({
30849
- tokenIdentifiers: [rawTokenIdentifier]
30850
- });
30851
- tokenPublicKey = tokenMetadata.tokenMetadata[0].issuerPublicKey;
30852
- }
30853
30891
  let sparkInvoices = [];
30854
30892
  const tokenOutputData = receiverOutputs.map((transfer) => {
30855
30893
  const receiverAddress = decodeSparkAddress(
@@ -30859,7 +30897,7 @@ var TokenTransactionService = class {
30859
30897
  if (receiverAddress.sparkInvoiceFields) {
30860
30898
  sparkInvoices.push(transfer.receiverSparkAddress);
30861
30899
  }
30862
- if (this.config.getTokenTransactionVersion() !== "V0" && receiverAddress.sparkInvoiceFields) {
30900
+ if (receiverAddress.sparkInvoiceFields) {
30863
30901
  return {
30864
30902
  receiverPublicKey: (0, import_utils20.hexToBytes)(receiverAddress.identityPublicKey),
30865
30903
  rawTokenIdentifier,
@@ -30870,24 +30908,14 @@ var TokenTransactionService = class {
30870
30908
  return {
30871
30909
  receiverPublicKey: (0, import_utils20.hexToBytes)(receiverAddress.identityPublicKey),
30872
30910
  rawTokenIdentifier,
30873
- tokenPublicKey,
30874
- // Remove for full v0 deprecation
30875
30911
  tokenAmount: transfer.tokenAmount
30876
30912
  };
30877
30913
  });
30878
- let tokenTransaction;
30879
- if (this.config.getTokenTransactionVersion() === "V0") {
30880
- tokenTransaction = await this.constructTransferTokenTransactionV0(
30881
- outputsToUse,
30882
- tokenOutputData
30883
- );
30884
- } else {
30885
- tokenTransaction = await this.constructTransferTokenTransaction(
30886
- outputsToUse,
30887
- tokenOutputData,
30888
- sparkInvoices
30889
- );
30890
- }
30914
+ const tokenTransaction = await this.constructTransferTokenTransaction(
30915
+ outputsToUse,
30916
+ tokenOutputData,
30917
+ sparkInvoices
30918
+ );
30891
30919
  const txId = await this.broadcastTokenTransaction(
30892
30920
  tokenTransaction,
30893
30921
  outputsToUse.map((output) => output.output.ownerPublicKey),
@@ -30895,44 +30923,6 @@ var TokenTransactionService = class {
30895
30923
  );
30896
30924
  return txId;
30897
30925
  }
30898
- async constructTransferTokenTransactionV0(selectedOutputs, tokenOutputData) {
30899
- selectedOutputs.sort(
30900
- (a, b) => a.previousTransactionVout - b.previousTransactionVout
30901
- );
30902
- const availableTokenAmount = sumAvailableTokens(selectedOutputs);
30903
- const totalRequestedAmount = tokenOutputData.reduce(
30904
- (sum, output) => sum + output.tokenAmount,
30905
- 0n
30906
- );
30907
- const tokenOutputs = tokenOutputData.map((output) => ({
30908
- ownerPublicKey: output.receiverPublicKey,
30909
- tokenPublicKey: output.tokenPublicKey,
30910
- tokenAmount: (0, import_utils19.numberToBytesBE)(output.tokenAmount, 16)
30911
- }));
30912
- if (availableTokenAmount > totalRequestedAmount) {
30913
- const changeAmount = availableTokenAmount - totalRequestedAmount;
30914
- const firstTokenPublicKey = tokenOutputData[0].tokenPublicKey;
30915
- tokenOutputs.push({
30916
- ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
30917
- tokenPublicKey: firstTokenPublicKey,
30918
- tokenAmount: (0, import_utils19.numberToBytesBE)(changeAmount, 16)
30919
- });
30920
- }
30921
- return {
30922
- network: this.config.getNetworkProto(),
30923
- tokenInputs: {
30924
- $case: "transferInput",
30925
- transferInput: {
30926
- outputsToSpend: selectedOutputs.map((output) => ({
30927
- prevTokenTransactionHash: output.previousTransactionHash,
30928
- prevTokenTransactionVout: output.previousTransactionVout
30929
- }))
30930
- }
30931
- },
30932
- tokenOutputs,
30933
- sparkOperatorIdentityPublicKeys: this.collectOperatorIdentityPublicKeys()
30934
- };
30935
- }
30936
30926
  async constructTransferTokenTransaction(selectedOutputs, tokenOutputData, sparkInvoices) {
30937
30927
  selectedOutputs.sort(
30938
30928
  (a, b) => a.previousTransactionVout - b.previousTransactionVout
@@ -30988,113 +30978,6 @@ var TokenTransactionService = class {
30988
30978
  }
30989
30979
  async broadcastTokenTransaction(tokenTransaction, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30990
30980
  const signingOperators = this.config.getSigningOperators();
30991
- if (!isTokenTransaction(tokenTransaction)) {
30992
- return this.broadcastTokenTransactionV0(
30993
- tokenTransaction,
30994
- signingOperators,
30995
- outputsToSpendSigningPublicKeys,
30996
- outputsToSpendCommitments
30997
- );
30998
- } else {
30999
- return this.broadcastTokenTransactionV1(
31000
- tokenTransaction,
31001
- signingOperators,
31002
- outputsToSpendSigningPublicKeys,
31003
- outputsToSpendCommitments
31004
- );
31005
- }
31006
- }
31007
- async broadcastTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
31008
- const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransactionV0(
31009
- tokenTransaction,
31010
- signingOperators,
31011
- outputsToSpendSigningPublicKeys,
31012
- outputsToSpendCommitments
31013
- );
31014
- const { successfulSignatures } = await this.signTokenTransactionV0(
31015
- finalTokenTransaction,
31016
- finalTokenTransactionHash,
31017
- signingOperators
31018
- );
31019
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
31020
- const outputsToSpend = finalTokenTransaction.tokenInputs.transferInput.outputsToSpend;
31021
- const errors = [];
31022
- const revocationSecrets = [];
31023
- for (let outputIndex = 0; outputIndex < outputsToSpend.length; outputIndex++) {
31024
- const outputKeyshares = successfulSignatures.map(({ identifier, response }) => ({
31025
- operatorIndex: parseInt(identifier, 16),
31026
- keyshare: response.revocationKeyshares[outputIndex]
31027
- }));
31028
- if (outputKeyshares.length < threshold) {
31029
- errors.push(
31030
- new ValidationError("Insufficient keyshares", {
31031
- field: "outputKeyshares",
31032
- value: outputKeyshares.length,
31033
- expected: threshold,
31034
- index: outputIndex
31035
- })
31036
- );
31037
- }
31038
- const seenIndices = /* @__PURE__ */ new Set();
31039
- for (const { operatorIndex } of outputKeyshares) {
31040
- if (seenIndices.has(operatorIndex)) {
31041
- errors.push(
31042
- new ValidationError("Duplicate operator index", {
31043
- field: "outputKeyshares",
31044
- value: operatorIndex,
31045
- expected: "Unique operator index",
31046
- index: outputIndex
31047
- })
31048
- );
31049
- }
31050
- seenIndices.add(operatorIndex);
31051
- }
31052
- const revocationSecret = recoverRevocationSecretFromKeyshares(
31053
- outputKeyshares,
31054
- threshold
31055
- );
31056
- const derivedRevocationCommitment = import_secp256k113.secp256k1.getPublicKey(
31057
- revocationSecret,
31058
- true
31059
- );
31060
- if (!outputsToSpendCommitments || !outputsToSpendCommitments[outputIndex] || !derivedRevocationCommitment.every(
31061
- (byte, i) => byte === outputsToSpendCommitments[outputIndex][i]
31062
- )) {
31063
- errors.push(
31064
- new InternalValidationError(
31065
- "Revocation commitment verification failed",
31066
- {
31067
- field: "revocationCommitment",
31068
- value: derivedRevocationCommitment,
31069
- expected: (0, import_utils19.bytesToHex)(outputsToSpendCommitments[outputIndex]),
31070
- outputIndex
31071
- }
31072
- )
31073
- );
31074
- }
31075
- revocationSecrets.push({
31076
- inputIndex: outputIndex,
31077
- revocationSecret
31078
- });
31079
- }
31080
- if (errors.length > 0) {
31081
- throw new ValidationError(
31082
- "Multiple validation errors occurred across outputs",
31083
- {
31084
- field: "outputValidation",
31085
- value: errors
31086
- }
31087
- );
31088
- }
31089
- await this.finalizeTokenTransaction(
31090
- finalTokenTransaction,
31091
- revocationSecrets,
31092
- threshold
31093
- );
31094
- }
31095
- return (0, import_utils19.bytesToHex)(finalTokenTransactionHash);
31096
- }
31097
- async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
31098
30981
  const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
31099
30982
  tokenTransaction,
31100
30983
  signingOperators,
@@ -31108,101 +30991,6 @@ var TokenTransactionService = class {
31108
30991
  );
31109
30992
  return (0, import_utils19.bytesToHex)(finalTokenTransactionHash);
31110
30993
  }
31111
- async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
31112
- const sparkClient = await this.connectionManager.createSparkClient(
31113
- this.config.getCoordinatorAddress()
31114
- );
31115
- const partialTokenTransactionHash = hashTokenTransactionV0(
31116
- tokenTransaction,
31117
- true
31118
- );
31119
- const ownerSignaturesWithIndex = [];
31120
- if (tokenTransaction.tokenInputs.$case === "mintInput") {
31121
- const issuerPublicKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
31122
- if (!issuerPublicKey) {
31123
- throw new ValidationError("Invalid mint input", {
31124
- field: "issuerPublicKey",
31125
- value: null,
31126
- expected: "Non-null issuer public key"
31127
- });
31128
- }
31129
- const ownerSignature = await this.signMessageWithKey(
31130
- partialTokenTransactionHash,
31131
- issuerPublicKey
31132
- );
31133
- ownerSignaturesWithIndex.push({
31134
- signature: ownerSignature,
31135
- inputIndex: 0
31136
- });
31137
- } else if (tokenTransaction.tokenInputs.$case === "transferInput") {
31138
- if (!outputsToSpendSigningPublicKeys || !outputsToSpendCommitments) {
31139
- throw new ValidationError("Invalid transfer input", {
31140
- field: "outputsToSpend",
31141
- value: {
31142
- signingPublicKeys: outputsToSpendSigningPublicKeys,
31143
- revocationPublicKeys: outputsToSpendCommitments
31144
- },
31145
- expected: "Non-null signing and revocation public keys"
31146
- });
31147
- }
31148
- for (const [i, key] of outputsToSpendSigningPublicKeys.entries()) {
31149
- if (!key) {
31150
- throw new ValidationError("Invalid signing key", {
31151
- field: "outputsToSpendSigningPublicKeys",
31152
- value: i,
31153
- expected: "Non-null signing key"
31154
- });
31155
- }
31156
- const ownerSignature = await this.signMessageWithKey(
31157
- partialTokenTransactionHash,
31158
- key
31159
- );
31160
- ownerSignaturesWithIndex.push({
31161
- signature: ownerSignature,
31162
- inputIndex: i
31163
- });
31164
- }
31165
- }
31166
- const startResponse = await sparkClient.start_token_transaction(
31167
- {
31168
- identityPublicKey: await this.config.signer.getIdentityPublicKey(),
31169
- partialTokenTransaction: tokenTransaction,
31170
- tokenTransactionSignatures: {
31171
- ownerSignatures: ownerSignaturesWithIndex
31172
- }
31173
- },
31174
- {
31175
- retry: true,
31176
- retryableStatuses: ["UNKNOWN", "UNAVAILABLE", "CANCELLED", "INTERNAL"],
31177
- retryMaxAttempts: 3
31178
- }
31179
- );
31180
- if (!startResponse.finalTokenTransaction) {
31181
- throw new Error("Final token transaction missing in start response");
31182
- }
31183
- if (!startResponse.keyshareInfo) {
31184
- throw new Error("Keyshare info missing in start response");
31185
- }
31186
- validateTokenTransactionV0(
31187
- startResponse.finalTokenTransaction,
31188
- tokenTransaction,
31189
- signingOperators,
31190
- startResponse.keyshareInfo,
31191
- this.config.getExpectedWithdrawBondSats(),
31192
- this.config.getExpectedWithdrawRelativeBlockLocktime(),
31193
- this.config.getThreshold()
31194
- );
31195
- const finalTokenTransaction = startResponse.finalTokenTransaction;
31196
- const finalTokenTransactionHash = hashTokenTransactionV0(
31197
- finalTokenTransaction,
31198
- false
31199
- );
31200
- return {
31201
- finalTokenTransaction,
31202
- finalTokenTransactionHash,
31203
- threshold: startResponse.keyshareInfo.threshold
31204
- };
31205
- }
31206
30994
  async startTokenTransaction(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
31207
30995
  const sparkClient = await this.connectionManager.createSparkTokenClient(
31208
30996
  this.config.getCoordinatorAddress()
@@ -31322,103 +31110,6 @@ var TokenTransactionService = class {
31322
31110
  threshold: startResponse.keyshareInfo.threshold
31323
31111
  };
31324
31112
  }
31325
- async signTokenTransactionV0(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
31326
- const soSignatures = await Promise.allSettled(
31327
- Object.entries(signingOperators).map(
31328
- async ([identifier, operator], index) => {
31329
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
31330
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
31331
- const payload = {
31332
- finalTokenTransactionHash,
31333
- operatorIdentityPublicKey: (0, import_utils20.hexToBytes)(operator.identityPublicKey)
31334
- };
31335
- const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
31336
- let operatorSpecificSignatures = [];
31337
- if (finalTokenTransaction.tokenInputs.$case === "mintInput") {
31338
- const issuerPublicKey = finalTokenTransaction.tokenInputs.mintInput.issuerPublicKey;
31339
- if (!issuerPublicKey) {
31340
- throw new ValidationError("Invalid mint input", {
31341
- field: "issuerPublicKey",
31342
- value: null,
31343
- expected: "Non-null issuer public key"
31344
- });
31345
- }
31346
- const ownerSignature = await this.signMessageWithKey(
31347
- payloadHash,
31348
- issuerPublicKey
31349
- );
31350
- operatorSpecificSignatures.push({
31351
- ownerSignature: {
31352
- signature: ownerSignature,
31353
- inputIndex: 0
31354
- },
31355
- payload
31356
- });
31357
- }
31358
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
31359
- const transferInput = finalTokenTransaction.tokenInputs.transferInput;
31360
- for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
31361
- let ownerSignature;
31362
- if (this.config.getTokenSignatures() === "SCHNORR") {
31363
- ownerSignature = await this.config.signer.signSchnorrWithIdentityKey(
31364
- payloadHash
31365
- );
31366
- } else {
31367
- ownerSignature = await this.config.signer.signMessageWithIdentityKey(
31368
- payloadHash
31369
- );
31370
- }
31371
- operatorSpecificSignatures.push({
31372
- ownerSignature: {
31373
- signature: ownerSignature,
31374
- inputIndex: i
31375
- },
31376
- payload
31377
- });
31378
- }
31379
- }
31380
- try {
31381
- const response = await internalSparkClient.sign_token_transaction(
31382
- {
31383
- finalTokenTransaction,
31384
- operatorSpecificSignatures,
31385
- identityPublicKey
31386
- },
31387
- {
31388
- retry: true,
31389
- retryableStatuses: [
31390
- "UNKNOWN",
31391
- "UNAVAILABLE",
31392
- "CANCELLED",
31393
- "INTERNAL"
31394
- ],
31395
- retryMaxAttempts: 3
31396
- }
31397
- );
31398
- return {
31399
- index,
31400
- identifier,
31401
- response
31402
- };
31403
- } catch (error) {
31404
- throw new NetworkError(
31405
- "Failed to sign token transaction",
31406
- {
31407
- operation: "sign_token_transaction",
31408
- errorCount: 1,
31409
- errors: error instanceof Error ? error.message : String(error)
31410
- },
31411
- error
31412
- );
31413
- }
31414
- }
31415
- )
31416
- );
31417
- const successfulSignatures = collectResponses(soSignatures);
31418
- return {
31419
- successfulSignatures
31420
- };
31421
- }
31422
31113
  async signTokenTransaction(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
31423
31114
  const coordinatorClient = await this.connectionManager.createSparkTokenClient(
31424
31115
  this.config.getCoordinatorAddress()
@@ -31490,54 +31181,6 @@ var TokenTransactionService = class {
31490
31181
  );
31491
31182
  }
31492
31183
  }
31493
- if (this.config.getTokenTransactionVersion() === "V0") {
31494
- return this.fetchOwnedTokenOutputsV0(params);
31495
- } else {
31496
- return this.fetchOwnedTokenOutputsV1(params);
31497
- }
31498
- }
31499
- async queryTokenTransactions(params) {
31500
- if (this.config.getTokenTransactionVersion() === "V0") {
31501
- return this.queryTokenTransactionsV0(params);
31502
- } else {
31503
- return this.queryTokenTransactionsV1(params);
31504
- }
31505
- }
31506
- async fetchOwnedTokenOutputsV0(params) {
31507
- const {
31508
- ownerPublicKeys,
31509
- issuerPublicKeys: tokenPublicKeys = [],
31510
- tokenIdentifiers = []
31511
- } = params;
31512
- const sparkClient = await this.connectionManager.createSparkClient(
31513
- this.config.getCoordinatorAddress()
31514
- );
31515
- try {
31516
- const result = await sparkClient.query_token_outputs({
31517
- ownerPublicKeys,
31518
- tokenPublicKeys,
31519
- tokenIdentifiers,
31520
- network: this.config.getNetworkProto()
31521
- });
31522
- return result.outputsWithPreviousTransactionData;
31523
- } catch (error) {
31524
- throw new NetworkError(
31525
- "Failed to fetch owned token outputs",
31526
- {
31527
- operation: "spark.query_token_outputs",
31528
- errorCount: 1,
31529
- errors: error instanceof Error ? error.message : String(error)
31530
- },
31531
- error
31532
- );
31533
- }
31534
- }
31535
- async fetchOwnedTokenOutputsV1(params) {
31536
- const {
31537
- ownerPublicKeys,
31538
- issuerPublicKeys = [],
31539
- tokenIdentifiers = []
31540
- } = params;
31541
31184
  const tokenClient = await this.connectionManager.createSparkTokenClient(
31542
31185
  this.config.getCoordinatorAddress()
31543
31186
  );
@@ -31578,75 +31221,7 @@ var TokenTransactionService = class {
31578
31221
  );
31579
31222
  }
31580
31223
  }
31581
- async queryTokenTransactionsV0(params) {
31582
- const {
31583
- ownerPublicKeys,
31584
- issuerPublicKeys,
31585
- tokenTransactionHashes,
31586
- tokenIdentifiers,
31587
- outputIds,
31588
- pageSize,
31589
- offset
31590
- } = params;
31591
- const sparkClient = await this.connectionManager.createSparkClient(
31592
- this.config.getCoordinatorAddress()
31593
- );
31594
- let queryParams = {
31595
- tokenPublicKeys: issuerPublicKeys?.map(import_utils20.hexToBytes),
31596
- ownerPublicKeys: ownerPublicKeys?.map(import_utils20.hexToBytes),
31597
- tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
31598
- const { tokenIdentifier } = decodeBech32mTokenIdentifier(
31599
- identifier,
31600
- this.config.getNetworkType()
31601
- );
31602
- return tokenIdentifier;
31603
- }),
31604
- tokenTransactionHashes: tokenTransactionHashes?.map(import_utils20.hexToBytes),
31605
- outputIds: outputIds || [],
31606
- limit: pageSize,
31607
- offset
31608
- };
31609
- try {
31610
- const response = await sparkClient.query_token_transactions(queryParams);
31611
- return {
31612
- tokenTransactionsWithStatus: response.tokenTransactionsWithStatus.map(
31613
- (tx) => {
31614
- const v1TokenTransaction = {
31615
- version: 1,
31616
- network: tx.tokenTransaction.network,
31617
- tokenInputs: tx.tokenTransaction.tokenInputs,
31618
- tokenOutputs: tx.tokenTransaction.tokenOutputs,
31619
- sparkOperatorIdentityPublicKeys: tx.tokenTransaction.sparkOperatorIdentityPublicKeys,
31620
- expiryTime: void 0,
31621
- // V0 doesn't have expiry time
31622
- clientCreatedTimestamp: tx.tokenTransaction?.tokenInputs?.$case === "mintInput" ? new Date(
31623
- tx.tokenTransaction.tokenInputs.mintInput.issuerProvidedTimestamp * 1e3
31624
- ) : /* @__PURE__ */ new Date(),
31625
- invoiceAttachments: []
31626
- };
31627
- return {
31628
- tokenTransaction: v1TokenTransaction,
31629
- status: tx.status,
31630
- confirmationMetadata: tx.confirmationMetadata,
31631
- tokenTransactionHash: tx.tokenTransactionHash
31632
- };
31633
- }
31634
- ),
31635
- offset: response.offset
31636
- };
31637
- } catch (error) {
31638
- throw new NetworkError(
31639
- "Failed to query token transactions",
31640
- {
31641
- operation: "spark.query_token_transactions",
31642
- errorCount: 1,
31643
- errors: error instanceof Error ? error.message : String(error)
31644
- },
31645
- error
31646
- );
31647
- }
31648
- }
31649
- async queryTokenTransactionsV1(params) {
31224
+ async queryTokenTransactions(params) {
31650
31225
  const {
31651
31226
  ownerPublicKeys,
31652
31227
  issuerPublicKeys,
@@ -31759,50 +31334,6 @@ var TokenTransactionService = class {
31759
31334
  });
31760
31335
  }
31761
31336
  }
31762
- async finalizeTokenTransaction(finalTokenTransaction, revocationSecrets, threshold) {
31763
- const signingOperators = this.config.getSigningOperators();
31764
- const soResponses = await Promise.allSettled(
31765
- Object.entries(signingOperators).map(async ([identifier, operator]) => {
31766
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
31767
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
31768
- try {
31769
- const response = await internalSparkClient.finalize_token_transaction(
31770
- {
31771
- finalTokenTransaction,
31772
- revocationSecrets,
31773
- identityPublicKey
31774
- },
31775
- {
31776
- retry: true,
31777
- retryableStatuses: [
31778
- "UNKNOWN",
31779
- "UNAVAILABLE",
31780
- "CANCELLED",
31781
- "INTERNAL"
31782
- ],
31783
- retryMaxAttempts: 3
31784
- }
31785
- );
31786
- return {
31787
- identifier,
31788
- response
31789
- };
31790
- } catch (error) {
31791
- throw new NetworkError(
31792
- "Failed to finalize token transaction",
31793
- {
31794
- operation: "finalize_token_transaction",
31795
- errorCount: 1,
31796
- errors: error instanceof Error ? error.message : String(error)
31797
- },
31798
- error
31799
- );
31800
- }
31801
- })
31802
- );
31803
- collectResponses(soResponses);
31804
- return finalTokenTransaction;
31805
- }
31806
31337
  async createSignaturesForOperators(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
31807
31338
  const inputTtxoSignaturesPerOperator = [];
31808
31339
  for (const [_, operator] of Object.entries(signingOperators)) {
@@ -31879,9 +31410,6 @@ var TokenTransactionService = class {
31879
31410
  return inputTtxoSignaturesPerOperator;
31880
31411
  }
31881
31412
  };
31882
- function isTokenTransaction(tokenTransaction) {
31883
- return "version" in tokenTransaction && "expiryTime" in tokenTransaction;
31884
- }
31885
31413
 
31886
31414
  // src/spark-wallet/spark-wallet.ts
31887
31415
  var import_sha213 = require("@noble/hashes/sha2");
@@ -32058,7 +31586,7 @@ var SigningService = class {
32058
31586
 
32059
31587
  // src/tests/utils/test-faucet.ts
32060
31588
  init_buffer();
32061
- var import_secp256k114 = require("@noble/curves/secp256k1");
31589
+ var import_secp256k112 = require("@noble/curves/secp256k1");
32062
31590
  var import_utils22 = require("@noble/curves/utils");
32063
31591
  var btc5 = __toESM(require("@scure/btc-signer"), 1);
32064
31592
  var import_btc_signer5 = require("@scure/btc-signer");
@@ -32079,7 +31607,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32079
31607
  this.username = username;
32080
31608
  this.password = password;
32081
31609
  this.miningAddress = getP2TRAddressFromPublicKey(
32082
- import_secp256k114.secp256k1.getPublicKey(STATIC_MINING_KEY),
31610
+ import_secp256k112.secp256k1.getPublicKey(STATIC_MINING_KEY),
32083
31611
  4 /* LOCAL */
32084
31612
  );
32085
31613
  }
@@ -32118,7 +31646,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32118
31646
  });
32119
31647
  }
32120
31648
  async refill() {
32121
- const minerPubKey = import_secp256k114.secp256k1.getPublicKey(STATIC_MINING_KEY);
31649
+ const minerPubKey = import_secp256k112.secp256k1.getPublicKey(STATIC_MINING_KEY);
32122
31650
  const address2 = getP2TRAddressFromPublicKey(minerPubKey, 4 /* LOCAL */);
32123
31651
  const scanResult = await this.call("scantxoutset", [
32124
31652
  "start",
@@ -32167,7 +31695,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32167
31695
  txid: selectedUtxo.txid,
32168
31696
  index: selectedUtxo.vout
32169
31697
  });
32170
- const faucetPubKey = import_secp256k114.secp256k1.getPublicKey(STATIC_FAUCET_KEY);
31698
+ const faucetPubKey = import_secp256k112.secp256k1.getPublicKey(STATIC_FAUCET_KEY);
32171
31699
  const script = getP2TRScriptFromPublicKey(faucetPubKey, 4 /* LOCAL */);
32172
31700
  for (let i = 0; i < numCoinsToCreate; i++) {
32173
31701
  splitTx.addOutput({
@@ -32228,7 +31756,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32228
31756
  await this.broadcastTx((0, import_utils22.bytesToHex)(signedTx.extract()));
32229
31757
  }
32230
31758
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
32231
- const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
31759
+ const pubKey = import_secp256k112.secp256k1.getPublicKey(key);
32232
31760
  const internalKey = pubKey.slice(1);
32233
31761
  const script = getP2TRScriptFromPublicKey(pubKey, 4 /* LOCAL */);
32234
31762
  unsignedTx.updateInput(0, {
@@ -32248,7 +31776,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32248
31776
  const tweakedKey = (0, import_utils23.taprootTweakPrivKey)(key, merkleRoot);
32249
31777
  if (!tweakedKey)
32250
31778
  throw new Error("Invalid private key for taproot tweaking");
32251
- const signature = import_secp256k114.schnorr.sign(sighash, tweakedKey);
31779
+ const signature = import_secp256k112.schnorr.sign(sighash, tweakedKey);
32252
31780
  unsignedTx.updateInput(0, {
32253
31781
  tapKeySig: signature
32254
31782
  });
@@ -32311,8 +31839,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
32311
31839
  return response;
32312
31840
  }
32313
31841
  async getNewAddress() {
32314
- const key = import_secp256k114.secp256k1.utils.randomPrivateKey();
32315
- const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
31842
+ const key = import_secp256k112.secp256k1.utils.randomPrivateKey();
31843
+ const pubKey = import_secp256k112.secp256k1.getPublicKey(key);
32316
31844
  return getP2TRAddressFromPublicKey(pubKey, 4 /* LOCAL */);
32317
31845
  }
32318
31846
  async sendToAddress(address2, amount, blocksToGenerate = 1) {
@@ -32333,8 +31861,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
32333
31861
  });
32334
31862
  const changeAmount = availableAmount - amount;
32335
31863
  if (changeAmount > 0) {
32336
- const changeKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
32337
- const changePubKey = import_secp256k114.secp256k1.getPublicKey(changeKey);
31864
+ const changeKey = import_secp256k112.secp256k1.utils.randomPrivateKey();
31865
+ const changePubKey = import_secp256k112.secp256k1.getPublicKey(changeKey);
32338
31866
  const changeScript = getP2TRScriptFromPublicKey(
32339
31867
  changePubKey,
32340
31868
  4 /* LOCAL */
@@ -32347,8 +31875,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
32347
31875
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
32348
31876
  const txHex = (0, import_utils22.bytesToHex)(signedTx.extract());
32349
31877
  await this.broadcastTx(txHex);
32350
- const randomKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
32351
- const randomPubKey = import_secp256k114.secp256k1.getPublicKey(randomKey);
31878
+ const randomKey = import_secp256k112.secp256k1.utils.randomPrivateKey();
31879
+ const randomPubKey = import_secp256k112.secp256k1.getPublicKey(randomKey);
32352
31880
  const randomAddress = getP2TRAddressFromPublicKey(
32353
31881
  randomPubKey,
32354
31882
  4 /* LOCAL */
@@ -32969,47 +32497,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32969
32497
  senderPublicKey,
32970
32498
  expiryTime
32971
32499
  }) {
32972
- const MAX_SATS_AMOUNT = 21e14;
32973
- if (amount && (amount < 0 || amount > MAX_SATS_AMOUNT)) {
32974
- throw new ValidationError(
32975
- `Amount must be between 0 and ${MAX_SATS_AMOUNT} sats`,
32976
- {
32977
- field: "amount",
32978
- value: amount,
32979
- expected: `less than or equal to ${MAX_SATS_AMOUNT}`
32980
- }
32981
- );
32982
- }
32983
- const protoPayment = {
32984
- $case: "satsPayment",
32985
- satsPayment: {
32986
- amount
32987
- }
32988
- };
32989
- const invoiceFields = {
32990
- version: 1,
32991
- id: (0, import_uuidv75.uuidv7obj)().bytes,
32992
- paymentType: protoPayment,
32993
- memo,
32994
- senderPublicKey: senderPublicKey ? (0, import_utils24.hexToBytes)(senderPublicKey) : void 0,
32995
- expiryTime: expiryTime ?? void 0
32996
- };
32997
- validateSparkInvoiceFields(invoiceFields);
32998
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
32999
- const hash = HashSparkInvoice(
33000
- invoiceFields,
33001
- identityPublicKey,
33002
- this.config.getNetworkType()
33003
- );
33004
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
33005
- return encodeSparkAddressWithSignature(
33006
- {
33007
- identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
33008
- network: this.config.getNetworkType(),
33009
- sparkInvoiceFields: invoiceFields
33010
- },
33011
- signature
33012
- );
32500
+ throw new NotImplementedError("Invoice functionality is not enabled");
33013
32501
  }
33014
32502
  /**
33015
32503
  * Creates a Spark invoice for a tokens payment on Spark.
@@ -33029,52 +32517,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33029
32517
  senderPublicKey,
33030
32518
  expiryTime
33031
32519
  }) {
33032
- const MAX_UINT128 = BigInt(2 ** 128 - 1);
33033
- if (amount && (amount < 0 || amount > MAX_UINT128)) {
33034
- throw new ValidationError(`Amount must be between 0 and ${MAX_UINT128}`, {
33035
- field: "amount",
33036
- value: amount,
33037
- expected: `greater than or equal to 0 and less than or equal to ${MAX_UINT128}`
33038
- });
33039
- }
33040
- let decodedTokenIdentifier = void 0;
33041
- if (tokenIdentifier) {
33042
- decodedTokenIdentifier = decodeBech32mTokenIdentifier(
33043
- tokenIdentifier,
33044
- this.config.getNetworkType()
33045
- ).tokenIdentifier;
33046
- }
33047
- const protoPayment = {
33048
- $case: "tokensPayment",
33049
- tokensPayment: {
33050
- tokenIdentifier: decodedTokenIdentifier ?? void 0,
33051
- amount: amount ? (0, import_utils24.numberToVarBytesBE)(amount) : void 0
33052
- }
33053
- };
33054
- const invoiceFields = {
33055
- version: 1,
33056
- id: (0, import_uuidv75.uuidv7obj)().bytes,
33057
- paymentType: protoPayment,
33058
- memo: memo ?? void 0,
33059
- senderPublicKey: senderPublicKey ? (0, import_utils24.hexToBytes)(senderPublicKey) : void 0,
33060
- expiryTime: expiryTime ?? void 0
33061
- };
33062
- validateSparkInvoiceFields(invoiceFields);
33063
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
33064
- const hash = HashSparkInvoice(
33065
- invoiceFields,
33066
- identityPublicKey,
33067
- this.config.getNetworkType()
33068
- );
33069
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
33070
- return encodeSparkAddressWithSignature(
33071
- {
33072
- identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
33073
- network: this.config.getNetworkType(),
33074
- sparkInvoiceFields: invoiceFields
33075
- },
33076
- signature
33077
- );
32520
+ throw new NotImplementedError("Invoice functionality is not enabled");
33078
32521
  }
33079
32522
  /**
33080
32523
  * Initializes the wallet using either a mnemonic phrase or a raw seed.
@@ -33399,7 +32842,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33399
32842
  }
33400
32843
  const sspClient = this.getSspClient();
33401
32844
  const cpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
33402
- import_secp256k115.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
32845
+ import_secp256k113.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
33403
32846
  );
33404
32847
  if (!cpfpAdaptorPubkey) {
33405
32848
  throw new Error("Failed to generate CPFP adaptor pubkey");
@@ -33407,13 +32850,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33407
32850
  let directAdaptorPubkey;
33408
32851
  if (directAdaptorPrivateKey.length > 0) {
33409
32852
  directAdaptorPubkey = (0, import_utils24.bytesToHex)(
33410
- import_secp256k115.secp256k1.getPublicKey(directAdaptorPrivateKey)
32853
+ import_secp256k113.secp256k1.getPublicKey(directAdaptorPrivateKey)
33411
32854
  );
33412
32855
  }
33413
32856
  let directFromCpfpAdaptorPubkey;
33414
32857
  if (directFromCpfpAdaptorPrivateKey.length > 0) {
33415
32858
  directFromCpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
33416
- import_secp256k115.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
32859
+ import_secp256k113.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
33417
32860
  );
33418
32861
  }
33419
32862
  let request = null;
@@ -35028,10 +34471,23 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
35028
34471
  if (!invoice2) {
35029
34472
  throw new Error("Failed to create lightning invoice");
35030
34473
  }
34474
+ const decodedInvoice = decodeInvoice(invoice2.invoice.encodedInvoice);
34475
+ if (invoice2.invoice.paymentHash !== (0, import_utils24.bytesToHex)(paymentHash) || decodedInvoice.paymentHash !== (0, import_utils24.bytesToHex)(paymentHash)) {
34476
+ throw new ValidationError("Payment hash mismatch", {
34477
+ field: "paymentHash",
34478
+ value: invoice2.invoice.paymentHash,
34479
+ expected: (0, import_utils24.bytesToHex)(paymentHash)
34480
+ });
34481
+ }
34482
+ if (decodedInvoice.amountMSats !== BigInt(amountSats2 * 1e3)) {
34483
+ throw new ValidationError("Amount mismatch", {
34484
+ field: "amountMSats",
34485
+ value: decodedInvoice.amountMSats,
34486
+ expected: amountSats2 * 1e3
34487
+ });
34488
+ }
35031
34489
  if (includeSparkAddress) {
35032
- const sparkFallbackAddress = decodeInvoice(
35033
- invoice2.invoice.encodedInvoice
35034
- ).fallbackAddress;
34490
+ const sparkFallbackAddress = decodedInvoice.fallbackAddress;
35035
34491
  if (!sparkFallbackAddress) {
35036
34492
  throw new ValidationError(
35037
34493
  "No spark fallback address found in lightning invoice",
@@ -35053,6 +34509,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
35053
34509
  }
35054
34510
  );
35055
34511
  }
34512
+ } else if (decodedInvoice.fallbackAddress !== void 0) {
34513
+ throw new ValidationError(
34514
+ "Spark fallback address found in lightning invoice but includeSparkAddress is false",
34515
+ {
34516
+ field: "sparkFallbackAddress",
34517
+ value: decodedInvoice.fallbackAddress
34518
+ }
34519
+ );
35056
34520
  }
35057
34521
  return invoice2;
35058
34522
  };
@@ -35220,91 +34684,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
35220
34684
  });
35221
34685
  }
35222
34686
  async fulfillSparkInvoice(sparkInvoices) {
35223
- if (!Array.isArray(sparkInvoices) || sparkInvoices.length === 0) {
35224
- throw new ValidationError("No Spark invoices provided", {
35225
- field: "sparkInvoices",
35226
- value: sparkInvoices,
35227
- expected: "Non-empty array"
35228
- });
35229
- }
35230
- const satsTransactionSuccess = [];
35231
- const satsTransactionErrors = [];
35232
- const tokenTransactionSuccess = [];
35233
- const tokenTransactionErrors = [];
35234
- const { satsInvoices, tokenInvoices, invalidInvoices } = await this.groupSparkInvoicesByPaymentType(sparkInvoices);
35235
- if (invalidInvoices.length > 0) {
35236
- return {
35237
- satsTransactionSuccess,
35238
- satsTransactionErrors,
35239
- tokenTransactionSuccess,
35240
- tokenTransactionErrors,
35241
- invalidInvoices
35242
- };
35243
- }
35244
- if (tokenInvoices.size > 0) {
35245
- await this.syncTokenOutputs();
35246
- const tokenTransferTasks = [];
35247
- for (const [identifierHex, decodedInvoices] of tokenInvoices.entries()) {
35248
- const tokenIdentifier = (0, import_utils24.hexToBytes)(identifierHex);
35249
- const tokenIdB32 = encodeBech32mTokenIdentifier({
35250
- tokenIdentifier,
35251
- network: this.config.getNetworkType()
35252
- });
35253
- const receiverOutputs = decodedInvoices.map((d) => ({
35254
- tokenIdentifier: tokenIdB32,
35255
- tokenAmount: d.amount,
35256
- receiverSparkAddress: d.invoice
35257
- }));
35258
- tokenTransferTasks.push(
35259
- this.tokenTransactionService.tokenTransfer({ tokenOutputs: this.tokenOutputs, receiverOutputs }).then((txid) => ({
35260
- ok: true,
35261
- tokenIdentifier: tokenIdB32,
35262
- txid
35263
- })).catch((e) => ({
35264
- ok: false,
35265
- tokenIdentifier: tokenIdB32,
35266
- error: e instanceof Error ? e : new Error(String(e))
35267
- }))
35268
- );
35269
- }
35270
- const results = await Promise.all(tokenTransferTasks);
35271
- for (const r of results) {
35272
- if (r.ok) {
35273
- tokenTransactionSuccess.push({
35274
- tokenIdentifier: r.tokenIdentifier,
35275
- txid: r.txid
35276
- });
35277
- } else {
35278
- tokenTransactionErrors.push({
35279
- tokenIdentifier: r.tokenIdentifier,
35280
- error: r.error
35281
- });
35282
- }
35283
- }
35284
- }
35285
- if (satsInvoices.length > 0) {
35286
- const transfers = await this.transferWithInvoice(satsInvoices);
35287
- for (const transfer of transfers) {
35288
- if (transfer.ok) {
35289
- satsTransactionSuccess.push({
35290
- invoice: transfer.param.sparkInvoice ?? "",
35291
- transferResponse: transfer.transfer
35292
- });
35293
- } else {
35294
- satsTransactionErrors.push({
35295
- invoice: transfer.param.sparkInvoice ?? "",
35296
- error: transfer.error
35297
- });
35298
- }
35299
- }
35300
- }
35301
- return {
35302
- satsTransactionSuccess,
35303
- satsTransactionErrors,
35304
- tokenTransactionSuccess,
35305
- tokenTransactionErrors,
35306
- invalidInvoices
35307
- };
34687
+ throw new NotImplementedError("Invoice functionality is not enabled");
35308
34688
  }
35309
34689
  async groupSparkInvoicesByPaymentType(sparkInvoices) {
35310
34690
  const satsInvoices = [];
@@ -35441,6 +34821,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
35441
34821
  });
35442
34822
  return { satsInvoices, tokenInvoices, invalidInvoices };
35443
34823
  }
34824
+ async querySparkInvoices(invoices) {
34825
+ throw new NotImplementedError("Invoice functionality is not enabled");
34826
+ }
35444
34827
  /**
35445
34828
  * Gets fee estimate for sending Lightning payments.
35446
34829
  *
@@ -36549,6 +35932,7 @@ setCrypto(cryptoImpl2);
36549
35932
  addPublicKeys,
36550
35933
  applyAdaptorToSignature,
36551
35934
  applyAdditiveTweakToPublicKey,
35935
+ assertBech32,
36552
35936
  bech32mDecode,
36553
35937
  bigIntToPrivateKey,
36554
35938
  checkIfSelectedOutputsAreAvailable,
@@ -36612,6 +35996,7 @@ setCrypto(cryptoImpl2);
36612
35996
  getTxIdNoReverse,
36613
35997
  initializeTracerEnv,
36614
35998
  isEphemeralAnchorOutput,
35999
+ isLegacySparkAddress,
36615
36000
  isSafeForNumber,
36616
36001
  isTxBroadcast,
36617
36002
  isValidPublicKey,