@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,95 +1,11 @@
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
 
10
- /******************************************************************************
11
- Copyright (c) Microsoft Corporation.
12
-
13
- Permission to use, copy, modify, and/or distribute this software for any
14
- purpose with or without fee is hereby granted.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
17
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
19
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
20
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
- PERFORMANCE OF THIS SOFTWARE.
23
- ***************************************************************************** */
24
-
25
- function __awaiter(thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- }
34
-
35
- function __classPrivateFieldGet(receiver, state, kind, f) {
36
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
37
- 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");
38
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
39
- }
40
-
41
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
42
- if (kind === "m") throw new TypeError("Private method is not writable");
43
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
44
- 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");
45
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
46
- }
47
-
48
- (undefined && undefined.__classPrivateFieldSet) || function (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
- (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
55
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
56
- 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");
57
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
58
- };
59
-
60
- /** Name of the feature. */
61
- const StandardConnect = 'standard:connect';
62
-
63
- /** Name of the feature. */
64
- const StandardDisconnect = 'standard:disconnect';
65
-
66
- /** Name of the feature. */
67
- const StandardEvents = 'standard:events';
68
-
69
- (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
70
- if (kind === "m") throw new TypeError("Private method is not writable");
71
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
72
- 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");
73
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
74
- };
75
- (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
76
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
77
- 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");
78
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
79
- };
80
-
81
- (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
82
- if (kind === "m") throw new TypeError("Private method is not writable");
83
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
84
- 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");
85
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
86
- };
87
- (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
88
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
89
- 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");
90
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
91
- };
92
-
93
9
  function fromUint8Array(byteArray) {
94
10
  return window.btoa(String.fromCharCode.call(null, ...byteArray));
95
11
  }
@@ -101,7 +17,6 @@ function getIsSupported() {
101
17
  /android/i.test(navigator.userAgent));
102
18
  }
103
19
 
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
20
  const SolanaMobileWalletAdapterWalletName = walletStandardMobile.SolanaMobileWalletAdapterWalletName;
106
21
  const SolanaMobileWalletAdapterRemoteWalletName = walletStandardMobile.SolanaMobileWalletAdapterRemoteWalletName;
107
22
  const SIGNATURE_LENGTH_IN_BYTES = 64;
@@ -121,43 +36,44 @@ function chainOrClusterToChainId(chain) {
121
36
  }
122
37
  }
123
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
+ };
124
65
  constructor(wallet, config) {
125
66
  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
67
  // 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 }) => fromUint8Array(publicKey)));
154
- return (_a = accounts.find(({ publicKey }) => 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;
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;
161
77
  // TODO: evaluate if this logic should be kept - it seems to create a nasty bug where
162
78
  // the wallet tries to auto connect on page load and gets blocked by the popup blocker
163
79
  // if (this.#readyState !== WalletReadyState.Unsupported) {
@@ -172,241 +88,224 @@ class BaseSolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageS
172
88
  // }
173
89
  }
174
90
  get publicKey() {
175
- var _a;
176
- if (!__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_publicKey, "f") && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f")) {
91
+ if (!this.#publicKey && this.#selectedAccount) {
177
92
  try {
178
- __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, new web3_js.PublicKey(__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f").publicKey), "f");
93
+ this.#publicKey = new web3_js.PublicKey(this.#selectedAccount.publicKey);
179
94
  }
180
95
  catch (e) {
181
- throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
96
+ throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && e?.message) || 'Unknown error', e);
182
97
  }
183
98
  }
184
- return (_a = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_publicKey, "f")) !== null && _a !== void 0 ? _a : null;
99
+ return this.#publicKey ?? null;
185
100
  }
186
101
  get connected() {
187
- return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").connected;
102
+ return this.#wallet.connected;
188
103
  }
189
104
  get connecting() {
190
- return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_connecting, "f");
105
+ return this.#connecting;
191
106
  }
192
107
  get readyState() {
193
- return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f");
108
+ return this.#readyState;
194
109
  }
195
110
  /** @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
- });
111
+ async autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
112
+ return await this.autoConnect();
200
113
  }
201
- autoConnect() {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_connect).call(this, true);
204
- });
114
+ async autoConnect() {
115
+ this.#connect(true);
116
+ }
117
+ async connect() {
118
+ this.#connect();
205
119
  }
206
- connect() {
207
- return __awaiter(this, void 0, void 0, function* () {
208
- __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_connect).call(this);
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
+ }
209
138
  });
210
139
  }
211
140
  /** @deprecated Use `connect()` or `autoConnect()` instead. */
212
- performAuthorization(signInPayload) {
213
- return __awaiter(this, void 0, void 0, function* () {
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;
214
176
  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;
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];
219
183
  }
220
- if (signInPayload) {
221
- yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignIn].signIn(signInPayload);
184
+ else {
185
+ throw new Error("Sign in failed, no sign in result returned by wallet");
222
186
  }
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
187
  }
228
188
  catch (e) {
229
189
  throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
230
190
  }
191
+ finally {
192
+ this.#connecting = false;
193
+ }
231
194
  });
232
195
  }
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
- }));
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
+ }
243
208
  });
244
209
  }
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];
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';
257
224
  }
258
- else {
259
- throw new Error("Sign in failed, no sign in result returned by wallet");
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';
260
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;
261
247
  }
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");
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;
267
262
  }
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;
280
- }
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 fromUint8Array(output.signature);
338
- }));
339
- return signature;
263
+ else {
264
+ const [signedTransaction] = await this.#performSignTransactions([transaction]);
265
+ if (isVersionedTransaction(signedTransaction)) {
266
+ return await connection.sendTransaction(signedTransaction);
340
267
  }
341
268
  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
- }
269
+ const serializedTransaction = signedTransaction.serialize();
270
+ return await connection.sendRawTransaction(serializedTransaction, {
271
+ ...options,
272
+ preflightCommitment: getTargetCommitment(),
273
+ });
350
274
  }
351
275
  }
352
- catch (error) {
353
- throw new walletAdapterBase.WalletSendTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
354
- }
355
- }));
276
+ }
277
+ catch (error) {
278
+ throw new walletAdapterBase.WalletSendTransactionError(error?.message, error);
279
+ }
356
280
  });
357
281
  }
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
- }));
282
+ async signTransaction(transaction) {
283
+ return await this.#runWithGuard(async () => {
284
+ const [signedTransaction] = await this.#performSignTransactions([transaction]);
285
+ return signedTransaction;
364
286
  });
365
287
  }
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
- }));
288
+ async signAllTransactions(transactions) {
289
+ return await this.#runWithGuard(async () => {
290
+ const signedTransactions = await this.#performSignTransactions(transactions);
291
+ return signedTransactions;
372
292
  });
373
293
  }
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;
294
+ #declareWalletAsInstalled() {
295
+ if (this.#readyState !== walletAdapterBase.WalletReadyState.Installed) {
296
+ this.emit('readyStateChange', (this.#readyState = walletAdapterBase.WalletReadyState.Installed));
379
297
  }
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
298
  }
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);
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();
407
306
  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) => {
307
+ if (walletStandardFeatures.SolanaSignTransaction in this.#wallet.features) {
308
+ return this.#wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(...transactions.map((value) => {
410
309
  return { account, transaction: value.serialize() };
411
310
  })).then((outputs) => {
412
311
  return outputs.map((output) => {
@@ -428,38 +327,36 @@ _BaseSolanaMobileWalletAdapter_wallet = new WeakMap(), _BaseSolanaMobileWalletAd
428
327
  }
429
328
  }
430
329
  catch (error) {
431
- throw new walletAdapterBase.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
330
+ throw new walletAdapterBase.WalletSignTransactionError(error?.message, error);
432
331
  }
433
- });
434
- }, _BaseSolanaMobileWalletAdapter_runWithGuard = function _BaseSolanaMobileWalletAdapter_runWithGuard(callback) {
435
- return __awaiter(this, void 0, void 0, function* () {
332
+ }
333
+ async #runWithGuard(callback) {
436
334
  try {
437
- return yield callback();
335
+ return await callback();
438
336
  }
439
337
  catch (e) {
440
338
  this.emit('error', e);
441
339
  throw e;
442
340
  }
443
- });
444
- };
341
+ }
342
+ }
445
343
  class LocalSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
446
344
  constructor(config) {
447
- var _a;
448
- const chain = chainOrClusterToChainId((_a = config.chain) !== null && _a !== void 0 ? _a : config.cluster);
345
+ const chain = chainOrClusterToChainId(config.chain ?? config.cluster);
449
346
  super(new walletStandardMobile.LocalSolanaMobileWalletAdapterWallet({
450
347
  appIdentity: config.appIdentity,
451
348
  authorizationCache: {
452
349
  set: config.authorizationResultCache.set,
453
- get: () => __awaiter(this, void 0, void 0, function* () {
454
- return yield config.authorizationResultCache.get();
455
- }),
350
+ get: async () => {
351
+ return await config.authorizationResultCache.get();
352
+ },
456
353
  clear: config.authorizationResultCache.clear,
457
354
  },
458
355
  chains: [chain],
459
356
  chainSelector: walletStandardMobile.createDefaultChainSelector(),
460
- onWalletNotFound: () => __awaiter(this, void 0, void 0, function* () {
357
+ onWalletNotFound: async () => {
461
358
  config.onWalletNotFound(this);
462
- }),
359
+ },
463
360
  }), {
464
361
  addressSelector: config.addressSelector,
465
362
  chain: chain,
@@ -473,17 +370,17 @@ class RemoteSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
473
370
  appIdentity: config.appIdentity,
474
371
  authorizationCache: {
475
372
  set: config.authorizationResultCache.set,
476
- get: () => __awaiter(this, void 0, void 0, function* () {
477
- return yield config.authorizationResultCache.get();
478
- }),
373
+ get: async () => {
374
+ return await config.authorizationResultCache.get();
375
+ },
479
376
  clear: config.authorizationResultCache.clear,
480
377
  },
481
378
  chains: [chain],
482
379
  chainSelector: walletStandardMobile.createDefaultChainSelector(),
483
380
  remoteHostAuthority: config.remoteHostAuthority,
484
- onWalletNotFound: () => __awaiter(this, void 0, void 0, function* () {
381
+ onWalletNotFound: async () => {
485
382
  config.onWalletNotFound(this);
486
- }),
383
+ },
487
384
  }), {
488
385
  addressSelector: config.addressSelector,
489
386
  chain: chain,
@@ -495,10 +392,8 @@ class SolanaMobileWalletAdapter extends LocalSolanaMobileWalletAdapter {
495
392
 
496
393
  function createDefaultAddressSelector() {
497
394
  return {
498
- select(addresses) {
499
- return __awaiter(this, void 0, void 0, function* () {
500
- return addresses[0];
501
- });
395
+ async select(addresses) {
396
+ return addresses[0];
502
397
  },
503
398
  };
504
399
  }
@@ -507,10 +402,8 @@ function createDefaultAuthorizationResultCache() {
507
402
  return walletStandardMobile.createDefaultAuthorizationCache();
508
403
  }
509
404
 
510
- function defaultWalletNotFoundHandler(mobileWalletAdapter) {
511
- return __awaiter(this, void 0, void 0, function* () {
512
- return walletStandardMobile.defaultErrorModalWalletNotFoundHandler();
513
- });
405
+ async function defaultWalletNotFoundHandler(mobileWalletAdapter) {
406
+ return walletStandardMobile.defaultErrorModalWalletNotFoundHandler();
514
407
  }
515
408
  function createDefaultWalletNotFoundHandler() {
516
409
  return defaultWalletNotFoundHandler;