@vue-solana/core 1.2.0 → 2.1.0

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.
Files changed (82) hide show
  1. package/README.md +48 -35
  2. package/dist/action.cjs +15 -0
  3. package/dist/action.d.cts +28 -0
  4. package/dist/action.d.mts +28 -0
  5. package/dist/action.d.ts +28 -0
  6. package/dist/action.mjs +12 -0
  7. package/dist/address.cjs +10 -10
  8. package/dist/address.d.cts +11 -13
  9. package/dist/address.d.mts +11 -13
  10. package/dist/address.d.ts +11 -13
  11. package/dist/address.mjs +10 -10
  12. package/dist/buffer-polyfill.d.cts +0 -1
  13. package/dist/buffer-polyfill.d.mts +0 -1
  14. package/dist/buffer-polyfill.d.ts +0 -1
  15. package/dist/clusters.d.cts +1 -4
  16. package/dist/clusters.d.mts +1 -4
  17. package/dist/clusters.d.ts +1 -4
  18. package/dist/index.cjs +14 -20
  19. package/dist/index.d.cts +7 -10
  20. package/dist/index.d.mts +7 -10
  21. package/dist/index.d.ts +7 -10
  22. package/dist/index.mjs +8 -9
  23. package/dist/ios-wallet.cjs +2 -2
  24. package/dist/ios-wallet.d.cts +1 -4
  25. package/dist/ios-wallet.d.mts +1 -4
  26. package/dist/ios-wallet.d.ts +1 -4
  27. package/dist/ios-wallet.mjs +2 -2
  28. package/dist/kit.cjs +4 -0
  29. package/dist/kit.d.cts +2 -5
  30. package/dist/kit.d.mts +2 -5
  31. package/dist/kit.d.ts +2 -5
  32. package/dist/kit.mjs +1 -1
  33. package/dist/mobile-wallet.d.cts +1 -4
  34. package/dist/mobile-wallet.d.mts +1 -4
  35. package/dist/mobile-wallet.d.ts +1 -4
  36. package/dist/rpc.cjs +0 -12
  37. package/dist/rpc.d.cts +2 -11
  38. package/dist/rpc.d.mts +2 -11
  39. package/dist/rpc.d.ts +2 -11
  40. package/dist/rpc.mjs +1 -12
  41. package/dist/shared/{core.Ch_Z7_17.mjs → core.BwW4HVQI.mjs} +12 -28
  42. package/dist/shared/{core.DAUuCWrr.d.mts → core.CQ_yMDAL.d.cts} +65 -30
  43. package/dist/shared/{core.DAUuCWrr.d.ts → core.CQ_yMDAL.d.mts} +65 -30
  44. package/dist/shared/{core.DAUuCWrr.d.cts → core.CQ_yMDAL.d.ts} +65 -30
  45. package/dist/shared/{core.BsekSwcZ.cjs → core.Cb48vQvC.cjs} +12 -28
  46. package/dist/shared/{core.DjbtrJWl.mjs → core.DEcQDbtz.mjs} +89 -37
  47. package/dist/shared/{core.BQoh-5Wu.cjs → core.DjxUirkw.cjs} +101 -49
  48. package/dist/token-accounts.cjs +44 -28
  49. package/dist/token-accounts.d.cts +20 -20
  50. package/dist/token-accounts.d.mts +20 -20
  51. package/dist/token-accounts.d.ts +20 -20
  52. package/dist/token-accounts.mjs +44 -28
  53. package/dist/transaction.cjs +50 -31
  54. package/dist/transaction.d.cts +9 -15
  55. package/dist/transaction.d.mts +9 -15
  56. package/dist/transaction.d.ts +9 -15
  57. package/dist/transaction.mjs +51 -32
  58. package/dist/types.d.cts +1 -4
  59. package/dist/types.d.mts +1 -4
  60. package/dist/types.d.ts +1 -4
  61. package/dist/wallet-standard.cjs +1 -4
  62. package/dist/wallet-standard.d.cts +1 -4
  63. package/dist/wallet-standard.d.mts +1 -4
  64. package/dist/wallet-standard.d.ts +1 -4
  65. package/dist/wallet-standard.mjs +1 -4
  66. package/dist/wallet.cjs +33 -0
  67. package/dist/wallet.d.cts +5 -5
  68. package/dist/wallet.d.mts +5 -5
  69. package/dist/wallet.d.ts +5 -5
  70. package/dist/wallet.mjs +31 -1
  71. package/package.json +6 -13
  72. package/dist/spl-token.cjs +0 -12
  73. package/dist/spl-token.d.cts +0 -4
  74. package/dist/spl-token.d.mts +0 -4
  75. package/dist/spl-token.d.ts +0 -4
  76. package/dist/spl-token.mjs +0 -1
  77. package/dist/web3.cjs +0 -13
  78. package/dist/web3.d.cts +0 -3
  79. package/dist/web3.d.mts +0 -3
  80. package/dist/web3.d.ts +0 -3
  81. package/dist/web3.mjs +0 -1
  82. package/types/web3-compat.d.ts +0 -140
@@ -1,35 +1,35 @@
1
- import { PublicKey, Connection } from '@vue-solana/core/web3';
2
- import { Account } from '@solana/spl-token';
1
+ import { Address, Commitment } from '@solana/kit';
2
+ import { b as SolanaClient } from './shared/core.CQ_yMDAL.js';
3
3
 
4
+ interface TokenAccountInfo {
5
+ address: Address;
6
+ mint: Address;
7
+ owner: Address;
8
+ amount: bigint;
9
+ decimals: number;
10
+ state: "frozen" | "initialized" | "uninitialized";
11
+ isNative: boolean;
12
+ }
4
13
  interface TokenAccountsByOwnerOptions {
5
- commitment?: "processed" | "confirmed" | "finalized";
6
- programId?: PublicKey;
14
+ commitment?: Commitment;
15
+ programId?: Address;
7
16
  }
8
17
  /**
9
- * Get all SPL token accounts for an owner using the legacy `Connection` API.
10
- *
11
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
12
- * `@vue-solana/core/kit`.
18
+ * Get all SPL token accounts for an owner using parsed kit RPC reads.
13
19
  */
14
- declare function getTokenAccountsByOwner(connection: Connection, owner: PublicKey, options?: TokenAccountsByOwnerOptions): Promise<Account[]>;
20
+ declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
15
21
  /**
16
- * Get a single token account using the legacy `Connection` API.
17
- *
18
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
19
- * `@vue-solana/core/kit`.
22
+ * Get a single parsed token account at the given address.
20
23
  */
21
- declare function getTokenAccount(connection: Connection, address: PublicKey): Promise<Account | null>;
24
+ declare function getTokenAccount(client: SolanaClient, address: Address, commitment?: Commitment): Promise<TokenAccountInfo | null>;
22
25
  interface TokenBalanceResult {
23
26
  amount: bigint;
24
27
  decimals: number;
25
28
  }
26
29
  /**
27
- * Read the token balance of the associated token account for an owner.
28
- *
29
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
30
- * `@vue-solana/core/kit`.
30
+ * Read the token balance of the accounts an owner holds for a given mint.
31
31
  */
32
- declare function getTokenBalance(connection: Connection, mint: PublicKey, owner: PublicKey): Promise<TokenBalanceResult | null>;
32
+ declare function getTokenBalance(client: SolanaClient, mint: Address, owner: Address, commitment?: Commitment): Promise<TokenBalanceResult | null>;
33
33
 
34
34
  export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
35
- export type { TokenAccountsByOwnerOptions, TokenBalanceResult };
35
+ export type { TokenAccountInfo, TokenAccountsByOwnerOptions, TokenBalanceResult };
@@ -1,52 +1,68 @@
1
- import { unpackAccount, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, unpackMint } from '@solana/spl-token';
1
+ import { address } from '@solana/kit';
2
2
  import { normalizeSolanaError } from './errors.mjs';
3
3
 
4
- async function getTokenAccountsByOwner(connection, owner, options) {
5
- const commitment = options?.commitment ?? "confirmed";
6
- const programId = options?.programId;
7
- const programIds = programId ? [programId] : [TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID];
4
+ const TOKEN_PROGRAM_ADDRESS = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
5
+ const TOKEN_2022_PROGRAM_ADDRESS = address("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
6
+ async function getTokenAccountsByOwner(client, owner, options = {}) {
7
+ const programIds = options.programId ? [options.programId] : [TOKEN_PROGRAM_ADDRESS, TOKEN_2022_PROGRAM_ADDRESS];
8
8
  try {
9
- const responses = await Promise.all(
10
- programIds.map(async (pid) => {
11
- const resp = await connection.getTokenAccountsByOwner(owner, { programId: pid }, commitment);
12
- return resp.value.map(
13
- (info) => unpackAccount(info.pubkey, { data: info.account.data })
14
- );
15
- })
9
+ const results = await Promise.all(
10
+ programIds.map(
11
+ (programId) => fetchParsedTokenAccounts(client, owner, { programId }, options.commitment)
12
+ )
16
13
  );
17
- return responses.flat();
14
+ return results.flat();
18
15
  } catch (cause) {
19
16
  throw normalizeSolanaError(cause, "RPC_FAILURE");
20
17
  }
21
18
  }
22
- async function getTokenAccount(connection, address) {
19
+ async function getTokenAccount(client, address2, commitment) {
23
20
  try {
24
- const accountInfo = await connection.getAccountInfo(address);
25
- if (!accountInfo) {
21
+ const response = await client.rpc.getAccountInfo(address2, { encoding: "jsonParsed", commitment }).send();
22
+ const accountInfo = response.value;
23
+ if (!accountInfo || !isParsedTokenAccount(accountInfo.data) || accountInfo.data.parsed.type !== "account") {
26
24
  return null;
27
25
  }
28
- return unpackAccount(address, accountInfo);
26
+ return tokenAccountInfoFromParsed(address2, accountInfo.data);
29
27
  } catch (cause) {
30
28
  throw normalizeSolanaError(cause, "RPC_FAILURE");
31
29
  }
32
30
  }
33
- async function getTokenBalance(connection, mint, owner) {
31
+ async function getTokenBalance(client, mint, owner, commitment) {
34
32
  try {
35
- const ata = getAssociatedTokenAddressSync(mint, owner, true);
36
- const accountInfo = await connection.getAccountInfo(ata);
37
- if (!accountInfo) {
33
+ const [account] = await fetchParsedTokenAccounts(client, owner, { mint }, commitment);
34
+ if (!account) {
38
35
  return null;
39
36
  }
40
- const tokenAccount = unpackAccount(ata, accountInfo);
41
- const mintAccountInfo = await connection.getAccountInfo(mint);
42
- if (!mintAccountInfo) {
43
- return null;
44
- }
45
- const mintAccount = unpackMint(mint, mintAccountInfo);
46
- return { amount: tokenAccount.amount, decimals: mintAccount.decimals };
37
+ return { amount: account.amount, decimals: account.decimals };
47
38
  } catch (cause) {
48
39
  throw normalizeSolanaError(cause, "RPC_FAILURE");
49
40
  }
50
41
  }
42
+ async function fetchParsedTokenAccounts(client, owner, filter, commitment) {
43
+ const response = await client.rpc.getTokenAccountsByOwner(owner, filter, { encoding: "jsonParsed", commitment }).send();
44
+ return response.value.filter(({ account }) => isParsedTokenAccount(account.data)).map(({ pubkey, account }) => tokenAccountInfoFromParsed(pubkey, account.data));
45
+ }
46
+ function isParsedTokenAccount(data) {
47
+ return typeof data === "object" && data !== null && "parsed" in data;
48
+ }
49
+ function tokenAccountInfoFromParsed(address2, data) {
50
+ if (data.parsed.type !== "account") {
51
+ throw new Error(`Token account ${address2} is not a parsed token account`);
52
+ }
53
+ const parsed = data.parsed.info;
54
+ if (!parsed) {
55
+ throw new Error(`Token account ${address2} has no parsed data`);
56
+ }
57
+ return {
58
+ address: address2,
59
+ mint: parsed.mint,
60
+ owner: parsed.owner,
61
+ amount: BigInt(parsed.tokenAmount.amount),
62
+ decimals: parsed.tokenAmount.decimals,
63
+ state: parsed.state,
64
+ isNative: parsed.isNative
65
+ };
66
+ }
51
67
 
52
68
  export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
@@ -1,61 +1,80 @@
1
1
  'use strict';
2
2
 
3
+ const kit = require('@solana/kit');
3
4
  const errors = require('./errors.cjs');
4
- const timeout = require('./timeout.cjs');
5
5
  const wallet = require('./wallet.cjs');
6
6
 
7
7
  const DEFAULT_CONFIRMATION_COMMITMENT = "confirmed";
8
8
  const DEFAULT_CONFIRMATION_TIMEOUT_MS = 6e4;
9
- async function signAndSendTransaction(connection, wallet$1, transaction, options) {
9
+ const SIGNATURE_STATUS_POLL_INTERVAL_MS = 1500;
10
+ const COMMITMENT_RANK = { processed: 0, confirmed: 1, finalized: 2 };
11
+ async function signAndSendTransaction(client, wallet$1, transaction, options) {
10
12
  try {
11
13
  wallet.assertWalletConnected(wallet$1);
12
- if (isMobileWalletAdapterWallet(wallet$1) && wallet$1.signTransaction) {
13
- wallet.assertWalletCanSign(wallet$1);
14
- return await signAndSendRawTransaction(connection, wallet$1, transaction, options);
15
- }
16
14
  if (wallet$1.signAndSendTransaction) {
17
15
  const result = await wallet$1.signAndSendTransaction(transaction, options);
18
16
  return result.signature;
19
17
  }
20
18
  wallet.assertWalletCanSign(wallet$1);
21
- return await signAndSendRawTransaction(connection, wallet$1, transaction, options);
19
+ const signedTransaction = await wallet$1.signTransaction(transaction);
20
+ const base64Transaction = toBase64WireTransaction(signedTransaction);
21
+ const { maxRetries, minContextSlot, preflightCommitment, skipPreflight } = options ?? {};
22
+ return await client.rpc.sendTransaction(base64Transaction, {
23
+ encoding: "base64",
24
+ maxRetries,
25
+ minContextSlot,
26
+ preflightCommitment,
27
+ skipPreflight
28
+ }).send();
22
29
  } catch (cause) {
23
30
  throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
24
31
  }
25
32
  }
26
- async function confirmTransactionSignature(connection, signature, options = {}) {
33
+ async function confirmTransactionSignature(client, signature, options = {}) {
27
34
  const commitment = options.commitment ?? DEFAULT_CONFIRMATION_COMMITMENT;
28
- const confirmation = connection.confirmTransaction(signature, commitment);
29
- let result;
35
+ const timeoutMs = options.timeoutMs ?? DEFAULT_CONFIRMATION_TIMEOUT_MS;
36
+ let elapsedMs = 0;
30
37
  try {
31
- result = await timeout.withSolanaTimeout(
32
- confirmation,
33
- options.timeoutMs ?? DEFAULT_CONFIRMATION_TIMEOUT_MS,
38
+ while (elapsedMs < timeoutMs) {
39
+ const response = await client.rpc.getSignatureStatuses([signature]).send();
40
+ const [status] = response.value;
41
+ if (!status) {
42
+ throw new Error(`Transaction ${signature} was not found.`);
43
+ }
44
+ if (status.err) {
45
+ throw errors.createSolanaError(
46
+ "RPC_FAILURE",
47
+ `Transaction ${signature} failed to reach ${commitment} commitment.`,
48
+ { cause: status.err }
49
+ );
50
+ }
51
+ if (hasReachedCommitment(status.confirmationStatus, commitment)) {
52
+ return { signature, commitment, status };
53
+ }
54
+ await wait(SIGNATURE_STATUS_POLL_INTERVAL_MS);
55
+ elapsedMs += SIGNATURE_STATUS_POLL_INTERVAL_MS;
56
+ }
57
+ throw errors.createSolanaError(
58
+ "TRANSACTION_TIMEOUT",
34
59
  `Timed out waiting for transaction ${signature} to reach ${commitment} commitment.`
35
60
  );
36
61
  } catch (cause) {
37
62
  throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
38
63
  }
39
- if (result.value.err) {
40
- throw errors.createSolanaError(
41
- "RPC_FAILURE",
42
- `Transaction ${signature} failed to reach ${commitment} commitment.`,
43
- { cause: result.value.err }
44
- );
45
- }
46
- return {
47
- signature,
48
- commitment,
49
- result
50
- };
51
64
  }
52
- async function signAndSendRawTransaction(connection, wallet, transaction, options) {
53
- const signedTransaction = await wallet.signTransaction(transaction);
54
- const rawTransaction = signedTransaction.serialize();
55
- return connection.sendRawTransaction(rawTransaction, options);
65
+ function toBase64WireTransaction(transaction) {
66
+ return kit.getBase64EncodedWireTransaction(kit.getTransactionDecoder().decode(transaction));
67
+ }
68
+ function hasReachedCommitment(actualStatus, targetCommitment) {
69
+ if (!actualStatus) {
70
+ return false;
71
+ }
72
+ return (COMMITMENT_RANK[actualStatus] ?? 0) >= (COMMITMENT_RANK[targetCommitment] ?? 0);
56
73
  }
57
- function isMobileWalletAdapterWallet(wallet) {
58
- return wallet.source === "mobile-wallet-adapter";
74
+ function wait(ms) {
75
+ return new Promise((resolve) => {
76
+ setTimeout(resolve, ms);
77
+ });
59
78
  }
60
79
 
61
80
  exports.confirmTransactionSignature = confirmTransactionSignature;
@@ -1,23 +1,17 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
- import { Connection, TransactionSignature } from '@solana/web3-compat';
4
- import { C as ConfirmTransactionOptions, T as TransactionConfirmation, h as SolanaWallet, g as SolanaTransaction, S as SendTransactionOptions } from './shared/core.DAUuCWrr.cjs';
5
- import '@solana/kit';
1
+ import { Signature } from '@solana/kit';
2
+ import { b as SolanaClient, C as ConfirmTransactionOptions, T as TransactionConfirmation, k as SolanaWallet, j as SolanaTransaction, S as SendTransactionOptions } from './shared/core.CQ_yMDAL.cjs';
6
3
 
7
4
  /**
8
- * Sign and send a transaction through a connected wallet using the legacy
9
- * web3-compat `Connection` API.
5
+ * Sign and send a transaction through a connected wallet.
10
6
  *
11
- * @deprecated Kit transactions are sent with `client.sendTransaction([...])`
12
- * once the client has a payer; see `@vue-solana/core/kit`.
7
+ * Walks through the supported kit RPC path: the wallet signs the raw wire
8
+ * transaction, and the client sends it via `client.rpc.sendTransaction`.
13
9
  */
14
- declare function signAndSendTransaction(connection: Connection, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<TransactionSignature>;
10
+ declare function signAndSendTransaction(client: SolanaClient, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<Signature>;
15
11
  /**
16
- * Confirm a transaction signature using the legacy `Connection` API.
17
- *
18
- * @deprecated Use `client.rpc.getSignatureStatuses([...]).send()` from
19
- * `@vue-solana/core/kit` instead.
12
+ * Confirm a transaction signature against the kit RPC until it reaches the
13
+ * requested commitment.
20
14
  */
21
- declare function confirmTransactionSignature(connection: Connection, signature: TransactionSignature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
15
+ declare function confirmTransactionSignature(client: SolanaClient, signature: Signature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
22
16
 
23
17
  export { confirmTransactionSignature, signAndSendTransaction };
@@ -1,23 +1,17 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
- import { Connection, TransactionSignature } from '@solana/web3-compat';
4
- import { C as ConfirmTransactionOptions, T as TransactionConfirmation, h as SolanaWallet, g as SolanaTransaction, S as SendTransactionOptions } from './shared/core.DAUuCWrr.mjs';
5
- import '@solana/kit';
1
+ import { Signature } from '@solana/kit';
2
+ import { b as SolanaClient, C as ConfirmTransactionOptions, T as TransactionConfirmation, k as SolanaWallet, j as SolanaTransaction, S as SendTransactionOptions } from './shared/core.CQ_yMDAL.mjs';
6
3
 
7
4
  /**
8
- * Sign and send a transaction through a connected wallet using the legacy
9
- * web3-compat `Connection` API.
5
+ * Sign and send a transaction through a connected wallet.
10
6
  *
11
- * @deprecated Kit transactions are sent with `client.sendTransaction([...])`
12
- * once the client has a payer; see `@vue-solana/core/kit`.
7
+ * Walks through the supported kit RPC path: the wallet signs the raw wire
8
+ * transaction, and the client sends it via `client.rpc.sendTransaction`.
13
9
  */
14
- declare function signAndSendTransaction(connection: Connection, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<TransactionSignature>;
10
+ declare function signAndSendTransaction(client: SolanaClient, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<Signature>;
15
11
  /**
16
- * Confirm a transaction signature using the legacy `Connection` API.
17
- *
18
- * @deprecated Use `client.rpc.getSignatureStatuses([...]).send()` from
19
- * `@vue-solana/core/kit` instead.
12
+ * Confirm a transaction signature against the kit RPC until it reaches the
13
+ * requested commitment.
20
14
  */
21
- declare function confirmTransactionSignature(connection: Connection, signature: TransactionSignature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
15
+ declare function confirmTransactionSignature(client: SolanaClient, signature: Signature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
22
16
 
23
17
  export { confirmTransactionSignature, signAndSendTransaction };
@@ -1,23 +1,17 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
- import { Connection, TransactionSignature } from '@solana/web3-compat';
4
- import { C as ConfirmTransactionOptions, T as TransactionConfirmation, h as SolanaWallet, g as SolanaTransaction, S as SendTransactionOptions } from './shared/core.DAUuCWrr.js';
5
- import '@solana/kit';
1
+ import { Signature } from '@solana/kit';
2
+ import { b as SolanaClient, C as ConfirmTransactionOptions, T as TransactionConfirmation, k as SolanaWallet, j as SolanaTransaction, S as SendTransactionOptions } from './shared/core.CQ_yMDAL.js';
6
3
 
7
4
  /**
8
- * Sign and send a transaction through a connected wallet using the legacy
9
- * web3-compat `Connection` API.
5
+ * Sign and send a transaction through a connected wallet.
10
6
  *
11
- * @deprecated Kit transactions are sent with `client.sendTransaction([...])`
12
- * once the client has a payer; see `@vue-solana/core/kit`.
7
+ * Walks through the supported kit RPC path: the wallet signs the raw wire
8
+ * transaction, and the client sends it via `client.rpc.sendTransaction`.
13
9
  */
14
- declare function signAndSendTransaction(connection: Connection, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<TransactionSignature>;
10
+ declare function signAndSendTransaction(client: SolanaClient, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<Signature>;
15
11
  /**
16
- * Confirm a transaction signature using the legacy `Connection` API.
17
- *
18
- * @deprecated Use `client.rpc.getSignatureStatuses([...]).send()` from
19
- * `@vue-solana/core/kit` instead.
12
+ * Confirm a transaction signature against the kit RPC until it reaches the
13
+ * requested commitment.
20
14
  */
21
- declare function confirmTransactionSignature(connection: Connection, signature: TransactionSignature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
15
+ declare function confirmTransactionSignature(client: SolanaClient, signature: Signature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
22
16
 
23
17
  export { confirmTransactionSignature, signAndSendTransaction };
@@ -1,59 +1,78 @@
1
- import { normalizeSolanaError, createSolanaError } from './errors.mjs';
2
- import { withSolanaTimeout } from './timeout.mjs';
1
+ import { getBase64EncodedWireTransaction, getTransactionDecoder } from '@solana/kit';
2
+ import { createSolanaError, normalizeSolanaError } from './errors.mjs';
3
3
  import { assertWalletConnected, assertWalletCanSign } from './wallet.mjs';
4
4
 
5
5
  const DEFAULT_CONFIRMATION_COMMITMENT = "confirmed";
6
6
  const DEFAULT_CONFIRMATION_TIMEOUT_MS = 6e4;
7
- async function signAndSendTransaction(connection, wallet, transaction, options) {
7
+ const SIGNATURE_STATUS_POLL_INTERVAL_MS = 1500;
8
+ const COMMITMENT_RANK = { processed: 0, confirmed: 1, finalized: 2 };
9
+ async function signAndSendTransaction(client, wallet, transaction, options) {
8
10
  try {
9
11
  assertWalletConnected(wallet);
10
- if (isMobileWalletAdapterWallet(wallet) && wallet.signTransaction) {
11
- assertWalletCanSign(wallet);
12
- return await signAndSendRawTransaction(connection, wallet, transaction, options);
13
- }
14
12
  if (wallet.signAndSendTransaction) {
15
13
  const result = await wallet.signAndSendTransaction(transaction, options);
16
14
  return result.signature;
17
15
  }
18
16
  assertWalletCanSign(wallet);
19
- return await signAndSendRawTransaction(connection, wallet, transaction, options);
17
+ const signedTransaction = await wallet.signTransaction(transaction);
18
+ const base64Transaction = toBase64WireTransaction(signedTransaction);
19
+ const { maxRetries, minContextSlot, preflightCommitment, skipPreflight } = options ?? {};
20
+ return await client.rpc.sendTransaction(base64Transaction, {
21
+ encoding: "base64",
22
+ maxRetries,
23
+ minContextSlot,
24
+ preflightCommitment,
25
+ skipPreflight
26
+ }).send();
20
27
  } catch (cause) {
21
28
  throw normalizeSolanaError(cause, "RPC_FAILURE");
22
29
  }
23
30
  }
24
- async function confirmTransactionSignature(connection, signature, options = {}) {
31
+ async function confirmTransactionSignature(client, signature, options = {}) {
25
32
  const commitment = options.commitment ?? DEFAULT_CONFIRMATION_COMMITMENT;
26
- const confirmation = connection.confirmTransaction(signature, commitment);
27
- let result;
33
+ const timeoutMs = options.timeoutMs ?? DEFAULT_CONFIRMATION_TIMEOUT_MS;
34
+ let elapsedMs = 0;
28
35
  try {
29
- result = await withSolanaTimeout(
30
- confirmation,
31
- options.timeoutMs ?? DEFAULT_CONFIRMATION_TIMEOUT_MS,
36
+ while (elapsedMs < timeoutMs) {
37
+ const response = await client.rpc.getSignatureStatuses([signature]).send();
38
+ const [status] = response.value;
39
+ if (!status) {
40
+ throw new Error(`Transaction ${signature} was not found.`);
41
+ }
42
+ if (status.err) {
43
+ throw createSolanaError(
44
+ "RPC_FAILURE",
45
+ `Transaction ${signature} failed to reach ${commitment} commitment.`,
46
+ { cause: status.err }
47
+ );
48
+ }
49
+ if (hasReachedCommitment(status.confirmationStatus, commitment)) {
50
+ return { signature, commitment, status };
51
+ }
52
+ await wait(SIGNATURE_STATUS_POLL_INTERVAL_MS);
53
+ elapsedMs += SIGNATURE_STATUS_POLL_INTERVAL_MS;
54
+ }
55
+ throw createSolanaError(
56
+ "TRANSACTION_TIMEOUT",
32
57
  `Timed out waiting for transaction ${signature} to reach ${commitment} commitment.`
33
58
  );
34
59
  } catch (cause) {
35
60
  throw normalizeSolanaError(cause, "RPC_FAILURE");
36
61
  }
37
- if (result.value.err) {
38
- throw createSolanaError(
39
- "RPC_FAILURE",
40
- `Transaction ${signature} failed to reach ${commitment} commitment.`,
41
- { cause: result.value.err }
42
- );
43
- }
44
- return {
45
- signature,
46
- commitment,
47
- result
48
- };
49
62
  }
50
- async function signAndSendRawTransaction(connection, wallet, transaction, options) {
51
- const signedTransaction = await wallet.signTransaction(transaction);
52
- const rawTransaction = signedTransaction.serialize();
53
- return connection.sendRawTransaction(rawTransaction, options);
63
+ function toBase64WireTransaction(transaction) {
64
+ return getBase64EncodedWireTransaction(getTransactionDecoder().decode(transaction));
65
+ }
66
+ function hasReachedCommitment(actualStatus, targetCommitment) {
67
+ if (!actualStatus) {
68
+ return false;
69
+ }
70
+ return (COMMITMENT_RANK[actualStatus] ?? 0) >= (COMMITMENT_RANK[targetCommitment] ?? 0);
54
71
  }
55
- function isMobileWalletAdapterWallet(wallet) {
56
- return wallet.source === "mobile-wallet-adapter";
72
+ function wait(ms) {
73
+ return new Promise((resolve) => {
74
+ setTimeout(resolve, ms);
75
+ });
57
76
  }
58
77
 
59
78
  export { confirmTransactionSignature, signAndSendTransaction };
package/dist/types.d.cts CHANGED
@@ -1,5 +1,2 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
- import '@solana/web3-compat';
4
- export { C as ConfirmTransactionOptions, S as SendTransactionOptions, a as SolanaChain, c as SolanaCluster, d as SolanaConfig, e as SolanaContext, f as SolanaSignMessageResult, g as SolanaTransaction, h as SolanaWallet, i as SolanaWalletInfo, T as TransactionConfirmation } from './shared/core.DAUuCWrr.cjs';
5
1
  import '@solana/kit';
2
+ export { C as ConfirmTransactionOptions, S as SendTransactionOptions, a as SolanaChain, c as SolanaCluster, d as SolanaConfig, e as SolanaContext, f as SolanaSignInAccount, g as SolanaSignInInput, h as SolanaSignInResult, i as SolanaSignMessageResult, j as SolanaTransaction, k as SolanaWallet, l as SolanaWalletInfo, T as TransactionConfirmation, m as TransactionStatus } from './shared/core.CQ_yMDAL.cjs';
package/dist/types.d.mts CHANGED
@@ -1,5 +1,2 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
- import '@solana/web3-compat';
4
- export { C as ConfirmTransactionOptions, S as SendTransactionOptions, a as SolanaChain, c as SolanaCluster, d as SolanaConfig, e as SolanaContext, f as SolanaSignMessageResult, g as SolanaTransaction, h as SolanaWallet, i as SolanaWalletInfo, T as TransactionConfirmation } from './shared/core.DAUuCWrr.mjs';
5
1
  import '@solana/kit';
2
+ export { C as ConfirmTransactionOptions, S as SendTransactionOptions, a as SolanaChain, c as SolanaCluster, d as SolanaConfig, e as SolanaContext, f as SolanaSignInAccount, g as SolanaSignInInput, h as SolanaSignInResult, i as SolanaSignMessageResult, j as SolanaTransaction, k as SolanaWallet, l as SolanaWalletInfo, T as TransactionConfirmation, m as TransactionStatus } from './shared/core.CQ_yMDAL.mjs';
package/dist/types.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
- import '@solana/web3-compat';
4
- export { C as ConfirmTransactionOptions, S as SendTransactionOptions, a as SolanaChain, c as SolanaCluster, d as SolanaConfig, e as SolanaContext, f as SolanaSignMessageResult, g as SolanaTransaction, h as SolanaWallet, i as SolanaWalletInfo, T as TransactionConfirmation } from './shared/core.DAUuCWrr.js';
5
1
  import '@solana/kit';
2
+ export { C as ConfirmTransactionOptions, S as SendTransactionOptions, a as SolanaChain, c as SolanaCluster, d as SolanaConfig, e as SolanaContext, f as SolanaSignInAccount, g as SolanaSignInInput, h as SolanaSignInResult, i as SolanaSignMessageResult, j as SolanaTransaction, k as SolanaWallet, l as SolanaWalletInfo, T as TransactionConfirmation, m as TransactionStatus } from './shared/core.CQ_yMDAL.js';
@@ -1,12 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const discovery = require('./shared/core.BQoh-5Wu.cjs');
3
+ const discovery = require('./shared/core.DjxUirkw.cjs');
4
4
  require('@wallet-standard/features');
5
5
  require('@solana/wallet-standard-features');
6
- require('@solana/web3-compat');
7
6
  require('bs58');
8
- require('./wallet.cjs');
9
- require('./errors.cjs');
10
7
  require('@wallet-standard/app');
11
8
 
12
9
 
@@ -1,8 +1,5 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
1
  import { WalletAccount, Wallet } from '@wallet-standard/base';
4
- import { a as SolanaChain, i as SolanaWalletInfo, h as SolanaWallet, c as SolanaCluster } from './shared/core.DAUuCWrr.cjs';
5
- import '@solana/web3-compat';
2
+ import { a as SolanaChain, l as SolanaWalletInfo, k as SolanaWallet, c as SolanaCluster } from './shared/core.CQ_yMDAL.cjs';
6
3
  import '@solana/kit';
7
4
 
8
5
  interface AdaptSolanaWalletOptions {
@@ -1,8 +1,5 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
1
  import { WalletAccount, Wallet } from '@wallet-standard/base';
4
- import { a as SolanaChain, i as SolanaWalletInfo, h as SolanaWallet, c as SolanaCluster } from './shared/core.DAUuCWrr.mjs';
5
- import '@solana/web3-compat';
2
+ import { a as SolanaChain, l as SolanaWalletInfo, k as SolanaWallet, c as SolanaCluster } from './shared/core.CQ_yMDAL.mjs';
6
3
  import '@solana/kit';
7
4
 
8
5
  interface AdaptSolanaWalletOptions {
@@ -1,8 +1,5 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
1
  import { WalletAccount, Wallet } from '@wallet-standard/base';
4
- import { a as SolanaChain, i as SolanaWalletInfo, h as SolanaWallet, c as SolanaCluster } from './shared/core.DAUuCWrr.js';
5
- import '@solana/web3-compat';
2
+ import { a as SolanaChain, l as SolanaWalletInfo, k as SolanaWallet, c as SolanaCluster } from './shared/core.CQ_yMDAL.js';
6
3
  import '@solana/kit';
7
4
 
8
5
  interface AdaptSolanaWalletOptions {
@@ -1,8 +1,5 @@
1
- export { S as SOLANA_CHAINS, a as SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, b as adaptSolanaStandardWallet, g as getRegisteredSolanaWallets, c as getSolanaChain, i as isSolanaStandardWallet, s as subscribeSolanaWallets } from './shared/core.DjbtrJWl.mjs';
1
+ export { S as SOLANA_CHAINS, a as SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, b as adaptSolanaStandardWallet, g as getRegisteredSolanaWallets, c as getSolanaChain, i as isSolanaStandardWallet, s as subscribeSolanaWallets } from './shared/core.DEcQDbtz.mjs';
2
2
  import '@wallet-standard/features';
3
3
  import '@solana/wallet-standard-features';
4
- import '@solana/web3-compat';
5
4
  import 'bs58';
6
- import './wallet.mjs';
7
- import './errors.mjs';
8
5
  import '@wallet-standard/app';
package/dist/wallet.cjs CHANGED
@@ -39,10 +39,43 @@ function assertWalletCanSignMessage(wallet) {
39
39
  );
40
40
  }
41
41
  }
42
+ function assertWalletCanSignIn(wallet) {
43
+ assertWalletConnected(wallet);
44
+ if (!wallet.signIn) {
45
+ throw new SolanaWalletError(
46
+ "WALLET_FEATURE_UNSUPPORTED",
47
+ "Solana wallet does not support signIn (Sign In With Solana)",
48
+ { feature: "signIn" }
49
+ );
50
+ }
51
+ }
52
+ function assertWalletCanSignTransactions(wallet) {
53
+ assertWalletConnected(wallet);
54
+ if (!wallet.signTransactions && !wallet.signAllTransactions) {
55
+ throw new SolanaWalletError(
56
+ "WALLET_FEATURE_UNSUPPORTED",
57
+ "Solana wallet does not support signTransactions",
58
+ { feature: "signTransactions" }
59
+ );
60
+ }
61
+ }
62
+ function assertWalletCanSignAndSendTransactions(wallet) {
63
+ assertWalletConnected(wallet);
64
+ if (!wallet.signAndSendTransactions && !wallet.signAndSendTransaction) {
65
+ throw new SolanaWalletError(
66
+ "WALLET_FEATURE_UNSUPPORTED",
67
+ "Solana wallet does not support signAndSendTransactions",
68
+ { feature: "signAndSendTransactions" }
69
+ );
70
+ }
71
+ }
42
72
 
43
73
  exports.SolanaWalletError = SolanaWalletError;
44
74
  exports.assertWalletCanSign = assertWalletCanSign;
75
+ exports.assertWalletCanSignAndSendTransactions = assertWalletCanSignAndSendTransactions;
76
+ exports.assertWalletCanSignIn = assertWalletCanSignIn;
45
77
  exports.assertWalletCanSignMessage = assertWalletCanSignMessage;
78
+ exports.assertWalletCanSignTransactions = assertWalletCanSignTransactions;
46
79
  exports.assertWalletConnected = assertWalletConnected;
47
80
  exports.createNoWalletSelectedError = createNoWalletSelectedError;
48
81
  exports.isWalletConnected = isWalletConnected;
package/dist/wallet.d.cts CHANGED
@@ -1,8 +1,5 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
- import { h as SolanaWallet } from './shared/core.DAUuCWrr.cjs';
1
+ import { k as SolanaWallet } from './shared/core.CQ_yMDAL.cjs';
4
2
  import { SolanaError } from './errors.cjs';
5
- import '@solana/web3-compat';
6
3
  import '@solana/kit';
7
4
 
8
5
  type SolanaWalletErrorCode = "NO_WALLET_SELECTED" | "WALLET_NOT_CONNECTED" | "WALLET_FEATURE_UNSUPPORTED";
@@ -19,6 +16,9 @@ declare function assertWalletConnected(wallet: SolanaWallet | null | undefined):
19
16
  };
20
17
  declare function assertWalletCanSign(wallet: SolanaWallet | null | undefined): asserts wallet is SolanaWallet & Required<Pick<SolanaWallet, "signTransaction">>;
21
18
  declare function assertWalletCanSignMessage(wallet: SolanaWallet | null | undefined): asserts wallet is SolanaWallet & Required<Pick<SolanaWallet, "signMessage">>;
19
+ declare function assertWalletCanSignIn(wallet: SolanaWallet | null | undefined): asserts wallet is SolanaWallet & Required<Pick<SolanaWallet, "signIn">>;
20
+ declare function assertWalletCanSignTransactions(wallet: SolanaWallet | null | undefined): asserts wallet is SolanaWallet & Required<Pick<SolanaWallet, "signTransactions">>;
21
+ declare function assertWalletCanSignAndSendTransactions(wallet: SolanaWallet | null | undefined): asserts wallet is SolanaWallet & Required<Pick<SolanaWallet, "signAndSendTransactions">>;
22
22
 
23
- export { SolanaWalletError, assertWalletCanSign, assertWalletCanSignMessage, assertWalletConnected, createNoWalletSelectedError, isWalletConnected };
23
+ export { SolanaWalletError, assertWalletCanSign, assertWalletCanSignAndSendTransactions, assertWalletCanSignIn, assertWalletCanSignMessage, assertWalletCanSignTransactions, assertWalletConnected, createNoWalletSelectedError, isWalletConnected };
24
24
  export type { SolanaWalletErrorCode };