@dynamic-labs/sui 4.9.8 → 4.9.9
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 +12 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -7
- package/src/SuiWalletConnector.cjs +48 -3
- package/src/SuiWalletConnector.d.ts +9 -2
- package/src/SuiWalletConnector.js +48 -3
- package/src/types.d.ts +7 -1
- package/src/utils/network/index.d.ts +1 -0
- package/src/utils/network/networkHelpers.cjs +16 -0
- package/src/utils/network/networkHelpers.d.ts +2 -0
- package/src/utils/network/networkHelpers.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.9.9](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.8...v4.9.9) (2025-03-26)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* **global-wallet-client:** properly clean up the popup state when popup is closed ([#8379](https://github.com/dynamic-labs/dynamic-auth/issues/8379)) ([782963f](https://github.com/dynamic-labs/dynamic-auth/commit/782963f87fcb2658b921ff6cc6f22c63be9714fb))
|
|
8
|
+
* hanging promises when a starknet wallet is connected but locked ([#8376](https://github.com/dynamic-labs/dynamic-auth/issues/8376)) ([a753939](https://github.com/dynamic-labs/dynamic-auth/commit/a7539395d4653be49f000ae51d15347a176b5b6c))
|
|
9
|
+
* token balance list should respect sort from backend ([#8383](https://github.com/dynamic-labs/dynamic-auth/issues/8383)) ([1c3bef4](https://github.com/dynamic-labs/dynamic-auth/commit/1c3bef47dbfd319e2444368a4a503b0839b5ad4b))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* add message auth code to global wallet ([#8354](https://github.com/dynamic-labs/dynamic-auth/issues/8354)) ([c847bf8](https://github.com/dynamic-labs/dynamic-auth/commit/c847bf8d66db54534348622255997f30f4309542))
|
|
13
|
+
|
|
2
14
|
### [4.9.8](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.7...v4.9.8) (2025-03-24)
|
|
3
15
|
|
|
4
16
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sui",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.9",
|
|
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",
|
|
@@ -21,12 +21,13 @@
|
|
|
21
21
|
"@dynamic-labs/sdk-api-core": "0.0.644",
|
|
22
22
|
"@mysten/wallet-standard": "0.13.29",
|
|
23
23
|
"text-encoding": "0.7.0",
|
|
24
|
-
"@dynamic-labs/assert-package-version": "4.9.
|
|
25
|
-
"@dynamic-labs/logger": "4.9.
|
|
26
|
-
"@dynamic-labs/rpc-providers": "4.9.
|
|
27
|
-
"@dynamic-labs/
|
|
28
|
-
"@dynamic-labs/
|
|
29
|
-
"@dynamic-labs/wallet-
|
|
24
|
+
"@dynamic-labs/assert-package-version": "4.9.9",
|
|
25
|
+
"@dynamic-labs/logger": "4.9.9",
|
|
26
|
+
"@dynamic-labs/rpc-providers": "4.9.9",
|
|
27
|
+
"@dynamic-labs/types": "4.9.9",
|
|
28
|
+
"@dynamic-labs/utils": "4.9.9",
|
|
29
|
+
"@dynamic-labs/wallet-book": "4.9.9",
|
|
30
|
+
"@dynamic-labs/wallet-connector-core": "4.9.9"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {}
|
|
32
33
|
}
|
|
@@ -8,6 +8,7 @@ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
|
8
8
|
var utils = require('@dynamic-labs/utils');
|
|
9
9
|
var logger = require('@dynamic-labs/logger');
|
|
10
10
|
var SuiWallet = require('./wallet/SuiWallet.cjs');
|
|
11
|
+
var networkHelpers = require('./utils/network/networkHelpers.cjs');
|
|
11
12
|
|
|
12
13
|
class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
13
14
|
constructor(name, opts) {
|
|
@@ -22,6 +23,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
22
23
|
this.name = name;
|
|
23
24
|
this.wallet = opts.wallet;
|
|
24
25
|
this.chainRpcProviders = opts.chainRpcProviders;
|
|
26
|
+
this.suiNetworks = opts.suiNetworks;
|
|
25
27
|
this.logger = new logger.Logger(this.name);
|
|
26
28
|
}
|
|
27
29
|
/** Helper to return the wallet features */
|
|
@@ -65,13 +67,17 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
65
67
|
return this.account.address;
|
|
66
68
|
});
|
|
67
69
|
}
|
|
70
|
+
/** Returns the network id of the account's active chain */
|
|
68
71
|
getNetwork() {
|
|
69
72
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
var _a;
|
|
71
|
-
if (!
|
|
73
|
+
var _a, _b;
|
|
74
|
+
if (!this.account) {
|
|
75
|
+
yield this.connect();
|
|
76
|
+
}
|
|
77
|
+
if (!((_b = (_a = this.account) === null || _a === void 0 ? void 0 : _a.chains) === null || _b === void 0 ? void 0 : _b[0])) {
|
|
72
78
|
return undefined;
|
|
73
79
|
}
|
|
74
|
-
return this.account.chains[0];
|
|
80
|
+
return networkHelpers.getSuiNetworkIdFromName(this.account.chains[0], this.suiNetworks);
|
|
75
81
|
});
|
|
76
82
|
}
|
|
77
83
|
getConnectedAccounts() {
|
|
@@ -80,6 +86,42 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
80
86
|
return ((_a = this.account) === null || _a === void 0 ? void 0 : _a.address) ? [this.account.address] : [];
|
|
81
87
|
});
|
|
82
88
|
}
|
|
89
|
+
setupEventListeners() {
|
|
90
|
+
var _a;
|
|
91
|
+
if (!this.canSetEventListeners)
|
|
92
|
+
return;
|
|
93
|
+
const eventsFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:events'];
|
|
94
|
+
if (!eventsFeature) {
|
|
95
|
+
throw new utils.DynamicError('Wallet not connected or does not support standard:events');
|
|
96
|
+
}
|
|
97
|
+
if (this.eventsHandler) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.eventsHandler = (event) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
var _b;
|
|
102
|
+
this.logger.debug('[eventsHandler] Received argument:', event);
|
|
103
|
+
if (!event.accounts || event.accounts.length === 0) {
|
|
104
|
+
this.emit('disconnect');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const [primaryAccount] = event.accounts;
|
|
108
|
+
if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
|
|
109
|
+
this.account = primaryAccount;
|
|
110
|
+
this.emit('accountChange', { accounts: [primaryAccount.address] });
|
|
111
|
+
}
|
|
112
|
+
if (primaryAccount.chains && primaryAccount.chains.length > 0) {
|
|
113
|
+
const [primaryChain] = primaryAccount.chains;
|
|
114
|
+
const suiChainId = networkHelpers.getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
|
|
115
|
+
if (suiChainId) {
|
|
116
|
+
this.emit('chainChange', {
|
|
117
|
+
chain: suiChainId,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
this.logger.debug('[setupEventListeners] Setting up sui wallet connector event listeners');
|
|
123
|
+
eventsFeature.on('change', this.eventsHandler);
|
|
124
|
+
}
|
|
83
125
|
getBalance(address) {
|
|
84
126
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
85
127
|
// Make RPC call to get balance
|
|
@@ -144,6 +186,9 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
144
186
|
throw new utils.DynamicError('Wallet does not support disconnect');
|
|
145
187
|
});
|
|
146
188
|
}
|
|
189
|
+
getEnabledNetworks() {
|
|
190
|
+
return this.suiNetworks;
|
|
191
|
+
}
|
|
147
192
|
}
|
|
148
193
|
|
|
149
194
|
exports.SuiWalletConnector = SuiWalletConnector;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SuiWalletFeatures, WalletAccount, WalletWithFeatures } from '@mysten/wallet-standard';
|
|
2
2
|
import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
3
|
import { Logger } from '@dynamic-labs/logger';
|
|
4
|
+
import { GenericNetwork } from '@dynamic-labs/types';
|
|
4
5
|
import { SuiWallet } from './wallet/SuiWallet';
|
|
5
|
-
import { SuiWalletConnectorProps } from './types';
|
|
6
|
+
import { SuiWalletConnectorProps, SuiWalletStandardEventHandler } from './types';
|
|
6
7
|
export declare abstract class SuiWalletConnector extends WalletConnectorBase<typeof SuiWallet> {
|
|
7
8
|
name: string;
|
|
8
9
|
ChainWallet: typeof SuiWallet;
|
|
@@ -11,10 +12,13 @@ export declare abstract class SuiWalletConnector extends WalletConnectorBase<typ
|
|
|
11
12
|
switchNetworkOnlyFromWallet: boolean;
|
|
12
13
|
/** required for metamask snap integration as MM snaps don't have event listeners */
|
|
13
14
|
canSetEventListeners: boolean;
|
|
15
|
+
eventsHandler: SuiWalletStandardEventHandler | undefined;
|
|
14
16
|
/** Sui wallet instance */
|
|
15
17
|
wallet: WalletWithFeatures<SuiWalletFeatures> | undefined;
|
|
16
18
|
/** Tracks the active wallet account */
|
|
17
19
|
protected account: WalletAccount | undefined;
|
|
20
|
+
/** Enabled SUI networks */
|
|
21
|
+
suiNetworks: GenericNetwork[];
|
|
18
22
|
/** Dynamic logger */
|
|
19
23
|
logger: Logger;
|
|
20
24
|
constructor(name: string, opts: SuiWalletConnectorProps);
|
|
@@ -24,12 +28,15 @@ export declare abstract class SuiWalletConnector extends WalletConnectorBase<typ
|
|
|
24
28
|
connect(): Promise<void>;
|
|
25
29
|
/** Get the wallet address by connecting to the current account */
|
|
26
30
|
getAddress(): Promise<string | undefined>;
|
|
27
|
-
|
|
31
|
+
/** Returns the network id of the account's active chain */
|
|
32
|
+
getNetwork(): Promise<string | undefined>;
|
|
28
33
|
getConnectedAccounts(): Promise<string[]>;
|
|
34
|
+
setupEventListeners(): void;
|
|
29
35
|
getBalance(address: string): Promise<string | undefined>;
|
|
30
36
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
31
37
|
getWalletAccount(): Promise<WalletAccount | undefined>;
|
|
32
38
|
getProvider(): Promise<string>;
|
|
33
39
|
endSession(): Promise<void>;
|
|
40
|
+
getEnabledNetworks(): GenericNetwork[];
|
|
34
41
|
}
|
|
35
42
|
export type SuiWalletConnectorType = SuiWalletConnector;
|
|
@@ -4,6 +4,7 @@ import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
|
4
4
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
5
5
|
import { Logger } from '@dynamic-labs/logger';
|
|
6
6
|
import { SuiWallet } from './wallet/SuiWallet.js';
|
|
7
|
+
import { getSuiNetworkIdFromName } from './utils/network/networkHelpers.js';
|
|
7
8
|
|
|
8
9
|
class SuiWalletConnector extends WalletConnectorBase {
|
|
9
10
|
constructor(name, opts) {
|
|
@@ -18,6 +19,7 @@ class SuiWalletConnector extends WalletConnectorBase {
|
|
|
18
19
|
this.name = name;
|
|
19
20
|
this.wallet = opts.wallet;
|
|
20
21
|
this.chainRpcProviders = opts.chainRpcProviders;
|
|
22
|
+
this.suiNetworks = opts.suiNetworks;
|
|
21
23
|
this.logger = new Logger(this.name);
|
|
22
24
|
}
|
|
23
25
|
/** Helper to return the wallet features */
|
|
@@ -61,13 +63,17 @@ class SuiWalletConnector extends WalletConnectorBase {
|
|
|
61
63
|
return this.account.address;
|
|
62
64
|
});
|
|
63
65
|
}
|
|
66
|
+
/** Returns the network id of the account's active chain */
|
|
64
67
|
getNetwork() {
|
|
65
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
var _a;
|
|
67
|
-
if (!
|
|
69
|
+
var _a, _b;
|
|
70
|
+
if (!this.account) {
|
|
71
|
+
yield this.connect();
|
|
72
|
+
}
|
|
73
|
+
if (!((_b = (_a = this.account) === null || _a === void 0 ? void 0 : _a.chains) === null || _b === void 0 ? void 0 : _b[0])) {
|
|
68
74
|
return undefined;
|
|
69
75
|
}
|
|
70
|
-
return this.account.chains[0];
|
|
76
|
+
return getSuiNetworkIdFromName(this.account.chains[0], this.suiNetworks);
|
|
71
77
|
});
|
|
72
78
|
}
|
|
73
79
|
getConnectedAccounts() {
|
|
@@ -76,6 +82,42 @@ class SuiWalletConnector extends WalletConnectorBase {
|
|
|
76
82
|
return ((_a = this.account) === null || _a === void 0 ? void 0 : _a.address) ? [this.account.address] : [];
|
|
77
83
|
});
|
|
78
84
|
}
|
|
85
|
+
setupEventListeners() {
|
|
86
|
+
var _a;
|
|
87
|
+
if (!this.canSetEventListeners)
|
|
88
|
+
return;
|
|
89
|
+
const eventsFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:events'];
|
|
90
|
+
if (!eventsFeature) {
|
|
91
|
+
throw new DynamicError('Wallet not connected or does not support standard:events');
|
|
92
|
+
}
|
|
93
|
+
if (this.eventsHandler) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.eventsHandler = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
var _b;
|
|
98
|
+
this.logger.debug('[eventsHandler] Received argument:', event);
|
|
99
|
+
if (!event.accounts || event.accounts.length === 0) {
|
|
100
|
+
this.emit('disconnect');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const [primaryAccount] = event.accounts;
|
|
104
|
+
if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
|
|
105
|
+
this.account = primaryAccount;
|
|
106
|
+
this.emit('accountChange', { accounts: [primaryAccount.address] });
|
|
107
|
+
}
|
|
108
|
+
if (primaryAccount.chains && primaryAccount.chains.length > 0) {
|
|
109
|
+
const [primaryChain] = primaryAccount.chains;
|
|
110
|
+
const suiChainId = getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
|
|
111
|
+
if (suiChainId) {
|
|
112
|
+
this.emit('chainChange', {
|
|
113
|
+
chain: suiChainId,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
this.logger.debug('[setupEventListeners] Setting up sui wallet connector event listeners');
|
|
119
|
+
eventsFeature.on('change', this.eventsHandler);
|
|
120
|
+
}
|
|
79
121
|
getBalance(address) {
|
|
80
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
123
|
// Make RPC call to get balance
|
|
@@ -140,6 +182,9 @@ class SuiWalletConnector extends WalletConnectorBase {
|
|
|
140
182
|
throw new DynamicError('Wallet does not support disconnect');
|
|
141
183
|
});
|
|
142
184
|
}
|
|
185
|
+
getEnabledNetworks() {
|
|
186
|
+
return this.suiNetworks;
|
|
187
|
+
}
|
|
143
188
|
}
|
|
144
189
|
|
|
145
190
|
export { SuiWalletConnector };
|
package/src/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletWithFeatures, SuiWalletFeatures } from '@mysten/wallet-standard';
|
|
1
|
+
import { WalletWithFeatures, SuiWalletFeatures, IdentifierRecord, IdentifierArray, WalletAccount } from '@mysten/wallet-standard';
|
|
2
2
|
import { IChainRpcProviders } from '@dynamic-labs/rpc-providers';
|
|
3
3
|
import { NetworkConfiguration } from '@dynamic-labs/sdk-api-core';
|
|
4
4
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
@@ -11,3 +11,9 @@ export type SuiWalletConnectorProps = {
|
|
|
11
11
|
wallet: WalletWithFeatures<SuiWalletFeatures>;
|
|
12
12
|
overrideKey?: string;
|
|
13
13
|
};
|
|
14
|
+
export type SuiChangeEvent = {
|
|
15
|
+
accounts: WalletAccount[];
|
|
16
|
+
chains: IdentifierArray;
|
|
17
|
+
features: IdentifierRecord<unknown>;
|
|
18
|
+
};
|
|
19
|
+
export type SuiWalletStandardEventHandler = (event: SuiChangeEvent) => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './networkHelpers';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const getSuiNetworkIdFromName = (name, networks) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const suiNetworkName = name.split(':').pop();
|
|
9
|
+
if (!suiNetworkName) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const chainId = (_a = networks.find((network) => network.name.toLowerCase().includes(suiNetworkName.toLowerCase()))) === null || _a === void 0 ? void 0 : _a.chainId;
|
|
13
|
+
return chainId ? String(chainId) : undefined;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.getSuiNetworkIdFromName = getSuiNetworkIdFromName;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const getSuiNetworkIdFromName = (name, networks) => {
|
|
3
|
+
var _a;
|
|
4
|
+
const suiNetworkName = name.split(':').pop();
|
|
5
|
+
if (!suiNetworkName) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
const chainId = (_a = networks.find((network) => network.name.toLowerCase().includes(suiNetworkName.toLowerCase()))) === null || _a === void 0 ? void 0 : _a.chainId;
|
|
9
|
+
return chainId ? String(chainId) : undefined;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { getSuiNetworkIdFromName };
|