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