@solana/client 0.2.3 → 1.0.0-rc.1
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/dist/index.browser.cjs +446 -380
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +444 -381
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +444 -381
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +446 -380
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +444 -381
- package/dist/index.node.mjs.map +1 -1
- package/dist/server/index.node.cjs +15 -2
- package/dist/server/index.node.cjs.map +1 -1
- package/dist/server/index.node.mjs +15 -2
- package/dist/server/index.node.mjs.map +1 -1
- package/dist/types/client/actions.d.ts.map +1 -1
- package/dist/types/client/createClient.d.ts.map +1 -1
- package/dist/types/client/defaultClient.d.ts +26 -0
- package/dist/types/client/defaultClient.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/serialization/state.d.ts.map +1 -1
- package/dist/types/types.d.ts +9 -2
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/cluster.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.browser.cjs
CHANGED
|
@@ -248,6 +248,7 @@ __name(deserializeSolanaState, "deserializeSolanaState");
|
|
|
248
248
|
function getSerializableStateSnapshot(client) {
|
|
249
249
|
const state = client.store.getState();
|
|
250
250
|
const wallet = state.wallet;
|
|
251
|
+
const autoConnectPreference = wallet.autoConnect;
|
|
251
252
|
let lastConnectorId = null;
|
|
252
253
|
let lastPublicKey = null;
|
|
253
254
|
if ("connectorId" in wallet) {
|
|
@@ -257,7 +258,7 @@ function getSerializableStateSnapshot(client) {
|
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
260
|
return {
|
|
260
|
-
autoconnect: Boolean(lastConnectorId),
|
|
261
|
+
autoconnect: autoConnectPreference ?? Boolean(lastConnectorId),
|
|
261
262
|
commitment: state.cluster.commitment,
|
|
262
263
|
endpoint: state.cluster.endpoint,
|
|
263
264
|
lastConnectorId,
|
|
@@ -283,6 +284,69 @@ function subscribeSolanaState(client, listener) {
|
|
|
283
284
|
}
|
|
284
285
|
__name(subscribeSolanaState, "subscribeSolanaState");
|
|
285
286
|
|
|
287
|
+
// src/utils/cluster.ts
|
|
288
|
+
function ensureHttpProtocol(endpoint) {
|
|
289
|
+
if (endpoint.startsWith("http://") || endpoint.startsWith("https://") || endpoint.startsWith("ws://") || endpoint.startsWith("wss://")) {
|
|
290
|
+
return endpoint;
|
|
291
|
+
}
|
|
292
|
+
return `https://${endpoint}`;
|
|
293
|
+
}
|
|
294
|
+
__name(ensureHttpProtocol, "ensureHttpProtocol");
|
|
295
|
+
var MONIKER_ENDPOINTS = {
|
|
296
|
+
devnet: {
|
|
297
|
+
endpoint: "https://api.devnet.solana.com",
|
|
298
|
+
websocketEndpoint: "wss://api.devnet.solana.com"
|
|
299
|
+
},
|
|
300
|
+
localhost: {
|
|
301
|
+
endpoint: "http://127.0.0.1:8899",
|
|
302
|
+
websocketEndpoint: "ws://127.0.0.1:8900"
|
|
303
|
+
},
|
|
304
|
+
localnet: {
|
|
305
|
+
endpoint: "http://127.0.0.1:8899",
|
|
306
|
+
websocketEndpoint: "ws://127.0.0.1:8900"
|
|
307
|
+
},
|
|
308
|
+
"mainnet-beta": {
|
|
309
|
+
endpoint: "https://api.mainnet-beta.solana.com",
|
|
310
|
+
websocketEndpoint: "wss://api.mainnet-beta.solana.com"
|
|
311
|
+
},
|
|
312
|
+
mainnet: {
|
|
313
|
+
endpoint: "https://api.mainnet-beta.solana.com",
|
|
314
|
+
websocketEndpoint: "wss://api.mainnet-beta.solana.com"
|
|
315
|
+
},
|
|
316
|
+
testnet: {
|
|
317
|
+
endpoint: "https://api.testnet.solana.com",
|
|
318
|
+
websocketEndpoint: "wss://api.testnet.solana.com"
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
function inferWebsocketEndpoint(endpoint) {
|
|
322
|
+
if (endpoint.startsWith("https://")) {
|
|
323
|
+
return endpoint.replace("https://", "wss://");
|
|
324
|
+
}
|
|
325
|
+
if (endpoint.startsWith("http://")) {
|
|
326
|
+
return endpoint.replace("http://", "ws://");
|
|
327
|
+
}
|
|
328
|
+
if (endpoint.startsWith("ws://") || endpoint.startsWith("wss://")) {
|
|
329
|
+
return endpoint;
|
|
330
|
+
}
|
|
331
|
+
return endpoint;
|
|
332
|
+
}
|
|
333
|
+
__name(inferWebsocketEndpoint, "inferWebsocketEndpoint");
|
|
334
|
+
function resolveCluster(config) {
|
|
335
|
+
const moniker = config.moniker ?? (config.endpoint ? "custom" : "devnet");
|
|
336
|
+
const mapped = moniker === "custom" ? void 0 : MONIKER_ENDPOINTS[moniker];
|
|
337
|
+
const endpoint = ensureHttpProtocol(config.endpoint ?? mapped?.endpoint);
|
|
338
|
+
const rawWebsocket = config.websocketEndpoint ? ensureHttpProtocol(config.websocketEndpoint) : void 0;
|
|
339
|
+
const websocketEndpoint = inferWebsocketEndpoint(
|
|
340
|
+
rawWebsocket ?? mapped?.websocketEndpoint ?? endpoint
|
|
341
|
+
);
|
|
342
|
+
return {
|
|
343
|
+
endpoint,
|
|
344
|
+
moniker,
|
|
345
|
+
websocketEndpoint
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
__name(resolveCluster, "resolveCluster");
|
|
349
|
+
|
|
286
350
|
// src/wallet/registry.ts
|
|
287
351
|
function createWalletRegistry(connectors) {
|
|
288
352
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -394,17 +458,18 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
394
458
|
if (!connector.isSupported()) {
|
|
395
459
|
throw new Error(`Wallet connector "${connectorId}" is not supported in this environment.`);
|
|
396
460
|
}
|
|
461
|
+
const autoConnectPreference = options.autoConnect ?? true;
|
|
397
462
|
store.setState((state) => ({
|
|
398
463
|
...state,
|
|
399
464
|
lastUpdatedAt: now(),
|
|
400
|
-
wallet: { connectorId, status: "connecting" }
|
|
465
|
+
wallet: { autoConnect: autoConnectPreference, connectorId, status: "connecting" }
|
|
401
466
|
}));
|
|
402
467
|
try {
|
|
403
468
|
const session = await connector.connect(options);
|
|
404
469
|
store.setState((state) => ({
|
|
405
470
|
...state,
|
|
406
471
|
lastUpdatedAt: now(),
|
|
407
|
-
wallet: { connectorId, session, status: "connected" }
|
|
472
|
+
wallet: { autoConnect: autoConnectPreference, connectorId, session, status: "connected" }
|
|
408
473
|
}));
|
|
409
474
|
logger({
|
|
410
475
|
data: { address: session.account.address.toString(), connectorId },
|
|
@@ -415,7 +480,7 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
415
480
|
store.setState((state) => ({
|
|
416
481
|
...state,
|
|
417
482
|
lastUpdatedAt: now(),
|
|
418
|
-
wallet: { connectorId, error, status: "error" }
|
|
483
|
+
wallet: { autoConnect: autoConnectPreference, connectorId, error, status: "error" }
|
|
419
484
|
}));
|
|
420
485
|
logger({
|
|
421
486
|
data: { connectorId, ...formatError(error) },
|
|
@@ -2131,18 +2196,22 @@ __name(createWatchers, "createWatchers");
|
|
|
2131
2196
|
// src/client/createClient.ts
|
|
2132
2197
|
function createClient(config) {
|
|
2133
2198
|
const hydratedConfig = config.initialState ? applySerializableState(config, config.initialState) : config;
|
|
2199
|
+
const resolvedCluster = resolveCluster({
|
|
2200
|
+
endpoint: hydratedConfig.rpc ?? hydratedConfig.endpoint,
|
|
2201
|
+
moniker: hydratedConfig.cluster,
|
|
2202
|
+
websocketEndpoint: hydratedConfig.websocket ?? hydratedConfig.websocketEndpoint
|
|
2203
|
+
});
|
|
2134
2204
|
const commitment = hydratedConfig.commitment ?? "confirmed";
|
|
2135
|
-
const websocketEndpoint = hydratedConfig.websocketEndpoint ?? hydratedConfig.endpoint;
|
|
2136
2205
|
const initialState = createInitialClientState({
|
|
2137
2206
|
commitment,
|
|
2138
|
-
endpoint:
|
|
2139
|
-
websocketEndpoint
|
|
2207
|
+
endpoint: resolvedCluster.endpoint,
|
|
2208
|
+
websocketEndpoint: resolvedCluster.websocketEndpoint
|
|
2140
2209
|
});
|
|
2141
2210
|
const store = config.createStore ? config.createStore(initialState) : createClientStore(initialState);
|
|
2142
2211
|
const rpcClient = hydratedConfig.rpcClient ?? createSolanaRpcClient({
|
|
2143
2212
|
commitment,
|
|
2144
|
-
endpoint:
|
|
2145
|
-
websocketEndpoint
|
|
2213
|
+
endpoint: resolvedCluster.endpoint,
|
|
2214
|
+
websocketEndpoint: resolvedCluster.websocketEndpoint
|
|
2146
2215
|
});
|
|
2147
2216
|
const runtime = {
|
|
2148
2217
|
rpc: rpcClient.rpc,
|
|
@@ -2161,7 +2230,10 @@ function createClient(config) {
|
|
|
2161
2230
|
},
|
|
2162
2231
|
lastUpdatedAt: now()
|
|
2163
2232
|
}));
|
|
2164
|
-
actions.setCluster(
|
|
2233
|
+
actions.setCluster(resolvedCluster.endpoint, {
|
|
2234
|
+
commitment,
|
|
2235
|
+
websocketEndpoint: resolvedCluster.websocketEndpoint
|
|
2236
|
+
}).catch(
|
|
2165
2237
|
(error) => logger({
|
|
2166
2238
|
data: formatError(error),
|
|
2167
2239
|
level: "error",
|
|
@@ -2199,104 +2271,382 @@ function createClient(config) {
|
|
|
2199
2271
|
};
|
|
2200
2272
|
}
|
|
2201
2273
|
__name(createClient, "createClient");
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2274
|
+
var base58Decoder = codecsStrings.getBase58Decoder();
|
|
2275
|
+
var transactionDecoder = transactions.getTransactionDecoder();
|
|
2276
|
+
var transactionEncoder = transactions.getTransactionEncoder();
|
|
2277
|
+
function deriveConnectorId(wallet) {
|
|
2278
|
+
const kebab = wallet.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
2279
|
+
return `wallet-standard:${kebab}`;
|
|
2206
2280
|
}
|
|
2207
|
-
__name(
|
|
2208
|
-
function
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2281
|
+
__name(deriveConnectorId, "deriveConnectorId");
|
|
2282
|
+
function getPrimaryAccount(accounts) {
|
|
2283
|
+
const primary = accounts[0];
|
|
2284
|
+
if (!primary) {
|
|
2285
|
+
throw new Error("Wallet returned no accounts.");
|
|
2286
|
+
}
|
|
2287
|
+
return primary;
|
|
2214
2288
|
}
|
|
2215
|
-
__name(
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
const authority = input.authority ?? resolveDefault?.();
|
|
2220
|
-
if (!authority) {
|
|
2221
|
-
throw new Error("Connect a wallet or supply an `authority` before sending SOL transfers.");
|
|
2289
|
+
__name(getPrimaryAccount, "getPrimaryAccount");
|
|
2290
|
+
function mapCommitment(commitment) {
|
|
2291
|
+
if (commitment === "processed" || commitment === "confirmed" || commitment === "finalized") {
|
|
2292
|
+
return commitment;
|
|
2222
2293
|
}
|
|
2294
|
+
return void 0;
|
|
2295
|
+
}
|
|
2296
|
+
__name(mapCommitment, "mapCommitment");
|
|
2297
|
+
function toSessionAccount(walletAccount) {
|
|
2223
2298
|
return {
|
|
2224
|
-
|
|
2225
|
-
|
|
2299
|
+
address: kit.address(walletAccount.address),
|
|
2300
|
+
label: walletAccount.label,
|
|
2301
|
+
publicKey: new Uint8Array(walletAccount.publicKey)
|
|
2226
2302
|
};
|
|
2227
2303
|
}
|
|
2228
|
-
__name(
|
|
2229
|
-
function
|
|
2230
|
-
const
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
}
|
|
2239
|
-
__name(notify, "notify");
|
|
2240
|
-
function setState(next) {
|
|
2241
|
-
state = next;
|
|
2242
|
-
notify();
|
|
2304
|
+
__name(toSessionAccount, "toSessionAccount");
|
|
2305
|
+
function getChain(account) {
|
|
2306
|
+
const [preferred] = account.chains ?? [];
|
|
2307
|
+
return preferred;
|
|
2308
|
+
}
|
|
2309
|
+
__name(getChain, "getChain");
|
|
2310
|
+
async function disconnectWallet2(wallet) {
|
|
2311
|
+
const disconnectFeature = wallet.features[features.StandardDisconnect];
|
|
2312
|
+
if (disconnectFeature) {
|
|
2313
|
+
await disconnectFeature.disconnect();
|
|
2243
2314
|
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2315
|
+
}
|
|
2316
|
+
__name(disconnectWallet2, "disconnectWallet");
|
|
2317
|
+
function createWalletStandardConnector(wallet, options = {}) {
|
|
2318
|
+
const metadata = {
|
|
2319
|
+
canAutoConnect: options.canAutoConnect ?? Boolean(wallet.features[features.StandardConnect]),
|
|
2320
|
+
icon: options.icon ?? wallet.icon,
|
|
2321
|
+
id: options.id ?? deriveConnectorId(wallet),
|
|
2322
|
+
kind: options.kind ?? "wallet-standard",
|
|
2323
|
+
name: options.name ?? wallet.name,
|
|
2324
|
+
ready: typeof window !== "undefined"
|
|
2325
|
+
};
|
|
2326
|
+
async function connect(connectionOptions = {}) {
|
|
2327
|
+
const connectFeature = wallet.features[features.StandardConnect];
|
|
2328
|
+
const shouldConnectSilently = Boolean(connectionOptions.autoConnect);
|
|
2329
|
+
let walletAccounts = wallet.accounts;
|
|
2330
|
+
if (connectFeature) {
|
|
2331
|
+
const { accounts } = await connectFeature.connect({
|
|
2332
|
+
silent: shouldConnectSilently || void 0
|
|
2333
|
+
});
|
|
2334
|
+
if (accounts.length) {
|
|
2335
|
+
walletAccounts = accounts;
|
|
2336
|
+
}
|
|
2255
2337
|
}
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2338
|
+
const primaryAccount = getPrimaryAccount(walletAccounts);
|
|
2339
|
+
const sessionAccount = toSessionAccount(primaryAccount);
|
|
2340
|
+
const signMessageFeature = wallet.features[walletStandardFeatures.SolanaSignMessage];
|
|
2341
|
+
const signTransactionFeature = wallet.features[walletStandardFeatures.SolanaSignTransaction];
|
|
2342
|
+
const signAndSendFeature = wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction];
|
|
2343
|
+
const resolvedChain = options.defaultChain ?? getChain(primaryAccount);
|
|
2344
|
+
const signMessage = signMessageFeature ? async (message) => {
|
|
2345
|
+
const [output] = await signMessageFeature.signMessage({
|
|
2346
|
+
account: primaryAccount,
|
|
2347
|
+
message
|
|
2348
|
+
});
|
|
2349
|
+
return output.signature;
|
|
2350
|
+
} : void 0;
|
|
2351
|
+
const signTransaction = signTransactionFeature ? async (transaction) => {
|
|
2352
|
+
const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
|
|
2353
|
+
const request = resolvedChain ? {
|
|
2354
|
+
account: primaryAccount,
|
|
2355
|
+
chain: resolvedChain,
|
|
2356
|
+
transaction: wireBytes
|
|
2357
|
+
} : {
|
|
2358
|
+
account: primaryAccount,
|
|
2359
|
+
transaction: wireBytes
|
|
2360
|
+
};
|
|
2361
|
+
const [output] = await signTransactionFeature.signTransaction(request);
|
|
2362
|
+
return transactionDecoder.decode(output.signedTransaction);
|
|
2363
|
+
} : void 0;
|
|
2364
|
+
const sendTransaction2 = signAndSendFeature ? async (transaction, config) => {
|
|
2365
|
+
const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
|
|
2366
|
+
const chain = options.defaultChain ?? getChain(primaryAccount) ?? "solana:mainnet-beta";
|
|
2367
|
+
const [output] = await signAndSendFeature.signAndSendTransaction({
|
|
2368
|
+
account: primaryAccount,
|
|
2369
|
+
chain,
|
|
2370
|
+
options: {
|
|
2371
|
+
commitment: mapCommitment(config?.commitment)
|
|
2372
|
+
},
|
|
2373
|
+
transaction: wireBytes
|
|
2374
|
+
});
|
|
2375
|
+
return base58Decoder.decode(output.signature);
|
|
2376
|
+
} : void 0;
|
|
2377
|
+
async function disconnectSession() {
|
|
2378
|
+
await disconnectWallet2(wallet);
|
|
2379
|
+
}
|
|
2380
|
+
__name(disconnectSession, "disconnectSession");
|
|
2381
|
+
return {
|
|
2382
|
+
account: sessionAccount,
|
|
2383
|
+
connector: metadata,
|
|
2384
|
+
disconnect: disconnectSession,
|
|
2385
|
+
sendTransaction: sendTransaction2,
|
|
2386
|
+
signMessage,
|
|
2387
|
+
signTransaction
|
|
2262
2388
|
};
|
|
2263
2389
|
}
|
|
2264
|
-
__name(
|
|
2265
|
-
function
|
|
2266
|
-
|
|
2267
|
-
}
|
|
2268
|
-
__name(reset, "reset");
|
|
2269
|
-
return {
|
|
2270
|
-
getHelper: /* @__PURE__ */ __name(() => helper, "getHelper"),
|
|
2271
|
-
getState: /* @__PURE__ */ __name(() => state, "getState"),
|
|
2272
|
-
reset,
|
|
2273
|
-
send,
|
|
2274
|
-
subscribe
|
|
2275
|
-
};
|
|
2276
|
-
}
|
|
2277
|
-
__name(createSolTransferController, "createSolTransferController");
|
|
2278
|
-
|
|
2279
|
-
// src/controllers/splTransferController.ts
|
|
2280
|
-
function ensureTransferConfig(input, resolveAuthority, resolveSourceOwner) {
|
|
2281
|
-
const authority = input.authority ?? resolveAuthority?.();
|
|
2282
|
-
if (!authority) {
|
|
2283
|
-
throw new Error("Connect a wallet or supply an `authority` before sending SPL tokens.");
|
|
2390
|
+
__name(connect, "connect");
|
|
2391
|
+
async function disconnect() {
|
|
2392
|
+
await disconnectWallet2(wallet);
|
|
2284
2393
|
}
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2394
|
+
__name(disconnect, "disconnect");
|
|
2395
|
+
function isSupported() {
|
|
2396
|
+
return typeof window !== "undefined";
|
|
2288
2397
|
}
|
|
2398
|
+
__name(isSupported, "isSupported");
|
|
2289
2399
|
return {
|
|
2290
|
-
...
|
|
2291
|
-
|
|
2292
|
-
|
|
2400
|
+
...metadata,
|
|
2401
|
+
connect,
|
|
2402
|
+
disconnect,
|
|
2403
|
+
isSupported
|
|
2293
2404
|
};
|
|
2294
2405
|
}
|
|
2295
|
-
__name(
|
|
2296
|
-
function
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2406
|
+
__name(createWalletStandardConnector, "createWalletStandardConnector");
|
|
2407
|
+
function mapWalletToConnector(wallet, overrides) {
|
|
2408
|
+
return createWalletStandardConnector(wallet, overrides?.(wallet));
|
|
2409
|
+
}
|
|
2410
|
+
__name(mapWalletToConnector, "mapWalletToConnector");
|
|
2411
|
+
function getWalletStandardConnectors(options = {}) {
|
|
2412
|
+
const { get } = app.getWallets();
|
|
2413
|
+
const connectors = get().map((wallet) => mapWalletToConnector(wallet, options.overrides));
|
|
2414
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2415
|
+
return connectors.filter((connector) => {
|
|
2416
|
+
if (seen.has(connector.id)) {
|
|
2417
|
+
return false;
|
|
2418
|
+
}
|
|
2419
|
+
seen.add(connector.id);
|
|
2420
|
+
return true;
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
__name(getWalletStandardConnectors, "getWalletStandardConnectors");
|
|
2424
|
+
function watchWalletStandardConnectors(onChange, options = {}) {
|
|
2425
|
+
const { get, on } = app.getWallets();
|
|
2426
|
+
const emit = /* @__PURE__ */ __name(() => {
|
|
2427
|
+
const connectors = get().map((wallet) => mapWalletToConnector(wallet, options.overrides));
|
|
2428
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2429
|
+
const deduplicated = connectors.filter((connector) => {
|
|
2430
|
+
if (seen.has(connector.id)) {
|
|
2431
|
+
return false;
|
|
2432
|
+
}
|
|
2433
|
+
seen.add(connector.id);
|
|
2434
|
+
return true;
|
|
2435
|
+
});
|
|
2436
|
+
onChange(deduplicated);
|
|
2437
|
+
}, "emit");
|
|
2438
|
+
emit();
|
|
2439
|
+
const offRegister = on("register", emit);
|
|
2440
|
+
const offUnregister = on("unregister", emit);
|
|
2441
|
+
return () => {
|
|
2442
|
+
offRegister();
|
|
2443
|
+
offUnregister();
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2446
|
+
__name(watchWalletStandardConnectors, "watchWalletStandardConnectors");
|
|
2447
|
+
|
|
2448
|
+
// src/wallet/connectors.ts
|
|
2449
|
+
function autoDiscover(options = {}) {
|
|
2450
|
+
const { get } = app.getWallets();
|
|
2451
|
+
const wallets = get().filter((wallet) => options.filter ? options.filter(wallet) : true);
|
|
2452
|
+
const connectors = wallets.map((wallet) => createWalletStandardConnector(wallet, options.overrides?.(wallet)));
|
|
2453
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2454
|
+
return connectors.filter((connector) => {
|
|
2455
|
+
if (seen.has(connector.id)) return false;
|
|
2456
|
+
seen.add(connector.id);
|
|
2457
|
+
return true;
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
__name(autoDiscover, "autoDiscover");
|
|
2461
|
+
function injected(options) {
|
|
2462
|
+
const connector = {
|
|
2463
|
+
canAutoConnect: true,
|
|
2464
|
+
id: "wallet-standard:injected",
|
|
2465
|
+
kind: "wallet-standard",
|
|
2466
|
+
name: "Injected Wallet",
|
|
2467
|
+
ready: typeof window !== "undefined",
|
|
2468
|
+
async connect() {
|
|
2469
|
+
const wallets = app.getWallets().get();
|
|
2470
|
+
const first = wallets.find((wallet) => features.StandardConnect in wallet.features);
|
|
2471
|
+
if (!first) {
|
|
2472
|
+
throw new Error("No Wallet Standard wallets available.");
|
|
2473
|
+
}
|
|
2474
|
+
return createWalletStandardConnector(first, options).connect();
|
|
2475
|
+
},
|
|
2476
|
+
async disconnect() {
|
|
2477
|
+
},
|
|
2478
|
+
isSupported() {
|
|
2479
|
+
return typeof window !== "undefined";
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2482
|
+
return connector;
|
|
2483
|
+
}
|
|
2484
|
+
__name(injected, "injected");
|
|
2485
|
+
function filterByName(name) {
|
|
2486
|
+
const lower = name.toLowerCase();
|
|
2487
|
+
return (wallet) => wallet.name.toLowerCase().includes(lower);
|
|
2488
|
+
}
|
|
2489
|
+
__name(filterByName, "filterByName");
|
|
2490
|
+
function phantom(options) {
|
|
2491
|
+
return autoDiscover({
|
|
2492
|
+
filter: filterByName("phantom"),
|
|
2493
|
+
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:phantom" }), "overrides")
|
|
2494
|
+
});
|
|
2495
|
+
}
|
|
2496
|
+
__name(phantom, "phantom");
|
|
2497
|
+
function solflare(options) {
|
|
2498
|
+
return autoDiscover({
|
|
2499
|
+
filter: filterByName("solflare"),
|
|
2500
|
+
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:solflare" }), "overrides")
|
|
2501
|
+
});
|
|
2502
|
+
}
|
|
2503
|
+
__name(solflare, "solflare");
|
|
2504
|
+
function backpack(options) {
|
|
2505
|
+
return autoDiscover({
|
|
2506
|
+
filter: filterByName("backpack"),
|
|
2507
|
+
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:backpack" }), "overrides")
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
__name(backpack, "backpack");
|
|
2511
|
+
|
|
2512
|
+
// src/client/defaultClient.ts
|
|
2513
|
+
function defaultWalletConnectors() {
|
|
2514
|
+
return [...phantom(), ...solflare(), ...backpack(), ...autoDiscover()];
|
|
2515
|
+
}
|
|
2516
|
+
__name(defaultWalletConnectors, "defaultWalletConnectors");
|
|
2517
|
+
function normalizeUrl(value) {
|
|
2518
|
+
if (!value) return void 0;
|
|
2519
|
+
const trimmed = value.trim();
|
|
2520
|
+
return trimmed.length ? trimmed : void 0;
|
|
2521
|
+
}
|
|
2522
|
+
__name(normalizeUrl, "normalizeUrl");
|
|
2523
|
+
function resolveClientConfig(config = {}) {
|
|
2524
|
+
const {
|
|
2525
|
+
cluster,
|
|
2526
|
+
endpoint: endpointOverride,
|
|
2527
|
+
rpc,
|
|
2528
|
+
websocket,
|
|
2529
|
+
websocketEndpoint,
|
|
2530
|
+
walletConnectors,
|
|
2531
|
+
...passthrough
|
|
2532
|
+
} = config;
|
|
2533
|
+
const resolvedEndpoint = normalizeUrl(rpc) ?? normalizeUrl(endpointOverride) ?? normalizeUrl(config.endpoint);
|
|
2534
|
+
const resolvedCluster = resolveCluster({
|
|
2535
|
+
endpoint: resolvedEndpoint,
|
|
2536
|
+
moniker: cluster ?? void 0,
|
|
2537
|
+
websocketEndpoint: normalizeUrl(websocket ?? websocketEndpoint)
|
|
2538
|
+
});
|
|
2539
|
+
const resolvedConnectors = walletConnectors === void 0 || walletConnectors === "default" ? defaultWalletConnectors() : walletConnectors;
|
|
2540
|
+
return {
|
|
2541
|
+
...passthrough,
|
|
2542
|
+
endpoint: resolvedCluster.endpoint,
|
|
2543
|
+
websocketEndpoint: resolvedCluster.websocketEndpoint,
|
|
2544
|
+
walletConnectors: resolvedConnectors
|
|
2545
|
+
};
|
|
2546
|
+
}
|
|
2547
|
+
__name(resolveClientConfig, "resolveClientConfig");
|
|
2548
|
+
function createDefaultClient(config = {}) {
|
|
2549
|
+
return createClient(resolveClientConfig(config));
|
|
2550
|
+
}
|
|
2551
|
+
__name(createDefaultClient, "createDefaultClient");
|
|
2552
|
+
|
|
2553
|
+
// src/state/asyncState.ts
|
|
2554
|
+
function createInitialAsyncState() {
|
|
2555
|
+
return { status: "idle" };
|
|
2556
|
+
}
|
|
2557
|
+
__name(createInitialAsyncState, "createInitialAsyncState");
|
|
2558
|
+
function createAsyncState(status, payload = {}) {
|
|
2559
|
+
return {
|
|
2560
|
+
data: payload.data,
|
|
2561
|
+
error: payload.error,
|
|
2562
|
+
status
|
|
2563
|
+
};
|
|
2564
|
+
}
|
|
2565
|
+
__name(createAsyncState, "createAsyncState");
|
|
2566
|
+
|
|
2567
|
+
// src/controllers/solTransferController.ts
|
|
2568
|
+
function ensureAuthority(input, resolveDefault) {
|
|
2569
|
+
const authority = input.authority ?? resolveDefault?.();
|
|
2570
|
+
if (!authority) {
|
|
2571
|
+
throw new Error("Connect a wallet or supply an `authority` before sending SOL transfers.");
|
|
2572
|
+
}
|
|
2573
|
+
return {
|
|
2574
|
+
...input,
|
|
2575
|
+
authority
|
|
2576
|
+
};
|
|
2577
|
+
}
|
|
2578
|
+
__name(ensureAuthority, "ensureAuthority");
|
|
2579
|
+
function createSolTransferController(config) {
|
|
2580
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
2581
|
+
const helper = config.helper;
|
|
2582
|
+
const authorityProvider = config.authorityProvider;
|
|
2583
|
+
let state = createInitialAsyncState();
|
|
2584
|
+
function notify() {
|
|
2585
|
+
for (const listener of listeners) {
|
|
2586
|
+
listener();
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
__name(notify, "notify");
|
|
2590
|
+
function setState(next) {
|
|
2591
|
+
state = next;
|
|
2592
|
+
notify();
|
|
2593
|
+
}
|
|
2594
|
+
__name(setState, "setState");
|
|
2595
|
+
async function send(config2, options) {
|
|
2596
|
+
const request = ensureAuthority(config2, authorityProvider);
|
|
2597
|
+
setState(createAsyncState("loading"));
|
|
2598
|
+
try {
|
|
2599
|
+
const signature4 = await helper.sendTransfer(request, options);
|
|
2600
|
+
setState(createAsyncState("success", { data: signature4 }));
|
|
2601
|
+
return signature4;
|
|
2602
|
+
} catch (error) {
|
|
2603
|
+
setState(createAsyncState("error", { error }));
|
|
2604
|
+
throw error;
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
__name(send, "send");
|
|
2608
|
+
function subscribe(listener) {
|
|
2609
|
+
listeners.add(listener);
|
|
2610
|
+
return () => {
|
|
2611
|
+
listeners.delete(listener);
|
|
2612
|
+
};
|
|
2613
|
+
}
|
|
2614
|
+
__name(subscribe, "subscribe");
|
|
2615
|
+
function reset() {
|
|
2616
|
+
setState(createInitialAsyncState());
|
|
2617
|
+
}
|
|
2618
|
+
__name(reset, "reset");
|
|
2619
|
+
return {
|
|
2620
|
+
getHelper: /* @__PURE__ */ __name(() => helper, "getHelper"),
|
|
2621
|
+
getState: /* @__PURE__ */ __name(() => state, "getState"),
|
|
2622
|
+
reset,
|
|
2623
|
+
send,
|
|
2624
|
+
subscribe
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
__name(createSolTransferController, "createSolTransferController");
|
|
2628
|
+
|
|
2629
|
+
// src/controllers/splTransferController.ts
|
|
2630
|
+
function ensureTransferConfig(input, resolveAuthority, resolveSourceOwner) {
|
|
2631
|
+
const authority = input.authority ?? resolveAuthority?.();
|
|
2632
|
+
if (!authority) {
|
|
2633
|
+
throw new Error("Connect a wallet or supply an `authority` before sending SPL tokens.");
|
|
2634
|
+
}
|
|
2635
|
+
const sourceOwner = input.sourceOwner ?? resolveSourceOwner?.();
|
|
2636
|
+
if (!sourceOwner) {
|
|
2637
|
+
throw new Error("Unable to resolve a source owner for the SPL token transfer.");
|
|
2638
|
+
}
|
|
2639
|
+
return {
|
|
2640
|
+
...input,
|
|
2641
|
+
authority,
|
|
2642
|
+
sourceOwner
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2645
|
+
__name(ensureTransferConfig, "ensureTransferConfig");
|
|
2646
|
+
function createSplTransferController(config) {
|
|
2647
|
+
const helper = config.helper;
|
|
2648
|
+
const authorityProvider = config.authorityProvider;
|
|
2649
|
+
const sourceOwnerProvider = config.sourceOwnerProvider;
|
|
2300
2650
|
const listeners = /* @__PURE__ */ new Set();
|
|
2301
2651
|
let state = createInitialAsyncState();
|
|
2302
2652
|
function notify() {
|
|
@@ -2677,56 +3027,6 @@ function toAddressString(addressLike) {
|
|
|
2677
3027
|
}
|
|
2678
3028
|
__name(toAddressString, "toAddressString");
|
|
2679
3029
|
|
|
2680
|
-
// src/utils/cluster.ts
|
|
2681
|
-
var MONIKER_ENDPOINTS = {
|
|
2682
|
-
devnet: {
|
|
2683
|
-
endpoint: "https://api.devnet.solana.com",
|
|
2684
|
-
websocketEndpoint: "wss://api.devnet.solana.com"
|
|
2685
|
-
},
|
|
2686
|
-
localhost: {
|
|
2687
|
-
endpoint: "http://127.0.0.1:8899",
|
|
2688
|
-
websocketEndpoint: "ws://127.0.0.1:8900"
|
|
2689
|
-
},
|
|
2690
|
-
localnet: {
|
|
2691
|
-
endpoint: "http://127.0.0.1:8899",
|
|
2692
|
-
websocketEndpoint: "ws://127.0.0.1:8900"
|
|
2693
|
-
},
|
|
2694
|
-
"mainnet-beta": {
|
|
2695
|
-
endpoint: "https://api.mainnet-beta.solana.com",
|
|
2696
|
-
websocketEndpoint: "wss://api.mainnet-beta.solana.com"
|
|
2697
|
-
},
|
|
2698
|
-
mainnet: {
|
|
2699
|
-
endpoint: "https://api.mainnet-beta.solana.com",
|
|
2700
|
-
websocketEndpoint: "wss://api.mainnet-beta.solana.com"
|
|
2701
|
-
},
|
|
2702
|
-
testnet: {
|
|
2703
|
-
endpoint: "https://api.testnet.solana.com",
|
|
2704
|
-
websocketEndpoint: "wss://api.testnet.solana.com"
|
|
2705
|
-
}
|
|
2706
|
-
};
|
|
2707
|
-
function inferWebsocketEndpoint(endpoint) {
|
|
2708
|
-
if (endpoint.startsWith("https://")) {
|
|
2709
|
-
return endpoint.replace("https://", "wss://");
|
|
2710
|
-
}
|
|
2711
|
-
if (endpoint.startsWith("http://")) {
|
|
2712
|
-
return endpoint.replace("http://", "ws://");
|
|
2713
|
-
}
|
|
2714
|
-
return endpoint;
|
|
2715
|
-
}
|
|
2716
|
-
__name(inferWebsocketEndpoint, "inferWebsocketEndpoint");
|
|
2717
|
-
function resolveCluster(config) {
|
|
2718
|
-
const moniker = config.moniker ?? (config.endpoint ? "custom" : "devnet");
|
|
2719
|
-
const mapped = moniker === "custom" ? void 0 : MONIKER_ENDPOINTS[moniker];
|
|
2720
|
-
const endpoint = config.endpoint ?? mapped?.endpoint;
|
|
2721
|
-
const websocketEndpoint = config.websocketEndpoint ?? mapped?.websocketEndpoint ?? inferWebsocketEndpoint(endpoint);
|
|
2722
|
-
return {
|
|
2723
|
-
endpoint,
|
|
2724
|
-
moniker,
|
|
2725
|
-
websocketEndpoint
|
|
2726
|
-
};
|
|
2727
|
-
}
|
|
2728
|
-
__name(resolveCluster, "resolveCluster");
|
|
2729
|
-
|
|
2730
3030
|
// src/utils/stableStringify.ts
|
|
2731
3031
|
function stableStringify(value) {
|
|
2732
3032
|
const result = JSON.stringify(value, (_key, candidate) => {
|
|
@@ -2741,243 +3041,6 @@ function stableStringify(value) {
|
|
|
2741
3041
|
return result ?? "undefined";
|
|
2742
3042
|
}
|
|
2743
3043
|
__name(stableStringify, "stableStringify");
|
|
2744
|
-
var base58Decoder = codecsStrings.getBase58Decoder();
|
|
2745
|
-
var transactionDecoder = transactions.getTransactionDecoder();
|
|
2746
|
-
var transactionEncoder = transactions.getTransactionEncoder();
|
|
2747
|
-
function deriveConnectorId(wallet) {
|
|
2748
|
-
const kebab = wallet.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
2749
|
-
return `wallet-standard:${kebab}`;
|
|
2750
|
-
}
|
|
2751
|
-
__name(deriveConnectorId, "deriveConnectorId");
|
|
2752
|
-
function getPrimaryAccount(accounts) {
|
|
2753
|
-
const primary = accounts[0];
|
|
2754
|
-
if (!primary) {
|
|
2755
|
-
throw new Error("Wallet returned no accounts.");
|
|
2756
|
-
}
|
|
2757
|
-
return primary;
|
|
2758
|
-
}
|
|
2759
|
-
__name(getPrimaryAccount, "getPrimaryAccount");
|
|
2760
|
-
function mapCommitment(commitment) {
|
|
2761
|
-
if (commitment === "processed" || commitment === "confirmed" || commitment === "finalized") {
|
|
2762
|
-
return commitment;
|
|
2763
|
-
}
|
|
2764
|
-
return void 0;
|
|
2765
|
-
}
|
|
2766
|
-
__name(mapCommitment, "mapCommitment");
|
|
2767
|
-
function toSessionAccount(walletAccount) {
|
|
2768
|
-
return {
|
|
2769
|
-
address: kit.address(walletAccount.address),
|
|
2770
|
-
label: walletAccount.label,
|
|
2771
|
-
publicKey: new Uint8Array(walletAccount.publicKey)
|
|
2772
|
-
};
|
|
2773
|
-
}
|
|
2774
|
-
__name(toSessionAccount, "toSessionAccount");
|
|
2775
|
-
function getChain(account) {
|
|
2776
|
-
const [preferred] = account.chains ?? [];
|
|
2777
|
-
return preferred;
|
|
2778
|
-
}
|
|
2779
|
-
__name(getChain, "getChain");
|
|
2780
|
-
async function disconnectWallet2(wallet) {
|
|
2781
|
-
const disconnectFeature = wallet.features[features.StandardDisconnect];
|
|
2782
|
-
if (disconnectFeature) {
|
|
2783
|
-
await disconnectFeature.disconnect();
|
|
2784
|
-
}
|
|
2785
|
-
}
|
|
2786
|
-
__name(disconnectWallet2, "disconnectWallet");
|
|
2787
|
-
function createWalletStandardConnector(wallet, options = {}) {
|
|
2788
|
-
const metadata = {
|
|
2789
|
-
canAutoConnect: options.canAutoConnect ?? Boolean(wallet.features[features.StandardConnect]),
|
|
2790
|
-
icon: options.icon ?? wallet.icon,
|
|
2791
|
-
id: options.id ?? deriveConnectorId(wallet),
|
|
2792
|
-
kind: options.kind ?? "wallet-standard",
|
|
2793
|
-
name: options.name ?? wallet.name,
|
|
2794
|
-
ready: typeof window !== "undefined"
|
|
2795
|
-
};
|
|
2796
|
-
async function connect(connectionOptions = {}) {
|
|
2797
|
-
const connectFeature = wallet.features[features.StandardConnect];
|
|
2798
|
-
const shouldConnectSilently = Boolean(connectionOptions.autoConnect);
|
|
2799
|
-
let walletAccounts = wallet.accounts;
|
|
2800
|
-
if (connectFeature) {
|
|
2801
|
-
const { accounts } = await connectFeature.connect({
|
|
2802
|
-
silent: shouldConnectSilently || void 0
|
|
2803
|
-
});
|
|
2804
|
-
if (accounts.length) {
|
|
2805
|
-
walletAccounts = accounts;
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
const primaryAccount = getPrimaryAccount(walletAccounts);
|
|
2809
|
-
const sessionAccount = toSessionAccount(primaryAccount);
|
|
2810
|
-
const signMessageFeature = wallet.features[walletStandardFeatures.SolanaSignMessage];
|
|
2811
|
-
const signTransactionFeature = wallet.features[walletStandardFeatures.SolanaSignTransaction];
|
|
2812
|
-
const signAndSendFeature = wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction];
|
|
2813
|
-
const resolvedChain = options.defaultChain ?? getChain(primaryAccount);
|
|
2814
|
-
const signMessage = signMessageFeature ? async (message) => {
|
|
2815
|
-
const [output] = await signMessageFeature.signMessage({
|
|
2816
|
-
account: primaryAccount,
|
|
2817
|
-
message
|
|
2818
|
-
});
|
|
2819
|
-
return output.signature;
|
|
2820
|
-
} : void 0;
|
|
2821
|
-
const signTransaction = signTransactionFeature ? async (transaction) => {
|
|
2822
|
-
const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
|
|
2823
|
-
const request = resolvedChain ? {
|
|
2824
|
-
account: primaryAccount,
|
|
2825
|
-
chain: resolvedChain,
|
|
2826
|
-
transaction: wireBytes
|
|
2827
|
-
} : {
|
|
2828
|
-
account: primaryAccount,
|
|
2829
|
-
transaction: wireBytes
|
|
2830
|
-
};
|
|
2831
|
-
const [output] = await signTransactionFeature.signTransaction(request);
|
|
2832
|
-
return transactionDecoder.decode(output.signedTransaction);
|
|
2833
|
-
} : void 0;
|
|
2834
|
-
const sendTransaction2 = signAndSendFeature ? async (transaction, config) => {
|
|
2835
|
-
const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
|
|
2836
|
-
const chain = options.defaultChain ?? getChain(primaryAccount) ?? "solana:mainnet-beta";
|
|
2837
|
-
const [output] = await signAndSendFeature.signAndSendTransaction({
|
|
2838
|
-
account: primaryAccount,
|
|
2839
|
-
chain,
|
|
2840
|
-
options: {
|
|
2841
|
-
commitment: mapCommitment(config?.commitment)
|
|
2842
|
-
},
|
|
2843
|
-
transaction: wireBytes
|
|
2844
|
-
});
|
|
2845
|
-
return base58Decoder.decode(output.signature);
|
|
2846
|
-
} : void 0;
|
|
2847
|
-
async function disconnectSession() {
|
|
2848
|
-
await disconnectWallet2(wallet);
|
|
2849
|
-
}
|
|
2850
|
-
__name(disconnectSession, "disconnectSession");
|
|
2851
|
-
return {
|
|
2852
|
-
account: sessionAccount,
|
|
2853
|
-
connector: metadata,
|
|
2854
|
-
disconnect: disconnectSession,
|
|
2855
|
-
sendTransaction: sendTransaction2,
|
|
2856
|
-
signMessage,
|
|
2857
|
-
signTransaction
|
|
2858
|
-
};
|
|
2859
|
-
}
|
|
2860
|
-
__name(connect, "connect");
|
|
2861
|
-
async function disconnect() {
|
|
2862
|
-
await disconnectWallet2(wallet);
|
|
2863
|
-
}
|
|
2864
|
-
__name(disconnect, "disconnect");
|
|
2865
|
-
function isSupported() {
|
|
2866
|
-
return typeof window !== "undefined";
|
|
2867
|
-
}
|
|
2868
|
-
__name(isSupported, "isSupported");
|
|
2869
|
-
return {
|
|
2870
|
-
...metadata,
|
|
2871
|
-
connect,
|
|
2872
|
-
disconnect,
|
|
2873
|
-
isSupported
|
|
2874
|
-
};
|
|
2875
|
-
}
|
|
2876
|
-
__name(createWalletStandardConnector, "createWalletStandardConnector");
|
|
2877
|
-
function mapWalletToConnector(wallet, overrides) {
|
|
2878
|
-
return createWalletStandardConnector(wallet, overrides?.(wallet));
|
|
2879
|
-
}
|
|
2880
|
-
__name(mapWalletToConnector, "mapWalletToConnector");
|
|
2881
|
-
function getWalletStandardConnectors(options = {}) {
|
|
2882
|
-
const { get } = app.getWallets();
|
|
2883
|
-
const connectors = get().map((wallet) => mapWalletToConnector(wallet, options.overrides));
|
|
2884
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2885
|
-
return connectors.filter((connector) => {
|
|
2886
|
-
if (seen.has(connector.id)) {
|
|
2887
|
-
return false;
|
|
2888
|
-
}
|
|
2889
|
-
seen.add(connector.id);
|
|
2890
|
-
return true;
|
|
2891
|
-
});
|
|
2892
|
-
}
|
|
2893
|
-
__name(getWalletStandardConnectors, "getWalletStandardConnectors");
|
|
2894
|
-
function watchWalletStandardConnectors(onChange, options = {}) {
|
|
2895
|
-
const { get, on } = app.getWallets();
|
|
2896
|
-
const emit = /* @__PURE__ */ __name(() => {
|
|
2897
|
-
const connectors = get().map((wallet) => mapWalletToConnector(wallet, options.overrides));
|
|
2898
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2899
|
-
const deduplicated = connectors.filter((connector) => {
|
|
2900
|
-
if (seen.has(connector.id)) {
|
|
2901
|
-
return false;
|
|
2902
|
-
}
|
|
2903
|
-
seen.add(connector.id);
|
|
2904
|
-
return true;
|
|
2905
|
-
});
|
|
2906
|
-
onChange(deduplicated);
|
|
2907
|
-
}, "emit");
|
|
2908
|
-
emit();
|
|
2909
|
-
const offRegister = on("register", emit);
|
|
2910
|
-
const offUnregister = on("unregister", emit);
|
|
2911
|
-
return () => {
|
|
2912
|
-
offRegister();
|
|
2913
|
-
offUnregister();
|
|
2914
|
-
};
|
|
2915
|
-
}
|
|
2916
|
-
__name(watchWalletStandardConnectors, "watchWalletStandardConnectors");
|
|
2917
|
-
|
|
2918
|
-
// src/wallet/connectors.ts
|
|
2919
|
-
function autoDiscover(options = {}) {
|
|
2920
|
-
const { get } = app.getWallets();
|
|
2921
|
-
const wallets = get().filter((wallet) => options.filter ? options.filter(wallet) : true);
|
|
2922
|
-
const connectors = wallets.map((wallet) => createWalletStandardConnector(wallet, options.overrides?.(wallet)));
|
|
2923
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2924
|
-
return connectors.filter((connector) => {
|
|
2925
|
-
if (seen.has(connector.id)) return false;
|
|
2926
|
-
seen.add(connector.id);
|
|
2927
|
-
return true;
|
|
2928
|
-
});
|
|
2929
|
-
}
|
|
2930
|
-
__name(autoDiscover, "autoDiscover");
|
|
2931
|
-
function injected(options) {
|
|
2932
|
-
const connector = {
|
|
2933
|
-
canAutoConnect: true,
|
|
2934
|
-
id: "wallet-standard:injected",
|
|
2935
|
-
kind: "wallet-standard",
|
|
2936
|
-
name: "Injected Wallet",
|
|
2937
|
-
ready: typeof window !== "undefined",
|
|
2938
|
-
async connect() {
|
|
2939
|
-
const wallets = app.getWallets().get();
|
|
2940
|
-
const first = wallets.find((wallet) => features.StandardConnect in wallet.features);
|
|
2941
|
-
if (!first) {
|
|
2942
|
-
throw new Error("No Wallet Standard wallets available.");
|
|
2943
|
-
}
|
|
2944
|
-
return createWalletStandardConnector(first, options).connect();
|
|
2945
|
-
},
|
|
2946
|
-
async disconnect() {
|
|
2947
|
-
},
|
|
2948
|
-
isSupported() {
|
|
2949
|
-
return typeof window !== "undefined";
|
|
2950
|
-
}
|
|
2951
|
-
};
|
|
2952
|
-
return connector;
|
|
2953
|
-
}
|
|
2954
|
-
__name(injected, "injected");
|
|
2955
|
-
function filterByName(name) {
|
|
2956
|
-
const lower = name.toLowerCase();
|
|
2957
|
-
return (wallet) => wallet.name.toLowerCase().includes(lower);
|
|
2958
|
-
}
|
|
2959
|
-
__name(filterByName, "filterByName");
|
|
2960
|
-
function phantom(options) {
|
|
2961
|
-
return autoDiscover({
|
|
2962
|
-
filter: filterByName("phantom"),
|
|
2963
|
-
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:phantom" }), "overrides")
|
|
2964
|
-
});
|
|
2965
|
-
}
|
|
2966
|
-
__name(phantom, "phantom");
|
|
2967
|
-
function solflare(options) {
|
|
2968
|
-
return autoDiscover({
|
|
2969
|
-
filter: filterByName("solflare"),
|
|
2970
|
-
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:solflare" }), "overrides")
|
|
2971
|
-
});
|
|
2972
|
-
}
|
|
2973
|
-
__name(solflare, "solflare");
|
|
2974
|
-
function backpack(options) {
|
|
2975
|
-
return autoDiscover({
|
|
2976
|
-
filter: filterByName("backpack"),
|
|
2977
|
-
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:backpack" }), "overrides")
|
|
2978
|
-
});
|
|
2979
|
-
}
|
|
2980
|
-
__name(backpack, "backpack");
|
|
2981
3044
|
|
|
2982
3045
|
exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
|
|
2983
3046
|
exports.SIGNATURE_STATUS_TIMEOUT_MS = SIGNATURE_STATUS_TIMEOUT_MS;
|
|
@@ -2998,6 +3061,7 @@ exports.connectWallet = connectWallet;
|
|
|
2998
3061
|
exports.createAsyncState = createAsyncState;
|
|
2999
3062
|
exports.createClient = createClient;
|
|
3000
3063
|
exports.createClientStore = createClientStore;
|
|
3064
|
+
exports.createDefaultClient = createDefaultClient;
|
|
3001
3065
|
exports.createDefaultClientStore = createDefaultClientStore;
|
|
3002
3066
|
exports.createInitialAsyncState = createInitialAsyncState;
|
|
3003
3067
|
exports.createInitialClientState = createInitialClientState;
|
|
@@ -3013,6 +3077,7 @@ exports.createTransactionPoolController = createTransactionPoolController;
|
|
|
3013
3077
|
exports.createTransactionRecipe = createTransactionRecipe;
|
|
3014
3078
|
exports.createWalletRegistry = createWalletRegistry;
|
|
3015
3079
|
exports.createWalletStandardConnector = createWalletStandardConnector;
|
|
3080
|
+
exports.defaultWalletConnectors = defaultWalletConnectors;
|
|
3016
3081
|
exports.deriveConfirmationStatus = deriveConfirmationStatus;
|
|
3017
3082
|
exports.deserializeSolanaState = deserializeSolanaState;
|
|
3018
3083
|
exports.disconnectWallet = disconnectWallet;
|
|
@@ -3034,6 +3099,7 @@ exports.phantom = phantom;
|
|
|
3034
3099
|
exports.pow10 = pow10;
|
|
3035
3100
|
exports.prepareTransaction = prepareTransaction;
|
|
3036
3101
|
exports.requestAirdrop = requestAirdrop;
|
|
3102
|
+
exports.resolveClientConfig = resolveClientConfig;
|
|
3037
3103
|
exports.resolveCluster = resolveCluster;
|
|
3038
3104
|
exports.sendTransaction = sendTransaction;
|
|
3039
3105
|
exports.serializeSolanaState = serializeSolanaState;
|