@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.
@@ -165,6 +165,94 @@ function createSolanaRpcClient(config) {
165
165
  }
166
166
  __name(createSolanaRpcClient, "createSolanaRpcClient");
167
167
 
168
+ // src/serialization/state.ts
169
+ var SERIALIZABLE_STATE_VERSION = 1;
170
+ function getInitialSerializableState(config) {
171
+ return {
172
+ autoconnect: false,
173
+ commitment: config.commitment,
174
+ endpoint: config.endpoint,
175
+ lastConnectorId: null,
176
+ lastPublicKey: null,
177
+ version: SERIALIZABLE_STATE_VERSION,
178
+ websocketEndpoint: config.websocketEndpoint
179
+ };
180
+ }
181
+ __name(getInitialSerializableState, "getInitialSerializableState");
182
+ function applySerializableState(config, state) {
183
+ if (!state) {
184
+ return config;
185
+ }
186
+ return {
187
+ ...config,
188
+ commitment: state.commitment ?? config.commitment,
189
+ endpoint: state.endpoint ?? config.endpoint,
190
+ websocketEndpoint: state.websocketEndpoint ?? config.websocketEndpoint
191
+ };
192
+ }
193
+ __name(applySerializableState, "applySerializableState");
194
+ function serializeSolanaState(state) {
195
+ return JSON.stringify(state);
196
+ }
197
+ __name(serializeSolanaState, "serializeSolanaState");
198
+ function deserializeSolanaState(json) {
199
+ if (!json) return null;
200
+ try {
201
+ const parsed = JSON.parse(json);
202
+ if (typeof parsed !== "object" || parsed === null) return null;
203
+ const state = parsed;
204
+ return {
205
+ autoconnect: state.autoconnect ?? false,
206
+ commitment: state.commitment,
207
+ endpoint: state.endpoint,
208
+ lastConnectorId: state.lastConnectorId ?? null,
209
+ lastPublicKey: state.lastPublicKey ?? null,
210
+ version: state.version ?? SERIALIZABLE_STATE_VERSION,
211
+ websocketEndpoint: state.websocketEndpoint
212
+ };
213
+ } catch {
214
+ return null;
215
+ }
216
+ }
217
+ __name(deserializeSolanaState, "deserializeSolanaState");
218
+ function getSerializableStateSnapshot(client) {
219
+ const state = client.store.getState();
220
+ const wallet = state.wallet;
221
+ let lastConnectorId = null;
222
+ let lastPublicKey = null;
223
+ if ("connectorId" in wallet) {
224
+ lastConnectorId = wallet.connectorId ?? null;
225
+ if (wallet.status === "connected") {
226
+ lastPublicKey = wallet.session.account.address.toString();
227
+ }
228
+ }
229
+ return {
230
+ autoconnect: false,
231
+ commitment: state.cluster.commitment,
232
+ endpoint: state.cluster.endpoint,
233
+ lastConnectorId,
234
+ lastPublicKey,
235
+ version: SERIALIZABLE_STATE_VERSION,
236
+ websocketEndpoint: state.cluster.websocketEndpoint
237
+ };
238
+ }
239
+ __name(getSerializableStateSnapshot, "getSerializableStateSnapshot");
240
+ function subscribeSolanaState(client, listener) {
241
+ let previous = serializeSolanaState(getSerializableStateSnapshot(client));
242
+ listener(JSON.parse(previous));
243
+ const unsubscribe = client.store.subscribe(() => {
244
+ const snapshot = getSerializableStateSnapshot(client);
245
+ const serialized = serializeSolanaState(snapshot);
246
+ if (serialized === previous) {
247
+ return;
248
+ }
249
+ previous = serialized;
250
+ listener(snapshot);
251
+ });
252
+ return unsubscribe;
253
+ }
254
+ __name(subscribeSolanaState, "subscribeSolanaState");
255
+
168
256
  // src/wallet/registry.ts
169
257
  function createWalletRegistry(connectors) {
170
258
  const byId = /* @__PURE__ */ new Map();
@@ -2012,25 +2100,26 @@ __name(createWatchers, "createWatchers");
2012
2100
 
2013
2101
  // src/client/createClient.ts
2014
2102
  function createClient(config) {
2015
- const commitment = config.commitment ?? "confirmed";
2016
- const websocketEndpoint = config.websocketEndpoint ?? config.endpoint;
2103
+ const hydratedConfig = config.initialState ? applySerializableState(config, config.initialState) : config;
2104
+ const commitment = hydratedConfig.commitment ?? "confirmed";
2105
+ const websocketEndpoint = hydratedConfig.websocketEndpoint ?? hydratedConfig.endpoint;
2017
2106
  const initialState = createInitialClientState({
2018
2107
  commitment,
2019
- endpoint: config.endpoint,
2108
+ endpoint: hydratedConfig.endpoint,
2020
2109
  websocketEndpoint
2021
2110
  });
2022
2111
  const store = config.createStore ? config.createStore(initialState) : createClientStore(initialState);
2023
- const rpcClient = config.rpcClient ?? createSolanaRpcClient({
2112
+ const rpcClient = hydratedConfig.rpcClient ?? createSolanaRpcClient({
2024
2113
  commitment,
2025
- endpoint: config.endpoint,
2114
+ endpoint: hydratedConfig.endpoint,
2026
2115
  websocketEndpoint
2027
2116
  });
2028
2117
  const runtime = {
2029
2118
  rpc: rpcClient.rpc,
2030
2119
  rpcSubscriptions: rpcClient.rpcSubscriptions
2031
2120
  };
2032
- const connectors = createWalletRegistry(config.walletConnectors ?? []);
2033
- const logger = createLogger(config.logger);
2121
+ const connectors = createWalletRegistry(hydratedConfig.walletConnectors ?? []);
2122
+ const logger = createLogger(hydratedConfig.logger);
2034
2123
  const actions = createActions({ connectors, logger, runtime, store });
2035
2124
  const watchers = createWatchers({ logger, runtime, store });
2036
2125
  const helpers = createClientHelpers(runtime, store);
@@ -2042,7 +2131,7 @@ function createClient(config) {
2042
2131
  },
2043
2132
  lastUpdatedAt: now()
2044
2133
  }));
2045
- actions.setCluster(config.endpoint, { commitment, websocketEndpoint }).catch(
2134
+ actions.setCluster(hydratedConfig.endpoint, { commitment, websocketEndpoint }).catch(
2046
2135
  (error) => logger({
2047
2136
  data: formatError(error),
2048
2137
  level: "error",
@@ -2246,33 +2335,6 @@ function lamportsFromJson(value) {
2246
2335
  return lamports(value, "lamports");
2247
2336
  }
2248
2337
  __name(lamportsFromJson, "lamportsFromJson");
2249
-
2250
- // src/serialization/state.ts
2251
- var SERIALIZABLE_STATE_VERSION = 1;
2252
- function getInitialSerializableState(config) {
2253
- return {
2254
- autoconnect: false,
2255
- commitment: config.commitment,
2256
- endpoint: config.endpoint,
2257
- lastConnectorId: null,
2258
- lastPublicKey: null,
2259
- version: SERIALIZABLE_STATE_VERSION,
2260
- websocketEndpoint: config.websocketEndpoint
2261
- };
2262
- }
2263
- __name(getInitialSerializableState, "getInitialSerializableState");
2264
- function applySerializableState(config, state) {
2265
- if (!state) {
2266
- return config;
2267
- }
2268
- return {
2269
- ...config,
2270
- commitment: state.commitment ?? config.commitment,
2271
- endpoint: state.endpoint ?? config.endpoint,
2272
- websocketEndpoint: state.websocketEndpoint ?? config.websocketEndpoint
2273
- };
2274
- }
2275
- __name(applySerializableState, "applySerializableState");
2276
2338
  var COMMITMENT_PRIORITY = {
2277
2339
  processed: 0,
2278
2340
  confirmed: 1,
@@ -2653,7 +2715,8 @@ var base58Decoder = codecsStrings.getBase58Decoder();
2653
2715
  var transactionDecoder = transactions.getTransactionDecoder();
2654
2716
  var transactionEncoder = transactions.getTransactionEncoder();
2655
2717
  function deriveConnectorId(wallet) {
2656
- return wallet.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
2718
+ const kebab = wallet.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
2719
+ return `wallet-standard:${kebab}`;
2657
2720
  }
2658
2721
  __name(deriveConnectorId, "deriveConnectorId");
2659
2722
  function getPrimaryAccount(accounts) {
@@ -2696,6 +2759,7 @@ function createWalletStandardConnector(wallet, options = {}) {
2696
2759
  canAutoConnect: options.canAutoConnect ?? Boolean(wallet.features[features.StandardConnect]),
2697
2760
  icon: options.icon ?? wallet.icon,
2698
2761
  id: options.id ?? deriveConnectorId(wallet),
2762
+ kind: options.kind ?? "wallet-standard",
2699
2763
  name: options.name ?? wallet.name,
2700
2764
  ready: typeof window !== "undefined"
2701
2765
  };
@@ -2853,6 +2917,7 @@ exports.createTransactionRecipe = createTransactionRecipe;
2853
2917
  exports.createWalletRegistry = createWalletRegistry;
2854
2918
  exports.createWalletStandardConnector = createWalletStandardConnector;
2855
2919
  exports.deriveConfirmationStatus = deriveConfirmationStatus;
2920
+ exports.deserializeSolanaState = deserializeSolanaState;
2856
2921
  exports.getInitialSerializableState = getInitialSerializableState;
2857
2922
  exports.getWalletStandardConnectors = getWalletStandardConnectors;
2858
2923
  exports.insertReferenceKey = insertReferenceKey;
@@ -2867,7 +2932,9 @@ exports.normalizeSignature = normalizeSignature;
2867
2932
  exports.pow10 = pow10;
2868
2933
  exports.prepareTransaction = prepareTransaction;
2869
2934
  exports.resolveCluster = resolveCluster;
2935
+ exports.serializeSolanaState = serializeSolanaState;
2870
2936
  exports.stableStringify = stableStringify;
2937
+ exports.subscribeSolanaState = subscribeSolanaState;
2871
2938
  exports.toAddress = toAddress2;
2872
2939
  exports.toAddressString = toAddressString;
2873
2940
  exports.toBigint = toBigint2;