@aptos-labs/wallet-adapter-react 0.1.7 → 0.2.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ # @aptos-labs/wallet-adapter-react
2
+
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - c3eb031: Export WalletReadyState enum from react package
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 6e53116: Add support to verify a signed message
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [18a0429]
18
+ - Updated dependencies [42e29f6]
19
+ - Updated dependencies [576bb57]
20
+ - Updated dependencies [6e53116]
21
+ - @aptos-labs/wallet-adapter-core@0.2.0
package/README.md CHANGED
@@ -4,6 +4,25 @@ A react provider wrapper for the Aptos Wallet Adapter
4
4
 
5
5
  Dapps that want to use the adapter should install this package and other supported wallet packages.
6
6
 
7
+ ### Support
8
+
9
+ The react provider supports all [wallet standard](https://aptos.dev/guides/wallet-standard) functions and feature functions
10
+
11
+ ##### Standard functions
12
+
13
+ connect
14
+ disconnect
15
+ connected
16
+ account
17
+ network
18
+ signAndSubmitTransaction
19
+ signMessage
20
+
21
+ ##### Feature functions
22
+
23
+ signTransaction
24
+ signMessageAndVerify
25
+
7
26
  ### Usage
8
27
 
9
28
  #### Install Dependencies
@@ -71,6 +90,7 @@ const {
71
90
  signAndSubmitTransaction,
72
91
  signTransaction,
73
92
  signMessage,
93
+ signMessageAndVerify,
74
94
  } = useWallet();
75
95
  ```
76
96
 
@@ -113,29 +133,6 @@ const {
113
133
  </button>
114
134
  ```
115
135
 
116
- ##### signTransaction(payload)
117
-
118
- ```js
119
- const onSignTransaction = async () => {
120
- const payload: Types.TransactionPayload = {
121
- type: "entry_function_payload",
122
- function: "0x1::coin::transfer",
123
- type_arguments: ["0x1::aptos_coin::AptosCoin"],
124
- arguments: [account?.address, 1], // 1 is in Octas
125
- };
126
- try {
127
- const response = await signTransaction(payload);
128
- console.log("response", response);
129
- } catch (error: any) {
130
- console.log("error", error);
131
- }
132
- };
133
-
134
- <button onClick={onSignTransaction}>
135
- Sign transaction
136
- </button>
137
- ```
138
-
139
136
  ##### signMessage(payload)
140
137
 
141
138
  ```js
@@ -185,3 +182,47 @@ const {
185
182
  wallets.map((wallet) => <p>{wallet.name}</p>);
186
183
  }
187
184
  ```
185
+
186
+ ##### signTransaction(payload)
187
+
188
+ ```js
189
+ const onSignTransaction = async () => {
190
+ const payload: Types.TransactionPayload = {
191
+ type: "entry_function_payload",
192
+ function: "0x1::coin::transfer",
193
+ type_arguments: ["0x1::aptos_coin::AptosCoin"],
194
+ arguments: [account?.address, 1], // 1 is in Octas
195
+ };
196
+ try {
197
+ const response = await signTransaction(payload);
198
+ console.log("response", response);
199
+ } catch (error: any) {
200
+ console.log("error", error);
201
+ }
202
+ };
203
+
204
+ <button onClick={onSignTransaction}>
205
+ Sign transaction
206
+ </button>
207
+ ```
208
+
209
+ ##### signMessageAndVerify(payload)
210
+
211
+ ```js
212
+ const onSignMessageAndVerify = async () => {
213
+ const payload = {
214
+ message: "Hello from Aptos Wallet Adapter",
215
+ nonce: "random_string",
216
+ };
217
+ try {
218
+ const response = await signMessageAndVerify(payload);
219
+ console.log("response", response);
220
+ } catch (error: any) {
221
+ console.log("error", error);
222
+ }
223
+ };
224
+
225
+ <button onClick={onSignMessageAndVerify}>
226
+ Sign message and verify
227
+ </button>
228
+ ```
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, SignMessagePayload, SignMessageResponse } from '@aptos-labs/wallet-adapter-core';
2
+ export { WalletName, WalletReadyState } from '@aptos-labs/wallet-adapter-core';
2
3
  import { Types } from 'aptos';
3
4
  import { ReactNode, FC } from 'react';
4
5
 
@@ -13,6 +14,7 @@ interface WalletContextState {
13
14
  signAndSubmitTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<any>;
14
15
  signTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<any>;
15
16
  signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
17
+ signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
16
18
  }
17
19
  declare function useWallet(): WalletContextState;
18
20
 
package/dist/index.js CHANGED
@@ -21,11 +21,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  AptosWalletAdapterProvider: () => AptosWalletAdapterProvider,
24
+ WalletReadyState: () => import_wallet_adapter_core.WalletReadyState,
24
25
  useWallet: () => useWallet
25
26
  });
26
27
  module.exports = __toCommonJS(src_exports);
27
28
 
28
29
  // src/useWallet.tsx
30
+ var import_wallet_adapter_core = require("@aptos-labs/wallet-adapter-core");
29
31
  var import_react = require("react");
30
32
  var DEFAULT_COUNTEXT = {
31
33
  connected: false
@@ -43,7 +45,7 @@ function useWallet() {
43
45
 
44
46
  // src/WalletProvider.tsx
45
47
  var import_react2 = require("react");
46
- var import_wallet_adapter_core = require("@aptos-labs/wallet-adapter-core");
48
+ var import_wallet_adapter_core2 = require("@aptos-labs/wallet-adapter-core");
47
49
  var import_jsx_runtime = require("react/jsx-runtime");
48
50
  var initialState = {
49
51
  connected: false,
@@ -57,7 +59,7 @@ var AptosWalletAdapterProvider = ({
57
59
  autoConnect = false
58
60
  }) => {
59
61
  const [{ connected, account, network, wallet }, setState] = (0, import_react2.useState)(initialState);
60
- const walletCore = (0, import_react2.useMemo)(() => new import_wallet_adapter_core.WalletCore(plugins), []);
62
+ const walletCore = (0, import_react2.useMemo)(() => new import_wallet_adapter_core2.WalletCore(plugins), []);
61
63
  const [wallets, setWallets] = (0, import_react2.useState)(walletCore.wallets);
62
64
  const connect = (walletName) => {
63
65
  try {
@@ -94,6 +96,13 @@ var AptosWalletAdapterProvider = ({
94
96
  throw error;
95
97
  }
96
98
  };
99
+ const signMessageAndVerify = async (message) => {
100
+ try {
101
+ return await walletCore.signMessageAndVerify(message);
102
+ } catch (error) {
103
+ throw error;
104
+ }
105
+ };
97
106
  (0, import_react2.useEffect)(() => {
98
107
  if (autoConnect) {
99
108
  if (localStorage.getItem("AptosWalletName")) {
@@ -194,7 +203,8 @@ var AptosWalletAdapterProvider = ({
194
203
  wallets,
195
204
  signAndSubmitTransaction,
196
205
  signTransaction,
197
- signMessage
206
+ signMessage,
207
+ signMessageAndVerify
198
208
  },
199
209
  children
200
210
  });
@@ -202,5 +212,6 @@ var AptosWalletAdapterProvider = ({
202
212
  // Annotate the CommonJS export names for ESM import in node:
203
213
  0 && (module.exports = {
204
214
  AptosWalletAdapterProvider,
215
+ WalletReadyState,
205
216
  useWallet
206
217
  });
package/dist/index.mjs CHANGED
@@ -1,4 +1,7 @@
1
1
  // src/useWallet.tsx
2
+ import {
3
+ WalletReadyState
4
+ } from "@aptos-labs/wallet-adapter-core";
2
5
  import { createContext, useContext } from "react";
3
6
  var DEFAULT_COUNTEXT = {
4
7
  connected: false
@@ -72,6 +75,13 @@ var AptosWalletAdapterProvider = ({
72
75
  throw error;
73
76
  }
74
77
  };
78
+ const signMessageAndVerify = async (message) => {
79
+ try {
80
+ return await walletCore.signMessageAndVerify(message);
81
+ } catch (error) {
82
+ throw error;
83
+ }
84
+ };
75
85
  useEffect(() => {
76
86
  if (autoConnect) {
77
87
  if (localStorage.getItem("AptosWalletName")) {
@@ -172,12 +182,14 @@ var AptosWalletAdapterProvider = ({
172
182
  wallets,
173
183
  signAndSubmitTransaction,
174
184
  signTransaction,
175
- signMessage
185
+ signMessage,
186
+ signMessageAndVerify
176
187
  },
177
188
  children
178
189
  });
179
190
  };
180
191
  export {
181
192
  AptosWalletAdapterProvider,
193
+ WalletReadyState,
182
194
  useWallet
183
195
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptos-labs/wallet-adapter-react",
3
- "version": "0.1.7",
3
+ "version": "0.2.1",
4
4
  "description": "Aptos Wallet Adapter React Provider",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -91,6 +91,14 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
91
91
  }
92
92
  };
93
93
 
94
+ const signMessageAndVerify = async (message: SignMessagePayload) => {
95
+ try {
96
+ return await walletCore.signMessageAndVerify(message);
97
+ } catch (error: any) {
98
+ throw error;
99
+ }
100
+ };
101
+
94
102
  useEffect(() => {
95
103
  if (autoConnect) {
96
104
  if (localStorage.getItem("AptosWalletName")) {
@@ -201,6 +209,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
201
209
  signAndSubmitTransaction,
202
210
  signTransaction,
203
211
  signMessage,
212
+ signMessageAndVerify,
204
213
  }}
205
214
  >
206
215
  {children}
package/src/index.tsx CHANGED
@@ -1,3 +1,4 @@
1
1
  import * as React from "react";
2
- export { useWallet } from "./useWallet";
2
+ export { useWallet, WalletReadyState } from "./useWallet";
3
+ export type { WalletName } from "./useWallet";
3
4
  export * from "./WalletProvider";
package/src/useWallet.tsx CHANGED
@@ -6,11 +6,13 @@ import {
6
6
  SignMessagePayload,
7
7
  SignMessageResponse,
8
8
  Wallet,
9
+ WalletReadyState,
9
10
  } from "@aptos-labs/wallet-adapter-core";
10
11
  import { createContext, useContext } from "react";
11
12
  import { Types } from "aptos";
12
13
 
13
14
  export type { WalletName };
15
+ export { WalletReadyState };
14
16
 
15
17
  export interface WalletContextState {
16
18
  connected: boolean;
@@ -29,6 +31,7 @@ export interface WalletContextState {
29
31
  options?: V
30
32
  ): Promise<any>;
31
33
  signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
34
+ signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
32
35
  }
33
36
 
34
37
  const DEFAULT_COUNTEXT = {