@kheopskit/core 1.0.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/MIGRATING_TO_V4.md +259 -0
  2. package/README.md +67 -0
  3. package/dist/chunk-4ENHC7G4.js +210 -0
  4. package/dist/chunk-4ENHC7G4.js.map +1 -0
  5. package/dist/chunk-6XAZANB5.mjs +450 -0
  6. package/dist/chunk-6XAZANB5.mjs.map +1 -0
  7. package/dist/chunk-7QSGAJ4A.mjs +210 -0
  8. package/dist/chunk-7QSGAJ4A.mjs.map +1 -0
  9. package/dist/chunk-B4L6GAYD.js +179 -0
  10. package/dist/chunk-B4L6GAYD.js.map +1 -0
  11. package/dist/chunk-BWUUHUDK.mjs +24 -0
  12. package/dist/chunk-BWUUHUDK.mjs.map +1 -0
  13. package/dist/chunk-D3EQMFZ2.js +24 -0
  14. package/dist/chunk-D3EQMFZ2.js.map +1 -0
  15. package/dist/chunk-XQWJM3KC.js +450 -0
  16. package/dist/chunk-XQWJM3KC.js.map +1 -0
  17. package/dist/chunk-YDLCHYHH.mjs +179 -0
  18. package/dist/chunk-YDLCHYHH.mjs.map +1 -0
  19. package/dist/ethereum.d.mts +61 -0
  20. package/dist/ethereum.d.ts +61 -0
  21. package/dist/ethereum.js +351 -0
  22. package/dist/ethereum.js.map +1 -0
  23. package/dist/ethereum.mjs +351 -0
  24. package/dist/ethereum.mjs.map +1 -0
  25. package/dist/getCachedObservable-C4E8dfMp.d.mts +20 -0
  26. package/dist/getCachedObservable-C4E8dfMp.d.ts +20 -0
  27. package/dist/index.d.mts +55 -267
  28. package/dist/index.d.ts +55 -267
  29. package/dist/index.js +327 -1355
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +263 -1325
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/internal.d.mts +86 -0
  34. package/dist/internal.d.ts +86 -0
  35. package/dist/internal.js +32 -0
  36. package/dist/internal.js.map +1 -0
  37. package/dist/internal.mjs +32 -0
  38. package/dist/internal.mjs.map +1 -0
  39. package/dist/polkadot.d.mts +70 -0
  40. package/dist/polkadot.d.ts +70 -0
  41. package/dist/polkadot.js +303 -0
  42. package/dist/polkadot.js.map +1 -0
  43. package/dist/polkadot.mjs +303 -0
  44. package/dist/polkadot.mjs.map +1 -0
  45. package/dist/solana.d.mts +98 -0
  46. package/dist/solana.d.ts +98 -0
  47. package/dist/solana.js +461 -0
  48. package/dist/solana.js.map +1 -0
  49. package/dist/solana.mjs +461 -0
  50. package/dist/solana.mjs.map +1 -0
  51. package/dist/types-C7V7DGlg.d.mts +349 -0
  52. package/dist/types-C7V7DGlg.d.ts +349 -0
  53. package/package.json +104 -18
@@ -0,0 +1,179 @@
1
+ import {
2
+ POLKADOT_EXTENSIONS
3
+ } from "./chunk-BWUUHUDK.mjs";
4
+ import {
5
+ isWalletConnectWallet,
6
+ parseWalletId,
7
+ safeLocalStorage
8
+ } from "./chunk-7QSGAJ4A.mjs";
9
+
10
+ // src/utils/hydrateState.ts
11
+ var lookupWalletIcon = (platform, identifier) => {
12
+ if (platform === "polkadot") {
13
+ return POLKADOT_EXTENSIONS[identifier]?.icon ?? "";
14
+ }
15
+ return "";
16
+ };
17
+ var PendingWalletError = class extends Error {
18
+ constructor(walletId) {
19
+ super(
20
+ `Wallet ${walletId} is still loading. Wait for isHydrating to be false before calling connect/disconnect.`
21
+ );
22
+ this.name = "PendingWalletError";
23
+ }
24
+ };
25
+ var hydrateWallet = (cached) => {
26
+ const throwPending = () => {
27
+ throw new PendingWalletError(cached.id);
28
+ };
29
+ if (cached.type === "walletconnect") {
30
+ return {
31
+ id: cached.id,
32
+ type: "walletconnect",
33
+ platforms: [],
34
+ name: cached.name,
35
+ icon: "",
36
+ isConnected: cached.isConnected,
37
+ connect: throwPending,
38
+ disconnect: throwPending
39
+ };
40
+ }
41
+ const { platform, identifier } = parseWalletId(cached.id);
42
+ return {
43
+ id: cached.id,
44
+ platform: cached.platform,
45
+ type: cached.type,
46
+ name: cached.name,
47
+ icon: lookupWalletIcon(platform, identifier),
48
+ isConnected: cached.isConnected,
49
+ connect: throwPending,
50
+ disconnect: throwPending
51
+ };
52
+ };
53
+ var hydrateAccount = (cached) => ({
54
+ id: cached.id,
55
+ platform: cached.platform,
56
+ address: cached.address,
57
+ name: cached.name,
58
+ walletId: cached.walletId,
59
+ walletName: cached.walletName,
60
+ // Spread (not direct keys) so the extra platform fields don't trip the
61
+ // excess-property check against BaseWalletAccount; they're read back via the
62
+ // platform-specific account types once narrowed by `platform`.
63
+ ...cached.platform === "ethereum" && { chainId: cached.chainId },
64
+ ...cached.platform === "polkadot" && {
65
+ type: cached.polkadotAccountType
66
+ }
67
+ });
68
+ var serializeWallet = (wallet) => ({
69
+ id: wallet.id,
70
+ // The WalletConnect connector has no platform.
71
+ platform: isWalletConnectWallet(wallet) ? void 0 : wallet.platform,
72
+ type: wallet.type,
73
+ name: wallet.name,
74
+ // Note: icon is NOT stored to save cookie space
75
+ isConnected: wallet.isConnected
76
+ });
77
+ var serializeAccount = (account) => ({
78
+ id: account.id,
79
+ platform: account.platform,
80
+ address: account.address,
81
+ name: account.name,
82
+ chainId: account.platform === "ethereum" ? account.chainId : void 0,
83
+ polkadotAccountType: account.platform === "polkadot" ? account.type : void 0,
84
+ walletId: account.walletId,
85
+ walletName: account.walletName
86
+ });
87
+
88
+ // src/utils/iconCache.ts
89
+ var ICON_CACHE_KEY = "kheopskit-icons";
90
+ var memoryCache = null;
91
+ var loadCache = () => {
92
+ if (memoryCache !== null) return memoryCache;
93
+ try {
94
+ const stored = safeLocalStorage.getItem(ICON_CACHE_KEY);
95
+ memoryCache = stored ? JSON.parse(stored) : {};
96
+ } catch {
97
+ memoryCache = {};
98
+ }
99
+ return memoryCache;
100
+ };
101
+ var saveCache = (cache) => {
102
+ try {
103
+ safeLocalStorage.setItem(ICON_CACHE_KEY, JSON.stringify(cache));
104
+ memoryCache = cache;
105
+ } catch {
106
+ }
107
+ };
108
+ var getCachedIcon = (walletId) => {
109
+ const cache = loadCache();
110
+ return cache[walletId] || void 0;
111
+ };
112
+ var setCachedIcons = (icons) => {
113
+ const cache = loadCache();
114
+ let changed = false;
115
+ for (const [walletId, icon] of Object.entries(icons)) {
116
+ if (icon && cache[walletId] !== icon) {
117
+ cache[walletId] = icon;
118
+ changed = true;
119
+ }
120
+ }
121
+ if (changed) {
122
+ saveCache(cache);
123
+ }
124
+ };
125
+
126
+ // src/utils/sortAccounts.ts
127
+ var PLATFORM_ORDER = {
128
+ polkadot: 0,
129
+ ethereum: 1,
130
+ solana: 2
131
+ };
132
+ var byWalletName = (a1, a2) => {
133
+ if (a1.walletName.toLowerCase() === "talisman") return -1;
134
+ if (a2.walletName.toLowerCase() === "talisman") return 1;
135
+ return a1.walletName.localeCompare(a2.walletName);
136
+ };
137
+ var sortAccounts = (a1, a2) => {
138
+ if (a1.platform !== a2.platform)
139
+ return PLATFORM_ORDER[a1.platform] - PLATFORM_ORDER[a2.platform];
140
+ if (a1.walletName !== a2.walletName) return byWalletName(a1, a2);
141
+ if (a1.platform === "polkadot" && a2.platform === "polkadot")
142
+ return a1.name !== a2.name ? (a1.name ?? "").localeCompare(a2.name ?? "") : a1.address.localeCompare(a2.address);
143
+ return a1.id.localeCompare(a2.id);
144
+ };
145
+
146
+ // src/utils/sortWallets.ts
147
+ var PLATFORM_ORDER2 = {
148
+ polkadot: 0,
149
+ ethereum: 1,
150
+ solana: 2
151
+ };
152
+ var orderOf = (wallet) => isWalletConnectWallet(wallet) ? 3 : PLATFORM_ORDER2[wallet.platform];
153
+ var sortWallets = (w1, w2) => {
154
+ const o1 = orderOf(w1);
155
+ const o2 = orderOf(w2);
156
+ if (o1 !== o2) return o1 - o2;
157
+ if (w1.name.toLowerCase() === "talisman") return -1;
158
+ if (w2.name.toLowerCase() === "talisman") return 1;
159
+ return w1.name.localeCompare(w2.name);
160
+ };
161
+
162
+ // src/api/platform.ts
163
+ var acceptsCachedAccount = (cached, platforms) => {
164
+ const plugin = platforms.find((p) => p.platform === cached.platform);
165
+ return plugin?.acceptsCachedAccount?.(cached) ?? true;
166
+ };
167
+
168
+ export {
169
+ hydrateWallet,
170
+ hydrateAccount,
171
+ serializeWallet,
172
+ serializeAccount,
173
+ getCachedIcon,
174
+ setCachedIcons,
175
+ sortAccounts,
176
+ sortWallets,
177
+ acceptsCachedAccount
178
+ };
179
+ //# sourceMappingURL=chunk-YDLCHYHH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/hydrateState.ts","../src/utils/iconCache.ts","../src/utils/sortAccounts.ts","../src/utils/sortWallets.ts","../src/api/platform.ts"],"sourcesContent":["import {\n\ttype BaseWallet,\n\ttype BaseWalletAccount,\n\ttype CachedAccount,\n\ttype CachedWallet,\n\tisWalletConnectWallet,\n\ttype PolkadotAccountType,\n\ttype WalletConnectWallet,\n} from \"../api/types\";\nimport { POLKADOT_EXTENSIONS } from \"./polkadotExtensions\";\nimport type { WalletAccountId } from \"./WalletAccountId\";\nimport { parseWalletId, type WalletId } from \"./WalletId\";\n\n/**\n * Looks up the icon for a wallet from known Polkadot extensions only.\n * Ethereum icons will be populated from the localStorage icon cache via the merge function.\n *\n * Note: We DON'T use localStorage icon cache here because hydrateWallet is called\n * during SSR (server) and client hydration. localStorage isn't available on server,\n * so using it would cause a hydration mismatch. Icons for Ethereum wallets will be\n * populated when the hydration buffer merges cached wallets with live wallets.\n */\nconst lookupWalletIcon = (platform: string, identifier: string): string => {\n\t// Only Polkadot extensions have hardcoded icons that are safe for SSR\n\tif (platform === \"polkadot\") {\n\t\treturn POLKADOT_EXTENSIONS[identifier]?.icon ?? \"\";\n\t}\n\t// Ethereum icons come from localStorage or live wallets - not here\n\treturn \"\";\n};\n\n/**\n * Error thrown when trying to use a placeholder wallet that hasn't fully loaded yet.\n */\nclass PendingWalletError extends Error {\n\tconstructor(walletId: string) {\n\t\tsuper(\n\t\t\t`Wallet ${walletId} is still loading. Wait for isHydrating to be false before calling connect/disconnect.`,\n\t\t);\n\t\tthis.name = \"PendingWalletError\";\n\t}\n}\n\n/**\n * Converts a CachedWallet to a placeholder wallet for SSR hydration display.\n *\n * The placeholder carries only the SDK-free {@link BaseWallet} fields; the real\n * wallet (with its injected provider/extension/standard-wallet handle) replaces\n * it once it loads. connect/disconnect throw until then.\n */\nexport const hydrateWallet = (\n\tcached: CachedWallet,\n): BaseWallet | WalletConnectWallet => {\n\tconst throwPending = () => {\n\t\tthrow new PendingWalletError(cached.id);\n\t};\n\n\t// The platform-less WalletConnect connector. `appKit`/`platforms` are SDK\n\t// state absent until the live connector loads (cast like other placeholder\n\t// SDK handles); icon is filled from the localStorage cache by the caller.\n\tif (cached.type === \"walletconnect\") {\n\t\treturn {\n\t\t\tid: cached.id,\n\t\t\ttype: \"walletconnect\",\n\t\t\tplatforms: [],\n\t\t\tname: cached.name,\n\t\t\ticon: \"\",\n\t\t\tisConnected: cached.isConnected,\n\t\t\tconnect: throwPending,\n\t\t\tdisconnect: throwPending,\n\t\t} as unknown as WalletConnectWallet;\n\t}\n\n\tconst { platform, identifier } = parseWalletId(cached.id);\n\n\treturn {\n\t\tid: cached.id,\n\t\tplatform: cached.platform as BaseWallet[\"platform\"],\n\t\ttype: cached.type,\n\t\tname: cached.name,\n\t\ticon: lookupWalletIcon(platform, identifier),\n\t\tisConnected: cached.isConnected,\n\t\tconnect: throwPending,\n\t\tdisconnect: throwPending,\n\t};\n};\n\n/**\n * Converts a CachedAccount to a placeholder account for SSR hydration display.\n *\n * The placeholder carries the SDK-free {@link BaseWalletAccount} fields plus the\n * plain, serializable platform data that lives in the cache — Ethereum `chainId`\n * and the Polkadot key `type`. Those render immediately on reload (no blank →\n * value flicker) and match what the live account will report. Only the SDK\n * handles (`client`/`signer`/`polkadotSigner`) are absent until the real account\n * replaces this placeholder; signing stays gated on `isHydrating` until then.\n */\nexport const hydrateAccount = (cached: CachedAccount): BaseWalletAccount => ({\n\tid: cached.id as WalletAccountId,\n\tplatform: cached.platform,\n\taddress: cached.address,\n\tname: cached.name,\n\twalletId: cached.walletId,\n\twalletName: cached.walletName,\n\t// Spread (not direct keys) so the extra platform fields don't trip the\n\t// excess-property check against BaseWalletAccount; they're read back via the\n\t// platform-specific account types once narrowed by `platform`.\n\t...(cached.platform === \"ethereum\" && { chainId: cached.chainId }),\n\t...(cached.platform === \"polkadot\" && {\n\t\ttype: cached.polkadotAccountType,\n\t}),\n});\n\n/**\n * Converts a wallet to a CachedWallet for storage.\n * Only extracts the serializable properties needed for hydration.\n */\nexport const serializeWallet = (\n\twallet: BaseWallet | WalletConnectWallet,\n): CachedWallet => ({\n\tid: wallet.id,\n\t// The WalletConnect connector has no platform.\n\tplatform: isWalletConnectWallet(wallet) ? undefined : wallet.platform,\n\ttype: wallet.type,\n\tname: wallet.name,\n\t// Note: icon is NOT stored to save cookie space\n\tisConnected: wallet.isConnected,\n});\n\n/**\n * Converts an account to a CachedAccount for storage.\n * Only extracts the serializable properties needed for hydration. Platform-only\n * fields (Ethereum chainId, Polkadot key type) are read defensively so this\n * stays SDK-free.\n */\nexport const serializeAccount = (\n\taccount: BaseWalletAccount,\n): CachedAccount => ({\n\tid: account.id,\n\tplatform: account.platform,\n\taddress: account.address,\n\tname: account.name,\n\tchainId:\n\t\taccount.platform === \"ethereum\"\n\t\t\t? (account as { chainId?: number }).chainId\n\t\t\t: undefined,\n\tpolkadotAccountType:\n\t\taccount.platform === \"polkadot\"\n\t\t\t? (account as { type?: PolkadotAccountType }).type\n\t\t\t: undefined,\n\twalletId: account.walletId as WalletId,\n\twalletName: account.walletName,\n});\n","import { safeLocalStorage } from \"./storage\";\n\n/**\n * Storage key for the icon cache in localStorage.\n */\nconst ICON_CACHE_KEY = \"kheopskit-icons\";\n\n/**\n * Icon cache type: a map of wallet ID to icon data URI or URL.\n */\ntype IconCache = Record<string, string>;\n\n/**\n * In-memory cache to avoid repeated localStorage reads.\n */\nlet memoryCache: IconCache | null = null;\n\n/**\n * Loads the icon cache from localStorage.\n */\nconst loadCache = (): IconCache => {\n\tif (memoryCache !== null) return memoryCache;\n\n\ttry {\n\t\tconst stored = safeLocalStorage.getItem(ICON_CACHE_KEY);\n\t\tmemoryCache = stored ? (JSON.parse(stored) as IconCache) : {};\n\t} catch {\n\t\tmemoryCache = {};\n\t}\n\treturn memoryCache;\n};\n\n/**\n * Saves the icon cache to localStorage.\n */\nconst saveCache = (cache: IconCache): void => {\n\ttry {\n\t\tsafeLocalStorage.setItem(ICON_CACHE_KEY, JSON.stringify(cache));\n\t\tmemoryCache = cache;\n\t} catch {\n\t\t// localStorage may be full or unavailable\n\t}\n};\n\n/**\n * Gets a cached icon for a wallet.\n * @param walletId - The wallet ID (e.g., \"ethereum:io.talisman\")\n * @returns The cached icon data URI, or undefined if not cached\n */\nexport const getCachedIcon = (walletId: string): string | undefined => {\n\tconst cache = loadCache();\n\treturn cache[walletId] || undefined;\n};\n\n/**\n * Sets multiple cached icons at once.\n * More efficient than calling setCachedIcon multiple times.\n * @param icons - Map of wallet ID to icon\n */\nexport const setCachedIcons = (icons: Record<string, string>): void => {\n\tconst cache = loadCache();\n\tlet changed = false;\n\n\tfor (const [walletId, icon] of Object.entries(icons)) {\n\t\tif (icon && cache[walletId] !== icon) {\n\t\t\tcache[walletId] = icon;\n\t\t\tchanged = true;\n\t\t}\n\t}\n\n\tif (changed) {\n\t\tsaveCache(cache);\n\t}\n};\n","import type { BaseWalletAccount, WalletPlatform } from \"../api/types\";\n\nconst PLATFORM_ORDER: Record<WalletPlatform, number> = {\n\tpolkadot: 0,\n\tethereum: 1,\n\tsolana: 2,\n};\n\n// Group accounts by wallet, surfacing Talisman first (case-insensitive).\nconst byWalletName = (a1: BaseWalletAccount, a2: BaseWalletAccount) => {\n\tif (a1.walletName.toLowerCase() === \"talisman\") return -1;\n\tif (a2.walletName.toLowerCase() === \"talisman\") return 1;\n\treturn a1.walletName.localeCompare(a2.walletName);\n};\n\nexport const sortAccounts = (a1: BaseWalletAccount, a2: BaseWalletAccount) => {\n\t// Sort by platform first: polkadot, then ethereum, then solana\n\tif (a1.platform !== a2.platform)\n\t\treturn PLATFORM_ORDER[a1.platform] - PLATFORM_ORDER[a2.platform];\n\n\t// Then group by wallet name\n\tif (a1.walletName !== a2.walletName) return byWalletName(a1, a2);\n\n\t// Polkadot accounts expose a friendly name; fall back to address\n\tif (a1.platform === \"polkadot\" && a2.platform === \"polkadot\")\n\t\treturn a1.name !== a2.name\n\t\t\t? (a1.name ?? \"\").localeCompare(a2.name ?? \"\")\n\t\t\t: a1.address.localeCompare(a2.address);\n\n\t// Ethereum and Solana accounts disambiguate by id\n\treturn a1.id.localeCompare(a2.id);\n};\n","import {\n\ttype BaseWallet,\n\tisWalletConnectWallet,\n\ttype WalletConnectWallet,\n\ttype WalletPlatform,\n} from \"../api/types\";\n\nconst PLATFORM_ORDER: Record<WalletPlatform, number> = {\n\tpolkadot: 0,\n\tethereum: 1,\n\tsolana: 2,\n};\n\n// The platform-less WalletConnect connector sorts after all platform wallets.\nconst orderOf = (wallet: BaseWallet | WalletConnectWallet) =>\n\tisWalletConnectWallet(wallet) ? 3 : PLATFORM_ORDER[wallet.platform];\n\nexport const sortWallets = (\n\tw1: BaseWallet | WalletConnectWallet,\n\tw2: BaseWallet | WalletConnectWallet,\n) => {\n\t// Sort by platform first: polkadot, then ethereum, then solana, then WC\n\tconst o1 = orderOf(w1);\n\tconst o2 = orderOf(w2);\n\tif (o1 !== o2) return o1 - o2;\n\n\t// Sort by name, but Talisman first\n\tif (w1.name.toLowerCase() === \"talisman\") return -1;\n\tif (w2.name.toLowerCase() === \"talisman\") return 1;\n\n\treturn w1.name.localeCompare(w2.name);\n};\n","import type { CachedAccount, KheopskitPlatform } from \"./types\";\n\n/**\n * Whether a cached account should survive SSR hydration, per its platform\n * plugin's `acceptsCachedAccount` hook. Plugins without the hook (and platforms\n * with no enabled plugin) accept all — matching the pre-plugin behavior where\n * only Polkadot accounts were filtered (by key type).\n */\nexport const acceptsCachedAccount = (\n\tcached: CachedAccount,\n\tplatforms: readonly KheopskitPlatform[],\n): boolean => {\n\tconst plugin = platforms.find((p) => p.platform === cached.platform);\n\treturn plugin?.acceptsCachedAccount?.(cached) ?? true;\n};\n"],"mappings":"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","names":["PLATFORM_ORDER"]}
@@ -0,0 +1,61 @@
1
+ import { W as WalletAccountId, a as WalletId, K as KheopskitPlatform } from './types-C7V7DGlg.mjs';
2
+ export { b as WalletConnectWallet, i as isInjectedWallet, c as isWalletConnectWallet } from './types-C7V7DGlg.mjs';
3
+ import { WalletClient, CustomTransport, Account, EIP1193Provider } from 'viem';
4
+ import 'rxjs';
5
+
6
+ /**
7
+ * Returns true if `address` is a valid Ethereum address.
8
+ *
9
+ * Mirrors viem's `isAddress` (strict): the shape must be `0x` + 40 hex, and a
10
+ * mixed-case address must pass the EIP-55 checksum. All-lowercase addresses are
11
+ * accepted as non-checksummed.
12
+ */
13
+ declare const isEthereumAddress: (address: string) => boolean;
14
+
15
+ type EthereumInjectedWallet = {
16
+ platform: "ethereum";
17
+ type: "injected";
18
+ id: WalletId;
19
+ /**
20
+ * Stable identifier of the underlying wallet source. For Ethereum this is the
21
+ * EIP-6963 `rdns`. Named consistently across platforms (Solana: Wallet
22
+ * Standard name; Polkadot: extension identifier).
23
+ */
24
+ sourceId: string;
25
+ provider: EIP1193Provider;
26
+ name: string;
27
+ icon: string;
28
+ isConnected: boolean;
29
+ connect: () => Promise<void>;
30
+ disconnect: () => Promise<void>;
31
+ };
32
+ type EthereumWallet = EthereumInjectedWallet;
33
+ type EthereumAccount = {
34
+ id: WalletAccountId;
35
+ platform: "ethereum";
36
+ /**
37
+ * Signing surface for this account: a viem {@link WalletClient} bound to the
38
+ * wallet's provider (sign/send via viem actions). Per-platform signing
39
+ * surfaces differ — Solana exposes `signer`/`getSigner(chain)`, Polkadot
40
+ * exposes `polkadotSigner`. Absent while `state.isHydrating` is `true`.
41
+ */
42
+ client: WalletClient<CustomTransport, undefined, Account, undefined>;
43
+ address: `0x${string}`;
44
+ /** Current chain ID the wallet is connected to. `undefined` while loading or after provider disconnect. */
45
+ chainId: number | undefined;
46
+ walletName: string;
47
+ walletId: WalletId;
48
+ };
49
+
50
+ /**
51
+ * Ethereum platform plugin. Pass to `getKheopskit$({ platforms: [ethereum()] })`.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { ethereum } from "@kheopskit/core/ethereum";
56
+ * ethereum();
57
+ * ```
58
+ */
59
+ declare const ethereum: () => KheopskitPlatform<"ethereum", EthereumWallet, EthereumAccount>;
60
+
61
+ export { type EthereumAccount, type EthereumInjectedWallet, type EthereumWallet, ethereum, isEthereumAddress };
@@ -0,0 +1,61 @@
1
+ import { W as WalletAccountId, a as WalletId, K as KheopskitPlatform } from './types-C7V7DGlg.js';
2
+ export { b as WalletConnectWallet, i as isInjectedWallet, c as isWalletConnectWallet } from './types-C7V7DGlg.js';
3
+ import { WalletClient, CustomTransport, Account, EIP1193Provider } from 'viem';
4
+ import 'rxjs';
5
+
6
+ /**
7
+ * Returns true if `address` is a valid Ethereum address.
8
+ *
9
+ * Mirrors viem's `isAddress` (strict): the shape must be `0x` + 40 hex, and a
10
+ * mixed-case address must pass the EIP-55 checksum. All-lowercase addresses are
11
+ * accepted as non-checksummed.
12
+ */
13
+ declare const isEthereumAddress: (address: string) => boolean;
14
+
15
+ type EthereumInjectedWallet = {
16
+ platform: "ethereum";
17
+ type: "injected";
18
+ id: WalletId;
19
+ /**
20
+ * Stable identifier of the underlying wallet source. For Ethereum this is the
21
+ * EIP-6963 `rdns`. Named consistently across platforms (Solana: Wallet
22
+ * Standard name; Polkadot: extension identifier).
23
+ */
24
+ sourceId: string;
25
+ provider: EIP1193Provider;
26
+ name: string;
27
+ icon: string;
28
+ isConnected: boolean;
29
+ connect: () => Promise<void>;
30
+ disconnect: () => Promise<void>;
31
+ };
32
+ type EthereumWallet = EthereumInjectedWallet;
33
+ type EthereumAccount = {
34
+ id: WalletAccountId;
35
+ platform: "ethereum";
36
+ /**
37
+ * Signing surface for this account: a viem {@link WalletClient} bound to the
38
+ * wallet's provider (sign/send via viem actions). Per-platform signing
39
+ * surfaces differ — Solana exposes `signer`/`getSigner(chain)`, Polkadot
40
+ * exposes `polkadotSigner`. Absent while `state.isHydrating` is `true`.
41
+ */
42
+ client: WalletClient<CustomTransport, undefined, Account, undefined>;
43
+ address: `0x${string}`;
44
+ /** Current chain ID the wallet is connected to. `undefined` while loading or after provider disconnect. */
45
+ chainId: number | undefined;
46
+ walletName: string;
47
+ walletId: WalletId;
48
+ };
49
+
50
+ /**
51
+ * Ethereum platform plugin. Pass to `getKheopskit$({ platforms: [ethereum()] })`.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { ethereum } from "@kheopskit/core/ethereum";
56
+ * ethereum();
57
+ * ```
58
+ */
59
+ declare const ethereum: () => KheopskitPlatform<"ethereum", EthereumWallet, EthereumAccount>;
60
+
61
+ export { type EthereumAccount, type EthereumInjectedWallet, type EthereumWallet, ethereum, isEthereumAddress };
@@ -0,0 +1,351 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+ var _chunkXQWJM3KCjs = require('./chunk-XQWJM3KC.js');
7
+
8
+
9
+
10
+
11
+
12
+
13
+ var _chunk4ENHC7G4js = require('./chunk-4ENHC7G4.js');
14
+
15
+ // src/api/ethereum/accounts.ts
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ var _rxjs = require('rxjs');
26
+
27
+
28
+
29
+
30
+ var _viem = require('viem');
31
+ var normalizeEvmChainId = (value) => {
32
+ let raw = value;
33
+ if (typeof raw === "string" && raw.startsWith("eip155:")) {
34
+ raw = raw.slice("eip155:".length);
35
+ }
36
+ if (typeof raw === "bigint") {
37
+ return raw >= 0n ? Number(raw) : void 0;
38
+ }
39
+ if (typeof raw === "number") {
40
+ return Number.isInteger(raw) && raw >= 0 ? raw : void 0;
41
+ }
42
+ if (typeof raw === "string") {
43
+ const normalized = raw.trim().toLowerCase();
44
+ if (!normalized) return void 0;
45
+ const parsed = normalized.startsWith("0x") ? Number.parseInt(normalized, 16) : Number.parseInt(normalized, 10);
46
+ return Number.isNaN(parsed) ? void 0 : parsed;
47
+ }
48
+ return void 0;
49
+ };
50
+ var toCaipNetworkId = (value) => {
51
+ const chainId = normalizeEvmChainId(value);
52
+ return chainId === void 0 ? void 0 : `eip155:${chainId}`;
53
+ };
54
+ var getInjectedWalletAccounts$ = (wallet) => {
55
+ if (!wallet.isConnected) return _rxjs.of.call(void 0, []);
56
+ return _chunk4ENHC7G4js.getCachedObservable$.call(void 0,
57
+ `accounts:${wallet.id}`,
58
+ () => new (0, _rxjs.Observable)((subscriber) => {
59
+ const addresses$ = new (0, _rxjs.ReplaySubject)(1);
60
+ const chainId$ = new (0, _rxjs.ReplaySubject)(1);
61
+ const getAccount = (address, chainId) => {
62
+ const client = _viem.createWalletClient.call(void 0, {
63
+ account: address,
64
+ transport: _viem.custom.call(void 0, wallet.provider)
65
+ });
66
+ return {
67
+ id: _chunkXQWJM3KCjs.getWalletAccountId.call(void 0, wallet.id, address),
68
+ platform: "ethereum",
69
+ client,
70
+ address: _viem.getAddress.call(void 0, address),
71
+ chainId,
72
+ walletName: wallet.name,
73
+ walletId: wallet.id
74
+ };
75
+ };
76
+ const handleAccountsChanged = (addrs) => {
77
+ addresses$.next(addrs);
78
+ };
79
+ const handleChainChanged = (chainIdHex) => {
80
+ chainId$.next(normalizeEvmChainId(chainIdHex));
81
+ };
82
+ const handleDisconnect = () => {
83
+ chainId$.next(void 0);
84
+ };
85
+ wallet.provider.on("accountsChanged", handleAccountsChanged);
86
+ wallet.provider.on("chainChanged", handleChainChanged);
87
+ wallet.provider.on("disconnect", handleDisconnect);
88
+ wallet.provider.request({ method: "eth_accounts" }).then((addrs) => addresses$.next(addrs)).catch((err) => {
89
+ console.error("Failed to get accounts", err);
90
+ addresses$.next([]);
91
+ });
92
+ wallet.provider.request({ method: "eth_chainId" }).then(handleChainChanged).catch(() => chainId$.next(void 0));
93
+ const sub = _rxjs.combineLatest.call(void 0, [addresses$, chainId$]).pipe(
94
+ _rxjs.map.call(void 0,
95
+ ([addresses, chainId]) => addresses.map((addr) => getAccount(addr, chainId))
96
+ )
97
+ ).subscribe(subscriber);
98
+ return () => {
99
+ wallet.provider.removeListener(
100
+ "accountsChanged",
101
+ handleAccountsChanged
102
+ );
103
+ wallet.provider.removeListener("chainChanged", handleChainChanged);
104
+ wallet.provider.removeListener("disconnect", handleDisconnect);
105
+ sub.unsubscribe();
106
+ };
107
+ }).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }))
108
+ );
109
+ };
110
+ var wrapWalletConnectProvider = (provider, sessionTopic, caipNetworkId) => {
111
+ return new Proxy(provider, {
112
+ get(target, prop, receiver) {
113
+ if (prop !== "request") return Reflect.get(target, prop, receiver);
114
+ return (args) => {
115
+ if (!args || typeof args !== "object" || !args.method)
116
+ return target.request(args);
117
+ const next = { ...args };
118
+ if (next.topic === void 0) next.topic = sessionTopic;
119
+ if (next.chainId === void 0 && caipNetworkId !== void 0)
120
+ next.chainId = caipNetworkId;
121
+ return target.request(next);
122
+ };
123
+ }
124
+ });
125
+ };
126
+ var sameAddresses = (a, b) => a.length === b.length && a.every((addr, i) => addr === b[i]);
127
+ var getWalletConnectAccounts$ = (wallet) => {
128
+ const provider = wallet.appKit.getProvider("eip155");
129
+ if (!wallet.platforms.includes("ethereum") || !_optionalChain([provider, 'optionalAccess', _ => _.session]))
130
+ return _rxjs.of.call(void 0, []);
131
+ return _chunk4ENHC7G4js.getCachedObservable$.call(void 0,
132
+ `accounts:${wallet.id}:ethereum:`,
133
+ () => new (0, _rxjs.Observable)((subscriber) => {
134
+ const caipNetworkId$ = new (0, _rxjs.ReplaySubject)(1);
135
+ const addresses$ = new (0, _rxjs.ReplaySubject)(1);
136
+ const readAddresses = () => {
137
+ const session = provider.session;
138
+ if (!session) return [];
139
+ const addresses = /* @__PURE__ */ new Set();
140
+ for (const namespace of Object.values(session.namespaces)) {
141
+ for (const account of _nullishCoalesce(namespace.accounts, () => ( []))) {
142
+ if (!account.startsWith("eip155:")) continue;
143
+ const raw = account.split(":")[2];
144
+ if (!raw) continue;
145
+ try {
146
+ addresses.add(_viem.getAddress.call(void 0, raw));
147
+ } catch (e) {
148
+ }
149
+ }
150
+ }
151
+ return [...addresses];
152
+ };
153
+ const readCaipNetworkId = () => {
154
+ const session = provider.session;
155
+ if (!session) return void 0;
156
+ for (const namespace of Object.values(session.namespaces)) {
157
+ for (const account of _nullishCoalesce(namespace.accounts, () => ( []))) {
158
+ if (!account.startsWith("eip155:")) continue;
159
+ const ref = account.split(":")[1];
160
+ if (ref) return `eip155:${ref}`;
161
+ }
162
+ }
163
+ return void 0;
164
+ };
165
+ const handleChainChanged = (chainId) => {
166
+ const caipNetworkId = toCaipNetworkId(chainId);
167
+ if (caipNetworkId) {
168
+ caipNetworkId$.next(caipNetworkId);
169
+ }
170
+ };
171
+ const handleAccountsChanged = () => addresses$.next(readAddresses());
172
+ provider.on("chainChanged", handleChainChanged);
173
+ provider.on("accountsChanged", handleAccountsChanged);
174
+ provider.on("session_update", handleAccountsChanged);
175
+ caipNetworkId$.next(readCaipNetworkId());
176
+ provider.request({ method: "eth_chainId" }).then(handleChainChanged).catch(() => {
177
+ });
178
+ addresses$.next(readAddresses());
179
+ const sub = _rxjs.combineLatest.call(void 0, [
180
+ caipNetworkId$.pipe(_rxjs.distinctUntilChanged.call(void 0, )),
181
+ addresses$.pipe(_rxjs.distinctUntilChanged.call(void 0, sameAddresses))
182
+ ]).pipe(
183
+ _rxjs.map.call(void 0, ([caipNetworkId, addresses]) => {
184
+ const chainId = normalizeEvmChainId(caipNetworkId);
185
+ const transport = _viem.custom.call(void 0,
186
+ wrapWalletConnectProvider(
187
+ provider,
188
+ // biome-ignore lint/style/noNonNullAssertion: legacy
189
+ provider.session.topic,
190
+ caipNetworkId
191
+ )
192
+ );
193
+ return addresses.map((addr) => {
194
+ const client = _viem.createWalletClient.call(void 0, {
195
+ account: addr,
196
+ transport
197
+ });
198
+ return {
199
+ id: _chunkXQWJM3KCjs.getWalletAccountId.call(void 0, wallet.id, addr),
200
+ platform: "ethereum",
201
+ walletName: wallet.name,
202
+ walletId: wallet.id,
203
+ address: addr,
204
+ client,
205
+ chainId
206
+ };
207
+ });
208
+ })
209
+ ).subscribe(subscriber);
210
+ return () => {
211
+ provider.off("chainChanged", handleChainChanged);
212
+ provider.off("accountsChanged", handleAccountsChanged);
213
+ provider.off("session_update", handleAccountsChanged);
214
+ sub.unsubscribe();
215
+ };
216
+ }).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }))
217
+ );
218
+ };
219
+ var getEthereumAccounts$ = (ethereumWallets) => new (0, _rxjs.Observable)((subscriber) => {
220
+ const sub = ethereumWallets.pipe(
221
+ _rxjs.map.call(void 0, (wallets) => wallets.filter((w) => w.isConnected)),
222
+ _rxjs.switchMap.call(void 0, (wallets) => {
223
+ return wallets.length ? _rxjs.combineLatest.call(void 0, [
224
+ ...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$),
225
+ ...wallets.filter(_chunk4ENHC7G4js.isWalletConnectWallet).map(getWalletConnectAccounts$)
226
+ ]) : _rxjs.of.call(void 0, []);
227
+ }),
228
+ _rxjs.map.call(void 0, (accounts) => accounts.flat()),
229
+ _rxjs.distinctUntilChanged.call(void 0, isSameAccountsList)
230
+ ).subscribe(subscriber);
231
+ return () => {
232
+ sub.unsubscribe();
233
+ };
234
+ }).pipe(
235
+ // logObservable("ethereumAccounts$", true),
236
+ _rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 })
237
+ );
238
+ var isSameAccountsList = (a, b) => {
239
+ if (a.length !== b.length) return false;
240
+ return a.every(
241
+ (account, i) => account.id === _optionalChain([b, 'access', _2 => _2[i], 'optionalAccess', _3 => _3.id]) && account.chainId === _optionalChain([b, 'access', _4 => _4[i], 'optionalAccess', _5 => _5.chainId])
242
+ );
243
+ };
244
+
245
+ // src/api/ethereum/wallets.ts
246
+
247
+
248
+ var _mipd = require('mipd');
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+ var providersDetails$ = new (0, _rxjs.Observable)(
258
+ (subscriber) => {
259
+ if (typeof window === "undefined") {
260
+ subscriber.next([]);
261
+ return () => {
262
+ };
263
+ }
264
+ const mipdStore = _mipd.createStore.call(void 0, );
265
+ const unsubscribe = mipdStore.subscribe((providerDetails2) => {
266
+ subscriber.next(providerDetails2);
267
+ });
268
+ const providerDetails = mipdStore.getProviders();
269
+ subscriber.next(providerDetails);
270
+ return () => {
271
+ unsubscribe();
272
+ mipdStore.destroy();
273
+ };
274
+ }
275
+ ).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }));
276
+ var createEthereumInjectedWallets$ = (store2) => new (0, _rxjs.Observable)((subscriber) => {
277
+ const enabledWalletIds$ = new (0, _rxjs.BehaviorSubject)(/* @__PURE__ */ new Set());
278
+ const connectWallet = async (walletId, provider) => {
279
+ if (enabledWalletIds$.value.has(walletId))
280
+ throw new (0, _chunkXQWJM3KCjs.KheopskitError)(
281
+ "WALLET_ALREADY_CONNECTED",
282
+ `wallet ${walletId} is already connected`,
283
+ { walletId }
284
+ );
285
+ await provider.request({
286
+ method: "eth_requestAccounts"
287
+ });
288
+ const newSet = new Set(enabledWalletIds$.value);
289
+ newSet.add(walletId);
290
+ enabledWalletIds$.next(newSet);
291
+ store2.addEnabledWalletId(walletId);
292
+ };
293
+ const disconnectWallet = async (walletId) => {
294
+ if (!enabledWalletIds$.value.has(walletId))
295
+ throw new (0, _chunkXQWJM3KCjs.KheopskitError)(
296
+ "WALLET_NOT_CONNECTED",
297
+ `wallet ${walletId} is not connected`,
298
+ { walletId }
299
+ );
300
+ const newSet = new Set(enabledWalletIds$.value);
301
+ newSet.delete(walletId);
302
+ enabledWalletIds$.next(newSet);
303
+ store2.removeEnabledWalletId(walletId);
304
+ _chunk4ENHC7G4js.clearCachedObservable.call(void 0, `accounts:${walletId}`);
305
+ };
306
+ const sub = _rxjs.combineLatest.call(void 0, [providersDetails$, enabledWalletIds$]).pipe(
307
+ _rxjs.map.call(void 0, ([providerDetails, enabledWalletIds]) => {
308
+ return providerDetails.map((pd) => {
309
+ const walletId = _chunk4ENHC7G4js.getWalletId.call(void 0, "ethereum", pd.info.rdns);
310
+ const provider = pd.provider;
311
+ return {
312
+ platform: "ethereum",
313
+ type: "injected",
314
+ id: walletId,
315
+ name: pd.info.name,
316
+ icon: pd.info.icon,
317
+ provider,
318
+ isConnected: enabledWalletIds.has(walletId),
319
+ sourceId: pd.info.rdns,
320
+ connect: () => connectWallet(walletId, provider),
321
+ disconnect: () => disconnectWallet(walletId)
322
+ };
323
+ });
324
+ }),
325
+ _rxjs.distinctUntilChanged.call(void 0, walletsEqual)
326
+ ).subscribe(subscriber);
327
+ return () => {
328
+ sub.unsubscribe();
329
+ };
330
+ }).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }));
331
+ var getEthereumWallets$ = (store2 = _chunkXQWJM3KCjs.store) => createEthereumInjectedWallets$(store2);
332
+ var walletsEqual = (a, b) => {
333
+ if (a.length !== b.length) return false;
334
+ return a.every(
335
+ (w, i) => w.id === _optionalChain([b, 'access', _6 => _6[i], 'optionalAccess', _7 => _7.id]) && w.isConnected === _optionalChain([b, 'access', _8 => _8[i], 'optionalAccess', _9 => _9.isConnected]) && w.name === _optionalChain([b, 'access', _10 => _10[i], 'optionalAccess', _11 => _11.name])
336
+ );
337
+ };
338
+
339
+ // src/api/ethereum/plugin.ts
340
+ var ethereum = () => ({
341
+ platform: "ethereum",
342
+ getWallets$: (ctx) => getEthereumWallets$(ctx.store),
343
+ getAccounts$: (wallets$) => getEthereumAccounts$(wallets$)
344
+ });
345
+
346
+
347
+
348
+
349
+
350
+ exports.ethereum = ethereum; exports.isEthereumAddress = _chunkXQWJM3KCjs.isEthereumAddress; exports.isInjectedWallet = _chunk4ENHC7G4js.isInjectedWallet; exports.isWalletConnectWallet = _chunk4ENHC7G4js.isWalletConnectWallet;
351
+ //# sourceMappingURL=ethereum.js.map