@manahippo/aptos-wallet-adapter 1.0.5 → 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/RiseWallet.d.ts +11 -3
- package/dist/WalletAdapters/RiseWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/RiseWallet.js +40 -16
- package/dist/WalletAdapters/RiseWallet.js.map +1 -1
- package/dist/WalletAdapters/SpacecyWallet.d.ts +79 -0
- package/dist/WalletAdapters/SpacecyWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/SpacecyWallet.js +258 -0
- package/dist/WalletAdapters/SpacecyWallet.js.map +1 -0
- package/dist/WalletAdapters/index.d.ts +2 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +2 -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/RiseWallet.ts +52 -17
- package/src/WalletAdapters/SpacecyWallet.ts +350 -0
- package/src/WalletAdapters/index.ts +2 -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
|
+
}
|
@@ -28,8 +28,10 @@ interface RiseAccount {
|
|
28
28
|
isConnected: boolean;
|
29
29
|
}
|
30
30
|
|
31
|
+
type AddressInfo = { address: string; publicKey: string; authKey?: string };
|
32
|
+
|
31
33
|
interface IRiseWallet {
|
32
|
-
connect: () => Promise<
|
34
|
+
connect: () => Promise<AddressInfo>;
|
33
35
|
account(): Promise<RiseAccount>;
|
34
36
|
isConnected: () => Promise<boolean>;
|
35
37
|
signAndSubmitTransaction(transaction: any): Promise<{ hash: Types.HexEncodedBytes }>;
|
@@ -37,6 +39,10 @@ interface IRiseWallet {
|
|
37
39
|
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
38
40
|
disconnect(): Promise<void>;
|
39
41
|
network(): Promise<NetworkInfo>;
|
42
|
+
on(event: string, listener: () => any): void;
|
43
|
+
off(event: string, listener: () => any): void;
|
44
|
+
onAccountChange: (listener: (newAddress: AddressInfo) => void) => void;
|
45
|
+
onNetworkChange: (listener: (network: NetworkInfo) => void) => void;
|
40
46
|
}
|
41
47
|
|
42
48
|
interface RiseWindow extends Window {
|
@@ -156,22 +162,20 @@ export class RiseWalletAdapter extends BaseWalletAdapter {
|
|
156
162
|
throw new WalletNotConnectedError('User has rejected the request');
|
157
163
|
}
|
158
164
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
const errMsg = error.message;
|
170
|
-
this.emit('error', new WalletGetNetworkError(errMsg));
|
171
|
-
throw error;
|
172
|
-
}
|
165
|
+
try {
|
166
|
+
const { chainId, api, name } = await provider.network();
|
167
|
+
|
168
|
+
this._network = name;
|
169
|
+
this._chainId = chainId;
|
170
|
+
this._api = api;
|
171
|
+
} catch (error: any) {
|
172
|
+
const errMsg = error.message;
|
173
|
+
this.emit('error', new WalletGetNetworkError(errMsg));
|
174
|
+
throw error;
|
173
175
|
}
|
174
176
|
|
177
|
+
provider?.on('disconnect', this.handleDisconnect);
|
178
|
+
|
175
179
|
const account = await provider?.account();
|
176
180
|
if (account) {
|
177
181
|
const { publicKey, address, authKey } = account;
|
@@ -200,6 +204,7 @@ export class RiseWalletAdapter extends BaseWalletAdapter {
|
|
200
204
|
|
201
205
|
try {
|
202
206
|
const provider = this._provider || window.rise;
|
207
|
+
provider?.off('disconnect', this.handleDisconnect);
|
203
208
|
await provider?.disconnect();
|
204
209
|
} catch (error: any) {
|
205
210
|
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
@@ -275,7 +280,18 @@ export class RiseWalletAdapter extends BaseWalletAdapter {
|
|
275
280
|
const wallet = this._wallet;
|
276
281
|
const provider = this._provider || window.rise;
|
277
282
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
278
|
-
|
283
|
+
const handleAccountChange = async (newAccount?: AddressInfo) => {
|
284
|
+
if (newAccount?.publicKey) {
|
285
|
+
this._wallet = {
|
286
|
+
...this._wallet,
|
287
|
+
publicKey: newAccount.publicKey || this._wallet?.publicKey,
|
288
|
+
authKey: newAccount.authKey || this._wallet?.authKey,
|
289
|
+
address: newAccount.address || this._wallet?.address
|
290
|
+
};
|
291
|
+
this.emit('accountChange', newAccount?.publicKey);
|
292
|
+
}
|
293
|
+
};
|
294
|
+
await provider?.onAccountChange?.(handleAccountChange);
|
279
295
|
} catch (error: any) {
|
280
296
|
const errMsg = error.message;
|
281
297
|
this.emit('error', new WalletAccountChangeError(errMsg));
|
@@ -288,11 +304,30 @@ export class RiseWalletAdapter extends BaseWalletAdapter {
|
|
288
304
|
const wallet = this._wallet;
|
289
305
|
const provider = this._provider || window.rise;
|
290
306
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
291
|
-
|
307
|
+
const handleNetworkChange = async (newNetwork: NetworkInfo) => {
|
308
|
+
const { chainId, api, name } = newNetwork;
|
309
|
+
this._network = name;
|
310
|
+
this._chainId = chainId;
|
311
|
+
this._api = api;
|
312
|
+
this.emit('networkChange', this._network);
|
313
|
+
};
|
314
|
+
await provider?.onNetworkChange?.(handleNetworkChange);
|
292
315
|
} catch (error: any) {
|
293
316
|
const errMsg = error.message;
|
294
317
|
this.emit('error', new WalletNetworkChangeError(errMsg));
|
295
318
|
throw error;
|
296
319
|
}
|
297
320
|
}
|
321
|
+
|
322
|
+
private handleDisconnect = () => {
|
323
|
+
try {
|
324
|
+
const provider = this._provider || window.rise;
|
325
|
+
|
326
|
+
provider?.off('disconnect', this.handleDisconnect);
|
327
|
+
|
328
|
+
this._wallet = null;
|
329
|
+
} finally {
|
330
|
+
this.emit('disconnect');
|
331
|
+
}
|
332
|
+
};
|
298
333
|
}
|