@llayer-network/wallet-standard-wallet-adapter-base 1.1.4
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/LICENSE +202 -0
- package/README.md +0 -0
- package/lib/cjs/adapter.js +440 -0
- package/lib/cjs/adapter.js.map +1 -0
- package/lib/cjs/index.js +20 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/lib/cjs/types.js +11 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/cjs/wallet.js +368 -0
- package/lib/cjs/wallet.js.map +1 -0
- package/lib/esm/adapter.js +397 -0
- package/lib/esm/adapter.js.map +1 -0
- package/lib/esm/index.js +4 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/lib/esm/types.js +8 -0
- package/lib/esm/types.js.map +1 -0
- package/lib/esm/wallet.js +349 -0
- package/lib/esm/wallet.js.map +1 -0
- package/lib/types/adapter.d.ts +32 -0
- package/lib/types/adapter.d.ts.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/types.d.ts +20 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/wallet.d.ts +32 -0
- package/lib/types/wallet.d.ts.map +1 -0
- package/package.json +51 -0
- package/src/adapter.ts +479 -0
- package/src/index.ts +3 -0
- package/src/types.ts +26 -0
- package/src/wallet.ts +457 -0
package/src/adapter.ts
ADDED
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseWalletAdapter,
|
|
3
|
+
isVersionedTransaction,
|
|
4
|
+
type SendTransactionOptions,
|
|
5
|
+
type StandardWalletAdapter as StandardWalletAdapterType,
|
|
6
|
+
type SupportedTransactionVersions,
|
|
7
|
+
WalletAccountError,
|
|
8
|
+
type WalletAdapterCompatibleStandardWallet,
|
|
9
|
+
WalletConfigError,
|
|
10
|
+
WalletConnectionError,
|
|
11
|
+
WalletDisconnectedError,
|
|
12
|
+
WalletDisconnectionError,
|
|
13
|
+
WalletError,
|
|
14
|
+
type WalletName,
|
|
15
|
+
WalletNotConnectedError,
|
|
16
|
+
WalletNotReadyError,
|
|
17
|
+
WalletPublicKeyError,
|
|
18
|
+
WalletReadyState,
|
|
19
|
+
WalletSendTransactionError,
|
|
20
|
+
WalletSignInError,
|
|
21
|
+
WalletSignMessageError,
|
|
22
|
+
WalletSignTransactionError,
|
|
23
|
+
} from '@solana/wallet-adapter-base';
|
|
24
|
+
import {
|
|
25
|
+
SolanaSignAndSendTransaction,
|
|
26
|
+
type SolanaSignAndSendTransactionFeature,
|
|
27
|
+
SolanaSignIn,
|
|
28
|
+
type SolanaSignInInput,
|
|
29
|
+
type SolanaSignInOutput,
|
|
30
|
+
SolanaSignMessage,
|
|
31
|
+
SolanaSignTransaction,
|
|
32
|
+
type SolanaSignTransactionFeature,
|
|
33
|
+
} from '@llayer-network/wallet-standard-features';
|
|
34
|
+
import { getChainForEndpoint, getCommitment } from '@llayer-network/wallet-standard-util';
|
|
35
|
+
import type { Connection, TransactionSignature } from '@solana/web3.js';
|
|
36
|
+
import { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
37
|
+
import type { WalletAccount } from '@llayer-wallet-standard/base';
|
|
38
|
+
import {
|
|
39
|
+
StandardConnect,
|
|
40
|
+
type StandardConnectInput,
|
|
41
|
+
StandardDisconnect,
|
|
42
|
+
StandardEvents,
|
|
43
|
+
type StandardEventsListeners,
|
|
44
|
+
} from '@llayer-wallet-standard/features';
|
|
45
|
+
import { arraysEqual } from '@llayer-wallet-standard/wallet';
|
|
46
|
+
import bs58 from 'bs58';
|
|
47
|
+
|
|
48
|
+
/** TODO: docs */
|
|
49
|
+
export interface StandardWalletAdapterConfig {
|
|
50
|
+
wallet: WalletAdapterCompatibleStandardWallet;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** TODO: docs */
|
|
54
|
+
export class StandardWalletAdapter extends BaseWalletAdapter implements StandardWalletAdapterType {
|
|
55
|
+
#account: WalletAccount | null;
|
|
56
|
+
#publicKey: PublicKey | null;
|
|
57
|
+
#connecting: boolean;
|
|
58
|
+
#disconnecting: boolean;
|
|
59
|
+
#off: (() => void) | null;
|
|
60
|
+
#supportedTransactionVersions: SupportedTransactionVersions;
|
|
61
|
+
readonly #wallet: WalletAdapterCompatibleStandardWallet;
|
|
62
|
+
readonly #readyState: WalletReadyState =
|
|
63
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
|
64
|
+
? WalletReadyState.Unsupported
|
|
65
|
+
: WalletReadyState.Installed;
|
|
66
|
+
|
|
67
|
+
get name() {
|
|
68
|
+
return this.#wallet.name as WalletName;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get url() {
|
|
72
|
+
return 'https://github.com/solana-labs/wallet-standard';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get icon() {
|
|
76
|
+
return this.#wallet.icon;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get readyState() {
|
|
80
|
+
return this.#readyState;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get publicKey() {
|
|
84
|
+
return this.#publicKey;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get connecting() {
|
|
88
|
+
return this.#connecting;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get supportedTransactionVersions() {
|
|
92
|
+
return this.#supportedTransactionVersions;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get wallet(): WalletAdapterCompatibleStandardWallet {
|
|
96
|
+
return this.#wallet;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get standard() {
|
|
100
|
+
return true as const;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
constructor({ wallet }: StandardWalletAdapterConfig) {
|
|
104
|
+
super();
|
|
105
|
+
|
|
106
|
+
this.#wallet = wallet;
|
|
107
|
+
this.#account = null;
|
|
108
|
+
this.#publicKey = null;
|
|
109
|
+
this.#connecting = false;
|
|
110
|
+
this.#disconnecting = false;
|
|
111
|
+
this.#off = this.#wallet.features[StandardEvents].on('change', this.#changed);
|
|
112
|
+
|
|
113
|
+
this.#reset();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
destroy(): void {
|
|
117
|
+
this.#account = null;
|
|
118
|
+
this.#publicKey = null;
|
|
119
|
+
this.#connecting = false;
|
|
120
|
+
this.#disconnecting = false;
|
|
121
|
+
|
|
122
|
+
const off = this.#off;
|
|
123
|
+
if (off) {
|
|
124
|
+
this.#off = null;
|
|
125
|
+
off();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async autoConnect(): Promise<void> {
|
|
130
|
+
return this.#connect({ silent: true });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async connect(): Promise<void> {
|
|
134
|
+
return this.#connect();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async #connect(input?: StandardConnectInput): Promise<void> {
|
|
138
|
+
try {
|
|
139
|
+
if (this.connected || this.connecting) return;
|
|
140
|
+
if (this.#readyState !== WalletReadyState.Installed) throw new WalletNotReadyError();
|
|
141
|
+
|
|
142
|
+
this.#connecting = true;
|
|
143
|
+
|
|
144
|
+
if (!this.#wallet.accounts.length) {
|
|
145
|
+
try {
|
|
146
|
+
await this.#wallet.features[StandardConnect].connect(input);
|
|
147
|
+
} catch (error: any) {
|
|
148
|
+
throw new WalletConnectionError(error?.message, error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const account = this.#wallet.accounts[0];
|
|
153
|
+
if (!account) throw new WalletAccountError();
|
|
154
|
+
|
|
155
|
+
this.#connected(account);
|
|
156
|
+
} catch (error: any) {
|
|
157
|
+
this.emit('error', error);
|
|
158
|
+
throw error;
|
|
159
|
+
} finally {
|
|
160
|
+
this.#connecting = false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async disconnect(): Promise<void> {
|
|
165
|
+
if (StandardDisconnect in this.#wallet.features) {
|
|
166
|
+
try {
|
|
167
|
+
this.#disconnecting = true;
|
|
168
|
+
await this.#wallet.features[StandardDisconnect].disconnect();
|
|
169
|
+
} catch (error: any) {
|
|
170
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
|
171
|
+
} finally {
|
|
172
|
+
this.#disconnecting = false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
this.#disconnected();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
#connected(account: WalletAccount) {
|
|
180
|
+
let publicKey: PublicKey;
|
|
181
|
+
try {
|
|
182
|
+
// Use account.address instead of account.publicKey since address could be a PDA
|
|
183
|
+
publicKey = new PublicKey(account.address);
|
|
184
|
+
} catch (error: any) {
|
|
185
|
+
throw new WalletPublicKeyError(error?.message, error);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.#account = account;
|
|
189
|
+
this.#publicKey = publicKey;
|
|
190
|
+
this.#reset();
|
|
191
|
+
this.emit('connect', publicKey);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
#disconnected(): void {
|
|
195
|
+
this.#account = null;
|
|
196
|
+
this.#publicKey = null;
|
|
197
|
+
this.#reset();
|
|
198
|
+
this.emit('disconnect');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
#reset() {
|
|
202
|
+
const supportedTransactionVersions =
|
|
203
|
+
SolanaSignAndSendTransaction in this.#wallet.features
|
|
204
|
+
? this.#wallet.features[SolanaSignAndSendTransaction].supportedTransactionVersions
|
|
205
|
+
: this.#wallet.features[SolanaSignTransaction].supportedTransactionVersions;
|
|
206
|
+
this.#supportedTransactionVersions = arraysEqual(supportedTransactionVersions, ['legacy'])
|
|
207
|
+
? null
|
|
208
|
+
: new Set(supportedTransactionVersions);
|
|
209
|
+
|
|
210
|
+
if (SolanaSignTransaction in this.#wallet.features && this.#account?.features.includes(SolanaSignTransaction)) {
|
|
211
|
+
this.signTransaction = this.#signTransaction;
|
|
212
|
+
this.signAllTransactions = this.#signAllTransactions;
|
|
213
|
+
} else {
|
|
214
|
+
delete this.signTransaction;
|
|
215
|
+
delete this.signAllTransactions;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (SolanaSignMessage in this.#wallet.features && this.#account?.features.includes(SolanaSignMessage)) {
|
|
219
|
+
this.signMessage = this.#signMessage;
|
|
220
|
+
} else {
|
|
221
|
+
delete this.signMessage;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (SolanaSignIn in this.#wallet.features) {
|
|
225
|
+
this.signIn = this.#signIn;
|
|
226
|
+
} else {
|
|
227
|
+
delete this.signIn;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
#changed: StandardEventsListeners['change'] = (properties) => {
|
|
232
|
+
// If accounts have changed on the wallet, reflect this on the adapter.
|
|
233
|
+
if ('accounts' in properties) {
|
|
234
|
+
const account = this.#wallet.accounts[0];
|
|
235
|
+
// If the adapter isn't connected, or is disconnecting, or the first account hasn't changed, do nothing.
|
|
236
|
+
if (this.#account && !this.#disconnecting && account !== this.#account) {
|
|
237
|
+
// If there's a connected account, connect the adapter. Otherwise, disconnect it.
|
|
238
|
+
if (account) {
|
|
239
|
+
// Connect the adapter.
|
|
240
|
+
this.#connected(account);
|
|
241
|
+
} else {
|
|
242
|
+
// Emit an error because the wallet spontaneously disconnected.
|
|
243
|
+
this.emit('error', new WalletDisconnectedError());
|
|
244
|
+
// Disconnect the adapter.
|
|
245
|
+
this.#disconnected();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// After reflecting account changes, if features have changed on the wallet, reflect this on the adapter.
|
|
251
|
+
if ('features' in properties) {
|
|
252
|
+
this.#reset();
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
async sendTransaction<T extends Transaction | VersionedTransaction>(
|
|
257
|
+
transaction: T,
|
|
258
|
+
connection: Connection,
|
|
259
|
+
options: SendTransactionOptions = {}
|
|
260
|
+
): Promise<TransactionSignature> {
|
|
261
|
+
try {
|
|
262
|
+
const account = this.#account;
|
|
263
|
+
if (!account) throw new WalletNotConnectedError();
|
|
264
|
+
|
|
265
|
+
let feature: typeof SolanaSignAndSendTransaction | typeof SolanaSignTransaction;
|
|
266
|
+
if (SolanaSignAndSendTransaction in this.#wallet.features) {
|
|
267
|
+
if (account.features.includes(SolanaSignAndSendTransaction)) {
|
|
268
|
+
feature = SolanaSignAndSendTransaction;
|
|
269
|
+
} else if (
|
|
270
|
+
SolanaSignTransaction in this.#wallet.features &&
|
|
271
|
+
account.features.includes(SolanaSignTransaction)
|
|
272
|
+
) {
|
|
273
|
+
feature = SolanaSignTransaction;
|
|
274
|
+
} else {
|
|
275
|
+
throw new WalletAccountError();
|
|
276
|
+
}
|
|
277
|
+
} else if (SolanaSignTransaction in this.#wallet.features) {
|
|
278
|
+
if (!account.features.includes(SolanaSignTransaction)) throw new WalletAccountError();
|
|
279
|
+
feature = SolanaSignTransaction;
|
|
280
|
+
} else {
|
|
281
|
+
throw new WalletConfigError();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const chain = getChainForEndpoint(connection.rpcEndpoint);
|
|
285
|
+
if (!account.chains.includes(chain)) throw new WalletSendTransactionError();
|
|
286
|
+
|
|
287
|
+
try {
|
|
288
|
+
const { signers, ...sendOptions } = options;
|
|
289
|
+
|
|
290
|
+
let serializedTransaction: Uint8Array;
|
|
291
|
+
if (isVersionedTransaction(transaction)) {
|
|
292
|
+
signers?.length && transaction.sign(signers);
|
|
293
|
+
serializedTransaction = transaction.serialize();
|
|
294
|
+
} else {
|
|
295
|
+
transaction = (await this.prepareTransaction(transaction, connection, sendOptions)) as T;
|
|
296
|
+
signers?.length && (transaction as Transaction).partialSign(...signers);
|
|
297
|
+
serializedTransaction = new Uint8Array(
|
|
298
|
+
(transaction as Transaction).serialize({
|
|
299
|
+
requireAllSignatures: false,
|
|
300
|
+
verifySignatures: false,
|
|
301
|
+
})
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (feature === SolanaSignAndSendTransaction) {
|
|
306
|
+
const [output] = await (this.#wallet.features as SolanaSignAndSendTransactionFeature)[
|
|
307
|
+
SolanaSignAndSendTransaction
|
|
308
|
+
].signAndSendTransaction({
|
|
309
|
+
account,
|
|
310
|
+
chain,
|
|
311
|
+
transaction: serializedTransaction,
|
|
312
|
+
options: {
|
|
313
|
+
preflightCommitment: getCommitment(
|
|
314
|
+
sendOptions.preflightCommitment || connection.commitment
|
|
315
|
+
),
|
|
316
|
+
skipPreflight: sendOptions.skipPreflight,
|
|
317
|
+
maxRetries: sendOptions.maxRetries,
|
|
318
|
+
minContextSlot: sendOptions.minContextSlot,
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
return bs58.encode(output!.signature);
|
|
323
|
+
} else {
|
|
324
|
+
const [output] = await (this.#wallet.features as SolanaSignTransactionFeature)[
|
|
325
|
+
SolanaSignTransaction
|
|
326
|
+
].signTransaction({
|
|
327
|
+
account,
|
|
328
|
+
chain,
|
|
329
|
+
transaction: serializedTransaction,
|
|
330
|
+
options: {
|
|
331
|
+
preflightCommitment: getCommitment(
|
|
332
|
+
sendOptions.preflightCommitment || connection.commitment
|
|
333
|
+
),
|
|
334
|
+
minContextSlot: sendOptions.minContextSlot,
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
return await connection.sendRawTransaction(output!.signedTransaction, {
|
|
339
|
+
...sendOptions,
|
|
340
|
+
preflightCommitment: getCommitment(sendOptions.preflightCommitment || connection.commitment),
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
} catch (error: any) {
|
|
344
|
+
if (error instanceof WalletError) throw error;
|
|
345
|
+
throw new WalletSendTransactionError(error?.message, error);
|
|
346
|
+
}
|
|
347
|
+
} catch (error: any) {
|
|
348
|
+
this.emit('error', error);
|
|
349
|
+
throw error;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
signTransaction: (<T extends Transaction | VersionedTransaction>(transaction: T) => Promise<T>) | undefined;
|
|
354
|
+
async #signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T> {
|
|
355
|
+
try {
|
|
356
|
+
const account = this.#account;
|
|
357
|
+
if (!account) throw new WalletNotConnectedError();
|
|
358
|
+
|
|
359
|
+
if (!(SolanaSignTransaction in this.#wallet.features)) throw new WalletConfigError();
|
|
360
|
+
if (!account.features.includes(SolanaSignTransaction)) throw new WalletAccountError();
|
|
361
|
+
|
|
362
|
+
try {
|
|
363
|
+
const signedTransactions = await this.#wallet.features[SolanaSignTransaction].signTransaction({
|
|
364
|
+
account,
|
|
365
|
+
transaction: isVersionedTransaction(transaction)
|
|
366
|
+
? transaction.serialize()
|
|
367
|
+
: new Uint8Array(
|
|
368
|
+
transaction.serialize({
|
|
369
|
+
requireAllSignatures: false,
|
|
370
|
+
verifySignatures: false,
|
|
371
|
+
})
|
|
372
|
+
),
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
const serializedTransaction = signedTransactions[0]!.signedTransaction;
|
|
376
|
+
|
|
377
|
+
return (
|
|
378
|
+
isVersionedTransaction(transaction)
|
|
379
|
+
? VersionedTransaction.deserialize(serializedTransaction)
|
|
380
|
+
: Transaction.from(serializedTransaction)
|
|
381
|
+
) as T;
|
|
382
|
+
} catch (error: any) {
|
|
383
|
+
if (error instanceof WalletError) throw error;
|
|
384
|
+
throw new WalletSignTransactionError(error?.message, error);
|
|
385
|
+
}
|
|
386
|
+
} catch (error: any) {
|
|
387
|
+
this.emit('error', error);
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
signAllTransactions: (<T extends Transaction | VersionedTransaction>(transaction: T[]) => Promise<T[]>) | undefined;
|
|
393
|
+
async #signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]> {
|
|
394
|
+
try {
|
|
395
|
+
const account = this.#account;
|
|
396
|
+
if (!account) throw new WalletNotConnectedError();
|
|
397
|
+
|
|
398
|
+
if (!(SolanaSignTransaction in this.#wallet.features)) throw new WalletConfigError();
|
|
399
|
+
if (!account.features.includes(SolanaSignTransaction)) throw new WalletAccountError();
|
|
400
|
+
|
|
401
|
+
try {
|
|
402
|
+
const signedTransactions = await this.#wallet.features[SolanaSignTransaction].signTransaction(
|
|
403
|
+
...transactions.map((transaction) => ({
|
|
404
|
+
account,
|
|
405
|
+
transaction: isVersionedTransaction(transaction)
|
|
406
|
+
? transaction.serialize()
|
|
407
|
+
: new Uint8Array(
|
|
408
|
+
transaction.serialize({
|
|
409
|
+
requireAllSignatures: false,
|
|
410
|
+
verifySignatures: false,
|
|
411
|
+
})
|
|
412
|
+
),
|
|
413
|
+
}))
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
return transactions.map((transaction, index) => {
|
|
417
|
+
const signedTransaction = signedTransactions[index]!.signedTransaction;
|
|
418
|
+
|
|
419
|
+
return (
|
|
420
|
+
isVersionedTransaction(transaction)
|
|
421
|
+
? VersionedTransaction.deserialize(signedTransaction)
|
|
422
|
+
: Transaction.from(signedTransaction)
|
|
423
|
+
) as T;
|
|
424
|
+
});
|
|
425
|
+
} catch (error: any) {
|
|
426
|
+
throw new WalletSignTransactionError(error?.message, error);
|
|
427
|
+
}
|
|
428
|
+
} catch (error: any) {
|
|
429
|
+
this.emit('error', error);
|
|
430
|
+
throw error;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
signMessage: ((message: Uint8Array) => Promise<Uint8Array>) | undefined;
|
|
435
|
+
async #signMessage(message: Uint8Array): Promise<Uint8Array> {
|
|
436
|
+
try {
|
|
437
|
+
const account = this.#account;
|
|
438
|
+
if (!account) throw new WalletNotConnectedError();
|
|
439
|
+
|
|
440
|
+
if (!(SolanaSignMessage in this.#wallet.features)) throw new WalletConfigError();
|
|
441
|
+
if (!account.features.includes(SolanaSignMessage)) throw new WalletAccountError();
|
|
442
|
+
|
|
443
|
+
try {
|
|
444
|
+
const signedMessages = await this.#wallet.features[SolanaSignMessage].signMessage({
|
|
445
|
+
account,
|
|
446
|
+
message,
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
return signedMessages[0]!.signature;
|
|
450
|
+
} catch (error: any) {
|
|
451
|
+
throw new WalletSignMessageError(error?.message, error);
|
|
452
|
+
}
|
|
453
|
+
} catch (error: any) {
|
|
454
|
+
this.emit('error', error);
|
|
455
|
+
throw error;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
signIn: ((input?: SolanaSignInInput) => Promise<SolanaSignInOutput>) | undefined;
|
|
460
|
+
async #signIn(input: SolanaSignInInput = {}): Promise<SolanaSignInOutput> {
|
|
461
|
+
try {
|
|
462
|
+
if (!(SolanaSignIn in this.#wallet.features)) throw new WalletConfigError();
|
|
463
|
+
|
|
464
|
+
let output: SolanaSignInOutput | undefined;
|
|
465
|
+
try {
|
|
466
|
+
[output] = await this.#wallet.features[SolanaSignIn].signIn(input);
|
|
467
|
+
} catch (error: any) {
|
|
468
|
+
throw new WalletSignInError(error?.message, error);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (!output) throw new WalletSignInError();
|
|
472
|
+
this.#connected(output.account);
|
|
473
|
+
return output;
|
|
474
|
+
} catch (error: any) {
|
|
475
|
+
this.emit('error', error);
|
|
476
|
+
throw error;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isWalletAdapterCompatibleStandardWallet,
|
|
3
|
+
type StandardWalletAdapter,
|
|
4
|
+
type WalletAdapterCompatibleStandardWallet,
|
|
5
|
+
} from '@solana/wallet-adapter-base';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `StandardWalletAdapter` from `@solana/wallet-adapter-base` instead.
|
|
9
|
+
*
|
|
10
|
+
* @group Deprecated
|
|
11
|
+
*/
|
|
12
|
+
export type StandardAdapter = StandardWalletAdapter;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `WalletAdapterCompatibleStandardWallet` from `@solana/wallet-adapter-base` instead.
|
|
16
|
+
*
|
|
17
|
+
* @group Deprecated
|
|
18
|
+
*/
|
|
19
|
+
export type WalletAdapterCompatibleWallet = WalletAdapterCompatibleStandardWallet;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use `isWalletAdapterCompatibleStandardWallet` from `@solana/wallet-adapter-base` instead.
|
|
23
|
+
*
|
|
24
|
+
* @group Deprecated
|
|
25
|
+
*/
|
|
26
|
+
export const isWalletAdapterCompatibleWallet = isWalletAdapterCompatibleStandardWallet;
|