@solana-mobile/wallet-adapter-mobile 2.2.6 → 2.2.8

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/lib/esm/index.js CHANGED
@@ -1,410 +1,341 @@
1
- import { BaseSignInMessageSignerWalletAdapter, WalletReadyState, WalletPublicKeyError, WalletNotReadyError, WalletConnectionError, WalletSignMessageError, WalletSendTransactionError, WalletNotConnectedError, WalletSignTransactionError } from '@solana/wallet-adapter-base';
2
- import { PublicKey, VersionedMessage, Transaction, VersionedTransaction } from '@solana/web3.js';
3
- import { SolanaSignIn, SolanaSignMessage, SolanaSignAndSendTransaction, SolanaSignTransaction } from '@solana/wallet-standard-features';
4
- import { StandardEvents, StandardConnect, StandardDisconnect } from '@wallet-standard/core';
5
- import { SolanaMobileWalletAdapterRemoteWalletName as SolanaMobileWalletAdapterRemoteWalletName$1, SolanaMobileWalletAdapterWalletName as SolanaMobileWalletAdapterWalletName$1, LocalSolanaMobileWalletAdapterWallet, createDefaultChainSelector, RemoteSolanaMobileWalletAdapterWallet, createDefaultAuthorizationCache, defaultErrorModalWalletNotFoundHandler } from '@solana-mobile/wallet-standard-mobile';
6
-
1
+ import { BaseSignInMessageSignerWalletAdapter, WalletConnectionError, WalletError, WalletNotConnectedError, WalletNotReadyError, WalletPublicKeyError, WalletReadyState, WalletSendTransactionError, WalletSignMessageError, WalletSignTransactionError } from "@solana/wallet-adapter-base";
2
+ import { SolanaSignAndSendTransaction, SolanaSignIn, SolanaSignMessage, SolanaSignTransaction } from "@solana/wallet-standard-features";
3
+ import { PublicKey, Transaction, VersionedMessage, VersionedTransaction } from "@solana/web3.js";
4
+ import { LocalSolanaMobileWalletAdapterWallet, RemoteSolanaMobileWalletAdapterWallet, SolanaMobileWalletAdapterRemoteWalletName as SolanaMobileWalletAdapterRemoteWalletName$1, SolanaMobileWalletAdapterWalletName as SolanaMobileWalletAdapterWalletName$1, createDefaultAuthorizationCache, createDefaultChainSelector, defaultErrorModalWalletNotFoundHandler } from "@solana-mobile/wallet-standard-mobile";
5
+ import { StandardConnect, StandardDisconnect, StandardEvents } from "@wallet-standard/core";
6
+ //#region src/base64Utils.ts
7
7
  function fromUint8Array(byteArray) {
8
- return window.btoa(String.fromCharCode.call(null, ...byteArray));
8
+ return window.btoa(String.fromCharCode.call(null, ...byteArray));
9
9
  }
10
-
10
+ //#endregion
11
+ //#region src/getIsSupported.ts
11
12
  function getIsSupported() {
12
- return (typeof window !== 'undefined' &&
13
- window.isSecureContext &&
14
- typeof document !== 'undefined' &&
15
- /android/i.test(navigator.userAgent));
13
+ return typeof window !== "undefined" && window.isSecureContext && typeof document !== "undefined" && /android/i.test(navigator.userAgent);
16
14
  }
17
-
15
+ //#endregion
16
+ //#region src/adapter.ts
18
17
  const SolanaMobileWalletAdapterWalletName = SolanaMobileWalletAdapterWalletName$1;
19
18
  const SolanaMobileWalletAdapterRemoteWalletName = SolanaMobileWalletAdapterRemoteWalletName$1;
20
19
  const SIGNATURE_LENGTH_IN_BYTES = 64;
21
20
  function isVersionedTransaction(transaction) {
22
- return 'version' in transaction;
21
+ return "version" in transaction;
23
22
  }
24
23
  function chainOrClusterToChainId(chain) {
25
- switch (chain) {
26
- case 'mainnet-beta':
27
- return 'solana:mainnet';
28
- case 'testnet':
29
- return 'solana:testnet';
30
- case 'devnet':
31
- return 'solana:devnet';
32
- default:
33
- return chain;
34
- }
35
- }
36
- class BaseSolanaMobileWalletAdapter extends BaseSignInMessageSignerWalletAdapter {
37
- supportedTransactionVersions = new Set(
38
- // FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
39
- ['legacy', 0]);
40
- name;
41
- icon;
42
- url;
43
- #wallet;
44
- #connecting = false;
45
- #readyState = getIsSupported() ? WalletReadyState.Loadable : WalletReadyState.Unsupported;
46
- #accountSelector;
47
- #selectedAccount;
48
- #publicKey;
49
- #handleChangeEvent = async (properties) => {
50
- if (properties.accounts && properties.accounts.length > 0) {
51
- this.#declareWalletAsInstalled();
52
- const nextSelectedAccount = await this.#accountSelector(properties.accounts);
53
- if (nextSelectedAccount !== this.#selectedAccount) {
54
- this.#selectedAccount = nextSelectedAccount;
55
- this.#publicKey = undefined;
56
- this.emit('connect',
57
- // Having just set `this.#selectedAccount`, `this.publicKey` is definitely non-null
58
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
59
- this.publicKey);
60
- }
61
- }
62
- };
63
- constructor(wallet, config) {
64
- super();
65
- // this.#chain = chainOrClusterToChainId(config.chain);
66
- this.#accountSelector = async (accounts) => {
67
- const selectedBase64EncodedAddress = await config.addressSelector.select(accounts.map(({ publicKey }) => fromUint8Array(new Uint8Array(publicKey))));
68
- return accounts.find(({ publicKey }) => fromUint8Array(new Uint8Array(publicKey)) === selectedBase64EncodedAddress) ?? accounts[0];
69
- };
70
- this.#wallet = wallet;
71
- this.#wallet.features[StandardEvents].on('change', this.#handleChangeEvent);
72
- this.name = this.#wallet.name;
73
- this.icon = this.#wallet.icon;
74
- this.url = this.#wallet.url;
75
- // TODO: evaluate if this logic should be kept - it seems to create a nasty bug where
76
- // the wallet tries to auto connect on page load and gets blocked by the popup blocker
77
- // if (this.#readyState !== WalletReadyState.Unsupported) {
78
- // config.authorizationResultCache.get().then((authorizationResult) => {
79
- // if (authorizationResult) {
80
- // // Having a prior authorization result is, right now, the best
81
- // // indication that a mobile wallet is installed. There is no API
82
- // // we can use to test for whether the association URI is supported.
83
- // this.#declareWalletAsInstalled();
84
- // }
85
- // });
86
- // }
87
- }
88
- get publicKey() {
89
- if (!this.#publicKey && this.#selectedAccount) {
90
- try {
91
- this.#publicKey = new PublicKey(this.#selectedAccount.publicKey);
92
- }
93
- catch (e) {
94
- throw new WalletPublicKeyError((e instanceof Error && e?.message) || 'Unknown error', e);
95
- }
96
- }
97
- return this.#publicKey ?? null;
98
- }
99
- get connected() {
100
- return this.#wallet.connected;
101
- }
102
- get connecting() {
103
- return this.#connecting;
104
- }
105
- get readyState() {
106
- return this.#readyState;
107
- }
108
- /** @deprecated Use `autoConnect()` instead. */
109
- async autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
110
- return await this.autoConnect();
111
- }
112
- async autoConnect() {
113
- this.#connect(true);
114
- }
115
- async connect() {
116
- this.#connect();
117
- }
118
- async #connect(autoConnect = false) {
119
- if (this.connecting || this.connected) {
120
- return;
121
- }
122
- return await this.#runWithGuard(async () => {
123
- if (this.#readyState !== WalletReadyState.Installed && this.#readyState !== WalletReadyState.Loadable) {
124
- throw new WalletNotReadyError();
125
- }
126
- this.#connecting = true;
127
- try {
128
- await this.#wallet.features[StandardConnect].connect({ silent: autoConnect });
129
- }
130
- catch (e) {
131
- throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
132
- }
133
- finally {
134
- this.#connecting = false;
135
- }
136
- });
137
- }
138
- /** @deprecated Use `connect()` or `autoConnect()` instead. */
139
- async performAuthorization(signInPayload) {
140
- try {
141
- const cachedAuthorizationResult = await this.#wallet.cachedAuthorizationResult;
142
- if (cachedAuthorizationResult) {
143
- await this.#wallet.features[StandardConnect].connect({ silent: true });
144
- return cachedAuthorizationResult;
145
- }
146
- if (signInPayload) {
147
- await this.#wallet.features[SolanaSignIn].signIn(signInPayload);
148
- }
149
- else
150
- await this.#wallet.features[StandardConnect].connect();
151
- const authorizationResult = await await this.#wallet.cachedAuthorizationResult;
152
- return authorizationResult;
153
- }
154
- catch (e) {
155
- throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
156
- }
157
- }
158
- async disconnect() {
159
- // return await this.#runWithGuard(this.#wallet.features[StandardDisconnect].disconnect);
160
- return await this.#runWithGuard(async () => {
161
- this.#connecting = false;
162
- this.#publicKey = undefined;
163
- this.#selectedAccount = undefined;
164
- await this.#wallet.features[StandardDisconnect].disconnect();
165
- this.emit('disconnect');
166
- });
167
- }
168
- async signIn(input) {
169
- return this.#runWithGuard(async () => {
170
- if (this.#readyState !== WalletReadyState.Installed && this.#readyState !== WalletReadyState.Loadable) {
171
- throw new WalletNotReadyError();
172
- }
173
- this.#connecting = true;
174
- try {
175
- const outputs = await this.#wallet.features[SolanaSignIn].signIn({
176
- ...input,
177
- domain: input?.domain ?? window.location.host
178
- });
179
- if (outputs.length > 0) {
180
- return outputs[0];
181
- }
182
- else {
183
- throw new Error("Sign in failed, no sign in result returned by wallet");
184
- }
185
- }
186
- catch (e) {
187
- throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
188
- }
189
- finally {
190
- this.#connecting = false;
191
- }
192
- });
193
- }
194
- async signMessage(message) {
195
- return await this.#runWithGuard(async () => {
196
- const account = this.#assertIsAuthorized();
197
- try {
198
- const outputs = await this.#wallet.features[SolanaSignMessage].signMessage({
199
- account, message: message
200
- });
201
- return outputs[0].signature;
202
- }
203
- catch (error) {
204
- throw new WalletSignMessageError(error?.message, error);
205
- }
206
- });
207
- }
208
- async sendTransaction(transaction, connection, options) {
209
- return await this.#runWithGuard(async () => {
210
- const account = this.#assertIsAuthorized();
211
- try {
212
- function getTargetCommitment() {
213
- let targetCommitment;
214
- switch (connection.commitment) {
215
- case 'confirmed':
216
- case 'finalized':
217
- case 'processed':
218
- targetCommitment = connection.commitment;
219
- break;
220
- default:
221
- targetCommitment = 'finalized';
222
- }
223
- let targetPreflightCommitment;
224
- switch (options?.preflightCommitment) {
225
- case 'confirmed':
226
- case 'finalized':
227
- case 'processed':
228
- targetPreflightCommitment = options.preflightCommitment;
229
- break;
230
- case undefined:
231
- targetPreflightCommitment = targetCommitment;
232
- break;
233
- default:
234
- targetPreflightCommitment = 'finalized';
235
- }
236
- const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
237
- ? 2
238
- : targetPreflightCommitment === 'confirmed'
239
- ? 1
240
- : 0;
241
- const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
242
- return preflightCommitmentScore < targetCommitmentScore
243
- ? targetPreflightCommitment
244
- : targetCommitment;
245
- }
246
- if (SolanaSignAndSendTransaction in this.#wallet.features) {
247
- const chain = chainOrClusterToChainId(this.#wallet.currentAuthorization.chain);
248
- const [signature] = (await this.#wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction({
249
- account,
250
- transaction: transaction.serialize(),
251
- chain: chain,
252
- options: options ? {
253
- skipPreflight: options.skipPreflight,
254
- maxRetries: options.maxRetries
255
- } : undefined
256
- })).map(((output) => {
257
- return fromUint8Array(output.signature);
258
- }));
259
- return signature;
260
- }
261
- else {
262
- const [signedTransaction] = await this.#performSignTransactions([transaction]);
263
- if (isVersionedTransaction(signedTransaction)) {
264
- return await connection.sendTransaction(signedTransaction);
265
- }
266
- else {
267
- const serializedTransaction = signedTransaction.serialize();
268
- return await connection.sendRawTransaction(serializedTransaction, {
269
- ...options,
270
- preflightCommitment: getTargetCommitment(),
271
- });
272
- }
273
- }
274
- }
275
- catch (error) {
276
- throw new WalletSendTransactionError(error?.message, error);
277
- }
278
- });
279
- }
280
- async signTransaction(transaction) {
281
- return await this.#runWithGuard(async () => {
282
- const [signedTransaction] = await this.#performSignTransactions([transaction]);
283
- return signedTransaction;
284
- });
285
- }
286
- async signAllTransactions(transactions) {
287
- return await this.#runWithGuard(async () => {
288
- const signedTransactions = await this.#performSignTransactions(transactions);
289
- return signedTransactions;
290
- });
291
- }
292
- #declareWalletAsInstalled() {
293
- if (this.#readyState !== WalletReadyState.Installed) {
294
- this.emit('readyStateChange', (this.#readyState = WalletReadyState.Installed));
295
- }
296
- }
297
- #assertIsAuthorized() {
298
- if (!this.#wallet.isAuthorized || !this.#selectedAccount)
299
- throw new WalletNotConnectedError();
300
- return this.#selectedAccount;
301
- }
302
- async #performSignTransactions(transactions) {
303
- const account = this.#assertIsAuthorized();
304
- try {
305
- if (SolanaSignTransaction in this.#wallet.features) {
306
- return this.#wallet.features[SolanaSignTransaction].signTransaction(...transactions.map((value) => {
307
- return { account, transaction: value.serialize() };
308
- })).then((outputs) => {
309
- return outputs.map((output) => {
310
- const byteArray = output.signedTransaction;
311
- const numSignatures = byteArray[0];
312
- const messageOffset = numSignatures * SIGNATURE_LENGTH_IN_BYTES + 1;
313
- const version = VersionedMessage.deserializeMessageVersion(byteArray.slice(messageOffset, byteArray.length));
314
- if (version === 'legacy') {
315
- return Transaction.from(byteArray);
316
- }
317
- else {
318
- return VersionedTransaction.deserialize(byteArray);
319
- }
320
- });
321
- });
322
- }
323
- else {
324
- throw new Error('Connected wallet does not support signing transactions');
325
- }
326
- }
327
- catch (error) {
328
- throw new WalletSignTransactionError(error?.message, error);
329
- }
330
- }
331
- async #runWithGuard(callback) {
332
- try {
333
- return await callback();
334
- }
335
- catch (e) {
336
- this.emit('error', e);
337
- throw e;
338
- }
339
- }
340
- }
341
- class LocalSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
342
- constructor(config) {
343
- const chain = chainOrClusterToChainId(config.chain ?? config.cluster);
344
- super(new LocalSolanaMobileWalletAdapterWallet({
345
- appIdentity: config.appIdentity,
346
- authorizationCache: {
347
- set: config.authorizationResultCache.set,
348
- get: async () => {
349
- return await config.authorizationResultCache.get();
350
- },
351
- clear: config.authorizationResultCache.clear,
352
- },
353
- chains: [chain],
354
- chainSelector: createDefaultChainSelector(),
355
- onWalletNotFound: async () => {
356
- config.onWalletNotFound(this);
357
- },
358
- }), {
359
- addressSelector: config.addressSelector,
360
- chain: chain,
361
- });
362
- }
363
- }
364
- class RemoteSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
365
- constructor(config) {
366
- const chain = chainOrClusterToChainId(config.chain);
367
- super(new RemoteSolanaMobileWalletAdapterWallet({
368
- appIdentity: config.appIdentity,
369
- authorizationCache: {
370
- set: config.authorizationResultCache.set,
371
- get: async () => {
372
- return await config.authorizationResultCache.get();
373
- },
374
- clear: config.authorizationResultCache.clear,
375
- },
376
- chains: [chain],
377
- chainSelector: createDefaultChainSelector(),
378
- remoteHostAuthority: config.remoteHostAuthority,
379
- onWalletNotFound: async () => {
380
- config.onWalletNotFound(this);
381
- },
382
- }), {
383
- addressSelector: config.addressSelector,
384
- chain: chain,
385
- });
386
- }
24
+ switch (chain) {
25
+ case "mainnet-beta": return "solana:mainnet";
26
+ case "testnet": return "solana:testnet";
27
+ case "devnet": return "solana:devnet";
28
+ default: return chain;
29
+ }
387
30
  }
388
- class SolanaMobileWalletAdapter extends LocalSolanaMobileWalletAdapter {
31
+ function getErrorMessage(error) {
32
+ return error instanceof Error ? error.message : "Unknown error";
389
33
  }
390
-
34
+ var BaseSolanaMobileWalletAdapter = class extends BaseSignInMessageSignerWalletAdapter {
35
+ supportedTransactionVersions = new Set(["legacy", 0]);
36
+ name;
37
+ icon;
38
+ url;
39
+ #wallet;
40
+ #connecting = false;
41
+ #readyState = getIsSupported() ? WalletReadyState.Loadable : WalletReadyState.Unsupported;
42
+ #accountSelector;
43
+ #selectedAccount;
44
+ #publicKey;
45
+ #handleChangeEvent = async (properties) => {
46
+ if (properties.accounts && properties.accounts.length > 0) {
47
+ this.#declareWalletAsInstalled();
48
+ const nextSelectedAccount = await this.#accountSelector(properties.accounts);
49
+ if (nextSelectedAccount !== this.#selectedAccount) {
50
+ this.#selectedAccount = nextSelectedAccount;
51
+ this.#publicKey = void 0;
52
+ this.emit("connect", this.publicKey);
53
+ }
54
+ }
55
+ };
56
+ constructor(wallet, config) {
57
+ super();
58
+ this.#accountSelector = async (accounts) => {
59
+ const selectedBase64EncodedAddress = await config.addressSelector.select(accounts.map(({ publicKey }) => fromUint8Array(new Uint8Array(publicKey))));
60
+ return accounts.find(({ publicKey }) => fromUint8Array(new Uint8Array(publicKey)) === selectedBase64EncodedAddress) ?? accounts[0];
61
+ };
62
+ this.#wallet = wallet;
63
+ this.#wallet.features[StandardEvents].on("change", this.#handleChangeEvent);
64
+ this.name = this.#wallet.name;
65
+ this.icon = this.#wallet.icon;
66
+ this.url = this.#wallet.url;
67
+ }
68
+ get publicKey() {
69
+ if (!this.#publicKey && this.#selectedAccount) try {
70
+ this.#publicKey = new PublicKey(this.#selectedAccount.publicKey);
71
+ } catch (e) {
72
+ throw new WalletPublicKeyError(e instanceof Error && e?.message || "Unknown error", e);
73
+ }
74
+ return this.#publicKey ?? null;
75
+ }
76
+ get connected() {
77
+ return this.#wallet.connected;
78
+ }
79
+ get connecting() {
80
+ return this.#connecting;
81
+ }
82
+ get readyState() {
83
+ return this.#readyState;
84
+ }
85
+ /** @deprecated Use `autoConnect()` instead. */
86
+ async autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
87
+ return await this.autoConnect();
88
+ }
89
+ async autoConnect() {
90
+ this.#connect(true);
91
+ }
92
+ async connect() {
93
+ this.#connect();
94
+ }
95
+ async #connect(autoConnect = false) {
96
+ if (this.connecting || this.connected) return;
97
+ return await this.#runWithGuard(async () => {
98
+ if (this.#readyState !== WalletReadyState.Installed && this.#readyState !== WalletReadyState.Loadable) throw new WalletNotReadyError();
99
+ this.#connecting = true;
100
+ try {
101
+ await this.#wallet.features[StandardConnect].connect({ silent: autoConnect });
102
+ } catch (e) {
103
+ throw new WalletConnectionError(e instanceof Error && e.message || "Unknown error", e);
104
+ } finally {
105
+ this.#connecting = false;
106
+ }
107
+ });
108
+ }
109
+ /** @deprecated Use `connect()` or `autoConnect()` instead. */
110
+ async performAuthorization(signInPayload) {
111
+ try {
112
+ const cachedAuthorizationResult = await this.#wallet.cachedAuthorizationResult;
113
+ if (cachedAuthorizationResult) {
114
+ await this.#wallet.features[StandardConnect].connect({ silent: true });
115
+ return cachedAuthorizationResult;
116
+ }
117
+ if (signInPayload) await this.#wallet.features[SolanaSignIn].signIn(signInPayload);
118
+ else await this.#wallet.features[StandardConnect].connect();
119
+ return await await this.#wallet.cachedAuthorizationResult;
120
+ } catch (e) {
121
+ throw new WalletConnectionError(e instanceof Error && e.message || "Unknown error", e);
122
+ }
123
+ }
124
+ async disconnect() {
125
+ return await this.#runWithGuard(async () => {
126
+ this.#connecting = false;
127
+ this.#publicKey = void 0;
128
+ this.#selectedAccount = void 0;
129
+ await this.#wallet.features[StandardDisconnect].disconnect();
130
+ this.emit("disconnect");
131
+ });
132
+ }
133
+ async signIn(input) {
134
+ return this.#runWithGuard(async () => {
135
+ if (this.#readyState !== WalletReadyState.Installed && this.#readyState !== WalletReadyState.Loadable) throw new WalletNotReadyError();
136
+ this.#connecting = true;
137
+ try {
138
+ const outputs = await this.#wallet.features[SolanaSignIn].signIn({
139
+ ...input,
140
+ domain: input?.domain ?? window.location.host
141
+ });
142
+ if (outputs.length > 0) return outputs[0];
143
+ else throw new Error("Sign in failed, no sign in result returned by wallet");
144
+ } catch (e) {
145
+ throw new WalletConnectionError(e instanceof Error && e.message || "Unknown error", e);
146
+ } finally {
147
+ this.#connecting = false;
148
+ }
149
+ });
150
+ }
151
+ async signMessage(message) {
152
+ return await this.#runWithGuard(async () => {
153
+ const account = this.#assertIsAuthorized();
154
+ try {
155
+ return (await this.#wallet.features[SolanaSignMessage].signMessage({
156
+ account,
157
+ message
158
+ }))[0].signature;
159
+ } catch (error) {
160
+ throw new WalletSignMessageError(getErrorMessage(error), error);
161
+ }
162
+ });
163
+ }
164
+ async sendTransaction(transaction, connection, options) {
165
+ return await this.#runWithGuard(async () => {
166
+ const account = this.#assertIsAuthorized();
167
+ try {
168
+ function getTargetCommitment() {
169
+ let targetCommitment;
170
+ switch (connection.commitment) {
171
+ case "confirmed":
172
+ case "finalized":
173
+ case "processed":
174
+ targetCommitment = connection.commitment;
175
+ break;
176
+ default: targetCommitment = "finalized";
177
+ }
178
+ let targetPreflightCommitment;
179
+ switch (options?.preflightCommitment) {
180
+ case "confirmed":
181
+ case "finalized":
182
+ case "processed":
183
+ targetPreflightCommitment = options.preflightCommitment;
184
+ break;
185
+ case void 0:
186
+ targetPreflightCommitment = targetCommitment;
187
+ break;
188
+ default: targetPreflightCommitment = "finalized";
189
+ }
190
+ return (targetPreflightCommitment === "finalized" ? 2 : targetPreflightCommitment === "confirmed" ? 1 : 0) < (targetCommitment === "finalized" ? 2 : targetCommitment === "confirmed" ? 1 : 0) ? targetPreflightCommitment : targetCommitment;
191
+ }
192
+ if (SolanaSignAndSendTransaction in this.#wallet.features) {
193
+ const chain = chainOrClusterToChainId(this.#wallet.currentAuthorization.chain);
194
+ const [signature] = (await this.#wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction({
195
+ account,
196
+ transaction: transaction.serialize(),
197
+ chain,
198
+ options: options ? {
199
+ skipPreflight: options.skipPreflight,
200
+ maxRetries: options.maxRetries
201
+ } : void 0
202
+ })).map((output) => {
203
+ return fromUint8Array(output.signature);
204
+ });
205
+ return signature;
206
+ } else {
207
+ const [signedTransaction] = await this.#performSignTransactions([transaction]);
208
+ if (isVersionedTransaction(signedTransaction)) return await connection.sendTransaction(signedTransaction);
209
+ else {
210
+ const serializedTransaction = signedTransaction.serialize();
211
+ return await connection.sendRawTransaction(serializedTransaction, {
212
+ ...options,
213
+ preflightCommitment: getTargetCommitment()
214
+ });
215
+ }
216
+ }
217
+ } catch (error) {
218
+ throw new WalletSendTransactionError(getErrorMessage(error), error);
219
+ }
220
+ });
221
+ }
222
+ async signTransaction(transaction) {
223
+ return await this.#runWithGuard(async () => {
224
+ const [signedTransaction] = await this.#performSignTransactions([transaction]);
225
+ return signedTransaction;
226
+ });
227
+ }
228
+ async signAllTransactions(transactions) {
229
+ return await this.#runWithGuard(async () => {
230
+ return await this.#performSignTransactions(transactions);
231
+ });
232
+ }
233
+ #declareWalletAsInstalled() {
234
+ if (this.#readyState !== WalletReadyState.Installed) this.emit("readyStateChange", this.#readyState = WalletReadyState.Installed);
235
+ }
236
+ #assertIsAuthorized() {
237
+ if (!this.#wallet.isAuthorized || !this.#selectedAccount) throw new WalletNotConnectedError();
238
+ return this.#selectedAccount;
239
+ }
240
+ async #performSignTransactions(transactions) {
241
+ const account = this.#assertIsAuthorized();
242
+ try {
243
+ if (SolanaSignTransaction in this.#wallet.features) return this.#wallet.features[SolanaSignTransaction].signTransaction(...transactions.map((value) => {
244
+ return {
245
+ account,
246
+ transaction: value.serialize()
247
+ };
248
+ })).then((outputs) => {
249
+ return outputs.map((output) => {
250
+ const byteArray = output.signedTransaction;
251
+ const messageOffset = byteArray[0] * SIGNATURE_LENGTH_IN_BYTES + 1;
252
+ if (VersionedMessage.deserializeMessageVersion(byteArray.slice(messageOffset, byteArray.length)) === "legacy") return Transaction.from(byteArray);
253
+ else return VersionedTransaction.deserialize(byteArray);
254
+ });
255
+ });
256
+ else throw new Error("Connected wallet does not support signing transactions");
257
+ } catch (error) {
258
+ throw new WalletSignTransactionError(getErrorMessage(error), error);
259
+ }
260
+ }
261
+ async #runWithGuard(callback) {
262
+ try {
263
+ return await callback();
264
+ } catch (e) {
265
+ this.emit("error", e instanceof WalletError ? e : new WalletError(getErrorMessage(e), e));
266
+ throw e;
267
+ }
268
+ }
269
+ };
270
+ var LocalSolanaMobileWalletAdapter = class extends BaseSolanaMobileWalletAdapter {
271
+ constructor(config) {
272
+ const chain = chainOrClusterToChainId(config.chain ?? config.cluster);
273
+ super(new LocalSolanaMobileWalletAdapterWallet({
274
+ appIdentity: config.appIdentity,
275
+ authorizationCache: {
276
+ set: config.authorizationResultCache.set,
277
+ get: async () => {
278
+ return await config.authorizationResultCache.get();
279
+ },
280
+ clear: config.authorizationResultCache.clear
281
+ },
282
+ chains: [chain],
283
+ chainSelector: createDefaultChainSelector(),
284
+ onWalletNotFound: async () => {
285
+ config.onWalletNotFound(this);
286
+ }
287
+ }), {
288
+ addressSelector: config.addressSelector,
289
+ chain
290
+ });
291
+ }
292
+ };
293
+ var RemoteSolanaMobileWalletAdapter = class extends BaseSolanaMobileWalletAdapter {
294
+ constructor(config) {
295
+ const chain = chainOrClusterToChainId(config.chain);
296
+ super(new RemoteSolanaMobileWalletAdapterWallet({
297
+ appIdentity: config.appIdentity,
298
+ authorizationCache: {
299
+ set: config.authorizationResultCache.set,
300
+ get: async () => {
301
+ return await config.authorizationResultCache.get();
302
+ },
303
+ clear: config.authorizationResultCache.clear
304
+ },
305
+ chains: [chain],
306
+ chainSelector: createDefaultChainSelector(),
307
+ remoteHostAuthority: config.remoteHostAuthority,
308
+ onWalletNotFound: async () => {
309
+ config.onWalletNotFound(this);
310
+ }
311
+ }), {
312
+ addressSelector: config.addressSelector,
313
+ chain
314
+ });
315
+ }
316
+ };
317
+ var SolanaMobileWalletAdapter = class extends LocalSolanaMobileWalletAdapter {};
318
+ //#endregion
319
+ //#region src/createDefaultAddressSelector.ts
391
320
  function createDefaultAddressSelector() {
392
- return {
393
- async select(addresses) {
394
- return addresses[0];
395
- },
396
- };
321
+ return { async select(addresses) {
322
+ return addresses[0];
323
+ } };
397
324
  }
398
-
325
+ //#endregion
326
+ //#region src/createDefaultAuthorizationResultCache.ts
399
327
  function createDefaultAuthorizationResultCache() {
400
- return createDefaultAuthorizationCache();
328
+ return createDefaultAuthorizationCache();
401
329
  }
402
-
403
- async function defaultWalletNotFoundHandler(mobileWalletAdapter) {
404
- return defaultErrorModalWalletNotFoundHandler();
330
+ //#endregion
331
+ //#region src/createDefaultWalletNotFoundHandler.ts
332
+ async function defaultWalletNotFoundHandler(_mobileWalletAdapter) {
333
+ return defaultErrorModalWalletNotFoundHandler();
405
334
  }
406
335
  function createDefaultWalletNotFoundHandler() {
407
- return defaultWalletNotFoundHandler;
336
+ return defaultWalletNotFoundHandler;
408
337
  }
409
-
338
+ //#endregion
410
339
  export { LocalSolanaMobileWalletAdapter, RemoteSolanaMobileWalletAdapter, SolanaMobileWalletAdapter, SolanaMobileWalletAdapterRemoteWalletName, SolanaMobileWalletAdapterWalletName, createDefaultAddressSelector, createDefaultAuthorizationResultCache, createDefaultWalletNotFoundHandler };
340
+
341
+ //# sourceMappingURL=index.js.map