@vue-solana/core 4.1.3 → 4.1.5

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/dist/index.mjs CHANGED
@@ -12,4 +12,4 @@ export { createSolanaPayReference, findTransactionSignaturesByReference, verifyS
12
12
  export { getSolanaPayPaymentStatus } from './solana-pay-status.mjs';
13
13
  export * from '@solana/kit';
14
14
  export { C as CreateTransferError, H as HTTPS_PROTOCOL, M as MEMO_PROGRAM_ID, P as ParseURLError, S as SOLANA_PROTOCOL, a as SOL_DECIMALS, T as TEN, b as TOKEN_PROGRAM_ID, c as createQR, d as createQRCanvas, e as createQRDataURL, f as createQROptions, g as createRecipient, h as createSPLToken, i as createStyledQRCode, j as encodeTransactionRequestURL, k as encodeTransferRequestURL, l as encodeURL, m as isValidSolanaAddress, p as parseURL } from './shared/core.CQFtdLrA.mjs';
15
- export { S as SOLANA_CHAINS, a as SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, b as adaptSolanaStandardWallet, d as disconnectSolanaStandardWallet, g as getRegisteredSolanaWallets, c as getSolanaChain, i as isSolanaStandardWallet, s as subscribeSolanaWallets } from './shared/core.D8oIzL0q.mjs';
15
+ export { S as SOLANA_CHAINS, a as SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, b as adaptSolanaStandardWallet, d as disconnectSolanaStandardWallet, g as getRegisteredSolanaWallets, c as getSolanaChain, i as isSolanaStandardWallet, s as subscribeSolanaWallets } from './shared/core.Fb0vU7a_.mjs';
@@ -33,6 +33,14 @@ declare function createChainScopedAuthorizationCache(chains: readonly SolanaChai
33
33
  * host-side registration. Intended for test/HMR reset only.
34
34
  */
35
35
  declare function unregisterSolanaMobileWallet(): void;
36
+ /**
37
+ * The identity MWA sends with every `authorize`, including the re-authorization
38
+ * that precedes each signing request. Wallets bind the auth token to it, so it
39
+ * must not change between page loads: `document.title` did (per route, per
40
+ * locale, and empty on a client-only route at registration time), and a session
41
+ * restored under one title was then re-authorized under another, which Phantom
42
+ * answered by opening without a prompt. Pass `appIdentity` to pin it explicitly.
43
+ */
36
44
  declare function getDefaultMobileWalletAppIdentity(): SolanaMobileWalletAppIdentity;
37
45
 
38
46
  export { createChainScopedAuthorizationCache, getDefaultMobileWalletAppIdentity, registerSolanaMobileWallet, unregisterSolanaMobileWallet };
@@ -61,11 +61,18 @@ function getDefaultMobileWalletAppIdentity() {
61
61
  };
62
62
  }
63
63
  return {
64
- name: document.title || "Vue Solana App",
64
+ name: getDocumentAppName(),
65
65
  uri: window.location.origin,
66
66
  icon: getDocumentIconPath()
67
67
  };
68
68
  }
69
+ function getDocumentAppName() {
70
+ const name = getMetaContent('meta[name="application-name"]') ?? getMetaContent('meta[property="og:site_name"]') ?? window.location.hostname;
71
+ return name || "Vue Solana App";
72
+ }
73
+ function getMetaContent(selector) {
74
+ return document.querySelector(selector)?.content.trim() || void 0;
75
+ }
69
76
  function getDocumentIconPath() {
70
77
  const icon = document.querySelector(
71
78
  'link[rel="icon"], link[rel="shortcut icon"], link[rel="apple-touch-icon"]'
@@ -73,10 +80,13 @@ function getDocumentIconPath() {
73
80
  if (!icon?.href) {
74
81
  return void 0;
75
82
  }
76
- if (icon.href.startsWith(window.location.origin)) {
77
- return icon.href.slice(window.location.origin.length).replace(/^\//, "");
83
+ if (icon.href.startsWith("data:")) {
84
+ return icon.href;
85
+ }
86
+ if (icon.href.startsWith(`${window.location.origin}/`)) {
87
+ return icon.href.slice(window.location.origin.length + 1);
78
88
  }
79
- return icon.href;
89
+ return void 0;
80
90
  }
81
91
 
82
92
  export { createChainScopedAuthorizationCache, getDefaultMobileWalletAppIdentity, isSolanaMobileWalletSupported, registerSolanaMobileWallet, unregisterSolanaMobileWallet };
@@ -78,10 +78,14 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
78
78
  let manuallyDisconnected = false;
79
79
  let signingIn = false;
80
80
  const isMobileWalletAdapter = walletInfo.source === "mobile-wallet-adapter";
81
+ const pendingMobileWalletRequests = /* @__PURE__ */ new Set();
81
82
  const eventsFeature = wallet.features[StandardEvents];
82
83
  const unsubscribeChange = eventsFeature?.on("change", (properties) => {
83
84
  if (properties.accounts) {
84
85
  accounts = properties.accounts;
86
+ if (accounts.length === 0) {
87
+ rejectPendingMobileWalletRequests();
88
+ }
85
89
  if (!signingIn) {
86
90
  account = allowAccountUpdates && !manuallyDisconnected ? getSolanaAccount(accounts, options.chain) : void 0;
87
91
  }
@@ -91,6 +95,30 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
91
95
  function dispose() {
92
96
  unsubscribeChange?.();
93
97
  }
98
+ function whileMobileWalletAuthorized(request) {
99
+ if (!isMobileWalletAdapter) {
100
+ return request();
101
+ }
102
+ let reject;
103
+ const deauthorized = new Promise((_, rejectRequest) => {
104
+ reject = rejectRequest;
105
+ });
106
+ pendingMobileWalletRequests.add(reject);
107
+ return Promise.race([request(), deauthorized]).finally(() => {
108
+ pendingMobileWalletRequests.delete(reject);
109
+ });
110
+ }
111
+ function rejectPendingMobileWalletRequests() {
112
+ for (const reject of pendingMobileWalletRequests) {
113
+ reject(
114
+ createSolanaError(
115
+ "WALLET_NOT_CONNECTED",
116
+ "The wallet ended this app's session instead of signing, usually because it no longer accepts the saved authorization. Connect the wallet again and retry."
117
+ )
118
+ );
119
+ }
120
+ pendingMobileWalletRequests.clear();
121
+ }
94
122
  async function verifySignInResult(result, requestedAddress) {
95
123
  if (!result) {
96
124
  throw new Error("Solana wallet did not return a sign-in result");
@@ -242,10 +270,12 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
242
270
  } : void 0,
243
271
  signMessage: hasSignMessage(wallet) ? async (message) => {
244
272
  const activeAccount = getActiveAccount(account);
245
- const [result] = await wallet.features[SolanaSignMessage].signMessage({
246
- account: activeAccount,
247
- message
248
- });
273
+ const [result] = await whileMobileWalletAuthorized(
274
+ () => wallet.features[SolanaSignMessage].signMessage({
275
+ account: activeAccount,
276
+ message
277
+ })
278
+ );
249
279
  if (!result) {
250
280
  throw new Error("Solana wallet did not return a message signature");
251
281
  }
@@ -264,36 +294,44 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
264
294
  } : void 0,
265
295
  signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
266
296
  const activeAccount = getActiveAccount(account);
267
- const [result] = await wallet.features[SolanaSignTransaction].signTransaction({
268
- account: activeAccount,
269
- transaction: new Uint8Array(transaction),
270
- chain: options.chain
271
- });
297
+ const [result] = await whileMobileWalletAuthorized(
298
+ () => wallet.features[SolanaSignTransaction].signTransaction({
299
+ account: activeAccount,
300
+ transaction: new Uint8Array(transaction),
301
+ chain: options.chain
302
+ })
303
+ );
272
304
  if (!result) {
273
305
  throw new Error("Solana wallet did not return a signed transaction");
274
306
  }
275
307
  return result.signedTransaction;
276
308
  } : void 0,
277
- signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => signAllThroughFeature(
278
- wallet,
279
- () => getActiveAccount(account),
280
- transactions,
281
- options.chain
309
+ signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => whileMobileWalletAuthorized(
310
+ () => signAllThroughFeature(
311
+ wallet,
312
+ () => getActiveAccount(account),
313
+ transactions,
314
+ options.chain
315
+ )
282
316
  ) : void 0,
283
- signTransactions: hasSignTransaction(wallet) ? async (transactions) => signAllThroughFeature(
284
- wallet,
285
- () => getActiveAccount(account),
286
- transactions,
287
- options.chain
317
+ signTransactions: hasSignTransaction(wallet) ? async (transactions) => whileMobileWalletAuthorized(
318
+ () => signAllThroughFeature(
319
+ wallet,
320
+ () => getActiveAccount(account),
321
+ transactions,
322
+ options.chain
323
+ )
288
324
  ) : void 0,
289
325
  signAndSendTransaction: hasSignAndSendTransaction(wallet) ? async (transaction, sendOptions) => {
290
326
  const activeAccount = getActiveAccount(account);
291
- const [result] = await wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction({
292
- account: activeAccount,
293
- transaction: new Uint8Array(transaction),
294
- chain: options.chain ?? getSolanaAccountChain(activeAccount),
295
- options: sendOptions
296
- });
327
+ const [result] = await whileMobileWalletAuthorized(
328
+ () => wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction({
329
+ account: activeAccount,
330
+ transaction: new Uint8Array(transaction),
331
+ chain: options.chain ?? getSolanaAccountChain(activeAccount),
332
+ options: sendOptions
333
+ })
334
+ );
297
335
  if (!result) {
298
336
  throw new Error("Solana wallet did not return a transaction signature");
299
337
  }
@@ -302,21 +340,20 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
302
340
  signAndSendTransactions: hasSignAndSendTransaction(wallet) ? async (transactions, sendOptions) => {
303
341
  const activeAccount = getActiveAccount(account);
304
342
  if (isMobileWalletAdapter && options.sendTransaction && transactions.length > 1 && hasSignTransaction(wallet)) {
305
- const signedTransactions = await signAllThroughFeature(
306
- wallet,
307
- () => activeAccount,
308
- transactions,
309
- options.chain
343
+ const signedTransactions = await whileMobileWalletAuthorized(
344
+ () => signAllThroughFeature(wallet, () => activeAccount, transactions, options.chain)
310
345
  );
311
346
  return sendSequentially(signedTransactions, options.sendTransaction, sendOptions);
312
347
  }
313
- const results = await wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction(
314
- ...transactions.map((transaction) => ({
315
- account: activeAccount,
316
- transaction: new Uint8Array(transaction),
317
- chain: options.chain ?? getSolanaAccountChain(activeAccount),
318
- options: sendOptions
319
- }))
348
+ const results = await whileMobileWalletAuthorized(
349
+ () => wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction(
350
+ ...transactions.map((transaction) => ({
351
+ account: activeAccount,
352
+ transaction: new Uint8Array(transaction),
353
+ chain: options.chain ?? getSolanaAccountChain(activeAccount),
354
+ options: sendOptions
355
+ }))
356
+ )
320
357
  );
321
358
  if (results.length !== transactions.length) {
322
359
  throw new Error(
@@ -1 +1 @@
1
- export { S as SOLANA_CHAINS, a as SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, b as adaptSolanaStandardWallet, d as disconnectSolanaStandardWallet, g as getRegisteredSolanaWallets, c as getSolanaChain, i as isSolanaStandardWallet, s as subscribeSolanaWallets } from './shared/core.D8oIzL0q.mjs';
1
+ export { S as SOLANA_CHAINS, a as SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, b as adaptSolanaStandardWallet, d as disconnectSolanaStandardWallet, g as getRegisteredSolanaWallets, c as getSolanaChain, i as isSolanaStandardWallet, s as subscribeSolanaWallets } from './shared/core.Fb0vU7a_.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-solana/core",
3
- "version": "4.1.3",
3
+ "version": "4.1.5",
4
4
  "description": "Framework-agnostic primitives for Vue Solana libraries.",
5
5
  "license": "MIT",
6
6
  "keywords": [