@vue-solana/core 2.6.1 → 3.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 (49) hide show
  1. package/README.md +6 -4
  2. package/dist/index.d.mts +2 -1
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.mjs +4 -3
  5. package/dist/ios-wallet.mjs +1 -1
  6. package/dist/kit.d.mts +1 -1
  7. package/dist/kit.d.ts +1 -1
  8. package/dist/kit.mjs +4 -4
  9. package/dist/shared/{core.TqudP0hB.mjs → core.DaUlAmcN.mjs} +15 -22
  10. package/dist/shared/{core.CDVW-ApZ.mjs → core.DuQGQqnc.mjs} +29 -26
  11. package/dist/timeout.mjs +3 -0
  12. package/dist/wallet-standard.mjs +1 -1
  13. package/dist/wallet.mjs +26 -39
  14. package/package.json +18 -35
  15. package/dist/action.cjs +0 -14
  16. package/dist/action.d.cts +0 -28
  17. package/dist/address.cjs +0 -33
  18. package/dist/address.d.cts +0 -16
  19. package/dist/buffer-polyfill.cjs +0 -12
  20. package/dist/buffer-polyfill.d.cts +0 -7
  21. package/dist/clusters.cjs +0 -37
  22. package/dist/clusters.d.cts +0 -10
  23. package/dist/errors.cjs +0 -50
  24. package/dist/errors.d.cts +0 -17
  25. package/dist/index.cjs +0 -94
  26. package/dist/index.d.cts +0 -19
  27. package/dist/ios-wallet.cjs +0 -17
  28. package/dist/ios-wallet.d.cts +0 -62
  29. package/dist/kit.cjs +0 -88
  30. package/dist/kit.d.cts +0 -3
  31. package/dist/mobile-wallet.cjs +0 -69
  32. package/dist/mobile-wallet.d.cts +0 -20
  33. package/dist/rpc.cjs +0 -20
  34. package/dist/rpc.d.cts +0 -7
  35. package/dist/shared/core.C9vxHRXl.d.cts +0 -193
  36. package/dist/shared/core.CasnoavM.cjs +0 -323
  37. package/dist/shared/core.eIBHqmLq.cjs +0 -598
  38. package/dist/timeout.cjs +0 -32
  39. package/dist/timeout.d.cts +0 -4
  40. package/dist/token-accounts.cjs +0 -72
  41. package/dist/token-accounts.d.cts +0 -36
  42. package/dist/transaction.cjs +0 -81
  43. package/dist/transaction.d.cts +0 -18
  44. package/dist/types.cjs +0 -2
  45. package/dist/types.d.cts +0 -3
  46. package/dist/wallet-standard.cjs +0 -17
  47. package/dist/wallet-standard.d.cts +0 -22
  48. package/dist/wallet.cjs +0 -81
  49. package/dist/wallet.d.cts +0 -25
@@ -1,193 +0,0 @@
1
- import * as _solana_kit_plugin_rpc from '@solana/kit-plugin-rpc';
2
- import * as _solana_kit from '@solana/kit';
3
- import { Commitment, Slot, TransactionSigner, Address, ReadonlyUint8Array, Signature } from '@solana/kit';
4
-
5
- /**
6
- * Solana cluster names. `mainnet` is Solana's official mainnet cluster name.
7
- * The legacy `mainnet-beta` spelling is still accepted and redirects to the
8
- * same mainnet endpoint.
9
- */
10
- type SolanaCluster = "mainnet" | "mainnet-beta" | "testnet" | "devnet" | "localnet";
11
- type SolanaChain = "solana:mainnet" | "solana:testnet" | "solana:devnet" | "solana:localnet";
12
- interface SolanaConfig {
13
- cluster?: SolanaCluster;
14
- endpoint?: string;
15
- wsEndpoint?: string;
16
- commitment?: Commitment;
17
- autoConnect?: boolean;
18
- /**
19
- * Kit client signer used to pay fees and sign client-sent transactions
20
- * (e.g. `useSendTransaction()`). Install one for demo/relayer flows; never
21
- * ship a funded keypair to end-user browsers.
22
- */
23
- payer?: TransactionSigner;
24
- /**
25
- * Serializable variant of `payer`: a 64-byte Ed25519 keypair encoded as
26
- * base64 (secret key first). Resolved to a Kit `TransactionSigner` when the
27
- * client is created. Direct Vue/core demos only; Nuxt does not forward this
28
- * value through public runtime config. Dev/demos only; never ship a funded
29
- * secret to production browsers.
30
- */
31
- payerSecretKey?: string;
32
- }
33
- interface SolanaContext {
34
- cluster: SolanaCluster;
35
- endpoint: string;
36
- wsEndpoint: string;
37
- client: SolanaClient;
38
- }
39
- /**
40
- * Raw serialized wire bytes. Widened to Kit's `ReadonlyUint8Array` because
41
- * that is what `getTransactionEncoder().encode()` returns — typing it as
42
- * `Uint8Array` rejected the output of the encoder the docs tell you to use.
43
- */
44
- type SolanaTransaction = ReadonlyUint8Array;
45
- interface SolanaSignMessageResult {
46
- signedMessage: Uint8Array;
47
- signature: Uint8Array;
48
- }
49
- interface SolanaSignInAccount {
50
- address: Address;
51
- publicKey: Uint8Array;
52
- chains: string[];
53
- label?: string;
54
- icon?: string;
55
- }
56
- interface SolanaSignInResult {
57
- account: SolanaSignInAccount;
58
- signedMessage: Uint8Array;
59
- signature: Uint8Array;
60
- signatureType?: "ed25519";
61
- }
62
- interface SolanaSignInInput {
63
- domain?: string;
64
- address?: string;
65
- statement?: string;
66
- uri?: string;
67
- version?: string;
68
- chainId?: string;
69
- nonce?: string;
70
- issuedAt?: string;
71
- expirationTime?: string;
72
- notBefore?: string;
73
- requestId?: string;
74
- resources?: readonly string[];
75
- }
76
- interface SolanaWallet {
77
- publicKey: Address | null;
78
- connected: boolean;
79
- connecting?: boolean;
80
- disconnecting?: boolean;
81
- platform?: SolanaWalletInfo["platform"];
82
- source?: SolanaWalletInfo["source"];
83
- connect: () => Promise<void>;
84
- disconnect: () => Promise<void>;
85
- signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
86
- signIn?: (input?: SolanaSignInInput) => Promise<SolanaSignInResult>;
87
- signTransaction?: (transaction: SolanaTransaction) => Promise<SolanaTransaction>;
88
- signAllTransactions?: (transactions: SolanaTransaction[]) => Promise<SolanaTransaction[]>;
89
- signTransactions?: (transactions: SolanaTransaction[]) => Promise<SolanaTransaction[]>;
90
- signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendTransactionOptions) => Promise<{
91
- signature: string;
92
- }>;
93
- signAndSendTransactions?: (transactions: SolanaTransaction[], options?: SendTransactionOptions) => Promise<string[]>;
94
- }
95
- interface SolanaWalletInfo {
96
- name: string;
97
- icon: string;
98
- chains: readonly string[];
99
- platform?: "browser" | "mobile" | "desktop";
100
- source?: "wallet-standard" | "mobile-wallet-adapter" | "deep-link" | "protocol-link";
101
- appUrl?: string;
102
- installUrl?: string;
103
- callbackUrl?: string;
104
- capabilities?: {
105
- connect?: boolean;
106
- disconnect?: boolean;
107
- signIn?: boolean;
108
- signMessage?: boolean;
109
- signTransaction?: boolean;
110
- signAllTransactions?: boolean;
111
- signAndSendTransaction?: boolean;
112
- };
113
- accounts: readonly {
114
- address: string;
115
- publicKey: Uint8Array;
116
- chains: readonly string[];
117
- label?: string;
118
- icon?: string;
119
- }[];
120
- wallet: unknown;
121
- }
122
- interface SendTransactionOptions {
123
- skipPreflight?: boolean;
124
- maxRetries?: bigint;
125
- minContextSlot?: Slot;
126
- preflightCommitment?: Commitment;
127
- }
128
- interface ConfirmTransactionOptions {
129
- commitment?: Commitment;
130
- timeoutMs?: number;
131
- }
132
- interface TransactionStatus {
133
- slot: Slot;
134
- confirmations: bigint | null;
135
- err: unknown | null;
136
- confirmationStatus: Commitment | null;
137
- }
138
- interface TransactionConfirmation {
139
- signature: Signature;
140
- commitment: Commitment;
141
- status: TransactionStatus;
142
- }
143
-
144
- declare function buildSolanaClient(endpoint: string, wsEndpoint: string, payer: TransactionSigner | undefined): _solana_kit.Client<{
145
- signTransactions: (input: _solana_kit.InstructionPlanInput | _solana_kit.TransactionPlanInput, config?: {
146
- abortSignal?: AbortSignal;
147
- }) => Promise<_solana_kit.TransactionPlanResult<_solana_kit_plugin_rpc.RpcSignContext>>;
148
- payer: TransactionSigner;
149
- rpc: _solana_kit.Rpc<_solana_kit.RequestAirdropApi & _solana_kit.GetAccountInfoApi & _solana_kit.GetAgGenesisCertApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetTransactionsForAddressApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi>;
150
- rpcSubscriptions: _solana_kit.RpcSubscriptions<_solana_kit.SolanaRpcSubscriptionsApi>;
151
- getMinimumBalance: (space: number, config?: _solana_kit.GetMinimumBalanceConfig) => Promise<_solana_kit.Lamports>;
152
- transactionPlanner: _solana_kit.TransactionPlanner;
153
- planTransaction: (input: _solana_kit.InstructionPlanInput, config?: {
154
- abortSignal?: AbortSignal;
155
- }) => Promise<_solana_kit.SingleTransactionPlan["message"]>;
156
- planTransactions: (input: _solana_kit.InstructionPlanInput, config?: {
157
- abortSignal?: AbortSignal;
158
- }) => Promise<_solana_kit.TransactionPlan>;
159
- signTransaction: (input: _solana_kit.InstructionPlanInput | (_solana_kit.TransactionMessage & _solana_kit.TransactionMessageWithFeePayer<string>) | Readonly<{
160
- kind: "single";
161
- message: _solana_kit.TransactionMessage & _solana_kit.TransactionMessageWithFeePayer<string>;
162
- planType: "transactionPlan";
163
- }>, config?: {
164
- abortSignal?: AbortSignal;
165
- }) => Promise<_solana_kit.SuccessfulSingleTransactionPlanResult<_solana_kit_plugin_rpc.RpcSignContext>>;
166
- transactionPlanExecutor: _solana_kit.TransactionPlanExecutor<_solana_kit_plugin_rpc.RpcSendContext>;
167
- sendTransaction: (input: _solana_kit.InstructionPlanInput | (_solana_kit.TransactionMessage & _solana_kit.TransactionMessageWithFeePayer<string>) | Readonly<{
168
- kind: "single";
169
- message: _solana_kit.TransactionMessage & _solana_kit.TransactionMessageWithFeePayer<string>;
170
- planType: "transactionPlan";
171
- }>, config?: {
172
- abortSignal?: AbortSignal;
173
- }) => Promise<_solana_kit.SuccessfulSingleTransactionPlanResult<_solana_kit_plugin_rpc.RpcSendContext>>;
174
- sendTransactions: (input: _solana_kit.InstructionPlanInput | _solana_kit.TransactionPlanInput, config?: {
175
- abortSignal?: AbortSignal;
176
- }) => Promise<_solana_kit.TransactionPlanResult<_solana_kit_plugin_rpc.RpcSendContext>>;
177
- airdrop: (address: Address, amount: _solana_kit.Lamports, abortSignal?: AbortSignal) => Promise<_solana_kit.Signature | undefined>;
178
- }>;
179
- type SolanaClientWithPayer = ReturnType<typeof buildSolanaClient>;
180
- type SolanaClientWithOptionalPayer = Omit<SolanaClientWithPayer, "payer"> & {
181
- payer?: TransactionSigner;
182
- };
183
- type SolanaConfigWithPayer = SolanaConfig & ({
184
- payer: TransactionSigner;
185
- } | {
186
- payerSecretKey: string;
187
- });
188
- declare function createSolanaClient(config: SolanaConfigWithPayer): SolanaClientWithPayer;
189
- declare function createSolanaClient(config?: SolanaConfig): SolanaClientWithOptionalPayer;
190
- type SolanaClient = SolanaClientWithOptionalPayer;
191
-
192
- export { createSolanaClient as n };
193
- export type { ConfirmTransactionOptions as C, SendTransactionOptions as S, TransactionConfirmation as T, SolanaChain as a, SolanaClient as b, SolanaCluster as c, SolanaConfig as d, SolanaContext as e, SolanaSignInAccount as f, SolanaSignInInput as g, SolanaSignInResult as h, SolanaSignMessageResult as i, SolanaTransaction as j, SolanaWallet as k, SolanaWalletInfo as l, TransactionStatus as m };
@@ -1,323 +0,0 @@
1
- 'use strict';
2
-
3
- const features = require('@wallet-standard/features');
4
- const walletStandardFeatures = require('@solana/wallet-standard-features');
5
- const bs58 = require('bs58');
6
- const app = require('@wallet-standard/app');
7
-
8
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
-
10
- const bs58__default = /*#__PURE__*/_interopDefaultCompat(bs58);
11
-
12
- const SOLANA_CHAINS = [
13
- "solana:mainnet",
14
- "solana:testnet",
15
- "solana:devnet",
16
- "solana:localnet"
17
- ];
18
- function getSolanaChain(cluster) {
19
- if (cluster === "mainnet-beta") {
20
- return "solana:mainnet";
21
- }
22
- return `solana:${cluster}`;
23
- }
24
-
25
- function hasVersionedFeature(wallet, feature) {
26
- const value = wallet.features[feature];
27
- return typeof value === "object" && value !== null && typeof value.version === "string";
28
- }
29
- function hasSignTransaction(wallet) {
30
- return hasVersionedFeature(wallet, walletStandardFeatures.SolanaSignTransaction);
31
- }
32
- function hasSignIn(wallet) {
33
- return hasVersionedFeature(wallet, walletStandardFeatures.SolanaSignIn);
34
- }
35
- function hasSignAndSendTransaction(wallet) {
36
- return hasVersionedFeature(wallet, walletStandardFeatures.SolanaSignAndSendTransaction);
37
- }
38
- function hasSignMessage(wallet) {
39
- return hasVersionedFeature(wallet, walletStandardFeatures.SolanaSignMessage);
40
- }
41
-
42
- function adaptSolanaStandardWallet(walletInfo, options = {}) {
43
- const wallet = walletInfo.wallet;
44
- let accounts = wallet.accounts;
45
- let account = options.account;
46
- let allowAccountUpdates = Boolean(options.account);
47
- let connecting = false;
48
- let disconnecting = false;
49
- let manuallyDisconnected = false;
50
- const eventsFeature = wallet.features[features.StandardEvents];
51
- eventsFeature?.on("change", (properties) => {
52
- if (properties.accounts) {
53
- accounts = properties.accounts;
54
- account = allowAccountUpdates && !manuallyDisconnected ? getSolanaAccount(accounts, options.chain) : void 0;
55
- options.onChange?.();
56
- }
57
- });
58
- return {
59
- platform: walletInfo.platform,
60
- source: walletInfo.source,
61
- get publicKey() {
62
- return account ? account.address : null;
63
- },
64
- get connected() {
65
- return Boolean(account);
66
- },
67
- get connecting() {
68
- return connecting;
69
- },
70
- get disconnecting() {
71
- return disconnecting;
72
- },
73
- async connect() {
74
- connecting = true;
75
- manuallyDisconnected = false;
76
- options.onChange?.();
77
- try {
78
- const feature = wallet.features[features.StandardConnect];
79
- const result = await feature.connect();
80
- accounts = result.accounts;
81
- allowAccountUpdates = true;
82
- account = getSolanaAccount(accounts, options.chain);
83
- if (!account) {
84
- throw new Error("Solana wallet did not authorize a Solana account");
85
- }
86
- } finally {
87
- connecting = false;
88
- options.onChange?.();
89
- }
90
- },
91
- async disconnect() {
92
- const feature = wallet.features[features.StandardDisconnect];
93
- disconnecting = true;
94
- manuallyDisconnected = true;
95
- allowAccountUpdates = false;
96
- account = void 0;
97
- options.onChange?.();
98
- try {
99
- await feature.disconnect();
100
- accounts = [];
101
- account = void 0;
102
- } catch (error) {
103
- manuallyDisconnected = false;
104
- allowAccountUpdates = true;
105
- account = getSolanaAccount(accounts, options.chain);
106
- throw error;
107
- } finally {
108
- disconnecting = false;
109
- options.onChange?.();
110
- }
111
- },
112
- signIn: hasSignIn(wallet) ? async (input) => {
113
- const [result] = await wallet.features[walletStandardFeatures.SolanaSignIn].signIn(...input ? [input] : []);
114
- if (!result) {
115
- throw new Error("Solana wallet did not return a sign-in result");
116
- }
117
- return toSolanaSignInResult(result);
118
- } : void 0,
119
- signMessage: hasSignMessage(wallet) ? async (message) => {
120
- const activeAccount = getActiveAccount(account);
121
- const [result] = await wallet.features[walletStandardFeatures.SolanaSignMessage].signMessage({
122
- account: activeAccount,
123
- message
124
- });
125
- if (!result) {
126
- throw new Error("Solana wallet did not return a message signature");
127
- }
128
- return result;
129
- } : void 0,
130
- signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
131
- const activeAccount = getActiveAccount(account);
132
- const [result] = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction({
133
- account: activeAccount,
134
- transaction: new Uint8Array(transaction),
135
- chain: options.chain
136
- });
137
- if (!result) {
138
- throw new Error("Solana wallet did not return a signed transaction");
139
- }
140
- return result.signedTransaction;
141
- } : void 0,
142
- signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => {
143
- const activeAccount = getActiveAccount(account);
144
- const results = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(
145
- ...transactions.map((transaction) => ({
146
- account: activeAccount,
147
- transaction: new Uint8Array(transaction),
148
- chain: options.chain
149
- }))
150
- );
151
- if (results.length !== transactions.length) {
152
- throw new Error(
153
- `Solana wallet returned ${results.length} signed transactions for ${transactions.length} requested transactions`
154
- );
155
- }
156
- return results.map((result) => {
157
- if (!result) {
158
- throw new Error("Solana wallet did not return a signed transaction");
159
- }
160
- return result.signedTransaction;
161
- });
162
- } : void 0,
163
- signTransactions: hasSignTransaction(wallet) ? async (transactions) => signAllThroughFeature(
164
- wallet,
165
- () => getActiveAccount(account),
166
- transactions,
167
- options.chain
168
- ) : void 0,
169
- signAndSendTransaction: hasSignAndSendTransaction(wallet) ? async (transaction, sendOptions) => {
170
- const activeAccount = getActiveAccount(account);
171
- const [result] = await wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
172
- account: activeAccount,
173
- transaction: new Uint8Array(transaction),
174
- chain: options.chain ?? getSolanaAccountChain(activeAccount),
175
- options: sendOptions
176
- });
177
- if (!result) {
178
- throw new Error("Solana wallet did not return a transaction signature");
179
- }
180
- return { signature: bs58__default.encode(result.signature) };
181
- } : void 0,
182
- signAndSendTransactions: hasSignAndSendTransaction(wallet) ? async (transactions, sendOptions) => {
183
- const activeAccount = getActiveAccount(account);
184
- const results = await wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction(
185
- ...transactions.map((transaction) => ({
186
- account: activeAccount,
187
- transaction: new Uint8Array(transaction),
188
- chain: options.chain ?? getSolanaAccountChain(activeAccount),
189
- options: sendOptions
190
- }))
191
- );
192
- if (results.length !== transactions.length) {
193
- throw new Error(
194
- `Solana wallet returned ${results.length} signatures for ${transactions.length} requested transactions`
195
- );
196
- }
197
- return results.map((result) => {
198
- if (!result) {
199
- throw new Error("Solana wallet did not return a transaction signature");
200
- }
201
- return bs58__default.encode(result.signature);
202
- });
203
- } : void 0
204
- };
205
- }
206
- async function signAllThroughFeature(wallet, getAccount, transactions, chain) {
207
- const activeAccount = getAccount();
208
- const results = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(
209
- ...transactions.map((transaction) => ({
210
- account: activeAccount,
211
- transaction: new Uint8Array(transaction),
212
- chain
213
- }))
214
- );
215
- if (results.length !== transactions.length) {
216
- throw new Error(
217
- `Solana wallet returned ${results.length} signed transactions for ${transactions.length} requested transactions`
218
- );
219
- }
220
- return results.map((result) => {
221
- if (!result) {
222
- throw new Error("Solana wallet did not return a signed transaction");
223
- }
224
- return result.signedTransaction;
225
- });
226
- }
227
- function toSolanaSignInResult(result) {
228
- return {
229
- account: {
230
- address: result.account.address,
231
- publicKey: Uint8Array.from(result.account.publicKey),
232
- chains: [...result.account.chains],
233
- label: result.account.label,
234
- icon: result.account.icon
235
- },
236
- signedMessage: result.signedMessage,
237
- signature: result.signature,
238
- signatureType: result.signatureType
239
- };
240
- }
241
- function getSolanaAccount(accounts, chain) {
242
- return accounts.find((account) => account.chains.some((accountChain) => accountChain === chain)) ?? accounts.find(
243
- (account) => account.chains.some((accountChain) => SOLANA_CHAINS.includes(accountChain))
244
- );
245
- }
246
- function getActiveAccount(account) {
247
- if (!account) {
248
- throw new Error("Solana wallet is not connected");
249
- }
250
- return account;
251
- }
252
- function getSolanaAccountChain(account) {
253
- const chain = account.chains.find(
254
- (accountChain) => SOLANA_CHAINS.includes(accountChain)
255
- );
256
- if (!chain) {
257
- throw new Error("Solana wallet account does not support a Solana chain");
258
- }
259
- return chain;
260
- }
261
-
262
- const SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME = "Mobile Wallet Adapter";
263
- function isSolanaStandardWallet(wallet) {
264
- return features.StandardConnect in wallet.features && features.StandardDisconnect in wallet.features && wallet.chains.some((chain) => SOLANA_CHAINS.includes(chain));
265
- }
266
- function getRegisteredSolanaWallets() {
267
- if (typeof window === "undefined") {
268
- return [];
269
- }
270
- return app.getWallets().get().filter(isSolanaStandardWallet).map(createSolanaWalletInfo);
271
- }
272
- function subscribeSolanaWallets(listener) {
273
- if (typeof window === "undefined") {
274
- return () => {
275
- };
276
- }
277
- const wallets = app.getWallets();
278
- const offRegister = wallets.on("register", listener);
279
- const offUnregister = wallets.on("unregister", listener);
280
- return () => {
281
- offRegister();
282
- offUnregister();
283
- };
284
- }
285
- function createSolanaWalletInfo(wallet) {
286
- const isMobileWallet = wallet.name === SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME;
287
- return {
288
- name: wallet.name,
289
- icon: wallet.icon,
290
- chains: wallet.chains,
291
- platform: isMobileWallet ? "mobile" : "browser",
292
- source: isMobileWallet ? "mobile-wallet-adapter" : "wallet-standard",
293
- appUrl: getWalletUrl(wallet),
294
- capabilities: {
295
- connect: true,
296
- disconnect: true,
297
- signIn: hasSignIn(wallet),
298
- signMessage: hasSignMessage(wallet),
299
- signTransaction: hasSignTransaction(wallet),
300
- signAllTransactions: hasSignTransaction(wallet),
301
- signAndSendTransaction: hasSignAndSendTransaction(wallet)
302
- },
303
- accounts: wallet.accounts.map((account) => ({
304
- address: account.address,
305
- publicKey: Uint8Array.from(account.publicKey),
306
- chains: account.chains,
307
- label: account.label,
308
- icon: account.icon
309
- })),
310
- wallet
311
- };
312
- }
313
- function getWalletUrl(wallet) {
314
- return "url" in wallet && typeof wallet.url === "string" ? wallet.url : void 0;
315
- }
316
-
317
- exports.SOLANA_CHAINS = SOLANA_CHAINS;
318
- exports.SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME = SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME;
319
- exports.adaptSolanaStandardWallet = adaptSolanaStandardWallet;
320
- exports.getRegisteredSolanaWallets = getRegisteredSolanaWallets;
321
- exports.getSolanaChain = getSolanaChain;
322
- exports.isSolanaStandardWallet = isSolanaStandardWallet;
323
- exports.subscribeSolanaWallets = subscribeSolanaWallets;