@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,8 +1,6 @@
1
1
  import { StandardEvents, StandardDisconnect, StandardConnect } from '@wallet-standard/features';
2
- import { SolanaSignAndSendTransaction, SolanaSignTransaction, SolanaSignMessage } from '@solana/wallet-standard-features';
3
- import { Transaction, VersionedTransaction, PublicKey } from '@solana/web3-compat';
2
+ import { SolanaSignTransaction, SolanaSignIn, SolanaSignAndSendTransaction, SolanaSignMessage } from '@solana/wallet-standard-features';
4
3
  import bs58 from 'bs58';
5
- import { SolanaWalletError } from '../wallet.mjs';
6
4
  import { getWallets } from '@wallet-standard/app';
7
5
 
8
6
  const SOLANA_CHAINS = [
@@ -18,27 +16,21 @@ function getSolanaChain(cluster) {
18
16
  return `solana:${cluster}`;
19
17
  }
20
18
 
19
+ function hasVersionedFeature(wallet, feature) {
20
+ const value = wallet.features[feature];
21
+ return typeof value === "object" && value !== null && typeof value.version === "string";
22
+ }
21
23
  function hasSignTransaction(wallet) {
22
- return SolanaSignTransaction in wallet.features;
24
+ return hasVersionedFeature(wallet, SolanaSignTransaction);
25
+ }
26
+ function hasSignIn(wallet) {
27
+ return hasVersionedFeature(wallet, SolanaSignIn);
23
28
  }
24
29
  function hasSignAndSendTransaction(wallet) {
25
- return SolanaSignAndSendTransaction in wallet.features;
30
+ return hasVersionedFeature(wallet, SolanaSignAndSendTransaction);
26
31
  }
27
32
  function hasSignMessage(wallet) {
28
- return SolanaSignMessage in wallet.features;
29
- }
30
-
31
- function serializeTransaction(transaction) {
32
- if (transaction instanceof Transaction) {
33
- return transaction.serialize({ requireAllSignatures: false, verifySignatures: false });
34
- }
35
- return transaction.serialize();
36
- }
37
- function deserializeTransaction(source, bytes) {
38
- if (source instanceof Transaction) {
39
- return Transaction.from(bytes);
40
- }
41
- return VersionedTransaction.deserialize(bytes);
33
+ return hasVersionedFeature(wallet, SolanaSignMessage);
42
34
  }
43
35
 
44
36
  function adaptSolanaStandardWallet(walletInfo, options = {}) {
@@ -61,10 +53,7 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
61
53
  platform: walletInfo.platform,
62
54
  source: walletInfo.source,
63
55
  get publicKey() {
64
- return account ? new PublicKey(account.publicKey) : null;
65
- },
66
- get address() {
67
- return account ? account.address : void 0;
56
+ return account ? account.address : null;
68
57
  },
69
58
  get connected() {
70
59
  return Boolean(account);
@@ -114,6 +103,13 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
114
103
  options.onChange?.();
115
104
  }
116
105
  },
106
+ signIn: hasSignIn(wallet) ? async (input) => {
107
+ const [result] = await wallet.features[SolanaSignIn].signIn(...input ? [input] : []);
108
+ if (!result) {
109
+ throw new Error("Solana wallet did not return a sign-in result");
110
+ }
111
+ return toSolanaSignInResult(result);
112
+ } : void 0,
117
113
  signMessage: hasSignMessage(wallet) ? async (message) => {
118
114
  const activeAccount = getActiveAccount(account);
119
115
  const [result] = await wallet.features[SolanaSignMessage].signMessage({
@@ -129,20 +125,20 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
129
125
  const activeAccount = getActiveAccount(account);
130
126
  const [result] = await wallet.features[SolanaSignTransaction].signTransaction({
131
127
  account: activeAccount,
132
- transaction: serializeTransaction(transaction),
128
+ transaction,
133
129
  chain: options.chain
134
130
  });
135
131
  if (!result) {
136
132
  throw new Error("Solana wallet did not return a signed transaction");
137
133
  }
138
- return deserializeTransaction(transaction, result.signedTransaction);
134
+ return result.signedTransaction;
139
135
  } : void 0,
140
136
  signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => {
141
137
  const activeAccount = getActiveAccount(account);
142
138
  const results = await wallet.features[SolanaSignTransaction].signTransaction(
143
139
  ...transactions.map((transaction) => ({
144
140
  account: activeAccount,
145
- transaction: serializeTransaction(transaction),
141
+ transaction,
146
142
  chain: options.chain
147
143
  }))
148
144
  );
@@ -151,26 +147,24 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
151
147
  `Solana wallet returned ${results.length} signed transactions for ${transactions.length} requested transactions`
152
148
  );
153
149
  }
154
- return results.map((result, index) => {
150
+ return results.map((result) => {
155
151
  if (!result) {
156
152
  throw new Error("Solana wallet did not return a signed transaction");
157
153
  }
158
- const transaction = transactions[index];
159
- if (!transaction) {
160
- throw new SolanaWalletError(
161
- "WALLET_FEATURE_UNSUPPORTED",
162
- "Solana wallet returned a signed transaction without a matching request",
163
- { feature: "signTransaction" }
164
- );
165
- }
166
- return deserializeTransaction(transaction, result.signedTransaction);
154
+ return result.signedTransaction;
167
155
  });
168
156
  } : void 0,
157
+ signTransactions: hasSignTransaction(wallet) ? async (transactions) => signAllThroughFeature(
158
+ wallet,
159
+ () => getActiveAccount(account),
160
+ transactions,
161
+ options.chain
162
+ ) : void 0,
169
163
  signAndSendTransaction: hasSignAndSendTransaction(wallet) ? async (transaction, sendOptions) => {
170
164
  const activeAccount = getActiveAccount(account);
171
165
  const [result] = await wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction({
172
166
  account: activeAccount,
173
- transaction: serializeTransaction(transaction),
167
+ transaction,
174
168
  chain: options.chain ?? getSolanaAccountChain(activeAccount),
175
169
  options: sendOptions
176
170
  });
@@ -178,9 +172,66 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
178
172
  throw new Error("Solana wallet did not return a transaction signature");
179
173
  }
180
174
  return { signature: bs58.encode(result.signature) };
175
+ } : void 0,
176
+ signAndSendTransactions: hasSignAndSendTransaction(wallet) ? async (transactions, sendOptions) => {
177
+ const activeAccount = getActiveAccount(account);
178
+ const results = await wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction(
179
+ ...transactions.map((transaction) => ({
180
+ account: activeAccount,
181
+ transaction,
182
+ chain: options.chain ?? getSolanaAccountChain(activeAccount),
183
+ options: sendOptions
184
+ }))
185
+ );
186
+ if (results.length !== transactions.length) {
187
+ throw new Error(
188
+ `Solana wallet returned ${results.length} signatures for ${transactions.length} requested transactions`
189
+ );
190
+ }
191
+ return results.map((result) => {
192
+ if (!result) {
193
+ throw new Error("Solana wallet did not return a transaction signature");
194
+ }
195
+ return bs58.encode(result.signature);
196
+ });
181
197
  } : void 0
182
198
  };
183
199
  }
200
+ async function signAllThroughFeature(wallet, getAccount, transactions, chain) {
201
+ const activeAccount = getAccount();
202
+ const results = await wallet.features[SolanaSignTransaction].signTransaction(
203
+ ...transactions.map((transaction) => ({
204
+ account: activeAccount,
205
+ transaction,
206
+ chain
207
+ }))
208
+ );
209
+ if (results.length !== transactions.length) {
210
+ throw new Error(
211
+ `Solana wallet returned ${results.length} signed transactions for ${transactions.length} requested transactions`
212
+ );
213
+ }
214
+ return results.map((result) => {
215
+ if (!result) {
216
+ throw new Error("Solana wallet did not return a signed transaction");
217
+ }
218
+ return result.signedTransaction;
219
+ });
220
+ }
221
+ function toSolanaSignInResult(result) {
222
+ return {
223
+ account: {
224
+ address: result.account.address,
225
+ publicKey: Uint8Array.from(result.account.publicKey),
226
+ chains: [...result.account.chains],
227
+ label: result.account.label,
228
+ icon: result.account.icon
229
+ },
230
+ signedMessage: result.signedMessage,
231
+ signature: result.signature,
232
+ signatureType: result.signatureType
233
+ };
234
+ }
184
235
  function getSolanaAccount(accounts, chain) {
185
236
  return accounts.find((account) => account.chains.some((accountChain) => accountChain === chain)) ?? accounts.find(
186
237
  (account) => account.chains.some((accountChain) => SOLANA_CHAINS.includes(accountChain))
@@ -237,6 +288,7 @@ function createSolanaWalletInfo(wallet) {
237
288
  capabilities: {
238
289
  connect: true,
239
290
  disconnect: true,
291
+ signIn: hasSignIn(wallet),
240
292
  signMessage: hasSignMessage(wallet),
241
293
  signTransaction: hasSignTransaction(wallet),
242
294
  signAllTransactions: hasSignTransaction(wallet),
@@ -2,9 +2,7 @@
2
2
 
3
3
  const features = require('@wallet-standard/features');
4
4
  const walletStandardFeatures = require('@solana/wallet-standard-features');
5
- const web3Compat = require('@solana/web3-compat');
6
5
  const bs58 = require('bs58');
7
- const wallet = require('../wallet.cjs');
8
6
  const app = require('@wallet-standard/app');
9
7
 
10
8
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -24,38 +22,32 @@ function getSolanaChain(cluster) {
24
22
  return `solana:${cluster}`;
25
23
  }
26
24
 
25
+ function hasVersionedFeature(wallet, feature) {
26
+ const value = wallet.features[feature];
27
+ return typeof value === "object" && value !== null && typeof value.version === "string";
28
+ }
27
29
  function hasSignTransaction(wallet) {
28
- return walletStandardFeatures.SolanaSignTransaction in wallet.features;
30
+ return hasVersionedFeature(wallet, walletStandardFeatures.SolanaSignTransaction);
31
+ }
32
+ function hasSignIn(wallet) {
33
+ return hasVersionedFeature(wallet, walletStandardFeatures.SolanaSignIn);
29
34
  }
30
35
  function hasSignAndSendTransaction(wallet) {
31
- return walletStandardFeatures.SolanaSignAndSendTransaction in wallet.features;
36
+ return hasVersionedFeature(wallet, walletStandardFeatures.SolanaSignAndSendTransaction);
32
37
  }
33
38
  function hasSignMessage(wallet) {
34
- return walletStandardFeatures.SolanaSignMessage in wallet.features;
35
- }
36
-
37
- function serializeTransaction(transaction) {
38
- if (transaction instanceof web3Compat.Transaction) {
39
- return transaction.serialize({ requireAllSignatures: false, verifySignatures: false });
40
- }
41
- return transaction.serialize();
42
- }
43
- function deserializeTransaction(source, bytes) {
44
- if (source instanceof web3Compat.Transaction) {
45
- return web3Compat.Transaction.from(bytes);
46
- }
47
- return web3Compat.VersionedTransaction.deserialize(bytes);
39
+ return hasVersionedFeature(wallet, walletStandardFeatures.SolanaSignMessage);
48
40
  }
49
41
 
50
42
  function adaptSolanaStandardWallet(walletInfo, options = {}) {
51
- const wallet$1 = walletInfo.wallet;
52
- let accounts = wallet$1.accounts;
43
+ const wallet = walletInfo.wallet;
44
+ let accounts = wallet.accounts;
53
45
  let account = options.account;
54
46
  let allowAccountUpdates = Boolean(options.account);
55
47
  let connecting = false;
56
48
  let disconnecting = false;
57
49
  let manuallyDisconnected = false;
58
- const eventsFeature = wallet$1.features[features.StandardEvents];
50
+ const eventsFeature = wallet.features[features.StandardEvents];
59
51
  eventsFeature?.on("change", (properties) => {
60
52
  if (properties.accounts) {
61
53
  accounts = properties.accounts;
@@ -67,10 +59,7 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
67
59
  platform: walletInfo.platform,
68
60
  source: walletInfo.source,
69
61
  get publicKey() {
70
- return account ? new web3Compat.PublicKey(account.publicKey) : null;
71
- },
72
- get address() {
73
- return account ? account.address : void 0;
62
+ return account ? account.address : null;
74
63
  },
75
64
  get connected() {
76
65
  return Boolean(account);
@@ -86,7 +75,7 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
86
75
  manuallyDisconnected = false;
87
76
  options.onChange?.();
88
77
  try {
89
- const feature = wallet$1.features[features.StandardConnect];
78
+ const feature = wallet.features[features.StandardConnect];
90
79
  const result = await feature.connect();
91
80
  accounts = result.accounts;
92
81
  allowAccountUpdates = true;
@@ -100,7 +89,7 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
100
89
  }
101
90
  },
102
91
  async disconnect() {
103
- const feature = wallet$1.features[features.StandardDisconnect];
92
+ const feature = wallet.features[features.StandardDisconnect];
104
93
  disconnecting = true;
105
94
  manuallyDisconnected = true;
106
95
  allowAccountUpdates = false;
@@ -120,9 +109,16 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
120
109
  options.onChange?.();
121
110
  }
122
111
  },
123
- signMessage: hasSignMessage(wallet$1) ? async (message) => {
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) => {
124
120
  const activeAccount = getActiveAccount(account);
125
- const [result] = await wallet$1.features[walletStandardFeatures.SolanaSignMessage].signMessage({
121
+ const [result] = await wallet.features[walletStandardFeatures.SolanaSignMessage].signMessage({
126
122
  account: activeAccount,
127
123
  message
128
124
  });
@@ -131,24 +127,24 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
131
127
  }
132
128
  return result;
133
129
  } : void 0,
134
- signTransaction: hasSignTransaction(wallet$1) ? async (transaction) => {
130
+ signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
135
131
  const activeAccount = getActiveAccount(account);
136
- const [result] = await wallet$1.features[walletStandardFeatures.SolanaSignTransaction].signTransaction({
132
+ const [result] = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction({
137
133
  account: activeAccount,
138
- transaction: serializeTransaction(transaction),
134
+ transaction,
139
135
  chain: options.chain
140
136
  });
141
137
  if (!result) {
142
138
  throw new Error("Solana wallet did not return a signed transaction");
143
139
  }
144
- return deserializeTransaction(transaction, result.signedTransaction);
140
+ return result.signedTransaction;
145
141
  } : void 0,
146
- signAllTransactions: hasSignTransaction(wallet$1) ? async (transactions) => {
142
+ signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => {
147
143
  const activeAccount = getActiveAccount(account);
148
- const results = await wallet$1.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(
144
+ const results = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(
149
145
  ...transactions.map((transaction) => ({
150
146
  account: activeAccount,
151
- transaction: serializeTransaction(transaction),
147
+ transaction,
152
148
  chain: options.chain
153
149
  }))
154
150
  );
@@ -157,26 +153,24 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
157
153
  `Solana wallet returned ${results.length} signed transactions for ${transactions.length} requested transactions`
158
154
  );
159
155
  }
160
- return results.map((result, index) => {
156
+ return results.map((result) => {
161
157
  if (!result) {
162
158
  throw new Error("Solana wallet did not return a signed transaction");
163
159
  }
164
- const transaction = transactions[index];
165
- if (!transaction) {
166
- throw new wallet.SolanaWalletError(
167
- "WALLET_FEATURE_UNSUPPORTED",
168
- "Solana wallet returned a signed transaction without a matching request",
169
- { feature: "signTransaction" }
170
- );
171
- }
172
- return deserializeTransaction(transaction, result.signedTransaction);
160
+ return result.signedTransaction;
173
161
  });
174
162
  } : void 0,
175
- signAndSendTransaction: hasSignAndSendTransaction(wallet$1) ? async (transaction, sendOptions) => {
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) => {
176
170
  const activeAccount = getActiveAccount(account);
177
- const [result] = await wallet$1.features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
171
+ const [result] = await wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
178
172
  account: activeAccount,
179
- transaction: serializeTransaction(transaction),
173
+ transaction,
180
174
  chain: options.chain ?? getSolanaAccountChain(activeAccount),
181
175
  options: sendOptions
182
176
  });
@@ -184,9 +178,66 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
184
178
  throw new Error("Solana wallet did not return a transaction signature");
185
179
  }
186
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,
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
+ });
187
203
  } : void 0
188
204
  };
189
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,
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
+ }
190
241
  function getSolanaAccount(accounts, chain) {
191
242
  return accounts.find((account) => account.chains.some((accountChain) => accountChain === chain)) ?? accounts.find(
192
243
  (account) => account.chains.some((accountChain) => SOLANA_CHAINS.includes(accountChain))
@@ -243,6 +294,7 @@ function createSolanaWalletInfo(wallet) {
243
294
  capabilities: {
244
295
  connect: true,
245
296
  disconnect: true,
297
+ signIn: hasSignIn(wallet),
246
298
  signMessage: hasSignMessage(wallet),
247
299
  signTransaction: hasSignTransaction(wallet),
248
300
  signAllTransactions: hasSignTransaction(wallet),
@@ -1,55 +1,71 @@
1
1
  'use strict';
2
2
 
3
- const splToken = require('@solana/spl-token');
3
+ const kit = require('@solana/kit');
4
4
  const errors = require('./errors.cjs');
5
5
 
6
- async function getTokenAccountsByOwner(connection, owner, options) {
7
- const commitment = options?.commitment ?? "confirmed";
8
- const programId = options?.programId;
9
- const programIds = programId ? [programId] : [splToken.TOKEN_PROGRAM_ID, splToken.TOKEN_2022_PROGRAM_ID];
6
+ const TOKEN_PROGRAM_ADDRESS = kit.address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
7
+ const TOKEN_2022_PROGRAM_ADDRESS = kit.address("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
8
+ async function getTokenAccountsByOwner(client, owner, options = {}) {
9
+ const programIds = options.programId ? [options.programId] : [TOKEN_PROGRAM_ADDRESS, TOKEN_2022_PROGRAM_ADDRESS];
10
10
  try {
11
- const responses = await Promise.all(
12
- programIds.map(async (pid) => {
13
- const resp = await connection.getTokenAccountsByOwner(owner, { programId: pid }, commitment);
14
- return resp.value.map(
15
- (info) => splToken.unpackAccount(info.pubkey, { data: info.account.data })
16
- );
17
- })
11
+ const results = await Promise.all(
12
+ programIds.map(
13
+ (programId) => fetchParsedTokenAccounts(client, owner, { programId }, options.commitment)
14
+ )
18
15
  );
19
- return responses.flat();
16
+ return results.flat();
20
17
  } catch (cause) {
21
18
  throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
22
19
  }
23
20
  }
24
- async function getTokenAccount(connection, address) {
21
+ async function getTokenAccount(client, address2, commitment) {
25
22
  try {
26
- const accountInfo = await connection.getAccountInfo(address);
27
- if (!accountInfo) {
23
+ const response = await client.rpc.getAccountInfo(address2, { encoding: "jsonParsed", commitment }).send();
24
+ const accountInfo = response.value;
25
+ if (!accountInfo || !isParsedTokenAccount(accountInfo.data) || accountInfo.data.parsed.type !== "account") {
28
26
  return null;
29
27
  }
30
- return splToken.unpackAccount(address, accountInfo);
28
+ return tokenAccountInfoFromParsed(address2, accountInfo.data);
31
29
  } catch (cause) {
32
30
  throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
33
31
  }
34
32
  }
35
- async function getTokenBalance(connection, mint, owner) {
33
+ async function getTokenBalance(client, mint, owner, commitment) {
36
34
  try {
37
- const ata = splToken.getAssociatedTokenAddressSync(mint, owner, true);
38
- const accountInfo = await connection.getAccountInfo(ata);
39
- if (!accountInfo) {
35
+ const [account] = await fetchParsedTokenAccounts(client, owner, { mint }, commitment);
36
+ if (!account) {
40
37
  return null;
41
38
  }
42
- const tokenAccount = splToken.unpackAccount(ata, accountInfo);
43
- const mintAccountInfo = await connection.getAccountInfo(mint);
44
- if (!mintAccountInfo) {
45
- return null;
46
- }
47
- const mintAccount = splToken.unpackMint(mint, mintAccountInfo);
48
- return { amount: tokenAccount.amount, decimals: mintAccount.decimals };
39
+ return { amount: account.amount, decimals: account.decimals };
49
40
  } catch (cause) {
50
41
  throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
51
42
  }
52
43
  }
44
+ async function fetchParsedTokenAccounts(client, owner, filter, commitment) {
45
+ const response = await client.rpc.getTokenAccountsByOwner(owner, filter, { encoding: "jsonParsed", commitment }).send();
46
+ return response.value.filter(({ account }) => isParsedTokenAccount(account.data)).map(({ pubkey, account }) => tokenAccountInfoFromParsed(pubkey, account.data));
47
+ }
48
+ function isParsedTokenAccount(data) {
49
+ return typeof data === "object" && data !== null && "parsed" in data;
50
+ }
51
+ function tokenAccountInfoFromParsed(address2, data) {
52
+ if (data.parsed.type !== "account") {
53
+ throw new Error(`Token account ${address2} is not a parsed token account`);
54
+ }
55
+ const parsed = data.parsed.info;
56
+ if (!parsed) {
57
+ throw new Error(`Token account ${address2} has no parsed data`);
58
+ }
59
+ return {
60
+ address: address2,
61
+ mint: parsed.mint,
62
+ owner: parsed.owner,
63
+ amount: BigInt(parsed.tokenAmount.amount),
64
+ decimals: parsed.tokenAmount.decimals,
65
+ state: parsed.state,
66
+ isNative: parsed.isNative
67
+ };
68
+ }
53
69
 
54
70
  exports.getTokenAccount = getTokenAccount;
55
71
  exports.getTokenAccountsByOwner = getTokenAccountsByOwner;
@@ -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.cjs';
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,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.mjs';
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 };