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