@vue-solana/core 4.1.6 → 4.1.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/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.CSMFFbai.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';
@@ -5,19 +5,12 @@ import { getBase64Decoder, getBase64Encoder } from '@solana/kit';
5
5
  import { createSolanaError } from './errors.mjs';
6
6
  import { isSolanaMobileWalletSupported } from './mobile-wallet-support.mjs';
7
7
 
8
- async function signMobileWalletMessages({
9
- appIdentity,
10
- authorizationCache,
11
- publicKey,
12
- messages
13
- }) {
8
+ async function runMobileWalletSession({ appIdentity, authorizationCache, publicKey }, request) {
14
9
  const cachedAuthorization = await authorizationCache.get();
15
10
  if (!cachedAuthorization) {
16
11
  throw createSolanaError("WALLET_NOT_CONNECTED", "Solana wallet is not connected");
17
12
  }
18
- const base64Decoder = getBase64Decoder();
19
- const base64Encoder = getBase64Encoder();
20
- const address = base64Decoder.decode(publicKey);
13
+ const address = getBase64Decoder().decode(publicKey);
21
14
  const chain = cachedAuthorization.chain;
22
15
  return transact(async (wallet) => {
23
16
  const authorization = await authorizeSession(
@@ -39,11 +32,40 @@ async function signMobileWalletMessages({
39
32
  wallet_uri_base: authorization.wallet_uri_base
40
33
  });
41
34
  }
35
+ return request(wallet, address);
36
+ });
37
+ }
38
+ function signMobileWalletMessages(options, messages) {
39
+ return runMobileWalletSession(options, async (wallet, address) => {
42
40
  const { signed_payloads } = await wallet.signMessages({
43
41
  addresses: messages.map(() => address),
44
- payloads: messages.map((message) => base64Decoder.decode(message))
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)
45
67
  });
46
- return signed_payloads.map((payload) => Uint8Array.from(base64Encoder.encode(payload)));
68
+ return signatures.map(fromBase64);
47
69
  });
48
70
  }
49
71
  async function authorizeSession(wallet, identity, chain, authToken) {
@@ -63,6 +85,23 @@ async function authorizeSession(wallet, identity, chain, authToken) {
63
85
  );
64
86
  }
65
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
+ }
66
105
  function getErrorMessage(error) {
67
106
  return error instanceof Error ? error.message : String(error);
68
107
  }
@@ -96,7 +135,13 @@ function registerSolanaMobileWallet(options = {}) {
96
135
  setSolanaMobileWalletAuthorizationStore({
97
136
  get: () => authorizationCache.get(),
98
137
  set: (authorization) => authorizationCache.set(authorization),
99
- signMessages: (publicKey, messages) => signMobileWalletMessages({ appIdentity, authorizationCache, publicKey, messages })
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
+ )
100
145
  });
101
146
  return true;
102
147
  }
@@ -108,14 +108,51 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
108
108
  pendingMobileWalletRequests.delete(reject);
109
109
  });
110
110
  }
111
- function signMessageThroughMobileWalletSession(activeAccount, message) {
112
- const signMessages = isMobileWalletAdapter ? getSolanaMobileWalletAuthorizationStore()?.signMessages : void 0;
113
- return signMessages?.(Uint8Array.from(activeAccount.publicKey), [message]).then(
114
- (signedPayloads) => signedPayloads.map((signedMessage) => ({
115
- signedMessage,
116
- signature: signedMessage.slice(-64)
117
- }))
118
- );
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
+ });
119
156
  }
120
157
  function rejectPendingMobileWalletRequests() {
121
158
  for (const reject of pendingMobileWalletRequests) {
@@ -279,8 +316,14 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
279
316
  } : void 0,
280
317
  signMessage: hasSignMessage(wallet) ? async (message) => {
281
318
  const activeAccount = getActiveAccount(account);
319
+ const signMessages = getMobileWalletSession()?.signMessages;
282
320
  const [result] = await whileMobileWalletAuthorized(
283
- () => signMessageThroughMobileWalletSession(activeAccount, message) ?? 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({
284
327
  account: activeAccount,
285
328
  message
286
329
  })
@@ -302,79 +345,43 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
302
345
  return { ...result, signedMessage };
303
346
  } : void 0,
304
347
  signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
305
- const activeAccount = getActiveAccount(account);
306
- const [result] = await whileMobileWalletAuthorized(
307
- () => wallet.features[SolanaSignTransaction].signTransaction({
308
- account: activeAccount,
309
- transaction: new Uint8Array(transaction),
310
- chain: options.chain
311
- })
348
+ const [signedTransaction] = await signTransactionsThroughWallet(
349
+ getActiveAccount(account),
350
+ [transaction]
312
351
  );
313
- if (!result) {
352
+ if (!signedTransaction) {
314
353
  throw new Error("Solana wallet did not return a signed transaction");
315
354
  }
316
- return result.signedTransaction;
355
+ return signedTransaction;
317
356
  } : void 0,
318
- signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => whileMobileWalletAuthorized(
319
- () => signAllThroughFeature(
320
- wallet,
321
- () => getActiveAccount(account),
322
- transactions,
323
- options.chain
324
- )
325
- ) : void 0,
326
- signTransactions: hasSignTransaction(wallet) ? async (transactions) => whileMobileWalletAuthorized(
327
- () => signAllThroughFeature(
328
- wallet,
329
- () => getActiveAccount(account),
330
- transactions,
331
- options.chain
332
- )
333
- ) : 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,
334
359
  signAndSendTransaction: hasSignAndSendTransaction(wallet) ? async (transaction, sendOptions) => {
335
- const activeAccount = getActiveAccount(account);
336
- const [result] = await whileMobileWalletAuthorized(
337
- () => wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction({
338
- account: activeAccount,
339
- transaction: new Uint8Array(transaction),
340
- chain: options.chain ?? getSolanaAccountChain(activeAccount),
341
- options: sendOptions
342
- })
360
+ const [signature] = await signAndSendTransactionsThroughWallet(
361
+ getActiveAccount(account),
362
+ [transaction],
363
+ sendOptions
343
364
  );
344
- if (!result) {
365
+ if (!signature) {
345
366
  throw new Error("Solana wallet did not return a transaction signature");
346
367
  }
347
- return { signature: getBase58Decoder().decode(result.signature) };
368
+ return { signature: getBase58Decoder().decode(signature) };
348
369
  } : void 0,
349
370
  signAndSendTransactions: hasSignAndSendTransaction(wallet) ? async (transactions, sendOptions) => {
350
371
  const activeAccount = getActiveAccount(account);
351
372
  if (isMobileWalletAdapter && options.sendTransaction && transactions.length > 1 && hasSignTransaction(wallet)) {
352
- const signedTransactions = await whileMobileWalletAuthorized(
353
- () => signAllThroughFeature(wallet, () => activeAccount, transactions, options.chain)
373
+ const signedTransactions = await signTransactionsThroughWallet(
374
+ activeAccount,
375
+ transactions
354
376
  );
355
377
  return sendSequentially(signedTransactions, options.sendTransaction, sendOptions);
356
378
  }
357
- const results = await whileMobileWalletAuthorized(
358
- () => wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction(
359
- ...transactions.map((transaction) => ({
360
- account: activeAccount,
361
- transaction: new Uint8Array(transaction),
362
- chain: options.chain ?? getSolanaAccountChain(activeAccount),
363
- options: sendOptions
364
- }))
365
- )
379
+ const signatures = await signAndSendTransactionsThroughWallet(
380
+ activeAccount,
381
+ transactions,
382
+ sendOptions
366
383
  );
367
- if (results.length !== transactions.length) {
368
- throw new Error(
369
- `Solana wallet returned ${results.length} signatures for ${transactions.length} requested transactions`
370
- );
371
- }
372
- return results.map((result) => {
373
- if (!result) {
374
- throw new Error("Solana wallet did not return a transaction signature");
375
- }
376
- return getBase58Decoder().decode(result.signature);
377
- });
384
+ return signatures.map((signature) => getBase58Decoder().decode(signature));
378
385
  } : void 0
379
386
  };
380
387
  }
@@ -402,8 +409,7 @@ async function sendSequentially(signedTransactions, sendTransaction, sendOptions
402
409
  }
403
410
  return signatures;
404
411
  }
405
- async function signAllThroughFeature(wallet, getAccount, transactions, chain) {
406
- const activeAccount = getAccount();
412
+ async function signAllThroughFeature(wallet, activeAccount, transactions, chain) {
407
413
  const results = await wallet.features[SolanaSignTransaction].signTransaction(
408
414
  ...transactions.map((transaction) => ({
409
415
  account: activeAccount,
@@ -411,11 +417,7 @@ async function signAllThroughFeature(wallet, getAccount, transactions, chain) {
411
417
  chain
412
418
  }))
413
419
  );
414
- if (results.length !== transactions.length) {
415
- throw new Error(
416
- `Solana wallet returned ${results.length} signed transactions for ${transactions.length} requested transactions`
417
- );
418
- }
420
+ assertResultCount(results, transactions, "signed transactions");
419
421
  return results.map((result) => {
420
422
  if (!result) {
421
423
  throw new Error("Solana wallet did not return a signed transaction");
@@ -423,6 +425,13 @@ async function signAllThroughFeature(wallet, getAccount, transactions, chain) {
423
425
  return result.signedTransaction;
424
426
  });
425
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
+ }
426
435
  function getDefaultSignInInput(account) {
427
436
  const domain = typeof location === "undefined" ? "" : location.host;
428
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.CSMFFbai.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.6",
3
+ "version": "4.1.8",
4
4
  "description": "Framework-agnostic primitives for Vue Solana libraries.",
5
5
  "license": "MIT",
6
6
  "keywords": [