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