@aptos-labs/wallet-adapter-core 3.6.0 → 3.8.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @aptos-labs/wallet-adapter-core
2
2
 
3
+ ## 3.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4127cfb: Support AIP-62 connect wallet method response
8
+
9
+ ## 3.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 4d6e2f6: Add AIP-62 wallet standard support
14
+
3
15
  ## 3.6.0
4
16
 
5
17
  ### Minor Changes
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, InputGenerateTransactionData, InputGenerateTransactionOptions, PendingTransactionResponse, InputSubmitTransactionData, AccountAddressInput, InputGenerateTransactionPayloadData, AnyRawTransaction, AccountAuthenticator, EntryFunctionArgumentTypes, SimpleEntryFunctionArgumentTypes } from '@aptos-labs/ts-sdk';
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 | InputGenerateTransactionData, options?: InputGenerateTransactionOptions): Promise<{
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,172 @@ interface PluginProvider {
130
137
  onNetworkChange: OnNetworkChange;
131
138
  }
132
139
 
140
+ type AptosStandardWallet = AptosWallet & {
141
+ readyState?: WalletReadyState;
142
+ };
143
+ declare class WalletStandardCore {
144
+ connect(wallet: Wallet): Promise<AccountInfo$1>;
145
+ /**
146
+ * Signs and submits a transaction to chain
147
+ *
148
+ * @param transactionInput InputTransactionData
149
+ * @returns PendingTransactionResponse
150
+ */
151
+ signAndSubmitTransaction(transactionInput: InputTransactionData, aptos: Aptos, account: AccountInfo, wallet: Wallet): Promise<PendingTransactionResponse>;
152
+ /**
153
+ * Signs a transaction
154
+ *
155
+ * To support both existing wallet adapter V1 and V2, we support 2 input types
156
+ *
157
+ * @param transactionOrPayload AnyRawTransaction
158
+ * @param options asFeePayer. To sign a transaction as the fee payer sponsor
159
+ *
160
+ * @returns AptosSignTransactionOutput
161
+ */
162
+ signTransaction(transaction: AnyRawTransaction, wallet: Wallet, asFeePayer?: boolean): Promise<AptosSignTransactionOutput>;
163
+ /**
164
+ * Sign message
165
+ *
166
+ * @param message AptosSignMessageInput
167
+ * @return AptosSignMessageOutput
168
+ * @throws WalletSignMessageError
169
+ */
170
+ signMessage(message: AptosSignMessageInput, wallet: Wallet): Promise<AptosSignMessageOutput>;
171
+ /**
172
+ * Signs a message and verifies the signer
173
+ * @param message AptosSignMessageInput
174
+ * @returns boolean
175
+ */
176
+ signMessageAndVerify(message: AptosSignMessageInput, wallet: Wallet): Promise<boolean>;
177
+ }
178
+
133
179
  declare class WalletCore extends EventEmitter<WalletCoreEvents> {
134
180
  private _wallets;
181
+ private _standard_wallets;
182
+ private _all_wallets;
135
183
  private _wallet;
136
184
  private _account;
137
185
  private _network;
138
- private readonly waletCoreV1;
186
+ private readonly walletCoreV1;
187
+ private readonly walletStandardCore;
139
188
  private _connecting;
140
189
  private _connected;
190
+ /**
191
+ * Core functionality constructor.
192
+ * For legacy wallet adapter v1 support we expect the dapp to pass in wallet plugins,
193
+ * since AIP-62 standard support this is optional for dapps.
194
+ *
195
+ * @param plugins legacy wallet adapter v1 wallet plugins
196
+ */
141
197
  constructor(plugins: ReadonlyArray<Wallet>);
142
198
  private scopePollingDetectionStrategy;
199
+ private fetchAptosWallets;
200
+ private setWallets;
201
+ /**
202
+ * To maintain support for both plugins and AIP-62 standard wallets,
203
+ * without introducing dapps breaking changes, we convert
204
+ * AIP-62 standard compatible wallets to the legacy adapter wallet plugin type.
205
+ *
206
+ * @param standardWallet An AIP-62 standard compatible wallet
207
+ */
208
+ private standardizeStandardWalletToPluginWalletType;
209
+ /**
210
+ * Helper function to ensure wallet exists
211
+ *
212
+ * @param wallet A wallet
213
+ */
214
+ private ensureWalletExists;
215
+ /**
216
+ * Helper function to ensure account exists
217
+ *
218
+ * @param account An account
219
+ */
220
+ private ensureAccountExists;
221
+ /**
222
+ * @deprecated use ensureWalletExists
223
+ */
143
224
  private doesWalletExist;
225
+ /**
226
+ * Function to cleat wallet adapter data.
227
+ *
228
+ * - Removes current connected wallet state
229
+ * - Removes current connected account state
230
+ * - Removes current connected network state
231
+ * - Removes autoconnect local storage value
232
+ */
144
233
  private clearData;
234
+ /**
235
+ * Queries and sets ANS name for the current connected wallet account
236
+ */
145
237
  private setAnsName;
238
+ /**
239
+ * Sets the connected wallet
240
+ *
241
+ * @param wallet A wallet
242
+ */
146
243
  setWallet(wallet: Wallet | null): void;
147
- setAccount(account: AccountInfo | null): void;
148
- setNetwork(network: NetworkInfo | null): void;
244
+ /**
245
+ * Sets the connected account
246
+ *
247
+ * `AccountInfo` type comes from a legacy wallet adapter plugin
248
+ * `StandardAccountInfo` type comes from AIP-62 standard compatible wallet when onAccountChange event is called
249
+ * `UserResponse<StandardAccountInfo>` type comes from AIP-62 standard compatible wallet on wallet connect
250
+ *
251
+ * @param account An account
252
+ */
253
+ setAccount(account: AccountInfo | AccountInfo$1 | UserResponse<AccountInfo$1> | null): void;
254
+ /**
255
+ * Sets the connected network
256
+ *
257
+ * `NetworkInfo` type comes from a legacy wallet adapter plugin
258
+ * `StandardNetworkInfo` type comes from AIP-62 standard compatible wallet
259
+ *
260
+ * @param network A network
261
+ */
262
+ setNetwork(network: NetworkInfo | NetworkInfo$1 | null): void;
263
+ /**
264
+ * Helper function to detect whether a wallet is connected
265
+ *
266
+ * @returns boolean
267
+ */
149
268
  isConnected(): boolean;
269
+ /**
270
+ * Getter to fetch all detected wallets
271
+ */
150
272
  get wallets(): ReadonlyArray<Wallet>;
273
+ /**
274
+ * Getter to fetch all detected plugin wallets
275
+ */
276
+ get pluginWallets(): ReadonlyArray<Wallet>;
277
+ /**
278
+ * Getter to fetch all detected AIP-62 standard compatible wallets
279
+ */
280
+ get standardWallets(): ReadonlyArray<AptosStandardWallet>;
151
281
  /**
152
282
  * Getter for the current connected wallet
283
+ *
153
284
  * @return wallet info
154
285
  * @throws WalletNotSelectedError
155
286
  */
156
287
  get wallet(): WalletInfo | null;
157
288
  /**
158
289
  * Getter for the current connected account
290
+ *
159
291
  * @return account info
160
292
  * @throws WalletAccountError
161
293
  */
162
294
  get account(): AccountInfo | null;
163
295
  /**
164
296
  * Getter for the current wallet network
297
+ *
165
298
  * @return network info
166
299
  * @throws WalletGetNetworkError
167
300
  */
168
301
  get network(): NetworkInfo | null;
169
302
  /**
170
- * We first make sure we can connect a dapp to a wallet.
171
- * If all good, we connect the wallet by calling `this.connectWallet`
172
- * @param walletName. The wallet name we want to connect.
303
+ * Helper function to run some checks before we connect with a wallet.
304
+ *
305
+ * @param walletName. The wallet name we want to connect with.
173
306
  */
174
307
  connect(walletName: string): Promise<void | string>;
175
308
  /**
@@ -183,11 +316,12 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
183
316
  */
184
317
  connectWallet(selectedWallet: Wallet): Promise<void>;
185
318
  /**
186
- Disconnect the exisitng wallet. On success, we clear the
187
- current account, current network and LocalStorage data.
188
- @emit emits "disconnect" event
189
- @throws WalletDisconnectionError
190
- */
319
+ * Disconnect the current connected wallet. On success, we clear the
320
+ * current account, current network and LocalStorage data.
321
+ *
322
+ * @emit emits "disconnect" event
323
+ * @throws WalletDisconnectionError
324
+ */
191
325
  disconnect(): Promise<void>;
192
326
  /**
193
327
  * Signs and submits a transaction to chain
@@ -212,12 +346,19 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
212
346
  */
213
347
  signTransaction(transactionOrPayload: AnyRawTransaction | Types.TransactionPayload, asFeePayer?: boolean, options?: InputGenerateTransactionOptions): Promise<AccountAuthenticator>;
214
348
  /**
215
- Sign message (doesnt submit to chain).
216
- @param message
217
- @return response from the wallet's signMessage function
218
- @throws WalletSignMessageError
349
+ * Sign message (doesnt submit to chain).
350
+ *
351
+ * @param message
352
+ * @return response from the wallet's signMessage function
353
+ * @throws WalletSignMessageError
219
354
  */
220
355
  signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
356
+ /**
357
+ * Submits transaction to chain
358
+ *
359
+ * @param transaction
360
+ * @returns PendingTransactionResponse
361
+ */
221
362
  submitTransaction(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>;
222
363
  /**
223
364
  Event for when account has changed on the wallet
@@ -251,4 +392,4 @@ declare function isRedirectable(): boolean;
251
392
  declare function generalizedErrorMessage(error: any): string;
252
393
  declare const areBCSArguments: (args: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes>) => boolean;
253
394
 
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 };
395
+ 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 };