@solana-mobile/wallet-standard-mobile 0.5.0 → 0.5.1

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,13 +1,36 @@
1
- 'use strict';
2
-
3
- var walletStandardFeatures = require('@solana/wallet-standard-features');
4
- var QRCode = require('qrcode');
5
- var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-protocol');
6
- var features = require('@wallet-standard/features');
7
- var base58 = require('bs58');
8
- var wallet = require('@wallet-standard/wallet');
9
- var walletStandardChains = require('@solana/wallet-standard-chains');
10
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let _solana_wallet_standard_features = require("@solana/wallet-standard-features");
25
+ let qrcode = require("qrcode");
26
+ qrcode = __toESM(qrcode);
27
+ let _solana_mobile_mobile_wallet_adapter_protocol = require("@solana-mobile/mobile-wallet-adapter-protocol");
28
+ let _wallet_standard_features = require("@wallet-standard/features");
29
+ let bs58 = require("bs58");
30
+ bs58 = __toESM(bs58);
31
+ let _wallet_standard_wallet = require("@wallet-standard/wallet");
32
+ let _solana_wallet_standard_chains = require("@solana/wallet-standard-chains");
33
+ //#region src/embedded-modal/loadingSpinner.ts
11
34
  const modalHtml$1 = `
12
35
  <div class="mobile-wallet-adapter-embedded-loading-indicator" role="dialog" aria-modal="true" aria-labelledby="modal-title">
13
36
  <div data-modal-close style="position: absolute; width: 100%; height: 100%;"></div>
@@ -88,92 +111,76 @@ const css$6 = `
88
111
  }
89
112
  }
90
113
  `;
91
- class EmbeddedLoadingSpinner {
92
- #root = null;
93
- #eventListeners = {};
94
- #listenersAttached = false;
95
- dom = null;
96
- constructor() {
97
- // Bind methods to ensure `this` context is correct
98
- this.init = this.init.bind(this);
99
- this.#root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
100
- }
101
- async init() {
102
- console.log('Injecting modal');
103
- this.#injectHTML();
104
- }
105
- open = () => {
106
- console.debug('Modal open');
107
- this.#attachEventListeners();
108
- if (this.#root) {
109
- this.#root.style.display = 'flex';
110
- }
111
- };
112
- close = (event = undefined) => {
113
- console.debug('Modal close');
114
- this.#removeEventListeners();
115
- if (this.#root) {
116
- this.#root.style.display = 'none';
117
- }
118
- this.#eventListeners['close']?.forEach((listener) => listener(event));
119
- };
120
- addEventListener(event, listener) {
121
- this.#eventListeners[event]?.push(listener) || (this.#eventListeners[event] = [listener]);
122
- return () => this.removeEventListener(event, listener);
123
- }
124
- removeEventListener(event, listener) {
125
- this.#eventListeners[event] = this.#eventListeners[event]?.filter((existingListener) => listener !== existingListener);
126
- }
127
- #injectHTML() {
128
- // Check if already injected by checking if shadow DOM exists
129
- if (this.dom) {
130
- return;
131
- }
132
- // Create a container for the modal
133
- this.#root = document.createElement('div');
134
- this.#root.id = 'mobile-wallet-adapter-embedded-root-ui';
135
- this.#root.innerHTML = modalHtml$1;
136
- this.#root.style.display = 'none';
137
- // Apply styles
138
- const styles = document.createElement('style');
139
- styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
140
- styles.textContent = css$6;
141
- // Create a shadow DOM to encapsulate the modal
142
- const host = document.createElement('div');
143
- this.dom = host.attachShadow({ mode: 'closed' });
144
- // Pass the CSS variable to the Shadow DOM
145
- host.style.setProperty('--spinner-color', '#FFFFFF');
146
- this.dom.appendChild(styles);
147
- this.dom.appendChild(this.#root);
148
- // Append the shadow DOM host to the body
149
- document.body.appendChild(host);
150
- }
151
- #attachEventListeners() {
152
- if (!this.#root || this.#listenersAttached)
153
- return;
154
- const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
155
- closers.forEach(closer => closer?.addEventListener('click', (event) => { this.close(event); }));
156
- window.addEventListener('load', this.close);
157
- document.addEventListener('keydown', this.#handleKeyDown);
158
- this.#listenersAttached = true;
159
- }
160
- #removeEventListeners() {
161
- if (!this.#listenersAttached)
162
- return;
163
- window.removeEventListener('load', this.close);
164
- document.removeEventListener('keydown', this.#handleKeyDown);
165
- if (!this.#root)
166
- return;
167
- const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
168
- closers.forEach(closer => closer?.removeEventListener('click', this.close));
169
- this.#listenersAttached = false;
170
- }
171
- #handleKeyDown = (event) => {
172
- if (event.key === 'Escape')
173
- this.close(event);
174
- };
175
- }
176
-
114
+ var EmbeddedLoadingSpinner = class {
115
+ #root = null;
116
+ #eventListeners = {};
117
+ #listenersAttached = false;
118
+ dom = null;
119
+ constructor() {
120
+ this.init = this.init.bind(this);
121
+ this.#root = document.getElementById("mobile-wallet-adapter-embedded-root-ui");
122
+ }
123
+ async init() {
124
+ console.log("Injecting modal");
125
+ this.#injectHTML();
126
+ }
127
+ open = () => {
128
+ console.debug("Modal open");
129
+ this.#attachEventListeners();
130
+ if (this.#root) this.#root.style.display = "flex";
131
+ };
132
+ close = (event = void 0) => {
133
+ console.debug("Modal close");
134
+ this.#removeEventListeners();
135
+ if (this.#root) this.#root.style.display = "none";
136
+ this.#eventListeners["close"]?.forEach((listener) => listener(event));
137
+ };
138
+ addEventListener(event, listener) {
139
+ this.#eventListeners[event]?.push(listener) || (this.#eventListeners[event] = [listener]);
140
+ return () => this.removeEventListener(event, listener);
141
+ }
142
+ removeEventListener(event, listener) {
143
+ this.#eventListeners[event] = this.#eventListeners[event]?.filter((existingListener) => listener !== existingListener);
144
+ }
145
+ #injectHTML() {
146
+ if (this.dom) return;
147
+ this.#root = document.createElement("div");
148
+ this.#root.id = "mobile-wallet-adapter-embedded-root-ui";
149
+ this.#root.innerHTML = modalHtml$1;
150
+ this.#root.style.display = "none";
151
+ const styles = document.createElement("style");
152
+ styles.id = "mobile-wallet-adapter-embedded-modal-styles";
153
+ styles.textContent = css$6;
154
+ const host = document.createElement("div");
155
+ this.dom = host.attachShadow({ mode: "closed" });
156
+ host.style.setProperty("--spinner-color", "#FFFFFF");
157
+ this.dom.appendChild(styles);
158
+ this.dom.appendChild(this.#root);
159
+ document.body.appendChild(host);
160
+ }
161
+ #attachEventListeners() {
162
+ if (!this.#root || this.#listenersAttached) return;
163
+ [...this.#root.querySelectorAll("[data-modal-close]")].forEach((closer) => closer?.addEventListener("click", (event) => {
164
+ this.close(event);
165
+ }));
166
+ window.addEventListener("load", this.close);
167
+ document.addEventListener("keydown", this.#handleKeyDown);
168
+ this.#listenersAttached = true;
169
+ }
170
+ #removeEventListeners() {
171
+ if (!this.#listenersAttached) return;
172
+ window.removeEventListener("load", this.close);
173
+ document.removeEventListener("keydown", this.#handleKeyDown);
174
+ if (!this.#root) return;
175
+ [...this.#root.querySelectorAll("[data-modal-close]")].forEach((closer) => closer?.removeEventListener("click", this.close));
176
+ this.#listenersAttached = false;
177
+ }
178
+ #handleKeyDown = (event) => {
179
+ if (event.key === "Escape") this.close(event);
180
+ };
181
+ };
182
+ //#endregion
183
+ //#region src/embedded-modal/modal.ts
177
184
  const modalHtml = `
178
185
  <div class="mobile-wallet-adapter-embedded-modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-title">
179
186
  <div data-modal-close style="position: absolute; width: 100%; height: 100%;"></div>
@@ -195,7 +202,7 @@ const css$5 = `
195
202
  justify-content: center; /* Center horizontally */
196
203
  align-items: center; /* Center vertically */
197
204
  position: fixed; /* Stay in place */
198
- z-index: 1; /* Sit on top */
205
+ z-index: 2147483647; /* Sit on top */
199
206
  left: 0;
200
207
  top: 0;
201
208
  width: 100%; /* Full width */
@@ -251,124 +258,100 @@ const fonts = `
251
258
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
252
259
  <link href="https://fonts.googleapis.com/css2?family=Inter+Tight:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
253
260
  `;
254
- class EmbeddedModal {
255
- #root = null;
256
- #eventListeners = {};
257
- #listenersAttached = false;
258
- dom = null;
259
- constructor() {
260
- // Bind methods to ensure `this` context is correct
261
- this.init = this.init.bind(this);
262
- this.#root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
263
- }
264
- async init() {
265
- console.log('Injecting modal');
266
- this.#injectHTML();
267
- }
268
- open = () => {
269
- console.debug('Modal open');
270
- this.#attachEventListeners();
271
- if (this.#root) {
272
- this.#root.style.display = 'flex';
273
- }
274
- };
275
- close = (event = undefined) => {
276
- console.debug('Modal close');
277
- this.#removeEventListeners();
278
- if (this.#root) {
279
- this.#root.style.display = 'none';
280
- }
281
- this.#eventListeners['close']?.forEach((listener) => listener(event));
282
- };
283
- addEventListener(event, listener) {
284
- this.#eventListeners[event]?.push(listener) || (this.#eventListeners[event] = [listener]);
285
- return () => this.removeEventListener(event, listener);
286
- }
287
- removeEventListener(event, listener) {
288
- this.#eventListeners[event] = this.#eventListeners[event]?.filter((existingListener) => listener !== existingListener);
289
- }
290
- #injectHTML() {
291
- // Check if the HTML has already been injected
292
- if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
293
- if (!this.#root)
294
- this.#root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
295
- return;
296
- }
297
- // Create a container for the modal
298
- this.#root = document.createElement('div');
299
- this.#root.id = 'mobile-wallet-adapter-embedded-root-ui';
300
- this.#root.innerHTML = modalHtml;
301
- this.#root.style.display = 'none';
302
- // Add modal content
303
- const content = this.#root.querySelector('.mobile-wallet-adapter-embedded-modal-content');
304
- if (content)
305
- content.innerHTML = this.contentHtml;
306
- // Apply styles
307
- const styles = document.createElement('style');
308
- styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
309
- styles.textContent = css$5 + this.contentStyles;
310
- // Create a shadow DOM to encapsulate the modal
311
- const host = document.createElement('div');
312
- host.innerHTML = fonts;
313
- this.dom = host.attachShadow({ mode: 'closed' });
314
- this.dom.appendChild(styles);
315
- this.dom.appendChild(this.#root);
316
- // Append the shadow DOM host to the body
317
- document.body.appendChild(host);
318
- }
319
- #attachEventListeners() {
320
- if (!this.#root || this.#listenersAttached)
321
- return;
322
- const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
323
- closers.forEach(closer => closer?.addEventListener('click', this.close));
324
- window.addEventListener('load', this.close);
325
- document.addEventListener('keydown', this.#handleKeyDown);
326
- this.#listenersAttached = true;
327
- }
328
- #removeEventListeners() {
329
- if (!this.#listenersAttached)
330
- return;
331
- window.removeEventListener('load', this.close);
332
- document.removeEventListener('keydown', this.#handleKeyDown);
333
- if (!this.#root)
334
- return;
335
- const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
336
- closers.forEach(closer => closer?.removeEventListener('click', this.close));
337
- this.#listenersAttached = false;
338
- }
339
- #handleKeyDown = (event) => {
340
- if (event.key === 'Escape')
341
- this.close(event);
342
- };
343
- }
344
-
345
- class RemoteConnectionModal extends EmbeddedModal {
346
- contentStyles = css$4;
347
- contentHtml = QRCodeHtml;
348
- async initWithQR(qrCode) {
349
- super.init();
350
- this.populateQRCode(qrCode);
351
- }
352
- async populateQRCode(qrUrl) {
353
- const qrcodeContainer = this.dom?.getElementById('mobile-wallet-adapter-embedded-modal-qr-code-container');
354
- if (qrcodeContainer) {
355
- const qrCodeElement = await QRCode.toCanvas(qrUrl, { width: 200, margin: 0 });
356
- if (qrcodeContainer.firstElementChild !== null) {
357
- qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
358
- }
359
- else
360
- qrcodeContainer.appendChild(qrCodeElement);
361
- // remove the loading placeholder for cleanup
362
- const qrPlaceholder = this.dom?.getElementById('mobile-wallet-adapter-embedded-modal-qr-placeholder');
363
- if (qrPlaceholder) {
364
- qrPlaceholder.style.display = 'none';
365
- }
366
- }
367
- else {
368
- console.error('QRCode Container not found');
369
- }
370
- }
371
- }
261
+ var EmbeddedModal = class {
262
+ #root = null;
263
+ #eventListeners = {};
264
+ #listenersAttached = false;
265
+ dom = null;
266
+ constructor() {
267
+ this.init = this.init.bind(this);
268
+ this.#root = document.getElementById("mobile-wallet-adapter-embedded-root-ui");
269
+ }
270
+ async init() {
271
+ console.log("Injecting modal");
272
+ this.#injectHTML();
273
+ }
274
+ open = () => {
275
+ console.debug("Modal open");
276
+ this.#attachEventListeners();
277
+ if (this.#root) this.#root.style.display = "flex";
278
+ };
279
+ close = (event = void 0) => {
280
+ console.debug("Modal close");
281
+ this.#removeEventListeners();
282
+ if (this.#root) this.#root.style.display = "none";
283
+ this.#eventListeners["close"]?.forEach((listener) => listener(event));
284
+ };
285
+ addEventListener(event, listener) {
286
+ this.#eventListeners[event]?.push(listener) || (this.#eventListeners[event] = [listener]);
287
+ return () => this.removeEventListener(event, listener);
288
+ }
289
+ removeEventListener(event, listener) {
290
+ this.#eventListeners[event] = this.#eventListeners[event]?.filter((existingListener) => listener !== existingListener);
291
+ }
292
+ #injectHTML() {
293
+ if (document.getElementById("mobile-wallet-adapter-embedded-root-ui")) {
294
+ if (!this.#root) this.#root = document.getElementById("mobile-wallet-adapter-embedded-root-ui");
295
+ return;
296
+ }
297
+ this.#root = document.createElement("div");
298
+ this.#root.id = "mobile-wallet-adapter-embedded-root-ui";
299
+ this.#root.innerHTML = modalHtml;
300
+ this.#root.style.display = "none";
301
+ const content = this.#root.querySelector(".mobile-wallet-adapter-embedded-modal-content");
302
+ if (content) content.innerHTML = this.contentHtml;
303
+ const styles = document.createElement("style");
304
+ styles.id = "mobile-wallet-adapter-embedded-modal-styles";
305
+ styles.textContent = css$5 + this.contentStyles;
306
+ const host = document.createElement("div");
307
+ host.innerHTML = fonts;
308
+ this.dom = host.attachShadow({ mode: "closed" });
309
+ this.dom.appendChild(styles);
310
+ this.dom.appendChild(this.#root);
311
+ document.body.appendChild(host);
312
+ }
313
+ #attachEventListeners() {
314
+ if (!this.#root || this.#listenersAttached) return;
315
+ [...this.#root.querySelectorAll("[data-modal-close]")].forEach((closer) => closer?.addEventListener("click", this.close));
316
+ window.addEventListener("load", this.close);
317
+ document.addEventListener("keydown", this.#handleKeyDown);
318
+ this.#listenersAttached = true;
319
+ }
320
+ #removeEventListeners() {
321
+ if (!this.#listenersAttached) return;
322
+ window.removeEventListener("load", this.close);
323
+ document.removeEventListener("keydown", this.#handleKeyDown);
324
+ if (!this.#root) return;
325
+ [...this.#root.querySelectorAll("[data-modal-close]")].forEach((closer) => closer?.removeEventListener("click", this.close));
326
+ this.#listenersAttached = false;
327
+ }
328
+ #handleKeyDown = (event) => {
329
+ if (event.key === "Escape") this.close(event);
330
+ };
331
+ };
332
+ //#endregion
333
+ //#region src/embedded-modal/remoteConnectionModal.ts
334
+ var RemoteConnectionModal = class extends EmbeddedModal {
335
+ contentStyles = css$4;
336
+ contentHtml = QRCodeHtml;
337
+ async initWithQR(qrCode) {
338
+ super.init();
339
+ this.populateQRCode(qrCode);
340
+ }
341
+ async populateQRCode(qrUrl) {
342
+ const qrcodeContainer = this.dom?.getElementById("mobile-wallet-adapter-embedded-modal-qr-code-container");
343
+ if (qrcodeContainer) {
344
+ const qrCodeElement = await qrcode.default.toCanvas(qrUrl, {
345
+ width: 200,
346
+ margin: 0
347
+ });
348
+ if (qrcodeContainer.firstElementChild !== null) qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
349
+ else qrcodeContainer.appendChild(qrCodeElement);
350
+ const qrPlaceholder = this.dom?.getElementById("mobile-wallet-adapter-embedded-modal-qr-placeholder");
351
+ if (qrPlaceholder) qrPlaceholder.style.display = "none";
352
+ } else console.error("QRCode Container not found");
353
+ }
354
+ };
372
355
  const QRCodeHtml = `
373
356
  <div class="mobile-wallet-adapter-embedded-modal-qr-content">
374
357
  <div>
@@ -628,36 +611,36 @@ const css$4 = `
628
611
  animation: spinRight 2.5s cubic-bezier(.2,0,.8,1) infinite;
629
612
  }
630
613
  `;
631
-
632
- const icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=';
633
-
614
+ //#endregion
615
+ //#region src/icon.ts
616
+ const icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=";
617
+ //#endregion
618
+ //#region src/base64Utils.ts
634
619
  function fromUint8Array(byteArray) {
635
- return window.btoa(String.fromCharCode.call(null, ...byteArray));
620
+ return window.btoa(String.fromCharCode.call(null, ...byteArray));
636
621
  }
637
622
  function toUint8Array(base64EncodedByteArray) {
638
- return new Uint8Array(window
639
- .atob(base64EncodedByteArray)
640
- .split('')
641
- .map((c) => c.charCodeAt(0)));
642
- }
643
-
644
- class LocalConnectionModal extends EmbeddedModal {
645
- contentStyles = css$3;
646
- contentHtml = ErrorDialogHtml$3;
647
- initWithCallback(callback) {
648
- super.init();
649
- this.#prepareLaunchAction(callback);
650
- }
651
- #prepareLaunchAction(callback) {
652
- const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
653
- const listener = async () => {
654
- launchButton?.removeEventListener('click', listener);
655
- this.close();
656
- callback();
657
- };
658
- launchButton?.addEventListener('click', listener);
659
- }
660
- }
623
+ return new Uint8Array(window.atob(base64EncodedByteArray).split("").map((c) => c.charCodeAt(0)));
624
+ }
625
+ //#endregion
626
+ //#region src/embedded-modal/localConnectionModal.ts
627
+ var LocalConnectionModal = class extends EmbeddedModal {
628
+ contentStyles = css$3;
629
+ contentHtml = ErrorDialogHtml$3;
630
+ initWithCallback(callback) {
631
+ super.init();
632
+ this.#prepareLaunchAction(callback);
633
+ }
634
+ #prepareLaunchAction(callback) {
635
+ const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
636
+ const listener = async () => {
637
+ launchButton?.removeEventListener("click", listener);
638
+ this.close();
639
+ callback();
640
+ };
641
+ launchButton?.addEventListener("click", listener);
642
+ }
643
+ };
661
644
  const ErrorDialogHtml$3 = `
662
645
  <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">
663
646
  <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"/>
@@ -715,28 +698,27 @@ const css$3 = `
715
698
  }
716
699
  }
717
700
  `;
718
-
719
- class LoopbackPermissionBlockedModal extends EmbeddedModal {
720
- contentStyles = css$2;
721
- get contentHtml() {
722
- const instructions = getIsPwaLaunchedAsApp()
723
- ? 'Long press the app icon on your home screen to open site settings'
724
- : 'Tap the lock or settings icon in the address bar to open site settings';
725
- return ErrorDialogHtml$2.replace('{{PERMISSION_INSTRUCTION_DETAIL}}', instructions);
726
- }
727
- async init() {
728
- super.init();
729
- this.#prepareLaunchAction();
730
- }
731
- #prepareLaunchAction() {
732
- const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
733
- const listener = async (event) => {
734
- launchButton?.removeEventListener('click', listener);
735
- this.close(event);
736
- };
737
- launchButton?.addEventListener('click', listener);
738
- }
739
- }
701
+ //#endregion
702
+ //#region src/embedded-modal/loopbackBlockedModal.ts
703
+ var LoopbackPermissionBlockedModal = class extends EmbeddedModal {
704
+ contentStyles = css$2;
705
+ get contentHtml() {
706
+ const instructions = getIsPwaLaunchedAsApp() ? "Long press the app icon on your home screen to open site settings" : "Tap the lock or settings icon in the address bar to open site settings";
707
+ return ErrorDialogHtml$2.replace("{{PERMISSION_INSTRUCTION_DETAIL}}", instructions);
708
+ }
709
+ async init() {
710
+ super.init();
711
+ this.#prepareLaunchAction();
712
+ }
713
+ #prepareLaunchAction() {
714
+ const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
715
+ const listener = async (event) => {
716
+ launchButton?.removeEventListener("click", listener);
717
+ this.close(event);
718
+ };
719
+ launchButton?.addEventListener("click", listener);
720
+ }
721
+ };
740
722
  const ErrorDialogHtml$2 = `
741
723
  <div class="mobile-wallet-adapter-embedded-modal-header">
742
724
  Local Wallet Connection
@@ -877,28 +859,27 @@ const css$2 = `
877
859
  }
878
860
  }
879
861
  `;
880
-
881
- class LoopbackPermissionModal extends EmbeddedModal {
882
- contentStyles = css$1;
883
- contentHtml = ErrorDialogHtml$1;
884
- async init() {
885
- super.init();
886
- this.#prepareLaunchAction();
887
- }
888
- #prepareLaunchAction() {
889
- const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
890
- const listener = async () => {
891
- launchButton?.removeEventListener('click', listener);
892
- try {
893
- // Trigger LNA permission prompting
894
- await fetch('http://localhost');
895
- }
896
- catch (e) { /* Ignore errors from fetch */ }
897
- this.close();
898
- };
899
- launchButton?.addEventListener('click', listener);
900
- }
901
- }
862
+ //#endregion
863
+ //#region src/embedded-modal/loopbackPermissionModal.ts
864
+ var LoopbackPermissionModal = class extends EmbeddedModal {
865
+ contentStyles = css$1;
866
+ contentHtml = ErrorDialogHtml$1;
867
+ async init() {
868
+ super.init();
869
+ this.#prepareLaunchAction();
870
+ }
871
+ #prepareLaunchAction() {
872
+ const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
873
+ const listener = async () => {
874
+ launchButton?.removeEventListener("click", listener);
875
+ try {
876
+ await fetch("http://localhost");
877
+ } catch (e) {}
878
+ this.close();
879
+ };
880
+ launchButton?.addEventListener("click", listener);
881
+ }
882
+ };
902
883
  const ErrorDialogHtml$1 = `
903
884
  <div class="mobile-wallet-adapter-embedded-modal-title">Allow connections to your wallet</div>
904
885
  <div id="mobile-wallet-adapter-local-launch-message" class="mobile-wallet-adapter-embedded-modal-subtitle">
@@ -972,1015 +953,834 @@ const css$1 = `
972
953
  }
973
954
  }
974
955
  `;
975
-
956
+ //#endregion
957
+ //#region src/getIsSupported.ts
976
958
  function getIsLocalAssociationSupported() {
977
- return (typeof window !== 'undefined' &&
978
- window.isSecureContext &&
979
- typeof document !== 'undefined' &&
980
- /android/i.test(navigator.userAgent));
959
+ return typeof window !== "undefined" && window.isSecureContext && typeof document !== "undefined" && /android/i.test(navigator.userAgent);
981
960
  }
982
961
  function getIsRemoteAssociationSupported() {
983
- return (typeof window !== 'undefined' &&
984
- window.isSecureContext &&
985
- typeof document !== 'undefined' &&
986
- !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
962
+ return typeof window !== "undefined" && window.isSecureContext && typeof document !== "undefined" && !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
987
963
  }
988
- // Source: https://github.com/anza-xyz/wallet-adapter/blob/master/packages/core/react/src/getEnvironment.ts#L14
989
- // This is the same implementation that gated MWA in the Anza wallet-adapter-react library.
990
964
  function isWebView(userAgentString) {
991
- return /(WebView|Version\/.+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+)|; wv\).+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+))/i.test(userAgentString);
965
+ return /(WebView|Version\/.+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+)|; wv\).+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+))/i.test(userAgentString);
966
+ }
967
+ function isSolanaMobileWebShell(userAgentString) {
968
+ return userAgentString.includes("Solana Mobile Web Shell");
992
969
  }
993
- // Source: https://web.dev/learn/pwa/detection/
994
970
  function getIsPwaLaunchedAsApp() {
995
- // Check for Android TWA
996
- const isAndroidTwa = typeof document !== 'undefined' && document.referrer.startsWith('android-app://');
997
- // Check for display-mode: standalone, fullscreen, or minimal-ui
998
- if (typeof window == 'undefined')
999
- return isAndroidTwa;
1000
- const isStandalone = window.matchMedia('(display-mode: standalone)').matches;
1001
- const isFullscreen = window.matchMedia('(display-mode: fullscreen)').matches;
1002
- const isMinimalUI = window.matchMedia('(display-mode: minimal-ui)').matches;
1003
- // App mode if any of these conditions are true
1004
- return isAndroidTwa || isStandalone || isFullscreen || isMinimalUI;
971
+ const isAndroidTwa = typeof document !== "undefined" && document.referrer.startsWith("android-app://");
972
+ if (typeof window == "undefined") return isAndroidTwa;
973
+ const isStandalone = window.matchMedia("(display-mode: standalone)").matches;
974
+ const isFullscreen = window.matchMedia("(display-mode: fullscreen)").matches;
975
+ const isMinimalUI = window.matchMedia("(display-mode: minimal-ui)").matches;
976
+ return isAndroidTwa || isStandalone || isFullscreen || isMinimalUI;
1005
977
  }
1006
978
  async function checkLocalNetworkAccessPermission() {
1007
- try {
1008
- let lnaPermission = await navigator.permissions.query({ name: "loopback-network" });
1009
- if (lnaPermission.state === "granted") {
1010
- // LNA permission already granted, continuing
1011
- return;
1012
- }
1013
- else if (lnaPermission.state === "denied") {
1014
- // LNA permission denied, aborting
1015
- const modal = new LoopbackPermissionBlockedModal();
1016
- modal.init();
1017
- modal.open();
1018
- throw new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, 'Local Network Access permission denied');
1019
- }
1020
- else if (lnaPermission.state === "prompt") {
1021
- // Show permission explainer to user, and wait for the permission to change
1022
- const modal = new LoopbackPermissionModal();
1023
- const updatedState = await new Promise((resolve, reject) => {
1024
- modal.addEventListener('close', (event) => {
1025
- if (event) {
1026
- reject(new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, 'Wallet connection cancelled by user', { event }));
1027
- }
1028
- });
1029
- lnaPermission.onchange = () => {
1030
- lnaPermission.onchange = null; // cleanup
1031
- resolve(lnaPermission.state);
1032
- };
1033
- modal.init();
1034
- modal.open();
1035
- });
1036
- if (updatedState === "granted") {
1037
- // User has granted the permission, now we need another click to continue
1038
- // Note: this is required to avoid being blocked by the browsers pop-up blocker
1039
- const modal = new LocalConnectionModal();
1040
- await new Promise((resolve, reject) => {
1041
- modal.addEventListener('close', (event) => {
1042
- if (event) {
1043
- reject(new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, 'Wallet connection cancelled by user', { event }));
1044
- }
1045
- });
1046
- modal.initWithCallback(async () => {
1047
- resolve(true);
1048
- });
1049
- modal.open();
1050
- });
1051
- return;
1052
- }
1053
- else {
1054
- // recurse, to avoid duplicating above logic
1055
- return await checkLocalNetworkAccessPermission();
1056
- }
1057
- }
1058
- // Shouldn't ever get here
1059
- throw new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, 'Local Network Access permission unknown');
1060
- }
1061
- catch (e) {
1062
- if (e instanceof TypeError &&
1063
- (e.message.includes('loopback-network') ||
1064
- e.message.includes('local-network-access'))) {
1065
- // LNA permission API not found, continuing
1066
- return;
1067
- }
1068
- // Re-throw existing adapter errors as-is
1069
- if (e instanceof mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError) {
1070
- throw e;
1071
- }
1072
- // An unknown error occurred, wrap it
1073
- throw new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, e instanceof Error ? e.message : 'Local Network Access permission unknown');
1074
- }
1075
- }
1076
-
1077
- const SolanaMobileWalletAdapterWalletName = 'Mobile Wallet Adapter';
1078
- const SolanaMobileWalletAdapterRemoteWalletName = 'Remote Mobile Wallet Adapter';
979
+ if (typeof navigator !== "undefined" && isSolanaMobileWebShell(navigator.userAgent)) return;
980
+ try {
981
+ let lnaPermission = await navigator.permissions.query({ name: "loopback-network" });
982
+ if (lnaPermission.state === "granted") return;
983
+ else if (lnaPermission.state === "denied") {
984
+ const modal = new LoopbackPermissionBlockedModal();
985
+ modal.init();
986
+ modal.open();
987
+ throw new _solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterError(_solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, "Local Network Access permission denied");
988
+ } else if (lnaPermission.state === "prompt") {
989
+ const modal = new LoopbackPermissionModal();
990
+ if (await new Promise((resolve, reject) => {
991
+ modal.addEventListener("close", (event) => {
992
+ if (event) reject(new _solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterError(_solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, "Wallet connection cancelled by user", { event }));
993
+ });
994
+ lnaPermission.onchange = () => {
995
+ lnaPermission.onchange = null;
996
+ resolve(lnaPermission.state);
997
+ };
998
+ modal.init();
999
+ modal.open();
1000
+ }) === "granted") {
1001
+ const modal = new LocalConnectionModal();
1002
+ await new Promise((resolve, reject) => {
1003
+ modal.addEventListener("close", (event) => {
1004
+ if (event) reject(new _solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterError(_solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, "Wallet connection cancelled by user", { event }));
1005
+ });
1006
+ modal.initWithCallback(async () => {
1007
+ resolve(true);
1008
+ });
1009
+ modal.open();
1010
+ });
1011
+ return;
1012
+ } else return await checkLocalNetworkAccessPermission();
1013
+ }
1014
+ throw new _solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterError(_solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, "Local Network Access permission unknown");
1015
+ } catch (e) {
1016
+ if (e instanceof TypeError && (e.message.includes("loopback-network") || e.message.includes("local-network-access"))) return;
1017
+ if (e instanceof _solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterError) throw e;
1018
+ throw new _solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterError(_solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, e instanceof Error ? e.message : "Local Network Access permission unknown");
1019
+ }
1020
+ }
1021
+ //#endregion
1022
+ //#region src/wallet.ts
1023
+ const SolanaMobileWalletAdapterWalletName = "Mobile Wallet Adapter";
1024
+ const SolanaMobileWalletAdapterRemoteWalletName = "Remote Mobile Wallet Adapter";
1079
1025
  const SIGNATURE_LENGTH_IN_BYTES = 64;
1080
- const DEFAULT_FEATURES = [walletStandardFeatures.SolanaSignAndSendTransaction, walletStandardFeatures.SolanaSignTransaction, walletStandardFeatures.SolanaSignMessage, walletStandardFeatures.SolanaSignIn];
1081
- const WALLET_ASSOCIATION_TIMEOUT = 30_000;
1082
- class LocalSolanaMobileWalletAdapterWallet {
1083
- #listeners = {};
1084
- #version = '1.0.0'; // wallet-standard version
1085
- #name = SolanaMobileWalletAdapterWalletName;
1086
- #url = 'https://solanamobile.com/wallets';
1087
- #icon = icon;
1088
- #appIdentity;
1089
- #authorization;
1090
- #authorizationCache;
1091
- #connecting = false;
1092
- /**
1093
- * Every time the connection is recycled in some way (eg. `disconnect()` is called)
1094
- * increment this and use it to make sure that `transact` calls from the previous
1095
- * 'generation' don't continue to do work and throw exceptions.
1096
- */
1097
- #connectionGeneration = 0;
1098
- #chains = [];
1099
- #chainSelector;
1100
- #optionalFeatures;
1101
- #onWalletNotFound;
1102
- get version() {
1103
- return this.#version;
1104
- }
1105
- get name() {
1106
- return this.#name;
1107
- }
1108
- get url() {
1109
- return this.#url;
1110
- }
1111
- get icon() {
1112
- return this.#icon;
1113
- }
1114
- get chains() {
1115
- return this.#chains;
1116
- }
1117
- get features() {
1118
- return {
1119
- [features.StandardConnect]: {
1120
- version: '1.0.0',
1121
- connect: this.#connect,
1122
- },
1123
- [features.StandardDisconnect]: {
1124
- version: '1.0.0',
1125
- disconnect: this.#disconnect,
1126
- },
1127
- [features.StandardEvents]: {
1128
- version: '1.0.0',
1129
- on: this.#on,
1130
- },
1131
- [walletStandardFeatures.SolanaSignMessage]: {
1132
- version: '1.0.0',
1133
- signMessage: this.#signMessage,
1134
- },
1135
- [walletStandardFeatures.SolanaSignIn]: {
1136
- version: '1.0.0',
1137
- signIn: this.#signIn,
1138
- },
1139
- ...this.#optionalFeatures,
1140
- };
1141
- }
1142
- get accounts() {
1143
- return this.#authorization?.accounts ?? [];
1144
- }
1145
- constructor(config) {
1146
- this.#authorizationCache = config.authorizationCache;
1147
- this.#appIdentity = config.appIdentity;
1148
- this.#chains = config.chains;
1149
- this.#chainSelector = config.chainSelector;
1150
- this.#onWalletNotFound = config.onWalletNotFound;
1151
- this.#optionalFeatures = {
1152
- // In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
1153
- // signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
1154
- // 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
1155
- // assume both are supported here. The features will be updated based on the actual connected
1156
- // wallets capabilities during connection regardless, so this is safe.
1157
- [walletStandardFeatures.SolanaSignAndSendTransaction]: {
1158
- version: '1.0.0',
1159
- supportedTransactionVersions: ['legacy', 0],
1160
- signAndSendTransaction: this.#signAndSendTransaction,
1161
- },
1162
- [walletStandardFeatures.SolanaSignTransaction]: {
1163
- version: '1.0.0',
1164
- supportedTransactionVersions: ['legacy', 0],
1165
- signTransaction: this.#signTransaction,
1166
- },
1167
- };
1168
- }
1169
- get connected() {
1170
- return !!this.#authorization;
1171
- }
1172
- get isAuthorized() {
1173
- return !!this.#authorization;
1174
- }
1175
- get currentAuthorization() {
1176
- return this.#authorization;
1177
- }
1178
- get cachedAuthorizationResult() {
1179
- return this.#authorizationCache.get();
1180
- }
1181
- #on = (event, listener) => {
1182
- this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
1183
- return () => this.#off(event, listener);
1184
- };
1185
- #emit(event, ...args) {
1186
- // eslint-disable-next-line prefer-spread
1187
- this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
1188
- }
1189
- #off(event, listener) {
1190
- this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
1191
- }
1192
- #connect = async ({ silent } = {}) => {
1193
- if (this.#connecting || this.connected) {
1194
- return { accounts: this.accounts };
1195
- }
1196
- this.#connecting = true;
1197
- try {
1198
- if (silent) {
1199
- const cachedAuthorization = await this.#authorizationCache.get();
1200
- if (cachedAuthorization) {
1201
- await this.#handleWalletCapabilitiesResult(cachedAuthorization.capabilities);
1202
- await this.#handleAuthorizationResult(cachedAuthorization);
1203
- }
1204
- else {
1205
- return { accounts: this.accounts };
1206
- }
1207
- }
1208
- else {
1209
- await this.#performAuthorization();
1210
- }
1211
- }
1212
- catch (e) {
1213
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1214
- }
1215
- finally {
1216
- this.#connecting = false;
1217
- }
1218
- return { accounts: this.accounts };
1219
- };
1220
- #performAuthorization = async (signInPayload) => {
1221
- try {
1222
- const cachedAuthorizationResult = await this.#authorizationCache.get();
1223
- if (cachedAuthorizationResult) {
1224
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1225
- this.#handleAuthorizationResult(cachedAuthorizationResult);
1226
- return cachedAuthorizationResult;
1227
- }
1228
- const selectedChain = await this.#chainSelector.select(this.#chains);
1229
- return await this.#transact(async (wallet) => {
1230
- const [capabilities, mwaAuthorizationResult] = await Promise.all([
1231
- wallet.getCapabilities(),
1232
- wallet.authorize({
1233
- chain: selectedChain,
1234
- identity: this.#appIdentity,
1235
- sign_in_payload: signInPayload,
1236
- })
1237
- ]);
1238
- const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1239
- const authorization = { ...mwaAuthorizationResult,
1240
- accounts, chain: selectedChain, capabilities: capabilities };
1241
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1242
- Promise.all([
1243
- this.#handleWalletCapabilitiesResult(capabilities),
1244
- this.#authorizationCache.set(authorization),
1245
- this.#handleAuthorizationResult(authorization),
1246
- ]);
1247
- return authorization;
1248
- });
1249
- }
1250
- catch (e) {
1251
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1252
- }
1253
- };
1254
- #handleAuthorizationResult = async (authorization) => {
1255
- const didPublicKeysChange =
1256
- // Case 1: We started from having no authorization.
1257
- this.#authorization == null ||
1258
- // Case 2: The number of authorized accounts changed.
1259
- this.#authorization?.accounts.length !== authorization.accounts.length ||
1260
- // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
1261
- this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
1262
- this.#authorization = authorization;
1263
- if (didPublicKeysChange) {
1264
- this.#emit('change', { accounts: this.accounts });
1265
- }
1266
- };
1267
- #handleWalletCapabilitiesResult = async (capabilities) => {
1268
- // TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
1269
- const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
1270
- const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions;
1271
- const didCapabilitiesChange = walletStandardFeatures.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
1272
- walletStandardFeatures.SolanaSignTransaction in this.features !== supportsSignTransaction;
1273
- this.#optionalFeatures = {
1274
- ...((supportsSignAndSendTransaction || (!supportsSignAndSendTransaction && !supportsSignTransaction)) && {
1275
- [walletStandardFeatures.SolanaSignAndSendTransaction]: {
1276
- version: '1.0.0',
1277
- supportedTransactionVersions: ['legacy', 0],
1278
- signAndSendTransaction: this.#signAndSendTransaction,
1279
- },
1280
- }),
1281
- ...(supportsSignTransaction && {
1282
- [walletStandardFeatures.SolanaSignTransaction]: {
1283
- version: '1.0.0',
1284
- supportedTransactionVersions: ['legacy', 0],
1285
- signTransaction: this.#signTransaction,
1286
- },
1287
- }),
1288
- };
1289
- if (didCapabilitiesChange) {
1290
- this.#emit('change', { features: this.features });
1291
- }
1292
- };
1293
- #performReauthorization = async (wallet, authToken, chain) => {
1294
- try {
1295
- const [capabilities, mwaAuthorizationResult] = await Promise.all([
1296
- this.#authorization?.capabilities ?? await wallet.getCapabilities(),
1297
- wallet.authorize({
1298
- auth_token: authToken,
1299
- identity: this.#appIdentity,
1300
- chain: chain
1301
- })
1302
- ]);
1303
- const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1304
- const authorization = { ...mwaAuthorizationResult,
1305
- accounts: accounts, chain: chain, capabilities: capabilities
1306
- };
1307
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1308
- Promise.all([
1309
- this.#authorizationCache.set(authorization),
1310
- this.#handleAuthorizationResult(authorization),
1311
- ]);
1312
- }
1313
- catch (e) {
1314
- this.#disconnect();
1315
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1316
- }
1317
- };
1318
- #disconnect = async () => {
1319
- this.#authorizationCache.clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1320
- this.#connecting = false;
1321
- this.#connectionGeneration++;
1322
- this.#authorization = undefined;
1323
- this.#emit('change', { accounts: this.accounts });
1324
- };
1325
- #transact = async (callback) => {
1326
- const walletUriBase = this.#authorization?.wallet_uri_base;
1327
- const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
1328
- const currentConnectionGeneration = this.#connectionGeneration;
1329
- const loadingSpinner = new EmbeddedLoadingSpinner();
1330
- try {
1331
- // check that we have permissions for local app connections, then run
1332
- // wallet association (transact). In case the user manually cancels
1333
- // the wallet association, cancel the connection after a timeout.
1334
- let associating = true;
1335
- let timeout = undefined;
1336
- const result = await Promise.race([
1337
- checkLocalNetworkAccessPermission()
1338
- .then(async () => {
1339
- // Begin local connection, show loading spinner while we connect
1340
- loadingSpinner.init();
1341
- const { wallet, close } = await mobileWalletAdapterProtocol.startScenario(config);
1342
- loadingSpinner.addEventListener('close', (event) => { if (event)
1343
- close(); });
1344
- loadingSpinner.open();
1345
- const result = await callback(await wallet);
1346
- loadingSpinner.close();
1347
- close();
1348
- return result;
1349
- }),
1350
- new Promise((_, reject) => {
1351
- timeout = setTimeout(() => {
1352
- if (associating) { // only timeout during association
1353
- reject(new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, 'Wallet connection timed out', { event: undefined }));
1354
- }
1355
- }, WALLET_ASSOCIATION_TIMEOUT);
1356
- })
1357
- ]);
1358
- clearTimeout(timeout);
1359
- return result;
1360
- }
1361
- catch (e) {
1362
- loadingSpinner.close();
1363
- if (this.#connectionGeneration !== currentConnectionGeneration) {
1364
- await new Promise(() => { }); // Never resolve.
1365
- }
1366
- if (e instanceof Error &&
1367
- e.name === 'SolanaMobileWalletAdapterError' &&
1368
- e.code === 'ERROR_WALLET_NOT_FOUND') {
1369
- await this.#onWalletNotFound(this);
1370
- }
1371
- throw e;
1372
- }
1373
- };
1374
- #assertIsAuthorized = () => {
1375
- if (!this.#authorization)
1376
- throw new Error('Wallet not connected');
1377
- return { authToken: this.#authorization.auth_token, chain: this.#authorization.chain };
1378
- };
1379
- #accountsToWalletStandardAccounts = (accounts) => {
1380
- return accounts.map((account) => {
1381
- const publicKey = toUint8Array(account.address);
1382
- return {
1383
- address: base58.encode(publicKey),
1384
- publicKey,
1385
- label: account.label,
1386
- icon: account.icon,
1387
- chains: account.chains ?? this.#chains,
1388
- // TODO: get supported features from getCapabilities API
1389
- features: account.features ?? DEFAULT_FEATURES
1390
- };
1391
- });
1392
- };
1393
- #performSignTransactions = async (transactions) => {
1394
- const { authToken, chain } = this.#assertIsAuthorized();
1395
- try {
1396
- const base64Transactions = transactions.map((tx) => { return fromUint8Array(tx); });
1397
- return await this.#transact(async (wallet) => {
1398
- await this.#performReauthorization(wallet, authToken, chain);
1399
- const signedTransactions = (await wallet.signTransactions({
1400
- payloads: base64Transactions,
1401
- })).signed_payloads.map(toUint8Array);
1402
- return signedTransactions;
1403
- });
1404
- }
1405
- catch (e) {
1406
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1407
- }
1408
- };
1409
- #performSignAndSendTransaction = async (transaction, options) => {
1410
- const { authToken, chain } = this.#assertIsAuthorized();
1411
- try {
1412
- return await this.#transact(async (wallet) => {
1413
- const [capabilities, _1] = await Promise.all([
1414
- wallet.getCapabilities(),
1415
- this.#performReauthorization(wallet, authToken, chain)
1416
- ]);
1417
- if (capabilities.supports_sign_and_send_transactions) {
1418
- const base64Transaction = fromUint8Array(transaction);
1419
- const signatures = (await wallet.signAndSendTransactions({
1420
- ...options,
1421
- payloads: [base64Transaction],
1422
- })).signatures.map(toUint8Array);
1423
- return signatures[0];
1424
- }
1425
- else {
1426
- throw new Error('connected wallet does not support signAndSendTransaction');
1427
- }
1428
- });
1429
- }
1430
- catch (e) {
1431
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1432
- }
1433
- };
1434
- #signAndSendTransaction = async (...inputs) => {
1435
- const outputs = [];
1436
- for (const input of inputs) {
1437
- const signature = await this.#performSignAndSendTransaction(input.transaction, input.options);
1438
- outputs.push({ signature });
1439
- }
1440
- return outputs;
1441
- };
1442
- #signTransaction = async (...inputs) => {
1443
- return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction)))
1444
- .map((signedTransaction) => {
1445
- return { signedTransaction };
1446
- });
1447
- };
1448
- #signMessage = async (...inputs) => {
1449
- const { authToken, chain } = this.#assertIsAuthorized();
1450
- const addresses = inputs.map(({ account }) => fromUint8Array(new Uint8Array(account.publicKey)));
1451
- const messages = inputs.map(({ message }) => fromUint8Array(message));
1452
- try {
1453
- return await this.#transact(async (wallet) => {
1454
- await this.#performReauthorization(wallet, authToken, chain);
1455
- const signedMessages = (await wallet.signMessages({
1456
- addresses: addresses,
1457
- payloads: messages,
1458
- })).signed_payloads.map(toUint8Array);
1459
- return signedMessages.map((signedMessage) => {
1460
- return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
1461
- });
1462
- });
1463
- }
1464
- catch (e) {
1465
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1466
- }
1467
- };
1468
- #signIn = async (...inputs) => {
1469
- const outputs = [];
1470
- if (inputs.length > 1) {
1471
- for (const input of inputs) {
1472
- outputs.push(await this.#performSignIn(input));
1473
- }
1474
- }
1475
- else {
1476
- return [await this.#performSignIn(inputs[0])];
1477
- }
1478
- return outputs;
1479
- };
1480
- #performSignIn = async (input) => {
1481
- this.#connecting = true;
1482
- try {
1483
- const authorizationResult = await this.#performAuthorization({
1484
- ...input,
1485
- domain: input?.domain ?? window.location.host
1486
- });
1487
- if (!authorizationResult.sign_in_result) {
1488
- throw new Error("Sign in failed, no sign in result returned by wallet");
1489
- }
1490
- const signedInAddress = authorizationResult.sign_in_result.address;
1491
- const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
1492
- return {
1493
- account: {
1494
- ...signedInAccount ?? {
1495
- address: base58.encode(toUint8Array(signedInAddress))
1496
- },
1497
- publicKey: toUint8Array(signedInAddress),
1498
- chains: signedInAccount?.chains ?? this.#chains,
1499
- features: signedInAccount?.features ?? authorizationResult.capabilities.features
1500
- },
1501
- signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
1502
- signature: toUint8Array(authorizationResult.sign_in_result.signature)
1503
- };
1504
- }
1505
- catch (e) {
1506
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1507
- }
1508
- finally {
1509
- this.#connecting = false;
1510
- }
1511
- };
1512
- }
1513
- class RemoteSolanaMobileWalletAdapterWallet {
1514
- #listeners = {};
1515
- #version = '1.0.0'; // wallet-standard version
1516
- #name = SolanaMobileWalletAdapterRemoteWalletName;
1517
- #url = 'https://solanamobile.com/wallets';
1518
- #icon = icon;
1519
- #appIdentity;
1520
- #authorization;
1521
- #authorizationCache;
1522
- #connecting = false;
1523
- /**
1524
- * Every time the connection is recycled in some way (eg. `disconnect()` is called)
1525
- * increment this and use it to make sure that `transact` calls from the previous
1526
- * 'generation' don't continue to do work and throw exceptions.
1527
- */
1528
- #connectionGeneration = 0;
1529
- #chains = [];
1530
- #chainSelector;
1531
- #optionalFeatures;
1532
- #onWalletNotFound;
1533
- #hostAuthority;
1534
- #session;
1535
- get version() {
1536
- return this.#version;
1537
- }
1538
- get name() {
1539
- return this.#name;
1540
- }
1541
- get url() {
1542
- return this.#url;
1543
- }
1544
- get icon() {
1545
- return this.#icon;
1546
- }
1547
- get chains() {
1548
- return this.#chains;
1549
- }
1550
- get features() {
1551
- return {
1552
- [features.StandardConnect]: {
1553
- version: '1.0.0',
1554
- connect: this.#connect,
1555
- },
1556
- [features.StandardDisconnect]: {
1557
- version: '1.0.0',
1558
- disconnect: this.#disconnect,
1559
- },
1560
- [features.StandardEvents]: {
1561
- version: '1.0.0',
1562
- on: this.#on,
1563
- },
1564
- [walletStandardFeatures.SolanaSignMessage]: {
1565
- version: '1.0.0',
1566
- signMessage: this.#signMessage,
1567
- },
1568
- [walletStandardFeatures.SolanaSignIn]: {
1569
- version: '1.0.0',
1570
- signIn: this.#signIn,
1571
- },
1572
- ...this.#optionalFeatures,
1573
- };
1574
- }
1575
- get accounts() {
1576
- return this.#authorization?.accounts ?? [];
1577
- }
1578
- constructor(config) {
1579
- this.#authorizationCache = config.authorizationCache;
1580
- this.#appIdentity = config.appIdentity;
1581
- this.#chains = config.chains;
1582
- this.#chainSelector = config.chainSelector;
1583
- this.#hostAuthority = config.remoteHostAuthority;
1584
- this.#onWalletNotFound = config.onWalletNotFound;
1585
- this.#optionalFeatures = {
1586
- // In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
1587
- // signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
1588
- // 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
1589
- // assume both are supported here. The features will be updated based on the actual connected
1590
- // wallets capabilities during connection regardless, so this is safe.
1591
- [walletStandardFeatures.SolanaSignAndSendTransaction]: {
1592
- version: '1.0.0',
1593
- supportedTransactionVersions: ['legacy', 0],
1594
- signAndSendTransaction: this.#signAndSendTransaction,
1595
- },
1596
- [walletStandardFeatures.SolanaSignTransaction]: {
1597
- version: '1.0.0',
1598
- supportedTransactionVersions: ['legacy', 0],
1599
- signTransaction: this.#signTransaction,
1600
- },
1601
- };
1602
- }
1603
- get connected() {
1604
- return !!this.#session && !!this.#authorization;
1605
- }
1606
- get isAuthorized() {
1607
- return !!this.#authorization;
1608
- }
1609
- get currentAuthorization() {
1610
- return this.#authorization;
1611
- }
1612
- get cachedAuthorizationResult() {
1613
- return this.#authorizationCache.get();
1614
- }
1615
- #on = (event, listener) => {
1616
- this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
1617
- return () => this.#off(event, listener);
1618
- };
1619
- #emit(event, ...args) {
1620
- // eslint-disable-next-line prefer-spread
1621
- this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
1622
- }
1623
- #off(event, listener) {
1624
- this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
1625
- }
1626
- #connect = async ({ silent } = {}) => {
1627
- if (this.#connecting || this.connected) {
1628
- return { accounts: this.accounts };
1629
- }
1630
- this.#connecting = true;
1631
- try {
1632
- await this.#performAuthorization();
1633
- }
1634
- catch (e) {
1635
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1636
- }
1637
- finally {
1638
- this.#connecting = false;
1639
- }
1640
- return { accounts: this.accounts };
1641
- };
1642
- #performAuthorization = async (signInPayload) => {
1643
- try {
1644
- const cachedAuthorizationResult = await this.#authorizationCache.get();
1645
- if (cachedAuthorizationResult) {
1646
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1647
- this.#handleAuthorizationResult(cachedAuthorizationResult);
1648
- return cachedAuthorizationResult;
1649
- }
1650
- if (this.#session)
1651
- this.#session = undefined;
1652
- const selectedChain = await this.#chainSelector.select(this.#chains);
1653
- return await this.#transact(async (wallet) => {
1654
- const [capabilities, mwaAuthorizationResult] = await Promise.all([
1655
- wallet.getCapabilities(),
1656
- wallet.authorize({
1657
- chain: selectedChain,
1658
- identity: this.#appIdentity,
1659
- sign_in_payload: signInPayload,
1660
- })
1661
- ]);
1662
- const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1663
- const authorizationResult = { ...mwaAuthorizationResult,
1664
- accounts, chain: selectedChain, capabilities: capabilities };
1665
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1666
- Promise.all([
1667
- this.#handleWalletCapabilitiesResult(capabilities),
1668
- this.#authorizationCache.set(authorizationResult),
1669
- this.#handleAuthorizationResult(authorizationResult),
1670
- ]);
1671
- return authorizationResult;
1672
- });
1673
- }
1674
- catch (e) {
1675
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1676
- }
1677
- };
1678
- #handleAuthorizationResult = async (authorization) => {
1679
- const didPublicKeysChange =
1680
- // Case 1: We started from having no authorization.
1681
- this.#authorization == null ||
1682
- // Case 2: The number of authorized accounts changed.
1683
- this.#authorization?.accounts.length !== authorization.accounts.length ||
1684
- // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
1685
- this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
1686
- this.#authorization = authorization;
1687
- if (didPublicKeysChange) {
1688
- this.#emit('change', { accounts: this.accounts });
1689
- }
1690
- };
1691
- #handleWalletCapabilitiesResult = async (capabilities) => {
1692
- // TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
1693
- const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
1694
- const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions ||
1695
- capabilities.features.includes('solana:signAndSendTransaction');
1696
- const didCapabilitiesChange = walletStandardFeatures.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
1697
- walletStandardFeatures.SolanaSignTransaction in this.features !== supportsSignTransaction;
1698
- this.#optionalFeatures = {
1699
- ...(supportsSignAndSendTransaction && {
1700
- [walletStandardFeatures.SolanaSignAndSendTransaction]: {
1701
- version: '1.0.0',
1702
- supportedTransactionVersions: capabilities.supported_transaction_versions,
1703
- signAndSendTransaction: this.#signAndSendTransaction,
1704
- },
1705
- }),
1706
- ...(supportsSignTransaction && {
1707
- [walletStandardFeatures.SolanaSignTransaction]: {
1708
- version: '1.0.0',
1709
- supportedTransactionVersions: capabilities.supported_transaction_versions,
1710
- signTransaction: this.#signTransaction,
1711
- },
1712
- }),
1713
- };
1714
- if (didCapabilitiesChange) {
1715
- this.#emit('change', { features: this.features });
1716
- }
1717
- };
1718
- #performReauthorization = async (wallet, authToken, chain) => {
1719
- try {
1720
- const [capabilities, mwaAuthorizationResult] = await Promise.all([
1721
- this.#authorization?.capabilities ?? await wallet.getCapabilities(),
1722
- wallet.authorize({
1723
- auth_token: authToken,
1724
- identity: this.#appIdentity,
1725
- chain: chain
1726
- })
1727
- ]);
1728
- const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1729
- const authorization = { ...mwaAuthorizationResult,
1730
- accounts: accounts, chain: chain, capabilities: capabilities };
1731
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1732
- Promise.all([
1733
- this.#authorizationCache.set(authorization),
1734
- this.#handleAuthorizationResult(authorization),
1735
- ]);
1736
- }
1737
- catch (e) {
1738
- this.#disconnect();
1739
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1740
- }
1741
- };
1742
- #disconnect = async () => {
1743
- this.#session?.close();
1744
- this.#authorizationCache.clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1745
- this.#connecting = false;
1746
- this.#connectionGeneration++;
1747
- this.#authorization = undefined;
1748
- this.#session = undefined;
1749
- this.#emit('change', { accounts: this.accounts });
1750
- };
1751
- #transact = async (callback) => {
1752
- const walletUriBase = this.#authorization?.wallet_uri_base;
1753
- const baseConfig = walletUriBase ? { baseUri: walletUriBase } : undefined;
1754
- const remoteConfig = { ...baseConfig, remoteHostAuthority: this.#hostAuthority };
1755
- const currentConnectionGeneration = this.#connectionGeneration;
1756
- const modal = new RemoteConnectionModal();
1757
- if (this.#session) {
1758
- return callback(this.#session.wallet);
1759
- }
1760
- try {
1761
- // Begin remote connection, show modal with loading anim while we connect
1762
- modal.init();
1763
- modal.open();
1764
- const { associationUrl, close, wallet } = await mobileWalletAdapterProtocol.startRemoteScenario(remoteConfig);
1765
- // Reflector is now connected, update the connection modal with qr code
1766
- const removeCloseListener = modal.addEventListener('close', (event) => {
1767
- if (event)
1768
- close();
1769
- });
1770
- modal.populateQRCode(associationUrl.toString());
1771
- // Wait for the wallet to be connected, then close the connection modal and proceed
1772
- this.#session = { close, wallet: await wallet };
1773
- removeCloseListener();
1774
- modal.close();
1775
- return await callback(this.#session.wallet);
1776
- }
1777
- catch (e) {
1778
- modal.close();
1779
- if (this.#connectionGeneration !== currentConnectionGeneration) {
1780
- await new Promise(() => { }); // Never resolve.
1781
- }
1782
- if (e instanceof Error &&
1783
- e.name === 'SolanaMobileWalletAdapterError' &&
1784
- e.code === 'ERROR_WALLET_NOT_FOUND') {
1785
- await this.#onWalletNotFound(this);
1786
- }
1787
- throw e;
1788
- }
1789
- };
1790
- #assertIsAuthorized = () => {
1791
- if (!this.#authorization)
1792
- throw new Error('Wallet not connected');
1793
- return { authToken: this.#authorization.auth_token, chain: this.#authorization.chain };
1794
- };
1795
- #accountsToWalletStandardAccounts = (accounts) => {
1796
- return accounts.map((account) => {
1797
- const publicKey = toUint8Array(account.address);
1798
- return {
1799
- address: base58.encode(publicKey),
1800
- publicKey,
1801
- label: account.label,
1802
- icon: account.icon,
1803
- chains: account.chains ?? this.#chains,
1804
- // TODO: get supported features from getCapabilities API
1805
- features: account.features ?? DEFAULT_FEATURES
1806
- };
1807
- });
1808
- };
1809
- #performSignTransactions = async (transactions) => {
1810
- const { authToken, chain } = this.#assertIsAuthorized();
1811
- try {
1812
- return await this.#transact(async (wallet) => {
1813
- await this.#performReauthorization(wallet, authToken, chain);
1814
- const signedTransactions = (await wallet.signTransactions({
1815
- payloads: transactions.map(fromUint8Array),
1816
- })).signed_payloads.map(toUint8Array);
1817
- return signedTransactions;
1818
- });
1819
- }
1820
- catch (e) {
1821
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1822
- }
1823
- };
1824
- #performSignAndSendTransaction = async (transaction, options) => {
1825
- const { authToken, chain } = this.#assertIsAuthorized();
1826
- try {
1827
- return await this.#transact(async (wallet) => {
1828
- const [capabilities, _1] = await Promise.all([
1829
- wallet.getCapabilities(),
1830
- this.#performReauthorization(wallet, authToken, chain)
1831
- ]);
1832
- if (capabilities.supports_sign_and_send_transactions) {
1833
- const signatures = (await wallet.signAndSendTransactions({
1834
- ...options,
1835
- payloads: [fromUint8Array(transaction)],
1836
- })).signatures.map(toUint8Array);
1837
- return signatures[0];
1838
- }
1839
- else {
1840
- throw new Error('connected wallet does not support signAndSendTransaction');
1841
- }
1842
- });
1843
- }
1844
- catch (e) {
1845
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1846
- }
1847
- };
1848
- #signAndSendTransaction = async (...inputs) => {
1849
- const outputs = [];
1850
- for (const input of inputs) {
1851
- const signature = (await this.#performSignAndSendTransaction(input.transaction, input.options));
1852
- outputs.push({ signature });
1853
- }
1854
- return outputs;
1855
- };
1856
- #signTransaction = async (...inputs) => {
1857
- return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction)))
1858
- .map((signedTransaction) => {
1859
- return { signedTransaction };
1860
- });
1861
- };
1862
- #signMessage = async (...inputs) => {
1863
- const { authToken, chain } = this.#assertIsAuthorized();
1864
- const addresses = inputs.map(({ account }) => fromUint8Array(new Uint8Array(account.publicKey)));
1865
- const messages = inputs.map(({ message }) => fromUint8Array(message));
1866
- try {
1867
- return await this.#transact(async (wallet) => {
1868
- await this.#performReauthorization(wallet, authToken, chain);
1869
- const signedMessages = (await wallet.signMessages({
1870
- addresses: addresses,
1871
- payloads: messages,
1872
- })).signed_payloads.map(toUint8Array);
1873
- return signedMessages.map((signedMessage) => {
1874
- return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
1875
- });
1876
- });
1877
- }
1878
- catch (e) {
1879
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1880
- }
1881
- };
1882
- #signIn = async (...inputs) => {
1883
- const outputs = [];
1884
- if (inputs.length > 1) {
1885
- for (const input of inputs) {
1886
- outputs.push(await this.#performSignIn(input));
1887
- }
1888
- }
1889
- else {
1890
- return [await this.#performSignIn(inputs[0])];
1891
- }
1892
- return outputs;
1893
- };
1894
- #performSignIn = async (input) => {
1895
- this.#connecting = true;
1896
- try {
1897
- const authorizationResult = await this.#performAuthorization({
1898
- ...input,
1899
- domain: input?.domain ?? window.location.host
1900
- });
1901
- if (!authorizationResult.sign_in_result) {
1902
- throw new Error("Sign in failed, no sign in result returned by wallet");
1903
- }
1904
- const signedInAddress = authorizationResult.sign_in_result.address;
1905
- const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
1906
- return {
1907
- account: {
1908
- ...signedInAccount ?? {
1909
- address: base58.encode(toUint8Array(signedInAddress))
1910
- },
1911
- publicKey: toUint8Array(signedInAddress),
1912
- chains: signedInAccount?.chains ?? this.#chains,
1913
- features: signedInAccount?.features ?? authorizationResult.capabilities.features
1914
- },
1915
- signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
1916
- signature: toUint8Array(authorizationResult.sign_in_result.signature)
1917
- };
1918
- }
1919
- catch (e) {
1920
- throw new Error((e instanceof Error && e.message) || 'Unknown error');
1921
- }
1922
- finally {
1923
- this.#connecting = false;
1924
- }
1925
- };
1926
- }
1927
-
1026
+ const DEFAULT_FEATURES = [
1027
+ _solana_wallet_standard_features.SolanaSignAndSendTransaction,
1028
+ _solana_wallet_standard_features.SolanaSignTransaction,
1029
+ _solana_wallet_standard_features.SolanaSignMessage,
1030
+ _solana_wallet_standard_features.SolanaSignIn
1031
+ ];
1032
+ const WALLET_ASSOCIATION_TIMEOUT = 3e4;
1033
+ var LocalSolanaMobileWalletAdapterWallet = class {
1034
+ #listeners = {};
1035
+ #version = "1.0.0";
1036
+ #name = SolanaMobileWalletAdapterWalletName;
1037
+ #url = "https://solanamobile.com/wallets";
1038
+ #icon = icon;
1039
+ #appIdentity;
1040
+ #authorization;
1041
+ #authorizationCache;
1042
+ #connecting = false;
1043
+ /**
1044
+ * Every time the connection is recycled in some way (eg. `disconnect()` is called)
1045
+ * increment this and use it to make sure that `transact` calls from the previous
1046
+ * 'generation' don't continue to do work and throw exceptions.
1047
+ */
1048
+ #connectionGeneration = 0;
1049
+ #chains = [];
1050
+ #chainSelector;
1051
+ #optionalFeatures;
1052
+ #onWalletNotFound;
1053
+ get version() {
1054
+ return this.#version;
1055
+ }
1056
+ get name() {
1057
+ return this.#name;
1058
+ }
1059
+ get url() {
1060
+ return this.#url;
1061
+ }
1062
+ get icon() {
1063
+ return this.#icon;
1064
+ }
1065
+ get chains() {
1066
+ return this.#chains;
1067
+ }
1068
+ get features() {
1069
+ return {
1070
+ [_wallet_standard_features.StandardConnect]: {
1071
+ version: "1.0.0",
1072
+ connect: this.#connect
1073
+ },
1074
+ [_wallet_standard_features.StandardDisconnect]: {
1075
+ version: "1.0.0",
1076
+ disconnect: this.#disconnect
1077
+ },
1078
+ [_wallet_standard_features.StandardEvents]: {
1079
+ version: "1.0.0",
1080
+ on: this.#on
1081
+ },
1082
+ [_solana_wallet_standard_features.SolanaSignMessage]: {
1083
+ version: "1.0.0",
1084
+ signMessage: this.#signMessage
1085
+ },
1086
+ [_solana_wallet_standard_features.SolanaSignIn]: {
1087
+ version: "1.0.0",
1088
+ signIn: this.#signIn
1089
+ },
1090
+ ...this.#optionalFeatures
1091
+ };
1092
+ }
1093
+ get accounts() {
1094
+ return this.#authorization?.accounts ?? [];
1095
+ }
1096
+ constructor(config) {
1097
+ this.#authorizationCache = config.authorizationCache;
1098
+ this.#appIdentity = config.appIdentity;
1099
+ this.#chains = config.chains;
1100
+ this.#chainSelector = config.chainSelector;
1101
+ this.#onWalletNotFound = config.onWalletNotFound;
1102
+ this.#optionalFeatures = {
1103
+ [_solana_wallet_standard_features.SolanaSignAndSendTransaction]: {
1104
+ version: "1.0.0",
1105
+ supportedTransactionVersions: ["legacy", 0],
1106
+ signAndSendTransaction: this.#signAndSendTransaction
1107
+ },
1108
+ [_solana_wallet_standard_features.SolanaSignTransaction]: {
1109
+ version: "1.0.0",
1110
+ supportedTransactionVersions: ["legacy", 0],
1111
+ signTransaction: this.#signTransaction
1112
+ }
1113
+ };
1114
+ }
1115
+ get connected() {
1116
+ return !!this.#authorization;
1117
+ }
1118
+ get isAuthorized() {
1119
+ return !!this.#authorization;
1120
+ }
1121
+ get currentAuthorization() {
1122
+ return this.#authorization;
1123
+ }
1124
+ get cachedAuthorizationResult() {
1125
+ return this.#authorizationCache.get();
1126
+ }
1127
+ #on = (event, listener) => {
1128
+ this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
1129
+ return () => this.#off(event, listener);
1130
+ };
1131
+ #emit(event, ...args) {
1132
+ this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
1133
+ }
1134
+ #off(event, listener) {
1135
+ this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
1136
+ }
1137
+ #connect = async ({ silent } = {}) => {
1138
+ if (this.#connecting || this.connected) return { accounts: this.accounts };
1139
+ this.#connecting = true;
1140
+ try {
1141
+ if (silent) {
1142
+ const cachedAuthorization = await this.#authorizationCache.get();
1143
+ if (cachedAuthorization) {
1144
+ await this.#handleWalletCapabilitiesResult(cachedAuthorization.capabilities);
1145
+ await this.#handleAuthorizationResult(cachedAuthorization);
1146
+ } else return { accounts: this.accounts };
1147
+ } else await this.#performAuthorization();
1148
+ } catch (e) {
1149
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1150
+ } finally {
1151
+ this.#connecting = false;
1152
+ }
1153
+ return { accounts: this.accounts };
1154
+ };
1155
+ #performAuthorization = async (signInPayload) => {
1156
+ try {
1157
+ const cachedAuthorizationResult = await this.#authorizationCache.get();
1158
+ if (cachedAuthorizationResult) {
1159
+ this.#handleAuthorizationResult(cachedAuthorizationResult);
1160
+ return cachedAuthorizationResult;
1161
+ }
1162
+ const selectedChain = await this.#chainSelector.select(this.#chains);
1163
+ return await this.#transact(async (wallet) => {
1164
+ const [capabilities, mwaAuthorizationResult] = await Promise.all([wallet.getCapabilities(), wallet.authorize({
1165
+ chain: selectedChain,
1166
+ identity: this.#appIdentity,
1167
+ sign_in_payload: signInPayload
1168
+ })]);
1169
+ const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1170
+ const authorization = {
1171
+ ...mwaAuthorizationResult,
1172
+ accounts,
1173
+ chain: selectedChain,
1174
+ capabilities
1175
+ };
1176
+ Promise.all([
1177
+ this.#handleWalletCapabilitiesResult(capabilities),
1178
+ this.#authorizationCache.set(authorization),
1179
+ this.#handleAuthorizationResult(authorization)
1180
+ ]);
1181
+ return authorization;
1182
+ });
1183
+ } catch (e) {
1184
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1185
+ }
1186
+ };
1187
+ #handleAuthorizationResult = async (authorization) => {
1188
+ const didPublicKeysChange = this.#authorization == null || this.#authorization?.accounts.length !== authorization.accounts.length || this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
1189
+ this.#authorization = authorization;
1190
+ if (didPublicKeysChange) this.#emit("change", { accounts: this.accounts });
1191
+ };
1192
+ #handleWalletCapabilitiesResult = async (capabilities) => {
1193
+ const supportsSignTransaction = capabilities.features.includes("solana:signTransactions");
1194
+ const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions;
1195
+ const didCapabilitiesChange = _solana_wallet_standard_features.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction || _solana_wallet_standard_features.SolanaSignTransaction in this.features !== supportsSignTransaction;
1196
+ this.#optionalFeatures = {
1197
+ ...(supportsSignAndSendTransaction || !supportsSignAndSendTransaction && !supportsSignTransaction) && { [_solana_wallet_standard_features.SolanaSignAndSendTransaction]: {
1198
+ version: "1.0.0",
1199
+ supportedTransactionVersions: ["legacy", 0],
1200
+ signAndSendTransaction: this.#signAndSendTransaction
1201
+ } },
1202
+ ...supportsSignTransaction && { [_solana_wallet_standard_features.SolanaSignTransaction]: {
1203
+ version: "1.0.0",
1204
+ supportedTransactionVersions: ["legacy", 0],
1205
+ signTransaction: this.#signTransaction
1206
+ } }
1207
+ };
1208
+ if (didCapabilitiesChange) this.#emit("change", { features: this.features });
1209
+ };
1210
+ #performReauthorization = async (wallet, authToken, chain) => {
1211
+ try {
1212
+ const [capabilities, mwaAuthorizationResult] = await Promise.all([this.#authorization?.capabilities ?? await wallet.getCapabilities(), wallet.authorize({
1213
+ auth_token: authToken,
1214
+ identity: this.#appIdentity,
1215
+ chain
1216
+ })]);
1217
+ const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1218
+ const authorization = {
1219
+ ...mwaAuthorizationResult,
1220
+ accounts,
1221
+ chain,
1222
+ capabilities
1223
+ };
1224
+ Promise.all([this.#authorizationCache.set(authorization), this.#handleAuthorizationResult(authorization)]);
1225
+ } catch (e) {
1226
+ this.#disconnect();
1227
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1228
+ }
1229
+ };
1230
+ #disconnect = async () => {
1231
+ this.#authorizationCache.clear();
1232
+ this.#connecting = false;
1233
+ this.#connectionGeneration++;
1234
+ this.#authorization = void 0;
1235
+ this.#emit("change", { accounts: this.accounts });
1236
+ };
1237
+ #transact = async (callback) => {
1238
+ const walletUriBase = this.#authorization?.wallet_uri_base;
1239
+ const config = walletUriBase ? { baseUri: walletUriBase } : void 0;
1240
+ const currentConnectionGeneration = this.#connectionGeneration;
1241
+ const loadingSpinner = new EmbeddedLoadingSpinner();
1242
+ try {
1243
+ let timeout = void 0;
1244
+ const result = await Promise.race([checkLocalNetworkAccessPermission().then(async () => {
1245
+ loadingSpinner.init();
1246
+ const { wallet, close } = await (0, _solana_mobile_mobile_wallet_adapter_protocol.startScenario)(config);
1247
+ loadingSpinner.addEventListener("close", (event) => {
1248
+ if (event) close();
1249
+ });
1250
+ loadingSpinner.open();
1251
+ const result = await callback(await wallet);
1252
+ loadingSpinner.close();
1253
+ close();
1254
+ return result;
1255
+ }), new Promise((_, reject) => {
1256
+ timeout = setTimeout(() => {
1257
+ reject(new _solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterError(_solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, "Wallet connection timed out", { event: void 0 }));
1258
+ }, WALLET_ASSOCIATION_TIMEOUT);
1259
+ })]);
1260
+ clearTimeout(timeout);
1261
+ return result;
1262
+ } catch (e) {
1263
+ loadingSpinner.close();
1264
+ if (this.#connectionGeneration !== currentConnectionGeneration) await new Promise(() => {});
1265
+ if (e instanceof Error && e.name === "SolanaMobileWalletAdapterError" && e.code === "ERROR_WALLET_NOT_FOUND") await this.#onWalletNotFound(this);
1266
+ throw e;
1267
+ }
1268
+ };
1269
+ #assertIsAuthorized = () => {
1270
+ if (!this.#authorization) throw new Error("Wallet not connected");
1271
+ return {
1272
+ authToken: this.#authorization.auth_token,
1273
+ chain: this.#authorization.chain
1274
+ };
1275
+ };
1276
+ #accountsToWalletStandardAccounts = (accounts) => {
1277
+ return accounts.map((account) => {
1278
+ const publicKey = toUint8Array(account.address);
1279
+ return {
1280
+ address: bs58.default.encode(publicKey),
1281
+ publicKey,
1282
+ label: account.label,
1283
+ icon: account.icon,
1284
+ chains: account.chains ?? this.#chains,
1285
+ features: account.features ?? DEFAULT_FEATURES
1286
+ };
1287
+ });
1288
+ };
1289
+ #performSignTransactions = async (transactions) => {
1290
+ const { authToken, chain } = this.#assertIsAuthorized();
1291
+ try {
1292
+ const base64Transactions = transactions.map((tx) => {
1293
+ return fromUint8Array(tx);
1294
+ });
1295
+ return await this.#transact(async (wallet) => {
1296
+ await this.#performReauthorization(wallet, authToken, chain);
1297
+ return (await wallet.signTransactions({ payloads: base64Transactions })).signed_payloads.map(toUint8Array);
1298
+ });
1299
+ } catch (e) {
1300
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1301
+ }
1302
+ };
1303
+ #performSignAndSendTransaction = async (transaction, options) => {
1304
+ const { authToken, chain } = this.#assertIsAuthorized();
1305
+ try {
1306
+ return await this.#transact(async (wallet) => {
1307
+ const [capabilities, _1] = await Promise.all([wallet.getCapabilities(), this.#performReauthorization(wallet, authToken, chain)]);
1308
+ if (capabilities.supports_sign_and_send_transactions) {
1309
+ const base64Transaction = fromUint8Array(transaction);
1310
+ return (await wallet.signAndSendTransactions({
1311
+ ...options,
1312
+ payloads: [base64Transaction]
1313
+ })).signatures.map(toUint8Array)[0];
1314
+ } else throw new Error("connected wallet does not support signAndSendTransaction");
1315
+ });
1316
+ } catch (e) {
1317
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1318
+ }
1319
+ };
1320
+ #signAndSendTransaction = async (...inputs) => {
1321
+ const outputs = [];
1322
+ for (const input of inputs) {
1323
+ const signature = await this.#performSignAndSendTransaction(input.transaction, input.options);
1324
+ outputs.push({ signature });
1325
+ }
1326
+ return outputs;
1327
+ };
1328
+ #signTransaction = async (...inputs) => {
1329
+ return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction))).map((signedTransaction) => {
1330
+ return { signedTransaction };
1331
+ });
1332
+ };
1333
+ #signMessage = async (...inputs) => {
1334
+ const { authToken, chain } = this.#assertIsAuthorized();
1335
+ const addresses = inputs.map(({ account }) => fromUint8Array(new Uint8Array(account.publicKey)));
1336
+ const messages = inputs.map(({ message }) => fromUint8Array(message));
1337
+ try {
1338
+ return await this.#transact(async (wallet) => {
1339
+ await this.#performReauthorization(wallet, authToken, chain);
1340
+ return (await wallet.signMessages({
1341
+ addresses,
1342
+ payloads: messages
1343
+ })).signed_payloads.map(toUint8Array).map((signedMessage) => {
1344
+ return {
1345
+ signedMessage,
1346
+ signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES)
1347
+ };
1348
+ });
1349
+ });
1350
+ } catch (e) {
1351
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1352
+ }
1353
+ };
1354
+ #signIn = async (...inputs) => {
1355
+ const outputs = [];
1356
+ if (inputs.length > 1) for (const input of inputs) outputs.push(await this.#performSignIn(input));
1357
+ else return [await this.#performSignIn(inputs[0])];
1358
+ return outputs;
1359
+ };
1360
+ #performSignIn = async (input) => {
1361
+ this.#connecting = true;
1362
+ try {
1363
+ const authorizationResult = await this.#performAuthorization({
1364
+ ...input,
1365
+ domain: input?.domain ?? window.location.host
1366
+ });
1367
+ if (!authorizationResult.sign_in_result) throw new Error("Sign in failed, no sign in result returned by wallet");
1368
+ const signedInAddress = authorizationResult.sign_in_result.address;
1369
+ const signedInAccount = authorizationResult.accounts.find((acc) => acc.address == signedInAddress);
1370
+ return {
1371
+ account: {
1372
+ ...signedInAccount ?? { address: bs58.default.encode(toUint8Array(signedInAddress)) },
1373
+ publicKey: toUint8Array(signedInAddress),
1374
+ chains: signedInAccount?.chains ?? this.#chains,
1375
+ features: signedInAccount?.features ?? authorizationResult.capabilities.features
1376
+ },
1377
+ signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
1378
+ signature: toUint8Array(authorizationResult.sign_in_result.signature)
1379
+ };
1380
+ } catch (e) {
1381
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1382
+ } finally {
1383
+ this.#connecting = false;
1384
+ }
1385
+ };
1386
+ };
1387
+ var RemoteSolanaMobileWalletAdapterWallet = class {
1388
+ #listeners = {};
1389
+ #version = "1.0.0";
1390
+ #name = SolanaMobileWalletAdapterRemoteWalletName;
1391
+ #url = "https://solanamobile.com/wallets";
1392
+ #icon = icon;
1393
+ #appIdentity;
1394
+ #authorization;
1395
+ #authorizationCache;
1396
+ #connecting = false;
1397
+ /**
1398
+ * Every time the connection is recycled in some way (eg. `disconnect()` is called)
1399
+ * increment this and use it to make sure that `transact` calls from the previous
1400
+ * 'generation' don't continue to do work and throw exceptions.
1401
+ */
1402
+ #connectionGeneration = 0;
1403
+ #chains = [];
1404
+ #chainSelector;
1405
+ #optionalFeatures;
1406
+ #onWalletNotFound;
1407
+ #hostAuthority;
1408
+ #session;
1409
+ get version() {
1410
+ return this.#version;
1411
+ }
1412
+ get name() {
1413
+ return this.#name;
1414
+ }
1415
+ get url() {
1416
+ return this.#url;
1417
+ }
1418
+ get icon() {
1419
+ return this.#icon;
1420
+ }
1421
+ get chains() {
1422
+ return this.#chains;
1423
+ }
1424
+ get features() {
1425
+ return {
1426
+ [_wallet_standard_features.StandardConnect]: {
1427
+ version: "1.0.0",
1428
+ connect: this.#connect
1429
+ },
1430
+ [_wallet_standard_features.StandardDisconnect]: {
1431
+ version: "1.0.0",
1432
+ disconnect: this.#disconnect
1433
+ },
1434
+ [_wallet_standard_features.StandardEvents]: {
1435
+ version: "1.0.0",
1436
+ on: this.#on
1437
+ },
1438
+ [_solana_wallet_standard_features.SolanaSignMessage]: {
1439
+ version: "1.0.0",
1440
+ signMessage: this.#signMessage
1441
+ },
1442
+ [_solana_wallet_standard_features.SolanaSignIn]: {
1443
+ version: "1.0.0",
1444
+ signIn: this.#signIn
1445
+ },
1446
+ ...this.#optionalFeatures
1447
+ };
1448
+ }
1449
+ get accounts() {
1450
+ return this.#authorization?.accounts ?? [];
1451
+ }
1452
+ constructor(config) {
1453
+ this.#authorizationCache = config.authorizationCache;
1454
+ this.#appIdentity = config.appIdentity;
1455
+ this.#chains = config.chains;
1456
+ this.#chainSelector = config.chainSelector;
1457
+ this.#hostAuthority = config.remoteHostAuthority;
1458
+ this.#onWalletNotFound = config.onWalletNotFound;
1459
+ this.#optionalFeatures = {
1460
+ [_solana_wallet_standard_features.SolanaSignAndSendTransaction]: {
1461
+ version: "1.0.0",
1462
+ supportedTransactionVersions: ["legacy", 0],
1463
+ signAndSendTransaction: this.#signAndSendTransaction
1464
+ },
1465
+ [_solana_wallet_standard_features.SolanaSignTransaction]: {
1466
+ version: "1.0.0",
1467
+ supportedTransactionVersions: ["legacy", 0],
1468
+ signTransaction: this.#signTransaction
1469
+ }
1470
+ };
1471
+ }
1472
+ get connected() {
1473
+ return !!this.#session && !!this.#authorization;
1474
+ }
1475
+ get isAuthorized() {
1476
+ return !!this.#authorization;
1477
+ }
1478
+ get currentAuthorization() {
1479
+ return this.#authorization;
1480
+ }
1481
+ get cachedAuthorizationResult() {
1482
+ return this.#authorizationCache.get();
1483
+ }
1484
+ #on = (event, listener) => {
1485
+ this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
1486
+ return () => this.#off(event, listener);
1487
+ };
1488
+ #emit(event, ...args) {
1489
+ this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
1490
+ }
1491
+ #off(event, listener) {
1492
+ this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
1493
+ }
1494
+ #connect = async ({ silent } = {}) => {
1495
+ if (this.#connecting || this.connected) return { accounts: this.accounts };
1496
+ this.#connecting = true;
1497
+ try {
1498
+ await this.#performAuthorization();
1499
+ } catch (e) {
1500
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1501
+ } finally {
1502
+ this.#connecting = false;
1503
+ }
1504
+ return { accounts: this.accounts };
1505
+ };
1506
+ #performAuthorization = async (signInPayload) => {
1507
+ try {
1508
+ const cachedAuthorizationResult = await this.#authorizationCache.get();
1509
+ if (cachedAuthorizationResult) {
1510
+ this.#handleAuthorizationResult(cachedAuthorizationResult);
1511
+ return cachedAuthorizationResult;
1512
+ }
1513
+ if (this.#session) this.#session = void 0;
1514
+ const selectedChain = await this.#chainSelector.select(this.#chains);
1515
+ return await this.#transact(async (wallet) => {
1516
+ const [capabilities, mwaAuthorizationResult] = await Promise.all([wallet.getCapabilities(), wallet.authorize({
1517
+ chain: selectedChain,
1518
+ identity: this.#appIdentity,
1519
+ sign_in_payload: signInPayload
1520
+ })]);
1521
+ const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1522
+ const authorizationResult = {
1523
+ ...mwaAuthorizationResult,
1524
+ accounts,
1525
+ chain: selectedChain,
1526
+ capabilities
1527
+ };
1528
+ Promise.all([
1529
+ this.#handleWalletCapabilitiesResult(capabilities),
1530
+ this.#authorizationCache.set(authorizationResult),
1531
+ this.#handleAuthorizationResult(authorizationResult)
1532
+ ]);
1533
+ return authorizationResult;
1534
+ });
1535
+ } catch (e) {
1536
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1537
+ }
1538
+ };
1539
+ #handleAuthorizationResult = async (authorization) => {
1540
+ const didPublicKeysChange = this.#authorization == null || this.#authorization?.accounts.length !== authorization.accounts.length || this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
1541
+ this.#authorization = authorization;
1542
+ if (didPublicKeysChange) this.#emit("change", { accounts: this.accounts });
1543
+ };
1544
+ #handleWalletCapabilitiesResult = async (capabilities) => {
1545
+ const supportsSignTransaction = capabilities.features.includes("solana:signTransactions");
1546
+ const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions || capabilities.features.includes("solana:signAndSendTransaction");
1547
+ const didCapabilitiesChange = _solana_wallet_standard_features.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction || _solana_wallet_standard_features.SolanaSignTransaction in this.features !== supportsSignTransaction;
1548
+ this.#optionalFeatures = {
1549
+ ...supportsSignAndSendTransaction && { [_solana_wallet_standard_features.SolanaSignAndSendTransaction]: {
1550
+ version: "1.0.0",
1551
+ supportedTransactionVersions: capabilities.supported_transaction_versions,
1552
+ signAndSendTransaction: this.#signAndSendTransaction
1553
+ } },
1554
+ ...supportsSignTransaction && { [_solana_wallet_standard_features.SolanaSignTransaction]: {
1555
+ version: "1.0.0",
1556
+ supportedTransactionVersions: capabilities.supported_transaction_versions,
1557
+ signTransaction: this.#signTransaction
1558
+ } }
1559
+ };
1560
+ if (didCapabilitiesChange) this.#emit("change", { features: this.features });
1561
+ };
1562
+ #performReauthorization = async (wallet, authToken, chain) => {
1563
+ try {
1564
+ const [capabilities, mwaAuthorizationResult] = await Promise.all([this.#authorization?.capabilities ?? await wallet.getCapabilities(), wallet.authorize({
1565
+ auth_token: authToken,
1566
+ identity: this.#appIdentity,
1567
+ chain
1568
+ })]);
1569
+ const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
1570
+ const authorization = {
1571
+ ...mwaAuthorizationResult,
1572
+ accounts,
1573
+ chain,
1574
+ capabilities
1575
+ };
1576
+ Promise.all([this.#authorizationCache.set(authorization), this.#handleAuthorizationResult(authorization)]);
1577
+ } catch (e) {
1578
+ this.#disconnect();
1579
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1580
+ }
1581
+ };
1582
+ #disconnect = async () => {
1583
+ this.#session?.close();
1584
+ this.#authorizationCache.clear();
1585
+ this.#connecting = false;
1586
+ this.#connectionGeneration++;
1587
+ this.#authorization = void 0;
1588
+ this.#session = void 0;
1589
+ this.#emit("change", { accounts: this.accounts });
1590
+ };
1591
+ #transact = async (callback) => {
1592
+ const walletUriBase = this.#authorization?.wallet_uri_base;
1593
+ const remoteConfig = {
1594
+ ...walletUriBase ? { baseUri: walletUriBase } : void 0,
1595
+ remoteHostAuthority: this.#hostAuthority
1596
+ };
1597
+ const currentConnectionGeneration = this.#connectionGeneration;
1598
+ const modal = new RemoteConnectionModal();
1599
+ if (this.#session) return callback(this.#session.wallet);
1600
+ try {
1601
+ modal.init();
1602
+ modal.open();
1603
+ const { associationUrl, close, wallet } = await (0, _solana_mobile_mobile_wallet_adapter_protocol.startRemoteScenario)(remoteConfig);
1604
+ const removeCloseListener = modal.addEventListener("close", (event) => {
1605
+ if (event) close();
1606
+ });
1607
+ modal.populateQRCode(associationUrl.toString());
1608
+ this.#session = {
1609
+ close,
1610
+ wallet: await wallet
1611
+ };
1612
+ removeCloseListener();
1613
+ modal.close();
1614
+ return await callback(this.#session.wallet);
1615
+ } catch (e) {
1616
+ modal.close();
1617
+ if (this.#connectionGeneration !== currentConnectionGeneration) await new Promise(() => {});
1618
+ if (e instanceof Error && e.name === "SolanaMobileWalletAdapterError" && e.code === "ERROR_WALLET_NOT_FOUND") await this.#onWalletNotFound(this);
1619
+ throw e;
1620
+ }
1621
+ };
1622
+ #assertIsAuthorized = () => {
1623
+ if (!this.#authorization) throw new Error("Wallet not connected");
1624
+ return {
1625
+ authToken: this.#authorization.auth_token,
1626
+ chain: this.#authorization.chain
1627
+ };
1628
+ };
1629
+ #accountsToWalletStandardAccounts = (accounts) => {
1630
+ return accounts.map((account) => {
1631
+ const publicKey = toUint8Array(account.address);
1632
+ return {
1633
+ address: bs58.default.encode(publicKey),
1634
+ publicKey,
1635
+ label: account.label,
1636
+ icon: account.icon,
1637
+ chains: account.chains ?? this.#chains,
1638
+ features: account.features ?? DEFAULT_FEATURES
1639
+ };
1640
+ });
1641
+ };
1642
+ #performSignTransactions = async (transactions) => {
1643
+ const { authToken, chain } = this.#assertIsAuthorized();
1644
+ try {
1645
+ return await this.#transact(async (wallet) => {
1646
+ await this.#performReauthorization(wallet, authToken, chain);
1647
+ return (await wallet.signTransactions({ payloads: transactions.map(fromUint8Array) })).signed_payloads.map(toUint8Array);
1648
+ });
1649
+ } catch (e) {
1650
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1651
+ }
1652
+ };
1653
+ #performSignAndSendTransaction = async (transaction, options) => {
1654
+ const { authToken, chain } = this.#assertIsAuthorized();
1655
+ try {
1656
+ return await this.#transact(async (wallet) => {
1657
+ const [capabilities, _1] = await Promise.all([wallet.getCapabilities(), this.#performReauthorization(wallet, authToken, chain)]);
1658
+ if (capabilities.supports_sign_and_send_transactions) return (await wallet.signAndSendTransactions({
1659
+ ...options,
1660
+ payloads: [fromUint8Array(transaction)]
1661
+ })).signatures.map(toUint8Array)[0];
1662
+ else throw new Error("connected wallet does not support signAndSendTransaction");
1663
+ });
1664
+ } catch (e) {
1665
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1666
+ }
1667
+ };
1668
+ #signAndSendTransaction = async (...inputs) => {
1669
+ const outputs = [];
1670
+ for (const input of inputs) {
1671
+ const signature = await this.#performSignAndSendTransaction(input.transaction, input.options);
1672
+ outputs.push({ signature });
1673
+ }
1674
+ return outputs;
1675
+ };
1676
+ #signTransaction = async (...inputs) => {
1677
+ return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction))).map((signedTransaction) => {
1678
+ return { signedTransaction };
1679
+ });
1680
+ };
1681
+ #signMessage = async (...inputs) => {
1682
+ const { authToken, chain } = this.#assertIsAuthorized();
1683
+ const addresses = inputs.map(({ account }) => fromUint8Array(new Uint8Array(account.publicKey)));
1684
+ const messages = inputs.map(({ message }) => fromUint8Array(message));
1685
+ try {
1686
+ return await this.#transact(async (wallet) => {
1687
+ await this.#performReauthorization(wallet, authToken, chain);
1688
+ return (await wallet.signMessages({
1689
+ addresses,
1690
+ payloads: messages
1691
+ })).signed_payloads.map(toUint8Array).map((signedMessage) => {
1692
+ return {
1693
+ signedMessage,
1694
+ signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES)
1695
+ };
1696
+ });
1697
+ });
1698
+ } catch (e) {
1699
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1700
+ }
1701
+ };
1702
+ #signIn = async (...inputs) => {
1703
+ const outputs = [];
1704
+ if (inputs.length > 1) for (const input of inputs) outputs.push(await this.#performSignIn(input));
1705
+ else return [await this.#performSignIn(inputs[0])];
1706
+ return outputs;
1707
+ };
1708
+ #performSignIn = async (input) => {
1709
+ this.#connecting = true;
1710
+ try {
1711
+ const authorizationResult = await this.#performAuthorization({
1712
+ ...input,
1713
+ domain: input?.domain ?? window.location.host
1714
+ });
1715
+ if (!authorizationResult.sign_in_result) throw new Error("Sign in failed, no sign in result returned by wallet");
1716
+ const signedInAddress = authorizationResult.sign_in_result.address;
1717
+ const signedInAccount = authorizationResult.accounts.find((acc) => acc.address == signedInAddress);
1718
+ return {
1719
+ account: {
1720
+ ...signedInAccount ?? { address: bs58.default.encode(toUint8Array(signedInAddress)) },
1721
+ publicKey: toUint8Array(signedInAddress),
1722
+ chains: signedInAccount?.chains ?? this.#chains,
1723
+ features: signedInAccount?.features ?? authorizationResult.capabilities.features
1724
+ },
1725
+ signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
1726
+ signature: toUint8Array(authorizationResult.sign_in_result.signature)
1727
+ };
1728
+ } catch (e) {
1729
+ throw new Error(e instanceof Error && e.message || "Unknown error");
1730
+ } finally {
1731
+ this.#connecting = false;
1732
+ }
1733
+ };
1734
+ };
1735
+ //#endregion
1736
+ //#region src/initialize.ts
1928
1737
  function registerMwa(config) {
1929
- if (typeof window === 'undefined') {
1930
- console.warn(`MWA not registered: no window object`);
1931
- return;
1932
- }
1933
- if (!window.isSecureContext) {
1934
- console.warn(`MWA not registered: secure context required (https)`);
1935
- return;
1936
- }
1937
- // Local association technically is possible in a webview, but we prevent registration
1938
- // by default because it usually fails in the most common cases (e.g wallet browsers).
1939
- if (getIsLocalAssociationSupported() && !isWebView(navigator.userAgent)) {
1940
- wallet.registerWallet(new LocalSolanaMobileWalletAdapterWallet(config));
1941
- }
1942
- else if (getIsRemoteAssociationSupported() && config.remoteHostAuthority !== undefined) {
1943
- wallet.registerWallet(new RemoteSolanaMobileWalletAdapterWallet({ ...config, remoteHostAuthority: config.remoteHostAuthority }));
1944
- }
1945
- else ;
1946
- }
1947
-
1948
- const WALLET_NOT_FOUND_ERROR_MESSAGE = 'To use mobile wallet adapter, you must have a compatible mobile wallet application installed on your device.';
1949
- 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.';
1950
- class ErrorModal extends EmbeddedModal {
1951
- contentStyles = css;
1952
- contentHtml = ErrorDialogHtml;
1953
- initWithError(error) {
1954
- super.init();
1955
- this.populateError(error);
1956
- }
1957
- populateError(error) {
1958
- const errorMessageElement = this.dom?.getElementById('mobile-wallet-adapter-error-message');
1959
- const actionBtn = this.dom?.getElementById('mobile-wallet-adapter-error-action');
1960
- if (errorMessageElement) {
1961
- if (error.name === 'SolanaMobileWalletAdapterError') {
1962
- switch (error.code) {
1963
- case 'ERROR_WALLET_NOT_FOUND':
1964
- errorMessageElement.innerHTML = WALLET_NOT_FOUND_ERROR_MESSAGE;
1965
- if (actionBtn)
1966
- actionBtn.addEventListener('click', () => {
1967
- window.location.href = 'https://solanamobile.com/wallets';
1968
- });
1969
- return;
1970
- case 'ERROR_BROWSER_NOT_SUPPORTED':
1971
- errorMessageElement.innerHTML = BROWSER_NOT_SUPPORTED_ERROR_MESSAGE;
1972
- if (actionBtn)
1973
- actionBtn.style.display = 'none';
1974
- return;
1975
- }
1976
- }
1977
- errorMessageElement.innerHTML = `An unexpected error occurred: ${error.message}`;
1978
- }
1979
- else {
1980
- console.log('Failed to locate error dialog element');
1981
- }
1982
- }
1983
- }
1738
+ if (typeof window === "undefined") {
1739
+ console.warn(`MWA not registered: no window object`);
1740
+ return;
1741
+ }
1742
+ if (!window.isSecureContext) {
1743
+ console.warn(`MWA not registered: secure context required (https)`);
1744
+ return;
1745
+ }
1746
+ const userAgent = navigator.userAgent;
1747
+ if (getIsLocalAssociationSupported() && (!isWebView(userAgent) || isSolanaMobileWebShell(userAgent))) (0, _wallet_standard_wallet.registerWallet)(new LocalSolanaMobileWalletAdapterWallet(config));
1748
+ else if (getIsRemoteAssociationSupported() && config.remoteHostAuthority !== void 0) (0, _wallet_standard_wallet.registerWallet)(new RemoteSolanaMobileWalletAdapterWallet({
1749
+ ...config,
1750
+ remoteHostAuthority: config.remoteHostAuthority
1751
+ }));
1752
+ }
1753
+ //#endregion
1754
+ //#region src/embedded-modal/errorModal.ts
1755
+ const WALLET_NOT_FOUND_ERROR_MESSAGE = "To use mobile wallet adapter, you must have a compatible mobile wallet application installed on your device.";
1756
+ 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.";
1757
+ var ErrorModal = class extends EmbeddedModal {
1758
+ contentStyles = css;
1759
+ contentHtml = ErrorDialogHtml;
1760
+ initWithError(error) {
1761
+ super.init();
1762
+ this.populateError(error);
1763
+ }
1764
+ populateError(error) {
1765
+ const errorMessageElement = this.dom?.getElementById("mobile-wallet-adapter-error-message");
1766
+ const actionBtn = this.dom?.getElementById("mobile-wallet-adapter-error-action");
1767
+ if (errorMessageElement) {
1768
+ if (error.name === "SolanaMobileWalletAdapterError") switch (error.code) {
1769
+ case "ERROR_WALLET_NOT_FOUND":
1770
+ errorMessageElement.innerHTML = WALLET_NOT_FOUND_ERROR_MESSAGE;
1771
+ if (actionBtn) actionBtn.addEventListener("click", () => {
1772
+ window.location.href = "https://solanamobile.com/wallets";
1773
+ });
1774
+ return;
1775
+ case "ERROR_BROWSER_NOT_SUPPORTED":
1776
+ errorMessageElement.innerHTML = BROWSER_NOT_SUPPORTED_ERROR_MESSAGE;
1777
+ if (actionBtn) actionBtn.style.display = "none";
1778
+ return;
1779
+ }
1780
+ errorMessageElement.innerHTML = `An unexpected error occurred: ${error.message}`;
1781
+ } else console.log("Failed to locate error dialog element");
1782
+ }
1783
+ };
1984
1784
  const ErrorDialogHtml = `
1985
1785
  <svg class="mobile-wallet-adapter-embedded-modal-error-icon" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#000000"><path d="M 280,-80 Q 197,-80 138.5,-138.5 80,-197 80,-280 80,-363 138.5,-421.5 197,-480 280,-480 q 83,0 141.5,58.5 58.5,58.5 58.5,141.5 0,83 -58.5,141.5 Q 363,-80 280,-80 Z M 824,-120 568,-376 Q 556,-389 542.5,-402.5 529,-416 516,-428 q 38,-24 61,-64 23,-40 23,-88 0,-75 -52.5,-127.5 Q 495,-760 420,-760 345,-760 292.5,-707.5 240,-655 240,-580 q 0,6 0.5,11.5 0.5,5.5 1.5,11.5 -18,2 -39.5,8 -21.5,6 -38.5,14 -2,-11 -3,-22 -1,-11 -1,-23 0,-109 75.5,-184.5 Q 311,-840 420,-840 q 109,0 184.5,75.5 75.5,75.5 75.5,184.5 0,43 -13.5,81.5 Q 653,-460 629,-428 l 251,252 z m -615,-61 71,-71 70,71 29,-28 -71,-71 71,-71 -28,-28 -71,71 -71,-71 -28,28 71,71 -71,71 z"/></svg>
1986
1786
  <div class="mobile-wallet-adapter-embedded-modal-title">We can't find a wallet.</div>
@@ -2040,117 +1840,81 @@ const css = `
2040
1840
  }
2041
1841
  }
2042
1842
  `;
2043
-
1843
+ //#endregion
1844
+ //#region src/createDefaultWalletNotFoundHandler.ts
2044
1845
  async function defaultErrorModalWalletNotFoundHandler() {
2045
- if (typeof window !== 'undefined') {
2046
- const userAgent = window.navigator.userAgent.toLowerCase();
2047
- const errorDialog = new ErrorModal();
2048
- if (userAgent.includes('wv')) { // Android WebView
2049
- // MWA is not supported in this browser so we inform the user
2050
- // errorDialog.initWithError(
2051
- // new SolanaMobileWalletAdapterError(
2052
- // SolanaMobileWalletAdapterErrorCode.ERROR_BROWSER_NOT_SUPPORTED,
2053
- // ''
2054
- // )
2055
- // );
2056
- // TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
2057
- errorDialog.initWithError({
2058
- name: 'SolanaMobileWalletAdapterError',
2059
- code: 'ERROR_BROWSER_NOT_SUPPORTED',
2060
- message: ''
2061
- });
2062
- }
2063
- else { // Browser, user does not have a wallet installed.
2064
- // errorDialog.initWithError(
2065
- // new SolanaMobileWalletAdapterError(
2066
- // SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND,
2067
- // ''
2068
- // )
2069
- // );
2070
- // TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
2071
- errorDialog.initWithError({
2072
- name: 'SolanaMobileWalletAdapterError',
2073
- code: 'ERROR_WALLET_NOT_FOUND',
2074
- message: ''
2075
- });
2076
- }
2077
- errorDialog.open();
2078
- }
1846
+ if (typeof window !== "undefined") {
1847
+ const userAgent = window.navigator.userAgent.toLowerCase();
1848
+ const errorDialog = new ErrorModal();
1849
+ if (userAgent.includes("wv")) errorDialog.initWithError({
1850
+ name: "SolanaMobileWalletAdapterError",
1851
+ code: "ERROR_BROWSER_NOT_SUPPORTED",
1852
+ message: ""
1853
+ });
1854
+ else errorDialog.initWithError({
1855
+ name: "SolanaMobileWalletAdapterError",
1856
+ code: "ERROR_WALLET_NOT_FOUND",
1857
+ message: ""
1858
+ });
1859
+ errorDialog.open();
1860
+ }
2079
1861
  }
2080
1862
  function createDefaultWalletNotFoundHandler() {
2081
- return async () => { defaultErrorModalWalletNotFoundHandler(); };
1863
+ return async () => {
1864
+ defaultErrorModalWalletNotFoundHandler();
1865
+ };
2082
1866
  }
2083
-
2084
- const CACHE_KEY = 'SolanaMobileWalletAdapterDefaultAuthorizationCache';
1867
+ //#endregion
1868
+ //#region src/createDefaultAuthorizationCache.ts
1869
+ const CACHE_KEY = "SolanaMobileWalletAdapterDefaultAuthorizationCache";
2085
1870
  function createDefaultAuthorizationCache() {
2086
- let storage;
2087
- try {
2088
- storage = window.localStorage;
2089
- // eslint-disable-next-line no-empty
2090
- }
2091
- catch { }
2092
- return {
2093
- async clear() {
2094
- if (!storage) {
2095
- return;
2096
- }
2097
- try {
2098
- storage.removeItem(CACHE_KEY);
2099
- // eslint-disable-next-line no-empty
2100
- }
2101
- catch { }
2102
- },
2103
- async get() {
2104
- if (!storage) {
2105
- return;
2106
- }
2107
- try {
2108
- const parsed = JSON.parse(storage.getItem(CACHE_KEY));
2109
- if (parsed && parsed.accounts) {
2110
- const parsedAccounts = parsed.accounts.map((account) => {
2111
- return {
2112
- ...account,
2113
- publicKey: 'publicKey' in account
2114
- ? new Uint8Array(Object.values(account.publicKey)) // Rebuild publicKey for WalletAccount
2115
- : base58.decode(account.address), // Fallback, get publicKey from address
2116
- };
2117
- });
2118
- return { ...parsed, accounts: parsedAccounts };
2119
- }
2120
- else
2121
- return parsed || undefined;
2122
- // eslint-disable-next-line no-empty
2123
- }
2124
- catch { }
2125
- },
2126
- async set(authorization) {
2127
- if (!storage) {
2128
- return;
2129
- }
2130
- try {
2131
- storage.setItem(CACHE_KEY, JSON.stringify(authorization));
2132
- // eslint-disable-next-line no-empty
2133
- }
2134
- catch { }
2135
- },
2136
- };
2137
- }
2138
-
1871
+ let storage;
1872
+ try {
1873
+ storage = window.localStorage;
1874
+ } catch {}
1875
+ return {
1876
+ async clear() {
1877
+ if (!storage) return;
1878
+ try {
1879
+ storage.removeItem(CACHE_KEY);
1880
+ } catch {}
1881
+ },
1882
+ async get() {
1883
+ if (!storage) return;
1884
+ try {
1885
+ const parsed = JSON.parse(storage.getItem(CACHE_KEY));
1886
+ if (parsed && parsed.accounts) {
1887
+ const parsedAccounts = parsed.accounts.map((account) => {
1888
+ return {
1889
+ ...account,
1890
+ publicKey: "publicKey" in account ? new Uint8Array(Object.values(account.publicKey)) : bs58.default.decode(account.address)
1891
+ };
1892
+ });
1893
+ return {
1894
+ ...parsed,
1895
+ accounts: parsedAccounts
1896
+ };
1897
+ } else return parsed || void 0;
1898
+ } catch {}
1899
+ },
1900
+ async set(authorization) {
1901
+ if (!storage) return;
1902
+ try {
1903
+ storage.setItem(CACHE_KEY, JSON.stringify(authorization));
1904
+ } catch {}
1905
+ }
1906
+ };
1907
+ }
1908
+ //#endregion
1909
+ //#region src/createDefaultChainSelector.ts
2139
1910
  function createDefaultChainSelector() {
2140
- return {
2141
- async select(chains) {
2142
- if (chains.length === 1) {
2143
- return chains[0];
2144
- }
2145
- else if (chains.includes(walletStandardChains.SOLANA_MAINNET_CHAIN)) {
2146
- return walletStandardChains.SOLANA_MAINNET_CHAIN;
2147
- }
2148
- else
2149
- return chains[0];
2150
- },
2151
- };
1911
+ return { async select(chains) {
1912
+ if (chains.length === 1) return chains[0];
1913
+ else if (chains.includes(_solana_wallet_standard_chains.SOLANA_MAINNET_CHAIN)) return _solana_wallet_standard_chains.SOLANA_MAINNET_CHAIN;
1914
+ else return chains[0];
1915
+ } };
2152
1916
  }
2153
-
1917
+ //#endregion
2154
1918
  exports.LocalSolanaMobileWalletAdapterWallet = LocalSolanaMobileWalletAdapterWallet;
2155
1919
  exports.RemoteSolanaMobileWalletAdapterWallet = RemoteSolanaMobileWalletAdapterWallet;
2156
1920
  exports.SolanaMobileWalletAdapterRemoteWalletName = SolanaMobileWalletAdapterRemoteWalletName;
@@ -2160,3 +1924,5 @@ exports.createDefaultChainSelector = createDefaultChainSelector;
2160
1924
  exports.createDefaultWalletNotFoundHandler = createDefaultWalletNotFoundHandler;
2161
1925
  exports.defaultErrorModalWalletNotFoundHandler = defaultErrorModalWalletNotFoundHandler;
2162
1926
  exports.registerMwa = registerMwa;
1927
+
1928
+ //# sourceMappingURL=index.browser.js.map