@dynamic-labs/sui-core 4.32.1 → 4.33.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/CHANGELOG.md +13 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/SuiWalletConnector.cjs +59 -8
- package/src/SuiWalletConnector.d.ts +13 -2
- package/src/SuiWalletConnector.js +59 -8
- package/src/types.d.ts +5 -0
- package/src/wallet/SuiWallet.cjs +22 -34
- package/src/wallet/SuiWallet.d.ts +10 -3
- package/src/wallet/SuiWallet.js +22 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.33.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.32.1...v4.33.0) (2025-09-26)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add support for signAndExecuteTransactionBlock and signTransactionBlock legacy sui features ([#9574](https://github.com/dynamic-labs/dynamic-auth/issues/9574)) ([316481f](https://github.com/dynamic-labs/dynamic-auth/commit/316481f9255ccc8873d267e85932df3b9d58184b))
|
|
8
|
+
* add viem account for waas wallets ([#9518](https://github.com/dynamic-labs/dynamic-auth/issues/9518)) ([39b6314](https://github.com/dynamic-labs/dynamic-auth/commit/39b631489a5fc38bf8077a91f7dd36d517e42512))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* unable to use backup codes to delete totp method on dynamics ui ([#9575](https://github.com/dynamic-labs/dynamic-auth/issues/9575)) ([db55161](https://github.com/dynamic-labs/dynamic-auth/commit/db5516191103ba00f3d993db28ec0df630e066b0))
|
|
14
|
+
|
|
2
15
|
### [4.32.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.32.0...v4.32.1) (2025-09-25)
|
|
3
16
|
|
|
4
17
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sui-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.33.0",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"@mysten/wallet-standard": "0.13.29",
|
|
23
23
|
"@mysten/sui": "1.24.0",
|
|
24
24
|
"text-encoding": "0.7.0",
|
|
25
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
26
|
-
"@dynamic-labs/logger": "4.
|
|
27
|
-
"@dynamic-labs/rpc-providers": "4.
|
|
28
|
-
"@dynamic-labs/types": "4.
|
|
29
|
-
"@dynamic-labs/utils": "4.
|
|
30
|
-
"@dynamic-labs/wallet-book": "4.
|
|
31
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
25
|
+
"@dynamic-labs/assert-package-version": "4.33.0",
|
|
26
|
+
"@dynamic-labs/logger": "4.33.0",
|
|
27
|
+
"@dynamic-labs/rpc-providers": "4.33.0",
|
|
28
|
+
"@dynamic-labs/types": "4.33.0",
|
|
29
|
+
"@dynamic-labs/utils": "4.33.0",
|
|
30
|
+
"@dynamic-labs/wallet-book": "4.33.0",
|
|
31
|
+
"@dynamic-labs/wallet-connector-core": "4.33.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {}
|
|
34
34
|
}
|
|
@@ -282,16 +282,13 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
282
282
|
client: suiClient,
|
|
283
283
|
from,
|
|
284
284
|
onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
throw new utils.DynamicError('No account or transaction found');
|
|
285
|
+
if (!transaction) {
|
|
286
|
+
throw new utils.DynamicError('Transaction must be provided');
|
|
288
287
|
}
|
|
289
|
-
const result = yield
|
|
290
|
-
account: this.account,
|
|
291
|
-
chain: this.account.chains[0],
|
|
288
|
+
const result = yield this.signAndExecuteTransactionFeature({
|
|
292
289
|
transaction,
|
|
293
|
-
})
|
|
294
|
-
return result;
|
|
290
|
+
});
|
|
291
|
+
return result.digest;
|
|
295
292
|
}),
|
|
296
293
|
});
|
|
297
294
|
});
|
|
@@ -326,6 +323,60 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
326
323
|
getEnabledNetworks() {
|
|
327
324
|
return this.suiNetworks;
|
|
328
325
|
}
|
|
326
|
+
signAndExecuteTransactionFeature(_a) {
|
|
327
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ transaction, legacyOptions, }) {
|
|
328
|
+
if (!this.account) {
|
|
329
|
+
throw new utils.DynamicError('No account found');
|
|
330
|
+
}
|
|
331
|
+
const features = this.getFeatures();
|
|
332
|
+
const signAndExecuteTransactionFeature = features === null || features === void 0 ? void 0 : features['sui:signAndExecuteTransaction'];
|
|
333
|
+
if (signAndExecuteTransactionFeature) {
|
|
334
|
+
return signAndExecuteTransactionFeature.signAndExecuteTransaction({
|
|
335
|
+
account: this.account,
|
|
336
|
+
chain: this.account.chains[0],
|
|
337
|
+
transaction,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
const signAndExecuteTransactionBlockFeature = features === null || features === void 0 ? void 0 : features['sui:signAndExecuteTransactionBlock'];
|
|
341
|
+
if (!signAndExecuteTransactionBlockFeature) {
|
|
342
|
+
throw new utils.DynamicError('Wallet does not support sui:signAndExecuteTransaction or sui:signAndExecuteTransactionBlock');
|
|
343
|
+
}
|
|
344
|
+
const result = yield signAndExecuteTransactionBlockFeature.signAndExecuteTransactionBlock({
|
|
345
|
+
account: this.account,
|
|
346
|
+
chain: this.account.chains[0],
|
|
347
|
+
options: legacyOptions === null || legacyOptions === void 0 ? void 0 : legacyOptions.options,
|
|
348
|
+
requestType: legacyOptions === null || legacyOptions === void 0 ? void 0 : legacyOptions.requestType,
|
|
349
|
+
transactionBlock: transaction,
|
|
350
|
+
});
|
|
351
|
+
return result;
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
signTransactionFeature(_a) {
|
|
355
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ transaction, }) {
|
|
356
|
+
if (!this.account) {
|
|
357
|
+
throw new utils.DynamicError('No account found');
|
|
358
|
+
}
|
|
359
|
+
const features = this.getFeatures();
|
|
360
|
+
const signTransactionFeature = features === null || features === void 0 ? void 0 : features['sui:signTransaction'];
|
|
361
|
+
if (signTransactionFeature) {
|
|
362
|
+
return signTransactionFeature === null || signTransactionFeature === void 0 ? void 0 : signTransactionFeature.signTransaction({
|
|
363
|
+
account: this.account,
|
|
364
|
+
chain: this.account.chains[0],
|
|
365
|
+
transaction,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
const signTransactionBlockFeature = features === null || features === void 0 ? void 0 : features['sui:signTransactionBlock'];
|
|
369
|
+
if (!signTransactionBlockFeature) {
|
|
370
|
+
throw new utils.DynamicError('Wallet does not support sui:signTransaction or sui:signTransactionBlock');
|
|
371
|
+
}
|
|
372
|
+
const result = yield signTransactionBlockFeature.signTransactionBlock({
|
|
373
|
+
account: this.account,
|
|
374
|
+
chain: this.account.chains[0],
|
|
375
|
+
transactionBlock: transaction,
|
|
376
|
+
});
|
|
377
|
+
return result;
|
|
378
|
+
});
|
|
379
|
+
}
|
|
329
380
|
}
|
|
330
381
|
|
|
331
382
|
exports.SuiWalletConnector = SuiWalletConnector;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { SuiClient } from '@mysten/sui/client';
|
|
2
|
-
import { SuiWalletFeatures, WalletAccount, WalletWithFeatures } from '@mysten/wallet-standard';
|
|
1
|
+
import { ExecuteTransactionRequestType, SuiClient, SuiTransactionBlockResponseOptions } from '@mysten/sui/client';
|
|
2
|
+
import { SignedTransaction, SuiSignAndExecuteTransactionBlockOutput, SuiSignAndExecuteTransactionOutput, SuiSignTransactionBlockOutput, SuiWalletFeatures, WalletAccount, WalletWithFeatures } from '@mysten/wallet-standard';
|
|
3
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
3
4
|
import { Logger } from '@dynamic-labs/logger';
|
|
4
5
|
import { GenericNetwork, IUITransaction } from '@dynamic-labs/types';
|
|
5
6
|
import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
@@ -76,5 +77,15 @@ export declare abstract class SuiWalletConnector extends WalletConnectorBase<typ
|
|
|
76
77
|
teardownEventListeners(): Promise<void>;
|
|
77
78
|
endSession(): Promise<void>;
|
|
78
79
|
getEnabledNetworks(): GenericNetwork[];
|
|
80
|
+
signAndExecuteTransactionFeature({ transaction, legacyOptions, }: {
|
|
81
|
+
transaction: Transaction;
|
|
82
|
+
legacyOptions?: {
|
|
83
|
+
options?: SuiTransactionBlockResponseOptions;
|
|
84
|
+
requestType?: ExecuteTransactionRequestType;
|
|
85
|
+
};
|
|
86
|
+
}): Promise<SuiSignAndExecuteTransactionOutput | SuiSignAndExecuteTransactionBlockOutput>;
|
|
87
|
+
signTransactionFeature({ transaction, }: {
|
|
88
|
+
transaction: Transaction;
|
|
89
|
+
}): Promise<SignedTransaction | SuiSignTransactionBlockOutput>;
|
|
79
90
|
}
|
|
80
91
|
export type SuiWalletConnectorType = SuiWalletConnector;
|
|
@@ -278,16 +278,13 @@ class SuiWalletConnector extends WalletConnectorBase {
|
|
|
278
278
|
client: suiClient,
|
|
279
279
|
from,
|
|
280
280
|
onSubmit: (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
throw new DynamicError('No account or transaction found');
|
|
281
|
+
if (!transaction) {
|
|
282
|
+
throw new DynamicError('Transaction must be provided');
|
|
284
283
|
}
|
|
285
|
-
const result = yield
|
|
286
|
-
account: this.account,
|
|
287
|
-
chain: this.account.chains[0],
|
|
284
|
+
const result = yield this.signAndExecuteTransactionFeature({
|
|
288
285
|
transaction,
|
|
289
|
-
})
|
|
290
|
-
return result;
|
|
286
|
+
});
|
|
287
|
+
return result.digest;
|
|
291
288
|
}),
|
|
292
289
|
});
|
|
293
290
|
});
|
|
@@ -322,6 +319,60 @@ class SuiWalletConnector extends WalletConnectorBase {
|
|
|
322
319
|
getEnabledNetworks() {
|
|
323
320
|
return this.suiNetworks;
|
|
324
321
|
}
|
|
322
|
+
signAndExecuteTransactionFeature(_a) {
|
|
323
|
+
return __awaiter(this, arguments, void 0, function* ({ transaction, legacyOptions, }) {
|
|
324
|
+
if (!this.account) {
|
|
325
|
+
throw new DynamicError('No account found');
|
|
326
|
+
}
|
|
327
|
+
const features = this.getFeatures();
|
|
328
|
+
const signAndExecuteTransactionFeature = features === null || features === void 0 ? void 0 : features['sui:signAndExecuteTransaction'];
|
|
329
|
+
if (signAndExecuteTransactionFeature) {
|
|
330
|
+
return signAndExecuteTransactionFeature.signAndExecuteTransaction({
|
|
331
|
+
account: this.account,
|
|
332
|
+
chain: this.account.chains[0],
|
|
333
|
+
transaction,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
const signAndExecuteTransactionBlockFeature = features === null || features === void 0 ? void 0 : features['sui:signAndExecuteTransactionBlock'];
|
|
337
|
+
if (!signAndExecuteTransactionBlockFeature) {
|
|
338
|
+
throw new DynamicError('Wallet does not support sui:signAndExecuteTransaction or sui:signAndExecuteTransactionBlock');
|
|
339
|
+
}
|
|
340
|
+
const result = yield signAndExecuteTransactionBlockFeature.signAndExecuteTransactionBlock({
|
|
341
|
+
account: this.account,
|
|
342
|
+
chain: this.account.chains[0],
|
|
343
|
+
options: legacyOptions === null || legacyOptions === void 0 ? void 0 : legacyOptions.options,
|
|
344
|
+
requestType: legacyOptions === null || legacyOptions === void 0 ? void 0 : legacyOptions.requestType,
|
|
345
|
+
transactionBlock: transaction,
|
|
346
|
+
});
|
|
347
|
+
return result;
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
signTransactionFeature(_a) {
|
|
351
|
+
return __awaiter(this, arguments, void 0, function* ({ transaction, }) {
|
|
352
|
+
if (!this.account) {
|
|
353
|
+
throw new DynamicError('No account found');
|
|
354
|
+
}
|
|
355
|
+
const features = this.getFeatures();
|
|
356
|
+
const signTransactionFeature = features === null || features === void 0 ? void 0 : features['sui:signTransaction'];
|
|
357
|
+
if (signTransactionFeature) {
|
|
358
|
+
return signTransactionFeature === null || signTransactionFeature === void 0 ? void 0 : signTransactionFeature.signTransaction({
|
|
359
|
+
account: this.account,
|
|
360
|
+
chain: this.account.chains[0],
|
|
361
|
+
transaction,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
const signTransactionBlockFeature = features === null || features === void 0 ? void 0 : features['sui:signTransactionBlock'];
|
|
365
|
+
if (!signTransactionBlockFeature) {
|
|
366
|
+
throw new DynamicError('Wallet does not support sui:signTransaction or sui:signTransactionBlock');
|
|
367
|
+
}
|
|
368
|
+
const result = yield signTransactionBlockFeature.signTransactionBlock({
|
|
369
|
+
account: this.account,
|
|
370
|
+
chain: this.account.chains[0],
|
|
371
|
+
transactionBlock: transaction,
|
|
372
|
+
});
|
|
373
|
+
return result;
|
|
374
|
+
});
|
|
375
|
+
}
|
|
325
376
|
}
|
|
326
377
|
|
|
327
378
|
export { SuiWalletConnector };
|
package/src/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WalletWithFeatures, SuiWalletFeatures, IdentifierRecord, IdentifierArray, WalletAccount } from '@mysten/wallet-standard';
|
|
2
|
+
import { ExecuteTransactionRequestType, SuiTransactionBlockResponseOptions } from '@mysten/sui/client';
|
|
2
3
|
import { IChainRpcProviders } from '@dynamic-labs/rpc-providers';
|
|
3
4
|
import { NetworkConfiguration } from '@dynamic-labs/sdk-api-core';
|
|
4
5
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
@@ -25,3 +26,7 @@ export type SuiSendBalanceProps = {
|
|
|
25
26
|
decimals?: number;
|
|
26
27
|
};
|
|
27
28
|
};
|
|
29
|
+
export type SuiSignAndExecuteTransactionBlockOptions = {
|
|
30
|
+
options?: SuiTransactionBlockResponseOptions;
|
|
31
|
+
requestType?: ExecuteTransactionRequestType;
|
|
32
|
+
};
|
package/src/wallet/SuiWallet.cjs
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
7
|
var transactions = require('@mysten/sui/transactions');
|
|
8
8
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
|
-
var utils = require('@dynamic-labs/utils');
|
|
10
9
|
var constants = require('../utils/constants/constants.cjs');
|
|
11
10
|
|
|
12
11
|
class SuiWallet extends walletConnectorCore.Wallet {
|
|
@@ -18,32 +17,17 @@ class SuiWallet extends walletConnectorCore.Wallet {
|
|
|
18
17
|
*/
|
|
19
18
|
sendBalance(_a) {
|
|
20
19
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
|
|
21
|
-
var _b;
|
|
22
20
|
yield this._connector.connect();
|
|
23
|
-
const account = yield this._connector.getWalletAccount();
|
|
24
|
-
const chain = account === null || account === void 0 ? void 0 : account.chains[0];
|
|
25
|
-
if (!account) {
|
|
26
|
-
throw new utils.DynamicError('Unable to retrieve Sui wallet account');
|
|
27
|
-
}
|
|
28
|
-
if (!chain) {
|
|
29
|
-
throw new utils.DynamicError('Unable to retrieve Sui active network');
|
|
30
|
-
}
|
|
31
|
-
const transactionFeature = (_b = this._connector.getFeatures()) === null || _b === void 0 ? void 0 : _b['sui:signAndExecuteTransaction'];
|
|
32
|
-
if (!transactionFeature) {
|
|
33
|
-
throw new utils.DynamicError('Wallet does not support sui:signAndExecuteTransaction');
|
|
34
|
-
}
|
|
35
21
|
const transaction = new transactions.Transaction();
|
|
36
22
|
const mistAmount = Number(amount) * constants.MIST_PER_SUI;
|
|
37
23
|
// Let the transaction calculate gas automatically
|
|
38
24
|
// https://sdk.mystenlabs.com/typescript/transaction-building/gas#gas-price
|
|
39
25
|
const [coin] = transaction.splitCoins(transaction.gas, [mistAmount]);
|
|
40
26
|
transaction.transferObjects([coin], toAddress);
|
|
41
|
-
const
|
|
42
|
-
account,
|
|
43
|
-
chain,
|
|
27
|
+
const result = yield this.signAndExecuteTransaction({
|
|
44
28
|
transaction,
|
|
45
29
|
});
|
|
46
|
-
return
|
|
30
|
+
return result.digest;
|
|
47
31
|
});
|
|
48
32
|
}
|
|
49
33
|
/**
|
|
@@ -89,26 +73,30 @@ class SuiWallet extends walletConnectorCore.Wallet {
|
|
|
89
73
|
*/
|
|
90
74
|
signTransaction(transaction) {
|
|
91
75
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
var _a;
|
|
93
76
|
yield this._connector.connect();
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (!transactionFeature) {
|
|
104
|
-
throw new utils.DynamicError('Wallet does not support sui:signTransaction');
|
|
77
|
+
const signedTransaction = yield this._connector.signTransactionFeature({
|
|
78
|
+
transaction,
|
|
79
|
+
});
|
|
80
|
+
// is SignedTransaction
|
|
81
|
+
if ('bytes' in signedTransaction) {
|
|
82
|
+
return {
|
|
83
|
+
bytes: signedTransaction.bytes,
|
|
84
|
+
signature: signedTransaction.signature,
|
|
85
|
+
};
|
|
105
86
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
87
|
+
// is SuiSignTransactionBlockOutput
|
|
88
|
+
return {
|
|
89
|
+
bytes: signedTransaction.transactionBlockBytes,
|
|
90
|
+
signature: signedTransaction.signature,
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
signAndExecuteTransaction(_a) {
|
|
95
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ transaction, legacyOptions, }) {
|
|
96
|
+
return this._connector.signAndExecuteTransactionFeature({
|
|
97
|
+
legacyOptions,
|
|
109
98
|
transaction,
|
|
110
99
|
});
|
|
111
|
-
return signedTransaction;
|
|
112
100
|
});
|
|
113
101
|
}
|
|
114
102
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Transaction } from '@mysten/sui/transactions';
|
|
2
2
|
import { SuiClient } from '@mysten/sui/client';
|
|
3
|
-
import {
|
|
3
|
+
import { SuiSignAndExecuteTransactionBlockOutput, SuiSignAndExecuteTransactionOutput, WalletAccount } from '@mysten/wallet-standard';
|
|
4
4
|
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { SuiWalletConnector } from '../SuiWalletConnector';
|
|
6
|
-
import { SuiSendBalanceProps } from '../types';
|
|
6
|
+
import { SuiSendBalanceProps, SuiSignAndExecuteTransactionBlockOptions } from '../types';
|
|
7
7
|
export declare class SuiWallet extends Wallet<SuiWalletConnector> {
|
|
8
8
|
/**
|
|
9
9
|
* Sends the native balance of the wallet to the given address.
|
|
@@ -36,5 +36,12 @@ export declare class SuiWallet extends Wallet<SuiWalletConnector> {
|
|
|
36
36
|
* @param tx - The [Transaction] to sign.
|
|
37
37
|
* @returns The signature of the signed transaction.
|
|
38
38
|
*/
|
|
39
|
-
signTransaction(transaction: Transaction): Promise<
|
|
39
|
+
signTransaction(transaction: Transaction): Promise<{
|
|
40
|
+
signature: string;
|
|
41
|
+
bytes: string;
|
|
42
|
+
}>;
|
|
43
|
+
signAndExecuteTransaction({ transaction, legacyOptions, }: {
|
|
44
|
+
transaction: Transaction;
|
|
45
|
+
legacyOptions?: SuiSignAndExecuteTransactionBlockOptions;
|
|
46
|
+
}): Promise<SuiSignAndExecuteTransactionOutput | SuiSignAndExecuteTransactionBlockOutput>;
|
|
40
47
|
}
|
package/src/wallet/SuiWallet.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
3
|
import { Transaction } from '@mysten/sui/transactions';
|
|
4
4
|
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
-
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
5
|
import { MIST_PER_SUI } from '../utils/constants/constants.js';
|
|
7
6
|
|
|
8
7
|
class SuiWallet extends Wallet {
|
|
@@ -14,32 +13,17 @@ class SuiWallet extends Wallet {
|
|
|
14
13
|
*/
|
|
15
14
|
sendBalance(_a) {
|
|
16
15
|
return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
|
|
17
|
-
var _b;
|
|
18
16
|
yield this._connector.connect();
|
|
19
|
-
const account = yield this._connector.getWalletAccount();
|
|
20
|
-
const chain = account === null || account === void 0 ? void 0 : account.chains[0];
|
|
21
|
-
if (!account) {
|
|
22
|
-
throw new DynamicError('Unable to retrieve Sui wallet account');
|
|
23
|
-
}
|
|
24
|
-
if (!chain) {
|
|
25
|
-
throw new DynamicError('Unable to retrieve Sui active network');
|
|
26
|
-
}
|
|
27
|
-
const transactionFeature = (_b = this._connector.getFeatures()) === null || _b === void 0 ? void 0 : _b['sui:signAndExecuteTransaction'];
|
|
28
|
-
if (!transactionFeature) {
|
|
29
|
-
throw new DynamicError('Wallet does not support sui:signAndExecuteTransaction');
|
|
30
|
-
}
|
|
31
17
|
const transaction = new Transaction();
|
|
32
18
|
const mistAmount = Number(amount) * MIST_PER_SUI;
|
|
33
19
|
// Let the transaction calculate gas automatically
|
|
34
20
|
// https://sdk.mystenlabs.com/typescript/transaction-building/gas#gas-price
|
|
35
21
|
const [coin] = transaction.splitCoins(transaction.gas, [mistAmount]);
|
|
36
22
|
transaction.transferObjects([coin], toAddress);
|
|
37
|
-
const
|
|
38
|
-
account,
|
|
39
|
-
chain,
|
|
23
|
+
const result = yield this.signAndExecuteTransaction({
|
|
40
24
|
transaction,
|
|
41
25
|
});
|
|
42
|
-
return
|
|
26
|
+
return result.digest;
|
|
43
27
|
});
|
|
44
28
|
}
|
|
45
29
|
/**
|
|
@@ -85,26 +69,30 @@ class SuiWallet extends Wallet {
|
|
|
85
69
|
*/
|
|
86
70
|
signTransaction(transaction) {
|
|
87
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
var _a;
|
|
89
72
|
yield this._connector.connect();
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (!transactionFeature) {
|
|
100
|
-
throw new DynamicError('Wallet does not support sui:signTransaction');
|
|
73
|
+
const signedTransaction = yield this._connector.signTransactionFeature({
|
|
74
|
+
transaction,
|
|
75
|
+
});
|
|
76
|
+
// is SignedTransaction
|
|
77
|
+
if ('bytes' in signedTransaction) {
|
|
78
|
+
return {
|
|
79
|
+
bytes: signedTransaction.bytes,
|
|
80
|
+
signature: signedTransaction.signature,
|
|
81
|
+
};
|
|
101
82
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
83
|
+
// is SuiSignTransactionBlockOutput
|
|
84
|
+
return {
|
|
85
|
+
bytes: signedTransaction.transactionBlockBytes,
|
|
86
|
+
signature: signedTransaction.signature,
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
signAndExecuteTransaction(_a) {
|
|
91
|
+
return __awaiter(this, arguments, void 0, function* ({ transaction, legacyOptions, }) {
|
|
92
|
+
return this._connector.signAndExecuteTransactionFeature({
|
|
93
|
+
legacyOptions,
|
|
105
94
|
transaction,
|
|
106
95
|
});
|
|
107
|
-
return signedTransaction;
|
|
108
96
|
});
|
|
109
97
|
}
|
|
110
98
|
}
|