@aptos-labs/wallet-adapter-core 3.6.0 → 3.7.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 +6 -0
- package/dist/index.d.ts +164 -24
- package/dist/index.js +472 -205
- package/dist/index.mjs +482 -207
- package/package.json +4 -3
- package/src/AIP62StandardWallets/WalletStandard.ts +176 -0
- package/src/LegacyWalletPlugins/WalletCoreV1.ts +251 -0
- package/src/{conversion.ts → LegacyWalletPlugins/conversion.ts} +4 -1
- package/src/{types.ts → LegacyWalletPlugins/types.ts} +32 -10
- package/src/WalletCore.ts +513 -243
- package/src/__tests__/WalletCore.test.ts +3 -14
- package/src/constants.ts +5 -0
- package/src/index.ts +2 -1
- package/src/utils/localStorage.ts +1 -1
- package/src/WalletCoreV1.ts +0 -91
- package/src/ans.ts +0 -21
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Types } from 'aptos';
|
|
2
2
|
export { TxnBuilderTypes, Types } from 'aptos';
|
|
3
|
-
import { Network,
|
|
3
|
+
import { Network, Signature, AnyRawTransaction, InputGenerateTransactionOptions, PendingTransactionResponse, InputSubmitTransactionData, AccountAddressInput, InputGenerateTransactionPayloadData, Aptos, AccountAuthenticator, EntryFunctionArgumentTypes, SimpleEntryFunctionArgumentTypes } from '@aptos-labs/ts-sdk';
|
|
4
4
|
export { AccountAuthenticator, AnyRawTransaction, InputGenerateTransactionData, InputGenerateTransactionOptions, InputSubmitTransactionData, PendingTransactionResponse } from '@aptos-labs/ts-sdk';
|
|
5
5
|
import EventEmitter from 'eventemitter3';
|
|
6
|
+
import { NetworkInfo as NetworkInfo$1, AccountInfo as AccountInfo$1, UserResponse, AptosSignAndSubmitTransactionOutput, AptosSignMessageOutput, AptosWallet, AptosSignTransactionOutput, AptosSignMessageInput } from '@aptos-labs/wallet-standard';
|
|
6
7
|
|
|
7
8
|
declare enum WalletReadyState {
|
|
8
9
|
/**
|
|
@@ -28,6 +29,7 @@ declare enum NetworkName {
|
|
|
28
29
|
Testnet = "testnet",
|
|
29
30
|
Devnet = "devnet"
|
|
30
31
|
}
|
|
32
|
+
declare const ChainIdToAnsSupportedNetworkMap: Record<string, string>;
|
|
31
33
|
|
|
32
34
|
type WalletName<T extends string = string> = T & {
|
|
33
35
|
__brand__: "WalletName";
|
|
@@ -57,6 +59,7 @@ declare interface WalletCoreEvents {
|
|
|
57
59
|
connect(account: AccountInfo | null): void;
|
|
58
60
|
disconnect(): void;
|
|
59
61
|
readyStateChange(wallet: Wallet): void;
|
|
62
|
+
standardWalletsAdded(wallets: Wallet): void;
|
|
60
63
|
networkChange(network: NetworkInfo | null): void;
|
|
61
64
|
accountChange(account: AccountInfo | null): void;
|
|
62
65
|
}
|
|
@@ -75,11 +78,11 @@ interface SignMessageResponse {
|
|
|
75
78
|
message: string;
|
|
76
79
|
nonce: string;
|
|
77
80
|
prefix: "APTOS";
|
|
78
|
-
signature: string | string[];
|
|
81
|
+
signature: string | string[] | Signature;
|
|
79
82
|
bitmap?: Uint8Array;
|
|
80
83
|
}
|
|
81
|
-
type OnNetworkChange = (callBack: (networkInfo: NetworkInfo) => Promise<void>) => Promise<void>;
|
|
82
|
-
type OnAccountChange = (callBack: (accountInfo: AccountInfo) => Promise<any>) => Promise<void>;
|
|
84
|
+
type OnNetworkChange = (callBack: (networkInfo: NetworkInfo | NetworkInfo$1) => Promise<void>) => Promise<void>;
|
|
85
|
+
type OnAccountChange = (callBack: (accountInfo: AccountInfo | AccountInfo$1) => Promise<any>) => Promise<void>;
|
|
83
86
|
interface AdapterPluginEvents {
|
|
84
87
|
onNetworkChange: OnNetworkChange;
|
|
85
88
|
onAccountChange: OnAccountChange;
|
|
@@ -88,25 +91,29 @@ interface AdapterPluginProps<Name extends string = string> {
|
|
|
88
91
|
name: WalletName<Name>;
|
|
89
92
|
url: string;
|
|
90
93
|
icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
|
|
91
|
-
version?: "v1" | "v2";
|
|
92
94
|
providerName?: string;
|
|
93
95
|
provider: any;
|
|
94
96
|
deeplinkProvider?: (data: {
|
|
95
97
|
url: string;
|
|
96
98
|
}) => string;
|
|
99
|
+
openInMobileApp?: () => void;
|
|
97
100
|
connect(): Promise<any>;
|
|
98
101
|
disconnect: () => Promise<any>;
|
|
99
102
|
network: () => Promise<any>;
|
|
100
|
-
signAndSubmitTransaction(transaction: Types.TransactionPayload |
|
|
103
|
+
signAndSubmitTransaction?(transaction: Types.TransactionPayload | InputTransactionData | AnyRawTransaction, options?: InputGenerateTransactionOptions): Promise<{
|
|
101
104
|
hash: Types.HexEncodedBytes;
|
|
102
105
|
output?: any;
|
|
103
|
-
} | PendingTransactionResponse
|
|
106
|
+
} | PendingTransactionResponse | UserResponse<AptosSignAndSubmitTransactionOutput>>;
|
|
104
107
|
submitTransaction?(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>;
|
|
105
|
-
signMessage<T extends SignMessagePayload>(message: T): Promise<SignMessageResponse
|
|
108
|
+
signMessage<T extends SignMessagePayload>(message: T): Promise<SignMessageResponse | UserResponse<AptosSignMessageOutput>>;
|
|
109
|
+
signTransaction?(// `any` type for backwards compatibility, especially for identity connect
|
|
110
|
+
transactionOrPayload: any, optionsOrAsFeePayer?: any): Promise<any>;
|
|
111
|
+
account?: () => Promise<AccountInfo | AccountInfo$1>;
|
|
106
112
|
}
|
|
107
113
|
type AdapterPlugin<Name extends string = string> = AdapterPluginProps<Name> & AdapterPluginEvents;
|
|
108
114
|
type Wallet<Name extends string = string> = AdapterPlugin<Name> & {
|
|
109
115
|
readyState?: WalletReadyState;
|
|
116
|
+
isAIP62Standard?: boolean;
|
|
110
117
|
};
|
|
111
118
|
interface TransactionOptions {
|
|
112
119
|
max_gas_amount?: bigint;
|
|
@@ -130,46 +137,171 @@ interface PluginProvider {
|
|
|
130
137
|
onNetworkChange: OnNetworkChange;
|
|
131
138
|
}
|
|
132
139
|
|
|
140
|
+
type AptosStandardWallet = AptosWallet & {
|
|
141
|
+
readyState?: WalletReadyState;
|
|
142
|
+
};
|
|
143
|
+
declare class WalletStandardCore {
|
|
144
|
+
/**
|
|
145
|
+
* Signs and submits a transaction to chain
|
|
146
|
+
*
|
|
147
|
+
* @param transactionInput InputTransactionData
|
|
148
|
+
* @returns PendingTransactionResponse
|
|
149
|
+
*/
|
|
150
|
+
signAndSubmitTransaction(transactionInput: InputTransactionData, aptos: Aptos, account: AccountInfo, wallet: Wallet): Promise<PendingTransactionResponse>;
|
|
151
|
+
/**
|
|
152
|
+
* Signs a transaction
|
|
153
|
+
*
|
|
154
|
+
* To support both existing wallet adapter V1 and V2, we support 2 input types
|
|
155
|
+
*
|
|
156
|
+
* @param transactionOrPayload AnyRawTransaction
|
|
157
|
+
* @param options asFeePayer. To sign a transaction as the fee payer sponsor
|
|
158
|
+
*
|
|
159
|
+
* @returns AptosSignTransactionOutput
|
|
160
|
+
*/
|
|
161
|
+
signTransaction(transaction: AnyRawTransaction, wallet: Wallet, asFeePayer?: boolean): Promise<AptosSignTransactionOutput>;
|
|
162
|
+
/**
|
|
163
|
+
* Sign message
|
|
164
|
+
*
|
|
165
|
+
* @param message AptosSignMessageInput
|
|
166
|
+
* @return AptosSignMessageOutput
|
|
167
|
+
* @throws WalletSignMessageError
|
|
168
|
+
*/
|
|
169
|
+
signMessage(message: AptosSignMessageInput, wallet: Wallet): Promise<AptosSignMessageOutput>;
|
|
170
|
+
/**
|
|
171
|
+
* Signs a message and verifies the signer
|
|
172
|
+
* @param message AptosSignMessageInput
|
|
173
|
+
* @returns boolean
|
|
174
|
+
*/
|
|
175
|
+
signMessageAndVerify(message: AptosSignMessageInput, wallet: Wallet): Promise<boolean>;
|
|
176
|
+
}
|
|
177
|
+
|
|
133
178
|
declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
134
179
|
private _wallets;
|
|
180
|
+
private _standard_wallets;
|
|
181
|
+
private _all_wallets;
|
|
135
182
|
private _wallet;
|
|
136
183
|
private _account;
|
|
137
184
|
private _network;
|
|
138
|
-
private readonly
|
|
185
|
+
private readonly walletCoreV1;
|
|
186
|
+
private readonly walletStandardCore;
|
|
139
187
|
private _connecting;
|
|
140
188
|
private _connected;
|
|
189
|
+
/**
|
|
190
|
+
* Core functionality constructor.
|
|
191
|
+
* For legacy wallet adapter v1 support we expect the dapp to pass in wallet plugins,
|
|
192
|
+
* since AIP-62 standard support this is optional for dapps.
|
|
193
|
+
*
|
|
194
|
+
* @param plugins legacy wallet adapter v1 wallet plugins
|
|
195
|
+
*/
|
|
141
196
|
constructor(plugins: ReadonlyArray<Wallet>);
|
|
142
197
|
private scopePollingDetectionStrategy;
|
|
198
|
+
private fetchAptosWallets;
|
|
199
|
+
private setWallets;
|
|
200
|
+
/**
|
|
201
|
+
* To maintain support for both plugins and AIP-62 standard wallets,
|
|
202
|
+
* without introducing dapps breaking changes, we convert
|
|
203
|
+
* AIP-62 standard compatible wallets to the legacy adapter wallet plugin type.
|
|
204
|
+
*
|
|
205
|
+
* @param standardWallet An AIP-62 standard compatible wallet
|
|
206
|
+
*/
|
|
207
|
+
private standardizeStandardWalletToPluginWalletType;
|
|
208
|
+
/**
|
|
209
|
+
* Helper function to ensure wallet exists
|
|
210
|
+
*
|
|
211
|
+
* @param wallet A wallet
|
|
212
|
+
*/
|
|
213
|
+
private ensureWalletExists;
|
|
214
|
+
/**
|
|
215
|
+
* Helper function to ensure account exists
|
|
216
|
+
*
|
|
217
|
+
* @param account An account
|
|
218
|
+
*/
|
|
219
|
+
private ensureAccountExists;
|
|
220
|
+
/**
|
|
221
|
+
* @deprecated use ensureWalletExists
|
|
222
|
+
*/
|
|
143
223
|
private doesWalletExist;
|
|
224
|
+
/**
|
|
225
|
+
* Function to cleat wallet adapter data.
|
|
226
|
+
*
|
|
227
|
+
* - Removes current connected wallet state
|
|
228
|
+
* - Removes current connected account state
|
|
229
|
+
* - Removes current connected network state
|
|
230
|
+
* - Removes autoconnect local storage value
|
|
231
|
+
*/
|
|
144
232
|
private clearData;
|
|
233
|
+
/**
|
|
234
|
+
* Queries and sets ANS name for the current connected wallet account
|
|
235
|
+
*/
|
|
145
236
|
private setAnsName;
|
|
237
|
+
/**
|
|
238
|
+
* Sets the connected wallet
|
|
239
|
+
*
|
|
240
|
+
* @param wallet A wallet
|
|
241
|
+
*/
|
|
146
242
|
setWallet(wallet: Wallet | null): void;
|
|
147
|
-
|
|
148
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Sets the connected account
|
|
245
|
+
*
|
|
246
|
+
* `AccountInfo` type comes from a legacy wallet adapter plugin
|
|
247
|
+
* `StandardAccountInfo` type comes from AIP-62 standard compatible wallet when onAccountChange event is called
|
|
248
|
+
* `UserResponse<StandardAccountInfo>` type comes from AIP-62 standard compatible wallet on wallet connect
|
|
249
|
+
*
|
|
250
|
+
* @param account An account
|
|
251
|
+
*/
|
|
252
|
+
setAccount(account: AccountInfo | AccountInfo$1 | UserResponse<AccountInfo$1> | null): void;
|
|
253
|
+
/**
|
|
254
|
+
* Sets the connected network
|
|
255
|
+
*
|
|
256
|
+
* `NetworkInfo` type comes from a legacy wallet adapter plugin
|
|
257
|
+
* `StandardNetworkInfo` type comes from AIP-62 standard compatible wallet
|
|
258
|
+
*
|
|
259
|
+
* @param network A network
|
|
260
|
+
*/
|
|
261
|
+
setNetwork(network: NetworkInfo | NetworkInfo$1 | null): void;
|
|
262
|
+
/**
|
|
263
|
+
* Helper function to detect whether a wallet is connected
|
|
264
|
+
*
|
|
265
|
+
* @returns boolean
|
|
266
|
+
*/
|
|
149
267
|
isConnected(): boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Getter to fetch all detected wallets
|
|
270
|
+
*/
|
|
150
271
|
get wallets(): ReadonlyArray<Wallet>;
|
|
272
|
+
/**
|
|
273
|
+
* Getter to fetch all detected plugin wallets
|
|
274
|
+
*/
|
|
275
|
+
get pluginWallets(): ReadonlyArray<Wallet>;
|
|
276
|
+
/**
|
|
277
|
+
* Getter to fetch all detected AIP-62 standard compatible wallets
|
|
278
|
+
*/
|
|
279
|
+
get standardWallets(): ReadonlyArray<AptosStandardWallet>;
|
|
151
280
|
/**
|
|
152
281
|
* Getter for the current connected wallet
|
|
282
|
+
*
|
|
153
283
|
* @return wallet info
|
|
154
284
|
* @throws WalletNotSelectedError
|
|
155
285
|
*/
|
|
156
286
|
get wallet(): WalletInfo | null;
|
|
157
287
|
/**
|
|
158
288
|
* Getter for the current connected account
|
|
289
|
+
*
|
|
159
290
|
* @return account info
|
|
160
291
|
* @throws WalletAccountError
|
|
161
292
|
*/
|
|
162
293
|
get account(): AccountInfo | null;
|
|
163
294
|
/**
|
|
164
295
|
* Getter for the current wallet network
|
|
296
|
+
*
|
|
165
297
|
* @return network info
|
|
166
298
|
* @throws WalletGetNetworkError
|
|
167
299
|
*/
|
|
168
300
|
get network(): NetworkInfo | null;
|
|
169
301
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* @param walletName. The wallet name we want to connect.
|
|
302
|
+
* Helper function to run some checks before we connect with a wallet.
|
|
303
|
+
*
|
|
304
|
+
* @param walletName. The wallet name we want to connect with.
|
|
173
305
|
*/
|
|
174
306
|
connect(walletName: string): Promise<void | string>;
|
|
175
307
|
/**
|
|
@@ -183,11 +315,12 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
183
315
|
*/
|
|
184
316
|
connectWallet(selectedWallet: Wallet): Promise<void>;
|
|
185
317
|
/**
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
318
|
+
* Disconnect the current connected wallet. On success, we clear the
|
|
319
|
+
* current account, current network and LocalStorage data.
|
|
320
|
+
*
|
|
321
|
+
* @emit emits "disconnect" event
|
|
322
|
+
* @throws WalletDisconnectionError
|
|
323
|
+
*/
|
|
191
324
|
disconnect(): Promise<void>;
|
|
192
325
|
/**
|
|
193
326
|
* Signs and submits a transaction to chain
|
|
@@ -212,12 +345,19 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
212
345
|
*/
|
|
213
346
|
signTransaction(transactionOrPayload: AnyRawTransaction | Types.TransactionPayload, asFeePayer?: boolean, options?: InputGenerateTransactionOptions): Promise<AccountAuthenticator>;
|
|
214
347
|
/**
|
|
215
|
-
Sign message (doesnt submit to chain).
|
|
216
|
-
|
|
217
|
-
@
|
|
218
|
-
@
|
|
348
|
+
* Sign message (doesnt submit to chain).
|
|
349
|
+
*
|
|
350
|
+
* @param message
|
|
351
|
+
* @return response from the wallet's signMessage function
|
|
352
|
+
* @throws WalletSignMessageError
|
|
219
353
|
*/
|
|
220
354
|
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
|
355
|
+
/**
|
|
356
|
+
* Submits transaction to chain
|
|
357
|
+
*
|
|
358
|
+
* @param transaction
|
|
359
|
+
* @returns PendingTransactionResponse
|
|
360
|
+
*/
|
|
221
361
|
submitTransaction(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>;
|
|
222
362
|
/**
|
|
223
363
|
Event for when account has changed on the wallet
|
|
@@ -251,4 +391,4 @@ declare function isRedirectable(): boolean;
|
|
|
251
391
|
declare function generalizedErrorMessage(error: any): string;
|
|
252
392
|
declare const areBCSArguments: (args: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes>) => boolean;
|
|
253
393
|
|
|
254
|
-
export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, InputTransactionData, NetworkInfo, NetworkName, OnAccountChange, OnNetworkChange, PluginProvider, SignMessagePayload, SignMessageResponse, TransactionOptions, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, areBCSArguments, generalizedErrorMessage, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage };
|
|
394
|
+
export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosStandardWallet, AptosWalletErrorResult, ChainIdToAnsSupportedNetworkMap, InputTransactionData, NetworkInfo, NetworkName, OnAccountChange, OnNetworkChange, PluginProvider, SignMessagePayload, SignMessageResponse, TransactionOptions, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, WalletStandardCore, areBCSArguments, generalizedErrorMessage, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage };
|