@mysten/dapp-kit-core 1.0.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 +27 -0
- package/LICENSE +201 -0
- package/README.md +3 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +793 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types-x68aipir.d.mts +240 -0
- package/dist/types-x68aipir.d.mts.map +1 -0
- package/dist/web/index.d.mts +270 -0
- package/dist/web/index.d.mts.map +1 -0
- package/dist/web/index.mjs +1446 -0
- package/dist/web/index.mjs.map +1 -0
- package/package.json +83 -0
- package/src/core/actions/connect-wallet.ts +117 -0
- package/src/core/actions/disconnect-wallet.ts +43 -0
- package/src/core/actions/sign-and-execute-transaction.ts +119 -0
- package/src/core/actions/sign-personal-message.ts +42 -0
- package/src/core/actions/sign-transaction.ts +83 -0
- package/src/core/actions/switch-account.ts +32 -0
- package/src/core/actions/switch-network.ts +16 -0
- package/src/core/index.ts +119 -0
- package/src/core/initializers/autoconnect-wallet.ts +116 -0
- package/src/core/initializers/manage-connection.ts +50 -0
- package/src/core/initializers/registered-wallets.ts +68 -0
- package/src/core/initializers/sync-state-to-storage.ts +44 -0
- package/src/core/store.ts +130 -0
- package/src/core/types.ts +87 -0
- package/src/index.ts +19 -0
- package/src/types.ts +15 -0
- package/src/utils/errors.ts +29 -0
- package/src/utils/lit.ts +61 -0
- package/src/utils/name.ts +26 -0
- package/src/utils/networks.ts +35 -0
- package/src/utils/signer.ts +75 -0
- package/src/utils/storage.ts +40 -0
- package/src/utils/transaction-result.ts +50 -0
- package/src/utils/wallets.ts +82 -0
- package/src/wallets/index.ts +56 -0
- package/src/wallets/slush-web.ts +27 -0
- package/src/wallets/unsafe-burner.ts +165 -0
- package/src/web/dapp-kit-connect-button.stories.ts +88 -0
- package/src/web/dapp-kit-connect-button.ts +114 -0
- package/src/web/dapp-kit-connect-modal.stories.ts +62 -0
- package/src/web/dapp-kit-connect-modal.styles.ts +48 -0
- package/src/web/dapp-kit-connect-modal.ts +244 -0
- package/src/web/index.ts +12 -0
- package/src/web/internal/base-modal.ts +149 -0
- package/src/web/internal/button.styles.ts +54 -0
- package/src/web/internal/button.ts +49 -0
- package/src/web/internal/connected-account-menu-item.ts +116 -0
- package/src/web/internal/connected-account-menu.styles.ts +217 -0
- package/src/web/internal/connected-account-menu.ts +193 -0
- package/src/web/internal/connection-status.styles.ts +47 -0
- package/src/web/internal/connection-status.ts +31 -0
- package/src/web/internal/icons/arrow-right-up-icon.ts +19 -0
- package/src/web/internal/icons/back-icon.ts +19 -0
- package/src/web/internal/icons/chevron-down-icon.ts +18 -0
- package/src/web/internal/icons/circle-check-icon.ts +19 -0
- package/src/web/internal/icons/close-icon.ts +18 -0
- package/src/web/internal/icons/copy-icon.ts +18 -0
- package/src/web/internal/icons/download-icon.ts +24 -0
- package/src/web/internal/icons/plus-icon.ts +18 -0
- package/src/web/internal/icons/unlink-icon.ts +18 -0
- package/src/web/internal/wallet-list-item.styles.ts +41 -0
- package/src/web/internal/wallet-list-item.ts +45 -0
- package/src/web/internal/wallet-list.styles.ts +49 -0
- package/src/web/internal/wallet-list.ts +46 -0
- package/src/web/styles/icon-button.ts +28 -0
- package/src/web/styles/index.ts +7 -0
- package/src/web/styles/reset.ts +45 -0
- package/src/web/styles/theme.ts +56 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,793 @@
|
|
|
1
|
+
import { atom, computed, map, onMount, readonlyType, task } from "nanostores";
|
|
2
|
+
import { ReadonlyWalletAccount, StandardConnect, StandardDisconnect, StandardEvents, SuiSignAndExecuteTransaction, SuiSignAndExecuteTransactionBlock, SuiSignPersonalMessage, SuiSignTransaction, SuiSignTransactionBlock, WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED, WalletStandardError, getWallets } from "@mysten/wallet-standard";
|
|
3
|
+
import { getWalletAccountFeature, getWalletFeature, uiWalletAccountBelongsToUiWallet, uiWalletAccountsAreSame } from "@wallet-standard/ui";
|
|
4
|
+
import { getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, getOrCreateUiWalletForStandardWallet_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } from "@wallet-standard/ui-registry";
|
|
5
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
6
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
7
|
+
import { fromBase64, toBase64 } from "@mysten/utils";
|
|
8
|
+
import { extractStatusFromEffectsBcs, parseTransactionBcs, parseTransactionEffectsBcs } from "@mysten/sui/client";
|
|
9
|
+
import { registerSlushWallet } from "@mysten/slush-wallet";
|
|
10
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
11
|
+
|
|
12
|
+
//#region src/utils/errors.ts
|
|
13
|
+
var DAppKitError = class extends Error {};
|
|
14
|
+
/**
|
|
15
|
+
* Thown when someone attempts to perform an action that requires an active wallet connection.
|
|
16
|
+
*/
|
|
17
|
+
var WalletNotConnectedError = class extends DAppKitError {};
|
|
18
|
+
/**
|
|
19
|
+
* Thown when an account tries to invoke a feature on a chain that doesn't support it.
|
|
20
|
+
*/
|
|
21
|
+
var ChainNotSupportedError = class extends DAppKitError {};
|
|
22
|
+
/**
|
|
23
|
+
* Thown when an account tries to invoke a feature that it doesn't support.
|
|
24
|
+
*/
|
|
25
|
+
var FeatureNotSupportedError = class extends DAppKitError {};
|
|
26
|
+
/**
|
|
27
|
+
* Thown when a wallet is connected but no accounts are authorized.
|
|
28
|
+
*/
|
|
29
|
+
var WalletNoAccountsConnectedError = class extends DAppKitError {};
|
|
30
|
+
/**
|
|
31
|
+
* Thown when an account can't be found for a specific wallet.
|
|
32
|
+
*/
|
|
33
|
+
var WalletAccountNotFoundError = class extends DAppKitError {};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/utils/networks.ts
|
|
37
|
+
function getChain(network) {
|
|
38
|
+
return `sui:${network}`;
|
|
39
|
+
}
|
|
40
|
+
function createNetworkConfig(networks, createClient) {
|
|
41
|
+
if (networks.length === 0) throw new DAppKitError("You must specify at least one Sui network for your application.");
|
|
42
|
+
const networkConfig = /* @__PURE__ */ new Map();
|
|
43
|
+
function getClient(network) {
|
|
44
|
+
if (networkConfig.has(network)) return networkConfig.get(network);
|
|
45
|
+
const client = createClient(network);
|
|
46
|
+
networkConfig.set(network, client);
|
|
47
|
+
return client;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
networkConfig: Object.freeze(networkConfig),
|
|
51
|
+
getClient
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/utils/wallets.ts
|
|
57
|
+
const requiredWalletFeatures = [StandardConnect, StandardEvents];
|
|
58
|
+
const signingFeatures = [SuiSignTransaction, SuiSignTransactionBlock];
|
|
59
|
+
function getAssociatedWalletOrThrow(account, wallets) {
|
|
60
|
+
const wallet = wallets.find((wallet$1) => uiWalletAccountBelongsToUiWallet(account, wallet$1));
|
|
61
|
+
if (!wallet) throw new DAppKitError(`Wallet not found for account ${account.address}.`);
|
|
62
|
+
return wallet;
|
|
63
|
+
}
|
|
64
|
+
function getWalletUniqueIdentifier(walletHandle) {
|
|
65
|
+
const underlyingWallet = getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(walletHandle);
|
|
66
|
+
return underlyingWallet.id ?? underlyingWallet.name;
|
|
67
|
+
}
|
|
68
|
+
function getAccountFeature({ account, featureName, chain }) {
|
|
69
|
+
if (!account.chains.includes(chain)) {
|
|
70
|
+
const cause = new WalletStandardError(WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED, {
|
|
71
|
+
chain,
|
|
72
|
+
featureName,
|
|
73
|
+
supportedChains: [...account.chains],
|
|
74
|
+
supportedFeatures: [...account.features],
|
|
75
|
+
address: account.address
|
|
76
|
+
});
|
|
77
|
+
throw new ChainNotSupportedError(`The account ${cause.context.address} does not support the chain "${cause.context.chain}".`, { cause });
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
return getWalletAccountFeature(account, featureName);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new FeatureNotSupportedError(`The account ${account.address} does not support the feature "${featureName}".`, { cause: error });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function tryGetAccountFeature(...args) {
|
|
86
|
+
try {
|
|
87
|
+
return getAccountFeature(...args);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (error instanceof FeatureNotSupportedError) return null;
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/core/store.ts
|
|
96
|
+
function createStores({ defaultNetwork, getClient }) {
|
|
97
|
+
const $baseConnection = map({
|
|
98
|
+
status: "disconnected",
|
|
99
|
+
currentAccount: null
|
|
100
|
+
});
|
|
101
|
+
const $currentNetwork = atom(defaultNetwork);
|
|
102
|
+
const $registeredWallets = atom([]);
|
|
103
|
+
const $compatibleWallets = computed([$registeredWallets, $currentNetwork], (wallets, currentNetwork) => {
|
|
104
|
+
return wallets.filter((wallet) => {
|
|
105
|
+
const areChainsCompatible = wallet.chains.some((chain) => getChain(currentNetwork) === chain);
|
|
106
|
+
const hasRequiredFeatures = requiredWalletFeatures.every((featureName) => wallet.features.includes(featureName));
|
|
107
|
+
const canSignTransactions = signingFeatures.some((featureName) => wallet.features.includes(featureName));
|
|
108
|
+
return areChainsCompatible && hasRequiredFeatures && canSignTransactions;
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
$currentNetwork,
|
|
113
|
+
$registeredWallets,
|
|
114
|
+
$compatibleWallets,
|
|
115
|
+
$baseConnection,
|
|
116
|
+
$currentClient: computed($currentNetwork, getClient),
|
|
117
|
+
$connection: computed([$baseConnection, $compatibleWallets], (connection, wallets) => {
|
|
118
|
+
switch (connection.status) {
|
|
119
|
+
case "connected": return {
|
|
120
|
+
wallet: getAssociatedWalletOrThrow(connection.currentAccount, wallets),
|
|
121
|
+
account: connection.currentAccount,
|
|
122
|
+
status: connection.status,
|
|
123
|
+
supportedIntents: connection.supportedIntents,
|
|
124
|
+
isConnected: true,
|
|
125
|
+
isConnecting: false,
|
|
126
|
+
isReconnecting: false,
|
|
127
|
+
isDisconnected: false
|
|
128
|
+
};
|
|
129
|
+
case "connecting": return {
|
|
130
|
+
wallet: null,
|
|
131
|
+
account: connection.currentAccount,
|
|
132
|
+
status: connection.status,
|
|
133
|
+
supportedIntents: [],
|
|
134
|
+
isConnected: false,
|
|
135
|
+
isConnecting: true,
|
|
136
|
+
isReconnecting: false,
|
|
137
|
+
isDisconnected: false
|
|
138
|
+
};
|
|
139
|
+
case "reconnecting": return {
|
|
140
|
+
wallet: getAssociatedWalletOrThrow(connection.currentAccount, wallets),
|
|
141
|
+
account: connection.currentAccount,
|
|
142
|
+
status: connection.status,
|
|
143
|
+
supportedIntents: connection.supportedIntents,
|
|
144
|
+
isConnected: false,
|
|
145
|
+
isConnecting: false,
|
|
146
|
+
isReconnecting: true,
|
|
147
|
+
isDisconnected: false
|
|
148
|
+
};
|
|
149
|
+
case "disconnected": return {
|
|
150
|
+
wallet: null,
|
|
151
|
+
account: connection.currentAccount,
|
|
152
|
+
status: connection.status,
|
|
153
|
+
supportedIntents: [],
|
|
154
|
+
isConnected: false,
|
|
155
|
+
isConnecting: false,
|
|
156
|
+
isReconnecting: false,
|
|
157
|
+
isDisconnected: true
|
|
158
|
+
};
|
|
159
|
+
default: throw new Error(`Encountered unknown connection status: ${connection}`);
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/core/initializers/registered-wallets.ts
|
|
167
|
+
/**
|
|
168
|
+
* Handles updating the store in response to wallets being added, removed, and their properties changing.
|
|
169
|
+
*/
|
|
170
|
+
function syncRegisteredWallets({ $registeredWallets }) {
|
|
171
|
+
onMount($registeredWallets, () => {
|
|
172
|
+
const walletsApi = getWallets();
|
|
173
|
+
const unsubscribeCallbacksByWallet = /* @__PURE__ */ new Map();
|
|
174
|
+
const onWalletsChanged = () => {
|
|
175
|
+
const wallets = walletsApi.get();
|
|
176
|
+
$registeredWallets.set(wallets.map(getOrCreateUiWalletForStandardWallet_DO_NOT_USE_OR_YOU_WILL_BE_FIRED));
|
|
177
|
+
};
|
|
178
|
+
const subscribeToWalletEvents = (wallet) => {
|
|
179
|
+
const unsubscribeFromChange = wallet.features[StandardEvents].on("change", () => {
|
|
180
|
+
onWalletsChanged();
|
|
181
|
+
});
|
|
182
|
+
unsubscribeCallbacksByWallet.set(wallet, unsubscribeFromChange);
|
|
183
|
+
};
|
|
184
|
+
const unsubscribeFromRegister = walletsApi.on("register", (...addedWallets) => {
|
|
185
|
+
addedWallets.filter(hasStandardEvents).forEach(subscribeToWalletEvents);
|
|
186
|
+
onWalletsChanged();
|
|
187
|
+
});
|
|
188
|
+
const unsubscribeFromUnregister = walletsApi.on("unregister", (...removedWallets) => {
|
|
189
|
+
removedWallets.filter(hasStandardEvents).forEach((wallet) => {
|
|
190
|
+
const unsubscribeFromChange = unsubscribeCallbacksByWallet.get(wallet);
|
|
191
|
+
if (unsubscribeFromChange) {
|
|
192
|
+
unsubscribeCallbacksByWallet.delete(wallet);
|
|
193
|
+
unsubscribeFromChange();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
onWalletsChanged();
|
|
197
|
+
});
|
|
198
|
+
walletsApi.get().filter(hasStandardEvents).forEach(subscribeToWalletEvents);
|
|
199
|
+
onWalletsChanged();
|
|
200
|
+
return () => {
|
|
201
|
+
unsubscribeFromRegister();
|
|
202
|
+
unsubscribeFromUnregister();
|
|
203
|
+
unsubscribeCallbacksByWallet.forEach((unsubscribe) => unsubscribe());
|
|
204
|
+
unsubscribeCallbacksByWallet.clear();
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function hasStandardEvents(wallet) {
|
|
209
|
+
return StandardEvents in wallet.features;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/core/actions/connect-wallet.ts
|
|
214
|
+
function connectWalletCreator({ $baseConnection }, supportedNetworks) {
|
|
215
|
+
/**
|
|
216
|
+
* Prompts the specified wallet to connect and authorize new accounts for the current domain.
|
|
217
|
+
*/
|
|
218
|
+
return async function connectWallet({ wallet, account, ...standardConnectArgs }) {
|
|
219
|
+
return await task(async () => {
|
|
220
|
+
const isAlreadyConnected = $baseConnection.get().status === "connected";
|
|
221
|
+
try {
|
|
222
|
+
$baseConnection.setKey("status", isAlreadyConnected ? "reconnecting" : "connecting");
|
|
223
|
+
const { accounts: suiAccounts, supportedIntents } = await internalConnectWallet(wallet, supportedNetworks, standardConnectArgs);
|
|
224
|
+
if (!isAlreadyConnected && suiAccounts.length === 0) throw new WalletNoAccountsConnectedError("No accounts were authorized.");
|
|
225
|
+
if (account && !uiWalletAccountBelongsToUiWallet(account, wallet)) throw new WalletAccountNotFoundError(`No account with address ${account.address} is authorized for ${wallet.name}.`);
|
|
226
|
+
$baseConnection.set({
|
|
227
|
+
status: "connected",
|
|
228
|
+
currentAccount: account ?? suiAccounts[0],
|
|
229
|
+
supportedIntents: supportedIntents ?? []
|
|
230
|
+
});
|
|
231
|
+
return { accounts: suiAccounts };
|
|
232
|
+
} catch (error) {
|
|
233
|
+
$baseConnection.setKey("status", isAlreadyConnected ? "connected" : "disconnected");
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
async function internalConnectWallet(wallet, supportedNetworks, args) {
|
|
240
|
+
const { connect } = getWalletFeature(wallet, StandardConnect);
|
|
241
|
+
const result = await connect(args);
|
|
242
|
+
const underlyingWallet = getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(wallet);
|
|
243
|
+
const supportedChains = supportedNetworks.map(getChain);
|
|
244
|
+
const supportedIntents = result.supportedIntents ?? await getSupportedIntentsFromFeature(wallet);
|
|
245
|
+
return {
|
|
246
|
+
accounts: result.accounts.filter((account) => account.chains.some((chain) => supportedChains.includes(chain))).map(getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.bind(null, underlyingWallet)),
|
|
247
|
+
supportedIntents
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
async function getSupportedIntentsFromFeature(wallet) {
|
|
251
|
+
if (!wallet.features.includes("sui:getCapabilities")) return [];
|
|
252
|
+
return (await getWalletFeature(wallet, "sui:getCapabilities")?.getCapabilities())?.supportedIntents ?? [];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/core/initializers/autoconnect-wallet.ts
|
|
257
|
+
/**
|
|
258
|
+
* Attempts to connect to a previously authorized wallet account on mount and when new wallets are registered.
|
|
259
|
+
*/
|
|
260
|
+
function autoConnectWallet({ networks, stores: { $baseConnection, $compatibleWallets }, storage, storageKey }) {
|
|
261
|
+
onMount($compatibleWallets, () => {
|
|
262
|
+
return $compatibleWallets.listen(async (wallets, oldWallets) => {
|
|
263
|
+
if (oldWallets && oldWallets.length > wallets.length) return;
|
|
264
|
+
if ($baseConnection.get().status !== "disconnected") return;
|
|
265
|
+
const savedWalletAccount = await task(() => {
|
|
266
|
+
return getSavedWalletAccount({
|
|
267
|
+
networks,
|
|
268
|
+
storage,
|
|
269
|
+
storageKey,
|
|
270
|
+
wallets
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
if (savedWalletAccount) $baseConnection.set({
|
|
274
|
+
status: "connected",
|
|
275
|
+
currentAccount: savedWalletAccount.account,
|
|
276
|
+
supportedIntents: savedWalletAccount.supportedIntents
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
async function getSavedWalletAccount({ networks, storage, storageKey, wallets }) {
|
|
282
|
+
const savedWalletIdAndAddress = await storage.getItem(storageKey);
|
|
283
|
+
if (!savedWalletIdAndAddress) return null;
|
|
284
|
+
const [savedWalletId, savedAccountAddress, savedIntents] = savedWalletIdAndAddress.split(":");
|
|
285
|
+
if (!savedWalletId || !savedAccountAddress) return null;
|
|
286
|
+
const targetWallet = wallets.find((wallet) => getWalletUniqueIdentifier(wallet) === savedWalletId);
|
|
287
|
+
if (!targetWallet) return null;
|
|
288
|
+
const existingAccount = targetWallet.accounts.find((account$1) => account$1.address === savedAccountAddress);
|
|
289
|
+
if (existingAccount) return {
|
|
290
|
+
account: existingAccount,
|
|
291
|
+
supportedIntents: (savedIntents ? savedIntents.split(",") : null) ?? await getSupportedIntentsFromFeature(targetWallet)
|
|
292
|
+
};
|
|
293
|
+
const { accounts: alreadyAuthorizedAccounts, supportedIntents } = await internalConnectWallet(targetWallet, networks, { silent: true });
|
|
294
|
+
const account = alreadyAuthorizedAccounts.find((account$1) => account$1.address === savedAccountAddress);
|
|
295
|
+
return account ? {
|
|
296
|
+
account,
|
|
297
|
+
supportedIntents
|
|
298
|
+
} : null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/utils/storage.ts
|
|
303
|
+
const DEFAULT_STORAGE_KEY = "mysten-dapp-kit:selected-wallet-and-address";
|
|
304
|
+
function getDefaultStorage() {
|
|
305
|
+
return isLocalStorageAvailable() ? localStorage : createInMemoryStorage();
|
|
306
|
+
}
|
|
307
|
+
function createInMemoryStorage() {
|
|
308
|
+
const store = /* @__PURE__ */ new Map();
|
|
309
|
+
return {
|
|
310
|
+
getItem(key) {
|
|
311
|
+
return store.get(key) ?? null;
|
|
312
|
+
},
|
|
313
|
+
setItem(key, value) {
|
|
314
|
+
store.set(key, value);
|
|
315
|
+
},
|
|
316
|
+
removeItem(key) {
|
|
317
|
+
store.delete(key);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function isLocalStorageAvailable() {
|
|
322
|
+
try {
|
|
323
|
+
const testKey = "__storage_test__";
|
|
324
|
+
localStorage.setItem(testKey, "test");
|
|
325
|
+
localStorage.removeItem(testKey);
|
|
326
|
+
return true;
|
|
327
|
+
} catch {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/core/initializers/sync-state-to-storage.ts
|
|
334
|
+
/**
|
|
335
|
+
* Syncs the most recently connected wallet name and address to storage.
|
|
336
|
+
*/
|
|
337
|
+
function syncStateToStorage({ stores: { $connection }, storage, storageKey }) {
|
|
338
|
+
onMount($connection, () => {
|
|
339
|
+
return $connection.listen((connection, oldConnection) => {
|
|
340
|
+
if (!oldConnection || oldConnection.status === connection.status) return;
|
|
341
|
+
if (connection.account) storage.setItem(storageKey, getSavedAccountStorageKey(connection.account, connection.supportedIntents));
|
|
342
|
+
else storage.removeItem(storageKey);
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function getSavedAccountStorageKey(account, supportedIntents) {
|
|
347
|
+
return `${getWalletUniqueIdentifier(account).replace(":", "_")}:${account.address}:${supportedIntents.join(",")}:`;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/core/initializers/manage-connection.ts
|
|
352
|
+
/**
|
|
353
|
+
* Handles updating the connection state in response to wallets and their properties changing.
|
|
354
|
+
*/
|
|
355
|
+
function manageWalletConnection({ $compatibleWallets, $baseConnection }) {
|
|
356
|
+
onMount($compatibleWallets, () => {
|
|
357
|
+
return $compatibleWallets.listen(async (wallets) => {
|
|
358
|
+
const connection = $baseConnection.get();
|
|
359
|
+
if (connection.status !== "connected") return;
|
|
360
|
+
const resolvedAccount = resolveWalletAccount(connection.currentAccount, wallets);
|
|
361
|
+
if (resolvedAccount) $baseConnection.setKey("currentAccount", resolvedAccount);
|
|
362
|
+
else $baseConnection.set({
|
|
363
|
+
status: "disconnected",
|
|
364
|
+
currentAccount: null
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
function resolveWalletAccount(currentAccount, wallets) {
|
|
370
|
+
for (const wallet of wallets) {
|
|
371
|
+
for (const walletAccount of wallet.accounts) if (uiWalletAccountsAreSame(currentAccount, walletAccount)) return walletAccount;
|
|
372
|
+
if (uiWalletAccountBelongsToUiWallet(currentAccount, wallet) && wallet.accounts[0]) return wallet.accounts[0];
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/core/actions/switch-network.ts
|
|
379
|
+
function switchNetworkCreator({ $currentNetwork }) {
|
|
380
|
+
/**
|
|
381
|
+
* Switches the currently selected network to the specified network.
|
|
382
|
+
*/
|
|
383
|
+
return function switchNetwork(network) {
|
|
384
|
+
$currentNetwork.set(network);
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/core/actions/disconnect-wallet.ts
|
|
390
|
+
function disconnectWalletCreator({ $baseConnection, $connection }) {
|
|
391
|
+
/**
|
|
392
|
+
* Disconnects the current wallet from the application and prompts the current wallet
|
|
393
|
+
* to deauthorize accounts from the current domain depending on the wallet's implemetation
|
|
394
|
+
* of `standard:disconnect`.
|
|
395
|
+
*/
|
|
396
|
+
return async function disconnectWallet(...standardDisconnectArgs) {
|
|
397
|
+
return await task(async () => {
|
|
398
|
+
const { wallet } = $connection.get();
|
|
399
|
+
if (!wallet) throw new WalletNotConnectedError("No wallet is connected.");
|
|
400
|
+
try {
|
|
401
|
+
const { disconnect } = getWalletFeature(wallet, StandardDisconnect);
|
|
402
|
+
await disconnect(...standardDisconnectArgs);
|
|
403
|
+
} catch (error) {
|
|
404
|
+
console.warn("Failed to disconnect the current wallet from the application.", error);
|
|
405
|
+
} finally {
|
|
406
|
+
$baseConnection.set({
|
|
407
|
+
status: "disconnected",
|
|
408
|
+
currentAccount: null
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/core/actions/switch-account.ts
|
|
417
|
+
function switchAccountCreator({ $baseConnection, $connection }) {
|
|
418
|
+
/**
|
|
419
|
+
* Switches the currently selected account to the specified account.
|
|
420
|
+
*/
|
|
421
|
+
return function switchAccount({ account }) {
|
|
422
|
+
const { wallet } = $connection.get();
|
|
423
|
+
if (!wallet) throw new WalletNotConnectedError("No wallet is connected.");
|
|
424
|
+
if (!uiWalletAccountBelongsToUiWallet(account, wallet)) throw new WalletAccountNotFoundError(`No account with address ${account.address} is connected to ${wallet.name}.`);
|
|
425
|
+
$baseConnection.setKey("currentAccount", account);
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/core/actions/sign-personal-message.ts
|
|
431
|
+
function signPersonalMessageCreator({ $connection, $currentNetwork }) {
|
|
432
|
+
/**
|
|
433
|
+
* Prompts the specified wallet account to sign a personal message.
|
|
434
|
+
*/
|
|
435
|
+
return async function signPersonalMessage({ ...standardArgs }) {
|
|
436
|
+
const { account } = $connection.get();
|
|
437
|
+
if (!account) throw new WalletNotConnectedError("No wallet is connected.");
|
|
438
|
+
const chain = getChain($currentNetwork.get());
|
|
439
|
+
return await getAccountFeature({
|
|
440
|
+
account,
|
|
441
|
+
chain,
|
|
442
|
+
featureName: SuiSignPersonalMessage
|
|
443
|
+
}).signPersonalMessage({
|
|
444
|
+
...standardArgs,
|
|
445
|
+
account: getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(account),
|
|
446
|
+
chain
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/utils/transaction-result.ts
|
|
453
|
+
function buildTransactionResult(digest, signature, transactionBytes, effectsBytes) {
|
|
454
|
+
const status = extractStatusFromEffectsBcs(effectsBytes);
|
|
455
|
+
let effects = null;
|
|
456
|
+
try {
|
|
457
|
+
effects = parseTransactionEffectsBcs(effectsBytes);
|
|
458
|
+
} catch {
|
|
459
|
+
console.warn("Parsing transaction effects failed, you may need to update the SDK to pickup the latest bcs types");
|
|
460
|
+
}
|
|
461
|
+
const txResult = {
|
|
462
|
+
digest,
|
|
463
|
+
signatures: [signature],
|
|
464
|
+
epoch: null,
|
|
465
|
+
status,
|
|
466
|
+
effects,
|
|
467
|
+
transaction: parseTransactionBcs(transactionBytes),
|
|
468
|
+
balanceChanges: void 0,
|
|
469
|
+
events: void 0,
|
|
470
|
+
objectTypes: void 0,
|
|
471
|
+
bcs: transactionBytes
|
|
472
|
+
};
|
|
473
|
+
return status.success ? {
|
|
474
|
+
$kind: "Transaction",
|
|
475
|
+
Transaction: txResult
|
|
476
|
+
} : {
|
|
477
|
+
$kind: "FailedTransaction",
|
|
478
|
+
FailedTransaction: txResult
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/core/actions/sign-and-execute-transaction.ts
|
|
484
|
+
function signAndExecuteTransactionCreator({ $connection, $currentClient }) {
|
|
485
|
+
/**
|
|
486
|
+
* Prompts the specified wallet account to sign and execute a transaction.
|
|
487
|
+
*/
|
|
488
|
+
return async function signAndExecuteTransaction({ transaction, ...standardArgs }) {
|
|
489
|
+
const { account, supportedIntents } = $connection.get();
|
|
490
|
+
if (!account) throw new WalletNotConnectedError("No wallet is connected.");
|
|
491
|
+
const underlyingAccount = getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(account);
|
|
492
|
+
const suiClient = $currentClient.get();
|
|
493
|
+
const chain = getChain(suiClient.network);
|
|
494
|
+
const transactionWrapper = { toJSON: async () => {
|
|
495
|
+
if (typeof transaction === "string") return transaction;
|
|
496
|
+
transaction.setSenderIfNotSet(account.address);
|
|
497
|
+
return await transaction.toJSON({
|
|
498
|
+
client: suiClient,
|
|
499
|
+
supportedIntents
|
|
500
|
+
});
|
|
501
|
+
} };
|
|
502
|
+
const signAndExecuteTransactionFeature = tryGetAccountFeature({
|
|
503
|
+
account,
|
|
504
|
+
chain,
|
|
505
|
+
featureName: SuiSignAndExecuteTransaction
|
|
506
|
+
});
|
|
507
|
+
if (signAndExecuteTransactionFeature) {
|
|
508
|
+
const result = await signAndExecuteTransactionFeature.signAndExecuteTransaction({
|
|
509
|
+
...standardArgs,
|
|
510
|
+
account: underlyingAccount,
|
|
511
|
+
transaction: transactionWrapper,
|
|
512
|
+
chain
|
|
513
|
+
});
|
|
514
|
+
const transactionBytes = fromBase64(result.bytes);
|
|
515
|
+
const effectsBytes = fromBase64(result.effects);
|
|
516
|
+
return buildTransactionResult(result.digest, result.signature, transactionBytes, effectsBytes);
|
|
517
|
+
}
|
|
518
|
+
const signAndExecuteTransactionBlockFeature = tryGetAccountFeature({
|
|
519
|
+
account,
|
|
520
|
+
chain,
|
|
521
|
+
featureName: SuiSignAndExecuteTransactionBlock
|
|
522
|
+
});
|
|
523
|
+
if (signAndExecuteTransactionBlockFeature) {
|
|
524
|
+
const transactionBlock = Transaction.from(await transactionWrapper.toJSON());
|
|
525
|
+
const { digest, rawEffects, rawTransaction } = await signAndExecuteTransactionBlockFeature.signAndExecuteTransactionBlock({
|
|
526
|
+
account,
|
|
527
|
+
chain,
|
|
528
|
+
transactionBlock,
|
|
529
|
+
options: {
|
|
530
|
+
showRawEffects: true,
|
|
531
|
+
showRawInput: true
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
const [{ txSignatures: [signature], intentMessage: { value: bcsTransaction } }] = bcs.SenderSignedData.parse(fromBase64(rawTransaction));
|
|
535
|
+
return buildTransactionResult(digest, signature, bcs.TransactionData.serialize(bcsTransaction).toBytes(), new Uint8Array(rawEffects));
|
|
536
|
+
}
|
|
537
|
+
throw new FeatureNotSupportedError(`The account ${account.address} does not support signing and executing transactions.`);
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
//#endregion
|
|
542
|
+
//#region src/core/actions/sign-transaction.ts
|
|
543
|
+
function signTransactionCreator({ $connection, $currentClient }) {
|
|
544
|
+
/**
|
|
545
|
+
* Prompts the specified wallet account to sign a transaction.
|
|
546
|
+
*/
|
|
547
|
+
return async function signTransaction({ transaction, ...standardArgs }) {
|
|
548
|
+
const { account, supportedIntents } = $connection.get();
|
|
549
|
+
if (!account) throw new WalletNotConnectedError("No wallet is connected.");
|
|
550
|
+
const underlyingAccount = getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(account);
|
|
551
|
+
const suiClient = $currentClient.get();
|
|
552
|
+
const chain = getChain(suiClient.network);
|
|
553
|
+
const transactionWrapper = { toJSON: async () => {
|
|
554
|
+
if (typeof transaction === "string") return transaction;
|
|
555
|
+
transaction.setSenderIfNotSet(account.address);
|
|
556
|
+
return await transaction.toJSON({
|
|
557
|
+
client: suiClient,
|
|
558
|
+
supportedIntents
|
|
559
|
+
});
|
|
560
|
+
} };
|
|
561
|
+
const signTransactionFeature = tryGetAccountFeature({
|
|
562
|
+
account,
|
|
563
|
+
chain,
|
|
564
|
+
featureName: SuiSignTransaction
|
|
565
|
+
});
|
|
566
|
+
if (signTransactionFeature) return await signTransactionFeature.signTransaction({
|
|
567
|
+
...standardArgs,
|
|
568
|
+
transaction: transactionWrapper,
|
|
569
|
+
account: underlyingAccount,
|
|
570
|
+
chain
|
|
571
|
+
});
|
|
572
|
+
const signTransactionBlockFeature = tryGetAccountFeature({
|
|
573
|
+
account,
|
|
574
|
+
chain,
|
|
575
|
+
featureName: SuiSignTransactionBlock
|
|
576
|
+
});
|
|
577
|
+
if (signTransactionBlockFeature) {
|
|
578
|
+
const transaction$1 = Transaction.from(await transactionWrapper.toJSON());
|
|
579
|
+
const { transactionBlockBytes, signature } = await signTransactionBlockFeature.signTransactionBlock({
|
|
580
|
+
transactionBlock: transaction$1,
|
|
581
|
+
account: underlyingAccount,
|
|
582
|
+
chain
|
|
583
|
+
});
|
|
584
|
+
return {
|
|
585
|
+
bytes: transactionBlockBytes,
|
|
586
|
+
signature
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
throw new FeatureNotSupportedError(`The account ${account.address} does not support signing transactions.`);
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
//#endregion
|
|
594
|
+
//#region src/wallets/slush-web.ts
|
|
595
|
+
function slushWebWalletInitializer(config) {
|
|
596
|
+
return {
|
|
597
|
+
id: "slush-web-wallet-initializer",
|
|
598
|
+
async initialize() {
|
|
599
|
+
const result = await registerSlushWallet(config?.appName || getDefaultAppName(), {
|
|
600
|
+
origin: config?.origin,
|
|
601
|
+
metadataApiUrl: config?.metadataApiUrl
|
|
602
|
+
});
|
|
603
|
+
if (!result) throw new Error("Registration un-successful.");
|
|
604
|
+
return { unregister: result.unregister };
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function getDefaultAppName() {
|
|
609
|
+
return document.querySelector(`meta[name="application-name"]`)?.content || document.title;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/wallets/index.ts
|
|
614
|
+
const initializerMap = /* @__PURE__ */ new Map();
|
|
615
|
+
async function registerAdditionalWallets(initializers, args) {
|
|
616
|
+
initializerMap.forEach((unregister) => unregister());
|
|
617
|
+
initializerMap.clear();
|
|
618
|
+
const initializePromises = [...new Map(initializers.map((init) => [init.id, init])).values()].map(async (initializer) => {
|
|
619
|
+
return {
|
|
620
|
+
initializer,
|
|
621
|
+
result: await initializer.initialize(args)
|
|
622
|
+
};
|
|
623
|
+
});
|
|
624
|
+
const initializerResults = await Promise.allSettled(initializePromises);
|
|
625
|
+
for (const settledResult of initializerResults) if (settledResult.status === "fulfilled") {
|
|
626
|
+
const { initializer, result } = settledResult.value;
|
|
627
|
+
initializerMap.set(initializer.id, result.unregister);
|
|
628
|
+
} else console.warn(`Skipping wallet initializer: "${settledResult.reason}".`);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region src/wallets/unsafe-burner.ts
|
|
633
|
+
function unsafeBurnerWalletInitializer() {
|
|
634
|
+
return {
|
|
635
|
+
id: "unsafe-burner-initalizer",
|
|
636
|
+
async initialize({ networks, getClient }) {
|
|
637
|
+
const wallet = new UnsafeBurnerWallet({ clients: networks.map(getClient) });
|
|
638
|
+
return { unregister: getWallets().register(wallet) };
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
var UnsafeBurnerWallet = class {
|
|
643
|
+
#chainConfig;
|
|
644
|
+
#keypair = new Ed25519Keypair();
|
|
645
|
+
#account;
|
|
646
|
+
constructor({ clients }) {
|
|
647
|
+
this.#chainConfig = clients.reduce((accumulator, client) => {
|
|
648
|
+
const chain = getChain(client.network);
|
|
649
|
+
accumulator[chain] = client;
|
|
650
|
+
return accumulator;
|
|
651
|
+
}, {});
|
|
652
|
+
this.#account = new ReadonlyWalletAccount({
|
|
653
|
+
address: this.#keypair.getPublicKey().toSuiAddress(),
|
|
654
|
+
publicKey: this.#keypair.getPublicKey().toSuiBytes(),
|
|
655
|
+
chains: this.chains,
|
|
656
|
+
features: [
|
|
657
|
+
SuiSignTransaction,
|
|
658
|
+
SuiSignAndExecuteTransaction,
|
|
659
|
+
SuiSignPersonalMessage
|
|
660
|
+
]
|
|
661
|
+
});
|
|
662
|
+
console.warn("Your application is currently using the unsafe burner wallet. Make sure that this wallet is disabled in production.");
|
|
663
|
+
}
|
|
664
|
+
get version() {
|
|
665
|
+
return "1.0.0";
|
|
666
|
+
}
|
|
667
|
+
get name() {
|
|
668
|
+
return "Unsafe Burner Wallet";
|
|
669
|
+
}
|
|
670
|
+
get icon() {
|
|
671
|
+
return "data:image/png;base64,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";
|
|
672
|
+
}
|
|
673
|
+
get chains() {
|
|
674
|
+
return Object.keys(this.#chainConfig);
|
|
675
|
+
}
|
|
676
|
+
get accounts() {
|
|
677
|
+
return [this.#account];
|
|
678
|
+
}
|
|
679
|
+
get features() {
|
|
680
|
+
return {
|
|
681
|
+
[StandardConnect]: {
|
|
682
|
+
version: "1.0.0",
|
|
683
|
+
connect: this.#connect
|
|
684
|
+
},
|
|
685
|
+
[StandardEvents]: {
|
|
686
|
+
version: "1.0.0",
|
|
687
|
+
on: this.#on
|
|
688
|
+
},
|
|
689
|
+
[SuiSignPersonalMessage]: {
|
|
690
|
+
version: "1.1.0",
|
|
691
|
+
signPersonalMessage: this.#signPersonalMessage
|
|
692
|
+
},
|
|
693
|
+
[SuiSignTransaction]: {
|
|
694
|
+
version: "2.0.0",
|
|
695
|
+
signTransaction: this.#signTransaction
|
|
696
|
+
},
|
|
697
|
+
[SuiSignAndExecuteTransaction]: {
|
|
698
|
+
version: "2.0.0",
|
|
699
|
+
signAndExecuteTransaction: this.#signAndExecuteTransaction
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
#on = () => {
|
|
704
|
+
return () => {};
|
|
705
|
+
};
|
|
706
|
+
#connect = async () => {
|
|
707
|
+
return { accounts: this.accounts };
|
|
708
|
+
};
|
|
709
|
+
#signPersonalMessage = async (messageInput) => {
|
|
710
|
+
return await this.#keypair.signPersonalMessage(messageInput.message);
|
|
711
|
+
};
|
|
712
|
+
#signTransaction = async ({ transaction, signal, chain }) => {
|
|
713
|
+
signal?.throwIfAborted();
|
|
714
|
+
const client = this.#chainConfig[chain];
|
|
715
|
+
if (!client) throw new Error(`Invalid chain "${chain}" specified.`);
|
|
716
|
+
const builtTransaction = await Transaction.from(await transaction.toJSON()).build({ client });
|
|
717
|
+
return await this.#keypair.signTransaction(builtTransaction);
|
|
718
|
+
};
|
|
719
|
+
#signAndExecuteTransaction = async ({ transaction, signal, chain }) => {
|
|
720
|
+
signal?.throwIfAborted();
|
|
721
|
+
const client = this.#chainConfig[chain];
|
|
722
|
+
if (!client) throw new Error(`Invalid chain "${chain}" specified.`);
|
|
723
|
+
const parsedTransaction = Transaction.from(await transaction.toJSON());
|
|
724
|
+
const bytes = await parsedTransaction.build({ client });
|
|
725
|
+
const result = await this.#keypair.signAndExecuteTransaction({
|
|
726
|
+
transaction: parsedTransaction,
|
|
727
|
+
client
|
|
728
|
+
});
|
|
729
|
+
const tx = result.Transaction ?? result.FailedTransaction;
|
|
730
|
+
return {
|
|
731
|
+
bytes: toBase64(bytes),
|
|
732
|
+
signature: tx.signatures[0],
|
|
733
|
+
digest: tx.digest,
|
|
734
|
+
effects: toBase64(tx.effects.bcs)
|
|
735
|
+
};
|
|
736
|
+
};
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region src/core/index.ts
|
|
741
|
+
function createDAppKit({ autoConnect = true, networks, createClient, defaultNetwork = networks[0], enableBurnerWallet = false, slushWalletConfig, storage = getDefaultStorage(), storageKey = DEFAULT_STORAGE_KEY, walletInitializers = [] }) {
|
|
742
|
+
const networkConfig = createNetworkConfig(networks, createClient);
|
|
743
|
+
const stores = createStores({
|
|
744
|
+
defaultNetwork,
|
|
745
|
+
getClient: networkConfig.getClient
|
|
746
|
+
});
|
|
747
|
+
function getClient(network) {
|
|
748
|
+
return network ? networkConfig.getClient(network) : stores.$currentClient.get();
|
|
749
|
+
}
|
|
750
|
+
storage ||= createInMemoryStorage();
|
|
751
|
+
syncStateToStorage({
|
|
752
|
+
stores,
|
|
753
|
+
storageKey,
|
|
754
|
+
storage
|
|
755
|
+
});
|
|
756
|
+
syncRegisteredWallets(stores);
|
|
757
|
+
manageWalletConnection(stores);
|
|
758
|
+
if (autoConnect) autoConnectWallet({
|
|
759
|
+
networks,
|
|
760
|
+
stores,
|
|
761
|
+
storageKey,
|
|
762
|
+
storage
|
|
763
|
+
});
|
|
764
|
+
registerAdditionalWallets([
|
|
765
|
+
...walletInitializers,
|
|
766
|
+
...enableBurnerWallet ? [unsafeBurnerWalletInitializer()] : [],
|
|
767
|
+
...slushWalletConfig !== null ? [slushWebWalletInitializer(slushWalletConfig)] : []
|
|
768
|
+
], {
|
|
769
|
+
networks,
|
|
770
|
+
getClient
|
|
771
|
+
});
|
|
772
|
+
return {
|
|
773
|
+
networks,
|
|
774
|
+
getClient,
|
|
775
|
+
signTransaction: signTransactionCreator(stores),
|
|
776
|
+
signAndExecuteTransaction: signAndExecuteTransactionCreator(stores),
|
|
777
|
+
signPersonalMessage: signPersonalMessageCreator(stores),
|
|
778
|
+
connectWallet: connectWalletCreator(stores, networks),
|
|
779
|
+
disconnectWallet: disconnectWalletCreator(stores),
|
|
780
|
+
switchAccount: switchAccountCreator(stores),
|
|
781
|
+
switchNetwork: switchNetworkCreator(stores),
|
|
782
|
+
stores: {
|
|
783
|
+
$wallets: stores.$compatibleWallets,
|
|
784
|
+
$connection: stores.$connection,
|
|
785
|
+
$currentNetwork: readonlyType(stores.$currentNetwork),
|
|
786
|
+
$currentClient: stores.$currentClient
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
//#endregion
|
|
792
|
+
export { createDAppKit, getWalletUniqueIdentifier };
|
|
793
|
+
//# sourceMappingURL=index.mjs.map
|