@solana-mobile/wallet-standard-mobile 0.1.0

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.
@@ -0,0 +1,1616 @@
1
+ import { SolanaSignAndSendTransaction, SolanaSignTransaction, SolanaSignMessage, SolanaSignIn } from '@solana/wallet-standard-features';
2
+ import { VersionedTransaction, PublicKey } from '@solana/web3.js';
3
+ import QRCode from 'qrcode';
4
+ import { StandardConnect, StandardDisconnect, StandardEvents } from '@wallet-standard/features';
5
+ import { SOLANA_MAINNET_CHAIN } from '@solana/wallet-standard-chains';
6
+ import { transact, startRemoteScenario } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
7
+ import base58 from 'bs58';
8
+
9
+ /******************************************************************************
10
+ Copyright (c) Microsoft Corporation.
11
+
12
+ Permission to use, copy, modify, and/or distribute this software for any
13
+ purpose with or without fee is hereby granted.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
+ PERFORMANCE OF THIS SOFTWARE.
22
+ ***************************************************************************** */
23
+
24
+ function __awaiter(thisArg, _arguments, P, generator) {
25
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
+ return new (P || (P = Promise))(function (resolve, reject) {
27
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
31
+ });
32
+ }
33
+
34
+ function __classPrivateFieldGet$1(receiver, state, kind, f) {
35
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
36
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
37
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
38
+ }
39
+
40
+ function __classPrivateFieldSet$1(receiver, state, value, kind, f) {
41
+ if (kind === "m") throw new TypeError("Private method is not writable");
42
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
43
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
44
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
45
+ }
46
+
47
+ var _EmbeddedModal_instances, _EmbeddedModal_root, _EmbeddedModal_eventListeners, _EmbeddedModal_listenersAttached, _EmbeddedModal_injectHTML, _EmbeddedModal_attachEventListeners, _EmbeddedModal_removeEventListeners, _EmbeddedModal_handleKeyDown;
48
+ const modalHtml = `
49
+ <div class="mobile-wallet-adapter-embedded-modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-title">
50
+ <div data-modal-close style="position: absolute; width: 100%; height: 100%;"></div>
51
+ <div class="mobile-wallet-adapter-embedded-modal-card">
52
+ <div>
53
+ <button data-modal-close class="mobile-wallet-adapter-embedded-modal-close">
54
+ <svg width="14" height="14">
55
+ <path d="M 6.7125,8.3036995 1.9082,13.108199 c -0.2113,0.2112 -0.4765,0.3168 -0.7957,0.3168 -0.3192,0 -0.5844,-0.1056 -0.7958,-0.3168 C 0.1056,12.896899 0,12.631699 0,12.312499 c 0,-0.3192 0.1056,-0.5844 0.3167,-0.7958 L 5.1212,6.7124995 0.3167,1.9082 C 0.1056,1.6969 0,1.4317 0,1.1125 0,0.7933 0.1056,0.5281 0.3167,0.3167 0.5281,0.1056 0.7933,0 1.1125,0 1.4317,0 1.6969,0.1056 1.9082,0.3167 L 6.7125,5.1212 11.5167,0.3167 C 11.7281,0.1056 11.9933,0 12.3125,0 c 0.3192,0 0.5844,0.1056 0.7957,0.3167 0.2112,0.2114 0.3168,0.4766 0.3168,0.7958 0,0.3192 -0.1056,0.5844 -0.3168,0.7957 L 8.3037001,6.7124995 13.1082,11.516699 c 0.2112,0.2114 0.3168,0.4766 0.3168,0.7958 0,0.3192 -0.1056,0.5844 -0.3168,0.7957 -0.2113,0.2112 -0.4765,0.3168 -0.7957,0.3168 -0.3192,0 -0.5844,-0.1056 -0.7958,-0.3168 z" />
56
+ </svg>
57
+ </button>
58
+ </div>
59
+ <div class="mobile-wallet-adapter-embedded-modal-content"></div>
60
+ </div>
61
+ </div>
62
+ `;
63
+ const css$2 = `
64
+ .mobile-wallet-adapter-embedded-modal-container {
65
+ display: flex; /* Use flexbox to center content */
66
+ justify-content: center; /* Center horizontally */
67
+ align-items: center; /* Center vertically */
68
+ position: fixed; /* Stay in place */
69
+ z-index: 1; /* Sit on top */
70
+ left: 0;
71
+ top: 0;
72
+ width: 100%; /* Full width */
73
+ height: 100%; /* Full height */
74
+ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
75
+ overflow-y: auto; /* enable scrolling */
76
+ }
77
+
78
+ .mobile-wallet-adapter-embedded-modal-card {
79
+ display: flex;
80
+ flex-direction: column;
81
+ margin: auto 20px;
82
+ max-width: 780px;
83
+ padding: 20px;
84
+ border-radius: 24px;
85
+ background: #ffffff;
86
+ font-family: "Inter Tight", "PT Sans", Calibri, sans-serif;
87
+ transform: translateY(-200%);
88
+ animation: slide-in 0.5s forwards;
89
+ }
90
+
91
+ @keyframes slide-in {
92
+ 100% { transform: translateY(0%); }
93
+ }
94
+
95
+ .mobile-wallet-adapter-embedded-modal-close {
96
+ display: flex;
97
+ align-items: center;
98
+ justify-content: center;
99
+ width: 32px;
100
+ height: 32px;
101
+ cursor: pointer;
102
+ background: #e4e9e9;
103
+ border: none;
104
+ border-radius: 50%;
105
+ }
106
+
107
+ .mobile-wallet-adapter-embedded-modal-close:focus-visible {
108
+ outline-color: red;
109
+ }
110
+
111
+ .mobile-wallet-adapter-embedded-modal-close svg {
112
+ fill: #546266;
113
+ transition: fill 200ms ease 0s;
114
+ }
115
+
116
+ .mobile-wallet-adapter-embedded-modal-close:hover svg {
117
+ fill: #fff;
118
+ }
119
+ `;
120
+ const fonts = `
121
+ <link rel="preconnect" href="https://fonts.googleapis.com">
122
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
123
+ <link href="https://fonts.googleapis.com/css2?family=Inter+Tight:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
124
+ `;
125
+ class EmbeddedModal {
126
+ constructor() {
127
+ _EmbeddedModal_instances.add(this);
128
+ _EmbeddedModal_root.set(this, null);
129
+ _EmbeddedModal_eventListeners.set(this, {});
130
+ _EmbeddedModal_listenersAttached.set(this, false);
131
+ this.dom = null;
132
+ this.open = () => {
133
+ console.debug('Modal open');
134
+ __classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_attachEventListeners).call(this);
135
+ if (__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f")) {
136
+ __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'flex';
137
+ }
138
+ };
139
+ this.close = (event = undefined) => {
140
+ var _a;
141
+ console.debug('Modal close');
142
+ __classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_removeEventListeners).call(this);
143
+ if (__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f")) {
144
+ __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'none';
145
+ }
146
+ (_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")['close']) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener(event));
147
+ };
148
+ _EmbeddedModal_handleKeyDown.set(this, (event) => {
149
+ if (event.key === 'Escape')
150
+ this.close(event);
151
+ });
152
+ // Bind methods to ensure `this` context is correct
153
+ this.init = this.init.bind(this);
154
+ __classPrivateFieldSet$1(this, _EmbeddedModal_root, document.getElementById('mobile-wallet-adapter-embedded-root-ui'), "f");
155
+ }
156
+ init() {
157
+ return __awaiter(this, void 0, void 0, function* () {
158
+ console.log('Injecting modal');
159
+ __classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_injectHTML).call(this);
160
+ });
161
+ }
162
+ addEventListener(event, listener) {
163
+ var _a;
164
+ ((_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event] = [listener]);
165
+ return () => this.removeEventListener(event, listener);
166
+ }
167
+ removeEventListener(event, listener) {
168
+ var _a;
169
+ __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
170
+ }
171
+ }
172
+ _EmbeddedModal_root = new WeakMap(), _EmbeddedModal_eventListeners = new WeakMap(), _EmbeddedModal_listenersAttached = new WeakMap(), _EmbeddedModal_handleKeyDown = new WeakMap(), _EmbeddedModal_instances = new WeakSet(), _EmbeddedModal_injectHTML = function _EmbeddedModal_injectHTML() {
173
+ // Check if the HTML has already been injected
174
+ if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
175
+ if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"))
176
+ __classPrivateFieldSet$1(this, _EmbeddedModal_root, document.getElementById('mobile-wallet-adapter-embedded-root-ui'), "f");
177
+ return;
178
+ }
179
+ // Create a container for the modal
180
+ __classPrivateFieldSet$1(this, _EmbeddedModal_root, document.createElement('div'), "f");
181
+ __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").id = 'mobile-wallet-adapter-embedded-root-ui';
182
+ __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").innerHTML = modalHtml;
183
+ __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'none';
184
+ // Add modal content
185
+ const content = __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelector('.mobile-wallet-adapter-embedded-modal-content');
186
+ if (content)
187
+ content.innerHTML = this.contentHtml;
188
+ // Apply styles
189
+ const styles = document.createElement('style');
190
+ styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
191
+ styles.textContent = css$2 + this.contentStyles;
192
+ // Create a shadow DOM to encapsulate the modal
193
+ const host = document.createElement('div');
194
+ host.innerHTML = fonts;
195
+ this.dom = host.attachShadow({ mode: 'closed' });
196
+ this.dom.appendChild(styles);
197
+ this.dom.appendChild(__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"));
198
+ // Append the shadow DOM host to the body
199
+ document.body.appendChild(host);
200
+ }, _EmbeddedModal_attachEventListeners = function _EmbeddedModal_attachEventListeners() {
201
+ if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f") || __classPrivateFieldGet$1(this, _EmbeddedModal_listenersAttached, "f"))
202
+ return;
203
+ const closers = [...__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelectorAll('[data-modal-close]')];
204
+ closers.forEach(closer => closer === null || closer === void 0 ? void 0 : closer.addEventListener('click', this.close));
205
+ window.addEventListener('load', this.close);
206
+ document.addEventListener('keydown', __classPrivateFieldGet$1(this, _EmbeddedModal_handleKeyDown, "f"));
207
+ __classPrivateFieldSet$1(this, _EmbeddedModal_listenersAttached, true, "f");
208
+ }, _EmbeddedModal_removeEventListeners = function _EmbeddedModal_removeEventListeners() {
209
+ if (!__classPrivateFieldGet$1(this, _EmbeddedModal_listenersAttached, "f"))
210
+ return;
211
+ window.removeEventListener('load', this.close);
212
+ document.removeEventListener('keydown', __classPrivateFieldGet$1(this, _EmbeddedModal_handleKeyDown, "f"));
213
+ if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"))
214
+ return;
215
+ const closers = [...__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelectorAll('[data-modal-close]')];
216
+ closers.forEach(closer => closer === null || closer === void 0 ? void 0 : closer.removeEventListener('click', this.close));
217
+ __classPrivateFieldSet$1(this, _EmbeddedModal_listenersAttached, false, "f");
218
+ };
219
+
220
+ class RemoteConnectionModal extends EmbeddedModal {
221
+ constructor() {
222
+ super(...arguments);
223
+ this.contentStyles = css$1;
224
+ this.contentHtml = QRCodeHtml;
225
+ }
226
+ initWithQR(qrCode) {
227
+ const _super = Object.create(null, {
228
+ init: { get: () => super.init }
229
+ });
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ _super.init.call(this);
232
+ this.populateQRCode(qrCode);
233
+ });
234
+ }
235
+ populateQRCode(qrUrl) {
236
+ var _a;
237
+ return __awaiter(this, void 0, void 0, function* () {
238
+ const qrcodeContainer = (_a = this.dom) === null || _a === void 0 ? void 0 : _a.getElementById('mobile-wallet-adapter-embedded-modal-qr-code-container');
239
+ if (qrcodeContainer) {
240
+ const qrCodeElement = yield QRCode.toCanvas(qrUrl, { width: 200, margin: 0 });
241
+ if (qrcodeContainer.firstElementChild !== null) {
242
+ qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
243
+ }
244
+ else
245
+ qrcodeContainer.appendChild(qrCodeElement);
246
+ }
247
+ else {
248
+ console.error('QRCode Container not found');
249
+ }
250
+ });
251
+ }
252
+ }
253
+ const QRCodeHtml = `
254
+ <div class="mobile-wallet-adapter-embedded-modal-qr-content">
255
+ <div>
256
+ <svg class="mobile-wallet-adapter-embedded-modal-icon" width="100%" height="100%">
257
+ <circle r="52" cx="53" cy="53" fill="#99b3be" stroke="#000000" stroke-width="2"/>
258
+ <path d="m 53,82.7305 c -3.3116,0 -6.1361,-1.169 -8.4735,-3.507 -2.338,-2.338 -3.507,-5.1625 -3.507,-8.4735 0,-3.3116 1.169,-6.1364 3.507,-8.4744 2.3374,-2.338 5.1619,-3.507 8.4735,-3.507 3.3116,0 6.1361,1.169 8.4735,3.507 2.338,2.338 3.507,5.1628 3.507,8.4744 0,3.311 -1.169,6.1355 -3.507,8.4735 -2.3374,2.338 -5.1619,3.507 -8.4735,3.507 z m 0.007,-5.25 c 1.8532,0 3.437,-0.6598 4.7512,-1.9793 1.3149,-1.3195 1.9723,-2.9058 1.9723,-4.7591 0,-1.8526 -0.6598,-3.4364 -1.9793,-4.7512 -1.3195,-1.3149 -2.9055,-1.9723 -4.7582,-1.9723 -1.8533,0 -3.437,0.6598 -4.7513,1.9793 -1.3148,1.3195 -1.9722,2.9058 -1.9722,4.7591 0,1.8527 0.6597,3.4364 1.9792,4.7512 1.3195,1.3149 2.9056,1.9723 4.7583,1.9723 z m -28,-33.5729 -3.85,-3.6347 c 4.1195,-4.025 8.8792,-7.1984 14.2791,-9.52 5.4005,-2.3223 11.2551,-3.4834 17.5639,-3.4834 6.3087,0 12.1634,1.1611 17.5639,3.4834 5.3999,2.3216 10.1596,5.495 14.2791,9.52 l -3.85,3.6347 C 77.2999,40.358 73.0684,37.5726 68.2985,35.5514 63.5292,33.5301 58.4296,32.5195 53,32.5195 c -5.4297,0 -10.5292,1.0106 -15.2985,3.0319 -4.7699,2.0212 -9.0014,4.8066 -12.6945,8.3562 z m 44.625,10.8771 c -2.2709,-2.1046 -4.7962,-3.7167 -7.5758,-4.8361 -2.7795,-1.12 -5.7983,-1.68 -9.0562,-1.68 -3.2579,0 -6.2621,0.56 -9.0125,1.68 -2.7504,1.1194 -5.2903,2.7315 -7.6195,4.8361 L 32.5189,51.15 c 2.8355,-2.6028 5.9777,-4.6086 9.4263,-6.0174 3.4481,-1.4087 7.133,-2.1131 11.0548,-2.1131 3.9217,0 7.5979,0.7044 11.0285,2.1131 3.43,1.4088 6.5631,3.4146 9.3992,6.0174 z"/>
259
+ </svg>
260
+ <div class="mobile-wallet-adapter-embedded-modal-title">Remote Mobile Wallet Adapter</div>
261
+ </div>
262
+ <div>
263
+ <div>
264
+ <h4 class="mobile-wallet-adapter-embedded-modal-qr-label">
265
+ Open your wallet and scan this code
266
+ </h4>
267
+ </div>
268
+ <div id="mobile-wallet-adapter-embedded-modal-qr-code-container" class="mobile-wallet-adapter-embedded-modal-qr-code-container"></div>
269
+ </div>
270
+ </div>
271
+ <div class="mobile-wallet-adapter-embedded-modal-divider"><hr></div>
272
+ <div class="mobile-wallet-adapter-embedded-modal-footer">
273
+ <div class="mobile-wallet-adapter-embedded-modal-subtitle">
274
+ Follow the instructions on your device. When you're finished, this screen will update.
275
+ </div>
276
+ <div class="mobile-wallet-adapter-embedded-modal-progress-badge">
277
+ <div>
278
+ <div class="spinner">
279
+ <div class="leftWrapper">
280
+ <div class="left">
281
+ <div class="circle"></div>
282
+ </div>
283
+ </div>
284
+ <div class="rightWrapper">
285
+ <div class="right">
286
+ <div class="circle"></div>
287
+ </div>
288
+ </div>
289
+ </div>
290
+ </div>
291
+ <div>Waiting for scan</div>
292
+ </div>
293
+ </div>
294
+ `;
295
+ const css$1 = `
296
+ .mobile-wallet-adapter-embedded-modal-qr-content {
297
+ display: flex;
298
+ margin-top: 10px;
299
+ padding: 10px;
300
+ }
301
+
302
+ .mobile-wallet-adapter-embedded-modal-qr-content > div:first-child {
303
+ display: flex;
304
+ flex-direction: column;
305
+ flex: 2;
306
+ margin-top: auto;
307
+ margin-right: 30px;
308
+ }
309
+
310
+ .mobile-wallet-adapter-embedded-modal-qr-content > div:nth-child(2) {
311
+ display: flex;
312
+ flex-direction: column;
313
+ flex: 1;
314
+ margin-left: auto;
315
+ }
316
+
317
+ .mobile-wallet-adapter-embedded-modal-footer {
318
+ display: flex;
319
+ padding: 10px;
320
+ }
321
+
322
+ .mobile-wallet-adapter-embedded-modal-icon {}
323
+
324
+ .mobile-wallet-adapter-embedded-modal-title {
325
+ color: #000000;
326
+ font-size: 2.5em;
327
+ font-weight: 600;
328
+ }
329
+
330
+ .mobile-wallet-adapter-embedded-modal-qr-label {
331
+ text-align: right;
332
+ color: #000000;
333
+ }
334
+
335
+ .mobile-wallet-adapter-embedded-modal-qr-code-container {
336
+ margin-left: auto;
337
+ }
338
+
339
+ .mobile-wallet-adapter-embedded-modal-divider {
340
+ margin-top: 20px;
341
+ padding-left: 10px;
342
+ padding-right: 10px;
343
+ }
344
+
345
+ .mobile-wallet-adapter-embedded-modal-divider hr {
346
+ border-top: 1px solid #D9DEDE;
347
+ }
348
+
349
+ .mobile-wallet-adapter-embedded-modal-subtitle {
350
+ margin: auto;
351
+ margin-right: 60px;
352
+ padding: 20px;
353
+ color: #6E8286;
354
+ }
355
+
356
+ .mobile-wallet-adapter-embedded-modal-progress-badge {
357
+ display: flex;
358
+ background: #F7F8F8;
359
+ height: 56px;
360
+ min-width: 200px;
361
+ margin: auto;
362
+ padding-left: 20px;
363
+ padding-right: 20px;
364
+ border-radius: 18px;
365
+ color: #A8B6B8;
366
+ align-items: center;
367
+ }
368
+
369
+ .mobile-wallet-adapter-embedded-modal-progress-badge > div:first-child {
370
+ margin-left: auto;
371
+ margin-right: 20px;
372
+ }
373
+
374
+ .mobile-wallet-adapter-embedded-modal-progress-badge > div:nth-child(2) {
375
+ margin-right: auto;
376
+ }
377
+
378
+ /* Smaller screens */
379
+ @media all and (max-width: 600px) {
380
+ .mobile-wallet-adapter-embedded-modal-card {
381
+ text-align: center;
382
+ }
383
+ .mobile-wallet-adapter-embedded-modal-qr-content {
384
+ flex-direction: column;
385
+ }
386
+ .mobile-wallet-adapter-embedded-modal-qr-content > div:first-child {
387
+ margin: auto;
388
+ }
389
+ .mobile-wallet-adapter-embedded-modal-qr-content > div:nth-child(2) {
390
+ margin: auto;
391
+ flex: 2 auto;
392
+ }
393
+ .mobile-wallet-adapter-embedded-modal-footer {
394
+ flex-direction: column;
395
+ }
396
+ .mobile-wallet-adapter-embedded-modal-icon {
397
+ display: none;
398
+ }
399
+ .mobile-wallet-adapter-embedded-modal-title {
400
+ font-size: 1.5em;
401
+ }
402
+ .mobile-wallet-adapter-embedded-modal-subtitle {
403
+ margin-right: unset;
404
+ }
405
+ .mobile-wallet-adapter-embedded-modal-qr-label {
406
+ text-align: center;
407
+ }
408
+ .mobile-wallet-adapter-embedded-modal-qr-code-container {
409
+ margin: auto;
410
+ }
411
+ }
412
+
413
+ /* Spinner */
414
+ @keyframes spinLeft {
415
+ 0% {
416
+ transform: rotate(20deg);
417
+ }
418
+ 50% {
419
+ transform: rotate(160deg);
420
+ }
421
+ 100% {
422
+ transform: rotate(20deg);
423
+ }
424
+ }
425
+ @keyframes spinRight {
426
+ 0% {
427
+ transform: rotate(160deg);
428
+ }
429
+ 50% {
430
+ transform: rotate(20deg);
431
+ }
432
+ 100% {
433
+ transform: rotate(160deg);
434
+ }
435
+ }
436
+ @keyframes spin {
437
+ 0% {
438
+ transform: rotate(0deg);
439
+ }
440
+ 100% {
441
+ transform: rotate(2520deg);
442
+ }
443
+ }
444
+
445
+ .spinner {
446
+ position: relative;
447
+ width: 1.5em;
448
+ height: 1.5em;
449
+ margin: auto;
450
+ animation: spin 10s linear infinite;
451
+ }
452
+ .spinner::before {
453
+ content: "";
454
+ position: absolute;
455
+ top: 0;
456
+ bottom: 0;
457
+ left: 0;
458
+ right: 0;
459
+ }
460
+ .right, .rightWrapper, .left, .leftWrapper {
461
+ position: absolute;
462
+ top: 0;
463
+ overflow: hidden;
464
+ width: .75em;
465
+ height: 1.5em;
466
+ }
467
+ .left, .leftWrapper {
468
+ left: 0;
469
+ }
470
+ .right {
471
+ left: -12px;
472
+ }
473
+ .rightWrapper {
474
+ right: 0;
475
+ }
476
+ .circle {
477
+ border: .125em solid #A8B6B8;
478
+ width: 1.25em; /* 1.5em - 2*0.125em border */
479
+ height: 1.25em; /* 1.5em - 2*0.125em border */
480
+ border-radius: 0.75em; /* 0.5*1.5em spinner size 8 */
481
+ }
482
+ .left {
483
+ transform-origin: 100% 50%;
484
+ animation: spinLeft 2.5s cubic-bezier(.2,0,.8,1) infinite;
485
+ }
486
+ .right {
487
+ transform-origin: 100% 50%;
488
+ animation: spinRight 2.5s cubic-bezier(.2,0,.8,1) infinite;
489
+ }
490
+ `;
491
+
492
+ const icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=';
493
+
494
+ function isVersionedTransaction(transaction) {
495
+ return 'version' in transaction;
496
+ }
497
+
498
+ function fromUint8Array(byteArray) {
499
+ return window.btoa(String.fromCharCode.call(null, ...byteArray));
500
+ }
501
+ function toUint8Array(base64EncodedByteArray) {
502
+ return new Uint8Array(window
503
+ .atob(base64EncodedByteArray)
504
+ .split('')
505
+ .map((c) => c.charCodeAt(0)));
506
+ }
507
+
508
+ var _LocalSolanaMobileWalletAdapterWallet_instances, _LocalSolanaMobileWalletAdapterWallet_listeners, _LocalSolanaMobileWalletAdapterWallet_version, _LocalSolanaMobileWalletAdapterWallet_name, _LocalSolanaMobileWalletAdapterWallet_url, _LocalSolanaMobileWalletAdapterWallet_icon, _LocalSolanaMobileWalletAdapterWallet_appIdentity, _LocalSolanaMobileWalletAdapterWallet_authorization, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, _LocalSolanaMobileWalletAdapterWallet_connecting, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, _LocalSolanaMobileWalletAdapterWallet_chains, _LocalSolanaMobileWalletAdapterWallet_chainSelector, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, _LocalSolanaMobileWalletAdapterWallet_on, _LocalSolanaMobileWalletAdapterWallet_emit, _LocalSolanaMobileWalletAdapterWallet_off, _LocalSolanaMobileWalletAdapterWallet_connect, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, _LocalSolanaMobileWalletAdapterWallet_disconnect, _LocalSolanaMobileWalletAdapterWallet_transact, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, _LocalSolanaMobileWalletAdapterWallet_performSignTransactions, _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, _LocalSolanaMobileWalletAdapterWallet_signTransaction, _LocalSolanaMobileWalletAdapterWallet_signMessage, _LocalSolanaMobileWalletAdapterWallet_signIn, _LocalSolanaMobileWalletAdapterWallet_performSignIn, _RemoteSolanaMobileWalletAdapterWallet_instances, _RemoteSolanaMobileWalletAdapterWallet_listeners, _RemoteSolanaMobileWalletAdapterWallet_version, _RemoteSolanaMobileWalletAdapterWallet_name, _RemoteSolanaMobileWalletAdapterWallet_url, _RemoteSolanaMobileWalletAdapterWallet_icon, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, _RemoteSolanaMobileWalletAdapterWallet_authorization, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, _RemoteSolanaMobileWalletAdapterWallet_connecting, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, _RemoteSolanaMobileWalletAdapterWallet_chains, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, _RemoteSolanaMobileWalletAdapterWallet_session, _RemoteSolanaMobileWalletAdapterWallet_on, _RemoteSolanaMobileWalletAdapterWallet_emit, _RemoteSolanaMobileWalletAdapterWallet_off, _RemoteSolanaMobileWalletAdapterWallet_connect, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, _RemoteSolanaMobileWalletAdapterWallet_disconnect, _RemoteSolanaMobileWalletAdapterWallet_transact, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions, _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, _RemoteSolanaMobileWalletAdapterWallet_signMessage, _RemoteSolanaMobileWalletAdapterWallet_signIn, _RemoteSolanaMobileWalletAdapterWallet_performSignIn;
509
+ const SolanaMobileWalletAdapterWalletName = 'Mobile Wallet Adapter';
510
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
511
+ const DEFAULT_FEATURES = [SolanaSignAndSendTransaction, SolanaSignTransaction, SolanaSignMessage, SolanaSignIn];
512
+ class LocalSolanaMobileWalletAdapterWallet {
513
+ constructor(config) {
514
+ _LocalSolanaMobileWalletAdapterWallet_instances.add(this);
515
+ _LocalSolanaMobileWalletAdapterWallet_listeners.set(this, {});
516
+ _LocalSolanaMobileWalletAdapterWallet_version.set(this, '1.0.0'); // wallet-standard version
517
+ _LocalSolanaMobileWalletAdapterWallet_name.set(this, SolanaMobileWalletAdapterWalletName);
518
+ _LocalSolanaMobileWalletAdapterWallet_url.set(this, 'https://solanamobile.com/wallets');
519
+ _LocalSolanaMobileWalletAdapterWallet_icon.set(this, icon);
520
+ _LocalSolanaMobileWalletAdapterWallet_appIdentity.set(this, void 0);
521
+ _LocalSolanaMobileWalletAdapterWallet_authorization.set(this, void 0);
522
+ _LocalSolanaMobileWalletAdapterWallet_authorizationCache.set(this, void 0);
523
+ _LocalSolanaMobileWalletAdapterWallet_connecting.set(this, false);
524
+ /**
525
+ * Every time the connection is recycled in some way (eg. `disconnect()` is called)
526
+ * increment this and use it to make sure that `transact` calls from the previous
527
+ * 'generation' don't continue to do work and throw exceptions.
528
+ */
529
+ _LocalSolanaMobileWalletAdapterWallet_connectionGeneration.set(this, 0);
530
+ _LocalSolanaMobileWalletAdapterWallet_chains.set(this, []);
531
+ _LocalSolanaMobileWalletAdapterWallet_chainSelector.set(this, void 0);
532
+ _LocalSolanaMobileWalletAdapterWallet_optionalFeatures.set(this, void 0);
533
+ _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound.set(this, void 0);
534
+ _LocalSolanaMobileWalletAdapterWallet_on.set(this, (event, listener) => {
535
+ var _a;
536
+ ((_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event] = [listener]);
537
+ return () => __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_off).call(this, event, listener);
538
+ });
539
+ _LocalSolanaMobileWalletAdapterWallet_connect.set(this, ({ silent } = {}) => __awaiter(this, void 0, void 0, function* () {
540
+ if (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, "f") || this.connected) {
541
+ return { accounts: this.accounts };
542
+ }
543
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, true, "f");
544
+ try {
545
+ if (silent) {
546
+ const cachedAuthorization = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
547
+ if (cachedAuthorization) {
548
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorization);
549
+ }
550
+ else {
551
+ return { accounts: this.accounts };
552
+ }
553
+ }
554
+ else {
555
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this);
556
+ }
557
+ }
558
+ catch (e) {
559
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
560
+ }
561
+ finally {
562
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false, "f");
563
+ }
564
+ return { accounts: this.accounts };
565
+ }));
566
+ _LocalSolanaMobileWalletAdapterWallet_performAuthorization.set(this, (signInPayload) => __awaiter(this, void 0, void 0, function* () {
567
+ try {
568
+ const cachedAuthorizationResult = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
569
+ if (cachedAuthorizationResult) {
570
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
571
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorizationResult);
572
+ return cachedAuthorizationResult;
573
+ }
574
+ const selectedChain = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chainSelector, "f").select(__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"));
575
+ return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
576
+ const [capabilities, mwaAuthorizationResult] = yield Promise.all([
577
+ wallet.getCapabilities(),
578
+ wallet.authorize({
579
+ chain: selectedChain,
580
+ identity: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, "f"),
581
+ sign_in_payload: signInPayload,
582
+ })
583
+ ]);
584
+ const accounts = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
585
+ const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts, chain: selectedChain });
586
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
587
+ Promise.all([
588
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, capabilities),
589
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
590
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
591
+ ]);
592
+ return authorization;
593
+ }));
594
+ }
595
+ catch (e) {
596
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
597
+ }
598
+ }));
599
+ _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult.set(this, (authorization) => __awaiter(this, void 0, void 0, function* () {
600
+ var _a;
601
+ const didPublicKeysChange =
602
+ // Case 1: We started from having no authorization.
603
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f") == null ||
604
+ // Case 2: The number of authorized accounts changed.
605
+ ((_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorization.accounts.length ||
606
+ // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
607
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
608
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, authorization, "f");
609
+ if (didPublicKeysChange) {
610
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
611
+ }
612
+ }));
613
+ _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult.set(this, (capabilities) => __awaiter(this, void 0, void 0, function* () {
614
+ // TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
615
+ const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
616
+ const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions;
617
+ const didCapabilitiesChange = SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
618
+ SolanaSignTransaction in this.features !== supportsSignTransaction;
619
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, Object.assign(Object.assign({}, ((supportsSignAndSendTransaction || (!supportsSignAndSendTransaction && !supportsSignTransaction)) && {
620
+ [SolanaSignAndSendTransaction]: {
621
+ version: '1.0.0',
622
+ supportedTransactionVersions: ['legacy', 0],
623
+ signAndSendTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
624
+ },
625
+ })), (supportsSignTransaction && {
626
+ [SolanaSignTransaction]: {
627
+ version: '1.0.0',
628
+ supportedTransactionVersions: ['legacy', 0],
629
+ signTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signTransaction, "f"),
630
+ },
631
+ })), "f");
632
+ if (didCapabilitiesChange) {
633
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { features: this.features });
634
+ }
635
+ }));
636
+ _LocalSolanaMobileWalletAdapterWallet_performReauthorization.set(this, (wallet, authToken, chain) => __awaiter(this, void 0, void 0, function* () {
637
+ try {
638
+ const mwaAuthorizationResult = yield wallet.authorize({
639
+ auth_token: authToken,
640
+ identity: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, "f"),
641
+ chain: chain
642
+ });
643
+ const accounts = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
644
+ const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts: accounts, chain: chain });
645
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
646
+ Promise.all([
647
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
648
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
649
+ ]);
650
+ }
651
+ catch (e) {
652
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_disconnect, "f").call(this);
653
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
654
+ }
655
+ }));
656
+ _LocalSolanaMobileWalletAdapterWallet_disconnect.set(this, () => __awaiter(this, void 0, void 0, function* () {
657
+ var _b;
658
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
659
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false, "f");
660
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, (_b = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f"), _b++, _b), "f");
661
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, undefined, "f");
662
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
663
+ }));
664
+ _LocalSolanaMobileWalletAdapterWallet_transact.set(this, (callback) => __awaiter(this, void 0, void 0, function* () {
665
+ var _c;
666
+ const walletUriBase = (_c = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _c === void 0 ? void 0 : _c.wallet_uri_base;
667
+ const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
668
+ const currentConnectionGeneration = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f");
669
+ try {
670
+ return yield transact(callback, config);
671
+ }
672
+ catch (e) {
673
+ if (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f") !== currentConnectionGeneration) {
674
+ yield new Promise(() => { }); // Never resolve.
675
+ }
676
+ if (e instanceof Error &&
677
+ e.name === 'SolanaMobileWalletAdapterError' &&
678
+ e.code === 'ERROR_WALLET_NOT_FOUND') {
679
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, "f").call(this, this);
680
+ }
681
+ throw e;
682
+ }
683
+ }));
684
+ _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized.set(this, () => {
685
+ if (!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f"))
686
+ throw new Error('Wallet not connected');
687
+ return { authToken: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").auth_token, chain: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").chain };
688
+ });
689
+ _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts.set(this, (accounts) => {
690
+ return accounts.map((account) => {
691
+ var _a, _b;
692
+ const publicKey = toUint8Array(account.address);
693
+ return {
694
+ address: base58.encode(publicKey),
695
+ publicKey,
696
+ label: account.label,
697
+ icon: account.icon,
698
+ chains: (_a = account.chains) !== null && _a !== void 0 ? _a : __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"),
699
+ // TODO: get supported features from getCapabilities API
700
+ features: (_b = account.features) !== null && _b !== void 0 ? _b : DEFAULT_FEATURES
701
+ };
702
+ });
703
+ });
704
+ _LocalSolanaMobileWalletAdapterWallet_performSignTransactions.set(this, (transactions) => __awaiter(this, void 0, void 0, function* () {
705
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
706
+ try {
707
+ return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
708
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
709
+ const signedTransactions = yield wallet.signTransactions({
710
+ transactions,
711
+ });
712
+ return signedTransactions;
713
+ }));
714
+ }
715
+ catch (e) {
716
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
717
+ }
718
+ }));
719
+ _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction.set(this, (transaction, options) => __awaiter(this, void 0, void 0, function* () {
720
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
721
+ try {
722
+ return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
723
+ const [capabilities, _1] = yield Promise.all([
724
+ wallet.getCapabilities(),
725
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain)
726
+ ]);
727
+ if (capabilities.supports_sign_and_send_transactions) {
728
+ const signatures = yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, options), { transactions: [transaction] }));
729
+ return signatures[0];
730
+ }
731
+ else {
732
+ throw new Error('connected wallet does not support signAndSendTransaction');
733
+ }
734
+ }));
735
+ }
736
+ catch (e) {
737
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
738
+ }
739
+ }));
740
+ _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
741
+ const outputs = [];
742
+ for (const input of inputs) {
743
+ const transaction = VersionedTransaction.deserialize(input.transaction);
744
+ const signature = (yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, "f").call(this, transaction, input.options));
745
+ outputs.push({ signature: base58.decode(signature) });
746
+ }
747
+ return outputs;
748
+ }));
749
+ _LocalSolanaMobileWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
750
+ const transactions = inputs.map(({ transaction }) => VersionedTransaction.deserialize(transaction));
751
+ const signedTransactions = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignTransactions, "f").call(this, transactions);
752
+ return signedTransactions.map((signedTransaction) => {
753
+ const serializedTransaction = isVersionedTransaction(signedTransaction)
754
+ ? signedTransaction.serialize()
755
+ : new Uint8Array(signedTransaction.serialize({
756
+ requireAllSignatures: false,
757
+ verifySignatures: false,
758
+ }));
759
+ return { signedTransaction: serializedTransaction };
760
+ });
761
+ }));
762
+ _LocalSolanaMobileWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
763
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
764
+ const addresses = inputs.map(({ account }) => fromUint8Array(account.publicKey));
765
+ const messages = inputs.map(({ message }) => message);
766
+ try {
767
+ return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
768
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
769
+ const signedMessages = yield wallet.signMessages({
770
+ addresses: addresses,
771
+ payloads: messages,
772
+ });
773
+ return signedMessages.map((signedMessage) => {
774
+ return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
775
+ });
776
+ }));
777
+ }
778
+ catch (e) {
779
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
780
+ }
781
+ }));
782
+ _LocalSolanaMobileWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
783
+ const outputs = [];
784
+ if (inputs.length > 1) {
785
+ for (const input of inputs) {
786
+ outputs.push(yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, input));
787
+ }
788
+ }
789
+ else {
790
+ return [yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, inputs[0])];
791
+ }
792
+ return outputs;
793
+ }));
794
+ _LocalSolanaMobileWalletAdapterWallet_performSignIn.set(this, (input) => __awaiter(this, void 0, void 0, function* () {
795
+ var _d, _e;
796
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, true, "f");
797
+ try {
798
+ const authorizationResult = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this, Object.assign(Object.assign({}, input), { domain: (_d = input === null || input === void 0 ? void 0 : input.domain) !== null && _d !== void 0 ? _d : window.location.host }));
799
+ if (!authorizationResult.sign_in_result) {
800
+ throw new Error("Sign in failed, no sign in result returned by wallet");
801
+ }
802
+ const signedInAddress = authorizationResult.sign_in_result.address;
803
+ const signedInAccount = Object.assign(Object.assign({}, (_e = authorizationResult.accounts.find(acc => acc.address == signedInAddress)) !== null && _e !== void 0 ? _e : {
804
+ address: signedInAddress
805
+ }), { publicKey: toUint8Array(signedInAddress) });
806
+ return {
807
+ account: signedInAccount,
808
+ signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
809
+ signature: toUint8Array(authorizationResult.sign_in_result.signature)
810
+ };
811
+ }
812
+ catch (e) {
813
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
814
+ }
815
+ finally {
816
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false, "f");
817
+ }
818
+ }));
819
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, config.authorizationCache, "f");
820
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, config.appIdentity, "f");
821
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, config.chains, "f");
822
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_chainSelector, config.chainSelector, "f");
823
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, config.onWalletNotFound, "f");
824
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, {
825
+ // We are forced to provide either SolanaSignAndSendTransaction or SolanaSignTransaction
826
+ // because the wallet-adapter compatible wallet-standard wallet requires at least one of them.
827
+ // MWA 2.0+ wallets must implement signAndSend and pre 2.0 wallets have always provided it so
828
+ // this is a safe assumption. We later update the features after we get the wallets capabilities.
829
+ [SolanaSignAndSendTransaction]: {
830
+ version: '1.0.0',
831
+ supportedTransactionVersions: ['legacy', 0],
832
+ signAndSendTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
833
+ },
834
+ }, "f");
835
+ }
836
+ get version() {
837
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_version, "f");
838
+ }
839
+ get name() {
840
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_name, "f");
841
+ }
842
+ get url() {
843
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_url, "f");
844
+ }
845
+ get icon() {
846
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_icon, "f");
847
+ }
848
+ get chains() {
849
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f");
850
+ }
851
+ get features() {
852
+ return Object.assign({ [StandardConnect]: {
853
+ version: '1.0.0',
854
+ connect: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connect, "f"),
855
+ }, [StandardDisconnect]: {
856
+ version: '1.0.0',
857
+ disconnect: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_disconnect, "f"),
858
+ }, [StandardEvents]: {
859
+ version: '1.0.0',
860
+ on: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_on, "f"),
861
+ }, [SolanaSignMessage]: {
862
+ version: '1.0.0',
863
+ signMessage: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signMessage, "f"),
864
+ }, [SolanaSignIn]: {
865
+ version: '1.0.0',
866
+ signIn: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signIn, "f"),
867
+ } }, __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, "f"));
868
+ }
869
+ get accounts() {
870
+ var _a, _b;
871
+ return (_b = (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : [];
872
+ }
873
+ get connected() {
874
+ return !!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
875
+ }
876
+ get isAuthorized() {
877
+ return !!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
878
+ }
879
+ get currentAuthorization() {
880
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
881
+ }
882
+ get cachedAuthorizationResult() {
883
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
884
+ }
885
+ }
886
+ _LocalSolanaMobileWalletAdapterWallet_listeners = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_version = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_name = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_url = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_icon = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_appIdentity = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_authorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_authorizationCache = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connecting = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connectionGeneration = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_chains = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_chainSelector = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_optionalFeatures = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_on = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connect = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performAuthorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performReauthorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_disconnect = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_transact = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignTransactions = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signMessage = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signIn = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignIn = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_instances = new WeakSet(), _LocalSolanaMobileWalletAdapterWallet_emit = function _LocalSolanaMobileWalletAdapterWallet_emit(event, ...args) {
887
+ var _a;
888
+ // eslint-disable-next-line prefer-spread
889
+ (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener.apply(null, args));
890
+ }, _LocalSolanaMobileWalletAdapterWallet_off = function _LocalSolanaMobileWalletAdapterWallet_off(event, listener) {
891
+ var _a;
892
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
893
+ };
894
+ class RemoteSolanaMobileWalletAdapterWallet {
895
+ constructor(config) {
896
+ _RemoteSolanaMobileWalletAdapterWallet_instances.add(this);
897
+ _RemoteSolanaMobileWalletAdapterWallet_listeners.set(this, {});
898
+ _RemoteSolanaMobileWalletAdapterWallet_version.set(this, '1.0.0'); // wallet-standard version
899
+ _RemoteSolanaMobileWalletAdapterWallet_name.set(this, SolanaMobileWalletAdapterWalletName);
900
+ _RemoteSolanaMobileWalletAdapterWallet_url.set(this, 'https://solanamobile.com/wallets');
901
+ _RemoteSolanaMobileWalletAdapterWallet_icon.set(this, icon);
902
+ _RemoteSolanaMobileWalletAdapterWallet_appIdentity.set(this, void 0);
903
+ _RemoteSolanaMobileWalletAdapterWallet_authorization.set(this, void 0);
904
+ _RemoteSolanaMobileWalletAdapterWallet_authorizationCache.set(this, void 0);
905
+ _RemoteSolanaMobileWalletAdapterWallet_connecting.set(this, false);
906
+ /**
907
+ * Every time the connection is recycled in some way (eg. `disconnect()` is called)
908
+ * increment this and use it to make sure that `transact` calls from the previous
909
+ * 'generation' don't continue to do work and throw exceptions.
910
+ */
911
+ _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration.set(this, 0);
912
+ _RemoteSolanaMobileWalletAdapterWallet_chains.set(this, []);
913
+ _RemoteSolanaMobileWalletAdapterWallet_chainSelector.set(this, void 0);
914
+ _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures.set(this, void 0);
915
+ _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound.set(this, void 0);
916
+ _RemoteSolanaMobileWalletAdapterWallet_hostAuthority.set(this, void 0);
917
+ _RemoteSolanaMobileWalletAdapterWallet_session.set(this, void 0);
918
+ _RemoteSolanaMobileWalletAdapterWallet_on.set(this, (event, listener) => {
919
+ var _a;
920
+ ((_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event] = [listener]);
921
+ return () => __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_off).call(this, event, listener);
922
+ });
923
+ _RemoteSolanaMobileWalletAdapterWallet_connect.set(this, ({ silent } = {}) => __awaiter(this, void 0, void 0, function* () {
924
+ if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, "f") || this.connected) {
925
+ return { accounts: this.accounts };
926
+ }
927
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, true, "f");
928
+ try {
929
+ yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this);
930
+ }
931
+ catch (e) {
932
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
933
+ }
934
+ finally {
935
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false, "f");
936
+ }
937
+ return { accounts: this.accounts };
938
+ }));
939
+ _RemoteSolanaMobileWalletAdapterWallet_performAuthorization.set(this, (signInPayload) => __awaiter(this, void 0, void 0, function* () {
940
+ try {
941
+ const cachedAuthorizationResult = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
942
+ if (cachedAuthorizationResult) {
943
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
944
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorizationResult);
945
+ return cachedAuthorizationResult;
946
+ }
947
+ if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f"))
948
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, undefined, "f");
949
+ const selectedChain = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, "f").select(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"));
950
+ return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
951
+ const [capabilities, mwaAuthorizationResult] = yield Promise.all([
952
+ wallet.getCapabilities(),
953
+ wallet.authorize({
954
+ chain: selectedChain,
955
+ identity: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, "f"),
956
+ sign_in_payload: signInPayload,
957
+ })
958
+ ]);
959
+ const accounts = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
960
+ const authorizationResult = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts, chain: selectedChain });
961
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
962
+ Promise.all([
963
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, capabilities),
964
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorizationResult),
965
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorizationResult),
966
+ ]);
967
+ return authorizationResult;
968
+ }));
969
+ }
970
+ catch (e) {
971
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
972
+ }
973
+ }));
974
+ _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult.set(this, (authorization) => __awaiter(this, void 0, void 0, function* () {
975
+ var _a;
976
+ const didPublicKeysChange =
977
+ // Case 1: We started from having no authorization.
978
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f") == null ||
979
+ // Case 2: The number of authorized accounts changed.
980
+ ((_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorization.accounts.length ||
981
+ // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
982
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
983
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, authorization, "f");
984
+ if (didPublicKeysChange) {
985
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
986
+ }
987
+ }));
988
+ _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult.set(this, (capabilities) => __awaiter(this, void 0, void 0, function* () {
989
+ // TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
990
+ const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
991
+ const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions ||
992
+ capabilities.features.includes('solana:signAndSendTransaction');
993
+ const didCapabilitiesChange = SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
994
+ SolanaSignTransaction in this.features !== supportsSignTransaction;
995
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, Object.assign(Object.assign({}, (supportsSignAndSendTransaction && {
996
+ [SolanaSignAndSendTransaction]: {
997
+ version: '1.0.0',
998
+ supportedTransactionVersions: capabilities.supported_transaction_versions,
999
+ signAndSendTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
1000
+ },
1001
+ })), (supportsSignTransaction && {
1002
+ [SolanaSignTransaction]: {
1003
+ version: '1.0.0',
1004
+ supportedTransactionVersions: capabilities.supported_transaction_versions,
1005
+ signTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, "f"),
1006
+ },
1007
+ })), "f");
1008
+ if (didCapabilitiesChange) {
1009
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { features: this.features });
1010
+ }
1011
+ }));
1012
+ _RemoteSolanaMobileWalletAdapterWallet_performReauthorization.set(this, (wallet, authToken, chain) => __awaiter(this, void 0, void 0, function* () {
1013
+ try {
1014
+ const mwaAuthorizationResult = yield wallet.authorize({
1015
+ auth_token: authToken,
1016
+ identity: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, "f"),
1017
+ });
1018
+ const accounts = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
1019
+ const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts: accounts, chain: chain });
1020
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1021
+ Promise.all([
1022
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
1023
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
1024
+ ]);
1025
+ }
1026
+ catch (e) {
1027
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_disconnect, "f").call(this);
1028
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1029
+ }
1030
+ }));
1031
+ _RemoteSolanaMobileWalletAdapterWallet_disconnect.set(this, () => __awaiter(this, void 0, void 0, function* () {
1032
+ var _b;
1033
+ var _c;
1034
+ (_b = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f")) === null || _b === void 0 ? void 0 : _b.close();
1035
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
1036
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false, "f");
1037
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, (_c = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f"), _c++, _c), "f");
1038
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, undefined, "f");
1039
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, undefined, "f");
1040
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
1041
+ }));
1042
+ _RemoteSolanaMobileWalletAdapterWallet_transact.set(this, (callback) => __awaiter(this, void 0, void 0, function* () {
1043
+ var _d;
1044
+ const walletUriBase = (_d = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _d === void 0 ? void 0 : _d.wallet_uri_base;
1045
+ const baseConfig = walletUriBase ? { baseUri: walletUriBase } : undefined;
1046
+ const remoteConfig = Object.assign(Object.assign({}, baseConfig), { remoteHostAuthority: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, "f") });
1047
+ const currentConnectionGeneration = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f");
1048
+ const modal = new RemoteConnectionModal();
1049
+ if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f")) {
1050
+ return callback(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f").wallet);
1051
+ }
1052
+ try {
1053
+ const { associationUrl, close, wallet } = yield startRemoteScenario(remoteConfig);
1054
+ const removeCloseListener = modal.addEventListener('close', (event) => {
1055
+ if (event)
1056
+ close();
1057
+ });
1058
+ modal.initWithQR(associationUrl.toString());
1059
+ modal.open();
1060
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, { close, wallet: yield wallet }, "f");
1061
+ removeCloseListener();
1062
+ modal.close();
1063
+ return yield callback(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f").wallet);
1064
+ }
1065
+ catch (e) {
1066
+ modal.close();
1067
+ if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f") !== currentConnectionGeneration) {
1068
+ yield new Promise(() => { }); // Never resolve.
1069
+ }
1070
+ if (e instanceof Error &&
1071
+ e.name === 'SolanaMobileWalletAdapterError' &&
1072
+ e.code === 'ERROR_WALLET_NOT_FOUND') {
1073
+ yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, "f").call(this, this);
1074
+ }
1075
+ throw e;
1076
+ }
1077
+ }));
1078
+ _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized.set(this, () => {
1079
+ if (!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f"))
1080
+ throw new Error('Wallet not connected');
1081
+ return { authToken: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").auth_token, chain: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").chain };
1082
+ });
1083
+ _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts.set(this, (accounts) => {
1084
+ return accounts.map((account) => {
1085
+ var _a, _b;
1086
+ const publicKey = toUint8Array(account.address);
1087
+ return {
1088
+ address: base58.encode(publicKey),
1089
+ publicKey,
1090
+ label: account.label,
1091
+ icon: account.icon,
1092
+ chains: (_a = account.chains) !== null && _a !== void 0 ? _a : __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"),
1093
+ // TODO: get supported features from getCapabilities API
1094
+ features: (_b = account.features) !== null && _b !== void 0 ? _b : DEFAULT_FEATURES
1095
+ };
1096
+ });
1097
+ });
1098
+ _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions.set(this, (transactions) => __awaiter(this, void 0, void 0, function* () {
1099
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
1100
+ try {
1101
+ return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
1102
+ yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
1103
+ const signedTransactions = yield wallet.signTransactions({
1104
+ transactions,
1105
+ });
1106
+ return signedTransactions;
1107
+ }));
1108
+ }
1109
+ catch (e) {
1110
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1111
+ }
1112
+ }));
1113
+ _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction.set(this, (transaction, options) => __awaiter(this, void 0, void 0, function* () {
1114
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
1115
+ try {
1116
+ return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
1117
+ const [capabilities, _1] = yield Promise.all([
1118
+ wallet.getCapabilities(),
1119
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain)
1120
+ ]);
1121
+ if (capabilities.supports_sign_and_send_transactions) {
1122
+ const signatures = yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, options), { transactions: [transaction] }));
1123
+ return signatures[0];
1124
+ }
1125
+ else {
1126
+ throw new Error('connected wallet does not support signAndSendTransaction');
1127
+ }
1128
+ }));
1129
+ }
1130
+ catch (e) {
1131
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1132
+ }
1133
+ }));
1134
+ _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
1135
+ const outputs = [];
1136
+ for (const input of inputs) {
1137
+ const transaction = VersionedTransaction.deserialize(input.transaction);
1138
+ const signature = (yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, "f").call(this, transaction, input.options));
1139
+ outputs.push({ signature: base58.decode(signature) });
1140
+ }
1141
+ return outputs;
1142
+ }));
1143
+ _RemoteSolanaMobileWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
1144
+ const transactions = inputs.map(({ transaction }) => VersionedTransaction.deserialize(transaction));
1145
+ const signedTransactions = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions, "f").call(this, transactions);
1146
+ return signedTransactions.map((signedTransaction) => {
1147
+ const serializedTransaction = isVersionedTransaction(signedTransaction)
1148
+ ? signedTransaction.serialize()
1149
+ : new Uint8Array(signedTransaction.serialize({
1150
+ requireAllSignatures: false,
1151
+ verifySignatures: false,
1152
+ }));
1153
+ return { signedTransaction: serializedTransaction };
1154
+ });
1155
+ }));
1156
+ _RemoteSolanaMobileWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
1157
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
1158
+ const addresses = inputs.map(({ account }) => fromUint8Array(account.publicKey));
1159
+ const messages = inputs.map(({ message }) => message);
1160
+ try {
1161
+ return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
1162
+ yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
1163
+ const signedMessages = yield wallet.signMessages({
1164
+ addresses: addresses,
1165
+ payloads: messages,
1166
+ });
1167
+ return signedMessages.map((signedMessage) => {
1168
+ return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
1169
+ });
1170
+ }));
1171
+ }
1172
+ catch (e) {
1173
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1174
+ }
1175
+ }));
1176
+ _RemoteSolanaMobileWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
1177
+ const outputs = [];
1178
+ if (inputs.length > 1) {
1179
+ for (const input of inputs) {
1180
+ outputs.push(yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, input));
1181
+ }
1182
+ }
1183
+ else {
1184
+ return [yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, inputs[0])];
1185
+ }
1186
+ return outputs;
1187
+ }));
1188
+ _RemoteSolanaMobileWalletAdapterWallet_performSignIn.set(this, (input) => __awaiter(this, void 0, void 0, function* () {
1189
+ var _e, _f;
1190
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, true, "f");
1191
+ try {
1192
+ const authorizationResult = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this, Object.assign(Object.assign({}, input), { domain: (_e = input === null || input === void 0 ? void 0 : input.domain) !== null && _e !== void 0 ? _e : window.location.host }));
1193
+ if (!authorizationResult.sign_in_result) {
1194
+ throw new Error("Sign in failed, no sign in result returned by wallet");
1195
+ }
1196
+ const signedInAddress = authorizationResult.sign_in_result.address;
1197
+ const signedInAccount = Object.assign(Object.assign({}, (_f = authorizationResult.accounts.find(acc => acc.address == signedInAddress)) !== null && _f !== void 0 ? _f : {
1198
+ address: signedInAddress
1199
+ }), { publicKey: toUint8Array(signedInAddress) });
1200
+ return {
1201
+ account: signedInAccount,
1202
+ signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
1203
+ signature: toUint8Array(authorizationResult.sign_in_result.signature)
1204
+ };
1205
+ }
1206
+ catch (e) {
1207
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
1208
+ }
1209
+ finally {
1210
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false, "f");
1211
+ }
1212
+ }));
1213
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, config.authorizationCache, "f");
1214
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, config.appIdentity, "f");
1215
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, config.chains, "f");
1216
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, config.chainSelector, "f");
1217
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, config.remoteHostAuthority, "f");
1218
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, config.onWalletNotFound, "f");
1219
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, {
1220
+ // We are forced to provide either SolanaSignAndSendTransaction or SolanaSignTransaction
1221
+ // because the wallet-adapter compatible wallet-standard wallet requires at least one of them.
1222
+ // MWA 2.0+ wallets must implement signAndSend and pre 2.0 wallets have always provided it so
1223
+ // this is a safe assumption. We later update the features after we get the wallets capabilities.
1224
+ [SolanaSignAndSendTransaction]: {
1225
+ version: '1.0.0',
1226
+ supportedTransactionVersions: ['legacy', 0],
1227
+ signAndSendTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
1228
+ },
1229
+ }, "f");
1230
+ }
1231
+ get version() {
1232
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_version, "f");
1233
+ }
1234
+ get name() {
1235
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_name, "f");
1236
+ }
1237
+ get url() {
1238
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_url, "f");
1239
+ }
1240
+ get icon() {
1241
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_icon, "f");
1242
+ }
1243
+ get chains() {
1244
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f");
1245
+ }
1246
+ get features() {
1247
+ return Object.assign({ [StandardConnect]: {
1248
+ version: '1.0.0',
1249
+ connect: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connect, "f"),
1250
+ }, [StandardDisconnect]: {
1251
+ version: '1.0.0',
1252
+ disconnect: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_disconnect, "f"),
1253
+ }, [StandardEvents]: {
1254
+ version: '1.0.0',
1255
+ on: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_on, "f"),
1256
+ }, [SolanaSignMessage]: {
1257
+ version: '1.0.0',
1258
+ signMessage: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signMessage, "f"),
1259
+ }, [SolanaSignIn]: {
1260
+ version: '1.0.0',
1261
+ signIn: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signIn, "f"),
1262
+ } }, __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, "f"));
1263
+ }
1264
+ get accounts() {
1265
+ var _a, _b;
1266
+ return (_b = (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : [];
1267
+ }
1268
+ get connected() {
1269
+ return !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f") && !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
1270
+ }
1271
+ get isAuthorized() {
1272
+ return !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
1273
+ }
1274
+ get currentAuthorization() {
1275
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
1276
+ }
1277
+ get cachedAuthorizationResult() {
1278
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
1279
+ }
1280
+ }
1281
+ _RemoteSolanaMobileWalletAdapterWallet_listeners = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_version = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_name = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_url = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_icon = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_appIdentity = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_authorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_authorizationCache = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connecting = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_chains = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_chainSelector = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_hostAuthority = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_session = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_on = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connect = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performAuthorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performReauthorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_disconnect = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_transact = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signMessage = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signIn = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignIn = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_instances = new WeakSet(), _RemoteSolanaMobileWalletAdapterWallet_emit = function _RemoteSolanaMobileWalletAdapterWallet_emit(event, ...args) {
1282
+ var _a;
1283
+ // eslint-disable-next-line prefer-spread
1284
+ (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener.apply(null, args));
1285
+ }, _RemoteSolanaMobileWalletAdapterWallet_off = function _RemoteSolanaMobileWalletAdapterWallet_off(event, listener) {
1286
+ var _a;
1287
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
1288
+ };
1289
+
1290
+ var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1291
+ if (kind === "m") throw new TypeError("Private method is not writable");
1292
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1293
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1294
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1295
+ };
1296
+ var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1297
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1298
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1299
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1300
+ };
1301
+ var _RegisterWalletEvent_detail;
1302
+ /**
1303
+ * Register a {@link "@wallet-standard/base".Wallet} as a Standard Wallet with the app.
1304
+ *
1305
+ * This dispatches a {@link "@wallet-standard/base".WindowRegisterWalletEvent} to notify the app that the Wallet is
1306
+ * ready to be registered.
1307
+ *
1308
+ * This also adds a listener for {@link "@wallet-standard/base".WindowAppReadyEvent} to listen for a notification from
1309
+ * the app that the app is ready to register the Wallet.
1310
+ *
1311
+ * This combination of event dispatch and listener guarantees that the Wallet will be registered synchronously as soon
1312
+ * as the app is ready whether the Wallet loads before or after the app.
1313
+ *
1314
+ * @param wallet Wallet to register.
1315
+ *
1316
+ * @group Wallet
1317
+ */
1318
+ function registerWallet(wallet) {
1319
+ const callback = ({ register }) => register(wallet);
1320
+ try {
1321
+ window.dispatchEvent(new RegisterWalletEvent(callback));
1322
+ }
1323
+ catch (error) {
1324
+ console.error('wallet-standard:register-wallet event could not be dispatched\n', error);
1325
+ }
1326
+ try {
1327
+ window.addEventListener('wallet-standard:app-ready', ({ detail: api }) => callback(api));
1328
+ }
1329
+ catch (error) {
1330
+ console.error('wallet-standard:app-ready event listener could not be added\n', error);
1331
+ }
1332
+ }
1333
+ class RegisterWalletEvent extends Event {
1334
+ constructor(callback) {
1335
+ super('wallet-standard:register-wallet', {
1336
+ bubbles: false,
1337
+ cancelable: false,
1338
+ composed: false,
1339
+ });
1340
+ _RegisterWalletEvent_detail.set(this, void 0);
1341
+ __classPrivateFieldSet(this, _RegisterWalletEvent_detail, callback, "f");
1342
+ }
1343
+ get detail() {
1344
+ return __classPrivateFieldGet(this, _RegisterWalletEvent_detail, "f");
1345
+ }
1346
+ get type() {
1347
+ return 'wallet-standard:register-wallet';
1348
+ }
1349
+ /** @deprecated */
1350
+ preventDefault() {
1351
+ throw new Error('preventDefault cannot be called');
1352
+ }
1353
+ /** @deprecated */
1354
+ stopImmediatePropagation() {
1355
+ throw new Error('stopImmediatePropagation cannot be called');
1356
+ }
1357
+ /** @deprecated */
1358
+ stopPropagation() {
1359
+ throw new Error('stopPropagation cannot be called');
1360
+ }
1361
+ }
1362
+ _RegisterWalletEvent_detail = new WeakMap();
1363
+
1364
+ (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1365
+ if (kind === "m") throw new TypeError("Private method is not writable");
1366
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1367
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1368
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1369
+ };
1370
+ (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1371
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1372
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1373
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1374
+ };
1375
+
1376
+ function getIsLocalAssociationSupported() {
1377
+ return (typeof window !== 'undefined' &&
1378
+ window.isSecureContext &&
1379
+ typeof document !== 'undefined' &&
1380
+ /android/i.test(navigator.userAgent));
1381
+ }
1382
+ function getIsRemoteAssociationSupported() {
1383
+ return (typeof window !== 'undefined' &&
1384
+ window.isSecureContext &&
1385
+ typeof document !== 'undefined' &&
1386
+ !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
1387
+ }
1388
+
1389
+ function registerMwa(config) {
1390
+ if (getIsLocalAssociationSupported()) {
1391
+ registerWallet(new LocalSolanaMobileWalletAdapterWallet(config));
1392
+ }
1393
+ else if (getIsRemoteAssociationSupported() && config.remoteHostAuthority !== undefined) {
1394
+ registerWallet(new RemoteSolanaMobileWalletAdapterWallet(Object.assign(Object.assign({}, config), { remoteHostAuthority: config.remoteHostAuthority })));
1395
+ }
1396
+ else ;
1397
+ }
1398
+
1399
+ const WALLET_NOT_FOUND_ERROR_MESSAGE = 'To use mobile wallet adapter, you must have a compatible mobile wallet application installed on your device.';
1400
+ 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.';
1401
+ class ErrorModal extends EmbeddedModal {
1402
+ constructor() {
1403
+ super(...arguments);
1404
+ this.contentStyles = css;
1405
+ this.contentHtml = ErrorDialogHtml;
1406
+ }
1407
+ initWithError(error) {
1408
+ super.init();
1409
+ this.populateError(error);
1410
+ }
1411
+ populateError(error) {
1412
+ var _a, _b;
1413
+ const errorMessageElement = (_a = this.dom) === null || _a === void 0 ? void 0 : _a.getElementById('mobile-wallet-adapter-error-message');
1414
+ const actionBtn = (_b = this.dom) === null || _b === void 0 ? void 0 : _b.getElementById('mobile-wallet-adapter-error-action');
1415
+ if (errorMessageElement) {
1416
+ if (error.name === 'SolanaMobileWalletAdapterError') {
1417
+ switch (error.code) {
1418
+ case 'ERROR_WALLET_NOT_FOUND':
1419
+ errorMessageElement.innerHTML = WALLET_NOT_FOUND_ERROR_MESSAGE;
1420
+ if (actionBtn)
1421
+ actionBtn.addEventListener('click', () => {
1422
+ window.location.href = 'https://solanamobile.com/wallets';
1423
+ });
1424
+ return;
1425
+ case 'ERROR_BROWSER_NOT_SUPPORTED':
1426
+ errorMessageElement.innerHTML = BROWSER_NOT_SUPPORTED_ERROR_MESSAGE;
1427
+ if (actionBtn)
1428
+ actionBtn.style.display = 'none';
1429
+ return;
1430
+ }
1431
+ }
1432
+ errorMessageElement.innerHTML = `An unexpected error occurred: ${error.message}`;
1433
+ }
1434
+ else {
1435
+ console.log('Failed to locate error dialog element');
1436
+ }
1437
+ }
1438
+ }
1439
+ const ErrorDialogHtml = `
1440
+ <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>
1441
+ <div class="mobile-wallet-adapter-embedded-modal-title">We can't find a wallet.</div>
1442
+ <div id="mobile-wallet-adapter-error-message" class="mobile-wallet-adapter-embedded-modal-subtitle"></div>
1443
+ <div>
1444
+ <button data-error-action id="mobile-wallet-adapter-error-action" class="mobile-wallet-adapter-embedded-modal-error-action">
1445
+ Find a wallet
1446
+ </button>
1447
+ </div>
1448
+ `;
1449
+ const css = `
1450
+ .mobile-wallet-adapter-embedded-modal-content {
1451
+ text-align: center;
1452
+ }
1453
+
1454
+ .mobile-wallet-adapter-embedded-modal-error-icon {
1455
+ margin-top: 24px;
1456
+ }
1457
+
1458
+ .mobile-wallet-adapter-embedded-modal-title {
1459
+ margin: 18px 100px auto 100px;
1460
+ color: #000000;
1461
+ font-size: 2.75em;
1462
+ font-weight: 600;
1463
+ }
1464
+
1465
+ .mobile-wallet-adapter-embedded-modal-subtitle {
1466
+ margin: 30px 60px 40px 60px;
1467
+ color: #000000;
1468
+ font-size: 1.25em;
1469
+ font-weight: 400;
1470
+ }
1471
+
1472
+ .mobile-wallet-adapter-embedded-modal-error-action {
1473
+ display: block;
1474
+ width: 100%;
1475
+ height: 56px;
1476
+ /*margin-top: 40px;*/
1477
+ font-size: 1.25em;
1478
+ /*line-height: 24px;*/
1479
+ /*letter-spacing: -1%;*/
1480
+ background: #000000;
1481
+ color: #FFFFFF;
1482
+ border-radius: 18px;
1483
+ }
1484
+
1485
+ /* Smaller screens */
1486
+ @media all and (max-width: 600px) {
1487
+ .mobile-wallet-adapter-embedded-modal-title {
1488
+ font-size: 1.5em;
1489
+ margin-right: 12px;
1490
+ margin-left: 12px;
1491
+ }
1492
+ .mobile-wallet-adapter-embedded-modal-subtitle {
1493
+ margin-right: 12px;
1494
+ margin-left: 12px;
1495
+ }
1496
+ }
1497
+ `;
1498
+
1499
+ function defaultErrorModalWalletNotFoundHandler() {
1500
+ return __awaiter(this, void 0, void 0, function* () {
1501
+ if (typeof window !== 'undefined') {
1502
+ const userAgent = window.navigator.userAgent.toLowerCase();
1503
+ const errorDialog = new ErrorModal();
1504
+ if (userAgent.includes('wv')) { // Android WebView
1505
+ // MWA is not supported in this browser so we inform the user
1506
+ // errorDialog.initWithError(
1507
+ // new SolanaMobileWalletAdapterError(
1508
+ // SolanaMobileWalletAdapterErrorCode.ERROR_BROWSER_NOT_SUPPORTED,
1509
+ // ''
1510
+ // )
1511
+ // );
1512
+ // TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
1513
+ errorDialog.initWithError({
1514
+ name: 'SolanaMobileWalletAdapterError',
1515
+ code: 'ERROR_BROWSER_NOT_SUPPORTED',
1516
+ message: ''
1517
+ });
1518
+ }
1519
+ else { // Browser, user does not have a wallet installed.
1520
+ // errorDialog.initWithError(
1521
+ // new SolanaMobileWalletAdapterError(
1522
+ // SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND,
1523
+ // ''
1524
+ // )
1525
+ // );
1526
+ // TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
1527
+ errorDialog.initWithError({
1528
+ name: 'SolanaMobileWalletAdapterError',
1529
+ code: 'ERROR_WALLET_NOT_FOUND',
1530
+ message: ''
1531
+ });
1532
+ }
1533
+ errorDialog.open();
1534
+ }
1535
+ });
1536
+ }
1537
+ function createDefaultWalletNotFoundHandler() {
1538
+ return () => __awaiter(this, void 0, void 0, function* () { defaultErrorModalWalletNotFoundHandler(); });
1539
+ }
1540
+
1541
+ const CACHE_KEY = 'SolanaMobileWalletAdapterDefaultAuthorizationCache';
1542
+ function createDefaultAuthorizationCache() {
1543
+ let storage;
1544
+ try {
1545
+ storage = window.localStorage;
1546
+ // eslint-disable-next-line no-empty
1547
+ }
1548
+ catch (_a) { }
1549
+ return {
1550
+ clear() {
1551
+ return __awaiter(this, void 0, void 0, function* () {
1552
+ if (!storage) {
1553
+ return;
1554
+ }
1555
+ try {
1556
+ storage.removeItem(CACHE_KEY);
1557
+ // eslint-disable-next-line no-empty
1558
+ }
1559
+ catch (_a) { }
1560
+ });
1561
+ },
1562
+ get() {
1563
+ return __awaiter(this, void 0, void 0, function* () {
1564
+ if (!storage) {
1565
+ return;
1566
+ }
1567
+ try {
1568
+ const parsed = JSON.parse(storage.getItem(CACHE_KEY));
1569
+ if (parsed && parsed.accounts) {
1570
+ const parsedAccounts = parsed.accounts.map((account) => {
1571
+ return Object.assign(Object.assign({}, account), { publicKey: 'publicKey' in account
1572
+ ? new Uint8Array(Object.values(account.publicKey)) // Rebuild publicKey for WalletAccount
1573
+ : new PublicKey(account.address).toBytes() });
1574
+ });
1575
+ return Object.assign(Object.assign({}, parsed), { accounts: parsedAccounts });
1576
+ }
1577
+ else
1578
+ return parsed || undefined;
1579
+ // eslint-disable-next-line no-empty
1580
+ }
1581
+ catch (_a) { }
1582
+ });
1583
+ },
1584
+ set(authorizationResult) {
1585
+ return __awaiter(this, void 0, void 0, function* () {
1586
+ if (!storage) {
1587
+ return;
1588
+ }
1589
+ try {
1590
+ storage.setItem(CACHE_KEY, JSON.stringify(authorizationResult));
1591
+ // eslint-disable-next-line no-empty
1592
+ }
1593
+ catch (_a) { }
1594
+ });
1595
+ },
1596
+ };
1597
+ }
1598
+
1599
+ function createDefaultChainSelector() {
1600
+ return {
1601
+ select(chains) {
1602
+ return __awaiter(this, void 0, void 0, function* () {
1603
+ if (chains.length === 1) {
1604
+ return chains[0];
1605
+ }
1606
+ else if (chains.includes(SOLANA_MAINNET_CHAIN)) {
1607
+ return SOLANA_MAINNET_CHAIN;
1608
+ }
1609
+ else
1610
+ return chains[0];
1611
+ });
1612
+ },
1613
+ };
1614
+ }
1615
+
1616
+ export { LocalSolanaMobileWalletAdapterWallet, RemoteSolanaMobileWalletAdapterWallet, SolanaMobileWalletAdapterWalletName, createDefaultAuthorizationCache, createDefaultChainSelector, createDefaultWalletNotFoundHandler, defaultErrorModalWalletNotFoundHandler, registerMwa };