@solana/client 0.1.2 → 0.1.4

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.
@@ -163,6 +163,94 @@ function createSolanaRpcClient(config) {
163
163
  }
164
164
  __name(createSolanaRpcClient, "createSolanaRpcClient");
165
165
 
166
+ // src/serialization/state.ts
167
+ var SERIALIZABLE_STATE_VERSION = 1;
168
+ function getInitialSerializableState(config) {
169
+ return {
170
+ autoconnect: false,
171
+ commitment: config.commitment,
172
+ endpoint: config.endpoint,
173
+ lastConnectorId: null,
174
+ lastPublicKey: null,
175
+ version: SERIALIZABLE_STATE_VERSION,
176
+ websocketEndpoint: config.websocketEndpoint
177
+ };
178
+ }
179
+ __name(getInitialSerializableState, "getInitialSerializableState");
180
+ function applySerializableState(config, state) {
181
+ if (!state) {
182
+ return config;
183
+ }
184
+ return {
185
+ ...config,
186
+ commitment: state.commitment ?? config.commitment,
187
+ endpoint: state.endpoint ?? config.endpoint,
188
+ websocketEndpoint: state.websocketEndpoint ?? config.websocketEndpoint
189
+ };
190
+ }
191
+ __name(applySerializableState, "applySerializableState");
192
+ function serializeSolanaState(state) {
193
+ return JSON.stringify(state);
194
+ }
195
+ __name(serializeSolanaState, "serializeSolanaState");
196
+ function deserializeSolanaState(json) {
197
+ if (!json) return null;
198
+ try {
199
+ const parsed = JSON.parse(json);
200
+ if (typeof parsed !== "object" || parsed === null) return null;
201
+ const state = parsed;
202
+ return {
203
+ autoconnect: state.autoconnect ?? false,
204
+ commitment: state.commitment,
205
+ endpoint: state.endpoint,
206
+ lastConnectorId: state.lastConnectorId ?? null,
207
+ lastPublicKey: state.lastPublicKey ?? null,
208
+ version: state.version ?? SERIALIZABLE_STATE_VERSION,
209
+ websocketEndpoint: state.websocketEndpoint
210
+ };
211
+ } catch {
212
+ return null;
213
+ }
214
+ }
215
+ __name(deserializeSolanaState, "deserializeSolanaState");
216
+ function getSerializableStateSnapshot(client) {
217
+ const state = client.store.getState();
218
+ const wallet = state.wallet;
219
+ let lastConnectorId = null;
220
+ let lastPublicKey = null;
221
+ if ("connectorId" in wallet) {
222
+ lastConnectorId = wallet.connectorId ?? null;
223
+ if (wallet.status === "connected") {
224
+ lastPublicKey = wallet.session.account.address.toString();
225
+ }
226
+ }
227
+ return {
228
+ autoconnect: false,
229
+ commitment: state.cluster.commitment,
230
+ endpoint: state.cluster.endpoint,
231
+ lastConnectorId,
232
+ lastPublicKey,
233
+ version: SERIALIZABLE_STATE_VERSION,
234
+ websocketEndpoint: state.cluster.websocketEndpoint
235
+ };
236
+ }
237
+ __name(getSerializableStateSnapshot, "getSerializableStateSnapshot");
238
+ function subscribeSolanaState(client, listener) {
239
+ let previous = serializeSolanaState(getSerializableStateSnapshot(client));
240
+ listener(JSON.parse(previous));
241
+ const unsubscribe = client.store.subscribe(() => {
242
+ const snapshot = getSerializableStateSnapshot(client);
243
+ const serialized = serializeSolanaState(snapshot);
244
+ if (serialized === previous) {
245
+ return;
246
+ }
247
+ previous = serialized;
248
+ listener(snapshot);
249
+ });
250
+ return unsubscribe;
251
+ }
252
+ __name(subscribeSolanaState, "subscribeSolanaState");
253
+
166
254
  // src/wallet/registry.ts
167
255
  function createWalletRegistry(connectors) {
168
256
  const byId = /* @__PURE__ */ new Map();
@@ -2010,25 +2098,26 @@ __name(createWatchers, "createWatchers");
2010
2098
 
2011
2099
  // src/client/createClient.ts
2012
2100
  function createClient(config) {
2013
- const commitment = config.commitment ?? "confirmed";
2014
- const websocketEndpoint = config.websocketEndpoint ?? config.endpoint;
2101
+ const hydratedConfig = config.initialState ? applySerializableState(config, config.initialState) : config;
2102
+ const commitment = hydratedConfig.commitment ?? "confirmed";
2103
+ const websocketEndpoint = hydratedConfig.websocketEndpoint ?? hydratedConfig.endpoint;
2015
2104
  const initialState = createInitialClientState({
2016
2105
  commitment,
2017
- endpoint: config.endpoint,
2106
+ endpoint: hydratedConfig.endpoint,
2018
2107
  websocketEndpoint
2019
2108
  });
2020
2109
  const store = config.createStore ? config.createStore(initialState) : createClientStore(initialState);
2021
- const rpcClient = config.rpcClient ?? createSolanaRpcClient({
2110
+ const rpcClient = hydratedConfig.rpcClient ?? createSolanaRpcClient({
2022
2111
  commitment,
2023
- endpoint: config.endpoint,
2112
+ endpoint: hydratedConfig.endpoint,
2024
2113
  websocketEndpoint
2025
2114
  });
2026
2115
  const runtime = {
2027
2116
  rpc: rpcClient.rpc,
2028
2117
  rpcSubscriptions: rpcClient.rpcSubscriptions
2029
2118
  };
2030
- const connectors = createWalletRegistry(config.walletConnectors ?? []);
2031
- const logger = createLogger(config.logger);
2119
+ const connectors = createWalletRegistry(hydratedConfig.walletConnectors ?? []);
2120
+ const logger = createLogger(hydratedConfig.logger);
2032
2121
  const actions = createActions({ connectors, logger, runtime, store });
2033
2122
  const watchers = createWatchers({ logger, runtime, store });
2034
2123
  const helpers = createClientHelpers(runtime, store);
@@ -2040,7 +2129,7 @@ function createClient(config) {
2040
2129
  },
2041
2130
  lastUpdatedAt: now()
2042
2131
  }));
2043
- actions.setCluster(config.endpoint, { commitment, websocketEndpoint }).catch(
2132
+ actions.setCluster(hydratedConfig.endpoint, { commitment, websocketEndpoint }).catch(
2044
2133
  (error) => logger({
2045
2134
  data: formatError(error),
2046
2135
  level: "error",
@@ -2244,33 +2333,6 @@ function lamportsFromJson(value) {
2244
2333
  return lamports(value, "lamports");
2245
2334
  }
2246
2335
  __name(lamportsFromJson, "lamportsFromJson");
2247
-
2248
- // src/serialization/state.ts
2249
- var SERIALIZABLE_STATE_VERSION = 1;
2250
- function getInitialSerializableState(config) {
2251
- return {
2252
- autoconnect: false,
2253
- commitment: config.commitment,
2254
- endpoint: config.endpoint,
2255
- lastConnectorId: null,
2256
- lastPublicKey: null,
2257
- version: SERIALIZABLE_STATE_VERSION,
2258
- websocketEndpoint: config.websocketEndpoint
2259
- };
2260
- }
2261
- __name(getInitialSerializableState, "getInitialSerializableState");
2262
- function applySerializableState(config, state) {
2263
- if (!state) {
2264
- return config;
2265
- }
2266
- return {
2267
- ...config,
2268
- commitment: state.commitment ?? config.commitment,
2269
- endpoint: state.endpoint ?? config.endpoint,
2270
- websocketEndpoint: state.websocketEndpoint ?? config.websocketEndpoint
2271
- };
2272
- }
2273
- __name(applySerializableState, "applySerializableState");
2274
2336
  var COMMITMENT_PRIORITY = {
2275
2337
  processed: 0,
2276
2338
  confirmed: 1,
@@ -2651,7 +2713,8 @@ var base58Decoder = getBase58Decoder();
2651
2713
  var transactionDecoder = getTransactionDecoder();
2652
2714
  var transactionEncoder = getTransactionEncoder();
2653
2715
  function deriveConnectorId(wallet) {
2654
- return wallet.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
2716
+ const kebab = wallet.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
2717
+ return `wallet-standard:${kebab}`;
2655
2718
  }
2656
2719
  __name(deriveConnectorId, "deriveConnectorId");
2657
2720
  function getPrimaryAccount(accounts) {
@@ -2694,6 +2757,7 @@ function createWalletStandardConnector(wallet, options = {}) {
2694
2757
  canAutoConnect: options.canAutoConnect ?? Boolean(wallet.features[StandardConnect]),
2695
2758
  icon: options.icon ?? wallet.icon,
2696
2759
  id: options.id ?? deriveConnectorId(wallet),
2760
+ kind: options.kind ?? "wallet-standard",
2697
2761
  name: options.name ?? wallet.name,
2698
2762
  ready: typeof window !== "undefined"
2699
2763
  };
@@ -2819,6 +2883,6 @@ function watchWalletStandardConnectors(onChange, options = {}) {
2819
2883
  }
2820
2884
  __name(watchWalletStandardConnectors, "watchWalletStandardConnectors");
2821
2885
 
2822
- export { LAMPORTS_PER_SOL, SIGNATURE_STATUS_TIMEOUT_MS, applyRatio, applySerializableState, assertDecimals, assertNonNegative, bigintFromJson, bigintToJson, checkedAdd, checkedDivide, checkedMultiply, checkedSubtract, confirmationMeetsCommitment, createAsyncState, createClient, createClientStore, createDefaultClientStore, createInitialAsyncState, createInitialClientState, createRatio, createSolTransferController, createSolTransferHelper, createSolanaRpcClient, createSplTokenHelper, createSplTransferController, createTokenAmount, createTransactionHelper, createTransactionPoolController, createTransactionRecipe, createWalletRegistry, createWalletStandardConnector, deriveConfirmationStatus, getInitialSerializableState, getWalletStandardConnectors, insertReferenceKey, insertReferenceKeys, lamports, lamportsFromJson, lamportsFromSol, lamportsMath, lamportsToJson, lamportsToSolString, normalizeSignature, pow10, prepareTransaction, resolveCluster, stableStringify, toAddress2 as toAddress, toAddressString, toBigint2 as toBigint, transactionToBase64, transactionToBase64WithSigners, watchWalletStandardConnectors };
2886
+ export { LAMPORTS_PER_SOL, SIGNATURE_STATUS_TIMEOUT_MS, applyRatio, applySerializableState, assertDecimals, assertNonNegative, bigintFromJson, bigintToJson, checkedAdd, checkedDivide, checkedMultiply, checkedSubtract, confirmationMeetsCommitment, createAsyncState, createClient, createClientStore, createDefaultClientStore, createInitialAsyncState, createInitialClientState, createRatio, createSolTransferController, createSolTransferHelper, createSolanaRpcClient, createSplTokenHelper, createSplTransferController, createTokenAmount, createTransactionHelper, createTransactionPoolController, createTransactionRecipe, createWalletRegistry, createWalletStandardConnector, deriveConfirmationStatus, deserializeSolanaState, getInitialSerializableState, getWalletStandardConnectors, insertReferenceKey, insertReferenceKeys, lamports, lamportsFromJson, lamportsFromSol, lamportsMath, lamportsToJson, lamportsToSolString, normalizeSignature, pow10, prepareTransaction, resolveCluster, serializeSolanaState, stableStringify, subscribeSolanaState, toAddress2 as toAddress, toAddressString, toBigint2 as toBigint, transactionToBase64, transactionToBase64WithSigners, watchWalletStandardConnectors };
2823
2887
  //# sourceMappingURL=index.browser.mjs.map
2824
2888
  //# sourceMappingURL=index.browser.mjs.map