@dynamic-labs/aptos 4.39.0 → 4.40.1

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.
@@ -0,0 +1,313 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { UserResponseStatus } from '@aptos-labs/wallet-standard';
4
+ import { getProvidersFromWindow } from '@dynamic-labs/utils';
5
+ import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
6
+ import { ProviderLookup, logger } from '@dynamic-labs/wallet-connector-core';
7
+
8
+ /**
9
+ * Helper class for managing Aptos wallet provider discovery and interactions.
10
+ *
11
+ * This class handles:
12
+ * - Finding installed wallet providers using legacy injection methods
13
+ * - Managing provider lookups using wallet book configuration
14
+ * - Setting up event listeners for account and network changes
15
+ * - Getting addresses and signing messages through the wallet-standard interface
16
+ */
17
+ class AptosProviderHelper {
18
+ constructor(connector) {
19
+ this.walletBookWallet = findWalletBookWallet(connector.walletBook, connector.key);
20
+ this.connector = connector;
21
+ }
22
+ /**
23
+ * Gets the installed Aptos provider using legacy injection.
24
+ */
25
+ getInstalledProvider() {
26
+ return this.getInjectedProvider();
27
+ }
28
+ /**
29
+ * Gets the injected provider using wallet book configuration.
30
+ */
31
+ getInjectedProvider() {
32
+ const config = this.getInjectedConfig();
33
+ if (!config ||
34
+ !config.extensionLocators ||
35
+ !config.extensionLocators.length)
36
+ return undefined;
37
+ const provider = this.installedProviderLookup(config.extensionLocators);
38
+ return provider;
39
+ }
40
+ /**
41
+ * Gets the injected configuration for Aptos from the wallet book.
42
+ */
43
+ getInjectedConfig() {
44
+ var _a;
45
+ const injectedConfig = (_a = this.walletBookWallet) === null || _a === void 0 ? void 0 : _a.injectedConfig;
46
+ return injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.find((c) => c.chain === 'aptos');
47
+ }
48
+ /**
49
+ * Gets all installed Aptos providers from various window locations.
50
+ */
51
+ installedProviders() {
52
+ const config = this.getInjectedConfig();
53
+ if (!config)
54
+ return [];
55
+ const providers = [];
56
+ if (config.windowLocations) {
57
+ for (const windowLocation of config.windowLocations) {
58
+ const foundProviders = getProvidersFromWindow(windowLocation);
59
+ if (foundProviders && foundProviders.length)
60
+ providers.push(...foundProviders);
61
+ }
62
+ }
63
+ return providers;
64
+ }
65
+ /**
66
+ * Looks up installed providers using extension locators.
67
+ */
68
+ installedProviderLookup(extensionLocators) {
69
+ const allInstalledProviders = this.installedProviders();
70
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
+ return ProviderLookup(allInstalledProviders, extensionLocators);
72
+ }
73
+ /**
74
+ * Finds the provider using the connector's findProvider method.
75
+ */
76
+ findProvider() {
77
+ return this.connector.findProvider();
78
+ }
79
+ /**
80
+ * Checks if a provider is installed.
81
+ */
82
+ isInstalledHelper() {
83
+ return this.findProvider() !== undefined;
84
+ }
85
+ /**
86
+ * Gets the current account address from the wallet.
87
+ */
88
+ getAddress() {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const provider = this.findProvider();
91
+ if (!provider) {
92
+ return undefined;
93
+ }
94
+ return this.getAddressWithProvider(provider);
95
+ });
96
+ }
97
+ /**
98
+ * Connects to the Aptos wallet provider.
99
+ */
100
+ connect() {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const provider = this.findProvider();
103
+ if (!provider) {
104
+ logger.error('No Aptos provider found to connect', {
105
+ connector: this.connector.name,
106
+ });
107
+ return undefined;
108
+ }
109
+ return provider;
110
+ });
111
+ }
112
+ /**
113
+ * Gets the address using a specific provider.
114
+ */
115
+ getAddressWithProvider(provider) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ try {
118
+ // Try to get account info from the provider
119
+ const accountMethod = provider.account;
120
+ if (accountMethod) {
121
+ const accountInfo = yield accountMethod();
122
+ return accountInfo.address.toString();
123
+ }
124
+ return undefined;
125
+ }
126
+ catch (err) {
127
+ // "Account not found" is expected when wallet is not connected yet
128
+ const isAccountNotFound = err instanceof Error && err.message === 'Account not found';
129
+ if (isAccountNotFound) {
130
+ logger.debug('[AptosProviderHelper] No account connected yet');
131
+ }
132
+ else {
133
+ logger.error('[AptosProviderHelper] getAddressWithProvider error:', err);
134
+ }
135
+ return undefined;
136
+ }
137
+ });
138
+ }
139
+ /**
140
+ * Signs a message using the Aptos wallet.
141
+ */
142
+ signMessage(messageToSign) {
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ var _a;
145
+ // Early returns for validation
146
+ const walletAddress = yield this.getAddress();
147
+ if (!walletAddress)
148
+ return undefined;
149
+ const provider = this.findProvider();
150
+ if (!provider)
151
+ return undefined;
152
+ const signMessageMethod = provider.signMessage;
153
+ if (!signMessageMethod) {
154
+ logger.error('[AptosProviderHelper] signMessage not supported');
155
+ return undefined;
156
+ }
157
+ const nonce = new Date().getTime().toString();
158
+ const result = yield signMessageMethod({
159
+ message: messageToSign,
160
+ nonce,
161
+ });
162
+ // Handle UserResponse format
163
+ if (this.isUserResponseApproved(result)) {
164
+ return this.handleUserResponseSignature(result);
165
+ }
166
+ // Handle direct signature format
167
+ if ('signature' in result) {
168
+ return (_a = result.signature) === null || _a === void 0 ? void 0 : _a.toString();
169
+ }
170
+ return undefined;
171
+ });
172
+ }
173
+ /**
174
+ * Checks if the result is an approved UserResponse
175
+ */
176
+ isUserResponseApproved(result) {
177
+ return (typeof result === 'object' &&
178
+ result !== null &&
179
+ 'status' in result &&
180
+ result.status === UserResponseStatus.APPROVED &&
181
+ 'args' in result);
182
+ }
183
+ /**
184
+ * Handles UserResponse signature format and returns JSON string
185
+ */
186
+ handleUserResponseSignature(result) {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ var _a;
189
+ const resultWithArgs = result;
190
+ const signature = (_a = resultWithArgs.args.signature) === null || _a === void 0 ? void 0 : _a.toString();
191
+ const { fullMessage, publicKey: walletPublicKey } = resultWithArgs.args;
192
+ // Get public key from account if not provided in result
193
+ const publicKey = walletPublicKey || (yield this.getPublicKeyFromAccount());
194
+ return JSON.stringify({
195
+ fullMessage,
196
+ publicKey,
197
+ signature,
198
+ });
199
+ });
200
+ }
201
+ /**
202
+ * Gets public key from the connected account
203
+ */
204
+ getPublicKeyFromAccount() {
205
+ return __awaiter(this, void 0, void 0, function* () {
206
+ var _a;
207
+ const provider = this.findProvider();
208
+ if (!(provider === null || provider === void 0 ? void 0 : provider.account))
209
+ return undefined;
210
+ try {
211
+ const accountInfo = yield provider.account();
212
+ return (_a = accountInfo.publicKey) === null || _a === void 0 ? void 0 : _a.toString();
213
+ }
214
+ catch (e) {
215
+ logger.debug('Failed to fetch public key:', e);
216
+ return undefined;
217
+ }
218
+ });
219
+ }
220
+ /**
221
+ * Gets connected accounts from the provider.
222
+ */
223
+ getConnectedAccounts() {
224
+ return __awaiter(this, void 0, void 0, function* () {
225
+ const provider = this.findProvider();
226
+ if (!provider)
227
+ return [];
228
+ try {
229
+ const accountMethod = provider.account;
230
+ if (accountMethod) {
231
+ const accountInfo = yield accountMethod();
232
+ return [accountInfo.address.toString()];
233
+ }
234
+ }
235
+ catch (e) {
236
+ // This is expected when wallet is not connected yet
237
+ logger.debug('Error getting connected accounts', {
238
+ connector: this.connector,
239
+ error: e,
240
+ });
241
+ }
242
+ return [];
243
+ });
244
+ }
245
+ /**
246
+ * Handles account change events.
247
+ */
248
+ handleAccountChange(walletConnector, web3Provider, address) {
249
+ return __awaiter(this, void 0, void 0, function* () {
250
+ if (!address) {
251
+ yield (web3Provider === null || web3Provider === void 0 ? void 0 : web3Provider.connect());
252
+ const accountMethod = web3Provider === null || web3Provider === void 0 ? void 0 : web3Provider.account;
253
+ if (accountMethod) {
254
+ const accountInfo = yield accountMethod();
255
+ if (accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.address) {
256
+ walletConnector.emit('accountChange', {
257
+ accounts: [accountInfo.address.toString()],
258
+ });
259
+ }
260
+ }
261
+ return;
262
+ }
263
+ if (address.toString()) {
264
+ walletConnector.emit('accountChange', { accounts: [address.toString()] });
265
+ }
266
+ });
267
+ }
268
+ /**
269
+ * Sets up event listeners for account and network changes.
270
+ */
271
+ _setupEventListeners() {
272
+ const provider = this.findProvider();
273
+ if (!provider) {
274
+ logger.warn('Provider not found', {
275
+ connector: this.connector,
276
+ });
277
+ return;
278
+ }
279
+ const onAccountChangeMethod = provider === null || provider === void 0 ? void 0 : provider.onAccountChange;
280
+ const onNetworkChangeMethod = provider === null || provider === void 0 ? void 0 : provider.onNetworkChange;
281
+ if (onAccountChangeMethod) {
282
+ onAccountChangeMethod((account) => {
283
+ if (account) {
284
+ this.handleAccountChange(this.connector, provider, account.address.toString());
285
+ }
286
+ else {
287
+ this.connector.emit('disconnect');
288
+ }
289
+ });
290
+ }
291
+ if (onNetworkChangeMethod) {
292
+ onNetworkChangeMethod((network) => {
293
+ if (network.chainId) {
294
+ this.connector.emit('chainChange', {
295
+ chain: network.chainId.toString(),
296
+ });
297
+ }
298
+ });
299
+ }
300
+ }
301
+ /**
302
+ * Tears down event listeners.
303
+ */
304
+ _teardownEventListeners() {
305
+ const provider = this.findProvider();
306
+ if (!provider)
307
+ return;
308
+ // Aptos providers don't have removeAllListeners like Solana
309
+ // Event listeners are automatically cleaned up when the provider is destroyed
310
+ }
311
+ }
312
+
313
+ export { AptosProviderHelper };
@@ -0,0 +1,87 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var AptosWalletConnector = require('../connectors/AptosWalletConnector/AptosWalletConnector.cjs');
8
+ var AptosProviderHelper = require('./AptosProviderHelper.cjs');
9
+
10
+ /**
11
+ * Base class for injected Aptos wallet connectors.
12
+ *
13
+ * This class extends AptosWalletConnector and provides common functionality
14
+ * for wallets that inject themselves into the browser window object.
15
+ *
16
+ * It handles:
17
+ * - Provider discovery and management
18
+ * - Connection flow (including mobile in-app browser support)
19
+ * - Event listener setup and teardown
20
+ * - Address retrieval and message signing
21
+ */
22
+ class InjectedWalletBase extends AptosWalletConnector.AptosWalletConnector {
23
+ get aptosProviderHelper() {
24
+ if (!this._aptosProviderHelper) {
25
+ this._aptosProviderHelper = new AptosProviderHelper.AptosProviderHelper(this);
26
+ }
27
+ return this._aptosProviderHelper;
28
+ }
29
+ findProvider() {
30
+ var _a;
31
+ return (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.getInstalledProvider();
32
+ }
33
+ setupEventListeners() {
34
+ var _a;
35
+ (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a._setupEventListeners();
36
+ }
37
+ teardownEventListeners() {
38
+ var _a;
39
+ (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a._teardownEventListeners();
40
+ }
41
+ connect() {
42
+ const _super = Object.create(null, {
43
+ connect: { get: () => super.connect }
44
+ });
45
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
46
+ // Call parent's connect which triggers the wallet-standard connect() method
47
+ yield _super.connect.call(this);
48
+ });
49
+ }
50
+ getSigner() {
51
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
52
+ var _a;
53
+ return (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.connect();
54
+ });
55
+ }
56
+ isInstalledOnBrowser() {
57
+ var _a;
58
+ return Boolean((_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.isInstalledHelper());
59
+ }
60
+ getAddress() {
61
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
62
+ var _a;
63
+ if (!this.isInstalledOnBrowser()) {
64
+ return;
65
+ }
66
+ // If no address, we need to connect first to trigger the wallet popup
67
+ yield this.connect();
68
+ // Now try to get the address again
69
+ const address = yield ((_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.getAddress());
70
+ return address;
71
+ });
72
+ }
73
+ signMessage(messageToSign) {
74
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
75
+ var _a;
76
+ return (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.signMessage(messageToSign);
77
+ });
78
+ }
79
+ getConnectedAccounts() {
80
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
81
+ var _a, _b;
82
+ return (_b = (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.getConnectedAccounts()) !== null && _b !== void 0 ? _b : [];
83
+ });
84
+ }
85
+ }
86
+
87
+ exports.InjectedWalletBase = InjectedWalletBase;
@@ -0,0 +1,28 @@
1
+ import { AptosWalletConnector } from '../connectors/AptosWalletConnector';
2
+ import type { IAptosProvider } from '../types';
3
+ import { AptosProviderHelper } from './AptosProviderHelper';
4
+ /**
5
+ * Base class for injected Aptos wallet connectors.
6
+ *
7
+ * This class extends AptosWalletConnector and provides common functionality
8
+ * for wallets that inject themselves into the browser window object.
9
+ *
10
+ * It handles:
11
+ * - Provider discovery and management
12
+ * - Connection flow (including mobile in-app browser support)
13
+ * - Event listener setup and teardown
14
+ * - Address retrieval and message signing
15
+ */
16
+ export declare abstract class InjectedWalletBase extends AptosWalletConnector {
17
+ _aptosProviderHelper: AptosProviderHelper | undefined;
18
+ get aptosProviderHelper(): AptosProviderHelper | undefined;
19
+ findProvider(): IAptosProvider | undefined;
20
+ setupEventListeners(): void;
21
+ teardownEventListeners(): void;
22
+ connect(): Promise<void>;
23
+ getSigner<T = IAptosProvider>(): Promise<T | undefined>;
24
+ isInstalledOnBrowser(): boolean;
25
+ getAddress(): Promise<string | undefined>;
26
+ signMessage(messageToSign: string): Promise<string | undefined>;
27
+ getConnectedAccounts(): Promise<string[]>;
28
+ }
@@ -0,0 +1,83 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { AptosWalletConnector } from '../connectors/AptosWalletConnector/AptosWalletConnector.js';
4
+ import { AptosProviderHelper } from './AptosProviderHelper.js';
5
+
6
+ /**
7
+ * Base class for injected Aptos wallet connectors.
8
+ *
9
+ * This class extends AptosWalletConnector and provides common functionality
10
+ * for wallets that inject themselves into the browser window object.
11
+ *
12
+ * It handles:
13
+ * - Provider discovery and management
14
+ * - Connection flow (including mobile in-app browser support)
15
+ * - Event listener setup and teardown
16
+ * - Address retrieval and message signing
17
+ */
18
+ class InjectedWalletBase extends AptosWalletConnector {
19
+ get aptosProviderHelper() {
20
+ if (!this._aptosProviderHelper) {
21
+ this._aptosProviderHelper = new AptosProviderHelper(this);
22
+ }
23
+ return this._aptosProviderHelper;
24
+ }
25
+ findProvider() {
26
+ var _a;
27
+ return (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.getInstalledProvider();
28
+ }
29
+ setupEventListeners() {
30
+ var _a;
31
+ (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a._setupEventListeners();
32
+ }
33
+ teardownEventListeners() {
34
+ var _a;
35
+ (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a._teardownEventListeners();
36
+ }
37
+ connect() {
38
+ const _super = Object.create(null, {
39
+ connect: { get: () => super.connect }
40
+ });
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ // Call parent's connect which triggers the wallet-standard connect() method
43
+ yield _super.connect.call(this);
44
+ });
45
+ }
46
+ getSigner() {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ var _a;
49
+ return (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.connect();
50
+ });
51
+ }
52
+ isInstalledOnBrowser() {
53
+ var _a;
54
+ return Boolean((_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.isInstalledHelper());
55
+ }
56
+ getAddress() {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ var _a;
59
+ if (!this.isInstalledOnBrowser()) {
60
+ return;
61
+ }
62
+ // If no address, we need to connect first to trigger the wallet popup
63
+ yield this.connect();
64
+ // Now try to get the address again
65
+ const address = yield ((_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.getAddress());
66
+ return address;
67
+ });
68
+ }
69
+ signMessage(messageToSign) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ var _a;
72
+ return (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.signMessage(messageToSign);
73
+ });
74
+ }
75
+ getConnectedAccounts() {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ var _a, _b;
78
+ return (_b = (_a = this.aptosProviderHelper) === null || _a === void 0 ? void 0 : _a.getConnectedAccounts()) !== null && _b !== void 0 ? _b : [];
79
+ });
80
+ }
81
+ }
82
+
83
+ export { InjectedWalletBase };
@@ -0,0 +1,171 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var walletBook = require('@dynamic-labs/wallet-book');
7
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
+ var utils = require('@dynamic-labs/utils');
9
+ var logger$1 = require('@dynamic-labs/logger');
10
+ var getWalletStandardWallets = require('../utils/getWalletStandardWallets/getWalletStandardWallets.cjs');
11
+ var isWalletWithRequiredFeatureSet = require('../utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.cjs');
12
+ var index = require('../consts/index.cjs');
13
+ var getConnectorConstructorForWalletStandardWallet = require('../walletStandard/getConnectorConstructorForWalletStandardWallet.cjs');
14
+ var InjectedWalletBase = require('./InjectedWalletBase.cjs');
15
+
16
+ const logger = new logger$1.Logger('fetchInjectedWalletConnectors');
17
+ /**
18
+ * List of wallet keys that have custom connector implementations.
19
+ * These wallets will not use the automatic wallet-standard connector.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const walletsWithCustomConnectors: string[] = [
24
+ * 'petra',
25
+ * 'okxaptos',
26
+ * ];
27
+ * ```
28
+ */
29
+ const walletsWithCustomConnectors = [
30
+ // Add wallet keys here that need custom connectors
31
+ ];
32
+ /**
33
+ * Determines whether a wallet-standard wallet should have a connector created for it.
34
+ *
35
+ * @param wallet - The wallet-standard wallet to check
36
+ * @param walletBook - The wallet book schema containing wallet metadata
37
+ * @param authMode - The authentication mode (optional, for future feature filtering)
38
+ * @returns True if a wallet-standard connector should be created
39
+ */
40
+ const shouldAddWalletStandardConnector = (wallet, walletBook) => {
41
+ var _a;
42
+ const { name } = wallet;
43
+ const chain = 'aptos';
44
+ const connectorKey = `${utils.sanitizeName(name)}${chain}`;
45
+ logger.logVerboseTroubleshootingMessage('[APTOS shouldAddWalletStandardConnector] Checking wallet:', { chain, connectorKey, features: Object.keys(wallet.features), name });
46
+ const shouldHandleWalletFromWalletBook = ([key, walletEntry]) => {
47
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
48
+ const hasMatchingKey = key === connectorKey;
49
+ const needsCustomConnector = walletsWithCustomConnectors.includes(connectorKey);
50
+ const hasMatchingNameAndChain = walletEntry.name === name &&
51
+ ((_b = (_a = walletEntry.injectedConfig) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.chain) === chain;
52
+ // If the wallet supports wallet-standard, we want to add the wallet-standard connector
53
+ // and not handle it as a default wallet-book wallet
54
+ const isNotWalletStandard = !((_f = (_e = (_d = (_c = walletEntry.injectedConfig) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.walletStandard) === null || _e === void 0 ? void 0 : _e.features) === null || _f === void 0 ? void 0 : _f.length);
55
+ // If injectedConfig is missing, it's not a traditional wallet book entry
56
+ const hasInjectedConfig = Boolean((_g = walletEntry.injectedConfig) === null || _g === void 0 ? void 0 : _g.length);
57
+ // If the chain doesn't match, it should be handled by wallet-standard
58
+ const hasMatchingChain = ((_j = (_h = walletEntry.injectedConfig) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.chain) === chain;
59
+ return ((hasMatchingKey || needsCustomConnector || hasMatchingNameAndChain) &&
60
+ hasInjectedConfig &&
61
+ hasMatchingChain &&
62
+ isNotWalletStandard);
63
+ };
64
+ const shouldHandleFromWalletBook = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {}).find(shouldHandleWalletFromWalletBook);
65
+ // Check if wallet has all required features based on auth mode
66
+ const additionalFeatures = [];
67
+ const hasAllFeatures = isWalletWithRequiredFeatureSet.isWalletWithRequiredFeatureSet(wallet, additionalFeatures);
68
+ logger.logVerboseTroubleshootingMessage('[APTOS shouldAddWalletStandardConnector] Decision:', {
69
+ hasAllFeatures,
70
+ requiredFeatures: [...index.REQUIRED_FEATURES, ...additionalFeatures],
71
+ shouldAdd: !shouldHandleFromWalletBook && hasAllFeatures,
72
+ shouldHandleFromWalletBook: Boolean(shouldHandleFromWalletBook),
73
+ });
74
+ return !shouldHandleFromWalletBook && hasAllFeatures;
75
+ };
76
+ /**
77
+ * Fetches all available injected Aptos wallet connectors.
78
+ *
79
+ * This function discovers and creates wallet connector constructors from two sources:
80
+ * 1. Wallet book entries - Traditional wallets defined in the wallet book
81
+ * 2. Wallet-standard wallets - AIP-62 compliant wallets discovered via wallet-standard
82
+ *
83
+ * The function automatically filters out wallets that:
84
+ * - Have custom connector implementations
85
+ * - Are already handled by wallet-standard connectors
86
+ * - Don't support the required Aptos feature set
87
+ *
88
+ * @param options - Configuration options
89
+ * @param options.walletBook - The wallet book schema containing wallet metadata
90
+ * @param options.authMode - The authentication mode for filtering wallet features
91
+ * @returns Array of wallet connector constructor classes
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const connectors = fetchInjectedWalletConnectors({
96
+ * walletBook,
97
+ * authMode: 'connect-and-sign'
98
+ * });
99
+ *
100
+ * // Instantiate connectors
101
+ * connectors.forEach(Connector => {
102
+ * const instance = new Connector(aptosWalletConnectorProps);
103
+ * });
104
+ * ```
105
+ */
106
+ const fetchInjectedWalletConnectors = ({ walletBook: walletBook$1, }) => {
107
+ var _a;
108
+ // Get wallet book connectors for traditional Aptos wallets
109
+ const walletBookConnectors = Object.entries((_a = walletBook$1 === null || walletBook$1 === void 0 ? void 0 : walletBook$1.wallets) !== null && _a !== void 0 ? _a : {})
110
+ .filter(([key, wallet]) => {
111
+ var _a, _b, _c;
112
+ const injectedConfig = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'aptos');
113
+ const isAptosWallet = Boolean(injectedConfig);
114
+ // Filter out wallets that require a custom connector or wallets that support wallet-standard,
115
+ // since they are already handled automatically with the wallet-standard connector
116
+ const shouldBeFiltered = walletsWithCustomConnectors.includes(key) ||
117
+ ((_c = (_b = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) === null || _b === void 0 ? void 0 : _b.features) === null || _c === void 0 ? void 0 : _c.length);
118
+ return isAptosWallet && !shouldBeFiltered;
119
+ })
120
+ .map(([key, wallet]) => {
121
+ const { shortName } = wallet;
122
+ const name = shortName || wallet.name;
123
+ return class extends InjectedWalletBase.InjectedWalletBase {
124
+ constructor() {
125
+ super(...arguments);
126
+ this.name = name;
127
+ // This is the key from the wallet book entry so that we don't purely rely on the normalized name
128
+ this.overrideKey = key;
129
+ }
130
+ getProvider() {
131
+ return this.findProvider();
132
+ }
133
+ };
134
+ });
135
+ // Get wallet-standard wallets
136
+ const { aptosWallets } = getWalletStandardWallets.getWalletStandardWallets();
137
+ logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Found wallet-standard wallets:', aptosWallets.map((w) => ({
138
+ features: Object.keys(w.features),
139
+ name: w.name,
140
+ })));
141
+ // Create connectors for wallet-standard wallets
142
+ const walletStandardConnectors = aptosWallets
143
+ .filter((wallet) =>
144
+ // Type incompatibility between @wallet-standard versions, casting is safe here
145
+ shouldAddWalletStandardConnector(
146
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
147
+ wallet, walletBook$1))
148
+ .map((wallet) => {
149
+ const walletBookWallet = walletBook.findWalletBookWalletByNameAndChain(walletBook$1, wallet.name, 'aptos');
150
+ // If the wallet book wallet is found, we want to use it to get the metadata
151
+ // to merge with the wallet-standard metadata, especially for additional properties
152
+ const walletBookMetadata = walletBookWallet &&
153
+ walletConnectorCore.getWalletMetadataFromWalletBook({
154
+ walletBook: walletBook$1,
155
+ walletBookWallet,
156
+ walletKey: `${utils.sanitizeName(wallet.name)}aptos`,
157
+ });
158
+ // Type incompatibility between @wallet-standard versions, casting is safe here
159
+ return getConnectorConstructorForWalletStandardWallet.getConnectorConstructorForWalletStandardWallet(
160
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
161
+ wallet, walletBookMetadata);
162
+ });
163
+ logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Created wallet-standard connectors:', walletStandardConnectors.map((w) => w.name));
164
+ logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Created wallet-book connectors:', walletBookConnectors.map((w) => w.name));
165
+ return [
166
+ ...walletBookConnectors,
167
+ ...walletStandardConnectors,
168
+ ];
169
+ };
170
+
171
+ exports.fetchInjectedWalletConnectors = fetchInjectedWalletConnectors;