@dynamic-labs/aptos 4.37.2
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 +6248 -0
- package/LICENSE +21 -0
- package/README.md +83 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +28 -0
- package/src/connectors/index.d.ts +0 -0
- package/src/consts/index.d.ts +2 -0
- package/src/index.cjs +18 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +14 -0
- package/src/types.d.ts +215 -0
- package/src/utils/assertProvider/assertProvider.d.ts +20 -0
- package/src/utils/assertProvider/index.d.ts +1 -0
- package/src/utils/getWalletStandardWallets/getWalletStandardWallets.d.ts +33 -0
- package/src/utils/getWalletStandardWallets/index.d.ts +1 -0
- package/src/utils/invokeWalletMethod/index.d.ts +1 -0
- package/src/utils/invokeWalletMethod/invokeWalletMethod.d.ts +37 -0
- package/src/utils/isWalletWithRequiredFeatureSet/index.d.ts +1 -0
- package/src/utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.d.ts +2 -0
- package/src/utils/parseConnectionResult/index.d.ts +1 -0
- package/src/utils/parseConnectionResult/parseConnectionResult.d.ts +18 -0
- package/src/wallet/index.d.ts +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Dynamic Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @dynamic-labs/aptos
|
|
2
|
+
|
|
3
|
+
An Aptos wallet connector package for the Dynamic SDK that enables seamless integration with Aptos network wallets.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @dynamic-labs/aptos
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## ๐ Supported Wallets
|
|
12
|
+
|
|
13
|
+
### Provider Interface
|
|
14
|
+
|
|
15
|
+
## ๐ Supported Networks
|
|
16
|
+
|
|
17
|
+
## ๐ Usage
|
|
18
|
+
|
|
19
|
+
### Basic Integration
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core';
|
|
23
|
+
import { AptosWalletConnectors } from '@dynamic-labs/aptos';
|
|
24
|
+
|
|
25
|
+
function App() {
|
|
26
|
+
return (
|
|
27
|
+
<DynamicContextProvider
|
|
28
|
+
settings={{
|
|
29
|
+
environmentId: 'your-environment-id',
|
|
30
|
+
walletConnectors: [AptosWalletConnectors()],
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
{/* Your app content */}
|
|
34
|
+
</DynamicContextProvider>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Type Checking
|
|
40
|
+
|
|
41
|
+
Use the `isAptosWallet` type guard to safely work with Aptos wallets:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { isAptosWallet } from '@dynamic-labs/aptos';
|
|
45
|
+
|
|
46
|
+
function handleWallet(wallet: Wallet) {
|
|
47
|
+
if (isAptosWallet(wallet)) {
|
|
48
|
+
// Do something
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## ๐งช Testing
|
|
54
|
+
|
|
55
|
+
### Run Tests
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx nx test aptos
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Build Package
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npx nx build aptos
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## ๐ค Contributing
|
|
68
|
+
|
|
69
|
+
We welcome contributions! Please see our [contributing guidelines](https://github.com/dynamic-labs/dynamic-sdk/blob/main/CONTRIBUTING.md) for details.
|
|
70
|
+
|
|
71
|
+
## ๐ License
|
|
72
|
+
|
|
73
|
+
This package is part of the Dynamic SDK and follows the same licensing terms. See [LICENSE](https://github.com/dynamic-labs/dynamic-sdk/blob/main/LICENSE) for details.
|
|
74
|
+
|
|
75
|
+
## ๐ Support
|
|
76
|
+
|
|
77
|
+
- **Documentation**: [docs.dynamic.xyz](https://docs.dynamic.xyz)
|
|
78
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/dynamic-labs/dynamic-sdk/issues)
|
|
79
|
+
- **Discord**: [Join our community](https://discord.gg/dynamic)
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
**Built with โค๏ธ by the Dynamic Labs team**
|
package/package.cjs
ADDED
package/package.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs/aptos",
|
|
3
|
+
"version": "4.37.2",
|
|
4
|
+
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
|
+
"author": "Dynamic Labs, Inc.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./src/index.cjs",
|
|
8
|
+
"module": "./src/index.js",
|
|
9
|
+
"types": "./src/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./src/index.d.ts",
|
|
14
|
+
"import": "./src/index.js",
|
|
15
|
+
"require": "./src/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://www.dynamic.xyz/",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@aptos-labs/ts-sdk": "5.1.1",
|
|
22
|
+
"@aptos-labs/wallet-standard": "0.5.2",
|
|
23
|
+
"@dynamic-labs/assert-package-version": "4.37.2",
|
|
24
|
+
"@wallet-standard/core": "1.1.1",
|
|
25
|
+
"@dynamic-labs/utils": "4.37.2"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {}
|
|
28
|
+
}
|
|
File without changes
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
|
+
var _package = require('../package.cjs');
|
|
8
|
+
|
|
9
|
+
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
|
|
14
|
+
const AptosWalletConnectors = () => [
|
|
15
|
+
// TODO: Add Aptos wallet connectors
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
exports.AptosWalletConnectors = AptosWalletConnectors;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AptosWalletConnectors: () => never[];
|
package/src/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
|
+
import { version } from '../package.js';
|
|
4
|
+
|
|
5
|
+
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
|
|
10
|
+
const AptosWalletConnectors = () => [
|
|
11
|
+
// TODO: Add Aptos wallet connectors
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export { AptosWalletConnectors };
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { AccountAuthenticator, AnyRawTransaction } from '@aptos-labs/ts-sdk';
|
|
2
|
+
import type { AccountInfo, AptosSignMessageInput, AptosSignMessageOutput, NetworkInfo, UserResponse } from '@aptos-labs/wallet-standard';
|
|
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.
|
|
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.
|
|
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)
|
|
23
|
+
*
|
|
24
|
+
* ## Core Features
|
|
25
|
+
* - **Connection Management**: Connect, disconnect, and account retrieval
|
|
26
|
+
* - **Network Support**: Network information and switching capabilities
|
|
27
|
+
* - **Transaction Signing**: Support for transaction and message signing
|
|
28
|
+
* - **Event Handling**: Account and network change listeners
|
|
29
|
+
* - **Flexible Returns**: Support for different response formats
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // Basic connection (works for both wallet-standard and injected)
|
|
34
|
+
* const result = await provider.connect();
|
|
35
|
+
*
|
|
36
|
+
* // Sign a transaction
|
|
37
|
+
* const signature = await provider.signTransaction(transaction);
|
|
38
|
+
*
|
|
39
|
+
* // Sign a message
|
|
40
|
+
* const messageSignature = await provider.signMessage({
|
|
41
|
+
* message: "Hello Aptos",
|
|
42
|
+
* nonce: "12345"
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Listen for account changes
|
|
46
|
+
* provider.onAccountChange?.((account) => {
|
|
47
|
+
* console.log('Account changed:', account);
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
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?: {
|
|
60
|
+
'aptos:connect'?: {
|
|
61
|
+
version: string;
|
|
62
|
+
connect(): Promise<UserResponse<AccountInfo>>;
|
|
63
|
+
};
|
|
64
|
+
'aptos:disconnect'?: {
|
|
65
|
+
version: string;
|
|
66
|
+
disconnect(): Promise<void>;
|
|
67
|
+
};
|
|
68
|
+
'aptos:signTransaction'?: {
|
|
69
|
+
version: string;
|
|
70
|
+
signTransaction(transaction: AnyRawTransaction, asFeePayer?: boolean): Promise<UserResponse<AccountAuthenticator>>;
|
|
71
|
+
};
|
|
72
|
+
'aptos:signMessage'?: {
|
|
73
|
+
version: string;
|
|
74
|
+
signMessage(input: AptosSignMessageInput): Promise<UserResponse<AptosSignMessageOutput>>;
|
|
75
|
+
};
|
|
76
|
+
'aptos:signAndSubmitTransaction'?: {
|
|
77
|
+
version: string;
|
|
78
|
+
signAndSubmitTransaction(transaction: AnyRawTransaction): Promise<UserResponse<{
|
|
79
|
+
hash: string;
|
|
80
|
+
}>>;
|
|
81
|
+
};
|
|
82
|
+
'aptos:network'?: {
|
|
83
|
+
version: string;
|
|
84
|
+
network(): Promise<NetworkInfo>;
|
|
85
|
+
};
|
|
86
|
+
'aptos:account'?: {
|
|
87
|
+
version: string;
|
|
88
|
+
account(): Promise<AccountInfo>;
|
|
89
|
+
};
|
|
90
|
+
'aptos:onAccountChange'?: {
|
|
91
|
+
version: string;
|
|
92
|
+
onAccountChange(callback: (account: AccountInfo | null) => void): () => void;
|
|
93
|
+
};
|
|
94
|
+
'aptos:onNetworkChange'?: {
|
|
95
|
+
version: string;
|
|
96
|
+
onNetworkChange(callback: (network: NetworkInfo) => void): () => void;
|
|
97
|
+
};
|
|
98
|
+
'aptos:submitTransaction'?: {
|
|
99
|
+
version: string;
|
|
100
|
+
submitTransaction(transaction: AccountAuthenticator): Promise<string>;
|
|
101
|
+
};
|
|
102
|
+
'aptos:getNetwork'?: {
|
|
103
|
+
version: string;
|
|
104
|
+
getNetwork(): Promise<NetworkInfo>;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
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
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Result from wallet connection, supporting different response formats
|
|
182
|
+
*/
|
|
183
|
+
export type AptosConnectionResult = UserResponse<AccountInfo> | AccountInfo | {
|
|
184
|
+
address: string;
|
|
185
|
+
publicKey?: string | Uint8Array;
|
|
186
|
+
} | string;
|
|
187
|
+
/**
|
|
188
|
+
* Props for sending APT or token balance
|
|
189
|
+
*/
|
|
190
|
+
export interface AptosSendBalanceProps {
|
|
191
|
+
/** Amount to send (in APT for native transfers) */
|
|
192
|
+
amount: string;
|
|
193
|
+
/** Recipient address */
|
|
194
|
+
toAddress: string;
|
|
195
|
+
/** Optional token information for non-APT transfers */
|
|
196
|
+
token?: {
|
|
197
|
+
/** Token contract address */
|
|
198
|
+
address: string;
|
|
199
|
+
/** Token decimals */
|
|
200
|
+
decimals?: number;
|
|
201
|
+
/** Token symbol */
|
|
202
|
+
symbol?: string;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Aptos wallet connector constructor properties
|
|
207
|
+
*/
|
|
208
|
+
export interface AptosWalletConnectorProps {
|
|
209
|
+
/** Wallet book schema */
|
|
210
|
+
walletBook: any;
|
|
211
|
+
/** Wallet metadata */
|
|
212
|
+
metadata?: any;
|
|
213
|
+
}
|
|
214
|
+
export type AptosFeatureName = keyof NonNullable<IAptosProvider['features']>;
|
|
215
|
+
export type AptosMethodName = 'connect' | 'disconnect' | 'signTransaction' | 'signMessage' | 'signAndSubmitTransaction' | 'submitTransaction' | 'getNetwork' | 'network';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IAptosProvider } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Asserts that a wallet provider is available and throws a consistent error if not.
|
|
4
|
+
*
|
|
5
|
+
* This utility function eliminates repetitive provider checking throughout the codebase
|
|
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.
|
|
8
|
+
*
|
|
9
|
+
* @param provider - The wallet provider to check, may be undefined
|
|
10
|
+
* @throws {DynamicError} When the provider is undefined or null
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const provider = getProvider();
|
|
15
|
+
* assertProvider(provider);
|
|
16
|
+
* // TypeScript now knows provider is not undefined
|
|
17
|
+
* await provider.connect();
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const assertProvider: (provider: IAptosProvider | undefined) => asserts provider is IAptosProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { assertProvider } from './assertProvider';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WalletsEventsListeners } from '@wallet-standard/core';
|
|
2
|
+
import { AptosWallet } from '@aptos-labs/wallet-standard';
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves all available Aptos-compatible wallets from the wallet standard registry.
|
|
5
|
+
*
|
|
6
|
+
* This function fetches all registered wallets and filters them to return only those
|
|
7
|
+
* that support the required Aptos feature set. It also provides an event listener
|
|
8
|
+
* function to monitor wallet registration events.
|
|
9
|
+
*
|
|
10
|
+
* @returns An object containing:
|
|
11
|
+
* - `aptosWallets`: Array of Aptos-compatible wallets that support required features
|
|
12
|
+
* - `on`: Event listener function to subscribe to wallet registration/unregistration events
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const { aptosWallets, on } = getWalletStandardWallets();
|
|
17
|
+
*
|
|
18
|
+
* // Use the Aptos wallets
|
|
19
|
+
* console.log('Available Aptos wallets:', aptosWallets);
|
|
20
|
+
*
|
|
21
|
+
* // Listen for new wallet registrations
|
|
22
|
+
* const unsubscribe = on('register', (wallet) => {
|
|
23
|
+
* console.log('New wallet registered:', wallet);
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Clean up listener when done
|
|
27
|
+
* unsubscribe();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const getWalletStandardWallets: () => {
|
|
31
|
+
aptosWallets: AptosWallet[];
|
|
32
|
+
on: <E extends keyof WalletsEventsListeners>(event: E, listener: WalletsEventsListeners[E]) => () => void;
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getWalletStandardWallets } from './getWalletStandardWallets';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { invokeWalletMethod } from './invokeWalletMethod';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IAptosProvider, AptosFeatureName, AptosMethodName } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Invokes a method on either wallet-standard or injected provider.
|
|
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.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The expected return type of the wallet method
|
|
11
|
+
* @param provider - The Aptos wallet provider (wallet-standard or injected)
|
|
12
|
+
* @param featureName - The wallet-standard feature name (e.g., 'aptos:connect')
|
|
13
|
+
* @param methodName - The method name to call (e.g., 'connect', 'signTransaction')
|
|
14
|
+
* @param args - Arguments to pass to the wallet method
|
|
15
|
+
* @returns Promise resolving to the method's return value
|
|
16
|
+
* @throws {DynamicError} When the method is not supported by the provider
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Connect to wallet
|
|
21
|
+
* const result = await invokeWalletMethod(
|
|
22
|
+
* provider,
|
|
23
|
+
* 'aptos:connect',
|
|
24
|
+
* 'connect'
|
|
25
|
+
* );
|
|
26
|
+
*
|
|
27
|
+
* // Sign transaction
|
|
28
|
+
* const signature = await invokeWalletMethod(
|
|
29
|
+
* provider,
|
|
30
|
+
* 'aptos:signTransaction',
|
|
31
|
+
* 'signTransaction',
|
|
32
|
+
* transaction,
|
|
33
|
+
* false // asFeePayer
|
|
34
|
+
* );
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const invokeWalletMethod: <T>(provider: IAptosProvider, featureName: AptosFeatureName, methodName: AptosMethodName, ...args: unknown[]) => Promise<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isWalletWithRequiredFeatureSet } from './isWalletWithRequiredFeatureSet';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Wallet, WalletWithFeatures } from '@wallet-standard/core';
|
|
2
|
+
export declare const isWalletWithRequiredFeatureSet: <AdditionalFeatures extends Readonly<Record<`${string}:${string}`, unknown>>>(wallet: Wallet, additionalFeatures?: (keyof AdditionalFeatures)[]) => wallet is WalletWithFeatures<import("@aptos-labs/wallet-standard").AptosFeatures & AdditionalFeatures>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseConnectionResult, type ParsedAccountInfo, } from './parseConnectionResult';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AccountInfo } from '@aptos-labs/wallet-standard';
|
|
2
|
+
import type { AptosConnectionResult } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Parsed account information that may be a full AccountInfo or minimal account data
|
|
5
|
+
*/
|
|
6
|
+
export type ParsedAccountInfo = AccountInfo | {
|
|
7
|
+
address: string;
|
|
8
|
+
publicKey?: string | Uint8Array;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Parses wallet connection result into account information.
|
|
12
|
+
* Handles different response formats from wallet-standard and injected providers.
|
|
13
|
+
*
|
|
14
|
+
* @param result - Connection result matching AptosConnectionResult format
|
|
15
|
+
* @returns Parsed account information (full AccountInfo or minimal account data)
|
|
16
|
+
* @throws {DynamicError} When result format is not supported
|
|
17
|
+
*/
|
|
18
|
+
export declare const parseConnectionResult: (result: AptosConnectionResult) => ParsedAccountInfo;
|
|
File without changes
|