@buildonspark/spark-sdk 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/bare/index.cjs +945 -1401
  3. package/dist/bare/index.d.cts +128 -10
  4. package/dist/bare/index.d.ts +128 -10
  5. package/dist/bare/index.js +940 -1399
  6. package/dist/{chunk-55XNR6DM.js → chunk-DIXXHATX.js} +1 -1
  7. package/dist/{chunk-MGCUXELA.js → chunk-IC4IUEOS.js} +931 -125
  8. package/dist/{chunk-MH7BMOLL.js → chunk-J2P3KTQP.js} +1 -1
  9. package/dist/{chunk-SXXM52XH.js → chunk-JE73HB26.js} +409 -1656
  10. package/dist/{chunk-73GJOG5R.js → chunk-XWLR6G5C.js} +1 -1
  11. package/dist/{client-DrjQwET9.d.ts → client-DBZ43pJT.d.ts} +1 -1
  12. package/dist/{client-DUFejFfn.d.cts → client-DWml6sjL.d.cts} +1 -1
  13. package/dist/debug.cjs +949 -1403
  14. package/dist/debug.d.cts +8 -5
  15. package/dist/debug.d.ts +8 -5
  16. package/dist/debug.js +4 -4
  17. package/dist/graphql/objects/index.d.cts +3 -3
  18. package/dist/graphql/objects/index.d.ts +3 -3
  19. package/dist/index.cjs +905 -1362
  20. package/dist/index.d.cts +6 -6
  21. package/dist/index.d.ts +6 -6
  22. package/dist/index.js +9 -5
  23. package/dist/index.node.cjs +905 -1362
  24. package/dist/index.node.d.cts +6 -6
  25. package/dist/index.node.d.ts +6 -6
  26. package/dist/index.node.js +8 -4
  27. package/dist/{logging-CGeEoKYd.d.cts → logging-BUpzk4Z6.d.cts} +3 -3
  28. package/dist/{logging-DpSsvFVM.d.ts → logging-Dt2ooQiP.d.ts} +3 -3
  29. package/dist/native/index.cjs +905 -1362
  30. package/dist/native/index.d.cts +129 -25
  31. package/dist/native/index.d.ts +129 -25
  32. package/dist/native/index.js +904 -1363
  33. package/dist/proto/spark.cjs +931 -125
  34. package/dist/proto/spark.d.cts +1 -1
  35. package/dist/proto/spark.d.ts +1 -1
  36. package/dist/proto/spark.js +17 -1
  37. package/dist/proto/spark_token.d.cts +1 -1
  38. package/dist/proto/spark_token.d.ts +1 -1
  39. package/dist/proto/spark_token.js +2 -2
  40. package/dist/{spark-CLz4-Ln8.d.cts → spark-DasxuVfm.d.cts} +150 -5
  41. package/dist/{spark-CLz4-Ln8.d.ts → spark-DasxuVfm.d.ts} +150 -5
  42. package/dist/{spark-wallet-BVBrWYKL.d.cts → spark-wallet-BoMIOPWW.d.cts} +13 -9
  43. package/dist/{spark-wallet-CFPm6wZs.d.ts → spark-wallet-jlC0XN5f.d.ts} +13 -9
  44. package/dist/{spark-wallet.node-e1gncoIZ.d.ts → spark-wallet.node-07PksUHH.d.cts} +1 -1
  45. package/dist/{spark-wallet.node-B_00X-1j.d.cts → spark-wallet.node-CdWkKMSq.d.ts} +1 -1
  46. package/dist/tests/test-utils.cjs +947 -144
  47. package/dist/tests/test-utils.d.cts +4 -4
  48. package/dist/tests/test-utils.d.ts +4 -4
  49. package/dist/tests/test-utils.js +5 -5
  50. package/dist/{token-transactions-BkAqlmY6.d.ts → token-transactions-BDzCrQSk.d.cts} +5 -19
  51. package/dist/{token-transactions-BZGtwFFM.d.cts → token-transactions-DscJaJOE.d.ts} +5 -19
  52. package/dist/types/index.cjs +923 -125
  53. package/dist/types/index.d.cts +2 -2
  54. package/dist/types/index.d.ts +2 -2
  55. package/dist/types/index.js +2 -2
  56. package/package.json +1 -1
  57. package/src/proto/spark.ts +1167 -103
  58. package/src/services/config.ts +0 -4
  59. package/src/services/token-transactions.ts +11 -703
  60. package/src/services/wallet-config.ts +0 -2
  61. package/src/spark-wallet/proto-descriptors.ts +1 -1
  62. package/src/spark-wallet/spark-wallet.ts +58 -215
  63. package/src/spark_descriptors.pb +0 -0
  64. package/src/tests/address.test.ts +141 -0
  65. package/src/tests/integration/address.test.ts +4 -0
  66. package/src/tests/integration/lightning.test.ts +14 -9
  67. package/src/tests/integration/token-output.test.ts +0 -1
  68. package/src/tests/integration/transfer.test.ts +108 -2
  69. package/src/tests/token-hashing.test.ts +0 -247
  70. package/src/utils/address.ts +58 -35
  71. package/src/utils/token-hashing.ts +1 -420
  72. package/src/utils/token-transaction-validation.ts +0 -330
@@ -162,19 +162,18 @@ var NotImplementedError = class extends SparkSDKError {
162
162
 
163
163
  // src/spark-wallet/spark-wallet.ts
164
164
  import { isNode as isNode3, isObject as isObject10, mapCurrencyAmount } from "@lightsparkdev/core";
165
- import { secp256k1 as secp256k114 } from "@noble/curves/secp256k1";
165
+ import { secp256k1 as secp256k112 } from "@noble/curves/secp256k1";
166
166
  import {
167
167
  bytesToHex as bytesToHex11,
168
168
  bytesToNumberBE as bytesToNumberBE8,
169
169
  equalBytes as equalBytes6,
170
- hexToBytes as hexToBytes11,
171
- numberToVarBytesBE
170
+ hexToBytes as hexToBytes11
172
171
  } from "@noble/curves/utils";
173
172
  import { validateMnemonic } from "@scure/bip39";
174
173
  import { wordlist as wordlist2 } from "@scure/bip39/wordlists/english";
175
174
  import { Address as Address4, OutScript as OutScript3, Transaction as Transaction7 } from "@scure/btc-signer";
176
175
  import { Mutex } from "async-mutex";
177
- import { uuidv7 as uuidv74, uuidv7obj } from "uuidv7";
176
+ import { uuidv7 as uuidv74 } from "uuidv7";
178
177
 
179
178
  // src/graphql/client.ts
180
179
  import {
@@ -2784,9 +2783,9 @@ function invoiceStatusFromJSON(object) {
2784
2783
  case 2:
2785
2784
  case "FINALIZED":
2786
2785
  return 2 /* FINALIZED */;
2787
- case 3:
2788
- case "EXPIRED":
2789
- return 3 /* EXPIRED */;
2786
+ case 4:
2787
+ case "RETURNED":
2788
+ return 4 /* RETURNED */;
2790
2789
  case -1:
2791
2790
  case "UNRECOGNIZED":
2792
2791
  default:
@@ -2801,8 +2800,8 @@ function invoiceStatusToJSON(object) {
2801
2800
  return "PENDING";
2802
2801
  case 2 /* FINALIZED */:
2803
2802
  return "FINALIZED";
2804
- case 3 /* EXPIRED */:
2805
- return "EXPIRED";
2803
+ case 4 /* RETURNED */:
2804
+ return "RETURNED";
2806
2805
  case -1 /* UNRECOGNIZED */:
2807
2806
  default:
2808
2807
  return "UNRECOGNIZED";
@@ -4606,6 +4605,626 @@ var SigningResult_SignatureSharesEntry = {
4606
4605
  return message;
4607
4606
  }
4608
4607
  };
4608
+ function createBaseRenewLeafRequest() {
4609
+ return { leafId: "", ownerIdentityPublicKey: new Uint8Array(0), signingJobs: void 0 };
4610
+ }
4611
+ var RenewLeafRequest = {
4612
+ encode(message, writer = new BinaryWriter4()) {
4613
+ if (message.leafId !== "") {
4614
+ writer.uint32(10).string(message.leafId);
4615
+ }
4616
+ if (message.ownerIdentityPublicKey.length !== 0) {
4617
+ writer.uint32(18).bytes(message.ownerIdentityPublicKey);
4618
+ }
4619
+ switch (message.signingJobs?.$case) {
4620
+ case "renewNodeTimelockSigningJob":
4621
+ RenewNodeTimelockSigningJob.encode(message.signingJobs.renewNodeTimelockSigningJob, writer.uint32(26).fork()).join();
4622
+ break;
4623
+ case "renewRefundTimelockSigningJob":
4624
+ RenewRefundTimelockSigningJob.encode(
4625
+ message.signingJobs.renewRefundTimelockSigningJob,
4626
+ writer.uint32(34).fork()
4627
+ ).join();
4628
+ break;
4629
+ }
4630
+ return writer;
4631
+ },
4632
+ decode(input, length) {
4633
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
4634
+ const end = length === void 0 ? reader.len : reader.pos + length;
4635
+ const message = createBaseRenewLeafRequest();
4636
+ while (reader.pos < end) {
4637
+ const tag = reader.uint32();
4638
+ switch (tag >>> 3) {
4639
+ case 1: {
4640
+ if (tag !== 10) {
4641
+ break;
4642
+ }
4643
+ message.leafId = reader.string();
4644
+ continue;
4645
+ }
4646
+ case 2: {
4647
+ if (tag !== 18) {
4648
+ break;
4649
+ }
4650
+ message.ownerIdentityPublicKey = reader.bytes();
4651
+ continue;
4652
+ }
4653
+ case 3: {
4654
+ if (tag !== 26) {
4655
+ break;
4656
+ }
4657
+ message.signingJobs = {
4658
+ $case: "renewNodeTimelockSigningJob",
4659
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.decode(reader, reader.uint32())
4660
+ };
4661
+ continue;
4662
+ }
4663
+ case 4: {
4664
+ if (tag !== 34) {
4665
+ break;
4666
+ }
4667
+ message.signingJobs = {
4668
+ $case: "renewRefundTimelockSigningJob",
4669
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.decode(reader, reader.uint32())
4670
+ };
4671
+ continue;
4672
+ }
4673
+ }
4674
+ if ((tag & 7) === 4 || tag === 0) {
4675
+ break;
4676
+ }
4677
+ reader.skip(tag & 7);
4678
+ }
4679
+ return message;
4680
+ },
4681
+ fromJSON(object) {
4682
+ return {
4683
+ leafId: isSet3(object.leafId) ? globalThis.String(object.leafId) : "",
4684
+ ownerIdentityPublicKey: isSet3(object.ownerIdentityPublicKey) ? bytesFromBase642(object.ownerIdentityPublicKey) : new Uint8Array(0),
4685
+ signingJobs: isSet3(object.renewNodeTimelockSigningJob) ? {
4686
+ $case: "renewNodeTimelockSigningJob",
4687
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromJSON(object.renewNodeTimelockSigningJob)
4688
+ } : isSet3(object.renewRefundTimelockSigningJob) ? {
4689
+ $case: "renewRefundTimelockSigningJob",
4690
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromJSON(object.renewRefundTimelockSigningJob)
4691
+ } : void 0
4692
+ };
4693
+ },
4694
+ toJSON(message) {
4695
+ const obj = {};
4696
+ if (message.leafId !== "") {
4697
+ obj.leafId = message.leafId;
4698
+ }
4699
+ if (message.ownerIdentityPublicKey.length !== 0) {
4700
+ obj.ownerIdentityPublicKey = base64FromBytes2(message.ownerIdentityPublicKey);
4701
+ }
4702
+ if (message.signingJobs?.$case === "renewNodeTimelockSigningJob") {
4703
+ obj.renewNodeTimelockSigningJob = RenewNodeTimelockSigningJob.toJSON(
4704
+ message.signingJobs.renewNodeTimelockSigningJob
4705
+ );
4706
+ } else if (message.signingJobs?.$case === "renewRefundTimelockSigningJob") {
4707
+ obj.renewRefundTimelockSigningJob = RenewRefundTimelockSigningJob.toJSON(
4708
+ message.signingJobs.renewRefundTimelockSigningJob
4709
+ );
4710
+ }
4711
+ return obj;
4712
+ },
4713
+ create(base) {
4714
+ return RenewLeafRequest.fromPartial(base ?? {});
4715
+ },
4716
+ fromPartial(object) {
4717
+ const message = createBaseRenewLeafRequest();
4718
+ message.leafId = object.leafId ?? "";
4719
+ message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
4720
+ switch (object.signingJobs?.$case) {
4721
+ case "renewNodeTimelockSigningJob": {
4722
+ if (object.signingJobs?.renewNodeTimelockSigningJob !== void 0 && object.signingJobs?.renewNodeTimelockSigningJob !== null) {
4723
+ message.signingJobs = {
4724
+ $case: "renewNodeTimelockSigningJob",
4725
+ renewNodeTimelockSigningJob: RenewNodeTimelockSigningJob.fromPartial(
4726
+ object.signingJobs.renewNodeTimelockSigningJob
4727
+ )
4728
+ };
4729
+ }
4730
+ break;
4731
+ }
4732
+ case "renewRefundTimelockSigningJob": {
4733
+ if (object.signingJobs?.renewRefundTimelockSigningJob !== void 0 && object.signingJobs?.renewRefundTimelockSigningJob !== null) {
4734
+ message.signingJobs = {
4735
+ $case: "renewRefundTimelockSigningJob",
4736
+ renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob.fromPartial(
4737
+ object.signingJobs.renewRefundTimelockSigningJob
4738
+ )
4739
+ };
4740
+ }
4741
+ break;
4742
+ }
4743
+ }
4744
+ return message;
4745
+ }
4746
+ };
4747
+ function createBaseRenewNodeTimelockSigningJob() {
4748
+ return {
4749
+ splitNodeTxSigningJob: void 0,
4750
+ splitNodeDirectTxSigningJob: void 0,
4751
+ nodeTxSigningJob: void 0,
4752
+ refundTxSigningJob: void 0,
4753
+ directNodeTxSigningJob: void 0,
4754
+ directRefundTxSigningJob: void 0,
4755
+ directFromCpfpRefundTxSigningJob: void 0
4756
+ };
4757
+ }
4758
+ var RenewNodeTimelockSigningJob = {
4759
+ encode(message, writer = new BinaryWriter4()) {
4760
+ if (message.splitNodeTxSigningJob !== void 0) {
4761
+ UserSignedTxSigningJob.encode(message.splitNodeTxSigningJob, writer.uint32(10).fork()).join();
4762
+ }
4763
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
4764
+ UserSignedTxSigningJob.encode(message.splitNodeDirectTxSigningJob, writer.uint32(18).fork()).join();
4765
+ }
4766
+ if (message.nodeTxSigningJob !== void 0) {
4767
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(26).fork()).join();
4768
+ }
4769
+ if (message.refundTxSigningJob !== void 0) {
4770
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(34).fork()).join();
4771
+ }
4772
+ if (message.directNodeTxSigningJob !== void 0) {
4773
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(42).fork()).join();
4774
+ }
4775
+ if (message.directRefundTxSigningJob !== void 0) {
4776
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(50).fork()).join();
4777
+ }
4778
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4779
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(58).fork()).join();
4780
+ }
4781
+ return writer;
4782
+ },
4783
+ decode(input, length) {
4784
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
4785
+ const end = length === void 0 ? reader.len : reader.pos + length;
4786
+ const message = createBaseRenewNodeTimelockSigningJob();
4787
+ while (reader.pos < end) {
4788
+ const tag = reader.uint32();
4789
+ switch (tag >>> 3) {
4790
+ case 1: {
4791
+ if (tag !== 10) {
4792
+ break;
4793
+ }
4794
+ message.splitNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4795
+ continue;
4796
+ }
4797
+ case 2: {
4798
+ if (tag !== 18) {
4799
+ break;
4800
+ }
4801
+ message.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4802
+ continue;
4803
+ }
4804
+ case 3: {
4805
+ if (tag !== 26) {
4806
+ break;
4807
+ }
4808
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4809
+ continue;
4810
+ }
4811
+ case 4: {
4812
+ if (tag !== 34) {
4813
+ break;
4814
+ }
4815
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4816
+ continue;
4817
+ }
4818
+ case 5: {
4819
+ if (tag !== 42) {
4820
+ break;
4821
+ }
4822
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4823
+ continue;
4824
+ }
4825
+ case 6: {
4826
+ if (tag !== 50) {
4827
+ break;
4828
+ }
4829
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4830
+ continue;
4831
+ }
4832
+ case 7: {
4833
+ if (tag !== 58) {
4834
+ break;
4835
+ }
4836
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4837
+ continue;
4838
+ }
4839
+ }
4840
+ if ((tag & 7) === 4 || tag === 0) {
4841
+ break;
4842
+ }
4843
+ reader.skip(tag & 7);
4844
+ }
4845
+ return message;
4846
+ },
4847
+ fromJSON(object) {
4848
+ return {
4849
+ splitNodeTxSigningJob: isSet3(object.splitNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeTxSigningJob) : void 0,
4850
+ splitNodeDirectTxSigningJob: isSet3(object.splitNodeDirectTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.splitNodeDirectTxSigningJob) : void 0,
4851
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
4852
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
4853
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
4854
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
4855
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
4856
+ };
4857
+ },
4858
+ toJSON(message) {
4859
+ const obj = {};
4860
+ if (message.splitNodeTxSigningJob !== void 0) {
4861
+ obj.splitNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeTxSigningJob);
4862
+ }
4863
+ if (message.splitNodeDirectTxSigningJob !== void 0) {
4864
+ obj.splitNodeDirectTxSigningJob = UserSignedTxSigningJob.toJSON(message.splitNodeDirectTxSigningJob);
4865
+ }
4866
+ if (message.nodeTxSigningJob !== void 0) {
4867
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
4868
+ }
4869
+ if (message.refundTxSigningJob !== void 0) {
4870
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
4871
+ }
4872
+ if (message.directNodeTxSigningJob !== void 0) {
4873
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
4874
+ }
4875
+ if (message.directRefundTxSigningJob !== void 0) {
4876
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
4877
+ }
4878
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4879
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
4880
+ }
4881
+ return obj;
4882
+ },
4883
+ create(base) {
4884
+ return RenewNodeTimelockSigningJob.fromPartial(base ?? {});
4885
+ },
4886
+ fromPartial(object) {
4887
+ const message = createBaseRenewNodeTimelockSigningJob();
4888
+ message.splitNodeTxSigningJob = object.splitNodeTxSigningJob !== void 0 && object.splitNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeTxSigningJob) : void 0;
4889
+ message.splitNodeDirectTxSigningJob = object.splitNodeDirectTxSigningJob !== void 0 && object.splitNodeDirectTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.splitNodeDirectTxSigningJob) : void 0;
4890
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
4891
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
4892
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
4893
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
4894
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
4895
+ return message;
4896
+ }
4897
+ };
4898
+ function createBaseRenewRefundTimelockSigningJob() {
4899
+ return {
4900
+ nodeTxSigningJob: void 0,
4901
+ refundTxSigningJob: void 0,
4902
+ directNodeTxSigningJob: void 0,
4903
+ directRefundTxSigningJob: void 0,
4904
+ directFromCpfpRefundTxSigningJob: void 0
4905
+ };
4906
+ }
4907
+ var RenewRefundTimelockSigningJob = {
4908
+ encode(message, writer = new BinaryWriter4()) {
4909
+ if (message.nodeTxSigningJob !== void 0) {
4910
+ UserSignedTxSigningJob.encode(message.nodeTxSigningJob, writer.uint32(10).fork()).join();
4911
+ }
4912
+ if (message.refundTxSigningJob !== void 0) {
4913
+ UserSignedTxSigningJob.encode(message.refundTxSigningJob, writer.uint32(18).fork()).join();
4914
+ }
4915
+ if (message.directNodeTxSigningJob !== void 0) {
4916
+ UserSignedTxSigningJob.encode(message.directNodeTxSigningJob, writer.uint32(26).fork()).join();
4917
+ }
4918
+ if (message.directRefundTxSigningJob !== void 0) {
4919
+ UserSignedTxSigningJob.encode(message.directRefundTxSigningJob, writer.uint32(34).fork()).join();
4920
+ }
4921
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
4922
+ UserSignedTxSigningJob.encode(message.directFromCpfpRefundTxSigningJob, writer.uint32(42).fork()).join();
4923
+ }
4924
+ return writer;
4925
+ },
4926
+ decode(input, length) {
4927
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
4928
+ const end = length === void 0 ? reader.len : reader.pos + length;
4929
+ const message = createBaseRenewRefundTimelockSigningJob();
4930
+ while (reader.pos < end) {
4931
+ const tag = reader.uint32();
4932
+ switch (tag >>> 3) {
4933
+ case 1: {
4934
+ if (tag !== 10) {
4935
+ break;
4936
+ }
4937
+ message.nodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4938
+ continue;
4939
+ }
4940
+ case 2: {
4941
+ if (tag !== 18) {
4942
+ break;
4943
+ }
4944
+ message.refundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4945
+ continue;
4946
+ }
4947
+ case 3: {
4948
+ if (tag !== 26) {
4949
+ break;
4950
+ }
4951
+ message.directNodeTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4952
+ continue;
4953
+ }
4954
+ case 4: {
4955
+ if (tag !== 34) {
4956
+ break;
4957
+ }
4958
+ message.directRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4959
+ continue;
4960
+ }
4961
+ case 5: {
4962
+ if (tag !== 42) {
4963
+ break;
4964
+ }
4965
+ message.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.decode(reader, reader.uint32());
4966
+ continue;
4967
+ }
4968
+ }
4969
+ if ((tag & 7) === 4 || tag === 0) {
4970
+ break;
4971
+ }
4972
+ reader.skip(tag & 7);
4973
+ }
4974
+ return message;
4975
+ },
4976
+ fromJSON(object) {
4977
+ return {
4978
+ nodeTxSigningJob: isSet3(object.nodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.nodeTxSigningJob) : void 0,
4979
+ refundTxSigningJob: isSet3(object.refundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.refundTxSigningJob) : void 0,
4980
+ directNodeTxSigningJob: isSet3(object.directNodeTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directNodeTxSigningJob) : void 0,
4981
+ directRefundTxSigningJob: isSet3(object.directRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directRefundTxSigningJob) : void 0,
4982
+ directFromCpfpRefundTxSigningJob: isSet3(object.directFromCpfpRefundTxSigningJob) ? UserSignedTxSigningJob.fromJSON(object.directFromCpfpRefundTxSigningJob) : void 0
4983
+ };
4984
+ },
4985
+ toJSON(message) {
4986
+ const obj = {};
4987
+ if (message.nodeTxSigningJob !== void 0) {
4988
+ obj.nodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.nodeTxSigningJob);
4989
+ }
4990
+ if (message.refundTxSigningJob !== void 0) {
4991
+ obj.refundTxSigningJob = UserSignedTxSigningJob.toJSON(message.refundTxSigningJob);
4992
+ }
4993
+ if (message.directNodeTxSigningJob !== void 0) {
4994
+ obj.directNodeTxSigningJob = UserSignedTxSigningJob.toJSON(message.directNodeTxSigningJob);
4995
+ }
4996
+ if (message.directRefundTxSigningJob !== void 0) {
4997
+ obj.directRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directRefundTxSigningJob);
4998
+ }
4999
+ if (message.directFromCpfpRefundTxSigningJob !== void 0) {
5000
+ obj.directFromCpfpRefundTxSigningJob = UserSignedTxSigningJob.toJSON(message.directFromCpfpRefundTxSigningJob);
5001
+ }
5002
+ return obj;
5003
+ },
5004
+ create(base) {
5005
+ return RenewRefundTimelockSigningJob.fromPartial(base ?? {});
5006
+ },
5007
+ fromPartial(object) {
5008
+ const message = createBaseRenewRefundTimelockSigningJob();
5009
+ message.nodeTxSigningJob = object.nodeTxSigningJob !== void 0 && object.nodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.nodeTxSigningJob) : void 0;
5010
+ message.refundTxSigningJob = object.refundTxSigningJob !== void 0 && object.refundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.refundTxSigningJob) : void 0;
5011
+ message.directNodeTxSigningJob = object.directNodeTxSigningJob !== void 0 && object.directNodeTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directNodeTxSigningJob) : void 0;
5012
+ message.directRefundTxSigningJob = object.directRefundTxSigningJob !== void 0 && object.directRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directRefundTxSigningJob) : void 0;
5013
+ message.directFromCpfpRefundTxSigningJob = object.directFromCpfpRefundTxSigningJob !== void 0 && object.directFromCpfpRefundTxSigningJob !== null ? UserSignedTxSigningJob.fromPartial(object.directFromCpfpRefundTxSigningJob) : void 0;
5014
+ return message;
5015
+ }
5016
+ };
5017
+ function createBaseRenewLeafResponse() {
5018
+ return { renewResult: void 0 };
5019
+ }
5020
+ var RenewLeafResponse = {
5021
+ encode(message, writer = new BinaryWriter4()) {
5022
+ switch (message.renewResult?.$case) {
5023
+ case "extendResult":
5024
+ RenewNodeTimelockResult.encode(message.renewResult.extendResult, writer.uint32(10).fork()).join();
5025
+ break;
5026
+ case "refreshResult":
5027
+ RenewRefundTimelockResult.encode(message.renewResult.refreshResult, writer.uint32(18).fork()).join();
5028
+ break;
5029
+ }
5030
+ return writer;
5031
+ },
5032
+ decode(input, length) {
5033
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
5034
+ const end = length === void 0 ? reader.len : reader.pos + length;
5035
+ const message = createBaseRenewLeafResponse();
5036
+ while (reader.pos < end) {
5037
+ const tag = reader.uint32();
5038
+ switch (tag >>> 3) {
5039
+ case 1: {
5040
+ if (tag !== 10) {
5041
+ break;
5042
+ }
5043
+ message.renewResult = {
5044
+ $case: "extendResult",
5045
+ extendResult: RenewNodeTimelockResult.decode(reader, reader.uint32())
5046
+ };
5047
+ continue;
5048
+ }
5049
+ case 2: {
5050
+ if (tag !== 18) {
5051
+ break;
5052
+ }
5053
+ message.renewResult = {
5054
+ $case: "refreshResult",
5055
+ refreshResult: RenewRefundTimelockResult.decode(reader, reader.uint32())
5056
+ };
5057
+ continue;
5058
+ }
5059
+ }
5060
+ if ((tag & 7) === 4 || tag === 0) {
5061
+ break;
5062
+ }
5063
+ reader.skip(tag & 7);
5064
+ }
5065
+ return message;
5066
+ },
5067
+ fromJSON(object) {
5068
+ return {
5069
+ renewResult: isSet3(object.extendResult) ? { $case: "extendResult", extendResult: RenewNodeTimelockResult.fromJSON(object.extendResult) } : isSet3(object.refreshResult) ? { $case: "refreshResult", refreshResult: RenewRefundTimelockResult.fromJSON(object.refreshResult) } : void 0
5070
+ };
5071
+ },
5072
+ toJSON(message) {
5073
+ const obj = {};
5074
+ if (message.renewResult?.$case === "extendResult") {
5075
+ obj.extendResult = RenewNodeTimelockResult.toJSON(message.renewResult.extendResult);
5076
+ } else if (message.renewResult?.$case === "refreshResult") {
5077
+ obj.refreshResult = RenewRefundTimelockResult.toJSON(message.renewResult.refreshResult);
5078
+ }
5079
+ return obj;
5080
+ },
5081
+ create(base) {
5082
+ return RenewLeafResponse.fromPartial(base ?? {});
5083
+ },
5084
+ fromPartial(object) {
5085
+ const message = createBaseRenewLeafResponse();
5086
+ switch (object.renewResult?.$case) {
5087
+ case "extendResult": {
5088
+ if (object.renewResult?.extendResult !== void 0 && object.renewResult?.extendResult !== null) {
5089
+ message.renewResult = {
5090
+ $case: "extendResult",
5091
+ extendResult: RenewNodeTimelockResult.fromPartial(object.renewResult.extendResult)
5092
+ };
5093
+ }
5094
+ break;
5095
+ }
5096
+ case "refreshResult": {
5097
+ if (object.renewResult?.refreshResult !== void 0 && object.renewResult?.refreshResult !== null) {
5098
+ message.renewResult = {
5099
+ $case: "refreshResult",
5100
+ refreshResult: RenewRefundTimelockResult.fromPartial(object.renewResult.refreshResult)
5101
+ };
5102
+ }
5103
+ break;
5104
+ }
5105
+ }
5106
+ return message;
5107
+ }
5108
+ };
5109
+ function createBaseRenewNodeTimelockResult() {
5110
+ return { splitNode: void 0, node: void 0 };
5111
+ }
5112
+ var RenewNodeTimelockResult = {
5113
+ encode(message, writer = new BinaryWriter4()) {
5114
+ if (message.splitNode !== void 0) {
5115
+ TreeNode.encode(message.splitNode, writer.uint32(10).fork()).join();
5116
+ }
5117
+ if (message.node !== void 0) {
5118
+ TreeNode.encode(message.node, writer.uint32(18).fork()).join();
5119
+ }
5120
+ return writer;
5121
+ },
5122
+ decode(input, length) {
5123
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
5124
+ const end = length === void 0 ? reader.len : reader.pos + length;
5125
+ const message = createBaseRenewNodeTimelockResult();
5126
+ while (reader.pos < end) {
5127
+ const tag = reader.uint32();
5128
+ switch (tag >>> 3) {
5129
+ case 1: {
5130
+ if (tag !== 10) {
5131
+ break;
5132
+ }
5133
+ message.splitNode = TreeNode.decode(reader, reader.uint32());
5134
+ continue;
5135
+ }
5136
+ case 2: {
5137
+ if (tag !== 18) {
5138
+ break;
5139
+ }
5140
+ message.node = TreeNode.decode(reader, reader.uint32());
5141
+ continue;
5142
+ }
5143
+ }
5144
+ if ((tag & 7) === 4 || tag === 0) {
5145
+ break;
5146
+ }
5147
+ reader.skip(tag & 7);
5148
+ }
5149
+ return message;
5150
+ },
5151
+ fromJSON(object) {
5152
+ return {
5153
+ splitNode: isSet3(object.splitNode) ? TreeNode.fromJSON(object.splitNode) : void 0,
5154
+ node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0
5155
+ };
5156
+ },
5157
+ toJSON(message) {
5158
+ const obj = {};
5159
+ if (message.splitNode !== void 0) {
5160
+ obj.splitNode = TreeNode.toJSON(message.splitNode);
5161
+ }
5162
+ if (message.node !== void 0) {
5163
+ obj.node = TreeNode.toJSON(message.node);
5164
+ }
5165
+ return obj;
5166
+ },
5167
+ create(base) {
5168
+ return RenewNodeTimelockResult.fromPartial(base ?? {});
5169
+ },
5170
+ fromPartial(object) {
5171
+ const message = createBaseRenewNodeTimelockResult();
5172
+ message.splitNode = object.splitNode !== void 0 && object.splitNode !== null ? TreeNode.fromPartial(object.splitNode) : void 0;
5173
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
5174
+ return message;
5175
+ }
5176
+ };
5177
+ function createBaseRenewRefundTimelockResult() {
5178
+ return { node: void 0 };
5179
+ }
5180
+ var RenewRefundTimelockResult = {
5181
+ encode(message, writer = new BinaryWriter4()) {
5182
+ if (message.node !== void 0) {
5183
+ TreeNode.encode(message.node, writer.uint32(10).fork()).join();
5184
+ }
5185
+ return writer;
5186
+ },
5187
+ decode(input, length) {
5188
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
5189
+ const end = length === void 0 ? reader.len : reader.pos + length;
5190
+ const message = createBaseRenewRefundTimelockResult();
5191
+ while (reader.pos < end) {
5192
+ const tag = reader.uint32();
5193
+ switch (tag >>> 3) {
5194
+ case 1: {
5195
+ if (tag !== 10) {
5196
+ break;
5197
+ }
5198
+ message.node = TreeNode.decode(reader, reader.uint32());
5199
+ continue;
5200
+ }
5201
+ }
5202
+ if ((tag & 7) === 4 || tag === 0) {
5203
+ break;
5204
+ }
5205
+ reader.skip(tag & 7);
5206
+ }
5207
+ return message;
5208
+ },
5209
+ fromJSON(object) {
5210
+ return { node: isSet3(object.node) ? TreeNode.fromJSON(object.node) : void 0 };
5211
+ },
5212
+ toJSON(message) {
5213
+ const obj = {};
5214
+ if (message.node !== void 0) {
5215
+ obj.node = TreeNode.toJSON(message.node);
5216
+ }
5217
+ return obj;
5218
+ },
5219
+ create(base) {
5220
+ return RenewRefundTimelockResult.fromPartial(base ?? {});
5221
+ },
5222
+ fromPartial(object) {
5223
+ const message = createBaseRenewRefundTimelockResult();
5224
+ message.node = object.node !== void 0 && object.node !== null ? TreeNode.fromPartial(object.node) : void 0;
5225
+ return message;
5226
+ }
5227
+ };
4609
5228
  function createBaseNodeSignatureShares() {
4610
5229
  return {
4611
5230
  nodeId: "",
@@ -16386,7 +17005,7 @@ var QuerySparkInvoicesResponse = {
16386
17005
  }
16387
17006
  };
16388
17007
  function createBaseInvoiceResponse() {
16389
- return { invoice: "", status: 0 };
17008
+ return { invoice: "", status: 0, transferType: void 0 };
16390
17009
  }
16391
17010
  var InvoiceResponse = {
16392
17011
  encode(message, writer = new BinaryWriter4()) {
@@ -16396,6 +17015,14 @@ var InvoiceResponse = {
16396
17015
  if (message.status !== 0) {
16397
17016
  writer.uint32(16).int32(message.status);
16398
17017
  }
17018
+ switch (message.transferType?.$case) {
17019
+ case "satsTransfer":
17020
+ SatsTransfer.encode(message.transferType.satsTransfer, writer.uint32(26).fork()).join();
17021
+ break;
17022
+ case "tokenTransfer":
17023
+ TokenTransfer.encode(message.transferType.tokenTransfer, writer.uint32(34).fork()).join();
17024
+ break;
17025
+ }
16399
17026
  return writer;
16400
17027
  },
16401
17028
  decode(input, length) {
@@ -16419,6 +17046,23 @@ var InvoiceResponse = {
16419
17046
  message.status = reader.int32();
16420
17047
  continue;
16421
17048
  }
17049
+ case 3: {
17050
+ if (tag !== 26) {
17051
+ break;
17052
+ }
17053
+ message.transferType = { $case: "satsTransfer", satsTransfer: SatsTransfer.decode(reader, reader.uint32()) };
17054
+ continue;
17055
+ }
17056
+ case 4: {
17057
+ if (tag !== 34) {
17058
+ break;
17059
+ }
17060
+ message.transferType = {
17061
+ $case: "tokenTransfer",
17062
+ tokenTransfer: TokenTransfer.decode(reader, reader.uint32())
17063
+ };
17064
+ continue;
17065
+ }
16422
17066
  }
16423
17067
  if ((tag & 7) === 4 || tag === 0) {
16424
17068
  break;
@@ -16430,7 +17074,8 @@ var InvoiceResponse = {
16430
17074
  fromJSON(object) {
16431
17075
  return {
16432
17076
  invoice: isSet3(object.invoice) ? globalThis.String(object.invoice) : "",
16433
- status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0
17077
+ status: isSet3(object.status) ? invoiceStatusFromJSON(object.status) : 0,
17078
+ transferType: isSet3(object.satsTransfer) ? { $case: "satsTransfer", satsTransfer: SatsTransfer.fromJSON(object.satsTransfer) } : isSet3(object.tokenTransfer) ? { $case: "tokenTransfer", tokenTransfer: TokenTransfer.fromJSON(object.tokenTransfer) } : void 0
16434
17079
  };
16435
17080
  },
16436
17081
  toJSON(message) {
@@ -16441,6 +17086,11 @@ var InvoiceResponse = {
16441
17086
  if (message.status !== 0) {
16442
17087
  obj.status = invoiceStatusToJSON(message.status);
16443
17088
  }
17089
+ if (message.transferType?.$case === "satsTransfer") {
17090
+ obj.satsTransfer = SatsTransfer.toJSON(message.transferType.satsTransfer);
17091
+ } else if (message.transferType?.$case === "tokenTransfer") {
17092
+ obj.tokenTransfer = TokenTransfer.toJSON(message.transferType.tokenTransfer);
17093
+ }
16444
17094
  return obj;
16445
17095
  },
16446
17096
  create(base) {
@@ -16450,6 +17100,130 @@ var InvoiceResponse = {
16450
17100
  const message = createBaseInvoiceResponse();
16451
17101
  message.invoice = object.invoice ?? "";
16452
17102
  message.status = object.status ?? 0;
17103
+ switch (object.transferType?.$case) {
17104
+ case "satsTransfer": {
17105
+ if (object.transferType?.satsTransfer !== void 0 && object.transferType?.satsTransfer !== null) {
17106
+ message.transferType = {
17107
+ $case: "satsTransfer",
17108
+ satsTransfer: SatsTransfer.fromPartial(object.transferType.satsTransfer)
17109
+ };
17110
+ }
17111
+ break;
17112
+ }
17113
+ case "tokenTransfer": {
17114
+ if (object.transferType?.tokenTransfer !== void 0 && object.transferType?.tokenTransfer !== null) {
17115
+ message.transferType = {
17116
+ $case: "tokenTransfer",
17117
+ tokenTransfer: TokenTransfer.fromPartial(object.transferType.tokenTransfer)
17118
+ };
17119
+ }
17120
+ break;
17121
+ }
17122
+ }
17123
+ return message;
17124
+ }
17125
+ };
17126
+ function createBaseSatsTransfer() {
17127
+ return { transferId: new Uint8Array(0) };
17128
+ }
17129
+ var SatsTransfer = {
17130
+ encode(message, writer = new BinaryWriter4()) {
17131
+ if (message.transferId.length !== 0) {
17132
+ writer.uint32(10).bytes(message.transferId);
17133
+ }
17134
+ return writer;
17135
+ },
17136
+ decode(input, length) {
17137
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
17138
+ const end = length === void 0 ? reader.len : reader.pos + length;
17139
+ const message = createBaseSatsTransfer();
17140
+ while (reader.pos < end) {
17141
+ const tag = reader.uint32();
17142
+ switch (tag >>> 3) {
17143
+ case 1: {
17144
+ if (tag !== 10) {
17145
+ break;
17146
+ }
17147
+ message.transferId = reader.bytes();
17148
+ continue;
17149
+ }
17150
+ }
17151
+ if ((tag & 7) === 4 || tag === 0) {
17152
+ break;
17153
+ }
17154
+ reader.skip(tag & 7);
17155
+ }
17156
+ return message;
17157
+ },
17158
+ fromJSON(object) {
17159
+ return { transferId: isSet3(object.transferId) ? bytesFromBase642(object.transferId) : new Uint8Array(0) };
17160
+ },
17161
+ toJSON(message) {
17162
+ const obj = {};
17163
+ if (message.transferId.length !== 0) {
17164
+ obj.transferId = base64FromBytes2(message.transferId);
17165
+ }
17166
+ return obj;
17167
+ },
17168
+ create(base) {
17169
+ return SatsTransfer.fromPartial(base ?? {});
17170
+ },
17171
+ fromPartial(object) {
17172
+ const message = createBaseSatsTransfer();
17173
+ message.transferId = object.transferId ?? new Uint8Array(0);
17174
+ return message;
17175
+ }
17176
+ };
17177
+ function createBaseTokenTransfer() {
17178
+ return { finalTokenTransactionHash: new Uint8Array(0) };
17179
+ }
17180
+ var TokenTransfer = {
17181
+ encode(message, writer = new BinaryWriter4()) {
17182
+ if (message.finalTokenTransactionHash.length !== 0) {
17183
+ writer.uint32(10).bytes(message.finalTokenTransactionHash);
17184
+ }
17185
+ return writer;
17186
+ },
17187
+ decode(input, length) {
17188
+ const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
17189
+ const end = length === void 0 ? reader.len : reader.pos + length;
17190
+ const message = createBaseTokenTransfer();
17191
+ while (reader.pos < end) {
17192
+ const tag = reader.uint32();
17193
+ switch (tag >>> 3) {
17194
+ case 1: {
17195
+ if (tag !== 10) {
17196
+ break;
17197
+ }
17198
+ message.finalTokenTransactionHash = reader.bytes();
17199
+ continue;
17200
+ }
17201
+ }
17202
+ if ((tag & 7) === 4 || tag === 0) {
17203
+ break;
17204
+ }
17205
+ reader.skip(tag & 7);
17206
+ }
17207
+ return message;
17208
+ },
17209
+ fromJSON(object) {
17210
+ return {
17211
+ finalTokenTransactionHash: isSet3(object.finalTokenTransactionHash) ? bytesFromBase642(object.finalTokenTransactionHash) : new Uint8Array(0)
17212
+ };
17213
+ },
17214
+ toJSON(message) {
17215
+ const obj = {};
17216
+ if (message.finalTokenTransactionHash.length !== 0) {
17217
+ obj.finalTokenTransactionHash = base64FromBytes2(message.finalTokenTransactionHash);
17218
+ }
17219
+ return obj;
17220
+ },
17221
+ create(base) {
17222
+ return TokenTransfer.fromPartial(base ?? {});
17223
+ },
17224
+ fromPartial(object) {
17225
+ const message = createBaseTokenTransfer();
17226
+ message.finalTokenTransactionHash = object.finalTokenTransactionHash ?? new Uint8Array(0);
16453
17227
  return message;
16454
17228
  }
16455
17229
  };
@@ -16665,6 +17439,21 @@ var SparkServiceDefinition = {
16665
17439
  responseStream: false,
16666
17440
  options: {}
16667
17441
  },
17442
+ /**
17443
+ * Resets the timelocks for a leaf's transactions. Can be used to reset the
17444
+ * refund transaction timelock for a leaf (when the node transaction
17445
+ * timelock is still > 300) or reset the node and refund transaction
17446
+ * timelock. Returns an error if a leaf is not yet eligible to renew the
17447
+ * timelocks, see RenewLeafRequest for more details.
17448
+ */
17449
+ renew_leaf: {
17450
+ name: "renew_leaf",
17451
+ requestType: RenewLeafRequest,
17452
+ requestStream: false,
17453
+ responseType: RenewLeafResponse,
17454
+ responseStream: false,
17455
+ options: {}
17456
+ },
16668
17457
  get_signing_operator_list: {
16669
17458
  name: "get_signing_operator_list",
16670
17459
  requestType: Empty,
@@ -17010,7 +17799,7 @@ var isWebExtension = (
17010
17799
  "chrome" in globalThis && globalThis.chrome.runtime?.id
17011
17800
  );
17012
17801
  var userAgent = "navigator" in globalThis ? globalThis.navigator.userAgent || "unknown-user-agent" : void 0;
17013
- var packageVersion = true ? "0.3.3" : "unknown";
17802
+ var packageVersion = true ? "0.3.5" : "unknown";
17014
17803
  var baseEnvStr = "unknown";
17015
17804
  if (isBun) {
17016
17805
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -18083,7 +18872,6 @@ var BASE_CONFIG = {
18083
18872
  threshold: 2,
18084
18873
  signingOperators: getLocalSigningOperators(),
18085
18874
  tokenSignatures: "SCHNORR",
18086
- tokenTransactionVersion: "V1",
18087
18875
  tokenValidityDurationSeconds: 180,
18088
18876
  electrsUrl: getElectrsUrl("LOCAL"),
18089
18877
  expectedWithdrawBondSats: 1e4,
@@ -18287,9 +19075,6 @@ var WalletConfigService = class {
18287
19075
  getTokenSignatures() {
18288
19076
  return this.config.tokenSignatures;
18289
19077
  }
18290
- getTokenTransactionVersion() {
18291
- return this.config.tokenTransactionVersion;
18292
- }
18293
19078
  getTokenValidityDurationSeconds() {
18294
19079
  return this.config.tokenValidityDurationSeconds;
18295
19080
  }
@@ -25713,7 +26498,6 @@ var LightningService = class {
25713
26498
  };
25714
26499
 
25715
26500
  // src/services/token-transactions.ts
25716
- import { secp256k1 as secp256k111 } from "@noble/curves/secp256k1";
25717
26501
  import {
25718
26502
  bytesToHex as bytesToHex8,
25719
26503
  bytesToNumberBE as bytesToNumberBE6,
@@ -25898,6 +26682,13 @@ function uint64be(value) {
25898
26682
  // src/utils/address.ts
25899
26683
  var BECH32M_LIMIT = 1024;
25900
26684
  var AddressNetwork = {
26685
+ MAINNET: "spark",
26686
+ TESTNET: "sparkt",
26687
+ REGTEST: "sparkrt",
26688
+ SIGNET: "sparks",
26689
+ LOCAL: "sparkl"
26690
+ };
26691
+ var LegacyAddressNetwork = {
25901
26692
  MAINNET: "sp",
25902
26693
  TESTNET: "spt",
25903
26694
  REGTEST: "sprt",
@@ -25928,7 +26719,7 @@ function encodeSparkAddressWithSignature(payload, signature) {
25928
26719
  const serializedPayload = w.finish();
25929
26720
  const words = bech32m.toWords(serializedPayload);
25930
26721
  return bech32mEncode(
25931
- AddressNetwork[payload.network],
26722
+ LegacyAddressNetwork[payload.network],
25932
26723
  words
25933
26724
  );
25934
26725
  } catch (error) {
@@ -25944,14 +26735,14 @@ function encodeSparkAddressWithSignature(payload, signature) {
25944
26735
  }
25945
26736
  function decodeSparkAddress(address2, network) {
25946
26737
  try {
25947
- const decoded = bech32mDecode(address2);
25948
- if (decoded.prefix !== AddressNetwork[network]) {
26738
+ if (network !== getNetworkFromSparkAddress(address2)) {
25949
26739
  throw new ValidationError("Invalid Spark address prefix", {
25950
26740
  field: "address",
25951
26741
  value: address2,
25952
- expected: `prefix='${AddressNetwork[network]}'`
26742
+ expected: `prefix='${AddressNetwork[network]}' or '${LegacyAddressNetwork[network]}'`
25953
26743
  });
25954
26744
  }
26745
+ const decoded = bech32mDecode(address2);
25955
26746
  const payload = SparkAddress.decode(bech32m.fromWords(decoded.words));
25956
26747
  const { identityPublicKey, sparkInvoiceFields, signature } = payload;
25957
26748
  const identityPubkeyHex = bytesToHex7(identityPublicKey);
@@ -25995,18 +26786,35 @@ function decodeSparkAddress(address2, network) {
25995
26786
  );
25996
26787
  }
25997
26788
  }
26789
+ var PrefixToNetwork = Object.fromEntries(
26790
+ Object.entries(AddressNetwork).map(([k, v]) => [v, k])
26791
+ );
26792
+ var LegacyPrefixToNetwork = Object.fromEntries(
26793
+ Object.entries(LegacyAddressNetwork).map(([k, v]) => [v, k])
26794
+ );
26795
+ function getNetworkFromSparkAddress(address2) {
26796
+ const { prefix } = bech32mDecode(address2);
26797
+ const network = PrefixToNetwork[prefix] ?? LegacyPrefixToNetwork[prefix];
26798
+ if (!network) {
26799
+ throw new ValidationError("Invalid Spark address prefix", {
26800
+ field: "network",
26801
+ value: address2,
26802
+ expected: "prefix='spark1', 'sparkt1', 'sparkrt1', 'sparks1', 'sparkl1' or legacy ('sp1', 'spt1', 'sprt1', 'sps1', 'spl1')"
26803
+ });
26804
+ }
26805
+ return network;
26806
+ }
26807
+ function isLegacySparkAddress(address2) {
26808
+ try {
26809
+ const { prefix } = bech32mDecode(address2);
26810
+ return prefix in LegacyPrefixToNetwork;
26811
+ } catch (error) {
26812
+ return false;
26813
+ }
26814
+ }
25998
26815
  function isValidSparkAddress(address2) {
25999
26816
  try {
26000
- const network = Object.entries(AddressNetwork).find(
26001
- ([_, prefix]) => address2.startsWith(prefix)
26002
- )?.[0];
26003
- if (!network) {
26004
- throw new ValidationError("Invalid Spark address network", {
26005
- field: "network",
26006
- value: address2,
26007
- expected: Object.values(AddressNetwork)
26008
- });
26009
- }
26817
+ const network = getNetworkFromSparkAddress(address2);
26010
26818
  decodeSparkAddress(address2, network);
26011
26819
  return true;
26012
26820
  } catch (error) {
@@ -26202,25 +27010,16 @@ function validateSparkInvoiceSignature(invoice) {
26202
27010
  );
26203
27011
  }
26204
27012
  }
26205
- function getNetworkFromSparkAddress(address2) {
26206
- const { prefix } = bech32mDecode(address2);
26207
- const network = Object.entries(AddressNetwork).find(
26208
- ([, p]) => p === prefix
26209
- )?.[0];
26210
- if (!network) {
26211
- throw new ValidationError("Invalid Spark address network", {
26212
- field: "network",
26213
- value: address2,
26214
- expected: Object.values(AddressNetwork)
26215
- });
26216
- }
26217
- return network;
26218
- }
26219
27013
  function toProtoTimestamp(date) {
26220
27014
  const ms = date.getTime();
26221
27015
  return { seconds: Math.floor(ms / 1e3), nanos: ms % 1e3 * 1e6 };
26222
27016
  }
27017
+ function assertBech32(s) {
27018
+ const i = s.lastIndexOf("1");
27019
+ if (i <= 0 || i >= s.length - 1) throw new Error("invalid bech32 string");
27020
+ }
26223
27021
  function bech32mDecode(address2) {
27022
+ assertBech32(address2);
26224
27023
  return bech32m.decode(address2, BECH32M_LIMIT);
26225
27024
  }
26226
27025
  function bech32mEncode(prefix, words) {
@@ -26255,34 +27054,11 @@ function isSafeForNumber(bi) {
26255
27054
  return bi >= BigInt(Number.MIN_SAFE_INTEGER) && bi <= BigInt(Number.MAX_SAFE_INTEGER);
26256
27055
  }
26257
27056
 
26258
- // src/utils/response-validation.ts
26259
- function collectResponses(responses) {
26260
- const successfulResponses = responses.filter(
26261
- (result) => result.status === "fulfilled"
26262
- ).map((result) => result.value);
26263
- const failedResponses = responses.filter(
26264
- (result) => result.status === "rejected"
26265
- );
26266
- if (failedResponses.length > 0) {
26267
- const errors = failedResponses.map((result) => result.reason).join("\n");
26268
- throw new NetworkError(
26269
- `${failedResponses.length} out of ${responses.length} requests failed, please try again`,
26270
- {
26271
- errorCount: failedResponses.length,
26272
- errors
26273
- }
26274
- );
26275
- }
26276
- return successfulResponses;
26277
- }
26278
-
26279
27057
  // src/utils/token-hashing.ts
26280
27058
  import { sha256 as sha25611 } from "@noble/hashes/sha2";
26281
27059
  import { bech32m as bech32m2 } from "@scure/base";
26282
27060
  function hashTokenTransaction(tokenTransaction, partialHash = false) {
26283
27061
  switch (tokenTransaction.version) {
26284
- case 0:
26285
- return hashTokenTransactionV0(tokenTransaction, partialHash);
26286
27062
  case 1:
26287
27063
  return hashTokenTransactionV1(tokenTransaction, partialHash);
26288
27064
  case 2:
@@ -26294,345 +27070,6 @@ function hashTokenTransaction(tokenTransaction, partialHash = false) {
26294
27070
  });
26295
27071
  }
26296
27072
  }
26297
- function hashTokenTransactionV0(tokenTransaction, partialHash = false) {
26298
- if (!tokenTransaction) {
26299
- throw new ValidationError("token transaction cannot be nil", {
26300
- field: "tokenTransaction"
26301
- });
26302
- }
26303
- let allHashes = [];
26304
- if (tokenTransaction.tokenInputs?.$case === "transferInput") {
26305
- if (!tokenTransaction.tokenInputs.transferInput.outputsToSpend) {
26306
- throw new ValidationError("outputs to spend cannot be null", {
26307
- field: "tokenInputs.transferInput.outputsToSpend"
26308
- });
26309
- }
26310
- if (tokenTransaction.tokenInputs.transferInput.outputsToSpend.length === 0) {
26311
- throw new ValidationError("outputs to spend cannot be empty", {
26312
- field: "tokenInputs.transferInput.outputsToSpend"
26313
- });
26314
- }
26315
- for (const [
26316
- i,
26317
- output
26318
- ] of tokenTransaction.tokenInputs.transferInput.outputsToSpend.entries()) {
26319
- if (!output) {
26320
- throw new ValidationError(`output cannot be null at index ${i}`, {
26321
- field: `tokenInputs.transferInput.outputsToSpend[${i}]`,
26322
- index: i
26323
- });
26324
- }
26325
- const hashObj2 = sha25611.create();
26326
- if (output.prevTokenTransactionHash) {
26327
- const prevHash = output.prevTokenTransactionHash;
26328
- if (output.prevTokenTransactionHash.length !== 32) {
26329
- throw new ValidationError(
26330
- `invalid previous transaction hash length at index ${i}`,
26331
- {
26332
- field: `tokenInputs.transferInput.outputsToSpend[${i}].prevTokenTransactionHash`,
26333
- value: prevHash,
26334
- expectedLength: 32,
26335
- actualLength: prevHash.length,
26336
- index: i
26337
- }
26338
- );
26339
- }
26340
- hashObj2.update(output.prevTokenTransactionHash);
26341
- }
26342
- const voutBytes = new Uint8Array(4);
26343
- new DataView(voutBytes.buffer).setUint32(
26344
- 0,
26345
- output.prevTokenTransactionVout,
26346
- false
26347
- );
26348
- hashObj2.update(voutBytes);
26349
- allHashes.push(hashObj2.digest());
26350
- }
26351
- }
26352
- if (tokenTransaction.tokenInputs?.$case === "mintInput") {
26353
- const hashObj2 = sha25611.create();
26354
- if (tokenTransaction.tokenInputs.mintInput.issuerPublicKey) {
26355
- const issuerPubKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
26356
- if (issuerPubKey.length === 0) {
26357
- throw new ValidationError("issuer public key cannot be empty", {
26358
- field: "tokenInputs.mintInput.issuerPublicKey",
26359
- value: issuerPubKey,
26360
- expectedLength: 1,
26361
- actualLength: 0
26362
- });
26363
- }
26364
- hashObj2.update(issuerPubKey);
26365
- let timestampValue = 0;
26366
- const mintInput = tokenTransaction.tokenInputs.mintInput;
26367
- if ("issuerProvidedTimestamp" in mintInput) {
26368
- const v0MintInput = mintInput;
26369
- if (v0MintInput.issuerProvidedTimestamp != 0) {
26370
- timestampValue = v0MintInput.issuerProvidedTimestamp;
26371
- }
26372
- } else if ("clientCreatedTimestamp" in tokenTransaction && tokenTransaction.clientCreatedTimestamp) {
26373
- timestampValue = tokenTransaction.clientCreatedTimestamp.getTime();
26374
- }
26375
- if (timestampValue != 0) {
26376
- const timestampBytes = new Uint8Array(8);
26377
- new DataView(timestampBytes.buffer).setBigUint64(
26378
- 0,
26379
- BigInt(timestampValue),
26380
- true
26381
- // true for little-endian to match Go implementation
26382
- );
26383
- hashObj2.update(timestampBytes);
26384
- }
26385
- allHashes.push(hashObj2.digest());
26386
- }
26387
- }
26388
- if (tokenTransaction.tokenInputs?.$case === "createInput") {
26389
- const issuerPubKeyHashObj = sha25611.create();
26390
- const createInput = tokenTransaction.tokenInputs.createInput;
26391
- if (!createInput.issuerPublicKey || createInput.issuerPublicKey.length === 0) {
26392
- throw new ValidationError("issuer public key cannot be nil or empty", {
26393
- field: "tokenInputs.createInput.issuerPublicKey"
26394
- });
26395
- }
26396
- issuerPubKeyHashObj.update(createInput.issuerPublicKey);
26397
- allHashes.push(issuerPubKeyHashObj.digest());
26398
- const tokenNameHashObj = sha25611.create();
26399
- if (!createInput.tokenName || createInput.tokenName.length === 0) {
26400
- throw new ValidationError("token name cannot be empty", {
26401
- field: "tokenInputs.createInput.tokenName"
26402
- });
26403
- }
26404
- if (createInput.tokenName.length > 20) {
26405
- throw new ValidationError("token name cannot be longer than 20 bytes", {
26406
- field: "tokenInputs.createInput.tokenName",
26407
- value: createInput.tokenName,
26408
- expectedLength: 20,
26409
- actualLength: createInput.tokenName.length
26410
- });
26411
- }
26412
- const tokenNameBytes = new Uint8Array(20);
26413
- const tokenNameEncoder = new TextEncoder();
26414
- tokenNameBytes.set(tokenNameEncoder.encode(createInput.tokenName));
26415
- tokenNameHashObj.update(tokenNameBytes);
26416
- allHashes.push(tokenNameHashObj.digest());
26417
- const tokenTickerHashObj = sha25611.create();
26418
- if (!createInput.tokenTicker || createInput.tokenTicker.length === 0) {
26419
- throw new ValidationError("token ticker cannot be empty", {
26420
- field: "tokenInputs.createInput.tokenTicker"
26421
- });
26422
- }
26423
- if (createInput.tokenTicker.length > 6) {
26424
- throw new ValidationError("token ticker cannot be longer than 6 bytes", {
26425
- field: "tokenInputs.createInput.tokenTicker",
26426
- value: createInput.tokenTicker,
26427
- expectedLength: 6,
26428
- actualLength: createInput.tokenTicker.length
26429
- });
26430
- }
26431
- const tokenTickerBytes = new Uint8Array(6);
26432
- const tokenTickerEncoder = new TextEncoder();
26433
- tokenTickerBytes.set(tokenTickerEncoder.encode(createInput.tokenTicker));
26434
- tokenTickerHashObj.update(tokenTickerBytes);
26435
- allHashes.push(tokenTickerHashObj.digest());
26436
- const decimalsHashObj = sha25611.create();
26437
- const decimalsBytes = new Uint8Array(4);
26438
- new DataView(decimalsBytes.buffer).setUint32(
26439
- 0,
26440
- createInput.decimals,
26441
- false
26442
- );
26443
- decimalsHashObj.update(decimalsBytes);
26444
- allHashes.push(decimalsHashObj.digest());
26445
- const maxSupplyHashObj = sha25611.create();
26446
- if (!createInput.maxSupply) {
26447
- throw new ValidationError("max supply cannot be nil", {
26448
- field: "tokenInputs.createInput.maxSupply"
26449
- });
26450
- }
26451
- if (createInput.maxSupply.length !== 16) {
26452
- throw new ValidationError("max supply must be exactly 16 bytes", {
26453
- field: "tokenInputs.createInput.maxSupply",
26454
- value: createInput.maxSupply,
26455
- expectedLength: 16,
26456
- actualLength: createInput.maxSupply.length
26457
- });
26458
- }
26459
- maxSupplyHashObj.update(createInput.maxSupply);
26460
- allHashes.push(maxSupplyHashObj.digest());
26461
- const isFreezableHashObj = sha25611.create();
26462
- const isFreezableByte = new Uint8Array([createInput.isFreezable ? 1 : 0]);
26463
- isFreezableHashObj.update(isFreezableByte);
26464
- allHashes.push(isFreezableHashObj.digest());
26465
- const creationEntityHashObj = sha25611.create();
26466
- if (!partialHash && createInput.creationEntityPublicKey) {
26467
- creationEntityHashObj.update(createInput.creationEntityPublicKey);
26468
- }
26469
- allHashes.push(creationEntityHashObj.digest());
26470
- }
26471
- if (!tokenTransaction.tokenOutputs) {
26472
- throw new ValidationError("token outputs cannot be null", {
26473
- field: "tokenOutputs"
26474
- });
26475
- }
26476
- if (tokenTransaction.tokenOutputs.length === 0 && tokenTransaction.tokenInputs?.$case !== "createInput") {
26477
- throw new ValidationError("token outputs cannot be empty", {
26478
- field: "tokenOutputs"
26479
- });
26480
- }
26481
- for (const [i, output] of tokenTransaction.tokenOutputs.entries()) {
26482
- if (!output) {
26483
- throw new ValidationError(`output cannot be null at index ${i}`, {
26484
- field: `tokenOutputs[${i}]`,
26485
- index: i
26486
- });
26487
- }
26488
- const hashObj2 = sha25611.create();
26489
- if (output.id && !partialHash) {
26490
- if (output.id.length === 0) {
26491
- throw new ValidationError(`output ID at index ${i} cannot be empty`, {
26492
- field: `tokenOutputs[${i}].id`,
26493
- index: i
26494
- });
26495
- }
26496
- hashObj2.update(new TextEncoder().encode(output.id));
26497
- }
26498
- if (output.ownerPublicKey) {
26499
- if (output.ownerPublicKey.length === 0) {
26500
- throw new ValidationError(
26501
- `owner public key at index ${i} cannot be empty`,
26502
- {
26503
- field: `tokenOutputs[${i}].ownerPublicKey`,
26504
- index: i
26505
- }
26506
- );
26507
- }
26508
- hashObj2.update(output.ownerPublicKey);
26509
- }
26510
- if (!partialHash) {
26511
- const revPubKey = output.revocationCommitment;
26512
- if (revPubKey) {
26513
- if (revPubKey.length === 0) {
26514
- throw new ValidationError(
26515
- `revocation commitment at index ${i} cannot be empty`,
26516
- {
26517
- field: `tokenOutputs[${i}].revocationCommitment`,
26518
- index: i
26519
- }
26520
- );
26521
- }
26522
- hashObj2.update(revPubKey);
26523
- }
26524
- const bondBytes = new Uint8Array(8);
26525
- new DataView(bondBytes.buffer).setBigUint64(
26526
- 0,
26527
- BigInt(output.withdrawBondSats),
26528
- false
26529
- );
26530
- hashObj2.update(bondBytes);
26531
- const locktimeBytes = new Uint8Array(8);
26532
- new DataView(locktimeBytes.buffer).setBigUint64(
26533
- 0,
26534
- BigInt(output.withdrawRelativeBlockLocktime),
26535
- false
26536
- );
26537
- hashObj2.update(locktimeBytes);
26538
- }
26539
- if (output.tokenPublicKey) {
26540
- if (output.tokenPublicKey.length === 0) {
26541
- throw new ValidationError(
26542
- `token public key at index ${i} cannot be empty`,
26543
- {
26544
- field: `tokenOutputs[${i}].tokenPublicKey`,
26545
- index: i
26546
- }
26547
- );
26548
- }
26549
- hashObj2.update(output.tokenPublicKey);
26550
- }
26551
- if (output.tokenAmount) {
26552
- if (output.tokenAmount.length === 0) {
26553
- throw new ValidationError(
26554
- `token amount at index ${i} cannot be empty`,
26555
- {
26556
- field: `tokenOutputs[${i}].tokenAmount`,
26557
- index: i
26558
- }
26559
- );
26560
- }
26561
- if (output.tokenAmount.length > 16) {
26562
- throw new ValidationError(
26563
- `token amount at index ${i} exceeds maximum length`,
26564
- {
26565
- field: `tokenOutputs[${i}].tokenAmount`,
26566
- value: output.tokenAmount,
26567
- expectedLength: 16,
26568
- actualLength: output.tokenAmount.length,
26569
- index: i
26570
- }
26571
- );
26572
- }
26573
- hashObj2.update(output.tokenAmount);
26574
- }
26575
- allHashes.push(hashObj2.digest());
26576
- }
26577
- if (!tokenTransaction.sparkOperatorIdentityPublicKeys) {
26578
- throw new ValidationError(
26579
- "spark operator identity public keys cannot be null",
26580
- {}
26581
- );
26582
- }
26583
- const sortedPubKeys = [
26584
- ...tokenTransaction.sparkOperatorIdentityPublicKeys || []
26585
- ].sort((a, b) => {
26586
- for (let i = 0; i < a.length && i < b.length; i++) {
26587
- if (a[i] !== b[i]) return a[i] - b[i];
26588
- }
26589
- return a.length - b.length;
26590
- });
26591
- for (const [i, pubKey] of sortedPubKeys.entries()) {
26592
- if (!pubKey) {
26593
- throw new ValidationError(
26594
- `operator public key at index ${i} cannot be null`,
26595
- {
26596
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
26597
- index: i
26598
- }
26599
- );
26600
- }
26601
- if (pubKey.length === 0) {
26602
- throw new ValidationError(
26603
- `operator public key at index ${i} cannot be empty`,
26604
- {
26605
- field: `sparkOperatorIdentityPublicKeys[${i}]`,
26606
- index: i
26607
- }
26608
- );
26609
- }
26610
- const hashObj2 = sha25611.create();
26611
- hashObj2.update(pubKey);
26612
- allHashes.push(hashObj2.digest());
26613
- }
26614
- const hashObj = sha25611.create();
26615
- let networkBytes = new Uint8Array(4);
26616
- new DataView(networkBytes.buffer).setUint32(
26617
- 0,
26618
- tokenTransaction.network.valueOf(),
26619
- false
26620
- // false for big-endian
26621
- );
26622
- hashObj.update(networkBytes);
26623
- allHashes.push(hashObj.digest());
26624
- const finalHashObj = sha25611.create();
26625
- const concatenatedHashes = new Uint8Array(
26626
- allHashes.reduce((sum, hash) => sum + hash.length, 0)
26627
- );
26628
- let offset = 0;
26629
- for (const hash of allHashes) {
26630
- concatenatedHashes.set(hash, offset);
26631
- offset += hash.length;
26632
- }
26633
- finalHashObj.update(concatenatedHashes);
26634
- return finalHashObj.digest();
26635
- }
26636
27073
  function hashTokenTransactionV1(tokenTransaction, partialHash = false) {
26637
27074
  if (!tokenTransaction) {
26638
27075
  throw new ValidationError("token transaction cannot be nil", {
@@ -27659,23 +28096,6 @@ function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier) {
27659
28096
  });
27660
28097
  }
27661
28098
 
27662
- // src/utils/token-keyshares.ts
27663
- import { secp256k1 as secp256k110 } from "@noble/curves/secp256k1";
27664
- function recoverRevocationSecretFromKeyshares(keyshares, threshold) {
27665
- const shares = keyshares.map((keyshare) => ({
27666
- fieldModulus: BigInt("0x" + secp256k110.CURVE.n.toString(16)),
27667
- // secp256k1 curve order
27668
- threshold,
27669
- index: BigInt(keyshare.operatorIndex),
27670
- share: BigInt(
27671
- "0x" + Buffer.from(keyshare.keyshare.keyshare).toString("hex")
27672
- ),
27673
- proofs: []
27674
- }));
27675
- const recoveredSecret = recoverSecret(shares);
27676
- return bigIntToPrivateKey(recoveredSecret);
27677
- }
27678
-
27679
28099
  // src/utils/token-transaction-validation.ts
27680
28100
  function areByteArraysEqual(a, b) {
27681
28101
  if (a.length !== b.length) {
@@ -27686,250 +28106,6 @@ function areByteArraysEqual(a, b) {
27686
28106
  function hasDuplicates(array) {
27687
28107
  return new Set(array).size !== array.length;
27688
28108
  }
27689
- function validateTokenTransactionV0(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
27690
- if (finalTokenTransaction.network !== partialTokenTransaction.network) {
27691
- throw new InternalValidationError(
27692
- "Network mismatch in response token transaction",
27693
- {
27694
- value: finalTokenTransaction.network,
27695
- expected: partialTokenTransaction.network
27696
- }
27697
- );
27698
- }
27699
- if (!finalTokenTransaction.tokenInputs) {
27700
- throw new InternalValidationError(
27701
- "Token inputs missing in final transaction",
27702
- {
27703
- value: finalTokenTransaction
27704
- }
27705
- );
27706
- }
27707
- if (!partialTokenTransaction.tokenInputs) {
27708
- throw new InternalValidationError(
27709
- "Token inputs missing in partial transaction",
27710
- {
27711
- value: partialTokenTransaction
27712
- }
27713
- );
27714
- }
27715
- if (finalTokenTransaction.tokenInputs.$case !== partialTokenTransaction.tokenInputs.$case) {
27716
- throw new InternalValidationError(
27717
- `Transaction type mismatch: final transaction has ${finalTokenTransaction.tokenInputs.$case}, partial transaction has ${partialTokenTransaction.tokenInputs.$case}`,
27718
- {
27719
- value: finalTokenTransaction.tokenInputs.$case,
27720
- expected: partialTokenTransaction.tokenInputs.$case
27721
- }
27722
- );
27723
- }
27724
- if (finalTokenTransaction.sparkOperatorIdentityPublicKeys.length !== partialTokenTransaction.sparkOperatorIdentityPublicKeys.length) {
27725
- throw new InternalValidationError(
27726
- "Spark operator identity public keys count mismatch",
27727
- {
27728
- value: finalTokenTransaction.sparkOperatorIdentityPublicKeys.length,
27729
- expected: partialTokenTransaction.sparkOperatorIdentityPublicKeys.length
27730
- }
27731
- );
27732
- }
27733
- if (partialTokenTransaction.tokenInputs.$case === "mintInput" && finalTokenTransaction.tokenInputs.$case === "mintInput") {
27734
- const finalMintInput = finalTokenTransaction.tokenInputs.mintInput;
27735
- const partialMintInput = partialTokenTransaction.tokenInputs.mintInput;
27736
- if (!areByteArraysEqual(
27737
- finalMintInput.issuerPublicKey,
27738
- partialMintInput.issuerPublicKey
27739
- )) {
27740
- throw new InternalValidationError(
27741
- "Issuer public key mismatch in mint input",
27742
- {
27743
- value: finalMintInput.issuerPublicKey.toString(),
27744
- expected: partialMintInput.issuerPublicKey.toString()
27745
- }
27746
- );
27747
- }
27748
- } else if (partialTokenTransaction.tokenInputs.$case === "transferInput" && finalTokenTransaction.tokenInputs.$case === "transferInput") {
27749
- const finalTransferInput = finalTokenTransaction.tokenInputs.transferInput;
27750
- const partialTransferInput = partialTokenTransaction.tokenInputs.transferInput;
27751
- if (finalTransferInput.outputsToSpend.length !== partialTransferInput.outputsToSpend.length) {
27752
- throw new InternalValidationError(
27753
- "Outputs to spend count mismatch in transfer input",
27754
- {
27755
- value: finalTransferInput.outputsToSpend.length,
27756
- expected: partialTransferInput.outputsToSpend.length
27757
- }
27758
- );
27759
- }
27760
- for (let i = 0; i < finalTransferInput.outputsToSpend.length; i++) {
27761
- const finalOutput = finalTransferInput.outputsToSpend[i];
27762
- const partialOutput = partialTransferInput.outputsToSpend[i];
27763
- if (!finalOutput) {
27764
- throw new InternalValidationError(
27765
- "Token output to spend missing in final transaction",
27766
- {
27767
- outputIndex: i,
27768
- value: finalOutput
27769
- }
27770
- );
27771
- }
27772
- if (!partialOutput) {
27773
- throw new InternalValidationError(
27774
- "Token output to spend missing in partial transaction",
27775
- {
27776
- outputIndex: i,
27777
- value: partialOutput
27778
- }
27779
- );
27780
- }
27781
- if (!areByteArraysEqual(
27782
- finalOutput.prevTokenTransactionHash,
27783
- partialOutput.prevTokenTransactionHash
27784
- )) {
27785
- throw new InternalValidationError(
27786
- "Previous token transaction hash mismatch in transfer input",
27787
- {
27788
- outputIndex: i,
27789
- value: finalOutput.prevTokenTransactionHash.toString(),
27790
- expected: partialOutput.prevTokenTransactionHash.toString()
27791
- }
27792
- );
27793
- }
27794
- if (finalOutput.prevTokenTransactionVout !== partialOutput.prevTokenTransactionVout) {
27795
- throw new InternalValidationError(
27796
- "Previous token transaction vout mismatch in transfer input",
27797
- {
27798
- outputIndex: i,
27799
- value: finalOutput.prevTokenTransactionVout,
27800
- expected: partialOutput.prevTokenTransactionVout
27801
- }
27802
- );
27803
- }
27804
- }
27805
- }
27806
- if (finalTokenTransaction.tokenOutputs.length !== partialTokenTransaction.tokenOutputs.length) {
27807
- throw new InternalValidationError("Token outputs count mismatch", {
27808
- value: finalTokenTransaction.tokenOutputs.length,
27809
- expected: partialTokenTransaction.tokenOutputs.length
27810
- });
27811
- }
27812
- for (let i = 0; i < finalTokenTransaction.tokenOutputs.length; i++) {
27813
- const finalOutput = finalTokenTransaction.tokenOutputs[i];
27814
- const partialOutput = partialTokenTransaction.tokenOutputs[i];
27815
- if (!finalOutput) {
27816
- throw new InternalValidationError(
27817
- "Token output missing in final transaction",
27818
- {
27819
- outputIndex: i,
27820
- value: finalOutput
27821
- }
27822
- );
27823
- }
27824
- if (!partialOutput) {
27825
- throw new InternalValidationError(
27826
- "Token output missing in partial transaction",
27827
- {
27828
- outputIndex: i,
27829
- value: partialOutput
27830
- }
27831
- );
27832
- }
27833
- if (!areByteArraysEqual(
27834
- finalOutput.ownerPublicKey,
27835
- partialOutput.ownerPublicKey
27836
- )) {
27837
- throw new InternalValidationError(
27838
- "Owner public key mismatch in token output",
27839
- {
27840
- outputIndex: i,
27841
- value: finalOutput.ownerPublicKey.toString(),
27842
- expected: partialOutput.ownerPublicKey.toString()
27843
- }
27844
- );
27845
- }
27846
- if (finalOutput.tokenPublicKey !== void 0 && partialOutput.tokenPublicKey !== void 0 && !areByteArraysEqual(
27847
- finalOutput.tokenPublicKey,
27848
- partialOutput.tokenPublicKey
27849
- )) {
27850
- throw new InternalValidationError(
27851
- "Token public key mismatch in token output",
27852
- {
27853
- outputIndex: i,
27854
- value: finalOutput.tokenPublicKey?.toString(),
27855
- expected: partialOutput.tokenPublicKey?.toString()
27856
- }
27857
- );
27858
- }
27859
- if (!areByteArraysEqual(finalOutput.tokenAmount, partialOutput.tokenAmount)) {
27860
- throw new InternalValidationError(
27861
- "Token amount mismatch in token output",
27862
- {
27863
- outputIndex: i,
27864
- value: finalOutput.tokenAmount.toString(),
27865
- expected: partialOutput.tokenAmount.toString()
27866
- }
27867
- );
27868
- }
27869
- if (finalOutput.withdrawBondSats !== void 0) {
27870
- if (finalOutput.withdrawBondSats !== expectedWithdrawBondSats) {
27871
- throw new InternalValidationError(
27872
- "Withdraw bond sats mismatch in token output",
27873
- {
27874
- outputIndex: i,
27875
- value: finalOutput.withdrawBondSats,
27876
- expected: expectedWithdrawBondSats
27877
- }
27878
- );
27879
- }
27880
- }
27881
- if (finalOutput.withdrawRelativeBlockLocktime !== void 0) {
27882
- if (finalOutput.withdrawRelativeBlockLocktime !== expectedWithdrawRelativeBlockLocktime) {
27883
- throw new InternalValidationError(
27884
- "Withdraw relative block locktime mismatch in token output",
27885
- {
27886
- outputIndex: i,
27887
- value: finalOutput.withdrawRelativeBlockLocktime,
27888
- expected: expectedWithdrawRelativeBlockLocktime
27889
- }
27890
- );
27891
- }
27892
- }
27893
- if (keyshareInfo.threshold !== expectedThreshold) {
27894
- throw new InternalValidationError(
27895
- "Threshold mismatch: expected " + expectedThreshold + " but got " + keyshareInfo.threshold,
27896
- {
27897
- field: "threshold",
27898
- value: keyshareInfo.threshold,
27899
- expected: expectedThreshold
27900
- }
27901
- );
27902
- }
27903
- }
27904
- if (keyshareInfo.ownerIdentifiers.length !== Object.keys(signingOperators).length) {
27905
- throw new InternalValidationError(
27906
- `Keyshare operator count (${keyshareInfo.ownerIdentifiers.length}) does not match signing operator count (${Object.keys(signingOperators).length})`,
27907
- {
27908
- keyshareInfo: keyshareInfo.ownerIdentifiers.length,
27909
- signingOperators: Object.keys(signingOperators).length
27910
- }
27911
- );
27912
- }
27913
- if (hasDuplicates(keyshareInfo.ownerIdentifiers)) {
27914
- throw new InternalValidationError(
27915
- "Duplicate ownerIdentifiers found in keyshareInfo",
27916
- {
27917
- keyshareInfo: keyshareInfo.ownerIdentifiers
27918
- }
27919
- );
27920
- }
27921
- for (const identifier of keyshareInfo.ownerIdentifiers) {
27922
- if (!signingOperators[identifier]) {
27923
- throw new InternalValidationError(
27924
- `Keyshare operator ${identifier} not found in signing operator list`,
27925
- {
27926
- keyshareInfo: identifier,
27927
- signingOperators: Object.keys(signingOperators)
27928
- }
27929
- );
27930
- }
27931
- }
27932
- }
27933
28109
  function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction, signingOperators, keyshareInfo, expectedWithdrawBondSats, expectedWithdrawRelativeBlockLocktime, expectedThreshold) {
27934
28110
  if (finalTokenTransaction.network !== partialTokenTransaction.network) {
27935
28111
  throw new InternalValidationError(
@@ -28330,16 +28506,6 @@ var TokenTransactionService = class {
28330
28506
  tokenIdentifier,
28331
28507
  this.config.getNetworkType()
28332
28508
  ).tokenIdentifier;
28333
- let tokenPublicKey;
28334
- if (this.config.getTokenTransactionVersion() === "V0") {
28335
- const tokenClient = await this.connectionManager.createSparkTokenClient(
28336
- this.config.getCoordinatorAddress()
28337
- );
28338
- const tokenMetadata = await tokenClient.query_token_metadata({
28339
- tokenIdentifiers: [rawTokenIdentifier]
28340
- });
28341
- tokenPublicKey = tokenMetadata.tokenMetadata[0].issuerPublicKey;
28342
- }
28343
28509
  let sparkInvoices = [];
28344
28510
  const tokenOutputData = receiverOutputs.map((transfer) => {
28345
28511
  const receiverAddress = decodeSparkAddress(
@@ -28349,7 +28515,7 @@ var TokenTransactionService = class {
28349
28515
  if (receiverAddress.sparkInvoiceFields) {
28350
28516
  sparkInvoices.push(transfer.receiverSparkAddress);
28351
28517
  }
28352
- if (this.config.getTokenTransactionVersion() !== "V0" && receiverAddress.sparkInvoiceFields) {
28518
+ if (receiverAddress.sparkInvoiceFields) {
28353
28519
  return {
28354
28520
  receiverPublicKey: hexToBytes8(receiverAddress.identityPublicKey),
28355
28521
  rawTokenIdentifier,
@@ -28360,24 +28526,14 @@ var TokenTransactionService = class {
28360
28526
  return {
28361
28527
  receiverPublicKey: hexToBytes8(receiverAddress.identityPublicKey),
28362
28528
  rawTokenIdentifier,
28363
- tokenPublicKey,
28364
- // Remove for full v0 deprecation
28365
28529
  tokenAmount: transfer.tokenAmount
28366
28530
  };
28367
28531
  });
28368
- let tokenTransaction;
28369
- if (this.config.getTokenTransactionVersion() === "V0") {
28370
- tokenTransaction = await this.constructTransferTokenTransactionV0(
28371
- outputsToUse,
28372
- tokenOutputData
28373
- );
28374
- } else {
28375
- tokenTransaction = await this.constructTransferTokenTransaction(
28376
- outputsToUse,
28377
- tokenOutputData,
28378
- sparkInvoices
28379
- );
28380
- }
28532
+ const tokenTransaction = await this.constructTransferTokenTransaction(
28533
+ outputsToUse,
28534
+ tokenOutputData,
28535
+ sparkInvoices
28536
+ );
28381
28537
  const txId = await this.broadcastTokenTransaction(
28382
28538
  tokenTransaction,
28383
28539
  outputsToUse.map((output) => output.output.ownerPublicKey),
@@ -28385,44 +28541,6 @@ var TokenTransactionService = class {
28385
28541
  );
28386
28542
  return txId;
28387
28543
  }
28388
- async constructTransferTokenTransactionV0(selectedOutputs, tokenOutputData) {
28389
- selectedOutputs.sort(
28390
- (a, b) => a.previousTransactionVout - b.previousTransactionVout
28391
- );
28392
- const availableTokenAmount = sumAvailableTokens(selectedOutputs);
28393
- const totalRequestedAmount = tokenOutputData.reduce(
28394
- (sum, output) => sum + output.tokenAmount,
28395
- 0n
28396
- );
28397
- const tokenOutputs = tokenOutputData.map((output) => ({
28398
- ownerPublicKey: output.receiverPublicKey,
28399
- tokenPublicKey: output.tokenPublicKey,
28400
- tokenAmount: numberToBytesBE4(output.tokenAmount, 16)
28401
- }));
28402
- if (availableTokenAmount > totalRequestedAmount) {
28403
- const changeAmount = availableTokenAmount - totalRequestedAmount;
28404
- const firstTokenPublicKey = tokenOutputData[0].tokenPublicKey;
28405
- tokenOutputs.push({
28406
- ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
28407
- tokenPublicKey: firstTokenPublicKey,
28408
- tokenAmount: numberToBytesBE4(changeAmount, 16)
28409
- });
28410
- }
28411
- return {
28412
- network: this.config.getNetworkProto(),
28413
- tokenInputs: {
28414
- $case: "transferInput",
28415
- transferInput: {
28416
- outputsToSpend: selectedOutputs.map((output) => ({
28417
- prevTokenTransactionHash: output.previousTransactionHash,
28418
- prevTokenTransactionVout: output.previousTransactionVout
28419
- }))
28420
- }
28421
- },
28422
- tokenOutputs,
28423
- sparkOperatorIdentityPublicKeys: this.collectOperatorIdentityPublicKeys()
28424
- };
28425
- }
28426
28544
  async constructTransferTokenTransaction(selectedOutputs, tokenOutputData, sparkInvoices) {
28427
28545
  selectedOutputs.sort(
28428
28546
  (a, b) => a.previousTransactionVout - b.previousTransactionVout
@@ -28478,113 +28596,6 @@ var TokenTransactionService = class {
28478
28596
  }
28479
28597
  async broadcastTokenTransaction(tokenTransaction, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
28480
28598
  const signingOperators = this.config.getSigningOperators();
28481
- if (!isTokenTransaction(tokenTransaction)) {
28482
- return this.broadcastTokenTransactionV0(
28483
- tokenTransaction,
28484
- signingOperators,
28485
- outputsToSpendSigningPublicKeys,
28486
- outputsToSpendCommitments
28487
- );
28488
- } else {
28489
- return this.broadcastTokenTransactionV1(
28490
- tokenTransaction,
28491
- signingOperators,
28492
- outputsToSpendSigningPublicKeys,
28493
- outputsToSpendCommitments
28494
- );
28495
- }
28496
- }
28497
- async broadcastTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
28498
- const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransactionV0(
28499
- tokenTransaction,
28500
- signingOperators,
28501
- outputsToSpendSigningPublicKeys,
28502
- outputsToSpendCommitments
28503
- );
28504
- const { successfulSignatures } = await this.signTokenTransactionV0(
28505
- finalTokenTransaction,
28506
- finalTokenTransactionHash,
28507
- signingOperators
28508
- );
28509
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
28510
- const outputsToSpend = finalTokenTransaction.tokenInputs.transferInput.outputsToSpend;
28511
- const errors = [];
28512
- const revocationSecrets = [];
28513
- for (let outputIndex = 0; outputIndex < outputsToSpend.length; outputIndex++) {
28514
- const outputKeyshares = successfulSignatures.map(({ identifier, response }) => ({
28515
- operatorIndex: parseInt(identifier, 16),
28516
- keyshare: response.revocationKeyshares[outputIndex]
28517
- }));
28518
- if (outputKeyshares.length < threshold) {
28519
- errors.push(
28520
- new ValidationError("Insufficient keyshares", {
28521
- field: "outputKeyshares",
28522
- value: outputKeyshares.length,
28523
- expected: threshold,
28524
- index: outputIndex
28525
- })
28526
- );
28527
- }
28528
- const seenIndices = /* @__PURE__ */ new Set();
28529
- for (const { operatorIndex } of outputKeyshares) {
28530
- if (seenIndices.has(operatorIndex)) {
28531
- errors.push(
28532
- new ValidationError("Duplicate operator index", {
28533
- field: "outputKeyshares",
28534
- value: operatorIndex,
28535
- expected: "Unique operator index",
28536
- index: outputIndex
28537
- })
28538
- );
28539
- }
28540
- seenIndices.add(operatorIndex);
28541
- }
28542
- const revocationSecret = recoverRevocationSecretFromKeyshares(
28543
- outputKeyshares,
28544
- threshold
28545
- );
28546
- const derivedRevocationCommitment = secp256k111.getPublicKey(
28547
- revocationSecret,
28548
- true
28549
- );
28550
- if (!outputsToSpendCommitments || !outputsToSpendCommitments[outputIndex] || !derivedRevocationCommitment.every(
28551
- (byte, i) => byte === outputsToSpendCommitments[outputIndex][i]
28552
- )) {
28553
- errors.push(
28554
- new InternalValidationError(
28555
- "Revocation commitment verification failed",
28556
- {
28557
- field: "revocationCommitment",
28558
- value: derivedRevocationCommitment,
28559
- expected: bytesToHex8(outputsToSpendCommitments[outputIndex]),
28560
- outputIndex
28561
- }
28562
- )
28563
- );
28564
- }
28565
- revocationSecrets.push({
28566
- inputIndex: outputIndex,
28567
- revocationSecret
28568
- });
28569
- }
28570
- if (errors.length > 0) {
28571
- throw new ValidationError(
28572
- "Multiple validation errors occurred across outputs",
28573
- {
28574
- field: "outputValidation",
28575
- value: errors
28576
- }
28577
- );
28578
- }
28579
- await this.finalizeTokenTransaction(
28580
- finalTokenTransaction,
28581
- revocationSecrets,
28582
- threshold
28583
- );
28584
- }
28585
- return bytesToHex8(finalTokenTransactionHash);
28586
- }
28587
- async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
28588
28599
  const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
28589
28600
  tokenTransaction,
28590
28601
  signingOperators,
@@ -28598,101 +28609,6 @@ var TokenTransactionService = class {
28598
28609
  );
28599
28610
  return bytesToHex8(finalTokenTransactionHash);
28600
28611
  }
28601
- async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
28602
- const sparkClient = await this.connectionManager.createSparkClient(
28603
- this.config.getCoordinatorAddress()
28604
- );
28605
- const partialTokenTransactionHash = hashTokenTransactionV0(
28606
- tokenTransaction,
28607
- true
28608
- );
28609
- const ownerSignaturesWithIndex = [];
28610
- if (tokenTransaction.tokenInputs.$case === "mintInput") {
28611
- const issuerPublicKey = tokenTransaction.tokenInputs.mintInput.issuerPublicKey;
28612
- if (!issuerPublicKey) {
28613
- throw new ValidationError("Invalid mint input", {
28614
- field: "issuerPublicKey",
28615
- value: null,
28616
- expected: "Non-null issuer public key"
28617
- });
28618
- }
28619
- const ownerSignature = await this.signMessageWithKey(
28620
- partialTokenTransactionHash,
28621
- issuerPublicKey
28622
- );
28623
- ownerSignaturesWithIndex.push({
28624
- signature: ownerSignature,
28625
- inputIndex: 0
28626
- });
28627
- } else if (tokenTransaction.tokenInputs.$case === "transferInput") {
28628
- if (!outputsToSpendSigningPublicKeys || !outputsToSpendCommitments) {
28629
- throw new ValidationError("Invalid transfer input", {
28630
- field: "outputsToSpend",
28631
- value: {
28632
- signingPublicKeys: outputsToSpendSigningPublicKeys,
28633
- revocationPublicKeys: outputsToSpendCommitments
28634
- },
28635
- expected: "Non-null signing and revocation public keys"
28636
- });
28637
- }
28638
- for (const [i, key] of outputsToSpendSigningPublicKeys.entries()) {
28639
- if (!key) {
28640
- throw new ValidationError("Invalid signing key", {
28641
- field: "outputsToSpendSigningPublicKeys",
28642
- value: i,
28643
- expected: "Non-null signing key"
28644
- });
28645
- }
28646
- const ownerSignature = await this.signMessageWithKey(
28647
- partialTokenTransactionHash,
28648
- key
28649
- );
28650
- ownerSignaturesWithIndex.push({
28651
- signature: ownerSignature,
28652
- inputIndex: i
28653
- });
28654
- }
28655
- }
28656
- const startResponse = await sparkClient.start_token_transaction(
28657
- {
28658
- identityPublicKey: await this.config.signer.getIdentityPublicKey(),
28659
- partialTokenTransaction: tokenTransaction,
28660
- tokenTransactionSignatures: {
28661
- ownerSignatures: ownerSignaturesWithIndex
28662
- }
28663
- },
28664
- {
28665
- retry: true,
28666
- retryableStatuses: ["UNKNOWN", "UNAVAILABLE", "CANCELLED", "INTERNAL"],
28667
- retryMaxAttempts: 3
28668
- }
28669
- );
28670
- if (!startResponse.finalTokenTransaction) {
28671
- throw new Error("Final token transaction missing in start response");
28672
- }
28673
- if (!startResponse.keyshareInfo) {
28674
- throw new Error("Keyshare info missing in start response");
28675
- }
28676
- validateTokenTransactionV0(
28677
- startResponse.finalTokenTransaction,
28678
- tokenTransaction,
28679
- signingOperators,
28680
- startResponse.keyshareInfo,
28681
- this.config.getExpectedWithdrawBondSats(),
28682
- this.config.getExpectedWithdrawRelativeBlockLocktime(),
28683
- this.config.getThreshold()
28684
- );
28685
- const finalTokenTransaction = startResponse.finalTokenTransaction;
28686
- const finalTokenTransactionHash = hashTokenTransactionV0(
28687
- finalTokenTransaction,
28688
- false
28689
- );
28690
- return {
28691
- finalTokenTransaction,
28692
- finalTokenTransactionHash,
28693
- threshold: startResponse.keyshareInfo.threshold
28694
- };
28695
- }
28696
28612
  async startTokenTransaction(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
28697
28613
  const sparkClient = await this.connectionManager.createSparkTokenClient(
28698
28614
  this.config.getCoordinatorAddress()
@@ -28812,103 +28728,6 @@ var TokenTransactionService = class {
28812
28728
  threshold: startResponse.keyshareInfo.threshold
28813
28729
  };
28814
28730
  }
28815
- async signTokenTransactionV0(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
28816
- const soSignatures = await Promise.allSettled(
28817
- Object.entries(signingOperators).map(
28818
- async ([identifier, operator], index) => {
28819
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
28820
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
28821
- const payload = {
28822
- finalTokenTransactionHash,
28823
- operatorIdentityPublicKey: hexToBytes8(operator.identityPublicKey)
28824
- };
28825
- const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
28826
- let operatorSpecificSignatures = [];
28827
- if (finalTokenTransaction.tokenInputs.$case === "mintInput") {
28828
- const issuerPublicKey = finalTokenTransaction.tokenInputs.mintInput.issuerPublicKey;
28829
- if (!issuerPublicKey) {
28830
- throw new ValidationError("Invalid mint input", {
28831
- field: "issuerPublicKey",
28832
- value: null,
28833
- expected: "Non-null issuer public key"
28834
- });
28835
- }
28836
- const ownerSignature = await this.signMessageWithKey(
28837
- payloadHash,
28838
- issuerPublicKey
28839
- );
28840
- operatorSpecificSignatures.push({
28841
- ownerSignature: {
28842
- signature: ownerSignature,
28843
- inputIndex: 0
28844
- },
28845
- payload
28846
- });
28847
- }
28848
- if (finalTokenTransaction.tokenInputs.$case === "transferInput") {
28849
- const transferInput = finalTokenTransaction.tokenInputs.transferInput;
28850
- for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
28851
- let ownerSignature;
28852
- if (this.config.getTokenSignatures() === "SCHNORR") {
28853
- ownerSignature = await this.config.signer.signSchnorrWithIdentityKey(
28854
- payloadHash
28855
- );
28856
- } else {
28857
- ownerSignature = await this.config.signer.signMessageWithIdentityKey(
28858
- payloadHash
28859
- );
28860
- }
28861
- operatorSpecificSignatures.push({
28862
- ownerSignature: {
28863
- signature: ownerSignature,
28864
- inputIndex: i
28865
- },
28866
- payload
28867
- });
28868
- }
28869
- }
28870
- try {
28871
- const response = await internalSparkClient.sign_token_transaction(
28872
- {
28873
- finalTokenTransaction,
28874
- operatorSpecificSignatures,
28875
- identityPublicKey
28876
- },
28877
- {
28878
- retry: true,
28879
- retryableStatuses: [
28880
- "UNKNOWN",
28881
- "UNAVAILABLE",
28882
- "CANCELLED",
28883
- "INTERNAL"
28884
- ],
28885
- retryMaxAttempts: 3
28886
- }
28887
- );
28888
- return {
28889
- index,
28890
- identifier,
28891
- response
28892
- };
28893
- } catch (error) {
28894
- throw new NetworkError(
28895
- "Failed to sign token transaction",
28896
- {
28897
- operation: "sign_token_transaction",
28898
- errorCount: 1,
28899
- errors: error instanceof Error ? error.message : String(error)
28900
- },
28901
- error
28902
- );
28903
- }
28904
- }
28905
- )
28906
- );
28907
- const successfulSignatures = collectResponses(soSignatures);
28908
- return {
28909
- successfulSignatures
28910
- };
28911
- }
28912
28731
  async signTokenTransaction(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
28913
28732
  const coordinatorClient = await this.connectionManager.createSparkTokenClient(
28914
28733
  this.config.getCoordinatorAddress()
@@ -28980,54 +28799,6 @@ var TokenTransactionService = class {
28980
28799
  );
28981
28800
  }
28982
28801
  }
28983
- if (this.config.getTokenTransactionVersion() === "V0") {
28984
- return this.fetchOwnedTokenOutputsV0(params);
28985
- } else {
28986
- return this.fetchOwnedTokenOutputsV1(params);
28987
- }
28988
- }
28989
- async queryTokenTransactions(params) {
28990
- if (this.config.getTokenTransactionVersion() === "V0") {
28991
- return this.queryTokenTransactionsV0(params);
28992
- } else {
28993
- return this.queryTokenTransactionsV1(params);
28994
- }
28995
- }
28996
- async fetchOwnedTokenOutputsV0(params) {
28997
- const {
28998
- ownerPublicKeys,
28999
- issuerPublicKeys: tokenPublicKeys = [],
29000
- tokenIdentifiers = []
29001
- } = params;
29002
- const sparkClient = await this.connectionManager.createSparkClient(
29003
- this.config.getCoordinatorAddress()
29004
- );
29005
- try {
29006
- const result = await sparkClient.query_token_outputs({
29007
- ownerPublicKeys,
29008
- tokenPublicKeys,
29009
- tokenIdentifiers,
29010
- network: this.config.getNetworkProto()
29011
- });
29012
- return result.outputsWithPreviousTransactionData;
29013
- } catch (error) {
29014
- throw new NetworkError(
29015
- "Failed to fetch owned token outputs",
29016
- {
29017
- operation: "spark.query_token_outputs",
29018
- errorCount: 1,
29019
- errors: error instanceof Error ? error.message : String(error)
29020
- },
29021
- error
29022
- );
29023
- }
29024
- }
29025
- async fetchOwnedTokenOutputsV1(params) {
29026
- const {
29027
- ownerPublicKeys,
29028
- issuerPublicKeys = [],
29029
- tokenIdentifiers = []
29030
- } = params;
29031
28802
  const tokenClient = await this.connectionManager.createSparkTokenClient(
29032
28803
  this.config.getCoordinatorAddress()
29033
28804
  );
@@ -29068,75 +28839,7 @@ var TokenTransactionService = class {
29068
28839
  );
29069
28840
  }
29070
28841
  }
29071
- async queryTokenTransactionsV0(params) {
29072
- const {
29073
- ownerPublicKeys,
29074
- issuerPublicKeys,
29075
- tokenTransactionHashes,
29076
- tokenIdentifiers,
29077
- outputIds,
29078
- pageSize,
29079
- offset
29080
- } = params;
29081
- const sparkClient = await this.connectionManager.createSparkClient(
29082
- this.config.getCoordinatorAddress()
29083
- );
29084
- let queryParams = {
29085
- tokenPublicKeys: issuerPublicKeys?.map(hexToBytes8),
29086
- ownerPublicKeys: ownerPublicKeys?.map(hexToBytes8),
29087
- tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
29088
- const { tokenIdentifier } = decodeBech32mTokenIdentifier(
29089
- identifier,
29090
- this.config.getNetworkType()
29091
- );
29092
- return tokenIdentifier;
29093
- }),
29094
- tokenTransactionHashes: tokenTransactionHashes?.map(hexToBytes8),
29095
- outputIds: outputIds || [],
29096
- limit: pageSize,
29097
- offset
29098
- };
29099
- try {
29100
- const response = await sparkClient.query_token_transactions(queryParams);
29101
- return {
29102
- tokenTransactionsWithStatus: response.tokenTransactionsWithStatus.map(
29103
- (tx) => {
29104
- const v1TokenTransaction = {
29105
- version: 1,
29106
- network: tx.tokenTransaction.network,
29107
- tokenInputs: tx.tokenTransaction.tokenInputs,
29108
- tokenOutputs: tx.tokenTransaction.tokenOutputs,
29109
- sparkOperatorIdentityPublicKeys: tx.tokenTransaction.sparkOperatorIdentityPublicKeys,
29110
- expiryTime: void 0,
29111
- // V0 doesn't have expiry time
29112
- clientCreatedTimestamp: tx.tokenTransaction?.tokenInputs?.$case === "mintInput" ? new Date(
29113
- tx.tokenTransaction.tokenInputs.mintInput.issuerProvidedTimestamp * 1e3
29114
- ) : /* @__PURE__ */ new Date(),
29115
- invoiceAttachments: []
29116
- };
29117
- return {
29118
- tokenTransaction: v1TokenTransaction,
29119
- status: tx.status,
29120
- confirmationMetadata: tx.confirmationMetadata,
29121
- tokenTransactionHash: tx.tokenTransactionHash
29122
- };
29123
- }
29124
- ),
29125
- offset: response.offset
29126
- };
29127
- } catch (error) {
29128
- throw new NetworkError(
29129
- "Failed to query token transactions",
29130
- {
29131
- operation: "spark.query_token_transactions",
29132
- errorCount: 1,
29133
- errors: error instanceof Error ? error.message : String(error)
29134
- },
29135
- error
29136
- );
29137
- }
29138
- }
29139
- async queryTokenTransactionsV1(params) {
28842
+ async queryTokenTransactions(params) {
29140
28843
  const {
29141
28844
  ownerPublicKeys,
29142
28845
  issuerPublicKeys,
@@ -29249,50 +28952,6 @@ var TokenTransactionService = class {
29249
28952
  });
29250
28953
  }
29251
28954
  }
29252
- async finalizeTokenTransaction(finalTokenTransaction, revocationSecrets, threshold) {
29253
- const signingOperators = this.config.getSigningOperators();
29254
- const soResponses = await Promise.allSettled(
29255
- Object.entries(signingOperators).map(async ([identifier, operator]) => {
29256
- const internalSparkClient = await this.connectionManager.createSparkClient(operator.address);
29257
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
29258
- try {
29259
- const response = await internalSparkClient.finalize_token_transaction(
29260
- {
29261
- finalTokenTransaction,
29262
- revocationSecrets,
29263
- identityPublicKey
29264
- },
29265
- {
29266
- retry: true,
29267
- retryableStatuses: [
29268
- "UNKNOWN",
29269
- "UNAVAILABLE",
29270
- "CANCELLED",
29271
- "INTERNAL"
29272
- ],
29273
- retryMaxAttempts: 3
29274
- }
29275
- );
29276
- return {
29277
- identifier,
29278
- response
29279
- };
29280
- } catch (error) {
29281
- throw new NetworkError(
29282
- "Failed to finalize token transaction",
29283
- {
29284
- operation: "finalize_token_transaction",
29285
- errorCount: 1,
29286
- errors: error instanceof Error ? error.message : String(error)
29287
- },
29288
- error
29289
- );
29290
- }
29291
- })
29292
- );
29293
- collectResponses(soResponses);
29294
- return finalTokenTransaction;
29295
- }
29296
28955
  async createSignaturesForOperators(finalTokenTransaction, finalTokenTransactionHash, signingOperators) {
29297
28956
  const inputTtxoSignaturesPerOperator = [];
29298
28957
  for (const [_, operator] of Object.entries(signingOperators)) {
@@ -29369,28 +29028,25 @@ var TokenTransactionService = class {
29369
29028
  return inputTtxoSignaturesPerOperator;
29370
29029
  }
29371
29030
  };
29372
- function isTokenTransaction(tokenTransaction) {
29373
- return "version" in tokenTransaction && "expiryTime" in tokenTransaction;
29374
- }
29375
29031
 
29376
29032
  // src/utils/adaptor-signature.ts
29377
29033
  import { mod } from "@noble/curves/abstract/modular";
29378
- import { schnorr as schnorr5, secp256k1 as secp256k112 } from "@noble/curves/secp256k1";
29034
+ import { schnorr as schnorr5, secp256k1 as secp256k110 } from "@noble/curves/secp256k1";
29379
29035
  import { bytesToNumberBE as bytesToNumberBE7, numberToBytesBE as numberToBytesBE5 } from "@noble/curves/utils";
29380
29036
  function generateSignatureFromExistingAdaptor(signature, adaptorPrivateKeyBytes) {
29381
29037
  const { r, s } = parseSignature(signature);
29382
29038
  const sBigInt = bytesToNumberBE7(s);
29383
29039
  const tBigInt = bytesToNumberBE7(adaptorPrivateKeyBytes);
29384
- const newS = mod(sBigInt - tBigInt, secp256k112.CURVE.n);
29040
+ const newS = mod(sBigInt - tBigInt, secp256k110.CURVE.n);
29385
29041
  const newSignature = new Uint8Array([...r, ...numberToBytesBE5(newS, 32)]);
29386
29042
  return newSignature;
29387
29043
  }
29388
29044
  function generateAdaptorFromSignature(signature) {
29389
- const adaptorPrivateKey = secp256k112.utils.randomPrivateKey();
29045
+ const adaptorPrivateKey = secp256k110.utils.randomPrivateKey();
29390
29046
  const { r, s } = parseSignature(signature);
29391
29047
  const sBigInt = bytesToNumberBE7(s);
29392
29048
  const tBigInt = bytesToNumberBE7(adaptorPrivateKey);
29393
- const newS = mod(sBigInt - tBigInt, secp256k112.CURVE.n);
29049
+ const newS = mod(sBigInt - tBigInt, secp256k110.CURVE.n);
29394
29050
  const newSignature = new Uint8Array([...r, ...numberToBytesBE5(newS, 32)]);
29395
29051
  return {
29396
29052
  adaptorSignature: newSignature,
@@ -29410,7 +29066,7 @@ function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes
29410
29066
  const { r, s } = parseSignature(signature);
29411
29067
  const sBigInt = bytesToNumberBE7(s);
29412
29068
  const adaptorPrivateKey = bytesToNumberBE7(adaptorPrivateKeyBytes);
29413
- const newS = mod(sBigInt + adaptorPrivateKey, secp256k112.CURVE.n);
29069
+ const newS = mod(sBigInt + adaptorPrivateKey, secp256k110.CURVE.n);
29414
29070
  const newSig = new Uint8Array([...r, ...numberToBytesBE5(newS, 32)]);
29415
29071
  try {
29416
29072
  if (schnorr5.verify(newSig, hash, pubkey)) {
@@ -29419,7 +29075,7 @@ function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes
29419
29075
  } catch (e) {
29420
29076
  console.error("[applyAdaptorToSignature] Addition verification failed:", e);
29421
29077
  }
29422
- const altS = mod(sBigInt - adaptorPrivateKey, secp256k112.CURVE.n);
29078
+ const altS = mod(sBigInt - adaptorPrivateKey, secp256k110.CURVE.n);
29423
29079
  const altSig = new Uint8Array([...r, ...numberToBytesBE5(altS, 32)]);
29424
29080
  try {
29425
29081
  if (schnorr5.verify(altSig, hash, pubkey)) {
@@ -29449,18 +29105,18 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
29449
29105
  if (commitmenet.length > 32) {
29450
29106
  throw new Error("hash of (r || P || m) too big");
29451
29107
  }
29452
- const e = mod(bytesToNumberBE7(commitmenet), secp256k112.CURVE.n);
29453
- const negE = mod(-e, secp256k112.CURVE.n);
29454
- const sG = secp256k112.Point.BASE.multiplyUnsafe(bytesToNumberBE7(s));
29108
+ const e = mod(bytesToNumberBE7(commitmenet), secp256k110.CURVE.n);
29109
+ const negE = mod(-e, secp256k110.CURVE.n);
29110
+ const sG = secp256k110.Point.BASE.multiplyUnsafe(bytesToNumberBE7(s));
29455
29111
  const eP = pubKey.multiplyUnsafe(negE);
29456
29112
  const R = sG.add(eP);
29457
29113
  if (R.is0()) {
29458
29114
  throw new Error("R is zero");
29459
29115
  }
29460
29116
  R.assertValidity();
29461
- const adaptorPoint = secp256k112.Point.fromHex(adaptorPubkey);
29117
+ const adaptorPoint = secp256k110.Point.fromHex(adaptorPubkey);
29462
29118
  const newR = R.add(adaptorPoint);
29463
- if (!inbound && newR.equals(secp256k112.Point.ZERO)) {
29119
+ if (!inbound && newR.equals(secp256k110.Point.ZERO)) {
29464
29120
  throw new Error("calculated R point is the point at infinity");
29465
29121
  }
29466
29122
  newR.assertValidity();
@@ -29488,16 +29144,16 @@ function parseSignature(signature) {
29488
29144
  }
29489
29145
  const r = signature.slice(0, 32);
29490
29146
  const s = signature.slice(32, 64);
29491
- if (bytesToNumberBE7(r) >= secp256k112.CURVE.Fp.ORDER) {
29147
+ if (bytesToNumberBE7(r) >= secp256k110.CURVE.Fp.ORDER) {
29492
29148
  throw new ValidationError("Invalid signature: r >= field prime", {
29493
29149
  rValue: bytesToNumberBE7(r),
29494
- fieldPrime: secp256k112.CURVE.Fp.ORDER
29150
+ fieldPrime: secp256k110.CURVE.Fp.ORDER
29495
29151
  });
29496
29152
  }
29497
- if (bytesToNumberBE7(s) >= secp256k112.CURVE.n) {
29153
+ if (bytesToNumberBE7(s) >= secp256k110.CURVE.n) {
29498
29154
  throw new ValidationError("Invalid signature: s >= group order", {
29499
29155
  sValue: bytesToNumberBE7(s),
29500
- groupOrder: secp256k112.CURVE.n
29156
+ groupOrder: secp256k110.CURVE.n
29501
29157
  });
29502
29158
  }
29503
29159
  return { r, s };
@@ -29679,7 +29335,7 @@ var SigningService = class {
29679
29335
  };
29680
29336
 
29681
29337
  // src/tests/utils/test-faucet.ts
29682
- import { schnorr as schnorr6, secp256k1 as secp256k113 } from "@noble/curves/secp256k1";
29338
+ import { schnorr as schnorr6, secp256k1 as secp256k111 } from "@noble/curves/secp256k1";
29683
29339
  import { bytesToHex as bytesToHex9, hexToBytes as hexToBytes10 } from "@noble/curves/utils";
29684
29340
  import * as btc3 from "@scure/btc-signer";
29685
29341
  import { Address as Address3, OutScript as OutScript2, SigHash as SigHash2, Transaction as Transaction6 } from "@scure/btc-signer";
@@ -29700,7 +29356,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
29700
29356
  this.username = username;
29701
29357
  this.password = password;
29702
29358
  this.miningAddress = getP2TRAddressFromPublicKey(
29703
- secp256k113.getPublicKey(STATIC_MINING_KEY),
29359
+ secp256k111.getPublicKey(STATIC_MINING_KEY),
29704
29360
  4 /* LOCAL */
29705
29361
  );
29706
29362
  }
@@ -29739,7 +29395,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
29739
29395
  });
29740
29396
  }
29741
29397
  async refill() {
29742
- const minerPubKey = secp256k113.getPublicKey(STATIC_MINING_KEY);
29398
+ const minerPubKey = secp256k111.getPublicKey(STATIC_MINING_KEY);
29743
29399
  const address2 = getP2TRAddressFromPublicKey(minerPubKey, 4 /* LOCAL */);
29744
29400
  const scanResult = await this.call("scantxoutset", [
29745
29401
  "start",
@@ -29788,7 +29444,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
29788
29444
  txid: selectedUtxo.txid,
29789
29445
  index: selectedUtxo.vout
29790
29446
  });
29791
- const faucetPubKey = secp256k113.getPublicKey(STATIC_FAUCET_KEY);
29447
+ const faucetPubKey = secp256k111.getPublicKey(STATIC_FAUCET_KEY);
29792
29448
  const script = getP2TRScriptFromPublicKey(faucetPubKey, 4 /* LOCAL */);
29793
29449
  for (let i = 0; i < numCoinsToCreate; i++) {
29794
29450
  splitTx.addOutput({
@@ -29849,7 +29505,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
29849
29505
  await this.broadcastTx(bytesToHex9(signedTx.extract()));
29850
29506
  }
29851
29507
  async signFaucetCoin(unsignedTx, fundingTxOut, key) {
29852
- const pubKey = secp256k113.getPublicKey(key);
29508
+ const pubKey = secp256k111.getPublicKey(key);
29853
29509
  const internalKey = pubKey.slice(1);
29854
29510
  const script = getP2TRScriptFromPublicKey(pubKey, 4 /* LOCAL */);
29855
29511
  unsignedTx.updateInput(0, {
@@ -29932,8 +29588,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
29932
29588
  return response;
29933
29589
  }
29934
29590
  async getNewAddress() {
29935
- const key = secp256k113.utils.randomPrivateKey();
29936
- const pubKey = secp256k113.getPublicKey(key);
29591
+ const key = secp256k111.utils.randomPrivateKey();
29592
+ const pubKey = secp256k111.getPublicKey(key);
29937
29593
  return getP2TRAddressFromPublicKey(pubKey, 4 /* LOCAL */);
29938
29594
  }
29939
29595
  async sendToAddress(address2, amount, blocksToGenerate = 1) {
@@ -29954,8 +29610,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
29954
29610
  });
29955
29611
  const changeAmount = availableAmount - amount;
29956
29612
  if (changeAmount > 0) {
29957
- const changeKey = secp256k113.utils.randomPrivateKey();
29958
- const changePubKey = secp256k113.getPublicKey(changeKey);
29613
+ const changeKey = secp256k111.utils.randomPrivateKey();
29614
+ const changePubKey = secp256k111.getPublicKey(changeKey);
29959
29615
  const changeScript = getP2TRScriptFromPublicKey(
29960
29616
  changePubKey,
29961
29617
  4 /* LOCAL */
@@ -29968,8 +29624,8 @@ var BitcoinFaucet = class _BitcoinFaucet {
29968
29624
  const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
29969
29625
  const txHex = bytesToHex9(signedTx.extract());
29970
29626
  await this.broadcastTx(txHex);
29971
- const randomKey = secp256k113.utils.randomPrivateKey();
29972
- const randomPubKey = secp256k113.getPublicKey(randomKey);
29627
+ const randomKey = secp256k111.utils.randomPrivateKey();
29628
+ const randomPubKey = secp256k111.getPublicKey(randomKey);
29973
29629
  const randomAddress = getP2TRAddressFromPublicKey(
29974
29630
  randomPubKey,
29975
29631
  4 /* LOCAL */
@@ -30632,47 +30288,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30632
30288
  senderPublicKey,
30633
30289
  expiryTime
30634
30290
  }) {
30635
- const MAX_SATS_AMOUNT = 21e14;
30636
- if (amount && (amount < 0 || amount > MAX_SATS_AMOUNT)) {
30637
- throw new ValidationError(
30638
- `Amount must be between 0 and ${MAX_SATS_AMOUNT} sats`,
30639
- {
30640
- field: "amount",
30641
- value: amount,
30642
- expected: `less than or equal to ${MAX_SATS_AMOUNT}`
30643
- }
30644
- );
30645
- }
30646
- const protoPayment = {
30647
- $case: "satsPayment",
30648
- satsPayment: {
30649
- amount
30650
- }
30651
- };
30652
- const invoiceFields = {
30653
- version: 1,
30654
- id: uuidv7obj().bytes,
30655
- paymentType: protoPayment,
30656
- memo,
30657
- senderPublicKey: senderPublicKey ? hexToBytes11(senderPublicKey) : void 0,
30658
- expiryTime: expiryTime ?? void 0
30659
- };
30660
- validateSparkInvoiceFields(invoiceFields);
30661
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
30662
- const hash = HashSparkInvoice(
30663
- invoiceFields,
30664
- identityPublicKey,
30665
- this.config.getNetworkType()
30666
- );
30667
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
30668
- return encodeSparkAddressWithSignature(
30669
- {
30670
- identityPublicKey: bytesToHex11(identityPublicKey),
30671
- network: this.config.getNetworkType(),
30672
- sparkInvoiceFields: invoiceFields
30673
- },
30674
- signature
30675
- );
30291
+ throw new NotImplementedError("Invoice functionality is not enabled");
30676
30292
  }
30677
30293
  /**
30678
30294
  * Creates a Spark invoice for a tokens payment on Spark.
@@ -30692,52 +30308,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
30692
30308
  senderPublicKey,
30693
30309
  expiryTime
30694
30310
  }) {
30695
- const MAX_UINT128 = BigInt(2 ** 128 - 1);
30696
- if (amount && (amount < 0 || amount > MAX_UINT128)) {
30697
- throw new ValidationError(`Amount must be between 0 and ${MAX_UINT128}`, {
30698
- field: "amount",
30699
- value: amount,
30700
- expected: `greater than or equal to 0 and less than or equal to ${MAX_UINT128}`
30701
- });
30702
- }
30703
- let decodedTokenIdentifier = void 0;
30704
- if (tokenIdentifier) {
30705
- decodedTokenIdentifier = decodeBech32mTokenIdentifier(
30706
- tokenIdentifier,
30707
- this.config.getNetworkType()
30708
- ).tokenIdentifier;
30709
- }
30710
- const protoPayment = {
30711
- $case: "tokensPayment",
30712
- tokensPayment: {
30713
- tokenIdentifier: decodedTokenIdentifier ?? void 0,
30714
- amount: amount ? numberToVarBytesBE(amount) : void 0
30715
- }
30716
- };
30717
- const invoiceFields = {
30718
- version: 1,
30719
- id: uuidv7obj().bytes,
30720
- paymentType: protoPayment,
30721
- memo: memo ?? void 0,
30722
- senderPublicKey: senderPublicKey ? hexToBytes11(senderPublicKey) : void 0,
30723
- expiryTime: expiryTime ?? void 0
30724
- };
30725
- validateSparkInvoiceFields(invoiceFields);
30726
- const identityPublicKey = await this.config.signer.getIdentityPublicKey();
30727
- const hash = HashSparkInvoice(
30728
- invoiceFields,
30729
- identityPublicKey,
30730
- this.config.getNetworkType()
30731
- );
30732
- const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
30733
- return encodeSparkAddressWithSignature(
30734
- {
30735
- identityPublicKey: bytesToHex11(identityPublicKey),
30736
- network: this.config.getNetworkType(),
30737
- sparkInvoiceFields: invoiceFields
30738
- },
30739
- signature
30740
- );
30311
+ throw new NotImplementedError("Invoice functionality is not enabled");
30741
30312
  }
30742
30313
  /**
30743
30314
  * Initializes the wallet using either a mnemonic phrase or a raw seed.
@@ -31062,7 +30633,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
31062
30633
  }
31063
30634
  const sspClient = this.getSspClient();
31064
30635
  const cpfpAdaptorPubkey = bytesToHex11(
31065
- secp256k114.getPublicKey(cpfpAdaptorPrivateKey)
30636
+ secp256k112.getPublicKey(cpfpAdaptorPrivateKey)
31066
30637
  );
31067
30638
  if (!cpfpAdaptorPubkey) {
31068
30639
  throw new Error("Failed to generate CPFP adaptor pubkey");
@@ -31070,13 +30641,13 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
31070
30641
  let directAdaptorPubkey;
31071
30642
  if (directAdaptorPrivateKey.length > 0) {
31072
30643
  directAdaptorPubkey = bytesToHex11(
31073
- secp256k114.getPublicKey(directAdaptorPrivateKey)
30644
+ secp256k112.getPublicKey(directAdaptorPrivateKey)
31074
30645
  );
31075
30646
  }
31076
30647
  let directFromCpfpAdaptorPubkey;
31077
30648
  if (directFromCpfpAdaptorPrivateKey.length > 0) {
31078
30649
  directFromCpfpAdaptorPubkey = bytesToHex11(
31079
- secp256k114.getPublicKey(directFromCpfpAdaptorPrivateKey)
30650
+ secp256k112.getPublicKey(directFromCpfpAdaptorPrivateKey)
31080
30651
  );
31081
30652
  }
31082
30653
  let request = null;
@@ -32691,10 +32262,30 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
32691
32262
  if (!invoice2) {
32692
32263
  throw new Error("Failed to create lightning invoice");
32693
32264
  }
32265
+ const decodedInvoice = decodeInvoice(invoice2.invoice.encodedInvoice);
32266
+ if (invoice2.invoice.paymentHash !== bytesToHex11(paymentHash) || decodedInvoice.paymentHash !== bytesToHex11(paymentHash)) {
32267
+ throw new ValidationError("Payment hash mismatch", {
32268
+ field: "paymentHash",
32269
+ value: invoice2.invoice.paymentHash,
32270
+ expected: bytesToHex11(paymentHash)
32271
+ });
32272
+ }
32273
+ if (decodedInvoice.amountMSats === null && amountSats2 !== 0) {
32274
+ throw new ValidationError("Amount mismatch", {
32275
+ field: "amountMSats",
32276
+ value: "null",
32277
+ expected: amountSats2 * 1e3
32278
+ });
32279
+ }
32280
+ if (decodedInvoice.amountMSats !== null && decodedInvoice.amountMSats !== BigInt(amountSats2 * 1e3)) {
32281
+ throw new ValidationError("Amount mismatch", {
32282
+ field: "amountMSats",
32283
+ value: decodedInvoice.amountMSats,
32284
+ expected: amountSats2 * 1e3
32285
+ });
32286
+ }
32694
32287
  if (includeSparkAddress) {
32695
- const sparkFallbackAddress = decodeInvoice(
32696
- invoice2.invoice.encodedInvoice
32697
- ).fallbackAddress;
32288
+ const sparkFallbackAddress = decodedInvoice.fallbackAddress;
32698
32289
  if (!sparkFallbackAddress) {
32699
32290
  throw new ValidationError(
32700
32291
  "No spark fallback address found in lightning invoice",
@@ -32716,6 +32307,14 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
32716
32307
  }
32717
32308
  );
32718
32309
  }
32310
+ } else if (decodedInvoice.fallbackAddress !== void 0) {
32311
+ throw new ValidationError(
32312
+ "Spark fallback address found in lightning invoice but includeSparkAddress is false",
32313
+ {
32314
+ field: "sparkFallbackAddress",
32315
+ value: decodedInvoice.fallbackAddress
32316
+ }
32317
+ );
32719
32318
  }
32720
32319
  return invoice2;
32721
32320
  };
@@ -32883,91 +32482,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
32883
32482
  });
32884
32483
  }
32885
32484
  async fulfillSparkInvoice(sparkInvoices) {
32886
- if (!Array.isArray(sparkInvoices) || sparkInvoices.length === 0) {
32887
- throw new ValidationError("No Spark invoices provided", {
32888
- field: "sparkInvoices",
32889
- value: sparkInvoices,
32890
- expected: "Non-empty array"
32891
- });
32892
- }
32893
- const satsTransactionSuccess = [];
32894
- const satsTransactionErrors = [];
32895
- const tokenTransactionSuccess = [];
32896
- const tokenTransactionErrors = [];
32897
- const { satsInvoices, tokenInvoices, invalidInvoices } = await this.groupSparkInvoicesByPaymentType(sparkInvoices);
32898
- if (invalidInvoices.length > 0) {
32899
- return {
32900
- satsTransactionSuccess,
32901
- satsTransactionErrors,
32902
- tokenTransactionSuccess,
32903
- tokenTransactionErrors,
32904
- invalidInvoices
32905
- };
32906
- }
32907
- if (tokenInvoices.size > 0) {
32908
- await this.syncTokenOutputs();
32909
- const tokenTransferTasks = [];
32910
- for (const [identifierHex, decodedInvoices] of tokenInvoices.entries()) {
32911
- const tokenIdentifier = hexToBytes11(identifierHex);
32912
- const tokenIdB32 = encodeBech32mTokenIdentifier({
32913
- tokenIdentifier,
32914
- network: this.config.getNetworkType()
32915
- });
32916
- const receiverOutputs = decodedInvoices.map((d) => ({
32917
- tokenIdentifier: tokenIdB32,
32918
- tokenAmount: d.amount,
32919
- receiverSparkAddress: d.invoice
32920
- }));
32921
- tokenTransferTasks.push(
32922
- this.tokenTransactionService.tokenTransfer({ tokenOutputs: this.tokenOutputs, receiverOutputs }).then((txid) => ({
32923
- ok: true,
32924
- tokenIdentifier: tokenIdB32,
32925
- txid
32926
- })).catch((e) => ({
32927
- ok: false,
32928
- tokenIdentifier: tokenIdB32,
32929
- error: e instanceof Error ? e : new Error(String(e))
32930
- }))
32931
- );
32932
- }
32933
- const results = await Promise.all(tokenTransferTasks);
32934
- for (const r of results) {
32935
- if (r.ok) {
32936
- tokenTransactionSuccess.push({
32937
- tokenIdentifier: r.tokenIdentifier,
32938
- txid: r.txid
32939
- });
32940
- } else {
32941
- tokenTransactionErrors.push({
32942
- tokenIdentifier: r.tokenIdentifier,
32943
- error: r.error
32944
- });
32945
- }
32946
- }
32947
- }
32948
- if (satsInvoices.length > 0) {
32949
- const transfers = await this.transferWithInvoice(satsInvoices);
32950
- for (const transfer of transfers) {
32951
- if (transfer.ok) {
32952
- satsTransactionSuccess.push({
32953
- invoice: transfer.param.sparkInvoice ?? "",
32954
- transferResponse: transfer.transfer
32955
- });
32956
- } else {
32957
- satsTransactionErrors.push({
32958
- invoice: transfer.param.sparkInvoice ?? "",
32959
- error: transfer.error
32960
- });
32961
- }
32962
- }
32963
- }
32964
- return {
32965
- satsTransactionSuccess,
32966
- satsTransactionErrors,
32967
- tokenTransactionSuccess,
32968
- tokenTransactionErrors,
32969
- invalidInvoices
32970
- };
32485
+ throw new NotImplementedError("Invoice functionality is not enabled");
32971
32486
  }
32972
32487
  async groupSparkInvoicesByPaymentType(sparkInvoices) {
32973
32488
  const satsInvoices = [];
@@ -33104,6 +32619,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
33104
32619
  });
33105
32620
  return { satsInvoices, tokenInvoices, invalidInvoices };
33106
32621
  }
32622
+ async querySparkInvoices(invoices) {
32623
+ throw new NotImplementedError("Invoice functionality is not enabled");
32624
+ }
33107
32625
  /**
33108
32626
  * Gets fee estimate for sending Lightning payments.
33109
32627
  *
@@ -34222,6 +33740,27 @@ async function isTxBroadcast(txid, baseUrl, network) {
34222
33740
  return true;
34223
33741
  }
34224
33742
 
33743
+ // src/utils/response-validation.ts
33744
+ function collectResponses(responses) {
33745
+ const successfulResponses = responses.filter(
33746
+ (result) => result.status === "fulfilled"
33747
+ ).map((result) => result.value);
33748
+ const failedResponses = responses.filter(
33749
+ (result) => result.status === "rejected"
33750
+ );
33751
+ if (failedResponses.length > 0) {
33752
+ const errors = failedResponses.map((result) => result.reason).join("\n");
33753
+ throw new NetworkError(
33754
+ `${failedResponses.length} out of ${responses.length} requests failed, please try again`,
33755
+ {
33756
+ errorCount: failedResponses.length,
33757
+ errors
33758
+ }
33759
+ );
33760
+ }
33761
+ return successfulResponses;
33762
+ }
33763
+
34225
33764
  // src/utils/unilateral-exit.ts
34226
33765
  import { bytesToHex as bytesToHex12, hexToBytes as hexToBytes12 } from "@noble/curves/utils";
34227
33766
  import { ripemd160 } from "@noble/hashes/legacy";
@@ -34762,6 +34301,7 @@ export {
34762
34301
  addPublicKeys,
34763
34302
  applyAdaptorToSignature,
34764
34303
  applyAdditiveTweakToPublicKey,
34304
+ assertBech32,
34765
34305
  bech32mDecode,
34766
34306
  bigIntToPrivateKey,
34767
34307
  checkIfSelectedOutputsAreAvailable,
@@ -34824,6 +34364,7 @@ export {
34824
34364
  getTxId,
34825
34365
  getTxIdNoReverse,
34826
34366
  isEphemeralAnchorOutput,
34367
+ isLegacySparkAddress,
34827
34368
  isSafeForNumber,
34828
34369
  isTxBroadcast,
34829
34370
  isValidPublicKey,