@kheopskit/core 5.0.1 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-7QSGAJ4A.mjs → chunk-3Y5N4N3Q.mjs} +119 -62
- package/dist/chunk-3Y5N4N3Q.mjs.map +1 -0
- package/dist/chunk-DF7EKK4G.mjs +106 -0
- package/dist/chunk-DF7EKK4G.mjs.map +1 -0
- package/dist/chunk-EH73P476.js +106 -0
- package/dist/chunk-EH73P476.js.map +1 -0
- package/dist/chunk-JVSCMJY5.mjs +147 -0
- package/dist/chunk-JVSCMJY5.mjs.map +1 -0
- package/dist/chunk-P7BPHHVV.js +76 -0
- package/dist/chunk-P7BPHHVV.js.map +1 -0
- package/dist/{chunk-4ENHC7G4.js → chunk-SO64R7Z6.js} +114 -57
- package/dist/chunk-SO64R7Z6.js.map +1 -0
- package/dist/chunk-WOPCW2OX.mjs +76 -0
- package/dist/chunk-WOPCW2OX.mjs.map +1 -0
- package/dist/chunk-XOGQMEV2.js +147 -0
- package/dist/chunk-XOGQMEV2.js.map +1 -0
- package/dist/ethereum.d.mts +2 -2
- package/dist/ethereum.d.ts +2 -2
- package/dist/ethereum.js +55 -115
- package/dist/ethereum.js.map +1 -1
- package/dist/ethereum.mjs +55 -115
- package/dist/ethereum.mjs.map +1 -1
- package/dist/index.d.mts +59 -3
- package/dist/index.d.ts +59 -3
- package/dist/index.js +442 -61
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +429 -48
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.mts +2 -39
- package/dist/internal.d.ts +2 -39
- package/dist/internal.js +3 -15
- package/dist/internal.js.map +1 -1
- package/dist/internal.mjs +6 -18
- package/dist/polkadot.d.mts +2 -2
- package/dist/polkadot.d.ts +2 -2
- package/dist/polkadot.js +75 -148
- package/dist/polkadot.js.map +1 -1
- package/dist/polkadot.mjs +76 -149
- package/dist/polkadot.mjs.map +1 -1
- package/dist/solana.d.mts +2 -2
- package/dist/solana.d.ts +2 -2
- package/dist/solana.js +90 -158
- package/dist/solana.js.map +1 -1
- package/dist/solana.mjs +86 -154
- package/dist/solana.mjs.map +1 -1
- package/dist/{types-C7V7DGlg.d.ts → types-0iDBydsK.d.mts} +24 -46
- package/dist/{types-C7V7DGlg.d.mts → types-0iDBydsK.d.ts} +24 -46
- package/package.json +1 -1
- package/dist/chunk-4ENHC7G4.js.map +0 -1
- package/dist/chunk-6XAZANB5.mjs +0 -450
- package/dist/chunk-6XAZANB5.mjs.map +0 -1
- package/dist/chunk-7QSGAJ4A.mjs.map +0 -1
- package/dist/chunk-B4L6GAYD.js +0 -179
- package/dist/chunk-B4L6GAYD.js.map +0 -1
- package/dist/chunk-XQWJM3KC.js +0 -450
- package/dist/chunk-XQWJM3KC.js.map +0 -1
- package/dist/chunk-YDLCHYHH.mjs +0 -179
- package/dist/chunk-YDLCHYHH.mjs.map +0 -1
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/appKit.ts","../src/api/kheopskit.ts","../src/utils/createHydrationBuffer.ts","../src/utils/logObservable.ts","../src/api/accounts.ts","../src/api/wallets.ts"],"sourcesContent":["import {\n\tBehaviorSubject,\n\tdistinctUntilChanged,\n\tfrom,\n\tmap,\n\tObservable,\n\tof,\n\tshareReplay,\n\tswitchMap,\n\ttap,\n} from \"rxjs\";\nimport { clearCachedObservablesByPrefix } from \"../utils/getCachedObservable\";\nimport { WALLET_CONNECT_WALLET_ID } from \"../utils/WalletId\";\nimport type {\n\tAppKitInstance,\n\tKheopskitConfig,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\n\n/**\n * Dynamically import @reown/appkit/core to avoid loading browser-only code\n * during SSR or in edge runtimes like Cloudflare Workers.\n * The AppKit library uses Lit for web components which requires document.\n */\nconst loadAppKit = async () => {\n\ttry {\n\t\tconst { createAppKit } = await import(\"@reown/appkit/core\");\n\t\treturn createAppKit;\n\t} catch (cause) {\n\t\tconsole.error(\n\t\t\t\"[kheopskit] WalletConnect is configured but @reown/appkit could not be loaded. \" +\n\t\t\t\t\"Install it with `pnpm add @reown/appkit` (or remove config.walletConnect). \" +\n\t\t\t\t\"WalletConnect wallets are disabled; injected wallets still work.\",\n\t\t\tcause,\n\t\t);\n\t\treturn null;\n\t}\n};\n\nconst WALLET_CONNECT_ICON =\n\t\"data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDQwMCA0MDAiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTAgMGg0MDB2NDAwaC00MDB6Ii8+PC9jbGlwUGF0aD48ZyBjbGlwLXBhdGg9InVybCgjYSkiPjxjaXJjbGUgY3g9IjIwMCIgY3k9IjIwMCIgZmlsbD0iIzMzOTZmZiIgcj0iMTk5LjUiIHN0cm9rZT0iIzY2YjFmZiIvPjxwYXRoIGQ9Im0xMjIuNTE5IDE0OC45NjVjNDIuNzkxLTQxLjcyOSAxMTIuMTcxLTQxLjcyOSAxNTQuOTYyIDBsNS4xNSA1LjAyMmMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtMTcuNjE3IDE3LjE4Yy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTcuMDg3LTYuOTExYy0yOS44NTMtMjkuMTExLTc4LjI1My0yOS4xMTEtMTA4LjEwNiAwbC03LjU5IDcuNDAxYy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTE3LjYxNy0xNy4xOGMtMi4xNC0yLjA4Ni0yLjE0LTUuNDY5IDAtNy41NTV6bTE5MS4zOTcgMzUuNTI5IDE1LjY3OSAxNS4yOWMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtNzAuNyA2OC45NDRjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTUwLjE3OC00OC45MzFjLS41MzUtLjUyMi0xLjQwMi0uNTIyLTEuOTM3IDBsLTUwLjE3OCA0OC45MzFjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTcwLjcwMTUtNjguOTQ1Yy0yLjEzOTYtMi4wODYtMi4xMzk2LTUuNDY5IDAtNy41NTVsMTUuNjc5NS0xNS4yOWMyLjEzOTYtMi4wODYgNS42MDg1LTIuMDg2IDcuNzQ4MSAwbDUwLjE3ODkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3Ny00OC45MzJjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMGw1MC4xNzkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3OS00OC45MzFjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+\";\n\n// Once it exists, the appKit object should never be recreated. Anchored on\n// globalThis so it stays a single instance even if this module is duplicated\n// across bundle chunks (e.g. CJS subpath entries).\nconst APPKIT_SYMBOL = Symbol.for(\"kheopskit.cachedAppKit\");\n// The projectId AppKit was first initialised with. AppKit is a process-wide\n// singleton, so a later call with a different WalletConnect config is silently\n// ignored — we keep this to warn loudly instead of letting it pass unnoticed.\nconst APPKIT_PROJECT_ID_SYMBOL = Symbol.for(\"kheopskit.cachedAppKitProjectId\");\ntype AppKitGlobal = Record<\n\tsymbol,\n\tObservable<WalletConnectWallet | null> | string | undefined\n>;\nconst getCachedAppKit = ():\n\t| Observable<WalletConnectWallet | null>\n\t| undefined =>\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_SYMBOL] as\n\t\t| Observable<WalletConnectWallet | null>\n\t\t| undefined;\nconst getCachedAppKitProjectId = (): string | undefined =>\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_PROJECT_ID_SYMBOL] as\n\t\t| string\n\t\t| undefined;\nconst setCachedAppKit = (\n\tvalue: Observable<WalletConnectWallet | null> | undefined,\n\tprojectId?: string,\n): void => {\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_SYMBOL] = value;\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_PROJECT_ID_SYMBOL] = projectId;\n};\n\n/**\n * Clears the cached AppKit observable.\n * Use when configuration changes or for testing purposes.\n * Note: This does NOT destroy the appKit instance created by Reown.\n */\nexport const resetAppKitCache = (): void => {\n\tsetCachedAppKit(undefined);\n};\n\n/**\n * Drops a WalletConnect namespace's cached account observables. Called when a\n * namespace transitions to disconnected — including external disconnects (from\n * the wallet app), which flip status via `subscribeProviders` without ever\n * calling `disconnect()` — so a later reconnect rebuilds the account observables\n * against the fresh session instead of a stale closure.\n *\n * Keys are `accounts:<walletId>:...`; the trailing colon scopes the prefix to\n * this wallet and avoids matching a sibling whose id is a string prefix.\n */\nconst dropAccountsCache = (platform: WalletPlatform): void => {\n\tclearCachedObservablesByPrefix(\n\t\t`accounts:${WALLET_CONNECT_WALLET_ID}:${platform}:`,\n\t);\n};\n\n/**\n * The single, platform-less WalletConnect connector for the given config — or\n * `null` when WalletConnect isn't configured, on the server, or when\n * `@reown/appkit` isn't installed.\n *\n * @remarks\n * The AppKit instance is a process-wide singleton (Reown AppKit itself cannot\n * be instantiated twice). The **first** call with a `walletConnect` config wins;\n * later calls with a *different* `walletConnect` config reuse that first\n * instance. Call {@link resetAppKitCache} before re-initialising if the\n * WalletConnect config must change.\n *\n * One WalletConnect session is shared across every namespace, and a namespace\n * can only be established during the initial pairing — it can't be added to a\n * live session afterwards. So this exposes ONE connector (not one per platform):\n * `connect()` opens the modal; the wallet approves whichever namespaces it\n * supports in that single pairing, and `platforms` reflects what the live\n * session carries. Per-namespace accounts are derived by each platform plugin.\n */\nexport const getWalletConnectWallet$ = (\n\tconfig: KheopskitConfig,\n): Observable<WalletConnectWallet | null> => {\n\tif (!config.walletConnect) return of(null);\n\n\t// SSR guard - don't try to load AppKit on the server\n\tif (typeof window === \"undefined\") return of(null);\n\n\tconst walletConnect = config.walletConnect;\n\n\tconst cachedProjectId = getCachedAppKitProjectId();\n\tif (\n\t\tcachedProjectId !== undefined &&\n\t\tcachedProjectId !== walletConnect.projectId\n\t) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] WalletConnect is already initialised with projectId %s; \" +\n\t\t\t\t\"AppKit is a process-wide singleton, so the first configuration wins and \" +\n\t\t\t\t\"projectId %s is ignored. Call resetAppKitCache() before re-initialising \" +\n\t\t\t\t\"if the WalletConnect config must change.\",\n\t\t\tcachedProjectId,\n\t\t\twalletConnect.projectId,\n\t\t);\n\t}\n\n\tlet cachedAppKit = getCachedAppKit();\n\tif (!cachedAppKit) {\n\t\t// Dynamic import avoids loading @reown/appkit at module-eval time (SSR /\n\t\t// edge runtimes like Cloudflare Workers).\n\t\tcachedAppKit = from(loadAppKit()).pipe(\n\t\t\tswitchMap((createAppKit) => {\n\t\t\t\t// @reown/appkit missing (optional peer dep) — degrade gracefully.\n\t\t\t\tif (!createAppKit) return of<WalletConnectWallet | null>(null);\n\t\t\t\treturn new Observable<WalletConnectWallet | null>((subscriber) => {\n\t\t\t\t\tconst appKit = createAppKit({\n\t\t\t\t\t\tprojectId: walletConnect.projectId,\n\t\t\t\t\t\tmetadata: walletConnect.metadata,\n\t\t\t\t\t\t// Loosely typed in WalletConnectConfig to keep @reown/appkit's\n\t\t\t\t\t\t// types out of core; forwarded to AppKit verbatim.\n\t\t\t\t\t\tnetworks: walletConnect.networks as never,\n\t\t\t\t\t\tthemeMode: walletConnect.themeMode,\n\t\t\t\t\t\tthemeVariables: walletConnect.themeVariables as never,\n\t\t\t\t\t\tuniversalProviderConfigOverride: {\n\t\t\t\t\t\t\tmethods: {\n\t\t\t\t\t\t\t\tpolkadot: [\"polkadot_signTransaction\", \"polkadot_signMessage\"],\n\t\t\t\t\t\t\t\tsolana: [\n\t\t\t\t\t\t\t\t\t\"solana_signTransaction\",\n\t\t\t\t\t\t\t\t\t\"solana_signMessage\",\n\t\t\t\t\t\t\t\t\t\"solana_signAndSendTransaction\",\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tallWallets: \"HIDE\",\n\t\t\t\t\t\tdebug: config.debug,\n\t\t\t\t\t\tallowUnsupportedChain: true,\n\t\t\t\t\t});\n\n\t\t\t\t\t// Exposed on the wallet as the (decoupled) AppKitInstance escape hatch.\n\t\t\t\t\tconst appKitInstance = appKit as unknown as AppKitInstance;\n\n\t\t\t\t\tconst status$ = new BehaviorSubject({\n\t\t\t\t\t\tisPolkadotConnected: false,\n\t\t\t\t\t\tisEthereumConnected: false,\n\t\t\t\t\t\tisSolanaConnected: false,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst unsubProviders = appKit.subscribeProviders((providers) => {\n\t\t\t\t\t\tstatus$.next({\n\t\t\t\t\t\t\tisPolkadotConnected: !!providers.polkadot,\n\t\t\t\t\t\t\tisEthereumConnected: !!providers.eip155,\n\t\t\t\t\t\t\tisSolanaConnected: !!providers.solana,\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\n\t\t\t\t\tconst namespaceOf: Record<WalletPlatform, string> = {\n\t\t\t\t\t\tpolkadot: \"polkadot\",\n\t\t\t\t\t\tethereum: \"eip155\",\n\t\t\t\t\t\tsolana: \"solana\",\n\t\t\t\t\t};\n\t\t\t\t\tconst allPlatforms: WalletPlatform[] = [\n\t\t\t\t\t\t\"polkadot\",\n\t\t\t\t\t\t\"ethereum\",\n\t\t\t\t\t\t\"solana\",\n\t\t\t\t\t];\n\t\t\t\t\tconst enabledPlatforms = allPlatforms.filter((p) =>\n\t\t\t\t\t\t(appKit.chainNamespaces as string[]).includes(namespaceOf[p]),\n\t\t\t\t\t);\n\n\t\t\t\t\tlet prevConnected = {\n\t\t\t\t\t\tpolkadot: false,\n\t\t\t\t\t\tethereum: false,\n\t\t\t\t\t\tsolana: false,\n\t\t\t\t\t};\n\n\t\t\t\t\tconst sub = status$\n\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\tmap((s) => ({\n\t\t\t\t\t\t\t\tpolkadot: s.isPolkadotConnected,\n\t\t\t\t\t\t\t\tethereum: s.isEthereumConnected,\n\t\t\t\t\t\t\t\tsolana: s.isSolanaConnected,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\tdistinctUntilChanged(\n\t\t\t\t\t\t\t\t(a, b) =>\n\t\t\t\t\t\t\t\t\ta.polkadot === b.polkadot &&\n\t\t\t\t\t\t\t\t\ta.ethereum === b.ethereum &&\n\t\t\t\t\t\t\t\t\ta.solana === b.solana,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\ttap((connected) => {\n\t\t\t\t\t\t\t\t// Drop caches for namespaces that just went disconnected.\n\t\t\t\t\t\t\t\tfor (const platform of allPlatforms)\n\t\t\t\t\t\t\t\t\tif (prevConnected[platform] && !connected[platform])\n\t\t\t\t\t\t\t\t\t\tdropAccountsCache(platform);\n\t\t\t\t\t\t\t\tprevConnected = connected;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tmap((connected): WalletConnectWallet => {\n\t\t\t\t\t\t\t\tconst platforms = enabledPlatforms.filter((p) => connected[p]);\n\t\t\t\t\t\t\t\tconst isConnected = platforms.length > 0;\n\t\t\t\t\t\t\t\tconst walletInfo = appKit.getWalletInfo();\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: WALLET_CONNECT_WALLET_ID,\n\t\t\t\t\t\t\t\t\ttype: \"walletconnect\",\n\t\t\t\t\t\t\t\t\tplatforms,\n\t\t\t\t\t\t\t\t\tappKit: appKitInstance,\n\t\t\t\t\t\t\t\t\tname: walletInfo?.name ?? \"WalletConnect\",\n\t\t\t\t\t\t\t\t\ticon: walletInfo?.icon ?? WALLET_CONNECT_ICON,\n\t\t\t\t\t\t\t\t\t// One shared session: connecting opens the modal; the wallet\n\t\t\t\t\t\t\t\t\t// approves namespaces in that single pairing. Disconnect is\n\t\t\t\t\t\t\t\t\t// session-wide; re-pair to change the approved set.\n\t\t\t\t\t\t\t\t\tconnect: async () => {\n\t\t\t\t\t\t\t\t\t\tif (!isConnected) await appKit.open();\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tdisconnect: async () => {\n\t\t\t\t\t\t\t\t\t\tif (isConnected) await appKit.disconnect();\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tisConnected,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.subscribe(subscriber);\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tsub.unsubscribe();\n\t\t\t\t\t\tunsubProviders();\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}),\n\t\t\t// refCount:false keeps the AppKit instance alive for the process lifetime\n\t\t\t// once created: createAppKit runs at most once (Reown AppKit cannot be\n\t\t\t// instantiated twice). With refCount:true the producer would re-run\n\t\t\t// createAppKit whenever every subscriber drained and a new one\n\t\t\t// re-subscribed — e.g. a React unmount/remount or StrictMode's\n\t\t\t// mount→unmount→remount — throwing on the duplicate Lit web components and\n\t\t\t// WalletConnect modal singleton. The replayed connector value also keeps\n\t\t\t// the wallet list stable across such teardown/rebuild cycles.\n\t\t\tshareReplay({ refCount: false, bufferSize: 1 }),\n\t\t);\n\t\tsetCachedAppKit(cachedAppKit, walletConnect.projectId);\n\t}\n\n\treturn cachedAppKit;\n};\n","import {\n\tcombineLatest,\n\tdebounceTime,\n\tdistinctUntilChanged,\n\tfilter,\n\tmap,\n\tObservable,\n\tshareReplay,\n\tthrottleTime,\n} from \"rxjs\";\nimport {\n\tcreateAccountHydrationBuffer,\n\tcreateHydrationBuffer,\n} from \"../utils/createHydrationBuffer\";\nimport {\n\thydrateAccount,\n\thydrateWallet,\n\tserializeAccount,\n\tserializeWallet,\n} from \"../utils/hydrateState\";\nimport { getCachedIcon, setCachedIcons } from \"../utils/iconCache\";\nimport { logObservable } from \"../utils/logObservable\";\nimport { sortAccounts } from \"../utils/sortAccounts\";\nimport { sortWallets } from \"../utils/sortWallets\";\nimport { getAccounts$ } from \"./accounts\";\nimport { resolveConfig } from \"./config\";\nimport { acceptsCachedAccount } from \"./platform\";\nimport { createKheopskitStore } from \"./store\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tKheopskitConfig,\n\tKheopskitPlatform,\n\tKheopskitState,\n\tWalletConnectWallet,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\nimport { getWallets$ } from \"./wallets\";\n\nexport type { KheopskitConfig, KheopskitState } from \"./types\";\n\n/** Options for {@link getKheopskit$}. */\nexport type GetKheopskitOptions = {\n\t/**\n\t * Cookie string for SSR hydration. When provided, state is read from cookies\n\t * instead of localStorage so the server can hydrate without a flash. Pass the\n\t * request's `cookie` header.\n\t */\n\tssrCookies?: string;\n\t/**\n\t * An existing store to reuse instead of creating one. Advanced escape hatch —\n\t * most callers omit it. (`@kheopskit/react` passes its provider-scoped store.)\n\t */\n\tstore?: ReturnType<typeof createKheopskitStore>;\n};\n\nexport const getKheopskit$ = <\n\tconst P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(\n\tconfig?: Partial<KheopskitConfig<P>>,\n\toptions: GetKheopskitOptions = {},\n): Observable<KheopskitState<P>> => {\n\tconst { ssrCookies, store: existingStore } = options;\n\tconst kc = resolveConfig(config);\n\tconst store =\n\t\texistingStore ??\n\t\tcreateKheopskitStore({ ssrCookies, storageKey: kc.storageKey });\n\n\tif (kc.debug) console.debug(\"[kheopskit] config\", kc);\n\n\t// Warn about SSR environment without cookies\n\tif (kc.debug && typeof window === \"undefined\" && ssrCookies === undefined) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] Running on server without `ssrCookies`. \" +\n\t\t\t\t\"Wallet state will not be hydrated. Pass cookies for SSR support.\",\n\t\t);\n\t}\n\n\t// Get cached state for hydration\n\tconst cachedState = store.getCachedState();\n\t// Hydrate wallets and enrich with icons from localStorage cache\n\tconst cachedWallets = cachedState.wallets.map((w) => {\n\t\tconst wallet = hydrateWallet(w);\n\t\t// If wallet doesn't have icon (e.g., Ethereum), try localStorage cache\n\t\tif (!wallet.icon) {\n\t\t\tconst cachedIcon = getCachedIcon(wallet.id);\n\t\t\tif (cachedIcon) {\n\t\t\t\treturn { ...wallet, icon: cachedIcon };\n\t\t\t}\n\t\t}\n\t\treturn wallet;\n\t});\n\tconst cachedAccounts = cachedState.accounts\n\t\t.filter((cached) => acceptsCachedAccount(cached, kc.platforms))\n\t\t.map(hydrateAccount);\n\n\tif (kc.debug && cachedWallets.length > 0) {\n\t\tconsole.debug(\"[kheopskit] hydrating from cache:\", {\n\t\t\twallets: cachedWallets.length,\n\t\t\taccounts: cachedAccounts.length,\n\t\t});\n\t}\n\n\treturn new Observable<KheopskitState>((subscriber) => {\n\t\t// Get live wallets and accounts\n\t\tconst liveWallets$ = getWallets$(kc, store);\n\t\tconst liveAccounts$ = getAccounts$(kc, liveWallets$);\n\n\t\t// Apply hydration buffer to wallets\n\t\tconst bufferedWallets$ = createHydrationBuffer(\n\t\t\tcachedWallets,\n\t\t\tliveWallets$,\n\t\t\tkc.hydrationGracePeriod,\n\t\t\t(w) => w.id,\n\t\t\t// Hydration converges when all cached-connected wallets are connected in live\n\t\t\t(liveWallets, cached) => {\n\t\t\t\tconst cachedConnectedIds = new Set(\n\t\t\t\t\tcached.filter((w) => w.isConnected).map((w) => w.id),\n\t\t\t\t);\n\t\t\t\tif (cachedConnectedIds.size === 0) return true;\n\t\t\t\treturn [...cachedConnectedIds].every((id) =>\n\t\t\t\t\tliveWallets.some((w) => w.id === id && w.isConnected),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Merge: prefer cached isConnected state but get icon from cache or live\n\t\t\t(live, cached) => ({\n\t\t\t\t...cached,\n\t\t\t\t// Priority: cached icon > localStorage cache > live icon\n\t\t\t\ticon: cached.icon || getCachedIcon(cached.id) || live.icon,\n\t\t\t\t// Use live wallet's connect/disconnect functions\n\t\t\t\tconnect: live.connect,\n\t\t\t\tdisconnect: live.disconnect,\n\t\t\t}),\n\t\t\t// Transform cached-only items: add icon from localStorage cache\n\t\t\t(cached) => ({\n\t\t\t\t...cached,\n\t\t\t\ticon: cached.icon || getCachedIcon(cached.id) || \"\",\n\t\t\t}),\n\t\t);\n\n\t\t// Apply hydration buffer to accounts\n\t\tconst bufferedAccounts$ = createAccountHydrationBuffer(\n\t\t\tcachedAccounts,\n\t\t\tliveAccounts$,\n\t\t\tkc.hydrationGracePeriod,\n\t\t\t(a) => a.walletId,\n\t\t\t// Hydration converges when all wallets with cached accounts have provided live accounts\n\t\t\t(liveAccounts, cached) => {\n\t\t\t\tconst cachedWalletIds = new Set(cached.map((a) => a.walletId));\n\t\t\t\tif (cachedWalletIds.size === 0) return true;\n\t\t\t\tconst liveWalletIds = new Set(liveAccounts.map((a) => a.walletId));\n\t\t\t\treturn [...cachedWalletIds].every((id) => liveWalletIds.has(id));\n\t\t\t},\n\t\t);\n\n\t\t// Share the buffered streams so the main and persistence subscriptions\n\t\t// below reuse a single hydration pipeline (timers, isHydrating state)\n\t\t// instead of running the buffering twice.\n\t\tconst sharedWallets$ = bufferedWallets$.pipe(\n\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t);\n\t\tconst sharedAccounts$ = bufferedAccounts$.pipe(\n\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t);\n\n\t\t// Combine buffered wallets and accounts\n\t\tconst subscription = combineLatest({\n\t\t\twallets: sharedWallets$,\n\t\t\taccounts: sharedAccounts$,\n\t\t})\n\t\t\t.pipe(\n\t\t\t\tmap(({ wallets, accounts }) => {\n\t\t\t\t\tif (kc.debug) {\n\t\t\t\t\t\tconsole.debug(\"[kheopskit] hydration state\", {\n\t\t\t\t\t\t\twalletsHydrating: wallets.isHydrating,\n\t\t\t\t\t\t\taccountsHydrating: accounts.isHydrating,\n\t\t\t\t\t\t\twalletsConnected: wallets.items.filter((w) => w.isConnected)\n\t\t\t\t\t\t\t\t.length,\n\t\t\t\t\t\t\twalletsTotal: wallets.items.length,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\t// Sort on every emission with the same comparators used for the\n\t\t\t\t\t// cached initial snapshot. The hydration buffers append cached-only\n\t\t\t\t\t// items after live ones (and reconnects land out of order), so\n\t\t\t\t\t// without this the list visibly reorders as wallets come back.\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconfig: kc,\n\t\t\t\t\t\twallets: [...wallets.items].sort(sortWallets),\n\t\t\t\t\t\taccounts: [...accounts.items].sort(sortAccounts),\n\t\t\t\t\t\tisHydrating: wallets.isHydrating || accounts.isHydrating,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.subscribe(subscriber);\n\n\t\t// Persist state snapshot when hydration completes and state stabilizes\n\t\tconst persistSub = combineLatest({\n\t\t\twallets: sharedWallets$,\n\t\t\taccounts: sharedAccounts$,\n\t\t})\n\t\t\t.pipe(\n\t\t\t\t// Wait for hydration to complete\n\t\t\t\tfilter(\n\t\t\t\t\t({ wallets, accounts }) =>\n\t\t\t\t\t\t!wallets.isHydrating && !accounts.isHydrating,\n\t\t\t\t),\n\t\t\t\t// Debounce to avoid excessive writes\n\t\t\t\tdebounceTime(1000),\n\t\t\t\t// Only persist if the serialized snapshot would actually change.\n\t\t\t\t// Compare the persisted fields (not just ids): an Ethereum chain switch\n\t\t\t\t// keeps the same account id but changes the cached chainId, so an\n\t\t\t\t// id-only comparator would skip persisting it.\n\t\t\t\tdistinctUntilChanged((prev, curr) => {\n\t\t\t\t\tconst prevWalletKeys = prev.wallets.items.map(walletPersistKey);\n\t\t\t\t\tconst currWalletKeys = curr.wallets.items.map(walletPersistKey);\n\t\t\t\t\tconst prevAccountKeys = prev.accounts.items.map(accountChangeKey);\n\t\t\t\t\tconst currAccountKeys = curr.accounts.items.map(accountChangeKey);\n\t\t\t\t\treturn (\n\t\t\t\t\t\tarraysEqual(prevWalletKeys, currWalletKeys) &&\n\t\t\t\t\t\tarraysEqual(prevAccountKeys, currAccountKeys)\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.subscribe(({ wallets, accounts }) => {\n\t\t\t\t// Cache ALL wallets to avoid wallet list flash on reload\n\t\t\t\t// Only accounts from connected wallets are cached\n\t\t\t\tconst connectedWalletIds = new Set(\n\t\t\t\t\twallets.items.filter((w) => w.isConnected).map((w) => w.id),\n\t\t\t\t);\n\t\t\t\tconst relevantAccounts = accounts.items.filter((a) =>\n\t\t\t\t\tconnectedWalletIds.has(a.walletId),\n\t\t\t\t);\n\n\t\t\t\tif (kc.debug) {\n\t\t\t\t\tconsole.debug(\"[kheopskit] persisting state snapshot:\", {\n\t\t\t\t\t\twallets: wallets.items.length,\n\t\t\t\t\t\taccounts: relevantAccounts.length,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tstore.setCachedState(\n\t\t\t\t\twallets.items.map(serializeWallet),\n\t\t\t\t\trelevantAccounts.map(serializeAccount),\n\t\t\t\t);\n\n\t\t\t\t// Cache wallet icons in localStorage (separate from cookies for size)\n\t\t\t\tconst icons: Record<string, string> = {};\n\t\t\t\tfor (const wallet of wallets.items) {\n\t\t\t\t\tif (wallet.icon) {\n\t\t\t\t\t\ticons[wallet.id] = wallet.icon;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsetCachedIcons(icons);\n\t\t\t});\n\n\t\treturn () => {\n\t\t\tsubscription.unsubscribe();\n\t\t\tpersistSub.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tdistinctUntilChanged(statesEqual),\n\t\tthrottleTime(16, undefined, { leading: true, trailing: true }), // ~1 frame at 60fps\n\t\tlogObservable(\"kheopskit$\", { enabled: kc.debug, printValue: true }),\n\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t// The runtime objects are the concrete per-plugin wallet/account types;\n\t\t// recover the precise KheopskitState<P> the caller's plugins imply.\n\t) as unknown as Observable<KheopskitState<P>>;\n};\n\nconst arraysEqual = (a: string[], b: string[]) =>\n\ta.length === b.length && a.every((v, i) => v === b[i]);\n\n// Mutable per-platform account fields that can change without the account id\n// changing. Declared locally (not imported from the platform packages) so this\n// core entry stays free of platform SDK types — see check:isolation.\ntype EthereumAccountFields = { chainId?: number };\ntype PolkadotAccountFields = { type?: string };\ntype SolanaAccountFields = { chains?: string[] };\n\n/**\n * A signature of an account covering its id plus the platform-specific fields\n * that can change without the id changing (Ethereum chainId, Polkadot key type,\n * Solana clusters). Used to detect both UI-relevant changes and changes worth\n * re-persisting, so the two comparators can't drift apart.\n */\nconst accountChangeKey = (account: BaseWalletAccount): string => {\n\tswitch (account.platform) {\n\t\tcase \"ethereum\":\n\t\t\treturn `${account.id}|${(account as EthereumAccountFields).chainId ?? \"\"}`;\n\t\tcase \"polkadot\":\n\t\t\treturn `${account.id}|${(account as PolkadotAccountFields).type ?? \"\"}`;\n\t\tcase \"solana\":\n\t\t\treturn `${account.id}|${((account as SolanaAccountFields).chains ?? []).join(\",\")}`;\n\t\tdefault:\n\t\t\treturn account.id;\n\t}\n};\n\n/** Platforms a wallet's live session carries (only the WalletConnect connector). */\nconst walletPlatforms = (wallet: BaseWallet | WalletConnectWallet): string =>\n\tisWalletConnectWallet(wallet) ? wallet.platforms.join(\",\") : \"\";\n\n/** Fields persisted to the cache for a wallet (icon is stored separately). */\nconst walletPersistKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\t`${wallet.id}|${wallet.isConnected ? 1 : 0}|${wallet.name}`;\n\n/**\n * UI-significant signature of a wallet: the persisted fields plus icon and the\n * WalletConnect connector's `platforms` array, which drive what the UI shows but\n * aren't part of the id (icon and platforms can arrive asynchronously after\n * connect without isConnected flipping).\n */\nconst walletUiKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\t`${walletPersistKey(wallet)}|${wallet.icon}|${walletPlatforms(wallet)}`;\n\n/**\n * Equality check for KheopskitState to prevent unnecessary emissions. Compares\n * the UI-significant signature of every wallet and account, in order.\n */\nconst statesEqual = (a: KheopskitState, b: KheopskitState): boolean =>\n\ta.isHydrating === b.isHydrating &&\n\ta.wallets.length === b.wallets.length &&\n\ta.accounts.length === b.accounts.length &&\n\ta.wallets.every((w, i) => {\n\t\tconst other = b.wallets[i];\n\t\treturn !!other && walletUiKey(w) === walletUiKey(other);\n\t}) &&\n\ta.accounts.every((acc, i) => {\n\t\tconst other = b.accounts[i];\n\t\treturn !!other && accountChangeKey(acc) === accountChangeKey(other);\n\t});\n","import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tfilter,\n\tmap,\n\tObservable,\n\tSubscription,\n\tshareReplay,\n\tstartWith,\n\ttake,\n\ttimer,\n} from \"rxjs\";\n\ntype HydrationBufferResult<T> = {\n\titems: T[];\n\tisHydrating: boolean;\n};\n\n/**\n * Core hydration buffer logic shared between wallets and accounts.\n *\n * During the grace period:\n * - Emits cached items immediately (before any live emissions)\n * - As live items arrive, merges them using the provided merge function\n *\n * After the grace period (and convergence, if provided):\n * - Only live items are returned\n * - isHydrating becomes false\n *\n * If an `isConverged` function is provided, hydration ends only when BOTH\n * the grace period has elapsed AND the live items have converged with cached\n * items (e.g., all previously-connected wallets have reconnected).\n * A max timeout (6x grace period) prevents infinite hydration.\n *\n * @param cachedItems - Initial cached items from storage\n * @param liveItems$ - Observable of live items as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param mergeFn - Function to merge live and cached items during hydration\n * @param isConverged - Optional function to check if live items have caught up to cached items\n */\nconst createBufferCore = <T>(\n\tcachedItems: T[],\n\tliveItems$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tmergeFn: (liveItems: T[], cachedItems: T[]) => T[],\n\tisConverged?: (liveItems: T[], cachedItems: T[]) => boolean,\n): Observable<HydrationBufferResult<T>> => {\n\t// If no grace period or no cached items, just pass through live items\n\tif (gracePeriodMs <= 0 || cachedItems.length === 0) {\n\t\treturn liveItems$.pipe(map((items) => ({ items, isHydrating: false })));\n\t}\n\n\t// Wrap in an Observable to properly manage all subscriptions\n\treturn new Observable<HydrationBufferResult<T>>((subscriber) => {\n\t\tconst subscriptions = new Subscription();\n\n\t\t// Track whether we're still in the hydration grace period\n\t\t// Using BehaviorSubject to keep a stateful value that doesn't complete\n\t\tconst isHydrating$ = new BehaviorSubject(true);\n\n\t\t// Use startWith to emit cached items immediately before any live emissions\n\t\tconst liveWithInitial$ = liveItems$.pipe(startWith([] as T[]));\n\n\t\tif (isConverged) {\n\t\t\t// With convergence check: hydration ends when timer fires AND live state has caught up\n\t\t\tconst timerFired$ = timer(gracePeriodMs).pipe(\n\t\t\t\tmap(() => true),\n\t\t\t\tstartWith(false),\n\t\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t\t);\n\n\t\t\t// End hydration when timer has fired AND convergence is met\n\t\t\tsubscriptions.add(\n\t\t\t\tcombineLatest([liveWithInitial$, timerFired$])\n\t\t\t\t\t.pipe(\n\t\t\t\t\t\tfilter(([, timerFired]) => timerFired),\n\t\t\t\t\t\tfilter(([liveItems]) => isConverged(liveItems, cachedItems)),\n\t\t\t\t\t\ttake(1),\n\t\t\t\t\t)\n\t\t\t\t\t.subscribe(() => {\n\t\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t\t}),\n\t\t\t);\n\n\t\t\t// Max timeout (6x grace period) to prevent infinite hydration\n\t\t\t// e.g., if auto-reconnect fails, we still end hydration\n\t\t\tsubscriptions.add(\n\t\t\t\ttimer(gracePeriodMs * 6).subscribe(() => {\n\t\t\t\t\tif (isHydrating$.value) {\n\t\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t} else {\n\t\t\t// Without convergence check: end hydration on timer only\n\t\t\tsubscriptions.add(\n\t\t\t\ttimer(gracePeriodMs).subscribe(() => {\n\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tsubscriptions.add(\n\t\t\tcombineLatest([liveWithInitial$, isHydrating$])\n\t\t\t\t.pipe(\n\t\t\t\t\tmap(([liveItems, isHydrating]) => {\n\t\t\t\t\t\tif (!isHydrating) {\n\t\t\t\t\t\t\t// Hydration complete - return only live items\n\t\t\t\t\t\t\treturn { items: liveItems, isHydrating: false };\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\titems: mergeFn(liveItems, cachedItems),\n\t\t\t\t\t\t\tisHydrating: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber),\n\t\t);\n\n\t\treturn () => {\n\t\t\tsubscriptions.unsubscribe();\n\t\t\tisHydrating$.complete();\n\t\t};\n\t});\n};\n\n/**\n * Creates a hydration buffer that merges cached items with live items.\n *\n * During hydration, cached items take precedence over live items with the same key.\n * This preserves the cached connected state (e.g., isConnected: true) while\n * auto-reconnect is still in progress. New live items not in the cache are added.\n *\n * @param cachedItems - Initial cached items from storage\n * @param liveItems$ - Observable of live items as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param getKey - Function to extract a unique key from an item\n * @param isConverged - Optional function to check if live items have caught up to cached items\n * @param mergeItem - Optional function to merge a live item with its cached counterpart\n * @param transformCachedOnly - Optional function to transform cached items not yet in the live stream\n */\nexport const createHydrationBuffer = <T>(\n\tcachedItems: T[],\n\tliveItems$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tgetKey: (item: T) => string,\n\tisConverged?: (liveItems: T[], cachedItems: T[]) => boolean,\n\tmergeItem?: (liveItem: T, cachedItem: T) => T,\n\ttransformCachedOnly?: (cachedItem: T) => T,\n): Observable<HydrationBufferResult<T>> => {\n\treturn createBufferCore(\n\t\tcachedItems,\n\t\tliveItems$,\n\t\tgracePeriodMs,\n\t\t(liveItems, cached) => {\n\t\t\tconst cachedByKey = new Map(cached.map((item) => [getKey(item), item]));\n\t\t\tconst liveKeys = new Set(liveItems.map(getKey));\n\n\t\t\t// For items in both live and cached, prefer cached (preserves connected state)\n\t\t\t// but allow mergeItem to customize how they're combined\n\t\t\t// For items only in live (newly discovered), use the live version\n\t\t\tconst mergedItems: T[] = liveItems.map((liveItem) => {\n\t\t\t\tconst key = getKey(liveItem);\n\t\t\t\tconst cachedItem = cachedByKey.get(key);\n\t\t\t\tif (!cachedItem) return liveItem;\n\t\t\t\treturn mergeItem ? mergeItem(liveItem, cachedItem) : cachedItem;\n\t\t\t});\n\n\t\t\t// Add cached items not yet in the live stream (e.g., extensions not yet detected)\n\t\t\tfor (const cachedItem of cached) {\n\t\t\t\tif (!liveKeys.has(getKey(cachedItem))) {\n\t\t\t\t\tconst transformed = transformCachedOnly\n\t\t\t\t\t\t? transformCachedOnly(cachedItem)\n\t\t\t\t\t\t: cachedItem;\n\t\t\t\t\tmergedItems.push(transformed);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mergedItems;\n\t\t},\n\t\tisConverged,\n\t);\n};\n\n/**\n * Creates a hydration buffer specifically for accounts, which need special handling.\n *\n * Accounts are grouped by wallet - when a wallet provides its account list,\n * we replace all cached accounts for that wallet with the live ones.\n * Cached accounts for wallets that haven't provided accounts yet are preserved.\n *\n * @param cachedAccounts - Initial cached accounts from storage\n * @param liveAccounts$ - Observable of live accounts as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param getWalletId - Function to extract the wallet ID from an account\n * @param isConverged - Optional function to check if live accounts have caught up to cached accounts\n */\nexport const createAccountHydrationBuffer = <T>(\n\tcachedAccounts: T[],\n\tliveAccounts$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tgetWalletId: (account: T) => string,\n\tisConverged?: (liveAccounts: T[], cachedAccounts: T[]) => boolean,\n): Observable<HydrationBufferResult<T>> => {\n\treturn createBufferCore(\n\t\tcachedAccounts,\n\t\tliveAccounts$,\n\t\tgracePeriodMs,\n\t\t(liveAccounts, cached) => {\n\t\t\tconst walletsWithLiveAccounts = new Set(liveAccounts.map(getWalletId));\n\t\t\tconst mergedAccounts: T[] = [...liveAccounts];\n\n\t\t\tfor (const cachedAccount of cached) {\n\t\t\t\tif (!walletsWithLiveAccounts.has(getWalletId(cachedAccount))) {\n\t\t\t\t\tmergedAccounts.push(cachedAccount);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mergedAccounts;\n\t\t},\n\t\tisConverged,\n\t);\n};\n","import { type MonoTypeOperatorFunction, tap } from \"rxjs\";\n\ntype Opts = {\n\tprintValue?: boolean;\n\tenabled?: boolean;\n};\n\nexport const logObservable = <T>(\n\tlabel: string,\n\topts?: Opts,\n): MonoTypeOperatorFunction<T> =>\n\ttap((value) => {\n\t\tconst { printValue = false, enabled = true } = opts || {};\n\n\t\tif (!label || !enabled) return;\n\n\t\tconst text = `[kheopskit] observable ${label} emit`;\n\n\t\tif (printValue) console.debug(text, value);\n\t\telse console.debug(text);\n\t});\n","import { combineLatest, map, Observable, of, shareReplay } from \"rxjs\";\nimport { sortAccounts } from \"../utils/sortAccounts\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tKheopskitConfig,\n\tWalletConnectWallet,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\nexport const getAccounts$ = (\n\tconfig: KheopskitConfig,\n\twallets: Observable<(BaseWallet | WalletConnectWallet)[]>,\n) => {\n\treturn new Observable<BaseWalletAccount[]>((subscriber) => {\n\t\t// Each plugin gets its own platform's (injected) wallets plus the shared\n\t\t// WalletConnect connector; it derives WC accounts only for the namespaces\n\t\t// the session carries.\n\t\tconst sources = config.platforms.map((plugin) =>\n\t\t\tplugin.getAccounts$(\n\t\t\t\twallets.pipe(\n\t\t\t\t\tmap((ws) =>\n\t\t\t\t\t\tws.filter(\n\t\t\t\t\t\t\t(w) => isWalletConnectWallet(w) || w.platform === plugin.platform,\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\tconst accounts$ = sources.length\n\t\t\t? combineLatest(sources).pipe(\n\t\t\t\t\tmap((accounts) => accounts.flat().sort(sortAccounts)),\n\t\t\t\t)\n\t\t\t: of<BaseWalletAccount[]>([]);\n\n\t\tconst sub = accounts$.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n","import {\n\tcombineLatest,\n\tfilter,\n\tmap,\n\tmergeMap,\n\tObservable,\n\tof,\n\tshareReplay,\n\ttake,\n} from \"rxjs\";\nimport { sortWallets } from \"../utils/sortWallets\";\nimport { getWalletConnectWallet$ } from \"./appKit\";\nimport { store as defaultStore, type KheopskitStore } from \"./store\";\nimport type {\n\tBaseWallet,\n\tKheopskitConfig,\n\tPlatformContext,\n\tWalletConnectWallet,\n} from \"./types\";\n\nexport const getWallets$ = (\n\tconfig: KheopskitConfig,\n\tstore: KheopskitStore = defaultStore,\n) => {\n\t// lock the list of wallets to auto reconnect on first call\n\tconst autoReconnectWalletIds$ = store.observable.pipe(\n\t\tmap((s) => s.autoReconnect ?? []),\n\t\ttake(1),\n\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t);\n\n\treturn new Observable<(BaseWallet | WalletConnectWallet)[]>((subscriber) => {\n\t\tconst ctx: PlatformContext = { config, store };\n\t\tconst observables = config.platforms.map((plugin) =>\n\t\t\tplugin.getWallets$(ctx),\n\t\t);\n\n\t\tconst platformWallets$ = observables.length\n\t\t\t? combineLatest(observables).pipe(map((wallets) => wallets.flat()))\n\t\t\t: of<BaseWallet[]>([]);\n\n\t\t// The single, platform-less WalletConnect connector is appended here (not\n\t\t// emitted per platform). It sorts last (see sortWallets).\n\t\tconst wallets$ = combineLatest([\n\t\t\tplatformWallets$,\n\t\t\tgetWalletConnectWallet$(config),\n\t\t]).pipe(\n\t\t\tmap(([platformWallets, walletConnect]) => {\n\t\t\t\tconst all: (BaseWallet | WalletConnectWallet)[] = walletConnect\n\t\t\t\t\t? [...platformWallets, walletConnect]\n\t\t\t\t\t: platformWallets;\n\t\t\t\treturn all.sort(sortWallets);\n\t\t\t}),\n\t\t\t// Note: No startWith([]) here - the hydration buffer handles initial state\n\t\t);\n\n\t\t// Track wallets currently reconnecting (avoid duplicate concurrent attempts)\n\t\t// and those already reconnected (so we don't fight a later manual disconnect).\n\t\t// A failed attempt is left out of `reconnected`, so it can retry when the\n\t\t// wallet next re-emits (e.g. a late-injecting extension).\n\t\tconst reconnectingWallets = new Set<string>();\n\t\tconst reconnectedWallets = new Set<string>();\n\t\t// Bounded retry: a wallet whose connect() keeps rejecting (e.g. a permission\n\t\t// permanently denied, or a buggy provider) must not be re-attempted on every\n\t\t// wallets$ emission — the stream re-emits frequently (polkadot polling,\n\t\t// mipd/wallet-standard register events). Allow a few attempts so a\n\t\t// late-injecting extension that isn't ready on first sight still reconnects,\n\t\t// then give up for this session.\n\t\tconst MAX_RECONNECT_ATTEMPTS = 3;\n\t\tconst failedAttempts = new Map<string, number>();\n\n\t\tconst subAutoReconnect = combineLatest([wallets$, autoReconnectWalletIds$])\n\t\t\t.pipe(\n\t\t\t\tfilter(([, walletIds]) => config.autoReconnect && !!walletIds?.length),\n\t\t\t\tmergeMap(([wallets, walletIds]) =>\n\t\t\t\t\twallets.filter((wallet) => walletIds?.includes(wallet.id)),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.subscribe(async (wallet) => {\n\t\t\t\tif (\n\t\t\t\t\twallet.isConnected ||\n\t\t\t\t\treconnectingWallets.has(wallet.id) ||\n\t\t\t\t\treconnectedWallets.has(wallet.id) ||\n\t\t\t\t\t(failedAttempts.get(wallet.id) ?? 0) >= MAX_RECONNECT_ATTEMPTS\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\treconnectingWallets.add(wallet.id);\n\t\t\t\ttry {\n\t\t\t\t\tawait wallet.connect();\n\t\t\t\t\treconnectedWallets.add(wallet.id);\n\t\t\t\t\tfailedAttempts.delete(wallet.id);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tfailedAttempts.set(\n\t\t\t\t\t\twallet.id,\n\t\t\t\t\t\t(failedAttempts.get(wallet.id) ?? 0) + 1,\n\t\t\t\t\t);\n\t\t\t\t\tconsole.error(\"Failed to reconnect wallet %s\", wallet.id, { err });\n\t\t\t\t} finally {\n\t\t\t\t\treconnectingWallets.delete(wallet.id);\n\t\t\t\t}\n\t\t\t});\n\n\t\tconst subWallets = wallets$.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsubAutoReconnect.unsubscribe();\n\t\t\tsubWallets.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAeP,IAAM,aAAa,YAAY;AAC9B,MAAI;AACH,UAAM,EAAE,aAAa,IAAI,MAAM,OAAO,oBAAoB;AAC1D,WAAO;AAAA,EACR,SAAS,OAAO;AACf,YAAQ;AAAA,MACP;AAAA,MAGA;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACD;AAEA,IAAM,sBACL;AAKD,IAAM,gBAAgB,uBAAO,IAAI,wBAAwB;AAIzD,IAAM,2BAA2B,uBAAO,IAAI,iCAAiC;AAK7E,IAAM,kBAAkB,MAGtB,WAAuC,aAAa;AAGtD,IAAM,2BAA2B,MAC/B,WAAuC,wBAAwB;AAGjE,IAAM,kBAAkB,CACvB,OACA,cACU;AACV,EAAC,WAAuC,aAAa,IAAI;AACzD,EAAC,WAAuC,wBAAwB,IAAI;AACrE;AAOO,IAAM,mBAAmB,MAAY;AAC3C,kBAAgB,MAAS;AAC1B;AAYA,IAAM,oBAAoB,C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AAC1B,SAAO,CAAC,CAAC,SAAS,iBAAiB,GAAG,MAAM,iBAAiB,KAAK;AACnE,CAAC;","names":["combineLatest","distinctUntilChanged","filter","map","Observable","shareReplay","BehaviorSubject","map","Observable","shareReplay","getWalletId","tap","combineLatest","map","Observable","of","shareReplay","Observable","map","combineLatest","of","shareReplay","combineLatest","filter","map","Observable","of","shareReplay","take","store","map","take","shareReplay","Observable","combineLatest","of","filter","store","Observable","shareReplay","combineLatest","map","filter","distinctUntilChanged"]}
|
|
1
|
+
{"version":3,"sources":["../src/api/appKit.ts","../src/api/config.ts","../src/utils/sortAccounts.ts","../src/utils/sortWallets.ts","../src/api/platform.ts","../src/api/hydration.ts","../src/api/kheopskit.ts","../src/utils/createHydrationBuffer.ts","../src/utils/logObservable.ts","../src/api/accounts.ts","../src/api/store.ts","../src/utils/createStore.ts","../src/api/compactStore.ts","../src/api/wallets.ts","../src/api/reconnectPolicy.ts"],"sourcesContent":["import {\n\tBehaviorSubject,\n\tdistinctUntilChanged,\n\tfrom,\n\tmap,\n\tObservable,\n\tof,\n\tshareReplay,\n\tswitchMap,\n\ttap,\n} from \"rxjs\";\nimport { clearCachedObservablesByPrefix } from \"../utils/getCachedObservable\";\nimport { WALLET_CONNECT_WALLET_ID } from \"../utils/WalletId\";\nimport type {\n\tAppKitInstance,\n\tKheopskitConfig,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\n\n/**\n * Dynamically import @reown/appkit/core to avoid loading browser-only code\n * during SSR or in edge runtimes like Cloudflare Workers.\n * The AppKit library uses Lit for web components which requires document.\n */\nconst loadAppKit = async () => {\n\ttry {\n\t\tconst { createAppKit } = await import(\"@reown/appkit/core\");\n\t\treturn createAppKit;\n\t} catch (cause) {\n\t\tconsole.error(\n\t\t\t\"[kheopskit] WalletConnect is configured but @reown/appkit could not be loaded. \" +\n\t\t\t\t\"Install it with `pnpm add @reown/appkit` (or remove config.walletConnect). \" +\n\t\t\t\t\"WalletConnect wallets are disabled; injected wall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TIyLTEuOTM3IDBsLTUwLjE3OCA0OC45MzFjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTcwLjcwMTUtNjguOTQ1Yy0yLjEzOTYtMi4wODYtMi4xMzk2LTUuNDY5IDAtNy41NTVsMTUuNjc5NS0xNS4yOWMyLjEzOTYtMi4wODYgNS42MDg1LTIuMDg2IDcuNzQ4MSAwbDUwLjE3ODkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3Ny00OC45MzJjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMGw1MC4xNzkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3OS00OC45MzFjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+\";\n\n// Once it exists, the appKit object should never be recreated. Anchored on\n// globalThis so it stays a single instance even if this module is duplicated\n// across bundle chunks (e.g. CJS subpath entries).\nconst APPKIT_SYMBOL = Symbol.for(\"kheopskit.cachedAppKit\");\n// The projectId AppKit was first initialised with. AppKit is a process-wide\n// singleton, so a later call with a different WalletConnect config is silently\n// ignored — we keep this to warn loudly instead of letting it pass unnoticed.\nconst APPKIT_PROJECT_ID_SYMBOL = Symbol.for(\"kheopskit.cachedAppKitProjectId\");\ntype AppKitGlobal = Record<\n\tsymbol,\n\tObservable<WalletConnectWallet | null> | string | undefined\n>;\nconst getCachedAppKit = ():\n\t| Observable<WalletConnectWallet | null>\n\t| undefined =>\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_SYMBOL] as\n\t\t| Observable<WalletConnectWallet | null>\n\t\t| undefined;\nconst getCachedAppKitProjectId = (): string | undefined =>\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_PROJECT_ID_SYMBOL] as\n\t\t| string\n\t\t| undefined;\nconst setCachedAppKit = (\n\tvalue: Observable<WalletConnectWallet | null> | undefined,\n\tprojectId?: string,\n): void => {\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_SYMBOL] = value;\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_PROJECT_ID_SYMBOL] = projectId;\n};\n\n/**\n * Clears the cached AppKit observable.\n * Use when configuration changes or for testing purposes.\n * Note: This does NOT destroy the appKit instance created by Reown.\n */\nexport const resetAppKitCache = (): void => {\n\tsetCachedAppKit(undefined);\n};\n\n/**\n * Drops a WalletConnect namespace's cached account observables. Called when a\n * namespace transitions to disconnected — including external disconnects (from\n * the wallet app), which flip status via `subscribeProviders` without ever\n * calling `disconnect()` — so a later reconnect rebuilds the account observables\n * against the fresh session instead of a stale closure.\n *\n * Keys are `accounts:<walletId>:...`; the trailing colon scopes the prefix to\n * this wallet and avoids matching a sibling whose id is a string prefix.\n */\nconst dropAccountsCache = (platform: WalletPlatform): void => {\n\tclearCachedObservablesByPrefix(\n\t\t`accounts:${WALLET_CONNECT_WALLET_ID}:${platform}:`,\n\t);\n};\n\n/**\n * The single, platform-less WalletConnect connector for the given config — or\n * `null` when WalletConnect isn't configured, on the server, or when\n * `@reown/appkit` isn't installed.\n *\n * @remarks\n * The AppKit instance is a process-wide singleton (Reown AppKit itself cannot\n * be instantiated twice). The **first** call with a `walletConnect` config wins;\n * later calls with a *different* `walletConnect` config reuse that first\n * instance. Call {@link resetAppKitCache} before re-initialising if the\n * WalletConnect config must change.\n *\n * One WalletConnect session is shared across every namespace, and a namespace\n * can only be established during the initial pairing — it can't be added to a\n * live session afterwards. So this exposes ONE connector (not one per platform):\n * `connect()` opens the modal; the wallet approves whichever namespaces it\n * supports in that single pairing, and `platforms` reflects what the live\n * session carries. Per-namespace accounts are derived by each platform plugin.\n */\nexport const getWalletConnectWallet$ = (\n\tconfig: KheopskitConfig,\n): Observable<WalletConnectWallet | null> => {\n\tif (!config.walletConnect) return of(null);\n\n\t// SSR guard - don't try to load AppKit on the server\n\tif (typeof window === \"undefined\") return of(null);\n\n\tconst walletConnect = config.walletConnect;\n\n\tconst cachedProjectId = getCachedAppKitProjectId();\n\tif (\n\t\tcachedProjectId !== undefined &&\n\t\tcachedProjectId !== walletConnect.projectId\n\t) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] WalletConnect is already initialised with projectId %s; \" +\n\t\t\t\t\"AppKit is a process-wide singleton, so the first configuration wins and \" +\n\t\t\t\t\"projectId %s is ignored. Call resetAppKitCache() before re-initialising \" +\n\t\t\t\t\"if the WalletConnect config must change.\",\n\t\t\tcachedProjectId,\n\t\t\twalletConnect.projectId,\n\t\t);\n\t}\n\n\tlet cachedAppKit = getCachedAppKit();\n\tif (!cachedAppKit) {\n\t\t// Dynamic import avoids loading @reown/appkit at module-eval time (SSR /\n\t\t// edge runtimes like Cloudflare Workers).\n\t\tcachedAppKit = from(loadAppKit()).pipe(\n\t\t\tswitchMap((createAppKit) => {\n\t\t\t\t// @reown/appkit missing (optional peer dep) — degrade gracefully.\n\t\t\t\tif (!createAppKit) return of<WalletConnectWallet | null>(null);\n\t\t\t\treturn new Observable<WalletConnectWallet | null>((subscriber) => {\n\t\t\t\t\tconst appKit = createAppKit({\n\t\t\t\t\t\tprojectId: walletConnect.projectId,\n\t\t\t\t\t\tmetadata: walletConnect.metadata,\n\t\t\t\t\t\t// Loosely typed in WalletConnectConfig to keep @reown/appkit's\n\t\t\t\t\t\t// types out of core; forwarded to AppKit verbatim.\n\t\t\t\t\t\tnetworks: walletConnect.networks as never,\n\t\t\t\t\t\tthemeMode: walletConnect.themeMode,\n\t\t\t\t\t\tthemeVariables: walletConnect.themeVariables as never,\n\t\t\t\t\t\tuniversalProviderConfigOverride: {\n\t\t\t\t\t\t\tmethods: {\n\t\t\t\t\t\t\t\tpolkadot: [\"polkadot_signTransaction\", \"polkadot_signMessage\"],\n\t\t\t\t\t\t\t\tsolana: [\n\t\t\t\t\t\t\t\t\t\"solana_signTransaction\",\n\t\t\t\t\t\t\t\t\t\"solana_signMessage\",\n\t\t\t\t\t\t\t\t\t\"solana_signAndSendTransaction\",\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tallWallets: \"HIDE\",\n\t\t\t\t\t\tdebug: config.debug,\n\t\t\t\t\t\tallowUnsupportedChain: true,\n\t\t\t\t\t});\n\n\t\t\t\t\t// Exposed on the wallet as the (decoupled) AppKitInstance escape hatch.\n\t\t\t\t\tconst appKitInstance = appKit as unknown as AppKitInstance;\n\n\t\t\t\t\tconst status$ = new BehaviorSubject({\n\t\t\t\t\t\tisPolkadotConnected: false,\n\t\t\t\t\t\tisEthereumConnected: false,\n\t\t\t\t\t\tisSolanaConnected: false,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst unsubProviders = appKit.subscribeProviders((providers) => {\n\t\t\t\t\t\tstatus$.next({\n\t\t\t\t\t\t\tisPolkadotConnected: !!providers.polkadot,\n\t\t\t\t\t\t\tisEthereumConnected: !!providers.eip155,\n\t\t\t\t\t\t\tisSolanaConnected: !!providers.solana,\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\n\t\t\t\t\tconst namespaceOf: Record<WalletPlatform, string> = {\n\t\t\t\t\t\tpolkadot: \"polkadot\",\n\t\t\t\t\t\tethereum: \"eip155\",\n\t\t\t\t\t\tsolana: \"solana\",\n\t\t\t\t\t};\n\t\t\t\t\tconst allPlatforms: WalletPlatform[] = [\n\t\t\t\t\t\t\"polkadot\",\n\t\t\t\t\t\t\"ethereum\",\n\t\t\t\t\t\t\"solana\",\n\t\t\t\t\t];\n\t\t\t\t\tconst enabledPlatforms = allPlatforms.filter((p) =>\n\t\t\t\t\t\t(appKit.chainNamespaces as string[]).includes(namespaceOf[p]),\n\t\t\t\t\t);\n\n\t\t\t\t\tlet prevConnected = {\n\t\t\t\t\t\tpolkadot: false,\n\t\t\t\t\t\tethereum: false,\n\t\t\t\t\t\tsolana: false,\n\t\t\t\t\t};\n\n\t\t\t\t\tconst sub = status$\n\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\tmap((s) => ({\n\t\t\t\t\t\t\t\tpolkadot: s.isPolkadotConnected,\n\t\t\t\t\t\t\t\tethereum: s.isEthereumConnected,\n\t\t\t\t\t\t\t\tsolana: s.isSolanaConnected,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\tdistinctUntilChanged(\n\t\t\t\t\t\t\t\t(a, b) =>\n\t\t\t\t\t\t\t\t\ta.polkadot === b.polkadot &&\n\t\t\t\t\t\t\t\t\ta.ethereum === b.ethereum &&\n\t\t\t\t\t\t\t\t\ta.solana === b.solana,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\ttap((connected) => {\n\t\t\t\t\t\t\t\t// Drop caches for namespaces that just went disconnected.\n\t\t\t\t\t\t\t\tfor (const platform of allPlatforms)\n\t\t\t\t\t\t\t\t\tif (prevConnected[platform] && !connected[platform])\n\t\t\t\t\t\t\t\t\t\tdropAccountsCache(platform);\n\t\t\t\t\t\t\t\tprevConnected = connected;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tmap((connected): WalletConnectWallet => {\n\t\t\t\t\t\t\t\tconst platforms = enabledPlatforms.filter((p) => connected[p]);\n\t\t\t\t\t\t\t\tconst isConnected = platforms.length > 0;\n\t\t\t\t\t\t\t\tconst walletInfo = appKit.getWalletInfo();\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: WALLET_CONNECT_WALLET_ID,\n\t\t\t\t\t\t\t\t\ttype: \"walletconnect\",\n\t\t\t\t\t\t\t\t\tplatforms,\n\t\t\t\t\t\t\t\t\tappKit: appKitInstance,\n\t\t\t\t\t\t\t\t\tname: walletInfo?.name ?? \"WalletConnect\",\n\t\t\t\t\t\t\t\t\ticon: walletInfo?.icon ?? WALLET_CONNECT_ICON,\n\t\t\t\t\t\t\t\t\t// One shared session: connecting opens the modal; the wallet\n\t\t\t\t\t\t\t\t\t// approves namespaces in that single pairing. Disconnect is\n\t\t\t\t\t\t\t\t\t// session-wide; re-pair to change the approved set.\n\t\t\t\t\t\t\t\t\tconnect: async () => {\n\t\t\t\t\t\t\t\t\t\tif (!isConnected) await appKit.open();\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tdisconnect: async () => {\n\t\t\t\t\t\t\t\t\t\tif (isConnected) await appKit.disconnect();\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tisConnected,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.subscribe(subscriber);\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tsub.unsubscribe();\n\t\t\t\t\t\tunsubProviders();\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}),\n\t\t\t// refCount:false keeps the AppKit instance alive for the process lifetime\n\t\t\t// once created: createAppKit runs at most once (Reown AppKit cannot be\n\t\t\t// instantiated twice). With refCount:true the producer would re-run\n\t\t\t// createAppKit whenever every subscriber drained and a new one\n\t\t\t// re-subscribed — e.g. a React unmount/remount or StrictMode's\n\t\t\t// mount→unmount→remount — throwing on the duplicate Lit web components and\n\t\t\t// WalletConnect modal singleton. The replayed connector value also keeps\n\t\t\t// the wallet list stable across such teardown/rebuild cycles.\n\t\t\tshareReplay({ refCount: false, bufferSize: 1 }),\n\t\t);\n\t\tsetCachedAppKit(cachedAppKit, walletConnect.projectId);\n\t}\n\n\treturn cachedAppKit;\n};\n","import type { KheopskitConfig, KheopskitPlatform } from \"./types\";\n\n/**\n * Default storage key for persisting wallet connection state.\n * Can be overridden via config.storageKey to avoid conflicts\n * when running multiple dapps on the same domain.\n */\nexport const DEFAULT_STORAGE_KEY = \"kheopskit\";\n\nconst DEFAULTS = {\n\tautoReconnect: true,\n\tdebug: false,\n\tstorageKey: DEFAULT_STORAGE_KEY,\n\thydrationGracePeriod: 500,\n} satisfies Omit<KheopskitConfig, \"platforms\" | \"walletConnect\">;\n\nexport const resolveConfig = <\n\tconst P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(\n\tconfig?: Partial<KheopskitConfig<P>>,\n): KheopskitConfig<P> => {\n\tconst platforms = (config?.platforms ?? []) as P;\n\n\t// Guard the v4 breaking change: platforms are plugin instances, not strings.\n\t// Catches JS callers (no tsc) and gives agents a fix that names the doc.\n\tconst invalidPlatforms = (platforms as readonly unknown[]).filter(\n\t\t(p) =>\n\t\t\ttypeof p !== \"object\" ||\n\t\t\tp === null ||\n\t\t\ttypeof (p as { getWallets$?: unknown }).getWallets$ !== \"function\",\n\t);\n\tif (invalidPlatforms.length > 0) {\n\t\tthrow new Error(\n\t\t\t\"[kheopskit] config.platforms must contain plugin instances created by the \" +\n\t\t\t\t\"per-platform factories (e.g. platforms: [polkadot(), ethereum(), solana()] \" +\n\t\t\t\t'imported from \"@kheopskit/core/<platform>\"). ' +\n\t\t\t\t`Invalid entries: ${JSON.stringify(invalidPlatforms)}. ` +\n\t\t\t\t'String platform names like \"polkadot\" were removed in v4 — see MIGRATING_TO_V4.md.',\n\t\t);\n\t}\n\n\tif (platforms.length === 0) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] No platforms configured; wallets and accounts will be empty. \" +\n\t\t\t\t'Pass e.g. platforms: [polkadot()] from \"@kheopskit/core/polkadot\".',\n\t\t);\n\t}\n\n\treturn Object.assign({}, DEFAULTS, config, { platforms });\n};\n","import type { BaseWalletAccount, WalletPlatform } from \"../api/types\";\n\nconst PLATFORM_ORDER: Record<WalletPlatform, number> = {\n\tpolkadot: 0,\n\tethereum: 1,\n\tsolana: 2,\n};\n\n// Group accounts by wallet, surfacing Talisman first (case-insensitive).\nconst byWalletName = (a1: BaseWalletAccount, a2: BaseWalletAccount) => {\n\tif (a1.walletName.toLowerCase() === \"talisman\") return -1;\n\tif (a2.walletName.toLowerCase() === \"talisman\") return 1;\n\treturn a1.walletName.localeCompare(a2.walletName);\n};\n\nexport const sortAccounts = (a1: BaseWalletAccount, a2: BaseWalletAccount) => {\n\t// Sort by platform first: polkadot, then ethereum, then solana\n\tif (a1.platform !== a2.platform)\n\t\treturn PLATFORM_ORDER[a1.platform] - PLATFORM_ORDER[a2.platform];\n\n\t// Then group by wallet name\n\tif (a1.walletName !== a2.walletName) return byWalletName(a1, a2);\n\n\t// Polkadot accounts expose a friendly name; fall back to address\n\tif (a1.platform === \"polkadot\" && a2.platform === \"polkadot\")\n\t\treturn a1.name !== a2.name\n\t\t\t? (a1.name ?? \"\").localeCompare(a2.name ?? \"\")\n\t\t\t: a1.address.localeCompare(a2.address);\n\n\t// Ethereum and Solana accounts disambiguate by id\n\treturn a1.id.localeCompare(a2.id);\n};\n","import {\n\ttype BaseWallet,\n\tisWalletConnectWallet,\n\ttype WalletConnectWallet,\n\ttype WalletPlatform,\n} from \"../api/types\";\n\nconst PLATFORM_ORDER: Record<WalletPlatform, number> = {\n\tpolkadot: 0,\n\tethereum: 1,\n\tsolana: 2,\n};\n\n// The platform-less WalletConnect connector sorts after all platform wallets.\nconst orderOf = (wallet: BaseWallet | WalletConnectWallet) =>\n\tisWalletConnectWallet(wallet) ? 3 : PLATFORM_ORDER[wallet.platform];\n\nexport const sortWallets = (\n\tw1: BaseWallet | WalletConnectWallet,\n\tw2: BaseWallet | WalletConnectWallet,\n) => {\n\t// Sort by platform first: polkadot, then ethereum, then solana, then WC\n\tconst o1 = orderOf(w1);\n\tconst o2 = orderOf(w2);\n\tif (o1 !== o2) return o1 - o2;\n\n\t// Sort by name, but Talisman first\n\tif (w1.name.toLowerCase() === \"talisman\") return -1;\n\tif (w2.name.toLowerCase() === \"talisman\") return 1;\n\n\treturn w1.name.localeCompare(w2.name);\n};\n","import type { CachedAccount, KheopskitPlatform } from \"./types\";\n\n/**\n * Whether a cached account should survive SSR hydration, per its platform\n * plugin's `acceptsCachedAccount` hook. Plugins without the hook (and platforms\n * with no enabled plugin) accept all — matching the pre-plugin behavior where\n * only Polkadot accounts were filtered (by key type).\n */\nexport const acceptsCachedAccount = (\n\tcached: CachedAccount,\n\tplatforms: readonly KheopskitPlatform[],\n): boolean => {\n\tconst plugin = platforms.find((p) => p.platform === cached.platform);\n\treturn plugin?.acceptsCachedAccount?.(cached) ?? true;\n};\n","import { hydrateAccount, hydrateWallet } from \"../utils/hydrateState\";\nimport { getCachedIcon } from \"../utils/iconCache\";\nimport { sortAccounts } from \"../utils/sortAccounts\";\nimport { sortWallets } from \"../utils/sortWallets\";\nimport { acceptsCachedAccount } from \"./platform\";\nimport type { KheopskitStore } from \"./store\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tKheopskitPlatform,\n\tWalletConnectWallet,\n} from \"./types\";\n\n/** Result of {@link getHydratedSnapshot}: placeholder wallets and accounts built from the cache. */\nexport type HydratedSnapshot = {\n\twallets: (BaseWallet | WalletConnectWallet)[];\n\taccounts: BaseWalletAccount[];\n};\n\nexport type GetHydratedSnapshotOptions = {\n\t/**\n\t * Enrich wallets that have no icon from the localStorage icon cache.\n\t *\n\t * Must stay `false` for any snapshot that has to match server-rendered markup\n\t * (React's `getServerSnapshot` runs on the client during hydration, where the\n\t * icon cache is populated — enriching there would diverge from the server,\n\t * which always sees an empty cache).\n\t */\n\ticons?: boolean;\n};\n\n/**\n * Builds the cached-state snapshot every consumer must agree on: read the\n * store's cached state, hydrate wallets/accounts into placeholders, filter\n * accounts through each platform plugin's `acceptsCachedAccount` hook, and sort\n * with the same comparators the live pipeline uses.\n *\n * This is the single implementation behind the observable's initial seed and\n * both React snapshot sources (`serverValue`/`initialValue`). They must produce\n * the same shape in the same order or the UI flickers/reorders on reload — by\n * sharing this helper, that agreement holds by construction.\n */\nexport const getHydratedSnapshot = (\n\tstore: KheopskitStore,\n\tplatforms: readonly KheopskitPlatform[],\n\toptions: GetHydratedSnapshotOptions = {},\n): HydratedSnapshot => {\n\tconst cached = store.getCachedState();\n\n\tconst wallets = cached.wallets\n\t\t.map((cachedWallet) => {\n\t\t\tconst wallet = hydrateWallet(cachedWallet);\n\t\t\t// Some wallets (e.g. Ethereum) have no SSR-safe icon; optionally fill it\n\t\t\t// from the localStorage cache.\n\t\t\tif (!options.icons || wallet.icon) return wallet;\n\t\t\tconst icon = getCachedIcon(wallet.id);\n\t\t\treturn icon ? { ...wallet, icon } : wallet;\n\t\t})\n\t\t.sort(sortWallets);\n\n\tconst accounts = cached.accounts\n\t\t.filter((account) => acceptsCachedAccount(account, platforms))\n\t\t.map(hydrateAccount)\n\t\t.sort(sortAccounts);\n\n\treturn { wallets, accounts };\n};\n","import {\n\tcombineLatest,\n\tdebounceTime,\n\tdistinctUntilChanged,\n\tfilter,\n\tmap,\n\tObservable,\n\tshareReplay,\n\tthrottleTime,\n} from \"rxjs\";\nimport {\n\tcreateAccountHydrationBuffer,\n\tcreateHydrationBuffer,\n} from \"../utils/createHydrationBuffer\";\nimport { serializeAccount, serializeWallet } from \"../utils/hydrateState\";\nimport { getCachedIcon, setCachedIcons } from \"../utils/iconCache\";\nimport { logObservable } from \"../utils/logObservable\";\nimport { sortAccounts } from \"../utils/sortAccounts\";\nimport { sortWallets } from \"../utils/sortWallets\";\nimport { getAccounts$ } from \"./accounts\";\nimport { resolveConfig } from \"./config\";\nimport { getHydratedSnapshot } from \"./hydration\";\nimport { createKheopskitStore } from \"./store\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tKheopskitConfig,\n\tKheopskitPlatform,\n\tKheopskitState,\n\tWalletConnectWallet,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\nimport { getWallets$ } from \"./wallets\";\n\nexport type { KheopskitConfig, KheopskitState } from \"./types\";\n\n/** Options for {@link getKheopskit$}. */\nexport type GetKheopskitOptions = {\n\t/**\n\t * Cookie string for SSR hydration. When provided, state is read from cookies\n\t * instead of localStorage so the server can hydrate without a flash. Pass the\n\t * request's `cookie` header.\n\t */\n\tssrCookies?: string;\n\t/**\n\t * An existing store to reuse instead of creating one. Advanced escape hatch —\n\t * most callers omit it. (`@kheopskit/react` passes its provider-scoped store.)\n\t */\n\tstore?: ReturnType<typeof createKheopskitStore>;\n};\n\nexport const getKheopskit$ = <\n\tconst P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(\n\tconfig?: Partial<KheopskitConfig<P>>,\n\toptions: GetKheopskitOptions = {},\n): Observable<KheopskitState<P>> => {\n\tconst { ssrCookies, store: existingStore } = options;\n\tconst kc = resolveConfig(config);\n\tconst store =\n\t\texistingStore ??\n\t\tcreateKheopskitStore({ ssrCookies, storageKey: kc.storageKey });\n\n\tif (kc.debug) console.debug(\"[kheopskit] config\", kc);\n\n\t// Warn about SSR environment without cookies\n\tif (kc.debug && typeof window === \"undefined\" && ssrCookies === undefined) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] Running on server without `ssrCookies`. \" +\n\t\t\t\t\"Wallet state will not be hydrated. Pass cookies for SSR support.\",\n\t\t);\n\t}\n\n\t// Get cached state for hydration (same snapshot the React provider builds)\n\tconst { wallets: cachedWallets, accounts: cachedAccounts } =\n\t\tgetHydratedSnapshot(store, kc.platforms, { icons: true });\n\n\tif (kc.debug && cachedWallets.length > 0) {\n\t\tconsole.debug(\"[kheopskit] hydrating from cache:\", {\n\t\t\twallets: cachedWallets.length,\n\t\t\taccounts: cachedAccounts.length,\n\t\t});\n\t}\n\n\treturn new Observable<KheopskitState>((subscriber) => {\n\t\t// Get live wallets and accounts\n\t\tconst liveWallets$ = getWallets$(kc, store);\n\t\tconst liveAccounts$ = getAccounts$(kc, liveWallets$);\n\n\t\t// Apply hydration buffer to wallets\n\t\tconst bufferedWallets$ = createHydrationBuffer(\n\t\t\tcachedWallets,\n\t\t\tliveWallets$,\n\t\t\tkc.hydrationGracePeriod,\n\t\t\t(w) => w.id,\n\t\t\t// Hydration converges when all cached-connected wallets are connected in live\n\t\t\t(liveWallets, cached) => {\n\t\t\t\tconst cachedConnectedIds = new Set(\n\t\t\t\t\tcached.filter((w) => w.isConnected).map((w) => w.id),\n\t\t\t\t);\n\t\t\t\tif (cachedConnectedIds.size === 0) return true;\n\t\t\t\treturn [...cachedConnectedIds].every((id) =>\n\t\t\t\t\tliveWallets.some((w) => w.id === id && w.isConnected),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Merge: prefer cached isConnected state but get icon from cache or live\n\t\t\t(live, cached) => ({\n\t\t\t\t...cached,\n\t\t\t\t// Priority: cached icon > localStorage cache > live icon\n\t\t\t\ticon: cached.icon || getCachedIcon(cached.id) || live.icon,\n\t\t\t\t// Use live wallet's connect/disconnect functions\n\t\t\t\tconnect: live.connect,\n\t\t\t\tdisconnect: live.disconnect,\n\t\t\t}),\n\t\t\t// Transform cached-only items: add icon from localStorage cache\n\t\t\t(cached) => ({\n\t\t\t\t...cached,\n\t\t\t\ticon: cached.icon || getCachedIcon(cached.id) || \"\",\n\t\t\t}),\n\t\t);\n\n\t\t// Apply hydration buffer to accounts\n\t\tconst bufferedAccounts$ = createAccountHydrationBuffer(\n\t\t\tcachedAccounts,\n\t\t\tliveAccounts$,\n\t\t\tkc.hydrationGracePeriod,\n\t\t\t(a) => a.walletId,\n\t\t\t// Hydration converges when all wallets with cached accounts have provided live accounts\n\t\t\t(liveAccounts, cached) => {\n\t\t\t\tconst cachedWalletIds = new Set(cached.map((a) => a.walletId));\n\t\t\t\tif (cachedWalletIds.size === 0) return true;\n\t\t\t\tconst liveWalletIds = new Set(liveAccounts.map((a) => a.walletId));\n\t\t\t\treturn [...cachedWalletIds].every((id) => liveWalletIds.has(id));\n\t\t\t},\n\t\t);\n\n\t\t// Share the buffered streams so the main and persistence subscriptions\n\t\t// below reuse a single hydration pipeline (timers, isHydrating state)\n\t\t// instead of running the buffering twice.\n\t\tconst sharedWallets$ = bufferedWallets$.pipe(\n\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t);\n\t\tconst sharedAccounts$ = bufferedAccounts$.pipe(\n\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t);\n\n\t\t// Combine buffered wallets and accounts\n\t\tconst subscription = combineLatest({\n\t\t\twallets: sharedWallets$,\n\t\t\taccounts: sharedAccounts$,\n\t\t})\n\t\t\t.pipe(\n\t\t\t\tmap(({ wallets, accounts }) => {\n\t\t\t\t\tif (kc.debug) {\n\t\t\t\t\t\tconsole.debug(\"[kheopskit] hydration state\", {\n\t\t\t\t\t\t\twalletsHydrating: wallets.isHydrating,\n\t\t\t\t\t\t\taccountsHydrating: accounts.isHydrating,\n\t\t\t\t\t\t\twalletsConnected: wallets.items.filter((w) => w.isConnected)\n\t\t\t\t\t\t\t\t.length,\n\t\t\t\t\t\t\twalletsTotal: wallets.items.length,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\t// Sort on every emission with the same comparators used for the\n\t\t\t\t\t// cached initial snapshot. The hydration buffers append cached-only\n\t\t\t\t\t// items after live ones (and reconnects land out of order), so\n\t\t\t\t\t// without this the list visibly reorders as wallets come back.\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconfig: kc,\n\t\t\t\t\t\twallets: [...wallets.items].sort(sortWallets),\n\t\t\t\t\t\taccounts: [...accounts.items].sort(sortAccounts),\n\t\t\t\t\t\tisHydrating: wallets.isHydrating || accounts.isHydrating,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.subscribe(subscriber);\n\n\t\t// Persist state snapshot when hydration completes and state stabilizes\n\t\tconst persistSub = combineLatest({\n\t\t\twallets: sharedWallets$,\n\t\t\taccounts: sharedAccounts$,\n\t\t})\n\t\t\t.pipe(\n\t\t\t\t// Wait for hydration to complete\n\t\t\t\tfilter(\n\t\t\t\t\t({ wallets, accounts }) =>\n\t\t\t\t\t\t!wallets.isHydrating && !accounts.isHydrating,\n\t\t\t\t),\n\t\t\t\t// Debounce to avoid excessive writes\n\t\t\t\tdebounceTime(1000),\n\t\t\t\t// Only persist if the serialized snapshot would actually change.\n\t\t\t\t// Compare the persisted fields (not just ids): an Ethereum chain switch\n\t\t\t\t// keeps the same account id but changes the cached chainId, so an\n\t\t\t\t// id-only comparator would skip persisting it.\n\t\t\t\tdistinctUntilChanged((prev, curr) => {\n\t\t\t\t\tconst prevWalletKeys = prev.wallets.items.map(walletPersistKey);\n\t\t\t\t\tconst currWalletKeys = curr.wallets.items.map(walletPersistKey);\n\t\t\t\t\tconst prevAccountKeys = prev.accounts.items.map(accountChangeKey);\n\t\t\t\t\tconst currAccountKeys = curr.accounts.items.map(accountChangeKey);\n\t\t\t\t\treturn (\n\t\t\t\t\t\tarraysEqual(prevWalletKeys, currWalletKeys) &&\n\t\t\t\t\t\tarraysEqual(prevAccountKeys, currAccountKeys)\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.subscribe(({ wallets, accounts }) => {\n\t\t\t\t// Cache ALL wallets to avoid wallet list flash on reload\n\t\t\t\t// Only accounts from connected wallets are cached\n\t\t\t\tconst connectedWalletIds = new Set(\n\t\t\t\t\twallets.items.filter((w) => w.isConnected).map((w) => w.id),\n\t\t\t\t);\n\t\t\t\tconst relevantAccounts = accounts.items.filter((a) =>\n\t\t\t\t\tconnectedWalletIds.has(a.walletId),\n\t\t\t\t);\n\n\t\t\t\tif (kc.debug) {\n\t\t\t\t\tconsole.debug(\"[kheopskit] persisting state snapshot:\", {\n\t\t\t\t\t\twallets: wallets.items.length,\n\t\t\t\t\t\taccounts: relevantAccounts.length,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tstore.setCachedState(\n\t\t\t\t\twallets.items.map(serializeWallet),\n\t\t\t\t\trelevantAccounts.map(serializeAccount),\n\t\t\t\t);\n\n\t\t\t\t// Cache wallet icons in localStorage (separate from cookies for size)\n\t\t\t\tconst icons: Record<string, string> = {};\n\t\t\t\tfor (const wallet of wallets.items) {\n\t\t\t\t\tif (wallet.icon) {\n\t\t\t\t\t\ticons[wallet.id] = wallet.icon;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsetCachedIcons(icons);\n\t\t\t});\n\n\t\treturn () => {\n\t\t\tsubscription.unsubscribe();\n\t\t\tpersistSub.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tdistinctUntilChanged(statesEqual),\n\t\tthrottleTime(16, undefined, { leading: true, trailing: true }), // ~1 frame at 60fps\n\t\tlogObservable(\"kheopskit$\", { enabled: kc.debug, printValue: true }),\n\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t// The runtime objects are the concrete per-plugin wallet/account types;\n\t\t// recover the precise KheopskitState<P> the caller's plugins imply.\n\t) as unknown as Observable<KheopskitState<P>>;\n};\n\nconst arraysEqual = (a: string[], b: string[]) =>\n\ta.length === b.length && a.every((v, i) => v === b[i]);\n\n// Mutable per-platform account fields that can change without the account id\n// changing. Declared locally (not imported from the platform packages) so this\n// core entry stays free of platform SDK types — see check:isolation.\ntype EthereumAccountFields = { chainId?: number };\ntype PolkadotAccountFields = { type?: string };\ntype SolanaAccountFields = { chains?: string[] };\n\n/**\n * A signature of an account covering its id plus the platform-specific fields\n * that can change without the id changing (Ethereum chainId, Polkadot key type,\n * Solana clusters). Used to detect both UI-relevant changes and changes worth\n * re-persisting, so the two comparators can't drift apart.\n */\nconst accountChangeKey = (account: BaseWalletAccount): string => {\n\tswitch (account.platform) {\n\t\tcase \"ethereum\":\n\t\t\treturn `${account.id}|${(account as EthereumAccountFields).chainId ?? \"\"}`;\n\t\tcase \"polkadot\":\n\t\t\treturn `${account.id}|${(account as PolkadotAccountFields).type ?? \"\"}`;\n\t\tcase \"solana\":\n\t\t\treturn `${account.id}|${((account as SolanaAccountFields).chains ?? []).join(\",\")}`;\n\t\tdefault:\n\t\t\treturn account.id;\n\t}\n};\n\n/** Platforms a wallet's live session carries (only the WalletConnect connector). */\nconst walletPlatforms = (wallet: BaseWallet | WalletConnectWallet): string =>\n\tisWalletConnectWallet(wallet) ? wallet.platforms.join(\",\") : \"\";\n\n/** Fields persisted to the cache for a wallet (icon is stored separately). */\nconst walletPersistKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\t`${wallet.id}|${wallet.isConnected ? 1 : 0}|${wallet.name}`;\n\n/**\n * UI-significant signature of a wallet: the persisted fields plus icon and the\n * WalletConnect connector's `platforms` array, which drive what the UI shows but\n * aren't part of the id (icon and platforms can arrive asynchronously after\n * connect without isConnected flipping).\n */\nconst walletUiKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\t`${walletPersistKey(wallet)}|${wallet.icon}|${walletPlatforms(wallet)}`;\n\n/**\n * Equality check for KheopskitState to prevent unnecessary emissions. Compares\n * the UI-significant signature of every wallet and account, in order.\n */\nconst statesEqual = (a: KheopskitState, b: KheopskitState): boolean =>\n\ta.isHydrating === b.isHydrating &&\n\ta.wallets.length === b.wallets.length &&\n\ta.accounts.length === b.accounts.length &&\n\ta.wallets.every((w, i) => {\n\t\tconst other = b.wallets[i];\n\t\treturn !!other && walletUiKey(w) === walletUiKey(other);\n\t}) &&\n\ta.accounts.every((acc, i) => {\n\t\tconst other = b.accounts[i];\n\t\treturn !!other && accountChangeKey(acc) === accountChangeKey(other);\n\t});\n","import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tfilter,\n\tmap,\n\tObservable,\n\tSubscription,\n\tshareReplay,\n\tstartWith,\n\ttake,\n\ttimer,\n} from \"rxjs\";\n\ntype HydrationBufferResult<T> = {\n\titems: T[];\n\tisHydrating: boolean;\n};\n\n/**\n * Core hydration buffer logic shared between wallets and accounts.\n *\n * During the grace period:\n * - Emits cached items immediately (before any live emissions)\n * - As live items arrive, merges them using the provided merge function\n *\n * After the grace period (and convergence, if provided):\n * - Only live items are returned\n * - isHydrating becomes false\n *\n * If an `isConverged` function is provided, hydration ends only when BOTH\n * the grace period has elapsed AND the live items have converged with cached\n * items (e.g., all previously-connected wallets have reconnected).\n * A max timeout (6x grace period) prevents infinite hydration.\n *\n * @param cachedItems - Initial cached items from storage\n * @param liveItems$ - Observable of live items as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param mergeFn - Function to merge live and cached items during hydration\n * @param isConverged - Optional function to check if live items have caught up to cached items\n */\nconst createBufferCore = <T>(\n\tcachedItems: T[],\n\tliveItems$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tmergeFn: (liveItems: T[], cachedItems: T[]) => T[],\n\tisConverged?: (liveItems: T[], cachedItems: T[]) => boolean,\n): Observable<HydrationBufferResult<T>> => {\n\t// If no grace period or no cached items, just pass through live items\n\tif (gracePeriodMs <= 0 || cachedItems.length === 0) {\n\t\treturn liveItems$.pipe(map((items) => ({ items, isHydrating: false })));\n\t}\n\n\t// Wrap in an Observable to properly manage all subscriptions\n\treturn new Observable<HydrationBufferResult<T>>((subscriber) => {\n\t\tconst subscriptions = new Subscription();\n\n\t\t// Track whether we're still in the hydration grace period\n\t\t// Using BehaviorSubject to keep a stateful value that doesn't complete\n\t\tconst isHydrating$ = new BehaviorSubject(true);\n\n\t\t// Use startWith to emit cached items immediately before any live emissions\n\t\tconst liveWithInitial$ = liveItems$.pipe(startWith([] as T[]));\n\n\t\tif (isConverged) {\n\t\t\t// With convergence check: hydration ends when timer fires AND live state has caught up\n\t\t\tconst timerFired$ = timer(gracePeriodMs).pipe(\n\t\t\t\tmap(() => true),\n\t\t\t\tstartWith(false),\n\t\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t\t);\n\n\t\t\t// End hydration when timer has fired AND convergence is met\n\t\t\tsubscriptions.add(\n\t\t\t\tcombineLatest([liveWithInitial$, timerFired$])\n\t\t\t\t\t.pipe(\n\t\t\t\t\t\tfilter(([, timerFired]) => timerFired),\n\t\t\t\t\t\tfilter(([liveItems]) => isConverged(liveItems, cachedItems)),\n\t\t\t\t\t\ttake(1),\n\t\t\t\t\t)\n\t\t\t\t\t.subscribe(() => {\n\t\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t\t}),\n\t\t\t);\n\n\t\t\t// Max timeout (6x grace period) to prevent infinite hydration\n\t\t\t// e.g., if auto-reconnect fails, we still end hydration\n\t\t\tsubscriptions.add(\n\t\t\t\ttimer(gracePeriodMs * 6).subscribe(() => {\n\t\t\t\t\tif (isHydrating$.value) {\n\t\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t} else {\n\t\t\t// Without convergence check: end hydration on timer only\n\t\t\tsubscriptions.add(\n\t\t\t\ttimer(gracePeriodMs).subscribe(() => {\n\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tsubscriptions.add(\n\t\t\tcombineLatest([liveWithInitial$, isHydrating$])\n\t\t\t\t.pipe(\n\t\t\t\t\tmap(([liveItems, isHydrating]) => {\n\t\t\t\t\t\tif (!isHydrating) {\n\t\t\t\t\t\t\t// Hydration complete - return only live items\n\t\t\t\t\t\t\treturn { items: liveItems, isHydrating: false };\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\titems: mergeFn(liveItems, cachedItems),\n\t\t\t\t\t\t\tisHydrating: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber),\n\t\t);\n\n\t\treturn () => {\n\t\t\tsubscriptions.unsubscribe();\n\t\t\tisHydrating$.complete();\n\t\t};\n\t});\n};\n\n/**\n * Creates a hydration buffer that merges cached items with live items.\n *\n * During hydration, cached items take precedence over live items with the same key.\n * This preserves the cached connected state (e.g., isConnected: true) while\n * auto-reconnect is still in progress. New live items not in the cache are added.\n *\n * @param cachedItems - Initial cached items from storage\n * @param liveItems$ - Observable of live items as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param getKey - Function to extract a unique key from an item\n * @param isConverged - Optional function to check if live items have caught up to cached items\n * @param mergeItem - Optional function to merge a live item with its cached counterpart\n * @param transformCachedOnly - Optional function to transform cached items not yet in the live stream\n */\nexport const createHydrationBuffer = <T>(\n\tcachedItems: T[],\n\tliveItems$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tgetKey: (item: T) => string,\n\tisConverged?: (liveItems: T[], cachedItems: T[]) => boolean,\n\tmergeItem?: (liveItem: T, cachedItem: T) => T,\n\ttransformCachedOnly?: (cachedItem: T) => T,\n): Observable<HydrationBufferResult<T>> => {\n\treturn createBufferCore(\n\t\tcachedItems,\n\t\tliveItems$,\n\t\tgracePeriodMs,\n\t\t(liveItems, cached) => {\n\t\t\tconst cachedByKey = new Map(cached.map((item) => [getKey(item), item]));\n\t\t\tconst liveKeys = new Set(liveItems.map(getKey));\n\n\t\t\t// For items in both live and cached, prefer cached (preserves connected state)\n\t\t\t// but allow mergeItem to customize how they're combined\n\t\t\t// For items only in live (newly discovered), use the live version\n\t\t\tconst mergedItems: T[] = liveItems.map((liveItem) => {\n\t\t\t\tconst key = getKey(liveItem);\n\t\t\t\tconst cachedItem = cachedByKey.get(key);\n\t\t\t\tif (!cachedItem) return liveItem;\n\t\t\t\treturn mergeItem ? mergeItem(liveItem, cachedItem) : cachedItem;\n\t\t\t});\n\n\t\t\t// Add cached items not yet in the live stream (e.g., extensions not yet detected)\n\t\t\tfor (const cachedItem of cached) {\n\t\t\t\tif (!liveKeys.has(getKey(cachedItem))) {\n\t\t\t\t\tconst transformed = transformCachedOnly\n\t\t\t\t\t\t? transformCachedOnly(cachedItem)\n\t\t\t\t\t\t: cachedItem;\n\t\t\t\t\tmergedItems.push(transformed);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mergedItems;\n\t\t},\n\t\tisConverged,\n\t);\n};\n\n/**\n * Creates a hydration buffer specifically for accounts, which need special handling.\n *\n * Accounts are grouped by wallet - when a wallet provides its account list,\n * we replace all cached accounts for that wallet with the live ones.\n * Cached accounts for wallets that haven't provided accounts yet are preserved.\n *\n * @param cachedAccounts - Initial cached accounts from storage\n * @param liveAccounts$ - Observable of live accounts as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param getWalletId - Function to extract the wallet ID from an account\n * @param isConverged - Optional function to check if live accounts have caught up to cached accounts\n */\nexport const createAccountHydrationBuffer = <T>(\n\tcachedAccounts: T[],\n\tliveAccounts$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tgetWalletId: (account: T) => string,\n\tisConverged?: (liveAccounts: T[], cachedAccounts: T[]) => boolean,\n): Observable<HydrationBufferResult<T>> => {\n\treturn createBufferCore(\n\t\tcachedAccounts,\n\t\tliveAccounts$,\n\t\tgracePeriodMs,\n\t\t(liveAccounts, cached) => {\n\t\t\tconst walletsWithLiveAccounts = new Set(liveAccounts.map(getWalletId));\n\t\t\tconst mergedAccounts: T[] = [...liveAccounts];\n\n\t\t\tfor (const cachedAccount of cached) {\n\t\t\t\tif (!walletsWithLiveAccounts.has(getWalletId(cachedAccount))) {\n\t\t\t\t\tmergedAccounts.push(cachedAccount);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mergedAccounts;\n\t\t},\n\t\tisConverged,\n\t);\n};\n","import { type MonoTypeOperatorFunction, tap } from \"rxjs\";\n\ntype Opts = {\n\tprintValue?: boolean;\n\tenabled?: boolean;\n};\n\nexport const logObservable = <T>(\n\tlabel: string,\n\topts?: Opts,\n): MonoTypeOperatorFunction<T> =>\n\ttap((value) => {\n\t\tconst { printValue = false, enabled = true } = opts || {};\n\n\t\tif (!label || !enabled) return;\n\n\t\tconst text = `[kheopskit] observable ${label} emit`;\n\n\t\tif (printValue) console.debug(text, value);\n\t\telse console.debug(text);\n\t});\n","import { combineLatest, map, Observable, of, shareReplay } from \"rxjs\";\nimport { sortAccounts } from \"../utils/sortAccounts\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tKheopskitConfig,\n\tWalletConnectWallet,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\nexport const getAccounts$ = (\n\tconfig: KheopskitConfig,\n\twallets: Observable<(BaseWallet | WalletConnectWallet)[]>,\n) => {\n\treturn new Observable<BaseWalletAccount[]>((subscriber) => {\n\t\t// Each plugin gets its own platform's (injected) wallets plus the shared\n\t\t// WalletConnect connector; it derives WC accounts only for the namespaces\n\t\t// the session carries.\n\t\tconst sources = config.platforms.map((plugin) =>\n\t\t\tplugin.getAccounts$(\n\t\t\t\twallets.pipe(\n\t\t\t\t\tmap((ws) =>\n\t\t\t\t\t\tws.filter(\n\t\t\t\t\t\t\t(w) => isWalletConnectWallet(w) || w.platform === plugin.platform,\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\tconst accounts$ = sources.length\n\t\t\t? combineLatest(sources).pipe(\n\t\t\t\t\tmap((accounts) => accounts.flat().sort(sortAccounts)),\n\t\t\t\t)\n\t\t\t: of<BaseWalletAccount[]>([]);\n\n\t\tconst sub = accounts$.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n","import { uniq } from \"lodash-es\";\nimport { createStore } from \"../utils/createStore\";\nimport { isWalletPlatform } from \"../utils/isWalletPlatform\";\nimport { safeLocalStorage } from \"../utils/storage\";\nimport {\n\tisValidWalletId,\n\tparseWalletId,\n\tWALLET_CONNECT_WALLET_ID,\n\ttype WalletId,\n} from \"../utils/WalletId\";\nimport { createCompactCookieStorage } from \"./compactStore\";\nimport { DEFAULT_STORAGE_KEY } from \"./config\";\nimport type {\n\tCachedAccount,\n\tCachedWallet,\n\tKheopskitStore,\n\tKheopskitStoreData,\n} from \"./types\";\n\nexport type { KheopskitStore } from \"./types\";\n\nconst DEFAULT_SETTINGS: KheopskitStoreData = {};\n\n/**\n * Validates a cached wallet read from persisted storage. Cached state may have\n * been written by an older (or corrupted) version with a different shape, so we\n * drop anything that wouldn't survive hydration/sort rather than letting it\n * throw at render time. Only the fields downstream code relies on are checked.\n */\nconst isValidCachedWallet = (value: unknown): value is CachedWallet => {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst w = value as Record<string, unknown>;\n\tif (!isValidWalletId(w.id)) return false;\n\tif (typeof w.name !== \"string\" || typeof w.isConnected !== \"boolean\")\n\t\treturn false;\n\t// The WalletConnect connector is platform-less with a fixed id; drop stale\n\t// per-platform WC entries written by older versions.\n\tif (w.type === \"walletconnect\")\n\t\treturn w.id === WALLET_CONNECT_WALLET_ID && w.platform === undefined;\n\treturn w.type === \"injected\" && isWalletPlatform(w.platform);\n};\n\n/** Validates a cached account read from persisted storage. See {@link isValidCachedWallet}. */\nconst isValidCachedAccount = (value: unknown): value is CachedAccount => {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst a = value as Record<string, unknown>;\n\treturn (\n\t\ttypeof a.id === \"string\" &&\n\t\t!!a.id &&\n\t\tisWalletPlatform(a.platform) &&\n\t\ttypeof a.address === \"string\" &&\n\t\t!!a.address &&\n\t\tisValidWalletId(a.walletId) &&\n\t\ttypeof a.walletName === \"string\"\n\t);\n};\n\ntype CreateKheopskitStoreOptions = {\n\t/**\n\t * Cookie string for SSR hydration.\n\t * When provided, uses cookieStorage instead of localStorage.\n\t */\n\tssrCookies?: string;\n\t/**\n\t * Custom storage key to namespace the stored data.\n\t * @default \"kheopskit\"\n\t */\n\tstorageKey?: string;\n};\n\n/**\n * Creates a kheopskit store with the appropriate storage backend.\n * Uses cookieStorage when ssrCookies is provided (for SSR hydration),\n * otherwise falls back to safeLocalStorage.\n *\n * @param options - Configuration options for the store\n */\nexport const createKheopskitStore = (\n\toptions: CreateKheopskitStoreOptions = {},\n): KheopskitStore => {\n\tconst { ssrCookies, storageKey = DEFAULT_STORAGE_KEY } = options;\n\tconst storage =\n\t\tssrCookies !== undefined\n\t\t\t? createCompactCookieStorage(ssrCookies)\n\t\t\t: safeLocalStorage;\n\tconst store = createStore(storageKey, DEFAULT_SETTINGS, storage);\n\n\tconst addEnabledWalletId = (walletId: WalletId) => {\n\t\tparseWalletId(walletId); // validate walletId\n\t\tstore.mutate((prev) => ({\n\t\t\t...prev,\n\t\t\tautoReconnect: uniq((prev.autoReconnect ?? []).concat(walletId)),\n\t\t}));\n\t};\n\n\tconst removeEnabledWalletId = (walletId: WalletId) => {\n\t\tstore.mutate((prev) => ({\n\t\t\t...prev,\n\t\t\tautoReconnect: uniq(\n\t\t\t\t(prev.autoReconnect ?? []).filter((id) => id !== walletId),\n\t\t\t),\n\t\t}));\n\t};\n\n\tconst getCachedState = () => {\n\t\t// `store.get()` returns whatever JSON was persisted — it may be from an\n\t\t// older version, a different shape, or outright corrupt. Read defensively:\n\t\t// coerce non-objects/arrays to empty and drop any entry that fails\n\t\t// validation, so stale cache degrades to \"start fresh\" instead of throwing\n\t\t// during hydration (which renders eagerly, so a throw blanks the dapp).\n\t\tconst data = store.get() as Partial<KheopskitStoreData> | null | undefined;\n\t\tconst cachedWallets = Array.isArray(data?.cachedWallets)\n\t\t\t? data.cachedWallets\n\t\t\t: [];\n\t\tconst cachedAccounts = Array.isArray(data?.cachedAccounts)\n\t\t\t? data.cachedAccounts\n\t\t\t: [];\n\t\treturn {\n\t\t\twallets: cachedWallets.filter(isValidCachedWallet),\n\t\t\taccounts: cachedAccounts.filter(isValidCachedAccount),\n\t\t};\n\t};\n\n\tconst setCachedState = (\n\t\twallets: CachedWallet[],\n\t\taccounts: CachedAccount[],\n\t) => {\n\t\tstore.mutate((prev) => ({\n\t\t\t...prev,\n\t\t\tcachedWallets: wallets,\n\t\t\tcachedAccounts: accounts,\n\t\t}));\n\t};\n\n\treturn {\n\t\tobservable: store.observable,\n\t\taddEnabledWalletId,\n\t\tremoveEnabledWalletId,\n\t\tgetCachedState,\n\t\tsetCachedState,\n\t};\n};\n\n/**\n * Cached default store instance, anchored on globalThis so it stays a single\n * instance even if this module is duplicated across bundle chunks (e.g. CJS\n * subpath entries). Lazily initialized on first access to be SSR-safe.\n */\nconst DEFAULT_STORE_SYMBOL = Symbol.for(\"kheopskit.defaultStore\");\n\n/**\n * Gets the default store, creating it on first access.\n * Uses localStorage on client, noop on server.\n * Lazily initialized to avoid SSR issues with module-level code.\n */\nexport const getDefaultStore = (): KheopskitStore => {\n\tconst g = globalThis as unknown as Record<symbol, KheopskitStore | undefined>;\n\tif (!g[DEFAULT_STORE_SYMBOL]) {\n\t\tg[DEFAULT_STORE_SYMBOL] = createKheopskitStore();\n\t}\n\treturn g[DEFAULT_STORE_SYMBOL];\n};\n","import { BehaviorSubject } from \"rxjs\";\nimport { type SyncableStorage, safeLocalStorage } from \"./storage\";\n\nexport const createStore = <T>(\n\tkey: string,\n\tdefaultValue: T,\n\tstorage: SyncableStorage = safeLocalStorage,\n) => {\n\tconst subject = new BehaviorSubject<T>(\n\t\tgetStoredData(key, defaultValue, storage),\n\t);\n\n\t// Cross-tab sync via storage.subscribe (uses storage event for localStorage, BroadcastChannel for cookies)\n\t// Only subscribe if window is available (client-side) and storage supports it\n\tlet unsubscribeStorage: (() => void) | undefined;\n\tif (typeof window !== \"undefined\" && storage.subscribe) {\n\t\tunsubscribeStorage = storage.subscribe(key, (newValue) => {\n\t\t\tsubject.next(parseData(newValue, defaultValue));\n\t\t});\n\t}\n\n\tconst update = (val: T) => {\n\t\tsetStoredData(key, val, storage);\n\t\tsubject.next(val);\n\t};\n\n\treturn {\n\t\tobservable: subject.asObservable(),\n\t\tset: (val: T) => update(val),\n\t\tmutate: (transform: (prev: T) => T) =>\n\t\t\tupdate(transform(subject.getValue())),\n\t\tget: () => structuredClone(subject.getValue()),\n\t\t/**\n\t\t * Cleanup subscriptions. Call this when the store is no longer needed.\n\t\t */\n\t\tdestroy: () => {\n\t\t\tunsubscribeStorage?.();\n\t\t\tsubject.complete();\n\t\t},\n\t};\n};\n\nconst parseData = <T>(str: string | null, defaultValue: T): T => {\n\ttry {\n\t\tif (str) return JSON.parse(str);\n\t} catch {\n\t\t// invalid data\n\t}\n\treturn defaultValue;\n};\n\nconst getStoredData = <T>(\n\tkey: string,\n\tdefaultValue: T,\n\tstorage: SyncableStorage,\n): T => {\n\tconst str = storage.getItem(key);\n\treturn parseData(str, defaultValue);\n};\n\nconst setStoredData = <T>(key: string, val: T, storage: SyncableStorage) => {\n\tconst str = JSON.stringify(val);\n\tstorage.setItem(key, str);\n};\n","import { isWalletPlatform } from \"../utils/isWalletPlatform\";\nimport { cookieStorage } from \"../utils/storage\";\nimport { getWalletAccountId } from \"../utils/WalletAccountId\";\nimport {\n\tisValidWalletId,\n\tparseWalletId,\n\tWALLET_CONNECT_WALLET_ID,\n\ttype WalletId,\n} from \"../utils/WalletId\";\nimport type {\n\tCachedAccount,\n\tCachedWallet,\n\tKheopskitStoreData,\n\tWalletPlatform,\n} from \"./types\";\n\n/**\n * Compact wire format for the cookie-persisted store (`CompactStoreV1`).\n *\n * Cookies are size-constrained (~4KB per cookie, sent on every request), so the\n * persisted {@link KheopskitStoreData} is encoded as terse tuples with\n * single-letter keys instead of raw JSON. This module owns that format: the\n * encoder, the defensive decoder, and the lazy migration from the legacy\n * verbose-JSON cookies written by older versions.\n *\n * Any change here is a compatibility question — new fields must be optional and\n * decoding must keep accepting everything older versions wrote (or degrade to\n * \"start fresh\", never throw).\n */\n\n// wallet type: 0=injected, 1=walletconnect\ntype CompactWalletEntry = [WalletId, string, 0 | 1, 0 | 1];\ntype CompactPolkadotAccountType = 0 | 1 | 2 | 3;\n// platform: 0=polkadot, 1=ethereum, 2=solana\ntype CompactPlatformCode = 0 | 1 | 2;\ntype CompactAccountEntry = [\n\tWalletId,\n\tstring,\n\tstring | null,\n\tnumber | null,\n\tCompactPolkadotAccountType | null,\n\t// Platform code. Newly written entries always include it (the WalletConnect\n\t// connector's walletId is platform-less, so platform can't be derived from\n\t// it); absent in entries written by older versions, where it's derived from\n\t// the walletId instead.\n\t(CompactPlatformCode | null)?,\n];\n\ntype CompactStoreV1 = {\n\tv: 1;\n\t// autoReconnect\n\tr?: WalletId[];\n\t// wallets: [id, name, isConnected(0|1), type(0=injected,1=walletconnect)?]\n\tw?: CompactWalletEntry[];\n\t// accounts: [walletId, address, name?, chainId?, polkadotType?, platform?]\n\ta?: CompactAccountEntry[];\n};\n\nconst EMPTY_STORE_DATA: KheopskitStoreData = {};\n\nconst toCompactPolkadotAccountType = (\n\ttype: CachedAccount[\"polkadotAccountType\"],\n): CompactPolkadotAccountType | null => {\n\tswitch (type) {\n\t\tcase \"sr25519\":\n\t\t\treturn 0;\n\t\tcase \"ed25519\":\n\t\t\treturn 1;\n\t\tcase \"ecdsa\":\n\t\t\treturn 2;\n\t\tcase \"ethereum\":\n\t\t\treturn 3;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n};\n\nconst fromCompactPolkadotAccountType = (\n\ttype: CompactPolkadotAccountType | null | undefined,\n): CachedAccount[\"polkadotAccountType\"] => {\n\tswitch (type) {\n\t\tcase 0:\n\t\t\treturn \"sr25519\";\n\t\tcase 1:\n\t\t\treturn \"ed25519\";\n\t\tcase 2:\n\t\t\treturn \"ecdsa\";\n\t\tcase 3:\n\t\t\treturn \"ethereum\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n};\n\nconst toCompactPlatform = (platform: WalletPlatform): CompactPlatformCode => {\n\tswitch (platform) {\n\t\tcase \"polkadot\":\n\t\t\treturn 0;\n\t\tcase \"ethereum\":\n\t\t\treturn 1;\n\t\tcase \"solana\":\n\t\t\treturn 2;\n\t}\n};\n\nconst fromCompactPlatform = (\n\tcode: CompactPlatformCode | null | undefined,\n): WalletPlatform | undefined => {\n\tswitch (code) {\n\t\tcase 0:\n\t\t\treturn \"polkadot\";\n\t\tcase 1:\n\t\t\treturn \"ethereum\";\n\t\tcase 2:\n\t\t\treturn \"solana\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n};\n\nconst isCompactStore = (value: unknown): value is CompactStoreV1 => {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tif (\"cachedWallets\" in value || \"cachedAccounts\" in value) return false;\n\treturn \"v\" in value || \"w\" in value || \"a\" in value || \"r\" in value;\n};\n\nconst toCompactStore = (data: KheopskitStoreData): CompactStoreV1 => {\n\tconst wallets = data.cachedWallets?.map(\n\t\t(wallet): CompactWalletEntry => [\n\t\t\twallet.id,\n\t\t\twallet.name,\n\t\t\twallet.isConnected ? 1 : 0,\n\t\t\twallet.type === \"walletconnect\" ? 1 : 0,\n\t\t],\n\t);\n\n\tconst accounts = data.cachedAccounts?.map(\n\t\t(account): CompactAccountEntry => [\n\t\t\taccount.walletId,\n\t\t\taccount.address,\n\t\t\taccount.name ?? null,\n\t\t\taccount.chainId ?? null,\n\t\t\ttoCompactPolkadotAccountType(account.polkadotAccountType),\n\t\t\ttoCompactPlatform(account.platform),\n\t\t],\n\t);\n\n\treturn {\n\t\tv: 1,\n\t\tr: data.autoReconnect,\n\t\tw: wallets?.length ? wallets : undefined,\n\t\ta: accounts?.length ? accounts : undefined,\n\t};\n};\n\nconst fromCompactStore = (data: CompactStoreV1): KheopskitStoreData => {\n\tconst walletNameMap = new Map<WalletId, string>();\n\n\t// Decode defensively: a compact payload may be malformed (older/corrupt\n\t// cookie, hand-edited). Skip entries with an unparseable wallet id rather\n\t// than throwing, which would crash store initialisation.\n\tconst wallets: CachedWallet[] = [];\n\tfor (const item of Array.isArray(data.w) ? data.w : []) {\n\t\tif (!Array.isArray(item)) continue;\n\t\tconst [id, name, isConnected, type] = item;\n\t\tif (!isValidWalletId(id)) continue;\n\t\tconst isWalletConnect = id === WALLET_CONNECT_WALLET_ID;\n\t\tconst walletType = type === 1 ? \"walletconnect\" : \"injected\";\n\t\t// Keep id/type consistent: the platform-less connector uses the fixed WC\n\t\t// id; everything else is a platform-prefixed injected wallet. Drop stale\n\t\t// mismatches (e.g. per-platform WC ids from older versions).\n\t\tif (isWalletConnect !== (walletType === \"walletconnect\")) continue;\n\t\twalletNameMap.set(id, name);\n\t\twallets.push({\n\t\t\tid,\n\t\t\tplatform: isWalletConnect ? undefined : parseWalletId(id).platform,\n\t\t\ttype: walletType,\n\t\t\tname,\n\t\t\tisConnected: isConnected === 1,\n\t\t});\n\t}\n\n\tconst accounts: CachedAccount[] = [];\n\tfor (const item of Array.isArray(data.a) ? data.a : []) {\n\t\tif (!Array.isArray(item)) continue;\n\t\tconst [\n\t\t\twalletId,\n\t\t\taddress,\n\t\t\tname,\n\t\t\tchainId,\n\t\t\tpolkadotAccountType,\n\t\t\tplatformCode,\n\t\t] = item;\n\t\tif (!isValidWalletId(walletId) || typeof address !== \"string\" || !address)\n\t\t\tcontinue;\n\t\t// Prefer the explicit platform code; fall back to deriving it from the\n\t\t// walletId for entries written before the code existed (never WC ones).\n\t\tconst platform =\n\t\t\tplatformCode != null\n\t\t\t\t? fromCompactPlatform(platformCode)\n\t\t\t\t: walletId === WALLET_CONNECT_WALLET_ID\n\t\t\t\t\t? undefined\n\t\t\t\t\t: parseWalletId(walletId).platform;\n\t\tif (!isWalletPlatform(platform)) continue;\n\t\taccounts.push({\n\t\t\tid: getWalletAccountId(walletId, address),\n\t\t\tplatform,\n\t\t\taddress,\n\t\t\tname: name ?? undefined,\n\t\t\tchainId: chainId ?? undefined,\n\t\t\tpolkadotAccountType:\n\t\t\t\tplatform === \"polkadot\"\n\t\t\t\t\t? fromCompactPolkadotAccountType(polkadotAccountType)\n\t\t\t\t\t: undefined,\n\t\t\twalletId,\n\t\t\twalletName: walletNameMap.get(walletId) ?? walletId,\n\t\t});\n\t}\n\n\treturn {\n\t\tautoReconnect: data.r,\n\t\tcachedWallets: wallets,\n\t\tcachedAccounts: accounts,\n\t};\n};\n\nconst decodeStore = (raw: string, fallback: KheopskitStoreData) => {\n\ttry {\n\t\tconst parsed = JSON.parse(raw) as unknown;\n\t\tif (isCompactStore(parsed)) return fromCompactStore(parsed);\n\t\treturn parsed as KheopskitStoreData;\n\t} catch {\n\t\treturn fallback;\n\t}\n};\n\nconst encodeStore = (data: KheopskitStoreData): string =>\n\tJSON.stringify(toCompactStore(data));\n\n/**\n * Cookie storage that transparently encodes/decodes {@link CompactStoreV1},\n * migrating legacy verbose-JSON cookies to the compact format on first read.\n */\nexport const createCompactCookieStorage = (initialCookies?: string) => {\n\tconst base = cookieStorage(initialCookies);\n\n\treturn {\n\t\tgetItem: (key: string) => {\n\t\t\tconst raw = base.getItem(key);\n\t\t\tif (!raw) return null;\n\t\t\tconst expanded = decodeStore(raw, EMPTY_STORE_DATA);\n\t\t\tif (typeof document !== \"undefined\") {\n\t\t\t\ttry {\n\t\t\t\t\tconst parsed = JSON.parse(raw) as unknown;\n\t\t\t\t\tif (!isCompactStore(parsed)) {\n\t\t\t\t\t\tbase.setItem(key, encodeStore(expanded));\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore malformed cookie during migration\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn JSON.stringify(expanded);\n\t\t},\n\t\tsetItem: (key: string, value: string) => {\n\t\t\tconst expanded = decodeStore(value, EMPTY_STORE_DATA);\n\t\t\tbase.setItem(key, encodeStore(expanded));\n\t\t},\n\t\tremoveItem: base.removeItem,\n\t\tsubscribe: (key: string, callback: (value: string | null) => void) => {\n\t\t\tconst unsubscribe = base.subscribe?.(key, (value) => {\n\t\t\t\tif (!value) {\n\t\t\t\t\tcallback(null);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst expanded = decodeStore(value, EMPTY_STORE_DATA);\n\t\t\t\tcallback(JSON.stringify(expanded));\n\t\t\t});\n\t\t\treturn () => {\n\t\t\t\tunsubscribe?.();\n\t\t\t};\n\t\t},\n\t};\n};\n","import {\n\tcombineLatest,\n\tfilter,\n\tmap,\n\tmergeMap,\n\tObservable,\n\tof,\n\tshareReplay,\n\ttake,\n} from \"rxjs\";\nimport { sortWallets } from \"../utils/sortWallets\";\nimport { getWalletConnectWallet$ } from \"./appKit\";\nimport { createReconnectPolicy } from \"./reconnectPolicy\";\nimport type { KheopskitStore } from \"./store\";\nimport type {\n\tBaseWallet,\n\tKheopskitConfig,\n\tPlatformContext,\n\tWalletConnectWallet,\n} from \"./types\";\n\nexport const getWallets$ = (config: KheopskitConfig, store: KheopskitStore) => {\n\t// lock the list of wallets to auto reconnect on first call\n\tconst autoReconnectWalletIds$ = store.observable.pipe(\n\t\tmap((s) => s.autoReconnect ?? []),\n\t\ttake(1),\n\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t);\n\n\treturn new Observable<(BaseWallet | WalletConnectWallet)[]>((subscriber) => {\n\t\tconst ctx: PlatformContext = { config, store };\n\t\tconst observables = config.platforms.map((plugin) =>\n\t\t\tplugin.getWallets$(ctx),\n\t\t);\n\n\t\tconst platformWallets$ = observables.length\n\t\t\t? combineLatest(observables).pipe(map((wallets) => wallets.flat()))\n\t\t\t: of<BaseWallet[]>([]);\n\n\t\t// The single, platform-less WalletConnect connector is appended here (not\n\t\t// emitted per platform). It sorts last (see sortWallets).\n\t\tconst wallets$ = combineLatest([\n\t\t\tplatformWallets$,\n\t\t\tgetWalletConnectWallet$(config),\n\t\t]).pipe(\n\t\t\tmap(([platformWallets, walletConnect]) => {\n\t\t\t\tconst all: (BaseWallet | WalletConnectWallet)[] = walletConnect\n\t\t\t\t\t? [...platformWallets, walletConnect]\n\t\t\t\t\t: platformWallets;\n\t\t\t\treturn all.sort(sortWallets);\n\t\t\t}),\n\t\t\t// Note: No startWith([]) here - the hydration buffer handles initial state\n\t\t);\n\n\t\tconst reconnectPolicy = createReconnectPolicy();\n\n\t\tconst subAutoReconnect = combineLatest([wallets$, autoReconnectWalletIds$])\n\t\t\t.pipe(\n\t\t\t\tfilter(([, walletIds]) => config.autoReconnect && !!walletIds?.length),\n\t\t\t\tmergeMap(([wallets, walletIds]) =>\n\t\t\t\t\twallets.filter((wallet) => walletIds?.includes(wallet.id)),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.subscribe(async (wallet) => {\n\t\t\t\tif (wallet.isConnected) return;\n\t\t\t\ttry {\n\t\t\t\t\tawait reconnectPolicy.attempt(wallet.id, () => wallet.connect());\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconsole.error(\"Failed to reconnect wallet %s\", wallet.id, { err });\n\t\t\t\t}\n\t\t\t});\n\n\t\tconst subWallets = wallets$.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsubAutoReconnect.unsubscribe();\n\t\t\tsubWallets.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n","/**\n * Bookkeeping for wallet auto-reconnect attempts.\n *\n * Tracks wallets currently reconnecting (to avoid duplicate concurrent\n * attempts) and those already reconnected (so we don't fight a later manual\n * disconnect). A failed attempt is retried when the wallet next re-emits\n * (e.g. a late-injecting extension that isn't ready on first sight), but only\n * up to `maxAttempts`: a wallet whose connect() keeps rejecting (a permission\n * permanently denied, a buggy provider) must not be re-attempted on every\n * wallets$ emission — the stream re-emits frequently (polkadot polling,\n * mipd/wallet-standard register events).\n */\nexport type ReconnectPolicyOptions = {\n\t/** @default 3 */\n\tmaxAttempts?: number;\n};\n\nexport const createReconnectPolicy = ({\n\tmaxAttempts = 3,\n}: ReconnectPolicyOptions = {}) => {\n\tconst reconnecting = new Set<string>();\n\tconst reconnected = new Set<string>();\n\tconst failedAttempts = new Map<string, number>();\n\n\tconst shouldAttempt = (walletId: string): boolean =>\n\t\t!reconnecting.has(walletId) &&\n\t\t!reconnected.has(walletId) &&\n\t\t(failedAttempts.get(walletId) ?? 0) < maxAttempts;\n\n\t/**\n\t * Runs `connect` under the policy. Resolves `false` without connecting when\n\t * an attempt is already in flight, the wallet already reconnected, or it\n\t * exhausted its attempts; resolves `true` on success. A rejection from\n\t * `connect` is recorded as a failed attempt and rethrown for the caller to\n\t * report.\n\t */\n\tconst attempt = async (\n\t\twalletId: string,\n\t\tconnect: () => Promise<unknown>,\n\t): Promise<boolean> => {\n\t\tif (!shouldAttempt(walletId)) return false;\n\n\t\treconnecting.add(walletId);\n\t\ttry {\n\t\t\tawait connect();\n\t\t\treconnected.add(walletId);\n\t\t\tfailedAttempts.delete(walletId);\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tfailedAttempts.set(walletId, (failedAttempts.get(walletId) ?? 0) + 1);\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\treconnecting.delete(walletId);\n\t\t}\n\t};\n\n\treturn { shouldAttempt, attempt };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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AAI,gBAAgB,MAAM,CAAC;AAMtE,IAAM,cAAc,CAAC,GAAmB,MACvC,EAAE,gBAAgB,EAAE,eACpB,EAAE,QAAQ,WAAW,EAAE,QAAQ,UAC/B,EAAE,SAAS,WAAW,EAAE,SAAS,UACjC,EAAE,QAAQ,MAAM,CAAC,GAAG,MAAM;AACzB,QAAM,QAAQ,EAAE,QAAQ,CAAC;AACzB,SAAO,CAAC,CAAC,SAAS,YAAY,CAAC,MAAM,YAAY,KAAK;AACvD,CAAC,KACD,EAAE,SAAS,MAAM,CAAC,KAAK,MAAM;AAC5B,QAAM,QAAQ,EAAE,SAAS,CAAC;AAC1B,SAAO,CAAC,CAAC,SAAS,iBAAiB,GAAG,MAAM,iBAAiB,KAAK;AACnE,CAAC;","names":["PLATFORM_ORDER","combineLatest","distinctUntilChanged","filter","map","Observable","shareReplay","BehaviorSubject","map","Observable","shareReplay","getWalletId","tap","combineLatest","map","Observable","of","shareReplay","Observable","map","combineLatest","of","shareReplay","BehaviorSubject","BehaviorSubject","combineLatest","filter","map","Observable","of","shareReplay","take","map","take","shareReplay","Observable","combineLatest","of","filter","Observable","shareReplay","combineLatest","map","filter","distinctUntilChanged"]}
|
package/dist/internal.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CachedAccount, K as KheopskitPlatform, h as BaseWalletAccount, j as CachedWallet, B as BaseWallet, b as WalletConnectWallet } from './types-C7V7DGlg.mjs';
|
|
2
1
|
export { a as clearCachedObservable, b as clearCachedObservablesByPrefix } from './getCachedObservable-C4E8dfMp.mjs';
|
|
2
|
+
import { f as BaseWalletAccount, C as CachedAccount, B as BaseWallet, b as WalletConnectWallet, j as CachedWallet } from './types-0iDBydsK.mjs';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
|
|
5
5
|
type Storage = {
|
|
@@ -26,33 +26,6 @@ type SyncableStorage = Storage & {
|
|
|
26
26
|
*/
|
|
27
27
|
declare const getSafeLocalStorage: () => SyncableStorage;
|
|
28
28
|
|
|
29
|
-
/**
|
|
30
|
-
* Whether a cached account should survive SSR hydration, per its platform
|
|
31
|
-
* plugin's `acceptsCachedAccount` hook. Plugins without the hook (and platforms
|
|
32
|
-
* with no enabled plugin) accept all — matching the pre-plugin behavior where
|
|
33
|
-
* only Polkadot accounts were filtered (by key type).
|
|
34
|
-
*/
|
|
35
|
-
declare const acceptsCachedAccount: (cached: CachedAccount, platforms: readonly KheopskitPlatform[]) => boolean;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Converts a CachedWallet to a placeholder wallet for SSR hydration display.
|
|
39
|
-
*
|
|
40
|
-
* The placeholder carries only the SDK-free {@link BaseWallet} fields; the real
|
|
41
|
-
* wallet (with its injected provider/extension/standard-wallet handle) replaces
|
|
42
|
-
* it once it loads. connect/disconnect throw until then.
|
|
43
|
-
*/
|
|
44
|
-
declare const hydrateWallet: (cached: CachedWallet) => BaseWallet | WalletConnectWallet;
|
|
45
|
-
/**
|
|
46
|
-
* Converts a CachedAccount to a placeholder account for SSR hydration display.
|
|
47
|
-
*
|
|
48
|
-
* The placeholder carries the SDK-free {@link BaseWalletAccount} fields plus the
|
|
49
|
-
* plain, serializable platform data that lives in the cache — Ethereum `chainId`
|
|
50
|
-
* and the Polkadot key `type`. Those render immediately on reload (no blank →
|
|
51
|
-
* value flicker) and match what the live account will report. Only the SDK
|
|
52
|
-
* handles (`client`/`signer`/`polkadotSigner`) are absent until the real account
|
|
53
|
-
* replaces this placeholder; signing stays gated on `isHydrating` until then.
|
|
54
|
-
*/
|
|
55
|
-
declare const hydrateAccount: (cached: CachedAccount) => BaseWalletAccount;
|
|
56
29
|
/**
|
|
57
30
|
* Converts a wallet to a CachedWallet for storage.
|
|
58
31
|
* Only extracts the serializable properties needed for hydration.
|
|
@@ -66,12 +39,6 @@ declare const serializeWallet: (wallet: BaseWallet | WalletConnectWallet) => Cac
|
|
|
66
39
|
*/
|
|
67
40
|
declare const serializeAccount: (account: BaseWalletAccount) => CachedAccount;
|
|
68
41
|
|
|
69
|
-
/**
|
|
70
|
-
* Gets a cached icon for a wallet.
|
|
71
|
-
* @param walletId - The wallet ID (e.g., "ethereum:io.talisman")
|
|
72
|
-
* @returns The cached icon data URI, or undefined if not cached
|
|
73
|
-
*/
|
|
74
|
-
declare const getCachedIcon: (walletId: string) => string | undefined;
|
|
75
42
|
/**
|
|
76
43
|
* Sets multiple cached icons at once.
|
|
77
44
|
* More efficient than calling setCachedIcon multiple times.
|
|
@@ -79,8 +46,4 @@ declare const getCachedIcon: (walletId: string) => string | undefined;
|
|
|
79
46
|
*/
|
|
80
47
|
declare const setCachedIcons: (icons: Record<string, string>) => void;
|
|
81
48
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
declare const sortWallets: (w1: BaseWallet | WalletConnectWallet, w2: BaseWallet | WalletConnectWallet) => number;
|
|
85
|
-
|
|
86
|
-
export { acceptsCachedAccount, getCachedIcon, getSafeLocalStorage, hydrateAccount, hydrateWallet, serializeAccount, serializeWallet, setCachedIcons, sortAccounts, sortWallets };
|
|
49
|
+
export { getSafeLocalStorage, serializeAccount, serializeWallet, setCachedIcons };
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CachedAccount, K as KheopskitPlatform, h as BaseWalletAccount, j as CachedWallet, B as BaseWallet, b as WalletConnectWallet } from './types-C7V7DGlg.js';
|
|
2
1
|
export { a as clearCachedObservable, b as clearCachedObservablesByPrefix } from './getCachedObservable-C4E8dfMp.js';
|
|
2
|
+
import { f as BaseWalletAccount, C as CachedAccount, B as BaseWallet, b as WalletConnectWallet, j as CachedWallet } from './types-0iDBydsK.js';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
|
|
5
5
|
type Storage = {
|
|
@@ -26,33 +26,6 @@ type SyncableStorage = Storage & {
|
|
|
26
26
|
*/
|
|
27
27
|
declare const getSafeLocalStorage: () => SyncableStorage;
|
|
28
28
|
|
|
29
|
-
/**
|
|
30
|
-
* Whether a cached account should survive SSR hydration, per its platform
|
|
31
|
-
* plugin's `acceptsCachedAccount` hook. Plugins without the hook (and platforms
|
|
32
|
-
* with no enabled plugin) accept all — matching the pre-plugin behavior where
|
|
33
|
-
* only Polkadot accounts were filtered (by key type).
|
|
34
|
-
*/
|
|
35
|
-
declare const acceptsCachedAccount: (cached: CachedAccount, platforms: readonly KheopskitPlatform[]) => boolean;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Converts a CachedWallet to a placeholder wallet for SSR hydration display.
|
|
39
|
-
*
|
|
40
|
-
* The placeholder carries only the SDK-free {@link BaseWallet} fields; the real
|
|
41
|
-
* wallet (with its injected provider/extension/standard-wallet handle) replaces
|
|
42
|
-
* it once it loads. connect/disconnect throw until then.
|
|
43
|
-
*/
|
|
44
|
-
declare const hydrateWallet: (cached: CachedWallet) => BaseWallet | WalletConnectWallet;
|
|
45
|
-
/**
|
|
46
|
-
* Converts a CachedAccount to a placeholder account for SSR hydration display.
|
|
47
|
-
*
|
|
48
|
-
* The placeholder carries the SDK-free {@link BaseWalletAccount} fields plus the
|
|
49
|
-
* plain, serializable platform data that lives in the cache — Ethereum `chainId`
|
|
50
|
-
* and the Polkadot key `type`. Those render immediately on reload (no blank →
|
|
51
|
-
* value flicker) and match what the live account will report. Only the SDK
|
|
52
|
-
* handles (`client`/`signer`/`polkadotSigner`) are absent until the real account
|
|
53
|
-
* replaces this placeholder; signing stays gated on `isHydrating` until then.
|
|
54
|
-
*/
|
|
55
|
-
declare const hydrateAccount: (cached: CachedAccount) => BaseWalletAccount;
|
|
56
29
|
/**
|
|
57
30
|
* Converts a wallet to a CachedWallet for storage.
|
|
58
31
|
* Only extracts the serializable properties needed for hydration.
|
|
@@ -66,12 +39,6 @@ declare const serializeWallet: (wallet: BaseWallet | WalletConnectWallet) => Cac
|
|
|
66
39
|
*/
|
|
67
40
|
declare const serializeAccount: (account: BaseWalletAccount) => CachedAccount;
|
|
68
41
|
|
|
69
|
-
/**
|
|
70
|
-
* Gets a cached icon for a wallet.
|
|
71
|
-
* @param walletId - The wallet ID (e.g., "ethereum:io.talisman")
|
|
72
|
-
* @returns The cached icon data URI, or undefined if not cached
|
|
73
|
-
*/
|
|
74
|
-
declare const getCachedIcon: (walletId: string) => string | undefined;
|
|
75
42
|
/**
|
|
76
43
|
* Sets multiple cached icons at once.
|
|
77
44
|
* More efficient than calling setCachedIcon multiple times.
|
|
@@ -79,8 +46,4 @@ declare const getCachedIcon: (walletId: string) => string | undefined;
|
|
|
79
46
|
*/
|
|
80
47
|
declare const setCachedIcons: (icons: Record<string, string>) => void;
|
|
81
48
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
declare const sortWallets: (w1: BaseWallet | WalletConnectWallet, w2: BaseWallet | WalletConnectWallet) => number;
|
|
85
|
-
|
|
86
|
-
export { acceptsCachedAccount, getCachedIcon, getSafeLocalStorage, hydrateAccount, hydrateWallet, serializeAccount, serializeWallet, setCachedIcons, sortAccounts, sortWallets };
|
|
49
|
+
export { getSafeLocalStorage, serializeAccount, serializeWallet, setCachedIcons };
|
package/dist/internal.js
CHANGED
|
@@ -3,24 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _chunkB4L6GAYDjs = require('./chunk-B4L6GAYD.js');
|
|
6
|
+
var _chunkSO64R7Z6js = require('./chunk-SO64R7Z6.js');
|
|
12
7
|
require('./chunk-D3EQMFZ2.js');
|
|
13
8
|
|
|
14
9
|
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
var _chunk4ENHC7G4js = require('./chunk-4ENHC7G4.js');
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
var _chunkP7BPHHVVjs = require('./chunk-P7BPHHVV.js');
|
|
24
12
|
|
|
25
13
|
|
|
26
14
|
|
|
@@ -28,5 +16,5 @@ var _chunk4ENHC7G4js = require('./chunk-4ENHC7G4.js');
|
|
|
28
16
|
|
|
29
17
|
|
|
30
18
|
|
|
31
|
-
exports.
|
|
19
|
+
exports.clearCachedObservable = _chunkP7BPHHVVjs.clearCachedObservable; exports.clearCachedObservablesByPrefix = _chunkP7BPHHVVjs.clearCachedObservablesByPrefix; exports.getSafeLocalStorage = _chunkSO64R7Z6js.getSafeLocalStorage; exports.serializeAccount = _chunkSO64R7Z6js.serializeAccount; exports.serializeWallet = _chunkSO64R7Z6js.serializeWallet; exports.setCachedIcons = _chunkSO64R7Z6js.setCachedIcons;
|
|
32
20
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kheopskit/kheopskit/packages/core/dist/internal.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kheopskit/kheopskit/packages/core/dist/internal.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,yZAAC","file":"/home/runner/work/kheopskit/kheopskit/packages/core/dist/internal.js"}
|
package/dist/internal.mjs
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
getCachedIcon,
|
|
4
|
-
hydrateAccount,
|
|
5
|
-
hydrateWallet,
|
|
2
|
+
getSafeLocalStorage,
|
|
6
3
|
serializeAccount,
|
|
7
4
|
serializeWallet,
|
|
8
|
-
setCachedIcons
|
|
9
|
-
|
|
10
|
-
sortWallets
|
|
11
|
-
} from "./chunk-YDLCHYHH.mjs";
|
|
5
|
+
setCachedIcons
|
|
6
|
+
} from "./chunk-3Y5N4N3Q.mjs";
|
|
12
7
|
import "./chunk-BWUUHUDK.mjs";
|
|
13
8
|
import {
|
|
14
9
|
clearCachedObservable,
|
|
15
|
-
clearCachedObservablesByPrefix
|
|
16
|
-
|
|
17
|
-
} from "./chunk-7QSGAJ4A.mjs";
|
|
10
|
+
clearCachedObservablesByPrefix
|
|
11
|
+
} from "./chunk-WOPCW2OX.mjs";
|
|
18
12
|
export {
|
|
19
|
-
acceptsCachedAccount,
|
|
20
13
|
clearCachedObservable,
|
|
21
14
|
clearCachedObservablesByPrefix,
|
|
22
|
-
getCachedIcon,
|
|
23
15
|
getSafeLocalStorage,
|
|
24
|
-
hydrateAccount,
|
|
25
|
-
hydrateWallet,
|
|
26
16
|
serializeAccount,
|
|
27
17
|
serializeWallet,
|
|
28
|
-
setCachedIcons
|
|
29
|
-
sortAccounts,
|
|
30
|
-
sortWallets
|
|
18
|
+
setCachedIcons
|
|
31
19
|
};
|
|
32
20
|
//# sourceMappingURL=internal.mjs.map
|
package/dist/polkadot.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as WalletConnectWallet, i as isInjectedWallet, c as isWalletConnectWallet } from './types-
|
|
1
|
+
import { l as PolkadotAccountType, W as WalletAccountId, a as WalletId, K as KheopskitPlatform } from './types-0iDBydsK.mjs';
|
|
2
|
+
export { b as WalletConnectWallet, i as isInjectedWallet, c as isWalletConnectWallet } from './types-0iDBydsK.mjs';
|
|
3
3
|
import { InjectedPolkadotAccount, InjectedExtension } from 'polkadot-api/pjs-signer';
|
|
4
4
|
import 'rxjs';
|
|
5
5
|
|
package/dist/polkadot.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as WalletConnectWallet, i as isInjectedWallet, c as isWalletConnectWallet } from './types-
|
|
1
|
+
import { l as PolkadotAccountType, W as WalletAccountId, a as WalletId, K as KheopskitPlatform } from './types-0iDBydsK.js';
|
|
2
|
+
export { b as WalletConnectWallet, i as isInjectedWallet, c as isWalletConnectWallet } from './types-0iDBydsK.js';
|
|
3
3
|
import { InjectedPolkadotAccount, InjectedExtension } from 'polkadot-api/pjs-signer';
|
|
4
4
|
import 'rxjs';
|
|
5
5
|
|