@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.
- package/CHANGELOG.md +19 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +7 -5
- package/src/index.cjs +12 -5
- package/src/index.d.ts +1 -1
- package/src/index.js +11 -4
- package/src/injected/AptosProviderHelper.cjs +317 -0
- package/src/injected/AptosProviderHelper.d.ts +106 -0
- package/src/injected/AptosProviderHelper.js +313 -0
- package/src/injected/InjectedWalletBase.cjs +87 -0
- package/src/injected/InjectedWalletBase.d.ts +28 -0
- package/src/injected/InjectedWalletBase.js +83 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +171 -0
- package/src/injected/fetchInjectedWalletConnectors.d.ts +48 -0
- package/src/injected/fetchInjectedWalletConnectors.js +167 -0
- package/src/injected/index.d.ts +3 -0
- package/src/types.d.ts +22 -1
- package/src/utils/getWalletStandardWallets/getWalletStandardWallets.cjs +30 -11
- package/src/utils/getWalletStandardWallets/getWalletStandardWallets.js +31 -12
- package/src/walletStandard/createAptosSignerFromWalletStandard.cjs +244 -0
- package/src/walletStandard/createAptosSignerFromWalletStandard.d.ts +9 -0
- package/src/walletStandard/createAptosSignerFromWalletStandard.js +240 -0
- package/src/walletStandard/getConnectorConstructorForWalletStandardWallet.cjs +31 -0
- package/src/walletStandard/getConnectorConstructorForWalletStandardWallet.d.ts +3 -0
- package/src/walletStandard/getConnectorConstructorForWalletStandardWallet.js +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.40.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.40.0...v4.40.1) (2025-10-24)
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add support for Keplr in-app browser redirect for cosmos chain ([#9770](https://github.com/dynamic-labs/dynamic-auth/issues/9770)) ([35652f3](https://github.com/dynamic-labs/dynamic-auth/commit/35652f3167a4e768f5d4c634ab1b4f127fd5076a))
|
|
7
|
+
|
|
8
|
+
## [4.40.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.39.0...v4.40.0) (2025-10-22)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add Wallet Connect Solana as a wallet option ([#9719](https://github.com/dynamic-labs/dynamic-auth/issues/9719)) ([ece5f6b](https://github.com/dynamic-labs/dynamic-auth/commit/ece5f6b36c1fbefdf05cf8203fe0fee0b2e8ed3d))
|
|
14
|
+
* make updates to crypto.com onramp flow ([#9746](https://github.com/dynamic-labs/dynamic-auth/issues/9746)) ([22040d2](https://github.com/dynamic-labs/dynamic-auth/commit/22040d28d0d66b84f5c3be9bed4cfce7f1978944))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* return undefined if json payload is undefined in parse token ([#9750](https://github.com/dynamic-labs/dynamic-auth/issues/9750)) ([5751198](https://github.com/dynamic-labs/dynamic-auth/commit/575119867c93f89062e96e30c02b128161fb9675))
|
|
20
|
+
|
|
2
21
|
## [4.39.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.38.0...v4.39.0) (2025-10-17)
|
|
3
22
|
|
|
4
23
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/aptos",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.40.1",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,11 +20,13 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@aptos-labs/ts-sdk": "5.1.1",
|
|
22
22
|
"@aptos-labs/wallet-standard": "0.5.2",
|
|
23
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
23
|
+
"@dynamic-labs/assert-package-version": "4.40.1",
|
|
24
24
|
"@wallet-standard/core": "1.1.1",
|
|
25
|
-
"@
|
|
26
|
-
"@dynamic-labs/
|
|
27
|
-
"@dynamic-labs/
|
|
25
|
+
"@wallet-standard/features": "1.0.3",
|
|
26
|
+
"@dynamic-labs/logger": "4.40.1",
|
|
27
|
+
"@dynamic-labs/utils": "4.40.1",
|
|
28
|
+
"@dynamic-labs/wallet-book": "4.40.1",
|
|
29
|
+
"@dynamic-labs/wallet-connector-core": "4.40.1"
|
|
28
30
|
},
|
|
29
31
|
"peerDependencies": {}
|
|
30
32
|
}
|
package/src/index.cjs
CHANGED
|
@@ -5,8 +5,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
7
|
var _package = require('../package.cjs');
|
|
8
|
-
|
|
8
|
+
require('../_virtual/_tslib.cjs');
|
|
9
|
+
require('@aptos-labs/wallet-standard');
|
|
10
|
+
require('@dynamic-labs/utils');
|
|
11
|
+
require('@dynamic-labs/wallet-book');
|
|
12
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
9
13
|
var AptosWalletConnector = require('./connectors/AptosWalletConnector/AptosWalletConnector.cjs');
|
|
14
|
+
var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConnectors.cjs');
|
|
15
|
+
var AptosWallet = require('./wallet/AptosWallet.cjs');
|
|
10
16
|
var assertProvider = require('./utils/assertProvider/assertProvider.cjs');
|
|
11
17
|
var getWalletStandardWallets = require('./utils/getWalletStandardWallets/getWalletStandardWallets.cjs');
|
|
12
18
|
var invokeWalletMethod = require('./utils/invokeWalletMethod/invokeWalletMethod.cjs');
|
|
@@ -16,13 +22,14 @@ var parseTransactionResponse = require('./utils/parseTransactionResponse/parseTr
|
|
|
16
22
|
|
|
17
23
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/aptos', _package.version);
|
|
18
24
|
// Wallet connector factory (to be implemented by specific wallet connectors)
|
|
19
|
-
const AptosWalletConnectors = () => [
|
|
20
|
-
// Specific wallet connectors will be added here by implementers
|
|
21
|
-
// e.g., PetraWalletConnector, OKXWalletConnector, etc.
|
|
25
|
+
const AptosWalletConnectors = (props) => [
|
|
26
|
+
// Specific wallet connectors will be added here by implementers
|
|
27
|
+
// e.g., PetraWalletConnector, OKXWalletConnector, etc.
|
|
28
|
+
...fetchInjectedWalletConnectors.fetchInjectedWalletConnectors(props),
|
|
22
29
|
];
|
|
23
30
|
|
|
24
|
-
exports.AptosWallet = AptosWallet.AptosWallet;
|
|
25
31
|
exports.AptosWalletConnector = AptosWalletConnector.AptosWalletConnector;
|
|
32
|
+
exports.AptosWallet = AptosWallet.AptosWallet;
|
|
26
33
|
exports.assertProvider = assertProvider.assertProvider;
|
|
27
34
|
exports.getWalletStandardWallets = getWalletStandardWallets.getWalletStandardWallets;
|
|
28
35
|
exports.invokeWalletMethod = invokeWalletMethod.invokeWalletMethod;
|
package/src/index.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export { invokeWalletMethod } from './utils/invokeWalletMethod';
|
|
|
7
7
|
export { isWalletWithRequiredFeatureSet } from './utils/isWalletWithRequiredFeatureSet';
|
|
8
8
|
export { parseConnectionResult, type ParsedAccountInfo, } from './utils/parseConnectionResult';
|
|
9
9
|
export { parseTransactionResponse } from './utils/parseTransactionResponse';
|
|
10
|
-
export declare const AptosWalletConnectors: () =>
|
|
10
|
+
export declare const AptosWalletConnectors: (props: any) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
3
|
import { version } from '../package.js';
|
|
4
|
-
|
|
4
|
+
import '../_virtual/_tslib.js';
|
|
5
|
+
import '@aptos-labs/wallet-standard';
|
|
6
|
+
import '@dynamic-labs/utils';
|
|
7
|
+
import '@dynamic-labs/wallet-book';
|
|
8
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
5
9
|
export { AptosWalletConnector } from './connectors/AptosWalletConnector/AptosWalletConnector.js';
|
|
10
|
+
import { fetchInjectedWalletConnectors } from './injected/fetchInjectedWalletConnectors.js';
|
|
11
|
+
export { AptosWallet } from './wallet/AptosWallet.js';
|
|
6
12
|
export { assertProvider } from './utils/assertProvider/assertProvider.js';
|
|
7
13
|
export { getWalletStandardWallets } from './utils/getWalletStandardWallets/getWalletStandardWallets.js';
|
|
8
14
|
export { invokeWalletMethod } from './utils/invokeWalletMethod/invokeWalletMethod.js';
|
|
@@ -12,9 +18,10 @@ export { parseTransactionResponse } from './utils/parseTransactionResponse/parse
|
|
|
12
18
|
|
|
13
19
|
assertPackageVersion('@dynamic-labs/aptos', version);
|
|
14
20
|
// Wallet connector factory (to be implemented by specific wallet connectors)
|
|
15
|
-
const AptosWalletConnectors = () => [
|
|
16
|
-
// Specific wallet connectors will be added here by implementers
|
|
17
|
-
// e.g., PetraWalletConnector, OKXWalletConnector, etc.
|
|
21
|
+
const AptosWalletConnectors = (props) => [
|
|
22
|
+
// Specific wallet connectors will be added here by implementers
|
|
23
|
+
// e.g., PetraWalletConnector, OKXWalletConnector, etc.
|
|
24
|
+
...fetchInjectedWalletConnectors(props),
|
|
18
25
|
];
|
|
19
26
|
|
|
20
27
|
export { AptosWalletConnectors };
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var walletStandard = require('@aptos-labs/wallet-standard');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
10
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Helper class for managing Aptos wallet provider discovery and interactions.
|
|
14
|
+
*
|
|
15
|
+
* This class handles:
|
|
16
|
+
* - Finding installed wallet providers using legacy injection methods
|
|
17
|
+
* - Managing provider lookups using wallet book configuration
|
|
18
|
+
* - Setting up event listeners for account and network changes
|
|
19
|
+
* - Getting addresses and signing messages through the wallet-standard interface
|
|
20
|
+
*/
|
|
21
|
+
class AptosProviderHelper {
|
|
22
|
+
constructor(connector) {
|
|
23
|
+
this.walletBookWallet = walletBook.findWalletBookWallet(connector.walletBook, connector.key);
|
|
24
|
+
this.connector = connector;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets the installed Aptos provider using legacy injection.
|
|
28
|
+
*/
|
|
29
|
+
getInstalledProvider() {
|
|
30
|
+
return this.getInjectedProvider();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Gets the injected provider using wallet book configuration.
|
|
34
|
+
*/
|
|
35
|
+
getInjectedProvider() {
|
|
36
|
+
const config = this.getInjectedConfig();
|
|
37
|
+
if (!config ||
|
|
38
|
+
!config.extensionLocators ||
|
|
39
|
+
!config.extensionLocators.length)
|
|
40
|
+
return undefined;
|
|
41
|
+
const provider = this.installedProviderLookup(config.extensionLocators);
|
|
42
|
+
return provider;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gets the injected configuration for Aptos from the wallet book.
|
|
46
|
+
*/
|
|
47
|
+
getInjectedConfig() {
|
|
48
|
+
var _a;
|
|
49
|
+
const injectedConfig = (_a = this.walletBookWallet) === null || _a === void 0 ? void 0 : _a.injectedConfig;
|
|
50
|
+
return injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.find((c) => c.chain === 'aptos');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets all installed Aptos providers from various window locations.
|
|
54
|
+
*/
|
|
55
|
+
installedProviders() {
|
|
56
|
+
const config = this.getInjectedConfig();
|
|
57
|
+
if (!config)
|
|
58
|
+
return [];
|
|
59
|
+
const providers = [];
|
|
60
|
+
if (config.windowLocations) {
|
|
61
|
+
for (const windowLocation of config.windowLocations) {
|
|
62
|
+
const foundProviders = utils.getProvidersFromWindow(windowLocation);
|
|
63
|
+
if (foundProviders && foundProviders.length)
|
|
64
|
+
providers.push(...foundProviders);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return providers;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Looks up installed providers using extension locators.
|
|
71
|
+
*/
|
|
72
|
+
installedProviderLookup(extensionLocators) {
|
|
73
|
+
const allInstalledProviders = this.installedProviders();
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
return walletConnectorCore.ProviderLookup(allInstalledProviders, extensionLocators);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Finds the provider using the connector's findProvider method.
|
|
79
|
+
*/
|
|
80
|
+
findProvider() {
|
|
81
|
+
return this.connector.findProvider();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Checks if a provider is installed.
|
|
85
|
+
*/
|
|
86
|
+
isInstalledHelper() {
|
|
87
|
+
return this.findProvider() !== undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Gets the current account address from the wallet.
|
|
91
|
+
*/
|
|
92
|
+
getAddress() {
|
|
93
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const provider = this.findProvider();
|
|
95
|
+
if (!provider) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return this.getAddressWithProvider(provider);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Connects to the Aptos wallet provider.
|
|
103
|
+
*/
|
|
104
|
+
connect() {
|
|
105
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const provider = this.findProvider();
|
|
107
|
+
if (!provider) {
|
|
108
|
+
walletConnectorCore.logger.error('No Aptos provider found to connect', {
|
|
109
|
+
connector: this.connector.name,
|
|
110
|
+
});
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
return provider;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Gets the address using a specific provider.
|
|
118
|
+
*/
|
|
119
|
+
getAddressWithProvider(provider) {
|
|
120
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
try {
|
|
122
|
+
// Try to get account info from the provider
|
|
123
|
+
const accountMethod = provider.account;
|
|
124
|
+
if (accountMethod) {
|
|
125
|
+
const accountInfo = yield accountMethod();
|
|
126
|
+
return accountInfo.address.toString();
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
// "Account not found" is expected when wallet is not connected yet
|
|
132
|
+
const isAccountNotFound = err instanceof Error && err.message === 'Account not found';
|
|
133
|
+
if (isAccountNotFound) {
|
|
134
|
+
walletConnectorCore.logger.debug('[AptosProviderHelper] No account connected yet');
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
walletConnectorCore.logger.error('[AptosProviderHelper] getAddressWithProvider error:', err);
|
|
138
|
+
}
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Signs a message using the Aptos wallet.
|
|
145
|
+
*/
|
|
146
|
+
signMessage(messageToSign) {
|
|
147
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
var _a;
|
|
149
|
+
// Early returns for validation
|
|
150
|
+
const walletAddress = yield this.getAddress();
|
|
151
|
+
if (!walletAddress)
|
|
152
|
+
return undefined;
|
|
153
|
+
const provider = this.findProvider();
|
|
154
|
+
if (!provider)
|
|
155
|
+
return undefined;
|
|
156
|
+
const signMessageMethod = provider.signMessage;
|
|
157
|
+
if (!signMessageMethod) {
|
|
158
|
+
walletConnectorCore.logger.error('[AptosProviderHelper] signMessage not supported');
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
const nonce = new Date().getTime().toString();
|
|
162
|
+
const result = yield signMessageMethod({
|
|
163
|
+
message: messageToSign,
|
|
164
|
+
nonce,
|
|
165
|
+
});
|
|
166
|
+
// Handle UserResponse format
|
|
167
|
+
if (this.isUserResponseApproved(result)) {
|
|
168
|
+
return this.handleUserResponseSignature(result);
|
|
169
|
+
}
|
|
170
|
+
// Handle direct signature format
|
|
171
|
+
if ('signature' in result) {
|
|
172
|
+
return (_a = result.signature) === null || _a === void 0 ? void 0 : _a.toString();
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Checks if the result is an approved UserResponse
|
|
179
|
+
*/
|
|
180
|
+
isUserResponseApproved(result) {
|
|
181
|
+
return (typeof result === 'object' &&
|
|
182
|
+
result !== null &&
|
|
183
|
+
'status' in result &&
|
|
184
|
+
result.status === walletStandard.UserResponseStatus.APPROVED &&
|
|
185
|
+
'args' in result);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Handles UserResponse signature format and returns JSON string
|
|
189
|
+
*/
|
|
190
|
+
handleUserResponseSignature(result) {
|
|
191
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
var _a;
|
|
193
|
+
const resultWithArgs = result;
|
|
194
|
+
const signature = (_a = resultWithArgs.args.signature) === null || _a === void 0 ? void 0 : _a.toString();
|
|
195
|
+
const { fullMessage, publicKey: walletPublicKey } = resultWithArgs.args;
|
|
196
|
+
// Get public key from account if not provided in result
|
|
197
|
+
const publicKey = walletPublicKey || (yield this.getPublicKeyFromAccount());
|
|
198
|
+
return JSON.stringify({
|
|
199
|
+
fullMessage,
|
|
200
|
+
publicKey,
|
|
201
|
+
signature,
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Gets public key from the connected account
|
|
207
|
+
*/
|
|
208
|
+
getPublicKeyFromAccount() {
|
|
209
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
var _a;
|
|
211
|
+
const provider = this.findProvider();
|
|
212
|
+
if (!(provider === null || provider === void 0 ? void 0 : provider.account))
|
|
213
|
+
return undefined;
|
|
214
|
+
try {
|
|
215
|
+
const accountInfo = yield provider.account();
|
|
216
|
+
return (_a = accountInfo.publicKey) === null || _a === void 0 ? void 0 : _a.toString();
|
|
217
|
+
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
walletConnectorCore.logger.debug('Failed to fetch public key:', e);
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Gets connected accounts from the provider.
|
|
226
|
+
*/
|
|
227
|
+
getConnectedAccounts() {
|
|
228
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
const provider = this.findProvider();
|
|
230
|
+
if (!provider)
|
|
231
|
+
return [];
|
|
232
|
+
try {
|
|
233
|
+
const accountMethod = provider.account;
|
|
234
|
+
if (accountMethod) {
|
|
235
|
+
const accountInfo = yield accountMethod();
|
|
236
|
+
return [accountInfo.address.toString()];
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
240
|
+
// This is expected when wallet is not connected yet
|
|
241
|
+
walletConnectorCore.logger.debug('Error getting connected accounts', {
|
|
242
|
+
connector: this.connector,
|
|
243
|
+
error: e,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return [];
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Handles account change events.
|
|
251
|
+
*/
|
|
252
|
+
handleAccountChange(walletConnector, web3Provider, address) {
|
|
253
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
if (!address) {
|
|
255
|
+
yield (web3Provider === null || web3Provider === void 0 ? void 0 : web3Provider.connect());
|
|
256
|
+
const accountMethod = web3Provider === null || web3Provider === void 0 ? void 0 : web3Provider.account;
|
|
257
|
+
if (accountMethod) {
|
|
258
|
+
const accountInfo = yield accountMethod();
|
|
259
|
+
if (accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.address) {
|
|
260
|
+
walletConnector.emit('accountChange', {
|
|
261
|
+
accounts: [accountInfo.address.toString()],
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (address.toString()) {
|
|
268
|
+
walletConnector.emit('accountChange', { accounts: [address.toString()] });
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Sets up event listeners for account and network changes.
|
|
274
|
+
*/
|
|
275
|
+
_setupEventListeners() {
|
|
276
|
+
const provider = this.findProvider();
|
|
277
|
+
if (!provider) {
|
|
278
|
+
walletConnectorCore.logger.warn('Provider not found', {
|
|
279
|
+
connector: this.connector,
|
|
280
|
+
});
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const onAccountChangeMethod = provider === null || provider === void 0 ? void 0 : provider.onAccountChange;
|
|
284
|
+
const onNetworkChangeMethod = provider === null || provider === void 0 ? void 0 : provider.onNetworkChange;
|
|
285
|
+
if (onAccountChangeMethod) {
|
|
286
|
+
onAccountChangeMethod((account) => {
|
|
287
|
+
if (account) {
|
|
288
|
+
this.handleAccountChange(this.connector, provider, account.address.toString());
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
this.connector.emit('disconnect');
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (onNetworkChangeMethod) {
|
|
296
|
+
onNetworkChangeMethod((network) => {
|
|
297
|
+
if (network.chainId) {
|
|
298
|
+
this.connector.emit('chainChange', {
|
|
299
|
+
chain: network.chainId.toString(),
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Tears down event listeners.
|
|
307
|
+
*/
|
|
308
|
+
_teardownEventListeners() {
|
|
309
|
+
const provider = this.findProvider();
|
|
310
|
+
if (!provider)
|
|
311
|
+
return;
|
|
312
|
+
// Aptos providers don't have removeAllListeners like Solana
|
|
313
|
+
// Event listeners are automatically cleaned up when the provider is destroyed
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
exports.AptosProviderHelper = AptosProviderHelper;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { ProviderCondition, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import type { ExtensionLocator, IAptosProvider } from '../types';
|
|
3
|
+
import type { InjectedWalletBase } from './InjectedWalletBase';
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for managing Aptos wallet provider discovery and interactions.
|
|
6
|
+
*
|
|
7
|
+
* This class handles:
|
|
8
|
+
* - Finding installed wallet providers using legacy injection methods
|
|
9
|
+
* - Managing provider lookups using wallet book configuration
|
|
10
|
+
* - Setting up event listeners for account and network changes
|
|
11
|
+
* - Getting addresses and signing messages through the wallet-standard interface
|
|
12
|
+
*/
|
|
13
|
+
export declare class AptosProviderHelper {
|
|
14
|
+
private walletBookWallet;
|
|
15
|
+
private connector;
|
|
16
|
+
constructor(connector: InjectedWalletBase);
|
|
17
|
+
/**
|
|
18
|
+
* Gets the installed Aptos provider using legacy injection.
|
|
19
|
+
*/
|
|
20
|
+
getInstalledProvider(): IAptosProvider | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the injected provider using wallet book configuration.
|
|
23
|
+
*/
|
|
24
|
+
getInjectedProvider(): IAptosProvider | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Gets the injected configuration for Aptos from the wallet book.
|
|
27
|
+
*/
|
|
28
|
+
getInjectedConfig(): {
|
|
29
|
+
chain: string;
|
|
30
|
+
extensionLocators: {
|
|
31
|
+
flag: string;
|
|
32
|
+
value: boolean;
|
|
33
|
+
}[];
|
|
34
|
+
providerInterface?: string | undefined;
|
|
35
|
+
walletStandard?: {
|
|
36
|
+
features: string[];
|
|
37
|
+
name: string;
|
|
38
|
+
providerId?: string | undefined;
|
|
39
|
+
} | undefined;
|
|
40
|
+
walletStandardLocators?: {
|
|
41
|
+
locator: string;
|
|
42
|
+
name: string;
|
|
43
|
+
}[] | undefined;
|
|
44
|
+
windowLocations?: string[] | undefined;
|
|
45
|
+
} | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Gets all installed Aptos providers from various window locations.
|
|
48
|
+
*/
|
|
49
|
+
installedProviders(): IAptosProvider[];
|
|
50
|
+
/**
|
|
51
|
+
* Looks up installed providers using extension locators.
|
|
52
|
+
*/
|
|
53
|
+
installedProviderLookup(extensionLocators: Array<ProviderCondition<ExtensionLocator>>): IAptosProvider | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Finds the provider using the connector's findProvider method.
|
|
56
|
+
*/
|
|
57
|
+
findProvider(): IAptosProvider | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a provider is installed.
|
|
60
|
+
*/
|
|
61
|
+
isInstalledHelper(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the current account address from the wallet.
|
|
64
|
+
*/
|
|
65
|
+
getAddress(): Promise<string | undefined>;
|
|
66
|
+
/**
|
|
67
|
+
* Connects to the Aptos wallet provider.
|
|
68
|
+
*/
|
|
69
|
+
connect(): Promise<IAptosProvider | undefined>;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the address using a specific provider.
|
|
72
|
+
*/
|
|
73
|
+
getAddressWithProvider(provider: IAptosProvider): Promise<string | undefined>;
|
|
74
|
+
/**
|
|
75
|
+
* Signs a message using the Aptos wallet.
|
|
76
|
+
*/
|
|
77
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
78
|
+
/**
|
|
79
|
+
* Checks if the result is an approved UserResponse
|
|
80
|
+
*/
|
|
81
|
+
private isUserResponseApproved;
|
|
82
|
+
/**
|
|
83
|
+
* Handles UserResponse signature format and returns JSON string
|
|
84
|
+
*/
|
|
85
|
+
private handleUserResponseSignature;
|
|
86
|
+
/**
|
|
87
|
+
* Gets public key from the connected account
|
|
88
|
+
*/
|
|
89
|
+
private getPublicKeyFromAccount;
|
|
90
|
+
/**
|
|
91
|
+
* Gets connected accounts from the provider.
|
|
92
|
+
*/
|
|
93
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Handles account change events.
|
|
96
|
+
*/
|
|
97
|
+
handleAccountChange(walletConnector: WalletConnector, web3Provider: IAptosProvider, address: string): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Sets up event listeners for account and network changes.
|
|
100
|
+
*/
|
|
101
|
+
_setupEventListeners(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Tears down event listeners.
|
|
104
|
+
*/
|
|
105
|
+
_teardownEventListeners(): void;
|
|
106
|
+
}
|