@buildonspark/spark-sdk 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/bare/index.cjs +938 -1401
  3. package/dist/bare/index.d.cts +128 -10
  4. package/dist/bare/index.d.ts +128 -10
  5. package/dist/bare/index.js +933 -1399
  6. package/dist/{chunk-MGCUXELA.js → chunk-IC4IUEOS.js} +931 -125
  7. package/dist/{chunk-MH7BMOLL.js → chunk-J2P3KTQP.js} +1 -1
  8. package/dist/{chunk-SXXM52XH.js → chunk-KIQTO4FX.js} +405 -1659
  9. package/dist/{chunk-73GJOG5R.js → chunk-XWLR6G5C.js} +1 -1
  10. package/dist/{chunk-55XNR6DM.js → chunk-YH7MDVTT.js} +1 -1
  11. package/dist/{client-DrjQwET9.d.ts → client-DBZ43pJT.d.ts} +1 -1
  12. package/dist/{client-DUFejFfn.d.cts → client-DWml6sjL.d.cts} +1 -1
  13. package/dist/debug.cjs +942 -1403
  14. package/dist/debug.d.cts +8 -5
  15. package/dist/debug.d.ts +8 -5
  16. package/dist/debug.js +4 -4
  17. package/dist/graphql/objects/index.d.cts +3 -3
  18. package/dist/graphql/objects/index.d.ts +3 -3
  19. package/dist/index.cjs +898 -1362
  20. package/dist/index.d.cts +6 -6
  21. package/dist/index.d.ts +6 -6
  22. package/dist/index.js +9 -5
  23. package/dist/index.node.cjs +898 -1362
  24. package/dist/index.node.d.cts +6 -6
  25. package/dist/index.node.d.ts +6 -6
  26. package/dist/index.node.js +8 -4
  27. package/dist/{logging-CGeEoKYd.d.cts → logging-BUpzk4Z6.d.cts} +3 -3
  28. package/dist/{logging-DpSsvFVM.d.ts → logging-Dt2ooQiP.d.ts} +3 -3
  29. package/dist/native/index.cjs +898 -1362
  30. package/dist/native/index.d.cts +129 -25
  31. package/dist/native/index.d.ts +129 -25
  32. package/dist/native/index.js +897 -1363
  33. package/dist/proto/spark.cjs +931 -125
  34. package/dist/proto/spark.d.cts +1 -1
  35. package/dist/proto/spark.d.ts +1 -1
  36. package/dist/proto/spark.js +17 -1
  37. package/dist/proto/spark_token.d.cts +1 -1
  38. package/dist/proto/spark_token.d.ts +1 -1
  39. package/dist/proto/spark_token.js +2 -2
  40. package/dist/{spark-CLz4-Ln8.d.cts → spark-DasxuVfm.d.cts} +150 -5
  41. package/dist/{spark-CLz4-Ln8.d.ts → spark-DasxuVfm.d.ts} +150 -5
  42. package/dist/{spark-wallet-BVBrWYKL.d.cts → spark-wallet-BoMIOPWW.d.cts} +13 -9
  43. package/dist/{spark-wallet-CFPm6wZs.d.ts → spark-wallet-jlC0XN5f.d.ts} +13 -9
  44. package/dist/{spark-wallet.node-e1gncoIZ.d.ts → spark-wallet.node-07PksUHH.d.cts} +1 -1
  45. package/dist/{spark-wallet.node-B_00X-1j.d.cts → spark-wallet.node-CdWkKMSq.d.ts} +1 -1
  46. package/dist/tests/test-utils.cjs +947 -144
  47. package/dist/tests/test-utils.d.cts +4 -4
  48. package/dist/tests/test-utils.d.ts +4 -4
  49. package/dist/tests/test-utils.js +5 -5
  50. package/dist/{token-transactions-BkAqlmY6.d.ts → token-transactions-BDzCrQSk.d.cts} +5 -19
  51. package/dist/{token-transactions-BZGtwFFM.d.cts → token-transactions-DscJaJOE.d.ts} +5 -19
  52. package/dist/types/index.cjs +923 -125
  53. package/dist/types/index.d.cts +2 -2
  54. package/dist/types/index.d.ts +2 -2
  55. package/dist/types/index.js +2 -2
  56. package/package.json +1 -1
  57. package/src/proto/spark.ts +1167 -103
  58. package/src/services/config.ts +0 -4
  59. package/src/services/token-transactions.ts +11 -703
  60. package/src/services/wallet-config.ts +0 -2
  61. package/src/spark-wallet/proto-descriptors.ts +1 -1
  62. package/src/spark-wallet/spark-wallet.ts +47 -215
  63. package/src/spark_descriptors.pb +0 -0
  64. package/src/tests/address.test.ts +141 -0
  65. package/src/tests/integration/address.test.ts +4 -0
  66. package/src/tests/integration/lightning.test.ts +14 -9
  67. package/src/tests/integration/token-output.test.ts +0 -1
  68. package/src/tests/integration/transfer.test.ts +108 -2
  69. package/src/tests/token-hashing.test.ts +0 -247
  70. package/src/utils/address.ts +58 -35
  71. package/src/utils/token-hashing.ts +1 -420
  72. package/src/utils/token-transaction-validation.ts +0 -330
@@ -1448,6 +1448,7 @@ __export(index_exports, {
1448
1448
  addPublicKeys: () => addPublicKeys,
1449
1449
  applyAdaptorToSignature: () => applyAdaptorToSignature,
1450
1450
  applyAdditiveTweakToPublicKey: () => applyAdditiveTweakToPublicKey,
1451
+ assertBech32: () => assertBech32,
1451
1452
  bech32mDecode: () => bech32mDecode,
1452
1453
  bigIntToPrivateKey: () => bigIntToPrivateKey,
1453
1454
  checkIfSelectedOutputsAreAvailable: () => checkIfSelectedOutputsAreAvailable,
@@ -1510,6 +1511,7 @@ __export(index_exports, {
1510
1511
  getTxId: () => getTxId,
1511
1512
  getTxIdNoReverse: () => getTxIdNoReverse,
1512
1513
  isEphemeralAnchorOutput: () => isEphemeralAnchorOutput,
1514
+ isLegacySparkAddress: () => isLegacySparkAddress,
1513
1515
  isSafeForNumber: () => isSafeForNumber,
1514
1516
  isTxBroadcast: () => isTxBroadcast,
1515
1517
  isValidPublicKey: () => isValidPublicKey,
@@ -2273,9 +2275,9 @@ function invoiceStatusFromJSON(object) {
2273
2275
  case 2:
2274
2276
  case "FINALIZED":
2275
2277
  return 2 /* FINALIZED */;
2276
- case 3:
2277
- case "EXPIRED":
2278
- return 3 /* EXPIRED */;
2278
+ case 4:
2279
+ case "RETURNED":
2280
+ return 4 /* RETURNED */;
2279
2281
  case -1:
2280
2282
  case "UNRECOGNIZED":
2281
2283
  default:
@@ -2290,8 +2292,8 @@ function invoiceStatusToJSON(object) {
2290
2292
  return "PENDING";
2291
2293
  case 2 /* FINALIZED */:
2292
2294
  return "FINALIZED";
2293
- case 3 /* EXPIRED */:
2294
- return "EXPIRED";
2295
+ case 4 /* RETURNED */:
2296
+ return "RETURNED";
2295
2297
  case -1 /* UNRECOGNIZED */:
2296
2298
  default:
2297
2299
  return "UNRECOGNIZED";
@@ -4095,6 +4097,626 @@ var SigningResult_SignatureSharesEntry = {
4095
4097
  return message;
4096
4098
  }
4097
4099
  };
4100
+ function createBaseRenewLeafRequest() {
4101
+ return { leafId: "", ownerIdentityPublicKey: new Uint8Array(0), signingJobs: void 0 };
4102
+ }
4103
+ var RenewLeafRequest = {
4104
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4105
+ if (message.leafId !== "") {
4106
+ writer.uint32(10).string(message.leafId);
4107
+ }
4108
+ if (message.ownerIdentityPublicKey.length !== 0) {
4109
+ writer.uint32(18).bytes(message.ownerIdentityPublicKey);
4110
+ }
4111
+ switch (message.signingJobs?.$case) {
4112
+ case "renewNodeTimelockSigningJob":
4113
+ RenewNodeTimelockSigningJob.encode(message.signingJobs.renewNodeTimelockSigningJob, writer.uint32(26).fork()).join();
4114
+ break;
4115
+ case "renewRefundTimelockSigningJob":
4116
+ RenewRefundTimelockSigningJob.encode(
4117
+ message.signingJobs.renewRefundTimelockSigningJob,
4118
+ writer.uint32(34).fork()
4119
+ ).join();
4120
+ break;
4121
+ }
4122
+ return writer;
4123
+ },
4124
+ decode(input, length) {
4125
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4126
+ const end = length === void 0 ? reader.len : reader.pos + length;
4127
+ const message = createBaseRenewLeafRequest();
4128
+ while (reader.pos < end) {
4129
+ const tag = reader.uint32();
4130
+ switch (tag >>> 3) {
4131
+ case 1: {
4132
+ if (tag !== 10) {
4133
+ break;
4134
+ }
4135
+ message.leafId = reader.string();
4136
+ continue;
4137
+ }
4138
+ case 2: {
4139
+ if (tag !== 18) {
4140
+ break;
4141
+ }
4142
+ message.ownerIdentityPublicKey = reader.bytes();
4143
+ continue;
4144
+ }
4145
+ case 3: {
4146
+ if (tag !== 26) {
4147
+ break;
4148
+ }
4149
+ message.signingJobs = {
4150
+ $case: "renewNodeTimelockSigningJob",
4151
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.decode(reader, reader.uint32())
4152
+ };
4153
+ continue;
4154
+ }
4155
+ case 4: {
4156
+ if (tag !== 34) {
4157
+ break;
4158
+ }
4159
+ message.signingJobs = {
4160
+ $case: "renewRefundTimelockSigningJob",
4161
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.decode(reader, reader.uint32())
4162
+ };
4163
+ continue;
4164
+ }
4165
+ }
4166
+ if ((tag & 7) === 4 || tag === 0) {
4167
+ break;
4168
+ }
4169
+ reader.skip(tag & 7);
4170
+ }
4171
+ return message;
4172
+ },
4173
+ fromJSON(object) {
4174
+ return {
4175
+ leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : "",
4176
+ ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
4177
+ signingJobs: isSet3(object.renewNodeTimelockSigningJob) ? {
4178
+ $case: "renewNodeTimelockSigningJob",
4179
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromJSON(object.renewNodeTimelockSigningJob)
4180
+ } : isSet3(object.renewRefundTimelockSigningJob) ? {
4181
+ $case: "renewRefundTimelockSigningJob",
4182
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromJSON(object.renewRefundTimelockSigningJob)
4183
+ } : void 0
4184
+ };
4185
+ },
4186
+ toJSON(message) {
4187
+ const obj = {};
4188
+ if (message.leafId !== "") {
4189
+ obj.leafId = message.leafId;
4190
+ }
4191
+ if (message.ownerIdentityPublicKey.length !== 0) {
4192
+ obj.ownerIdentityPublicKey = base64FromBytes2(message.ownerIdentityPublicKey);
4193
+ }
4194
+ if (message.signingJobs?.$case === "renewNodeTimelockSigningJob") {
4195
+ obj.renewNodeTimelockSigningJob = RenewNodeTimelockSigningJob.toJSON(
4196
+ message.signingJobs.renewNodeTimelockSigningJob
4197
+ );
4198
+ } else if (message.signingJobs?.$case === "renewRefundTimelockSigningJob") {
4199
+ obj.renewRefundTimelockSigningJob = RenewRefundTimelockSigningJob.toJSON(
4200
+ message.signingJobs.renewRefundTimelockSigningJob
4201
+ );
4202
+ }
4203
+ return obj;
4204
+ },
4205
+ create(base) {
4206
+ return RenewLeafRequest.fromPartial(base ?? {});
4207
+ },
4208
+ fromPartial(object) {
4209
+ const message = createBaseRenewLeafRequest();
4210
+ message.leafId = object.leafId ?? "";
4211
+ message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
4212
+ switch (object.signingJobs?.$case) {
4213
+ case "renewNodeTimelockSigningJob": {
4214
+ if (object.signingJobs?.renewNodeTimelockSigningJob !== void 0 && object.signingJobs?.renewNodeTimelockSigningJob !== null) {
4215
+ message.signingJobs = {
4216
+ $case: "renewNodeTimelockSigningJob",
4217
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromPartial(
4218
+ object.signingJobs.renewNodeTimelockSigningJob
4219
+ )
4220
+ };
4221
+ }
4222
+ break;
4223
+ }
4224
+ case "renewRefundTimelockSigningJob": {
4225
+ if (object.signingJobs?.renewRefundTimelockSigningJob !== void 0 && object.signingJobs?.renewRefundTimelockSigningJob !== null) {
4226
+ message.signingJobs = {
4227
+ $case: "renewRefundTimelockSigningJob",
4228
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromPartial(
4229
+ object.signingJobs.renewRefundTimelockSigningJob
4230
+ )
4231
+ };
4232
+ }
4233
+ break;
4234
+ }
4235
+ }
4236
+ return message;
4237
+ }
4238
+ };
4239
+ function createBaseRenewNodeTimelockSigningJob() {
4240
+ return {
4241
+ splitNodeTxSigningJob: void 0,
4242
+ splitNodeDirectTxSigningJob: void 0,
4243
+ nodeTxSigningJob: void 0,
4244
+ refundTxSigningJob: void 0,
4245
+ directNodeTxSigningJob: void 0,
4246
+ directRefundTxSigningJob: void 0,
4247
+ directFromCpfpRefundTxSigningJob: void 0
4248
+ };
4249
+ }
4250
+ var RenewNodeTimelockSigningJob = {
4251
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4252
+ if (message.splitNodeTxSigningJob !== void 0) {
4253
+ UserSignedTxSigningJob.encode(message.splitNodeTxSigningJob, writer.uint32(10).fork()).join();
4254
+ }
4255
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
4256
+ UserSignedTxSigningJob.encode(message.splitNodeDirectTxSigningJob, writer.uint32(18).fork()).join();
4257
+ }
4258
+ if (message.nodeTxSigningJob !== void 0) {
4259
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(26).fork()).join();
4260
+ }
4261
+ if (message.refundTxSigningJob !== void 0) {
4262
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(34).fork()).join();
4263
+ }
4264
+ if (message.directNodeTxSigningJob !== void 0) {
4265
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(42).fork()).join();
4266
+ }
4267
+ if (message.directRefundTxSigningJob !== void 0) {
4268
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(50).fork()).join();
4269
+ }
4270
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4271
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(58).fork()).join();
4272
+ }
4273
+ return writer;
4274
+ },
4275
+ decode(input, length) {
4276
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4277
+ const end = length === void 0 ? reader.len : reader.pos + length;
4278
+ const message = createBaseRenewNodeTimelockSigningJob();
4279
+ while (reader.pos < end) {
4280
+ const tag = reader.uint32();
4281
+ switch (tag >>> 3) {
4282
+ case 1: {
4283
+ if (tag !== 10) {
4284
+ break;
4285
+ }
4286
+ message.splitNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4287
+ continue;
4288
+ }
4289
+ case 2: {
4290
+ if (tag !== 18) {
4291
+ break;
4292
+ }
4293
+ message.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4294
+ continue;
4295
+ }
4296
+ case 3: {
4297
+ if (tag !== 26) {
4298
+ break;
4299
+ }
4300
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4301
+ continue;
4302
+ }
4303
+ case 4: {
4304
+ if (tag !== 34) {
4305
+ break;
4306
+ }
4307
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4308
+ continue;
4309
+ }
4310
+ case 5: {
4311
+ if (tag !== 42) {
4312
+ break;
4313
+ }
4314
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4315
+ continue;
4316
+ }
4317
+ case 6: {
4318
+ if (tag !== 50) {
4319
+ break;
4320
+ }
4321
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4322
+ continue;
4323
+ }
4324
+ case 7: {
4325
+ if (tag !== 58) {
4326
+ break;
4327
+ }
4328
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4329
+ continue;
4330
+ }
4331
+ }
4332
+ if ((tag & 7) === 4 || tag === 0) {
4333
+ break;
4334
+ }
4335
+ reader.skip(tag & 7);
4336
+ }
4337
+ return message;
4338
+ },
4339
+ fromJSON(object) {
4340
+ return {
4341
+ splitNodeTxSigningJob: isSet3(object.splitNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeTxSigningJob) : void 0,
4342
+ splitNodeDirectTxSigningJob: isSet3(object.splitNodeDirectTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeDirectTxSigningJob) : void 0,
4343
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
4344
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
4345
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
4346
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
4347
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
4348
+ };
4349
+ },
4350
+ toJSON(message) {
4351
+ const obj = {};
4352
+ if (message.splitNodeTxSigningJob !== void 0) {
4353
+ obj.splitNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeTxSigningJob);
4354
+ }
4355
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
4356
+ obj.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeDirectTxSigningJob);
4357
+ }
4358
+ if (message.nodeTxSigningJob !== void 0) {
4359
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
4360
+ }
4361
+ if (message.refundTxSigningJob !== void 0) {
4362
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
4363
+ }
4364
+ if (message.directNodeTxSigningJob !== void 0) {
4365
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
4366
+ }
4367
+ if (message.directRefundTxSigningJob !== void 0) {
4368
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
4369
+ }
4370
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4371
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
4372
+ }
4373
+ return obj;
4374
+ },
4375
+ create(base) {
4376
+ return RenewNodeTimelockSigningJob.fromPartial(base ?? {});
4377
+ },
4378
+ fromPartial(object) {
4379
+ const message = createBaseRenewNodeTimelockSigningJob();
4380
+ message.splitNodeTxSigningJob = object.splitNodeTxSigningJob !== void 0 && object.splitNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeTxSigningJob) : void 0;
4381
+ message.splitNodeDirectTxSigningJob = object.splitNodeDirectTxSigningJob !== void 0 && object.splitNodeDirectTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeDirectTxSigningJob) : void 0;
4382
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
4383
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
4384
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
4385
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
4386
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
4387
+ return message;
4388
+ }
4389
+ };
4390
+ function createBaseRenewRefundTimelockSigningJob() {
4391
+ return {
4392
+ nodeTxSigningJob: void 0,
4393
+ refundTxSigningJob: void 0,
4394
+ directNodeTxSigningJob: void 0,
4395
+ directRefundTxSigningJob: void 0,
4396
+ directFromCpfpRefundTxSigningJob: void 0
4397
+ };
4398
+ }
4399
+ var RenewRefundTimelockSigningJob = {
4400
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4401
+ if (message.nodeTxSigningJob !== void 0) {
4402
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(10).fork()).join();
4403
+ }
4404
+ if (message.refundTxSigningJob !== void 0) {
4405
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(18).fork()).join();
4406
+ }
4407
+ if (message.directNodeTxSigningJob !== void 0) {
4408
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(26).fork()).join();
4409
+ }
4410
+ if (message.directRefundTxSigningJob !== void 0) {
4411
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(34).fork()).join();
4412
+ }
4413
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4414
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(42).fork()).join();
4415
+ }
4416
+ return writer;
4417
+ },
4418
+ decode(input, length) {
4419
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4420
+ const end = length === void 0 ? reader.len : reader.pos + length;
4421
+ const message = createBaseRenewRefundTimelockSigningJob();
4422
+ while (reader.pos < end) {
4423
+ const tag = reader.uint32();
4424
+ switch (tag >>> 3) {
4425
+ case 1: {
4426
+ if (tag !== 10) {
4427
+ break;
4428
+ }
4429
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4430
+ continue;
4431
+ }
4432
+ case 2: {
4433
+ if (tag !== 18) {
4434
+ break;
4435
+ }
4436
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4437
+ continue;
4438
+ }
4439
+ case 3: {
4440
+ if (tag !== 26) {
4441
+ break;
4442
+ }
4443
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4444
+ continue;
4445
+ }
4446
+ case 4: {
4447
+ if (tag !== 34) {
4448
+ break;
4449
+ }
4450
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4451
+ continue;
4452
+ }
4453
+ case 5: {
4454
+ if (tag !== 42) {
4455
+ break;
4456
+ }
4457
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4458
+ continue;
4459
+ }
4460
+ }
4461
+ if ((tag & 7) === 4 || tag === 0) {
4462
+ break;
4463
+ }
4464
+ reader.skip(tag & 7);
4465
+ }
4466
+ return message;
4467
+ },
4468
+ fromJSON(object) {
4469
+ return {
4470
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
4471
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
4472
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
4473
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
4474
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
4475
+ };
4476
+ },
4477
+ toJSON(message) {
4478
+ const obj = {};
4479
+ if (message.nodeTxSigningJob !== void 0) {
4480
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
4481
+ }
4482
+ if (message.refundTxSigningJob !== void 0) {
4483
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
4484
+ }
4485
+ if (message.directNodeTxSigningJob !== void 0) {
4486
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
4487
+ }
4488
+ if (message.directRefundTxSigningJob !== void 0) {
4489
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
4490
+ }
4491
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4492
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
4493
+ }
4494
+ return obj;
4495
+ },
4496
+ create(base) {
4497
+ return RenewRefundTimelockSigningJob.fromPartial(base ?? {});
4498
+ },
4499
+ fromPartial(object) {
4500
+ const message = createBaseRenewRefundTimelockSigningJob();
4501
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
4502
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
4503
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
4504
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
4505
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
4506
+ return message;
4507
+ }
4508
+ };
4509
+ function createBaseRenewLeafResponse() {
4510
+ return { renewResult: void 0 };
4511
+ }
4512
+ var RenewLeafResponse = {
4513
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4514
+ switch (message.renewResult?.$case) {
4515
+ case "extendResult":
4516
+ RenewNodeTimelockResult.encode(message.renewResult.extendResult, writer.uint32(10).fork()).join();
4517
+ break;
4518
+ case "refreshResult":
4519
+ RenewRefundTimelockResult.encode(message.renewResult.refreshResult, writer.uint32(18).fork()).join();
4520
+ break;
4521
+ }
4522
+ return writer;
4523
+ },
4524
+ decode(input, length) {
4525
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4526
+ const end = length === void 0 ? reader.len : reader.pos + length;
4527
+ const message = createBaseRenewLeafResponse();
4528
+ while (reader.pos < end) {
4529
+ const tag = reader.uint32();
4530
+ switch (tag >>> 3) {
4531
+ case 1: {
4532
+ if (tag !== 10) {
4533
+ break;
4534
+ }
4535
+ message.renewResult = {
4536
+ $case: "extendResult",
4537
+ extendResult: RenewNodeTimelockResult.decode(reader, reader.uint32())
4538
+ };
4539
+ continue;
4540
+ }
4541
+ case 2: {
4542
+ if (tag !== 18) {
4543
+ break;
4544
+ }
4545
+ message.renewResult = {
4546
+ $case: "refreshResult",
4547
+ refreshResult: RenewRefundTimelockResult.decode(reader, reader.uint32())
4548
+ };
4549
+ continue;
4550
+ }
4551
+ }
4552
+ if ((tag & 7) === 4 || tag === 0) {
4553
+ break;
4554
+ }
4555
+ reader.skip(tag & 7);
4556
+ }
4557
+ return message;
4558
+ },
4559
+ fromJSON(object) {
4560
+ return {
4561
+ renewResult: isSet3(object.extendResult) ? { $case: "extendResult", extendResult: RenewNodeTimelockResult.fromJSON(object.extendResult) } : isSet3(object.refreshResult) ? { $case: "refreshResult", refreshResult: RenewRefundTimelockResult.fromJSON(object.refreshResult) } : void 0
4562
+ };
4563
+ },
4564
+ toJSON(message) {
4565
+ const obj = {};
4566
+ if (message.renewResult?.$case === "extendResult") {
4567
+ obj.extendResult = RenewNodeTimelockResult.toJSON(message.renewResult.extendResult);
4568
+ } else if (message.renewResult?.$case === "refreshResult") {
4569
+ obj.refreshResult = RenewRefundTimelockResult.toJSON(message.renewResult.refreshResult);
4570
+ }
4571
+ return obj;
4572
+ },
4573
+ create(base) {
4574
+ return RenewLeafResponse.fromPartial(base ?? {});
4575
+ },
4576
+ fromPartial(object) {
4577
+ const message = createBaseRenewLeafResponse();
4578
+ switch (object.renewResult?.$case) {
4579
+ case "extendResult": {
4580
+ if (object.renewResult?.extendResult !== void 0 && object.renewResult?.extendResult !== null) {
4581
+ message.renewResult = {
4582
+ $case: "extendResult",
4583
+ extendResult: RenewNodeTimelockResult.fromPartial(object.renewResult.extendResult)
4584
+ };
4585
+ }
4586
+ break;
4587
+ }
4588
+ case "refreshResult": {
4589
+ if (object.renewResult?.refreshResult !== void 0 && object.renewResult?.refreshResult !== null) {
4590
+ message.renewResult = {
4591
+ $case: "refreshResult",
4592
+ refreshResult: RenewRefundTimelockResult.fromPartial(object.renewResult.refreshResult)
4593
+ };
4594
+ }
4595
+ break;
4596
+ }
4597
+ }
4598
+ return message;
4599
+ }
4600
+ };
4601
+ function createBaseRenewNodeTimelockResult() {
4602
+ return { splitNode: void 0, node: void 0 };
4603
+ }
4604
+ var RenewNodeTimelockResult = {
4605
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4606
+ if (message.splitNode !== void 0) {
4607
+ TreeNode.encode(message.splitNode, writer.uint32(10).fork()).join();
4608
+ }
4609
+ if (message.node !== void 0) {
4610
+ TreeNode.encode(message.node, writer.uint32(18).fork()).join();
4611
+ }
4612
+ return writer;
4613
+ },
4614
+ decode(input, length) {
4615
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4616
+ const end = length === void 0 ? reader.len : reader.pos + length;
4617
+ const message = createBaseRenewNodeTimelockResult();
4618
+ while (reader.pos < end) {
4619
+ const tag = reader.uint32();
4620
+ switch (tag >>> 3) {
4621
+ case 1: {
4622
+ if (tag !== 10) {
4623
+ break;
4624
+ }
4625
+ message.splitNode = TreeNode.decode(reader, reader.uint32());
4626
+ continue;
4627
+ }
4628
+ case 2: {
4629
+ if (tag !== 18) {
4630
+ break;
4631
+ }
4632
+ message.node = TreeNode.decode(reader, reader.uint32());
4633
+ continue;
4634
+ }
4635
+ }
4636
+ if ((tag & 7) === 4 || tag === 0) {
4637
+ break;
4638
+ }
4639
+ reader.skip(tag & 7);
4640
+ }
4641
+ return message;
4642
+ },
4643
+ fromJSON(object) {
4644
+ return {
4645
+ splitNode: isSet3(object.splitNode) ? TreeNode.fromJSON(object.splitNode) : void 0,
4646
+ node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0
4647
+ };
4648
+ },
4649
+ toJSON(message) {
4650
+ const obj = {};
4651
+ if (message.splitNode !== void 0) {
4652
+ obj.splitNode = TreeNode.toJSON(message.splitNode);
4653
+ }
4654
+ if (message.node !== void 0) {
4655
+ obj.node = TreeNode.toJSON(message.node);
4656
+ }
4657
+ return obj;
4658
+ },
4659
+ create(base) {
4660
+ return RenewNodeTimelockResult.fromPartial(base ?? {});
4661
+ },
4662
+ fromPartial(object) {
4663
+ const message = createBaseRenewNodeTimelockResult();
4664
+ message.splitNode = object.splitNode !== void 0 && object.splitNode !== null ? TreeNode.fromPartial(object.splitNode) : void 0;
4665
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
4666
+ return message;
4667
+ }
4668
+ };
4669
+ function createBaseRenewRefundTimelockResult() {
4670
+ return { node: void 0 };
4671
+ }
4672
+ var RenewRefundTimelockResult = {
4673
+ encode(message, writer = new import_wire4.BinaryWriter()) {
4674
+ if (message.node !== void 0) {
4675
+ TreeNode.encode(message.node, writer.uint32(10).fork()).join();
4676
+ }
4677
+ return writer;
4678
+ },
4679
+ decode(input, length) {
4680
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
4681
+ const end = length === void 0 ? reader.len : reader.pos + length;
4682
+ const message = createBaseRenewRefundTimelockResult();
4683
+ while (reader.pos < end) {
4684
+ const tag = reader.uint32();
4685
+ switch (tag >>> 3) {
4686
+ case 1: {
4687
+ if (tag !== 10) {
4688
+ break;
4689
+ }
4690
+ message.node = TreeNode.decode(reader, reader.uint32());
4691
+ continue;
4692
+ }
4693
+ }
4694
+ if ((tag & 7) === 4 || tag === 0) {
4695
+ break;
4696
+ }
4697
+ reader.skip(tag & 7);
4698
+ }
4699
+ return message;
4700
+ },
4701
+ fromJSON(object) {
4702
+ return { node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0 };
4703
+ },
4704
+ toJSON(message) {
4705
+ const obj = {};
4706
+ if (message.node !== void 0) {
4707
+ obj.node = TreeNode.toJSON(message.node);
4708
+ }
4709
+ return obj;
4710
+ },
4711
+ create(base) {
4712
+ return RenewRefundTimelockResult.fromPartial(base ?? {});
4713
+ },
4714
+ fromPartial(object) {
4715
+ const message = createBaseRenewRefundTimelockResult();
4716
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
4717
+ return message;
4718
+ }
4719
+ };
4098
4720
  function createBaseNodeSignatureShares() {
4099
4721
  return {
4100
4722
  nodeId: "",
@@ -15875,7 +16497,7 @@ var QuerySparkInvoicesResponse = {
15875
16497
  }
15876
16498
  };
15877
16499
  function createBaseInvoiceResponse() {
15878
- return { invoice: "", status: 0 };
16500
+ return { invoice: "", status: 0, transferType: void 0 };
15879
16501
  }
15880
16502
  var InvoiceResponse = {
15881
16503
  encode(message, writer = new import_wire4.BinaryWriter()) {
@@ -15885,6 +16507,14 @@ var InvoiceResponse = {
15885
16507
  if (message.status !== 0) {
15886
16508
  writer.uint32(16).int32(message.status);
15887
16509
  }
16510
+ switch (message.transferType?.$case) {
16511
+ case "satsTransfer":
16512
+ SatsTransfer.encode(message.transferType.satsTransfer, writer.uint32(26).fork()).join();
16513
+ break;
16514
+ case "tokenTransfer":
16515
+ TokenTransfer.encode(message.transferType.tokenTransfer, writer.uint32(34).fork()).join();
16516
+ break;
16517
+ }
15888
16518
  return writer;
15889
16519
  },
15890
16520
  decode(input, length) {
@@ -15908,6 +16538,23 @@ var InvoiceResponse = {
15908
16538
  message.status = reader.int32();
15909
16539
  continue;
15910
16540
  }
16541
+ case 3: {
16542
+ if (tag !== 26) {
16543
+ break;
16544
+ }
16545
+ message.transferType = { $case: "satsTransfer", satsTransfer: SatsTransfer.decode(reader, reader.uint32()) };
16546
+ continue;
16547
+ }
16548
+ case 4: {
16549
+ if (tag !== 34) {
16550
+ break;
16551
+ }
16552
+ message.transferType = {
16553
+ $case: "tokenTransfer",
16554
+ tokenTransfer: TokenTransfer.decode(reader, reader.uint32())
16555
+ };
16556
+ continue;
16557
+ }
15911
16558
  }
15912
16559
  if ((tag & 7) === 4 || tag === 0) {
15913
16560
  break;
@@ -15919,7 +16566,8 @@ var InvoiceResponse = {
15919
16566
  fromJSON(object) {
15920
16567
  return {
15921
16568
  invoice: isSet3(object.invoice) ? globalThis.String(object.invoice) : "",
15922
- status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0
16569
+ status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0,
16570
+ transferType: isSet3(object.satsTransfer) ? { $case: "satsTransfer", satsTransfer: SatsTransfer.fromJSON(object.satsTransfer) } : isSet3(object.tokenTransfer) ? { $case: "tokenTransfer", tokenTransfer: TokenTransfer.fromJSON(object.tokenTransfer) } : void 0
15923
16571
  };
15924
16572
  },
15925
16573
  toJSON(message) {
@@ -15930,6 +16578,11 @@ var InvoiceResponse = {
15930
16578
  if (message.status !== 0) {
15931
16579
  obj.status = invoiceStatusToJSON(message.status);
15932
16580
  }
16581
+ if (message.transferType?.$case === "satsTransfer") {
16582
+ obj.satsTransfer = SatsTransfer.toJSON(message.transferType.satsTransfer);
16583
+ } else if (message.transferType?.$case === "tokenTransfer") {
16584
+ obj.tokenTransfer = TokenTransfer.toJSON(message.transferType.tokenTransfer);
16585
+ }
15933
16586
  return obj;
15934
16587
  },
15935
16588
  create(base) {
@@ -15939,6 +16592,130 @@ var InvoiceResponse = {
15939
16592
  const message = createBaseInvoiceResponse();
15940
16593
  message.invoice = object.invoice ?? "";
15941
16594
  message.status = object.status ?? 0;
16595
+ switch (object.transferType?.$case) {
16596
+ case "satsTransfer": {
16597
+ if (object.transferType?.satsTransfer !== void 0 && object.transferType?.satsTransfer !== null) {
16598
+ message.transferType = {
16599
+ $case: "satsTransfer",
16600
+ satsTransfer: SatsTransfer.fromPartial(object.transferType.satsTransfer)
16601
+ };
16602
+ }
16603
+ break;
16604
+ }
16605
+ case "tokenTransfer": {
16606
+ if (object.transferType?.tokenTransfer !== void 0 && object.transferType?.tokenTransfer !== null) {
16607
+ message.transferType = {
16608
+ $case: "tokenTransfer",
16609
+ tokenTransfer: TokenTransfer.fromPartial(object.transferType.tokenTransfer)
16610
+ };
16611
+ }
16612
+ break;
16613
+ }
16614
+ }
16615
+ return message;
16616
+ }
16617
+ };
16618
+ function createBaseSatsTransfer() {
16619
+ return { transferId: new Uint8Array(0) };
16620
+ }
16621
+ var SatsTransfer = {
16622
+ encode(message, writer = new import_wire4.BinaryWriter()) {
16623
+ if (message.transferId.length !== 0) {
16624
+ writer.uint32(10).bytes(message.transferId);
16625
+ }
16626
+ return writer;
16627
+ },
16628
+ decode(input, length) {
16629
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
16630
+ const end = length === void 0 ? reader.len : reader.pos + length;
16631
+ const message = createBaseSatsTransfer();
16632
+ while (reader.pos < end) {
16633
+ const tag = reader.uint32();
16634
+ switch (tag >>> 3) {
16635
+ case 1: {
16636
+ if (tag !== 10) {
16637
+ break;
16638
+ }
16639
+ message.transferId = reader.bytes();
16640
+ continue;
16641
+ }
16642
+ }
16643
+ if ((tag & 7) === 4 || tag === 0) {
16644
+ break;
16645
+ }
16646
+ reader.skip(tag & 7);
16647
+ }
16648
+ return message;
16649
+ },
16650
+ fromJSON(object) {
16651
+ return { transferId: isSet3(object.transferId) ? bytesFromBase642(object.transferId) : new Uint8Array(0) };
16652
+ },
16653
+ toJSON(message) {
16654
+ const obj = {};
16655
+ if (message.transferId.length !== 0) {
16656
+ obj.transferId = base64FromBytes2(message.transferId);
16657
+ }
16658
+ return obj;
16659
+ },
16660
+ create(base) {
16661
+ return SatsTransfer.fromPartial(base ?? {});
16662
+ },
16663
+ fromPartial(object) {
16664
+ const message = createBaseSatsTransfer();
16665
+ message.transferId = object.transferId ?? new Uint8Array(0);
16666
+ return message;
16667
+ }
16668
+ };
16669
+ function createBaseTokenTransfer() {
16670
+ return { finalTokenTransactionHash: new Uint8Array(0) };
16671
+ }
16672
+ var TokenTransfer = {
16673
+ encode(message, writer = new import_wire4.BinaryWriter()) {
16674
+ if (message.finalTokenTransactionHash.length !== 0) {
16675
+ writer.uint32(10).bytes(message.finalTokenTransactionHash);
16676
+ }
16677
+ return writer;
16678
+ },
16679
+ decode(input, length) {
16680
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
16681
+ const end = length === void 0 ? reader.len : reader.pos + length;
16682
+ const message = createBaseTokenTransfer();
16683
+ while (reader.pos < end) {
16684
+ const tag = reader.uint32();
16685
+ switch (tag >>> 3) {
16686
+ case 1: {
16687
+ if (tag !== 10) {
16688
+ break;
16689
+ }
16690
+ message.finalTokenTransactionHash = reader.bytes();
16691
+ continue;
16692
+ }
16693
+ }
16694
+ if ((tag & 7) === 4 || tag === 0) {
16695
+ break;
16696
+ }
16697
+ reader.skip(tag & 7);
16698
+ }
16699
+ return message;
16700
+ },
16701
+ fromJSON(object) {
16702
+ return {
16703
+ finalTokenTransactionHash: isSet3(object.finalTokenTransactionHash) ? bytesFromBase642(object.finalTokenTransactionHash) : new Uint8Array(0)
16704
+ };
16705
+ },
16706
+ toJSON(message) {
16707
+ const obj = {};
16708
+ if (message.finalTokenTransactionHash.length !== 0) {
16709
+ obj.finalTokenTransactionHash = base64FromBytes2(message.finalTokenTransactionHash);
16710
+ }
16711
+ return obj;
16712
+ },
16713
+ create(base) {
16714
+ return TokenTransfer.fromPartial(base ?? {});
16715
+ },
16716
+ fromPartial(object) {
16717
+ const message = createBaseTokenTransfer();
16718
+ message.finalTokenTransactionHash = object.finalTokenTransactionHash ?? new Uint8Array(0);
15942
16719
  return message;
15943
16720
  }
15944
16721
  };
@@ -16154,6 +16931,21 @@ var SparkServiceDefinition = {
16154
16931
  responseStream: false,
16155
16932
  options: {}
16156
16933
  },
16934
+ /**
16935
+ * Resets the timelocks for a leaf's transactions. Can be used to reset the
16936
+ * refund transaction timelock for a leaf (when the node transaction
16937
+ * timelock is still > 300) or reset the node and refund transaction
16938
+ * timelock. Returns an error if a leaf is not yet eligible to renew the
16939
+ * timelocks, see RenewLeafRequest for more details.
16940
+ */
16941
+ renew_leaf: {
16942
+ name: "renew_leaf",
16943
+ requestType: RenewLeafRequest,
16944
+ requestStream: false,
16945
+ responseType: RenewLeafResponse,
16946
+ responseStream: false,
16947
+ options: {}
16948
+ },
16157
16949
  get_signing_operator_list: {
16158
16950
  name: "get_signing_operator_list",
16159
16951
  requestType: Empty,
@@ -16644,6 +17436,13 @@ function uint64be(value) {
16644
17436
  // src/utils/address.ts
16645
17437
  var BECH32M_LIMIT = 1024;
16646
17438
  var AddressNetwork = {
17439
+ MAINNET: "spark",
17440
+ TESTNET: "sparkt",
17441
+ REGTEST: "sparkrt",
17442
+ SIGNET: "sparks",
17443
+ LOCAL: "sparkl"
17444
+ };
17445
+ var LegacyAddressNetwork = {
16647
17446
  MAINNET: "sp",
16648
17447
  TESTNET: "spt",
16649
17448
  REGTEST: "sprt",
@@ -16674,7 +17473,7 @@ function encodeSparkAddressWithSignature(payload, signature) {
16674
17473
  const serializedPayload = w.finish();
16675
17474
  const words = import_base2.bech32m.toWords(serializedPayload);
16676
17475
  return bech32mEncode(
16677
- AddressNetwork[payload.network],
17476
+ LegacyAddressNetwork[payload.network],
16678
17477
  words
16679
17478
  );
16680
17479
  } catch (error) {
@@ -16690,14 +17489,14 @@ function encodeSparkAddressWithSignature(payload, signature) {
16690
17489
  }
16691
17490
  function decodeSparkAddress(address2, network) {
16692
17491
  try {
16693
- const decoded = bech32mDecode(address2);
16694
- if (decoded.prefix !== AddressNetwork[network]) {
17492
+ if (network !== getNetworkFromSparkAddress(address2)) {
16695
17493
  throw new ValidationError("Invalid Spark address prefix", {
16696
17494
  field: "address",
16697
17495
  value: address2,
16698
- expected: `prefix='${AddressNetwork[network]}'`
17496
+ expected: `prefix='${AddressNetwork[network]}' or '${LegacyAddressNetwork[network]}'`
16699
17497
  });
16700
17498
  }
17499
+ const decoded = bech32mDecode(address2);
16701
17500
  const payload = SparkAddress.decode(import_base2.bech32m.fromWords(decoded.words));
16702
17501
  const { identityPublicKey, sparkInvoiceFields, signature } = payload;
16703
17502
  const identityPubkeyHex = (0, import_utils3.bytesToHex)(identityPublicKey);
@@ -16741,18 +17540,35 @@ function decodeSparkAddress(address2, network) {
16741
17540
  );
16742
17541
  }
16743
17542
  }
17543
+ var PrefixToNetwork = Object.fromEntries(
17544
+ Object.entries(AddressNetwork).map(([k, v]) => [v, k])
17545
+ );
17546
+ var LegacyPrefixToNetwork = Object.fromEntries(
17547
+ Object.entries(LegacyAddressNetwork).map(([k, v]) => [v, k])
17548
+ );
17549
+ function getNetworkFromSparkAddress(address2) {
17550
+ const { prefix } = bech32mDecode(address2);
17551
+ const network = PrefixToNetwork[prefix] ?? LegacyPrefixToNetwork[prefix];
17552
+ if (!network) {
17553
+ throw new ValidationError("Invalid Spark address prefix", {
17554
+ field: "network",
17555
+ value: address2,
17556
+ expected: "prefix='spark1', 'sparkt1', 'sparkrt1', 'sparks1', 'sparkl1' or legacy ('sp1', 'spt1', 'sprt1', 'sps1', 'spl1')"
17557
+ });
17558
+ }
17559
+ return network;
17560
+ }
17561
+ function isLegacySparkAddress(address2) {
17562
+ try {
17563
+ const { prefix } = bech32mDecode(address2);
17564
+ return prefix in LegacyPrefixToNetwork;
17565
+ } catch (error) {
17566
+ return false;
17567
+ }
17568
+ }
16744
17569
  function isValidSparkAddress(address2) {
16745
17570
  try {
16746
- const network = Object.entries(AddressNetwork).find(
16747
- ([_, prefix]) => address2.startsWith(prefix)
16748
- )?.[0];
16749
- if (!network) {
16750
- throw new ValidationError("Invalid Spark address network", {
16751
- field: "network",
16752
- value: address2,
16753
- expected: Object.values(AddressNetwork)
16754
- });
16755
- }
17571
+ const network = getNetworkFromSparkAddress(address2);
16756
17572
  decodeSparkAddress(address2, network);
16757
17573
  return true;
16758
17574
  } catch (error) {
@@ -16948,25 +17764,16 @@ function validateSparkInvoiceSignature(invoice) {
16948
17764
  );
16949
17765
  }
16950
17766
  }
16951
- function getNetworkFromSparkAddress(address2) {
16952
- const { prefix } = bech32mDecode(address2);
16953
- const network = Object.entries(AddressNetwork).find(
16954
- ([, p]) => p === prefix
16955
- )?.[0];
16956
- if (!network) {
16957
- throw new ValidationError("Invalid Spark address network", {
16958
- field: "network",
16959
- value: address2,
16960
- expected: Object.values(AddressNetwork)
16961
- });
16962
- }
16963
- return network;
16964
- }
16965
17767
  function toProtoTimestamp(date) {
16966
17768
  const ms = date.getTime();
16967
17769
  return { seconds: Math.floor(ms / 1e3), nanos: ms % 1e3 * 1e6 };
16968
17770
  }
17771
+ function assertBech32(s) {
17772
+ const i = s.lastIndexOf("1");
17773
+ if (i <= 0 || i >= s.length - 1) throw new Error("invalid bech32 string");
17774
+ }
16969
17775
  function bech32mDecode(address2) {
17776
+ assertBech32(address2);
16970
17777
  return import_base2.bech32m.decode(address2, BECH32M_LIMIT);
16971
17778
  }
16972
17779
  function bech32mEncode(prefix, words) {
@@ -17579,7 +18386,6 @@ var BASE_CONFIG = {
17579
18386
  threshold: 2,
17580
18387
  signingOperators: getLocalSigningOperators(),
17581
18388
  tokenSignatures: "SCHNORR",
17582
- tokenTransactionVersion: "V1",
17583
18389
  tokenValidityDurationSeconds: 180,
17584
18390
  electrsUrl: getElectrsUrl("LOCAL"),
17585
18391
  expectedWithdrawBondSats: 1e4,
@@ -20238,7 +21044,7 @@ var isWebExtension = (
20238
21044
  "chrome" in globalThis && globalThis.chrome.runtime?.id
20239
21045
  );
20240
21046
  var userAgent = "navigator" in globalThis ? globalThis.navigator.userAgent || "unknown-user-agent" : void 0;
20241
- var packageVersion = true ? "0.3.3" : "unknown";
21047
+ var packageVersion = true ? "0.3.4" : "unknown";
20242
21048
  var baseEnvStr = "unknown";
20243
21049
  if (isBun) {
20244
21050
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -20702,7 +21508,7 @@ var ReactNativeSparkSigner = class extends DefaultSparkSigner {
20702
21508
  // src/spark-wallet/spark-wallet.ts
20703
21509
  init_buffer();
20704
21510
  var import_core13 = require("@lightsparkdev/core");
20705
- var import_secp256k115 = require("@noble/curves/secp256k1");
21511
+ var import_secp256k113 = require("@noble/curves/secp256k1");
20706
21512
  var import_utils24 = require("@noble/curves/utils");
20707
21513
  var import_bip392 = require("@scure/bip39");
20708
21514
  var import_english2 = require("@scure/bip39/wordlists/english");
@@ -21932,9 +22738,6 @@ var WalletConfigService = class {
21932
22738
  getTokenSignatures() {
21933
22739
  return this.config.tokenSignatures;
21934
22740
  }
21935
- getTokenTransactionVersion() {
21936
- return this.config.tokenTransactionVersion;
21937
- }
21938
22741
  getTokenValidityDurationSeconds() {
21939
22742
  return this.config.tokenValidityDurationSeconds;
21940
22743
  }
@@ -28829,7 +29632,6 @@ var LightningService = class {
28829
29632
 
28830
29633
  // src/services/token-transactions.ts
28831
29634
  init_buffer();
28832
- var import_secp256k113 = require("@noble/curves/secp256k1");
28833
29635
  var import_utils19 = require("@noble/curves/utils");
28834
29636
  var import_utils20 = require("@noble/hashes/utils");
28835
29637
 
@@ -28839,8 +29641,6 @@ var import_sha212 = require("@noble/hashes/sha2");
28839
29641
  var import_base4 = require("@scure/base");
28840
29642
  function hashTokenTransaction(tokenTransaction, partialHash = false) {
28841
29643
  switch (tokenTransaction.version) {
28842
- case 0:
28843
- return hashTokenTransactionV0(tokenTransaction, partialHash);
28844
29644
  case 1:
28845
29645
  return hashTokenTransactionV1(tokenTransaction, partialHash);
28846
29646
  case 2:
@@ -28852,345 +29652,6 @@ function hashTokenTransaction(tokenTransaction, partialHash = false) {
28852
29652
  });
28853
29653
  }
28854
29654
  }
28855
- function hashTokenTransactionV0(tokenTransaction, partialHash = false) {
28856
- if (!tokenTransaction) {
28857
- throw new ValidationError("token transaction cannot be nil", {
28858
- field: "tokenTransaction"
28859
- });
28860
- }
28861
- let allHashes = [];
28862
- if (tokenTransaction.tokenInputs?.$case === "transferInput") {
28863
- if (!tokenTransaction.tokenInputs.transferInput.outputsToSpend) {
28864
- throw new ValidationError("outputs to spend cannot be null", {
28865
- field: "tokenInputs.transferInput.outputsToSpend"
28866
- });
28867
- }
28868
- if (tokenTransaction.tokenInputs.transferInput.outputsToSpend.length === 0) {
28869
- throw new ValidationError("outputs to spend cannot be empty", {
28870
- field: "tokenInputs.transferInput.outputsToSpend"
28871
- });
28872
- }
28873
- for (const [
28874
- i,
28875
- output
28876
- ] of tokenTransaction.tokenInputs.transferInput.outputsToSpend.entries()) {
28877
- if (!output) {
28878
- throw new ValidationError(`output cannot be null at index ${i}`, {
28879
- field: `tokenInputs.transferInput.outputsToSpend[${i}]`,
28880
- index: i
28881
- });
28882
- }
28883
- const hashObj2 = import_sha212.sha256.create();
28884
- if (output.prevTokenTransactionHash) {
28885
- const prevHash = output.prevTokenTransactionHash;
28886
- if (output.prevTokenTransactionHash.length !== 32) {
28887
- throw new ValidationError(
28888
- `invalid previous transaction hash length at index ${i}`,
28889
- {
28890
- field: `tokenInputs.transferInput.outputsToSpend[${i}].prevTokenTransactionHash`,
28891
- value: prevHash,
28892
- expectedLength: 32,
28893
- actualLength: prevHash.length,
28894
- index: i
28895
- }
28896
- );
28897
- }
28898
- hashObj2.update(output.prevTokenTransactionHash);
28899
- }
28900
- const voutBytes = new Uint8Array(4);
28901
- new DataView(voutBytes.buffer).setUint32(
28902
- 0,
28903
- output.prevTokenTransactionVout,
28904
- false
28905
- );
28906
- hashObj2.update(voutBytes);
28907
- allHashes.push(hashObj2.digest());
28908
- }
28909
- }
28910
- if (tokenTransaction.tokenInputs?.$case === "mintInput") {
28911
- const hashObj2 = import_sha212.sha256.create();
28912
- if (tokenTransaction.tokenInputs.mintInput.issuerPublicKey) {
28913
- const issuerPubKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
28914
- if (issuerPubKey.length === 0) {
28915
- throw new ValidationError("issuer public key cannot be empty", {
28916
- field: "tokenInputs.mintInput.issuerPublicKey",
28917
- value: issuerPubKey,
28918
- expectedLength: 1,
28919
- actualLength: 0
28920
- });
28921
- }
28922
- hashObj2.update(issuerPubKey);
28923
- let timestampValue = 0;
28924
- const mintInput = tokenTransaction.tokenInputs.mintInput;
28925
- if ("issuerProvidedTimestamp" in mintInput) {
28926
- const v0MintInput = mintInput;
28927
- if (v0MintInput.issuerProvidedTimestamp != 0) {
28928
- timestampValue = v0MintInput.issuerProvidedTimestamp;
28929
- }
28930
- } else if ("clientCreatedTimestamp" in tokenTransaction && tokenTransaction.clientCreatedTimestamp) {
28931
- timestampValue = tokenTransaction.clientCreatedTimestamp.getTime();
28932
- }
28933
- if (timestampValue != 0) {
28934
- const timestampBytes = new Uint8Array(8);
28935
- new DataView(timestampBytes.buffer).setBigUint64(
28936
- 0,
28937
- BigInt(timestampValue),
28938
- true
28939
- // true for little-endian to match Go implementation
28940
- );
28941
- hashObj2.update(timestampBytes);
28942
- }
28943
- allHashes.push(hashObj2.digest());
28944
- }
28945
- }
28946
- if (tokenTransaction.tokenInputs?.$case === "createInput") {
28947
- const issuerPubKeyHashObj = import_sha212.sha256.create();
28948
- const createInput = tokenTransaction.tokenInputs.createInput;
28949
- if (!createInput.issuerPublicKey || createInput.issuerPublicKey.length === 0) {
28950
- throw new ValidationError("issuer public key cannot be nil or empty", {
28951
- field: "tokenInputs.createInput.issuerPublicKey"
28952
- });
28953
- }
28954
- issuerPubKeyHashObj.update(createInput.issuerPublicKey);
28955
- allHashes.push(issuerPubKeyHashObj.digest());
28956
- const tokenNameHashObj = import_sha212.sha256.create();
28957
- if (!createInput.tokenName || createInput.tokenName.length === 0) {
28958
- throw new ValidationError("token name cannot be empty", {
28959
- field: "tokenInputs.createInput.tokenName"
28960
- });
28961
- }
28962
- if (createInput.tokenName.length > 20) {
28963
- throw new ValidationError("token name cannot be longer than 20 bytes", {
28964
- field: "tokenInputs.createInput.tokenName",
28965
- value: createInput.tokenName,
28966
- expectedLength: 20,
28967
- actualLength: createInput.tokenName.length
28968
- });
28969
- }
28970
- const tokenNameBytes = new Uint8Array(20);
28971
- const tokenNameEncoder = new TextEncoder();
28972
- tokenNameBytes.set(tokenNameEncoder.encode(createInput.tokenName));
28973
- tokenNameHashObj.update(tokenNameBytes);
28974
- allHashes.push(tokenNameHashObj.digest());
28975
- const tokenTickerHashObj = import_sha212.sha256.create();
28976
- if (!createInput.tokenTicker || createInput.tokenTicker.length === 0) {
28977
- throw new ValidationError("token ticker cannot be empty", {
28978
- field: "tokenInputs.createInput.tokenTicker"
28979
- });
28980
- }
28981
- if (createInput.tokenTicker.length > 6) {
28982
- throw new ValidationError("token ticker cannot be longer than 6 bytes", {
28983
- field: "tokenInputs.createInput.tokenTicker",
28984
- value: createInput.tokenTicker,
28985
- expectedLength: 6,
28986
- actualLength: createInput.tokenTicker.length
28987
- });
28988
- }
28989
- const tokenTickerBytes = new Uint8Array(6);
28990
- const tokenTickerEncoder = new TextEncoder();
28991
- tokenTickerBytes.set(tokenTickerEncoder.encode(createInput.tokenTicker));
28992
- tokenTickerHashObj.update(tokenTickerBytes);
28993
- allHashes.push(tokenTickerHashObj.digest());
28994
- const decimalsHashObj = import_sha212.sha256.create();
28995
- const decimalsBytes = new Uint8Array(4);
28996
- new DataView(decimalsBytes.buffer).setUint32(
28997
- 0,
28998
- createInput.decimals,
28999
- false
29000
- );
29001
- decimalsHashObj.update(decimalsBytes);
29002
- allHashes.push(decimalsHashObj.digest());
29003
- const maxSupplyHashObj = import_sha212.sha256.create();
29004
- if (!createInput.maxSupply) {
29005
- throw new ValidationError("max supply cannot be nil", {
29006
- field: "tokenInputs.createInput.maxSupply"
29007
- });
29008
- }
29009
- if (createInput.maxSupply.length !== 16) {
29010
- throw new ValidationError("max supply must be exactly 16 bytes", {
29011
- field: "tokenInputs.createInput.maxSupply",
29012
- value: createInput.maxSupply,
29013
- expectedLength: 16,
29014
- actualLength: createInput.maxSupply.length
29015
- });
29016
- }
29017
- maxSupplyHashObj.update(createInput.maxSupply);
29018
- allHashes.push(maxSupplyHashObj.digest());
29019
- const isFreezableHashObj = import_sha212.sha256.create();
29020
- const isFreezableByte = new Uint8Array([createInput.isFreezable ? 1 : 0]);
29021
- isFreezableHashObj.update(isFreezableByte);
29022
- allHashes.push(isFreezableHashObj.digest());
29023
- const creationEntityHashObj = import_sha212.sha256.create();
29024
- if (!partialHash && createInput.creationEntityPublicKey) {
29025
- creationEntityHashObj.update(createInput.creationEntityPublicKey);
29026
- }
29027
- allHashes.push(creationEntityHashObj.digest());
29028
- }
29029
- if (!tokenTransaction.tokenOutputs) {
29030
- throw new ValidationError("token outputs cannot be null", {
29031
- field: "tokenOutputs"
29032
- });
29033
- }
29034
- if (tokenTransaction.tokenOutputs.length === 0 && tokenTransaction.tokenInputs?.$case !== "createInput") {
29035
- throw new ValidationError("token outputs cannot be empty", {
29036
- field: "tokenOutputs"
29037
- });
29038
- }
29039
- for (const [i, output] of tokenTransaction.tokenOutputs.entries()) {
29040
- if (!output) {
29041
- throw new ValidationError(`output cannot be null at index ${i}`, {
29042
- field: `tokenOutputs[${i}]`,
29043
- index: i
29044
- });
29045
- }
29046
- const hashObj2 = import_sha212.sha256.create();
29047
- if (output.id && !partialHash) {
29048
- if (output.id.length === 0) {
29049
- throw new ValidationError(`output ID at index ${i} cannot be empty`, {
29050
- field: `tokenOutputs[${i}].id`,
29051
- index: i
29052
- });
29053
- }
29054
- hashObj2.update(new TextEncoder().encode(output.id));
29055
- }
29056
- if (output.ownerPublicKey) {
29057
- if (output.ownerPublicKey.length === 0) {
29058
- throw new ValidationError(
29059
- `owner public key at index ${i} cannot be empty`,
29060
- {
29061
- field: `tokenOutputs[${i}].ownerPublicKey`,
29062
- index: i
29063
- }
29064
- );
29065
- }
29066
- hashObj2.update(output.ownerPublicKey);
29067
- }
29068
- if (!partialHash) {
29069
- const revPubKey = output.revocationCommitment;
29070
- if (revPubKey) {
29071
- if (revPubKey.length === 0) {
29072
- throw new ValidationError(
29073
- `revocation commitment at index ${i} cannot be empty`,
29074
- {
29075
- field: `tokenOutputs[${i}].revocationCommitment`,
29076
- index: i
29077
- }
29078
- );
29079
- }
29080
- hashObj2.update(revPubKey);
29081
- }
29082
- const bondBytes = new Uint8Array(8);
29083
- new DataView(bondBytes.buffer).setBigUint64(
29084
- 0,
29085
- BigInt(output.withdrawBondSats),
29086
- false
29087
- );
29088
- hashObj2.update(bondBytes);
29089
- const locktimeBytes = new Uint8Array(8);
29090
- new DataView(locktimeBytes.buffer).setBigUint64(
29091
- 0,
29092
- BigInt(output.withdrawRelativeBlockLocktime),
29093
- false
29094
- );
29095
- hashObj2.update(locktimeBytes);
29096
- }
29097
- if (output.tokenPublicKey) {
29098
- if (output.tokenPublicKey.length === 0) {
29099
- throw new ValidationError(
29100
- `token public key at index ${i} cannot be empty`,
29101
- {
29102
- field: `tokenOutputs[${i}].tokenPublicKey`,
29103
- index: i
29104
- }
29105
- );
29106
- }
29107
- hashObj2.update(output.tokenPublicKey);
29108
- }
29109
- if (output.tokenAmount) {
29110
- if (output.tokenAmount.length === 0) {
29111
- throw new ValidationError(
29112
- `token amount at index ${i} cannot be empty`,
29113
- {
29114
- field: `tokenOutputs[${i}].tokenAmount`,
29115
- index: i
29116
- }
29117
- );
29118
- }
29119
- if (output.tokenAmount.length > 16) {
29120
- throw new ValidationError(
29121
- `token amount at index ${i} exceeds maximum length`,
29122
- {
29123
- field: `tokenOutputs[${i}].tokenAmount`,
29124
- value: output.tokenAmount,
29125
- expectedLength: 16,
29126
- actualLength: output.tokenAmount.length,
29127
- index: i
29128
- }
29129
- );
29130
- }
29131
- hashObj2.update(output.tokenAmount);
29132
- }
29133
- allHashes.push(hashObj2.digest());
29134
- }
29135
- if (!tokenTransaction.sparkOperatorIdentityPublicKeys) {
29136
- throw new ValidationError(
29137
- "spark operator identity public keys cannot be null",
29138
- {}
29139
- );
29140
- }
29141
- const sortedPubKeys = [
29142
- ...tokenTransaction.sparkOperatorIdentityPublicKeys || []
29143
- ].sort((a, b) => {
29144
- for (let i = 0; i < a.length && i < b.length; i++) {
29145
- if (a[i] !== b[i]) return a[i] - b[i];
29146
- }
29147
- return a.length - b.length;
29148
- });
29149
- for (const [i, pubKey] of sortedPubKeys.entries()) {
29150
- if (!pubKey) {
29151
- throw new ValidationError(
29152
- `operator public key at index ${i} cannot be null`,
29153
- {
29154
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
29155
- index: i
29156
- }
29157
- );
29158
- }
29159
- if (pubKey.length === 0) {
29160
- throw new ValidationError(
29161
- `operator public key at index ${i} cannot be empty`,
29162
- {
29163
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
29164
- index: i
29165
- }
29166
- );
29167
- }
29168
- const hashObj2 = import_sha212.sha256.create();
29169
- hashObj2.update(pubKey);
29170
- allHashes.push(hashObj2.digest());
29171
- }
29172
- const hashObj = import_sha212.sha256.create();
29173
- let networkBytes = new Uint8Array(4);
29174
- new DataView(networkBytes.buffer).setUint32(
29175
- 0,
29176
- tokenTransaction.network.valueOf(),
29177
- false
29178
- // false for big-endian
29179
- );
29180
- hashObj.update(networkBytes);
29181
- allHashes.push(hashObj.digest());
29182
- const finalHashObj = import_sha212.sha256.create();
29183
- const concatenatedHashes = new Uint8Array(
29184
- allHashes.reduce((sum, hash) => sum + hash.length, 0)
29185
- );
29186
- let offset = 0;
29187
- for (const hash of allHashes) {
29188
- concatenatedHashes.set(hash, offset);
29189
- offset += hash.length;
29190
- }
29191
- finalHashObj.update(concatenatedHashes);
29192
- return finalHashObj.digest();
29193
- }
29194
29655
  function hashTokenTransactionV1(tokenTransaction, partialHash = false) {
29195
29656
  if (!tokenTransaction) {
29196
29657
  throw new ValidationError("token transaction cannot be nil", {
@@ -30120,24 +30581,6 @@ function hashOperatorSpecificTokenTransactionSignablePayload(payload) {
30120
30581
  return finalHashObj.digest();
30121
30582
  }
30122
30583
 
30123
- // src/utils/token-keyshares.ts
30124
- init_buffer();
30125
- var import_secp256k112 = require("@noble/curves/secp256k1");
30126
- function recoverRevocationSecretFromKeyshares(keyshares, threshold) {
30127
- const shares = keyshares.map((keyshare) => ({
30128
- fieldModulus: BigInt("0x" + import_secp256k112.secp256k1.CURVE.n.toString(16)),
30129
- // secp256k1 curve order
30130
- threshold,
30131
- index: BigInt(keyshare.operatorIndex),
30132
- share: BigInt(
30133
- "0x" + import_buffer.Buffer.from(keyshare.keyshare.keyshare).toString("hex")
30134
- ),
30135
- proofs: []
30136
- }));
30137
- const recoveredSecret = recoverSecret(shares);
30138
- return bigIntToPrivateKey(recoveredSecret);
30139
- }
30140
-
30141
30584
  // src/utils/token-transaction-validation.ts
30142
30585
  init_buffer();
30143
30586
  function areByteArraysEqual(a, b) {
@@ -30149,250 +30592,6 @@ function areByteArraysEqual(a, b) {
30149
30592
  function hasDuplicates(array) {
30150
30593
  return new Set(array).size !== array.length;
30151
30594
  }
30152
- function validateTokenTransactionV0(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
30153
- if (finalTokenTransaction.network !== partialTokenTransaction.network) {
30154
- throw new InternalValidationError(
30155
- "Network mismatch in response token transaction",
30156
- {
30157
- value: finalTokenTransaction.network,
30158
- expected: partialTokenTransaction.network
30159
- }
30160
- );
30161
- }
30162
- if (!finalTokenTransaction.tokenInputs) {
30163
- throw new InternalValidationError(
30164
- "Token inputs missing in final transaction",
30165
- {
30166
- value: finalTokenTransaction
30167
- }
30168
- );
30169
- }
30170
- if (!partialTokenTransaction.tokenInputs) {
30171
- throw new InternalValidationError(
30172
- "Token inputs missing in partial transaction",
30173
- {
30174
- value: partialTokenTransaction
30175
- }
30176
- );
30177
- }
30178
- if (finalTokenTransaction.tokenInputs.$case !== partialTokenTransaction.tokenInputs.$case) {
30179
- throw new InternalValidationError(
30180
- `Transaction type mismatch: final transaction has ${finalTokenTransaction.tokenInputs.$case}, partial transaction has ${partialTokenTransaction.tokenInputs.$case}`,
30181
- {
30182
- value: finalTokenTransaction.tokenInputs.$case,
30183
- expected: partialTokenTransaction.tokenInputs.$case
30184
- }
30185
- );
30186
- }
30187
- if (finalTokenTransaction.sparkOperatorIdentityPublicKeys.length !== partialTokenTransaction.sparkOperatorIdentityPublicKeys.length) {
30188
- throw new InternalValidationError(
30189
- "Spark operator identity public keys count mismatch",
30190
- {
30191
- value: finalTokenTransaction.sparkOperatorIdentityPublicKeys.length,
30192
- expected: partialTokenTransaction.sparkOperatorIdentityPublicKeys.length
30193
- }
30194
- );
30195
- }
30196
- if (partialTokenTransaction.tokenInputs.$case === "mintInput" && finalTokenTransaction.tokenInputs.$case === "mintInput") {
30197
- const finalMintInput = finalTokenTransaction.tokenInputs.mintInput;
30198
- const partialMintInput = partialTokenTransaction.tokenInputs.mintInput;
30199
- if (!areByteArraysEqual(
30200
- finalMintInput.issuerPublicKey,
30201
- partialMintInput.issuerPublicKey
30202
- )) {
30203
- throw new InternalValidationError(
30204
- "Issuer public key mismatch in mint input",
30205
- {
30206
- value: finalMintInput.issuerPublicKey.toString(),
30207
- expected: partialMintInput.issuerPublicKey.toString()
30208
- }
30209
- );
30210
- }
30211
- } else if (partialTokenTransaction.tokenInputs.$case === "transferInput" && finalTokenTransaction.tokenInputs.$case === "transferInput") {
30212
- const finalTransferInput = finalTokenTransaction.tokenInputs.transferInput;
30213
- const partialTransferInput = partialTokenTransaction.tokenInputs.transferInput;
30214
- if (finalTransferInput.outputsToSpend.length !== partialTransferInput.outputsToSpend.length) {
30215
- throw new InternalValidationError(
30216
- "Outputs to spend count mismatch in transfer input",
30217
- {
30218
- value: finalTransferInput.outputsToSpend.length,
30219
- expected: partialTransferInput.outputsToSpend.length
30220
- }
30221
- );
30222
- }
30223
- for (let i = 0; i < finalTransferInput.outputsToSpend.length; i++) {
30224
- const finalOutput = finalTransferInput.outputsToSpend[i];
30225
- const partialOutput = partialTransferInput.outputsToSpend[i];
30226
- if (!finalOutput) {
30227
- throw new InternalValidationError(
30228
- "Token output to spend missing in final transaction",
30229
- {
30230
- outputIndex: i,
30231
- value: finalOutput
30232
- }
30233
- );
30234
- }
30235
- if (!partialOutput) {
30236
- throw new InternalValidationError(
30237
- "Token output to spend missing in partial transaction",
30238
- {
30239
- outputIndex: i,
30240
- value: partialOutput
30241
- }
30242
- );
30243
- }
30244
- if (!areByteArraysEqual(
30245
- finalOutput.prevTokenTransactionHash,
30246
- partialOutput.prevTokenTransactionHash
30247
- )) {
30248
- throw new InternalValidationError(
30249
- "Previous token transaction hash mismatch in transfer input",
30250
- {
30251
- outputIndex: i,
30252
- value: finalOutput.prevTokenTransactionHash.toString(),
30253
- expected: partialOutput.prevTokenTransactionHash.toString()
30254
- }
30255
- );
30256
- }
30257
- if (finalOutput.prevTokenTransactionVout !== partialOutput.prevTokenTransactionVout) {
30258
- throw new InternalValidationError(
30259
- "Previous token transaction vout mismatch in transfer input",
30260
- {
30261
- outputIndex: i,
30262
- value: finalOutput.prevTokenTransactionVout,
30263
- expected: partialOutput.prevTokenTransactionVout
30264
- }
30265
- );
30266
- }
30267
- }
30268
- }
30269
- if (finalTokenTransaction.tokenOutputs.length !== partialTokenTransaction.tokenOutputs.length) {
30270
- throw new InternalValidationError("Token outputs count mismatch", {
30271
- value: finalTokenTransaction.tokenOutputs.length,
30272
- expected: partialTokenTransaction.tokenOutputs.length
30273
- });
30274
- }
30275
- for (let i = 0; i < finalTokenTransaction.tokenOutputs.length; i++) {
30276
- const finalOutput = finalTokenTransaction.tokenOutputs[i];
30277
- const partialOutput = partialTokenTransaction.tokenOutputs[i];
30278
- if (!finalOutput) {
30279
- throw new InternalValidationError(
30280
- "Token output missing in final transaction",
30281
- {
30282
- outputIndex: i,
30283
- value: finalOutput
30284
- }
30285
- );
30286
- }
30287
- if (!partialOutput) {
30288
- throw new InternalValidationError(
30289
- "Token output missing in partial transaction",
30290
- {
30291
- outputIndex: i,
30292
- value: partialOutput
30293
- }
30294
- );
30295
- }
30296
- if (!areByteArraysEqual(
30297
- finalOutput.ownerPublicKey,
30298
- partialOutput.ownerPublicKey
30299
- )) {
30300
- throw new InternalValidationError(
30301
- "Owner public key mismatch in token output",
30302
- {
30303
- outputIndex: i,
30304
- value: finalOutput.ownerPublicKey.toString(),
30305
- expected: partialOutput.ownerPublicKey.toString()
30306
- }
30307
- );
30308
- }
30309
- if (finalOutput.tokenPublicKey !== void 0 && partialOutput.tokenPublicKey !== void 0 && !areByteArraysEqual(
30310
- finalOutput.tokenPublicKey,
30311
- partialOutput.tokenPublicKey
30312
- )) {
30313
- throw new InternalValidationError(
30314
- "Token public key mismatch in token output",
30315
- {
30316
- outputIndex: i,
30317
- value: finalOutput.tokenPublicKey?.toString(),
30318
- expected: partialOutput.tokenPublicKey?.toString()
30319
- }
30320
- );
30321
- }
30322
- if (!areByteArraysEqual(finalOutput.tokenAmount, partialOutput.tokenAmount)) {
30323
- throw new InternalValidationError(
30324
- "Token amount mismatch in token output",
30325
- {
30326
- outputIndex: i,
30327
- value: finalOutput.tokenAmount.toString(),
30328
- expected: partialOutput.tokenAmount.toString()
30329
- }
30330
- );
30331
- }
30332
- if (finalOutput.withdrawBondSats !== void 0) {
30333
- if (finalOutput.withdrawBondSats !== expectedWithdrawBondSats) {
30334
- throw new InternalValidationError(
30335
- "Withdraw bond sats mismatch in token output",
30336
- {
30337
- outputIndex: i,
30338
- value: finalOutput.withdrawBondSats,
30339
- expected: expectedWithdrawBondSats
30340
- }
30341
- );
30342
- }
30343
- }
30344
- if (finalOutput.withdrawRelativeBlockLocktime !== void 0) {
30345
- if (finalOutput.withdrawRelativeBlockLocktime !== expectedWithdrawRelativeBlockLocktime) {
30346
- throw new InternalValidationError(
30347
- "Withdraw relative block locktime mismatch in token output",
30348
- {
30349
- outputIndex: i,
30350
- value: finalOutput.withdrawRelativeBlockLocktime,
30351
- expected: expectedWithdrawRelativeBlockLocktime
30352
- }
30353
- );
30354
- }
30355
- }
30356
- if (keyshareInfo.threshold !== expectedThreshold) {
30357
- throw new InternalValidationError(
30358
- "Threshold mismatch: expected " + expectedThreshold + " but got " + keyshareInfo.threshold,
30359
- {
30360
- field: "threshold",
30361
- value: keyshareInfo.threshold,
30362
- expected: expectedThreshold
30363
- }
30364
- );
30365
- }
30366
- }
30367
- if (keyshareInfo.ownerIdentifiers.length !== Object.keys(signingOperators).length) {
30368
- throw new InternalValidationError(
30369
- `Keyshare operator count (${keyshareInfo.ownerIdentifiers.length}) does not match signing operator count (${Object.keys(signingOperators).length})`,
30370
- {
30371
- keyshareInfo: keyshareInfo.ownerIdentifiers.length,
30372
- signingOperators: Object.keys(signingOperators).length
30373
- }
30374
- );
30375
- }
30376
- if (hasDuplicates(keyshareInfo.ownerIdentifiers)) {
30377
- throw new InternalValidationError(
30378
- "Duplicate ownerIdentifiers found in keyshareInfo",
30379
- {
30380
- keyshareInfo: keyshareInfo.ownerIdentifiers
30381
- }
30382
- );
30383
- }
30384
- for (const identifier of keyshareInfo.ownerIdentifiers) {
30385
- if (!signingOperators[identifier]) {
30386
- throw new InternalValidationError(
30387
- `Keyshare operator ${identifier} not found in signing operator list`,
30388
- {
30389
- keyshareInfo: identifier,
30390
- signingOperators: Object.keys(signingOperators)
30391
- }
30392
- );
30393
- }
30394
- }
30395
- }
30396
30595
  function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
30397
30596
  if (finalTokenTransaction.network !== partialTokenTransaction.network) {
30398
30597
  throw new InternalValidationError(
@@ -30745,16 +30944,6 @@ var TokenTransactionService = class {
30745
30944
  tokenIdentifier,
30746
30945
  this.config.getNetworkType()
30747
30946
  ).tokenIdentifier;
30748
- let tokenPublicKey;
30749
- if (this.config.getTokenTransactionVersion() === "V0") {
30750
- const tokenClient = await this.connectionManager.createSparkTokenClient(
30751
- this.config.getCoordinatorAddress()
30752
- );
30753
- const tokenMetadata = await tokenClient.query_token_metadata({
30754
- tokenIdentifiers: [rawTokenIdentifier]
30755
- });
30756
- tokenPublicKey = tokenMetadata.tokenMetadata[0].issuerPublicKey;
30757
- }
30758
30947
  let sparkInvoices = [];
30759
30948
  const tokenOutputData = receiverOutputs.map((transfer) => {
30760
30949
  const receiverAddress = decodeSparkAddress(
@@ -30764,7 +30953,7 @@ var TokenTransactionService = class {
30764
30953
  if (receiverAddress.sparkInvoiceFields) {
30765
30954
  sparkInvoices.push(transfer.receiverSparkAddress);
30766
30955
  }
30767
- if (this.config.getTokenTransactionVersion() !== "V0" && receiverAddress.sparkInvoiceFields) {
30956
+ if (receiverAddress.sparkInvoiceFields) {
30768
30957
  return {
30769
30958
  receiverPublicKey: (0, import_utils20.hexToBytes)(receiverAddress.identityPublicKey),
30770
30959
  rawTokenIdentifier,
@@ -30775,24 +30964,14 @@ var TokenTransactionService = class {
30775
30964
  return {
30776
30965
  receiverPublicKey: (0, import_utils20.hexToBytes)(receiverAddress.identityPublicKey),
30777
30966
  rawTokenIdentifier,
30778
- tokenPublicKey,
30779
- // Remove for full v0 deprecation
30780
30967
  tokenAmount: transfer.tokenAmount
30781
30968
  };
30782
30969
  });
30783
- let tokenTransaction;
30784
- if (this.config.getTokenTransactionVersion() === "V0") {
30785
- tokenTransaction = await this.constructTransferTokenTransactionV0(
30786
- outputsToUse,
30787
- tokenOutputData
30788
- );
30789
- } else {
30790
- tokenTransaction = await this.constructTransferTokenTransaction(
30791
- outputsToUse,
30792
- tokenOutputData,
30793
- sparkInvoices
30794
- );
30795
- }
30970
+ const tokenTransaction = await this.constructTransferTokenTransaction(
30971
+ outputsToUse,
30972
+ tokenOutputData,
30973
+ sparkInvoices
30974
+ );
30796
30975
  const txId = await this.broadcastTokenTransaction(
30797
30976
  tokenTransaction,
30798
30977
  outputsToUse.map((output) => output.output.ownerPublicKey),
@@ -30800,44 +30979,6 @@ var TokenTransactionService = class {
30800
30979
  );
30801
30980
  return txId;
30802
30981
  }
30803
- async constructTransferTokenTransactionV0(selectedOutputs, tokenOutputData) {
30804
- selectedOutputs.sort(
30805
- (a, b) => a.previousTransactionVout - b.previousTransactionVout
30806
- );
30807
- const availableTokenAmount = sumAvailableTokens(selectedOutputs);
30808
- const totalRequestedAmount = tokenOutputData.reduce(
30809
- (sum, output) => sum + output.tokenAmount,
30810
- 0n
30811
- );
30812
- const tokenOutputs = tokenOutputData.map((output) => ({
30813
- ownerPublicKey: output.receiverPublicKey,
30814
- tokenPublicKey: output.tokenPublicKey,
30815
- tokenAmount: (0, import_utils19.numberToBytesBE)(output.tokenAmount, 16)
30816
- }));
30817
- if (availableTokenAmount > totalRequestedAmount) {
30818
- const changeAmount = availableTokenAmount - totalRequestedAmount;
30819
- const firstTokenPublicKey = tokenOutputData[0].tokenPublicKey;
30820
- tokenOutputs.push({
30821
- ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
30822
- tokenPublicKey: firstTokenPublicKey,
30823
- tokenAmount: (0, import_utils19.numberToBytesBE)(changeAmount, 16)
30824
- });
30825
- }
30826
- return {
30827
- network: this.config.getNetworkProto(),
30828
- tokenInputs: {
30829
- $case: "transferInput",
30830
- transferInput: {
30831
- outputsToSpend: selectedOutputs.map((output) => ({
30832
- prevTokenTransactionHash: output.previousTransactionHash,
30833
- prevTokenTransactionVout: output.previousTransactionVout
30834
- }))
30835
- }
30836
- },
30837
- tokenOutputs,
30838
- sparkOperatorIdentityPublicKeys: this.collectOperatorIdentityPublicKeys()
30839
- };
30840
- }
30841
30982
  async constructTransferTokenTransaction(selectedOutputs, tokenOutputData, sparkInvoices) {
30842
30983
  selectedOutputs.sort(
30843
30984
  (a, b) => a.previousTransactionVout - b.previousTransactionVout
@@ -30893,113 +31034,6 @@ var TokenTransactionService = class {
30893
31034
  }
30894
31035
  async broadcastTokenTransaction(tokenTransaction, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30895
31036
  const signingOperators = this.config.getSigningOperators();
30896
- if (!isTokenTransaction(tokenTransaction)) {
30897
- return this.broadcastTokenTransactionV0(
30898
- tokenTransaction,
30899
- signingOperators,
30900
- outputsToSpendSigningPublicKeys,
30901
- outputsToSpendCommitments
30902
- );
30903
- } else {
30904
- return this.broadcastTokenTransactionV1(
30905
- tokenTransaction,
30906
- signingOperators,
30907
- outputsToSpendSigningPublicKeys,
30908
- outputsToSpendCommitments
30909
- );
30910
- }
30911
- }
30912
- async broadcastTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
30913
- const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransactionV0(
30914
- tokenTransaction,
30915
- signingOperators,
30916
- outputsToSpendSigningPublicKeys,
30917
- outputsToSpendCommitments
30918
- );
30919
- const { successfulSignatures } = await this.signTokenTransactionV0(
30920
- finalTokenTransaction,
30921
- finalTokenTransactionHash,
30922
- signingOperators
30923
- );
30924
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
30925
- const outputsToSpend = finalTokenTransaction.tokenInputs.transferInput.outputsToSpend;
30926
- const errors = [];
30927
- const revocationSecrets = [];
30928
- for (let outputIndex = 0; outputIndex < outputsToSpend.length; outputIndex++) {
30929
- const outputKeyshares = successfulSignatures.map(({ identifier, response }) => ({
30930
- operatorIndex: parseInt(identifier, 16),
30931
- keyshare: response.revocationKeyshares[outputIndex]
30932
- }));
30933
- if (outputKeyshares.length < threshold) {
30934
- errors.push(
30935
- new ValidationError("Insufficient keyshares", {
30936
- field: "outputKeyshares",
30937
- value: outputKeyshares.length,
30938
- expected: threshold,
30939
- index: outputIndex
30940
- })
30941
- );
30942
- }
30943
- const seenIndices = /* @__PURE__ */ new Set();
30944
- for (const { operatorIndex } of outputKeyshares) {
30945
- if (seenIndices.has(operatorIndex)) {
30946
- errors.push(
30947
- new ValidationError("Duplicate operator index", {
30948
- field: "outputKeyshares",
30949
- value: operatorIndex,
30950
- expected: "Unique operator index",
30951
- index: outputIndex
30952
- })
30953
- );
30954
- }
30955
- seenIndices.add(operatorIndex);
30956
- }
30957
- const revocationSecret = recoverRevocationSecretFromKeyshares(
30958
- outputKeyshares,
30959
- threshold
30960
- );
30961
- const derivedRevocationCommitment = import_secp256k113.secp256k1.getPublicKey(
30962
- revocationSecret,
30963
- true
30964
- );
30965
- if (!outputsToSpendCommitments || !outputsToSpendCommitments[outputIndex] || !derivedRevocationCommitment.every(
30966
- (byte, i) => byte === outputsToSpendCommitments[outputIndex][i]
30967
- )) {
30968
- errors.push(
30969
- new InternalValidationError(
30970
- "Revocation commitment verification failed",
30971
- {
30972
- field: "revocationCommitment",
30973
- value: derivedRevocationCommitment,
30974
- expected: (0, import_utils19.bytesToHex)(outputsToSpendCommitments[outputIndex]),
30975
- outputIndex
30976
- }
30977
- )
30978
- );
30979
- }
30980
- revocationSecrets.push({
30981
- inputIndex: outputIndex,
30982
- revocationSecret
30983
- });
30984
- }
30985
- if (errors.length > 0) {
30986
- throw new ValidationError(
30987
- "Multiple validation errors occurred across outputs",
30988
- {
30989
- field: "outputValidation",
30990
- value: errors
30991
- }
30992
- );
30993
- }
30994
- await this.finalizeTokenTransaction(
30995
- finalTokenTransaction,
30996
- revocationSecrets,
30997
- threshold
30998
- );
30999
- }
31000
- return (0, import_utils19.bytesToHex)(finalTokenTransactionHash);
31001
- }
31002
- async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
31003
31037
  const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
31004
31038
  tokenTransaction,
31005
31039
  signingOperators,
@@ -31013,101 +31047,6 @@ var TokenTransactionService = class {
31013
31047
  );
31014
31048
  return (0, import_utils19.bytesToHex)(finalTokenTransactionHash);
31015
31049
  }
31016
- async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
31017
- const sparkClient = await this.connectionManager.createSparkClient(
31018
- this.config.getCoordinatorAddress()
31019
- );
31020
- const partialTokenTransactionHash = hashTokenTransactionV0(
31021
- tokenTransaction,
31022
- true
31023
- );
31024
- const ownerSignaturesWithIndex = [];
31025
- if (tokenTransaction.tokenInputs.$case === "mintInput") {
31026
- const issuerPublicKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
31027
- if (!issuerPublicKey) {
31028
- throw new ValidationError("Invalid mint input", {
31029
- field: "issuerPublicKey",
31030
- value: null,
31031
- expected: "Non-null issuer public key"
31032
- });
31033
- }
31034
- const ownerSignature = await this.signMessageWithKey(
31035
- partialTokenTransactionHash,
31036
- issuerPublicKey
31037
- );
31038
- ownerSignaturesWithIndex.push({
31039
- signature: ownerSignature,
31040
- inputIndex: 0
31041
- });
31042
- } else if (tokenTransaction.tokenInputs.$case === "transferInput") {
31043
- if (!outputsToSpendSigningPublicKeys || !outputsToSpendCommitments) {
31044
- throw new ValidationError("Invalid transfer input", {
31045
- field: "outputsToSpend",
31046
- value: {
31047
- signingPublicKeys: outputsToSpendSigningPublicKeys,
31048
- revocationPublicKeys: outputsToSpendCommitments
31049
- },
31050
- expected: "Non-null signing and revocation public keys"
31051
- });
31052
- }
31053
- for (const [i, key] of outputsToSpendSigningPublicKeys.entries()) {
31054
- if (!key) {
31055
- throw new ValidationError("Invalid signing key", {
31056
- field: "outputsToSpendSigningPublicKeys",
31057
- value: i,
31058
- expected: "Non-null signing key"
31059
- });
31060
- }
31061
- const ownerSignature = await this.signMessageWithKey(
31062
- partialTokenTransactionHash,
31063
- key
31064
- );
31065
- ownerSignaturesWithIndex.push({
31066
- signature: ownerSignature,
31067
- inputIndex: i
31068
- });
31069
- }
31070
- }
31071
- const startResponse = await sparkClient.start_token_transaction(
31072
- {
31073
- identityPublicKey: await this.config.signer.getIdentityPublicKey(),
31074
- partialTokenTransaction: tokenTransaction,
31075
- tokenTransactionSignatures: {
31076
- ownerSignatures: ownerSignaturesWithIndex
31077
- }
31078
- },
31079
- {
31080
- retry: true,
31081
- retryableStatuses: ["UNKNOWN", "UNAVAILABLE", "CANCELLED", "INTERNAL"],
31082
- retryMaxAttempts: 3
31083
- }
31084
- );
31085
- if (!startResponse.finalTokenTransaction) {
31086
- throw new Error("Final token transaction missing in start response");
31087
- }
31088
- if (!startResponse.keyshareInfo) {
31089
- throw new Error("Keyshare info missing in start response");
31090
- }
31091
- validateTokenTransactionV0(
31092
- startResponse.finalTokenTransaction,
31093
- tokenTransaction,
31094
- signingOperators,
31095
- startResponse.keyshareInfo,
31096
- this.config.getExpectedWithdrawBondSats(),
31097
- this.config.getExpectedWithdrawRelativeBlockLocktime(),
31098
- this.config.getThreshold()
31099
- );
31100
- const finalTokenTransaction = startResponse.finalTokenTransaction;
31101
- const finalTokenTransactionHash = hashTokenTransactionV0(
31102
- finalTokenTransaction,
31103
- false
31104
- );
31105
- return {
31106
- finalTokenTransaction,
31107
- finalTokenTransactionHash,
31108
- threshold: startResponse.keyshareInfo.threshold
31109
- };
31110
- }
31111
31050
  async startTokenTransaction(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
31112
31051
  const sparkClient = await this.connectionManager.createSparkTokenClient(
31113
31052
  this.config.getCoordinatorAddress()
@@ -31227,103 +31166,6 @@ var TokenTransactionService = class {
31227
31166
  threshold: startResponse.keyshareInfo.threshold
31228
31167
  };
31229
31168
  }
31230
- async signTokenTransactionV0(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
31231
- const soSignatures = await Promise.allSettled(
31232
- Object.entries(signingOperators).map(
31233
- async ([identifier, operator], index) => {
31234
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
31235
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
31236
- const payload = {
31237
- finalTokenTransactionHash,
31238
- operatorIdentityPublicKey: (0, import_utils20.hexToBytes)(operator.identityPublicKey)
31239
- };
31240
- const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
31241
- let operatorSpecificSignatures = [];
31242
- if (finalTokenTransaction.tokenInputs.$case === "mintInput") {
31243
- const issuerPublicKey = finalTokenTransaction.tokenInputs.mintInput.issuerPublicKey;
31244
- if (!issuerPublicKey) {
31245
- throw new ValidationError("Invalid mint input", {
31246
- field: "issuerPublicKey",
31247
- value: null,
31248
- expected: "Non-null issuer public key"
31249
- });
31250
- }
31251
- const ownerSignature = await this.signMessageWithKey(
31252
- payloadHash,
31253
- issuerPublicKey
31254
- );
31255
- operatorSpecificSignatures.push({
31256
- ownerSignature: {
31257
- signature: ownerSignature,
31258
- inputIndex: 0
31259
- },
31260
- payload
31261
- });
31262
- }
31263
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
31264
- const transferInput = finalTokenTransaction.tokenInputs.transferInput;
31265
- for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
31266
- let ownerSignature;
31267
- if (this.config.getTokenSignatures() === "SCHNORR") {
31268
- ownerSignature = await this.config.signer.signSchnorrWithIdentityKey(
31269
- payloadHash
31270
- );
31271
- } else {
31272
- ownerSignature = await this.config.signer.signMessageWithIdentityKey(
31273
- payloadHash
31274
- );
31275
- }
31276
- operatorSpecificSignatures.push({
31277
- ownerSignature: {
31278
- signature: ownerSignature,
31279
- inputIndex: i
31280
- },
31281
- payload
31282
- });
31283
- }
31284
- }
31285
- try {
31286
- const response = await internalSparkClient.sign_token_transaction(
31287
- {
31288
- finalTokenTransaction,
31289
- operatorSpecificSignatures,
31290
- identityPublicKey
31291
- },
31292
- {
31293
- retry: true,
31294
- retryableStatuses: [
31295
- "UNKNOWN",
31296
- "UNAVAILABLE",
31297
- "CANCELLED",
31298
- "INTERNAL"
31299
- ],
31300
- retryMaxAttempts: 3
31301
- }
31302
- );
31303
- return {
31304
- index,
31305
- identifier,
31306
- response
31307
- };
31308
- } catch (error) {
31309
- throw new NetworkError(
31310
- "Failed to sign token transaction",
31311
- {
31312
- operation: "sign_token_transaction",
31313
- errorCount: 1,
31314
- errors: error instanceof Error ? error.message : String(error)
31315
- },
31316
- error
31317
- );
31318
- }
31319
- }
31320
- )
31321
- );
31322
- const successfulSignatures = collectResponses(soSignatures);
31323
- return {
31324
- successfulSignatures
31325
- };
31326
- }
31327
31169
  async signTokenTransaction(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
31328
31170
  const coordinatorClient = await this.connectionManager.createSparkTokenClient(
31329
31171
  this.config.getCoordinatorAddress()
@@ -31395,54 +31237,6 @@ var TokenTransactionService = class {
31395
31237
  );
31396
31238
  }
31397
31239
  }
31398
- if (this.config.getTokenTransactionVersion() === "V0") {
31399
- return this.fetchOwnedTokenOutputsV0(params);
31400
- } else {
31401
- return this.fetchOwnedTokenOutputsV1(params);
31402
- }
31403
- }
31404
- async queryTokenTransactions(params) {
31405
- if (this.config.getTokenTransactionVersion() === "V0") {
31406
- return this.queryTokenTransactionsV0(params);
31407
- } else {
31408
- return this.queryTokenTransactionsV1(params);
31409
- }
31410
- }
31411
- async fetchOwnedTokenOutputsV0(params) {
31412
- const {
31413
- ownerPublicKeys,
31414
- issuerPublicKeys: tokenPublicKeys = [],
31415
- tokenIdentifiers = []
31416
- } = params;
31417
- const sparkClient = await this.connectionManager.createSparkClient(
31418
- this.config.getCoordinatorAddress()
31419
- );
31420
- try {
31421
- const result = await sparkClient.query_token_outputs({
31422
- ownerPublicKeys,
31423
- tokenPublicKeys,
31424
- tokenIdentifiers,
31425
- network: this.config.getNetworkProto()
31426
- });
31427
- return result.outputsWithPreviousTransactionData;
31428
- } catch (error) {
31429
- throw new NetworkError(
31430
- "Failed to fetch owned token outputs",
31431
- {
31432
- operation: "spark.query_token_outputs",
31433
- errorCount: 1,
31434
- errors: error instanceof Error ? error.message : String(error)
31435
- },
31436
- error
31437
- );
31438
- }
31439
- }
31440
- async fetchOwnedTokenOutputsV1(params) {
31441
- const {
31442
- ownerPublicKeys,
31443
- issuerPublicKeys = [],
31444
- tokenIdentifiers = []
31445
- } = params;
31446
31240
  const tokenClient = await this.connectionManager.createSparkTokenClient(
31447
31241
  this.config.getCoordinatorAddress()
31448
31242
  );
@@ -31483,75 +31277,7 @@ var TokenTransactionService = class {
31483
31277
  );
31484
31278
  }
31485
31279
  }
31486
- async queryTokenTransactionsV0(params) {
31487
- const {
31488
- ownerPublicKeys,
31489
- issuerPublicKeys,
31490
- tokenTransactionHashes,
31491
- tokenIdentifiers,
31492
- outputIds,
31493
- pageSize,
31494
- offset
31495
- } = params;
31496
- const sparkClient = await this.connectionManager.createSparkClient(
31497
- this.config.getCoordinatorAddress()
31498
- );
31499
- let queryParams = {
31500
- tokenPublicKeys: issuerPublicKeys?.map(import_utils20.hexToBytes),
31501
- ownerPublicKeys: ownerPublicKeys?.map(import_utils20.hexToBytes),
31502
- tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
31503
- const { tokenIdentifier } = decodeBech32mTokenIdentifier(
31504
- identifier,
31505
- this.config.getNetworkType()
31506
- );
31507
- return tokenIdentifier;
31508
- }),
31509
- tokenTransactionHashes: tokenTransactionHashes?.map(import_utils20.hexToBytes),
31510
- outputIds: outputIds || [],
31511
- limit: pageSize,
31512
- offset
31513
- };
31514
- try {
31515
- const response = await sparkClient.query_token_transactions(queryParams);
31516
- return {
31517
- tokenTransactionsWithStatus: response.tokenTransactionsWithStatus.map(
31518
- (tx) => {
31519
- const v1TokenTransaction = {
31520
- version: 1,
31521
- network: tx.tokenTransaction.network,
31522
- tokenInputs: tx.tokenTransaction.tokenInputs,
31523
- tokenOutputs: tx.tokenTransaction.tokenOutputs,
31524
- sparkOperatorIdentityPublicKeys: tx.tokenTransaction.sparkOperatorIdentityPublicKeys,
31525
- expiryTime: void 0,
31526
- // V0 doesn't have expiry time
31527
- clientCreatedTimestamp: tx.tokenTransaction?.tokenInputs?.$case === "mintInput" ? new Date(
31528
- tx.tokenTransaction.tokenInputs.mintInput.issuerProvidedTimestamp * 1e3
31529
- ) : /* @__PURE__ */ new Date(),
31530
- invoiceAttachments: []
31531
- };
31532
- return {
31533
- tokenTransaction: v1TokenTransaction,
31534
- status: tx.status,
31535
- confirmationMetadata: tx.confirmationMetadata,
31536
- tokenTransactionHash: tx.tokenTransactionHash
31537
- };
31538
- }
31539
- ),
31540
- offset: response.offset
31541
- };
31542
- } catch (error) {
31543
- throw new NetworkError(
31544
- "Failed to query token transactions",
31545
- {
31546
- operation: "spark.query_token_transactions",
31547
- errorCount: 1,
31548
- errors: error instanceof Error ? error.message : String(error)
31549
- },
31550
- error
31551
- );
31552
- }
31553
- }
31554
- async queryTokenTransactionsV1(params) {
31280
+ async queryTokenTransactions(params) {
31555
31281
  const {
31556
31282
  ownerPublicKeys,
31557
31283
  issuerPublicKeys,
@@ -31664,50 +31390,6 @@ var TokenTransactionService = class {
31664
31390
  });
31665
31391
  }
31666
31392
  }
31667
- async finalizeTokenTransaction(finalTokenTransaction, revocationSecrets, threshold) {
31668
- const signingOperators = this.config.getSigningOperators();
31669
- const soResponses = await Promise.allSettled(
31670
- Object.entries(signingOperators).map(async ([identifier, operator]) => {
31671
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
31672
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
31673
- try {
31674
- const response = await internalSparkClient.finalize_token_transaction(
31675
- {
31676
- finalTokenTransaction,
31677
- revocationSecrets,
31678
- identityPublicKey
31679
- },
31680
- {
31681
- retry: true,
31682
- retryableStatuses: [
31683
- "UNKNOWN",
31684
- "UNAVAILABLE",
31685
- "CANCELLED",
31686
- "INTERNAL"
31687
- ],
31688
- retryMaxAttempts: 3
31689
- }
31690
- );
31691
- return {
31692
- identifier,
31693
- response
31694
- };
31695
- } catch (error) {
31696
- throw new NetworkError(
31697
- "Failed to finalize token transaction",
31698
- {
31699
- operation: "finalize_token_transaction",
31700
- errorCount: 1,
31701
- errors: error instanceof Error ? error.message : String(error)
31702
- },
31703
- error
31704
- );
31705
- }
31706
- })
31707
- );
31708
- collectResponses(soResponses);
31709
- return finalTokenTransaction;
31710
- }
31711
31393
  async createSignaturesForOperators(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
31712
31394
  const inputTtxoSignaturesPerOperator = [];
31713
31395
  for (const [_, operator] of Object.entries(signingOperators)) {
@@ -31784,9 +31466,6 @@ var TokenTransactionService = class {
31784
31466
  return inputTtxoSignaturesPerOperator;
31785
31467
  }
31786
31468
  };
31787
- function isTokenTransaction(tokenTransaction) {
31788
- return "version" in tokenTransaction && "expiryTime" in tokenTransaction;
31789
- }
31790
31469
 
31791
31470
  // src/spark-wallet/spark-wallet.ts
31792
31471
  var import_sha213 = require("@noble/hashes/sha2");
@@ -31963,7 +31642,7 @@ var SigningService = class {
31963
31642
 
31964
31643
  // src/tests/utils/test-faucet.ts
31965
31644
  init_buffer();
31966
- var import_secp256k114 = require("@noble/curves/secp256k1");
31645
+ var import_secp256k112 = require("@noble/curves/secp256k1");
31967
31646
  var import_utils22 = require("@noble/curves/utils");
31968
31647
  var btc5 = __toESM(require("@scure/btc-signer"), 1);
31969
31648
  var import_btc_signer5 = require("@scure/btc-signer");
@@ -31984,7 +31663,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
31984
31663
  this.username = username;
31985
31664
  this.password = password;
31986
31665
  this.miningAddress = getP2TRAddressFromPublicKey(
31987
- import_secp256k114.secp256k1.getPublicKey(STATIC_MINING_KEY),
31666
+ import_secp256k112.secp256k1.getPublicKey(STATIC_MINING_KEY),
31988
31667
  4 /* LOCAL */
31989
31668
  );
31990
31669
  }
@@ -32023,7 +31702,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32023
31702
  });
32024
31703
  }
32025
31704
  async refill() {
32026
- const minerPubKey = import_secp256k114.secp256k1.getPublicKey(STATIC_MINING_KEY);
31705
+ const minerPubKey = import_secp256k112.secp256k1.getPublicKey(STATIC_MINING_KEY);
32027
31706
  const address2 = getP2TRAddressFromPublicKey(minerPubKey, 4 /* LOCAL */);
32028
31707
  const scanResult = await this.call("scantxoutset", [
32029
31708
  "start",
@@ -32072,7 +31751,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32072
31751
  txid: selectedUtxo.txid,
32073
31752
  index: selectedUtxo.vout
32074
31753
  });
32075
- const faucetPubKey = import_secp256k114.secp256k1.getPublicKey(STATIC_FAUCET_KEY);
31754
+ const faucetPubKey = import_secp256k112.secp256k1.getPublicKey(STATIC_FAUCET_KEY);
32076
31755
  const script = getP2TRScriptFromPublicKey(faucetPubKey, 4 /* LOCAL */);
32077
31756
  for (let i = 0; i < numCoinsToCreate; i++) {
32078
31757
  splitTx.addOutput({
@@ -32133,7 +31812,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32133
31812
  await this.broadcastTx((0, import_utils22.bytesToHex)(signedTx.extract()));
32134
31813
  }
32135
31814
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
32136
- const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
31815
+ const pubKey = import_secp256k112.secp256k1.getPublicKey(key);
32137
31816
  const internalKey = pubKey.slice(1);
32138
31817
  const script = getP2TRScriptFromPublicKey(pubKey, 4 /* LOCAL */);
32139
31818
  unsignedTx.updateInput(0, {
@@ -32153,7 +31832,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
32153
31832
  const tweakedKey = (0, import_utils23.taprootTweakPrivKey)(key, merkleRoot);
32154
31833
  if (!tweakedKey)
32155
31834
  throw new Error("Invalid private key for taproot tweaking");
32156
- const signature = import_secp256k114.schnorr.sign(sighash, tweakedKey);
31835
+ const signature = import_secp256k112.schnorr.sign(sighash, tweakedKey);
32157
31836
  unsignedTx.updateInput(0, {
32158
31837
  tapKeySig: signature
32159
31838
  });
@@ -32216,8 +31895,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
32216
31895
  return response;
32217
31896
  }
32218
31897
  async getNewAddress() {
32219
- const key = import_secp256k114.secp256k1.utils.randomPrivateKey();
32220
- const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
31898
+ const key = import_secp256k112.secp256k1.utils.randomPrivateKey();
31899
+ const pubKey = import_secp256k112.secp256k1.getPublicKey(key);
32221
31900
  return getP2TRAddressFromPublicKey(pubKey, 4 /* LOCAL */);
32222
31901
  }
32223
31902
  async sendToAddress(address2, amount, blocksToGenerate = 1) {
@@ -32238,8 +31917,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
32238
31917
  });
32239
31918
  const changeAmount = availableAmount - amount;
32240
31919
  if (changeAmount > 0) {
32241
- const changeKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
32242
- const changePubKey = import_secp256k114.secp256k1.getPublicKey(changeKey);
31920
+ const changeKey = import_secp256k112.secp256k1.utils.randomPrivateKey();
31921
+ const changePubKey = import_secp256k112.secp256k1.getPublicKey(changeKey);
32243
31922
  const changeScript = getP2TRScriptFromPublicKey(
32244
31923
  changePubKey,
32245
31924
  4 /* LOCAL */
@@ -32252,8 +31931,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
32252
31931
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
32253
31932
  const txHex = (0, import_utils22.bytesToHex)(signedTx.extract());
32254
31933
  await this.broadcastTx(txHex);
32255
- const randomKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
32256
- const randomPubKey = import_secp256k114.secp256k1.getPublicKey(randomKey);
31934
+ const randomKey = import_secp256k112.secp256k1.utils.randomPrivateKey();
31935
+ const randomPubKey = import_secp256k112.secp256k1.getPublicKey(randomKey);
32257
31936
  const randomAddress = getP2TRAddressFromPublicKey(
32258
31937
  randomPubKey,
32259
31938
  4 /* LOCAL */
@@ -32874,47 +32553,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32874
32553
  senderPublicKey,
32875
32554
  expiryTime
32876
32555
  }) {
32877
- const MAX_SATS_AMOUNT = 21e14;
32878
- if (amount && (amount < 0 || amount > MAX_SATS_AMOUNT)) {
32879
- throw new ValidationError(
32880
- `Amount must be between 0 and ${MAX_SATS_AMOUNT} sats`,
32881
- {
32882
- field: "amount",
32883
- value: amount,
32884
- expected: `less than or equal to ${MAX_SATS_AMOUNT}`
32885
- }
32886
- );
32887
- }
32888
- const protoPayment = {
32889
- $case: "satsPayment",
32890
- satsPayment: {
32891
- amount
32892
- }
32893
- };
32894
- const invoiceFields = {
32895
- version: 1,
32896
- id: (0, import_uuidv75.uuidv7obj)().bytes,
32897
- paymentType: protoPayment,
32898
- memo,
32899
- senderPublicKey: senderPublicKey ? (0, import_utils24.hexToBytes)(senderPublicKey) : void 0,
32900
- expiryTime: expiryTime ?? void 0
32901
- };
32902
- validateSparkInvoiceFields(invoiceFields);
32903
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
32904
- const hash = HashSparkInvoice(
32905
- invoiceFields,
32906
- identityPublicKey,
32907
- this.config.getNetworkType()
32908
- );
32909
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
32910
- return encodeSparkAddressWithSignature(
32911
- {
32912
- identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
32913
- network: this.config.getNetworkType(),
32914
- sparkInvoiceFields: invoiceFields
32915
- },
32916
- signature
32917
- );
32556
+ throw new NotImplementedError("Invoice functionality is not enabled");
32918
32557
  }
32919
32558
  /**
32920
32559
  * Creates a Spark invoice for a tokens payment on Spark.
@@ -32934,52 +32573,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32934
32573
  senderPublicKey,
32935
32574
  expiryTime
32936
32575
  }) {
32937
- const MAX_UINT128 = BigInt(2 ** 128 - 1);
32938
- if (amount && (amount < 0 || amount > MAX_UINT128)) {
32939
- throw new ValidationError(`Amount must be between 0 and ${MAX_UINT128}`, {
32940
- field: "amount",
32941
- value: amount,
32942
- expected: `greater than or equal to 0 and less than or equal to ${MAX_UINT128}`
32943
- });
32944
- }
32945
- let decodedTokenIdentifier = void 0;
32946
- if (tokenIdentifier) {
32947
- decodedTokenIdentifier = decodeBech32mTokenIdentifier(
32948
- tokenIdentifier,
32949
- this.config.getNetworkType()
32950
- ).tokenIdentifier;
32951
- }
32952
- const protoPayment = {
32953
- $case: "tokensPayment",
32954
- tokensPayment: {
32955
- tokenIdentifier: decodedTokenIdentifier ?? void 0,
32956
- amount: amount ? (0, import_utils24.numberToVarBytesBE)(amount) : void 0
32957
- }
32958
- };
32959
- const invoiceFields = {
32960
- version: 1,
32961
- id: (0, import_uuidv75.uuidv7obj)().bytes,
32962
- paymentType: protoPayment,
32963
- memo: memo ?? void 0,
32964
- senderPublicKey: senderPublicKey ? (0, import_utils24.hexToBytes)(senderPublicKey) : void 0,
32965
- expiryTime: expiryTime ?? void 0
32966
- };
32967
- validateSparkInvoiceFields(invoiceFields);
32968
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
32969
- const hash = HashSparkInvoice(
32970
- invoiceFields,
32971
- identityPublicKey,
32972
- this.config.getNetworkType()
32973
- );
32974
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
32975
- return encodeSparkAddressWithSignature(
32976
- {
32977
- identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
32978
- network: this.config.getNetworkType(),
32979
- sparkInvoiceFields: invoiceFields
32980
- },
32981
- signature
32982
- );
32576
+ throw new NotImplementedError("Invoice functionality is not enabled");
32983
32577
  }
32984
32578
  /**
32985
32579
  * Initializes the wallet using either a mnemonic phrase or a raw seed.
@@ -33304,7 +32898,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33304
32898
  }
33305
32899
  const sspClient = this.getSspClient();
33306
32900
  const cpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
33307
- import_secp256k115.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
32901
+ import_secp256k113.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
33308
32902
  );
33309
32903
  if (!cpfpAdaptorPubkey) {
33310
32904
  throw new Error("Failed to generate CPFP adaptor pubkey");
@@ -33312,13 +32906,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
33312
32906
  let directAdaptorPubkey;
33313
32907
  if (directAdaptorPrivateKey.length > 0) {
33314
32908
  directAdaptorPubkey = (0, import_utils24.bytesToHex)(
33315
- import_secp256k115.secp256k1.getPublicKey(directAdaptorPrivateKey)
32909
+ import_secp256k113.secp256k1.getPublicKey(directAdaptorPrivateKey)
33316
32910
  );
33317
32911
  }
33318
32912
  let directFromCpfpAdaptorPubkey;
33319
32913
  if (directFromCpfpAdaptorPrivateKey.length > 0) {
33320
32914
  directFromCpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
33321
- import_secp256k115.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
32915
+ import_secp256k113.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
33322
32916
  );
33323
32917
  }
33324
32918
  let request = null;
@@ -34933,10 +34527,23 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34933
34527
  if (!invoice2) {
34934
34528
  throw new Error("Failed to create lightning invoice");
34935
34529
  }
34530
+ const decodedInvoice = decodeInvoice(invoice2.invoice.encodedInvoice);
34531
+ if (invoice2.invoice.paymentHash !== (0, import_utils24.bytesToHex)(paymentHash) || decodedInvoice.paymentHash !== (0, import_utils24.bytesToHex)(paymentHash)) {
34532
+ throw new ValidationError("Payment hash mismatch", {
34533
+ field: "paymentHash",
34534
+ value: invoice2.invoice.paymentHash,
34535
+ expected: (0, import_utils24.bytesToHex)(paymentHash)
34536
+ });
34537
+ }
34538
+ if (decodedInvoice.amountMSats !== BigInt(amountSats2 * 1e3)) {
34539
+ throw new ValidationError("Amount mismatch", {
34540
+ field: "amountMSats",
34541
+ value: decodedInvoice.amountMSats,
34542
+ expected: amountSats2 * 1e3
34543
+ });
34544
+ }
34936
34545
  if (includeSparkAddress) {
34937
- const sparkFallbackAddress = decodeInvoice(
34938
- invoice2.invoice.encodedInvoice
34939
- ).fallbackAddress;
34546
+ const sparkFallbackAddress = decodedInvoice.fallbackAddress;
34940
34547
  if (!sparkFallbackAddress) {
34941
34548
  throw new ValidationError(
34942
34549
  "No spark fallback address found in lightning invoice",
@@ -34958,6 +34565,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
34958
34565
  }
34959
34566
  );
34960
34567
  }
34568
+ } else if (decodedInvoice.fallbackAddress !== void 0) {
34569
+ throw new ValidationError(
34570
+ "Spark fallback address found in lightning invoice but includeSparkAddress is false",
34571
+ {
34572
+ field: "sparkFallbackAddress",
34573
+ value: decodedInvoice.fallbackAddress
34574
+ }
34575
+ );
34961
34576
  }
34962
34577
  return invoice2;
34963
34578
  };
@@ -35125,91 +34740,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
35125
34740
  });
35126
34741
  }
35127
34742
  async fulfillSparkInvoice(sparkInvoices) {
35128
- if (!Array.isArray(sparkInvoices) || sparkInvoices.length === 0) {
35129
- throw new ValidationError("No Spark invoices provided", {
35130
- field: "sparkInvoices",
35131
- value: sparkInvoices,
35132
- expected: "Non-empty array"
35133
- });
35134
- }
35135
- const satsTransactionSuccess = [];
35136
- const satsTransactionErrors = [];
35137
- const tokenTransactionSuccess = [];
35138
- const tokenTransactionErrors = [];
35139
- const { satsInvoices, tokenInvoices, invalidInvoices } = await this.groupSparkInvoicesByPaymentType(sparkInvoices);
35140
- if (invalidInvoices.length > 0) {
35141
- return {
35142
- satsTransactionSuccess,
35143
- satsTransactionErrors,
35144
- tokenTransactionSuccess,
35145
- tokenTransactionErrors,
35146
- invalidInvoices
35147
- };
35148
- }
35149
- if (tokenInvoices.size > 0) {
35150
- await this.syncTokenOutputs();
35151
- const tokenTransferTasks = [];
35152
- for (const [identifierHex, decodedInvoices] of tokenInvoices.entries()) {
35153
- const tokenIdentifier = (0, import_utils24.hexToBytes)(identifierHex);
35154
- const tokenIdB32 = encodeBech32mTokenIdentifier({
35155
- tokenIdentifier,
35156
- network: this.config.getNetworkType()
35157
- });
35158
- const receiverOutputs = decodedInvoices.map((d) => ({
35159
- tokenIdentifier: tokenIdB32,
35160
- tokenAmount: d.amount,
35161
- receiverSparkAddress: d.invoice
35162
- }));
35163
- tokenTransferTasks.push(
35164
- this.tokenTransactionService.tokenTransfer({ tokenOutputs: this.tokenOutputs, receiverOutputs }).then((txid) => ({
35165
- ok: true,
35166
- tokenIdentifier: tokenIdB32,
35167
- txid
35168
- })).catch((e) => ({
35169
- ok: false,
35170
- tokenIdentifier: tokenIdB32,
35171
- error: e instanceof Error ? e : new Error(String(e))
35172
- }))
35173
- );
35174
- }
35175
- const results = await Promise.all(tokenTransferTasks);
35176
- for (const r of results) {
35177
- if (r.ok) {
35178
- tokenTransactionSuccess.push({
35179
- tokenIdentifier: r.tokenIdentifier,
35180
- txid: r.txid
35181
- });
35182
- } else {
35183
- tokenTransactionErrors.push({
35184
- tokenIdentifier: r.tokenIdentifier,
35185
- error: r.error
35186
- });
35187
- }
35188
- }
35189
- }
35190
- if (satsInvoices.length > 0) {
35191
- const transfers = await this.transferWithInvoice(satsInvoices);
35192
- for (const transfer of transfers) {
35193
- if (transfer.ok) {
35194
- satsTransactionSuccess.push({
35195
- invoice: transfer.param.sparkInvoice ?? "",
35196
- transferResponse: transfer.transfer
35197
- });
35198
- } else {
35199
- satsTransactionErrors.push({
35200
- invoice: transfer.param.sparkInvoice ?? "",
35201
- error: transfer.error
35202
- });
35203
- }
35204
- }
35205
- }
35206
- return {
35207
- satsTransactionSuccess,
35208
- satsTransactionErrors,
35209
- tokenTransactionSuccess,
35210
- tokenTransactionErrors,
35211
- invalidInvoices
35212
- };
34743
+ throw new NotImplementedError("Invoice functionality is not enabled");
35213
34744
  }
35214
34745
  async groupSparkInvoicesByPaymentType(sparkInvoices) {
35215
34746
  const satsInvoices = [];
@@ -35346,6 +34877,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
35346
34877
  });
35347
34878
  return { satsInvoices, tokenInvoices, invalidInvoices };
35348
34879
  }
34880
+ async querySparkInvoices(invoices) {
34881
+ throw new NotImplementedError("Invoice functionality is not enabled");
34882
+ }
35349
34883
  /**
35350
34884
  * Gets fee estimate for sending Lightning payments.
35351
34885
  *
@@ -36393,6 +35927,7 @@ setCrypto(globalThis.crypto);
36393
35927
  addPublicKeys,
36394
35928
  applyAdaptorToSignature,
36395
35929
  applyAdditiveTweakToPublicKey,
35930
+ assertBech32,
36396
35931
  bech32mDecode,
36397
35932
  bigIntToPrivateKey,
36398
35933
  checkIfSelectedOutputsAreAvailable,
@@ -36455,6 +35990,7 @@ setCrypto(globalThis.crypto);
36455
35990
  getTxId,
36456
35991
  getTxIdNoReverse,
36457
35992
  isEphemeralAnchorOutput,
35993
+ isLegacySparkAddress,
36458
35994
  isSafeForNumber,
36459
35995
  isTxBroadcast,
36460
35996
  isValidPublicKey,