@kheopskit/core 1.0.0 → 4.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 (57) hide show
  1. package/MIGRATING_TO_V4.md +259 -0
  2. package/README.md +67 -0
  3. package/dist/chunk-4RBYRNY3.mjs +164 -0
  4. package/dist/chunk-4RBYRNY3.mjs.map +1 -0
  5. package/dist/chunk-BWUUHUDK.mjs +24 -0
  6. package/dist/chunk-BWUUHUDK.mjs.map +1 -0
  7. package/dist/chunk-D3EQMFZ2.js +24 -0
  8. package/dist/chunk-D3EQMFZ2.js.map +1 -0
  9. package/dist/chunk-FIAL4HTE.js +1 -0
  10. package/dist/chunk-FIAL4HTE.js.map +1 -0
  11. package/dist/chunk-KWFQDD7E.mjs +578 -0
  12. package/dist/chunk-KWFQDD7E.mjs.map +1 -0
  13. package/dist/chunk-NU46D4MZ.js +578 -0
  14. package/dist/chunk-NU46D4MZ.js.map +1 -0
  15. package/dist/chunk-PNPPI5CH.mjs +201 -0
  16. package/dist/chunk-PNPPI5CH.mjs.map +1 -0
  17. package/dist/chunk-SIUWQBT4.js +201 -0
  18. package/dist/chunk-SIUWQBT4.js.map +1 -0
  19. package/dist/chunk-TMAPQWW2.js +164 -0
  20. package/dist/chunk-TMAPQWW2.js.map +1 -0
  21. package/dist/chunk-YFD3IKK5.mjs +1 -0
  22. package/dist/chunk-YFD3IKK5.mjs.map +1 -0
  23. package/dist/ethereum.d.mts +60 -0
  24. package/dist/ethereum.d.ts +60 -0
  25. package/dist/ethereum.js +332 -0
  26. package/dist/ethereum.js.map +1 -0
  27. package/dist/ethereum.mjs +332 -0
  28. package/dist/ethereum.mjs.map +1 -0
  29. package/dist/getCachedObservable-C4E8dfMp.d.mts +20 -0
  30. package/dist/getCachedObservable-C4E8dfMp.d.ts +20 -0
  31. package/dist/index.d.mts +44 -270
  32. package/dist/index.d.ts +44 -270
  33. package/dist/index.js +160 -1394
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.mjs +119 -1387
  36. package/dist/index.mjs.map +1 -1
  37. package/dist/internal.d.mts +86 -0
  38. package/dist/internal.d.ts +86 -0
  39. package/dist/internal.js +32 -0
  40. package/dist/internal.js.map +1 -0
  41. package/dist/internal.mjs +32 -0
  42. package/dist/internal.mjs.map +1 -0
  43. package/dist/polkadot.d.mts +69 -0
  44. package/dist/polkadot.d.ts +69 -0
  45. package/dist/polkadot.js +314 -0
  46. package/dist/polkadot.js.map +1 -0
  47. package/dist/polkadot.mjs +314 -0
  48. package/dist/polkadot.mjs.map +1 -0
  49. package/dist/solana.d.mts +97 -0
  50. package/dist/solana.d.ts +97 -0
  51. package/dist/solana.js +466 -0
  52. package/dist/solana.js.map +1 -0
  53. package/dist/solana.mjs +466 -0
  54. package/dist/solana.mjs.map +1 -0
  55. package/dist/types-BNzRUNw-.d.mts +319 -0
  56. package/dist/types-BNzRUNw-.d.ts +319 -0
  57. package/package.json +76 -16
package/dist/index.d.mts CHANGED
@@ -1,220 +1,9 @@
1
- import { AppKit, ThemeMode, ThemeVariables } from '@reown/appkit/core';
2
- import { AppKitNetwork } from '@reown/appkit/networks';
3
- import { Metadata } from '@walletconnect/universal-provider';
4
- import { InjectedExtension, InjectedPolkadotAccount } from 'polkadot-api/pjs-signer';
5
- import { EIP1193Provider, WalletClient, CustomTransport, Account } from 'viem';
6
- import * as rxjs from 'rxjs';
1
+ export { c as clearAllCachedObservables } from './getCachedObservable-C4E8dfMp.mjs';
2
+ import { K as KheopskitPlatform, b as KheopskitConfig, c as createKheopskitStore, d as KheopskitState } from './types-BNzRUNw-.mjs';
3
+ export { A as AccountOf, e as AppKitInstance, f as AppKitWallet, B as BaseWallet, g as BaseWalletAccount, C as CachedAccount, h as CachedWallet, E as EthereumAppKitWallet, P as PlatformContext, i as PolkadotAccountType, j as PolkadotAppKitWallet, S as SolanaAppKitWallet, W as WalletAccountId, k as WalletConnectConfig, l as WalletConnectMetadata, m as WalletConnectProvider, a as WalletId, n as WalletOf, o as WalletPlatform, p as WalletType, q as getDefaultStore, r as getWalletAccountId, s as getWalletId, t as parseWalletId } from './types-BNzRUNw-.mjs';
7
4
  import { Observable } from 'rxjs';
8
5
 
9
- /**
10
- * Clears an observable from the cache.
11
- * Use when a wallet disconnects or configuration changes.
12
- */
13
- declare const clearCachedObservable: (key: string) => void;
14
- /**
15
- * Clears all cached observables.
16
- * Use when resetting the entire kheopskit state.
17
- */
18
- declare const clearAllCachedObservables: () => void;
19
-
20
- type Storage = {
21
- getItem: (key: string) => string | null;
22
- setItem: (key: string, value: string) => void;
23
- removeItem: (key: string) => void;
24
- };
25
- /**
26
- * Extended storage interface with cross-tab sync support.
27
- */
28
- type SyncableStorage = Storage & {
29
- /**
30
- * Subscribe to storage changes from other tabs.
31
- * Returns an unsubscribe function.
32
- */
33
- subscribe?: (key: string, callback: (value: string | null) => void) => () => void;
34
- };
35
- /**
36
- * A safe localStorage wrapper that falls back to noopStorage
37
- * when localStorage is not available (e.g., during SSR).
38
- * Includes cross-tab sync via the native 'storage' event.
39
- *
40
- * Lazily initialized on first access to be SSR-safe.
41
- */
42
- declare const getSafeLocalStorage: () => SyncableStorage;
43
-
44
- type WalletAccountId = string;
45
-
46
- type WalletId = string;
47
-
48
- type KheopskitConfig = {
49
- autoReconnect: boolean;
50
- platforms: WalletPlatform[];
51
- /**
52
- * Allowed Polkadot account key types.
53
- * Accounts with other key types are filtered out from kheopskit state.
54
- *
55
- * @default ["sr25519", "ed25519", "ecdsa"]
56
- */
57
- polkadotAccountTypes: PolkadotAccountType[];
58
- walletConnect?: {
59
- projectId: string;
60
- metadata: Metadata;
61
- /** Defaults to wss://relay.walletconnect.com */
62
- relayUrl?: string;
63
- /**
64
- * list of CAIP-13 ids of polkadot-sdk chains
65
- * see https://docs.reown.com/advanced/multichain/polkadot/dapp-integration-guide#walletconnect-code%2Fcomponent-setup
66
- */
67
- networks: [AppKitNetwork, ...AppKitNetwork[]];
68
- themeMode?: ThemeMode;
69
- themeVariables?: ThemeVariables;
70
- };
71
- debug: boolean;
72
- /**
73
- * Custom storage key for persisting wallet connection state.
74
- * Useful when running multiple kheopskit instances on the same domain
75
- * to prevent state conflicts between different dapps.
76
- *
77
- * @default "kheopskit"
78
- *
79
- * @example
80
- * ```ts
81
- * // For app "MyDapp" to avoid conflicts
82
- * { storageKey: "kheopskit-mydapp" }
83
- * ```
84
- */
85
- storageKey: string;
86
- /**
87
- * Grace period in milliseconds to wait for wallets to inject before
88
- * syncing to actual state. During this period, cached wallet/account
89
- * state from storage is preserved to prevent UI flashing.
90
- *
91
- * Set to 0 to disable hydration buffering.
92
- *
93
- * @default 500
94
- */
95
- hydrationGracePeriod: number;
96
- };
97
- type PolkadotInjectedWallet = {
98
- id: WalletId;
99
- platform: "polkadot";
100
- type: "injected";
101
- extensionId: string;
102
- extension: InjectedExtension | undefined;
103
- name: string;
104
- icon: string;
105
- isConnected: boolean;
106
- connect: () => Promise<void>;
107
- disconnect: () => void;
108
- };
109
- type PolkadotAppKitWallet = {
110
- id: WalletId;
111
- platform: "polkadot";
112
- type: "appKit";
113
- appKit: AppKit;
114
- name: string;
115
- icon: string;
116
- isConnected: boolean;
117
- connect: () => Promise<void>;
118
- disconnect: () => void;
119
- };
120
- type PolkadotWallet = PolkadotInjectedWallet | PolkadotAppKitWallet;
121
- type EthereumInjectedWallet = {
122
- platform: "ethereum";
123
- type: "injected";
124
- id: WalletId;
125
- providerId: string;
126
- provider: EIP1193Provider;
127
- name: string;
128
- icon: string;
129
- isConnected: boolean;
130
- connect: () => Promise<void>;
131
- disconnect: () => void;
132
- };
133
- type EthereumAppKitWallet = {
134
- platform: "ethereum";
135
- type: "appKit";
136
- id: WalletId;
137
- appKit: AppKit;
138
- name: string;
139
- icon: string;
140
- isConnected: boolean;
141
- connect: () => Promise<void>;
142
- disconnect: () => void;
143
- };
144
- type EthereumWallet = EthereumInjectedWallet | EthereumAppKitWallet;
145
- type Wallet = PolkadotWallet | EthereumWallet;
146
- type WalletPlatform = Wallet["platform"];
147
- type PolkadotAccountType = "sr25519" | "ed25519" | "ecdsa" | "ethereum";
148
- type PolkadotAccount = Omit<InjectedPolkadotAccount, "type"> & {
149
- type: PolkadotAccountType;
150
- id: WalletAccountId;
151
- platform: "polkadot";
152
- walletName: string;
153
- walletId: string;
154
- };
155
- type EthereumAccount = {
156
- id: WalletAccountId;
157
- platform: "ethereum";
158
- client: WalletClient<CustomTransport, undefined, Account, undefined>;
159
- address: `0x${string}`;
160
- /** Current chain ID the wallet is connected to. `undefined` while loading or after provider disconnect. */
161
- chainId: number | undefined;
162
- walletName: string;
163
- walletId: string;
164
- isWalletDefault: boolean;
165
- };
166
- type WalletAccount = PolkadotAccount | EthereumAccount;
167
- /**
168
- * Serializable wallet data for SSR hydration cache.
169
- * Contains only the data needed to render wallet UI without flash.
170
- * Note: icon is NOT stored to save cookie space - it's looked up at hydration time.
171
- */
172
- type CachedWallet = {
173
- id: WalletId;
174
- platform: WalletPlatform;
175
- type: "injected" | "appKit";
176
- name: string;
177
- isConnected: boolean;
178
- };
179
- /**
180
- * Serializable account data for SSR hydration cache.
181
- * Contains only the data needed to render account UI without flash.
182
- */
183
- type CachedAccount = {
184
- id: string;
185
- platform: WalletPlatform;
186
- address: string;
187
- name?: string;
188
- /** Cached chain ID for Ethereum accounts. */
189
- chainId?: number;
190
- /** Cached key type for Polkadot accounts. */
191
- polkadotAccountType?: PolkadotAccountType;
192
- walletId: WalletId;
193
- walletName: string;
194
- };
195
-
196
- /**
197
- * Converts a CachedWallet to a placeholder Wallet object.
198
- * The placeholder has the same display properties but connect/disconnect throw errors.
199
- *
200
- * @param cached - The cached wallet data from storage
201
- * @returns A placeholder Wallet object that can be displayed but not interacted with
202
- */
203
- declare const hydrateWallet: (cached: CachedWallet) => Wallet;
204
- /**
205
- * Converts a CachedAccount to a placeholder WalletAccount object.
206
- *
207
- * @param cached - The cached account data from storage
208
- * @returns A placeholder WalletAccount object that can be displayed
209
- */
210
- declare const hydrateAccount: (cached: CachedAccount) => WalletAccount;
211
-
212
- /**
213
- * Gets a cached icon for a wallet.
214
- * @param walletId - The wallet ID (e.g., "ethereum:io.talisman")
215
- * @returns The cached icon data URI, or undefined if not cached
216
- */
217
- declare const getCachedIcon: (walletId: string) => string | undefined;
6
+ declare const isValidAddress: (address: string) => boolean;
218
7
 
219
8
  /**
220
9
  * Clears the cached AppKit observable.
@@ -229,65 +18,50 @@ declare const resetAppKitCache: () => void;
229
18
  * when running multiple dapps on the same domain.
230
19
  */
231
20
  declare const DEFAULT_STORAGE_KEY = "kheopskit";
232
- declare const resolveConfig: (config: Partial<KheopskitConfig> | undefined) => KheopskitConfig;
21
+ declare const resolveConfig: <const P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]>(config?: Partial<KheopskitConfig<P>>) => KheopskitConfig<P>;
233
22
 
234
- type KheopskitStoreData = {
235
- autoReconnect?: WalletId[];
236
- /** Cached wallet state for SSR hydration to prevent UI flash */
237
- cachedWallets?: CachedWallet[];
238
- /** Cached account state for SSR hydration to prevent UI flash */
239
- cachedAccounts?: CachedAccount[];
240
- };
241
- type CreateKheopskitStoreOptions = {
242
- /**
243
- * Cookie string for SSR hydration.
244
- * When provided, uses cookieStorage instead of localStorage.
245
- */
246
- ssrCookies?: string;
247
- /**
248
- * Custom storage key to namespace the stored data.
249
- * @default "kheopskit"
250
- */
251
- storageKey?: string;
252
- };
253
23
  /**
254
- * Creates a kheopskit store with the appropriate storage backend.
255
- * Uses cookieStorage when ssrCookies is provided (for SSR hydration),
256
- * otherwise falls back to safeLocalStorage.
257
- *
258
- * @param options - Configuration options for the store
24
+ * Stable error codes thrown by kheopskit. Catch a {@link KheopskitError} and
25
+ * branch on `error.code` instead of matching message strings.
259
26
  */
260
- declare const createKheopskitStore: (options?: CreateKheopskitStoreOptions) => {
261
- observable: rxjs.Observable<KheopskitStoreData>;
262
- addEnabledWalletId: (walletId: WalletId) => void;
263
- removeEnabledWalletId: (walletId: WalletId) => void;
264
- getCachedState: () => {
265
- wallets: CachedWallet[];
266
- accounts: CachedAccount[];
267
- };
268
- setCachedState: (wallets: CachedWallet[], accounts: CachedAccount[]) => void;
269
- };
270
- type KheopskitStore = ReturnType<typeof createKheopskitStore>;
27
+ type KheopskitErrorCode =
28
+ /** `connect()` called on a wallet that is already connected. */
29
+ "WALLET_ALREADY_CONNECTED"
30
+ /** `disconnect()` called on a wallet that is not connected. */
31
+ | "WALLET_NOT_CONNECTED"
32
+ /** The wallet does not advertise a capability kheopskit needs to proceed. */
33
+ | "FEATURE_NOT_SUPPORTED"
34
+ /** No active WalletConnect session for the requested operation. */
35
+ | "NO_SESSION"
36
+ /** No provider available for the requested namespace. */
37
+ | "NO_PROVIDER"
38
+ /** The requested chain cannot be used for this operation (e.g. a Solana cluster with no CAIP-2 id over WalletConnect). */
39
+ | "UNSUPPORTED_CHAIN";
271
40
  /**
272
- * Gets the default store, creating it on first access.
273
- * Uses localStorage on client, noop on server.
274
- * Lazily initialized to avoid SSR issues with module-level code.
41
+ * Error thrown by kheopskit wallet/account operations. Carries a stable
42
+ * {@link KheopskitErrorCode} and, when relevant, the offending wallet id.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * try {
47
+ * await wallet.connect();
48
+ * } catch (error) {
49
+ * if (error instanceof KheopskitError && error.code === "WALLET_ALREADY_CONNECTED") {
50
+ * // ignore
51
+ * } else throw error;
52
+ * }
53
+ * ```
275
54
  */
276
- declare const getDefaultStore: () => KheopskitStore;
55
+ declare class KheopskitError extends Error {
56
+ readonly code: KheopskitErrorCode;
57
+ /** The wallet id this error relates to, when applicable. */
58
+ readonly walletId?: string;
59
+ constructor(code: KheopskitErrorCode, message: string, options?: {
60
+ walletId?: string;
61
+ cause?: unknown;
62
+ });
63
+ }
277
64
 
278
- type KheopskitState = {
279
- wallets: Wallet[];
280
- accounts: WalletAccount[];
281
- config: KheopskitConfig;
282
- /**
283
- * Whether the state is still being hydrated from cache.
284
- * During hydration, cached wallets/accounts may be displayed
285
- * before the actual wallet extensions have injected.
286
- *
287
- * Use this to show loading indicators or disable certain actions.
288
- */
289
- isHydrating: boolean;
290
- };
291
- declare const getKheopskit$: (config?: Partial<KheopskitConfig>, ssrCookies?: string, existingStore?: ReturnType<typeof createKheopskitStore>) => Observable<KheopskitState>;
65
+ declare const getKheopskit$: <const P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]>(config?: Partial<KheopskitConfig<P>>, ssrCookies?: string, existingStore?: ReturnType<typeof createKheopskitStore>) => Observable<KheopskitState<P>>;
292
66
 
293
- export { type CachedAccount, type CachedWallet, DEFAULT_STORAGE_KEY, type EthereumAccount, type EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, type KheopskitConfig, type KheopskitState, type PolkadotAccount, type PolkadotAccountType, type PolkadotAppKitWallet, type PolkadotInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, clearAllCachedObservables, clearCachedObservable, createKheopskitStore, getCachedIcon, getDefaultStore, getKheopskit$, getSafeLocalStorage, hydrateAccount, hydrateWallet, resetAppKitCache, resolveConfig };
67
+ export { DEFAULT_STORAGE_KEY, KheopskitConfig, KheopskitError, type KheopskitErrorCode, KheopskitPlatform, KheopskitState, createKheopskitStore, getKheopskit$, isValidAddress, resetAppKitCache, resolveConfig };
package/dist/index.d.ts CHANGED
@@ -1,220 +1,9 @@
1
- import { AppKit, ThemeMode, ThemeVariables } from '@reown/appkit/core';
2
- import { AppKitNetwork } from '@reown/appkit/networks';
3
- import { Metadata } from '@walletconnect/universal-provider';
4
- import { InjectedExtension, InjectedPolkadotAccount } from 'polkadot-api/pjs-signer';
5
- import { EIP1193Provider, WalletClient, CustomTransport, Account } from 'viem';
6
- import * as rxjs from 'rxjs';
1
+ export { c as clearAllCachedObservables } from './getCachedObservable-C4E8dfMp.js';
2
+ import { K as KheopskitPlatform, b as KheopskitConfig, c as createKheopskitStore, d as KheopskitState } from './types-BNzRUNw-.js';
3
+ export { A as AccountOf, e as AppKitInstance, f as AppKitWallet, B as BaseWallet, g as BaseWalletAccount, C as CachedAccount, h as CachedWallet, E as EthereumAppKitWallet, P as PlatformContext, i as PolkadotAccountType, j as PolkadotAppKitWallet, S as SolanaAppKitWallet, W as WalletAccountId, k as WalletConnectConfig, l as WalletConnectMetadata, m as WalletConnectProvider, a as WalletId, n as WalletOf, o as WalletPlatform, p as WalletType, q as getDefaultStore, r as getWalletAccountId, s as getWalletId, t as parseWalletId } from './types-BNzRUNw-.js';
7
4
  import { Observable } from 'rxjs';
8
5
 
9
- /**
10
- * Clears an observable from the cache.
11
- * Use when a wallet disconnects or configuration changes.
12
- */
13
- declare const clearCachedObservable: (key: string) => void;
14
- /**
15
- * Clears all cached observables.
16
- * Use when resetting the entire kheopskit state.
17
- */
18
- declare const clearAllCachedObservables: () => void;
19
-
20
- type Storage = {
21
- getItem: (key: string) => string | null;
22
- setItem: (key: string, value: string) => void;
23
- removeItem: (key: string) => void;
24
- };
25
- /**
26
- * Extended storage interface with cross-tab sync support.
27
- */
28
- type SyncableStorage = Storage & {
29
- /**
30
- * Subscribe to storage changes from other tabs.
31
- * Returns an unsubscribe function.
32
- */
33
- subscribe?: (key: string, callback: (value: string | null) => void) => () => void;
34
- };
35
- /**
36
- * A safe localStorage wrapper that falls back to noopStorage
37
- * when localStorage is not available (e.g., during SSR).
38
- * Includes cross-tab sync via the native 'storage' event.
39
- *
40
- * Lazily initialized on first access to be SSR-safe.
41
- */
42
- declare const getSafeLocalStorage: () => SyncableStorage;
43
-
44
- type WalletAccountId = string;
45
-
46
- type WalletId = string;
47
-
48
- type KheopskitConfig = {
49
- autoReconnect: boolean;
50
- platforms: WalletPlatform[];
51
- /**
52
- * Allowed Polkadot account key types.
53
- * Accounts with other key types are filtered out from kheopskit state.
54
- *
55
- * @default ["sr25519", "ed25519", "ecdsa"]
56
- */
57
- polkadotAccountTypes: PolkadotAccountType[];
58
- walletConnect?: {
59
- projectId: string;
60
- metadata: Metadata;
61
- /** Defaults to wss://relay.walletconnect.com */
62
- relayUrl?: string;
63
- /**
64
- * list of CAIP-13 ids of polkadot-sdk chains
65
- * see https://docs.reown.com/advanced/multichain/polkadot/dapp-integration-guide#walletconnect-code%2Fcomponent-setup
66
- */
67
- networks: [AppKitNetwork, ...AppKitNetwork[]];
68
- themeMode?: ThemeMode;
69
- themeVariables?: ThemeVariables;
70
- };
71
- debug: boolean;
72
- /**
73
- * Custom storage key for persisting wallet connection state.
74
- * Useful when running multiple kheopskit instances on the same domain
75
- * to prevent state conflicts between different dapps.
76
- *
77
- * @default "kheopskit"
78
- *
79
- * @example
80
- * ```ts
81
- * // For app "MyDapp" to avoid conflicts
82
- * { storageKey: "kheopskit-mydapp" }
83
- * ```
84
- */
85
- storageKey: string;
86
- /**
87
- * Grace period in milliseconds to wait for wallets to inject before
88
- * syncing to actual state. During this period, cached wallet/account
89
- * state from storage is preserved to prevent UI flashing.
90
- *
91
- * Set to 0 to disable hydration buffering.
92
- *
93
- * @default 500
94
- */
95
- hydrationGracePeriod: number;
96
- };
97
- type PolkadotInjectedWallet = {
98
- id: WalletId;
99
- platform: "polkadot";
100
- type: "injected";
101
- extensionId: string;
102
- extension: InjectedExtension | undefined;
103
- name: string;
104
- icon: string;
105
- isConnected: boolean;
106
- connect: () => Promise<void>;
107
- disconnect: () => void;
108
- };
109
- type PolkadotAppKitWallet = {
110
- id: WalletId;
111
- platform: "polkadot";
112
- type: "appKit";
113
- appKit: AppKit;
114
- name: string;
115
- icon: string;
116
- isConnected: boolean;
117
- connect: () => Promise<void>;
118
- disconnect: () => void;
119
- };
120
- type PolkadotWallet = PolkadotInjectedWallet | PolkadotAppKitWallet;
121
- type EthereumInjectedWallet = {
122
- platform: "ethereum";
123
- type: "injected";
124
- id: WalletId;
125
- providerId: string;
126
- provider: EIP1193Provider;
127
- name: string;
128
- icon: string;
129
- isConnected: boolean;
130
- connect: () => Promise<void>;
131
- disconnect: () => void;
132
- };
133
- type EthereumAppKitWallet = {
134
- platform: "ethereum";
135
- type: "appKit";
136
- id: WalletId;
137
- appKit: AppKit;
138
- name: string;
139
- icon: string;
140
- isConnected: boolean;
141
- connect: () => Promise<void>;
142
- disconnect: () => void;
143
- };
144
- type EthereumWallet = EthereumInjectedWallet | EthereumAppKitWallet;
145
- type Wallet = PolkadotWallet | EthereumWallet;
146
- type WalletPlatform = Wallet["platform"];
147
- type PolkadotAccountType = "sr25519" | "ed25519" | "ecdsa" | "ethereum";
148
- type PolkadotAccount = Omit<InjectedPolkadotAccount, "type"> & {
149
- type: PolkadotAccountType;
150
- id: WalletAccountId;
151
- platform: "polkadot";
152
- walletName: string;
153
- walletId: string;
154
- };
155
- type EthereumAccount = {
156
- id: WalletAccountId;
157
- platform: "ethereum";
158
- client: WalletClient<CustomTransport, undefined, Account, undefined>;
159
- address: `0x${string}`;
160
- /** Current chain ID the wallet is connected to. `undefined` while loading or after provider disconnect. */
161
- chainId: number | undefined;
162
- walletName: string;
163
- walletId: string;
164
- isWalletDefault: boolean;
165
- };
166
- type WalletAccount = PolkadotAccount | EthereumAccount;
167
- /**
168
- * Serializable wallet data for SSR hydration cache.
169
- * Contains only the data needed to render wallet UI without flash.
170
- * Note: icon is NOT stored to save cookie space - it's looked up at hydration time.
171
- */
172
- type CachedWallet = {
173
- id: WalletId;
174
- platform: WalletPlatform;
175
- type: "injected" | "appKit";
176
- name: string;
177
- isConnected: boolean;
178
- };
179
- /**
180
- * Serializable account data for SSR hydration cache.
181
- * Contains only the data needed to render account UI without flash.
182
- */
183
- type CachedAccount = {
184
- id: string;
185
- platform: WalletPlatform;
186
- address: string;
187
- name?: string;
188
- /** Cached chain ID for Ethereum accounts. */
189
- chainId?: number;
190
- /** Cached key type for Polkadot accounts. */
191
- polkadotAccountType?: PolkadotAccountType;
192
- walletId: WalletId;
193
- walletName: string;
194
- };
195
-
196
- /**
197
- * Converts a CachedWallet to a placeholder Wallet object.
198
- * The placeholder has the same display properties but connect/disconnect throw errors.
199
- *
200
- * @param cached - The cached wallet data from storage
201
- * @returns A placeholder Wallet object that can be displayed but not interacted with
202
- */
203
- declare const hydrateWallet: (cached: CachedWallet) => Wallet;
204
- /**
205
- * Converts a CachedAccount to a placeholder WalletAccount object.
206
- *
207
- * @param cached - The cached account data from storage
208
- * @returns A placeholder WalletAccount object that can be displayed
209
- */
210
- declare const hydrateAccount: (cached: CachedAccount) => WalletAccount;
211
-
212
- /**
213
- * Gets a cached icon for a wallet.
214
- * @param walletId - The wallet ID (e.g., "ethereum:io.talisman")
215
- * @returns The cached icon data URI, or undefined if not cached
216
- */
217
- declare const getCachedIcon: (walletId: string) => string | undefined;
6
+ declare const isValidAddress: (address: string) => boolean;
218
7
 
219
8
  /**
220
9
  * Clears the cached AppKit observable.
@@ -229,65 +18,50 @@ declare const resetAppKitCache: () => void;
229
18
  * when running multiple dapps on the same domain.
230
19
  */
231
20
  declare const DEFAULT_STORAGE_KEY = "kheopskit";
232
- declare const resolveConfig: (config: Partial<KheopskitConfig> | undefined) => KheopskitConfig;
21
+ declare const resolveConfig: <const P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]>(config?: Partial<KheopskitConfig<P>>) => KheopskitConfig<P>;
233
22
 
234
- type KheopskitStoreData = {
235
- autoReconnect?: WalletId[];
236
- /** Cached wallet state for SSR hydration to prevent UI flash */
237
- cachedWallets?: CachedWallet[];
238
- /** Cached account state for SSR hydration to prevent UI flash */
239
- cachedAccounts?: CachedAccount[];
240
- };
241
- type CreateKheopskitStoreOptions = {
242
- /**
243
- * Cookie string for SSR hydration.
244
- * When provided, uses cookieStorage instead of localStorage.
245
- */
246
- ssrCookies?: string;
247
- /**
248
- * Custom storage key to namespace the stored data.
249
- * @default "kheopskit"
250
- */
251
- storageKey?: string;
252
- };
253
23
  /**
254
- * Creates a kheopskit store with the appropriate storage backend.
255
- * Uses cookieStorage when ssrCookies is provided (for SSR hydration),
256
- * otherwise falls back to safeLocalStorage.
257
- *
258
- * @param options - Configuration options for the store
24
+ * Stable error codes thrown by kheopskit. Catch a {@link KheopskitError} and
25
+ * branch on `error.code` instead of matching message strings.
259
26
  */
260
- declare const createKheopskitStore: (options?: CreateKheopskitStoreOptions) => {
261
- observable: rxjs.Observable<KheopskitStoreData>;
262
- addEnabledWalletId: (walletId: WalletId) => void;
263
- removeEnabledWalletId: (walletId: WalletId) => void;
264
- getCachedState: () => {
265
- wallets: CachedWallet[];
266
- accounts: CachedAccount[];
267
- };
268
- setCachedState: (wallets: CachedWallet[], accounts: CachedAccount[]) => void;
269
- };
270
- type KheopskitStore = ReturnType<typeof createKheopskitStore>;
27
+ type KheopskitErrorCode =
28
+ /** `connect()` called on a wallet that is already connected. */
29
+ "WALLET_ALREADY_CONNECTED"
30
+ /** `disconnect()` called on a wallet that is not connected. */
31
+ | "WALLET_NOT_CONNECTED"
32
+ /** The wallet does not advertise a capability kheopskit needs to proceed. */
33
+ | "FEATURE_NOT_SUPPORTED"
34
+ /** No active WalletConnect session for the requested operation. */
35
+ | "NO_SESSION"
36
+ /** No provider available for the requested namespace. */
37
+ | "NO_PROVIDER"
38
+ /** The requested chain cannot be used for this operation (e.g. a Solana cluster with no CAIP-2 id over WalletConnect). */
39
+ | "UNSUPPORTED_CHAIN";
271
40
  /**
272
- * Gets the default store, creating it on first access.
273
- * Uses localStorage on client, noop on server.
274
- * Lazily initialized to avoid SSR issues with module-level code.
41
+ * Error thrown by kheopskit wallet/account operations. Carries a stable
42
+ * {@link KheopskitErrorCode} and, when relevant, the offending wallet id.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * try {
47
+ * await wallet.connect();
48
+ * } catch (error) {
49
+ * if (error instanceof KheopskitError && error.code === "WALLET_ALREADY_CONNECTED") {
50
+ * // ignore
51
+ * } else throw error;
52
+ * }
53
+ * ```
275
54
  */
276
- declare const getDefaultStore: () => KheopskitStore;
55
+ declare class KheopskitError extends Error {
56
+ readonly code: KheopskitErrorCode;
57
+ /** The wallet id this error relates to, when applicable. */
58
+ readonly walletId?: string;
59
+ constructor(code: KheopskitErrorCode, message: string, options?: {
60
+ walletId?: string;
61
+ cause?: unknown;
62
+ });
63
+ }
277
64
 
278
- type KheopskitState = {
279
- wallets: Wallet[];
280
- accounts: WalletAccount[];
281
- config: KheopskitConfig;
282
- /**
283
- * Whether the state is still being hydrated from cache.
284
- * During hydration, cached wallets/accounts may be displayed
285
- * before the actual wallet extensions have injected.
286
- *
287
- * Use this to show loading indicators or disable certain actions.
288
- */
289
- isHydrating: boolean;
290
- };
291
- declare const getKheopskit$: (config?: Partial<KheopskitConfig>, ssrCookies?: string, existingStore?: ReturnType<typeof createKheopskitStore>) => Observable<KheopskitState>;
65
+ declare const getKheopskit$: <const P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]>(config?: Partial<KheopskitConfig<P>>, ssrCookies?: string, existingStore?: ReturnType<typeof createKheopskitStore>) => Observable<KheopskitState<P>>;
292
66
 
293
- export { type CachedAccount, type CachedWallet, DEFAULT_STORAGE_KEY, type EthereumAccount, type EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, type KheopskitConfig, type KheopskitState, type PolkadotAccount, type PolkadotAccountType, type PolkadotAppKitWallet, type PolkadotInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, clearAllCachedObservables, clearCachedObservable, createKheopskitStore, getCachedIcon, getDefaultStore, getKheopskit$, getSafeLocalStorage, hydrateAccount, hydrateWallet, resetAppKitCache, resolveConfig };
67
+ export { DEFAULT_STORAGE_KEY, KheopskitConfig, KheopskitError, type KheopskitErrorCode, KheopskitPlatform, KheopskitState, createKheopskitStore, getKheopskit$, isValidAddress, resetAppKitCache, resolveConfig };