@dynamic-labs/sui 4.9.13-preview.1 → 4.10.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 CHANGED
@@ -1,26 +1,18 @@
1
1
 
2
- ### [4.9.13-preview.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.12...v4.9.13-preview.1) (2025-03-29)
2
+ ## [4.10.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.12...v4.10.0) (2025-03-30)
3
3
 
4
4
 
5
5
  ### Features
6
-
7
- * add zk sync aa connector ([7ef9031](https://github.com/dynamic-labs/dynamic-auth/commit/7ef9031ce709b1ebc2d908da7d120e83733be7cf))
6
+ * Sui Support for branded wallets
7
+ * better handling of non-multiasset balance fetching ([#8419](https://github.com/dynamic-labs/dynamic-auth/issues/8419)) ([574d4ea](https://github.com/dynamic-labs/dynamic-auth/commit/574d4eabf85e6f85325dc374b6cd84aa9fdd7ed4))
8
8
 
9
9
 
10
10
  ### Bug Fixes
11
11
 
12
- * Adjust parallel tasks to default 16 ([#8413](https://github.com/dynamic-labs/dynamic-auth/issues/8413)) ([b62d34c](https://github.com/dynamic-labs/dynamic-auth/commit/b62d34cb780859d3d8414421539116520d0ebcbd))
13
12
  * do not prompt passkey with 7702 on v2 wallets ([#8391](https://github.com/dynamic-labs/dynamic-auth/issues/8391)) ([bb91396](https://github.com/dynamic-labs/dynamic-auth/commit/bb913965121e97801922f5ca828d11e4a551a3b6))
14
13
  * ensure the global wallet app url is used ([#8404](https://github.com/dynamic-labs/dynamic-auth/issues/8404)) ([23a7d91](https://github.com/dynamic-labs/dynamic-auth/commit/23a7d91b50cc85e67de52306f91163c675e0f007))
15
14
  * **global-wallet-client:** use global wallet env id when storing data to ls ([#8405](https://github.com/dynamic-labs/dynamic-auth/issues/8405)) ([2b3d9ce](https://github.com/dynamic-labs/dynamic-auth/commit/2b3d9ce8dd82dda487759e0621c73bfad2842aef))
16
15
 
17
- ### [4.9.13-preview.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.12...v4.9.13-preview.0) (2025-03-28)
18
-
19
-
20
- ### Features
21
-
22
- * add zk sync aa connector ([0859f98](https://github.com/dynamic-labs/dynamic-auth/commit/0859f9810442c9229a1465f59f2400272c83ba09))
23
-
24
16
  ### [4.9.12](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.11...v4.9.12) (2025-03-28)
25
17
 
26
18
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.9.13-preview.1";
6
+ var version = "4.10.0";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.9.13-preview.1";
2
+ var version = "4.10.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.9.13-preview.1",
3
+ "version": "4.10.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,17 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
+ "@dynamic-labs/sdk-api-core": "0.0.650",
21
22
  "@mysten/wallet-standard": "0.13.29",
22
23
  "@mysten/sui": "1.24.0",
23
- "@dynamic-labs/sdk-api-core": "0.0.645",
24
24
  "text-encoding": "0.7.0",
25
- "@dynamic-labs/assert-package-version": "4.9.13-preview.1",
26
- "@dynamic-labs/logger": "4.9.13-preview.1",
27
- "@dynamic-labs/rpc-providers": "4.9.13-preview.1",
28
- "@dynamic-labs/types": "4.9.13-preview.1",
29
- "@dynamic-labs/utils": "4.9.13-preview.1",
30
- "@dynamic-labs/wallet-book": "4.9.13-preview.1",
31
- "@dynamic-labs/wallet-connector-core": "4.9.13-preview.1"
25
+ "@dynamic-labs/assert-package-version": "4.10.0",
26
+ "@dynamic-labs/logger": "4.10.0",
27
+ "@dynamic-labs/rpc-providers": "4.10.0",
28
+ "@dynamic-labs/types": "4.10.0",
29
+ "@dynamic-labs/utils": "4.10.0",
30
+ "@dynamic-labs/wallet-book": "4.10.0",
31
+ "@dynamic-labs/wallet-connector-core": "4.10.0"
32
32
  },
33
33
  "peerDependencies": {}
34
34
  }
@@ -36,7 +36,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
36
36
  }
37
37
  /** Connect to the wallet using the standard:connect feature */
38
38
  connect() {
39
- return _tslib.__awaiter(this, void 0, void 0, function* () {
39
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ silent } = {}) {
40
40
  var _a, _b;
41
41
  if (this.account) {
42
42
  // Account is already connected
@@ -44,11 +44,14 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
44
44
  }
45
45
  const connectFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:connect'];
46
46
  if (!connectFeature) {
47
+ if (silent) {
48
+ return;
49
+ }
47
50
  throw new utils.DynamicError('Wallet does not support standard:connect');
48
51
  }
49
52
  this.logger.debug('[connect] Creating new connection');
50
53
  try {
51
- const response = yield connectFeature.connect();
54
+ const response = yield connectFeature.connect(silent ? { silent } : undefined);
52
55
  this.logger.debug(`[connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
53
56
  this.account = response === null || response === void 0 ? void 0 : response.accounts[0];
54
57
  const primaryChain = (_b = this.account) === null || _b === void 0 ? void 0 : _b.chains[0];
@@ -58,6 +61,9 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
58
61
  }
59
62
  catch (error) {
60
63
  this.logger.error(error);
64
+ if (silent) {
65
+ return;
66
+ }
61
67
  throw new utils.DynamicError('Connection failed');
62
68
  }
63
69
  this.setupEventListeners();
@@ -86,9 +92,36 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
86
92
  getConnectedAccounts() {
87
93
  return _tslib.__awaiter(this, void 0, void 0, function* () {
88
94
  var _a;
89
- return ((_a = this.account) === null || _a === void 0 ? void 0 : _a.address) ? [this.account.address] : [];
95
+ if (!this.account) {
96
+ yield this.connect({ silent: true });
97
+ }
98
+ const address = (_a = this.account) === null || _a === void 0 ? void 0 : _a.address;
99
+ if (address) {
100
+ return [address];
101
+ }
102
+ return [];
90
103
  });
91
104
  }
105
+ /**
106
+ * Helper to get the chain id from a [SuiChangeEvent].
107
+ *
108
+ * Some wallets set the event.chains objects but others use event.accounts.chains,
109
+ * so we need to deal with both cases.
110
+ *
111
+ * @param event - The [SuiChangeEvent] to get the chain id from
112
+ * @returns The dynamic chain id or '-1' if the chain id is not found
113
+ */
114
+ getChainFromEvent(event) {
115
+ var _a, _b, _c, _d, _e;
116
+ let suiChain = (_a = event.chains) === null || _a === void 0 ? void 0 : _a[0];
117
+ if (!suiChain) {
118
+ 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];
119
+ }
120
+ if (!suiChain) {
121
+ return '-1';
122
+ }
123
+ return (_e = networkHelpers.getSuiNetworkIdFromName(suiChain, this.suiNetworks)) !== null && _e !== void 0 ? _e : '-1';
124
+ }
92
125
  setupEventListeners() {
93
126
  var _a;
94
127
  if (!this.canSetEventListeners || this.eventsHandler)
@@ -100,40 +133,40 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
100
133
  }
101
134
  this.eventsHandler = (event) => _tslib.__awaiter(this, void 0, void 0, function* () {
102
135
  var _b;
103
- this.logger.debug('[eventsHandler] Received argument:', event);
104
- if (!event.accounts || event.accounts.length === 0) {
105
- this.emit('disconnect');
106
- return;
107
- }
108
- const [primaryAccount] = event.accounts;
109
- if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
110
- this.account = primaryAccount;
111
- this.emit('accountChange', { accounts: [primaryAccount.address] });
112
- }
113
- if (primaryAccount.chains && primaryAccount.chains.length > 0) {
114
- const [primaryChain] = primaryAccount.chains;
115
- const suiChainId = networkHelpers.getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
116
- if (suiChainId && suiChainId !== this.activeNetworkId) {
117
- this.activeNetworkId = suiChainId;
118
- this.emit('chainChange', {
119
- chain: suiChainId,
120
- });
136
+ if (event.accounts) {
137
+ // If the event sets accounts but it's empty, we need to disconnect.
138
+ if (event.accounts.length === 0 && this.account) {
139
+ this.account = undefined;
140
+ this.emit('disconnect');
141
+ return;
142
+ }
143
+ const [primaryAccount] = event.accounts;
144
+ if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
145
+ this.account = primaryAccount;
146
+ this.emit('accountChange', { accounts: [primaryAccount.address] });
121
147
  }
122
148
  }
149
+ // Some events will leave out accounts but set the chains object, so we process those
150
+ // with the helper.
151
+ const suiChainId = this.getChainFromEvent(event);
152
+ if (suiChainId !== this.activeNetworkId) {
153
+ this.activeNetworkId = suiChainId;
154
+ this.emit('chainChange', { chain: suiChainId });
155
+ }
123
156
  });
124
157
  this.logger.debug('[setupEventListeners] Setting up sui wallet connector event listeners');
125
- eventsFeature.on('change', this.eventsHandler);
158
+ this.eventsUnsubscribeHandler = eventsFeature.on('change', this.eventsHandler);
126
159
  }
127
160
  /**
128
161
  * Helper to get the Sui client for the current network
129
162
  *
130
163
  * The client will prefer the private customer rpc url if available.
131
164
  */
132
- getSuiClient(networkId) {
165
+ getWalletClient(networkId) {
133
166
  return _tslib.__awaiter(this, void 0, void 0, function* () {
134
167
  const clientNetworkId = networkId !== null && networkId !== void 0 ? networkId : (yield this.getNetwork());
135
168
  if (!clientNetworkId) {
136
- this.logger.error('[getSuiClient] Failed to get network id');
169
+ this.logger.error('[getWalletClient] Failed to get network id');
137
170
  return undefined;
138
171
  }
139
172
  // Default to an existing client if available
@@ -143,7 +176,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
143
176
  const network = this.getEnabledNetworks().find((network) => network.networkId === clientNetworkId);
144
177
  const url = network ? networkHelpers.getPreferredRpcUrl(network) : undefined;
145
178
  if (!url) {
146
- this.logger.error('[getSuiClient] Failed to get network url');
179
+ this.logger.error('[getWalletClient] Failed to get network url');
147
180
  return undefined;
148
181
  }
149
182
  this.suiClients[clientNetworkId] = new client.SuiClient({
@@ -154,7 +187,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
154
187
  }
155
188
  getBalance(address) {
156
189
  return _tslib.__awaiter(this, void 0, void 0, function* () {
157
- const client = yield this.getSuiClient();
190
+ const client = yield this.getWalletClient();
158
191
  if (!client) {
159
192
  this.logger.error('[getBalance] Failed to get Sui client');
160
193
  return undefined;
@@ -206,10 +239,12 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
206
239
  return this.account;
207
240
  });
208
241
  }
209
- // Stub method
210
- getProvider() {
242
+ teardownEventListeners() {
211
243
  return _tslib.__awaiter(this, void 0, void 0, function* () {
212
- return 'getProvider not implemented';
244
+ if (this.eventsUnsubscribeHandler) {
245
+ this.eventsUnsubscribeHandler();
246
+ this.eventsUnsubscribeHandler = undefined;
247
+ }
213
248
  });
214
249
  }
215
250
  endSession() {
@@ -16,6 +16,7 @@ export declare abstract class SuiWalletConnector extends WalletConnectorBase<typ
16
16
  eventsHandler: SuiWalletStandardEventHandler | undefined;
17
17
  /** Sui wallet instance */
18
18
  wallet: WalletWithFeatures<SuiWalletFeatures> | undefined;
19
+ eventsUnsubscribeHandler: (() => void) | undefined;
19
20
  /** Tracks the active wallet account */
20
21
  protected account: WalletAccount | undefined;
21
22
  /**
@@ -35,23 +36,35 @@ export declare abstract class SuiWalletConnector extends WalletConnectorBase<typ
35
36
  /** Helper to return the wallet features */
36
37
  getFeatures(): SuiWalletFeatures | undefined;
37
38
  /** Connect to the wallet using the standard:connect feature */
38
- connect(): Promise<void>;
39
+ connect({ silent }?: {
40
+ silent?: boolean;
41
+ }): Promise<void>;
39
42
  /** Get the wallet address by connecting to the current account */
40
43
  getAddress(): Promise<string | undefined>;
41
44
  /** Returns the network id of the account's active chain */
42
45
  getNetwork(): Promise<string | undefined>;
43
46
  getConnectedAccounts(): Promise<string[]>;
47
+ /**
48
+ * Helper to get the chain id from a [SuiChangeEvent].
49
+ *
50
+ * Some wallets set the event.chains objects but others use event.accounts.chains,
51
+ * so we need to deal with both cases.
52
+ *
53
+ * @param event - The [SuiChangeEvent] to get the chain id from
54
+ * @returns The dynamic chain id or '-1' if the chain id is not found
55
+ */
56
+ private getChainFromEvent;
44
57
  setupEventListeners(): void;
45
58
  /**
46
59
  * Helper to get the Sui client for the current network
47
60
  *
48
61
  * The client will prefer the private customer rpc url if available.
49
62
  */
50
- getSuiClient(networkId?: string): Promise<SuiClient | undefined>;
63
+ getWalletClient(networkId?: string): Promise<SuiClient | undefined>;
51
64
  getBalance(address: string): Promise<string | undefined>;
52
65
  signMessage(messageToSign: string): Promise<string | undefined>;
53
66
  getWalletAccount(): Promise<WalletAccount | undefined>;
54
- getProvider(): Promise<string>;
67
+ teardownEventListeners(): Promise<void>;
55
68
  endSession(): Promise<void>;
56
69
  getEnabledNetworks(): GenericNetwork[];
57
70
  }
@@ -32,7 +32,7 @@ class SuiWalletConnector extends WalletConnectorBase {
32
32
  }
33
33
  /** Connect to the wallet using the standard:connect feature */
34
34
  connect() {
35
- return __awaiter(this, void 0, void 0, function* () {
35
+ return __awaiter(this, arguments, void 0, function* ({ silent } = {}) {
36
36
  var _a, _b;
37
37
  if (this.account) {
38
38
  // Account is already connected
@@ -40,11 +40,14 @@ class SuiWalletConnector extends WalletConnectorBase {
40
40
  }
41
41
  const connectFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:connect'];
42
42
  if (!connectFeature) {
43
+ if (silent) {
44
+ return;
45
+ }
43
46
  throw new DynamicError('Wallet does not support standard:connect');
44
47
  }
45
48
  this.logger.debug('[connect] Creating new connection');
46
49
  try {
47
- const response = yield connectFeature.connect();
50
+ const response = yield connectFeature.connect(silent ? { silent } : undefined);
48
51
  this.logger.debug(`[connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
49
52
  this.account = response === null || response === void 0 ? void 0 : response.accounts[0];
50
53
  const primaryChain = (_b = this.account) === null || _b === void 0 ? void 0 : _b.chains[0];
@@ -54,6 +57,9 @@ class SuiWalletConnector extends WalletConnectorBase {
54
57
  }
55
58
  catch (error) {
56
59
  this.logger.error(error);
60
+ if (silent) {
61
+ return;
62
+ }
57
63
  throw new DynamicError('Connection failed');
58
64
  }
59
65
  this.setupEventListeners();
@@ -82,9 +88,36 @@ class SuiWalletConnector extends WalletConnectorBase {
82
88
  getConnectedAccounts() {
83
89
  return __awaiter(this, void 0, void 0, function* () {
84
90
  var _a;
85
- return ((_a = this.account) === null || _a === void 0 ? void 0 : _a.address) ? [this.account.address] : [];
91
+ if (!this.account) {
92
+ yield this.connect({ silent: true });
93
+ }
94
+ const address = (_a = this.account) === null || _a === void 0 ? void 0 : _a.address;
95
+ if (address) {
96
+ return [address];
97
+ }
98
+ return [];
86
99
  });
87
100
  }
101
+ /**
102
+ * Helper to get the chain id from a [SuiChangeEvent].
103
+ *
104
+ * Some wallets set the event.chains objects but others use event.accounts.chains,
105
+ * so we need to deal with both cases.
106
+ *
107
+ * @param event - The [SuiChangeEvent] to get the chain id from
108
+ * @returns The dynamic chain id or '-1' if the chain id is not found
109
+ */
110
+ getChainFromEvent(event) {
111
+ var _a, _b, _c, _d, _e;
112
+ let suiChain = (_a = event.chains) === null || _a === void 0 ? void 0 : _a[0];
113
+ if (!suiChain) {
114
+ 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];
115
+ }
116
+ if (!suiChain) {
117
+ return '-1';
118
+ }
119
+ return (_e = getSuiNetworkIdFromName(suiChain, this.suiNetworks)) !== null && _e !== void 0 ? _e : '-1';
120
+ }
88
121
  setupEventListeners() {
89
122
  var _a;
90
123
  if (!this.canSetEventListeners || this.eventsHandler)
@@ -96,40 +129,40 @@ class SuiWalletConnector extends WalletConnectorBase {
96
129
  }
97
130
  this.eventsHandler = (event) => __awaiter(this, void 0, void 0, function* () {
98
131
  var _b;
99
- this.logger.debug('[eventsHandler] Received argument:', event);
100
- if (!event.accounts || event.accounts.length === 0) {
101
- this.emit('disconnect');
102
- return;
103
- }
104
- const [primaryAccount] = event.accounts;
105
- if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
106
- this.account = primaryAccount;
107
- this.emit('accountChange', { accounts: [primaryAccount.address] });
108
- }
109
- if (primaryAccount.chains && primaryAccount.chains.length > 0) {
110
- const [primaryChain] = primaryAccount.chains;
111
- const suiChainId = getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
112
- if (suiChainId && suiChainId !== this.activeNetworkId) {
113
- this.activeNetworkId = suiChainId;
114
- this.emit('chainChange', {
115
- chain: suiChainId,
116
- });
132
+ if (event.accounts) {
133
+ // If the event sets accounts but it's empty, we need to disconnect.
134
+ if (event.accounts.length === 0 && this.account) {
135
+ this.account = undefined;
136
+ this.emit('disconnect');
137
+ return;
138
+ }
139
+ const [primaryAccount] = event.accounts;
140
+ if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
141
+ this.account = primaryAccount;
142
+ this.emit('accountChange', { accounts: [primaryAccount.address] });
117
143
  }
118
144
  }
145
+ // Some events will leave out accounts but set the chains object, so we process those
146
+ // with the helper.
147
+ const suiChainId = this.getChainFromEvent(event);
148
+ if (suiChainId !== this.activeNetworkId) {
149
+ this.activeNetworkId = suiChainId;
150
+ this.emit('chainChange', { chain: suiChainId });
151
+ }
119
152
  });
120
153
  this.logger.debug('[setupEventListeners] Setting up sui wallet connector event listeners');
121
- eventsFeature.on('change', this.eventsHandler);
154
+ this.eventsUnsubscribeHandler = eventsFeature.on('change', this.eventsHandler);
122
155
  }
123
156
  /**
124
157
  * Helper to get the Sui client for the current network
125
158
  *
126
159
  * The client will prefer the private customer rpc url if available.
127
160
  */
128
- getSuiClient(networkId) {
161
+ getWalletClient(networkId) {
129
162
  return __awaiter(this, void 0, void 0, function* () {
130
163
  const clientNetworkId = networkId !== null && networkId !== void 0 ? networkId : (yield this.getNetwork());
131
164
  if (!clientNetworkId) {
132
- this.logger.error('[getSuiClient] Failed to get network id');
165
+ this.logger.error('[getWalletClient] Failed to get network id');
133
166
  return undefined;
134
167
  }
135
168
  // Default to an existing client if available
@@ -139,7 +172,7 @@ class SuiWalletConnector extends WalletConnectorBase {
139
172
  const network = this.getEnabledNetworks().find((network) => network.networkId === clientNetworkId);
140
173
  const url = network ? getPreferredRpcUrl(network) : undefined;
141
174
  if (!url) {
142
- this.logger.error('[getSuiClient] Failed to get network url');
175
+ this.logger.error('[getWalletClient] Failed to get network url');
143
176
  return undefined;
144
177
  }
145
178
  this.suiClients[clientNetworkId] = new SuiClient({
@@ -150,7 +183,7 @@ class SuiWalletConnector extends WalletConnectorBase {
150
183
  }
151
184
  getBalance(address) {
152
185
  return __awaiter(this, void 0, void 0, function* () {
153
- const client = yield this.getSuiClient();
186
+ const client = yield this.getWalletClient();
154
187
  if (!client) {
155
188
  this.logger.error('[getBalance] Failed to get Sui client');
156
189
  return undefined;
@@ -202,10 +235,12 @@ class SuiWalletConnector extends WalletConnectorBase {
202
235
  return this.account;
203
236
  });
204
237
  }
205
- // Stub method
206
- getProvider() {
238
+ teardownEventListeners() {
207
239
  return __awaiter(this, void 0, void 0, function* () {
208
- return 'getProvider not implemented';
240
+ if (this.eventsUnsubscribeHandler) {
241
+ this.eventsUnsubscribeHandler();
242
+ this.eventsUnsubscribeHandler = undefined;
243
+ }
209
244
  });
210
245
  }
211
246
  endSession() {
package/src/index.cjs CHANGED
@@ -6,7 +6,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var assertPackageVersion = require('@dynamic-labs/assert-package-version');
7
7
  var _package = require('../package.cjs');
8
8
  var fetchSuiInjectedWalletConnectors = require('./wallets/injected/fetchSuiInjectedWalletConnectors.cjs');
9
+ var constants = require('./utils/constants/constants.cjs');
9
10
  var SuiWalletConnector = require('./SuiWalletConnector.cjs');
11
+ var SuiWallet = require('./wallet/SuiWallet.cjs');
12
+ var isSuiWallet = require('./wallet/isSuiWallet/isSuiWallet.cjs');
10
13
 
11
14
  /* eslint-disable @typescript-eslint/no-unused-vars */
12
15
  assertPackageVersion.assertPackageVersion('@dynamic-labs/sui', _package.version);
@@ -15,5 +18,8 @@ const SuiWalletConnectors = (props) => [
15
18
  ...fetchSuiInjectedWalletConnectors.fetchSuiInjectedWalletConnectors(props),
16
19
  ];
17
20
 
21
+ exports.MIST_PER_SUI = constants.MIST_PER_SUI;
18
22
  exports.SuiWalletConnector = SuiWalletConnector.SuiWalletConnector;
23
+ exports.SuiWallet = SuiWallet.SuiWallet;
24
+ exports.isSuiWallet = isSuiWallet.isSuiWallet;
19
25
  exports.SuiWalletConnectors = SuiWalletConnectors;
package/src/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
+ export * from './utils/constants';
1
2
  export declare const SuiWalletConnectors: (props: any) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
2
3
  export { SuiWalletConnector } from './SuiWalletConnector';
4
+ export { SuiWallet } from './wallet/SuiWallet';
5
+ export { isSuiWallet } from './wallet/isSuiWallet';
package/src/index.js CHANGED
@@ -2,7 +2,10 @@
2
2
  import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
3
3
  import { version } from '../package.js';
4
4
  import { fetchSuiInjectedWalletConnectors } from './wallets/injected/fetchSuiInjectedWalletConnectors.js';
5
+ export { MIST_PER_SUI } from './utils/constants/constants.js';
5
6
  export { SuiWalletConnector } from './SuiWalletConnector.js';
7
+ export { SuiWallet } from './wallet/SuiWallet.js';
8
+ export { isSuiWallet } from './wallet/isSuiWallet/isSuiWallet.js';
6
9
 
7
10
  /* eslint-disable @typescript-eslint/no-unused-vars */
8
11
  assertPackageVersion('@dynamic-labs/sui', version);
package/src/types.d.ts CHANGED
@@ -17,3 +17,11 @@ export type SuiChangeEvent = {
17
17
  features: IdentifierRecord<unknown>;
18
18
  };
19
19
  export type SuiWalletStandardEventHandler = (event: SuiChangeEvent) => Promise<void>;
20
+ export type SuiSendBalanceProps = {
21
+ amount: string;
22
+ toAddress: string;
23
+ token?: {
24
+ address: string;
25
+ decimals?: number;
26
+ };
27
+ };
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const MIST_PER_SUI = 1e9;
7
+
8
+ exports.MIST_PER_SUI = MIST_PER_SUI;
@@ -0,0 +1 @@
1
+ export declare const MIST_PER_SUI = 1000000000;
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const MIST_PER_SUI = 1e9;
3
+
4
+ export { MIST_PER_SUI };
@@ -0,0 +1 @@
1
+ export * from './constants';
@@ -4,20 +4,103 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var transactions = require('@mysten/sui/transactions');
7
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
+ var utils = require('@dynamic-labs/utils');
10
+ var constants = require('../utils/constants/constants.cjs');
8
11
 
9
12
  class SuiWallet extends walletConnectorCore.Wallet {
10
13
  /**
11
14
  * Sends the native balance of the wallet to the given address.
12
15
  * @param amount - The amount of balance
13
16
  * @param toAddress - The address to send the balance to.
14
- * @returns The signature of the sent transaction.
17
+ * @returns The transaction as base64 encoded bcs.
15
18
  */
16
- sendBalance() {
19
+ sendBalance(_a) {
20
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
21
+ var _b;
22
+ 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
+ const transaction = new transactions.Transaction();
36
+ const mistAmount = Number(amount) * constants.MIST_PER_SUI;
37
+ transaction.setGasPrice(1000);
38
+ transaction.setGasBudget(10000000);
39
+ const [coin] = transaction.splitCoins(transaction.gas, [mistAmount]);
40
+ transaction.transferObjects([coin], toAddress);
41
+ const { bytes } = yield transactionFeature.signAndExecuteTransaction({
42
+ account,
43
+ chain,
44
+ transaction,
45
+ });
46
+ return bytes;
47
+ });
48
+ }
49
+ /**
50
+ * Returns the Sui Client object initialized for the wallet's current network.
51
+ * @returns The [SuiClient] object.
52
+ */
53
+ getWalletClient() {
54
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
55
+ return this._connector.getWalletClient();
56
+ });
57
+ }
58
+ /**
59
+ * Returns the wallet's current active account.
60
+ * @returns a readonly [WalletAccount] object.
61
+ */
62
+ getWalletAccount() {
63
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
64
+ return this._connector.getWalletAccount();
65
+ });
66
+ }
67
+ /**
68
+ * Returns the wallet's current active network.
69
+ * @returns a string representing the active network, i.e. 'sui:devnet'.
70
+ */
71
+ getActiveNetwork() {
72
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
73
+ const account = yield this._connector.getWalletAccount();
74
+ return account === null || account === void 0 ? void 0 : account.chains[0];
75
+ });
76
+ }
77
+ /**
78
+ * Signs a Sui [Transaction].
79
+ * @param tx - The [Transaction] to sign.
80
+ * @returns The signature of the signed transaction.
81
+ */
82
+ signTransaction(transaction) {
17
83
  return _tslib.__awaiter(this, void 0, void 0, function* () {
18
- // Currently does nothing
84
+ var _a;
19
85
  yield this._connector.connect();
20
- return '';
86
+ const account = yield this._connector.getWalletAccount();
87
+ const chain = account === null || account === void 0 ? void 0 : account.chains[0];
88
+ if (!account) {
89
+ throw new utils.DynamicError('Unable to retrieve Sui wallet account');
90
+ }
91
+ if (!chain) {
92
+ throw new utils.DynamicError('Unable to retrieve Sui active network');
93
+ }
94
+ const transactionFeature = (_a = this._connector.getFeatures()) === null || _a === void 0 ? void 0 : _a['sui:signTransaction'];
95
+ if (!transactionFeature) {
96
+ throw new utils.DynamicError('Wallet does not support sui:signTransaction');
97
+ }
98
+ const signedTransaction = yield transactionFeature.signTransaction({
99
+ account,
100
+ chain,
101
+ transaction,
102
+ });
103
+ return signedTransaction;
21
104
  });
22
105
  }
23
106
  }
@@ -1,11 +1,36 @@
1
+ import { Transaction } from '@mysten/sui/transactions';
2
+ import { SuiClient } from '@mysten/sui/client';
3
+ import { SignedTransaction, WalletAccount } from '@mysten/wallet-standard';
1
4
  import { Wallet } from '@dynamic-labs/wallet-connector-core';
2
5
  import { SuiWalletConnector } from '../SuiWalletConnector';
6
+ import { SuiSendBalanceProps } from '../types';
3
7
  export declare class SuiWallet extends Wallet<SuiWalletConnector> {
4
8
  /**
5
9
  * Sends the native balance of the wallet to the given address.
6
10
  * @param amount - The amount of balance
7
11
  * @param toAddress - The address to send the balance to.
8
- * @returns The signature of the sent transaction.
12
+ * @returns The transaction as base64 encoded bcs.
9
13
  */
10
- sendBalance(): Promise<string>;
14
+ sendBalance({ amount, toAddress, }: SuiSendBalanceProps): Promise<string>;
15
+ /**
16
+ * Returns the Sui Client object initialized for the wallet's current network.
17
+ * @returns The [SuiClient] object.
18
+ */
19
+ getWalletClient(): Promise<SuiClient | undefined>;
20
+ /**
21
+ * Returns the wallet's current active account.
22
+ * @returns a readonly [WalletAccount] object.
23
+ */
24
+ getWalletAccount(): Promise<WalletAccount | undefined>;
25
+ /**
26
+ * Returns the wallet's current active network.
27
+ * @returns a string representing the active network, i.e. 'sui:devnet'.
28
+ */
29
+ getActiveNetwork(): Promise<string | undefined>;
30
+ /**
31
+ * Signs a Sui [Transaction].
32
+ * @param tx - The [Transaction] to sign.
33
+ * @returns The signature of the signed transaction.
34
+ */
35
+ signTransaction(transaction: Transaction): Promise<SignedTransaction>;
11
36
  }
@@ -1,19 +1,102 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { Transaction } from '@mysten/sui/transactions';
3
4
  import { Wallet } from '@dynamic-labs/wallet-connector-core';
5
+ import { DynamicError } from '@dynamic-labs/utils';
6
+ import { MIST_PER_SUI } from '../utils/constants/constants.js';
4
7
 
5
8
  class SuiWallet extends Wallet {
6
9
  /**
7
10
  * Sends the native balance of the wallet to the given address.
8
11
  * @param amount - The amount of balance
9
12
  * @param toAddress - The address to send the balance to.
10
- * @returns The signature of the sent transaction.
13
+ * @returns The transaction as base64 encoded bcs.
11
14
  */
12
- sendBalance() {
15
+ sendBalance(_a) {
16
+ return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
17
+ var _b;
18
+ 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
+ const transaction = new Transaction();
32
+ const mistAmount = Number(amount) * MIST_PER_SUI;
33
+ transaction.setGasPrice(1000);
34
+ transaction.setGasBudget(10000000);
35
+ const [coin] = transaction.splitCoins(transaction.gas, [mistAmount]);
36
+ transaction.transferObjects([coin], toAddress);
37
+ const { bytes } = yield transactionFeature.signAndExecuteTransaction({
38
+ account,
39
+ chain,
40
+ transaction,
41
+ });
42
+ return bytes;
43
+ });
44
+ }
45
+ /**
46
+ * Returns the Sui Client object initialized for the wallet's current network.
47
+ * @returns The [SuiClient] object.
48
+ */
49
+ getWalletClient() {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ return this._connector.getWalletClient();
52
+ });
53
+ }
54
+ /**
55
+ * Returns the wallet's current active account.
56
+ * @returns a readonly [WalletAccount] object.
57
+ */
58
+ getWalletAccount() {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ return this._connector.getWalletAccount();
61
+ });
62
+ }
63
+ /**
64
+ * Returns the wallet's current active network.
65
+ * @returns a string representing the active network, i.e. 'sui:devnet'.
66
+ */
67
+ getActiveNetwork() {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const account = yield this._connector.getWalletAccount();
70
+ return account === null || account === void 0 ? void 0 : account.chains[0];
71
+ });
72
+ }
73
+ /**
74
+ * Signs a Sui [Transaction].
75
+ * @param tx - The [Transaction] to sign.
76
+ * @returns The signature of the signed transaction.
77
+ */
78
+ signTransaction(transaction) {
13
79
  return __awaiter(this, void 0, void 0, function* () {
14
- // Currently does nothing
80
+ var _a;
15
81
  yield this._connector.connect();
16
- return '';
82
+ const account = yield this._connector.getWalletAccount();
83
+ const chain = account === null || account === void 0 ? void 0 : account.chains[0];
84
+ if (!account) {
85
+ throw new DynamicError('Unable to retrieve Sui wallet account');
86
+ }
87
+ if (!chain) {
88
+ throw new DynamicError('Unable to retrieve Sui active network');
89
+ }
90
+ const transactionFeature = (_a = this._connector.getFeatures()) === null || _a === void 0 ? void 0 : _a['sui:signTransaction'];
91
+ if (!transactionFeature) {
92
+ throw new DynamicError('Wallet does not support sui:signTransaction');
93
+ }
94
+ const signedTransaction = yield transactionFeature.signTransaction({
95
+ account,
96
+ chain,
97
+ transaction,
98
+ });
99
+ return signedTransaction;
17
100
  });
18
101
  }
19
102
  }
@@ -0,0 +1 @@
1
+ export * from './isSuiWallet';
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const isSuiWallet = (wallet) => wallet.chain === 'SUI';
7
+
8
+ exports.isSuiWallet = isSuiWallet;
@@ -0,0 +1,3 @@
1
+ import { Wallet } from '@dynamic-labs/wallet-connector-core';
2
+ import { SuiWallet } from '../SuiWallet';
3
+ export declare const isSuiWallet: (wallet: Wallet) => wallet is SuiWallet;
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const isSuiWallet = (wallet) => wallet.chain === 'SUI';
3
+
4
+ export { isSuiWallet };