@dynamic-labs/aptos 4.38.0 → 4.39.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/_virtual/_tslib.cjs +36 -0
  3. package/_virtual/_tslib.js +32 -0
  4. package/package.cjs +1 -1
  5. package/package.js +1 -1
  6. package/package.json +5 -3
  7. package/src/connectors/AptosWalletConnector/AptosWalletConnector.cjs +208 -0
  8. package/src/connectors/AptosWalletConnector/AptosWalletConnector.d.ts +71 -0
  9. package/src/connectors/AptosWalletConnector/AptosWalletConnector.js +204 -0
  10. package/src/connectors/AptosWalletConnector/index.d.ts +1 -0
  11. package/src/consts/index.cjs +19 -0
  12. package/src/consts/index.js +15 -0
  13. package/src/index.cjs +19 -5
  14. package/src/index.d.ts +9 -0
  15. package/src/index.js +11 -5
  16. package/src/types.d.ts +13 -114
  17. package/src/utils/assertProvider/assertProvider.cjs +36 -0
  18. package/src/utils/assertProvider/assertProvider.d.ts +6 -5
  19. package/src/utils/assertProvider/assertProvider.js +32 -0
  20. package/src/utils/getWalletStandardWallets/getWalletStandardWallets.cjs +49 -0
  21. package/src/utils/getWalletStandardWallets/getWalletStandardWallets.js +45 -0
  22. package/src/utils/invokeWalletMethod/invokeWalletMethod.cjs +61 -0
  23. package/src/utils/invokeWalletMethod/invokeWalletMethod.d.ts +6 -7
  24. package/src/utils/invokeWalletMethod/invokeWalletMethod.js +57 -0
  25. package/src/utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.cjs +10 -0
  26. package/src/utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.js +6 -0
  27. package/src/utils/parseConnectionResult/parseConnectionResult.cjs +40 -0
  28. package/src/utils/parseConnectionResult/parseConnectionResult.d.ts +7 -10
  29. package/src/utils/parseConnectionResult/parseConnectionResult.js +36 -0
  30. package/src/utils/parseTransactionResponse/parseTransactionResponse.cjs +53 -0
  31. package/src/utils/parseTransactionResponse/parseTransactionResponse.d.ts +3 -3
  32. package/src/utils/parseTransactionResponse/parseTransactionResponse.js +49 -0
  33. package/src/wallet/AptosWallet.cjs +138 -0
  34. package/src/wallet/AptosWallet.d.ts +76 -0
  35. package/src/wallet/AptosWallet.js +134 -0
  36. package/src/wallet/index.d.ts +1 -0
  37. package/src/connectors/index.d.ts +0 -0
package/src/index.cjs CHANGED
@@ -5,14 +5,28 @@ 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
+ var AptosWallet = require('./wallet/AptosWallet.cjs');
9
+ var AptosWalletConnector = require('./connectors/AptosWalletConnector/AptosWalletConnector.cjs');
10
+ var assertProvider = require('./utils/assertProvider/assertProvider.cjs');
11
+ var getWalletStandardWallets = require('./utils/getWalletStandardWallets/getWalletStandardWallets.cjs');
12
+ var invokeWalletMethod = require('./utils/invokeWalletMethod/invokeWalletMethod.cjs');
13
+ var isWalletWithRequiredFeatureSet = require('./utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.cjs');
14
+ var parseConnectionResult = require('./utils/parseConnectionResult/parseConnectionResult.cjs');
15
+ var parseTransactionResponse = require('./utils/parseTransactionResponse/parseTransactionResponse.cjs');
8
16
 
9
17
  assertPackageVersion.assertPackageVersion('@dynamic-labs/aptos', _package.version);
10
- // TODO: Add connector exports
11
- // TODO: Add type exports
12
- // TODO: Add wallet exports
13
- // TODO: Add utility exports
18
+ // Wallet connector factory (to be implemented by specific wallet connectors)
14
19
  const AptosWalletConnectors = () => [
15
- // TODO: Add Aptos wallet connectors
20
+ // Specific wallet connectors will be added here by implementers
21
+ // e.g., PetraWalletConnector, OKXWalletConnector, etc.
16
22
  ];
17
23
 
24
+ exports.AptosWallet = AptosWallet.AptosWallet;
25
+ exports.AptosWalletConnector = AptosWalletConnector.AptosWalletConnector;
26
+ exports.assertProvider = assertProvider.assertProvider;
27
+ exports.getWalletStandardWallets = getWalletStandardWallets.getWalletStandardWallets;
28
+ exports.invokeWalletMethod = invokeWalletMethod.invokeWalletMethod;
29
+ exports.isWalletWithRequiredFeatureSet = isWalletWithRequiredFeatureSet.isWalletWithRequiredFeatureSet;
30
+ exports.parseConnectionResult = parseConnectionResult.parseConnectionResult;
31
+ exports.parseTransactionResponse = parseTransactionResponse.parseTransactionResponse;
18
32
  exports.AptosWalletConnectors = AptosWalletConnectors;
package/src/index.d.ts CHANGED
@@ -1 +1,10 @@
1
+ export { AptosWallet } from './wallet';
2
+ export { AptosWalletConnector } from './connectors/AptosWalletConnector';
3
+ export type { IAptosProvider, AptosConnectionResult, AptosSendBalanceProps, AptosWalletConnectorProps, AptosFeatureName, AptosMethodName, } from './types';
4
+ export { assertProvider } from './utils/assertProvider';
5
+ export { getWalletStandardWallets } from './utils/getWalletStandardWallets';
6
+ export { invokeWalletMethod } from './utils/invokeWalletMethod';
7
+ export { isWalletWithRequiredFeatureSet } from './utils/isWalletWithRequiredFeatureSet';
8
+ export { parseConnectionResult, type ParsedAccountInfo, } from './utils/parseConnectionResult';
9
+ export { parseTransactionResponse } from './utils/parseTransactionResponse';
1
10
  export declare const AptosWalletConnectors: () => never[];
package/src/index.js CHANGED
@@ -1,14 +1,20 @@
1
1
  'use client'
2
2
  import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
3
3
  import { version } from '../package.js';
4
+ export { AptosWallet } from './wallet/AptosWallet.js';
5
+ export { AptosWalletConnector } from './connectors/AptosWalletConnector/AptosWalletConnector.js';
6
+ export { assertProvider } from './utils/assertProvider/assertProvider.js';
7
+ export { getWalletStandardWallets } from './utils/getWalletStandardWallets/getWalletStandardWallets.js';
8
+ export { invokeWalletMethod } from './utils/invokeWalletMethod/invokeWalletMethod.js';
9
+ export { isWalletWithRequiredFeatureSet } from './utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.js';
10
+ export { parseConnectionResult } from './utils/parseConnectionResult/parseConnectionResult.js';
11
+ export { parseTransactionResponse } from './utils/parseTransactionResponse/parseTransactionResponse.js';
4
12
 
5
13
  assertPackageVersion('@dynamic-labs/aptos', version);
6
- // TODO: Add connector exports
7
- // TODO: Add type exports
8
- // TODO: Add wallet exports
9
- // TODO: Add utility exports
14
+ // Wallet connector factory (to be implemented by specific wallet connectors)
10
15
  const AptosWalletConnectors = () => [
11
- // TODO: Add Aptos wallet connectors
16
+ // Specific wallet connectors will be added here by implementers
17
+ // e.g., PetraWalletConnector, OKXWalletConnector, etc.
12
18
  ];
13
19
 
14
20
  export { AptosWalletConnectors };
package/src/types.d.ts CHANGED
@@ -1,62 +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
3
  /**
4
- * Global window interface extension for Aptos wallet providers
5
- */
6
- declare global {
7
- interface Window {
8
- aptos?: IAptosProvider;
9
- }
10
- }
11
- /**
12
- * Interface that all Aptos wallet providers must implement.
4
+ * Interface for AIP-62 compliant Aptos wallet providers.
13
5
  *
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.
18
- *
19
- * ## Design Philosophy
20
- * This interface accommodates both:
21
- * - **Wallet Standard**: Modern wallets implementing AIP-62 wallet standard with `features` object
22
- * - **Injected Providers**: Wallets that inject methods directly (like OKX, Petra legacy)
6
+ * This interface is designed to work exclusively with wallet-standard compliant wallets
7
+ * that implement AIP-62. All major Aptos wallets now support this standard, including:
8
+ * OKX, AptosConnect, Petra, Nightly, Pontem, RimoSafe, MSafe, Bitget, and Backpack.
23
9
  *
24
10
  * ## Core Features
25
11
  * - **Connection Management**: Connect, disconnect, and account retrieval
26
12
  * - **Network Support**: Network information and switching capabilities
27
13
  * - **Transaction Signing**: Support for transaction and message signing
28
14
  * - **Event Handling**: Account and network change listeners
29
- * - **Flexible Returns**: Support for different response formats
30
15
  *
31
16
  * @example
32
17
  * ```typescript
33
- * // Basic connection (works for both wallet-standard and injected)
34
- * const result = await provider.connect();
18
+ * // Connect to wallet using wallet-standard
19
+ * const result = await provider.features['aptos:connect']?.connect();
35
20
  *
36
21
  * // Sign a transaction
37
- * const signature = await provider.signTransaction(transaction);
22
+ * const signature = await provider.features['aptos:signTransaction']?.signTransaction(transaction);
38
23
  *
39
24
  * // Sign a message
40
- * const messageSignature = await provider.signMessage({
25
+ * const messageSignature = await provider.features['aptos:signMessage']?.signMessage({
41
26
  * message: "Hello Aptos",
42
27
  * nonce: "12345"
43
28
  * });
44
- *
45
- * // Listen for account changes
46
- * provider.onAccountChange?.((account) => {
47
- * console.log('Account changed:', account);
48
- * });
49
29
  * ```
50
30
  */
51
31
  export interface IAptosProvider {
52
- /** Whether the wallet is currently connected */
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) */
59
- features?: {
32
+ /** Wallet-standard features (AIP-62 compliant wallets) */
33
+ features: {
60
34
  'aptos:connect'?: {
61
35
  version: string;
62
36
  connect(): Promise<UserResponse<AccountInfo>>;
@@ -104,86 +78,11 @@ export interface IAptosProvider {
104
78
  getNetwork(): Promise<NetworkInfo>;
105
79
  };
106
80
  };
107
- /**
108
- * Establishes a connection to the wallet
109
- * @returns Promise resolving to connection result with account information
110
- */
111
- connect(): Promise<AptosConnectionResult>;
112
- /**
113
- * Disconnects from the wallet
114
- * @returns Promise that resolves when disconnected
115
- */
116
- disconnect(): Promise<void>;
117
- /**
118
- * Retrieves the current account information
119
- * @returns Promise resolving to account information
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;
179
81
  }
180
82
  /**
181
- * Result from wallet connection, supporting different response formats
83
+ * Result from wallet connection (wallet-standard only)
182
84
  */
183
- export type AptosConnectionResult = UserResponse<AccountInfo> | AccountInfo | {
184
- address: string;
185
- publicKey?: string | Uint8Array;
186
- } | string;
85
+ export type AptosConnectionResult = UserResponse<AccountInfo>;
187
86
  /**
188
87
  * Props for sending APT or token balance
189
88
  */
@@ -212,4 +111,4 @@ export interface AptosWalletConnectorProps {
212
111
  metadata?: any;
213
112
  }
214
113
  export type AptosFeatureName = keyof NonNullable<IAptosProvider['features']>;
215
- export type AptosMethodName = 'connect' | 'disconnect' | 'signTransaction' | 'signMessage' | 'signAndSubmitTransaction' | 'submitTransaction' | 'getNetwork' | 'network';
114
+ export type AptosMethodName = 'connect' | 'disconnect' | 'signTransaction' | 'signMessage' | 'signAndSubmitTransaction' | 'submitTransaction' | 'getNetwork' | 'network' | 'account' | 'onAccountChange' | 'onNetworkChange';
@@ -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 a wallet provider is available and throws a consistent error if not.
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 null
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,49 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var core = require('@wallet-standard/core');
7
+ var walletStandard = require('@aptos-labs/wallet-standard');
8
+
9
+ /**
10
+ * Retrieves all available Aptos-compatible wallets from the wallet standard registry.
11
+ *
12
+ * This function fetches all registered wallets and filters them to return only those
13
+ * that support the required Aptos feature set. It also provides an event listener
14
+ * function to monitor wallet registration events.
15
+ *
16
+ * @returns An object containing:
17
+ * - `aptosWallets`: Array of Aptos-compatible wallets that support required features
18
+ * - `on`: Event listener function to subscribe to wallet registration/unregistration events
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const { aptosWallets, on } = getWalletStandardWallets();
23
+ *
24
+ * // Use the Aptos wallets
25
+ * console.log('Available Aptos wallets:', aptosWallets);
26
+ *
27
+ * // Listen for new wallet registrations
28
+ * const unsubscribe = on('register', (wallet) => {
29
+ * console.log('New wallet registered:', wallet);
30
+ * });
31
+ *
32
+ * // Clean up listener when done
33
+ * unsubscribe();
34
+ * ```
35
+ */
36
+ const getWalletStandardWallets = () => {
37
+ const { get, on } = core.getWallets();
38
+ const wallets = get();
39
+ const aptosWallets = [];
40
+ wallets.map((wallet) => {
41
+ const isAptos = walletStandard.isWalletWithRequiredFeatureSet(wallet);
42
+ if (isAptos) {
43
+ aptosWallets.push(wallet);
44
+ }
45
+ });
46
+ return { aptosWallets: aptosWallets, on };
47
+ };
48
+
49
+ exports.getWalletStandardWallets = getWalletStandardWallets;
@@ -0,0 +1,45 @@
1
+ 'use client'
2
+ import { getWallets } from '@wallet-standard/core';
3
+ import { isWalletWithRequiredFeatureSet } from '@aptos-labs/wallet-standard';
4
+
5
+ /**
6
+ * Retrieves all available Aptos-compatible wallets from the wallet standard registry.
7
+ *
8
+ * This function fetches all registered wallets and filters them to return only those
9
+ * that support the required Aptos feature set. It also provides an event listener
10
+ * function to monitor wallet registration events.
11
+ *
12
+ * @returns An object containing:
13
+ * - `aptosWallets`: Array of Aptos-compatible wallets that support required features
14
+ * - `on`: Event listener function to subscribe to wallet registration/unregistration events
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const { aptosWallets, on } = getWalletStandardWallets();
19
+ *
20
+ * // Use the Aptos wallets
21
+ * console.log('Available Aptos wallets:', aptosWallets);
22
+ *
23
+ * // Listen for new wallet registrations
24
+ * const unsubscribe = on('register', (wallet) => {
25
+ * console.log('New wallet registered:', wallet);
26
+ * });
27
+ *
28
+ * // Clean up listener when done
29
+ * unsubscribe();
30
+ * ```
31
+ */
32
+ const getWalletStandardWallets = () => {
33
+ const { get, on } = getWallets();
34
+ const wallets = get();
35
+ const aptosWallets = [];
36
+ wallets.map((wallet) => {
37
+ const isAptos = isWalletWithRequiredFeatureSet(wallet);
38
+ if (isAptos) {
39
+ aptosWallets.push(wallet);
40
+ }
41
+ });
42
+ return { aptosWallets: aptosWallets, on };
43
+ };
44
+
45
+ export { getWalletStandardWallets };
@@ -0,0 +1,61 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var utils = require('@dynamic-labs/utils');
8
+
9
+ /**
10
+ * Invokes a method on AIP-62 compliant wallet-standard provider.
11
+ *
12
+ * This utility provides a clean interface for calling wallet-standard features
13
+ * on Aptos wallets that implement AIP-62. All major Aptos wallets now support
14
+ * this standard, making legacy provider support unnecessary.
15
+ *
16
+ * @template T - The expected return type of the wallet method
17
+ * @param provider - The AIP-62 compliant Aptos wallet provider
18
+ * @param featureName - The wallet-standard feature name (e.g., 'aptos:connect')
19
+ * @param methodName - The method name to call (e.g., 'connect', 'signTransaction')
20
+ * @param args - Arguments to pass to the wallet method
21
+ * @returns Promise resolving to the method's return value
22
+ * @throws {DynamicError} When the feature or method is not supported by the provider
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // Connect to wallet
27
+ * const result = await invokeWalletMethod(
28
+ * provider,
29
+ * 'aptos:connect',
30
+ * 'connect'
31
+ * );
32
+ *
33
+ * // Sign transaction
34
+ * const signature = await invokeWalletMethod(
35
+ * provider,
36
+ * 'aptos:signTransaction',
37
+ * 'signTransaction',
38
+ * transaction,
39
+ * false // asFeePayer
40
+ * );
41
+ * ```
42
+ */
43
+ const invokeWalletMethod = (provider, featureName, methodName, ...args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
44
+ // Check if provider has features
45
+ if (!provider.features) {
46
+ throw new utils.DynamicError(`Feature ${featureName} not supported by wallet`);
47
+ }
48
+ // Get the wallet-standard feature
49
+ const feature = provider.features[featureName];
50
+ if (!feature || typeof feature !== 'object') {
51
+ throw new utils.DynamicError(`Feature ${featureName} not supported by wallet`);
52
+ }
53
+ // Get the method from the feature
54
+ const method = feature[methodName];
55
+ if (typeof method !== 'function') {
56
+ throw new utils.DynamicError(`Method ${methodName} not available in feature ${featureName}`);
57
+ }
58
+ return method(...args);
59
+ });
60
+
61
+ exports.invokeWalletMethod = invokeWalletMethod;
@@ -1,19 +1,18 @@
1
1
  import type { IAptosProvider, AptosFeatureName, AptosMethodName } from '../../types';
2
2
  /**
3
- * Invokes a method on either wallet-standard or injected provider.
3
+ * Invokes a method on AIP-62 compliant wallet-standard provider.
4
4
  *
5
- * This utility handles the dual provider pattern used throughout Aptos wallet interactions,
6
- * automatically detecting whether to use wallet-standard features or direct method calls
7
- * on injected providers. It provides a unified interface for calling wallet methods
8
- * regardless of the underlying wallet implementation.
5
+ * This utility provides a clean interface for calling wallet-standard features
6
+ * on Aptos wallets that implement AIP-62. All major Aptos wallets now support
7
+ * this standard, making legacy provider support unnecessary.
9
8
  *
10
9
  * @template T - The expected return type of the wallet method
11
- * @param provider - The Aptos wallet provider (wallet-standard or injected)
10
+ * @param provider - The AIP-62 compliant Aptos wallet provider
12
11
  * @param featureName - The wallet-standard feature name (e.g., 'aptos:connect')
13
12
  * @param methodName - The method name to call (e.g., 'connect', 'signTransaction')
14
13
  * @param args - Arguments to pass to the wallet method
15
14
  * @returns Promise resolving to the method's return value
16
- * @throws {DynamicError} When the method is not supported by the provider
15
+ * @throws {DynamicError} When the feature or method is not supported by the provider
17
16
  *
18
17
  * @example
19
18
  * ```typescript
@@ -0,0 +1,57 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../_virtual/_tslib.js';
3
+ import { DynamicError } from '@dynamic-labs/utils';
4
+
5
+ /**
6
+ * Invokes a method on AIP-62 compliant wallet-standard provider.
7
+ *
8
+ * This utility provides a clean interface for calling wallet-standard features
9
+ * on Aptos wallets that implement AIP-62. All major Aptos wallets now support
10
+ * this standard, making legacy provider support unnecessary.
11
+ *
12
+ * @template T - The expected return type of the wallet method
13
+ * @param provider - The AIP-62 compliant Aptos wallet provider
14
+ * @param featureName - The wallet-standard feature name (e.g., 'aptos:connect')
15
+ * @param methodName - The method name to call (e.g., 'connect', 'signTransaction')
16
+ * @param args - Arguments to pass to the wallet method
17
+ * @returns Promise resolving to the method's return value
18
+ * @throws {DynamicError} When the feature or method is not supported by the provider
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * // Connect to wallet
23
+ * const result = await invokeWalletMethod(
24
+ * provider,
25
+ * 'aptos:connect',
26
+ * 'connect'
27
+ * );
28
+ *
29
+ * // Sign transaction
30
+ * const signature = await invokeWalletMethod(
31
+ * provider,
32
+ * 'aptos:signTransaction',
33
+ * 'signTransaction',
34
+ * transaction,
35
+ * false // asFeePayer
36
+ * );
37
+ * ```
38
+ */
39
+ const invokeWalletMethod = (provider, featureName, methodName, ...args) => __awaiter(void 0, void 0, void 0, function* () {
40
+ // Check if provider has features
41
+ if (!provider.features) {
42
+ throw new DynamicError(`Feature ${featureName} not supported by wallet`);
43
+ }
44
+ // Get the wallet-standard feature
45
+ const feature = provider.features[featureName];
46
+ if (!feature || typeof feature !== 'object') {
47
+ throw new DynamicError(`Feature ${featureName} not supported by wallet`);
48
+ }
49
+ // Get the method from the feature
50
+ const method = feature[methodName];
51
+ if (typeof method !== 'function') {
52
+ throw new DynamicError(`Method ${methodName} not available in feature ${featureName}`);
53
+ }
54
+ return method(...args);
55
+ });
56
+
57
+ export { invokeWalletMethod };
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var index = require('../../consts/index.cjs');
7
+
8
+ const isWalletWithRequiredFeatureSet = (wallet, additionalFeatures = []) => [...index.REQUIRED_FEATURES, ...additionalFeatures].every((feature) => feature in wallet.features);
9
+
10
+ exports.isWalletWithRequiredFeatureSet = isWalletWithRequiredFeatureSet;
@@ -0,0 +1,6 @@
1
+ 'use client'
2
+ import { REQUIRED_FEATURES } from '../../consts/index.js';
3
+
4
+ const isWalletWithRequiredFeatureSet = (wallet, additionalFeatures = []) => [...REQUIRED_FEATURES, ...additionalFeatures].every((feature) => feature in wallet.features);
5
+
6
+ export { isWalletWithRequiredFeatureSet };
@@ -0,0 +1,40 @@
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 utils = require('@dynamic-labs/utils');
8
+
9
+ /**
10
+ * Type guard to check if an object is a UserResponse with AccountInfo
11
+ */
12
+ const isUserResponse = (obj) => {
13
+ if (typeof obj !== 'object' || obj === null)
14
+ return false;
15
+ const candidate = obj;
16
+ return ('status' in candidate &&
17
+ 'args' in candidate &&
18
+ Object.values(walletStandard.UserResponseStatus).includes(candidate.status));
19
+ };
20
+ /**
21
+ * Parses wallet-standard connection result into AccountInfo.
22
+ * Only handles AIP-62 compliant wallet-standard responses.
23
+ *
24
+ * @param result - Connection result from wallet-standard (UserResponse<AccountInfo>)
25
+ * @returns AccountInfo from the approved response
26
+ * @throws {DynamicError} When result format is not supported or user rejected
27
+ */
28
+ const parseConnectionResult = (result) => {
29
+ // Handle wallet-standard UserResponse format (only format we support)
30
+ if (isUserResponse(result) && result.status === walletStandard.UserResponseStatus.APPROVED) {
31
+ return result.args;
32
+ }
33
+ // If it's a rejected response, throw appropriate error
34
+ if (isUserResponse(result) && result.status === walletStandard.UserResponseStatus.REJECTED) {
35
+ throw new utils.DynamicError('User rejected connection request');
36
+ }
37
+ throw new utils.DynamicError('Invalid wallet-standard connection response');
38
+ };
39
+
40
+ exports.parseConnectionResult = parseConnectionResult;