@aptos-labs/wallet-adapter-core 2.5.1 → 3.0.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/src/types.ts CHANGED
@@ -1,17 +1,40 @@
1
1
  import { Types } from "aptos";
2
- import { NetworkName, WalletReadyState } from "./constants";
2
+ import {
3
+ Network,
4
+ InputGenerateTransactionData,
5
+ InputGenerateTransactionOptions,
6
+ InputSubmitTransactionData,
7
+ PendingTransactionResponse,
8
+ } from "@aptos-labs/ts-sdk";
9
+ import { WalletReadyState } from "./constants";
3
10
 
4
11
  export { TxnBuilderTypes, Types } from "aptos";
12
+ export type {
13
+ InputGenerateTransactionData,
14
+ InputGenerateTransactionOptions,
15
+ AnyRawTransaction,
16
+ InputSubmitTransactionData,
17
+ PendingTransactionResponse,
18
+ AccountAuthenticator,
19
+ } from "@aptos-labs/ts-sdk";
20
+
5
21
  // WalletName is a nominal type that wallet adapters should use, e.g. `'MyCryptoWallet' as WalletName<'MyCryptoWallet'>`
6
22
  export type WalletName<T extends string = string> = T & {
7
23
  __brand__: "WalletName";
8
24
  };
25
+
9
26
  export type NetworkInfo = {
10
- name: NetworkName;
27
+ name: Network;
11
28
  chainId?: string;
12
29
  url?: string;
13
30
  };
14
31
 
32
+ export type WalletInfo = {
33
+ name: WalletName;
34
+ icon: string;
35
+ url: string;
36
+ };
37
+
15
38
  export type AccountInfo = {
16
39
  address: string;
17
40
  publicKey: string | string[];
@@ -25,45 +48,68 @@ export interface AptosWalletErrorResult {
25
48
  message: string;
26
49
  }
27
50
 
51
+ export declare interface WalletCoreEvents {
52
+ connect(account: AccountInfo | null): void;
53
+ disconnect(): void;
54
+ readyStateChange(wallet: Wallet): void;
55
+ networkChange(network: NetworkInfo | null): void;
56
+ accountChange(account: AccountInfo | null): void;
57
+ }
58
+
59
+ export interface SignMessagePayload {
60
+ address?: boolean; // Should we include the address of the account in the message
61
+ application?: boolean; // Should we include the domain of the dapp
62
+ chainId?: boolean; // Should we include the current chain id the wallet is connected to
63
+ message: string; // The message to be signed and displayed to the user
64
+ nonce: string; // A nonce the dapp should generate
65
+ }
66
+
67
+ export interface SignMessageResponse {
68
+ address?: string;
69
+ application?: string;
70
+ chainId?: number;
71
+ fullMessage: string; // The message that was generated to sign
72
+ message: string; // The message passed in by the user
73
+ nonce: string;
74
+ prefix: "APTOS"; // Should always be APTOS
75
+ signature: string | string[]; // The signed full message
76
+ bitmap?: Uint8Array; // a 4-byte (32 bits) bit-vector of length N
77
+ }
78
+
28
79
  export type OnNetworkChange = (
29
80
  callBack: (networkInfo: NetworkInfo) => Promise<void>
30
81
  ) => Promise<void>;
31
82
 
32
- export interface PluginProvider {
33
- connect: () => Promise<AccountInfo>;
34
- account: () => Promise<AccountInfo>;
35
- disconnect: () => Promise<void>;
36
- signAndSubmitTransaction: (
37
- transaction: any,
38
- options?: any
39
- ) => Promise<{ hash: Types.HexEncodedBytes } | AptosWalletErrorResult>;
40
- signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>;
41
- network: () => Promise<NetworkName>;
42
- onAccountChange: (
43
- listener: (newAddress: AccountInfo) => Promise<void>
44
- ) => Promise<void>;
45
- onNetworkChange: OnNetworkChange;
46
- }
83
+ export type OnAccountChange = (
84
+ callBack: (accountInfo: AccountInfo) => Promise<any>
85
+ ) => Promise<void>;
47
86
 
48
87
  export interface AdapterPluginEvents {
49
88
  onNetworkChange: OnNetworkChange;
50
- onAccountChange(callback: any): Promise<any>;
89
+ onAccountChange: OnAccountChange;
51
90
  }
52
91
 
92
+ // TODO add signTransaction()
53
93
  export interface AdapterPluginProps<Name extends string = string> {
54
94
  name: WalletName<Name>;
55
95
  url: string;
56
96
  icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
97
+ version?: "v1" | "v2";
57
98
  providerName?: string;
58
99
  provider: any;
59
100
  deeplinkProvider?: (data: { url: string }) => string;
60
101
  connect(): Promise<any>;
61
102
  disconnect: () => Promise<any>;
62
103
  network: () => Promise<any>;
63
- signAndSubmitTransaction<T extends Types.TransactionPayload, V>(
64
- transaction: T,
65
- options?: V
66
- ): Promise<{ hash: Types.HexEncodedBytes }>;
104
+ signAndSubmitTransaction<V>(
105
+ transaction: Types.TransactionPayload | InputGenerateTransactionData,
106
+ options?: InputGenerateTransactionOptions
107
+ ): Promise<
108
+ { hash: Types.HexEncodedBytes; output?: any } | PendingTransactionResponse
109
+ >;
110
+ submitTransaction?(
111
+ transaction: InputSubmitTransactionData
112
+ ): Promise<PendingTransactionResponse>;
67
113
  signMessage<T extends SignMessagePayload>(
68
114
  message: T
69
115
  ): Promise<SignMessageResponse>;
@@ -76,40 +122,6 @@ export type Wallet<Name extends string = string> = AdapterPlugin<Name> & {
76
122
  readyState?: WalletReadyState;
77
123
  };
78
124
 
79
- export type WalletInfo = {
80
- name: WalletName;
81
- icon: string;
82
- url: string;
83
- };
84
-
85
- export declare interface WalletCoreEvents {
86
- connect(account: AccountInfo | null): void;
87
- disconnect(): void;
88
- readyStateChange(wallet: Wallet): void;
89
- networkChange(network: NetworkInfo | null): void;
90
- accountChange(account: AccountInfo | null): void;
91
- }
92
-
93
- export interface SignMessagePayload {
94
- address?: boolean; // Should we include the address of the account in the message
95
- application?: boolean; // Should we include the domain of the dapp
96
- chainId?: boolean; // Should we include the current chain id the wallet is connected to
97
- message: string; // The message to be signed and displayed to the user
98
- nonce: string; // A nonce the dapp should generate
99
- }
100
-
101
- export interface SignMessageResponse {
102
- address?: string;
103
- application?: string;
104
- chainId?: number;
105
- fullMessage: string; // The message that was generated to sign
106
- message: string; // The message passed in by the user
107
- nonce: string;
108
- prefix: "APTOS"; // Should always be APTOS
109
- signature: string | string[]; // The signed full message
110
- bitmap?: Uint8Array; // a 4-byte (32 bits) bit-vector of length N
111
- }
112
-
113
125
  export interface TransactionOptions {
114
126
  max_gas_amount?: bigint;
115
127
  gas_unit_price?: bigint;
@@ -18,9 +18,15 @@ export function isInAppBrowser(): boolean {
18
18
 
19
19
  export function isRedirectable(): boolean {
20
20
  // SSR: return false
21
- if (typeof navigator === 'undefined' || !navigator) return false;
21
+ if (typeof navigator === "undefined" || !navigator) return false;
22
22
 
23
23
  // if we are on mobile and NOT in a in-app browser we will redirect to a wallet app
24
24
 
25
25
  return isMobile() && !isInAppBrowser();
26
26
  }
27
+
28
+ export function generalizedErrorMessage(error: any): string {
29
+ return typeof error === "object" && "message" in error
30
+ ? error.message
31
+ : error;
32
+ }