@manahippo/aptos-wallet-adapter 1.0.2 → 1.0.3
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 +6 -6
- package/dist/WalletAdapters/BloctoWallet.d.ts +3 -3
- package/dist/WalletAdapters/BloctoWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/BloctoWallet.js +1 -3
- package/dist/WalletAdapters/BloctoWallet.js.map +1 -1
- package/dist/WalletAdapters/FoxWallet.d.ts +64 -0
- package/dist/WalletAdapters/FoxWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/FoxWallet.js +239 -0
- package/dist/WalletAdapters/FoxWallet.js.map +1 -0
- package/dist/WalletAdapters/HyperPayWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HyperPayWallet.js +2 -2
- package/dist/WalletAdapters/HyperPayWallet.js.map +1 -1
- package/dist/WalletAdapters/MsafeWallet.d.ts +39 -0
- package/dist/WalletAdapters/MsafeWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/MsafeWallet.js +225 -0
- package/dist/WalletAdapters/MsafeWallet.js.map +1 -0
- package/dist/WalletAdapters/NightlyWallet.js +2 -2
- package/dist/WalletAdapters/NightlyWallet.js.map +1 -1
- package/dist/WalletAdapters/SpikaWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/SpikaWallet.js +1 -1
- package/dist/WalletAdapters/SpikaWallet.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 +35 -6
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/dist/utilities/util.d.ts +4 -0
- package/dist/utilities/util.d.ts.map +1 -1
- package/dist/utilities/util.js +23 -1
- package/dist/utilities/util.js.map +1 -1
- package/package.json +4 -3
- package/src/WalletAdapters/BloctoWallet.ts +7 -7
- package/src/WalletAdapters/FoxWallet.ts +312 -0
- package/src/WalletAdapters/HyperPayWallet.ts +2 -2
- package/src/WalletAdapters/MsafeWallet.ts +261 -0
- package/src/WalletAdapters/NightlyWallet.ts +2 -2
- package/src/WalletAdapters/SpikaWallet.ts +1 -1
- package/src/WalletAdapters/index.ts +2 -0
- package/src/WalletProviders/WalletProvider.tsx +37 -7
- package/src/utilities/util.ts +13 -0
@@ -0,0 +1,312 @@
|
|
1
|
+
import { 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
|
+
scopePollingDetectionStrategy,
|
18
|
+
SignMessagePayload,
|
19
|
+
SignMessageResponse,
|
20
|
+
WalletAdapterNetwork,
|
21
|
+
WalletName,
|
22
|
+
WalletReadyState
|
23
|
+
} from './BaseAdapter';
|
24
|
+
|
25
|
+
interface IApotsErrorResult {
|
26
|
+
code: number;
|
27
|
+
name: string;
|
28
|
+
message: string;
|
29
|
+
}
|
30
|
+
|
31
|
+
type AddressInfo = { address: string; publicKey: string; authKey?: string };
|
32
|
+
|
33
|
+
interface IFoxWallet {
|
34
|
+
connect: () => Promise<AddressInfo>;
|
35
|
+
account: () => Promise<AddressInfo>;
|
36
|
+
isConnected: () => Promise<boolean>;
|
37
|
+
signAndSubmitTransaction(
|
38
|
+
transaction: any,
|
39
|
+
options?: any
|
40
|
+
): Promise<{ hash: Types.HexEncodedBytes } | IApotsErrorResult>;
|
41
|
+
signTransaction(transaction: any, options?: any): Promise<Uint8Array | IApotsErrorResult>;
|
42
|
+
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
43
|
+
disconnect(): Promise<void>;
|
44
|
+
network(): Promise<WalletAdapterNetwork>;
|
45
|
+
requestId: Promise<number>;
|
46
|
+
onAccountChange: (listener: (newAddress: AddressInfo) => void) => void;
|
47
|
+
onNetworkChange: (listener: (network: { networkName: string }) => void) => void;
|
48
|
+
}
|
49
|
+
|
50
|
+
interface AptosWindow extends Window {
|
51
|
+
foxwallet?: IFoxWallet;
|
52
|
+
aptos?: IFoxWallet;
|
53
|
+
}
|
54
|
+
|
55
|
+
declare const window: AptosWindow;
|
56
|
+
|
57
|
+
export const FoxWalletName = 'FoxWallet' as WalletName<'FoxWallet'>;
|
58
|
+
|
59
|
+
export interface FoxWalletAdapterConfig {
|
60
|
+
provider?: IFoxWallet;
|
61
|
+
// network?: WalletAdapterNetwork;
|
62
|
+
timeout?: number;
|
63
|
+
}
|
64
|
+
|
65
|
+
export class FoxWalletAdapter extends BaseWalletAdapter {
|
66
|
+
name = FoxWalletName;
|
67
|
+
|
68
|
+
url = 'https://foxwallet.com';
|
69
|
+
|
70
|
+
icon =
|
71
|
+
'https://hc.foxwallet.com/assets/files/FoxWallet-logo-v4-9d2b5eec06bdd619c8678a8052dfc8da.svg';
|
72
|
+
|
73
|
+
protected _provider: IFoxWallet | undefined;
|
74
|
+
|
75
|
+
protected _network: WalletAdapterNetwork;
|
76
|
+
|
77
|
+
protected _chainId: string;
|
78
|
+
|
79
|
+
protected _api: string;
|
80
|
+
|
81
|
+
protected _timeout: number;
|
82
|
+
|
83
|
+
protected _readyState: WalletReadyState =
|
84
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
85
|
+
? WalletReadyState.Unsupported
|
86
|
+
: WalletReadyState.NotDetected;
|
87
|
+
|
88
|
+
protected _connecting: boolean;
|
89
|
+
|
90
|
+
protected _wallet: any | null;
|
91
|
+
|
92
|
+
constructor({
|
93
|
+
// provider,
|
94
|
+
// network = WalletAdapterNetwork.Testnet,
|
95
|
+
timeout = 10000
|
96
|
+
}: FoxWalletAdapterConfig = {}) {
|
97
|
+
super();
|
98
|
+
|
99
|
+
this._provider = typeof window !== 'undefined' ? window.aptos : undefined;
|
100
|
+
this._network = undefined;
|
101
|
+
this._timeout = timeout;
|
102
|
+
this._connecting = false;
|
103
|
+
this._wallet = null;
|
104
|
+
|
105
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
106
|
+
scopePollingDetectionStrategy(() => {
|
107
|
+
if (window.foxwallet && window.aptos) {
|
108
|
+
this._readyState = WalletReadyState.Installed;
|
109
|
+
this.emit('readyStateChange', this._readyState);
|
110
|
+
return true;
|
111
|
+
}
|
112
|
+
return false;
|
113
|
+
});
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
get publicAccount(): AccountKeys {
|
118
|
+
return {
|
119
|
+
publicKey: this._wallet?.publicKey || null,
|
120
|
+
address: this._wallet?.address || null,
|
121
|
+
authKey: this._wallet?.authKey || null
|
122
|
+
};
|
123
|
+
}
|
124
|
+
|
125
|
+
get network(): NetworkInfo {
|
126
|
+
return {
|
127
|
+
name: this._network,
|
128
|
+
api: this._api,
|
129
|
+
chainId: this._chainId
|
130
|
+
};
|
131
|
+
}
|
132
|
+
|
133
|
+
get connecting(): boolean {
|
134
|
+
return this._connecting;
|
135
|
+
}
|
136
|
+
|
137
|
+
get connected(): boolean {
|
138
|
+
return !!this._wallet?.isConnected;
|
139
|
+
}
|
140
|
+
|
141
|
+
get readyState(): WalletReadyState {
|
142
|
+
return this._readyState;
|
143
|
+
}
|
144
|
+
|
145
|
+
async connect(): Promise<void> {
|
146
|
+
try {
|
147
|
+
if (this.connected || this.connecting) return;
|
148
|
+
if (
|
149
|
+
!(
|
150
|
+
this._readyState === WalletReadyState.Loadable ||
|
151
|
+
this._readyState === WalletReadyState.Installed
|
152
|
+
)
|
153
|
+
)
|
154
|
+
throw new WalletNotReadyError();
|
155
|
+
this._connecting = true;
|
156
|
+
|
157
|
+
const provider = this._provider || window.aptos;
|
158
|
+
const response = await provider?.connect();
|
159
|
+
this._wallet = {
|
160
|
+
address: response?.address,
|
161
|
+
publicKey: response?.publicKey,
|
162
|
+
isConnected: true
|
163
|
+
};
|
164
|
+
|
165
|
+
try {
|
166
|
+
const name = await provider?.network();
|
167
|
+
const chainId = null;
|
168
|
+
const api = null;
|
169
|
+
|
170
|
+
this._network = name;
|
171
|
+
this._chainId = chainId;
|
172
|
+
this._api = api;
|
173
|
+
} catch (error: any) {
|
174
|
+
const errMsg = error.message;
|
175
|
+
this.emit('error', new WalletGetNetworkError(errMsg));
|
176
|
+
throw error;
|
177
|
+
}
|
178
|
+
|
179
|
+
this.emit('connect', this._wallet.publicKey);
|
180
|
+
} catch (error: any) {
|
181
|
+
this.emit('error', error);
|
182
|
+
throw error;
|
183
|
+
} finally {
|
184
|
+
this._connecting = false;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
async disconnect(): Promise<void> {
|
189
|
+
const wallet = this._wallet;
|
190
|
+
const provider = this._provider || window.aptos;
|
191
|
+
if (wallet) {
|
192
|
+
this._wallet = null;
|
193
|
+
|
194
|
+
try {
|
195
|
+
await provider?.disconnect();
|
196
|
+
} catch (error: any) {
|
197
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
this.emit('disconnect');
|
202
|
+
}
|
203
|
+
|
204
|
+
async signTransaction(transaction: Types.TransactionPayload, options?: any): Promise<Uint8Array> {
|
205
|
+
try {
|
206
|
+
const wallet = this._wallet;
|
207
|
+
const provider = this._provider || window.aptos;
|
208
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
209
|
+
|
210
|
+
const response = await provider.signTransaction(transaction, options);
|
211
|
+
if ((response as IApotsErrorResult).code) {
|
212
|
+
throw new Error((response as IApotsErrorResult).message);
|
213
|
+
}
|
214
|
+
return response as Uint8Array;
|
215
|
+
} catch (error: any) {
|
216
|
+
const errMsg = error.message;
|
217
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
218
|
+
throw error;
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
async signAndSubmitTransaction(
|
223
|
+
transaction: Types.TransactionPayload,
|
224
|
+
options?: any
|
225
|
+
): Promise<{ hash: Types.HexEncodedBytes }> {
|
226
|
+
try {
|
227
|
+
const wallet = this._wallet;
|
228
|
+
const provider = this._provider || window.aptos;
|
229
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
230
|
+
|
231
|
+
const response = await provider.signAndSubmitTransaction(transaction, options);
|
232
|
+
if ((response as IApotsErrorResult).code) {
|
233
|
+
throw new Error((response as IApotsErrorResult).message);
|
234
|
+
}
|
235
|
+
return response as { hash: Types.HexEncodedBytes };
|
236
|
+
} catch (error: any) {
|
237
|
+
const errMsg = error.message;
|
238
|
+
this.emit('error', new WalletSignAndSubmitMessageError(errMsg));
|
239
|
+
throw error;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
async signMessage(msgPayload: SignMessagePayload): Promise<SignMessageResponse> {
|
244
|
+
try {
|
245
|
+
const wallet = this._wallet;
|
246
|
+
const provider = this._provider || window.aptos;
|
247
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
248
|
+
if (typeof msgPayload !== 'object' || !msgPayload.nonce) {
|
249
|
+
throw new WalletSignMessageError('Invalid signMessage Payload');
|
250
|
+
}
|
251
|
+
const response = await provider?.signMessage(msgPayload);
|
252
|
+
if (response) {
|
253
|
+
return response;
|
254
|
+
} else {
|
255
|
+
throw new Error('Sign Message failed');
|
256
|
+
}
|
257
|
+
} catch (error: any) {
|
258
|
+
const errMsg = error.message;
|
259
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
260
|
+
throw error;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
async onAccountChange(): Promise<void> {
|
265
|
+
try {
|
266
|
+
const wallet = this._wallet;
|
267
|
+
const provider = this._provider || window.aptos;
|
268
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
269
|
+
const handleAccountChange = async (newAccount: AddressInfo) => {
|
270
|
+
if (newAccount?.publicKey) {
|
271
|
+
this._wallet = {
|
272
|
+
...this._wallet,
|
273
|
+
publicKey: newAccount.publicKey || this._wallet?.publicKey,
|
274
|
+
authKey: newAccount.authKey || this._wallet?.authKey,
|
275
|
+
address: newAccount.address || this._wallet?.address
|
276
|
+
};
|
277
|
+
} else {
|
278
|
+
const response = await provider?.connect();
|
279
|
+
this._wallet = {
|
280
|
+
...this._wallet,
|
281
|
+
authKey: response?.authKey || this._wallet?.authKey,
|
282
|
+
address: response?.address || this._wallet?.address,
|
283
|
+
publicKey: response?.publicKey || this._wallet?.publicKey
|
284
|
+
};
|
285
|
+
}
|
286
|
+
this.emit('accountChange', newAccount.publicKey);
|
287
|
+
};
|
288
|
+
await provider?.onAccountChange(handleAccountChange);
|
289
|
+
} catch (error: any) {
|
290
|
+
const errMsg = error.message;
|
291
|
+
this.emit('error', new WalletAccountChangeError(errMsg));
|
292
|
+
throw error;
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
async onNetworkChange(): Promise<void> {
|
297
|
+
try {
|
298
|
+
const wallet = this._wallet;
|
299
|
+
const provider = this._provider || window.aptos;
|
300
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
301
|
+
const handleNetworkChange = async (newNetwork: { networkName: WalletAdapterNetwork }) => {
|
302
|
+
this._network = newNetwork.networkName;
|
303
|
+
this.emit('networkChange', this._network);
|
304
|
+
};
|
305
|
+
await provider?.onNetworkChange(handleNetworkChange);
|
306
|
+
} catch (error: any) {
|
307
|
+
const errMsg = error.message;
|
308
|
+
this.emit('error', new WalletNetworkChangeError(errMsg));
|
309
|
+
throw error;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
}
|
@@ -60,10 +60,10 @@ export interface HyperPayWalletAdapterConfig {
|
|
60
60
|
export class HyperPayWalletAdapter extends BaseWalletAdapter {
|
61
61
|
name = HyperPayWalletName;
|
62
62
|
|
63
|
-
url = 'https://www.hyperpay.
|
63
|
+
url = 'https://www.hyperpay.io/';
|
64
64
|
|
65
65
|
icon =
|
66
|
-
'
|
66
|
+
'https://hyperpay.oss-ap-southeast-1.aliyuncs.com/heperpay/1666601839.png';
|
67
67
|
|
68
68
|
protected _provider: IHyperPayWallet | undefined;
|
69
69
|
|
@@ -0,0 +1,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-iframe';
|
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 = 'https://app.m-safe.io';
|
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
|
+
protected _api: string;
|
48
|
+
|
49
|
+
protected _readyState: WalletReadyState =
|
50
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
51
|
+
? WalletReadyState.Unsupported
|
52
|
+
: WalletReadyState.NotDetected;
|
53
|
+
|
54
|
+
protected _connecting: boolean;
|
55
|
+
|
56
|
+
protected _wallet: MsafeAccount | null;
|
57
|
+
|
58
|
+
constructor(origin?: string) {
|
59
|
+
super();
|
60
|
+
|
61
|
+
this._network = undefined;
|
62
|
+
this._connecting = false;
|
63
|
+
MsafeWallet.new(origin)
|
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
|
+
get publicAccount(): AccountKeys {
|
73
|
+
return {
|
74
|
+
publicKey: this._wallet?.publicKey || null,
|
75
|
+
address: this._wallet?.address || null,
|
76
|
+
authKey: this._wallet?.authKey || null
|
77
|
+
};
|
78
|
+
}
|
79
|
+
|
80
|
+
get network(): NetworkInfo {
|
81
|
+
return {
|
82
|
+
name: this._network,
|
83
|
+
chainId: this._chainId
|
84
|
+
};
|
85
|
+
}
|
86
|
+
|
87
|
+
get connecting(): boolean {
|
88
|
+
return this._connecting;
|
89
|
+
}
|
90
|
+
|
91
|
+
get connected(): boolean {
|
92
|
+
return !!this._wallet?.isConnected;
|
93
|
+
}
|
94
|
+
|
95
|
+
get readyState(): WalletReadyState {
|
96
|
+
return this._readyState;
|
97
|
+
}
|
98
|
+
|
99
|
+
async connect(): Promise<void> {
|
100
|
+
try {
|
101
|
+
if (this.connected || this.connecting) return;
|
102
|
+
if (
|
103
|
+
!(
|
104
|
+
this._readyState === WalletReadyState.Loadable ||
|
105
|
+
this._readyState === WalletReadyState.Installed
|
106
|
+
)
|
107
|
+
)
|
108
|
+
throw new WalletNotReadyError();
|
109
|
+
this._connecting = true;
|
110
|
+
|
111
|
+
const provider = this._provider;
|
112
|
+
const isConnected = await provider?.isConnected();
|
113
|
+
if (isConnected) {
|
114
|
+
await provider?.disconnect();
|
115
|
+
}
|
116
|
+
const response = await provider?.connect();
|
117
|
+
|
118
|
+
if (!response) {
|
119
|
+
throw new WalletNotConnectedError('No connect response');
|
120
|
+
}
|
121
|
+
|
122
|
+
const walletAccount = await provider?.account();
|
123
|
+
if (walletAccount) {
|
124
|
+
this._wallet = {
|
125
|
+
...walletAccount,
|
126
|
+
isConnected: true
|
127
|
+
} as any;
|
128
|
+
|
129
|
+
try {
|
130
|
+
const name = await provider?.network();
|
131
|
+
const chainId = await provider?.chainId();
|
132
|
+
|
133
|
+
this._network = name as WalletAdapterNetwork;
|
134
|
+
this._chainId = chainId.toString();
|
135
|
+
} catch (error: any) {
|
136
|
+
const errMsg = error.message;
|
137
|
+
this.emit('error', new WalletGetNetworkError(errMsg));
|
138
|
+
throw error;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
this.emit('connect', this._wallet?.address || '');
|
142
|
+
} catch (error: any) {
|
143
|
+
this.emit('error', new Error(error));
|
144
|
+
throw error;
|
145
|
+
} finally {
|
146
|
+
this._connecting = false;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
async disconnect(): Promise<void> {
|
151
|
+
const wallet = this._wallet;
|
152
|
+
const provider = this._provider;
|
153
|
+
if (wallet) {
|
154
|
+
this._wallet = null;
|
155
|
+
|
156
|
+
try {
|
157
|
+
await provider?.disconnect();
|
158
|
+
} catch (error: any) {
|
159
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
this.emit('disconnect');
|
164
|
+
}
|
165
|
+
|
166
|
+
async signTransaction(
|
167
|
+
transactionPyld: Types.TransactionPayload,
|
168
|
+
options?: any
|
169
|
+
): Promise<Uint8Array> {
|
170
|
+
try {
|
171
|
+
const wallet = this._wallet;
|
172
|
+
const provider = this._provider;
|
173
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
174
|
+
const response = await provider.signTransaction(transactionPyld as any, options);
|
175
|
+
|
176
|
+
if (!response) {
|
177
|
+
throw new Error('No response');
|
178
|
+
}
|
179
|
+
return response;
|
180
|
+
} catch (error: any) {
|
181
|
+
this.emit('error', new WalletSignTransactionError(error));
|
182
|
+
throw error;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
async signAndSubmitTransaction(
|
187
|
+
transactionPyld: Types.TransactionPayload,
|
188
|
+
options?: any
|
189
|
+
): Promise<{ hash: Types.HexEncodedBytes }> {
|
190
|
+
try {
|
191
|
+
const wallet = this._wallet;
|
192
|
+
const provider = this._provider;
|
193
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
194
|
+
const response = await provider.signAndSubmit(transactionPyld as any, options);
|
195
|
+
|
196
|
+
if (!response) {
|
197
|
+
throw new Error('No response');
|
198
|
+
}
|
199
|
+
return { hash: HexString.fromUint8Array(response).hex() };
|
200
|
+
} catch (error: any) {
|
201
|
+
this.emit('error', new WalletSignAndSubmitMessageError(error));
|
202
|
+
throw error;
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
async signMessage(msgPayload: SignMessagePayload): Promise<SignMessageResponse> {
|
207
|
+
try {
|
208
|
+
const wallet = this._wallet;
|
209
|
+
const provider = this._provider;
|
210
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
211
|
+
const response = await provider.signMessage(msgPayload as any);
|
212
|
+
if (response) {
|
213
|
+
return response as any;
|
214
|
+
} else {
|
215
|
+
throw new Error('Sign Message failed');
|
216
|
+
}
|
217
|
+
} catch (error: any) {
|
218
|
+
const errMsg = error.message;
|
219
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
220
|
+
throw error;
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
async onAccountChange(): Promise<void> {
|
225
|
+
try {
|
226
|
+
const wallet = this._wallet;
|
227
|
+
const provider = this._provider;
|
228
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
229
|
+
const handleChangeAccount = async (newAccount: Account) => {
|
230
|
+
this._wallet = {
|
231
|
+
...this._wallet,
|
232
|
+
...newAccount
|
233
|
+
};
|
234
|
+
this.emit('accountChange', newAccount.address);
|
235
|
+
};
|
236
|
+
provider.onChangeAccount(handleChangeAccount);
|
237
|
+
} catch (error: any) {
|
238
|
+
const errMsg = error.message;
|
239
|
+
this.emit('error', new WalletAccountChangeError(errMsg));
|
240
|
+
throw error;
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
async onNetworkChange(): Promise<void> {
|
245
|
+
try {
|
246
|
+
const wallet = this._wallet;
|
247
|
+
const provider = this._provider;
|
248
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
249
|
+
const handleNetworkChange = async (newNetwork: WalletAdapterNetwork) => {
|
250
|
+
this._network = newNetwork;
|
251
|
+
this._chainId = (await this._provider.chainId()).toString();
|
252
|
+
this.emit('networkChange', this._network);
|
253
|
+
};
|
254
|
+
provider.onChangeNetwork(handleNetworkChange);
|
255
|
+
} catch (error: any) {
|
256
|
+
const errMsg = error.message;
|
257
|
+
this.emit('error', new WalletNetworkChangeError(errMsg));
|
258
|
+
throw error;
|
259
|
+
}
|
260
|
+
}
|
261
|
+
}
|
@@ -124,13 +124,13 @@ export class NightlyWalletAdapter extends BaseWalletAdapter {
|
|
124
124
|
}: NightlyWalletAdapterConfig = {}) {
|
125
125
|
super();
|
126
126
|
|
127
|
-
this._provider = window.nightly?.aptos;
|
127
|
+
this._provider = typeof window !== 'undefined' ? window.nightly?.aptos : undefined;
|
128
128
|
this._network = undefined;
|
129
129
|
this._timeout = timeout;
|
130
130
|
this._connecting = false;
|
131
131
|
this._wallet = null;
|
132
132
|
|
133
|
-
if (this._readyState !== WalletReadyState.Unsupported) {
|
133
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
134
134
|
scopePollingDetectionStrategy(() => {
|
135
135
|
if (window.nightly?.aptos) {
|
136
136
|
this._readyState = WalletReadyState.Installed;
|
@@ -51,7 +51,7 @@ export class SpikaWalletAdapter extends BaseWalletAdapter {
|
|
51
51
|
|
52
52
|
url = 'https://chrome.google.com/webstore/detail/spika/fadkojdgchhfkdkklllhcphknohbmjmb';
|
53
53
|
|
54
|
-
icon = 'https://
|
54
|
+
icon = 'https://raw.githubusercontent.com/hippospace/aptos-wallet-adapter/main/logos/spika.svg';
|
55
55
|
|
56
56
|
protected _provider: ISpikaWallet | undefined;
|
57
57
|
|