@vue-solana/core 0.4.1 → 0.5.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.
- package/README.md +12 -2
- package/dist/index.cjs +19 -17
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +4 -4
- package/dist/ios-wallet.cjs +12 -538
- package/dist/ios-wallet.d.cts +27 -8
- package/dist/ios-wallet.d.mts +27 -8
- package/dist/ios-wallet.d.ts +27 -8
- package/dist/ios-wallet.mjs +4 -517
- package/dist/rpc.cjs +1 -4
- package/dist/rpc.mjs +1 -4
- package/dist/shared/core.8V8PLE-S.cjs +237 -0
- package/dist/shared/core.D7olTUN_.mjs +225 -0
- package/dist/shared/core.DJZldB_x.cjs +612 -0
- package/dist/shared/core.DSI7vIfT.mjs +586 -0
- package/dist/transaction.cjs +35 -0
- package/dist/transaction.d.cts +3 -2
- package/dist/transaction.d.mts +3 -2
- package/dist/transaction.d.ts +3 -2
- package/dist/transaction.mjs +35 -1
- package/dist/types.d.cts +11 -2
- package/dist/types.d.mts +11 -2
- package/dist/types.d.ts +11 -2
- package/dist/wallet-standard.cjs +13 -219
- package/dist/wallet-standard.d.cts +6 -3
- package/dist/wallet-standard.d.mts +6 -3
- package/dist/wallet-standard.d.ts +6 -3
- package/dist/wallet-standard.mjs +6 -213
- package/package.json +1 -1
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const features = require('@wallet-standard/features');
|
|
4
|
+
const walletStandardFeatures = require('@solana/wallet-standard-features');
|
|
5
|
+
const web3Compat = require('@solana/web3-compat');
|
|
6
|
+
const bs58 = require('bs58');
|
|
7
|
+
const app = require('@wallet-standard/app');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
10
|
+
|
|
11
|
+
const bs58__default = /*#__PURE__*/_interopDefaultCompat(bs58);
|
|
12
|
+
|
|
13
|
+
const SOLANA_CHAINS = [
|
|
14
|
+
"solana:mainnet",
|
|
15
|
+
"solana:testnet",
|
|
16
|
+
"solana:devnet",
|
|
17
|
+
"solana:localnet"
|
|
18
|
+
];
|
|
19
|
+
function getSolanaChain(cluster) {
|
|
20
|
+
if (cluster === "mainnet-beta") {
|
|
21
|
+
return "solana:mainnet";
|
|
22
|
+
}
|
|
23
|
+
return `solana:${cluster}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function hasSignTransaction(wallet) {
|
|
27
|
+
return walletStandardFeatures.SolanaSignTransaction in wallet.features;
|
|
28
|
+
}
|
|
29
|
+
function hasSignAndSendTransaction(wallet) {
|
|
30
|
+
return walletStandardFeatures.SolanaSignAndSendTransaction in wallet.features;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function serializeTransaction(transaction) {
|
|
34
|
+
if (transaction instanceof web3Compat.Transaction) {
|
|
35
|
+
return transaction.serialize({ requireAllSignatures: false, verifySignatures: false });
|
|
36
|
+
}
|
|
37
|
+
return transaction.serialize();
|
|
38
|
+
}
|
|
39
|
+
function deserializeTransaction(source, bytes) {
|
|
40
|
+
if (source instanceof web3Compat.Transaction) {
|
|
41
|
+
return web3Compat.Transaction.from(bytes);
|
|
42
|
+
}
|
|
43
|
+
return web3Compat.VersionedTransaction.deserialize(bytes);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
47
|
+
const wallet = walletInfo.wallet;
|
|
48
|
+
let accounts = wallet.accounts;
|
|
49
|
+
let account = options.account;
|
|
50
|
+
let allowAccountUpdates = Boolean(options.account);
|
|
51
|
+
let connecting = false;
|
|
52
|
+
let disconnecting = false;
|
|
53
|
+
let manuallyDisconnected = false;
|
|
54
|
+
const eventsFeature = wallet.features[features.StandardEvents];
|
|
55
|
+
eventsFeature?.on("change", (properties) => {
|
|
56
|
+
if (properties.accounts) {
|
|
57
|
+
accounts = properties.accounts;
|
|
58
|
+
account = allowAccountUpdates && !manuallyDisconnected ? getSolanaAccount(accounts, options.chain) : void 0;
|
|
59
|
+
options.onChange?.();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
platform: walletInfo.platform,
|
|
64
|
+
source: walletInfo.source,
|
|
65
|
+
get publicKey() {
|
|
66
|
+
return account ? new web3Compat.PublicKey(account.publicKey) : null;
|
|
67
|
+
},
|
|
68
|
+
get connected() {
|
|
69
|
+
return Boolean(account);
|
|
70
|
+
},
|
|
71
|
+
get connecting() {
|
|
72
|
+
return connecting;
|
|
73
|
+
},
|
|
74
|
+
get disconnecting() {
|
|
75
|
+
return disconnecting;
|
|
76
|
+
},
|
|
77
|
+
async connect() {
|
|
78
|
+
connecting = true;
|
|
79
|
+
manuallyDisconnected = false;
|
|
80
|
+
options.onChange?.();
|
|
81
|
+
try {
|
|
82
|
+
const feature = wallet.features[features.StandardConnect];
|
|
83
|
+
const result = await feature.connect();
|
|
84
|
+
accounts = result.accounts;
|
|
85
|
+
allowAccountUpdates = true;
|
|
86
|
+
account = getSolanaAccount(accounts, options.chain);
|
|
87
|
+
if (!account) {
|
|
88
|
+
throw new Error("Solana wallet did not authorize a Solana account");
|
|
89
|
+
}
|
|
90
|
+
} finally {
|
|
91
|
+
connecting = false;
|
|
92
|
+
options.onChange?.();
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async disconnect() {
|
|
96
|
+
const feature = wallet.features[features.StandardDisconnect];
|
|
97
|
+
disconnecting = true;
|
|
98
|
+
manuallyDisconnected = true;
|
|
99
|
+
allowAccountUpdates = false;
|
|
100
|
+
account = void 0;
|
|
101
|
+
options.onChange?.();
|
|
102
|
+
try {
|
|
103
|
+
await feature.disconnect();
|
|
104
|
+
accounts = [];
|
|
105
|
+
account = void 0;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
manuallyDisconnected = false;
|
|
108
|
+
allowAccountUpdates = true;
|
|
109
|
+
account = getSolanaAccount(accounts, options.chain);
|
|
110
|
+
throw error;
|
|
111
|
+
} finally {
|
|
112
|
+
disconnecting = false;
|
|
113
|
+
options.onChange?.();
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
|
|
117
|
+
const activeAccount = getActiveAccount(account);
|
|
118
|
+
const [result] = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction({
|
|
119
|
+
account: activeAccount,
|
|
120
|
+
transaction: serializeTransaction(transaction),
|
|
121
|
+
chain: options.chain
|
|
122
|
+
});
|
|
123
|
+
if (!result) {
|
|
124
|
+
throw new Error("Solana wallet did not return a signed transaction");
|
|
125
|
+
}
|
|
126
|
+
return deserializeTransaction(transaction, result.signedTransaction);
|
|
127
|
+
} : void 0,
|
|
128
|
+
signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => {
|
|
129
|
+
const activeAccount = getActiveAccount(account);
|
|
130
|
+
const results = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(
|
|
131
|
+
...transactions.map((transaction) => ({
|
|
132
|
+
account: activeAccount,
|
|
133
|
+
transaction: serializeTransaction(transaction),
|
|
134
|
+
chain: options.chain
|
|
135
|
+
}))
|
|
136
|
+
);
|
|
137
|
+
if (results.length !== transactions.length) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
`Solana wallet returned ${results.length} signed transactions for ${transactions.length} requested transactions`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return results.map((result, index) => {
|
|
143
|
+
if (!result) {
|
|
144
|
+
throw new Error("Solana wallet did not return a signed transaction");
|
|
145
|
+
}
|
|
146
|
+
return deserializeTransaction(transactions[index], result.signedTransaction);
|
|
147
|
+
});
|
|
148
|
+
} : void 0,
|
|
149
|
+
signAndSendTransaction: hasSignAndSendTransaction(wallet) ? async (transaction, sendOptions) => {
|
|
150
|
+
const activeAccount = getActiveAccount(account);
|
|
151
|
+
const [result] = await wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
|
|
152
|
+
account: activeAccount,
|
|
153
|
+
transaction: serializeTransaction(transaction),
|
|
154
|
+
chain: options.chain ?? getSolanaAccountChain(activeAccount),
|
|
155
|
+
options: sendOptions
|
|
156
|
+
});
|
|
157
|
+
if (!result) {
|
|
158
|
+
throw new Error("Solana wallet did not return a transaction signature");
|
|
159
|
+
}
|
|
160
|
+
return { signature: bs58__default.encode(result.signature) };
|
|
161
|
+
} : void 0
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function getSolanaAccount(accounts, chain) {
|
|
165
|
+
return accounts.find((account) => account.chains.some((accountChain) => accountChain === chain)) ?? accounts.find(
|
|
166
|
+
(account) => account.chains.some((accountChain) => SOLANA_CHAINS.includes(accountChain))
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
function getActiveAccount(account) {
|
|
170
|
+
if (!account) {
|
|
171
|
+
throw new Error("Solana wallet is not connected");
|
|
172
|
+
}
|
|
173
|
+
return account;
|
|
174
|
+
}
|
|
175
|
+
function getSolanaAccountChain(account) {
|
|
176
|
+
const chain = account.chains.find(
|
|
177
|
+
(accountChain) => SOLANA_CHAINS.includes(accountChain)
|
|
178
|
+
);
|
|
179
|
+
if (!chain) {
|
|
180
|
+
throw new Error("Solana wallet account does not support a Solana chain");
|
|
181
|
+
}
|
|
182
|
+
return chain;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME = "Mobile Wallet Adapter";
|
|
186
|
+
function isSolanaStandardWallet(wallet) {
|
|
187
|
+
return features.StandardConnect in wallet.features && features.StandardDisconnect in wallet.features && wallet.chains.some((chain) => SOLANA_CHAINS.includes(chain));
|
|
188
|
+
}
|
|
189
|
+
function getRegisteredSolanaWallets() {
|
|
190
|
+
if (typeof window === "undefined") {
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
return app.getWallets().get().filter(isSolanaStandardWallet).map(createSolanaWalletInfo);
|
|
194
|
+
}
|
|
195
|
+
function subscribeSolanaWallets(listener) {
|
|
196
|
+
if (typeof window === "undefined") {
|
|
197
|
+
return () => {
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const wallets = app.getWallets();
|
|
201
|
+
const offRegister = wallets.on("register", listener);
|
|
202
|
+
const offUnregister = wallets.on("unregister", listener);
|
|
203
|
+
return () => {
|
|
204
|
+
offRegister();
|
|
205
|
+
offUnregister();
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function createSolanaWalletInfo(wallet) {
|
|
209
|
+
const isMobileWallet = wallet.name === SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME;
|
|
210
|
+
return {
|
|
211
|
+
name: wallet.name,
|
|
212
|
+
icon: wallet.icon,
|
|
213
|
+
chains: wallet.chains,
|
|
214
|
+
platform: isMobileWallet ? "mobile" : "browser",
|
|
215
|
+
source: isMobileWallet ? "mobile-wallet-adapter" : "wallet-standard",
|
|
216
|
+
appUrl: getWalletUrl(wallet),
|
|
217
|
+
accounts: wallet.accounts.map((account) => ({
|
|
218
|
+
address: account.address,
|
|
219
|
+
publicKey: Uint8Array.from(account.publicKey),
|
|
220
|
+
chains: account.chains,
|
|
221
|
+
label: account.label,
|
|
222
|
+
icon: account.icon
|
|
223
|
+
})),
|
|
224
|
+
wallet
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function getWalletUrl(wallet) {
|
|
228
|
+
return "url" in wallet && typeof wallet.url === "string" ? wallet.url : void 0;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
exports.SOLANA_CHAINS = SOLANA_CHAINS;
|
|
232
|
+
exports.SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME = SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME;
|
|
233
|
+
exports.adaptSolanaStandardWallet = adaptSolanaStandardWallet;
|
|
234
|
+
exports.getRegisteredSolanaWallets = getRegisteredSolanaWallets;
|
|
235
|
+
exports.getSolanaChain = getSolanaChain;
|
|
236
|
+
exports.isSolanaStandardWallet = isSolanaStandardWallet;
|
|
237
|
+
exports.subscribeSolanaWallets = subscribeSolanaWallets;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { StandardEvents, StandardDisconnect, StandardConnect } from '@wallet-standard/features';
|
|
2
|
+
import { SolanaSignAndSendTransaction, SolanaSignTransaction } from '@solana/wallet-standard-features';
|
|
3
|
+
import { Transaction, VersionedTransaction, PublicKey } from '@solana/web3-compat';
|
|
4
|
+
import bs58 from 'bs58';
|
|
5
|
+
import { getWallets } from '@wallet-standard/app';
|
|
6
|
+
|
|
7
|
+
const SOLANA_CHAINS = [
|
|
8
|
+
"solana:mainnet",
|
|
9
|
+
"solana:testnet",
|
|
10
|
+
"solana:devnet",
|
|
11
|
+
"solana:localnet"
|
|
12
|
+
];
|
|
13
|
+
function getSolanaChain(cluster) {
|
|
14
|
+
if (cluster === "mainnet-beta") {
|
|
15
|
+
return "solana:mainnet";
|
|
16
|
+
}
|
|
17
|
+
return `solana:${cluster}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function hasSignTransaction(wallet) {
|
|
21
|
+
return SolanaSignTransaction in wallet.features;
|
|
22
|
+
}
|
|
23
|
+
function hasSignAndSendTransaction(wallet) {
|
|
24
|
+
return SolanaSignAndSendTransaction in wallet.features;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function serializeTransaction(transaction) {
|
|
28
|
+
if (transaction instanceof Transaction) {
|
|
29
|
+
return transaction.serialize({ requireAllSignatures: false, verifySignatures: false });
|
|
30
|
+
}
|
|
31
|
+
return transaction.serialize();
|
|
32
|
+
}
|
|
33
|
+
function deserializeTransaction(source, bytes) {
|
|
34
|
+
if (source instanceof Transaction) {
|
|
35
|
+
return Transaction.from(bytes);
|
|
36
|
+
}
|
|
37
|
+
return VersionedTransaction.deserialize(bytes);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
41
|
+
const wallet = walletInfo.wallet;
|
|
42
|
+
let accounts = wallet.accounts;
|
|
43
|
+
let account = options.account;
|
|
44
|
+
let allowAccountUpdates = Boolean(options.account);
|
|
45
|
+
let connecting = false;
|
|
46
|
+
let disconnecting = false;
|
|
47
|
+
let manuallyDisconnected = false;
|
|
48
|
+
const eventsFeature = wallet.features[StandardEvents];
|
|
49
|
+
eventsFeature?.on("change", (properties) => {
|
|
50
|
+
if (properties.accounts) {
|
|
51
|
+
accounts = properties.accounts;
|
|
52
|
+
account = allowAccountUpdates && !manuallyDisconnected ? getSolanaAccount(accounts, options.chain) : void 0;
|
|
53
|
+
options.onChange?.();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
platform: walletInfo.platform,
|
|
58
|
+
source: walletInfo.source,
|
|
59
|
+
get publicKey() {
|
|
60
|
+
return account ? new PublicKey(account.publicKey) : null;
|
|
61
|
+
},
|
|
62
|
+
get connected() {
|
|
63
|
+
return Boolean(account);
|
|
64
|
+
},
|
|
65
|
+
get connecting() {
|
|
66
|
+
return connecting;
|
|
67
|
+
},
|
|
68
|
+
get disconnecting() {
|
|
69
|
+
return disconnecting;
|
|
70
|
+
},
|
|
71
|
+
async connect() {
|
|
72
|
+
connecting = true;
|
|
73
|
+
manuallyDisconnected = false;
|
|
74
|
+
options.onChange?.();
|
|
75
|
+
try {
|
|
76
|
+
const feature = wallet.features[StandardConnect];
|
|
77
|
+
const result = await feature.connect();
|
|
78
|
+
accounts = result.accounts;
|
|
79
|
+
allowAccountUpdates = true;
|
|
80
|
+
account = getSolanaAccount(accounts, options.chain);
|
|
81
|
+
if (!account) {
|
|
82
|
+
throw new Error("Solana wallet did not authorize a Solana account");
|
|
83
|
+
}
|
|
84
|
+
} finally {
|
|
85
|
+
connecting = false;
|
|
86
|
+
options.onChange?.();
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
async disconnect() {
|
|
90
|
+
const feature = wallet.features[StandardDisconnect];
|
|
91
|
+
disconnecting = true;
|
|
92
|
+
manuallyDisconnected = true;
|
|
93
|
+
allowAccountUpdates = false;
|
|
94
|
+
account = void 0;
|
|
95
|
+
options.onChange?.();
|
|
96
|
+
try {
|
|
97
|
+
await feature.disconnect();
|
|
98
|
+
accounts = [];
|
|
99
|
+
account = void 0;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
manuallyDisconnected = false;
|
|
102
|
+
allowAccountUpdates = true;
|
|
103
|
+
account = getSolanaAccount(accounts, options.chain);
|
|
104
|
+
throw error;
|
|
105
|
+
} finally {
|
|
106
|
+
disconnecting = false;
|
|
107
|
+
options.onChange?.();
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
|
|
111
|
+
const activeAccount = getActiveAccount(account);
|
|
112
|
+
const [result] = await wallet.features[SolanaSignTransaction].signTransaction({
|
|
113
|
+
account: activeAccount,
|
|
114
|
+
transaction: serializeTransaction(transaction),
|
|
115
|
+
chain: options.chain
|
|
116
|
+
});
|
|
117
|
+
if (!result) {
|
|
118
|
+
throw new Error("Solana wallet did not return a signed transaction");
|
|
119
|
+
}
|
|
120
|
+
return deserializeTransaction(transaction, result.signedTransaction);
|
|
121
|
+
} : void 0,
|
|
122
|
+
signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => {
|
|
123
|
+
const activeAccount = getActiveAccount(account);
|
|
124
|
+
const results = await wallet.features[SolanaSignTransaction].signTransaction(
|
|
125
|
+
...transactions.map((transaction) => ({
|
|
126
|
+
account: activeAccount,
|
|
127
|
+
transaction: serializeTransaction(transaction),
|
|
128
|
+
chain: options.chain
|
|
129
|
+
}))
|
|
130
|
+
);
|
|
131
|
+
if (results.length !== transactions.length) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
`Solana wallet returned ${results.length} signed transactions for ${transactions.length} requested transactions`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return results.map((result, index) => {
|
|
137
|
+
if (!result) {
|
|
138
|
+
throw new Error("Solana wallet did not return a signed transaction");
|
|
139
|
+
}
|
|
140
|
+
return deserializeTransaction(transactions[index], result.signedTransaction);
|
|
141
|
+
});
|
|
142
|
+
} : void 0,
|
|
143
|
+
signAndSendTransaction: hasSignAndSendTransaction(wallet) ? async (transaction, sendOptions) => {
|
|
144
|
+
const activeAccount = getActiveAccount(account);
|
|
145
|
+
const [result] = await wallet.features[SolanaSignAndSendTransaction].signAndSendTransaction({
|
|
146
|
+
account: activeAccount,
|
|
147
|
+
transaction: serializeTransaction(transaction),
|
|
148
|
+
chain: options.chain ?? getSolanaAccountChain(activeAccount),
|
|
149
|
+
options: sendOptions
|
|
150
|
+
});
|
|
151
|
+
if (!result) {
|
|
152
|
+
throw new Error("Solana wallet did not return a transaction signature");
|
|
153
|
+
}
|
|
154
|
+
return { signature: bs58.encode(result.signature) };
|
|
155
|
+
} : void 0
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function getSolanaAccount(accounts, chain) {
|
|
159
|
+
return accounts.find((account) => account.chains.some((accountChain) => accountChain === chain)) ?? accounts.find(
|
|
160
|
+
(account) => account.chains.some((accountChain) => SOLANA_CHAINS.includes(accountChain))
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
function getActiveAccount(account) {
|
|
164
|
+
if (!account) {
|
|
165
|
+
throw new Error("Solana wallet is not connected");
|
|
166
|
+
}
|
|
167
|
+
return account;
|
|
168
|
+
}
|
|
169
|
+
function getSolanaAccountChain(account) {
|
|
170
|
+
const chain = account.chains.find(
|
|
171
|
+
(accountChain) => SOLANA_CHAINS.includes(accountChain)
|
|
172
|
+
);
|
|
173
|
+
if (!chain) {
|
|
174
|
+
throw new Error("Solana wallet account does not support a Solana chain");
|
|
175
|
+
}
|
|
176
|
+
return chain;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME = "Mobile Wallet Adapter";
|
|
180
|
+
function isSolanaStandardWallet(wallet) {
|
|
181
|
+
return StandardConnect in wallet.features && StandardDisconnect in wallet.features && wallet.chains.some((chain) => SOLANA_CHAINS.includes(chain));
|
|
182
|
+
}
|
|
183
|
+
function getRegisteredSolanaWallets() {
|
|
184
|
+
if (typeof window === "undefined") {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
return getWallets().get().filter(isSolanaStandardWallet).map(createSolanaWalletInfo);
|
|
188
|
+
}
|
|
189
|
+
function subscribeSolanaWallets(listener) {
|
|
190
|
+
if (typeof window === "undefined") {
|
|
191
|
+
return () => {
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const wallets = getWallets();
|
|
195
|
+
const offRegister = wallets.on("register", listener);
|
|
196
|
+
const offUnregister = wallets.on("unregister", listener);
|
|
197
|
+
return () => {
|
|
198
|
+
offRegister();
|
|
199
|
+
offUnregister();
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function createSolanaWalletInfo(wallet) {
|
|
203
|
+
const isMobileWallet = wallet.name === SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME;
|
|
204
|
+
return {
|
|
205
|
+
name: wallet.name,
|
|
206
|
+
icon: wallet.icon,
|
|
207
|
+
chains: wallet.chains,
|
|
208
|
+
platform: isMobileWallet ? "mobile" : "browser",
|
|
209
|
+
source: isMobileWallet ? "mobile-wallet-adapter" : "wallet-standard",
|
|
210
|
+
appUrl: getWalletUrl(wallet),
|
|
211
|
+
accounts: wallet.accounts.map((account) => ({
|
|
212
|
+
address: account.address,
|
|
213
|
+
publicKey: Uint8Array.from(account.publicKey),
|
|
214
|
+
chains: account.chains,
|
|
215
|
+
label: account.label,
|
|
216
|
+
icon: account.icon
|
|
217
|
+
})),
|
|
218
|
+
wallet
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function getWalletUrl(wallet) {
|
|
222
|
+
return "url" in wallet && typeof wallet.url === "string" ? wallet.url : void 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export { SOLANA_CHAINS as S, SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME as a, adaptSolanaStandardWallet as b, getSolanaChain as c, getRegisteredSolanaWallets as g, isSolanaStandardWallet as i, subscribeSolanaWallets as s };
|