@vue-solana/core 4.1.5 → 4.1.7

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.Fb0vU7a_.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.bHkdj4bp.mjs';
@@ -1,7 +1,111 @@
1
1
  import { createDefaultAuthorizationCache, registerMwa, createDefaultWalletNotFoundHandler, createDefaultChainSelector } from '@solana-mobile/wallet-standard-mobile';
2
2
  import { s as setSolanaMobileWalletAuthorizationStore } from './shared/core.DQCWbyEu.mjs';
3
+ import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol';
4
+ import { getBase64Decoder, getBase64Encoder } from '@solana/kit';
5
+ import { createSolanaError } from './errors.mjs';
3
6
  import { isSolanaMobileWalletSupported } from './mobile-wallet-support.mjs';
4
7
 
8
+ async function runMobileWalletSession({ appIdentity, authorizationCache, publicKey }, request) {
9
+ const cachedAuthorization = await authorizationCache.get();
10
+ if (!cachedAuthorization) {
11
+ throw createSolanaError("WALLET_NOT_CONNECTED", "Solana wallet is not connected");
12
+ }
13
+ const address = getBase64Decoder().decode(publicKey);
14
+ const chain = cachedAuthorization.chain;
15
+ return transact(async (wallet) => {
16
+ const authorization = await authorizeSession(
17
+ wallet,
18
+ appIdentity,
19
+ chain,
20
+ cachedAuthorization.auth_token
21
+ );
22
+ if (!authorization.accounts.some((account) => account.address === address)) {
23
+ throw createSolanaError(
24
+ "WALLET_NOT_CONNECTED",
25
+ "The wallet authorized a different account than the connected one. Connect the wallet again and retry."
26
+ );
27
+ }
28
+ if (authorization.auth_token !== cachedAuthorization.auth_token) {
29
+ await authorizationCache.set({
30
+ ...cachedAuthorization,
31
+ auth_token: authorization.auth_token,
32
+ wallet_uri_base: authorization.wallet_uri_base
33
+ });
34
+ }
35
+ return request(wallet, address);
36
+ });
37
+ }
38
+ function signMobileWalletMessages(options, messages) {
39
+ return runMobileWalletSession(options, async (wallet, address) => {
40
+ const { signed_payloads } = await wallet.signMessages({
41
+ addresses: messages.map(() => address),
42
+ payloads: messages.map(toBase64)
43
+ });
44
+ return signed_payloads.map(fromBase64);
45
+ });
46
+ }
47
+ function signMobileWalletTransactions(options, transactions) {
48
+ return runMobileWalletSession(options, async (wallet) => {
49
+ const { signed_payloads } = await wallet.signTransactions({
50
+ payloads: transactions.map(toBase64)
51
+ });
52
+ return signed_payloads.map(fromBase64);
53
+ });
54
+ }
55
+ function signAndSendMobileWalletTransactions(options, transactions, sendOptions) {
56
+ return runMobileWalletSession(options, async (wallet) => {
57
+ const capabilities = await wallet.getCapabilities();
58
+ if (!capabilities.supports_sign_and_send_transactions) {
59
+ throw createSolanaError(
60
+ "WALLET_FEATURE_UNSUPPORTED",
61
+ "The connected wallet does not support signAndSendTransaction"
62
+ );
63
+ }
64
+ const { signatures } = await wallet.signAndSendTransactions({
65
+ payloads: transactions.map(toBase64),
66
+ options: toMobileWalletSendOptions(sendOptions)
67
+ });
68
+ return signatures.map(fromBase64);
69
+ });
70
+ }
71
+ async function authorizeSession(wallet, identity, chain, authToken) {
72
+ let reauthorizationError;
73
+ try {
74
+ return await wallet.authorize({ auth_token: authToken, identity, chain });
75
+ } catch (error) {
76
+ reauthorizationError = error;
77
+ }
78
+ try {
79
+ return await wallet.authorize({ identity, chain });
80
+ } catch (authorizationError) {
81
+ throw createSolanaError(
82
+ "WALLET_FAILURE",
83
+ `The wallet rejected the saved authorization (${getErrorMessage(reauthorizationError)}) and a fresh one (${getErrorMessage(authorizationError)}).`,
84
+ { cause: authorizationError }
85
+ );
86
+ }
87
+ }
88
+ function toMobileWalletSendOptions(sendOptions) {
89
+ if (!sendOptions) {
90
+ return void 0;
91
+ }
92
+ return {
93
+ commitment: sendOptions.preflightCommitment,
94
+ skip_preflight: sendOptions.skipPreflight,
95
+ max_retries: sendOptions.maxRetries === void 0 ? void 0 : Number(sendOptions.maxRetries),
96
+ min_context_slot: sendOptions.minContextSlot === void 0 ? void 0 : Number(sendOptions.minContextSlot)
97
+ };
98
+ }
99
+ function toBase64(bytes) {
100
+ return getBase64Decoder().decode(bytes);
101
+ }
102
+ function fromBase64(value) {
103
+ return Uint8Array.from(getBase64Encoder().encode(value));
104
+ }
105
+ function getErrorMessage(error) {
106
+ return error instanceof Error ? error.message : String(error);
107
+ }
108
+
5
109
  const DEFAULT_MOBILE_WALLET_CHAINS = ["solana:mainnet", "solana:devnet"];
6
110
  const registeredMobileWalletKeys = /* @__PURE__ */ new Set();
7
111
  function registerSolanaMobileWallet(options = {}) {
@@ -30,7 +134,14 @@ function registerSolanaMobileWallet(options = {}) {
30
134
  registeredMobileWalletKeys.add(registrationKey);
31
135
  setSolanaMobileWalletAuthorizationStore({
32
136
  get: () => authorizationCache.get(),
33
- set: (authorization) => authorizationCache.set(authorization)
137
+ set: (authorization) => authorizationCache.set(authorization),
138
+ signMessages: (publicKey, messages) => signMobileWalletMessages({ appIdentity, authorizationCache, publicKey }, messages),
139
+ signTransactions: (publicKey, transactions) => signMobileWalletTransactions({ appIdentity, authorizationCache, publicKey }, transactions),
140
+ signAndSendTransactions: (publicKey, transactions, sendOptions) => signAndSendMobileWalletTransactions(
141
+ { appIdentity, authorizationCache, publicKey },
142
+ transactions,
143
+ sendOptions
144
+ )
34
145
  });
35
146
  return true;
36
147
  }
@@ -108,6 +108,52 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
108
108
  pendingMobileWalletRequests.delete(reject);
109
109
  });
110
110
  }
111
+ function getMobileWalletSession() {
112
+ return isMobileWalletAdapter ? getSolanaMobileWalletAuthorizationStore() : void 0;
113
+ }
114
+ function signTransactionsThroughWallet(activeAccount, transactions) {
115
+ const signTransactions = getMobileWalletSession()?.signTransactions;
116
+ return whileMobileWalletAuthorized(async () => {
117
+ if (!signTransactions) {
118
+ return signAllThroughFeature(
119
+ wallet,
120
+ activeAccount,
121
+ transactions,
122
+ options.chain
123
+ );
124
+ }
125
+ const signedTransactions = await signTransactions(
126
+ Uint8Array.from(activeAccount.publicKey),
127
+ transactions.map((transaction) => new Uint8Array(transaction))
128
+ );
129
+ assertResultCount(signedTransactions, transactions, "signed transactions");
130
+ return signedTransactions;
131
+ });
132
+ }
133
+ function signAndSendTransactionsThroughWallet(activeAccount, transactions, sendOptions) {
134
+ const signAndSendTransactions = getMobileWalletSession()?.signAndSendTransactions;
135
+ return whileMobileWalletAuthorized(async () => {
136
+ const signatures = signAndSendTransactions ? await signAndSendTransactions(
137
+ Uint8Array.from(activeAccount.publicKey),
138
+ transactions.map((transaction) => new Uint8Array(transaction)),
139
+ sendOptions
140
+ ) : (await wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction(
141
+ ...transactions.map((transaction) => ({
142
+ account: activeAccount,
143
+ transaction: new Uint8Array(transaction),
144
+ chain: options.chain ?? getSolanaAccountChain(activeAccount),
145
+ options: sendOptions
146
+ }))
147
+ )).map((result) => {
148
+ if (!result) {
149
+ throw new Error("Solana wallet did not return a transaction signature");
150
+ }
151
+ return result.signature;
152
+ });
153
+ assertResultCount(signatures, transactions, "signatures");
154
+ return signatures;
155
+ });
156
+ }
111
157
  function rejectPendingMobileWalletRequests() {
112
158
  for (const reject of pendingMobileWalletRequests) {
113
159
  reject(
@@ -270,8 +316,14 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
270
316
  } : void 0,
271
317
  signMessage: hasSignMessage(wallet) ? async (message) => {
272
318
  const activeAccount = getActiveAccount(account);
319
+ const signMessages = getMobileWalletSession()?.signMessages;
273
320
  const [result] = await whileMobileWalletAuthorized(
274
- () => wallet.features[SolanaSignMessage].signMessage({
321
+ async () => signMessages ? (await signMessages(Uint8Array.from(activeAccount.publicKey), [message])).map(
322
+ (signedMessage2) => ({
323
+ signedMessage: signedMessage2,
324
+ signature: signedMessage2.slice(-64)
325
+ })
326
+ ) : wallet.features[SolanaSignMessage].signMessage({
275
327
  account: activeAccount,
276
328
  message
277
329
  })
@@ -293,79 +345,43 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
293
345
  return { ...result, signedMessage };
294
346
  } : void 0,
295
347
  signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
296
- const activeAccount = getActiveAccount(account);
297
- const [result] = await whileMobileWalletAuthorized(
298
- () => wallet.features[SolanaSignTransaction].signTransaction({
299
- account: activeAccount,
300
- transaction: new Uint8Array(transaction),
301
- chain: options.chain
302
- })
348
+ const [signedTransaction] = await signTransactionsThroughWallet(
349
+ getActiveAccount(account),
350
+ [transaction]
303
351
  );
304
- if (!result) {
352
+ if (!signedTransaction) {
305
353
  throw new Error("Solana wallet did not return a signed transaction");
306
354
  }
307
- return result.signedTransaction;
355
+ return signedTransaction;
308
356
  } : void 0,
309
- signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => whileMobileWalletAuthorized(
310
- () => signAllThroughFeature(
311
- wallet,
312
- () => getActiveAccount(account),
313
- transactions,
314
- options.chain
315
- )
316
- ) : void 0,
317
- signTransactions: hasSignTransaction(wallet) ? async (transactions) => whileMobileWalletAuthorized(
318
- () => signAllThroughFeature(
319
- wallet,
320
- () => getActiveAccount(account),
321
- transactions,
322
- options.chain
323
- )
324
- ) : void 0,
357
+ signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => signTransactionsThroughWallet(getActiveAccount(account), transactions) : void 0,
358
+ signTransactions: hasSignTransaction(wallet) ? async (transactions) => signTransactionsThroughWallet(getActiveAccount(account), transactions) : void 0,
325
359
  signAndSendTransaction: hasSignAndSendTransaction(wallet) ? async (transaction, sendOptions) => {
326
- const activeAccount = getActiveAccount(account);
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
- })
360
+ const [signature] = await signAndSendTransactionsThroughWallet(
361
+ getActiveAccount(account),
362
+ [transaction],
363
+ sendOptions
334
364
  );
335
- if (!result) {
365
+ if (!signature) {
336
366
  throw new Error("Solana wallet did not return a transaction signature");
337
367
  }
338
- return { signature: getBase58Decoder().decode(result.signature) };
368
+ return { signature: getBase58Decoder().decode(signature) };
339
369
  } : void 0,
340
370
  signAndSendTransactions: hasSignAndSendTransaction(wallet) ? async (transactions, sendOptions) => {
341
371
  const activeAccount = getActiveAccount(account);
342
372
  if (isMobileWalletAdapter && options.sendTransaction && transactions.length > 1 && hasSignTransaction(wallet)) {
343
- const signedTransactions = await whileMobileWalletAuthorized(
344
- () => signAllThroughFeature(wallet, () => activeAccount, transactions, options.chain)
373
+ const signedTransactions = await signTransactionsThroughWallet(
374
+ activeAccount,
375
+ transactions
345
376
  );
346
377
  return sendSequentially(signedTransactions, options.sendTransaction, sendOptions);
347
378
  }
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
- )
379
+ const signatures = await signAndSendTransactionsThroughWallet(
380
+ activeAccount,
381
+ transactions,
382
+ sendOptions
357
383
  );
358
- if (results.length !== transactions.length) {
359
- throw new Error(
360
- `Solana wallet returned ${results.length} signatures for ${transactions.length} requested transactions`
361
- );
362
- }
363
- return results.map((result) => {
364
- if (!result) {
365
- throw new Error("Solana wallet did not return a transaction signature");
366
- }
367
- return getBase58Decoder().decode(result.signature);
368
- });
384
+ return signatures.map((signature) => getBase58Decoder().decode(signature));
369
385
  } : void 0
370
386
  };
371
387
  }
@@ -393,8 +409,7 @@ async function sendSequentially(signedTransactions, sendTransaction, sendOptions
393
409
  }
394
410
  return signatures;
395
411
  }
396
- async function signAllThroughFeature(wallet, getAccount, transactions, chain) {
397
- const activeAccount = getAccount();
412
+ async function signAllThroughFeature(wallet, activeAccount, transactions, chain) {
398
413
  const results = await wallet.features[SolanaSignTransaction].signTransaction(
399
414
  ...transactions.map((transaction) => ({
400
415
  account: activeAccount,
@@ -402,11 +417,7 @@ async function signAllThroughFeature(wallet, getAccount, transactions, chain) {
402
417
  chain
403
418
  }))
404
419
  );
405
- if (results.length !== transactions.length) {
406
- throw new Error(
407
- `Solana wallet returned ${results.length} signed transactions for ${transactions.length} requested transactions`
408
- );
409
- }
420
+ assertResultCount(results, transactions, "signed transactions");
410
421
  return results.map((result) => {
411
422
  if (!result) {
412
423
  throw new Error("Solana wallet did not return a signed transaction");
@@ -414,6 +425,13 @@ async function signAllThroughFeature(wallet, getAccount, transactions, chain) {
414
425
  return result.signedTransaction;
415
426
  });
416
427
  }
428
+ function assertResultCount(results, transactions, label) {
429
+ if (results.length !== transactions.length) {
430
+ throw new Error(
431
+ `Solana wallet returned ${results.length} ${label} for ${transactions.length} requested transactions`
432
+ );
433
+ }
434
+ }
417
435
  function getDefaultSignInInput(account) {
418
436
  const domain = typeof location === "undefined" ? "" : location.host;
419
437
  return account ? { domain, address: account.address } : { domain };
@@ -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.Fb0vU7a_.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.bHkdj4bp.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-solana/core",
3
- "version": "4.1.5",
3
+ "version": "4.1.7",
4
4
  "description": "Framework-agnostic primitives for Vue Solana libraries.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -115,6 +115,7 @@
115
115
  "access": "public"
116
116
  },
117
117
  "dependencies": {
118
+ "@solana-mobile/mobile-wallet-adapter-protocol": "^2.2.9",
118
119
  "@solana-mobile/wallet-standard-mobile": "^0.5.3",
119
120
  "@solana/kit": "^8.6.0",
120
121
  "@solana/kit-plugin-rpc": "^0.19.0",