@buildonspark/spark-sdk 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/bare/index.cjs +945 -1401
  3. package/dist/bare/index.d.cts +128 -10
  4. package/dist/bare/index.d.ts +128 -10
  5. package/dist/bare/index.js +940 -1399
  6. package/dist/{chunk-55XNR6DM.js → chunk-DIXXHATX.js} +1 -1
  7. package/dist/{chunk-MGCUXELA.js → chunk-IC4IUEOS.js} +931 -125
  8. package/dist/{chunk-MH7BMOLL.js → chunk-J2P3KTQP.js} +1 -1
  9. package/dist/{chunk-SXXM52XH.js → chunk-JE73HB26.js} +409 -1656
  10. package/dist/{chunk-73GJOG5R.js → chunk-XWLR6G5C.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 +949 -1403
  14. package/dist/debug.d.cts +8 -5
  15. package/dist/debug.d.ts +8 -5
  16. package/dist/debug.js +4 -4
  17. package/dist/graphql/objects/index.d.cts +3 -3
  18. package/dist/graphql/objects/index.d.ts +3 -3
  19. package/dist/index.cjs +905 -1362
  20. package/dist/index.d.cts +6 -6
  21. package/dist/index.d.ts +6 -6
  22. package/dist/index.js +9 -5
  23. package/dist/index.node.cjs +905 -1362
  24. package/dist/index.node.d.cts +6 -6
  25. package/dist/index.node.d.ts +6 -6
  26. package/dist/index.node.js +8 -4
  27. package/dist/{logging-CGeEoKYd.d.cts → logging-BUpzk4Z6.d.cts} +3 -3
  28. package/dist/{logging-DpSsvFVM.d.ts → logging-Dt2ooQiP.d.ts} +3 -3
  29. package/dist/native/index.cjs +905 -1362
  30. package/dist/native/index.d.cts +129 -25
  31. package/dist/native/index.d.ts +129 -25
  32. package/dist/native/index.js +904 -1363
  33. package/dist/proto/spark.cjs +931 -125
  34. package/dist/proto/spark.d.cts +1 -1
  35. package/dist/proto/spark.d.ts +1 -1
  36. package/dist/proto/spark.js +17 -1
  37. package/dist/proto/spark_token.d.cts +1 -1
  38. package/dist/proto/spark_token.d.ts +1 -1
  39. package/dist/proto/spark_token.js +2 -2
  40. package/dist/{spark-CLz4-Ln8.d.cts → spark-DasxuVfm.d.cts} +150 -5
  41. package/dist/{spark-CLz4-Ln8.d.ts → spark-DasxuVfm.d.ts} +150 -5
  42. package/dist/{spark-wallet-BVBrWYKL.d.cts → spark-wallet-BoMIOPWW.d.cts} +13 -9
  43. package/dist/{spark-wallet-CFPm6wZs.d.ts → spark-wallet-jlC0XN5f.d.ts} +13 -9
  44. package/dist/{spark-wallet.node-e1gncoIZ.d.ts → spark-wallet.node-07PksUHH.d.cts} +1 -1
  45. package/dist/{spark-wallet.node-B_00X-1j.d.cts → spark-wallet.node-CdWkKMSq.d.ts} +1 -1
  46. package/dist/tests/test-utils.cjs +947 -144
  47. package/dist/tests/test-utils.d.cts +4 -4
  48. package/dist/tests/test-utils.d.ts +4 -4
  49. package/dist/tests/test-utils.js +5 -5
  50. package/dist/{token-transactions-BkAqlmY6.d.ts → token-transactions-BDzCrQSk.d.cts} +5 -19
  51. package/dist/{token-transactions-BZGtwFFM.d.cts → token-transactions-DscJaJOE.d.ts} +5 -19
  52. package/dist/types/index.cjs +923 -125
  53. package/dist/types/index.d.cts +2 -2
  54. package/dist/types/index.d.ts +2 -2
  55. package/dist/types/index.js +2 -2
  56. package/package.json +1 -1
  57. package/src/proto/spark.ts +1167 -103
  58. package/src/services/config.ts +0 -4
  59. package/src/services/token-transactions.ts +11 -703
  60. package/src/services/wallet-config.ts +0 -2
  61. package/src/spark-wallet/proto-descriptors.ts +1 -1
  62. package/src/spark-wallet/spark-wallet.ts +58 -215
  63. package/src/spark_descriptors.pb +0 -0
  64. package/src/tests/address.test.ts +141 -0
  65. package/src/tests/integration/address.test.ts +4 -0
  66. package/src/tests/integration/lightning.test.ts +14 -9
  67. package/src/tests/integration/token-output.test.ts +0 -1
  68. package/src/tests/integration/transfer.test.ts +108 -2
  69. package/src/tests/token-hashing.test.ts +0 -247
  70. package/src/utils/address.ts +58 -35
  71. package/src/utils/token-hashing.ts +1 -420
  72. package/src/utils/token-transaction-validation.ts +0 -330
@@ -1450,6 +1450,7 @@ __export(index_node_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_node_exports, {
1513
1514
  getTxIdNoReverse: () => getTxIdNoReverse,
1514
1515
  initializeTracerEnv: () => initializeTracerEnvNodeJS,
1515
1516
  isEphemeralAnchorOutput: () => isEphemeralAnchorOutput,
1517
+ isLegacySparkAddress: () => isLegacySparkAddress,
1516
1518
  isSafeForNumber: () => isSafeForNumber,
1517
1519
  isTxBroadcast: () => isTxBroadcast,
1518
1520
  isValidPublicKey: () => isValidPublicKey,
@@ -2277,9 +2279,9 @@ function invoiceStatusFromJSON(object) {
2277
2279
  case 2:
2278
2280
  case "FINALIZED":
2279
2281
  return 2 /* FINALIZED */;
2280
- case 3:
2281
- case "EXPIRED":
2282
- return 3 /* EXPIRED */;
2282
+ case 4:
2283
+ case "RETURNED":
2284
+ return 4 /* RETURNED */;
2283
2285
  case -1:
2284
2286
  case "UNRECOGNIZED":
2285
2287
  default:
@@ -2294,8 +2296,8 @@ function invoiceStatusToJSON(object) {
2294
2296
  return "PENDING";
2295
2297
  case 2 /* FINALIZED */:
2296
2298
  return "FINALIZED";
2297
- case 3 /* EXPIRED */:
2298
- return "EXPIRED";
2299
+ case 4 /* RETURNED */:
2300
+ return "RETURNED";
2299
2301
  case -1 /* UNRECOGNIZED */:
2300
2302
  default:
2301
2303
  return "UNRECOGNIZED";
@@ -4099,6 +4101,626 @@ var SigningResult_SignatureSharesEntry = {
4099
4101
  return message;
4100
4102
  }
4101
4103
  };
4104
+ function createBaseRenewLeafRequest() {
4105
+ return { leafId: "", ownerIdentityPublicKey: new Uint8Array(0), signingJobs: void 0 };
4106
+ }
4107
+ var RenewLeafRequest = {
4108
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4109
+ if (message.leafId !== "") {
4110
+ writer.uint32(10).string(message.leafId);
4111
+ }
4112
+ if (message.ownerIdentityPublicKey.length !== 0) {
4113
+ writer.uint32(18).bytes(message.ownerIdentityPublicKey);
4114
+ }
4115
+ switch (message.signingJobs?.$case) {
4116
+ case "renewNodeTimelockSigningJob":
4117
+ RenewNodeTimelockSigningJob.encode(message.signingJobs.renewNodeTimelockSigningJob, writer.uint32(26).fork()).join();
4118
+ break;
4119
+ case "renewRefundTimelockSigningJob":
4120
+ RenewRefundTimelockSigningJob.encode(
4121
+ message.signingJobs.renewRefundTimelockSigningJob,
4122
+ writer.uint32(34).fork()
4123
+ ).join();
4124
+ break;
4125
+ }
4126
+ return writer;
4127
+ },
4128
+ decode(input, length) {
4129
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4130
+ const end = length === void 0 ? reader.len : reader.pos + length;
4131
+ const message = createBaseRenewLeafRequest();
4132
+ while (reader.pos < end) {
4133
+ const tag = reader.uint32();
4134
+ switch (tag >>> 3) {
4135
+ case 1: {
4136
+ if (tag !== 10) {
4137
+ break;
4138
+ }
4139
+ message.leafId = reader.string();
4140
+ continue;
4141
+ }
4142
+ case 2: {
4143
+ if (tag !== 18) {
4144
+ break;
4145
+ }
4146
+ message.ownerIdentityPublicKey = reader.bytes();
4147
+ continue;
4148
+ }
4149
+ case 3: {
4150
+ if (tag !== 26) {
4151
+ break;
4152
+ }
4153
+ message.signingJobs = {
4154
+ $case: "renewNodeTimelockSigningJob",
4155
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.decode(reader, reader.uint32())
4156
+ };
4157
+ continue;
4158
+ }
4159
+ case 4: {
4160
+ if (tag !== 34) {
4161
+ break;
4162
+ }
4163
+ message.signingJobs = {
4164
+ $case: "renewRefundTimelockSigningJob",
4165
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.decode(reader, reader.uint32())
4166
+ };
4167
+ continue;
4168
+ }
4169
+ }
4170
+ if ((tag & 7) === 4 || tag === 0) {
4171
+ break;
4172
+ }
4173
+ reader.skip(tag & 7);
4174
+ }
4175
+ return message;
4176
+ },
4177
+ fromJSON(object) {
4178
+ return {
4179
+ leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : "",
4180
+ ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
4181
+ signingJobs: isSet3(object.renewNodeTimelockSigningJob) ? {
4182
+ $case: "renewNodeTimelockSigningJob",
4183
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromJSON(object.renewNodeTimelockSigningJob)
4184
+ } : isSet3(object.renewRefundTimelockSigningJob) ? {
4185
+ $case: "renewRefundTimelockSigningJob",
4186
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromJSON(object.renewRefundTimelockSigningJob)
4187
+ } : void 0
4188
+ };
4189
+ },
4190
+ toJSON(message) {
4191
+ const obj = {};
4192
+ if (message.leafId !== "") {
4193
+ obj.leafId = message.leafId;
4194
+ }
4195
+ if (message.ownerIdentityPublicKey.length !== 0) {
4196
+ obj.ownerIdentityPublicKey = base64FromBytes2(message.ownerIdentityPublicKey);
4197
+ }
4198
+ if (message.signingJobs?.$case === "renewNodeTimelockSigningJob") {
4199
+ obj.renewNodeTimelockSigningJob = RenewNodeTimelockSigningJob.toJSON(
4200
+ message.signingJobs.renewNodeTimelockSigningJob
4201
+ );
4202
+ } else if (message.signingJobs?.$case === "renewRefundTimelockSigningJob") {
4203
+ obj.renewRefundTimelockSigningJob = RenewRefundTimelockSigningJob.toJSON(
4204
+ message.signingJobs.renewRefundTimelockSigningJob
4205
+ );
4206
+ }
4207
+ return obj;
4208
+ },
4209
+ create(base) {
4210
+ return RenewLeafRequest.fromPartial(base ?? {});
4211
+ },
4212
+ fromPartial(object) {
4213
+ const message = createBaseRenewLeafRequest();
4214
+ message.leafId = object.leafId ?? "";
4215
+ message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
4216
+ switch (object.signingJobs?.$case) {
4217
+ case "renewNodeTimelockSigningJob": {
4218
+ if (object.signingJobs?.renewNodeTimelockSigningJob !== void 0 && object.signingJobs?.renewNodeTimelockSigningJob !== null) {
4219
+ message.signingJobs = {
4220
+ $case: "renewNodeTimelockSigningJob",
4221
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromPartial(
4222
+ object.signingJobs.renewNodeTimelockSigningJob
4223
+ )
4224
+ };
4225
+ }
4226
+ break;
4227
+ }
4228
+ case "renewRefundTimelockSigningJob": {
4229
+ if (object.signingJobs?.renewRefundTimelockSigningJob !== void 0 && object.signingJobs?.renewRefundTimelockSigningJob !== null) {
4230
+ message.signingJobs = {
4231
+ $case: "renewRefundTimelockSigningJob",
4232
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromPartial(
4233
+ object.signingJobs.renewRefundTimelockSigningJob
4234
+ )
4235
+ };
4236
+ }
4237
+ break;
4238
+ }
4239
+ }
4240
+ return message;
4241
+ }
4242
+ };
4243
+ function createBaseRenewNodeTimelockSigningJob() {
4244
+ return {
4245
+ splitNodeTxSigningJob: void 0,
4246
+ splitNodeDirectTxSigningJob: void 0,
4247
+ nodeTxSigningJob: void 0,
4248
+ refundTxSigningJob: void 0,
4249
+ directNodeTxSigningJob: void 0,
4250
+ directRefundTxSigningJob: void 0,
4251
+ directFromCpfpRefundTxSigningJob: void 0
4252
+ };
4253
+ }
4254
+ var RenewNodeTimelockSigningJob = {
4255
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4256
+ if (message.splitNodeTxSigningJob !== void 0) {
4257
+ UserSignedTxSigningJob.encode(message.splitNodeTxSigningJob, writer.uint32(10).fork()).join();
4258
+ }
4259
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
4260
+ UserSignedTxSigningJob.encode(message.splitNodeDirectTxSigningJob, writer.uint32(18).fork()).join();
4261
+ }
4262
+ if (message.nodeTxSigningJob !== void 0) {
4263
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(26).fork()).join();
4264
+ }
4265
+ if (message.refundTxSigningJob !== void 0) {
4266
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(34).fork()).join();
4267
+ }
4268
+ if (message.directNodeTxSigningJob !== void 0) {
4269
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(42).fork()).join();
4270
+ }
4271
+ if (message.directRefundTxSigningJob !== void 0) {
4272
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(50).fork()).join();
4273
+ }
4274
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4275
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(58).fork()).join();
4276
+ }
4277
+ return writer;
4278
+ },
4279
+ decode(input, length) {
4280
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4281
+ const end = length === void 0 ? reader.len : reader.pos + length;
4282
+ const message = createBaseRenewNodeTimelockSigningJob();
4283
+ while (reader.pos < end) {
4284
+ const tag = reader.uint32();
4285
+ switch (tag >>> 3) {
4286
+ case 1: {
4287
+ if (tag !== 10) {
4288
+ break;
4289
+ }
4290
+ message.splitNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4291
+ continue;
4292
+ }
4293
+ case 2: {
4294
+ if (tag !== 18) {
4295
+ break;
4296
+ }
4297
+ message.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4298
+ continue;
4299
+ }
4300
+ case 3: {
4301
+ if (tag !== 26) {
4302
+ break;
4303
+ }
4304
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4305
+ continue;
4306
+ }
4307
+ case 4: {
4308
+ if (tag !== 34) {
4309
+ break;
4310
+ }
4311
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4312
+ continue;
4313
+ }
4314
+ case 5: {
4315
+ if (tag !== 42) {
4316
+ break;
4317
+ }
4318
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4319
+ continue;
4320
+ }
4321
+ case 6: {
4322
+ if (tag !== 50) {
4323
+ break;
4324
+ }
4325
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4326
+ continue;
4327
+ }
4328
+ case 7: {
4329
+ if (tag !== 58) {
4330
+ break;
4331
+ }
4332
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4333
+ continue;
4334
+ }
4335
+ }
4336
+ if ((tag & 7) === 4 || tag === 0) {
4337
+ break;
4338
+ }
4339
+ reader.skip(tag & 7);
4340
+ }
4341
+ return message;
4342
+ },
4343
+ fromJSON(object) {
4344
+ return {
4345
+ splitNodeTxSigningJob: isSet3(object.splitNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeTxSigningJob) : void 0,
4346
+ splitNodeDirectTxSigningJob: isSet3(object.splitNodeDirectTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeDirectTxSigningJob) : void 0,
4347
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
4348
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
4349
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
4350
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
4351
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
4352
+ };
4353
+ },
4354
+ toJSON(message) {
4355
+ const obj = {};
4356
+ if (message.splitNodeTxSigningJob !== void 0) {
4357
+ obj.splitNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeTxSigningJob);
4358
+ }
4359
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
4360
+ obj.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeDirectTxSigningJob);
4361
+ }
4362
+ if (message.nodeTxSigningJob !== void 0) {
4363
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
4364
+ }
4365
+ if (message.refundTxSigningJob !== void 0) {
4366
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
4367
+ }
4368
+ if (message.directNodeTxSigningJob !== void 0) {
4369
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
4370
+ }
4371
+ if (message.directRefundTxSigningJob !== void 0) {
4372
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
4373
+ }
4374
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4375
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
4376
+ }
4377
+ return obj;
4378
+ },
4379
+ create(base) {
4380
+ return RenewNodeTimelockSigningJob.fromPartial(base ?? {});
4381
+ },
4382
+ fromPartial(object) {
4383
+ const message = createBaseRenewNodeTimelockSigningJob();
4384
+ message.splitNodeTxSigningJob = object.splitNodeTxSigningJob !== void 0 && object.splitNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeTxSigningJob) : void 0;
4385
+ message.splitNodeDirectTxSigningJob = object.splitNodeDirectTxSigningJob !== void 0 && object.splitNodeDirectTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeDirectTxSigningJob) : void 0;
4386
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
4387
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
4388
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
4389
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
4390
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
4391
+ return message;
4392
+ }
4393
+ };
4394
+ function createBaseRenewRefundTimelockSigningJob() {
4395
+ return {
4396
+ nodeTxSigningJob: void 0,
4397
+ refundTxSigningJob: void 0,
4398
+ directNodeTxSigningJob: void 0,
4399
+ directRefundTxSigningJob: void 0,
4400
+ directFromCpfpRefundTxSigningJob: void 0
4401
+ };
4402
+ }
4403
+ var RenewRefundTimelockSigningJob = {
4404
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4405
+ if (message.nodeTxSigningJob !== void 0) {
4406
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(10).fork()).join();
4407
+ }
4408
+ if (message.refundTxSigningJob !== void 0) {
4409
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(18).fork()).join();
4410
+ }
4411
+ if (message.directNodeTxSigningJob !== void 0) {
4412
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(26).fork()).join();
4413
+ }
4414
+ if (message.directRefundTxSigningJob !== void 0) {
4415
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(34).fork()).join();
4416
+ }
4417
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4418
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(42).fork()).join();
4419
+ }
4420
+ return writer;
4421
+ },
4422
+ decode(input, length) {
4423
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4424
+ const end = length === void 0 ? reader.len : reader.pos + length;
4425
+ const message = createBaseRenewRefundTimelockSigningJob();
4426
+ while (reader.pos < end) {
4427
+ const tag = reader.uint32();
4428
+ switch (tag >>> 3) {
4429
+ case 1: {
4430
+ if (tag !== 10) {
4431
+ break;
4432
+ }
4433
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4434
+ continue;
4435
+ }
4436
+ case 2: {
4437
+ if (tag !== 18) {
4438
+ break;
4439
+ }
4440
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4441
+ continue;
4442
+ }
4443
+ case 3: {
4444
+ if (tag !== 26) {
4445
+ break;
4446
+ }
4447
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4448
+ continue;
4449
+ }
4450
+ case 4: {
4451
+ if (tag !== 34) {
4452
+ break;
4453
+ }
4454
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4455
+ continue;
4456
+ }
4457
+ case 5: {
4458
+ if (tag !== 42) {
4459
+ break;
4460
+ }
4461
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4462
+ continue;
4463
+ }
4464
+ }
4465
+ if ((tag & 7) === 4 || tag === 0) {
4466
+ break;
4467
+ }
4468
+ reader.skip(tag & 7);
4469
+ }
4470
+ return message;
4471
+ },
4472
+ fromJSON(object) {
4473
+ return {
4474
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
4475
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
4476
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
4477
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
4478
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
4479
+ };
4480
+ },
4481
+ toJSON(message) {
4482
+ const obj = {};
4483
+ if (message.nodeTxSigningJob !== void 0) {
4484
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
4485
+ }
4486
+ if (message.refundTxSigningJob !== void 0) {
4487
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
4488
+ }
4489
+ if (message.directNodeTxSigningJob !== void 0) {
4490
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
4491
+ }
4492
+ if (message.directRefundTxSigningJob !== void 0) {
4493
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
4494
+ }
4495
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4496
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
4497
+ }
4498
+ return obj;
4499
+ },
4500
+ create(base) {
4501
+ return RenewRefundTimelockSigningJob.fromPartial(base ?? {});
4502
+ },
4503
+ fromPartial(object) {
4504
+ const message = createBaseRenewRefundTimelockSigningJob();
4505
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
4506
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
4507
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
4508
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
4509
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
4510
+ return message;
4511
+ }
4512
+ };
4513
+ function createBaseRenewLeafResponse() {
4514
+ return { renewResult: void 0 };
4515
+ }
4516
+ var RenewLeafResponse = {
4517
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4518
+ switch (message.renewResult?.$case) {
4519
+ case "extendResult":
4520
+ RenewNodeTimelockResult.encode(message.renewResult.extendResult, writer.uint32(10).fork()).join();
4521
+ break;
4522
+ case "refreshResult":
4523
+ RenewRefundTimelockResult.encode(message.renewResult.refreshResult, writer.uint32(18).fork()).join();
4524
+ break;
4525
+ }
4526
+ return writer;
4527
+ },
4528
+ decode(input, length) {
4529
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4530
+ const end = length === void 0 ? reader.len : reader.pos + length;
4531
+ const message = createBaseRenewLeafResponse();
4532
+ while (reader.pos < end) {
4533
+ const tag = reader.uint32();
4534
+ switch (tag >>> 3) {
4535
+ case 1: {
4536
+ if (tag !== 10) {
4537
+ break;
4538
+ }
4539
+ message.renewResult = {
4540
+ $case: "extendResult",
4541
+ extendResult: RenewNodeTimelockResult.decode(reader, reader.uint32())
4542
+ };
4543
+ continue;
4544
+ }
4545
+ case 2: {
4546
+ if (tag !== 18) {
4547
+ break;
4548
+ }
4549
+ message.renewResult = {
4550
+ $case: "refreshResult",
4551
+ refreshResult: RenewRefundTimelockResult.decode(reader, reader.uint32())
4552
+ };
4553
+ continue;
4554
+ }
4555
+ }
4556
+ if ((tag & 7) === 4 || tag === 0) {
4557
+ break;
4558
+ }
4559
+ reader.skip(tag & 7);
4560
+ }
4561
+ return message;
4562
+ },
4563
+ fromJSON(object) {
4564
+ return {
4565
+ renewResult: isSet3(object.extendResult) ? { $case: "extendResult", extendResult: RenewNodeTimelockResult.fromJSON(object.extendResult) } : isSet3(object.refreshResult) ? { $case: "refreshResult", refreshResult: RenewRefundTimelockResult.fromJSON(object.refreshResult) } : void 0
4566
+ };
4567
+ },
4568
+ toJSON(message) {
4569
+ const obj = {};
4570
+ if (message.renewResult?.$case === "extendResult") {
4571
+ obj.extendResult = RenewNodeTimelockResult.toJSON(message.renewResult.extendResult);
4572
+ } else if (message.renewResult?.$case === "refreshResult") {
4573
+ obj.refreshResult = RenewRefundTimelockResult.toJSON(message.renewResult.refreshResult);
4574
+ }
4575
+ return obj;
4576
+ },
4577
+ create(base) {
4578
+ return RenewLeafResponse.fromPartial(base ?? {});
4579
+ },
4580
+ fromPartial(object) {
4581
+ const message = createBaseRenewLeafResponse();
4582
+ switch (object.renewResult?.$case) {
4583
+ case "extendResult": {
4584
+ if (object.renewResult?.extendResult !== void 0 && object.renewResult?.extendResult !== null) {
4585
+ message.renewResult = {
4586
+ $case: "extendResult",
4587
+ extendResult: RenewNodeTimelockResult.fromPartial(object.renewResult.extendResult)
4588
+ };
4589
+ }
4590
+ break;
4591
+ }
4592
+ case "refreshResult": {
4593
+ if (object.renewResult?.refreshResult !== void 0 && object.renewResult?.refreshResult !== null) {
4594
+ message.renewResult = {
4595
+ $case: "refreshResult",
4596
+ refreshResult: RenewRefundTimelockResult.fromPartial(object.renewResult.refreshResult)
4597
+ };
4598
+ }
4599
+ break;
4600
+ }
4601
+ }
4602
+ return message;
4603
+ }
4604
+ };
4605
+ function createBaseRenewNodeTimelockResult() {
4606
+ return { splitNode: void 0, node: void 0 };
4607
+ }
4608
+ var RenewNodeTimelockResult = {
4609
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4610
+ if (message.splitNode !== void 0) {
4611
+ TreeNode.encode(message.splitNode, writer.uint32(10).fork()).join();
4612
+ }
4613
+ if (message.node !== void 0) {
4614
+ TreeNode.encode(message.node, writer.uint32(18).fork()).join();
4615
+ }
4616
+ return writer;
4617
+ },
4618
+ decode(input, length) {
4619
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4620
+ const end = length === void 0 ? reader.len : reader.pos + length;
4621
+ const message = createBaseRenewNodeTimelockResult();
4622
+ while (reader.pos < end) {
4623
+ const tag = reader.uint32();
4624
+ switch (tag >>> 3) {
4625
+ case 1: {
4626
+ if (tag !== 10) {
4627
+ break;
4628
+ }
4629
+ message.splitNode = TreeNode.decode(reader, reader.uint32());
4630
+ continue;
4631
+ }
4632
+ case 2: {
4633
+ if (tag !== 18) {
4634
+ break;
4635
+ }
4636
+ message.node = TreeNode.decode(reader, reader.uint32());
4637
+ continue;
4638
+ }
4639
+ }
4640
+ if ((tag & 7) === 4 || tag === 0) {
4641
+ break;
4642
+ }
4643
+ reader.skip(tag & 7);
4644
+ }
4645
+ return message;
4646
+ },
4647
+ fromJSON(object) {
4648
+ return {
4649
+ splitNode: isSet3(object.splitNode) ? TreeNode.fromJSON(object.splitNode) : void 0,
4650
+ node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0
4651
+ };
4652
+ },
4653
+ toJSON(message) {
4654
+ const obj = {};
4655
+ if (message.splitNode !== void 0) {
4656
+ obj.splitNode = TreeNode.toJSON(message.splitNode);
4657
+ }
4658
+ if (message.node !== void 0) {
4659
+ obj.node = TreeNode.toJSON(message.node);
4660
+ }
4661
+ return obj;
4662
+ },
4663
+ create(base) {
4664
+ return RenewNodeTimelockResult.fromPartial(base ?? {});
4665
+ },
4666
+ fromPartial(object) {
4667
+ const message = createBaseRenewNodeTimelockResult();
4668
+ message.splitNode = object.splitNode !== void 0 && object.splitNode !== null ? TreeNode.fromPartial(object.splitNode) : void 0;
4669
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
4670
+ return message;
4671
+ }
4672
+ };
4673
+ function createBaseRenewRefundTimelockResult() {
4674
+ return { node: void 0 };
4675
+ }
4676
+ var RenewRefundTimelockResult = {
4677
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4678
+ if (message.node !== void 0) {
4679
+ TreeNode.encode(message.node, writer.uint32(10).fork()).join();
4680
+ }
4681
+ return writer;
4682
+ },
4683
+ decode(input, length) {
4684
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4685
+ const end = length === void 0 ? reader.len : reader.pos + length;
4686
+ const message = createBaseRenewRefundTimelockResult();
4687
+ while (reader.pos < end) {
4688
+ const tag = reader.uint32();
4689
+ switch (tag >>> 3) {
4690
+ case 1: {
4691
+ if (tag !== 10) {
4692
+ break;
4693
+ }
4694
+ message.node = TreeNode.decode(reader, reader.uint32());
4695
+ continue;
4696
+ }
4697
+ }
4698
+ if ((tag & 7) === 4 || tag === 0) {
4699
+ break;
4700
+ }
4701
+ reader.skip(tag & 7);
4702
+ }
4703
+ return message;
4704
+ },
4705
+ fromJSON(object) {
4706
+ return { node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0 };
4707
+ },
4708
+ toJSON(message) {
4709
+ const obj = {};
4710
+ if (message.node !== void 0) {
4711
+ obj.node = TreeNode.toJSON(message.node);
4712
+ }
4713
+ return obj;
4714
+ },
4715
+ create(base) {
4716
+ return RenewRefundTimelockResult.fromPartial(base ?? {});
4717
+ },
4718
+ fromPartial(object) {
4719
+ const message = createBaseRenewRefundTimelockResult();
4720
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
4721
+ return message;
4722
+ }
4723
+ };
4102
4724
  function createBaseNodeSignatureShares() {
4103
4725
  return {
4104
4726
  nodeId: "",
@@ -15879,7 +16501,7 @@ var QuerySparkInvoicesResponse = {
15879
16501
  }
15880
16502
  };
15881
16503
  function createBaseInvoiceResponse() {
15882
- return { invoice: "", status: 0 };
16504
+ return { invoice: "", status: 0, transferType: void 0 };
15883
16505
  }
15884
16506
  var InvoiceResponse = {
15885
16507
  encode(message, writer = new import_wire4.BinaryWriter()) {
@@ -15889,6 +16511,14 @@ var InvoiceResponse = {
15889
16511
  if (message.status !== 0) {
15890
16512
  writer.uint32(16).int32(message.status);
15891
16513
  }
16514
+ switch (message.transferType?.$case) {
16515
+ case "satsTransfer":
16516
+ SatsTransfer.encode(message.transferType.satsTransfer, writer.uint32(26).fork()).join();
16517
+ break;
16518
+ case "tokenTransfer":
16519
+ TokenTransfer.encode(message.transferType.tokenTransfer, writer.uint32(34).fork()).join();
16520
+ break;
16521
+ }
15892
16522
  return writer;
15893
16523
  },
15894
16524
  decode(input, length) {
@@ -15912,6 +16542,23 @@ var InvoiceResponse = {
15912
16542
  message.status = reader.int32();
15913
16543
  continue;
15914
16544
  }
16545
+ case 3: {
16546
+ if (tag !== 26) {
16547
+ break;
16548
+ }
16549
+ message.transferType = { $case: "satsTransfer", satsTransfer: SatsTransfer.decode(reader, reader.uint32()) };
16550
+ continue;
16551
+ }
16552
+ case 4: {
16553
+ if (tag !== 34) {
16554
+ break;
16555
+ }
16556
+ message.transferType = {
16557
+ $case: "tokenTransfer",
16558
+ tokenTransfer: TokenTransfer.decode(reader, reader.uint32())
16559
+ };
16560
+ continue;
16561
+ }
15915
16562
  }
15916
16563
  if ((tag & 7) === 4 || tag === 0) {
15917
16564
  break;
@@ -15923,7 +16570,8 @@ var InvoiceResponse = {
15923
16570
  fromJSON(object) {
15924
16571
  return {
15925
16572
  invoice: isSet3(object.invoice) ? globalThis.String(object.invoice) : "",
15926
- status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0
16573
+ status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0,
16574
+ transferType: isSet3(object.satsTransfer) ? { $case: "satsTransfer", satsTransfer: SatsTransfer.fromJSON(object.satsTransfer) } : isSet3(object.tokenTransfer) ? { $case: "tokenTransfer", tokenTransfer: TokenTransfer.fromJSON(object.tokenTransfer) } : void 0
15927
16575
  };
15928
16576
  },
15929
16577
  toJSON(message) {
@@ -15934,6 +16582,11 @@ var InvoiceResponse = {
15934
16582
  if (message.status !== 0) {
15935
16583
  obj.status = invoiceStatusToJSON(message.status);
15936
16584
  }
16585
+ if (message.transferType?.$case === "satsTransfer") {
16586
+ obj.satsTransfer = SatsTransfer.toJSON(message.transferType.satsTransfer);
16587
+ } else if (message.transferType?.$case === "tokenTransfer") {
16588
+ obj.tokenTransfer = TokenTransfer.toJSON(message.transferType.tokenTransfer);
16589
+ }
15937
16590
  return obj;
15938
16591
  },
15939
16592
  create(base) {
@@ -15943,6 +16596,130 @@ var InvoiceResponse = {
15943
16596
  const message = createBaseInvoiceResponse();
15944
16597
  message.invoice = object.invoice ?? "";
15945
16598
  message.status = object.status ?? 0;
16599
+ switch (object.transferType?.$case) {
16600
+ case "satsTransfer": {
16601
+ if (object.transferType?.satsTransfer !== void 0 && object.transferType?.satsTransfer !== null) {
16602
+ message.transferType = {
16603
+ $case: "satsTransfer",
16604
+ satsTransfer: SatsTransfer.fromPartial(object.transferType.satsTransfer)
16605
+ };
16606
+ }
16607
+ break;
16608
+ }
16609
+ case "tokenTransfer": {
16610
+ if (object.transferType?.tokenTransfer !== void 0 && object.transferType?.tokenTransfer !== null) {
16611
+ message.transferType = {
16612
+ $case: "tokenTransfer",
16613
+ tokenTransfer: TokenTransfer.fromPartial(object.transferType.tokenTransfer)
16614
+ };
16615
+ }
16616
+ break;
16617
+ }
16618
+ }
16619
+ return message;
16620
+ }
16621
+ };
16622
+ function createBaseSatsTransfer() {
16623
+ return { transferId: new Uint8Array(0) };
16624
+ }
16625
+ var SatsTransfer = {
16626
+ encode(message, writer = new import_wire4.BinaryWriter()) {
16627
+ if (message.transferId.length !== 0) {
16628
+ writer.uint32(10).bytes(message.transferId);
16629
+ }
16630
+ return writer;
16631
+ },
16632
+ decode(input, length) {
16633
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
16634
+ const end = length === void 0 ? reader.len : reader.pos + length;
16635
+ const message = createBaseSatsTransfer();
16636
+ while (reader.pos < end) {
16637
+ const tag = reader.uint32();
16638
+ switch (tag >>> 3) {
16639
+ case 1: {
16640
+ if (tag !== 10) {
16641
+ break;
16642
+ }
16643
+ message.transferId = reader.bytes();
16644
+ continue;
16645
+ }
16646
+ }
16647
+ if ((tag & 7) === 4 || tag === 0) {
16648
+ break;
16649
+ }
16650
+ reader.skip(tag & 7);
16651
+ }
16652
+ return message;
16653
+ },
16654
+ fromJSON(object) {
16655
+ return { transferId: isSet3(object.transferId) ? bytesFromBase642(object.transferId) : new Uint8Array(0) };
16656
+ },
16657
+ toJSON(message) {
16658
+ const obj = {};
16659
+ if (message.transferId.length !== 0) {
16660
+ obj.transferId = base64FromBytes2(message.transferId);
16661
+ }
16662
+ return obj;
16663
+ },
16664
+ create(base) {
16665
+ return SatsTransfer.fromPartial(base ?? {});
16666
+ },
16667
+ fromPartial(object) {
16668
+ const message = createBaseSatsTransfer();
16669
+ message.transferId = object.transferId ?? new Uint8Array(0);
16670
+ return message;
16671
+ }
16672
+ };
16673
+ function createBaseTokenTransfer() {
16674
+ return { finalTokenTransactionHash: new Uint8Array(0) };
16675
+ }
16676
+ var TokenTransfer = {
16677
+ encode(message, writer = new import_wire4.BinaryWriter()) {
16678
+ if (message.finalTokenTransactionHash.length !== 0) {
16679
+ writer.uint32(10).bytes(message.finalTokenTransactionHash);
16680
+ }
16681
+ return writer;
16682
+ },
16683
+ decode(input, length) {
16684
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
16685
+ const end = length === void 0 ? reader.len : reader.pos + length;
16686
+ const message = createBaseTokenTransfer();
16687
+ while (reader.pos < end) {
16688
+ const tag = reader.uint32();
16689
+ switch (tag >>> 3) {
16690
+ case 1: {
16691
+ if (tag !== 10) {
16692
+ break;
16693
+ }
16694
+ message.finalTokenTransactionHash = reader.bytes();
16695
+ continue;
16696
+ }
16697
+ }
16698
+ if ((tag & 7) === 4 || tag === 0) {
16699
+ break;
16700
+ }
16701
+ reader.skip(tag & 7);
16702
+ }
16703
+ return message;
16704
+ },
16705
+ fromJSON(object) {
16706
+ return {
16707
+ finalTokenTransactionHash: isSet3(object.finalTokenTransactionHash) ? bytesFromBase642(object.finalTokenTransactionHash) : new Uint8Array(0)
16708
+ };
16709
+ },
16710
+ toJSON(message) {
16711
+ const obj = {};
16712
+ if (message.finalTokenTransactionHash.length !== 0) {
16713
+ obj.finalTokenTransactionHash = base64FromBytes2(message.finalTokenTransactionHash);
16714
+ }
16715
+ return obj;
16716
+ },
16717
+ create(base) {
16718
+ return TokenTransfer.fromPartial(base ?? {});
16719
+ },
16720
+ fromPartial(object) {
16721
+ const message = createBaseTokenTransfer();
16722
+ message.finalTokenTransactionHash = object.finalTokenTransactionHash ?? new Uint8Array(0);
15946
16723
  return message;
15947
16724
  }
15948
16725
  };
@@ -16158,6 +16935,21 @@ var SparkServiceDefinition = {
16158
16935
  responseStream: false,
16159
16936
  options: {}
16160
16937
  },
16938
+ /**
16939
+ * Resets the timelocks for a leaf's transactions. Can be used to reset the
16940
+ * refund transaction timelock for a leaf (when the node transaction
16941
+ * timelock is still > 300) or reset the node and refund transaction
16942
+ * timelock. Returns an error if a leaf is not yet eligible to renew the
16943
+ * timelocks, see RenewLeafRequest for more details.
16944
+ */
16945
+ renew_leaf: {
16946
+ name: "renew_leaf",
16947
+ requestType: RenewLeafRequest,
16948
+ requestStream: false,
16949
+ responseType: RenewLeafResponse,
16950
+ responseStream: false,
16951
+ options: {}
16952
+ },
16161
16953
  get_signing_operator_list: {
16162
16954
  name: "get_signing_operator_list",
16163
16955
  requestType: Empty,
@@ -16648,6 +17440,13 @@ function uint64be(value) {
16648
17440
  // src/utils/address.ts
16649
17441
  var BECH32M_LIMIT = 1024;
16650
17442
  var AddressNetwork = {
17443
+ MAINNET: "spark",
17444
+ TESTNET: "sparkt",
17445
+ REGTEST: "sparkrt",
17446
+ SIGNET: "sparks",
17447
+ LOCAL: "sparkl"
17448
+ };
17449
+ var LegacyAddressNetwork = {
16651
17450
  MAINNET: "sp",
16652
17451
  TESTNET: "spt",
16653
17452
  REGTEST: "sprt",
@@ -16678,7 +17477,7 @@ function encodeSparkAddressWithSignature(payload, signature) {
16678
17477
  const serializedPayload = w.finish();
16679
17478
  const words = import_base2.bech32m.toWords(serializedPayload);
16680
17479
  return bech32mEncode(
16681
- AddressNetwork[payload.network],
17480
+ LegacyAddressNetwork[payload.network],
16682
17481
  words
16683
17482
  );
16684
17483
  } catch (error) {
@@ -16694,14 +17493,14 @@ function encodeSparkAddressWithSignature(payload, signature) {
16694
17493
  }
16695
17494
  function decodeSparkAddress(address2, network) {
16696
17495
  try {
16697
- const decoded = bech32mDecode(address2);
16698
- if (decoded.prefix !== AddressNetwork[network]) {
17496
+ if (network !== getNetworkFromSparkAddress(address2)) {
16699
17497
  throw new ValidationError("Invalid Spark address prefix", {
16700
17498
  field: "address",
16701
17499
  value: address2,
16702
- expected: `prefix='${AddressNetwork[network]}'`
17500
+ expected: `prefix='${AddressNetwork[network]}' or '${LegacyAddressNetwork[network]}'`
16703
17501
  });
16704
17502
  }
17503
+ const decoded = bech32mDecode(address2);
16705
17504
  const payload = SparkAddress.decode(import_base2.bech32m.fromWords(decoded.words));
16706
17505
  const { identityPublicKey, sparkInvoiceFields, signature } = payload;
16707
17506
  const identityPubkeyHex = (0, import_utils3.bytesToHex)(identityPublicKey);
@@ -16745,18 +17544,35 @@ function decodeSparkAddress(address2, network) {
16745
17544
  );
16746
17545
  }
16747
17546
  }
17547
+ var PrefixToNetwork = Object.fromEntries(
17548
+ Object.entries(AddressNetwork).map(([k, v]) => [v, k])
17549
+ );
17550
+ var LegacyPrefixToNetwork = Object.fromEntries(
17551
+ Object.entries(LegacyAddressNetwork).map(([k, v]) => [v, k])
17552
+ );
17553
+ function getNetworkFromSparkAddress(address2) {
17554
+ const { prefix } = bech32mDecode(address2);
17555
+ const network = PrefixToNetwork[prefix] ?? LegacyPrefixToNetwork[prefix];
17556
+ if (!network) {
17557
+ throw new ValidationError("Invalid Spark address prefix", {
17558
+ field: "network",
17559
+ value: address2,
17560
+ expected: "prefix='spark1', 'sparkt1', 'sparkrt1', 'sparks1', 'sparkl1' or legacy ('sp1', 'spt1', 'sprt1', 'sps1', 'spl1')"
17561
+ });
17562
+ }
17563
+ return network;
17564
+ }
17565
+ function isLegacySparkAddress(address2) {
17566
+ try {
17567
+ const { prefix } = bech32mDecode(address2);
17568
+ return prefix in LegacyPrefixToNetwork;
17569
+ } catch (error) {
17570
+ return false;
17571
+ }
17572
+ }
16748
17573
  function isValidSparkAddress(address2) {
16749
17574
  try {
16750
- const network = Object.entries(AddressNetwork).find(
16751
- ([_, prefix]) => address2.startsWith(prefix)
16752
- )?.[0];
16753
- if (!network) {
16754
- throw new ValidationError("Invalid Spark address network", {
16755
- field: "network",
16756
- value: address2,
16757
- expected: Object.values(AddressNetwork)
16758
- });
16759
- }
17575
+ const network = getNetworkFromSparkAddress(address2);
16760
17576
  decodeSparkAddress(address2, network);
16761
17577
  return true;
16762
17578
  } catch (error) {
@@ -16952,25 +17768,16 @@ function validateSparkInvoiceSignature(invoice) {
16952
17768
  );
16953
17769
  }
16954
17770
  }
16955
- function getNetworkFromSparkAddress(address2) {
16956
- const { prefix } = bech32mDecode(address2);
16957
- const network = Object.entries(AddressNetwork).find(
16958
- ([, p]) => p === prefix
16959
- )?.[0];
16960
- if (!network) {
16961
- throw new ValidationError("Invalid Spark address network", {
16962
- field: "network",
16963
- value: address2,
16964
- expected: Object.values(AddressNetwork)
16965
- });
16966
- }
16967
- return network;
16968
- }
16969
17771
  function toProtoTimestamp(date) {
16970
17772
  const ms = date.getTime();
16971
17773
  return { seconds: Math.floor(ms / 1e3), nanos: ms % 1e3 * 1e6 };
16972
17774
  }
17775
+ function assertBech32(s) {
17776
+ const i = s.lastIndexOf("1");
17777
+ if (i <= 0 || i >= s.length - 1) throw new Error("invalid bech32 string");
17778
+ }
16973
17779
  function bech32mDecode(address2) {
17780
+ assertBech32(address2);
16974
17781
  return import_base2.bech32m.decode(address2, BECH32M_LIMIT);
16975
17782
  }
16976
17783
  function bech32mEncode(prefix, words) {
@@ -17583,7 +18390,6 @@ var BASE_CONFIG = {
17583
18390
  threshold: 2,
17584
18391
  signingOperators: getLocalSigningOperators(),
17585
18392
  tokenSignatures: "SCHNORR",
17586
- tokenTransactionVersion: "V1",
17587
18393
  tokenValidityDurationSeconds: 180,
17588
18394
  electrsUrl: getElectrsUrl("LOCAL"),
17589
18395
  expectedWithdrawBondSats: 1e4,
@@ -20113,7 +20919,7 @@ var isWebExtension = (
20113
20919
  "chrome" in globalThis && globalThis.chrome.runtime?.id
20114
20920
  );
20115
20921
  var userAgent = "navigator" in globalThis ? globalThis.navigator.userAgent || "unknown-user-agent" : void 0;
20116
- var packageVersion = true ? "0.3.3" : "unknown";
20922
+ var packageVersion = true ? "0.3.5" : "unknown";
20117
20923
  var baseEnvStr = "unknown";
20118
20924
  if (isBun) {
20119
20925
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -20647,7 +21453,7 @@ init_buffer();
20647
21453
  // src/spark-wallet/spark-wallet.ts
20648
21454
  init_buffer();
20649
21455
  var import_core13 = require("@lightsparkdev/core");
20650
- var import_secp256k115 = require("@noble/curves/secp256k1");
21456
+ var import_secp256k113 = require("@noble/curves/secp256k1");
20651
21457
  var import_utils24 = require("@noble/curves/utils");
20652
21458
  var import_bip392 = require("@scure/bip39");
20653
21459
  var import_english2 = require("@scure/bip39/wordlists/english");
@@ -21877,9 +22683,6 @@ var WalletConfigService = class {
21877
22683
  getTokenSignatures() {
21878
22684
  return this.config.tokenSignatures;
21879
22685
  }
21880
- getTokenTransactionVersion() {
21881
- return this.config.tokenTransactionVersion;
21882
- }
21883
22686
  getTokenValidityDurationSeconds() {
21884
22687
  return this.config.tokenValidityDurationSeconds;
21885
22688
  }
@@ -28774,7 +29577,6 @@ var LightningService = class {
28774
29577
 
28775
29578
  // src/services/token-transactions.ts
28776
29579
  init_buffer();
28777
- var import_secp256k113 = require("@noble/curves/secp256k1");
28778
29580
  var import_utils19 = require("@noble/curves/utils");
28779
29581
  var import_utils20 = require("@noble/hashes/utils");
28780
29582
 
@@ -28784,8 +29586,6 @@ var import_sha212 = require("@noble/hashes/sha2");
28784
29586
  var import_base4 = require("@scure/base");
28785
29587
  function hashTokenTransaction(tokenTransaction, partialHash = false) {
28786
29588
  switch (tokenTransaction.version) {
28787
- case 0:
28788
- return hashTokenTransactionV0(tokenTransaction, partialHash);
28789
29589
  case 1:
28790
29590
  return hashTokenTransactionV1(tokenTransaction, partialHash);
28791
29591
  case 2:
@@ -28797,345 +29597,6 @@ function hashTokenTransaction(tokenTransaction, partialHash = false) {
28797
29597
  });
28798
29598
  }
28799
29599
  }
28800
- function hashTokenTransactionV0(tokenTransaction, partialHash = false) {
28801
- if (!tokenTransaction) {
28802
- throw new ValidationError("token transaction cannot be nil", {
28803
- field: "tokenTransaction"
28804
- });
28805
- }
28806
- let allHashes = [];
28807
- if (tokenTransaction.tokenInputs?.$case === "transferInput") {
28808
- if (!tokenTransaction.tokenInputs.transferInput.outputsToSpend) {
28809
- throw new ValidationError("outputs to spend cannot be null", {
28810
- field: "tokenInputs.transferInput.outputsToSpend"
28811
- });
28812
- }
28813
- if (tokenTransaction.tokenInputs.transferInput.outputsToSpend.length === 0) {
28814
- throw new ValidationError("outputs to spend cannot be empty", {
28815
- field: "tokenInputs.transferInput.outputsToSpend"
28816
- });
28817
- }
28818
- for (const [
28819
- i,
28820
- output
28821
- ] of tokenTransaction.tokenInputs.transferInput.outputsToSpend.entries()) {
28822
- if (!output) {
28823
- throw new ValidationError(`output cannot be null at index ${i}`, {
28824
- field: `tokenInputs.transferInput.outputsToSpend[${i}]`,
28825
- index: i
28826
- });
28827
- }
28828
- const hashObj2 = import_sha212.sha256.create();
28829
- if (output.prevTokenTransactionHash) {
28830
- const prevHash = output.prevTokenTransactionHash;
28831
- if (output.prevTokenTransactionHash.length !== 32) {
28832
- throw new ValidationError(
28833
- `invalid previous transaction hash length at index ${i}`,
28834
- {
28835
- field: `tokenInputs.transferInput.outputsToSpend[${i}].prevTokenTransactionHash`,
28836
- value: prevHash,
28837
- expectedLength: 32,
28838
- actualLength: prevHash.length,
28839
- index: i
28840
- }
28841
- );
28842
- }
28843
- hashObj2.update(output.prevTokenTransactionHash);
28844
- }
28845
- const voutBytes = new Uint8Array(4);
28846
- new DataView(voutBytes.buffer).setUint32(
28847
- 0,
28848
- output.prevTokenTransactionVout,
28849
- false
28850
- );
28851
- hashObj2.update(voutBytes);
28852
- allHashes.push(hashObj2.digest());
28853
- }
28854
- }
28855
- if (tokenTransaction.tokenInputs?.$case === "mintInput") {
28856
- const hashObj2 = import_sha212.sha256.create();
28857
- if (tokenTransaction.tokenInputs.mintInput.issuerPublicKey) {
28858
- const issuerPubKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
28859
- if (issuerPubKey.length === 0) {
28860
- throw new ValidationError("issuer public key cannot be empty", {
28861
- field: "tokenInputs.mintInput.issuerPublicKey",
28862
- value: issuerPubKey,
28863
- expectedLength: 1,
28864
- actualLength: 0
28865
- });
28866
- }
28867
- hashObj2.update(issuerPubKey);
28868
- let timestampValue = 0;
28869
- const mintInput = tokenTransaction.tokenInputs.mintInput;
28870
- if ("issuerProvidedTimestamp" in mintInput) {
28871
- const v0MintInput = mintInput;
28872
- if (v0MintInput.issuerProvidedTimestamp != 0) {
28873
- timestampValue = v0MintInput.issuerProvidedTimestamp;
28874
- }
28875
- } else if ("clientCreatedTimestamp" in tokenTransaction && tokenTransaction.clientCreatedTimestamp) {
28876
- timestampValue = tokenTransaction.clientCreatedTimestamp.getTime();
28877
- }
28878
- if (timestampValue != 0) {
28879
- const timestampBytes = new Uint8Array(8);
28880
- new DataView(timestampBytes.buffer).setBigUint64(
28881
- 0,
28882
- BigInt(timestampValue),
28883
- true
28884
- // true for little-endian to match Go implementation
28885
- );
28886
- hashObj2.update(timestampBytes);
28887
- }
28888
- allHashes.push(hashObj2.digest());
28889
- }
28890
- }
28891
- if (tokenTransaction.tokenInputs?.$case === "createInput") {
28892
- const issuerPubKeyHashObj = import_sha212.sha256.create();
28893
- const createInput = tokenTransaction.tokenInputs.createInput;
28894
- if (!createInput.issuerPublicKey || createInput.issuerPublicKey.length === 0) {
28895
- throw new ValidationError("issuer public key cannot be nil or empty", {
28896
- field: "tokenInputs.createInput.issuerPublicKey"
28897
- });
28898
- }
28899
- issuerPubKeyHashObj.update(createInput.issuerPublicKey);
28900
- allHashes.push(issuerPubKeyHashObj.digest());
28901
- const tokenNameHashObj = import_sha212.sha256.create();
28902
- if (!createInput.tokenName || createInput.tokenName.length === 0) {
28903
- throw new ValidationError("token name cannot be empty", {
28904
- field: "tokenInputs.createInput.tokenName"
28905
- });
28906
- }
28907
- if (createInput.tokenName.length > 20) {
28908
- throw new ValidationError("token name cannot be longer than 20 bytes", {
28909
- field: "tokenInputs.createInput.tokenName",
28910
- value: createInput.tokenName,
28911
- expectedLength: 20,
28912
- actualLength: createInput.tokenName.length
28913
- });
28914
- }
28915
- const tokenNameBytes = new Uint8Array(20);
28916
- const tokenNameEncoder = new TextEncoder();
28917
- tokenNameBytes.set(tokenNameEncoder.encode(createInput.tokenName));
28918
- tokenNameHashObj.update(tokenNameBytes);
28919
- allHashes.push(tokenNameHashObj.digest());
28920
- const tokenTickerHashObj = import_sha212.sha256.create();
28921
- if (!createInput.tokenTicker || createInput.tokenTicker.length === 0) {
28922
- throw new ValidationError("token ticker cannot be empty", {
28923
- field: "tokenInputs.createInput.tokenTicker"
28924
- });
28925
- }
28926
- if (createInput.tokenTicker.length > 6) {
28927
- throw new ValidationError("token ticker cannot be longer than 6 bytes", {
28928
- field: "tokenInputs.createInput.tokenTicker",
28929
- value: createInput.tokenTicker,
28930
- expectedLength: 6,
28931
- actualLength: createInput.tokenTicker.length
28932
- });
28933
- }
28934
- const tokenTickerBytes = new Uint8Array(6);
28935
- const tokenTickerEncoder = new TextEncoder();
28936
- tokenTickerBytes.set(tokenTickerEncoder.encode(createInput.tokenTicker));
28937
- tokenTickerHashObj.update(tokenTickerBytes);
28938
- allHashes.push(tokenTickerHashObj.digest());
28939
- const decimalsHashObj = import_sha212.sha256.create();
28940
- const decimalsBytes = new Uint8Array(4);
28941
- new DataView(decimalsBytes.buffer).setUint32(
28942
- 0,
28943
- createInput.decimals,
28944
- false
28945
- );
28946
- decimalsHashObj.update(decimalsBytes);
28947
- allHashes.push(decimalsHashObj.digest());
28948
- const maxSupplyHashObj = import_sha212.sha256.create();
28949
- if (!createInput.maxSupply) {
28950
- throw new ValidationError("max supply cannot be nil", {
28951
- field: "tokenInputs.createInput.maxSupply"
28952
- });
28953
- }
28954
- if (createInput.maxSupply.length !== 16) {
28955
- throw new ValidationError("max supply must be exactly 16 bytes", {
28956
- field: "tokenInputs.createInput.maxSupply",
28957
- value: createInput.maxSupply,
28958
- expectedLength: 16,
28959
- actualLength: createInput.maxSupply.length
28960
- });
28961
- }
28962
- maxSupplyHashObj.update(createInput.maxSupply);
28963
- allHashes.push(maxSupplyHashObj.digest());
28964
- const isFreezableHashObj = import_sha212.sha256.create();
28965
- const isFreezableByte = new Uint8Array([createInput.isFreezable ? 1 : 0]);
28966
- isFreezableHashObj.update(isFreezableByte);
28967
- allHashes.push(isFreezableHashObj.digest());
28968
- const creationEntityHashObj = import_sha212.sha256.create();
28969
- if (!partialHash && createInput.creationEntityPublicKey) {
28970
- creationEntityHashObj.update(createInput.creationEntityPublicKey);
28971
- }
28972
- allHashes.push(creationEntityHashObj.digest());
28973
- }
28974
- if (!tokenTransaction.tokenOutputs) {
28975
- throw new ValidationError("token outputs cannot be null", {
28976
- field: "tokenOutputs"
28977
- });
28978
- }
28979
- if (tokenTransaction.tokenOutputs.length === 0 && tokenTransaction.tokenInputs?.$case !== "createInput") {
28980
- throw new ValidationError("token outputs cannot be empty", {
28981
- field: "tokenOutputs"
28982
- });
28983
- }
28984
- for (const [i, output] of tokenTransaction.tokenOutputs.entries()) {
28985
- if (!output) {
28986
- throw new ValidationError(`output cannot be null at index ${i}`, {
28987
- field: `tokenOutputs[${i}]`,
28988
- index: i
28989
- });
28990
- }
28991
- const hashObj2 = import_sha212.sha256.create();
28992
- if (output.id && !partialHash) {
28993
- if (output.id.length === 0) {
28994
- throw new ValidationError(`output ID at index ${i} cannot be empty`, {
28995
- field: `tokenOutputs[${i}].id`,
28996
- index: i
28997
- });
28998
- }
28999
- hashObj2.update(new TextEncoder().encode(output.id));
29000
- }
29001
- if (output.ownerPublicKey) {
29002
- if (output.ownerPublicKey.length === 0) {
29003
- throw new ValidationError(
29004
- `owner public key at index ${i} cannot be empty`,
29005
- {
29006
- field: `tokenOutputs[${i}].ownerPublicKey`,
29007
- index: i
29008
- }
29009
- );
29010
- }
29011
- hashObj2.update(output.ownerPublicKey);
29012
- }
29013
- if (!partialHash) {
29014
- const revPubKey = output.revocationCommitment;
29015
- if (revPubKey) {
29016
- if (revPubKey.length === 0) {
29017
- throw new ValidationError(
29018
- `revocation commitment at index ${i} cannot be empty`,
29019
- {
29020
- field: `tokenOutputs[${i}].revocationCommitment`,
29021
- index: i
29022
- }
29023
- );
29024
- }
29025
- hashObj2.update(revPubKey);
29026
- }
29027
- const bondBytes = new Uint8Array(8);
29028
- new DataView(bondBytes.buffer).setBigUint64(
29029
- 0,
29030
- BigInt(output.withdrawBondSats),
29031
- false
29032
- );
29033
- hashObj2.update(bondBytes);
29034
- const locktimeBytes = new Uint8Array(8);
29035
- new DataView(locktimeBytes.buffer).setBigUint64(
29036
- 0,
29037
- BigInt(output.withdrawRelativeBlockLocktime),
29038
- false
29039
- );
29040
- hashObj2.update(locktimeBytes);
29041
- }
29042
- if (output.tokenPublicKey) {
29043
- if (output.tokenPublicKey.length === 0) {
29044
- throw new ValidationError(
29045
- `token public key at index ${i} cannot be empty`,
29046
- {
29047
- field: `tokenOutputs[${i}].tokenPublicKey`,
29048
- index: i
29049
- }
29050
- );
29051
- }
29052
- hashObj2.update(output.tokenPublicKey);
29053
- }
29054
- if (output.tokenAmount) {
29055
- if (output.tokenAmount.length === 0) {
29056
- throw new ValidationError(
29057
- `token amount at index ${i} cannot be empty`,
29058
- {
29059
- field: `tokenOutputs[${i}].tokenAmount`,
29060
- index: i
29061
- }
29062
- );
29063
- }
29064
- if (output.tokenAmount.length > 16) {
29065
- throw new ValidationError(
29066
- `token amount at index ${i} exceeds maximum length`,
29067
- {
29068
- field: `tokenOutputs[${i}].tokenAmount`,
29069
- value: output.tokenAmount,
29070
- expectedLength: 16,
29071
- actualLength: output.tokenAmount.length,
29072
- index: i
29073
- }
29074
- );
29075
- }
29076
- hashObj2.update(output.tokenAmount);
29077
- }
29078
- allHashes.push(hashObj2.digest());
29079
- }
29080
- if (!tokenTransaction.sparkOperatorIdentityPublicKeys) {
29081
- throw new ValidationError(
29082
- "spark operator identity public keys cannot be null",
29083
- {}
29084
- );
29085
- }
29086
- const sortedPubKeys = [
29087
- ...tokenTransaction.sparkOperatorIdentityPublicKeys || []
29088
- ].sort((a, b) => {
29089
- for (let i = 0; i < a.length && i < b.length; i++) {
29090
- if (a[i] !== b[i]) return a[i] - b[i];
29091
- }
29092
- return a.length - b.length;
29093
- });
29094
- for (const [i, pubKey] of sortedPubKeys.entries()) {
29095
- if (!pubKey) {
29096
- throw new ValidationError(
29097
- `operator public key at index ${i} cannot be null`,
29098
- {
29099
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
29100
- index: i
29101
- }
29102
- );
29103
- }
29104
- if (pubKey.length === 0) {
29105
- throw new ValidationError(
29106
- `operator public key at index ${i} cannot be empty`,
29107
- {
29108
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
29109
- index: i
29110
- }
29111
- );
29112
- }
29113
- const hashObj2 = import_sha212.sha256.create();
29114
- hashObj2.update(pubKey);
29115
- allHashes.push(hashObj2.digest());
29116
- }
29117
- const hashObj = import_sha212.sha256.create();
29118
- let networkBytes = new Uint8Array(4);
29119
- new DataView(networkBytes.buffer).setUint32(
29120
- 0,
29121
- tokenTransaction.network.valueOf(),
29122
- false
29123
- // false for big-endian
29124
- );
29125
- hashObj.update(networkBytes);
29126
- allHashes.push(hashObj.digest());
29127
- const finalHashObj = import_sha212.sha256.create();
29128
- const concatenatedHashes = new Uint8Array(
29129
- allHashes.reduce((sum, hash) => sum + hash.length, 0)
29130
- );
29131
- let offset = 0;
29132
- for (const hash of allHashes) {
29133
- concatenatedHashes.set(hash, offset);
29134
- offset += hash.length;
29135
- }
29136
- finalHashObj.update(concatenatedHashes);
29137
- return finalHashObj.digest();
29138
- }
29139
29600
  function hashTokenTransactionV1(tokenTransaction, partialHash = false) {
29140
29601
  if (!tokenTransaction) {
29141
29602
  throw new ValidationError("token transaction cannot be nil", {
@@ -30065,24 +30526,6 @@ function hashOperatorSpecificTokenTransactionSignablePayload(payload) {
30065
30526
  return finalHashObj.digest();
30066
30527
  }
30067
30528
 
30068
- // src/utils/token-keyshares.ts
30069
- init_buffer();
30070
- var import_secp256k112 = require("@noble/curves/secp256k1");
30071
- function recoverRevocationSecretFromKeyshares(keyshares, threshold) {
30072
- const shares = keyshares.map((keyshare) => ({
30073
- fieldModulus: BigInt("0x" + import_secp256k112.secp256k1.CURVE.n.toString(16)),
30074
- // secp256k1 curve order
30075
- threshold,
30076
- index: BigInt(keyshare.operatorIndex),
30077
- share: BigInt(
30078
- "0x" + import_buffer.Buffer.from(keyshare.keyshare.keyshare).toString("hex")
30079
- ),
30080
- proofs: []
30081
- }));
30082
- const recoveredSecret = recoverSecret(shares);
30083
- return bigIntToPrivateKey(recoveredSecret);
30084
- }
30085
-
30086
30529
  // src/utils/token-transaction-validation.ts
30087
30530
  init_buffer();
30088
30531
  function areByteArraysEqual(a, b) {
@@ -30094,250 +30537,6 @@ function areByteArraysEqual(a, b) {
30094
30537
  function hasDuplicates(array) {
30095
30538
  return new Set(array).size !== array.length;
30096
30539
  }
30097
- function validateTokenTransactionV0(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
30098
- if (finalTokenTransaction.network !== partialTokenTransaction.network) {
30099
- throw new InternalValidationError(
30100
- "Network mismatch in response token transaction",
30101
- {
30102
- value: finalTokenTransaction.network,
30103
- expected: partialTokenTransaction.network
30104
- }
30105
- );
30106
- }
30107
- if (!finalTokenTransaction.tokenInputs) {
30108
- throw new InternalValidationError(
30109
- "Token inputs missing in final transaction",
30110
- {
30111
- value: finalTokenTransaction
30112
- }
30113
- );
30114
- }
30115
- if (!partialTokenTransaction.tokenInputs) {
30116
- throw new InternalValidationError(
30117
- "Token inputs missing in partial transaction",
30118
- {
30119
- value: partialTokenTransaction
30120
- }
30121
- );
30122
- }
30123
- if (finalTokenTransaction.tokenInputs.$case !== partialTokenTransaction.tokenInputs.$case) {
30124
- throw new InternalValidationError(
30125
- `Transaction type mismatch: final transaction has ${finalTokenTransaction.tokenInputs.$case}, partial transaction has ${partialTokenTransaction.tokenInputs.$case}`,
30126
- {
30127
- value: finalTokenTransaction.tokenInputs.$case,
30128
- expected: partialTokenTransaction.tokenInputs.$case
30129
- }
30130
- );
30131
- }
30132
- if (finalTokenTransaction.sparkOperatorIdentityPublicKeys.length !== partialTokenTransaction.sparkOperatorIdentityPublicKeys.length) {
30133
- throw new InternalValidationError(
30134
- "Spark operator identity public keys count mismatch",
30135
- {
30136
- value: finalTokenTransaction.sparkOperatorIdentityPublicKeys.length,
30137
- expected: partialTokenTransaction.sparkOperatorIdentityPublicKeys.length
30138
- }
30139
- );
30140
- }
30141
- if (partialTokenTransaction.tokenInputs.$case === "mintInput" && finalTokenTransaction.tokenInputs.$case === "mintInput") {
30142
- const finalMintInput = finalTokenTransaction.tokenInputs.mintInput;
30143
- const partialMintInput = partialTokenTransaction.tokenInputs.mintInput;
30144
- if (!areByteArraysEqual(
30145
- finalMintInput.issuerPublicKey,
30146
- partialMintInput.issuerPublicKey
30147
- )) {
30148
- throw new InternalValidationError(
30149
- "Issuer public key mismatch in mint input",
30150
- {
30151
- value: finalMintInput.issuerPublicKey.toString(),
30152
- expected: partialMintInput.issuerPublicKey.toString()
30153
- }
30154
- );
30155
- }
30156
- } else if (partialTokenTransaction.tokenInputs.$case === "transferInput" && finalTokenTransaction.tokenInputs.$case === "transferInput") {
30157
- const finalTransferInput = finalTokenTransaction.tokenInputs.transferInput;
30158
- const partialTransferInput = partialTokenTransaction.tokenInputs.transferInput;
30159
- if (finalTransferInput.outputsToSpend.length !== partialTransferInput.outputsToSpend.length) {
30160
- throw new InternalValidationError(
30161
- "Outputs to spend count mismatch in transfer input",
30162
- {
30163
- value: finalTransferInput.outputsToSpend.length,
30164
- expected: partialTransferInput.outputsToSpend.length
30165
- }
30166
- );
30167
- }
30168
- for (let i = 0; i < finalTransferInput.outputsToSpend.length; i++) {
30169
- const finalOutput = finalTransferInput.outputsToSpend[i];
30170
- const partialOutput = partialTransferInput.outputsToSpend[i];
30171
- if (!finalOutput) {
30172
- throw new InternalValidationError(
30173
- "Token output to spend missing in final transaction",
30174
- {
30175
- outputIndex: i,
30176
- value: finalOutput
30177
- }
30178
- );
30179
- }
30180
- if (!partialOutput) {
30181
- throw new InternalValidationError(
30182
- "Token output to spend missing in partial transaction",
30183
- {
30184
- outputIndex: i,
30185
- value: partialOutput
30186
- }
30187
- );
30188
- }
30189
- if (!areByteArraysEqual(
30190
- finalOutput.prevTokenTransactionHash,
30191
- partialOutput.prevTokenTransactionHash
30192
- )) {
30193
- throw new InternalValidationError(
30194
- "Previous token transaction hash mismatch in transfer input",
30195
- {
30196
- outputIndex: i,
30197
- value: finalOutput.prevTokenTransactionHash.toString(),
30198
- expected: partialOutput.prevTokenTransactionHash.toString()
30199
- }
30200
- );
30201
- }
30202
- if (finalOutput.prevTokenTransactionVout !== partialOutput.prevTokenTransactionVout) {
30203
- throw new InternalValidationError(
30204
- "Previous token transaction vout mismatch in transfer input",
30205
- {
30206
- outputIndex: i,
30207
- value: finalOutput.prevTokenTransactionVout,
30208
- expected: partialOutput.prevTokenTransactionVout
30209
- }
30210
- );
30211
- }
30212
- }
30213
- }
30214
- if (finalTokenTransaction.tokenOutputs.length !== partialTokenTransaction.tokenOutputs.length) {
30215
- throw new InternalValidationError("Token outputs count mismatch", {
30216
- value: finalTokenTransaction.tokenOutputs.length,
30217
- expected: partialTokenTransaction.tokenOutputs.length
30218
- });
30219
- }
30220
- for (let i = 0; i < finalTokenTransaction.tokenOutputs.length; i++) {
30221
- const finalOutput = finalTokenTransaction.tokenOutputs[i];
30222
- const partialOutput = partialTokenTransaction.tokenOutputs[i];
30223
- if (!finalOutput) {
30224
- throw new InternalValidationError(
30225
- "Token output missing in final transaction",
30226
- {
30227
- outputIndex: i,
30228
- value: finalOutput
30229
- }
30230
- );
30231
- }
30232
- if (!partialOutput) {
30233
- throw new InternalValidationError(
30234
- "Token output missing in partial transaction",
30235
- {
30236
- outputIndex: i,
30237
- value: partialOutput
30238
- }
30239
- );
30240
- }
30241
- if (!areByteArraysEqual(
30242
- finalOutput.ownerPublicKey,
30243
- partialOutput.ownerPublicKey
30244
- )) {
30245
- throw new InternalValidationError(
30246
- "Owner public key mismatch in token output",
30247
- {
30248
- outputIndex: i,
30249
- value: finalOutput.ownerPublicKey.toString(),
30250
- expected: partialOutput.ownerPublicKey.toString()
30251
- }
30252
- );
30253
- }
30254
- if (finalOutput.tokenPublicKey !== void 0 && partialOutput.tokenPublicKey !== void 0 && !areByteArraysEqual(
30255
- finalOutput.tokenPublicKey,
30256
- partialOutput.tokenPublicKey
30257
- )) {
30258
- throw new InternalValidationError(
30259
- "Token public key mismatch in token output",
30260
- {
30261
- outputIndex: i,
30262
- value: finalOutput.tokenPublicKey?.toString(),
30263
- expected: partialOutput.tokenPublicKey?.toString()
30264
- }
30265
- );
30266
- }
30267
- if (!areByteArraysEqual(finalOutput.tokenAmount, partialOutput.tokenAmount)) {
30268
- throw new InternalValidationError(
30269
- "Token amount mismatch in token output",
30270
- {
30271
- outputIndex: i,
30272
- value: finalOutput.tokenAmount.toString(),
30273
- expected: partialOutput.tokenAmount.toString()
30274
- }
30275
- );
30276
- }
30277
- if (finalOutput.withdrawBondSats !== void 0) {
30278
- if (finalOutput.withdrawBondSats !== expectedWithdrawBondSats) {
30279
- throw new InternalValidationError(
30280
- "Withdraw bond sats mismatch in token output",
30281
- {
30282
- outputIndex: i,
30283
- value: finalOutput.withdrawBondSats,
30284
- expected: expectedWithdrawBondSats
30285
- }
30286
- );
30287
- }
30288
- }
30289
- if (finalOutput.withdrawRelativeBlockLocktime !== void 0) {
30290
- if (finalOutput.withdrawRelativeBlockLocktime !== expectedWithdrawRelativeBlockLocktime) {
30291
- throw new InternalValidationError(
30292
- "Withdraw relative block locktime mismatch in token output",
30293
- {
30294
- outputIndex: i,
30295
- value: finalOutput.withdrawRelativeBlockLocktime,
30296
- expected: expectedWithdrawRelativeBlockLocktime
30297
- }
30298
- );
30299
- }
30300
- }
30301
- if (keyshareInfo.threshold !== expectedThreshold) {
30302
- throw new InternalValidationError(
30303
- "Threshold mismatch: expected " + expectedThreshold + " but got " + keyshareInfo.threshold,
30304
- {
30305
- field: "threshold",
30306
- value: keyshareInfo.threshold,
30307
- expected: expectedThreshold
30308
- }
30309
- );
30310
- }
30311
- }
30312
- if (keyshareInfo.ownerIdentifiers.length !== Object.keys(signingOperators).length) {
30313
- throw new InternalValidationError(
30314
- `Keyshare operator count (${keyshareInfo.ownerIdentifiers.length}) does not match signing operator count (${Object.keys(signingOperators).length})`,
30315
- {
30316
- keyshareInfo: keyshareInfo.ownerIdentifiers.length,
30317
- signingOperators: Object.keys(signingOperators).length
30318
- }
30319
- );
30320
- }
30321
- if (hasDuplicates(keyshareInfo.ownerIdentifiers)) {
30322
- throw new InternalValidationError(
30323
- "Duplicate ownerIdentifiers found in keyshareInfo",
30324
- {
30325
- keyshareInfo: keyshareInfo.ownerIdentifiers
30326
- }
30327
- );
30328
- }
30329
- for (const identifier of keyshareInfo.ownerIdentifiers) {
30330
- if (!signingOperators[identifier]) {
30331
- throw new InternalValidationError(
30332
- `Keyshare operator ${identifier} not found in signing operator list`,
30333
- {
30334
- keyshareInfo: identifier,
30335
- signingOperators: Object.keys(signingOperators)
30336
- }
30337
- );
30338
- }
30339
- }
30340
- }
30341
30540
  function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
30342
30541
  if (finalTokenTransaction.network !== partialTokenTransaction.network) {
30343
30542
  throw new InternalValidationError(
@@ -30690,16 +30889,6 @@ var TokenTransactionService = class {
30690
30889
  tokenIdentifier,
30691
30890
  this.config.getNetworkType()
30692
30891
  ).tokenIdentifier;
30693
- let tokenPublicKey;
30694
- if (this.config.getTokenTransactionVersion() === "V0") {
30695
- const tokenClient = await this.connectionManager.createSparkTokenClient(
30696
- this.config.getCoordinatorAddress()
30697
- );
30698
- const tokenMetadata = await tokenClient.query_token_metadata({
30699
- tokenIdentifiers: [rawTokenIdentifier]
30700
- });
30701
- tokenPublicKey = tokenMetadata.tokenMetadata[0].issuerPublicKey;
30702
- }
30703
30892
  let sparkInvoices = [];
30704
30893
  const tokenOutputData = receiverOutputs.map((transfer) => {
30705
30894
  const receiverAddress = decodeSparkAddress(
@@ -30709,7 +30898,7 @@ var TokenTransactionService = class {
30709
30898
  if (receiverAddress.sparkInvoiceFields) {
30710
30899
  sparkInvoices.push(transfer.receiverSparkAddress);
30711
30900
  }
30712
- if (this.config.getTokenTransactionVersion() !== "V0" && receiverAddress.sparkInvoiceFields) {
30901
+ if (receiverAddress.sparkInvoiceFields) {
30713
30902
  return {
30714
30903
  receiverPublicKey: (0, import_utils20.hexToBytes)(receiverAddress.identityPublicKey),
30715
30904
  rawTokenIdentifier,
@@ -30720,24 +30909,14 @@ var TokenTransactionService = class {
30720
30909
  return {
30721
30910
  receiverPublicKey: (0, import_utils20.hexToBytes)(receiverAddress.identityPublicKey),
30722
30911
  rawTokenIdentifier,
30723
- tokenPublicKey,
30724
- // Remove for full v0 deprecation
30725
30912
  tokenAmount: transfer.tokenAmount
30726
30913
  };
30727
30914
  });
30728
- let tokenTransaction;
30729
- if (this.config.getTokenTransactionVersion() === "V0") {
30730
- tokenTransaction = await this.constructTransferTokenTransactionV0(
30731
- outputsToUse,
30732
- tokenOutputData
30733
- );
30734
- } else {
30735
- tokenTransaction = await this.constructTransferTokenTransaction(
30736
- outputsToUse,
30737
- tokenOutputData,
30738
- sparkInvoices
30739
- );
30740
- }
30915
+ const tokenTransaction = await this.constructTransferTokenTransaction(
30916
+ outputsToUse,
30917
+ tokenOutputData,
30918
+ sparkInvoices
30919
+ );
30741
30920
  const txId = await this.broadcastTokenTransaction(
30742
30921
  tokenTransaction,
30743
30922
  outputsToUse.map((output) => output.output.ownerPublicKey),
@@ -30745,44 +30924,6 @@ var TokenTransactionService = class {
30745
30924
  );
30746
30925
  return txId;
30747
30926
  }
30748
- async constructTransferTokenTransactionV0(selectedOutputs, tokenOutputData) {
30749
- selectedOutputs.sort(
30750
- (a, b) => a.previousTransactionVout - b.previousTransactionVout
30751
- );
30752
- const availableTokenAmount = sumAvailableTokens(selectedOutputs);
30753
- const totalRequestedAmount = tokenOutputData.reduce(
30754
- (sum, output) => sum + output.tokenAmount,
30755
- 0n
30756
- );
30757
- const tokenOutputs = tokenOutputData.map((output) => ({
30758
- ownerPublicKey: output.receiverPublicKey,
30759
- tokenPublicKey: output.tokenPublicKey,
30760
- tokenAmount: (0, import_utils19.numberToBytesBE)(output.tokenAmount, 16)
30761
- }));
30762
- if (availableTokenAmount > totalRequestedAmount) {
30763
- const changeAmount = availableTokenAmount - totalRequestedAmount;
30764
- const firstTokenPublicKey = tokenOutputData[0].tokenPublicKey;
30765
- tokenOutputs.push({
30766
- ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
30767
- tokenPublicKey: firstTokenPublicKey,
30768
- tokenAmount: (0, import_utils19.numberToBytesBE)(changeAmount, 16)
30769
- });
30770
- }
30771
- return {
30772
- network: this.config.getNetworkProto(),
30773
- tokenInputs: {
30774
- $case: "transferInput",
30775
- transferInput: {
30776
- outputsToSpend: selectedOutputs.map((output) => ({
30777
- prevTokenTransactionHash: output.previousTransactionHash,
30778
- prevTokenTransactionVout: output.previousTransactionVout
30779
- }))
30780
- }
30781
- },
30782
- tokenOutputs,
30783
- sparkOperatorIdentityPublicKeys: this.collectOperatorIdentityPublicKeys()
30784
- };
30785
- }
30786
30927
  async constructTransferTokenTransaction(selectedOutputs, tokenOutputData, sparkInvoices) {
30787
30928
  selectedOutputs.sort(
30788
30929
  (a, b) => a.previousTransactionVout - b.previousTransactionVout
@@ -30838,113 +30979,6 @@ var TokenTransactionService = class {
30838
30979
  }
30839
30980
  async broadcastTokenTransaction(tokenTransaction, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30840
30981
  const signingOperators = this.config.getSigningOperators();
30841
- if (!isTokenTransaction(tokenTransaction)) {
30842
- return this.broadcastTokenTransactionV0(
30843
- tokenTransaction,
30844
- signingOperators,
30845
- outputsToSpendSigningPublicKeys,
30846
- outputsToSpendCommitments
30847
- );
30848
- } else {
30849
- return this.broadcastTokenTransactionV1(
30850
- tokenTransaction,
30851
- signingOperators,
30852
- outputsToSpendSigningPublicKeys,
30853
- outputsToSpendCommitments
30854
- );
30855
- }
30856
- }
30857
- async broadcastTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30858
- const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransactionV0(
30859
- tokenTransaction,
30860
- signingOperators,
30861
- outputsToSpendSigningPublicKeys,
30862
- outputsToSpendCommitments
30863
- );
30864
- const { successfulSignatures } = await this.signTokenTransactionV0(
30865
- finalTokenTransaction,
30866
- finalTokenTransactionHash,
30867
- signingOperators
30868
- );
30869
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
30870
- const outputsToSpend = finalTokenTransaction.tokenInputs.transferInput.outputsToSpend;
30871
- const errors = [];
30872
- const revocationSecrets = [];
30873
- for (let outputIndex = 0; outputIndex < outputsToSpend.length; outputIndex++) {
30874
- const outputKeyshares = successfulSignatures.map(({ identifier, response }) => ({
30875
- operatorIndex: parseInt(identifier, 16),
30876
- keyshare: response.revocationKeyshares[outputIndex]
30877
- }));
30878
- if (outputKeyshares.length < threshold) {
30879
- errors.push(
30880
- new ValidationError("Insufficient keyshares", {
30881
- field: "outputKeyshares",
30882
- value: outputKeyshares.length,
30883
- expected: threshold,
30884
- index: outputIndex
30885
- })
30886
- );
30887
- }
30888
- const seenIndices = /* @__PURE__ */ new Set();
30889
- for (const { operatorIndex } of outputKeyshares) {
30890
- if (seenIndices.has(operatorIndex)) {
30891
- errors.push(
30892
- new ValidationError("Duplicate operator index", {
30893
- field: "outputKeyshares",
30894
- value: operatorIndex,
30895
- expected: "Unique operator index",
30896
- index: outputIndex
30897
- })
30898
- );
30899
- }
30900
- seenIndices.add(operatorIndex);
30901
- }
30902
- const revocationSecret = recoverRevocationSecretFromKeyshares(
30903
- outputKeyshares,
30904
- threshold
30905
- );
30906
- const derivedRevocationCommitment = import_secp256k113.secp256k1.getPublicKey(
30907
- revocationSecret,
30908
- true
30909
- );
30910
- if (!outputsToSpendCommitments || !outputsToSpendCommitments[outputIndex] || !derivedRevocationCommitment.every(
30911
- (byte, i) => byte === outputsToSpendCommitments[outputIndex][i]
30912
- )) {
30913
- errors.push(
30914
- new InternalValidationError(
30915
- "Revocation commitment verification failed",
30916
- {
30917
- field: "revocationCommitment",
30918
- value: derivedRevocationCommitment,
30919
- expected: (0, import_utils19.bytesToHex)(outputsToSpendCommitments[outputIndex]),
30920
- outputIndex
30921
- }
30922
- )
30923
- );
30924
- }
30925
- revocationSecrets.push({
30926
- inputIndex: outputIndex,
30927
- revocationSecret
30928
- });
30929
- }
30930
- if (errors.length > 0) {
30931
- throw new ValidationError(
30932
- "Multiple validation errors occurred across outputs",
30933
- {
30934
- field: "outputValidation",
30935
- value: errors
30936
- }
30937
- );
30938
- }
30939
- await this.finalizeTokenTransaction(
30940
- finalTokenTransaction,
30941
- revocationSecrets,
30942
- threshold
30943
- );
30944
- }
30945
- return (0, import_utils19.bytesToHex)(finalTokenTransactionHash);
30946
- }
30947
- async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30948
30982
  const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
30949
30983
  tokenTransaction,
30950
30984
  signingOperators,
@@ -30958,101 +30992,6 @@ var TokenTransactionService = class {
30958
30992
  );
30959
30993
  return (0, import_utils19.bytesToHex)(finalTokenTransactionHash);
30960
30994
  }
30961
- async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30962
- const sparkClient = await this.connectionManager.createSparkClient(
30963
- this.config.getCoordinatorAddress()
30964
- );
30965
- const partialTokenTransactionHash = hashTokenTransactionV0(
30966
- tokenTransaction,
30967
- true
30968
- );
30969
- const ownerSignaturesWithIndex = [];
30970
- if (tokenTransaction.tokenInputs.$case === "mintInput") {
30971
- const issuerPublicKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
30972
- if (!issuerPublicKey) {
30973
- throw new ValidationError("Invalid mint input", {
30974
- field: "issuerPublicKey",
30975
- value: null,
30976
- expected: "Non-null issuer public key"
30977
- });
30978
- }
30979
- const ownerSignature = await this.signMessageWithKey(
30980
- partialTokenTransactionHash,
30981
- issuerPublicKey
30982
- );
30983
- ownerSignaturesWithIndex.push({
30984
- signature: ownerSignature,
30985
- inputIndex: 0
30986
- });
30987
- } else if (tokenTransaction.tokenInputs.$case === "transferInput") {
30988
- if (!outputsToSpendSigningPublicKeys || !outputsToSpendCommitments) {
30989
- throw new ValidationError("Invalid transfer input", {
30990
- field: "outputsToSpend",
30991
- value: {
30992
- signingPublicKeys: outputsToSpendSigningPublicKeys,
30993
- revocationPublicKeys: outputsToSpendCommitments
30994
- },
30995
- expected: "Non-null signing and revocation public keys"
30996
- });
30997
- }
30998
- for (const [i, key] of outputsToSpendSigningPublicKeys.entries()) {
30999
- if (!key) {
31000
- throw new ValidationError("Invalid signing key", {
31001
- field: "outputsToSpendSigningPublicKeys",
31002
- value: i,
31003
- expected: "Non-null signing key"
31004
- });
31005
- }
31006
- const ownerSignature = await this.signMessageWithKey(
31007
- partialTokenTransactionHash,
31008
- key
31009
- );
31010
- ownerSignaturesWithIndex.push({
31011
- signature: ownerSignature,
31012
- inputIndex: i
31013
- });
31014
- }
31015
- }
31016
- const startResponse = await sparkClient.start_token_transaction(
31017
- {
31018
- identityPublicKey: await this.config.signer.getIdentityPublicKey(),
31019
- partialTokenTransaction: tokenTransaction,
31020
- tokenTransactionSignatures: {
31021
- ownerSignatures: ownerSignaturesWithIndex
31022
- }
31023
- },
31024
- {
31025
- retry: true,
31026
- retryableStatuses: ["UNKNOWN", "UNAVAILABLE", "CANCELLED", "INTERNAL"],
31027
- retryMaxAttempts: 3
31028
- }
31029
- );
31030
- if (!startResponse.finalTokenTransaction) {
31031
- throw new Error("Final token transaction missing in start response");
31032
- }
31033
- if (!startResponse.keyshareInfo) {
31034
- throw new Error("Keyshare info missing in start response");
31035
- }
31036
- validateTokenTransactionV0(
31037
- startResponse.finalTokenTransaction,
31038
- tokenTransaction,
31039
- signingOperators,
31040
- startResponse.keyshareInfo,
31041
- this.config.getExpectedWithdrawBondSats(),
31042
- this.config.getExpectedWithdrawRelativeBlockLocktime(),
31043
- this.config.getThreshold()
31044
- );
31045
- const finalTokenTransaction = startResponse.finalTokenTransaction;
31046
- const finalTokenTransactionHash = hashTokenTransactionV0(
31047
- finalTokenTransaction,
31048
- false
31049
- );
31050
- return {
31051
- finalTokenTransaction,
31052
- finalTokenTransactionHash,
31053
- threshold: startResponse.keyshareInfo.threshold
31054
- };
31055
- }
31056
30995
  async startTokenTransaction(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
31057
30996
  const sparkClient = await this.connectionManager.createSparkTokenClient(
31058
30997
  this.config.getCoordinatorAddress()
@@ -31172,103 +31111,6 @@ var TokenTransactionService = class {
31172
31111
  threshold: startResponse.keyshareInfo.threshold
31173
31112
  };
31174
31113
  }
31175
- async signTokenTransactionV0(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
31176
- const soSignatures = await Promise.allSettled(
31177
- Object.entries(signingOperators).map(
31178
- async ([identifier, operator], index) => {
31179
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
31180
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
31181
- const payload = {
31182
- finalTokenTransactionHash,
31183
- operatorIdentityPublicKey: (0, import_utils20.hexToBytes)(operator.identityPublicKey)
31184
- };
31185
- const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
31186
- let operatorSpecificSignatures = [];
31187
- if (finalTokenTransaction.tokenInputs.$case === "mintInput") {
31188
- const issuerPublicKey = finalTokenTransaction.tokenInputs.mintInput.issuerPublicKey;
31189
- if (!issuerPublicKey) {
31190
- throw new ValidationError("Invalid mint input", {
31191
- field: "issuerPublicKey",
31192
- value: null,
31193
- expected: "Non-null issuer public key"
31194
- });
31195
- }
31196
- const ownerSignature = await this.signMessageWithKey(
31197
- payloadHash,
31198
- issuerPublicKey
31199
- );
31200
- operatorSpecificSignatures.push({
31201
- ownerSignature: {
31202
- signature: ownerSignature,
31203
- inputIndex: 0
31204
- },
31205
- payload
31206
- });
31207
- }
31208
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
31209
- const transferInput = finalTokenTransaction.tokenInputs.transferInput;
31210
- for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
31211
- let ownerSignature;
31212
- if (this.config.getTokenSignatures() === "SCHNORR") {
31213
- ownerSignature = await this.config.signer.signSchnorrWithIdentityKey(
31214
- payloadHash
31215
- );
31216
- } else {
31217
- ownerSignature = await this.config.signer.signMessageWithIdentityKey(
31218
- payloadHash
31219
- );
31220
- }
31221
- operatorSpecificSignatures.push({
31222
- ownerSignature: {
31223
- signature: ownerSignature,
31224
- inputIndex: i
31225
- },
31226
- payload
31227
- });
31228
- }
31229
- }
31230
- try {
31231
- const response = await internalSparkClient.sign_token_transaction(
31232
- {
31233
- finalTokenTransaction,
31234
- operatorSpecificSignatures,
31235
- identityPublicKey
31236
- },
31237
- {
31238
- retry: true,
31239
- retryableStatuses: [
31240
- "UNKNOWN",
31241
- "UNAVAILABLE",
31242
- "CANCELLED",
31243
- "INTERNAL"
31244
- ],
31245
- retryMaxAttempts: 3
31246
- }
31247
- );
31248
- return {
31249
- index,
31250
- identifier,
31251
- response
31252
- };
31253
- } catch (error) {
31254
- throw new NetworkError(
31255
- "Failed to sign token transaction",
31256
- {
31257
- operation: "sign_token_transaction",
31258
- errorCount: 1,
31259
- errors: error instanceof Error ? error.message : String(error)
31260
- },
31261
- error
31262
- );
31263
- }
31264
- }
31265
- )
31266
- );
31267
- const successfulSignatures = collectResponses(soSignatures);
31268
- return {
31269
- successfulSignatures
31270
- };
31271
- }
31272
31114
  async signTokenTransaction(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
31273
31115
  const coordinatorClient = await this.connectionManager.createSparkTokenClient(
31274
31116
  this.config.getCoordinatorAddress()
@@ -31340,54 +31182,6 @@ var TokenTransactionService = class {
31340
31182
  );
31341
31183
  }
31342
31184
  }
31343
- if (this.config.getTokenTransactionVersion() === "V0") {
31344
- return this.fetchOwnedTokenOutputsV0(params);
31345
- } else {
31346
- return this.fetchOwnedTokenOutputsV1(params);
31347
- }
31348
- }
31349
- async queryTokenTransactions(params) {
31350
- if (this.config.getTokenTransactionVersion() === "V0") {
31351
- return this.queryTokenTransactionsV0(params);
31352
- } else {
31353
- return this.queryTokenTransactionsV1(params);
31354
- }
31355
- }
31356
- async fetchOwnedTokenOutputsV0(params) {
31357
- const {
31358
- ownerPublicKeys,
31359
- issuerPublicKeys: tokenPublicKeys = [],
31360
- tokenIdentifiers = []
31361
- } = params;
31362
- const sparkClient = await this.connectionManager.createSparkClient(
31363
- this.config.getCoordinatorAddress()
31364
- );
31365
- try {
31366
- const result = await sparkClient.query_token_outputs({
31367
- ownerPublicKeys,
31368
- tokenPublicKeys,
31369
- tokenIdentifiers,
31370
- network: this.config.getNetworkProto()
31371
- });
31372
- return result.outputsWithPreviousTransactionData;
31373
- } catch (error) {
31374
- throw new NetworkError(
31375
- "Failed to fetch owned token outputs",
31376
- {
31377
- operation: "spark.query_token_outputs",
31378
- errorCount: 1,
31379
- errors: error instanceof Error ? error.message : String(error)
31380
- },
31381
- error
31382
- );
31383
- }
31384
- }
31385
- async fetchOwnedTokenOutputsV1(params) {
31386
- const {
31387
- ownerPublicKeys,
31388
- issuerPublicKeys = [],
31389
- tokenIdentifiers = []
31390
- } = params;
31391
31185
  const tokenClient = await this.connectionManager.createSparkTokenClient(
31392
31186
  this.config.getCoordinatorAddress()
31393
31187
  );
@@ -31428,75 +31222,7 @@ var TokenTransactionService = class {
31428
31222
  );
31429
31223
  }
31430
31224
  }
31431
- async queryTokenTransactionsV0(params) {
31432
- const {
31433
- ownerPublicKeys,
31434
- issuerPublicKeys,
31435
- tokenTransactionHashes,
31436
- tokenIdentifiers,
31437
- outputIds,
31438
- pageSize,
31439
- offset
31440
- } = params;
31441
- const sparkClient = await this.connectionManager.createSparkClient(
31442
- this.config.getCoordinatorAddress()
31443
- );
31444
- let queryParams = {
31445
- tokenPublicKeys: issuerPublicKeys?.map(import_utils20.hexToBytes),
31446
- ownerPublicKeys: ownerPublicKeys?.map(import_utils20.hexToBytes),
31447
- tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
31448
- const { tokenIdentifier } = decodeBech32mTokenIdentifier(
31449
- identifier,
31450
- this.config.getNetworkType()
31451
- );
31452
- return tokenIdentifier;
31453
- }),
31454
- tokenTransactionHashes: tokenTransactionHashes?.map(import_utils20.hexToBytes),
31455
- outputIds: outputIds || [],
31456
- limit: pageSize,
31457
- offset
31458
- };
31459
- try {
31460
- const response = await sparkClient.query_token_transactions(queryParams);
31461
- return {
31462
- tokenTransactionsWithStatus: response.tokenTransactionsWithStatus.map(
31463
- (tx) => {
31464
- const v1TokenTransaction = {
31465
- version: 1,
31466
- network: tx.tokenTransaction.network,
31467
- tokenInputs: tx.tokenTransaction.tokenInputs,
31468
- tokenOutputs: tx.tokenTransaction.tokenOutputs,
31469
- sparkOperatorIdentityPublicKeys: tx.tokenTransaction.sparkOperatorIdentityPublicKeys,
31470
- expiryTime: void 0,
31471
- // V0 doesn't have expiry time
31472
- clientCreatedTimestamp: tx.tokenTransaction?.tokenInputs?.$case === "mintInput" ? new Date(
31473
- tx.tokenTransaction.tokenInputs.mintInput.issuerProvidedTimestamp * 1e3
31474
- ) : /* @__PURE__ */ new Date(),
31475
- invoiceAttachments: []
31476
- };
31477
- return {
31478
- tokenTransaction: v1TokenTransaction,
31479
- status: tx.status,
31480
- confirmationMetadata: tx.confirmationMetadata,
31481
- tokenTransactionHash: tx.tokenTransactionHash
31482
- };
31483
- }
31484
- ),
31485
- offset: response.offset
31486
- };
31487
- } catch (error) {
31488
- throw new NetworkError(
31489
- "Failed to query token transactions",
31490
- {
31491
- operation: "spark.query_token_transactions",
31492
- errorCount: 1,
31493
- errors: error instanceof Error ? error.message : String(error)
31494
- },
31495
- error
31496
- );
31497
- }
31498
- }
31499
- async queryTokenTransactionsV1(params) {
31225
+ async queryTokenTransactions(params) {
31500
31226
  const {
31501
31227
  ownerPublicKeys,
31502
31228
  issuerPublicKeys,
@@ -31609,50 +31335,6 @@ var TokenTransactionService = class {
31609
31335
  });
31610
31336
  }
31611
31337
  }
31612
- async finalizeTokenTransaction(finalTokenTransaction, revocationSecrets, threshold) {
31613
- const signingOperators = this.config.getSigningOperators();
31614
- const soResponses = await Promise.allSettled(
31615
- Object.entries(signingOperators).map(async ([identifier, operator]) => {
31616
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
31617
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
31618
- try {
31619
- const response = await internalSparkClient.finalize_token_transaction(
31620
- {
31621
- finalTokenTransaction,
31622
- revocationSecrets,
31623
- identityPublicKey
31624
- },
31625
- {
31626
- retry: true,
31627
- retryableStatuses: [
31628
- "UNKNOWN",
31629
- "UNAVAILABLE",
31630
- "CANCELLED",
31631
- "INTERNAL"
31632
- ],
31633
- retryMaxAttempts: 3
31634
- }
31635
- );
31636
- return {
31637
- identifier,
31638
- response
31639
- };
31640
- } catch (error) {
31641
- throw new NetworkError(
31642
- "Failed to finalize token transaction",
31643
- {
31644
- operation: "finalize_token_transaction",
31645
- errorCount: 1,
31646
- errors: error instanceof Error ? error.message : String(error)
31647
- },
31648
- error
31649
- );
31650
- }
31651
- })
31652
- );
31653
- collectResponses(soResponses);
31654
- return finalTokenTransaction;
31655
- }
31656
31338
  async createSignaturesForOperators(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
31657
31339
  const inputTtxoSignaturesPerOperator = [];
31658
31340
  for (const [_, operator] of Object.entries(signingOperators)) {
@@ -31729,9 +31411,6 @@ var TokenTransactionService = class {
31729
31411
  return inputTtxoSignaturesPerOperator;
31730
31412
  }
31731
31413
  };
31732
- function isTokenTransaction(tokenTransaction) {
31733
- return "version" in tokenTransaction && "expiryTime" in tokenTransaction;
31734
- }
31735
31414
 
31736
31415
  // src/spark-wallet/spark-wallet.ts
31737
31416
  var import_sha213 = require("@noble/hashes/sha2");
@@ -31908,7 +31587,7 @@ var SigningService = class {
31908
31587
 
31909
31588
  // src/tests/utils/test-faucet.ts
31910
31589
  init_buffer();
31911
- var import_secp256k114 = require("@noble/curves/secp256k1");
31590
+ var import_secp256k112 = require("@noble/curves/secp256k1");
31912
31591
  var import_utils22 = require("@noble/curves/utils");
31913
31592
  var btc5 = __toESM(require("@scure/btc-signer"), 1);
31914
31593
  var import_btc_signer5 = require("@scure/btc-signer");
@@ -31929,7 +31608,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31929
31608
  this.username = username;
31930
31609
  this.password = password;
31931
31610
  this.miningAddress = getP2TRAddressFromPublicKey(
31932
- import_secp256k114.secp256k1.getPublicKey(STATIC_MINING_KEY),
31611
+ import_secp256k112.secp256k1.getPublicKey(STATIC_MINING_KEY),
31933
31612
  4 /* LOCAL */
31934
31613
  );
31935
31614
  }
@@ -31968,7 +31647,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31968
31647
  });
31969
31648
  }
31970
31649
  async refill() {
31971
- const minerPubKey = import_secp256k114.secp256k1.getPublicKey(STATIC_MINING_KEY);
31650
+ const minerPubKey = import_secp256k112.secp256k1.getPublicKey(STATIC_MINING_KEY);
31972
31651
  const address2 = getP2TRAddressFromPublicKey(minerPubKey, 4 /* LOCAL */);
31973
31652
  const scanResult = await this.call("scantxoutset", [
31974
31653
  "start",
@@ -32017,7 +31696,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32017
31696
  txid: selectedUtxo.txid,
32018
31697
  index: selectedUtxo.vout
32019
31698
  });
32020
- const faucetPubKey = import_secp256k114.secp256k1.getPublicKey(STATIC_FAUCET_KEY);
31699
+ const faucetPubKey = import_secp256k112.secp256k1.getPublicKey(STATIC_FAUCET_KEY);
32021
31700
  const script = getP2TRScriptFromPublicKey(faucetPubKey, 4 /* LOCAL */);
32022
31701
  for (let i = 0; i < numCoinsToCreate; i++) {
32023
31702
  splitTx.addOutput({
@@ -32078,7 +31757,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32078
31757
  await this.broadcastTx((0, import_utils22.bytesToHex)(signedTx.extract()));
32079
31758
  }
32080
31759
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
32081
- const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
31760
+ const pubKey = import_secp256k112.secp256k1.getPublicKey(key);
32082
31761
  const internalKey = pubKey.slice(1);
32083
31762
  const script = getP2TRScriptFromPublicKey(pubKey, 4 /* LOCAL */);
32084
31763
  unsignedTx.updateInput(0, {
@@ -32098,7 +31777,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32098
31777
  const tweakedKey = (0, import_utils23.taprootTweakPrivKey)(key, merkleRoot);
32099
31778
  if (!tweakedKey)
32100
31779
  throw new Error("Invalid private key for taproot tweaking");
32101
- const signature = import_secp256k114.schnorr.sign(sighash, tweakedKey);
31780
+ const signature = import_secp256k112.schnorr.sign(sighash, tweakedKey);
32102
31781
  unsignedTx.updateInput(0, {
32103
31782
  tapKeySig: signature
32104
31783
  });
@@ -32161,8 +31840,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
32161
31840
  return response;
32162
31841
  }
32163
31842
  async getNewAddress() {
32164
- const key = import_secp256k114.secp256k1.utils.randomPrivateKey();
32165
- const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
31843
+ const key = import_secp256k112.secp256k1.utils.randomPrivateKey();
31844
+ const pubKey = import_secp256k112.secp256k1.getPublicKey(key);
32166
31845
  return getP2TRAddressFromPublicKey(pubKey, 4 /* LOCAL */);
32167
31846
  }
32168
31847
  async sendToAddress(address2, amount, blocksToGenerate = 1) {
@@ -32183,8 +31862,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
32183
31862
  });
32184
31863
  const changeAmount = availableAmount - amount;
32185
31864
  if (changeAmount > 0) {
32186
- const changeKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
32187
- const changePubKey = import_secp256k114.secp256k1.getPublicKey(changeKey);
31865
+ const changeKey = import_secp256k112.secp256k1.utils.randomPrivateKey();
31866
+ const changePubKey = import_secp256k112.secp256k1.getPublicKey(changeKey);
32188
31867
  const changeScript = getP2TRScriptFromPublicKey(
32189
31868
  changePubKey,
32190
31869
  4 /* LOCAL */
@@ -32197,8 +31876,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
32197
31876
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
32198
31877
  const txHex = (0, import_utils22.bytesToHex)(signedTx.extract());
32199
31878
  await this.broadcastTx(txHex);
32200
- const randomKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
32201
- const randomPubKey = import_secp256k114.secp256k1.getPublicKey(randomKey);
31879
+ const randomKey = import_secp256k112.secp256k1.utils.randomPrivateKey();
31880
+ const randomPubKey = import_secp256k112.secp256k1.getPublicKey(randomKey);
32202
31881
  const randomAddress = getP2TRAddressFromPublicKey(
32203
31882
  randomPubKey,
32204
31883
  4 /* LOCAL */
@@ -32819,47 +32498,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32819
32498
  senderPublicKey,
32820
32499
  expiryTime
32821
32500
  }) {
32822
- const MAX_SATS_AMOUNT = 21e14;
32823
- if (amount && (amount < 0 || amount > MAX_SATS_AMOUNT)) {
32824
- throw new ValidationError(
32825
- `Amount must be between 0 and ${MAX_SATS_AMOUNT} sats`,
32826
- {
32827
- field: "amount",
32828
- value: amount,
32829
- expected: `less than or equal to ${MAX_SATS_AMOUNT}`
32830
- }
32831
- );
32832
- }
32833
- const protoPayment = {
32834
- $case: "satsPayment",
32835
- satsPayment: {
32836
- amount
32837
- }
32838
- };
32839
- const invoiceFields = {
32840
- version: 1,
32841
- id: (0, import_uuidv75.uuidv7obj)().bytes,
32842
- paymentType: protoPayment,
32843
- memo,
32844
- senderPublicKey: senderPublicKey ? (0, import_utils24.hexToBytes)(senderPublicKey) : void 0,
32845
- expiryTime: expiryTime ?? void 0
32846
- };
32847
- validateSparkInvoiceFields(invoiceFields);
32848
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
32849
- const hash = HashSparkInvoice(
32850
- invoiceFields,
32851
- identityPublicKey,
32852
- this.config.getNetworkType()
32853
- );
32854
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
32855
- return encodeSparkAddressWithSignature(
32856
- {
32857
- identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
32858
- network: this.config.getNetworkType(),
32859
- sparkInvoiceFields: invoiceFields
32860
- },
32861
- signature
32862
- );
32501
+ throw new NotImplementedError("Invoice functionality is not enabled");
32863
32502
  }
32864
32503
  /**
32865
32504
  * Creates a Spark invoice for a tokens payment on Spark.
@@ -32879,52 +32518,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32879
32518
  senderPublicKey,
32880
32519
  expiryTime
32881
32520
  }) {
32882
- const MAX_UINT128 = BigInt(2 ** 128 - 1);
32883
- if (amount && (amount < 0 || amount > MAX_UINT128)) {
32884
- throw new ValidationError(`Amount must be between 0 and ${MAX_UINT128}`, {
32885
- field: "amount",
32886
- value: amount,
32887
- expected: `greater than or equal to 0 and less than or equal to ${MAX_UINT128}`
32888
- });
32889
- }
32890
- let decodedTokenIdentifier = void 0;
32891
- if (tokenIdentifier) {
32892
- decodedTokenIdentifier = decodeBech32mTokenIdentifier(
32893
- tokenIdentifier,
32894
- this.config.getNetworkType()
32895
- ).tokenIdentifier;
32896
- }
32897
- const protoPayment = {
32898
- $case: "tokensPayment",
32899
- tokensPayment: {
32900
- tokenIdentifier: decodedTokenIdentifier ?? void 0,
32901
- amount: amount ? (0, import_utils24.numberToVarBytesBE)(amount) : void 0
32902
- }
32903
- };
32904
- const invoiceFields = {
32905
- version: 1,
32906
- id: (0, import_uuidv75.uuidv7obj)().bytes,
32907
- paymentType: protoPayment,
32908
- memo: memo ?? void 0,
32909
- senderPublicKey: senderPublicKey ? (0, import_utils24.hexToBytes)(senderPublicKey) : void 0,
32910
- expiryTime: expiryTime ?? void 0
32911
- };
32912
- validateSparkInvoiceFields(invoiceFields);
32913
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
32914
- const hash = HashSparkInvoice(
32915
- invoiceFields,
32916
- identityPublicKey,
32917
- this.config.getNetworkType()
32918
- );
32919
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
32920
- return encodeSparkAddressWithSignature(
32921
- {
32922
- identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
32923
- network: this.config.getNetworkType(),
32924
- sparkInvoiceFields: invoiceFields
32925
- },
32926
- signature
32927
- );
32521
+ throw new NotImplementedError("Invoice functionality is not enabled");
32928
32522
  }
32929
32523
  /**
32930
32524
  * Initializes the wallet using either a mnemonic phrase or a raw seed.
@@ -33249,7 +32843,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33249
32843
  }
33250
32844
  const sspClient = this.getSspClient();
33251
32845
  const cpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
33252
- import_secp256k115.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
32846
+ import_secp256k113.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
33253
32847
  );
33254
32848
  if (!cpfpAdaptorPubkey) {
33255
32849
  throw new Error("Failed to generate CPFP adaptor pubkey");
@@ -33257,13 +32851,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33257
32851
  let directAdaptorPubkey;
33258
32852
  if (directAdaptorPrivateKey.length > 0) {
33259
32853
  directAdaptorPubkey = (0, import_utils24.bytesToHex)(
33260
- import_secp256k115.secp256k1.getPublicKey(directAdaptorPrivateKey)
32854
+ import_secp256k113.secp256k1.getPublicKey(directAdaptorPrivateKey)
33261
32855
  );
33262
32856
  }
33263
32857
  let directFromCpfpAdaptorPubkey;
33264
32858
  if (directFromCpfpAdaptorPrivateKey.length > 0) {
33265
32859
  directFromCpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
33266
- import_secp256k115.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
32860
+ import_secp256k113.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
33267
32861
  );
33268
32862
  }
33269
32863
  let request = null;
@@ -34878,10 +34472,30 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34878
34472
  if (!invoice2) {
34879
34473
  throw new Error("Failed to create lightning invoice");
34880
34474
  }
34475
+ const decodedInvoice = decodeInvoice(invoice2.invoice.encodedInvoice);
34476
+ if (invoice2.invoice.paymentHash !== (0, import_utils24.bytesToHex)(paymentHash) || decodedInvoice.paymentHash !== (0, import_utils24.bytesToHex)(paymentHash)) {
34477
+ throw new ValidationError("Payment hash mismatch", {
34478
+ field: "paymentHash",
34479
+ value: invoice2.invoice.paymentHash,
34480
+ expected: (0, import_utils24.bytesToHex)(paymentHash)
34481
+ });
34482
+ }
34483
+ if (decodedInvoice.amountMSats === null && amountSats2 !== 0) {
34484
+ throw new ValidationError("Amount mismatch", {
34485
+ field: "amountMSats",
34486
+ value: "null",
34487
+ expected: amountSats2 * 1e3
34488
+ });
34489
+ }
34490
+ if (decodedInvoice.amountMSats !== null && decodedInvoice.amountMSats !== BigInt(amountSats2 * 1e3)) {
34491
+ throw new ValidationError("Amount mismatch", {
34492
+ field: "amountMSats",
34493
+ value: decodedInvoice.amountMSats,
34494
+ expected: amountSats2 * 1e3
34495
+ });
34496
+ }
34881
34497
  if (includeSparkAddress) {
34882
- const sparkFallbackAddress = decodeInvoice(
34883
- invoice2.invoice.encodedInvoice
34884
- ).fallbackAddress;
34498
+ const sparkFallbackAddress = decodedInvoice.fallbackAddress;
34885
34499
  if (!sparkFallbackAddress) {
34886
34500
  throw new ValidationError(
34887
34501
  "No spark fallback address found in lightning invoice",
@@ -34903,6 +34517,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34903
34517
  }
34904
34518
  );
34905
34519
  }
34520
+ } else if (decodedInvoice.fallbackAddress !== void 0) {
34521
+ throw new ValidationError(
34522
+ "Spark fallback address found in lightning invoice but includeSparkAddress is false",
34523
+ {
34524
+ field: "sparkFallbackAddress",
34525
+ value: decodedInvoice.fallbackAddress
34526
+ }
34527
+ );
34906
34528
  }
34907
34529
  return invoice2;
34908
34530
  };
@@ -35070,91 +34692,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
35070
34692
  });
35071
34693
  }
35072
34694
  async fulfillSparkInvoice(sparkInvoices) {
35073
- if (!Array.isArray(sparkInvoices) || sparkInvoices.length === 0) {
35074
- throw new ValidationError("No Spark invoices provided", {
35075
- field: "sparkInvoices",
35076
- value: sparkInvoices,
35077
- expected: "Non-empty array"
35078
- });
35079
- }
35080
- const satsTransactionSuccess = [];
35081
- const satsTransactionErrors = [];
35082
- const tokenTransactionSuccess = [];
35083
- const tokenTransactionErrors = [];
35084
- const { satsInvoices, tokenInvoices, invalidInvoices } = await this.groupSparkInvoicesByPaymentType(sparkInvoices);
35085
- if (invalidInvoices.length > 0) {
35086
- return {
35087
- satsTransactionSuccess,
35088
- satsTransactionErrors,
35089
- tokenTransactionSuccess,
35090
- tokenTransactionErrors,
35091
- invalidInvoices
35092
- };
35093
- }
35094
- if (tokenInvoices.size > 0) {
35095
- await this.syncTokenOutputs();
35096
- const tokenTransferTasks = [];
35097
- for (const [identifierHex, decodedInvoices] of tokenInvoices.entries()) {
35098
- const tokenIdentifier = (0, import_utils24.hexToBytes)(identifierHex);
35099
- const tokenIdB32 = encodeBech32mTokenIdentifier({
35100
- tokenIdentifier,
35101
- network: this.config.getNetworkType()
35102
- });
35103
- const receiverOutputs = decodedInvoices.map((d) => ({
35104
- tokenIdentifier: tokenIdB32,
35105
- tokenAmount: d.amount,
35106
- receiverSparkAddress: d.invoice
35107
- }));
35108
- tokenTransferTasks.push(
35109
- this.tokenTransactionService.tokenTransfer({ tokenOutputs: this.tokenOutputs, receiverOutputs }).then((txid) => ({
35110
- ok: true,
35111
- tokenIdentifier: tokenIdB32,
35112
- txid
35113
- })).catch((e) => ({
35114
- ok: false,
35115
- tokenIdentifier: tokenIdB32,
35116
- error: e instanceof Error ? e : new Error(String(e))
35117
- }))
35118
- );
35119
- }
35120
- const results = await Promise.all(tokenTransferTasks);
35121
- for (const r of results) {
35122
- if (r.ok) {
35123
- tokenTransactionSuccess.push({
35124
- tokenIdentifier: r.tokenIdentifier,
35125
- txid: r.txid
35126
- });
35127
- } else {
35128
- tokenTransactionErrors.push({
35129
- tokenIdentifier: r.tokenIdentifier,
35130
- error: r.error
35131
- });
35132
- }
35133
- }
35134
- }
35135
- if (satsInvoices.length > 0) {
35136
- const transfers = await this.transferWithInvoice(satsInvoices);
35137
- for (const transfer of transfers) {
35138
- if (transfer.ok) {
35139
- satsTransactionSuccess.push({
35140
- invoice: transfer.param.sparkInvoice ?? "",
35141
- transferResponse: transfer.transfer
35142
- });
35143
- } else {
35144
- satsTransactionErrors.push({
35145
- invoice: transfer.param.sparkInvoice ?? "",
35146
- error: transfer.error
35147
- });
35148
- }
35149
- }
35150
- }
35151
- return {
35152
- satsTransactionSuccess,
35153
- satsTransactionErrors,
35154
- tokenTransactionSuccess,
35155
- tokenTransactionErrors,
35156
- invalidInvoices
35157
- };
34695
+ throw new NotImplementedError("Invoice functionality is not enabled");
35158
34696
  }
35159
34697
  async groupSparkInvoicesByPaymentType(sparkInvoices) {
35160
34698
  const satsInvoices = [];
@@ -35291,6 +34829,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
35291
34829
  });
35292
34830
  return { satsInvoices, tokenInvoices, invalidInvoices };
35293
34831
  }
34832
+ async querySparkInvoices(invoices) {
34833
+ throw new NotImplementedError("Invoice functionality is not enabled");
34834
+ }
35294
34835
  /**
35295
34836
  * Gets fee estimate for sending Lightning payments.
35296
34837
  *
@@ -36402,6 +35943,7 @@ setCrypto(cryptoImpl2);
36402
35943
  addPublicKeys,
36403
35944
  applyAdaptorToSignature,
36404
35945
  applyAdditiveTweakToPublicKey,
35946
+ assertBech32,
36405
35947
  bech32mDecode,
36406
35948
  bigIntToPrivateKey,
36407
35949
  checkIfSelectedOutputsAreAvailable,
@@ -36465,6 +36007,7 @@ setCrypto(cryptoImpl2);
36465
36007
  getTxIdNoReverse,
36466
36008
  initializeTracerEnv,
36467
36009
  isEphemeralAnchorOutput,
36010
+ isLegacySparkAddress,
36468
36011
  isSafeForNumber,
36469
36012
  isTxBroadcast,
36470
36013
  isValidPublicKey,