@manahippo/aptos-wallet-adapter 0.4.3 → 0.4.5
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/NightlyWallet.d.ts +52 -0
- package/dist/WalletAdapters/NightlyWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.js +270 -230
- package/dist/WalletAdapters/NightlyWallet.js.map +1 -1
- 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 +3 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +3 -1
- 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 +5 -3
- package/src/WalletAdapters/AptosSnap.ts +235 -0
- package/src/WalletAdapters/FletchWallet.ts +223 -0
- package/src/WalletAdapters/NightlyWallet.ts +285 -260
- 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 +3 -1
- package/src/WalletProviders/WalletProvider.tsx +14 -7
|
@@ -1,261 +1,286 @@
|
|
|
1
1
|
export const NightlyWallet = () => {};
|
|
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
|
-
|
|
2
|
+
|
|
3
|
+
import { PendingTransaction, TransactionPayload } from 'aptos/src/generated';
|
|
4
|
+
import * as SHA3 from 'js-sha3';
|
|
5
|
+
import { aptosClient } from '../config/aptosConstants';
|
|
6
|
+
import {
|
|
7
|
+
WalletDisconnectionError,
|
|
8
|
+
WalletNotConnectedError,
|
|
9
|
+
WalletNotReadyError,
|
|
10
|
+
WalletSignMessageError,
|
|
11
|
+
WalletSignTransactionError
|
|
12
|
+
} from '../WalletProviders/errors';
|
|
13
|
+
import {
|
|
14
|
+
AccountKeys,
|
|
15
|
+
BaseWalletAdapter,
|
|
16
|
+
scopePollingDetectionStrategy,
|
|
17
|
+
WalletName,
|
|
18
|
+
WalletReadyState
|
|
19
|
+
} from './BaseAdapter';
|
|
20
|
+
|
|
21
|
+
export class AptosPublicKey {
|
|
22
|
+
private readonly hexString: string;
|
|
23
|
+
|
|
24
|
+
static default() {
|
|
25
|
+
return new AptosPublicKey('0'.repeat(64));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
address() {
|
|
29
|
+
const hash = SHA3.sha3_256.create();
|
|
30
|
+
hash.update(Buffer.from(this.asPureHex(), 'hex'));
|
|
31
|
+
hash.update('\x00');
|
|
32
|
+
return '0x' + hash.hex();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
asUint8Array() {
|
|
36
|
+
return new Uint8Array(Buffer.from(this.asPureHex(), 'hex'));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
asString() {
|
|
40
|
+
return this.hexString;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
asPureHex() {
|
|
44
|
+
return this.hexString.substr(2);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
constructor(hexString: string) {
|
|
48
|
+
if (hexString.startsWith('0x')) {
|
|
49
|
+
this.hexString = hexString;
|
|
50
|
+
} else {
|
|
51
|
+
this.hexString = `0x${hexString}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
interface AptosNightly {
|
|
56
|
+
publicKey: AptosPublicKey;
|
|
57
|
+
constructor(eventMap: Map<string, (data: any) => any>);
|
|
58
|
+
connect(onDisconnect?: () => void, eagerConnect?: boolean): Promise<AptosPublicKey>;
|
|
59
|
+
disconnect(): Promise<void>;
|
|
60
|
+
signTransaction: (transaction: TransactionPayload) => Promise<Uint8Array>;
|
|
61
|
+
signAllTransactions: (transaction: TransactionPayload[]) => Promise<Uint8Array[]>;
|
|
62
|
+
signMessage(msg: string): Promise<Uint8Array>;
|
|
63
|
+
}
|
|
64
|
+
interface NightlyWindow extends Window {
|
|
65
|
+
nightly?: {
|
|
66
|
+
aptos: AptosNightly;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare const window: NightlyWindow;
|
|
71
|
+
|
|
72
|
+
export const NightlyWalletName = 'Nightly' as WalletName<'Nightly'>;
|
|
73
|
+
|
|
74
|
+
export interface NightlyWalletAdapterConfig {
|
|
75
|
+
provider?: AptosNightly;
|
|
76
|
+
// network?: WalletAdapterNetwork;
|
|
77
|
+
timeout?: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class NightlyWalletAdapter extends BaseWalletAdapter {
|
|
81
|
+
name = NightlyWalletName;
|
|
82
|
+
|
|
83
|
+
url =
|
|
84
|
+
'https://chrome.google.com/webstore/detail/nightly/fiikommddbeccaoicoejoniammnalkfa/related?hl=en&authuser=0';
|
|
85
|
+
|
|
86
|
+
icon =
|
|
87
|
+
'https://lh3.googleusercontent.com/_feXM9qulMM5w9BYMLzMpZrxW2WlBmdyg3SbETIoRsHdAD9PANnLCEPabC7lzEK0N8fOyyvFkY3746jk8l73zUErxhU=w128-h128-e365-rj-sc0x00ffffff';
|
|
88
|
+
|
|
89
|
+
protected _provider: AptosNightly | undefined;
|
|
90
|
+
|
|
91
|
+
// protected _network: WalletAdapterNetwork;
|
|
92
|
+
protected _timeout: number;
|
|
93
|
+
|
|
94
|
+
protected _readyState: WalletReadyState =
|
|
95
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
|
96
|
+
? WalletReadyState.Unsupported
|
|
97
|
+
: WalletReadyState.NotDetected;
|
|
98
|
+
|
|
99
|
+
protected _connecting: boolean;
|
|
100
|
+
|
|
101
|
+
protected _wallet: {
|
|
102
|
+
publicKey?: string;
|
|
103
|
+
address?: string;
|
|
104
|
+
authKey?: string;
|
|
105
|
+
isConnected: boolean;
|
|
106
|
+
} | null;
|
|
107
|
+
|
|
108
|
+
constructor({
|
|
109
|
+
// provider,
|
|
110
|
+
// network = WalletAdapterNetwork.Mainnet,
|
|
111
|
+
timeout = 10000
|
|
112
|
+
}: NightlyWalletAdapterConfig = {}) {
|
|
113
|
+
super();
|
|
114
|
+
|
|
115
|
+
this._provider = window.nightly?.aptos;
|
|
116
|
+
// this._network = network;
|
|
117
|
+
this._timeout = timeout;
|
|
118
|
+
this._connecting = false;
|
|
119
|
+
this._wallet = null;
|
|
120
|
+
|
|
121
|
+
if (this._readyState !== WalletReadyState.Unsupported) {
|
|
122
|
+
scopePollingDetectionStrategy(() => {
|
|
123
|
+
if (window.nightly?.aptos) {
|
|
124
|
+
this._readyState = WalletReadyState.Installed;
|
|
125
|
+
this.emit('readyStateChange', this._readyState);
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
get publicAccount(): AccountKeys {
|
|
134
|
+
return {
|
|
135
|
+
publicKey: this._wallet?.publicKey || null,
|
|
136
|
+
address: this._wallet?.address || null,
|
|
137
|
+
authKey: this._wallet?.authKey || null
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
get connecting(): boolean {
|
|
142
|
+
return this._connecting;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
get connected(): boolean {
|
|
146
|
+
return !!this._wallet?.isConnected;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
get readyState(): WalletReadyState {
|
|
150
|
+
return this._readyState;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async connect(): Promise<void> {
|
|
154
|
+
try {
|
|
155
|
+
if (this.connected || this.connecting) return;
|
|
156
|
+
if (
|
|
157
|
+
!(
|
|
158
|
+
this._readyState === WalletReadyState.Loadable ||
|
|
159
|
+
this._readyState === WalletReadyState.Installed
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
throw new WalletNotReadyError();
|
|
163
|
+
this._connecting = true;
|
|
164
|
+
|
|
165
|
+
const provider = this._provider || window.nightly?.aptos;
|
|
166
|
+
const publicKey = await provider?.connect(() => {
|
|
167
|
+
this._wallet = null;
|
|
168
|
+
this.emit('disconnect');
|
|
169
|
+
});
|
|
170
|
+
this._wallet = {
|
|
171
|
+
publicKey: publicKey?.asString(),
|
|
172
|
+
address: publicKey?.address(),
|
|
173
|
+
isConnected: true
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
this.emit('connect', this._wallet.publicKey || '');
|
|
177
|
+
} catch (error: any) {
|
|
178
|
+
this.emit('error', error);
|
|
179
|
+
throw error;
|
|
180
|
+
} finally {
|
|
181
|
+
this._connecting = false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async disconnect(): Promise<void> {
|
|
186
|
+
const wallet = this._wallet;
|
|
187
|
+
if (wallet) {
|
|
188
|
+
this._wallet = null;
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
const provider = this._provider || window.nightly?.aptos;
|
|
192
|
+
await provider?.disconnect();
|
|
193
|
+
} catch (error: any) {
|
|
194
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this.emit('disconnect');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async signTransaction(payload: TransactionPayload): Promise<Uint8Array> {
|
|
202
|
+
try {
|
|
203
|
+
const wallet = this._wallet;
|
|
204
|
+
if (!wallet) throw new WalletNotConnectedError();
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
const provider = this._provider || window.nightly?.aptos;
|
|
208
|
+
const response = await provider?.signTransaction(payload);
|
|
209
|
+
if (response) {
|
|
210
|
+
return response;
|
|
211
|
+
} else {
|
|
212
|
+
throw new Error('Transaction failed');
|
|
213
|
+
}
|
|
214
|
+
} catch (error: any) {
|
|
215
|
+
throw new WalletSignTransactionError(error?.message, error);
|
|
216
|
+
}
|
|
217
|
+
} catch (error: any) {
|
|
218
|
+
this.emit('error', error);
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async signAllTransaction(payload: TransactionPayload[]): Promise<Uint8Array[]> {
|
|
224
|
+
try {
|
|
225
|
+
const wallet = this._wallet;
|
|
226
|
+
if (!wallet) throw new WalletNotConnectedError();
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
const provider = this._provider || window.nightly?.aptos;
|
|
230
|
+
const response = await provider?.signAllTransactions(payload);
|
|
231
|
+
if (response) {
|
|
232
|
+
return response;
|
|
233
|
+
} else {
|
|
234
|
+
throw new Error('Transaction failed');
|
|
235
|
+
}
|
|
236
|
+
} catch (error: any) {
|
|
237
|
+
throw new WalletSignTransactionError(error?.message, error);
|
|
238
|
+
}
|
|
239
|
+
} catch (error: any) {
|
|
240
|
+
this.emit('error', error);
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async signAndSubmitTransaction(tx: TransactionPayload): Promise<PendingTransaction> {
|
|
246
|
+
try {
|
|
247
|
+
const wallet = this._wallet;
|
|
248
|
+
if (!wallet) throw new WalletNotConnectedError();
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
const provider = this._provider || window.nightly?.aptos;
|
|
252
|
+
const response = await provider?.signTransaction(tx);
|
|
253
|
+
const result = await aptosClient.submitSignedBCSTransaction(response);
|
|
254
|
+
if (response) {
|
|
255
|
+
return result;
|
|
256
|
+
} else {
|
|
257
|
+
throw new Error('Transaction failed');
|
|
258
|
+
}
|
|
259
|
+
} catch (error: any) {
|
|
260
|
+
const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
|
261
|
+
throw new WalletSignTransactionError(errMsg);
|
|
262
|
+
}
|
|
263
|
+
} catch (error: any) {
|
|
264
|
+
this.emit('error', error);
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async signMessage(message: string): Promise<string> {
|
|
270
|
+
try {
|
|
271
|
+
const wallet = this._wallet;
|
|
272
|
+
const provider = this._provider || window.nightly.aptos;
|
|
273
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
|
274
|
+
const response = await provider?.signMessage(message);
|
|
275
|
+
if (response) {
|
|
276
|
+
return Buffer.from(response).toString('hex');
|
|
277
|
+
} else {
|
|
278
|
+
throw new Error('Sign Message failed');
|
|
279
|
+
}
|
|
280
|
+
} catch (error: any) {
|
|
281
|
+
const errMsg = error.message;
|
|
282
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
@@ -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;
|