@kheopskit/core 0.0.22 → 0.1.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.js CHANGED
@@ -1,46 +1,588 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
8
10
  __defProp(target, name, { get: all[name], enumerable: true });
9
11
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
12
+ var __copyProps = (to, from2, except, desc) => {
13
+ if (from2 && typeof from2 === "object" || typeof from2 === "function") {
14
+ for (let key of __getOwnPropNames(from2))
13
15
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
21
31
  var index_exports = {};
22
32
  __export(index_exports, {
33
+ DEFAULT_STORAGE_KEY: () => DEFAULT_STORAGE_KEY,
34
+ clearAllCachedObservables: () => clearAllCachedObservables,
35
+ clearCachedObservable: () => clearCachedObservable,
36
+ createKheopskitStore: () => createKheopskitStore,
37
+ getCachedIcon: () => getCachedIcon,
38
+ getDefaultStore: () => getDefaultStore,
23
39
  getKheopskit$: () => getKheopskit$,
40
+ getSafeLocalStorage: () => getSafeLocalStorage,
41
+ hydrateAccount: () => hydrateAccount,
42
+ hydrateWallet: () => hydrateWallet,
43
+ resetAppKitCache: () => resetAppKitCache,
24
44
  resolveConfig: () => resolveConfig
25
45
  });
26
46
  module.exports = __toCommonJS(index_exports);
27
47
 
48
+ // src/utils/getCachedObservable.ts
49
+ var CACHE = /* @__PURE__ */ new Map();
50
+ var getCachedObservable$ = (key, create) => {
51
+ if (!CACHE.has(key)) CACHE.set(key, create());
52
+ return CACHE.get(key);
53
+ };
54
+ var clearCachedObservable = (key) => {
55
+ CACHE.delete(key);
56
+ };
57
+ var clearAllCachedObservables = () => {
58
+ CACHE.clear();
59
+ };
60
+
61
+ // src/utils/polkadotExtensions.ts
62
+ var POLKADOT_EXTENSIONS = {
63
+ talisman: {
64
+ name: "Talisman",
65
+ icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBmaWxsPSIjZGRmZTc2IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wIDcwLjI1YzAgMjEuMjU1IDAgMzEuODgzIDQuNDYzIDM5Ljg1MmEzNSAzNSAwIDAgMCAxMy40MzUgMTMuNDM1QzI1Ljg2NyAxMjggMzYuNDk1IDEyOCA1Ny43NSAxMjhoMTIuNWMyMS4yNTUgMCAzMS44ODMgMCAzOS44NTItNC40NjNhMzUgMzUgMCAwIDAgMTMuNDM1LTEzLjQzNUMxMj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JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg=="
78
+ }
79
+ };
80
+
81
+ // src/utils/isWalletPlatform.ts
82
+ var isWalletPlatform = (platform) => typeof platform === "string" && ["polkadot", "ethereum"].includes(platform);
83
+
84
+ // src/utils/WalletId.ts
85
+ var getWalletId = (platform, identifier) => {
86
+ if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
87
+ if (!identifier) throw new Error("Invalid name");
88
+ return `${platform}:${identifier}`;
89
+ };
90
+ var parseWalletId = (walletId) => {
91
+ if (!walletId) throw new Error("Invalid walletId");
92
+ const [platform, identifier] = walletId.split(":");
93
+ if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
94
+ if (!identifier) throw new Error("Invalid address");
95
+ return { platform, identifier };
96
+ };
97
+
98
+ // src/utils/hydrateState.ts
99
+ var lookupWalletIcon = (platform, identifier) => {
100
+ if (platform === "polkadot") {
101
+ return POLKADOT_EXTENSIONS[identifier]?.icon ?? "";
102
+ }
103
+ return "";
104
+ };
105
+ var PendingWalletError = class extends Error {
106
+ constructor(walletId) {
107
+ super(
108
+ `Wallet ${walletId} is still loading. Wait for isHydrating to be false before calling connect/disconnect.`
109
+ );
110
+ this.name = "PendingWalletError";
111
+ }
112
+ };
113
+ var hydrateWallet = (cached) => {
114
+ const { platform, identifier } = parseWalletId(cached.id);
115
+ const throwPending = () => {
116
+ throw new PendingWalletError(cached.id);
117
+ };
118
+ const icon = lookupWalletIcon(platform, identifier);
119
+ if (platform === "polkadot") {
120
+ return {
121
+ id: cached.id,
122
+ platform: "polkadot",
123
+ type: "injected",
124
+ extensionId: identifier,
125
+ extension: void 0,
126
+ name: cached.name,
127
+ icon,
128
+ isConnected: cached.isConnected,
129
+ connect: throwPending,
130
+ disconnect: throwPending
131
+ };
132
+ }
133
+ if (platform === "ethereum") {
134
+ return {
135
+ id: cached.id,
136
+ platform: "ethereum",
137
+ type: "injected",
138
+ providerId: identifier,
139
+ provider: {},
140
+ // Placeholder - will be replaced by real wallet
141
+ name: cached.name,
142
+ icon,
143
+ isConnected: cached.isConnected,
144
+ connect: throwPending,
145
+ disconnect: throwPending
146
+ };
147
+ }
148
+ throw new Error(`Unknown platform: ${platform}`);
149
+ };
150
+ var hydrateAccount = (cached) => {
151
+ if (cached.platform === "polkadot") {
152
+ return {
153
+ id: cached.id,
154
+ platform: "polkadot",
155
+ address: cached.address,
156
+ name: cached.name,
157
+ walletId: cached.walletId,
158
+ walletName: cached.walletName,
159
+ // PolkadotSigner is required but we can't provide a real one
160
+ // This is a placeholder that will be replaced by the real account
161
+ polkadotSigner: {}
162
+ };
163
+ }
164
+ if (cached.platform === "ethereum") {
165
+ return {
166
+ id: cached.id,
167
+ platform: "ethereum",
168
+ address: cached.address,
169
+ walletId: cached.walletId,
170
+ walletName: cached.walletName,
171
+ isWalletDefault: false,
172
+ client: {}
173
+ // Placeholder
174
+ };
175
+ }
176
+ throw new Error(`Unknown platform: ${cached.platform}`);
177
+ };
178
+ var serializeWallet = (wallet) => ({
179
+ id: wallet.id,
180
+ platform: wallet.platform,
181
+ type: wallet.type,
182
+ name: wallet.name,
183
+ // Note: icon is NOT stored to save cookie space
184
+ isConnected: wallet.isConnected
185
+ });
186
+ var serializeAccount = (account) => ({
187
+ id: account.id,
188
+ platform: account.platform,
189
+ address: account.address,
190
+ name: "name" in account ? account.name : void 0,
191
+ walletId: account.walletId,
192
+ walletName: account.walletName
193
+ });
194
+
195
+ // src/utils/storage.ts
196
+ var noopStorage = {
197
+ getItem: () => null,
198
+ setItem: () => {
199
+ },
200
+ removeItem: () => {
201
+ }
202
+ };
203
+ var _safeLocalStorage = null;
204
+ var createSafeLocalStorage = () => {
205
+ if (typeof window === "undefined") return noopStorage;
206
+ try {
207
+ const testKey = "__kheopskit_test__";
208
+ window.localStorage.setItem(testKey, testKey);
209
+ window.localStorage.removeItem(testKey);
210
+ return {
211
+ getItem: (key) => window.localStorage.getItem(key),
212
+ setItem: (key, value) => window.localStorage.setItem(key, value),
213
+ removeItem: (key) => window.localStorage.removeItem(key),
214
+ subscribe: (key, callback) => {
215
+ const handler = (event) => {
216
+ if (event.key === key) {
217
+ callback(event.newValue);
218
+ }
219
+ };
220
+ window.addEventListener("storage", handler);
221
+ return () => window.removeEventListener("storage", handler);
222
+ }
223
+ };
224
+ } catch {
225
+ return noopStorage;
226
+ }
227
+ };
228
+ var getSafeLocalStorage = () => {
229
+ if (_safeLocalStorage === null) {
230
+ _safeLocalStorage = createSafeLocalStorage();
231
+ }
232
+ return _safeLocalStorage;
233
+ };
234
+ var safeLocalStorage = {
235
+ getItem: (key) => getSafeLocalStorage().getItem(key),
236
+ setItem: (key, value) => getSafeLocalStorage().setItem(key, value),
237
+ removeItem: (key) => getSafeLocalStorage().removeItem(key),
238
+ subscribe: (key, callback) => {
239
+ const storage = getSafeLocalStorage();
240
+ return storage.subscribe?.(key, callback) ?? (() => {
241
+ });
242
+ }
243
+ };
244
+ var parseCookie = (cookieString, key) => {
245
+ if (!cookieString) return null;
246
+ for (const cookie of cookieString.split(";")) {
247
+ const [k, ...v] = cookie.split("=");
248
+ const cookieKey = k?.trim();
249
+ if (cookieKey === key) {
250
+ try {
251
+ return decodeURIComponent(v.join("=").trim());
252
+ } catch {
253
+ return null;
254
+ }
255
+ }
256
+ }
257
+ return null;
258
+ };
259
+ var COOKIE_MAX_SIZE = 3 * 1024;
260
+ var BROADCAST_CHANNEL_NAME = "kheopskit-storage-sync";
261
+ var sharedBroadcastChannel = null;
262
+ var getBroadcastChannel = () => {
263
+ if (sharedBroadcastChannel) return sharedBroadcastChannel;
264
+ if (typeof BroadcastChannel === "undefined") return null;
265
+ try {
266
+ sharedBroadcastChannel = new BroadcastChannel(BROADCAST_CHANNEL_NAME);
267
+ } catch {
268
+ }
269
+ return sharedBroadcastChannel;
270
+ };
271
+ var isSecureConnection = () => typeof window !== "undefined" && window.location.protocol === "https:";
272
+ var cookieStorage = (initialCookies) => {
273
+ return {
274
+ getItem: (key) => {
275
+ const cookieString = typeof document !== "undefined" ? document.cookie : initialCookies;
276
+ return parseCookie(cookieString, key);
277
+ },
278
+ setItem: (key, value) => {
279
+ if (typeof document === "undefined") return;
280
+ const encodedValue = encodeURIComponent(value);
281
+ if (encodedValue.length > COOKIE_MAX_SIZE) {
282
+ console.warn(
283
+ `[kheopskit] Cookie value for "${key}" exceeds recommended size limit (${encodedValue.length} > ${COOKIE_MAX_SIZE} bytes). This may cause issues with cookie storage. Consider reducing the number of connected wallets.`
284
+ );
285
+ }
286
+ const expires = /* @__PURE__ */ new Date();
287
+ expires.setFullYear(expires.getFullYear() + 1);
288
+ let cookieStr = `${key}=${encodedValue};expires=${expires.toUTCString()};path=/;SameSite=Lax`;
289
+ if (isSecureConnection()) {
290
+ cookieStr += ";Secure";
291
+ }
292
+ document.cookie = cookieStr;
293
+ getBroadcastChannel()?.postMessage({ type: "set", key, value });
294
+ },
295
+ removeItem: (key) => {
296
+ if (typeof document === "undefined") return;
297
+ let cookieStr = `${key}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;SameSite=Lax`;
298
+ if (isSecureConnection()) {
299
+ cookieStr += ";Secure";
300
+ }
301
+ document.cookie = cookieStr;
302
+ getBroadcastChannel()?.postMessage({ type: "remove", key });
303
+ },
304
+ subscribe: (key, callback) => {
305
+ const channel = getBroadcastChannel();
306
+ if (!channel) return () => {
307
+ };
308
+ const handler = (event) => {
309
+ const data = event.data;
310
+ if (data.key === key) {
311
+ if (data.type === "set") {
312
+ callback(data.value ?? null);
313
+ } else if (data.type === "remove") {
314
+ callback(null);
315
+ }
316
+ }
317
+ };
318
+ channel.addEventListener("message", handler);
319
+ return () => {
320
+ channel.removeEventListener("message", handler);
321
+ };
322
+ }
323
+ };
324
+ };
325
+
326
+ // src/utils/iconCache.ts
327
+ var ICON_CACHE_KEY = "kheopskit-icons";
328
+ var memoryCache = null;
329
+ var loadCache = () => {
330
+ if (memoryCache !== null) return memoryCache;
331
+ try {
332
+ const stored = safeLocalStorage.getItem(ICON_CACHE_KEY);
333
+ memoryCache = stored ? JSON.parse(stored) : {};
334
+ } catch {
335
+ memoryCache = {};
336
+ }
337
+ return memoryCache;
338
+ };
339
+ var saveCache = (cache) => {
340
+ try {
341
+ safeLocalStorage.setItem(ICON_CACHE_KEY, JSON.stringify(cache));
342
+ memoryCache = cache;
343
+ } catch {
344
+ }
345
+ };
346
+ var getCachedIcon = (walletId) => {
347
+ const cache = loadCache();
348
+ return cache[walletId] || void 0;
349
+ };
350
+ var setCachedIcons = (icons) => {
351
+ const cache = loadCache();
352
+ let changed = false;
353
+ for (const [walletId, icon] of Object.entries(icons)) {
354
+ if (icon && cache[walletId] !== icon) {
355
+ cache[walletId] = icon;
356
+ changed = true;
357
+ }
358
+ }
359
+ if (changed) {
360
+ saveCache(cache);
361
+ }
362
+ };
363
+
364
+ // src/api/appKit.ts
365
+ var import_rxjs = require("rxjs");
366
+ var loadAppKit = async () => {
367
+ const { createAppKit } = await import("@reown/appkit/core");
368
+ return createAppKit;
369
+ };
370
+ var WALLET_CONNECT_ICON = "data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDQwMCA0MDAiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTAgMGg0MDB2NDAwaC00MDB6Ii8+PC9jbGlwUGF0aD48ZyBjbGlwLXBhdGg9InVybCgjYSkiPjxjaXJjbGUgY3g9IjIwMCIgY3k9IjIwMCIgZmlsbD0iIzMzOTZmZiIgcj0iMTk5LjUiIHN0cm9rZT0iIzY2YjFmZiIvPjxwYXRoIGQ9Im0xMjIuNTE5IDE0OC45NjVjNDIuNzkxLTQxLjcyOSAxMTIuMTcxLTQxLjcyOSAxNTQuOTYyIDBsNS4xNSA1LjAyMmMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtMTcuNjE3IDE3LjE4Yy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTcuMDg3LTYuOTExYy0yOS44NTMtMjkuMTExLTc4LjI1My0yOS4xMTEtMTA4LjEwNiAwbC03LjU5IDcuNDAxYy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTE3LjYxNy0xNy4xOGMtMi4xNC0yLjA4Ni0yLjE0LTUuNDY5IDAtNy41NTV6bTE5MS4zOTcgMzUuNTI5IDE1LjY3OSAxNS4yOWMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtNzAuNyA2OC45NDRjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTUwLjE3OC00OC45MzFjLS41MzUtLjUyMi0xLjQwMi0uNTIyLTEuOTM3IDBsLTUwLjE3OCA0OC45MzFjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTcwLjcwMTUtNjguOTQ1Yy0yLjEzOTYtMi4wODYtMi4xMzk2LTUuNDY5IDAtNy41NTVsMTUuNjc5NS0xNS4yOWMyLjEzOTYtMi4wODYgNS42MDg1LTIuMDg2IDcuNzQ4MSAwbDUwLjE3ODkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3Ny00OC45MzJjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMGw1MC4xNzkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3OS00OC45MzFjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+";
371
+ var cachedAppKit = null;
372
+ var resetAppKitCache = () => {
373
+ cachedAppKit = null;
374
+ };
375
+ var getAppKitWallets$ = (config) => {
376
+ if (!config.walletConnect) return (0, import_rxjs.of)({});
377
+ if (typeof window === "undefined") return (0, import_rxjs.of)({});
378
+ const walletConnect = config.walletConnect;
379
+ if (!cachedAppKit) {
380
+ cachedAppKit = (0, import_rxjs.from)(loadAppKit()).pipe(
381
+ (0, import_rxjs.switchMap)((createAppKit) => {
382
+ return new import_rxjs.Observable((subscriber) => {
383
+ const appKit = createAppKit({
384
+ projectId: walletConnect.projectId,
385
+ metadata: walletConnect.metadata,
386
+ networks: walletConnect.networks,
387
+ themeMode: walletConnect.themeMode,
388
+ themeVariables: walletConnect.themeVariables,
389
+ universalProviderConfigOverride: {
390
+ methods: {
391
+ polkadot: ["polkadot_signTransaction", "polkadot_signMessage"]
392
+ }
393
+ },
394
+ allWallets: "HIDE",
395
+ debug: config.debug,
396
+ allowUnsupportedChain: true
397
+ });
398
+ const status$ = new import_rxjs.BehaviorSubject({
399
+ isPolkadotConnected: false,
400
+ isEthereumConnected: false
401
+ });
402
+ const unsubProviders = appKit.subscribeProviders((providers) => {
403
+ status$.next({
404
+ isPolkadotConnected: !!providers.polkadot,
405
+ isEthereumConnected: !!providers.eip155
406
+ });
407
+ });
408
+ const polkadotWallet$ = appKit.chainNamespaces.includes("polkadot") ? status$.pipe(
409
+ (0, import_rxjs.map)((s) => s.isPolkadotConnected),
410
+ (0, import_rxjs.distinctUntilChanged)(),
411
+ (0, import_rxjs.map)((isConnected) => {
412
+ const walletInfo = appKit.getWalletInfo();
413
+ return {
414
+ id: getWalletId("polkadot", "walletconnect"),
415
+ platform: "polkadot",
416
+ type: "appKit",
417
+ appKit,
418
+ // todo maybe we dont want to expose the appKit instance
419
+ name: walletInfo?.name ?? "WalletConnect",
420
+ icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
421
+ connect: async () => {
422
+ if (!isConnected) await appKit.open();
423
+ },
424
+ disconnect: () => {
425
+ if (isConnected) appKit.disconnect();
426
+ },
427
+ isConnected
428
+ };
429
+ })
430
+ ) : (0, import_rxjs.of)(void 0);
431
+ const ethereumWallet$ = appKit.chainNamespaces.includes("eip155") ? status$.pipe(
432
+ (0, import_rxjs.map)((s) => s.isEthereumConnected),
433
+ (0, import_rxjs.distinctUntilChanged)(),
434
+ (0, import_rxjs.map)((isConnected) => {
435
+ const walletInfo = appKit.getWalletInfo();
436
+ return {
437
+ id: getWalletId("ethereum", "walletconnect"),
438
+ platform: "ethereum",
439
+ type: "appKit",
440
+ appKit,
441
+ name: walletInfo?.name ?? "WalletConnect",
442
+ icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
443
+ connect: () => appKit.open(),
444
+ disconnect: () => appKit.disconnect(),
445
+ isConnected
446
+ };
447
+ })
448
+ ) : (0, import_rxjs.of)(void 0);
449
+ const sub = (0, import_rxjs.combineLatest)({
450
+ polkadot: polkadotWallet$,
451
+ ethereum: ethereumWallet$
452
+ }).subscribe(subscriber);
453
+ return () => {
454
+ sub.unsubscribe();
455
+ unsubProviders();
456
+ };
457
+ });
458
+ }),
459
+ (0, import_rxjs.shareReplay)({ refCount: true, bufferSize: 1 })
460
+ );
461
+ }
462
+ return cachedAppKit;
463
+ };
464
+
28
465
  // src/api/config.ts
466
+ var DEFAULT_STORAGE_KEY = "kheopskit";
29
467
  var DEFAULT_CONFIG = {
30
468
  autoReconnect: true,
31
469
  platforms: ["polkadot"],
32
- debug: false
470
+ debug: false,
471
+ storageKey: DEFAULT_STORAGE_KEY,
472
+ hydrationGracePeriod: 500
33
473
  };
34
474
  var resolveConfig = (config) => {
35
475
  return Object.assign({}, DEFAULT_CONFIG, config);
36
476
  };
37
477
 
38
478
  // src/api/kheopskit.ts
39
- var import_rxjs10 = require("rxjs");
479
+ var import_rxjs11 = require("rxjs");
480
+
481
+ // src/utils/createHydrationBuffer.ts
482
+ var import_rxjs2 = require("rxjs");
483
+ var createBufferCore = (cachedItems, liveItems$, gracePeriodMs, mergeFn, isConverged) => {
484
+ if (gracePeriodMs <= 0 || cachedItems.length === 0) {
485
+ return liveItems$.pipe((0, import_rxjs2.map)((items) => ({ items, isHydrating: false })));
486
+ }
487
+ return new import_rxjs2.Observable((subscriber) => {
488
+ const subscriptions = new import_rxjs2.Subscription();
489
+ const isHydrating$ = new import_rxjs2.BehaviorSubject(true);
490
+ const liveWithInitial$ = liveItems$.pipe((0, import_rxjs2.startWith)([]));
491
+ if (isConverged) {
492
+ const timerFired$ = (0, import_rxjs2.timer)(gracePeriodMs).pipe(
493
+ (0, import_rxjs2.map)(() => true),
494
+ (0, import_rxjs2.startWith)(false),
495
+ (0, import_rxjs2.shareReplay)({ bufferSize: 1, refCount: true })
496
+ );
497
+ subscriptions.add(
498
+ (0, import_rxjs2.combineLatest)([liveWithInitial$, timerFired$]).pipe(
499
+ (0, import_rxjs2.filter)(([, timerFired]) => timerFired),
500
+ (0, import_rxjs2.filter)(([liveItems]) => isConverged(liveItems, cachedItems)),
501
+ (0, import_rxjs2.take)(1)
502
+ ).subscribe(() => {
503
+ isHydrating$.next(false);
504
+ })
505
+ );
506
+ subscriptions.add(
507
+ (0, import_rxjs2.timer)(gracePeriodMs * 6).subscribe(() => {
508
+ if (isHydrating$.value) {
509
+ isHydrating$.next(false);
510
+ }
511
+ })
512
+ );
513
+ } else {
514
+ subscriptions.add(
515
+ (0, import_rxjs2.timer)(gracePeriodMs).subscribe(() => {
516
+ isHydrating$.next(false);
517
+ })
518
+ );
519
+ }
520
+ subscriptions.add(
521
+ (0, import_rxjs2.combineLatest)([liveWithInitial$, isHydrating$]).pipe(
522
+ (0, import_rxjs2.map)(([liveItems, isHydrating]) => {
523
+ if (!isHydrating) {
524
+ return { items: liveItems, isHydrating: false };
525
+ }
526
+ return {
527
+ items: mergeFn(liveItems, cachedItems),
528
+ isHydrating: true
529
+ };
530
+ })
531
+ ).subscribe(subscriber)
532
+ );
533
+ return () => {
534
+ subscriptions.unsubscribe();
535
+ isHydrating$.complete();
536
+ };
537
+ });
538
+ };
539
+ var createHydrationBuffer = (cachedItems, liveItems$, gracePeriodMs, getKey, isConverged, mergeItem, transformCachedOnly) => {
540
+ return createBufferCore(
541
+ cachedItems,
542
+ liveItems$,
543
+ gracePeriodMs,
544
+ (liveItems, cached) => {
545
+ const cachedByKey = new Map(cached.map((item) => [getKey(item), item]));
546
+ const liveKeys = new Set(liveItems.map(getKey));
547
+ const mergedItems = liveItems.map((liveItem) => {
548
+ const key = getKey(liveItem);
549
+ const cachedItem = cachedByKey.get(key);
550
+ if (!cachedItem) return liveItem;
551
+ return mergeItem ? mergeItem(liveItem, cachedItem) : cachedItem;
552
+ });
553
+ for (const cachedItem of cached) {
554
+ if (!liveKeys.has(getKey(cachedItem))) {
555
+ const transformed = transformCachedOnly ? transformCachedOnly(cachedItem) : cachedItem;
556
+ mergedItems.push(transformed);
557
+ }
558
+ }
559
+ return mergedItems;
560
+ },
561
+ isConverged
562
+ );
563
+ };
564
+ var createAccountHydrationBuffer = (cachedAccounts, liveAccounts$, gracePeriodMs, getWalletId2, isConverged) => {
565
+ return createBufferCore(
566
+ cachedAccounts,
567
+ liveAccounts$,
568
+ gracePeriodMs,
569
+ (liveAccounts, cached) => {
570
+ const walletsWithLiveAccounts = new Set(liveAccounts.map(getWalletId2));
571
+ const mergedAccounts = [...liveAccounts];
572
+ for (const cachedAccount of cached) {
573
+ if (!walletsWithLiveAccounts.has(getWalletId2(cachedAccount))) {
574
+ mergedAccounts.push(cachedAccount);
575
+ }
576
+ }
577
+ return mergedAccounts;
578
+ },
579
+ isConverged
580
+ );
581
+ };
40
582
 
41
583
  // src/utils/logObservable.ts
42
- var import_rxjs = require("rxjs");
43
- var logObservable = (label, opts) => (0, import_rxjs.tap)((value) => {
584
+ var import_rxjs3 = require("rxjs");
585
+ var logObservable = (label, opts) => (0, import_rxjs3.tap)((value) => {
44
586
  const { printValue = false, enabled = true } = opts || {};
45
587
  if (!label || !enabled) return;
46
588
  const text = `[kheopskit] observable ${label} emit`;
@@ -49,7 +591,7 @@ var logObservable = (label, opts) => (0, import_rxjs.tap)((value) => {
49
591
  });
50
592
 
51
593
  // src/api/accounts.ts
52
- var import_rxjs5 = require("rxjs");
594
+ var import_rxjs7 = require("rxjs");
53
595
 
54
596
  // src/utils/sortAccounts.ts
55
597
  var sortAccounts = (a1, a2) => {
@@ -70,32 +612,43 @@ var sortAccounts = (a1, a2) => {
70
612
  if (a2.walletName === "Talisman") return 1;
71
613
  return a1.walletName.localeCompare(a2.walletName);
72
614
  }
73
- return 0;
615
+ return a1.id.localeCompare(a2.id);
74
616
  }
75
617
  return 0;
76
618
  };
77
619
 
78
620
  // src/api/ethereum/accounts.ts
79
- var import_rxjs3 = require("rxjs");
621
+ var import_rxjs5 = require("rxjs");
80
622
  var import_viem2 = require("viem");
81
623
 
82
624
  // src/utils/createStore.ts
83
- var import_rxjs2 = require("rxjs");
84
- var createStore = (key, defaultValue) => {
85
- const subject = new import_rxjs2.BehaviorSubject(getStoredData(key, defaultValue));
86
- (0, import_rxjs2.fromEvent)(window, "storage").pipe(
87
- (0, import_rxjs2.filter)((event) => event.key === key),
88
- (0, import_rxjs2.map)((event) => parseData(event.newValue, defaultValue))
89
- ).subscribe((newValue) => subject.next(newValue));
625
+ var import_rxjs4 = require("rxjs");
626
+ var createStore = (key, defaultValue, storage = safeLocalStorage) => {
627
+ const subject = new import_rxjs4.BehaviorSubject(
628
+ getStoredData(key, defaultValue, storage)
629
+ );
630
+ let unsubscribeStorage;
631
+ if (typeof window !== "undefined" && storage.subscribe) {
632
+ unsubscribeStorage = storage.subscribe(key, (newValue) => {
633
+ subject.next(parseData(newValue, defaultValue));
634
+ });
635
+ }
90
636
  const update = (val) => {
91
- setStoredData(key, val);
637
+ setStoredData(key, val, storage);
92
638
  subject.next(val);
93
639
  };
94
640
  return {
95
641
  observable: subject.asObservable(),
96
642
  set: (val) => update(val),
97
643
  mutate: (transform) => update(transform(subject.getValue())),
98
- get: () => structuredClone(subject.getValue())
644
+ get: () => structuredClone(subject.getValue()),
645
+ /**
646
+ * Cleanup subscriptions. Call this when the store is no longer needed.
647
+ */
648
+ destroy: () => {
649
+ unsubscribeStorage?.();
650
+ subject.complete();
651
+ }
99
652
  };
100
653
  };
101
654
  var parseData = (str, defaultValue) => {
@@ -105,13 +658,13 @@ var parseData = (str, defaultValue) => {
105
658
  }
106
659
  return defaultValue;
107
660
  };
108
- var getStoredData = (key, defaultValue) => {
109
- const str = localStorage.getItem(key);
661
+ var getStoredData = (key, defaultValue, storage) => {
662
+ const str = storage.getItem(key);
110
663
  return parseData(str, defaultValue);
111
664
  };
112
- var setStoredData = (key, val) => {
665
+ var setStoredData = (key, val, storage) => {
113
666
  const str = JSON.stringify(val);
114
- localStorage.setItem(key, str);
667
+ storage.setItem(key, str);
115
668
  };
116
669
 
117
670
  // src/utils/isEthereumAddress.ts
@@ -136,9 +689,6 @@ var isValidAddress = (address) => {
136
689
  return address.startsWith("0x") ? isEthereumAddress(address) : isSs58Address(address);
137
690
  };
138
691
 
139
- // src/utils/isWalletPlatform.ts
140
- var isWalletPlatform = (platform) => typeof platform === "string" && ["polkadot", "ethereum"].includes(platform);
141
-
142
692
  // src/utils/WalletAccountId.ts
143
693
  var getWalletAccountId = (walletId, address) => {
144
694
  if (!walletId) throw new Error("Missing walletId");
@@ -146,19 +696,12 @@ var getWalletAccountId = (walletId, address) => {
146
696
  return `${walletId}::${address}`;
147
697
  };
148
698
 
149
- // src/utils/getCachedObservable.ts
150
- var CACHE = /* @__PURE__ */ new Map();
151
- var getCachedObservable$ = (key, create) => {
152
- if (!CACHE.has(key)) CACHE.set(key, create());
153
- return CACHE.get(key);
154
- };
155
-
156
699
  // src/api/ethereum/accounts.ts
157
700
  var getInjectedWalletAccounts$ = (wallet) => {
158
- if (!wallet.isConnected) return (0, import_rxjs3.of)([]);
701
+ if (!wallet.isConnected) return (0, import_rxjs5.of)([]);
159
702
  return getCachedObservable$(
160
703
  `accounts:${wallet.id}`,
161
- () => new import_rxjs3.Observable((subscriber) => {
704
+ () => new import_rxjs5.Observable((subscriber) => {
162
705
  const getAccount = (address, i) => {
163
706
  const client = (0, import_viem2.createWalletClient)({
164
707
  account: address,
@@ -190,7 +733,7 @@ var getInjectedWalletAccounts$ = (wallet) => {
190
733
  handleAccountsChanged
191
734
  );
192
735
  };
193
- }).pipe((0, import_rxjs3.shareReplay)({ refCount: true, bufferSize: 1 }))
736
+ }).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }))
194
737
  );
195
738
  };
196
739
  var wrapWalletConnectProvider = (provider, sessionTopic, caipNetworkId) => {
@@ -211,19 +754,19 @@ var getAppKitAccounts$ = (wallet) => {
211
754
  const account = wallet.appKit.getAccount("eip155");
212
755
  const provider = wallet.appKit.getProvider("eip155");
213
756
  if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
214
- return (0, import_rxjs3.of)([]);
757
+ return (0, import_rxjs5.of)([]);
215
758
  return getCachedObservable$(
216
759
  "accounts:appKit",
217
- () => new import_rxjs3.Observable((subscriber) => {
218
- const caipNetworkId$ = new import_rxjs3.ReplaySubject(1);
760
+ () => new import_rxjs5.Observable((subscriber) => {
761
+ const caipNetworkId$ = new import_rxjs5.ReplaySubject(1);
219
762
  const handleChainChanged = (chainId) => {
220
763
  caipNetworkId$.next(`eip155:${chainId}`);
221
764
  };
222
765
  provider.on("chainChanged", handleChainChanged);
223
766
  provider.request({ method: "eth_chainId" }).then(handleChainChanged);
224
767
  const sub = caipNetworkId$.pipe(
225
- (0, import_rxjs3.distinctUntilChanged)(),
226
- (0, import_rxjs3.map)(
768
+ (0, import_rxjs5.distinctUntilChanged)(),
769
+ (0, import_rxjs5.map)(
227
770
  (caipNetworkId) => (0, import_viem2.custom)(
228
771
  wrapWalletConnectProvider(
229
772
  provider,
@@ -233,7 +776,7 @@ var getAppKitAccounts$ = (wallet) => {
233
776
  )
234
777
  )
235
778
  ),
236
- (0, import_rxjs3.map)(
779
+ (0, import_rxjs5.map)(
237
780
  (transport) => account.allAccounts.map((acc, i) => {
238
781
  const client = (0, import_viem2.createWalletClient)({
239
782
  account: acc.address,
@@ -255,28 +798,28 @@ var getAppKitAccounts$ = (wallet) => {
255
798
  provider.off("chainChanged", handleChainChanged);
256
799
  sub.unsubscribe();
257
800
  };
258
- }).pipe((0, import_rxjs3.shareReplay)({ refCount: true, bufferSize: 1 }))
801
+ }).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }))
259
802
  );
260
803
  };
261
- var getEthereumAccounts$ = (ethereumWallets) => new import_rxjs3.Observable((subscriber) => {
804
+ var getEthereumAccounts$ = (ethereumWallets) => new import_rxjs5.Observable((subscriber) => {
262
805
  const sub = ethereumWallets.pipe(
263
- (0, import_rxjs3.map)((wallets) => wallets.filter((w) => w.isConnected)),
264
- (0, import_rxjs3.switchMap)((wallets) => {
265
- return wallets.length ? (0, import_rxjs3.combineLatest)([
806
+ (0, import_rxjs5.map)((wallets) => wallets.filter((w) => w.isConnected)),
807
+ (0, import_rxjs5.switchMap)((wallets) => {
808
+ return wallets.length ? (0, import_rxjs5.combineLatest)([
266
809
  ...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$),
267
810
  ...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$)
268
811
  // todo appkit
269
- ]) : (0, import_rxjs3.of)([]);
812
+ ]) : (0, import_rxjs5.of)([]);
270
813
  }),
271
- (0, import_rxjs3.map)((accounts) => accounts.flat()),
272
- (0, import_rxjs3.distinctUntilChanged)(isSameAccountsList)
814
+ (0, import_rxjs5.map)((accounts) => accounts.flat()),
815
+ (0, import_rxjs5.distinctUntilChanged)(isSameAccountsList)
273
816
  ).subscribe(subscriber);
274
817
  return () => {
275
818
  sub.unsubscribe();
276
819
  };
277
820
  }).pipe(
278
821
  // logObservable("ethereumAccounts$", true),
279
- (0, import_rxjs3.shareReplay)({ refCount: true, bufferSize: 1 })
822
+ (0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 })
280
823
  );
281
824
  var isSameAccountsList = (a, b) => {
282
825
  if (a.length !== b.length) return false;
@@ -285,10 +828,10 @@ var isSameAccountsList = (a, b) => {
285
828
 
286
829
  // src/api/polkadot/accounts.ts
287
830
  var import_pjs_signer = require("polkadot-api/pjs-signer");
288
- var import_rxjs4 = require("rxjs");
831
+ var import_rxjs6 = require("rxjs");
289
832
  var getInjectedWalletAccounts$2 = (wallet) => {
290
- if (!wallet.isConnected) return (0, import_rxjs4.of)([]);
291
- return new import_rxjs4.Observable((subscriber) => {
833
+ if (!wallet.isConnected) return (0, import_rxjs6.of)([]);
834
+ return new import_rxjs6.Observable((subscriber) => {
292
835
  const getAccount = (account) => ({
293
836
  id: getWalletAccountId(wallet.id, account.address),
294
837
  ...account,
@@ -349,8 +892,8 @@ var getAppKitAccounts$2 = (wallet) => {
349
892
  const account = wallet.appKit.getAccount("polkadot");
350
893
  const provider = wallet.appKit.getProvider("polkadot");
351
894
  if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
352
- return (0, import_rxjs4.of)([]);
353
- return (0, import_rxjs4.of)(
895
+ return (0, import_rxjs6.of)([]);
896
+ return (0, import_rxjs6.of)(
354
897
  account.allAccounts.map(
355
898
  (acc) => ({
356
899
  id: getWalletAccountId(wallet.id, acc.address),
@@ -366,22 +909,22 @@ var getAppKitAccounts$2 = (wallet) => {
366
909
  )
367
910
  );
368
911
  };
369
- var getPolkadotAccounts$ = (polkadotWallets$) => new import_rxjs4.Observable((subscriber) => {
912
+ var getPolkadotAccounts$ = (polkadotWallets$) => new import_rxjs6.Observable((subscriber) => {
370
913
  const sub = polkadotWallets$.pipe(
371
- (0, import_rxjs4.map)((wallets) => wallets.filter((w) => w.isConnected)),
372
- (0, import_rxjs4.switchMap)(
373
- (wallets) => wallets.length ? (0, import_rxjs4.combineLatest)([
914
+ (0, import_rxjs6.map)((wallets) => wallets.filter((w) => w.isConnected)),
915
+ (0, import_rxjs6.switchMap)(
916
+ (wallets) => wallets.length ? (0, import_rxjs6.combineLatest)([
374
917
  ...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$2),
375
918
  ...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$2)
376
- ]) : (0, import_rxjs4.of)([])
919
+ ]) : (0, import_rxjs6.of)([])
377
920
  ),
378
- (0, import_rxjs4.map)((accounts) => accounts.flat()),
379
- (0, import_rxjs4.distinctUntilChanged)(isSameAccountsList2)
921
+ (0, import_rxjs6.map)((accounts) => accounts.flat()),
922
+ (0, import_rxjs6.distinctUntilChanged)(isSameAccountsList2)
380
923
  ).subscribe(subscriber);
381
924
  return () => {
382
925
  sub.unsubscribe();
383
926
  };
384
- }).pipe((0, import_rxjs4.shareReplay)({ refCount: true, bufferSize: 1 }));
927
+ }).pipe((0, import_rxjs6.shareReplay)({ refCount: true, bufferSize: 1 }));
385
928
  var isSameAccountsList2 = (a, b) => {
386
929
  if (a.length !== b.length) return false;
387
930
  return a.every((account, i) => account.id === b[i]?.id);
@@ -389,37 +932,206 @@ var isSameAccountsList2 = (a, b) => {
389
932
 
390
933
  // src/api/accounts.ts
391
934
  var getAccounts$ = (config, wallets) => {
392
- return new import_rxjs5.Observable((subscriber) => {
935
+ return new import_rxjs7.Observable((subscriber) => {
393
936
  const sources = config.platforms.map(
394
937
  (platform) => {
395
938
  switch (platform) {
396
939
  case "polkadot":
397
940
  return getPolkadotAccounts$(
398
941
  wallets.pipe(
399
- (0, import_rxjs5.map)((w) => w.filter((w2) => w2.platform === "polkadot"))
942
+ (0, import_rxjs7.map)((w) => w.filter((w2) => w2.platform === "polkadot"))
400
943
  )
401
944
  );
402
945
  case "ethereum":
403
946
  return getEthereumAccounts$(
404
947
  wallets.pipe(
405
- (0, import_rxjs5.map)((w) => w.filter((w2) => w2.platform === "ethereum"))
948
+ (0, import_rxjs7.map)((w) => w.filter((w2) => w2.platform === "ethereum"))
406
949
  )
407
950
  );
408
951
  }
409
952
  }
410
953
  );
411
- const accounts$ = sources.length ? (0, import_rxjs5.combineLatest)(sources).pipe(
412
- (0, import_rxjs5.map)((accounts) => accounts.flat().sort(sortAccounts))
413
- ) : (0, import_rxjs5.of)([]);
954
+ const accounts$ = sources.length ? (0, import_rxjs7.combineLatest)(sources).pipe(
955
+ (0, import_rxjs7.map)((accounts) => accounts.flat().sort(sortAccounts))
956
+ ) : (0, import_rxjs7.of)([]);
414
957
  const sub = accounts$.subscribe(subscriber);
415
958
  return () => {
416
959
  sub.unsubscribe();
417
960
  };
418
- }).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }));
961
+ }).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
962
+ };
963
+
964
+ // src/api/store.ts
965
+ var import_lodash_es = require("lodash-es");
966
+ var DEFAULT_SETTINGS = {};
967
+ var createKheopskitStore = (options = {}) => {
968
+ const { ssrCookies, storageKey = DEFAULT_STORAGE_KEY } = options;
969
+ const storage = ssrCookies !== void 0 ? createCompactCookieStorage(ssrCookies) : safeLocalStorage;
970
+ const store2 = createStore(storageKey, DEFAULT_SETTINGS, storage);
971
+ const addEnabledWalletId = (walletId) => {
972
+ parseWalletId(walletId);
973
+ store2.mutate((prev) => ({
974
+ ...prev,
975
+ autoReconnect: (0, import_lodash_es.uniq)((prev.autoReconnect ?? []).concat(walletId))
976
+ }));
977
+ };
978
+ const removeEnabledWalletId = (walletId) => {
979
+ store2.mutate((prev) => ({
980
+ ...prev,
981
+ autoReconnect: (0, import_lodash_es.uniq)(
982
+ (prev.autoReconnect ?? []).filter((id) => id !== walletId)
983
+ )
984
+ }));
985
+ };
986
+ const getCachedState = () => {
987
+ const data = store2.get();
988
+ return {
989
+ wallets: data.cachedWallets ?? [],
990
+ accounts: data.cachedAccounts ?? []
991
+ };
992
+ };
993
+ const setCachedState = (wallets, accounts) => {
994
+ store2.mutate((prev) => ({
995
+ ...prev,
996
+ cachedWallets: wallets,
997
+ cachedAccounts: accounts
998
+ }));
999
+ };
1000
+ return {
1001
+ observable: store2.observable,
1002
+ addEnabledWalletId,
1003
+ removeEnabledWalletId,
1004
+ getCachedState,
1005
+ setCachedState
1006
+ };
1007
+ };
1008
+ var _defaultStore = null;
1009
+ var getDefaultStore = () => {
1010
+ if (_defaultStore === null) {
1011
+ _defaultStore = createKheopskitStore();
1012
+ }
1013
+ return _defaultStore;
1014
+ };
1015
+ var store = {
1016
+ get observable() {
1017
+ return getDefaultStore().observable;
1018
+ },
1019
+ addEnabledWalletId: (walletId) => getDefaultStore().addEnabledWalletId(walletId),
1020
+ removeEnabledWalletId: (walletId) => getDefaultStore().removeEnabledWalletId(walletId),
1021
+ getCachedState: () => getDefaultStore().getCachedState(),
1022
+ setCachedState: (wallets, accounts) => getDefaultStore().setCachedState(wallets, accounts)
1023
+ };
1024
+ var isCompactStore = (value) => {
1025
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1026
+ if ("cachedWallets" in value || "cachedAccounts" in value) return false;
1027
+ return "v" in value || "w" in value || "a" in value || "r" in value;
1028
+ };
1029
+ var toCompactStore = (data) => {
1030
+ const wallets = data.cachedWallets?.map(
1031
+ (wallet) => [
1032
+ wallet.id,
1033
+ wallet.name,
1034
+ wallet.isConnected ? 1 : 0,
1035
+ wallet.type === "appKit" ? 1 : 0
1036
+ ]
1037
+ );
1038
+ const accounts = data.cachedAccounts?.map(
1039
+ (account) => [
1040
+ account.walletId,
1041
+ account.address,
1042
+ account.name ?? null
1043
+ ]
1044
+ );
1045
+ return {
1046
+ v: 1,
1047
+ r: data.autoReconnect,
1048
+ w: wallets?.length ? wallets : void 0,
1049
+ a: accounts?.length ? accounts : void 0
1050
+ };
1051
+ };
1052
+ var fromCompactStore = (data) => {
1053
+ const walletNameMap = /* @__PURE__ */ new Map();
1054
+ const wallets = (data.w ?? []).map((item) => {
1055
+ const [id, name, isConnected, type] = item;
1056
+ walletNameMap.set(id, name);
1057
+ const { platform } = parseWalletId(id);
1058
+ return {
1059
+ id,
1060
+ platform,
1061
+ type: type === 1 ? "appKit" : "injected",
1062
+ name,
1063
+ isConnected: isConnected === 1
1064
+ };
1065
+ });
1066
+ const accounts = (data.a ?? []).map((item) => {
1067
+ const [walletId, address, name] = item;
1068
+ const { platform } = parseWalletId(walletId);
1069
+ return {
1070
+ id: getWalletAccountId(walletId, address),
1071
+ platform,
1072
+ address,
1073
+ name: name ?? void 0,
1074
+ walletId,
1075
+ walletName: walletNameMap.get(walletId) ?? walletId
1076
+ };
1077
+ });
1078
+ return {
1079
+ autoReconnect: data.r,
1080
+ cachedWallets: wallets,
1081
+ cachedAccounts: accounts
1082
+ };
1083
+ };
1084
+ var decodeStore = (raw, fallback) => {
1085
+ try {
1086
+ const parsed = JSON.parse(raw);
1087
+ if (isCompactStore(parsed)) return fromCompactStore(parsed);
1088
+ return parsed;
1089
+ } catch {
1090
+ return fallback;
1091
+ }
1092
+ };
1093
+ var encodeStore = (data) => JSON.stringify(toCompactStore(data));
1094
+ var createCompactCookieStorage = (initialCookies) => {
1095
+ const base = cookieStorage(initialCookies);
1096
+ return {
1097
+ getItem: (key) => {
1098
+ const raw = base.getItem(key);
1099
+ if (!raw) return null;
1100
+ const expanded = decodeStore(raw, DEFAULT_SETTINGS);
1101
+ if (typeof document !== "undefined") {
1102
+ try {
1103
+ const parsed = JSON.parse(raw);
1104
+ if (!isCompactStore(parsed)) {
1105
+ base.setItem(key, encodeStore(expanded));
1106
+ }
1107
+ } catch {
1108
+ }
1109
+ }
1110
+ return JSON.stringify(expanded);
1111
+ },
1112
+ setItem: (key, value) => {
1113
+ const expanded = decodeStore(value, DEFAULT_SETTINGS);
1114
+ base.setItem(key, encodeStore(expanded));
1115
+ },
1116
+ removeItem: base.removeItem,
1117
+ subscribe: (key, callback) => {
1118
+ const unsubscribe = base.subscribe?.(key, (value) => {
1119
+ if (!value) {
1120
+ callback(null);
1121
+ return;
1122
+ }
1123
+ const expanded = decodeStore(value, DEFAULT_SETTINGS);
1124
+ callback(JSON.stringify(expanded));
1125
+ });
1126
+ return () => {
1127
+ unsubscribe?.();
1128
+ };
1129
+ }
1130
+ };
419
1131
  };
420
1132
 
421
1133
  // src/api/wallets.ts
422
- var import_rxjs9 = require("rxjs");
1134
+ var import_rxjs10 = require("rxjs");
423
1135
 
424
1136
  // src/utils/sortWallets.ts
425
1137
  var sortWallets = (w1, w2) => {
@@ -433,246 +1145,101 @@ var sortWallets = (w1, w2) => {
433
1145
 
434
1146
  // src/api/ethereum/wallets.ts
435
1147
  var import_mipd = require("mipd");
436
- var import_rxjs7 = require("rxjs");
437
-
438
- // src/api/store.ts
439
- var import_lodash = require("lodash");
440
-
441
- // src/utils/WalletId.ts
442
- var getWalletId = (platform, identifier) => {
443
- if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
444
- if (!identifier) throw new Error("Invalid name");
445
- return `${platform}:${identifier}`;
446
- };
447
- var parseWalletId = (walletId) => {
448
- if (!walletId) throw new Error("Invalid walletId");
449
- const [platform, identifier] = walletId.split(":");
450
- if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
451
- if (!identifier) throw new Error("Invalid address");
452
- return { platform, identifier };
453
- };
454
-
455
- // src/api/store.ts
456
- var LOCAL_STORAGE_KEY = "kheopskit";
457
- var DEFAULT_SETTINGS = {};
458
- var storage = createStore(LOCAL_STORAGE_KEY, DEFAULT_SETTINGS);
459
- var addEnabledWalletId = (walletId) => {
460
- parseWalletId(walletId);
461
- storage.mutate((prev) => ({
462
- ...prev,
463
- autoReconnect: (0, import_lodash.uniq)((prev.autoReconnect ?? []).concat(walletId))
464
- }));
465
- };
466
- var removeEnabledWalletId = (walletId) => {
467
- storage.mutate((prev) => ({
468
- ...prev,
469
- autoReconnect: (0, import_lodash.uniq)(
470
- (prev.autoReconnect ?? []).filter((id) => id !== walletId)
471
- )
472
- }));
473
- };
474
- var store = {
475
- observable: storage.observable,
476
- addEnabledWalletId,
477
- removeEnabledWalletId
478
- };
479
-
480
- // src/api/appKit.ts
481
- var import_core = require("@reown/appkit/core");
482
- var import_rxjs6 = require("rxjs");
483
- var WALLET_CONNECT_ICON = "data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDQwMCA0MDAiIHdpZHR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S0xNS4yOWMyLjEzOTYtMi4wODYgNS42MDg1LTIuMDg2IDcuNzQ4MSAwbDUwLjE3ODkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3Ny00OC45MzJjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMGw1MC4xNzkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3OS00OC45MzFjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+";
484
- var cachedAppKit = null;
485
- var getAppKitWallets$ = (config) => {
486
- if (!config.walletConnect) return (0, import_rxjs6.of)({});
487
- const walletConnect = config.walletConnect;
488
- if (!cachedAppKit) {
489
- cachedAppKit = new import_rxjs6.Observable((subscriber) => {
490
- const appKit = (0, import_core.createAppKit)({
491
- projectId: walletConnect.projectId,
492
- metadata: walletConnect.metadata,
493
- networks: walletConnect.networks,
494
- themeMode: walletConnect.themeMode,
495
- themeVariables: walletConnect.themeVariables,
496
- universalProviderConfigOverride: {
497
- methods: {
498
- polkadot: ["polkadot_signTransaction", "polkadot_signMessage"]
499
- }
500
- },
501
- allWallets: "HIDE",
502
- debug: config.debug,
503
- allowUnsupportedChain: true
504
- });
505
- const status$ = new import_rxjs6.BehaviorSubject({
506
- isPolkadotConnected: false,
507
- isEthereumConnected: false
508
- });
509
- const unsubProviders = appKit.subscribeProviders((providers) => {
510
- status$.next({
511
- isPolkadotConnected: !!providers.polkadot,
512
- isEthereumConnected: !!providers.eip155
513
- });
514
- });
515
- const polkadotWallet$ = appKit.chainNamespaces.includes("polkadot") ? status$.pipe(
516
- (0, import_rxjs6.map)((s) => s.isPolkadotConnected),
517
- (0, import_rxjs6.distinctUntilChanged)(),
518
- (0, import_rxjs6.map)((isConnected) => {
519
- const walletInfo = appKit.getWalletInfo();
520
- return {
521
- id: getWalletId("polkadot", "walletconnect"),
522
- platform: "polkadot",
523
- type: "appKit",
524
- appKit,
525
- // todo maybe we dont want to expose the appKit instance
526
- name: walletInfo?.name ?? "WalletConnect",
527
- icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
528
- connect: async () => {
529
- if (!isConnected) await appKit.open();
530
- },
531
- disconnect: () => {
532
- if (isConnected) appKit.disconnect();
533
- },
534
- isConnected
535
- };
536
- })
537
- ) : (0, import_rxjs6.of)(void 0);
538
- const ethereumWallet$ = appKit.chainNamespaces.includes("eip155") ? status$.pipe(
539
- (0, import_rxjs6.map)((s) => s.isEthereumConnected),
540
- (0, import_rxjs6.distinctUntilChanged)(),
541
- (0, import_rxjs6.map)((isConnected) => {
542
- const walletInfo = appKit.getWalletInfo();
543
- return {
544
- id: getWalletId("ethereum", "walletconnect"),
545
- platform: "ethereum",
546
- type: "appKit",
547
- appKit,
548
- name: walletInfo?.name ?? "WalletConnect",
549
- icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
550
- connect: () => appKit.open(),
551
- disconnect: () => appKit.disconnect(),
552
- isConnected
553
- };
554
- })
555
- ) : (0, import_rxjs6.of)(void 0);
556
- const sub = (0, import_rxjs6.combineLatest)({
557
- polkadot: polkadotWallet$,
558
- ethereum: ethereumWallet$
559
- }).subscribe(subscriber);
1148
+ var import_rxjs8 = require("rxjs");
1149
+ var providersDetails$ = new import_rxjs8.Observable(
1150
+ (subscriber) => {
1151
+ if (typeof window === "undefined") {
1152
+ subscriber.next([]);
560
1153
  return () => {
561
- sub.unsubscribe();
562
- unsubProviders();
563
1154
  };
564
- }).pipe((0, import_rxjs6.shareReplay)({ refCount: true, bufferSize: 1 }));
565
- }
566
- return cachedAppKit;
567
- };
568
-
569
- // src/api/ethereum/wallets.ts
570
- var providersDetails$ = new import_rxjs7.Observable(
571
- (subscriber) => {
572
- const store2 = (0, import_mipd.createStore)();
573
- const unsubscribe = store2.subscribe((providerDetails2) => {
1155
+ }
1156
+ const mipdStore = (0, import_mipd.createStore)();
1157
+ const unsubscribe = mipdStore.subscribe((providerDetails2) => {
574
1158
  subscriber.next(providerDetails2);
575
1159
  });
576
- const providerDetails = store2.getProviders();
1160
+ const providerDetails = mipdStore.getProviders();
577
1161
  subscriber.next(providerDetails);
578
1162
  return () => {
579
1163
  unsubscribe();
580
- store2.destroy();
1164
+ mipdStore.destroy();
581
1165
  };
582
1166
  }
583
- ).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
584
- var ethereumInjectedWallets$ = new import_rxjs7.Observable(
585
- (subscriber) => {
586
- const enabledWalletIds$ = new import_rxjs7.BehaviorSubject(/* @__PURE__ */ new Set());
587
- const connectWallet = async (walletId, provider) => {
588
- if (enabledWalletIds$.value.has(walletId))
589
- throw new Error(`Extension ${walletId} already connected`);
590
- await provider.request({
591
- method: "eth_requestAccounts"
1167
+ ).pipe((0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 }));
1168
+ var createEthereumInjectedWallets$ = (store2) => new import_rxjs8.Observable((subscriber) => {
1169
+ const enabledWalletIds$ = new import_rxjs8.BehaviorSubject(/* @__PURE__ */ new Set());
1170
+ const connectWallet = async (walletId, provider) => {
1171
+ if (enabledWalletIds$.value.has(walletId))
1172
+ throw new Error(`Extension ${walletId} already connected`);
1173
+ await provider.request({
1174
+ method: "eth_requestAccounts"
1175
+ });
1176
+ const newSet = new Set(enabledWalletIds$.value);
1177
+ newSet.add(walletId);
1178
+ enabledWalletIds$.next(newSet);
1179
+ store2.addEnabledWalletId(walletId);
1180
+ };
1181
+ const disconnectWallet = async (walletId) => {
1182
+ if (!enabledWalletIds$.value.has(walletId))
1183
+ throw new Error(`Extension ${walletId} is not connected`);
1184
+ const newSet = new Set(enabledWalletIds$.value);
1185
+ newSet.delete(walletId);
1186
+ enabledWalletIds$.next(newSet);
1187
+ store2.removeEnabledWalletId(walletId);
1188
+ };
1189
+ const sub = (0, import_rxjs8.combineLatest)([providersDetails$, enabledWalletIds$]).pipe(
1190
+ (0, import_rxjs8.map)(([providerDetails, enabledWalletIds]) => {
1191
+ return providerDetails.map((pd) => {
1192
+ const walletId = getWalletId("ethereum", pd.info.rdns);
1193
+ const provider = pd.provider;
1194
+ return {
1195
+ platform: "ethereum",
1196
+ type: "injected",
1197
+ id: walletId,
1198
+ name: pd.info.name,
1199
+ icon: pd.info.icon,
1200
+ provider,
1201
+ isConnected: enabledWalletIds.has(walletId),
1202
+ providerId: pd.info.rdns,
1203
+ connect: () => connectWallet(walletId, provider),
1204
+ disconnect: () => disconnectWallet(walletId)
1205
+ };
592
1206
  });
593
- const newSet = new Set(enabledWalletIds$.value);
594
- newSet.add(walletId);
595
- enabledWalletIds$.next(newSet);
596
- store.addEnabledWalletId(walletId);
597
- };
598
- const disconnectWallet = async (walletId) => {
599
- if (!enabledWalletIds$.value.has(walletId))
600
- throw new Error(`Extension ${walletId} is not connected`);
601
- const newSet = new Set(enabledWalletIds$.value);
602
- newSet.delete(walletId);
603
- enabledWalletIds$.next(newSet);
604
- store.removeEnabledWalletId(walletId);
605
- };
606
- const sub = (0, import_rxjs7.combineLatest)([providersDetails$, enabledWalletIds$]).pipe(
607
- (0, import_rxjs7.map)(([providerDetails, enabledWalletIds]) => {
608
- return providerDetails.map((pd) => {
609
- const walletId = getWalletId("ethereum", pd.info.rdns);
610
- const provider = pd.provider;
611
- return {
612
- platform: "ethereum",
613
- type: "injected",
614
- id: walletId,
615
- name: pd.info.name,
616
- icon: pd.info.icon,
617
- provider,
618
- isConnected: enabledWalletIds.has(walletId),
619
- providerId: pd.info.rdns,
620
- connect: () => connectWallet(walletId, provider),
621
- disconnect: () => disconnectWallet(walletId)
622
- };
623
- });
624
- })
625
- ).subscribe(subscriber);
626
- return () => {
627
- sub.unsubscribe();
628
- };
629
- }
630
- ).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
631
- var getEthereumWallets$ = (config) => {
632
- return new import_rxjs7.Observable((subscriber) => {
633
- const subscription = (0, import_rxjs7.combineLatest)([
634
- ethereumInjectedWallets$,
635
- getAppKitWallets$(config)?.pipe((0, import_rxjs7.map)((w) => w.ethereum))
1207
+ }),
1208
+ (0, import_rxjs8.distinctUntilChanged)(walletsEqual)
1209
+ ).subscribe(subscriber);
1210
+ return () => {
1211
+ sub.unsubscribe();
1212
+ };
1213
+ }).pipe((0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 }));
1214
+ var getEthereumWallets$ = (config, store2 = store) => {
1215
+ return new import_rxjs8.Observable((subscriber) => {
1216
+ const subscription = (0, import_rxjs8.combineLatest)([
1217
+ createEthereumInjectedWallets$(store2),
1218
+ getAppKitWallets$(config)?.pipe((0, import_rxjs8.map)((w) => w.ethereum))
636
1219
  ]).pipe(
637
- (0, import_rxjs7.map)(
1220
+ (0, import_rxjs8.map)(
638
1221
  ([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
639
1222
  )
640
1223
  ).subscribe(subscriber);
641
1224
  return () => {
642
1225
  subscription.unsubscribe();
643
1226
  };
644
- }).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
1227
+ }).pipe((0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 }));
645
1228
  };
646
-
647
- // src/api/polkadot/wallets.ts
648
- var import_lodash2 = require("lodash");
649
- var import_pjs_signer2 = require("polkadot-api/pjs-signer");
650
- var import_rxjs8 = require("rxjs");
651
-
652
- // src/utils/polkadotExtensions.ts
653
- var POLKADOT_EXTENSIONS = {
654
- talisman: {
655
- name: "Talisman",
656
- icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBmaWxsPSIjZGRmZTc2IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wIDcwLjI1YzAgMjEuMjU1IDAgMzEuODgzIDQuNDYzIDM5Ljg1MmE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BncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNDNTQ5RkYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjU0QkZGIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg=="
669
- }
1229
+ var walletsEqual = (a, b) => {
1230
+ if (a.length !== b.length) return false;
1231
+ return a.every(
1232
+ (w, i) => w.id === b[i]?.id && w.isConnected === b[i]?.isConnected && w.name === b[i]?.name
1233
+ );
670
1234
  };
671
1235
 
672
1236
  // src/api/polkadot/wallets.ts
673
- var getInjectedWalletsIds = () => (0, import_pjs_signer2.getInjectedExtensions)().map((name) => getWalletId("polkadot", name));
1237
+ var import_lodash_es2 = require("lodash-es");
1238
+ var import_pjs_signer2 = require("polkadot-api/pjs-signer");
1239
+ var import_rxjs9 = require("rxjs");
1240
+ var getInjectedWalletsIds = () => typeof window === "undefined" ? [] : (0, import_pjs_signer2.getInjectedExtensions)().map((name) => getWalletId("polkadot", name));
674
1241
  var createWalletIdsPoller$ = () => {
675
- return new import_rxjs8.Observable((subscriber) => {
1242
+ return new import_rxjs9.Observable((subscriber) => {
676
1243
  subscriber.next(getInjectedWalletsIds());
677
1244
  const intervals = [100, 200, 300, 500];
678
1245
  let index = 0;
@@ -689,12 +1256,12 @@ var createWalletIdsPoller$ = () => {
689
1256
  return () => {
690
1257
  };
691
1258
  }).pipe(
692
- (0, import_rxjs8.distinctUntilChanged)(import_lodash2.isEqual),
693
- (0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 })
1259
+ (0, import_rxjs9.distinctUntilChanged)(import_lodash_es2.isEqual),
1260
+ (0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 })
694
1261
  );
695
1262
  };
696
- var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
697
- const enabledExtensions$ = new import_rxjs8.BehaviorSubject(/* @__PURE__ */ new Map());
1263
+ var createPolkadotInjectedWallets$ = (store2) => new import_rxjs9.Observable((subscriber) => {
1264
+ const enabledExtensions$ = new import_rxjs9.BehaviorSubject(/* @__PURE__ */ new Map());
698
1265
  const connect = async (walletId) => {
699
1266
  if (enabledExtensions$.value.has(walletId))
700
1267
  throw new Error(`Extension ${walletId} already connected`);
@@ -703,7 +1270,7 @@ var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
703
1270
  const newMap = new Map(enabledExtensions$.value);
704
1271
  newMap.set(walletId, extension);
705
1272
  enabledExtensions$.next(newMap);
706
- store.addEnabledWalletId(walletId);
1273
+ store2.addEnabledWalletId(walletId);
707
1274
  };
708
1275
  const disconnect = (walletId) => {
709
1276
  if (!enabledExtensions$.value.has(walletId))
@@ -711,11 +1278,11 @@ var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
711
1278
  const newMap = new Map(enabledExtensions$.value);
712
1279
  newMap.delete(walletId);
713
1280
  enabledExtensions$.next(newMap);
714
- store.removeEnabledWalletId(walletId);
1281
+ store2.removeEnabledWalletId(walletId);
715
1282
  };
716
1283
  const walletIds$ = createWalletIdsPoller$();
717
- const subscription = (0, import_rxjs8.combineLatest)([walletIds$, enabledExtensions$]).pipe(
718
- (0, import_rxjs8.map)(([walletIds, enabledExtensions]) => {
1284
+ const subscription = (0, import_rxjs9.combineLatest)([walletIds$, enabledExtensions$]).pipe(
1285
+ (0, import_rxjs9.map)(([walletIds, enabledExtensions]) => {
719
1286
  return walletIds.map((id) => {
720
1287
  const { identifier } = parseWalletId(id);
721
1288
  const extension = enabledExtensions.get(id);
@@ -733,64 +1300,64 @@ var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
733
1300
  disconnect: () => disconnect(id)
734
1301
  };
735
1302
  });
736
- })
1303
+ }),
1304
+ (0, import_rxjs9.distinctUntilChanged)(walletsEqual2)
737
1305
  ).subscribe(subscriber);
738
1306
  return () => {
739
1307
  subscription.unsubscribe();
740
1308
  };
741
- }).pipe(
742
- // logObservable("polkadotInjectedWallets$"),
743
- (0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 })
744
- );
745
- var getPolkadotWallets$ = (config) => {
746
- return new import_rxjs8.Observable((subscriber) => {
747
- const subscription = (0, import_rxjs8.combineLatest)([
748
- polkadotInjectedWallets$,
749
- getAppKitWallets$(config)?.pipe((0, import_rxjs8.map)((w) => w.polkadot))
1309
+ }).pipe((0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 }));
1310
+ var getPolkadotWallets$ = (config, store2 = store) => {
1311
+ return new import_rxjs9.Observable((subscriber) => {
1312
+ const subscription = (0, import_rxjs9.combineLatest)([
1313
+ createPolkadotInjectedWallets$(store2),
1314
+ getAppKitWallets$(config)?.pipe((0, import_rxjs9.map)((w) => w.polkadot))
750
1315
  ]).pipe(
751
- (0, import_rxjs8.map)(
1316
+ (0, import_rxjs9.map)(
752
1317
  ([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
753
1318
  )
754
1319
  ).subscribe(subscriber);
755
1320
  return () => {
756
1321
  subscription.unsubscribe();
757
1322
  };
758
- }).pipe(
759
- // logObservable("getPolkadotWallets$"),
760
- (0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 })
1323
+ }).pipe((0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 }));
1324
+ };
1325
+ var walletsEqual2 = (a, b) => {
1326
+ if (a.length !== b.length) return false;
1327
+ return a.every(
1328
+ (w, i) => w.id === b[i]?.id && w.isConnected === b[i]?.isConnected && w.name === b[i]?.name
761
1329
  );
762
1330
  };
763
1331
 
764
1332
  // src/api/wallets.ts
765
- var autoReconnectWalletIds$ = store.observable.pipe(
766
- (0, import_rxjs9.map)((s) => s.autoReconnect ?? []),
767
- (0, import_rxjs9.take)(1),
768
- (0, import_rxjs9.shareReplay)(1)
769
- );
770
- var getWallets$ = (config) => {
771
- return new import_rxjs9.Observable((subscriber) => {
1333
+ var getWallets$ = (config, store2 = store) => {
1334
+ const autoReconnectWalletIds$ = store2.observable.pipe(
1335
+ (0, import_rxjs10.map)((s) => s.autoReconnect ?? []),
1336
+ (0, import_rxjs10.take)(1),
1337
+ (0, import_rxjs10.shareReplay)({ bufferSize: 1, refCount: true })
1338
+ );
1339
+ return new import_rxjs10.Observable((subscriber) => {
772
1340
  const observables = config.platforms.map(
773
1341
  (platform) => {
774
1342
  switch (platform) {
775
1343
  case "polkadot":
776
- return getPolkadotWallets$(config);
1344
+ return getPolkadotWallets$(config, store2);
777
1345
  case "ethereum":
778
- return getEthereumWallets$(config);
1346
+ return getEthereumWallets$(config, store2);
779
1347
  }
780
1348
  }
781
1349
  );
782
- const wallets$ = observables.length ? (0, import_rxjs9.combineLatest)(observables).pipe(
783
- (0, import_rxjs9.map)((wallets) => wallets.flat().sort(sortWallets)),
784
- // Emit empty array immediately so UI doesn't wait
785
- (0, import_rxjs9.startWith)([])
786
- ) : (0, import_rxjs9.of)([]);
1350
+ const wallets$ = observables.length ? (0, import_rxjs10.combineLatest)(observables).pipe(
1351
+ (0, import_rxjs10.map)((wallets) => wallets.flat().sort(sortWallets))
1352
+ // Note: No startWith([]) here - the hydration buffer handles initial state
1353
+ ) : (0, import_rxjs10.of)([]);
787
1354
  const reconnectingWallets = /* @__PURE__ */ new Set();
788
- const subAutoReconnect = (0, import_rxjs9.combineLatest)([wallets$, autoReconnectWalletIds$]).pipe(
789
- (0, import_rxjs9.filter)(([, walletIds]) => config.autoReconnect && !!walletIds?.length),
790
- (0, import_rxjs9.mergeMap)(
1355
+ const subAutoReconnect = (0, import_rxjs10.combineLatest)([wallets$, autoReconnectWalletIds$]).pipe(
1356
+ (0, import_rxjs10.filter)(([, walletIds]) => config.autoReconnect && !!walletIds?.length),
1357
+ (0, import_rxjs10.mergeMap)(
791
1358
  ([wallets, walletIds]) => wallets.filter((wallet) => walletIds?.includes(wallet.id))
792
1359
  ),
793
- (0, import_rxjs9.distinct)((w) => w.id)
1360
+ (0, import_rxjs10.distinct)((w) => w.id)
794
1361
  ).subscribe(async (wallet) => {
795
1362
  if (wallet.isConnected || reconnectingWallets.has(wallet.id)) {
796
1363
  return;
@@ -809,32 +1376,176 @@ var getWallets$ = (config) => {
809
1376
  subAutoReconnect.unsubscribe();
810
1377
  subWallets.unsubscribe();
811
1378
  };
812
- }).pipe((0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 }));
1379
+ }).pipe((0, import_rxjs10.shareReplay)({ refCount: true, bufferSize: 1 }));
813
1380
  };
814
1381
 
815
1382
  // src/api/kheopskit.ts
816
- var getKheopskit$ = (config) => {
1383
+ var getKheopskit$ = (config, ssrCookies, existingStore) => {
817
1384
  const kc = resolveConfig(config);
818
- console.debug("[kheopskit] config", kc);
819
- return new import_rxjs10.Observable((subscriber) => {
820
- const wallets$ = getWallets$(kc);
821
- const subscription = (0, import_rxjs10.combineLatest)({
822
- wallets: wallets$,
823
- accounts: getAccounts$(kc, wallets$)
824
- }).pipe((0, import_rxjs10.map)(({ wallets, accounts }) => ({ config: kc, wallets, accounts }))).subscribe(subscriber);
1385
+ const store2 = existingStore ?? createKheopskitStore({ ssrCookies, storageKey: kc.storageKey });
1386
+ if (kc.debug) console.debug("[kheopskit] config", kc);
1387
+ if (kc.debug && typeof window === "undefined" && ssrCookies === void 0) {
1388
+ console.warn(
1389
+ "[kheopskit] Running on server without `ssrCookies`. Wallet state will not be hydrated. Pass cookies for SSR support."
1390
+ );
1391
+ }
1392
+ const cachedState = store2.getCachedState();
1393
+ const cachedWallets = cachedState.wallets.map((w) => {
1394
+ const wallet = hydrateWallet(w);
1395
+ if (!wallet.icon) {
1396
+ const cachedIcon = getCachedIcon(wallet.id);
1397
+ if (cachedIcon) {
1398
+ return { ...wallet, icon: cachedIcon };
1399
+ }
1400
+ }
1401
+ return wallet;
1402
+ });
1403
+ const cachedAccounts = cachedState.accounts.map(hydrateAccount);
1404
+ if (kc.debug && cachedWallets.length > 0) {
1405
+ console.debug("[kheopskit] hydrating from cache:", {
1406
+ wallets: cachedWallets.length,
1407
+ accounts: cachedAccounts.length
1408
+ });
1409
+ }
1410
+ return new import_rxjs11.Observable((subscriber) => {
1411
+ const liveWallets$ = getWallets$(kc, store2);
1412
+ const liveAccounts$ = getAccounts$(kc, liveWallets$);
1413
+ const bufferedWallets$ = createHydrationBuffer(
1414
+ cachedWallets,
1415
+ liveWallets$,
1416
+ kc.hydrationGracePeriod,
1417
+ (w) => w.id,
1418
+ // Hydration converges when all cached-connected wallets are connected in live
1419
+ (liveWallets, cached) => {
1420
+ const cachedConnectedIds = new Set(
1421
+ cached.filter((w) => w.isConnected).map((w) => w.id)
1422
+ );
1423
+ if (cachedConnectedIds.size === 0) return true;
1424
+ return [...cachedConnectedIds].every(
1425
+ (id) => liveWallets.some((w) => w.id === id && w.isConnected)
1426
+ );
1427
+ },
1428
+ // Merge: prefer cached isConnected state but get icon from cache or live
1429
+ (live, cached) => ({
1430
+ ...cached,
1431
+ // Priority: cached icon > localStorage cache > live icon
1432
+ icon: cached.icon || getCachedIcon(cached.id) || live.icon,
1433
+ // Use live wallet's connect/disconnect functions
1434
+ connect: live.connect,
1435
+ disconnect: live.disconnect
1436
+ }),
1437
+ // Transform cached-only items: add icon from localStorage cache
1438
+ (cached) => ({
1439
+ ...cached,
1440
+ icon: cached.icon || getCachedIcon(cached.id) || ""
1441
+ })
1442
+ );
1443
+ const bufferedAccounts$ = createAccountHydrationBuffer(
1444
+ cachedAccounts,
1445
+ liveAccounts$,
1446
+ kc.hydrationGracePeriod,
1447
+ (a) => a.walletId,
1448
+ // Hydration converges when all wallets with cached accounts have provided live accounts
1449
+ (liveAccounts, cached) => {
1450
+ const cachedWalletIds = new Set(cached.map((a) => a.walletId));
1451
+ if (cachedWalletIds.size === 0) return true;
1452
+ const liveWalletIds = new Set(liveAccounts.map((a) => a.walletId));
1453
+ return [...cachedWalletIds].every((id) => liveWalletIds.has(id));
1454
+ }
1455
+ );
1456
+ const subscription = (0, import_rxjs11.combineLatest)({
1457
+ wallets: bufferedWallets$,
1458
+ accounts: bufferedAccounts$
1459
+ }).pipe(
1460
+ (0, import_rxjs11.map)(({ wallets, accounts }) => {
1461
+ if (kc.debug) {
1462
+ console.debug("[kheopskit] hydration state", {
1463
+ walletsHydrating: wallets.isHydrating,
1464
+ accountsHydrating: accounts.isHydrating,
1465
+ walletsConnected: wallets.items.filter((w) => w.isConnected).length,
1466
+ walletsTotal: wallets.items.length
1467
+ });
1468
+ }
1469
+ return {
1470
+ config: kc,
1471
+ wallets: wallets.items,
1472
+ accounts: accounts.items,
1473
+ isHydrating: wallets.isHydrating || accounts.isHydrating
1474
+ };
1475
+ })
1476
+ ).subscribe(subscriber);
1477
+ const persistSub = (0, import_rxjs11.combineLatest)({
1478
+ wallets: bufferedWallets$,
1479
+ accounts: bufferedAccounts$
1480
+ }).pipe(
1481
+ // Wait for hydration to complete
1482
+ (0, import_rxjs11.filter)(
1483
+ ({ wallets, accounts }) => !wallets.isHydrating && !accounts.isHydrating
1484
+ ),
1485
+ // Debounce to avoid excessive writes
1486
+ (0, import_rxjs11.debounceTime)(1e3),
1487
+ // Only persist if state actually changed
1488
+ (0, import_rxjs11.distinctUntilChanged)((prev, curr) => {
1489
+ const prevWalletIds = prev.wallets.items.map((w) => w.id);
1490
+ const currWalletIds = curr.wallets.items.map((w) => w.id);
1491
+ const prevAccountIds = prev.accounts.items.map((a) => a.id);
1492
+ const currAccountIds = curr.accounts.items.map((a) => a.id);
1493
+ return arraysEqual(prevWalletIds, currWalletIds) && arraysEqual(prevAccountIds, currAccountIds);
1494
+ })
1495
+ ).subscribe(({ wallets, accounts }) => {
1496
+ const connectedWalletIds = new Set(
1497
+ wallets.items.filter((w) => w.isConnected).map((w) => w.id)
1498
+ );
1499
+ const relevantAccounts = accounts.items.filter(
1500
+ (a) => connectedWalletIds.has(a.walletId)
1501
+ );
1502
+ if (kc.debug) {
1503
+ console.debug("[kheopskit] persisting state snapshot:", {
1504
+ wallets: wallets.items.length,
1505
+ accounts: relevantAccounts.length
1506
+ });
1507
+ }
1508
+ store2.setCachedState(
1509
+ wallets.items.map(serializeWallet),
1510
+ relevantAccounts.map(serializeAccount)
1511
+ );
1512
+ const icons = {};
1513
+ for (const wallet of wallets.items) {
1514
+ if (wallet.icon) {
1515
+ icons[wallet.id] = wallet.icon;
1516
+ }
1517
+ }
1518
+ setCachedIcons(icons);
1519
+ });
825
1520
  return () => {
826
1521
  subscription.unsubscribe();
1522
+ persistSub.unsubscribe();
827
1523
  };
828
1524
  }).pipe(
829
- (0, import_rxjs10.throttleTime)(16, void 0, { leading: true, trailing: true }),
1525
+ (0, import_rxjs11.distinctUntilChanged)(statesEqual),
1526
+ (0, import_rxjs11.throttleTime)(16, void 0, { leading: true, trailing: true }),
830
1527
  // ~1 frame at 60fps
831
1528
  logObservable("kheopskit$", { enabled: kc.debug, printValue: true }),
832
- (0, import_rxjs10.shareReplay)({ bufferSize: 1, refCount: true })
1529
+ (0, import_rxjs11.shareReplay)({ bufferSize: 1, refCount: true })
833
1530
  );
834
1531
  };
1532
+ var arraysEqual = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
1533
+ var statesEqual = (a, b) => a.isHydrating === b.isHydrating && a.wallets.length === b.wallets.length && a.accounts.length === b.accounts.length && a.wallets.every(
1534
+ (w, i) => w.id === b.wallets[i]?.id && w.isConnected === b.wallets[i]?.isConnected
1535
+ ) && a.accounts.every((acc, i) => acc.id === b.accounts[i]?.id);
835
1536
  // Annotate the CommonJS export names for ESM import in node:
836
1537
  0 && (module.exports = {
1538
+ DEFAULT_STORAGE_KEY,
1539
+ clearAllCachedObservables,
1540
+ clearCachedObservable,
1541
+ createKheopskitStore,
1542
+ getCachedIcon,
1543
+ getDefaultStore,
837
1544
  getKheopskit$,
1545
+ getSafeLocalStorage,
1546
+ hydrateAccount,
1547
+ hydrateWallet,
1548
+ resetAppKitCache,
838
1549
  resolveConfig
839
1550
  });
840
1551
  //# sourceMappingURL=index.js.map