@manahippo/aptos-wallet-adapter 1.0.6 → 1.0.7
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 +4 -2
- package/dist/WalletAdapters/HyperPayWallet.d.ts +7 -5
- package/dist/WalletAdapters/HyperPayWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HyperPayWallet.js +20 -4
- package/dist/WalletAdapters/HyperPayWallet.js.map +1 -1
- package/dist/WalletAdapters/MsafeWallet.d.ts +37 -0
- package/dist/WalletAdapters/MsafeWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MsafeWallet.js +229 -226
- package/dist/WalletAdapters/MsafeWallet.js.map +1 -1
- package/dist/WalletAdapters/index.d.ts +1 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +1 -1
- package/dist/WalletAdapters/index.js.map +1 -1
- package/package.json +3 -2
- package/src/WalletAdapters/HyperPayWallet.ts +27 -5
- package/src/WalletAdapters/MsafeWallet.ts +262 -261
- package/src/WalletAdapters/index.ts +1 -1
@@ -1,261 +1,262 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
//
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
1
|
+
import { HexString, MaybeHexString, Types } from 'aptos';
|
2
|
+
import {
|
3
|
+
WalletAccountChangeError,
|
4
|
+
WalletDisconnectionError,
|
5
|
+
WalletGetNetworkError,
|
6
|
+
WalletNetworkChangeError,
|
7
|
+
WalletNotConnectedError,
|
8
|
+
WalletNotReadyError,
|
9
|
+
WalletSignAndSubmitMessageError,
|
10
|
+
WalletSignMessageError,
|
11
|
+
WalletSignTransactionError
|
12
|
+
} from '../WalletProviders/errors';
|
13
|
+
import {
|
14
|
+
AccountKeys,
|
15
|
+
BaseWalletAdapter,
|
16
|
+
NetworkInfo,
|
17
|
+
SignMessagePayload,
|
18
|
+
SignMessageResponse,
|
19
|
+
WalletAdapterNetwork,
|
20
|
+
WalletName,
|
21
|
+
WalletReadyState
|
22
|
+
} from './BaseAdapter';
|
23
|
+
import { Account, MsafeWallet } from 'msafe-wallet';
|
24
|
+
|
25
|
+
export const MsafeWalletName = 'Msafe' as WalletName<'Msafe'>;
|
26
|
+
|
27
|
+
interface MsafeAccount {
|
28
|
+
address: MaybeHexString;
|
29
|
+
publicKey: MaybeHexString;
|
30
|
+
authKey: MaybeHexString;
|
31
|
+
isConnected: boolean;
|
32
|
+
}
|
33
|
+
|
34
|
+
export class MsafeWalletAdapter extends BaseWalletAdapter {
|
35
|
+
name = MsafeWalletName;
|
36
|
+
|
37
|
+
url = MsafeWallet.getOrigin();
|
38
|
+
|
39
|
+
icon = 'https://raw.githubusercontent.com/hippospace/aptos-wallet-adapter/main/logos/msafe.png';
|
40
|
+
|
41
|
+
protected _provider: MsafeWallet | undefined;
|
42
|
+
|
43
|
+
protected _network: WalletAdapterNetwork;
|
44
|
+
|
45
|
+
protected _chainId: string;
|
46
|
+
|
47
|
+
// MsafeWallet only works in msafe appstore iframe
|
48
|
+
protected _readyState: WalletReadyState = MsafeWallet.inMsafeWallet()
|
49
|
+
? WalletReadyState.NotDetected
|
50
|
+
: WalletReadyState.Unsupported;
|
51
|
+
|
52
|
+
protected _connecting: boolean;
|
53
|
+
|
54
|
+
protected _wallet: MsafeAccount | null;
|
55
|
+
|
56
|
+
constructor(origin: 'Mainnet' | 'Testnet' | string = 'Mainnet') {
|
57
|
+
super();
|
58
|
+
this._network = undefined;
|
59
|
+
this._connecting = false;
|
60
|
+
const msafeOrigin = MsafeWallet.getOrigin(origin);
|
61
|
+
this.url = MsafeWallet.getAppUrl(origin);
|
62
|
+
if (this._readyState === WalletReadyState.NotDetected) {
|
63
|
+
MsafeWallet.new(msafeOrigin)
|
64
|
+
.then((msafe) => {
|
65
|
+
this._provider = msafe;
|
66
|
+
this._readyState = WalletReadyState.Installed;
|
67
|
+
this.emit('readyStateChange', this._readyState);
|
68
|
+
})
|
69
|
+
.catch((e) => console.log(e));
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
get publicAccount(): AccountKeys {
|
74
|
+
return {
|
75
|
+
publicKey: this._wallet?.publicKey || null,
|
76
|
+
address: this._wallet?.address || null,
|
77
|
+
authKey: this._wallet?.authKey || null
|
78
|
+
};
|
79
|
+
}
|
80
|
+
|
81
|
+
get network(): NetworkInfo {
|
82
|
+
return {
|
83
|
+
name: this._network,
|
84
|
+
chainId: this._chainId
|
85
|
+
};
|
86
|
+
}
|
87
|
+
|
88
|
+
get connecting(): boolean {
|
89
|
+
return this._connecting;
|
90
|
+
}
|
91
|
+
|
92
|
+
get connected(): boolean {
|
93
|
+
return !!this._wallet?.isConnected;
|
94
|
+
}
|
95
|
+
|
96
|
+
get readyState(): WalletReadyState {
|
97
|
+
return this._readyState;
|
98
|
+
}
|
99
|
+
|
100
|
+
async connect(): Promise<void> {
|
101
|
+
try {
|
102
|
+
if (this.connected || this.connecting) return;
|
103
|
+
if (
|
104
|
+
!(
|
105
|
+
this._readyState === WalletReadyState.Loadable ||
|
106
|
+
this._readyState === WalletReadyState.Installed
|
107
|
+
)
|
108
|
+
)
|
109
|
+
throw new WalletNotReadyError();
|
110
|
+
this._connecting = true;
|
111
|
+
|
112
|
+
const provider = this._provider;
|
113
|
+
const isConnected = await provider?.isConnected();
|
114
|
+
if (isConnected) {
|
115
|
+
await provider?.disconnect();
|
116
|
+
}
|
117
|
+
const response = await provider?.connect();
|
118
|
+
|
119
|
+
if (!response) {
|
120
|
+
throw new WalletNotConnectedError('No connect response');
|
121
|
+
}
|
122
|
+
|
123
|
+
const walletAccount = await provider?.account();
|
124
|
+
if (walletAccount) {
|
125
|
+
this._wallet = {
|
126
|
+
...walletAccount,
|
127
|
+
isConnected: true
|
128
|
+
} as any;
|
129
|
+
|
130
|
+
try {
|
131
|
+
const name = await provider?.network();
|
132
|
+
const chainId = await provider?.chainId();
|
133
|
+
|
134
|
+
this._network = name as WalletAdapterNetwork;
|
135
|
+
this._chainId = chainId.toString();
|
136
|
+
} catch (error: any) {
|
137
|
+
const errMsg = error.message;
|
138
|
+
this.emit('error', new WalletGetNetworkError(errMsg));
|
139
|
+
throw error;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
this.emit('connect', this._wallet?.address || '');
|
143
|
+
} catch (error: any) {
|
144
|
+
this.emit('error', new Error(error));
|
145
|
+
throw error;
|
146
|
+
} finally {
|
147
|
+
this._connecting = false;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
async disconnect(): Promise<void> {
|
152
|
+
const wallet = this._wallet;
|
153
|
+
const provider = this._provider;
|
154
|
+
if (wallet) {
|
155
|
+
this._wallet = null;
|
156
|
+
|
157
|
+
try {
|
158
|
+
await provider?.disconnect();
|
159
|
+
} catch (error: any) {
|
160
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
this.emit('disconnect');
|
165
|
+
}
|
166
|
+
|
167
|
+
async signTransaction(
|
168
|
+
transactionPyld: Types.TransactionPayload,
|
169
|
+
options?: any
|
170
|
+
): Promise<Uint8Array> {
|
171
|
+
try {
|
172
|
+
const wallet = this._wallet;
|
173
|
+
const provider = this._provider;
|
174
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
175
|
+
const response = await provider.signTransaction(transactionPyld as any, options);
|
176
|
+
|
177
|
+
if (!response) {
|
178
|
+
throw new Error('No response');
|
179
|
+
}
|
180
|
+
return response;
|
181
|
+
} catch (error: any) {
|
182
|
+
this.emit('error', new WalletSignTransactionError(error));
|
183
|
+
throw error;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
async signAndSubmitTransaction(
|
188
|
+
transactionPyld: Types.TransactionPayload,
|
189
|
+
options?: any
|
190
|
+
): Promise<{ hash: Types.HexEncodedBytes }> {
|
191
|
+
try {
|
192
|
+
const wallet = this._wallet;
|
193
|
+
const provider = this._provider;
|
194
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
195
|
+
const response = await provider.signAndSubmit(transactionPyld as any, options);
|
196
|
+
|
197
|
+
if (!response) {
|
198
|
+
throw new Error('No response');
|
199
|
+
}
|
200
|
+
return { hash: HexString.fromUint8Array(response).hex() };
|
201
|
+
} catch (error: any) {
|
202
|
+
this.emit('error', new WalletSignAndSubmitMessageError(error));
|
203
|
+
throw error;
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
async signMessage(msgPayload: SignMessagePayload): Promise<SignMessageResponse> {
|
208
|
+
try {
|
209
|
+
const wallet = this._wallet;
|
210
|
+
const provider = this._provider;
|
211
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
212
|
+
const response = await provider.signMessage(msgPayload as any);
|
213
|
+
if (response) {
|
214
|
+
return response as any;
|
215
|
+
} else {
|
216
|
+
throw new Error('Sign Message failed');
|
217
|
+
}
|
218
|
+
} catch (error: any) {
|
219
|
+
const errMsg = error.message;
|
220
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
221
|
+
throw error;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
async onAccountChange(): Promise<void> {
|
226
|
+
try {
|
227
|
+
const wallet = this._wallet;
|
228
|
+
const provider = this._provider;
|
229
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
230
|
+
const handleChangeAccount = async (newAccount: Account) => {
|
231
|
+
this._wallet = {
|
232
|
+
...this._wallet,
|
233
|
+
...newAccount
|
234
|
+
};
|
235
|
+
this.emit('accountChange', newAccount.address);
|
236
|
+
};
|
237
|
+
provider.onChangeAccount(handleChangeAccount);
|
238
|
+
} catch (error: any) {
|
239
|
+
const errMsg = error.message;
|
240
|
+
this.emit('error', new WalletAccountChangeError(errMsg));
|
241
|
+
throw error;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
|
245
|
+
async onNetworkChange(): Promise<void> {
|
246
|
+
try {
|
247
|
+
const wallet = this._wallet;
|
248
|
+
const provider = this._provider;
|
249
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
250
|
+
const handleNetworkChange = async (newNetwork: WalletAdapterNetwork) => {
|
251
|
+
this._network = newNetwork;
|
252
|
+
this._chainId = (await this._provider.chainId()).toString();
|
253
|
+
this.emit('networkChange', this._network);
|
254
|
+
};
|
255
|
+
provider.onChangeNetwork(handleNetworkChange);
|
256
|
+
} catch (error: any) {
|
257
|
+
const errMsg = error.message;
|
258
|
+
this.emit('error', new WalletNetworkChangeError(errMsg));
|
259
|
+
throw error;
|
260
|
+
}
|
261
|
+
}
|
262
|
+
}
|
@@ -18,7 +18,7 @@ export * from './BloctoWallet';
|
|
18
18
|
export * from './Coin98Wallet';
|
19
19
|
export * from './SafePalWallet';
|
20
20
|
export * from './FoxWallet';
|
21
|
-
|
21
|
+
export * from './MsafeWallet';
|
22
22
|
export * from './OpenBlockWallet';
|
23
23
|
export * from './CloverWallet';
|
24
24
|
export * from './SpacecyWallet';
|