@solana-mobile/wallet-adapter-mobile 2.1.5 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -119
- package/lib/cjs/index.browser.js +355 -1180
- package/lib/cjs/index.js +355 -1180
- package/lib/cjs/index.native.js +352 -1126
- package/lib/esm/index.browser.js +356 -1177
- package/lib/esm/index.js +356 -1177
- package/lib/types/index.browser.d.ts +32 -100
- package/lib/types/index.browser.d.ts.map +1 -1
- package/lib/types/index.d.ts +32 -100
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.native.d.ts +32 -100
- package/lib/types/index.native.d.ts.map +1 -1
- package/package.json +31 -20
package/lib/cjs/index.browser.js
CHANGED
|
@@ -4,13 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var walletAdapterBase = require('@solana/wallet-adapter-base');
|
|
6
6
|
var web3_js = require('@solana/web3.js');
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var jsBase64 = require('js-base64');
|
|
10
|
-
|
|
11
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
-
|
|
13
|
-
var QRCode__default = /*#__PURE__*/_interopDefaultLegacy(QRCode);
|
|
7
|
+
var walletStandardFeatures = require('@solana/wallet-standard-features');
|
|
8
|
+
var walletStandardMobile = require('@solana-mobile/wallet-standard-mobile');
|
|
14
9
|
|
|
15
10
|
/******************************************************************************
|
|
16
11
|
Copyright (c) Microsoft Corporation.
|
|
@@ -35,111 +30,166 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
35
30
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
36
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
37
32
|
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
36
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
37
|
+
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");
|
|
38
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
42
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
43
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
44
|
+
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");
|
|
45
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
38
46
|
}
|
|
39
47
|
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
(undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
49
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
50
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
51
|
+
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");
|
|
52
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
53
|
+
};
|
|
54
|
+
(undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
55
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
56
|
+
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");
|
|
57
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Name of the feature. */
|
|
61
|
+
const StandardConnect = 'standard:connect';
|
|
62
|
+
|
|
63
|
+
/** Name of the feature. */
|
|
64
|
+
const StandardDisconnect = 'standard:disconnect';
|
|
65
|
+
|
|
66
|
+
/** Name of the feature. */
|
|
67
|
+
const StandardEvents = 'standard:events';
|
|
68
|
+
|
|
69
|
+
(undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
70
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
71
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
72
|
+
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");
|
|
73
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
74
|
+
};
|
|
75
|
+
(undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
76
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
77
|
+
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");
|
|
78
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
(undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
82
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
83
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
84
|
+
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");
|
|
85
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
86
|
+
};
|
|
87
|
+
(undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
88
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
89
|
+
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");
|
|
90
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
function fromUint8Array(byteArray) {
|
|
94
|
+
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
45
95
|
}
|
|
46
96
|
|
|
47
|
-
function getIsSupported
|
|
97
|
+
function getIsSupported() {
|
|
48
98
|
return (typeof window !== 'undefined' &&
|
|
49
99
|
window.isSecureContext &&
|
|
50
100
|
typeof document !== 'undefined' &&
|
|
51
101
|
/android/i.test(navigator.userAgent));
|
|
52
102
|
}
|
|
53
103
|
|
|
104
|
+
var _BaseSolanaMobileWalletAdapter_instances, _BaseSolanaMobileWalletAdapter_wallet, _BaseSolanaMobileWalletAdapter_connecting, _BaseSolanaMobileWalletAdapter_readyState, _BaseSolanaMobileWalletAdapter_accountSelector, _BaseSolanaMobileWalletAdapter_selectedAccount, _BaseSolanaMobileWalletAdapter_publicKey, _BaseSolanaMobileWalletAdapter_handleChangeEvent, _BaseSolanaMobileWalletAdapter_connect, _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled, _BaseSolanaMobileWalletAdapter_assertIsAuthorized, _BaseSolanaMobileWalletAdapter_performSignTransactions, _BaseSolanaMobileWalletAdapter_runWithGuard;
|
|
54
105
|
const SolanaMobileWalletAdapterWalletName = 'Mobile Wallet Adapter';
|
|
55
|
-
const SIGNATURE_LENGTH_IN_BYTES
|
|
56
|
-
function getPublicKeyFromAddress$1(address) {
|
|
57
|
-
const publicKeyByteArray = toUint8Array(address);
|
|
58
|
-
return new web3_js.PublicKey(publicKeyByteArray);
|
|
59
|
-
}
|
|
106
|
+
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
60
107
|
function isVersionedTransaction(transaction) {
|
|
61
108
|
return 'version' in transaction;
|
|
62
109
|
}
|
|
63
|
-
function
|
|
64
|
-
switch (
|
|
110
|
+
function chainOrClusterToChainId(chain) {
|
|
111
|
+
switch (chain) {
|
|
65
112
|
case 'mainnet-beta':
|
|
66
113
|
return 'solana:mainnet';
|
|
67
114
|
case 'testnet':
|
|
68
115
|
return 'solana:testnet';
|
|
69
116
|
case 'devnet':
|
|
70
117
|
return 'solana:devnet';
|
|
118
|
+
default:
|
|
119
|
+
return chain;
|
|
71
120
|
}
|
|
72
121
|
}
|
|
73
|
-
class
|
|
74
|
-
constructor(config) {
|
|
75
|
-
var _a;
|
|
122
|
+
class BaseSolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageSignerWalletAdapter {
|
|
123
|
+
constructor(wallet, config) {
|
|
76
124
|
super();
|
|
125
|
+
_BaseSolanaMobileWalletAdapter_instances.add(this);
|
|
77
126
|
this.supportedTransactionVersions = new Set(
|
|
78
127
|
// FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
|
|
79
128
|
['legacy', 0]);
|
|
80
|
-
this
|
|
81
|
-
this
|
|
82
|
-
this.
|
|
83
|
-
this
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (this._readyState !== walletAdapterBase.WalletReadyState.Unsupported) {
|
|
98
|
-
this._authorizationResultCache.get().then((authorizationResult) => {
|
|
99
|
-
if (authorizationResult) {
|
|
100
|
-
// Having a prior authorization result is, right now, the best
|
|
101
|
-
// indication that a mobile wallet is installed. There is no API
|
|
102
|
-
// we can use to test for whether the association URI is supported.
|
|
103
|
-
this.declareWalletAsInstalled();
|
|
129
|
+
_BaseSolanaMobileWalletAdapter_wallet.set(this, void 0);
|
|
130
|
+
_BaseSolanaMobileWalletAdapter_connecting.set(this, false);
|
|
131
|
+
_BaseSolanaMobileWalletAdapter_readyState.set(this, getIsSupported() ? walletAdapterBase.WalletReadyState.Loadable : walletAdapterBase.WalletReadyState.Unsupported);
|
|
132
|
+
_BaseSolanaMobileWalletAdapter_accountSelector.set(this, void 0);
|
|
133
|
+
_BaseSolanaMobileWalletAdapter_selectedAccount.set(this, void 0);
|
|
134
|
+
_BaseSolanaMobileWalletAdapter_publicKey.set(this, void 0);
|
|
135
|
+
_BaseSolanaMobileWalletAdapter_handleChangeEvent.set(this, (properties) => __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
if (properties.accounts && properties.accounts.length > 0) {
|
|
137
|
+
__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled).call(this);
|
|
138
|
+
const nextSelectedAccount = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_accountSelector, "f").call(this, properties.accounts);
|
|
139
|
+
if (nextSelectedAccount !== __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f")) {
|
|
140
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, nextSelectedAccount, "f");
|
|
141
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, undefined, "f");
|
|
142
|
+
this.emit('connect',
|
|
143
|
+
// Having just set `this.#selectedAccount`, `this.publicKey` is definitely non-null
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
145
|
+
this.publicKey);
|
|
104
146
|
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
147
|
+
}
|
|
148
|
+
}));
|
|
149
|
+
// this.#chain = chainOrClusterToChainId(config.chain);
|
|
150
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_accountSelector, (accounts) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
var _a;
|
|
152
|
+
const selectedBase64EncodedAddress = yield config.addressSelector.select(accounts.map(({ publicKey }) => fromUint8Array(publicKey)));
|
|
153
|
+
return (_a = accounts.find(({ publicKey }) => fromUint8Array(publicKey) === selectedBase64EncodedAddress)) !== null && _a !== void 0 ? _a : accounts[0];
|
|
154
|
+
}), "f");
|
|
155
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_wallet, wallet, "f");
|
|
156
|
+
__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardEvents].on('change', __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_handleChangeEvent, "f"));
|
|
157
|
+
this.name = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").name;
|
|
158
|
+
this.icon = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").icon;
|
|
159
|
+
this.url = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").url;
|
|
160
|
+
// TODO: evaluate if this logic should be kept - it seems to create a nasty bug where
|
|
161
|
+
// the wallet tries to auto connect on page load and gets blocked by the popup blocker
|
|
162
|
+
// if (this.#readyState !== WalletReadyState.Unsupported) {
|
|
163
|
+
// config.authorizationResultCache.get().then((authorizationResult) => {
|
|
164
|
+
// if (authorizationResult) {
|
|
165
|
+
// // Having a prior authorization result is, right now, the best
|
|
166
|
+
// // indication that a mobile wallet is installed. There is no API
|
|
167
|
+
// // we can use to test for whether the association URI is supported.
|
|
168
|
+
// this.#declareWalletAsInstalled();
|
|
169
|
+
// }
|
|
170
|
+
// });
|
|
171
|
+
// }
|
|
107
172
|
}
|
|
108
173
|
get publicKey() {
|
|
109
|
-
|
|
174
|
+
var _a;
|
|
175
|
+
if (!__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_publicKey, "f") && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f")) {
|
|
110
176
|
try {
|
|
111
|
-
this
|
|
177
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, new web3_js.PublicKey(__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f").publicKey), "f");
|
|
112
178
|
}
|
|
113
179
|
catch (e) {
|
|
114
180
|
throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
|
|
115
181
|
}
|
|
116
182
|
}
|
|
117
|
-
return this
|
|
183
|
+
return (_a = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_publicKey, "f")) !== null && _a !== void 0 ? _a : null;
|
|
118
184
|
}
|
|
119
185
|
get connected() {
|
|
120
|
-
return
|
|
186
|
+
return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").connected;
|
|
121
187
|
}
|
|
122
188
|
get connecting() {
|
|
123
|
-
return this
|
|
189
|
+
return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_connecting, "f");
|
|
124
190
|
}
|
|
125
191
|
get readyState() {
|
|
126
|
-
return this
|
|
127
|
-
}
|
|
128
|
-
declareWalletAsInstalled() {
|
|
129
|
-
if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
|
|
130
|
-
this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
runWithGuard(callback) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
try {
|
|
136
|
-
return yield callback();
|
|
137
|
-
}
|
|
138
|
-
catch (e) {
|
|
139
|
-
this.emit('error', e);
|
|
140
|
-
throw e;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
192
|
+
return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f");
|
|
143
193
|
}
|
|
144
194
|
/** @deprecated Use `autoConnect()` instead. */
|
|
145
195
|
autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
|
|
@@ -149,1066 +199,154 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageSigne
|
|
|
149
199
|
}
|
|
150
200
|
autoConnect() {
|
|
151
201
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
|
|
157
|
-
throw new walletAdapterBase.WalletNotReadyError();
|
|
158
|
-
}
|
|
159
|
-
this._connecting = true;
|
|
160
|
-
try {
|
|
161
|
-
const cachedAuthorizationResult = yield this._authorizationResultCache.get();
|
|
162
|
-
if (cachedAuthorizationResult) {
|
|
163
|
-
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
164
|
-
this.handleAuthorizationResult(cachedAuthorizationResult);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
catch (e) {
|
|
168
|
-
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
169
|
-
}
|
|
170
|
-
finally {
|
|
171
|
-
this._connecting = false;
|
|
172
|
-
}
|
|
173
|
-
}));
|
|
202
|
+
__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_connect).call(this, true);
|
|
174
203
|
});
|
|
175
204
|
}
|
|
176
205
|
connect() {
|
|
177
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
-
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
|
|
182
|
-
if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
|
|
183
|
-
throw new walletAdapterBase.WalletNotReadyError();
|
|
184
|
-
}
|
|
185
|
-
this._connecting = true;
|
|
186
|
-
try {
|
|
187
|
-
yield this.performAuthorization();
|
|
188
|
-
}
|
|
189
|
-
catch (e) {
|
|
190
|
-
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
191
|
-
}
|
|
192
|
-
finally {
|
|
193
|
-
this._connecting = false;
|
|
194
|
-
}
|
|
195
|
-
}));
|
|
207
|
+
__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_connect).call(this);
|
|
196
208
|
});
|
|
197
209
|
}
|
|
210
|
+
/** @deprecated Use `connect()` or `autoConnect()` instead. */
|
|
198
211
|
performAuthorization(signInPayload) {
|
|
199
212
|
return __awaiter(this, void 0, void 0, function* () {
|
|
200
213
|
try {
|
|
201
|
-
const cachedAuthorizationResult = yield this.
|
|
214
|
+
const cachedAuthorizationResult = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").cachedAuthorizationResult;
|
|
202
215
|
if (cachedAuthorizationResult) {
|
|
203
|
-
|
|
204
|
-
this.handleAuthorizationResult(cachedAuthorizationResult);
|
|
216
|
+
yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect({ silent: true });
|
|
205
217
|
return cachedAuthorizationResult;
|
|
206
218
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
chain: this._chain,
|
|
210
|
-
identity: this._appIdentity,
|
|
211
|
-
sign_in_payload: signInPayload,
|
|
212
|
-
});
|
|
213
|
-
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
214
|
-
Promise.all([
|
|
215
|
-
this._authorizationResultCache.set(authorizationResult),
|
|
216
|
-
this.handleAuthorizationResult(authorizationResult),
|
|
217
|
-
]);
|
|
218
|
-
return authorizationResult;
|
|
219
|
-
}));
|
|
220
|
-
}
|
|
221
|
-
catch (e) {
|
|
222
|
-
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
handleAuthorizationResult(authorizationResult) {
|
|
227
|
-
var _a;
|
|
228
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
-
const didPublicKeysChange =
|
|
230
|
-
// Case 1: We started from having no authorization.
|
|
231
|
-
this._authorizationResult == null ||
|
|
232
|
-
// Case 2: The number of authorized accounts changed.
|
|
233
|
-
((_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorizationResult.accounts.length ||
|
|
234
|
-
// Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
|
|
235
|
-
this._authorizationResult.accounts.some((account, ii) => account.address !== authorizationResult.accounts[ii].address);
|
|
236
|
-
this._authorizationResult = authorizationResult;
|
|
237
|
-
this.declareWalletAsInstalled();
|
|
238
|
-
if (didPublicKeysChange) {
|
|
239
|
-
const nextSelectedAddress = yield this._addressSelector.select(authorizationResult.accounts.map(({ address }) => address));
|
|
240
|
-
if (nextSelectedAddress !== this._selectedAddress) {
|
|
241
|
-
this._selectedAddress = nextSelectedAddress;
|
|
242
|
-
delete this._publicKey;
|
|
243
|
-
this.emit('connect',
|
|
244
|
-
// Having just set `this._selectedAddress`, `this.publicKey` is definitely non-null
|
|
245
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
246
|
-
this.publicKey);
|
|
219
|
+
if (signInPayload) {
|
|
220
|
+
yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignIn].signIn(signInPayload);
|
|
247
221
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
-
try {
|
|
254
|
-
const authorizationResult = yield wallet.authorize({
|
|
255
|
-
auth_token: authToken,
|
|
256
|
-
identity: this._appIdentity,
|
|
257
|
-
});
|
|
258
|
-
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
259
|
-
Promise.all([
|
|
260
|
-
this._authorizationResultCache.set(authorizationResult),
|
|
261
|
-
this.handleAuthorizationResult(authorizationResult),
|
|
262
|
-
]);
|
|
222
|
+
else
|
|
223
|
+
yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect();
|
|
224
|
+
const authorizationResult = yield yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").cachedAuthorizationResult;
|
|
225
|
+
return authorizationResult;
|
|
263
226
|
}
|
|
264
227
|
catch (e) {
|
|
265
|
-
|
|
266
|
-
throw new walletAdapterBase.WalletDisconnectedError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
|
|
228
|
+
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
267
229
|
}
|
|
268
230
|
});
|
|
269
231
|
}
|
|
270
232
|
disconnect() {
|
|
271
233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
-
this.
|
|
273
|
-
this.
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
transact(callback) {
|
|
282
|
-
var _a;
|
|
283
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
-
const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.wallet_uri_base;
|
|
285
|
-
const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
|
|
286
|
-
const remoteConfig = this._hostAuthority ? { remoteHostAuthority: this._hostAuthority } : undefined;
|
|
287
|
-
const currentConnectionGeneration = this._connectionGeneration;
|
|
288
|
-
try {
|
|
289
|
-
return yield mobileWalletAdapterProtocolWeb3js.transact(callback, Object.assign(Object.assign({}, config), remoteConfig));
|
|
290
|
-
}
|
|
291
|
-
catch (e) {
|
|
292
|
-
if (this._connectionGeneration !== currentConnectionGeneration) {
|
|
293
|
-
yield new Promise(() => { }); // Never resolve.
|
|
294
|
-
}
|
|
295
|
-
if (e instanceof Error &&
|
|
296
|
-
e.name === 'SolanaMobileWalletAdapterError' &&
|
|
297
|
-
e.code === 'ERROR_WALLET_NOT_FOUND') {
|
|
298
|
-
yield this._onWalletNotFound(this);
|
|
299
|
-
}
|
|
300
|
-
throw e;
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
assertIsAuthorized() {
|
|
305
|
-
if (!this._authorizationResult || !this._selectedAddress)
|
|
306
|
-
throw new walletAdapterBase.WalletNotConnectedError();
|
|
307
|
-
return {
|
|
308
|
-
authToken: this._authorizationResult.auth_token,
|
|
309
|
-
selectedAddress: this._selectedAddress,
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
performSignTransactions(transactions) {
|
|
313
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
314
|
-
const { authToken } = this.assertIsAuthorized();
|
|
315
|
-
try {
|
|
316
|
-
return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
317
|
-
yield this.performReauthorization(wallet, authToken);
|
|
318
|
-
const signedTransactions = yield wallet.signTransactions({
|
|
319
|
-
transactions,
|
|
320
|
-
});
|
|
321
|
-
return signedTransactions;
|
|
322
|
-
}));
|
|
323
|
-
}
|
|
324
|
-
catch (error) {
|
|
325
|
-
throw new walletAdapterBase.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
sendTransaction(transaction, connection, options) {
|
|
330
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
-
return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
|
|
332
|
-
const { authToken } = this.assertIsAuthorized();
|
|
333
|
-
const minContextSlot = options === null || options === void 0 ? void 0 : options.minContextSlot;
|
|
334
|
-
try {
|
|
335
|
-
return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
336
|
-
function getTargetCommitment() {
|
|
337
|
-
let targetCommitment;
|
|
338
|
-
switch (connection.commitment) {
|
|
339
|
-
case 'confirmed':
|
|
340
|
-
case 'finalized':
|
|
341
|
-
case 'processed':
|
|
342
|
-
targetCommitment = connection.commitment;
|
|
343
|
-
break;
|
|
344
|
-
default:
|
|
345
|
-
targetCommitment = 'finalized';
|
|
346
|
-
}
|
|
347
|
-
let targetPreflightCommitment;
|
|
348
|
-
switch (options === null || options === void 0 ? void 0 : options.preflightCommitment) {
|
|
349
|
-
case 'confirmed':
|
|
350
|
-
case 'finalized':
|
|
351
|
-
case 'processed':
|
|
352
|
-
targetPreflightCommitment = options.preflightCommitment;
|
|
353
|
-
break;
|
|
354
|
-
case undefined:
|
|
355
|
-
targetPreflightCommitment = targetCommitment;
|
|
356
|
-
break;
|
|
357
|
-
default:
|
|
358
|
-
targetPreflightCommitment = 'finalized';
|
|
359
|
-
}
|
|
360
|
-
const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
|
|
361
|
-
? 2
|
|
362
|
-
: targetPreflightCommitment === 'confirmed'
|
|
363
|
-
? 1
|
|
364
|
-
: 0;
|
|
365
|
-
const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
|
|
366
|
-
return preflightCommitmentScore < targetCommitmentScore
|
|
367
|
-
? targetPreflightCommitment
|
|
368
|
-
: targetCommitment;
|
|
369
|
-
}
|
|
370
|
-
const [capabilities, _1, _2] = yield Promise.all([
|
|
371
|
-
wallet.getCapabilities(),
|
|
372
|
-
this.performReauthorization(wallet, authToken),
|
|
373
|
-
isVersionedTransaction(transaction)
|
|
374
|
-
? null
|
|
375
|
-
: /**
|
|
376
|
-
* Unlike versioned transactions, legacy `Transaction` objects
|
|
377
|
-
* may not have an associated `feePayer` or `recentBlockhash`.
|
|
378
|
-
* This code exists to patch them up in case they are missing.
|
|
379
|
-
*/
|
|
380
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
381
|
-
var _a;
|
|
382
|
-
transaction.feePayer || (transaction.feePayer = (_a = this.publicKey) !== null && _a !== void 0 ? _a : undefined);
|
|
383
|
-
if (transaction.recentBlockhash == null) {
|
|
384
|
-
const { blockhash } = yield connection.getLatestBlockhash({
|
|
385
|
-
commitment: getTargetCommitment(),
|
|
386
|
-
});
|
|
387
|
-
transaction.recentBlockhash = blockhash;
|
|
388
|
-
}
|
|
389
|
-
}))(),
|
|
390
|
-
]);
|
|
391
|
-
if (capabilities.supports_sign_and_send_transactions) {
|
|
392
|
-
const signatures = yield wallet.signAndSendTransactions({
|
|
393
|
-
minContextSlot,
|
|
394
|
-
transactions: [transaction],
|
|
395
|
-
});
|
|
396
|
-
return signatures[0];
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
const [signedTransaction] = yield wallet.signTransactions({
|
|
400
|
-
transactions: [transaction],
|
|
401
|
-
});
|
|
402
|
-
if (isVersionedTransaction(signedTransaction)) {
|
|
403
|
-
return yield connection.sendTransaction(signedTransaction);
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
const serializedTransaction = signedTransaction.serialize();
|
|
407
|
-
return yield connection.sendRawTransaction(serializedTransaction, Object.assign(Object.assign({}, options), { preflightCommitment: getTargetCommitment() }));
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}));
|
|
411
|
-
}
|
|
412
|
-
catch (error) {
|
|
413
|
-
throw new walletAdapterBase.WalletSendTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
|
|
414
|
-
}
|
|
415
|
-
}));
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
signTransaction(transaction) {
|
|
419
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
420
|
-
return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
|
|
421
|
-
const [signedTransaction] = yield this.performSignTransactions([transaction]);
|
|
422
|
-
return signedTransaction;
|
|
423
|
-
}));
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
signAllTransactions(transactions) {
|
|
427
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
428
|
-
return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
|
|
429
|
-
const signedTransactions = yield this.performSignTransactions(transactions);
|
|
430
|
-
return signedTransactions;
|
|
431
|
-
}));
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
signMessage(message) {
|
|
435
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
436
|
-
return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
|
|
437
|
-
const { authToken, selectedAddress } = this.assertIsAuthorized();
|
|
438
|
-
try {
|
|
439
|
-
return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
440
|
-
yield this.performReauthorization(wallet, authToken);
|
|
441
|
-
const [signedMessage] = yield wallet.signMessages({
|
|
442
|
-
addresses: [selectedAddress],
|
|
443
|
-
payloads: [message],
|
|
444
|
-
});
|
|
445
|
-
const signature = signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES$1);
|
|
446
|
-
return signature;
|
|
447
|
-
}));
|
|
448
|
-
}
|
|
449
|
-
catch (error) {
|
|
450
|
-
throw new walletAdapterBase.WalletSignMessageError(error === null || error === void 0 ? void 0 : error.message, error);
|
|
451
|
-
}
|
|
234
|
+
// return await this.#runWithGuard(this.#wallet.features[StandardDisconnect].disconnect);
|
|
235
|
+
return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
236
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, false, "f");
|
|
237
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, undefined, "f");
|
|
238
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, undefined, "f");
|
|
239
|
+
yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardDisconnect].disconnect();
|
|
240
|
+
this.emit('disconnect');
|
|
452
241
|
}));
|
|
453
242
|
});
|
|
454
243
|
}
|
|
455
244
|
signIn(input) {
|
|
456
245
|
return __awaiter(this, void 0, void 0, function* () {
|
|
457
|
-
return
|
|
458
|
-
var _a
|
|
459
|
-
if (this
|
|
246
|
+
return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
247
|
+
var _a;
|
|
248
|
+
if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Installed && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Loadable) {
|
|
460
249
|
throw new walletAdapterBase.WalletNotReadyError();
|
|
461
250
|
}
|
|
462
|
-
this
|
|
251
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, true, "f");
|
|
463
252
|
try {
|
|
464
|
-
const
|
|
465
|
-
if (
|
|
466
|
-
|
|
253
|
+
const outputs = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignIn].signIn(Object.assign(Object.assign({}, input), { domain: (_a = input === null || input === void 0 ? void 0 : input.domain) !== null && _a !== void 0 ? _a : window.location.host }));
|
|
254
|
+
if (outputs.length > 0) {
|
|
255
|
+
return outputs[0];
|
|
467
256
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
address: signedInAddress
|
|
471
|
-
}), { publicKey: toUint8Array(signedInAddress) });
|
|
472
|
-
return {
|
|
473
|
-
account: signedInAccount,
|
|
474
|
-
signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
|
|
475
|
-
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
catch (e) {
|
|
479
|
-
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
480
|
-
}
|
|
481
|
-
finally {
|
|
482
|
-
this._connecting = false;
|
|
483
|
-
}
|
|
484
|
-
}));
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
const BluetoothHtml = `
|
|
490
|
-
<div class="mobile-wallet-adapter-embedded-modal-content">
|
|
491
|
-
<button id="mobile-wallet-adapter-embedded-modal-close" class="mobile-wallet-adapter-embedded-modal-close">
|
|
492
|
-
<svg width="14" height="14">
|
|
493
|
-
<path d="M14 12.461 8.3 6.772l5.234-5.233L12.006 0 6.772 5.234 1.54 0 0 1.539l5.234 5.233L0 12.006l1.539 1.528L6.772 8.3l5.69 5.7L14 12.461z" />
|
|
494
|
-
</svg>
|
|
495
|
-
</button>
|
|
496
|
-
<h1><b>Jupiter</b> wants to connect</h1>
|
|
497
|
-
<p class="mobile-wallet-adapter-embedded-modal-subtitle">Connect to your mobile wallet app through Bluetooth.</p>
|
|
498
|
-
<div class="mobile-wallet-adapter-embedded-modal-connection-status-container">
|
|
499
|
-
<div id="status-not-connected" class="connection-status">
|
|
500
|
-
<svg class="bluetooth-icon" width="24" height="24" viewBox="0 0 24 24">
|
|
501
|
-
<path fill="#a0a0a0" d="M14.24 12.01l2.32 2.32c.28-.72.44-1.51.44-2.33 0-.82-.16-1.59-.43-2.31l-2.33 2.32zm5.29-5.3l-1.26 1.26c.63 1.21.98 2.57.98 4.02s-.36 2.82-.98 4.02l1.2 1.2c.97-1.54 1.54-3.36 1.54-5.31-.01-1.89-.55-3.67-1.48-5.19zm-3.82 1L10 2H9v7.59L4.41 5 3 6.41 8.59 12 3 17.59 4.41 19 9 14.41V22h1l5.71-5.71-4.3-4.29 4.3-4.29zM11 5.83l1.88 1.88L11 9.59V5.83zm1.88 10.46L11 18.17v-3.76l1.88 1.88z"/>
|
|
502
|
-
</svg>
|
|
503
|
-
<p>Not connected</p>
|
|
504
|
-
</div>
|
|
505
|
-
<div id="status-connecting" class="connection-status" style="display:none;">
|
|
506
|
-
<div class="spinner"></div>
|
|
507
|
-
<p>Connecting...</p>
|
|
508
|
-
</div>
|
|
509
|
-
<div id="status-connected" class="connection-status" style="display:none;">
|
|
510
|
-
<svg class="checkmark-icon" width="24" height="24" viewBox="0 0 24 24">
|
|
511
|
-
<path fill="#4CAF50" d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/>
|
|
512
|
-
</svg>
|
|
513
|
-
<p>Connected</p>
|
|
514
|
-
</div>
|
|
515
|
-
</div>
|
|
516
|
-
<div class="button-group">
|
|
517
|
-
<button id="cancel-btn" class="cancel-btn">Cancel</button>
|
|
518
|
-
<button id="connect-btn" class="connect-btn">Connect</button>
|
|
519
|
-
</div>
|
|
520
|
-
</div>
|
|
521
|
-
`;
|
|
522
|
-
|
|
523
|
-
const QRCodeHtml = `
|
|
524
|
-
<div class="mobile-wallet-adapter-embedded-modal-content">
|
|
525
|
-
<button id="mobile-wallet-adapter-embedded-modal-close" class="mobile-wallet-adapter-embedded-modal-close">
|
|
526
|
-
<svg width="14" height="14">
|
|
527
|
-
<path d="M14 12.461 8.3 6.772l5.234-5.233L12.006 0 6.772 5.234 1.54 0 0 1.539l5.234 5.233L0 12.006l1.539 1.528L6.772 8.3l5.69 5.7L14 12.461z" />
|
|
528
|
-
</svg>
|
|
529
|
-
</button>
|
|
530
|
-
<h1>Scan to connect</h1>
|
|
531
|
-
<p class="mobile-wallet-adapter-embedded-modal-subtitle">Use your wallet app to scan the QR Code and connect.</p>
|
|
532
|
-
<div id="mobile-wallet-adapter-embedded-modal-qr-code-container" />
|
|
533
|
-
</div>
|
|
534
|
-
`;
|
|
535
|
-
|
|
536
|
-
const css = `
|
|
537
|
-
.mobile-wallet-adapter-embedded-modal {
|
|
538
|
-
display: flex; /* Use flexbox to center content */
|
|
539
|
-
flex-direction: column;
|
|
540
|
-
justify-content: center; /* Center horizontally */
|
|
541
|
-
align-items: center; /* Center vertically */
|
|
542
|
-
position: fixed; /* Stay in place */
|
|
543
|
-
z-index: 1; /* Sit on top */
|
|
544
|
-
left: 0;
|
|
545
|
-
top: 0;
|
|
546
|
-
width: 100%; /* Full width */
|
|
547
|
-
height: 100%; /* Full height */
|
|
548
|
-
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
.mobile-wallet-adapter-embedded-modal-content {
|
|
552
|
-
background: #10141f;
|
|
553
|
-
padding: 20px;
|
|
554
|
-
border-radius: 10px;
|
|
555
|
-
width: 80%;
|
|
556
|
-
max-width: 500px;
|
|
557
|
-
text-align: center;
|
|
558
|
-
position: relative;
|
|
559
|
-
display: flex;
|
|
560
|
-
flex-direction: column;
|
|
561
|
-
align-items: center; /* Center children horizontally */
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
.mobile-wallet-adapter-embedded-modal-subtitle {
|
|
565
|
-
color: #D8D8D8;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
.mobile-wallet-adapter-embedded-modal-close {
|
|
569
|
-
display: flex;
|
|
570
|
-
align-items: center;
|
|
571
|
-
justify-content: center;
|
|
572
|
-
position: absolute;
|
|
573
|
-
top: 18px;
|
|
574
|
-
right: 18px;
|
|
575
|
-
padding: 12px;
|
|
576
|
-
cursor: pointer;
|
|
577
|
-
background: #1a1f2e;
|
|
578
|
-
border: none;
|
|
579
|
-
border-radius: 50%;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
.mobile-wallet-adapter-embedded-modal-close:focus-visible {
|
|
583
|
-
outline-color: white;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
.mobile-wallet-adapter-embedded-modal-close svg {
|
|
587
|
-
fill: #777;
|
|
588
|
-
transition: fill 200ms ease 0s;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
.mobile-wallet-adapter-embedded-modal-close:hover svg {
|
|
592
|
-
fill: #fff;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
.icon-container {
|
|
596
|
-
display: flex;
|
|
597
|
-
justify-content: center;
|
|
598
|
-
margin-bottom: 20px;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
.icon {
|
|
602
|
-
width: 80px;
|
|
603
|
-
height: 80px;
|
|
604
|
-
border-radius: 50%;
|
|
605
|
-
background-color: #ddd; /* Placeholder for icon background */
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
/* Modal Title */
|
|
609
|
-
.mobile-wallet-adapter-embedded-modal-content h1 {
|
|
610
|
-
color: white;
|
|
611
|
-
font-size: 24px;
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
.button-group {
|
|
615
|
-
display: flex;
|
|
616
|
-
width: 100%;
|
|
617
|
-
gap: 10px;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
.connect-btn, .cancel-btn {
|
|
621
|
-
flex: 1;
|
|
622
|
-
padding: 12px 20px;
|
|
623
|
-
font-size: 16px;
|
|
624
|
-
cursor: pointer;
|
|
625
|
-
border-radius: 10px;
|
|
626
|
-
transition: all 0.3s ease;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
.connect-btn {
|
|
630
|
-
background-color: #007bff;
|
|
631
|
-
color: white;
|
|
632
|
-
border: none;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
.connect-btn:hover {
|
|
636
|
-
background-color: #0056b3;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
.cancel-btn {
|
|
640
|
-
background-color: transparent;
|
|
641
|
-
color: #a0a0a0;
|
|
642
|
-
border: 1px solid #a0a0a0;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
.cancel-btn:hover {
|
|
646
|
-
background-color: rgba(160, 160, 160, 0.1);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
/* BT Connection Status */
|
|
650
|
-
|
|
651
|
-
.mobile-wallet-adapter-embedded-modal-connection-status-container {
|
|
652
|
-
margin: 20px 0px 20px 0px;
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
.connection-status {
|
|
656
|
-
display: flex;
|
|
657
|
-
flex-direction: column;
|
|
658
|
-
align-items: center;
|
|
659
|
-
justify-content: center;
|
|
660
|
-
margin: 20px 0;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
.connection-status p {
|
|
664
|
-
margin-top: 10px;
|
|
665
|
-
color: #a0a0a0;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
.bluetooth-icon, .checkmark-icon {
|
|
669
|
-
width: 48px;
|
|
670
|
-
height: 48px;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
.spinner {
|
|
674
|
-
border: 4px solid #f3f3f3;
|
|
675
|
-
border-top: 4px solid #3498db;
|
|
676
|
-
border-radius: 50%;
|
|
677
|
-
width: 40px;
|
|
678
|
-
height: 40px;
|
|
679
|
-
animation: spin 1s linear infinite;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
@keyframes spin {
|
|
683
|
-
0% { transform: rotate(0deg); }
|
|
684
|
-
100% { transform: rotate(360deg); }
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
/* QR Code */
|
|
688
|
-
|
|
689
|
-
#mobile-wallet-adapter-embedded-modal-qr-code-container {
|
|
690
|
-
width: 500px;
|
|
691
|
-
height: 500px;
|
|
692
|
-
align-content: center;
|
|
693
|
-
}
|
|
694
|
-
`;
|
|
695
|
-
|
|
696
|
-
class EmbeddedModal {
|
|
697
|
-
constructor(title) {
|
|
698
|
-
this._root = null;
|
|
699
|
-
this._title = title;
|
|
700
|
-
// Bind methods to ensure `this` context is correct
|
|
701
|
-
this.init = this.init.bind(this);
|
|
702
|
-
this.injectQRCodeHTML = this.injectQRCodeHTML.bind(this);
|
|
703
|
-
this.injectBluetoothHTML = this.injectBluetoothHTML.bind(this);
|
|
704
|
-
this.open = this.open.bind(this);
|
|
705
|
-
this.close = this.close.bind(this);
|
|
706
|
-
this.connect = this.connect.bind(this);
|
|
707
|
-
this._root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
|
|
708
|
-
}
|
|
709
|
-
init(qrCode) {
|
|
710
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
711
|
-
console.log('Injecting modal');
|
|
712
|
-
this.injectStyles();
|
|
713
|
-
this.injectQRCodeHTML(qrCode);
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
setConnectionStatus(status) {
|
|
717
|
-
if (!this._root)
|
|
718
|
-
return;
|
|
719
|
-
const statuses = ['not-connected', 'connecting', 'connected'];
|
|
720
|
-
statuses.forEach((s) => {
|
|
721
|
-
const el = this._root.querySelector(`#status-${s}`);
|
|
722
|
-
if (el instanceof HTMLElement) {
|
|
723
|
-
el.style.display = s === status ? 'flex' : 'none';
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
injectStyles() {
|
|
728
|
-
// Check if the styles have already been injected
|
|
729
|
-
if (document.getElementById('mobile-wallet-adapter-styles')) {
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
const styleElement = document.createElement('style');
|
|
733
|
-
styleElement.id = 'mobile-wallet-adapter-styles';
|
|
734
|
-
styleElement.textContent = css;
|
|
735
|
-
document.head.appendChild(styleElement);
|
|
736
|
-
}
|
|
737
|
-
populateQRCode(qrUrl) {
|
|
738
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
739
|
-
const qrcodeContainer = document.getElementById('mobile-wallet-adapter-embedded-modal-qr-code-container');
|
|
740
|
-
if (qrcodeContainer) {
|
|
741
|
-
const qrCodeElement = yield QRCode__default["default"].toCanvas(qrUrl, { width: 400 });
|
|
742
|
-
if (qrcodeContainer.firstElementChild !== null) {
|
|
743
|
-
qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
|
|
744
|
-
}
|
|
745
|
-
else
|
|
746
|
-
qrcodeContainer.appendChild(qrCodeElement);
|
|
747
|
-
}
|
|
748
|
-
else {
|
|
749
|
-
console.error('QRCode Container not found');
|
|
750
|
-
}
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
injectQRCodeHTML(qrCode) {
|
|
754
|
-
// Check if the HTML has already been injected
|
|
755
|
-
if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
|
|
756
|
-
if (!this._root)
|
|
757
|
-
this._root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
|
|
758
|
-
this.populateQRCode(qrCode);
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
// Create a container for the modal
|
|
762
|
-
this._root = document.createElement('div');
|
|
763
|
-
this._root.id = 'mobile-wallet-adapter-embedded-root-ui';
|
|
764
|
-
this._root.className = 'mobile-wallet-adapter-embedded-modal';
|
|
765
|
-
this._root.innerHTML = QRCodeHtml;
|
|
766
|
-
this._root.style.display = 'none';
|
|
767
|
-
// Append the modal to the body
|
|
768
|
-
document.body.appendChild(this._root);
|
|
769
|
-
// Render the QRCode
|
|
770
|
-
this.populateQRCode(qrCode);
|
|
771
|
-
this.attachEventListeners();
|
|
772
|
-
}
|
|
773
|
-
injectBluetoothHTML() {
|
|
774
|
-
// Check if the HTML has already been injected
|
|
775
|
-
if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
|
|
776
|
-
return;
|
|
777
|
-
}
|
|
778
|
-
this._root = document.createElement('div');
|
|
779
|
-
this._root.id = 'mobile-wallet-adapter-embedded-root-ui';
|
|
780
|
-
this._root.className = 'mobile-wallet-adapter-embedded-modal';
|
|
781
|
-
this._root.innerHTML = BluetoothHtml;
|
|
782
|
-
document.body.appendChild(this._root);
|
|
783
|
-
this.attachEventListeners();
|
|
784
|
-
}
|
|
785
|
-
attachEventListeners() {
|
|
786
|
-
if (!this._root)
|
|
787
|
-
return;
|
|
788
|
-
const closeBtn = this._root.querySelector('#mobile-wallet-adapter-embedded-modal-close');
|
|
789
|
-
const cancelBtn = this._root.querySelector('#cancel-btn');
|
|
790
|
-
const connectBtn = this._root.querySelector('#connect-btn');
|
|
791
|
-
closeBtn === null || closeBtn === void 0 ? void 0 : closeBtn.addEventListener('click', () => this.close());
|
|
792
|
-
cancelBtn === null || cancelBtn === void 0 ? void 0 : cancelBtn.addEventListener('click', () => this.close());
|
|
793
|
-
connectBtn === null || connectBtn === void 0 ? void 0 : connectBtn.addEventListener('click', () => this.connect());
|
|
794
|
-
}
|
|
795
|
-
open() {
|
|
796
|
-
console.debug('Modal open');
|
|
797
|
-
if (this._root) {
|
|
798
|
-
this._root.style.display = 'flex';
|
|
799
|
-
this.setConnectionStatus('not-connected'); // Reset status when opening
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
close() {
|
|
803
|
-
console.debug('Modal close');
|
|
804
|
-
if (this._root) {
|
|
805
|
-
this._root.style.display = 'none';
|
|
806
|
-
this.setConnectionStatus('not-connected'); // Reset status when closing
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
connect() {
|
|
810
|
-
console.log('Connecting...');
|
|
811
|
-
// Mock connection
|
|
812
|
-
this.setConnectionStatus('connecting');
|
|
813
|
-
// Simulate connection process
|
|
814
|
-
setTimeout(() => {
|
|
815
|
-
this.setConnectionStatus('connected');
|
|
816
|
-
console.log('Connected!');
|
|
817
|
-
}, 5000); // 5 seconds delay
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
const SolanaMobileWalletAdapterRemoteWalletName = 'MWA (Remote)';
|
|
822
|
-
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
823
|
-
function getPublicKeyFromAddress(address) {
|
|
824
|
-
const publicKeyByteArray = jsBase64.toUint8Array(address);
|
|
825
|
-
return new web3_js.PublicKey(publicKeyByteArray);
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* Determine the mobile operating system.
|
|
829
|
-
* Returns true if running on a mobile operating system, or false otherwise.
|
|
830
|
-
*
|
|
831
|
-
* @returns {boolean}
|
|
832
|
-
*/
|
|
833
|
-
function isMobileOperatingSystem() {
|
|
834
|
-
var userAgent = navigator.userAgent;
|
|
835
|
-
// Windows Phone must come first because its UA also contains "Android"
|
|
836
|
-
if (/windows phone/i.test(userAgent)) {
|
|
837
|
-
return true;
|
|
838
|
-
}
|
|
839
|
-
if (/android/i.test(userAgent)) {
|
|
840
|
-
return true;
|
|
841
|
-
}
|
|
842
|
-
// iOS detection from: http://stackoverflow.com/a/9039885/177710
|
|
843
|
-
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
|
|
844
|
-
return true;
|
|
845
|
-
}
|
|
846
|
-
return false;
|
|
847
|
-
}
|
|
848
|
-
function getIsSupported() {
|
|
849
|
-
return (typeof window !== 'undefined' &&
|
|
850
|
-
window.isSecureContext &&
|
|
851
|
-
typeof document !== 'undefined' &&
|
|
852
|
-
!isMobileOperatingSystem());
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
* This burner wallet adapter is unsafe to use and is only included to provide an easy way for applications to test
|
|
856
|
-
* Wallet Adapter without using a third-party wallet.
|
|
857
|
-
*/
|
|
858
|
-
class SolanaMobileWalletAdapterRemote extends walletAdapterBase.BaseSignInMessageSignerWalletAdapter {
|
|
859
|
-
constructor(config) {
|
|
860
|
-
super();
|
|
861
|
-
this.supportedTransactionVersions = new Set(
|
|
862
|
-
// FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
|
|
863
|
-
['legacy', 0]);
|
|
864
|
-
this.name = SolanaMobileWalletAdapterRemoteWalletName;
|
|
865
|
-
this.url = 'https://solanamobile.com/wallets';
|
|
866
|
-
this.icon = 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjI4IiB3aWR0aD0iMjgiIHZpZXdCb3g9Ii0zIDAgMjggMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0RDQjhGRiI+PHBhdGggZD0iTTE3LjQgMTcuNEgxNXYyLjRoMi40di0yLjRabTEuMi05LjZoLTIuNHYyLjRoMi40VjcuOFoiLz48cGF0aCBkPSJNMjEuNiAzVjBoLTIuNHYzaC0zLjZWMGgtMi40djNoLTIuNHY2LjZINC41YTIuMSAyLjEgMCAxIDEgMC00LjJoMi43VjNINC41QTQuNSA0LjUgMCAwIDAgMCA3LjVWMjRoMjEuNnYtNi42aC0yLjR2NC4ySDIuNFYxMS41Yy41LjMgMS4yLjQgMS44LjVoNy41QTYuNiA2LjYgMCAwIDAgMjQgOVYzaC0yLjRabTAgNS43YTQuMiA0LjIgMCAxIDEtOC40IDBWNS40aDguNHYzLjNaIi8+PC9nPjwvc3ZnPg==';
|
|
867
|
-
this._connecting = false;
|
|
868
|
-
/**
|
|
869
|
-
* Every time the connection is recycled in some way (eg. `disconnect()` is called)
|
|
870
|
-
* increment this and use it to make sure that `transact` calls from the previous
|
|
871
|
-
* 'generation' don't continue to do work and throw exceptions.
|
|
872
|
-
*/
|
|
873
|
-
this._connectionGeneration = 0;
|
|
874
|
-
this._readyState = getIsSupported() ? walletAdapterBase.WalletReadyState.Loadable : walletAdapterBase.WalletReadyState.Unsupported;
|
|
875
|
-
this._authorizationResultCache = config.authorizationResultCache;
|
|
876
|
-
this._addressSelector = config.addressSelector;
|
|
877
|
-
this._appIdentity = config.appIdentity;
|
|
878
|
-
this._chain = config.chain;
|
|
879
|
-
this._hostAuthority = config.remoteHostAuthority;
|
|
880
|
-
this._onWalletNotFound = config.onWalletNotFound;
|
|
881
|
-
if (this._readyState !== walletAdapterBase.WalletReadyState.Unsupported) {
|
|
882
|
-
this._authorizationResultCache.get().then((authorizationResult) => {
|
|
883
|
-
if (authorizationResult) {
|
|
884
|
-
// Having a prior authorization result is, right now, the best
|
|
885
|
-
// indication that a mobile wallet is installed. There is no API
|
|
886
|
-
// we can use to test for whether the association URI is supported.
|
|
887
|
-
this.declareWalletAsInstalled();
|
|
888
|
-
}
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
get publicKey() {
|
|
893
|
-
if (this._publicKey == null && this._selectedAddress != null) {
|
|
894
|
-
try {
|
|
895
|
-
this._publicKey = getPublicKeyFromAddress(this._selectedAddress);
|
|
896
|
-
}
|
|
897
|
-
catch (e) {
|
|
898
|
-
throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
return this._publicKey ? this._publicKey : null;
|
|
902
|
-
}
|
|
903
|
-
get connected() {
|
|
904
|
-
return !!this._authorizationResult;
|
|
905
|
-
}
|
|
906
|
-
get connecting() {
|
|
907
|
-
return this._connecting;
|
|
908
|
-
}
|
|
909
|
-
get readyState() {
|
|
910
|
-
return this._readyState;
|
|
911
|
-
}
|
|
912
|
-
declareWalletAsInstalled() {
|
|
913
|
-
if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
|
|
914
|
-
this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
runWithGuard(callback) {
|
|
918
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
919
|
-
try {
|
|
920
|
-
return yield callback();
|
|
921
|
-
}
|
|
922
|
-
catch (e) {
|
|
923
|
-
this.emit('error', e);
|
|
924
|
-
throw e;
|
|
925
|
-
}
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
autoConnect() {
|
|
929
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
930
|
-
if (this.connecting || this.connected) {
|
|
931
|
-
return;
|
|
932
|
-
}
|
|
933
|
-
return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
|
|
934
|
-
if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
|
|
935
|
-
throw new walletAdapterBase.WalletNotReadyError();
|
|
936
|
-
}
|
|
937
|
-
this._connecting = true;
|
|
938
|
-
try {
|
|
939
|
-
const cachedAuthorizationResult = yield this._authorizationResultCache.get();
|
|
940
|
-
if (cachedAuthorizationResult) {
|
|
941
|
-
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
942
|
-
this.handleAuthorizationResult(cachedAuthorizationResult);
|
|
257
|
+
else {
|
|
258
|
+
throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
943
259
|
}
|
|
944
260
|
}
|
|
945
261
|
catch (e) {
|
|
946
262
|
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
947
263
|
}
|
|
948
264
|
finally {
|
|
949
|
-
this
|
|
265
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, false, "f");
|
|
950
266
|
}
|
|
951
267
|
}));
|
|
952
268
|
});
|
|
953
269
|
}
|
|
954
|
-
|
|
270
|
+
signMessage(message) {
|
|
955
271
|
return __awaiter(this, void 0, void 0, function* () {
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
}
|
|
959
|
-
return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
|
|
960
|
-
if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
|
|
961
|
-
throw new walletAdapterBase.WalletNotReadyError();
|
|
962
|
-
}
|
|
963
|
-
this._connecting = true;
|
|
272
|
+
return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
273
|
+
const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
|
|
964
274
|
try {
|
|
965
|
-
yield this.
|
|
966
|
-
|
|
967
|
-
catch (e) {
|
|
968
|
-
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
969
|
-
}
|
|
970
|
-
finally {
|
|
971
|
-
this._connecting = false;
|
|
972
|
-
}
|
|
973
|
-
}));
|
|
974
|
-
});
|
|
975
|
-
}
|
|
976
|
-
performAuthorization(signInPayload) {
|
|
977
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
978
|
-
try {
|
|
979
|
-
const cachedAuthorizationResult = yield this._authorizationResultCache.get();
|
|
980
|
-
if (cachedAuthorizationResult) {
|
|
981
|
-
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
982
|
-
this.handleAuthorizationResult(cachedAuthorizationResult);
|
|
983
|
-
return cachedAuthorizationResult;
|
|
984
|
-
}
|
|
985
|
-
if (this._wallet)
|
|
986
|
-
delete this._wallet;
|
|
987
|
-
return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
988
|
-
this._wallet = wallet;
|
|
989
|
-
const authorizationResult = yield wallet.authorize({
|
|
990
|
-
chain: this._chain,
|
|
991
|
-
identity: this._appIdentity,
|
|
992
|
-
sign_in_payload: signInPayload,
|
|
275
|
+
const outputs = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignMessage].signMessage({
|
|
276
|
+
account, message: message
|
|
993
277
|
});
|
|
994
|
-
|
|
995
|
-
Promise.all([
|
|
996
|
-
this._authorizationResultCache.set(authorizationResult),
|
|
997
|
-
this.handleAuthorizationResult(authorizationResult),
|
|
998
|
-
]);
|
|
999
|
-
return authorizationResult;
|
|
1000
|
-
}));
|
|
1001
|
-
}
|
|
1002
|
-
catch (e) {
|
|
1003
|
-
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
1004
|
-
}
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
handleAuthorizationResult(authorizationResult) {
|
|
1008
|
-
var _a;
|
|
1009
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1010
|
-
const didPublicKeysChange =
|
|
1011
|
-
// Case 1: We started from having no authorization.
|
|
1012
|
-
this._authorizationResult == null ||
|
|
1013
|
-
// Case 2: The number of authorized accounts changed.
|
|
1014
|
-
((_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorizationResult.accounts.length ||
|
|
1015
|
-
// Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
|
|
1016
|
-
this._authorizationResult.accounts.some((account, ii) => account.address !== authorizationResult.accounts[ii].address);
|
|
1017
|
-
this._authorizationResult = authorizationResult;
|
|
1018
|
-
this.declareWalletAsInstalled();
|
|
1019
|
-
if (didPublicKeysChange) {
|
|
1020
|
-
const nextSelectedAddress = yield this._addressSelector.select(authorizationResult.accounts.map(({ address }) => address));
|
|
1021
|
-
if (nextSelectedAddress !== this._selectedAddress) {
|
|
1022
|
-
this._selectedAddress = nextSelectedAddress;
|
|
1023
|
-
delete this._publicKey;
|
|
1024
|
-
this.emit('connect',
|
|
1025
|
-
// Having just set `this._selectedAddress`, `this.publicKey` is definitely non-null
|
|
1026
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1027
|
-
this.publicKey);
|
|
278
|
+
return outputs[0].signature;
|
|
1028
279
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
}
|
|
1032
|
-
performReauthorization(wallet, authToken) {
|
|
1033
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1034
|
-
try {
|
|
1035
|
-
const authorizationResult = yield wallet.authorize({
|
|
1036
|
-
auth_token: authToken,
|
|
1037
|
-
identity: this._appIdentity,
|
|
1038
|
-
});
|
|
1039
|
-
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1040
|
-
Promise.all([
|
|
1041
|
-
this._authorizationResultCache.set(authorizationResult),
|
|
1042
|
-
this.handleAuthorizationResult(authorizationResult),
|
|
1043
|
-
]);
|
|
1044
|
-
}
|
|
1045
|
-
catch (e) {
|
|
1046
|
-
this.disconnect();
|
|
1047
|
-
throw new walletAdapterBase.WalletDisconnectedError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
|
|
1048
|
-
}
|
|
1049
|
-
});
|
|
1050
|
-
}
|
|
1051
|
-
disconnect() {
|
|
1052
|
-
var _a;
|
|
1053
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1054
|
-
// TODO: figure out why this call throws "TypeError: _a.terminateSession is not a function"
|
|
1055
|
-
// even though the session termination is actually executed (websocket closes).
|
|
1056
|
-
try {
|
|
1057
|
-
(_a = this._wallet) === null || _a === void 0 ? void 0 : _a.terminateSession();
|
|
1058
|
-
}
|
|
1059
|
-
catch (e) { }
|
|
1060
|
-
this._authorizationResultCache.clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1061
|
-
this._connecting = false;
|
|
1062
|
-
this._connectionGeneration++;
|
|
1063
|
-
delete this._authorizationResult;
|
|
1064
|
-
delete this._publicKey;
|
|
1065
|
-
delete this._selectedAddress;
|
|
1066
|
-
delete this._wallet;
|
|
1067
|
-
this.emit('disconnect');
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
1070
|
-
transact(callback) {
|
|
1071
|
-
var _a;
|
|
1072
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1073
|
-
const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.wallet_uri_base;
|
|
1074
|
-
const baseConfig = walletUriBase ? { baseUri: walletUriBase } : undefined;
|
|
1075
|
-
const remoteConfig = Object.assign(Object.assign({}, baseConfig), { remoteHostAuthority: this._hostAuthority });
|
|
1076
|
-
const currentConnectionGeneration = this._connectionGeneration;
|
|
1077
|
-
const modal = new EmbeddedModal('MWA QR');
|
|
1078
|
-
if (this._wallet) {
|
|
1079
|
-
return callback(this._wallet);
|
|
1080
|
-
}
|
|
1081
|
-
try {
|
|
1082
|
-
const { associationUrl, result: promise } = yield mobileWalletAdapterProtocolWeb3js.transactRemote((wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
1083
|
-
const result = yield callback(wallet);
|
|
1084
|
-
modal.close();
|
|
1085
|
-
return result;
|
|
1086
|
-
}), remoteConfig);
|
|
1087
|
-
modal.init(associationUrl.toString());
|
|
1088
|
-
modal.open();
|
|
1089
|
-
return yield promise;
|
|
1090
|
-
}
|
|
1091
|
-
catch (e) {
|
|
1092
|
-
modal.close();
|
|
1093
|
-
if (this._connectionGeneration !== currentConnectionGeneration) {
|
|
1094
|
-
yield new Promise(() => { }); // Never resolve.
|
|
1095
|
-
}
|
|
1096
|
-
if (e instanceof Error &&
|
|
1097
|
-
e.name === 'SolanaMobileWalletAdapterError' &&
|
|
1098
|
-
e.code === 'ERROR_WALLET_NOT_FOUND') {
|
|
1099
|
-
yield this._onWalletNotFound(this);
|
|
280
|
+
catch (error) {
|
|
281
|
+
throw new walletAdapterBase.WalletSignMessageError(error === null || error === void 0 ? void 0 : error.message, error);
|
|
1100
282
|
}
|
|
1101
|
-
|
|
1102
|
-
}
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
|
-
assertIsAuthorized() {
|
|
1106
|
-
if (!this._authorizationResult || !this._selectedAddress)
|
|
1107
|
-
throw new walletAdapterBase.WalletNotConnectedError();
|
|
1108
|
-
return {
|
|
1109
|
-
authToken: this._authorizationResult.auth_token,
|
|
1110
|
-
selectedAddress: this._selectedAddress,
|
|
1111
|
-
};
|
|
1112
|
-
}
|
|
1113
|
-
performSignTransactions(transactions) {
|
|
1114
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1115
|
-
const { authToken } = this.assertIsAuthorized();
|
|
1116
|
-
try {
|
|
1117
|
-
return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
1118
|
-
yield this.performReauthorization(wallet, authToken);
|
|
1119
|
-
const signedTransactions = yield wallet.signTransactions({
|
|
1120
|
-
transactions,
|
|
1121
|
-
});
|
|
1122
|
-
return signedTransactions;
|
|
1123
|
-
}));
|
|
1124
|
-
}
|
|
1125
|
-
catch (error) {
|
|
1126
|
-
throw new walletAdapterBase.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
|
|
1127
|
-
}
|
|
283
|
+
}));
|
|
1128
284
|
});
|
|
1129
285
|
}
|
|
1130
286
|
sendTransaction(transaction, connection, options) {
|
|
1131
287
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1132
|
-
return yield this.
|
|
1133
|
-
const
|
|
1134
|
-
const minContextSlot = options === null || options === void 0 ? void 0 : options.minContextSlot;
|
|
288
|
+
return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
289
|
+
const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
|
|
1135
290
|
try {
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
targetCommitment = 'finalized';
|
|
1147
|
-
}
|
|
1148
|
-
let targetPreflightCommitment;
|
|
1149
|
-
switch (options === null || options === void 0 ? void 0 : options.preflightCommitment) {
|
|
1150
|
-
case 'confirmed':
|
|
1151
|
-
case 'finalized':
|
|
1152
|
-
case 'processed':
|
|
1153
|
-
targetPreflightCommitment = options.preflightCommitment;
|
|
1154
|
-
break;
|
|
1155
|
-
case undefined:
|
|
1156
|
-
targetPreflightCommitment = targetCommitment;
|
|
1157
|
-
break;
|
|
1158
|
-
default:
|
|
1159
|
-
targetPreflightCommitment = 'finalized';
|
|
1160
|
-
}
|
|
1161
|
-
const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
|
|
1162
|
-
? 2
|
|
1163
|
-
: targetPreflightCommitment === 'confirmed'
|
|
1164
|
-
? 1
|
|
1165
|
-
: 0;
|
|
1166
|
-
const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
|
|
1167
|
-
return preflightCommitmentScore < targetCommitmentScore
|
|
1168
|
-
? targetPreflightCommitment
|
|
1169
|
-
: targetCommitment;
|
|
291
|
+
function getTargetCommitment() {
|
|
292
|
+
let targetCommitment;
|
|
293
|
+
switch (connection.commitment) {
|
|
294
|
+
case 'confirmed':
|
|
295
|
+
case 'finalized':
|
|
296
|
+
case 'processed':
|
|
297
|
+
targetCommitment = connection.commitment;
|
|
298
|
+
break;
|
|
299
|
+
default:
|
|
300
|
+
targetCommitment = 'finalized';
|
|
1170
301
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
302
|
+
let targetPreflightCommitment;
|
|
303
|
+
switch (options === null || options === void 0 ? void 0 : options.preflightCommitment) {
|
|
304
|
+
case 'confirmed':
|
|
305
|
+
case 'finalized':
|
|
306
|
+
case 'processed':
|
|
307
|
+
targetPreflightCommitment = options.preflightCommitment;
|
|
308
|
+
break;
|
|
309
|
+
case undefined:
|
|
310
|
+
targetPreflightCommitment = targetCommitment;
|
|
311
|
+
break;
|
|
312
|
+
default:
|
|
313
|
+
targetPreflightCommitment = 'finalized';
|
|
314
|
+
}
|
|
315
|
+
const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
|
|
316
|
+
? 2
|
|
317
|
+
: targetPreflightCommitment === 'confirmed'
|
|
318
|
+
? 1
|
|
319
|
+
: 0;
|
|
320
|
+
const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
|
|
321
|
+
return preflightCommitmentScore < targetCommitmentScore
|
|
322
|
+
? targetPreflightCommitment
|
|
323
|
+
: targetCommitment;
|
|
324
|
+
}
|
|
325
|
+
if (walletStandardFeatures.SolanaSignAndSendTransaction in __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features) {
|
|
326
|
+
const chain = chainOrClusterToChainId(__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").currentAuthorization.chain);
|
|
327
|
+
const [signature] = (yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
|
|
328
|
+
account,
|
|
329
|
+
transaction: transaction.serialize(),
|
|
330
|
+
chain: chain,
|
|
331
|
+
options: options ? {
|
|
332
|
+
skipPreflight: options.skipPreflight,
|
|
333
|
+
maxRetries: options.maxRetries
|
|
334
|
+
} : undefined
|
|
335
|
+
})).map(((output) => {
|
|
336
|
+
return fromUint8Array(output.signature);
|
|
337
|
+
}));
|
|
338
|
+
return signature;
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
const [signedTransaction] = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_performSignTransactions).call(this, [transaction]);
|
|
342
|
+
if (isVersionedTransaction(signedTransaction)) {
|
|
343
|
+
return yield connection.sendTransaction(signedTransaction);
|
|
1198
344
|
}
|
|
1199
345
|
else {
|
|
1200
|
-
const
|
|
1201
|
-
|
|
1202
|
-
});
|
|
1203
|
-
if (walletAdapterBase.isVersionedTransaction(signedTransaction)) {
|
|
1204
|
-
return yield connection.sendTransaction(signedTransaction);
|
|
1205
|
-
}
|
|
1206
|
-
else {
|
|
1207
|
-
const serializedTransaction = signedTransaction.serialize();
|
|
1208
|
-
return yield connection.sendRawTransaction(serializedTransaction, Object.assign(Object.assign({}, options), { preflightCommitment: getTargetCommitment() }));
|
|
1209
|
-
}
|
|
346
|
+
const serializedTransaction = signedTransaction.serialize();
|
|
347
|
+
return yield connection.sendRawTransaction(serializedTransaction, Object.assign(Object.assign({}, options), { preflightCommitment: getTargetCommitment() }));
|
|
1210
348
|
}
|
|
1211
|
-
}
|
|
349
|
+
}
|
|
1212
350
|
}
|
|
1213
351
|
catch (error) {
|
|
1214
352
|
throw new walletAdapterBase.WalletSendTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
|
|
@@ -1218,74 +356,157 @@ class SolanaMobileWalletAdapterRemote extends walletAdapterBase.BaseSignInMessag
|
|
|
1218
356
|
}
|
|
1219
357
|
signTransaction(transaction) {
|
|
1220
358
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1221
|
-
return yield this.
|
|
1222
|
-
const [signedTransaction] = yield this.
|
|
359
|
+
return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
const [signedTransaction] = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_performSignTransactions).call(this, [transaction]);
|
|
1223
361
|
return signedTransaction;
|
|
1224
362
|
}));
|
|
1225
363
|
});
|
|
1226
364
|
}
|
|
1227
365
|
signAllTransactions(transactions) {
|
|
1228
366
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1229
|
-
return yield this.
|
|
1230
|
-
const signedTransactions = yield this.
|
|
367
|
+
return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
368
|
+
const signedTransactions = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_performSignTransactions).call(this, transactions);
|
|
1231
369
|
return signedTransactions;
|
|
1232
370
|
}));
|
|
1233
371
|
});
|
|
1234
372
|
}
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
373
|
+
}
|
|
374
|
+
_BaseSolanaMobileWalletAdapter_wallet = new WeakMap(), _BaseSolanaMobileWalletAdapter_connecting = new WeakMap(), _BaseSolanaMobileWalletAdapter_readyState = new WeakMap(), _BaseSolanaMobileWalletAdapter_accountSelector = new WeakMap(), _BaseSolanaMobileWalletAdapter_selectedAccount = new WeakMap(), _BaseSolanaMobileWalletAdapter_publicKey = new WeakMap(), _BaseSolanaMobileWalletAdapter_handleChangeEvent = new WeakMap(), _BaseSolanaMobileWalletAdapter_instances = new WeakSet(), _BaseSolanaMobileWalletAdapter_connect = function _BaseSolanaMobileWalletAdapter_connect(autoConnect = false) {
|
|
375
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
376
|
+
if (this.connecting || this.connected) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
380
|
+
if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Installed && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Loadable) {
|
|
381
|
+
throw new walletAdapterBase.WalletNotReadyError();
|
|
382
|
+
}
|
|
383
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, true, "f");
|
|
384
|
+
try {
|
|
385
|
+
yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect({ silent: autoConnect });
|
|
386
|
+
}
|
|
387
|
+
catch (e) {
|
|
388
|
+
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
389
|
+
}
|
|
390
|
+
finally {
|
|
391
|
+
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, false, "f");
|
|
392
|
+
}
|
|
393
|
+
}));
|
|
394
|
+
});
|
|
395
|
+
}, _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled = function _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled() {
|
|
396
|
+
if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== walletAdapterBase.WalletReadyState.Installed) {
|
|
397
|
+
this.emit('readyStateChange', (__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_readyState, walletAdapterBase.WalletReadyState.Installed, "f")));
|
|
398
|
+
}
|
|
399
|
+
}, _BaseSolanaMobileWalletAdapter_assertIsAuthorized = function _BaseSolanaMobileWalletAdapter_assertIsAuthorized() {
|
|
400
|
+
if (!__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").isAuthorized || !__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f"))
|
|
401
|
+
throw new walletAdapterBase.WalletNotConnectedError();
|
|
402
|
+
return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f");
|
|
403
|
+
}, _BaseSolanaMobileWalletAdapter_performSignTransactions = function _BaseSolanaMobileWalletAdapter_performSignTransactions(transactions) {
|
|
404
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
405
|
+
const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
|
|
406
|
+
try {
|
|
407
|
+
if (walletStandardFeatures.SolanaSignTransaction in __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features) {
|
|
408
|
+
return __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[walletStandardFeatures.SolanaSignTransaction].signTransaction(...transactions.map((value) => {
|
|
409
|
+
return { account, transaction: value.serialize() };
|
|
410
|
+
})).then((outputs) => {
|
|
411
|
+
return outputs.map((output) => {
|
|
412
|
+
const byteArray = output.signedTransaction;
|
|
413
|
+
const numSignatures = byteArray[0];
|
|
414
|
+
const messageOffset = numSignatures * SIGNATURE_LENGTH_IN_BYTES + 1;
|
|
415
|
+
const version = web3_js.VersionedMessage.deserializeMessageVersion(byteArray.slice(messageOffset, byteArray.length));
|
|
416
|
+
if (version === 'legacy') {
|
|
417
|
+
return web3_js.Transaction.from(byteArray);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
return web3_js.VersionedTransaction.deserialize(byteArray);
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
throw new Error('Connected wallet does not support signing transactions');
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
throw new walletAdapterBase.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}, _BaseSolanaMobileWalletAdapter_runWithGuard = function _BaseSolanaMobileWalletAdapter_runWithGuard(callback) {
|
|
434
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
435
|
+
try {
|
|
436
|
+
return yield callback();
|
|
437
|
+
}
|
|
438
|
+
catch (e) {
|
|
439
|
+
this.emit('error', e);
|
|
440
|
+
throw e;
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
class LocalSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
|
|
445
|
+
constructor(config) {
|
|
446
|
+
var _a;
|
|
447
|
+
const chain = chainOrClusterToChainId((_a = config.chain) !== null && _a !== void 0 ? _a : config.cluster);
|
|
448
|
+
super(new walletStandardMobile.LocalSolanaMobileWalletAdapterWallet({
|
|
449
|
+
appIdentity: config.appIdentity,
|
|
450
|
+
authorizationCache: {
|
|
451
|
+
set: config.authorizationResultCache.set,
|
|
452
|
+
get: () => __awaiter(this, void 0, void 0, function* () {
|
|
453
|
+
const authorizationResult = yield config.authorizationResultCache.get();
|
|
454
|
+
if (authorizationResult && 'chain' in authorizationResult) {
|
|
455
|
+
return authorizationResult;
|
|
456
|
+
}
|
|
457
|
+
else if (authorizationResult) {
|
|
458
|
+
return Object.assign(Object.assign({}, authorizationResult), { chain: chain });
|
|
459
|
+
}
|
|
460
|
+
else
|
|
461
|
+
return undefined;
|
|
462
|
+
}),
|
|
463
|
+
clear: config.authorizationResultCache.clear,
|
|
464
|
+
},
|
|
465
|
+
chains: [chain],
|
|
466
|
+
chainSelector: walletStandardMobile.createDefaultChainSelector(),
|
|
467
|
+
onWalletNotFound: () => __awaiter(this, void 0, void 0, function* () {
|
|
468
|
+
config.onWalletNotFound(this);
|
|
469
|
+
}),
|
|
470
|
+
}), {
|
|
471
|
+
addressSelector: config.addressSelector,
|
|
472
|
+
chain: chain,
|
|
1254
473
|
});
|
|
1255
474
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
const authorizationResult = yield
|
|
1266
|
-
if (
|
|
1267
|
-
|
|
475
|
+
}
|
|
476
|
+
class RemoteSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
|
|
477
|
+
constructor(config) {
|
|
478
|
+
const chain = chainOrClusterToChainId(config.chain);
|
|
479
|
+
super(new walletStandardMobile.RemoteSolanaMobileWalletAdapterWallet({
|
|
480
|
+
appIdentity: config.appIdentity,
|
|
481
|
+
authorizationCache: {
|
|
482
|
+
set: config.authorizationResultCache.set,
|
|
483
|
+
get: () => __awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
const authorizationResult = yield config.authorizationResultCache.get();
|
|
485
|
+
if (authorizationResult && 'chain' in authorizationResult) {
|
|
486
|
+
return authorizationResult;
|
|
1268
487
|
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
488
|
+
else if (authorizationResult) {
|
|
489
|
+
return Object.assign(Object.assign({}, authorizationResult), { chain: chain });
|
|
490
|
+
}
|
|
491
|
+
else
|
|
492
|
+
return undefined;
|
|
493
|
+
}),
|
|
494
|
+
clear: config.authorizationResultCache.clear,
|
|
495
|
+
},
|
|
496
|
+
chains: [chain],
|
|
497
|
+
chainSelector: walletStandardMobile.createDefaultChainSelector(),
|
|
498
|
+
remoteHostAuthority: config.remoteHostAuthority,
|
|
499
|
+
onWalletNotFound: () => __awaiter(this, void 0, void 0, function* () {
|
|
500
|
+
config.onWalletNotFound(this);
|
|
501
|
+
}),
|
|
502
|
+
}), {
|
|
503
|
+
addressSelector: config.addressSelector,
|
|
504
|
+
chain: chain,
|
|
1286
505
|
});
|
|
1287
506
|
}
|
|
1288
507
|
}
|
|
508
|
+
class SolanaMobileWalletAdapter extends LocalSolanaMobileWalletAdapter {
|
|
509
|
+
}
|
|
1289
510
|
|
|
1290
511
|
function createDefaultAddressSelector() {
|
|
1291
512
|
return {
|
|
@@ -1297,68 +518,22 @@ function createDefaultAddressSelector() {
|
|
|
1297
518
|
};
|
|
1298
519
|
}
|
|
1299
520
|
|
|
1300
|
-
const CACHE_KEY = 'SolanaMobileWalletAdapterDefaultAuthorizationCache';
|
|
1301
521
|
function createDefaultAuthorizationResultCache() {
|
|
1302
|
-
|
|
1303
|
-
try {
|
|
1304
|
-
storage = window.localStorage;
|
|
1305
|
-
// eslint-disable-next-line no-empty
|
|
1306
|
-
}
|
|
1307
|
-
catch (_a) { }
|
|
1308
|
-
return {
|
|
1309
|
-
clear() {
|
|
1310
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1311
|
-
if (!storage) {
|
|
1312
|
-
return;
|
|
1313
|
-
}
|
|
1314
|
-
try {
|
|
1315
|
-
storage.removeItem(CACHE_KEY);
|
|
1316
|
-
// eslint-disable-next-line no-empty
|
|
1317
|
-
}
|
|
1318
|
-
catch (_a) { }
|
|
1319
|
-
});
|
|
1320
|
-
},
|
|
1321
|
-
get() {
|
|
1322
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1323
|
-
if (!storage) {
|
|
1324
|
-
return;
|
|
1325
|
-
}
|
|
1326
|
-
try {
|
|
1327
|
-
return JSON.parse(storage.getItem(CACHE_KEY)) || undefined;
|
|
1328
|
-
// eslint-disable-next-line no-empty
|
|
1329
|
-
}
|
|
1330
|
-
catch (_a) { }
|
|
1331
|
-
});
|
|
1332
|
-
},
|
|
1333
|
-
set(authorizationResult) {
|
|
1334
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1335
|
-
if (!storage) {
|
|
1336
|
-
return;
|
|
1337
|
-
}
|
|
1338
|
-
try {
|
|
1339
|
-
storage.setItem(CACHE_KEY, JSON.stringify(authorizationResult));
|
|
1340
|
-
// eslint-disable-next-line no-empty
|
|
1341
|
-
}
|
|
1342
|
-
catch (_a) { }
|
|
1343
|
-
});
|
|
1344
|
-
},
|
|
1345
|
-
};
|
|
522
|
+
return walletStandardMobile.createDefaultAuthorizationCache();
|
|
1346
523
|
}
|
|
1347
524
|
|
|
1348
525
|
function defaultWalletNotFoundHandler(mobileWalletAdapter) {
|
|
1349
526
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1350
|
-
|
|
1351
|
-
window.location.assign(mobileWalletAdapter.url);
|
|
1352
|
-
}
|
|
527
|
+
return walletStandardMobile.defaultErrorModalWalletNotFoundHandler();
|
|
1353
528
|
});
|
|
1354
529
|
}
|
|
1355
530
|
function createDefaultWalletNotFoundHandler() {
|
|
1356
531
|
return defaultWalletNotFoundHandler;
|
|
1357
532
|
}
|
|
1358
533
|
|
|
534
|
+
exports.LocalSolanaMobileWalletAdapter = LocalSolanaMobileWalletAdapter;
|
|
535
|
+
exports.RemoteSolanaMobileWalletAdapter = RemoteSolanaMobileWalletAdapter;
|
|
1359
536
|
exports.SolanaMobileWalletAdapter = SolanaMobileWalletAdapter;
|
|
1360
|
-
exports.SolanaMobileWalletAdapterRemote = SolanaMobileWalletAdapterRemote;
|
|
1361
|
-
exports.SolanaMobileWalletAdapterRemoteWalletName = SolanaMobileWalletAdapterRemoteWalletName;
|
|
1362
537
|
exports.SolanaMobileWalletAdapterWalletName = SolanaMobileWalletAdapterWalletName;
|
|
1363
538
|
exports.createDefaultAddressSelector = createDefaultAddressSelector;
|
|
1364
539
|
exports.createDefaultAuthorizationResultCache = createDefaultAuthorizationResultCache;
|