@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.
- package/CHANGELOG.md +432 -0
- package/MIGRATING_TO_V6.md +840 -0
- package/README.md +629 -12
- package/dist/ethereum.d.mts +12 -6
- package/dist/ethereum.d.ts +12 -6
- package/dist/ethereum.js +13 -10
- package/dist/ethereum.js.map +1 -1
- package/dist/ethereum.mjs +7 -4
- package/dist/ethereum.mjs.map +1 -1
- package/dist/{iconCache-pP2ES4pJ.mjs → iconCache-C-U3IEbP.mjs} +21 -40
- package/dist/iconCache-C-U3IEbP.mjs.map +1 -0
- package/dist/{iconCache-DUtkJlaX.js → iconCache-FR4iy6go.js} +21 -40
- package/dist/iconCache-FR4iy6go.js.map +1 -0
- package/dist/index.d.mts +17 -63
- package/dist/index.d.ts +17 -63
- package/dist/index.js +387 -373
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +384 -369
- package/dist/index.mjs.map +1 -1
- package/dist/injectedWallets-48L-AL1I.mjs +173 -0
- package/dist/injectedWallets-48L-AL1I.mjs.map +1 -0
- package/dist/injectedWallets-Dy8YGKL-.js +178 -0
- package/dist/injectedWallets-Dy8YGKL-.js.map +1 -0
- package/dist/internal.d.mts +3 -27
- package/dist/internal.d.ts +3 -27
- package/dist/internal.js +2 -2
- package/dist/internal.mjs +2 -2
- package/dist/pageLoad-BZ7o8p5R.mjs +24 -0
- package/dist/pageLoad-BZ7o8p5R.mjs.map +1 -0
- package/dist/pageLoad-D1wLeuFG.js +28 -0
- package/dist/pageLoad-D1wLeuFG.js.map +1 -0
- package/dist/platformAccounts-BjIeRcFN.js +321 -0
- package/dist/platformAccounts-BjIeRcFN.js.map +1 -0
- package/dist/platformAccounts-yyRUrnel.mjs +256 -0
- package/dist/platformAccounts-yyRUrnel.mjs.map +1 -0
- package/dist/polkadot.d.mts +127 -11
- package/dist/polkadot.d.ts +127 -11
- package/dist/polkadot.js +187 -106
- package/dist/polkadot.js.map +1 -1
- package/dist/polkadot.mjs +180 -99
- package/dist/polkadot.mjs.map +1 -1
- package/dist/solana.d.mts +11 -5
- package/dist/solana.d.ts +11 -5
- package/dist/solana.js +18 -15
- package/dist/solana.js.map +1 -1
- package/dist/solana.mjs +7 -4
- package/dist/solana.mjs.map +1 -1
- package/dist/storage-D3AwNgqc.d.mts +27 -0
- package/dist/storage-D3AwNgqc.d.ts +27 -0
- package/dist/testing.d.mts +71 -0
- package/dist/testing.d.ts +71 -0
- package/dist/testing.js +136 -0
- package/dist/testing.js.map +1 -0
- package/dist/testing.mjs +131 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/{types-DKU-SNio.js → types-BWHvNFlN.js} +149 -2
- package/dist/types-BWHvNFlN.js.map +1 -0
- package/dist/types-Yor672md.mjs +215 -0
- package/dist/types-Yor672md.mjs.map +1 -0
- package/dist/types-lkMXVJNG.d.mts +685 -0
- package/dist/types-lkMXVJNG.d.ts +685 -0
- package/dist/walletconnect.d.mts +41 -0
- package/dist/walletconnect.d.ts +41 -0
- package/dist/walletconnect.js +219 -0
- package/dist/walletconnect.js.map +1 -0
- package/dist/walletconnect.mjs +216 -0
- package/dist/walletconnect.mjs.map +1 -0
- package/package.json +30 -6
- package/dist/errors-BLFP1dQI.mjs +0 -181
- package/dist/errors-BLFP1dQI.mjs.map +0 -1
- package/dist/errors-DYWVPHrR.js +0 -222
- package/dist/errors-DYWVPHrR.js.map +0 -1
- package/dist/iconCache-DUtkJlaX.js.map +0 -1
- package/dist/iconCache-pP2ES4pJ.mjs.map +0 -1
- package/dist/injectedWallets-BqR-_aAy.js +0 -148
- package/dist/injectedWallets-BqR-_aAy.js.map +0 -1
- package/dist/injectedWallets-Uz4hPuoW.mjs +0 -119
- package/dist/injectedWallets-Uz4hPuoW.mjs.map +0 -1
- package/dist/types-AxUDtkR-.d.mts +0 -338
- package/dist/types-AxUDtkR-.d.ts +0 -338
- package/dist/types-DKU-SNio.js.map +0 -1
- package/dist/types-jnifAAA0.mjs +0 -104
- package/dist/types-jnifAAA0.mjs.map +0 -1
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
const require_types = require("./types-DKU-SNio.js");
|
|
2
|
-
const require_errors = require("./errors-DYWVPHrR.js");
|
|
3
|
-
let rxjs = require("rxjs");
|
|
4
|
-
//#region src/api/platformAccounts.ts
|
|
5
|
-
/** Shared engine behind every platform's `getAccounts$`. */
|
|
6
|
-
const createPlatformAccounts$ = ({ wallets$, getInjectedAccounts$, getWalletConnectAccounts$, mapAccounts, accountChangeKey = (account) => account.id }) => {
|
|
7
|
-
const accountsListEqual = (a, b) => a.length === b.length && a.every((account, i) => {
|
|
8
|
-
const other = b[i];
|
|
9
|
-
return !!other && accountChangeKey(account) === accountChangeKey(other);
|
|
10
|
-
});
|
|
11
|
-
return new rxjs.Observable((subscriber) => {
|
|
12
|
-
const sub = wallets$.pipe((0, rxjs.map)((wallets) => wallets.filter((w) => w.isConnected)), (0, rxjs.switchMap)((wallets) => wallets.length ? (0, rxjs.combineLatest)([...wallets.filter((w) => !require_types.isWalletConnectWallet(w)).map(getInjectedAccounts$), ...wallets.filter(require_types.isWalletConnectWallet).map(getWalletConnectAccounts$)]) : (0, rxjs.of)([])), (0, rxjs.map)((accounts) => {
|
|
13
|
-
const flat = accounts.flat();
|
|
14
|
-
return mapAccounts ? mapAccounts(flat) : flat;
|
|
15
|
-
}), (0, rxjs.distinctUntilChanged)(accountsListEqual)).subscribe(subscriber);
|
|
16
|
-
return () => {
|
|
17
|
-
sub.unsubscribe();
|
|
18
|
-
};
|
|
19
|
-
}).pipe((0, rxjs.shareReplay)({
|
|
20
|
-
refCount: true,
|
|
21
|
-
bufferSize: 1
|
|
22
|
-
}));
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* CAIP-10 account strings ("<namespace>:<chainRef>:<address>") the live
|
|
26
|
-
* WalletConnect session carries for a namespace.
|
|
27
|
-
*/
|
|
28
|
-
const getSessionCaip10s = (session, namespace) => Object.values(session.namespaces).flatMap((ns) => ns.accounts ?? []).filter((account) => account.startsWith(`${namespace}:`));
|
|
29
|
-
/**
|
|
30
|
-
* Unique addresses from CAIP-10 account strings (one entry per chain, so the
|
|
31
|
-
* same address repeats — dedupe).
|
|
32
|
-
*/
|
|
33
|
-
const getCaip10Addresses = (caip10s) => [...new Set(caip10s.map((account) => account.split(":")[2]).filter((address) => !!address))];
|
|
34
|
-
/**
|
|
35
|
-
* Shared shape of the Polkadot/Solana WalletConnect account streams: no-op
|
|
36
|
-
* unless the session carries the platform's namespace, then a cached
|
|
37
|
-
* observable that rebuilds the account list from the session on
|
|
38
|
-
* `session_update` / `accountsChanged`.
|
|
39
|
-
*
|
|
40
|
-
* AppKit's `getAccount(namespace).allAccounts` is always empty for namespaces
|
|
41
|
-
* without a native AppKit adapter — the WalletConnect session is the source of
|
|
42
|
-
* truth, hence the session-driven rebuild.
|
|
43
|
-
*/
|
|
44
|
-
const getWalletConnectSessionAccounts$ = (options) => {
|
|
45
|
-
const { wallet, platform, namespace, cacheKey, buildAccounts } = options;
|
|
46
|
-
const provider = wallet.appKit.getProvider(namespace);
|
|
47
|
-
if (!wallet.platforms.includes(platform) || !provider?.session) return (0, rxjs.of)([]);
|
|
48
|
-
return require_types.getCachedObservable$(cacheKey, () => new rxjs.Observable((subscriber) => {
|
|
49
|
-
subscriber.next(buildAccounts(provider));
|
|
50
|
-
const reemit = () => subscriber.next(buildAccounts(provider));
|
|
51
|
-
provider.on("session_update", reemit);
|
|
52
|
-
provider.on("accountsChanged", reemit);
|
|
53
|
-
return () => {
|
|
54
|
-
provider.off("session_update", reemit);
|
|
55
|
-
provider.off("accountsChanged", reemit);
|
|
56
|
-
};
|
|
57
|
-
}).pipe((0, rxjs.shareReplay)({
|
|
58
|
-
refCount: true,
|
|
59
|
-
bufferSize: 1
|
|
60
|
-
})));
|
|
61
|
-
};
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/api/injectedWallets.ts
|
|
64
|
-
/**
|
|
65
|
-
* Compare two wallet arrays by their relevant properties (not functions).
|
|
66
|
-
* Shared by every platform's injected-wallets stream.
|
|
67
|
-
*/
|
|
68
|
-
const walletsEqual = (a, b) => {
|
|
69
|
-
if (a.length !== b.length) return false;
|
|
70
|
-
return a.every((w, i) => w.id === b[i]?.id && w.isConnected === b[i]?.isConnected && w.name === b[i]?.name);
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* The shared engine behind every platform's injected-wallets stream: tracks
|
|
74
|
-
* connected wallets (and their live handles), guards double
|
|
75
|
-
* connect/disconnect, persists connected ids to the store for auto-reconnect,
|
|
76
|
-
* and re-emits the wallet list whenever the registry or connection state
|
|
77
|
-
* changes.
|
|
78
|
-
*/
|
|
79
|
-
const createInjectedWallets$ = (store, adapter) => new rxjs.Observable((subscriber) => {
|
|
80
|
-
const handles$ = new rxjs.BehaviorSubject(/* @__PURE__ */ new Map());
|
|
81
|
-
const connect = async (source, walletId) => {
|
|
82
|
-
if (handles$.value.has(walletId)) throw new require_errors.KheopskitError("WALLET_ALREADY_CONNECTED", `wallet ${walletId} is already connected`, { walletId });
|
|
83
|
-
const handle = await adapter.connect(source, walletId);
|
|
84
|
-
const next = new Map(handles$.value);
|
|
85
|
-
next.set(walletId, handle);
|
|
86
|
-
handles$.next(next);
|
|
87
|
-
store.addEnabledWalletId(walletId);
|
|
88
|
-
};
|
|
89
|
-
const disconnect = async (source, walletId) => {
|
|
90
|
-
if (!handles$.value.has(walletId)) throw new require_errors.KheopskitError("WALLET_NOT_CONNECTED", `wallet ${walletId} is not connected`, { walletId });
|
|
91
|
-
await adapter.disconnect?.(source, walletId);
|
|
92
|
-
const next = new Map(handles$.value);
|
|
93
|
-
next.delete(walletId);
|
|
94
|
-
handles$.next(next);
|
|
95
|
-
store.removeEnabledWalletId(walletId);
|
|
96
|
-
adapter.onDisconnected?.(walletId);
|
|
97
|
-
};
|
|
98
|
-
const sub = (0, rxjs.combineLatest)([adapter.sources$, handles$]).pipe((0, rxjs.map)(([sources, handles]) => sources.map((source) => {
|
|
99
|
-
const walletId = adapter.getWalletId(source);
|
|
100
|
-
return adapter.buildWallet({
|
|
101
|
-
source,
|
|
102
|
-
walletId,
|
|
103
|
-
handle: handles.get(walletId),
|
|
104
|
-
isConnected: handles.has(walletId),
|
|
105
|
-
connect: () => connect(source, walletId),
|
|
106
|
-
disconnect: () => disconnect(source, walletId)
|
|
107
|
-
});
|
|
108
|
-
})), (0, rxjs.distinctUntilChanged)(walletsEqual)).subscribe(subscriber);
|
|
109
|
-
return () => {
|
|
110
|
-
sub.unsubscribe();
|
|
111
|
-
};
|
|
112
|
-
}).pipe((0, rxjs.shareReplay)({
|
|
113
|
-
refCount: true,
|
|
114
|
-
bufferSize: 1
|
|
115
|
-
}));
|
|
116
|
-
//#endregion
|
|
117
|
-
Object.defineProperty(exports, "createInjectedWallets$", {
|
|
118
|
-
enumerable: true,
|
|
119
|
-
get: function() {
|
|
120
|
-
return createInjectedWallets$;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
Object.defineProperty(exports, "createPlatformAccounts$", {
|
|
124
|
-
enumerable: true,
|
|
125
|
-
get: function() {
|
|
126
|
-
return createPlatformAccounts$;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
Object.defineProperty(exports, "getCaip10Addresses", {
|
|
130
|
-
enumerable: true,
|
|
131
|
-
get: function() {
|
|
132
|
-
return getCaip10Addresses;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
Object.defineProperty(exports, "getSessionCaip10s", {
|
|
136
|
-
enumerable: true,
|
|
137
|
-
get: function() {
|
|
138
|
-
return getSessionCaip10s;
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
Object.defineProperty(exports, "getWalletConnectSessionAccounts$", {
|
|
142
|
-
enumerable: true,
|
|
143
|
-
get: function() {
|
|
144
|
-
return getWalletConnectSessionAccounts$;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
//# sourceMappingURL=injectedWallets-BqR-_aAy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectedWallets-BqR-_aAy.js","names":["Observable","map","switchMap","combineLatest","isWalletConnectWallet","of","distinctUntilChanged","shareReplay","getCachedObservable$","Observable","BehaviorSubject","KheopskitError","combineLatest","map","distinctUntilChanged","shareReplay"],"sources":["../src/api/platformAccounts.ts","../src/api/injectedWallets.ts"],"sourcesContent":["import {\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tof,\n\tshareReplay,\n\tswitchMap,\n} from \"rxjs\";\nimport { getCachedObservable$ } from \"../utils/getCachedObservable\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\n/**\n * The platform-specific surface of an accounts stream. The shared pipeline —\n * filter connected wallets, fan out per-wallet account streams, flatten,\n * change-detect, share — is owned by {@link createPlatformAccounts$}.\n */\nexport type PlatformAccountsOptions<\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n> = {\n\t/** This platform's wallets plus the shared WalletConnect connector. */\n\twallets$: Observable<(TWallet | WalletConnectWallet)[]>;\n\t/** Account stream for one connected injected wallet. */\n\tgetInjectedAccounts$: (wallet: TWallet) => Observable<TAccount[]>;\n\t/** Account stream for the WalletConnect connector. */\n\tgetWalletConnectAccounts$: (\n\t\twallet: WalletConnectWallet,\n\t) => Observable<TAccount[]>;\n\t/** Optional post-flatten transform (e.g. Polkadot's `accountTypes` filter). */\n\tmapAccounts?: (accounts: TAccount[]) => TAccount[];\n\t/**\n\t * Signature of the account fields that should trigger a re-emission.\n\t * Defaults to the account id; platforms add mutable fields (Ethereum\n\t * `chainId`, Solana `chains`).\n\t */\n\taccountChangeKey?: (account: TAccount) => string;\n};\n\n/** Shared engine behind every platform's `getAccounts$`. */\nexport const createPlatformAccounts$ = <\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n>({\n\twallets$,\n\tgetInjectedAccounts$,\n\tgetWalletConnectAccounts$,\n\tmapAccounts,\n\taccountChangeKey = (account) => account.id,\n}: PlatformAccountsOptions<TWallet, TAccount>): Observable<TAccount[]> => {\n\tconst accountsListEqual = (a: TAccount[], b: TAccount[]) =>\n\t\ta.length === b.length &&\n\t\ta.every((account, i) => {\n\t\t\tconst other = b[i];\n\t\t\treturn !!other && accountChangeKey(account) === accountChangeKey(other);\n\t\t});\n\n\treturn new Observable<TAccount[]>((subscriber) => {\n\t\tconst sub = wallets$\n\t\t\t.pipe(\n\t\t\t\tmap((wallets) => wallets.filter((w) => w.isConnected)),\n\t\t\t\tswitchMap((wallets) =>\n\t\t\t\t\twallets.length\n\t\t\t\t\t\t? combineLatest([\n\t\t\t\t\t\t\t\t...wallets\n\t\t\t\t\t\t\t\t\t.filter((w): w is TWallet => !isWalletConnectWallet(w))\n\t\t\t\t\t\t\t\t\t.map(getInjectedAccounts$),\n\t\t\t\t\t\t\t\t...wallets\n\t\t\t\t\t\t\t\t\t.filter(isWalletConnectWallet)\n\t\t\t\t\t\t\t\t\t.map(getWalletConnectAccounts$),\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t: of([]),\n\t\t\t\t),\n\t\t\t\tmap((accounts) => {\n\t\t\t\t\tconst flat = accounts.flat();\n\t\t\t\t\treturn mapAccounts ? mapAccounts(flat) : flat;\n\t\t\t\t}),\n\t\t\t\tdistinctUntilChanged(accountsListEqual),\n\t\t\t)\n\t\t\t.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n\n/**\n * CAIP-10 account strings (\"<namespace>:<chainRef>:<address>\") the live\n * WalletConnect session carries for a namespace.\n */\nexport const getSessionCaip10s = (\n\tsession: NonNullable<WalletConnectProvider[\"session\"]>,\n\tnamespace: string,\n): string[] =>\n\tObject.values(session.namespaces)\n\t\t.flatMap((ns) => ns.accounts ?? [])\n\t\t.filter((account) => account.startsWith(`${namespace}:`));\n\n/**\n * Unique addresses from CAIP-10 account strings (one entry per chain, so the\n * same address repeats — dedupe).\n */\nexport const getCaip10Addresses = (caip10s: string[]): string[] => [\n\t...new Set(\n\t\tcaip10s\n\t\t\t.map((account) => account.split(\":\")[2])\n\t\t\t.filter((address): address is string => !!address),\n\t),\n];\n\n/**\n * Shared shape of the Polkadot/Solana WalletConnect account streams: no-op\n * unless the session carries the platform's namespace, then a cached\n * observable that rebuilds the account list from the session on\n * `session_update` / `accountsChanged`.\n *\n * AppKit's `getAccount(namespace).allAccounts` is always empty for namespaces\n * without a native AppKit adapter — the WalletConnect session is the source of\n * truth, hence the session-driven rebuild.\n */\nexport const getWalletConnectSessionAccounts$ = <\n\tTAccount extends BaseWalletAccount,\n>(options: {\n\twallet: WalletConnectWallet;\n\tplatform: WalletPlatform;\n\t/** WalletConnect namespace, e.g. \"polkadot\" | \"solana\" | \"eip155\". */\n\tnamespace: string;\n\t/** Cache key for {@link getCachedObservable$} — must be reconnect-safe. */\n\tcacheKey: string;\n\t/** Build the account list from the live session. */\n\tbuildAccounts: (provider: WalletConnectProvider) => TAccount[];\n}): Observable<TAccount[]> => {\n\tconst { wallet, platform, namespace, cacheKey, buildAccounts } = options;\n\tconst provider = wallet.appKit.getProvider(namespace);\n\n\tif (!wallet.platforms.includes(platform) || !provider?.session) return of([]);\n\n\treturn getCachedObservable$(cacheKey, () =>\n\t\tnew Observable<TAccount[]>((subscriber) => {\n\t\t\tsubscriber.next(buildAccounts(provider));\n\n\t\t\t// Re-derive when the WalletConnect session's accounts change, mirroring\n\t\t\t// the injected paths' change subscriptions.\n\t\t\tconst reemit = () => subscriber.next(buildAccounts(provider));\n\t\t\tprovider.on(\"session_update\", reemit);\n\t\t\tprovider.on(\"accountsChanged\", reemit);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"session_update\", reemit);\n\t\t\t\tprovider.off(\"accountsChanged\", reemit);\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n","import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tshareReplay,\n} from \"rxjs\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport { KheopskitError } from \"./errors\";\nimport type { KheopskitStore } from \"./store\";\nimport type { BaseWallet } from \"./types\";\n\n/**\n * Compare two wallet arrays by their relevant properties (not functions).\n * Shared by every platform's injected-wallets stream.\n */\nconst walletsEqual = <\n\tW extends Pick<BaseWallet, \"id\" | \"isConnected\" | \"name\">,\n>(\n\ta: W[],\n\tb: W[],\n): boolean => {\n\tif (a.length !== b.length) return false;\n\treturn a.every(\n\t\t(w, i) =>\n\t\t\tw.id === b[i]?.id &&\n\t\t\tw.isConnected === b[i]?.isConnected &&\n\t\t\tw.name === b[i]?.name,\n\t);\n};\n\n/**\n * The platform-specific surface of an injected-wallets stream. Everything else\n * — the connect/disconnect state machine, the connected-ids bookkeeping, the\n * store persistence, change detection and sharing — is owned by\n * {@link createInjectedWallets$}.\n *\n * @typeParam TSource - a wallet as the platform's registry reports it\n * @typeParam TWallet - the platform's wallet type\n * @typeParam THandle - live connection handle retained while connected\n * (Polkadot keeps the `InjectedExtension`; platforms with no handle use void)\n */\nexport type InjectedWalletsAdapter<\n\tTSource,\n\tTWallet extends BaseWallet,\n\tTHandle = void,\n> = {\n\t/** Live registry of the platform's injected wallets (emits `[]` during SSR). */\n\tsources$: Observable<readonly TSource[]>;\n\t/** Stable wallet id for a registry entry. */\n\tgetWalletId: (source: TSource) => WalletId;\n\t/**\n\t * Platform connect call (e.g. `connectInjectedExtension`,\n\t * `eth_requestAccounts`, `standard:connect`). The resolved value is retained\n\t * as the wallet's live handle until disconnect.\n\t */\n\tconnect: (source: TSource, walletId: WalletId) => Promise<THandle>;\n\t/**\n\t * Optional platform disconnect call, awaited before local state clears so a\n\t * failed disconnect rejects without desyncing the connected list.\n\t */\n\tdisconnect?: (source: TSource, walletId: WalletId) => Promise<void>;\n\t/**\n\t * Runs after a disconnect fully applied — the place to drop cached account\n\t * observables so a later reconnect rebuilds them against a fresh handle.\n\t */\n\tonDisconnected?: (walletId: WalletId) => void;\n\t/** Build the platform wallet object for one registry entry. */\n\tbuildWallet: (args: {\n\t\tsource: TSource;\n\t\twalletId: WalletId;\n\t\t/** Live connection handle; `undefined` while disconnected. */\n\t\thandle: THandle | undefined;\n\t\tisConnected: boolean;\n\t\tconnect: () => Promise<void>;\n\t\tdisconnect: () => Promise<void>;\n\t}) => TWallet;\n};\n\n/**\n * The shared engine behind every platform's injected-wallets stream: tracks\n * connected wallets (and their live handles), guards double\n * connect/disconnect, persists connected ids to the store for auto-reconnect,\n * and re-emits the wallet list whenever the registry or connection state\n * changes.\n */\nexport const createInjectedWallets$ = <\n\tTSource,\n\tTWallet extends BaseWallet,\n\tTHandle = void,\n>(\n\tstore: KheopskitStore,\n\tadapter: InjectedWalletsAdapter<TSource, TWallet, THandle>,\n): Observable<TWallet[]> =>\n\tnew Observable<TWallet[]>((subscriber) => {\n\t\tconst handles$ = new BehaviorSubject<Map<WalletId, THandle>>(new Map());\n\n\t\tconst connect = async (source: TSource, walletId: WalletId) => {\n\t\t\tif (handles$.value.has(walletId))\n\t\t\t\tthrow new KheopskitError(\n\t\t\t\t\t\"WALLET_ALREADY_CONNECTED\",\n\t\t\t\t\t`wallet ${walletId} is already connected`,\n\t\t\t\t\t{ walletId },\n\t\t\t\t);\n\n\t\t\tconst handle = await adapter.connect(source, walletId);\n\n\t\t\tconst next = new Map(handles$.value);\n\t\t\tnext.set(walletId, handle);\n\t\t\thandles$.next(next);\n\n\t\t\tstore.addEnabledWalletId(walletId);\n\t\t};\n\n\t\tconst disconnect = async (source: TSource, walletId: WalletId) => {\n\t\t\tif (!handles$.value.has(walletId))\n\t\t\t\tthrow new KheopskitError(\n\t\t\t\t\t\"WALLET_NOT_CONNECTED\",\n\t\t\t\t\t`wallet ${walletId} is not connected`,\n\t\t\t\t\t{ walletId },\n\t\t\t\t);\n\n\t\t\tawait adapter.disconnect?.(source, walletId);\n\n\t\t\tconst next = new Map(handles$.value);\n\t\t\tnext.delete(walletId);\n\t\t\thandles$.next(next);\n\n\t\t\tstore.removeEnabledWalletId(walletId);\n\n\t\t\tadapter.onDisconnected?.(walletId);\n\t\t};\n\n\t\tconst sub = combineLatest([adapter.sources$, handles$])\n\t\t\t.pipe(\n\t\t\t\tmap(([sources, handles]) =>\n\t\t\t\t\tsources.map((source): TWallet => {\n\t\t\t\t\t\tconst walletId = adapter.getWalletId(source);\n\t\t\t\t\t\treturn adapter.buildWallet({\n\t\t\t\t\t\t\tsource,\n\t\t\t\t\t\t\twalletId,\n\t\t\t\t\t\t\thandle: handles.get(walletId),\n\t\t\t\t\t\t\tisConnected: handles.has(walletId),\n\t\t\t\t\t\t\tconnect: () => connect(source, walletId),\n\t\t\t\t\t\t\tdisconnect: () => disconnect(source, walletId),\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\tdistinctUntilChanged(walletsEqual),\n\t\t\t)\n\t\t\t.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n"],"mappings":";;;;;AA+CA,MAAa,2BAGX,EACD,UACA,sBACA,2BACA,aACA,oBAAoB,YAAY,QAAQ,SACiC;CACzE,MAAM,qBAAqB,GAAe,MACzC,EAAE,WAAW,EAAE,UACf,EAAE,OAAO,SAAS,MAAM;EACvB,MAAM,QAAQ,EAAE;EAChB,OAAO,CAAC,CAAC,SAAS,iBAAiB,OAAO,MAAM,iBAAiB,KAAK;CACvE,CAAC;CAEF,OAAO,IAAIA,KAAAA,YAAwB,eAAe;EACjD,MAAM,MAAM,SACV,MAAA,GACAC,KAAAA,IAAAA,EAAK,YAAY,QAAQ,QAAQ,MAAM,EAAE,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S,oBACnB,EAAE,SAAS,CACZ;EAED,MAAM,QAAQ,aAAa,QAAQ,QAAQ;EAE3C,MAAM,OAAO,IAAI,IAAI,SAAS,KAAK;EACnC,KAAK,OAAO,QAAQ;EACpB,SAAS,KAAK,IAAI;EAElB,MAAM,sBAAsB,QAAQ;EAEpC,QAAQ,iBAAiB,QAAQ;CAClC;CAEA,MAAM,OAAA,GAAMC,KAAAA,cAAAA,CAAc,CAAC,QAAQ,UAAU,QAAQ,CAAC,CAAC,CACrD,MAAA,GACAC,KAAAA,IAAAA,EAAK,CAAC,SAAS,aACd,QAAQ,KAAK,WAAoB;EAChC,MAAM,WAAW,QAAQ,YAAY,MAAM;EAC3C,OAAO,QAAQ,YAAY;GAC1B;GACA;GACA,QAAQ,QAAQ,IAAI,QAAQ;GAC5B,aAAa,QAAQ,IAAI,QAAQ;GACjC,eAAe,QAAQ,QAAQ,QAAQ;GACvC,kBAAkB,WAAW,QAAQ,QAAQ;EAC9C,CAAC;CACF,CAAC,CACF,IAAA,GACAC,KAAAA,qBAAAA,CAAqB,YAAY,CAClC,CAAC,CACA,UAAU,UAAU;CAEtB,aAAa;EACZ,IAAI,YAAY;CACjB;AACD,CAAC,CAAC,CAAC,MAAA,GAAKC,KAAAA,YAAAA,CAAY;CAAE,UAAU;CAAM,YAAY;AAAE,CAAC,CAAC"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { d as getCachedObservable$, n as isWalletConnectWallet } from "./types-jnifAAA0.mjs";
|
|
2
|
-
import { t as KheopskitError } from "./errors-BLFP1dQI.mjs";
|
|
3
|
-
import { BehaviorSubject, Observable, combineLatest, distinctUntilChanged, map, of, shareReplay, switchMap } from "rxjs";
|
|
4
|
-
//#region src/api/platformAccounts.ts
|
|
5
|
-
/** Shared engine behind every platform's `getAccounts$`. */
|
|
6
|
-
const createPlatformAccounts$ = ({ wallets$, getInjectedAccounts$, getWalletConnectAccounts$, mapAccounts, accountChangeKey = (account) => account.id }) => {
|
|
7
|
-
const accountsListEqual = (a, b) => a.length === b.length && a.every((account, i) => {
|
|
8
|
-
const other = b[i];
|
|
9
|
-
return !!other && accountChangeKey(account) === accountChangeKey(other);
|
|
10
|
-
});
|
|
11
|
-
return new Observable((subscriber) => {
|
|
12
|
-
const sub = wallets$.pipe(map((wallets) => wallets.filter((w) => w.isConnected)), switchMap((wallets) => wallets.length ? combineLatest([...wallets.filter((w) => !isWalletConnectWallet(w)).map(getInjectedAccounts$), ...wallets.filter(isWalletConnectWallet).map(getWalletConnectAccounts$)]) : of([])), map((accounts) => {
|
|
13
|
-
const flat = accounts.flat();
|
|
14
|
-
return mapAccounts ? mapAccounts(flat) : flat;
|
|
15
|
-
}), distinctUntilChanged(accountsListEqual)).subscribe(subscriber);
|
|
16
|
-
return () => {
|
|
17
|
-
sub.unsubscribe();
|
|
18
|
-
};
|
|
19
|
-
}).pipe(shareReplay({
|
|
20
|
-
refCount: true,
|
|
21
|
-
bufferSize: 1
|
|
22
|
-
}));
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* CAIP-10 account strings ("<namespace>:<chainRef>:<address>") the live
|
|
26
|
-
* WalletConnect session carries for a namespace.
|
|
27
|
-
*/
|
|
28
|
-
const getSessionCaip10s = (session, namespace) => Object.values(session.namespaces).flatMap((ns) => ns.accounts ?? []).filter((account) => account.startsWith(`${namespace}:`));
|
|
29
|
-
/**
|
|
30
|
-
* Unique addresses from CAIP-10 account strings (one entry per chain, so the
|
|
31
|
-
* same address repeats — dedupe).
|
|
32
|
-
*/
|
|
33
|
-
const getCaip10Addresses = (caip10s) => [...new Set(caip10s.map((account) => account.split(":")[2]).filter((address) => !!address))];
|
|
34
|
-
/**
|
|
35
|
-
* Shared shape of the Polkadot/Solana WalletConnect account streams: no-op
|
|
36
|
-
* unless the session carries the platform's namespace, then a cached
|
|
37
|
-
* observable that rebuilds the account list from the session on
|
|
38
|
-
* `session_update` / `accountsChanged`.
|
|
39
|
-
*
|
|
40
|
-
* AppKit's `getAccount(namespace).allAccounts` is always empty for namespaces
|
|
41
|
-
* without a native AppKit adapter — the WalletConnect session is the source of
|
|
42
|
-
* truth, hence the session-driven rebuild.
|
|
43
|
-
*/
|
|
44
|
-
const getWalletConnectSessionAccounts$ = (options) => {
|
|
45
|
-
const { wallet, platform, namespace, cacheKey, buildAccounts } = options;
|
|
46
|
-
const provider = wallet.appKit.getProvider(namespace);
|
|
47
|
-
if (!wallet.platforms.includes(platform) || !provider?.session) return of([]);
|
|
48
|
-
return getCachedObservable$(cacheKey, () => new Observable((subscriber) => {
|
|
49
|
-
subscriber.next(buildAccounts(provider));
|
|
50
|
-
const reemit = () => subscriber.next(buildAccounts(provider));
|
|
51
|
-
provider.on("session_update", reemit);
|
|
52
|
-
provider.on("accountsChanged", reemit);
|
|
53
|
-
return () => {
|
|
54
|
-
provider.off("session_update", reemit);
|
|
55
|
-
provider.off("accountsChanged", reemit);
|
|
56
|
-
};
|
|
57
|
-
}).pipe(shareReplay({
|
|
58
|
-
refCount: true,
|
|
59
|
-
bufferSize: 1
|
|
60
|
-
})));
|
|
61
|
-
};
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/api/injectedWallets.ts
|
|
64
|
-
/**
|
|
65
|
-
* Compare two wallet arrays by their relevant properties (not functions).
|
|
66
|
-
* Shared by every platform's injected-wallets stream.
|
|
67
|
-
*/
|
|
68
|
-
const walletsEqual = (a, b) => {
|
|
69
|
-
if (a.length !== b.length) return false;
|
|
70
|
-
return a.every((w, i) => w.id === b[i]?.id && w.isConnected === b[i]?.isConnected && w.name === b[i]?.name);
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* The shared engine behind every platform's injected-wallets stream: tracks
|
|
74
|
-
* connected wallets (and their live handles), guards double
|
|
75
|
-
* connect/disconnect, persists connected ids to the store for auto-reconnect,
|
|
76
|
-
* and re-emits the wallet list whenever the registry or connection state
|
|
77
|
-
* changes.
|
|
78
|
-
*/
|
|
79
|
-
const createInjectedWallets$ = (store, adapter) => new Observable((subscriber) => {
|
|
80
|
-
const handles$ = new BehaviorSubject(/* @__PURE__ */ new Map());
|
|
81
|
-
const connect = async (source, walletId) => {
|
|
82
|
-
if (handles$.value.has(walletId)) throw new KheopskitError("WALLET_ALREADY_CONNECTED", `wallet ${walletId} is already connected`, { walletId });
|
|
83
|
-
const handle = await adapter.connect(source, walletId);
|
|
84
|
-
const next = new Map(handles$.value);
|
|
85
|
-
next.set(walletId, handle);
|
|
86
|
-
handles$.next(next);
|
|
87
|
-
store.addEnabledWalletId(walletId);
|
|
88
|
-
};
|
|
89
|
-
const disconnect = async (source, walletId) => {
|
|
90
|
-
if (!handles$.value.has(walletId)) throw new KheopskitError("WALLET_NOT_CONNECTED", `wallet ${walletId} is not connected`, { walletId });
|
|
91
|
-
await adapter.disconnect?.(source, walletId);
|
|
92
|
-
const next = new Map(handles$.value);
|
|
93
|
-
next.delete(walletId);
|
|
94
|
-
handles$.next(next);
|
|
95
|
-
store.removeEnabledWalletId(walletId);
|
|
96
|
-
adapter.onDisconnected?.(walletId);
|
|
97
|
-
};
|
|
98
|
-
const sub = combineLatest([adapter.sources$, handles$]).pipe(map(([sources, handles]) => sources.map((source) => {
|
|
99
|
-
const walletId = adapter.getWalletId(source);
|
|
100
|
-
return adapter.buildWallet({
|
|
101
|
-
source,
|
|
102
|
-
walletId,
|
|
103
|
-
handle: handles.get(walletId),
|
|
104
|
-
isConnected: handles.has(walletId),
|
|
105
|
-
connect: () => connect(source, walletId),
|
|
106
|
-
disconnect: () => disconnect(source, walletId)
|
|
107
|
-
});
|
|
108
|
-
})), distinctUntilChanged(walletsEqual)).subscribe(subscriber);
|
|
109
|
-
return () => {
|
|
110
|
-
sub.unsubscribe();
|
|
111
|
-
};
|
|
112
|
-
}).pipe(shareReplay({
|
|
113
|
-
refCount: true,
|
|
114
|
-
bufferSize: 1
|
|
115
|
-
}));
|
|
116
|
-
//#endregion
|
|
117
|
-
export { getWalletConnectSessionAccounts$ as a, getSessionCaip10s as i, createPlatformAccounts$ as n, getCaip10Addresses as r, createInjectedWallets$ as t };
|
|
118
|
-
|
|
119
|
-
//# sourceMappingURL=injectedWallets-Uz4hPuoW.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectedWallets-Uz4hPuoW.mjs","names":[],"sources":["../src/api/platformAccounts.ts","../src/api/injectedWallets.ts"],"sourcesContent":["import {\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tof,\n\tshareReplay,\n\tswitchMap,\n} from \"rxjs\";\nimport { getCachedObservable$ } from \"../utils/getCachedObservable\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\n/**\n * The platform-specific surface of an accounts stream. The shared pipeline —\n * filter connected wallets, fan out per-wallet account streams, flatten,\n * change-detect, share — is owned by {@link createPlatformAccounts$}.\n */\nexport type PlatformAccountsOptions<\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n> = {\n\t/** This platform's wallets plus the shared WalletConnect connector. */\n\twallets$: Observable<(TWallet | WalletConnectWallet)[]>;\n\t/** Account stream for one connected injected wallet. */\n\tgetInjectedAccounts$: (wallet: TWallet) => Observable<TAccount[]>;\n\t/** Account stream for the WalletConnect connector. */\n\tgetWalletConnectAccounts$: (\n\t\twallet: WalletConnectWallet,\n\t) => Observable<TAccount[]>;\n\t/** Optional post-flatten transform (e.g. Polkadot's `accountTypes` filter). */\n\tmapAccounts?: (accounts: TAccount[]) => TAccount[];\n\t/**\n\t * Signature of the account fields that should trigger a re-emission.\n\t * Defaults to the account id; platforms add mutable fields (Ethereum\n\t * `chainId`, Solana `chains`).\n\t */\n\taccountChangeKey?: (account: TAccount) => string;\n};\n\n/** Shared engine behind every platform's `getAccounts$`. */\nexport const createPlatformAccounts$ = <\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n>({\n\twallets$,\n\tgetInjectedAccounts$,\n\tgetWalletConnectAccounts$,\n\tmapAccounts,\n\taccountChangeKey = (account) => account.id,\n}: PlatformAccountsOptions<TWallet, TAccount>): Observable<TAccount[]> => {\n\tconst accountsListEqual = (a: TAccount[], b: TAccount[]) =>\n\t\ta.length === b.length &&\n\t\ta.every((account, i) => {\n\t\t\tconst other = b[i];\n\t\t\treturn !!other && accountChangeKey(account) === accountChangeKey(other);\n\t\t});\n\n\treturn new Observable<TAccount[]>((subscriber) => {\n\t\tconst sub = wallets$\n\t\t\t.pipe(\n\t\t\t\tmap((wallets) => wallets.filter((w) => w.isConnected)),\n\t\t\t\tswitchMap((wallets) =>\n\t\t\t\t\twallets.length\n\t\t\t\t\t\t? combineLatest([\n\t\t\t\t\t\t\t\t...wallets\n\t\t\t\t\t\t\t\t\t.filter((w): w is TWallet => !isWalletConnectWallet(w))\n\t\t\t\t\t\t\t\t\t.map(getInjectedAccounts$),\n\t\t\t\t\t\t\t\t...wallets\n\t\t\t\t\t\t\t\t\t.filter(isWalletConnectWallet)\n\t\t\t\t\t\t\t\t\t.map(getWalletConnectAccounts$),\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t: of([]),\n\t\t\t\t),\n\t\t\t\tmap((accounts) => {\n\t\t\t\t\tconst flat = accounts.flat();\n\t\t\t\t\treturn mapAccounts ? mapAccounts(flat) : flat;\n\t\t\t\t}),\n\t\t\t\tdistinctUntilChanged(accountsListEqual),\n\t\t\t)\n\t\t\t.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n\n/**\n * CAIP-10 account strings (\"<namespace>:<chainRef>:<address>\") the live\n * WalletConnect session carries for a namespace.\n */\nexport const getSessionCaip10s = (\n\tsession: NonNullable<WalletConnectProvider[\"session\"]>,\n\tnamespace: string,\n): string[] =>\n\tObject.values(session.namespaces)\n\t\t.flatMap((ns) => ns.accounts ?? [])\n\t\t.filter((account) => account.startsWith(`${namespace}:`));\n\n/**\n * Unique addresses from CAIP-10 account strings (one entry per chain, so the\n * same address repeats — dedupe).\n */\nexport const getCaip10Addresses = (caip10s: string[]): string[] => [\n\t...new Set(\n\t\tcaip10s\n\t\t\t.map((account) => account.split(\":\")[2])\n\t\t\t.filter((address): address is string => !!address),\n\t),\n];\n\n/**\n * Shared shape of the Polkadot/Solana WalletConnect account streams: no-op\n * unless the session carries the platform's namespace, then a cached\n * observable that rebuilds the account list from the session on\n * `session_update` / `accountsChanged`.\n *\n * AppKit's `getAccount(namespace).allAccounts` is always empty for namespaces\n * without a native AppKit adapter — the WalletConnect session is the source of\n * truth, hence the session-driven rebuild.\n */\nexport const getWalletConnectSessionAccounts$ = <\n\tTAccount extends BaseWalletAccount,\n>(options: {\n\twallet: WalletConnectWallet;\n\tplatform: WalletPlatform;\n\t/** WalletConnect namespace, e.g. \"polkadot\" | \"solana\" | \"eip155\". */\n\tnamespace: string;\n\t/** Cache key for {@link getCachedObservable$} — must be reconnect-safe. */\n\tcacheKey: string;\n\t/** Build the account list from the live session. */\n\tbuildAccounts: (provider: WalletConnectProvider) => TAccount[];\n}): Observable<TAccount[]> => {\n\tconst { wallet, platform, namespace, cacheKey, buildAccounts } = options;\n\tconst provider = wallet.appKit.getProvider(namespace);\n\n\tif (!wallet.platforms.includes(platform) || !provider?.session) return of([]);\n\n\treturn getCachedObservable$(cacheKey, () =>\n\t\tnew Observable<TAccount[]>((subscriber) => {\n\t\t\tsubscriber.next(buildAccounts(provider));\n\n\t\t\t// Re-derive when the WalletConnect session's accounts change, mirroring\n\t\t\t// the injected paths' change subscriptions.\n\t\t\tconst reemit = () => subscriber.next(buildAccounts(provider));\n\t\t\tprovider.on(\"session_update\", reemit);\n\t\t\tprovider.on(\"accountsChanged\", reemit);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"session_update\", reemit);\n\t\t\t\tprovider.off(\"accountsChanged\", reemit);\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n","import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tshareReplay,\n} from \"rxjs\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport { KheopskitError } from \"./errors\";\nimport type { KheopskitStore } from \"./store\";\nimport type { BaseWallet } from \"./types\";\n\n/**\n * Compare two wallet arrays by their relevant properties (not functions).\n * Shared by every platform's injected-wallets stream.\n */\nconst walletsEqual = <\n\tW extends Pick<BaseWallet, \"id\" | \"isConnected\" | \"name\">,\n>(\n\ta: W[],\n\tb: W[],\n): boolean => {\n\tif (a.length !== b.length) return false;\n\treturn a.every(\n\t\t(w, i) =>\n\t\t\tw.id === b[i]?.id &&\n\t\t\tw.isConnected === b[i]?.isConnected &&\n\t\t\tw.name === b[i]?.name,\n\t);\n};\n\n/**\n * The platform-specific surface of an injected-wallets stream. Everything else\n * — the connect/disconnect state machine, the connected-ids bookkeeping, the\n * store persistence, change detection and sharing — is owned by\n * {@link createInjectedWallets$}.\n *\n * @typeParam TSource - a wallet as the platform's registry reports it\n * @typeParam TWallet - the platform's wallet type\n * @typeParam THandle - live connection handle retained while connected\n * (Polkadot keeps the `InjectedExtension`; platforms with no handle use void)\n */\nexport type InjectedWalletsAdapter<\n\tTSource,\n\tTWallet extends BaseWallet,\n\tTHandle = void,\n> = {\n\t/** Live registry of the platform's injected wallets (emits `[]` during SSR). */\n\tsources$: Observable<readonly TSource[]>;\n\t/** Stable wallet id for a registry entry. */\n\tgetWalletId: (source: TSource) => WalletId;\n\t/**\n\t * Platform connect call (e.g. `connectInjectedExtension`,\n\t * `eth_requestAccounts`, `standard:connect`). The resolved value is retained\n\t * as the wallet's live handle until disconnect.\n\t */\n\tconnect: (source: TSource, walletId: WalletId) => Promise<THandle>;\n\t/**\n\t * Optional platform disconnect call, awaited before local state clears so a\n\t * failed disconnect rejects without desyncing the connected list.\n\t */\n\tdisconnect?: (source: TSource, walletId: WalletId) => Promise<void>;\n\t/**\n\t * Runs after a disconnect fully applied — the place to drop cached account\n\t * observables so a later reconnect rebuilds them against a fresh handle.\n\t */\n\tonDisconnected?: (walletId: WalletId) => void;\n\t/** Build the platform wallet object for one registry entry. */\n\tbuildWallet: (args: {\n\t\tsource: TSource;\n\t\twalletId: WalletId;\n\t\t/** Live connection handle; `undefined` while disconnected. */\n\t\thandle: THandle | undefined;\n\t\tisConnected: boolean;\n\t\tconnect: () => Promise<void>;\n\t\tdisconnect: () => Promise<void>;\n\t}) => TWallet;\n};\n\n/**\n * The shared engine behind every platform's injected-wallets stream: tracks\n * connected wallets (and their live handles), guards double\n * connect/disconnect, persists connected ids to the store for auto-reconnect,\n * and re-emits the wallet list whenever the registry or connection state\n * changes.\n */\nexport const createInjectedWallets$ = <\n\tTSource,\n\tTWallet extends BaseWallet,\n\tTHandle = void,\n>(\n\tstore: KheopskitStore,\n\tadapter: InjectedWalletsAdapter<TSource, TWallet, THandle>,\n): Observable<TWallet[]> =>\n\tnew Observable<TWallet[]>((subscriber) => {\n\t\tconst handles$ = new BehaviorSubject<Map<WalletId, THandle>>(new Map());\n\n\t\tconst connect = async (source: TSource, walletId: WalletId) => {\n\t\t\tif (handles$.value.has(walletId))\n\t\t\t\tthrow new KheopskitError(\n\t\t\t\t\t\"WALLET_ALREADY_CONNECTED\",\n\t\t\t\t\t`wallet ${walletId} is already connected`,\n\t\t\t\t\t{ walletId },\n\t\t\t\t);\n\n\t\t\tconst handle = await adapter.connect(source, walletId);\n\n\t\t\tconst next = new Map(handles$.value);\n\t\t\tnext.set(walletId, handle);\n\t\t\thandles$.next(next);\n\n\t\t\tstore.addEnabledWalletId(walletId);\n\t\t};\n\n\t\tconst disconnect = async (source: TSource, walletId: WalletId) => {\n\t\t\tif (!handles$.value.has(walletId))\n\t\t\t\tthrow new KheopskitError(\n\t\t\t\t\t\"WALLET_NOT_CONNECTED\",\n\t\t\t\t\t`wallet ${walletId} is not connected`,\n\t\t\t\t\t{ walletId },\n\t\t\t\t);\n\n\t\t\tawait adapter.disconnect?.(source, walletId);\n\n\t\t\tconst next = new Map(handles$.value);\n\t\t\tnext.delete(walletId);\n\t\t\thandles$.next(next);\n\n\t\t\tstore.removeEnabledWalletId(walletId);\n\n\t\t\tadapter.onDisconnected?.(walletId);\n\t\t};\n\n\t\tconst sub = combineLatest([adapter.sources$, handles$])\n\t\t\t.pipe(\n\t\t\t\tmap(([sources, handles]) =>\n\t\t\t\t\tsources.map((source): TWallet => {\n\t\t\t\t\t\tconst walletId = adapter.getWalletId(source);\n\t\t\t\t\t\treturn adapter.buildWallet({\n\t\t\t\t\t\t\tsource,\n\t\t\t\t\t\t\twalletId,\n\t\t\t\t\t\t\thandle: handles.get(walletId),\n\t\t\t\t\t\t\tisConnected: handles.has(walletId),\n\t\t\t\t\t\t\tconnect: () => connect(source, walletId),\n\t\t\t\t\t\t\tdisconnect: () => disconnect(source, walletId),\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\tdistinctUntilChanged(walletsEqual),\n\t\t\t)\n\t\t\t.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n"],"mappings":";;;;;AA+CA,MAAa,2BAGX,EACD,UACA,sBACA,2BACA,aACA,oBAAoB,YAAY,QAAQ,SACiC;CACzE,MAAM,qBAAqB,GAAe,MACzC,EAAE,WAAW,EAAE,UACf,EAAE,OAAO,SAAS,MAAM;EACvB,MAAM,QAAQ,EAAE;EAChB,OAAO,CAAC,CAAC,SAAS,iBAAiB,OAAO,MAAM,iBAAiB,KAAK;CACvE,CAAC;CAEF,OAAO,IAAI,YAAwB,eAAe;EACjD,MAAM,MAAM,SACV,KACA,KAAK,YAAY,QAAQ,QAAQ,MAAM,EAAE,WAAW,CAAC,GACrD,WAAW,YACV,QAAQ,SACL,cAAc,CACd,GAAG,QACD,QAAQ,MAAoB,CAA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AQ,KAAK,WAAoB;EAChC,MAAM,WAAW,QAAQ,YAAY,MAAM;EAC3C,OAAO,QAAQ,YAAY;GAC1B;GACA;GACA,QAAQ,QAAQ,IAAI,QAAQ;GAC5B,aAAa,QAAQ,IAAI,QAAQ;GACjC,eAAe,QAAQ,QAAQ,QAAQ;GACvC,kBAAkB,WAAW,QAAQ,QAAQ;EAC9C,CAAC;CACF,CAAC,CACF,GACA,qBAAqB,YAAY,CAClC,CAAC,CACA,UAAU,UAAU;CAEtB,aAAa;EACZ,IAAI,YAAY;CACjB;AACD,CAAC,CAAC,CAAC,KAAK,YAAY;CAAE,UAAU;CAAM,YAAY;AAAE,CAAC,CAAC"}
|
|
@@ -1,338 +0,0 @@
|
|
|
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/types.d.ts
|
|
24
|
-
type WalletPlatform = "polkadot" | "ethereum" | "solana";
|
|
25
|
-
/**
|
|
26
|
-
* Minimal structural view of a WalletConnect `UniversalProvider` — the subset
|
|
27
|
-
* kheopskit reads. Declared locally so core never depends on
|
|
28
|
-
* `@walletconnect/universal-provider`. The concrete instance comes from
|
|
29
|
-
* `@reown/appkit` at runtime.
|
|
30
|
-
*/
|
|
31
|
-
type WalletConnectProvider = {
|
|
32
|
-
session?: {
|
|
33
|
-
topic: string;
|
|
34
|
-
namespaces: Record<string, {
|
|
35
|
-
accounts?: string[];
|
|
36
|
-
}>;
|
|
37
|
-
};
|
|
38
|
-
client: {
|
|
39
|
-
request<T = unknown>(args: {
|
|
40
|
-
topic: string;
|
|
41
|
-
chainId: string;
|
|
42
|
-
request: {
|
|
43
|
-
method: string;
|
|
44
|
-
params: unknown;
|
|
45
|
-
};
|
|
46
|
-
}): Promise<T>;
|
|
47
|
-
};
|
|
48
|
-
request(args: {
|
|
49
|
-
method: string;
|
|
50
|
-
params?: unknown;
|
|
51
|
-
}): Promise<unknown>;
|
|
52
|
-
on(event: string, listener: (...args: unknown[]) => void): void;
|
|
53
|
-
off(event: string, listener: (...args: unknown[]) => void): void;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Minimal structural view of the Reown AppKit instance — the subset kheopskit's
|
|
57
|
-
* account factories use. Exposed as the `appKit` escape hatch on AppKit wallets;
|
|
58
|
-
* cast it to `@reown/appkit`'s `AppKit` type for the full API. Declared locally
|
|
59
|
-
* so core never depends on `@reown/appkit`'s types (it's an optional peer).
|
|
60
|
-
*/
|
|
61
|
-
type AppKitInstance = {
|
|
62
|
-
getProvider<T = WalletConnectProvider>(namespace: string): T | undefined;
|
|
63
|
-
getAccount(namespace: string): {
|
|
64
|
-
allAccounts: {
|
|
65
|
-
address: string;
|
|
66
|
-
}[];
|
|
67
|
-
} | undefined;
|
|
68
|
-
getCaipNetworks(namespace: string): {
|
|
69
|
-
caipNetworkId?: string;
|
|
70
|
-
}[];
|
|
71
|
-
};
|
|
72
|
-
type WalletType = "injected" | "walletconnect";
|
|
73
|
-
type PolkadotAccountType = "sr25519" | "ed25519" | "ecdsa" | "ethereum";
|
|
74
|
-
/**
|
|
75
|
-
* SDK-free fields common to every wallet, regardless of platform. Platform
|
|
76
|
-
* packages (`@kheopskit/core/<platform>`) extend this with SDK-typed fields
|
|
77
|
-
* (the injected provider/extension/standard-wallet handle).
|
|
78
|
-
*/
|
|
79
|
-
type BaseWallet = {
|
|
80
|
-
id: WalletId;
|
|
81
|
-
platform: WalletPlatform;
|
|
82
|
-
type: WalletType;
|
|
83
|
-
name: string;
|
|
84
|
-
icon: string;
|
|
85
|
-
isConnected: boolean;
|
|
86
|
-
connect: () => Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* Disconnect the wallet. Resolves once the underlying provider/extension
|
|
89
|
-
* disconnect completes; rejects if it fails so callers can surface or retry.
|
|
90
|
-
*/
|
|
91
|
-
disconnect: () => Promise<void>;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* SDK-free fields common to every account, regardless of platform. Platform
|
|
95
|
-
* packages extend this with their SDK-typed signer/client.
|
|
96
|
-
*/
|
|
97
|
-
type BaseWalletAccount = {
|
|
98
|
-
id: WalletAccountId;
|
|
99
|
-
platform: WalletPlatform;
|
|
100
|
-
/** Base58 (Solana), SS58 (Polkadot) or 0x-hex (Ethereum) address. */
|
|
101
|
-
address: string;
|
|
102
|
-
/** Friendly account name, when the wallet exposes one (e.g. Polkadot). */
|
|
103
|
-
name?: string;
|
|
104
|
-
walletName: string;
|
|
105
|
-
walletId: WalletId;
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* The single WalletConnect connector, shared across every platform.
|
|
109
|
-
*
|
|
110
|
-
* Unlike injected wallets, it is **not tied to a platform**: one WalletConnect
|
|
111
|
-
* session spans whichever namespaces the remote wallet approves in a single
|
|
112
|
-
* pairing (a namespace can't be added to a live session afterwards). So there is
|
|
113
|
-
* exactly one of these in `wallets`, discriminated by `type: "walletconnect"`.
|
|
114
|
-
* Its accounts appear in `accounts`, each carrying its own `platform`.
|
|
115
|
-
*/
|
|
116
|
-
type WalletConnectWallet = {
|
|
117
|
-
id: WalletId;
|
|
118
|
-
type: "walletconnect";
|
|
119
|
-
/**
|
|
120
|
-
* Platforms (namespaces) the live session currently carries. Empty until
|
|
121
|
-
* connected; populated with whatever the wallet approved (e.g. just
|
|
122
|
-
* `["ethereum"]`, or `["polkadot", "ethereum"]`).
|
|
123
|
-
*/
|
|
124
|
-
platforms: WalletPlatform[];
|
|
125
|
-
/**
|
|
126
|
-
* Raw Reown AppKit instance, exposed as an escape hatch for advanced use
|
|
127
|
-
* (custom modal control, reading providers directly). Most consumers should
|
|
128
|
-
* use `connect`/`disconnect` and the derived accounts instead.
|
|
129
|
-
*/
|
|
130
|
-
appKit: AppKitInstance;
|
|
131
|
-
name: string;
|
|
132
|
-
icon: string;
|
|
133
|
-
isConnected: boolean;
|
|
134
|
-
connect: () => Promise<void>;
|
|
135
|
-
disconnect: () => Promise<void>;
|
|
136
|
-
};
|
|
137
|
-
/** Narrows a wallet to the platform-less {@link WalletConnectWallet}. */
|
|
138
|
-
declare const isWalletConnectWallet: (wallet: BaseWallet | WalletConnectWallet) => wallet is WalletConnectWallet;
|
|
139
|
-
/**
|
|
140
|
-
* Narrows a wallet to an injected (browser-extension / Wallet Standard) wallet —
|
|
141
|
-
* the complement of {@link isWalletConnectWallet}. `state.wallets` is
|
|
142
|
-
* `(InjectedWallet | WalletConnectWallet)[]`, so use this to recover the
|
|
143
|
-
* injected-only fields when iterating: `platform`, `sourceId`, and the SDK
|
|
144
|
-
* handle (`provider` on Ethereum, `extension` on Polkadot, `wallet` on Solana).
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* for (const wallet of wallets.filter(isInjectedWallet)) {
|
|
149
|
-
* console.log(wallet.platform, wallet.sourceId); // typed, no WC widening
|
|
150
|
-
* }
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
declare const isInjectedWallet: <W extends BaseWallet | WalletConnectWallet>(wallet: W) => wallet is Exclude<W, WalletConnectWallet>;
|
|
154
|
-
/**
|
|
155
|
-
* Dapp metadata shown in the WalletConnect modal. Mirrors WalletConnect's
|
|
156
|
-
* `Metadata`, declared locally so core doesn't depend on
|
|
157
|
-
* `@walletconnect/universal-provider`.
|
|
158
|
-
*/
|
|
159
|
-
type WalletConnectMetadata = {
|
|
160
|
-
name: string;
|
|
161
|
-
description: string;
|
|
162
|
-
url: string;
|
|
163
|
-
icons: string[];
|
|
164
|
-
};
|
|
165
|
-
type WalletConnectConfig = {
|
|
166
|
-
projectId: string;
|
|
167
|
-
metadata: WalletConnectMetadata;
|
|
168
|
-
/** Defaults to wss://relay.walletconnect.com */
|
|
169
|
-
relayUrl?: string;
|
|
170
|
-
/**
|
|
171
|
-
* Networks AppKit should enable. Pass `AppKitNetwork[]` from
|
|
172
|
-
* `@reown/appkit/networks` (see
|
|
173
|
-
* https://docs.reown.com/advanced/multichain/polkadot/dapp-integration-guide#walletconnect-code%2Fcomponent-setup).
|
|
174
|
-
* Loosely typed (`unknown`) so core doesn't depend on `@reown/appkit`'s
|
|
175
|
-
* types — the value is forwarded to AppKit as-is.
|
|
176
|
-
*/
|
|
177
|
-
networks: [unknown, ...unknown[]];
|
|
178
|
-
themeMode?: "light" | "dark";
|
|
179
|
-
themeVariables?: Record<string, string | number>;
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* Context passed to a platform plugin's `getWallets$`. Carries the shared store
|
|
183
|
-
* and the resolved core config (for WalletConnect / debug).
|
|
184
|
-
*/
|
|
185
|
-
type PlatformContext = {
|
|
186
|
-
store: KheopskitStore;
|
|
187
|
-
config: KheopskitConfig;
|
|
188
|
-
};
|
|
189
|
-
/**
|
|
190
|
-
* A platform plugin. Created by the per-platform factories exported from
|
|
191
|
-
* `@kheopskit/core/polkadot`, `/ethereum`, `/solana`. Core iterates plugins
|
|
192
|
-
* generically and never imports a platform SDK itself.
|
|
193
|
-
*
|
|
194
|
-
* @typeParam TPlatform - the platform discriminant
|
|
195
|
-
* @typeParam TWallet - the platform's wallet type (extends {@link BaseWallet})
|
|
196
|
-
* @typeParam TAccount - the platform's account type (extends {@link BaseWalletAccount})
|
|
197
|
-
*/
|
|
198
|
-
type KheopskitPlatform<TPlatform extends WalletPlatform = WalletPlatform, TWallet extends BaseWallet = BaseWallet, TAccount extends BaseWalletAccount = BaseWalletAccount> = {
|
|
199
|
-
readonly platform: TPlatform;
|
|
200
|
-
getWallets$(ctx: PlatformContext): Observable<TWallet[]>;
|
|
201
|
-
getAccounts$(wallets$: Observable<(TWallet | WalletConnectWallet)[]>): Observable<TAccount[]>;
|
|
202
|
-
/**
|
|
203
|
-
* Optional hydration filter. Cached accounts for which this returns false are
|
|
204
|
-
* dropped during SSR hydration (Polkadot uses it to honour `accountTypes`).
|
|
205
|
-
*/
|
|
206
|
-
acceptsCachedAccount?(cached: CachedAccount): boolean;
|
|
207
|
-
};
|
|
208
|
-
type ElementOf<T> = T extends readonly (infer E)[] ? E : never;
|
|
209
|
-
/** The account type produced by a plugin (inferred from its `getAccounts$`). */
|
|
210
|
-
type AccountOf<T> = T extends {
|
|
211
|
-
getAccounts$: (wallets$: never) => Observable<infer R>;
|
|
212
|
-
} ? ElementOf<R> : never;
|
|
213
|
-
/** The wallet type produced by a plugin (inferred from its `getWallets$`). */
|
|
214
|
-
type WalletOf<T> = T extends {
|
|
215
|
-
getWallets$: (ctx: never) => Observable<infer R>;
|
|
216
|
-
} ? ElementOf<R> : never;
|
|
217
|
-
type KheopskitConfig<P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]> = {
|
|
218
|
-
autoReconnect: boolean;
|
|
219
|
-
/**
|
|
220
|
-
* Platform plugins to enable, e.g. `[polkadot(), solana({ chain })]`.
|
|
221
|
-
* Import factories from `@kheopskit/core/<platform>`.
|
|
222
|
-
*/
|
|
223
|
-
platforms: P;
|
|
224
|
-
walletConnect?: WalletConnectConfig;
|
|
225
|
-
/**
|
|
226
|
-
* Dapp name sent to Polkadot injected extensions on connect. Some
|
|
227
|
-
* extensions (e.g. polkadot.js) warn about a suspicious origin when it's
|
|
228
|
-
* empty.
|
|
229
|
-
*
|
|
230
|
-
* @default walletConnect.metadata.name, then window.location.hostname
|
|
231
|
-
*/
|
|
232
|
-
appName?: string;
|
|
233
|
-
debug: boolean;
|
|
234
|
-
/**
|
|
235
|
-
* Custom storage key for persisting wallet connection state.
|
|
236
|
-
* Useful when running multiple kheopskit instances on the same domain
|
|
237
|
-
* to prevent state conflicts between different dapps.
|
|
238
|
-
*
|
|
239
|
-
* @default "kheopskit"
|
|
240
|
-
*/
|
|
241
|
-
storageKey: string;
|
|
242
|
-
/**
|
|
243
|
-
* Grace period in milliseconds to wait for wallets to inject before
|
|
244
|
-
* syncing to actual state. During this period, cached wallet/account
|
|
245
|
-
* state from storage is preserved to prevent UI flashing.
|
|
246
|
-
*
|
|
247
|
-
* Set to 0 to disable hydration buffering.
|
|
248
|
-
*
|
|
249
|
-
* @default 500
|
|
250
|
-
*/
|
|
251
|
-
hydrationGracePeriod: number;
|
|
252
|
-
};
|
|
253
|
-
/**
|
|
254
|
-
* The current kheopskit state.
|
|
255
|
-
*
|
|
256
|
-
* @remarks
|
|
257
|
-
* While {@link KheopskitState.isHydrating} is `true`, `wallets` and `accounts`
|
|
258
|
-
* may contain cached placeholders restored from storage. The **SDK handles** the
|
|
259
|
-
* platform types advertise (e.g. `account.signer` / `getSigner` on Solana,
|
|
260
|
-
* `account.client` on Ethereum, `wallet.provider` / `extension`) are **absent at
|
|
261
|
-
* runtime even though the types claim them**, and placeholder wallets throw if
|
|
262
|
-
* `connect`/`disconnect` is called. Guard all access to those behind
|
|
263
|
-
* `!isHydrating`.
|
|
264
|
-
*
|
|
265
|
-
* The plain, serializable platform data that is persisted in the cache IS
|
|
266
|
-
* restored on the placeholders (Ethereum `chainId`, Polkadot key `type`), so it
|
|
267
|
-
* renders immediately on reload without flashing. Solana `chains` is not cached,
|
|
268
|
-
* so it remains absent until the live account loads.
|
|
269
|
-
*/
|
|
270
|
-
type KheopskitState<P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]> = {
|
|
271
|
-
wallets: (WalletOf<P[number]> | WalletConnectWallet)[];
|
|
272
|
-
accounts: AccountOf<P[number]>[];
|
|
273
|
-
config: KheopskitConfig<P>;
|
|
274
|
-
/**
|
|
275
|
-
* Whether the state is still being hydrated from cache.
|
|
276
|
-
*
|
|
277
|
-
* During hydration, cached wallets/accounts may be displayed before the
|
|
278
|
-
* actual wallet extensions have injected. See the type-level remarks: while
|
|
279
|
-
* this is `true`, SDK-typed fields (signer/client/provider/extension) are not
|
|
280
|
-
* present at runtime — guard all access behind `!isHydrating`.
|
|
281
|
-
*/
|
|
282
|
-
isHydrating: boolean;
|
|
283
|
-
};
|
|
284
|
-
/** Shape of the persisted store data (localStorage, or cookies in compact form). */
|
|
285
|
-
type KheopskitStoreData = {
|
|
286
|
-
autoReconnect?: WalletId[];
|
|
287
|
-
/** Cached wallet state for SSR hydration to prevent UI flash */
|
|
288
|
-
cachedWallets?: CachedWallet[];
|
|
289
|
-
/** Cached account state for SSR hydration to prevent UI flash */
|
|
290
|
-
cachedAccounts?: CachedAccount[];
|
|
291
|
-
};
|
|
292
|
-
/**
|
|
293
|
-
* The persisted settings store shared between core and framework bindings.
|
|
294
|
-
* Declared structurally here (implemented by `createKheopskitStore`) so modules
|
|
295
|
-
* can depend on the interface without importing the implementation.
|
|
296
|
-
*/
|
|
297
|
-
type KheopskitStore = {
|
|
298
|
-
observable: Observable<KheopskitStoreData>;
|
|
299
|
-
addEnabledWalletId: (walletId: WalletId) => void;
|
|
300
|
-
removeEnabledWalletId: (walletId: WalletId) => void;
|
|
301
|
-
getCachedState: () => {
|
|
302
|
-
wallets: CachedWallet[];
|
|
303
|
-
accounts: CachedAccount[];
|
|
304
|
-
};
|
|
305
|
-
setCachedState: (wallets: CachedWallet[], accounts: CachedAccount[]) => void;
|
|
306
|
-
};
|
|
307
|
-
/**
|
|
308
|
-
* Serializable wallet data for SSR hydration cache.
|
|
309
|
-
* Contains only the data needed to render wallet UI without flash.
|
|
310
|
-
* Note: icon is NOT stored to save cookie space - it's looked up at hydration time.
|
|
311
|
-
*/
|
|
312
|
-
type CachedWallet = {
|
|
313
|
-
id: WalletId;
|
|
314
|
-
/** Absent for the platform-less WalletConnect connector. */
|
|
315
|
-
platform?: WalletPlatform;
|
|
316
|
-
type: WalletType;
|
|
317
|
-
name: string;
|
|
318
|
-
isConnected: boolean;
|
|
319
|
-
};
|
|
320
|
-
/**
|
|
321
|
-
* Serializable account data for SSR hydration cache.
|
|
322
|
-
* Contains only the data needed to render account UI without flash.
|
|
323
|
-
*/
|
|
324
|
-
type CachedAccount = {
|
|
325
|
-
id: string;
|
|
326
|
-
platform: WalletPlatform;
|
|
327
|
-
address: string;
|
|
328
|
-
name?: string;
|
|
329
|
-
/** Cached chain ID for Ethereum accounts. */
|
|
330
|
-
chainId?: number;
|
|
331
|
-
/** Cached key type for Polkadot accounts. */
|
|
332
|
-
polkadotAccountType?: PolkadotAccountType;
|
|
333
|
-
walletId: WalletId;
|
|
334
|
-
walletName: string;
|
|
335
|
-
};
|
|
336
|
-
//#endregion
|
|
337
|
-
export { WalletId as C, WalletAccountId as D, parseWalletId as E, getWalletAccountId as O, isWalletConnectWallet as S, isValidWalletId as T, WalletConnectWallet as _, CachedAccount as a, WalletType as b, KheopskitPlatform as c, KheopskitStoreData as d, PlatformContext as f, WalletConnectProvider as g, WalletConnectMetadata as h, BaseWalletAccount as i, parseWalletAccountId as k, KheopskitState as l, WalletConnectConfig as m, AppKitInstance as n, CachedWallet as o, PolkadotAccountType as p, BaseWallet as r, KheopskitConfig as s, AccountOf as t, KheopskitStore as u, WalletOf as v, getWalletId as w, isInjectedWallet as x, WalletPlatform as y };
|
|
338
|
-
//# sourceMappingURL=types-AxUDtkR-.d.mts.map
|