@kheopskit/core 5.3.0 → 6.0.0-rc.1

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 (83) hide show
  1. package/CHANGELOG.md +432 -0
  2. package/MIGRATING_TO_V6.md +840 -0
  3. package/README.md +629 -12
  4. package/dist/ethereum.d.mts +12 -6
  5. package/dist/ethereum.d.ts +12 -6
  6. package/dist/ethereum.js +13 -10
  7. package/dist/ethereum.js.map +1 -1
  8. package/dist/ethereum.mjs +7 -4
  9. package/dist/ethereum.mjs.map +1 -1
  10. package/dist/{iconCache-pP2ES4pJ.mjs → iconCache-C-U3IEbP.mjs} +21 -40
  11. package/dist/iconCache-C-U3IEbP.mjs.map +1 -0
  12. package/dist/{iconCache-DUtkJlaX.js → iconCache-FR4iy6go.js} +21 -40
  13. package/dist/iconCache-FR4iy6go.js.map +1 -0
  14. package/dist/index.d.mts +17 -63
  15. package/dist/index.d.ts +17 -63
  16. package/dist/index.js +387 -373
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +384 -369
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/injectedWallets-48L-AL1I.mjs +173 -0
  21. package/dist/injectedWallets-48L-AL1I.mjs.map +1 -0
  22. package/dist/injectedWallets-Dy8YGKL-.js +178 -0
  23. package/dist/injectedWallets-Dy8YGKL-.js.map +1 -0
  24. package/dist/internal.d.mts +3 -27
  25. package/dist/internal.d.ts +3 -27
  26. package/dist/internal.js +2 -2
  27. package/dist/internal.mjs +2 -2
  28. package/dist/pageLoad-BZ7o8p5R.mjs +24 -0
  29. package/dist/pageLoad-BZ7o8p5R.mjs.map +1 -0
  30. package/dist/pageLoad-D1wLeuFG.js +28 -0
  31. package/dist/pageLoad-D1wLeuFG.js.map +1 -0
  32. package/dist/platformAccounts-BjIeRcFN.js +321 -0
  33. package/dist/platformAccounts-BjIeRcFN.js.map +1 -0
  34. package/dist/platformAccounts-yyRUrnel.mjs +256 -0
  35. package/dist/platformAccounts-yyRUrnel.mjs.map +1 -0
  36. package/dist/polkadot.d.mts +127 -11
  37. package/dist/polkadot.d.ts +127 -11
  38. package/dist/polkadot.js +187 -106
  39. package/dist/polkadot.js.map +1 -1
  40. package/dist/polkadot.mjs +180 -99
  41. package/dist/polkadot.mjs.map +1 -1
  42. package/dist/solana.d.mts +11 -5
  43. package/dist/solana.d.ts +11 -5
  44. package/dist/solana.js +18 -15
  45. package/dist/solana.js.map +1 -1
  46. package/dist/solana.mjs +7 -4
  47. package/dist/solana.mjs.map +1 -1
  48. package/dist/storage-D3AwNgqc.d.mts +27 -0
  49. package/dist/storage-D3AwNgqc.d.ts +27 -0
  50. package/dist/testing.d.mts +71 -0
  51. package/dist/testing.d.ts +71 -0
  52. package/dist/testing.js +136 -0
  53. package/dist/testing.js.map +1 -0
  54. package/dist/testing.mjs +131 -0
  55. package/dist/testing.mjs.map +1 -0
  56. package/dist/{types-DKU-SNio.js → types-BWHvNFlN.js} +149 -2
  57. package/dist/types-BWHvNFlN.js.map +1 -0
  58. package/dist/types-Yor672md.mjs +215 -0
  59. package/dist/types-Yor672md.mjs.map +1 -0
  60. package/dist/types-lkMXVJNG.d.mts +685 -0
  61. package/dist/types-lkMXVJNG.d.ts +685 -0
  62. package/dist/walletconnect.d.mts +41 -0
  63. package/dist/walletconnect.d.ts +41 -0
  64. package/dist/walletconnect.js +219 -0
  65. package/dist/walletconnect.js.map +1 -0
  66. package/dist/walletconnect.mjs +216 -0
  67. package/dist/walletconnect.mjs.map +1 -0
  68. package/package.json +30 -6
  69. package/dist/errors-BLFP1dQI.mjs +0 -181
  70. package/dist/errors-BLFP1dQI.mjs.map +0 -1
  71. package/dist/errors-DYWVPHrR.js +0 -222
  72. package/dist/errors-DYWVPHrR.js.map +0 -1
  73. package/dist/iconCache-DUtkJlaX.js.map +0 -1
  74. package/dist/iconCache-pP2ES4pJ.mjs.map +0 -1
  75. package/dist/injectedWallets-BqR-_aAy.js +0 -148
  76. package/dist/injectedWallets-BqR-_aAy.js.map +0 -1
  77. package/dist/injectedWallets-Uz4hPuoW.mjs +0 -119
  78. package/dist/injectedWallets-Uz4hPuoW.mjs.map +0 -1
  79. package/dist/types-AxUDtkR-.d.mts +0 -338
  80. package/dist/types-AxUDtkR-.d.ts +0 -338
  81. package/dist/types-DKU-SNio.js.map +0 -1
  82. package/dist/types-jnifAAA0.mjs +0 -104
  83. package/dist/types-jnifAAA0.mjs.map +0 -1
@@ -0,0 +1,685 @@
1
+ import { Observable } from "rxjs";
2
+ //#region src/utils/WalletAccountId.d.ts
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
+ //#endregion
10
+ //#region src/utils/WalletId.d.ts
11
+ type WalletId = string;
12
+ declare const getWalletId: (platform: WalletPlatform, identifier: string) => WalletId;
13
+ declare const parseWalletId: (walletId: string) => {
14
+ platform: WalletPlatform;
15
+ identifier: string;
16
+ };
17
+ /**
18
+ * Non-throwing variant of {@link parseWalletId}. Use when validating untrusted
19
+ * input (e.g. cached state persisted by an older version) before parsing.
20
+ */
21
+ declare const isValidWalletId: (walletId: unknown) => walletId is WalletId;
22
+ //#endregion
23
+ //#region src/api/errors.d.ts
24
+ /**
25
+ * Stable error codes thrown by kheopskit. Catch a {@link KheopskitError} and
26
+ * branch on `error.code` instead of matching message strings.
27
+ */
28
+ type KheopskitErrorCode =
29
+ /**
30
+ * This `connect()` or `disconnect()` call was abandoned. For `connect()`:
31
+ * its `signal` fired before the platform answered, `disconnect()` was
32
+ * called while it pended, its wallet disappeared, or the last `kheopskit$`
33
+ * subscriber unsubscribed.
34
+ * For either call on an injected wallet: the wallet object came from a
35
+ * subscription that had already ended, in which case the call rejects
36
+ * without asking the platform and without changing the remembered list. A
37
+ * placeholder's `connect()` rejects the same way, its `disconnect()`
38
+ * resolves, and the WalletConnect connector still calls AppKit.
39
+ */
40
+ "ABORTED" |
41
+ /** The user refused the wallet's connect prompt. `cause` holds the platform error. */
42
+ "USER_REJECTED" |
43
+ /** The wallet's connect call failed for another reason. `cause` holds the platform error. */
44
+ "CONNECT_FAILED" |
45
+ /**
46
+ * `connect()` was called on a placeholder wallet restored from the cache:
47
+ * on `kheopskit$`, hydration ended without kheopskit discovering that
48
+ * wallet; on `getHydratedSnapshot` and the React provider's initial
49
+ * snapshot, always.
50
+ */
51
+ "WALLET_PENDING" |
52
+ /** The wallet does not advertise a capability kheopskit needs to proceed. */
53
+ "FEATURE_NOT_SUPPORTED" |
54
+ /** No active WalletConnect session for the requested operation. */
55
+ "NO_SESSION" |
56
+ /** No provider available for the requested namespace. */
57
+ "NO_PROVIDER" |
58
+ /** The installed polkadot-api version exposes neither `getTxCreatorFromPjs` (v3) nor `getPolkadotSignerFromPjs` (v2). */
59
+ "UNSUPPORTED_VERSION" |
60
+ /** The requested chain cannot be used for this operation (e.g. a Solana cluster with no CAIP-2 id over WalletConnect). */
61
+ "UNSUPPORTED_CHAIN" |
62
+ /** `getKheopskit$` received a config value it cannot use. The message names the fix. */
63
+ "INVALID_CONFIG";
64
+ /**
65
+ * Error thrown by kheopskit wallet/account operations. Carries a stable
66
+ * {@link KheopskitErrorCode} and, when relevant, the offending wallet id.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * try {
71
+ * await wallet.connect();
72
+ * } catch (error) {
73
+ * if (error instanceof KheopskitError && error.code === "USER_REJECTED") {
74
+ * // the user closed or refused the wallet prompt
75
+ * } else throw error;
76
+ * }
77
+ * ```
78
+ */
79
+ declare class KheopskitError extends Error {
80
+ readonly code: KheopskitErrorCode;
81
+ /** The wallet id this error relates to, when applicable. */
82
+ readonly walletId?: WalletId;
83
+ constructor(code: KheopskitErrorCode, message: string, options?: {
84
+ walletId?: WalletId;
85
+ cause?: unknown;
86
+ });
87
+ }
88
+ //#endregion
89
+ //#region src/api/types.d.ts
90
+ type WalletPlatform = "polkadot" | "ethereum" | "solana";
91
+ /**
92
+ * Minimal structural view of a WalletConnect `UniversalProvider`, the subset
93
+ * kheopskit reads. Declared locally so core never depends on
94
+ * `@walletconnect/universal-provider`. The concrete instance comes from
95
+ * `@reown/appkit` at runtime.
96
+ */
97
+ type WalletConnectProvider = {
98
+ session?: {
99
+ topic: string;
100
+ namespaces: Record<string, {
101
+ accounts?: string[];
102
+ }>;
103
+ };
104
+ client: {
105
+ request<T = unknown>(args: {
106
+ topic: string;
107
+ chainId: string;
108
+ request: {
109
+ method: string;
110
+ params: unknown;
111
+ };
112
+ }): Promise<T>;
113
+ };
114
+ request(args: {
115
+ method: string;
116
+ params?: unknown;
117
+ }): Promise<unknown>;
118
+ on(event: string, listener: (...args: unknown[]) => void): void;
119
+ off(event: string, listener: (...args: unknown[]) => void): void;
120
+ };
121
+ /**
122
+ * Minimal structural view of the Reown AppKit instance, the subset kheopskit's
123
+ * account factories use. Exposed as the `appKit` escape hatch on AppKit wallets;
124
+ * cast it to `@reown/appkit`'s `AppKit` type for the full API. Declared locally
125
+ * so core never depends on `@reown/appkit`'s types (it's an optional peer).
126
+ */
127
+ type AppKitInstance = {
128
+ getProvider<T = WalletConnectProvider>(namespace: string): T | undefined;
129
+ getAccount(namespace: string): {
130
+ allAccounts: {
131
+ address: string;
132
+ }[];
133
+ } | undefined;
134
+ getCaipNetworks(namespace: string): {
135
+ caipNetworkId?: string;
136
+ }[];
137
+ };
138
+ type WalletType = "injected" | "walletconnect";
139
+ /**
140
+ * Where a wallet stands with the dapp. `connecting` covers a `connect()` call
141
+ * in flight and an auto-reconnect in flight alike.
142
+ */
143
+ type WalletStatus = "disconnected" | "connecting" | "connected";
144
+ type PolkadotAccountType = "sr25519" | "ed25519" | "ecdsa" | "ethereum";
145
+ /** Options accepted by {@link BaseWallet.connect}. */
146
+ type ConnectOptions = {
147
+ /**
148
+ * Ends this caller's wait for the platform's answer: its promise rejects
149
+ * with a `KheopskitError` of code `ABORTED`. An abort after the platform
150
+ * has granted the connect changes nothing, and a Polkadot extension counts
151
+ * as granted only once its account list has been read. Other callers
152
+ * sharing the attempt keep waiting. The extension's own prompt may stay
153
+ * open: nothing can withdraw it from the page. A Polkadot `connect()`
154
+ * started while that prompt is open waits for it instead of asking again,
155
+ * and connects with the handle it answers. Once no caller waits any more
156
+ * and no later `connect()` joined that prompt, kheopskit drops a handle
157
+ * the platform hands back afterwards without revoking the platform's
158
+ * grant, and the wallet is neither connected nor remembered. Kheopskit
159
+ * sets no timeout of its own, because an extension prompt
160
+ * pends only while the user has not answered it; pass
161
+ * `AbortSignal.timeout(ms)` to cap the wait.
162
+ */
163
+ signal?: AbortSignal;
164
+ };
165
+ /**
166
+ * SDK-free fields common to every wallet, regardless of platform. Platform
167
+ * packages (`@kheopskit/core/<platform>`) extend this with SDK-typed fields
168
+ * (the injected provider/extension/standard-wallet handle).
169
+ */
170
+ type BaseWallet = {
171
+ /** `<platform>:<identifier>`, e.g. `polkadot:talisman`. Stable across reloads. */
172
+ id: WalletId;
173
+ /** The platform whose registry listed the wallet. */
174
+ platform: WalletPlatform;
175
+ /**
176
+ * `"injected"`, for a browser extension or Wallet Standard wallet. The
177
+ * WalletConnect connector is the separate {@link WalletConnectWallet}.
178
+ */
179
+ type: WalletType;
180
+ /** Display name, e.g. `Talisman`. */
181
+ name: string;
182
+ /** Icon URL or data URI. `""` when the wallet exposes none. */
183
+ icon: string;
184
+ /**
185
+ * `true` for a wallet restored from the cache that kheopskit has not
186
+ * discovered yet: its SDK handle and `sourceId` are absent and it is never
187
+ * connected. On `kheopskit$` its `connect()` waits for the live wallet and
188
+ * connects that one, rejecting with `WALLET_PENDING` if hydration ends first
189
+ * and `ABORTED` if its `signal` fires or the subscription ends. On
190
+ * `getHydratedSnapshot` it rejects with `WALLET_PENDING`. Its `disconnect()`
191
+ * resolves at once. Set on every wallet of `kheopskit$` and of the hydrated
192
+ * snapshot; plugins leave it unset.
193
+ */
194
+ isPlaceholder?: boolean;
195
+ /**
196
+ * `connecting` while a `connect()` call or an auto-reconnect waits for the
197
+ * platform, `connected` once the platform granted it, `disconnected`
198
+ * otherwise. On a reload, a remembered wallet kheopskit will reconnect is
199
+ * `connecting` from the first frame when the cache recorded it connected,
200
+ * which the cache does 1 s after the state settles.
201
+ */
202
+ status: WalletStatus;
203
+ /**
204
+ * The last `connect()` or auto-reconnect that the platform refused or
205
+ * failed (`USER_REJECTED` or `CONNECT_FAILED`, or `FEATURE_NOT_SUPPORTED`
206
+ * for a Wallet Standard wallet without `standard:connect`). Cleared when
207
+ * the next attempt starts. An aborted attempt sets nothing.
208
+ */
209
+ error?: KheopskitError;
210
+ /** `status === "connected"`. */
211
+ isConnected: boolean;
212
+ /**
213
+ * Connects the wallet.
214
+ *
215
+ * - **Shared in flight.** Concurrent calls on one wallet share a single
216
+ * platform attempt and the platform is asked once. Each call gets its own
217
+ * promise: aborting a caller's `signal` rejects only that caller with code
218
+ * `ABORTED`. The attempt itself is abandoned only when every caller that
219
+ * passed a signal has aborted and no caller without one joined, when
220
+ * `disconnect()` is called, or when the last `kheopskit$` subscriber
221
+ * unsubscribes; those reject every remaining caller with `ABORTED`.
222
+ * - **Idempotent.** On a connected wallet it resolves at once without
223
+ * touching the platform, unless a `disconnect()` still waits for the
224
+ * platform. It then waits for that disconnect to settle and connects
225
+ * again if the wallet ended up disconnected.
226
+ * - **Abortable.** See {@link ConnectOptions.signal}. There is no default
227
+ * timeout.
228
+ * - **Settles with the state.** It resolves only after `kheopskit$` has
229
+ * emitted a state in which this wallet has `isConnected: true`, so the
230
+ * consumer-visible state already reflects the connect. On platforms that
231
+ * list accounts asynchronously (Ethereum `eth_accounts`), the accounts may
232
+ * arrive in a later emission. No emission shows a disconnected wallet
233
+ * still listing live accounts, or a connected wallet listing the accounts
234
+ * of a previous connection. During hydration a wallet's cached
235
+ * placeholder accounts stay listed whatever its status. Another wallet's
236
+ * pending `eth_accounts` request never delays them. A `disconnect()` that
237
+ * completes while it waits for that state rejects it with `ABORTED`. If
238
+ * the platform's disconnect is still pending or refuses, it resolves once
239
+ * the state shows the wallet connected (today only Solana has a platform
240
+ * disconnect). A `connect()`
241
+ * whose wallet disappears before the platform grants it (an extension
242
+ * removed, a Wallet Standard wallet unregistered) rejects `ABORTED`;
243
+ * granted first, it resolves and the wallet stays remembered. Once the last `kheopskit$`
244
+ * subscriber has unsubscribed, a call on a wallet object from that
245
+ * subscription rejects with `ABORTED` without asking the platform,
246
+ * placeholders included.
247
+ * - **Typed rejections.** A platform rejection is wrapped in a
248
+ * `KheopskitError` carrying the original error as `cause` and the
249
+ * `walletId`: `USER_REJECTED` when the user refused the prompt,
250
+ * `CONNECT_FAILED` otherwise. A Wallet Standard wallet without
251
+ * `standard:connect` rejects with `FEATURE_NOT_SUPPORTED`.
252
+ */
253
+ connect: (options?: ConnectOptions) => Promise<void>;
254
+ /**
255
+ * Disconnects the wallet.
256
+ *
257
+ * On a disconnected wallet it resolves at once. While a `connect()` waits
258
+ * for the platform to grant it, it aborts that connect (its promise rejects
259
+ * with `ABORTED`) and never waits for the extension prompt. Otherwise it
260
+ * first waits for the platform's disconnect and rejects if that fails, so
261
+ * callers can surface or retry. It then resolves once `kheopskit$` has
262
+ * emitted a state in which this wallet has `isConnected: false`, or once a
263
+ * later `connect()`, the wallet leaving the list or the end of the
264
+ * subscription makes that emission impossible. Once the last `kheopskit$`
265
+ * subscriber has unsubscribed, a call on a wallet object from that
266
+ * subscription rejects with `ABORTED` without asking the platform and
267
+ * without changing the remembered list, except on a placeholder, whose
268
+ * `disconnect()` resolves. A `disconnect()` started before that point
269
+ * settles once the platform has answered: the wallet was
270
+ * forgotten when it was called, and nothing else is written once the
271
+ * subscription has ended.
272
+ */
273
+ disconnect: () => Promise<void>;
274
+ };
275
+ /**
276
+ * SDK-free fields common to every account, regardless of platform. Platform
277
+ * packages extend this with their SDK-typed signer/client.
278
+ */
279
+ type BaseWalletAccount = {
280
+ /** `<walletId>::<address>`, e.g. `polkadot:talisman::5Grw…`. */
281
+ id: WalletAccountId;
282
+ /**
283
+ * `true` for an account restored from the cache that the live wallet has
284
+ * not listed yet: its signing surface is absent. Set on every account of
285
+ * `kheopskit$` and of the hydrated snapshot; plugins leave it unset.
286
+ */
287
+ isPlaceholder?: boolean;
288
+ /** The platform of the wallet that lists the account. */
289
+ platform: WalletPlatform;
290
+ /** Base58 (Solana), SS58 (Polkadot) or 0x-hex (Ethereum) address. */
291
+ address: string;
292
+ /** Friendly account name, when the wallet exposes one (e.g. Polkadot). */
293
+ name?: string;
294
+ /** `name` of the wallet that lists the account. */
295
+ walletName: string;
296
+ /** `id` of the wallet that lists the account. */
297
+ walletId: WalletId;
298
+ };
299
+ type LiveWalletConnectWallet = {
300
+ /** See {@link BaseWallet.isPlaceholder}. */
301
+ isPlaceholder?: false;
302
+ /** `"walletconnect"`, the one connector shared by every platform. */
303
+ id: WalletId;
304
+ /** Narrow with {@link isWalletConnectWallet}. */
305
+ type: "walletconnect";
306
+ /**
307
+ * Platforms (namespaces) the live session currently carries. Empty until
308
+ * connected; populated with whatever the wallet approved (e.g. just
309
+ * `["ethereum"]`, or `["polkadot", "ethereum"]`).
310
+ */
311
+ platforms: WalletPlatform[];
312
+ /**
313
+ * Raw Reown AppKit instance, exposed as an escape hatch for advanced use
314
+ * (custom modal control, reading providers directly). Most consumers should
315
+ * use `connect`/`disconnect` and the derived accounts instead.
316
+ */
317
+ appKit: AppKitInstance;
318
+ /** The name AppKit reports for the paired wallet, `"WalletConnect"` when it reports none. */
319
+ name: string;
320
+ /** The icon AppKit reports for the paired wallet, the WalletConnect logo when it reports none. */
321
+ icon: string;
322
+ /**
323
+ * `connecting` while `connect()` opens the modal, `connected` while a
324
+ * session is live, `disconnected` otherwise. On a reload with a cached
325
+ * session it is `connecting` until AppKit restores the session or hydration
326
+ * ends.
327
+ */
328
+ status: WalletStatus;
329
+ /** The last `connect()` whose modal failed to open. Cleared by the next call. */
330
+ error?: KheopskitError;
331
+ /** `status === "connected"`. */
332
+ isConnected: boolean;
333
+ /**
334
+ * Opens the WalletConnect modal and resolves once it is open; `isConnected`
335
+ * follows when the user approves a session. Unlike injected wallets, this
336
+ * promise does not wait for the state to show the connector connected, and
337
+ * `signal` is accepted for signature compatibility only.
338
+ */
339
+ connect: (options?: ConnectOptions) => Promise<void>;
340
+ /** Ends the live session when there is one; resolves at once otherwise. */
341
+ disconnect: () => Promise<void>;
342
+ };
343
+ /**
344
+ * The single WalletConnect connector, shared across every platform.
345
+ *
346
+ * Unlike injected wallets, it is **not tied to a platform**: one WalletConnect
347
+ * session spans whichever namespaces the remote wallet approves in a single
348
+ * pairing (a namespace can't be added to a live session afterwards). So there is
349
+ * exactly one of these in `wallets`, discriminated by `type: "walletconnect"`.
350
+ * Its accounts appear in `accounts`, each carrying its own `platform`.
351
+ *
352
+ * A placeholder (see {@link BaseWallet.isPlaceholder}) has no `appKit`.
353
+ */
354
+ type WalletConnectWallet = LiveWalletConnectWallet | PlaceholderWallet<LiveWalletConnectWallet, "appKit">;
355
+ /**
356
+ * The cached stand-in for a live item `T`: `isPlaceholder: true`, and the
357
+ * fields `K`, which only the live item carries, absent. Platform account and
358
+ * wallet types are `T | Placeholder<T, K>`, so narrow on `isPlaceholder`
359
+ * before reading a field of `K`.
360
+ */
361
+ type Placeholder<T, K extends keyof T> = Omit<T, K | "isPlaceholder"> & {
362
+ /** Restored from the cache and not yet replaced by the live item. */
363
+ isPlaceholder: true;
364
+ } & { [P in K]?: undefined; };
365
+ /** A {@link Placeholder} wallet, which is never connected. */
366
+ type PlaceholderWallet<T extends {
367
+ isConnected: boolean;
368
+ }, K extends keyof T> = Omit<Placeholder<T, K>, "isConnected"> & {
369
+ isConnected: false;
370
+ };
371
+ /** Narrows a wallet to the platform-less {@link WalletConnectWallet}. */
372
+ declare const isWalletConnectWallet: (wallet: BaseWallet | WalletConnectWallet) => wallet is WalletConnectWallet;
373
+ /**
374
+ * Narrows a wallet to an injected (browser-extension / Wallet Standard) wallet,
375
+ * the complement of {@link isWalletConnectWallet}. `state.wallets` is
376
+ * `(InjectedWallet | WalletConnectWallet)[]`, so use this to recover the
377
+ * injected-only fields when iterating: `platform`, `sourceId`, and the SDK
378
+ * handle (`provider` on Ethereum, `extension` on Polkadot, `wallet` on Solana).
379
+ *
380
+ * @example
381
+ * ```ts
382
+ * for (const wallet of wallets.filter(isInjectedWallet)) {
383
+ * console.log(wallet.platform, wallet.sourceId); // typed, no WC widening
384
+ * }
385
+ * ```
386
+ */
387
+ declare const isInjectedWallet: <W extends BaseWallet | WalletConnectWallet>(wallet: W) => wallet is Exclude<W, WalletConnectWallet>;
388
+ /**
389
+ * Dapp metadata shown in the WalletConnect modal. Mirrors WalletConnect's
390
+ * `Metadata`, declared locally so core doesn't depend on
391
+ * `@walletconnect/universal-provider`.
392
+ */
393
+ type WalletConnectMetadata = {
394
+ name: string;
395
+ description: string;
396
+ url: string;
397
+ icons: string[];
398
+ };
399
+ /**
400
+ * The WalletConnect connector for `config.walletConnect`. Create it with
401
+ * `walletConnect()` from `@kheopskit/core/walletconnect`; that entry is the only
402
+ * one that loads Reown AppKit.
403
+ */
404
+ type WalletConnectPlugin = {
405
+ readonly type: "walletconnect";
406
+ readonly metadata: WalletConnectMetadata;
407
+ getWallet$(ctx: PlatformContext): Observable<WalletConnectWallet | null>;
408
+ };
409
+ /**
410
+ * Context passed to a platform plugin's `getWallets$`. Carries the shared store
411
+ * and the resolved core config (for WalletConnect / debug).
412
+ */
413
+ type PlatformContext = {
414
+ store: KheopskitStore;
415
+ config: KheopskitConfig;
416
+ };
417
+ /**
418
+ * A platform plugin. Created by the per-platform factories exported from
419
+ * `@kheopskit/core/polkadot`, `/ethereum`, `/solana`. Core iterates plugins
420
+ * generically and never imports a platform SDK itself.
421
+ *
422
+ * @typeParam TPlatform - the platform discriminant
423
+ * @typeParam TWallet - the platform's wallet type (extends {@link BaseWallet})
424
+ * @typeParam TAccount - the platform's account type (extends {@link BaseWalletAccount})
425
+ */
426
+ type KheopskitPlatform<TPlatform extends WalletPlatform = WalletPlatform, TWallet extends BaseWallet = BaseWallet, TAccount extends BaseWalletAccount = BaseWalletAccount> = {
427
+ readonly platform: TPlatform;
428
+ getWallets$(ctx: PlatformContext): Observable<TWallet[]>;
429
+ getAccounts$(wallets$: Observable<(TWallet | WalletConnectWallet)[]>): Observable<TAccount[]>;
430
+ /**
431
+ * Optional hydration filter. Cached accounts for which this returns false are
432
+ * dropped during SSR hydration (Polkadot uses it to honour `accountTypes`).
433
+ */
434
+ acceptsCachedAccount?(cached: CachedAccount): boolean;
435
+ };
436
+ type ElementOf<T> = T extends readonly (infer E)[] ? E : never;
437
+ /** The account type produced by a plugin (inferred from its `getAccounts$`). */
438
+ type AccountOf<T> = T extends {
439
+ getAccounts$: (wallets$: never) => Observable<infer R>;
440
+ } ? ElementOf<R> : never;
441
+ /** The wallet type produced by a plugin (inferred from its `getWallets$`). */
442
+ type WalletOf<T> = T extends {
443
+ getWallets$: (ctx: never) => Observable<infer R>;
444
+ } ? ElementOf<R> : never;
445
+ type KheopskitConfig<P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]> = {
446
+ /**
447
+ * Which remembered injected wallets kheopskit reconnects after a reload.
448
+ *
449
+ * A wallet is remembered on every successful `connect()` and forgotten on
450
+ * `disconnect()`, whatever this option says; the list is the store's
451
+ * `remembered`. `true` reconnects every remembered injected wallet, `false`
452
+ * none, and a function is asked for each cached connected injected wallet
453
+ * on the first frame, then for each remembered one with its live object
454
+ * before the attempt. The function must be synchronous and pure. It runs on
455
+ * the server and on the client for the same input and both must agree, or
456
+ * the markup diverges. It receives the {@link BaseWallet} fields only, so
457
+ * key on `id`.
458
+ *
459
+ * The WalletConnect row is not governed by this option: AppKit restores its
460
+ * own session on load, and the row hydrates `connecting` while it does.
461
+ *
462
+ * A reconnect opens no connect prompt while the site stays authorised in
463
+ * the extension. When the authorisation was revoked the extension prompts
464
+ * once; a refusal forgets the wallet, so the next load stays silent. A manual
465
+ * `connect()` or `disconnect()` on a remembered wallet ends its automatic
466
+ * reconnect for the session. A `disconnect()` while the automatic reconnect
467
+ * still waits for the extension aborts it without forgetting the wallet, so
468
+ * the next load reconnects it.
469
+ * Automatic reconnect also ends when the wallet disappears mid-attempt; the
470
+ * wallet stays remembered for the next load.
471
+ *
472
+ * A cached connected wallet this accepts shows `status: "connecting"` from
473
+ * the first frame until its attempt settles. A wallet this rejects shows
474
+ * `disconnected` from the first frame, without its cached accounts, so
475
+ * nothing flashes from connected to disconnected.
476
+ *
477
+ * @default true
478
+ */
479
+ autoReconnect: boolean | ((wallet: BaseWallet) => boolean);
480
+ /**
481
+ * Platform plugins to enable, e.g. `[polkadot(), solana({ chain })]`.
482
+ * Import factories from `@kheopskit/core/<platform>`.
483
+ */
484
+ platforms: P;
485
+ /** Create with `walletConnect()` from `@kheopskit/core/walletconnect`. */
486
+ walletConnect?: WalletConnectPlugin;
487
+ /**
488
+ * Dapp name sent to Polkadot injected extensions on connect. Some
489
+ * extensions (e.g. polkadot.js) warn about a suspicious origin when it's
490
+ * empty.
491
+ *
492
+ * @default walletConnect.metadata.name, then window.location.hostname
493
+ */
494
+ appName?: string;
495
+ /**
496
+ * Logs the resolved config, every state emission and the hydration and
497
+ * persistence steps with `console.debug`.
498
+ *
499
+ * @default false
500
+ */
501
+ debug: boolean;
502
+ /**
503
+ * Custom storage key for persisting wallet connection state.
504
+ * Useful when running multiple kheopskit instances on the same domain
505
+ * to prevent state conflicts between different dapps.
506
+ *
507
+ * @default "kheopskit"
508
+ */
509
+ storageKey: string;
510
+ /**
511
+ * Minimum time in milliseconds the cached placeholders are shown after a
512
+ * reload, so the wallet list does not flash while extensions inject and
513
+ * remembered wallets reconnect. Hydration goes on past it until the rule
514
+ * documented on {@link KheopskitConfig.hydrationTimeout} ends it, and that
515
+ * timeout wins over a longer grace period. The old cap of six times this
516
+ * value is gone, so an app that raises it sets `hydrationTimeout` as well.
517
+ *
518
+ * `0` disables placeholders: `isHydrating` is `false` from the first
519
+ * emission.
520
+ *
521
+ * @default 500
522
+ */
523
+ hydrationGracePeriod: number;
524
+ /**
525
+ * Upper bound in milliseconds on {@link KheopskitState.isHydrating}.
526
+ *
527
+ * `isHydrating` turns `false` once `hydrationGracePeriod` has elapsed,
528
+ * discovery has ended ({@link KheopskitState.isDiscovering} is `false`),
529
+ * and every wallet that hydrated as `connecting` has settled. A wallet has
530
+ * settled when it is absent from the discovered wallets, connected once its
531
+ * account list has been read (an empty list counts) or connected with no
532
+ * cached accounts, disconnected with `error` set, or disconnected and not
533
+ * remembered when hydration began. At `hydrationTimeout` hydration ends
534
+ * whatever is pending, and a wallet whose reconnect is still pending stays
535
+ * `connecting`.
536
+ *
537
+ * - Discovery ends only after the page fires `load`, so a page with a cache
538
+ * hydrates until `load` or `hydrationTimeout`, whichever comes first,
539
+ * even when no wallet reconnects.
540
+ * - A wallet that reconnects without sharing any account with the site
541
+ * settles as soon as it answers; its cached accounts leave the list when
542
+ * hydration ends.
543
+ * - A failed reconnect ends that wallet's wait, even when the reconnect
544
+ * policy still permits a retry. A retry runs only when the wallet list next
545
+ * changes (a wallet discovered or removed, or any wallet's status, error
546
+ * or name changing), which may never happen, so waiting for it would
547
+ * hold most failed reconnects until `hydrationTimeout`. A retry that
548
+ * does run shows on the live wallet's `status`, not as a placeholder.
549
+ * - A remembered wallet the user disconnects during or right after its
550
+ * reconnect holds hydration, and shows its cached accounts, until
551
+ * `hydrationTimeout`.
552
+ * - A prompt the extension opens for a revoked site holds hydration until
553
+ * the user answers or `hydrationTimeout` elapses.
554
+ *
555
+ * @default 3000
556
+ */
557
+ hydrationTimeout: number;
558
+ };
559
+ /**
560
+ * The current kheopskit state.
561
+ *
562
+ * @remarks
563
+ * While {@link KheopskitState.isHydrating} is `true`, `wallets` and `accounts`
564
+ * may contain placeholders restored from the cache, flagged
565
+ * `isPlaceholder: true`. Each platform type is a union on that flag: a
566
+ * placeholder lacks the SDK handles (`account.txCreator` or `polkadotSigner`
567
+ * on Polkadot, `account.client` on Ethereum, `account.signer` / `getSigner` on
568
+ * Solana, `wallet.extension` / `provider` / `wallet` and `sourceId`). Reading
569
+ * one without narrowing yields a possibly-`undefined` value, so the compiler
570
+ * rejects using it as present until you narrow:
571
+ *
572
+ * ```ts
573
+ * if (account.isPlaceholder) return;
574
+ * account.txCreator; // TxCreator
575
+ * ```
576
+ *
577
+ * A placeholder wallet's `connect()` waits for the live wallet and connects
578
+ * it, rejecting with `WALLET_PENDING` if hydration ends first. No item is a
579
+ * placeholder once `isHydrating` is `false`.
580
+ *
581
+ * The plain, serializable platform data that is persisted in the cache IS
582
+ * restored on the placeholders (Ethereum `chainId`, Polkadot key `type`), so it
583
+ * renders immediately on reload without flashing. Solana `chains` is not
584
+ * cached: a placeholder account's is empty.
585
+ */
586
+ type KheopskitState<P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]> = {
587
+ /**
588
+ * Every discovered wallet, connected or not, then the WalletConnect
589
+ * connector once AppKit has loaded, when `config.walletConnect` is set.
590
+ * While `isHydrating` is `true`, also the cached placeholders. Sorted by
591
+ * platform (Polkadot, Ethereum, Solana, WalletConnect), then Talisman
592
+ * first, then by name.
593
+ */
594
+ wallets: (WalletOf<P[number]> | WalletConnectWallet)[];
595
+ /**
596
+ * The accounts of every connected wallet. While `isHydrating` is `true`,
597
+ * also the cached placeholders of every wallet that has no live account
598
+ * yet. Grouped by platform, then by wallet (Talisman first, then by wallet
599
+ * name); inside a wallet, in the order the wallet lists them.
600
+ */
601
+ accounts: AccountOf<P[number]>[];
602
+ /** The resolved config, with every default filled in. */
603
+ config: KheopskitConfig<P>;
604
+ /**
605
+ * Whether the state is still being hydrated from cache.
606
+ *
607
+ * During hydration, cached wallets/accounts may be displayed before the
608
+ * actual wallet extensions have injected. See the type-level remarks: those
609
+ * are flagged `isPlaceholder: true` and carry no SDK handle.
610
+ */
611
+ isHydrating: boolean;
612
+ /**
613
+ * Whether wallet discovery may still be incomplete.
614
+ *
615
+ * `true` when the subscription started before `document.readyState` was
616
+ * `"complete"`. It turns `false` in the first emission after `window` fired
617
+ * `load` and the Polkadot registry (`window.injectedWeb3`) was read again,
618
+ * so that emission already lists every extension injected by `load`. When the
619
+ * subscription starts after `load`, it is `false` from the first emission.
620
+ * Always `true` on the server.
621
+ *
622
+ * This rests on wallets injecting `injectedWeb3` before `load`. It says
623
+ * nothing about wallets that inject after `load`. Ethereum (EIP-6963) and
624
+ * Solana (Wallet Standard) registries are event-driven and need no re-read.
625
+ */
626
+ isDiscovering: boolean;
627
+ };
628
+ /** Shape of the persisted store data (localStorage, or cookies in compact form). */
629
+ type KheopskitStoreData = {
630
+ /** Wallets the user connected and has not disconnected */
631
+ remembered?: WalletId[];
632
+ /** Cached wallet state for SSR hydration to prevent UI flash */
633
+ cachedWallets?: CachedWallet[];
634
+ /** Cached account state for SSR hydration to prevent UI flash */
635
+ cachedAccounts?: CachedAccount[];
636
+ };
637
+ /**
638
+ * The persisted settings store shared between core and framework bindings.
639
+ * Declared structurally here (implemented by `createKheopskitStore`) so modules
640
+ * can depend on the interface without importing the implementation.
641
+ */
642
+ type KheopskitStore = {
643
+ observable: Observable<KheopskitStoreData>;
644
+ rememberWallet: (walletId: WalletId) => void;
645
+ forgetWallet: (walletId: WalletId) => void;
646
+ getCachedState: () => {
647
+ wallets: CachedWallet[];
648
+ accounts: CachedAccount[];
649
+ };
650
+ setCachedState: (wallets: CachedWallet[], accounts: CachedAccount[]) => void;
651
+ /** Stops cross-tab storage sync and completes `observable`. */
652
+ destroy: () => void;
653
+ };
654
+ /**
655
+ * Serializable wallet data for SSR hydration cache.
656
+ * Contains only the data needed to render wallet UI without flash.
657
+ * Note: icon is NOT stored to save cookie space - it's looked up at hydration time.
658
+ */
659
+ type CachedWallet = {
660
+ id: WalletId;
661
+ /** Absent for the platform-less WalletConnect connector. */
662
+ platform?: WalletPlatform;
663
+ type: WalletType;
664
+ name: string;
665
+ isConnected: boolean;
666
+ };
667
+ /**
668
+ * Serializable account data for SSR hydration cache.
669
+ * Contains only the data needed to render account UI without flash.
670
+ */
671
+ type CachedAccount = {
672
+ id: string;
673
+ platform: WalletPlatform;
674
+ address: string;
675
+ name?: string;
676
+ /** Cached chain ID for Ethereum accounts. */
677
+ chainId?: number;
678
+ /** Cached key type for Polkadot accounts. */
679
+ polkadotAccountType?: PolkadotAccountType;
680
+ walletId: WalletId;
681
+ walletName: string;
682
+ };
683
+ //#endregion
684
+ export { getWalletId as A, WalletStatus as C, KheopskitError as D, isWalletConnectWallet as E, parseWalletAccountId as F, parseWalletId as M, WalletAccountId as N, KheopskitErrorCode as O, getWalletAccountId as P, WalletPlatform as S, isInjectedWallet as T, WalletConnectMetadata as _, CachedAccount as a, WalletConnectWallet as b, KheopskitConfig as c, KheopskitStore as d, KheopskitStoreData as f, PolkadotAccountType as g, PlatformContext as h, BaseWalletAccount as i, isValidWalletId as j, WalletId as k, KheopskitPlatform as l, PlaceholderWallet as m, AppKitInstance as n, CachedWallet as o, Placeholder as p, BaseWallet as r, ConnectOptions as s, AccountOf as t, KheopskitState as u, WalletConnectPlugin as v, WalletType as w, WalletOf as x, WalletConnectProvider as y };
685
+ //# sourceMappingURL=types-lkMXVJNG.d.mts.map