@dynamic-labs/sui 4.19.6 → 4.20.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +1 -1
  3. package/package.cjs +1 -1
  4. package/package.js +1 -1
  5. package/package.json +4 -11
  6. package/src/SuiWalletConnectors.cjs +15 -0
  7. package/src/SuiWalletConnectors.d.ts +1 -0
  8. package/src/SuiWalletConnectors.js +11 -0
  9. package/src/index.cjs +2 -17
  10. package/src/index.d.ts +1 -7
  11. package/src/index.js +1 -13
  12. package/_virtual/_tslib.cjs +0 -36
  13. package/_virtual/_tslib.js +0 -32
  14. package/src/SuiWalletConnector.cjs +0 -306
  15. package/src/SuiWalletConnector.d.ts +0 -75
  16. package/src/SuiWalletConnector.js +0 -302
  17. package/src/types.d.ts +0 -27
  18. package/src/utils/SuiUiTransaction/SuiUiTransaction.cjs +0 -125
  19. package/src/utils/SuiUiTransaction/SuiUiTransaction.d.ts +0 -47
  20. package/src/utils/SuiUiTransaction/SuiUiTransaction.js +0 -121
  21. package/src/utils/SuiUiTransaction/index.d.ts +0 -1
  22. package/src/utils/constants/constants.cjs +0 -8
  23. package/src/utils/constants/constants.d.ts +0 -1
  24. package/src/utils/constants/constants.js +0 -4
  25. package/src/utils/constants/index.d.ts +0 -1
  26. package/src/utils/network/index.d.ts +0 -1
  27. package/src/utils/network/networkHelpers.cjs +0 -34
  28. package/src/utils/network/networkHelpers.d.ts +0 -19
  29. package/src/utils/network/networkHelpers.js +0 -29
  30. package/src/wallet/SuiWallet.cjs +0 -116
  31. package/src/wallet/SuiWallet.d.ts +0 -40
  32. package/src/wallet/SuiWallet.js +0 -112
  33. package/src/wallet/index.d.ts +0 -1
  34. package/src/wallet/isSuiWallet/index.d.ts +0 -1
  35. package/src/wallet/isSuiWallet/isSuiWallet.cjs +0 -8
  36. package/src/wallet/isSuiWallet/isSuiWallet.d.ts +0 -3
  37. package/src/wallet/isSuiWallet/isSuiWallet.js +0 -4
  38. package/src/wallets/injected/fetchSuiInjectedWalletConnectors.cjs +0 -64
  39. package/src/wallets/injected/fetchSuiInjectedWalletConnectors.d.ts +0 -5
  40. package/src/wallets/injected/fetchSuiInjectedWalletConnectors.js +0 -60
  41. package/src/wallets/injected/index.d.ts +0 -1
  42. package/src/wallets/injected/injected.cjs +0 -19
  43. package/src/wallets/injected/injected.d.ts +0 -13
  44. package/src/wallets/injected/injected.js +0 -15
package/CHANGELOG.md CHANGED
@@ -1,4 +1,30 @@
1
1
 
2
+ ## [4.20.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.19.7...v4.20.0) (2025-06-09)
3
+
4
+
5
+ ### Features
6
+
7
+ * encapsulate waas connectors within main connectors ([#8878](https://github.com/dynamic-labs/dynamic-auth/issues/8878)) ([fd1b6ab](https://github.com/dynamic-labs/dynamic-auth/commit/fd1b6ab037ff7ce5c66b30d9611689e8cc03b97b))
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * hide duplicate social connection logo on global wallets ([#8903](https://github.com/dynamic-labs/dynamic-auth/issues/8903)) ([c2f86e7](https://github.com/dynamic-labs/dynamic-auth/commit/c2f86e7aae91764b174abaa18439ffbdf7287475))
13
+
14
+ ### [4.19.7](https://github.com/dynamic-labs/dynamic-auth/compare/v4.19.6...v4.19.7) (2025-06-06)
15
+
16
+
17
+ ### Features
18
+
19
+ * add util to find waas wallets ([#8871](https://github.com/dynamic-labs/dynamic-auth/issues/8871)) ([2d7114e](https://github.com/dynamic-labs/dynamic-auth/commit/2d7114e51f5badf1d04600597f1fd9433fabf3d0))
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * make sure smart account is deployed before creating sessions ([#8894](https://github.com/dynamic-labs/dynamic-auth/issues/8894)) ([5ba3d23](https://github.com/dynamic-labs/dynamic-auth/commit/5ba3d23bb8ef7c7438809128c8ef74c390ba1d48))
25
+ * only deploy zksync smart account if not deployed ([#8840](https://github.com/dynamic-labs/dynamic-auth/issues/8840)) ([66a306a](https://github.com/dynamic-labs/dynamic-auth/commit/66a306aaee25c58f685fa050a5d6aea79b196fce))
26
+ * primary wallet loading time when using React 19 ([#8896](https://github.com/dynamic-labs/dynamic-auth/issues/8896)) ([f5690f3](https://github.com/dynamic-labs/dynamic-auth/commit/f5690f31012e8fc6a5650423d4ece6c04f7c1811))
27
+
2
28
  ### [4.19.6](https://github.com/dynamic-labs/dynamic-auth/compare/v4.19.5...v4.19.6) (2025-06-04)
3
29
 
4
30
 
package/README.md CHANGED
@@ -1 +1 @@
1
- # SUI Package
1
+ # Sui Package
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.19.6";
6
+ var version = "4.20.0";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.19.6";
2
+ var version = "4.20.0";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sui",
3
- "version": "4.19.6",
3
+ "version": "4.20.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",
@@ -18,17 +18,10 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
- "@dynamic-labs/sdk-api-core": "0.0.681",
22
- "@mysten/wallet-standard": "0.13.29",
23
- "@mysten/sui": "1.24.0",
24
21
  "text-encoding": "0.7.0",
25
- "@dynamic-labs/assert-package-version": "4.19.6",
26
- "@dynamic-labs/logger": "4.19.6",
27
- "@dynamic-labs/rpc-providers": "4.19.6",
28
- "@dynamic-labs/types": "4.19.6",
29
- "@dynamic-labs/utils": "4.19.6",
30
- "@dynamic-labs/wallet-book": "4.19.6",
31
- "@dynamic-labs/wallet-connector-core": "4.19.6"
22
+ "@dynamic-labs/assert-package-version": "4.20.0",
23
+ "@dynamic-labs/sui-core": "4.20.0",
24
+ "@dynamic-labs/waas-sui": "4.20.0"
32
25
  },
33
26
  "peerDependencies": {}
34
27
  }
@@ -0,0 +1,15 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var suiCore = require('@dynamic-labs/sui-core');
7
+ var waasSui = require('@dynamic-labs/waas-sui');
8
+
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ const SuiWalletConnectors = (props) => [
11
+ ...suiCore.fetchSuiInjectedWalletConnectors(props),
12
+ ...waasSui.DynamicWaasSuiConnectors(),
13
+ ];
14
+
15
+ exports.SuiWalletConnectors = SuiWalletConnectors;
@@ -0,0 +1 @@
1
+ export declare const SuiWalletConnectors: (props: any) => (import("@dynamic-labs/wallet-connector-core").WalletConnectorConstructor | typeof import("@dynamic-labs/waas-sui").DynamicWaasSuiConnector)[];
@@ -0,0 +1,11 @@
1
+ 'use client'
2
+ import { fetchSuiInjectedWalletConnectors } from '@dynamic-labs/sui-core';
3
+ import { DynamicWaasSuiConnectors } from '@dynamic-labs/waas-sui';
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ const SuiWalletConnectors = (props) => [
7
+ ...fetchSuiInjectedWalletConnectors(props),
8
+ ...DynamicWaasSuiConnectors(),
9
+ ];
10
+
11
+ export { SuiWalletConnectors };
package/src/index.cjs CHANGED
@@ -5,23 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var assertPackageVersion = require('@dynamic-labs/assert-package-version');
7
7
  var _package = require('../package.cjs');
8
- var fetchSuiInjectedWalletConnectors = require('./wallets/injected/fetchSuiInjectedWalletConnectors.cjs');
9
- var constants = require('./utils/constants/constants.cjs');
10
- var SuiWalletConnector = require('./SuiWalletConnector.cjs');
11
- var SuiWallet = require('./wallet/SuiWallet.cjs');
12
- var isSuiWallet = require('./wallet/isSuiWallet/isSuiWallet.cjs');
13
- var SuiUiTransaction = require('./utils/SuiUiTransaction/SuiUiTransaction.cjs');
8
+ var SuiWalletConnectors = require('./SuiWalletConnectors.cjs');
14
9
 
15
- /* eslint-disable @typescript-eslint/no-unused-vars */
16
10
  assertPackageVersion.assertPackageVersion('@dynamic-labs/sui', _package.version);
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- const SuiWalletConnectors = (props) => [
19
- ...fetchSuiInjectedWalletConnectors.fetchSuiInjectedWalletConnectors(props),
20
- ];
21
11
 
22
- exports.MIST_PER_SUI = constants.MIST_PER_SUI;
23
- exports.SuiWalletConnector = SuiWalletConnector.SuiWalletConnector;
24
- exports.SuiWallet = SuiWallet.SuiWallet;
25
- exports.isSuiWallet = isSuiWallet.isSuiWallet;
26
- exports.SuiUiTransaction = SuiUiTransaction.SuiUiTransaction;
27
- exports.SuiWalletConnectors = SuiWalletConnectors;
12
+ exports.SuiWalletConnectors = SuiWalletConnectors.SuiWalletConnectors;
package/src/index.d.ts CHANGED
@@ -1,7 +1 @@
1
- export * from './utils/constants';
2
- export declare const SuiWalletConnectors: (props: any) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
3
- export { SuiWalletConnector } from './SuiWalletConnector';
4
- export { SuiWallet } from './wallet/SuiWallet';
5
- export { isSuiWallet } from './wallet/isSuiWallet';
6
- export type { SuiWalletConnectorProps, SuiSendBalanceProps } from './types';
7
- export { SuiUiTransaction } from './utils/SuiUiTransaction/SuiUiTransaction';
1
+ export * from './SuiWalletConnectors';
package/src/index.js CHANGED
@@ -1,18 +1,6 @@
1
1
  'use client'
2
2
  import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
3
3
  import { version } from '../package.js';
4
- import { fetchSuiInjectedWalletConnectors } from './wallets/injected/fetchSuiInjectedWalletConnectors.js';
5
- export { MIST_PER_SUI } from './utils/constants/constants.js';
6
- export { SuiWalletConnector } from './SuiWalletConnector.js';
7
- export { SuiWallet } from './wallet/SuiWallet.js';
8
- export { isSuiWallet } from './wallet/isSuiWallet/isSuiWallet.js';
9
- export { SuiUiTransaction } from './utils/SuiUiTransaction/SuiUiTransaction.js';
4
+ export { SuiWalletConnectors } from './SuiWalletConnectors.js';
10
5
 
11
- /* eslint-disable @typescript-eslint/no-unused-vars */
12
6
  assertPackageVersion('@dynamic-labs/sui', version);
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- const SuiWalletConnectors = (props) => [
15
- ...fetchSuiInjectedWalletConnectors(props),
16
- ];
17
-
18
- export { SuiWalletConnectors };
@@ -1,36 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- /******************************************************************************
7
- Copyright (c) Microsoft Corporation.
8
-
9
- Permission to use, copy, modify, and/or distribute this software for any
10
- purpose with or without fee is hereby granted.
11
-
12
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
- PERFORMANCE OF THIS SOFTWARE.
19
- ***************************************************************************** */
20
-
21
- function __awaiter(thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- }
30
-
31
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
32
- var e = new Error(message);
33
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
34
- };
35
-
36
- exports.__awaiter = __awaiter;
@@ -1,32 +0,0 @@
1
- 'use client'
2
- /******************************************************************************
3
- Copyright (c) Microsoft Corporation.
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted.
7
-
8
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
- PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */
16
-
17
- function __awaiter(thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- }
26
-
27
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
28
- var e = new Error(message);
29
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
30
- };
31
-
32
- export { __awaiter };
@@ -1,306 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var _tslib = require('../_virtual/_tslib.cjs');
7
- var client = require('@mysten/sui/client');
8
- var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
- var utils = require('@dynamic-labs/utils');
10
- var logger = require('@dynamic-labs/logger');
11
- var SuiWallet = require('./wallet/SuiWallet.cjs');
12
- var networkHelpers = require('./utils/network/networkHelpers.cjs');
13
- var SuiUiTransaction = require('./utils/SuiUiTransaction/SuiUiTransaction.cjs');
14
-
15
- class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
16
- constructor(name, opts) {
17
- super(opts);
18
- this.name = 'Sui';
19
- this.ChainWallet = SuiWallet.SuiWallet;
20
- this.connectedChain = 'SUI';
21
- this.supportedChains = ['SUI'];
22
- this.switchNetworkOnlyFromWallet = true;
23
- /** required for metamask snap integration as MM snaps don't have event listeners */
24
- this.canSetEventListeners = true;
25
- /** Sui clients */
26
- this.suiClients = {};
27
- /** Whether the connector is currently attempting to connect */
28
- this.isConnecting = false;
29
- this.name = name;
30
- this.wallet = opts.wallet;
31
- this.chainRpcProviders = opts.chainRpcProviders;
32
- this.suiNetworks = opts.suiNetworks;
33
- this.logger = new logger.Logger(this.name);
34
- }
35
- /** Helper to return the wallet features */
36
- getFeatures() {
37
- var _a;
38
- return (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features;
39
- }
40
- /** Connect to the wallet using the standard:connect feature */
41
- connect() {
42
- return _tslib.__awaiter(this, arguments, void 0, function* ({ silent } = {}) {
43
- var _a, _b;
44
- if (this.account || this.isConnecting) {
45
- // Account is already connected or we're already connecting
46
- return;
47
- }
48
- const connectFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:connect'];
49
- if (!connectFeature) {
50
- if (silent) {
51
- return;
52
- }
53
- throw new utils.DynamicError('Wallet does not support standard:connect');
54
- }
55
- // Start connecting
56
- this.isConnecting = true;
57
- this.logger.debug('[connect] Creating new connection');
58
- try {
59
- const response = yield connectFeature.connect(silent ? { silent } : undefined);
60
- this.logger.debug(`[connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
61
- this.account = response === null || response === void 0 ? void 0 : response.accounts[0];
62
- const primaryChain = (_b = this.account) === null || _b === void 0 ? void 0 : _b.chains[0];
63
- if (primaryChain) {
64
- this.activeNetworkId = networkHelpers.getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
65
- }
66
- }
67
- catch (error) {
68
- this.logger.error(error);
69
- if (silent) {
70
- return;
71
- }
72
- throw new utils.DynamicError('Connection failed');
73
- }
74
- finally {
75
- this.isConnecting = false;
76
- }
77
- this.setupEventListeners();
78
- });
79
- }
80
- /** Get the wallet address by connecting to the current account */
81
- getAddress() {
82
- return _tslib.__awaiter(this, void 0, void 0, function* () {
83
- this.logger.debug('[getAddress] called, attempting to obtain the account address');
84
- yield this.connect();
85
- if (!this.account) {
86
- throw new utils.DynamicError('No account found');
87
- }
88
- return this.account.address;
89
- });
90
- }
91
- /** Returns the network id of the account's active chain */
92
- getNetwork() {
93
- return _tslib.__awaiter(this, void 0, void 0, function* () {
94
- if (!this.account) {
95
- yield this.connect();
96
- }
97
- return this.activeNetworkId;
98
- });
99
- }
100
- getConnectedAccounts() {
101
- return _tslib.__awaiter(this, void 0, void 0, function* () {
102
- var _a;
103
- if (!this.account) {
104
- yield this.connect({ silent: true });
105
- }
106
- const address = (_a = this.account) === null || _a === void 0 ? void 0 : _a.address;
107
- if (address) {
108
- return [address];
109
- }
110
- return [];
111
- });
112
- }
113
- /**
114
- * Helper to get the chain id from a [SuiChangeEvent].
115
- *
116
- * Some wallets set the event.chains objects but others use event.accounts.chains,
117
- * so we need to deal with both cases.
118
- *
119
- * @param event - The [SuiChangeEvent] to get the chain id from
120
- * @returns The dynamic chain id or '-1' if the chain id is not found
121
- */
122
- getChainFromEvent(event) {
123
- var _a, _b, _c, _d, _e;
124
- let suiChain = (_a = event.chains) === null || _a === void 0 ? void 0 : _a[0];
125
- if (!suiChain) {
126
- suiChain = (_d = (_c = (_b = event.accounts) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.chains) === null || _d === void 0 ? void 0 : _d[0];
127
- }
128
- if (!suiChain) {
129
- return '-1';
130
- }
131
- return (_e = networkHelpers.getSuiNetworkIdFromName(suiChain, this.suiNetworks)) !== null && _e !== void 0 ? _e : '-1';
132
- }
133
- setupEventListeners() {
134
- var _a;
135
- if (!this.canSetEventListeners || this.eventsHandler)
136
- return;
137
- const eventsFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:events'];
138
- if (!eventsFeature) {
139
- this.logger.debug('[setupEventListeners] Wallet not connected or does not support standard:events');
140
- return;
141
- }
142
- this.eventsHandler = (event) => _tslib.__awaiter(this, void 0, void 0, function* () {
143
- var _b;
144
- if (event.accounts) {
145
- // If the event sets accounts but it's empty, we need to disconnect.
146
- if (event.accounts.length === 0 && this.account) {
147
- this.account = undefined;
148
- this.emit('disconnect');
149
- return;
150
- }
151
- const [primaryAccount] = event.accounts;
152
- if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
153
- this.account = primaryAccount;
154
- this.emit('accountChange', { accounts: [primaryAccount.address] });
155
- }
156
- }
157
- // Some events will leave out accounts but set the chains object, so we process those
158
- // with the helper.
159
- const suiChainId = this.getChainFromEvent(event);
160
- if (suiChainId !== this.activeNetworkId) {
161
- this.activeNetworkId = suiChainId;
162
- this.emit('chainChange', { chain: suiChainId });
163
- }
164
- });
165
- this.logger.debug('[setupEventListeners] Setting up sui wallet connector event listeners');
166
- this.eventsUnsubscribeHandler = eventsFeature.on('change', this.eventsHandler);
167
- }
168
- /**
169
- * Helper to get the Sui client for the current network
170
- *
171
- * The client will prefer the private customer rpc url if available.
172
- */
173
- getSuiClient(networkId) {
174
- return _tslib.__awaiter(this, void 0, void 0, function* () {
175
- const clientNetworkId = networkId !== null && networkId !== void 0 ? networkId : (yield this.getNetwork());
176
- if (!clientNetworkId) {
177
- this.logger.error('[getSuiClient] Failed to get network id');
178
- return undefined;
179
- }
180
- // Default to an existing client if available
181
- if (this.suiClients[clientNetworkId]) {
182
- return this.suiClients[clientNetworkId];
183
- }
184
- const network = this.getEnabledNetworks().find((network) => network.networkId === clientNetworkId);
185
- const url = network ? networkHelpers.getPreferredRpcUrl(network) : undefined;
186
- if (!url) {
187
- this.logger.error('[getSuiClient] Failed to get network url');
188
- return undefined;
189
- }
190
- this.suiClients[clientNetworkId] = new client.SuiClient({
191
- url: url,
192
- });
193
- return this.suiClients[clientNetworkId];
194
- });
195
- }
196
- getBalance(address) {
197
- return _tslib.__awaiter(this, void 0, void 0, function* () {
198
- const client = yield this.getSuiClient();
199
- if (!client) {
200
- this.logger.error('[getBalance] Failed to get Sui client');
201
- return undefined;
202
- }
203
- const balanceResult = yield client.getBalance({
204
- owner: address,
205
- });
206
- // Balance comes back as MIST, 1 SUI = 1e9 MIST
207
- const balance = Number(balanceResult === null || balanceResult === void 0 ? void 0 : balanceResult.totalBalance) / 1e9;
208
- if (Number.isNaN(balance)) {
209
- this.logger.error(`[getBalance] Failed to get balance for address: ${address}`);
210
- return undefined;
211
- }
212
- return balance.toFixed(6);
213
- });
214
- }
215
- signMessage(messageToSign) {
216
- return _tslib.__awaiter(this, void 0, void 0, function* () {
217
- var _a;
218
- this.logger.debug('[signMessage] called, attempting to sign a message');
219
- const signFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage'];
220
- if (!signFeature) {
221
- throw new utils.DynamicError('Wallet does not support sui:signPersonalMessage');
222
- }
223
- yield this.connect();
224
- if (!this.account) {
225
- throw new utils.DynamicError('[signMessage] No account found');
226
- }
227
- let output;
228
- try {
229
- output = yield signFeature.signPersonalMessage({
230
- account: this.account,
231
- message: new TextEncoder().encode(messageToSign),
232
- });
233
- }
234
- catch (error) {
235
- this.logger.error(error);
236
- throw new utils.DynamicError('An error occured during signing');
237
- }
238
- if (!output || !output.signature) {
239
- throw new utils.DynamicError('[signMessage] Failed to sign message');
240
- }
241
- this.logger.debug(`[signMessage] Signed message: ${output.signature}`);
242
- return output.signature;
243
- });
244
- }
245
- getWalletAccount() {
246
- return _tslib.__awaiter(this, void 0, void 0, function* () {
247
- return this.account;
248
- });
249
- }
250
- /** Function used to create transactions in the SDK interface */
251
- createUiTransaction(from) {
252
- return _tslib.__awaiter(this, void 0, void 0, function* () {
253
- yield this.validateActiveWallet(from);
254
- const suiClient = yield this.getSuiClient();
255
- if (!suiClient) {
256
- throw new utils.DynamicError('No Sui client available');
257
- }
258
- return new SuiUiTransaction.SuiUiTransaction({
259
- client: suiClient,
260
- from,
261
- onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
262
- var _a, _b;
263
- if (!this.account || !transaction) {
264
- throw new utils.DynamicError('No account or transaction found');
265
- }
266
- const result = yield ((_b = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['sui:signAndExecuteTransaction']) === null || _b === void 0 ? void 0 : _b.signAndExecuteTransaction({
267
- account: this.account,
268
- chain: this.account.chains[0],
269
- transaction,
270
- }));
271
- return result;
272
- }),
273
- });
274
- });
275
- }
276
- teardownEventListeners() {
277
- return _tslib.__awaiter(this, void 0, void 0, function* () {
278
- if (this.eventsUnsubscribeHandler) {
279
- this.eventsUnsubscribeHandler();
280
- this.eventsUnsubscribeHandler = undefined;
281
- }
282
- });
283
- }
284
- endSession() {
285
- return _tslib.__awaiter(this, void 0, void 0, function* () {
286
- var _a;
287
- this.teardownEventListeners();
288
- this.account = undefined;
289
- const disconnectFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:disconnect'];
290
- if (disconnectFeature) {
291
- yield disconnectFeature.disconnect();
292
- return;
293
- }
294
- if (this.wallet.disconnect) {
295
- yield this.wallet.disconnect();
296
- return;
297
- }
298
- throw new utils.DynamicError('Wallet does not support disconnect');
299
- });
300
- }
301
- getEnabledNetworks() {
302
- return this.suiNetworks;
303
- }
304
- }
305
-
306
- exports.SuiWalletConnector = SuiWalletConnector;
@@ -1,75 +0,0 @@
1
- import { SuiWalletFeatures, WalletAccount, WalletWithFeatures } from '@mysten/wallet-standard';
2
- import { SuiClient } from '@mysten/sui/client';
3
- import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
4
- import { Logger } from '@dynamic-labs/logger';
5
- import { GenericNetwork, IUITransaction } from '@dynamic-labs/types';
6
- import { SuiWallet } from './wallet/SuiWallet';
7
- import { SuiWalletConnectorProps, SuiWalletStandardEventHandler } from './types';
8
- export declare abstract class SuiWalletConnector extends WalletConnectorBase<typeof SuiWallet> {
9
- name: string;
10
- ChainWallet: typeof SuiWallet;
11
- connectedChain: Chain;
12
- supportedChains: Chain[];
13
- switchNetworkOnlyFromWallet: boolean;
14
- /** required for metamask snap integration as MM snaps don't have event listeners */
15
- canSetEventListeners: boolean;
16
- eventsHandler: SuiWalletStandardEventHandler | undefined;
17
- /** Sui wallet instance */
18
- wallet: WalletWithFeatures<SuiWalletFeatures> | undefined;
19
- eventsUnsubscribeHandler: (() => void) | undefined;
20
- /** Tracks the active wallet account */
21
- protected account: WalletAccount | undefined;
22
- /**
23
- * Tracks the active network id
24
- *
25
- * This is needed because the account's network order doesn't update after a
26
- * network change event.
27
- */
28
- protected activeNetworkId: string | undefined;
29
- /** Sui clients */
30
- suiClients: Record<string, SuiClient>;
31
- /** Enabled SUI networks */
32
- suiNetworks: GenericNetwork[];
33
- /** Dynamic logger */
34
- logger: Logger;
35
- /** Whether the connector is currently attempting to connect */
36
- protected isConnecting: boolean;
37
- constructor(name: string, opts: SuiWalletConnectorProps);
38
- /** Helper to return the wallet features */
39
- getFeatures(): SuiWalletFeatures | undefined;
40
- /** Connect to the wallet using the standard:connect feature */
41
- connect({ silent }?: {
42
- silent?: boolean;
43
- }): Promise<void>;
44
- /** Get the wallet address by connecting to the current account */
45
- getAddress(): Promise<string | undefined>;
46
- /** Returns the network id of the account's active chain */
47
- getNetwork(): Promise<string | undefined>;
48
- getConnectedAccounts(): Promise<string[]>;
49
- /**
50
- * Helper to get the chain id from a [SuiChangeEvent].
51
- *
52
- * Some wallets set the event.chains objects but others use event.accounts.chains,
53
- * so we need to deal with both cases.
54
- *
55
- * @param event - The [SuiChangeEvent] to get the chain id from
56
- * @returns The dynamic chain id or '-1' if the chain id is not found
57
- */
58
- private getChainFromEvent;
59
- setupEventListeners(): void;
60
- /**
61
- * Helper to get the Sui client for the current network
62
- *
63
- * The client will prefer the private customer rpc url if available.
64
- */
65
- getSuiClient(networkId?: string): Promise<SuiClient | undefined>;
66
- getBalance(address: string): Promise<string | undefined>;
67
- signMessage(messageToSign: string): Promise<string | undefined>;
68
- getWalletAccount(): Promise<WalletAccount | undefined>;
69
- /** Function used to create transactions in the SDK interface */
70
- createUiTransaction(from: string): Promise<IUITransaction>;
71
- teardownEventListeners(): Promise<void>;
72
- endSession(): Promise<void>;
73
- getEnabledNetworks(): GenericNetwork[];
74
- }
75
- export type SuiWalletConnectorType = SuiWalletConnector;