@solana-mobile/wallet-adapter-mobile 2.2.6 → 2.2.8
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 +4 -5
- package/lib/cjs/index.browser.js +324 -394
- package/lib/cjs/index.browser.js.map +1 -0
- package/lib/cjs/index.js +324 -394
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/index.native.js +364 -415
- package/lib/cjs/index.native.js.map +1 -0
- package/lib/cjs/package.json +1 -3
- package/lib/esm/index.browser.js +321 -390
- package/lib/esm/index.browser.js.map +1 -0
- package/lib/esm/index.js +321 -390
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -3
- package/lib/types/index.d.ts +67 -60
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +12 -11
- package/lib/types/index.browser.d.ts +0 -79
- package/lib/types/index.browser.d.ts.map +0 -1
- package/lib/types/index.native.d.ts +0 -79
- package/lib/types/index.native.d.ts.map +0 -1
package/lib/cjs/index.browser.js
CHANGED
|
@@ -1,414 +1,342 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _solana_wallet_adapter_base = require("@solana/wallet-adapter-base");
|
|
3
|
+
let _solana_wallet_standard_features = require("@solana/wallet-standard-features");
|
|
4
|
+
let _solana_web3_js = require("@solana/web3.js");
|
|
5
|
+
let _solana_mobile_wallet_standard_mobile = require("@solana-mobile/wallet-standard-mobile");
|
|
6
|
+
let _wallet_standard_core = require("@wallet-standard/core");
|
|
7
|
+
//#region src/base64Utils.ts
|
|
9
8
|
function fromUint8Array(byteArray) {
|
|
10
|
-
|
|
9
|
+
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
11
10
|
}
|
|
12
|
-
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/getIsSupported.ts
|
|
13
13
|
function getIsSupported() {
|
|
14
|
-
|
|
15
|
-
window.isSecureContext &&
|
|
16
|
-
typeof document !== 'undefined' &&
|
|
17
|
-
/android/i.test(navigator.userAgent));
|
|
14
|
+
return typeof window !== "undefined" && window.isSecureContext && typeof document !== "undefined" && /android/i.test(navigator.userAgent);
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/adapter.ts
|
|
18
|
+
const SolanaMobileWalletAdapterWalletName = _solana_mobile_wallet_standard_mobile.SolanaMobileWalletAdapterWalletName;
|
|
19
|
+
const SolanaMobileWalletAdapterRemoteWalletName = _solana_mobile_wallet_standard_mobile.SolanaMobileWalletAdapterRemoteWalletName;
|
|
22
20
|
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
23
21
|
function isVersionedTransaction(transaction) {
|
|
24
|
-
|
|
22
|
+
return "version" in transaction;
|
|
25
23
|
}
|
|
26
24
|
function chainOrClusterToChainId(chain) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return 'solana:devnet';
|
|
34
|
-
default:
|
|
35
|
-
return chain;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
class BaseSolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageSignerWalletAdapter {
|
|
39
|
-
supportedTransactionVersions = new Set(
|
|
40
|
-
// FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
|
|
41
|
-
['legacy', 0]);
|
|
42
|
-
name;
|
|
43
|
-
icon;
|
|
44
|
-
url;
|
|
45
|
-
#wallet;
|
|
46
|
-
#connecting = false;
|
|
47
|
-
#readyState = getIsSupported() ? walletAdapterBase.WalletReadyState.Loadable : walletAdapterBase.WalletReadyState.Unsupported;
|
|
48
|
-
#accountSelector;
|
|
49
|
-
#selectedAccount;
|
|
50
|
-
#publicKey;
|
|
51
|
-
#handleChangeEvent = async (properties) => {
|
|
52
|
-
if (properties.accounts && properties.accounts.length > 0) {
|
|
53
|
-
this.#declareWalletAsInstalled();
|
|
54
|
-
const nextSelectedAccount = await this.#accountSelector(properties.accounts);
|
|
55
|
-
if (nextSelectedAccount !== this.#selectedAccount) {
|
|
56
|
-
this.#selectedAccount = nextSelectedAccount;
|
|
57
|
-
this.#publicKey = undefined;
|
|
58
|
-
this.emit('connect',
|
|
59
|
-
// Having just set `this.#selectedAccount`, `this.publicKey` is definitely non-null
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
61
|
-
this.publicKey);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
constructor(wallet, config) {
|
|
66
|
-
super();
|
|
67
|
-
// this.#chain = chainOrClusterToChainId(config.chain);
|
|
68
|
-
this.#accountSelector = async (accounts) => {
|
|
69
|
-
const selectedBase64EncodedAddress = await config.addressSelector.select(accounts.map(({ publicKey }) => fromUint8Array(new Uint8Array(publicKey))));
|
|
70
|
-
return accounts.find(({ publicKey }) => fromUint8Array(new Uint8Array(publicKey)) === selectedBase64EncodedAddress) ?? accounts[0];
|
|
71
|
-
};
|
|
72
|
-
this.#wallet = wallet;
|
|
73
|
-
this.#wallet.features[core.StandardEvents].on('change', this.#handleChangeEvent);
|
|
74
|
-
this.name = this.#wallet.name;
|
|
75
|
-
this.icon = this.#wallet.icon;
|
|
76
|
-
this.url = this.#wallet.url;
|
|
77
|
-
// TODO: evaluate if this logic should be kept - it seems to create a nasty bug where
|
|
78
|
-
// the wallet tries to auto connect on page load and gets blocked by the popup blocker
|
|
79
|
-
// if (this.#readyState !== WalletReadyState.Unsupported) {
|
|
80
|
-
// config.authorizationResultCache.get().then((authorizationResult) => {
|
|
81
|
-
// if (authorizationResult) {
|
|
82
|
-
// // Having a prior authorization result is, right now, the best
|
|
83
|
-
// // indication that a mobile wallet is installed. There is no API
|
|
84
|
-
// // we can use to test for whether the association URI is supported.
|
|
85
|
-
// this.#declareWalletAsInstalled();
|
|
86
|
-
// }
|
|
87
|
-
// });
|
|
88
|
-
// }
|
|
89
|
-
}
|
|
90
|
-
get publicKey() {
|
|
91
|
-
if (!this.#publicKey && this.#selectedAccount) {
|
|
92
|
-
try {
|
|
93
|
-
this.#publicKey = new web3_js.PublicKey(this.#selectedAccount.publicKey);
|
|
94
|
-
}
|
|
95
|
-
catch (e) {
|
|
96
|
-
throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && e?.message) || 'Unknown error', e);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return this.#publicKey ?? null;
|
|
100
|
-
}
|
|
101
|
-
get connected() {
|
|
102
|
-
return this.#wallet.connected;
|
|
103
|
-
}
|
|
104
|
-
get connecting() {
|
|
105
|
-
return this.#connecting;
|
|
106
|
-
}
|
|
107
|
-
get readyState() {
|
|
108
|
-
return this.#readyState;
|
|
109
|
-
}
|
|
110
|
-
/** @deprecated Use `autoConnect()` instead. */
|
|
111
|
-
async autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
|
|
112
|
-
return await this.autoConnect();
|
|
113
|
-
}
|
|
114
|
-
async autoConnect() {
|
|
115
|
-
this.#connect(true);
|
|
116
|
-
}
|
|
117
|
-
async connect() {
|
|
118
|
-
this.#connect();
|
|
119
|
-
}
|
|
120
|
-
async #connect(autoConnect = false) {
|
|
121
|
-
if (this.connecting || this.connected) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
return await this.#runWithGuard(async () => {
|
|
125
|
-
if (this.#readyState !== walletAdapterBase.WalletReadyState.Installed && this.#readyState !== walletAdapterBase.WalletReadyState.Loadable) {
|
|
126
|
-
throw new walletAdapterBase.WalletNotReadyError();
|
|
127
|
-
}
|
|
128
|
-
this.#connecting = true;
|
|
129
|
-
try {
|
|
130
|
-
await this.#wallet.features[core.StandardConnect].connect({ silent: autoConnect });
|
|
131
|
-
}
|
|
132
|
-
catch (e) {
|
|
133
|
-
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
134
|
-
}
|
|
135
|
-
finally {
|
|
136
|
-
this.#connecting = false;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
/** @deprecated Use `connect()` or `autoConnect()` instead. */
|
|
141
|
-
async performAuthorization(signInPayload) {
|
|
142
|
-
try {
|
|
143
|
-
const cachedAuthorizationResult = await this.#wallet.cachedAuthorizationResult;
|
|
144
|
-
if (cachedAuthorizationResult) {
|
|
145
|
-
await this.#wallet.features[core.StandardConnect].connect({ silent: true });
|
|
146
|
-
return cachedAuthorizationResult;
|
|
147
|
-
}
|
|
148
|
-
if (signInPayload) {
|
|
149
|
-
await this.#wallet.features[walletStandardFeatures.SolanaSignIn].signIn(signInPayload);
|
|
150
|
-
}
|
|
151
|
-
else
|
|
152
|
-
await this.#wallet.features[core.StandardConnect].connect();
|
|
153
|
-
const authorizationResult = await await this.#wallet.cachedAuthorizationResult;
|
|
154
|
-
return authorizationResult;
|
|
155
|
-
}
|
|
156
|
-
catch (e) {
|
|
157
|
-
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
async disconnect() {
|
|
161
|
-
// return await this.#runWithGuard(this.#wallet.features[StandardDisconnect].disconnect);
|
|
162
|
-
return await this.#runWithGuard(async () => {
|
|
163
|
-
this.#connecting = false;
|
|
164
|
-
this.#publicKey = undefined;
|
|
165
|
-
this.#selectedAccount = undefined;
|
|
166
|
-
await this.#wallet.features[core.StandardDisconnect].disconnect();
|
|
167
|
-
this.emit('disconnect');
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
async signIn(input) {
|
|
171
|
-
return this.#runWithGuard(async () => {
|
|
172
|
-
if (this.#readyState !== walletAdapterBase.WalletReadyState.Installed && this.#readyState !== walletAdapterBase.WalletReadyState.Loadable) {
|
|
173
|
-
throw new walletAdapterBase.WalletNotReadyError();
|
|
174
|
-
}
|
|
175
|
-
this.#connecting = true;
|
|
176
|
-
try {
|
|
177
|
-
const outputs = await this.#wallet.features[walletStandardFeatures.SolanaSignIn].signIn({
|
|
178
|
-
...input,
|
|
179
|
-
domain: input?.domain ?? window.location.host
|
|
180
|
-
});
|
|
181
|
-
if (outputs.length > 0) {
|
|
182
|
-
return outputs[0];
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (e) {
|
|
189
|
-
throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
|
|
190
|
-
}
|
|
191
|
-
finally {
|
|
192
|
-
this.#connecting = false;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
async signMessage(message) {
|
|
197
|
-
return await this.#runWithGuard(async () => {
|
|
198
|
-
const account = this.#assertIsAuthorized();
|
|
199
|
-
try {
|
|
200
|
-
const outputs = await this.#wallet.features[walletStandardFeatures.SolanaSignMessage].signMessage({
|
|
201
|
-
account, message: message
|
|
202
|
-
});
|
|
203
|
-
return outputs[0].signature;
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
throw new walletAdapterBase.WalletSignMessageError(error?.message, error);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
async sendTransaction(transaction, connection, options) {
|
|
211
|
-
return await this.#runWithGuard(async () => {
|
|
212
|
-
const account = this.#assertIsAuthorized();
|
|
213
|
-
try {
|
|
214
|
-
function getTargetCommitment() {
|
|
215
|
-
let targetCommitment;
|
|
216
|
-
switch (connection.commitment) {
|
|
217
|
-
case 'confirmed':
|
|
218
|
-
case 'finalized':
|
|
219
|
-
case 'processed':
|
|
220
|
-
targetCommitment = connection.commitment;
|
|
221
|
-
break;
|
|
222
|
-
default:
|
|
223
|
-
targetCommitment = 'finalized';
|
|
224
|
-
}
|
|
225
|
-
let targetPreflightCommitment;
|
|
226
|
-
switch (options?.preflightCommitment) {
|
|
227
|
-
case 'confirmed':
|
|
228
|
-
case 'finalized':
|
|
229
|
-
case 'processed':
|
|
230
|
-
targetPreflightCommitment = options.preflightCommitment;
|
|
231
|
-
break;
|
|
232
|
-
case undefined:
|
|
233
|
-
targetPreflightCommitment = targetCommitment;
|
|
234
|
-
break;
|
|
235
|
-
default:
|
|
236
|
-
targetPreflightCommitment = 'finalized';
|
|
237
|
-
}
|
|
238
|
-
const preflightCommitmentScore = targetPreflightCommitment === 'finalized'
|
|
239
|
-
? 2
|
|
240
|
-
: targetPreflightCommitment === 'confirmed'
|
|
241
|
-
? 1
|
|
242
|
-
: 0;
|
|
243
|
-
const targetCommitmentScore = targetCommitment === 'finalized' ? 2 : targetCommitment === 'confirmed' ? 1 : 0;
|
|
244
|
-
return preflightCommitmentScore < targetCommitmentScore
|
|
245
|
-
? targetPreflightCommitment
|
|
246
|
-
: targetCommitment;
|
|
247
|
-
}
|
|
248
|
-
if (walletStandardFeatures.SolanaSignAndSendTransaction in this.#wallet.features) {
|
|
249
|
-
const chain = chainOrClusterToChainId(this.#wallet.currentAuthorization.chain);
|
|
250
|
-
const [signature] = (await this.#wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
|
|
251
|
-
account,
|
|
252
|
-
transaction: transaction.serialize(),
|
|
253
|
-
chain: chain,
|
|
254
|
-
options: options ? {
|
|
255
|
-
skipPreflight: options.skipPreflight,
|
|
256
|
-
maxRetries: options.maxRetries
|
|
257
|
-
} : undefined
|
|
258
|
-
})).map(((output) => {
|
|
259
|
-
return fromUint8Array(output.signature);
|
|
260
|
-
}));
|
|
261
|
-
return signature;
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
const [signedTransaction] = await this.#performSignTransactions([transaction]);
|
|
265
|
-
if (isVersionedTransaction(signedTransaction)) {
|
|
266
|
-
return await connection.sendTransaction(signedTransaction);
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
const serializedTransaction = signedTransaction.serialize();
|
|
270
|
-
return await connection.sendRawTransaction(serializedTransaction, {
|
|
271
|
-
...options,
|
|
272
|
-
preflightCommitment: getTargetCommitment(),
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
throw new walletAdapterBase.WalletSendTransactionError(error?.message, error);
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
async signTransaction(transaction) {
|
|
283
|
-
return await this.#runWithGuard(async () => {
|
|
284
|
-
const [signedTransaction] = await this.#performSignTransactions([transaction]);
|
|
285
|
-
return signedTransaction;
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
async signAllTransactions(transactions) {
|
|
289
|
-
return await this.#runWithGuard(async () => {
|
|
290
|
-
const signedTransactions = await this.#performSignTransactions(transactions);
|
|
291
|
-
return signedTransactions;
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
#declareWalletAsInstalled() {
|
|
295
|
-
if (this.#readyState !== walletAdapterBase.WalletReadyState.Installed) {
|
|
296
|
-
this.emit('readyStateChange', (this.#readyState = walletAdapterBase.WalletReadyState.Installed));
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
#assertIsAuthorized() {
|
|
300
|
-
if (!this.#wallet.isAuthorized || !this.#selectedAccount)
|
|
301
|
-
throw new walletAdapterBase.WalletNotConnectedError();
|
|
302
|
-
return this.#selectedAccount;
|
|
303
|
-
}
|
|
304
|
-
async #performSignTransactions(transactions) {
|
|
305
|
-
const account = this.#assertIsAuthorized();
|
|
306
|
-
try {
|
|
307
|
-
if (walletStandardFeatures.SolanaSignTransaction in this.#wallet.features) {
|
|
308
|
-
return this.#wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(...transactions.map((value) => {
|
|
309
|
-
return { account, transaction: value.serialize() };
|
|
310
|
-
})).then((outputs) => {
|
|
311
|
-
return outputs.map((output) => {
|
|
312
|
-
const byteArray = output.signedTransaction;
|
|
313
|
-
const numSignatures = byteArray[0];
|
|
314
|
-
const messageOffset = numSignatures * SIGNATURE_LENGTH_IN_BYTES + 1;
|
|
315
|
-
const version = web3_js.VersionedMessage.deserializeMessageVersion(byteArray.slice(messageOffset, byteArray.length));
|
|
316
|
-
if (version === 'legacy') {
|
|
317
|
-
return web3_js.Transaction.from(byteArray);
|
|
318
|
-
}
|
|
319
|
-
else {
|
|
320
|
-
return web3_js.VersionedTransaction.deserialize(byteArray);
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
326
|
-
throw new Error('Connected wallet does not support signing transactions');
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
catch (error) {
|
|
330
|
-
throw new walletAdapterBase.WalletSignTransactionError(error?.message, error);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
async #runWithGuard(callback) {
|
|
334
|
-
try {
|
|
335
|
-
return await callback();
|
|
336
|
-
}
|
|
337
|
-
catch (e) {
|
|
338
|
-
this.emit('error', e);
|
|
339
|
-
throw e;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
class LocalSolanaMobileWalletAdapter extends BaseSolanaMobileWalletAdapter {
|
|
344
|
-
constructor(config) {
|
|
345
|
-
const chain = chainOrClusterToChainId(config.chain ?? config.cluster);
|
|
346
|
-
super(new walletStandardMobile.LocalSolanaMobileWalletAdapterWallet({
|
|
347
|
-
appIdentity: config.appIdentity,
|
|
348
|
-
authorizationCache: {
|
|
349
|
-
set: config.authorizationResultCache.set,
|
|
350
|
-
get: async () => {
|
|
351
|
-
return await config.authorizationResultCache.get();
|
|
352
|
-
},
|
|
353
|
-
clear: config.authorizationResultCache.clear,
|
|
354
|
-
},
|
|
355
|
-
chains: [chain],
|
|
356
|
-
chainSelector: walletStandardMobile.createDefaultChainSelector(),
|
|
357
|
-
onWalletNotFound: async () => {
|
|
358
|
-
config.onWalletNotFound(this);
|
|
359
|
-
},
|
|
360
|
-
}), {
|
|
361
|
-
addressSelector: config.addressSelector,
|
|
362
|
-
chain: chain,
|
|
363
|
-
});
|
|
364
|
-
}
|
|
25
|
+
switch (chain) {
|
|
26
|
+
case "mainnet-beta": return "solana:mainnet";
|
|
27
|
+
case "testnet": return "solana:testnet";
|
|
28
|
+
case "devnet": return "solana:devnet";
|
|
29
|
+
default: return chain;
|
|
30
|
+
}
|
|
365
31
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const chain = chainOrClusterToChainId(config.chain);
|
|
369
|
-
super(new walletStandardMobile.RemoteSolanaMobileWalletAdapterWallet({
|
|
370
|
-
appIdentity: config.appIdentity,
|
|
371
|
-
authorizationCache: {
|
|
372
|
-
set: config.authorizationResultCache.set,
|
|
373
|
-
get: async () => {
|
|
374
|
-
return await config.authorizationResultCache.get();
|
|
375
|
-
},
|
|
376
|
-
clear: config.authorizationResultCache.clear,
|
|
377
|
-
},
|
|
378
|
-
chains: [chain],
|
|
379
|
-
chainSelector: walletStandardMobile.createDefaultChainSelector(),
|
|
380
|
-
remoteHostAuthority: config.remoteHostAuthority,
|
|
381
|
-
onWalletNotFound: async () => {
|
|
382
|
-
config.onWalletNotFound(this);
|
|
383
|
-
},
|
|
384
|
-
}), {
|
|
385
|
-
addressSelector: config.addressSelector,
|
|
386
|
-
chain: chain,
|
|
387
|
-
});
|
|
388
|
-
}
|
|
32
|
+
function getErrorMessage(error) {
|
|
33
|
+
return error instanceof Error ? error.message : "Unknown error";
|
|
389
34
|
}
|
|
390
|
-
class
|
|
391
|
-
|
|
392
|
-
|
|
35
|
+
var BaseSolanaMobileWalletAdapter = class extends _solana_wallet_adapter_base.BaseSignInMessageSignerWalletAdapter {
|
|
36
|
+
supportedTransactionVersions = new Set(["legacy", 0]);
|
|
37
|
+
name;
|
|
38
|
+
icon;
|
|
39
|
+
url;
|
|
40
|
+
#wallet;
|
|
41
|
+
#connecting = false;
|
|
42
|
+
#readyState = getIsSupported() ? _solana_wallet_adapter_base.WalletReadyState.Loadable : _solana_wallet_adapter_base.WalletReadyState.Unsupported;
|
|
43
|
+
#accountSelector;
|
|
44
|
+
#selectedAccount;
|
|
45
|
+
#publicKey;
|
|
46
|
+
#handleChangeEvent = async (properties) => {
|
|
47
|
+
if (properties.accounts && properties.accounts.length > 0) {
|
|
48
|
+
this.#declareWalletAsInstalled();
|
|
49
|
+
const nextSelectedAccount = await this.#accountSelector(properties.accounts);
|
|
50
|
+
if (nextSelectedAccount !== this.#selectedAccount) {
|
|
51
|
+
this.#selectedAccount = nextSelectedAccount;
|
|
52
|
+
this.#publicKey = void 0;
|
|
53
|
+
this.emit("connect", this.publicKey);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
constructor(wallet, config) {
|
|
58
|
+
super();
|
|
59
|
+
this.#accountSelector = async (accounts) => {
|
|
60
|
+
const selectedBase64EncodedAddress = await config.addressSelector.select(accounts.map(({ publicKey }) => fromUint8Array(new Uint8Array(publicKey))));
|
|
61
|
+
return accounts.find(({ publicKey }) => fromUint8Array(new Uint8Array(publicKey)) === selectedBase64EncodedAddress) ?? accounts[0];
|
|
62
|
+
};
|
|
63
|
+
this.#wallet = wallet;
|
|
64
|
+
this.#wallet.features[_wallet_standard_core.StandardEvents].on("change", this.#handleChangeEvent);
|
|
65
|
+
this.name = this.#wallet.name;
|
|
66
|
+
this.icon = this.#wallet.icon;
|
|
67
|
+
this.url = this.#wallet.url;
|
|
68
|
+
}
|
|
69
|
+
get publicKey() {
|
|
70
|
+
if (!this.#publicKey && this.#selectedAccount) try {
|
|
71
|
+
this.#publicKey = new _solana_web3_js.PublicKey(this.#selectedAccount.publicKey);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
throw new _solana_wallet_adapter_base.WalletPublicKeyError(e instanceof Error && e?.message || "Unknown error", e);
|
|
74
|
+
}
|
|
75
|
+
return this.#publicKey ?? null;
|
|
76
|
+
}
|
|
77
|
+
get connected() {
|
|
78
|
+
return this.#wallet.connected;
|
|
79
|
+
}
|
|
80
|
+
get connecting() {
|
|
81
|
+
return this.#connecting;
|
|
82
|
+
}
|
|
83
|
+
get readyState() {
|
|
84
|
+
return this.#readyState;
|
|
85
|
+
}
|
|
86
|
+
/** @deprecated Use `autoConnect()` instead. */
|
|
87
|
+
async autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
|
|
88
|
+
return await this.autoConnect();
|
|
89
|
+
}
|
|
90
|
+
async autoConnect() {
|
|
91
|
+
this.#connect(true);
|
|
92
|
+
}
|
|
93
|
+
async connect() {
|
|
94
|
+
this.#connect();
|
|
95
|
+
}
|
|
96
|
+
async #connect(autoConnect = false) {
|
|
97
|
+
if (this.connecting || this.connected) return;
|
|
98
|
+
return await this.#runWithGuard(async () => {
|
|
99
|
+
if (this.#readyState !== _solana_wallet_adapter_base.WalletReadyState.Installed && this.#readyState !== _solana_wallet_adapter_base.WalletReadyState.Loadable) throw new _solana_wallet_adapter_base.WalletNotReadyError();
|
|
100
|
+
this.#connecting = true;
|
|
101
|
+
try {
|
|
102
|
+
await this.#wallet.features[_wallet_standard_core.StandardConnect].connect({ silent: autoConnect });
|
|
103
|
+
} catch (e) {
|
|
104
|
+
throw new _solana_wallet_adapter_base.WalletConnectionError(e instanceof Error && e.message || "Unknown error", e);
|
|
105
|
+
} finally {
|
|
106
|
+
this.#connecting = false;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/** @deprecated Use `connect()` or `autoConnect()` instead. */
|
|
111
|
+
async performAuthorization(signInPayload) {
|
|
112
|
+
try {
|
|
113
|
+
const cachedAuthorizationResult = await this.#wallet.cachedAuthorizationResult;
|
|
114
|
+
if (cachedAuthorizationResult) {
|
|
115
|
+
await this.#wallet.features[_wallet_standard_core.StandardConnect].connect({ silent: true });
|
|
116
|
+
return cachedAuthorizationResult;
|
|
117
|
+
}
|
|
118
|
+
if (signInPayload) await this.#wallet.features[_solana_wallet_standard_features.SolanaSignIn].signIn(signInPayload);
|
|
119
|
+
else await this.#wallet.features[_wallet_standard_core.StandardConnect].connect();
|
|
120
|
+
return await await this.#wallet.cachedAuthorizationResult;
|
|
121
|
+
} catch (e) {
|
|
122
|
+
throw new _solana_wallet_adapter_base.WalletConnectionError(e instanceof Error && e.message || "Unknown error", e);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async disconnect() {
|
|
126
|
+
return await this.#runWithGuard(async () => {
|
|
127
|
+
this.#connecting = false;
|
|
128
|
+
this.#publicKey = void 0;
|
|
129
|
+
this.#selectedAccount = void 0;
|
|
130
|
+
await this.#wallet.features[_wallet_standard_core.StandardDisconnect].disconnect();
|
|
131
|
+
this.emit("disconnect");
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async signIn(input) {
|
|
135
|
+
return this.#runWithGuard(async () => {
|
|
136
|
+
if (this.#readyState !== _solana_wallet_adapter_base.WalletReadyState.Installed && this.#readyState !== _solana_wallet_adapter_base.WalletReadyState.Loadable) throw new _solana_wallet_adapter_base.WalletNotReadyError();
|
|
137
|
+
this.#connecting = true;
|
|
138
|
+
try {
|
|
139
|
+
const outputs = await this.#wallet.features[_solana_wallet_standard_features.SolanaSignIn].signIn({
|
|
140
|
+
...input,
|
|
141
|
+
domain: input?.domain ?? window.location.host
|
|
142
|
+
});
|
|
143
|
+
if (outputs.length > 0) return outputs[0];
|
|
144
|
+
else throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
145
|
+
} catch (e) {
|
|
146
|
+
throw new _solana_wallet_adapter_base.WalletConnectionError(e instanceof Error && e.message || "Unknown error", e);
|
|
147
|
+
} finally {
|
|
148
|
+
this.#connecting = false;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async signMessage(message) {
|
|
153
|
+
return await this.#runWithGuard(async () => {
|
|
154
|
+
const account = this.#assertIsAuthorized();
|
|
155
|
+
try {
|
|
156
|
+
return (await this.#wallet.features[_solana_wallet_standard_features.SolanaSignMessage].signMessage({
|
|
157
|
+
account,
|
|
158
|
+
message
|
|
159
|
+
}))[0].signature;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
throw new _solana_wallet_adapter_base.WalletSignMessageError(getErrorMessage(error), error);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async sendTransaction(transaction, connection, options) {
|
|
166
|
+
return await this.#runWithGuard(async () => {
|
|
167
|
+
const account = this.#assertIsAuthorized();
|
|
168
|
+
try {
|
|
169
|
+
function getTargetCommitment() {
|
|
170
|
+
let targetCommitment;
|
|
171
|
+
switch (connection.commitment) {
|
|
172
|
+
case "confirmed":
|
|
173
|
+
case "finalized":
|
|
174
|
+
case "processed":
|
|
175
|
+
targetCommitment = connection.commitment;
|
|
176
|
+
break;
|
|
177
|
+
default: targetCommitment = "finalized";
|
|
178
|
+
}
|
|
179
|
+
let targetPreflightCommitment;
|
|
180
|
+
switch (options?.preflightCommitment) {
|
|
181
|
+
case "confirmed":
|
|
182
|
+
case "finalized":
|
|
183
|
+
case "processed":
|
|
184
|
+
targetPreflightCommitment = options.preflightCommitment;
|
|
185
|
+
break;
|
|
186
|
+
case void 0:
|
|
187
|
+
targetPreflightCommitment = targetCommitment;
|
|
188
|
+
break;
|
|
189
|
+
default: targetPreflightCommitment = "finalized";
|
|
190
|
+
}
|
|
191
|
+
return (targetPreflightCommitment === "finalized" ? 2 : targetPreflightCommitment === "confirmed" ? 1 : 0) < (targetCommitment === "finalized" ? 2 : targetCommitment === "confirmed" ? 1 : 0) ? targetPreflightCommitment : targetCommitment;
|
|
192
|
+
}
|
|
193
|
+
if (_solana_wallet_standard_features.SolanaSignAndSendTransaction in this.#wallet.features) {
|
|
194
|
+
const chain = chainOrClusterToChainId(this.#wallet.currentAuthorization.chain);
|
|
195
|
+
const [signature] = (await this.#wallet.features[_solana_wallet_standard_features.SolanaSignAndSendTransaction].signAndSendTransaction({
|
|
196
|
+
account,
|
|
197
|
+
transaction: transaction.serialize(),
|
|
198
|
+
chain,
|
|
199
|
+
options: options ? {
|
|
200
|
+
skipPreflight: options.skipPreflight,
|
|
201
|
+
maxRetries: options.maxRetries
|
|
202
|
+
} : void 0
|
|
203
|
+
})).map((output) => {
|
|
204
|
+
return fromUint8Array(output.signature);
|
|
205
|
+
});
|
|
206
|
+
return signature;
|
|
207
|
+
} else {
|
|
208
|
+
const [signedTransaction] = await this.#performSignTransactions([transaction]);
|
|
209
|
+
if (isVersionedTransaction(signedTransaction)) return await connection.sendTransaction(signedTransaction);
|
|
210
|
+
else {
|
|
211
|
+
const serializedTransaction = signedTransaction.serialize();
|
|
212
|
+
return await connection.sendRawTransaction(serializedTransaction, {
|
|
213
|
+
...options,
|
|
214
|
+
preflightCommitment: getTargetCommitment()
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
throw new _solana_wallet_adapter_base.WalletSendTransactionError(getErrorMessage(error), error);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
async signTransaction(transaction) {
|
|
224
|
+
return await this.#runWithGuard(async () => {
|
|
225
|
+
const [signedTransaction] = await this.#performSignTransactions([transaction]);
|
|
226
|
+
return signedTransaction;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
async signAllTransactions(transactions) {
|
|
230
|
+
return await this.#runWithGuard(async () => {
|
|
231
|
+
return await this.#performSignTransactions(transactions);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
#declareWalletAsInstalled() {
|
|
235
|
+
if (this.#readyState !== _solana_wallet_adapter_base.WalletReadyState.Installed) this.emit("readyStateChange", this.#readyState = _solana_wallet_adapter_base.WalletReadyState.Installed);
|
|
236
|
+
}
|
|
237
|
+
#assertIsAuthorized() {
|
|
238
|
+
if (!this.#wallet.isAuthorized || !this.#selectedAccount) throw new _solana_wallet_adapter_base.WalletNotConnectedError();
|
|
239
|
+
return this.#selectedAccount;
|
|
240
|
+
}
|
|
241
|
+
async #performSignTransactions(transactions) {
|
|
242
|
+
const account = this.#assertIsAuthorized();
|
|
243
|
+
try {
|
|
244
|
+
if (_solana_wallet_standard_features.SolanaSignTransaction in this.#wallet.features) return this.#wallet.features[_solana_wallet_standard_features.SolanaSignTransaction].signTransaction(...transactions.map((value) => {
|
|
245
|
+
return {
|
|
246
|
+
account,
|
|
247
|
+
transaction: value.serialize()
|
|
248
|
+
};
|
|
249
|
+
})).then((outputs) => {
|
|
250
|
+
return outputs.map((output) => {
|
|
251
|
+
const byteArray = output.signedTransaction;
|
|
252
|
+
const messageOffset = byteArray[0] * SIGNATURE_LENGTH_IN_BYTES + 1;
|
|
253
|
+
if (_solana_web3_js.VersionedMessage.deserializeMessageVersion(byteArray.slice(messageOffset, byteArray.length)) === "legacy") return _solana_web3_js.Transaction.from(byteArray);
|
|
254
|
+
else return _solana_web3_js.VersionedTransaction.deserialize(byteArray);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
else throw new Error("Connected wallet does not support signing transactions");
|
|
258
|
+
} catch (error) {
|
|
259
|
+
throw new _solana_wallet_adapter_base.WalletSignTransactionError(getErrorMessage(error), error);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async #runWithGuard(callback) {
|
|
263
|
+
try {
|
|
264
|
+
return await callback();
|
|
265
|
+
} catch (e) {
|
|
266
|
+
this.emit("error", e instanceof _solana_wallet_adapter_base.WalletError ? e : new _solana_wallet_adapter_base.WalletError(getErrorMessage(e), e));
|
|
267
|
+
throw e;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
var LocalSolanaMobileWalletAdapter = class extends BaseSolanaMobileWalletAdapter {
|
|
272
|
+
constructor(config) {
|
|
273
|
+
const chain = chainOrClusterToChainId(config.chain ?? config.cluster);
|
|
274
|
+
super(new _solana_mobile_wallet_standard_mobile.LocalSolanaMobileWalletAdapterWallet({
|
|
275
|
+
appIdentity: config.appIdentity,
|
|
276
|
+
authorizationCache: {
|
|
277
|
+
set: config.authorizationResultCache.set,
|
|
278
|
+
get: async () => {
|
|
279
|
+
return await config.authorizationResultCache.get();
|
|
280
|
+
},
|
|
281
|
+
clear: config.authorizationResultCache.clear
|
|
282
|
+
},
|
|
283
|
+
chains: [chain],
|
|
284
|
+
chainSelector: (0, _solana_mobile_wallet_standard_mobile.createDefaultChainSelector)(),
|
|
285
|
+
onWalletNotFound: async () => {
|
|
286
|
+
config.onWalletNotFound(this);
|
|
287
|
+
}
|
|
288
|
+
}), {
|
|
289
|
+
addressSelector: config.addressSelector,
|
|
290
|
+
chain
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
var RemoteSolanaMobileWalletAdapter = class extends BaseSolanaMobileWalletAdapter {
|
|
295
|
+
constructor(config) {
|
|
296
|
+
const chain = chainOrClusterToChainId(config.chain);
|
|
297
|
+
super(new _solana_mobile_wallet_standard_mobile.RemoteSolanaMobileWalletAdapterWallet({
|
|
298
|
+
appIdentity: config.appIdentity,
|
|
299
|
+
authorizationCache: {
|
|
300
|
+
set: config.authorizationResultCache.set,
|
|
301
|
+
get: async () => {
|
|
302
|
+
return await config.authorizationResultCache.get();
|
|
303
|
+
},
|
|
304
|
+
clear: config.authorizationResultCache.clear
|
|
305
|
+
},
|
|
306
|
+
chains: [chain],
|
|
307
|
+
chainSelector: (0, _solana_mobile_wallet_standard_mobile.createDefaultChainSelector)(),
|
|
308
|
+
remoteHostAuthority: config.remoteHostAuthority,
|
|
309
|
+
onWalletNotFound: async () => {
|
|
310
|
+
config.onWalletNotFound(this);
|
|
311
|
+
}
|
|
312
|
+
}), {
|
|
313
|
+
addressSelector: config.addressSelector,
|
|
314
|
+
chain
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
var SolanaMobileWalletAdapter = class extends LocalSolanaMobileWalletAdapter {};
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/createDefaultAddressSelector.ts
|
|
393
321
|
function createDefaultAddressSelector() {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
},
|
|
398
|
-
};
|
|
322
|
+
return { async select(addresses) {
|
|
323
|
+
return addresses[0];
|
|
324
|
+
} };
|
|
399
325
|
}
|
|
400
|
-
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/createDefaultAuthorizationResultCache.ts
|
|
401
328
|
function createDefaultAuthorizationResultCache() {
|
|
402
|
-
|
|
329
|
+
return (0, _solana_mobile_wallet_standard_mobile.createDefaultAuthorizationCache)();
|
|
403
330
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/createDefaultWalletNotFoundHandler.ts
|
|
333
|
+
async function defaultWalletNotFoundHandler(_mobileWalletAdapter) {
|
|
334
|
+
return (0, _solana_mobile_wallet_standard_mobile.defaultErrorModalWalletNotFoundHandler)();
|
|
407
335
|
}
|
|
408
336
|
function createDefaultWalletNotFoundHandler() {
|
|
409
|
-
|
|
337
|
+
return defaultWalletNotFoundHandler;
|
|
410
338
|
}
|
|
411
|
-
|
|
339
|
+
//#endregion
|
|
412
340
|
exports.LocalSolanaMobileWalletAdapter = LocalSolanaMobileWalletAdapter;
|
|
413
341
|
exports.RemoteSolanaMobileWalletAdapter = RemoteSolanaMobileWalletAdapter;
|
|
414
342
|
exports.SolanaMobileWalletAdapter = SolanaMobileWalletAdapter;
|
|
@@ -417,3 +345,5 @@ exports.SolanaMobileWalletAdapterWalletName = SolanaMobileWalletAdapterWalletNam
|
|
|
417
345
|
exports.createDefaultAddressSelector = createDefaultAddressSelector;
|
|
418
346
|
exports.createDefaultAuthorizationResultCache = createDefaultAuthorizationResultCache;
|
|
419
347
|
exports.createDefaultWalletNotFoundHandler = createDefaultWalletNotFoundHandler;
|
|
348
|
+
|
|
349
|
+
//# sourceMappingURL=index.browser.js.map
|