@aptos-labs/wallet-adapter-core 3.3.0 → 3.5.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.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4ca4201: Export PluginProvider type
8
+
9
+ ## 3.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - e1e9eb2: ['Bug fix'] Use current connected wallet to compare to the selected wallet before connecting to a wallet
14
+
3
15
  ## 3.3.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -97,7 +97,7 @@ interface AdapterPluginProps<Name extends string = string> {
97
97
  connect(): Promise<any>;
98
98
  disconnect: () => Promise<any>;
99
99
  network: () => Promise<any>;
100
- signAndSubmitTransaction<V>(transaction: Types.TransactionPayload | InputGenerateTransactionData, options?: InputGenerateTransactionOptions): Promise<{
100
+ signAndSubmitTransaction(transaction: Types.TransactionPayload | InputGenerateTransactionData, options?: InputGenerateTransactionOptions): Promise<{
101
101
  hash: Types.HexEncodedBytes;
102
102
  output?: any;
103
103
  } | PendingTransactionResponse>;
@@ -117,6 +117,18 @@ type InputTransactionData = {
117
117
  data: InputGenerateTransactionPayloadData;
118
118
  options?: InputGenerateTransactionOptions;
119
119
  };
120
+ interface PluginProvider {
121
+ connect: () => Promise<AccountInfo>;
122
+ account: () => Promise<AccountInfo>;
123
+ disconnect: () => Promise<void>;
124
+ signAndSubmitTransaction: (transaction: any, options?: any) => Promise<{
125
+ hash: Types.HexEncodedBytes;
126
+ } | AptosWalletErrorResult>;
127
+ signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>;
128
+ network: () => Promise<NetworkInfo>;
129
+ onAccountChange: (listener: (newAddress: AccountInfo) => Promise<void>) => Promise<void>;
130
+ onNetworkChange: OnNetworkChange;
131
+ }
120
132
 
121
133
  declare class WalletCore extends EventEmitter<WalletCoreEvents> {
122
134
  private _wallets;
@@ -239,4 +251,4 @@ declare function isRedirectable(): boolean;
239
251
  declare function generalizedErrorMessage(error: any): string;
240
252
  declare const areBCSArguments: (args: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes>) => boolean;
241
253
 
242
- export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, InputTransactionData, NetworkInfo, NetworkName, OnAccountChange, OnNetworkChange, SignMessagePayload, SignMessageResponse, TransactionOptions, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, areBCSArguments, generalizedErrorMessage, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage };
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 };
package/dist/index.js CHANGED
@@ -309,6 +309,11 @@ var WalletCoreV1 = class extends import_eventemitter3.default {
309
309
  }
310
310
  }
311
311
  async signAndSubmitBCSTransaction(transaction, wallet, options) {
312
+ if (!("signAndSubmitBCSTransaction" in wallet)) {
313
+ throw new WalletNotSupportedMethod(
314
+ `Submit a BCS Transaction is not supported by ${wallet.name}`
315
+ ).message;
316
+ }
312
317
  try {
313
318
  const response = await wallet.signAndSubmitBCSTransaction(
314
319
  transaction,
@@ -435,14 +440,14 @@ var WalletCore = class extends import_eventemitter32.default {
435
440
  }
436
441
  }
437
442
  async connect(walletName) {
438
- var _a;
443
+ var _a, _b;
439
444
  const selectedWallet = (_a = this._wallets) == null ? void 0 : _a.find(
440
445
  (wallet) => wallet.name === walletName
441
446
  );
442
447
  if (!selectedWallet)
443
448
  return;
444
449
  if (this._connected) {
445
- if (selectedWallet.name === walletName)
450
+ if (((_b = this._wallet) == null ? void 0 : _b.name) === walletName)
446
451
  throw new WalletConnectionError(
447
452
  `${walletName} wallet is already connected`
448
453
  ).message;
package/dist/index.mjs CHANGED
@@ -275,6 +275,11 @@ var WalletCoreV1 = class extends EventEmitter {
275
275
  }
276
276
  }
277
277
  async signAndSubmitBCSTransaction(transaction, wallet, options) {
278
+ if (!("signAndSubmitBCSTransaction" in wallet)) {
279
+ throw new WalletNotSupportedMethod(
280
+ `Submit a BCS Transaction is not supported by ${wallet.name}`
281
+ ).message;
282
+ }
278
283
  try {
279
284
  const response = await wallet.signAndSubmitBCSTransaction(
280
285
  transaction,
@@ -401,14 +406,14 @@ var WalletCore = class extends EventEmitter2 {
401
406
  }
402
407
  }
403
408
  async connect(walletName) {
404
- var _a;
409
+ var _a, _b;
405
410
  const selectedWallet = (_a = this._wallets) == null ? void 0 : _a.find(
406
411
  (wallet) => wallet.name === walletName
407
412
  );
408
413
  if (!selectedWallet)
409
414
  return;
410
415
  if (this._connected) {
411
- if (selectedWallet.name === walletName)
416
+ if (((_b = this._wallet) == null ? void 0 : _b.name) === walletName)
412
417
  throw new WalletConnectionError(
413
418
  `${walletName} wallet is already connected`
414
419
  ).message;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptos-labs/wallet-adapter-core",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "Aptos Wallet Adapter Core",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/src/WalletCore.ts CHANGED
@@ -207,7 +207,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
207
207
 
208
208
  if (this._connected) {
209
209
  // if the selected wallet is already connected, we don't need to connect again
210
- if (selectedWallet.name === walletName)
210
+ if (this._wallet?.name === walletName)
211
211
  throw new WalletConnectionError(
212
212
  `${walletName} wallet is already connected`
213
213
  ).message;
@@ -2,6 +2,7 @@ import { TxnBuilderTypes, Types } from "aptos";
2
2
  import EventEmitter from "eventemitter3";
3
3
 
4
4
  import {
5
+ WalletNotSupportedMethod,
5
6
  WalletSignAndSubmitMessageError,
6
7
  WalletSignTransactionError,
7
8
  } from "./error";
@@ -45,6 +46,11 @@ export class WalletCoreV1 extends EventEmitter<WalletCoreEvents> {
45
46
  wallet: Wallet,
46
47
  options?: TransactionOptions
47
48
  ): Promise<any> {
49
+ if (!("signAndSubmitBCSTransaction" in wallet)) {
50
+ throw new WalletNotSupportedMethod(
51
+ `Submit a BCS Transaction is not supported by ${wallet.name}`
52
+ ).message;
53
+ }
48
54
  try {
49
55
  const response = await (wallet as any).signAndSubmitBCSTransaction(
50
56
  transaction,
package/src/types.ts CHANGED
@@ -103,7 +103,7 @@ export interface AdapterPluginProps<Name extends string = string> {
103
103
  connect(): Promise<any>;
104
104
  disconnect: () => Promise<any>;
105
105
  network: () => Promise<any>;
106
- signAndSubmitTransaction<V>(
106
+ signAndSubmitTransaction(
107
107
  transaction: Types.TransactionPayload | InputGenerateTransactionData,
108
108
  options?: InputGenerateTransactionOptions
109
109
  ): Promise<
@@ -134,3 +134,20 @@ export type InputTransactionData = {
134
134
  data: InputGenerateTransactionPayloadData;
135
135
  options?: InputGenerateTransactionOptions;
136
136
  };
137
+
138
+ // To be used by a wallet plugin
139
+ export interface PluginProvider {
140
+ connect: () => Promise<AccountInfo>;
141
+ account: () => Promise<AccountInfo>;
142
+ disconnect: () => Promise<void>;
143
+ signAndSubmitTransaction: (
144
+ transaction: any,
145
+ options?: any
146
+ ) => Promise<{ hash: Types.HexEncodedBytes } | AptosWalletErrorResult>;
147
+ signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>;
148
+ network: () => Promise<NetworkInfo>;
149
+ onAccountChange: (
150
+ listener: (newAddress: AccountInfo) => Promise<void>
151
+ ) => Promise<void>;
152
+ onNetworkChange: OnNetworkChange;
153
+ }