@msafe/sui3-sdk 0.0.11 → 0.0.12-pre-0fb7c20.0
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 +45 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -7
- package/dist/index.d.ts +15 -7
- package/dist/index.js +46 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/MSafeAccount.ts +46 -19
- package/src/core/MessageHelper.ts +6 -2
- package/src/types/msafe.ts +15 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _mysten_sui_js_src_cryptography from '@mysten/sui.js/src/cryptography';
|
|
2
2
|
import { PublicKey as PublicKey$1 } from '@mysten/sui.js/src/cryptography';
|
|
3
3
|
import * as _mysten_sui_js_client from '@mysten/sui.js/client';
|
|
4
|
-
import { SuiClient, ExecuteTransactionRequestType, SuiTransactionBlockResponseOptions, SuiTransactionBlockResponse, CoinMetadata, SuiObjectDataOptions, SuiObjectResponse, SuiObjectData, CoinStruct } from '@mysten/sui.js/client';
|
|
4
|
+
import { SuiClient, GasCostSummary, DryRunTransactionBlockResponse, ExecuteTransactionRequestType, SuiTransactionBlockResponseOptions, SuiTransactionBlockResponse, CoinMetadata, SuiObjectDataOptions, SuiObjectResponse, SuiObjectData, CoinStruct } from '@mysten/sui.js/client';
|
|
5
5
|
import * as _msafe_sui3_utils from '@msafe/sui3-utils';
|
|
6
6
|
import { AuthLoginRequest, MSafeAccountInfo, UserWithOwnedMSafe, HistoryTransaction, CreateMSafeAccountInfoRequest, MultisigAccountManager } from '@msafe/sui3-utils';
|
|
7
7
|
import { PublicKey, SerializedSignature, SignatureScheme } from '@mysten/sui.js/cryptography';
|
|
@@ -72,9 +72,9 @@ interface PendingTx {
|
|
|
72
72
|
createdAt: Date;
|
|
73
73
|
sequenceNumber: number;
|
|
74
74
|
votes: PendingVote[];
|
|
75
|
-
rejectDigest
|
|
76
|
-
rejectPayload
|
|
77
|
-
rejectVotes
|
|
75
|
+
rejectDigest: string;
|
|
76
|
+
rejectPayload: string;
|
|
77
|
+
rejectVotes: PendingVote[];
|
|
78
78
|
}
|
|
79
79
|
interface PendingVote {
|
|
80
80
|
userAddress: string;
|
|
@@ -117,6 +117,13 @@ interface FutureIntention {
|
|
|
117
117
|
statusRemark?: string;
|
|
118
118
|
createdAt: Date;
|
|
119
119
|
}
|
|
120
|
+
interface SimulationResult {
|
|
121
|
+
success: boolean;
|
|
122
|
+
errorMsg?: string;
|
|
123
|
+
gasPrice: bigint;
|
|
124
|
+
gasUsed: GasCostSummary;
|
|
125
|
+
dryRunResult: DryRunTransactionBlockResponse;
|
|
126
|
+
}
|
|
120
127
|
|
|
121
128
|
interface IWallet {
|
|
122
129
|
walletType: string;
|
|
@@ -328,6 +335,7 @@ declare class MessageHelper {
|
|
|
328
335
|
static updateAddressBookMessage(updates: UpdateAddressBookEntry[]): string;
|
|
329
336
|
}
|
|
330
337
|
interface ProposeIntentionData {
|
|
338
|
+
msafeAddress: string;
|
|
331
339
|
intention: TxIntention;
|
|
332
340
|
sn: number;
|
|
333
341
|
}
|
|
@@ -361,9 +369,8 @@ declare class MSafeAccount {
|
|
|
361
369
|
static new(globals: MSafeGlobals, address: string): Promise<MSafeAccountInfo>;
|
|
362
370
|
ownedCoins(): Promise<OwnedCoin[]>;
|
|
363
371
|
ownedObjects(options?: BatchObjectOptions): Promise<SuiObjectData[]>;
|
|
364
|
-
pendingTransactions(): Promise<PendingTx[]>;
|
|
365
372
|
pendingTransaction(): Promise<PendingTx | undefined>;
|
|
366
|
-
historyTransaction(paginationOption?: PaginationOption): Promise<_msafe_sui3_utils.HistoryTransaction
|
|
373
|
+
historyTransaction(paginationOption?: PaginationOption): Promise<PagedResult<_msafe_sui3_utils.HistoryTransaction>>;
|
|
367
374
|
futureIntentions(paginationOption?: PaginationOption): Promise<FutureIntention[]>;
|
|
368
375
|
currentSequenceNumber(): Promise<number>;
|
|
369
376
|
nextSequenceNumber(): Promise<number>;
|
|
@@ -373,6 +380,7 @@ declare class MSafeAccount {
|
|
|
373
380
|
rejectCurrentTx(pending?: PendingTx): Promise<void>;
|
|
374
381
|
buildNextIntentionAndAddToPending(): Promise<void>;
|
|
375
382
|
skipNextFailedIntention(): Promise<void>;
|
|
383
|
+
simulateIntention(intention: TxIntention): Promise<SimulationResult>;
|
|
376
384
|
executePendingTx(pending: PendingTx): Promise<_mysten_sui_js_client.SuiTransactionBlockResponse>;
|
|
377
385
|
get address(): string;
|
|
378
386
|
private get backend();
|
|
@@ -477,4 +485,4 @@ declare class Coin {
|
|
|
477
485
|
static getBalance(data: SuiObjectData): bigint | undefined;
|
|
478
486
|
}
|
|
479
487
|
|
|
480
|
-
export { AUTH_SIGN_MESSAGE, AddressBookSDK, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeAccountInfo, type CreatePermissionInfo, type DBConfig, DEV_API_URL, DEV_DATABASE_CONFIG, DEV_SYNCING_URL, type DeleteAddressBookEntry, ENV_CONFIGS, Formatter, type FutureIntention, type GetAddressBookResult, type GetAddressBookResultEntry, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, type IntentionCoinTransfer, IntentionHelper, type IntentionObjectTransfer, type JWTToken, LOCAL_API_URL, LOCAL_DATABASE_CONFIG, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnv, MSafeGlobals, MessageHelper, OpAddressBookType, type PagedMeta, type PagedResult, type PaginationMeta, type PaginationOption, type PaginationResponse, type PendingTx, type PendingVote, PublicKeySerde, type ReceiveTransaction, SUI_COIN, SignatureVerifier, TESTNET_RPC_URL, type TxIntention, UNIT_DATABASE_CONFIG, Uint8ArrayToHex, type UpdateAddressBookEntry, type UpsertAddressBookEntry, getAllCoins, getMSafeConfig, getPublicKeyFromChain, stringToBuffer };
|
|
488
|
+
export { AUTH_SIGN_MESSAGE, AddressBookSDK, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeAccountInfo, type CreatePermissionInfo, type DBConfig, DEV_API_URL, DEV_DATABASE_CONFIG, DEV_SYNCING_URL, type DeleteAddressBookEntry, ENV_CONFIGS, Formatter, type FutureIntention, type GetAddressBookResult, type GetAddressBookResultEntry, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, type IntentionCoinTransfer, IntentionHelper, type IntentionObjectTransfer, type JWTToken, LOCAL_API_URL, LOCAL_DATABASE_CONFIG, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnv, MSafeGlobals, MessageHelper, OpAddressBookType, type PagedMeta, type PagedResult, type PaginationMeta, type PaginationOption, type PaginationResponse, type PendingTx, type PendingVote, PublicKeySerde, type ReceiveTransaction, SUI_COIN, SignatureVerifier, type SimulationResult, TESTNET_RPC_URL, type TxIntention, UNIT_DATABASE_CONFIG, Uint8ArrayToHex, type UpdateAddressBookEntry, type UpsertAddressBookEntry, getAllCoins, getMSafeConfig, getPublicKeyFromChain, stringToBuffer };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _mysten_sui_js_src_cryptography from '@mysten/sui.js/src/cryptography';
|
|
2
2
|
import { PublicKey as PublicKey$1 } from '@mysten/sui.js/src/cryptography';
|
|
3
3
|
import * as _mysten_sui_js_client from '@mysten/sui.js/client';
|
|
4
|
-
import { SuiClient, ExecuteTransactionRequestType, SuiTransactionBlockResponseOptions, SuiTransactionBlockResponse, CoinMetadata, SuiObjectDataOptions, SuiObjectResponse, SuiObjectData, CoinStruct } from '@mysten/sui.js/client';
|
|
4
|
+
import { SuiClient, GasCostSummary, DryRunTransactionBlockResponse, ExecuteTransactionRequestType, SuiTransactionBlockResponseOptions, SuiTransactionBlockResponse, CoinMetadata, SuiObjectDataOptions, SuiObjectResponse, SuiObjectData, CoinStruct } from '@mysten/sui.js/client';
|
|
5
5
|
import * as _msafe_sui3_utils from '@msafe/sui3-utils';
|
|
6
6
|
import { AuthLoginRequest, MSafeAccountInfo, UserWithOwnedMSafe, HistoryTransaction, CreateMSafeAccountInfoRequest, MultisigAccountManager } from '@msafe/sui3-utils';
|
|
7
7
|
import { PublicKey, SerializedSignature, SignatureScheme } from '@mysten/sui.js/cryptography';
|
|
@@ -72,9 +72,9 @@ interface PendingTx {
|
|
|
72
72
|
createdAt: Date;
|
|
73
73
|
sequenceNumber: number;
|
|
74
74
|
votes: PendingVote[];
|
|
75
|
-
rejectDigest
|
|
76
|
-
rejectPayload
|
|
77
|
-
rejectVotes
|
|
75
|
+
rejectDigest: string;
|
|
76
|
+
rejectPayload: string;
|
|
77
|
+
rejectVotes: PendingVote[];
|
|
78
78
|
}
|
|
79
79
|
interface PendingVote {
|
|
80
80
|
userAddress: string;
|
|
@@ -117,6 +117,13 @@ interface FutureIntention {
|
|
|
117
117
|
statusRemark?: string;
|
|
118
118
|
createdAt: Date;
|
|
119
119
|
}
|
|
120
|
+
interface SimulationResult {
|
|
121
|
+
success: boolean;
|
|
122
|
+
errorMsg?: string;
|
|
123
|
+
gasPrice: bigint;
|
|
124
|
+
gasUsed: GasCostSummary;
|
|
125
|
+
dryRunResult: DryRunTransactionBlockResponse;
|
|
126
|
+
}
|
|
120
127
|
|
|
121
128
|
interface IWallet {
|
|
122
129
|
walletType: string;
|
|
@@ -328,6 +335,7 @@ declare class MessageHelper {
|
|
|
328
335
|
static updateAddressBookMessage(updates: UpdateAddressBookEntry[]): string;
|
|
329
336
|
}
|
|
330
337
|
interface ProposeIntentionData {
|
|
338
|
+
msafeAddress: string;
|
|
331
339
|
intention: TxIntention;
|
|
332
340
|
sn: number;
|
|
333
341
|
}
|
|
@@ -361,9 +369,8 @@ declare class MSafeAccount {
|
|
|
361
369
|
static new(globals: MSafeGlobals, address: string): Promise<MSafeAccountInfo>;
|
|
362
370
|
ownedCoins(): Promise<OwnedCoin[]>;
|
|
363
371
|
ownedObjects(options?: BatchObjectOptions): Promise<SuiObjectData[]>;
|
|
364
|
-
pendingTransactions(): Promise<PendingTx[]>;
|
|
365
372
|
pendingTransaction(): Promise<PendingTx | undefined>;
|
|
366
|
-
historyTransaction(paginationOption?: PaginationOption): Promise<_msafe_sui3_utils.HistoryTransaction
|
|
373
|
+
historyTransaction(paginationOption?: PaginationOption): Promise<PagedResult<_msafe_sui3_utils.HistoryTransaction>>;
|
|
367
374
|
futureIntentions(paginationOption?: PaginationOption): Promise<FutureIntention[]>;
|
|
368
375
|
currentSequenceNumber(): Promise<number>;
|
|
369
376
|
nextSequenceNumber(): Promise<number>;
|
|
@@ -373,6 +380,7 @@ declare class MSafeAccount {
|
|
|
373
380
|
rejectCurrentTx(pending?: PendingTx): Promise<void>;
|
|
374
381
|
buildNextIntentionAndAddToPending(): Promise<void>;
|
|
375
382
|
skipNextFailedIntention(): Promise<void>;
|
|
383
|
+
simulateIntention(intention: TxIntention): Promise<SimulationResult>;
|
|
376
384
|
executePendingTx(pending: PendingTx): Promise<_mysten_sui_js_client.SuiTransactionBlockResponse>;
|
|
377
385
|
get address(): string;
|
|
378
386
|
private get backend();
|
|
@@ -477,4 +485,4 @@ declare class Coin {
|
|
|
477
485
|
static getBalance(data: SuiObjectData): bigint | undefined;
|
|
478
486
|
}
|
|
479
487
|
|
|
480
|
-
export { AUTH_SIGN_MESSAGE, AddressBookSDK, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeAccountInfo, type CreatePermissionInfo, type DBConfig, DEV_API_URL, DEV_DATABASE_CONFIG, DEV_SYNCING_URL, type DeleteAddressBookEntry, ENV_CONFIGS, Formatter, type FutureIntention, type GetAddressBookResult, type GetAddressBookResultEntry, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, type IntentionCoinTransfer, IntentionHelper, type IntentionObjectTransfer, type JWTToken, LOCAL_API_URL, LOCAL_DATABASE_CONFIG, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnv, MSafeGlobals, MessageHelper, OpAddressBookType, type PagedMeta, type PagedResult, type PaginationMeta, type PaginationOption, type PaginationResponse, type PendingTx, type PendingVote, PublicKeySerde, type ReceiveTransaction, SUI_COIN, SignatureVerifier, TESTNET_RPC_URL, type TxIntention, UNIT_DATABASE_CONFIG, Uint8ArrayToHex, type UpdateAddressBookEntry, type UpsertAddressBookEntry, getAllCoins, getMSafeConfig, getPublicKeyFromChain, stringToBuffer };
|
|
488
|
+
export { AUTH_SIGN_MESSAGE, AddressBookSDK, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeAccountInfo, type CreatePermissionInfo, type DBConfig, DEV_API_URL, DEV_DATABASE_CONFIG, DEV_SYNCING_URL, type DeleteAddressBookEntry, ENV_CONFIGS, Formatter, type FutureIntention, type GetAddressBookResult, type GetAddressBookResultEntry, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, type IntentionCoinTransfer, IntentionHelper, type IntentionObjectTransfer, type JWTToken, LOCAL_API_URL, LOCAL_DATABASE_CONFIG, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnv, MSafeGlobals, MessageHelper, OpAddressBookType, type PagedMeta, type PagedResult, type PaginationMeta, type PaginationOption, type PaginationResponse, type PendingTx, type PendingVote, PublicKeySerde, type ReceiveTransaction, SUI_COIN, SignatureVerifier, type SimulationResult, TESTNET_RPC_URL, type TxIntention, UNIT_DATABASE_CONFIG, Uint8ArrayToHex, type UpdateAddressBookEntry, type UpsertAddressBookEntry, getAllCoins, getMSafeConfig, getPublicKeyFromChain, stringToBuffer };
|
package/dist/index.js
CHANGED
|
@@ -480,11 +480,12 @@ var MessageHelper = class {
|
|
|
480
480
|
return matches ? matches[1] : void 0;
|
|
481
481
|
}
|
|
482
482
|
static proposeIntentionMessage(data) {
|
|
483
|
-
const { intention, sn } = data;
|
|
483
|
+
const { msafeAddress, intention, sn } = data;
|
|
484
484
|
const intentionData = IntentionHelper.ser(intention);
|
|
485
485
|
const msg = {
|
|
486
486
|
intentionData,
|
|
487
|
-
sequenceNumber: sn
|
|
487
|
+
sequenceNumber: sn,
|
|
488
|
+
msafeAddress
|
|
488
489
|
};
|
|
489
490
|
return JSON.stringify(msg);
|
|
490
491
|
}
|
|
@@ -493,8 +494,9 @@ var MessageHelper = class {
|
|
|
493
494
|
if (!("intentionData" in de) || typeof de.intentionData !== "string" || !("sequenceNumber" in de) || typeof de.sequenceNumber !== "number") {
|
|
494
495
|
throw new Error("Invalid intention data");
|
|
495
496
|
}
|
|
496
|
-
const { sequenceNumber, intentionData } = de;
|
|
497
|
+
const { msafeAddress, sequenceNumber, intentionData } = de;
|
|
497
498
|
return {
|
|
499
|
+
msafeAddress,
|
|
498
500
|
sn: sequenceNumber,
|
|
499
501
|
intention: IntentionHelper.de(intentionData)
|
|
500
502
|
};
|
|
@@ -534,7 +536,7 @@ var AddressBookSDK = class {
|
|
|
534
536
|
};
|
|
535
537
|
|
|
536
538
|
// src/core/MSafeAccount.ts
|
|
537
|
-
import { MultisigAccountManager as MultisigAccountManager2 } from "@msafe/sui3-utils";
|
|
539
|
+
import { buildIntentionTransaction, MultisigAccountManager as MultisigAccountManager2 } from "@msafe/sui3-utils";
|
|
538
540
|
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
|
|
539
541
|
|
|
540
542
|
// src/utils/iter/iterator.ts
|
|
@@ -696,10 +698,11 @@ var MSafeAccount = class {
|
|
|
696
698
|
);
|
|
697
699
|
}
|
|
698
700
|
async ownedObjects(options) {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
701
|
+
const filterCoinObjectOptions = {
|
|
702
|
+
filter: (objRes) => !objRes?.data?.type?.startsWith("0x2::coin::Coin"),
|
|
703
|
+
...options
|
|
704
|
+
};
|
|
705
|
+
return getAllOwnedObjects(this.suiClient, this.address, filterCoinObjectOptions);
|
|
703
706
|
}
|
|
704
707
|
async pendingTransaction() {
|
|
705
708
|
const pendings = await this.backend.getPendingTransactions(this.address);
|
|
@@ -709,18 +712,17 @@ var MSafeAccount = class {
|
|
|
709
712
|
if (pendings.length === 0) {
|
|
710
713
|
return void 0;
|
|
711
714
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
715
|
+
const pendingTx = pendings.find((tx) => !tx.isRejectTx);
|
|
716
|
+
const rejectPending = pendings.find((tx) => tx.isRejectTx);
|
|
717
|
+
return {
|
|
718
|
+
...pendingTx,
|
|
719
|
+
rejectDigest: rejectPending?.digest ?? "",
|
|
720
|
+
rejectPayload: rejectPending?.payload ?? "",
|
|
721
|
+
rejectVotes: rejectPending?.votes ?? []
|
|
722
|
+
};
|
|
720
723
|
}
|
|
721
724
|
async historyTransaction(paginationOption) {
|
|
722
|
-
|
|
723
|
-
return paginatedHistoryTransactions.data;
|
|
725
|
+
return this.backend.getHistoryTransactions(this.address, paginationOption);
|
|
724
726
|
}
|
|
725
727
|
async futureIntentions(paginationOption) {
|
|
726
728
|
const paginatedIntentions = await this.backend.getFutureIntentions(this.address, paginationOption);
|
|
@@ -733,7 +735,11 @@ var MSafeAccount = class {
|
|
|
733
735
|
return this.backend.getNextSequenceNumber(this.address);
|
|
734
736
|
}
|
|
735
737
|
async proposeIntention(intention, sequenceNumber) {
|
|
736
|
-
const message = MessageHelper.proposeIntentionMessage({
|
|
738
|
+
const message = MessageHelper.proposeIntentionMessage({
|
|
739
|
+
intention,
|
|
740
|
+
sn: sequenceNumber,
|
|
741
|
+
msafeAddress: this.address
|
|
742
|
+
});
|
|
737
743
|
const signature = await this.wallet.signPersonalMessage({
|
|
738
744
|
messageStr: message
|
|
739
745
|
});
|
|
@@ -783,7 +789,7 @@ var MSafeAccount = class {
|
|
|
783
789
|
payloadToReject = pending.payload;
|
|
784
790
|
} else {
|
|
785
791
|
const pendingTx = await this.pendingTransaction();
|
|
786
|
-
if (!pendingTx || pendingTx
|
|
792
|
+
if (!pendingTx || pendingTx.rejectDigest !== "") {
|
|
787
793
|
throw new Error("Already rejected");
|
|
788
794
|
}
|
|
789
795
|
payloadToReject = pendingTx.payload;
|
|
@@ -808,6 +814,26 @@ var MSafeAccount = class {
|
|
|
808
814
|
async skipNextFailedIntention() {
|
|
809
815
|
return this.backend.skipNextFailedIntention({ msafeAddress: this.address, userAddress: await this.userAddress() });
|
|
810
816
|
}
|
|
817
|
+
async simulateIntention(intention) {
|
|
818
|
+
const txb = await buildIntentionTransaction(this.suiClient, intention, this.address);
|
|
819
|
+
if (!txb.blockData.gasConfig.price) {
|
|
820
|
+
const refGas = await this.suiClient.getReferenceGasPrice();
|
|
821
|
+
txb.setGasPrice(refGas);
|
|
822
|
+
}
|
|
823
|
+
const payload = await txb.build({ client: this.suiClient });
|
|
824
|
+
const dryRunResult = await this.suiClient.dryRunTransactionBlock({ transactionBlock: payload });
|
|
825
|
+
const success = dryRunResult.effects.status.status === "success";
|
|
826
|
+
const errorMsg = dryRunResult.effects.status.error;
|
|
827
|
+
const gasPrice = BigInt(txb.blockData.gasConfig.price);
|
|
828
|
+
const { gasUsed } = dryRunResult.effects;
|
|
829
|
+
return {
|
|
830
|
+
success,
|
|
831
|
+
errorMsg,
|
|
832
|
+
gasPrice,
|
|
833
|
+
gasUsed,
|
|
834
|
+
dryRunResult
|
|
835
|
+
};
|
|
836
|
+
}
|
|
811
837
|
async executePendingTx(pending) {
|
|
812
838
|
let gotSigs;
|
|
813
839
|
let payload;
|