@dynamic-labs-sdk/sui 0.1.0-alpha.29 → 0.1.0-alpha.30
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 +8 -0
- package/README.md +4 -18
- package/_extends.cjs.js +19 -0
- package/_extends.esm.js +15 -0
- package/addSuiWalletStandardExtension.cjs.js +303 -0
- package/addSuiWalletStandardExtension.esm.js +301 -0
- package/addWaasSuiExtension.cjs.js +140 -0
- package/addWaasSuiExtension.esm.js +138 -0
- package/index.cjs.js +146 -20
- package/index.esm.js +141 -17
- package/package.json +13 -5
- package/src/SuiNetworkProvider.types.d.ts +8 -0
- package/src/SuiNetworkProvider.types.d.ts.map +1 -0
- package/src/SuiWalletAccount.types.d.ts +8 -0
- package/src/SuiWalletAccount.types.d.ts.map +1 -0
- package/src/SuiWalletProvider.types.d.ts +40 -0
- package/src/SuiWalletProvider.types.d.ts.map +1 -0
- package/src/addSuiExtension/addSuiExtension.d.ts +11 -0
- package/src/addSuiExtension/addSuiExtension.d.ts.map +1 -0
- package/src/addSuiExtension/index.d.ts +2 -0
- package/src/addSuiExtension/index.d.ts.map +1 -0
- package/src/errors/NotSuiProviderError/NotSuiProviderError.d.ts.map +1 -1
- package/src/exports/index.d.ts +9 -4
- package/src/exports/index.d.ts.map +1 -1
- package/src/exports/waas.d.ts +2 -0
- package/src/exports/waas.d.ts.map +1 -0
- package/src/exports/walletStandard.d.ts +2 -0
- package/src/exports/walletStandard.d.ts.map +1 -0
- package/src/getSuiClient/getSuiClient.d.ts +3 -3
- package/src/getSuiClient/getSuiClient.d.ts.map +1 -1
- package/src/isSuiNetworkProvider/index.d.ts +2 -0
- package/src/isSuiNetworkProvider/index.d.ts.map +1 -0
- package/src/isSuiNetworkProvider/isSuiNetworkProvider.d.ts +10 -0
- package/src/isSuiNetworkProvider/isSuiNetworkProvider.d.ts.map +1 -0
- package/src/isSuiWalletAccount/isSuiWalletAccount.d.ts +5 -4
- package/src/isSuiWalletAccount/isSuiWalletAccount.d.ts.map +1 -1
- package/src/isSuiWalletProvider/isSuiWalletProvider.d.ts +1 -5
- package/src/isSuiWalletProvider/isSuiWalletProvider.d.ts.map +1 -1
- package/src/registerSuiNetworkProviderBuilder/index.d.ts +2 -0
- package/src/registerSuiNetworkProviderBuilder/index.d.ts.map +1 -0
- package/src/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.d.ts +3 -0
- package/src/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.d.ts.map +1 -0
- package/src/signAndExecuteTransaction/index.d.ts +2 -0
- package/src/signAndExecuteTransaction/index.d.ts.map +1 -0
- package/src/signAndExecuteTransaction/signAndExecuteTransaction.d.ts +17 -0
- package/src/signAndExecuteTransaction/signAndExecuteTransaction.d.ts.map +1 -0
- package/src/signAndExecuteTransactionBlock/index.d.ts +2 -0
- package/src/signAndExecuteTransactionBlock/index.d.ts.map +1 -0
- package/src/signAndExecuteTransactionBlock/signAndExecuteTransactionBlock.d.ts +25 -0
- package/src/signAndExecuteTransactionBlock/signAndExecuteTransactionBlock.d.ts.map +1 -0
- package/src/signTransaction/index.d.ts +2 -0
- package/src/signTransaction/index.d.ts.map +1 -0
- package/src/signTransaction/signTransaction.d.ts +17 -0
- package/src/signTransaction/signTransaction.d.ts.map +1 -0
- package/src/signTransactionBlock/index.d.ts +2 -0
- package/src/signTransactionBlock/index.d.ts.map +1 -0
- package/src/signTransactionBlock/signTransactionBlock.d.ts +20 -0
- package/src/signTransactionBlock/signTransactionBlock.d.ts.map +1 -0
- package/src/utils/createSuiNetworkProvider/createSuiNetworkProvider.d.ts +4 -0
- package/src/utils/createSuiNetworkProvider/createSuiNetworkProvider.d.ts.map +1 -0
- package/src/utils/createSuiNetworkProvider/index.d.ts +2 -0
- package/src/utils/createSuiNetworkProvider/index.d.ts.map +1 -0
- package/src/utils/fetchSuiBalance/fetchSuiBalance.d.ts +5 -0
- package/src/utils/fetchSuiBalance/fetchSuiBalance.d.ts.map +1 -0
- package/src/utils/fetchSuiBalance/index.d.ts +2 -0
- package/src/utils/fetchSuiBalance/index.d.ts.map +1 -0
- package/src/waas/WaasSuiWalletProvider.types.d.ts +4 -0
- package/src/waas/WaasSuiWalletProvider.types.d.ts.map +1 -0
- package/src/waas/addWaasSuiExtension/addWaasSuiExtension.d.ts +11 -0
- package/src/waas/addWaasSuiExtension/addWaasSuiExtension.d.ts.map +1 -0
- package/src/waas/addWaasSuiExtension/index.d.ts +2 -0
- package/src/waas/addWaasSuiExtension/index.d.ts.map +1 -0
- package/src/waas/utils/createWalletProviderForWaasSui/createWalletProviderForWaasSui.d.ts +4 -0
- package/src/waas/utils/createWalletProviderForWaasSui/createWalletProviderForWaasSui.d.ts.map +1 -0
- package/src/waas/utils/createWalletProviderForWaasSui/index.d.ts +2 -0
- package/src/waas/utils/createWalletProviderForWaasSui/index.d.ts.map +1 -0
- package/src/walletStandard/addSuiWalletStandardExtension/addSuiWalletStandardExtension.d.ts +11 -0
- package/src/walletStandard/addSuiWalletStandardExtension/addSuiWalletStandardExtension.d.ts.map +1 -0
- package/src/walletStandard/addSuiWalletStandardExtension/index.d.ts +2 -0
- package/src/walletStandard/addSuiWalletStandardExtension/index.d.ts.map +1 -0
- package/src/walletStandard/utils/createWalletProviderFromSuiStandardWallet/createWalletProviderFromSuiStandardWallet.d.ts +10 -0
- package/src/walletStandard/utils/createWalletProviderFromSuiStandardWallet/createWalletProviderFromSuiStandardWallet.d.ts.map +1 -0
- package/src/walletStandard/utils/createWalletProviderFromSuiStandardWallet/index.d.ts +2 -0
- package/src/walletStandard/utils/createWalletProviderFromSuiStandardWallet/index.d.ts.map +1 -0
- package/waas.cjs.d.ts +1 -0
- package/waas.cjs.js +14 -0
- package/waas.esm.d.ts +1 -0
- package/waas.esm.js +10 -0
- package/walletStandard.cjs.d.ts +1 -0
- package/walletStandard.cjs.js +15 -0
- package/walletStandard.esm.d.ts +1 -0
- package/walletStandard.esm.js +11 -0
- package/src/types/SuiClient.types.d.ts +0 -29
- package/src/types/SuiClient.types.d.ts.map +0 -1
- package/src/types/SuiWalletFeatures.types.d.ts +0 -32
- package/src/types/SuiWalletFeatures.types.d.ts.map +0 -1
- package/src/types/SuiWalletProvider.types.d.ts +0 -8
- package/src/types/SuiWalletProvider.types.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 0.1.0-alpha.30 (2025-11-19)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- allow social account unlinking ([#618](https://github.com/dynamic-labs/dynamic-sdk/pull/618))
|
|
6
|
+
- add support for Sui external wallets ([#643](https://github.com/dynamic-labs/dynamic-sdk/pull/643))
|
|
7
|
+
- add support for Sui embedded wallets ([#652](https://github.com/dynamic-labs/dynamic-sdk/pull/652))
|
|
8
|
+
|
|
1
9
|
## 0.1.0-alpha.29 (2025-11-12)
|
|
2
10
|
|
|
3
11
|
### 🚀 Features
|
package/README.md
CHANGED
|
@@ -12,24 +12,10 @@ pnpm add @dynamic-labs-sdk/sui
|
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
14
|
import { addSuiExtension } from '@dynamic-labs-sdk/sui';
|
|
15
|
+
import { createDynamicClient } from '@dynamic-labs-sdk/client';
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
const dynamicClient = createDynamicClient({
|
|
18
|
+
environmentId: '123',
|
|
19
|
+
});
|
|
17
20
|
addSuiExtension(dynamicClient);
|
|
18
21
|
```
|
|
19
|
-
|
|
20
|
-
This will register all SUI-compatible wallets that implement the wallet standard with your Dynamic client.
|
|
21
|
-
|
|
22
|
-
## Features
|
|
23
|
-
|
|
24
|
-
- SUI wallet provider integration
|
|
25
|
-
- SUI wallet standard support
|
|
26
|
-
- Easy extension for Dynamic SDK
|
|
27
|
-
|
|
28
|
-
## Requirements
|
|
29
|
-
|
|
30
|
-
- [@dynamic-labs-sdk/client](https://www.npmjs.com/package/@dynamic-labs-sdk/client)
|
|
31
|
-
- [@mysten/wallet-standard](https://www.npmjs.com/package/@mysten/wallet-standard)
|
|
32
|
-
|
|
33
|
-
## License
|
|
34
|
-
|
|
35
|
-
MIT
|
package/_extends.cjs.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var name = "@dynamic-labs-sdk/sui";
|
|
4
|
+
var version = "0.1.0-alpha.30";
|
|
5
|
+
|
|
6
|
+
function _extends() {
|
|
7
|
+
_extends = Object.assign || function assign(target) {
|
|
8
|
+
for(var i = 1; i < arguments.length; i++){
|
|
9
|
+
var source = arguments[i];
|
|
10
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
11
|
+
}
|
|
12
|
+
return target;
|
|
13
|
+
};
|
|
14
|
+
return _extends.apply(this, arguments);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports._extends = _extends;
|
|
18
|
+
exports.name = name;
|
|
19
|
+
exports.version = version;
|
package/_extends.esm.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var name = "@dynamic-labs-sdk/sui";
|
|
2
|
+
var version = "0.1.0-alpha.30";
|
|
3
|
+
|
|
4
|
+
function _extends() {
|
|
5
|
+
_extends = Object.assign || function assign(target) {
|
|
6
|
+
for(var i = 1; i < arguments.length; i++){
|
|
7
|
+
var source = arguments[i];
|
|
8
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
9
|
+
}
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
return _extends.apply(this, arguments);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { _extends as _, name as n, version as v };
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@dynamic-labs-sdk/client/core');
|
|
4
|
+
var walletStandard = require('@mysten/wallet-standard');
|
|
5
|
+
var _extends = require('./_extends.cjs.js');
|
|
6
|
+
var client = require('@mysten/sui/client');
|
|
7
|
+
var utils = require('@mysten/sui/utils');
|
|
8
|
+
var client$1 = require('@dynamic-labs-sdk/client');
|
|
9
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
10
|
+
|
|
11
|
+
const fetchSuiBalance = async ({ address, rpcUrl })=>{
|
|
12
|
+
// Create a SuiClient using the provided RPC URL.
|
|
13
|
+
const suiClient = new client.SuiClient({
|
|
14
|
+
url: rpcUrl
|
|
15
|
+
});
|
|
16
|
+
const balanceInMist = await suiClient.getBalance({
|
|
17
|
+
owner: address
|
|
18
|
+
});
|
|
19
|
+
// Balance comes back as MIST, 1 SUI = 1e9 MIST
|
|
20
|
+
const balance = Number(balanceInMist.totalBalance) / Number(utils.MIST_PER_SUI);
|
|
21
|
+
if (Number.isNaN(balance)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return balance.toString();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const createSuiNetworkProvider = (networkData)=>_extends._extends({}, core.createBaseNetworkProvider('SUI', networkData), {
|
|
28
|
+
getBalance: async ({ address })=>({
|
|
29
|
+
balance: await fetchSuiBalance({
|
|
30
|
+
address,
|
|
31
|
+
rpcUrl: networkData.rpcUrls.http[0]
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const registerSuiNetworkProviderBuilder = (client)=>{
|
|
37
|
+
const networkProviderBuilderRegistry = core.getNetworkProviderBuilderRegistry(client);
|
|
38
|
+
/**
|
|
39
|
+
* If the Sui network provider builder is already registered, return.
|
|
40
|
+
*/ if (networkProviderBuilderRegistry.get().get('SUI')) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
networkProviderBuilderRegistry.register({
|
|
44
|
+
builder: createSuiNetworkProvider,
|
|
45
|
+
chain: 'SUI'
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const createWalletProviderFromSuiStandardWallet = ({ dynamicClient, walletStandardWallet })=>{
|
|
50
|
+
const features = walletStandardWallet.features;
|
|
51
|
+
const walletProviderType = sdkApiCore.WalletProviderEnum.BrowserExtension;
|
|
52
|
+
const key = core.formatWalletProviderKey({
|
|
53
|
+
chain: 'SUI',
|
|
54
|
+
displayName: walletStandardWallet.name,
|
|
55
|
+
walletProviderType
|
|
56
|
+
});
|
|
57
|
+
const runConnectFeature = async ({ silent = false } = {})=>{
|
|
58
|
+
var _features_standardconnect, _result_accounts;
|
|
59
|
+
const connectMethod = (_features_standardconnect = features['standard:connect']) == null ? void 0 : _features_standardconnect.connect;
|
|
60
|
+
core.assertDefined(connectMethod, 'connect method not found in wallet features');
|
|
61
|
+
const result = await connectMethod({
|
|
62
|
+
silent
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
addresses: (_result_accounts = result.accounts) == null ? void 0 : _result_accounts.map((account)=>{
|
|
66
|
+
var _account_publicKey;
|
|
67
|
+
return {
|
|
68
|
+
address: account.address,
|
|
69
|
+
publicKey: (_account_publicKey = account.publicKey) == null ? void 0 : _account_publicKey.toString()
|
|
70
|
+
};
|
|
71
|
+
})
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const connect = async ()=>{
|
|
75
|
+
const autoConnectedAccounts = walletStandardWallet.accounts;
|
|
76
|
+
if ((autoConnectedAccounts == null ? void 0 : autoConnectedAccounts.length) && autoConnectedAccounts[0].address) {
|
|
77
|
+
var _autoConnectedAccounts__publicKey;
|
|
78
|
+
return {
|
|
79
|
+
addresses: [
|
|
80
|
+
{
|
|
81
|
+
address: autoConnectedAccounts[0].address,
|
|
82
|
+
publicKey: (_autoConnectedAccounts__publicKey = autoConnectedAccounts[0].publicKey) == null ? void 0 : _autoConnectedAccounts__publicKey.toString()
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return runConnectFeature();
|
|
88
|
+
};
|
|
89
|
+
const disconnect = async ()=>{
|
|
90
|
+
var _features_standarddisconnect;
|
|
91
|
+
const disconnectMethod = (_features_standarddisconnect = features['standard:disconnect']) == null ? void 0 : _features_standarddisconnect.disconnect;
|
|
92
|
+
core.assertDefined(disconnectMethod, 'disconnect method not found in wallet features');
|
|
93
|
+
await disconnectMethod();
|
|
94
|
+
};
|
|
95
|
+
const getActiveNetworkId = async ()=>core.getActiveNetworkIdFromLastKnownRegistry({
|
|
96
|
+
client: dynamicClient,
|
|
97
|
+
walletProviderKey: key
|
|
98
|
+
});
|
|
99
|
+
const getCurrentAccount = async ()=>{
|
|
100
|
+
var _walletStandardWallet_accounts;
|
|
101
|
+
if (!isConnected()) {
|
|
102
|
+
await runConnectFeature({
|
|
103
|
+
silent: true
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const account = (_walletStandardWallet_accounts = walletStandardWallet.accounts) == null ? void 0 : _walletStandardWallet_accounts[0];
|
|
107
|
+
core.assertDefined(account, 'No connected accounts found');
|
|
108
|
+
return account;
|
|
109
|
+
};
|
|
110
|
+
const getSuiClient = async ({ walletAccount })=>{
|
|
111
|
+
var _activeNetworkData_networkData;
|
|
112
|
+
const activeNetworkData = await client$1.getActiveNetworkData({
|
|
113
|
+
walletAccount
|
|
114
|
+
}, dynamicClient);
|
|
115
|
+
core.assertDefined(activeNetworkData, 'No active network data found');
|
|
116
|
+
const url = (_activeNetworkData_networkData = activeNetworkData.networkData) == null ? void 0 : _activeNetworkData_networkData.rpcUrls.http[0];
|
|
117
|
+
core.assertDefined(url, 'No RPC URL found for active network');
|
|
118
|
+
const client$2 = new client.SuiClient({
|
|
119
|
+
url
|
|
120
|
+
});
|
|
121
|
+
return client$2;
|
|
122
|
+
};
|
|
123
|
+
const isConnected = ()=>{
|
|
124
|
+
var _walletStandardWallet_accounts;
|
|
125
|
+
return ((_walletStandardWallet_accounts = walletStandardWallet.accounts) == null ? void 0 : _walletStandardWallet_accounts.length) > 0;
|
|
126
|
+
};
|
|
127
|
+
const getConnectedAddresses = async ()=>{
|
|
128
|
+
if (!isConnected()) {
|
|
129
|
+
await runConnectFeature({
|
|
130
|
+
silent: true
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
addresses: walletStandardWallet.accounts.map((account)=>account.address)
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
const signAndExecuteTransaction = async ({ transaction, walletAccount })=>{
|
|
138
|
+
var _features_suisignAndExecuteTransaction;
|
|
139
|
+
await client$1.assertWalletAccountSigningAvailability({
|
|
140
|
+
walletAccount
|
|
141
|
+
}, dynamicClient);
|
|
142
|
+
const signAndExecuteTransactionMethod = (_features_suisignAndExecuteTransaction = features['sui:signAndExecuteTransaction']) == null ? void 0 : _features_suisignAndExecuteTransaction.signAndExecuteTransaction;
|
|
143
|
+
core.assertDefined(signAndExecuteTransactionMethod, 'signAndExecuteTransaction method not found in wallet features');
|
|
144
|
+
const account = await getCurrentAccount();
|
|
145
|
+
return signAndExecuteTransactionMethod({
|
|
146
|
+
account,
|
|
147
|
+
chain: account.chains[0],
|
|
148
|
+
transaction
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
/* This method is deprecated, but still required by some wallets for backwards compatibility. */ const signAndExecuteTransactionBlock = async ({ options, requestType, transactionBlock, walletAccount })=>{
|
|
152
|
+
var _features_suisignAndExecuteTransactionBlock;
|
|
153
|
+
await client$1.assertWalletAccountSigningAvailability({
|
|
154
|
+
walletAccount
|
|
155
|
+
}, dynamicClient);
|
|
156
|
+
const signAndExecuteTransactionBlockMethod = (_features_suisignAndExecuteTransactionBlock = features['sui:signAndExecuteTransactionBlock']) == null ? void 0 : _features_suisignAndExecuteTransactionBlock.signAndExecuteTransactionBlock;
|
|
157
|
+
core.assertDefined(signAndExecuteTransactionBlockMethod, 'signAndExecuteTransactionBlock method not found in wallet features');
|
|
158
|
+
const account = await getCurrentAccount();
|
|
159
|
+
return signAndExecuteTransactionBlockMethod({
|
|
160
|
+
account,
|
|
161
|
+
chain: account.chains[0],
|
|
162
|
+
options,
|
|
163
|
+
requestType,
|
|
164
|
+
transactionBlock
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const signMessage = async ({ message, walletAccount })=>{
|
|
168
|
+
var _features_suisignPersonalMessage;
|
|
169
|
+
const signMessageMethod = (_features_suisignPersonalMessage = features['sui:signPersonalMessage']) == null ? void 0 : _features_suisignPersonalMessage.signPersonalMessage;
|
|
170
|
+
core.assertDefined(signMessageMethod, 'signPersonalMessage method not found in wallet features');
|
|
171
|
+
core.assertDefined(walletAccount, 'Wallet account not found');
|
|
172
|
+
await client$1.assertWalletAccountSigningAvailability({
|
|
173
|
+
walletAccount
|
|
174
|
+
}, dynamicClient);
|
|
175
|
+
const encodedMessage = new TextEncoder().encode(message);
|
|
176
|
+
const account = await getCurrentAccount();
|
|
177
|
+
const { signature } = await signMessageMethod({
|
|
178
|
+
account,
|
|
179
|
+
message: encodedMessage
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
signature
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
const signTransaction = async ({ transaction, walletAccount })=>{
|
|
186
|
+
var _features_suisignTransaction;
|
|
187
|
+
const signTransactionMethod = (_features_suisignTransaction = features['sui:signTransaction']) == null ? void 0 : _features_suisignTransaction.signTransaction;
|
|
188
|
+
core.assertDefined(signTransactionMethod, 'signTransaction method not found in wallet features');
|
|
189
|
+
await client$1.assertWalletAccountSigningAvailability({
|
|
190
|
+
walletAccount
|
|
191
|
+
}, dynamicClient);
|
|
192
|
+
const account = await getCurrentAccount();
|
|
193
|
+
return signTransactionMethod({
|
|
194
|
+
account,
|
|
195
|
+
chain: account.chains[0],
|
|
196
|
+
transaction
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
/* This method is deprecated, but still required by some wallets for backwards compatibility. */ const signTransactionBlock = async ({ transactionBlock, walletAccount })=>{
|
|
200
|
+
var _features_suisignTransactionBlock;
|
|
201
|
+
const signTransactionBlockMethod = (_features_suisignTransactionBlock = features['sui:signTransactionBlock']) == null ? void 0 : _features_suisignTransactionBlock.signTransactionBlock;
|
|
202
|
+
core.assertDefined(signTransactionBlockMethod, 'signTransactionBlock method not found in wallet features');
|
|
203
|
+
await client$1.assertWalletAccountSigningAvailability({
|
|
204
|
+
walletAccount
|
|
205
|
+
}, dynamicClient);
|
|
206
|
+
const account = await getCurrentAccount();
|
|
207
|
+
return signTransactionBlockMethod({
|
|
208
|
+
account,
|
|
209
|
+
chain: account.chains[0],
|
|
210
|
+
transactionBlock
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
const switchActiveNetwork = async ({ networkId })=>core.switchActiveNetworkInLastKnownRegistry({
|
|
214
|
+
client: dynamicClient,
|
|
215
|
+
networkId,
|
|
216
|
+
walletProviderKey: key
|
|
217
|
+
});
|
|
218
|
+
const { getEventEmitter, cleanupEventEmitter } = core.createWalletProviderEventEmitter({
|
|
219
|
+
removeEventListeners: ({ setupReturnValue })=>{
|
|
220
|
+
core.assertDefined(setupReturnValue, 'Setup return value not defined');
|
|
221
|
+
setupReturnValue();
|
|
222
|
+
},
|
|
223
|
+
setupEventListeners: ({ handleAccountsChanged })=>{
|
|
224
|
+
const eventsFeature = features['standard:events'];
|
|
225
|
+
return eventsFeature.on('change', ({ accounts })=>{
|
|
226
|
+
var _accounts_map;
|
|
227
|
+
handleAccountsChanged({
|
|
228
|
+
addresses: (_accounts_map = accounts == null ? void 0 : accounts.map((account)=>account.address)) != null ? _accounts_map : []
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
},
|
|
232
|
+
supportedEvents: [
|
|
233
|
+
'accountsChanged'
|
|
234
|
+
]
|
|
235
|
+
});
|
|
236
|
+
const terminate = async ()=>{
|
|
237
|
+
cleanupEventEmitter();
|
|
238
|
+
};
|
|
239
|
+
const walletProvider = {
|
|
240
|
+
chain: 'SUI',
|
|
241
|
+
connect,
|
|
242
|
+
disconnect,
|
|
243
|
+
get events () {
|
|
244
|
+
return getEventEmitter();
|
|
245
|
+
},
|
|
246
|
+
getActiveNetworkId,
|
|
247
|
+
getConnectedAddresses,
|
|
248
|
+
getSuiClient,
|
|
249
|
+
groupKey: core.formatWalletProviderGroupKey(walletStandardWallet.name),
|
|
250
|
+
key,
|
|
251
|
+
metadata: {
|
|
252
|
+
displayName: walletStandardWallet.name,
|
|
253
|
+
icon: walletStandardWallet.icon
|
|
254
|
+
},
|
|
255
|
+
signAndExecuteTransaction,
|
|
256
|
+
signAndExecuteTransactionBlock,
|
|
257
|
+
signMessage,
|
|
258
|
+
signTransaction,
|
|
259
|
+
signTransactionBlock,
|
|
260
|
+
switchActiveNetwork,
|
|
261
|
+
terminate,
|
|
262
|
+
walletProviderType
|
|
263
|
+
};
|
|
264
|
+
return walletProvider;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const SUI_WALLET_STANDARD_EXTENSION_KEY = 'suiWalletStandard';
|
|
268
|
+
/**
|
|
269
|
+
* Adds the Sui Wallet Standard extension to the Dynamic client.
|
|
270
|
+
*
|
|
271
|
+
* This extension enables integration with wallets that implement the Sui Wallet Standard,
|
|
272
|
+
* automatically detecting and registering compatible wallets for use with the Dynamic SDK.
|
|
273
|
+
*
|
|
274
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
275
|
+
*/ const addSuiWalletStandardExtension = (client = core.getDefaultClient())=>{
|
|
276
|
+
if (core.hasExtension({
|
|
277
|
+
extensionKey: SUI_WALLET_STANDARD_EXTENSION_KEY
|
|
278
|
+
}, client)) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
core.registerExtension({
|
|
282
|
+
extensionKey: SUI_WALLET_STANDARD_EXTENSION_KEY
|
|
283
|
+
}, client);
|
|
284
|
+
registerSuiNetworkProviderBuilder(client);
|
|
285
|
+
const walletProviderRegistry = core.getWalletProviderRegistry(client);
|
|
286
|
+
const walletStandardWallets = walletStandard.getWallets().get().filter((wallet)=>walletStandard.isWalletWithRequiredFeatureSet(wallet, [
|
|
287
|
+
'standard:events',
|
|
288
|
+
'standard:connect',
|
|
289
|
+
'sui:signPersonalMessage'
|
|
290
|
+
]));
|
|
291
|
+
walletStandardWallets.forEach((walletStandardWallet)=>{
|
|
292
|
+
const walletProvider = createWalletProviderFromSuiStandardWallet({
|
|
293
|
+
dynamicClient: client,
|
|
294
|
+
walletStandardWallet
|
|
295
|
+
});
|
|
296
|
+
walletProviderRegistry.register({
|
|
297
|
+
priority: core.WalletProviderPriority.WALLET_SELF_ANNOUNCEMENT_STANDARD,
|
|
298
|
+
walletProvider
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
exports.addSuiWalletStandardExtension = addSuiWalletStandardExtension;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { createBaseNetworkProvider, getNetworkProviderBuilderRegistry, formatWalletProviderKey, createWalletProviderEventEmitter, assertDefined, formatWalletProviderGroupKey, switchActiveNetworkInLastKnownRegistry, getActiveNetworkIdFromLastKnownRegistry, getDefaultClient, hasExtension, registerExtension, getWalletProviderRegistry, WalletProviderPriority } from '@dynamic-labs-sdk/client/core';
|
|
2
|
+
import { getWallets, isWalletWithRequiredFeatureSet } from '@mysten/wallet-standard';
|
|
3
|
+
import { _ as _extends } from './_extends.esm.js';
|
|
4
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
5
|
+
import { MIST_PER_SUI } from '@mysten/sui/utils';
|
|
6
|
+
import { assertWalletAccountSigningAvailability, getActiveNetworkData } from '@dynamic-labs-sdk/client';
|
|
7
|
+
import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
8
|
+
|
|
9
|
+
const fetchSuiBalance = async ({ address, rpcUrl })=>{
|
|
10
|
+
// Create a SuiClient using the provided RPC URL.
|
|
11
|
+
const suiClient = new SuiClient({
|
|
12
|
+
url: rpcUrl
|
|
13
|
+
});
|
|
14
|
+
const balanceInMist = await suiClient.getBalance({
|
|
15
|
+
owner: address
|
|
16
|
+
});
|
|
17
|
+
// Balance comes back as MIST, 1 SUI = 1e9 MIST
|
|
18
|
+
const balance = Number(balanceInMist.totalBalance) / Number(MIST_PER_SUI);
|
|
19
|
+
if (Number.isNaN(balance)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return balance.toString();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const createSuiNetworkProvider = (networkData)=>_extends({}, createBaseNetworkProvider('SUI', networkData), {
|
|
26
|
+
getBalance: async ({ address })=>({
|
|
27
|
+
balance: await fetchSuiBalance({
|
|
28
|
+
address,
|
|
29
|
+
rpcUrl: networkData.rpcUrls.http[0]
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const registerSuiNetworkProviderBuilder = (client)=>{
|
|
35
|
+
const networkProviderBuilderRegistry = getNetworkProviderBuilderRegistry(client);
|
|
36
|
+
/**
|
|
37
|
+
* If the Sui network provider builder is already registered, return.
|
|
38
|
+
*/ if (networkProviderBuilderRegistry.get().get('SUI')) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
networkProviderBuilderRegistry.register({
|
|
42
|
+
builder: createSuiNetworkProvider,
|
|
43
|
+
chain: 'SUI'
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const createWalletProviderFromSuiStandardWallet = ({ dynamicClient, walletStandardWallet })=>{
|
|
48
|
+
const features = walletStandardWallet.features;
|
|
49
|
+
const walletProviderType = WalletProviderEnum.BrowserExtension;
|
|
50
|
+
const key = formatWalletProviderKey({
|
|
51
|
+
chain: 'SUI',
|
|
52
|
+
displayName: walletStandardWallet.name,
|
|
53
|
+
walletProviderType
|
|
54
|
+
});
|
|
55
|
+
const runConnectFeature = async ({ silent = false } = {})=>{
|
|
56
|
+
var _features_standardconnect, _result_accounts;
|
|
57
|
+
const connectMethod = (_features_standardconnect = features['standard:connect']) == null ? void 0 : _features_standardconnect.connect;
|
|
58
|
+
assertDefined(connectMethod, 'connect method not found in wallet features');
|
|
59
|
+
const result = await connectMethod({
|
|
60
|
+
silent
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
addresses: (_result_accounts = result.accounts) == null ? void 0 : _result_accounts.map((account)=>{
|
|
64
|
+
var _account_publicKey;
|
|
65
|
+
return {
|
|
66
|
+
address: account.address,
|
|
67
|
+
publicKey: (_account_publicKey = account.publicKey) == null ? void 0 : _account_publicKey.toString()
|
|
68
|
+
};
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const connect = async ()=>{
|
|
73
|
+
const autoConnectedAccounts = walletStandardWallet.accounts;
|
|
74
|
+
if ((autoConnectedAccounts == null ? void 0 : autoConnectedAccounts.length) && autoConnectedAccounts[0].address) {
|
|
75
|
+
var _autoConnectedAccounts__publicKey;
|
|
76
|
+
return {
|
|
77
|
+
addresses: [
|
|
78
|
+
{
|
|
79
|
+
address: autoConnectedAccounts[0].address,
|
|
80
|
+
publicKey: (_autoConnectedAccounts__publicKey = autoConnectedAccounts[0].publicKey) == null ? void 0 : _autoConnectedAccounts__publicKey.toString()
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return runConnectFeature();
|
|
86
|
+
};
|
|
87
|
+
const disconnect = async ()=>{
|
|
88
|
+
var _features_standarddisconnect;
|
|
89
|
+
const disconnectMethod = (_features_standarddisconnect = features['standard:disconnect']) == null ? void 0 : _features_standarddisconnect.disconnect;
|
|
90
|
+
assertDefined(disconnectMethod, 'disconnect method not found in wallet features');
|
|
91
|
+
await disconnectMethod();
|
|
92
|
+
};
|
|
93
|
+
const getActiveNetworkId = async ()=>getActiveNetworkIdFromLastKnownRegistry({
|
|
94
|
+
client: dynamicClient,
|
|
95
|
+
walletProviderKey: key
|
|
96
|
+
});
|
|
97
|
+
const getCurrentAccount = async ()=>{
|
|
98
|
+
var _walletStandardWallet_accounts;
|
|
99
|
+
if (!isConnected()) {
|
|
100
|
+
await runConnectFeature({
|
|
101
|
+
silent: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const account = (_walletStandardWallet_accounts = walletStandardWallet.accounts) == null ? void 0 : _walletStandardWallet_accounts[0];
|
|
105
|
+
assertDefined(account, 'No connected accounts found');
|
|
106
|
+
return account;
|
|
107
|
+
};
|
|
108
|
+
const getSuiClient = async ({ walletAccount })=>{
|
|
109
|
+
var _activeNetworkData_networkData;
|
|
110
|
+
const activeNetworkData = await getActiveNetworkData({
|
|
111
|
+
walletAccount
|
|
112
|
+
}, dynamicClient);
|
|
113
|
+
assertDefined(activeNetworkData, 'No active network data found');
|
|
114
|
+
const url = (_activeNetworkData_networkData = activeNetworkData.networkData) == null ? void 0 : _activeNetworkData_networkData.rpcUrls.http[0];
|
|
115
|
+
assertDefined(url, 'No RPC URL found for active network');
|
|
116
|
+
const client = new SuiClient({
|
|
117
|
+
url
|
|
118
|
+
});
|
|
119
|
+
return client;
|
|
120
|
+
};
|
|
121
|
+
const isConnected = ()=>{
|
|
122
|
+
var _walletStandardWallet_accounts;
|
|
123
|
+
return ((_walletStandardWallet_accounts = walletStandardWallet.accounts) == null ? void 0 : _walletStandardWallet_accounts.length) > 0;
|
|
124
|
+
};
|
|
125
|
+
const getConnectedAddresses = async ()=>{
|
|
126
|
+
if (!isConnected()) {
|
|
127
|
+
await runConnectFeature({
|
|
128
|
+
silent: true
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
addresses: walletStandardWallet.accounts.map((account)=>account.address)
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
const signAndExecuteTransaction = async ({ transaction, walletAccount })=>{
|
|
136
|
+
var _features_suisignAndExecuteTransaction;
|
|
137
|
+
await assertWalletAccountSigningAvailability({
|
|
138
|
+
walletAccount
|
|
139
|
+
}, dynamicClient);
|
|
140
|
+
const signAndExecuteTransactionMethod = (_features_suisignAndExecuteTransaction = features['sui:signAndExecuteTransaction']) == null ? void 0 : _features_suisignAndExecuteTransaction.signAndExecuteTransaction;
|
|
141
|
+
assertDefined(signAndExecuteTransactionMethod, 'signAndExecuteTransaction method not found in wallet features');
|
|
142
|
+
const account = await getCurrentAccount();
|
|
143
|
+
return signAndExecuteTransactionMethod({
|
|
144
|
+
account,
|
|
145
|
+
chain: account.chains[0],
|
|
146
|
+
transaction
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
/* This method is deprecated, but still required by some wallets for backwards compatibility. */ const signAndExecuteTransactionBlock = async ({ options, requestType, transactionBlock, walletAccount })=>{
|
|
150
|
+
var _features_suisignAndExecuteTransactionBlock;
|
|
151
|
+
await assertWalletAccountSigningAvailability({
|
|
152
|
+
walletAccount
|
|
153
|
+
}, dynamicClient);
|
|
154
|
+
const signAndExecuteTransactionBlockMethod = (_features_suisignAndExecuteTransactionBlock = features['sui:signAndExecuteTransactionBlock']) == null ? void 0 : _features_suisignAndExecuteTransactionBlock.signAndExecuteTransactionBlock;
|
|
155
|
+
assertDefined(signAndExecuteTransactionBlockMethod, 'signAndExecuteTransactionBlock method not found in wallet features');
|
|
156
|
+
const account = await getCurrentAccount();
|
|
157
|
+
return signAndExecuteTransactionBlockMethod({
|
|
158
|
+
account,
|
|
159
|
+
chain: account.chains[0],
|
|
160
|
+
options,
|
|
161
|
+
requestType,
|
|
162
|
+
transactionBlock
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
const signMessage = async ({ message, walletAccount })=>{
|
|
166
|
+
var _features_suisignPersonalMessage;
|
|
167
|
+
const signMessageMethod = (_features_suisignPersonalMessage = features['sui:signPersonalMessage']) == null ? void 0 : _features_suisignPersonalMessage.signPersonalMessage;
|
|
168
|
+
assertDefined(signMessageMethod, 'signPersonalMessage method not found in wallet features');
|
|
169
|
+
assertDefined(walletAccount, 'Wallet account not found');
|
|
170
|
+
await assertWalletAccountSigningAvailability({
|
|
171
|
+
walletAccount
|
|
172
|
+
}, dynamicClient);
|
|
173
|
+
const encodedMessage = new TextEncoder().encode(message);
|
|
174
|
+
const account = await getCurrentAccount();
|
|
175
|
+
const { signature } = await signMessageMethod({
|
|
176
|
+
account,
|
|
177
|
+
message: encodedMessage
|
|
178
|
+
});
|
|
179
|
+
return {
|
|
180
|
+
signature
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const signTransaction = async ({ transaction, walletAccount })=>{
|
|
184
|
+
var _features_suisignTransaction;
|
|
185
|
+
const signTransactionMethod = (_features_suisignTransaction = features['sui:signTransaction']) == null ? void 0 : _features_suisignTransaction.signTransaction;
|
|
186
|
+
assertDefined(signTransactionMethod, 'signTransaction method not found in wallet features');
|
|
187
|
+
await assertWalletAccountSigningAvailability({
|
|
188
|
+
walletAccount
|
|
189
|
+
}, dynamicClient);
|
|
190
|
+
const account = await getCurrentAccount();
|
|
191
|
+
return signTransactionMethod({
|
|
192
|
+
account,
|
|
193
|
+
chain: account.chains[0],
|
|
194
|
+
transaction
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
/* This method is deprecated, but still required by some wallets for backwards compatibility. */ const signTransactionBlock = async ({ transactionBlock, walletAccount })=>{
|
|
198
|
+
var _features_suisignTransactionBlock;
|
|
199
|
+
const signTransactionBlockMethod = (_features_suisignTransactionBlock = features['sui:signTransactionBlock']) == null ? void 0 : _features_suisignTransactionBlock.signTransactionBlock;
|
|
200
|
+
assertDefined(signTransactionBlockMethod, 'signTransactionBlock method not found in wallet features');
|
|
201
|
+
await assertWalletAccountSigningAvailability({
|
|
202
|
+
walletAccount
|
|
203
|
+
}, dynamicClient);
|
|
204
|
+
const account = await getCurrentAccount();
|
|
205
|
+
return signTransactionBlockMethod({
|
|
206
|
+
account,
|
|
207
|
+
chain: account.chains[0],
|
|
208
|
+
transactionBlock
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
const switchActiveNetwork = async ({ networkId })=>switchActiveNetworkInLastKnownRegistry({
|
|
212
|
+
client: dynamicClient,
|
|
213
|
+
networkId,
|
|
214
|
+
walletProviderKey: key
|
|
215
|
+
});
|
|
216
|
+
const { getEventEmitter, cleanupEventEmitter } = createWalletProviderEventEmitter({
|
|
217
|
+
removeEventListeners: ({ setupReturnValue })=>{
|
|
218
|
+
assertDefined(setupReturnValue, 'Setup return value not defined');
|
|
219
|
+
setupReturnValue();
|
|
220
|
+
},
|
|
221
|
+
setupEventListeners: ({ handleAccountsChanged })=>{
|
|
222
|
+
const eventsFeature = features['standard:events'];
|
|
223
|
+
return eventsFeature.on('change', ({ accounts })=>{
|
|
224
|
+
var _accounts_map;
|
|
225
|
+
handleAccountsChanged({
|
|
226
|
+
addresses: (_accounts_map = accounts == null ? void 0 : accounts.map((account)=>account.address)) != null ? _accounts_map : []
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
supportedEvents: [
|
|
231
|
+
'accountsChanged'
|
|
232
|
+
]
|
|
233
|
+
});
|
|
234
|
+
const terminate = async ()=>{
|
|
235
|
+
cleanupEventEmitter();
|
|
236
|
+
};
|
|
237
|
+
const walletProvider = {
|
|
238
|
+
chain: 'SUI',
|
|
239
|
+
connect,
|
|
240
|
+
disconnect,
|
|
241
|
+
get events () {
|
|
242
|
+
return getEventEmitter();
|
|
243
|
+
},
|
|
244
|
+
getActiveNetworkId,
|
|
245
|
+
getConnectedAddresses,
|
|
246
|
+
getSuiClient,
|
|
247
|
+
groupKey: formatWalletProviderGroupKey(walletStandardWallet.name),
|
|
248
|
+
key,
|
|
249
|
+
metadata: {
|
|
250
|
+
displayName: walletStandardWallet.name,
|
|
251
|
+
icon: walletStandardWallet.icon
|
|
252
|
+
},
|
|
253
|
+
signAndExecuteTransaction,
|
|
254
|
+
signAndExecuteTransactionBlock,
|
|
255
|
+
signMessage,
|
|
256
|
+
signTransaction,
|
|
257
|
+
signTransactionBlock,
|
|
258
|
+
switchActiveNetwork,
|
|
259
|
+
terminate,
|
|
260
|
+
walletProviderType
|
|
261
|
+
};
|
|
262
|
+
return walletProvider;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const SUI_WALLET_STANDARD_EXTENSION_KEY = 'suiWalletStandard';
|
|
266
|
+
/**
|
|
267
|
+
* Adds the Sui Wallet Standard extension to the Dynamic client.
|
|
268
|
+
*
|
|
269
|
+
* This extension enables integration with wallets that implement the Sui Wallet Standard,
|
|
270
|
+
* automatically detecting and registering compatible wallets for use with the Dynamic SDK.
|
|
271
|
+
*
|
|
272
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
273
|
+
*/ const addSuiWalletStandardExtension = (client = getDefaultClient())=>{
|
|
274
|
+
if (hasExtension({
|
|
275
|
+
extensionKey: SUI_WALLET_STANDARD_EXTENSION_KEY
|
|
276
|
+
}, client)) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
registerExtension({
|
|
280
|
+
extensionKey: SUI_WALLET_STANDARD_EXTENSION_KEY
|
|
281
|
+
}, client);
|
|
282
|
+
registerSuiNetworkProviderBuilder(client);
|
|
283
|
+
const walletProviderRegistry = getWalletProviderRegistry(client);
|
|
284
|
+
const walletStandardWallets = getWallets().get().filter((wallet)=>isWalletWithRequiredFeatureSet(wallet, [
|
|
285
|
+
'standard:events',
|
|
286
|
+
'standard:connect',
|
|
287
|
+
'sui:signPersonalMessage'
|
|
288
|
+
]));
|
|
289
|
+
walletStandardWallets.forEach((walletStandardWallet)=>{
|
|
290
|
+
const walletProvider = createWalletProviderFromSuiStandardWallet({
|
|
291
|
+
dynamicClient: client,
|
|
292
|
+
walletStandardWallet
|
|
293
|
+
});
|
|
294
|
+
walletProviderRegistry.register({
|
|
295
|
+
priority: WalletProviderPriority.WALLET_SELF_ANNOUNCEMENT_STANDARD,
|
|
296
|
+
walletProvider
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export { addSuiWalletStandardExtension as a };
|