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