@solana-mobile/wallet-adapter-mobile 2.1.5 → 2.2.2

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.
@@ -4,15 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var walletAdapterBase = require('@solana/wallet-adapter-base');
6
6
  var web3_js = require('@solana/web3.js');
7
- var mobileWalletAdapterProtocolWeb3js = require('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
7
+ var walletStandardFeatures = require('@solana/wallet-standard-features');
8
+ var walletStandardMobile = require('@solana-mobile/wallet-standard-mobile');
8
9
  var jsBase64 = require('js-base64');
9
10
  var reactNative = require('react-native');
10
- var QRCode = require('qrcode');
11
11
  var AsyncStorage = require('@react-native-async-storage/async-storage');
12
12
 
13
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
14
 
15
- var QRCode__default = /*#__PURE__*/_interopDefaultLegacy(QRCode);
16
15
  var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
17
16
 
18
17
  /******************************************************************************
@@ -38,101 +37,159 @@ function __awaiter(thisArg, _arguments, P, generator) {
38
37
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
39
38
  step((generator = generator.apply(thisArg, _arguments || [])).next());
40
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;
41
53
  }
42
54
 
43
- function getIsSupported$1() {
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
+ function getIsSupported() {
44
101
  return reactNative.Platform.OS === 'android';
45
102
  }
46
103
 
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;
47
105
  const SolanaMobileWalletAdapterWalletName = 'Mobile Wallet Adapter';
48
- const SIGNATURE_LENGTH_IN_BYTES$1 = 64;
49
- function getPublicKeyFromAddress$1(address) {
50
- const publicKeyByteArray = jsBase64.toUint8Array(address);
51
- return new web3_js.PublicKey(publicKeyByteArray);
52
- }
106
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
53
107
  function isVersionedTransaction(transaction) {
54
108
  return 'version' in transaction;
55
109
  }
56
- function clusterToChainId(cluster) {
57
- switch (cluster) {
110
+ function chainOrClusterToChainId(chain) {
111
+ switch (chain) {
58
112
  case 'mainnet-beta':
59
113
  return 'solana:mainnet';
60
114
  case 'testnet':
61
115
  return 'solana:testnet';
62
116
  case 'devnet':
63
117
  return 'solana:devnet';
118
+ default:
119
+ return chain;
64
120
  }
65
121
  }
66
- class SolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageSignerWalletAdapter {
67
- constructor(config) {
68
- var _a;
122
+ class BaseSolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageSignerWalletAdapter {
123
+ constructor(wallet, config) {
69
124
  super();
125
+ _BaseSolanaMobileWalletAdapter_instances.add(this);
70
126
  this.supportedTransactionVersions = new Set(
71
127
  // FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
72
128
  ['legacy', 0]);
73
- this.name = SolanaMobileWalletAdapterWalletName;
74
- this.url = 'https://solanamobile.com/wallets';
75
- this.icon = 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjI4IiB3aWR0aD0iMjgiIHZpZXdCb3g9Ii0zIDAgMjggMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0RDQjhGRiI+PHBhdGggZD0iTTE3LjQgMTcuNEgxNXYyLjRoMi40di0yLjRabTEuMi05LjZoLTIuNHYyLjRoMi40VjcuOFoiLz48cGF0aCBkPSJNMjEuNiAzVjBoLTIuNHYzaC0zLjZWMGgtMi40djNoLTIuNHY2LjZINC41YTIuMSAyLjEgMCAxIDEgMC00LjJoMi43VjNINC41QTQuNSA0LjUgMCAwIDAgMCA3LjVWMjRoMjEuNnYtNi42aC0yLjR2NC4ySDIuNFYxMS41Yy41LjMgMS4yLjQgMS44LjVoNy41QTYuNiA2LjYgMCAwIDAgMjQgOVYzaC0yLjRabTAgNS43YTQuMiA0LjIgMCAxIDEtOC40IDBWNS40aDguNHYzLjNaIi8+PC9nPjwvc3ZnPg==';
76
- this._connecting = false;
77
- /**
78
- * Every time the connection is recycled in some way (eg. `disconnect()` is called)
79
- * increment this and use it to make sure that `transact` calls from the previous
80
- * 'generation' don't continue to do work and throw exceptions.
81
- */
82
- this._connectionGeneration = 0;
83
- this._readyState = getIsSupported$1() ? walletAdapterBase.WalletReadyState.Loadable : walletAdapterBase.WalletReadyState.Unsupported;
84
- this._authorizationResultCache = config.authorizationResultCache;
85
- this._addressSelector = config.addressSelector;
86
- this._appIdentity = config.appIdentity;
87
- this._chain = (_a = config.chain) !== null && _a !== void 0 ? _a : clusterToChainId(config.cluster);
88
- this._hostAuthority = config.remoteHostAuthority;
89
- this._onWalletNotFound = config.onWalletNotFound;
90
- if (this._readyState !== walletAdapterBase.WalletReadyState.Unsupported) {
91
- this._authorizationResultCache.get().then((authorizationResult) => {
92
- if (authorizationResult) {
93
- // Having a prior authorization result is, right now, the best
94
- // indication that a mobile wallet is installed. There is no API
95
- // we can use to test for whether the association URI is supported.
96
- this.declareWalletAsInstalled();
129
+ _BaseSolanaMobileWalletAdapter_wallet.set(this, void 0);
130
+ _BaseSolanaMobileWalletAdapter_connecting.set(this, false);
131
+ _BaseSolanaMobileWalletAdapter_readyState.set(this, getIsSupported() ? walletAdapterBase.WalletReadyState.Loadable : walletAdapterBase.WalletReadyState.Unsupported);
132
+ _BaseSolanaMobileWalletAdapter_accountSelector.set(this, void 0);
133
+ _BaseSolanaMobileWalletAdapter_selectedAccount.set(this, void 0);
134
+ _BaseSolanaMobileWalletAdapter_publicKey.set(this, void 0);
135
+ _BaseSolanaMobileWalletAdapter_handleChangeEvent.set(this, (properties) => __awaiter(this, void 0, void 0, function* () {
136
+ if (properties.accounts && properties.accounts.length > 0) {
137
+ __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled).call(this);
138
+ const nextSelectedAccount = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_accountSelector, "f").call(this, properties.accounts);
139
+ if (nextSelectedAccount !== __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f")) {
140
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, nextSelectedAccount, "f");
141
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, undefined, "f");
142
+ this.emit('connect',
143
+ // Having just set `this.#selectedAccount`, `this.publicKey` is definitely non-null
144
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
145
+ this.publicKey);
97
146
  }
98
- });
99
- }
147
+ }
148
+ }));
149
+ // this.#chain = chainOrClusterToChainId(config.chain);
150
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_accountSelector, (accounts) => __awaiter(this, void 0, void 0, function* () {
151
+ var _a;
152
+ const selectedBase64EncodedAddress = yield config.addressSelector.select(accounts.map(({ publicKey }) => jsBase64.fromUint8Array(publicKey)));
153
+ return (_a = accounts.find(({ publicKey }) => jsBase64.fromUint8Array(publicKey) === selectedBase64EncodedAddress)) !== null && _a !== void 0 ? _a : accounts[0];
154
+ }), "f");
155
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_wallet, wallet, "f");
156
+ __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardEvents].on('change', __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_handleChangeEvent, "f"));
157
+ this.name = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").name;
158
+ this.icon = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").icon;
159
+ this.url = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").url;
160
+ // TODO: evaluate if this logic should be kept - it seems to create a nasty bug where
161
+ // the wallet tries to auto connect on page load and gets blocked by the popup blocker
162
+ // if (this.#readyState !== WalletReadyState.Unsupported) {
163
+ // config.authorizationResultCache.get().then((authorizationResult) => {
164
+ // if (authorizationResult) {
165
+ // // Having a prior authorization result is, right now, the best
166
+ // // indication that a mobile wallet is installed. There is no API
167
+ // // we can use to test for whether the association URI is supported.
168
+ // this.#declareWalletAsInstalled();
169
+ // }
170
+ // });
171
+ // }
100
172
  }
101
173
  get publicKey() {
102
- if (this._publicKey == null && this._selectedAddress != null) {
174
+ var _a;
175
+ if (!__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_publicKey, "f") && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f")) {
103
176
  try {
104
- this._publicKey = getPublicKeyFromAddress$1(this._selectedAddress);
177
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, new web3_js.PublicKey(__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f").publicKey), "f");
105
178
  }
106
179
  catch (e) {
107
180
  throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
108
181
  }
109
182
  }
110
- return this._publicKey ? this._publicKey : null;
183
+ return (_a = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_publicKey, "f")) !== null && _a !== void 0 ? _a : null;
111
184
  }
112
185
  get connected() {
113
- return !!this._authorizationResult;
186
+ return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").connected;
114
187
  }
115
188
  get connecting() {
116
- return this._connecting;
189
+ return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_connecting, "f");
117
190
  }
118
191
  get readyState() {
119
- return this._readyState;
120
- }
121
- declareWalletAsInstalled() {
122
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
123
- this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
124
- }
125
- }
126
- runWithGuard(callback) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- try {
129
- return yield callback();
130
- }
131
- catch (e) {
132
- this.emit('error', e);
133
- throw e;
134
- }
135
- });
192
+ return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f");
136
193
  }
137
194
  /** @deprecated Use `autoConnect()` instead. */
138
195
  autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
@@ -142,1066 +199,154 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageSigne
142
199
  }
143
200
  autoConnect() {
144
201
  return __awaiter(this, void 0, void 0, function* () {
145
- if (this.connecting || this.connected) {
146
- return;
147
- }
148
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
149
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
150
- throw new walletAdapterBase.WalletNotReadyError();
151
- }
152
- this._connecting = true;
153
- try {
154
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
155
- if (cachedAuthorizationResult) {
156
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
157
- this.handleAuthorizationResult(cachedAuthorizationResult);
158
- }
159
- }
160
- catch (e) {
161
- throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
162
- }
163
- finally {
164
- this._connecting = false;
165
- }
166
- }));
202
+ __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_connect).call(this, true);
167
203
  });
168
204
  }
169
205
  connect() {
170
206
  return __awaiter(this, void 0, void 0, function* () {
171
- if (this.connecting || this.connected) {
172
- return;
173
- }
174
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
175
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
176
- throw new walletAdapterBase.WalletNotReadyError();
177
- }
178
- this._connecting = true;
179
- try {
180
- yield this.performAuthorization();
181
- }
182
- catch (e) {
183
- throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
184
- }
185
- finally {
186
- this._connecting = false;
187
- }
188
- }));
207
+ __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_connect).call(this);
189
208
  });
190
209
  }
210
+ /** @deprecated Use `connect()` or `autoConnect()` instead. */
191
211
  performAuthorization(signInPayload) {
192
212
  return __awaiter(this, void 0, void 0, function* () {
193
213
  try {
194
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
214
+ const cachedAuthorizationResult = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").cachedAuthorizationResult;
195
215
  if (cachedAuthorizationResult) {
196
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
197
- this.handleAuthorizationResult(cachedAuthorizationResult);
216
+ yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect({ silent: true });
198
217
  return cachedAuthorizationResult;
199
218
  }
200
- return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
201
- const authorizationResult = yield wallet.authorize({
202
- chain: this._chain,
203
- identity: this._appIdentity,
204
- sign_in_payload: signInPayload,
205
- });
206
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
207
- Promise.all([
208
- this._authorizationResultCache.set(authorizationResult),
209
- this.handleAuthorizationResult(authorizationResult),
210
- ]);
211
- return authorizationResult;
212
- }));
213
- }
214
- catch (e) {
215
- throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
216
- }
217
- });
218
- }
219
- handleAuthorizationResult(authorizationResult) {
220
- var _a;
221
- return __awaiter(this, void 0, void 0, function* () {
222
- const didPublicKeysChange =
223
- // Case 1: We started from having no authorization.
224
- this._authorizationResult == null ||
225
- // Case 2: The number of authorized accounts changed.
226
- ((_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorizationResult.accounts.length ||
227
- // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
228
- this._authorizationResult.accounts.some((account, ii) => account.address !== authorizationResult.accounts[ii].address);
229
- this._authorizationResult = authorizationResult;
230
- this.declareWalletAsInstalled();
231
- if (didPublicKeysChange) {
232
- const nextSelectedAddress = yield this._addressSelector.select(authorizationResult.accounts.map(({ address }) => address));
233
- if (nextSelectedAddress !== this._selectedAddress) {
234
- this._selectedAddress = nextSelectedAddress;
235
- delete this._publicKey;
236
- this.emit('connect',
237
- // Having just set `this._selectedAddress`, `this.publicKey` is definitely non-null
238
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
239
- this.publicKey);
219
+ if (signInPayload) {
220
+ yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignIn].signIn(signInPayload);
240
221
  }
241
- }
242
- });
243
- }
244
- performReauthorization(wallet, authToken) {
245
- return __awaiter(this, void 0, void 0, function* () {
246
- try {
247
- const authorizationResult = yield wallet.authorize({
248
- auth_token: authToken,
249
- identity: this._appIdentity,
250
- });
251
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
252
- Promise.all([
253
- this._authorizationResultCache.set(authorizationResult),
254
- this.handleAuthorizationResult(authorizationResult),
255
- ]);
222
+ else
223
+ yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect();
224
+ const authorizationResult = yield yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").cachedAuthorizationResult;
225
+ return authorizationResult;
256
226
  }
257
227
  catch (e) {
258
- this.disconnect();
259
- throw new walletAdapterBase.WalletDisconnectedError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
228
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
260
229
  }
261
230
  });
262
231
  }
263
232
  disconnect() {
264
233
  return __awaiter(this, void 0, void 0, function* () {
265
- this._authorizationResultCache.clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
266
- this._connecting = false;
267
- this._connectionGeneration++;
268
- delete this._authorizationResult;
269
- delete this._publicKey;
270
- delete this._selectedAddress;
271
- this.emit('disconnect');
272
- });
273
- }
274
- transact(callback) {
275
- var _a;
276
- return __awaiter(this, void 0, void 0, function* () {
277
- const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.wallet_uri_base;
278
- const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
279
- const remoteConfig = this._hostAuthority ? { remoteHostAuthority: this._hostAuthority } : undefined;
280
- const currentConnectionGeneration = this._connectionGeneration;
281
- try {
282
- return yield mobileWalletAdapterProtocolWeb3js.transact(callback, Object.assign(Object.assign({}, config), remoteConfig));
283
- }
284
- catch (e) {
285
- if (this._connectionGeneration !== currentConnectionGeneration) {
286
- yield new Promise(() => { }); // Never resolve.
287
- }
288
- if (e instanceof Error &&
289
- e.name === 'SolanaMobileWalletAdapterError' &&
290
- e.code === 'ERROR_WALLET_NOT_FOUND') {
291
- yield this._onWalletNotFound(this);
292
- }
293
- throw e;
294
- }
295
- });
296
- }
297
- assertIsAuthorized() {
298
- if (!this._authorizationResult || !this._selectedAddress)
299
- throw new walletAdapterBase.WalletNotConnectedError();
300
- return {
301
- authToken: this._authorizationResult.auth_token,
302
- selectedAddress: this._selectedAddress,
303
- };
304
- }
305
- performSignTransactions(transactions) {
306
- return __awaiter(this, void 0, void 0, function* () {
307
- const { authToken } = this.assertIsAuthorized();
308
- try {
309
- return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
310
- yield this.performReauthorization(wallet, authToken);
311
- const signedTransactions = yield wallet.signTransactions({
312
- transactions,
313
- });
314
- return signedTransactions;
315
- }));
316
- }
317
- catch (error) {
318
- throw new walletAdapterBase.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
319
- }
320
- });
321
- }
322
- sendTransaction(transaction, connection, options) {
323
- return __awaiter(this, void 0, void 0, function* () {
324
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
325
- const { authToken } = this.assertIsAuthorized();
326
- const minContextSlot = options === null || options === void 0 ? void 0 : options.minContextSlot;
327
- try {
328
- return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
329
- function getTargetCommitment() {
330
- let targetCommitment;
331
- switch (connection.commitment) {
332
- case 'confirmed':
333
- case 'finalized':
334
- case 'processed':
335
- targetCommitment = connection.commitment;
336
- break;
337
- default:
338
- targetCommitment = 'finalized';
339
- }
340
- let targetPreflightCommitment;
341
- switch (options === null || options === void 0 ? void 0 : options.preflightCommitment) {
342
- case 'confirmed':
343
- case 'finalized':
344
- case 'processed':
345
- targetPreflightCommitment = options.preflightCommitment;
346
- break;
347
- case undefined:
348
- targetPreflightCommitment = targetCommitment;
349
- break;
350
- default:
351
- targetPreflightCommitment = 'finalized';
352
- }
353
- const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
354
- ? 2
355
- : targetPreflightCommitment === 'confirmed'
356
- ? 1
357
- : 0;
358
- const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
359
- return preflightCommitmentScore < targetCommitmentScore
360
- ? targetPreflightCommitment
361
- : targetCommitment;
362
- }
363
- const [capabilities, _1, _2] = yield Promise.all([
364
- wallet.getCapabilities(),
365
- this.performReauthorization(wallet, authToken),
366
- isVersionedTransaction(transaction)
367
- ? null
368
- : /**
369
- * Unlike versioned transactions, legacy `Transaction` objects
370
- * may not have an associated `feePayer` or `recentBlockhash`.
371
- * This code exists to patch them up in case they are missing.
372
- */
373
- (() => __awaiter(this, void 0, void 0, function* () {
374
- var _a;
375
- transaction.feePayer || (transaction.feePayer = (_a = this.publicKey) !== null && _a !== void 0 ? _a : undefined);
376
- if (transaction.recentBlockhash == null) {
377
- const { blockhash } = yield connection.getLatestBlockhash({
378
- commitment: getTargetCommitment(),
379
- });
380
- transaction.recentBlockhash = blockhash;
381
- }
382
- }))(),
383
- ]);
384
- if (capabilities.supports_sign_and_send_transactions) {
385
- const signatures = yield wallet.signAndSendTransactions({
386
- minContextSlot,
387
- transactions: [transaction],
388
- });
389
- return signatures[0];
390
- }
391
- else {
392
- const [signedTransaction] = yield wallet.signTransactions({
393
- transactions: [transaction],
394
- });
395
- if (isVersionedTransaction(signedTransaction)) {
396
- return yield connection.sendTransaction(signedTransaction);
397
- }
398
- else {
399
- const serializedTransaction = signedTransaction.serialize();
400
- return yield connection.sendRawTransaction(serializedTransaction, Object.assign(Object.assign({}, options), { preflightCommitment: getTargetCommitment() }));
401
- }
402
- }
403
- }));
404
- }
405
- catch (error) {
406
- throw new walletAdapterBase.WalletSendTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
407
- }
408
- }));
409
- });
410
- }
411
- signTransaction(transaction) {
412
- return __awaiter(this, void 0, void 0, function* () {
413
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
414
- const [signedTransaction] = yield this.performSignTransactions([transaction]);
415
- return signedTransaction;
416
- }));
417
- });
418
- }
419
- signAllTransactions(transactions) {
420
- return __awaiter(this, void 0, void 0, function* () {
421
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
422
- const signedTransactions = yield this.performSignTransactions(transactions);
423
- return signedTransactions;
424
- }));
425
- });
426
- }
427
- signMessage(message) {
428
- return __awaiter(this, void 0, void 0, function* () {
429
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
430
- const { authToken, selectedAddress } = this.assertIsAuthorized();
431
- try {
432
- return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
433
- yield this.performReauthorization(wallet, authToken);
434
- const [signedMessage] = yield wallet.signMessages({
435
- addresses: [selectedAddress],
436
- payloads: [message],
437
- });
438
- const signature = signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES$1);
439
- return signature;
440
- }));
441
- }
442
- catch (error) {
443
- throw new walletAdapterBase.WalletSignMessageError(error === null || error === void 0 ? void 0 : error.message, error);
444
- }
234
+ // return await this.#runWithGuard(this.#wallet.features[StandardDisconnect].disconnect);
235
+ return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
236
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, false, "f");
237
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, undefined, "f");
238
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, undefined, "f");
239
+ yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardDisconnect].disconnect();
240
+ this.emit('disconnect');
445
241
  }));
446
242
  });
447
243
  }
448
244
  signIn(input) {
449
245
  return __awaiter(this, void 0, void 0, function* () {
450
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
451
- var _a, _b;
452
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
246
+ return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
247
+ var _a;
248
+ if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Installed && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Loadable) {
453
249
  throw new walletAdapterBase.WalletNotReadyError();
454
250
  }
455
- this._connecting = true;
251
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, true, "f");
456
252
  try {
457
- const authorizationResult = yield this.performAuthorization(Object.assign(Object.assign({}, input), { domain: (_a = input === null || input === void 0 ? void 0 : input.domain) !== null && _a !== void 0 ? _a : window.location.host }));
458
- if (!authorizationResult.sign_in_result) {
459
- throw new Error("Sign in failed, no sign in result returned by wallet");
253
+ 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 }));
254
+ if (outputs.length > 0) {
255
+ return outputs[0];
460
256
  }
461
- const signedInAddress = authorizationResult.sign_in_result.address;
462
- const signedInAccount = Object.assign(Object.assign({}, (_b = authorizationResult.accounts.find(acc => acc.address == signedInAddress)) !== null && _b !== void 0 ? _b : {
463
- address: signedInAddress
464
- }), { publicKey: jsBase64.toUint8Array(signedInAddress) });
465
- return {
466
- account: signedInAccount,
467
- signedMessage: jsBase64.toUint8Array(authorizationResult.sign_in_result.signed_message),
468
- signature: jsBase64.toUint8Array(authorizationResult.sign_in_result.signature)
469
- };
470
- }
471
- catch (e) {
472
- throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
473
- }
474
- finally {
475
- this._connecting = false;
476
- }
477
- }));
478
- });
479
- }
480
- }
481
-
482
- const BluetoothHtml = `
483
- <div class="mobile-wallet-adapter-embedded-modal-content">
484
- <button id="mobile-wallet-adapter-embedded-modal-close" class="mobile-wallet-adapter-embedded-modal-close">
485
- <svg width="14" height="14">
486
- <path d="M14 12.461 8.3 6.772l5.234-5.233L12.006 0 6.772 5.234 1.54 0 0 1.539l5.234 5.233L0 12.006l1.539 1.528L6.772 8.3l5.69 5.7L14 12.461z" />
487
- </svg>
488
- </button>
489
- <h1><b>Jupiter</b> wants to connect</h1>
490
- <p class="mobile-wallet-adapter-embedded-modal-subtitle">Connect to your mobile wallet app through Bluetooth.</p>
491
- <div class="mobile-wallet-adapter-embedded-modal-connection-status-container">
492
- <div id="status-not-connected" class="connection-status">
493
- <svg class="bluetooth-icon" width="24" height="24" viewBox="0 0 24 24">
494
- <path fill="#a0a0a0" d="M14.24 12.01l2.32 2.32c.28-.72.44-1.51.44-2.33 0-.82-.16-1.59-.43-2.31l-2.33 2.32zm5.29-5.3l-1.26 1.26c.63 1.21.98 2.57.98 4.02s-.36 2.82-.98 4.02l1.2 1.2c.97-1.54 1.54-3.36 1.54-5.31-.01-1.89-.55-3.67-1.48-5.19zm-3.82 1L10 2H9v7.59L4.41 5 3 6.41 8.59 12 3 17.59 4.41 19 9 14.41V22h1l5.71-5.71-4.3-4.29 4.3-4.29zM11 5.83l1.88 1.88L11 9.59V5.83zm1.88 10.46L11 18.17v-3.76l1.88 1.88z"/>
495
- </svg>
496
- <p>Not connected</p>
497
- </div>
498
- <div id="status-connecting" class="connection-status" style="display:none;">
499
- <div class="spinner"></div>
500
- <p>Connecting...</p>
501
- </div>
502
- <div id="status-connected" class="connection-status" style="display:none;">
503
- <svg class="checkmark-icon" width="24" height="24" viewBox="0 0 24 24">
504
- <path fill="#4CAF50" d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/>
505
- </svg>
506
- <p>Connected</p>
507
- </div>
508
- </div>
509
- <div class="button-group">
510
- <button id="cancel-btn" class="cancel-btn">Cancel</button>
511
- <button id="connect-btn" class="connect-btn">Connect</button>
512
- </div>
513
- </div>
514
- `;
515
-
516
- const QRCodeHtml = `
517
- <div class="mobile-wallet-adapter-embedded-modal-content">
518
- <button id="mobile-wallet-adapter-embedded-modal-close" class="mobile-wallet-adapter-embedded-modal-close">
519
- <svg width="14" height="14">
520
- <path d="M14 12.461 8.3 6.772l5.234-5.233L12.006 0 6.772 5.234 1.54 0 0 1.539l5.234 5.233L0 12.006l1.539 1.528L6.772 8.3l5.69 5.7L14 12.461z" />
521
- </svg>
522
- </button>
523
- <h1>Scan to connect</h1>
524
- <p class="mobile-wallet-adapter-embedded-modal-subtitle">Use your wallet app to scan the QR Code and connect.</p>
525
- <div id="mobile-wallet-adapter-embedded-modal-qr-code-container" />
526
- </div>
527
- `;
528
-
529
- const css = `
530
- .mobile-wallet-adapter-embedded-modal {
531
- display: flex; /* Use flexbox to center content */
532
- flex-direction: column;
533
- justify-content: center; /* Center horizontally */
534
- align-items: center; /* Center vertically */
535
- position: fixed; /* Stay in place */
536
- z-index: 1; /* Sit on top */
537
- left: 0;
538
- top: 0;
539
- width: 100%; /* Full width */
540
- height: 100%; /* Full height */
541
- background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
542
- }
543
-
544
- .mobile-wallet-adapter-embedded-modal-content {
545
- background: #10141f;
546
- padding: 20px;
547
- border-radius: 10px;
548
- width: 80%;
549
- max-width: 500px;
550
- text-align: center;
551
- position: relative;
552
- display: flex;
553
- flex-direction: column;
554
- align-items: center; /* Center children horizontally */
555
- }
556
-
557
- .mobile-wallet-adapter-embedded-modal-subtitle {
558
- color: #D8D8D8;
559
- }
560
-
561
- .mobile-wallet-adapter-embedded-modal-close {
562
- display: flex;
563
- align-items: center;
564
- justify-content: center;
565
- position: absolute;
566
- top: 18px;
567
- right: 18px;
568
- padding: 12px;
569
- cursor: pointer;
570
- background: #1a1f2e;
571
- border: none;
572
- border-radius: 50%;
573
- }
574
-
575
- .mobile-wallet-adapter-embedded-modal-close:focus-visible {
576
- outline-color: white;
577
- }
578
-
579
- .mobile-wallet-adapter-embedded-modal-close svg {
580
- fill: #777;
581
- transition: fill 200ms ease 0s;
582
- }
583
-
584
- .mobile-wallet-adapter-embedded-modal-close:hover svg {
585
- fill: #fff;
586
- }
587
-
588
- .icon-container {
589
- display: flex;
590
- justify-content: center;
591
- margin-bottom: 20px;
592
- }
593
-
594
- .icon {
595
- width: 80px;
596
- height: 80px;
597
- border-radius: 50%;
598
- background-color: #ddd; /* Placeholder for icon background */
599
- }
600
-
601
- /* Modal Title */
602
- .mobile-wallet-adapter-embedded-modal-content h1 {
603
- color: white;
604
- font-size: 24px;
605
- }
606
-
607
- .button-group {
608
- display: flex;
609
- width: 100%;
610
- gap: 10px;
611
- }
612
-
613
- .connect-btn, .cancel-btn {
614
- flex: 1;
615
- padding: 12px 20px;
616
- font-size: 16px;
617
- cursor: pointer;
618
- border-radius: 10px;
619
- transition: all 0.3s ease;
620
- }
621
-
622
- .connect-btn {
623
- background-color: #007bff;
624
- color: white;
625
- border: none;
626
- }
627
-
628
- .connect-btn:hover {
629
- background-color: #0056b3;
630
- }
631
-
632
- .cancel-btn {
633
- background-color: transparent;
634
- color: #a0a0a0;
635
- border: 1px solid #a0a0a0;
636
- }
637
-
638
- .cancel-btn:hover {
639
- background-color: rgba(160, 160, 160, 0.1);
640
- }
641
-
642
- /* BT Connection Status */
643
-
644
- .mobile-wallet-adapter-embedded-modal-connection-status-container {
645
- margin: 20px 0px 20px 0px;
646
- }
647
-
648
- .connection-status {
649
- display: flex;
650
- flex-direction: column;
651
- align-items: center;
652
- justify-content: center;
653
- margin: 20px 0;
654
- }
655
-
656
- .connection-status p {
657
- margin-top: 10px;
658
- color: #a0a0a0;
659
- }
660
-
661
- .bluetooth-icon, .checkmark-icon {
662
- width: 48px;
663
- height: 48px;
664
- }
665
-
666
- .spinner {
667
- border: 4px solid #f3f3f3;
668
- border-top: 4px solid #3498db;
669
- border-radius: 50%;
670
- width: 40px;
671
- height: 40px;
672
- animation: spin 1s linear infinite;
673
- }
674
-
675
- @keyframes spin {
676
- 0% { transform: rotate(0deg); }
677
- 100% { transform: rotate(360deg); }
678
- }
679
-
680
- /* QR Code */
681
-
682
- #mobile-wallet-adapter-embedded-modal-qr-code-container {
683
- width: 500px;
684
- height: 500px;
685
- align-content: center;
686
- }
687
- `;
688
-
689
- class EmbeddedModal {
690
- constructor(title) {
691
- this._root = null;
692
- this._title = title;
693
- // Bind methods to ensure `this` context is correct
694
- this.init = this.init.bind(this);
695
- this.injectQRCodeHTML = this.injectQRCodeHTML.bind(this);
696
- this.injectBluetoothHTML = this.injectBluetoothHTML.bind(this);
697
- this.open = this.open.bind(this);
698
- this.close = this.close.bind(this);
699
- this.connect = this.connect.bind(this);
700
- this._root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
701
- }
702
- init(qrCode) {
703
- return __awaiter(this, void 0, void 0, function* () {
704
- console.log('Injecting modal');
705
- this.injectStyles();
706
- this.injectQRCodeHTML(qrCode);
707
- });
708
- }
709
- setConnectionStatus(status) {
710
- if (!this._root)
711
- return;
712
- const statuses = ['not-connected', 'connecting', 'connected'];
713
- statuses.forEach((s) => {
714
- const el = this._root.querySelector(`#status-${s}`);
715
- if (el instanceof HTMLElement) {
716
- el.style.display = s === status ? 'flex' : 'none';
717
- }
718
- });
719
- }
720
- injectStyles() {
721
- // Check if the styles have already been injected
722
- if (document.getElementById('mobile-wallet-adapter-styles')) {
723
- return;
724
- }
725
- const styleElement = document.createElement('style');
726
- styleElement.id = 'mobile-wallet-adapter-styles';
727
- styleElement.textContent = css;
728
- document.head.appendChild(styleElement);
729
- }
730
- populateQRCode(qrUrl) {
731
- return __awaiter(this, void 0, void 0, function* () {
732
- const qrcodeContainer = document.getElementById('mobile-wallet-adapter-embedded-modal-qr-code-container');
733
- if (qrcodeContainer) {
734
- const qrCodeElement = yield QRCode__default["default"].toCanvas(qrUrl, { width: 400 });
735
- if (qrcodeContainer.firstElementChild !== null) {
736
- qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
737
- }
738
- else
739
- qrcodeContainer.appendChild(qrCodeElement);
740
- }
741
- else {
742
- console.error('QRCode Container not found');
743
- }
744
- });
745
- }
746
- injectQRCodeHTML(qrCode) {
747
- // Check if the HTML has already been injected
748
- if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
749
- if (!this._root)
750
- this._root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
751
- this.populateQRCode(qrCode);
752
- return;
753
- }
754
- // Create a container for the modal
755
- this._root = document.createElement('div');
756
- this._root.id = 'mobile-wallet-adapter-embedded-root-ui';
757
- this._root.className = 'mobile-wallet-adapter-embedded-modal';
758
- this._root.innerHTML = QRCodeHtml;
759
- this._root.style.display = 'none';
760
- // Append the modal to the body
761
- document.body.appendChild(this._root);
762
- // Render the QRCode
763
- this.populateQRCode(qrCode);
764
- this.attachEventListeners();
765
- }
766
- injectBluetoothHTML() {
767
- // Check if the HTML has already been injected
768
- if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
769
- return;
770
- }
771
- this._root = document.createElement('div');
772
- this._root.id = 'mobile-wallet-adapter-embedded-root-ui';
773
- this._root.className = 'mobile-wallet-adapter-embedded-modal';
774
- this._root.innerHTML = BluetoothHtml;
775
- document.body.appendChild(this._root);
776
- this.attachEventListeners();
777
- }
778
- attachEventListeners() {
779
- if (!this._root)
780
- return;
781
- const closeBtn = this._root.querySelector('#mobile-wallet-adapter-embedded-modal-close');
782
- const cancelBtn = this._root.querySelector('#cancel-btn');
783
- const connectBtn = this._root.querySelector('#connect-btn');
784
- closeBtn === null || closeBtn === void 0 ? void 0 : closeBtn.addEventListener('click', () => this.close());
785
- cancelBtn === null || cancelBtn === void 0 ? void 0 : cancelBtn.addEventListener('click', () => this.close());
786
- connectBtn === null || connectBtn === void 0 ? void 0 : connectBtn.addEventListener('click', () => this.connect());
787
- }
788
- open() {
789
- console.debug('Modal open');
790
- if (this._root) {
791
- this._root.style.display = 'flex';
792
- this.setConnectionStatus('not-connected'); // Reset status when opening
793
- }
794
- }
795
- close() {
796
- console.debug('Modal close');
797
- if (this._root) {
798
- this._root.style.display = 'none';
799
- this.setConnectionStatus('not-connected'); // Reset status when closing
800
- }
801
- }
802
- connect() {
803
- console.log('Connecting...');
804
- // Mock connection
805
- this.setConnectionStatus('connecting');
806
- // Simulate connection process
807
- setTimeout(() => {
808
- this.setConnectionStatus('connected');
809
- console.log('Connected!');
810
- }, 5000); // 5 seconds delay
811
- }
812
- }
813
-
814
- const SolanaMobileWalletAdapterRemoteWalletName = 'MWA (Remote)';
815
- const SIGNATURE_LENGTH_IN_BYTES = 64;
816
- function getPublicKeyFromAddress(address) {
817
- const publicKeyByteArray = jsBase64.toUint8Array(address);
818
- return new web3_js.PublicKey(publicKeyByteArray);
819
- }
820
- /**
821
- * Determine the mobile operating system.
822
- * Returns true if running on a mobile operating system, or false otherwise.
823
- *
824
- * @returns {boolean}
825
- */
826
- function isMobileOperatingSystem() {
827
- var userAgent = navigator.userAgent;
828
- // Windows Phone must come first because its UA also contains "Android"
829
- if (/windows phone/i.test(userAgent)) {
830
- return true;
831
- }
832
- if (/android/i.test(userAgent)) {
833
- return true;
834
- }
835
- // iOS detection from: http://stackoverflow.com/a/9039885/177710
836
- if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
837
- return true;
838
- }
839
- return false;
840
- }
841
- function getIsSupported() {
842
- return (typeof window !== 'undefined' &&
843
- window.isSecureContext &&
844
- typeof document !== 'undefined' &&
845
- !isMobileOperatingSystem());
846
- }
847
- /**
848
- * This burner wallet adapter is unsafe to use and is only included to provide an easy way for applications to test
849
- * Wallet Adapter without using a third-party wallet.
850
- */
851
- class SolanaMobileWalletAdapterRemote extends walletAdapterBase.BaseSignInMessageSignerWalletAdapter {
852
- constructor(config) {
853
- super();
854
- this.supportedTransactionVersions = new Set(
855
- // FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
856
- ['legacy', 0]);
857
- this.name = SolanaMobileWalletAdapterRemoteWalletName;
858
- this.url = 'https://solanamobile.com/wallets';
859
- this.icon = 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjI4IiB3aWR0aD0iMjgiIHZpZXdCb3g9Ii0zIDAgMjggMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0RDQjhGRiI+PHBhdGggZD0iTTE3LjQgMTcuNEgxNXYyLjRoMi40di0yLjRabTEuMi05LjZoLTIuNHYyLjRoMi40VjcuOFoiLz48cGF0aCBkPSJNMjEuNiAzVjBoLTIuNHYzaC0zLjZWMGgtMi40djNoLTIuNHY2LjZINC41YTIuMSAyLjEgMCAxIDEgMC00LjJoMi43VjNINC41QTQuNSA0LjUgMCAwIDAgMCA3LjVWMjRoMjEuNnYtNi42aC0yLjR2NC4ySDIuNFYxMS41Yy41LjMgMS4yLjQgMS44LjVoNy41QTYuNiA2LjYgMCAwIDAgMjQgOVYzaC0yLjRabTAgNS43YTQuMiA0LjIgMCAxIDEtOC40IDBWNS40aDguNHYzLjNaIi8+PC9nPjwvc3ZnPg==';
860
- this._connecting = false;
861
- /**
862
- * Every time the connection is recycled in some way (eg. `disconnect()` is called)
863
- * increment this and use it to make sure that `transact` calls from the previous
864
- * 'generation' don't continue to do work and throw exceptions.
865
- */
866
- this._connectionGeneration = 0;
867
- this._readyState = getIsSupported() ? walletAdapterBase.WalletReadyState.Loadable : walletAdapterBase.WalletReadyState.Unsupported;
868
- this._authorizationResultCache = config.authorizationResultCache;
869
- this._addressSelector = config.addressSelector;
870
- this._appIdentity = config.appIdentity;
871
- this._chain = config.chain;
872
- this._hostAuthority = config.remoteHostAuthority;
873
- this._onWalletNotFound = config.onWalletNotFound;
874
- if (this._readyState !== walletAdapterBase.WalletReadyState.Unsupported) {
875
- this._authorizationResultCache.get().then((authorizationResult) => {
876
- if (authorizationResult) {
877
- // Having a prior authorization result is, right now, the best
878
- // indication that a mobile wallet is installed. There is no API
879
- // we can use to test for whether the association URI is supported.
880
- this.declareWalletAsInstalled();
881
- }
882
- });
883
- }
884
- }
885
- get publicKey() {
886
- if (this._publicKey == null && this._selectedAddress != null) {
887
- try {
888
- this._publicKey = getPublicKeyFromAddress(this._selectedAddress);
889
- }
890
- catch (e) {
891
- throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
892
- }
893
- }
894
- return this._publicKey ? this._publicKey : null;
895
- }
896
- get connected() {
897
- return !!this._authorizationResult;
898
- }
899
- get connecting() {
900
- return this._connecting;
901
- }
902
- get readyState() {
903
- return this._readyState;
904
- }
905
- declareWalletAsInstalled() {
906
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
907
- this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
908
- }
909
- }
910
- runWithGuard(callback) {
911
- return __awaiter(this, void 0, void 0, function* () {
912
- try {
913
- return yield callback();
914
- }
915
- catch (e) {
916
- this.emit('error', e);
917
- throw e;
918
- }
919
- });
920
- }
921
- autoConnect() {
922
- return __awaiter(this, void 0, void 0, function* () {
923
- if (this.connecting || this.connected) {
924
- return;
925
- }
926
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
927
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
928
- throw new walletAdapterBase.WalletNotReadyError();
929
- }
930
- this._connecting = true;
931
- try {
932
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
933
- if (cachedAuthorizationResult) {
934
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
935
- this.handleAuthorizationResult(cachedAuthorizationResult);
257
+ else {
258
+ throw new Error("Sign in failed, no sign in result returned by wallet");
936
259
  }
937
260
  }
938
261
  catch (e) {
939
262
  throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
940
263
  }
941
264
  finally {
942
- this._connecting = false;
265
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, false, "f");
943
266
  }
944
267
  }));
945
268
  });
946
269
  }
947
- connect() {
270
+ signMessage(message) {
948
271
  return __awaiter(this, void 0, void 0, function* () {
949
- if (this.connecting || this.connected) {
950
- return;
951
- }
952
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
953
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
954
- throw new walletAdapterBase.WalletNotReadyError();
955
- }
956
- this._connecting = true;
272
+ return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
273
+ const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
957
274
  try {
958
- yield this.performAuthorization();
959
- }
960
- catch (e) {
961
- throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
962
- }
963
- finally {
964
- this._connecting = false;
965
- }
966
- }));
967
- });
968
- }
969
- performAuthorization(signInPayload) {
970
- return __awaiter(this, void 0, void 0, function* () {
971
- try {
972
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
973
- if (cachedAuthorizationResult) {
974
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
975
- this.handleAuthorizationResult(cachedAuthorizationResult);
976
- return cachedAuthorizationResult;
977
- }
978
- if (this._wallet)
979
- delete this._wallet;
980
- return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
981
- this._wallet = wallet;
982
- const authorizationResult = yield wallet.authorize({
983
- chain: this._chain,
984
- identity: this._appIdentity,
985
- sign_in_payload: signInPayload,
275
+ const outputs = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignMessage].signMessage({
276
+ account, message: message
986
277
  });
987
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
988
- Promise.all([
989
- this._authorizationResultCache.set(authorizationResult),
990
- this.handleAuthorizationResult(authorizationResult),
991
- ]);
992
- return authorizationResult;
993
- }));
994
- }
995
- catch (e) {
996
- throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
997
- }
998
- });
999
- }
1000
- handleAuthorizationResult(authorizationResult) {
1001
- var _a;
1002
- return __awaiter(this, void 0, void 0, function* () {
1003
- const didPublicKeysChange =
1004
- // Case 1: We started from having no authorization.
1005
- this._authorizationResult == null ||
1006
- // Case 2: The number of authorized accounts changed.
1007
- ((_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorizationResult.accounts.length ||
1008
- // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
1009
- this._authorizationResult.accounts.some((account, ii) => account.address !== authorizationResult.accounts[ii].address);
1010
- this._authorizationResult = authorizationResult;
1011
- this.declareWalletAsInstalled();
1012
- if (didPublicKeysChange) {
1013
- const nextSelectedAddress = yield this._addressSelector.select(authorizationResult.accounts.map(({ address }) => address));
1014
- if (nextSelectedAddress !== this._selectedAddress) {
1015
- this._selectedAddress = nextSelectedAddress;
1016
- delete this._publicKey;
1017
- this.emit('connect',
1018
- // Having just set `this._selectedAddress`, `this.publicKey` is definitely non-null
1019
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1020
- this.publicKey);
1021
- }
1022
- }
1023
- });
1024
- }
1025
- performReauthorization(wallet, authToken) {
1026
- return __awaiter(this, void 0, void 0, function* () {
1027
- try {
1028
- const authorizationResult = yield wallet.authorize({
1029
- auth_token: authToken,
1030
- identity: this._appIdentity,
1031
- });
1032
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1033
- Promise.all([
1034
- this._authorizationResultCache.set(authorizationResult),
1035
- this.handleAuthorizationResult(authorizationResult),
1036
- ]);
1037
- }
1038
- catch (e) {
1039
- this.disconnect();
1040
- throw new walletAdapterBase.WalletDisconnectedError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
1041
- }
1042
- });
1043
- }
1044
- disconnect() {
1045
- var _a;
1046
- return __awaiter(this, void 0, void 0, function* () {
1047
- // TODO: figure out why this call throws "TypeError: _a.terminateSession is not a function"
1048
- // even though the session termination is actually executed (websocket closes).
1049
- try {
1050
- (_a = this._wallet) === null || _a === void 0 ? void 0 : _a.terminateSession();
1051
- }
1052
- catch (e) { }
1053
- this._authorizationResultCache.clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1054
- this._connecting = false;
1055
- this._connectionGeneration++;
1056
- delete this._authorizationResult;
1057
- delete this._publicKey;
1058
- delete this._selectedAddress;
1059
- delete this._wallet;
1060
- this.emit('disconnect');
1061
- });
1062
- }
1063
- transact(callback) {
1064
- var _a;
1065
- return __awaiter(this, void 0, void 0, function* () {
1066
- const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.wallet_uri_base;
1067
- const baseConfig = walletUriBase ? { baseUri: walletUriBase } : undefined;
1068
- const remoteConfig = Object.assign(Object.assign({}, baseConfig), { remoteHostAuthority: this._hostAuthority });
1069
- const currentConnectionGeneration = this._connectionGeneration;
1070
- const modal = new EmbeddedModal('MWA QR');
1071
- if (this._wallet) {
1072
- return callback(this._wallet);
1073
- }
1074
- try {
1075
- const { associationUrl, result: promise } = yield mobileWalletAdapterProtocolWeb3js.transactRemote((wallet) => __awaiter(this, void 0, void 0, function* () {
1076
- const result = yield callback(wallet);
1077
- modal.close();
1078
- return result;
1079
- }), remoteConfig);
1080
- modal.init(associationUrl.toString());
1081
- modal.open();
1082
- return yield promise;
1083
- }
1084
- catch (e) {
1085
- modal.close();
1086
- if (this._connectionGeneration !== currentConnectionGeneration) {
1087
- yield new Promise(() => { }); // Never resolve.
278
+ return outputs[0].signature;
1088
279
  }
1089
- if (e instanceof Error &&
1090
- e.name === 'SolanaMobileWalletAdapterError' &&
1091
- e.code === 'ERROR_WALLET_NOT_FOUND') {
1092
- yield this._onWalletNotFound(this);
280
+ catch (error) {
281
+ throw new walletAdapterBase.WalletSignMessageError(error === null || error === void 0 ? void 0 : error.message, error);
1093
282
  }
1094
- throw e;
1095
- }
1096
- });
1097
- }
1098
- assertIsAuthorized() {
1099
- if (!this._authorizationResult || !this._selectedAddress)
1100
- throw new walletAdapterBase.WalletNotConnectedError();
1101
- return {
1102
- authToken: this._authorizationResult.auth_token,
1103
- selectedAddress: this._selectedAddress,
1104
- };
1105
- }
1106
- performSignTransactions(transactions) {
1107
- return __awaiter(this, void 0, void 0, function* () {
1108
- const { authToken } = this.assertIsAuthorized();
1109
- try {
1110
- return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
1111
- yield this.performReauthorization(wallet, authToken);
1112
- const signedTransactions = yield wallet.signTransactions({
1113
- transactions,
1114
- });
1115
- return signedTransactions;
1116
- }));
1117
- }
1118
- catch (error) {
1119
- throw new walletAdapterBase.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
1120
- }
283
+ }));
1121
284
  });
1122
285
  }
1123
286
  sendTransaction(transaction, connection, options) {
1124
287
  return __awaiter(this, void 0, void 0, function* () {
1125
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
1126
- const { authToken } = this.assertIsAuthorized();
1127
- const minContextSlot = options === null || options === void 0 ? void 0 : options.minContextSlot;
288
+ return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
289
+ const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
1128
290
  try {
1129
- return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
1130
- function getTargetCommitment() {
1131
- let targetCommitment;
1132
- switch (connection.commitment) {
1133
- case 'confirmed':
1134
- case 'finalized':
1135
- case 'processed':
1136
- targetCommitment = connection.commitment;
1137
- break;
1138
- default:
1139
- targetCommitment = 'finalized';
1140
- }
1141
- let targetPreflightCommitment;
1142
- switch (options === null || options === void 0 ? void 0 : options.preflightCommitment) {
1143
- case 'confirmed':
1144
- case 'finalized':
1145
- case 'processed':
1146
- targetPreflightCommitment = options.preflightCommitment;
1147
- break;
1148
- case undefined:
1149
- targetPreflightCommitment = targetCommitment;
1150
- break;
1151
- default:
1152
- targetPreflightCommitment = 'finalized';
1153
- }
1154
- const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
1155
- ? 2
1156
- : targetPreflightCommitment === 'confirmed'
1157
- ? 1
1158
- : 0;
1159
- const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
1160
- return preflightCommitmentScore < targetCommitmentScore
1161
- ? targetPreflightCommitment
1162
- : targetCommitment;
291
+ function getTargetCommitment() {
292
+ let targetCommitment;
293
+ switch (connection.commitment) {
294
+ case 'confirmed':
295
+ case 'finalized':
296
+ case 'processed':
297
+ targetCommitment = connection.commitment;
298
+ break;
299
+ default:
300
+ targetCommitment = 'finalized';
1163
301
  }
1164
- const [capabilities, _1, _2] = yield Promise.all([
1165
- wallet.getCapabilities(),
1166
- this.performReauthorization(wallet, authToken),
1167
- walletAdapterBase.isVersionedTransaction(transaction)
1168
- ? null
1169
- : /**
1170
- * Unlike versioned transactions, legacy `Transaction` objects
1171
- * may not have an associated `feePayer` or `recentBlockhash`.
1172
- * This code exists to patch them up in case they are missing.
1173
- */
1174
- (() => __awaiter(this, void 0, void 0, function* () {
1175
- var _a;
1176
- transaction.feePayer || (transaction.feePayer = (_a = this.publicKey) !== null && _a !== void 0 ? _a : undefined);
1177
- if (transaction.recentBlockhash == null) {
1178
- const { blockhash } = yield connection.getLatestBlockhash({
1179
- commitment: getTargetCommitment(),
1180
- });
1181
- transaction.recentBlockhash = blockhash;
1182
- }
1183
- }))(),
1184
- ]);
1185
- if (capabilities.supports_sign_and_send_transactions) {
1186
- const signatures = yield wallet.signAndSendTransactions({
1187
- minContextSlot,
1188
- transactions: [transaction],
1189
- });
1190
- return signatures[0];
302
+ let targetPreflightCommitment;
303
+ switch (options === null || options === void 0 ? void 0 : options.preflightCommitment) {
304
+ case 'confirmed':
305
+ case 'finalized':
306
+ case 'processed':
307
+ targetPreflightCommitment = options.preflightCommitment;
308
+ break;
309
+ case undefined:
310
+ targetPreflightCommitment = targetCommitment;
311
+ break;
312
+ default:
313
+ targetPreflightCommitment = 'finalized';
314
+ }
315
+ const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
316
+ ? 2
317
+ : targetPreflightCommitment === 'confirmed'
318
+ ? 1
319
+ : 0;
320
+ const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
321
+ return preflightCommitmentScore < targetCommitmentScore
322
+ ? targetPreflightCommitment
323
+ : targetCommitment;
324
+ }
325
+ if (walletStandardFeatures.SolanaSignAndSendTransaction in __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features) {
326
+ const chain = chainOrClusterToChainId(__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").currentAuthorization.chain);
327
+ const [signature] = (yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
328
+ account,
329
+ transaction: transaction.serialize(),
330
+ chain: chain,
331
+ options: options ? {
332
+ skipPreflight: options.skipPreflight,
333
+ maxRetries: options.maxRetries
334
+ } : undefined
335
+ })).map(((output) => {
336
+ return jsBase64.fromUint8Array(output.signature);
337
+ }));
338
+ return signature;
339
+ }
340
+ else {
341
+ const [signedTransaction] = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_performSignTransactions).call(this, [transaction]);
342
+ if (isVersionedTransaction(signedTransaction)) {
343
+ return yield connection.sendTransaction(signedTransaction);
1191
344
  }
1192
345
  else {
1193
- const [signedTransaction] = yield wallet.signTransactions({
1194
- transactions: [transaction],
1195
- });
1196
- if (walletAdapterBase.isVersionedTransaction(signedTransaction)) {
1197
- return yield connection.sendTransaction(signedTransaction);
1198
- }
1199
- else {
1200
- const serializedTransaction = signedTransaction.serialize();
1201
- return yield connection.sendRawTransaction(serializedTransaction, Object.assign(Object.assign({}, options), { preflightCommitment: getTargetCommitment() }));
1202
- }
346
+ const serializedTransaction = signedTransaction.serialize();
347
+ return yield connection.sendRawTransaction(serializedTransaction, Object.assign(Object.assign({}, options), { preflightCommitment: getTargetCommitment() }));
1203
348
  }
1204
- }));
349
+ }
1205
350
  }
1206
351
  catch (error) {
1207
352
  throw new walletAdapterBase.WalletSendTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
@@ -1211,74 +356,157 @@ class SolanaMobileWalletAdapterRemote extends walletAdapterBase.BaseSignInMessag
1211
356
  }
1212
357
  signTransaction(transaction) {
1213
358
  return __awaiter(this, void 0, void 0, function* () {
1214
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
1215
- const [signedTransaction] = yield this.performSignTransactions([transaction]);
359
+ return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
360
+ const [signedTransaction] = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_performSignTransactions).call(this, [transaction]);
1216
361
  return signedTransaction;
1217
362
  }));
1218
363
  });
1219
364
  }
1220
365
  signAllTransactions(transactions) {
1221
366
  return __awaiter(this, void 0, void 0, function* () {
1222
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
1223
- const signedTransactions = yield this.performSignTransactions(transactions);
367
+ return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
368
+ const signedTransactions = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_performSignTransactions).call(this, transactions);
1224
369
  return signedTransactions;
1225
370
  }));
1226
371
  });
1227
372
  }
1228
- signMessage(message) {
1229
- return __awaiter(this, void 0, void 0, function* () {
1230
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
1231
- const { authToken, selectedAddress } = this.assertIsAuthorized();
1232
- try {
1233
- return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
1234
- yield this.performReauthorization(wallet, authToken);
1235
- const [signedMessage] = yield wallet.signMessages({
1236
- addresses: [selectedAddress],
1237
- payloads: [message],
1238
- });
1239
- const signature = signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES);
1240
- return signature;
1241
- }));
1242
- }
1243
- catch (error) {
1244
- throw new walletAdapterBase.WalletSignMessageError(error === null || error === void 0 ? void 0 : error.message, error);
1245
- }
1246
- }));
373
+ }
374
+ _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) {
375
+ return __awaiter(this, void 0, void 0, function* () {
376
+ if (this.connecting || this.connected) {
377
+ return;
378
+ }
379
+ return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
380
+ if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Installed && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Loadable) {
381
+ throw new walletAdapterBase.WalletNotReadyError();
382
+ }
383
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, true, "f");
384
+ try {
385
+ yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect({ silent: autoConnect });
386
+ }
387
+ catch (e) {
388
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
389
+ }
390
+ finally {
391
+ __classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, false, "f");
392
+ }
393
+ }));
394
+ });
395
+ }, _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled = function _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled() {
396
+ if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Installed) {
397
+ this.emit('readyStateChange', (__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_readyState, walletAdapterBase.WalletReadyState.Installed, "f")));
398
+ }
399
+ }, _BaseSolanaMobileWalletAdapter_assertIsAuthorized = function _BaseSolanaMobileWalletAdapter_assertIsAuthorized() {
400
+ if (!__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").isAuthorized || !__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f"))
401
+ throw new walletAdapterBase.WalletNotConnectedError();
402
+ return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f");
403
+ }, _BaseSolanaMobileWalletAdapter_performSignTransactions = function _BaseSolanaMobileWalletAdapter_performSignTransactions(transactions) {
404
+ return __awaiter(this, void 0, void 0, function* () {
405
+ const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
406
+ try {
407
+ if (walletStandardFeatures.SolanaSignTransaction in __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features) {
408
+ return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignTransaction].signTransaction(...transactions.map((value) => {
409
+ return { account, transaction: value.serialize() };
410
+ })).then((outputs) => {
411
+ return outputs.map((output) => {
412
+ const byteArray = output.signedTransaction;
413
+ const numSignatures = byteArray[0];
414
+ const messageOffset = numSignatures * SIGNATURE_LENGTH_IN_BYTES + 1;
415
+ const version = web3_js.VersionedMessage.deserializeMessageVersion(byteArray.slice(messageOffset, byteArray.length));
416
+ if (version === 'legacy') {
417
+ return web3_js.Transaction.from(byteArray);
418
+ }
419
+ else {
420
+ return web3_js.VersionedTransaction.deserialize(byteArray);
421
+ }
422
+ });
423
+ });
424
+ }
425
+ else {
426
+ throw new Error('Connected wallet does not support signing transactions');
427
+ }
428
+ }
429
+ catch (error) {
430
+ throw new walletAdapterBase.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
431
+ }
432
+ });
433
+ }, _BaseSolanaMobileWalletAdapter_runWithGuard = function _BaseSolanaMobileWalletAdapter_runWithGuard(callback) {
434
+ return __awaiter(this, void 0, void 0, function* () {
435
+ try {
436
+ return yield callback();
437
+ }
438
+ catch (e) {
439
+ this.emit('error', e);
440
+ throw e;
441
+ }
442
+ });
443
+ };
444
+ class LocalSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
445
+ constructor(config) {
446
+ var _a;
447
+ const chain = chainOrClusterToChainId((_a = config.chain) !== null && _a !== void 0 ? _a : config.cluster);
448
+ super(new walletStandardMobile.LocalSolanaMobileWalletAdapterWallet({
449
+ appIdentity: config.appIdentity,
450
+ authorizationCache: {
451
+ set: config.authorizationResultCache.set,
452
+ get: () => __awaiter(this, void 0, void 0, function* () {
453
+ const authorizationResult = yield config.authorizationResultCache.get();
454
+ if (authorizationResult && 'chain' in authorizationResult) {
455
+ return authorizationResult;
456
+ }
457
+ else if (authorizationResult) {
458
+ return Object.assign(Object.assign({}, authorizationResult), { chain: chain });
459
+ }
460
+ else
461
+ return undefined;
462
+ }),
463
+ clear: config.authorizationResultCache.clear,
464
+ },
465
+ chains: [chain],
466
+ chainSelector: walletStandardMobile.createDefaultChainSelector(),
467
+ onWalletNotFound: () => __awaiter(this, void 0, void 0, function* () {
468
+ config.onWalletNotFound(this);
469
+ }),
470
+ }), {
471
+ addressSelector: config.addressSelector,
472
+ chain: chain,
1247
473
  });
1248
474
  }
1249
- signIn(input) {
1250
- return __awaiter(this, void 0, void 0, function* () {
1251
- return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
1252
- var _a, _b;
1253
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
1254
- throw new walletAdapterBase.WalletNotReadyError();
1255
- }
1256
- this._connecting = true;
1257
- try {
1258
- const authorizationResult = yield this.performAuthorization(Object.assign(Object.assign({}, input), { domain: (_a = input === null || input === void 0 ? void 0 : input.domain) !== null && _a !== void 0 ? _a : window.location.host }));
1259
- if (!authorizationResult.sign_in_result) {
1260
- throw new Error("Sign in failed, no sign in result returned by wallet");
475
+ }
476
+ class RemoteSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
477
+ constructor(config) {
478
+ const chain = chainOrClusterToChainId(config.chain);
479
+ super(new walletStandardMobile.RemoteSolanaMobileWalletAdapterWallet({
480
+ appIdentity: config.appIdentity,
481
+ authorizationCache: {
482
+ set: config.authorizationResultCache.set,
483
+ get: () => __awaiter(this, void 0, void 0, function* () {
484
+ const authorizationResult = yield config.authorizationResultCache.get();
485
+ if (authorizationResult && 'chain' in authorizationResult) {
486
+ return authorizationResult;
1261
487
  }
1262
- const signedInAddress = authorizationResult.sign_in_result.address;
1263
- const signedInAccount = Object.assign(Object.assign({}, (_b = authorizationResult.accounts.find(acc => acc.address == signedInAddress)) !== null && _b !== void 0 ? _b : {
1264
- address: signedInAddress
1265
- }), { publicKey: jsBase64.toUint8Array(signedInAddress) });
1266
- return {
1267
- account: signedInAccount,
1268
- signedMessage: jsBase64.toUint8Array(authorizationResult.sign_in_result.signed_message),
1269
- signature: jsBase64.toUint8Array(authorizationResult.sign_in_result.signature)
1270
- };
1271
- }
1272
- catch (e) {
1273
- throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
1274
- }
1275
- finally {
1276
- this._connecting = false;
1277
- }
1278
- }));
488
+ else if (authorizationResult) {
489
+ return Object.assign(Object.assign({}, authorizationResult), { chain: chain });
490
+ }
491
+ else
492
+ return undefined;
493
+ }),
494
+ clear: config.authorizationResultCache.clear,
495
+ },
496
+ chains: [chain],
497
+ chainSelector: walletStandardMobile.createDefaultChainSelector(),
498
+ remoteHostAuthority: config.remoteHostAuthority,
499
+ onWalletNotFound: () => __awaiter(this, void 0, void 0, function* () {
500
+ config.onWalletNotFound(this);
501
+ }),
502
+ }), {
503
+ addressSelector: config.addressSelector,
504
+ chain: chain,
1279
505
  });
1280
506
  }
1281
507
  }
508
+ class SolanaMobileWalletAdapter extends LocalSolanaMobileWalletAdapter {
509
+ }
1282
510
 
1283
511
  function createDefaultAddressSelector() {
1284
512
  return {
@@ -1325,18 +553,16 @@ function createDefaultAuthorizationResultCache() {
1325
553
 
1326
554
  function defaultWalletNotFoundHandler(mobileWalletAdapter) {
1327
555
  return __awaiter(this, void 0, void 0, function* () {
1328
- if (typeof window !== 'undefined') {
1329
- window.location.assign(mobileWalletAdapter.url);
1330
- }
556
+ return walletStandardMobile.defaultErrorModalWalletNotFoundHandler();
1331
557
  });
1332
558
  }
1333
559
  function createDefaultWalletNotFoundHandler() {
1334
560
  return defaultWalletNotFoundHandler;
1335
561
  }
1336
562
 
563
+ exports.LocalSolanaMobileWalletAdapter = LocalSolanaMobileWalletAdapter;
564
+ exports.RemoteSolanaMobileWalletAdapter = RemoteSolanaMobileWalletAdapter;
1337
565
  exports.SolanaMobileWalletAdapter = SolanaMobileWalletAdapter;
1338
- exports.SolanaMobileWalletAdapterRemote = SolanaMobileWalletAdapterRemote;
1339
- exports.SolanaMobileWalletAdapterRemoteWalletName = SolanaMobileWalletAdapterRemoteWalletName;
1340
566
  exports.SolanaMobileWalletAdapterWalletName = SolanaMobileWalletAdapterWalletName;
1341
567
  exports.createDefaultAddressSelector = createDefaultAddressSelector;
1342
568
  exports.createDefaultAuthorizationResultCache = createDefaultAuthorizationResultCache;