@buildonspark/spark-sdk 0.2.1 → 0.2.3

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 (77) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/{chunk-TM6CHQXC.js → chunk-3SEOTO43.js} +1 -1
  3. package/dist/{chunk-2ENZX6LT.js → chunk-AAZWSPUK.js} +84 -8
  4. package/dist/{chunk-4JD4HIAN.js → chunk-G4MSZ6DE.js} +299 -1
  5. package/dist/{chunk-KFDVDUIS.js → chunk-PLLJIZC3.js} +138 -35
  6. package/dist/{chunk-N4JAOOIN.js → chunk-PTRXJS7Q.js} +1 -1
  7. package/dist/{client-DKbwpcnl.d.ts → client-CGTRS23n.d.ts} +21 -4
  8. package/dist/{client-Drs5Lapg.d.cts → client-CcYzmpmj.d.cts} +21 -4
  9. package/dist/debug.cjs +455 -40
  10. package/dist/debug.d.cts +5 -5
  11. package/dist/debug.d.ts +5 -5
  12. package/dist/debug.js +4 -4
  13. package/dist/graphql/objects/index.d.cts +2 -2
  14. package/dist/graphql/objects/index.d.ts +2 -2
  15. package/dist/index.cjs +515 -40
  16. package/dist/index.d.cts +5 -5
  17. package/dist/index.d.ts +5 -5
  18. package/dist/index.js +7 -5
  19. package/dist/index.node.cjs +517 -44
  20. package/dist/index.node.d.cts +8 -6
  21. package/dist/index.node.d.ts +8 -6
  22. package/dist/index.node.js +6 -4
  23. package/dist/native/index.cjs +459 -43
  24. package/dist/native/index.d.cts +62 -15
  25. package/dist/native/index.d.ts +62 -15
  26. package/dist/native/index.js +459 -43
  27. package/dist/proto/lrc20.d.cts +1 -1
  28. package/dist/proto/lrc20.d.ts +1 -1
  29. package/dist/proto/lrc20.js +1 -1
  30. package/dist/proto/spark.cjs +84 -8
  31. package/dist/proto/spark.d.cts +1 -1
  32. package/dist/proto/spark.d.ts +1 -1
  33. package/dist/proto/spark.js +1 -1
  34. package/dist/proto/spark_token.cjs +301 -0
  35. package/dist/proto/spark_token.d.cts +35 -2
  36. package/dist/proto/spark_token.d.ts +35 -2
  37. package/dist/proto/spark_token.js +8 -2
  38. package/dist/{sdk-types-DJ2ve9YY.d.cts → sdk-types-CB9HrW5O.d.cts} +1 -1
  39. package/dist/{sdk-types-DCIVdKUT.d.ts → sdk-types-CkRNraXT.d.ts} +1 -1
  40. package/dist/{spark-BUOx3U7Q.d.cts → spark-B_7nZx6T.d.cts} +112 -10
  41. package/dist/{spark-BUOx3U7Q.d.ts → spark-B_7nZx6T.d.ts} +112 -10
  42. package/dist/{spark-wallet-DbCjWOfP.d.ts → spark-wallet-CxcGPXRB.d.ts} +10 -6
  43. package/dist/{spark-wallet-BslnB-4H.d.cts → spark-wallet-DJJm19BP.d.cts} +10 -6
  44. package/dist/tests/test-utils.cjs +455 -17
  45. package/dist/tests/test-utils.d.cts +9 -5
  46. package/dist/tests/test-utils.d.ts +9 -5
  47. package/dist/tests/test-utils.js +13 -6
  48. package/dist/types/index.cjs +84 -8
  49. package/dist/types/index.d.cts +3 -3
  50. package/dist/types/index.d.ts +3 -3
  51. package/dist/types/index.js +2 -2
  52. package/dist/{xchain-address-BIcYZU3K.d.ts → xchain-address-Bh9w1SeC.d.ts} +3 -3
  53. package/dist/{xchain-address-C3B-Jfk5.d.cts → xchain-address-SZ7dkVUE.d.cts} +3 -3
  54. package/package.json +1 -1
  55. package/src/index.node.ts +6 -6
  56. package/src/index.ts +5 -5
  57. package/src/proto/spark.ts +172 -16
  58. package/src/proto/spark_token.ts +369 -0
  59. package/src/services/connection.ts +3 -3
  60. package/src/services/coop-exit.ts +1 -1
  61. package/src/services/deposit.ts +2 -2
  62. package/src/services/signing.ts +1 -1
  63. package/src/services/token-transactions.ts +6 -2
  64. package/src/services/transfer.ts +25 -9
  65. package/src/services/tree-creation.ts +10 -7
  66. package/src/signer/signer.react-native.ts +4 -3
  67. package/src/signer/signer.ts +84 -6
  68. package/src/signer/types.ts +7 -1
  69. package/src/spark-wallet/spark-wallet.ts +56 -15
  70. package/src/tests/integration/coop-exit.test.ts +5 -3
  71. package/src/tests/integration/deposit.test.ts +20 -10
  72. package/src/tests/integration/lightning.test.ts +13 -7
  73. package/src/tests/integration/message-signing.test.ts +10 -7
  74. package/src/tests/integration/swap.test.ts +8 -4
  75. package/src/tests/integration/transfer.test.ts +25 -11
  76. package/src/tests/integration/wallet.test.ts +9 -4
  77. package/src/tests/test-utils.ts +10 -1
@@ -1306,6 +1306,7 @@ __export(index_node_exports, {
1306
1306
  TaprootOutputKeysGenerator: () => TaprootOutputKeysGenerator,
1307
1307
  TaprootSparkSigner: () => TaprootSparkSigner,
1308
1308
  TokenTransactionService: () => TokenTransactionService,
1309
+ UnsafeStatelessSparkSigner: () => UnsafeStatelessSparkSigner,
1309
1310
  ValidationError: () => ValidationError,
1310
1311
  WalletConfig: () => WalletConfig,
1311
1312
  addPrivateKeys: () => addPrivateKeys,
@@ -1381,6 +1382,7 @@ __export(index_node_exports, {
1381
1382
  });
1382
1383
  module.exports = __toCommonJS(index_node_exports);
1383
1384
  init_buffer();
1385
+ var import_crypto3 = __toESM(require("crypto"), 1);
1384
1386
 
1385
1387
  // src/utils/crypto.ts
1386
1388
  init_buffer();
@@ -1397,9 +1399,6 @@ var setCrypto = (cryptoImplParam) => {
1397
1399
  cryptoImpl = cryptoImplParam;
1398
1400
  };
1399
1401
 
1400
- // src/index.node.ts
1401
- var import_crypto4 = __toESM(require("crypto"), 1);
1402
-
1403
1402
  // src/errors/index.ts
1404
1403
  init_buffer();
1405
1404
 
@@ -15732,14 +15731,6 @@ var SparkServiceDefinition = {
15732
15731
  responseStream: false,
15733
15732
  options: {}
15734
15733
  },
15735
- create_tree_v2: {
15736
- name: "create_tree_v2",
15737
- requestType: CreateTreeRequest,
15738
- requestStream: false,
15739
- responseType: CreateTreeResponse,
15740
- responseStream: false,
15741
- options: {}
15742
- },
15743
15734
  get_signing_operator_list: {
15744
15735
  name: "get_signing_operator_list",
15745
15736
  requestType: Empty,
@@ -15906,6 +15897,90 @@ var SparkServiceDefinition = {
15906
15897
  responseType: ExitSingleNodeTreesResponse,
15907
15898
  responseStream: false,
15908
15899
  options: {}
15900
+ },
15901
+ /**
15902
+ * The following endpoints enforce inclusion of Direct Transactions used
15903
+ * for unilateral exits
15904
+ */
15905
+ create_tree_v2: {
15906
+ name: "create_tree_v2",
15907
+ requestType: CreateTreeRequest,
15908
+ requestStream: false,
15909
+ responseType: CreateTreeResponse,
15910
+ responseStream: false,
15911
+ options: {}
15912
+ },
15913
+ cooperative_exit_v2: {
15914
+ name: "cooperative_exit_v2",
15915
+ requestType: CooperativeExitRequest,
15916
+ requestStream: false,
15917
+ responseType: CooperativeExitResponse,
15918
+ responseStream: false,
15919
+ options: {}
15920
+ },
15921
+ extend_leaf_v2: {
15922
+ name: "extend_leaf_v2",
15923
+ requestType: ExtendLeafRequest,
15924
+ requestStream: false,
15925
+ responseType: ExtendLeafResponse,
15926
+ responseStream: false,
15927
+ options: {}
15928
+ },
15929
+ claim_transfer_sign_refunds_v2: {
15930
+ name: "claim_transfer_sign_refunds_v2",
15931
+ requestType: ClaimTransferSignRefundsRequest,
15932
+ requestStream: false,
15933
+ responseType: ClaimTransferSignRefundsResponse,
15934
+ responseStream: false,
15935
+ options: {}
15936
+ },
15937
+ finalize_node_signatures_v2: {
15938
+ name: "finalize_node_signatures_v2",
15939
+ requestType: FinalizeNodeSignaturesRequest,
15940
+ requestStream: false,
15941
+ responseType: FinalizeNodeSignaturesResponse,
15942
+ responseStream: false,
15943
+ options: {}
15944
+ },
15945
+ initiate_preimage_swap_v2: {
15946
+ name: "initiate_preimage_swap_v2",
15947
+ requestType: InitiatePreimageSwapRequest,
15948
+ requestStream: false,
15949
+ responseType: InitiatePreimageSwapResponse,
15950
+ responseStream: false,
15951
+ options: {}
15952
+ },
15953
+ start_leaf_swap_v2: {
15954
+ name: "start_leaf_swap_v2",
15955
+ requestType: StartTransferRequest,
15956
+ requestStream: false,
15957
+ responseType: StartTransferResponse,
15958
+ responseStream: false,
15959
+ options: {}
15960
+ },
15961
+ counter_leaf_swap_v2: {
15962
+ name: "counter_leaf_swap_v2",
15963
+ requestType: CounterLeafSwapRequest,
15964
+ requestStream: false,
15965
+ responseType: CounterLeafSwapResponse,
15966
+ responseStream: false,
15967
+ options: {}
15968
+ },
15969
+ start_transfer_v2: {
15970
+ name: "start_transfer_v2",
15971
+ requestType: StartTransferRequest,
15972
+ requestStream: false,
15973
+ responseType: StartTransferResponse,
15974
+ responseStream: false,
15975
+ options: {}
15976
+ },
15977
+ refresh_timelock_v2: {
15978
+ name: "refresh_timelock_v2",
15979
+ requestType: RefreshTimelockRequest,
15980
+ requestStream: false,
15981
+ responseType: RefreshTimelockResponse,
15982
+ responseStream: false,
15983
+ options: {}
15909
15984
  }
15910
15985
  }
15911
15986
  };
@@ -18857,7 +18932,7 @@ init_buffer();
18857
18932
  var import_core8 = require("@lightsparkdev/core");
18858
18933
  var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
18859
18934
  var isBun = globalThis.Bun !== void 0;
18860
- var packageVersion = true ? "0.2.1" : "unknown";
18935
+ var packageVersion = true ? "0.2.3" : "unknown";
18861
18936
  var baseEnvStr = "unknown";
18862
18937
  if (isBun) {
18863
18938
  const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
@@ -19189,7 +19264,8 @@ var DefaultSparkSigner = class {
19189
19264
  field: "privateKey"
19190
19265
  });
19191
19266
  }
19192
- const nonce = this.commitmentToNonceMap.get(selfCommitment);
19267
+ const commitment = selfCommitment.commitment;
19268
+ const nonce = this.commitmentToNonceMap.get(commitment);
19193
19269
  if (!nonce) {
19194
19270
  throw new ValidationError("Nonce not found for commitment", {
19195
19271
  field: "nonce"
@@ -19204,7 +19280,7 @@ var DefaultSparkSigner = class {
19204
19280
  message,
19205
19281
  keyPackage,
19206
19282
  nonce,
19207
- selfCommitment,
19283
+ selfCommitment: commitment,
19208
19284
  statechainCommitments,
19209
19285
  adaptorPubKey
19210
19286
  });
@@ -19232,7 +19308,7 @@ var DefaultSparkSigner = class {
19232
19308
  statechainPublicKeys,
19233
19309
  verifyingKey,
19234
19310
  statechainCommitments,
19235
- selfCommitment,
19311
+ selfCommitment: selfCommitment.commitment,
19236
19312
  selfPublicKey: publicKey,
19237
19313
  selfSignature,
19238
19314
  adaptorPubKey
@@ -19283,7 +19359,9 @@ var DefaultSparkSigner = class {
19283
19359
  const nonce = getRandomSigningNonce();
19284
19360
  const commitment = getSigningCommitmentFromNonce(nonce);
19285
19361
  this.commitmentToNonceMap.set(commitment, nonce);
19286
- return commitment;
19362
+ return {
19363
+ commitment
19364
+ };
19287
19365
  }
19288
19366
  async validateMessageWithIdentityKey(message, signature) {
19289
19367
  if (!this.identityKey?.publicKey) {
@@ -19337,6 +19415,64 @@ var DefaultSparkSigner = class {
19337
19415
  tx.signIdx(privateKey, index);
19338
19416
  }
19339
19417
  };
19418
+ var UnsafeStatelessSparkSigner = class extends DefaultSparkSigner {
19419
+ constructor({
19420
+ sparkKeysGenerator
19421
+ } = {}) {
19422
+ super({
19423
+ sparkKeysGenerator
19424
+ });
19425
+ }
19426
+ async getRandomSigningCommitment() {
19427
+ const nonce = getRandomSigningNonce();
19428
+ const commitment = getSigningCommitmentFromNonce(nonce);
19429
+ return {
19430
+ commitment,
19431
+ nonce
19432
+ };
19433
+ }
19434
+ async signFrost({
19435
+ message,
19436
+ keyDerivation,
19437
+ publicKey,
19438
+ verifyingKey,
19439
+ selfCommitment,
19440
+ statechainCommitments,
19441
+ adaptorPubKey
19442
+ }) {
19443
+ const SparkFrost = await getSparkFrostModule();
19444
+ if (!SparkFrost) {
19445
+ throw new ValidationError("SparkFrost module not found", {
19446
+ field: "SparkFrost"
19447
+ });
19448
+ }
19449
+ const signingPrivateKey = await this.getSigningPrivateKeyFromDerivation(keyDerivation);
19450
+ if (!signingPrivateKey) {
19451
+ throw new ValidationError("Private key not found for public key", {
19452
+ field: "privateKey"
19453
+ });
19454
+ }
19455
+ const { commitment, nonce } = selfCommitment;
19456
+ if (!nonce) {
19457
+ throw new ValidationError("Nonce not found for commitment", {
19458
+ field: "nonce"
19459
+ });
19460
+ }
19461
+ const keyPackage = {
19462
+ secretKey: signingPrivateKey,
19463
+ publicKey,
19464
+ verifyingKey
19465
+ };
19466
+ return SparkFrost.signFrost({
19467
+ message,
19468
+ keyPackage,
19469
+ nonce,
19470
+ selfCommitment: commitment,
19471
+ statechainCommitments,
19472
+ adaptorPubKey
19473
+ });
19474
+ }
19475
+ };
19340
19476
  var TaprootSparkSigner = class extends DefaultSparkSigner {
19341
19477
  constructor(useAddressIndex = false) {
19342
19478
  super({
@@ -23559,6 +23695,293 @@ var TokenTransactionWithStatus2 = {
23559
23695
  return message;
23560
23696
  }
23561
23697
  };
23698
+ function createBaseFreezeTokensPayload2() {
23699
+ return {
23700
+ version: 0,
23701
+ ownerPublicKey: new Uint8Array(0),
23702
+ tokenPublicKey: void 0,
23703
+ tokenIdentifier: void 0,
23704
+ issuerProvidedTimestamp: 0,
23705
+ operatorIdentityPublicKey: new Uint8Array(0),
23706
+ shouldUnfreeze: false
23707
+ };
23708
+ }
23709
+ var FreezeTokensPayload2 = {
23710
+ encode(message, writer = new import_wire7.BinaryWriter()) {
23711
+ if (message.version !== 0) {
23712
+ writer.uint32(8).uint32(message.version);
23713
+ }
23714
+ if (message.ownerPublicKey.length !== 0) {
23715
+ writer.uint32(18).bytes(message.ownerPublicKey);
23716
+ }
23717
+ if (message.tokenPublicKey !== void 0) {
23718
+ writer.uint32(26).bytes(message.tokenPublicKey);
23719
+ }
23720
+ if (message.tokenIdentifier !== void 0) {
23721
+ writer.uint32(34).bytes(message.tokenIdentifier);
23722
+ }
23723
+ if (message.issuerProvidedTimestamp !== 0) {
23724
+ writer.uint32(40).uint64(message.issuerProvidedTimestamp);
23725
+ }
23726
+ if (message.operatorIdentityPublicKey.length !== 0) {
23727
+ writer.uint32(50).bytes(message.operatorIdentityPublicKey);
23728
+ }
23729
+ if (message.shouldUnfreeze !== false) {
23730
+ writer.uint32(56).bool(message.shouldUnfreeze);
23731
+ }
23732
+ return writer;
23733
+ },
23734
+ decode(input, length) {
23735
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
23736
+ const end = length === void 0 ? reader.len : reader.pos + length;
23737
+ const message = createBaseFreezeTokensPayload2();
23738
+ while (reader.pos < end) {
23739
+ const tag = reader.uint32();
23740
+ switch (tag >>> 3) {
23741
+ case 1: {
23742
+ if (tag !== 8) {
23743
+ break;
23744
+ }
23745
+ message.version = reader.uint32();
23746
+ continue;
23747
+ }
23748
+ case 2: {
23749
+ if (tag !== 18) {
23750
+ break;
23751
+ }
23752
+ message.ownerPublicKey = reader.bytes();
23753
+ continue;
23754
+ }
23755
+ case 3: {
23756
+ if (tag !== 26) {
23757
+ break;
23758
+ }
23759
+ message.tokenPublicKey = reader.bytes();
23760
+ continue;
23761
+ }
23762
+ case 4: {
23763
+ if (tag !== 34) {
23764
+ break;
23765
+ }
23766
+ message.tokenIdentifier = reader.bytes();
23767
+ continue;
23768
+ }
23769
+ case 5: {
23770
+ if (tag !== 40) {
23771
+ break;
23772
+ }
23773
+ message.issuerProvidedTimestamp = longToNumber4(reader.uint64());
23774
+ continue;
23775
+ }
23776
+ case 6: {
23777
+ if (tag !== 50) {
23778
+ break;
23779
+ }
23780
+ message.operatorIdentityPublicKey = reader.bytes();
23781
+ continue;
23782
+ }
23783
+ case 7: {
23784
+ if (tag !== 56) {
23785
+ break;
23786
+ }
23787
+ message.shouldUnfreeze = reader.bool();
23788
+ continue;
23789
+ }
23790
+ }
23791
+ if ((tag & 7) === 4 || tag === 0) {
23792
+ break;
23793
+ }
23794
+ reader.skip(tag & 7);
23795
+ }
23796
+ return message;
23797
+ },
23798
+ fromJSON(object) {
23799
+ return {
23800
+ version: isSet6(object.version) ? globalThis.Number(object.version) : 0,
23801
+ ownerPublicKey: isSet6(object.ownerPublicKey) ? bytesFromBase645(object.ownerPublicKey) : new Uint8Array(0),
23802
+ tokenPublicKey: isSet6(object.tokenPublicKey) ? bytesFromBase645(object.tokenPublicKey) : void 0,
23803
+ tokenIdentifier: isSet6(object.tokenIdentifier) ? bytesFromBase645(object.tokenIdentifier) : void 0,
23804
+ issuerProvidedTimestamp: isSet6(object.issuerProvidedTimestamp) ? globalThis.Number(object.issuerProvidedTimestamp) : 0,
23805
+ operatorIdentityPublicKey: isSet6(object.operatorIdentityPublicKey) ? bytesFromBase645(object.operatorIdentityPublicKey) : new Uint8Array(0),
23806
+ shouldUnfreeze: isSet6(object.shouldUnfreeze) ? globalThis.Boolean(object.shouldUnfreeze) : false
23807
+ };
23808
+ },
23809
+ toJSON(message) {
23810
+ const obj = {};
23811
+ if (message.version !== 0) {
23812
+ obj.version = Math.round(message.version);
23813
+ }
23814
+ if (message.ownerPublicKey.length !== 0) {
23815
+ obj.ownerPublicKey = base64FromBytes5(message.ownerPublicKey);
23816
+ }
23817
+ if (message.tokenPublicKey !== void 0) {
23818
+ obj.tokenPublicKey = base64FromBytes5(message.tokenPublicKey);
23819
+ }
23820
+ if (message.tokenIdentifier !== void 0) {
23821
+ obj.tokenIdentifier = base64FromBytes5(message.tokenIdentifier);
23822
+ }
23823
+ if (message.issuerProvidedTimestamp !== 0) {
23824
+ obj.issuerProvidedTimestamp = Math.round(message.issuerProvidedTimestamp);
23825
+ }
23826
+ if (message.operatorIdentityPublicKey.length !== 0) {
23827
+ obj.operatorIdentityPublicKey = base64FromBytes5(message.operatorIdentityPublicKey);
23828
+ }
23829
+ if (message.shouldUnfreeze !== false) {
23830
+ obj.shouldUnfreeze = message.shouldUnfreeze;
23831
+ }
23832
+ return obj;
23833
+ },
23834
+ create(base) {
23835
+ return FreezeTokensPayload2.fromPartial(base ?? {});
23836
+ },
23837
+ fromPartial(object) {
23838
+ const message = createBaseFreezeTokensPayload2();
23839
+ message.version = object.version ?? 0;
23840
+ message.ownerPublicKey = object.ownerPublicKey ?? new Uint8Array(0);
23841
+ message.tokenPublicKey = object.tokenPublicKey ?? void 0;
23842
+ message.tokenIdentifier = object.tokenIdentifier ?? void 0;
23843
+ message.issuerProvidedTimestamp = object.issuerProvidedTimestamp ?? 0;
23844
+ message.operatorIdentityPublicKey = object.operatorIdentityPublicKey ?? new Uint8Array(0);
23845
+ message.shouldUnfreeze = object.shouldUnfreeze ?? false;
23846
+ return message;
23847
+ }
23848
+ };
23849
+ function createBaseFreezeTokensRequest2() {
23850
+ return { freezeTokensPayload: void 0, issuerSignature: new Uint8Array(0) };
23851
+ }
23852
+ var FreezeTokensRequest2 = {
23853
+ encode(message, writer = new import_wire7.BinaryWriter()) {
23854
+ if (message.freezeTokensPayload !== void 0) {
23855
+ FreezeTokensPayload2.encode(message.freezeTokensPayload, writer.uint32(10).fork()).join();
23856
+ }
23857
+ if (message.issuerSignature.length !== 0) {
23858
+ writer.uint32(18).bytes(message.issuerSignature);
23859
+ }
23860
+ return writer;
23861
+ },
23862
+ decode(input, length) {
23863
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
23864
+ const end = length === void 0 ? reader.len : reader.pos + length;
23865
+ const message = createBaseFreezeTokensRequest2();
23866
+ while (reader.pos < end) {
23867
+ const tag = reader.uint32();
23868
+ switch (tag >>> 3) {
23869
+ case 1: {
23870
+ if (tag !== 10) {
23871
+ break;
23872
+ }
23873
+ message.freezeTokensPayload = FreezeTokensPayload2.decode(reader, reader.uint32());
23874
+ continue;
23875
+ }
23876
+ case 2: {
23877
+ if (tag !== 18) {
23878
+ break;
23879
+ }
23880
+ message.issuerSignature = reader.bytes();
23881
+ continue;
23882
+ }
23883
+ }
23884
+ if ((tag & 7) === 4 || tag === 0) {
23885
+ break;
23886
+ }
23887
+ reader.skip(tag & 7);
23888
+ }
23889
+ return message;
23890
+ },
23891
+ fromJSON(object) {
23892
+ return {
23893
+ freezeTokensPayload: isSet6(object.freezeTokensPayload) ? FreezeTokensPayload2.fromJSON(object.freezeTokensPayload) : void 0,
23894
+ issuerSignature: isSet6(object.issuerSignature) ? bytesFromBase645(object.issuerSignature) : new Uint8Array(0)
23895
+ };
23896
+ },
23897
+ toJSON(message) {
23898
+ const obj = {};
23899
+ if (message.freezeTokensPayload !== void 0) {
23900
+ obj.freezeTokensPayload = FreezeTokensPayload2.toJSON(message.freezeTokensPayload);
23901
+ }
23902
+ if (message.issuerSignature.length !== 0) {
23903
+ obj.issuerSignature = base64FromBytes5(message.issuerSignature);
23904
+ }
23905
+ return obj;
23906
+ },
23907
+ create(base) {
23908
+ return FreezeTokensRequest2.fromPartial(base ?? {});
23909
+ },
23910
+ fromPartial(object) {
23911
+ const message = createBaseFreezeTokensRequest2();
23912
+ message.freezeTokensPayload = object.freezeTokensPayload !== void 0 && object.freezeTokensPayload !== null ? FreezeTokensPayload2.fromPartial(object.freezeTokensPayload) : void 0;
23913
+ message.issuerSignature = object.issuerSignature ?? new Uint8Array(0);
23914
+ return message;
23915
+ }
23916
+ };
23917
+ function createBaseFreezeTokensResponse2() {
23918
+ return { impactedOutputIds: [], impactedTokenAmount: new Uint8Array(0) };
23919
+ }
23920
+ var FreezeTokensResponse2 = {
23921
+ encode(message, writer = new import_wire7.BinaryWriter()) {
23922
+ for (const v of message.impactedOutputIds) {
23923
+ writer.uint32(10).string(v);
23924
+ }
23925
+ if (message.impactedTokenAmount.length !== 0) {
23926
+ writer.uint32(18).bytes(message.impactedTokenAmount);
23927
+ }
23928
+ return writer;
23929
+ },
23930
+ decode(input, length) {
23931
+ const reader = input instanceof import_wire7.BinaryReader ? input : new import_wire7.BinaryReader(input);
23932
+ const end = length === void 0 ? reader.len : reader.pos + length;
23933
+ const message = createBaseFreezeTokensResponse2();
23934
+ while (reader.pos < end) {
23935
+ const tag = reader.uint32();
23936
+ switch (tag >>> 3) {
23937
+ case 1: {
23938
+ if (tag !== 10) {
23939
+ break;
23940
+ }
23941
+ message.impactedOutputIds.push(reader.string());
23942
+ continue;
23943
+ }
23944
+ case 2: {
23945
+ if (tag !== 18) {
23946
+ break;
23947
+ }
23948
+ message.impactedTokenAmount = reader.bytes();
23949
+ continue;
23950
+ }
23951
+ }
23952
+ if ((tag & 7) === 4 || tag === 0) {
23953
+ break;
23954
+ }
23955
+ reader.skip(tag & 7);
23956
+ }
23957
+ return message;
23958
+ },
23959
+ fromJSON(object) {
23960
+ return {
23961
+ impactedOutputIds: globalThis.Array.isArray(object?.impactedOutputIds) ? object.impactedOutputIds.map((e) => globalThis.String(e)) : [],
23962
+ impactedTokenAmount: isSet6(object.impactedTokenAmount) ? bytesFromBase645(object.impactedTokenAmount) : new Uint8Array(0)
23963
+ };
23964
+ },
23965
+ toJSON(message) {
23966
+ const obj = {};
23967
+ if (message.impactedOutputIds?.length) {
23968
+ obj.impactedOutputIds = message.impactedOutputIds;
23969
+ }
23970
+ if (message.impactedTokenAmount.length !== 0) {
23971
+ obj.impactedTokenAmount = base64FromBytes5(message.impactedTokenAmount);
23972
+ }
23973
+ return obj;
23974
+ },
23975
+ create(base) {
23976
+ return FreezeTokensResponse2.fromPartial(base ?? {});
23977
+ },
23978
+ fromPartial(object) {
23979
+ const message = createBaseFreezeTokensResponse2();
23980
+ message.impactedOutputIds = object.impactedOutputIds?.map((e) => e) || [];
23981
+ message.impactedTokenAmount = object.impactedTokenAmount ?? new Uint8Array(0);
23982
+ return message;
23983
+ }
23984
+ };
23562
23985
  var SparkTokenServiceDefinition = {
23563
23986
  name: "SparkTokenService",
23564
23987
  fullName: "spark_token.SparkTokenService",
@@ -23610,6 +24033,14 @@ var SparkTokenServiceDefinition = {
23610
24033
  responseType: QueryTokenOutputsResponse2,
23611
24034
  responseStream: false,
23612
24035
  options: {}
24036
+ },
24037
+ freeze_tokens: {
24038
+ name: "freeze_tokens",
24039
+ requestType: FreezeTokensRequest2,
24040
+ requestStream: false,
24041
+ responseType: FreezeTokensResponse2,
24042
+ responseStream: false,
24043
+ options: {}
23613
24044
  }
23614
24045
  }
23615
24046
  };
@@ -24068,6 +24499,13 @@ var DEFAULT_EXPIRY_TIME = 10 * 60 * 1e3;
24068
24499
  function initialSequence() {
24069
24500
  return 1 << 30 | INITIAL_TIME_LOCK;
24070
24501
  }
24502
+ function getSigningJobProto(signingJob) {
24503
+ return {
24504
+ signingPublicKey: signingJob.signingPublicKey,
24505
+ rawTx: signingJob.rawTx,
24506
+ signingNonceCommitment: signingJob.signingNonceCommitment.commitment
24507
+ };
24508
+ }
24071
24509
  var BaseTransferService = class {
24072
24510
  config;
24073
24511
  connectionManager;
@@ -24694,7 +25132,7 @@ var TransferService = class extends BaseTransferService {
24694
25132
  refundSigningData.keyDerivation
24695
25133
  ),
24696
25134
  rawTx: refundTx.toBytes(),
24697
- signingNonceCommitment: refundNonceCommitmentProto
25135
+ signingNonceCommitment: refundNonceCommitmentProto.commitment
24698
25136
  },
24699
25137
  // TODO: Add direct refund signature
24700
25138
  directRefundTxSigningJob: void 0,
@@ -25006,7 +25444,7 @@ var TransferService = class extends BaseTransferService {
25006
25444
  const response = await sparkClient.refresh_timelock({
25007
25445
  leafId: leaf.id,
25008
25446
  ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
25009
- signingJobs
25447
+ signingJobs: signingJobs.map(getSigningJobProto)
25010
25448
  });
25011
25449
  if (signingJobs.length !== response.signingResults.length) {
25012
25450
  throw Error(
@@ -25172,8 +25610,8 @@ var TransferService = class extends BaseTransferService {
25172
25610
  const response = await sparkClient.extend_leaf({
25173
25611
  leafId: node.id,
25174
25612
  ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
25175
- nodeTxSigningJob: newNodeSigningJob,
25176
- refundTxSigningJob: newRefundSigningJob
25613
+ nodeTxSigningJob: getSigningJobProto(newNodeSigningJob),
25614
+ refundTxSigningJob: getSigningJobProto(newRefundSigningJob)
25177
25615
  });
25178
25616
  if (!response.nodeTxSigningResult || !response.refundTxSigningResult) {
25179
25617
  throw new Error("Signing result does not exist");
@@ -25281,7 +25719,7 @@ var TransferService = class extends BaseTransferService {
25281
25719
  const response = await sparkClient.refresh_timelock({
25282
25720
  leafId: node.id,
25283
25721
  ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
25284
- signingJobs: [refundSigningJob]
25722
+ signingJobs: [getSigningJobProto(refundSigningJob)]
25285
25723
  });
25286
25724
  if (response.signingResults.length !== 1) {
25287
25725
  throw Error(
@@ -25433,7 +25871,7 @@ var CoopExitService = class extends BaseTransferService {
25433
25871
  leaf.keyDerivation
25434
25872
  ),
25435
25873
  rawTx: refundTx.toBytes(),
25436
- signingNonceCommitment
25874
+ signingNonceCommitment: signingNonceCommitment.commitment
25437
25875
  },
25438
25876
  // TODO: Add direct refund signature
25439
25877
  directRefundTxSigningJob: void 0,
@@ -25688,12 +26126,12 @@ var DepositService = class {
25688
26126
  rootTxSigningJob: {
25689
26127
  rawTx: rootTx.toBytes(),
25690
26128
  signingPublicKey: signingPubKey,
25691
- signingNonceCommitment: rootNonceCommitment
26129
+ signingNonceCommitment: rootNonceCommitment.commitment
25692
26130
  },
25693
26131
  refundTxSigningJob: {
25694
26132
  rawTx: refundTx.toBytes(),
25695
26133
  signingPublicKey: signingPubKey,
25696
- signingNonceCommitment: refundNonceCommitment
26134
+ signingNonceCommitment: refundNonceCommitment.commitment
25697
26135
  }
25698
26136
  });
25699
26137
  } catch (error) {
@@ -28316,7 +28754,9 @@ var TokenTransactionService = class {
28316
28754
  issuerPublicKeys,
28317
28755
  tokenTransactionHashes,
28318
28756
  tokenIdentifiers,
28319
- outputIds
28757
+ outputIds,
28758
+ pageSize,
28759
+ offset
28320
28760
  } = params;
28321
28761
  const tokenClient = await this.connectionManager.createSparkTokenClient(
28322
28762
  this.config.getCoordinatorAddress()
@@ -28327,8 +28767,8 @@ var TokenTransactionService = class {
28327
28767
  tokenIdentifiers: tokenIdentifiers?.map(import_utils19.hexToBytes),
28328
28768
  tokenTransactionHashes: tokenTransactionHashes?.map(import_utils19.hexToBytes),
28329
28769
  outputIds: outputIds || [],
28330
- limit: 100,
28331
- offset: 0
28770
+ limit: pageSize,
28771
+ offset
28332
28772
  };
28333
28773
  try {
28334
28774
  const response = await tokenClient.query_token_transactions(queryParams);
@@ -28765,7 +29205,7 @@ var TreeCreationService = class {
28765
29205
  const signingJob = {
28766
29206
  signingPublicKey: node.signingPublicKey,
28767
29207
  rawTx: tx.toBytes(),
28768
- signingNonceCommitment
29208
+ signingNonceCommitment: signingNonceCommitment.commitment
28769
29209
  };
28770
29210
  internalCreationNode.nodeTxSigningCommitment = signingNonceCommitment;
28771
29211
  internalCreationNode.nodeTxSigningJob = signingJob;
@@ -28794,7 +29234,7 @@ var TreeCreationService = class {
28794
29234
  const childSigningJob = {
28795
29235
  signingPublicKey: node.signingPublicKey,
28796
29236
  rawTx: childTx.toBytes(),
28797
- signingNonceCommitment: childSigningNonceCommitment
29237
+ signingNonceCommitment: childSigningNonceCommitment.commitment
28798
29238
  };
28799
29239
  childCreationNode.nodeTxSigningCommitment = childSigningNonceCommitment;
28800
29240
  childCreationNode.nodeTxSigningJob = childSigningJob;
@@ -28821,7 +29261,7 @@ var TreeCreationService = class {
28821
29261
  const refundSigningJob = {
28822
29262
  signingPublicKey: node.signingPublicKey,
28823
29263
  rawTx: refundTx.toBytes(),
28824
- signingNonceCommitment: refundSigningNonceCommitment
29264
+ signingNonceCommitment: refundSigningNonceCommitment.commitment
28825
29265
  };
28826
29266
  childCreationNode.refundTxSigningCommitment = refundSigningNonceCommitment;
28827
29267
  childCreationNode.refundTxSigningJob = refundSigningJob;
@@ -28856,7 +29296,7 @@ var TreeCreationService = class {
28856
29296
  const rootNodeSigningJob = {
28857
29297
  signingPublicKey: root.signingPublicKey,
28858
29298
  rawTx: rootNodeTx.toBytes(),
28859
- signingNonceCommitment: rootNodeSigningCommitment
29299
+ signingNonceCommitment: rootNodeSigningCommitment.commitment
28860
29300
  };
28861
29301
  const rootCreationNode = {
28862
29302
  nodeTxSigningJob: rootNodeSigningJob,
@@ -29089,7 +29529,7 @@ var SigningService = class {
29089
29529
  leaf.keyDerivation
29090
29530
  ),
29091
29531
  rawTx: refundTx.toBytes(),
29092
- signingNonceCommitment: signingCommitment,
29532
+ signingNonceCommitment: signingCommitment.commitment,
29093
29533
  userSignature: signingResult,
29094
29534
  signingCommitments: {
29095
29535
  signingCommitments: signingNonceCommitments
@@ -29682,11 +30122,24 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29682
30122
  }
29683
30123
  }
29684
30124
  }
29685
- const verifyKey = (pubkey1, pubkey2, verifyingKey) => {
29686
- return (0, import_utils24.equalBytes)(addPublicKeys(pubkey1, pubkey2), verifyingKey);
29687
- };
29688
- for (const [id, leaf] of Object.entries(leaves.nodes)) {
29689
- if (!verifyKey(
30125
+ const availableLeaves = Object.entries(leaves.nodes).filter(
30126
+ ([_, node]) => node.status === "AVAILABLE"
30127
+ );
30128
+ for (const [id, leaf] of availableLeaves) {
30129
+ if (leaf.parentNodeId && leaf.status === "AVAILABLE" && this.verifyKey(
30130
+ await this.config.signer.getPublicKeyFromDerivation({
30131
+ type: "leaf" /* LEAF */,
30132
+ path: leaf.parentNodeId
30133
+ }),
30134
+ leaf.signingKeyshare?.publicKey ?? new Uint8Array(),
30135
+ leaf.verifyingPublicKey
30136
+ )) {
30137
+ this.transferLeavesToSelf([leaf], {
30138
+ type: "leaf" /* LEAF */,
30139
+ path: leaf.parentNodeId
30140
+ });
30141
+ leavesToIgnore.add(id);
30142
+ } else if (!this.verifyKey(
29690
30143
  await this.config.signer.getPublicKeyFromDerivation({
29691
30144
  type: "leaf" /* LEAF */,
29692
30145
  path: leaf.id
@@ -29697,9 +30150,23 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29697
30150
  leavesToIgnore.add(id);
29698
30151
  }
29699
30152
  }
29700
- return Object.entries(leaves.nodes).filter(
29701
- ([_, node]) => node.status === "AVAILABLE" && !leavesToIgnore.has(node.id)
29702
- ).map(([_, node]) => node);
30153
+ return availableLeaves.filter(([_, node]) => !leavesToIgnore.has(node.id)).map(([_, node]) => node);
30154
+ }
30155
+ async checkExtendLeaves(leaves) {
30156
+ await this.withLeaves(async () => {
30157
+ for (const leaf of leaves) {
30158
+ if (!leaf.parentNodeId && leaf.status === "AVAILABLE") {
30159
+ const res = await this.transferService.extendTimelock(leaf);
30160
+ await this.transferLeavesToSelf(res.nodes, {
30161
+ type: "leaf" /* LEAF */,
30162
+ path: leaf.id
30163
+ });
30164
+ }
30165
+ }
30166
+ });
30167
+ }
30168
+ verifyKey(pubkey1, pubkey2, verifyingKey) {
30169
+ return (0, import_utils24.equalBytes)(addPublicKeys(pubkey1, pubkey2), verifyingKey);
29703
30170
  }
29704
30171
  async selectLeaves(targetAmounts) {
29705
30172
  if (targetAmounts.length === 0) {
@@ -29838,6 +30305,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
29838
30305
  leaves = await this.checkRefreshTimelockNodes(leaves);
29839
30306
  leaves = await this.checkExtendTimeLockNodes(leaves);
29840
30307
  this.leaves = leaves;
30308
+ this.checkExtendLeaves(leaves);
29841
30309
  this.optimizeLeaves().catch((e) => {
29842
30310
  console.error("Failed to optimize leaves", e);
29843
30311
  });
@@ -30537,7 +31005,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
30537
31005
  const signingJob = {
30538
31006
  rawTx: tx.toBytes(),
30539
31007
  signingPublicKey: await this.config.signer.getStaticDepositSigningKey(0),
30540
- signingNonceCommitment
31008
+ signingNonceCommitment: signingNonceCommitment.commitment
30541
31009
  };
30542
31010
  const message = await this.getStaticDepositSigningPayload(
30543
31011
  depositTransactionId,
@@ -31998,14 +32466,18 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
31998
32466
  issuerPublicKeys,
31999
32467
  tokenTransactionHashes,
32000
32468
  tokenIdentifiers,
32001
- outputIds
32469
+ outputIds,
32470
+ pageSize = 100,
32471
+ offset = 0
32002
32472
  }) {
32003
32473
  return this.tokenTransactionService.queryTokenTransactions({
32004
32474
  ownerPublicKeys,
32005
32475
  issuerPublicKeys,
32006
32476
  tokenTransactionHashes,
32007
32477
  tokenIdentifiers,
32008
- outputIds
32478
+ outputIds,
32479
+ pageSize,
32480
+ offset
32009
32481
  });
32010
32482
  }
32011
32483
  async getTokenL1Address() {
@@ -32467,7 +32939,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
32467
32939
  init_buffer();
32468
32940
 
32469
32941
  // src/index.node.ts
32470
- var cryptoImpl2 = typeof global !== "undefined" && global.crypto ? global.crypto : import_crypto4.default;
32942
+ var cryptoImpl2 = typeof global !== "undefined" && global.crypto ? global.crypto : import_crypto3.default;
32471
32943
  setCrypto(cryptoImpl2);
32472
32944
  // Annotate the CommonJS export names for ESM import in node:
32473
32945
  0 && (module.exports = {
@@ -32490,6 +32962,7 @@ setCrypto(cryptoImpl2);
32490
32962
  TaprootOutputKeysGenerator,
32491
32963
  TaprootSparkSigner,
32492
32964
  TokenTransactionService,
32965
+ UnsafeStatelessSparkSigner,
32493
32966
  ValidationError,
32494
32967
  WalletConfig,
32495
32968
  addPrivateKeys,