@manahippo/aptos-wallet-adapter 0.4.3 → 0.4.4
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/README.md +5 -2
- package/dist/WalletAdapters/AptosSnap.d.ts +42 -0
- package/dist/WalletAdapters/AptosSnap.d.ts.map +1 -0
- package/dist/WalletAdapters/AptosSnap.js +185 -0
- package/dist/WalletAdapters/AptosSnap.js.map +1 -0
- package/dist/WalletAdapters/FletchWallet.d.ts +57 -0
- package/dist/WalletAdapters/FletchWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/FletchWallet.js +178 -0
- package/dist/WalletAdapters/FletchWallet.js.map +1 -0
- package/dist/WalletAdapters/PetraWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/PetraWallet.js +1 -1
- package/dist/WalletAdapters/PetraWallet.js.map +1 -1
- package/dist/WalletAdapters/PontemWallet.d.ts +4 -6
- package/dist/WalletAdapters/PontemWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/PontemWallet.js +4 -5
- package/dist/WalletAdapters/PontemWallet.js.map +1 -1
- package/dist/WalletAdapters/RiseWallet.d.ts +3 -5
- package/dist/WalletAdapters/RiseWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/RiseWallet.js +7 -5
- package/dist/WalletAdapters/RiseWallet.js.map +1 -1
- package/dist/WalletAdapters/index.d.ts +2 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +2 -0
- package/dist/WalletAdapters/index.js.map +1 -1
- package/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
- package/dist/WalletProviders/WalletProvider.js +12 -5
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/package.json +3 -2
- package/src/WalletAdapters/AptosSnap.ts +235 -0
- package/src/WalletAdapters/FletchWallet.ts +223 -0
- package/src/WalletAdapters/PetraWallet.ts +2 -1
- package/src/WalletAdapters/PontemWallet.ts +8 -9
- package/src/WalletAdapters/RiseWallet.ts +10 -7
- package/src/WalletAdapters/index.ts +2 -0
- package/src/WalletProviders/WalletProvider.tsx +14 -7
@@ -0,0 +1,223 @@
|
|
1
|
+
import { HexEncodedBytes, TransactionPayload } from 'aptos/src/generated';
|
2
|
+
import {
|
3
|
+
WalletDisconnectionError,
|
4
|
+
WalletNotConnectedError,
|
5
|
+
WalletNotReadyError,
|
6
|
+
WalletSignAndSubmitMessageError,
|
7
|
+
WalletSignMessageError,
|
8
|
+
WalletSignTransactionError
|
9
|
+
} from '../WalletProviders/errors';
|
10
|
+
import {
|
11
|
+
AccountKeys,
|
12
|
+
BaseWalletAdapter,
|
13
|
+
scopePollingDetectionStrategy,
|
14
|
+
SignMessagePayload,
|
15
|
+
SignMessageResponse,
|
16
|
+
WalletName,
|
17
|
+
WalletReadyState
|
18
|
+
} from './BaseAdapter';
|
19
|
+
|
20
|
+
interface IFletchWallet {
|
21
|
+
connect: () => Promise<{ Address: string; PublicKey: string, code: number, error?: any }>;
|
22
|
+
account: () => Promise<string>;
|
23
|
+
isConnected: () => Promise<boolean>;
|
24
|
+
signAndSubmitTransaction(transaction: any): Promise<{ code: number, error?: any, hash: string }>;
|
25
|
+
signTransaction(payload: any): Promise<{ code: number, error?: any, tx: Uint8Array }>;
|
26
|
+
signMessage(message: SignMessagePayload): Promise<{ code: number, error?: any, signedMessage: SignMessageResponse }>;
|
27
|
+
disconnect(): Promise<void>;
|
28
|
+
}
|
29
|
+
|
30
|
+
interface AptosWindow extends Window {
|
31
|
+
fletch?: IFletchWallet;
|
32
|
+
}
|
33
|
+
|
34
|
+
declare const window: AptosWindow;
|
35
|
+
|
36
|
+
export const FletchWalletName = 'Fletch' as WalletName<'Fletch'>;
|
37
|
+
|
38
|
+
export interface FletchWalletAdapterConfig {
|
39
|
+
provider?: IFletchWallet;
|
40
|
+
// network?: WalletAdapterNetwork;
|
41
|
+
timeout?: number;
|
42
|
+
}
|
43
|
+
|
44
|
+
export class FletchWalletAdapter extends BaseWalletAdapter {
|
45
|
+
name = FletchWalletName;
|
46
|
+
|
47
|
+
url = 'http://fletchwallet.io';
|
48
|
+
|
49
|
+
icon = 'http://fletchwallet.io/img/fletch-white.svg';
|
50
|
+
|
51
|
+
protected _provider: IFletchWallet;
|
52
|
+
|
53
|
+
// protected _network: WalletAdapterNetwork;
|
54
|
+
protected _timeout: number;
|
55
|
+
|
56
|
+
protected _readyState: WalletReadyState =
|
57
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
58
|
+
? WalletReadyState.Unsupported
|
59
|
+
: WalletReadyState.NotDetected;
|
60
|
+
|
61
|
+
protected _connecting: boolean;
|
62
|
+
|
63
|
+
protected _wallet: any | null;
|
64
|
+
|
65
|
+
constructor({
|
66
|
+
// provider,
|
67
|
+
// network = WalletAdapterNetwork.Mainnet,
|
68
|
+
timeout = 10000
|
69
|
+
}: FletchWalletAdapterConfig = {}) {
|
70
|
+
super();
|
71
|
+
|
72
|
+
this._provider = typeof window !== 'undefined' ? window.fletch : undefined;
|
73
|
+
// this._network = network;
|
74
|
+
this._timeout = timeout;
|
75
|
+
this._connecting = false;
|
76
|
+
this._wallet = null;
|
77
|
+
|
78
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
79
|
+
scopePollingDetectionStrategy(() => {
|
80
|
+
if (window.fletch) {
|
81
|
+
this._readyState = WalletReadyState.Installed;
|
82
|
+
this.emit('readyStateChange', this._readyState);
|
83
|
+
return true;
|
84
|
+
}
|
85
|
+
return false;
|
86
|
+
});
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
get publicAccount(): AccountKeys {
|
91
|
+
return {
|
92
|
+
publicKey: this._wallet?.publicKey || null,
|
93
|
+
address: this._wallet?.address || null,
|
94
|
+
authKey: this._wallet?.authKey || null
|
95
|
+
};
|
96
|
+
}
|
97
|
+
|
98
|
+
get connecting(): boolean {
|
99
|
+
return this._connecting;
|
100
|
+
}
|
101
|
+
|
102
|
+
get connected(): boolean {
|
103
|
+
return !!this._wallet?.isConnected;
|
104
|
+
}
|
105
|
+
|
106
|
+
get readyState(): WalletReadyState {
|
107
|
+
return this._readyState;
|
108
|
+
}
|
109
|
+
|
110
|
+
async connect(): Promise<void> {
|
111
|
+
try {
|
112
|
+
if (this.connected || this.connecting) return;
|
113
|
+
if (
|
114
|
+
!(
|
115
|
+
this._readyState === WalletReadyState.Loadable ||
|
116
|
+
this._readyState === WalletReadyState.Installed
|
117
|
+
)
|
118
|
+
)
|
119
|
+
throw new WalletNotReadyError();
|
120
|
+
this._connecting = true;
|
121
|
+
|
122
|
+
const provider = this._provider || window.fletch;
|
123
|
+
const isConnected = await this._provider?.isConnected();
|
124
|
+
if (isConnected === true) {
|
125
|
+
await provider?.disconnect();
|
126
|
+
}
|
127
|
+
|
128
|
+
const response = await provider?.connect();
|
129
|
+
if (response.code != 200) {
|
130
|
+
throw response.error
|
131
|
+
}
|
132
|
+
this._wallet = {
|
133
|
+
address: response?.Address,
|
134
|
+
publicKey: response?.PublicKey,
|
135
|
+
isConnected: true
|
136
|
+
};
|
137
|
+
|
138
|
+
this.emit('connect', this._wallet.publicKey);
|
139
|
+
} catch (error: any) {
|
140
|
+
this.emit('error', error);
|
141
|
+
throw error;
|
142
|
+
} finally {
|
143
|
+
this._connecting = false;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
async disconnect(): Promise<void> {
|
148
|
+
const wallet = this._wallet;
|
149
|
+
const provider = this._provider || window.fletch;
|
150
|
+
if (wallet) {
|
151
|
+
this._wallet = null;
|
152
|
+
|
153
|
+
try {
|
154
|
+
await provider?.disconnect();
|
155
|
+
} catch (error: any) {
|
156
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
this.emit('disconnect');
|
161
|
+
}
|
162
|
+
|
163
|
+
async signTransaction(transaction: TransactionPayload): Promise<Uint8Array> {
|
164
|
+
try {
|
165
|
+
const wallet = this._wallet;
|
166
|
+
const provider = this._provider || window.fletch;
|
167
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
168
|
+
|
169
|
+
const response = await provider.signTransaction(transaction);
|
170
|
+
if (response.code != 200) {
|
171
|
+
throw response.error
|
172
|
+
}
|
173
|
+
return response.tx;
|
174
|
+
} catch (error: any) {
|
175
|
+
const errMsg = error.message;
|
176
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
177
|
+
throw error;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
async signAndSubmitTransaction(
|
182
|
+
transaction: TransactionPayload
|
183
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
184
|
+
try {
|
185
|
+
const wallet = this._wallet;
|
186
|
+
const provider = this._provider || window.fletch;
|
187
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
188
|
+
const response = await provider.signAndSubmitTransaction(transaction);
|
189
|
+
if (response.code == 200) {
|
190
|
+
return { hash: response.hash };
|
191
|
+
}
|
192
|
+
|
193
|
+
throw response.error
|
194
|
+
|
195
|
+
} catch (error: any) {
|
196
|
+
const errMsg = error.message;
|
197
|
+
this.emit('error', new WalletSignAndSubmitMessageError(errMsg));
|
198
|
+
throw error;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
async signMessage(msgPayload: SignMessagePayload): Promise<SignMessageResponse> {
|
203
|
+
try {
|
204
|
+
const wallet = this._wallet;
|
205
|
+
const provider = this._provider || window.fletch;
|
206
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
207
|
+
if (typeof msgPayload !== 'object' || !msgPayload.nonce) {
|
208
|
+
throw new WalletSignMessageError('Invalid signMessage Payload');
|
209
|
+
}
|
210
|
+
|
211
|
+
const response = await provider?.signMessage(msgPayload);
|
212
|
+
if (response.code == 200) {
|
213
|
+
return response.signedMessage;
|
214
|
+
}
|
215
|
+
|
216
|
+
throw response.error
|
217
|
+
} catch (error: any) {
|
218
|
+
const errMsg = error.message;
|
219
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
220
|
+
throw error;
|
221
|
+
}
|
222
|
+
}
|
223
|
+
}
|
@@ -53,7 +53,8 @@ export interface AptosWalletAdapterConfig {
|
|
53
53
|
export class AptosWalletAdapter extends BaseWalletAdapter {
|
54
54
|
name = AptosWalletName;
|
55
55
|
|
56
|
-
url =
|
56
|
+
url =
|
57
|
+
'https://chrome.google.com/webstore/detail/petra-aptos-wallet/ejjladinnckdgjemekebdpeokbikhfci';
|
57
58
|
|
58
59
|
icon = 'https://miro.medium.com/fit/c/176/176/1*Gf747eyRywU8Img0tK5wvw.png';
|
59
60
|
|
@@ -12,6 +12,8 @@ import {
|
|
12
12
|
AccountKeys,
|
13
13
|
BaseWalletAdapter,
|
14
14
|
scopePollingDetectionStrategy,
|
15
|
+
SignMessagePayload,
|
16
|
+
SignMessageResponse,
|
15
17
|
WalletName,
|
16
18
|
WalletReadyState
|
17
19
|
} from './BaseAdapter';
|
@@ -45,11 +47,9 @@ interface IPontemWallet {
|
|
45
47
|
}>;
|
46
48
|
isConnected(): Promise<boolean>;
|
47
49
|
signTransaction(transaction: TransactionPayload, options?: any): Promise<Uint8Array>;
|
48
|
-
signMessage(message:
|
50
|
+
signMessage(message: SignMessagePayload): Promise<{
|
49
51
|
success: boolean;
|
50
|
-
result:
|
51
|
-
hexString: HexEncodedBytes;
|
52
|
-
};
|
52
|
+
result: SignMessageResponse;
|
53
53
|
}>;
|
54
54
|
disconnect(): Promise<void>;
|
55
55
|
}
|
@@ -221,20 +221,19 @@ export class PontemWalletAdapter extends BaseWalletAdapter {
|
|
221
221
|
}
|
222
222
|
return { hash: response.result.hash };
|
223
223
|
} catch (error: any) {
|
224
|
-
this.emit('error', new WalletSignAndSubmitMessageError(error.
|
224
|
+
this.emit('error', new WalletSignAndSubmitMessageError(error.message));
|
225
225
|
throw error;
|
226
226
|
}
|
227
227
|
}
|
228
228
|
|
229
|
-
async signMessage(
|
229
|
+
async signMessage(messagePayload: SignMessagePayload): Promise<SignMessageResponse> {
|
230
230
|
try {
|
231
231
|
const wallet = this._wallet;
|
232
232
|
const provider = this._provider || window.pontem;
|
233
233
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
234
|
-
const response = await provider?.signMessage(
|
235
|
-
console.log('MEMEM>>>', response);
|
234
|
+
const response = await provider?.signMessage(messagePayload);
|
236
235
|
if (response.success) {
|
237
|
-
return response.result
|
236
|
+
return response.result;
|
238
237
|
} else {
|
239
238
|
throw new Error('Sign Message failed');
|
240
239
|
}
|
@@ -10,6 +10,8 @@ import {
|
|
10
10
|
AccountKeys,
|
11
11
|
BaseWalletAdapter,
|
12
12
|
scopePollingDetectionStrategy,
|
13
|
+
SignMessagePayload,
|
14
|
+
SignMessageResponse,
|
13
15
|
WalletName,
|
14
16
|
WalletReadyState
|
15
17
|
} from './BaseAdapter';
|
@@ -28,7 +30,7 @@ interface IRiseWallet {
|
|
28
30
|
isConnected: () => Promise<boolean>;
|
29
31
|
signAndSubmitTransaction(transaction: any): Promise<{ hash: HexEncodedBytes }>;
|
30
32
|
signTransaction(transaction: any, options?: any): Promise<Uint8Array>;
|
31
|
-
signMessage(message:
|
33
|
+
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
32
34
|
disconnect(): Promise<void>;
|
33
35
|
}
|
34
36
|
|
@@ -213,20 +215,21 @@ export class RiseWalletAdapter extends BaseWalletAdapter {
|
|
213
215
|
}
|
214
216
|
}
|
215
217
|
|
216
|
-
async signMessage(
|
218
|
+
async signMessage(msgPayload: SignMessagePayload): Promise<SignMessageResponse> {
|
217
219
|
try {
|
218
220
|
const wallet = this._wallet;
|
219
221
|
const provider = this._provider || window.rise;
|
220
222
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
223
|
+
if (typeof msgPayload !== 'object' || !msgPayload.nonce) {
|
224
|
+
throw new WalletSignMessageError('Invalid signMessage Payload');
|
225
|
+
}
|
226
|
+
const response = await provider?.signMessage(msgPayload);
|
227
|
+
if (response) {
|
228
|
+
return response;
|
225
229
|
} else {
|
226
230
|
throw new Error('Sign Message failed');
|
227
231
|
}
|
228
232
|
} catch (error: any) {
|
229
|
-
console.log('err', error);
|
230
233
|
const errMsg = error.message;
|
231
234
|
this.emit('error', new WalletSignMessageError(errMsg));
|
232
235
|
throw error;
|
@@ -105,6 +105,7 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
105
105
|
useEffect(() => {
|
106
106
|
const selectedWallet = wallets.find((wAdapter) => wAdapter.adapter.name === name);
|
107
107
|
if (selectedWallet) {
|
108
|
+
console.log('selectedWallets', selectedWallet);
|
108
109
|
setState({
|
109
110
|
wallet: selectedWallet,
|
110
111
|
adapter: selectedWallet.adapter,
|
@@ -180,14 +181,20 @@ export const WalletProvider: FC<WalletProviderProps> = ({
|
|
180
181
|
|
181
182
|
// If autoConnect is enabled, try to connect when the adapter changes and is ready
|
182
183
|
useEffect(() => {
|
183
|
-
if (
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
184
|
+
if (isConnecting.current || connected || !autoConnect || !adapter) return;
|
185
|
+
|
186
|
+
// Handle wallet not installed in Auto-connect mode
|
187
|
+
if (!(readyState === WalletReadyState.Installed || readyState === WalletReadyState.Loadable)) {
|
188
|
+
// Clear the selected wallet
|
189
|
+
setName(null);
|
190
|
+
|
191
|
+
if (typeof window !== 'undefined') {
|
192
|
+
window.open(adapter.url, '_blank');
|
193
|
+
}
|
194
|
+
|
195
|
+
handleError(new WalletNotReadyError());
|
190
196
|
return;
|
197
|
+
}
|
191
198
|
|
192
199
|
(async function () {
|
193
200
|
isConnecting.current = true;
|