@buildonspark/spark-sdk 0.1.39 → 0.1.41

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 (125) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -1
  3. package/dist/{RequestLightningSendInput-39_zGri6.d.cts → RequestLightningSendInput-DXcLoiCe.d.cts} +10 -2
  4. package/dist/{RequestLightningSendInput-B4JdzclX.d.ts → RequestLightningSendInput-mXUWn_cp.d.ts} +10 -2
  5. package/dist/address/index.cjs +138 -6
  6. package/dist/address/index.d.cts +18 -6
  7. package/dist/address/index.d.ts +18 -6
  8. package/dist/address/index.js +5 -2
  9. package/dist/{chunk-FWQPAPXK.js → chunk-2ZXXLPG2.js} +1 -1
  10. package/dist/{chunk-S7KD6DDL.js → chunk-6YVPOQ2A.js} +41 -20
  11. package/dist/{chunk-ZUVYYR5T.js → chunk-7EFSUADA.js} +1 -0
  12. package/dist/{chunk-NS4UZRQ7.js → chunk-ABZA6R5S.js} +1 -1
  13. package/dist/{chunk-57XLH3ZR.js → chunk-ATEHMLKP.js} +23 -23
  14. package/dist/{chunk-VJTDG4BQ.js → chunk-HK6LPV6Z.js} +10 -1
  15. package/dist/{chunk-W3EC5XSA.js → chunk-J5W5Q2ZP.js} +337 -72
  16. package/dist/{chunk-TKYOYOYJ.js → chunk-KKSU7OZO.js} +653 -76
  17. package/dist/chunk-L3EHBOUX.js +0 -0
  18. package/dist/{chunk-C5LTJBI7.js → chunk-M6A4KFIG.js} +125 -226
  19. package/dist/{chunk-A74XSEW3.js → chunk-MIVX3GHD.js} +1 -1
  20. package/dist/{chunk-RGWBSZIO.js → chunk-ROKY5KS4.js} +23 -3
  21. package/dist/{chunk-LIP2K6KR.js → chunk-TM4TOEOX.js} +26 -8
  22. package/dist/{chunk-RAPBVYJY.js → chunk-UKT6OFLO.js} +125 -35
  23. package/dist/chunk-VA7MV4MZ.js +1073 -0
  24. package/dist/chunk-YEZDPUFY.js +840 -0
  25. package/dist/{chunk-DI7QXUQJ.js → chunk-ZXDE2XMU.js} +8 -5
  26. package/dist/graphql/objects/index.cjs +6 -3
  27. package/dist/graphql/objects/index.d.cts +6 -5
  28. package/dist/graphql/objects/index.d.ts +6 -5
  29. package/dist/graphql/objects/index.js +1 -1
  30. package/dist/{index-DEo_hdN3.d.cts → index-CFh4uWzi.d.cts} +60 -6
  31. package/dist/{index-BVY0yH_H.d.ts → index-OSDtPMmC.d.ts} +60 -6
  32. package/dist/index.cjs +3316 -954
  33. package/dist/index.d.cts +9 -8
  34. package/dist/index.d.ts +9 -8
  35. package/dist/index.js +48 -26
  36. package/dist/index.node.cjs +3316 -954
  37. package/dist/index.node.d.cts +9 -8
  38. package/dist/index.node.d.ts +9 -8
  39. package/dist/index.node.js +48 -26
  40. package/dist/native/index.cjs +3323 -961
  41. package/dist/native/index.d.cts +542 -260
  42. package/dist/native/index.d.ts +542 -260
  43. package/dist/native/index.js +3192 -838
  44. package/dist/{network-DobHpaV6.d.ts → network-BF2GYPye.d.ts} +9 -2
  45. package/dist/{network-GFGEHkS4.d.cts → network-BiwBmoOg.d.cts} +9 -2
  46. package/dist/proto/lrc20.d.cts +1 -1
  47. package/dist/proto/lrc20.d.ts +1 -1
  48. package/dist/proto/lrc20.js +2 -2
  49. package/dist/proto/spark.cjs +125 -226
  50. package/dist/proto/spark.d.cts +1 -1
  51. package/dist/proto/spark.d.ts +1 -1
  52. package/dist/proto/spark.js +3 -5
  53. package/dist/proto/spark_token.cjs +1364 -0
  54. package/dist/proto/spark_token.d.cts +209 -0
  55. package/dist/proto/spark_token.d.ts +209 -0
  56. package/dist/proto/spark_token.js +32 -0
  57. package/dist/{sdk-types-BuVMn2rX.d.cts → sdk-types-CfhdFnsA.d.cts} +1 -1
  58. package/dist/{sdk-types-BeI6DM_M.d.ts → sdk-types-MnQrHolg.d.ts} +1 -1
  59. package/dist/services/config.cjs +64 -40
  60. package/dist/services/config.d.cts +6 -5
  61. package/dist/services/config.d.ts +6 -5
  62. package/dist/services/config.js +7 -7
  63. package/dist/services/connection.cjs +1108 -306
  64. package/dist/services/connection.d.cts +10 -5
  65. package/dist/services/connection.d.ts +10 -5
  66. package/dist/services/connection.js +3 -2
  67. package/dist/services/index.cjs +1702 -488
  68. package/dist/services/index.d.cts +6 -5
  69. package/dist/services/index.d.ts +6 -5
  70. package/dist/services/index.js +16 -14
  71. package/dist/services/lrc-connection.d.cts +5 -5
  72. package/dist/services/lrc-connection.d.ts +5 -5
  73. package/dist/services/lrc-connection.js +3 -3
  74. package/dist/services/token-transactions.cjs +637 -247
  75. package/dist/services/token-transactions.d.cts +19 -8
  76. package/dist/services/token-transactions.d.ts +19 -8
  77. package/dist/services/token-transactions.js +5 -4
  78. package/dist/services/wallet-config.cjs +1 -0
  79. package/dist/services/wallet-config.d.cts +6 -5
  80. package/dist/services/wallet-config.d.ts +6 -5
  81. package/dist/services/wallet-config.js +1 -1
  82. package/dist/signer/signer.cjs +122 -35
  83. package/dist/signer/signer.d.cts +4 -3
  84. package/dist/signer/signer.d.ts +4 -3
  85. package/dist/signer/signer.js +8 -4
  86. package/dist/{signer-C1t40Wus.d.cts → signer-BhLS7SYR.d.cts} +35 -14
  87. package/dist/{signer-DFGw9RRp.d.ts → signer-CylxIujU.d.ts} +35 -14
  88. package/dist/{spark-DXYE9gMM.d.ts → spark-DjR1b3TC.d.cts} +13 -21
  89. package/dist/{spark-DXYE9gMM.d.cts → spark-DjR1b3TC.d.ts} +13 -21
  90. package/dist/types/index.cjs +130 -227
  91. package/dist/types/index.d.cts +6 -5
  92. package/dist/types/index.d.ts +6 -5
  93. package/dist/types/index.js +3 -3
  94. package/dist/utils/index.cjs +1169 -3
  95. package/dist/utils/index.d.cts +66 -6
  96. package/dist/utils/index.d.ts +66 -6
  97. package/dist/utils/index.js +35 -14
  98. package/package.json +6 -2
  99. package/src/address/address.ts +41 -6
  100. package/src/graphql/client.ts +15 -0
  101. package/src/graphql/objects/Transfer.ts +7 -0
  102. package/src/graphql/queries/Transfer.ts +10 -0
  103. package/src/proto/spark.ts +215 -337
  104. package/src/proto/spark_token.ts +1407 -0
  105. package/src/services/config.ts +4 -0
  106. package/src/services/connection.ts +37 -1
  107. package/src/services/deposit.ts +23 -5
  108. package/src/services/token-transactions.ts +426 -75
  109. package/src/services/transfer.ts +182 -11
  110. package/src/services/tree-creation.ts +29 -14
  111. package/src/services/wallet-config.ts +2 -0
  112. package/src/signer/signer.ts +190 -48
  113. package/src/spark-wallet/spark-wallet.ts +510 -6
  114. package/src/tests/integration/transfer.test.ts +186 -214
  115. package/src/tests/integration/tree-creation.test.ts +5 -1
  116. package/src/tests/signer.test.ts +34 -0
  117. package/src/tests/transaction.test.ts +12 -0
  118. package/src/tests/xchain-address.test.ts +28 -0
  119. package/src/utils/index.ts +2 -0
  120. package/src/utils/mempool.ts +26 -1
  121. package/src/utils/network.ts +15 -0
  122. package/src/utils/transaction.ts +51 -3
  123. package/src/utils/unilateral-exit.ts +729 -0
  124. package/src/utils/xchain-address.ts +36 -0
  125. package/dist/chunk-E5SL7XTO.js +0 -301
@@ -877,6 +877,9 @@ function tokenTransactionStatusFromJSON(object) {
877
877
  case 1:
878
878
  case "TOKEN_TRANSACTION_SIGNED":
879
879
  return 1 /* TOKEN_TRANSACTION_SIGNED */;
880
+ case 5:
881
+ case "TOKEN_TRANSACTION_REVEALED":
882
+ return 5 /* TOKEN_TRANSACTION_REVEALED */;
880
883
  case 2:
881
884
  case "TOKEN_TRANSACTION_FINALIZED":
882
885
  return 2 /* TOKEN_TRANSACTION_FINALIZED */;
@@ -901,6 +904,8 @@ function tokenTransactionStatusToJSON(object) {
901
904
  return "TOKEN_TRANSACTION_STARTED";
902
905
  case 1 /* TOKEN_TRANSACTION_SIGNED */:
903
906
  return "TOKEN_TRANSACTION_SIGNED";
907
+ case 5 /* TOKEN_TRANSACTION_REVEALED */:
908
+ return "TOKEN_TRANSACTION_REVEALED";
904
909
  case 2 /* TOKEN_TRANSACTION_FINALIZED */:
905
910
  return "TOKEN_TRANSACTION_FINALIZED";
906
911
  case 3 /* TOKEN_TRANSACTION_STARTED_CANCELLED */:
@@ -5576,59 +5581,6 @@ var SecretShare = {
5576
5581
  return message;
5577
5582
  }
5578
5583
  };
5579
- function createBaseSecretProof() {
5580
- return { proofs: [] };
5581
- }
5582
- var SecretProof = {
5583
- encode(message, writer = new import_wire5.BinaryWriter()) {
5584
- for (const v of message.proofs) {
5585
- writer.uint32(10).bytes(v);
5586
- }
5587
- return writer;
5588
- },
5589
- decode(input, length) {
5590
- const reader = input instanceof import_wire5.BinaryReader ? input : new import_wire5.BinaryReader(input);
5591
- let end = length === void 0 ? reader.len : reader.pos + length;
5592
- const message = createBaseSecretProof();
5593
- while (reader.pos < end) {
5594
- const tag = reader.uint32();
5595
- switch (tag >>> 3) {
5596
- case 1: {
5597
- if (tag !== 10) {
5598
- break;
5599
- }
5600
- message.proofs.push(reader.bytes());
5601
- continue;
5602
- }
5603
- }
5604
- if ((tag & 7) === 4 || tag === 0) {
5605
- break;
5606
- }
5607
- reader.skip(tag & 7);
5608
- }
5609
- return message;
5610
- },
5611
- fromJSON(object) {
5612
- return {
5613
- proofs: globalThis.Array.isArray(object?.proofs) ? object.proofs.map((e) => bytesFromBase643(e)) : []
5614
- };
5615
- },
5616
- toJSON(message) {
5617
- const obj = {};
5618
- if (message.proofs?.length) {
5619
- obj.proofs = message.proofs.map((e) => base64FromBytes3(e));
5620
- }
5621
- return obj;
5622
- },
5623
- create(base) {
5624
- return SecretProof.fromPartial(base ?? {});
5625
- },
5626
- fromPartial(object) {
5627
- const message = createBaseSecretProof();
5628
- message.proofs = object.proofs?.map((e) => e) || [];
5629
- return message;
5630
- }
5631
- };
5632
5584
  function createBaseLeafRefundTxSigningJob() {
5633
5585
  return { leafId: "", refundTxSigningJob: void 0 };
5634
5586
  }
@@ -6041,7 +5993,6 @@ function createBaseStartTransferRequest() {
6041
5993
  leavesToSend: [],
6042
5994
  receiverIdentityPublicKey: new Uint8Array(0),
6043
5995
  expiryTime: void 0,
6044
- keyTweakProofs: {},
6045
5996
  transferPackage: void 0
6046
5997
  };
6047
5998
  }
@@ -6062,9 +6013,6 @@ var StartTransferRequest = {
6062
6013
  if (message.expiryTime !== void 0) {
6063
6014
  Timestamp.encode(toTimestamp(message.expiryTime), writer.uint32(42).fork()).join();
6064
6015
  }
6065
- Object.entries(message.keyTweakProofs).forEach(([key, value]) => {
6066
- StartTransferRequest_KeyTweakProofsEntry.encode({ key, value }, writer.uint32(50).fork()).join();
6067
- });
6068
6016
  if (message.transferPackage !== void 0) {
6069
6017
  TransferPackage.encode(message.transferPackage, writer.uint32(58).fork()).join();
6070
6018
  }
@@ -6112,16 +6060,6 @@ var StartTransferRequest = {
6112
6060
  message.expiryTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
6113
6061
  continue;
6114
6062
  }
6115
- case 6: {
6116
- if (tag !== 50) {
6117
- break;
6118
- }
6119
- const entry6 = StartTransferRequest_KeyTweakProofsEntry.decode(reader, reader.uint32());
6120
- if (entry6.value !== void 0) {
6121
- message.keyTweakProofs[entry6.key] = entry6.value;
6122
- }
6123
- continue;
6124
- }
6125
6063
  case 7: {
6126
6064
  if (tag !== 58) {
6127
6065
  break;
@@ -6144,10 +6082,6 @@ var StartTransferRequest = {
6144
6082
  leavesToSend: globalThis.Array.isArray(object?.leavesToSend) ? object.leavesToSend.map((e) => LeafRefundTxSigningJob.fromJSON(e)) : [],
6145
6083
  receiverIdentityPublicKey: isSet4(object.receiverIdentityPublicKey) ? bytesFromBase643(object.receiverIdentityPublicKey) : new Uint8Array(0),
6146
6084
  expiryTime: isSet4(object.expiryTime) ? fromJsonTimestamp(object.expiryTime) : void 0,
6147
- keyTweakProofs: isObject(object.keyTweakProofs) ? Object.entries(object.keyTweakProofs).reduce((acc, [key, value]) => {
6148
- acc[key] = SecretProof.fromJSON(value);
6149
- return acc;
6150
- }, {}) : {},
6151
6085
  transferPackage: isSet4(object.transferPackage) ? TransferPackage.fromJSON(object.transferPackage) : void 0
6152
6086
  };
6153
6087
  },
@@ -6168,15 +6102,6 @@ var StartTransferRequest = {
6168
6102
  if (message.expiryTime !== void 0) {
6169
6103
  obj.expiryTime = message.expiryTime.toISOString();
6170
6104
  }
6171
- if (message.keyTweakProofs) {
6172
- const entries = Object.entries(message.keyTweakProofs);
6173
- if (entries.length > 0) {
6174
- obj.keyTweakProofs = {};
6175
- entries.forEach(([k, v]) => {
6176
- obj.keyTweakProofs[k] = SecretProof.toJSON(v);
6177
- });
6178
- }
6179
- }
6180
6105
  if (message.transferPackage !== void 0) {
6181
6106
  obj.transferPackage = TransferPackage.toJSON(message.transferPackage);
6182
6107
  }
@@ -6192,87 +6117,10 @@ var StartTransferRequest = {
6192
6117
  message.leavesToSend = object.leavesToSend?.map((e) => LeafRefundTxSigningJob.fromPartial(e)) || [];
6193
6118
  message.receiverIdentityPublicKey = object.receiverIdentityPublicKey ?? new Uint8Array(0);
6194
6119
  message.expiryTime = object.expiryTime ?? void 0;
6195
- message.keyTweakProofs = Object.entries(object.keyTweakProofs ?? {}).reduce(
6196
- (acc, [key, value]) => {
6197
- if (value !== void 0) {
6198
- acc[key] = SecretProof.fromPartial(value);
6199
- }
6200
- return acc;
6201
- },
6202
- {}
6203
- );
6204
6120
  message.transferPackage = object.transferPackage !== void 0 && object.transferPackage !== null ? TransferPackage.fromPartial(object.transferPackage) : void 0;
6205
6121
  return message;
6206
6122
  }
6207
6123
  };
6208
- function createBaseStartTransferRequest_KeyTweakProofsEntry() {
6209
- return { key: "", value: void 0 };
6210
- }
6211
- var StartTransferRequest_KeyTweakProofsEntry = {
6212
- encode(message, writer = new import_wire5.BinaryWriter()) {
6213
- if (message.key !== "") {
6214
- writer.uint32(10).string(message.key);
6215
- }
6216
- if (message.value !== void 0) {
6217
- SecretProof.encode(message.value, writer.uint32(18).fork()).join();
6218
- }
6219
- return writer;
6220
- },
6221
- decode(input, length) {
6222
- const reader = input instanceof import_wire5.BinaryReader ? input : new import_wire5.BinaryReader(input);
6223
- let end = length === void 0 ? reader.len : reader.pos + length;
6224
- const message = createBaseStartTransferRequest_KeyTweakProofsEntry();
6225
- while (reader.pos < end) {
6226
- const tag = reader.uint32();
6227
- switch (tag >>> 3) {
6228
- case 1: {
6229
- if (tag !== 10) {
6230
- break;
6231
- }
6232
- message.key = reader.string();
6233
- continue;
6234
- }
6235
- case 2: {
6236
- if (tag !== 18) {
6237
- break;
6238
- }
6239
- message.value = SecretProof.decode(reader, reader.uint32());
6240
- continue;
6241
- }
6242
- }
6243
- if ((tag & 7) === 4 || tag === 0) {
6244
- break;
6245
- }
6246
- reader.skip(tag & 7);
6247
- }
6248
- return message;
6249
- },
6250
- fromJSON(object) {
6251
- return {
6252
- key: isSet4(object.key) ? globalThis.String(object.key) : "",
6253
- value: isSet4(object.value) ? SecretProof.fromJSON(object.value) : void 0
6254
- };
6255
- },
6256
- toJSON(message) {
6257
- const obj = {};
6258
- if (message.key !== "") {
6259
- obj.key = message.key;
6260
- }
6261
- if (message.value !== void 0) {
6262
- obj.value = SecretProof.toJSON(message.value);
6263
- }
6264
- return obj;
6265
- },
6266
- create(base) {
6267
- return StartTransferRequest_KeyTweakProofsEntry.fromPartial(base ?? {});
6268
- },
6269
- fromPartial(object) {
6270
- const message = createBaseStartTransferRequest_KeyTweakProofsEntry();
6271
- message.key = object.key ?? "";
6272
- message.value = object.value !== void 0 && object.value !== null ? SecretProof.fromPartial(object.value) : void 0;
6273
- return message;
6274
- }
6275
- };
6276
6124
  function createBaseStartTransferResponse() {
6277
6125
  return { transfer: void 0, signingResults: [] };
6278
6126
  }
@@ -6819,12 +6667,7 @@ var FinalizeTransferRequest = {
6819
6667
  }
6820
6668
  };
6821
6669
  function createBaseFinalizeTransferWithTransferPackageRequest() {
6822
- return {
6823
- transferId: "",
6824
- ownerIdentityPublicKey: new Uint8Array(0),
6825
- transferPackage: void 0,
6826
- refundSignatures: {}
6827
- };
6670
+ return { transferId: "", ownerIdentityPublicKey: new Uint8Array(0), transferPackage: void 0 };
6828
6671
  }
6829
6672
  var FinalizeTransferWithTransferPackageRequest = {
6830
6673
  encode(message, writer = new import_wire5.BinaryWriter()) {
@@ -6837,12 +6680,6 @@ var FinalizeTransferWithTransferPackageRequest = {
6837
6680
  if (message.transferPackage !== void 0) {
6838
6681
  TransferPackage.encode(message.transferPackage, writer.uint32(26).fork()).join();
6839
6682
  }
6840
- Object.entries(message.refundSignatures).forEach(([key, value]) => {
6841
- FinalizeTransferWithTransferPackageRequest_RefundSignaturesEntry.encode(
6842
- { key, value },
6843
- writer.uint32(34).fork()
6844
- ).join();
6845
- });
6846
6683
  return writer;
6847
6684
  },
6848
6685
  decode(input, length) {
@@ -6873,19 +6710,6 @@ var FinalizeTransferWithTransferPackageRequest = {
6873
6710
  message.transferPackage = TransferPackage.decode(reader, reader.uint32());
6874
6711
  continue;
6875
6712
  }
6876
- case 4: {
6877
- if (tag !== 34) {
6878
- break;
6879
- }
6880
- const entry4 = FinalizeTransferWithTransferPackageRequest_RefundSignaturesEntry.decode(
6881
- reader,
6882
- reader.uint32()
6883
- );
6884
- if (entry4.value !== void 0) {
6885
- message.refundSignatures[entry4.key] = entry4.value;
6886
- }
6887
- continue;
6888
- }
6889
6713
  }
6890
6714
  if ((tag & 7) === 4 || tag === 0) {
6891
6715
  break;
@@ -6898,11 +6722,7 @@ var FinalizeTransferWithTransferPackageRequest = {
6898
6722
  return {
6899
6723
  transferId: isSet4(object.transferId) ? globalThis.String(object.transferId) : "",
6900
6724
  ownerIdentityPublicKey: isSet4(object.ownerIdentityPublicKey) ? bytesFromBase643(object.ownerIdentityPublicKey) : new Uint8Array(0),
6901
- transferPackage: isSet4(object.transferPackage) ? TransferPackage.fromJSON(object.transferPackage) : void 0,
6902
- refundSignatures: isObject(object.refundSignatures) ? Object.entries(object.refundSignatures).reduce((acc, [key, value]) => {
6903
- acc[key] = bytesFromBase643(value);
6904
- return acc;
6905
- }, {}) : {}
6725
+ transferPackage: isSet4(object.transferPackage) ? TransferPackage.fromJSON(object.transferPackage) : void 0
6906
6726
  };
6907
6727
  },
6908
6728
  toJSON(message) {
@@ -6916,15 +6736,6 @@ var FinalizeTransferWithTransferPackageRequest = {
6916
6736
  if (message.transferPackage !== void 0) {
6917
6737
  obj.transferPackage = TransferPackage.toJSON(message.transferPackage);
6918
6738
  }
6919
- if (message.refundSignatures) {
6920
- const entries = Object.entries(message.refundSignatures);
6921
- if (entries.length > 0) {
6922
- obj.refundSignatures = {};
6923
- entries.forEach(([k, v]) => {
6924
- obj.refundSignatures[k] = base64FromBytes3(v);
6925
- });
6926
- }
6927
- }
6928
6739
  return obj;
6929
6740
  },
6930
6741
  create(base) {
@@ -6935,83 +6746,6 @@ var FinalizeTransferWithTransferPackageRequest = {
6935
6746
  message.transferId = object.transferId ?? "";
6936
6747
  message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
6937
6748
  message.transferPackage = object.transferPackage !== void 0 && object.transferPackage !== null ? TransferPackage.fromPartial(object.transferPackage) : void 0;
6938
- message.refundSignatures = Object.entries(object.refundSignatures ?? {}).reduce(
6939
- (acc, [key, value]) => {
6940
- if (value !== void 0) {
6941
- acc[key] = value;
6942
- }
6943
- return acc;
6944
- },
6945
- {}
6946
- );
6947
- return message;
6948
- }
6949
- };
6950
- function createBaseFinalizeTransferWithTransferPackageRequest_RefundSignaturesEntry() {
6951
- return { key: "", value: new Uint8Array(0) };
6952
- }
6953
- var FinalizeTransferWithTransferPackageRequest_RefundSignaturesEntry = {
6954
- encode(message, writer = new import_wire5.BinaryWriter()) {
6955
- if (message.key !== "") {
6956
- writer.uint32(10).string(message.key);
6957
- }
6958
- if (message.value.length !== 0) {
6959
- writer.uint32(18).bytes(message.value);
6960
- }
6961
- return writer;
6962
- },
6963
- decode(input, length) {
6964
- const reader = input instanceof import_wire5.BinaryReader ? input : new import_wire5.BinaryReader(input);
6965
- let end = length === void 0 ? reader.len : reader.pos + length;
6966
- const message = createBaseFinalizeTransferWithTransferPackageRequest_RefundSignaturesEntry();
6967
- while (reader.pos < end) {
6968
- const tag = reader.uint32();
6969
- switch (tag >>> 3) {
6970
- case 1: {
6971
- if (tag !== 10) {
6972
- break;
6973
- }
6974
- message.key = reader.string();
6975
- continue;
6976
- }
6977
- case 2: {
6978
- if (tag !== 18) {
6979
- break;
6980
- }
6981
- message.value = reader.bytes();
6982
- continue;
6983
- }
6984
- }
6985
- if ((tag & 7) === 4 || tag === 0) {
6986
- break;
6987
- }
6988
- reader.skip(tag & 7);
6989
- }
6990
- return message;
6991
- },
6992
- fromJSON(object) {
6993
- return {
6994
- key: isSet4(object.key) ? globalThis.String(object.key) : "",
6995
- value: isSet4(object.value) ? bytesFromBase643(object.value) : new Uint8Array(0)
6996
- };
6997
- },
6998
- toJSON(message) {
6999
- const obj = {};
7000
- if (message.key !== "") {
7001
- obj.key = message.key;
7002
- }
7003
- if (message.value.length !== 0) {
7004
- obj.value = base64FromBytes3(message.value);
7005
- }
7006
- return obj;
7007
- },
7008
- create(base) {
7009
- return FinalizeTransferWithTransferPackageRequest_RefundSignaturesEntry.fromPartial(base ?? {});
7010
- },
7011
- fromPartial(object) {
7012
- const message = createBaseFinalizeTransferWithTransferPackageRequest_RefundSignaturesEntry();
7013
- message.key = object.key ?? "";
7014
- message.value = object.value ?? new Uint8Array(0);
7015
6749
  return message;
7016
6750
  }
7017
6751
  };
@@ -14230,39 +13964,1091 @@ function isSet5(value) {
14230
13964
  return value !== null && value !== void 0;
14231
13965
  }
14232
13966
 
14233
- // src/services/connection.ts
14234
- var ConnectionManager = class {
14235
- config;
14236
- clients = /* @__PURE__ */ new Map();
14237
- // We are going to .unref() the underlying channels for stream clients
14238
- // to prevent the stream from keeping the process alive
14239
- // Using a different map to avoid unforeseen problems with unary calls
14240
- streamClients = /* @__PURE__ */ new Map();
14241
- constructor(config) {
14242
- this.config = config;
14243
- }
14244
- // When initializing wallet, go ahead and instantiate all clients
14245
- async createClients() {
14246
- await Promise.all(
14247
- Object.values(this.config.getSigningOperators()).map((operator) => {
14248
- this.createSparkClient(operator.address);
14249
- })
14250
- );
14251
- }
14252
- async closeConnections() {
14253
- await Promise.all(
14254
- Array.from(this.clients.values()).map(
14255
- (client) => client.client.close?.()
14256
- )
14257
- );
14258
- this.clients.clear();
14259
- }
14260
- async createMockClient(address) {
14261
- const channel = await this.createChannelWithTLS(address);
14262
- const isNodeChannel = "close" in channel;
14263
- if (import_core.isNode && isNodeChannel && !isBun) {
14264
- const grpcModule = await import("nice-grpc");
14265
- const { createClient } = "default" in grpcModule ? grpcModule.default : grpcModule;
13967
+ // src/proto/spark_token.ts
13968
+ init_buffer();
13969
+ var import_wire7 = require("@bufbuild/protobuf/wire");
13970
+ function createBaseTokenOutputToSpend2() {
13971
+ return { prevTokenTransactionHash: new Uint8Array(0), prevTokenTransactionVout: 0 };
13972
+ }
13973
+ var TokenOutputToSpend2 = {
13974
+ encode(message, writer = new import_wire7.BinaryWriter()) {
13975
+ if (message.prevTokenTransactionHash.length !== 0) {
13976
+ writer.uint32(10).bytes(message.prevTokenTransactionHash);
13977
+ }
13978
+ if (message.prevTokenTransactionVout !== 0) {
13979
+ writer.uint32(16).uint32(message.prevTokenTransactionVout);
13980
+ }
13981
+ return writer;
13982
+ },
13983
+ decode(input, length) {
13984
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
13985
+ let end = length === void 0 ? reader.len : reader.pos + length;
13986
+ const message = createBaseTokenOutputToSpend2();
13987
+ while (reader.pos < end) {
13988
+ const tag = reader.uint32();
13989
+ switch (tag >>> 3) {
13990
+ case 1: {
13991
+ if (tag !== 10) {
13992
+ break;
13993
+ }
13994
+ message.prevTokenTransactionHash = reader.bytes();
13995
+ continue;
13996
+ }
13997
+ case 2: {
13998
+ if (tag !== 16) {
13999
+ break;
14000
+ }
14001
+ message.prevTokenTransactionVout = reader.uint32();
14002
+ continue;
14003
+ }
14004
+ }
14005
+ if ((tag & 7) === 4 || tag === 0) {
14006
+ break;
14007
+ }
14008
+ reader.skip(tag & 7);
14009
+ }
14010
+ return message;
14011
+ },
14012
+ fromJSON(object) {
14013
+ return {
14014
+ prevTokenTransactionHash: isSet6(object.prevTokenTransactionHash) ? bytesFromBase645(object.prevTokenTransactionHash) : new Uint8Array(0),
14015
+ prevTokenTransactionVout: isSet6(object.prevTokenTransactionVout) ? globalThis.Number(object.prevTokenTransactionVout) : 0
14016
+ };
14017
+ },
14018
+ toJSON(message) {
14019
+ const obj = {};
14020
+ if (message.prevTokenTransactionHash.length !== 0) {
14021
+ obj.prevTokenTransactionHash = base64FromBytes5(message.prevTokenTransactionHash);
14022
+ }
14023
+ if (message.prevTokenTransactionVout !== 0) {
14024
+ obj.prevTokenTransactionVout = Math.round(message.prevTokenTransactionVout);
14025
+ }
14026
+ return obj;
14027
+ },
14028
+ create(base) {
14029
+ return TokenOutputToSpend2.fromPartial(base ?? {});
14030
+ },
14031
+ fromPartial(object) {
14032
+ const message = createBaseTokenOutputToSpend2();
14033
+ message.prevTokenTransactionHash = object.prevTokenTransactionHash ?? new Uint8Array(0);
14034
+ message.prevTokenTransactionVout = object.prevTokenTransactionVout ?? 0;
14035
+ return message;
14036
+ }
14037
+ };
14038
+ function createBaseTokenTransferInput2() {
14039
+ return { outputsToSpend: [] };
14040
+ }
14041
+ var TokenTransferInput2 = {
14042
+ encode(message, writer = new import_wire7.BinaryWriter()) {
14043
+ for (const v of message.outputsToSpend) {
14044
+ TokenOutputToSpend2.encode(v, writer.uint32(10).fork()).join();
14045
+ }
14046
+ return writer;
14047
+ },
14048
+ decode(input, length) {
14049
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
14050
+ let end = length === void 0 ? reader.len : reader.pos + length;
14051
+ const message = createBaseTokenTransferInput2();
14052
+ while (reader.pos < end) {
14053
+ const tag = reader.uint32();
14054
+ switch (tag >>> 3) {
14055
+ case 1: {
14056
+ if (tag !== 10) {
14057
+ break;
14058
+ }
14059
+ message.outputsToSpend.push(TokenOutputToSpend2.decode(reader, reader.uint32()));
14060
+ continue;
14061
+ }
14062
+ }
14063
+ if ((tag & 7) === 4 || tag === 0) {
14064
+ break;
14065
+ }
14066
+ reader.skip(tag & 7);
14067
+ }
14068
+ return message;
14069
+ },
14070
+ fromJSON(object) {
14071
+ return {
14072
+ outputsToSpend: globalThis.Array.isArray(object?.outputsToSpend) ? object.outputsToSpend.map((e) => TokenOutputToSpend2.fromJSON(e)) : []
14073
+ };
14074
+ },
14075
+ toJSON(message) {
14076
+ const obj = {};
14077
+ if (message.outputsToSpend?.length) {
14078
+ obj.outputsToSpend = message.outputsToSpend.map((e) => TokenOutputToSpend2.toJSON(e));
14079
+ }
14080
+ return obj;
14081
+ },
14082
+ create(base) {
14083
+ return TokenTransferInput2.fromPartial(base ?? {});
14084
+ },
14085
+ fromPartial(object) {
14086
+ const message = createBaseTokenTransferInput2();
14087
+ message.outputsToSpend = object.outputsToSpend?.map((e) => TokenOutputToSpend2.fromPartial(e)) || [];
14088
+ return message;
14089
+ }
14090
+ };
14091
+ function createBaseTokenMintInput2() {
14092
+ return { issuerPublicKey: new Uint8Array(0), issuerProvidedTimestamp: 0 };
14093
+ }
14094
+ var TokenMintInput2 = {
14095
+ encode(message, writer = new import_wire7.BinaryWriter()) {
14096
+ if (message.issuerPublicKey.length !== 0) {
14097
+ writer.uint32(10).bytes(message.issuerPublicKey);
14098
+ }
14099
+ if (message.issuerProvidedTimestamp !== 0) {
14100
+ writer.uint32(16).uint64(message.issuerProvidedTimestamp);
14101
+ }
14102
+ return writer;
14103
+ },
14104
+ decode(input, length) {
14105
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
14106
+ let end = length === void 0 ? reader.len : reader.pos + length;
14107
+ const message = createBaseTokenMintInput2();
14108
+ while (reader.pos < end) {
14109
+ const tag = reader.uint32();
14110
+ switch (tag >>> 3) {
14111
+ case 1: {
14112
+ if (tag !== 10) {
14113
+ break;
14114
+ }
14115
+ message.issuerPublicKey = reader.bytes();
14116
+ continue;
14117
+ }
14118
+ case 2: {
14119
+ if (tag !== 16) {
14120
+ break;
14121
+ }
14122
+ message.issuerProvidedTimestamp = longToNumber4(reader.uint64());
14123
+ continue;
14124
+ }
14125
+ }
14126
+ if ((tag & 7) === 4 || tag === 0) {
14127
+ break;
14128
+ }
14129
+ reader.skip(tag & 7);
14130
+ }
14131
+ return message;
14132
+ },
14133
+ fromJSON(object) {
14134
+ return {
14135
+ issuerPublicKey: isSet6(object.issuerPublicKey) ? bytesFromBase645(object.issuerPublicKey) : new Uint8Array(0),
14136
+ issuerProvidedTimestamp: isSet6(object.issuerProvidedTimestamp) ? globalThis.Number(object.issuerProvidedTimestamp) : 0
14137
+ };
14138
+ },
14139
+ toJSON(message) {
14140
+ const obj = {};
14141
+ if (message.issuerPublicKey.length !== 0) {
14142
+ obj.issuerPublicKey = base64FromBytes5(message.issuerPublicKey);
14143
+ }
14144
+ if (message.issuerProvidedTimestamp !== 0) {
14145
+ obj.issuerProvidedTimestamp = Math.round(message.issuerProvidedTimestamp);
14146
+ }
14147
+ return obj;
14148
+ },
14149
+ create(base) {
14150
+ return TokenMintInput2.fromPartial(base ?? {});
14151
+ },
14152
+ fromPartial(object) {
14153
+ const message = createBaseTokenMintInput2();
14154
+ message.issuerPublicKey = object.issuerPublicKey ?? new Uint8Array(0);
14155
+ message.issuerProvidedTimestamp = object.issuerProvidedTimestamp ?? 0;
14156
+ return message;
14157
+ }
14158
+ };
14159
+ function createBaseTokenOutput2() {
14160
+ return {
14161
+ id: void 0,
14162
+ ownerPublicKey: new Uint8Array(0),
14163
+ revocationCommitment: void 0,
14164
+ withdrawBondSats: void 0,
14165
+ withdrawRelativeBlockLocktime: void 0,
14166
+ tokenPublicKey: new Uint8Array(0),
14167
+ tokenAmount: new Uint8Array(0)
14168
+ };
14169
+ }
14170
+ var TokenOutput2 = {
14171
+ encode(message, writer = new import_wire7.BinaryWriter()) {
14172
+ if (message.id !== void 0) {
14173
+ writer.uint32(10).string(message.id);
14174
+ }
14175
+ if (message.ownerPublicKey.length !== 0) {
14176
+ writer.uint32(18).bytes(message.ownerPublicKey);
14177
+ }
14178
+ if (message.revocationCommitment !== void 0) {
14179
+ writer.uint32(26).bytes(message.revocationCommitment);
14180
+ }
14181
+ if (message.withdrawBondSats !== void 0) {
14182
+ writer.uint32(32).uint64(message.withdrawBondSats);
14183
+ }
14184
+ if (message.withdrawRelativeBlockLocktime !== void 0) {
14185
+ writer.uint32(40).uint64(message.withdrawRelativeBlockLocktime);
14186
+ }
14187
+ if (message.tokenPublicKey.length !== 0) {
14188
+ writer.uint32(50).bytes(message.tokenPublicKey);
14189
+ }
14190
+ if (message.tokenAmount.length !== 0) {
14191
+ writer.uint32(58).bytes(message.tokenAmount);
14192
+ }
14193
+ return writer;
14194
+ },
14195
+ decode(input, length) {
14196
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
14197
+ let end = length === void 0 ? reader.len : reader.pos + length;
14198
+ const message = createBaseTokenOutput2();
14199
+ while (reader.pos < end) {
14200
+ const tag = reader.uint32();
14201
+ switch (tag >>> 3) {
14202
+ case 1: {
14203
+ if (tag !== 10) {
14204
+ break;
14205
+ }
14206
+ message.id = reader.string();
14207
+ continue;
14208
+ }
14209
+ case 2: {
14210
+ if (tag !== 18) {
14211
+ break;
14212
+ }
14213
+ message.ownerPublicKey = reader.bytes();
14214
+ continue;
14215
+ }
14216
+ case 3: {
14217
+ if (tag !== 26) {
14218
+ break;
14219
+ }
14220
+ message.revocationCommitment = reader.bytes();
14221
+ continue;
14222
+ }
14223
+ case 4: {
14224
+ if (tag !== 32) {
14225
+ break;
14226
+ }
14227
+ message.withdrawBondSats = longToNumber4(reader.uint64());
14228
+ continue;
14229
+ }
14230
+ case 5: {
14231
+ if (tag !== 40) {
14232
+ break;
14233
+ }
14234
+ message.withdrawRelativeBlockLocktime = longToNumber4(reader.uint64());
14235
+ continue;
14236
+ }
14237
+ case 6: {
14238
+ if (tag !== 50) {
14239
+ break;
14240
+ }
14241
+ message.tokenPublicKey = reader.bytes();
14242
+ continue;
14243
+ }
14244
+ case 7: {
14245
+ if (tag !== 58) {
14246
+ break;
14247
+ }
14248
+ message.tokenAmount = reader.bytes();
14249
+ continue;
14250
+ }
14251
+ }
14252
+ if ((tag & 7) === 4 || tag === 0) {
14253
+ break;
14254
+ }
14255
+ reader.skip(tag & 7);
14256
+ }
14257
+ return message;
14258
+ },
14259
+ fromJSON(object) {
14260
+ return {
14261
+ id: isSet6(object.id) ? globalThis.String(object.id) : void 0,
14262
+ ownerPublicKey: isSet6(object.ownerPublicKey) ? bytesFromBase645(object.ownerPublicKey) : new Uint8Array(0),
14263
+ revocationCommitment: isSet6(object.revocationCommitment) ? bytesFromBase645(object.revocationCommitment) : void 0,
14264
+ withdrawBondSats: isSet6(object.withdrawBondSats) ? globalThis.Number(object.withdrawBondSats) : void 0,
14265
+ withdrawRelativeBlockLocktime: isSet6(object.withdrawRelativeBlockLocktime) ? globalThis.Number(object.withdrawRelativeBlockLocktime) : void 0,
14266
+ tokenPublicKey: isSet6(object.tokenPublicKey) ? bytesFromBase645(object.tokenPublicKey) : new Uint8Array(0),
14267
+ tokenAmount: isSet6(object.tokenAmount) ? bytesFromBase645(object.tokenAmount) : new Uint8Array(0)
14268
+ };
14269
+ },
14270
+ toJSON(message) {
14271
+ const obj = {};
14272
+ if (message.id !== void 0) {
14273
+ obj.id = message.id;
14274
+ }
14275
+ if (message.ownerPublicKey.length !== 0) {
14276
+ obj.ownerPublicKey = base64FromBytes5(message.ownerPublicKey);
14277
+ }
14278
+ if (message.revocationCommitment !== void 0) {
14279
+ obj.revocationCommitment = base64FromBytes5(message.revocationCommitment);
14280
+ }
14281
+ if (message.withdrawBondSats !== void 0) {
14282
+ obj.withdrawBondSats = Math.round(message.withdrawBondSats);
14283
+ }
14284
+ if (message.withdrawRelativeBlockLocktime !== void 0) {
14285
+ obj.withdrawRelativeBlockLocktime = Math.round(message.withdrawRelativeBlockLocktime);
14286
+ }
14287
+ if (message.tokenPublicKey.length !== 0) {
14288
+ obj.tokenPublicKey = base64FromBytes5(message.tokenPublicKey);
14289
+ }
14290
+ if (message.tokenAmount.length !== 0) {
14291
+ obj.tokenAmount = base64FromBytes5(message.tokenAmount);
14292
+ }
14293
+ return obj;
14294
+ },
14295
+ create(base) {
14296
+ return TokenOutput2.fromPartial(base ?? {});
14297
+ },
14298
+ fromPartial(object) {
14299
+ const message = createBaseTokenOutput2();
14300
+ message.id = object.id ?? void 0;
14301
+ message.ownerPublicKey = object.ownerPublicKey ?? new Uint8Array(0);
14302
+ message.revocationCommitment = object.revocationCommitment ?? void 0;
14303
+ message.withdrawBondSats = object.withdrawBondSats ?? void 0;
14304
+ message.withdrawRelativeBlockLocktime = object.withdrawRelativeBlockLocktime ?? void 0;
14305
+ message.tokenPublicKey = object.tokenPublicKey ?? new Uint8Array(0);
14306
+ message.tokenAmount = object.tokenAmount ?? new Uint8Array(0);
14307
+ return message;
14308
+ }
14309
+ };
14310
+ function createBaseTokenTransaction2() {
14311
+ return {
14312
+ version: 0,
14313
+ tokenInputs: void 0,
14314
+ tokenOutputs: [],
14315
+ sparkOperatorIdentityPublicKeys: [],
14316
+ expiryTime: void 0,
14317
+ network: 0
14318
+ };
14319
+ }
14320
+ var TokenTransaction2 = {
14321
+ encode(message, writer = new import_wire7.BinaryWriter()) {
14322
+ if (message.version !== 0) {
14323
+ writer.uint32(8).uint32(message.version);
14324
+ }
14325
+ switch (message.tokenInputs?.$case) {
14326
+ case "mintInput":
14327
+ TokenMintInput2.encode(message.tokenInputs.mintInput, writer.uint32(18).fork()).join();
14328
+ break;
14329
+ case "transferInput":
14330
+ TokenTransferInput2.encode(message.tokenInputs.transferInput, writer.uint32(26).fork()).join();
14331
+ break;
14332
+ }
14333
+ for (const v of message.tokenOutputs) {
14334
+ TokenOutput2.encode(v, writer.uint32(34).fork()).join();
14335
+ }
14336
+ for (const v of message.sparkOperatorIdentityPublicKeys) {
14337
+ writer.uint32(42).bytes(v);
14338
+ }
14339
+ if (message.expiryTime !== void 0) {
14340
+ Timestamp.encode(toTimestamp2(message.expiryTime), writer.uint32(50).fork()).join();
14341
+ }
14342
+ if (message.network !== 0) {
14343
+ writer.uint32(56).int32(message.network);
14344
+ }
14345
+ return writer;
14346
+ },
14347
+ decode(input, length) {
14348
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
14349
+ let end = length === void 0 ? reader.len : reader.pos + length;
14350
+ const message = createBaseTokenTransaction2();
14351
+ while (reader.pos < end) {
14352
+ const tag = reader.uint32();
14353
+ switch (tag >>> 3) {
14354
+ case 1: {
14355
+ if (tag !== 8) {
14356
+ break;
14357
+ }
14358
+ message.version = reader.uint32();
14359
+ continue;
14360
+ }
14361
+ case 2: {
14362
+ if (tag !== 18) {
14363
+ break;
14364
+ }
14365
+ message.tokenInputs = { $case: "mintInput", mintInput: TokenMintInput2.decode(reader, reader.uint32()) };
14366
+ continue;
14367
+ }
14368
+ case 3: {
14369
+ if (tag !== 26) {
14370
+ break;
14371
+ }
14372
+ message.tokenInputs = {
14373
+ $case: "transferInput",
14374
+ transferInput: TokenTransferInput2.decode(reader, reader.uint32())
14375
+ };
14376
+ continue;
14377
+ }
14378
+ case 4: {
14379
+ if (tag !== 34) {
14380
+ break;
14381
+ }
14382
+ message.tokenOutputs.push(TokenOutput2.decode(reader, reader.uint32()));
14383
+ continue;
14384
+ }
14385
+ case 5: {
14386
+ if (tag !== 42) {
14387
+ break;
14388
+ }
14389
+ message.sparkOperatorIdentityPublicKeys.push(reader.bytes());
14390
+ continue;
14391
+ }
14392
+ case 6: {
14393
+ if (tag !== 50) {
14394
+ break;
14395
+ }
14396
+ message.expiryTime = fromTimestamp2(Timestamp.decode(reader, reader.uint32()));
14397
+ continue;
14398
+ }
14399
+ case 7: {
14400
+ if (tag !== 56) {
14401
+ break;
14402
+ }
14403
+ message.network = reader.int32();
14404
+ continue;
14405
+ }
14406
+ }
14407
+ if ((tag & 7) === 4 || tag === 0) {
14408
+ break;
14409
+ }
14410
+ reader.skip(tag & 7);
14411
+ }
14412
+ return message;
14413
+ },
14414
+ fromJSON(object) {
14415
+ return {
14416
+ version: isSet6(object.version) ? globalThis.Number(object.version) : 0,
14417
+ tokenInputs: isSet6(object.mintInput) ? { $case: "mintInput", mintInput: TokenMintInput2.fromJSON(object.mintInput) } : isSet6(object.transferInput) ? { $case: "transferInput", transferInput: TokenTransferInput2.fromJSON(object.transferInput) } : void 0,
14418
+ tokenOutputs: globalThis.Array.isArray(object?.tokenOutputs) ? object.tokenOutputs.map((e) => TokenOutput2.fromJSON(e)) : [],
14419
+ sparkOperatorIdentityPublicKeys: globalThis.Array.isArray(object?.sparkOperatorIdentityPublicKeys) ? object.sparkOperatorIdentityPublicKeys.map((e) => bytesFromBase645(e)) : [],
14420
+ expiryTime: isSet6(object.expiryTime) ? fromJsonTimestamp2(object.expiryTime) : void 0,
14421
+ network: isSet6(object.network) ? networkFromJSON(object.network) : 0
14422
+ };
14423
+ },
14424
+ toJSON(message) {
14425
+ const obj = {};
14426
+ if (message.version !== 0) {
14427
+ obj.version = Math.round(message.version);
14428
+ }
14429
+ if (message.tokenInputs?.$case === "mintInput") {
14430
+ obj.mintInput = TokenMintInput2.toJSON(message.tokenInputs.mintInput);
14431
+ } else if (message.tokenInputs?.$case === "transferInput") {
14432
+ obj.transferInput = TokenTransferInput2.toJSON(message.tokenInputs.transferInput);
14433
+ }
14434
+ if (message.tokenOutputs?.length) {
14435
+ obj.tokenOutputs = message.tokenOutputs.map((e) => TokenOutput2.toJSON(e));
14436
+ }
14437
+ if (message.sparkOperatorIdentityPublicKeys?.length) {
14438
+ obj.sparkOperatorIdentityPublicKeys = message.sparkOperatorIdentityPublicKeys.map((e) => base64FromBytes5(e));
14439
+ }
14440
+ if (message.expiryTime !== void 0) {
14441
+ obj.expiryTime = message.expiryTime.toISOString();
14442
+ }
14443
+ if (message.network !== 0) {
14444
+ obj.network = networkToJSON(message.network);
14445
+ }
14446
+ return obj;
14447
+ },
14448
+ create(base) {
14449
+ return TokenTransaction2.fromPartial(base ?? {});
14450
+ },
14451
+ fromPartial(object) {
14452
+ const message = createBaseTokenTransaction2();
14453
+ message.version = object.version ?? 0;
14454
+ switch (object.tokenInputs?.$case) {
14455
+ case "mintInput": {
14456
+ if (object.tokenInputs?.mintInput !== void 0 && object.tokenInputs?.mintInput !== null) {
14457
+ message.tokenInputs = {
14458
+ $case: "mintInput",
14459
+ mintInput: TokenMintInput2.fromPartial(object.tokenInputs.mintInput)
14460
+ };
14461
+ }
14462
+ break;
14463
+ }
14464
+ case "transferInput": {
14465
+ if (object.tokenInputs?.transferInput !== void 0 && object.tokenInputs?.transferInput !== null) {
14466
+ message.tokenInputs = {
14467
+ $case: "transferInput",
14468
+ transferInput: TokenTransferInput2.fromPartial(object.tokenInputs.transferInput)
14469
+ };
14470
+ }
14471
+ break;
14472
+ }
14473
+ }
14474
+ message.tokenOutputs = object.tokenOutputs?.map((e) => TokenOutput2.fromPartial(e)) || [];
14475
+ message.sparkOperatorIdentityPublicKeys = object.sparkOperatorIdentityPublicKeys?.map((e) => e) || [];
14476
+ message.expiryTime = object.expiryTime ?? void 0;
14477
+ message.network = object.network ?? 0;
14478
+ return message;
14479
+ }
14480
+ };
14481
+ function createBaseSignatureWithIndex2() {
14482
+ return { signature: new Uint8Array(0), inputIndex: 0 };
14483
+ }
14484
+ var SignatureWithIndex2 = {
14485
+ encode(message, writer = new import_wire7.BinaryWriter()) {
14486
+ if (message.signature.length !== 0) {
14487
+ writer.uint32(10).bytes(message.signature);
14488
+ }
14489
+ if (message.inputIndex !== 0) {
14490
+ writer.uint32(16).uint32(message.inputIndex);
14491
+ }
14492
+ return writer;
14493
+ },
14494
+ decode(input, length) {
14495
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
14496
+ let end = length === void 0 ? reader.len : reader.pos + length;
14497
+ const message = createBaseSignatureWithIndex2();
14498
+ while (reader.pos < end) {
14499
+ const tag = reader.uint32();
14500
+ switch (tag >>> 3) {
14501
+ case 1: {
14502
+ if (tag !== 10) {
14503
+ break;
14504
+ }
14505
+ message.signature = reader.bytes();
14506
+ continue;
14507
+ }
14508
+ case 2: {
14509
+ if (tag !== 16) {
14510
+ break;
14511
+ }
14512
+ message.inputIndex = reader.uint32();
14513
+ continue;
14514
+ }
14515
+ }
14516
+ if ((tag & 7) === 4 || tag === 0) {
14517
+ break;
14518
+ }
14519
+ reader.skip(tag & 7);
14520
+ }
14521
+ return message;
14522
+ },
14523
+ fromJSON(object) {
14524
+ return {
14525
+ signature: isSet6(object.signature) ? bytesFromBase645(object.signature) : new Uint8Array(0),
14526
+ inputIndex: isSet6(object.inputIndex) ? globalThis.Number(object.inputIndex) : 0
14527
+ };
14528
+ },
14529
+ toJSON(message) {
14530
+ const obj = {};
14531
+ if (message.signature.length !== 0) {
14532
+ obj.signature = base64FromBytes5(message.signature);
14533
+ }
14534
+ if (message.inputIndex !== 0) {
14535
+ obj.inputIndex = Math.round(message.inputIndex);
14536
+ }
14537
+ return obj;
14538
+ },
14539
+ create(base) {
14540
+ return SignatureWithIndex2.fromPartial(base ?? {});
14541
+ },
14542
+ fromPartial(object) {
14543
+ const message = createBaseSignatureWithIndex2();
14544
+ message.signature = object.signature ?? new Uint8Array(0);
14545
+ message.inputIndex = object.inputIndex ?? 0;
14546
+ return message;
14547
+ }
14548
+ };
14549
+ function createBaseInputTtxoSignaturesPerOperator() {
14550
+ return { ttxoSignatures: [], operatorIdentityPublicKey: new Uint8Array(0) };
14551
+ }
14552
+ var InputTtxoSignaturesPerOperator = {
14553
+ encode(message, writer = new import_wire7.BinaryWriter()) {
14554
+ for (const v of message.ttxoSignatures) {
14555
+ SignatureWithIndex2.encode(v, writer.uint32(10).fork()).join();
14556
+ }
14557
+ if (message.operatorIdentityPublicKey.length !== 0) {
14558
+ writer.uint32(18).bytes(message.operatorIdentityPublicKey);
14559
+ }
14560
+ return writer;
14561
+ },
14562
+ decode(input, length) {
14563
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
14564
+ let end = length === void 0 ? reader.len : reader.pos + length;
14565
+ const message = createBaseInputTtxoSignaturesPerOperator();
14566
+ while (reader.pos < end) {
14567
+ const tag = reader.uint32();
14568
+ switch (tag >>> 3) {
14569
+ case 1: {
14570
+ if (tag !== 10) {
14571
+ break;
14572
+ }
14573
+ message.ttxoSignatures.push(SignatureWithIndex2.decode(reader, reader.uint32()));
14574
+ continue;
14575
+ }
14576
+ case 2: {
14577
+ if (tag !== 18) {
14578
+ break;
14579
+ }
14580
+ message.operatorIdentityPublicKey = reader.bytes();
14581
+ continue;
14582
+ }
14583
+ }
14584
+ if ((tag & 7) === 4 || tag === 0) {
14585
+ break;
14586
+ }
14587
+ reader.skip(tag & 7);
14588
+ }
14589
+ return message;
14590
+ },
14591
+ fromJSON(object) {
14592
+ return {
14593
+ ttxoSignatures: globalThis.Array.isArray(object?.ttxoSignatures) ? object.ttxoSignatures.map((e) => SignatureWithIndex2.fromJSON(e)) : [],
14594
+ operatorIdentityPublicKey: isSet6(object.operatorIdentityPublicKey) ? bytesFromBase645(object.operatorIdentityPublicKey) : new Uint8Array(0)
14595
+ };
14596
+ },
14597
+ toJSON(message) {
14598
+ const obj = {};
14599
+ if (message.ttxoSignatures?.length) {
14600
+ obj.ttxoSignatures = message.ttxoSignatures.map((e) => SignatureWithIndex2.toJSON(e));
14601
+ }
14602
+ if (message.operatorIdentityPublicKey.length !== 0) {
14603
+ obj.operatorIdentityPublicKey = base64FromBytes5(message.operatorIdentityPublicKey);
14604
+ }
14605
+ return obj;
14606
+ },
14607
+ create(base) {
14608
+ return InputTtxoSignaturesPerOperator.fromPartial(base ?? {});
14609
+ },
14610
+ fromPartial(object) {
14611
+ const message = createBaseInputTtxoSignaturesPerOperator();
14612
+ message.ttxoSignatures = object.ttxoSignatures?.map((e) => SignatureWithIndex2.fromPartial(e)) || [];
14613
+ message.operatorIdentityPublicKey = object.operatorIdentityPublicKey ?? new Uint8Array(0);
14614
+ return message;
14615
+ }
14616
+ };
14617
+ function createBaseStartTransactionRequest() {
14618
+ return {
14619
+ identityPublicKey: new Uint8Array(0),
14620
+ partialTokenTransaction: void 0,
14621
+ partialTokenTransactionOwnerSignatures: [],
14622
+ validityDurationSeconds: 0
14623
+ };
14624
+ }
14625
+ var StartTransactionRequest = {
14626
+ encode(message, writer = new import_wire7.BinaryWriter()) {
14627
+ if (message.identityPublicKey.length !== 0) {
14628
+ writer.uint32(10).bytes(message.identityPublicKey);
14629
+ }
14630
+ if (message.partialTokenTransaction !== void 0) {
14631
+ TokenTransaction2.encode(message.partialTokenTransaction, writer.uint32(18).fork()).join();
14632
+ }
14633
+ for (const v of message.partialTokenTransactionOwnerSignatures) {
14634
+ SignatureWithIndex2.encode(v, writer.uint32(26).fork()).join();
14635
+ }
14636
+ if (message.validityDurationSeconds !== 0) {
14637
+ writer.uint32(32).uint64(message.validityDurationSeconds);
14638
+ }
14639
+ return writer;
14640
+ },
14641
+ decode(input, length) {
14642
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
14643
+ let end = length === void 0 ? reader.len : reader.pos + length;
14644
+ const message = createBaseStartTransactionRequest();
14645
+ while (reader.pos < end) {
14646
+ const tag = reader.uint32();
14647
+ switch (tag >>> 3) {
14648
+ case 1: {
14649
+ if (tag !== 10) {
14650
+ break;
14651
+ }
14652
+ message.identityPublicKey = reader.bytes();
14653
+ continue;
14654
+ }
14655
+ case 2: {
14656
+ if (tag !== 18) {
14657
+ break;
14658
+ }
14659
+ message.partialTokenTransaction = TokenTransaction2.decode(reader, reader.uint32());
14660
+ continue;
14661
+ }
14662
+ case 3: {
14663
+ if (tag !== 26) {
14664
+ break;
14665
+ }
14666
+ message.partialTokenTransactionOwnerSignatures.push(SignatureWithIndex2.decode(reader, reader.uint32()));
14667
+ continue;
14668
+ }
14669
+ case 4: {
14670
+ if (tag !== 32) {
14671
+ break;
14672
+ }
14673
+ message.validityDurationSeconds = longToNumber4(reader.uint64());
14674
+ continue;
14675
+ }
14676
+ }
14677
+ if ((tag & 7) === 4 || tag === 0) {
14678
+ break;
14679
+ }
14680
+ reader.skip(tag & 7);
14681
+ }
14682
+ return message;
14683
+ },
14684
+ fromJSON(object) {
14685
+ return {
14686
+ identityPublicKey: isSet6(object.identityPublicKey) ? bytesFromBase645(object.identityPublicKey) : new Uint8Array(0),
14687
+ partialTokenTransaction: isSet6(object.partialTokenTransaction) ? TokenTransaction2.fromJSON(object.partialTokenTransaction) : void 0,
14688
+ partialTokenTransactionOwnerSignatures: globalThis.Array.isArray(object?.partialTokenTransactionOwnerSignatures) ? object.partialTokenTransactionOwnerSignatures.map((e) => SignatureWithIndex2.fromJSON(e)) : [],
14689
+ validityDurationSeconds: isSet6(object.validityDurationSeconds) ? globalThis.Number(object.validityDurationSeconds) : 0
14690
+ };
14691
+ },
14692
+ toJSON(message) {
14693
+ const obj = {};
14694
+ if (message.identityPublicKey.length !== 0) {
14695
+ obj.identityPublicKey = base64FromBytes5(message.identityPublicKey);
14696
+ }
14697
+ if (message.partialTokenTransaction !== void 0) {
14698
+ obj.partialTokenTransaction = TokenTransaction2.toJSON(message.partialTokenTransaction);
14699
+ }
14700
+ if (message.partialTokenTransactionOwnerSignatures?.length) {
14701
+ obj.partialTokenTransactionOwnerSignatures = message.partialTokenTransactionOwnerSignatures.map(
14702
+ (e) => SignatureWithIndex2.toJSON(e)
14703
+ );
14704
+ }
14705
+ if (message.validityDurationSeconds !== 0) {
14706
+ obj.validityDurationSeconds = Math.round(message.validityDurationSeconds);
14707
+ }
14708
+ return obj;
14709
+ },
14710
+ create(base) {
14711
+ return StartTransactionRequest.fromPartial(base ?? {});
14712
+ },
14713
+ fromPartial(object) {
14714
+ const message = createBaseStartTransactionRequest();
14715
+ message.identityPublicKey = object.identityPublicKey ?? new Uint8Array(0);
14716
+ message.partialTokenTransaction = object.partialTokenTransaction !== void 0 && object.partialTokenTransaction !== null ? TokenTransaction2.fromPartial(object.partialTokenTransaction) : void 0;
14717
+ message.partialTokenTransactionOwnerSignatures = object.partialTokenTransactionOwnerSignatures?.map((e) => SignatureWithIndex2.fromPartial(e)) || [];
14718
+ message.validityDurationSeconds = object.validityDurationSeconds ?? 0;
14719
+ return message;
14720
+ }
14721
+ };
14722
+ function createBaseStartTransactionResponse() {
14723
+ return { finalTokenTransaction: void 0, keyshareInfo: void 0 };
14724
+ }
14725
+ var StartTransactionResponse = {
14726
+ encode(message, writer = new import_wire7.BinaryWriter()) {
14727
+ if (message.finalTokenTransaction !== void 0) {
14728
+ TokenTransaction2.encode(message.finalTokenTransaction, writer.uint32(10).fork()).join();
14729
+ }
14730
+ if (message.keyshareInfo !== void 0) {
14731
+ SigningKeyshare.encode(message.keyshareInfo, writer.uint32(18).fork()).join();
14732
+ }
14733
+ return writer;
14734
+ },
14735
+ decode(input, length) {
14736
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
14737
+ let end = length === void 0 ? reader.len : reader.pos + length;
14738
+ const message = createBaseStartTransactionResponse();
14739
+ while (reader.pos < end) {
14740
+ const tag = reader.uint32();
14741
+ switch (tag >>> 3) {
14742
+ case 1: {
14743
+ if (tag !== 10) {
14744
+ break;
14745
+ }
14746
+ message.finalTokenTransaction = TokenTransaction2.decode(reader, reader.uint32());
14747
+ continue;
14748
+ }
14749
+ case 2: {
14750
+ if (tag !== 18) {
14751
+ break;
14752
+ }
14753
+ message.keyshareInfo = SigningKeyshare.decode(reader, reader.uint32());
14754
+ continue;
14755
+ }
14756
+ }
14757
+ if ((tag & 7) === 4 || tag === 0) {
14758
+ break;
14759
+ }
14760
+ reader.skip(tag & 7);
14761
+ }
14762
+ return message;
14763
+ },
14764
+ fromJSON(object) {
14765
+ return {
14766
+ finalTokenTransaction: isSet6(object.finalTokenTransaction) ? TokenTransaction2.fromJSON(object.finalTokenTransaction) : void 0,
14767
+ keyshareInfo: isSet6(object.keyshareInfo) ? SigningKeyshare.fromJSON(object.keyshareInfo) : void 0
14768
+ };
14769
+ },
14770
+ toJSON(message) {
14771
+ const obj = {};
14772
+ if (message.finalTokenTransaction !== void 0) {
14773
+ obj.finalTokenTransaction = TokenTransaction2.toJSON(message.finalTokenTransaction);
14774
+ }
14775
+ if (message.keyshareInfo !== void 0) {
14776
+ obj.keyshareInfo = SigningKeyshare.toJSON(message.keyshareInfo);
14777
+ }
14778
+ return obj;
14779
+ },
14780
+ create(base) {
14781
+ return StartTransactionResponse.fromPartial(base ?? {});
14782
+ },
14783
+ fromPartial(object) {
14784
+ const message = createBaseStartTransactionResponse();
14785
+ message.finalTokenTransaction = object.finalTokenTransaction !== void 0 && object.finalTokenTransaction !== null ? TokenTransaction2.fromPartial(object.finalTokenTransaction) : void 0;
14786
+ message.keyshareInfo = object.keyshareInfo !== void 0 && object.keyshareInfo !== null ? SigningKeyshare.fromPartial(object.keyshareInfo) : void 0;
14787
+ return message;
14788
+ }
14789
+ };
14790
+ function createBaseCommitTransactionRequest() {
14791
+ return {
14792
+ finalTokenTransaction: void 0,
14793
+ finalTokenTransactionHash: new Uint8Array(0),
14794
+ inputTtxoSignaturesPerOperator: [],
14795
+ ownerIdentityPublicKey: new Uint8Array(0)
14796
+ };
14797
+ }
14798
+ var CommitTransactionRequest = {
14799
+ encode(message, writer = new import_wire7.BinaryWriter()) {
14800
+ if (message.finalTokenTransaction !== void 0) {
14801
+ TokenTransaction2.encode(message.finalTokenTransaction, writer.uint32(10).fork()).join();
14802
+ }
14803
+ if (message.finalTokenTransactionHash.length !== 0) {
14804
+ writer.uint32(18).bytes(message.finalTokenTransactionHash);
14805
+ }
14806
+ for (const v of message.inputTtxoSignaturesPerOperator) {
14807
+ InputTtxoSignaturesPerOperator.encode(v, writer.uint32(26).fork()).join();
14808
+ }
14809
+ if (message.ownerIdentityPublicKey.length !== 0) {
14810
+ writer.uint32(34).bytes(message.ownerIdentityPublicKey);
14811
+ }
14812
+ return writer;
14813
+ },
14814
+ decode(input, length) {
14815
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
14816
+ let end = length === void 0 ? reader.len : reader.pos + length;
14817
+ const message = createBaseCommitTransactionRequest();
14818
+ while (reader.pos < end) {
14819
+ const tag = reader.uint32();
14820
+ switch (tag >>> 3) {
14821
+ case 1: {
14822
+ if (tag !== 10) {
14823
+ break;
14824
+ }
14825
+ message.finalTokenTransaction = TokenTransaction2.decode(reader, reader.uint32());
14826
+ continue;
14827
+ }
14828
+ case 2: {
14829
+ if (tag !== 18) {
14830
+ break;
14831
+ }
14832
+ message.finalTokenTransactionHash = reader.bytes();
14833
+ continue;
14834
+ }
14835
+ case 3: {
14836
+ if (tag !== 26) {
14837
+ break;
14838
+ }
14839
+ message.inputTtxoSignaturesPerOperator.push(InputTtxoSignaturesPerOperator.decode(reader, reader.uint32()));
14840
+ continue;
14841
+ }
14842
+ case 4: {
14843
+ if (tag !== 34) {
14844
+ break;
14845
+ }
14846
+ message.ownerIdentityPublicKey = reader.bytes();
14847
+ continue;
14848
+ }
14849
+ }
14850
+ if ((tag & 7) === 4 || tag === 0) {
14851
+ break;
14852
+ }
14853
+ reader.skip(tag & 7);
14854
+ }
14855
+ return message;
14856
+ },
14857
+ fromJSON(object) {
14858
+ return {
14859
+ finalTokenTransaction: isSet6(object.finalTokenTransaction) ? TokenTransaction2.fromJSON(object.finalTokenTransaction) : void 0,
14860
+ finalTokenTransactionHash: isSet6(object.finalTokenTransactionHash) ? bytesFromBase645(object.finalTokenTransactionHash) : new Uint8Array(0),
14861
+ inputTtxoSignaturesPerOperator: globalThis.Array.isArray(object?.inputTtxoSignaturesPerOperator) ? object.inputTtxoSignaturesPerOperator.map((e) => InputTtxoSignaturesPerOperator.fromJSON(e)) : [],
14862
+ ownerIdentityPublicKey: isSet6(object.ownerIdentityPublicKey) ? bytesFromBase645(object.ownerIdentityPublicKey) : new Uint8Array(0)
14863
+ };
14864
+ },
14865
+ toJSON(message) {
14866
+ const obj = {};
14867
+ if (message.finalTokenTransaction !== void 0) {
14868
+ obj.finalTokenTransaction = TokenTransaction2.toJSON(message.finalTokenTransaction);
14869
+ }
14870
+ if (message.finalTokenTransactionHash.length !== 0) {
14871
+ obj.finalTokenTransactionHash = base64FromBytes5(message.finalTokenTransactionHash);
14872
+ }
14873
+ if (message.inputTtxoSignaturesPerOperator?.length) {
14874
+ obj.inputTtxoSignaturesPerOperator = message.inputTtxoSignaturesPerOperator.map(
14875
+ (e) => InputTtxoSignaturesPerOperator.toJSON(e)
14876
+ );
14877
+ }
14878
+ if (message.ownerIdentityPublicKey.length !== 0) {
14879
+ obj.ownerIdentityPublicKey = base64FromBytes5(message.ownerIdentityPublicKey);
14880
+ }
14881
+ return obj;
14882
+ },
14883
+ create(base) {
14884
+ return CommitTransactionRequest.fromPartial(base ?? {});
14885
+ },
14886
+ fromPartial(object) {
14887
+ const message = createBaseCommitTransactionRequest();
14888
+ message.finalTokenTransaction = object.finalTokenTransaction !== void 0 && object.finalTokenTransaction !== null ? TokenTransaction2.fromPartial(object.finalTokenTransaction) : void 0;
14889
+ message.finalTokenTransactionHash = object.finalTokenTransactionHash ?? new Uint8Array(0);
14890
+ message.inputTtxoSignaturesPerOperator = object.inputTtxoSignaturesPerOperator?.map((e) => InputTtxoSignaturesPerOperator.fromPartial(e)) || [];
14891
+ message.ownerIdentityPublicKey = object.ownerIdentityPublicKey ?? new Uint8Array(0);
14892
+ return message;
14893
+ }
14894
+ };
14895
+ function createBaseCommitTransactionResponse() {
14896
+ return {};
14897
+ }
14898
+ var CommitTransactionResponse = {
14899
+ encode(_, writer = new import_wire7.BinaryWriter()) {
14900
+ return writer;
14901
+ },
14902
+ decode(input, length) {
14903
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
14904
+ let end = length === void 0 ? reader.len : reader.pos + length;
14905
+ const message = createBaseCommitTransactionResponse();
14906
+ while (reader.pos < end) {
14907
+ const tag = reader.uint32();
14908
+ switch (tag >>> 3) {
14909
+ }
14910
+ if ((tag & 7) === 4 || tag === 0) {
14911
+ break;
14912
+ }
14913
+ reader.skip(tag & 7);
14914
+ }
14915
+ return message;
14916
+ },
14917
+ fromJSON(_) {
14918
+ return {};
14919
+ },
14920
+ toJSON(_) {
14921
+ const obj = {};
14922
+ return obj;
14923
+ },
14924
+ create(base) {
14925
+ return CommitTransactionResponse.fromPartial(base ?? {});
14926
+ },
14927
+ fromPartial(_) {
14928
+ const message = createBaseCommitTransactionResponse();
14929
+ return message;
14930
+ }
14931
+ };
14932
+ var SparkTokenServiceDefinition = {
14933
+ name: "SparkTokenService",
14934
+ fullName: "spark_token.SparkTokenService",
14935
+ methods: {
14936
+ /**
14937
+ * Start process to create final token transaction with all inputs required
14938
+ * from user and SOs (including revocation secret commitment)
14939
+ */
14940
+ start_transaction: {
14941
+ name: "start_transaction",
14942
+ requestType: StartTransactionRequest,
14943
+ requestStream: false,
14944
+ responseType: StartTransactionResponse,
14945
+ responseStream: false,
14946
+ options: {}
14947
+ },
14948
+ /**
14949
+ * Complete the transaction and commit it with all SOs. This will be
14950
+ * coordinated by one SO.
14951
+ */
14952
+ commit_transaction: {
14953
+ name: "commit_transaction",
14954
+ requestType: CommitTransactionRequest,
14955
+ requestStream: false,
14956
+ responseType: CommitTransactionResponse,
14957
+ responseStream: false,
14958
+ options: {}
14959
+ }
14960
+ }
14961
+ };
14962
+ function bytesFromBase645(b64) {
14963
+ if (globalThis.Buffer) {
14964
+ return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
14965
+ } else {
14966
+ const bin = globalThis.atob(b64);
14967
+ const arr = new Uint8Array(bin.length);
14968
+ for (let i = 0; i < bin.length; ++i) {
14969
+ arr[i] = bin.charCodeAt(i);
14970
+ }
14971
+ return arr;
14972
+ }
14973
+ }
14974
+ function base64FromBytes5(arr) {
14975
+ if (globalThis.Buffer) {
14976
+ return globalThis.Buffer.from(arr).toString("base64");
14977
+ } else {
14978
+ const bin = [];
14979
+ arr.forEach((byte) => {
14980
+ bin.push(globalThis.String.fromCharCode(byte));
14981
+ });
14982
+ return globalThis.btoa(bin.join(""));
14983
+ }
14984
+ }
14985
+ function toTimestamp2(date) {
14986
+ const seconds = Math.trunc(date.getTime() / 1e3);
14987
+ const nanos = date.getTime() % 1e3 * 1e6;
14988
+ return { seconds, nanos };
14989
+ }
14990
+ function fromTimestamp2(t) {
14991
+ let millis = (t.seconds || 0) * 1e3;
14992
+ millis += (t.nanos || 0) / 1e6;
14993
+ return new globalThis.Date(millis);
14994
+ }
14995
+ function fromJsonTimestamp2(o) {
14996
+ if (o instanceof globalThis.Date) {
14997
+ return o;
14998
+ } else if (typeof o === "string") {
14999
+ return new globalThis.Date(o);
15000
+ } else {
15001
+ return fromTimestamp2(Timestamp.fromJSON(o));
15002
+ }
15003
+ }
15004
+ function longToNumber4(int64) {
15005
+ const num = globalThis.Number(int64.toString());
15006
+ if (num > globalThis.Number.MAX_SAFE_INTEGER) {
15007
+ throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
15008
+ }
15009
+ if (num < globalThis.Number.MIN_SAFE_INTEGER) {
15010
+ throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
15011
+ }
15012
+ return num;
15013
+ }
15014
+ function isSet6(value) {
15015
+ return value !== null && value !== void 0;
15016
+ }
15017
+
15018
+ // src/services/connection.ts
15019
+ var ConnectionManager = class {
15020
+ config;
15021
+ clients = /* @__PURE__ */ new Map();
15022
+ tokenClients = /* @__PURE__ */ new Map();
15023
+ // We are going to .unref() the underlying channels for stream clients
15024
+ // to prevent the stream from keeping the process alive
15025
+ // Using a different map to avoid unforeseen problems with unary calls
15026
+ streamClients = /* @__PURE__ */ new Map();
15027
+ constructor(config) {
15028
+ this.config = config;
15029
+ }
15030
+ // When initializing wallet, go ahead and instantiate all clients
15031
+ async createClients() {
15032
+ await Promise.all(
15033
+ Object.values(this.config.getSigningOperators()).map((operator) => {
15034
+ this.createSparkClient(operator.address);
15035
+ })
15036
+ );
15037
+ }
15038
+ async closeConnections() {
15039
+ await Promise.all(
15040
+ Array.from(this.clients.values()).map(
15041
+ (client) => client.client.close?.()
15042
+ )
15043
+ );
15044
+ this.clients.clear();
15045
+ }
15046
+ async createMockClient(address) {
15047
+ const channel = await this.createChannelWithTLS(address);
15048
+ const isNodeChannel = "close" in channel;
15049
+ if (import_core.isNode && isNodeChannel && !isBun) {
15050
+ const grpcModule = await import("nice-grpc");
15051
+ const { createClient } = "default" in grpcModule ? grpcModule.default : grpcModule;
14266
15052
  const client = createClient(MockServiceDefinition, channel);
14267
15053
  return { ...client, close: () => channel.close() };
14268
15054
  } else if (!isNodeChannel) {
@@ -14357,6 +15143,22 @@ var ConnectionManager = class {
14357
15143
  this.clients.set(address, { client, authToken });
14358
15144
  return client;
14359
15145
  }
15146
+ async createSparkTokenClient(address, certPath) {
15147
+ if (this.tokenClients.has(address)) {
15148
+ return this.tokenClients.get(address).client;
15149
+ }
15150
+ const authToken = await this.authenticate(address);
15151
+ const channel = await this.createChannelWithTLS(address, certPath);
15152
+ const middleware = this.createMiddleware(address, authToken);
15153
+ const tokenClient = await this.createGrpcClient(
15154
+ SparkTokenServiceDefinition,
15155
+ channel,
15156
+ true,
15157
+ middleware
15158
+ );
15159
+ this.tokenClients.set(address, { client: tokenClient, authToken });
15160
+ return tokenClient;
15161
+ }
14360
15162
  async getStreamChannel(address) {
14361
15163
  return this.streamClients.get(address)?.channel;
14362
15164
  }