@kheopskit/core 6.0.2 → 6.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/WalletAccountId-6ZXQM_ed.mjs +116 -0
  3. package/dist/WalletAccountId-6ZXQM_ed.mjs.map +1 -0
  4. package/dist/WalletAccountId-D8Xc13VY.js +151 -0
  5. package/dist/WalletAccountId-D8Xc13VY.js.map +1 -0
  6. package/dist/{config-Bb-Zz8J1.d.ts → config-CubhhFON.d.ts} +2 -2
  7. package/dist/{config-C-Xk2AP_.d.mts → config-rvX2pkqc.d.mts} +2 -2
  8. package/dist/ethereum.d.mts +1 -1
  9. package/dist/ethereum.d.ts +1 -1
  10. package/dist/ethereum.js +11 -11
  11. package/dist/ethereum.js.map +1 -1
  12. package/dist/ethereum.mjs +2 -2
  13. package/dist/index.d.mts +3 -3
  14. package/dist/index.d.ts +3 -3
  15. package/dist/index.js +12 -12
  16. package/dist/index.mjs +3 -3
  17. package/dist/{instance-BJVnjk4r.mjs → instance-0-PWH43j.mjs} +3 -3
  18. package/dist/{instance-BJVnjk4r.mjs.map → instance-0-PWH43j.mjs.map} +1 -1
  19. package/dist/{instance-1BgEld17.d.ts → instance-BokWUMmA.d.ts} +2 -2
  20. package/dist/{instance-aPJrTyvW.js → instance-CegD47uC.js} +25 -25
  21. package/dist/{instance-aPJrTyvW.js.map → instance-CegD47uC.js.map} +1 -1
  22. package/dist/{instance-DDvZiq1L.d.mts → instance-DoOr7mrc.d.mts} +2 -2
  23. package/dist/internal.d.mts +2 -2
  24. package/dist/internal.d.ts +2 -2
  25. package/dist/internal.js +4 -4
  26. package/dist/internal.mjs +2 -2
  27. package/dist/{platformAccounts-CqMSpl3X.js → platformAccounts-D8XmOSvD.js} +133 -115
  28. package/dist/platformAccounts-D8XmOSvD.js.map +1 -0
  29. package/dist/{platformAccounts-C1sFv82e.mjs → platformAccounts-sy621l8C.mjs} +87 -99
  30. package/dist/{types-DaRMgleZ.js.map → platformAccounts-sy621l8C.mjs.map} +1 -1
  31. package/dist/polkadot.d.mts +1 -1
  32. package/dist/polkadot.d.ts +1 -1
  33. package/dist/polkadot.js +15 -13
  34. package/dist/polkadot.js.map +1 -1
  35. package/dist/polkadot.mjs +7 -5
  36. package/dist/polkadot.mjs.map +1 -1
  37. package/dist/solana.d.mts +1 -1
  38. package/dist/solana.d.ts +1 -1
  39. package/dist/solana.js +10 -10
  40. package/dist/solana.js.map +1 -1
  41. package/dist/solana.mjs +2 -2
  42. package/dist/testing.d.mts +2 -2
  43. package/dist/testing.d.ts +2 -2
  44. package/dist/{types-BGeGUtxz.d.mts → types-BfIzw1fd.d.mts} +8 -1
  45. package/dist/{types-BGeGUtxz.d.ts → types-BfIzw1fd.d.ts} +8 -1
  46. package/dist/walletconnect.d.mts +1 -1
  47. package/dist/walletconnect.d.ts +1 -1
  48. package/dist/walletconnect.js +20 -17
  49. package/dist/walletconnect.js.map +1 -1
  50. package/dist/walletconnect.mjs +17 -14
  51. package/dist/walletconnect.mjs.map +1 -1
  52. package/package.json +1 -1
  53. package/dist/platformAccounts-C1sFv82e.mjs.map +0 -1
  54. package/dist/platformAccounts-CqMSpl3X.js.map +0 -1
  55. package/dist/types-DaRMgleZ.js +0 -169
  56. package/dist/types-DcpmEGhO.mjs +0 -104
  57. package/dist/types-DcpmEGhO.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_types = require("./types-DaRMgleZ.js");
2
+ const require_platformAccounts = require("./platformAccounts-D8XmOSvD.js");
3
3
  const require_errors = require("./errors-B6Z21vkI.js");
4
4
  let rxjs = require("rxjs");
5
5
  //#region src/api/walletconnect/plugin.ts
@@ -39,7 +39,7 @@ const resetAppKitCache = () => {
39
39
  * this wallet and avoids matching a sibling whose id is a string prefix.
40
40
  */
41
41
  const dropAccountsCache = (platform) => {
42
- require_types.clearCachedObservablesByPrefix(`accounts:${require_types.WALLET_CONNECT_WALLET_ID}:${platform}:`);
42
+ require_platformAccounts.clearCachedObservablesByPrefix(`accounts:${require_platformAccounts.WALLET_CONNECT_WALLET_ID}:${platform}:`);
43
43
  };
44
44
  const namespaceOf = {
45
45
  polkadot: "polkadot",
@@ -72,12 +72,17 @@ const createConnector$ = (appKit) => {
72
72
  opening: false,
73
73
  error: void 0
74
74
  });
75
- const syncProviders = (providers) => {
75
+ const liveSession = (platform) => {
76
+ const namespace = namespaceOf[platform];
77
+ const session = appKit.getProvider(namespace)?.session;
78
+ return session && require_platformAccounts.getSessionCaip10s(session, namespace).length > 0 ? session : void 0;
79
+ };
80
+ const syncProviders = () => {
76
81
  status$.next({
77
82
  ...status$.value,
78
- isPolkadotConnected: !!providers.polkadot,
79
- isEthereumConnected: !!providers.eip155,
80
- isSolanaConnected: !!providers.solana
83
+ isPolkadotConnected: !!liveSession("polkadot"),
84
+ isEthereumConnected: !!liveSession("ethereum"),
85
+ isSolanaConnected: !!liveSession("solana")
81
86
  });
82
87
  };
83
88
  const openModal = async () => {
@@ -89,7 +94,7 @@ const createConnector$ = (appKit) => {
89
94
  try {
90
95
  await appKit.open();
91
96
  } catch (cause) {
92
- const error = require_errors.toConnectError(cause, require_types.WALLET_CONNECT_WALLET_ID, () => false);
97
+ const error = require_errors.toConnectError(cause, require_platformAccounts.WALLET_CONNECT_WALLET_ID, () => false);
93
98
  status$.next({
94
99
  ...status$.value,
95
100
  opening: false,
@@ -120,14 +125,14 @@ const createConnector$ = (appKit) => {
120
125
  }), (0, rxjs.map)(({ opening, error, ...connected }) => {
121
126
  const platforms = enabledPlatforms.filter((p) => connected[p]);
122
127
  const isConnected = platforms.length > 0;
123
- const walletInfo = appKit.getWalletInfo();
128
+ const peer = platforms[0] && liveSession(platforms[0])?.peer?.metadata;
124
129
  return {
125
- id: require_types.WALLET_CONNECT_WALLET_ID,
130
+ id: require_platformAccounts.WALLET_CONNECT_WALLET_ID,
126
131
  type: "walletconnect",
127
132
  platforms,
128
133
  appKit: appKitInstance,
129
- name: walletInfo?.name ?? "WalletConnect",
130
- icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
134
+ name: peer?.name || "WalletConnect",
135
+ icon: peer?.icons?.[0] || WALLET_CONNECT_ICON,
131
136
  connect: async () => {
132
137
  if (!isConnected) await openModal();
133
138
  },
@@ -141,15 +146,13 @@ const createConnector$ = (appKit) => {
141
146
  }));
142
147
  return new rxjs.Observable((subscriber) => {
143
148
  for (const platform of allPlatforms) dropAccountsCache(platform);
144
- syncProviders({
145
- polkadot: appKit.getProvider("polkadot"),
146
- eip155: appKit.getProvider("eip155"),
147
- solana: appKit.getProvider("solana")
148
- });
149
+ syncProviders();
149
150
  const unsubProviders = appKit.subscribeProviders(syncProviders);
151
+ const sessionSub = (0, rxjs.from)(appKit.getUniversalProvider()).pipe((0, rxjs.catchError)(() => rxjs.EMPTY), (0, rxjs.switchMap)((provider) => provider ? (0, rxjs.merge)((0, rxjs.fromEvent)(provider, "session_delete"), (0, rxjs.fromEvent)(provider, "connect"), (0, rxjs.of)(void 0)) : rxjs.EMPTY)).subscribe(syncProviders);
150
152
  const sub = wallet$.subscribe(subscriber);
151
153
  return () => {
152
154
  sub.unsubscribe();
155
+ sessionSub.unsubscribe();
153
156
  unsubProviders();
154
157
  };
155
158
  });
@@ -219,7 +222,7 @@ const walletConnect = (options) => ({
219
222
  getWallet$: ({ config }) => getWalletConnectWallet$(options, config.debug)
220
223
  });
221
224
  //#endregion
222
- exports.isWalletConnectWallet = require_types.isWalletConnectWallet;
225
+ exports.isWalletConnectWallet = require_platformAccounts.isWalletConnectWallet;
223
226
  exports.resetAppKitCache = resetAppKitCache;
224
227
  exports.walletConnect = walletConnect;
225
228
 
@@ -1 +1 @@
1
- {"version":3,"file":"walletconnect.js","names":["WALLET_CONNECT_WALLET_ID","BehaviorSubject","toConnectError","map","distinctUntilChanged","tap","Observable","of","from","shareReplay","switchMap"],"sources":["../src/api/walletconnect/plugin.ts"],"sourcesContent":["import type { AppKit } from \"@reown/appkit/core\";\nimport {\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 KheopskitError, toConnectError } from \"../errors\";\nimport type {\n\tAppKitInstance,\n\tWalletConnectMetadata,\n\tWalletConnectPlugin,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"../types\";\n\nexport type WalletConnectOptions = {\n\tprojectId: string;\n\tmetadata: WalletConnectMetadata;\n\t/**\n\t * Networks AppKit should enable. Pass `AppKitNetwork[]` from\n\t * `@reown/appkit/networks` (see\n\t * https://docs.reown.com/advanced/multichain/polkadot/dapp-integration-guide#walletconnect-code%2Fcomponent-setup).\n\t * Loosely typed (`unknown`) so the declarations don't depend on\n\t * `@reown/appkit`'s types; the value is forwarded to AppKit as-is.\n\t */\n\tnetworks: [unknown, ...unknown[]];\n\tthemeMode?: \"light\" | \"dark\";\n\tthemeVariables?: Record<string, string | number>;\n\t/**\n\t * Extra Reown AppKit `createAppKit` options (e.g. `featuredWalletIds`,\n\t * `features`, `allWallets`), forwarded as-is; see\n\t * https://docs.reown.com/appkit/javascript/core/options.\n\t * kheopskit sets `projectId`, `metadata`, `networks`, `themeMode`,\n\t * `themeVariables` and `universalProviderConfigOverride` itself, so those\n\t * keys are rejected here.\n\t */\n\tappKitOptions?: AppKitOptions;\n};\n\ntype KheopskitOwnedAppKitKey =\n\t| \"projectId\"\n\t| \"metadata\"\n\t| \"networks\"\n\t| \"themeMode\"\n\t| \"themeVariables\"\n\t| \"universalProviderConfigOverride\";\n\ntype AppKitOptions = Record<string, unknown> &\n\tPartial<Record<KheopskitOwnedAppKitKey, never>>;\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 * 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\nconst namespaceOf: Record<WalletPlatform, string> = {\n\tpolkadot: \"polkadot\",\n\tethereum: \"eip155\",\n\tsolana: \"solana\",\n};\nconst allPlatforms: WalletPlatform[] = [\"polkadot\", \"ethereum\", \"solana\"];\n\nconst methodsByNamespace: Record<string, string[]> = {\n\tpolkadot: [\"polkadot_signTransaction\", \"polkadot_signMessage\"],\n\tsolana: [\n\t\t\"solana_signTransaction\",\n\t\t\"solana_signMessage\",\n\t\t\"solana_signAndSendTransaction\",\n\t],\n};\n\n// AppKit turns every overridden namespace into a pairing request, and rejects\n// the pairing when one of them has no chains.\nconst methodsFor = (networks: unknown[]): Record<string, string[]> => {\n\tconst namespaces = new Set(\n\t\tnetworks.map(\n\t\t\t(network) => (network as { chainNamespace?: string }).chainNamespace,\n\t\t),\n\t);\n\treturn Object.fromEntries(\n\t\tObject.entries(methodsByNamespace).filter(([namespace]) =>\n\t\t\tnamespaces.has(namespace),\n\t\t),\n\t);\n};\n\nconst createConnector$ = (appKit: AppKit): Observable<WalletConnectWallet> => {\n\t// Exposed on the wallet as the (decoupled) AppKitInstance escape hatch.\n\tconst appKitInstance = appKit as unknown as AppKitInstance;\n\n\tconst status$ = new BehaviorSubject<{\n\t\tisPolkadotConnected: boolean;\n\t\tisEthereumConnected: boolean;\n\t\tisSolanaConnected: boolean;\n\t\topening: boolean;\n\t\terror: KheopskitError | undefined;\n\t}>({\n\t\tisPolkadotConnected: false,\n\t\tisEthereumConnected: false,\n\t\tisSolanaConnected: false,\n\t\topening: false,\n\t\terror: undefined,\n\t});\n\n\tconst syncProviders = (providers: Partial<Record<string, unknown>>) => {\n\t\tstatus$.next({\n\t\t\t...status$.value,\n\t\t\tisPolkadotConnected: !!providers.polkadot,\n\t\t\tisEthereumConnected: !!providers.eip155,\n\t\t\tisSolanaConnected: !!providers.solana,\n\t\t});\n\t};\n\n\tconst openModal = async () => {\n\t\tstatus$.next({ ...status$.value, opening: true, error: undefined });\n\t\ttry {\n\t\t\tawait appKit.open();\n\t\t} catch (cause) {\n\t\t\tconst error = toConnectError(\n\t\t\t\tcause,\n\t\t\t\tWALLET_CONNECT_WALLET_ID,\n\t\t\t\t() => false,\n\t\t\t);\n\t\t\tstatus$.next({ ...status$.value, opening: false, error });\n\t\t\tthrow error;\n\t\t}\n\t\tstatus$.next({ ...status$.value, opening: false });\n\t};\n\n\tconst enabledPlatforms = allPlatforms.filter((p) =>\n\t\t(appKit.chainNamespaces as string[]).includes(namespaceOf[p]),\n\t);\n\n\tlet prevConnected = {\n\t\tpolkadot: false,\n\t\tethereum: false,\n\t\tsolana: false,\n\t};\n\n\tconst wallet$ = status$.pipe(\n\t\tmap((s) => ({\n\t\t\tpolkadot: s.isPolkadotConnected,\n\t\t\tethereum: s.isEthereumConnected,\n\t\t\tsolana: s.isSolanaConnected,\n\t\t\topening: s.opening,\n\t\t\terror: s.error,\n\t\t})),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) =>\n\t\t\t\ta.polkadot === b.polkadot &&\n\t\t\t\ta.ethereum === b.ethereum &&\n\t\t\t\ta.solana === b.solana &&\n\t\t\t\ta.opening === b.opening &&\n\t\t\t\ta.error === b.error,\n\t\t),\n\t\ttap((connected) => {\n\t\t\t// Drop caches for namespaces that just went disconnected.\n\t\t\tfor (const platform of allPlatforms)\n\t\t\t\tif (prevConnected[platform] && !connected[platform])\n\t\t\t\t\tdropAccountsCache(platform);\n\t\t\tprevConnected = connected;\n\t\t}),\n\t\tmap(({ opening, error, ...connected }): WalletConnectWallet => {\n\t\t\tconst platforms = enabledPlatforms.filter((p) => connected[p]);\n\t\t\tconst isConnected = platforms.length > 0;\n\t\t\tconst walletInfo = appKit.getWalletInfo();\n\t\t\treturn {\n\t\t\t\tid: WALLET_CONNECT_WALLET_ID,\n\t\t\t\ttype: \"walletconnect\",\n\t\t\t\tplatforms,\n\t\t\t\tappKit: appKitInstance,\n\t\t\t\tname: walletInfo?.name ?? \"WalletConnect\",\n\t\t\t\ticon: walletInfo?.icon ?? WALLET_CONNECT_ICON,\n\t\t\t\t// One shared session: connecting opens the modal; the wallet\n\t\t\t\t// approves namespaces in that single pairing. Disconnect is\n\t\t\t\t// session-wide; re-pair to change the approved set.\n\t\t\t\tconnect: async () => {\n\t\t\t\t\tif (!isConnected) await openModal();\n\t\t\t\t},\n\t\t\t\tdisconnect: async () => {\n\t\t\t\t\tif (isConnected) await appKit.disconnect();\n\t\t\t\t},\n\t\t\t\tstatus: isConnected\n\t\t\t\t\t? \"connected\"\n\t\t\t\t\t: opening\n\t\t\t\t\t\t? \"connecting\"\n\t\t\t\t\t\t: \"disconnected\",\n\t\t\t\terror,\n\t\t\t\tisConnected,\n\t\t\t};\n\t\t}),\n\t);\n\n\treturn new Observable<WalletConnectWallet>((subscriber) => {\n\t\tfor (const platform of allPlatforms) dropAccountsCache(platform);\n\t\t// AppKit's subscribeProviders only reports later changes, so read the\n\t\t// state that may have changed while nobody observed.\n\t\tsyncProviders({\n\t\t\tpolkadot: appKit.getProvider(\"polkadot\"),\n\t\t\teip155: appKit.getProvider(\"eip155\"),\n\t\t\tsolana: appKit.getProvider(\"solana\"),\n\t\t});\n\t\tconst unsubProviders = appKit.subscribeProviders(syncProviders);\n\t\tconst sub = wallet$.subscribe(subscriber);\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t\tunsubProviders();\n\t\t};\n\t});\n};\n\n/**\n * @remarks\n * The AppKit instance is a process-wide singleton: a second instance would\n * share AppKit's module-level controller state with the first, so it is\n * created once. 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 */\nconst getWalletConnectWallet$ = (\n\twalletConnect: WalletConnectOptions,\n\tdebug: boolean,\n): Observable<WalletConnectWallet | null> => {\n\t// SSR guard - don't try to load AppKit on the server\n\tif (typeof window === \"undefined\") return of(null);\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\tconst connectorOnce$ = from(loadAppKit()).pipe(\n\t\t\tmap((createAppKit) =>\n\t\t\t\t// @reown/appkit missing (optional peer dep) — degrade gracefully.\n\t\t\t\tcreateAppKit\n\t\t\t\t\t? createConnector$(\n\t\t\t\t\t\t\tcreateAppKit({\n\t\t\t\t\t\t\t\tallWallets: \"HIDE\",\n\t\t\t\t\t\t\t\tdebug,\n\t\t\t\t\t\t\t\tallowUnsupportedChain: true,\n\t\t\t\t\t\t\t\t...walletConnect.appKitOptions,\n\t\t\t\t\t\t\t\tprojectId: walletConnect.projectId,\n\t\t\t\t\t\t\t\tmetadata: walletConnect.metadata,\n\t\t\t\t\t\t\t\tnetworks: walletConnect.networks as never,\n\t\t\t\t\t\t\t\tthemeMode: walletConnect.themeMode,\n\t\t\t\t\t\t\t\tthemeVariables: walletConnect.themeVariables as never,\n\t\t\t\t\t\t\t\tuniversalProviderConfigOverride: {\n\t\t\t\t\t\t\t\t\tmethods: methodsFor(walletConnect.networks),\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: null,\n\t\t\t),\n\t\t\tshareReplay({ refCount: false, bufferSize: 1 }),\n\t\t);\n\t\tcachedAppKit = connectorOnce$.pipe(\n\t\t\tswitchMap((wallet$) => wallet$ ?? of(null)),\n\t\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t\t);\n\t\tsetCachedAppKit(cachedAppKit, walletConnect.projectId);\n\t}\n\n\treturn cachedAppKit;\n};\n\n/**\n * The WalletConnect plugin for `config.walletConnect`. Importing this entry is\n * what brings Reown AppKit into a dapp's bundle; a dapp that never imports it\n * ships none of it.\n *\n * @example\n * ```ts\n * import { walletConnect } from \"@kheopskit/core/walletconnect\";\n *\n * createKheopskit({\n * platforms: [polkadot()],\n * walletConnect: walletConnect({ projectId, metadata, networks }),\n * });\n * ```\n */\nexport const walletConnect = (\n\toptions: WalletConnectOptions,\n): WalletConnectPlugin => ({\n\ttype: \"walletconnect\",\n\tmetadata: options.metadata,\n\tgetWallet$: ({ config }) => getWalletConnectWallet$(options, config.debug),\n});\n"],"mappings":";;;;;;;;;;AA+DA,MAAM,aAAa,YAAY;CAC9B,IAAI;EACH,MAAM,EAAE,iBAAiB,MAAM,OAAO;EACtC,OAAO;CACR,SAAS,OAAO;EACf,QAAQ,MACP,8NAGA,KACD;EACA,OAAO;CACR;AACD;AAEA,MAAM,sBACL;AAKD,MAAM,gBAAgB,OAAO,IAAI,wBAAwB;AAIzD,MAAM,2BAA2B,OAAO,IAAI,iCAAiC;AAK7E,MAAM,wBAGJ,WAAuC;AAGzC,MAAM,iCACJ,WAAuC;AAGzC,MAAM,mBACL,OACA,cACU;CACV,WAAwC,iBAAiB;CACzD,WAAwC,4BAA4B;AACrE;;;;;;AAOA,MAAa,yBAA+B;CAC3C,gBAAgB,KAAA,CAAS;AAC1B;;;;;AAMA,MAAM,qBAAqB,aAAmC;CAC7D,cAAA,+BACC,YAAYA,cAAAA,yBAAyB,GAAG,SAAS,EAClD;AACD;AAEA,MAAM,cAA8C;CACnD,UAAU;CACV,UAAU;CACV,QAAQ;AACT;AACA,MAAM,eAAiC;CAAC;CAAY;CAAY;AAAQ;AAExE,MAAM,qBAA+C;CACpD,UAAU,CAAC,4BAA4B,sBAAsB;CAC7D,QAAQ;EACP;EACA;EACA;CACD;AACD;AAIA,MAAM,cAAc,aAAkD;CACrE,MAAM,aAAa,IAAI,IACtB,SAAS,KACP,YAAa,QAAwC,cACvD,CACD;CACA,OAAO,OAAO,YACb,OAAO,QAAQ,kBAAkB,CAAC,CAAC,QAAQ,CAAC,eAC3C,WAAW,IAAI,SAAS,CACzB,CACD;AACD;AAEA,MAAM,oBAAoB,WAAoD;CAE7E,MAAM,iBAAiB;CAEvB,MAAM,UAAU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,IAAAA,EAAK,iBAEJ,eACG,iBACA,aAAa;GACZ,YAAY;GACZ;GACA,uBAAuB;GACvB,GAAG,cAAc;GACjB,WAAW,cAAc;GACzB,UAAU,cAAc;GACxB,UAAU,cAAc;GACxB,WAAW,cAAc;GACzB,gBAAgB,cAAc;GAC9B,iCAAiC,EAChC,SAAS,WAAW,cAAc,QAAQ,EAC3C;EACD,CAAC,CACF,IACC,IACJ,IAAA,GACAM,KAAAA,YAAAA,CAAY;GAAE,UAAU;GAAO,YAAY;EAAE,CAAC,CAEnB,CAAC,CAAC,MAAA,GAC7BC,KAAAA,UAAAA,EAAW,YAAY,YAAA,GAAWH,KAAAA,GAAAA,CAAG,IAAI,CAAC,IAAA,GAC1CE,KAAAA,YAAAA,CAAY;GAAE,UAAU;GAAM,YAAY;EAAE,CAAC,CAC9C;EACA,gBAAgB,cAAc,cAAc,SAAS;CACtD;CAEA,OAAO;AACR;;;;;;;;;;;;;;;;AAiBA,MAAa,iBACZ,aAC0B;CAC1B,MAAM;CACN,UAAU,QAAQ;CAClB,aAAa,EAAE,aAAa,wBAAwB,SAAS,OAAO,KAAK;AAC1E"}
1
+ {"version":3,"file":"walletconnect.js","names":["WALLET_CONNECT_WALLET_ID","BehaviorSubject","getSessionCaip10s","toConnectError","map","distinctUntilChanged","tap","Observable","from","catchError","EMPTY","switchMap","merge","fromEvent","of","shareReplay"],"sources":["../src/api/walletconnect/plugin.ts"],"sourcesContent":["import type { AppKit } from \"@reown/appkit/core\";\nimport {\n\tBehaviorSubject,\n\tcatchError,\n\tdistinctUntilChanged,\n\tEMPTY,\n\tfrom,\n\tfromEvent,\n\tmap,\n\tmerge,\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 KheopskitError, toConnectError } from \"../errors\";\nimport { getSessionCaip10s } from \"../platformAccounts\";\nimport type {\n\tAppKitInstance,\n\tWalletConnectMetadata,\n\tWalletConnectPlugin,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"../types\";\n\nexport type WalletConnectOptions = {\n\tprojectId: string;\n\tmetadata: WalletConnectMetadata;\n\t/**\n\t * Networks AppKit should enable. Pass `AppKitNetwork[]` from\n\t * `@reown/appkit/networks` (see\n\t * https://docs.reown.com/advanced/multichain/polkadot/dapp-integration-guide#walletconnect-code%2Fcomponent-setup).\n\t * Loosely typed (`unknown`) so the declarations don't depend on\n\t * `@reown/appkit`'s types; the value is forwarded to AppKit as-is.\n\t */\n\tnetworks: [unknown, ...unknown[]];\n\tthemeMode?: \"light\" | \"dark\";\n\tthemeVariables?: Record<string, string | number>;\n\t/**\n\t * Extra Reown AppKit `createAppKit` options (e.g. `featuredWalletIds`,\n\t * `features`, `allWallets`), forwarded as-is; see\n\t * https://docs.reown.com/appkit/javascript/core/options.\n\t * kheopskit sets `projectId`, `metadata`, `networks`, `themeMode`,\n\t * `themeVariables` and `universalProviderConfigOverride` itself, so those\n\t * keys are rejected here.\n\t */\n\tappKitOptions?: AppKitOptions;\n};\n\ntype KheopskitOwnedAppKitKey =\n\t| \"projectId\"\n\t| \"metadata\"\n\t| \"networks\"\n\t| \"themeMode\"\n\t| \"themeVariables\"\n\t| \"universalProviderConfigOverride\";\n\ntype AppKitOptions = Record<string, unknown> &\n\tPartial<Record<KheopskitOwnedAppKitKey, never>>;\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 * 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\nconst namespaceOf = {\n\tpolkadot: \"polkadot\",\n\tethereum: \"eip155\",\n\tsolana: \"solana\",\n} as const satisfies Record<WalletPlatform, string>;\nconst allPlatforms: WalletPlatform[] = [\"polkadot\", \"ethereum\", \"solana\"];\n\nconst methodsByNamespace: Record<string, string[]> = {\n\tpolkadot: [\"polkadot_signTransaction\", \"polkadot_signMessage\"],\n\tsolana: [\n\t\t\"solana_signTransaction\",\n\t\t\"solana_signMessage\",\n\t\t\"solana_signAndSendTransaction\",\n\t],\n};\n\n// AppKit turns every overridden namespace into a pairing request, and rejects\n// the pairing when one of them has no chains.\nconst methodsFor = (networks: unknown[]): Record<string, string[]> => {\n\tconst namespaces = new Set(\n\t\tnetworks.map(\n\t\t\t(network) => (network as { chainNamespace?: string }).chainNamespace,\n\t\t),\n\t);\n\treturn Object.fromEntries(\n\t\tObject.entries(methodsByNamespace).filter(([namespace]) =>\n\t\t\tnamespaces.has(namespace),\n\t\t),\n\t);\n};\n\nconst createConnector$ = (appKit: AppKit): Observable<WalletConnectWallet> => {\n\t// Exposed on the wallet as the (decoupled) AppKitInstance escape hatch.\n\tconst appKitInstance = appKit as unknown as AppKitInstance;\n\n\tconst status$ = new BehaviorSubject<{\n\t\tisPolkadotConnected: boolean;\n\t\tisEthereumConnected: boolean;\n\t\tisSolanaConnected: boolean;\n\t\topening: boolean;\n\t\terror: KheopskitError | undefined;\n\t}>({\n\t\tisPolkadotConnected: false,\n\t\tisEthereumConnected: false,\n\t\tisSolanaConnected: false,\n\t\topening: false,\n\t\terror: undefined,\n\t});\n\n\tconst liveSession = (platform: WalletPlatform) => {\n\t\tconst namespace = namespaceOf[platform];\n\t\tconst session =\n\t\t\tappKit.getProvider<WalletConnectProvider>(namespace)?.session;\n\t\treturn session && getSessionCaip10s(session, namespace).length > 0\n\t\t\t? session\n\t\t\t: undefined;\n\t};\n\n\tconst syncProviders = () => {\n\t\tstatus$.next({\n\t\t\t...status$.value,\n\t\t\tisPolkadotConnected: !!liveSession(\"polkadot\"),\n\t\t\tisEthereumConnected: !!liveSession(\"ethereum\"),\n\t\t\tisSolanaConnected: !!liveSession(\"solana\"),\n\t\t});\n\t};\n\n\tconst openModal = async () => {\n\t\tstatus$.next({ ...status$.value, opening: true, error: undefined });\n\t\ttry {\n\t\t\tawait appKit.open();\n\t\t} catch (cause) {\n\t\t\tconst error = toConnectError(\n\t\t\t\tcause,\n\t\t\t\tWALLET_CONNECT_WALLET_ID,\n\t\t\t\t() => false,\n\t\t\t);\n\t\t\tstatus$.next({ ...status$.value, opening: false, error });\n\t\t\tthrow error;\n\t\t}\n\t\tstatus$.next({ ...status$.value, opening: false });\n\t};\n\n\tconst enabledPlatforms = allPlatforms.filter((p) =>\n\t\t(appKit.chainNamespaces as string[]).includes(namespaceOf[p]),\n\t);\n\n\tlet prevConnected = {\n\t\tpolkadot: false,\n\t\tethereum: false,\n\t\tsolana: false,\n\t};\n\n\tconst wallet$ = status$.pipe(\n\t\tmap((s) => ({\n\t\t\tpolkadot: s.isPolkadotConnected,\n\t\t\tethereum: s.isEthereumConnected,\n\t\t\tsolana: s.isSolanaConnected,\n\t\t\topening: s.opening,\n\t\t\terror: s.error,\n\t\t})),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) =>\n\t\t\t\ta.polkadot === b.polkadot &&\n\t\t\t\ta.ethereum === b.ethereum &&\n\t\t\t\ta.solana === b.solana &&\n\t\t\t\ta.opening === b.opening &&\n\t\t\t\ta.error === b.error,\n\t\t),\n\t\ttap((connected) => {\n\t\t\t// Drop caches for namespaces that just went disconnected.\n\t\t\tfor (const platform of allPlatforms)\n\t\t\t\tif (prevConnected[platform] && !connected[platform])\n\t\t\t\t\tdropAccountsCache(platform);\n\t\t\tprevConnected = connected;\n\t\t}),\n\t\tmap(({ opening, error, ...connected }): WalletConnectWallet => {\n\t\t\tconst platforms = enabledPlatforms.filter((p) => connected[p]);\n\t\t\tconst isConnected = platforms.length > 0;\n\t\t\tconst peer = platforms[0] && liveSession(platforms[0])?.peer?.metadata;\n\t\t\treturn {\n\t\t\t\tid: WALLET_CONNECT_WALLET_ID,\n\t\t\t\ttype: \"walletconnect\",\n\t\t\t\tplatforms,\n\t\t\t\tappKit: appKitInstance,\n\t\t\t\tname: peer?.name || \"WalletConnect\",\n\t\t\t\ticon: peer?.icons?.[0] || WALLET_CONNECT_ICON,\n\t\t\t\t// One shared session: connecting opens the modal; the wallet\n\t\t\t\t// approves namespaces in that single pairing. Disconnect is\n\t\t\t\t// session-wide; re-pair to change the approved set.\n\t\t\t\tconnect: async () => {\n\t\t\t\t\tif (!isConnected) await openModal();\n\t\t\t\t},\n\t\t\t\tdisconnect: async () => {\n\t\t\t\t\tif (isConnected) await appKit.disconnect();\n\t\t\t\t},\n\t\t\t\tstatus: isConnected\n\t\t\t\t\t? \"connected\"\n\t\t\t\t\t: opening\n\t\t\t\t\t\t? \"connecting\"\n\t\t\t\t\t\t: \"disconnected\",\n\t\t\t\terror,\n\t\t\t\tisConnected,\n\t\t\t};\n\t\t}),\n\t);\n\n\treturn new Observable<WalletConnectWallet>((subscriber) => {\n\t\tfor (const platform of allPlatforms) dropAccountsCache(platform);\n\t\t// AppKit's subscribeProviders only reports later changes, so read the\n\t\t// state that may have changed while nobody observed.\n\t\tsyncProviders();\n\t\tconst unsubProviders = appKit.subscribeProviders(syncProviders);\n\t\t// AppKit keeps a namespace's provider registered when the wallet ends the\n\t\t// session, and registers that same object again on the next pairing, so\n\t\t// subscribeProviders reports neither.\n\t\tconst sessionSub = from(appKit.getUniversalProvider())\n\t\t\t.pipe(\n\t\t\t\tcatchError(() => EMPTY),\n\t\t\t\tswitchMap((provider) =>\n\t\t\t\t\tprovider\n\t\t\t\t\t\t? merge(\n\t\t\t\t\t\t\t\tfromEvent(provider, \"session_delete\"),\n\t\t\t\t\t\t\t\tfromEvent(provider, \"connect\"),\n\t\t\t\t\t\t\t\tof(undefined),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: EMPTY,\n\t\t\t\t),\n\t\t\t)\n\t\t\t.subscribe(syncProviders);\n\t\tconst sub = wallet$.subscribe(subscriber);\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t\tsessionSub.unsubscribe();\n\t\t\tunsubProviders();\n\t\t};\n\t});\n};\n\n/**\n * @remarks\n * The AppKit instance is a process-wide singleton: a second instance would\n * share AppKit's module-level controller state with the first, so it is\n * created once. 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 */\nconst getWalletConnectWallet$ = (\n\twalletConnect: WalletConnectOptions,\n\tdebug: boolean,\n): Observable<WalletConnectWallet | null> => {\n\t// SSR guard - don't try to load AppKit on the server\n\tif (typeof window === \"undefined\") return of(null);\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\tconst connectorOnce$ = from(loadAppKit()).pipe(\n\t\t\tmap((createAppKit) =>\n\t\t\t\t// @reown/appkit missing (optional peer dep) — degrade gracefully.\n\t\t\t\tcreateAppKit\n\t\t\t\t\t? createConnector$(\n\t\t\t\t\t\t\tcreateAppKit({\n\t\t\t\t\t\t\t\tallWallets: \"HIDE\",\n\t\t\t\t\t\t\t\tdebug,\n\t\t\t\t\t\t\t\tallowUnsupportedChain: true,\n\t\t\t\t\t\t\t\t...walletConnect.appKitOptions,\n\t\t\t\t\t\t\t\tprojectId: walletConnect.projectId,\n\t\t\t\t\t\t\t\tmetadata: walletConnect.metadata,\n\t\t\t\t\t\t\t\tnetworks: walletConnect.networks as never,\n\t\t\t\t\t\t\t\tthemeMode: walletConnect.themeMode,\n\t\t\t\t\t\t\t\tthemeVariables: walletConnect.themeVariables as never,\n\t\t\t\t\t\t\t\tuniversalProviderConfigOverride: {\n\t\t\t\t\t\t\t\t\tmethods: methodsFor(walletConnect.networks),\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: null,\n\t\t\t),\n\t\t\tshareReplay({ refCount: false, bufferSize: 1 }),\n\t\t);\n\t\tcachedAppKit = connectorOnce$.pipe(\n\t\t\tswitchMap((wallet$) => wallet$ ?? of(null)),\n\t\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t\t);\n\t\tsetCachedAppKit(cachedAppKit, walletConnect.projectId);\n\t}\n\n\treturn cachedAppKit;\n};\n\n/**\n * The WalletConnect plugin for `config.walletConnect`. Importing this entry is\n * what brings Reown AppKit into a dapp's bundle; a dapp that never imports it\n * ships none of it.\n *\n * @example\n * ```ts\n * import { walletConnect } from \"@kheopskit/core/walletconnect\";\n *\n * createKheopskit({\n * platforms: [polkadot()],\n * walletConnect: walletConnect({ projectId, metadata, networks }),\n * });\n * ```\n */\nexport const walletConnect = (\n\toptions: WalletConnectOptions,\n): WalletConnectPlugin => ({\n\ttype: \"walletconnect\",\n\tmetadata: options.metadata,\n\tgetWallet$: ({ config }) => getWalletConnectWallet$(options, config.debug),\n});\n"],"mappings":";;;;;;;;;;AAqEA,MAAM,aAAa,YAAY;CAC9B,IAAI;EACH,MAAM,EAAE,iBAAiB,MAAM,OAAO;EACtC,OAAO;CACR,SAAS,OAAO;EACf,QAAQ,MACP,8NAGA,KACD;EACA,OAAO;CACR;AACD;AAEA,MAAM,sBACL;AAKD,MAAM,gBAAgB,OAAO,IAAI,wBAAwB;AAIzD,MAAM,2BAA2B,OAAO,IAAI,iCAAiC;AAK7E,MAAM,wBAGJ,WAAuC;AAGzC,MAAM,iCACJ,WAAuC;AAGzC,MAAM,mBACL,OACA,cACU;CACV,WAAwC,iBAAiB;CACzD,WAAwC,4BAA4B;AACrE;;;;;;AAOA,MAAa,yBAA+B;CAC3C,gBAAgB,KAAA,CAAS;AAC1B;;;;;AAMA,MAAM,qBAAqB,aAAmC;CAC7D,yBAAA,+BACC,YAAYA,yBAAAA,yBAAyB,GAAG,SAAS,EAClD;AACD;AAEA,MAAM,cAAc;CACnB,UAAU;CACV,UAAU;CACV,QAAQ;AACT;AACA,MAAM,eAAiC;CAAC;CAAY;CAAY;AAAQ;AAExE,MAAM,qBAA+C;CACpD,UAAU,CAAC,4BAA4B,sBAAsB;CAC7D,QAAQ;EACP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AA,GAAWG,KAAAA,GAAAA,CAAG,IAAI,CAAC,IAAA,GAC1CC,KAAAA,YAAAA,CAAY;GAAE,UAAU;GAAM,YAAY;EAAE,CAAC,CAC9C;EACA,gBAAgB,cAAc,cAAc,SAAS;CACtD;CAEA,OAAO;AACR;;;;;;;;;;;;;;;;AAiBA,MAAa,iBACZ,aAC0B;CAC1B,MAAM;CACN,UAAU,QAAQ;CAClB,aAAa,EAAE,aAAa,wBAAwB,SAAS,OAAO,KAAK;AAC1E"}
@@ -1,6 +1,6 @@
1
- import { n as isWalletConnectWallet, r as WALLET_CONNECT_WALLET_ID, u as clearCachedObservablesByPrefix } from "./types-DcpmEGhO.mjs";
1
+ import { c as WALLET_CONNECT_WALLET_ID, h as clearCachedObservablesByPrefix, i as getSessionCaip10s, s as isWalletConnectWallet } from "./platformAccounts-sy621l8C.mjs";
2
2
  import { o as toConnectError } from "./errors-DszTFbnO.mjs";
3
- import { BehaviorSubject, Observable, distinctUntilChanged, from, map, of, shareReplay, switchMap, tap } from "rxjs";
3
+ import { BehaviorSubject, EMPTY, Observable, catchError, distinctUntilChanged, from, fromEvent, map, merge, of, shareReplay, switchMap, tap } from "rxjs";
4
4
  //#region src/api/walletconnect/plugin.ts
5
5
  /**
6
6
  * Dynamically import @reown/appkit/core to avoid loading browser-only code
@@ -71,12 +71,17 @@ const createConnector$ = (appKit) => {
71
71
  opening: false,
72
72
  error: void 0
73
73
  });
74
- const syncProviders = (providers) => {
74
+ const liveSession = (platform) => {
75
+ const namespace = namespaceOf[platform];
76
+ const session = appKit.getProvider(namespace)?.session;
77
+ return session && getSessionCaip10s(session, namespace).length > 0 ? session : void 0;
78
+ };
79
+ const syncProviders = () => {
75
80
  status$.next({
76
81
  ...status$.value,
77
- isPolkadotConnected: !!providers.polkadot,
78
- isEthereumConnected: !!providers.eip155,
79
- isSolanaConnected: !!providers.solana
82
+ isPolkadotConnected: !!liveSession("polkadot"),
83
+ isEthereumConnected: !!liveSession("ethereum"),
84
+ isSolanaConnected: !!liveSession("solana")
80
85
  });
81
86
  };
82
87
  const openModal = async () => {
@@ -119,14 +124,14 @@ const createConnector$ = (appKit) => {
119
124
  }), map(({ opening, error, ...connected }) => {
120
125
  const platforms = enabledPlatforms.filter((p) => connected[p]);
121
126
  const isConnected = platforms.length > 0;
122
- const walletInfo = appKit.getWalletInfo();
127
+ const peer = platforms[0] && liveSession(platforms[0])?.peer?.metadata;
123
128
  return {
124
129
  id: WALLET_CONNECT_WALLET_ID,
125
130
  type: "walletconnect",
126
131
  platforms,
127
132
  appKit: appKitInstance,
128
- name: walletInfo?.name ?? "WalletConnect",
129
- icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
133
+ name: peer?.name || "WalletConnect",
134
+ icon: peer?.icons?.[0] || WALLET_CONNECT_ICON,
130
135
  connect: async () => {
131
136
  if (!isConnected) await openModal();
132
137
  },
@@ -140,15 +145,13 @@ const createConnector$ = (appKit) => {
140
145
  }));
141
146
  return new Observable((subscriber) => {
142
147
  for (const platform of allPlatforms) dropAccountsCache(platform);
143
- syncProviders({
144
- polkadot: appKit.getProvider("polkadot"),
145
- eip155: appKit.getProvider("eip155"),
146
- solana: appKit.getProvider("solana")
147
- });
148
+ syncProviders();
148
149
  const unsubProviders = appKit.subscribeProviders(syncProviders);
150
+ const sessionSub = from(appKit.getUniversalProvider()).pipe(catchError(() => EMPTY), switchMap((provider) => provider ? merge(fromEvent(provider, "session_delete"), fromEvent(provider, "connect"), of(void 0)) : EMPTY)).subscribe(syncProviders);
149
151
  const sub = wallet$.subscribe(subscriber);
150
152
  return () => {
151
153
  sub.unsubscribe();
154
+ sessionSub.unsubscribe();
152
155
  unsubProviders();
153
156
  };
154
157
  });
@@ -1 +1 @@
1
- {"version":3,"file":"walletconnect.mjs","names":[],"sources":["../src/api/walletconnect/plugin.ts"],"sourcesContent":["import type { AppKit } from \"@reown/appkit/core\";\nimport {\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 KheopskitError, toConnectError } from \"../errors\";\nimport type {\n\tAppKitInstance,\n\tWalletConnectMetadata,\n\tWalletConnectPlugin,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"../types\";\n\nexport type WalletConnectOptions = {\n\tprojectId: string;\n\tmetadata: WalletConnectMetadata;\n\t/**\n\t * Networks AppKit should enable. Pass `AppKitNetwork[]` from\n\t * `@reown/appkit/networks` (see\n\t * https://docs.reown.com/advanced/multichain/polkadot/dapp-integration-guide#walletconnect-code%2Fcomponent-setup).\n\t * Loosely typed (`unknown`) so the declarations don't depend on\n\t * `@reown/appkit`'s types; the value is forwarded to AppKit as-is.\n\t */\n\tnetworks: [unknown, ...unknown[]];\n\tthemeMode?: \"light\" | \"dark\";\n\tthemeVariables?: Record<string, string | number>;\n\t/**\n\t * Extra Reown AppKit `createAppKit` options (e.g. `featuredWalletIds`,\n\t * `features`, `allWallets`), forwarded as-is; see\n\t * https://docs.reown.com/appkit/javascript/core/options.\n\t * kheopskit sets `projectId`, `metadata`, `networks`, `themeMode`,\n\t * `themeVariables` and `universalProviderConfigOverride` itself, so those\n\t * keys are rejected here.\n\t */\n\tappKitOptions?: AppKitOptions;\n};\n\ntype KheopskitOwnedAppKitKey =\n\t| \"projectId\"\n\t| \"metadata\"\n\t| \"networks\"\n\t| \"themeMode\"\n\t| \"themeVariables\"\n\t| \"universalProviderConfigOverride\";\n\ntype AppKitOptions = Record<string, unknown> &\n\tPartial<Record<KheopskitOwnedAppKitKey, never>>;\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 * 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\nconst namespaceOf: Record<WalletPlatform, string> = {\n\tpolkadot: \"polkadot\",\n\tethereum: \"eip155\",\n\tsolana: \"solana\",\n};\nconst allPlatforms: WalletPlatform[] = [\"polkadot\", \"ethereum\", \"solana\"];\n\nconst methodsByNamespace: Record<string, string[]> = {\n\tpolkadot: [\"polkadot_signTransaction\", \"polkadot_signMessage\"],\n\tsolana: [\n\t\t\"solana_signTransaction\",\n\t\t\"solana_signMessage\",\n\t\t\"solana_signAndSendTransaction\",\n\t],\n};\n\n// AppKit turns every overridden namespace into a pairing request, and rejects\n// the pairing when one of them has no chains.\nconst methodsFor = (networks: unknown[]): Record<string, string[]> => {\n\tconst namespaces = new Set(\n\t\tnetworks.map(\n\t\t\t(network) => (network as { chainNamespace?: string }).chainNamespace,\n\t\t),\n\t);\n\treturn Object.fromEntries(\n\t\tObject.entries(methodsByNamespace).filter(([namespace]) =>\n\t\t\tnamespaces.has(namespace),\n\t\t),\n\t);\n};\n\nconst createConnector$ = (appKit: AppKit): Observable<WalletConnectWallet> => {\n\t// Exposed on the wallet as the (decoupled) AppKitInstance escape hatch.\n\tconst appKitInstance = appKit as unknown as AppKitInstance;\n\n\tconst status$ = new BehaviorSubject<{\n\t\tisPolkadotConnected: boolean;\n\t\tisEthereumConnected: boolean;\n\t\tisSolanaConnected: boolean;\n\t\topening: boolean;\n\t\terror: KheopskitError | undefined;\n\t}>({\n\t\tisPolkadotConnected: false,\n\t\tisEthereumConnected: false,\n\t\tisSolanaConnected: false,\n\t\topening: false,\n\t\terror: undefined,\n\t});\n\n\tconst syncProviders = (providers: Partial<Record<string, unknown>>) => {\n\t\tstatus$.next({\n\t\t\t...status$.value,\n\t\t\tisPolkadotConnected: !!providers.polkadot,\n\t\t\tisEthereumConnected: !!providers.eip155,\n\t\t\tisSolanaConnected: !!providers.solana,\n\t\t});\n\t};\n\n\tconst openModal = async () => {\n\t\tstatus$.next({ ...status$.value, opening: true, error: undefined });\n\t\ttry {\n\t\t\tawait appKit.open();\n\t\t} catch (cause) {\n\t\t\tconst error = toConnectError(\n\t\t\t\tcause,\n\t\t\t\tWALLET_CONNECT_WALLET_ID,\n\t\t\t\t() => false,\n\t\t\t);\n\t\t\tstatus$.next({ ...status$.value, opening: false, error });\n\t\t\tthrow error;\n\t\t}\n\t\tstatus$.next({ ...status$.value, opening: false });\n\t};\n\n\tconst enabledPlatforms = allPlatforms.filter((p) =>\n\t\t(appKit.chainNamespaces as string[]).includes(namespaceOf[p]),\n\t);\n\n\tlet prevConnected = {\n\t\tpolkadot: false,\n\t\tethereum: false,\n\t\tsolana: false,\n\t};\n\n\tconst wallet$ = status$.pipe(\n\t\tmap((s) => ({\n\t\t\tpolkadot: s.isPolkadotConnected,\n\t\t\tethereum: s.isEthereumConnected,\n\t\t\tsolana: s.isSolanaConnected,\n\t\t\topening: s.opening,\n\t\t\terror: s.error,\n\t\t})),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) =>\n\t\t\t\ta.polkadot === b.polkadot &&\n\t\t\t\ta.ethereum === b.ethereum &&\n\t\t\t\ta.solana === b.solana &&\n\t\t\t\ta.opening === b.opening &&\n\t\t\t\ta.error === b.error,\n\t\t),\n\t\ttap((connected) => {\n\t\t\t// Drop caches for namespaces that just went disconnected.\n\t\t\tfor (const platform of allPlatforms)\n\t\t\t\tif (prevConnected[platform] && !connected[platform])\n\t\t\t\t\tdropAccountsCache(platform);\n\t\t\tprevConnected = connected;\n\t\t}),\n\t\tmap(({ opening, error, ...connected }): WalletConnectWallet => {\n\t\t\tconst platforms = enabledPlatforms.filter((p) => connected[p]);\n\t\t\tconst isConnected = platforms.length > 0;\n\t\t\tconst walletInfo = appKit.getWalletInfo();\n\t\t\treturn {\n\t\t\t\tid: WALLET_CONNECT_WALLET_ID,\n\t\t\t\ttype: \"walletconnect\",\n\t\t\t\tplatforms,\n\t\t\t\tappKit: appKitInstance,\n\t\t\t\tname: walletInfo?.name ?? \"WalletConnect\",\n\t\t\t\ticon: walletInfo?.icon ?? WALLET_CONNECT_ICON,\n\t\t\t\t// One shared session: connecting opens the modal; the wallet\n\t\t\t\t// approves namespaces in that single pairing. Disconnect is\n\t\t\t\t// session-wide; re-pair to change the approved set.\n\t\t\t\tconnect: async () => {\n\t\t\t\t\tif (!isConnected) await openModal();\n\t\t\t\t},\n\t\t\t\tdisconnect: async () => {\n\t\t\t\t\tif (isConnected) await appKit.disconnect();\n\t\t\t\t},\n\t\t\t\tstatus: isConnected\n\t\t\t\t\t? \"connected\"\n\t\t\t\t\t: opening\n\t\t\t\t\t\t? \"connecting\"\n\t\t\t\t\t\t: \"disconnected\",\n\t\t\t\terror,\n\t\t\t\tisConnected,\n\t\t\t};\n\t\t}),\n\t);\n\n\treturn new Observable<WalletConnectWallet>((subscriber) => {\n\t\tfor (const platform of allPlatforms) dropAccountsCache(platform);\n\t\t// AppKit's subscribeProviders only reports later changes, so read the\n\t\t// state that may have changed while nobody observed.\n\t\tsyncProviders({\n\t\t\tpolkadot: appKit.getProvider(\"polkadot\"),\n\t\t\teip155: appKit.getProvider(\"eip155\"),\n\t\t\tsolana: appKit.getProvider(\"solana\"),\n\t\t});\n\t\tconst unsubProviders = appKit.subscribeProviders(syncProviders);\n\t\tconst sub = wallet$.subscribe(subscriber);\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t\tunsubProviders();\n\t\t};\n\t});\n};\n\n/**\n * @remarks\n * The AppKit instance is a process-wide singleton: a second instance would\n * share AppKit's module-level controller state with the first, so it is\n * created once. 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 */\nconst getWalletConnectWallet$ = (\n\twalletConnect: WalletConnectOptions,\n\tdebug: boolean,\n): Observable<WalletConnectWallet | null> => {\n\t// SSR guard - don't try to load AppKit on the server\n\tif (typeof window === \"undefined\") return of(null);\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\tconst connectorOnce$ = from(loadAppKit()).pipe(\n\t\t\tmap((createAppKit) =>\n\t\t\t\t// @reown/appkit missing (optional peer dep) — degrade gracefully.\n\t\t\t\tcreateAppKit\n\t\t\t\t\t? createConnector$(\n\t\t\t\t\t\t\tcreateAppKit({\n\t\t\t\t\t\t\t\tallWallets: \"HIDE\",\n\t\t\t\t\t\t\t\tdebug,\n\t\t\t\t\t\t\t\tallowUnsupportedChain: true,\n\t\t\t\t\t\t\t\t...walletConnect.appKitOptions,\n\t\t\t\t\t\t\t\tprojectId: walletConnect.projectId,\n\t\t\t\t\t\t\t\tmetadata: walletConnect.metadata,\n\t\t\t\t\t\t\t\tnetworks: walletConnect.networks as never,\n\t\t\t\t\t\t\t\tthemeMode: walletConnect.themeMode,\n\t\t\t\t\t\t\t\tthemeVariables: walletConnect.themeVariables as never,\n\t\t\t\t\t\t\t\tuniversalProviderConfigOverride: {\n\t\t\t\t\t\t\t\t\tmethods: methodsFor(walletConnect.networks),\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: null,\n\t\t\t),\n\t\t\tshareReplay({ refCount: false, bufferSize: 1 }),\n\t\t);\n\t\tcachedAppKit = connectorOnce$.pipe(\n\t\t\tswitchMap((wallet$) => wallet$ ?? of(null)),\n\t\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t\t);\n\t\tsetCachedAppKit(cachedAppKit, walletConnect.projectId);\n\t}\n\n\treturn cachedAppKit;\n};\n\n/**\n * The WalletConnect plugin for `config.walletConnect`. Importing this entry is\n * what brings Reown AppKit into a dapp's bundle; a dapp that never imports it\n * ships none of it.\n *\n * @example\n * ```ts\n * import { walletConnect } from \"@kheopskit/core/walletconnect\";\n *\n * createKheopskit({\n * platforms: [polkadot()],\n * walletConnect: walletConnect({ projectId, metadata, networks }),\n * });\n * ```\n */\nexport const walletConnect = (\n\toptions: WalletConnectOptions,\n): WalletConnectPlugin => ({\n\ttype: \"walletconnect\",\n\tmetadata: options.metadata,\n\tgetWallet$: ({ config }) => getWalletConnectWallet$(options, config.debug),\n});\n"],"mappings":";;;;;;;;;AA+DA,MAAM,aAAa,YAAY;CAC9B,IAAI;EACH,MAAM,EAAE,iBAAiB,MAAM,OAAO;EACtC,OAAO;CACR,SAAS,OAAO;EACf,QAAQ,MACP,8NAGA,KACD;EACA,OAAO;CACR;AACD;AAEA,MAAM,sBACL;AAKD,MAAM,gBAAgB,OAAO,IAAI,wBAAwB;AAIzD,MAAM,2BAA2B,OAAO,IAAI,iCAAiC;AAK7E,MAAM,wBAGJ,WAAuC;AAGzC,MAAM,iCACJ,WAAuC;AAGzC,MAAM,mBACL,OACA,cACU;CACV,WAAwC,iBAAiB;CACzD,WAAwC,4BAA4B;AACrE;;;;;;AAOA,MAAa,yBAA+B;CAC3C,gBAAgB,KAAA,CAAS;AAC1B;;;;;AAMA,MAAM,qBAAqB,aAAmC;CAC7D,+BACC,YAAY,yBAAyB,GAAG,SAAS,EAClD;AACD;AAEA,MAAM,cAA8C;CACnD,UAAU;CACV,UAAU;CACV,QAAQ;AACT;AACA,MAAM,eAAiC;CAAC;CAAY;CAAY;AAAQ;AAExE,MAAM,qBAA+C;CACpD,UAAU,CAAC,4BAA4B,sBAAsB;CAC7D,QAAQ;EACP;EACA;EACA;CACD;AACD;AAIA,MAAM,cAAc,aAAkD;CACrE,MAAM,aAAa,IAAI,IACtB,SAAS,KACP,YAAa,QAAwC,cACvD,CACD;CACA,OAAO,OAAO,YACb,OAAO,QAAQ,kBAAkB,CAAC,CAAC,QAAQ,CAAC,eAC3C,WAAW,IAAI,SAAS,CACzB,CACD;AACD;AAEA,MAAM,oBAAoB,WAAoD;CAE7E,MAAM,iBAAiB;CAEvB,MAAM,UAAU,IAAI,gBAMjB;EACF,qBAAqB;EACrB,qBAAqB;EACrB,mBAAmB;EACnB,SAAS;EACT,OAAO,KAAA;CACR,CAAC;CAED,MAAM,iBAAiB,cAAgD;EACtE,QAA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,KAC7B,WAAW,YAAY,WAAW,GAAG,IAAI,CAAC,GAC1C,YAAY;GAAE,UAAU;GAAM,YAAY;EAAE,CAAC,CAC9C;EACA,gBAAgB,cAAc,cAAc,SAAS;CACtD;CAEA,OAAO;AACR;;;;;;;;;;;;;;;;AAiBA,MAAa,iBACZ,aAC0B;CAC1B,MAAM;CACN,UAAU,QAAQ;CAClB,aAAa,EAAE,aAAa,wBAAwB,SAAS,OAAO,KAAK;AAC1E"}
1
+ {"version":3,"file":"walletconnect.mjs","names":[],"sources":["../src/api/walletconnect/plugin.ts"],"sourcesContent":["import type { AppKit } from \"@reown/appkit/core\";\nimport {\n\tBehaviorSubject,\n\tcatchError,\n\tdistinctUntilChanged,\n\tEMPTY,\n\tfrom,\n\tfromEvent,\n\tmap,\n\tmerge,\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 KheopskitError, toConnectError } from \"../errors\";\nimport { getSessionCaip10s } from \"../platformAccounts\";\nimport type {\n\tAppKitInstance,\n\tWalletConnectMetadata,\n\tWalletConnectPlugin,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"../types\";\n\nexport type WalletConnectOptions = {\n\tprojectId: string;\n\tmetadata: WalletConnectMetadata;\n\t/**\n\t * Networks AppKit should enable. Pass `AppKitNetwork[]` from\n\t * `@reown/appkit/networks` (see\n\t * https://docs.reown.com/advanced/multichain/polkadot/dapp-integration-guide#walletconnect-code%2Fcomponent-setup).\n\t * Loosely typed (`unknown`) so the declarations don't depend on\n\t * `@reown/appkit`'s types; the value is forwarded to AppKit as-is.\n\t */\n\tnetworks: [unknown, ...unknown[]];\n\tthemeMode?: \"light\" | \"dark\";\n\tthemeVariables?: Record<string, string | number>;\n\t/**\n\t * Extra Reown AppKit `createAppKit` options (e.g. `featuredWalletIds`,\n\t * `features`, `allWallets`), forwarded as-is; see\n\t * https://docs.reown.com/appkit/javascript/core/options.\n\t * kheopskit sets `projectId`, `metadata`, `networks`, `themeMode`,\n\t * `themeVariables` and `universalProviderConfigOverride` itself, so those\n\t * keys are rejected here.\n\t */\n\tappKitOptions?: AppKitOptions;\n};\n\ntype KheopskitOwnedAppKitKey =\n\t| \"projectId\"\n\t| \"metadata\"\n\t| \"networks\"\n\t| \"themeMode\"\n\t| \"themeVariables\"\n\t| \"universalProviderConfigOverride\";\n\ntype AppKitOptions = Record<string, unknown> &\n\tPartial<Record<KheopskitOwnedAppKitKey, never>>;\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+PC9jbGlwUGF0aD48ZyBjbGlwLXBhdGg9InVybCgjYSkiPjxjaXJjbGUgY3g9IjIwMCIgY3k9IjI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ODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+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 * 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\nconst namespaceOf = {\n\tpolkadot: \"polkadot\",\n\tethereum: \"eip155\",\n\tsolana: \"solana\",\n} as const satisfies Record<WalletPlatform, string>;\nconst allPlatforms: WalletPlatform[] = [\"polkadot\", \"ethereum\", \"solana\"];\n\nconst methodsByNamespace: Record<string, string[]> = {\n\tpolkadot: [\"polkadot_signTransaction\", \"polkadot_signMessage\"],\n\tsolana: [\n\t\t\"solana_signTransaction\",\n\t\t\"solana_signMessage\",\n\t\t\"solana_signAndSendTransaction\",\n\t],\n};\n\n// AppKit turns every overridden namespace into a pairing request, and rejects\n// the pairing when one of them has no chains.\nconst methodsFor = (networks: unknown[]): Record<string, string[]> => {\n\tconst namespaces = new Set(\n\t\tnetworks.map(\n\t\t\t(network) => (network as { chainNamespace?: string }).chainNamespace,\n\t\t),\n\t);\n\treturn Object.fromEntries(\n\t\tObject.entries(methodsByNamespace).filter(([namespace]) =>\n\t\t\tnamespaces.has(namespace),\n\t\t),\n\t);\n};\n\nconst createConnector$ = (appKit: AppKit): Observable<WalletConnectWallet> => {\n\t// Exposed on the wallet as the (decoupled) AppKitInstance escape hatch.\n\tconst appKitInstance = appKit as unknown as AppKitInstance;\n\n\tconst status$ = new BehaviorSubject<{\n\t\tisPolkadotConnected: boolean;\n\t\tisEthereumConnected: boolean;\n\t\tisSolanaConnected: boolean;\n\t\topening: boolean;\n\t\terror: KheopskitError | undefined;\n\t}>({\n\t\tisPolkadotConnected: false,\n\t\tisEthereumConnected: false,\n\t\tisSolanaConnected: false,\n\t\topening: false,\n\t\terror: undefined,\n\t});\n\n\tconst liveSession = (platform: WalletPlatform) => {\n\t\tconst namespace = namespaceOf[platform];\n\t\tconst session =\n\t\t\tappKit.getProvider<WalletConnectProvider>(namespace)?.session;\n\t\treturn session && getSessionCaip10s(session, namespace).length > 0\n\t\t\t? session\n\t\t\t: undefined;\n\t};\n\n\tconst syncProviders = () => {\n\t\tstatus$.next({\n\t\t\t...status$.value,\n\t\t\tisPolkadotConnected: !!liveSession(\"polkadot\"),\n\t\t\tisEthereumConnected: !!liveSession(\"ethereum\"),\n\t\t\tisSolanaConnected: !!liveSession(\"solana\"),\n\t\t});\n\t};\n\n\tconst openModal = async () => {\n\t\tstatus$.next({ ...status$.value, opening: true, error: undefined });\n\t\ttry {\n\t\t\tawait appKit.open();\n\t\t} catch (cause) {\n\t\t\tconst error = toConnectError(\n\t\t\t\tcause,\n\t\t\t\tWALLET_CONNECT_WALLET_ID,\n\t\t\t\t() => false,\n\t\t\t);\n\t\t\tstatus$.next({ ...status$.value, opening: false, error });\n\t\t\tthrow error;\n\t\t}\n\t\tstatus$.next({ ...status$.value, opening: false });\n\t};\n\n\tconst enabledPlatforms = allPlatforms.filter((p) =>\n\t\t(appKit.chainNamespaces as string[]).includes(namespaceOf[p]),\n\t);\n\n\tlet prevConnected = {\n\t\tpolkadot: false,\n\t\tethereum: false,\n\t\tsolana: false,\n\t};\n\n\tconst wallet$ = status$.pipe(\n\t\tmap((s) => ({\n\t\t\tpolkadot: s.isPolkadotConnected,\n\t\t\tethereum: s.isEthereumConnected,\n\t\t\tsolana: s.isSolanaConnected,\n\t\t\topening: s.opening,\n\t\t\terror: s.error,\n\t\t})),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) =>\n\t\t\t\ta.polkadot === b.polkadot &&\n\t\t\t\ta.ethereum === b.ethereum &&\n\t\t\t\ta.solana === b.solana &&\n\t\t\t\ta.opening === b.opening &&\n\t\t\t\ta.error === b.error,\n\t\t),\n\t\ttap((connected) => {\n\t\t\t// Drop caches for namespaces that just went disconnected.\n\t\t\tfor (const platform of allPlatforms)\n\t\t\t\tif (prevConnected[platform] && !connected[platform])\n\t\t\t\t\tdropAccountsCache(platform);\n\t\t\tprevConnected = connected;\n\t\t}),\n\t\tmap(({ opening, error, ...connected }): WalletConnectWallet => {\n\t\t\tconst platforms = enabledPlatforms.filter((p) => connected[p]);\n\t\t\tconst isConnected = platforms.length > 0;\n\t\t\tconst peer = platforms[0] && liveSession(platforms[0])?.peer?.metadata;\n\t\t\treturn {\n\t\t\t\tid: WALLET_CONNECT_WALLET_ID,\n\t\t\t\ttype: \"walletconnect\",\n\t\t\t\tplatforms,\n\t\t\t\tappKit: appKitInstance,\n\t\t\t\tname: peer?.name || \"WalletConnect\",\n\t\t\t\ticon: peer?.icons?.[0] || WALLET_CONNECT_ICON,\n\t\t\t\t// One shared session: connecting opens the modal; the wallet\n\t\t\t\t// approves namespaces in that single pairing. Disconnect is\n\t\t\t\t// session-wide; re-pair to change the approved set.\n\t\t\t\tconnect: async () => {\n\t\t\t\t\tif (!isConnected) await openModal();\n\t\t\t\t},\n\t\t\t\tdisconnect: async () => {\n\t\t\t\t\tif (isConnected) await appKit.disconnect();\n\t\t\t\t},\n\t\t\t\tstatus: isConnected\n\t\t\t\t\t? \"connected\"\n\t\t\t\t\t: opening\n\t\t\t\t\t\t? \"connecting\"\n\t\t\t\t\t\t: \"disconnected\",\n\t\t\t\terror,\n\t\t\t\tisConnected,\n\t\t\t};\n\t\t}),\n\t);\n\n\treturn new Observable<WalletConnectWallet>((subscriber) => {\n\t\tfor (const platform of allPlatforms) dropAccountsCache(platform);\n\t\t// AppKit's subscribeProviders only reports later changes, so read the\n\t\t// state that may have changed while nobody observed.\n\t\tsyncProviders();\n\t\tconst unsubProviders = appKit.subscribeProviders(syncProviders);\n\t\t// AppKit keeps a namespace's provider registered when the wallet ends the\n\t\t// session, and registers that same object again on the next pairing, so\n\t\t// subscribeProviders reports neither.\n\t\tconst sessionSub = from(appKit.getUniversalProvider())\n\t\t\t.pipe(\n\t\t\t\tcatchError(() => EMPTY),\n\t\t\t\tswitchMap((provider) =>\n\t\t\t\t\tprovider\n\t\t\t\t\t\t? merge(\n\t\t\t\t\t\t\t\tfromEvent(provider, \"session_delete\"),\n\t\t\t\t\t\t\t\tfromEvent(provider, \"connect\"),\n\t\t\t\t\t\t\t\tof(undefined),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: EMPTY,\n\t\t\t\t),\n\t\t\t)\n\t\t\t.subscribe(syncProviders);\n\t\tconst sub = wallet$.subscribe(subscriber);\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t\tsessionSub.unsubscribe();\n\t\t\tunsubProviders();\n\t\t};\n\t});\n};\n\n/**\n * @remarks\n * The AppKit instance is a process-wide singleton: a second instance would\n * share AppKit's module-level controller state with the first, so it is\n * created once. 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 */\nconst getWalletConnectWallet$ = (\n\twalletConnect: WalletConnectOptions,\n\tdebug: boolean,\n): Observable<WalletConnectWallet | null> => {\n\t// SSR guard - don't try to load AppKit on the server\n\tif (typeof window === \"undefined\") return of(null);\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\tconst connectorOnce$ = from(loadAppKit()).pipe(\n\t\t\tmap((createAppKit) =>\n\t\t\t\t// @reown/appkit missing (optional peer dep) — degrade gracefully.\n\t\t\t\tcreateAppKit\n\t\t\t\t\t? createConnector$(\n\t\t\t\t\t\t\tcreateAppKit({\n\t\t\t\t\t\t\t\tallWallets: \"HIDE\",\n\t\t\t\t\t\t\t\tdebug,\n\t\t\t\t\t\t\t\tallowUnsupportedChain: true,\n\t\t\t\t\t\t\t\t...walletConnect.appKitOptions,\n\t\t\t\t\t\t\t\tprojectId: walletConnect.projectId,\n\t\t\t\t\t\t\t\tmetadata: walletConnect.metadata,\n\t\t\t\t\t\t\t\tnetworks: walletConnect.networks as never,\n\t\t\t\t\t\t\t\tthemeMode: walletConnect.themeMode,\n\t\t\t\t\t\t\t\tthemeVariables: walletConnect.themeVariables as never,\n\t\t\t\t\t\t\t\tuniversalProviderConfigOverride: {\n\t\t\t\t\t\t\t\t\tmethods: methodsFor(walletConnect.networks),\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: null,\n\t\t\t),\n\t\t\tshareReplay({ refCount: false, bufferSize: 1 }),\n\t\t);\n\t\tcachedAppKit = connectorOnce$.pipe(\n\t\t\tswitchMap((wallet$) => wallet$ ?? of(null)),\n\t\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t\t);\n\t\tsetCachedAppKit(cachedAppKit, walletConnect.projectId);\n\t}\n\n\treturn cachedAppKit;\n};\n\n/**\n * The WalletConnect plugin for `config.walletConnect`. Importing this entry is\n * what brings Reown AppKit into a dapp's bundle; a dapp that never imports it\n * ships none of it.\n *\n * @example\n * ```ts\n * import { walletConnect } from \"@kheopskit/core/walletconnect\";\n *\n * createKheopskit({\n * platforms: [polkadot()],\n * walletConnect: walletConnect({ projectId, metadata, networks }),\n * });\n * ```\n */\nexport const walletConnect = (\n\toptions: WalletConnectOptions,\n): WalletConnectPlugin => ({\n\ttype: \"walletconnect\",\n\tmetadata: options.metadata,\n\tgetWallet$: ({ config }) => getWalletConnectWallet$(options, config.debug),\n});\n"],"mappings":";;;;;;;;;AAqEA,MAAM,aAAa,YA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c;GACjB,WAAW,cAAc;GACzB,UAAU,cAAc;GACxB,UAAU,cAAc;GACxB,WAAW,cAAc;GACzB,gBAAgB,cAAc;GAC9B,iCAAiC,EAChC,SAAS,WAAW,cAAc,QAAQ,EAC3C;EACD,CAAC,CACF,IACC,IACJ,GACA,YAAY;GAAE,UAAU;GAAO,YAAY;EAAE,CAAC,CAEnB,CAAC,CAAC,KAC7B,WAAW,YAAY,WAAW,GAAG,IAAI,CAAC,GAC1C,YAAY;GAAE,UAAU;GAAM,YAAY;EAAE,CAAC,CAC9C;EACA,gBAAgB,cAAc,cAAc,SAAS;CACtD;CAEA,OAAO;AACR;;;;;;;;;;;;;;;;AAiBA,MAAa,iBACZ,aAC0B;CAC1B,MAAM;CACN,UAAU,QAAQ;CAClB,aAAa,EAAE,aAAa,wBAAwB,SAAS,OAAO,KAAK;AAC1E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kheopskit/core",
3
- "version": "6.0.2",
3
+ "version": "6.0.4",
4
4
  "description": "Framework-agnostic wallet and account discovery for Polkadot, Ethereum and Solana dapps. Upgrading from v5? Read MIGRATING_TO_V6.md, shipped in this package.",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -1 +0,0 @@
1
- {"version":3,"file":"platformAccounts-C1sFv82e.mjs","names":[],"sources":["../src/utils/isEthereumAddress.ts","../src/utils/isSolanaAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/WalletAccountId.ts","../src/api/platformAccounts.ts"],"sourcesContent":["import { keccak_256 } from \"@noble/hashes/sha3.js\";\n\nconst HEX_ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst encoder = new TextEncoder();\n\n/**\n * Verifies the EIP-55 mixed-case checksum of an Ethereum address.\n * Dependency-free (keccak via @noble/hashes) so core stays decoupled from viem.\n */\nconst isChecksumValid = (address: string): boolean => {\n\tconst hex = address.slice(2);\n\tconst hash = keccak_256(encoder.encode(hex.toLowerCase()));\n\tfor (let i = 0; i < 40; i++) {\n\t\tconst char = hex.charAt(i);\n\t\tconst isLetter =\n\t\t\t(char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\");\n\t\tif (!isLetter) continue;\n\t\tconst byte = hash[i >> 1] ?? 0;\n\t\tconst nibble = i % 2 === 0 ? byte >> 4 : byte & 0x0f;\n\t\tconst isUpper = char <= \"F\";\n\t\tif (isUpper !== nibble >= 8) return false;\n\t}\n\treturn true;\n};\n\n/**\n * Returns true if `address` is a valid Ethereum address.\n *\n * Mirrors viem's `isAddress` (strict): the shape must be `0x` + 40 hex, and a\n * mixed-case address must pass the EIP-55 checksum. All-lowercase addresses are\n * accepted as non-checksummed.\n */\nexport const isEthereumAddress = (address: string): boolean => {\n\tif (!HEX_ADDRESS.test(address)) return false;\n\tif (address === address.toLowerCase()) return true;\n\treturn isChecksumValid(address);\n};\n","import { base58 } from \"@scure/base\";\n\n/**\n * Returns true if the value is a valid Solana address: a base58-encoded\n * 32-byte ed25519 public key.\n *\n * Solana addresses carry no checksum, so this is a pure base58 + length check.\n * Dependency-free (base58 via @scure/base) so core stays decoupled from\n * @solana/kit.\n */\nexport const isSolanaAddress = (address: string): boolean => {\n\tif (!address) return false;\n\ttry {\n\t\treturn base58.decode(address).length === 32;\n\t} catch {\n\t\treturn false;\n\t}\n};\n","import { blake2b } from \"@noble/hashes/blake2.js\";\nimport { base58 } from \"@scure/base\";\n\n// The \"SS58PRE\" prefix used in the SS58 checksum preimage.\nconst SS58PRE = new Uint8Array([0x53, 0x53, 0x35, 0x38, 0x50, 0x52, 0x45]);\n\n/**\n * Returns true if `address` is a valid SS58-encoded 32-byte account id (the\n * only form Substrate wallets inject), verifying the blake2b-512 checksum.\n *\n * Dependency-free (base58 via @scure/base, blake2b via @noble/hashes) so core\n * stays decoupled from polkadot-api.\n */\nexport const isSs58Address = (address: string): boolean => {\n\tif (!address) return false;\n\n\tlet decoded: Uint8Array;\n\ttry {\n\t\tdecoded = base58.decode(address);\n\t} catch {\n\t\treturn false;\n\t}\n\n\t// First byte encodes the network prefix; the high bit is reserved/invalid.\n\tconst firstByte = decoded[0];\n\tif (firstByte === undefined || firstByte & 0b1000_0000) return false;\n\t// The 0b0100_0000 bit marks a 2-byte prefix.\n\tconst prefixLength = firstByte & 0b0100_0000 ? 2 : 1;\n\n\t// AccountId32 layout: prefix + 32-byte pubkey + 2-byte checksum.\n\tif (decoded.length !== prefixLength + 32 + 2) return false;\n\n\tconst body = decoded.subarray(0, decoded.length - 2);\n\tconst preimage = new Uint8Array(SS58PRE.length + body.length);\n\tpreimage.set(SS58PRE);\n\tpreimage.set(body, SS58PRE.length);\n\tconst hash = blake2b(preimage, { dkLen: 64 });\n\n\treturn (\n\t\tdecoded[decoded.length - 2] === hash[0] &&\n\t\tdecoded[decoded.length - 1] === hash[1]\n\t);\n};\n","import { isEthereumAddress } from \"./isEthereumAddress\";\nimport { isSolanaAddress } from \"./isSolanaAddress\";\nimport { isSs58Address } from \"./isSs58Address\";\n\nexport const isValidAddress = (address: string): boolean => {\n\tif (address.startsWith(\"0x\")) return isEthereumAddress(address);\n\t// SS58 (checksummed) and Solana (base58, no checksum) are disjoint: a\n\t// 32-byte Solana pubkey fails SS58 decoding, and an SS58 address decodes to\n\t// more than 32 bytes so it fails the Solana length check.\n\treturn isSs58Address(address) || isSolanaAddress(address);\n};\n","import { isValidAddress } from \"./isValidAddress\";\n\nexport type WalletAccountId = string;\n\nexport const getWalletAccountId = (\n\twalletId: string,\n\taddress: string,\n): WalletAccountId => {\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn `${walletId}::${address}`;\n};\n\nexport const parseWalletAccountId = (accountId: string) => {\n\tif (!accountId) throw new Error(\"Invalid walletAccountId\");\n\tconst [walletId, address] = accountId.split(\"::\");\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!address || !isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn { walletId, address };\n};\n","import {\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tof,\n\tSubscription,\n\tshareReplay,\n} from \"rxjs\";\nimport { getCachedObservable$ } from \"../utils/getCachedObservable\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\nexport type LiveWalletConnectWallet = Exclude<\n\tWalletConnectWallet,\n\t{ isPlaceholder: true }\n>;\n\nexport type PlatformAccountsOptions<\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n> = {\n\t/** This platform's wallets plus the shared WalletConnect connector. */\n\twallets$: Observable<(TWallet | WalletConnectWallet)[]>;\n\t/** Account stream for one connected injected wallet. */\n\tgetInjectedAccounts$: (wallet: TWallet) => Observable<TAccount[]>;\n\t/** Account stream for the WalletConnect connector. */\n\tgetWalletConnectAccounts$: (\n\t\twallet: LiveWalletConnectWallet,\n\t) => Observable<TAccount[]>;\n\t/** Optional post-flatten transform (e.g. Polkadot's `accountTypes` filter). */\n\tmapAccounts?: (accounts: TAccount[]) => TAccount[];\n\t/**\n\t * Signature of the account fields that should trigger a re-emission.\n\t * Defaults to the account id; platforms add mutable fields (Ethereum\n\t * `chainId`, Solana `chains`).\n\t */\n\taccountChangeKey?: (account: TAccount) => string;\n};\n\n/** The account list plus the connected wallets whose stream has answered, an empty list included. */\nexport type PlatformAccountsFrame<TAccount> = {\n\taccounts: TAccount[];\n\tanswered: WalletId[];\n};\n\nexport type PlatformAccounts$<TAccount> = Observable<TAccount[]> & {\n\tframes$: Observable<PlatformAccountsFrame<TAccount>>;\n};\n\nconst isPlatformAccounts$ = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): accounts$ is PlatformAccounts$<TAccount> => \"frames$\" in accounts$;\n\n/** A plugin not built on `createPlatformAccounts$` reports no answered wallet. */\nexport const framesOf = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): Observable<PlatformAccountsFrame<TAccount>> =>\n\tisPlatformAccounts$(accounts$)\n\t\t? accounts$.frames$\n\t\t: accounts$.pipe(map((accounts) => ({ accounts, answered: [] })));\n\nconst idsEqual = (a: WalletId[], b: WalletId[]) =>\n\ta.length === b.length && a.every((id, i) => id === b[i]);\n\ntype WalletConnection<TAccount> = {\n\tkey: string;\n\taccounts: TAccount[];\n\tanswered: boolean;\n\tcompleted: boolean;\n\tsubscription: Subscription;\n};\n\nconst sessionKey = (wallet: WalletConnectWallet): string =>\n\t`${wallet.id}|${wallet.platforms.join(\",\")}`;\n\nconst connectionKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\tisWalletConnectWallet(wallet) ? sessionKey(wallet) : wallet.id;\n\n/** Shared engine behind every platform's `getAccounts$`. */\nexport const createPlatformAccounts$ = <\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n>({\n\twallets$,\n\tgetInjectedAccounts$,\n\tgetWalletConnectAccounts$,\n\tmapAccounts,\n\taccountChangeKey = (account) => account.id,\n}: PlatformAccountsOptions<TWallet, TAccount>): PlatformAccounts$<TAccount> => {\n\ttype Frame = PlatformAccountsFrame<TAccount>;\n\tconst nameAndChangeKey = (account: TAccount) =>\n\t\t`${account.name ?? \"\"}|${accountChangeKey(account)}`;\n\tconst accountsListEqual = (a: TAccount[], b: TAccount[]) =>\n\t\ta.length === b.length &&\n\t\ta.every((account, i) => {\n\t\t\tconst other = b[i];\n\t\t\treturn !!other && nameAndChangeKey(account) === nameAndChangeKey(other);\n\t\t});\n\tconst accountsOf = (wallet: TWallet | LiveWalletConnectWallet) =>\n\t\tisWalletConnectWallet(wallet)\n\t\t\t? getWalletConnectAccounts$(wallet)\n\t\t\t: getInjectedAccounts$(wallet);\n\n\tconst frames$ = new Observable<Frame>((subscriber) => {\n\t\tconst connections = new Map<WalletId, WalletConnection<TAccount>>();\n\t\tlet connectedIds: WalletId[] = [];\n\t\tlet walletsCompleted = false;\n\t\tlet emitted = false;\n\n\t\tconst awaitingFirstAnswers = () =>\n\t\t\t!emitted &&\n\t\t\t[...connections.values()].some((connection) => !connection.answered);\n\n\t\tconst accountsListed = () =>\n\t\t\tconnectedIds.flatMap((id) => connections.get(id)?.accounts ?? []);\n\t\tconst walletsAnswered = () =>\n\t\t\tconnectedIds.filter((id) => connections.get(id)?.answered);\n\n\t\tconst emit = () => {\n\t\t\tif (awaitingFirstAnswers()) return;\n\t\t\temitted = true;\n\t\t\tsubscriber.next({\n\t\t\t\taccounts: accountsListed(),\n\t\t\t\tanswered: walletsAnswered(),\n\t\t\t});\n\t\t};\n\n\t\tconst completeIfDone = () => {\n\t\t\tif (\n\t\t\t\twalletsCompleted &&\n\t\t\t\t[...connections.values()].every((connection) => connection.completed)\n\t\t\t)\n\t\t\t\tsubscriber.complete();\n\t\t};\n\n\t\tconst reconcile = (wallets: (TWallet | WalletConnectWallet)[]) => {\n\t\t\tconst connected = wallets.filter(\n\t\t\t\t(wallet): wallet is TWallet | LiveWalletConnectWallet =>\n\t\t\t\t\twallet.isConnected && !wallet.isPlaceholder,\n\t\t\t);\n\t\t\tconst keys = new Map(\n\t\t\t\tconnected.map((w) => [w.id, connectionKey(w)] as const),\n\t\t\t);\n\t\t\tfor (const [id, connection] of connections) {\n\t\t\t\tif (keys.get(id) === connection.key) continue;\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t\t\tconnections.delete(id);\n\t\t\t}\n\t\t\tconnectedIds = connected.map((wallet) => wallet.id);\n\t\t\tconst opened = connected\n\t\t\t\t.filter((wallet) => !connections.has(wallet.id))\n\t\t\t\t.map((wallet) => {\n\t\t\t\t\tconst connection: WalletConnection<TAccount> = {\n\t\t\t\t\t\tkey: connectionKey(wallet),\n\t\t\t\t\t\taccounts: [],\n\t\t\t\t\t\tanswered: false,\n\t\t\t\t\t\tcompleted: false,\n\t\t\t\t\t\tsubscription: new Subscription(),\n\t\t\t\t\t};\n\t\t\t\t\tconnections.set(wallet.id, connection);\n\t\t\t\t\treturn { wallet, connection };\n\t\t\t\t});\n\t\t\tfor (const { wallet, connection } of opened) {\n\t\t\t\tconnection.subscription.add(\n\t\t\t\t\taccountsOf(wallet).subscribe({\n\t\t\t\t\t\tnext: (accounts) => {\n\t\t\t\t\t\t\tconnection.accounts = accounts;\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror: (error) => {\n\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t`[kheopskit] Could not list the accounts of ${wallet.id}`,\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconnection.accounts = [];\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t\tcompleteIfDone();\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcomplete: () => {\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\tcompleteIfDone();\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\temit();\n\t\t};\n\n\t\tconst sub = wallets$.subscribe({\n\t\t\tnext: reconcile,\n\t\t\terror: (error) => subscriber.error(error),\n\t\t\tcomplete: () => {\n\t\t\t\twalletsCompleted = true;\n\t\t\t\tcompleteIfDone();\n\t\t\t},\n\t\t});\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t\tfor (const connection of connections.values())\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tmap((frame) =>\n\t\t\tmapAccounts ? { ...frame, accounts: mapAccounts(frame.accounts) } : frame,\n\t\t),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) =>\n\t\t\t\taccountsListEqual(a.accounts, b.accounts) &&\n\t\t\t\tidsEqual(a.answered, b.answered),\n\t\t),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\tconst accounts$ = frames$.pipe(\n\t\tmap((frame) => frame.accounts),\n\t\tdistinctUntilChanged(accountsListEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\treturn Object.assign(accounts$, { frames$ });\n};\n\n/**\n * CAIP-10 account strings (\"<namespace>:<chainRef>:<address>\") the live\n * WalletConnect session carries for a namespace.\n */\nexport const getSessionCaip10s = (\n\tsession: NonNullable<WalletConnectProvider[\"session\"]>,\n\tnamespace: string,\n): string[] =>\n\tObject.values(session.namespaces)\n\t\t.flatMap((ns) => ns.accounts ?? [])\n\t\t.filter((account) => account.startsWith(`${namespace}:`));\n\n/**\n * Unique addresses from CAIP-10 account strings (one entry per chain, so the\n * same address repeats — dedupe).\n */\nexport const getCaip10Addresses = (caip10s: string[]): string[] => [\n\t...new Set(\n\t\tcaip10s\n\t\t\t.map((account) => account.split(\":\")[2])\n\t\t\t.filter((address): address is string => !!address),\n\t),\n];\n\n/**\n * Shared shape of the Polkadot/Solana WalletConnect account streams: no-op\n * unless the session carries the platform's namespace, then a cached\n * observable that rebuilds the account list from the session on\n * `session_update` / `accountsChanged`.\n *\n * AppKit's `getAccount(namespace).allAccounts` is always empty for namespaces\n * without a native AppKit adapter — the WalletConnect session is the source of\n * truth, hence the session-driven rebuild.\n */\nexport const getWalletConnectSessionAccounts$ = <\n\tTAccount extends BaseWalletAccount,\n>(options: {\n\twallet: LiveWalletConnectWallet;\n\tplatform: WalletPlatform;\n\t/** WalletConnect namespace, e.g. \"polkadot\" | \"solana\" | \"eip155\". */\n\tnamespace: string;\n\t/** Cache key for {@link getCachedObservable$} — must be reconnect-safe. */\n\tcacheKey: string;\n\t/** Build the account list from the live session. */\n\tbuildAccounts: (provider: WalletConnectProvider) => TAccount[];\n}): Observable<TAccount[]> => {\n\tconst { wallet, platform, namespace, cacheKey, buildAccounts } = options;\n\tconst provider = wallet.appKit.getProvider(namespace);\n\n\tif (!wallet.platforms.includes(platform) || !provider?.session) return of([]);\n\n\treturn getCachedObservable$(cacheKey, () =>\n\t\tnew Observable<TAccount[]>((subscriber) => {\n\t\t\tsubscriber.next(buildAccounts(provider));\n\n\t\t\t// Re-derive when the WalletConnect session's accounts change, mirroring\n\t\t\t// the injected paths' change subscriptions.\n\t\t\tconst reemit = () => subscriber.next(buildAccounts(provider));\n\t\t\tprovider.on(\"session_update\", reemit);\n\t\t\tprovider.on(\"accountsChanged\", reemit);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"session_update\", reemit);\n\t\t\t\tprovider.off(\"accountsChanged\", reemit);\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n"],"mappings":";;;;;;AAEA,MAAM,cAAc;AACpB,MAAM,UAAU,IAAI,YAAY;;;;;AAMhC,MAAM,mBAAmB,YAA6B;CACrD,MAAM,MAAM,QAAQ,MAAM,CAAC;CAC3B,MAAM,OAAO,WAAW,QAAQ,OAAO,IAAI,YAAY,CAAC,CAAC;CACzD,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK;EAC5B,MAAM,OAAO,IAAI,OAAO,CAAC;EAGzB,IAAI,EADF,QAAQ,OAAO,QAAQ,OAAS,QAAQ,OAAO,QAAQ,MAC1C;EACf,MAAM,OAAO,KAAK,KAAK,MAAM;EAC7B,MAAM,SAAS,IAAI,MAAM,IAAI,QAAQ,IAAI,OAAO;EAEhD,IADgB,QAAQ,QACR,UAAU,GAAG,OAAO;CACrC;CACA,OAAO;AACR;;;;;;;;AASA,MAAa,qBAAqB,YAA6B;CAC9D,IAAI,CAAC,YAAY,KAAK,OAAO,GAAG,OAAO;CACvC,IAAI,YAAY,QAAQ,YAAY,GAAG,OAAO;CAC9C,OAAO,gBAAgB,OAAO;AAC/B;;;;;;;;;;;AC1BA,MAAa,mBAAmB,YAA6B;CAC5D,IAAI,CAAC,SAAS,OAAO;CACrB,IAAI;EACH,OAAO,OA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AAC,OAAO,CACnD,CACD;;;;;;;;;;;AAYA,MAAa,oCAEX,YAS4B;CAC7B,MAAM,EAAE,QAAQ,UAAU,WAAW,UAAU,kBAAkB;CACjE,MAAM,WAAW,OAAO,OAAO,YAAY,SAAS;CAEpD,IAAI,CAAC,OAAO,UAAU,SAAS,QAAQ,KAAK,CAAC,UAAU,SAAS,OAAO,GAAG,CAAC,CAAC;CAE5E,OAAO,qBAAqB,gBAC3B,IAAI,YAAwB,eAAe;EAC1C,WAAW,KAAK,cAAc,QAAQ,CAAC;EAIvC,MAAM,eAAe,WAAW,KAAK,cAAc,QAAQ,CAAC;EAC5D,SAAS,GAAG,kBAAkB,MAAM;EACpC,SAAS,GAAG,mBAAmB,MAAM;EAErC,aAAa;GACZ,SAAS,IAAI,kBAAkB,MAAM;GACrC,SAAS,IAAI,mBAAmB,MAAM;EACvC;CACD,CAAC,CAAC,CAAC,KAAK,YAAY;EAAE,UAAU;EAAM,YAAY;CAAE,CAAC,CAAC,CACvD;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"platformAccounts-CqMSpl3X.js","names":["keccak_256","base58","base58","blake2b","map","isWalletConnectWallet","Observable","Subscription","distinctUntilChanged","shareReplay","of","getCachedObservable$"],"sources":["../src/utils/isEthereumAddress.ts","../src/utils/isSolanaAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/WalletAccountId.ts","../src/api/platformAccounts.ts"],"sourcesContent":["import { keccak_256 } from \"@noble/hashes/sha3.js\";\n\nconst HEX_ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst encoder = new TextEncoder();\n\n/**\n * Verifies the EIP-55 mixed-case checksum of an Ethereum address.\n * Dependency-free (keccak via @noble/hashes) so core stays decoupled from viem.\n */\nconst isChecksumValid = (address: string): boolean => {\n\tconst hex = address.slice(2);\n\tconst hash = keccak_256(encoder.encode(hex.toLowerCase()));\n\tfor (let i = 0; i < 40; i++) {\n\t\tconst char = hex.charAt(i);\n\t\tconst isLetter =\n\t\t\t(char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\");\n\t\tif (!isLetter) continue;\n\t\tconst byte = hash[i >> 1] ?? 0;\n\t\tconst nibble = i % 2 === 0 ? byte >> 4 : byte & 0x0f;\n\t\tconst isUpper = char <= \"F\";\n\t\tif (isUpper !== nibble >= 8) return false;\n\t}\n\treturn true;\n};\n\n/**\n * Returns true if `address` is a valid Ethereum address.\n *\n * Mirrors viem's `isAddress` (strict): the shape must be `0x` + 40 hex, and a\n * mixed-case address must pass the EIP-55 checksum. All-lowercase addresses are\n * accepted as non-checksummed.\n */\nexport const isEthereumAddress = (address: string): boolean => {\n\tif (!HEX_ADDRESS.test(address)) return false;\n\tif (address === address.toLowerCase()) return true;\n\treturn isChecksumValid(address);\n};\n","import { base58 } from \"@scure/base\";\n\n/**\n * Returns true if the value is a valid Solana address: a base58-encoded\n * 32-byte ed25519 public key.\n *\n * Solana addresses carry no checksum, so this is a pure base58 + length check.\n * Dependency-free (base58 via @scure/base) so core stays decoupled from\n * @solana/kit.\n */\nexport const isSolanaAddress = (address: string): boolean => {\n\tif (!address) return false;\n\ttry {\n\t\treturn base58.decode(address).length === 32;\n\t} catch {\n\t\treturn false;\n\t}\n};\n","import { blake2b } from \"@noble/hashes/blake2.js\";\nimport { base58 } from \"@scure/base\";\n\n// The \"SS58PRE\" prefix used in the SS58 checksum preimage.\nconst SS58PRE = new Uint8Array([0x53, 0x53, 0x35, 0x38, 0x50, 0x52, 0x45]);\n\n/**\n * Returns true if `address` is a valid SS58-encoded 32-byte account id (the\n * only form Substrate wallets inject), verifying the blake2b-512 checksum.\n *\n * Dependency-free (base58 via @scure/base, blake2b via @noble/hashes) so core\n * stays decoupled from polkadot-api.\n */\nexport const isSs58Address = (address: string): boolean => {\n\tif (!address) return false;\n\n\tlet decoded: Uint8Array;\n\ttry {\n\t\tdecoded = base58.decode(address);\n\t} catch {\n\t\treturn false;\n\t}\n\n\t// First byte encodes the network prefix; the high bit is reserved/invalid.\n\tconst firstByte = decoded[0];\n\tif (firstByte === undefined || firstByte & 0b1000_0000) return false;\n\t// The 0b0100_0000 bit marks a 2-byte prefix.\n\tconst prefixLength = firstByte & 0b0100_0000 ? 2 : 1;\n\n\t// AccountId32 layout: prefix + 32-byte pubkey + 2-byte checksum.\n\tif (decoded.length !== prefixLength + 32 + 2) return false;\n\n\tconst body = decoded.subarray(0, decoded.length - 2);\n\tconst preimage = new Uint8Array(SS58PRE.length + body.length);\n\tpreimage.set(SS58PRE);\n\tpreimage.set(body, SS58PRE.length);\n\tconst hash = blake2b(preimage, { dkLen: 64 });\n\n\treturn (\n\t\tdecoded[decoded.length - 2] === hash[0] &&\n\t\tdecoded[decoded.length - 1] === hash[1]\n\t);\n};\n","import { isEthereumAddress } from \"./isEthereumAddress\";\nimport { isSolanaAddress } from \"./isSolanaAddress\";\nimport { isSs58Address } from \"./isSs58Address\";\n\nexport const isValidAddress = (address: string): boolean => {\n\tif (address.startsWith(\"0x\")) return isEthereumAddress(address);\n\t// SS58 (checksummed) and Solana (base58, no checksum) are disjoint: a\n\t// 32-byte Solana pubkey fails SS58 decoding, and an SS58 address decodes to\n\t// more than 32 bytes so it fails the Solana length check.\n\treturn isSs58Address(address) || isSolanaAddress(address);\n};\n","import { isValidAddress } from \"./isValidAddress\";\n\nexport type WalletAccountId = string;\n\nexport const getWalletAccountId = (\n\twalletId: string,\n\taddress: string,\n): WalletAccountId => {\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn `${walletId}::${address}`;\n};\n\nexport const parseWalletAccountId = (accountId: string) => {\n\tif (!accountId) throw new Error(\"Invalid walletAccountId\");\n\tconst [walletId, address] = accountId.split(\"::\");\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!address || !isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn { walletId, address };\n};\n","import {\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tof,\n\tSubscription,\n\tshareReplay,\n} from \"rxjs\";\nimport { getCachedObservable$ } from \"../utils/getCachedObservable\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\nexport type LiveWalletConnectWallet = Exclude<\n\tWalletConnectWallet,\n\t{ isPlaceholder: true }\n>;\n\nexport type PlatformAccountsOptions<\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n> = {\n\t/** This platform's wallets plus the shared WalletConnect connector. */\n\twallets$: Observable<(TWallet | WalletConnectWallet)[]>;\n\t/** Account stream for one connected injected wallet. */\n\tgetInjectedAccounts$: (wallet: TWallet) => Observable<TAccount[]>;\n\t/** Account stream for the WalletConnect connector. */\n\tgetWalletConnectAccounts$: (\n\t\twallet: LiveWalletConnectWallet,\n\t) => Observable<TAccount[]>;\n\t/** Optional post-flatten transform (e.g. Polkadot's `accountTypes` filter). */\n\tmapAccounts?: (accounts: TAccount[]) => TAccount[];\n\t/**\n\t * Signature of the account fields that should trigger a re-emission.\n\t * Defaults to the account id; platforms add mutable fields (Ethereum\n\t * `chainId`, Solana `chains`).\n\t */\n\taccountChangeKey?: (account: TAccount) => string;\n};\n\n/** The account list plus the connected wallets whose stream has answered, an empty list included. */\nexport type PlatformAccountsFrame<TAccount> = {\n\taccounts: TAccount[];\n\tanswered: WalletId[];\n};\n\nexport type PlatformAccounts$<TAccount> = Observable<TAccount[]> & {\n\tframes$: Observable<PlatformAccountsFrame<TAccount>>;\n};\n\nconst isPlatformAccounts$ = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): accounts$ is PlatformAccounts$<TAccount> => \"frames$\" in accounts$;\n\n/** A plugin not built on `createPlatformAccounts$` reports no answered wallet. */\nexport const framesOf = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): Observable<PlatformAccountsFrame<TAccount>> =>\n\tisPlatformAccounts$(accounts$)\n\t\t? accounts$.frames$\n\t\t: accounts$.pipe(map((accounts) => ({ accounts, answered: [] })));\n\nconst idsEqual = (a: WalletId[], b: WalletId[]) =>\n\ta.length === b.length && a.every((id, i) => id === b[i]);\n\ntype WalletConnection<TAccount> = {\n\tkey: string;\n\taccounts: TAccount[];\n\tanswered: boolean;\n\tcompleted: boolean;\n\tsubscription: Subscription;\n};\n\nconst sessionKey = (wallet: WalletConnectWallet): string =>\n\t`${wallet.id}|${wallet.platforms.join(\",\")}`;\n\nconst connectionKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\tisWalletConnectWallet(wallet) ? sessionKey(wallet) : wallet.id;\n\n/** Shared engine behind every platform's `getAccounts$`. */\nexport const createPlatformAccounts$ = <\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n>({\n\twallets$,\n\tgetInjectedAccounts$,\n\tgetWalletConnectAccounts$,\n\tmapAccounts,\n\taccountChangeKey = (account) => account.id,\n}: PlatformAccountsOptions<TWallet, TAccount>): PlatformAccounts$<TAccount> => {\n\ttype Frame = PlatformAccountsFrame<TAccount>;\n\tconst nameAndChangeKey = (account: TAccount) =>\n\t\t`${account.name ?? \"\"}|${accountChangeKey(account)}`;\n\tconst accountsListEqual = (a: TAccount[], b: TAccount[]) =>\n\t\ta.length === b.length &&\n\t\ta.every((account, i) => {\n\t\t\tconst other = b[i];\n\t\t\treturn !!other && nameAndChangeKey(account) === nameAndChangeKey(other);\n\t\t});\n\tconst accountsOf = (wallet: TWallet | LiveWalletConnectWallet) =>\n\t\tisWalletConnectWallet(wallet)\n\t\t\t? getWalletConnectAccounts$(wallet)\n\t\t\t: getInjectedAccounts$(wallet);\n\n\tconst frames$ = new Observable<Frame>((subscriber) => {\n\t\tconst connections = new Map<WalletId, WalletConnection<TAccount>>();\n\t\tlet connectedIds: WalletId[] = [];\n\t\tlet walletsCompleted = false;\n\t\tlet emitted = false;\n\n\t\tconst awaitingFirstAnswers = () =>\n\t\t\t!emitted &&\n\t\t\t[...connections.values()].some((connection) => !connection.answered);\n\n\t\tconst accountsListed = () =>\n\t\t\tconnectedIds.flatMap((id) => connections.get(id)?.accounts ?? []);\n\t\tconst walletsAnswered = () =>\n\t\t\tconnectedIds.filter((id) => connections.get(id)?.answered);\n\n\t\tconst emit = () => {\n\t\t\tif (awaitingFirstAnswers()) return;\n\t\t\temitted = true;\n\t\t\tsubscriber.next({\n\t\t\t\taccounts: accountsListed(),\n\t\t\t\tanswered: walletsAnswered(),\n\t\t\t});\n\t\t};\n\n\t\tconst completeIfDone = () => {\n\t\t\tif (\n\t\t\t\twalletsCompleted &&\n\t\t\t\t[...connections.values()].every((connection) => connection.completed)\n\t\t\t)\n\t\t\t\tsubscriber.complete();\n\t\t};\n\n\t\tconst reconcile = (wallets: (TWallet | WalletConnectWallet)[]) => {\n\t\t\tconst connected = wallets.filter(\n\t\t\t\t(wallet): wallet is TWallet | LiveWalletConnectWallet =>\n\t\t\t\t\twallet.isConnected && !wallet.isPlaceholder,\n\t\t\t);\n\t\t\tconst keys = new Map(\n\t\t\t\tconnected.map((w) => [w.id, connectionKey(w)] as const),\n\t\t\t);\n\t\t\tfor (const [id, connection] of connections) {\n\t\t\t\tif (keys.get(id) === connection.key) continue;\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t\t\tconnections.delete(id);\n\t\t\t}\n\t\t\tconnectedIds = connected.map((wallet) => wallet.id);\n\t\t\tconst opened = connected\n\t\t\t\t.filter((wallet) => !connections.has(wallet.id))\n\t\t\t\t.map((wallet) => {\n\t\t\t\t\tconst connection: WalletConnection<TAccount> = {\n\t\t\t\t\t\tkey: connectionKey(wallet),\n\t\t\t\t\t\taccounts: [],\n\t\t\t\t\t\tanswered: false,\n\t\t\t\t\t\tcompleted: false,\n\t\t\t\t\t\tsubscription: new Subscription(),\n\t\t\t\t\t};\n\t\t\t\t\tconnections.set(wallet.id, connection);\n\t\t\t\t\treturn { wallet, connection };\n\t\t\t\t});\n\t\t\tfor (const { wallet, connection } of opened) {\n\t\t\t\tconnection.subscription.add(\n\t\t\t\t\taccountsOf(wallet).subscribe({\n\t\t\t\t\t\tnext: (accounts) => {\n\t\t\t\t\t\t\tconnection.accounts = accounts;\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror: (error) => {\n\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t`[kheopskit] Could not list the accounts of ${wallet.id}`,\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconnection.accounts = [];\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t\tcompleteIfDone();\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcomplete: () => {\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\tcompleteIfDone();\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\temit();\n\t\t};\n\n\t\tconst sub = wallets$.subscribe({\n\t\t\tnext: reconcile,\n\t\t\terror: (error) => subscriber.error(error),\n\t\t\tcomplete: () => {\n\t\t\t\twalletsCompleted = true;\n\t\t\t\tcompleteIfDone();\n\t\t\t},\n\t\t});\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t\tfor (const connection of connections.values())\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tmap((frame) =>\n\t\t\tmapAccounts ? { ...frame, accounts: mapAccounts(frame.accounts) } : frame,\n\t\t),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) =>\n\t\t\t\taccountsListEqual(a.accounts, b.accounts) &&\n\t\t\t\tidsEqual(a.answered, b.answered),\n\t\t),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\tconst accounts$ = frames$.pipe(\n\t\tmap((frame) => frame.accounts),\n\t\tdistinctUntilChanged(accountsListEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\treturn Object.assign(accounts$, { frames$ });\n};\n\n/**\n * CAIP-10 account strings (\"<namespace>:<chainRef>:<address>\") the live\n * WalletConnect session carries for a namespace.\n */\nexport const getSessionCaip10s = (\n\tsession: NonNullable<WalletConnectProvider[\"session\"]>,\n\tnamespace: string,\n): string[] =>\n\tObject.values(session.namespaces)\n\t\t.flatMap((ns) => ns.accounts ?? [])\n\t\t.filter((account) => account.startsWith(`${namespace}:`));\n\n/**\n * Unique addresses from CAIP-10 account strings (one entry per chain, so the\n * same address repeats — dedupe).\n */\nexport const getCaip10Addresses = (caip10s: string[]): string[] => [\n\t...new Set(\n\t\tcaip10s\n\t\t\t.map((account) => account.split(\":\")[2])\n\t\t\t.filter((address): address is string => !!address),\n\t),\n];\n\n/**\n * Shared shape of the Polkadot/Solana WalletConnect account streams: no-op\n * unless the session carries the platform's namespace, then a cached\n * observable that rebuilds the account list from the session on\n * `session_update` / `accountsChanged`.\n *\n * AppKit's `getAccount(namespace).allAccounts` is always empty for namespaces\n * without a native AppKit adapter — the WalletConnect session is the source of\n * truth, hence the session-driven rebuild.\n */\nexport const getWalletConnectSessionAccounts$ = <\n\tTAccount extends BaseWalletAccount,\n>(options: {\n\twallet: LiveWalletConnectWallet;\n\tplatform: WalletPlatform;\n\t/** WalletConnect namespace, e.g. \"polkadot\" | \"solana\" | \"eip155\". */\n\tnamespace: string;\n\t/** Cache key for {@link getCachedObservable$} — must be reconnect-safe. */\n\tcacheKey: string;\n\t/** Build the account list from the live session. */\n\tbuildAccounts: (provider: WalletConnectProvider) => TAccount[];\n}): Observable<TAccount[]> => {\n\tconst { wallet, platform, namespace, cacheKey, buildAccounts } = options;\n\tconst provider = wallet.appKit.getProvider(namespace);\n\n\tif (!wallet.platforms.includes(platform) || !provider?.session) return of([]);\n\n\treturn getCachedObservable$(cacheKey, () =>\n\t\tnew Observable<TAccount[]>((subscriber) => {\n\t\t\tsubscriber.next(buildAccounts(provider));\n\n\t\t\t// Re-derive when the WalletConnect session's accounts change, mirroring\n\t\t\t// the injected paths' change subscriptions.\n\t\t\tconst reemit = () => subscriber.next(buildAccounts(provider));\n\t\t\tprovider.on(\"session_update\", reemit);\n\t\t\tprovider.on(\"accountsChanged\", reemit);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"session_update\", reemit);\n\t\t\t\tprovider.off(\"accountsChanged\", reemit);\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n"],"mappings":";;;;;;AAEA,MAAM,cAAc;AACpB,MAAM,UAAU,IAAI,YAAY;;;;;AAMhC,MAAM,mBAAmB,YAA6B;CACrD,MAAM,MAAM,QAAQ,MAAM,CAAC;CAC3B,MAAM,QAAA,GAAOA,sBAAAA,WAAAA,CAAW,QAAQ,OAAO,IAAI,YAAY,CAAC,CAAC;CACzD,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK;EAC5B,MAAM,OAAO,IAAI,OAAO,CAAC;EAGzB,IAAI,EADF,QAAQ,OAAO,QAAQ,OAAS,QAAQ,OAAO,QAAQ,MAC1C;EACf,MAAM,OAAO,KAAK,KAAK,MAAM;EAC7B,MAAM,SAAS,IAAI,MAAM,IAAI,QAAQ,IAAI,OAAO;EAEhD,IADgB,QAAQ,QACR,UAAU,GAAG,OAAO;CACrC;CACA,OAAO;AACR;;;;;;;;AASA,MAAa,qBAAqB,YAA6B;CAC9D,IAAI,CAAC,YAAY,KAAK,OAAO,GAAG,OAAO;CACvC,IAAI,YAAY,QAAQ,YAAY,GAAG,OAAO;CAC9C,OAAO,gBAAgB,OAAO;AAC/B;;;;;;;;;;;AC1BA,MAAa,mBAAmB,YAA6B;CAC5D,IAAI,CAAC,SAAS,OAAO;CACrB,IAAI;EACH,OAAOC,YAAAA,OAAO,OAAO,OAAO,CAAC,CA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