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