@msafe/sui3-sdk 0.0.15-pre-3e855d9.0 → 0.0.15

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.
package/dist/index.js CHANGED
@@ -96,10 +96,13 @@ var InvitationSDK = class {
96
96
 
97
97
  // src/core/MSafeAccount.ts
98
98
  import {
99
- buildIntentionTransaction,
100
99
  MultiSigAccount as MultiSigAccount2,
101
- SigningMessageHelper as SigningMessageHelper3
100
+ SigningMessageHelper as SigningMessageHelper3,
101
+ TransactionDefaultApplication,
102
+ TransactionSubTypes,
103
+ TransactionType
102
104
  } from "@msafe/sui3-utils";
105
+ import { TransactionBlock as TransactionBlock4 } from "@mysten/sui.js/transactions";
103
106
  import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
104
107
 
105
108
  // src/transactions/coin-transfer.ts
@@ -630,28 +633,34 @@ var MSafeAccount = class _MSafeAccount {
630
633
  return getAllOwnedObjects(this.suiClient, this.address, filterCoinObjectOptions);
631
634
  }
632
635
  async pendingTransaction() {
633
- const pendings = await this.backend.getPendingTransactions(this.address);
634
- if (pendings.length > 2) {
635
- throw new Error(`invalid backend getPendingTransactions resp, length should not > 2: ${pendings}`);
636
- }
637
- if (pendings.length === 0) {
636
+ const res = await this.backend.getPendingTransactions({ msafeAddress: this.address });
637
+ if (!res.pending) {
638
638
  return void 0;
639
639
  }
640
- const pendingTx = pendings.find((tx) => !tx.isRejectTx);
641
- const rejectPending = pendings.find((tx) => tx.isRejectTx);
640
+ const pendingTx = res.pending;
641
+ const rejectPending = res.reject;
642
642
  return {
643
- ...pendingTx,
643
+ createdAt: pendingTx.createAt,
644
+ creator: pendingTx.creator,
645
+ digest: pendingTx.digest,
646
+ intention: pendingTx.intention,
647
+ sequenceNumber: pendingTx.sequenceNumber,
648
+ payload: pendingTx.payload,
649
+ votes: pendingTx.votes,
650
+ msafeAddress: pendingTx.msafeAddress,
644
651
  rejectDigest: rejectPending?.digest ?? "",
645
652
  rejectPayload: rejectPending?.payload ?? "",
646
653
  rejectVotes: rejectPending?.votes ?? []
647
654
  };
648
655
  }
649
- async historyTransaction(paginationOption) {
650
- return this.backend.getHistoryTransactions(this.address, paginationOption);
656
+ async historyTransaction(pagination) {
657
+ return this.backend.getHistoryTransactions({
658
+ msafeAddress: this.address,
659
+ ...pagination
660
+ });
651
661
  }
652
- async futureIntentions(paginationOption) {
653
- const paginatedIntentions = await this.backend.getFutureIntentions(this.address, paginationOption);
654
- return paginatedIntentions.data;
662
+ async futureIntentions(pagination) {
663
+ return this.backend.getFutureIntentions({ msafeAddress: this.address, ...pagination });
655
664
  }
656
665
  async currentSequenceNumber() {
657
666
  return this.backend.getCurrentSequenceNumber(this.address);
@@ -671,17 +680,35 @@ var MSafeAccount = class _MSafeAccount {
671
680
  await this.backend.proposeIntention({
672
681
  ...input,
673
682
  msafeAddress: this.address,
674
- userAddress: await this.userAddress(),
675
683
  signature: signature.signature
676
684
  });
677
685
  }
686
+ async proposeCoinTransferIntention(intention) {
687
+ const sn = await this.nextSequenceNumber();
688
+ return this.proposeIntention({
689
+ application: TransactionDefaultApplication,
690
+ txType: TransactionType.Assets,
691
+ txSubType: TransactionSubTypes.assets.coin.send,
692
+ sequenceNumber: sn,
693
+ intention
694
+ });
695
+ }
696
+ async proposeObjectTransferIntention(intention) {
697
+ const sn = await this.nextSequenceNumber();
698
+ return this.proposeIntention({
699
+ application: TransactionDefaultApplication,
700
+ txType: TransactionType.Assets,
701
+ txSubType: TransactionSubTypes.assets.object.send,
702
+ sequenceNumber: sn,
703
+ intention
704
+ });
705
+ }
678
706
  async voteForTransaction(digest, payload) {
679
707
  const payloadBytes = HexToUint8Array(payload);
680
708
  const signature = await this.wallet.signTransactionBlock({ transactionBlock: payloadBytes });
681
709
  return this.backend.voteForTransaction({
682
710
  msafeAddress: this.address,
683
- userAddress: await this.userAddress(),
684
- txDigest: digest,
711
+ digest,
685
712
  signature: signature.signature
686
713
  });
687
714
  }
@@ -704,20 +731,12 @@ var MSafeAccount = class _MSafeAccount {
704
731
  signature: signature.signature
705
732
  });
706
733
  }
707
- async rejectCurrentTx(pending) {
708
- let payloadToReject;
709
- if (pending) {
710
- if (pending.isRejectTx) {
711
- throw new Error("Pending not reject transaction");
712
- }
713
- payloadToReject = pending.payload;
714
- } else {
715
- const pendingTx = await this.pendingTransaction();
716
- if (!pendingTx || pendingTx.rejectDigest !== "") {
717
- throw new Error("Already rejected");
718
- }
719
- payloadToReject = pendingTx.payload;
734
+ async rejectCurrentTx() {
735
+ const pendingTx = await this.pendingTransaction();
736
+ if (!pendingTx || pendingTx.rejectDigest !== "") {
737
+ throw new Error("Already rejected");
720
738
  }
739
+ const payloadToReject = pendingTx.payload;
721
740
  const rejectTxb = await IntentionHelper.buildRejectTransaction({
722
741
  msafeAddress: this.address,
723
742
  payloadToReject
@@ -727,7 +746,6 @@ var MSafeAccount = class _MSafeAccount {
727
746
  const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
728
747
  return this.backend.rejectCurrentTx({
729
748
  msafeAddress: this.address,
730
- userAddress: await this.userAddress(),
731
749
  digest,
732
750
  signature: signature.signature
733
751
  });
@@ -736,10 +754,11 @@ var MSafeAccount = class _MSafeAccount {
736
754
  return this.backend.buildNextIntentionAndAddToPending({ msafeAddress: this.address });
737
755
  }
738
756
  async skipNextFailedIntention() {
739
- return this.backend.skipNextFailedIntention({ msafeAddress: this.address, userAddress: await this.userAddress() });
757
+ return this.backend.skipNextFailedIntention({ msafeAddress: this.address });
740
758
  }
741
759
  async simulateIntention(intention) {
742
- const txb = await buildIntentionTransaction(this.suiClient, intention, this.address);
760
+ const txb = new TransactionBlock4();
761
+ txb.setSender(this.address);
743
762
  if (!txb.blockData.gasConfig.price) {
744
763
  const refGas = await this.suiClient.getReferenceGasPrice();
745
764
  txb.setGasPrice(refGas);
@@ -971,8 +990,9 @@ var BackendImpl = class _BackendImpl {
971
990
  throw new Error(`Invalid updateMSafeStatus return: ${res}`);
972
991
  }
973
992
  }
974
- async getPendingTransactions(msafeAddress) {
975
- const res = await axios.get(`${this.apiURL}/transaction/pending/${msafeAddress}`, {
993
+ async getPendingTransactions(input) {
994
+ const res = await axios.get(`${this.apiURL}/transaction/pending`, {
995
+ params: input,
976
996
  headers: this.headers()
977
997
  });
978
998
  if (res.status !== 200 && res.status !== 201) {
@@ -980,28 +1000,19 @@ var BackendImpl = class _BackendImpl {
980
1000
  }
981
1001
  return res.data;
982
1002
  }
983
- async getHistoryTransactions(msafeAddress, paginationOption) {
984
- const res = await axios.get(
985
- `${this.apiURL}/transaction/history?address=${msafeAddress}`,
986
- {
987
- params: {
988
- page: paginationOption?.page,
989
- limit: paginationOption?.limit
990
- },
991
- headers: this.headers()
992
- }
993
- );
1003
+ async getHistoryTransactions(input) {
1004
+ const res = await axios.get(`${this.apiURL}/transaction/history`, {
1005
+ params: input,
1006
+ headers: this.headers()
1007
+ });
994
1008
  if (res.status !== 200 && res.status !== 201) {
995
1009
  throw new Error(`invalid getCurrentSequenceNumber return: ${res}`);
996
1010
  }
997
1011
  return res.data;
998
1012
  }
999
- async getFutureIntentions(msafeAddress, paginationOption) {
1000
- const res = await axios.get(`${this.apiURL}/transaction/intention/${msafeAddress}`, {
1001
- params: {
1002
- page: paginationOption?.page,
1003
- limit: paginationOption?.limit
1004
- },
1013
+ async getFutureIntentions(input) {
1014
+ const res = await axios.get(`${this.apiURL}/transaction/intention`, {
1015
+ params: input,
1005
1016
  headers: this.headers()
1006
1017
  });
1007
1018
  if (res.status !== 200 && res.status !== 201) {
@@ -1009,8 +1020,11 @@ var BackendImpl = class _BackendImpl {
1009
1020
  }
1010
1021
  return res.data;
1011
1022
  }
1012
- async getCurrentSequenceNumber(msafeAddress) {
1013
- const res = await axios.get(`${this.apiURL}/transaction/sn/current/${msafeAddress}`, {
1023
+ async getCurrentSequenceNumber(address) {
1024
+ const res = await axios.get(`${this.apiURL}/transaction/sn/current`, {
1025
+ params: {
1026
+ msafeAddress: address
1027
+ },
1014
1028
  headers: this.headers()
1015
1029
  });
1016
1030
  if (res.status !== 200 && res.status !== 201) {
@@ -1018,8 +1032,11 @@ var BackendImpl = class _BackendImpl {
1018
1032
  }
1019
1033
  return res.data;
1020
1034
  }
1021
- async getNextSequenceNumber(msafeAddress) {
1022
- const res = await axios.get(`${this.apiURL}/transaction/sn/next/${msafeAddress}`, {
1035
+ async getNextSequenceNumber(address) {
1036
+ const res = await axios.get(`${this.apiURL}/transaction/sn/next`, {
1037
+ params: {
1038
+ msafeAddress: address
1039
+ },
1023
1040
  headers: this.headers()
1024
1041
  });
1025
1042
  if (res.status !== 200 && res.status !== 201) {
@@ -1047,57 +1064,29 @@ var BackendImpl = class _BackendImpl {
1047
1064
  return void 0;
1048
1065
  }
1049
1066
  async rejectCurrentTx(input) {
1050
- const res = await axios.post(
1051
- `${this.apiURL}/transaction/pending/reject`,
1052
- {
1053
- address: input.msafeAddress,
1054
- digest: input.digest,
1055
- signature: input.signature
1056
- },
1057
- {
1058
- headers: this.headers()
1059
- }
1060
- );
1067
+ const res = await axios.post(`${this.apiURL}/transaction/pending/reject`, input, {
1068
+ headers: this.headers()
1069
+ });
1061
1070
  if (res.status !== 200 && res.status !== 201) {
1062
1071
  throw new Error(`invalid voteForTransaction return: ${res}`);
1063
1072
  }
1064
1073
  }
1065
1074
  async voteForTransaction(input) {
1066
- const res = await axios.post(
1067
- `${this.apiURL}/transaction/pending/vote`,
1068
- {
1069
- address: input.msafeAddress,
1070
- digest: input.txDigest,
1071
- signature: input.signature
1072
- },
1073
- {
1074
- headers: this.headers()
1075
- }
1076
- );
1075
+ const res = await axios.post(`${this.apiURL}/transaction/pending/vote`, input, {
1076
+ headers: this.headers()
1077
+ });
1077
1078
  if (res.status !== 200 && res.status !== 201) {
1078
1079
  throw new Error(`invalid voteForTransaction return: ${res}`);
1079
1080
  }
1080
1081
  }
1081
1082
  async buildNextIntentionAndAddToPending(input) {
1082
- const res = await axios.post(
1083
- `${this.apiURL}/transaction/pending/build`,
1084
- {
1085
- address: input.msafeAddress
1086
- },
1087
- { headers: this.headers() }
1088
- );
1083
+ const res = await axios.post(`${this.apiURL}/transaction/pending/build`, input, { headers: this.headers() });
1089
1084
  if (res.status !== 200 && res.status !== 201) {
1090
1085
  throw new Error(`invalid buildNextIntentionAndAddToPending return: ${res}`);
1091
1086
  }
1092
1087
  }
1093
1088
  async skipNextFailedIntention(input) {
1094
- const res = await axios.post(
1095
- `${this.apiURL}/transaction/pending/skip`,
1096
- {
1097
- msafeAddress: input.msafeAddress
1098
- },
1099
- { headers: this.headers() }
1100
- );
1089
+ const res = await axios.post(`${this.apiURL}/transaction/pending/skip`, input, { headers: this.headers() });
1101
1090
  if (res.status !== 200 && res.status !== 201) {
1102
1091
  throw new Error(`invalid skipNextFailedIntention return: ${res}`);
1103
1092
  }