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