@manahippo/aptos-wallet-adapter 0.3.0 → 0.3.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/README.md +5 -3
- package/dist/WalletAdapters/AptosWallet.d.ts +12 -4
- package/dist/WalletAdapters/AptosWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/AptosWallet.js +30 -11
- package/dist/WalletAdapters/AptosWallet.js.map +1 -1
- package/dist/WalletAdapters/BaseAdapter.d.ts +4 -2
- package/dist/WalletAdapters/BaseAdapter.d.ts.map +1 -1
- package/dist/WalletAdapters/BaseAdapter.js.map +1 -1
- package/dist/WalletAdapters/FewchaWallet.d.ts +3 -2
- package/dist/WalletAdapters/FewchaWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/FewchaWallet.js +46 -45
- package/dist/WalletAdapters/FewchaWallet.js.map +1 -1
- package/dist/WalletAdapters/HippoExtensionWallet.d.ts +4 -2
- package/dist/WalletAdapters/HippoExtensionWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HippoExtensionWallet.js +24 -2
- package/dist/WalletAdapters/HippoExtensionWallet.js.map +1 -1
- package/dist/WalletAdapters/HippoWallet.d.ts +3 -2
- package/dist/WalletAdapters/HippoWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HippoWallet.js +26 -1
- package/dist/WalletAdapters/HippoWallet.js.map +1 -1
- package/dist/WalletAdapters/MartianWallet.d.ts +4 -2
- package/dist/WalletAdapters/MartianWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MartianWallet.js +30 -8
- package/dist/WalletAdapters/MartianWallet.js.map +1 -1
- package/dist/WalletAdapters/PontemWallet.d.ts +6 -4
- package/dist/WalletAdapters/PontemWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/PontemWallet.js +28 -6
- package/dist/WalletAdapters/PontemWallet.js.map +1 -1
- package/dist/WalletAdapters/SpikaWallet.d.ts +46 -0
- package/dist/WalletAdapters/SpikaWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/{MultiMaskWallet.js → SpikaWallet.js} +71 -82
- package/dist/WalletAdapters/SpikaWallet.js.map +1 -0
- package/dist/WalletAdapters/index.d.ts +1 -1
- 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/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
- package/dist/WalletProviders/WalletProvider.js +9 -1
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/dist/WalletProviders/useWallet.d.ts +1 -0
- package/dist/WalletProviders/useWallet.d.ts.map +1 -1
- package/dist/WalletProviders/useWallet.js.map +1 -1
- package/package.json +3 -3
- package/src/WalletAdapters/AptosWallet.ts +41 -13
- package/src/WalletAdapters/BaseAdapter.ts +11 -2
- package/src/WalletAdapters/FewchaWallet.ts +45 -25
- package/src/WalletAdapters/HippoExtensionWallet.ts +23 -2
- package/src/WalletAdapters/HippoWallet.ts +27 -1
- package/src/WalletAdapters/MartianWallet.ts +29 -8
- package/src/WalletAdapters/PontemWallet.ts +32 -7
- package/src/WalletAdapters/SpikaWallet.ts +229 -0
- package/src/WalletAdapters/index.ts +1 -1
- package/src/WalletProviders/WalletProvider.tsx +11 -1
- package/src/WalletProviders/useWallet.ts +1 -0
- package/dist/WalletAdapters/MultiMaskWallet.d.ts +0 -41
- package/dist/WalletAdapters/MultiMaskWallet.d.ts.map +0 -1
- package/dist/WalletAdapters/MultiMaskWallet.js.map +0 -1
- package/src/WalletAdapters/MultiMaskWallet.ts +0 -248
|
@@ -3,9 +3,11 @@ import {
|
|
|
3
3
|
WalletDisconnectionError,
|
|
4
4
|
WalletNotConnectedError,
|
|
5
5
|
WalletNotReadyError,
|
|
6
|
+
WalletSignAndSubmitMessageError,
|
|
7
|
+
WalletSignMessageError,
|
|
6
8
|
WalletSignTransactionError
|
|
7
9
|
} from '../WalletProviders/errors';
|
|
8
|
-
import Web3, {
|
|
10
|
+
import Web3, { Web3ProviderType } from '@fewcha/web3';
|
|
9
11
|
import {
|
|
10
12
|
AccountKeys,
|
|
11
13
|
BaseWalletAdapter,
|
|
@@ -16,10 +18,11 @@ import {
|
|
|
16
18
|
import {
|
|
17
19
|
TransactionPayload,
|
|
18
20
|
SubmitTransactionRequest,
|
|
19
|
-
HexEncodedBytes
|
|
21
|
+
HexEncodedBytes,
|
|
22
|
+
EntryFunctionPayload
|
|
20
23
|
} from 'aptos/dist/generated';
|
|
21
24
|
|
|
22
|
-
export const FewchaWalletName = 'Fewcha
|
|
25
|
+
export const FewchaWalletName = 'Fewcha' as WalletName<'Fewcha'>;
|
|
23
26
|
|
|
24
27
|
interface FewchaWindow extends Window {
|
|
25
28
|
fewcha: Web3ProviderType;
|
|
@@ -58,8 +61,6 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
|
58
61
|
}: FewchaAdapterConfig = {}) {
|
|
59
62
|
super();
|
|
60
63
|
|
|
61
|
-
this._provider =
|
|
62
|
-
typeof window !== 'undefined' ? new Web3(new Web3Provider(window.fewcha)).action : undefined;
|
|
63
64
|
// this._network = network;
|
|
64
65
|
this._timeout = timeout;
|
|
65
66
|
this._connecting = false;
|
|
@@ -110,12 +111,12 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
|
110
111
|
throw new WalletNotReadyError();
|
|
111
112
|
|
|
112
113
|
this._connecting = true;
|
|
113
|
-
const provider =
|
|
114
|
-
const isConnected = await
|
|
114
|
+
const provider = new Web3().action;
|
|
115
|
+
const isConnected = await provider.isConnected();
|
|
115
116
|
if (isConnected?.data === true) {
|
|
116
|
-
await provider
|
|
117
|
+
await provider.disconnect();
|
|
117
118
|
}
|
|
118
|
-
const response = await provider
|
|
119
|
+
const response = await provider.connect();
|
|
119
120
|
if (response.status === 401) {
|
|
120
121
|
throw new WalletConnectionError('User has rejected the connection');
|
|
121
122
|
} else if (response.status !== 200) {
|
|
@@ -124,7 +125,7 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
|
124
125
|
let accountDetail = { ...response.data };
|
|
125
126
|
|
|
126
127
|
if (!accountDetail.publicKey) {
|
|
127
|
-
const accountResp = await provider
|
|
128
|
+
const accountResp = await provider.account();
|
|
128
129
|
if (!accountResp.data.publicKey) {
|
|
129
130
|
throw new WalletConnectionError('Wallet connect issue', response.data);
|
|
130
131
|
}
|
|
@@ -134,6 +135,7 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
|
134
135
|
connected: true,
|
|
135
136
|
...accountDetail
|
|
136
137
|
};
|
|
138
|
+
this._provider = provider;
|
|
137
139
|
this.emit('connect', this._wallet.publicKey);
|
|
138
140
|
} catch (error: any) {
|
|
139
141
|
this.emit('error', error);
|
|
@@ -144,22 +146,22 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
async disconnect(): Promise<void> {
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
149
|
-
this._wallet = null;
|
|
150
|
-
|
|
149
|
+
const provider = this._provider;
|
|
150
|
+
if (provider) {
|
|
151
151
|
try {
|
|
152
|
-
const
|
|
153
|
-
const isDisconnected = await provider?.disconnect();
|
|
152
|
+
const isDisconnected = await provider.disconnect();
|
|
154
153
|
if (isDisconnected.data === true) {
|
|
155
|
-
this.
|
|
154
|
+
this._provider = undefined;
|
|
155
|
+
this._wallet = null;
|
|
156
156
|
} else {
|
|
157
157
|
throw new Error('Disconnect failed');
|
|
158
158
|
}
|
|
159
159
|
} catch (error: any) {
|
|
160
160
|
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
|
161
|
+
throw error;
|
|
161
162
|
}
|
|
162
163
|
}
|
|
164
|
+
this.emit('disconnect');
|
|
163
165
|
}
|
|
164
166
|
|
|
165
167
|
async signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest> {
|
|
@@ -168,12 +170,12 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
|
168
170
|
if (!wallet) throw new WalletNotConnectedError();
|
|
169
171
|
|
|
170
172
|
const provider = this._provider || window.fewcha;
|
|
171
|
-
const tx = await provider.generateTransaction(transaction);
|
|
172
|
-
if (!tx) throw new
|
|
173
|
+
const tx = await provider.generateTransaction(transaction as EntryFunctionPayload);
|
|
174
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
|
173
175
|
const response = await provider?.signTransaction(tx.data);
|
|
174
176
|
|
|
175
177
|
if (!response) {
|
|
176
|
-
throw new
|
|
178
|
+
throw new Error('No response');
|
|
177
179
|
}
|
|
178
180
|
const result = { hash: response } as any;
|
|
179
181
|
return result as SubmitTransactionRequest;
|
|
@@ -192,20 +194,38 @@ export class FewchaWalletAdapter extends BaseWalletAdapter {
|
|
|
192
194
|
if (!wallet) throw new WalletNotConnectedError();
|
|
193
195
|
|
|
194
196
|
const provider = this._provider || window.fewcha;
|
|
195
|
-
const tx = await provider.generateTransaction(transaction);
|
|
196
|
-
if (!tx) throw new
|
|
197
|
+
const tx = await provider.generateTransaction(transaction as EntryFunctionPayload);
|
|
198
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
|
197
199
|
const response = await provider?.signAndSubmitTransaction(tx.data);
|
|
198
200
|
if (response.status === 401) {
|
|
199
|
-
throw new
|
|
201
|
+
throw new Error('User has rejected the transaction');
|
|
200
202
|
} else if (response.status !== 200) {
|
|
201
|
-
throw new
|
|
203
|
+
throw new Error('Transaction issue');
|
|
202
204
|
}
|
|
203
205
|
return {
|
|
204
206
|
hash: response.data
|
|
205
207
|
};
|
|
206
208
|
} catch (error: any) {
|
|
207
209
|
const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
|
208
|
-
this.emit('error', new
|
|
210
|
+
this.emit('error', new WalletSignAndSubmitMessageError(errMsg));
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async signMessage(message: string): Promise<string> {
|
|
216
|
+
try {
|
|
217
|
+
const wallet = this._wallet;
|
|
218
|
+
const provider = this._provider || window.fewcha;
|
|
219
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
220
|
+
const response = await provider?.signMessage(message);
|
|
221
|
+
if (response) {
|
|
222
|
+
return response.data;
|
|
223
|
+
} else {
|
|
224
|
+
throw new Error('Sign Message failed');
|
|
225
|
+
}
|
|
226
|
+
} catch (error: any) {
|
|
227
|
+
const errMsg = error.message;
|
|
228
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
|
209
229
|
throw error;
|
|
210
230
|
}
|
|
211
231
|
}
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
WalletDisconnectionError,
|
|
9
9
|
WalletNotConnectedError,
|
|
10
10
|
WalletNotReadyError,
|
|
11
|
+
WalletSignAndSubmitMessageError,
|
|
12
|
+
WalletSignMessageError,
|
|
11
13
|
WalletSignTransactionError
|
|
12
14
|
} from '../WalletProviders/errors';
|
|
13
15
|
import {
|
|
@@ -28,6 +30,7 @@ interface IHippoWallet {
|
|
|
28
30
|
isConnected: () => Promise<boolean>;
|
|
29
31
|
signAndSubmitTransaction(transaction: any): Promise<any>;
|
|
30
32
|
signTransaction(transaction: any): Promise<void>;
|
|
33
|
+
signMessage(message: string): Promise<string>;
|
|
31
34
|
disconnect(): Promise<void>;
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -37,7 +40,7 @@ interface HippoWindow extends Window {
|
|
|
37
40
|
|
|
38
41
|
declare const window: HippoWindow;
|
|
39
42
|
|
|
40
|
-
export const HippoExtensionWalletName = 'Hippo
|
|
43
|
+
export const HippoExtensionWalletName = 'Hippo' as WalletName<'Hippo'>;
|
|
41
44
|
|
|
42
45
|
export interface HippoExtensionWalletAdapterConfig {
|
|
43
46
|
provider?: IHippoWallet;
|
|
@@ -195,11 +198,29 @@ export class HippoExtensionWalletAdapter extends BaseWalletAdapter {
|
|
|
195
198
|
}
|
|
196
199
|
} catch (error: any) {
|
|
197
200
|
// console.log('transact err', error, error.message);
|
|
198
|
-
throw new
|
|
201
|
+
throw new WalletSignAndSubmitMessageError(error.message || error);
|
|
199
202
|
}
|
|
200
203
|
} catch (error: any) {
|
|
201
204
|
this.emit('error', error);
|
|
202
205
|
throw error;
|
|
203
206
|
}
|
|
204
207
|
}
|
|
208
|
+
|
|
209
|
+
async signMessage(message: string): Promise<string> {
|
|
210
|
+
try {
|
|
211
|
+
const wallet = this._wallet;
|
|
212
|
+
const provider = this._provider || window.hippoWallet;
|
|
213
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
214
|
+
const response = await provider?.signMessage(message);
|
|
215
|
+
if (response) {
|
|
216
|
+
return response;
|
|
217
|
+
} else {
|
|
218
|
+
throw new Error('Sign Message failed');
|
|
219
|
+
}
|
|
220
|
+
} catch (error: any) {
|
|
221
|
+
const errMsg = error.message;
|
|
222
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
205
226
|
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '../WalletProviders/errors';
|
|
13
13
|
import { AccountKeys, BaseWalletAdapter, WalletName, WalletReadyState } from './BaseAdapter';
|
|
14
14
|
|
|
15
|
-
export const HippoWalletName = 'Hippo Web
|
|
15
|
+
export const HippoWalletName = 'Hippo Web' as WalletName<'Hippo Web'>;
|
|
16
16
|
|
|
17
17
|
export interface HippoWalletAdapterConfig {
|
|
18
18
|
provider?: string;
|
|
@@ -196,6 +196,32 @@ export class HippoWalletAdapter extends BaseWalletAdapter {
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
async signMessage(message: string): Promise<string> {
|
|
200
|
+
try {
|
|
201
|
+
const request = new URLSearchParams({
|
|
202
|
+
request: JSON.stringify({
|
|
203
|
+
method: 'signMessage',
|
|
204
|
+
payload: message
|
|
205
|
+
}),
|
|
206
|
+
origin: window.location.origin
|
|
207
|
+
}).toString();
|
|
208
|
+
const popup = window.open(
|
|
209
|
+
`${WEBWALLET_URL}?${request}`,
|
|
210
|
+
'Transaction Confirmation',
|
|
211
|
+
'scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=440,height=700'
|
|
212
|
+
);
|
|
213
|
+
if (!popup) throw new WalletNotConnectedError();
|
|
214
|
+
const promise = await new Promise((resolve, reject) => {
|
|
215
|
+
this.once('success', resolve);
|
|
216
|
+
this.once('error', reject);
|
|
217
|
+
});
|
|
218
|
+
return promise as string;
|
|
219
|
+
} catch (error: any) {
|
|
220
|
+
this.emit('error', error);
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
199
225
|
private _beforeUnload = (): void => {
|
|
200
226
|
void this.disconnect();
|
|
201
227
|
};
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
WalletDisconnectionError,
|
|
9
9
|
WalletNotConnectedError,
|
|
10
10
|
WalletNotReadyError,
|
|
11
|
+
WalletSignAndSubmitMessageError,
|
|
12
|
+
WalletSignMessageError,
|
|
11
13
|
WalletSignTransactionError
|
|
12
14
|
} from '../WalletProviders/errors';
|
|
13
15
|
import {
|
|
@@ -38,6 +40,7 @@ interface IMartianWallet {
|
|
|
38
40
|
generateTransaction(sender: MaybeHexString, payload: any): Promise<any>;
|
|
39
41
|
signAndSubmitTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
|
40
42
|
signTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
|
43
|
+
signMessage(message: string): Promise<string>;
|
|
41
44
|
disconnect(): Promise<void>;
|
|
42
45
|
}
|
|
43
46
|
|
|
@@ -47,7 +50,7 @@ interface MartianWindow extends Window {
|
|
|
47
50
|
|
|
48
51
|
declare const window: MartianWindow;
|
|
49
52
|
|
|
50
|
-
export const MartianWalletName = '
|
|
53
|
+
export const MartianWalletName = 'Martian' as WalletName<'Martian'>;
|
|
51
54
|
|
|
52
55
|
export interface MartianWalletAdapterConfig {
|
|
53
56
|
provider?: IMartianWallet;
|
|
@@ -61,7 +64,7 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
|
61
64
|
url = 'https://chrome.google.com/webstore/detail/martian-wallet/efbglgofoippbgcjepnhiblaibcnclgk';
|
|
62
65
|
|
|
63
66
|
icon =
|
|
64
|
-
'
|
|
67
|
+
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzUyIiBoZWlnaHQ9IjM1MiIgdmlld0JveD0iMCAwIDM1MiAzNTIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzNTIiIGhlaWdodD0iMzUyIiByeD0iODciIGZpbGw9IiMxRjFGMUYiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNjkuNzAxIDg5LjA4NDFDMTU5LjUwOCA4OS44MzA5IDE1MC41NDcgOTIuMDAxNCAxNDEuMDc2IDk2LjAxNjlDMTM5LjQyNCA5Ni43MTc0IDEzMy43MDIgOTkuNjAzNyAxMzIuMTE2IDEwMC41MzdDMTI4LjEzMSAxMDIuODgxIDEyMy4wNDMgMTA2LjQ5NiAxMTkuNTg2IDEwOS40NEMxMTYuOTc1IDExMS42NjUgMTExLjIxNiAxMTcuNDUyIDEwOS4yMDIgMTE5Ljg3NkMxMDUuMDg1IDEyNC44MzIgMTAxLjA4OCAxMzAuODg2IDk4LjQzODQgMTM2LjE3OUM5Ny45OTQyIDEzNy4wNjYgOTcuNTYzNSAxMzcuODE3IDk3LjQ4MTMgMTM3Ljg0OEM5Ny4zOTkzIDEzNy44OCA5Ny4zMzIgMTM3Ljk5NSA5Ny4zMzIgMTM4LjEwNUM5Ny4zMzIgMTM4LjIxNCA5Ni43Njg1IDEzOS42MDggOTYuMDc5NiAxNDEuMkM5NC42OTc1IDE0NC4zOTYgOTIuOTE3NiAxNDkuNDk2IDkxLjk5MjUgMTUyLjkwOUM4OS42MjY3IDE2MS42NCA4OC41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44NDMgMjIzLjk3NiAyMTYuOTU5IDIyMi43MDRDMjE5LjYzOSAyMjIuMDM4IDIyNC4xNTggMjIwLjc5NCAyMjQuNjU3IDIyMC41ODZDMjI0Ljg0NCAyMjAuNTA4IDIyNi4wMjkgMjIwLjA5MiAyMjcuMjkgMjE5LjY2MkMyMjguNTUxIDIxOS4yMzEgMjMwLjYxNSAyMTguNDY2IDIzMS44NzcgMjE3Ljk2MUMyMzQuMzIzIDIxNi45ODIgMjM0LjQyNSAyMTYuOTQ5IDIzNC40MjUgMjE3LjEyOVoiIGZpbGw9IndoaXRlIi8+Cjwvc3ZnPgo=';
|
|
65
68
|
|
|
66
69
|
protected _provider: IMartianWallet | undefined;
|
|
67
70
|
|
|
@@ -183,16 +186,16 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
|
183
186
|
const provider = this._provider || window.martian;
|
|
184
187
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
185
188
|
const tx = await provider.generateTransaction(wallet.address || '', transactionPyld);
|
|
186
|
-
if (!tx) throw new
|
|
189
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
|
187
190
|
const response = await provider?.signTransaction(tx);
|
|
188
191
|
|
|
189
192
|
if (!response) {
|
|
190
|
-
throw new
|
|
193
|
+
throw new Error('No response');
|
|
191
194
|
}
|
|
192
195
|
const result = { hash: response } as any;
|
|
193
196
|
return result as SubmitTransactionRequest;
|
|
194
197
|
} catch (error: any) {
|
|
195
|
-
this.emit('error', error);
|
|
198
|
+
this.emit('error', new WalletSignTransactionError(error));
|
|
196
199
|
throw error;
|
|
197
200
|
}
|
|
198
201
|
}
|
|
@@ -205,15 +208,33 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
|
205
208
|
const provider = this._provider || window.martian;
|
|
206
209
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
207
210
|
const tx = await provider.generateTransaction(wallet.address || '', transactionPyld);
|
|
208
|
-
if (!tx) throw new
|
|
211
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
|
209
212
|
const response = await provider?.signAndSubmitTransaction(tx);
|
|
210
213
|
|
|
211
214
|
if (!response) {
|
|
212
|
-
throw new
|
|
215
|
+
throw new Error('No response');
|
|
213
216
|
}
|
|
214
217
|
return { hash: response };
|
|
215
218
|
} catch (error: any) {
|
|
216
|
-
this.emit('error', new
|
|
219
|
+
this.emit('error', new WalletSignAndSubmitMessageError(error));
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async signMessage(message: string): Promise<string> {
|
|
225
|
+
try {
|
|
226
|
+
const wallet = this._wallet;
|
|
227
|
+
const provider = this._provider || window.martian;
|
|
228
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
229
|
+
const response = await provider?.signMessage(message);
|
|
230
|
+
if (response) {
|
|
231
|
+
return response;
|
|
232
|
+
} else {
|
|
233
|
+
throw new Error('Sign Message failed');
|
|
234
|
+
}
|
|
235
|
+
} catch (error: any) {
|
|
236
|
+
const errMsg = error.message;
|
|
237
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
|
217
238
|
throw error;
|
|
218
239
|
}
|
|
219
240
|
}
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
WalletDisconnectionError,
|
|
9
9
|
WalletNotConnectedError,
|
|
10
10
|
WalletNotReadyError,
|
|
11
|
+
WalletSignAndSubmitMessageError,
|
|
12
|
+
WalletSignMessageError,
|
|
11
13
|
WalletSignTransactionError
|
|
12
14
|
} from '../WalletProviders/errors';
|
|
13
15
|
import {
|
|
@@ -35,13 +37,17 @@ interface IPontemWallet {
|
|
|
35
37
|
connect: () => Promise<ConnectPontemAccount>;
|
|
36
38
|
account(): Promise<MaybeHexString>;
|
|
37
39
|
generateTransaction(sender: MaybeHexString, payload: any): Promise<any>;
|
|
38
|
-
signAndSubmit(
|
|
40
|
+
signAndSubmit(
|
|
41
|
+
transaction: TransactionPayload,
|
|
42
|
+
options?: any
|
|
43
|
+
): Promise<{
|
|
39
44
|
success: boolean;
|
|
40
45
|
result: {
|
|
41
46
|
hash: HexEncodedBytes;
|
|
42
47
|
};
|
|
43
48
|
}>;
|
|
44
49
|
// signTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
|
50
|
+
signMessage(message: string): Promise<string>;
|
|
45
51
|
disconnect(): Promise<void>;
|
|
46
52
|
}
|
|
47
53
|
|
|
@@ -51,7 +57,7 @@ interface PontemWindow extends Window {
|
|
|
51
57
|
|
|
52
58
|
declare const window: PontemWindow;
|
|
53
59
|
|
|
54
|
-
export const PontemWalletName = '
|
|
60
|
+
export const PontemWalletName = 'Pontem' as WalletName<'Pontem'>;
|
|
55
61
|
|
|
56
62
|
export interface PontemWalletAdapterConfig {
|
|
57
63
|
provider?: IPontemWallet;
|
|
@@ -199,26 +205,45 @@ export class PontemWalletAdapter extends BaseWalletAdapter {
|
|
|
199
205
|
// const result = { hash: response } as any;
|
|
200
206
|
return {} as SubmitTransactionRequest;
|
|
201
207
|
} catch (error: any) {
|
|
202
|
-
this.emit('error', error);
|
|
208
|
+
this.emit('error', new WalletSignTransactionError(error));
|
|
203
209
|
throw error;
|
|
204
210
|
}
|
|
205
211
|
}
|
|
206
212
|
|
|
207
213
|
async signAndSubmitTransaction(
|
|
208
|
-
transactionPyld: TransactionPayload
|
|
214
|
+
transactionPyld: TransactionPayload,
|
|
215
|
+
options?: any
|
|
209
216
|
): Promise<{ hash: HexEncodedBytes }> {
|
|
210
217
|
try {
|
|
211
218
|
const wallet = this._wallet;
|
|
212
219
|
const provider = this._provider || window.pontem;
|
|
213
220
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
214
|
-
const response = await provider?.signAndSubmit(transactionPyld);
|
|
221
|
+
const response = await provider?.signAndSubmit(transactionPyld, options);
|
|
215
222
|
|
|
216
223
|
if (!response || !response.success) {
|
|
217
|
-
throw new
|
|
224
|
+
throw new Error('No response');
|
|
218
225
|
}
|
|
219
226
|
return { hash: response.result.hash };
|
|
220
227
|
} catch (error: any) {
|
|
221
|
-
this.emit('error', new
|
|
228
|
+
this.emit('error', new WalletSignAndSubmitMessageError(error.error.message));
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async signMessage(message: string): Promise<string> {
|
|
234
|
+
try {
|
|
235
|
+
const wallet = this._wallet;
|
|
236
|
+
const provider = this._provider || window.pontem;
|
|
237
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
238
|
+
const response = await provider?.signMessage(message);
|
|
239
|
+
if (response) {
|
|
240
|
+
return response;
|
|
241
|
+
} else {
|
|
242
|
+
throw new Error('Sign Message failed');
|
|
243
|
+
}
|
|
244
|
+
} catch (error: any) {
|
|
245
|
+
const errMsg = error.message;
|
|
246
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
|
222
247
|
throw error;
|
|
223
248
|
}
|
|
224
249
|
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HexEncodedBytes,
|
|
3
|
+
SubmitTransactionRequest,
|
|
4
|
+
TransactionPayload
|
|
5
|
+
} from 'aptos/dist/generated';
|
|
6
|
+
import {
|
|
7
|
+
WalletDisconnectionError,
|
|
8
|
+
WalletNotConnectedError,
|
|
9
|
+
WalletNotReadyError,
|
|
10
|
+
WalletSignAndSubmitMessageError,
|
|
11
|
+
WalletSignMessageError,
|
|
12
|
+
WalletSignTransactionError
|
|
13
|
+
} from '../WalletProviders/errors';
|
|
14
|
+
import {
|
|
15
|
+
AccountKeys,
|
|
16
|
+
BaseWalletAdapter,
|
|
17
|
+
scopePollingDetectionStrategy,
|
|
18
|
+
WalletName,
|
|
19
|
+
WalletReadyState
|
|
20
|
+
} from './BaseAdapter';
|
|
21
|
+
|
|
22
|
+
interface ISpikaWallet {
|
|
23
|
+
connect: () => Promise<{ publicKey: string; account: string; authKey: string }>;
|
|
24
|
+
account: () => Promise<string>;
|
|
25
|
+
isConnected: () => Promise<boolean>;
|
|
26
|
+
signAndSubmitTransaction(transaction: any): Promise<{ hash: HexEncodedBytes }>;
|
|
27
|
+
signTransaction(transaction: any): Promise<SubmitTransactionRequest>;
|
|
28
|
+
signMessage(message: string): Promise<string>;
|
|
29
|
+
disconnect(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface SpikaWindow extends Window {
|
|
33
|
+
spika?: ISpikaWallet;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare const window: SpikaWindow;
|
|
37
|
+
|
|
38
|
+
export const SpikaWalletName = 'Spika' as WalletName<'Spika'>;
|
|
39
|
+
|
|
40
|
+
export interface SpikaWalletAdapterConfig {
|
|
41
|
+
provider?: ISpikaWallet;
|
|
42
|
+
// network?: WalletAdapterNetwork;
|
|
43
|
+
timeout?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class SpikaWalletAdapter extends BaseWalletAdapter {
|
|
47
|
+
name = SpikaWalletName;
|
|
48
|
+
|
|
49
|
+
url = 'https://chrome.google.com/webstore/detail/spika/fadkojdgchhfkdkklllhcphknohbmjmb';
|
|
50
|
+
|
|
51
|
+
icon = 'https://pbs.twimg.com/profile_images/1562544739181887488/vSqEIeyh_400x400.png';
|
|
52
|
+
|
|
53
|
+
protected _provider: ISpikaWallet | undefined;
|
|
54
|
+
|
|
55
|
+
// protected _network: WalletAdapterNetwork;
|
|
56
|
+
protected _timeout: number;
|
|
57
|
+
|
|
58
|
+
protected _readyState: WalletReadyState =
|
|
59
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
|
60
|
+
? WalletReadyState.Unsupported
|
|
61
|
+
: WalletReadyState.NotDetected;
|
|
62
|
+
|
|
63
|
+
protected _connecting: boolean;
|
|
64
|
+
|
|
65
|
+
protected _wallet: any | null;
|
|
66
|
+
|
|
67
|
+
constructor({
|
|
68
|
+
// provider,
|
|
69
|
+
// network = WalletAdapterNetwork.Mainnet,
|
|
70
|
+
timeout = 10000
|
|
71
|
+
}: SpikaWalletAdapterConfig = {}) {
|
|
72
|
+
super();
|
|
73
|
+
|
|
74
|
+
this._provider = typeof window !== 'undefined' ? window.spika : undefined;
|
|
75
|
+
// this._network = network;
|
|
76
|
+
this._timeout = timeout;
|
|
77
|
+
this._connecting = false;
|
|
78
|
+
this._wallet = null;
|
|
79
|
+
|
|
80
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
|
81
|
+
scopePollingDetectionStrategy(() => {
|
|
82
|
+
if (window.spika) {
|
|
83
|
+
this._readyState = WalletReadyState.Installed;
|
|
84
|
+
this.emit('readyStateChange', this._readyState);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get publicAccount(): AccountKeys {
|
|
93
|
+
return {
|
|
94
|
+
publicKey: this._wallet?.publicKey || null,
|
|
95
|
+
address: this._wallet?.address || null,
|
|
96
|
+
authKey: this._wallet?.authKey || null
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
get connecting(): boolean {
|
|
101
|
+
return this._connecting;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get connected(): boolean {
|
|
105
|
+
return !!this._wallet?.isConnected;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get readyState(): WalletReadyState {
|
|
109
|
+
return this._readyState;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async connect(): Promise<void> {
|
|
113
|
+
try {
|
|
114
|
+
if (this.connected || this.connecting) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (
|
|
119
|
+
!(
|
|
120
|
+
this._readyState === WalletReadyState.Loadable ||
|
|
121
|
+
this._readyState === WalletReadyState.Installed
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
throw new WalletNotReadyError();
|
|
125
|
+
this._connecting = true;
|
|
126
|
+
|
|
127
|
+
const provider = this._provider || window.spika;
|
|
128
|
+
const isConnected = await this._provider?.isConnected();
|
|
129
|
+
if (isConnected === true) {
|
|
130
|
+
await provider?.disconnect();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const response = await provider?.connect();
|
|
134
|
+
if (response?.publicKey !== undefined) {
|
|
135
|
+
this._wallet = {
|
|
136
|
+
publicKey: response?.publicKey,
|
|
137
|
+
address: response?.account,
|
|
138
|
+
authKey: response?.authKey,
|
|
139
|
+
isConnected: true
|
|
140
|
+
};
|
|
141
|
+
} else {
|
|
142
|
+
this._wallet = {
|
|
143
|
+
isConnected: false
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
this.emit('connect', this._wallet.publicKey);
|
|
148
|
+
} catch (error: any) {
|
|
149
|
+
this.emit('error', error);
|
|
150
|
+
throw error;
|
|
151
|
+
} finally {
|
|
152
|
+
this._connecting = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async disconnect(): Promise<void> {
|
|
157
|
+
const wallet = this._wallet;
|
|
158
|
+
if (wallet) {
|
|
159
|
+
this._wallet = null;
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
const provider = this._provider || window.spika;
|
|
163
|
+
await provider?.disconnect();
|
|
164
|
+
} catch (error: any) {
|
|
165
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
this.emit('disconnect');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async signTransaction(transaction: TransactionPayload): Promise<SubmitTransactionRequest> {
|
|
173
|
+
try {
|
|
174
|
+
const wallet = this._wallet;
|
|
175
|
+
const provider = this._provider || window.spika;
|
|
176
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
177
|
+
|
|
178
|
+
const response = await provider?.signTransaction(transaction);
|
|
179
|
+
if (response) {
|
|
180
|
+
return response;
|
|
181
|
+
} else {
|
|
182
|
+
throw new Error('Sign Transaction failed');
|
|
183
|
+
}
|
|
184
|
+
} catch (error: any) {
|
|
185
|
+
const errMsg = error.message;
|
|
186
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async signAndSubmitTransaction(
|
|
192
|
+
transaction: TransactionPayload
|
|
193
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
|
194
|
+
try {
|
|
195
|
+
const wallet = this._wallet;
|
|
196
|
+
const provider = this._provider || window.spika;
|
|
197
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
198
|
+
|
|
199
|
+
const response = await provider?.signAndSubmitTransaction(transaction);
|
|
200
|
+
if (response) {
|
|
201
|
+
return response;
|
|
202
|
+
} else {
|
|
203
|
+
throw new Error('Transaction failed');
|
|
204
|
+
}
|
|
205
|
+
} catch (error: any) {
|
|
206
|
+
const errMsg = error.message;
|
|
207
|
+
this.emit('error', new WalletSignAndSubmitMessageError(errMsg));
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async signMessage(message: string): Promise<string> {
|
|
213
|
+
try {
|
|
214
|
+
const wallet = this._wallet;
|
|
215
|
+
const provider = this._provider || window.spika;
|
|
216
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
217
|
+
const response = await provider?.signMessage(message);
|
|
218
|
+
if (response) {
|
|
219
|
+
return response;
|
|
220
|
+
} else {
|
|
221
|
+
throw new Error('Sign Message failed');
|
|
222
|
+
}
|
|
223
|
+
} catch (error: any) {
|
|
224
|
+
const errMsg = error.message;
|
|
225
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -3,7 +3,7 @@ export * from './BaseAdapter';
|
|
|
3
3
|
export * from './HippoExtensionWallet';
|
|
4
4
|
export * from './HippoWallet';
|
|
5
5
|
export * from './MartianWallet';
|
|
6
|
-
export * from './MultiMaskWallet';
|
|
7
6
|
export * from './FewchaWallet';
|
|
8
7
|
export * from './PontemWallet';
|
|
9
8
|
// export * from './NightlyWallet';
|
|
9
|
+
export * from './SpikaWallet';
|