@solana-mobile/wallet-adapter-mobile 2.2.5 → 2.2.6
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/lib/cjs/index.browser.js +229 -336
- package/lib/cjs/index.js +229 -336
- package/lib/cjs/index.native.js +247 -364
- package/lib/esm/index.browser.js +231 -336
- package/lib/esm/index.js +231 -336
- package/lib/types/index.browser.d.ts +3 -3
- package/lib/types/index.d.ts +3 -3
- package/lib/types/index.native.d.ts +3 -3
- package/package.json +73 -68
package/lib/esm/index.browser.js
CHANGED
|
@@ -1,90 +1,8 @@
|
|
|
1
|
-
import { BaseSignInMessageSignerWalletAdapter, WalletReadyState, WalletPublicKeyError,
|
|
1
|
+
import { BaseSignInMessageSignerWalletAdapter, WalletReadyState, WalletPublicKeyError, WalletNotReadyError, WalletConnectionError, WalletSignMessageError, WalletSendTransactionError, WalletNotConnectedError, WalletSignTransactionError } from '@solana/wallet-adapter-base';
|
|
2
2
|
import { PublicKey, VersionedMessage, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
3
3
|
import { SolanaSignIn, SolanaSignMessage, SolanaSignAndSendTransaction, SolanaSignTransaction } from '@solana/wallet-standard-features';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
/******************************************************************************
|
|
7
|
-
Copyright (c) Microsoft Corporation.
|
|
8
|
-
|
|
9
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
-
purpose with or without fee is hereby granted.
|
|
11
|
-
|
|
12
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
-
***************************************************************************** */
|
|
20
|
-
|
|
21
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
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;
|
|
42
|
-
}
|
|
43
|
-
|
|
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
|
-
};
|
|
4
|
+
import { StandardEvents, StandardConnect, StandardDisconnect } from '@wallet-standard/core';
|
|
5
|
+
import { SolanaMobileWalletAdapterRemoteWalletName as SolanaMobileWalletAdapterRemoteWalletName$1, SolanaMobileWalletAdapterWalletName as SolanaMobileWalletAdapterWalletName$1, LocalSolanaMobileWalletAdapterWallet, createDefaultChainSelector, RemoteSolanaMobileWalletAdapterWallet, createDefaultAuthorizationCache, defaultErrorModalWalletNotFoundHandler } from '@solana-mobile/wallet-standard-mobile';
|
|
88
6
|
|
|
89
7
|
function fromUint8Array(byteArray) {
|
|
90
8
|
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
@@ -97,7 +15,6 @@ function getIsSupported() {
|
|
|
97
15
|
/android/i.test(navigator.userAgent));
|
|
98
16
|
}
|
|
99
17
|
|
|
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;
|
|
101
18
|
const SolanaMobileWalletAdapterWalletName = SolanaMobileWalletAdapterWalletName$1;
|
|
102
19
|
const SolanaMobileWalletAdapterRemoteWalletName = SolanaMobileWalletAdapterRemoteWalletName$1;
|
|
103
20
|
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
@@ -117,43 +34,44 @@ function chainOrClusterToChainId(chain) {
|
|
|
117
34
|
}
|
|
118
35
|
}
|
|
119
36
|
class BaseSolanaMobileWalletAdapter extends BaseSignInMessageSignerWalletAdapter {
|
|
37
|
+
supportedTransactionVersions = new Set(
|
|
38
|
+
// FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
|
|
39
|
+
['legacy', 0]);
|
|
40
|
+
name;
|
|
41
|
+
icon;
|
|
42
|
+
url;
|
|
43
|
+
#wallet;
|
|
44
|
+
#connecting = false;
|
|
45
|
+
#readyState = getIsSupported() ? WalletReadyState.Loadable : WalletReadyState.Unsupported;
|
|
46
|
+
#accountSelector;
|
|
47
|
+
#selectedAccount;
|
|
48
|
+
#publicKey;
|
|
49
|
+
#handleChangeEvent = async (properties) => {
|
|
50
|
+
if (properties.accounts && properties.accounts.length > 0) {
|
|
51
|
+
this.#declareWalletAsInstalled();
|
|
52
|
+
const nextSelectedAccount = await this.#accountSelector(properties.accounts);
|
|
53
|
+
if (nextSelectedAccount !== this.#selectedAccount) {
|
|
54
|
+
this.#selectedAccount = nextSelectedAccount;
|
|
55
|
+
this.#publicKey = undefined;
|
|
56
|
+
this.emit('connect',
|
|
57
|
+
// Having just set `this.#selectedAccount`, `this.publicKey` is definitely non-null
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
59
|
+
this.publicKey);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
120
63
|
constructor(wallet, config) {
|
|
121
64
|
super();
|
|
122
|
-
_BaseSolanaMobileWalletAdapter_instances.add(this);
|
|
123
|
-
this.supportedTransactionVersions = new Set(
|
|
124
|
-
// FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
|
|
125
|
-
['legacy', 0]);
|
|
126
|
-
_BaseSolanaMobileWalletAdapter_wallet.set(this, void 0);
|
|
127
|
-
_BaseSolanaMobileWalletAdapter_connecting.set(this, false);
|
|
128
|
-
_BaseSolanaMobileWalletAdapter_readyState.set(this, getIsSupported() ? WalletReadyState.Loadable : WalletReadyState.Unsupported);
|
|
129
|
-
_BaseSolanaMobileWalletAdapter_accountSelector.set(this, void 0);
|
|
130
|
-
_BaseSolanaMobileWalletAdapter_selectedAccount.set(this, void 0);
|
|
131
|
-
_BaseSolanaMobileWalletAdapter_publicKey.set(this, void 0);
|
|
132
|
-
_BaseSolanaMobileWalletAdapter_handleChangeEvent.set(this, (properties) => __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
if (properties.accounts && properties.accounts.length > 0) {
|
|
134
|
-
__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled).call(this);
|
|
135
|
-
const nextSelectedAccount = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_accountSelector, "f").call(this, properties.accounts);
|
|
136
|
-
if (nextSelectedAccount !== __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f")) {
|
|
137
|
-
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, nextSelectedAccount, "f");
|
|
138
|
-
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_publicKey, undefined, "f");
|
|
139
|
-
this.emit('connect',
|
|
140
|
-
// Having just set `this.#selectedAccount`, `this.publicKey` is definitely non-null
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
142
|
-
this.publicKey);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}));
|
|
146
65
|
// this.#chain = chainOrClusterToChainId(config.chain);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
this.
|
|
155
|
-
this.
|
|
156
|
-
this.url = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").url;
|
|
66
|
+
this.#accountSelector = async (accounts) => {
|
|
67
|
+
const selectedBase64EncodedAddress = await config.addressSelector.select(accounts.map(({ publicKey }) => fromUint8Array(new Uint8Array(publicKey))));
|
|
68
|
+
return accounts.find(({ publicKey }) => fromUint8Array(new Uint8Array(publicKey)) === selectedBase64EncodedAddress) ?? accounts[0];
|
|
69
|
+
};
|
|
70
|
+
this.#wallet = wallet;
|
|
71
|
+
this.#wallet.features[StandardEvents].on('change', this.#handleChangeEvent);
|
|
72
|
+
this.name = this.#wallet.name;
|
|
73
|
+
this.icon = this.#wallet.icon;
|
|
74
|
+
this.url = this.#wallet.url;
|
|
157
75
|
// TODO: evaluate if this logic should be kept - it seems to create a nasty bug where
|
|
158
76
|
// the wallet tries to auto connect on page load and gets blocked by the popup blocker
|
|
159
77
|
// if (this.#readyState !== WalletReadyState.Unsupported) {
|
|
@@ -168,241 +86,224 @@ class BaseSolanaMobileWalletAdapter extends BaseSignInMessageSignerWalletAdapter
|
|
|
168
86
|
// }
|
|
169
87
|
}
|
|
170
88
|
get publicKey() {
|
|
171
|
-
|
|
172
|
-
if (!__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_publicKey, "f") && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_selectedAccount, "f")) {
|
|
89
|
+
if (!this.#publicKey && this.#selectedAccount) {
|
|
173
90
|
try {
|
|
174
|
-
|
|
91
|
+
this.#publicKey = new PublicKey(this.#selectedAccount.publicKey);
|
|
175
92
|
}
|
|
176
93
|
catch (e) {
|
|
177
|
-
throw new WalletPublicKeyError((e instanceof Error &&
|
|
94
|
+
throw new WalletPublicKeyError((e instanceof Error && e?.message) || 'Unknown error', e);
|
|
178
95
|
}
|
|
179
96
|
}
|
|
180
|
-
return
|
|
97
|
+
return this.#publicKey ?? null;
|
|
181
98
|
}
|
|
182
99
|
get connected() {
|
|
183
|
-
return
|
|
100
|
+
return this.#wallet.connected;
|
|
184
101
|
}
|
|
185
102
|
get connecting() {
|
|
186
|
-
return
|
|
103
|
+
return this.#connecting;
|
|
187
104
|
}
|
|
188
105
|
get readyState() {
|
|
189
|
-
return
|
|
106
|
+
return this.#readyState;
|
|
190
107
|
}
|
|
191
108
|
/** @deprecated Use `autoConnect()` instead. */
|
|
192
|
-
autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
|
|
193
|
-
return
|
|
194
|
-
return yield this.autoConnect();
|
|
195
|
-
});
|
|
109
|
+
async autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
|
|
110
|
+
return await this.autoConnect();
|
|
196
111
|
}
|
|
197
|
-
autoConnect() {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
112
|
+
async autoConnect() {
|
|
113
|
+
this.#connect(true);
|
|
114
|
+
}
|
|
115
|
+
async connect() {
|
|
116
|
+
this.#connect();
|
|
201
117
|
}
|
|
202
|
-
connect() {
|
|
203
|
-
|
|
204
|
-
|
|
118
|
+
async #connect(autoConnect = false) {
|
|
119
|
+
if (this.connecting || this.connected) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
return await this.#runWithGuard(async () => {
|
|
123
|
+
if (this.#readyState !== WalletReadyState.Installed && this.#readyState !== WalletReadyState.Loadable) {
|
|
124
|
+
throw new WalletNotReadyError();
|
|
125
|
+
}
|
|
126
|
+
this.#connecting = true;
|
|
127
|
+
try {
|
|
128
|
+
await this.#wallet.features[StandardConnect].connect({ silent: autoConnect });
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
this.#connecting = false;
|
|
135
|
+
}
|
|
205
136
|
});
|
|
206
137
|
}
|
|
207
138
|
/** @deprecated Use `connect()` or `autoConnect()` instead. */
|
|
208
|
-
performAuthorization(signInPayload) {
|
|
209
|
-
|
|
139
|
+
async performAuthorization(signInPayload) {
|
|
140
|
+
try {
|
|
141
|
+
const cachedAuthorizationResult = await this.#wallet.cachedAuthorizationResult;
|
|
142
|
+
if (cachedAuthorizationResult) {
|
|
143
|
+
await this.#wallet.features[StandardConnect].connect({ silent: true });
|
|
144
|
+
return cachedAuthorizationResult;
|
|
145
|
+
}
|
|
146
|
+
if (signInPayload) {
|
|
147
|
+
await this.#wallet.features[SolanaSignIn].signIn(signInPayload);
|
|
148
|
+
}
|
|
149
|
+
else
|
|
150
|
+
await this.#wallet.features[StandardConnect].connect();
|
|
151
|
+
const authorizationResult = await await this.#wallet.cachedAuthorizationResult;
|
|
152
|
+
return authorizationResult;
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async disconnect() {
|
|
159
|
+
// return await this.#runWithGuard(this.#wallet.features[StandardDisconnect].disconnect);
|
|
160
|
+
return await this.#runWithGuard(async () => {
|
|
161
|
+
this.#connecting = false;
|
|
162
|
+
this.#publicKey = undefined;
|
|
163
|
+
this.#selectedAccount = undefined;
|
|
164
|
+
await this.#wallet.features[StandardDisconnect].disconnect();
|
|
165
|
+
this.emit('disconnect');
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
async signIn(input) {
|
|
169
|
+
return this.#runWithGuard(async () => {
|
|
170
|
+
if (this.#readyState !== WalletReadyState.Installed && this.#readyState !== WalletReadyState.Loadable) {
|
|
171
|
+
throw new WalletNotReadyError();
|
|
172
|
+
}
|
|
173
|
+
this.#connecting = true;
|
|
210
174
|
try {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
175
|
+
const outputs = await this.#wallet.features[SolanaSignIn].signIn({
|
|
176
|
+
...input,
|
|
177
|
+
domain: input?.domain ?? window.location.host
|
|
178
|
+
});
|
|
179
|
+
if (outputs.length > 0) {
|
|
180
|
+
return outputs[0];
|
|
215
181
|
}
|
|
216
|
-
|
|
217
|
-
|
|
182
|
+
else {
|
|
183
|
+
throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
218
184
|
}
|
|
219
|
-
else
|
|
220
|
-
yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect();
|
|
221
|
-
const authorizationResult = yield yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").cachedAuthorizationResult;
|
|
222
|
-
return authorizationResult;
|
|
223
185
|
}
|
|
224
186
|
catch (e) {
|
|
225
187
|
throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
226
188
|
}
|
|
189
|
+
finally {
|
|
190
|
+
this.#connecting = false;
|
|
191
|
+
}
|
|
227
192
|
});
|
|
228
193
|
}
|
|
229
|
-
|
|
230
|
-
return
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
194
|
+
async signMessage(message) {
|
|
195
|
+
return await this.#runWithGuard(async () => {
|
|
196
|
+
const account = this.#assertIsAuthorized();
|
|
197
|
+
try {
|
|
198
|
+
const outputs = await this.#wallet.features[SolanaSignMessage].signMessage({
|
|
199
|
+
account, message: message
|
|
200
|
+
});
|
|
201
|
+
return outputs[0].signature;
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
throw new WalletSignMessageError(error?.message, error);
|
|
205
|
+
}
|
|
239
206
|
});
|
|
240
207
|
}
|
|
241
|
-
|
|
242
|
-
return
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
208
|
+
async sendTransaction(transaction, connection, options) {
|
|
209
|
+
return await this.#runWithGuard(async () => {
|
|
210
|
+
const account = this.#assertIsAuthorized();
|
|
211
|
+
try {
|
|
212
|
+
function getTargetCommitment() {
|
|
213
|
+
let targetCommitment;
|
|
214
|
+
switch (connection.commitment) {
|
|
215
|
+
case 'confirmed':
|
|
216
|
+
case 'finalized':
|
|
217
|
+
case 'processed':
|
|
218
|
+
targetCommitment = connection.commitment;
|
|
219
|
+
break;
|
|
220
|
+
default:
|
|
221
|
+
targetCommitment = 'finalized';
|
|
253
222
|
}
|
|
254
|
-
|
|
255
|
-
|
|
223
|
+
let targetPreflightCommitment;
|
|
224
|
+
switch (options?.preflightCommitment) {
|
|
225
|
+
case 'confirmed':
|
|
226
|
+
case 'finalized':
|
|
227
|
+
case 'processed':
|
|
228
|
+
targetPreflightCommitment = options.preflightCommitment;
|
|
229
|
+
break;
|
|
230
|
+
case undefined:
|
|
231
|
+
targetPreflightCommitment = targetCommitment;
|
|
232
|
+
break;
|
|
233
|
+
default:
|
|
234
|
+
targetPreflightCommitment = 'finalized';
|
|
256
235
|
}
|
|
236
|
+
const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
|
|
237
|
+
? 2
|
|
238
|
+
: targetPreflightCommitment === 'confirmed'
|
|
239
|
+
? 1
|
|
240
|
+
: 0;
|
|
241
|
+
const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
|
|
242
|
+
return preflightCommitmentScore < targetCommitmentScore
|
|
243
|
+
? targetPreflightCommitment
|
|
244
|
+
: targetCommitment;
|
|
257
245
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
246
|
+
if (SolanaSignAndSendTransaction in this.#wallet.features) {
|
|
247
|
+
const chain = chainOrClusterToChainId(this.#wallet.currentAuthorization.chain);
|
|
248
|
+
const [signature] = (await this.#wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction({
|
|
249
|
+
account,
|
|
250
|
+
transaction: transaction.serialize(),
|
|
251
|
+
chain: chain,
|
|
252
|
+
options: options ? {
|
|
253
|
+
skipPreflight: options.skipPreflight,
|
|
254
|
+
maxRetries: options.maxRetries
|
|
255
|
+
} : undefined
|
|
256
|
+
})).map(((output) => {
|
|
257
|
+
return fromUint8Array(output.signature);
|
|
258
|
+
}));
|
|
259
|
+
return signature;
|
|
263
260
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
-
return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
270
|
-
const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
|
|
271
|
-
try {
|
|
272
|
-
const outputs = yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[SolanaSignMessage].signMessage({
|
|
273
|
-
account, message: message
|
|
274
|
-
});
|
|
275
|
-
return outputs[0].signature;
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
throw new WalletSignMessageError(error === null || error === void 0 ? void 0 : error.message, error);
|
|
279
|
-
}
|
|
280
|
-
}));
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
sendTransaction(transaction, connection, options) {
|
|
284
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
-
return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
286
|
-
const account = __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_assertIsAuthorized).call(this);
|
|
287
|
-
try {
|
|
288
|
-
function getTargetCommitment() {
|
|
289
|
-
let targetCommitment;
|
|
290
|
-
switch (connection.commitment) {
|
|
291
|
-
case 'confirmed':
|
|
292
|
-
case 'finalized':
|
|
293
|
-
case 'processed':
|
|
294
|
-
targetCommitment = connection.commitment;
|
|
295
|
-
break;
|
|
296
|
-
default:
|
|
297
|
-
targetCommitment = 'finalized';
|
|
298
|
-
}
|
|
299
|
-
let targetPreflightCommitment;
|
|
300
|
-
switch (options === null || options === void 0 ? void 0 : options.preflightCommitment) {
|
|
301
|
-
case 'confirmed':
|
|
302
|
-
case 'finalized':
|
|
303
|
-
case 'processed':
|
|
304
|
-
targetPreflightCommitment = options.preflightCommitment;
|
|
305
|
-
break;
|
|
306
|
-
case undefined:
|
|
307
|
-
targetPreflightCommitment = targetCommitment;
|
|
308
|
-
break;
|
|
309
|
-
default:
|
|
310
|
-
targetPreflightCommitment = 'finalized';
|
|
311
|
-
}
|
|
312
|
-
const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
|
|
313
|
-
? 2
|
|
314
|
-
: targetPreflightCommitment === 'confirmed'
|
|
315
|
-
? 1
|
|
316
|
-
: 0;
|
|
317
|
-
const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
|
|
318
|
-
return preflightCommitmentScore < targetCommitmentScore
|
|
319
|
-
? targetPreflightCommitment
|
|
320
|
-
: targetCommitment;
|
|
321
|
-
}
|
|
322
|
-
if (SolanaSignAndSendTransaction in __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features) {
|
|
323
|
-
const chain = chainOrClusterToChainId(__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").currentAuthorization.chain);
|
|
324
|
-
const [signature] = (yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[SolanaSignAndSendTransaction].signAndSendTransaction({
|
|
325
|
-
account,
|
|
326
|
-
transaction: transaction.serialize(),
|
|
327
|
-
chain: chain,
|
|
328
|
-
options: options ? {
|
|
329
|
-
skipPreflight: options.skipPreflight,
|
|
330
|
-
maxRetries: options.maxRetries
|
|
331
|
-
} : undefined
|
|
332
|
-
})).map(((output) => {
|
|
333
|
-
return fromUint8Array(output.signature);
|
|
334
|
-
}));
|
|
335
|
-
return signature;
|
|
261
|
+
else {
|
|
262
|
+
const [signedTransaction] = await this.#performSignTransactions([transaction]);
|
|
263
|
+
if (isVersionedTransaction(signedTransaction)) {
|
|
264
|
+
return await connection.sendTransaction(signedTransaction);
|
|
336
265
|
}
|
|
337
266
|
else {
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
const serializedTransaction = signedTransaction.serialize();
|
|
344
|
-
return yield connection.sendRawTransaction(serializedTransaction, Object.assign(Object.assign({}, options), { preflightCommitment: getTargetCommitment() }));
|
|
345
|
-
}
|
|
267
|
+
const serializedTransaction = signedTransaction.serialize();
|
|
268
|
+
return await connection.sendRawTransaction(serializedTransaction, {
|
|
269
|
+
...options,
|
|
270
|
+
preflightCommitment: getTargetCommitment(),
|
|
271
|
+
});
|
|
346
272
|
}
|
|
347
273
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
throw new WalletSendTransactionError(error?.message, error);
|
|
277
|
+
}
|
|
352
278
|
});
|
|
353
279
|
}
|
|
354
|
-
signTransaction(transaction) {
|
|
355
|
-
return
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return signedTransaction;
|
|
359
|
-
}));
|
|
280
|
+
async signTransaction(transaction) {
|
|
281
|
+
return await this.#runWithGuard(async () => {
|
|
282
|
+
const [signedTransaction] = await this.#performSignTransactions([transaction]);
|
|
283
|
+
return signedTransaction;
|
|
360
284
|
});
|
|
361
285
|
}
|
|
362
|
-
signAllTransactions(transactions) {
|
|
363
|
-
return
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
return signedTransactions;
|
|
367
|
-
}));
|
|
286
|
+
async signAllTransactions(transactions) {
|
|
287
|
+
return await this.#runWithGuard(async () => {
|
|
288
|
+
const signedTransactions = await this.#performSignTransactions(transactions);
|
|
289
|
+
return signedTransactions;
|
|
368
290
|
});
|
|
369
291
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (this.connecting || this.connected) {
|
|
374
|
-
return;
|
|
292
|
+
#declareWalletAsInstalled() {
|
|
293
|
+
if (this.#readyState !== WalletReadyState.Installed) {
|
|
294
|
+
this.emit('readyStateChange', (this.#readyState = WalletReadyState.Installed));
|
|
375
295
|
}
|
|
376
|
-
return yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_instances, "m", _BaseSolanaMobileWalletAdapter_runWithGuard).call(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
377
|
-
if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== WalletReadyState.Installed && __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== WalletReadyState.Loadable) {
|
|
378
|
-
throw new WalletNotReadyError();
|
|
379
|
-
}
|
|
380
|
-
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, true, "f");
|
|
381
|
-
try {
|
|
382
|
-
yield __classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_wallet, "f").features[StandardConnect].connect({ silent: autoConnect });
|
|
383
|
-
}
|
|
384
|
-
catch (e) {
|
|
385
|
-
throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
386
|
-
}
|
|
387
|
-
finally {
|
|
388
|
-
__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_connecting, false, "f");
|
|
389
|
-
}
|
|
390
|
-
}));
|
|
391
|
-
});
|
|
392
|
-
}, _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled = function _BaseSolanaMobileWalletAdapter_declareWalletAsInstalled() {
|
|
393
|
-
if (__classPrivateFieldGet(this, _BaseSolanaMobileWalletAdapter_readyState, "f") !== WalletReadyState.Installed) {
|
|
394
|
-
this.emit('readyStateChange', (__classPrivateFieldSet(this, _BaseSolanaMobileWalletAdapter_readyState, WalletReadyState.Installed, "f")));
|
|
395
296
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const account =
|
|
297
|
+
#assertIsAuthorized() {
|
|
298
|
+
if (!this.#wallet.isAuthorized || !this.#selectedAccount)
|
|
299
|
+
throw new WalletNotConnectedError();
|
|
300
|
+
return this.#selectedAccount;
|
|
301
|
+
}
|
|
302
|
+
async #performSignTransactions(transactions) {
|
|
303
|
+
const account = this.#assertIsAuthorized();
|
|
403
304
|
try {
|
|
404
|
-
if (SolanaSignTransaction in
|
|
405
|
-
return
|
|
305
|
+
if (SolanaSignTransaction in this.#wallet.features) {
|
|
306
|
+
return this.#wallet.features[SolanaSignTransaction].signTransaction(...transactions.map((value) => {
|
|
406
307
|
return { account, transaction: value.serialize() };
|
|
407
308
|
})).then((outputs) => {
|
|
408
309
|
return outputs.map((output) => {
|
|
@@ -424,38 +325,36 @@ _BaseSolanaMobileWalletAdapter_wallet = new WeakMap(), _BaseSolanaMobileWalletAd
|
|
|
424
325
|
}
|
|
425
326
|
}
|
|
426
327
|
catch (error) {
|
|
427
|
-
throw new WalletSignTransactionError(error
|
|
328
|
+
throw new WalletSignTransactionError(error?.message, error);
|
|
428
329
|
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
330
|
+
}
|
|
331
|
+
async #runWithGuard(callback) {
|
|
432
332
|
try {
|
|
433
|
-
return
|
|
333
|
+
return await callback();
|
|
434
334
|
}
|
|
435
335
|
catch (e) {
|
|
436
336
|
this.emit('error', e);
|
|
437
337
|
throw e;
|
|
438
338
|
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
441
341
|
class LocalSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
|
|
442
342
|
constructor(config) {
|
|
443
|
-
|
|
444
|
-
const chain = chainOrClusterToChainId((_a = config.chain) !== null && _a !== void 0 ? _a : config.cluster);
|
|
343
|
+
const chain = chainOrClusterToChainId(config.chain ?? config.cluster);
|
|
445
344
|
super(new LocalSolanaMobileWalletAdapterWallet({
|
|
446
345
|
appIdentity: config.appIdentity,
|
|
447
346
|
authorizationCache: {
|
|
448
347
|
set: config.authorizationResultCache.set,
|
|
449
|
-
get: () =>
|
|
450
|
-
return
|
|
451
|
-
}
|
|
348
|
+
get: async () => {
|
|
349
|
+
return await config.authorizationResultCache.get();
|
|
350
|
+
},
|
|
452
351
|
clear: config.authorizationResultCache.clear,
|
|
453
352
|
},
|
|
454
353
|
chains: [chain],
|
|
455
354
|
chainSelector: createDefaultChainSelector(),
|
|
456
|
-
onWalletNotFound: () =>
|
|
355
|
+
onWalletNotFound: async () => {
|
|
457
356
|
config.onWalletNotFound(this);
|
|
458
|
-
}
|
|
357
|
+
},
|
|
459
358
|
}), {
|
|
460
359
|
addressSelector: config.addressSelector,
|
|
461
360
|
chain: chain,
|
|
@@ -469,17 +368,17 @@ class RemoteSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
|
|
|
469
368
|
appIdentity: config.appIdentity,
|
|
470
369
|
authorizationCache: {
|
|
471
370
|
set: config.authorizationResultCache.set,
|
|
472
|
-
get: () =>
|
|
473
|
-
return
|
|
474
|
-
}
|
|
371
|
+
get: async () => {
|
|
372
|
+
return await config.authorizationResultCache.get();
|
|
373
|
+
},
|
|
475
374
|
clear: config.authorizationResultCache.clear,
|
|
476
375
|
},
|
|
477
376
|
chains: [chain],
|
|
478
377
|
chainSelector: createDefaultChainSelector(),
|
|
479
378
|
remoteHostAuthority: config.remoteHostAuthority,
|
|
480
|
-
onWalletNotFound: () =>
|
|
379
|
+
onWalletNotFound: async () => {
|
|
481
380
|
config.onWalletNotFound(this);
|
|
482
|
-
}
|
|
381
|
+
},
|
|
483
382
|
}), {
|
|
484
383
|
addressSelector: config.addressSelector,
|
|
485
384
|
chain: chain,
|
|
@@ -491,10 +390,8 @@ class SolanaMobileWalletAdapter extends LocalSolanaMobileWalletAdapter {
|
|
|
491
390
|
|
|
492
391
|
function createDefaultAddressSelector() {
|
|
493
392
|
return {
|
|
494
|
-
select(addresses) {
|
|
495
|
-
return
|
|
496
|
-
return addresses[0];
|
|
497
|
-
});
|
|
393
|
+
async select(addresses) {
|
|
394
|
+
return addresses[0];
|
|
498
395
|
},
|
|
499
396
|
};
|
|
500
397
|
}
|
|
@@ -503,10 +400,8 @@ function createDefaultAuthorizationResultCache() {
|
|
|
503
400
|
return createDefaultAuthorizationCache();
|
|
504
401
|
}
|
|
505
402
|
|
|
506
|
-
function defaultWalletNotFoundHandler(mobileWalletAdapter) {
|
|
507
|
-
return
|
|
508
|
-
return defaultErrorModalWalletNotFoundHandler();
|
|
509
|
-
});
|
|
403
|
+
async function defaultWalletNotFoundHandler(mobileWalletAdapter) {
|
|
404
|
+
return defaultErrorModalWalletNotFoundHandler();
|
|
510
405
|
}
|
|
511
406
|
function createDefaultWalletNotFoundHandler() {
|
|
512
407
|
return defaultWalletNotFoundHandler;
|