@solana/client 0.2.3 → 1.0.0-rc.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.
@@ -283,6 +283,69 @@ function subscribeSolanaState(client, listener) {
283
283
  }
284
284
  __name(subscribeSolanaState, "subscribeSolanaState");
285
285
 
286
+ // src/utils/cluster.ts
287
+ function ensureHttpProtocol(endpoint) {
288
+ if (endpoint.startsWith("http://") || endpoint.startsWith("https://") || endpoint.startsWith("ws://") || endpoint.startsWith("wss://")) {
289
+ return endpoint;
290
+ }
291
+ return `https://${endpoint}`;
292
+ }
293
+ __name(ensureHttpProtocol, "ensureHttpProtocol");
294
+ var MONIKER_ENDPOINTS = {
295
+ devnet: {
296
+ endpoint: "https://api.devnet.solana.com",
297
+ websocketEndpoint: "wss://api.devnet.solana.com"
298
+ },
299
+ localhost: {
300
+ endpoint: "http://127.0.0.1:8899",
301
+ websocketEndpoint: "ws://127.0.0.1:8900"
302
+ },
303
+ localnet: {
304
+ endpoint: "http://127.0.0.1:8899",
305
+ websocketEndpoint: "ws://127.0.0.1:8900"
306
+ },
307
+ "mainnet-beta": {
308
+ endpoint: "https://api.mainnet-beta.solana.com",
309
+ websocketEndpoint: "wss://api.mainnet-beta.solana.com"
310
+ },
311
+ mainnet: {
312
+ endpoint: "https://api.mainnet-beta.solana.com",
313
+ websocketEndpoint: "wss://api.mainnet-beta.solana.com"
314
+ },
315
+ testnet: {
316
+ endpoint: "https://api.testnet.solana.com",
317
+ websocketEndpoint: "wss://api.testnet.solana.com"
318
+ }
319
+ };
320
+ function inferWebsocketEndpoint(endpoint) {
321
+ if (endpoint.startsWith("https://")) {
322
+ return endpoint.replace("https://", "wss://");
323
+ }
324
+ if (endpoint.startsWith("http://")) {
325
+ return endpoint.replace("http://", "ws://");
326
+ }
327
+ if (endpoint.startsWith("ws://") || endpoint.startsWith("wss://")) {
328
+ return endpoint;
329
+ }
330
+ return endpoint;
331
+ }
332
+ __name(inferWebsocketEndpoint, "inferWebsocketEndpoint");
333
+ function resolveCluster(config) {
334
+ const moniker = config.moniker ?? (config.endpoint ? "custom" : "devnet");
335
+ const mapped = moniker === "custom" ? void 0 : MONIKER_ENDPOINTS[moniker];
336
+ const endpoint = ensureHttpProtocol(config.endpoint ?? mapped?.endpoint);
337
+ const rawWebsocket = config.websocketEndpoint ? ensureHttpProtocol(config.websocketEndpoint) : void 0;
338
+ const websocketEndpoint = inferWebsocketEndpoint(
339
+ rawWebsocket ?? mapped?.websocketEndpoint ?? endpoint
340
+ );
341
+ return {
342
+ endpoint,
343
+ moniker,
344
+ websocketEndpoint
345
+ };
346
+ }
347
+ __name(resolveCluster, "resolveCluster");
348
+
286
349
  // src/wallet/registry.ts
287
350
  function createWalletRegistry(connectors) {
288
351
  const byId = /* @__PURE__ */ new Map();
@@ -2131,18 +2194,22 @@ __name(createWatchers, "createWatchers");
2131
2194
  // src/client/createClient.ts
2132
2195
  function createClient(config) {
2133
2196
  const hydratedConfig = config.initialState ? applySerializableState(config, config.initialState) : config;
2197
+ const resolvedCluster = resolveCluster({
2198
+ endpoint: hydratedConfig.rpc ?? hydratedConfig.endpoint,
2199
+ moniker: hydratedConfig.cluster,
2200
+ websocketEndpoint: hydratedConfig.websocket ?? hydratedConfig.websocketEndpoint
2201
+ });
2134
2202
  const commitment = hydratedConfig.commitment ?? "confirmed";
2135
- const websocketEndpoint = hydratedConfig.websocketEndpoint ?? hydratedConfig.endpoint;
2136
2203
  const initialState = createInitialClientState({
2137
2204
  commitment,
2138
- endpoint: hydratedConfig.endpoint,
2139
- websocketEndpoint
2205
+ endpoint: resolvedCluster.endpoint,
2206
+ websocketEndpoint: resolvedCluster.websocketEndpoint
2140
2207
  });
2141
2208
  const store = config.createStore ? config.createStore(initialState) : createClientStore(initialState);
2142
2209
  const rpcClient = hydratedConfig.rpcClient ?? createSolanaRpcClient({
2143
2210
  commitment,
2144
- endpoint: hydratedConfig.endpoint,
2145
- websocketEndpoint
2211
+ endpoint: resolvedCluster.endpoint,
2212
+ websocketEndpoint: resolvedCluster.websocketEndpoint
2146
2213
  });
2147
2214
  const runtime = {
2148
2215
  rpc: rpcClient.rpc,
@@ -2161,7 +2228,10 @@ function createClient(config) {
2161
2228
  },
2162
2229
  lastUpdatedAt: now()
2163
2230
  }));
2164
- actions.setCluster(hydratedConfig.endpoint, { commitment, websocketEndpoint }).catch(
2231
+ actions.setCluster(resolvedCluster.endpoint, {
2232
+ commitment,
2233
+ websocketEndpoint: resolvedCluster.websocketEndpoint
2234
+ }).catch(
2165
2235
  (error) => logger({
2166
2236
  data: formatError(error),
2167
2237
  level: "error",
@@ -2199,104 +2269,382 @@ function createClient(config) {
2199
2269
  };
2200
2270
  }
2201
2271
  __name(createClient, "createClient");
2202
-
2203
- // src/state/asyncState.ts
2204
- function createInitialAsyncState() {
2205
- return { status: "idle" };
2272
+ var base58Decoder = codecsStrings.getBase58Decoder();
2273
+ var transactionDecoder = transactions.getTransactionDecoder();
2274
+ var transactionEncoder = transactions.getTransactionEncoder();
2275
+ function deriveConnectorId(wallet) {
2276
+ const kebab = wallet.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
2277
+ return `wallet-standard:${kebab}`;
2206
2278
  }
2207
- __name(createInitialAsyncState, "createInitialAsyncState");
2208
- function createAsyncState(status, payload = {}) {
2209
- return {
2210
- data: payload.data,
2211
- error: payload.error,
2212
- status
2213
- };
2279
+ __name(deriveConnectorId, "deriveConnectorId");
2280
+ function getPrimaryAccount(accounts) {
2281
+ const primary = accounts[0];
2282
+ if (!primary) {
2283
+ throw new Error("Wallet returned no accounts.");
2284
+ }
2285
+ return primary;
2214
2286
  }
2215
- __name(createAsyncState, "createAsyncState");
2216
-
2217
- // src/controllers/solTransferController.ts
2218
- function ensureAuthority(input, resolveDefault) {
2219
- const authority = input.authority ?? resolveDefault?.();
2220
- if (!authority) {
2221
- throw new Error("Connect a wallet or supply an `authority` before sending SOL transfers.");
2287
+ __name(getPrimaryAccount, "getPrimaryAccount");
2288
+ function mapCommitment(commitment) {
2289
+ if (commitment === "processed" || commitment === "confirmed" || commitment === "finalized") {
2290
+ return commitment;
2222
2291
  }
2292
+ return void 0;
2293
+ }
2294
+ __name(mapCommitment, "mapCommitment");
2295
+ function toSessionAccount(walletAccount) {
2223
2296
  return {
2224
- ...input,
2225
- authority
2297
+ address: kit.address(walletAccount.address),
2298
+ label: walletAccount.label,
2299
+ publicKey: new Uint8Array(walletAccount.publicKey)
2226
2300
  };
2227
2301
  }
2228
- __name(ensureAuthority, "ensureAuthority");
2229
- function createSolTransferController(config) {
2230
- const listeners = /* @__PURE__ */ new Set();
2231
- const helper = config.helper;
2232
- const authorityProvider = config.authorityProvider;
2233
- let state = createInitialAsyncState();
2234
- function notify() {
2235
- for (const listener of listeners) {
2236
- listener();
2237
- }
2238
- }
2239
- __name(notify, "notify");
2240
- function setState(next) {
2241
- state = next;
2242
- notify();
2302
+ __name(toSessionAccount, "toSessionAccount");
2303
+ function getChain(account) {
2304
+ const [preferred] = account.chains ?? [];
2305
+ return preferred;
2306
+ }
2307
+ __name(getChain, "getChain");
2308
+ async function disconnectWallet2(wallet) {
2309
+ const disconnectFeature = wallet.features[features.StandardDisconnect];
2310
+ if (disconnectFeature) {
2311
+ await disconnectFeature.disconnect();
2243
2312
  }
2244
- __name(setState, "setState");
2245
- async function send(config2, options) {
2246
- const request = ensureAuthority(config2, authorityProvider);
2247
- setState(createAsyncState("loading"));
2248
- try {
2249
- const signature4 = await helper.sendTransfer(request, options);
2250
- setState(createAsyncState("success", { data: signature4 }));
2251
- return signature4;
2252
- } catch (error) {
2253
- setState(createAsyncState("error", { error }));
2254
- throw error;
2313
+ }
2314
+ __name(disconnectWallet2, "disconnectWallet");
2315
+ function createWalletStandardConnector(wallet, options = {}) {
2316
+ const metadata = {
2317
+ canAutoConnect: options.canAutoConnect ?? Boolean(wallet.features[features.StandardConnect]),
2318
+ icon: options.icon ?? wallet.icon,
2319
+ id: options.id ?? deriveConnectorId(wallet),
2320
+ kind: options.kind ?? "wallet-standard",
2321
+ name: options.name ?? wallet.name,
2322
+ ready: typeof window !== "undefined"
2323
+ };
2324
+ async function connect(connectionOptions = {}) {
2325
+ const connectFeature = wallet.features[features.StandardConnect];
2326
+ const shouldConnectSilently = Boolean(connectionOptions.autoConnect);
2327
+ let walletAccounts = wallet.accounts;
2328
+ if (connectFeature) {
2329
+ const { accounts } = await connectFeature.connect({
2330
+ silent: shouldConnectSilently || void 0
2331
+ });
2332
+ if (accounts.length) {
2333
+ walletAccounts = accounts;
2334
+ }
2255
2335
  }
2256
- }
2257
- __name(send, "send");
2258
- function subscribe(listener) {
2259
- listeners.add(listener);
2260
- return () => {
2261
- listeners.delete(listener);
2336
+ const primaryAccount = getPrimaryAccount(walletAccounts);
2337
+ const sessionAccount = toSessionAccount(primaryAccount);
2338
+ const signMessageFeature = wallet.features[walletStandardFeatures.SolanaSignMessage];
2339
+ const signTransactionFeature = wallet.features[walletStandardFeatures.SolanaSignTransaction];
2340
+ const signAndSendFeature = wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction];
2341
+ const resolvedChain = options.defaultChain ?? getChain(primaryAccount);
2342
+ const signMessage = signMessageFeature ? async (message) => {
2343
+ const [output] = await signMessageFeature.signMessage({
2344
+ account: primaryAccount,
2345
+ message
2346
+ });
2347
+ return output.signature;
2348
+ } : void 0;
2349
+ const signTransaction = signTransactionFeature ? async (transaction) => {
2350
+ const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
2351
+ const request = resolvedChain ? {
2352
+ account: primaryAccount,
2353
+ chain: resolvedChain,
2354
+ transaction: wireBytes
2355
+ } : {
2356
+ account: primaryAccount,
2357
+ transaction: wireBytes
2358
+ };
2359
+ const [output] = await signTransactionFeature.signTransaction(request);
2360
+ return transactionDecoder.decode(output.signedTransaction);
2361
+ } : void 0;
2362
+ const sendTransaction2 = signAndSendFeature ? async (transaction, config) => {
2363
+ const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
2364
+ const chain = options.defaultChain ?? getChain(primaryAccount) ?? "solana:mainnet-beta";
2365
+ const [output] = await signAndSendFeature.signAndSendTransaction({
2366
+ account: primaryAccount,
2367
+ chain,
2368
+ options: {
2369
+ commitment: mapCommitment(config?.commitment)
2370
+ },
2371
+ transaction: wireBytes
2372
+ });
2373
+ return base58Decoder.decode(output.signature);
2374
+ } : void 0;
2375
+ async function disconnectSession() {
2376
+ await disconnectWallet2(wallet);
2377
+ }
2378
+ __name(disconnectSession, "disconnectSession");
2379
+ return {
2380
+ account: sessionAccount,
2381
+ connector: metadata,
2382
+ disconnect: disconnectSession,
2383
+ sendTransaction: sendTransaction2,
2384
+ signMessage,
2385
+ signTransaction
2262
2386
  };
2263
2387
  }
2264
- __name(subscribe, "subscribe");
2265
- function reset() {
2266
- setState(createInitialAsyncState());
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.");
2388
+ __name(connect, "connect");
2389
+ async function disconnect() {
2390
+ await disconnectWallet2(wallet);
2284
2391
  }
2285
- const sourceOwner = input.sourceOwner ?? resolveSourceOwner?.();
2286
- if (!sourceOwner) {
2287
- throw new Error("Unable to resolve a source owner for the SPL token transfer.");
2392
+ __name(disconnect, "disconnect");
2393
+ function isSupported() {
2394
+ return typeof window !== "undefined";
2288
2395
  }
2396
+ __name(isSupported, "isSupported");
2289
2397
  return {
2290
- ...input,
2291
- authority,
2292
- sourceOwner
2398
+ ...metadata,
2399
+ connect,
2400
+ disconnect,
2401
+ isSupported
2293
2402
  };
2294
2403
  }
2295
- __name(ensureTransferConfig, "ensureTransferConfig");
2296
- function createSplTransferController(config) {
2297
- const helper = config.helper;
2298
- const authorityProvider = config.authorityProvider;
2299
- const sourceOwnerProvider = config.sourceOwnerProvider;
2404
+ __name(createWalletStandardConnector, "createWalletStandardConnector");
2405
+ function mapWalletToConnector(wallet, overrides) {
2406
+ return createWalletStandardConnector(wallet, overrides?.(wallet));
2407
+ }
2408
+ __name(mapWalletToConnector, "mapWalletToConnector");
2409
+ function getWalletStandardConnectors(options = {}) {
2410
+ const { get } = app.getWallets();
2411
+ const connectors = get().map((wallet) => mapWalletToConnector(wallet, options.overrides));
2412
+ const seen = /* @__PURE__ */ new Set();
2413
+ return connectors.filter((connector) => {
2414
+ if (seen.has(connector.id)) {
2415
+ return false;
2416
+ }
2417
+ seen.add(connector.id);
2418
+ return true;
2419
+ });
2420
+ }
2421
+ __name(getWalletStandardConnectors, "getWalletStandardConnectors");
2422
+ function watchWalletStandardConnectors(onChange, options = {}) {
2423
+ const { get, on } = app.getWallets();
2424
+ const emit = /* @__PURE__ */ __name(() => {
2425
+ const connectors = get().map((wallet) => mapWalletToConnector(wallet, options.overrides));
2426
+ const seen = /* @__PURE__ */ new Set();
2427
+ const deduplicated = connectors.filter((connector) => {
2428
+ if (seen.has(connector.id)) {
2429
+ return false;
2430
+ }
2431
+ seen.add(connector.id);
2432
+ return true;
2433
+ });
2434
+ onChange(deduplicated);
2435
+ }, "emit");
2436
+ emit();
2437
+ const offRegister = on("register", emit);
2438
+ const offUnregister = on("unregister", emit);
2439
+ return () => {
2440
+ offRegister();
2441
+ offUnregister();
2442
+ };
2443
+ }
2444
+ __name(watchWalletStandardConnectors, "watchWalletStandardConnectors");
2445
+
2446
+ // src/wallet/connectors.ts
2447
+ function autoDiscover(options = {}) {
2448
+ const { get } = app.getWallets();
2449
+ const wallets = get().filter((wallet) => options.filter ? options.filter(wallet) : true);
2450
+ const connectors = wallets.map((wallet) => createWalletStandardConnector(wallet, options.overrides?.(wallet)));
2451
+ const seen = /* @__PURE__ */ new Set();
2452
+ return connectors.filter((connector) => {
2453
+ if (seen.has(connector.id)) return false;
2454
+ seen.add(connector.id);
2455
+ return true;
2456
+ });
2457
+ }
2458
+ __name(autoDiscover, "autoDiscover");
2459
+ function injected(options) {
2460
+ const connector = {
2461
+ canAutoConnect: true,
2462
+ id: "wallet-standard:injected",
2463
+ kind: "wallet-standard",
2464
+ name: "Injected Wallet",
2465
+ ready: typeof window !== "undefined",
2466
+ async connect() {
2467
+ const wallets = app.getWallets().get();
2468
+ const first = wallets.find((wallet) => features.StandardConnect in wallet.features);
2469
+ if (!first) {
2470
+ throw new Error("No Wallet Standard wallets available.");
2471
+ }
2472
+ return createWalletStandardConnector(first, options).connect();
2473
+ },
2474
+ async disconnect() {
2475
+ },
2476
+ isSupported() {
2477
+ return typeof window !== "undefined";
2478
+ }
2479
+ };
2480
+ return connector;
2481
+ }
2482
+ __name(injected, "injected");
2483
+ function filterByName(name) {
2484
+ const lower = name.toLowerCase();
2485
+ return (wallet) => wallet.name.toLowerCase().includes(lower);
2486
+ }
2487
+ __name(filterByName, "filterByName");
2488
+ function phantom(options) {
2489
+ return autoDiscover({
2490
+ filter: filterByName("phantom"),
2491
+ overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:phantom" }), "overrides")
2492
+ });
2493
+ }
2494
+ __name(phantom, "phantom");
2495
+ function solflare(options) {
2496
+ return autoDiscover({
2497
+ filter: filterByName("solflare"),
2498
+ overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:solflare" }), "overrides")
2499
+ });
2500
+ }
2501
+ __name(solflare, "solflare");
2502
+ function backpack(options) {
2503
+ return autoDiscover({
2504
+ filter: filterByName("backpack"),
2505
+ overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:backpack" }), "overrides")
2506
+ });
2507
+ }
2508
+ __name(backpack, "backpack");
2509
+
2510
+ // src/client/defaultClient.ts
2511
+ function defaultWalletConnectors() {
2512
+ return [...phantom(), ...solflare(), ...backpack(), ...autoDiscover()];
2513
+ }
2514
+ __name(defaultWalletConnectors, "defaultWalletConnectors");
2515
+ function normalizeUrl(value) {
2516
+ if (!value) return void 0;
2517
+ const trimmed = value.trim();
2518
+ return trimmed.length ? trimmed : void 0;
2519
+ }
2520
+ __name(normalizeUrl, "normalizeUrl");
2521
+ function resolveClientConfig(config = {}) {
2522
+ const {
2523
+ cluster,
2524
+ endpoint: endpointOverride,
2525
+ rpc,
2526
+ websocket,
2527
+ websocketEndpoint,
2528
+ walletConnectors,
2529
+ ...passthrough
2530
+ } = config;
2531
+ const resolvedEndpoint = normalizeUrl(rpc) ?? normalizeUrl(endpointOverride) ?? normalizeUrl(config.endpoint);
2532
+ const resolvedCluster = resolveCluster({
2533
+ endpoint: resolvedEndpoint,
2534
+ moniker: cluster ?? void 0,
2535
+ websocketEndpoint: normalizeUrl(websocket ?? websocketEndpoint)
2536
+ });
2537
+ const resolvedConnectors = walletConnectors === void 0 || walletConnectors === "default" ? defaultWalletConnectors() : walletConnectors;
2538
+ return {
2539
+ ...passthrough,
2540
+ endpoint: resolvedCluster.endpoint,
2541
+ websocketEndpoint: resolvedCluster.websocketEndpoint,
2542
+ walletConnectors: resolvedConnectors
2543
+ };
2544
+ }
2545
+ __name(resolveClientConfig, "resolveClientConfig");
2546
+ function createDefaultClient(config = {}) {
2547
+ return createClient(resolveClientConfig(config));
2548
+ }
2549
+ __name(createDefaultClient, "createDefaultClient");
2550
+
2551
+ // src/state/asyncState.ts
2552
+ function createInitialAsyncState() {
2553
+ return { status: "idle" };
2554
+ }
2555
+ __name(createInitialAsyncState, "createInitialAsyncState");
2556
+ function createAsyncState(status, payload = {}) {
2557
+ return {
2558
+ data: payload.data,
2559
+ error: payload.error,
2560
+ status
2561
+ };
2562
+ }
2563
+ __name(createAsyncState, "createAsyncState");
2564
+
2565
+ // src/controllers/solTransferController.ts
2566
+ function ensureAuthority(input, resolveDefault) {
2567
+ const authority = input.authority ?? resolveDefault?.();
2568
+ if (!authority) {
2569
+ throw new Error("Connect a wallet or supply an `authority` before sending SOL transfers.");
2570
+ }
2571
+ return {
2572
+ ...input,
2573
+ authority
2574
+ };
2575
+ }
2576
+ __name(ensureAuthority, "ensureAuthority");
2577
+ function createSolTransferController(config) {
2578
+ const listeners = /* @__PURE__ */ new Set();
2579
+ const helper = config.helper;
2580
+ const authorityProvider = config.authorityProvider;
2581
+ let state = createInitialAsyncState();
2582
+ function notify() {
2583
+ for (const listener of listeners) {
2584
+ listener();
2585
+ }
2586
+ }
2587
+ __name(notify, "notify");
2588
+ function setState(next) {
2589
+ state = next;
2590
+ notify();
2591
+ }
2592
+ __name(setState, "setState");
2593
+ async function send(config2, options) {
2594
+ const request = ensureAuthority(config2, authorityProvider);
2595
+ setState(createAsyncState("loading"));
2596
+ try {
2597
+ const signature4 = await helper.sendTransfer(request, options);
2598
+ setState(createAsyncState("success", { data: signature4 }));
2599
+ return signature4;
2600
+ } catch (error) {
2601
+ setState(createAsyncState("error", { error }));
2602
+ throw error;
2603
+ }
2604
+ }
2605
+ __name(send, "send");
2606
+ function subscribe(listener) {
2607
+ listeners.add(listener);
2608
+ return () => {
2609
+ listeners.delete(listener);
2610
+ };
2611
+ }
2612
+ __name(subscribe, "subscribe");
2613
+ function reset() {
2614
+ setState(createInitialAsyncState());
2615
+ }
2616
+ __name(reset, "reset");
2617
+ return {
2618
+ getHelper: /* @__PURE__ */ __name(() => helper, "getHelper"),
2619
+ getState: /* @__PURE__ */ __name(() => state, "getState"),
2620
+ reset,
2621
+ send,
2622
+ subscribe
2623
+ };
2624
+ }
2625
+ __name(createSolTransferController, "createSolTransferController");
2626
+
2627
+ // src/controllers/splTransferController.ts
2628
+ function ensureTransferConfig(input, resolveAuthority, resolveSourceOwner) {
2629
+ const authority = input.authority ?? resolveAuthority?.();
2630
+ if (!authority) {
2631
+ throw new Error("Connect a wallet or supply an `authority` before sending SPL tokens.");
2632
+ }
2633
+ const sourceOwner = input.sourceOwner ?? resolveSourceOwner?.();
2634
+ if (!sourceOwner) {
2635
+ throw new Error("Unable to resolve a source owner for the SPL token transfer.");
2636
+ }
2637
+ return {
2638
+ ...input,
2639
+ authority,
2640
+ sourceOwner
2641
+ };
2642
+ }
2643
+ __name(ensureTransferConfig, "ensureTransferConfig");
2644
+ function createSplTransferController(config) {
2645
+ const helper = config.helper;
2646
+ const authorityProvider = config.authorityProvider;
2647
+ const sourceOwnerProvider = config.sourceOwnerProvider;
2300
2648
  const listeners = /* @__PURE__ */ new Set();
2301
2649
  let state = createInitialAsyncState();
2302
2650
  function notify() {
@@ -2677,56 +3025,6 @@ function toAddressString(addressLike) {
2677
3025
  }
2678
3026
  __name(toAddressString, "toAddressString");
2679
3027
 
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
3028
  // src/utils/stableStringify.ts
2731
3029
  function stableStringify(value) {
2732
3030
  const result = JSON.stringify(value, (_key, candidate) => {
@@ -2741,243 +3039,6 @@ function stableStringify(value) {
2741
3039
  return result ?? "undefined";
2742
3040
  }
2743
3041
  __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
3042
 
2982
3043
  exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
2983
3044
  exports.SIGNATURE_STATUS_TIMEOUT_MS = SIGNATURE_STATUS_TIMEOUT_MS;
@@ -2998,6 +3059,7 @@ exports.connectWallet = connectWallet;
2998
3059
  exports.createAsyncState = createAsyncState;
2999
3060
  exports.createClient = createClient;
3000
3061
  exports.createClientStore = createClientStore;
3062
+ exports.createDefaultClient = createDefaultClient;
3001
3063
  exports.createDefaultClientStore = createDefaultClientStore;
3002
3064
  exports.createInitialAsyncState = createInitialAsyncState;
3003
3065
  exports.createInitialClientState = createInitialClientState;
@@ -3013,6 +3075,7 @@ exports.createTransactionPoolController = createTransactionPoolController;
3013
3075
  exports.createTransactionRecipe = createTransactionRecipe;
3014
3076
  exports.createWalletRegistry = createWalletRegistry;
3015
3077
  exports.createWalletStandardConnector = createWalletStandardConnector;
3078
+ exports.defaultWalletConnectors = defaultWalletConnectors;
3016
3079
  exports.deriveConfirmationStatus = deriveConfirmationStatus;
3017
3080
  exports.deserializeSolanaState = deserializeSolanaState;
3018
3081
  exports.disconnectWallet = disconnectWallet;
@@ -3034,6 +3097,7 @@ exports.phantom = phantom;
3034
3097
  exports.pow10 = pow10;
3035
3098
  exports.prepareTransaction = prepareTransaction;
3036
3099
  exports.requestAirdrop = requestAirdrop;
3100
+ exports.resolveClientConfig = resolveClientConfig;
3037
3101
  exports.resolveCluster = resolveCluster;
3038
3102
  exports.sendTransaction = sendTransaction;
3039
3103
  exports.serializeSolanaState = serializeSolanaState;