@solana-mobile/wallet-standard-mobile 0.4.4 → 0.5.0-beta2

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,61 +1,181 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var walletStandardFeatures = require('@solana/wallet-standard-features');
6
4
  var QRCode = require('qrcode');
7
5
  var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-protocol');
8
6
  var features = require('@wallet-standard/features');
9
7
  var jsBase64 = require('js-base64');
10
8
  var base58 = require('bs58');
11
- var require$$0 = require('is-plain-obj');
9
+ var wallet = require('@wallet-standard/wallet');
10
+ var AsyncStorage = require('@react-native-async-storage/async-storage');
12
11
  var walletStandardChains = require('@solana/wallet-standard-chains');
13
12
 
14
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+ const modalHtml$1 = `
14
+ <div class="mobile-wallet-adapter-embedded-loading-indicator" role="dialog" aria-modal="true" aria-labelledby="modal-title">
15
+ <div data-modal-close style="position: absolute; width: 100%; height: 100%;"></div>
16
+ <div class="mobile-wallet-adapter-embedded-loading-container">
17
+ <div class="mobile-wallet-adapter-embedded-loading-animation"></div>
18
+ </div>
19
+ </div>
20
+ `;
21
+ const css$6 = `
22
+ .mobile-wallet-adapter-embedded-loading-indicator {
23
+ display: flex; /* Use flexbox to center content */
24
+ justify-content: center; /* Center horizontally */
25
+ align-items: start; /* Center vertically */
26
+ position: fixed; /* Stay in place */
27
+ z-index: 1; /* Sit on top */
28
+ left: 0;
29
+ top: 0;
30
+ width: 100%; /* Full width */
31
+ height: 100%; /* Full height */
32
+ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
33
+ overflow-y: auto; /* enable scrolling */
34
+ }
35
+
36
+ .mobile-wallet-adapter-embedded-loading-container {
37
+ display: flex;
38
+ margin: auto;
39
+ }
15
40
 
16
- var QRCode__default = /*#__PURE__*/_interopDefaultLegacy(QRCode);
17
- var base58__default = /*#__PURE__*/_interopDefaultLegacy(base58);
18
- var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
41
+ .mobile-wallet-adapter-embedded-loading-animation {
42
+ position: relative;
43
+ left: -9999px;
44
+ width: 10px;
45
+ height: 10px;
46
+ border-radius: 5px;
47
+ background-color: var(--spinner-color);
48
+ color: var(--spinner-color);
49
+ box-shadow: 9984px 0 0 0 var(--spinner-color),
50
+ 9999px 0 0 0 var(--spinner-color),
51
+ 10014px 0 0 0 var(--spinner-color);
52
+ animation: dot-typing 1.5s infinite linear;
53
+ }
19
54
 
20
- /******************************************************************************
21
- Copyright (c) Microsoft Corporation.
22
-
23
- Permission to use, copy, modify, and/or distribute this software for any
24
- purpose with or without fee is hereby granted.
25
-
26
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
27
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
28
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
29
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
30
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
31
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
32
- PERFORMANCE OF THIS SOFTWARE.
33
- ***************************************************************************** */
34
-
35
- function __awaiter(thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- }
44
-
45
- function __classPrivateFieldGet$1(receiver, state, kind, f) {
46
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
47
- 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");
48
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
49
- }
50
-
51
- function __classPrivateFieldSet$1(receiver, state, value, kind, f) {
52
- if (kind === "m") throw new TypeError("Private method is not writable");
53
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
54
- 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");
55
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
55
+ @keyframes dot-typing {
56
+ 0% {
57
+ box-shadow: 9984px 0 0 0 var(--spinner-color),
58
+ 9999px 0 0 0 var(--spinner-color),
59
+ 10014px 0 0 0 var(--spinner-color);
60
+ }
61
+ 16.667% {
62
+ box-shadow: 9984px -10px 0 0 var(--spinner-color),
63
+ 9999px 0 0 0 var(--spinner-color),
64
+ 10014px 0 0 0 var(--spinner-color);
65
+ }
66
+ 33.333% {
67
+ box-shadow: 9984px 0 0 0 var(--spinner-color),
68
+ 9999px 0 0 0 var(--spinner-color),
69
+ 10014px 0 0 0 var(--spinner-color);
70
+ }
71
+ 50% {
72
+ box-shadow: 9984px 0 0 0 var(--spinner-color),
73
+ 9999px -10px 0 0 var(--spinner-color),
74
+ 10014px 0 0 0 var(--spinner-color);
75
+ }
76
+ 66.667% {
77
+ box-shadow: 9984px 0 0 0 var(--spinner-color),
78
+ 9999px 0 0 0 var(--spinner-color),
79
+ 10014px 0 0 0 var(--spinner-color);
80
+ }
81
+ 83.333% {
82
+ box-shadow: 9984px 0 0 0 var(--spinner-color),
83
+ 9999px 0 0 0 var(--spinner-color),
84
+ 10014px -10px 0 0 var(--spinner-color);
85
+ }
86
+ 100% {
87
+ box-shadow: 9984px 0 0 0 var(--spinner-color),
88
+ 9999px 0 0 0 var(--spinner-color),
89
+ 10014px 0 0 0 var(--spinner-color);
90
+ }
91
+ }
92
+ `;
93
+ class EmbeddedLoadingSpinner {
94
+ #root = null;
95
+ #eventListeners = {};
96
+ #listenersAttached = false;
97
+ dom = null;
98
+ constructor() {
99
+ // Bind methods to ensure `this` context is correct
100
+ this.init = this.init.bind(this);
101
+ this.#root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
102
+ }
103
+ async init() {
104
+ console.log('Injecting modal');
105
+ this.#injectHTML();
106
+ }
107
+ open = () => {
108
+ console.debug('Modal open');
109
+ this.#attachEventListeners();
110
+ if (this.#root) {
111
+ this.#root.style.display = 'flex';
112
+ }
113
+ };
114
+ close = (event = undefined) => {
115
+ console.debug('Modal close');
116
+ this.#removeEventListeners();
117
+ if (this.#root) {
118
+ this.#root.style.display = 'none';
119
+ }
120
+ this.#eventListeners['close']?.forEach((listener) => listener(event));
121
+ };
122
+ addEventListener(event, listener) {
123
+ this.#eventListeners[event]?.push(listener) || (this.#eventListeners[event] = [listener]);
124
+ return () => this.removeEventListener(event, listener);
125
+ }
126
+ removeEventListener(event, listener) {
127
+ this.#eventListeners[event] = this.#eventListeners[event]?.filter((existingListener) => listener !== existingListener);
128
+ }
129
+ #injectHTML() {
130
+ // Check if already injected by checking if shadow DOM exists
131
+ if (this.dom) {
132
+ return;
133
+ }
134
+ // Create a container for the modal
135
+ this.#root = document.createElement('div');
136
+ this.#root.id = 'mobile-wallet-adapter-embedded-root-ui';
137
+ this.#root.innerHTML = modalHtml$1;
138
+ this.#root.style.display = 'none';
139
+ // Apply styles
140
+ const styles = document.createElement('style');
141
+ styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
142
+ styles.textContent = css$6;
143
+ // Create a shadow DOM to encapsulate the modal
144
+ const host = document.createElement('div');
145
+ this.dom = host.attachShadow({ mode: 'closed' });
146
+ // Pass the CSS variable to the Shadow DOM
147
+ host.style.setProperty('--spinner-color', '#FFFFFF');
148
+ this.dom.appendChild(styles);
149
+ this.dom.appendChild(this.#root);
150
+ // Append the shadow DOM host to the body
151
+ document.body.appendChild(host);
152
+ }
153
+ #attachEventListeners() {
154
+ if (!this.#root || this.#listenersAttached)
155
+ return;
156
+ const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
157
+ closers.forEach(closer => closer?.addEventListener('click', (event) => { this.close(event); }));
158
+ window.addEventListener('load', this.close);
159
+ document.addEventListener('keydown', this.#handleKeyDown);
160
+ this.#listenersAttached = true;
161
+ }
162
+ #removeEventListeners() {
163
+ if (!this.#listenersAttached)
164
+ return;
165
+ window.removeEventListener('load', this.close);
166
+ document.removeEventListener('keydown', this.#handleKeyDown);
167
+ if (!this.#root)
168
+ return;
169
+ const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
170
+ closers.forEach(closer => closer?.removeEventListener('click', this.close));
171
+ this.#listenersAttached = false;
172
+ }
173
+ #handleKeyDown = (event) => {
174
+ if (event.key === 'Escape')
175
+ this.close(event);
176
+ };
56
177
  }
57
178
 
58
- var _EmbeddedModal_instances, _EmbeddedModal_root, _EmbeddedModal_eventListeners, _EmbeddedModal_listenersAttached, _EmbeddedModal_injectHTML, _EmbeddedModal_attachEventListeners, _EmbeddedModal_removeEventListeners, _EmbeddedModal_handleKeyDown;
59
179
  const modalHtml = `
60
180
  <div class="mobile-wallet-adapter-embedded-modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-title">
61
181
  <div data-modal-close style="position: absolute; width: 100%; height: 100%;"></div>
@@ -71,7 +191,7 @@ const modalHtml = `
71
191
  </div>
72
192
  </div>
73
193
  `;
74
- const css$2 = `
194
+ const css$5 = `
75
195
  .mobile-wallet-adapter-embedded-modal-container {
76
196
  display: flex; /* Use flexbox to center content */
77
197
  justify-content: center; /* Center horizontally */
@@ -134,131 +254,121 @@ const fonts = `
134
254
  <link href="https://fonts.googleapis.com/css2?family=Inter+Tight:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
135
255
  `;
136
256
  class EmbeddedModal {
257
+ #root = null;
258
+ #eventListeners = {};
259
+ #listenersAttached = false;
260
+ dom = null;
137
261
  constructor() {
138
- _EmbeddedModal_instances.add(this);
139
- _EmbeddedModal_root.set(this, null);
140
- _EmbeddedModal_eventListeners.set(this, {});
141
- _EmbeddedModal_listenersAttached.set(this, false);
142
- this.dom = null;
143
- this.open = () => {
144
- console.debug('Modal open');
145
- __classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_attachEventListeners).call(this);
146
- if (__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f")) {
147
- __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'flex';
148
- }
149
- };
150
- this.close = (event = undefined) => {
151
- var _a;
152
- console.debug('Modal close');
153
- __classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_removeEventListeners).call(this);
154
- if (__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f")) {
155
- __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'none';
156
- }
157
- (_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")['close']) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener(event));
158
- };
159
- _EmbeddedModal_handleKeyDown.set(this, (event) => {
160
- if (event.key === 'Escape')
161
- this.close(event);
162
- });
163
262
  // Bind methods to ensure `this` context is correct
164
263
  this.init = this.init.bind(this);
165
- __classPrivateFieldSet$1(this, _EmbeddedModal_root, document.getElementById('mobile-wallet-adapter-embedded-root-ui'), "f");
264
+ this.#root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
166
265
  }
167
- init() {
168
- return __awaiter(this, void 0, void 0, function* () {
169
- console.log('Injecting modal');
170
- __classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_injectHTML).call(this);
171
- });
266
+ async init() {
267
+ console.log('Injecting modal');
268
+ this.#injectHTML();
172
269
  }
270
+ open = () => {
271
+ console.debug('Modal open');
272
+ this.#attachEventListeners();
273
+ if (this.#root) {
274
+ this.#root.style.display = 'flex';
275
+ }
276
+ };
277
+ close = (event = undefined) => {
278
+ console.debug('Modal close');
279
+ this.#removeEventListeners();
280
+ if (this.#root) {
281
+ this.#root.style.display = 'none';
282
+ }
283
+ this.#eventListeners['close']?.forEach((listener) => listener(event));
284
+ };
173
285
  addEventListener(event, listener) {
174
- var _a;
175
- ((_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event] = [listener]);
286
+ this.#eventListeners[event]?.push(listener) || (this.#eventListeners[event] = [listener]);
176
287
  return () => this.removeEventListener(event, listener);
177
288
  }
178
289
  removeEventListener(event, listener) {
179
- var _a;
180
- __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
181
- }
290
+ this.#eventListeners[event] = this.#eventListeners[event]?.filter((existingListener) => listener !== existingListener);
291
+ }
292
+ #injectHTML() {
293
+ // Check if the HTML has already been injected
294
+ if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
295
+ if (!this.#root)
296
+ this.#root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
297
+ return;
298
+ }
299
+ // Create a container for the modal
300
+ this.#root = document.createElement('div');
301
+ this.#root.id = 'mobile-wallet-adapter-embedded-root-ui';
302
+ this.#root.innerHTML = modalHtml;
303
+ this.#root.style.display = 'none';
304
+ // Add modal content
305
+ const content = this.#root.querySelector('.mobile-wallet-adapter-embedded-modal-content');
306
+ if (content)
307
+ content.innerHTML = this.contentHtml;
308
+ // Apply styles
309
+ const styles = document.createElement('style');
310
+ styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
311
+ styles.textContent = css$5 + this.contentStyles;
312
+ // Create a shadow DOM to encapsulate the modal
313
+ const host = document.createElement('div');
314
+ host.innerHTML = fonts;
315
+ this.dom = host.attachShadow({ mode: 'closed' });
316
+ this.dom.appendChild(styles);
317
+ this.dom.appendChild(this.#root);
318
+ // Append the shadow DOM host to the body
319
+ document.body.appendChild(host);
320
+ }
321
+ #attachEventListeners() {
322
+ if (!this.#root || this.#listenersAttached)
323
+ return;
324
+ const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
325
+ closers.forEach(closer => closer?.addEventListener('click', this.close));
326
+ window.addEventListener('load', this.close);
327
+ document.addEventListener('keydown', this.#handleKeyDown);
328
+ this.#listenersAttached = true;
329
+ }
330
+ #removeEventListeners() {
331
+ if (!this.#listenersAttached)
332
+ return;
333
+ window.removeEventListener('load', this.close);
334
+ document.removeEventListener('keydown', this.#handleKeyDown);
335
+ if (!this.#root)
336
+ return;
337
+ const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
338
+ closers.forEach(closer => closer?.removeEventListener('click', this.close));
339
+ this.#listenersAttached = false;
340
+ }
341
+ #handleKeyDown = (event) => {
342
+ if (event.key === 'Escape')
343
+ this.close(event);
344
+ };
182
345
  }
183
- _EmbeddedModal_root = new WeakMap(), _EmbeddedModal_eventListeners = new WeakMap(), _EmbeddedModal_listenersAttached = new WeakMap(), _EmbeddedModal_handleKeyDown = new WeakMap(), _EmbeddedModal_instances = new WeakSet(), _EmbeddedModal_injectHTML = function _EmbeddedModal_injectHTML() {
184
- // Check if the HTML has already been injected
185
- if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
186
- if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"))
187
- __classPrivateFieldSet$1(this, _EmbeddedModal_root, document.getElementById('mobile-wallet-adapter-embedded-root-ui'), "f");
188
- return;
189
- }
190
- // Create a container for the modal
191
- __classPrivateFieldSet$1(this, _EmbeddedModal_root, document.createElement('div'), "f");
192
- __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").id = 'mobile-wallet-adapter-embedded-root-ui';
193
- __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").innerHTML = modalHtml;
194
- __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'none';
195
- // Add modal content
196
- const content = __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelector('.mobile-wallet-adapter-embedded-modal-content');
197
- if (content)
198
- content.innerHTML = this.contentHtml;
199
- // Apply styles
200
- const styles = document.createElement('style');
201
- styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
202
- styles.textContent = css$2 + this.contentStyles;
203
- // Create a shadow DOM to encapsulate the modal
204
- const host = document.createElement('div');
205
- host.innerHTML = fonts;
206
- this.dom = host.attachShadow({ mode: 'closed' });
207
- this.dom.appendChild(styles);
208
- this.dom.appendChild(__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"));
209
- // Append the shadow DOM host to the body
210
- document.body.appendChild(host);
211
- }, _EmbeddedModal_attachEventListeners = function _EmbeddedModal_attachEventListeners() {
212
- if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f") || __classPrivateFieldGet$1(this, _EmbeddedModal_listenersAttached, "f"))
213
- return;
214
- const closers = [...__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelectorAll('[data-modal-close]')];
215
- closers.forEach(closer => closer === null || closer === void 0 ? void 0 : closer.addEventListener('click', this.close));
216
- window.addEventListener('load', this.close);
217
- document.addEventListener('keydown', __classPrivateFieldGet$1(this, _EmbeddedModal_handleKeyDown, "f"));
218
- __classPrivateFieldSet$1(this, _EmbeddedModal_listenersAttached, true, "f");
219
- }, _EmbeddedModal_removeEventListeners = function _EmbeddedModal_removeEventListeners() {
220
- if (!__classPrivateFieldGet$1(this, _EmbeddedModal_listenersAttached, "f"))
221
- return;
222
- window.removeEventListener('load', this.close);
223
- document.removeEventListener('keydown', __classPrivateFieldGet$1(this, _EmbeddedModal_handleKeyDown, "f"));
224
- if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"))
225
- return;
226
- const closers = [...__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelectorAll('[data-modal-close]')];
227
- closers.forEach(closer => closer === null || closer === void 0 ? void 0 : closer.removeEventListener('click', this.close));
228
- __classPrivateFieldSet$1(this, _EmbeddedModal_listenersAttached, false, "f");
229
- };
230
346
 
231
347
  class RemoteConnectionModal extends EmbeddedModal {
232
- constructor() {
233
- super(...arguments);
234
- this.contentStyles = css$1;
235
- this.contentHtml = QRCodeHtml;
236
- }
237
- initWithQR(qrCode) {
238
- const _super = Object.create(null, {
239
- init: { get: () => super.init }
240
- });
241
- return __awaiter(this, void 0, void 0, function* () {
242
- _super.init.call(this);
243
- this.populateQRCode(qrCode);
244
- });
245
- }
246
- populateQRCode(qrUrl) {
247
- var _a;
248
- return __awaiter(this, void 0, void 0, function* () {
249
- const qrcodeContainer = (_a = this.dom) === null || _a === void 0 ? void 0 : _a.getElementById('mobile-wallet-adapter-embedded-modal-qr-code-container');
250
- if (qrcodeContainer) {
251
- const qrCodeElement = yield QRCode__default["default"].toCanvas(qrUrl, { width: 200, margin: 0 });
252
- if (qrcodeContainer.firstElementChild !== null) {
253
- qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
254
- }
255
- else
256
- qrcodeContainer.appendChild(qrCodeElement);
348
+ contentStyles = css$4;
349
+ contentHtml = QRCodeHtml;
350
+ async initWithQR(qrCode) {
351
+ super.init();
352
+ this.populateQRCode(qrCode);
353
+ }
354
+ async populateQRCode(qrUrl) {
355
+ const qrcodeContainer = this.dom?.getElementById('mobile-wallet-adapter-embedded-modal-qr-code-container');
356
+ if (qrcodeContainer) {
357
+ const qrCodeElement = await QRCode.toCanvas(qrUrl, { width: 200, margin: 0 });
358
+ if (qrcodeContainer.firstElementChild !== null) {
359
+ qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
257
360
  }
258
- else {
259
- console.error('QRCode Container not found');
361
+ else
362
+ qrcodeContainer.appendChild(qrCodeElement);
363
+ // remove the loading placeholder for cleanup
364
+ const qrPlaceholder = this.dom?.getElementById('mobile-wallet-adapter-embedded-modal-qr-placeholder');
365
+ if (qrPlaceholder) {
366
+ qrPlaceholder.style.display = 'none';
260
367
  }
261
- });
368
+ }
369
+ else {
370
+ console.error('QRCode Container not found');
371
+ }
262
372
  }
263
373
  }
264
374
  const QRCodeHtml = `
@@ -276,7 +386,9 @@ const QRCodeHtml = `
276
386
  Open your wallet and scan this code
277
387
  </h4>
278
388
  </div>
279
- <div id="mobile-wallet-adapter-embedded-modal-qr-code-container" class="mobile-wallet-adapter-embedded-modal-qr-code-container"></div>
389
+ <div id="mobile-wallet-adapter-embedded-modal-qr-code-container" class="mobile-wallet-adapter-embedded-modal-qr-code-container">
390
+ <div id="mobile-wallet-adapter-embedded-modal-qr-placeholder" class="mobile-wallet-adapter-embedded-modal-qr-placeholder"></div>
391
+ </div>
280
392
  </div>
281
393
  </div>
282
394
  <div class="mobile-wallet-adapter-embedded-modal-divider"><hr></div>
@@ -303,7 +415,7 @@ const QRCodeHtml = `
303
415
  </div>
304
416
  </div>
305
417
  `;
306
- const css$1 = `
418
+ const css$4 = `
307
419
  .mobile-wallet-adapter-embedded-modal-qr-content {
308
420
  display: flex;
309
421
  margin-top: 10px;
@@ -347,6 +459,16 @@ const css$1 = `
347
459
  margin-left: auto;
348
460
  }
349
461
 
462
+ .mobile-wallet-adapter-embedded-modal-qr-placeholder {
463
+ margin-left: auto;
464
+ min-width: 200px;
465
+ min-height: 200px;
466
+ background: linear-gradient(-60deg, #F7F8F8 30%, #ECEEEE 50%, #F7F8F8 70%);
467
+ background-size: 200%;
468
+ animation: placeholderAnimate 2.7s linear infinite;
469
+ border-radius: 12px;
470
+ }
471
+
350
472
  .mobile-wallet-adapter-embedded-modal-divider {
351
473
  margin-top: 20px;
352
474
  padding-left: 10px;
@@ -419,6 +541,15 @@ const css$1 = `
419
541
  .mobile-wallet-adapter-embedded-modal-qr-code-container {
420
542
  margin: auto;
421
543
  }
544
+ .mobile-wallet-adapter-embedded-modal-qr-placeholder {
545
+ margin: auto;
546
+ }
547
+ }
548
+
549
+ /* QR Placeholder */
550
+ @keyframes placeholderAnimate {
551
+ 0% { background-position: 200% 0; }
552
+ 100% { background-position: -200% 0; }
422
553
  }
423
554
 
424
555
  /* Spinner */
@@ -502,899 +633,1288 @@ const css$1 = `
502
633
 
503
634
  const icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=';
504
635
 
505
- var _LocalSolanaMobileWalletAdapterWallet_instances, _LocalSolanaMobileWalletAdapterWallet_listeners, _LocalSolanaMobileWalletAdapterWallet_version, _LocalSolanaMobileWalletAdapterWallet_name, _LocalSolanaMobileWalletAdapterWallet_url, _LocalSolanaMobileWalletAdapterWallet_icon, _LocalSolanaMobileWalletAdapterWallet_appIdentity, _LocalSolanaMobileWalletAdapterWallet_authorization, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, _LocalSolanaMobileWalletAdapterWallet_connecting, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, _LocalSolanaMobileWalletAdapterWallet_chains, _LocalSolanaMobileWalletAdapterWallet_chainSelector, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, _LocalSolanaMobileWalletAdapterWallet_on, _LocalSolanaMobileWalletAdapterWallet_emit, _LocalSolanaMobileWalletAdapterWallet_off, _LocalSolanaMobileWalletAdapterWallet_connect, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, _LocalSolanaMobileWalletAdapterWallet_disconnect, _LocalSolanaMobileWalletAdapterWallet_transact, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, _LocalSolanaMobileWalletAdapterWallet_performSignTransactions, _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, _LocalSolanaMobileWalletAdapterWallet_signTransaction, _LocalSolanaMobileWalletAdapterWallet_signMessage, _LocalSolanaMobileWalletAdapterWallet_signIn, _LocalSolanaMobileWalletAdapterWallet_performSignIn, _RemoteSolanaMobileWalletAdapterWallet_instances, _RemoteSolanaMobileWalletAdapterWallet_listeners, _RemoteSolanaMobileWalletAdapterWallet_version, _RemoteSolanaMobileWalletAdapterWallet_name, _RemoteSolanaMobileWalletAdapterWallet_url, _RemoteSolanaMobileWalletAdapterWallet_icon, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, _RemoteSolanaMobileWalletAdapterWallet_authorization, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, _RemoteSolanaMobileWalletAdapterWallet_connecting, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, _RemoteSolanaMobileWalletAdapterWallet_chains, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, _RemoteSolanaMobileWalletAdapterWallet_session, _RemoteSolanaMobileWalletAdapterWallet_on, _RemoteSolanaMobileWalletAdapterWallet_emit, _RemoteSolanaMobileWalletAdapterWallet_off, _RemoteSolanaMobileWalletAdapterWallet_connect, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, _RemoteSolanaMobileWalletAdapterWallet_disconnect, _RemoteSolanaMobileWalletAdapterWallet_transact, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions, _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, _RemoteSolanaMobileWalletAdapterWallet_signMessage, _RemoteSolanaMobileWalletAdapterWallet_signIn, _RemoteSolanaMobileWalletAdapterWallet_performSignIn;
506
- const SolanaMobileWalletAdapterWalletName = 'Mobile Wallet Adapter';
507
- const SolanaMobileWalletAdapterRemoteWalletName = 'Remote Mobile Wallet Adapter';
508
- const SIGNATURE_LENGTH_IN_BYTES = 64;
509
- const DEFAULT_FEATURES = [walletStandardFeatures.SolanaSignAndSendTransaction, walletStandardFeatures.SolanaSignTransaction, walletStandardFeatures.SolanaSignMessage, walletStandardFeatures.SolanaSignIn];
510
- class LocalSolanaMobileWalletAdapterWallet {
511
- constructor(config) {
512
- _LocalSolanaMobileWalletAdapterWallet_instances.add(this);
513
- _LocalSolanaMobileWalletAdapterWallet_listeners.set(this, {});
514
- _LocalSolanaMobileWalletAdapterWallet_version.set(this, '1.0.0'); // wallet-standard version
515
- _LocalSolanaMobileWalletAdapterWallet_name.set(this, SolanaMobileWalletAdapterWalletName);
516
- _LocalSolanaMobileWalletAdapterWallet_url.set(this, 'https://solanamobile.com/wallets');
517
- _LocalSolanaMobileWalletAdapterWallet_icon.set(this, icon);
518
- _LocalSolanaMobileWalletAdapterWallet_appIdentity.set(this, void 0);
519
- _LocalSolanaMobileWalletAdapterWallet_authorization.set(this, void 0);
520
- _LocalSolanaMobileWalletAdapterWallet_authorizationCache.set(this, void 0);
521
- _LocalSolanaMobileWalletAdapterWallet_connecting.set(this, false);
522
- /**
523
- * Every time the connection is recycled in some way (eg. `disconnect()` is called)
524
- * increment this and use it to make sure that `transact` calls from the previous
525
- * 'generation' don't continue to do work and throw exceptions.
526
- */
527
- _LocalSolanaMobileWalletAdapterWallet_connectionGeneration.set(this, 0);
528
- _LocalSolanaMobileWalletAdapterWallet_chains.set(this, []);
529
- _LocalSolanaMobileWalletAdapterWallet_chainSelector.set(this, void 0);
530
- _LocalSolanaMobileWalletAdapterWallet_optionalFeatures.set(this, void 0);
531
- _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound.set(this, void 0);
532
- _LocalSolanaMobileWalletAdapterWallet_on.set(this, (event, listener) => {
533
- var _a;
534
- ((_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event] = [listener]);
535
- return () => __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_off).call(this, event, listener);
536
- });
537
- _LocalSolanaMobileWalletAdapterWallet_connect.set(this, ({ silent } = {}) => __awaiter(this, void 0, void 0, function* () {
538
- if (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, "f") || this.connected) {
539
- return { accounts: this.accounts };
540
- }
541
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, true, "f");
542
- try {
543
- if (silent) {
544
- const cachedAuthorization = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
545
- if (cachedAuthorization) {
546
- yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, cachedAuthorization.capabilities);
547
- yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorization);
548
- }
549
- else {
550
- return { accounts: this.accounts };
551
- }
552
- }
553
- else {
554
- yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this);
555
- }
556
- }
557
- catch (e) {
558
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
559
- }
560
- finally {
561
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false, "f");
562
- }
563
- return { accounts: this.accounts };
564
- }));
565
- _LocalSolanaMobileWalletAdapterWallet_performAuthorization.set(this, (signInPayload) => __awaiter(this, void 0, void 0, function* () {
566
- try {
567
- const cachedAuthorizationResult = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
568
- if (cachedAuthorizationResult) {
569
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
570
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorizationResult);
571
- return cachedAuthorizationResult;
572
- }
573
- const selectedChain = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chainSelector, "f").select(__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"));
574
- return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
575
- const [capabilities, mwaAuthorizationResult] = yield Promise.all([
576
- wallet.getCapabilities(),
577
- wallet.authorize({
578
- chain: selectedChain,
579
- identity: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, "f"),
580
- sign_in_payload: signInPayload,
581
- })
582
- ]);
583
- const accounts = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
584
- const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts, chain: selectedChain, capabilities: capabilities });
585
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
586
- Promise.all([
587
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, capabilities),
588
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
589
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
590
- ]);
591
- return authorization;
592
- }));
593
- }
594
- catch (e) {
595
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
596
- }
597
- }));
598
- _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult.set(this, (authorization) => __awaiter(this, void 0, void 0, function* () {
599
- var _a;
600
- const didPublicKeysChange =
601
- // Case 1: We started from having no authorization.
602
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f") == null ||
603
- // Case 2: The number of authorized accounts changed.
604
- ((_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorization.accounts.length ||
605
- // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
606
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
607
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, authorization, "f");
608
- if (didPublicKeysChange) {
609
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
610
- }
611
- }));
612
- _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult.set(this, (capabilities) => __awaiter(this, void 0, void 0, function* () {
613
- // TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
614
- const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
615
- const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions;
616
- const didCapabilitiesChange = walletStandardFeatures.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
617
- walletStandardFeatures.SolanaSignTransaction in this.features !== supportsSignTransaction;
618
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, Object.assign(Object.assign({}, ((supportsSignAndSendTransaction || (!supportsSignAndSendTransaction && !supportsSignTransaction)) && {
619
- [walletStandardFeatures.SolanaSignAndSendTransaction]: {
620
- version: '1.0.0',
621
- supportedTransactionVersions: ['legacy', 0],
622
- signAndSendTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
623
- },
624
- })), (supportsSignTransaction && {
625
- [walletStandardFeatures.SolanaSignTransaction]: {
626
- version: '1.0.0',
627
- supportedTransactionVersions: ['legacy', 0],
628
- signTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signTransaction, "f"),
629
- },
630
- })), "f");
631
- if (didCapabilitiesChange) {
632
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { features: this.features });
633
- }
634
- }));
635
- _LocalSolanaMobileWalletAdapterWallet_performReauthorization.set(this, (wallet, authToken, chain) => __awaiter(this, void 0, void 0, function* () {
636
- var _b, _c;
637
- try {
638
- const [capabilities, mwaAuthorizationResult] = yield Promise.all([
639
- (_c = (_b = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _b === void 0 ? void 0 : _b.capabilities) !== null && _c !== void 0 ? _c : yield wallet.getCapabilities(),
640
- wallet.authorize({
641
- auth_token: authToken,
642
- identity: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, "f"),
643
- chain: chain
644
- })
645
- ]);
646
- const accounts = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
647
- const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts: accounts, chain: chain, capabilities: capabilities });
648
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
649
- Promise.all([
650
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
651
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
652
- ]);
653
- }
654
- catch (e) {
655
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_disconnect, "f").call(this);
656
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
657
- }
658
- }));
659
- _LocalSolanaMobileWalletAdapterWallet_disconnect.set(this, () => __awaiter(this, void 0, void 0, function* () {
660
- var _d;
661
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
662
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false, "f");
663
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, (_d = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f"), _d++, _d), "f");
664
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, undefined, "f");
665
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
666
- }));
667
- _LocalSolanaMobileWalletAdapterWallet_transact.set(this, (callback) => __awaiter(this, void 0, void 0, function* () {
668
- var _e;
669
- const walletUriBase = (_e = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _e === void 0 ? void 0 : _e.wallet_uri_base;
670
- const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
671
- const currentConnectionGeneration = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f");
672
- try {
673
- return yield mobileWalletAdapterProtocol.transact(callback, config);
674
- }
675
- catch (e) {
676
- if (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f") !== currentConnectionGeneration) {
677
- yield new Promise(() => { }); // Never resolve.
678
- }
679
- if (e instanceof Error &&
680
- e.name === 'SolanaMobileWalletAdapterError' &&
681
- e.code === 'ERROR_WALLET_NOT_FOUND') {
682
- yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, "f").call(this, this);
683
- }
684
- throw e;
685
- }
686
- }));
687
- _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized.set(this, () => {
688
- if (!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f"))
689
- throw new Error('Wallet not connected');
690
- return { authToken: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").auth_token, chain: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").chain };
691
- });
692
- _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts.set(this, (accounts) => {
693
- return accounts.map((account) => {
694
- var _a, _b;
695
- const publicKey = jsBase64.toUint8Array(account.address);
696
- return {
697
- address: base58__default["default"].encode(publicKey),
698
- publicKey,
699
- label: account.label,
700
- icon: account.icon,
701
- chains: (_a = account.chains) !== null && _a !== void 0 ? _a : __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"),
702
- // TODO: get supported features from getCapabilities API
703
- features: (_b = account.features) !== null && _b !== void 0 ? _b : DEFAULT_FEATURES
704
- };
705
- });
706
- });
707
- _LocalSolanaMobileWalletAdapterWallet_performSignTransactions.set(this, (transactions) => __awaiter(this, void 0, void 0, function* () {
708
- const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
709
- try {
710
- const base64Transactions = transactions.map((tx) => { return jsBase64.fromUint8Array(tx); });
711
- return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
712
- yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
713
- const signedTransactions = (yield wallet.signTransactions({
714
- payloads: base64Transactions,
715
- })).signed_payloads.map(jsBase64.toUint8Array);
716
- return signedTransactions;
717
- }));
718
- }
719
- catch (e) {
720
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
721
- }
722
- }));
723
- _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction.set(this, (transaction, options) => __awaiter(this, void 0, void 0, function* () {
724
- const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
725
- try {
726
- return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
727
- const [capabilities, _1] = yield Promise.all([
728
- wallet.getCapabilities(),
729
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain)
730
- ]);
731
- if (capabilities.supports_sign_and_send_transactions) {
732
- const base64Transaction = jsBase64.fromUint8Array(transaction);
733
- const signatures = (yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, options), { payloads: [base64Transaction] }))).signatures.map(jsBase64.toUint8Array);
734
- return signatures[0];
735
- }
736
- else {
737
- throw new Error('connected wallet does not support signAndSendTransaction');
738
- }
739
- }));
740
- }
741
- catch (e) {
742
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
743
- }
744
- }));
745
- _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
746
- const outputs = [];
747
- for (const input of inputs) {
748
- const signature = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, "f").call(this, input.transaction, input.options);
749
- outputs.push({ signature });
750
- }
751
- return outputs;
752
- }));
753
- _LocalSolanaMobileWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
754
- return (yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignTransactions, "f").call(this, inputs.map(({ transaction }) => transaction)))
755
- .map((signedTransaction) => {
756
- return { signedTransaction };
757
- });
758
- }));
759
- _LocalSolanaMobileWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
760
- const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
761
- const addresses = inputs.map(({ account }) => jsBase64.fromUint8Array(account.publicKey));
762
- const messages = inputs.map(({ message }) => jsBase64.fromUint8Array(message));
763
- try {
764
- return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
765
- yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
766
- const signedMessages = (yield wallet.signMessages({
767
- addresses: addresses,
768
- payloads: messages,
769
- })).signed_payloads.map(jsBase64.toUint8Array);
770
- return signedMessages.map((signedMessage) => {
771
- return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
772
- });
773
- }));
774
- }
775
- catch (e) {
776
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
777
- }
778
- }));
779
- _LocalSolanaMobileWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
780
- const outputs = [];
781
- if (inputs.length > 1) {
782
- for (const input of inputs) {
783
- outputs.push(yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, input));
784
- }
785
- }
786
- else {
787
- return [yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, inputs[0])];
788
- }
789
- return outputs;
790
- }));
791
- _LocalSolanaMobileWalletAdapterWallet_performSignIn.set(this, (input) => __awaiter(this, void 0, void 0, function* () {
792
- var _f, _g, _h;
793
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, true, "f");
794
- try {
795
- const authorizationResult = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this, Object.assign(Object.assign({}, input), { domain: (_f = input === null || input === void 0 ? void 0 : input.domain) !== null && _f !== void 0 ? _f : window.location.host }));
796
- if (!authorizationResult.sign_in_result) {
797
- throw new Error("Sign in failed, no sign in result returned by wallet");
798
- }
799
- const signedInAddress = authorizationResult.sign_in_result.address;
800
- const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
801
- return {
802
- account: Object.assign(Object.assign({}, signedInAccount !== null && signedInAccount !== void 0 ? signedInAccount : {
803
- address: base58__default["default"].encode(jsBase64.toUint8Array(signedInAddress))
804
- }), { publicKey: jsBase64.toUint8Array(signedInAddress), chains: (_g = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.chains) !== null && _g !== void 0 ? _g : __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"), features: (_h = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.features) !== null && _h !== void 0 ? _h : authorizationResult.capabilities.features }),
805
- signedMessage: jsBase64.toUint8Array(authorizationResult.sign_in_result.signed_message),
806
- signature: jsBase64.toUint8Array(authorizationResult.sign_in_result.signature)
807
- };
808
- }
809
- catch (e) {
810
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
811
- }
812
- finally {
813
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false, "f");
814
- }
815
- }));
816
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, config.authorizationCache, "f");
817
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, config.appIdentity, "f");
818
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, config.chains, "f");
819
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_chainSelector, config.chainSelector, "f");
820
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, config.onWalletNotFound, "f");
821
- __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, {
822
- // In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
823
- // signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
824
- // 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
825
- // assume both are supported here. The features will be updated based on the actual connected
826
- // wallets capabilities during connection regardless, so this is safe.
827
- [walletStandardFeatures.SolanaSignAndSendTransaction]: {
828
- version: '1.0.0',
829
- supportedTransactionVersions: ['legacy', 0],
830
- signAndSendTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
831
- },
832
- [walletStandardFeatures.SolanaSignTransaction]: {
833
- version: '1.0.0',
834
- supportedTransactionVersions: ['legacy', 0],
835
- signTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signTransaction, "f"),
836
- },
837
- }, "f");
838
- }
839
- get version() {
840
- return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_version, "f");
841
- }
842
- get name() {
843
- return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_name, "f");
844
- }
845
- get url() {
846
- return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_url, "f");
847
- }
848
- get icon() {
849
- return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_icon, "f");
850
- }
851
- get chains() {
852
- return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f");
853
- }
854
- get features() {
855
- return Object.assign({ [features.StandardConnect]: {
856
- version: '1.0.0',
857
- connect: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connect, "f"),
858
- }, [features.StandardDisconnect]: {
859
- version: '1.0.0',
860
- disconnect: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_disconnect, "f"),
861
- }, [features.StandardEvents]: {
862
- version: '1.0.0',
863
- on: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_on, "f"),
864
- }, [walletStandardFeatures.SolanaSignMessage]: {
865
- version: '1.0.0',
866
- signMessage: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signMessage, "f"),
867
- }, [walletStandardFeatures.SolanaSignIn]: {
868
- version: '1.0.0',
869
- signIn: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signIn, "f"),
870
- } }, __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, "f"));
871
- }
872
- get accounts() {
873
- var _a, _b;
874
- return (_b = (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : [];
636
+ class LocalConnectionModal extends EmbeddedModal {
637
+ contentStyles = css$3;
638
+ contentHtml = ErrorDialogHtml$3;
639
+ initWithCallback(callback) {
640
+ super.init();
641
+ this.#prepareLaunchAction(callback);
642
+ }
643
+ #prepareLaunchAction(callback) {
644
+ const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
645
+ const listener = async () => {
646
+ launchButton?.removeEventListener('click', listener);
647
+ this.close();
648
+ callback();
649
+ };
650
+ launchButton?.addEventListener('click', listener);
875
651
  }
876
- get connected() {
877
- return !!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
652
+ }
653
+ const ErrorDialogHtml$3 = `
654
+ <svg class="mobile-wallet-adapter-embedded-modal-launch-icon" width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
655
+ <path d="M21.6 48C7.2 48 0 40.8 0 26.4V21.6C0 7.2 7.2 0 21.6 0H26.4C40.8 0 48 7.2 48 21.6V26.4C48 40.8 40.8 48 26.4 48H21.6Z" fill="#15994E"/>
656
+ <mask id="mask0_189_522" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
657
+ <rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
658
+ </mask>
659
+ <g mask="url(#mask0_189_522)">
660
+ <mask id="mask1_189_522" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
661
+ <rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
662
+ </mask>
663
+ <g mask="url(#mask1_189_522)">
664
+ <path d="M22.1092 26.1208L19.4498 23.4615C19.1736 23.1851 18.8253 23.0468 18.4048 23.0468C17.9846 23.0468 17.6363 23.1851 17.3598 23.4615C17.0836 23.7377 16.9468 24.0861 16.9495 24.5065C16.9522 24.9267 17.0916 25.275 17.3678 25.5512L21.0405 29.2238C21.3463 29.5276 21.7031 29.6795 22.1108 29.6795C22.5184 29.6795 22.8742 29.5276 23.1782 29.2238L30.5918 21.8098C30.8683 21.5336 31.0065 21.1867 31.0065 20.7692C31.0065 20.3514 30.8683 20.0044 30.5918 19.7282C30.3156 19.4517 29.9673 19.3135 29.5468 19.3135C29.1266 19.3135 28.7784 19.4517 28.5022 19.7282L22.1092 26.1208ZM23.9998 37.6042C22.113 37.6042 20.3425 37.2473 18.6885 36.5335C17.0343 35.8197 15.5954 34.8512 14.3718 33.6278C13.1485 32.4043 12.18 30.9654 11.4662 29.3112C10.7524 27.6572 10.3955 25.8867 10.3955 23.9998C10.3955 22.113 10.7524 20.3425 11.4662 18.6885C12.18 17.0343 13.1485 15.5954 14.3718 14.3718C15.5954 13.1485 17.0343 12.18 18.6885 11.4662C20.3425 10.7524 22.113 10.3955 23.9998 10.3955C25.8867 10.3955 27.6572 10.7524 29.3112 11.4662C30.9654 12.18 32.4043 13.1485 33.6278 14.3718C34.8512 15.5954 35.8197 17.0343 36.5335 18.6885C37.2473 20.3425 37.6042 22.113 37.6042 23.9998C37.6042 25.8867 37.2473 27.6572 36.5335 29.3112C35.8197 30.9654 34.8512 32.4043 33.6278 33.6278C32.4043 34.8512 30.9654 35.8197 29.3112 36.5335C27.6572 37.2473 25.8867 37.6042 23.9998 37.6042Z" fill="white"/>
665
+ </g>
666
+ </g>
667
+ </svg>
668
+ <div class="mobile-wallet-adapter-embedded-modal-title">Ready to connect!</div>
669
+ <div>
670
+ <button data-modal-action id="mobile-wallet-adapter-launch-action" class="mobile-wallet-adapter-embedded-modal-launch-action">
671
+ Connect Wallet
672
+ </button>
673
+ </div>
674
+ `;
675
+ const css$3 = `
676
+ .mobile-wallet-adapter-embedded-modal-close {
677
+ display: none;
678
+ }
679
+ .mobile-wallet-adapter-embedded-modal-content {
680
+ text-align: center;
681
+ min-width: 300px;
682
+ }
683
+ .mobile-wallet-adapter-embedded-modal-launch-icon {
684
+ margin-top: 24px;
685
+ }
686
+ .mobile-wallet-adapter-embedded-modal-title {
687
+ margin: 18px 100px 30px 100px;
688
+ color: #000000;
689
+ font-size: 2.75em;
690
+ font-weight: 600;
691
+ }
692
+ .mobile-wallet-adapter-embedded-modal-launch-action {
693
+ display: block;
694
+ width: 100%;
695
+ height: 56px;
696
+ font-size: 1.25em;
697
+ background: #000000;
698
+ color: #FFFFFF;
699
+ border-radius: 18px;
700
+ }
701
+ /* Smaller screens */
702
+ @media all and (max-width: 600px) {
703
+ .mobile-wallet-adapter-embedded-modal-title {
704
+ font-size: 1.5em;
705
+ margin-right: 12px;
706
+ margin-left: 12px;
878
707
  }
879
- get isAuthorized() {
880
- return !!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
708
+ }
709
+ `;
710
+
711
+ class LoopbackPermissionBlockedModal extends EmbeddedModal {
712
+ contentStyles = css$2;
713
+ get contentHtml() {
714
+ const instructions = getIsPwaLaunchedAsApp()
715
+ ? 'Long press the app icon on your home screen to open site settings'
716
+ : 'Tap the lock or settings icon in the address bar to open site settings';
717
+ return ErrorDialogHtml$2.replace('{{PERMISSION_INSTRUCTION_DETAIL}}', instructions);
881
718
  }
882
- get currentAuthorization() {
883
- return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
719
+ async init() {
720
+ super.init();
721
+ this.#prepareLaunchAction();
884
722
  }
885
- get cachedAuthorizationResult() {
886
- return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
723
+ #prepareLaunchAction() {
724
+ const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
725
+ const listener = async (event) => {
726
+ launchButton?.removeEventListener('click', listener);
727
+ this.close(event);
728
+ };
729
+ launchButton?.addEventListener('click', listener);
887
730
  }
888
731
  }
889
- _LocalSolanaMobileWalletAdapterWallet_listeners = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_version = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_name = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_url = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_icon = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_appIdentity = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_authorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_authorizationCache = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connecting = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connectionGeneration = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_chains = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_chainSelector = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_optionalFeatures = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_on = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connect = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performAuthorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performReauthorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_disconnect = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_transact = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignTransactions = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signMessage = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signIn = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignIn = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_instances = new WeakSet(), _LocalSolanaMobileWalletAdapterWallet_emit = function _LocalSolanaMobileWalletAdapterWallet_emit(event, ...args) {
890
- var _a;
891
- // eslint-disable-next-line prefer-spread
892
- (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener.apply(null, args));
893
- }, _LocalSolanaMobileWalletAdapterWallet_off = function _LocalSolanaMobileWalletAdapterWallet_off(event, listener) {
894
- var _a;
895
- __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
896
- };
897
- class RemoteSolanaMobileWalletAdapterWallet {
898
- constructor(config) {
899
- _RemoteSolanaMobileWalletAdapterWallet_instances.add(this);
900
- _RemoteSolanaMobileWalletAdapterWallet_listeners.set(this, {});
901
- _RemoteSolanaMobileWalletAdapterWallet_version.set(this, '1.0.0'); // wallet-standard version
902
- _RemoteSolanaMobileWalletAdapterWallet_name.set(this, SolanaMobileWalletAdapterRemoteWalletName);
903
- _RemoteSolanaMobileWalletAdapterWallet_url.set(this, 'https://solanamobile.com/wallets');
904
- _RemoteSolanaMobileWalletAdapterWallet_icon.set(this, icon);
905
- _RemoteSolanaMobileWalletAdapterWallet_appIdentity.set(this, void 0);
906
- _RemoteSolanaMobileWalletAdapterWallet_authorization.set(this, void 0);
907
- _RemoteSolanaMobileWalletAdapterWallet_authorizationCache.set(this, void 0);
908
- _RemoteSolanaMobileWalletAdapterWallet_connecting.set(this, false);
909
- /**
910
- * Every time the connection is recycled in some way (eg. `disconnect()` is called)
911
- * increment this and use it to make sure that `transact` calls from the previous
912
- * 'generation' don't continue to do work and throw exceptions.
913
- */
914
- _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration.set(this, 0);
915
- _RemoteSolanaMobileWalletAdapterWallet_chains.set(this, []);
916
- _RemoteSolanaMobileWalletAdapterWallet_chainSelector.set(this, void 0);
917
- _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures.set(this, void 0);
918
- _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound.set(this, void 0);
919
- _RemoteSolanaMobileWalletAdapterWallet_hostAuthority.set(this, void 0);
920
- _RemoteSolanaMobileWalletAdapterWallet_session.set(this, void 0);
921
- _RemoteSolanaMobileWalletAdapterWallet_on.set(this, (event, listener) => {
922
- var _a;
923
- ((_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event] = [listener]);
924
- return () => __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_off).call(this, event, listener);
925
- });
926
- _RemoteSolanaMobileWalletAdapterWallet_connect.set(this, ({ silent } = {}) => __awaiter(this, void 0, void 0, function* () {
927
- if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, "f") || this.connected) {
928
- return { accounts: this.accounts };
929
- }
930
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, true, "f");
931
- try {
932
- yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this);
933
- }
934
- catch (e) {
935
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
936
- }
937
- finally {
938
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false, "f");
939
- }
940
- return { accounts: this.accounts };
941
- }));
942
- _RemoteSolanaMobileWalletAdapterWallet_performAuthorization.set(this, (signInPayload) => __awaiter(this, void 0, void 0, function* () {
943
- try {
944
- const cachedAuthorizationResult = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
945
- if (cachedAuthorizationResult) {
946
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
947
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorizationResult);
948
- return cachedAuthorizationResult;
949
- }
950
- if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f"))
951
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, undefined, "f");
952
- const selectedChain = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, "f").select(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"));
953
- return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
954
- const [capabilities, mwaAuthorizationResult] = yield Promise.all([
955
- wallet.getCapabilities(),
956
- wallet.authorize({
957
- chain: selectedChain,
958
- identity: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, "f"),
959
- sign_in_payload: signInPayload,
960
- })
961
- ]);
962
- const accounts = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
963
- const authorizationResult = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts, chain: selectedChain, capabilities: capabilities });
964
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
965
- Promise.all([
966
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, capabilities),
967
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorizationResult),
968
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorizationResult),
969
- ]);
970
- return authorizationResult;
971
- }));
972
- }
973
- catch (e) {
974
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
975
- }
976
- }));
977
- _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult.set(this, (authorization) => __awaiter(this, void 0, void 0, function* () {
978
- var _a;
979
- const didPublicKeysChange =
980
- // Case 1: We started from having no authorization.
981
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f") == null ||
982
- // Case 2: The number of authorized accounts changed.
983
- ((_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorization.accounts.length ||
984
- // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
985
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
986
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, authorization, "f");
987
- if (didPublicKeysChange) {
988
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
989
- }
990
- }));
991
- _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult.set(this, (capabilities) => __awaiter(this, void 0, void 0, function* () {
992
- // TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
993
- const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
994
- const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions ||
995
- capabilities.features.includes('solana:signAndSendTransaction');
996
- const didCapabilitiesChange = walletStandardFeatures.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
997
- walletStandardFeatures.SolanaSignTransaction in this.features !== supportsSignTransaction;
998
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, Object.assign(Object.assign({}, (supportsSignAndSendTransaction && {
999
- [walletStandardFeatures.SolanaSignAndSendTransaction]: {
1000
- version: '1.0.0',
1001
- supportedTransactionVersions: capabilities.supported_transaction_versions,
1002
- signAndSendTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
1003
- },
1004
- })), (supportsSignTransaction && {
1005
- [walletStandardFeatures.SolanaSignTransaction]: {
1006
- version: '1.0.0',
1007
- supportedTransactionVersions: capabilities.supported_transaction_versions,
1008
- signTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, "f"),
1009
- },
1010
- })), "f");
1011
- if (didCapabilitiesChange) {
1012
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { features: this.features });
1013
- }
1014
- }));
1015
- _RemoteSolanaMobileWalletAdapterWallet_performReauthorization.set(this, (wallet, authToken, chain) => __awaiter(this, void 0, void 0, function* () {
1016
- var _b, _c;
732
+ const ErrorDialogHtml$2 = `
733
+ <div class="mobile-wallet-adapter-embedded-modal-header">
734
+ Local Wallet Connection
735
+ </div>
736
+ <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
737
+ <path d="M21.6 48C7.2 48 0 40.8 0 26.4V21.6C0 7.2 7.2 0 21.6 0H26.4C40.8 0 48 7.2 48 21.6V26.4C48 40.8 40.8 48 26.4 48H21.6Z" fill="#ED1515"/>
738
+ <mask id="mask0_147_1364" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
739
+ <rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
740
+ </mask>
741
+ <g mask="url(#mask0_147_1364)">
742
+ <path d="M20.1398 36.2705C19.7363 36.2705 19.3508 36.1945 18.9835 36.0425C18.6162 35.8907 18.2916 35.674 18.0098 35.3922L12.6072 29.9895C12.3254 29.7077 12.1086 29.3832 11.9568 29.0158C11.8048 28.6485 11.7288 28.2631 11.7288 27.8595V20.1395C11.7288 19.736 11.8048 19.3505 11.9568 18.9832C12.1086 18.6158 12.3254 18.2913 12.6072 18.0095L18.0098 12.6068C18.2916 12.3251 18.6162 12.1083 18.9835 11.9565C19.3508 11.8045 19.7363 11.7285 20.1398 11.7285H27.8598C28.2634 11.7285 28.6488 11.8045 29.0162 11.9565C29.3835 12.1083 29.708 12.3251 29.9898 12.6068L35.3925 18.0095C35.6743 18.2913 35.891 18.6158 36.0428 18.9832C36.1948 19.3505 36.2708 19.736 36.2708 20.1395V27.8595C36.2708 28.2631 36.1948 28.6485 36.0428 29.0158C35.891 29.3832 35.6743 29.7077 35.3925 29.9895L29.9898 35.3922C29.708 35.674 29.3835 35.8907 29.0162 36.0425C28.6488 36.1945 28.2634 36.2705 27.8598 36.2705H20.1398ZM20.1732 33.2372H27.8265L33.2375 27.8262V20.1728L27.8265 14.7618H20.1732L14.7622 20.1728V27.8262L20.1732 33.2372ZM23.9998 25.9538L26.7868 28.7408C27.0473 29.0013 27.3729 29.1302 27.7638 29.1275C28.1549 29.1248 28.4807 28.9933 28.7412 28.7328C29.0016 28.4724 29.1318 28.1466 29.1318 27.7555C29.1318 27.3646 29.0016 27.039 28.7412 26.7785L25.9542 23.9995L28.7412 21.2125C29.0016 20.9521 29.1318 20.6264 29.1318 20.2355C29.1318 19.8444 29.0016 19.5186 28.7412 19.2582C28.4807 18.9977 28.1549 18.8675 27.7638 18.8675C27.3729 18.8675 27.0473 18.9977 26.7868 19.2582L23.9998 22.0452L21.2128 19.2582C20.9524 18.9977 20.628 18.8675 20.2398 18.8675C19.8514 18.8675 19.5269 18.9977 19.2665 19.2582C19.006 19.5186 18.8758 19.8444 18.8758 20.2355C18.8758 20.6264 19.006 20.9521 19.2665 21.2125L22.0455 23.9995L19.2585 26.7865C18.998 27.047 18.8692 27.3713 18.8718 27.7595C18.8745 28.148 19.006 28.4724 19.2665 28.7328C19.5269 28.9933 19.8527 29.1235 20.2438 29.1235C20.6347 29.1235 20.9604 28.9933 21.2208 28.7328L23.9998 25.9538Z" fill="black"/>
743
+ </g>
744
+ </svg>
745
+ <div class="mobile-wallet-adapter-embedded-modal-title">
746
+ Your wallet connection is blocked
747
+ </div>
748
+ <div id="mobile-wallet-adapter-local-launch-message" class="mobile-wallet-adapter-embedded-modal-subtitle">
749
+ Visit site settings in the address bar and allow "Apps on Device".
750
+ </div>
751
+
752
+ <div class="mobile-wallet-adapter-embedded-modal-divider"><hr></div>
753
+ <div class="mobile-wallet-adapter-embedded-modal-footer">
754
+ <div class="mobile-wallet-adapter-embedded-modal-details">
755
+ <!-- Clickable header (label associated with the checkbox) -->
756
+ <label for="collapsible-1" class="mobile-wallet-adapter-embedded-modal-details-collapsible-header">
757
+ <!-- Hidden checkbox to track state -->
758
+ <input type="checkbox" id="collapsible-1" class="mobile-wallet-adapter-embedded-modal-details-collapsible-input">
759
+ <span class="mobile-wallet-adapter-embedded-modal-details-collapsible-header-label">
760
+ See details
761
+ </span>
762
+ <svg class="mobile-wallet-adapter-embedded-modal-details-collapsible-header-icon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
763
+ <mask id="mask0_147_1382" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="24" height="24">
764
+ <rect width="24" height="24" fill="#D9D9D9"/>
765
+ </mask>
766
+ <g mask="url(#mask0_147_1382)">
767
+ <path d="M11.9999 17.0811C11.8506 17.0811 11.7087 17.0563 11.5741 17.0067C11.4395 16.957 11.3162 16.8762 11.2042 16.7643L6.57924 12.1393C6.36801 11.9281 6.26656 11.667 6.27489 11.3561C6.28322 11.0453 6.39301 10.7842 6.60424 10.573C6.81547 10.3618 7.08069 10.2561 7.39989 10.2561C7.71909 10.2561 7.9843 10.3618 8.19554 10.573L11.9999 14.3773L15.8292 10.548C16.0405 10.3368 16.3015 10.2353 16.6124 10.2436C16.9233 10.252 17.1843 10.3618 17.3955 10.573C17.6068 10.7842 17.7124 11.0494 17.7124 11.3686C17.7124 11.6878 17.6068 11.9531 17.3955 12.1643L12.7955 16.7643C12.6836 16.8762 12.5603 16.957 12.4257 17.0067C12.2911 17.0563 12.1492 17.0811 11.9999 17.0811Z" fill="black"/>
768
+ </g>
769
+ </svg>
770
+ </label>
771
+
772
+ <!-- Content to show/hide -->
773
+ <ul class="mobile-wallet-adapter-embedded-modal-details-collapsible-content">
774
+ <li>{{PERMISSION_INSTRUCTION_DETAIL}}</li>
775
+ <li>Allow "Apps on Device"</li>
776
+ </ul>
777
+ </div>
778
+ </div>
779
+ <div>
780
+ <button data-modal-action id="mobile-wallet-adapter-launch-action" class="mobile-wallet-adapter-embedded-modal-launch-action">
781
+ Got it
782
+ </button>
783
+ </div>
784
+ `;
785
+ const css$2 = `
786
+ .mobile-wallet-adapter-embedded-modal-close {
787
+ display: none;
788
+ }
789
+ .mobile-wallet-adapter-embedded-modal-content {
790
+ text-align: center;
791
+ }
792
+ .mobile-wallet-adapter-embedded-modal-header {
793
+ margin: 18px auto 30px auto;
794
+ color: #7D9093;
795
+ font-size: 1.0em;
796
+ font-weight: 500;
797
+ }
798
+ .mobile-wallet-adapter-embedded-modal-title {
799
+ margin: 18px 100px auto 100px;
800
+ color: #000000;
801
+ font-size: 2.75em;
802
+ font-weight: 600;
803
+ }
804
+ .mobile-wallet-adapter-embedded-modal-subtitle {
805
+ margin: 12px 60px 30px 60px;
806
+ color: #7D9093;
807
+ font-size: 1.25em;
808
+ font-weight: 400;
809
+ }
810
+ .mobile-wallet-adapter-embedded-modal-details-collapsible-header {
811
+ display: flex;
812
+ flex-direction: row;
813
+ justify-content: space-between;
814
+ margin: 10px auto 10px auto;
815
+ color: #000000;
816
+ font-size: 1.5em;
817
+ font-weight: 600;
818
+ cursor: pointer; /* Show pointer on hover */
819
+ transition: background 0.2s ease; /* Smooth background change */
820
+ }
821
+ .mobile-wallet-adapter-embedded-modal-details-collapsible-header-icon {
822
+ transition: rotate 0.3s ease;
823
+ }
824
+ .mobile-wallet-adapter-embedded-modal-details-collapsible-input {
825
+ display: none; /* Hide the checkbox */
826
+ }
827
+ .mobile-wallet-adapter-embedded-modal-details-collapsible-content {
828
+ margin: 0px auto 40px auto;
829
+ max-height: 0px; /* Collapse content */
830
+ overflow: hidden; /* Hide overflow when collapsed */
831
+ transition: max-height 0.3s ease; /* Smooth transition */
832
+ }
833
+ .mobile-wallet-adapter-embedded-modal-details-collapsible-content li {
834
+ margin: 20px auto;
835
+ color: #000000;
836
+ font-size: 1.25em;
837
+ font-weight: 400;
838
+ text-align: left;
839
+ }
840
+ /* When checkbox is checked, show content */
841
+ .mobile-wallet-adapter-embedded-modal-details-collapsible-header:has(> input:checked) ~ .mobile-wallet-adapter-embedded-modal-details-collapsible-content {
842
+ max-height: 300px;
843
+ }
844
+ .mobile-wallet-adapter-embedded-modal-details-collapsible-header:has(> input:checked) > .mobile-wallet-adapter-embedded-modal-details-collapsible-header-icon {
845
+ rotate: 180deg;
846
+ }
847
+ .mobile-wallet-adapter-embedded-modal-launch-action {
848
+ display: block;
849
+ width: 100%;
850
+ height: 56px;
851
+ /*margin-top: 40px;*/
852
+ font-size: 1.25em;
853
+ /*line-height: 24px;*/
854
+ /*letter-spacing: -1%;*/
855
+ background: #000000;
856
+ color: #FFFFFF;
857
+ border-radius: 18px;
858
+ }
859
+ /* Smaller screens */
860
+ @media all and (max-width: 600px) {
861
+ .mobile-wallet-adapter-embedded-modal-title {
862
+ font-size: 1.75em;
863
+ margin-right: 12px;
864
+ margin-left: 12px;
865
+ }
866
+ .mobile-wallet-adapter-embedded-modal-subtitle {
867
+ margin-right: 12px;
868
+ margin-left: 12px;
869
+ }
870
+ }
871
+ `;
872
+
873
+ class LoopbackPermissionModal extends EmbeddedModal {
874
+ contentStyles = css$1;
875
+ contentHtml = ErrorDialogHtml$1;
876
+ async init() {
877
+ super.init();
878
+ this.#prepareLaunchAction();
879
+ }
880
+ #prepareLaunchAction() {
881
+ const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
882
+ const listener = async () => {
883
+ launchButton?.removeEventListener('click', listener);
1017
884
  try {
1018
- const [capabilities, mwaAuthorizationResult] = yield Promise.all([
1019
- (_c = (_b = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _b === void 0 ? void 0 : _b.capabilities) !== null && _c !== void 0 ? _c : yield wallet.getCapabilities(),
1020
- wallet.authorize({
1021
- auth_token: authToken,
1022
- identity: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, "f"),
1023
- chain: chain
1024
- })
1025
- ]);
1026
- const accounts = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
1027
- const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts: accounts, chain: chain, capabilities: capabilities });
1028
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1029
- Promise.all([
1030
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
1031
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
1032
- ]);
885
+ // Trigger LNA permission prompting
886
+ await fetch('http://localhost');
1033
887
  }
1034
- catch (e) {
1035
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_disconnect, "f").call(this);
1036
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1037
- }
1038
- }));
1039
- _RemoteSolanaMobileWalletAdapterWallet_disconnect.set(this, () => __awaiter(this, void 0, void 0, function* () {
1040
- var _d;
1041
- var _e;
1042
- (_d = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f")) === null || _d === void 0 ? void 0 : _d.close();
1043
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1044
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false, "f");
1045
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, (_e = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f"), _e++, _e), "f");
1046
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, undefined, "f");
1047
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, undefined, "f");
1048
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
1049
- }));
1050
- _RemoteSolanaMobileWalletAdapterWallet_transact.set(this, (callback) => __awaiter(this, void 0, void 0, function* () {
1051
- var _f;
1052
- const walletUriBase = (_f = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _f === void 0 ? void 0 : _f.wallet_uri_base;
1053
- const baseConfig = walletUriBase ? { baseUri: walletUriBase } : undefined;
1054
- const remoteConfig = Object.assign(Object.assign({}, baseConfig), { remoteHostAuthority: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, "f") });
1055
- const currentConnectionGeneration = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f");
1056
- const modal = new RemoteConnectionModal();
1057
- if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f")) {
1058
- return callback(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f").wallet);
1059
- }
1060
- try {
1061
- const { associationUrl, close, wallet } = yield mobileWalletAdapterProtocol.startRemoteScenario(remoteConfig);
1062
- const removeCloseListener = modal.addEventListener('close', (event) => {
1063
- if (event)
1064
- close();
888
+ catch (e) { /* Ignore errors from fetch */ }
889
+ this.close();
890
+ };
891
+ launchButton?.addEventListener('click', listener);
892
+ }
893
+ }
894
+ const ErrorDialogHtml$1 = `
895
+ <div class="mobile-wallet-adapter-embedded-modal-title">Allow connections to your wallet</div>
896
+ <div id="mobile-wallet-adapter-local-launch-message" class="mobile-wallet-adapter-embedded-modal-subtitle">
897
+ Tap "Allow" on the next screen
898
+ </div>
899
+ <svg class="mobile-wallet-adapter-embedded-modal-permission-prompt-mock" xmlns="http://www.w3.org/2000/svg" width="281" height="83" viewBox="0 0 281 83" fill="none">
900
+ <rect width="281" height="83" rx="22" fill="#F0F3F5"/>
901
+ <path d="M254.194 64L252.626 56.657H254.047L254.866 61.452L254.985 62.278H255.02L255.146 61.452L255.993 57.497H257.4L258.254 61.431L258.373 62.278H258.415L258.534 61.431L259.346 56.657H260.718L259.143 64H257.673L256.826 59.961L256.693 59.093H256.651L256.511 59.961L255.664 64H254.194Z" fill="black"/>
902
+ <path d="M248.837 64.231C248.147 64.231 247.54 64.07 247.017 63.748C246.495 63.426 246.086 62.978 245.792 62.404C245.498 61.83 245.351 61.1673 245.351 60.416V60.241C245.351 59.4897 245.498 58.827 245.792 58.253C246.086 57.679 246.495 57.2333 247.017 56.916C247.54 56.594 248.147 56.433 248.837 56.433C249.528 56.433 250.135 56.594 250.657 56.916C251.18 57.2333 251.588 57.679 251.882 58.253C252.176 58.827 252.323 59.4897 252.323 60.241V60.416C252.323 61.1673 252.176 61.83 251.882 62.404C251.588 62.978 251.18 63.426 250.657 63.748C250.135 64.07 249.528 64.231 248.837 64.231ZM248.837 62.824C249.43 62.824 249.897 62.607 250.237 62.173C250.583 61.7343 250.755 61.1417 250.755 60.395V60.262C250.755 59.5107 250.583 58.918 250.237 58.484C249.897 58.05 249.43 57.833 248.837 57.833C248.249 57.833 247.783 58.05 247.437 58.484C247.092 58.918 246.919 59.5107 246.919 60.262V60.395C246.919 61.1417 247.092 61.7343 247.437 62.173C247.783 62.607 248.249 62.824 248.837 62.824Z" fill="black"/>
903
+ <path d="M242.298 64.231C241.467 64.231 240.814 63.993 240.338 63.517C239.866 63.0364 239.631 62.3737 239.631 61.529V53.78H241.178V61.389C241.178 62.3317 241.591 62.803 242.417 62.803C242.65 62.803 242.865 62.7587 243.061 62.67C243.257 62.5814 243.464 62.4367 243.684 62.236L244.538 63.377C244.225 63.6664 243.884 63.881 243.516 64.021C243.152 64.161 242.746 64.231 242.298 64.231ZM237.51 55.061V53.78H240.611V55.061H237.51Z" fill="black"/>
904
+ <path d="M234.463 64.231C233.633 64.231 232.979 63.993 232.503 63.517C232.032 63.0364 231.796 62.3737 231.796 61.529V53.78H233.343V61.389C233.343 62.3317 233.756 62.803 234.582 62.803C234.816 62.803 235.03 62.7587 235.226 62.67C235.422 62.5814 235.63 62.4367 235.849 62.236L236.703 63.377C236.391 63.6664 236.05 63.881 235.681 64.021C235.317 64.161 234.911 64.231 234.463 64.231ZM229.675 55.061V53.78H232.776V55.061H229.675Z" fill="black"/>
905
+ <path d="M221.442 64L224.557 53.976H226.132L229.233 64H227.581L225.642 56.972L225.341 55.761H225.299L225.005 56.972L223.073 64H221.442ZM222.835 61.634L223.255 60.29H227.371L227.805 61.634H222.835Z" fill="black"/>
906
+ <path d="M178.261 64L175.034 60.066V60.024L178.121 56.657H180.011L176.504 60.423V59.632L180.165 64H178.261ZM173.543 64V53.78H175.097V64H173.543Z" fill="#7D9093" fill-opacity="0.5"/>
907
+ <path d="M169.306 64.224C168.588 64.224 167.958 64.0653 167.416 63.748C166.88 63.426 166.462 62.9803 166.163 62.411C165.865 61.837 165.715 61.1673 165.715 60.402V60.248C165.715 59.4873 165.862 58.8223 166.156 58.253C166.45 57.679 166.863 57.2333 167.395 56.916C167.927 56.594 168.546 56.433 169.25 56.433C169.978 56.433 170.59 56.6056 171.084 56.951C171.579 57.2917 171.955 57.777 172.211 58.407L170.874 58.995C170.72 58.6123 170.508 58.323 170.237 58.127C169.967 57.9263 169.633 57.826 169.236 57.826C168.63 57.826 168.149 58.0383 167.794 58.463C167.444 58.883 167.269 59.4616 167.269 60.199V60.465C167.269 61.1837 167.454 61.7577 167.822 62.187C168.196 62.6163 168.69 62.831 169.306 62.831C169.712 62.831 170.06 62.733 170.349 62.537C170.639 62.341 170.877 62.0423 171.063 61.641L172.379 62.285C172.188 62.6957 171.941 63.0457 171.637 63.335C171.334 63.6243 170.986 63.846 170.594 64C170.202 64.1493 169.773 64.224 169.306 64.224Z" fill="#7D9093" fill-opacity="0.5"/>
908
+ <path d="M161.003 64.231C160.312 64.231 159.706 64.07 159.183 63.748C158.66 63.426 158.252 62.978 157.958 62.404C157.664 61.83 157.517 61.1673 157.517 60.416V60.241C157.517 59.4897 157.664 58.827 157.958 58.253C158.252 57.679 158.66 57.2333 159.183 56.916C159.706 56.594 160.312 56.433 161.003 56.433C161.694 56.433 162.3 56.594 162.823 56.916C163.346 57.2333 163.754 57.679 164.048 58.253C164.342 58.827 164.489 59.4897 164.489 60.241V60.416C164.489 61.1673 164.342 61.83 164.048 62.404C163.754 62.978 163.346 63.426 162.823 63.748C162.3 64.07 161.694 64.231 161.003 64.231ZM161.003 62.824C161.596 62.824 162.062 62.607 162.403 62.173C162.748 61.7343 162.921 61.1417 162.921 60.395V60.262C162.921 59.5107 162.748 58.918 162.403 58.484C162.062 58.05 161.596 57.833 161.003 57.833C160.415 57.833 159.948 58.05 159.603 58.484C159.258 58.918 159.085 59.5107 159.085 60.262V60.395C159.085 61.1417 159.258 61.7343 159.603 62.173C159.948 62.607 160.415 62.824 161.003 62.824Z" fill="#7D9093" fill-opacity="0.5"/>
909
+ <path d="M154.463 64.231C153.633 64.231 152.979 63.993 152.503 63.517C152.032 63.0364 151.796 62.3737 151.796 61.529V53.78H153.343V61.389C153.343 62.3317 153.756 62.803 154.582 62.803C154.816 62.803 155.03 62.7587 155.226 62.67C155.422 62.5814 155.63 62.4367 155.849 62.236L156.703 63.377C156.391 63.6664 156.05 63.881 155.681 64.021C155.317 64.161 154.911 64.231 154.463 64.231ZM149.675 55.061V53.78H152.776V55.061H149.675Z" fill="#7D9093" fill-opacity="0.5"/>
910
+ <path d="M142.24 64V53.976H145.544C146.421 53.976 147.112 54.1953 147.616 54.634C148.12 55.0726 148.372 55.6583 148.372 56.391V56.566C148.372 57.0886 148.246 57.5366 147.994 57.91C147.742 58.2833 147.38 58.5586 146.909 58.736V58.792C147.492 58.9226 147.947 59.2003 148.274 59.625C148.605 60.045 148.771 60.5606 148.771 61.172V61.361C148.771 61.893 148.645 62.3573 148.393 62.754C148.145 63.1506 147.795 63.4586 147.343 63.678C146.895 63.8926 146.365 64 145.754 64H142.24ZM143.794 62.656H145.572C146.085 62.656 146.482 62.5253 146.762 62.264C147.042 62.0026 147.182 61.6293 147.182 61.144V60.99C147.182 60.5046 147.037 60.1313 146.748 59.87C146.463 59.604 146.05 59.471 145.509 59.471H143.36V58.183H145.32C145.791 58.183 146.153 58.064 146.405 57.826C146.657 57.588 146.783 57.2496 146.783 56.811V56.685C146.783 56.2416 146.657 55.9033 146.405 55.67C146.157 55.4366 145.796 55.32 145.32 55.32H143.794V62.656Z" fill="#7D9093" fill-opacity="0.5"/>
911
+ <rect x="18" y="17" width="246" height="7" rx="3.5" fill="#7D9093" fill-opacity="0.26"/>
912
+ <rect x="18" y="33" width="82" height="7" rx="3.5" fill="#7D9093" fill-opacity="0.26"/>
913
+ </svg>
914
+ <div>
915
+ <button data-modal-action id="mobile-wallet-adapter-launch-action" class="mobile-wallet-adapter-embedded-modal-launch-action">
916
+ Continue to Allow
917
+ </button>
918
+ </div>
919
+ `;
920
+ const css$1 = `
921
+ .mobile-wallet-adapter-embedded-modal-close {
922
+ display: none;
923
+ }
924
+ .mobile-wallet-adapter-embedded-modal-content {
925
+ text-align: center;
926
+ }
927
+ .mobile-wallet-adapter-embedded-modal-title {
928
+ margin: 18px 100px auto 100px;
929
+ color: #000000;
930
+ font-size: 2.75em;
931
+ font-weight: 600;
932
+ }
933
+ .mobile-wallet-adapter-embedded-modal-subtitle {
934
+ margin: 20px 60px 40px 60px;
935
+ color: #7D9093;
936
+ font-size: 1.25em;
937
+ font-weight: 400;
938
+ }
939
+ .mobile-wallet-adapter-embedded-modal-permission-prompt-mock {
940
+ width: 90%;
941
+ height: auto;
942
+ margin: 0 auto 30px auto;
943
+ display: block;
944
+ }
945
+ .mobile-wallet-adapter-embedded-modal-launch-action {
946
+ display: block;
947
+ width: 100%;
948
+ height: 56px;
949
+ font-size: 1.25em;
950
+ background: #000000;
951
+ color: #FFFFFF;
952
+ border-radius: 18px;
953
+ }
954
+ /* Smaller screens */
955
+ @media all and (max-width: 600px) {
956
+ .mobile-wallet-adapter-embedded-modal-title {
957
+ font-size: 1.5em;
958
+ margin-right: 12px;
959
+ margin-left: 12px;
960
+ }
961
+ .mobile-wallet-adapter-embedded-modal-subtitle {
962
+ margin-right: 12px;
963
+ margin-left: 12px;
964
+ }
965
+ }
966
+ `;
967
+
968
+ function getIsLocalAssociationSupported() {
969
+ return (typeof window !== 'undefined' &&
970
+ window.isSecureContext &&
971
+ typeof document !== 'undefined' &&
972
+ /android/i.test(navigator.userAgent));
973
+ }
974
+ function getIsRemoteAssociationSupported() {
975
+ return (typeof window !== 'undefined' &&
976
+ window.isSecureContext &&
977
+ typeof document !== 'undefined' &&
978
+ !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
979
+ }
980
+ // Source: https://github.com/anza-xyz/wallet-adapter/blob/master/packages/core/react/src/getEnvironment.ts#L14
981
+ // This is the same implementation that gated MWA in the Anza wallet-adapter-react library.
982
+ function isWebView(userAgentString) {
983
+ return /(WebView|Version\/.+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+)|; wv\).+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+))/i.test(userAgentString);
984
+ }
985
+ // Source: https://web.dev/learn/pwa/detection/
986
+ function getIsPwaLaunchedAsApp() {
987
+ // Check for Android TWA
988
+ const isAndroidTwa = typeof document !== 'undefined' && document.referrer.startsWith('android-app://');
989
+ // Check for display-mode: standalone, fullscreen, or minimal-ui
990
+ if (typeof window == 'undefined')
991
+ return isAndroidTwa;
992
+ const isStandalone = window.matchMedia('(display-mode: standalone)').matches;
993
+ const isFullscreen = window.matchMedia('(display-mode: fullscreen)').matches;
994
+ const isMinimalUI = window.matchMedia('(display-mode: minimal-ui)').matches;
995
+ // App mode if any of these conditions are true
996
+ return isAndroidTwa || isStandalone || isFullscreen || isMinimalUI;
997
+ }
998
+ async function checkLocalNetworkAccessPermission() {
999
+ try {
1000
+ let lnaPermission = await navigator.permissions.query({ name: "loopback-network" });
1001
+ if (lnaPermission.state === "granted") {
1002
+ // LNA permission already granted, continuing
1003
+ return;
1004
+ }
1005
+ else if (lnaPermission.state === "denied") {
1006
+ // LNA permission denied, aborting
1007
+ const modal = new LoopbackPermissionBlockedModal();
1008
+ modal.init();
1009
+ modal.open();
1010
+ throw new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, 'Local Network Access permission denied');
1011
+ }
1012
+ else if (lnaPermission.state === "prompt") {
1013
+ // Show permission explainer to user, and wait for the permission to change
1014
+ const modal = new LoopbackPermissionModal();
1015
+ const updatedState = await new Promise((resolve, reject) => {
1016
+ modal.addEventListener('close', (event) => {
1017
+ if (event) {
1018
+ reject(new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, 'Wallet connection cancelled by user', { event }));
1019
+ }
1065
1020
  });
1066
- modal.initWithQR(associationUrl.toString());
1067
- modal.open();
1068
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, { close, wallet: yield wallet }, "f");
1069
- removeCloseListener();
1070
- modal.close();
1071
- return yield callback(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f").wallet);
1072
- }
1073
- catch (e) {
1074
- modal.close();
1075
- if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f") !== currentConnectionGeneration) {
1076
- yield new Promise(() => { }); // Never resolve.
1077
- }
1078
- if (e instanceof Error &&
1079
- e.name === 'SolanaMobileWalletAdapterError' &&
1080
- e.code === 'ERROR_WALLET_NOT_FOUND') {
1081
- yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, "f").call(this, this);
1082
- }
1083
- throw e;
1084
- }
1085
- }));
1086
- _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized.set(this, () => {
1087
- if (!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f"))
1088
- throw new Error('Wallet not connected');
1089
- return { authToken: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").auth_token, chain: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").chain };
1090
- });
1091
- _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts.set(this, (accounts) => {
1092
- return accounts.map((account) => {
1093
- var _a, _b;
1094
- const publicKey = jsBase64.toUint8Array(account.address);
1095
- return {
1096
- address: base58__default["default"].encode(publicKey),
1097
- publicKey,
1098
- label: account.label,
1099
- icon: account.icon,
1100
- chains: (_a = account.chains) !== null && _a !== void 0 ? _a : __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"),
1101
- // TODO: get supported features from getCapabilities API
1102
- features: (_b = account.features) !== null && _b !== void 0 ? _b : DEFAULT_FEATURES
1021
+ lnaPermission.onchange = () => {
1022
+ lnaPermission.onchange = null; // cleanup
1023
+ resolve(lnaPermission.state);
1103
1024
  };
1025
+ modal.init();
1026
+ modal.open();
1104
1027
  });
1105
- });
1106
- _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions.set(this, (transactions) => __awaiter(this, void 0, void 0, function* () {
1107
- const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
1108
- try {
1109
- return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
1110
- yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
1111
- const signedTransactions = (yield wallet.signTransactions({
1112
- payloads: transactions.map(jsBase64.fromUint8Array),
1113
- })).signed_payloads.map(jsBase64.toUint8Array);
1114
- return signedTransactions;
1115
- }));
1028
+ if (updatedState === "granted") {
1029
+ // User has granted the permission, now we need another click to continue
1030
+ // Note: this is required to avoid being blocked by the browsers pop-up blocker
1031
+ const modal = new LocalConnectionModal();
1032
+ await new Promise((resolve, reject) => {
1033
+ modal.addEventListener('close', (event) => {
1034
+ if (event) {
1035
+ reject(new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, 'Wallet connection cancelled by user', { event }));
1036
+ }
1037
+ });
1038
+ modal.initWithCallback(async () => {
1039
+ resolve(true);
1040
+ });
1041
+ modal.open();
1042
+ });
1043
+ return;
1116
1044
  }
1117
- catch (e) {
1118
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1045
+ else {
1046
+ // recurse, to avoid duplicating above logic
1047
+ return await checkLocalNetworkAccessPermission();
1119
1048
  }
1120
- }));
1121
- _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction.set(this, (transaction, options) => __awaiter(this, void 0, void 0, function* () {
1122
- const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
1123
- try {
1124
- return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
1125
- const [capabilities, _1] = yield Promise.all([
1126
- wallet.getCapabilities(),
1127
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain)
1128
- ]);
1129
- if (capabilities.supports_sign_and_send_transactions) {
1130
- const signatures = (yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, options), { payloads: [jsBase64.fromUint8Array(transaction)] }))).signatures.map(jsBase64.toUint8Array);
1131
- return signatures[0];
1132
- }
1133
- else {
1134
- throw new Error('connected wallet does not support signAndSendTransaction');
1135
- }
1136
- }));
1049
+ }
1050
+ // Shouldn't ever get here
1051
+ throw new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, 'Local Network Access permission unknown');
1052
+ }
1053
+ catch (e) {
1054
+ if (e instanceof TypeError &&
1055
+ (e.message.includes('loopback-network') ||
1056
+ e.message.includes('local-network-access'))) {
1057
+ // LNA permission API not found, continuing
1058
+ return;
1059
+ }
1060
+ // Re-throw existing adapter errors as-is
1061
+ if (e instanceof mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError) {
1062
+ throw e;
1063
+ }
1064
+ // An unknown error occurred, wrap it
1065
+ throw new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, e instanceof Error ? e.message : 'Local Network Access permission unknown');
1066
+ }
1067
+ }
1068
+
1069
+ const SolanaMobileWalletAdapterWalletName = 'Mobile Wallet Adapter';
1070
+ const SolanaMobileWalletAdapterRemoteWalletName = 'Remote Mobile Wallet Adapter';
1071
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
1072
+ const DEFAULT_FEATURES = [walletStandardFeatures.SolanaSignAndSendTransaction, walletStandardFeatures.SolanaSignTransaction, walletStandardFeatures.SolanaSignMessage, walletStandardFeatures.SolanaSignIn];
1073
+ const WALLET_ASSOCIATION_TIMEOUT = 30_000;
1074
+ class LocalSolanaMobileWalletAdapterWallet {
1075
+ #listeners = {};
1076
+ #version = '1.0.0'; // wallet-standard version
1077
+ #name = SolanaMobileWalletAdapterWalletName;
1078
+ #url = 'https://solanamobile.com/wallets';
1079
+ #icon = icon;
1080
+ #appIdentity;
1081
+ #authorization;
1082
+ #authorizationCache;
1083
+ #connecting = false;
1084
+ /**
1085
+ * Every time the connection is recycled in some way (eg. `disconnect()` is called)
1086
+ * increment this and use it to make sure that `transact` calls from the previous
1087
+ * 'generation' don't continue to do work and throw exceptions.
1088
+ */
1089
+ #connectionGeneration = 0;
1090
+ #chains = [];
1091
+ #chainSelector;
1092
+ #optionalFeatures;
1093
+ #onWalletNotFound;
1094
+ get version() {
1095
+ return this.#version;
1096
+ }
1097
+ get name() {
1098
+ return this.#name;
1099
+ }
1100
+ get url() {
1101
+ return this.#url;
1102
+ }
1103
+ get icon() {
1104
+ return this.#icon;
1105
+ }
1106
+ get chains() {
1107
+ return this.#chains;
1108
+ }
1109
+ get features() {
1110
+ return {
1111
+ [features.StandardConnect]: {
1112
+ version: '1.0.0',
1113
+ connect: this.#connect,
1114
+ },
1115
+ [features.StandardDisconnect]: {
1116
+ version: '1.0.0',
1117
+ disconnect: this.#disconnect,
1118
+ },
1119
+ [features.StandardEvents]: {
1120
+ version: '1.0.0',
1121
+ on: this.#on,
1122
+ },
1123
+ [walletStandardFeatures.SolanaSignMessage]: {
1124
+ version: '1.0.0',
1125
+ signMessage: this.#signMessage,
1126
+ },
1127
+ [walletStandardFeatures.SolanaSignIn]: {
1128
+ version: '1.0.0',
1129
+ signIn: this.#signIn,
1130
+ },
1131
+ ...this.#optionalFeatures,
1132
+ };
1133
+ }
1134
+ get accounts() {
1135
+ return this.#authorization?.accounts ?? [];
1136
+ }
1137
+ constructor(config) {
1138
+ this.#authorizationCache = config.authorizationCache;
1139
+ this.#appIdentity = config.appIdentity;
1140
+ this.#chains = config.chains;
1141
+ this.#chainSelector = config.chainSelector;
1142
+ this.#onWalletNotFound = config.onWalletNotFound;
1143
+ this.#optionalFeatures = {
1144
+ // In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
1145
+ // signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
1146
+ // 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
1147
+ // assume both are supported here. The features will be updated based on the actual connected
1148
+ // wallets capabilities during connection regardless, so this is safe.
1149
+ [walletStandardFeatures.SolanaSignAndSendTransaction]: {
1150
+ version: '1.0.0',
1151
+ supportedTransactionVersions: ['legacy', 0],
1152
+ signAndSendTransaction: this.#signAndSendTransaction,
1153
+ },
1154
+ [walletStandardFeatures.SolanaSignTransaction]: {
1155
+ version: '1.0.0',
1156
+ supportedTransactionVersions: ['legacy', 0],
1157
+ signTransaction: this.#signTransaction,
1158
+ },
1159
+ };
1160
+ }
1161
+ get connected() {
1162
+ return !!this.#authorization;
1163
+ }
1164
+ get isAuthorized() {
1165
+ return !!this.#authorization;
1166
+ }
1167
+ get currentAuthorization() {
1168
+ return this.#authorization;
1169
+ }
1170
+ get cachedAuthorizationResult() {
1171
+ return this.#authorizationCache.get();
1172
+ }
1173
+ #on = (event, listener) => {
1174
+ this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
1175
+ return () => this.#off(event, listener);
1176
+ };
1177
+ #emit(event, ...args) {
1178
+ // eslint-disable-next-line prefer-spread
1179
+ this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
1180
+ }
1181
+ #off(event, listener) {
1182
+ this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
1183
+ }
1184
+ #connect = async ({ silent } = {}) => {
1185
+ if (this.#connecting || this.connected) {
1186
+ return { accounts: this.accounts };
1187
+ }
1188
+ this.#connecting = true;
1189
+ try {
1190
+ if (silent) {
1191
+ const cachedAuthorization = await this.#authorizationCache.get();
1192
+ if (cachedAuthorization) {
1193
+ await this.#handleWalletCapabilitiesResult(cachedAuthorization.capabilities);
1194
+ await this.#handleAuthorizationResult(cachedAuthorization);
1195
+ }
1196
+ else {
1197
+ return { accounts: this.accounts };
1198
+ }
1137
1199
  }
1138
- catch (e) {
1139
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1200
+ else {
1201
+ await this.#performAuthorization();
1140
1202
  }
1141
- }));
1142
- _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
1143
- const outputs = [];
1144
- for (const input of inputs) {
1145
- const signature = (yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, "f").call(this, input.transaction, input.options));
1146
- outputs.push({ signature });
1203
+ }
1204
+ catch (e) {
1205
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1206
+ }
1207
+ finally {
1208
+ this.#connecting = false;
1209
+ }
1210
+ return { accounts: this.accounts };
1211
+ };
1212
+ #performAuthorization = async (signInPayload) => {
1213
+ try {
1214
+ const cachedAuthorizationResult = await this.#authorizationCache.get();
1215
+ if (cachedAuthorizationResult) {
1216
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1217
+ this.#handleAuthorizationResult(cachedAuthorizationResult);
1218
+ return cachedAuthorizationResult;
1147
1219
  }
1148
- return outputs;
1149
- }));
1150
- _RemoteSolanaMobileWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
1151
- return (yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions, "f").call(this, inputs.map(({ transaction }) => transaction)))
1152
- .map((signedTransaction) => {
1153
- return { signedTransaction };
1220
+ const selectedChain = await this.#chainSelector.select(this.#chains);
1221
+ return await this.#transact(async (wallet) => {
1222
+ const [capabilities, mwaAuthorizationResult] = await Promise.all([
1223
+ wallet.getCapabilities(),
1224
+ wallet.authorize({
1225
+ chain: selectedChain,
1226
+ identity: this.#appIdentity,
1227
+ sign_in_payload: signInPayload,
1228
+ })
1229
+ ]);
1230
+ const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1231
+ const authorization = { ...mwaAuthorizationResult,
1232
+ accounts, chain: selectedChain, capabilities: capabilities };
1233
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1234
+ Promise.all([
1235
+ this.#handleWalletCapabilitiesResult(capabilities),
1236
+ this.#authorizationCache.set(authorization),
1237
+ this.#handleAuthorizationResult(authorization),
1238
+ ]);
1239
+ return authorization;
1154
1240
  });
1155
- }));
1156
- _RemoteSolanaMobileWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
1157
- const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
1158
- const addresses = inputs.map(({ account }) => jsBase64.fromUint8Array(account.publicKey));
1159
- const messages = inputs.map(({ message }) => jsBase64.fromUint8Array(message));
1160
- try {
1161
- return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
1162
- yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
1163
- const signedMessages = (yield wallet.signMessages({
1164
- addresses: addresses,
1165
- payloads: messages,
1166
- })).signed_payloads.map(jsBase64.toUint8Array);
1167
- return signedMessages.map((signedMessage) => {
1168
- return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
1169
- });
1170
- }));
1241
+ }
1242
+ catch (e) {
1243
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1244
+ }
1245
+ };
1246
+ #handleAuthorizationResult = async (authorization) => {
1247
+ const didPublicKeysChange =
1248
+ // Case 1: We started from having no authorization.
1249
+ this.#authorization == null ||
1250
+ // Case 2: The number of authorized accounts changed.
1251
+ this.#authorization?.accounts.length !== authorization.accounts.length ||
1252
+ // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
1253
+ this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
1254
+ this.#authorization = authorization;
1255
+ if (didPublicKeysChange) {
1256
+ this.#emit('change', { accounts: this.accounts });
1257
+ }
1258
+ };
1259
+ #handleWalletCapabilitiesResult = async (capabilities) => {
1260
+ // TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
1261
+ const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
1262
+ const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions;
1263
+ const didCapabilitiesChange = walletStandardFeatures.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
1264
+ walletStandardFeatures.SolanaSignTransaction in this.features !== supportsSignTransaction;
1265
+ this.#optionalFeatures = {
1266
+ ...((supportsSignAndSendTransaction || (!supportsSignAndSendTransaction && !supportsSignTransaction)) && {
1267
+ [walletStandardFeatures.SolanaSignAndSendTransaction]: {
1268
+ version: '1.0.0',
1269
+ supportedTransactionVersions: ['legacy', 0],
1270
+ signAndSendTransaction: this.#signAndSendTransaction,
1271
+ },
1272
+ }),
1273
+ ...(supportsSignTransaction && {
1274
+ [walletStandardFeatures.SolanaSignTransaction]: {
1275
+ version: '1.0.0',
1276
+ supportedTransactionVersions: ['legacy', 0],
1277
+ signTransaction: this.#signTransaction,
1278
+ },
1279
+ }),
1280
+ };
1281
+ if (didCapabilitiesChange) {
1282
+ this.#emit('change', { features: this.features });
1283
+ }
1284
+ };
1285
+ #performReauthorization = async (wallet, authToken, chain) => {
1286
+ try {
1287
+ const [capabilities, mwaAuthorizationResult] = await Promise.all([
1288
+ this.#authorization?.capabilities ?? await wallet.getCapabilities(),
1289
+ wallet.authorize({
1290
+ auth_token: authToken,
1291
+ identity: this.#appIdentity,
1292
+ chain: chain
1293
+ })
1294
+ ]);
1295
+ const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1296
+ const authorization = { ...mwaAuthorizationResult,
1297
+ accounts: accounts, chain: chain, capabilities: capabilities
1298
+ };
1299
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1300
+ Promise.all([
1301
+ this.#authorizationCache.set(authorization),
1302
+ this.#handleAuthorizationResult(authorization),
1303
+ ]);
1304
+ }
1305
+ catch (e) {
1306
+ this.#disconnect();
1307
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1308
+ }
1309
+ };
1310
+ #disconnect = async () => {
1311
+ this.#authorizationCache.clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1312
+ this.#connecting = false;
1313
+ this.#connectionGeneration++;
1314
+ this.#authorization = undefined;
1315
+ this.#emit('change', { accounts: this.accounts });
1316
+ };
1317
+ #transact = async (callback) => {
1318
+ const walletUriBase = this.#authorization?.wallet_uri_base;
1319
+ const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
1320
+ const currentConnectionGeneration = this.#connectionGeneration;
1321
+ const loadingSpinner = new EmbeddedLoadingSpinner();
1322
+ try {
1323
+ // check that we have permissions for local app connections, then run
1324
+ // wallet association (transact). In case the user manually cancels
1325
+ // the wallet association, cancel the connection after a timeout.
1326
+ let associating = true;
1327
+ let timeout = undefined;
1328
+ const result = await Promise.race([
1329
+ checkLocalNetworkAccessPermission()
1330
+ .then(async () => {
1331
+ // Begin local connection, show loading spinner while we connect
1332
+ loadingSpinner.init();
1333
+ const { wallet, close } = await mobileWalletAdapterProtocol.startScenario(config);
1334
+ loadingSpinner.addEventListener('close', (event) => { if (event)
1335
+ close(); });
1336
+ loadingSpinner.open();
1337
+ const result = await callback(await wallet);
1338
+ loadingSpinner.close();
1339
+ close();
1340
+ return result;
1341
+ }),
1342
+ new Promise((_, reject) => {
1343
+ timeout = setTimeout(() => {
1344
+ if (associating) { // only timeout during association
1345
+ reject(new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, 'Wallet connection timed out', { event: undefined }));
1346
+ }
1347
+ }, WALLET_ASSOCIATION_TIMEOUT);
1348
+ })
1349
+ ]);
1350
+ clearTimeout(timeout);
1351
+ return result;
1352
+ }
1353
+ catch (e) {
1354
+ loadingSpinner.close();
1355
+ if (this.#connectionGeneration !== currentConnectionGeneration) {
1356
+ await new Promise(() => { }); // Never resolve.
1171
1357
  }
1172
- catch (e) {
1173
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1358
+ if (e instanceof Error &&
1359
+ e.name === 'SolanaMobileWalletAdapterError' &&
1360
+ e.code === 'ERROR_WALLET_NOT_FOUND') {
1361
+ await this.#onWalletNotFound(this);
1174
1362
  }
1175
- }));
1176
- _RemoteSolanaMobileWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
1177
- const outputs = [];
1178
- if (inputs.length > 1) {
1179
- for (const input of inputs) {
1180
- outputs.push(yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, input));
1363
+ throw e;
1364
+ }
1365
+ };
1366
+ #assertIsAuthorized = () => {
1367
+ if (!this.#authorization)
1368
+ throw new Error('Wallet not connected');
1369
+ return { authToken: this.#authorization.auth_token, chain: this.#authorization.chain };
1370
+ };
1371
+ #accountsToWalletStandardAccounts = (accounts) => {
1372
+ return accounts.map((account) => {
1373
+ const publicKey = jsBase64.toUint8Array(account.address);
1374
+ return {
1375
+ address: base58.encode(publicKey),
1376
+ publicKey,
1377
+ label: account.label,
1378
+ icon: account.icon,
1379
+ chains: account.chains ?? this.#chains,
1380
+ // TODO: get supported features from getCapabilities API
1381
+ features: account.features ?? DEFAULT_FEATURES
1382
+ };
1383
+ });
1384
+ };
1385
+ #performSignTransactions = async (transactions) => {
1386
+ const { authToken, chain } = this.#assertIsAuthorized();
1387
+ try {
1388
+ const base64Transactions = transactions.map((tx) => { return jsBase64.fromUint8Array(tx); });
1389
+ return await this.#transact(async (wallet) => {
1390
+ await this.#performReauthorization(wallet, authToken, chain);
1391
+ const signedTransactions = (await wallet.signTransactions({
1392
+ payloads: base64Transactions,
1393
+ })).signed_payloads.map(jsBase64.toUint8Array);
1394
+ return signedTransactions;
1395
+ });
1396
+ }
1397
+ catch (e) {
1398
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1399
+ }
1400
+ };
1401
+ #performSignAndSendTransaction = async (transaction, options) => {
1402
+ const { authToken, chain } = this.#assertIsAuthorized();
1403
+ try {
1404
+ return await this.#transact(async (wallet) => {
1405
+ const [capabilities, _1] = await Promise.all([
1406
+ wallet.getCapabilities(),
1407
+ this.#performReauthorization(wallet, authToken, chain)
1408
+ ]);
1409
+ if (capabilities.supports_sign_and_send_transactions) {
1410
+ const base64Transaction = jsBase64.fromUint8Array(transaction);
1411
+ const signatures = (await wallet.signAndSendTransactions({
1412
+ ...options,
1413
+ payloads: [base64Transaction],
1414
+ })).signatures.map(jsBase64.toUint8Array);
1415
+ return signatures[0];
1181
1416
  }
1182
- }
1183
- else {
1184
- return [yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, inputs[0])];
1185
- }
1186
- return outputs;
1187
- }));
1188
- _RemoteSolanaMobileWalletAdapterWallet_performSignIn.set(this, (input) => __awaiter(this, void 0, void 0, function* () {
1189
- var _g, _h, _j;
1190
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, true, "f");
1191
- try {
1192
- const authorizationResult = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this, Object.assign(Object.assign({}, input), { domain: (_g = input === null || input === void 0 ? void 0 : input.domain) !== null && _g !== void 0 ? _g : window.location.host }));
1193
- if (!authorizationResult.sign_in_result) {
1194
- throw new Error("Sign in failed, no sign in result returned by wallet");
1417
+ else {
1418
+ throw new Error('connected wallet does not support signAndSendTransaction');
1195
1419
  }
1196
- const signedInAddress = authorizationResult.sign_in_result.address;
1197
- const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
1198
- return {
1199
- account: Object.assign(Object.assign({}, signedInAccount !== null && signedInAccount !== void 0 ? signedInAccount : {
1200
- address: base58__default["default"].encode(jsBase64.toUint8Array(signedInAddress))
1201
- }), { publicKey: jsBase64.toUint8Array(signedInAddress), chains: (_h = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.chains) !== null && _h !== void 0 ? _h : __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"), features: (_j = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.features) !== null && _j !== void 0 ? _j : authorizationResult.capabilities.features }),
1202
- signedMessage: jsBase64.toUint8Array(authorizationResult.sign_in_result.signed_message),
1203
- signature: jsBase64.toUint8Array(authorizationResult.sign_in_result.signature)
1204
- };
1205
- }
1206
- catch (e) {
1207
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1420
+ });
1421
+ }
1422
+ catch (e) {
1423
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1424
+ }
1425
+ };
1426
+ #signAndSendTransaction = async (...inputs) => {
1427
+ const outputs = [];
1428
+ for (const input of inputs) {
1429
+ const signature = await this.#performSignAndSendTransaction(input.transaction, input.options);
1430
+ outputs.push({ signature });
1431
+ }
1432
+ return outputs;
1433
+ };
1434
+ #signTransaction = async (...inputs) => {
1435
+ return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction)))
1436
+ .map((signedTransaction) => {
1437
+ return { signedTransaction };
1438
+ });
1439
+ };
1440
+ #signMessage = async (...inputs) => {
1441
+ const { authToken, chain } = this.#assertIsAuthorized();
1442
+ const addresses = inputs.map(({ account }) => jsBase64.fromUint8Array(new Uint8Array(account.publicKey)));
1443
+ const messages = inputs.map(({ message }) => jsBase64.fromUint8Array(message));
1444
+ try {
1445
+ return await this.#transact(async (wallet) => {
1446
+ await this.#performReauthorization(wallet, authToken, chain);
1447
+ const signedMessages = (await wallet.signMessages({
1448
+ addresses: addresses,
1449
+ payloads: messages,
1450
+ })).signed_payloads.map(jsBase64.toUint8Array);
1451
+ return signedMessages.map((signedMessage) => {
1452
+ return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
1453
+ });
1454
+ });
1455
+ }
1456
+ catch (e) {
1457
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1458
+ }
1459
+ };
1460
+ #signIn = async (...inputs) => {
1461
+ const outputs = [];
1462
+ if (inputs.length > 1) {
1463
+ for (const input of inputs) {
1464
+ outputs.push(await this.#performSignIn(input));
1208
1465
  }
1209
- finally {
1210
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false, "f");
1466
+ }
1467
+ else {
1468
+ return [await this.#performSignIn(inputs[0])];
1469
+ }
1470
+ return outputs;
1471
+ };
1472
+ #performSignIn = async (input) => {
1473
+ this.#connecting = true;
1474
+ try {
1475
+ const authorizationResult = await this.#performAuthorization({
1476
+ ...input,
1477
+ domain: input?.domain ?? window.location.host
1478
+ });
1479
+ if (!authorizationResult.sign_in_result) {
1480
+ throw new Error("Sign in failed, no sign in result returned by wallet");
1211
1481
  }
1212
- }));
1213
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, config.authorizationCache, "f");
1214
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, config.appIdentity, "f");
1215
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, config.chains, "f");
1216
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, config.chainSelector, "f");
1217
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, config.remoteHostAuthority, "f");
1218
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, config.onWalletNotFound, "f");
1219
- __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, {
1220
- // In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
1221
- // signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
1222
- // 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
1223
- // assume both are supported here. The features will be updated based on the actual connected
1224
- // wallets capabilities during connection regardless, so this is safe.
1225
- [walletStandardFeatures.SolanaSignAndSendTransaction]: {
1226
- version: '1.0.0',
1227
- supportedTransactionVersions: ['legacy', 0],
1228
- signAndSendTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
1229
- },
1230
- [walletStandardFeatures.SolanaSignTransaction]: {
1231
- version: '1.0.0',
1232
- supportedTransactionVersions: ['legacy', 0],
1233
- signTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, "f"),
1234
- },
1235
- }, "f");
1236
- }
1482
+ const signedInAddress = authorizationResult.sign_in_result.address;
1483
+ const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
1484
+ return {
1485
+ account: {
1486
+ ...signedInAccount ?? {
1487
+ address: base58.encode(jsBase64.toUint8Array(signedInAddress))
1488
+ },
1489
+ publicKey: jsBase64.toUint8Array(signedInAddress),
1490
+ chains: signedInAccount?.chains ?? this.#chains,
1491
+ features: signedInAccount?.features ?? authorizationResult.capabilities.features
1492
+ },
1493
+ signedMessage: jsBase64.toUint8Array(authorizationResult.sign_in_result.signed_message),
1494
+ signature: jsBase64.toUint8Array(authorizationResult.sign_in_result.signature)
1495
+ };
1496
+ }
1497
+ catch (e) {
1498
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1499
+ }
1500
+ finally {
1501
+ this.#connecting = false;
1502
+ }
1503
+ };
1504
+ }
1505
+ class RemoteSolanaMobileWalletAdapterWallet {
1506
+ #listeners = {};
1507
+ #version = '1.0.0'; // wallet-standard version
1508
+ #name = SolanaMobileWalletAdapterRemoteWalletName;
1509
+ #url = 'https://solanamobile.com/wallets';
1510
+ #icon = icon;
1511
+ #appIdentity;
1512
+ #authorization;
1513
+ #authorizationCache;
1514
+ #connecting = false;
1515
+ /**
1516
+ * Every time the connection is recycled in some way (eg. `disconnect()` is called)
1517
+ * increment this and use it to make sure that `transact` calls from the previous
1518
+ * 'generation' don't continue to do work and throw exceptions.
1519
+ */
1520
+ #connectionGeneration = 0;
1521
+ #chains = [];
1522
+ #chainSelector;
1523
+ #optionalFeatures;
1524
+ #onWalletNotFound;
1525
+ #hostAuthority;
1526
+ #session;
1237
1527
  get version() {
1238
- return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_version, "f");
1528
+ return this.#version;
1239
1529
  }
1240
1530
  get name() {
1241
- return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_name, "f");
1531
+ return this.#name;
1242
1532
  }
1243
1533
  get url() {
1244
- return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_url, "f");
1534
+ return this.#url;
1245
1535
  }
1246
1536
  get icon() {
1247
- return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_icon, "f");
1537
+ return this.#icon;
1248
1538
  }
1249
1539
  get chains() {
1250
- return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f");
1540
+ return this.#chains;
1251
1541
  }
1252
1542
  get features() {
1253
- return Object.assign({ [features.StandardConnect]: {
1543
+ return {
1544
+ [features.StandardConnect]: {
1254
1545
  version: '1.0.0',
1255
- connect: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connect, "f"),
1256
- }, [features.StandardDisconnect]: {
1546
+ connect: this.#connect,
1547
+ },
1548
+ [features.StandardDisconnect]: {
1257
1549
  version: '1.0.0',
1258
- disconnect: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_disconnect, "f"),
1259
- }, [features.StandardEvents]: {
1550
+ disconnect: this.#disconnect,
1551
+ },
1552
+ [features.StandardEvents]: {
1260
1553
  version: '1.0.0',
1261
- on: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_on, "f"),
1262
- }, [walletStandardFeatures.SolanaSignMessage]: {
1554
+ on: this.#on,
1555
+ },
1556
+ [walletStandardFeatures.SolanaSignMessage]: {
1263
1557
  version: '1.0.0',
1264
- signMessage: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signMessage, "f"),
1265
- }, [walletStandardFeatures.SolanaSignIn]: {
1558
+ signMessage: this.#signMessage,
1559
+ },
1560
+ [walletStandardFeatures.SolanaSignIn]: {
1266
1561
  version: '1.0.0',
1267
- signIn: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signIn, "f"),
1268
- } }, __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, "f"));
1562
+ signIn: this.#signIn,
1563
+ },
1564
+ ...this.#optionalFeatures,
1565
+ };
1269
1566
  }
1270
1567
  get accounts() {
1271
- var _a, _b;
1272
- return (_b = (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : [];
1568
+ return this.#authorization?.accounts ?? [];
1569
+ }
1570
+ constructor(config) {
1571
+ this.#authorizationCache = config.authorizationCache;
1572
+ this.#appIdentity = config.appIdentity;
1573
+ this.#chains = config.chains;
1574
+ this.#chainSelector = config.chainSelector;
1575
+ this.#hostAuthority = config.remoteHostAuthority;
1576
+ this.#onWalletNotFound = config.onWalletNotFound;
1577
+ this.#optionalFeatures = {
1578
+ // In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
1579
+ // signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
1580
+ // 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
1581
+ // assume both are supported here. The features will be updated based on the actual connected
1582
+ // wallets capabilities during connection regardless, so this is safe.
1583
+ [walletStandardFeatures.SolanaSignAndSendTransaction]: {
1584
+ version: '1.0.0',
1585
+ supportedTransactionVersions: ['legacy', 0],
1586
+ signAndSendTransaction: this.#signAndSendTransaction,
1587
+ },
1588
+ [walletStandardFeatures.SolanaSignTransaction]: {
1589
+ version: '1.0.0',
1590
+ supportedTransactionVersions: ['legacy', 0],
1591
+ signTransaction: this.#signTransaction,
1592
+ },
1593
+ };
1273
1594
  }
1274
1595
  get connected() {
1275
- return !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f") && !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
1596
+ return !!this.#session && !!this.#authorization;
1276
1597
  }
1277
1598
  get isAuthorized() {
1278
- return !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
1599
+ return !!this.#authorization;
1279
1600
  }
1280
1601
  get currentAuthorization() {
1281
- return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
1602
+ return this.#authorization;
1282
1603
  }
1283
1604
  get cachedAuthorizationResult() {
1284
- return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
1605
+ return this.#authorizationCache.get();
1285
1606
  }
1286
- }
1287
- _RemoteSolanaMobileWalletAdapterWallet_listeners = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_version = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_name = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_url = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_icon = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_appIdentity = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_authorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_authorizationCache = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connecting = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_chains = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_chainSelector = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_hostAuthority = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_session = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_on = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connect = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performAuthorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performReauthorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_disconnect = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_transact = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signMessage = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signIn = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignIn = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_instances = new WeakSet(), _RemoteSolanaMobileWalletAdapterWallet_emit = function _RemoteSolanaMobileWalletAdapterWallet_emit(event, ...args) {
1288
- var _a;
1289
- // eslint-disable-next-line prefer-spread
1290
- (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener.apply(null, args));
1291
- }, _RemoteSolanaMobileWalletAdapterWallet_off = function _RemoteSolanaMobileWalletAdapterWallet_off(event, listener) {
1292
- var _a;
1293
- __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
1294
- };
1295
-
1296
- var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1297
- if (kind === "m") throw new TypeError("Private method is not writable");
1298
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1299
- 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");
1300
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1301
- };
1302
- var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1303
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1304
- 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");
1305
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1306
- };
1307
- var _RegisterWalletEvent_detail;
1308
- /**
1309
- * Register a {@link "@wallet-standard/base".Wallet} as a Standard Wallet with the app.
1310
- *
1311
- * This dispatches a {@link "@wallet-standard/base".WindowRegisterWalletEvent} to notify the app that the Wallet is
1312
- * ready to be registered.
1313
- *
1314
- * This also adds a listener for {@link "@wallet-standard/base".WindowAppReadyEvent} to listen for a notification from
1315
- * the app that the app is ready to register the Wallet.
1316
- *
1317
- * This combination of event dispatch and listener guarantees that the Wallet will be registered synchronously as soon
1318
- * as the app is ready whether the Wallet loads before or after the app.
1319
- *
1320
- * @param wallet Wallet to register.
1321
- *
1322
- * @group Wallet
1323
- */
1324
- function registerWallet(wallet) {
1325
- const callback = ({ register }) => register(wallet);
1326
- try {
1327
- window.dispatchEvent(new RegisterWalletEvent(callback));
1328
- }
1329
- catch (error) {
1330
- console.error('wallet-standard:register-wallet event could not be dispatched\n', error);
1331
- }
1332
- try {
1333
- window.addEventListener('wallet-standard:app-ready', ({ detail: api }) => callback(api));
1607
+ #on = (event, listener) => {
1608
+ this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
1609
+ return () => this.#off(event, listener);
1610
+ };
1611
+ #emit(event, ...args) {
1612
+ // eslint-disable-next-line prefer-spread
1613
+ this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
1334
1614
  }
1335
- catch (error) {
1336
- console.error('wallet-standard:app-ready event listener could not be added\n', error);
1615
+ #off(event, listener) {
1616
+ this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
1337
1617
  }
1338
- }
1339
- class RegisterWalletEvent extends Event {
1340
- constructor(callback) {
1341
- super('wallet-standard:register-wallet', {
1342
- bubbles: false,
1343
- cancelable: false,
1344
- composed: false,
1618
+ #connect = async ({ silent } = {}) => {
1619
+ if (this.#connecting || this.connected) {
1620
+ return { accounts: this.accounts };
1621
+ }
1622
+ this.#connecting = true;
1623
+ try {
1624
+ await this.#performAuthorization();
1625
+ }
1626
+ catch (e) {
1627
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1628
+ }
1629
+ finally {
1630
+ this.#connecting = false;
1631
+ }
1632
+ return { accounts: this.accounts };
1633
+ };
1634
+ #performAuthorization = async (signInPayload) => {
1635
+ try {
1636
+ const cachedAuthorizationResult = await this.#authorizationCache.get();
1637
+ if (cachedAuthorizationResult) {
1638
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1639
+ this.#handleAuthorizationResult(cachedAuthorizationResult);
1640
+ return cachedAuthorizationResult;
1641
+ }
1642
+ if (this.#session)
1643
+ this.#session = undefined;
1644
+ const selectedChain = await this.#chainSelector.select(this.#chains);
1645
+ return await this.#transact(async (wallet) => {
1646
+ const [capabilities, mwaAuthorizationResult] = await Promise.all([
1647
+ wallet.getCapabilities(),
1648
+ wallet.authorize({
1649
+ chain: selectedChain,
1650
+ identity: this.#appIdentity,
1651
+ sign_in_payload: signInPayload,
1652
+ })
1653
+ ]);
1654
+ const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1655
+ const authorizationResult = { ...mwaAuthorizationResult,
1656
+ accounts, chain: selectedChain, capabilities: capabilities };
1657
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1658
+ Promise.all([
1659
+ this.#handleWalletCapabilitiesResult(capabilities),
1660
+ this.#authorizationCache.set(authorizationResult),
1661
+ this.#handleAuthorizationResult(authorizationResult),
1662
+ ]);
1663
+ return authorizationResult;
1664
+ });
1665
+ }
1666
+ catch (e) {
1667
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1668
+ }
1669
+ };
1670
+ #handleAuthorizationResult = async (authorization) => {
1671
+ const didPublicKeysChange =
1672
+ // Case 1: We started from having no authorization.
1673
+ this.#authorization == null ||
1674
+ // Case 2: The number of authorized accounts changed.
1675
+ this.#authorization?.accounts.length !== authorization.accounts.length ||
1676
+ // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
1677
+ this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
1678
+ this.#authorization = authorization;
1679
+ if (didPublicKeysChange) {
1680
+ this.#emit('change', { accounts: this.accounts });
1681
+ }
1682
+ };
1683
+ #handleWalletCapabilitiesResult = async (capabilities) => {
1684
+ // TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
1685
+ const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
1686
+ const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions ||
1687
+ capabilities.features.includes('solana:signAndSendTransaction');
1688
+ const didCapabilitiesChange = walletStandardFeatures.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
1689
+ walletStandardFeatures.SolanaSignTransaction in this.features !== supportsSignTransaction;
1690
+ this.#optionalFeatures = {
1691
+ ...(supportsSignAndSendTransaction && {
1692
+ [walletStandardFeatures.SolanaSignAndSendTransaction]: {
1693
+ version: '1.0.0',
1694
+ supportedTransactionVersions: capabilities.supported_transaction_versions,
1695
+ signAndSendTransaction: this.#signAndSendTransaction,
1696
+ },
1697
+ }),
1698
+ ...(supportsSignTransaction && {
1699
+ [walletStandardFeatures.SolanaSignTransaction]: {
1700
+ version: '1.0.0',
1701
+ supportedTransactionVersions: capabilities.supported_transaction_versions,
1702
+ signTransaction: this.#signTransaction,
1703
+ },
1704
+ }),
1705
+ };
1706
+ if (didCapabilitiesChange) {
1707
+ this.#emit('change', { features: this.features });
1708
+ }
1709
+ };
1710
+ #performReauthorization = async (wallet, authToken, chain) => {
1711
+ try {
1712
+ const [capabilities, mwaAuthorizationResult] = await Promise.all([
1713
+ this.#authorization?.capabilities ?? await wallet.getCapabilities(),
1714
+ wallet.authorize({
1715
+ auth_token: authToken,
1716
+ identity: this.#appIdentity,
1717
+ chain: chain
1718
+ })
1719
+ ]);
1720
+ const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1721
+ const authorization = { ...mwaAuthorizationResult,
1722
+ accounts: accounts, chain: chain, capabilities: capabilities };
1723
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1724
+ Promise.all([
1725
+ this.#authorizationCache.set(authorization),
1726
+ this.#handleAuthorizationResult(authorization),
1727
+ ]);
1728
+ }
1729
+ catch (e) {
1730
+ this.#disconnect();
1731
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1732
+ }
1733
+ };
1734
+ #disconnect = async () => {
1735
+ this.#session?.close();
1736
+ this.#authorizationCache.clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1737
+ this.#connecting = false;
1738
+ this.#connectionGeneration++;
1739
+ this.#authorization = undefined;
1740
+ this.#session = undefined;
1741
+ this.#emit('change', { accounts: this.accounts });
1742
+ };
1743
+ #transact = async (callback) => {
1744
+ const walletUriBase = this.#authorization?.wallet_uri_base;
1745
+ const baseConfig = walletUriBase ? { baseUri: walletUriBase } : undefined;
1746
+ const remoteConfig = { ...baseConfig, remoteHostAuthority: this.#hostAuthority };
1747
+ const currentConnectionGeneration = this.#connectionGeneration;
1748
+ const modal = new RemoteConnectionModal();
1749
+ if (this.#session) {
1750
+ return callback(this.#session.wallet);
1751
+ }
1752
+ try {
1753
+ // Begin remote connection, show modal with loading anim while we connect
1754
+ modal.init();
1755
+ modal.open();
1756
+ const { associationUrl, close, wallet } = await mobileWalletAdapterProtocol.startRemoteScenario(remoteConfig);
1757
+ // Reflector is now connected, update the connection modal with qr code
1758
+ const removeCloseListener = modal.addEventListener('close', (event) => {
1759
+ if (event)
1760
+ close();
1761
+ });
1762
+ modal.populateQRCode(associationUrl.toString());
1763
+ // Wait for the wallet to be connected, then close the connection modal and proceed
1764
+ this.#session = { close, wallet: await wallet };
1765
+ removeCloseListener();
1766
+ modal.close();
1767
+ return await callback(this.#session.wallet);
1768
+ }
1769
+ catch (e) {
1770
+ modal.close();
1771
+ if (this.#connectionGeneration !== currentConnectionGeneration) {
1772
+ await new Promise(() => { }); // Never resolve.
1773
+ }
1774
+ if (e instanceof Error &&
1775
+ e.name === 'SolanaMobileWalletAdapterError' &&
1776
+ e.code === 'ERROR_WALLET_NOT_FOUND') {
1777
+ await this.#onWalletNotFound(this);
1778
+ }
1779
+ throw e;
1780
+ }
1781
+ };
1782
+ #assertIsAuthorized = () => {
1783
+ if (!this.#authorization)
1784
+ throw new Error('Wallet not connected');
1785
+ return { authToken: this.#authorization.auth_token, chain: this.#authorization.chain };
1786
+ };
1787
+ #accountsToWalletStandardAccounts = (accounts) => {
1788
+ return accounts.map((account) => {
1789
+ const publicKey = jsBase64.toUint8Array(account.address);
1790
+ return {
1791
+ address: base58.encode(publicKey),
1792
+ publicKey,
1793
+ label: account.label,
1794
+ icon: account.icon,
1795
+ chains: account.chains ?? this.#chains,
1796
+ // TODO: get supported features from getCapabilities API
1797
+ features: account.features ?? DEFAULT_FEATURES
1798
+ };
1345
1799
  });
1346
- _RegisterWalletEvent_detail.set(this, void 0);
1347
- __classPrivateFieldSet(this, _RegisterWalletEvent_detail, callback, "f");
1348
- }
1349
- get detail() {
1350
- return __classPrivateFieldGet(this, _RegisterWalletEvent_detail, "f");
1351
- }
1352
- get type() {
1353
- return 'wallet-standard:register-wallet';
1354
- }
1355
- /** @deprecated */
1356
- preventDefault() {
1357
- throw new Error('preventDefault cannot be called');
1358
- }
1359
- /** @deprecated */
1360
- stopImmediatePropagation() {
1361
- throw new Error('stopImmediatePropagation cannot be called');
1362
- }
1363
- /** @deprecated */
1364
- stopPropagation() {
1365
- throw new Error('stopPropagation cannot be called');
1366
- }
1367
- }
1368
- _RegisterWalletEvent_detail = new WeakMap();
1369
-
1370
- (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1371
- if (kind === "m") throw new TypeError("Private method is not writable");
1372
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1373
- 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");
1374
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1375
- };
1376
- (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1377
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1378
- 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");
1379
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1380
- };
1381
-
1382
- function getIsLocalAssociationSupported() {
1383
- return (typeof window !== 'undefined' &&
1384
- window.isSecureContext &&
1385
- typeof document !== 'undefined' &&
1386
- /android/i.test(navigator.userAgent));
1387
- }
1388
- function getIsRemoteAssociationSupported() {
1389
- return (typeof window !== 'undefined' &&
1390
- window.isSecureContext &&
1391
- typeof document !== 'undefined' &&
1392
- !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
1393
- }
1394
- // Source: https://github.com/anza-xyz/wallet-adapter/blob/master/packages/core/react/src/getEnvironment.ts#L14
1395
- // This is the same implementation that gated MWA in the Anza wallet-adapter-react library.
1396
- function isWebView(userAgentString) {
1397
- return /(WebView|Version\/.+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+)|; wv\).+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+))/i.test(userAgentString);
1800
+ };
1801
+ #performSignTransactions = async (transactions) => {
1802
+ const { authToken, chain } = this.#assertIsAuthorized();
1803
+ try {
1804
+ return await this.#transact(async (wallet) => {
1805
+ await this.#performReauthorization(wallet, authToken, chain);
1806
+ const signedTransactions = (await wallet.signTransactions({
1807
+ payloads: transactions.map(jsBase64.fromUint8Array),
1808
+ })).signed_payloads.map(jsBase64.toUint8Array);
1809
+ return signedTransactions;
1810
+ });
1811
+ }
1812
+ catch (e) {
1813
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1814
+ }
1815
+ };
1816
+ #performSignAndSendTransaction = async (transaction, options) => {
1817
+ const { authToken, chain } = this.#assertIsAuthorized();
1818
+ try {
1819
+ return await this.#transact(async (wallet) => {
1820
+ const [capabilities, _1] = await Promise.all([
1821
+ wallet.getCapabilities(),
1822
+ this.#performReauthorization(wallet, authToken, chain)
1823
+ ]);
1824
+ if (capabilities.supports_sign_and_send_transactions) {
1825
+ const signatures = (await wallet.signAndSendTransactions({
1826
+ ...options,
1827
+ payloads: [jsBase64.fromUint8Array(transaction)],
1828
+ })).signatures.map(jsBase64.toUint8Array);
1829
+ return signatures[0];
1830
+ }
1831
+ else {
1832
+ throw new Error('connected wallet does not support signAndSendTransaction');
1833
+ }
1834
+ });
1835
+ }
1836
+ catch (e) {
1837
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1838
+ }
1839
+ };
1840
+ #signAndSendTransaction = async (...inputs) => {
1841
+ const outputs = [];
1842
+ for (const input of inputs) {
1843
+ const signature = (await this.#performSignAndSendTransaction(input.transaction, input.options));
1844
+ outputs.push({ signature });
1845
+ }
1846
+ return outputs;
1847
+ };
1848
+ #signTransaction = async (...inputs) => {
1849
+ return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction)))
1850
+ .map((signedTransaction) => {
1851
+ return { signedTransaction };
1852
+ });
1853
+ };
1854
+ #signMessage = async (...inputs) => {
1855
+ const { authToken, chain } = this.#assertIsAuthorized();
1856
+ const addresses = inputs.map(({ account }) => jsBase64.fromUint8Array(new Uint8Array(account.publicKey)));
1857
+ const messages = inputs.map(({ message }) => jsBase64.fromUint8Array(message));
1858
+ try {
1859
+ return await this.#transact(async (wallet) => {
1860
+ await this.#performReauthorization(wallet, authToken, chain);
1861
+ const signedMessages = (await wallet.signMessages({
1862
+ addresses: addresses,
1863
+ payloads: messages,
1864
+ })).signed_payloads.map(jsBase64.toUint8Array);
1865
+ return signedMessages.map((signedMessage) => {
1866
+ return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
1867
+ });
1868
+ });
1869
+ }
1870
+ catch (e) {
1871
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1872
+ }
1873
+ };
1874
+ #signIn = async (...inputs) => {
1875
+ const outputs = [];
1876
+ if (inputs.length > 1) {
1877
+ for (const input of inputs) {
1878
+ outputs.push(await this.#performSignIn(input));
1879
+ }
1880
+ }
1881
+ else {
1882
+ return [await this.#performSignIn(inputs[0])];
1883
+ }
1884
+ return outputs;
1885
+ };
1886
+ #performSignIn = async (input) => {
1887
+ this.#connecting = true;
1888
+ try {
1889
+ const authorizationResult = await this.#performAuthorization({
1890
+ ...input,
1891
+ domain: input?.domain ?? window.location.host
1892
+ });
1893
+ if (!authorizationResult.sign_in_result) {
1894
+ throw new Error("Sign in failed, no sign in result returned by wallet");
1895
+ }
1896
+ const signedInAddress = authorizationResult.sign_in_result.address;
1897
+ const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
1898
+ return {
1899
+ account: {
1900
+ ...signedInAccount ?? {
1901
+ address: base58.encode(jsBase64.toUint8Array(signedInAddress))
1902
+ },
1903
+ publicKey: jsBase64.toUint8Array(signedInAddress),
1904
+ chains: signedInAccount?.chains ?? this.#chains,
1905
+ features: signedInAccount?.features ?? authorizationResult.capabilities.features
1906
+ },
1907
+ signedMessage: jsBase64.toUint8Array(authorizationResult.sign_in_result.signed_message),
1908
+ signature: jsBase64.toUint8Array(authorizationResult.sign_in_result.signature)
1909
+ };
1910
+ }
1911
+ catch (e) {
1912
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1913
+ }
1914
+ finally {
1915
+ this.#connecting = false;
1916
+ }
1917
+ };
1398
1918
  }
1399
1919
 
1400
1920
  function registerMwa(config) {
@@ -1409,10 +1929,10 @@ function registerMwa(config) {
1409
1929
  // Local association technically is possible in a webview, but we prevent registration
1410
1930
  // by default because it usually fails in the most common cases (e.g wallet browsers).
1411
1931
  if (getIsLocalAssociationSupported() && !isWebView(navigator.userAgent)) {
1412
- registerWallet(new LocalSolanaMobileWalletAdapterWallet(config));
1932
+ wallet.registerWallet(new LocalSolanaMobileWalletAdapterWallet(config));
1413
1933
  }
1414
1934
  else if (getIsRemoteAssociationSupported() && config.remoteHostAuthority !== undefined) {
1415
- registerWallet(new RemoteSolanaMobileWalletAdapterWallet(Object.assign(Object.assign({}, config), { remoteHostAuthority: config.remoteHostAuthority })));
1935
+ wallet.registerWallet(new RemoteSolanaMobileWalletAdapterWallet({ ...config, remoteHostAuthority: config.remoteHostAuthority }));
1416
1936
  }
1417
1937
  else ;
1418
1938
  }
@@ -1420,19 +1940,15 @@ function registerMwa(config) {
1420
1940
  const WALLET_NOT_FOUND_ERROR_MESSAGE = 'To use mobile wallet adapter, you must have a compatible mobile wallet application installed on your device.';
1421
1941
  const BROWSER_NOT_SUPPORTED_ERROR_MESSAGE = 'This browser appears to be incompatible with mobile wallet adapter. Open this page in a compatible mobile browser app and try again.';
1422
1942
  class ErrorModal extends EmbeddedModal {
1423
- constructor() {
1424
- super(...arguments);
1425
- this.contentStyles = css;
1426
- this.contentHtml = ErrorDialogHtml;
1427
- }
1943
+ contentStyles = css;
1944
+ contentHtml = ErrorDialogHtml;
1428
1945
  initWithError(error) {
1429
1946
  super.init();
1430
1947
  this.populateError(error);
1431
1948
  }
1432
1949
  populateError(error) {
1433
- var _a, _b;
1434
- const errorMessageElement = (_a = this.dom) === null || _a === void 0 ? void 0 : _a.getElementById('mobile-wallet-adapter-error-message');
1435
- const actionBtn = (_b = this.dom) === null || _b === void 0 ? void 0 : _b.getElementById('mobile-wallet-adapter-error-action');
1950
+ const errorMessageElement = this.dom?.getElementById('mobile-wallet-adapter-error-message');
1951
+ const actionBtn = this.dom?.getElementById('mobile-wallet-adapter-error-action');
1436
1952
  if (errorMessageElement) {
1437
1953
  if (error.name === 'SolanaMobileWalletAdapterError') {
1438
1954
  switch (error.code) {
@@ -1517,433 +2033,97 @@ const css = `
1517
2033
  }
1518
2034
  `;
1519
2035
 
1520
- function defaultErrorModalWalletNotFoundHandler() {
1521
- return __awaiter(this, void 0, void 0, function* () {
1522
- if (typeof window !== 'undefined') {
1523
- const userAgent = window.navigator.userAgent.toLowerCase();
1524
- const errorDialog = new ErrorModal();
1525
- if (userAgent.includes('wv')) { // Android WebView
1526
- // MWA is not supported in this browser so we inform the user
1527
- // errorDialog.initWithError(
1528
- // new SolanaMobileWalletAdapterError(
1529
- // SolanaMobileWalletAdapterErrorCode.ERROR_BROWSER_NOT_SUPPORTED,
1530
- // ''
1531
- // )
1532
- // );
1533
- // TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
1534
- errorDialog.initWithError({
1535
- name: 'SolanaMobileWalletAdapterError',
1536
- code: 'ERROR_BROWSER_NOT_SUPPORTED',
1537
- message: ''
1538
- });
1539
- }
1540
- else { // Browser, user does not have a wallet installed.
1541
- // errorDialog.initWithError(
1542
- // new SolanaMobileWalletAdapterError(
1543
- // SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND,
1544
- // ''
1545
- // )
1546
- // );
1547
- // TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
1548
- errorDialog.initWithError({
1549
- name: 'SolanaMobileWalletAdapterError',
1550
- code: 'ERROR_WALLET_NOT_FOUND',
1551
- message: ''
1552
- });
1553
- }
1554
- errorDialog.open();
2036
+ async function defaultErrorModalWalletNotFoundHandler() {
2037
+ if (typeof window !== 'undefined') {
2038
+ const userAgent = window.navigator.userAgent.toLowerCase();
2039
+ const errorDialog = new ErrorModal();
2040
+ if (userAgent.includes('wv')) { // Android WebView
2041
+ // MWA is not supported in this browser so we inform the user
2042
+ // errorDialog.initWithError(
2043
+ // new SolanaMobileWalletAdapterError(
2044
+ // SolanaMobileWalletAdapterErrorCode.ERROR_BROWSER_NOT_SUPPORTED,
2045
+ // ''
2046
+ // )
2047
+ // );
2048
+ // TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
2049
+ errorDialog.initWithError({
2050
+ name: 'SolanaMobileWalletAdapterError',
2051
+ code: 'ERROR_BROWSER_NOT_SUPPORTED',
2052
+ message: ''
2053
+ });
1555
2054
  }
1556
- });
1557
- }
1558
- function createDefaultWalletNotFoundHandler() {
1559
- return () => __awaiter(this, void 0, void 0, function* () { defaultErrorModalWalletNotFoundHandler(); });
1560
- }
1561
-
1562
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
1563
-
1564
- const isOptionObject = require$$0__default["default"];
1565
-
1566
- const {hasOwnProperty} = Object.prototype;
1567
- const {propertyIsEnumerable} = Object;
1568
- const defineProperty = (object, name, value) => Object.defineProperty(object, name, {
1569
- value,
1570
- writable: true,
1571
- enumerable: true,
1572
- configurable: true
1573
- });
1574
-
1575
- const globalThis$1 = commonjsGlobal;
1576
- const defaultMergeOptions = {
1577
- concatArrays: false,
1578
- ignoreUndefined: false
1579
- };
1580
-
1581
- const getEnumerableOwnPropertyKeys = value => {
1582
- const keys = [];
1583
-
1584
- for (const key in value) {
1585
- if (hasOwnProperty.call(value, key)) {
1586
- keys.push(key);
1587
- }
1588
- }
1589
-
1590
- /* istanbul ignore else */
1591
- if (Object.getOwnPropertySymbols) {
1592
- const symbols = Object.getOwnPropertySymbols(value);
1593
-
1594
- for (const symbol of symbols) {
1595
- if (propertyIsEnumerable.call(value, symbol)) {
1596
- keys.push(symbol);
1597
- }
1598
- }
1599
- }
1600
-
1601
- return keys;
1602
- };
1603
-
1604
- function clone(value) {
1605
- if (Array.isArray(value)) {
1606
- return cloneArray(value);
1607
- }
1608
-
1609
- if (isOptionObject(value)) {
1610
- return cloneOptionObject(value);
1611
- }
1612
-
1613
- return value;
1614
- }
1615
-
1616
- function cloneArray(array) {
1617
- const result = array.slice(0, 0);
1618
-
1619
- getEnumerableOwnPropertyKeys(array).forEach(key => {
1620
- defineProperty(result, key, clone(array[key]));
1621
- });
1622
-
1623
- return result;
1624
- }
1625
-
1626
- function cloneOptionObject(object) {
1627
- const result = Object.getPrototypeOf(object) === null ? Object.create(null) : {};
1628
-
1629
- getEnumerableOwnPropertyKeys(object).forEach(key => {
1630
- defineProperty(result, key, clone(object[key]));
1631
- });
1632
-
1633
- return result;
1634
- }
1635
-
1636
- /**
1637
- * @param {*} merged already cloned
1638
- * @param {*} source something to merge
1639
- * @param {string[]} keys keys to merge
1640
- * @param {Object} config Config Object
1641
- * @returns {*} cloned Object
1642
- */
1643
- const mergeKeys = (merged, source, keys, config) => {
1644
- keys.forEach(key => {
1645
- if (typeof source[key] === 'undefined' && config.ignoreUndefined) {
1646
- return;
1647
- }
1648
-
1649
- // Do not recurse into prototype chain of merged
1650
- if (key in merged && merged[key] !== Object.getPrototypeOf(merged)) {
1651
- defineProperty(merged, key, merge$1(merged[key], source[key], config));
1652
- } else {
1653
- defineProperty(merged, key, clone(source[key]));
1654
- }
1655
- });
1656
-
1657
- return merged;
1658
- };
1659
-
1660
- /**
1661
- * @param {*} merged already cloned
1662
- * @param {*} source something to merge
1663
- * @param {Object} config Config Object
1664
- * @returns {*} cloned Object
1665
- *
1666
- * see [Array.prototype.concat ( ...arguments )](http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.concat)
1667
- */
1668
- const concatArrays = (merged, source, config) => {
1669
- let result = merged.slice(0, 0);
1670
- let resultIndex = 0;
1671
-
1672
- [merged, source].forEach(array => {
1673
- const indices = [];
1674
-
1675
- // `result.concat(array)` with cloning
1676
- for (let k = 0; k < array.length; k++) {
1677
- if (!hasOwnProperty.call(array, k)) {
1678
- continue;
1679
- }
1680
-
1681
- indices.push(String(k));
1682
-
1683
- if (array === merged) {
1684
- // Already cloned
1685
- defineProperty(result, resultIndex++, array[k]);
1686
- } else {
1687
- defineProperty(result, resultIndex++, clone(array[k]));
1688
- }
1689
- }
1690
-
1691
- // Merge non-index keys
1692
- result = mergeKeys(result, array, getEnumerableOwnPropertyKeys(array).filter(key => !indices.includes(key)), config);
1693
- });
1694
-
1695
- return result;
1696
- };
1697
-
1698
- /**
1699
- * @param {*} merged already cloned
1700
- * @param {*} source something to merge
1701
- * @param {Object} config Config Object
1702
- * @returns {*} cloned Object
1703
- */
1704
- function merge$1(merged, source, config) {
1705
- if (config.concatArrays && Array.isArray(merged) && Array.isArray(source)) {
1706
- return concatArrays(merged, source, config);
1707
- }
1708
-
1709
- if (!isOptionObject(source) || !isOptionObject(merged)) {
1710
- return clone(source);
1711
- }
1712
-
1713
- return mergeKeys(merged, source, getEnumerableOwnPropertyKeys(source), config);
1714
- }
1715
-
1716
- var mergeOptions = function (...options) {
1717
- const config = merge$1(clone(defaultMergeOptions), (this !== globalThis$1 && this) || {}, defaultMergeOptions);
1718
- let merged = {_: {}};
1719
-
1720
- for (const option of options) {
1721
- if (option === undefined) {
1722
- continue;
1723
- }
1724
-
1725
- if (!isOptionObject(option)) {
1726
- throw new TypeError('`' + option + '` is not an Option Object');
1727
- }
1728
-
1729
- merged = merge$1(merged, {_: option}, config);
1730
- }
1731
-
1732
- return merged._;
1733
- };
1734
-
1735
- /**
1736
- * Copyright (c) Nicolas Gallagher.
1737
- * Copyright (c) Facebook, Inc. and its affiliates.
1738
- *
1739
- * This source code is licensed under the MIT license found in the
1740
- * LICENSE file in the root directory of this source tree.
1741
- */
1742
- const merge = mergeOptions.bind({
1743
- concatArrays: true,
1744
- ignoreUndefined: true
1745
- });
1746
-
1747
- function mergeLocalStorageItem(key, value) {
1748
- const oldValue = window.localStorage.getItem(key);
1749
-
1750
- if (oldValue) {
1751
- const oldObject = JSON.parse(oldValue);
1752
- const newObject = JSON.parse(value);
1753
- const nextValue = JSON.stringify(merge(oldObject, newObject));
1754
- window.localStorage.setItem(key, nextValue);
1755
- } else {
1756
- window.localStorage.setItem(key, value);
1757
- }
1758
- }
1759
-
1760
- function createPromise(getValue, callback) {
1761
- return new Promise((resolve, reject) => {
1762
- try {
1763
- const value = getValue();
1764
- callback === null || callback === void 0 ? void 0 : callback(null, value);
1765
- resolve(value);
1766
- } catch (err) {
1767
- callback === null || callback === void 0 ? void 0 : callback(err);
1768
- reject(err);
2055
+ else { // Browser, user does not have a wallet installed.
2056
+ // errorDialog.initWithError(
2057
+ // new SolanaMobileWalletAdapterError(
2058
+ // SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND,
2059
+ // ''
2060
+ // )
2061
+ // );
2062
+ // TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
2063
+ errorDialog.initWithError({
2064
+ name: 'SolanaMobileWalletAdapterError',
2065
+ code: 'ERROR_WALLET_NOT_FOUND',
2066
+ message: ''
2067
+ });
2068
+ }
2069
+ errorDialog.open();
1769
2070
  }
1770
- });
1771
2071
  }
1772
-
1773
- function createPromiseAll(promises, callback, processResult) {
1774
- return Promise.all(promises).then(result => {
1775
- var _processResult;
1776
-
1777
- const value = (_processResult = processResult === null || processResult === void 0 ? void 0 : processResult(result)) !== null && _processResult !== void 0 ? _processResult : null;
1778
- callback === null || callback === void 0 ? void 0 : callback(null, value);
1779
- return Promise.resolve(value);
1780
- }, errors => {
1781
- callback === null || callback === void 0 ? void 0 : callback(errors);
1782
- return Promise.reject(errors);
1783
- });
2072
+ function createDefaultWalletNotFoundHandler() {
2073
+ return async () => { defaultErrorModalWalletNotFoundHandler(); };
1784
2074
  }
1785
2075
 
1786
- const AsyncStorage = {
1787
- /**
1788
- * Fetches `key` value.
1789
- */
1790
- getItem: (key, callback) => {
1791
- return createPromise(() => window.localStorage.getItem(key), callback);
1792
- },
1793
-
1794
- /**
1795
- * Sets `value` for `key`.
1796
- */
1797
- setItem: (key, value, callback) => {
1798
- return createPromise(() => window.localStorage.setItem(key, value), callback);
1799
- },
1800
-
1801
- /**
1802
- * Removes a `key`
1803
- */
1804
- removeItem: (key, callback) => {
1805
- return createPromise(() => window.localStorage.removeItem(key), callback);
1806
- },
1807
-
1808
- /**
1809
- * Merges existing value with input value, assuming they are stringified JSON.
1810
- */
1811
- mergeItem: (key, value, callback) => {
1812
- return createPromise(() => mergeLocalStorageItem(key, value), callback);
1813
- },
1814
-
1815
- /**
1816
- * Erases *all* AsyncStorage for the domain.
1817
- */
1818
- clear: callback => {
1819
- return createPromise(() => window.localStorage.clear(), callback);
1820
- },
1821
-
1822
- /**
1823
- * Gets *all* keys known to the app, for all callers, libraries, etc.
1824
- */
1825
- getAllKeys: callback => {
1826
- return createPromise(() => {
1827
- const numberOfKeys = window.localStorage.length;
1828
- const keys = [];
1829
-
1830
- for (let i = 0; i < numberOfKeys; i += 1) {
1831
- const key = window.localStorage.key(i) || '';
1832
- keys.push(key);
1833
- }
1834
-
1835
- return keys;
1836
- }, callback);
1837
- },
1838
-
1839
- /**
1840
- * (stub) Flushes any pending requests using a single batch call to get the data.
1841
- */
1842
- flushGetRequests: () => undefined,
1843
-
1844
- /**
1845
- * multiGet resolves to an array of key-value pair arrays that matches the
1846
- * input format of multiSet.
1847
- *
1848
- * multiGet(['k1', 'k2']) -> [['k1', 'val1'], ['k2', 'val2']]
1849
- */
1850
- multiGet: (keys, callback) => {
1851
- const promises = keys.map(key => AsyncStorage.getItem(key));
1852
-
1853
- const processResult = result => result.map((value, i) => [keys[i], value]);
1854
-
1855
- return createPromiseAll(promises, callback, processResult);
1856
- },
1857
-
1858
- /**
1859
- * Takes an array of key-value array pairs.
1860
- * multiSet([['k1', 'val1'], ['k2', 'val2']])
1861
- */
1862
- multiSet: (keyValuePairs, callback) => {
1863
- const promises = keyValuePairs.map(item => AsyncStorage.setItem(item[0], item[1]));
1864
- return createPromiseAll(promises, callback);
1865
- },
1866
-
1867
- /**
1868
- * Delete all the keys in the `keys` array.
1869
- */
1870
- multiRemove: (keys, callback) => {
1871
- const promises = keys.map(key => AsyncStorage.removeItem(key));
1872
- return createPromiseAll(promises, callback);
1873
- },
1874
-
1875
- /**
1876
- * Takes an array of key-value array pairs and merges them with existing
1877
- * values, assuming they are stringified JSON.
1878
- *
1879
- * multiMerge([['k1', 'val1'], ['k2', 'val2']])
1880
- */
1881
- multiMerge: (keyValuePairs, callback) => {
1882
- const promises = keyValuePairs.map(item => {
1883
- var _AsyncStorage$mergeIt, _AsyncStorage$mergeIt2;
1884
-
1885
- return (_AsyncStorage$mergeIt = (_AsyncStorage$mergeIt2 = AsyncStorage.mergeItem) === null || _AsyncStorage$mergeIt2 === void 0 ? void 0 : _AsyncStorage$mergeIt2.call(AsyncStorage, item[0], item[1])) !== null && _AsyncStorage$mergeIt !== void 0 ? _AsyncStorage$mergeIt : Promise.reject('Not implemented');
1886
- });
1887
- return createPromiseAll(promises, callback);
1888
- }
1889
- };
1890
-
1891
2076
  const CACHE_KEY = 'SolanaMobileWalletAdapterWalletStandardDefaultAuthorizationCache';
1892
2077
  function createDefaultAuthorizationCache() {
1893
2078
  return {
1894
- clear() {
1895
- return __awaiter(this, void 0, void 0, function* () {
1896
- try {
1897
- yield AsyncStorage.removeItem(CACHE_KEY);
1898
- // eslint-disable-next-line no-empty
1899
- }
1900
- catch (_a) { }
1901
- });
2079
+ async clear() {
2080
+ try {
2081
+ await AsyncStorage.removeItem(CACHE_KEY);
2082
+ // eslint-disable-next-line no-empty
2083
+ }
2084
+ catch { }
1902
2085
  },
1903
- get() {
1904
- return __awaiter(this, void 0, void 0, function* () {
1905
- try {
1906
- const parsed = JSON.parse((yield AsyncStorage.getItem(CACHE_KEY)));
1907
- if (parsed && parsed.accounts) {
1908
- const parsedAccounts = parsed.accounts.map((account) => {
1909
- return Object.assign(Object.assign({}, account), { publicKey: 'publicKey' in account
1910
- ? new Uint8Array(Object.values(account.publicKey)) // Rebuild publicKey for WalletAccount
1911
- : base58__default["default"].decode(account.address) });
1912
- });
1913
- return Object.assign(Object.assign({}, parsed), { accounts: parsedAccounts });
1914
- }
1915
- else
1916
- return parsed || undefined;
1917
- // eslint-disable-next-line no-empty
2086
+ async get() {
2087
+ try {
2088
+ const parsed = JSON.parse((await AsyncStorage.getItem(CACHE_KEY)));
2089
+ if (parsed && parsed.accounts) {
2090
+ const parsedAccounts = parsed.accounts.map((account) => {
2091
+ return {
2092
+ ...account,
2093
+ publicKey: 'publicKey' in account
2094
+ ? new Uint8Array(Object.values(account.publicKey)) // Rebuild publicKey for WalletAccount
2095
+ : base58.decode(account.address), // Fallback, get publicKey from address
2096
+ };
2097
+ });
2098
+ return { ...parsed, accounts: parsedAccounts };
1918
2099
  }
1919
- catch (_a) { }
1920
- });
2100
+ else
2101
+ return parsed || undefined;
2102
+ // eslint-disable-next-line no-empty
2103
+ }
2104
+ catch { }
1921
2105
  },
1922
- set(authorizationResult) {
1923
- return __awaiter(this, void 0, void 0, function* () {
1924
- try {
1925
- yield AsyncStorage.setItem(CACHE_KEY, JSON.stringify(authorizationResult));
1926
- // eslint-disable-next-line no-empty
1927
- }
1928
- catch (_a) { }
1929
- });
2106
+ async set(authorizationResult) {
2107
+ try {
2108
+ await AsyncStorage.setItem(CACHE_KEY, JSON.stringify(authorizationResult));
2109
+ // eslint-disable-next-line no-empty
2110
+ }
2111
+ catch { }
1930
2112
  },
1931
2113
  };
1932
2114
  }
1933
2115
 
1934
2116
  function createDefaultChainSelector() {
1935
2117
  return {
1936
- select(chains) {
1937
- return __awaiter(this, void 0, void 0, function* () {
1938
- if (chains.length === 1) {
1939
- return chains[0];
1940
- }
1941
- else if (chains.includes(walletStandardChains.SOLANA_MAINNET_CHAIN)) {
1942
- return walletStandardChains.SOLANA_MAINNET_CHAIN;
1943
- }
1944
- else
1945
- return chains[0];
1946
- });
2118
+ async select(chains) {
2119
+ if (chains.length === 1) {
2120
+ return chains[0];
2121
+ }
2122
+ else if (chains.includes(walletStandardChains.SOLANA_MAINNET_CHAIN)) {
2123
+ return walletStandardChains.SOLANA_MAINNET_CHAIN;
2124
+ }
2125
+ else
2126
+ return chains[0];
1947
2127
  },
1948
2128
  };
1949
2129
  }