@kheopskit/core 5.1.0 → 5.1.2

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 (76) hide show
  1. package/dist/errors-Caq2csKx.mjs +181 -0
  2. package/dist/errors-Caq2csKx.mjs.map +1 -0
  3. package/dist/errors-DPw6pc2H.js +222 -0
  4. package/dist/errors-DPw6pc2H.js.map +1 -0
  5. package/dist/ethereum.d.mts +39 -38
  6. package/dist/ethereum.d.ts +39 -38
  7. package/dist/ethereum.js +214 -281
  8. package/dist/ethereum.js.map +1 -1
  9. package/dist/ethereum.mjs +211 -282
  10. package/dist/ethereum.mjs.map +1 -1
  11. package/dist/{getCachedObservable-C4E8dfMp.d.ts → getCachedObservable-LUq9IfEx.d.mts} +5 -2
  12. package/dist/{getCachedObservable-C4E8dfMp.d.mts → getCachedObservable-LUq9IfEx.d.ts} +5 -2
  13. package/dist/iconCache-BSa42Sui.mjs +343 -0
  14. package/dist/iconCache-BSa42Sui.mjs.map +1 -0
  15. package/dist/iconCache-DS4zNiP1.js +396 -0
  16. package/dist/iconCache-DS4zNiP1.js.map +1 -0
  17. package/dist/index.d.mts +65 -59
  18. package/dist/index.d.ts +65 -59
  19. package/dist/index.js +901 -1015
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +885 -1016
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/injectedWallets-B1MCxAE9.js +148 -0
  24. package/dist/injectedWallets-B1MCxAE9.js.map +1 -0
  25. package/dist/injectedWallets-B3Vysfvr.mjs +119 -0
  26. package/dist/injectedWallets-B3Vysfvr.mjs.map +1 -0
  27. package/dist/internal.d.mts +18 -16
  28. package/dist/internal.d.ts +18 -16
  29. package/dist/internal.js +9 -20
  30. package/dist/internal.mjs +3 -20
  31. package/dist/polkadot.d.mts +37 -36
  32. package/dist/polkadot.d.ts +37 -36
  33. package/dist/polkadot.js +178 -220
  34. package/dist/polkadot.js.map +1 -1
  35. package/dist/polkadot.mjs +175 -221
  36. package/dist/polkadot.mjs.map +1 -1
  37. package/dist/polkadotExtensions-BoVKhNU_.mjs +23 -0
  38. package/dist/polkadotExtensions-BoVKhNU_.mjs.map +1 -0
  39. package/dist/polkadotExtensions-y4J9UzYl.js +28 -0
  40. package/dist/polkadotExtensions-y4J9UzYl.js.map +1 -0
  41. package/dist/solana.d.mts +50 -48
  42. package/dist/solana.d.ts +50 -48
  43. package/dist/solana.js +320 -378
  44. package/dist/solana.js.map +1 -1
  45. package/dist/solana.mjs +314 -379
  46. package/dist/solana.mjs.map +1 -1
  47. package/dist/types-Cb-vuEru.d.mts +330 -0
  48. package/dist/types-Cb-vuEru.d.ts +330 -0
  49. package/dist/types-DKU-SNio.js +169 -0
  50. package/dist/{chunk-P7BPHHVV.js.map → types-DKU-SNio.js.map} +1 -1
  51. package/dist/types-jnifAAA0.mjs +104 -0
  52. package/dist/types-jnifAAA0.mjs.map +1 -0
  53. package/package.json +12 -12
  54. package/dist/chunk-3Y5N4N3Q.mjs +0 -267
  55. package/dist/chunk-3Y5N4N3Q.mjs.map +0 -1
  56. package/dist/chunk-BWUUHUDK.mjs +0 -24
  57. package/dist/chunk-BWUUHUDK.mjs.map +0 -1
  58. package/dist/chunk-D3EQMFZ2.js +0 -24
  59. package/dist/chunk-D3EQMFZ2.js.map +0 -1
  60. package/dist/chunk-DF7EKK4G.mjs +0 -106
  61. package/dist/chunk-DF7EKK4G.mjs.map +0 -1
  62. package/dist/chunk-EH73P476.js +0 -106
  63. package/dist/chunk-EH73P476.js.map +0 -1
  64. package/dist/chunk-JVSCMJY5.mjs +0 -147
  65. package/dist/chunk-JVSCMJY5.mjs.map +0 -1
  66. package/dist/chunk-P7BPHHVV.js +0 -76
  67. package/dist/chunk-SO64R7Z6.js +0 -267
  68. package/dist/chunk-SO64R7Z6.js.map +0 -1
  69. package/dist/chunk-WOPCW2OX.mjs +0 -76
  70. package/dist/chunk-WOPCW2OX.mjs.map +0 -1
  71. package/dist/chunk-XOGQMEV2.js +0 -147
  72. package/dist/chunk-XOGQMEV2.js.map +0 -1
  73. package/dist/internal.js.map +0 -1
  74. package/dist/internal.mjs.map +0 -1
  75. package/dist/types-0iDBydsK.d.mts +0 -327
  76. package/dist/types-0iDBydsK.d.ts +0 -327
@@ -1,327 +0,0 @@
1
- import { Observable } from 'rxjs';
2
-
3
- type WalletAccountId = string;
4
- declare const getWalletAccountId: (walletId: string, address: string) => WalletAccountId;
5
- declare const parseWalletAccountId: (accountId: string) => {
6
- walletId: string;
7
- address: string;
8
- };
9
-
10
- type WalletId = string;
11
- declare const getWalletId: (platform: WalletPlatform, identifier: string) => WalletId;
12
- declare const parseWalletId: (walletId: string) => {
13
- platform: WalletPlatform;
14
- identifier: string;
15
- };
16
- /**
17
- * Non-throwing variant of {@link parseWalletId}. Use when validating untrusted
18
- * input (e.g. cached state persisted by an older version) before parsing.
19
- */
20
- declare const isValidWalletId: (walletId: unknown) => walletId is WalletId;
21
-
22
- type WalletPlatform = "polkadot" | "ethereum" | "solana";
23
- /**
24
- * Minimal structural view of a WalletConnect `UniversalProvider` — the subset
25
- * kheopskit reads. Declared locally so core never depends on
26
- * `@walletconnect/universal-provider`. The concrete instance comes from
27
- * `@reown/appkit` at runtime.
28
- */
29
- type WalletConnectProvider = {
30
- session?: {
31
- topic: string;
32
- namespaces: Record<string, {
33
- accounts?: string[];
34
- }>;
35
- };
36
- client: {
37
- request<T = unknown>(args: {
38
- topic: string;
39
- chainId: string;
40
- request: {
41
- method: string;
42
- params: unknown;
43
- };
44
- }): Promise<T>;
45
- };
46
- request(args: {
47
- method: string;
48
- params?: unknown;
49
- }): Promise<unknown>;
50
- on(event: string, listener: (...args: unknown[]) => void): void;
51
- off(event: string, listener: (...args: unknown[]) => void): void;
52
- };
53
- /**
54
- * Minimal structural view of the Reown AppKit instance — the subset kheopskit's
55
- * account factories use. Exposed as the `appKit` escape hatch on AppKit wallets;
56
- * cast it to `@reown/appkit`'s `AppKit` type for the full API. Declared locally
57
- * so core never depends on `@reown/appkit`'s types (it's an optional peer).
58
- */
59
- type AppKitInstance = {
60
- getProvider<T = WalletConnectProvider>(namespace: string): T | undefined;
61
- getAccount(namespace: string): {
62
- allAccounts: {
63
- address: string;
64
- }[];
65
- } | undefined;
66
- getCaipNetworks(namespace: string): {
67
- caipNetworkId?: string;
68
- }[];
69
- };
70
- type WalletType = "injected" | "walletconnect";
71
- type PolkadotAccountType = "sr25519" | "ed25519" | "ecdsa" | "ethereum";
72
- /**
73
- * SDK-free fields common to every wallet, regardless of platform. Platform
74
- * packages (`@kheopskit/core/<platform>`) extend this with SDK-typed fields
75
- * (the injected provider/extension/standard-wallet handle).
76
- */
77
- type BaseWallet = {
78
- id: WalletId;
79
- platform: WalletPlatform;
80
- type: WalletType;
81
- name: string;
82
- icon: string;
83
- isConnected: boolean;
84
- connect: () => Promise<void>;
85
- /**
86
- * Disconnect the wallet. Resolves once the underlying provider/extension
87
- * disconnect completes; rejects if it fails so callers can surface or retry.
88
- */
89
- disconnect: () => Promise<void>;
90
- };
91
- /**
92
- * SDK-free fields common to every account, regardless of platform. Platform
93
- * packages extend this with their SDK-typed signer/client.
94
- */
95
- type BaseWalletAccount = {
96
- id: WalletAccountId;
97
- platform: WalletPlatform;
98
- /** Base58 (Solana), SS58 (Polkadot) or 0x-hex (Ethereum) address. */
99
- address: string;
100
- /** Friendly account name, when the wallet exposes one (e.g. Polkadot). */
101
- name?: string;
102
- walletName: string;
103
- walletId: WalletId;
104
- };
105
- /**
106
- * The single WalletConnect connector, shared across every platform.
107
- *
108
- * Unlike injected wallets, it is **not tied to a platform**: one WalletConnect
109
- * session spans whichever namespaces the remote wallet approves in a single
110
- * pairing (a namespace can't be added to a live session afterwards). So there is
111
- * exactly one of these in `wallets`, discriminated by `type: "walletconnect"`.
112
- * Its accounts appear in `accounts`, each carrying its own `platform`.
113
- */
114
- type WalletConnectWallet = {
115
- id: WalletId;
116
- type: "walletconnect";
117
- /**
118
- * Platforms (namespaces) the live session currently carries. Empty until
119
- * connected; populated with whatever the wallet approved (e.g. just
120
- * `["ethereum"]`, or `["polkadot", "ethereum"]`).
121
- */
122
- platforms: WalletPlatform[];
123
- /**
124
- * Raw Reown AppKit instance, exposed as an escape hatch for advanced use
125
- * (custom modal control, reading providers directly). Most consumers should
126
- * use `connect`/`disconnect` and the derived accounts instead.
127
- */
128
- appKit: AppKitInstance;
129
- name: string;
130
- icon: string;
131
- isConnected: boolean;
132
- connect: () => Promise<void>;
133
- disconnect: () => Promise<void>;
134
- };
135
- /** Narrows a wallet to the platform-less {@link WalletConnectWallet}. */
136
- declare const isWalletConnectWallet: (wallet: BaseWallet | WalletConnectWallet) => wallet is WalletConnectWallet;
137
- /**
138
- * Narrows a wallet to an injected (browser-extension / Wallet Standard) wallet —
139
- * the complement of {@link isWalletConnectWallet}. `state.wallets` is
140
- * `(InjectedWallet | WalletConnectWallet)[]`, so use this to recover the
141
- * injected-only fields when iterating: `platform`, `sourceId`, and the SDK
142
- * handle (`provider` on Ethereum, `extension` on Polkadot, `wallet` on Solana).
143
- *
144
- * @example
145
- * ```ts
146
- * for (const wallet of wallets.filter(isInjectedWallet)) {
147
- * console.log(wallet.platform, wallet.sourceId); // typed, no WC widening
148
- * }
149
- * ```
150
- */
151
- declare const isInjectedWallet: <W extends BaseWallet | WalletConnectWallet>(wallet: W) => wallet is Exclude<W, WalletConnectWallet>;
152
- /**
153
- * Dapp metadata shown in the WalletConnect modal. Mirrors WalletConnect's
154
- * `Metadata`, declared locally so core doesn't depend on
155
- * `@walletconnect/universal-provider`.
156
- */
157
- type WalletConnectMetadata = {
158
- name: string;
159
- description: string;
160
- url: string;
161
- icons: string[];
162
- };
163
- type WalletConnectConfig = {
164
- projectId: string;
165
- metadata: WalletConnectMetadata;
166
- /** Defaults to wss://relay.walletconnect.com */
167
- relayUrl?: string;
168
- /**
169
- * Networks AppKit should enable. Pass `AppKitNetwork[]` from
170
- * `@reown/appkit/networks` (see
171
- * https://docs.reown.com/advanced/multichain/polkadot/dapp-integration-guide#walletconnect-code%2Fcomponent-setup).
172
- * Loosely typed (`unknown`) so core doesn't depend on `@reown/appkit`'s
173
- * types — the value is forwarded to AppKit as-is.
174
- */
175
- networks: [unknown, ...unknown[]];
176
- themeMode?: "light" | "dark";
177
- themeVariables?: Record<string, string | number>;
178
- };
179
- /**
180
- * Context passed to a platform plugin's `getWallets$`. Carries the shared store
181
- * and the resolved core config (for WalletConnect / debug).
182
- */
183
- type PlatformContext = {
184
- store: KheopskitStore;
185
- config: KheopskitConfig;
186
- };
187
- /**
188
- * A platform plugin. Created by the per-platform factories exported from
189
- * `@kheopskit/core/polkadot`, `/ethereum`, `/solana`. Core iterates plugins
190
- * generically and never imports a platform SDK itself.
191
- *
192
- * @typeParam TPlatform - the platform discriminant
193
- * @typeParam TWallet - the platform's wallet type (extends {@link BaseWallet})
194
- * @typeParam TAccount - the platform's account type (extends {@link BaseWalletAccount})
195
- */
196
- type KheopskitPlatform<TPlatform extends WalletPlatform = WalletPlatform, TWallet extends BaseWallet = BaseWallet, TAccount extends BaseWalletAccount = BaseWalletAccount> = {
197
- readonly platform: TPlatform;
198
- getWallets$(ctx: PlatformContext): Observable<TWallet[]>;
199
- getAccounts$(wallets$: Observable<(TWallet | WalletConnectWallet)[]>): Observable<TAccount[]>;
200
- /**
201
- * Optional hydration filter. Cached accounts for which this returns false are
202
- * dropped during SSR hydration (Polkadot uses it to honour `accountTypes`).
203
- */
204
- acceptsCachedAccount?(cached: CachedAccount): boolean;
205
- };
206
- type ElementOf<T> = T extends readonly (infer E)[] ? E : never;
207
- /** The account type produced by a plugin (inferred from its `getAccounts$`). */
208
- type AccountOf<T> = T extends {
209
- getAccounts$: (wallets$: never) => Observable<infer R>;
210
- } ? ElementOf<R> : never;
211
- /** The wallet type produced by a plugin (inferred from its `getWallets$`). */
212
- type WalletOf<T> = T extends {
213
- getWallets$: (ctx: never) => Observable<infer R>;
214
- } ? ElementOf<R> : never;
215
- type KheopskitConfig<P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]> = {
216
- autoReconnect: boolean;
217
- /**
218
- * Platform plugins to enable, e.g. `[polkadot(), solana({ chain })]`.
219
- * Import factories from `@kheopskit/core/<platform>`.
220
- */
221
- platforms: P;
222
- walletConnect?: WalletConnectConfig;
223
- debug: boolean;
224
- /**
225
- * Custom storage key for persisting wallet connection state.
226
- * Useful when running multiple kheopskit instances on the same domain
227
- * to prevent state conflicts between different dapps.
228
- *
229
- * @default "kheopskit"
230
- */
231
- storageKey: string;
232
- /**
233
- * Grace period in milliseconds to wait for wallets to inject before
234
- * syncing to actual state. During this period, cached wallet/account
235
- * state from storage is preserved to prevent UI flashing.
236
- *
237
- * Set to 0 to disable hydration buffering.
238
- *
239
- * @default 500
240
- */
241
- hydrationGracePeriod: number;
242
- };
243
- /**
244
- * The current kheopskit state.
245
- *
246
- * @remarks
247
- * While {@link KheopskitState.isHydrating} is `true`, `wallets` and `accounts`
248
- * may contain cached placeholders restored from storage. The **SDK handles** the
249
- * platform types advertise (e.g. `account.signer` / `getSigner` on Solana,
250
- * `account.client` on Ethereum, `wallet.provider` / `extension`) are **absent at
251
- * runtime even though the types claim them**, and placeholder wallets throw if
252
- * `connect`/`disconnect` is called. Guard all access to those behind
253
- * `!isHydrating`.
254
- *
255
- * The plain, serializable platform data that is persisted in the cache IS
256
- * restored on the placeholders (Ethereum `chainId`, Polkadot key `type`), so it
257
- * renders immediately on reload without flashing. Solana `chains` is not cached,
258
- * so it remains absent until the live account loads.
259
- */
260
- type KheopskitState<P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]> = {
261
- wallets: (WalletOf<P[number]> | WalletConnectWallet)[];
262
- accounts: AccountOf<P[number]>[];
263
- config: KheopskitConfig<P>;
264
- /**
265
- * Whether the state is still being hydrated from cache.
266
- *
267
- * During hydration, cached wallets/accounts may be displayed before the
268
- * actual wallet extensions have injected. See the type-level remarks: while
269
- * this is `true`, SDK-typed fields (signer/client/provider/extension) are not
270
- * present at runtime — guard all access behind `!isHydrating`.
271
- */
272
- isHydrating: boolean;
273
- };
274
- /** Shape of the persisted store data (localStorage, or cookies in compact form). */
275
- type KheopskitStoreData = {
276
- autoReconnect?: WalletId[];
277
- /** Cached wallet state for SSR hydration to prevent UI flash */
278
- cachedWallets?: CachedWallet[];
279
- /** Cached account state for SSR hydration to prevent UI flash */
280
- cachedAccounts?: CachedAccount[];
281
- };
282
- /**
283
- * The persisted settings store shared between core and framework bindings.
284
- * Declared structurally here (implemented by `createKheopskitStore`) so modules
285
- * can depend on the interface without importing the implementation.
286
- */
287
- type KheopskitStore = {
288
- observable: Observable<KheopskitStoreData>;
289
- addEnabledWalletId: (walletId: WalletId) => void;
290
- removeEnabledWalletId: (walletId: WalletId) => void;
291
- getCachedState: () => {
292
- wallets: CachedWallet[];
293
- accounts: CachedAccount[];
294
- };
295
- setCachedState: (wallets: CachedWallet[], accounts: CachedAccount[]) => void;
296
- };
297
- /**
298
- * Serializable wallet data for SSR hydration cache.
299
- * Contains only the data needed to render wallet UI without flash.
300
- * Note: icon is NOT stored to save cookie space - it's looked up at hydration time.
301
- */
302
- type CachedWallet = {
303
- id: WalletId;
304
- /** Absent for the platform-less WalletConnect connector. */
305
- platform?: WalletPlatform;
306
- type: WalletType;
307
- name: string;
308
- isConnected: boolean;
309
- };
310
- /**
311
- * Serializable account data for SSR hydration cache.
312
- * Contains only the data needed to render account UI without flash.
313
- */
314
- type CachedAccount = {
315
- id: string;
316
- platform: WalletPlatform;
317
- address: string;
318
- name?: string;
319
- /** Cached chain ID for Ethereum accounts. */
320
- chainId?: number;
321
- /** Cached key type for Polkadot accounts. */
322
- polkadotAccountType?: PolkadotAccountType;
323
- walletId: WalletId;
324
- walletName: string;
325
- };
326
-
327
- export { type AccountOf as A, type BaseWallet as B, type CachedAccount as C, type KheopskitPlatform as K, type PlatformContext as P, type WalletAccountId as W, type WalletId as a, type WalletConnectWallet as b, isWalletConnectWallet as c, type KheopskitConfig as d, type KheopskitStore as e, type BaseWalletAccount as f, type KheopskitState as g, type AppKitInstance as h, isInjectedWallet as i, type CachedWallet as j, type KheopskitStoreData as k, type PolkadotAccountType as l, type WalletConnectConfig as m, type WalletConnectMetadata as n, type WalletConnectProvider as o, type WalletOf as p, type WalletPlatform as q, type WalletType as r, getWalletAccountId as s, getWalletId as t, isValidWalletId as u, parseWalletAccountId as v, parseWalletId as w };
@@ -1,327 +0,0 @@
1
- import { Observable } from 'rxjs';
2
-
3
- type WalletAccountId = string;
4
- declare const getWalletAccountId: (walletId: string, address: string) => WalletAccountId;
5
- declare const parseWalletAccountId: (accountId: string) => {
6
- walletId: string;
7
- address: string;
8
- };
9
-
10
- type WalletId = string;
11
- declare const getWalletId: (platform: WalletPlatform, identifier: string) => WalletId;
12
- declare const parseWalletId: (walletId: string) => {
13
- platform: WalletPlatform;
14
- identifier: string;
15
- };
16
- /**
17
- * Non-throwing variant of {@link parseWalletId}. Use when validating untrusted
18
- * input (e.g. cached state persisted by an older version) before parsing.
19
- */
20
- declare const isValidWalletId: (walletId: unknown) => walletId is WalletId;
21
-
22
- type WalletPlatform = "polkadot" | "ethereum" | "solana";
23
- /**
24
- * Minimal structural view of a WalletConnect `UniversalProvider` — the subset
25
- * kheopskit reads. Declared locally so core never depends on
26
- * `@walletconnect/universal-provider`. The concrete instance comes from
27
- * `@reown/appkit` at runtime.
28
- */
29
- type WalletConnectProvider = {
30
- session?: {
31
- topic: string;
32
- namespaces: Record<string, {
33
- accounts?: string[];
34
- }>;
35
- };
36
- client: {
37
- request<T = unknown>(args: {
38
- topic: string;
39
- chainId: string;
40
- request: {
41
- method: string;
42
- params: unknown;
43
- };
44
- }): Promise<T>;
45
- };
46
- request(args: {
47
- method: string;
48
- params?: unknown;
49
- }): Promise<unknown>;
50
- on(event: string, listener: (...args: unknown[]) => void): void;
51
- off(event: string, listener: (...args: unknown[]) => void): void;
52
- };
53
- /**
54
- * Minimal structural view of the Reown AppKit instance — the subset kheopskit's
55
- * account factories use. Exposed as the `appKit` escape hatch on AppKit wallets;
56
- * cast it to `@reown/appkit`'s `AppKit` type for the full API. Declared locally
57
- * so core never depends on `@reown/appkit`'s types (it's an optional peer).
58
- */
59
- type AppKitInstance = {
60
- getProvider<T = WalletConnectProvider>(namespace: string): T | undefined;
61
- getAccount(namespace: string): {
62
- allAccounts: {
63
- address: string;
64
- }[];
65
- } | undefined;
66
- getCaipNetworks(namespace: string): {
67
- caipNetworkId?: string;
68
- }[];
69
- };
70
- type WalletType = "injected" | "walletconnect";
71
- type PolkadotAccountType = "sr25519" | "ed25519" | "ecdsa" | "ethereum";
72
- /**
73
- * SDK-free fields common to every wallet, regardless of platform. Platform
74
- * packages (`@kheopskit/core/<platform>`) extend this with SDK-typed fields
75
- * (the injected provider/extension/standard-wallet handle).
76
- */
77
- type BaseWallet = {
78
- id: WalletId;
79
- platform: WalletPlatform;
80
- type: WalletType;
81
- name: string;
82
- icon: string;
83
- isConnected: boolean;
84
- connect: () => Promise<void>;
85
- /**
86
- * Disconnect the wallet. Resolves once the underlying provider/extension
87
- * disconnect completes; rejects if it fails so callers can surface or retry.
88
- */
89
- disconnect: () => Promise<void>;
90
- };
91
- /**
92
- * SDK-free fields common to every account, regardless of platform. Platform
93
- * packages extend this with their SDK-typed signer/client.
94
- */
95
- type BaseWalletAccount = {
96
- id: WalletAccountId;
97
- platform: WalletPlatform;
98
- /** Base58 (Solana), SS58 (Polkadot) or 0x-hex (Ethereum) address. */
99
- address: string;
100
- /** Friendly account name, when the wallet exposes one (e.g. Polkadot). */
101
- name?: string;
102
- walletName: string;
103
- walletId: WalletId;
104
- };
105
- /**
106
- * The single WalletConnect connector, shared across every platform.
107
- *
108
- * Unlike injected wallets, it is **not tied to a platform**: one WalletConnect
109
- * session spans whichever namespaces the remote wallet approves in a single
110
- * pairing (a namespace can't be added to a live session afterwards). So there is
111
- * exactly one of these in `wallets`, discriminated by `type: "walletconnect"`.
112
- * Its accounts appear in `accounts`, each carrying its own `platform`.
113
- */
114
- type WalletConnectWallet = {
115
- id: WalletId;
116
- type: "walletconnect";
117
- /**
118
- * Platforms (namespaces) the live session currently carries. Empty until
119
- * connected; populated with whatever the wallet approved (e.g. just
120
- * `["ethereum"]`, or `["polkadot", "ethereum"]`).
121
- */
122
- platforms: WalletPlatform[];
123
- /**
124
- * Raw Reown AppKit instance, exposed as an escape hatch for advanced use
125
- * (custom modal control, reading providers directly). Most consumers should
126
- * use `connect`/`disconnect` and the derived accounts instead.
127
- */
128
- appKit: AppKitInstance;
129
- name: string;
130
- icon: string;
131
- isConnected: boolean;
132
- connect: () => Promise<void>;
133
- disconnect: () => Promise<void>;
134
- };
135
- /** Narrows a wallet to the platform-less {@link WalletConnectWallet}. */
136
- declare const isWalletConnectWallet: (wallet: BaseWallet | WalletConnectWallet) => wallet is WalletConnectWallet;
137
- /**
138
- * Narrows a wallet to an injected (browser-extension / Wallet Standard) wallet —
139
- * the complement of {@link isWalletConnectWallet}. `state.wallets` is
140
- * `(InjectedWallet | WalletConnectWallet)[]`, so use this to recover the
141
- * injected-only fields when iterating: `platform`, `sourceId`, and the SDK
142
- * handle (`provider` on Ethereum, `extension` on Polkadot, `wallet` on Solana).
143
- *
144
- * @example
145
- * ```ts
146
- * for (const wallet of wallets.filter(isInjectedWallet)) {
147
- * console.log(wallet.platform, wallet.sourceId); // typed, no WC widening
148
- * }
149
- * ```
150
- */
151
- declare const isInjectedWallet: <W extends BaseWallet | WalletConnectWallet>(wallet: W) => wallet is Exclude<W, WalletConnectWallet>;
152
- /**
153
- * Dapp metadata shown in the WalletConnect modal. Mirrors WalletConnect's
154
- * `Metadata`, declared locally so core doesn't depend on
155
- * `@walletconnect/universal-provider`.
156
- */
157
- type WalletConnectMetadata = {
158
- name: string;
159
- description: string;
160
- url: string;
161
- icons: string[];
162
- };
163
- type WalletConnectConfig = {
164
- projectId: string;
165
- metadata: WalletConnectMetadata;
166
- /** Defaults to wss://relay.walletconnect.com */
167
- relayUrl?: string;
168
- /**
169
- * Networks AppKit should enable. Pass `AppKitNetwork[]` from
170
- * `@reown/appkit/networks` (see
171
- * https://docs.reown.com/advanced/multichain/polkadot/dapp-integration-guide#walletconnect-code%2Fcomponent-setup).
172
- * Loosely typed (`unknown`) so core doesn't depend on `@reown/appkit`'s
173
- * types — the value is forwarded to AppKit as-is.
174
- */
175
- networks: [unknown, ...unknown[]];
176
- themeMode?: "light" | "dark";
177
- themeVariables?: Record<string, string | number>;
178
- };
179
- /**
180
- * Context passed to a platform plugin's `getWallets$`. Carries the shared store
181
- * and the resolved core config (for WalletConnect / debug).
182
- */
183
- type PlatformContext = {
184
- store: KheopskitStore;
185
- config: KheopskitConfig;
186
- };
187
- /**
188
- * A platform plugin. Created by the per-platform factories exported from
189
- * `@kheopskit/core/polkadot`, `/ethereum`, `/solana`. Core iterates plugins
190
- * generically and never imports a platform SDK itself.
191
- *
192
- * @typeParam TPlatform - the platform discriminant
193
- * @typeParam TWallet - the platform's wallet type (extends {@link BaseWallet})
194
- * @typeParam TAccount - the platform's account type (extends {@link BaseWalletAccount})
195
- */
196
- type KheopskitPlatform<TPlatform extends WalletPlatform = WalletPlatform, TWallet extends BaseWallet = BaseWallet, TAccount extends BaseWalletAccount = BaseWalletAccount> = {
197
- readonly platform: TPlatform;
198
- getWallets$(ctx: PlatformContext): Observable<TWallet[]>;
199
- getAccounts$(wallets$: Observable<(TWallet | WalletConnectWallet)[]>): Observable<TAccount[]>;
200
- /**
201
- * Optional hydration filter. Cached accounts for which this returns false are
202
- * dropped during SSR hydration (Polkadot uses it to honour `accountTypes`).
203
- */
204
- acceptsCachedAccount?(cached: CachedAccount): boolean;
205
- };
206
- type ElementOf<T> = T extends readonly (infer E)[] ? E : never;
207
- /** The account type produced by a plugin (inferred from its `getAccounts$`). */
208
- type AccountOf<T> = T extends {
209
- getAccounts$: (wallets$: never) => Observable<infer R>;
210
- } ? ElementOf<R> : never;
211
- /** The wallet type produced by a plugin (inferred from its `getWallets$`). */
212
- type WalletOf<T> = T extends {
213
- getWallets$: (ctx: never) => Observable<infer R>;
214
- } ? ElementOf<R> : never;
215
- type KheopskitConfig<P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]> = {
216
- autoReconnect: boolean;
217
- /**
218
- * Platform plugins to enable, e.g. `[polkadot(), solana({ chain })]`.
219
- * Import factories from `@kheopskit/core/<platform>`.
220
- */
221
- platforms: P;
222
- walletConnect?: WalletConnectConfig;
223
- debug: boolean;
224
- /**
225
- * Custom storage key for persisting wallet connection state.
226
- * Useful when running multiple kheopskit instances on the same domain
227
- * to prevent state conflicts between different dapps.
228
- *
229
- * @default "kheopskit"
230
- */
231
- storageKey: string;
232
- /**
233
- * Grace period in milliseconds to wait for wallets to inject before
234
- * syncing to actual state. During this period, cached wallet/account
235
- * state from storage is preserved to prevent UI flashing.
236
- *
237
- * Set to 0 to disable hydration buffering.
238
- *
239
- * @default 500
240
- */
241
- hydrationGracePeriod: number;
242
- };
243
- /**
244
- * The current kheopskit state.
245
- *
246
- * @remarks
247
- * While {@link KheopskitState.isHydrating} is `true`, `wallets` and `accounts`
248
- * may contain cached placeholders restored from storage. The **SDK handles** the
249
- * platform types advertise (e.g. `account.signer` / `getSigner` on Solana,
250
- * `account.client` on Ethereum, `wallet.provider` / `extension`) are **absent at
251
- * runtime even though the types claim them**, and placeholder wallets throw if
252
- * `connect`/`disconnect` is called. Guard all access to those behind
253
- * `!isHydrating`.
254
- *
255
- * The plain, serializable platform data that is persisted in the cache IS
256
- * restored on the placeholders (Ethereum `chainId`, Polkadot key `type`), so it
257
- * renders immediately on reload without flashing. Solana `chains` is not cached,
258
- * so it remains absent until the live account loads.
259
- */
260
- type KheopskitState<P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]> = {
261
- wallets: (WalletOf<P[number]> | WalletConnectWallet)[];
262
- accounts: AccountOf<P[number]>[];
263
- config: KheopskitConfig<P>;
264
- /**
265
- * Whether the state is still being hydrated from cache.
266
- *
267
- * During hydration, cached wallets/accounts may be displayed before the
268
- * actual wallet extensions have injected. See the type-level remarks: while
269
- * this is `true`, SDK-typed fields (signer/client/provider/extension) are not
270
- * present at runtime — guard all access behind `!isHydrating`.
271
- */
272
- isHydrating: boolean;
273
- };
274
- /** Shape of the persisted store data (localStorage, or cookies in compact form). */
275
- type KheopskitStoreData = {
276
- autoReconnect?: WalletId[];
277
- /** Cached wallet state for SSR hydration to prevent UI flash */
278
- cachedWallets?: CachedWallet[];
279
- /** Cached account state for SSR hydration to prevent UI flash */
280
- cachedAccounts?: CachedAccount[];
281
- };
282
- /**
283
- * The persisted settings store shared between core and framework bindings.
284
- * Declared structurally here (implemented by `createKheopskitStore`) so modules
285
- * can depend on the interface without importing the implementation.
286
- */
287
- type KheopskitStore = {
288
- observable: Observable<KheopskitStoreData>;
289
- addEnabledWalletId: (walletId: WalletId) => void;
290
- removeEnabledWalletId: (walletId: WalletId) => void;
291
- getCachedState: () => {
292
- wallets: CachedWallet[];
293
- accounts: CachedAccount[];
294
- };
295
- setCachedState: (wallets: CachedWallet[], accounts: CachedAccount[]) => void;
296
- };
297
- /**
298
- * Serializable wallet data for SSR hydration cache.
299
- * Contains only the data needed to render wallet UI without flash.
300
- * Note: icon is NOT stored to save cookie space - it's looked up at hydration time.
301
- */
302
- type CachedWallet = {
303
- id: WalletId;
304
- /** Absent for the platform-less WalletConnect connector. */
305
- platform?: WalletPlatform;
306
- type: WalletType;
307
- name: string;
308
- isConnected: boolean;
309
- };
310
- /**
311
- * Serializable account data for SSR hydration cache.
312
- * Contains only the data needed to render account UI without flash.
313
- */
314
- type CachedAccount = {
315
- id: string;
316
- platform: WalletPlatform;
317
- address: string;
318
- name?: string;
319
- /** Cached chain ID for Ethereum accounts. */
320
- chainId?: number;
321
- /** Cached key type for Polkadot accounts. */
322
- polkadotAccountType?: PolkadotAccountType;
323
- walletId: WalletId;
324
- walletName: string;
325
- };
326
-
327
- export { type AccountOf as A, type BaseWallet as B, type CachedAccount as C, type KheopskitPlatform as K, type PlatformContext as P, type WalletAccountId as W, type WalletId as a, type WalletConnectWallet as b, isWalletConnectWallet as c, type KheopskitConfig as d, type KheopskitStore as e, type BaseWalletAccount as f, type KheopskitState as g, type AppKitInstance as h, isInjectedWallet as i, type CachedWallet as j, type KheopskitStoreData as k, type PolkadotAccountType as l, type WalletConnectConfig as m, type WalletConnectMetadata as n, type WalletConnectProvider as o, type WalletOf as p, type WalletPlatform as q, type WalletType as r, getWalletAccountId as s, getWalletId as t, isValidWalletId as u, parseWalletAccountId as v, parseWalletId as w };