@dynamic-labs/aptos 4.38.0 → 4.40.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 +21 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +7 -3
- package/src/connectors/AptosWalletConnector/AptosWalletConnector.cjs +208 -0
- package/src/connectors/AptosWalletConnector/AptosWalletConnector.d.ts +71 -0
- package/src/connectors/AptosWalletConnector/AptosWalletConnector.js +204 -0
- package/src/connectors/AptosWalletConnector/index.d.ts +1 -0
- package/src/consts/index.cjs +19 -0
- package/src/consts/index.js +15 -0
- package/src/index.cjs +27 -6
- package/src/index.d.ts +10 -1
- package/src/index.js +19 -6
- 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 +33 -113
- package/src/utils/assertProvider/assertProvider.cjs +36 -0
- package/src/utils/assertProvider/assertProvider.d.ts +6 -5
- package/src/utils/assertProvider/assertProvider.js +32 -0
- package/src/utils/getWalletStandardWallets/getWalletStandardWallets.cjs +68 -0
- package/src/utils/getWalletStandardWallets/getWalletStandardWallets.js +64 -0
- package/src/utils/invokeWalletMethod/invokeWalletMethod.cjs +61 -0
- package/src/utils/invokeWalletMethod/invokeWalletMethod.d.ts +6 -7
- package/src/utils/invokeWalletMethod/invokeWalletMethod.js +57 -0
- package/src/utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.cjs +10 -0
- package/src/utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.js +6 -0
- package/src/utils/parseConnectionResult/parseConnectionResult.cjs +40 -0
- package/src/utils/parseConnectionResult/parseConnectionResult.d.ts +7 -10
- package/src/utils/parseConnectionResult/parseConnectionResult.js +36 -0
- package/src/utils/parseTransactionResponse/parseTransactionResponse.cjs +53 -0
- package/src/utils/parseTransactionResponse/parseTransactionResponse.d.ts +3 -3
- package/src/utils/parseTransactionResponse/parseTransactionResponse.js +49 -0
- package/src/wallet/AptosWallet.cjs +138 -0
- package/src/wallet/AptosWallet.d.ts +76 -0
- package/src/wallet/AptosWallet.js +134 -0
- package/src/wallet/index.d.ts +1 -0
- 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/src/connectors/index.d.ts +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
2
|
+
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
/**
|
|
4
|
+
* Array of wallet connector constructors that have custom implementations.
|
|
5
|
+
* These wallets override the default wallet-standard behavior.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* export const injectedWalletOverrides: WalletConnectorConstructor[] = [
|
|
10
|
+
* PetraWallet,
|
|
11
|
+
* OKXAptosWallet,
|
|
12
|
+
* ];
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const injectedWalletOverrides: WalletConnectorConstructor[];
|
|
16
|
+
/**
|
|
17
|
+
* Fetches all available injected Aptos wallet connectors.
|
|
18
|
+
*
|
|
19
|
+
* This function discovers and creates wallet connector constructors from two sources:
|
|
20
|
+
* 1. Wallet book entries - Traditional wallets defined in the wallet book
|
|
21
|
+
* 2. Wallet-standard wallets - AIP-62 compliant wallets discovered via wallet-standard
|
|
22
|
+
*
|
|
23
|
+
* The function automatically filters out wallets that:
|
|
24
|
+
* - Have custom connector implementations
|
|
25
|
+
* - Are already handled by wallet-standard connectors
|
|
26
|
+
* - Don't support the required Aptos feature set
|
|
27
|
+
*
|
|
28
|
+
* @param options - Configuration options
|
|
29
|
+
* @param options.walletBook - The wallet book schema containing wallet metadata
|
|
30
|
+
* @param options.authMode - The authentication mode for filtering wallet features
|
|
31
|
+
* @returns Array of wallet connector constructor classes
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const connectors = fetchInjectedWalletConnectors({
|
|
36
|
+
* walletBook,
|
|
37
|
+
* authMode: 'connect-and-sign'
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Instantiate connectors
|
|
41
|
+
* connectors.forEach(Connector => {
|
|
42
|
+
* const instance = new Connector(aptosWalletConnectorProps);
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const fetchInjectedWalletConnectors: ({ walletBook, }: {
|
|
47
|
+
walletBook: WalletBookSchema;
|
|
48
|
+
}) => WalletConnectorConstructor[];
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { findWalletBookWalletByNameAndChain } from '@dynamic-labs/wallet-book';
|
|
3
|
+
import { getWalletMetadataFromWalletBook } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { sanitizeName } from '@dynamic-labs/utils';
|
|
5
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
6
|
+
import { getWalletStandardWallets } from '../utils/getWalletStandardWallets/getWalletStandardWallets.js';
|
|
7
|
+
import { isWalletWithRequiredFeatureSet } from '../utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.js';
|
|
8
|
+
import { REQUIRED_FEATURES } from '../consts/index.js';
|
|
9
|
+
import { getConnectorConstructorForWalletStandardWallet } from '../walletStandard/getConnectorConstructorForWalletStandardWallet.js';
|
|
10
|
+
import { InjectedWalletBase } from './InjectedWalletBase.js';
|
|
11
|
+
|
|
12
|
+
const logger = new Logger('fetchInjectedWalletConnectors');
|
|
13
|
+
/**
|
|
14
|
+
* List of wallet keys that have custom connector implementations.
|
|
15
|
+
* These wallets will not use the automatic wallet-standard connector.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const walletsWithCustomConnectors: string[] = [
|
|
20
|
+
* 'petra',
|
|
21
|
+
* 'okxaptos',
|
|
22
|
+
* ];
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const walletsWithCustomConnectors = [
|
|
26
|
+
// Add wallet keys here that need custom connectors
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Determines whether a wallet-standard wallet should have a connector created for it.
|
|
30
|
+
*
|
|
31
|
+
* @param wallet - The wallet-standard wallet to check
|
|
32
|
+
* @param walletBook - The wallet book schema containing wallet metadata
|
|
33
|
+
* @param authMode - The authentication mode (optional, for future feature filtering)
|
|
34
|
+
* @returns True if a wallet-standard connector should be created
|
|
35
|
+
*/
|
|
36
|
+
const shouldAddWalletStandardConnector = (wallet, walletBook) => {
|
|
37
|
+
var _a;
|
|
38
|
+
const { name } = wallet;
|
|
39
|
+
const chain = 'aptos';
|
|
40
|
+
const connectorKey = `${sanitizeName(name)}${chain}`;
|
|
41
|
+
logger.logVerboseTroubleshootingMessage('[APTOS shouldAddWalletStandardConnector] Checking wallet:', { chain, connectorKey, features: Object.keys(wallet.features), name });
|
|
42
|
+
const shouldHandleWalletFromWalletBook = ([key, walletEntry]) => {
|
|
43
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
44
|
+
const hasMatchingKey = key === connectorKey;
|
|
45
|
+
const needsCustomConnector = walletsWithCustomConnectors.includes(connectorKey);
|
|
46
|
+
const hasMatchingNameAndChain = walletEntry.name === name &&
|
|
47
|
+
((_b = (_a = walletEntry.injectedConfig) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.chain) === chain;
|
|
48
|
+
// If the wallet supports wallet-standard, we want to add the wallet-standard connector
|
|
49
|
+
// and not handle it as a default wallet-book wallet
|
|
50
|
+
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);
|
|
51
|
+
// If injectedConfig is missing, it's not a traditional wallet book entry
|
|
52
|
+
const hasInjectedConfig = Boolean((_g = walletEntry.injectedConfig) === null || _g === void 0 ? void 0 : _g.length);
|
|
53
|
+
// If the chain doesn't match, it should be handled by wallet-standard
|
|
54
|
+
const hasMatchingChain = ((_j = (_h = walletEntry.injectedConfig) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.chain) === chain;
|
|
55
|
+
return ((hasMatchingKey || needsCustomConnector || hasMatchingNameAndChain) &&
|
|
56
|
+
hasInjectedConfig &&
|
|
57
|
+
hasMatchingChain &&
|
|
58
|
+
isNotWalletStandard);
|
|
59
|
+
};
|
|
60
|
+
const shouldHandleFromWalletBook = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {}).find(shouldHandleWalletFromWalletBook);
|
|
61
|
+
// Check if wallet has all required features based on auth mode
|
|
62
|
+
const additionalFeatures = [];
|
|
63
|
+
const hasAllFeatures = isWalletWithRequiredFeatureSet(wallet, additionalFeatures);
|
|
64
|
+
logger.logVerboseTroubleshootingMessage('[APTOS shouldAddWalletStandardConnector] Decision:', {
|
|
65
|
+
hasAllFeatures,
|
|
66
|
+
requiredFeatures: [...REQUIRED_FEATURES, ...additionalFeatures],
|
|
67
|
+
shouldAdd: !shouldHandleFromWalletBook && hasAllFeatures,
|
|
68
|
+
shouldHandleFromWalletBook: Boolean(shouldHandleFromWalletBook),
|
|
69
|
+
});
|
|
70
|
+
return !shouldHandleFromWalletBook && hasAllFeatures;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Fetches all available injected Aptos wallet connectors.
|
|
74
|
+
*
|
|
75
|
+
* This function discovers and creates wallet connector constructors from two sources:
|
|
76
|
+
* 1. Wallet book entries - Traditional wallets defined in the wallet book
|
|
77
|
+
* 2. Wallet-standard wallets - AIP-62 compliant wallets discovered via wallet-standard
|
|
78
|
+
*
|
|
79
|
+
* The function automatically filters out wallets that:
|
|
80
|
+
* - Have custom connector implementations
|
|
81
|
+
* - Are already handled by wallet-standard connectors
|
|
82
|
+
* - Don't support the required Aptos feature set
|
|
83
|
+
*
|
|
84
|
+
* @param options - Configuration options
|
|
85
|
+
* @param options.walletBook - The wallet book schema containing wallet metadata
|
|
86
|
+
* @param options.authMode - The authentication mode for filtering wallet features
|
|
87
|
+
* @returns Array of wallet connector constructor classes
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const connectors = fetchInjectedWalletConnectors({
|
|
92
|
+
* walletBook,
|
|
93
|
+
* authMode: 'connect-and-sign'
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* // Instantiate connectors
|
|
97
|
+
* connectors.forEach(Connector => {
|
|
98
|
+
* const instance = new Connector(aptosWalletConnectorProps);
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
const fetchInjectedWalletConnectors = ({ walletBook, }) => {
|
|
103
|
+
var _a;
|
|
104
|
+
// Get wallet book connectors for traditional Aptos wallets
|
|
105
|
+
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
106
|
+
.filter(([key, wallet]) => {
|
|
107
|
+
var _a, _b, _c;
|
|
108
|
+
const injectedConfig = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'aptos');
|
|
109
|
+
const isAptosWallet = Boolean(injectedConfig);
|
|
110
|
+
// Filter out wallets that require a custom connector or wallets that support wallet-standard,
|
|
111
|
+
// since they are already handled automatically with the wallet-standard connector
|
|
112
|
+
const shouldBeFiltered = walletsWithCustomConnectors.includes(key) ||
|
|
113
|
+
((_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);
|
|
114
|
+
return isAptosWallet && !shouldBeFiltered;
|
|
115
|
+
})
|
|
116
|
+
.map(([key, wallet]) => {
|
|
117
|
+
const { shortName } = wallet;
|
|
118
|
+
const name = shortName || wallet.name;
|
|
119
|
+
return class extends InjectedWalletBase {
|
|
120
|
+
constructor() {
|
|
121
|
+
super(...arguments);
|
|
122
|
+
this.name = name;
|
|
123
|
+
// This is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
124
|
+
this.overrideKey = key;
|
|
125
|
+
}
|
|
126
|
+
getProvider() {
|
|
127
|
+
return this.findProvider();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
// Get wallet-standard wallets
|
|
132
|
+
const { aptosWallets } = getWalletStandardWallets();
|
|
133
|
+
logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Found wallet-standard wallets:', aptosWallets.map((w) => ({
|
|
134
|
+
features: Object.keys(w.features),
|
|
135
|
+
name: w.name,
|
|
136
|
+
})));
|
|
137
|
+
// Create connectors for wallet-standard wallets
|
|
138
|
+
const walletStandardConnectors = aptosWallets
|
|
139
|
+
.filter((wallet) =>
|
|
140
|
+
// Type incompatibility between @wallet-standard versions, casting is safe here
|
|
141
|
+
shouldAddWalletStandardConnector(
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
143
|
+
wallet, walletBook))
|
|
144
|
+
.map((wallet) => {
|
|
145
|
+
const walletBookWallet = findWalletBookWalletByNameAndChain(walletBook, wallet.name, 'aptos');
|
|
146
|
+
// If the wallet book wallet is found, we want to use it to get the metadata
|
|
147
|
+
// to merge with the wallet-standard metadata, especially for additional properties
|
|
148
|
+
const walletBookMetadata = walletBookWallet &&
|
|
149
|
+
getWalletMetadataFromWalletBook({
|
|
150
|
+
walletBook,
|
|
151
|
+
walletBookWallet,
|
|
152
|
+
walletKey: `${sanitizeName(wallet.name)}aptos`,
|
|
153
|
+
});
|
|
154
|
+
// Type incompatibility between @wallet-standard versions, casting is safe here
|
|
155
|
+
return getConnectorConstructorForWalletStandardWallet(
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
157
|
+
wallet, walletBookMetadata);
|
|
158
|
+
});
|
|
159
|
+
logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Created wallet-standard connectors:', walletStandardConnectors.map((w) => w.name));
|
|
160
|
+
logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Created wallet-book connectors:', walletBookConnectors.map((w) => w.name));
|
|
161
|
+
return [
|
|
162
|
+
...walletBookConnectors,
|
|
163
|
+
...walletStandardConnectors,
|
|
164
|
+
];
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export { fetchInjectedWalletConnectors };
|
package/src/types.d.ts
CHANGED
|
@@ -1,61 +1,36 @@
|
|
|
1
1
|
import type { AccountAuthenticator, AnyRawTransaction } from '@aptos-labs/ts-sdk';
|
|
2
2
|
import type { AccountInfo, AptosSignMessageInput, AptosSignMessageOutput, NetworkInfo, UserResponse } from '@aptos-labs/wallet-standard';
|
|
3
|
+
import { ProviderCondition } from '@dynamic-labs/wallet-connector-core';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
declare global {
|
|
7
|
-
interface Window {
|
|
8
|
-
aptos?: IAptosProvider;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Interface that all Aptos wallet providers must implement.
|
|
13
|
-
*
|
|
14
|
-
* This interface is designed to work with both wallet-standard compliant wallets
|
|
15
|
-
* and injected providers (like OKX, Petra, etc.). It supports the core methods
|
|
16
|
-
* needed for Aptos wallet functionality while maintaining flexibility for different
|
|
17
|
-
* wallet implementations.
|
|
5
|
+
* Interface for AIP-62 compliant Aptos wallet providers.
|
|
18
6
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* - **Injected Providers**: Wallets that inject methods directly (like OKX, Petra legacy)
|
|
7
|
+
* This interface is designed to work exclusively with wallet-standard compliant wallets
|
|
8
|
+
* that implement AIP-62. All major Aptos wallets now support this standard, including:
|
|
9
|
+
* OKX, AptosConnect, Petra, Nightly, Pontem, RimoSafe, MSafe, Bitget, and Backpack.
|
|
23
10
|
*
|
|
24
11
|
* ## Core Features
|
|
25
12
|
* - **Connection Management**: Connect, disconnect, and account retrieval
|
|
26
13
|
* - **Network Support**: Network information and switching capabilities
|
|
27
14
|
* - **Transaction Signing**: Support for transaction and message signing
|
|
28
15
|
* - **Event Handling**: Account and network change listeners
|
|
29
|
-
* - **Flexible Returns**: Support for different response formats
|
|
30
16
|
*
|
|
31
17
|
* @example
|
|
32
18
|
* ```typescript
|
|
33
|
-
* //
|
|
34
|
-
* const result = await provider.connect();
|
|
19
|
+
* // Connect to wallet using wallet-standard
|
|
20
|
+
* const result = await provider.features['aptos:connect']?.connect();
|
|
35
21
|
*
|
|
36
22
|
* // Sign a transaction
|
|
37
|
-
* const signature = await provider.signTransaction(transaction);
|
|
23
|
+
* const signature = await provider.features['aptos:signTransaction']?.signTransaction(transaction);
|
|
38
24
|
*
|
|
39
25
|
* // Sign a message
|
|
40
|
-
* const messageSignature = await provider.signMessage({
|
|
26
|
+
* const messageSignature = await provider.features['aptos:signMessage']?.signMessage({
|
|
41
27
|
* message: "Hello Aptos",
|
|
42
28
|
* nonce: "12345"
|
|
43
29
|
* });
|
|
44
|
-
*
|
|
45
|
-
* // Listen for account changes
|
|
46
|
-
* provider.onAccountChange?.((account) => {
|
|
47
|
-
* console.log('Account changed:', account);
|
|
48
|
-
* });
|
|
49
30
|
* ```
|
|
50
31
|
*/
|
|
51
32
|
export interface IAptosProvider {
|
|
52
|
-
/**
|
|
53
|
-
isConnected?: boolean;
|
|
54
|
-
/** The current network information */
|
|
55
|
-
network?: NetworkInfo;
|
|
56
|
-
/** The current account information */
|
|
57
|
-
account?: AccountInfo;
|
|
58
|
-
/** Wallet-standard features (for AIP-62 compliant wallets) */
|
|
33
|
+
/** Wallet-standard features (AIP-62 compliant wallets) */
|
|
59
34
|
features?: {
|
|
60
35
|
'aptos:connect'?: {
|
|
61
36
|
version: string;
|
|
@@ -104,86 +79,24 @@ export interface IAptosProvider {
|
|
|
104
79
|
getNetwork(): Promise<NetworkInfo>;
|
|
105
80
|
};
|
|
106
81
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*/
|
|
121
|
-
getAccount?(): Promise<AccountInfo>;
|
|
122
|
-
/**
|
|
123
|
-
* Retrieves the current network information
|
|
124
|
-
* @returns Promise resolving to network information
|
|
125
|
-
*/
|
|
126
|
-
getNetwork?(): Promise<NetworkInfo>;
|
|
127
|
-
/**
|
|
128
|
-
* Signs a transaction for submission to the network
|
|
129
|
-
* @param transaction - Transaction to sign
|
|
130
|
-
* @param asFeePayer - Whether signing as fee payer (optional)
|
|
131
|
-
* @returns Promise resolving to signed transaction or user response
|
|
132
|
-
*/
|
|
133
|
-
signTransaction(transaction: AnyRawTransaction, asFeePayer?: boolean): Promise<UserResponse<AccountAuthenticator> | AccountAuthenticator>;
|
|
134
|
-
/**
|
|
135
|
-
* Signs a message for authentication purposes
|
|
136
|
-
* @param input - Message signing input parameters
|
|
137
|
-
* @returns Promise resolving to signature result or user response
|
|
138
|
-
*/
|
|
139
|
-
signMessage(input: AptosSignMessageInput): Promise<UserResponse<AptosSignMessageOutput> | AptosSignMessageOutput>;
|
|
140
|
-
/**
|
|
141
|
-
* Submits a signed transaction to the network
|
|
142
|
-
* @param transaction - Signed transaction to submit
|
|
143
|
-
* @returns Promise resolving to transaction hash
|
|
144
|
-
*/
|
|
145
|
-
submitTransaction?(transaction: AccountAuthenticator): Promise<string>;
|
|
146
|
-
/**
|
|
147
|
-
* Signs and submits a transaction in one call
|
|
148
|
-
* @param transaction - Transaction to sign and submit
|
|
149
|
-
* @returns Promise resolving to transaction hash
|
|
150
|
-
*/
|
|
151
|
-
signAndSubmitTransaction?(transaction: AnyRawTransaction): Promise<string>;
|
|
152
|
-
/**
|
|
153
|
-
* Switches to a different Aptos network
|
|
154
|
-
* @param network - Network to switch to
|
|
155
|
-
* @returns Promise that resolves when network is switched
|
|
156
|
-
*/
|
|
157
|
-
changeNetwork?(network: NetworkInfo | string): Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Listen for account changes
|
|
160
|
-
* @param callback - Callback function for account changes
|
|
161
|
-
* @returns Cleanup function to remove listener
|
|
162
|
-
*/
|
|
163
|
-
onAccountChange?(callback: (account: AccountInfo | null) => void): (() => void) | void;
|
|
164
|
-
/**
|
|
165
|
-
* Listen for network changes
|
|
166
|
-
* @param callback - Callback function for network changes
|
|
167
|
-
* @returns Cleanup function to remove listener
|
|
168
|
-
*/
|
|
169
|
-
onNetworkChange?(callback: (network: NetworkInfo) => void): (() => void) | void;
|
|
170
|
-
/**
|
|
171
|
-
* Generic request method for custom wallet operations
|
|
172
|
-
* @param method - The method name to call
|
|
173
|
-
* @param params - Optional parameters for the method
|
|
174
|
-
* @returns Promise resolving to the method result
|
|
175
|
-
*/
|
|
176
|
-
request?(method: string, params?: unknown): Promise<unknown>;
|
|
177
|
-
/** Additional properties that providers may implement */
|
|
178
|
-
[key: string]: unknown;
|
|
82
|
+
account: () => Promise<AccountInfo>;
|
|
83
|
+
connect: () => Promise<UserResponse<AccountInfo>>;
|
|
84
|
+
disconnect: () => Promise<void>;
|
|
85
|
+
signTransaction(transaction: AnyRawTransaction, asFeePayer?: boolean): Promise<UserResponse<AccountAuthenticator>>;
|
|
86
|
+
signMessage(input: AptosSignMessageInput): Promise<UserResponse<AptosSignMessageOutput>>;
|
|
87
|
+
signAndSubmitTransaction(transaction: AnyRawTransaction): Promise<UserResponse<{
|
|
88
|
+
hash: string;
|
|
89
|
+
}>>;
|
|
90
|
+
getNetwork?: () => Promise<NetworkInfo>;
|
|
91
|
+
onAccountChange?: (callback: (account: AccountInfo | null) => void) => void;
|
|
92
|
+
onNetworkChange?: (callback: (network: NetworkInfo) => void) => void;
|
|
93
|
+
onDisconnect?: (callback: () => void) => void;
|
|
94
|
+
isConnected?: () => Promise<boolean>;
|
|
179
95
|
}
|
|
180
96
|
/**
|
|
181
|
-
* Result from wallet connection
|
|
97
|
+
* Result from wallet connection (wallet-standard only)
|
|
182
98
|
*/
|
|
183
|
-
export type AptosConnectionResult = UserResponse<AccountInfo
|
|
184
|
-
address: string;
|
|
185
|
-
publicKey?: string | Uint8Array;
|
|
186
|
-
} | string;
|
|
99
|
+
export type AptosConnectionResult = UserResponse<AccountInfo>;
|
|
187
100
|
/**
|
|
188
101
|
* Props for sending APT or token balance
|
|
189
102
|
*/
|
|
@@ -212,4 +125,11 @@ export interface AptosWalletConnectorProps {
|
|
|
212
125
|
metadata?: any;
|
|
213
126
|
}
|
|
214
127
|
export type AptosFeatureName = keyof NonNullable<IAptosProvider['features']>;
|
|
215
|
-
export type AptosMethodName = 'connect' | 'disconnect' | 'signTransaction' | 'signMessage' | 'signAndSubmitTransaction' | 'submitTransaction' | 'getNetwork' | 'network';
|
|
128
|
+
export type AptosMethodName = 'connect' | 'disconnect' | 'signTransaction' | 'signMessage' | 'signAndSubmitTransaction' | 'submitTransaction' | 'getNetwork' | 'network' | 'account' | 'onAccountChange' | 'onNetworkChange';
|
|
129
|
+
/**
|
|
130
|
+
* Extension locators for identifying Aptos wallet browser extensions.
|
|
131
|
+
* These flags are typically set on the injected provider object to identify
|
|
132
|
+
* which wallet extension is present.
|
|
133
|
+
*/
|
|
134
|
+
export type ExtensionLocator = 'isPetraWallet' | 'isNightlyWallet' | 'isPontemWallet' | 'isMartianWallet' | 'isFewchaWallet' | 'isRiseWallet' | 'isMSafeWallet' | 'isOkxWallet' | 'isBitgetWallet' | 'isBackpackWallet';
|
|
135
|
+
export type AptosProviderCondition = ProviderCondition<ExtensionLocator>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Asserts that an AIP-62 compliant wallet provider is available and throws a consistent error if not.
|
|
10
|
+
*
|
|
11
|
+
* This utility function eliminates repetitive provider checking throughout the codebase
|
|
12
|
+
* by providing a centralized assertion with consistent error messaging. After calling
|
|
13
|
+
* this function, TypeScript will know that the provider is guaranteed to be non-null
|
|
14
|
+
* and has the required wallet-standard features.
|
|
15
|
+
*
|
|
16
|
+
* @param provider - The wallet provider to check, may be undefined
|
|
17
|
+
* @throws {DynamicError} When the provider is undefined, null, or missing features
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const provider = getProvider();
|
|
22
|
+
* assertProvider(provider);
|
|
23
|
+
* // TypeScript now knows provider is not undefined and has features
|
|
24
|
+
* await provider.features['aptos:connect']?.connect();
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const assertProvider = (provider) => {
|
|
28
|
+
if (!provider) {
|
|
29
|
+
throw new utils.DynamicError('No wallet provider available');
|
|
30
|
+
}
|
|
31
|
+
if (!provider.features) {
|
|
32
|
+
throw new utils.DynamicError('Wallet provider does not support AIP-62 wallet standard');
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.assertProvider = assertProvider;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import type { IAptosProvider } from '../../types';
|
|
2
2
|
/**
|
|
3
|
-
* Asserts that
|
|
3
|
+
* Asserts that an AIP-62 compliant wallet provider is available and throws a consistent error if not.
|
|
4
4
|
*
|
|
5
5
|
* This utility function eliminates repetitive provider checking throughout the codebase
|
|
6
6
|
* by providing a centralized assertion with consistent error messaging. After calling
|
|
7
|
-
* this function, TypeScript will know that the provider is guaranteed to be non-null
|
|
7
|
+
* this function, TypeScript will know that the provider is guaranteed to be non-null
|
|
8
|
+
* and has the required wallet-standard features.
|
|
8
9
|
*
|
|
9
10
|
* @param provider - The wallet provider to check, may be undefined
|
|
10
|
-
* @throws {DynamicError} When the provider is undefined or
|
|
11
|
+
* @throws {DynamicError} When the provider is undefined, null, or missing features
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* ```typescript
|
|
14
15
|
* const provider = getProvider();
|
|
15
16
|
* assertProvider(provider);
|
|
16
|
-
* // TypeScript now knows provider is not undefined
|
|
17
|
-
* await provider.connect();
|
|
17
|
+
* // TypeScript now knows provider is not undefined and has features
|
|
18
|
+
* await provider.features['aptos:connect']?.connect();
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
21
|
export declare const assertProvider: (provider: IAptosProvider | undefined) => asserts provider is IAptosProvider;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Asserts that an AIP-62 compliant wallet provider is available and throws a consistent error if not.
|
|
6
|
+
*
|
|
7
|
+
* This utility function eliminates repetitive provider checking throughout the codebase
|
|
8
|
+
* by providing a centralized assertion with consistent error messaging. After calling
|
|
9
|
+
* this function, TypeScript will know that the provider is guaranteed to be non-null
|
|
10
|
+
* and has the required wallet-standard features.
|
|
11
|
+
*
|
|
12
|
+
* @param provider - The wallet provider to check, may be undefined
|
|
13
|
+
* @throws {DynamicError} When the provider is undefined, null, or missing features
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const provider = getProvider();
|
|
18
|
+
* assertProvider(provider);
|
|
19
|
+
* // TypeScript now knows provider is not undefined and has features
|
|
20
|
+
* await provider.features['aptos:connect']?.connect();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const assertProvider = (provider) => {
|
|
24
|
+
if (!provider) {
|
|
25
|
+
throw new DynamicError('No wallet provider available');
|
|
26
|
+
}
|
|
27
|
+
if (!provider.features) {
|
|
28
|
+
throw new DynamicError('Wallet provider does not support AIP-62 wallet standard');
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { assertProvider };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var walletStandard = require('@aptos-labs/wallet-standard');
|
|
7
|
+
var logger$1 = require('@dynamic-labs/logger');
|
|
8
|
+
|
|
9
|
+
const logger = new logger$1.Logger('getWalletStandardWallets');
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves all available Aptos-compatible wallets from the wallet standard registry.
|
|
12
|
+
*
|
|
13
|
+
* This function fetches all registered wallets and filters them to return only those
|
|
14
|
+
* that support the required Aptos feature set. It also provides an event listener
|
|
15
|
+
* function to monitor wallet registration events.
|
|
16
|
+
*
|
|
17
|
+
* @returns An object containing:
|
|
18
|
+
* - `aptosWallets`: Array of Aptos-compatible wallets that support required features
|
|
19
|
+
* - `on`: Event listener function to subscribe to wallet registration/unregistration events
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const { aptosWallets, on } = getWalletStandardWallets();
|
|
24
|
+
*
|
|
25
|
+
* // Use the Aptos wallets
|
|
26
|
+
* console.log('Available Aptos wallets:', aptosWallets);
|
|
27
|
+
*
|
|
28
|
+
* // Listen for new wallet registrations
|
|
29
|
+
* const unsubscribe = on('register', (wallet) => {
|
|
30
|
+
* console.log('New wallet registered:', wallet);
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Clean up listener when done
|
|
34
|
+
* unsubscribe();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const getWalletStandardWallets = () => {
|
|
38
|
+
try {
|
|
39
|
+
const { aptosWallets } = walletStandard.getAptosWallets();
|
|
40
|
+
const foundAptosWallets = [];
|
|
41
|
+
aptosWallets.map((wallet) => {
|
|
42
|
+
try {
|
|
43
|
+
const isAptos = walletStandard.isWalletWithRequiredFeatureSet(wallet);
|
|
44
|
+
if (isAptos) {
|
|
45
|
+
foundAptosWallets.push(wallet);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
// Log error for individual wallet but continue processing others
|
|
50
|
+
logger.debug('[getWalletStandardWallets] Error checking wallet features:', error);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
aptosWallets: foundAptosWallets,
|
|
55
|
+
on: () => () => { },
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
// If wallet discovery fails completely, return empty array
|
|
60
|
+
logger.error('[getWalletStandardWallets] Failed to discover wallets:', error);
|
|
61
|
+
return {
|
|
62
|
+
aptosWallets: [],
|
|
63
|
+
on: () => () => { },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
exports.getWalletStandardWallets = getWalletStandardWallets;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { getAptosWallets, isWalletWithRequiredFeatureSet } from '@aptos-labs/wallet-standard';
|
|
3
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
4
|
+
|
|
5
|
+
const logger = new Logger('getWalletStandardWallets');
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves all available Aptos-compatible wallets from the wallet standard registry.
|
|
8
|
+
*
|
|
9
|
+
* This function fetches all registered wallets and filters them to return only those
|
|
10
|
+
* that support the required Aptos feature set. It also provides an event listener
|
|
11
|
+
* function to monitor wallet registration events.
|
|
12
|
+
*
|
|
13
|
+
* @returns An object containing:
|
|
14
|
+
* - `aptosWallets`: Array of Aptos-compatible wallets that support required features
|
|
15
|
+
* - `on`: Event listener function to subscribe to wallet registration/unregistration events
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const { aptosWallets, on } = getWalletStandardWallets();
|
|
20
|
+
*
|
|
21
|
+
* // Use the Aptos wallets
|
|
22
|
+
* console.log('Available Aptos wallets:', aptosWallets);
|
|
23
|
+
*
|
|
24
|
+
* // Listen for new wallet registrations
|
|
25
|
+
* const unsubscribe = on('register', (wallet) => {
|
|
26
|
+
* console.log('New wallet registered:', wallet);
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Clean up listener when done
|
|
30
|
+
* unsubscribe();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
const getWalletStandardWallets = () => {
|
|
34
|
+
try {
|
|
35
|
+
const { aptosWallets } = getAptosWallets();
|
|
36
|
+
const foundAptosWallets = [];
|
|
37
|
+
aptosWallets.map((wallet) => {
|
|
38
|
+
try {
|
|
39
|
+
const isAptos = isWalletWithRequiredFeatureSet(wallet);
|
|
40
|
+
if (isAptos) {
|
|
41
|
+
foundAptosWallets.push(wallet);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
// Log error for individual wallet but continue processing others
|
|
46
|
+
logger.debug('[getWalletStandardWallets] Error checking wallet features:', error);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
aptosWallets: foundAptosWallets,
|
|
51
|
+
on: () => () => { },
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
// If wallet discovery fails completely, return empty array
|
|
56
|
+
logger.error('[getWalletStandardWallets] Failed to discover wallets:', error);
|
|
57
|
+
return {
|
|
58
|
+
aptosWallets: [],
|
|
59
|
+
on: () => () => { },
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { getWalletStandardWallets };
|