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