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

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