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

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,107 +1,18 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var walletAdapterBase = require('@solana/wallet-adapter-base');
6
4
  var web3_js = require('@solana/web3.js');
7
5
  var walletStandardFeatures = require('@solana/wallet-standard-features');
6
+ var core = require('@wallet-standard/core');
8
7
  var walletStandardMobile = require('@solana-mobile/wallet-standard-mobile');
9
8
  var jsBase64 = require('js-base64');
10
9
  var reactNative = require('react-native');
11
10
  var AsyncStorage = require('@react-native-async-storage/async-storage');
12
11
 
13
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
-
15
- var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
16
-
17
- /******************************************************************************
18
- Copyright (c) Microsoft Corporation.
19
-
20
- Permission to use, copy, modify, and/or distribute this software for any
21
- purpose with or without fee is hereby granted.
22
-
23
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
24
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
25
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
26
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
27
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
28
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
29
- PERFORMANCE OF THIS SOFTWARE.
30
- ***************************************************************************** */
31
-
32
- function __awaiter(thisArg, _arguments, P, generator) {
33
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
- return new (P || (P = Promise))(function (resolve, reject) {
35
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
- step((generator = generator.apply(thisArg, _arguments || [])).next());
39
- });
40
- }
41
-
42
- function __classPrivateFieldGet(receiver, state, kind, f) {
43
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
44
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
45
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
46
- }
47
-
48
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
49
- if (kind === "m") throw new TypeError("Private method is not writable");
50
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
51
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
52
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
53
- }
54
-
55
- (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
56
- if (kind === "m") throw new TypeError("Private method is not writable");
57
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
58
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
59
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
60
- };
61
- (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
62
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
63
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
64
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
65
- };
66
-
67
- /** Name of the feature. */
68
- const StandardConnect = 'standard:connect';
69
-
70
- /** Name of the feature. */
71
- const StandardDisconnect = 'standard:disconnect';
72
-
73
- /** Name of the feature. */
74
- const StandardEvents = 'standard:events';
75
-
76
- (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
77
- if (kind === "m") throw new TypeError("Private method is not writable");
78
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
79
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
80
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
81
- };
82
- (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
83
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
84
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
85
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
86
- };
87
-
88
- (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
89
- if (kind === "m") throw new TypeError("Private method is not writable");
90
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
91
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
92
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
93
- };
94
- (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
95
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
96
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
97
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
98
- };
99
-
100
12
  function getIsSupported() {
101
13
  return reactNative.Platform.OS === 'android';
102
14
  }
103
15
 
104
- var _BaseSolanaMobileWalletAdapter_instances, _BaseSolanaMobileWalletAdapter_wallet, _BaseSolanaMobileWalletAdapter_connecting, _BaseSolanaMobileWalletAdapter_readyState, _BaseSolanaMobileWalletAdapter_accountSelector, _BaseSolanaMobileWalletAdapter_selectedAccount, _BaseSolanaMobileWalletAdapter_publicKey, _BaseSolanaMobileWalletAdapter_handleChangeEvent, _BaseSolanaMobileWalletAdapter_connect, _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled, _BaseSolanaMobileWalletAdapter_assertIsAuthorized, _BaseSolanaMobileWalletAdapter_performSignTransactions, _BaseSolanaMobileWalletAdapter_runWithGuard;
105
16
  const SolanaMobileWalletAdapterWalletName = walletStandardMobile.SolanaMobileWalletAdapterWalletName;
106
17
  const SolanaMobileWalletAdapterRemoteWalletName = walletStandardMobile.SolanaMobileWalletAdapterRemoteWalletName;
107
18
  const SIGNATURE_LENGTH_IN_BYTES = 64;
@@ -121,43 +32,44 @@ function chainOrClusterToChainId(chain) {
121
32
  }
122
33
  }
123
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
+ };
124
61
  constructor(wallet, config) {
125
62
  super();
126
- _BaseSolanaMobileWalletAdapter_instances.add(this);
127
- this.supportedTransactionVersions = new Set(
128
- // FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
129
- ['legacy', 0]);
130
- _BaseSolanaMobileWalletAdapter_wallet.set(this, void 0);
131
- _BaseSolanaMobileWalletAdapter_connecting.set(this, false);
132
- _BaseSolanaMobileWalletAdapter_readyState.set(this, getIsSupported() ? walletAdapterBase.WalletReadyState.Loadable : walletAdapterBase.WalletReadyState.Unsupported);
133
- _BaseSolanaMobileWalletAdapter_accountSelector.set(this, void 0);
134
- _BaseSolanaMobileWalletAdapter_selectedAccount.set(this, void 0);
135
- _BaseSolanaMobileWalletAdapter_publicKey.set(this, void 0);
136
- _BaseSolanaMobileWalletAdapter_handleChangeEvent.set(this, (properties) => __awaiter(this, void 0, void 0, function* () {
137
- if (properties.accounts && properties.accounts.length > 0) {
138
- __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled).call(this);
139
- const nextSelectedAccount = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_accountSelector, "f").call(this, properties.accounts);
140
- if (nextSelectedAccount !== __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f")) {
141
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, nextSelectedAccount, "f");
142
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, undefined, "f");
143
- this.emit('connect',
144
- // Having just set `this.#selectedAccount`, `this.publicKey` is definitely non-null
145
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
146
- this.publicKey);
147
- }
148
- }
149
- }));
150
63
  // this.#chain = chainOrClusterToChainId(config.chain);
151
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_accountSelector, (accounts) => __awaiter(this, void 0, void 0, function* () {
152
- var _a;
153
- const selectedBase64EncodedAddress = yield config.addressSelector.select(accounts.map(({ publicKey }) => jsBase64.fromUint8Array(publicKey)));
154
- return (_a = accounts.find(({ publicKey }) => jsBase64.fromUint8Array(publicKey) === selectedBase64EncodedAddress)) !== null && _a !== void 0 ? _a : accounts[0];
155
- }), "f");
156
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_wallet, wallet, "f");
157
- __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardEvents].on('change', __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_handleChangeEvent, "f"));
158
- this.name = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").name;
159
- this.icon = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").icon;
160
- this.url = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").url;
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;
161
73
  // TODO: evaluate if this logic should be kept - it seems to create a nasty bug where
162
74
  // the wallet tries to auto connect on page load and gets blocked by the popup blocker
163
75
  // if (this.#readyState !== WalletReadyState.Unsupported) {
@@ -172,241 +84,224 @@ class BaseSolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageS
172
84
  // }
173
85
  }
174
86
  get publicKey() {
175
- var _a;
176
- if (!__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_publicKey, "f") && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f")) {
87
+ if (!this.#publicKey && this.#selectedAccount) {
177
88
  try {
178
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, new web3_js.PublicKey(__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f").publicKey), "f");
89
+ this.#publicKey = new web3_js.PublicKey(this.#selectedAccount.publicKey);
179
90
  }
180
91
  catch (e) {
181
- throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
92
+ throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && e?.message) || 'Unknown error', e);
182
93
  }
183
94
  }
184
- return (_a = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_publicKey, "f")) !== null && _a !== void 0 ? _a : null;
95
+ return this.#publicKey ?? null;
185
96
  }
186
97
  get connected() {
187
- return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").connected;
98
+ return this.#wallet.connected;
188
99
  }
189
100
  get connecting() {
190
- return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_connecting, "f");
101
+ return this.#connecting;
191
102
  }
192
103
  get readyState() {
193
- return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f");
104
+ return this.#readyState;
194
105
  }
195
106
  /** @deprecated Use `autoConnect()` instead. */
196
- autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
197
- return __awaiter(this, void 0, void 0, function* () {
198
- return yield this.autoConnect();
199
- });
107
+ async autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
108
+ return await this.autoConnect();
200
109
  }
201
- autoConnect() {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_connect).call(this, true);
204
- });
110
+ async autoConnect() {
111
+ this.#connect(true);
205
112
  }
206
- connect() {
207
- return __awaiter(this, void 0, void 0, function* () {
208
- __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_connect).call(this);
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
+ }
209
134
  });
210
135
  }
211
136
  /** @deprecated Use `connect()` or `autoConnect()` instead. */
212
- performAuthorization(signInPayload) {
213
- return __awaiter(this, void 0, void 0, function* () {
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;
214
172
  try {
215
- const cachedAuthorizationResult = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").cachedAuthorizationResult;
216
- if (cachedAuthorizationResult) {
217
- yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect({ silent: true });
218
- return cachedAuthorizationResult;
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];
219
179
  }
220
- if (signInPayload) {
221
- yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignIn].signIn(signInPayload);
180
+ else {
181
+ throw new Error("Sign in failed, no sign in result returned by wallet");
222
182
  }
223
- else
224
- yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect();
225
- const authorizationResult = yield yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").cachedAuthorizationResult;
226
- return authorizationResult;
227
183
  }
228
184
  catch (e) {
229
185
  throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
230
186
  }
187
+ finally {
188
+ this.#connecting = false;
189
+ }
231
190
  });
232
191
  }
233
- disconnect() {
234
- return __awaiter(this, void 0, void 0, function* () {
235
- // return await this.#runWithGuard(this.#wallet.features[StandardDisconnect].disconnect);
236
- return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
237
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, false, "f");
238
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, undefined, "f");
239
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, undefined, "f");
240
- yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardDisconnect].disconnect();
241
- this.emit('disconnect');
242
- }));
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
+ }
243
204
  });
244
205
  }
245
- signIn(input) {
246
- return __awaiter(this, void 0, void 0, function* () {
247
- return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
248
- var _a;
249
- if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Installed && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Loadable) {
250
- throw new walletAdapterBase.WalletNotReadyError();
251
- }
252
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, true, "f");
253
- try {
254
- const outputs = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignIn].signIn(Object.assign(Object.assign({}, input), { domain: (_a = input === null || input === void 0 ? void 0 : input.domain) !== null && _a !== void 0 ? _a : window.location.host }));
255
- if (outputs.length > 0) {
256
- return outputs[0];
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';
257
220
  }
258
- else {
259
- throw new Error("Sign in failed, no sign in result returned by wallet");
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';
260
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;
261
243
  }
262
- catch (e) {
263
- throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
264
- }
265
- finally {
266
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, false, "f");
267
- }
268
- }));
269
- });
270
- }
271
- signMessage(message) {
272
- return __awaiter(this, void 0, void 0, function* () {
273
- return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
274
- const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
275
- try {
276
- const outputs = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignMessage].signMessage({
277
- account, message: message
278
- });
279
- return outputs[0].signature;
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;
280
258
  }
281
- catch (error) {
282
- throw new walletAdapterBase.WalletSignMessageError(error === null || error === void 0 ? void 0 : error.message, error);
283
- }
284
- }));
285
- });
286
- }
287
- sendTransaction(transaction, connection, options) {
288
- return __awaiter(this, void 0, void 0, function* () {
289
- return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
290
- const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
291
- try {
292
- function getTargetCommitment() {
293
- let targetCommitment;
294
- switch (connection.commitment) {
295
- case 'confirmed':
296
- case 'finalized':
297
- case 'processed':
298
- targetCommitment = connection.commitment;
299
- break;
300
- default:
301
- targetCommitment = 'finalized';
302
- }
303
- let targetPreflightCommitment;
304
- switch (options === null || options === void 0 ? void 0 : options.preflightCommitment) {
305
- case 'confirmed':
306
- case 'finalized':
307
- case 'processed':
308
- targetPreflightCommitment = options.preflightCommitment;
309
- break;
310
- case undefined:
311
- targetPreflightCommitment = targetCommitment;
312
- break;
313
- default:
314
- targetPreflightCommitment = 'finalized';
315
- }
316
- const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
317
- ? 2
318
- : targetPreflightCommitment === 'confirmed'
319
- ? 1
320
- : 0;
321
- const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
322
- return preflightCommitmentScore < targetCommitmentScore
323
- ? targetPreflightCommitment
324
- : targetCommitment;
325
- }
326
- if (walletStandardFeatures.SolanaSignAndSendTransaction in __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features) {
327
- const chain = chainOrClusterToChainId(__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").currentAuthorization.chain);
328
- const [signature] = (yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
329
- account,
330
- transaction: transaction.serialize(),
331
- chain: chain,
332
- options: options ? {
333
- skipPreflight: options.skipPreflight,
334
- maxRetries: options.maxRetries
335
- } : undefined
336
- })).map(((output) => {
337
- return jsBase64.fromUint8Array(output.signature);
338
- }));
339
- return signature;
259
+ else {
260
+ const [signedTransaction] = await this.#performSignTransactions([transaction]);
261
+ if (isVersionedTransaction(signedTransaction)) {
262
+ return await connection.sendTransaction(signedTransaction);
340
263
  }
341
264
  else {
342
- const [signedTransaction] = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_performSignTransactions).call(this, [transaction]);
343
- if (isVersionedTransaction(signedTransaction)) {
344
- return yield connection.sendTransaction(signedTransaction);
345
- }
346
- else {
347
- const serializedTransaction = signedTransaction.serialize();
348
- return yield connection.sendRawTransaction(serializedTransaction, Object.assign(Object.assign({}, options), { preflightCommitment: getTargetCommitment() }));
349
- }
265
+ const serializedTransaction = signedTransaction.serialize();
266
+ return await connection.sendRawTransaction(serializedTransaction, {
267
+ ...options,
268
+ preflightCommitment: getTargetCommitment(),
269
+ });
350
270
  }
351
271
  }
352
- catch (error) {
353
- throw new walletAdapterBase.WalletSendTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
354
- }
355
- }));
272
+ }
273
+ catch (error) {
274
+ throw new walletAdapterBase.WalletSendTransactionError(error?.message, error);
275
+ }
356
276
  });
357
277
  }
358
- signTransaction(transaction) {
359
- return __awaiter(this, void 0, void 0, function* () {
360
- return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
361
- const [signedTransaction] = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_performSignTransactions).call(this, [transaction]);
362
- return signedTransaction;
363
- }));
278
+ async signTransaction(transaction) {
279
+ return await this.#runWithGuard(async () => {
280
+ const [signedTransaction] = await this.#performSignTransactions([transaction]);
281
+ return signedTransaction;
364
282
  });
365
283
  }
366
- signAllTransactions(transactions) {
367
- return __awaiter(this, void 0, void 0, function* () {
368
- return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
369
- const signedTransactions = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_performSignTransactions).call(this, transactions);
370
- return signedTransactions;
371
- }));
284
+ async signAllTransactions(transactions) {
285
+ return await this.#runWithGuard(async () => {
286
+ const signedTransactions = await this.#performSignTransactions(transactions);
287
+ return signedTransactions;
372
288
  });
373
289
  }
374
- }
375
- _BaseSolanaMobileWalletAdapter_wallet = new WeakMap(), _BaseSolanaMobileWalletAdapter_connecting = new WeakMap(), _BaseSolanaMobileWalletAdapter_readyState = new WeakMap(), _BaseSolanaMobileWalletAdapter_accountSelector = new WeakMap(), _BaseSolanaMobileWalletAdapter_selectedAccount = new WeakMap(), _BaseSolanaMobileWalletAdapter_publicKey = new WeakMap(), _BaseSolanaMobileWalletAdapter_handleChangeEvent = new WeakMap(), _BaseSolanaMobileWalletAdapter_instances = new WeakSet(), _BaseSolanaMobileWalletAdapter_connect = function _BaseSolanaMobileWalletAdapter_connect(autoConnect = false) {
376
- return __awaiter(this, void 0, void 0, function* () {
377
- if (this.connecting || this.connected) {
378
- return;
290
+ #declareWalletAsInstalled() {
291
+ if (this.#readyState !== walletAdapterBase.WalletReadyState.Installed) {
292
+ this.emit('readyStateChange', (this.#readyState = walletAdapterBase.WalletReadyState.Installed));
379
293
  }
380
- return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
381
- if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Installed && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Loadable) {
382
- throw new walletAdapterBase.WalletNotReadyError();
383
- }
384
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, true, "f");
385
- try {
386
- yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect({ silent: autoConnect });
387
- }
388
- catch (e) {
389
- throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
390
- }
391
- finally {
392
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, false, "f");
393
- }
394
- }));
395
- });
396
- }, _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled = function _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled() {
397
- if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Installed) {
398
- this.emit('readyStateChange', (__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_readyState, walletAdapterBase.WalletReadyState.Installed, "f")));
399
294
  }
400
- }, _BaseSolanaMobileWalletAdapter_assertIsAuthorized = function _BaseSolanaMobileWalletAdapter_assertIsAuthorized() {
401
- if (!__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").isAuthorized || !__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f"))
402
- throw new walletAdapterBase.WalletNotConnectedError();
403
- return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f");
404
- }, _BaseSolanaMobileWalletAdapter_performSignTransactions = function _BaseSolanaMobileWalletAdapter_performSignTransactions(transactions) {
405
- return __awaiter(this, void 0, void 0, function* () {
406
- const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
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();
407
302
  try {
408
- if (walletStandardFeatures.SolanaSignTransaction in __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features) {
409
- return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignTransaction].signTransaction(...transactions.map((value) => {
303
+ if (walletStandardFeatures.SolanaSignTransaction in this.#wallet.features) {
304
+ return this.#wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(...transactions.map((value) => {
410
305
  return { account, transaction: value.serialize() };
411
306
  })).then((outputs) => {
412
307
  return outputs.map((output) => {
@@ -428,38 +323,36 @@ _BaseSolanaMobileWalletAdapter_wallet = new WeakMap(), _BaseSolanaMobileWalletAd
428
323
  }
429
324
  }
430
325
  catch (error) {
431
- throw new walletAdapterBase.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
326
+ throw new walletAdapterBase.WalletSignTransactionError(error?.message, error);
432
327
  }
433
- });
434
- }, _BaseSolanaMobileWalletAdapter_runWithGuard = function _BaseSolanaMobileWalletAdapter_runWithGuard(callback) {
435
- return __awaiter(this, void 0, void 0, function* () {
328
+ }
329
+ async #runWithGuard(callback) {
436
330
  try {
437
- return yield callback();
331
+ return await callback();
438
332
  }
439
333
  catch (e) {
440
334
  this.emit('error', e);
441
335
  throw e;
442
336
  }
443
- });
444
- };
337
+ }
338
+ }
445
339
  class LocalSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
446
340
  constructor(config) {
447
- var _a;
448
- const chain = chainOrClusterToChainId((_a = config.chain) !== null && _a !== void 0 ? _a : config.cluster);
341
+ const chain = chainOrClusterToChainId(config.chain ?? config.cluster);
449
342
  super(new walletStandardMobile.LocalSolanaMobileWalletAdapterWallet({
450
343
  appIdentity: config.appIdentity,
451
344
  authorizationCache: {
452
345
  set: config.authorizationResultCache.set,
453
- get: () => __awaiter(this, void 0, void 0, function* () {
454
- return yield config.authorizationResultCache.get();
455
- }),
346
+ get: async () => {
347
+ return await config.authorizationResultCache.get();
348
+ },
456
349
  clear: config.authorizationResultCache.clear,
457
350
  },
458
351
  chains: [chain],
459
352
  chainSelector: walletStandardMobile.createDefaultChainSelector(),
460
- onWalletNotFound: () => __awaiter(this, void 0, void 0, function* () {
353
+ onWalletNotFound: async () => {
461
354
  config.onWalletNotFound(this);
462
- }),
355
+ },
463
356
  }), {
464
357
  addressSelector: config.addressSelector,
465
358
  chain: chain,
@@ -473,17 +366,17 @@ class RemoteSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
473
366
  appIdentity: config.appIdentity,
474
367
  authorizationCache: {
475
368
  set: config.authorizationResultCache.set,
476
- get: () => __awaiter(this, void 0, void 0, function* () {
477
- return yield config.authorizationResultCache.get();
478
- }),
369
+ get: async () => {
370
+ return await config.authorizationResultCache.get();
371
+ },
479
372
  clear: config.authorizationResultCache.clear,
480
373
  },
481
374
  chains: [chain],
482
375
  chainSelector: walletStandardMobile.createDefaultChainSelector(),
483
376
  remoteHostAuthority: config.remoteHostAuthority,
484
- onWalletNotFound: () => __awaiter(this, void 0, void 0, function* () {
377
+ onWalletNotFound: async () => {
485
378
  config.onWalletNotFound(this);
486
- }),
379
+ },
487
380
  }), {
488
381
  addressSelector: config.addressSelector,
489
382
  chain: chain,
@@ -495,10 +388,8 @@ class SolanaMobileWalletAdapter extends LocalSolanaMobileWalletAdapter {
495
388
 
496
389
  function createDefaultAddressSelector() {
497
390
  return {
498
- select(addresses) {
499
- return __awaiter(this, void 0, void 0, function* () {
500
- return addresses[0];
501
- });
391
+ async select(addresses) {
392
+ return addresses[0];
502
393
  },
503
394
  };
504
395
  }
@@ -506,40 +397,32 @@ function createDefaultAddressSelector() {
506
397
  const CACHE_KEY = 'SolanaMobileWalletAdapterDefaultAuthorizationCache';
507
398
  function createDefaultAuthorizationResultCache() {
508
399
  return {
509
- clear() {
510
- return __awaiter(this, void 0, void 0, function* () {
511
- try {
512
- yield AsyncStorage__default["default"].removeItem(CACHE_KEY);
513
- // eslint-disable-next-line no-empty
514
- }
515
- catch (_a) { }
516
- });
400
+ async clear() {
401
+ try {
402
+ await AsyncStorage.removeItem(CACHE_KEY);
403
+ // eslint-disable-next-line no-empty
404
+ }
405
+ catch { }
517
406
  },
518
- get() {
519
- return __awaiter(this, void 0, void 0, function* () {
520
- try {
521
- return (JSON.parse((yield AsyncStorage__default["default"].getItem(CACHE_KEY))) || undefined);
522
- // eslint-disable-next-line no-empty
523
- }
524
- catch (_a) { }
525
- });
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 { }
526
413
  },
527
- set(authorizationResult) {
528
- return __awaiter(this, void 0, void 0, function* () {
529
- try {
530
- yield AsyncStorage__default["default"].setItem(CACHE_KEY, JSON.stringify(authorizationResult));
531
- // eslint-disable-next-line no-empty
532
- }
533
- catch (_a) { }
534
- });
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 { }
535
420
  },
536
421
  };
537
422
  }
538
423
 
539
- function defaultWalletNotFoundHandler(mobileWalletAdapter) {
540
- return __awaiter(this, void 0, void 0, function* () {
541
- return walletStandardMobile.defaultErrorModalWalletNotFoundHandler();
542
- });
424
+ async function defaultWalletNotFoundHandler(mobileWalletAdapter) {
425
+ return walletStandardMobile.defaultErrorModalWalletNotFoundHandler();
543
426
  }
544
427
  function createDefaultWalletNotFoundHandler() {
545
428
  return defaultWalletNotFoundHandler;