@vue-solana/core 1.1.0 → 2.0.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 (75) hide show
  1. package/README.md +44 -35
  2. package/dist/address.cjs +10 -10
  3. package/dist/address.d.cts +14 -10
  4. package/dist/address.d.mts +14 -10
  5. package/dist/address.d.ts +14 -10
  6. package/dist/address.mjs +10 -10
  7. package/dist/buffer-polyfill.d.cts +0 -1
  8. package/dist/buffer-polyfill.d.mts +0 -1
  9. package/dist/buffer-polyfill.d.ts +0 -1
  10. package/dist/clusters.d.cts +2 -4
  11. package/dist/clusters.d.mts +2 -4
  12. package/dist/clusters.d.ts +2 -4
  13. package/dist/index.cjs +9 -19
  14. package/dist/index.d.cts +5 -8
  15. package/dist/index.d.mts +5 -8
  16. package/dist/index.d.ts +5 -8
  17. package/dist/index.mjs +7 -6
  18. package/dist/ios-wallet.cjs +2 -2
  19. package/dist/ios-wallet.d.cts +2 -4
  20. package/dist/ios-wallet.d.mts +2 -4
  21. package/dist/ios-wallet.d.ts +2 -4
  22. package/dist/ios-wallet.mjs +2 -2
  23. package/dist/kit.cjs +21 -0
  24. package/dist/kit.d.cts +2 -0
  25. package/dist/kit.d.mts +2 -0
  26. package/dist/kit.d.ts +2 -0
  27. package/dist/kit.mjs +18 -0
  28. package/dist/mobile-wallet.d.cts +2 -4
  29. package/dist/mobile-wallet.d.mts +2 -4
  30. package/dist/mobile-wallet.d.ts +2 -4
  31. package/dist/rpc.cjs +4 -12
  32. package/dist/rpc.d.cts +3 -6
  33. package/dist/rpc.d.mts +3 -6
  34. package/dist/rpc.d.ts +3 -6
  35. package/dist/rpc.mjs +5 -12
  36. package/dist/shared/{core.BBMCTQpw.mjs → core.BOHiMZiM.mjs} +7 -30
  37. package/dist/shared/{core.Ch_Z7_17.mjs → core.BwW4HVQI.mjs} +12 -28
  38. package/dist/shared/{core.BsekSwcZ.cjs → core.Cb48vQvC.cjs} +12 -28
  39. package/dist/shared/{core.BU9rgxEj.cjs → core.Cu_gaUSn.cjs} +20 -43
  40. package/dist/shared/core.DMgTrB_2.d.cts +102 -0
  41. package/dist/shared/core.DMgTrB_2.d.mts +102 -0
  42. package/dist/shared/core.DMgTrB_2.d.ts +102 -0
  43. package/dist/token-accounts.cjs +44 -28
  44. package/dist/token-accounts.d.cts +26 -8
  45. package/dist/token-accounts.d.mts +26 -8
  46. package/dist/token-accounts.d.ts +26 -8
  47. package/dist/token-accounts.mjs +44 -28
  48. package/dist/transaction.cjs +50 -31
  49. package/dist/transaction.d.cts +14 -6
  50. package/dist/transaction.d.mts +14 -6
  51. package/dist/transaction.d.ts +14 -6
  52. package/dist/transaction.mjs +51 -32
  53. package/dist/types.d.cts +2 -80
  54. package/dist/types.d.mts +2 -80
  55. package/dist/types.d.ts +2 -80
  56. package/dist/wallet-standard.cjs +1 -4
  57. package/dist/wallet-standard.d.cts +2 -4
  58. package/dist/wallet-standard.d.mts +2 -4
  59. package/dist/wallet-standard.d.ts +2 -4
  60. package/dist/wallet-standard.mjs +1 -4
  61. package/dist/wallet.d.cts +2 -4
  62. package/dist/wallet.d.mts +2 -4
  63. package/dist/wallet.d.ts +2 -4
  64. package/package.json +9 -14
  65. package/dist/spl-token.cjs +0 -12
  66. package/dist/spl-token.d.cts +0 -4
  67. package/dist/spl-token.d.mts +0 -4
  68. package/dist/spl-token.d.ts +0 -4
  69. package/dist/spl-token.mjs +0 -1
  70. package/dist/web3.cjs +0 -13
  71. package/dist/web3.d.cts +0 -3
  72. package/dist/web3.d.mts +0 -3
  73. package/dist/web3.d.ts +0 -3
  74. package/dist/web3.mjs +0 -1
  75. package/types/web3-compat.d.ts +0 -140
@@ -1,17 +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.DMgTrB_2.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
- declare function getTokenAccountsByOwner(connection: Connection, owner: PublicKey, options?: TokenAccountsByOwnerOptions): Promise<Account[]>;
9
- declare function getTokenAccount(connection: Connection, address: PublicKey): Promise<Account | null>;
17
+ /**
18
+ * Get all SPL token accounts for an owner using parsed kit RPC reads.
19
+ */
20
+ declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
21
+ /**
22
+ * Get a single parsed token account at the given address.
23
+ */
24
+ declare function getTokenAccount(client: SolanaClient, address: Address, commitment?: Commitment): Promise<TokenAccountInfo | null>;
10
25
  interface TokenBalanceResult {
11
26
  amount: bigint;
12
27
  decimals: number;
13
28
  }
14
- declare function getTokenBalance(connection: Connection, mint: PublicKey, owner: PublicKey): Promise<TokenBalanceResult | null>;
29
+ /**
30
+ * Read the token balance of the accounts an owner holds for a given mint.
31
+ */
32
+ declare function getTokenBalance(client: SolanaClient, mint: Address, owner: Address, commitment?: Commitment): Promise<TokenBalanceResult | null>;
15
33
 
16
34
  export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
17
- 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,9 +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 { ConfirmTransactionOptions, TransactionConfirmation, SolanaWallet, SolanaTransaction, SendTransactionOptions } from './types.cjs';
1
+ import { Signature } from '@solana/kit';
2
+ import { b as SolanaClient, C as ConfirmTransactionOptions, T as TransactionConfirmation, h as SolanaWallet, g as SolanaTransaction, S as SendTransactionOptions } from './shared/core.DMgTrB_2.cjs';
5
3
 
6
- declare function signAndSendTransaction(connection: Connection, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<TransactionSignature>;
7
- declare function confirmTransactionSignature(connection: Connection, signature: TransactionSignature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
4
+ /**
5
+ * Sign and send a transaction through a connected wallet.
6
+ *
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`.
9
+ */
10
+ declare function signAndSendTransaction(client: SolanaClient, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<Signature>;
11
+ /**
12
+ * Confirm a transaction signature against the kit RPC until it reaches the
13
+ * requested commitment.
14
+ */
15
+ declare function confirmTransactionSignature(client: SolanaClient, signature: Signature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
8
16
 
9
17
  export { confirmTransactionSignature, signAndSendTransaction };
@@ -1,9 +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 { ConfirmTransactionOptions, TransactionConfirmation, SolanaWallet, SolanaTransaction, SendTransactionOptions } from './types.mjs';
1
+ import { Signature } from '@solana/kit';
2
+ import { b as SolanaClient, C as ConfirmTransactionOptions, T as TransactionConfirmation, h as SolanaWallet, g as SolanaTransaction, S as SendTransactionOptions } from './shared/core.DMgTrB_2.mjs';
5
3
 
6
- declare function signAndSendTransaction(connection: Connection, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<TransactionSignature>;
7
- declare function confirmTransactionSignature(connection: Connection, signature: TransactionSignature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
4
+ /**
5
+ * Sign and send a transaction through a connected wallet.
6
+ *
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`.
9
+ */
10
+ declare function signAndSendTransaction(client: SolanaClient, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<Signature>;
11
+ /**
12
+ * Confirm a transaction signature against the kit RPC until it reaches the
13
+ * requested commitment.
14
+ */
15
+ declare function confirmTransactionSignature(client: SolanaClient, signature: Signature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
8
16
 
9
17
  export { confirmTransactionSignature, signAndSendTransaction };
@@ -1,9 +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 { ConfirmTransactionOptions, TransactionConfirmation, SolanaWallet, SolanaTransaction, SendTransactionOptions } from './types.js';
1
+ import { Signature } from '@solana/kit';
2
+ import { b as SolanaClient, C as ConfirmTransactionOptions, T as TransactionConfirmation, h as SolanaWallet, g as SolanaTransaction, S as SendTransactionOptions } from './shared/core.DMgTrB_2.js';
5
3
 
6
- declare function signAndSendTransaction(connection: Connection, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<TransactionSignature>;
7
- declare function confirmTransactionSignature(connection: Connection, signature: TransactionSignature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
4
+ /**
5
+ * Sign and send a transaction through a connected wallet.
6
+ *
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`.
9
+ */
10
+ declare function signAndSendTransaction(client: SolanaClient, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<Signature>;
11
+ /**
12
+ * Confirm a transaction signature against the kit RPC until it reaches the
13
+ * requested commitment.
14
+ */
15
+ declare function confirmTransactionSignature(client: SolanaClient, signature: Signature, options?: ConfirmTransactionOptions): Promise<TransactionConfirmation>;
8
16
 
9
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,80 +1,2 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
- import { Commitment, SendOptions, Connection, Transaction, VersionedTransaction, PublicKey, TransactionSignature, RpcResponseAndContext, SignatureResult } from '@solana/web3-compat';
4
-
5
- type SolanaCluster = "mainnet-beta" | "testnet" | "devnet" | "localnet";
6
- type SolanaChain = "solana:mainnet" | "solana:testnet" | "solana:devnet" | "solana:localnet";
7
- interface SolanaConfig {
8
- cluster?: SolanaCluster;
9
- endpoint?: string;
10
- wsEndpoint?: string;
11
- commitment?: Commitment;
12
- autoConnect?: boolean;
13
- }
14
- interface SolanaContext {
15
- cluster: SolanaCluster;
16
- endpoint: string;
17
- wsEndpoint: string;
18
- connection: Connection;
19
- }
20
- type SolanaTransaction = Transaction | VersionedTransaction;
21
- interface SolanaSignMessageResult {
22
- signedMessage: Uint8Array;
23
- signature: Uint8Array;
24
- }
25
- interface SolanaWallet {
26
- publicKey: PublicKey | null;
27
- connected: boolean;
28
- connecting?: boolean;
29
- disconnecting?: boolean;
30
- platform?: SolanaWalletInfo["platform"];
31
- source?: SolanaWalletInfo["source"];
32
- connect: () => Promise<void>;
33
- disconnect: () => Promise<void>;
34
- signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
35
- signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
36
- signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
37
- signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
38
- signature: TransactionSignature;
39
- }>;
40
- }
41
- interface SolanaWalletInfo {
42
- name: string;
43
- icon: string;
44
- chains: readonly string[];
45
- platform?: "browser" | "mobile" | "desktop";
46
- source?: "wallet-standard" | "mobile-wallet-adapter" | "deep-link" | "protocol-link";
47
- appUrl?: string;
48
- installUrl?: string;
49
- callbackUrl?: string;
50
- capabilities?: {
51
- connect?: boolean;
52
- disconnect?: boolean;
53
- signMessage?: boolean;
54
- signTransaction?: boolean;
55
- signAllTransactions?: boolean;
56
- signAndSendTransaction?: boolean;
57
- };
58
- accounts: readonly {
59
- address: string;
60
- publicKey: Uint8Array;
61
- chains: readonly string[];
62
- label?: string;
63
- icon?: string;
64
- }[];
65
- wallet: unknown;
66
- }
67
- interface SendTransactionOptions extends SendOptions {
68
- skipPreflight?: boolean;
69
- }
70
- interface ConfirmTransactionOptions {
71
- commitment?: Commitment;
72
- timeoutMs?: number;
73
- }
74
- interface TransactionConfirmation {
75
- signature: TransactionSignature;
76
- commitment: Commitment;
77
- result: RpcResponseAndContext<SignatureResult>;
78
- }
79
-
80
- export type { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaSignMessageResult, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation };
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 SolanaSignMessageResult, g as SolanaTransaction, h as SolanaWallet, i as SolanaWalletInfo, T as TransactionConfirmation, j as TransactionStatus } from './shared/core.DMgTrB_2.cjs';
package/dist/types.d.mts CHANGED
@@ -1,80 +1,2 @@
1
- /// <reference path="../types/web3-compat.d.ts" />
2
- /// <reference path="../types/buffer.d.ts" />
3
- import { Commitment, SendOptions, Connection, Transaction, VersionedTransaction, PublicKey, TransactionSignature, RpcResponseAndContext, SignatureResult } from '@solana/web3-compat';
4
-
5
- type SolanaCluster = "mainnet-beta" | "testnet" | "devnet" | "localnet";
6
- type SolanaChain = "solana:mainnet" | "solana:testnet" | "solana:devnet" | "solana:localnet";
7
- interface SolanaConfig {
8
- cluster?: SolanaCluster;
9
- endpoint?: string;
10
- wsEndpoint?: string;
11
- commitment?: Commitment;
12
- autoConnect?: boolean;
13
- }
14
- interface SolanaContext {
15
- cluster: SolanaCluster;
16
- endpoint: string;
17
- wsEndpoint: string;
18
- connection: Connection;
19
- }
20
- type SolanaTransaction = Transaction | VersionedTransaction;
21
- interface SolanaSignMessageResult {
22
- signedMessage: Uint8Array;
23
- signature: Uint8Array;
24
- }
25
- interface SolanaWallet {
26
- publicKey: PublicKey | null;
27
- connected: boolean;
28
- connecting?: boolean;
29
- disconnecting?: boolean;
30
- platform?: SolanaWalletInfo["platform"];
31
- source?: SolanaWalletInfo["source"];
32
- connect: () => Promise<void>;
33
- disconnect: () => Promise<void>;
34
- signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
35
- signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
36
- signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
37
- signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
38
- signature: TransactionSignature;
39
- }>;
40
- }
41
- interface SolanaWalletInfo {
42
- name: string;
43
- icon: string;
44
- chains: readonly string[];
45
- platform?: "browser" | "mobile" | "desktop";
46
- source?: "wallet-standard" | "mobile-wallet-adapter" | "deep-link" | "protocol-link";
47
- appUrl?: string;
48
- installUrl?: string;
49
- callbackUrl?: string;
50
- capabilities?: {
51
- connect?: boolean;
52
- disconnect?: boolean;
53
- signMessage?: boolean;
54
- signTransaction?: boolean;
55
- signAllTransactions?: boolean;
56
- signAndSendTransaction?: boolean;
57
- };
58
- accounts: readonly {
59
- address: string;
60
- publicKey: Uint8Array;
61
- chains: readonly string[];
62
- label?: string;
63
- icon?: string;
64
- }[];
65
- wallet: unknown;
66
- }
67
- interface SendTransactionOptions extends SendOptions {
68
- skipPreflight?: boolean;
69
- }
70
- interface ConfirmTransactionOptions {
71
- commitment?: Commitment;
72
- timeoutMs?: number;
73
- }
74
- interface TransactionConfirmation {
75
- signature: TransactionSignature;
76
- commitment: Commitment;
77
- result: RpcResponseAndContext<SignatureResult>;
78
- }
79
-
80
- export type { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaSignMessageResult, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation };
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 SolanaSignMessageResult, g as SolanaTransaction, h as SolanaWallet, i as SolanaWalletInfo, T as TransactionConfirmation, j as TransactionStatus } from './shared/core.DMgTrB_2.mjs';