@kheopskit/core 5.0.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/{chunk-7QSGAJ4A.mjs → chunk-3Y5N4N3Q.mjs} +119 -62
  2. package/dist/chunk-3Y5N4N3Q.mjs.map +1 -0
  3. package/dist/chunk-DF7EKK4G.mjs +106 -0
  4. package/dist/chunk-DF7EKK4G.mjs.map +1 -0
  5. package/dist/chunk-EH73P476.js +106 -0
  6. package/dist/chunk-EH73P476.js.map +1 -0
  7. package/dist/chunk-JVSCMJY5.mjs +147 -0
  8. package/dist/chunk-JVSCMJY5.mjs.map +1 -0
  9. package/dist/chunk-P7BPHHVV.js +76 -0
  10. package/dist/chunk-P7BPHHVV.js.map +1 -0
  11. package/dist/{chunk-4ENHC7G4.js → chunk-SO64R7Z6.js} +114 -57
  12. package/dist/chunk-SO64R7Z6.js.map +1 -0
  13. package/dist/chunk-WOPCW2OX.mjs +76 -0
  14. package/dist/chunk-WOPCW2OX.mjs.map +1 -0
  15. package/dist/chunk-XOGQMEV2.js +147 -0
  16. package/dist/chunk-XOGQMEV2.js.map +1 -0
  17. package/dist/ethereum.d.mts +2 -2
  18. package/dist/ethereum.d.ts +2 -2
  19. package/dist/ethereum.js +55 -115
  20. package/dist/ethereum.js.map +1 -1
  21. package/dist/ethereum.mjs +55 -115
  22. package/dist/ethereum.mjs.map +1 -1
  23. package/dist/index.d.mts +59 -3
  24. package/dist/index.d.ts +59 -3
  25. package/dist/index.js +442 -61
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +429 -48
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/internal.d.mts +2 -39
  30. package/dist/internal.d.ts +2 -39
  31. package/dist/internal.js +3 -15
  32. package/dist/internal.js.map +1 -1
  33. package/dist/internal.mjs +6 -18
  34. package/dist/polkadot.d.mts +2 -2
  35. package/dist/polkadot.d.ts +2 -2
  36. package/dist/polkadot.js +75 -148
  37. package/dist/polkadot.js.map +1 -1
  38. package/dist/polkadot.mjs +76 -149
  39. package/dist/polkadot.mjs.map +1 -1
  40. package/dist/solana.d.mts +2 -2
  41. package/dist/solana.d.ts +2 -2
  42. package/dist/solana.js +90 -158
  43. package/dist/solana.js.map +1 -1
  44. package/dist/solana.mjs +86 -154
  45. package/dist/solana.mjs.map +1 -1
  46. package/dist/{types-C7V7DGlg.d.ts → types-0iDBydsK.d.mts} +24 -46
  47. package/dist/{types-C7V7DGlg.d.mts → types-0iDBydsK.d.ts} +24 -46
  48. package/package.json +1 -1
  49. package/dist/chunk-4ENHC7G4.js.map +0 -1
  50. package/dist/chunk-6XAZANB5.mjs +0 -450
  51. package/dist/chunk-6XAZANB5.mjs.map +0 -1
  52. package/dist/chunk-7QSGAJ4A.mjs.map +0 -1
  53. package/dist/chunk-B4L6GAYD.js +0 -179
  54. package/dist/chunk-B4L6GAYD.js.map +0 -1
  55. package/dist/chunk-XQWJM3KC.js +0 -450
  56. package/dist/chunk-XQWJM3KC.js.map +0 -1
  57. package/dist/chunk-YDLCHYHH.mjs +0 -179
  58. package/dist/chunk-YDLCHYHH.mjs.map +0 -1
@@ -1,6 +1,10 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1
+ import {
2
+ POLKADOT_EXTENSIONS
3
+ } from "./chunk-BWUUHUDK.mjs";
4
+ import {
5
+ isWalletConnectWallet,
6
+ parseWalletId
7
+ } from "./chunk-WOPCW2OX.mjs";
4
8
 
5
9
  // src/utils/storage.ts
6
10
  var noopStorage = {
@@ -133,78 +137,131 @@ var cookieStorage = (initialCookies) => {
133
137
  };
134
138
  };
135
139
 
136
- // src/utils/isWalletPlatform.ts
137
- var isWalletPlatform = (platform) => typeof platform === "string" && ["polkadot", "ethereum", "solana"].includes(platform);
138
-
139
- // src/utils/WalletId.ts
140
- var WALLET_CONNECT_WALLET_ID = "walletconnect";
141
- var getWalletId = (platform, identifier) => {
142
- if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
143
- if (!identifier) throw new Error("Invalid name");
144
- return `${platform}:${identifier}`;
140
+ // src/utils/hydrateState.ts
141
+ var lookupWalletIcon = (platform, identifier) => {
142
+ if (platform === "polkadot") {
143
+ return POLKADOT_EXTENSIONS[identifier]?.icon ?? "";
144
+ }
145
+ return "";
145
146
  };
146
- var parseWalletId = (walletId) => {
147
- if (!walletId) throw new Error("Invalid walletId");
148
- const [platform, identifier] = walletId.split(":");
149
- if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
150
- if (!identifier) throw new Error("Invalid address");
151
- return { platform, identifier };
147
+ var PendingWalletError = class extends Error {
148
+ constructor(walletId) {
149
+ super(
150
+ `Wallet ${walletId} is still loading. Wait for isHydrating to be false before calling connect/disconnect.`
151
+ );
152
+ this.name = "PendingWalletError";
153
+ }
152
154
  };
153
- var isValidWalletId = (walletId) => {
154
- if (typeof walletId !== "string" || !walletId) return false;
155
- if (walletId === WALLET_CONNECT_WALLET_ID) return true;
156
- const [platform, identifier] = walletId.split(":");
157
- return isWalletPlatform(platform) && !!identifier;
155
+ var hydrateWallet = (cached) => {
156
+ const throwPending = () => {
157
+ throw new PendingWalletError(cached.id);
158
+ };
159
+ if (cached.type === "walletconnect") {
160
+ return {
161
+ id: cached.id,
162
+ type: "walletconnect",
163
+ platforms: [],
164
+ name: cached.name,
165
+ icon: "",
166
+ isConnected: cached.isConnected,
167
+ connect: throwPending,
168
+ disconnect: throwPending
169
+ };
170
+ }
171
+ const { platform, identifier } = parseWalletId(cached.id);
172
+ return {
173
+ id: cached.id,
174
+ platform: cached.platform,
175
+ type: cached.type,
176
+ name: cached.name,
177
+ icon: lookupWalletIcon(platform, identifier),
178
+ isConnected: cached.isConnected,
179
+ connect: throwPending,
180
+ disconnect: throwPending
181
+ };
158
182
  };
183
+ var hydrateAccount = (cached) => ({
184
+ id: cached.id,
185
+ platform: cached.platform,
186
+ address: cached.address,
187
+ name: cached.name,
188
+ walletId: cached.walletId,
189
+ walletName: cached.walletName,
190
+ // Spread (not direct keys) so the extra platform fields don't trip the
191
+ // excess-property check against BaseWalletAccount; they're read back via the
192
+ // platform-specific account types once narrowed by `platform`.
193
+ ...cached.platform === "ethereum" && { chainId: cached.chainId },
194
+ ...cached.platform === "polkadot" && {
195
+ type: cached.polkadotAccountType
196
+ }
197
+ });
198
+ var serializeWallet = (wallet) => ({
199
+ id: wallet.id,
200
+ // The WalletConnect connector has no platform.
201
+ platform: isWalletConnectWallet(wallet) ? void 0 : wallet.platform,
202
+ type: wallet.type,
203
+ name: wallet.name,
204
+ // Note: icon is NOT stored to save cookie space
205
+ isConnected: wallet.isConnected
206
+ });
207
+ var serializeAccount = (account) => ({
208
+ id: account.id,
209
+ platform: account.platform,
210
+ address: account.address,
211
+ name: account.name,
212
+ chainId: account.platform === "ethereum" ? account.chainId : void 0,
213
+ polkadotAccountType: account.platform === "polkadot" ? account.type : void 0,
214
+ walletId: account.walletId,
215
+ walletName: account.walletName
216
+ });
159
217
 
160
- // src/utils/getCachedObservable.ts
161
- var CACHE_SYMBOL = /* @__PURE__ */ Symbol.for("kheopskit.observableCache");
162
- var getCache = () => {
163
- const g = globalThis;
164
- let cache = g[CACHE_SYMBOL];
165
- if (!cache) {
166
- cache = /* @__PURE__ */ new Map();
167
- g[CACHE_SYMBOL] = cache;
218
+ // src/utils/iconCache.ts
219
+ var ICON_CACHE_KEY = "kheopskit-icons";
220
+ var memoryCache = null;
221
+ var loadCache = () => {
222
+ if (memoryCache !== null) return memoryCache;
223
+ try {
224
+ const stored = safeLocalStorage.getItem(ICON_CACHE_KEY);
225
+ memoryCache = stored ? JSON.parse(stored) : {};
226
+ } catch {
227
+ memoryCache = {};
168
228
  }
169
- return cache;
229
+ return memoryCache;
170
230
  };
171
- var getCachedObservable$ = (key, create) => {
172
- const cache = getCache();
173
- if (!cache.has(key)) cache.set(key, create());
174
- return cache.get(key);
231
+ var saveCache = (cache) => {
232
+ try {
233
+ safeLocalStorage.setItem(ICON_CACHE_KEY, JSON.stringify(cache));
234
+ memoryCache = cache;
235
+ } catch {
236
+ }
175
237
  };
176
- var clearCachedObservable = (key) => {
177
- getCache().delete(key);
238
+ var getCachedIcon = (walletId) => {
239
+ const cache = loadCache();
240
+ return cache[walletId] || void 0;
178
241
  };
179
- var clearCachedObservablesByPrefix = (prefix) => {
180
- const cache = getCache();
181
- for (const key of cache.keys()) {
182
- if (key.startsWith(prefix)) cache.delete(key);
242
+ var setCachedIcons = (icons) => {
243
+ const cache = loadCache();
244
+ let changed = false;
245
+ for (const [walletId, icon] of Object.entries(icons)) {
246
+ if (icon && cache[walletId] !== icon) {
247
+ cache[walletId] = icon;
248
+ changed = true;
249
+ }
250
+ }
251
+ if (changed) {
252
+ saveCache(cache);
183
253
  }
184
- };
185
- var clearAllCachedObservables = () => {
186
- getCache().clear();
187
254
  };
188
255
 
189
- // src/api/types.ts
190
- var isWalletConnectWallet = (wallet) => wallet.type === "walletconnect";
191
- var isInjectedWallet = (wallet) => wallet.type === "injected";
192
-
193
256
  export {
194
- __publicField,
195
257
  getSafeLocalStorage,
196
258
  safeLocalStorage,
197
259
  cookieStorage,
198
- isWalletPlatform,
199
- WALLET_CONNECT_WALLET_ID,
200
- getWalletId,
201
- parseWalletId,
202
- isValidWalletId,
203
- getCachedObservable$,
204
- clearCachedObservable,
205
- clearCachedObservablesByPrefix,
206
- clearAllCachedObservables,
207
- isWalletConnectWallet,
208
- isInjectedWallet
260
+ hydrateWallet,
261
+ hydrateAccount,
262
+ serializeWallet,
263
+ serializeAccount,
264
+ getCachedIcon,
265
+ setCachedIcons
209
266
  };
210
- //# sourceMappingURL=chunk-7QSGAJ4A.mjs.map
267
+ //# sourceMappingURL=chunk-3Y5N4N3Q.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/storage.ts","../src/utils/hydrateState.ts","../src/utils/iconCache.ts"],"sourcesContent":["export type Storage = {\n\tgetItem: (key: string) => string | null;\n\tsetItem: (key: string, value: string) => void;\n\tremoveItem: (key: string) => void;\n};\n\n/**\n * Extended storage interface with cross-tab sync support.\n */\nexport type SyncableStorage = Storage & {\n\t/**\n\t * Subscribe to storage changes from other tabs.\n\t * Returns an unsubscribe function.\n\t */\n\tsubscribe?: (\n\t\tkey: string,\n\t\tcallback: (value: string | null) => void,\n\t) => () => void;\n};\n\n/**\n * A no-op storage implementation that does nothing.\n * Useful for testing or SSR environments where no storage is needed.\n */\nexport const noopStorage: SyncableStorage = {\n\tgetItem: () => null,\n\tsetItem: () => {},\n\tremoveItem: () => {},\n};\n\n/**\n * Cached localStorage wrapper instance.\n * Lazily initialized on first access to avoid SSR issues.\n */\nlet _safeLocalStorage: SyncableStorage | null = null;\n\n/**\n * Creates the localStorage wrapper, testing for availability.\n * Returns noopStorage if localStorage is unavailable (SSR, private browsing, etc.)\n */\nconst createSafeLocalStorage = (): SyncableStorage => {\n\tif (typeof window === \"undefined\") return noopStorage;\n\n\ttry {\n\t\t// Test that localStorage is accessible (may throw in private browsing)\n\t\tconst testKey = \"__kheopskit_test__\";\n\t\twindow.localStorage.setItem(testKey, testKey);\n\t\twindow.localStorage.removeItem(testKey);\n\n\t\treturn {\n\t\t\tgetItem: (key: string) => window.localStorage.getItem(key),\n\t\t\tsetItem: (key: string, value: string) =>\n\t\t\t\twindow.localStorage.setItem(key, value),\n\t\t\tremoveItem: (key: string) => window.localStorage.removeItem(key),\n\t\t\tsubscribe: (key: string, callback: (value: string | null) => void) => {\n\t\t\t\tconst handler = (event: StorageEvent) => {\n\t\t\t\t\tif (event.key === key) {\n\t\t\t\t\t\tcallback(event.newValue);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\twindow.addEventListener(\"storage\", handler);\n\t\t\t\treturn () => window.removeEventListener(\"storage\", handler);\n\t\t\t},\n\t\t};\n\t} catch {\n\t\treturn noopStorage;\n\t}\n};\n\n/**\n * A safe localStorage wrapper that falls back to noopStorage\n * when localStorage is not available (e.g., during SSR).\n * Includes cross-tab sync via the native 'storage' event.\n *\n * Lazily initialized on first access to be SSR-safe.\n */\nexport const getSafeLocalStorage = (): SyncableStorage => {\n\tif (_safeLocalStorage === null) {\n\t\t_safeLocalStorage = createSafeLocalStorage();\n\t}\n\treturn _safeLocalStorage;\n};\n\n/**\n * @deprecated Use getSafeLocalStorage() instead. This is kept for backward compatibility.\n * Returns a proxy that lazily initializes on first method call.\n */\nexport const safeLocalStorage: SyncableStorage = {\n\tgetItem: (key: string) => getSafeLocalStorage().getItem(key),\n\tsetItem: (key: string, value: string) =>\n\t\tgetSafeLocalStorage().setItem(key, value),\n\tremoveItem: (key: string) => getSafeLocalStorage().removeItem(key),\n\tsubscribe: (key: string, callback: (value: string | null) => void) => {\n\t\tconst storage = getSafeLocalStorage();\n\t\treturn storage.subscribe?.(key, callback) ?? (() => {});\n\t},\n};\n\n/**\n * Parse a cookie string to extract the value for a specific key.\n * @param cookieString - The full cookie header string (e.g., document.cookie or req.headers.cookie)\n * @param key - The cookie key to find\n * @returns The cookie value or null if not found\n */\nexport const parseCookie = (\n\tcookieString: string | undefined,\n\tkey: string,\n): string | null => {\n\tif (!cookieString) return null;\n\n\tfor (const cookie of cookieString.split(\";\")) {\n\t\tconst [k, ...v] = cookie.split(\"=\");\n\t\tconst cookieKey = k?.trim();\n\t\tif (cookieKey === key) {\n\t\t\ttry {\n\t\t\t\treturn decodeURIComponent(v.join(\"=\").trim());\n\t\t\t} catch {\n\t\t\t\treturn null; // Malformed cookie value\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n};\n\n/**\n * Maximum recommended size for cookie storage (3KB to stay well under 4KB limit).\n *\n * @remarks\n * Cookie storage is subject to browser limits (typically 4KB per cookie).\n * When users connect many wallets, the auto-reconnect list may exceed this limit.\n * If this happens:\n * - A console warning will be logged\n * - Some browsers may silently reject the cookie\n * - Consider using fewer simultaneous wallet connections\n *\n * The stored data includes wallet IDs in format `platform:identifier`\n * (e.g., `polkadot:talisman`, `ethereum:io.metamask`).\n */\nexport const COOKIE_MAX_SIZE = 3 * 1024;\n\n/**\n * BroadcastChannel name for cross-tab cookie sync.\n */\nconst BROADCAST_CHANNEL_NAME = \"kheopskit-storage-sync\";\n\n/**\n * Singleton BroadcastChannel for cross-tab cookie sync.\n * Created once and shared across all cookieStorage instances.\n */\nlet sharedBroadcastChannel: BroadcastChannel | null = null;\n\nconst getBroadcastChannel = (): BroadcastChannel | null => {\n\tif (sharedBroadcastChannel) return sharedBroadcastChannel;\n\tif (typeof BroadcastChannel === \"undefined\") return null;\n\n\ttry {\n\t\tsharedBroadcastChannel = new BroadcastChannel(BROADCAST_CHANNEL_NAME);\n\t} catch {\n\t\t// BroadcastChannel not supported or failed\n\t}\n\treturn sharedBroadcastChannel;\n};\n\n/**\n * Check if the current connection is secure (HTTPS).\n * Must be called at runtime (inside methods) to work correctly after SSR hydration.\n */\nconst isSecureConnection = (): boolean =>\n\ttypeof window !== \"undefined\" && window.location.protocol === \"https:\";\n\n/**\n * A cookie-based storage implementation for SSR environments.\n * Reads cookies from an optional initial cookie string (for SSR hydration),\n * writes to document.cookie on the client.\n *\n * Features:\n * - Secure flag automatically added for HTTPS connections\n * - Cross-tab synchronization via BroadcastChannel API\n * - Size limit warning when data exceeds recommended limits\n *\n * @param initialCookies - Optional cookie string for server-side hydration\n */\nexport const cookieStorage = (initialCookies?: string): SyncableStorage => {\n\treturn {\n\t\tgetItem: (key: string) => {\n\t\t\t// On server, use initialCookies. On client, read from document.cookie\n\t\t\tconst cookieString =\n\t\t\t\ttypeof document !== \"undefined\" ? document.cookie : initialCookies;\n\t\t\treturn parseCookie(cookieString, key);\n\t\t},\n\t\tsetItem: (key: string, value: string) => {\n\t\t\tif (typeof document === \"undefined\") return;\n\n\t\t\t// Warn if value exceeds recommended size\n\t\t\tconst encodedValue = encodeURIComponent(value);\n\t\t\tif (encodedValue.length > COOKIE_MAX_SIZE) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[kheopskit] Cookie value for \"${key}\" exceeds recommended size limit (${encodedValue.length} > ${COOKIE_MAX_SIZE} bytes). ` +\n\t\t\t\t\t\t\"This may cause issues with cookie storage. Consider reducing the number of connected wallets.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Set cookie with 1 year expiry\n\t\t\tconst expires = new Date();\n\t\t\texpires.setFullYear(expires.getFullYear() + 1);\n\n\t\t\t// Build cookie string with security attributes\n\t\t\tlet cookieStr = `${key}=${encodedValue};expires=${expires.toUTCString()};path=/;SameSite=Lax`;\n\t\t\tif (isSecureConnection()) {\n\t\t\t\tcookieStr += \";Secure\";\n\t\t\t}\n\n\t\t\t// biome-ignore lint: necessary for cookie storage - direct cookie assignment is the standard API\n\t\t\tdocument.cookie = cookieStr;\n\n\t\t\t// Broadcast change to other tabs\n\t\t\tgetBroadcastChannel()?.postMessage({ type: \"set\", key, value });\n\t\t},\n\t\tremoveItem: (key: string) => {\n\t\t\tif (typeof document === \"undefined\") return;\n\n\t\t\t// Build delete cookie string\n\t\t\tlet cookieStr = `${key}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;SameSite=Lax`;\n\t\t\tif (isSecureConnection()) {\n\t\t\t\tcookieStr += \";Secure\";\n\t\t\t}\n\n\t\t\t// biome-ignore lint: necessary for cookie storage - direct cookie assignment is the standard API\n\t\t\tdocument.cookie = cookieStr;\n\n\t\t\t// Broadcast change to other tabs\n\t\t\tgetBroadcastChannel()?.postMessage({ type: \"remove\", key });\n\t\t},\n\t\tsubscribe: (key: string, callback: (value: string | null) => void) => {\n\t\t\tconst channel = getBroadcastChannel();\n\t\t\tif (!channel) return () => {};\n\n\t\t\tconst handler = (event: MessageEvent) => {\n\t\t\t\tconst data = event.data as {\n\t\t\t\t\ttype: string;\n\t\t\t\t\tkey: string;\n\t\t\t\t\tvalue?: string;\n\t\t\t\t};\n\t\t\t\tif (data.key === key) {\n\t\t\t\t\tif (data.type === \"set\") {\n\t\t\t\t\t\tcallback(data.value ?? null);\n\t\t\t\t\t} else if (data.type === \"remove\") {\n\t\t\t\t\t\tcallback(null);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tchannel.addEventListener(\"message\", handler);\n\t\t\treturn () => {\n\t\t\t\tchannel.removeEventListener(\"message\", handler);\n\t\t\t};\n\t\t},\n\t};\n};\n\n/**\n * Cleanup the shared BroadcastChannel used for cross-tab cookie sync.\n * Call this when you're done using cookie storage (e.g., in tests or when unmounting).\n *\n * @remarks\n * In normal browser usage, you typically don't need to call this -\n * the channel will be cleaned up when the page is closed.\n * This is primarily useful for testing environments where multiple\n * test runs may accumulate channels.\n */\nexport const cleanupBroadcastChannel = (): void => {\n\tif (sharedBroadcastChannel) {\n\t\tsharedBroadcastChannel.close();\n\t\tsharedBroadcastChannel = null;\n\t}\n};\n","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"],"mappings":";;;;;;;;;AAwBO,IAAM,cAA+B;AAAA,EAC3C,SAAS,MAAM;AAAA,EACf,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,YAAY,MAAM;AAAA,EAAC;AACpB;AAMA,IAAI,oBAA4C;AAMhD,IAAM,yBAAyB,MAAuB;AACrD,MAAI,OAAO,WAAW,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AAClC,MAAI,gBAAgB,KAAM,QAAO;AAEjC,MAAI;AACH,UAAM,SAAS,iBAAiB,QAAQ,cAAc;AACtD,kBAAc,SAAU,KAAK,MAAM,MAAM,IAAkB,CAAC;AAAA,EAC7D,QAAQ;AACP,kBAAc,CAAC;AAAA,EAChB;AACA,SAAO;AACR;AAKA,IAAM,YAAY,CAAC,UAA2B;AAC7C,MAAI;AACH,qBAAiB,QAAQ,gBAAgB,KAAK,UAAU,KAAK,CAAC;AAC9D,kBAAc;AAAA,EACf,QAAQ;AAAA,EAER;AACD;AAOO,IAAM,gBAAgB,CAAC,aAAyC;AACtE,QAAM,QAAQ,UAAU;AACxB,SAAO,MAAM,QAAQ,KAAK;AAC3B;AAOO,IAAM,iBAAiB,CAAC,UAAwC;AACtE,QAAM,QAAQ,UAAU;AACxB,MAAI,UAAU;AAEd,aAAW,CAAC,UAAU,IAAI,KAAK,OAAO,QAAQ,KAAK,GAAG;AACrD,QAAI,QAAQ,MAAM,QAAQ,MAAM,MAAM;AACrC,YAAM,QAAQ,IAAI;AAClB,gBAAU;AAAA,IACX;AAAA,EACD;AAEA,MAAI,SAAS;AACZ,cAAU,KAAK;AAAA,EAChB;AACD;","names":[]}
@@ -0,0 +1,106 @@
1
+ import {
2
+ __publicField
3
+ } from "./chunk-WOPCW2OX.mjs";
4
+
5
+ // src/utils/isEthereumAddress.ts
6
+ import { keccak_256 } from "@noble/hashes/sha3";
7
+ var HEX_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
8
+ var encoder = new TextEncoder();
9
+ var isChecksumValid = (address) => {
10
+ const hex = address.slice(2);
11
+ const hash = keccak_256(encoder.encode(hex.toLowerCase()));
12
+ for (let i = 0; i < 40; i++) {
13
+ const char = hex.charAt(i);
14
+ const isLetter = char >= "a" && char <= "f" || char >= "A" && char <= "F";
15
+ if (!isLetter) continue;
16
+ const byte = hash[i >> 1] ?? 0;
17
+ const nibble = i % 2 === 0 ? byte >> 4 : byte & 15;
18
+ const isUpper = char <= "F";
19
+ if (isUpper !== nibble >= 8) return false;
20
+ }
21
+ return true;
22
+ };
23
+ var isEthereumAddress = (address) => {
24
+ if (!HEX_ADDRESS.test(address)) return false;
25
+ if (address === address.toLowerCase()) return true;
26
+ return isChecksumValid(address);
27
+ };
28
+
29
+ // src/utils/isSolanaAddress.ts
30
+ import { base58 } from "@scure/base";
31
+ var isSolanaAddress = (address) => {
32
+ if (!address) return false;
33
+ try {
34
+ return base58.decode(address).length === 32;
35
+ } catch {
36
+ return false;
37
+ }
38
+ };
39
+
40
+ // src/utils/isSs58Address.ts
41
+ import { blake2b } from "@noble/hashes/blake2b";
42
+ import { base58 as base582 } from "@scure/base";
43
+ var SS58PRE = new Uint8Array([83, 83, 53, 56, 80, 82, 69]);
44
+ var isSs58Address = (address) => {
45
+ if (!address) return false;
46
+ let decoded;
47
+ try {
48
+ decoded = base582.decode(address);
49
+ } catch {
50
+ return false;
51
+ }
52
+ const firstByte = decoded[0];
53
+ if (firstByte === void 0 || firstByte & 128) return false;
54
+ const prefixLength = firstByte & 64 ? 2 : 1;
55
+ if (decoded.length !== prefixLength + 32 + 2) return false;
56
+ const body = decoded.subarray(0, decoded.length - 2);
57
+ const preimage = new Uint8Array(SS58PRE.length + body.length);
58
+ preimage.set(SS58PRE);
59
+ preimage.set(body, SS58PRE.length);
60
+ const hash = blake2b(preimage, { dkLen: 64 });
61
+ return decoded[decoded.length - 2] === hash[0] && decoded[decoded.length - 1] === hash[1];
62
+ };
63
+
64
+ // src/utils/isValidAddress.ts
65
+ var isValidAddress = (address) => {
66
+ if (address.startsWith("0x")) return isEthereumAddress(address);
67
+ return isSs58Address(address) || isSolanaAddress(address);
68
+ };
69
+
70
+ // src/utils/WalletAccountId.ts
71
+ var getWalletAccountId = (walletId, address) => {
72
+ if (!walletId) throw new Error("Missing walletId");
73
+ if (!isValidAddress(address)) throw new Error("Invalid address");
74
+ return `${walletId}::${address}`;
75
+ };
76
+ var parseWalletAccountId = (accountId) => {
77
+ if (!accountId) throw new Error("Invalid walletAccountId");
78
+ const [walletId, address] = accountId.split("::");
79
+ if (!walletId) throw new Error("Missing walletId");
80
+ if (!address || !isValidAddress(address)) throw new Error("Invalid address");
81
+ return { walletId, address };
82
+ };
83
+
84
+ // src/api/errors.ts
85
+ var KheopskitError = class extends Error {
86
+ constructor(code, message, options) {
87
+ super(`[kheopskit] ${message}`, { cause: options?.cause });
88
+ __publicField(this, "code");
89
+ /** The wallet id this error relates to, when applicable. */
90
+ __publicField(this, "walletId");
91
+ this.name = "KheopskitError";
92
+ this.code = code;
93
+ this.walletId = options?.walletId;
94
+ }
95
+ };
96
+
97
+ export {
98
+ isEthereumAddress,
99
+ isSolanaAddress,
100
+ isSs58Address,
101
+ isValidAddress,
102
+ getWalletAccountId,
103
+ parseWalletAccountId,
104
+ KheopskitError
105
+ };
106
+ //# sourceMappingURL=chunk-DF7EKK4G.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/isEthereumAddress.ts","../src/utils/isSolanaAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/WalletAccountId.ts","../src/api/errors.ts"],"sourcesContent":["import { keccak_256 } from \"@noble/hashes/sha3\";\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/blake2b\";\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 type { WalletId } from \"../utils/WalletId\";\n\n/**\n * Stable error codes thrown by kheopskit. Catch a {@link KheopskitError} and\n * branch on `error.code` instead of matching message strings.\n */\nexport type KheopskitErrorCode =\n\t/** `connect()` called on a wallet that is already connected. */\n\t| \"WALLET_ALREADY_CONNECTED\"\n\t/** `disconnect()` called on a wallet that is not connected. */\n\t| \"WALLET_NOT_CONNECTED\"\n\t/** The wallet does not advertise a capability kheopskit needs to proceed. */\n\t| \"FEATURE_NOT_SUPPORTED\"\n\t/** No active WalletConnect session for the requested operation. */\n\t| \"NO_SESSION\"\n\t/** No provider available for the requested namespace. */\n\t| \"NO_PROVIDER\"\n\t/** The requested chain cannot be used for this operation (e.g. a Solana cluster with no CAIP-2 id over WalletConnect). */\n\t| \"UNSUPPORTED_CHAIN\";\n\n/**\n * Error thrown by kheopskit wallet/account operations. Carries a stable\n * {@link KheopskitErrorCode} and, when relevant, the offending wallet id.\n *\n * @example\n * ```ts\n * try {\n * await wallet.connect();\n * } catch (error) {\n * if (error instanceof KheopskitError && error.code === \"WALLET_ALREADY_CONNECTED\") {\n * // ignore\n * } else throw error;\n * }\n * ```\n */\nexport class KheopskitError extends Error {\n\treadonly code: KheopskitErrorCode;\n\t/** The wallet id this error relates to, when applicable. */\n\treadonly walletId?: WalletId;\n\n\tconstructor(\n\t\tcode: KheopskitErrorCode,\n\t\tmessage: string,\n\t\toptions?: { walletId?: WalletId; cause?: unknown },\n\t) {\n\t\tsuper(`[kheopskit] ${message}`, { cause: options?.cause });\n\t\tthis.name = \"KheopskitError\";\n\t\tthis.code = code;\n\t\tthis.walletId = options?.walletId;\n\t}\n}\n"],"mappings":";;;;;AAAA,SAAS,kBAAkB;AAE3B,IAAM,cAAc;AACpB,IAAM,UAAU,IAAI,YAAY;AAMhC,IAAM,kBAAkB,CAAC,YAA6B;AACrD,QAAM,MAAM,QAAQ,MAAM,CAAC;AAC3B,QAAM,OAAO,WAAW,QAAQ,OAAO,IAAI,YAAY,CAAC,CAAC;AACzD,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AAC5B,UAAM,OAAO,IAAI,OAAO,CAAC;AACzB,UAAM,WACJ,QAAQ,OAAO,QAAQ,OAAS,QAAQ,OAAO,QAAQ;AACzD,QAAI,CAAC,SAAU;AACf,UAAM,OAAO,KAAK,KAAK,CAAC,KAAK;AAC7B,UAAM,SAAS,IAAI,MAAM,IAAI,QA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,KAAK,CAAC;AAExC;;;ACtCO,IAAM,iBAAiB,CAAC,YAA6B;AAC3D,MAAI,QAAQ,WAAW,IAAI,EAAG,QAAO,kBAAkB,OAAO;AAI9D,SAAO,cAAc,OAAO,KAAK,gBAAgB,OAAO;AACzD;;;ACNO,IAAM,qBAAqB,CACjC,UACA,YACqB;AACrB,MAAI,CAAC,SAAU,OAAM,IAAI,MAAM,kBAAkB;AACjD,MAAI,CAAC,eAAe,OAAO,EAAG,OAAM,IAAI,MAAM,iBAAiB;AAC/D,SAAO,GAAG,QAAQ,KAAK,OAAO;AAC/B;AAEO,IAAM,uBAAuB,CAAC,cAAsB;AAC1D,MAAI,CAAC,UAAW,OAAM,IAAI,MAAM,yBAAyB;AACzD,QAAM,CAAC,UAAU,OAAO,IAAI,UAAU,MAAM,IAAI;AAChD,MAAI,CAAC,SAAU,OAAM,IAAI,MAAM,kBAAkB;AACjD,MAAI,CAAC,WAAW,CAAC,eAAe,OAAO,EAAG,OAAM,IAAI,MAAM,iBAAiB;AAC3E,SAAO,EAAE,UAAU,QAAQ;AAC5B;;;ACgBO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAKzC,YACC,MACA,SACA,SACC;AACD,UAAM,eAAe,OAAO,IAAI,EAAE,OAAO,SAAS,MAAM,CAAC;AAT1D,wBAAS;AAET;AAAA,wBAAS;AAQR,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW,SAAS;AAAA,EAC1B;AACD;","names":["base58"]}
@@ -0,0 +1,106 @@
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
+ var _chunkP7BPHHVVjs = require('./chunk-P7BPHHVV.js');
4
+
5
+ // src/utils/isEthereumAddress.ts
6
+ var _sha3 = require('@noble/hashes/sha3');
7
+ var HEX_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
8
+ var encoder = new TextEncoder();
9
+ var isChecksumValid = (address) => {
10
+ const hex = address.slice(2);
11
+ const hash = _sha3.keccak_256.call(void 0, encoder.encode(hex.toLowerCase()));
12
+ for (let i = 0; i < 40; i++) {
13
+ const char = hex.charAt(i);
14
+ const isLetter = char >= "a" && char <= "f" || char >= "A" && char <= "F";
15
+ if (!isLetter) continue;
16
+ const byte = _nullishCoalesce(hash[i >> 1], () => ( 0));
17
+ const nibble = i % 2 === 0 ? byte >> 4 : byte & 15;
18
+ const isUpper = char <= "F";
19
+ if (isUpper !== nibble >= 8) return false;
20
+ }
21
+ return true;
22
+ };
23
+ var isEthereumAddress = (address) => {
24
+ if (!HEX_ADDRESS.test(address)) return false;
25
+ if (address === address.toLowerCase()) return true;
26
+ return isChecksumValid(address);
27
+ };
28
+
29
+ // src/utils/isSolanaAddress.ts
30
+ var _base = require('@scure/base');
31
+ var isSolanaAddress = (address) => {
32
+ if (!address) return false;
33
+ try {
34
+ return _base.base58.decode(address).length === 32;
35
+ } catch (e) {
36
+ return false;
37
+ }
38
+ };
39
+
40
+ // src/utils/isSs58Address.ts
41
+ var _blake2b = require('@noble/hashes/blake2b');
42
+
43
+ var SS58PRE = new Uint8Array([83, 83, 53, 56, 80, 82, 69]);
44
+ var isSs58Address = (address) => {
45
+ if (!address) return false;
46
+ let decoded;
47
+ try {
48
+ decoded = _base.base58.decode(address);
49
+ } catch (e2) {
50
+ return false;
51
+ }
52
+ const firstByte = decoded[0];
53
+ if (firstByte === void 0 || firstByte & 128) return false;
54
+ const prefixLength = firstByte & 64 ? 2 : 1;
55
+ if (decoded.length !== prefixLength + 32 + 2) return false;
56
+ const body = decoded.subarray(0, decoded.length - 2);
57
+ const preimage = new Uint8Array(SS58PRE.length + body.length);
58
+ preimage.set(SS58PRE);
59
+ preimage.set(body, SS58PRE.length);
60
+ const hash = _blake2b.blake2b.call(void 0, preimage, { dkLen: 64 });
61
+ return decoded[decoded.length - 2] === hash[0] && decoded[decoded.length - 1] === hash[1];
62
+ };
63
+
64
+ // src/utils/isValidAddress.ts
65
+ var isValidAddress = (address) => {
66
+ if (address.startsWith("0x")) return isEthereumAddress(address);
67
+ return isSs58Address(address) || isSolanaAddress(address);
68
+ };
69
+
70
+ // src/utils/WalletAccountId.ts
71
+ var getWalletAccountId = (walletId, address) => {
72
+ if (!walletId) throw new Error("Missing walletId");
73
+ if (!isValidAddress(address)) throw new Error("Invalid address");
74
+ return `${walletId}::${address}`;
75
+ };
76
+ var parseWalletAccountId = (accountId) => {
77
+ if (!accountId) throw new Error("Invalid walletAccountId");
78
+ const [walletId, address] = accountId.split("::");
79
+ if (!walletId) throw new Error("Missing walletId");
80
+ if (!address || !isValidAddress(address)) throw new Error("Invalid address");
81
+ return { walletId, address };
82
+ };
83
+
84
+ // src/api/errors.ts
85
+ var KheopskitError = class extends Error {
86
+ constructor(code, message, options) {
87
+ super(`[kheopskit] ${message}`, { cause: _optionalChain([options, 'optionalAccess', _ => _.cause]) });
88
+ _chunkP7BPHHVVjs.__publicField.call(void 0, this, "code");
89
+ /** The wallet id this error relates to, when applicable. */
90
+ _chunkP7BPHHVVjs.__publicField.call(void 0, this, "walletId");
91
+ this.name = "KheopskitError";
92
+ this.code = code;
93
+ this.walletId = _optionalChain([options, 'optionalAccess', _2 => _2.walletId]);
94
+ }
95
+ };
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+ exports.isEthereumAddress = isEthereumAddress; exports.isSolanaAddress = isSolanaAddress; exports.isSs58Address = isSs58Address; exports.isValidAddress = isValidAddress; exports.getWalletAccountId = getWalletAccountId; exports.parseWalletAccountId = parseWalletAccountId; exports.KheopskitError = KheopskitError;
106
+ //# sourceMappingURL=chunk-EH73P476.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/kheopskit/kheopskit/packages/core/dist/chunk-EH73P476.js","../src/utils/isEthereumAddress.ts","../src/utils/isSolanaAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/WalletAccountId.ts","../src/api/errors.ts"],"names":["base58"],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACJA,0CAA2B;AAE3B,IAAM,YAAA,EAAc,qBAAA;AACpB,IAAM,QAAA,EAAU,IAAI,WAAA,CAAY,CAAA;AAMhC,IAAM,gBAAA,EAAkB,CAAC,OAAA,EAAA,GAA6B;AACrD,EAAA,MAAM,IAAA,EAAM,OAAA,CAAQ,KAAA,CAAM,CAAC,CAAA;AAC3B,EAAA,MAAM,KAAA,EAAO,8BAAA,OAAW,CAAQ,MAAA,CAAO,GAAA,CAAI,WAAA,CAAY,CAAC,CAAC,CAAA;AACzD,EAAA,IAAA,CAAA,IAAS,EAAA,EAAI,CAAA,EAAG,EAAA,EAAI,EAAA,EAAI,CAAA,EAAA,EAAK;AAC5B,IAAA,MAAM,KAAA,EAAO,GAAA,CAAI,MAAA,CAAO,CAAC,CAAA;AACzB,IAAA,MAAM,SAAA,EACJ,KAAA,GAAQ,IAAA,GAAO,KAAA,GAAQ,IAAA,GAAS,KAAA,GAAQ,IAAA,GAAO,KAAA,GAAQ,GAAA;AACzD,IAAA,GAAA,CAAI,CAAC,QAAA,EAAU,QAAA;AACf,IAAA,MAAM,KAAA,mBAAO,IAAA,CAAK,EAAA,GAAK,CAAC,CAAA,UAAK,GAAA;AAC7B,IAAA,MAAM,OAAA,EAAS,EAAA,EAAI,EAAA,IAAM,EAAA,EAAI,KAAA,GAAQ,EAAA,EAAI,KAAA,EAAO,EAAA;AAChD,IAAA,MAAM,QAAA,EAAU,KAAA,GAAQ,GAAA;AACxB,IAAA,G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D,EAAA,GAAA,CAAI,CAAC,cAAA,CAAe,OAAO,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,iBAAiB,CAAA;AAC/D,EAAA,OAAO,CAAA,EAAA;AACR;AAEa;AACP,EAAA;AACE,EAAA;AACF,EAAA;AACA,EAAA;AACE,EAAA;AACR;AL+DU;AACA;AMhDG;AAKZ,EAAA;AAKO,IAAA;AATP,IAAA;AAEA;AAAA,IAAA;AAQM,IAAA;AACA,IAAA;AACA,IAAA;AACN,EAAA;AACD;AN6CU;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kheopskit/kheopskit/packages/core/dist/chunk-EH73P476.js","sourcesContent":[null,"import { keccak_256 } from \"@noble/hashes/sha3\";\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/blake2b\";\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 type { WalletId } from \"../utils/WalletId\";\n\n/**\n * Stable error codes thrown by kheopskit. Catch a {@link KheopskitError} and\n * branch on `error.code` instead of matching message strings.\n */\nexport type KheopskitErrorCode =\n\t/** `connect()` called on a wallet that is already connected. */\n\t| \"WALLET_ALREADY_CONNECTED\"\n\t/** `disconnect()` called on a wallet that is not connected. */\n\t| \"WALLET_NOT_CONNECTED\"\n\t/** The wallet does not advertise a capability kheopskit needs to proceed. */\n\t| \"FEATURE_NOT_SUPPORTED\"\n\t/** No active WalletConnect session for the requested operation. */\n\t| \"NO_SESSION\"\n\t/** No provider available for the requested namespace. */\n\t| \"NO_PROVIDER\"\n\t/** The requested chain cannot be used for this operation (e.g. a Solana cluster with no CAIP-2 id over WalletConnect). */\n\t| \"UNSUPPORTED_CHAIN\";\n\n/**\n * Error thrown by kheopskit wallet/account operations. Carries a stable\n * {@link KheopskitErrorCode} and, when relevant, the offending wallet id.\n *\n * @example\n * ```ts\n * try {\n * await wallet.connect();\n * } catch (error) {\n * if (error instanceof KheopskitError && error.code === \"WALLET_ALREADY_CONNECTED\") {\n * // ignore\n * } else throw error;\n * }\n * ```\n */\nexport class KheopskitError extends Error {\n\treadonly code: KheopskitErrorCode;\n\t/** The wallet id this error relates to, when applicable. */\n\treadonly walletId?: WalletId;\n\n\tconstructor(\n\t\tcode: KheopskitErrorCode,\n\t\tmessage: string,\n\t\toptions?: { walletId?: WalletId; cause?: unknown },\n\t) {\n\t\tsuper(`[kheopskit] ${message}`, { cause: options?.cause });\n\t\tthis.name = \"KheopskitError\";\n\t\tthis.code = code;\n\t\tthis.walletId = options?.walletId;\n\t}\n}\n"]}