@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.native.mjs
CHANGED
|
@@ -246,6 +246,7 @@ __name(deserializeSolanaState, "deserializeSolanaState");
|
|
|
246
246
|
function getSerializableStateSnapshot(client) {
|
|
247
247
|
const state = client.store.getState();
|
|
248
248
|
const wallet = state.wallet;
|
|
249
|
+
const autoConnectPreference = wallet.autoConnect;
|
|
249
250
|
let lastConnectorId = null;
|
|
250
251
|
let lastPublicKey = null;
|
|
251
252
|
if ("connectorId" in wallet) {
|
|
@@ -255,7 +256,7 @@ function getSerializableStateSnapshot(client) {
|
|
|
255
256
|
}
|
|
256
257
|
}
|
|
257
258
|
return {
|
|
258
|
-
autoconnect: Boolean(lastConnectorId),
|
|
259
|
+
autoconnect: autoConnectPreference ?? Boolean(lastConnectorId),
|
|
259
260
|
commitment: state.cluster.commitment,
|
|
260
261
|
endpoint: state.cluster.endpoint,
|
|
261
262
|
lastConnectorId,
|
|
@@ -281,6 +282,69 @@ function subscribeSolanaState(client, listener) {
|
|
|
281
282
|
}
|
|
282
283
|
__name(subscribeSolanaState, "subscribeSolanaState");
|
|
283
284
|
|
|
285
|
+
// src/utils/cluster.ts
|
|
286
|
+
function ensureHttpProtocol(endpoint) {
|
|
287
|
+
if (endpoint.startsWith("http://") || endpoint.startsWith("https://") || endpoint.startsWith("ws://") || endpoint.startsWith("wss://")) {
|
|
288
|
+
return endpoint;
|
|
289
|
+
}
|
|
290
|
+
return `https://${endpoint}`;
|
|
291
|
+
}
|
|
292
|
+
__name(ensureHttpProtocol, "ensureHttpProtocol");
|
|
293
|
+
var MONIKER_ENDPOINTS = {
|
|
294
|
+
devnet: {
|
|
295
|
+
endpoint: "https://api.devnet.solana.com",
|
|
296
|
+
websocketEndpoint: "wss://api.devnet.solana.com"
|
|
297
|
+
},
|
|
298
|
+
localhost: {
|
|
299
|
+
endpoint: "http://127.0.0.1:8899",
|
|
300
|
+
websocketEndpoint: "ws://127.0.0.1:8900"
|
|
301
|
+
},
|
|
302
|
+
localnet: {
|
|
303
|
+
endpoint: "http://127.0.0.1:8899",
|
|
304
|
+
websocketEndpoint: "ws://127.0.0.1:8900"
|
|
305
|
+
},
|
|
306
|
+
"mainnet-beta": {
|
|
307
|
+
endpoint: "https://api.mainnet-beta.solana.com",
|
|
308
|
+
websocketEndpoint: "wss://api.mainnet-beta.solana.com"
|
|
309
|
+
},
|
|
310
|
+
mainnet: {
|
|
311
|
+
endpoint: "https://api.mainnet-beta.solana.com",
|
|
312
|
+
websocketEndpoint: "wss://api.mainnet-beta.solana.com"
|
|
313
|
+
},
|
|
314
|
+
testnet: {
|
|
315
|
+
endpoint: "https://api.testnet.solana.com",
|
|
316
|
+
websocketEndpoint: "wss://api.testnet.solana.com"
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
function inferWebsocketEndpoint(endpoint) {
|
|
320
|
+
if (endpoint.startsWith("https://")) {
|
|
321
|
+
return endpoint.replace("https://", "wss://");
|
|
322
|
+
}
|
|
323
|
+
if (endpoint.startsWith("http://")) {
|
|
324
|
+
return endpoint.replace("http://", "ws://");
|
|
325
|
+
}
|
|
326
|
+
if (endpoint.startsWith("ws://") || endpoint.startsWith("wss://")) {
|
|
327
|
+
return endpoint;
|
|
328
|
+
}
|
|
329
|
+
return endpoint;
|
|
330
|
+
}
|
|
331
|
+
__name(inferWebsocketEndpoint, "inferWebsocketEndpoint");
|
|
332
|
+
function resolveCluster(config) {
|
|
333
|
+
const moniker = config.moniker ?? (config.endpoint ? "custom" : "devnet");
|
|
334
|
+
const mapped = moniker === "custom" ? void 0 : MONIKER_ENDPOINTS[moniker];
|
|
335
|
+
const endpoint = ensureHttpProtocol(config.endpoint ?? mapped?.endpoint);
|
|
336
|
+
const rawWebsocket = config.websocketEndpoint ? ensureHttpProtocol(config.websocketEndpoint) : void 0;
|
|
337
|
+
const websocketEndpoint = inferWebsocketEndpoint(
|
|
338
|
+
rawWebsocket ?? mapped?.websocketEndpoint ?? endpoint
|
|
339
|
+
);
|
|
340
|
+
return {
|
|
341
|
+
endpoint,
|
|
342
|
+
moniker,
|
|
343
|
+
websocketEndpoint
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
__name(resolveCluster, "resolveCluster");
|
|
347
|
+
|
|
284
348
|
// src/wallet/registry.ts
|
|
285
349
|
function createWalletRegistry(connectors) {
|
|
286
350
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -392,17 +456,18 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
392
456
|
if (!connector.isSupported()) {
|
|
393
457
|
throw new Error(`Wallet connector "${connectorId}" is not supported in this environment.`);
|
|
394
458
|
}
|
|
459
|
+
const autoConnectPreference = options.autoConnect ?? true;
|
|
395
460
|
store.setState((state) => ({
|
|
396
461
|
...state,
|
|
397
462
|
lastUpdatedAt: now(),
|
|
398
|
-
wallet: { connectorId, status: "connecting" }
|
|
463
|
+
wallet: { autoConnect: autoConnectPreference, connectorId, status: "connecting" }
|
|
399
464
|
}));
|
|
400
465
|
try {
|
|
401
466
|
const session = await connector.connect(options);
|
|
402
467
|
store.setState((state) => ({
|
|
403
468
|
...state,
|
|
404
469
|
lastUpdatedAt: now(),
|
|
405
|
-
wallet: { connectorId, session, status: "connected" }
|
|
470
|
+
wallet: { autoConnect: autoConnectPreference, connectorId, session, status: "connected" }
|
|
406
471
|
}));
|
|
407
472
|
logger({
|
|
408
473
|
data: { address: session.account.address.toString(), connectorId },
|
|
@@ -413,7 +478,7 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
413
478
|
store.setState((state) => ({
|
|
414
479
|
...state,
|
|
415
480
|
lastUpdatedAt: now(),
|
|
416
|
-
wallet: { connectorId, error, status: "error" }
|
|
481
|
+
wallet: { autoConnect: autoConnectPreference, connectorId, error, status: "error" }
|
|
417
482
|
}));
|
|
418
483
|
logger({
|
|
419
484
|
data: { connectorId, ...formatError(error) },
|
|
@@ -2129,18 +2194,22 @@ __name(createWatchers, "createWatchers");
|
|
|
2129
2194
|
// src/client/createClient.ts
|
|
2130
2195
|
function createClient(config) {
|
|
2131
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
|
+
});
|
|
2132
2202
|
const commitment = hydratedConfig.commitment ?? "confirmed";
|
|
2133
|
-
const websocketEndpoint = hydratedConfig.websocketEndpoint ?? hydratedConfig.endpoint;
|
|
2134
2203
|
const initialState = createInitialClientState({
|
|
2135
2204
|
commitment,
|
|
2136
|
-
endpoint:
|
|
2137
|
-
websocketEndpoint
|
|
2205
|
+
endpoint: resolvedCluster.endpoint,
|
|
2206
|
+
websocketEndpoint: resolvedCluster.websocketEndpoint
|
|
2138
2207
|
});
|
|
2139
2208
|
const store = config.createStore ? config.createStore(initialState) : createClientStore(initialState);
|
|
2140
2209
|
const rpcClient = hydratedConfig.rpcClient ?? createSolanaRpcClient({
|
|
2141
2210
|
commitment,
|
|
2142
|
-
endpoint:
|
|
2143
|
-
websocketEndpoint
|
|
2211
|
+
endpoint: resolvedCluster.endpoint,
|
|
2212
|
+
websocketEndpoint: resolvedCluster.websocketEndpoint
|
|
2144
2213
|
});
|
|
2145
2214
|
const runtime = {
|
|
2146
2215
|
rpc: rpcClient.rpc,
|
|
@@ -2159,7 +2228,10 @@ function createClient(config) {
|
|
|
2159
2228
|
},
|
|
2160
2229
|
lastUpdatedAt: now()
|
|
2161
2230
|
}));
|
|
2162
|
-
actions.setCluster(
|
|
2231
|
+
actions.setCluster(resolvedCluster.endpoint, {
|
|
2232
|
+
commitment,
|
|
2233
|
+
websocketEndpoint: resolvedCluster.websocketEndpoint
|
|
2234
|
+
}).catch(
|
|
2163
2235
|
(error) => logger({
|
|
2164
2236
|
data: formatError(error),
|
|
2165
2237
|
level: "error",
|
|
@@ -2197,104 +2269,382 @@ function createClient(config) {
|
|
|
2197
2269
|
};
|
|
2198
2270
|
}
|
|
2199
2271
|
__name(createClient, "createClient");
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2272
|
+
var base58Decoder = getBase58Decoder();
|
|
2273
|
+
var transactionDecoder = getTransactionDecoder();
|
|
2274
|
+
var transactionEncoder = getTransactionEncoder();
|
|
2275
|
+
function deriveConnectorId(wallet) {
|
|
2276
|
+
const kebab = wallet.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
2277
|
+
return `wallet-standard:${kebab}`;
|
|
2204
2278
|
}
|
|
2205
|
-
__name(
|
|
2206
|
-
function
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
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;
|
|
2212
2286
|
}
|
|
2213
|
-
__name(
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
const authority = input.authority ?? resolveDefault?.();
|
|
2218
|
-
if (!authority) {
|
|
2219
|
-
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;
|
|
2220
2291
|
}
|
|
2292
|
+
return void 0;
|
|
2293
|
+
}
|
|
2294
|
+
__name(mapCommitment, "mapCommitment");
|
|
2295
|
+
function toSessionAccount(walletAccount) {
|
|
2221
2296
|
return {
|
|
2222
|
-
|
|
2223
|
-
|
|
2297
|
+
address: address(walletAccount.address),
|
|
2298
|
+
label: walletAccount.label,
|
|
2299
|
+
publicKey: new Uint8Array(walletAccount.publicKey)
|
|
2224
2300
|
};
|
|
2225
2301
|
}
|
|
2226
|
-
__name(
|
|
2227
|
-
function
|
|
2228
|
-
const
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
}
|
|
2237
|
-
__name(notify, "notify");
|
|
2238
|
-
function setState(next) {
|
|
2239
|
-
state = next;
|
|
2240
|
-
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[StandardDisconnect];
|
|
2310
|
+
if (disconnectFeature) {
|
|
2311
|
+
await disconnectFeature.disconnect();
|
|
2241
2312
|
}
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2313
|
+
}
|
|
2314
|
+
__name(disconnectWallet2, "disconnectWallet");
|
|
2315
|
+
function createWalletStandardConnector(wallet, options = {}) {
|
|
2316
|
+
const metadata = {
|
|
2317
|
+
canAutoConnect: options.canAutoConnect ?? Boolean(wallet.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[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
|
+
}
|
|
2253
2335
|
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2336
|
+
const primaryAccount = getPrimaryAccount(walletAccounts);
|
|
2337
|
+
const sessionAccount = toSessionAccount(primaryAccount);
|
|
2338
|
+
const signMessageFeature = wallet.features[SolanaSignMessage];
|
|
2339
|
+
const signTransactionFeature = wallet.features[SolanaSignTransaction];
|
|
2340
|
+
const signAndSendFeature = wallet.features[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
|
|
2260
2386
|
};
|
|
2261
2387
|
}
|
|
2262
|
-
__name(
|
|
2263
|
-
function
|
|
2264
|
-
|
|
2265
|
-
}
|
|
2266
|
-
__name(reset, "reset");
|
|
2267
|
-
return {
|
|
2268
|
-
getHelper: /* @__PURE__ */ __name(() => helper, "getHelper"),
|
|
2269
|
-
getState: /* @__PURE__ */ __name(() => state, "getState"),
|
|
2270
|
-
reset,
|
|
2271
|
-
send,
|
|
2272
|
-
subscribe
|
|
2273
|
-
};
|
|
2274
|
-
}
|
|
2275
|
-
__name(createSolTransferController, "createSolTransferController");
|
|
2276
|
-
|
|
2277
|
-
// src/controllers/splTransferController.ts
|
|
2278
|
-
function ensureTransferConfig(input, resolveAuthority, resolveSourceOwner) {
|
|
2279
|
-
const authority = input.authority ?? resolveAuthority?.();
|
|
2280
|
-
if (!authority) {
|
|
2281
|
-
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);
|
|
2282
2391
|
}
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2392
|
+
__name(disconnect, "disconnect");
|
|
2393
|
+
function isSupported() {
|
|
2394
|
+
return typeof window !== "undefined";
|
|
2286
2395
|
}
|
|
2396
|
+
__name(isSupported, "isSupported");
|
|
2287
2397
|
return {
|
|
2288
|
-
...
|
|
2289
|
-
|
|
2290
|
-
|
|
2398
|
+
...metadata,
|
|
2399
|
+
connect,
|
|
2400
|
+
disconnect,
|
|
2401
|
+
isSupported
|
|
2291
2402
|
};
|
|
2292
2403
|
}
|
|
2293
|
-
__name(
|
|
2294
|
-
function
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
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 } = 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 } = 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 } = 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 = getWallets().get();
|
|
2468
|
+
const first = wallets.find((wallet) => 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;
|
|
2298
2648
|
const listeners = /* @__PURE__ */ new Set();
|
|
2299
2649
|
let state = createInitialAsyncState();
|
|
2300
2650
|
function notify() {
|
|
@@ -2675,56 +3025,6 @@ function toAddressString(addressLike) {
|
|
|
2675
3025
|
}
|
|
2676
3026
|
__name(toAddressString, "toAddressString");
|
|
2677
3027
|
|
|
2678
|
-
// src/utils/cluster.ts
|
|
2679
|
-
var MONIKER_ENDPOINTS = {
|
|
2680
|
-
devnet: {
|
|
2681
|
-
endpoint: "https://api.devnet.solana.com",
|
|
2682
|
-
websocketEndpoint: "wss://api.devnet.solana.com"
|
|
2683
|
-
},
|
|
2684
|
-
localhost: {
|
|
2685
|
-
endpoint: "http://127.0.0.1:8899",
|
|
2686
|
-
websocketEndpoint: "ws://127.0.0.1:8900"
|
|
2687
|
-
},
|
|
2688
|
-
localnet: {
|
|
2689
|
-
endpoint: "http://127.0.0.1:8899",
|
|
2690
|
-
websocketEndpoint: "ws://127.0.0.1:8900"
|
|
2691
|
-
},
|
|
2692
|
-
"mainnet-beta": {
|
|
2693
|
-
endpoint: "https://api.mainnet-beta.solana.com",
|
|
2694
|
-
websocketEndpoint: "wss://api.mainnet-beta.solana.com"
|
|
2695
|
-
},
|
|
2696
|
-
mainnet: {
|
|
2697
|
-
endpoint: "https://api.mainnet-beta.solana.com",
|
|
2698
|
-
websocketEndpoint: "wss://api.mainnet-beta.solana.com"
|
|
2699
|
-
},
|
|
2700
|
-
testnet: {
|
|
2701
|
-
endpoint: "https://api.testnet.solana.com",
|
|
2702
|
-
websocketEndpoint: "wss://api.testnet.solana.com"
|
|
2703
|
-
}
|
|
2704
|
-
};
|
|
2705
|
-
function inferWebsocketEndpoint(endpoint) {
|
|
2706
|
-
if (endpoint.startsWith("https://")) {
|
|
2707
|
-
return endpoint.replace("https://", "wss://");
|
|
2708
|
-
}
|
|
2709
|
-
if (endpoint.startsWith("http://")) {
|
|
2710
|
-
return endpoint.replace("http://", "ws://");
|
|
2711
|
-
}
|
|
2712
|
-
return endpoint;
|
|
2713
|
-
}
|
|
2714
|
-
__name(inferWebsocketEndpoint, "inferWebsocketEndpoint");
|
|
2715
|
-
function resolveCluster(config) {
|
|
2716
|
-
const moniker = config.moniker ?? (config.endpoint ? "custom" : "devnet");
|
|
2717
|
-
const mapped = moniker === "custom" ? void 0 : MONIKER_ENDPOINTS[moniker];
|
|
2718
|
-
const endpoint = config.endpoint ?? mapped?.endpoint;
|
|
2719
|
-
const websocketEndpoint = config.websocketEndpoint ?? mapped?.websocketEndpoint ?? inferWebsocketEndpoint(endpoint);
|
|
2720
|
-
return {
|
|
2721
|
-
endpoint,
|
|
2722
|
-
moniker,
|
|
2723
|
-
websocketEndpoint
|
|
2724
|
-
};
|
|
2725
|
-
}
|
|
2726
|
-
__name(resolveCluster, "resolveCluster");
|
|
2727
|
-
|
|
2728
3028
|
// src/utils/stableStringify.ts
|
|
2729
3029
|
function stableStringify(value) {
|
|
2730
3030
|
const result = JSON.stringify(value, (_key, candidate) => {
|
|
@@ -2739,244 +3039,7 @@ function stableStringify(value) {
|
|
|
2739
3039
|
return result ?? "undefined";
|
|
2740
3040
|
}
|
|
2741
3041
|
__name(stableStringify, "stableStringify");
|
|
2742
|
-
var base58Decoder = getBase58Decoder();
|
|
2743
|
-
var transactionDecoder = getTransactionDecoder();
|
|
2744
|
-
var transactionEncoder = getTransactionEncoder();
|
|
2745
|
-
function deriveConnectorId(wallet) {
|
|
2746
|
-
const kebab = wallet.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
2747
|
-
return `wallet-standard:${kebab}`;
|
|
2748
|
-
}
|
|
2749
|
-
__name(deriveConnectorId, "deriveConnectorId");
|
|
2750
|
-
function getPrimaryAccount(accounts) {
|
|
2751
|
-
const primary = accounts[0];
|
|
2752
|
-
if (!primary) {
|
|
2753
|
-
throw new Error("Wallet returned no accounts.");
|
|
2754
|
-
}
|
|
2755
|
-
return primary;
|
|
2756
|
-
}
|
|
2757
|
-
__name(getPrimaryAccount, "getPrimaryAccount");
|
|
2758
|
-
function mapCommitment(commitment) {
|
|
2759
|
-
if (commitment === "processed" || commitment === "confirmed" || commitment === "finalized") {
|
|
2760
|
-
return commitment;
|
|
2761
|
-
}
|
|
2762
|
-
return void 0;
|
|
2763
|
-
}
|
|
2764
|
-
__name(mapCommitment, "mapCommitment");
|
|
2765
|
-
function toSessionAccount(walletAccount) {
|
|
2766
|
-
return {
|
|
2767
|
-
address: address(walletAccount.address),
|
|
2768
|
-
label: walletAccount.label,
|
|
2769
|
-
publicKey: new Uint8Array(walletAccount.publicKey)
|
|
2770
|
-
};
|
|
2771
|
-
}
|
|
2772
|
-
__name(toSessionAccount, "toSessionAccount");
|
|
2773
|
-
function getChain(account) {
|
|
2774
|
-
const [preferred] = account.chains ?? [];
|
|
2775
|
-
return preferred;
|
|
2776
|
-
}
|
|
2777
|
-
__name(getChain, "getChain");
|
|
2778
|
-
async function disconnectWallet2(wallet) {
|
|
2779
|
-
const disconnectFeature = wallet.features[StandardDisconnect];
|
|
2780
|
-
if (disconnectFeature) {
|
|
2781
|
-
await disconnectFeature.disconnect();
|
|
2782
|
-
}
|
|
2783
|
-
}
|
|
2784
|
-
__name(disconnectWallet2, "disconnectWallet");
|
|
2785
|
-
function createWalletStandardConnector(wallet, options = {}) {
|
|
2786
|
-
const metadata = {
|
|
2787
|
-
canAutoConnect: options.canAutoConnect ?? Boolean(wallet.features[StandardConnect]),
|
|
2788
|
-
icon: options.icon ?? wallet.icon,
|
|
2789
|
-
id: options.id ?? deriveConnectorId(wallet),
|
|
2790
|
-
kind: options.kind ?? "wallet-standard",
|
|
2791
|
-
name: options.name ?? wallet.name,
|
|
2792
|
-
ready: typeof window !== "undefined"
|
|
2793
|
-
};
|
|
2794
|
-
async function connect(connectionOptions = {}) {
|
|
2795
|
-
const connectFeature = wallet.features[StandardConnect];
|
|
2796
|
-
const shouldConnectSilently = Boolean(connectionOptions.autoConnect);
|
|
2797
|
-
let walletAccounts = wallet.accounts;
|
|
2798
|
-
if (connectFeature) {
|
|
2799
|
-
const { accounts } = await connectFeature.connect({
|
|
2800
|
-
silent: shouldConnectSilently || void 0
|
|
2801
|
-
});
|
|
2802
|
-
if (accounts.length) {
|
|
2803
|
-
walletAccounts = accounts;
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2806
|
-
const primaryAccount = getPrimaryAccount(walletAccounts);
|
|
2807
|
-
const sessionAccount = toSessionAccount(primaryAccount);
|
|
2808
|
-
const signMessageFeature = wallet.features[SolanaSignMessage];
|
|
2809
|
-
const signTransactionFeature = wallet.features[SolanaSignTransaction];
|
|
2810
|
-
const signAndSendFeature = wallet.features[SolanaSignAndSendTransaction];
|
|
2811
|
-
const resolvedChain = options.defaultChain ?? getChain(primaryAccount);
|
|
2812
|
-
const signMessage = signMessageFeature ? async (message) => {
|
|
2813
|
-
const [output] = await signMessageFeature.signMessage({
|
|
2814
|
-
account: primaryAccount,
|
|
2815
|
-
message
|
|
2816
|
-
});
|
|
2817
|
-
return output.signature;
|
|
2818
|
-
} : void 0;
|
|
2819
|
-
const signTransaction = signTransactionFeature ? async (transaction) => {
|
|
2820
|
-
const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
|
|
2821
|
-
const request = resolvedChain ? {
|
|
2822
|
-
account: primaryAccount,
|
|
2823
|
-
chain: resolvedChain,
|
|
2824
|
-
transaction: wireBytes
|
|
2825
|
-
} : {
|
|
2826
|
-
account: primaryAccount,
|
|
2827
|
-
transaction: wireBytes
|
|
2828
|
-
};
|
|
2829
|
-
const [output] = await signTransactionFeature.signTransaction(request);
|
|
2830
|
-
return transactionDecoder.decode(output.signedTransaction);
|
|
2831
|
-
} : void 0;
|
|
2832
|
-
const sendTransaction2 = signAndSendFeature ? async (transaction, config) => {
|
|
2833
|
-
const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
|
|
2834
|
-
const chain = options.defaultChain ?? getChain(primaryAccount) ?? "solana:mainnet-beta";
|
|
2835
|
-
const [output] = await signAndSendFeature.signAndSendTransaction({
|
|
2836
|
-
account: primaryAccount,
|
|
2837
|
-
chain,
|
|
2838
|
-
options: {
|
|
2839
|
-
commitment: mapCommitment(config?.commitment)
|
|
2840
|
-
},
|
|
2841
|
-
transaction: wireBytes
|
|
2842
|
-
});
|
|
2843
|
-
return base58Decoder.decode(output.signature);
|
|
2844
|
-
} : void 0;
|
|
2845
|
-
async function disconnectSession() {
|
|
2846
|
-
await disconnectWallet2(wallet);
|
|
2847
|
-
}
|
|
2848
|
-
__name(disconnectSession, "disconnectSession");
|
|
2849
|
-
return {
|
|
2850
|
-
account: sessionAccount,
|
|
2851
|
-
connector: metadata,
|
|
2852
|
-
disconnect: disconnectSession,
|
|
2853
|
-
sendTransaction: sendTransaction2,
|
|
2854
|
-
signMessage,
|
|
2855
|
-
signTransaction
|
|
2856
|
-
};
|
|
2857
|
-
}
|
|
2858
|
-
__name(connect, "connect");
|
|
2859
|
-
async function disconnect() {
|
|
2860
|
-
await disconnectWallet2(wallet);
|
|
2861
|
-
}
|
|
2862
|
-
__name(disconnect, "disconnect");
|
|
2863
|
-
function isSupported() {
|
|
2864
|
-
return typeof window !== "undefined";
|
|
2865
|
-
}
|
|
2866
|
-
__name(isSupported, "isSupported");
|
|
2867
|
-
return {
|
|
2868
|
-
...metadata,
|
|
2869
|
-
connect,
|
|
2870
|
-
disconnect,
|
|
2871
|
-
isSupported
|
|
2872
|
-
};
|
|
2873
|
-
}
|
|
2874
|
-
__name(createWalletStandardConnector, "createWalletStandardConnector");
|
|
2875
|
-
function mapWalletToConnector(wallet, overrides) {
|
|
2876
|
-
return createWalletStandardConnector(wallet, overrides?.(wallet));
|
|
2877
|
-
}
|
|
2878
|
-
__name(mapWalletToConnector, "mapWalletToConnector");
|
|
2879
|
-
function getWalletStandardConnectors(options = {}) {
|
|
2880
|
-
const { get } = getWallets();
|
|
2881
|
-
const connectors = get().map((wallet) => mapWalletToConnector(wallet, options.overrides));
|
|
2882
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2883
|
-
return connectors.filter((connector) => {
|
|
2884
|
-
if (seen.has(connector.id)) {
|
|
2885
|
-
return false;
|
|
2886
|
-
}
|
|
2887
|
-
seen.add(connector.id);
|
|
2888
|
-
return true;
|
|
2889
|
-
});
|
|
2890
|
-
}
|
|
2891
|
-
__name(getWalletStandardConnectors, "getWalletStandardConnectors");
|
|
2892
|
-
function watchWalletStandardConnectors(onChange, options = {}) {
|
|
2893
|
-
const { get, on } = getWallets();
|
|
2894
|
-
const emit = /* @__PURE__ */ __name(() => {
|
|
2895
|
-
const connectors = get().map((wallet) => mapWalletToConnector(wallet, options.overrides));
|
|
2896
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2897
|
-
const deduplicated = connectors.filter((connector) => {
|
|
2898
|
-
if (seen.has(connector.id)) {
|
|
2899
|
-
return false;
|
|
2900
|
-
}
|
|
2901
|
-
seen.add(connector.id);
|
|
2902
|
-
return true;
|
|
2903
|
-
});
|
|
2904
|
-
onChange(deduplicated);
|
|
2905
|
-
}, "emit");
|
|
2906
|
-
emit();
|
|
2907
|
-
const offRegister = on("register", emit);
|
|
2908
|
-
const offUnregister = on("unregister", emit);
|
|
2909
|
-
return () => {
|
|
2910
|
-
offRegister();
|
|
2911
|
-
offUnregister();
|
|
2912
|
-
};
|
|
2913
|
-
}
|
|
2914
|
-
__name(watchWalletStandardConnectors, "watchWalletStandardConnectors");
|
|
2915
|
-
|
|
2916
|
-
// src/wallet/connectors.ts
|
|
2917
|
-
function autoDiscover(options = {}) {
|
|
2918
|
-
const { get } = getWallets();
|
|
2919
|
-
const wallets = get().filter((wallet) => options.filter ? options.filter(wallet) : true);
|
|
2920
|
-
const connectors = wallets.map((wallet) => createWalletStandardConnector(wallet, options.overrides?.(wallet)));
|
|
2921
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2922
|
-
return connectors.filter((connector) => {
|
|
2923
|
-
if (seen.has(connector.id)) return false;
|
|
2924
|
-
seen.add(connector.id);
|
|
2925
|
-
return true;
|
|
2926
|
-
});
|
|
2927
|
-
}
|
|
2928
|
-
__name(autoDiscover, "autoDiscover");
|
|
2929
|
-
function injected(options) {
|
|
2930
|
-
const connector = {
|
|
2931
|
-
canAutoConnect: true,
|
|
2932
|
-
id: "wallet-standard:injected",
|
|
2933
|
-
kind: "wallet-standard",
|
|
2934
|
-
name: "Injected Wallet",
|
|
2935
|
-
ready: typeof window !== "undefined",
|
|
2936
|
-
async connect() {
|
|
2937
|
-
const wallets = getWallets().get();
|
|
2938
|
-
const first = wallets.find((wallet) => StandardConnect in wallet.features);
|
|
2939
|
-
if (!first) {
|
|
2940
|
-
throw new Error("No Wallet Standard wallets available.");
|
|
2941
|
-
}
|
|
2942
|
-
return createWalletStandardConnector(first, options).connect();
|
|
2943
|
-
},
|
|
2944
|
-
async disconnect() {
|
|
2945
|
-
},
|
|
2946
|
-
isSupported() {
|
|
2947
|
-
return typeof window !== "undefined";
|
|
2948
|
-
}
|
|
2949
|
-
};
|
|
2950
|
-
return connector;
|
|
2951
|
-
}
|
|
2952
|
-
__name(injected, "injected");
|
|
2953
|
-
function filterByName(name) {
|
|
2954
|
-
const lower = name.toLowerCase();
|
|
2955
|
-
return (wallet) => wallet.name.toLowerCase().includes(lower);
|
|
2956
|
-
}
|
|
2957
|
-
__name(filterByName, "filterByName");
|
|
2958
|
-
function phantom(options) {
|
|
2959
|
-
return autoDiscover({
|
|
2960
|
-
filter: filterByName("phantom"),
|
|
2961
|
-
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:phantom" }), "overrides")
|
|
2962
|
-
});
|
|
2963
|
-
}
|
|
2964
|
-
__name(phantom, "phantom");
|
|
2965
|
-
function solflare(options) {
|
|
2966
|
-
return autoDiscover({
|
|
2967
|
-
filter: filterByName("solflare"),
|
|
2968
|
-
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:solflare" }), "overrides")
|
|
2969
|
-
});
|
|
2970
|
-
}
|
|
2971
|
-
__name(solflare, "solflare");
|
|
2972
|
-
function backpack(options) {
|
|
2973
|
-
return autoDiscover({
|
|
2974
|
-
filter: filterByName("backpack"),
|
|
2975
|
-
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:backpack" }), "overrides")
|
|
2976
|
-
});
|
|
2977
|
-
}
|
|
2978
|
-
__name(backpack, "backpack");
|
|
2979
3042
|
|
|
2980
|
-
export { LAMPORTS_PER_SOL, SIGNATURE_STATUS_TIMEOUT_MS, applyRatio, applySerializableState, assertDecimals, assertNonNegative, autoDiscover, backpack, bigintFromJson, bigintToJson, checkedAdd, checkedDivide, checkedMultiply, checkedSubtract, confirmationMeetsCommitment, connectWallet, createAsyncState, createClient, createClientStore, createDefaultClientStore, createInitialAsyncState, createInitialClientState, createRatio, createSolTransferController, createSolTransferHelper, createSolanaRpcClient, createSplTokenHelper, createSplTransferController, createTokenAmount, createTransactionHelper, createTransactionPoolController, createTransactionRecipe, createWalletRegistry, createWalletStandardConnector, deriveConfirmationStatus, deserializeSolanaState, disconnectWallet, fetchAccount, fetchBalance, getInitialSerializableState, getWalletStandardConnectors, injected, insertReferenceKey, insertReferenceKeys, lamports, lamportsFromJson, lamportsFromSol, lamportsMath, lamportsToJson, lamportsToSolString, normalizeSignature, phantom, pow10, prepareTransaction, requestAirdrop, resolveCluster, sendTransaction, serializeSolanaState, setCluster, solflare, stableStringify, subscribeSolanaState, toAddress2 as toAddress, toAddressString, toBigint2 as toBigint, transactionToBase64, transactionToBase64WithSigners, watchWalletStandardConnectors };
|
|
3043
|
+
export { LAMPORTS_PER_SOL, SIGNATURE_STATUS_TIMEOUT_MS, applyRatio, applySerializableState, assertDecimals, assertNonNegative, autoDiscover, backpack, bigintFromJson, bigintToJson, checkedAdd, checkedDivide, checkedMultiply, checkedSubtract, confirmationMeetsCommitment, connectWallet, createAsyncState, createClient, createClientStore, createDefaultClient, createDefaultClientStore, createInitialAsyncState, createInitialClientState, createRatio, createSolTransferController, createSolTransferHelper, createSolanaRpcClient, createSplTokenHelper, createSplTransferController, createTokenAmount, createTransactionHelper, createTransactionPoolController, createTransactionRecipe, createWalletRegistry, createWalletStandardConnector, defaultWalletConnectors, deriveConfirmationStatus, deserializeSolanaState, disconnectWallet, fetchAccount, fetchBalance, getInitialSerializableState, getWalletStandardConnectors, injected, insertReferenceKey, insertReferenceKeys, lamports, lamportsFromJson, lamportsFromSol, lamportsMath, lamportsToJson, lamportsToSolString, normalizeSignature, phantom, pow10, prepareTransaction, requestAirdrop, resolveClientConfig, resolveCluster, sendTransaction, serializeSolanaState, setCluster, solflare, stableStringify, subscribeSolanaState, toAddress2 as toAddress, toAddressString, toBigint2 as toBigint, transactionToBase64, transactionToBase64WithSigners, watchWalletStandardConnectors };
|
|
2981
3044
|
//# sourceMappingURL=index.native.mjs.map
|
|
2982
3045
|
//# sourceMappingURL=index.native.mjs.map
|