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